@zhin.js/adapter-napcat 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +674 -0
- package/README.md +60 -95
- package/adapters/napcat.js +47 -0
- package/adapters/napcat.ts +64 -0
- package/agent/PERMITS.md +19 -0
- package/{skills/napcat/SKILL.md → agent/skills/napcat.md} +6 -6
- package/agent/tools/ai_tts.ts +19 -0
- package/agent/tools/del_group_notice.ts +20 -0
- package/agent/tools/delete_essence_msg.ts +19 -0
- package/agent/tools/delete_friend.ts +18 -0
- package/agent/tools/download_file.ts +17 -0
- package/agent/tools/forward_single_msg.ts +28 -0
- package/agent/tools/get_ai_characters.ts +17 -0
- package/agent/tools/get_essence_list.ts +17 -0
- package/agent/tools/get_friend_msg_history.ts +18 -0
- package/agent/tools/get_group_file_url.ts +19 -0
- package/agent/tools/get_group_info_ex.ts +17 -0
- package/agent/tools/get_group_msg_history.ts +19 -0
- package/agent/tools/get_group_notice.ts +17 -0
- package/agent/tools/get_group_root_files.ts +17 -0
- package/agent/tools/get_group_shut_list.ts +17 -0
- package/agent/tools/get_mini_app_ark.ts +20 -0
- package/agent/tools/get_user_status.ts +16 -0
- package/agent/tools/group_sign.ts +18 -0
- package/agent/tools/mark_msg_as_read.ts +17 -0
- package/agent/tools/ocr_image.ts +16 -0
- package/agent/tools/send_forward_msg.ts +27 -0
- package/agent/tools/send_group_notice.ts +21 -0
- package/agent/tools/send_like.ts +18 -0
- package/agent/tools/send_poke.ts +18 -0
- package/agent/tools/set_avatar.ts +17 -0
- package/agent/tools/set_emoji_reaction.ts +18 -0
- package/agent/tools/set_essence_msg.ts +19 -0
- package/agent/tools/set_group_portrait.ts +20 -0
- package/agent/tools/set_online_status.ts +18 -0
- package/agent/tools/set_profile.ts +21 -0
- package/agent/tools/set_signature.ts +17 -0
- package/agent/tools/set_title.ts +21 -0
- package/agent/tools/translate.ts +16 -0
- package/agent/tools/upload_group_file.ts +21 -0
- package/commands/endpoint/add/[id].js +3 -0
- package/commands/endpoint/add/[id].ts +3 -0
- package/commands/endpoint/list.js +3 -0
- package/commands/endpoint/list.ts +3 -0
- package/commands/endpoint/remove/[id].js +3 -0
- package/commands/endpoint/remove/[id].ts +3 -0
- package/lib/client.d.ts +52 -0
- package/lib/client.js +62 -0
- package/lib/endpoint-management.d.ts +15 -0
- package/lib/endpoint-management.js +47 -0
- package/lib/http-endpoint.d.ts +27 -0
- package/lib/http-endpoint.js +177 -0
- package/lib/index.d.ts +11 -22
- package/lib/index.js +10 -58
- package/lib/napcat-endpoint-commands.d.ts +1 -0
- package/lib/napcat-endpoint-commands.js +28 -0
- package/lib/napcat-inbound.d.ts +12 -5
- package/lib/napcat-inbound.js +28 -13
- package/lib/napcat-runtime-state.d.ts +1 -0
- package/lib/napcat-runtime-state.js +6 -0
- package/lib/onebot-get-msg.d.ts +16 -3
- package/lib/onebot-get-msg.js +53 -1
- package/lib/protocol.d.ts +165 -0
- package/lib/protocol.js +305 -0
- package/lib/side-event-dispatch.d.ts +7 -0
- package/lib/side-event-dispatch.js +36 -0
- package/lib/webhook.d.ts +2 -0
- package/lib/webhook.js +14 -0
- package/lib/ws-endpoint.d.ts +27 -0
- package/lib/ws-endpoint.js +241 -0
- package/lib/ws-transport.d.ts +13 -0
- package/lib/ws-transport.js +75 -0
- package/lib/ws-types.d.ts +17 -0
- package/lib/ws-types.js +1 -0
- package/lib/wss-auth.d.ts +2 -0
- package/lib/wss-auth.js +16 -0
- package/lib/wss-endpoint.d.ts +26 -0
- package/lib/wss-endpoint.js +187 -0
- package/package.json +62 -30
- package/plugin.js +18 -0
- package/schema.json +110 -0
- package/src/client.ts +79 -0
- package/src/endpoint-management.ts +72 -0
- package/src/http-endpoint.ts +234 -0
- package/src/index.ts +63 -85
- package/src/napcat-endpoint-commands.ts +26 -0
- package/src/napcat-inbound.ts +34 -10
- package/src/napcat-runtime-state.ts +7 -0
- package/src/onebot-get-msg.ts +69 -5
- package/src/protocol.ts +468 -0
- package/src/side-event-dispatch.ts +48 -0
- package/src/webhook.ts +16 -0
- package/src/ws-endpoint.ts +301 -0
- package/src/ws-transport.ts +105 -0
- package/src/ws-types.ts +20 -0
- package/src/wss-auth.ts +17 -0
- package/src/wss-endpoint.ts +242 -0
- package/client/NapCatManagement.tsx +0 -113
- package/client/index.tsx +0 -11
- package/client/tsconfig.json +0 -7
- package/client/utils/api.ts +0 -30
- package/dist/index.js +0 -27
- package/lib/adapter.d.ts +0 -27
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -93
- package/lib/adapter.js.map +0 -1
- package/lib/agent-prompt.d.ts +0 -3
- package/lib/agent-prompt.d.ts.map +0 -1
- package/lib/agent-prompt.js +0 -105
- package/lib/agent-prompt.js.map +0 -1
- package/lib/bot-base.d.ts +0 -143
- package/lib/bot-base.d.ts.map +0 -1
- package/lib/bot-base.js +0 -334
- package/lib/bot-base.js.map +0 -1
- package/lib/bot-http.d.ts +0 -18
- package/lib/bot-http.d.ts.map +0 -1
- package/lib/bot-http.js +0 -119
- package/lib/bot-http.js.map +0 -1
- package/lib/bot-ws-client.d.ts +0 -21
- package/lib/bot-ws-client.d.ts.map +0 -1
- package/lib/bot-ws-client.js +0 -165
- package/lib/bot-ws-client.js.map +0 -1
- package/lib/bot-ws-server.d.ts +0 -21
- package/lib/bot-ws-server.d.ts.map +0 -1
- package/lib/bot-ws-server.js +0 -150
- package/lib/bot-ws-server.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/napcat-inbound.d.ts.map +0 -1
- package/lib/napcat-inbound.js.map +0 -1
- package/lib/onebot-get-msg.d.ts.map +0 -1
- package/lib/onebot-get-msg.js.map +0 -1
- package/lib/routes.d.ts +0 -4
- package/lib/routes.d.ts.map +0 -1
- package/lib/routes.js +0 -61
- package/lib/routes.js.map +0 -1
- package/lib/tools.d.ts +0 -8
- package/lib/tools.d.ts.map +0 -1
- package/lib/tools.js +0 -605
- package/lib/tools.js.map +0 -1
- package/lib/types.d.ts +0 -293
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -6
- package/lib/types.js.map +0 -1
- package/lib/typing-indicator.d.ts +0 -45
- package/lib/typing-indicator.d.ts.map +0 -1
- package/lib/typing-indicator.js +0 -132
- package/lib/typing-indicator.js.map +0 -1
- package/plugin.yml +0 -3
- package/src/adapter.ts +0 -99
- package/src/agent-prompt.ts +0 -114
- package/src/bot-base.ts +0 -376
- package/src/bot-http.ts +0 -109
- package/src/bot-ws-client.ts +0 -164
- package/src/bot-ws-server.ts +0 -150
- package/src/routes.ts +0 -61
- package/src/tools.ts +0 -632
- package/src/types.ts +0 -279
- package/src/typing-indicator.ts +0 -184
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ type: string; title: string; desc: string; pic_url: string; jump_url: string }>({
|
|
5
|
+
description: '签名小程序卡片(如 B 站分享卡片等)。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
type: z.string().describe('卡片类型'),
|
|
8
|
+
title: z.string().describe('标题'),
|
|
9
|
+
desc: z.string().describe('描述'),
|
|
10
|
+
pic_url: z.string().describe('图片 URL'),
|
|
11
|
+
jump_url: z.string().describe('跳转 URL'),
|
|
12
|
+
}),
|
|
13
|
+
adapter: 'napcat',
|
|
14
|
+
tags: ['napcat', 'qq'],
|
|
15
|
+
keywords: ['小程序', 'mini app', '卡片', 'ark'],
|
|
16
|
+
async execute({ type, title, desc, pic_url, jump_url }: { type: string; title: string; desc: string; pic_url: string; jump_url: string }, context) {
|
|
17
|
+
const endpoint = context.$client;
|
|
18
|
+
return endpoint.getMiniAppArk(type, title, desc, pic_url, jump_url);
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ user_id: number }>({
|
|
5
|
+
description: '获取用户在线状态。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
user_id: z.number().describe('目标 QQ 号'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'napcat',
|
|
10
|
+
tags: ['napcat', 'qq'],
|
|
11
|
+
keywords: ['在线状态', '用户状态', 'online status'],
|
|
12
|
+
async execute({ user_id }: { user_id: number }, context) {
|
|
13
|
+
const endpoint = context.$client;
|
|
14
|
+
return endpoint.ncGetUserStatus(user_id);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ group_id: number }>({
|
|
5
|
+
description: '群签到/群打卡。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
group_id: z.number().describe('群号'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'napcat',
|
|
10
|
+
tags: ['napcat', 'qq'],
|
|
11
|
+
keywords: ['签到', '打卡', 'sign', 'check in'],
|
|
12
|
+
scopes: ['group'],
|
|
13
|
+
async execute({ group_id }: { group_id: number }, context) {
|
|
14
|
+
const endpoint = context.$client;
|
|
15
|
+
await endpoint.sendGroupSign(group_id);
|
|
16
|
+
return { success: true };
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ message_id: number }>({
|
|
5
|
+
description: '标记消息为已读。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
message_id: z.number().describe('消息 ID'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'napcat',
|
|
10
|
+
tags: ['napcat', 'qq'],
|
|
11
|
+
keywords: ['已读', 'mark read', '标记已读'],
|
|
12
|
+
async execute({ message_id }: { message_id: number }, context) {
|
|
13
|
+
const endpoint = context.$client;
|
|
14
|
+
await endpoint.markMsgAsRead(message_id);
|
|
15
|
+
return { success: true };
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ image: string }>({
|
|
5
|
+
description: '图片 OCR 文字识别。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
image: z.string().describe('图片 file 参数(收到消息中的 file 字段或 URL)'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'napcat',
|
|
10
|
+
tags: ['napcat', 'qq'],
|
|
11
|
+
keywords: ['OCR', '文字识别', '图片识别', 'ocr'],
|
|
12
|
+
async execute({ image }: { image: string }, context) {
|
|
13
|
+
const endpoint = context.$client;
|
|
14
|
+
return endpoint.ocrImage(image);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{
|
|
5
|
+
message_type: 'private' | 'group';
|
|
6
|
+
id: number;
|
|
7
|
+
messages: string;
|
|
8
|
+
}>({
|
|
9
|
+
description: '发送合并转发消息(群聊或私聊)。messages 为转发节点数组。',
|
|
10
|
+
inputSchema: z.object({
|
|
11
|
+
message_type: z.enum(['private', 'group']).describe('private 或 group'),
|
|
12
|
+
id: z.number().describe('群号或 QQ 号'),
|
|
13
|
+
messages: z.string().describe('转发节点 JSON(node 数组)'),
|
|
14
|
+
}),
|
|
15
|
+
adapter: 'napcat',
|
|
16
|
+
tags: ['napcat', 'qq'],
|
|
17
|
+
keywords: ['合并转发', 'forward', '转发消息'],
|
|
18
|
+
async execute({ message_type, id, messages }: {
|
|
19
|
+
message_type: 'private' | 'group';
|
|
20
|
+
id: number;
|
|
21
|
+
messages: string;
|
|
22
|
+
}, context) {
|
|
23
|
+
const endpoint = context.$client;
|
|
24
|
+
const nodes = typeof messages === 'string' ? JSON.parse(messages) : messages;
|
|
25
|
+
return endpoint.sendForwardMsg(message_type, id, nodes);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ group_id: number; content: string; image?: string }>({
|
|
5
|
+
description: '发送群公告。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
group_id: z.number().describe('群号'),
|
|
8
|
+
content: z.string().describe('公告内容'),
|
|
9
|
+
image: z.string().optional().describe('图片(URL 或 base64,可选)'),
|
|
10
|
+
}),
|
|
11
|
+
adapter: 'napcat',
|
|
12
|
+
tags: ['napcat', 'qq'],
|
|
13
|
+
keywords: ['群公告', 'notice', '公告', '发公告'],
|
|
14
|
+
permissions: ['platform(napcat,scene_admin)'],
|
|
15
|
+
scopes: ['group'],
|
|
16
|
+
async execute({ group_id, content, image }: { group_id: number; content: string; image?: string }, context) {
|
|
17
|
+
const endpoint = context.$client;
|
|
18
|
+
await endpoint.sendGroupNotice(group_id, content, image);
|
|
19
|
+
return { success: true };
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ user_id: number; times?: number }>({
|
|
5
|
+
description: '给好友点赞(每人每天最多 10 次)。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
user_id: z.number().describe('目标 QQ 号'),
|
|
8
|
+
times: z.number().optional().describe('点赞次数(1-10)'),
|
|
9
|
+
}),
|
|
10
|
+
adapter: 'napcat',
|
|
11
|
+
tags: ['napcat', 'qq'],
|
|
12
|
+
keywords: ['点赞', 'like', '赞', '好友赞'],
|
|
13
|
+
async execute({ user_id, times }: { user_id: number; times?: number }, context) {
|
|
14
|
+
const endpoint = context.$client;
|
|
15
|
+
await endpoint.sendLike(user_id, times || 1);
|
|
16
|
+
return { success: true, message: `已给 ${user_id} 点赞 ${times || 1} 次` };
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ user_id: number; group_id?: number }>({
|
|
5
|
+
description: '戳一戳(群聊或私聊)。group_id 不传时为私聊戳一戳。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
user_id: z.number().describe('目标用户 QQ 号'),
|
|
8
|
+
group_id: z.number().optional().describe('群号(不传则为私聊戳一戳)'),
|
|
9
|
+
}),
|
|
10
|
+
adapter: 'napcat',
|
|
11
|
+
tags: ['napcat', 'qq'],
|
|
12
|
+
keywords: ['戳一戳', 'poke', '戳', '拍一拍'],
|
|
13
|
+
async execute({ user_id, group_id }: { user_id: number; group_id?: number }, context) {
|
|
14
|
+
const endpoint = context.$client;
|
|
15
|
+
await endpoint.sendPoke(user_id, group_id);
|
|
16
|
+
return { success: true, message: `已戳 ${user_id}` };
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ file: string }>({
|
|
5
|
+
description: '修改 QQ 头像。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
file: z.string().describe('图片(URL 或 base64)'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'napcat',
|
|
10
|
+
tags: ['napcat', 'qq'],
|
|
11
|
+
keywords: ['头像', 'avatar', '设置头像', '换头像'],
|
|
12
|
+
async execute({ file }: { file: string }, context) {
|
|
13
|
+
const endpoint = context.$client;
|
|
14
|
+
await endpoint.setQQAvatar(file);
|
|
15
|
+
return { success: true };
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ message_id: number; emoji_id: string }>({
|
|
5
|
+
description: '为消息添加表情回应(贴表情)。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
message_id: z.number().describe('消息 ID'),
|
|
8
|
+
emoji_id: z.string().describe('表情 ID'),
|
|
9
|
+
}),
|
|
10
|
+
adapter: 'napcat',
|
|
11
|
+
tags: ['napcat', 'qq'],
|
|
12
|
+
keywords: ['表情回应', 'reaction', '贴表情', 'emoji'],
|
|
13
|
+
async execute({ message_id, emoji_id }: { message_id: number; emoji_id: string }, context) {
|
|
14
|
+
const endpoint = context.$client;
|
|
15
|
+
await endpoint.setMsgEmojiLike(message_id, emoji_id);
|
|
16
|
+
return { success: true };
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ message_id: number }>({
|
|
5
|
+
description: '设置群精华消息。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
message_id: z.number().describe('消息 ID'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'napcat',
|
|
10
|
+
tags: ['napcat', 'qq'],
|
|
11
|
+
keywords: ['精华', 'essence', '设精', '加精'],
|
|
12
|
+
permissions: ['platform(napcat,scene_admin)'],
|
|
13
|
+
scopes: ['group'],
|
|
14
|
+
async execute({ message_id }: { message_id: number }, context) {
|
|
15
|
+
const endpoint = context.$client;
|
|
16
|
+
await endpoint.setEssenceMsg(message_id);
|
|
17
|
+
return { success: true };
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ group_id: number; file: string }>({
|
|
5
|
+
description: '设置群头像。file 为图片 URL 或 base64。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
group_id: z.number().describe('群号'),
|
|
8
|
+
file: z.string().describe('图片(URL 或 base64)'),
|
|
9
|
+
}),
|
|
10
|
+
adapter: 'napcat',
|
|
11
|
+
tags: ['napcat', 'qq'],
|
|
12
|
+
keywords: ['群头像', 'group portrait', '设置群头像'],
|
|
13
|
+
permissions: ['platform(napcat,scene_admin)'],
|
|
14
|
+
scopes: ['group'],
|
|
15
|
+
async execute({ group_id, file }: { group_id: number; file: string }, context) {
|
|
16
|
+
const endpoint = context.$client;
|
|
17
|
+
await endpoint.setGroupPortrait(group_id, file);
|
|
18
|
+
return { success: true };
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ status: number; ext_status?: number }>({
|
|
5
|
+
description: '设置在线状态(在线、隐身、忙碌等)。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
status: z.number().describe('状态码(11=在线, 21=离开, 31=隐身, 41=忙碌, 50=请勿打扰, 60=Q我吧)'),
|
|
8
|
+
ext_status: z.number().optional().describe('扩展状态码'),
|
|
9
|
+
}),
|
|
10
|
+
adapter: 'napcat',
|
|
11
|
+
tags: ['napcat', 'qq'],
|
|
12
|
+
keywords: ['在线状态', '隐身', '忙碌', 'online', 'status'],
|
|
13
|
+
async execute({ status, ext_status }: { status: number; ext_status?: number }, context) {
|
|
14
|
+
const endpoint = context.$client;
|
|
15
|
+
await endpoint.setOnlineStatus(status, ext_status || 0);
|
|
16
|
+
return { success: true };
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ nickname: string; company?: string; email?: string; college?: string; personal_note?: string }>({
|
|
5
|
+
description: '修改 QQ 资料(昵称等)。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
nickname: z.string().describe('昵称'),
|
|
8
|
+
company: z.string().optional().describe('公司(可选)'),
|
|
9
|
+
email: z.string().optional().describe('邮箱(可选)'),
|
|
10
|
+
college: z.string().optional().describe('学校(可选)'),
|
|
11
|
+
personal_note: z.string().optional().describe('个人说明(可选)'),
|
|
12
|
+
}),
|
|
13
|
+
adapter: 'napcat',
|
|
14
|
+
tags: ['napcat', 'qq'],
|
|
15
|
+
keywords: ['修改资料', '设置昵称', 'profile', 'set profile'],
|
|
16
|
+
async execute({ nickname, company, email, college, personal_note }: { nickname: string; company?: string; email?: string; college?: string; personal_note?: string }, context) {
|
|
17
|
+
const endpoint = context.$client;
|
|
18
|
+
await endpoint.setQQProfile(nickname, company, email, college, personal_note);
|
|
19
|
+
return { success: true };
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ signature: string }>({
|
|
5
|
+
description: '设置个人签名(个性签名)。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
signature: z.string().describe('签名内容'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'napcat',
|
|
10
|
+
tags: ['napcat', 'qq'],
|
|
11
|
+
keywords: ['签名', '个性签名', 'signature', 'longnick'],
|
|
12
|
+
async execute({ signature }: { signature: string }, context) {
|
|
13
|
+
const endpoint = context.$client;
|
|
14
|
+
await endpoint.setSelfLongnick(signature);
|
|
15
|
+
return { success: true };
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ group_id: number; user_id: number; title: string }>({
|
|
5
|
+
description: '设置群成员专属头衔。需要群主权限。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
group_id: z.number().describe('群号'),
|
|
8
|
+
user_id: z.number().describe('目标成员 QQ 号'),
|
|
9
|
+
title: z.string().describe('头衔文字'),
|
|
10
|
+
}),
|
|
11
|
+
adapter: 'napcat',
|
|
12
|
+
tags: ['napcat', 'qq'],
|
|
13
|
+
keywords: ['头衔', 'title', '专属头衔', '设置头衔'],
|
|
14
|
+
permissions: ['platform(napcat,scene_owner)'],
|
|
15
|
+
scopes: ['group'],
|
|
16
|
+
async execute({ group_id, user_id, title }: { group_id: number; user_id: number; title: string }, context) {
|
|
17
|
+
const endpoint = context.$client;
|
|
18
|
+
await endpoint.setTitle(group_id, user_id, title);
|
|
19
|
+
return { success: true, message: `已设置 ${user_id} 头衔为 "${title}"` };
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ text: string }>({
|
|
5
|
+
description: '英译中翻译。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
text: z.string().describe('要翻译的英文文本'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'napcat',
|
|
10
|
+
tags: ['napcat', 'qq'],
|
|
11
|
+
keywords: ['翻译', 'translate', '英译中'],
|
|
12
|
+
async execute({ text }: { text: string }, context) {
|
|
13
|
+
const endpoint = context.$client;
|
|
14
|
+
return endpoint.translateEn2Zh(text);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ group_id: number; file: string; name: string; folder?: string }>({
|
|
5
|
+
description: '上传文件到群。file 为本地路径或 URL。',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
group_id: z.number().describe('群号'),
|
|
8
|
+
file: z.string().describe('文件路径或 URL'),
|
|
9
|
+
name: z.string().describe('文件名'),
|
|
10
|
+
folder: z.string().optional().describe('目标文件夹 ID(可选)'),
|
|
11
|
+
}),
|
|
12
|
+
adapter: 'napcat',
|
|
13
|
+
tags: ['napcat', 'qq'],
|
|
14
|
+
keywords: ['上传文件', 'upload file', '群文件'],
|
|
15
|
+
scopes: ['group'],
|
|
16
|
+
async execute({ group_id, file, name, folder }: { group_id: number; file: string; name: string; folder?: string }, context) {
|
|
17
|
+
const endpoint = context.$client;
|
|
18
|
+
await endpoint.uploadGroupFile(group_id, file, name, folder);
|
|
19
|
+
return { success: true };
|
|
20
|
+
},
|
|
21
|
+
});
|
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { NapCatEvent } from './protocol.js';
|
|
2
|
+
export type NapcatApiCall = (action: string, params?: Record<string, unknown>) => Promise<unknown>;
|
|
3
|
+
/** Transport-independent NapCat protocol Client produced by every Endpoint mode. */
|
|
4
|
+
export declare class NapcatClient {
|
|
5
|
+
readonly callApi: NapcatApiCall;
|
|
6
|
+
constructor(callApi: NapcatApiCall);
|
|
7
|
+
setTitle(groupId: number, userId: number, title: string, duration?: number): Promise<boolean>;
|
|
8
|
+
sendLike(userId: number, times?: number): Promise<unknown>;
|
|
9
|
+
deleteFriend(userId: number): Promise<unknown>;
|
|
10
|
+
markMsgAsRead(messageId: number): Promise<unknown>;
|
|
11
|
+
ocrImage(image: string): Promise<unknown>;
|
|
12
|
+
setQQProfile(nickname: string, company?: string, email?: string, college?: string, personalNote?: string): Promise<unknown>;
|
|
13
|
+
setGroupPortrait(groupId: number, file: string): Promise<unknown>;
|
|
14
|
+
setEssenceMsg(messageId: number): Promise<unknown>;
|
|
15
|
+
deleteEssenceMsg(messageId: number): Promise<unknown>;
|
|
16
|
+
getEssenceMsgList(groupId: number): Promise<unknown>;
|
|
17
|
+
sendGroupSign(groupId: number): Promise<unknown>;
|
|
18
|
+
sendGroupNotice(groupId: number, content: string, image?: string): Promise<unknown>;
|
|
19
|
+
getGroupNotice(groupId: number): Promise<unknown>;
|
|
20
|
+
deleteGroupNotice(groupId: number, noticeId: string): Promise<unknown>;
|
|
21
|
+
uploadGroupFile(groupId: number, file: string, name: string, folder?: string): Promise<unknown>;
|
|
22
|
+
getGroupRootFiles(groupId: number): Promise<unknown>;
|
|
23
|
+
getGroupFileUrl(groupId: number, fileId: string, busid: number): Promise<unknown>;
|
|
24
|
+
downloadFile(url: string, threadCount?: number, headers?: string[]): Promise<unknown>;
|
|
25
|
+
setOnlineStatus(status: number, extStatus: number): Promise<unknown>;
|
|
26
|
+
setQQAvatar(file: string): Promise<unknown>;
|
|
27
|
+
forwardFriendSingleMsg(userId: number, messageId: number): Promise<unknown>;
|
|
28
|
+
forwardGroupSingleMsg(groupId: number, messageId: number): Promise<unknown>;
|
|
29
|
+
translateEn2Zh(sourceText: string): Promise<unknown>;
|
|
30
|
+
setMsgEmojiLike(messageId: number, emojiId: string): Promise<unknown>;
|
|
31
|
+
sendForwardMsg(messageType: 'private' | 'group', id: number, messages: unknown[]): Promise<unknown>;
|
|
32
|
+
getFriendMsgHistory(userId: number, messageSeq?: number, count?: number): Promise<unknown>;
|
|
33
|
+
getGroupMsgHistory(groupId: number, messageSeq?: number, count?: number): Promise<unknown>;
|
|
34
|
+
setSelfLongnick(longnick: string): Promise<unknown>;
|
|
35
|
+
getGroupInfoEx(groupId: number): Promise<unknown>;
|
|
36
|
+
sendPoke(userId: number, groupId?: number): Promise<unknown>;
|
|
37
|
+
ncGetUserStatus(userId: number): Promise<unknown>;
|
|
38
|
+
getGroupShutList(groupId: number): Promise<unknown>;
|
|
39
|
+
getMiniAppArk(type: string, title: string, desc: string, picUrl: string, jumpUrl: string): Promise<unknown>;
|
|
40
|
+
getAiCharacters(groupId: number): Promise<unknown>;
|
|
41
|
+
sendGroupAiRecord(groupId: number, characterId: string, text: string): Promise<unknown>;
|
|
42
|
+
}
|
|
43
|
+
export type NapcatClientEventMap = Record<string, NapCatEvent>;
|
|
44
|
+
declare module '@zhin.js/feature-kit' {
|
|
45
|
+
interface AdapterClientRegistry {
|
|
46
|
+
readonly napcat: {
|
|
47
|
+
readonly client: NapcatClient;
|
|
48
|
+
readonly events: NapcatClientEventMap;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export declare const napcatClient: import("@zhin.js/adapter").EndpointClientToken<NapcatClient, NapcatClientEventMap>;
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { defineEndpointClient } from 'zhin.js/adapter';
|
|
2
|
+
/** Transport-independent NapCat protocol Client produced by every Endpoint mode. */
|
|
3
|
+
export class NapcatClient {
|
|
4
|
+
callApi;
|
|
5
|
+
constructor(callApi) {
|
|
6
|
+
this.callApi = callApi;
|
|
7
|
+
}
|
|
8
|
+
async setTitle(groupId, userId, title, duration = -1) {
|
|
9
|
+
await this.callApi('set_group_special_title', {
|
|
10
|
+
group_id: groupId,
|
|
11
|
+
user_id: userId,
|
|
12
|
+
special_title: title,
|
|
13
|
+
duration,
|
|
14
|
+
});
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
sendLike(userId, times = 1) { return this.callApi('send_like', { user_id: userId, times }); }
|
|
18
|
+
deleteFriend(userId) { return this.callApi('delete_friend', { user_id: userId }); }
|
|
19
|
+
markMsgAsRead(messageId) { return this.callApi('mark_msg_as_read', { message_id: messageId }); }
|
|
20
|
+
ocrImage(image) { return this.callApi('ocr_image', { image }); }
|
|
21
|
+
setQQProfile(nickname, company, email, college, personalNote) {
|
|
22
|
+
return this.callApi('set_qq_profile', { nickname, company, email, college, personal_note: personalNote });
|
|
23
|
+
}
|
|
24
|
+
setGroupPortrait(groupId, file) { return this.callApi('set_group_portrait', { group_id: groupId, file }); }
|
|
25
|
+
setEssenceMsg(messageId) { return this.callApi('set_essence_msg', { message_id: messageId }); }
|
|
26
|
+
deleteEssenceMsg(messageId) { return this.callApi('delete_essence_msg', { message_id: messageId }); }
|
|
27
|
+
getEssenceMsgList(groupId) { return this.callApi('get_essence_msg_list', { group_id: groupId }); }
|
|
28
|
+
sendGroupSign(groupId) { return this.callApi('send_group_sign', { group_id: groupId }); }
|
|
29
|
+
sendGroupNotice(groupId, content, image) { return this.callApi('_send_group_notice', { group_id: groupId, content, image }); }
|
|
30
|
+
getGroupNotice(groupId) { return this.callApi('_get_group_notice', { group_id: groupId }); }
|
|
31
|
+
deleteGroupNotice(groupId, noticeId) { return this.callApi('_del_group_notice', { group_id: groupId, notice_id: noticeId }); }
|
|
32
|
+
uploadGroupFile(groupId, file, name, folder) { return this.callApi('upload_group_file', { group_id: groupId, file, name, folder }); }
|
|
33
|
+
getGroupRootFiles(groupId) { return this.callApi('get_group_root_files', { group_id: groupId }); }
|
|
34
|
+
getGroupFileUrl(groupId, fileId, busid) { return this.callApi('get_group_file_url', { group_id: groupId, file_id: fileId, busid }); }
|
|
35
|
+
downloadFile(url, threadCount = 1, headers) { return this.callApi('download_file', { url, thread_count: threadCount, headers }); }
|
|
36
|
+
setOnlineStatus(status, extStatus) { return this.callApi('set_online_status', { status, ext_status: extStatus }); }
|
|
37
|
+
setQQAvatar(file) { return this.callApi('set_qq_avatar', { file }); }
|
|
38
|
+
forwardFriendSingleMsg(userId, messageId) { return this.callApi('forward_friend_single_msg', { user_id: userId, message_id: messageId }); }
|
|
39
|
+
forwardGroupSingleMsg(groupId, messageId) { return this.callApi('forward_group_single_msg', { group_id: groupId, message_id: messageId }); }
|
|
40
|
+
translateEn2Zh(sourceText) { return this.callApi('translate_en2zh', { source_text: sourceText }); }
|
|
41
|
+
setMsgEmojiLike(messageId, emojiId) { return this.callApi('set_msg_emoji_like', { message_id: messageId, emoji_id: emojiId }); }
|
|
42
|
+
sendForwardMsg(messageType, id, messages) {
|
|
43
|
+
return this.callApi('send_forward_msg', {
|
|
44
|
+
message_type: messageType,
|
|
45
|
+
[messageType === 'group' ? 'group_id' : 'user_id']: id,
|
|
46
|
+
messages,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
getFriendMsgHistory(userId, messageSeq, count) { return this.callApi('get_friend_msg_history', { user_id: userId, message_seq: messageSeq, count }); }
|
|
50
|
+
getGroupMsgHistory(groupId, messageSeq, count) { return this.callApi('get_group_msg_history', { group_id: groupId, message_seq: messageSeq, count }); }
|
|
51
|
+
setSelfLongnick(longnick) { return this.callApi('set_self_longnick', { longNick: longnick }); }
|
|
52
|
+
getGroupInfoEx(groupId) { return this.callApi('get_group_info_ex', { group_id: groupId }); }
|
|
53
|
+
sendPoke(userId, groupId) { return this.callApi('send_poke', { user_id: userId, group_id: groupId }); }
|
|
54
|
+
ncGetUserStatus(userId) { return this.callApi('nc_get_user_status', { user_id: userId }); }
|
|
55
|
+
getGroupShutList(groupId) { return this.callApi('get_group_shut_list', { group_id: groupId }); }
|
|
56
|
+
getMiniAppArk(type, title, desc, picUrl, jumpUrl) { return this.callApi('get_mini_app_ark', { type, title, desc, picUrl, jumpUrl }); }
|
|
57
|
+
getAiCharacters(groupId) { return this.callApi('get_ai_characters', { group_id: groupId }); }
|
|
58
|
+
sendGroupAiRecord(groupId, characterId, text) {
|
|
59
|
+
return this.callApi('send_group_ai_record', { group_id: groupId, character: characterId, text });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export const napcatClient = defineEndpointClient('napcat');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NapCat endpoint management 语义端口(Console 社交面 RPC 消费,见
|
|
3
|
+
* packages/im/adapter/src/endpoint-management.ts)。
|
|
4
|
+
*
|
|
5
|
+
* 归一化取舍:
|
|
6
|
+
* - friend → {user_id:number, nickname, remark: remark ?? ''}
|
|
7
|
+
* - group → {group_id:number, name: group_name ?? name}
|
|
8
|
+
* - 群成员列表保持 OneBot11 原生形状,仅保证数组
|
|
9
|
+
*/
|
|
10
|
+
import type { EndpointManagement } from 'zhin.js/adapter';
|
|
11
|
+
/** 管理面只依赖 endpoint 的 callApi(ws/wss/http 三种传输各自实现)。 */
|
|
12
|
+
export interface NapCatManagementCaller {
|
|
13
|
+
callApi(action: string, params?: Record<string, unknown>): Promise<unknown>;
|
|
14
|
+
}
|
|
15
|
+
export declare function createNapCatEndpointManagement(endpoint: NapCatManagementCaller): EndpointManagement;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export function createNapCatEndpointManagement(endpoint) {
|
|
2
|
+
return Object.freeze({
|
|
3
|
+
async listFriends() {
|
|
4
|
+
const data = await endpoint.callApi('get_friend_list');
|
|
5
|
+
return toArray(data).map((value) => {
|
|
6
|
+
const friend = asRecord(value);
|
|
7
|
+
return {
|
|
8
|
+
user_id: toNumberId(friend.user_id, 'user_id'),
|
|
9
|
+
nickname: String(friend.nickname ?? ''),
|
|
10
|
+
remark: String(friend.remark ?? ''),
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
async listGroups() {
|
|
15
|
+
const data = await endpoint.callApi('get_group_list');
|
|
16
|
+
return toArray(data).map((value) => {
|
|
17
|
+
const group = asRecord(value);
|
|
18
|
+
return {
|
|
19
|
+
group_id: toNumberId(group.group_id, 'group_id'),
|
|
20
|
+
name: String(group.group_name ?? group.name ?? ''),
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
async listGroupMembers(groupId) {
|
|
25
|
+
const data = await endpoint.callApi('get_group_member_list', {
|
|
26
|
+
group_id: toNumberId(groupId, 'group_id'),
|
|
27
|
+
});
|
|
28
|
+
return toArray(data);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function asRecord(value) {
|
|
33
|
+
return value !== null && typeof value === 'object'
|
|
34
|
+
? value
|
|
35
|
+
: {};
|
|
36
|
+
}
|
|
37
|
+
function toArray(value) {
|
|
38
|
+
return Array.isArray(value) ? value : [];
|
|
39
|
+
}
|
|
40
|
+
/** console RPC 传入的 gid/uid 可能是字符串,统一收敛为数字。 */
|
|
41
|
+
function toNumberId(value, label) {
|
|
42
|
+
const n = Number(value);
|
|
43
|
+
if (!Number.isFinite(n) || String(value ?? '').trim() === '') {
|
|
44
|
+
throw new TypeError(`napcat ${label} 必须是数字: ${String(value)}`);
|
|
45
|
+
}
|
|
46
|
+
return n;
|
|
47
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Endpoint } from 'zhin.js/adapter';
|
|
2
|
+
import { type EndpointControl, type EndpointManagement, type EndpointSendRequest } from 'zhin.js/adapter';
|
|
3
|
+
import type { HttpHost } from '@zhin.js/host-http';
|
|
4
|
+
import type { CapabilityId } from 'zhin.js';
|
|
5
|
+
import { callNapCatHttpAction, type NapCatEvent, type NapCatHttpConfig } from './protocol.js';
|
|
6
|
+
import { NapcatClient } from './client.js';
|
|
7
|
+
export interface NapCatHttpEndpointOptions {
|
|
8
|
+
readonly id: CapabilityId;
|
|
9
|
+
readonly http: HttpHost;
|
|
10
|
+
readonly config: NapCatHttpConfig;
|
|
11
|
+
readonly callHttpAction?: typeof callNapCatHttpAction;
|
|
12
|
+
}
|
|
13
|
+
export declare class NapCatHttpEndpoint extends Endpoint<NapcatClient> {
|
|
14
|
+
#private;
|
|
15
|
+
readonly client: NapcatClient;
|
|
16
|
+
readonly management: EndpointManagement;
|
|
17
|
+
readonly control: EndpointControl;
|
|
18
|
+
readonly content: import("@zhin.js/adapter").EndpointContentPort;
|
|
19
|
+
constructor(options: NapCatHttpEndpointOptions);
|
|
20
|
+
start(): Promise<void>;
|
|
21
|
+
open(): void;
|
|
22
|
+
close(): void;
|
|
23
|
+
stop(): Promise<void>;
|
|
24
|
+
send({ conversation, payload }: EndpointSendRequest): Promise<string>;
|
|
25
|
+
recallMessage(messageId: string): Promise<void>;
|
|
26
|
+
admit(ev: NapCatEvent): void;
|
|
27
|
+
}
|