Skip to content
中文

Registry ​

CORE · interface · Type contract

Mutable catalog. Registrations append; seal freezes the set against later writes.

Import ​

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

Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs.

Definition ​

ts
interface Registry<Definition>

Extends or implements: ReadonlyCatalog<Definition>.

Type parameters ​

Type parameterConstraintDefault type
Definition{ readonly id: string }—

Field structure ​

FieldTypeRequiredDescription
register(definition: Definition) => Registry<Definition>RequiredAdds one definition; implementations reject blank or duplicate ids.
registerAll(definitions: Iterable<Definition>) => Registry<Definition>RequiredSee the type definition and usage context.
seal() => Registry<Definition>RequiredRejects every later registration on this instance.
definitionsreadonly Readonly<Definition>[]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<Definition>>RequiredSee the type definition and usage context.
entries() => IterableIterator<readonly [string, Readonly<Definition>]>RequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => Readonly<Definition> | undefinedRequiredReturns the definition or undefined; the caller decides whether absence is an error.
require(id: string) => Readonly<Definition>RequiredReturns the definition or throws; use when the id is a required reference.

Member index ​

MemberPurpose
registerAdds one definition; implementations reject blank or duplicate ids.
registerAllSee the overload below for full inputs and outputs.
sealRejects every later registration on this instance.
idsIds in the same order as definitions.
valuesSee the overload below for full inputs and outputs.
entriesSee the overload below for full inputs and outputs.
hasSee the overload below for full inputs and outputs.
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.

Member details ​

register ​

Adds one definition; implementations reject blank or duplicate ids.

ts
Registry.register(definition: Definition): Registry<Definition>

Adds one definition; implementations reject blank or duplicate ids.

ParameterTypePassingDescription
definitionDefinitionRequired—

Returns: Registry<Definition>.

Return value structure
FieldTypeRequiredDescription
register(definition: Definition) => Registry<Definition>RequiredAdds one definition; implementations reject blank or duplicate ids.
registerAll(definitions: Iterable<Definition>) => Registry<Definition>RequiredSee the type definition and usage context.
seal() => Registry<Definition>RequiredRejects every later registration on this instance.
definitionsreadonly Readonly<Definition>[]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<Definition>>RequiredSee the type definition and usage context.
entries() => IterableIterator<readonly [string, Readonly<Definition>]>RequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => Readonly<Definition> | undefinedRequiredReturns the definition or undefined; the caller decides whether absence is an error.
require(id: string) => Readonly<Definition>RequiredReturns the definition or throws; use when the id is a required reference.

registerAll ​

ts
Registry.registerAll(definitions: Iterable<Definition>): Registry<Definition>
ParameterTypePassingDescription
definitionsIterable<Definition>Required—

Returns: Registry<Definition>.

Return value structure
FieldTypeRequiredDescription
register(definition: Definition) => Registry<Definition>RequiredAdds one definition; implementations reject blank or duplicate ids.
registerAll(definitions: Iterable<Definition>) => Registry<Definition>RequiredSee the type definition and usage context.
seal() => Registry<Definition>RequiredRejects every later registration on this instance.
definitionsreadonly Readonly<Definition>[]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<Definition>>RequiredSee the type definition and usage context.
entries() => IterableIterator<readonly [string, Readonly<Definition>]>RequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => Readonly<Definition> | undefinedRequiredReturns the definition or undefined; the caller decides whether absence is an error.
require(id: string) => Readonly<Definition>RequiredReturns the definition or throws; use when the id is a required reference.

seal ​

Rejects every later registration on this instance.

ts
Registry.seal(): Registry<Definition>

Rejects every later registration on this instance.

No call parameters.

Returns: Registry<Definition>.

Return value structure
FieldTypeRequiredDescription
register(definition: Definition) => Registry<Definition>RequiredAdds one definition; implementations reject blank or duplicate ids.
registerAll(definitions: Iterable<Definition>) => Registry<Definition>RequiredSee the type definition and usage context.
seal() => Registry<Definition>RequiredRejects every later registration on this instance.
definitionsreadonly Readonly<Definition>[]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<Definition>>RequiredSee the type definition and usage context.
entries() => IterableIterator<readonly [string, Readonly<Definition>]>RequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => Readonly<Definition> | undefinedRequiredReturns the definition or undefined; the caller decides whether absence is an error.
require(id: string) => Readonly<Definition>RequiredReturns the definition or throws; use when the id is a required reference.

ids ​

Ids in the same order as definitions.

ts
Registry.ids(): readonly string[]

Ids in the same order as definitions.

No call parameters.

Returns: readonly string[].

values ​

ts
Registry.values(): IterableIterator<Readonly<Definition>>

No call parameters.

Returns: IterableIterator<Readonly<Definition>>.

entries ​

ts
Registry.entries(): IterableIterator<readonly [string, Readonly<Definition>]>

No call parameters.

Returns: IterableIterator<readonly [string, Readonly<Definition>]>.

has ​

ts
Registry.has(id: string): boolean
ParameterTypePassingDescription
idstringRequired—

Returns: boolean.

get ​

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

ts
Registry.get(id: string): Readonly<Definition> | undefined

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

ParameterTypePassingDescription
idstringRequired—

Returns: Readonly<Definition> \| undefined.

Optional shapes of Return value: choose one shape; required fields for each branch are listed separately.

Branch 1

undefined

Branch 2
FieldTypeRequiredDescription
idDefinition["id"]RequiredRead-only. See the type definition and usage context.

require ​

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

ts
Registry.require(id: string): Readonly<Definition>

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

ParameterTypePassingDescription
idstringRequired—

Returns: Readonly<Definition>.

Return value structure
FieldTypeRequiredDescription
idDefinition["id"]RequiredRead-only. See the type definition and usage context.

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.