Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,12 @@ export function Prompt(props: PromptProps) {
const model = sync.data.provider.find((item) => item.id === last.providerID)?.models[last.modelID]
const pct = model?.limit.context ? `${Math.round((tokens / model.limit.context) * 100)}%` : undefined
const cost = msg.reduce((sum, item) => sum + (item.role === "assistant" ? item.cost : 0), 0)
const elapsed = last.time.completed ? last.time.completed - last.time.created : 0
const tps = elapsed > 0 ? last.tokens.output / (elapsed / 1000) : undefined
return {
context: pct ? `${Locale.number(tokens)} (${pct})` : Locale.number(tokens),
cost: cost > 0 ? money.format(cost) : undefined,
tps: tps ? `${tps.toFixed(0)} t/s` : undefined,
}
})

Expand Down Expand Up @@ -1245,7 +1248,7 @@ export function Prompt(props: PromptProps) {
<Match when={usage()}>
{(item) => (
<text fg={theme.textMuted} wrapMode="none">
{[item().context, item().cost].filter(Boolean).join(" · ")}
{[item().tps, item().context, item().cost].filter(Boolean).join(" · ")}
</text>
)}
</Match>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ function View(props: { api: TuiPluginApi; session_id: string }) {
return {
tokens: 0,
percent: null,
tps: null,
}
}

const tokens =
last.tokens.input + last.tokens.output + last.tokens.reasoning + last.tokens.cache.read + last.tokens.cache.write
const model = props.api.state.provider.find((item) => item.id === last.providerID)?.models[last.modelID]
const elapsed = last.time.completed ? last.time.completed - last.time.created : 0
const tps = elapsed > 0 ? last.tokens.output / (elapsed / 1000) : null
return {
tokens,
percent: model?.limit.context ? Math.round((tokens / model.limit.context) * 100) : null,
tps,
}
})

Expand All @@ -39,6 +43,7 @@ function View(props: { api: TuiPluginApi; session_id: string }) {
</text>
<text fg={theme().textMuted}>{state().tokens.toLocaleString()} tokens</text>
<text fg={theme().textMuted}>{state().percent ?? 0}% used</text>
{state().tps !== null && <text fg={theme().textMuted}>{state().tps!.toFixed(0)} t/s</text>}
<text fg={theme().textMuted}>{money.format(cost())} spent</text>
</box>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ export function SubagentFooter() {
currency: "USD",
})

const elapsed = last.time.completed ? last.time.completed - last.time.created : 0
const tps = elapsed > 0 ? last.tokens.output / (elapsed / 1000) : undefined

return {
context: pct ? `${Locale.number(tokens)} (${pct})` : Locale.number(tokens),
cost: cost > 0 ? money.format(cost) : undefined,
tps: tps ? `${tps.toFixed(0)} t/s` : undefined,
}
})

Expand Down Expand Up @@ -87,7 +91,7 @@ export function SubagentFooter() {
<Show when={usage()}>
{(item) => (
<text fg={theme.textMuted} wrapMode="none">
{[item().context, item().cost].filter(Boolean).join(" · ")}
{[item().tps, item().context, item().cost].filter(Boolean).join(" · ")}
</text>
)}
</Show>
Expand Down
Loading