ReplyPreviewRule
SUPPORT · interface · Type contract
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.
Import
ts
import type { ReplyPreviewRule } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').ReplyPreviewRule} ReplyPreviewRule */Other public entry points:@jangts/agent-core/support.
Definition
ts
interface ReplyPreviewRuleField structure
| Field | Type | Required | Description |
|---|---|---|---|
toolId | string | undefined | Optional | Native function wire name. Omit only for a registered plain-text stage. |
stageId | string | undefined | Optional | Restrict the rule to one stage; omitted matches any stage producing this capability. |
paths | readonly (readonly string[])[] | undefined | Optional | JSON paths to project, where * matches any array index; defaults to text/bubble paths. |
when | { path: readonly string[]; values: readonly string[]; } | undefined | Optional | Presentation eligibility from a complete string field in the same proposal. |
Examples
- Body preview: ordered output is not final acceptance: Extract displayable body text by registered stage/tool/field path, and refuse to treat control proposals as executed results.
Add a preview for a plain-text stage
Beginner · 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);Allow only displayable fields of an explicit body protocol
Configuration · Node.js
Rules must correspond to the reply tool and Schema the App actually registers; configuring a preview does not create a model 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);