@zhin.js/adapter-discord 1.1.0 → 1.1.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 +110 -0
- package/README.md +7 -8
- package/adapters/{discord.js → discord/index.js} +6 -6
- package/adapters/{discord.ts → discord/index.ts} +9 -9
- 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/{agent/tools/add_role.ts → agents/discord/skills/discord/tools/add_role/index.ts} +4 -4
- package/agents/discord/skills/discord/tools/create_thread/index.js +29 -0
- package/{agent/tools/create_thread.ts → agents/discord/skills/discord/tools/create_thread/index.ts} +4 -4
- package/agents/discord/skills/discord/tools/forum_post/index.js +33 -0
- package/{agent/tools/forum_post.ts → agents/discord/skills/discord/tools/forum_post/index.ts} +2 -2
- package/agents/discord/skills/discord/tools/list_roles/index.js +28 -0
- package/{agent/tools/list_roles.ts → agents/discord/skills/discord/tools/list_roles/index.ts} +4 -4
- package/agents/discord/skills/discord/tools/react/index.js +24 -0
- package/{agent/tools/react.ts → agents/discord/skills/discord/tools/react/index.ts} +2 -2
- package/agents/discord/skills/discord/tools/remove_role/index.js +24 -0
- package/{agent/tools/remove_role.ts → agents/discord/skills/discord/tools/remove_role/index.ts} +4 -4
- package/agents/discord/skills/discord/tools/send_embed/index.js +43 -0
- package/{agent/tools/send_embed.ts → agents/discord/skills/discord/tools/send_embed/index.ts} +2 -2
- package/agents/discord/system.md +3 -0
- package/commands/{endpoint/add/[id].js → discord/endpoint/add/[id]/index.js} +1 -1
- package/commands/discord/endpoint/add/[id]/index.ts +3 -0
- package/{lib/discord-endpoint-commands.js → commands/discord/endpoint/definition.js} +5 -4
- package/{src/discord-endpoint-commands.ts → commands/discord/endpoint/definition.ts} +4 -4
- package/commands/{endpoint/list.js → discord/endpoint/list/index.js} +1 -1
- package/commands/discord/endpoint/list/index.ts +3 -0
- package/commands/{endpoint/remove/[id].js → discord/endpoint/remove/[id]/index.js} +1 -1
- package/commands/discord/endpoint/remove/[id]/index.ts +3 -0
- package/lib/discord-runtime-state.js +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +1 -1
- package/lib/protocol.d.ts +15 -32
- package/lib/protocol.js +20 -33
- package/package.json +32 -21
- package/schema.json +66 -2
- package/src/discord-runtime-state.ts +1 -1
- package/src/index.ts +3 -1
- package/src/protocol.ts +37 -64
- package/agent/skills/discord.md +0 -104
- package/commands/endpoint/add/[id].ts +0 -3
- package/commands/endpoint/list.ts +0 -3
- package/commands/endpoint/remove/[id].ts +0 -3
- package/lib/discord-endpoint-commands.d.ts +0 -1
- /package/{agent/PERMITS.md → PERMITS.md} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,115 @@
|
|
|
1
1
|
# @zhin.js/adapter-discord
|
|
2
2
|
|
|
3
|
+
## 1.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [5b5d270]
|
|
8
|
+
- Updated dependencies [36c2eb9]
|
|
9
|
+
- @zhin.js/im-contract@1.1.2
|
|
10
|
+
- @zhin.js/core@1.1.38
|
|
11
|
+
- @zhin.js/adapter@1.1.15
|
|
12
|
+
- @zhin.js/host-http@1.1.2
|
|
13
|
+
- @zhin.js/agent-feature@1.1.2
|
|
14
|
+
- @zhin.js/feature-kit@1.1.2
|
|
15
|
+
- @zhin.js/permission@1.1.2
|
|
16
|
+
- @zhin.js/skill@1.1.2
|
|
17
|
+
- @zhin.js/tool@1.1.2
|
|
18
|
+
|
|
19
|
+
## 1.1.2
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- a9e4a40: Derive Command user routes only from explicit `commands/**/*/index.ts(x)` entry paths instead of prepending the plugin owner. Child plugins can now publish top-level static or dynamic commands, while duplicate routes across owners fail during generation construction. Adapter endpoint commands move to explicit paths such as `commands/qq/endpoint/list/index.ts` and are invoked as `qq endpoint list`.
|
|
24
|
+
- 8740059: Standardize TypeScript capabilities on named module directories such as `commands/foo/index.ts`, `middlewares/audit/index.ts`, `handlers/message-receive/index.ts`, `pages/workroom/index.tsx`, and `mcps/filesystem/index.ts`. Only the fixed `index` entry is discovered; sibling files remain private helpers.
|
|
25
|
+
|
|
26
|
+
Command route segments come from directories, while `[name]`, `[[name]]`, `[...name]`, and `[[...name]]` directories declare dynamic parameters. Plugin owners do not enter the route unless their config explicitly sets `commandNamespace`; Endpoint `commandPrefix` remains platform-owned and defaults to an empty string.
|
|
27
|
+
|
|
28
|
+
Migrate the built-in adapters, plugins, examples, generators, migration tooling, hot reload classification, Agent authoring surfaces, documentation, and release artifacts to the explicit entry convention.
|
|
29
|
+
|
|
30
|
+
Make Tool ownership and progressive disclosure explicit across all four supported locations: plugin-public `tools/`, Agent-private `agents/<name>/tools/`, Skill-private `skills/<name>/tools/`, and Agent-Skill-private `agents/<name>/skills/<name>/tools/`. Move adapter and group-suite operations that require domain instructions into their owning Skills so `load_skill` is the only path that unlocks their schemas.
|
|
31
|
+
|
|
32
|
+
Remove the package-root `agent/` convention. Public capabilities now use named package-root directories, schedules use `schedules/<name>/index.ts` or `plugin.ts` injection, MCP connections use `mcps/<name>/index.ts`, Prompt Sections use `prompt-sections/<name>/index.ts`, Agent definitions use `agents/<name>/`, and permission vocabulary is published as `PERMITS.md`.
|
|
33
|
+
|
|
34
|
+
- 25a845a: Unify Skills on `skills/<name>/SKILL.md`, support Agent-private Skills and nested Skill-private Tools, publish and mount existing plugin Skills, add governed Skill metadata and Turn access filtering, unlock only already-admitted same-owner Tools, and make `on-risk` and `once` approval behavior precise.
|
|
35
|
+
- ddbb92e: Isolate adapter Skills under platform-specific Agents and automatically select the matching platform Agent for IM ingress, preventing unrelated adapter Skills from entering another platform's prompt surface.
|
|
36
|
+
- 4380cf9: Colocate adapter command definitions and Agent Skill handlers with their owning capabilities, and provide a shared validated platform permission constructor.
|
|
37
|
+
- bc0df3c: Require the canonical expanded Discord endpoint configuration. The protocol no longer reinterprets nested `endpoints` or reads endpoint identity and token from `process.env`. The public config type is now `DiscordEndpointConfig`, and each schema entry uses `id` as its identity.
|
|
38
|
+
- 5c3858e: Make `@zhin.js/im-contract` the explicit zero-dependency owner of transport identities, canonical segments, media guards, conversation facts, stores, and delivery contracts. Platform adapters now read media contracts from that foundation instead of reaching through Core.
|
|
39
|
+
- 33ea736: Use `tools/<name>/index.ts` and `defineAgentTool` from `@zhin.js/tool` as the sole Agent Tool authoring model. Remove the duplicate `@zhin.js/tools` definition, context, bridge, export, and discovery path; migrate plugin manifests, examples, scaffolding, HMR, and prepack compilation to the generation-owned Tool Feature.
|
|
40
|
+
- Updated dependencies [c861789]
|
|
41
|
+
- Updated dependencies [1414ccb]
|
|
42
|
+
- Updated dependencies [743d470]
|
|
43
|
+
- Updated dependencies [62dee52]
|
|
44
|
+
- Updated dependencies [cd54131]
|
|
45
|
+
- Updated dependencies [244e475]
|
|
46
|
+
- Updated dependencies [a9e4a40]
|
|
47
|
+
- Updated dependencies [5855db7]
|
|
48
|
+
- Updated dependencies [ec921d2]
|
|
49
|
+
- Updated dependencies [8740059]
|
|
50
|
+
- Updated dependencies [63d1f7a]
|
|
51
|
+
- Updated dependencies [25a845a]
|
|
52
|
+
- Updated dependencies [103f2c3]
|
|
53
|
+
- Updated dependencies [9110ab8]
|
|
54
|
+
- Updated dependencies [cd2a888]
|
|
55
|
+
- Updated dependencies [eb3227a]
|
|
56
|
+
- Updated dependencies [b853dba]
|
|
57
|
+
- Updated dependencies [e561309]
|
|
58
|
+
- Updated dependencies [d4c6175]
|
|
59
|
+
- Updated dependencies [7a0e1ca]
|
|
60
|
+
- Updated dependencies [103b5d3]
|
|
61
|
+
- Updated dependencies [5a7a7f7]
|
|
62
|
+
- Updated dependencies [b076eae]
|
|
63
|
+
- Updated dependencies [535fed1]
|
|
64
|
+
- Updated dependencies [73a24b7]
|
|
65
|
+
- Updated dependencies [4380cf9]
|
|
66
|
+
- Updated dependencies [2dbbc15]
|
|
67
|
+
- Updated dependencies [1cb1163]
|
|
68
|
+
- Updated dependencies [be3061e]
|
|
69
|
+
- Updated dependencies [75f8332]
|
|
70
|
+
- Updated dependencies [81935e2]
|
|
71
|
+
- Updated dependencies [f9ed01b]
|
|
72
|
+
- Updated dependencies [ac0ab50]
|
|
73
|
+
- Updated dependencies [5140ce1]
|
|
74
|
+
- Updated dependencies [522d75f]
|
|
75
|
+
- Updated dependencies [a7611b3]
|
|
76
|
+
- Updated dependencies [8823044]
|
|
77
|
+
- Updated dependencies [379439b]
|
|
78
|
+
- Updated dependencies [11c9352]
|
|
79
|
+
- Updated dependencies [6b70e46]
|
|
80
|
+
- Updated dependencies [135ac91]
|
|
81
|
+
- Updated dependencies [140cf0f]
|
|
82
|
+
- Updated dependencies [251e4d2]
|
|
83
|
+
- Updated dependencies [203ad34]
|
|
84
|
+
- Updated dependencies [e6c5113]
|
|
85
|
+
- Updated dependencies [e0f6478]
|
|
86
|
+
- Updated dependencies [baef56b]
|
|
87
|
+
- Updated dependencies [698f16f]
|
|
88
|
+
- Updated dependencies [da0a8e3]
|
|
89
|
+
- Updated dependencies [2fd8017]
|
|
90
|
+
- Updated dependencies [5c3858e]
|
|
91
|
+
- Updated dependencies [33ea736]
|
|
92
|
+
- Updated dependencies [507d602]
|
|
93
|
+
- Updated dependencies [df9f76b]
|
|
94
|
+
- @zhin.js/core@1.1.37
|
|
95
|
+
- @zhin.js/tool@1.1.1
|
|
96
|
+
- @zhin.js/host-http@1.1.1
|
|
97
|
+
- @zhin.js/adapter@1.1.14
|
|
98
|
+
- @zhin.js/feature-kit@1.1.1
|
|
99
|
+
- @zhin.js/agent-feature@1.1.1
|
|
100
|
+
- @zhin.js/skill@1.1.1
|
|
101
|
+
- @zhin.js/logger@1.1.1
|
|
102
|
+
- @zhin.js/im-contract@1.1.1
|
|
103
|
+
- @zhin.js/permission@1.1.1
|
|
104
|
+
|
|
105
|
+
## 1.1.1
|
|
106
|
+
|
|
107
|
+
### Patch Changes
|
|
108
|
+
|
|
109
|
+
- Updated dependencies [769e67f]
|
|
110
|
+
- @zhin.js/adapter@1.1.13
|
|
111
|
+
- @zhin.js/core@1.1.36
|
|
112
|
+
|
|
3
113
|
## 1.1.0
|
|
4
114
|
|
|
5
115
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ pnpm add @zhin.js/adapter-discord discord.js
|
|
|
19
19
|
|
|
20
20
|
## Plugin Runtime
|
|
21
21
|
|
|
22
|
-
- `@zhin.js/adapter` — 约定式 `adapters/discord.ts`(`defineAdapter`)
|
|
22
|
+
- `@zhin.js/adapter` — 约定式 `adapters/discord/index.ts`(`defineAdapter`)
|
|
23
23
|
- `@zhin.js/core` — `Endpoint.emit(...)` 入站、`outboundMessageToken` 出站
|
|
24
24
|
- `zhin.js` — `plugin.ts`(`definePlugin`)
|
|
25
25
|
- 配置经插件 `schema.json` 落到 `plugins.<instanceKey>`
|
|
@@ -42,7 +42,7 @@ pnpm add @zhin.js/adapter-discord discord.js
|
|
|
42
42
|
| **Gateway(默认)** | 本地/生产均可;discord.js 连接 Gateway,无需公网 HTTPS |
|
|
43
43
|
| **host-http** | Gateway **不需要**;Interactions webhook 延期至下一棒 |
|
|
44
44
|
|
|
45
|
-
必填字段(`endpoints[i]`):`
|
|
45
|
+
必填字段(`endpoints[i]`):`id`、`token`。
|
|
46
46
|
|
|
47
47
|
## 最小配置
|
|
48
48
|
|
|
@@ -52,7 +52,7 @@ plugins:
|
|
|
52
52
|
discord:
|
|
53
53
|
# connection: gateway # 默认
|
|
54
54
|
endpoints:
|
|
55
|
-
-
|
|
55
|
+
- id: my-discord-bot
|
|
56
56
|
token: ${DISCORD_BOT_TOKEN}
|
|
57
57
|
```
|
|
58
58
|
|
|
@@ -62,8 +62,7 @@ plugins:
|
|
|
62
62
|
|
|
63
63
|
| 变量 | 说明 |
|
|
64
64
|
|------|------|
|
|
65
|
-
| `DISCORD_BOT_TOKEN` | Bot Token |
|
|
66
|
-
| `DISCORD_BOT_NAME` | 可选,默认 endpoint 名 |
|
|
65
|
+
| `DISCORD_BOT_TOKEN` | YAML 示例中 `token` 引用的 Bot Token |
|
|
67
66
|
|
|
68
67
|
## Interactions(HTTP)
|
|
69
68
|
|
|
@@ -73,9 +72,9 @@ plugins:
|
|
|
73
72
|
|
|
74
73
|
| 类别 | 路径 |
|
|
75
74
|
|------|------|
|
|
76
|
-
| Permit 词汇 | `
|
|
77
|
-
| 平台工具(7 个) | `
|
|
78
|
-
| 技能说明 | `
|
|
75
|
+
| Permit 词汇 | `PERMITS.md` |
|
|
76
|
+
| 平台工具(7 个) | `agents/discord/skills/discord/tools/`(Skill 激活后披露 `discord_*`:角色、Embed、反应等) |
|
|
77
|
+
| 技能说明 | `agents/discord/skills/discord/SKILL.md` |
|
|
79
78
|
|
|
80
79
|
工具使用 Discord Snowflake ID 标识 `guild_id`、`user_id`、`channel_id`。
|
|
81
80
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
2
|
/**
|
|
3
|
-
* Convention entry: discover `adapters/discord.ts` → defineAdapter.
|
|
3
|
+
* Convention entry: discover `adapters/discord/index.ts` → defineAdapter.
|
|
4
4
|
*/
|
|
5
5
|
import { defineAdapter } from 'zhin.js/adapter';
|
|
6
6
|
import { httpHostToken } from '@zhin.js/host-http';
|
|
7
|
-
import { DiscordGatewayEndpoint, DiscordInteractionsEndpoint, } from "
|
|
8
|
-
import { resolveDiscordConfig, } from "
|
|
9
|
-
import { discordRuntimeStateToken } from "
|
|
10
|
-
export { DiscordGatewayEndpoint, DiscordInteractionsEndpoint, } from "
|
|
7
|
+
import { DiscordGatewayEndpoint, DiscordInteractionsEndpoint, } from "../../lib/endpoint.js";
|
|
8
|
+
import { resolveDiscordConfig, } from "../../lib/protocol.js";
|
|
9
|
+
import { discordRuntimeStateToken } from "../../lib/discord-runtime-state.js";
|
|
10
|
+
export { DiscordGatewayEndpoint, DiscordInteractionsEndpoint, } from "../../lib/endpoint.js";
|
|
11
11
|
export default defineAdapter({
|
|
12
12
|
capabilities: ['inbound', 'outbound'],
|
|
13
13
|
operations: (context) => context.config.connection === 'interactions'
|
|
@@ -21,7 +21,7 @@ export default defineAdapter({
|
|
|
21
21
|
},
|
|
22
22
|
create(context) {
|
|
23
23
|
const config = resolveDiscordConfig(context.config);
|
|
24
|
-
// 注册到插件运行时状态(discord
|
|
24
|
+
// 注册到插件运行时状态(discord endpoint list 的"运行中"数据源)
|
|
25
25
|
context.use(discordRuntimeStateToken).endpoints.set(config.id, {
|
|
26
26
|
id: config.id,
|
|
27
27
|
mode: config.connection,
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Convention entry: discover `adapters/discord.ts` → defineAdapter.
|
|
2
|
+
* Convention entry: discover `adapters/discord/index.ts` → defineAdapter.
|
|
3
3
|
*/
|
|
4
4
|
import { defineAdapter } from 'zhin.js/adapter';
|
|
5
5
|
import { httpHostToken } from '@zhin.js/host-http';
|
|
6
6
|
import {
|
|
7
7
|
DiscordGatewayEndpoint,
|
|
8
8
|
DiscordInteractionsEndpoint,
|
|
9
|
-
} from '
|
|
9
|
+
} from '../../src/endpoint.js';
|
|
10
10
|
import {
|
|
11
11
|
resolveDiscordConfig,
|
|
12
|
-
type
|
|
13
|
-
} from '
|
|
14
|
-
import { discordRuntimeStateToken } from '
|
|
12
|
+
type DiscordEndpointConfig,
|
|
13
|
+
} from '../../src/protocol.js';
|
|
14
|
+
import { discordRuntimeStateToken } from '../../src/discord-runtime-state.js';
|
|
15
15
|
|
|
16
16
|
export {
|
|
17
17
|
DiscordGatewayEndpoint,
|
|
18
18
|
DiscordInteractionsEndpoint,
|
|
19
|
-
} from '
|
|
19
|
+
} from '../../src/endpoint.js';
|
|
20
20
|
export type {
|
|
21
21
|
CreateDiscordClient,
|
|
22
22
|
DiscordClientTransport,
|
|
23
23
|
DiscordEndpointOptions,
|
|
24
24
|
DiscordInteractionsEndpointOptions,
|
|
25
|
-
} from '
|
|
25
|
+
} from '../../src/endpoint.js';
|
|
26
26
|
|
|
27
|
-
export default defineAdapter<
|
|
27
|
+
export default defineAdapter<DiscordEndpointConfig>({
|
|
28
28
|
capabilities: ['inbound', 'outbound'],
|
|
29
29
|
operations: (context) => context.config.connection === 'interactions'
|
|
30
30
|
? ['recall']
|
|
@@ -37,7 +37,7 @@ export default defineAdapter<DiscordAdapterConfig>({
|
|
|
37
37
|
},
|
|
38
38
|
create(context) {
|
|
39
39
|
const config = resolveDiscordConfig(context.config);
|
|
40
|
-
// 注册到插件运行时状态(discord
|
|
40
|
+
// 注册到插件运行时状态(discord endpoint list 的"运行中"数据源)
|
|
41
41
|
context.use(discordRuntimeStateToken).endpoints.set(config.id, {
|
|
42
42
|
id: config.id,
|
|
43
43
|
mode: config.connection,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "DISCORD Platform Agent",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Handles discord platform-specific operations and progressively loads only the required platform Skill.",
|
|
5
|
+
"trigger_rules": {
|
|
6
|
+
"file_patterns": [],
|
|
7
|
+
"keywords": [
|
|
8
|
+
"discord",
|
|
9
|
+
"adapter:discord"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"entry_points": [
|
|
13
|
+
"system.md",
|
|
14
|
+
"boundaries.md",
|
|
15
|
+
"conventions.md"
|
|
16
|
+
],
|
|
17
|
+
"platforms": [
|
|
18
|
+
"discord"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: discord
|
|
3
|
+
platforms: [discord]
|
|
4
|
+
description: Discord 角色、线程、论坛帖子、反应和 Embed 操作能力。
|
|
5
|
+
keywords: [discord, role, thread, forum, reaction, embed]
|
|
6
|
+
tags: [adapter, community]
|
|
7
|
+
tools:
|
|
8
|
+
- add_role
|
|
9
|
+
- remove_role
|
|
10
|
+
- list_roles
|
|
11
|
+
- create_thread
|
|
12
|
+
- react
|
|
13
|
+
- send_embed
|
|
14
|
+
- forum_post
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Discord
|
|
18
|
+
|
|
19
|
+
按“先查询、后修改”执行:授予或移除角色前先用 `list_roles` 找到角色 ID;创建线程或论坛帖子时使用当前频道上下文;发送结构化内容时使用 `send_embed`;表情回应使用 `react`。
|
|
20
|
+
|
|
21
|
+
当前 Agent Tool 不提供踢人、封禁、禁言、改昵称或成员列表操作,不要声称已经执行这些动作。
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
5
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
6
|
+
export default defineAgentTool({
|
|
7
|
+
description: '给成员添加 Discord 角色',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
guild_id: z.string().describe('服务器 ID'),
|
|
10
|
+
user_id: z.string().describe('用户 ID'),
|
|
11
|
+
role_id: z.string().describe('角色 ID'),
|
|
12
|
+
}),
|
|
13
|
+
adapter: 'discord',
|
|
14
|
+
tags: ['discord'],
|
|
15
|
+
permissions: [platformPermission('discord', 'manage_roles')],
|
|
16
|
+
async execute({ guild_id, user_id, role_id }, context) {
|
|
17
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
18
|
+
const guild = await client.guilds.fetch(guild_id);
|
|
19
|
+
const member = await guild.members.fetch(user_id);
|
|
20
|
+
await member.roles.add(role_id);
|
|
21
|
+
const success = true;
|
|
22
|
+
return { success, message: success ? `已给用户 ${user_id} 添加角色` : '操作失败' };
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineAgentTool } from '@zhin.js/
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { requireDiscordGatewayClient } from '
|
|
4
|
-
import {
|
|
3
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
4
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
5
5
|
|
|
6
6
|
export default defineAgentTool<{ guild_id: string; user_id: string; role_id: string }>({
|
|
7
7
|
description: '给成员添加 Discord 角色',
|
|
@@ -12,7 +12,7 @@ export default defineAgentTool<{ guild_id: string; user_id: string; role_id: str
|
|
|
12
12
|
}),
|
|
13
13
|
adapter: 'discord',
|
|
14
14
|
tags: ['discord'],
|
|
15
|
-
permissions: [
|
|
15
|
+
permissions: [platformPermission('discord', 'manage_roles')],
|
|
16
16
|
async execute({ guild_id, user_id, role_id }: { guild_id: string; user_id: string; role_id: string }, context) {
|
|
17
17
|
const client = requireDiscordGatewayClient(context.$client);
|
|
18
18
|
const guild = await client.guilds.fetch(guild_id);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
5
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
6
|
+
export default defineAgentTool({
|
|
7
|
+
description: '在 Discord 频道中创建帖子/子线程',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
channel_id: z.string().describe('频道 ID'),
|
|
10
|
+
name: z.string().describe('帖子标题'),
|
|
11
|
+
message_id: z.string().optional().describe('基于某条消息创建(可选)'),
|
|
12
|
+
auto_archive_duration: z.number().optional().describe('自动归档时间(分钟:60/1440/4320/10080)'),
|
|
13
|
+
}),
|
|
14
|
+
adapter: 'discord',
|
|
15
|
+
tags: ['discord'],
|
|
16
|
+
permissions: [platformPermission('discord', 'manage_channels')],
|
|
17
|
+
async execute({ channel_id, name, message_id, auto_archive_duration }, context) {
|
|
18
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
19
|
+
const channel = await client.channels.fetch(channel_id);
|
|
20
|
+
if (!channel?.threads)
|
|
21
|
+
throw new Error(`Channel ${channel_id} 不支持创建帖子`);
|
|
22
|
+
const thread = await channel.threads.create({
|
|
23
|
+
name,
|
|
24
|
+
autoArchiveDuration: auto_archive_duration || 1440,
|
|
25
|
+
...(message_id ? { startMessage: message_id } : {}),
|
|
26
|
+
});
|
|
27
|
+
return { success: true, thread_id: thread.id, message: `帖子 "${name}" 已创建` };
|
|
28
|
+
},
|
|
29
|
+
});
|
package/{agent/tools/create_thread.ts → agents/discord/skills/discord/tools/create_thread/index.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineAgentTool } from '@zhin.js/
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { requireDiscordGatewayClient } from '
|
|
4
|
-
import {
|
|
3
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
4
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
5
5
|
|
|
6
6
|
export default defineAgentTool<{ channel_id: string; name: string; message_id?: string; auto_archive_duration?: number }>({
|
|
7
7
|
description: '在 Discord 频道中创建帖子/子线程',
|
|
@@ -13,7 +13,7 @@ export default defineAgentTool<{ channel_id: string; name: string; message_id?:
|
|
|
13
13
|
}),
|
|
14
14
|
adapter: 'discord',
|
|
15
15
|
tags: ['discord'],
|
|
16
|
-
permissions: [
|
|
16
|
+
permissions: [platformPermission('discord', 'manage_channels')],
|
|
17
17
|
async execute({ channel_id, name, message_id, auto_archive_duration }: { channel_id: string; name: string; message_id?: string; auto_archive_duration?: number }, context) {
|
|
18
18
|
const client = requireDiscordGatewayClient(context.$client);
|
|
19
19
|
const channel = await client.channels.fetch(channel_id);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
5
|
+
import { ChannelType } from 'discord.js';
|
|
6
|
+
export default defineAgentTool({
|
|
7
|
+
description: '在 Discord 论坛频道中创建帖子',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
channel_id: z.string().describe('论坛频道 ID'),
|
|
10
|
+
name: z.string().describe('帖子标题'),
|
|
11
|
+
content: z.string().describe('帖子内容'),
|
|
12
|
+
tags: z.string().optional().describe('标签名,逗号分隔(可选)'),
|
|
13
|
+
}),
|
|
14
|
+
adapter: 'discord',
|
|
15
|
+
tags: ['discord'],
|
|
16
|
+
async execute({ channel_id, name, content, tags }, context) {
|
|
17
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
18
|
+
const tagList = tags ? tags.split(',').map((t) => t.trim()) : undefined;
|
|
19
|
+
const channel = await client.channels.fetch(channel_id);
|
|
20
|
+
if (!channel?.threads || channel.type !== ChannelType.GuildForum) {
|
|
21
|
+
throw new Error(`Channel ${channel_id} 不是论坛频道`);
|
|
22
|
+
}
|
|
23
|
+
const tagIds = tagList?.length
|
|
24
|
+
? channel.availableTags?.filter((tag) => tagList.includes(tag.name)).map((tag) => tag.id)
|
|
25
|
+
: undefined;
|
|
26
|
+
const thread = await channel.threads.create({
|
|
27
|
+
name,
|
|
28
|
+
message: { content },
|
|
29
|
+
...(tagIds?.length ? { appliedTags: tagIds } : {}),
|
|
30
|
+
});
|
|
31
|
+
return { success: true, thread_id: thread.id, message: `论坛帖 "${name}" 已创建` };
|
|
32
|
+
},
|
|
33
|
+
});
|
package/{agent/tools/forum_post.ts → agents/discord/skills/discord/tools/forum_post/index.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineAgentTool } from '@zhin.js/
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { requireDiscordGatewayClient } from '
|
|
3
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
4
4
|
import { ChannelType } from 'discord.js';
|
|
5
5
|
|
|
6
6
|
export default defineAgentTool<{ channel_id: string; name: string; content: string; tags?: string }>({
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
5
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
6
|
+
export default defineAgentTool({
|
|
7
|
+
description: '获取 Discord 服务器角色列表',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
guild_id: z.string().describe('服务器 ID'),
|
|
10
|
+
}),
|
|
11
|
+
adapter: 'discord',
|
|
12
|
+
tags: ['discord'],
|
|
13
|
+
permissions: [platformPermission('discord', 'manage_roles')],
|
|
14
|
+
async execute({ guild_id }, context) {
|
|
15
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
16
|
+
const guild = await client.guilds.fetch(guild_id);
|
|
17
|
+
await guild.roles.fetch();
|
|
18
|
+
const cache = guild.roles.cache;
|
|
19
|
+
const roles = [...cache.values()].map((role) => ({
|
|
20
|
+
id: role.id,
|
|
21
|
+
name: role.name,
|
|
22
|
+
color: role.hexColor,
|
|
23
|
+
position: role.position,
|
|
24
|
+
permissions: role.permissions.bitfield.toString(),
|
|
25
|
+
}));
|
|
26
|
+
return { roles, count: roles.length };
|
|
27
|
+
},
|
|
28
|
+
});
|
package/{agent/tools/list_roles.ts → agents/discord/skills/discord/tools/list_roles/index.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineAgentTool } from '@zhin.js/
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { requireDiscordGatewayClient } from '
|
|
4
|
-
import {
|
|
3
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
4
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
5
5
|
|
|
6
6
|
export default defineAgentTool<{ guild_id: string }>({
|
|
7
7
|
description: '获取 Discord 服务器角色列表',
|
|
@@ -10,7 +10,7 @@ export default defineAgentTool<{ guild_id: string }>({
|
|
|
10
10
|
}),
|
|
11
11
|
adapter: 'discord',
|
|
12
12
|
tags: ['discord'],
|
|
13
|
-
permissions: [
|
|
13
|
+
permissions: [platformPermission('discord', 'manage_roles')],
|
|
14
14
|
async execute({ guild_id }: { guild_id: string }, context) {
|
|
15
15
|
const client = requireDiscordGatewayClient(context.$client);
|
|
16
16
|
const guild = await client.guilds.fetch(guild_id);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
5
|
+
export default defineAgentTool({
|
|
6
|
+
description: '对 Discord 消息添加表情反应',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
channel_id: z.string().describe('频道 ID'),
|
|
9
|
+
message_id: z.string().describe('消息 ID'),
|
|
10
|
+
emoji: z.string().describe('表情(Unicode 表情或自定义表情如 <:name:id>)'),
|
|
11
|
+
}),
|
|
12
|
+
adapter: 'discord',
|
|
13
|
+
tags: ['discord'],
|
|
14
|
+
async execute({ channel_id, message_id, emoji }, context) {
|
|
15
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
16
|
+
const channel = await client.channels.fetch(channel_id);
|
|
17
|
+
if (!channel?.isTextBased() || !channel.messages) {
|
|
18
|
+
throw new Error(`Channel ${channel_id} 不是文本频道`);
|
|
19
|
+
}
|
|
20
|
+
const message = await channel.messages.fetch(message_id);
|
|
21
|
+
await message.react(emoji);
|
|
22
|
+
return { success: true, message: `已添加反应 ${emoji}` };
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineAgentTool } from '@zhin.js/
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { requireDiscordGatewayClient } from '
|
|
3
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
4
4
|
|
|
5
5
|
export default defineAgentTool<{ channel_id: string; message_id: string; emoji: string }>({
|
|
6
6
|
description: '对 Discord 消息添加表情反应',
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
5
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
6
|
+
export default defineAgentTool({
|
|
7
|
+
description: '移除成员的 Discord 角色',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
guild_id: z.string().describe('服务器 ID'),
|
|
10
|
+
user_id: z.string().describe('用户 ID'),
|
|
11
|
+
role_id: z.string().describe('角色 ID'),
|
|
12
|
+
}),
|
|
13
|
+
adapter: 'discord',
|
|
14
|
+
tags: ['discord'],
|
|
15
|
+
permissions: [platformPermission('discord', 'manage_roles')],
|
|
16
|
+
async execute({ guild_id, user_id, role_id }, context) {
|
|
17
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
18
|
+
const guild = await client.guilds.fetch(guild_id);
|
|
19
|
+
const member = await guild.members.fetch(user_id);
|
|
20
|
+
await member.roles.remove(role_id);
|
|
21
|
+
const success = true;
|
|
22
|
+
return { success, message: success ? `已移除用户 ${user_id} 的角色` : '操作失败' };
|
|
23
|
+
},
|
|
24
|
+
});
|
package/{agent/tools/remove_role.ts → agents/discord/skills/discord/tools/remove_role/index.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineAgentTool } from '@zhin.js/
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { requireDiscordGatewayClient } from '
|
|
4
|
-
import {
|
|
3
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
4
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
5
5
|
|
|
6
6
|
export default defineAgentTool<{ guild_id: string; user_id: string; role_id: string }>({
|
|
7
7
|
description: '移除成员的 Discord 角色',
|
|
@@ -12,7 +12,7 @@ export default defineAgentTool<{ guild_id: string; user_id: string; role_id: str
|
|
|
12
12
|
}),
|
|
13
13
|
adapter: 'discord',
|
|
14
14
|
tags: ['discord'],
|
|
15
|
-
permissions: [
|
|
15
|
+
permissions: [platformPermission('discord', 'manage_roles')],
|
|
16
16
|
async execute({ guild_id, user_id, role_id }: { guild_id: string; user_id: string; role_id: string }, context) {
|
|
17
17
|
const client = requireDiscordGatewayClient(context.$client);
|
|
18
18
|
const guild = await client.guilds.fetch(guild_id);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
5
|
+
export default defineAgentTool({
|
|
6
|
+
description: '发送 Discord 富文本嵌入消息(Embed)',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
channel_id: z.string().describe('频道 ID'),
|
|
9
|
+
title: z.string().optional().describe('Embed 标题'),
|
|
10
|
+
description: z.string().optional().describe('Embed 描述'),
|
|
11
|
+
color: z.number().optional().describe('颜色值(十进制,如 0x00ff00 = 65280)'),
|
|
12
|
+
url: z.string().optional().describe('标题链接(可选)'),
|
|
13
|
+
fields: z.string().optional().describe('字段,JSON 格式: [{"name":"k","value":"v","inline":false}]'),
|
|
14
|
+
}),
|
|
15
|
+
adapter: 'discord',
|
|
16
|
+
tags: ['discord'],
|
|
17
|
+
async execute({ channel_id, title, description, color, url, fields }, context) {
|
|
18
|
+
const client = requireDiscordGatewayClient(context.$client);
|
|
19
|
+
const embedData = {};
|
|
20
|
+
if (title)
|
|
21
|
+
embedData.title = title;
|
|
22
|
+
if (description)
|
|
23
|
+
embedData.description = description;
|
|
24
|
+
if (color)
|
|
25
|
+
embedData.color = color;
|
|
26
|
+
if (url)
|
|
27
|
+
embedData.url = url;
|
|
28
|
+
if (fields) {
|
|
29
|
+
try {
|
|
30
|
+
embedData.fields = JSON.parse(fields);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return { success: false, message: 'fields 格式错误,应为 JSON 数组' };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const channel = await client.channels.fetch(channel_id);
|
|
37
|
+
if (!channel?.isTextBased() || !channel.send) {
|
|
38
|
+
throw new Error(`Channel ${channel_id} 不是文本频道`);
|
|
39
|
+
}
|
|
40
|
+
const msg = await channel.send({ embeds: [embedData] });
|
|
41
|
+
return { success: true, message_id: msg.id, message: 'Embed 已发送' };
|
|
42
|
+
},
|
|
43
|
+
});
|
package/{agent/tools/send_embed.ts → agents/discord/skills/discord/tools/send_embed/index.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineAgentTool } from '@zhin.js/
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { requireDiscordGatewayClient } from '
|
|
3
|
+
import { requireDiscordGatewayClient } from '@zhin.js/adapter-discord';
|
|
4
4
|
|
|
5
5
|
export default defineAgentTool<{ channel_id: string; title?: string; description?: string; color?: number; url?: string; fields?: string }>({
|
|
6
6
|
description: '发送 Discord 富文本嵌入消息(Embed)',
|