diff --git a/src/auto-reply/reply/directive-handling.model-picker.test.ts b/src/auto-reply/reply/directive-handling.model-picker.test.ts new file mode 100644 index 00000000000..b426d7237e1 --- /dev/null +++ b/src/auto-reply/reply/directive-handling.model-picker.test.ts @@ -0,0 +1,34 @@ +import { describe, expect, it } from "vitest"; +import { + buildModelPickerItems, + resolveProviderEndpointLabel, +} from "./directive-handling.model-picker.js"; + +describe("directive-handling.model-picker", () => { + it("dedupes provider aliases when building picker items", () => { + expect( + buildModelPickerItems([ + { provider: "z.ai", id: "glm-5" }, + { provider: "z-ai", id: "glm-5" }, + ]), + ).toEqual([{ provider: "zai", model: "glm-5" }]); + }); + + it("matches provider endpoint labels across canonical aliases", () => { + const result = resolveProviderEndpointLabel("z-ai", { + models: { + providers: { + "z.ai": { + baseUrl: "https://api.z.ai/api/paas/v4", + api: "responses", + }, + }, + }, + } as never); + + expect(result).toEqual({ + endpoint: "https://api.z.ai/api/paas/v4", + api: "responses", + }); + }); +}); diff --git a/src/auto-reply/reply/directive-handling.model-picker.ts b/src/auto-reply/reply/directive-handling.model-picker.ts index 46c892dab0f..7122b1f204a 100644 --- a/src/auto-reply/reply/directive-handling.model-picker.ts +++ b/src/auto-reply/reply/directive-handling.model-picker.ts @@ -1,4 +1,8 @@ -import { type ModelRef, normalizeProviderId } from "../../agents/model-selection.js"; +import { + findNormalizedProviderValue, + type ModelRef, + normalizeProviderId, +} from "../../agents/model-selection.js"; import type { OpenClawConfig } from "../../config/config.js"; export type ModelPickerCatalogEntry = { @@ -88,7 +92,7 @@ export function resolveProviderEndpointLabel( string, { baseUrl?: string; api?: string } | undefined >; - const entry = providers[normalized]; + const entry = findNormalizedProviderValue(providers, normalized); const endpoint = entry?.baseUrl?.trim(); const api = entry?.api?.trim(); return {