Skip to content

Commit 92dc390

Browse files
committed
feat: display llm call counter, per anomalyco#4577
1 parent 2458e75 commit 92dc390

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

  • packages/opencode/src/cli/cmd/tui/routes/session

‎packages/opencode/src/cli/cmd/tui/routes/session/header.tsx‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ const Title = (props: { session: Accessor<Session> }) => {
1616
)
1717
}
1818

19-
const ContextInfo = (props: { context: Accessor<string | undefined>; cost: Accessor<string> }) => {
19+
const ContextInfo = (props: { context: Accessor<string | undefined>; cost: Accessor<string>; llmCalls: Accessor<number> }) => {
2020
const { theme } = useTheme()
2121
return (
2222
<Show when={props.context()}>
2323
<text fg={theme.textMuted} wrapMode="none" flexShrink={0}>
24-
{props.context()} ({props.cost()})
24+
{props.context()} ({props.cost()}) ({props.llmCalls()} calls)
2525
</text>
2626
</Show>
2727
)
@@ -58,6 +58,22 @@ export function Header() {
5858
return result
5959
})
6060

61+
// Count LLM calls (step-finish parts) across all messages in session
62+
const llmCalls = createMemo(() => {
63+
let count = 0
64+
for (const msg of messages()) {
65+
if (msg.role === "assistant") {
66+
const parts = sync.data.part[msg.id] ?? []
67+
for (const part of parts) {
68+
if (part.type === "step-finish") {
69+
count++
70+
}
71+
}
72+
}
73+
}
74+
return count
75+
})
76+
6177
const { theme } = useTheme()
6278

6379
return (
@@ -67,7 +83,7 @@ export function Header() {
6783
fallback={
6884
<box flexDirection="row" justifyContent="space-between" gap={1}>
6985
<Title session={session} />
70-
<ContextInfo context={context} cost={cost} />
86+
<ContextInfo context={context} cost={cost} llmCalls={llmCalls} />
7187
</box>
7288
}
7389
>
@@ -87,7 +103,7 @@ export function Header() {
87103
</Match>
88104
</Switch>
89105
</box>
90-
<ContextInfo context={context} cost={cost} />
106+
<ContextInfo context={context} cost={cost} llmCalls={llmCalls} />
91107
</box>
92108
</Show>
93109
</box>

0 commit comments

Comments
 (0)