ModelToolRegistry
CORE · class · Runtime value
A request/stage projection is a sealed registry. Hosts filter availability before projection.
Import
import { ModelToolRegistry } from '@jangts/agent-core';import { ModelToolRegistry } from '@jangts/agent-core';Other public entry points:@jangts/agent-core, @jangts/agent-core/types.
Definition
class ModelToolRegistryConstructor
new ModelToolRegistry(definitions?: Iterable<ModelToolRegistration>): ModelToolRegistry| Parameter | Type | Passing | Description |
|---|---|---|---|
definitions | Iterable<ModelToolRegistration> | Optional | — |
Returns: ModelToolRegistry.
Instance properties
| Field | Type | Required | Description |
|---|---|---|---|
definitions | readonly Readonly<Readonly<ModelTool<unknown, unknown, any>>>[] | Required | Read-only. Frozen snapshot of the registered definitions, in insertion order. |
Member index
| Member | Purpose |
|---|---|
register | Register one capability. |
ids | Registered ids in declaration order. |
entries | Live iterator over [id, definition] pairs; it reflects only entries added before sealing. |
registerAll | Register several tools. |
require | See the overload below for full inputs and outputs. |
has | See the overload below for full inputs and outputs. |
get | See the overload below for full inputs and outputs. |
values | Live iterator over the registered definitions. |
seal | Close the registry to further registration. Sealing is idempotent and does not affect existing entries. |
select | Derive a sealed sub-catalog for one stage. |
withIntent | Discover active demand-facing tools without tying the projection to a workflow entry. |
resolve | Parse model-supplied arguments and run the selected capability. |
Member details
register
Instance method.
Register one capability.
register<Result>(capability: ModelToolRegistration<Result>): ModelToolRegistryRegister one capability.
| Type parameter | Constraint | Default type |
|---|---|---|
Result | — | — |
| Parameter | Type | Passing | Description |
|---|---|---|---|
capability | ModelToolRegistration<Result> | Required | — |
Fields of capability
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. Unique id within its registry; never blank. |
description | string | Required | Read-only. Model-visible description explaining when the capability applies. |
inputSchema | SchemaAdapter<any> | Required | Read-only. Schema describing the arguments; must be an object schema. |
active | ToolCondition<any> | undefined | Optional | Read-only. Omitted means active. Authorization remains a separate execution boundary. |
asIntent | AsIntent<any> | undefined | Optional | Read-only. Omitted means this tool is not advertised by withIntent(). |
resolve | ((input: any, context: Readonly<{ stageId: string; }>) => Result) | undefined | Optional | Read-only. See the type definition and usage context. |
Returns: ModelToolRegistry.
ids
Instance method.
Registered ids in declaration order.
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.
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.
registerAll(definitions: Iterable<ModelToolRegistration>): ModelToolRegistryRegister several tools.
| Parameter | Type | Passing | Description |
|---|---|---|---|
definitions | Iterable<ModelToolRegistration> | Required | — |
Returns: ModelToolRegistry.
require
Instance method.
require(id: string): RegisteredModelTool| Parameter | Type | Passing | Description |
|---|---|---|---|
id | string | Required | — |
Returns: Readonly<ModelTool<unknown, unknown, any>>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. Unique id within its registry; never blank. |
description | string | Required | Read-only. Model-visible description explaining when the capability applies. |
inputSchema | SchemaAdapter<unknown> | Required | Read-only. Schema describing the arguments; must be an object schema. |
active | ToolCondition<any> | undefined | Optional | Read-only. Omitted means active. Authorization remains a separate execution boundary. |
asIntent | AsIntent<any> | undefined | Optional | Read-only. Omitted means this tool is not advertised by withIntent(). |
resolve | (input: unknown, context: Readonly<{ stageId: string; }>) => unknown | Required | Converts 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.
has(id: string): boolean| Parameter | Type | Passing | Description |
|---|---|---|---|
id | string | Required | — |
Returns: boolean.
get
Instance method.
get(id: string): RegisteredModelTool | undefined| Parameter | Type | Passing | Description |
|---|---|---|---|
id | string | Required | — |
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
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. Unique id within its registry; never blank. |
description | string | Required | Read-only. Model-visible description explaining when the capability applies. |
inputSchema | SchemaAdapter<unknown> | Required | Read-only. Schema describing the arguments; must be an object schema. |
active | ToolCondition<any> | undefined | Optional | Read-only. Omitted means active. Authorization remains a separate execution boundary. |
asIntent | AsIntent<any> | undefined | Optional | Read-only. Omitted means this tool is not advertised by withIntent(). |
resolve | (input: unknown, context: Readonly<{ stageId: string; }>) => unknown | Required | Converts 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.
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.
seal(): ModelToolRegistryClose 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.
select(ids: readonly string[], context?: unknown): ModelToolRegistryDerive a sealed sub-catalog for one stage.
| Parameter | Type | Passing | Description |
|---|---|---|---|
ids | readonly string[] | Required | — |
context | unknown | Optional | — |
Returns: ModelToolRegistry.
withIntent
Instance method.
Discover active demand-facing tools without tying the projection to a workflow entry.
withIntent(context: unknown): ModelToolRegistryDiscover active demand-facing tools without tying the projection to a workflow entry.
| Parameter | Type | Passing | Description |
|---|---|---|---|
context | unknown | Required | — |
Returns: ModelToolRegistry.
resolve
Instance method.
Parse model-supplied arguments and run the selected capability.
resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>): unknownParse model-supplied arguments and run the selected capability.
| Parameter | Type | Passing | Description |
|---|---|---|---|
selection | ModelSelection | Required | — |
context | Readonly<{ stageId: string; }> | Required | — |
Fields of selection
| Field | Type | Required | Description |
|---|---|---|---|
input | Record<string, unknown> | Required | Read-only. Arguments exactly as produced by the model, before schema parsing. |
call | { id: string; name: string; argumentChars: number; } | undefined | Optional | Read-only. Native function call that carried the selection, when the provider used one. |
toolId | string | Required | Read-only. Capability the selection resolved to. |
Fields of context
| Field | Type | Required | Description |
|---|---|---|---|
stageId | string | Required | See the type definition and usage context. |
Returns: unknown.
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
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' }));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
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());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());