createReplyPreview
SUPPORT · function · Runtime value
Create a model-output event handler that publishes preview bubbles.
The handler resets on model.start, ignores other invocations, disables itself on unexpected output, and clears the preview when a call ends unsuccessfully. Rules are snapshotted at creation, and only explicitly registered prose fields are projected.
Import
import { createReplyPreview } from '@jangts/agent-core/support';import { createReplyPreview } from '@jangts/agent-core/support';Other public entry points:@jangts/agent-core/support.
Definition
Call
createReplyPreview(options: ReplyPreviewOptions): (event: ModelOutputEvent) => Promise<void>Create a model-output event handler that publishes preview bubbles.
The handler resets on model.start, ignores other invocations, disables itself on unexpected output, and clears the preview when a call ends unsuccessfully. Rules are snapshotted at creation, and only explicitly registered prose fields are projected.
| Parameter | Type | Passing | Description |
|---|---|---|---|
options | ReplyPreviewOptions | Required | — |
Fields of options
| Field | Type | Required | Description |
|---|---|---|---|
sink | (bubbles: string[]) => void | Promise<void> | Required | Read-only. Receives the current bubble list; rejection propagates to the event caller. |
rules | readonly ReplyPreviewRule[] | Required | See the type definition and usage context. |
render | ((text: string) => string) | undefined | Optional | Presentation only; must not authorize, persist or execute a proposal. |
maxChars | number | undefined | Optional | Streamed characters tolerated before preview is disabled; default 16000. |
Returns: (event: ModelOutputEvent) => Promise<void>.
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
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);