Skip to content
中文

textOutputEvents ​

KIT · function · Runtime value

Wrap already-chunked text as text events.

Import ​

ts
import { textOutputEvents } from '@jangts/agent-core/events';
js
import { textOutputEvents } 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
textOutputEvents(chunks: AsyncIterable<string>): AsyncIterable<AgentOutputEvent>

Wrap already-chunked text as text events.

ParameterTypePassingDescription
chunksAsyncIterable<string>Required—

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.