Skip to content
English

OutputDefinition ​

KIT · interface · 类型合同

One output shape.

导入 ​

ts
import type { OutputDefinition } from '@jangts/agent-core/kits/presentation';
js
/** @typedef {import('@jangts/agent-core/kits/presentation').OutputDefinition} OutputDefinition */

其他公开入口:@jangts/agent-core/types、@jangts/agent-core/kits/presentation、@jangts/agent-core/kits。

定义 ​

ts
interface OutputDefinition

字段结构 ​

字段类型必需说明
idstring必需只读。Output id; duplicate ids are rejected.
kind"text" | "master" | "record" | "group"必需只读。Shape family. text holds one required field; group holds program-assigned items.
fieldsreadonly OutputField[] | undefined可省略只读。Fields of text, master and record outputs; forbidden for groups.
masterstring | undefined可省略只读。Master template for master outputs; its slots must match the field ids exactly.
allowedOutputIdsreadonly string[] | undefined可省略只读。Output ids a group may contain; required and unique for groups.
maxItemsnumber | undefined可省略只读。Maximum group members; required for groups and at least 1.

使用示例 ​

先组合一段生成文本 ​

入门 · 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);
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);

相同 compose 让程序持有说明前缀 ​

配置 · 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);
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);

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。