Skip to content
English

publishReplyEvents ​

KIT · function · 运行时值

Stream one reply as paced text chunks and bubble separators.

Publish a validated reply without exposing its internal boundary to consumers. The pacing options are upper bounds, not exact timings: the pause and interval are clamped against maxDurationMs, so added delay never exceeds the budget while every chunk is still emitted.

导入 ​

ts
import { publishReplyEvents } from '@jangts/agent-core/events';
js
import { publishReplyEvents } from '@jangts/agent-core/events';

其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/events、@jangts/agent-core/kits/presentation、@jangts/agent-core/kits。

定义 ​

调用 ​

ts
publishReplyEvents(request: { text: string; delivery?: ReplyDeliveryOptions; }, context: ExecutionContext): AsyncIterable<AgentOutputEvent>

Stream one reply as paced text chunks and bubble separators.

Publish a validated reply without exposing its internal boundary to consumers. The pacing options are upper bounds, not exact timings: the pause and interval are clamped against maxDurationMs, so added delay never exceeds the budget while every chunk is still emitted.

参数类型传递说明
request{ text: string; delivery?: ReplyDeliveryOptions; }必需—
contextExecutionContext必需—
request 的字段
字段类型必需说明
textstring必需见类型定义及调用场景。
deliveryReplyDeliveryOptions | undefined可省略见类型定义及调用场景。
context 的字段
字段类型必需说明
loggerSubFlowLog | undefined可省略只读。Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignal必需只读。Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefined可省略只读。Diagnostic scope of the enclosing call, when recording is enabled.

返回: AsyncIterable<AgentOutputEvent>。

使用示例 ​

先输出已经接受的答复 ​

入门 · Node.js

ts
import { Presentation } from '@jangts/agent-core/kits/presentation';
const context = { signal: new AbortController().signal };
for await (const event of Presentation.publishReplyEvents({ text: '这是已经接受的答复。' }, context)) console.log(event);
js
import { Presentation } from '@jangts/agent-core/kits/presentation';
const context = { signal: new AbortController().signal };
for await (const event of Presentation.publishReplyEvents({ text: '这是已经接受的答复。' }, context))
    console.log(event);

相同事件入口增加分片与气泡 ​

配置 · Node.js

ts
import { Presentation } from '@jangts/agent-core/kits/presentation';
const text = Presentation.replyBubbleTexts({ text: '先说明定义。', bubbles: ['再解释输入输出。'] }).join(Presentation.REPLY_BUBBLE_BOUNDARY);
const events = Presentation.publishReplyEvents({ text, delivery: { chunkSize: 6, intervalMs: 10, bubblePauseMs: 30, maxDurationMs: 1000 } }, { signal: new AbortController().signal });
for await (const event of events) {
  if (event.type === 'text') process.stdout.write(event.text);
  else if (event.type === 'bubble') process.stdout.write('\n');
}
js
import { Presentation } from '@jangts/agent-core/kits/presentation';
const text = Presentation.replyBubbleTexts({ text: '先说明定义。', bubbles: ['再解释输入输出。'] }).join(Presentation.REPLY_BUBBLE_BOUNDARY);
const events = Presentation.publishReplyEvents({ text, delivery: { chunkSize: 6, intervalMs: 10, bubblePauseMs: 30, maxDurationMs: 1000 } }, { signal: new AbortController().signal });
for await (const event of events) {
    if (event.type === 'text')
        process.stdout.write(event.text);
    else if (event.type === 'bubble')
        process.stdout.write('\n');
}

在同一合同间转换已有文本流 ​

扩展 · Node.js

ts
import { Presentation } from '@jangts/agent-core/kits/presentation';
async function* chunks() { yield '已接受的'; yield '正文。'; }
const events = Presentation.textOutputEvents(chunks());
for await (const text of Presentation.serializeOutputEvents(events)) console.log(text);
js
import { Presentation } from '@jangts/agent-core/kits/presentation';
async function* chunks() { yield '已接受的'; yield '正文。'; }
const events = Presentation.textOutputEvents(chunks());
for await (const text of Presentation.serializeOutputEvents(events))
    console.log(text);

相关策略源码 ​

相关定义 ​

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