ReplyPreviewRule
SUPPORT · interface · 类型合同
One projection rule: which stage/capability it matches and which prose fields may be shown.
A rule without toolId may only match a registered plain-text stage.
导入
ts
import type { ReplyPreviewRule } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').ReplyPreviewRule} ReplyPreviewRule */其他公开入口:@jangts/agent-core/support。
定义
ts
interface ReplyPreviewRule字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
toolId | string | undefined | 可省略 | Native function wire name. Omit only for a registered plain-text stage. |
stageId | string | undefined | 可省略 | Restrict the rule to one stage; omitted matches any stage producing this capability. |
paths | readonly (readonly string[])[] | undefined | 可省略 | JSON paths to project, where * matches any array index; defaults to text/bubble paths. |
when | { path: readonly string[]; values: readonly string[]; } | undefined | 可省略 | Presentation eligibility from a complete string field in the same proposal. |
使用示例
- 正文预览:有序输出,不代替最终接受:按已登记的 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);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);只允许明确正文协议的可展示字段
配置 · 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);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);