mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 03:24:54 +00:00
feat(tui): show explicit subagent model (#49388)
Co-authored-by: kitlangton <7587245+kitlangton@users.noreply.github.com>
This commit is contained in:
parent
8520617ca8
commit
fca4a8fa3b
2 changed files with 25 additions and 3 deletions
|
|
@ -34,6 +34,7 @@ import type {
|
|||
SessionMessageAssistantTool,
|
||||
SessionMessageUser,
|
||||
SessionInfo,
|
||||
ModelInfo,
|
||||
} from "@opencode/client"
|
||||
import { useLocal } from "../../context/local"
|
||||
import { Locale } from "../../util/locale"
|
||||
|
|
@ -3167,6 +3168,7 @@ function Subagent(props: ToolProps) {
|
|||
const sessionID = createMemo(() => stringValue(props.metadata.sessionID) ?? stringValue(props.metadata.sessionId))
|
||||
const description = createMemo(() => stringValue(props.input.description))
|
||||
const continuation = createMemo(() => Boolean(stringValue(props.input.sessionID)))
|
||||
const model = createMemo(() => subagentModelLabel(stringValue(props.input.model), data.location.model.list()))
|
||||
const isRunning = createMemo(() => {
|
||||
const id = sessionID()
|
||||
return props.part.state.status === "running" || Boolean(id && data.session.status(id) === "running")
|
||||
|
|
@ -3190,13 +3192,24 @@ function Subagent(props: ToolProps) {
|
|||
) : undefined
|
||||
}
|
||||
>
|
||||
{continuation()
|
||||
? `Continue subagent — ${description() ?? "Subagent"}`
|
||||
: `${Locale.titlecase(stringValue(props.input.agent) ?? stringValue(props.input.subagent_type) ?? "General")} Subagent — ${description() ?? "Subagent"}`}
|
||||
{`${continuation() ? "Continue subagent" : `${Locale.titlecase(stringValue(props.input.agent) ?? stringValue(props.input.subagent_type) ?? "General")} Subagent`} — ${description() ?? "Subagent"}${model() ? ` · ${model()}` : ""}`}
|
||||
</InlineTool>
|
||||
)
|
||||
}
|
||||
|
||||
export function subagentModelLabel(
|
||||
value: string | undefined,
|
||||
models: readonly Pick<ModelInfo, "providerID" | "id" | "name">[] | undefined,
|
||||
) {
|
||||
if (!value) return
|
||||
const [reference, variant] = value.split("#")
|
||||
const separator = reference.indexOf("/")
|
||||
const providerID = separator === -1 ? "" : reference.slice(0, separator)
|
||||
const modelID = separator === -1 ? reference : reference.slice(separator + 1)
|
||||
const name = models?.find((item) => item.providerID === providerID && item.id === modelID)?.name
|
||||
return `${name ?? reference}${variant ? ` (${variant})` : ""}`
|
||||
}
|
||||
|
||||
export function isBackgroundSubagent(
|
||||
metadata: Record<string, unknown>,
|
||||
status: SessionMessageAssistantTool["state"]["status"],
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import {
|
|||
parseDiagnostics,
|
||||
parseQuestionAnswers,
|
||||
parseQuestions,
|
||||
subagentModelLabel,
|
||||
toolDisplay,
|
||||
} from "../../../src/routes/session"
|
||||
|
||||
|
|
@ -237,6 +238,14 @@ describe("TUI inline tool wrapping", () => {
|
|||
expect(isBackgroundSubagent({ status: "completed" }, "completed")).toBeFalse()
|
||||
})
|
||||
|
||||
test("labels only explicit subagent model overrides", () => {
|
||||
const models = [{ providerID: "anthropic", id: "claude-opus-4-1", name: "Claude Opus 4.1" }]
|
||||
expect(subagentModelLabel(undefined, models)).toBeUndefined()
|
||||
expect(subagentModelLabel("anthropic/claude-opus-4-1", models)).toBe("Claude Opus 4.1")
|
||||
expect(subagentModelLabel("anthropic/claude-opus-4-1#max", models)).toBe("Claude Opus 4.1 (max)")
|
||||
expect(subagentModelLabel("custom/reviewer", models)).toBe("custom/reviewer")
|
||||
})
|
||||
|
||||
test("snapshots consecutive grep, glob, and read rows at a narrow width", async () => {
|
||||
expect(await renderFrame(() => <Fixture />, { width: 72, height: 12 })).toMatchSnapshot()
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue