@zhin.js/adapter-qq 5.0.1 → 5.0.3

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 (134) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +52 -408
  3. package/adapters/qq.ts +45 -0
  4. package/agent/tools/add_role.ts +23 -0
  5. package/agent/tools/channel_info.ts +19 -0
  6. package/agent/tools/create_role.ts +22 -0
  7. package/agent/tools/list_channels.ts +20 -0
  8. package/agent/tools/list_guilds.ts +17 -0
  9. package/agent/tools/list_roles.ts +20 -0
  10. package/agent/tools/member_detail.ts +20 -0
  11. package/agent/tools/remove_role.ts +23 -0
  12. package/lib/endpoint.d.ts +64 -120
  13. package/lib/endpoint.js +279 -564
  14. package/lib/index.d.ts +6 -23
  15. package/lib/index.js +6 -375
  16. package/lib/platform-permit.d.ts +1 -2
  17. package/lib/platform-permit.js +4 -2
  18. package/lib/protocol.d.ts +96 -0
  19. package/lib/protocol.js +129 -0
  20. package/lib/qq-agent-deps.d.ts +21 -0
  21. package/lib/qq-agent-deps.js +30 -0
  22. package/lib/webhook.d.ts +18 -0
  23. package/lib/webhook.js +100 -0
  24. package/lib/ws.d.ts +24 -0
  25. package/lib/ws.js +118 -0
  26. package/package.json +47 -33
  27. package/plugin.ts +13 -0
  28. package/schema.json +51 -0
  29. package/src/endpoint.ts +313 -605
  30. package/src/index.ts +55 -368
  31. package/src/platform-permit.ts +1 -2
  32. package/src/protocol.ts +229 -0
  33. package/src/qq-agent-deps.ts +60 -0
  34. package/src/webhook.ts +127 -0
  35. package/src/ws.ts +172 -0
  36. package/client/Dashboard.tsx +0 -230
  37. package/client/index.tsx +0 -11
  38. package/client/tsconfig.json +0 -7
  39. package/client/utils/api.ts +0 -30
  40. package/dist/index.js +0 -30
  41. package/lib/adapter.d.ts +0 -32
  42. package/lib/adapter.d.ts.map +0 -1
  43. package/lib/adapter.js +0 -82
  44. package/lib/adapter.js.map +0 -1
  45. package/lib/endpoint.d.ts.map +0 -1
  46. package/lib/endpoint.js.map +0 -1
  47. package/lib/gateway-config.d.ts +0 -14
  48. package/lib/gateway-config.d.ts.map +0 -1
  49. package/lib/gateway-config.js +0 -32
  50. package/lib/gateway-config.js.map +0 -1
  51. package/lib/group-at-normalize.d.ts +0 -8
  52. package/lib/group-at-normalize.d.ts.map +0 -1
  53. package/lib/group-at-normalize.js +0 -68
  54. package/lib/group-at-normalize.js.map +0 -1
  55. package/lib/inbound-action.d.ts +0 -15
  56. package/lib/inbound-action.d.ts.map +0 -1
  57. package/lib/inbound-action.js +0 -57
  58. package/lib/inbound-action.js.map +0 -1
  59. package/lib/inbound-normalize.d.ts +0 -11
  60. package/lib/inbound-normalize.d.ts.map +0 -1
  61. package/lib/inbound-normalize.js +0 -47
  62. package/lib/inbound-normalize.js.map +0 -1
  63. package/lib/index.d.ts.map +0 -1
  64. package/lib/index.js.map +0 -1
  65. package/lib/mention-enrich.d.ts +0 -12
  66. package/lib/mention-enrich.d.ts.map +0 -1
  67. package/lib/mention-enrich.js +0 -52
  68. package/lib/mention-enrich.js.map +0 -1
  69. package/lib/outbound-keyboard.d.ts +0 -4
  70. package/lib/outbound-keyboard.d.ts.map +0 -1
  71. package/lib/outbound-keyboard.js +0 -96
  72. package/lib/outbound-keyboard.js.map +0 -1
  73. package/lib/outbound-markdown.d.ts +0 -24
  74. package/lib/outbound-markdown.d.ts.map +0 -1
  75. package/lib/outbound-markdown.js +0 -177
  76. package/lib/outbound-markdown.js.map +0 -1
  77. package/lib/outbound-media.d.ts +0 -11
  78. package/lib/outbound-media.d.ts.map +0 -1
  79. package/lib/outbound-media.js +0 -51
  80. package/lib/outbound-media.js.map +0 -1
  81. package/lib/outbound-mixed-media.d.ts +0 -21
  82. package/lib/outbound-mixed-media.d.ts.map +0 -1
  83. package/lib/outbound-mixed-media.js +0 -78
  84. package/lib/outbound-mixed-media.js.map +0 -1
  85. package/lib/platform-permit.d.ts.map +0 -1
  86. package/lib/platform-permit.js.map +0 -1
  87. package/lib/qq-bind-api.d.ts +0 -37
  88. package/lib/qq-bind-api.d.ts.map +0 -1
  89. package/lib/qq-bind-api.js +0 -90
  90. package/lib/qq-bind-api.js.map +0 -1
  91. package/lib/qq-bind-flow.d.ts +0 -20
  92. package/lib/qq-bind-flow.d.ts.map +0 -1
  93. package/lib/qq-bind-flow.js +0 -86
  94. package/lib/qq-bind-flow.js.map +0 -1
  95. package/lib/qq-bind-persist.d.ts +0 -11
  96. package/lib/qq-bind-persist.d.ts.map +0 -1
  97. package/lib/qq-bind-persist.js +0 -52
  98. package/lib/qq-bind-persist.js.map +0 -1
  99. package/lib/qq-endpoint-manager.d.ts +0 -16
  100. package/lib/qq-endpoint-manager.d.ts.map +0 -1
  101. package/lib/qq-endpoint-manager.js +0 -159
  102. package/lib/qq-endpoint-manager.js.map +0 -1
  103. package/lib/sdk-version.d.ts +0 -8
  104. package/lib/sdk-version.d.ts.map +0 -1
  105. package/lib/sdk-version.js +0 -19
  106. package/lib/sdk-version.js.map +0 -1
  107. package/lib/segment-mapper.d.ts +0 -2
  108. package/lib/segment-mapper.d.ts.map +0 -1
  109. package/lib/segment-mapper.js +0 -2
  110. package/lib/segment-mapper.js.map +0 -1
  111. package/lib/types.d.ts +0 -45
  112. package/lib/types.d.ts.map +0 -1
  113. package/lib/types.js +0 -2
  114. package/lib/types.js.map +0 -1
  115. package/plugin.yml +0 -3
  116. package/src/adapter.ts +0 -101
  117. package/src/gateway-config.ts +0 -48
  118. package/src/group-at-normalize.ts +0 -76
  119. package/src/inbound-action.ts +0 -87
  120. package/src/inbound-normalize.ts +0 -57
  121. package/src/mention-enrich.ts +0 -71
  122. package/src/outbound-keyboard.ts +0 -118
  123. package/src/outbound-markdown.ts +0 -203
  124. package/src/outbound-media.ts +0 -58
  125. package/src/outbound-mixed-media.ts +0 -101
  126. package/src/qq-bind-api.ts +0 -145
  127. package/src/qq-bind-flow.ts +0 -127
  128. package/src/qq-bind-persist.ts +0 -71
  129. package/src/qq-endpoint-manager.ts +0 -199
  130. package/src/sdk-version.ts +0 -21
  131. package/src/segment-mapper.ts +0 -1
  132. package/src/types.ts +0 -53
  133. /package/{skills/qq → agent}/PERMITS.md +0 -0
  134. /package/{skills/qq/SKILL.md → agent/skills/qq.md} +0 -0
@@ -0,0 +1,20 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { platformPermit } from '../../src/platform-permit.js';
4
+ import { getQqAgentDeps } from '../../src/qq-agent-deps.js';
5
+
6
+ export default defineAgentTool<{ endpoint_id: string; guild_id: string }>({
7
+ description: '获取 QQ 频道下的子频道列表',
8
+ inputSchema: z.object({
9
+ endpoint_id: z.string().describe('Endpoint 名称'),
10
+ guild_id: z.string().describe('频道 ID'),
11
+ }),
12
+ platforms: ['qq'],
13
+ tags: ['qq'],
14
+ permissions: [platformPermit('manage_channels')],
15
+ async execute({ endpoint_id, guild_id }: { endpoint_id: string; guild_id: string }) {
16
+ const endpoint = getQqAgentDeps().getEndpoint(endpoint_id);
17
+ const channels = await endpoint.getChannels(guild_id);
18
+ return { channels, count: channels.length };
19
+ },
20
+ });
@@ -0,0 +1,17 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { getQqAgentDeps } from '../../src/qq-agent-deps.js';
4
+
5
+ export default defineAgentTool<{ endpoint_id: string }>({
6
+ description: '获取 QQ 频道列表',
7
+ inputSchema: z.object({
8
+ endpoint_id: z.string().describe('Endpoint 名称'),
9
+ }),
10
+ platforms: ['qq'],
11
+ tags: ['qq'],
12
+ async execute({ endpoint_id }: { endpoint_id: string }) {
13
+ const endpoint = getQqAgentDeps().getEndpoint(endpoint_id);
14
+ const guilds = await endpoint.getGuilds();
15
+ return { guilds, count: guilds.length };
16
+ },
17
+ });
@@ -0,0 +1,20 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { platformPermit } from '../../src/platform-permit.js';
4
+ import { getQqAgentDeps } from '../../src/qq-agent-deps.js';
5
+
6
+ export default defineAgentTool<{ endpoint_id: string; guild_id: string }>({
7
+ description: '获取 QQ 频道角色列表',
8
+ inputSchema: z.object({
9
+ endpoint_id: z.string().describe('Endpoint 名称'),
10
+ guild_id: z.string().describe('频道 ID'),
11
+ }),
12
+ platforms: ['qq'],
13
+ tags: ['qq'],
14
+ permissions: [platformPermit('manage_roles')],
15
+ async execute({ endpoint_id, guild_id }: { endpoint_id: string; guild_id: string }) {
16
+ const endpoint = getQqAgentDeps().getEndpoint(endpoint_id);
17
+ const roles = await endpoint.getGuildRoles(guild_id);
18
+ return { roles, count: roles.length };
19
+ },
20
+ });
@@ -0,0 +1,20 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { platformPermit } from '../../src/platform-permit.js';
4
+ import { getQqAgentDeps } from '../../src/qq-agent-deps.js';
5
+
6
+ export default defineAgentTool<{ endpoint_id: string; guild_id: string; user_id: string }>({
7
+ description: '获取 QQ 频道中指定成员的详细信息',
8
+ inputSchema: z.object({
9
+ endpoint_id: z.string().describe('Endpoint 名称'),
10
+ guild_id: z.string().describe('频道 ID'),
11
+ user_id: z.string().describe('用户 ID'),
12
+ }),
13
+ platforms: ['qq'],
14
+ tags: ['qq'],
15
+ permissions: [platformPermit('guild_admin')],
16
+ async execute({ endpoint_id, guild_id, user_id }: { endpoint_id: string; guild_id: string; user_id: string }) {
17
+ const endpoint = getQqAgentDeps().getEndpoint(endpoint_id);
18
+ return endpoint.getGuildMember(guild_id, user_id);
19
+ },
20
+ });
@@ -0,0 +1,23 @@
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
+ import { z } from 'zod';
3
+ import { platformPermit } from '../../src/platform-permit.js';
4
+ import { getQqAgentDeps } from '../../src/qq-agent-deps.js';
5
+
6
+ export default defineAgentTool<{ endpoint_id: string; guild_id: string; channel_id: string; user_id: string; role_id: string }>({
7
+ description: '移除成员的 QQ 频道角色',
8
+ inputSchema: z.object({
9
+ endpoint_id: z.string().describe('Endpoint 名称'),
10
+ guild_id: z.string().describe('频道 ID'),
11
+ channel_id: z.string().describe('子频道 ID'),
12
+ user_id: z.string().describe('用户 ID'),
13
+ role_id: z.string().describe('角色 ID'),
14
+ }),
15
+ platforms: ['qq'],
16
+ tags: ['qq'],
17
+ permissions: [platformPermit('manage_roles')],
18
+ async execute({ endpoint_id, guild_id, channel_id, user_id, role_id }: { endpoint_id: string; guild_id: string; channel_id: string; user_id: string; role_id: string }) {
19
+ const endpoint = getQqAgentDeps().getEndpoint(endpoint_id);
20
+ const success = await endpoint.removeMemberRole(guild_id, channel_id, user_id, role_id);
21
+ return { success, message: success ? '已移除成员的角色' : '操作失败' };
22
+ },
23
+ });
package/lib/endpoint.d.ts CHANGED
@@ -1,125 +1,69 @@
1
1
  /**
2
- * QQ 官方 Endpoint 实现
2
+ * QQ endpoints — lifecycle, outbound, admit, agent tool surface.
3
3
  */
4
- import { Bot as QQOfficialClient, PrivateMessageEvent, GroupMessageEvent } from "qq-official-bot";
5
- import { Endpoint, Message, SendOptions } from 'zhin.js';
6
- import { ReceiverMode, type QQEndpointConfig, type ApplicationPlatform } from "./types.js";
7
- import type { QQAdapter } from "./adapter.js";
8
- import { type QqWsPacket } from "./inbound-normalize.js";
9
- /** 从 qq-official-bot SendResult / 审核回包中解析出站消息 ID */
10
- export declare function resolveOutboundMessageId(result: unknown): string;
11
- export declare class QQEndpoint<T extends ReceiverMode, M extends ApplicationPlatform = ApplicationPlatform> extends QQOfficialClient implements Endpoint<QQEndpointConfig<T, M>, PrivateMessageEvent | GroupMessageEvent> {
12
- adapter: QQAdapter;
13
- $connected: boolean;
14
- $config: QQEndpointConfig<T, M>;
15
- /** 平台侧机器人 user_id,用于 @ 触发匹配 */
16
- $platformUserId?: string;
17
- get pluginLogger(): import("zhin.js").Logger;
18
- get $id(): string;
19
- constructor(adapter: QQAdapter, config: QQEndpointConfig<T, M>);
20
- /** 出站 QQ API 请求附带 SDK 版本,便于平台侧日志排查 */
21
- private attachSdkVersionHeader;
22
- /** 归一化 QQ API v2 群聊字段后再交给 qq-official-bot 解析 */
23
- dispatchEvent(event: string, wsRes: QqWsPacket): void;
24
- private guildMemberCache;
25
- private guildOwnerCache;
26
- private enrichGuildSender;
27
- private handleQQMessage;
28
- private handleQQAction;
29
- private handleGroupNotice;
30
- $connect(): Promise<void>;
31
- $disconnect(): Promise<void>;
32
- private resolveWebhookPath;
33
- /**
34
- * Webhook 入站:middleware(挂 host-router)或独立 HTTP 端口(qq-official-bot 内置服务)。
35
- */
36
- private mountWebhookReceiver;
37
- private toWireSendContent;
38
- $formatMessage(msg: PrivateMessageEvent | GroupMessageEvent): Message<PrivateMessageEvent | GroupMessageEvent>;
39
- $sendMessage(options: SendOptions): Promise<string>;
40
- /** 内联图 + 文本:上传 file_info 后以 msg_type=7 图文混排发送(二维码等场景) */
41
- private $sendTextImageMixedMedia;
42
- private resolveV2EndpointPath;
43
- $recallMessage(id: string): Promise<void>;
44
- /**
45
- * 获取频道列表
46
- */
47
- getGuilds(): Promise<any[]>;
48
- /**
49
- * 获取频道详情
50
- * @param guildId 频道 ID
51
- */
52
- getGuildInfo(guildId: string): Promise<any>;
53
- /**
54
- * 获取子频道列表
55
- * @param guildId 频道 ID
56
- */
57
- getChannels(guildId: string): Promise<any[]>;
58
- /**
59
- * 获取子频道详情
60
- * @param channelId 子频道 ID
61
- */
62
- getChannelInfo(channelId: string): Promise<any>;
63
- /**
64
- * 获取频道成员列表
65
- * @param guildId 频道 ID
66
- */
67
- getGuildMembers(guildId: string): Promise<any[]>;
68
- /**
69
- * 获取频道成员详情
70
- * @param guildId 频道 ID
71
- * @param userId 用户 ID
72
- */
73
- getGuildMember(guildId: string, userId: string): Promise<any>;
74
- /**
75
- * 删除频道成员(踢出)
76
- * @param guildId 频道 ID
77
- * @param userId 用户 ID
78
- * @param addBlacklist 是否加入黑名单
79
- * @param deleteHistoryMsg 删除历史消息天数 (-1不删除,0全部删除,3/7/15/30)
80
- */
81
- removeGuildMember(guildId: string, userId: string, addBlacklist?: boolean, deleteHistoryMsg?: -1 | 0 | 3 | 7 | 15 | 30): Promise<boolean>;
82
- /**
83
- * 获取频道角色列表
84
- * @param guildId 频道 ID
85
- */
86
- getGuildRoles(guildId: string): Promise<any[]>;
87
- /**
88
- * 创建频道角色
89
- * @param guildId 频道 ID
90
- * @param name 角色名
91
- * @param color 颜色
92
- * @param hoist 是否在成员列表中单独展示 (0 或 1)
93
- */
94
- createGuildRole(guildId: string, name: string, color?: number, hoist?: 0 | 1): Promise<any>;
95
- /**
96
- * 给成员添加角色
97
- * @param guildId 频道 ID
98
- * @param channelId 子频道 ID
99
- * @param userId 用户 ID
100
- * @param roleId 角色 ID
101
- */
4
+ import type { EndpointInstance } from '@zhin.js/adapter';
5
+ import type { MessageGateway } from '@zhin.js/core/runtime';
6
+ import type { HttpHost } from '@zhin.js/host-http';
7
+ import type { CapabilityId } from '@zhin.js/plugin-runtime';
8
+ import { type QqInboundMessage, type ResolvedQqHttpConfig, type ResolvedQqWebsocketConfig } from './protocol.js';
9
+ import { type CreateQqHttpBot } from './webhook.js';
10
+ import { type CreateQqBot } from './ws.js';
11
+ export type { CreateQqBot, QqBotTransport } from './ws.js';
12
+ export type { CreateQqHttpBot, QqHttpBotTransport } from './webhook.js';
13
+ export interface QqEndpointOptions {
14
+ readonly id: CapabilityId;
15
+ readonly gateway: MessageGateway;
16
+ readonly config: ResolvedQqWebsocketConfig;
17
+ readonly createBot?: CreateQqBot;
18
+ }
19
+ export declare class QqWebsocketEndpoint implements EndpointInstance {
20
+ #private;
21
+ constructor(options: QqEndpointOptions);
22
+ start(): Promise<void>;
23
+ open(): void;
24
+ close(): void;
25
+ stop(): Promise<void>;
26
+ send({ target, payload }: {
27
+ readonly target: string;
28
+ readonly payload: unknown;
29
+ }): Promise<string>;
30
+ /** Test / internal: admit a message when open. */
31
+ admit(msg: QqInboundMessage): void;
32
+ getGuilds(): Promise<unknown[]>;
33
+ getChannels(guildId: string): Promise<unknown[]>;
34
+ getChannelInfo(channelId: string): Promise<unknown>;
35
+ getGuildMember(guildId: string, userId: string): Promise<unknown>;
36
+ getGuildRoles(guildId: string): Promise<unknown[]>;
37
+ createGuildRole(guildId: string, name: string, color?: number): Promise<unknown>;
38
+ addMemberRole(guildId: string, channelId: string, userId: string, roleId: string): Promise<boolean>;
39
+ removeMemberRole(guildId: string, channelId: string, userId: string, roleId: string): Promise<boolean>;
40
+ }
41
+ export interface QqHttpEndpointOptions {
42
+ readonly id: CapabilityId;
43
+ readonly gateway: MessageGateway;
44
+ readonly http: HttpHost;
45
+ readonly config: ResolvedQqHttpConfig;
46
+ readonly createBot?: CreateQqHttpBot;
47
+ }
48
+ /** Webhook / middleware inbound via httpHostToken POST (qq-official-bot Middleware receiver). */
49
+ export declare class QqHttpEndpoint implements EndpointInstance {
50
+ #private;
51
+ constructor(options: QqHttpEndpointOptions);
52
+ start(): Promise<void>;
53
+ open(): void;
54
+ close(): void;
55
+ stop(): Promise<void>;
56
+ send({ target, payload }: {
57
+ readonly target: string;
58
+ readonly payload: unknown;
59
+ }): Promise<string>;
60
+ admit(msg: QqInboundMessage): void;
61
+ getGuilds(): Promise<unknown[]>;
62
+ getChannels(guildId: string): Promise<unknown[]>;
63
+ getChannelInfo(channelId: string): Promise<unknown>;
64
+ getGuildMember(guildId: string, userId: string): Promise<unknown>;
65
+ getGuildRoles(guildId: string): Promise<unknown[]>;
66
+ createGuildRole(guildId: string, name: string, color?: number): Promise<unknown>;
102
67
  addMemberRole(guildId: string, channelId: string, userId: string, roleId: string): Promise<boolean>;
103
- /**
104
- * 移除成员角色
105
- * @param guildId 频道 ID
106
- * @param channelId 子频道 ID
107
- * @param userId 用户 ID
108
- * @param roleId 角色 ID
109
- */
110
68
  removeMemberRole(guildId: string, channelId: string, userId: string, roleId: string): Promise<boolean>;
111
- /**
112
- * 禁言成员(批量)
113
- * @param guildId 频道 ID
114
- * @param userIds 用户 ID 列表
115
- * @param muteSeconds 禁言时长(秒),0 表示解除禁言
116
- */
117
- muteMembers(guildId: string, userIds: string[], muteSeconds: number): Promise<boolean>;
118
- /**
119
- * 全员禁言
120
- * @param guildId 频道 ID
121
- * @param muteSeconds 禁言时长(秒),0 表示解除禁言
122
- */
123
- muteAll(guildId: string, muteSeconds: number): Promise<boolean>;
124
69
  }
125
- //# sourceMappingURL=endpoint.d.ts.map