fix(regression): normalize model picker provider endpoint aliases

This commit is contained in:
Tak Hoffman
2026-03-27 22:01:25 -05:00
parent 969294f8c5
commit ae2b1aef10
2 changed files with 40 additions and 2 deletions

View File

@@ -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",
});
});
});

View File

@@ -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 {