AgentOutputEvent
KIT · type · Type contract
One output event of a delivered reply.
Import
ts
import type { AgentOutputEvent } from '@jangts/agent-core/events';js
/** @typedef {import('@jangts/agent-core/events').AgentOutputEvent} AgentOutputEvent */Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/events, @jangts/agent-core/kits/presentation, @jangts/agent-core/kits.
Definition
Type: AgentOutputEvent
Type expression
ts
type AgentOutputEvent = | { type: 'text'; text: string }
/** Preview of the bubbles to be delivered, emitted before any text. */
| { type: 'preview'; bubbles: string[] }
/** Replaces everything delivered so far with `text`. */
| { type: 'replace'; text: string }
/** Separates the next text chunk into a new bubble. */
| { type: 'bubble' };Union branch structure
Optional shapes of AgentOutputEvent: choose one shape; required fields for each branch are listed separately.
Branch 1
| Field | Type | Required | Description |
|---|---|---|---|
type | "text" | Required | See the type definition and usage context. |
text | string | Required | See the type definition and usage context. |
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
type | "preview" | Required | See the type definition and usage context. |
bubbles | string[] | Required | See the type definition and usage context. |
Branch 3
| Field | Type | Required | Description |
|---|---|---|---|
type | "replace" | Required | See the type definition and usage context. |
text | string | Required | See the type definition and usage context. |
Branch 4
| Field | Type | Required | Description |
|---|---|---|---|
type | "bubble" | Required | See the type definition and usage context. |
Examples
- Presentation: field ownership and final output: The model fills only the fields it is assigned; fixed text, bound values, and semantic keys are owned by the program.
- Reply events: text chunks and bubble boundaries: Turn an accepted reply into awaitable text/bubble events while preserving cancellation and delivery backpressure.
First compose one piece of generated text
Beginner · Node.js
ts
import { Presentation } from '@jangts/agent-core/kits/presentation';
const outputs = Presentation.defineOutputCatalog([
{ id: 'reply', kind: 'text', fields: [{ id: 'text', owner: 'generated' }] },
]);
console.log(outputs.toModelSchema('reply'));
const output = outputs.compose({ outputId: 'reply', input: { generated: { text: '普通对象即可定义节点。' } } }, { app: {}, signal: new AbortController().signal });
console.log(output.value);js
import { Presentation } from '@jangts/agent-core/kits/presentation';
const outputs = Presentation.defineOutputCatalog([
{ id: 'reply', kind: 'text', fields: [{ id: 'text', owner: 'generated' }] },
]);
console.log(outputs.toModelSchema('reply'));
const output = outputs.compose({ outputId: 'reply', input: { generated: { text: '普通对象即可定义节点。' } } }, { app: {}, signal: new AbortController().signal });
console.log(output.value);Let the program own the explanatory prefix in the same compose
Configuration · Node.js
ts
import { Presentation } from '@jangts/agent-core/kits/presentation';
const outputs = Presentation.defineOutputCatalog([
{ id: 'reply', kind: 'master', master: '{{prefix}}{{text}}', fields: [
{ id: 'prefix', owner: 'constant', constantValue: '接口说明:' },
{ id: 'text', owner: 'generated' },
] },
]);
console.log(outputs.toModelSchema('reply')); // 只有 text 由模型填写
console.log(outputs.compose({ outputId: 'reply', input: { generated: { text: '普通对象即可定义节点。' } } }, { app: {}, signal: new AbortController().signal }).value);js
import { Presentation } from '@jangts/agent-core/kits/presentation';
const outputs = Presentation.defineOutputCatalog([
{ id: 'reply', kind: 'master', master: '{{prefix}}{{text}}', fields: [
{ id: 'prefix', owner: 'constant', constantValue: '接口说明:' },
{ id: 'text', owner: 'generated' },
] },
]);
console.log(outputs.toModelSchema('reply')); // 只有 text 由模型填写
console.log(outputs.compose({ outputId: 'reply', input: { generated: { text: '普通对象即可定义节点。' } } }, { app: {}, signal: new AbortController().signal }).value);