Skip to content
中文

ReadonlyCatalog ​

CORE · interface · Type contract

Read-only projection of a definition set; the implementation owns ordering and validation.

Import ​

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

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

Definition ​

ts
interface ReadonlyCatalog<Definition>

Type parameters ​

Type parameterConstraintDefault type
Definition{ readonly id: string }—

Field structure ​

FieldTypeRequiredDescription
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
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 ​

ids ​

Ids in the same order as definitions.

ts
ReadonlyCatalog.ids(): readonly string[]

Ids in the same order as definitions.

No call parameters.

Returns: readonly string[].

values ​

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

No call parameters.

Returns: IterableIterator<Readonly<Definition>>.

entries ​

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

No call parameters.

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

has ​

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

Returns: boolean.

get ​

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

ts
ReadonlyCatalog.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
ReadonlyCatalog.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.