Skip to content
中文

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 ​

ts
import { createReplyPreview } from '@jangts/agent-core/support';
js
import { createReplyPreview } from '@jangts/agent-core/support';

Other public entry points:@jangts/agent-core/support.

Definition ​

Call ​

ts
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.

ParameterTypePassingDescription
optionsReplyPreviewOptionsRequired—
Fields of options
FieldTypeRequiredDescription
sink(bubbles: string[]) => void | Promise<void>RequiredRead-only. Receives the current bubble list; rejection propagates to the event caller.
rulesreadonly ReplyPreviewRule[]RequiredSee the type definition and usage context.
render((text: string) => string) | undefinedOptionalPresentation only; must not authorize, persist or execute a proposal.
maxCharsnumber | undefinedOptionalStreamed characters tolerated before preview is disabled; default 16000.

Returns: (event: ModelOutputEvent) => Promise<void>.

Examples ​

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);

API reference, usage examples and developer guides.