feat(onebot): expose system face catalog queries

Add read-only actions for catalog retrieval, per-face lookup, search, and super-face classification. Publish matching SDK methods and generated MCP schemas, including valid face ID zero.
This commit is contained in:
DrSmoothl committed 2026-08-04 23:13:51 +08:00
1 parent 8e9a4d878e
commit c6619fda0a
11 files changed
+1257 -3

No files matched your search

+2
View File
@@ -20,6 +20,7 @@ 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';
import { actions as systemFaceActions } from './system-face';
export interface ActionGroup {
/** Domain category (= source file), surfaced to the MCP / UI for grouping. */
@@ -196,6 +197,7 @@ export const ACTION_GROUPS: readonly ActionGroup[] = [
{ category: '扩展', actions: extendedActions },
{ category: '群相册', actions: groupAlbumActions },
{ category: '空间', actions: qzoneActions },
{ category: '系统表情', actions: systemFaceActions },
{ category: '流式接口', actions: [...streamFileActions, ...streamDownloadActions] },
];
+137
View File
@@ -0,0 +1,137 @@
import { isSuperFaceEntry } from '@snowluma/protocol/oidb-services/sys-faces/fetch-sys-faces';
import type { SysFaceEntry } from '@snowluma/protocol/sys-face-store';
import { defineAction, f } from '../action-kit';
import { okResponse, type JsonObject } from '../types';
function faceEntry(face: SysFaceEntry): JsonObject {
return {
q_sid: face.qSid,
q_des: face.qDes,
em_code: face.emCode,
q_cid: face.qCid,
ani_sticker_type: face.aniStickerType,
ani_sticker_pack_id: face.aniStickerPackId,
ani_sticker_id: face.aniStickerId,
url: face.url,
emoji_name_alias: face.emojiNameAlias,
ani_sticker_width: face.aniStickerWidth,
ani_sticker_height: face.aniStickerHeight,
is_super: isSuperFaceEntry(face),
};
}
const refreshField = () => f.bool().default(false).describe('是否强制从 QQ 刷新目录');
const faceIdField = () => f.faceId().describe('QQ 系统表情编号');
const nullableInteger = { type: ['integer', 'null'] };
const nullableString = { type: ['string', 'null'] };
const faceSchema = {
type: 'object',
properties: {
q_sid: { type: 'string', description: '表情编号' },
q_des: { type: 'string', description: '表情描述' },
em_code: { type: 'string' },
q_cid: nullableInteger,
ani_sticker_type: nullableInteger,
ani_sticker_pack_id: nullableInteger,
ani_sticker_id: nullableInteger,
url: nullableString,
emoji_name_alias: { type: 'array', items: { type: 'string' } },
ani_sticker_width: nullableInteger,
ani_sticker_height: nullableInteger,
is_super: { type: 'boolean', description: '是否使用超级表情格式' },
},
required: [
'q_sid', 'q_des', 'em_code', 'q_cid', 'ani_sticker_type',
'ani_sticker_pack_id', 'ani_sticker_id', 'url', 'emoji_name_alias',
'ani_sticker_width', 'ani_sticker_height', 'is_super',
],
};
export const actions = [
defineAction({
name: 'fetch_sys_faces',
summary: '获取 QQ 系统表情目录',
readOnly: true,
returns: '按分组返回完整的 QQ 系统表情映射。',
returnsSchema: {
type: 'object',
properties: {
packs: {
type: 'array',
items: {
type: 'object',
properties: {
pack_name: { type: 'string' },
emojis: { type: 'array', items: faceSchema },
},
required: ['pack_name', 'emojis'],
},
},
},
required: ['packs'],
},
params: { refresh: refreshField() },
run: async (params, ctx) => {
const packs = await ctx.bridge.apis.systemFace.fetchCatalog(params.refresh);
return okResponse({
packs: packs.map((pack) => ({
pack_name: pack.packName,
emojis: pack.emojis.map(faceEntry),
})),
});
},
}),
defineAction({
name: 'fetch_face_entity',
summary: '按编号查询 QQ 系统表情',
readOnly: true,
returns: '表情详情;编号不存在时返回 null。',
returnsSchema: { anyOf: [faceSchema, { type: 'null' }] },
params: {
face_id: faceIdField(),
refresh: refreshField(),
},
run: async (params, ctx) => {
const face = await ctx.bridge.apis.systemFace.fetchFace(params.face_id, params.refresh);
return okResponse(face ? faceEntry(face) : null);
},
}),
defineAction({
name: 'search_sys_faces',
summary: '搜索 QQ 系统表情',
readOnly: true,
returns: '匹配编号、名称、别名或分组名的表情列表。',
returnsSchema: {
type: 'object',
properties: { faces: { type: 'array', items: faceSchema } },
required: ['faces'],
},
params: {
query: f.string({ allowEmpty: false }).describe('编号、名称、别名或分组名'),
},
run: async (params, ctx) => okResponse({
faces: (await ctx.bridge.apis.systemFace.search(params.query)).map(faceEntry),
}),
}),
defineAction({
name: 'fetch_super_face_id',
summary: '判断 QQ 系统表情是否使用超级表情格式',
readOnly: true,
returns: '是否使用超级表情格式。',
returnsSchema: {
type: 'object',
properties: { is_super: { type: 'boolean' } },
required: ['is_super'],
},
params: {
face_id: faceIdField(),
refresh: refreshField(),
},
run: async (params, ctx) => okResponse({
is_super: await ctx.bridge.apis.systemFace.isSuper(params.face_id, params.refresh),
}),
}),
];
@@ -90,9 +90,9 @@ describe('compileActionRegistry namespace conflicts', () => {
});
describe('compiled production Action registry', () => {
it('preserves all 181 canonical Action docs', () => {
expect(ACTION_REGISTRY.actions).toHaveLength(181);
expect(collectActionDocs()).toHaveLength(181);
it('preserves all 185 canonical Action docs', () => {
expect(ACTION_REGISTRY.actions).toHaveLength(185);
expect(collectActionDocs()).toHaveLength(185);
});
it('resolves every executable name to exactly one canonical doc', () => {
@@ -0,0 +1,65 @@
import { describe, expect, it, vi } from 'vitest';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
import { ApiHandler, type ApiActionContext } from '../src/api-handler';
const FACE = {
qSid: '392', qDes: '/龙年快乐', emCode: '10392', qCid: 392,
aniStickerType: 3, aniStickerPackId: 1, aniStickerId: 38,
url: 'https://example.invalid/392', emojiNameAlias: ['dragon'],
aniStickerWidth: 200, aniStickerHeight: 200,
};
function handler(systemFace: Record<string, unknown>): ApiHandler {
const bridge = { apis: { systemFace } } as unknown as BridgeInterface;
return new ApiHandler({ bridge } as ApiActionContext);
}
describe('system face actions', () => {
it('returns the full pack mapping and supports an explicit server refresh', async () => {
const fetchCatalog = vi.fn(async () => [{ packName: '超级表情', emojis: [FACE] }]);
const response = await handler({ fetchCatalog }).handle('fetch_sys_faces', { refresh: true });
expect(fetchCatalog).toHaveBeenCalledWith(true);
expect(response).toMatchObject({
status: 'ok',
data: {
packs: [{
pack_name: '超级表情',
emojis: [{ q_sid: '392', q_des: '/龙年快乐', is_super: true }],
}],
},
});
});
it('looks up one id without redownloading a fresh catalog', async () => {
const fetchFace = vi.fn(async () => FACE);
const response = await handler({ fetchFace }).handle('fetch_face_entity', { face_id: '392' });
expect(fetchFace).toHaveBeenCalledWith(392, false);
expect(response).toMatchObject({ status: 'ok', data: { q_sid: '392', q_des: '/龙年快乐' } });
});
it('accepts face id 0', async () => {
const fetchFace = vi.fn(async () => ({ ...FACE, qSid: '0', qDes: '/惊讶' }));
const response = await handler({ fetchFace }).handle('fetch_face_entity', { face_id: 0 });
expect(fetchFace).toHaveBeenCalledWith(0, false);
expect(response).toMatchObject({ status: 'ok', data: { q_sid: '0', q_des: '/惊讶' } });
});
it('searches descriptions and aliases through the shared local catalog', async () => {
const search = vi.fn(async () => [FACE]);
const response = await handler({ search }).handle('search_sys_faces', { query: 'dragon' });
expect(search).toHaveBeenCalledWith('dragon');
expect(response).toMatchObject({ status: 'ok', data: { faces: [{ q_sid: '392' }] } });
});
it('reports whether an id uses the super-face wire shape', async () => {
const isSuper = vi.fn(async () => true);
const response = await handler({ isSuper }).handle('fetch_super_face_id', { face_id: 392 });
expect(isSuper).toHaveBeenCalledWith(392, false);
expect(response).toMatchObject({ status: 'ok', data: { is_super: true } });
});
});