<!-- source-hash: c000c5cabcd81a500ce236944b8c4464 -->
Provides the SSE/Guide-mode transport adapter for the unified chat surface, implementing `UnifiedChatState` by consuming server-sent events from the chat stream endpoint and mapping them into structured `DocChatMessage` segments, sources, refs, and per-turn metadata.

## Key Components

| Export | Type | Description |
|--------|------|-------------|
| `useSseChatAdapter` | Hook | Primary hook — reads `source` from runtime context, manages SSE stream lifecycle, slash commands, and turn metadata |
| `DocChatMessage` | Interface | Full message shape including `segments`, `sources`, `chatRefs`, and `scrollAnchor` |
| `ChatSource` | Interface | Per-citation source descriptor with support for single-row and grouped chips |
| `ChatTurnMeta` | Interface | Per-turn LLM metadata (provider, token counts, cache hit rate, routing decision) |
| `UseSseChatAdapterOptions` | Interface | DI options — primarily `tableIdForDocumentType` override for non-standard RAG table configs |
| `StreamingPhase` | Type (re-export) | Streaming lifecycle phase, re-exported from `unified-chat-state.types` for backward compatibility |
| `createDocStreamFn` | Internal factory | Builds the per-call async generator that POSTs to the SSE endpoint and yields `MessageSegment` chunks |

## Usage Example

```typescript
import { useSseChatAdapter } from './use-sse-chat-adapter'

// Basic — tableIdForDocumentType defaults to the lib-baked map
const chatState = useSseChatAdapter()

// With custom document type registry (per-tenant override)
const chatState = useSseChatAdapter({
  tableIdForDocumentType: (docType) =>
    myTenantRegistry[docType] ?? null,
})

// Consume the returned UnifiedChatState
const { messages, sendMessage, isStreaming, streamingPhase } = chatState
```

> **Note:** `source` is read automatically from `ChatRuntimeContext` — no parameter needed. It is optional: an empty `source` falls back to a stable constant (`DEFAULT_CHAT_SOURCE`) for the localStorage history namespace and is never sent on the wire (the hub resolves source server-side).