fix(tui): resolve wrong provider prefix when session has model without modelProvider (#25874)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: f0953a7284
Co-authored-by: lbo728 <72309817+lbo728@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
byungsker
2026-02-25 14:36:27 +09:00
committed by GitHub
parent 8f5f599a34
commit 177386ed73
12 changed files with 559 additions and 13 deletions

View File

@@ -3,6 +3,7 @@ import type { OpenClawConfig } from "../config/config.js";
import { resetLogger, setLoggerOverride } from "../logging/logger.js";
import {
buildAllowedModelSet,
inferUniqueProviderFromConfiguredModels,
parseModelRef,
buildModelAliasIndex,
modelKey,
@@ -134,6 +135,85 @@ describe("model-selection", () => {
});
});
describe("inferUniqueProviderFromConfiguredModels", () => {
it("infers provider when configured model match is unique", () => {
const cfg = {
agents: {
defaults: {
models: {
"anthropic/claude-sonnet-4-6": {},
},
},
},
} as OpenClawConfig;
expect(
inferUniqueProviderFromConfiguredModels({
cfg,
model: "claude-sonnet-4-6",
}),
).toBe("anthropic");
});
it("returns undefined when configured matches are ambiguous", () => {
const cfg = {
agents: {
defaults: {
models: {
"anthropic/claude-sonnet-4-6": {},
"minimax/claude-sonnet-4-6": {},
},
},
},
} as OpenClawConfig;
expect(
inferUniqueProviderFromConfiguredModels({
cfg,
model: "claude-sonnet-4-6",
}),
).toBeUndefined();
});
it("returns undefined for provider-prefixed model ids", () => {
const cfg = {
agents: {
defaults: {
models: {
"anthropic/claude-sonnet-4-6": {},
},
},
},
} as OpenClawConfig;
expect(
inferUniqueProviderFromConfiguredModels({
cfg,
model: "anthropic/claude-sonnet-4-6",
}),
).toBeUndefined();
});
it("infers provider for slash-containing model id when allowlist match is unique", () => {
const cfg = {
agents: {
defaults: {
models: {
"vercel-ai-gateway/anthropic/claude-sonnet-4-6": {},
},
},
},
} as OpenClawConfig;
expect(
inferUniqueProviderFromConfiguredModels({
cfg,
model: "anthropic/claude-sonnet-4-6",
}),
).toBe("vercel-ai-gateway");
});
});
describe("buildModelAliasIndex", () => {
it("should build alias index from config", () => {
const cfg: Partial<OpenClawConfig> = {

View File

@@ -171,6 +171,42 @@ export function parseModelRef(raw: string, defaultProvider: string): ModelRef |
return normalizeModelRef(providerRaw, model);
}
export function inferUniqueProviderFromConfiguredModels(params: {
cfg: OpenClawConfig;
model: string;
}): string | undefined {
const model = params.model.trim();
if (!model) {
return undefined;
}
const configuredModels = params.cfg.agents?.defaults?.models;
if (!configuredModels) {
return undefined;
}
const normalized = model.toLowerCase();
const providers = new Set<string>();
for (const key of Object.keys(configuredModels)) {
const ref = key.trim();
if (!ref || !ref.includes("/")) {
continue;
}
const parsed = parseModelRef(ref, DEFAULT_PROVIDER);
if (!parsed) {
continue;
}
if (parsed.model === model || parsed.model.toLowerCase() === normalized) {
providers.add(parsed.provider);
if (providers.size > 1) {
return undefined;
}
}
}
if (providers.size !== 1) {
return undefined;
}
return providers.values().next().value;
}
export function normalizeModelSelection(value: unknown): string | undefined {
if (typeof value === "string") {
const trimmed = value.trim();