@zhin.js/adapter-discord 7.0.8 → 7.0.9

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 CHANGED
@@ -1,5 +1,26 @@
1
1
  # @zhin.js/adapter-discord
2
2
 
3
+ ## 7.0.9
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [63253bb]
8
+ - Updated dependencies [6fb24dd]
9
+ - Updated dependencies [d162216]
10
+ - Updated dependencies [7427818]
11
+ - Updated dependencies [90da255]
12
+ - Updated dependencies [8e973dc]
13
+ - Updated dependencies [953cfe1]
14
+ - Updated dependencies [0e73866]
15
+ - @zhin.js/plugin-runtime@1.1.6
16
+ - @zhin.js/core@1.5.8
17
+ - @zhin.js/adapter@1.1.8
18
+ - @zhin.js/host-http@1.0.9
19
+ - @zhin.js/agent@1.1.9
20
+ - zhin.js@6.0.8
21
+ - @zhin.js/command@1.0.12
22
+ - @zhin.js/permission@1.0.2
23
+
3
24
  ## 7.0.8
4
25
 
5
26
  ### 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(messageId: string): Promise<void>;
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(messageId: string): Promise<void>;
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: (messageId) => this.recallMessage(messageId),
28
- addReaction: async (messageId, emoji, hint) => {
29
- const reference = parseLegacyMessageReference(messageId);
30
- const channelId = hint?.channelId
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, nativeMessageId, emoji);
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: formatLegacyConversationRef(conversation),
103
- messageId,
96
+ target: conversation.id,
97
+ messageId: snowflake,
104
98
  }));
105
- return messageId;
99
+ return snowflake;
106
100
  }
107
- async recallMessage(messageId) {
108
- if (!messageId)
101
+ async recallMessage(message) {
102
+ if (!message.id)
109
103
  return;
110
- const reference = parseLegacyMessageReference(messageId);
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(snowflake);
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: (messageId) => this.recallMessage(messageId),
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
- // recall 链路仍是本端点编码的 legacy 引用,在边界内部从 conversation 派生
378
- return snowflake ? formatLegacyMessageRef({ conversation, id: snowflake }) : '';
366
+ return snowflake;
379
367
  }
380
- async recallMessage(messageId) {
381
- if (!messageId)
382
- return;
383
- const reference = parseLegacyMessageReference(messageId);
384
- if (!reference)
368
+ async recallMessage(message) {
369
+ if (!message.id)
385
370
  return;
386
- const channelId = nativeConversationId(reference.target);
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.8",
3
+ "version": "7.0.9",
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.7",
37
- "@zhin.js/command": "1.0.11",
38
- "@zhin.js/core": "1.5.7",
39
- "@zhin.js/host-http": "1.0.8",
36
+ "@zhin.js/adapter": "1.1.8",
37
+ "@zhin.js/command": "1.0.12",
38
+ "@zhin.js/core": "1.5.8",
39
+ "@zhin.js/host-http": "1.0.9",
40
40
  "@zhin.js/im-contract": "1.0.3",
41
41
  "@zhin.js/logger": "1.0.76",
42
- "@zhin.js/permission": "1.0.1",
43
- "@zhin.js/plugin-runtime": "1.1.5"
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.7",
48
- "@zhin.js/agent": "1.1.8",
49
- "@zhin.js/core": "1.5.7",
50
- "@zhin.js/plugin-runtime": "1.1.5",
51
- "zhin.js": "6.0.7"
47
+ "@zhin.js/adapter": "1.1.8",
48
+ "@zhin.js/agent": "1.1.9",
49
+ "@zhin.js/core": "1.5.8",
50
+ "@zhin.js/plugin-runtime": "1.1.6",
51
+ "zhin.js": "6.0.8"
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.8",
70
- "@zhin.js/host-http": "1.0.8",
71
- "zhin.js": "6.0.7"
69
+ "@zhin.js/agent": "1.1.9",
70
+ "@zhin.js/host-http": "1.0.9",
71
+ "zhin.js": "6.0.8"
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
- formatLegacyConversationRef,
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: (messageId: string) => this.recallMessage(messageId),
75
+ recall: (message: MessageRef) => this.recallMessage(message),
79
76
  addReaction: async (
80
- messageId: string,
77
+ message: MessageRef,
81
78
  emoji: string,
82
79
  hint?: { readonly sceneType?: string; readonly channelId?: string },
83
80
  ) => {
84
- const reference = parseLegacyMessageReference(messageId);
85
- const channelId = hint?.channelId
86
- ?? (reference ? nativeConversationId(reference.target) : undefined);
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: formatLegacyConversationRef(conversation),
160
- messageId,
151
+ target: conversation.id,
152
+ messageId: snowflake,
161
153
  }));
162
- return messageId;
154
+ return snowflake;
163
155
  }
164
156
 
165
- async recallMessage(messageId: string): Promise<void> {
166
- if (!messageId) return;
167
- const reference = parseLegacyMessageReference(messageId);
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(snowflake);
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: (messageId: string) => this.recallMessage(messageId),
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
- // recall 链路仍是本端点编码的 legacy 引用,在边界内部从 conversation 派生
497
- return snowflake ? formatLegacyMessageRef({ conversation, id: snowflake }) : '';
484
+ return snowflake;
498
485
  }
499
486
 
500
- async recallMessage(messageId: string): Promise<void> {
501
- if (!messageId) return;
502
- const reference = parseLegacyMessageReference(messageId);
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),