@zhin.js/adapter-kook 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.
- package/CHANGELOG.md +60 -0
- package/README.md +58 -451
- package/adapters/kook.ts +46 -0
- package/agent/tools/blacklist.ts +33 -0
- package/agent/tools/create_role.ts +25 -0
- package/agent/tools/delete_role.ts +21 -0
- package/agent/tools/grant_role.ts +22 -0
- package/agent/tools/list_roles.ts +27 -0
- package/agent/tools/revoke_role.ts +22 -0
- package/lib/endpoint.d.ts +80 -151
- package/lib/endpoint.js +260 -736
- package/lib/index.d.ts +6 -18
- package/lib/index.js +6 -350
- package/lib/kook-agent-deps.d.ts +29 -0
- package/lib/kook-agent-deps.js +30 -0
- package/lib/platform-permit.d.ts +12 -3
- package/lib/platform-permit.js +5 -3
- package/lib/protocol.d.ts +147 -0
- package/lib/protocol.js +279 -0
- package/lib/webhook.d.ts +15 -0
- package/lib/webhook.js +76 -0
- package/lib/ws.d.ts +42 -0
- package/lib/ws.js +63 -0
- package/package.json +47 -33
- package/plugin.ts +13 -0
- package/schema.json +55 -0
- package/src/endpoint.ts +287 -866
- package/src/index.ts +55 -331
- package/src/kook-agent-deps.ts +55 -0
- package/src/platform-permit.ts +13 -4
- package/src/protocol.ts +429 -0
- package/src/webhook.ts +116 -0
- package/src/ws.ts +120 -0
- package/client/Dashboard.tsx +0 -255
- package/client/index.tsx +0 -11
- package/client/tsconfig.json +0 -7
- package/client/utils/api.ts +0 -30
- package/dist/index.js +0 -31
- package/lib/adapter.d.ts +0 -30
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -67
- package/lib/adapter.js.map +0 -1
- package/lib/endpoint.d.ts.map +0 -1
- package/lib/endpoint.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/kook-asset-upload.d.ts +0 -12
- package/lib/kook-asset-upload.d.ts.map +0 -1
- package/lib/kook-asset-upload.js +0 -46
- package/lib/kook-asset-upload.js.map +0 -1
- package/lib/kook-inbound.d.ts +0 -6
- package/lib/kook-inbound.d.ts.map +0 -1
- package/lib/kook-inbound.js +0 -22
- package/lib/kook-inbound.js.map +0 -1
- package/lib/kook-msg-route.d.ts +0 -34
- package/lib/kook-msg-route.d.ts.map +0 -1
- package/lib/kook-msg-route.js +0 -106
- package/lib/kook-msg-route.js.map +0 -1
- package/lib/kook-side-events.d.ts +0 -46
- package/lib/kook-side-events.d.ts.map +0 -1
- package/lib/kook-side-events.js +0 -189
- package/lib/kook-side-events.js.map +0 -1
- package/lib/outbound-keyboard.d.ts +0 -13
- package/lib/outbound-keyboard.d.ts.map +0 -1
- package/lib/outbound-keyboard.js +0 -63
- package/lib/outbound-keyboard.js.map +0 -1
- package/lib/outbound-media.d.ts +0 -10
- package/lib/outbound-media.d.ts.map +0 -1
- package/lib/outbound-media.js +0 -42
- package/lib/outbound-media.js.map +0 -1
- package/lib/outbound-sendable.d.ts +0 -12
- package/lib/outbound-sendable.d.ts.map +0 -1
- package/lib/outbound-sendable.js +0 -64
- package/lib/outbound-sendable.js.map +0 -1
- package/lib/platform-permit.d.ts.map +0 -1
- package/lib/platform-permit.js.map +0 -1
- package/lib/segment-mapper.d.ts +0 -2
- package/lib/segment-mapper.d.ts.map +0 -1
- package/lib/segment-mapper.js +0 -2
- package/lib/segment-mapper.js.map +0 -1
- package/lib/types.d.ts +0 -54
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -8
- package/lib/types.js.map +0 -1
- package/plugin.yml +0 -3
- package/src/adapter.ts +0 -76
- package/src/kook-asset-upload.ts +0 -55
- package/src/kook-inbound.ts +0 -22
- package/src/kook-msg-route.ts +0 -122
- package/src/kook-side-events.ts +0 -250
- package/src/outbound-keyboard.ts +0 -78
- package/src/outbound-media.ts +0 -67
- package/src/outbound-sendable.ts +0 -73
- package/src/segment-mapper.ts +0 -1
- package/src/types.ts +0 -59
- /package/{skills/kook → agent}/PERMITS.md +0 -0
- /package/{skills/kook/SKILL.md → agent/skills/kook.md} +0 -0
package/src/index.ts
CHANGED
|
@@ -1,331 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
description: '给用户授予 KOOK 服务器角色',
|
|
57
|
-
parameters: {
|
|
58
|
-
type: 'object',
|
|
59
|
-
properties: {
|
|
60
|
-
endpoint_id: { type: 'string', description: 'Endpoint 名称', contextKey: 'endpointId' },
|
|
61
|
-
guild_id: { type: 'string', description: '服务器 ID' },
|
|
62
|
-
user_id: { type: 'string', description: '用户 ID' },
|
|
63
|
-
role_id: { type: 'string', description: '角色 ID' },
|
|
64
|
-
},
|
|
65
|
-
required: ['endpoint_id', 'guild_id', 'user_id', 'role_id'],
|
|
66
|
-
},
|
|
67
|
-
platforms: ['kook'],
|
|
68
|
-
tags: ['kook'],
|
|
69
|
-
permissions: [platformPermit('manage_roles')],
|
|
70
|
-
execute: async (args: Record<string, any>) => {
|
|
71
|
-
const endpoint = kook.endpoints.get(args.endpoint_id);
|
|
72
|
-
if (!endpoint) throw new Error(`Endpoint ${args.endpoint_id} 不存在`);
|
|
73
|
-
const success = await endpoint.grantRole(args.guild_id, args.user_id, args.role_id);
|
|
74
|
-
return { success, message: success ? `已授予用户 ${args.user_id} 角色 ${args.role_id}` : '授予角色失败' };
|
|
75
|
-
},
|
|
76
|
-
}, plugin.name));
|
|
77
|
-
|
|
78
|
-
disposers.push(toolService.addTool({
|
|
79
|
-
name: 'kook_revoke_role',
|
|
80
|
-
description: '撤销用户的 KOOK 服务器角色',
|
|
81
|
-
parameters: {
|
|
82
|
-
type: 'object',
|
|
83
|
-
properties: {
|
|
84
|
-
endpoint_id: { type: 'string', description: 'Endpoint 名称', contextKey: 'endpointId' },
|
|
85
|
-
guild_id: { type: 'string', description: '服务器 ID' },
|
|
86
|
-
user_id: { type: 'string', description: '用户 ID' },
|
|
87
|
-
role_id: { type: 'string', description: '角色 ID' },
|
|
88
|
-
},
|
|
89
|
-
required: ['endpoint_id', 'guild_id', 'user_id', 'role_id'],
|
|
90
|
-
},
|
|
91
|
-
platforms: ['kook'],
|
|
92
|
-
tags: ['kook'],
|
|
93
|
-
permissions: [platformPermit('manage_roles')],
|
|
94
|
-
execute: async (args: Record<string, any>) => {
|
|
95
|
-
const endpoint = kook.endpoints.get(args.endpoint_id);
|
|
96
|
-
if (!endpoint) throw new Error(`Endpoint ${args.endpoint_id} 不存在`);
|
|
97
|
-
const success = await endpoint.revokeRole(args.guild_id, args.user_id, args.role_id);
|
|
98
|
-
return { success, message: success ? `已撤销用户 ${args.user_id} 的角色 ${args.role_id}` : '撤销角色失败' };
|
|
99
|
-
},
|
|
100
|
-
}, plugin.name));
|
|
101
|
-
|
|
102
|
-
disposers.push(toolService.addTool({
|
|
103
|
-
name: 'kook_list_roles',
|
|
104
|
-
description: '获取 KOOK 服务器的角色列表',
|
|
105
|
-
parameters: {
|
|
106
|
-
type: 'object',
|
|
107
|
-
properties: {
|
|
108
|
-
endpoint_id: { type: 'string', description: 'Endpoint 名称', contextKey: 'endpointId' },
|
|
109
|
-
guild_id: { type: 'string', description: '服务器 ID' },
|
|
110
|
-
},
|
|
111
|
-
required: ['endpoint_id', 'guild_id'],
|
|
112
|
-
},
|
|
113
|
-
platforms: ['kook'],
|
|
114
|
-
tags: ['kook'],
|
|
115
|
-
execute: async (args: Record<string, any>) => {
|
|
116
|
-
const endpoint = kook.endpoints.get(args.endpoint_id);
|
|
117
|
-
if (!endpoint) throw new Error(`Endpoint ${args.endpoint_id} 不存在`);
|
|
118
|
-
const roles = await endpoint.getRoleList(args.guild_id);
|
|
119
|
-
return {
|
|
120
|
-
roles: roles.map((r: any) => ({
|
|
121
|
-
id: r.role_id,
|
|
122
|
-
name: r.name,
|
|
123
|
-
color: r.color,
|
|
124
|
-
position: r.position,
|
|
125
|
-
permissions: r.permissions,
|
|
126
|
-
})),
|
|
127
|
-
count: roles.length,
|
|
128
|
-
};
|
|
129
|
-
},
|
|
130
|
-
}, plugin.name));
|
|
131
|
-
|
|
132
|
-
disposers.push(toolService.addTool({
|
|
133
|
-
name: 'kook_create_role',
|
|
134
|
-
description: '在 KOOK 服务器中创建新角色',
|
|
135
|
-
parameters: {
|
|
136
|
-
type: 'object',
|
|
137
|
-
properties: {
|
|
138
|
-
endpoint_id: { type: 'string', description: 'Endpoint 名称', contextKey: 'endpointId' },
|
|
139
|
-
guild_id: { type: 'string', description: '服务器 ID' },
|
|
140
|
-
name: { type: 'string', description: '角色名称' },
|
|
141
|
-
},
|
|
142
|
-
required: ['endpoint_id', 'guild_id', 'name'],
|
|
143
|
-
},
|
|
144
|
-
platforms: ['kook'],
|
|
145
|
-
tags: ['kook'],
|
|
146
|
-
permissions: [platformPermit('guild_owner')],
|
|
147
|
-
execute: async (args: Record<string, any>) => {
|
|
148
|
-
const endpoint = kook.endpoints.get(args.endpoint_id);
|
|
149
|
-
if (!endpoint) throw new Error(`Endpoint ${args.endpoint_id} 不存在`);
|
|
150
|
-
const role = await endpoint.createRole(args.guild_id, args.name);
|
|
151
|
-
return {
|
|
152
|
-
success: true,
|
|
153
|
-
message: `已创建角色 "${args.name}"`,
|
|
154
|
-
role: { id: role.role_id, name: role.name },
|
|
155
|
-
};
|
|
156
|
-
},
|
|
157
|
-
}, plugin.name));
|
|
158
|
-
|
|
159
|
-
disposers.push(toolService.addTool({
|
|
160
|
-
name: 'kook_delete_role',
|
|
161
|
-
description: '删除 KOOK 服务器中的角色',
|
|
162
|
-
parameters: {
|
|
163
|
-
type: 'object',
|
|
164
|
-
properties: {
|
|
165
|
-
endpoint_id: { type: 'string', description: 'Endpoint 名称', contextKey: 'endpointId' },
|
|
166
|
-
guild_id: { type: 'string', description: '服务器 ID' },
|
|
167
|
-
role_id: { type: 'string', description: '角色 ID' },
|
|
168
|
-
},
|
|
169
|
-
required: ['endpoint_id', 'guild_id', 'role_id'],
|
|
170
|
-
},
|
|
171
|
-
platforms: ['kook'],
|
|
172
|
-
tags: ['kook'],
|
|
173
|
-
permissions: [platformPermit('guild_owner')],
|
|
174
|
-
execute: async (args: Record<string, any>) => {
|
|
175
|
-
const endpoint = kook.endpoints.get(args.endpoint_id);
|
|
176
|
-
if (!endpoint) throw new Error(`Endpoint ${args.endpoint_id} 不存在`);
|
|
177
|
-
const success = await endpoint.deleteRole(args.guild_id, args.role_id);
|
|
178
|
-
return { success, message: success ? `已删除角色 ${args.role_id}` : '删除角色失败' };
|
|
179
|
-
},
|
|
180
|
-
}, plugin.name));
|
|
181
|
-
|
|
182
|
-
disposers.push(toolService.addTool({
|
|
183
|
-
name: 'kook_blacklist',
|
|
184
|
-
description: 'KOOK 服务器黑名单管理:添加/移除',
|
|
185
|
-
parameters: {
|
|
186
|
-
type: 'object',
|
|
187
|
-
properties: {
|
|
188
|
-
endpoint_id: { type: 'string', description: 'Endpoint 名称', contextKey: 'endpointId' },
|
|
189
|
-
guild_id: { type: 'string', description: '服务器 ID' },
|
|
190
|
-
action: { type: 'string', description: 'add|remove', enum: ['add', 'remove'] },
|
|
191
|
-
user_id: { type: 'string', description: '用户 ID' },
|
|
192
|
-
remark: { type: 'string', description: '备注(add 可选)' },
|
|
193
|
-
},
|
|
194
|
-
required: ['endpoint_id', 'guild_id', 'action', 'user_id'],
|
|
195
|
-
},
|
|
196
|
-
platforms: ['kook'],
|
|
197
|
-
tags: ['kook'],
|
|
198
|
-
permissions: [platformPermit('guild_admin')],
|
|
199
|
-
execute: async (args: Record<string, any>) => {
|
|
200
|
-
const endpoint = kook.endpoints.get(args.endpoint_id);
|
|
201
|
-
if (!endpoint) throw new Error(`Endpoint ${args.endpoint_id} 不存在`);
|
|
202
|
-
switch (args.action) {
|
|
203
|
-
case 'add': {
|
|
204
|
-
const success = await endpoint.addToBlacklist(args.guild_id, args.user_id, args.remark);
|
|
205
|
-
return { success, message: success ? `已将 ${args.user_id} 加入黑名单` : '操作失败' };
|
|
206
|
-
}
|
|
207
|
-
case 'remove': {
|
|
208
|
-
const success = await endpoint.removeFromBlacklist(args.guild_id, args.user_id);
|
|
209
|
-
return { success, message: success ? `已将 ${args.user_id} 从黑名单移除` : '操作失败' };
|
|
210
|
-
}
|
|
211
|
-
default:
|
|
212
|
-
return { success: false, message: `未知操作: ${args.action}` };
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
}, plugin.name));
|
|
216
|
-
|
|
217
|
-
return () => disposers.forEach(d => d());
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
// ── Web 控制台 ─────────────────────────────────────────────────────────
|
|
221
|
-
useContext("web", (pageManager) => {
|
|
222
|
-
pageManager.addEntry({
|
|
223
|
-
id: "kook",
|
|
224
|
-
development: path.resolve(import.meta.dirname, "../client/index.tsx"),
|
|
225
|
-
production: path.resolve(import.meta.dirname, "../dist/index.js"),
|
|
226
|
-
meta: { name: "KOOK" },
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
useContext("router", "kook", (router: any, kook: KookAdapter) => {
|
|
231
|
-
router.get("/api/kook/endpoints", async (ctx: any) => {
|
|
232
|
-
try {
|
|
233
|
-
const endpoints = Array.from(kook.endpoints.values());
|
|
234
|
-
const result = endpoints.map((endpoint: any) => {
|
|
235
|
-
try {
|
|
236
|
-
return {
|
|
237
|
-
name: endpoint.$config.name,
|
|
238
|
-
connected: endpoint.$connected || false,
|
|
239
|
-
guildCount: endpoint.guilds?.size || 0,
|
|
240
|
-
status: endpoint.$connected ? "online" : "offline",
|
|
241
|
-
};
|
|
242
|
-
} catch {
|
|
243
|
-
return { name: endpoint.$config.name, connected: false, guildCount: 0, status: "error" };
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
ctx.body = { success: true, data: result };
|
|
247
|
-
} catch {
|
|
248
|
-
ctx.status = 500;
|
|
249
|
-
ctx.body = { success: false, error: "获取 Endpoint 数据失败" };
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
// Endpoint 连接/断开
|
|
254
|
-
router.post("/api/kook/endpoints/:name/connect", async (ctx: any) => {
|
|
255
|
-
try {
|
|
256
|
-
const endpoint = kook.endpoints.get(ctx.params.name);
|
|
257
|
-
if (!endpoint) { ctx.status = 404; ctx.body = { success: false, error: "Endpoint 不存在" }; return; }
|
|
258
|
-
if (endpoint.$connected) { ctx.body = { success: true, message: "已经在线" }; return; }
|
|
259
|
-
await endpoint.$connect();
|
|
260
|
-
ctx.body = { success: true, message: "连接成功" };
|
|
261
|
-
} catch (e: unknown) {
|
|
262
|
-
ctx.status = 500;
|
|
263
|
-
ctx.body = { success: false, error: e instanceof Error ? e.message : "连接失败" };
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
router.post("/api/kook/endpoints/:name/disconnect", async (ctx: any) => {
|
|
268
|
-
try {
|
|
269
|
-
const endpoint = kook.endpoints.get(ctx.params.name);
|
|
270
|
-
if (!endpoint) { ctx.status = 404; ctx.body = { success: false, error: "Endpoint 不存在" }; return; }
|
|
271
|
-
if (!endpoint.$connected) { ctx.body = { success: true, message: "已经离线" }; return; }
|
|
272
|
-
await endpoint.$disconnect();
|
|
273
|
-
ctx.body = { success: true, message: "已断开" };
|
|
274
|
-
} catch (e: unknown) {
|
|
275
|
-
ctx.status = 500;
|
|
276
|
-
ctx.body = { success: false, error: e instanceof Error ? e.message : "断开失败" };
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
// 角色列表
|
|
281
|
-
router.get("/api/kook/endpoints/:name/guilds/:guildId/roles", async (ctx: any) => {
|
|
282
|
-
try {
|
|
283
|
-
const endpoint: any = kook.endpoints.get(ctx.params.name);
|
|
284
|
-
if (!endpoint) { ctx.status = 404; ctx.body = { success: false, error: "Endpoint 不存在" }; return; }
|
|
285
|
-
if (!endpoint.$connected) { ctx.status = 400; ctx.body = { success: false, error: "Endpoint 未连接" }; return; }
|
|
286
|
-
const roles = await endpoint.getRoleList(ctx.params.guildId);
|
|
287
|
-
ctx.body = {
|
|
288
|
-
success: true,
|
|
289
|
-
data: roles.map((r: any) => ({
|
|
290
|
-
id: r.role_id,
|
|
291
|
-
name: r.name,
|
|
292
|
-
color: r.color,
|
|
293
|
-
position: r.position,
|
|
294
|
-
})),
|
|
295
|
-
};
|
|
296
|
-
} catch (e: unknown) {
|
|
297
|
-
ctx.status = 500;
|
|
298
|
-
ctx.body = { success: false, error: e instanceof Error ? e.message : "获取角色列表失败" };
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
// 创建角色
|
|
303
|
-
router.post("/api/kook/endpoints/:name/guilds/:guildId/roles", async (ctx: any) => {
|
|
304
|
-
try {
|
|
305
|
-
const endpoint: any = kook.endpoints.get(ctx.params.name);
|
|
306
|
-
if (!endpoint) { ctx.status = 404; ctx.body = { success: false, error: "Endpoint 不存在" }; return; }
|
|
307
|
-
if (!endpoint.$connected) { ctx.status = 400; ctx.body = { success: false, error: "Endpoint 未连接" }; return; }
|
|
308
|
-
const { name } = ctx.request.body || {};
|
|
309
|
-
if (!name) { ctx.status = 400; ctx.body = { success: false, error: "缺少角色名称" }; return; }
|
|
310
|
-
const role = await endpoint.createRole(ctx.params.guildId, name);
|
|
311
|
-
ctx.body = { success: true, data: { id: role.role_id, name: role.name } };
|
|
312
|
-
} catch (e: unknown) {
|
|
313
|
-
ctx.status = 500;
|
|
314
|
-
ctx.body = { success: false, error: e instanceof Error ? e.message : "创建角色失败" };
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
// 删除角色
|
|
319
|
-
router.delete("/api/kook/endpoints/:name/guilds/:guildId/roles/:roleId", async (ctx: any) => {
|
|
320
|
-
try {
|
|
321
|
-
const endpoint: any = kook.endpoints.get(ctx.params.name);
|
|
322
|
-
if (!endpoint) { ctx.status = 404; ctx.body = { success: false, error: "Endpoint 不存在" }; return; }
|
|
323
|
-
if (!endpoint.$connected) { ctx.status = 400; ctx.body = { success: false, error: "Endpoint 未连接" }; return; }
|
|
324
|
-
const success = await endpoint.deleteRole(ctx.params.guildId, ctx.params.roleId);
|
|
325
|
-
ctx.body = { success, message: success ? "角色已删除" : "删除失败" };
|
|
326
|
-
} catch (e: unknown) {
|
|
327
|
-
ctx.status = 500;
|
|
328
|
-
ctx.body = { success: false, error: e instanceof Error ? e.message : "删除角色失败" };
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
});
|
|
1
|
+
export {
|
|
2
|
+
formatInboundContent,
|
|
3
|
+
formatInboundTarget,
|
|
4
|
+
formatOutboundKmarkdown,
|
|
5
|
+
parseSendTarget,
|
|
6
|
+
resolveKookConfig,
|
|
7
|
+
senderDisplayName,
|
|
8
|
+
KookPermission,
|
|
9
|
+
type KookAdapterConfig,
|
|
10
|
+
type KookInboundMessage,
|
|
11
|
+
type KookWireSegment,
|
|
12
|
+
type LogLevel,
|
|
13
|
+
type ParsedSendTarget,
|
|
14
|
+
type ResolvedKookConfig,
|
|
15
|
+
type ResolvedKookWebhookConfig,
|
|
16
|
+
type ResolvedKookWebsocketConfig,
|
|
17
|
+
} from './protocol.js';
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
KookWebhookEndpoint,
|
|
21
|
+
KookWebsocketEndpoint,
|
|
22
|
+
type KookEndpointOptions,
|
|
23
|
+
type KookWebhookEndpointOptions,
|
|
24
|
+
} from './endpoint.js';
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
registerKookWebhookRoutes,
|
|
28
|
+
handleKookWebhookRequest,
|
|
29
|
+
type KookWebhookHandler,
|
|
30
|
+
} from './webhook.js';
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
defaultCreateClient,
|
|
34
|
+
defaultCreateWebhookClient,
|
|
35
|
+
normalizeKookMessage,
|
|
36
|
+
type CreateKookClient,
|
|
37
|
+
type KookClientTransport,
|
|
38
|
+
} from './ws.js';
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
getKookAgentDeps,
|
|
42
|
+
registerKookAgentEndpoint,
|
|
43
|
+
setKookAgentDeps,
|
|
44
|
+
type KookAgentDeps,
|
|
45
|
+
type KookAgentEndpoint,
|
|
46
|
+
} from './kook-agent-deps.js';
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
checkKookPlatformPermit,
|
|
50
|
+
kookGroupPermitResolver,
|
|
51
|
+
normalizeKookSenderForPermit,
|
|
52
|
+
platformPermit,
|
|
53
|
+
registerKookPlatformPermitChecker,
|
|
54
|
+
type KookSenderInfo,
|
|
55
|
+
} from './platform-permit.js';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent tool deps for kook.
|
|
3
|
+
* Endpoints register themselves on start; tools look up by config name / endpoint id.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface KookAgentEndpoint {
|
|
7
|
+
getRoleList(guildId: string): Promise<Array<{
|
|
8
|
+
role_id: string | number;
|
|
9
|
+
name: string;
|
|
10
|
+
color?: number;
|
|
11
|
+
position?: number;
|
|
12
|
+
permissions?: unknown;
|
|
13
|
+
}>>;
|
|
14
|
+
createRole(guildId: string, name: string): Promise<{ role_id: string | number; name: string }>;
|
|
15
|
+
deleteRole(guildId: string, roleId: string): Promise<boolean>;
|
|
16
|
+
grantRole(guildId: string, userId: string, roleId: string): Promise<boolean>;
|
|
17
|
+
revokeRole(guildId: string, userId: string, roleId: string): Promise<boolean>;
|
|
18
|
+
addToBlacklist(guildId: string, userId: string, remark?: string): Promise<boolean>;
|
|
19
|
+
removeFromBlacklist(guildId: string, userId: string): Promise<boolean>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface KookAgentDeps {
|
|
23
|
+
getEndpoint: (endpointId: string) => KookAgentEndpoint;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const endpoints = new Map<string, KookAgentEndpoint>();
|
|
27
|
+
let override: KookAgentDeps | null = null;
|
|
28
|
+
|
|
29
|
+
export function registerKookAgentEndpoint(
|
|
30
|
+
endpointId: string,
|
|
31
|
+
endpoint: KookAgentEndpoint,
|
|
32
|
+
): () => void {
|
|
33
|
+
endpoints.set(endpointId, endpoint);
|
|
34
|
+
return () => {
|
|
35
|
+
if (endpoints.get(endpointId) === endpoint) {
|
|
36
|
+
endpoints.delete(endpointId);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Optional override used by tests / transitional callers. Pass `null` to clear. */
|
|
42
|
+
export function setKookAgentDeps(deps: KookAgentDeps | null): void {
|
|
43
|
+
override = deps;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function getKookAgentDeps(): KookAgentDeps {
|
|
47
|
+
if (override) return override;
|
|
48
|
+
return {
|
|
49
|
+
getEndpoint(endpointId: string): KookAgentEndpoint {
|
|
50
|
+
const registered = endpoints.get(endpointId);
|
|
51
|
+
if (!registered) throw new Error(`Endpoint ${endpointId} 不存在`);
|
|
52
|
+
return registered;
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
package/src/platform-permit.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* KOOK platform permit — guild / channel 差异化门禁
|
|
3
3
|
*/
|
|
4
|
-
import type
|
|
5
|
-
import {
|
|
6
|
-
import { KookPermission } from './types.js';
|
|
7
|
-
import type { KookSenderInfo } from './types.js';
|
|
4
|
+
import { registerPlatformPermitChecker, type Message } from '@zhin.js/core';
|
|
5
|
+
import { KookPermission } from './protocol.js';
|
|
8
6
|
|
|
9
7
|
const ADAPTER = 'kook';
|
|
10
8
|
|
|
@@ -21,6 +19,17 @@ export function kookGroupPermitResolver(logicalPerm: string): string {
|
|
|
21
19
|
return platformPermit(FACTORY_PERM_MAP[logicalPerm] ?? logicalPerm);
|
|
22
20
|
}
|
|
23
21
|
|
|
22
|
+
export interface KookSenderInfo {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
permission?: KookPermission;
|
|
26
|
+
roles?: number[];
|
|
27
|
+
isGuildOwner?: boolean;
|
|
28
|
+
isAdmin?: boolean;
|
|
29
|
+
role?: string;
|
|
30
|
+
permissions?: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
24
33
|
export function normalizeKookSenderForPermit(
|
|
25
34
|
info: KookSenderInfo,
|
|
26
35
|
isChannel: boolean,
|