fix(tui): use catalog display name in model switch notices (#34913)
This commit is contained in:
@@ -1229,10 +1229,11 @@ function AssistantFooter(props: { message: SessionMessageAssistant }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function SessionSwitchMessageV2(props: { message: SessionMessage }) {
|
function SessionSwitchMessageV2(props: { message: SessionMessage }) {
|
||||||
|
const ctx = use()
|
||||||
const { theme } = useTheme()
|
const { theme } = useTheme()
|
||||||
const text = () => {
|
const text = () => {
|
||||||
if (props.message.type === "agent-switched") return `Switched agent to ${props.message.agent}`
|
if (props.message.type === "agent-switched") return `Switched agent to ${props.message.agent}`
|
||||||
if (props.message.type === "model-switched") return switchLabel(props.message.model)
|
if (props.message.type === "model-switched") return switchLabel(props.message.model, ctx.models())
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return <text fg={theme.textMuted}>{text()}</text>
|
return <text fg={theme.textMuted}>{text()}</text>
|
||||||
|
|||||||
@@ -31,6 +31,14 @@ export function formatRef(model: { providerID: string; id: string; variant?: str
|
|||||||
return [model.providerID, model.id, model.variant].filter((value) => value !== undefined).join("/")
|
return [model.providerID, model.id, model.variant].filter((value) => value !== undefined).join("/")
|
||||||
}
|
}
|
||||||
|
|
||||||
export function switchLabel(model: { providerID: string; id: string; variant?: string }) {
|
export function switchLabel(
|
||||||
return `Switched model to ${formatRef(model)}`
|
model: { providerID: string; id: string; variant?: string },
|
||||||
|
models?: readonly { providerID: string; id: string; name: string }[],
|
||||||
|
) {
|
||||||
|
const display = models?.find((item) => item.providerID === model.providerID && item.id === model.id)?.name
|
||||||
|
if (display === undefined) return `Switched model to ${formatRef(model)}`
|
||||||
|
// Variant-only switches publish the same model id; without the variant the
|
||||||
|
// notice would look like a redundant model switch.
|
||||||
|
const variant = model.variant && model.variant !== "default" ? ` (${model.variant})` : ""
|
||||||
|
return `Switched model to ${display}${variant}`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,21 @@ describe("util.model", () => {
|
|||||||
"Switched model to anthropic/sonnet/thinking",
|
"Switched model to anthropic/sonnet/thinking",
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("uses the catalog display name in model switch notices", () => {
|
||||||
|
const models = [
|
||||||
|
{ providerID: "openai", id: "gpt-5.5-fast", name: "GPT-5.5 Fast" },
|
||||||
|
{ providerID: "anthropic", id: "sonnet", name: "Claude Sonnet" },
|
||||||
|
]
|
||||||
|
expect(switchLabel({ providerID: "openai", id: "gpt-5.5-fast", variant: "high" }, models)).toBe(
|
||||||
|
"Switched model to GPT-5.5 Fast (high)",
|
||||||
|
)
|
||||||
|
expect(switchLabel({ providerID: "anthropic", id: "sonnet" }, models)).toBe("Switched model to Claude Sonnet")
|
||||||
|
expect(switchLabel({ providerID: "anthropic", id: "sonnet", variant: "default" }, models)).toBe(
|
||||||
|
"Switched model to Claude Sonnet",
|
||||||
|
)
|
||||||
|
expect(switchLabel({ providerID: "removed", id: "gone", variant: "high" }, models)).toBe(
|
||||||
|
"Switched model to removed/gone/high",
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user