ReplyPreviewTool
SUPPORT · interface · 类型合同
Capability declaration used to derive preview rules.
Omitted preview means the capability never previews, so previewing is an explicit opt-in.
导入
ts
import type { ReplyPreviewTool } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').ReplyPreviewTool} ReplyPreviewTool */其他公开入口:@jangts/agent-core/support、@jangts/agent-core/support/model。
定义
ts
interface ReplyPreviewTool字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
id | string | 必需 | 只读。Capability ID, which must equal the native function wire name used for transport. |
jsonSchema | Readonly<Record<string, unknown>> | 必需 | 只读。Input schema used to prove that preview and eligibility paths really exist. |
preview | true | Omit<ReplyPreviewRule, "stageId" | "toolId"> | undefined | 可省略 | 只读。Explicit preview opt-in: true uses the default text/bubble paths, an object narrows the paths and eligibility, and omission means the capability never previews. |
使用示例
- 从 Tool 与阶段声明生成预览规则:复用实际 Schema 与阶段引用,只为明确允许展示的 Tool 生成规则。
明确标记纯文本阶段
入门 · Node.js
ts
import { Support } from '@jangts/agent-core';
const rules = Support.createReplyPreviewRules({ stages: [{ id: 'reply', preview: 'text' }], tools: [] });
const preview = Support.createReplyPreview({ rules, sink: bubbles => { console.log(bubbles); } });
console.log(typeof preview);js
import { Support } from '@jangts/agent-core';
const rules = Support.createReplyPreviewRules({ stages: [{ id: 'reply', preview: 'text' }], tools: [] });
const preview = Support.createReplyPreview({ rules, sink: bubbles => { console.log(bubbles); } });
console.log(typeof preview);复用结构化 Tool 的 Schema 与阶段引用
配置 · Node.js
真实 App 应从它已经登记的 Tool 和阶段声明投影这两个数组;本例用最小静态资料展示所需字段。
ts
import { Support } from '@jangts/agent-core';
const tools = [{ id: 'reply', jsonSchema: { type: 'object', properties: { answer: { type: 'string' } } },
preview: { paths: [['answer']] } }];
const rules = Support.createReplyPreviewRules({
stages: [{ id: 'respond', toolIds: ['reply'], preview: 'tools' }], tools,
});
const preview = Support.createReplyPreview({ rules, sink: bubbles => { console.log(bubbles); } });
console.log(rules, typeof preview);js
import { Support } from '@jangts/agent-core';
const tools = [{ id: 'reply', jsonSchema: { type: 'object', properties: { answer: { type: 'string' } } },
preview: { paths: [['answer']] } }];
const rules = Support.createReplyPreviewRules({
stages: [{ id: 'respond', toolIds: ['reply'], preview: 'tools' }], tools,
});
const preview = Support.createReplyPreview({ rules, sink: bubbles => { console.log(bubbles); } });
console.log(rules, typeof preview);