-
-
Notifications
You must be signed in to change notification settings - Fork 96
feat: show message info on click #2802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
esokullu
merged 7 commits into
webbrain-one:main
from
alectimison-maker:feat/message-info-pills
Aug 16, 2026
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d537fd3
feat: show message info on click
alectimison-maker 0494b09
fix: avoid misleading message metadata
alectimison-maker 5b116dc
fix(message-info): pass endedAt through synthesized run_complete on r…
alectimison-maker aafa249
fix(message-info): propagate streamed finish reasons and expose a sem…
alectimison-maker e7dd541
Fix message info streaming and accessibility
esokullu f771bf6
Merge concurrent message-info fixes
esokullu a6bf43b
Merge main into message info
esokullu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| function formatSentTime(createdAt, locale) { | ||
| const value = Number(createdAt); | ||
| if (!Number.isFinite(value) || value <= 0) return ''; | ||
| try { | ||
| return new Intl.DateTimeFormat(locale || undefined, { | ||
| year: 'numeric', | ||
| month: '2-digit', | ||
| day: '2-digit', | ||
| hour: '2-digit', | ||
| minute: '2-digit', | ||
| hour12: false, | ||
| timeZone: 'UTC', | ||
| timeZoneName: 'short', | ||
| }).format(new Date(value)); | ||
| } catch { | ||
| return new Date(value).toISOString().replace('T', ' ').slice(0, 16) + ' UTC'; | ||
| } | ||
| } | ||
|
|
||
| function firstPositiveInteger(...values) { | ||
| for (const value of values) { | ||
| const number = Number(value); | ||
| if (Number.isFinite(number) && number > 0) return Math.floor(number); | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| function finishReason(result) { | ||
| const raw = result?.raw || {}; | ||
| return String( | ||
| result?.finishReason | ||
| ?? raw?.choices?.[0]?.finish_reason | ||
| ?? raw?.stop_reason | ||
| ?? raw?.stopReason | ||
| ?? '', | ||
| ).replace(/[\u0000-\u001f\u007f]/g, '').trim().slice(0, 80); | ||
| } | ||
|
|
||
| function formatNumber(value, locale, maximumFractionDigits = 0) { | ||
| try { | ||
| return new Intl.NumberFormat(locale || undefined, { | ||
| maximumFractionDigits, | ||
| }).format(value); | ||
| } catch { | ||
| return Number(value).toFixed(maximumFractionDigits).replace(/\.0+$/, ''); | ||
| } | ||
| } | ||
|
|
||
| export function aggregateMessageCompletion(current, result, durationMs) { | ||
| const previous = current || {}; | ||
| const usage = result?.usage || {}; | ||
| const inputTokens = firstPositiveInteger( | ||
| usage.prompt_tokens, | ||
| usage.input_tokens, | ||
| usage.promptTokens, | ||
| usage.inputTokens, | ||
| ); | ||
| const outputTokens = firstPositiveInteger( | ||
| usage.completion_tokens, | ||
| usage.output_tokens, | ||
| usage.completionTokens, | ||
| usage.outputTokens, | ||
| ); | ||
| const reportedTotal = firstPositiveInteger(usage.total_tokens, usage.totalTokens); | ||
| const elapsed = Number(durationMs); | ||
| return { | ||
| inputTokens: firstPositiveInteger(previous.inputTokens) + inputTokens, | ||
| outputTokens: firstPositiveInteger(previous.outputTokens) + outputTokens, | ||
| totalTokens: firstPositiveInteger(previous.totalTokens) + (reportedTotal || inputTokens + outputTokens), | ||
| durationMs: firstPositiveInteger(previous.durationMs) + (Number.isFinite(elapsed) && elapsed > 0 ? Math.round(elapsed) : 0), | ||
| finishReason: finishReason(result) || String(previous.finishReason || '').slice(0, 80), | ||
| }; | ||
| } | ||
|
|
||
| export function buildMessageInfoPills({ createdAt, completion = {}, verbose = false, locale } = {}) { | ||
| const time = formatSentTime(createdAt, locale); | ||
| if (!time) return []; | ||
| const pills = [{ | ||
| kind: 'sent', | ||
| key: 'sp.message_info.sent', | ||
| params: { time }, | ||
| }]; | ||
| if (!verbose) return pills; | ||
| const outputTokens = firstPositiveInteger(completion.outputTokens); | ||
| const displayedTokens = outputTokens || firstPositiveInteger(completion.totalTokens); | ||
| const durationMs = firstPositiveInteger(completion.durationMs); | ||
| if (outputTokens && durationMs) { | ||
| pills.push({ | ||
| kind: 'speed', | ||
| key: 'sp.message_info.speed', | ||
| params: { rate: formatNumber((outputTokens * 1000) / durationMs, locale, 2) }, | ||
| }); | ||
| } | ||
| if (displayedTokens) { | ||
| pills.push({ | ||
| kind: 'tokens', | ||
| key: 'sp.message_info.tokens', | ||
| params: { count: formatNumber(displayedTokens, locale) }, | ||
| }); | ||
| } | ||
| if (durationMs) { | ||
| pills.push({ | ||
| kind: 'duration', | ||
| key: 'sp.message_info.duration', | ||
| params: { seconds: formatNumber(durationMs / 1000, locale, 2) }, | ||
| }); | ||
| } | ||
| const reason = String(completion.finishReason || '').trim().slice(0, 80); | ||
| if (reason) { | ||
| pills.push({ | ||
| kind: 'finish', | ||
| key: 'sp.message_info.finish', | ||
| params: { reason }, | ||
| }); | ||
| } | ||
| return pills; | ||
| } |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in aafa249. The collector in
_chatStreamWithCostAllowancenow preserves the terminal reason from the providerdonechunk (and itsrawpayload when present) and passes it into the result, soaggregateMessageCompletioncan readresult.finishReasoninstead of always receiving an empty reason on the primary streaming Ask path. The streaming providers that actually observe a terminal reason (OpenAI Chat Completionschoice.finish_reason, Anthropicmessage_delta.delta.stop_reason, llama.cpp / Azurechoice.finish_reason, BedrockstopReason) now attach it to theirdonechunk. The Responses API has no per-generation stop reason, and the aggregation test already treats lifecyclestatusas not-a-reason, so no value is fabricated there. Verified:node test/run.js1755 passed.