Chat: show the model's thinking while a turn streams #1907

Closed
opened 2026-11-12 12:27:07 +00:00 by sam · 1 comment
Owner

While a turn streams, the dashboard shows only a static Thinking indicator. The gateway drops the model's reasoning when it reads the ai-sdk stream (ReasoningPart is never forwarded). Surface reasoning deltas end to end: a reasoning event on the gateway chat stream, carried through the dashboard SSE stream, rendered in the chat bubble as a collapsible trace like the agent transcript already renders reasoning.

While a turn streams, the dashboard shows only a static Thinking indicator. The gateway drops the model's reasoning when it reads the ai-sdk stream (ReasoningPart is never forwarded). Surface reasoning deltas end to end: a reasoning event on the gateway chat stream, carried through the dashboard SSE stream, rendered in the chat bubble as a collapsible trace like the agent transcript already renders reasoning.
sam self-assigned this 2026-11-12 13:22:56 +00:00
Author
Owner

Streamed model thinking now surfaces end to end. PR: #1910 (branch feat/1907-chat-thinking)

Gateway (ff8615b09):

  • internal/gateway/stream.go: the ai-sdk FullStream drain moved here from the archiegateway composition as DrainStreamParts, next to the TurnStream it feeds; new reasoning-delta case forwards each delta on the new optional ReasoningStream method. toolCallRecorder passes it through.
  • internal/gateway/chat_local.go: localChatStream.Reasoning emits ChatEvent{Kind: "reasoning", Text: delta} on the same stream. done/error semantics unchanged; the FullStream is still drained to close with no stream attached.
  • internal/app/archiegateway/chat_setup.go: one call site now calls gateway.DrainStreamParts (the drain was only reachable there; moving it is what lets the gateway own and test the forwarding).
  • internal/webui needed no change: handleChatStream's default branch already forwards any event kind with its text as an SSE frame (verified by reading the switch).

UI (433ea390a):

  • ui/src/chat/state.ts: reasoning frames accumulate into streamingTurn.reasoning alongside delta.
  • ui/src/chat/ChatThinking.vue (new) + ChatTranscript.vue + ChatBubble.vue: the live row renders thinking as a collapsible "Thinking" trace from the components/ui trace/collapsible pattern (same as AgentTranscript), spinning icon + shimmering title while no reasoning text has arrived yet; nothing renders when the model emits no reasoning; reasoning never enters the reply text. Keyboard/a11y come from the Collapsible trigger (button, focus ring).

Tests:

  • internal/gateway/chat_stream_test.go: table-driven fake SDK stream; reasoning deltas become Kind "reasoning" ChatEvents, text deltas and tool results still work, nil stream still drains. Failed pre-fix (undefined DrainStreamParts), passes now.
  • ui/test/chat-thinking.test.ts: drives the real sendMessage frame loop over a stubbed SSE stream (resolve hook stubs @/lib/api and @/router). Fails on the pre-fix state.ts, passes now.

Commands run on this exact tree: go test -short ./internal/gateway/... ./internal/app/archiegateway/... ./internal/domain/messaging/... (ok), pnpm test (105 pass), pnpm run typecheck (clean), pnpm run build (ok), task check (pass).

Not verified: a live browser check of a streaming turn with a real provider (this environment has no configured model provider / full stack), so the rendered live-thinking row was not eyeballed in a browser. The SSE frame shape was verified against internal/webui/chat.go and the UI frame handling is covered by the node test.

Streamed model thinking now surfaces end to end. PR: https://git.catlow.cloud/sam/archie/pulls/1910 (branch feat/1907-chat-thinking) Gateway (ff8615b09): - internal/gateway/stream.go: the ai-sdk FullStream drain moved here from the archiegateway composition as `DrainStreamParts`, next to the TurnStream it feeds; new `reasoning-delta` case forwards each delta on the new optional `ReasoningStream` method. `toolCallRecorder` passes it through. - internal/gateway/chat_local.go: `localChatStream.Reasoning` emits `ChatEvent{Kind: "reasoning", Text: delta}` on the same stream. done/error semantics unchanged; the FullStream is still drained to close with no stream attached. - internal/app/archiegateway/chat_setup.go: one call site now calls `gateway.DrainStreamParts` (the drain was only reachable there; moving it is what lets the gateway own and test the forwarding). - internal/webui needed no change: handleChatStream's default branch already forwards any event kind with its text as an SSE frame (verified by reading the switch). UI (433ea390a): - ui/src/chat/state.ts: `reasoning` frames accumulate into `streamingTurn.reasoning` alongside `delta`. - ui/src/chat/ChatThinking.vue (new) + ChatTranscript.vue + ChatBubble.vue: the live row renders thinking as a collapsible "Thinking" trace from the components/ui trace/collapsible pattern (same as AgentTranscript), spinning icon + shimmering title while no reasoning text has arrived yet; nothing renders when the model emits no reasoning; reasoning never enters the reply text. Keyboard/a11y come from the Collapsible trigger (button, focus ring). Tests: - internal/gateway/chat_stream_test.go: table-driven fake SDK stream; reasoning deltas become Kind "reasoning" ChatEvents, text deltas and tool results still work, nil stream still drains. Failed pre-fix (undefined DrainStreamParts), passes now. - ui/test/chat-thinking.test.ts: drives the real sendMessage frame loop over a stubbed SSE stream (resolve hook stubs @/lib/api and @/router). Fails on the pre-fix state.ts, passes now. Commands run on this exact tree: `go test -short ./internal/gateway/... ./internal/app/archiegateway/... ./internal/domain/messaging/...` (ok), `pnpm test` (105 pass), `pnpm run typecheck` (clean), `pnpm run build` (ok), `task check` (pass). Not verified: a live browser check of a streaming turn with a real provider (this environment has no configured model provider / full stack), so the rendered live-thinking row was not eyeballed in a browser. The SSE frame shape was verified against internal/webui/chat.go and the UI frame handling is covered by the node test.
sam closed this issue 2026-11-12 13:45:42 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#1907