@zhin.js/adapter-kook 5.0.2 → 6.0.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.
Files changed (88) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +61 -453
  3. package/adapters/kook.ts +46 -0
  4. package/agent/tools/blacklist.ts +2 -2
  5. package/agent/tools/create_role.ts +2 -2
  6. package/agent/tools/delete_role.ts +2 -2
  7. package/agent/tools/grant_role.ts +2 -2
  8. package/agent/tools/list_roles.ts +2 -2
  9. package/agent/tools/revoke_role.ts +2 -2
  10. package/lib/endpoint.d.ts +84 -0
  11. package/lib/endpoint.js +299 -0
  12. package/lib/index.d.ts +6 -0
  13. package/lib/index.js +6 -0
  14. package/lib/kook-agent-deps.d.ts +29 -0
  15. package/lib/kook-agent-deps.js +30 -0
  16. package/lib/platform-permit.d.ts +23 -0
  17. package/lib/{src/platform-permit.js → platform-permit.js} +2 -3
  18. package/lib/protocol.d.ts +147 -0
  19. package/lib/protocol.js +279 -0
  20. package/lib/webhook.d.ts +15 -0
  21. package/lib/webhook.js +76 -0
  22. package/lib/ws.d.ts +42 -0
  23. package/lib/ws.js +63 -0
  24. package/package.json +44 -40
  25. package/plugin.ts +13 -0
  26. package/schema.json +92 -0
  27. package/src/endpoint.ts +287 -879
  28. package/src/index.ts +55 -177
  29. package/src/kook-agent-deps.ts +44 -11
  30. package/src/platform-permit.ts +13 -3
  31. package/src/protocol.ts +429 -0
  32. package/src/webhook.ts +116 -0
  33. package/src/ws.ts +120 -0
  34. package/client/Dashboard.tsx +0 -255
  35. package/client/index.tsx +0 -11
  36. package/client/tsconfig.json +0 -7
  37. package/client/utils/api.ts +0 -30
  38. package/dist/index.js +0 -31
  39. package/lib/agent/tools/blacklist.js +0 -33
  40. package/lib/agent/tools/blacklist.js.map +0 -1
  41. package/lib/agent/tools/create_role.js +0 -25
  42. package/lib/agent/tools/create_role.js.map +0 -1
  43. package/lib/agent/tools/delete_role.js +0 -21
  44. package/lib/agent/tools/delete_role.js.map +0 -1
  45. package/lib/agent/tools/grant_role.js +0 -22
  46. package/lib/agent/tools/grant_role.js.map +0 -1
  47. package/lib/agent/tools/list_roles.js +0 -27
  48. package/lib/agent/tools/list_roles.js.map +0 -1
  49. package/lib/agent/tools/revoke_role.js +0 -22
  50. package/lib/agent/tools/revoke_role.js.map +0 -1
  51. package/lib/src/adapter.js +0 -67
  52. package/lib/src/adapter.js.map +0 -1
  53. package/lib/src/endpoint.js +0 -796
  54. package/lib/src/endpoint.js.map +0 -1
  55. package/lib/src/index.js +0 -197
  56. package/lib/src/index.js.map +0 -1
  57. package/lib/src/kook-agent-deps.js +0 -10
  58. package/lib/src/kook-agent-deps.js.map +0 -1
  59. package/lib/src/kook-asset-upload.js +0 -46
  60. package/lib/src/kook-asset-upload.js.map +0 -1
  61. package/lib/src/kook-inbound.js +0 -22
  62. package/lib/src/kook-inbound.js.map +0 -1
  63. package/lib/src/kook-msg-route.js +0 -106
  64. package/lib/src/kook-msg-route.js.map +0 -1
  65. package/lib/src/kook-side-events.js +0 -166
  66. package/lib/src/kook-side-events.js.map +0 -1
  67. package/lib/src/outbound-keyboard.js +0 -66
  68. package/lib/src/outbound-keyboard.js.map +0 -1
  69. package/lib/src/outbound-media.js +0 -45
  70. package/lib/src/outbound-media.js.map +0 -1
  71. package/lib/src/outbound-sendable.js +0 -64
  72. package/lib/src/outbound-sendable.js.map +0 -1
  73. package/lib/src/platform-permit.js.map +0 -1
  74. package/lib/src/segment-mapper.js +0 -2
  75. package/lib/src/segment-mapper.js.map +0 -1
  76. package/lib/src/types.js +0 -8
  77. package/lib/src/types.js.map +0 -1
  78. package/plugin.yml +0 -3
  79. package/src/adapter.ts +0 -75
  80. package/src/kook-asset-upload.ts +0 -55
  81. package/src/kook-inbound.ts +0 -22
  82. package/src/kook-msg-route.ts +0 -122
  83. package/src/kook-side-events.ts +0 -230
  84. package/src/outbound-keyboard.ts +0 -77
  85. package/src/outbound-media.ts +0 -60
  86. package/src/outbound-sendable.ts +0 -73
  87. package/src/segment-mapper.ts +0 -1
  88. package/src/types.ts +0 -58
@@ -1,9 +1,9 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { platformPermit } from '../../src/platform-permit.js';
4
4
  import { getKookAgentDeps } from '../../src/kook-agent-deps.js';
5
5
 
6
- export default defineTool<{ endpoint_id: string; guild_id: string; name: string }>({
6
+ export default defineAgentTool<{ endpoint_id: string; guild_id: string; name: string }>({
7
7
  description: '在 KOOK 服务器中创建新角色',
8
8
  inputSchema: z.object({
9
9
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -1,9 +1,9 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { platformPermit } from '../../src/platform-permit.js';
4
4
  import { getKookAgentDeps } from '../../src/kook-agent-deps.js';
5
5
 
6
- export default defineTool<{ endpoint_id: string; guild_id: string; role_id: string }>({
6
+ export default defineAgentTool<{ endpoint_id: string; guild_id: string; role_id: string }>({
7
7
  description: '删除 KOOK 服务器中的角色',
8
8
  inputSchema: z.object({
9
9
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -1,9 +1,9 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { platformPermit } from '../../src/platform-permit.js';
4
4
  import { getKookAgentDeps } from '../../src/kook-agent-deps.js';
5
5
 
6
- export default defineTool<{ endpoint_id: string; guild_id: string; user_id: string; role_id: string }>({
6
+ export default defineAgentTool<{ endpoint_id: string; guild_id: string; user_id: string; role_id: string }>({
7
7
  description: '给用户授予 KOOK 服务器角色',
8
8
  inputSchema: z.object({
9
9
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -1,8 +1,8 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { getKookAgentDeps } from '../../src/kook-agent-deps.js';
4
4
 
5
- export default defineTool<{ endpoint_id: string; guild_id: string }>({
5
+ export default defineAgentTool<{ endpoint_id: string; guild_id: string }>({
6
6
  description: '获取 KOOK 服务器的角色列表',
7
7
  inputSchema: z.object({
8
8
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -1,9 +1,9 @@
1
- import { defineTool } from '@zhin.js/agent/tools';
1
+ import { defineAgentTool } from '@zhin.js/agent/tools';
2
2
  import { z } from 'zod';
3
3
  import { platformPermit } from '../../src/platform-permit.js';
4
4
  import { getKookAgentDeps } from '../../src/kook-agent-deps.js';
5
5
 
6
- export default defineTool<{ endpoint_id: string; guild_id: string; user_id: string; role_id: string }>({
6
+ export default defineAgentTool<{ endpoint_id: string; guild_id: string; user_id: string; role_id: string }>({
7
7
  description: '撤销用户的 KOOK 服务器角色',
8
8
  inputSchema: z.object({
9
9
  endpoint_id: z.string().describe('Endpoint 名称'),
@@ -0,0 +1,84 @@
1
+ import type { EndpointInstance } from '@zhin.js/adapter';
2
+ import type { MessageGateway } from '@zhin.js/core/runtime';
3
+ import type { HttpHost } from '@zhin.js/host-http';
4
+ import type { CapabilityId } from '@zhin.js/plugin-runtime';
5
+ import { type KookInboundMessage, type ResolvedKookWebhookConfig, type ResolvedKookWebsocketConfig } from './protocol.js';
6
+ import { type CreateKookClient } from './ws.js';
7
+ export interface KookEndpointOptions {
8
+ readonly id: CapabilityId;
9
+ readonly gateway: MessageGateway;
10
+ readonly config: ResolvedKookWebsocketConfig;
11
+ readonly createClient?: CreateKookClient;
12
+ }
13
+ export declare class KookWebsocketEndpoint implements EndpointInstance {
14
+ #private;
15
+ constructor(options: KookEndpointOptions);
16
+ start(): Promise<void>;
17
+ open(): void;
18
+ close(): void;
19
+ stop(): Promise<void>;
20
+ send({ target, payload }: {
21
+ readonly target: string;
22
+ readonly payload: unknown;
23
+ }): Promise<string>;
24
+ /** Test / internal: admit a message when open. */
25
+ admit(msg: KookInboundMessage): void;
26
+ getRoleList(guildId: string): Promise<{
27
+ role_id: string | number;
28
+ name: string;
29
+ color?: number;
30
+ position?: number;
31
+ permissions?: unknown;
32
+ }[]>;
33
+ createRole(guildId: string, name: string): Promise<{
34
+ role_id: string | number;
35
+ name: string;
36
+ }>;
37
+ deleteRole(guildId: string, roleId: string): Promise<boolean>;
38
+ grantRole(guildId: string, userId: string, roleId: string): Promise<boolean>;
39
+ revokeRole(guildId: string, userId: string, roleId: string): Promise<boolean>;
40
+ addToBlacklist(guildId: string, userId: string, remark?: string): Promise<boolean>;
41
+ removeFromBlacklist(guildId: string, userId: string): Promise<boolean>;
42
+ }
43
+ export interface KookWebhookEndpointOptions {
44
+ readonly id: CapabilityId;
45
+ readonly gateway: MessageGateway;
46
+ readonly http: HttpHost;
47
+ readonly config: ResolvedKookWebhookConfig;
48
+ readonly createClient?: CreateKookClient;
49
+ }
50
+ export declare class KookWebhookEndpoint implements EndpointInstance {
51
+ #private;
52
+ constructor(options: KookWebhookEndpointOptions);
53
+ /** Used by webhook handler. */
54
+ get isOpen(): boolean;
55
+ get config(): ResolvedKookWebhookConfig;
56
+ get selfId(): string | undefined;
57
+ start(): Promise<void>;
58
+ open(): void;
59
+ close(): void;
60
+ stop(): Promise<void>;
61
+ send({ target, payload }: {
62
+ readonly target: string;
63
+ readonly payload: unknown;
64
+ }): Promise<string>;
65
+ /** Test / internal: admit a message when open. */
66
+ admit(msg: KookInboundMessage): void;
67
+ checkAndRememberSn(sn: number): boolean;
68
+ getRoleList(guildId: string): Promise<{
69
+ role_id: string | number;
70
+ name: string;
71
+ color?: number;
72
+ position?: number;
73
+ permissions?: unknown;
74
+ }[]>;
75
+ createRole(guildId: string, name: string): Promise<{
76
+ role_id: string | number;
77
+ name: string;
78
+ }>;
79
+ deleteRole(guildId: string, roleId: string): Promise<boolean>;
80
+ grantRole(guildId: string, userId: string, roleId: string): Promise<boolean>;
81
+ revokeRole(guildId: string, userId: string, roleId: string): Promise<boolean>;
82
+ addToBlacklist(guildId: string, userId: string, remark?: string): Promise<boolean>;
83
+ removeFromBlacklist(guildId: string, userId: string): Promise<boolean>;
84
+ }
@@ -0,0 +1,299 @@
1
+ import { formatCompact, getLogger } from '@zhin.js/logger';
2
+ import { registerKookAgentEndpoint } from './kook-agent-deps.js';
3
+ import { formatInboundContent, formatInboundTarget, formatOutboundKmarkdown, isKookBotMentioned, parseSendTarget, senderDisplayName, } from './protocol.js';
4
+ import { registerKookWebhookRoutes } from './webhook.js';
5
+ import { defaultCreateClient, defaultCreateWebhookClient, normalizeKookMessage, } from './ws.js';
6
+ const logger = getLogger('kook');
7
+ export class KookWebsocketEndpoint {
8
+ #options;
9
+ #createClient;
10
+ #client = null;
11
+ #open = false;
12
+ #started = false;
13
+ #unregisterAgent;
14
+ constructor(options) {
15
+ this.#options = options;
16
+ this.#createClient = options.createClient ?? defaultCreateClient;
17
+ }
18
+ async start() {
19
+ if (this.#started)
20
+ return;
21
+ this.#started = true;
22
+ try {
23
+ this.#unregisterAgent = registerKookAgentEndpoint(this.#options.config.name, this);
24
+ this.#client = this.#createClient(this.#options.config);
25
+ this.#bindClient(this.#client);
26
+ await this.#client.connect();
27
+ logger.info(formatCompact({
28
+ op: 'connect',
29
+ endpoint: this.#options.config.name,
30
+ mode: 'websocket',
31
+ self_id: this.#client.self_id != null ? String(this.#client.self_id) : undefined,
32
+ }));
33
+ }
34
+ catch (error) {
35
+ await this.stop();
36
+ logger.error('Failed to connect KOOK websocket:', error);
37
+ throw error;
38
+ }
39
+ }
40
+ open() {
41
+ this.#open = true;
42
+ }
43
+ close() {
44
+ this.#open = false;
45
+ }
46
+ async stop() {
47
+ this.#open = false;
48
+ this.#unregisterAgent?.();
49
+ this.#unregisterAgent = undefined;
50
+ if (this.#client) {
51
+ try {
52
+ this.#client.removeAllListeners();
53
+ await this.#client.disconnect();
54
+ }
55
+ catch {
56
+ /* ignore */
57
+ }
58
+ this.#client = null;
59
+ }
60
+ this.#started = false;
61
+ logger.debug(formatCompact({ op: 'disconnect', endpoint: this.#options.config.name }));
62
+ }
63
+ async send({ target, payload }) {
64
+ const body = formatOutboundKmarkdown(payload);
65
+ const parsed = parseSendTarget(target);
66
+ const client = this.#requireClient();
67
+ const result = parsed.kind === 'private'
68
+ ? await client.sendPrivateMsg(parsed.id, body)
69
+ : await client.sendChannelMsg(parsed.id, body);
70
+ const messageId = result?.msg_id != null ? String(result.msg_id) : '';
71
+ logger.debug(formatCompact({
72
+ op: 'kook_send',
73
+ endpoint: this.#options.config.name,
74
+ target,
75
+ messageId,
76
+ }));
77
+ return messageId;
78
+ }
79
+ /** Test / internal: admit a message when open. */
80
+ admit(msg) {
81
+ if (!this.#open)
82
+ return;
83
+ if (msg.authorBot)
84
+ return;
85
+ const target = formatInboundTarget(msg);
86
+ const selfId = this.#client?.self_id != null ? String(this.#client.self_id) : undefined;
87
+ void this.#options.gateway.receive({
88
+ adapter: this.#options.id,
89
+ target,
90
+ content: formatInboundContent(msg),
91
+ sender: senderDisplayName(msg),
92
+ id: msg.id,
93
+ metadata: Object.freeze({
94
+ endpoint: this.#options.config.name,
95
+ channelKind: msg.channelKind,
96
+ userId: msg.authorId,
97
+ guildId: msg.guildId,
98
+ roles: msg.authorRoles,
99
+ ...(isKookBotMentioned(msg, selfId) ? { mentioned: true } : {}),
100
+ }),
101
+ }).catch((err) => {
102
+ logger.warn(formatCompact({
103
+ op: 'kook_gateway_receive_failed',
104
+ target,
105
+ error: err instanceof Error ? err.message : String(err),
106
+ }));
107
+ });
108
+ }
109
+ // ── Agent tool surface ──────────────────────────────────────────────
110
+ async getRoleList(guildId) {
111
+ return this.#requireClient().pickGuild(guildId).getRoleList();
112
+ }
113
+ async createRole(guildId, name) {
114
+ return this.#requireClient().pickGuild(guildId).createRole(name);
115
+ }
116
+ async deleteRole(guildId, roleId) {
117
+ return this.#requireClient().pickGuild(guildId).deleteRole(roleId);
118
+ }
119
+ async grantRole(guildId, userId, roleId) {
120
+ return this.#requireClient().pickGuildMember(guildId, userId).grant(roleId);
121
+ }
122
+ async revokeRole(guildId, userId, roleId) {
123
+ return this.#requireClient().pickGuildMember(guildId, userId).revoke(roleId);
124
+ }
125
+ async addToBlacklist(guildId, userId, remark) {
126
+ return this.#requireClient().pickGuildMember(guildId, userId).addToBlackList(remark);
127
+ }
128
+ async removeFromBlacklist(guildId, userId) {
129
+ return this.#requireClient().pickGuildMember(guildId, userId).removeFromBlackList();
130
+ }
131
+ #bindClient(client) {
132
+ client.on('message', (raw) => {
133
+ const msg = normalizeKookMessage(raw);
134
+ if (msg)
135
+ this.admit(msg);
136
+ });
137
+ }
138
+ #requireClient() {
139
+ if (!this.#client)
140
+ throw new Error('KOOK client not connected');
141
+ return this.#client;
142
+ }
143
+ }
144
+ export class KookWebhookEndpoint {
145
+ #options;
146
+ #createClient;
147
+ #client = null;
148
+ #routeReleases = [];
149
+ #processedSn = new Set();
150
+ #open = false;
151
+ #started = false;
152
+ #unregisterAgent;
153
+ constructor(options) {
154
+ this.#options = options;
155
+ this.#createClient = options.createClient ?? defaultCreateWebhookClient;
156
+ }
157
+ /** Used by webhook handler. */
158
+ get isOpen() {
159
+ return this.#open;
160
+ }
161
+ get config() {
162
+ return this.#options.config;
163
+ }
164
+ get selfId() {
165
+ return this.#client?.self_id != null ? String(this.#client.self_id) : undefined;
166
+ }
167
+ async start() {
168
+ if (this.#started)
169
+ return;
170
+ this.#started = true;
171
+ try {
172
+ this.#unregisterAgent = registerKookAgentEndpoint(this.#options.config.name, this);
173
+ this.#client = this.#createClient(this.#options.config);
174
+ await this.#client.init();
175
+ this.#routeReleases.push(...registerKookWebhookRoutes(this.#options.http, this));
176
+ logger.info(formatCompact({
177
+ op: 'connect',
178
+ endpoint: this.#options.config.name,
179
+ mode: 'webhook',
180
+ path: this.#options.config.webhookPath,
181
+ self_id: this.#client.self_id != null ? String(this.#client.self_id) : undefined,
182
+ }));
183
+ }
184
+ catch (error) {
185
+ await this.stop();
186
+ logger.error('Failed to connect KOOK webhook:', error);
187
+ throw error;
188
+ }
189
+ }
190
+ open() {
191
+ this.#open = true;
192
+ }
193
+ close() {
194
+ this.#open = false;
195
+ }
196
+ async stop() {
197
+ this.#open = false;
198
+ for (const release of this.#routeReleases.splice(0))
199
+ release();
200
+ this.#unregisterAgent?.();
201
+ this.#unregisterAgent = undefined;
202
+ this.#processedSn.clear();
203
+ if (this.#client) {
204
+ try {
205
+ this.#client.removeAllListeners();
206
+ await this.#client.disconnect();
207
+ }
208
+ catch {
209
+ /* ignore */
210
+ }
211
+ this.#client = null;
212
+ }
213
+ this.#started = false;
214
+ logger.debug(formatCompact({ op: 'disconnect', endpoint: this.#options.config.name }));
215
+ }
216
+ async send({ target, payload }) {
217
+ const body = formatOutboundKmarkdown(payload);
218
+ const parsed = parseSendTarget(target);
219
+ const client = this.#requireClient();
220
+ const result = parsed.kind === 'private'
221
+ ? await client.sendPrivateMsg(parsed.id, body)
222
+ : await client.sendChannelMsg(parsed.id, body);
223
+ const messageId = result?.msg_id != null ? String(result.msg_id) : '';
224
+ logger.debug(formatCompact({
225
+ op: 'kook_send',
226
+ endpoint: this.#options.config.name,
227
+ target,
228
+ messageId,
229
+ }));
230
+ return messageId;
231
+ }
232
+ /** Test / internal: admit a message when open. */
233
+ admit(msg) {
234
+ if (!this.#open)
235
+ return;
236
+ if (msg.authorBot)
237
+ return;
238
+ const target = formatInboundTarget(msg);
239
+ const selfId = this.#client?.self_id != null ? String(this.#client.self_id) : undefined;
240
+ void this.#options.gateway.receive({
241
+ adapter: this.#options.id,
242
+ target,
243
+ content: formatInboundContent(msg),
244
+ sender: senderDisplayName(msg),
245
+ id: msg.id,
246
+ metadata: Object.freeze({
247
+ endpoint: this.#options.config.name,
248
+ channelKind: msg.channelKind,
249
+ userId: msg.authorId,
250
+ guildId: msg.guildId,
251
+ roles: msg.authorRoles,
252
+ ...(isKookBotMentioned(msg, selfId) ? { mentioned: true } : {}),
253
+ }),
254
+ }).catch((err) => {
255
+ logger.warn(formatCompact({
256
+ op: 'kook_gateway_receive_failed',
257
+ target,
258
+ error: err instanceof Error ? err.message : String(err),
259
+ }));
260
+ });
261
+ }
262
+ checkAndRememberSn(sn) {
263
+ if (this.#processedSn.has(sn))
264
+ return false;
265
+ this.#processedSn.add(sn);
266
+ if (this.#processedSn.size > 1024) {
267
+ const first = this.#processedSn.values().next().value;
268
+ if (first != null)
269
+ this.#processedSn.delete(first);
270
+ }
271
+ return true;
272
+ }
273
+ async getRoleList(guildId) {
274
+ return this.#requireClient().pickGuild(guildId).getRoleList();
275
+ }
276
+ async createRole(guildId, name) {
277
+ return this.#requireClient().pickGuild(guildId).createRole(name);
278
+ }
279
+ async deleteRole(guildId, roleId) {
280
+ return this.#requireClient().pickGuild(guildId).deleteRole(roleId);
281
+ }
282
+ async grantRole(guildId, userId, roleId) {
283
+ return this.#requireClient().pickGuildMember(guildId, userId).grant(roleId);
284
+ }
285
+ async revokeRole(guildId, userId, roleId) {
286
+ return this.#requireClient().pickGuildMember(guildId, userId).revoke(roleId);
287
+ }
288
+ async addToBlacklist(guildId, userId, remark) {
289
+ return this.#requireClient().pickGuildMember(guildId, userId).addToBlackList(remark);
290
+ }
291
+ async removeFromBlacklist(guildId, userId) {
292
+ return this.#requireClient().pickGuildMember(guildId, userId).removeFromBlackList();
293
+ }
294
+ #requireClient() {
295
+ if (!this.#client)
296
+ throw new Error('KOOK client not initialized');
297
+ return this.#client;
298
+ }
299
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export { formatInboundContent, formatInboundTarget, formatOutboundKmarkdown, parseSendTarget, resolveKookConfig, senderDisplayName, KookPermission, type KookAdapterConfig, type KookInboundMessage, type KookWireSegment, type LogLevel, type ParsedSendTarget, type ResolvedKookConfig, type ResolvedKookWebhookConfig, type ResolvedKookWebsocketConfig, } from './protocol.js';
2
+ export { KookWebhookEndpoint, KookWebsocketEndpoint, type KookEndpointOptions, type KookWebhookEndpointOptions, } from './endpoint.js';
3
+ export { registerKookWebhookRoutes, handleKookWebhookRequest, type KookWebhookHandler, } from './webhook.js';
4
+ export { defaultCreateClient, defaultCreateWebhookClient, normalizeKookMessage, type CreateKookClient, type KookClientTransport, } from './ws.js';
5
+ export { getKookAgentDeps, registerKookAgentEndpoint, setKookAgentDeps, type KookAgentDeps, type KookAgentEndpoint, } from './kook-agent-deps.js';
6
+ export { checkKookPlatformPermit, kookGroupPermitResolver, normalizeKookSenderForPermit, platformPermit, registerKookPlatformPermitChecker, type KookSenderInfo, } from './platform-permit.js';
package/lib/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { formatInboundContent, formatInboundTarget, formatOutboundKmarkdown, parseSendTarget, resolveKookConfig, senderDisplayName, KookPermission, } from './protocol.js';
2
+ export { KookWebhookEndpoint, KookWebsocketEndpoint, } from './endpoint.js';
3
+ export { registerKookWebhookRoutes, handleKookWebhookRequest, } from './webhook.js';
4
+ export { defaultCreateClient, defaultCreateWebhookClient, normalizeKookMessage, } from './ws.js';
5
+ export { getKookAgentDeps, registerKookAgentEndpoint, setKookAgentDeps, } from './kook-agent-deps.js';
6
+ export { checkKookPlatformPermit, kookGroupPermitResolver, normalizeKookSenderForPermit, platformPermit, registerKookPlatformPermitChecker, } from './platform-permit.js';
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Agent tool deps for kook.
3
+ * Endpoints register themselves on start; tools look up by config name / endpoint id.
4
+ */
5
+ export interface KookAgentEndpoint {
6
+ getRoleList(guildId: string): Promise<Array<{
7
+ role_id: string | number;
8
+ name: string;
9
+ color?: number;
10
+ position?: number;
11
+ permissions?: unknown;
12
+ }>>;
13
+ createRole(guildId: string, name: string): Promise<{
14
+ role_id: string | number;
15
+ name: string;
16
+ }>;
17
+ deleteRole(guildId: string, roleId: string): Promise<boolean>;
18
+ grantRole(guildId: string, userId: string, roleId: string): Promise<boolean>;
19
+ revokeRole(guildId: string, userId: string, roleId: string): Promise<boolean>;
20
+ addToBlacklist(guildId: string, userId: string, remark?: string): Promise<boolean>;
21
+ removeFromBlacklist(guildId: string, userId: string): Promise<boolean>;
22
+ }
23
+ export interface KookAgentDeps {
24
+ getEndpoint: (endpointId: string) => KookAgentEndpoint;
25
+ }
26
+ export declare function registerKookAgentEndpoint(endpointId: string, endpoint: KookAgentEndpoint): () => void;
27
+ /** Optional override used by tests / transitional callers. Pass `null` to clear. */
28
+ export declare function setKookAgentDeps(deps: KookAgentDeps | null): void;
29
+ export declare function getKookAgentDeps(): KookAgentDeps;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Agent tool deps for kook.
3
+ * Endpoints register themselves on start; tools look up by config name / endpoint id.
4
+ */
5
+ const endpoints = new Map();
6
+ let override = null;
7
+ export function registerKookAgentEndpoint(endpointId, endpoint) {
8
+ endpoints.set(endpointId, endpoint);
9
+ return () => {
10
+ if (endpoints.get(endpointId) === endpoint) {
11
+ endpoints.delete(endpointId);
12
+ }
13
+ };
14
+ }
15
+ /** Optional override used by tests / transitional callers. Pass `null` to clear. */
16
+ export function setKookAgentDeps(deps) {
17
+ override = deps;
18
+ }
19
+ export function getKookAgentDeps() {
20
+ if (override)
21
+ return override;
22
+ return {
23
+ getEndpoint(endpointId) {
24
+ const registered = endpoints.get(endpointId);
25
+ if (!registered)
26
+ throw new Error(`Endpoint ${endpointId} 不存在`);
27
+ return registered;
28
+ },
29
+ };
30
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * KOOK platform permit — guild / channel 差异化门禁
3
+ */
4
+ import { type Message } from '@zhin.js/core';
5
+ import { KookPermission } from './protocol.js';
6
+ export declare function platformPermit(perm: string): string;
7
+ export declare function kookGroupPermitResolver(logicalPerm: string): string;
8
+ export interface KookSenderInfo {
9
+ id: string;
10
+ name: string;
11
+ permission?: KookPermission;
12
+ roles?: number[];
13
+ isGuildOwner?: boolean;
14
+ isAdmin?: boolean;
15
+ role?: string;
16
+ permissions?: string[];
17
+ }
18
+ export declare function normalizeKookSenderForPermit(info: KookSenderInfo, isChannel: boolean): {
19
+ role?: string;
20
+ permissions?: string[];
21
+ };
22
+ export declare function checkKookPlatformPermit(perm: string, message: Message<any>): boolean;
23
+ export declare function registerKookPlatformPermitChecker(): () => void;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * KOOK platform permit — guild / channel 差异化门禁
3
3
  */
4
- import { registerPlatformPermitChecker } from 'zhin.js';
5
- import { KookPermission } from './types.js';
4
+ import { registerPlatformPermitChecker } from '@zhin.js/core';
5
+ import { KookPermission } from './protocol.js';
6
6
  const ADAPTER = 'kook';
7
7
  export function platformPermit(perm) {
8
8
  return `platform(${ADAPTER},${perm})`;
@@ -63,4 +63,3 @@ export function checkKookPlatformPermit(perm, message) {
63
63
  export function registerKookPlatformPermitChecker() {
64
64
  return registerPlatformPermitChecker(ADAPTER, checkKookPlatformPermit);
65
65
  }
66
- //# sourceMappingURL=platform-permit.js.map