Skip to content
English

SseReadOptions ​

CORE · type · 类型合同

Per-read configuration; snapshotted when readSse starts.

导入 ​

ts
import type { SseReadOptions } from '@jangts/agent-core/sse';
js
/** @typedef {import('@jangts/agent-core/sse').SseReadOptions} SseReadOptions */

其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/sse、@jangts/agent-core/support。

定义 ​

类型: SseReadOptions

字段结构 ​

字段类型必需说明
signalAbortSignal | undefined可省略Cancels the pending read and any later read from the same stream.
idleTimeoutMsnumber | undefined可省略Maximum silence between chunks in milliseconds; omitted or <= 0 disables the timer.
waitForCancelboolean | undefined可省略Await reader.cancel() before returning. false lets browser adapters skip the wait.

使用示例 ​

在本地解析一帧 SSE ​

入门 · 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);
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);

生产者等待每一次事件交付 ​

配置 · 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);
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);

相关策略源码 ​

接口参考、使用示例与开发指南。