Core 扩展点索引(一方扩展速查)
@aalis/core 暴露的所有 declare module 扩展点,及本仓库内谁在 augment 什么—— 便于在一方代码里查定义、查谁扩了什么。
这不是注册门禁。 第三方插件扩展任一扩展点,只需在你自己的包里写
declare module '@aalis/core' { ... }(见 plugin-author-guide), 编译期即生效——无需在本表登记,也不会(无法)出现在本表里。扩展点的权威定义在各-api包的declare module声明;本表只收录本仓库的一方包,作发现与查阅之用,并非全集。 查找一个事件/能力/钩子的真实定义,按本表"扩展者"列的包名去packages/<包目录>/src/index.ts查(一方实现;例外路径在行内标注)。
核心原则:core 自身只声明空接口,所有键值由 plugin-*-api 通过 declaration merging 注入。 这是「忒修斯之船」原则——业务概念可以全部换掉,core 永远不感知它们。
1. ServiceTypeMap
服务名 → 服务实例接口类型映射。ctx.provide(name, inst) 和 ctx.getService(name) / ctx.getAllServices(name) 在编译期靠它把服务名字面量推断成对应实例类型(未登记的名字退回 unknown)。 取用只传名字,不带任何 capabilities 参数;同名多实现时的胜者由 preference > priority > 注册顺序决定。
领域能力(LLM 的 tool-calling / vision、storage 的 local-path 等)不在这里—— 它们挂在服务实例 / model-handle 元数据上,由各领域
*-api的 helper(如resolveLLMModel)按需筛选, 而非走 core 的 DI。core 的服务注册只认名字与实例类型。
位置:packages/core/src/types/services.ts
扩展者:
每个 -api 契约包注入一条,服务名即包名去掉 api- 前缀(agent / asr / authority / code-sandbox / commands / cron-engine / doctor / embedding / flow-control / gateway / llm / media / memory / message-archive / persona / platform / process / session-confirm / session-manager / storage / tools / vectorstore / workflow),两个例外: @aalis/api-tool-session 注入 session-history,@aalis/api-webui 注入 webui-server 与 webui-client。
没有独立契约包、在自己 src/index.ts 里就地声明的插件:
| 插件包 | 注册的服务 |
|---|---|
@aalis/plugin-checkpoint | checkpoint |
@aalis/plugin-cli | cli |
@aalis/plugin-file-reader | file-reader |
@aalis/plugin-memory-vector | semantic-memory |
@aalis/plugin-package-manager | package-manager |
@aalis/plugin-scheduler | scheduler |
@aalis/plugin-skills | skills |
@aalis/plugin-trigger-policy | trigger-policy |
@aalis/plugin-user-relation | user-relation |
@aalis/plugin-websearch-serper | web-search |
2. AalisEvents
EventBus 事件签名表。ctx.on(name, handler) 在编译期靠它做事件名 + payload 约束。
位置:packages/core/src/types/events.ts。core 内置十一项,目录与时序说明以 core/events.md 为准 (没有 dispose 事件——清理副作用用 ctx.onDispose(fn),见 context)
扩展者:
| api 包 | 注入的事件键 |
|---|---|
@aalis/schema-message | inbound:message / inbound:message:archived / assistant:message:archived / outbound:message / outbound:stream |
@aalis/api-agent | token:usage / token:request |
@aalis/api-doctor | doctor:updated |
@aalis/api-gateway | gateway:phase:done |
@aalis/api-media | media:processed |
@aalis/api-memory | memory:messages-deleted / history:changed / session:compress / session:compressing |
@aalis/api-session-manager | session:created / session:updated / session:completed / session:deleted |
@aalis/api-tools | tool:execute |
@aalis/api-workflow | trigger:fired / workflow:run:start / workflow:run:done / workflow:run:error / workflow:node:done |
@aalis/plugin-scheduler | scheduler:job:start / scheduler:job:done / scheduler:job:error |
@aalis/plugin-todo-list | todo:updated |
@aalis/runtime、@aalis/plugin-cli | terminal:claimed / terminal:released(同一对键,两处等价声明) |
3. HookContextMap
中间件钩子上下文表。ctx.middleware(name, fn) 在编译期靠它推 data 类型。
位置:packages/core/src/types/hooks.ts(空 interface)
扩展者:
| api 包 | 注入的钩子键 |
|---|---|
@aalis/api-agent | agent:input:before / agent:llm:before / agent:llm:after / agent:tool:before / agent:tool:after / agent:reply:before / agent:turn:after |
@aalis/api-gateway | inbound:confirm / inbound:command / inbound:flow / inbound:trigger / inbound:dispatch / outbound:dispatch |
@aalis/api-memory | memory:clear |
4. ContributionPointMap
贡献点表:贡献点名 → spec 类型。ctx.contribute(point, spec) / ctx.collect(point) 在编译期靠它推 spec 类型。
与 HookContextMap 的分工:改写或截停既有流程 → hooks;往共享产物添自己的一块 → 贡献点。 贡献者拿只读视图、无短路、无排序影响力;排布与执行策略归收集方(贡献点 owner)。
位置:packages/core/src/types/contributions.ts(空 interface)
扩展者:
| api 包 | 注入的贡献点键 |
|---|---|
@aalis/api-agent | agent:prompt(提示词块,锚位 identity / knowledge / context / turn-context / turn-hint) |
5. AalisConfig(配置 schema 业务字段)
应用根配置的字段表。core 只声明自身管理的字段(name / logLevel / plugins / disabledPlugins / servicePreferences), 业务字段由 -api 包通过 declaration merging 注入。
位置:packages/core/src/context/config.ts(interface AalisConfig)。表单描述 CORE_CONFIG_SCHEMA 在 packages/schema-config/src/index.ts,那是宿主侧的渲染词汇,与本接口是两件事。
扩展者:
| api 包 | 注入的字段 |
|---|---|
@aalis/api-authority | owners / deniedCapabilities / authorityOverrides / confirmOverrides / restrictedPolicy / autoConfirmUntil / network |
6. Context 领域 Helper
各契约包导出 领域 helper(一个普通函数,输入 ctx,输出 typed scoped service),调用方在 apply() 内自取自用。helper 内部封装 ctx.getService 与 whenService 延迟逻辑,保留「即插即用、无需关心顺序」的体验。
扩展者:
| api 包 | 领域 helper |
|---|---|
@aalis/api-tools | useToolService(ctx) / toolsWithGroups(tools, groups) |
@aalis/api-commands | useCommandService(ctx) |
@aalis/api-webui | useWebuiService(ctx) |
@aalis/api-agent | useAgent(ctx) |
示例:
import { useToolService, toolsWithGroups } from '@aalis/api-tools';
import { useCommandService } from '@aalis/api-commands';
import { useWebuiService } from '@aalis/api-webui';
import { useAgent } from '@aalis/api-agent';
export default class MyPlugin {
apply(ctx: Context) {
const tools = toolsWithGroups(useToolService(ctx), ['my-group']);
tools.register({ definition, handler });
const commands = useCommandService(ctx);
commands.command('hello', 'hi').action(async () => 'hi');
// 注册 WebUI 页面(webui-server 未就绪时自动延迟绑定)
const webui = useWebuiService(ctx);
webui.registerPage({ key: 'my', label: '我的', icon: 'star', order: 50, renderer: 'my' });
// 注册 agent 输入预处理器
useAgent(ctx).registerPreprocessor('my-preproc', async (msg, next) => { /* ... */ await next(); });
}
}7. PluginModule
插件模块的元数据接口(core 自持 name / displayName / inject / provides / core / reusable / apply 等)。 仅供"插件类型自身"扩展使用,业务很少 augment 这个。
扩展者:
| 包 | 注入的字段 |
|---|---|
@aalis/schema-config | configSchema(插件配置表单 schema,默认值经 defaultsFrom 派生) |
@aalis/api-webui | subsystem(WebUI 分组)/ extends(对 core 扩展的声明,仅前端展示)/ actions(插件 RPC 动作表) |
8. 各服务的 XxxCapabilityRegistry
按服务隔离的能力注册表。每个服务自己定义一个 XxxCapabilityRegistry interface, 第三方插件可以 augment 它新增能力字面量。
示例:
LLMCapabilityRegistry(packages/api-llm/src/index.ts)— LLM 能力
第三方扩展示例:
declare module '@aalis/api-llm' {
interface LLMCapabilityRegistry {
AudioInput: 'audio_input';
}
}速查:我想……
- 加一个新事件 → 在自己的
*-api包内declare module '@aalis/core' { interface AalisEvents { ... } } - 加一个新钩子 → 同上但写
HookContextMap - 加一个新贡献点 → 同上但写
ContributionPointMap(spec 须含id: string) - 加一个新服务名 → 同上但写
ServiceTypeMap(服务名 → 服务实例接口类型)。领域能力不在这里登记——按需在自己的*-api里把它们放到服务实例 / model-handle 元数据上,用 helper 筛选(可选XxxCapabilityRegistry见第 8 节) - 加一个
ctx.xxx()便捷方法 → 在*-api包用declare module '@aalis/core' { interface Context { xxx(...): ...; } },并在 plugin 实现里Context.prototype.xxx = ...。慎用——优先考虑改成 Service。 - 加一个配置字段 → 在
*-api包declare module '@aalis/core' { interface AalisConfig { myField: ... } },并提供 schema 给 ConfigManager