@zhin.js/adapter-napcat 7.0.0 → 7.0.2

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +18 -3
  3. package/adapters/napcat.js +1 -8
  4. package/adapters/napcat.ts +1 -8
  5. package/agent/tools/ai_tts.ts +4 -6
  6. package/agent/tools/del_group_notice.ts +4 -6
  7. package/agent/tools/delete_essence_msg.ts +4 -6
  8. package/agent/tools/delete_friend.ts +4 -6
  9. package/agent/tools/download_file.ts +4 -6
  10. package/agent/tools/forward_single_msg.ts +4 -8
  11. package/agent/tools/get_ai_characters.ts +4 -6
  12. package/agent/tools/get_essence_list.ts +4 -6
  13. package/agent/tools/get_friend_msg_history.ts +4 -6
  14. package/agent/tools/get_group_file_url.ts +4 -6
  15. package/agent/tools/get_group_info_ex.ts +4 -6
  16. package/agent/tools/get_group_msg_history.ts +4 -6
  17. package/agent/tools/get_group_notice.ts +4 -6
  18. package/agent/tools/get_group_root_files.ts +4 -6
  19. package/agent/tools/get_group_shut_list.ts +4 -6
  20. package/agent/tools/get_mini_app_ark.ts +4 -6
  21. package/agent/tools/get_user_status.ts +4 -6
  22. package/agent/tools/group_sign.ts +4 -6
  23. package/agent/tools/mark_msg_as_read.ts +4 -6
  24. package/agent/tools/ocr_image.ts +4 -6
  25. package/agent/tools/send_forward_msg.ts +4 -8
  26. package/agent/tools/send_group_notice.ts +4 -6
  27. package/agent/tools/send_like.ts +4 -6
  28. package/agent/tools/send_poke.ts +4 -6
  29. package/agent/tools/set_avatar.ts +4 -6
  30. package/agent/tools/set_emoji_reaction.ts +4 -6
  31. package/agent/tools/set_essence_msg.ts +4 -6
  32. package/agent/tools/set_group_portrait.ts +4 -6
  33. package/agent/tools/set_online_status.ts +4 -6
  34. package/agent/tools/set_profile.ts +4 -6
  35. package/agent/tools/set_signature.ts +4 -6
  36. package/agent/tools/set_title.ts +4 -6
  37. package/agent/tools/translate.ts +4 -6
  38. package/agent/tools/upload_group_file.ts +4 -6
  39. package/lib/{napcat-agent-deps.d.ts → client.d.ts} +15 -14
  40. package/lib/client.js +62 -0
  41. package/lib/http-endpoint.d.ts +5 -6
  42. package/lib/http-endpoint.js +22 -12
  43. package/lib/index.d.ts +1 -1
  44. package/lib/index.js +1 -1
  45. package/lib/napcat-endpoint-commands.d.ts +1 -1
  46. package/lib/side-event-dispatch.d.ts +2 -2
  47. package/lib/side-event-dispatch.js +3 -3
  48. package/lib/ws-endpoint.d.ts +5 -41
  49. package/lib/ws-endpoint.js +24 -156
  50. package/lib/wss-endpoint.d.ts +5 -6
  51. package/lib/wss-endpoint.js +23 -13
  52. package/package.json +15 -14
  53. package/src/client.ts +79 -0
  54. package/src/http-endpoint.ts +24 -20
  55. package/src/index.ts +4 -7
  56. package/src/side-event-dispatch.ts +4 -4
  57. package/src/ws-endpoint.ts +26 -202
  58. package/src/wss-endpoint.ts +25 -21
  59. package/lib/napcat-agent-deps.js +0 -33
  60. package/src/napcat-agent-deps.ts +0 -95
@@ -1,18 +1,16 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; message_id: number }>({
4
+ export default defineAgentTool<{ message_id: number }>({
6
5
  description: '标记消息为已读。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  message_id: z.number().describe('消息 ID'),
10
8
  }),
11
- platforms: ['napcat'],
9
+ adapter: 'napcat',
12
10
  tags: ['napcat', 'qq'],
13
11
  keywords: ['已读', 'mark read', '标记已读'],
14
- async execute({ endpoint_id, message_id }: { endpoint_id: string; message_id: number }) {
15
- const endpoint = getEndpoint(endpoint_id);
12
+ async execute({ message_id }: { message_id: number }, context) {
13
+ const endpoint = context.$client;
16
14
  await endpoint.markMsgAsRead(message_id);
17
15
  return { success: true };
18
16
  },
@@ -1,18 +1,16 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; image: string }>({
4
+ export default defineAgentTool<{ image: string }>({
6
5
  description: '图片 OCR 文字识别。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  image: z.string().describe('图片 file 参数(收到消息中的 file 字段或 URL)'),
10
8
  }),
11
- platforms: ['napcat'],
9
+ adapter: 'napcat',
12
10
  tags: ['napcat', 'qq'],
13
11
  keywords: ['OCR', '文字识别', '图片识别', 'ocr'],
14
- async execute({ endpoint_id, image }: { endpoint_id: string; image: string }) {
15
- const endpoint = getEndpoint(endpoint_id);
12
+ async execute({ image }: { image: string }, context) {
13
+ const endpoint = context.$client;
16
14
  return endpoint.ocrImage(image);
17
15
  },
18
16
  });
@@ -1,30 +1,26 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
4
  export default defineAgentTool<{
6
- endpoint_id: string;
7
5
  message_type: 'private' | 'group';
8
6
  id: number;
9
7
  messages: string;
10
8
  }>({
11
9
  description: '发送合并转发消息(群聊或私聊)。messages 为转发节点数组。',
12
10
  inputSchema: z.object({
13
- endpoint_id: z.string().describe('Endpoint 名称'),
14
11
  message_type: z.enum(['private', 'group']).describe('private 或 group'),
15
12
  id: z.number().describe('群号或 QQ 号'),
16
13
  messages: z.string().describe('转发节点 JSON(node 数组)'),
17
14
  }),
18
- platforms: ['napcat'],
15
+ adapter: 'napcat',
19
16
  tags: ['napcat', 'qq'],
20
17
  keywords: ['合并转发', 'forward', '转发消息'],
21
- async execute({ endpoint_id, message_type, id, messages }: {
22
- endpoint_id: string;
18
+ async execute({ message_type, id, messages }: {
23
19
  message_type: 'private' | 'group';
24
20
  id: number;
25
21
  messages: string;
26
- }) {
27
- const endpoint = getEndpoint(endpoint_id);
22
+ }, context) {
23
+ const endpoint = context.$client;
28
24
  const nodes = typeof messages === 'string' ? JSON.parse(messages) : messages;
29
25
  return endpoint.sendForwardMsg(message_type, id, nodes);
30
26
  },
@@ -1,22 +1,20 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; group_id: number; content: string; image?: string }>({
4
+ export default defineAgentTool<{ group_id: number; content: string; image?: string }>({
6
5
  description: '发送群公告。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  group_id: z.number().describe('群号'),
10
8
  content: z.string().describe('公告内容'),
11
9
  image: z.string().optional().describe('图片(URL 或 base64,可选)'),
12
10
  }),
13
- platforms: ['napcat'],
11
+ adapter: 'napcat',
14
12
  tags: ['napcat', 'qq'],
15
13
  keywords: ['群公告', 'notice', '公告', '发公告'],
16
14
  permissions: ['platform(napcat,scene_admin)'],
17
15
  scopes: ['group'],
18
- async execute({ endpoint_id, group_id, content, image }: { endpoint_id: string; group_id: number; content: string; image?: string }) {
19
- const endpoint = getEndpoint(endpoint_id);
16
+ async execute({ group_id, content, image }: { group_id: number; content: string; image?: string }, context) {
17
+ const endpoint = context.$client;
20
18
  await endpoint.sendGroupNotice(group_id, content, image);
21
19
  return { success: true };
22
20
  },
@@ -1,19 +1,17 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; user_id: number; times?: number }>({
4
+ export default defineAgentTool<{ user_id: number; times?: number }>({
6
5
  description: '给好友点赞(每人每天最多 10 次)。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  user_id: z.number().describe('目标 QQ 号'),
10
8
  times: z.number().optional().describe('点赞次数(1-10)'),
11
9
  }),
12
- platforms: ['napcat'],
10
+ adapter: 'napcat',
13
11
  tags: ['napcat', 'qq'],
14
12
  keywords: ['点赞', 'like', '赞', '好友赞'],
15
- async execute({ endpoint_id, user_id, times }: { endpoint_id: string; user_id: number; times?: number }) {
16
- const endpoint = getEndpoint(endpoint_id);
13
+ async execute({ user_id, times }: { user_id: number; times?: number }, context) {
14
+ const endpoint = context.$client;
17
15
  await endpoint.sendLike(user_id, times || 1);
18
16
  return { success: true, message: `已给 ${user_id} 点赞 ${times || 1} 次` };
19
17
  },
@@ -1,19 +1,17 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; user_id: number; group_id?: number }>({
4
+ export default defineAgentTool<{ user_id: number; group_id?: number }>({
6
5
  description: '戳一戳(群聊或私聊)。group_id 不传时为私聊戳一戳。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  user_id: z.number().describe('目标用户 QQ 号'),
10
8
  group_id: z.number().optional().describe('群号(不传则为私聊戳一戳)'),
11
9
  }),
12
- platforms: ['napcat'],
10
+ adapter: 'napcat',
13
11
  tags: ['napcat', 'qq'],
14
12
  keywords: ['戳一戳', 'poke', '戳', '拍一拍'],
15
- async execute({ endpoint_id, user_id, group_id }: { endpoint_id: string; user_id: number; group_id?: number }) {
16
- const endpoint = getEndpoint(endpoint_id);
13
+ async execute({ user_id, group_id }: { user_id: number; group_id?: number }, context) {
14
+ const endpoint = context.$client;
17
15
  await endpoint.sendPoke(user_id, group_id);
18
16
  return { success: true, message: `已戳 ${user_id}` };
19
17
  },
@@ -1,18 +1,16 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; file: string }>({
4
+ export default defineAgentTool<{ file: string }>({
6
5
  description: '修改 QQ 头像。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  file: z.string().describe('图片(URL 或 base64)'),
10
8
  }),
11
- platforms: ['napcat'],
9
+ adapter: 'napcat',
12
10
  tags: ['napcat', 'qq'],
13
11
  keywords: ['头像', 'avatar', '设置头像', '换头像'],
14
- async execute({ endpoint_id, file }: { endpoint_id: string; file: string }) {
15
- const endpoint = getEndpoint(endpoint_id);
12
+ async execute({ file }: { file: string }, context) {
13
+ const endpoint = context.$client;
16
14
  await endpoint.setQQAvatar(file);
17
15
  return { success: true };
18
16
  },
@@ -1,19 +1,17 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; message_id: number; emoji_id: string }>({
4
+ export default defineAgentTool<{ message_id: number; emoji_id: string }>({
6
5
  description: '为消息添加表情回应(贴表情)。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  message_id: z.number().describe('消息 ID'),
10
8
  emoji_id: z.string().describe('表情 ID'),
11
9
  }),
12
- platforms: ['napcat'],
10
+ adapter: 'napcat',
13
11
  tags: ['napcat', 'qq'],
14
12
  keywords: ['表情回应', 'reaction', '贴表情', 'emoji'],
15
- async execute({ endpoint_id, message_id, emoji_id }: { endpoint_id: string; message_id: number; emoji_id: string }) {
16
- const endpoint = getEndpoint(endpoint_id);
13
+ async execute({ message_id, emoji_id }: { message_id: number; emoji_id: string }, context) {
14
+ const endpoint = context.$client;
17
15
  await endpoint.setMsgEmojiLike(message_id, emoji_id);
18
16
  return { success: true };
19
17
  },
@@ -1,20 +1,18 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; message_id: number }>({
4
+ export default defineAgentTool<{ message_id: number }>({
6
5
  description: '设置群精华消息。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  message_id: z.number().describe('消息 ID'),
10
8
  }),
11
- platforms: ['napcat'],
9
+ adapter: 'napcat',
12
10
  tags: ['napcat', 'qq'],
13
11
  keywords: ['精华', 'essence', '设精', '加精'],
14
12
  permissions: ['platform(napcat,scene_admin)'],
15
13
  scopes: ['group'],
16
- async execute({ endpoint_id, message_id }: { endpoint_id: string; message_id: number }) {
17
- const endpoint = getEndpoint(endpoint_id);
14
+ async execute({ message_id }: { message_id: number }, context) {
15
+ const endpoint = context.$client;
18
16
  await endpoint.setEssenceMsg(message_id);
19
17
  return { success: true };
20
18
  },
@@ -1,21 +1,19 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; group_id: number; file: string }>({
4
+ export default defineAgentTool<{ group_id: number; file: string }>({
6
5
  description: '设置群头像。file 为图片 URL 或 base64。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  group_id: z.number().describe('群号'),
10
8
  file: z.string().describe('图片(URL 或 base64)'),
11
9
  }),
12
- platforms: ['napcat'],
10
+ adapter: 'napcat',
13
11
  tags: ['napcat', 'qq'],
14
12
  keywords: ['群头像', 'group portrait', '设置群头像'],
15
13
  permissions: ['platform(napcat,scene_admin)'],
16
14
  scopes: ['group'],
17
- async execute({ endpoint_id, group_id, file }: { endpoint_id: string; group_id: number; file: string }) {
18
- const endpoint = getEndpoint(endpoint_id);
15
+ async execute({ group_id, file }: { group_id: number; file: string }, context) {
16
+ const endpoint = context.$client;
19
17
  await endpoint.setGroupPortrait(group_id, file);
20
18
  return { success: true };
21
19
  },
@@ -1,19 +1,17 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; status: number; ext_status?: number }>({
4
+ export default defineAgentTool<{ status: number; ext_status?: number }>({
6
5
  description: '设置在线状态(在线、隐身、忙碌等)。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  status: z.number().describe('状态码(11=在线, 21=离开, 31=隐身, 41=忙碌, 50=请勿打扰, 60=Q我吧)'),
10
8
  ext_status: z.number().optional().describe('扩展状态码'),
11
9
  }),
12
- platforms: ['napcat'],
10
+ adapter: 'napcat',
13
11
  tags: ['napcat', 'qq'],
14
12
  keywords: ['在线状态', '隐身', '忙碌', 'online', 'status'],
15
- async execute({ endpoint_id, status, ext_status }: { endpoint_id: string; status: number; ext_status?: number }) {
16
- const endpoint = getEndpoint(endpoint_id);
13
+ async execute({ status, ext_status }: { status: number; ext_status?: number }, context) {
14
+ const endpoint = context.$client;
17
15
  await endpoint.setOnlineStatus(status, ext_status || 0);
18
16
  return { success: true };
19
17
  },
@@ -1,22 +1,20 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; nickname: string; company?: string; email?: string; college?: string; personal_note?: string }>({
4
+ export default defineAgentTool<{ nickname: string; company?: string; email?: string; college?: string; personal_note?: string }>({
6
5
  description: '修改 QQ 资料(昵称等)。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  nickname: z.string().describe('昵称'),
10
8
  company: z.string().optional().describe('公司(可选)'),
11
9
  email: z.string().optional().describe('邮箱(可选)'),
12
10
  college: z.string().optional().describe('学校(可选)'),
13
11
  personal_note: z.string().optional().describe('个人说明(可选)'),
14
12
  }),
15
- platforms: ['napcat'],
13
+ adapter: 'napcat',
16
14
  tags: ['napcat', 'qq'],
17
15
  keywords: ['修改资料', '设置昵称', 'profile', 'set profile'],
18
- async execute({ endpoint_id, nickname, company, email, college, personal_note }: { endpoint_id: string; nickname: string; company?: string; email?: string; college?: string; personal_note?: string }) {
19
- const endpoint = getEndpoint(endpoint_id);
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;
20
18
  await endpoint.setQQProfile(nickname, company, email, college, personal_note);
21
19
  return { success: true };
22
20
  },
@@ -1,18 +1,16 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; signature: string }>({
4
+ export default defineAgentTool<{ signature: string }>({
6
5
  description: '设置个人签名(个性签名)。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  signature: z.string().describe('签名内容'),
10
8
  }),
11
- platforms: ['napcat'],
9
+ adapter: 'napcat',
12
10
  tags: ['napcat', 'qq'],
13
11
  keywords: ['签名', '个性签名', 'signature', 'longnick'],
14
- async execute({ endpoint_id, signature }: { endpoint_id: string; signature: string }) {
15
- const endpoint = getEndpoint(endpoint_id);
12
+ async execute({ signature }: { signature: string }, context) {
13
+ const endpoint = context.$client;
16
14
  await endpoint.setSelfLongnick(signature);
17
15
  return { success: true };
18
16
  },
@@ -1,22 +1,20 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; group_id: number; user_id: number; title: string }>({
4
+ export default defineAgentTool<{ group_id: number; user_id: number; title: string }>({
6
5
  description: '设置群成员专属头衔。需要群主权限。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  group_id: z.number().describe('群号'),
10
8
  user_id: z.number().describe('目标成员 QQ 号'),
11
9
  title: z.string().describe('头衔文字'),
12
10
  }),
13
- platforms: ['napcat'],
11
+ adapter: 'napcat',
14
12
  tags: ['napcat', 'qq'],
15
13
  keywords: ['头衔', 'title', '专属头衔', '设置头衔'],
16
14
  permissions: ['platform(napcat,scene_owner)'],
17
15
  scopes: ['group'],
18
- async execute({ endpoint_id, group_id, user_id, title }: { endpoint_id: string; group_id: number; user_id: number; title: string }) {
19
- const endpoint = getEndpoint(endpoint_id);
16
+ async execute({ group_id, user_id, title }: { group_id: number; user_id: number; title: string }, context) {
17
+ const endpoint = context.$client;
20
18
  await endpoint.setTitle(group_id, user_id, title);
21
19
  return { success: true, message: `已设置 ${user_id} 头衔为 "${title}"` };
22
20
  },
@@ -1,18 +1,16 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; text: string }>({
4
+ export default defineAgentTool<{ text: string }>({
6
5
  description: '英译中翻译。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  text: z.string().describe('要翻译的英文文本'),
10
8
  }),
11
- platforms: ['napcat'],
9
+ adapter: 'napcat',
12
10
  tags: ['napcat', 'qq'],
13
11
  keywords: ['翻译', 'translate', '英译中'],
14
- async execute({ endpoint_id, text }: { endpoint_id: string; text: string }) {
15
- const endpoint = getEndpoint(endpoint_id);
12
+ async execute({ text }: { text: string }, context) {
13
+ const endpoint = context.$client;
16
14
  return endpoint.translateEn2Zh(text);
17
15
  },
18
16
  });
@@ -1,22 +1,20 @@
1
1
  import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
- import { getEndpoint } from '../../src/napcat-agent-deps.js';
4
3
 
5
- export default defineAgentTool<{ endpoint_id: string; group_id: number; file: string; name: string; folder?: string }>({
4
+ export default defineAgentTool<{ group_id: number; file: string; name: string; folder?: string }>({
6
5
  description: '上传文件到群。file 为本地路径或 URL。',
7
6
  inputSchema: z.object({
8
- endpoint_id: z.string().describe('Endpoint 名称'),
9
7
  group_id: z.number().describe('群号'),
10
8
  file: z.string().describe('文件路径或 URL'),
11
9
  name: z.string().describe('文件名'),
12
10
  folder: z.string().optional().describe('目标文件夹 ID(可选)'),
13
11
  }),
14
- platforms: ['napcat'],
12
+ adapter: 'napcat',
15
13
  tags: ['napcat', 'qq'],
16
14
  keywords: ['上传文件', 'upload file', '群文件'],
17
15
  scopes: ['group'],
18
- async execute({ endpoint_id, group_id, file, name, folder }: { endpoint_id: string; group_id: number; file: string; name: string; folder?: string }) {
19
- const endpoint = getEndpoint(endpoint_id);
16
+ async execute({ group_id, file, name, folder }: { group_id: number; file: string; name: string; folder?: string }, context) {
17
+ const endpoint = context.$client;
20
18
  await endpoint.uploadGroupFile(group_id, file, name, folder);
21
19
  return { success: true };
22
20
  },
@@ -1,9 +1,9 @@
1
- /**
2
- * Agent tool deps for napcat.
3
- * Endpoints register themselves on start; tools look up by config name / endpoint id.
4
- */
5
- export interface NapcatAgentEndpoint {
6
- callApi(action: string, params?: Record<string, unknown>): Promise<unknown>;
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
7
  setTitle(groupId: number, userId: number, title: string, duration?: number): Promise<boolean>;
8
8
  sendLike(userId: number, times?: number): Promise<unknown>;
9
9
  deleteFriend(userId: number): Promise<unknown>;
@@ -40,12 +40,13 @@ export interface NapcatAgentEndpoint {
40
40
  getAiCharacters(groupId: number): Promise<unknown>;
41
41
  sendGroupAiRecord(groupId: number, characterId: string, text: string): Promise<unknown>;
42
42
  }
43
- export interface NapcatAgentDeps {
44
- getEndpoint: (endpointKey: string) => NapcatAgentEndpoint;
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
+ }
45
51
  }
46
- export declare function registerNapcatAgentEndpoint(endpointKey: string, endpoint: NapcatAgentEndpoint): () => void;
47
- /** Optional override used by tests / transitional callers. Pass `null` to clear. */
48
- export declare function setNapcatAgentDeps(deps: NapcatAgentDeps | null): void;
49
- export declare function getNapcatAgentDeps(): NapcatAgentDeps;
50
- /** Convenience for agent/tools (unchanged call sites). */
51
- export declare function getEndpoint(endpointKey: string): NapcatAgentEndpoint;
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');
@@ -1,18 +1,18 @@
1
- import { type EndpointControl, type EndpointInstance, type EndpointManagement, type EndpointSendRequest } from 'zhin.js/adapter';
2
- import type { MessageGateway, SideEventGateway } from '@zhin.js/core/runtime';
1
+ import { Endpoint } from 'zhin.js/adapter';
2
+ import { type EndpointControl, type EndpointManagement, type EndpointSendRequest } from 'zhin.js/adapter';
3
3
  import type { HttpHost } from '@zhin.js/host-http';
4
4
  import type { CapabilityId } from 'zhin.js';
5
5
  import { callNapCatHttpAction, type NapCatEvent, type NapCatHttpConfig } from './protocol.js';
6
+ import { NapcatClient } from './client.js';
6
7
  export interface NapCatHttpEndpointOptions {
7
8
  readonly id: CapabilityId;
8
- readonly gateway: MessageGateway;
9
- readonly sideEvents?: SideEventGateway;
10
9
  readonly http: HttpHost;
11
10
  readonly config: NapCatHttpConfig;
12
11
  readonly callHttpAction?: typeof callNapCatHttpAction;
13
12
  }
14
- export declare class NapCatHttpEndpoint implements EndpointInstance {
13
+ export declare class NapCatHttpEndpoint extends Endpoint<NapcatClient> {
15
14
  #private;
15
+ readonly client: NapcatClient;
16
16
  readonly management: EndpointManagement;
17
17
  readonly control: EndpointControl;
18
18
  readonly content: import("@zhin.js/adapter").EndpointContentPort;
@@ -23,6 +23,5 @@ export declare class NapCatHttpEndpoint implements EndpointInstance {
23
23
  stop(): Promise<void>;
24
24
  send({ conversation, payload }: EndpointSendRequest): Promise<string>;
25
25
  recallMessage(messageId: string): Promise<void>;
26
- callApi(action: string, params?: Record<string, unknown>): Promise<unknown>;
27
26
  admit(ev: NapCatEvent): void;
28
27
  }