mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-29 19:01:44 +00:00
fix: normalize provider catalog config lookup
This commit is contained in:
@@ -121,6 +121,36 @@ describe("buildSingleProviderApiKeyCatalog", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("matches explicit base url config across canonical provider aliases", async () => {
|
||||
const result = await buildSingleProviderApiKeyCatalog({
|
||||
ctx: createCatalogContext({
|
||||
apiKeys: { zai: "secret-key" },
|
||||
config: {
|
||||
models: {
|
||||
providers: {
|
||||
"z.ai": {
|
||||
baseUrl: " https://api.z.ai/custom ",
|
||||
models: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
providerId: "z-ai",
|
||||
buildProvider: () => createProviderConfig({ baseUrl: "https://default.example/zai" }),
|
||||
allowExplicitBaseUrl: true,
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
provider: {
|
||||
api: "openai-completions",
|
||||
baseUrl: "https://api.z.ai/custom",
|
||||
models: [],
|
||||
apiKey: "secret-key",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("adds api key to each paired provider", async () => {
|
||||
const result = await buildPairedProviderApiKeyCatalog({
|
||||
ctx: createCatalogContext({
|
||||
|
||||
@@ -24,14 +24,18 @@ export async function buildSingleProviderApiKeyCatalog(params: {
|
||||
buildProvider: () => ModelProviderConfig | Promise<ModelProviderConfig>;
|
||||
allowExplicitBaseUrl?: boolean;
|
||||
}): Promise<ProviderCatalogResult> {
|
||||
const apiKey = params.ctx.resolveProviderApiKey(params.providerId).apiKey;
|
||||
const providerId = normalizeProviderId(params.providerId);
|
||||
const apiKey = params.ctx.resolveProviderApiKey(providerId).apiKey;
|
||||
if (!apiKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const explicitProvider = params.allowExplicitBaseUrl
|
||||
? params.ctx.config.models?.providers?.[params.providerId]
|
||||
: undefined;
|
||||
const explicitProvider =
|
||||
params.allowExplicitBaseUrl && params.ctx.config.models?.providers
|
||||
? Object.entries(params.ctx.config.models.providers).find(
|
||||
([configuredProviderId]) => normalizeProviderId(configuredProviderId) === providerId,
|
||||
)?.[1]
|
||||
: undefined;
|
||||
const explicitBaseUrl =
|
||||
typeof explicitProvider?.baseUrl === "string" ? explicitProvider.baseUrl.trim() : "";
|
||||
|
||||
@@ -51,7 +55,7 @@ export async function buildPairedProviderApiKeyCatalog(params: {
|
||||
| Record<string, ModelProviderConfig>
|
||||
| Promise<Record<string, ModelProviderConfig>>;
|
||||
}): Promise<ProviderCatalogResult> {
|
||||
const apiKey = params.ctx.resolveProviderApiKey(params.providerId).apiKey;
|
||||
const apiKey = params.ctx.resolveProviderApiKey(normalizeProviderId(params.providerId)).apiKey;
|
||||
if (!apiKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user