feat(chat): client + react entries — session client, reconnecting stream, useChatSession

Merged
SA
3mo ago
+1755-26

Chunk B of plans/chat-v3-pane-mount.md. ./client: reconnecting WS consumer (envelope-parsed frames, cursor resume, reset-keeps-connection, injectable backoff) + sessionClient over a structural ChatTransport typed via type-only ChatRouterInputs/Outputs — no runtime dep on chat-runtime (tsconfig-paths type bridge; avoids the turbo package cycle) and no @trpc/server in the client package. ./react: useChatSession (seed→reduce→live tail, outbox clientId-echo clearing, one commit per frame with RN-safe scheduler fallback, loadOlder with older-merges-under semantics, auto-resync on reset) + useTimeline/useApprovals. 32 tests incl. hook-level reconnect parity against a real runtime over an in-memory socket pair.

https://claude.ai/code/session_01XRFCEPsfmJHu2SenDKYJ2h


Summary by cubic

Adds a reconnecting session stream, a typed session client, and React hooks for chat sessions. This delivers reliable live updates with resume, pagination, and a simple API for apps.

  • New Features

    • @superset/chat client
      • subscribeToSession: reconnecting stream with since-cursor resume, reset handling, and configurable exponential backoff.
      • createSessionClient: typed transport over ChatRouterInputs/Outputs (no runtime dep), prompt dedupe by commandId, item pagination, approvals/mode/turn controls, and multiple managed streams.
    • @superset/chat React
      • useChatSession: seeds via getSession + getItems, batches live frames into one commit per animation frame (RN-safe timeout fallback), clears outbox on clientId echo, loads older pages, and auto-resyncs on stream reset.
      • useTimeline and useApprovals: memoized derived views of the session snapshot.
    • Testing utilities
      • In-memory stream server with drop/reconnect controls, manual wait scheduler, and DOM registrator for hook tests. 32 tests cover reconnect, pagination, and hook parity.
  • Refactors

    • @superset/chat-runtime: adds ./testing export for cross-package tests and exposes ChatRouterInputs/Outputs for client typing.
    • @superset/chat: adds ./client and ./react entry points; uses a tsconfig type-only bridge to avoid a package cycle; no @trpc/server in the client.

Summary by CodeRabbit

  • New Features

    • Added a typed chat session client for creating sessions, sending prompts, pagination, approvals, mode changes, and lifecycle management.
    • Added reliable live session subscriptions with reconnect support and stream recovery.
    • Added React hooks for managing chat sessions, pending approvals, and conversation timelines.
    • Added public package entry points for client and React integrations.
    • Added reusable testing utilities and public runtime testing exports.
  • Tests

    • Added comprehensive coverage for streaming, reconnection, pagination, approvals, timelines, and session workflows.