mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 21:10:21 +00:00
fix: keep provider discovery on mockable lazy runtime paths
This commit is contained in:
39
src/agents/provider-model-normalization.runtime.ts
Normal file
39
src/agents/provider-model-normalization.runtime.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user