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

+17 -25
View File
@@ -1,21 +1,11 @@
import { renderParamsVerbose, summarizeParams } from '@snowluma/common/log-summary';
import { createLogger, getLogLevel, nextRequestId, runWithRequestId, type Logger } from '@snowluma/common/logger';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
import { register as registerExtended } from './actions/extended';
import { register as registerFriend } from './actions/friend';
import { register as registerGroupAdmin } from './actions/group-admin';
import { register as registerGroupAlbum } from './actions/group-album';
import { register as registerGroupFile } from './actions/group-file';
import { register as registerGroupInfo } from './actions/group-info';
import { register as registerInfo } from './actions/info';
import { register as registerMessage } from './actions/message';
import { register as registerQzone } from './actions/qzone';
import { register as registerRequest } from './actions/request';
import { register as registerStreamFile } from './actions/stream-file';
import { register as registerStreamDownload } from './actions/stream-download';
import { ALL_ACTIONS } from './actions';
import { registerActions } from './action-kit';
import type { ForwardPreviewMeta } from './modules/message-actions';
import type { JsonObject, JsonValue, MessageMeta } from './types';
import { RETCODE, failedResponse } from './types';
import { RETCODE, failedResponse, okResponse } from './types';
import { type StreamSink, wrapStreamFrame, wrapStreamTerminal } from './streaming';
const moduleLog = createLogger('Bridge.Action');
@@ -112,18 +102,20 @@ export class ApiHandler {
constructor(context: ApiActionContext, uin?: number) {
this.log = typeof uin === 'number' && uin > 0 ? moduleLog.child({ uin }) : moduleLog;
registerInfo(this, context);
registerMessage(this, context);
registerFriend(this, context);
registerGroupInfo(this, context);
registerGroupAdmin(this, context);
registerGroupFile(this, context);
registerRequest(this, context);
registerExtended(this, context);
registerGroupAlbum(this, context);
registerQzone(this, context);
registerStreamFile(this, context);
registerStreamDownload(this, context);
registerActions(this, context, ALL_ACTIONS);
// The one non-ActionSpec handler: `.handle_quick_operation` needs the
// ApiHandler itself (to re-drive actions via executeQuickOperation), which
// ActionSpec.run's (params, ctx) signature can't supply — so it's the sole
// raw registration, kept here rather than in an action file's footer.
this.registerAction('.handle_quick_operation', async (params) => {
const opContext = params.context as JsonObject | undefined;
const operation = params.operation as Record<string, unknown> | undefined;
if (!opContext || !operation) return failedResponse(RETCODE.BAD_REQUEST, 'context and operation are required');
const { executeQuickOperation } = await import('./network/quick-operation');
await executeQuickOperation(opContext, operation, this);
return okResponse();
});
}
registerAction(action: string, handler: ActionHandler): void {