@zhin.js/adapter-kook 1.0.83 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/CHANGELOG.md +813 -16
  2. package/README.md +75 -374
  3. package/adapters/kook.js +41 -0
  4. package/adapters/kook.ts +56 -0
  5. package/agent/PERMITS.md +23 -0
  6. package/agent/tools/blacklist.ts +31 -0
  7. package/agent/tools/create_role.ts +23 -0
  8. package/agent/tools/delete_role.ts +19 -0
  9. package/agent/tools/grant_role.ts +20 -0
  10. package/agent/tools/list_roles.ts +25 -0
  11. package/agent/tools/revoke_role.ts +20 -0
  12. package/commands/endpoint/add/[id].js +3 -0
  13. package/commands/endpoint/add/[id].ts +3 -0
  14. package/commands/endpoint/list.js +3 -0
  15. package/commands/endpoint/list.ts +3 -0
  16. package/commands/endpoint/remove/[id].js +3 -0
  17. package/commands/endpoint/remove/[id].ts +3 -0
  18. package/lib/client.d.ts +11 -0
  19. package/lib/client.js +2 -0
  20. package/lib/endpoint.d.ts +59 -0
  21. package/lib/endpoint.js +374 -0
  22. package/lib/index.d.ts +6 -18
  23. package/lib/index.js +6 -342
  24. package/lib/kook-endpoint-commands.d.ts +1 -0
  25. package/lib/kook-endpoint-commands.js +18 -0
  26. package/lib/kook-runtime-state.d.ts +1 -0
  27. package/lib/kook-runtime-state.js +6 -0
  28. package/lib/platform-permit.d.ts +22 -0
  29. package/lib/platform-permit.js +48 -0
  30. package/lib/protocol.d.ts +144 -0
  31. package/lib/protocol.js +313 -0
  32. package/lib/side-event-dispatch.d.ts +3 -0
  33. package/lib/side-event-dispatch.js +49 -0
  34. package/lib/webhook.d.ts +16 -0
  35. package/lib/webhook.js +71 -0
  36. package/lib/ws.d.ts +56 -0
  37. package/lib/ws.js +63 -0
  38. package/package.json +60 -28
  39. package/plugin.js +19 -0
  40. package/schema.json +128 -0
  41. package/src/client.ts +15 -0
  42. package/src/endpoint.ts +433 -0
  43. package/src/index.ts +45 -322
  44. package/src/kook-endpoint-commands.ts +19 -0
  45. package/src/kook-runtime-state.ts +7 -0
  46. package/src/platform-permit.ts +75 -0
  47. package/src/protocol.ts +462 -0
  48. package/src/side-event-dispatch.ts +54 -0
  49. package/src/webhook.ts +114 -0
  50. package/src/ws.ts +131 -0
  51. package/client/Dashboard.tsx +0 -255
  52. package/client/index.tsx +0 -11
  53. package/client/tsconfig.json +0 -7
  54. package/client/utils/api.ts +0 -17
  55. package/dist/index.js +0 -31
  56. package/lib/adapter.d.ts +0 -26
  57. package/lib/adapter.d.ts.map +0 -1
  58. package/lib/adapter.js +0 -61
  59. package/lib/adapter.js.map +0 -1
  60. package/lib/bot.d.ts +0 -122
  61. package/lib/bot.d.ts.map +0 -1
  62. package/lib/bot.js +0 -608
  63. package/lib/bot.js.map +0 -1
  64. package/lib/index.d.ts.map +0 -1
  65. package/lib/index.js.map +0 -1
  66. package/lib/types.d.ts +0 -32
  67. package/lib/types.d.ts.map +0 -1
  68. package/lib/types.js +0 -8
  69. package/lib/types.js.map +0 -1
  70. package/plugin.yml +0 -3
  71. package/src/adapter.ts +0 -71
  72. package/src/bot.ts +0 -693
  73. package/src/types.ts +0 -36
  74. /package/{skills/kook/SKILL.md → agent/skills/kook.md} +0 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zhin.js/adapter-kook",
3
- "version": "1.0.83",
4
- "description": "Zhin.js adapter for KOOK (开黑啦)",
3
+ "version": "1.1.0",
4
+ "description": "Zhin.js KOOK adapter for Plugin Runtime (WebSocket gateway or Webhook)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./lib/index.d.ts",
@@ -33,53 +33,85 @@
33
33
  "directory": "plugins/adapters/kook"
34
34
  },
35
35
  "dependencies": {
36
- "kook-client": "^1.0.4"
37
- },
38
- "devDependencies": {
39
- "@types/react": "^19.2.14",
40
- "@types/react-dom": "^19.2.3",
41
- "lucide-react": "^1.14.0",
42
- "typescript": "^6.0.3",
43
- "@zhin.js/cli": "1.0.76",
44
- "@zhin.js/console": "2.0.23",
45
- "zhin.js": "1.0.80"
36
+ "kook-client": "^1.0.4",
37
+ "@zhin.js/adapter": "1.1.12",
38
+ "@zhin.js/core": "1.1.35",
39
+ "@zhin.js/feature-kit": "1.1.0",
40
+ "@zhin.js/host-http": "1.1.0",
41
+ "@zhin.js/im-contract": "1.1.0",
42
+ "@zhin.js/logger": "1.1.0",
43
+ "@zhin.js/permission": "1.1.0"
46
44
  },
47
45
  "peerDependencies": {
48
- "@zhin.js/client": "1.0.18",
49
- "@zhin.js/console": "2.0.23",
50
- "@zhin.js/http": "1.0.73",
51
- "@zhin.js/logger": "0.1.62",
52
- "zhin.js": "1.0.80"
46
+ "zod": "^4.0.0",
47
+ "@zhin.js/adapter": "^1.1.12",
48
+ "@zhin.js/agent": "^1.1.23",
49
+ "@zhin.js/command": "^1.1.0",
50
+ "@zhin.js/core": "^1.1.35",
51
+ "zhin.js": "^1.1.0"
53
52
  },
54
53
  "peerDependenciesMeta": {
55
- "@zhin.js/client": {
54
+ "@zhin.js/agent": {
55
+ "optional": true
56
+ },
57
+ "@zhin.js/command": {
56
58
  "optional": true
57
59
  },
58
- "@zhin.js/http": {
60
+ "zhin.js": {
59
61
  "optional": true
60
62
  },
61
- "@zhin.js/console": {
63
+ "zod": {
62
64
  "optional": true
63
65
  }
64
66
  },
67
+ "devDependencies": {
68
+ "@types/node": "^26.1.2",
69
+ "typescript": "^6.0.3",
70
+ "vitest": "^4.1.10",
71
+ "zod": "^4.4.3",
72
+ "@zhin.js/agent": "1.1.23",
73
+ "@zhin.js/host-http": "1.1.0",
74
+ "zhin.js": "1.1.0"
75
+ },
65
76
  "files": [
77
+ "adapters",
78
+ "commands",
79
+ "plugin.js",
80
+ "schema.json",
66
81
  "src",
67
82
  "lib",
68
- "client",
69
- "dist",
70
- "skills",
71
- "plugin.yml",
83
+ "agent",
72
84
  "README.md",
73
- "node",
74
85
  "CHANGELOG.md"
75
86
  ],
76
87
  "publishConfig": {
77
88
  "access": "public",
78
89
  "registry": "https://registry.npmjs.org"
79
90
  },
91
+ "engines": {
92
+ "node": "^20.19.0 || >=22.12.0"
93
+ },
94
+ "zhin": {
95
+ "protocol": 1,
96
+ "type": "plugin",
97
+ "entry": "./plugin.js",
98
+ "engine": "^1.0.0",
99
+ "runtime": "trusted",
100
+ "features": [
101
+ {
102
+ "package": "@zhin.js/adapter",
103
+ "api": "^1.0.0"
104
+ },
105
+ {
106
+ "package": "@zhin.js/command",
107
+ "api": "^1.0.0"
108
+ }
109
+ ],
110
+ "plugins": []
111
+ },
80
112
  "scripts": {
81
- "build": "zhin build",
82
- "clean": "rimraf lib dist",
83
- "build:node": "tsc"
113
+ "build": "tsc",
114
+ "clean": "rimraf lib",
115
+ "test": "NODE_OPTIONS=--experimental-strip-types vitest run --root ../../.. plugins/adapters/kook/tests"
84
116
  }
85
117
  }
package/plugin.js ADDED
@@ -0,0 +1,19 @@
1
+ // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
+ import { createEndpointRuntimeState } from 'zhin.js/adapter';
3
+ import { definePlugin } from 'zhin.js';
4
+ import { permissionHostToken } from '@zhin.js/permission';
5
+ import { checkKookPlatformPermit } from "./lib/platform-permit.js";
6
+ import { kookRuntimeStateToken } from "./lib/kook-runtime-state.js";
7
+ export default definePlugin({
8
+ name: 'kook',
9
+ metadata: {
10
+ displayName: 'KOOK WebSocket Adapter',
11
+ },
12
+ setup(context) {
13
+ context.resources.provide(kookRuntimeStateToken, createEndpointRuntimeState());
14
+ if (context.resources.has(permissionHostToken)) {
15
+ const host = context.resources.use(permissionHostToken);
16
+ return host.registerPlatform('kook', checkKookPlatformPermit);
17
+ }
18
+ },
19
+ });
package/schema.json ADDED
@@ -0,0 +1,128 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "type": "object",
4
+ "additionalProperties": false,
5
+ "properties": {
6
+ "connection": {
7
+ "type": "string",
8
+ "enum": [
9
+ "websocket",
10
+ "webhook"
11
+ ],
12
+ "default": "websocket",
13
+ "description": "WebSocket gateway (default). webhook requires httpHostToken, verify_token, and a public HTTPS callback URL."
14
+ },
15
+ "webhookPath": {
16
+ "type": "string",
17
+ "default": "/kook/webhook",
18
+ "description": "POST path registered via httpHostToken when connection is webhook."
19
+ },
20
+ "data_dir": {
21
+ "type": "string"
22
+ },
23
+ "timeout": {
24
+ "type": "number",
25
+ "default": 10000
26
+ },
27
+ "max_retry": {
28
+ "type": "number",
29
+ "default": 3
30
+ },
31
+ "ignore": {
32
+ "type": "string",
33
+ "enum": [
34
+ "bot",
35
+ "self"
36
+ ],
37
+ "default": "bot"
38
+ },
39
+ "logLevel": {
40
+ "type": "string",
41
+ "enum": [
42
+ "trace",
43
+ "debug",
44
+ "info",
45
+ "warn",
46
+ "error",
47
+ "fatal",
48
+ "mark",
49
+ "off"
50
+ ],
51
+ "default": "info"
52
+ },
53
+ "master": {
54
+ "type": [
55
+ "string",
56
+ "number"
57
+ ],
58
+ "description": "框架 master(KOOK user id;AI/工具权限、endpoint 管理)。endpoints[i].master 可逐项覆盖"
59
+ },
60
+ "trusted": {
61
+ "type": "array",
62
+ "items": {
63
+ "type": [
64
+ "string",
65
+ "number"
66
+ ],
67
+ "description": "Trusted KOOK user id"
68
+ },
69
+ "description": "框架 trusted 用户列表(弱于 master)。endpoints[i].trusted 可逐项追加"
70
+ },
71
+ "endpoints": {
72
+ "type": "array",
73
+ "description": "多账号:一个插件实例挂多个 endpoint。每项与顶层字段同构(id 必填,其余覆盖顶层)",
74
+ "items": {
75
+ "type": "object",
76
+ "additionalProperties": true,
77
+ "properties": {
78
+ "master": {
79
+ "type": [
80
+ "string",
81
+ "number"
82
+ ],
83
+ "description": "本 endpoint 的框架 master(KOOK user id);覆盖顶层 master"
84
+ },
85
+ "trusted": {
86
+ "type": "array",
87
+ "items": {
88
+ "type": [
89
+ "string",
90
+ "number"
91
+ ],
92
+ "description": "Trusted KOOK user id"
93
+ },
94
+ "description": "本 endpoint 的 trusted 列表"
95
+ },
96
+ "token": {
97
+ "type": "string",
98
+ "description": "KOOK bot token"
99
+ },
100
+ "verify_token": {
101
+ "type": "string",
102
+ "description": "KOOK developer console verify token (required for webhook mode)."
103
+ },
104
+ "encrypt_key": {
105
+ "type": "string",
106
+ "description": "Optional Encrypt Key when message encryption is enabled in KOOK console."
107
+ },
108
+ "id": {
109
+ "type": "string",
110
+ "description": "KOOK bot name"
111
+ }
112
+ },
113
+ "required": [
114
+ "id",
115
+ "token"
116
+ ]
117
+ }
118
+ },
119
+ "commandPrefix": {
120
+ "type": "string",
121
+ "default": "",
122
+ "description": "命令前缀(默认 '' 无前缀,任意文本按命令匹配;如 '/' 要求 / 开头)。endpoints[i] 可逐项覆盖"
123
+ }
124
+ },
125
+ "required": [
126
+ "endpoints"
127
+ ]
128
+ }
package/src/client.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { defineEndpointClient } from 'zhin.js/adapter';
2
+ import type { KookClientTransport } from './ws.js';
3
+
4
+ export type KookClientEventMap = Record<string, unknown>;
5
+
6
+ declare module '@zhin.js/feature-kit' {
7
+ interface AdapterClientRegistry {
8
+ readonly kook: {
9
+ readonly client: KookClientTransport;
10
+ readonly events: KookClientEventMap;
11
+ };
12
+ }
13
+ }
14
+
15
+ export const kookClient = defineEndpointClient<KookClientTransport, KookClientEventMap>('kook');