fix: resolve bare alias to full model key in buildModelOptions
When the agent config stored a model alias (e.g. 'k2p5') instead of the full qualified key (e.g. 'kimi-coding/k2p5'), buildModelOptions would add the bare alias as an option value. The backend would then resolve 'k2p5' using the default provider (minimax), producing 'minimax/k2p5' which is not in the allowed list. Now buildModelOptions reverse-matches the alias to the full key before using the value, ensuring the select always submits a complete provider/key pair.
This commit is contained in:
parent
5e417b44e1
commit
276206ff4b
@ -576,9 +576,35 @@ export function buildModelOptions(
|
||||
current?: string | null,
|
||||
) {
|
||||
const options = resolveConfiguredModels(configForm);
|
||||
const hasCurrent = current ? options.some((option) => option.value === current) : false;
|
||||
if (current && !hasCurrent) {
|
||||
options.unshift({ value: current, label: `Current (${current})` });
|
||||
|
||||
// Resolve bare alias (e.g. "k2p5") → full key (e.g. "kimi-coding/k2p5")
|
||||
// so the select value is always a complete provider/key, never a bare alias.
|
||||
const resolvedCurrent = (() => {
|
||||
if (!current) return null;
|
||||
if (options.some((o) => o.value === current)) return current;
|
||||
const cfg = configForm as ConfigSnapshot | null;
|
||||
const models = cfg?.agents?.defaults?.models;
|
||||
if (models && typeof models === "object") {
|
||||
for (const [modelId, modelRaw] of Object.entries(models)) {
|
||||
const alias =
|
||||
modelRaw && typeof modelRaw === "object" && "alias" in modelRaw
|
||||
? typeof (modelRaw as { alias?: unknown }).alias === "string"
|
||||
? (modelRaw as { alias?: string }).alias?.trim()
|
||||
: undefined
|
||||
: undefined;
|
||||
if (alias === current) {
|
||||
return modelId.trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
return current;
|
||||
})();
|
||||
|
||||
const hasCurrent = resolvedCurrent
|
||||
? options.some((option) => option.value === resolvedCurrent)
|
||||
: false;
|
||||
if (resolvedCurrent && !hasCurrent) {
|
||||
options.unshift({ value: resolvedCurrent, label: `Current (${resolvedCurrent})` });
|
||||
}
|
||||
if (options.length === 0) {
|
||||
return html`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user