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.
createReplyPreview accepts rules, sink, optional render, and maxChars, and returns a handler for ModelRunner.sink.output. Rules define the transient display scope: which stages, which tool, and which body paths may be shown.
The preview receives a model stream that has not been fully validated, so it must not be used to execute tools, approve write operations, or persist the final reply. A failed model.end revokes the preview. The sink awaits in order and propagates failures; do not mistakenly write it as a side-channel observer that ignores Promises. render is synchronous, and rules and receivers are fixed at creation time.
Progressive examples for the same business case
Add a preview for a plain-text stage
Beginner · Node.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);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.
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);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);