Skip to content
中文

ToolModelView ​

SUPPORT · interface · Type contract

Model capability view of a tool catalog, retaining the host context type.

Import ​

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

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

Definition ​

ts
interface ToolModelView<App>

Extends or implements: ModelToolRegistry.

Type parameters ​

Type parameterConstraintDefault type
App—unknown

Field structure ​

FieldTypeRequiredDescription
values() => IterableIterator<RegisteredModelTool<ToolProposal>>RequiredSee the type definition and usage context.
resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>) => ToolProposalRequiredResolves a model selection into a proposal; throws for unknown or invalid selections.
select(ids: readonly string[], context?: App) => ToolModelView<App>RequiredNarrows the capability set to ids; throws for unregistered ids.
withIntent(context: App) => ToolModelView<App>RequiredDiscovery retains this projection's ToolProposal result contract.
register<Result>(capability: ModelToolRegistration<Result>) => ToolModelView<App>RequiredRegister one capability.
definitionsreadonly Readonly<Readonly<ModelTool<unknown, unknown, any>>>[]RequiredRead-only. Frozen snapshot of the registered definitions, in insertion order.
ids() => readonly string[]RequiredRegistered ids in declaration order.
entries() => IterableIterator<readonly [string, RegisteredModelTool]>RequiredLive iterator over [id, definition] pairs; it reflects only entries added before sealing.
registerAll(definitions: Iterable<ModelToolRegistration>) => ToolModelView<App>RequiredRegister several tools.
require(id: string) => RegisteredModelToolRequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => RegisteredModelTool | undefinedRequiredSee the type definition and usage context.
seal() => ToolModelView<App>RequiredClose the registry to further registration. Sealing is idempotent and does not affect existing entries.

Member index ​

MemberPurpose
valuesSee the overload below for full inputs and outputs.
resolveResolves a model selection into a proposal; throws for unknown or invalid selections.
selectNarrows the capability set to ids; throws for unregistered ids.
withIntentDiscovery retains this projection's ToolProposal result contract.
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.
sealClose the registry to further registration. Sealing is idempotent and does not affect existing entries.

Member details ​

values ​

ts
ToolModelView.values(): IterableIterator<RegisteredModelTool<ToolProposal>>

No call parameters.

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

resolve ​

Resolves a model selection into a proposal; throws for unknown or invalid selections.

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

Resolves a model selection into a proposal; throws for unknown or invalid selections.

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

Return value structure
FieldTypeRequiredDescription
toolIdstringRequiredRead-only. See the type definition and usage context.
inputunknownRequiredRead-only. See the type definition and usage context.

select ​

Narrows the capability set to ids; throws for unregistered ids.

ts
ToolModelView.select(ids: readonly string[], context?: App): ToolModelView<App>

Narrows the capability set to ids; throws for unregistered ids.

ParameterTypePassingDescription
idsreadonly string[]Required—
contextApp | undefinedOptional—

Returns: ToolModelView<App>.

Return value structure
FieldTypeRequiredDescription
values() => IterableIterator<RegisteredModelTool<ToolProposal>>RequiredSee the type definition and usage context.
resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>) => ToolProposalRequiredResolves a model selection into a proposal; throws for unknown or invalid selections.
select(ids: readonly string[], context?: App) => ToolModelView<App>RequiredNarrows the capability set to ids; throws for unregistered ids.
withIntent(context: App) => ToolModelView<App>RequiredDiscovery retains this projection's ToolProposal result contract.
register<Result>(capability: ModelToolRegistration<Result>) => ToolModelView<App>RequiredRegister one capability.
definitionsreadonly Readonly<Readonly<ModelTool<unknown, unknown, any>>>[]RequiredRead-only. Frozen snapshot of the registered definitions, in insertion order.
ids() => readonly string[]RequiredRegistered ids in declaration order.
entries() => IterableIterator<readonly [string, RegisteredModelTool]>RequiredLive iterator over [id, definition] pairs; it reflects only entries added before sealing.
registerAll(definitions: Iterable<ModelToolRegistration>) => ToolModelView<App>RequiredRegister several tools.
require(id: string) => RegisteredModelToolRequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => RegisteredModelTool | undefinedRequiredSee the type definition and usage context.
seal() => ToolModelView<App>RequiredClose the registry to further registration. Sealing is idempotent and does not affect existing entries.

withIntent ​

Discovery retains this projection's ToolProposal result contract.

ts
ToolModelView.withIntent(context: App): ToolModelView<App>

Discovery retains this projection's ToolProposal result contract.

ParameterTypePassingDescription
contextAppRequired—

Returns: ToolModelView<App>.

Return value structure
FieldTypeRequiredDescription
values() => IterableIterator<RegisteredModelTool<ToolProposal>>RequiredSee the type definition and usage context.
resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>) => ToolProposalRequiredResolves a model selection into a proposal; throws for unknown or invalid selections.
select(ids: readonly string[], context?: App) => ToolModelView<App>RequiredNarrows the capability set to ids; throws for unregistered ids.
withIntent(context: App) => ToolModelView<App>RequiredDiscovery retains this projection's ToolProposal result contract.
register<Result>(capability: ModelToolRegistration<Result>) => ToolModelView<App>RequiredRegister one capability.
definitionsreadonly Readonly<Readonly<ModelTool<unknown, unknown, any>>>[]RequiredRead-only. Frozen snapshot of the registered definitions, in insertion order.
ids() => readonly string[]RequiredRegistered ids in declaration order.
entries() => IterableIterator<readonly [string, RegisteredModelTool]>RequiredLive iterator over [id, definition] pairs; it reflects only entries added before sealing.
registerAll(definitions: Iterable<ModelToolRegistration>) => ToolModelView<App>RequiredRegister several tools.
require(id: string) => RegisteredModelToolRequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => RegisteredModelTool | undefinedRequiredSee the type definition and usage context.
seal() => ToolModelView<App>RequiredClose the registry to further registration. Sealing is idempotent and does not affect existing entries.

register ​

Register one capability.

ts
ToolModelView.register<Result>(capability: ModelToolRegistration<Result>): ToolModelView<App>

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: ToolModelView<App>.

Return value structure
FieldTypeRequiredDescription
values() => IterableIterator<RegisteredModelTool<ToolProposal>>RequiredSee the type definition and usage context.
resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>) => ToolProposalRequiredResolves a model selection into a proposal; throws for unknown or invalid selections.
select(ids: readonly string[], context?: App) => ToolModelView<App>RequiredNarrows the capability set to ids; throws for unregistered ids.
withIntent(context: App) => ToolModelView<App>RequiredDiscovery retains this projection's ToolProposal result contract.
register<Result>(capability: ModelToolRegistration<Result>) => ToolModelView<App>RequiredRegister one capability.
definitionsreadonly Readonly<Readonly<ModelTool<unknown, unknown, any>>>[]RequiredRead-only. Frozen snapshot of the registered definitions, in insertion order.
ids() => readonly string[]RequiredRegistered ids in declaration order.
entries() => IterableIterator<readonly [string, RegisteredModelTool]>RequiredLive iterator over [id, definition] pairs; it reflects only entries added before sealing.
registerAll(definitions: Iterable<ModelToolRegistration>) => ToolModelView<App>RequiredRegister several tools.
require(id: string) => RegisteredModelToolRequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => RegisteredModelTool | undefinedRequiredSee the type definition and usage context.
seal() => ToolModelView<App>RequiredClose the registry to further registration. Sealing is idempotent and does not affect existing entries.

ids ​

Registered ids in declaration order.

ts
ToolModelView.ids(): readonly string[]

Registered ids in declaration order.

No call parameters.

Returns: readonly string[].

entries ​

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

ts
ToolModelView.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 ​

Register several tools.

ts
ToolModelView.registerAll(definitions: Iterable<ModelToolRegistration>): ToolModelView<App>

Register several tools.

ParameterTypePassingDescription
definitionsIterable<ModelToolRegistration>Required—

Returns: ToolModelView<App>.

Return value structure
FieldTypeRequiredDescription
values() => IterableIterator<RegisteredModelTool<ToolProposal>>RequiredSee the type definition and usage context.
resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>) => ToolProposalRequiredResolves a model selection into a proposal; throws for unknown or invalid selections.
select(ids: readonly string[], context?: App) => ToolModelView<App>RequiredNarrows the capability set to ids; throws for unregistered ids.
withIntent(context: App) => ToolModelView<App>RequiredDiscovery retains this projection's ToolProposal result contract.
register<Result>(capability: ModelToolRegistration<Result>) => ToolModelView<App>RequiredRegister one capability.
definitionsreadonly Readonly<Readonly<ModelTool<unknown, unknown, any>>>[]RequiredRead-only. Frozen snapshot of the registered definitions, in insertion order.
ids() => readonly string[]RequiredRegistered ids in declaration order.
entries() => IterableIterator<readonly [string, RegisteredModelTool]>RequiredLive iterator over [id, definition] pairs; it reflects only entries added before sealing.
registerAll(definitions: Iterable<ModelToolRegistration>) => ToolModelView<App>RequiredRegister several tools.
require(id: string) => RegisteredModelToolRequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => RegisteredModelTool | undefinedRequiredSee the type definition and usage context.
seal() => ToolModelView<App>RequiredClose the registry to further registration. Sealing is idempotent and does not affect existing entries.

require ​

ts
ToolModelView.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 ​

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

Returns: boolean.

get ​

ts
ToolModelView.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.

seal ​

Close the registry to further registration.

Sealing is idempotent and does not affect existing entries.

ts
ToolModelView.seal(): ToolModelView<App>

Close the registry to further registration.

Sealing is idempotent and does not affect existing entries.

No call parameters.

Returns: ToolModelView<App>.

Return value structure
FieldTypeRequiredDescription
values() => IterableIterator<RegisteredModelTool<ToolProposal>>RequiredSee the type definition and usage context.
resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>) => ToolProposalRequiredResolves a model selection into a proposal; throws for unknown or invalid selections.
select(ids: readonly string[], context?: App) => ToolModelView<App>RequiredNarrows the capability set to ids; throws for unregistered ids.
withIntent(context: App) => ToolModelView<App>RequiredDiscovery retains this projection's ToolProposal result contract.
register<Result>(capability: ModelToolRegistration<Result>) => ToolModelView<App>RequiredRegister one capability.
definitionsreadonly Readonly<Readonly<ModelTool<unknown, unknown, any>>>[]RequiredRead-only. Frozen snapshot of the registered definitions, in insertion order.
ids() => readonly string[]RequiredRegistered ids in declaration order.
entries() => IterableIterator<readonly [string, RegisteredModelTool]>RequiredLive iterator over [id, definition] pairs; it reflects only entries added before sealing.
registerAll(definitions: Iterable<ModelToolRegistration>) => ToolModelView<App>RequiredRegister several tools.
require(id: string) => RegisteredModelToolRequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => RegisteredModelTool | undefinedRequiredSee the type definition and usage context.
seal() => ToolModelView<App>RequiredClose the registry to further registration. Sealing is idempotent and does not affect existing entries.

Examples ​

Define and use a read-only tool ​

Beginner · Node.js

ts
import { Support } from '@jangts/agent-core';
const inputSchema = Support.defineSchema({
  jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
  parse(value: unknown) {
    if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length) throw new TypeError('需要空对象');
    return {};
  },
});
const catalog = Support.defineToolCatalog([{ id: 'get_status', kind: 'read', description: '读取服务状态', inputSchema,
  authorize() {},
  execute() { return '服务运行正常'; },
  parseOutput(value: unknown) { if (typeof value !== 'string') throw new TypeError('需要字符串'); return value; },
}]);
const tools = catalog.bind({ app: undefined });
console.log((await tools.invoke({ toolId: 'get_status', input: {} })).value);
console.log(catalog.tools.ids());
js
import { Support } from '@jangts/agent-core';
const inputSchema = Support.defineSchema({
    jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
    parse(value) {
        if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length)
            throw new TypeError('需要空对象');
        return {};
    },
});
const catalog = Support.defineToolCatalog([{ id: 'get_status', kind: 'read', description: '读取服务状态', inputSchema,
        authorize() { },
        execute() { return '服务运行正常'; },
        parseOutput(value) { if (typeof value !== 'string')
            throw new TypeError('需要字符串'); return value; },
    }]);
const tools = catalog.bind({ app: undefined });
console.log((await tools.invoke({ toolId: 'get_status', input: {} })).value);
console.log(catalog.tools.ids());

Keep the list and add this request's permissions and service dependencies ​

Configuration · Node.js

ts
import { Support } from '@jangts/agent-core';
import type { OperationContext } from '@jangts/agent-core/types';
type App = { allowed: boolean; readStatus(): Promise<string> };
const inputSchema = Support.defineSchema({
  jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
  parse(value: unknown) {
    if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length) throw new TypeError('需要空对象');
    return {};
  },
});
const catalog = Support.defineToolCatalog<App>([{ id: 'get_status', kind: 'read', description: '读取状态', inputSchema,
  authorize(_input: {}, { app }: OperationContext<App>) { if (!app.allowed) throw new Error('当前请求没有读取权限'); },
  execute(_input: {}, { app }: OperationContext<App>) { return app.readStatus(); },
  parseOutput(value: unknown) { if (typeof value !== 'string') throw new TypeError('需要字符串'); return value; },
}]);
const tools = catalog.bind({ app: { allowed: true, readStatus: async () => '服务运行正常' },
  execution: { signal: AbortSignal.timeout(10000) },
});
console.log((await tools.invoke({ toolId: 'get_status', input: {} })).value);
js
import { Support } from '@jangts/agent-core';
const inputSchema = Support.defineSchema({
    jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
    parse(value) {
        if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length)
            throw new TypeError('需要空对象');
        return {};
    },
});
const catalog = Support.defineToolCatalog([{ id: 'get_status', kind: 'read', description: '读取状态', inputSchema,
        authorize(_input, { app }) { if (!app.allowed)
            throw new Error('当前请求没有读取权限'); },
        execute(_input, { app }) { return app.readStatus(); },
        parseOutput(value) { if (typeof value !== 'string')
            throw new TypeError('需要字符串'); return value; },
    }]);
const tools = catalog.bind({ app: { allowed: true, readStatus: async () => '服务运行正常' },
    execution: { signal: AbortSignal.timeout(10000) },
});
console.log((await tools.invoke({ toolId: 'get_status', input: {} })).value);

API reference, usage examples and developer guides.