Skip to content
English

PreparedModelTransport ​

CORE · interface · 类型合同

Prepared transport handed to the runner, including sampling defaults.

导入 ​

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

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

定义 ​

ts
interface PreparedModelTransport<Result>

泛型参数 ​

类型参数约束默认类型
Result—unknown

字段结构 ​

字段类型必需说明
optionsPick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature">必需只读。见类型定义及调用场景。
schemaCharsnumber必需只读。见类型定义及调用场景。
instructionstring | undefined可省略只读。见类型定义及调用场景。
createResponse() => ModelResponseCollector<Result>必需见类型定义及调用场景。

成员目录 ​

成员用途
createResponse完整输入输出见下方重载。

成员详情 ​

createResponse ​

ts
PreparedModelTransport.createResponse(): ModelResponseCollector<Result>

无调用参数。

返回: ModelResponseCollector<Result>。

返回值结构
字段类型必需说明
call{ id: string; name: string; argumentChars: number; } | undefined可省略只读。Native function call that carried the selection, when the response used one.
callsreadonly { id: string; name: string; argumentChars: number; toolId?: string; }[] | undefined可省略只读。All native calls carried by a session response; omitted by single-selection collectors.
outputCharsnumber必需只读。Output characters accumulated so far, for output-budget accounting.
push(part: ModelPart) => void必需Appends one streamed part; parts arrive in provider order.
finish() => Result必需Finalizes the response. Throws when the accumulated content is not a valid selection.

使用示例 ​

声明两个可选择 Tool ​

入门 · Node.js

ts
import { ModelToolRegistry } from '@jangts/agent-core';
const inputSchema = { jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
  parse(value: unknown) {
    if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length) throw new Error('需要空对象');
    return {};
  } };
const tools = new ModelToolRegistry([
  { id: 'greet', description: '回答问候', inputSchema, resolve: () => 'greet' },
  { id: 'status', description: '查询状态', inputSchema, resolve: () => 'status' },
]).seal();
console.log(tools.resolve({ toolId: 'status', input: {} }, { stageId: 'recognize' }));
js
import { ModelToolRegistry } from '@jangts/agent-core';
const inputSchema = { jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
    parse(value) {
        if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length)
            throw new Error('需要空对象');
        return {};
    } };
const tools = new ModelToolRegistry([
    { id: 'greet', description: '回答问候', inputSchema, resolve: () => 'greet' },
    { id: 'status', description: '查询状态', inputSchema, resolve: () => 'status' },
]).seal();
console.log(tools.resolve({ toolId: 'status', input: {} }, { stageId: 'recognize' }));

仅向一个阶段投影允许的子集 ​

配置 · Node.js

ts
import { ModelToolRegistry, Support } from '@jangts/agent-core';
const schema = Support.defineSchema({ jsonSchema: { type: 'object', properties: {} },
  parse(value: unknown) { if (!value || typeof value !== 'object' || Array.isArray(value)) throw new TypeError('需要对象'); return {}; } });
const registry = new ModelToolRegistry([
  { id: 'greet', description: '问候', inputSchema: schema, resolve: () => 'greet' },
  { id: 'status', description: '状态', inputSchema: schema, resolve: () => 'status' },
]).seal();
const readOnly = registry.select(['status']);
const transport = Support.createModelTransport({ id: 'recognize', tools: readOnly });
console.log(transport.id, readOnly.ids());
js
import { ModelToolRegistry, Support } from '@jangts/agent-core';
const schema = Support.defineSchema({ jsonSchema: { type: 'object', properties: {} },
    parse(value) { if (!value || typeof value !== 'object' || Array.isArray(value))
        throw new TypeError('需要对象'); return {}; } });
const registry = new ModelToolRegistry([
    { id: 'greet', description: '问候', inputSchema: schema, resolve: () => 'greet' },
    { id: 'status', description: '状态', inputSchema: schema, resolve: () => 'status' },
]).seal();
const readOnly = registry.select(['status']);
const transport = Support.createModelTransport({ id: 'recognize', tools: readOnly });
console.log(transport.id, readOnly.ids());

相关定义 ​

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