fix(tui): include variant in model switch notice (#34856)
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
This commit is contained in:
co-authored by
Aiden Cline
parent
674d08f9be
commit
cfd35c9354
@@ -71,6 +71,7 @@ import { OPENCODE_BASE_MODE, useBindings, useCommandShortcut } from "../../keyma
|
|||||||
import { usePathFormatter } from "../../context/path-format"
|
import { usePathFormatter } from "../../context/path-format"
|
||||||
import { LocationProvider } from "../../context/location"
|
import { LocationProvider } from "../../context/location"
|
||||||
import { createSessionRows, type PartRef, type SessionRow } from "./rows"
|
import { createSessionRows, type PartRef, type SessionRow } from "./rows"
|
||||||
|
import { switchLabel } from "../../util/model"
|
||||||
|
|
||||||
addDefaultParsers(parsers.parsers)
|
addDefaultParsers(parsers.parsers)
|
||||||
|
|
||||||
@@ -1231,8 +1232,7 @@ function SessionSwitchMessageV2(props: { message: SessionMessage }) {
|
|||||||
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")
|
if (props.message.type === "model-switched") return switchLabel(props.message.model)
|
||||||
return `Switched model to ${props.message.model.providerID}/${props.message.model.id}`
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return <text fg={theme.textMuted}>{text()}</text>
|
return <text fg={theme.textMuted}>{text()}</text>
|
||||||
|
|||||||
@@ -26,3 +26,11 @@ export function name(
|
|||||||
) {
|
) {
|
||||||
return get(list, providerID, modelID)?.name ?? modelID
|
return get(list, providerID, modelID)?.name ?? modelID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatRef(model: { providerID: string; id: string; variant?: string }) {
|
||||||
|
return [model.providerID, model.id, model.variant].filter((value) => value !== undefined).join("/")
|
||||||
|
}
|
||||||
|
|
||||||
|
export function switchLabel(model: { providerID: string; id: string; variant?: string }) {
|
||||||
|
return `Switched model to ${formatRef(model)}`
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,20 @@
|
|||||||
import { describe, expect, test } from "bun:test"
|
import { describe, expect, test } from "bun:test"
|
||||||
import { parse } from "../../src/util/model"
|
import { formatRef, parse, switchLabel } from "../../src/util/model"
|
||||||
|
|
||||||
describe("util.model", () => {
|
describe("util.model", () => {
|
||||||
test("splits provider from a nested model identifier", () => {
|
test("splits provider from a nested model identifier", () => {
|
||||||
expect(parse("provider/org/model")).toEqual({ providerID: "provider", modelID: "org/model" })
|
expect(parse("provider/org/model")).toEqual({ providerID: "provider", modelID: "org/model" })
|
||||||
expect(parse("invalid")).toEqual({ providerID: "invalid", modelID: "" })
|
expect(parse("invalid")).toEqual({ providerID: "invalid", modelID: "" })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("includes the selected variant in model refs", () => {
|
||||||
|
expect(formatRef({ providerID: "anthropic", id: "sonnet", variant: "thinking" })).toBe("anthropic/sonnet/thinking")
|
||||||
|
expect(formatRef({ providerID: "anthropic", id: "sonnet" })).toBe("anthropic/sonnet")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("includes the selected variant in model switch notices", () => {
|
||||||
|
expect(switchLabel({ providerID: "anthropic", id: "sonnet", variant: "thinking" })).toBe(
|
||||||
|
"Switched model to anthropic/sonnet/thinking",
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user