defineRegistrationCatalog
SUPPORT · function · Runtime value
Compile an ordered installation plan.
Predicates observe the effects of preceding installations at request time; a predicate that throws rejects the install instead of being treated as false. Callbacks are bound to their declaring definition so implementations may rely on this.
Import
import { defineRegistrationCatalog } from '@jangts/agent-core/support';import { defineRegistrationCatalog } from '@jangts/agent-core/support';Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/support.
Definition
Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Context | — | — |
Call
defineRegistrationCatalog<Context>(definitions: readonly RegistrationDefinition<Context>[]): Readonly<{ install(context: Context): void; definitions: readonly Readonly<{ id: string; when: ((context: Context) => boolean) | undefined; register: (context: Context) => void; }>[]; ids(): readonly string[]; values(): IterableIterator<Readonly<{ id: string; when: ((context: Context) => boolean) | undefined; register: (context: Context) => void; }>>; entries(): IterableIterator<readonly [string, Readonly<{ id: string; when: ((context: Context) => boolean) | undefined; register: (context: Context) => void; }>]>; has(id: string): boolean; get(id: string): Readonly<{ id: string; when: ((context: Context) => boolean) | undefined; register: (context: Context) => void; }> | undefined; require(id: string): Readonly<{ id: string; when: ((context: Context) => boolean) | undefined; register: (context: Context) => void; }>; }>Compile an ordered installation plan.
Predicates observe the effects of preceding installations at request time; a predicate that throws rejects the install instead of being treated as false. Callbacks are bound to their declaring definition so implementations may rely on this.
| Type parameter | Constraint | Default type |
|---|---|---|
Context | — | — |
| Parameter | Type | Passing | Description |
|---|---|---|---|
definitions | readonly RegistrationDefinition<Context>[] | Required | — |
Returns: Readonly<{ install(context: Context): void; definitions: readonly Readonly<{ id: string; when: ((context: Context) => boolean) \| undefined; register: (context: Context) => void; }>[]; ids(): readonly string[]; values(): IterableIterator<Readonly<{ id: string; when: ((context: Context) => boolean) \| undefined; register: (context: Context) => void; }>>; entries(): IterableIterator<readonly [string, Readonly<{ id: string; when: ((context: Context) => boolean) \| undefined; register: (context: Context) => void; }>]>; has(id: string): boolean; get(id: string): Readonly<{ id: string; when: ((context: Context) => boolean) \| undefined; register: (context: Context) => void; }> \| undefined; require(id: string): Readonly<{ id: string; when: ((context: Context) => boolean) \| undefined; register: (context: Context) => void; }>; }>.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
install | (context: Context) => void | Required | Run every enabled step in declaration order against context. Stops at the first failing predicate or handler; earlier installations are not rolled back. |
definitions | readonly Readonly<{ id: string; when: ((context: Context) => boolean) | undefined; register: (context: Context) => void; }>[] | 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<{ id: string; when: ((context: Context) => boolean) | undefined; register: (context: Context) => void; }>> | Required | See the type definition and usage context. |
entries | () => IterableIterator<readonly [string, Readonly<{ id: string; when: ((context: Context) => boolean) | undefined; register: (context: Context) => void; }>]> | Required | See the type definition and usage context. |
has | (id: string) => boolean | Required | See the type definition and usage context. |
get | (id: string) => Readonly<{ id: string; when: ((context: Context) => boolean) | undefined; register: (context: Context) => void; }> | undefined | Required | Returns the definition or undefined; the caller decides whether absence is an error. |
require | (id: string) => Readonly<{ id: string; when: ((context: Context) => boolean) | undefined; register: (context: Context) => void; }> | 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);