feat(chat): unify QuickChat backend path and consolidate render toggle

Backend
- chat.ts now routes both regular chat and QuickChat through
  createResolvedAgentSession instead of branching to createFnAgent for
  the no-runtime-hint case. This removes the divergent path where
  pi-ai's cleanupSessionResources(sessionId) could tear down resources
  the next generation depends on.
- sendMessage's finally only disposes the agent if it still owns the
  activeGenerations slot. A newer generation that has pre-empted us
  cleans up its own agent in its own finally — disposing here would
  yank the underlying CLI process out from under it.
- __setCreateFnAgent test helper now mirrors its mock into the
  createResolvedAgentSession slot so existing test setups still work
  after the unification.

Frontend
- Extract createChatStreamHandlers (RAF coalescing, accumulators,
  tool-call dedup, fallback handling) — useChat and useQuickChat were
  duplicating ~85 LOC each. Both now compose the shared factory.
- Move shared chat types into chatTypes.ts. The hooks re-export them
  for backward compatibility with existing consumers.
- Removed per-message Markdown/plain-text eye toggles. A single
  thread-level toggle in the chat header now flips every assistant
  bubble (including the streaming one) between rendered Markdown and
  plain text.
- Model-only chats hide the per-message agent identity row entirely;
  the model name is already in the thread header.

Tests
- Updated ChatView tests to reflect the new render-toggle contract
  (single header toggle drives all bubbles) and the model-only avatar
  suppression.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-05-05 11:04:48 -07:00
parent 02eb1c5b30
commit 32c19af7d3
9 changed files with 491 additions and 373 deletions

View File

@@ -215,10 +215,40 @@
}
.chat-thread-header-new-chat {
margin-left: auto;
flex-shrink: 0;
}
/* Single thread-wide markdown / plain-text toggle, anchored to the right of
* the header next to "New Chat". Replaces the per-message eye toggle that
* used to live inside every assistant bubble. */
.chat-thread-header-render-toggle {
margin-left: auto;
display: inline-flex;
align-items: center;
justify-content: center;
width: calc(var(--space-md) * 3);
height: calc(var(--space-md) * 3);
min-width: calc(var(--space-md) * 3);
min-height: calc(var(--space-md) * 3);
padding: 0;
border: none;
border-radius: 4px;
color: var(--text-muted);
background: transparent;
cursor: pointer;
outline: none;
transition: background var(--transition-fast), color var(--transition-fast);
}
.chat-thread-header-render-toggle:hover {
background: var(--bg-hover, var(--bg-secondary));
color: var(--text);
}
.chat-thread-header-render-toggle--plain {
color: var(--text);
}
/* Messages */
.chat-messages {
flex: 1;
@@ -262,6 +292,15 @@
color: var(--text-secondary);
}
/* Model-only chats hide the per-message agent identity. The toggle still
* needs a place to live, so collapse the avatar row to just the toggle on
* the right edge instead of a full identity strip. */
.chat-message-avatar.chat-message-avatar--toolbar-only {
margin-bottom: 0;
min-height: 0;
justify-content: flex-end;
}
.chat-message-render-toggle {
display: inline-flex;
align-items: center;