refactor(api): move Tier-2 extras to ExtrasApi (#6 commit 11/13)

Inlines `actions/extras.ts` into `apis/extras.ts::ExtrasApi`. Covers
the napcat-parity Tier-2 surface: group todo CRUD (0xF90_1/2/3),
stranger online/ext status decode (0xFE1_2), and AI voice list +
synthesis (0x929D / 0x929B).

`StrangerStatus`, `AiVoiceChatType`, `AiVoiceCategory`, `AiVoiceItem`
are now exported from `apis/extras.ts` and re-exported through
`bridge.ts` for backwards compatibility (the OneBot side imports
them via `@snowluma/core`).

No renaming — the names already read cleanly under `apis.extras.X`.

The `fetchAiVoiceList` / `fetchAiVoice` chatType parameter is widened
to `AiVoiceChatType | number` because the OneBot side passes a raw
number from JSON. The wire encoder is happy with any integer; the
strict enum just gives autocompletion at call sites that have it.

Callers updated: `actions/extended.ts` (7 sites).
Tests rewritten:
  - `extras.test.ts` → uses `new ExtrasApi(bridge as any).method(...)`
    and the it.each dispatch switches to method-name strings.
  - `extended-actions.test.ts` APIS_ROUTING gains the extras block.

587/587 tests pass.
This commit is contained in:
DrSmoothl committed 2026-05-20 23:40:57 +08:00
1 parent e5ac2a61b1
commit 22add4ad1c
8 files changed
+205 -204

No files matched your search

+8 -8
View File
@@ -1170,18 +1170,18 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
return failedResponse(RETCODE.ACTION_FAILED, err instanceof Error ? err.message : String(err));
}
};
h.registerAction('set_group_todo', handleGroupTodo((g, s) => ctx.bridge.setGroupTodo(g, s)));
h.registerAction('complete_group_todo', handleGroupTodo((g, s) => ctx.bridge.completeGroupTodo(g, s)));
h.registerAction('cancel_group_todo', handleGroupTodo((g, s) => ctx.bridge.cancelGroupTodo(g, s)));
h.registerAction('set_group_todo', handleGroupTodo((g, s) => ctx.bridge.apis.extras.setGroupTodo(g, BigInt(s))));
h.registerAction('complete_group_todo', handleGroupTodo((g, s) => ctx.bridge.apis.extras.completeGroupTodo(g, BigInt(s))));
h.registerAction('cancel_group_todo', handleGroupTodo((g, s) => ctx.bridge.apis.extras.cancelGroupTodo(g, BigInt(s))));
// --- User online/ext status (napcat: nc_get_user_status) ---
h.registerAction('nc_get_user_status', async (params) => {
const userId = asNumber(params.user_id);
if (!userId) return failedResponse(RETCODE.BAD_REQUEST, 'user_id is required');
const status = await ctx.bridge.getStrangerStatus(userId);
const status = await ctx.bridge.apis.extras.getStrangerStatus(userId);
if (!status) return failedResponse(RETCODE.ACTION_FAILED, 'failed to fetch user status');
return okResponse(status);
return okResponse({ ...status });
});
// --- AI voice (oidb 0x929D / 0x929B) ---
@@ -1191,7 +1191,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
const chatType = asNumber(params.chat_type) || 1;
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
try {
const list = await ctx.bridge.fetchAiVoiceList(groupId, chatType);
const list = await ctx.bridge.apis.extras.fetchAiVoiceList(groupId, chatType);
return okResponse(list.map((cat) => ({
type: cat.category,
characters: cat.voices.map((v) => ({
@@ -1214,7 +1214,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
return failedResponse(RETCODE.BAD_REQUEST, 'group_id, character and text are required');
}
try {
const node = await ctx.bridge.fetchAiVoice(groupId, character, text, chatType);
const node = await ctx.bridge.apis.extras.fetchAiVoice(groupId, character, text, chatType);
const url = await ctx.bridge.apis.groupFile.getPttUrl(groupId, node);
return okResponse(url);
} catch (err) {
@@ -1234,7 +1234,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
return failedResponse(RETCODE.BAD_REQUEST, 'group_id, character and text are required');
}
try {
await ctx.bridge.fetchAiVoice(groupId, character, text, chatType);
await ctx.bridge.apis.extras.fetchAiVoice(groupId, character, text, chatType);
return okResponse({ message_id: 0 });
} catch (err) {
return failedResponse(RETCODE.ACTION_FAILED, err instanceof Error ? err.message : String(err));