@zhin.js/adapter-discord 7.0.8 → 7.0.10
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 +34 -0
- package/lib/endpoint.d.ts +3 -2
- package/lib/endpoint.js +17 -34
- package/package.json +15 -15
- package/src/endpoint.ts +18 -35
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @zhin.js/adapter-discord
|
|
2
2
|
|
|
3
|
+
## 7.0.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [e4757a8]
|
|
8
|
+
- Updated dependencies [c3c0ebf]
|
|
9
|
+
- @zhin.js/command@1.0.13
|
|
10
|
+
- @zhin.js/host-http@1.0.10
|
|
11
|
+
- @zhin.js/agent@1.1.10
|
|
12
|
+
- @zhin.js/core@1.5.9
|
|
13
|
+
- @zhin.js/adapter@1.1.9
|
|
14
|
+
- zhin.js@6.0.9
|
|
15
|
+
|
|
16
|
+
## 7.0.9
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [63253bb]
|
|
21
|
+
- Updated dependencies [6fb24dd]
|
|
22
|
+
- Updated dependencies [d162216]
|
|
23
|
+
- Updated dependencies [7427818]
|
|
24
|
+
- Updated dependencies [90da255]
|
|
25
|
+
- Updated dependencies [8e973dc]
|
|
26
|
+
- Updated dependencies [953cfe1]
|
|
27
|
+
- Updated dependencies [0e73866]
|
|
28
|
+
- @zhin.js/plugin-runtime@1.1.6
|
|
29
|
+
- @zhin.js/core@1.5.8
|
|
30
|
+
- @zhin.js/adapter@1.1.8
|
|
31
|
+
- @zhin.js/host-http@1.0.9
|
|
32
|
+
- @zhin.js/agent@1.1.9
|
|
33
|
+
- zhin.js@6.0.8
|
|
34
|
+
- @zhin.js/command@1.0.12
|
|
35
|
+
- @zhin.js/permission@1.0.2
|
|
36
|
+
|
|
3
37
|
## 7.0.8
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
package/lib/endpoint.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { EndpointControl, EndpointInstance, EndpointManagement, EndpointSendRequest } from '@zhin.js/adapter';
|
|
2
2
|
import type { MessageGateway } from '@zhin.js/core/runtime';
|
|
3
3
|
import type { HttpHost } from '@zhin.js/host-http';
|
|
4
|
+
import { type MessageRef } from '@zhin.js/im-contract';
|
|
4
5
|
import type { CapabilityId } from '@zhin.js/plugin-runtime';
|
|
5
6
|
import { type CreateDiscordClient, type DiscordClientTransport } from './gateway.js';
|
|
6
7
|
import { type DiscordButtonInbound, type DiscordInboundMessage, type ResolvedDiscordGatewayConfig, type ResolvedDiscordInteractionsConfig } from './protocol.js';
|
|
@@ -21,7 +22,7 @@ export declare class DiscordGatewayEndpoint implements EndpointInstance {
|
|
|
21
22
|
close(): void;
|
|
22
23
|
stop(): Promise<void>;
|
|
23
24
|
send({ conversation, payload }: EndpointSendRequest): Promise<string>;
|
|
24
|
-
recallMessage(
|
|
25
|
+
recallMessage(message: MessageRef): Promise<void>;
|
|
25
26
|
/** Test / internal: admit a message when open. */
|
|
26
27
|
admit(msg: DiscordInboundMessage): void;
|
|
27
28
|
/** Test / internal: admit a button interaction when open. */
|
|
@@ -65,7 +66,7 @@ export declare class DiscordInteractionsEndpoint implements EndpointInstance {
|
|
|
65
66
|
close(): void;
|
|
66
67
|
stop(): Promise<void>;
|
|
67
68
|
send({ conversation, payload }: EndpointSendRequest): Promise<string>;
|
|
68
|
-
recallMessage(
|
|
69
|
+
recallMessage(message: MessageRef): Promise<void>;
|
|
69
70
|
admit(msg: DiscordInboundMessage): void;
|
|
70
71
|
}
|
|
71
72
|
/**
|
package/lib/endpoint.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* DiscordEndpoint — lifecycle, outbound, admit, gateway / interactions modes, agent tool surface.
|
|
3
3
|
*/
|
|
4
4
|
import { ChannelType } from 'discord.js';
|
|
5
|
-
import { formatLegacyConversationRef, formatLegacyMessageRef, nativeConversationId, parseLegacyMessageReference, } from '@zhin.js/im-contract';
|
|
6
5
|
import { formatCompact, getAdapterLogger } from '@zhin.js/logger';
|
|
7
6
|
import { registerDiscordAgentEndpoint } from './discord-agent-deps.js';
|
|
8
7
|
import { connectDiscordGatewayClient, defaultCreateClient, DEFAULT_INTENTS, resolveSenderRole, toMessageCreateOptions, } from './gateway.js';
|
|
@@ -24,15 +23,12 @@ export class DiscordGatewayEndpoint {
|
|
|
24
23
|
getMembers: (guildId) => this.getMembers(guildId),
|
|
25
24
|
});
|
|
26
25
|
control = Object.freeze({
|
|
27
|
-
recall: (
|
|
28
|
-
addReaction: async (
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
?? (reference ? nativeConversationId(reference.target) : undefined);
|
|
32
|
-
const nativeMessageId = reference?.messageId ?? messageId;
|
|
33
|
-
if (!channelId || !nativeMessageId)
|
|
26
|
+
recall: (message) => this.recallMessage(message),
|
|
27
|
+
addReaction: async (message, emoji, hint) => {
|
|
28
|
+
const channelId = hint?.channelId ?? message.conversation.id;
|
|
29
|
+
if (!channelId || !message.id)
|
|
34
30
|
return null;
|
|
35
|
-
await this.addReaction(channelId,
|
|
31
|
+
await this.addReaction(channelId, message.id, emoji);
|
|
36
32
|
return emoji;
|
|
37
33
|
},
|
|
38
34
|
});
|
|
@@ -93,29 +89,22 @@ export class DiscordGatewayEndpoint {
|
|
|
93
89
|
}
|
|
94
90
|
async send({ conversation, payload }) {
|
|
95
91
|
const body = formatOutboundBody(payload);
|
|
96
|
-
// recall 链路仍是本端点编码的 legacy 引用,在边界内部从 conversation 派生
|
|
97
92
|
const snowflake = await this.#sendBody(conversation.id, body);
|
|
98
|
-
const messageId = formatLegacyMessageRef({ conversation, id: snowflake });
|
|
99
93
|
this.#logger.debug(formatCompact({
|
|
100
94
|
op: 'discord_send',
|
|
101
95
|
endpoint: this.#options.config.id,
|
|
102
|
-
target:
|
|
103
|
-
messageId,
|
|
96
|
+
target: conversation.id,
|
|
97
|
+
messageId: snowflake,
|
|
104
98
|
}));
|
|
105
|
-
return
|
|
99
|
+
return snowflake;
|
|
106
100
|
}
|
|
107
|
-
async recallMessage(
|
|
108
|
-
if (!
|
|
101
|
+
async recallMessage(message) {
|
|
102
|
+
if (!message.id)
|
|
109
103
|
return;
|
|
110
|
-
const
|
|
111
|
-
if (!reference)
|
|
112
|
-
return;
|
|
113
|
-
const channelId = nativeConversationId(reference.target);
|
|
114
|
-
const snowflake = reference.messageId;
|
|
115
|
-
const channel = await this.#requireClient().channels.fetch(channelId);
|
|
104
|
+
const channel = await this.#requireClient().channels.fetch(message.conversation.id);
|
|
116
105
|
if (!channel?.isTextBased() || !channel.messages)
|
|
117
106
|
return;
|
|
118
|
-
const msg = await channel.messages.fetch(
|
|
107
|
+
const msg = await channel.messages.fetch(message.id);
|
|
119
108
|
await msg.delete();
|
|
120
109
|
}
|
|
121
110
|
/** Test / internal: admit a message when open. */
|
|
@@ -318,7 +307,7 @@ export class DiscordInteractionsEndpoint {
|
|
|
318
307
|
#open = false;
|
|
319
308
|
#started = false;
|
|
320
309
|
control = Object.freeze({
|
|
321
|
-
recall: (
|
|
310
|
+
recall: (message) => this.recallMessage(message),
|
|
322
311
|
});
|
|
323
312
|
constructor(options) {
|
|
324
313
|
this.#logger = getAdapterLogger('discord', options.config.id);
|
|
@@ -374,18 +363,12 @@ export class DiscordInteractionsEndpoint {
|
|
|
374
363
|
}
|
|
375
364
|
const data = JSON.parse(text);
|
|
376
365
|
const snowflake = data.id ?? '';
|
|
377
|
-
|
|
378
|
-
return snowflake ? formatLegacyMessageRef({ conversation, id: snowflake }) : '';
|
|
366
|
+
return snowflake;
|
|
379
367
|
}
|
|
380
|
-
async recallMessage(
|
|
381
|
-
if (!
|
|
382
|
-
return;
|
|
383
|
-
const reference = parseLegacyMessageReference(messageId);
|
|
384
|
-
if (!reference)
|
|
368
|
+
async recallMessage(message) {
|
|
369
|
+
if (!message.id)
|
|
385
370
|
return;
|
|
386
|
-
const
|
|
387
|
-
const snowflake = reference.messageId;
|
|
388
|
-
const response = await this.#fetch(`${DISCORD_API}/channels/${channelId}/messages/${snowflake}`, {
|
|
371
|
+
const response = await this.#fetch(`${DISCORD_API}/channels/${message.conversation.id}/messages/${message.id}`, {
|
|
389
372
|
method: 'DELETE',
|
|
390
373
|
headers: { Authorization: `Bot ${this.#options.config.token}` },
|
|
391
374
|
signal: AbortSignal.timeout(OUTBOUND_TIMEOUT_MS),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-discord",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.10",
|
|
4
4
|
"description": "Zhin.js Discord adapter for Plugin Runtime (Gateway WebSocket)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -33,22 +33,22 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"discord.js": "^14.27.0",
|
|
36
|
-
"@zhin.js/adapter": "1.1.
|
|
37
|
-
"@zhin.js/command": "1.0.
|
|
38
|
-
"@zhin.js/core": "1.5.
|
|
39
|
-
"@zhin.js/host-http": "1.0.
|
|
36
|
+
"@zhin.js/adapter": "1.1.9",
|
|
37
|
+
"@zhin.js/command": "1.0.13",
|
|
38
|
+
"@zhin.js/core": "1.5.9",
|
|
39
|
+
"@zhin.js/host-http": "1.0.10",
|
|
40
40
|
"@zhin.js/im-contract": "1.0.3",
|
|
41
41
|
"@zhin.js/logger": "1.0.76",
|
|
42
|
-
"@zhin.js/permission": "1.0.
|
|
43
|
-
"@zhin.js/plugin-runtime": "1.1.
|
|
42
|
+
"@zhin.js/permission": "1.0.2",
|
|
43
|
+
"@zhin.js/plugin-runtime": "1.1.6"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"zod": "^4.0.0",
|
|
47
|
-
"@zhin.js/adapter": "1.1.
|
|
48
|
-
"@zhin.js/agent": "1.1.
|
|
49
|
-
"@zhin.js/core": "1.5.
|
|
50
|
-
"@zhin.js/plugin-runtime": "1.1.
|
|
51
|
-
"zhin.js": "6.0.
|
|
47
|
+
"@zhin.js/adapter": "1.1.9",
|
|
48
|
+
"@zhin.js/agent": "1.1.10",
|
|
49
|
+
"@zhin.js/core": "1.5.9",
|
|
50
|
+
"@zhin.js/plugin-runtime": "1.1.6",
|
|
51
|
+
"zhin.js": "6.0.9"
|
|
52
52
|
},
|
|
53
53
|
"peerDependenciesMeta": {
|
|
54
54
|
"zhin.js": {
|
|
@@ -66,9 +66,9 @@
|
|
|
66
66
|
"typescript": "^6.0.3",
|
|
67
67
|
"vitest": "^4.1.10",
|
|
68
68
|
"zod": "^4.4.3",
|
|
69
|
-
"@zhin.js/agent": "1.1.
|
|
70
|
-
"@zhin.js/host-http": "1.0.
|
|
71
|
-
"zhin.js": "6.0.
|
|
69
|
+
"@zhin.js/agent": "1.1.10",
|
|
70
|
+
"@zhin.js/host-http": "1.0.10",
|
|
71
|
+
"zhin.js": "6.0.9"
|
|
72
72
|
},
|
|
73
73
|
"files": [
|
|
74
74
|
"adapters",
|
package/src/endpoint.ts
CHANGED
|
@@ -13,10 +13,7 @@ import type {
|
|
|
13
13
|
import type { MessageGateway } from '@zhin.js/core/runtime';
|
|
14
14
|
import type { HttpHost, HttpRouteRegistration } from '@zhin.js/host-http';
|
|
15
15
|
import {
|
|
16
|
-
|
|
17
|
-
formatLegacyMessageRef,
|
|
18
|
-
nativeConversationId,
|
|
19
|
-
parseLegacyMessageReference,
|
|
16
|
+
type MessageRef,
|
|
20
17
|
} from '@zhin.js/im-contract';
|
|
21
18
|
import { formatCompact, getAdapterLogger } from '@zhin.js/logger';
|
|
22
19
|
import type { CapabilityId } from '@zhin.js/plugin-runtime';
|
|
@@ -75,18 +72,15 @@ export class DiscordGatewayEndpoint implements EndpointInstance {
|
|
|
75
72
|
getMembers: (guildId) => this.getMembers(guildId),
|
|
76
73
|
});
|
|
77
74
|
readonly control: EndpointControl = Object.freeze({
|
|
78
|
-
recall: (
|
|
75
|
+
recall: (message: MessageRef) => this.recallMessage(message),
|
|
79
76
|
addReaction: async (
|
|
80
|
-
|
|
77
|
+
message: MessageRef,
|
|
81
78
|
emoji: string,
|
|
82
79
|
hint?: { readonly sceneType?: string; readonly channelId?: string },
|
|
83
80
|
) => {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const nativeMessageId = reference?.messageId ?? messageId;
|
|
88
|
-
if (!channelId || !nativeMessageId) return null;
|
|
89
|
-
await this.addReaction(channelId, nativeMessageId, emoji);
|
|
81
|
+
const channelId = hint?.channelId ?? message.conversation.id;
|
|
82
|
+
if (!channelId || !message.id) return null;
|
|
83
|
+
await this.addReaction(channelId, message.id, emoji);
|
|
90
84
|
return emoji;
|
|
91
85
|
},
|
|
92
86
|
});
|
|
@@ -150,27 +144,21 @@ export class DiscordGatewayEndpoint implements EndpointInstance {
|
|
|
150
144
|
|
|
151
145
|
async send({ conversation, payload }: EndpointSendRequest): Promise<string> {
|
|
152
146
|
const body = formatOutboundBody(payload);
|
|
153
|
-
// recall 链路仍是本端点编码的 legacy 引用,在边界内部从 conversation 派生
|
|
154
147
|
const snowflake = await this.#sendBody(conversation.id, body);
|
|
155
|
-
const messageId = formatLegacyMessageRef({ conversation, id: snowflake });
|
|
156
148
|
this.#logger.debug(formatCompact({
|
|
157
149
|
op: 'discord_send',
|
|
158
150
|
endpoint: this.#options.config.id,
|
|
159
|
-
target:
|
|
160
|
-
messageId,
|
|
151
|
+
target: conversation.id,
|
|
152
|
+
messageId: snowflake,
|
|
161
153
|
}));
|
|
162
|
-
return
|
|
154
|
+
return snowflake;
|
|
163
155
|
}
|
|
164
156
|
|
|
165
|
-
async recallMessage(
|
|
166
|
-
if (!
|
|
167
|
-
const
|
|
168
|
-
if (!reference) return;
|
|
169
|
-
const channelId = nativeConversationId(reference.target);
|
|
170
|
-
const snowflake = reference.messageId;
|
|
171
|
-
const channel = await this.#requireClient().channels.fetch(channelId);
|
|
157
|
+
async recallMessage(message: MessageRef): Promise<void> {
|
|
158
|
+
if (!message.id) return;
|
|
159
|
+
const channel = await this.#requireClient().channels.fetch(message.conversation.id);
|
|
172
160
|
if (!channel?.isTextBased() || !channel.messages) return;
|
|
173
|
-
const msg = await channel.messages.fetch(
|
|
161
|
+
const msg = await channel.messages.fetch(message.id);
|
|
174
162
|
await msg.delete();
|
|
175
163
|
}
|
|
176
164
|
|
|
@@ -431,7 +419,7 @@ export class DiscordInteractionsEndpoint implements EndpointInstance {
|
|
|
431
419
|
#open = false;
|
|
432
420
|
#started = false;
|
|
433
421
|
readonly control: EndpointControl = Object.freeze({
|
|
434
|
-
recall: (
|
|
422
|
+
recall: (message: MessageRef) => this.recallMessage(message),
|
|
435
423
|
});
|
|
436
424
|
|
|
437
425
|
constructor(options: DiscordInteractionsEndpointOptions) {
|
|
@@ -493,17 +481,12 @@ export class DiscordInteractionsEndpoint implements EndpointInstance {
|
|
|
493
481
|
}
|
|
494
482
|
const data = JSON.parse(text) as { id?: string };
|
|
495
483
|
const snowflake = data.id ?? '';
|
|
496
|
-
|
|
497
|
-
return snowflake ? formatLegacyMessageRef({ conversation, id: snowflake }) : '';
|
|
484
|
+
return snowflake;
|
|
498
485
|
}
|
|
499
486
|
|
|
500
|
-
async recallMessage(
|
|
501
|
-
if (!
|
|
502
|
-
const
|
|
503
|
-
if (!reference) return;
|
|
504
|
-
const channelId = nativeConversationId(reference.target);
|
|
505
|
-
const snowflake = reference.messageId;
|
|
506
|
-
const response = await this.#fetch(`${DISCORD_API}/channels/${channelId}/messages/${snowflake}`, {
|
|
487
|
+
async recallMessage(message: MessageRef): Promise<void> {
|
|
488
|
+
if (!message.id) return;
|
|
489
|
+
const response = await this.#fetch(`${DISCORD_API}/channels/${message.conversation.id}/messages/${message.id}`, {
|
|
507
490
|
method: 'DELETE',
|
|
508
491
|
headers: { Authorization: `Bot ${this.#options.config.token}` },
|
|
509
492
|
signal: AbortSignal.timeout(OUTBOUND_TIMEOUT_MS),
|