ModelTransportDefinition
CORE · interface · Type contract
One registered transport: a wire format prepared for a stage.
Import
ts
import type { ModelTransportDefinition } from '@jangts/agent-core/model';js
/** @typedef {import('@jangts/agent-core/model').ModelTransportDefinition} ModelTransportDefinition */Other public entry points:@jangts/agent-core, @jangts/agent-core/model, @jangts/agent-core/types, @jangts/agent-core/structs.
Definition
ts
interface ModelTransportDefinition<Result>Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Result | — | unknown |
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. Transport id used by call requests and reported in diagnostics. |
prepare | (stageId: string) => import("./interactions.js").PreparedModelTransport<Result> | Required | Builds the prepared transport for stageId; must not spend a call by itself. |
Member index
| Member | Purpose |
|---|---|
prepare | Builds the prepared transport for stageId; must not spend a call by itself. |
Member details
prepare
Builds the prepared transport for stageId; must not spend a call by itself.
ts
ModelTransportDefinition.prepare(stageId: string): import("./interactions.js").PreparedModelTransport<Result>Builds the prepared transport for stageId; must not spend a call by itself.
| Parameter | Type | Passing | Description |
|---|---|---|---|
stageId | string | Required | — |
Returns: PreparedModelTransport<Result>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
options | Pick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature"> | Required | Read-only. See the type definition and usage context. |
schemaChars | number | Required | Read-only. See the type definition and usage context. |
instruction | string | undefined | Optional | Read-only. See the type definition and usage context. |
createResponse | () => ModelResponseCollector<Result> | Required | See the type definition and usage context. |
Examples
- Model tools and transports: typed selection only after full validation: A tool definition provides a Schema and resolver; a transport translates wire output into the unified model selection contract.
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());