Skip to content
English

ModelToolCatalog ​

CORE · type · 类型合同

A compiled entity catalog also supports the minimal stage source contract.

导入 ​

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

其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs。

定义 ​

类型: ModelToolCatalog<Output>

类型表达式
ts
type ModelToolCatalog<Output = unknown> = ReadonlyCatalog<RegisteredModelTool<Output>> &
  ModelToolSource<Output> & {
    /** Explicit selection, optionally filtered against a host context. */
    select(ids: readonly string[], context?: unknown): ModelToolCatalog<Output>;
    /** Demand-facing active tools; no workflow node or invocation is implied. */
    withIntent(context: unknown): ModelToolCatalog<Output>;
  };

泛型参数 ​

类型参数约束默认类型
Output—unknown

字段结构 ​

字段类型必需说明
definitionsreadonly Readonly<Readonly<ModelTool<unknown, Output, any>>>[]必需只读。Definitions in registration order; each entry is frozen by the implementation.
ids() => readonly string[]必需Ids in the same order as definitions.
values(() => IterableIterator<Readonly<Readonly<ModelTool<unknown, Output, any>>>>) & (() => IterableIterator<Readonly<ModelTool<unknown, Output, any>>>)必需见类型定义及调用场景。
entries() => IterableIterator<readonly [string, Readonly<Readonly<ModelTool<unknown, Output, any>>>]>必需见类型定义及调用场景。
has(id: string) => boolean必需见类型定义及调用场景。
get(id: string) => Readonly<Readonly<ModelTool<unknown, Output, any>>> | undefined必需Returns the definition or undefined; the caller decides whether absence is an error.
require(id: string) => Readonly<Readonly<ModelTool<unknown, Output, any>>>必需Returns the definition or throws; use when the id is a required reference.
resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>) => Output必需Resolves one selection; throws when the capability is absent from this source.
select(ids: readonly string[], context?: unknown) => ModelToolCatalog<Output>必需Explicit selection, optionally filtered against a host context.
withIntent(context: unknown) => ModelToolCatalog<Output>必需Demand-facing active tools; no workflow node or invocation is implied.

成员目录 ​

成员用途
idsIds in the same order as definitions.
values完整输入输出见下方重载。
entries完整输入输出见下方重载。
has完整输入输出见下方重载。
getReturns the definition or undefined; the caller decides whether absence is an error.
requireReturns the definition or throws; use when the id is a required reference.
resolveResolves one selection; throws when the capability is absent from this source.
selectExplicit selection, optionally filtered against a host context.
withIntentDemand-facing active tools; no workflow node or invocation is implied.

成员详情 ​

ids ​

Ids in the same order as definitions.

ts
ModelToolCatalog.ids(): readonly string[]

Ids in the same order as definitions.

无调用参数。

返回: readonly string[]。

values ​

ts
ModelToolCatalog.values(): IterableIterator<Readonly<Readonly<ModelTool<unknown, Output, any>>>>

无调用参数。

返回: IterableIterator<Readonly<Readonly<ModelTool<unknown, Output, any>>>>。

entries ​

ts
ModelToolCatalog.entries(): IterableIterator<readonly [string, Readonly<Readonly<ModelTool<unknown, Output, any>>>]>

无调用参数。

返回: IterableIterator<readonly [string, Readonly<Readonly<ModelTool<unknown, Output, any>>>]>。

has ​

ts
ModelToolCatalog.has(id: string): boolean
参数类型传递说明
idstring必需—

返回: boolean。

get ​

Returns the definition or undefined; the caller decides whether absence is an error.

ts
ModelToolCatalog.get(id: string): Readonly<Readonly<ModelTool<unknown, Output, any>>> | undefined

Returns the definition or undefined; the caller decides whether absence is an error.

参数类型传递说明
idstring必需—

返回: Readonly<Readonly<ModelTool<unknown, Output, any>>> \| undefined。

返回值的可选结构: 选择其中一种结构,各分支的字段要求分别列出。

分支 1

undefined

分支 2
字段类型必需说明
idstring必需只读。Unique id within its registry; never blank.
descriptionstring必需只读。Model-visible description explaining when the capability applies.
inputSchemaSchemaAdapter<unknown>必需只读。Schema describing the arguments; must be an object schema.
activeToolCondition<any> | undefined可省略只读。Omitted means active. Authorization remains a separate execution boundary.
asIntentAsIntent<any> | undefined可省略只读。Omitted means this tool is not advertised by withIntent().
resolve(input: unknown, context: Readonly<{ stageId: string; }>) => Output必需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.

require ​

Returns the definition or throws; use when the id is a required reference.

ts
ModelToolCatalog.require(id: string): Readonly<Readonly<ModelTool<unknown, Output, any>>>

Returns the definition or throws; use when the id is a required reference.

参数类型传递说明
idstring必需—

返回: Readonly<Readonly<ModelTool<unknown, Output, any>>>。

返回值结构
字段类型必需说明
idstring必需只读。Unique id within its registry; never blank.
descriptionstring必需只读。Model-visible description explaining when the capability applies.
inputSchemaSchemaAdapter<unknown>必需只读。Schema describing the arguments; must be an object schema.
activeToolCondition<any> | undefined可省略只读。Omitted means active. Authorization remains a separate execution boundary.
asIntentAsIntent<any> | undefined可省略只读。Omitted means this tool is not advertised by withIntent().
resolve(input: unknown, context: Readonly<{ stageId: string; }>) => Output必需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.

resolve ​

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

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

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

参数类型传递说明
selectionModelSelection必需—
contextReadonly<{ stageId: string; }>必需—
selection 的字段
字段类型必需说明
inputRecord<string, unknown>必需只读。Arguments exactly as produced by the model, before schema parsing.
call{ id: string; name: string; argumentChars: number; } | undefined可省略只读。Native function call that carried the selection, when the provider used one.
toolIdstring必需只读。Capability the selection resolved to.
context 的字段
字段类型必需说明
stageIdstring必需见类型定义及调用场景。

返回: Output。

等待后的值: Awaited<Output>。

select ​

Explicit selection, optionally filtered against a host context.

ts
ModelToolCatalog.select(ids: readonly string[], context?: unknown): ModelToolCatalog<Output>

Explicit selection, optionally filtered against a host context.

参数类型传递说明
idsreadonly string[]必需—
contextunknown可省略—

返回: ModelToolCatalog<Output>。

返回值结构
字段类型必需说明
definitionsreadonly Readonly<Readonly<ModelTool<unknown, Output, any>>>[]必需只读。Definitions in registration order; each entry is frozen by the implementation.
ids() => readonly string[]必需Ids in the same order as definitions.
values(() => IterableIterator<Readonly<Readonly<ModelTool<unknown, Output, any>>>>) & (() => IterableIterator<Readonly<ModelTool<unknown, Output, any>>>)必需见类型定义及调用场景。
entries() => IterableIterator<readonly [string, Readonly<Readonly<ModelTool<unknown, Output, any>>>]>必需见类型定义及调用场景。
has(id: string) => boolean必需见类型定义及调用场景。
get(id: string) => Readonly<Readonly<ModelTool<unknown, Output, any>>> | undefined必需Returns the definition or undefined; the caller decides whether absence is an error.
require(id: string) => Readonly<Readonly<ModelTool<unknown, Output, any>>>必需Returns the definition or throws; use when the id is a required reference.
resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>) => Output必需Resolves one selection; throws when the capability is absent from this source.
select(ids: readonly string[], context?: unknown) => ModelToolCatalog<Output>必需Explicit selection, optionally filtered against a host context.
withIntent(context: unknown) => ModelToolCatalog<Output>必需Demand-facing active tools; no workflow node or invocation is implied.

withIntent ​

Demand-facing active tools; no workflow node or invocation is implied.

ts
ModelToolCatalog.withIntent(context: unknown): ModelToolCatalog<Output>

Demand-facing active tools; no workflow node or invocation is implied.

参数类型传递说明
contextunknown必需—

返回: ModelToolCatalog<Output>。

返回值结构
字段类型必需说明
definitionsreadonly Readonly<Readonly<ModelTool<unknown, Output, any>>>[]必需只读。Definitions in registration order; each entry is frozen by the implementation.
ids() => readonly string[]必需Ids in the same order as definitions.
values(() => IterableIterator<Readonly<Readonly<ModelTool<unknown, Output, any>>>>) & (() => IterableIterator<Readonly<ModelTool<unknown, Output, any>>>)必需见类型定义及调用场景。
entries() => IterableIterator<readonly [string, Readonly<Readonly<ModelTool<unknown, Output, any>>>]>必需见类型定义及调用场景。
has(id: string) => boolean必需见类型定义及调用场景。
get(id: string) => Readonly<Readonly<ModelTool<unknown, Output, any>>> | undefined必需Returns the definition or undefined; the caller decides whether absence is an error.
require(id: string) => Readonly<Readonly<ModelTool<unknown, Output, any>>>必需Returns the definition or throws; use when the id is a required reference.
resolve(selection: ModelSelection, context: Readonly<{ stageId: string; }>) => Output必需Resolves one selection; throws when the capability is absent from this source.
select(ids: readonly string[], context?: unknown) => ModelToolCatalog<Output>必需Explicit selection, optionally filtered against a host context.
withIntent(context: unknown) => ModelToolCatalog<Output>必需Demand-facing active tools; no workflow node or invocation is implied.

使用示例 ​

创建具名文本传输 ​

入门 · Node.js

ts
import { ModelRunner, Support } from '@jangts/agent-core';
const text = Support.createTextTransport({ id: 'brief', options: { temperature: 0.2 } });
const runner = new ModelRunner({ provider: { async *stream() { yield '服务正常'; } }, transports: [text] });
console.log((await runner.invoke({ input: '简答服务状态', transport: text })).value);
js
import { ModelRunner, Support } from '@jangts/agent-core';
const text = Support.createTextTransport({ id: 'brief', options: { temperature: 0.2 } });
const runner = new ModelRunner({ provider: { async *stream() { yield '服务正常'; } }, transports: [text] });
console.log((await runner.invoke({ input: '简答服务状态', transport: text })).value);

从同源 Tool 生成两个阶段的传输 ​

配置 · 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 tools = Support.defineModelTools([
  { id: 'greet', description: '问候', inputSchema, resolve: () => 'greet' },
  { id: 'status', description: '状态查询', inputSchema, resolve: () => 'status' },
]);
const transport = Support.createStageModelTransport({ id: 'intent', tools,
  stages: [{ id: 'recognize', toolIds: ['greet', 'status'] }, { id: 'status-only', toolIds: ['status'] }],
});
console.log(transport.prepare('status-only').schemaChars);
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 tools = Support.defineModelTools([
    { id: 'greet', description: '问候', inputSchema, resolve: () => 'greet' },
    { id: 'status', description: '状态查询', inputSchema, resolve: () => 'status' },
]);
const transport = Support.createStageModelTransport({ id: 'intent', tools,
    stages: [{ id: 'recognize', toolIds: ['greet', 'status'] }, { id: 'status-only', toolIds: ['status'] }],
});
console.log(transport.prepare('status-only').schemaChars);

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。