Skip to content

Commit cfd35c9

Browse files
fix(tui): include variant in model switch notice (#34856)
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
1 parent 674d08f commit cfd35c9

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

packages/tui/src/routes/session/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import { OPENCODE_BASE_MODE, useBindings, useCommandShortcut } from "../../keyma
7171
import { usePathFormatter } from "../../context/path-format"
7272
import { LocationProvider } from "../../context/location"
7373
import { createSessionRows, type PartRef, type SessionRow } from "./rows"
74+
import { switchLabel } from "../../util/model"
7475

7576
addDefaultParsers(parsers.parsers)
7677

@@ -1231,8 +1232,7 @@ function SessionSwitchMessageV2(props: { message: SessionMessage }) {
12311232
const { theme } = useTheme()
12321233
const text = () => {
12331234
if (props.message.type === "agent-switched") return `Switched agent to ${props.message.agent}`
1234-
if (props.message.type === "model-switched")
1235-
return `Switched model to ${props.message.model.providerID}/${props.message.model.id}`
1235+
if (props.message.type === "model-switched") return switchLabel(props.message.model)
12361236
return ""
12371237
}
12381238
return <text fg={theme.textMuted}>{text()}</text>

packages/tui/src/util/model.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,11 @@ export function name(
2626
) {
2727
return get(list, providerID, modelID)?.name ?? modelID
2828
}
29+
30+
export function formatRef(model: { providerID: string; id: string; variant?: string }) {
31+
return [model.providerID, model.id, model.variant].filter((value) => value !== undefined).join("/")
32+
}
33+
34+
export function switchLabel(model: { providerID: string; id: string; variant?: string }) {
35+
return `Switched model to ${formatRef(model)}`
36+
}
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
import { describe, expect, test } from "bun:test"
2-
import { parse } from "../../src/util/model"
2+
import { formatRef, parse, switchLabel } from "../../src/util/model"
33

44
describe("util.model", () => {
55
test("splits provider from a nested model identifier", () => {
66
expect(parse("provider/org/model")).toEqual({ providerID: "provider", modelID: "org/model" })
77
expect(parse("invalid")).toEqual({ providerID: "invalid", modelID: "" })
88
})
9+
10+
test("includes the selected variant in model refs", () => {
11+
expect(formatRef({ providerID: "anthropic", id: "sonnet", variant: "thinking" })).toBe("anthropic/sonnet/thinking")
12+
expect(formatRef({ providerID: "anthropic", id: "sonnet" })).toBe("anthropic/sonnet")
13+
})
14+
15+
test("includes the selected variant in model switch notices", () => {
16+
expect(switchLabel({ providerID: "anthropic", id: "sonnet", variant: "thinking" })).toBe(
17+
"Switched model to anthropic/sonnet/thinking",
18+
)
19+
})
920
})

0 commit comments

Comments
 (0)