Skip to content

feat(narratives): stopped-turn UX, reasoning polish, token-usage readout#425

Open
ddebasmita-lab wants to merge 3 commits into
datacommonsorg:mainfrom
ddebasmita-lab:narratives-reasoning-token-usage
Open

feat(narratives): stopped-turn UX, reasoning polish, token-usage readout#425
ddebasmita-lab wants to merge 3 commits into
datacommonsorg:mainfrom
ddebasmita-lab:narratives-reasoning-token-usage

Conversation

@ddebasmita-lab

Copy link
Copy Markdown
Contributor

Overview

Follow-up UI chunk for the narratives Data Agent, bringing the remaining
front-end refinements into the repo. No backend/build-config changes.

Changes made

  • Stopped-turn UX: when the user clicks Stop mid-stream, the half-finished
    reasoning/answer is replaced with a "Stopped per your request" note instead
    of leaving truncated chrome (data_agent.tsx, block_reasoning.tsx).
  • Reasoning-aside polish: the reasoning section reads as a muted aside with
    a left bar; heading styling and spacing refined (block_reasoning.tsx).
  • Mobile drawer nav refinements to the session drawer (drawer_session.tsx).
  • Token-usage readout (debug-only): a Tokens IN / OUT / Total block in the
    header, shown only when the page is opened with ?debug=tokens. It reads
    an optional usage SSE event; off by default and invisible to normal users.
    Temporary instrumentation for gauging per-query cost (header.tsx,
    use_sse_chat.ts).

Testing done

  • npm run lint (tsc --noEmit, strict) — clean.
  • npm run build (vite) — clean.
  • npm test (vitest) — passing.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the chat interface by styling the reasoning block with a continuous left bar, adding section navigation to the mobile drawer, introducing a temporary token-usage readout in the header, and handling stopped turns gracefully. The reviewer identified a critical issue where stopped turns are not filtered from the chat history, potentially causing Gemini API crashes due to consecutive user messages. Additionally, feedback was provided regarding visual bugs with nested list borders in the reasoning block and the anti-pattern of evaluating window.location at module load time for the token debug flag.

Comment thread narratives/src/hooks/use_sse_chat.ts
Comment thread narratives/src/components/block_reasoning.tsx
Comment thread narratives/src/components/header.tsx Outdated
…e readout

Brings the narratives UI in line with the downstream app:

- Stopped-turn handling: when the user hits Stop, replace the half-finished
  reasoning/answer with a "Stopped per your request" note (data_agent,
  block_reasoning).
- Reasoning-aside styling polish and mobile drawer nav refinements
  (block_reasoning, drawer_session).
- Optional per-query Gemini token-usage readout in the header, gated behind
  ?debug=tokens (off by default; reads a `usage` SSE event). Temporary cost
  instrumentation for measuring query cost.
@ddebasmita-lab
ddebasmita-lab force-pushed the narratives-reasoning-token-usage branch from 52fd22b to a58c936 Compare July 24, 2026 14:26
…ug flag

Address review feedback on PR:
- useSseChat: only include completed turns (not stopped/errored/empty) when
  building the Gemini history, so an aborted turn can't produce consecutive
  user messages (400 from the API).
- header: evaluate the ?debug=tokens flag per render via isTokenDebugEnabled()
  instead of once at module load (testable, SPA-reactive, SSR-safe).
Rewrite a change-narrative comment (referenced the removed ThoughtsPanel) to
describe present behavior, per the review convention that comments state what
the code does rather than what it used to do.
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.

1 participant