feat(tui): show tokens per second in the response footer - #46108
Open
iceteaSA wants to merge 1 commit into
Open
Conversation
Upstream PR anomalyco#12721 by @JohnC0de, reimplemented against the current TUI. The tokens-per-second formula and its validity guards are theirs; that PR targeted `packages/opencode/src/cli/cmd/tui/routes/session/`, which no longer exists, so this reimplements the feature against `packages/tui/` and adds the `time.firstToken` stamp the calculation needs. Co-authored-by: João Carlos Magalhães de Castro <88864312+JohnC0de@users.noreply.github.com>
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Related PRs Found#12721 - feat(tui): add tokens per second to response footer
#42372 - feat(app): show tokens-per-second in context usage indicator
The PR description explicitly acknowledges these relationships and indicates that #12721 should take precedence if rebased. The current PR (#46108) is a cleaner implementation of the same design on a current branch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #6096
Type of change
Credit
This is @JohnC0de's #12721 rebased onto current
dev— same design (TPS calc incore/so non-TUI consumers can use it,firstTokenrecorded inprocessor.ts, sub-250ms/tool/errored turns filtered out), which is itself a clean take on @edlsh's #5497. #12721 only went stale — it'sdirtyagainstdevnow. If @JohnC0de rebases it, theirs should land and I'll close this. Take anything from here that helps.What does this PR do?
Adds a
tok/sreadout to the assistant footer, after the duration:18.3s · 131 tok/s.processor.tsstampstime.firstTokenon the first streamed token (tool-only turns included). TPS isgeneratedTokens / ((completed − firstToken) / 1000), output plus reasoning. The calc lives inpackages/core/src/session/tokens.tsso the SDK can reuse it;firstTokenis optional on the message schema and persisted, so a session-level average can come later without a migration.How did you verify your code works?
The timestamp guard is compiler-enforced, not test-enforced: delete the narrowing and it's a type error (
'completed' is possibly 'undefined'). The zero-token, sub-threshold, and rounding guards each go red when reverted.packages/coreTPS tests: 22 pass / 0 failpackages/opencodefull suite: 3396 pass / 0 failbun typecheckclean inopencode,core,tuiScreenshots / recordings
Footer gains a
· NN tok/ssegment; no new surface.Checklist