@openclaw/discord 2026.5.7 → 2026.5.9-beta.1

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 (110) hide show
  1. package/dist/{access-CHY9FK3X.js → access-Lk7H_e7y.js} +1 -1
  2. package/dist/action-runtime-api.js +1 -1
  3. package/dist/{allow-list-ek-1hMKN.js → allow-list-Dtho5Hww.js} +1 -1
  4. package/dist/api.js +19 -17
  5. package/dist/{approval-handler.runtime-BBZRYAGs.js → approval-handler.runtime-CqvKEAqO.js} +3 -3
  6. package/dist/{approval-native-CBdZsAR7.js → approval-native-W5mtrjYy.js} +2 -2
  7. package/dist/{approval-shared-Ck6TxKgo.js → approval-shared-D0FVj8b_.js} +1 -1
  8. package/dist/{audit-CCJ0h49k.js → audit-CrCPCVFG.js} +3 -3
  9. package/dist/{channel-UXGa9PGc.js → channel-CRTWY5R-.js} +53 -31
  10. package/dist/{channel-actions-Br29_1nE.js → channel-actions-BRgtLo8F.js} +27 -1
  11. package/dist/{channel-actions.runtime-ChmNUig1.js → channel-actions.runtime-gosyu06g.js} +5 -5
  12. package/dist/channel-config-api.js +1 -1
  13. package/dist/channel-plugin-api.js +1 -1
  14. package/dist/{channel.setup-D_xyQu_h.js → channel.setup-BQlXR1Gt.js} +3 -3
  15. package/dist/chunk-BDgKaWaV.js +179 -0
  16. package/dist/{components-D5LnN7ZQ.js → components-BWdIitIb.js} +2 -2
  17. package/dist/{config-schema-Cc953rAs.js → config-schema-D1DUqXws.js} +46 -1
  18. package/dist/contract-api.js +7 -7
  19. package/dist/{conversation-identity-DHhS0ez3.js → conversation-identity-6hcTVj3L.js} +1 -1
  20. package/dist/directory-contract-api.js +1 -1
  21. package/dist/{directory-live-DJ0V5asB.js → directory-live-D3kbmVAu.js} +3 -3
  22. package/dist/{discord-eZlimVfW.js → discord-Du6FnKAq.js} +30 -13
  23. package/dist/{doctor-Bo-yifB3.js → doctor-Ys2-q5bc.js} +3 -3
  24. package/dist/{doctor-contract-Bso46EOQ.js → doctor-contract-DSB2zzJA.js} +1 -1
  25. package/dist/doctor-contract-api.js +1 -1
  26. package/dist/{handle-action.guild-admin-sJiQymg8.js → handle-action.guild-admin-LM6kZ6zE.js} +6 -3
  27. package/dist/{inbound-context-CRylwjg0.js → inbound-context-BobVUBqo.js} +1 -1
  28. package/dist/{manager.runtime-Cug1PoeZ.js → manager.runtime-C_cPd048.js} +802 -134
  29. package/dist/{mentions-BPZUaFk7.js → mentions-CiPUID82.js} +1 -1
  30. package/dist/{message-handler-C9Ohf-ea.js → message-handler-C2ZQV7ZQ.js} +7 -7
  31. package/dist/{message-handler.preflight-BrvazsYn.js → message-handler.preflight-B5hN7RpX.js} +15 -15
  32. package/dist/{message-handler.process-CEnzuLiN.js → message-handler.process-Dns8D7t2.js} +82 -65
  33. package/dist/{message-utils-9kaGF59d.js → message-utils-B3uf0_3D.js} +2 -2
  34. package/dist/normalize-DBcng6RL.js +58 -0
  35. package/dist/{outbound-adapter-DNsTVJfH.js → outbound-adapter-jP0OgIyW.js} +78 -17
  36. package/dist/{outbound-session-route-DK9qkPgP.js → outbound-session-route-BaJRt05p.js} +1 -1
  37. package/dist/{preflight-audio-CRmUxxuM.js → preflight-audio-6J0vFNtu.js} +1 -1
  38. package/dist/{preview-streaming-Cc_oeIPP.js → preview-streaming-CXrFDP2T.js} +1 -0
  39. package/dist/{probe-E80IMT1X.js → probe-91lU5eh8.js} +1 -1
  40. package/dist/{probe.runtime-CMgUDax3.js → probe.runtime-DV37RDCU.js} +1 -1
  41. package/dist/{provider-CuOh6z_b.js → provider-D_QVXvp8.js} +53 -50
  42. package/dist/{provider-session.runtime-CCESIHVo.js → provider-session.runtime-CcPDguh6.js} +3 -3
  43. package/dist/provider.runtime-O7G03kik.js +2 -0
  44. package/dist/{reply-delivery-D9aKHtDH.js → reply-delivery-DKTZ6HkK.js} +10 -7
  45. package/dist/{resolve-allowlist-common-_e1cWOb3.js → resolve-allowlist-common-LhuVITjh.js} +2 -2
  46. package/dist/{resolve-channels-kyuvrXJg.js → resolve-channels-DjpVRJdT.js} +3 -3
  47. package/dist/{resolve-users-CAwh4EBq.js → resolve-users-DrZYxZSX.js} +2 -2
  48. package/dist/{route-resolution-BWErj5Cn.js → route-resolution-CYRPDKY4.js} +3 -3
  49. package/dist/{runtime-D8alY00g.js → runtime-BHAwVXEa.js} +7 -7
  50. package/dist/runtime-api.actions.js +2 -2
  51. package/dist/runtime-api.js +25 -25
  52. package/dist/runtime-api.lookup.js +6 -6
  53. package/dist/runtime-api.monitor--iuvLjPX.js +6 -0
  54. package/dist/runtime-api.monitor.js +7 -7
  55. package/dist/runtime-api.send.js +5 -5
  56. package/dist/runtime-api.threads.js +5 -5
  57. package/dist/runtime-setter-api.js +1 -1
  58. package/dist/secret-contract-api.js +1 -1
  59. package/dist/{security-audit-BtRd_VhN.js → security-audit-D8IaFuCm.js} +1 -1
  60. package/dist/security-audit-contract-api.js +1 -1
  61. package/dist/{security-audit.runtime-Dm1LW9KX.js → security-audit.runtime-DO1398sV.js} +1 -1
  62. package/dist/security-contract-api.js +1 -1
  63. package/dist/{send-8S_HKJpQ.js → send-C3peGbWO.js} +83 -56
  64. package/dist/{send.components-A42c_5tQ.js → send.components-Dsk3IzS_.js} +22 -14
  65. package/dist/{send.outbound-D3tonSz8.js → send.outbound-CXyInQ3c.js} +22 -11
  66. package/dist/send.receipt-DXimpUGs.js +35 -0
  67. package/dist/{send.shared-BQGiUPvZ.js → send.shared-BydEWvYg.js} +26 -7
  68. package/dist/{sender-identity-BGUfyvOC.js → sender-identity-DVJCrDxs.js} +1 -1
  69. package/dist/session-key-api.js +1 -1
  70. package/dist/setup-plugin-api.js +1 -1
  71. package/dist/{shared-BEW4H3bj.js → shared-BWD6uc0p.js} +8 -8
  72. package/dist/{shared-interactive-KgJjCqnB.js → shared-interactive-BZCU0ZJ8.js} +2 -2
  73. package/dist/{subagent-hooks-T0LPLh4H.js → subagent-hooks-DtbWOdAK.js} +1 -1
  74. package/dist/subagent-hooks-api.js +1 -1
  75. package/dist/{system-events-_fzSG--3.js → system-events-Dsc8MFYs.js} +2 -2
  76. package/dist/target-parsing-D-H7nnh2.js +51 -0
  77. package/dist/target-resolver-D7t8FMhO.js +85 -0
  78. package/dist/targets-DzAZIwg4.js +3 -0
  79. package/dist/test-api.js +4 -4
  80. package/dist/{thread-bindings-CMpZjP50.js → thread-bindings-B90pBWJg.js} +6 -6
  81. package/dist/{thread-bindings.discord-api-CwWGoyei.js → thread-bindings.discord-api-Dvf789Je.js} +7 -7
  82. package/dist/{thread-bindings.manager-BtxfLfWf.js → thread-bindings.manager-AwZ5Vble.js} +5 -5
  83. package/dist/{thread-bindings.session-updates-jcZSiRPI.js → thread-bindings.session-updates-B_AcsXSf.js} +1 -1
  84. package/dist/{threading-BMmpA2JR.js → threading-Dku_cGS8.js} +4 -4
  85. package/dist/timeouts.js +1 -1
  86. package/dist/{typing-Bw6NKWLZ.js → typing-BIjMmOZB.js} +2 -2
  87. package/openclaw.plugin.json +222 -1
  88. package/package.json +5 -5
  89. package/dist/provider.runtime-B68g3qLv.js +0 -2
  90. package/dist/runtime-api.monitor-DzkCxeBL.js +0 -6
  91. package/dist/target-resolver-DA84_xbt.js +0 -365
  92. package/dist/targets-FwL1BPTU.js +0 -2
  93. /package/dist/{agent-components.runtime-Dof1YMSz.js → agent-components.runtime-caj0h9y4.js} +0 -0
  94. /package/dist/{api-DzNBVTto.js → api-DaTujGTe.js} +0 -0
  95. /package/dist/{audit-core-CejGc3hO.js → audit-core-CIvZE94W.js} +0 -0
  96. /package/dist/{channel-access-DFIQqbYm.js → channel-access-CXAdcM95.js} +0 -0
  97. /package/dist/{directory-cache-D93eSrpB.js → directory-cache-D3l2v2_L.js} +0 -0
  98. /package/dist/{directory-config-DoETeOOx.js → directory-config-S2852QcC.js} +0 -0
  99. /package/dist/{doctor-shared-Cqvfgv9m.js → doctor-shared-DtOaqWzy.js} +0 -0
  100. /package/dist/{format-D8TsaXxW.js → format-XDPCvGK4.js} +0 -0
  101. /package/dist/{pluralkit-OFss_pIy.js → pluralkit-EXKKni07.js} +0 -0
  102. /package/dist/{preflight-audio.runtime-DPVbpZid.js → preflight-audio.runtime-3hiRefuj.js} +0 -0
  103. /package/dist/{runtime-K9RT6Egn.js → runtime-EoVRXYxX.js} +0 -0
  104. /package/dist/{secret-config-contract-5S9U9pjx.js → secret-config-contract-BA9jVaKx.js} +0 -0
  105. /package/dist/{security-contract-BE8rsdPq.js → security-contract-B7i5uqn6.js} +0 -0
  106. /package/dist/{security-doctor-DiilN216.js → security-doctor-2SGSPibT.js} +0 -0
  107. /package/dist/{session-contract-CuW9Nlxg.js → session-contract-DwjfF970.js} +0 -0
  108. /package/dist/{session-key-normalization-B5La-jFM.js → session-key-normalization-DvI2OlyS.js} +0 -0
  109. /package/dist/{thread-bindings.state-WU4duXKY.js → thread-bindings.state-CBwtFsbB.js} +0 -0
  110. /package/dist/{timeouts-CdsmBWWs.js → timeouts-BxAzVpSG.js} +0 -0
@@ -1,365 +0,0 @@
1
- import { c as resolveDiscordAccountAllowFrom, s as resolveDiscordAccount } from "./accounts-CaHGiVB4.js";
2
- import { t as rememberDiscordDirectoryUser } from "./directory-cache-D93eSrpB.js";
3
- import { r as listDiscordDirectoryPeersLive } from "./directory-live-DJ0V5asB.js";
4
- import { buildMessagingTarget, parseMentionPrefixOrAtUserTarget, requireTargetKind } from "openclaw/plugin-sdk/messaging-targets";
5
- import { chunkMarkdownTextWithMode } from "openclaw/plugin-sdk/reply-chunking";
6
- //#region extensions/discord/src/target-parsing.ts
7
- function parseDiscordTarget(raw, options = {}) {
8
- const trimmed = raw.trim();
9
- if (!trimmed) return;
10
- const providerPrefixedTarget = parseDiscordProviderPrefixedTarget(trimmed);
11
- if (providerPrefixedTarget) return providerPrefixedTarget;
12
- const userTarget = parseMentionPrefixOrAtUserTarget({
13
- raw: trimmed,
14
- mentionPattern: /^<@!?(\d+)>$/,
15
- prefixes: [
16
- {
17
- prefix: "user:",
18
- kind: "user"
19
- },
20
- {
21
- prefix: "channel:",
22
- kind: "channel"
23
- },
24
- {
25
- prefix: "discord:",
26
- kind: "user"
27
- }
28
- ],
29
- atUserPattern: /^\d+$/,
30
- atUserErrorMessage: "Discord DMs require a user id (use user:<id> or a <@id> mention)"
31
- });
32
- if (userTarget) return userTarget;
33
- if (/^\d+$/.test(trimmed)) {
34
- if (options.defaultKind) return buildMessagingTarget(options.defaultKind, trimmed, trimmed);
35
- throw new Error(options.ambiguousMessage ?? `Ambiguous Discord recipient "${trimmed}". For DMs use "user:${trimmed}" or "<@${trimmed}>"; for channels use "channel:${trimmed}".`);
36
- }
37
- return buildMessagingTarget("channel", trimmed, trimmed);
38
- }
39
- function parseDiscordProviderPrefixedTarget(raw) {
40
- const match = /^discord:(channel|user):(.+)$/i.exec(raw);
41
- if (!match) return;
42
- const kind = match[1]?.toLowerCase();
43
- const id = match[2]?.trim();
44
- if (!kind || !id) return;
45
- return buildMessagingTarget(kind, id, `${kind}:${id}`);
46
- }
47
- function resolveDiscordChannelId(raw) {
48
- return requireTargetKind({
49
- platform: "Discord",
50
- target: parseDiscordTarget(raw, { defaultKind: "channel" }),
51
- kind: "channel"
52
- });
53
- }
54
- //#endregion
55
- //#region extensions/discord/src/chunk.ts
56
- const DEFAULT_MAX_CHARS = 2e3;
57
- const DEFAULT_MAX_LINES = 17;
58
- const FENCE_RE = /^( {0,3})(`{3,}|~{3,})(.*)$/;
59
- const CJK_PUNCTUATION_BREAK_AFTER_RE = /[、。,.!?;:)]}〉》」』】〕〗〙]/u;
60
- function countLines(text) {
61
- if (!text) return 0;
62
- return text.split("\n").length;
63
- }
64
- function parseFenceLine(line) {
65
- const match = line.match(FENCE_RE);
66
- if (!match) return null;
67
- const indent = match[1] ?? "";
68
- const marker = match[2] ?? "";
69
- return {
70
- indent,
71
- markerChar: marker[0] ?? "`",
72
- markerLen: marker.length,
73
- openLine: line
74
- };
75
- }
76
- function closeFenceLine(openFence) {
77
- return `${openFence.indent}${openFence.markerChar.repeat(openFence.markerLen)}`;
78
- }
79
- function closeFenceIfNeeded(text, openFence) {
80
- if (!openFence) return text;
81
- const closeLine = closeFenceLine(openFence);
82
- if (!text) return closeLine;
83
- if (!text.endsWith("\n")) return `${text}\n${closeLine}`;
84
- return `${text}${closeLine}`;
85
- }
86
- function isHighSurrogate(code) {
87
- return code >= 55296 && code <= 56319;
88
- }
89
- function isLowSurrogate(code) {
90
- return code >= 56320 && code <= 57343;
91
- }
92
- function clampToCodePointBoundary(text, index) {
93
- const boundary = Math.min(Math.max(0, index), text.length);
94
- if (boundary <= 0 || boundary >= text.length) return boundary;
95
- const previous = text.charCodeAt(boundary - 1);
96
- const next = text.charCodeAt(boundary);
97
- if (isHighSurrogate(previous) && isLowSurrogate(next)) return boundary > 1 ? boundary - 1 : boundary + 1;
98
- return boundary;
99
- }
100
- function findWhitespaceBreak(window) {
101
- for (let i = window.length - 1; i >= 0; i--) if (/\s/.test(window[i])) return i;
102
- return -1;
103
- }
104
- function findCjkPunctuationBreak(window) {
105
- for (let end = window.length; end > 0;) {
106
- const start = isLowSurrogate(window.charCodeAt(end - 1)) && end > 1 ? end - 2 : end - 1;
107
- const char = window.slice(start, end);
108
- if (start > 0 && CJK_PUNCTUATION_BREAK_AFTER_RE.test(char)) return end;
109
- end = start;
110
- }
111
- return -1;
112
- }
113
- function splitLongLine(line, maxChars, opts) {
114
- const limit = Math.max(1, Math.floor(maxChars));
115
- if (line.length <= limit) return [line];
116
- const out = [];
117
- let remaining = line;
118
- while (remaining.length > limit) {
119
- if (opts.preserveWhitespace) {
120
- const breakIdx = clampToCodePointBoundary(remaining, limit);
121
- out.push(remaining.slice(0, breakIdx));
122
- remaining = remaining.slice(breakIdx);
123
- continue;
124
- }
125
- const window = remaining.slice(0, limit);
126
- let breakIdx = findWhitespaceBreak(window);
127
- if (breakIdx <= 0) breakIdx = findCjkPunctuationBreak(window);
128
- if (breakIdx <= 0) breakIdx = clampToCodePointBoundary(remaining, limit);
129
- out.push(remaining.slice(0, breakIdx));
130
- remaining = remaining.slice(breakIdx);
131
- }
132
- if (remaining.length) out.push(remaining);
133
- return out;
134
- }
135
- /**
136
- * Chunks outbound Discord text by both character count and (soft) line count,
137
- * while keeping fenced code blocks balanced across chunks.
138
- */
139
- function chunkDiscordText(text, opts = {}) {
140
- const maxChars = Math.max(1, Math.floor(opts.maxChars ?? DEFAULT_MAX_CHARS));
141
- const maxLines = Math.max(1, Math.floor(opts.maxLines ?? DEFAULT_MAX_LINES));
142
- const body = text ?? "";
143
- if (!body) return [];
144
- if (body.length <= maxChars && countLines(body) <= maxLines) return [body];
145
- const lines = body.split("\n");
146
- const chunks = [];
147
- let current = "";
148
- let currentLines = 0;
149
- let openFence = null;
150
- const flush = () => {
151
- if (!current) return;
152
- const payload = closeFenceIfNeeded(current, openFence);
153
- if (payload.trim().length) chunks.push(payload);
154
- current = "";
155
- currentLines = 0;
156
- if (openFence) {
157
- current = openFence.openLine;
158
- currentLines = 1;
159
- }
160
- };
161
- for (const originalLine of lines) {
162
- const fenceInfo = parseFenceLine(originalLine);
163
- const wasInsideFence = openFence !== null;
164
- let nextOpenFence = openFence;
165
- if (fenceInfo) {
166
- if (!openFence) nextOpenFence = fenceInfo;
167
- else if (openFence.markerChar === fenceInfo.markerChar && fenceInfo.markerLen >= openFence.markerLen) nextOpenFence = null;
168
- }
169
- const reserveChars = nextOpenFence ? closeFenceLine(nextOpenFence).length + 1 : 0;
170
- const reserveLines = nextOpenFence ? 1 : 0;
171
- const effectiveMaxChars = maxChars - reserveChars;
172
- const effectiveMaxLines = maxLines - reserveLines;
173
- const charLimit = effectiveMaxChars > 0 ? effectiveMaxChars : maxChars;
174
- const lineLimit = effectiveMaxLines > 0 ? effectiveMaxLines : maxLines;
175
- const prefixLen = current.length > 0 ? current.length + 1 : 0;
176
- const segments = splitLongLine(originalLine, Math.max(1, charLimit - prefixLen), { preserveWhitespace: wasInsideFence });
177
- for (let segIndex = 0; segIndex < segments.length; segIndex++) {
178
- const segment = segments[segIndex];
179
- const isLineContinuation = segIndex > 0;
180
- const addition = `${isLineContinuation ? "" : current.length > 0 ? "\n" : ""}${segment}`;
181
- const nextLen = current.length + addition.length;
182
- const nextLines = currentLines + (isLineContinuation ? 0 : 1);
183
- if ((nextLen > charLimit || nextLines > lineLimit) && current.length > 0) flush();
184
- if (current.length > 0) {
185
- current += addition;
186
- if (!isLineContinuation) currentLines += 1;
187
- } else {
188
- current = segment;
189
- currentLines = 1;
190
- }
191
- }
192
- openFence = nextOpenFence;
193
- }
194
- if (current.length) {
195
- const payload = closeFenceIfNeeded(current, openFence);
196
- if (payload.trim().length) chunks.push(payload);
197
- }
198
- return rebalanceReasoningItalics(text, chunks);
199
- }
200
- function chunkDiscordTextWithMode(text, opts) {
201
- if ((opts.chunkMode ?? "length") !== "newline") return chunkDiscordText(text, opts);
202
- const lineChunks = chunkMarkdownTextWithMode(text, Math.max(1, Math.floor(opts.maxChars ?? DEFAULT_MAX_CHARS)), "newline");
203
- const chunks = [];
204
- for (const line of lineChunks) {
205
- const nested = chunkDiscordText(line, opts);
206
- if (!nested.length && line) {
207
- chunks.push(line);
208
- continue;
209
- }
210
- chunks.push(...nested);
211
- }
212
- return chunks;
213
- }
214
- function rebalanceReasoningItalics(source, chunks) {
215
- if (chunks.length <= 1) return chunks;
216
- if (!(source.startsWith("Reasoning:\n_") && source.trimEnd().endsWith("_"))) return chunks;
217
- const adjusted = [...chunks];
218
- for (let i = 0; i < adjusted.length; i++) {
219
- const isLast = i === adjusted.length - 1;
220
- const current = adjusted[i];
221
- if (!current.trimEnd().endsWith("_")) adjusted[i] = `${current}_`;
222
- if (isLast) break;
223
- const next = adjusted[i + 1];
224
- const leadingWhitespaceLen = next.length - next.trimStart().length;
225
- const leadingWhitespace = next.slice(0, leadingWhitespaceLen);
226
- const nextBody = next.slice(leadingWhitespaceLen);
227
- if (!nextBody.startsWith("_")) adjusted[i + 1] = `${leadingWhitespace}_${nextBody}`;
228
- }
229
- return adjusted;
230
- }
231
- //#endregion
232
- //#region extensions/discord/src/normalize.ts
233
- function normalizeDiscordMessagingTarget(raw) {
234
- return parseDiscordTarget(raw, { defaultKind: "channel" })?.normalized;
235
- }
236
- /**
237
- * Normalize a Discord outbound target for delivery. Bare numeric IDs are
238
- * prefixed with "channel:" to avoid the ambiguous-target error in
239
- * parseDiscordTarget, unless the ID is explicitly configured as an allowed DM
240
- * sender. All other formats pass through unchanged.
241
- */
242
- function normalizeDiscordOutboundTarget(to, allowFrom) {
243
- const trimmed = to?.trim();
244
- if (!trimmed) return {
245
- ok: false,
246
- error: /* @__PURE__ */ new Error("Discord recipient is required. Use \"channel:<id>\" for channels or \"user:<id>\" for DMs.")
247
- };
248
- if (/^\d+$/.test(trimmed)) {
249
- if (allowFromContainsDiscordUserId(allowFrom, trimmed)) return {
250
- ok: true,
251
- to: `user:${trimmed}`
252
- };
253
- return {
254
- ok: true,
255
- to: `channel:${trimmed}`
256
- };
257
- }
258
- if (/^discord:(?:channel|user):/i.test(trimmed)) return {
259
- ok: true,
260
- to: normalizeDiscordMessagingTarget(trimmed) ?? trimmed
261
- };
262
- return {
263
- ok: true,
264
- to: trimmed
265
- };
266
- }
267
- function allowFromContainsDiscordUserId(allowFrom, userId) {
268
- const normalizedUserId = userId.trim();
269
- if (!normalizedUserId) return false;
270
- return (allowFrom ?? []).some((entry) => normalizeAllowFromDiscordUserId(entry) === normalizedUserId);
271
- }
272
- function normalizeAllowFromDiscordUserId(entry) {
273
- const trimmed = entry.trim().toLowerCase();
274
- if (!trimmed || trimmed === "*") return;
275
- const mentionMatch = /^<@!?(\d+)>$/.exec(trimmed);
276
- if (mentionMatch) return mentionMatch[1];
277
- const prefixedMatch = /^(?:discord:)?user:(\d+)$/.exec(trimmed);
278
- if (prefixedMatch) return prefixedMatch[1];
279
- const discordMatch = /^discord:(\d+)$/.exec(trimmed);
280
- if (discordMatch) return discordMatch[1];
281
- return /^\d+$/.test(trimmed) ? trimmed : void 0;
282
- }
283
- function looksLikeDiscordTargetId(raw) {
284
- const trimmed = raw.trim();
285
- if (!trimmed) return false;
286
- if (/^<@!?\d+>$/.test(trimmed)) return true;
287
- if (/^(user|channel|discord):/i.test(trimmed)) return true;
288
- if (/^\d{6,}$/.test(trimmed)) return true;
289
- return false;
290
- }
291
- //#endregion
292
- //#region extensions/discord/src/send-target-parsing.ts
293
- const parseDiscordSendTarget = (raw, options = {}) => parseDiscordTarget(raw, options);
294
- //#endregion
295
- //#region extensions/discord/src/target-resolver.ts
296
- /**
297
- * Resolve a Discord username to user ID using the directory lookup.
298
- * This enables sending DMs by username instead of requiring explicit user IDs.
299
- */
300
- async function resolveDiscordTarget(raw, options, parseOptions = {}) {
301
- const trimmed = raw.trim();
302
- if (!trimmed) return;
303
- const likelyUsername = isLikelyUsername(trimmed);
304
- const shouldLookup = isExplicitUserLookup(trimmed, parseOptions) || likelyUsername;
305
- if (/^\d+$/.test(trimmed) && parseOptions.defaultKind !== "user" && isConfiguredAllowedDiscordDmUser(trimmed, options)) return buildMessagingTarget("user", trimmed, trimmed);
306
- const directParse = safeParseDiscordTarget(trimmed, parseOptions);
307
- if (directParse && directParse.kind !== "channel" && !likelyUsername) return directParse;
308
- if (!shouldLookup) return directParse ?? parseDiscordSendTarget(trimmed, parseOptions);
309
- try {
310
- const match = (await listDiscordDirectoryPeersLive({
311
- ...options,
312
- query: trimmed,
313
- limit: 1
314
- }))[0];
315
- if (match && match.kind === "user") {
316
- const userId = match.id.replace(/^user:/, "");
317
- const resolvedAccountId = resolveDiscordAccount({
318
- cfg: options.cfg,
319
- accountId: options.accountId
320
- }).accountId;
321
- rememberDiscordDirectoryUser({
322
- accountId: resolvedAccountId,
323
- userId,
324
- handles: [
325
- trimmed,
326
- match.name,
327
- match.handle
328
- ]
329
- });
330
- return buildMessagingTarget("user", userId, trimmed);
331
- }
332
- } catch {}
333
- return parseDiscordSendTarget(trimmed, parseOptions);
334
- }
335
- async function parseAndResolveDiscordTarget(raw, options, parseOptions = {}) {
336
- const resolved = await resolveDiscordTarget(raw, options, parseOptions) ?? parseDiscordSendTarget(raw, parseOptions);
337
- if (!resolved) throw new Error("Recipient is required for Discord sends");
338
- return resolved;
339
- }
340
- function safeParseDiscordTarget(input, options) {
341
- try {
342
- return parseDiscordSendTarget(input, options);
343
- } catch {
344
- return;
345
- }
346
- }
347
- function isConfiguredAllowedDiscordDmUser(input, options) {
348
- return allowFromContainsDiscordUserId(resolveDiscordAccountAllowFrom({
349
- cfg: options.cfg,
350
- accountId: options.accountId
351
- }) ?? [], input);
352
- }
353
- function isExplicitUserLookup(input, options) {
354
- if (/^<@!?(\d+)>$/.test(input)) return true;
355
- if (/^(user:|discord:)/.test(input)) return true;
356
- if (input.startsWith("@")) return true;
357
- if (/^\d+$/.test(input)) return options.defaultKind === "user";
358
- return false;
359
- }
360
- function isLikelyUsername(input) {
361
- if (/^(user:|channel:|discord:|@|<@!?)|[\d]+$/.test(input)) return false;
362
- return true;
363
- }
364
- //#endregion
365
- export { normalizeDiscordMessagingTarget as a, parseDiscordTarget as c, looksLikeDiscordTargetId as i, resolveDiscordChannelId as l, resolveDiscordTarget as n, normalizeDiscordOutboundTarget as o, parseDiscordSendTarget as r, chunkDiscordTextWithMode as s, parseAndResolveDiscordTarget as t };
@@ -1,2 +0,0 @@
1
- import "./target-resolver-DA84_xbt.js";
2
- export {};
File without changes
File without changes