Sse
A reusable Server-Sent Events client over fetch (an
EventSource can't POST a JSON body), mirroring apiFetch (profile header,
ApiError). Each data: frame is JSON; a named error event aborts
with an ApiError, and the stream ends on the done event.
Interfaces¶
SSEHandlers¶
Defined in: src/shared/api/sse.ts:12
Per-frame callbacks for a streamed response.
Properties¶
| Property | Type | Description | Defined in |
|---|---|---|---|
onEvent? |
(event, dataJson) => void |
A named non-data event (e.g. breakdown's focus), with its JSON data. |
src/shared/api/sse.ts:16 |
onToken |
(token) => void |
A decoded text chunk of the answer. | src/shared/api/sse.ts:14 |
Functions¶
streamSSE()¶
Defined in: src/shared/api/sse.ts:30
POSTs body and streams the Server-Sent Events response, invoking the
handlers per frame until the terminal done event.
Parameters¶
| Parameter | Type | Description |
|---|---|---|
url |
string |
The relative API path. |
body |
unknown |
The JSON request body. |
handlers |
SSEHandlers |
Per-frame callbacks. |
signal? |
AbortSignal |
Aborts the stream. |
Returns¶
Promise\<void>
Resolves at the done event.
Throws¶
On a non-2xx response or a streamed error event.