Files
openclaw/src/agents/provider-model-normalization.runtime.ts
2026-03-28 11:40:40 +00:00

40 lines
1.0 KiB
TypeScript

import { createRequire } from "node:module";
type ProviderRuntimeModule = Pick<
typeof import("../plugins/provider-runtime.js"),
"normalizeProviderModelIdWithPlugin"
>;
const require = createRequire(import.meta.url);
const PROVIDER_RUNTIME_CANDIDATES = [
"../plugins/provider-runtime.js",
"../plugins/provider-runtime.ts",
] as const;
let providerRuntimeModule: ProviderRuntimeModule | undefined;
function loadProviderRuntime(): ProviderRuntimeModule | null {
if (providerRuntimeModule) {
return providerRuntimeModule;
}
for (const candidate of PROVIDER_RUNTIME_CANDIDATES) {
try {
providerRuntimeModule = require(candidate) as ProviderRuntimeModule;
return providerRuntimeModule;
} catch {
// Try source/runtime candidates in order.
}
}
return null;
}
export function normalizeProviderModelIdWithRuntime(params: {
provider: string;
context: {
provider: string;
modelId: string;
};
}): string | undefined {
return loadProviderRuntime()?.normalizeProviderModelIdWithPlugin(params);
}