@zhin.js/adapter-discord 1.0.87 → 1.1.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.
- package/CHANGELOG.md +949 -66
- package/PERMITS.md +25 -0
- package/README.md +60 -67
- package/adapters/discord/index.js +41 -0
- package/adapters/discord/index.ts +57 -0
- package/agents/discord/agent.json +20 -0
- package/agents/discord/boundaries.md +3 -0
- package/agents/discord/conventions.md +3 -0
- package/agents/discord/skills/discord/SKILL.md +21 -0
- package/agents/discord/skills/discord/tools/add_role/index.js +24 -0
- package/agents/discord/skills/discord/tools/add_role/index.ts +26 -0
- package/agents/discord/skills/discord/tools/create_thread/index.js +29 -0
- package/agents/discord/skills/discord/tools/create_thread/index.ts +28 -0
- package/agents/discord/skills/discord/tools/forum_post/index.js +33 -0
- package/agents/discord/skills/discord/tools/forum_post/index.ts +33 -0
- package/agents/discord/skills/discord/tools/list_roles/index.js +28 -0
- package/agents/discord/skills/discord/tools/list_roles/index.ts +34 -0
- package/agents/discord/skills/discord/tools/react/index.js +24 -0
- package/agents/discord/skills/discord/tools/react/index.ts +24 -0
- package/agents/discord/skills/discord/tools/remove_role/index.js +24 -0
- package/agents/discord/skills/discord/tools/remove_role/index.ts +26 -0
- package/agents/discord/skills/discord/tools/send_embed/index.js +43 -0
- package/agents/discord/skills/discord/tools/send_embed/index.ts +38 -0
- package/agents/discord/system.md +3 -0
- package/commands/discord/endpoint/add/[id]/index.js +3 -0
- package/commands/discord/endpoint/add/[id]/index.ts +3 -0
- package/commands/discord/endpoint/definition.js +19 -0
- package/commands/discord/endpoint/definition.ts +19 -0
- package/commands/discord/endpoint/list/index.js +3 -0
- package/commands/discord/endpoint/list/index.ts +3 -0
- package/commands/discord/endpoint/remove/[id]/index.js +3 -0
- package/commands/discord/endpoint/remove/[id]/index.ts +3 -0
- package/lib/client.d.ts +16 -0
- package/lib/client.js +8 -0
- package/lib/discord-runtime-state.d.ts +1 -0
- package/lib/discord-runtime-state.js +6 -0
- package/lib/endpoint.d.ts +72 -0
- package/lib/endpoint.js +458 -0
- package/lib/gateway.d.ts +144 -0
- package/lib/gateway.js +303 -0
- package/lib/index.d.ts +6 -18
- package/lib/index.js +6 -323
- package/lib/platform-permit.d.ts +14 -0
- package/lib/platform-permit.js +42 -0
- package/lib/protocol.d.ts +145 -0
- package/lib/protocol.js +320 -0
- package/lib/side-event-dispatch.d.ts +8 -0
- package/lib/side-event-dispatch.js +24 -0
- package/lib/webhook.d.ts +14 -0
- package/lib/webhook.js +88 -0
- package/package.json +74 -30
- package/plugin.js +19 -0
- package/schema.json +205 -0
- package/src/client.ts +24 -0
- package/src/discord-runtime-state.ts +7 -0
- package/src/endpoint.ts +562 -0
- package/src/gateway.ts +426 -0
- package/src/index.ts +57 -323
- package/src/platform-permit.ts +57 -0
- package/src/protocol.ts +475 -0
- package/src/side-event-dispatch.ts +37 -0
- package/src/webhook.ts +123 -0
- package/client/Dashboard.tsx +0 -195
- package/client/index.tsx +0 -11
- package/client/tsconfig.json +0 -7
- package/client/utils/api.ts +0 -17
- package/dist/index.js +0 -29
- package/lib/adapter.d.ts +0 -19
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -90
- package/lib/adapter.js.map +0 -1
- package/lib/bot-interactions.d.ts +0 -33
- package/lib/bot-interactions.d.ts.map +0 -1
- package/lib/bot-interactions.js +0 -278
- package/lib/bot-interactions.js.map +0 -1
- package/lib/bot.d.ts +0 -117
- package/lib/bot.d.ts.map +0 -1
- package/lib/bot.js +0 -904
- package/lib/bot.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types.d.ts +0 -49
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/plugin.yml +0 -3
- package/skills/discord/SKILL.md +0 -104
- package/src/adapter.ts +0 -107
- package/src/bot-interactions.ts +0 -348
- package/src/bot.ts +0 -1037
- package/src/types.ts +0 -60
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-discord",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Zhin.js adapter for
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"description": "Zhin.js Discord adapter for Plugin Runtime (Gateway WebSocket)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
@@ -32,52 +32,96 @@
|
|
|
32
32
|
"directory": "plugins/adapters/discord"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"discord.js": "^14.
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"@zhin.js/
|
|
46
|
-
"@zhin.js/console": "2.0.24",
|
|
47
|
-
"zhin.js": "1.0.81"
|
|
35
|
+
"discord.js": "^14.27.0",
|
|
36
|
+
"@zhin.js/adapter": "1.1.14",
|
|
37
|
+
"@zhin.js/agent-feature": "1.1.1",
|
|
38
|
+
"@zhin.js/core": "1.1.37",
|
|
39
|
+
"@zhin.js/feature-kit": "1.1.1",
|
|
40
|
+
"@zhin.js/host-http": "1.1.1",
|
|
41
|
+
"@zhin.js/im-contract": "1.1.1",
|
|
42
|
+
"@zhin.js/logger": "1.1.1",
|
|
43
|
+
"@zhin.js/permission": "1.1.1",
|
|
44
|
+
"@zhin.js/skill": "1.1.1",
|
|
45
|
+
"@zhin.js/tool": "1.1.1"
|
|
48
46
|
},
|
|
49
47
|
"peerDependencies": {
|
|
50
|
-
"
|
|
51
|
-
"@zhin.js/
|
|
52
|
-
"@zhin.js/
|
|
53
|
-
"zhin.js": "1.
|
|
48
|
+
"zod": "^4.0.0",
|
|
49
|
+
"@zhin.js/adapter": "^1.1.14",
|
|
50
|
+
"@zhin.js/command": "^1.1.1",
|
|
51
|
+
"@zhin.js/core": "^1.1.37",
|
|
52
|
+
"zhin.js": "^1.1.2"
|
|
54
53
|
},
|
|
55
54
|
"peerDependenciesMeta": {
|
|
56
|
-
"@zhin.js/
|
|
55
|
+
"@zhin.js/command": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"zhin.js": {
|
|
57
59
|
"optional": true
|
|
58
60
|
},
|
|
59
|
-
"
|
|
61
|
+
"zod": {
|
|
60
62
|
"optional": true
|
|
61
63
|
}
|
|
62
64
|
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@types/node": "^26.1.2",
|
|
67
|
+
"typescript": "^6.0.3",
|
|
68
|
+
"vitest": "^4.1.10",
|
|
69
|
+
"zod": "^4.4.3",
|
|
70
|
+
"@zhin.js/host-http": "1.1.1",
|
|
71
|
+
"zhin.js": "1.1.2"
|
|
72
|
+
},
|
|
63
73
|
"files": [
|
|
74
|
+
"adapters",
|
|
75
|
+
"commands",
|
|
76
|
+
"plugin.js",
|
|
77
|
+
"schema.json",
|
|
64
78
|
"src",
|
|
65
79
|
"lib",
|
|
66
|
-
"
|
|
67
|
-
"dist",
|
|
68
|
-
"skills",
|
|
69
|
-
"plugin.yml",
|
|
80
|
+
"agents",
|
|
70
81
|
"README.md",
|
|
71
|
-
"
|
|
72
|
-
"
|
|
82
|
+
"CHANGELOG.md",
|
|
83
|
+
"PERMITS.md"
|
|
73
84
|
],
|
|
74
85
|
"publishConfig": {
|
|
75
86
|
"access": "public",
|
|
76
87
|
"registry": "https://registry.npmjs.org"
|
|
77
88
|
},
|
|
89
|
+
"engines": {
|
|
90
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
91
|
+
},
|
|
92
|
+
"zhin": {
|
|
93
|
+
"protocol": 1,
|
|
94
|
+
"type": "plugin",
|
|
95
|
+
"entry": "./plugin.js",
|
|
96
|
+
"engine": "^1.0.0",
|
|
97
|
+
"runtime": "trusted",
|
|
98
|
+
"features": [
|
|
99
|
+
{
|
|
100
|
+
"package": "@zhin.js/adapter",
|
|
101
|
+
"api": "^1.0.0"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"package": "@zhin.js/command",
|
|
105
|
+
"api": "^1.0.0"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"package": "@zhin.js/tool",
|
|
109
|
+
"api": "^1.0.0"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"package": "@zhin.js/skill",
|
|
113
|
+
"api": "^1.0.0"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"package": "@zhin.js/agent-feature",
|
|
117
|
+
"api": "^1.0.0"
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
"plugins": []
|
|
121
|
+
},
|
|
78
122
|
"scripts": {
|
|
79
|
-
"build": "
|
|
80
|
-
"clean": "rimraf lib
|
|
81
|
-
"
|
|
123
|
+
"build": "tsc",
|
|
124
|
+
"clean": "rimraf lib",
|
|
125
|
+
"test": "NODE_OPTIONS=--experimental-strip-types vitest run --root ../../.. plugins/adapters/discord/tests"
|
|
82
126
|
}
|
|
83
127
|
}
|
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 { checkDiscordPlatformPermit } from "./lib/platform-permit.js";
|
|
6
|
+
import { discordRuntimeStateToken } from "./lib/discord-runtime-state.js";
|
|
7
|
+
export default definePlugin({
|
|
8
|
+
name: 'discord',
|
|
9
|
+
metadata: {
|
|
10
|
+
displayName: 'Discord Gateway Adapter',
|
|
11
|
+
},
|
|
12
|
+
setup(context) {
|
|
13
|
+
context.resources.provide(discordRuntimeStateToken, createEndpointRuntimeState());
|
|
14
|
+
if (context.resources.has(permissionHostToken)) {
|
|
15
|
+
const host = context.resources.use(permissionHostToken);
|
|
16
|
+
return host.registerPlatform('discord', checkDiscordPlatformPermit);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
});
|
package/schema.json
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
"gateway",
|
|
10
|
+
"interactions"
|
|
11
|
+
],
|
|
12
|
+
"default": "gateway",
|
|
13
|
+
"description": "Gateway WebSocket (default). interactions uses httpHostToken POST + Ed25519 verify."
|
|
14
|
+
},
|
|
15
|
+
"intents": {
|
|
16
|
+
"type": "array",
|
|
17
|
+
"items": {
|
|
18
|
+
"type": "number"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"enableSlashCommands": {
|
|
22
|
+
"type": "boolean",
|
|
23
|
+
"default": false
|
|
24
|
+
},
|
|
25
|
+
"globalCommands": {
|
|
26
|
+
"type": "boolean",
|
|
27
|
+
"default": false
|
|
28
|
+
},
|
|
29
|
+
"defaultActivity": {
|
|
30
|
+
"type": "object",
|
|
31
|
+
"additionalProperties": false,
|
|
32
|
+
"properties": {
|
|
33
|
+
"name": {
|
|
34
|
+
"type": "string"
|
|
35
|
+
},
|
|
36
|
+
"type": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"enum": [
|
|
39
|
+
"PLAYING",
|
|
40
|
+
"STREAMING",
|
|
41
|
+
"LISTENING",
|
|
42
|
+
"WATCHING",
|
|
43
|
+
"COMPETING"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"url": {
|
|
47
|
+
"type": "string"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"required": [
|
|
51
|
+
"name",
|
|
52
|
+
"type"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"slashCommands": {
|
|
56
|
+
"type": "array",
|
|
57
|
+
"items": {
|
|
58
|
+
"type": "object"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"applicationId": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"description": "Required when connection is interactions."
|
|
64
|
+
},
|
|
65
|
+
"publicKey": {
|
|
66
|
+
"type": "string",
|
|
67
|
+
"description": "Required when connection is interactions (hex Ed25519 public key)."
|
|
68
|
+
},
|
|
69
|
+
"interactionsPath": {
|
|
70
|
+
"type": "string",
|
|
71
|
+
"default": "/discord/interactions",
|
|
72
|
+
"description": "POST path on httpHostToken when connection is interactions."
|
|
73
|
+
},
|
|
74
|
+
"master": {
|
|
75
|
+
"type": [
|
|
76
|
+
"string",
|
|
77
|
+
"number"
|
|
78
|
+
],
|
|
79
|
+
"description": "框架 master(Discord user snowflake;AI/工具权限、endpoint 管理)。endpoints[i].master 可逐项覆盖"
|
|
80
|
+
},
|
|
81
|
+
"trusted": {
|
|
82
|
+
"type": "array",
|
|
83
|
+
"items": {
|
|
84
|
+
"type": [
|
|
85
|
+
"string",
|
|
86
|
+
"number"
|
|
87
|
+
],
|
|
88
|
+
"description": "Trusted Discord user snowflake"
|
|
89
|
+
},
|
|
90
|
+
"description": "框架 trusted 用户列表(弱于 master)。endpoints[i].trusted 可逐项追加"
|
|
91
|
+
},
|
|
92
|
+
"endpoints": {
|
|
93
|
+
"type": "array",
|
|
94
|
+
"minItems": 1,
|
|
95
|
+
"description": "多账号:每项定义一个 endpoint,id/token 必填,其余字段覆盖实例默认值",
|
|
96
|
+
"items": {
|
|
97
|
+
"type": "object",
|
|
98
|
+
"additionalProperties": false,
|
|
99
|
+
"properties": {
|
|
100
|
+
"master": {
|
|
101
|
+
"type": [
|
|
102
|
+
"string",
|
|
103
|
+
"number"
|
|
104
|
+
],
|
|
105
|
+
"description": "本 endpoint 的框架 master(Discord user snowflake);覆盖顶层 master"
|
|
106
|
+
},
|
|
107
|
+
"trusted": {
|
|
108
|
+
"type": "array",
|
|
109
|
+
"items": {
|
|
110
|
+
"type": [
|
|
111
|
+
"string",
|
|
112
|
+
"number"
|
|
113
|
+
],
|
|
114
|
+
"description": "Trusted Discord user snowflake"
|
|
115
|
+
},
|
|
116
|
+
"description": "本 endpoint 的 trusted 列表"
|
|
117
|
+
},
|
|
118
|
+
"token": {
|
|
119
|
+
"type": "string",
|
|
120
|
+
"description": "Discord bot token"
|
|
121
|
+
},
|
|
122
|
+
"connection": {
|
|
123
|
+
"type": "string",
|
|
124
|
+
"enum": [
|
|
125
|
+
"gateway",
|
|
126
|
+
"interactions"
|
|
127
|
+
]
|
|
128
|
+
},
|
|
129
|
+
"intents": {
|
|
130
|
+
"type": "array",
|
|
131
|
+
"items": {
|
|
132
|
+
"type": "number"
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
"enableSlashCommands": {
|
|
136
|
+
"type": "boolean"
|
|
137
|
+
},
|
|
138
|
+
"globalCommands": {
|
|
139
|
+
"type": "boolean"
|
|
140
|
+
},
|
|
141
|
+
"defaultActivity": {
|
|
142
|
+
"type": "object",
|
|
143
|
+
"additionalProperties": false,
|
|
144
|
+
"properties": {
|
|
145
|
+
"name": {
|
|
146
|
+
"type": "string"
|
|
147
|
+
},
|
|
148
|
+
"type": {
|
|
149
|
+
"type": "string",
|
|
150
|
+
"enum": [
|
|
151
|
+
"PLAYING",
|
|
152
|
+
"STREAMING",
|
|
153
|
+
"LISTENING",
|
|
154
|
+
"WATCHING",
|
|
155
|
+
"COMPETING"
|
|
156
|
+
]
|
|
157
|
+
},
|
|
158
|
+
"url": {
|
|
159
|
+
"type": "string"
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
"required": [
|
|
163
|
+
"name",
|
|
164
|
+
"type"
|
|
165
|
+
]
|
|
166
|
+
},
|
|
167
|
+
"slashCommands": {
|
|
168
|
+
"type": "array",
|
|
169
|
+
"items": {
|
|
170
|
+
"type": "object"
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
"applicationId": {
|
|
174
|
+
"type": "string"
|
|
175
|
+
},
|
|
176
|
+
"publicKey": {
|
|
177
|
+
"type": "string"
|
|
178
|
+
},
|
|
179
|
+
"interactionsPath": {
|
|
180
|
+
"type": "string"
|
|
181
|
+
},
|
|
182
|
+
"commandPrefix": {
|
|
183
|
+
"type": "string"
|
|
184
|
+
},
|
|
185
|
+
"id": {
|
|
186
|
+
"type": "string",
|
|
187
|
+
"description": "Discord bot name"
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
"required": [
|
|
191
|
+
"id",
|
|
192
|
+
"token"
|
|
193
|
+
]
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
"commandPrefix": {
|
|
197
|
+
"type": "string",
|
|
198
|
+
"default": "",
|
|
199
|
+
"description": "命令前缀(默认 '' 无前缀,任意文本按命令匹配;如 '/' 要求 / 开头)。endpoints[i] 可逐项覆盖"
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
"required": [
|
|
203
|
+
"endpoints"
|
|
204
|
+
]
|
|
205
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineEndpointClient } from 'zhin.js/adapter';
|
|
2
|
+
import type { DiscordRestClient } from './endpoint.js';
|
|
3
|
+
import type { DiscordClientTransport } from './gateway.js';
|
|
4
|
+
|
|
5
|
+
/** Exact Client variants produced by the Gateway and Interactions Endpoints. */
|
|
6
|
+
export type DiscordClient = DiscordClientTransport | DiscordRestClient;
|
|
7
|
+
export type DiscordClientEventMap = Record<string, unknown>;
|
|
8
|
+
|
|
9
|
+
/** Narrow an adapter Client for Gateway-only SDK operations. */
|
|
10
|
+
export function requireDiscordGatewayClient(client: DiscordClient): DiscordClientTransport {
|
|
11
|
+
if ('guilds' in client && 'channels' in client) return client;
|
|
12
|
+
throw new Error('This Discord tool requires a Gateway Endpoint Client');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare module '@zhin.js/feature-kit' {
|
|
16
|
+
interface AdapterClientRegistry {
|
|
17
|
+
readonly discord: {
|
|
18
|
+
readonly client: DiscordClient;
|
|
19
|
+
readonly events: DiscordClientEventMap;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const discordClient = defineEndpointClient<DiscordClient, DiscordClientEventMap>('discord');
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord 插件实例的运行时状态:adapter create() 注册的 endpoint 列表。
|
|
3
|
+
* 由 plugin.ts setup() provide,adapter create 与 `discord endpoint` 命令共享(同一 owner generation)。
|
|
4
|
+
*/
|
|
5
|
+
import { defineEndpointRuntimeStateToken } from 'zhin.js/adapter';
|
|
6
|
+
|
|
7
|
+
export const discordRuntimeStateToken = defineEndpointRuntimeStateToken('discord');
|