Skip to content
中文

ModelToolSource ​

CORE · interface · Type contract

Minimal source a stage needs: enumerate tools and resolve one selection.

Import ​

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

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

Definition ​

ts
interface ModelToolSource<Output>

Type parameters ​

Type parameterConstraintDefault type
Output—unknown

Field structure ​

FieldTypeRequiredDescription
values() => IterableIterator<RegisteredModelTool<Output>>RequiredSee the type definition and usage context.
resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>) => OutputRequiredResolves one selection; throws when the capability is absent from this source.

Member index ​

MemberPurpose
valuesSee the overload below for full inputs and outputs.
resolveResolves one selection; throws when the capability is absent from this source.

Member details ​

values ​

ts
ModelToolSource.values(): IterableIterator<RegisteredModelTool<Output>>

No call parameters.

Returns: IterableIterator<Readonly<ModelTool<unknown, Output, any>>>.

resolve ​

Resolves one selection; throws when the capability is absent from this source.

ts
ModelToolSource.resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>): Output

Resolves one selection; throws when the capability is absent from this source.

ParameterTypePassingDescription
selectionModelSelectionRequired—
contextReadonly<{ stageId: string; }>Required—
Fields of selection
FieldTypeRequiredDescription
inputRecord<string, unknown>RequiredRead-only. Arguments exactly as produced by the model, before schema parsing.
call{ id: string; name: string; argumentChars: number; } | undefinedOptionalRead-only. Native function call that carried the selection, when the provider used one.
toolIdstringRequiredRead-only. Capability the selection resolved to.
Fields of context
FieldTypeRequiredDescription
stageIdstringRequiredSee the type definition and usage context.

Returns: Output.

Awaited value: Awaited<Output>.

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.