Skip to content
English

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

字段结构 ​

字段类型必需说明
toolIdstring | undefined可省略Native function wire name. Omit only for a registered plain-text stage.
stageIdstring | undefined可省略Restrict the rule to one stage; omitted matches any stage producing this capability.
pathsreadonly (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.

使用示例 ​

为纯文本阶段增加预览 ​

入门 · 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);

接口参考、使用示例与开发指南。