Skip to content
中文

ModelToolRegistry ​

CORE · class · Runtime value

A request/stage projection is a sealed registry. Hosts filter availability before projection.

Import ​

ts
import { ModelToolRegistry } from '@jangts/agent-core';
js
import { ModelToolRegistry } from '@jangts/agent-core';

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

Definition ​

ts
class ModelToolRegistry

Constructor ​

ts
new ModelToolRegistry(definitions?: Iterable<ModelToolRegistration>): ModelToolRegistry
ParameterTypePassingDescription
definitionsIterable<ModelToolRegistration>Optional—

Returns: ModelToolRegistry.

Instance properties ​

FieldTypeRequiredDescription
definitionsreadonly Readonly<Readonly<ModelTool<unknown, unknown, any>>>[]RequiredRead-only. Frozen snapshot of the registered definitions, in insertion order.

Member index ​

MemberPurpose
registerRegister one capability.
idsRegistered ids in declaration order.
entriesLive iterator over [id, definition] pairs; it reflects only entries added before sealing.
registerAllRegister several tools.
requireSee the overload below for full inputs and outputs.
hasSee the overload below for full inputs and outputs.
getSee the overload below for full inputs and outputs.
valuesLive iterator over the registered definitions.
sealClose the registry to further registration. Sealing is idempotent and does not affect existing entries.
selectDerive a sealed sub-catalog for one stage.
withIntentDiscover active demand-facing tools without tying the projection to a workflow entry.
resolveParse model-supplied arguments and run the selected capability.

Member details ​

register ​

Instance method.

Register one capability.

ts
register<Result>(capability: ModelToolRegistration<Result>): ModelToolRegistry

Register one capability.

Type parameterConstraintDefault type
Result——
ParameterTypePassingDescription
capabilityModelToolRegistration<Result>Required—
Fields of capability
FieldTypeRequiredDescription
idstringRequiredRead-only. Unique id within its registry; never blank.
descriptionstringRequiredRead-only. Model-visible description explaining when the capability applies.
inputSchemaSchemaAdapter<any>RequiredRead-only. Schema describing the arguments; must be an object schema.
activeToolCondition<any> | undefinedOptionalRead-only. Omitted means active. Authorization remains a separate execution boundary.
asIntentAsIntent<any> | undefinedOptionalRead-only. Omitted means this tool is not advertised by withIntent().
resolve((input: any, context: Readonly<{ stageId: string; }>) => Result) | undefinedOptionalRead-only. See the type definition and usage context.

Returns: ModelToolRegistry.

ids ​

Instance method.

Registered ids in declaration order.

ts
ids(): readonly string[]

Registered ids in declaration order.

No call parameters.

Returns: readonly string[].

entries ​

Instance method.

Live iterator over [id, definition] pairs; it reflects only entries added before sealing.

ts
entries(): IterableIterator<readonly [string, RegisteredModelTool]>

Live iterator over [id, definition] pairs; it reflects only entries added before sealing.

No call parameters.

Returns: IterableIterator<readonly [string, Readonly<ModelTool<unknown, unknown, any>>]>.

registerAll ​

Instance method.

Register several tools.

ts
registerAll(definitions: Iterable<ModelToolRegistration>): ModelToolRegistry

Register several tools.

ParameterTypePassingDescription
definitionsIterable<ModelToolRegistration>Required—

Returns: ModelToolRegistry.

require ​

Instance method.

ts
require(id: string): RegisteredModelTool
ParameterTypePassingDescription
idstringRequired—

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

Return value structure
FieldTypeRequiredDescription
idstringRequiredRead-only. Unique id within its registry; never blank.
descriptionstringRequiredRead-only. Model-visible description explaining when the capability applies.
inputSchemaSchemaAdapter<unknown>RequiredRead-only. Schema describing the arguments; must be an object schema.
activeToolCondition<any> | undefinedOptionalRead-only. Omitted means active. Authorization remains a separate execution boundary.
asIntentAsIntent<any> | undefinedOptionalRead-only. Omitted means this tool is not advertised by withIntent().
resolve(input: unknown, context: Readonly<{ stageId: string; }>) => unknownRequiredConverts validated arguments into the value handed back to the caller. Runs inside the model call, so it must return synchronously; throwing rejects the selection.

has ​

Instance method.

ts
has(id: string): boolean
ParameterTypePassingDescription
idstringRequired—

Returns: boolean.

get ​

Instance method.

ts
get(id: string): RegisteredModelTool | undefined
ParameterTypePassingDescription
idstringRequired—

Returns: Readonly<ModelTool<unknown, unknown, any>> \| undefined.

Optional shapes of Return value: choose one shape; required fields for each branch are listed separately.

Branch 1

undefined

Branch 2
FieldTypeRequiredDescription
idstringRequiredRead-only. Unique id within its registry; never blank.
descriptionstringRequiredRead-only. Model-visible description explaining when the capability applies.
inputSchemaSchemaAdapter<unknown>RequiredRead-only. Schema describing the arguments; must be an object schema.
activeToolCondition<any> | undefinedOptionalRead-only. Omitted means active. Authorization remains a separate execution boundary.
asIntentAsIntent<any> | undefinedOptionalRead-only. Omitted means this tool is not advertised by withIntent().
resolve(input: unknown, context: Readonly<{ stageId: string; }>) => unknownRequiredConverts validated arguments into the value handed back to the caller. Runs inside the model call, so it must return synchronously; throwing rejects the selection.

values ​

Instance method.

Live iterator over the registered definitions.

ts
values(): IterableIterator<RegisteredModelTool>

Live iterator over the registered definitions.

No call parameters.

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

seal ​

Instance method.

Close the registry to further registration.

Sealing is idempotent and does not affect existing entries.

ts
seal(): ModelToolRegistry

Close the registry to further registration.

Sealing is idempotent and does not affect existing entries.

No call parameters.

Returns: ModelToolRegistry.

select ​

Instance method.

Derive a sealed sub-catalog for one stage.

ts
select(ids: readonly string[], context?: unknown): ModelToolRegistry

Derive a sealed sub-catalog for one stage.

ParameterTypePassingDescription
idsreadonly string[]Required—
contextunknownOptional—

Returns: ModelToolRegistry.

withIntent ​

Instance method.

Discover active demand-facing tools without tying the projection to a workflow entry.

ts
withIntent(context: unknown): ModelToolRegistry

Discover active demand-facing tools without tying the projection to a workflow entry.

ParameterTypePassingDescription
contextunknownRequired—

Returns: ModelToolRegistry.

resolve ​

Instance method.

Parse model-supplied arguments and run the selected capability.

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

Parse model-supplied arguments and run the selected capability.

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: unknown.

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.