feat(chat-runtime): tRPC router over commands + WebSocket sink adapter

Merged
SA
3mo ago
+547-0

Stacked on #6167. The package now owns its transport surface: createChatRouter(runtime) (own initTRPC, procedures close over the runtime, inputs are exactly the protocol schemas, ChatRouter type exported for end-to-end inference) + createWsSink turning any structural WebSocket into a runtime Sink. Host-service's future mount = createChatRouter(runtime) at a path + wsSink per socket. 7 new tests (57 total green).

https://claude.ai/code/session_01XRFCEPsfmJHu2SenDKYJ2h


Summary by cubic

Adds a tRPC router over chat commands and a WebSocket sink adapter for streaming envelopes. The router resolves cwd on the host and returns typed tRPC errors for common failures.

  • New Features

    • Router: createChatRouter(runtime, { resolveCwd }) exposes 8 protocol commands as tRPC procedures with zod inputs from @superset/chat/protocol; exports ChatRouter, ChatRouterOptions, and createChatCallerFactory.
    • Host-resolved cwd: createSession calls resolveCwd(workspaceId); clients never send cwd.
    • Typed errors: unknown harness → BAD_REQUEST; not-running sessions → NOT_FOUND/CONFLICT; invalid inputs rejected by zod.
    • createWsSink(socket) adapts any structural WebSocket to the runtime Sink, JSON-serializes envelopes, chains/restores onclose, closes on send error, and is idempotent on peer/host close; exports WsSinkSocket.
  • Dependencies

    • Added @trpc/server@11.16.0 to packages/chat-runtime.