SseReadOptions
CORE · type · Type contract
Per-read configuration; snapshotted when readSse starts.
Import
ts
import type { SseReadOptions } from '@jangts/agent-core/sse';1
js
/** @typedef {import('@jangts/agent-core/sse').SseReadOptions} SseReadOptions */1
Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/sse, @jangts/agent-core/support.
Definition
Type: SseReadOptions
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
signal | AbortSignal | undefined | Optional | Cancels the pending read and any later read from the same stream. |
idleTimeoutMs | number | undefined | Optional | Maximum silence between chunks in milliseconds; omitted or <= 0 disables the timer. |
waitForCancel | boolean | undefined | Optional | Await reader.cancel() before returning. false lets browser adapters skip the wait. |
Examples
- SSE, JSON frames, and bounded event streams: Reuse transport mechanics while preserving cancellation and backpressure; protocol parsing and business validation remain separate.
- Support: the aggregate entry for recommended usage: Support aggregates recommended construction, policies, and same-source configuration generation; Core execution does not depend on this namespace.
Parse one SSE frame locally
Beginner · Node.js
ts
import { Support } from '@jangts/agent-core';
const frame = Support.encodeSseEvent({ event: 'status', data: JSON.stringify({ phase: 'thinking' }) });
const body = new Response(frame).body!;
for await (const event of Support.readSse(body)) console.log(event.event, event.data);1
2
3
4
2
3
4
js
import { Support } from '@jangts/agent-core';
const frame = Support.encodeSseEvent({ event: 'status', data: JSON.stringify({ phase: 'thinking' }) });
const body = new Response(frame).body;
for await (const event of Support.readSse(body))
console.log(event.event, event.data);1
2
3
4
5
2
3
4
5
Producer waits for each event delivery
Configuration · Node.js
ts
import { Support } from '@jangts/agent-core';
const signal = new AbortController().signal;
const stream = Support.streamEvents<{ phase: string }>(async emit => {
await emit({ phase: 'preparing' });
await emit({ phase: 'complete' });
}, { signal });
for await (const event of stream) console.log(event.phase);1
2
3
4
5
6
7
2
3
4
5
6
7
js
import { Support } from '@jangts/agent-core';
const signal = new AbortController().signal;
const stream = Support.streamEvents(async (emit) => {
await emit({ phase: 'preparing' });
await emit({ phase: 'complete' });
}, { signal });
for await (const event of stream)
console.log(event.phase);1
2
3
4
5
6
7
8
2
3
4
5
6
7
8