Skip to content
English

defineAssociatedCatalog ​

SUPPORT · function · 运行时值

Compile independent and owner-derived Tool declarations, validating all references eagerly.

导入 ​

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

其他公开入口:@jangts/agent-core/support。

定义 ​

泛型参数 ​

类型参数约束默认类型
EntryAssociatedRegistration—

调用 ​

ts
defineAssociatedCatalog<Entry extends AssociatedRegistration>(entries: readonly Entry[], options?: AssociationOptions<Entry>): Readonly<{ tools: ModelToolCatalog<any>; bindings: ReadonlyCatalog<{ id: Entry["id"]; toolIds: readonly string[]; }>; sources: ReadonlyCatalog<{ id: string; sources: readonly Readonly<{ toolIds: readonly string[]; kind: "standalone" | "registration"; id: string; description: string; }>[]; }>; definitions: readonly Readonly<Entry>[]; ids(): readonly string[]; values(): IterableIterator<Readonly<Entry>>; entries(): IterableIterator<readonly [string, Readonly<Entry>]>; has(id: string): boolean; get(id: string): Readonly<Entry> | undefined; require(id: string): Readonly<Entry>; }>

Compile independent and owner-derived Tool declarations, validating all references eagerly.

类型参数约束默认类型
EntryAssociatedRegistration—
参数类型传递说明
entriesreadonly Entry[]必需—
optionsAssociationOptions<Entry>可省略—
options 的字段
字段类型必需说明
toolsreadonly ModelToolRegistration[] | undefined可省略只读。见类型定义及调用场景。
toolDefaults((entry: Readonly<Entry>) => ModelToolRegistration | undefined) | undefined可省略只读。见类型定义及调用场景。

返回: Readonly<{ tools: ModelToolCatalog<any>; bindings: ReadonlyCatalog<{ id: Entry["id"]; toolIds: readonly string[]; }>; sources: ReadonlyCatalog<{ id: string; sources: readonly Readonly<{ toolIds: readonly string[]; kind: "standalone" \| "registration"; id: string; description: string; }>[]; }>; definitions: readonly Readonly<Entry>[]; ids(): readonly string[]; values(): IterableIterator<Readonly<Entry>>; entries(): IterableIterator<readonly [string, Readonly<Entry>]>; has(id: string): boolean; get(id: string): Readonly<Entry> \| undefined; require(id: string): Readonly<Entry>; }>。

返回值结构
字段类型必需说明
toolsModelToolCatalog<any>必需见类型定义及调用场景。
bindingsReadonlyCatalog<{ id: Entry["id"]; toolIds: readonly string[]; }>必需见类型定义及调用场景。
sourcesReadonlyCatalog<{ id: string; sources: readonly Readonly<{ toolIds: readonly string[]; kind: "standalone" | "registration"; id: string; description: string; }>[]; }>必需见类型定义及调用场景。
definitionsreadonly Readonly<Entry>[]必需只读。Definitions in registration order; each entry is frozen by the implementation.
ids() => readonly string[]必需Ids in the same order as definitions.
values() => IterableIterator<Readonly<Entry>>必需见类型定义及调用场景。
entries() => IterableIterator<readonly [string, Readonly<Entry>]>必需见类型定义及调用场景。
has(id: string) => boolean必需见类型定义及调用场景。
get(id: string) => Readonly<Entry> | undefined必需Returns the definition or undefined; the caller decides whether absence is an error.
require(id: string) => Readonly<Entry>必需Returns the definition or throws; use when the id is a required reference.

使用示例 ​

直接复用现有模块声明 ​

入门 · Node.js

ts
import { Support } from '@jangts/agent-core';
const modules = [{ id: 'service', description: '服务查询能力', tools: [{ id: 'get_status' }] }];
const catalog = Support.defineCapabilityCatalog(modules);
console.log(catalog.ids(), catalog.findToolOwner('get_status')?.id);
js
import { Support } from '@jangts/agent-core';
const modules = [{ id: 'service', description: '服务查询能力', tools: [{ id: 'get_status' }] }];
const catalog = Support.defineCapabilityCatalog(modules);
console.log(catalog.ids(), catalog.findToolOwner('get_status')?.id);

增加工具引用和有序安装 ​

配置 · Node.js

ts
import { Support } from '@jangts/agent-core';
const modules = [{ id: 'service', description: '服务查询', tools: [{ id: 'get_status' }],
  references: [{ id: 'status-skill', requiredToolIds: ['get_status'], optionalToolIds: [] }] }];
const moduleCatalog = Support.defineCapabilityCatalog(modules, { toolReferences: module => module.references });
const registration = Support.defineRegistrationCatalog<{ installed: string[] }>([
  { id: 'service', register: app => { app.installed.push(moduleCatalog.require('service').id); } },
  { id: 'status-view', when: app => app.installed.includes('service'), register: app => { app.installed.push('status-view'); } },
]);
const app = { installed: [] as string[] };
registration.install(app);
console.log(app.installed);
js
import { Support } from '@jangts/agent-core';
const modules = [{ id: 'service', description: '服务查询', tools: [{ id: 'get_status' }],
        references: [{ id: 'status-skill', requiredToolIds: ['get_status'], optionalToolIds: [] }] }];
const moduleCatalog = Support.defineCapabilityCatalog(modules, { toolReferences: module => module.references });
const registration = Support.defineRegistrationCatalog([
    { id: 'service', register: app => { app.installed.push(moduleCatalog.require('service').id); } },
    { id: 'status-view', when: app => app.installed.includes('service'), register: app => { app.installed.push('status-view'); } },
]);
const app = { installed: [] };
registration.install(app);
console.log(app.installed);

相关策略源码 ​

相关定义 ​

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