ReplyPreviewOptions
SUPPORT · interface · 类型合同
Settings for createReplyPreview; sink receives every bubble list and is required.
导入
ts
import type { ReplyPreviewOptions } from '@jangts/agent-core/support';1
js
/** @typedef {import('@jangts/agent-core/support').ReplyPreviewOptions} ReplyPreviewOptions */1
其他公开入口:@jangts/agent-core/support。
定义
ts
interface ReplyPreviewOptions1
继承或实现: ReplyPreviewSettings。
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
sink | (bubbles: string[]) => void | Promise<void> | 必需 | 只读。Receives the current bubble list; rejection propagates to the event caller. |
rules | readonly ReplyPreviewRule[] | 必需 | 见类型定义及调用场景。 |
render | ((text: string) => string) | undefined | 可省略 | Presentation only; must not authorize, persist or execute a proposal. |
maxChars | number | undefined | 可省略 | Streamed characters tolerated before preview is disabled; default 16000. |
成员目录
| 成员 | 用途 |
|---|---|
sink | Receives the current bubble list; rejection propagates to the event caller. |
成员详情
sink
Receives the current bubble list; rejection propagates to the event caller.
ts
ReplyPreviewOptions.sink(bubbles: string[]): void | Promise<void>1
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
bubbles | string[] | 必需 | — |
返回: void \| Promise<void>。
等待后的值: void。
使用示例
- 正文预览:有序输出,不代替最终接受:按已登记的 stage/tool/字段路径提取可展示正文,拒绝把控制提议当作已执行结果。
为纯文本阶段增加预览
入门 · Node.js
ts
import { ModelRunner, Support } from '@jangts/agent-core';
const preview = Support.createReplyPreview({ rules: [{ stageId: 'reply' }],
sink: bubbles => { console.log('preview', bubbles); },
});
const runner = new ModelRunner({ provider: { async *stream() { yield '你好'; yield ',Core'; } }, sink: { output: preview } });
console.log((await runner.invoke({ input: '你好', stageId: 'reply' })).value);1
2
3
4
5
6
2
3
4
5
6
js
import { ModelRunner, Support } from '@jangts/agent-core';
const preview = Support.createReplyPreview({ rules: [{ stageId: 'reply' }],
sink: bubbles => { console.log('preview', bubbles); },
});
const runner = new ModelRunner({ provider: { async *stream() { yield '你好'; yield ',Core'; } }, sink: { output: preview } });
console.log((await runner.invoke({ input: '你好', stageId: 'reply' })).value);1
2
3
4
5
6
2
3
4
5
6
只允许明确正文协议的可展示字段
配置 · Node.js
规则必须对应 App 实际登记的 reply Tool 与 Schema,配置预览本身不创建模型 Tool。
ts
import { Support } from '@jangts/agent-core';
const preview = Support.createReplyPreview({
rules: [{ stageId: 'reply', toolId: 'reply', paths: [['answer'], ['bubbles', '*']],
when: { path: ['kind'], values: ['reply'] } }],
sink: async bubbles => { console.log('当前暂态正文', bubbles); },
maxChars: 4000,
});
console.log(typeof preview);1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
js
import { Support } from '@jangts/agent-core';
const preview = Support.createReplyPreview({
rules: [{ stageId: 'reply', toolId: 'reply', paths: [['answer'], ['bubbles', '*']],
when: { path: ['kind'], values: ['reply'] } }],
sink: async (bubbles) => { console.log('当前暂态正文', bubbles); },
maxChars: 4000,
});
console.log(typeof preview);1
2
3
4
5
6
7
8
2
3
4
5
6
7
8