AssociationOptions
SUPPORT · interface · 类型合同
Shared independent tools and a default projection from existing contracts.
导入
ts
import type { AssociationOptions } from '@jangts/agent-core/support';1
js
/** @typedef {import('@jangts/agent-core/support').AssociationOptions} AssociationOptions */1
其他公开入口:@jangts/agent-core/support。
定义
ts
interface AssociationOptions<Entry>1
泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Entry | AssociatedRegistration | — |
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
tools | readonly ModelToolRegistration[] | undefined | 可省略 | 只读。见类型定义及调用场景。 |
toolDefaults | ((entry: Readonly<Entry>) => ModelToolRegistration | undefined) | undefined | 可省略 | 只读。见类型定义及调用场景。 |
使用示例
- 能力组合与声明式安装:集中列出模块、工具引用和注册顺序;通用循环只消费这份实际清单。
- Support:推荐用法的聚合入口:Support 聚合推荐的构造、策略与同源配置生成;Core 运行不依赖这个命名空间。
直接复用现有模块声明
入门 · 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);1
2
3
4
2
3
4
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);1
2
3
4
2
3
4
增加工具引用和有序安装
配置 · 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);1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
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);1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11