AgentOutputEvent
KIT · type · 类型合同
One output event of a delivered reply.
导入
ts
import type { AgentOutputEvent } from '@jangts/agent-core/events';js
/** @typedef {import('@jangts/agent-core/events').AgentOutputEvent} AgentOutputEvent */其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/events、@jangts/agent-core/kits/presentation、@jangts/agent-core/kits。
定义
类型: AgentOutputEvent
类型表达式
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' };联合分支结构
AgentOutputEvent的可选结构: 选择其中一种结构,各分支的字段要求分别列出。
分支 1
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
type | "text" | 必需 | 见类型定义及调用场景。 |
text | string | 必需 | 见类型定义及调用场景。 |
分支 2
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
type | "preview" | 必需 | 见类型定义及调用场景。 |
bubbles | string[] | 必需 | 见类型定义及调用场景。 |
分支 3
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
type | "replace" | 必需 | 见类型定义及调用场景。 |
text | string | 必需 | 见类型定义及调用场景。 |
分支 4
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
type | "bubble" | 必需 | 见类型定义及调用场景。 |
使用示例
- Presentation:字段所有权与最终输出:模型只填写被分配的字段;固定文字、绑定值和语义键由程序拥有。
- 答复事件:文本分片和气泡边界:把已经接受的答复变成可等待的文本/气泡事件,保留取消和交付背压。
先组合一段生成文本
入门 · 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);相同 compose 让程序持有说明前缀
配置 · 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);