publishReplyEvents
KIT · function · Runtime value
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.
Import
import { publishReplyEvents } from '@jangts/agent-core/events';import { publishReplyEvents } from '@jangts/agent-core/events';Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/events, @jangts/agent-core/kits/presentation, @jangts/agent-core/kits.
Definition
Call
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.
| Parameter | Type | Passing | Description |
|---|---|---|---|
request | { text: string; delivery?: ReplyDeliveryOptions; } | Required | — |
context | ExecutionContext | Required | — |
Fields of request
| Field | Type | Required | Description |
|---|---|---|---|
text | string | Required | See the type definition and usage context. |
delivery | ReplyDeliveryOptions | undefined | Optional | See the type definition and usage context. |
Fields of context
| Field | Type | Required | Description |
|---|---|---|---|
logger | SubFlowLog | undefined | Optional | Read-only. Explicit optional recorder for this operation; never inferred from diagnostics. |
signal | AbortSignal | Required | Read-only. Non-optional cancellation signal; never undefined once execution has started. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Diagnostic scope of the enclosing call, when recording is enabled. |
Returns: AsyncIterable<AgentOutputEvent>.
Examples
- Reply events: text chunks and bubble boundaries: Turn an accepted reply into awaitable text/bubble events while preserving cancellation and delivery backpressure.
First output a reply that is already accepted
Beginner · Node.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);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);Add chunking and bubbles to the same event entry
Configuration · Node.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');
}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');
}Convert an existing text stream within the same contract
Extension · Node.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);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);