Skip to content
中文

PreparedModelTransport ​

CORE · interface · Type contract

Prepared transport handed to the runner, including sampling defaults.

Import ​

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

Other public entry points:@jangts/agent-core/types, @jangts/agent-core/structs.

Definition ​

ts
interface PreparedModelTransport<Result>

Type parameters ​

Type parameterConstraintDefault type
Result—unknown

Field structure ​

FieldTypeRequiredDescription
optionsPick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature">RequiredRead-only. See the type definition and usage context.
schemaCharsnumberRequiredRead-only. See the type definition and usage context.
instructionstring | undefinedOptionalRead-only. See the type definition and usage context.
createResponse() => ModelResponseCollector<Result>RequiredSee the type definition and usage context.

Member index ​

MemberPurpose
createResponseSee the overload below for full inputs and outputs.

Member details ​

createResponse ​

ts
PreparedModelTransport.createResponse(): ModelResponseCollector<Result>

No call parameters.

Returns: ModelResponseCollector<Result>.

Return value structure
FieldTypeRequiredDescription
call{ id: string; name: string; argumentChars: number; } | undefinedOptionalRead-only. Native function call that carried the selection, when the response used one.
callsreadonly { id: string; name: string; argumentChars: number; toolId?: string; }[] | undefinedOptionalRead-only. All native calls carried by a session response; omitted by single-selection collectors.
outputCharsnumberRequiredRead-only. Output characters accumulated so far, for output-budget accounting.
push(part: ModelPart) => voidRequiredAppends one streamed part; parts arrive in provider order.
finish() => ResultRequiredFinalizes the response. Throws when the accumulated content is not a valid selection.

Examples ​

Declare two selectable tools ​

Beginner · 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' }));

Project an allowed subset to only one stage ​

Configuration · 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());

API reference, usage examples and developer guides.