@zhin.js/adapter-discord 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.
Files changed (68) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +51 -76
  3. package/adapters/discord.ts +46 -0
  4. package/agent/tools/add_role.ts +24 -0
  5. package/agent/tools/create_thread.ts +25 -0
  6. package/agent/tools/forum_post.ts +24 -0
  7. package/agent/tools/list_roles.ts +22 -0
  8. package/agent/tools/react.ts +22 -0
  9. package/agent/tools/remove_role.ts +24 -0
  10. package/agent/tools/send_embed.ts +37 -0
  11. package/lib/discord-agent-deps.d.ts +35 -0
  12. package/lib/discord-agent-deps.js +32 -0
  13. package/lib/endpoint.d.ts +66 -119
  14. package/lib/endpoint.js +308 -1047
  15. package/lib/gateway.d.ts +122 -0
  16. package/lib/gateway.js +235 -0
  17. package/lib/index.d.ts +6 -18
  18. package/lib/index.js +6 -330
  19. package/lib/platform-permit.d.ts +1 -2
  20. package/lib/platform-permit.js +4 -2
  21. package/lib/protocol.d.ts +135 -0
  22. package/lib/protocol.js +234 -0
  23. package/lib/webhook.d.ts +13 -0
  24. package/lib/webhook.js +86 -0
  25. package/package.json +48 -31
  26. package/plugin.ts +13 -0
  27. package/schema.json +63 -0
  28. package/src/discord-agent-deps.ts +79 -0
  29. package/src/endpoint.ts +385 -1167
  30. package/src/gateway.ts +337 -0
  31. package/src/index.ts +55 -332
  32. package/src/platform-permit.ts +1 -2
  33. package/src/protocol.ts +392 -0
  34. package/src/webhook.ts +121 -0
  35. package/client/Dashboard.tsx +0 -195
  36. package/client/index.tsx +0 -11
  37. package/client/tsconfig.json +0 -7
  38. package/client/utils/api.ts +0 -30
  39. package/dist/index.js +0 -29
  40. package/lib/adapter.d.ts +0 -25
  41. package/lib/adapter.d.ts.map +0 -1
  42. package/lib/adapter.js +0 -96
  43. package/lib/adapter.js.map +0 -1
  44. package/lib/endpoint-interactions.d.ts +0 -34
  45. package/lib/endpoint-interactions.d.ts.map +0 -1
  46. package/lib/endpoint-interactions.js +0 -284
  47. package/lib/endpoint-interactions.js.map +0 -1
  48. package/lib/endpoint.d.ts.map +0 -1
  49. package/lib/endpoint.js.map +0 -1
  50. package/lib/index.d.ts.map +0 -1
  51. package/lib/index.js.map +0 -1
  52. package/lib/platform-permit.d.ts.map +0 -1
  53. package/lib/platform-permit.js.map +0 -1
  54. package/lib/segment-mapper.d.ts +0 -2
  55. package/lib/segment-mapper.d.ts.map +0 -1
  56. package/lib/segment-mapper.js +0 -2
  57. package/lib/segment-mapper.js.map +0 -1
  58. package/lib/types.d.ts +0 -49
  59. package/lib/types.d.ts.map +0 -1
  60. package/lib/types.js +0 -2
  61. package/lib/types.js.map +0 -1
  62. package/plugin.yml +0 -3
  63. package/src/adapter.ts +0 -108
  64. package/src/endpoint-interactions.ts +0 -354
  65. package/src/segment-mapper.ts +0 -1
  66. package/src/types.ts +0 -60
  67. /package/{skills/discord → agent}/PERMITS.md +0 -0
  68. /package/{skills/discord/SKILL.md → agent/skills/discord.md} +0 -0
package/lib/endpoint.d.ts CHANGED
@@ -1,124 +1,71 @@
1
- /**
2
- * Discord Endpoint 实现 (Gateway)
3
- */
4
- import { Client, Message as DiscordMessage, TextChannel, DMChannel, NewsChannel, ThreadChannel, EmbedBuilder, AttachmentBuilder, MessageCreateOptions, ChatInputCommandInteraction } from 'discord.js';
5
- import { Endpoint, Message, SendOptions, SendContent, MessageSegment, type EditMessageOptions } from 'zhin.js';
6
- import type { DiscordGatewayConfig, DiscordChannelMessage } from "./types.js";
7
- import type { DiscordAdapter } from "./adapter.js";
8
- export declare class DiscordEndpoint extends Client implements Endpoint<DiscordGatewayConfig, DiscordChannelMessage> {
9
- adapter: DiscordAdapter;
10
- $config: DiscordGatewayConfig;
11
- private slashCommandHandlers;
12
- /** message_id -> channel_id,用于在仅有 message_id 的场景执行 reaction 操作 */
13
- private readonly messageChannelMap;
14
- $connected: boolean;
15
- get pluginLogger(): import("zhin.js").Logger;
16
- get $id(): string;
17
- constructor(adapter: DiscordAdapter, $config: DiscordGatewayConfig);
18
- private handleDiscordMessage;
19
- private handleSlashCommand;
20
- private handleButtonInteraction;
21
- $connect(): Promise<void>;
22
- $disconnect(): Promise<void>;
23
- $formatMessage(msg: DiscordChannelMessage): Message<DiscordChannelMessage>;
24
- parseMessageContent(msg: DiscordChannelMessage): MessageSegment[];
25
- parseTextContent(content: string, msg: DiscordChannelMessage): MessageSegment[];
26
- parseAttachment(attachment: any): MessageSegment[];
27
- $sendMessage(options: SendOptions): Promise<string>;
28
- sendContentToChannel(channel: TextChannel | DMChannel | NewsChannel | ThreadChannel, content: SendContent, extraOptions?: MessageCreateOptions): Promise<DiscordMessage<boolean>>;
29
- $editMessage(options: EditMessageOptions): Promise<void>;
30
- $recallMessage(id: string): Promise<void>;
31
- /**
32
- * 踢出成员
33
- * @param guildId 服务器 ID
34
- * @param userId 用户 ID
35
- * @param reason 原因
36
- */
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 CreateDiscordClient } from './gateway.js';
6
+ import { type DiscordButtonInbound, type DiscordInboundMessage, type ResolvedDiscordGatewayConfig, type ResolvedDiscordInteractionsConfig } from './protocol.js';
7
+ export type { CreateDiscordClient, DiscordClientTransport, } from './gateway.js';
8
+ export interface DiscordEndpointOptions {
9
+ readonly id: CapabilityId;
10
+ readonly gateway: MessageGateway;
11
+ readonly config: ResolvedDiscordGatewayConfig;
12
+ readonly createClient?: CreateDiscordClient;
13
+ }
14
+ export declare class DiscordGatewayEndpoint implements EndpointInstance {
15
+ #private;
16
+ constructor(options: DiscordEndpointOptions);
17
+ start(): Promise<void>;
18
+ open(): void;
19
+ close(): void;
20
+ stop(): Promise<void>;
21
+ send({ target, payload }: {
22
+ readonly target: string;
23
+ readonly payload: unknown;
24
+ }): Promise<string>;
25
+ /** Test / internal: admit a message when open. */
26
+ admit(msg: DiscordInboundMessage): void;
27
+ /** Test / internal: admit a button interaction when open. */
28
+ admitButton(interaction: DiscordButtonInbound): void;
29
+ addRole(guildId: string, userId: string, roleId: string): Promise<boolean>;
30
+ removeRole(guildId: string, userId: string, roleId: string): Promise<boolean>;
31
+ getRoles(guildId: string): Promise<unknown[]>;
32
+ createThread(channelId: string, name: string, messageId?: string, autoArchiveDuration?: number): Promise<{
33
+ id: string;
34
+ }>;
35
+ addReaction(channelId: string, messageId: string, emoji: string): Promise<void>;
36
+ sendEmbed(channelId: string, embedData: Record<string, unknown>): Promise<{
37
+ id: string;
38
+ }>;
39
+ createForumPost(channelId: string, name: string, content: string, tags?: string[]): Promise<{
40
+ id: string;
41
+ }>;
37
42
  kickMember(guildId: string, userId: string, reason?: string): Promise<boolean>;
38
- /**
39
- * 封禁成员
40
- * @param guildId 服务器 ID
41
- * @param userId 用户 ID
42
- * @param reason 原因
43
- * @param deleteMessageDays 删除消息天数
44
- */
45
- banMember(guildId: string, userId: string, reason?: string, deleteMessageDays?: number): Promise<boolean>;
46
- /**
47
- * 解除封禁
48
- * @param guildId 服务器 ID
49
- * @param userId 用户 ID
50
- * @param reason 原因
51
- */
43
+ banMember(guildId: string, userId: string, reason?: string): Promise<boolean>;
52
44
  unbanMember(guildId: string, userId: string, reason?: string): Promise<boolean>;
53
- /**
54
- * 超时(禁言)成员
55
- * @param guildId 服务器 ID
56
- * @param userId 用户 ID
57
- * @param duration 超时时长(秒),0 表示取消超时
58
- * @param reason 原因
59
- */
60
45
  timeoutMember(guildId: string, userId: string, duration?: number, reason?: string): Promise<boolean>;
61
- /**
62
- * 修改成员昵称
63
- * @param guildId 服务器 ID
64
- * @param userId 用户 ID
65
- * @param nickname 新昵称
66
- */
67
46
  setNickname(guildId: string, userId: string, nickname: string): Promise<boolean>;
68
- /**
69
- * 添加角色
70
- * @param guildId 服务器 ID
71
- * @param userId 用户 ID
72
- * @param roleId 角色 ID
73
- */
74
- addRole(guildId: string, userId: string, roleId: string): Promise<boolean>;
75
- /**
76
- * 移除角色
77
- * @param guildId 服务器 ID
78
- * @param userId 用户 ID
79
- * @param roleId 角色 ID
80
- */
81
- removeRole(guildId: string, userId: string, roleId: string): Promise<boolean>;
82
- /**
83
- * 获取服务器角色列表
84
- * @param guildId 服务器 ID
85
- */
86
- getRoles(guildId: string): Promise<any[]>;
87
- /**
88
- * 获取成员列表
89
- * @param guildId 服务器 ID
90
- * @param limit 数量限制
91
- */
92
- getMembers(guildId: string, limit?: number): Promise<any[]>;
93
- /**
94
- * 获取服务器信息
95
- * @param guildId 服务器 ID
96
- */
97
- getGuildInfo(guildId: string): Promise<any>;
98
- createThread(channelId: string, name: string, messageId?: string, autoArchiveDuration?: number): Promise<ThreadChannel>;
99
- addReaction(channelId: string, messageId: string, emoji: string): Promise<void>;
100
- private resolveDiscordMessageRef;
101
- $addReaction(messageId: string, emoji: string): Promise<string | null>;
102
- $removeReaction(messageId: string, reactionId: string): Promise<void>;
103
- sendEmbed(channelId: string, embedData: {
104
- title?: string;
105
- description?: string;
106
- color?: number;
107
- url?: string;
108
- fields?: {
109
- name: string;
110
- value: string;
111
- inline?: boolean;
112
- }[];
113
- }): Promise<DiscordMessage<boolean>>;
114
- createForumPost(channelId: string, name: string, content: string, tags?: string[]): Promise<ThreadChannel>;
115
- handleFileSegment(data: any, files: AttachmentBuilder[], textContent: string): Promise<void>;
116
- createEmbedFromData(data: any): EmbedBuilder;
117
- private getActivityType;
118
- private registerSlashCommands;
119
- addSlashCommandHandler(commandName: string, handler: (interaction: ChatInputCommandInteraction) => Promise<void>): void;
120
- removeSlashCommandHandler(commandName: string): boolean;
121
- private fileExists;
122
- static formatContentToText(content: SendContent): string;
47
+ getMembers(guildId: string, limit?: number): Promise<unknown[]>;
48
+ getGuildInfo(guildId: string): Promise<unknown>;
49
+ }
50
+ export interface DiscordInteractionsEndpointOptions {
51
+ readonly id: CapabilityId;
52
+ readonly gateway: MessageGateway;
53
+ readonly http: HttpHost;
54
+ readonly config: ResolvedDiscordInteractionsConfig;
55
+ readonly fetch?: typeof globalThis.fetch;
56
+ }
57
+ export declare class DiscordInteractionsEndpoint implements EndpointInstance {
58
+ #private;
59
+ constructor(options: DiscordInteractionsEndpointOptions);
60
+ get isOpen(): boolean;
61
+ get config(): ResolvedDiscordInteractionsConfig;
62
+ start(): Promise<void>;
63
+ open(): void;
64
+ close(): void;
65
+ stop(): Promise<void>;
66
+ send({ target, payload }: {
67
+ readonly target: string;
68
+ readonly payload: unknown;
69
+ }): Promise<string>;
70
+ admit(msg: DiscordInboundMessage): void;
123
71
  }
124
- //# sourceMappingURL=endpoint.d.ts.map