RegistrationDefinition
SUPPORT · interface · 类型合同
One install step.
导入
ts
import type { RegistrationDefinition } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').RegistrationDefinition} RegistrationDefinition */其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/support。
定义
ts
interface RegistrationDefinition<Context>泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Context | — | — |
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
id | string | 必需 | 只读。Unique step id; also the catalog key. |
when | ((context: Context) => boolean) | undefined | 可省略 | 只读。Installs the step when true; must be synchronous and is re-evaluated per install. |
register | (context: Context) => void | 必需 | 只读。Performs the installation; must return void synchronously. |
成员目录
| 成员 | 用途 |
|---|---|
register | Performs the installation; must return void synchronously. |
成员详情
register
Performs the installation; must return void synchronously.
ts
RegistrationDefinition.register(context: Context): void| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
context | Context | 必需 | — |
返回: void。
使用示例
- 能力组合与声明式安装:集中列出模块、工具引用和注册顺序;通用循环只消费这份实际清单。
直接复用现有模块声明
入门 · 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);增加工具引用和有序安装
配置 · 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);