refactor(onebot): collapse action registration into a single barrel

加一个 action 文件原本要同步改三处手写清单:ApiHandler 的 12 个 register import +
12 行构造调用、各文件的 register footer、action-docs 的 13 import + GROUPS。现收敛
成一个 actions/index.ts barrel 作为「文件→动作 + 分类」的单一真相。

- action-kit:抽 RegisteredActionSpec(describe+register),ActionSpec/
  StreamActionSpec extends 它,registerActions 参数放宽到 RegisteredActionSpec[]
  (它只调 .register),于是 stream 动作也能并入统一注册。
- 新增 actions/index.ts:ACTION_GROUPS(11 组含分类,stream 合并)+ ALL_ACTIONS。
- api-handler:12 import+12 调用 → registerActions(this, context, ALL_ACTIONS);
  .handle_quick_operation(唯一非 ActionSpec 的裸 handler,需要 h 本身)从
  extended 搬进构造器一处显式注册。
- action-docs:改用 barrel 的 ACTION_GROUPS,删本地 GROUPS + 13 import。
- 删 12 个 register footer + 清理因此变 unused 的 ApiHandler/ApiActionContext import。

行为严格不变:注册的动作集合、.handle_quick_operation、文档分类/计数均一致。
onebot 516 全绿、全仓 12 包 typecheck Done;对抗性 Agent 逐条对比 HEAD 确认等价。
This commit is contained in:
DrSmoothl committed 2026-07-01 17:49:07 +08:00
1 parent b6cde5101d
commit 891a197335
16 files changed
+98 -139

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
// Action registry barrel — the single source of "which files contribute which
// actions", replacing three hand-synced lists that had to stay in lock-step:
// 1. ApiHandler's 12 `register as registerX` imports + 12 constructor calls,
// 2. each file's `export function register(h, ctx)` footer,
// 3. action-docs' own 13 imports + GROUPS array.
// Adding an action file now means editing exactly one place: ACTION_GROUPS.
//
// "Source file = domain category" is the existing convention (see action-docs),
// so the category label lives here too, making ACTION_GROUPS serve both runtime
// registration (via ALL_ACTIONS) and the doc collector (via the groups).
import type { RegisteredActionSpec } from '../action-kit';
import { actions as infoActions } from './info';
import { actions as messageActions } from './message';
import { actions as friendActions } from './friend';
import { actions as groupInfoActions } from './group-info';
import { actions as groupAdminActions } from './group-admin';
import { actions as groupFileActions } from './group-file';
import { actions as requestActions } from './request';
import { actions as extendedActions } from './extended';
import { actions as groupAlbumActions } from './group-album';
import { actions as qzoneActions } from './qzone';
import { actions as streamFileActions } from './stream-file';
import { actions as streamDownloadActions } from './stream-download';
export interface ActionGroup {
/** Domain category (= source file), surfaced to the MCP / UI for grouping. */
readonly category: string;
readonly actions: readonly RegisteredActionSpec[];
}
/** Every action, grouped by domain category. The single source of truth. */
export const ACTION_GROUPS: readonly ActionGroup[] = [
{ category: '信息', actions: infoActions },
{ category: '消息', actions: messageActions },
{ category: '好友', actions: friendActions },
{ category: '群信息', actions: groupInfoActions },
{ category: '群管理', actions: groupAdminActions },
{ category: '群文件', actions: groupFileActions },
{ category: '请求', actions: requestActions },
{ category: '扩展', actions: extendedActions },
{ category: '群相册', actions: groupAlbumActions },
{ category: '空间', actions: qzoneActions },
{ category: '流式接口', actions: [...streamFileActions, ...streamDownloadActions] },
];
/** Flat list of every action spec, for one-shot registration onto an ApiHandler. */
export const ALL_ACTIONS: readonly RegisteredActionSpec[] = ACTION_GROUPS.flatMap((g) => g.actions);