Skip to content
中文

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 ​

ts
import { publishReplyEvents } from '@jangts/agent-core/events';
js
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 ​

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.

ParameterTypePassingDescription
request{ text: string; delivery?: ReplyDeliveryOptions; }Required—
contextExecutionContextRequired—
Fields of request
FieldTypeRequiredDescription
textstringRequiredSee the type definition and usage context.
deliveryReplyDeliveryOptions | undefinedOptionalSee the type definition and usage context.
Fields of context
FieldTypeRequiredDescription
loggerSubFlowLog | undefinedOptionalRead-only. Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignalRequiredRead-only. Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Diagnostic scope of the enclosing call, when recording is enabled.

Returns: AsyncIterable<AgentOutputEvent>.

Examples ​

First output a reply that is already accepted ​

Beginner · 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);

Add chunking and bubbles to the same event entry ​

Configuration · 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');
}

Convert an existing text stream within the same contract ​

Extension · 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);

API reference, usage examples and developer guides.