Skip to content

Commit f0e8686

Browse files
committed
Fix TPS calculation to use current message instead of other messages
1 parent bca9e4e commit f0e8686

File tree

1 file changed

+6
-13
lines changed
  • packages/opencode/src/cli/cmd/tui/routes/session

1 file changed

+6
-13
lines changed

packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,10 +1200,9 @@ function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; las
12001200
if (!final()) return 0
12011201
if (!props.message.time.completed) return 0
12021202
if (!(sync.data.config.tui as any)?.display_message_tps) return 0
1203-
1204-
const assistantMessages : AssistantMessage[] = messages().filter((msg) => msg.role === "assistant" && msg.id !== props.message.id) as AssistantMessage[]
12051203

1206-
const allParts = assistantMessages.flatMap((msg) => getParts(msg.id))
1204+
// Get parts for the current message only
1205+
const allParts = getParts(props.message.id)
12071206

12081207
const INVALID_REASONING_TEXTS = ["[REDACTED]", "", null, undefined] as const
12091208

@@ -1240,17 +1239,11 @@ function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; las
12401239
}
12411240

12421241
if (totalStreamingTimeMs === 0) return 0
1243-
1244-
const totals = assistantMessages.reduce(
1245-
(acc, m) => {
1246-
acc.output += m.tokens.output
1247-
if (hasValidReasoning) acc.reasoning += m.tokens.reasoning // Only count reasoning tokens if valid reasoning parts exists
1248-
return acc
1249-
},
1250-
{ output: 0, reasoning: 0 },
1251-
)
12521242

1253-
const totalTokens = totals.reasoning + totals.output
1243+
// Use token counts from the current message
1244+
const outputTokens = props.message.tokens.output
1245+
const reasoningTokens = hasValidReasoning ? props.message.tokens.reasoning : 0
1246+
const totalTokens = outputTokens + reasoningTokens
12541247

12551248
if (totalTokens === 0) return 0
12561249

0 commit comments

Comments
 (0)