TextTemplateOptions
KIT · interface · Type contract
Text template construction options.
Import
ts
import type { TextTemplateOptions } from '@jangts/agent-core/kits/presentation';1
js
/** @typedef {import('@jangts/agent-core/kits/presentation').TextTemplateOptions} TextTemplateOptions */1
Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/kits/presentation, @jangts/agent-core/kits.
Definition
ts
interface TextTemplateOptions1
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
observe | ((result: string) => void | Promise<void>) | undefined | Optional | Read-only. Observer invoked with every rendered text. |
errors | { readonly missingField?: (key: string) => Error | string; } | undefined | Optional | Read-only. Builds the error for a slot the caller did not supply; receives the slot name. |
Examples
- Presentation: field ownership and final output: The model fills only the fields it is assigned; fixed text, bound values, and semantic keys are owned by the program.
- Templates, semantic slots, and expression selection: The program owns templates and preference order, inserted values are replaced only once, and the App supplies the random source for variants.
First compose one piece of generated text
Beginner · Node.js
ts
import { Presentation } from '@jangts/agent-core/kits/presentation';
const outputs = Presentation.defineOutputCatalog([
{ id: 'reply', kind: 'text', fields: [{ id: 'text', owner: 'generated' }] },
]);
console.log(outputs.toModelSchema('reply'));
const output = outputs.compose({ outputId: 'reply', input: { generated: { text: '普通对象即可定义节点。' } } }, { app: {}, signal: new AbortController().signal });
console.log(output.value);1
2
3
4
5
6
7
2
3
4
5
6
7
js
import { Presentation } from '@jangts/agent-core/kits/presentation';
const outputs = Presentation.defineOutputCatalog([
{ id: 'reply', kind: 'text', fields: [{ id: 'text', owner: 'generated' }] },
]);
console.log(outputs.toModelSchema('reply'));
const output = outputs.compose({ outputId: 'reply', input: { generated: { text: '普通对象即可定义节点。' } } }, { app: {}, signal: new AbortController().signal });
console.log(output.value);1
2
3
4
5
6
7
2
3
4
5
6
7
Let the program own the explanatory prefix in the same compose
Configuration · Node.js
ts
import { Presentation } from '@jangts/agent-core/kits/presentation';
const outputs = Presentation.defineOutputCatalog([
{ id: 'reply', kind: 'master', master: '{{prefix}}{{text}}', fields: [
{ id: 'prefix', owner: 'constant', constantValue: '接口说明:' },
{ id: 'text', owner: 'generated' },
] },
]);
console.log(outputs.toModelSchema('reply')); // 只有 text 由模型填写
console.log(outputs.compose({ outputId: 'reply', input: { generated: { text: '普通对象即可定义节点。' } } }, { app: {}, signal: new AbortController().signal }).value);1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
js
import { Presentation } from '@jangts/agent-core/kits/presentation';
const outputs = Presentation.defineOutputCatalog([
{ id: 'reply', kind: 'master', master: '{{prefix}}{{text}}', fields: [
{ id: 'prefix', owner: 'constant', constantValue: '接口说明:' },
{ id: 'text', owner: 'generated' },
] },
]);
console.log(outputs.toModelSchema('reply')); // 只有 text 由模型填写
console.log(outputs.compose({ outputId: 'reply', input: { generated: { text: '普通对象即可定义节点。' } } }, { app: {}, signal: new AbortController().signal }).value);1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9