Skip to content
中文

defineAssociatedCatalog ​

SUPPORT · function · Runtime value

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

Import ​

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

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

Definition ​

Type parameters ​

Type parameterConstraintDefault type
EntryAssociatedRegistration—

Call ​

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.

Type parameterConstraintDefault type
EntryAssociatedRegistration—
ParameterTypePassingDescription
entriesreadonly Entry[]Required—
optionsAssociationOptions<Entry>Optional—
Fields of options
FieldTypeRequiredDescription
toolsreadonly ModelToolRegistration[] | undefinedOptionalRead-only. See the type definition and usage context.
toolDefaults((entry: Readonly<Entry>) => ModelToolRegistration | undefined) | undefinedOptionalRead-only. See the type definition and usage context.

Returns: 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>; }>.

Return value structure
FieldTypeRequiredDescription
toolsModelToolCatalog<any>RequiredSee the type definition and usage context.
bindingsReadonlyCatalog<{ id: Entry["id"]; toolIds: readonly string[]; }>RequiredSee the type definition and usage context.
sourcesReadonlyCatalog<{ id: string; sources: readonly Readonly<{ toolIds: readonly string[]; kind: "standalone" | "registration"; id: string; description: string; }>[]; }>RequiredSee the type definition and usage context.
definitionsreadonly Readonly<Entry>[]RequiredRead-only. Definitions in registration order; each entry is frozen by the implementation.
ids() => readonly string[]RequiredIds in the same order as definitions.
values() => IterableIterator<Readonly<Entry>>RequiredSee the type definition and usage context.
entries() => IterableIterator<readonly [string, Readonly<Entry>]>RequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => Readonly<Entry> | undefinedRequiredReturns the definition or undefined; the caller decides whether absence is an error.
require(id: string) => Readonly<Entry>RequiredReturns the definition or throws; use when the id is a required reference.

Examples ​

Reuse existing module declarations directly ​

Beginner · 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);

Add tool references and ordered installation ​

Configuration · 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);

API reference, usage examples and developer guides.