defineAssociatedCatalog
SUPPORT · function · Runtime value
Compile independent and owner-derived Tool declarations, validating all references eagerly.
Import
import { defineAssociatedCatalog } from '@jangts/agent-core/support';import { defineAssociatedCatalog } from '@jangts/agent-core/support';Other public entry points:@jangts/agent-core/support.
Definition
Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Entry | AssociatedRegistration | — |
Call
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 parameter | Constraint | Default type |
|---|---|---|
Entry | AssociatedRegistration | — |
| Parameter | Type | Passing | Description |
|---|---|---|---|
entries | readonly Entry[] | Required | — |
options | AssociationOptions<Entry> | Optional | — |
Fields of options
| Field | Type | Required | Description |
|---|---|---|---|
tools | readonly ModelToolRegistration[] | undefined | Optional | Read-only. See the type definition and usage context. |
toolDefaults | ((entry: Readonly<Entry>) => ModelToolRegistration | undefined) | undefined | Optional | Read-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
| Field | Type | Required | Description |
|---|---|---|---|
tools | ModelToolCatalog<any> | Required | See the type definition and usage context. |
bindings | ReadonlyCatalog<{ id: Entry["id"]; toolIds: readonly string[]; }> | Required | See the type definition and usage context. |
sources | ReadonlyCatalog<{ id: string; sources: readonly Readonly<{ toolIds: readonly string[]; kind: "standalone" | "registration"; id: string; description: string; }>[]; }> | Required | See the type definition and usage context. |
definitions | readonly Readonly<Entry>[] | Required | Read-only. Definitions in registration order; each entry is frozen by the implementation. |
ids | () => readonly string[] | Required | Ids in the same order as definitions. |
values | () => IterableIterator<Readonly<Entry>> | Required | See the type definition and usage context. |
entries | () => IterableIterator<readonly [string, Readonly<Entry>]> | Required | See the type definition and usage context. |
has | (id: string) => boolean | Required | See the type definition and usage context. |
get | (id: string) => Readonly<Entry> | undefined | Required | Returns the definition or undefined; the caller decides whether absence is an error. |
require | (id: string) => Readonly<Entry> | Required | Returns the definition or throws; use when the id is a required reference. |
Examples
- Tool module composition and declarative installation: List modules, tool references, and registration order in one place; the generic loop consumes only that actual list.
Reuse existing module declarations directly
Beginner · Node.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);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
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);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);