Skip to content

feat(web): show each bot chat's model and tool usage - #146

Merged
cheetahbyte merged 2 commits into
mainfrom
feat/web-chat-usage
Nov 17, 2026
Merged

cheetahbyte merged 2 commits into
mainfrom
feat/web-chat-usage

Conversation

@lauragarden

Copy link
Copy Markdown
Contributor

Summary

A bot's details panel in the web chat has a Usage section listing the tokens and cost of each model and tool its bot chat has used, with a total. The job pane's cost now includes the tools bucket too.

DetailsBody
└── ChatUsage (bot-chat/chat-usage.tsx)   reads chatQuery(botId).data.usage, kept live by the snapshot stream
    └── usageRows / costLine / formatTokens (chat/usage.ts)
JobPane subtitle ── costLine (same helper, previously models only)
  • Contract: usageDocument (contract/tool-details.ts) now reads totalTokens and the tools bucket. This is a client-side parser only. The snapshot's usage stays unknown in the OpenAPI spec, so the API doesn't change.
  • Web: usage.ts replaces costLine in jobs.tsx. Models show by model ID, tools by name with "(tool)", and tokens use the compact format ("12K tokens"). A zero cost isn't shown, as before. The section shows "No usage yet" before the first request.
  • jobs.test.ts moved to chat/usage.test.ts with the helper.

Closes #105

Why

Chat usage, including vision model costs, reached the chat snapshot API, but the web showed none of it. The job pane's cost left out the tools bucket, where intent-check costs are recorded.

Evidence

  • bun run check passes on the branch: lint, format, typecheck, openapi:check, and 1318 tests, 0 failing. The apps/docs check passes.
  • New usage.test.ts case: costLine counts the tools bucket ($3.0000 for one model and one tool at $1.50 each; the old costLine returned $1.5000). Further cases cover row order, a document that doesn't parse, and token formatting.
  • New chat-usage.dom.test.tsx: rows with tokens, cost, and total; tokens without a cost for a provider that reports zero; "No usage yet".
  • Not checked by hand: the section in a browser, and live updates during a turn.

Risk and rollback

Reversibility: Reversible.

Blast radius: The web bot details panel and sheet, and the cost in the job pane subtitle.

  • Jobs that used tools with their own cost now show a higher total in the job pane than before.
  • Usage covers the bot chat's own conversation only; the section says that jobs have their own usage.

A bot's details list the tokens and cost of every model and tool its bot
chat has used, with a total. Job panes now include the tools bucket in
their cost.

Closes #105
@lauragarden lauragarden self-assigned this Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

React Doctor found 1 new issue in 1 file · 1 warning · score 85 / 100 (Great) · 0 fixed · vs main

1 warning

features/bot-chat/chat-usage.tsx

  • ⚠️ L53 Number before && renders stray 0 rendering-conditional-render

Reviewed by React Doctor for commit d994d87. See inline comments for fixes.

<Row key={`${row.kind}:${row.name}`} row={row} />
))}
</ul>
{total && (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React Doctor · react-doctor/rendering-conditional-render (warning)

Your users see a stray '0' on screen when a number before && is zero, so use value > 0, Boolean(value), or a ternary instead.

Fix → Use {items.length > 0 && <List />}, or a ternary like {items.length ? <List /> : null}.

Docs

@cheetahbyte
cheetahbyte merged commit 2f5b9ef into main Nov 17, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show each chat's model and tool usage in the web chat

2 participants