@openclaw/discord 2026.7.2-beta.7 → 2026.8.1-beta.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 (114) hide show
  1. package/dist/{account-inspect-SXiCBCgP.js → account-inspect-D5xmUpnj.js} +49 -43
  2. package/dist/account-inspect-api.js +1 -1
  3. package/dist/accounts-DNl-oCEw.js +371 -0
  4. package/dist/action-runtime-api.js +1 -1
  5. package/dist/{active-turn-thread-route-MlKWp8RD.js → active-turn-thread-route-fmHl1HNd.js} +9 -11
  6. package/dist/{activities-api-DTKsuDxf.js → activities-api-KCBAmWxD.js} +133 -175
  7. package/dist/activities-api.js +1 -1
  8. package/dist/{allow-list-DzKrtfah.js → allow-list-BDMimASD.js} +2 -3
  9. package/dist/{api-DnrK9gML.js → api-DNVbJyEy.js} +7 -2
  10. package/dist/api.js +18 -18
  11. package/dist/{approval-handler.runtime-HymvFTYn.js → approval-handler.runtime-B12RCYr8.js} +6 -6
  12. package/dist/{approval-message-safety-DEyKVsAw.js → approval-message-safety-XGFPbDoI.js} +89 -3
  13. package/dist/{audit-CjsrabP8.js → audit-Yc7eZDd6.js} +5 -5
  14. package/dist/{channel-actions-uXFTJX3o.js → channel-actions-Dr2QI8Bf.js} +11 -7
  15. package/dist/{channel-actions.runtime-CIYU90sl.js → channel-actions.runtime-CODTvo7c.js} +99 -97
  16. package/dist/{channel-vKa-76xY.js → channel-cXYzGc4L.js} +102 -104
  17. package/dist/channel-config-api.js +1 -1
  18. package/dist/channel-plugin-api.js +1 -1
  19. package/dist/{channel.setup-CmcwZ_qd.js → channel.setup-CSiwnMgs.js} +16 -54
  20. package/dist/{outbound-session-route-H-HoyH5U.js → components-ezGKo_Yh.js} +69 -142
  21. package/dist/{config-schema-WHRQcY19.js → config-schema-DC5kDtQ5.js} +42 -11
  22. package/dist/conversation-binding-route-D6rCQ5S0.js +43 -0
  23. package/dist/{directory-config-D_LojtCe.js → directory-config-XyCfoqLg.js} +2 -2
  24. package/dist/directory-contract-api.js +1 -1
  25. package/dist/{directory-live-Bw5Ephzv.js → directory-live-Df0NbFJB.js} +7 -4
  26. package/dist/{doctor-Bc4S1qyd.js → doctor-DYY31GrO.js} +34 -13
  27. package/dist/{doctor-contract-CCFMIDk9.js → doctor-contract-DsWvKIXF.js} +2 -3
  28. package/dist/doctor-contract-api.js +147 -2
  29. package/dist/{handle-action.guild-admin-D6VRRW-C.js → handle-action.guild-admin-6Tvvinsa.js} +4 -7
  30. package/dist/{inbound-event-delivery-CEPlt2uz.js → inbound-event-delivery-De2qxTrP.js} +4 -25
  31. package/dist/index.js +5 -4
  32. package/dist/{message-handler-CeiSulIw.js → message-handler-B61q5MOF.js} +118 -33
  33. package/dist/{message-handler.preflight-DibgQFf2.js → message-handler.preflight-Bzg_Hawz.js} +75 -61
  34. package/dist/{message-handler.process-Dnc_oz9y.js → message-handler.process--4_712Ec.js} +236 -296
  35. package/dist/{message-utils-BgTwT_q7.js → message-utils-BXLLnFl6.js} +34 -35
  36. package/dist/{model-picker-preference-primitives-D25pnCOu.js → model-picker-preference-primitives-BHT1LkR_.js} +3 -3
  37. package/dist/{outbound-adapter-DtE-i2OJ.js → outbound-adapter-DxHTOqiN.js} +157 -68
  38. package/dist/{outbound-components-C7GVyfPh.js → outbound-components-B2PL0ooH.js} +3 -3
  39. package/dist/owner-access-Bg41VzAf.js +107 -0
  40. package/dist/{pluralkit-CD4B11JB.js → pluralkit-dUl4v1X3.js} +1 -1
  41. package/dist/{preflight-audio-BjnQZ5yS.js → preflight-audio-DrnqFA8U.js} +22 -28
  42. package/dist/{probe-BeWKhjqX.js → probe-BTdtVRwU.js} +37 -13
  43. package/dist/probe.runtime-Dq5-PRKT.js +2 -0
  44. package/dist/{provider-DfQJX3z5.js → provider-DlK_ynqt.js} +1131 -2021
  45. package/dist/{provider-session.runtime-Bo88k0pV.js → provider-session.runtime-CvvphHvs.js} +3 -3
  46. package/dist/provider.runtime-CzKGRiAF.js +2 -0
  47. package/dist/realtime-session.runtime-ysbMG8v7.js +1351 -0
  48. package/dist/{resolve-allowlist-common-DHERApxi.js → resolve-allowlist-common-DIVXbD1P.js} +3 -3
  49. package/dist/{resolve-channels-BjepAj8b.js → resolve-channels-CGeUoIqb.js} +4 -4
  50. package/dist/{resolve-users-Bc28htgt.js → resolve-users-BtKxLUZv.js} +3 -3
  51. package/dist/{chunk-DX4jpFQP.js → retry-DNsVTeTo.js} +308 -131
  52. package/dist/{runtime-BmW_j_hl.js → runtime-CQovMsH3.js} +12 -15
  53. package/dist/{runtime-_aRC6V2s.js → runtime-D71_VFLr.js} +49 -58
  54. package/dist/runtime-api.actions.js +2 -2
  55. package/dist/runtime-api.js +23 -23
  56. package/dist/runtime-api.lookup.js +5 -5
  57. package/dist/runtime-api.monitor-CzeTYF32.js +6 -0
  58. package/dist/runtime-api.monitor.js +6 -5
  59. package/dist/runtime-api.send.js +6 -6
  60. package/dist/runtime-api.threads.js +5 -6
  61. package/dist/sdk-runtime-37OU6_Yh.js +369 -0
  62. package/dist/{secret-config-contract-B1akrlyY.js → secret-config-contract-B3i6WxV5.js} +53 -25
  63. package/dist/secret-contract-api.js +1 -1
  64. package/dist/security-audit-contract-api.js +1 -1
  65. package/dist/{security-audit.runtime-CPN0xFYz.js → security-audit.runtime-BVKF9VtY.js} +1 -1
  66. package/dist/{send-CdkZ6zeW.js → send-rQIffSYu.js} +180 -91
  67. package/dist/{send.components-5uqwkjgE.js → send.components-ChK1wS7w.js} +32 -46
  68. package/dist/{send.outbound-D-80Ej-t.js → send.outbound-HIkgji_7.js} +57 -34
  69. package/dist/{send.reactions-CtlmGd_o.js → send.reactions-gmJ6yFPo.js} +14 -21
  70. package/dist/{send.receipt-CuwRrpFz.js → send.receipt-Cnhoautb.js} +29 -1
  71. package/dist/{send.shared-jpvAG_u6.js → send.shared-B3fpaLWJ.js} +112 -181
  72. package/dist/{sender-identity-mG_zsdox.js → sender-identity-BJtfyise.js} +1 -1
  73. package/dist/setup-entry.js +0 -5
  74. package/dist/setup-plugin-api.js +1 -1
  75. package/dist/{shared-CXF1tup1.js → shared-CaAaoksy.js} +27 -23
  76. package/dist/subagent-hooks-CNT2ZJTJ.js +49 -0
  77. package/dist/subagent-hooks-api.js +2 -6
  78. package/dist/subagent-progress-FPLqBY1s.js +110 -0
  79. package/dist/{system-events-DdUqf91B.js → system-events-Nuwoq_au.js} +2 -2
  80. package/dist/{target-resolver-C3s_2m0t.js → target-resolver-DIXShHaZ.js} +3 -3
  81. package/dist/targets-B2pf49zc.js +3 -0
  82. package/dist/{thread-bindings-C-M-ly7P.js → thread-bindings-VlymUnbz.js} +29 -28
  83. package/dist/{thread-bindings.manager-DYvSlrva.js → thread-bindings.manager-CngsgErq.js} +258 -29
  84. package/dist/{thread-bindings.session-updates-DAIlp7Px.js → thread-bindings.session-updates-CJb-BpPL.js} +1 -1
  85. package/dist/{thread-bindings.state-Cgi5uRn-.js → thread-bindings.state-D8OMdk4O.js} +3 -16
  86. package/dist/threading-DU6pgeGm.js +456 -0
  87. package/dist/transcripts-source-DeIMNbRh.js +265 -0
  88. package/dist/transcripts-source-api.js +7 -2
  89. package/dist/{typing--Mzo2kM7.js → typing-oLiS5Z13.js} +1 -1
  90. package/dist/voice-runtime-CjNFaynA.js +2549 -0
  91. package/openclaw.plugin.json +215 -25
  92. package/package.json +15 -11
  93. package/skills/discord/SKILL.md +22 -115
  94. package/dist/accounts-DJTf1LtA.js +0 -219
  95. package/dist/channel-api-CAJ0wMoV.js +0 -21
  96. package/dist/legacy-state-migrations-api.js +0 -138
  97. package/dist/manager.runtime-Bjav3pfC.js +0 -3655
  98. package/dist/preflight-audio.runtime-CoCXMM8r.js +0 -7
  99. package/dist/probe.runtime-DqFGFMbZ.js +0 -2
  100. package/dist/provider.runtime-Cy7XZmyh.js +0 -2
  101. package/dist/runtime-api.monitor-CCRubd3-.js +0 -5
  102. package/dist/session-binding-contract-api.js +0 -2
  103. package/dist/subagent-hooks-Dxy7Fmnq.js +0 -120
  104. package/dist/subagent-progress-DI3sYLLo.js +0 -664
  105. package/dist/targets-Dv_RN7vT.js +0 -3
  106. package/dist/thread-bindings.discord-api-BoDNqamb.js +0 -246
  107. package/dist/transcripts-source-DIKGsTGT.js +0 -123
  108. package/node_modules/p-map/index.d.ts +0 -155
  109. package/node_modules/p-map/index.js +0 -285
  110. package/node_modules/p-map/license +0 -9
  111. package/node_modules/p-map/package.json +0 -57
  112. package/node_modules/p-map/readme.md +0 -190
  113. package/dist/{audit-core-xwjIczO0.js → audit-core-BCX8UeFH.js} +1 -1
  114. package/dist/{security-audit-jGnJF__m.js → security-audit-BfJhAXZp.js} +1 -1
@@ -1,246 +0,0 @@
1
- import { st as createChannelWebhook, u as resolveDiscordChannelId, yt as getChannel } from "./chunk-DX4jpFQP.js";
2
- import { F as createDiscordRestClient } from "./send.shared-jpvAG_u6.js";
3
- import { t as sendMessageDiscord } from "./send.outbound-D-80Ej-t.js";
4
- import { a as createThreadDiscord, r as sendWebhookMessageDiscord } from "./send-CdkZ6zeW.js";
5
- import { g as rememberReusableWebhook, i as REUSABLE_WEBHOOKS_BY_ACCOUNT_CHANNEL, j as toReusableWebhookKey, t as BINDINGS_BY_THREAD_ID } from "./thread-bindings.state-Cgi5uRn-.js";
6
- import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
7
- import { ChannelType } from "discord-api-types/v10";
8
- import { parseStrictNonNegativeInteger } from "openclaw/plugin-sdk/number-runtime";
9
- import { logVerbose } from "openclaw/plugin-sdk/runtime-env";
10
- import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
11
- import { SYSTEM_MARK } from "openclaw/plugin-sdk/text-chunking";
12
- import { formatThreadBindingDurationLabel, resolveThreadBindingFarewellText, resolveThreadBindingIntroText, resolveThreadBindingThreadName } from "openclaw/plugin-sdk/conversation-runtime";
13
- //#region extensions/discord/src/monitor/thread-bindings.persona.ts
14
- const THREAD_BINDING_PERSONA_MAX_CHARS = 80;
15
- function normalizePersonaLabel(value) {
16
- if (!value) return;
17
- return value.replace(/\s+/g, " ").trim() || void 0;
18
- }
19
- function resolveThreadBindingPersona(params) {
20
- return truncateUtf16Safe(`${SYSTEM_MARK} ${normalizePersonaLabel(params.label) || normalizePersonaLabel(params.agentId) || "agent"}`, THREAD_BINDING_PERSONA_MAX_CHARS);
21
- }
22
- function resolveThreadBindingPersonaFromRecord(record) {
23
- return resolveThreadBindingPersona({
24
- label: record.label,
25
- agentId: record.agentId
26
- });
27
- }
28
- //#endregion
29
- //#region extensions/discord/src/monitor/channel-access.ts
30
- function readDiscordChannelPropertySafe(channel, key) {
31
- if (!channel || typeof channel !== "object") return;
32
- try {
33
- if (!(key in channel)) return;
34
- return channel[key];
35
- } catch {
36
- return;
37
- }
38
- }
39
- function resolveDiscordChannelStringPropertySafe(channel, key) {
40
- const value = readDiscordChannelPropertySafe(channel, key);
41
- return typeof value === "string" ? value : void 0;
42
- }
43
- function resolveDiscordChannelNumberPropertySafe(channel, key) {
44
- const value = readDiscordChannelPropertySafe(channel, key);
45
- return typeof value === "number" ? value : void 0;
46
- }
47
- const DISCORD_CHANNEL_SNAKE_CASE_ALIASES = {
48
- ownerId: "owner_id",
49
- parentId: "parent_id"
50
- };
51
- function resolveDiscordChannelStringWithAliasSafe(channel, camelKey) {
52
- const camelValue = resolveDiscordChannelStringPropertySafe(channel, camelKey);
53
- if (camelValue !== void 0) return camelValue;
54
- const snakeKey = DISCORD_CHANNEL_SNAKE_CASE_ALIASES[camelKey];
55
- if (!snakeKey) return;
56
- const directSnakeValue = resolveDiscordChannelStringPropertySafe(channel, snakeKey);
57
- if (directSnakeValue !== void 0) return directSnakeValue;
58
- return resolveDiscordChannelStringPropertySafe(readDiscordChannelPropertySafe(channel, "rawData"), snakeKey);
59
- }
60
- function resolveDiscordChannelNameSafe(channel) {
61
- return resolveDiscordChannelStringPropertySafe(channel, "name");
62
- }
63
- function resolveDiscordChannelIdSafe(channel) {
64
- return resolveDiscordChannelStringPropertySafe(channel, "id");
65
- }
66
- function resolveDiscordChannelTopicSafe(channel) {
67
- return resolveDiscordChannelStringPropertySafe(channel, "topic");
68
- }
69
- function resolveDiscordChannelParentIdSafe(channel) {
70
- return resolveDiscordChannelStringWithAliasSafe(channel, "parentId");
71
- }
72
- function resolveDiscordChannelOwnerIdSafe(channel) {
73
- return resolveDiscordChannelStringWithAliasSafe(channel, "ownerId");
74
- }
75
- function resolveDiscordChannelParentSafe(channel) {
76
- return readDiscordChannelPropertySafe(channel, "parent");
77
- }
78
- function resolveDiscordChannelInfoSafe(channel) {
79
- const parent = resolveDiscordChannelParentSafe(channel);
80
- return {
81
- name: resolveDiscordChannelNameSafe(channel),
82
- topic: resolveDiscordChannelTopicSafe(channel),
83
- type: resolveDiscordChannelNumberPropertySafe(channel, "type"),
84
- parentId: resolveDiscordChannelParentIdSafe(channel),
85
- ownerId: resolveDiscordChannelOwnerIdSafe(channel),
86
- parentName: resolveDiscordChannelNameSafe(parent)
87
- };
88
- }
89
- //#endregion
90
- //#region extensions/discord/src/monitor/thread-bindings.types.ts
91
- const THREAD_BINDINGS_SWEEP_INTERVAL_MS = 12e4;
92
- const DEFAULT_THREAD_BINDING_IDLE_TIMEOUT_MS = 1440 * 60 * 1e3;
93
- //#endregion
94
- //#region extensions/discord/src/monitor/thread-bindings.discord-api.ts
95
- function buildThreadTarget(threadId) {
96
- return /^(channel:|user:)/i.test(threadId) ? threadId : `channel:${threadId}`;
97
- }
98
- function isThreadArchived(raw) {
99
- if (!raw || typeof raw !== "object") return false;
100
- const asRecord = raw;
101
- if (asRecord.archived === true) return true;
102
- if (asRecord.thread_metadata?.archived === true) return true;
103
- if (asRecord.threadMetadata?.archived === true) return true;
104
- return false;
105
- }
106
- function isThreadChannelType(type) {
107
- return type === ChannelType.PublicThread || type === ChannelType.PrivateThread || type === ChannelType.AnnouncementThread;
108
- }
109
- function normalizeDiscordBindingChannelId(raw) {
110
- const trimmed = normalizeOptionalString(raw) ?? "";
111
- if (!trimmed) return null;
112
- try {
113
- return resolveDiscordChannelId(trimmed);
114
- } catch {
115
- return null;
116
- }
117
- }
118
- function summarizeDiscordError(err) {
119
- if (err instanceof Error) return err.message;
120
- if (typeof err === "string") return err;
121
- if (typeof err === "number" || typeof err === "boolean" || typeof err === "bigint" || typeof err === "symbol") return String(err);
122
- return "error";
123
- }
124
- function extractNumericDiscordErrorValue(value) {
125
- return parseStrictNonNegativeInteger(value);
126
- }
127
- function extractDiscordErrorStatus(err) {
128
- if (!err || typeof err !== "object") return;
129
- const candidate = err;
130
- return extractNumericDiscordErrorValue(candidate.status) ?? extractNumericDiscordErrorValue(candidate.statusCode) ?? extractNumericDiscordErrorValue(candidate.response?.status);
131
- }
132
- function extractDiscordErrorCode(err) {
133
- if (!err || typeof err !== "object") return;
134
- const candidate = err;
135
- return extractNumericDiscordErrorValue(candidate.code) ?? extractNumericDiscordErrorValue(candidate.rawError?.code) ?? extractNumericDiscordErrorValue(candidate.body?.code) ?? extractNumericDiscordErrorValue(candidate.response?.body?.code) ?? extractNumericDiscordErrorValue(candidate.response?.data?.code);
136
- }
137
- function isDiscordThreadGoneError(err) {
138
- if (extractDiscordErrorCode(err) === 10003) return true;
139
- const status = extractDiscordErrorStatus(err);
140
- return status === 404 || status === 403;
141
- }
142
- async function maybeSendBindingMessage(params) {
143
- const text = params.text.trim();
144
- if (!text) return;
145
- const record = params.record;
146
- if (params.preferWebhook !== false && record.webhookId && record.webhookToken) try {
147
- await sendWebhookMessageDiscord(text, {
148
- cfg: params.cfg,
149
- webhookId: record.webhookId,
150
- webhookToken: record.webhookToken,
151
- accountId: record.accountId,
152
- threadId: record.threadId,
153
- username: resolveThreadBindingPersonaFromRecord(record)
154
- });
155
- return;
156
- } catch (err) {
157
- logVerbose(`discord thread binding webhook send failed: ${summarizeDiscordError(err)}`);
158
- }
159
- try {
160
- await sendMessageDiscord(buildThreadTarget(record.threadId), text, {
161
- cfg: params.cfg,
162
- accountId: record.accountId
163
- });
164
- } catch (err) {
165
- logVerbose(`discord thread binding fallback send failed: ${summarizeDiscordError(err)}`);
166
- }
167
- }
168
- async function createWebhookForChannel(params) {
169
- try {
170
- const rest = createDiscordRestClient({
171
- cfg: params.cfg,
172
- accountId: params.accountId,
173
- token: params.token
174
- }).rest;
175
- const created = await createChannelWebhook(rest, params.channelId, { body: { name: "OpenClaw Agents" } });
176
- const webhookId = normalizeOptionalString(created?.id) ?? "";
177
- const webhookToken = normalizeOptionalString(created?.token) ?? "";
178
- if (!webhookId || !webhookToken) return {};
179
- return {
180
- webhookId,
181
- webhookToken
182
- };
183
- } catch (err) {
184
- logVerbose(`discord thread binding webhook create failed for ${params.channelId}: ${summarizeDiscordError(err)}`);
185
- return {};
186
- }
187
- }
188
- function findReusableWebhook(params) {
189
- const reusableKey = toReusableWebhookKey({
190
- accountId: params.accountId,
191
- channelId: params.channelId
192
- });
193
- const cached = REUSABLE_WEBHOOKS_BY_ACCOUNT_CHANNEL.get(reusableKey);
194
- if (cached) return {
195
- webhookId: cached.webhookId,
196
- webhookToken: cached.webhookToken
197
- };
198
- for (const record of BINDINGS_BY_THREAD_ID.values()) {
199
- if (record.accountId !== params.accountId) continue;
200
- if (record.channelId !== params.channelId) continue;
201
- if (!record.webhookId || !record.webhookToken) continue;
202
- rememberReusableWebhook(record);
203
- return {
204
- webhookId: record.webhookId,
205
- webhookToken: record.webhookToken
206
- };
207
- }
208
- return {};
209
- }
210
- async function resolveChannelIdForBinding(params) {
211
- const explicit = normalizeDiscordBindingChannelId(params.channelId);
212
- if (explicit) return explicit;
213
- const lookupThreadId = normalizeDiscordBindingChannelId(params.threadId);
214
- if (!lookupThreadId) return null;
215
- try {
216
- const rest = createDiscordRestClient({
217
- cfg: params.cfg,
218
- accountId: params.accountId,
219
- token: params.token
220
- }).rest;
221
- const channel = await getChannel(rest, lookupThreadId);
222
- const channelInfo = resolveDiscordChannelInfoSafe(channel);
223
- const channelId = normalizeOptionalString(resolveDiscordChannelIdSafe(channel)) ?? "";
224
- const type = channelInfo.type;
225
- const parentId = normalizeOptionalString(channelInfo.parentId) ?? "";
226
- if (parentId && isThreadChannelType(type)) return parentId;
227
- return channelId || null;
228
- } catch (err) {
229
- logVerbose(`discord thread binding channel resolve failed for ${lookupThreadId}: ${summarizeDiscordError(err)}`);
230
- return null;
231
- }
232
- }
233
- async function createThreadForBinding(params) {
234
- try {
235
- return (normalizeOptionalString((await createThreadDiscord(params.channelId, { name: params.threadName }, {
236
- cfg: params.cfg,
237
- accountId: params.accountId,
238
- token: params.token
239
- }))?.id) ?? "") || null;
240
- } catch (err) {
241
- logVerbose(`discord thread binding auto-thread create failed for ${params.channelId}: ${summarizeDiscordError(err)}`);
242
- return null;
243
- }
244
- }
245
- //#endregion
246
- export { resolveThreadBindingThreadName as S, resolveThreadBindingPersona as _, isThreadArchived as a, resolveThreadBindingFarewellText as b, summarizeDiscordError as c, resolveDiscordChannelIdSafe as d, resolveDiscordChannelInfoSafe as f, resolveDiscordChannelTopicSafe as g, resolveDiscordChannelParentSafe as h, isDiscordThreadGoneError as i, DEFAULT_THREAD_BINDING_IDLE_TIMEOUT_MS as l, resolveDiscordChannelParentIdSafe as m, createWebhookForChannel as n, maybeSendBindingMessage as o, resolveDiscordChannelNameSafe as p, findReusableWebhook as r, resolveChannelIdForBinding as s, createThreadForBinding as t, THREAD_BINDINGS_SWEEP_INTERVAL_MS as u, resolveThreadBindingPersonaFromRecord as v, resolveThreadBindingIntroText as x, formatThreadBindingDurationLabel as y };
@@ -1,123 +0,0 @@
1
- import { Yt as __exportAll } from "./chunk-DX4jpFQP.js";
2
- //#region extensions/discord/src/voice/transcripts-source.ts
3
- var transcripts_source_exports = /* @__PURE__ */ __exportAll({
4
- discordVoiceTranscriptsSourceProvider: () => discordVoiceTranscriptsSourceProvider,
5
- setDiscordTranscriptsVoiceManager: () => setDiscordTranscriptsVoiceManager
6
- });
7
- const managersByAccountId = /* @__PURE__ */ new Map();
8
- const managerWaiters = /* @__PURE__ */ new Set();
9
- function setDiscordTranscriptsVoiceManager(params) {
10
- if (params.manager) {
11
- managersByAccountId.set(params.accountId, params.manager);
12
- for (const waiter of managerWaiters) if (!waiter.accountId || waiter.accountId === params.accountId) waiter.resolve();
13
- } else managersByAccountId.delete(params.accountId);
14
- }
15
- function resolveManager(request) {
16
- const accountId = request.session.source.accountId?.trim();
17
- if (accountId) return managersByAccountId.get(accountId);
18
- return [...managersByAccountId.values()][0];
19
- }
20
- async function waitForManager(request) {
21
- const existing = resolveManager(request);
22
- if (existing) return existing;
23
- if (request.abortSignal?.aborted) return;
24
- const startupWaitMs = request.startupWaitMs ?? 0;
25
- if (startupWaitMs <= 0) return;
26
- const accountId = request.session.source.accountId?.trim() || void 0;
27
- await new Promise((resolve) => {
28
- const waiter = {
29
- accountId,
30
- resolve: () => {
31
- clearTimeout(timer);
32
- request.abortSignal?.removeEventListener("abort", waiter.resolve);
33
- managerWaiters.delete(waiter);
34
- resolve();
35
- }
36
- };
37
- const timer = setTimeout(waiter.resolve, startupWaitMs);
38
- timer.unref?.();
39
- request.abortSignal?.addEventListener("abort", waiter.resolve, { once: true });
40
- managerWaiters.add(waiter);
41
- });
42
- if (request.abortSignal?.aborted) return;
43
- return resolveManager(request);
44
- }
45
- const discordVoiceTranscriptsSourceProvider = {
46
- id: "discord-voice",
47
- aliases: ["discord"],
48
- name: "Discord Voice",
49
- sourceKinds: ["live-audio"],
50
- async start(request) {
51
- const manager = await waitForManager(request);
52
- if (!manager) return {
53
- ok: false,
54
- error: "Discord voice manager is not available."
55
- };
56
- if (request.abortSignal?.aborted) return {
57
- ok: false,
58
- error: "Discord transcripts start aborted."
59
- };
60
- const guildId = request.session.source.guildId?.trim();
61
- const channelId = request.session.source.channelId?.trim();
62
- if (!guildId || !channelId) return {
63
- ok: false,
64
- error: "Discord transcripts require guildId and channelId."
65
- };
66
- const joined = await manager.join({
67
- guildId,
68
- channelId
69
- }, { transcripts: {
70
- sessionId: request.session.sessionId,
71
- onUtterance: request.onUtterance
72
- } });
73
- if (!joined.ok) return {
74
- ok: false,
75
- error: joined.message
76
- };
77
- return {
78
- ok: true,
79
- session: request.session
80
- };
81
- },
82
- async stop(request) {
83
- const accountId = request.source.accountId?.trim();
84
- const manager = accountId ? managersByAccountId.get(accountId) : [...managersByAccountId.values()][0];
85
- if (!manager) return {
86
- ok: false,
87
- error: "Discord voice manager is not available."
88
- };
89
- const guildId = request.source.guildId?.trim();
90
- if (!guildId) return {
91
- ok: false,
92
- error: "Discord transcripts require guildId."
93
- };
94
- const result = await manager.leave({
95
- guildId,
96
- channelId: request.source.channelId
97
- }, { transcriptsSessionId: request.sessionId });
98
- if (!result.ok) return {
99
- ok: false,
100
- error: result.message
101
- };
102
- return {
103
- ok: true,
104
- sessionId: request.sessionId,
105
- stoppedAt: (/* @__PURE__ */ new Date()).toISOString()
106
- };
107
- },
108
- async status(source) {
109
- const accountId = source.accountId?.trim();
110
- return (accountId ? managersByAccountId.get(accountId) : [...managersByAccountId.values()][0])?.status().map((entry) => ({
111
- active: entry.ok,
112
- message: entry.message,
113
- source: {
114
- providerId: "discord-voice",
115
- accountId,
116
- guildId: entry.guildId,
117
- channelId: entry.channelId
118
- }
119
- })) ?? [];
120
- }
121
- };
122
- //#endregion
123
- export { transcripts_source_exports as n, discordVoiceTranscriptsSourceProvider as t };
@@ -1,155 +0,0 @@
1
- type BaseOptions = {
2
- /**
3
- Number of concurrently pending promises returned by `mapper`.
4
-
5
- Must be an integer from 1 and up or `Infinity`.
6
-
7
- @default Infinity
8
- */
9
- readonly concurrency?: number;
10
- };
11
-
12
- export type Options = BaseOptions & {
13
- /**
14
- When `true`, the first mapper rejection will be rejected back to the consumer.
15
-
16
- When `false`, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an [`AggregateError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError) containing all the errors from the rejected promises.
17
-
18
- Caveat: When `true`, any already-started async mappers will continue to run until they resolve or reject. In the case of infinite concurrency with sync iterables, *all* mappers are invoked on startup and will continue after the first rejection. Use the `signal` option for abort control.
19
-
20
- @default true
21
- */
22
- readonly stopOnError?: boolean;
23
-
24
- /**
25
- You can abort the promises using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
26
-
27
- @example
28
- ```
29
- import pMap from 'p-map';
30
- import delay from 'delay';
31
-
32
- const abortController = new AbortController();
33
-
34
- setTimeout(() => {
35
- abortController.abort();
36
- }, 500);
37
-
38
- const mapper = async value => value;
39
-
40
- await pMap([delay(1000), delay(1000)], mapper, {signal: abortController.signal});
41
- // Throws AbortError (DOMException) after 500 ms.
42
- ```
43
- */
44
- readonly signal?: AbortSignal | undefined;
45
- };
46
-
47
- export type IterableOptions = BaseOptions & {
48
- /**
49
- Maximum number of promises returned by `mapper` that have resolved but not yet collected by the consumer of the async iterable. Calls to `mapper` will be limited so that there is never too much backpressure.
50
-
51
- Useful whenever you are consuming the iterable slower than what the mapper function can produce concurrently. For example, to avoid making an overwhelming number of HTTP requests if you are saving each of the results to a database.
52
-
53
- Default: `options.concurrency`
54
- */
55
- readonly backpressure?: number;
56
- };
57
-
58
- type MaybePromise<T> = T | Promise<T>;
59
-
60
- /**
61
- Function which is called for every item in `input`. Expected to return a `Promise` or value.
62
-
63
- @param element - Iterated element.
64
- @param index - Index of the element in the source array.
65
- */
66
- export type Mapper<Element = any, NewElement = unknown> = (
67
- element: Element,
68
- index: number
69
- ) => MaybePromise<NewElement | typeof pMapSkip>;
70
-
71
- /**
72
- @param input - Synchronous or asynchronous iterable that is iterated over concurrently, calling the `mapper` function for each element. Each iterated item is `await`'d before the `mapper` is invoked so the iterable may return a `Promise` that resolves to an item. Asynchronous iterables (different from synchronous iterables that return `Promise` that resolves to an item) can be used when the next item may not be ready without waiting for an asynchronous process to complete and/or the end of the iterable may be reached after the asynchronous process completes. For example, reading from a remote queue when the queue has reached empty, or reading lines from a stream.
73
- @param mapper - Function which is called for every item in `input`. Expected to return a `Promise` or value.
74
- @returns A `Promise` that is fulfilled when all promises in `input` and the ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. The fulfilled value is an `Array` of the fulfilled values returned from `mapper` in `input` order.
75
-
76
- @example
77
- ```
78
- import pMap from 'p-map';
79
- import got from 'got';
80
-
81
- const sites = [
82
- getWebsiteFromUsername('sindresorhus'), //=> Promise
83
- 'https://avajs.dev',
84
- 'https://github.com'
85
- ];
86
-
87
- const mapper = async site => {
88
- const {requestUrl} = await got.head(site);
89
- return requestUrl;
90
- };
91
-
92
- const result = await pMap(sites, mapper, {concurrency: 2});
93
-
94
- console.log(result);
95
- //=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
96
- ```
97
- */
98
- export default function pMap<Element, NewElement>(
99
- input: AsyncIterable<Element | Promise<Element>> | Iterable<Element | Promise<Element>>,
100
- mapper: Mapper<Element, NewElement>,
101
- options?: Options
102
- ): Promise<Array<Exclude<NewElement, typeof pMapSkip>>>;
103
-
104
- /**
105
- @param input - Synchronous or asynchronous iterable that is iterated over concurrently, calling the `mapper` function for each element. Each iterated item is `await`'d before the `mapper` is invoked so the iterable may return a `Promise` that resolves to an item. Asynchronous iterables (different from synchronous iterables that return `Promise` that resolves to an item) can be used when the next item may not be ready without waiting for an asynchronous process to complete and/or the end of the iterable may be reached after the asynchronous process completes. For example, reading from a remote queue when the queue has reached empty, or reading lines from a stream.
106
- @param mapper - Function which is called for every item in `input`. Expected to return a `Promise` or value.
107
- @returns An async iterable that streams each return value from `mapper` in order.
108
-
109
- @example
110
- ```
111
- import {pMapIterable} from 'p-map';
112
-
113
- // Multiple posts are fetched concurrently, with limited concurrency and backpressure
114
- for await (const post of pMapIterable(postIds, getPostMetadata, {concurrency: 8})) {
115
- console.log(post);
116
- };
117
- ```
118
- */
119
- export function pMapIterable<Element, NewElement>(
120
- input: AsyncIterable<Element | Promise<Element>> | Iterable<Element | Promise<Element>>,
121
- mapper: Mapper<Element, NewElement>,
122
- options?: IterableOptions
123
- ): AsyncIterable<Exclude<NewElement, typeof pMapSkip>>;
124
-
125
- /**
126
- Return this value from a `mapper` function to skip including the value in the returned array.
127
-
128
- @example
129
- ```
130
- import pMap, {pMapSkip} from 'p-map';
131
- import got from 'got';
132
-
133
- const sites = [
134
- getWebsiteFromUsername('sindresorhus'), //=> Promise
135
- 'https://avajs.dev',
136
- 'https://example.invalid',
137
- 'https://github.com'
138
- ];
139
-
140
- const mapper = async site => {
141
- try {
142
- const {requestUrl} = await got.head(site);
143
- return requestUrl;
144
- } catch {
145
- return pMapSkip;
146
- }
147
- };
148
-
149
- const result = await pMap(sites, mapper, {concurrency: 2});
150
-
151
- console.log(result);
152
- //=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
153
- ```
154
- */
155
- export const pMapSkip: unique symbol;