@openclaw/discord 2026.11.7 → 2026.11.10-beta.2

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 (124) hide show
  1. package/README.md +37 -0
  2. package/dist/.setup/{account-inspect-DGkdWwix.mjs → account-inspect-CSz5Qodj.mjs} +2 -3
  3. package/dist/.setup/{accounts-C_25wyxC.mjs → accounts-DtjvhJUj.mjs} +4 -8
  4. package/dist/.setup/{active-turn-thread-route-KvRTAVE3.mjs → active-turn-thread-route-DkPnk2x8.mjs} +1 -2
  5. package/dist/.setup/{allow-list-C3j0qLDp.mjs → allow-list-CkqpzPvP.mjs} +4 -8
  6. package/dist/.setup/{api-DYRggUgK.mjs → api-C4j_kC-2.mjs} +4 -6
  7. package/dist/.setup/{approval-handler.runtime-BN4W1r0o.mjs → approval-handler.runtime-DXzPFNvC.mjs} +10 -10
  8. package/dist/.setup/{approval-message-updates-DKsCfxSW.mjs → approval-message-updates-DqOXxPss.mjs} +3 -4
  9. package/dist/.setup/{audit-BL6EoUun.mjs → audit-B9vk3V2z.mjs} +6 -7
  10. package/dist/.setup/{channel-DdI2l55_.mjs → channel-CKffiPiV.mjs} +38 -41
  11. package/dist/.setup/{channel-access-9cyzozUP.mjs → channel-access-DhJhVrdZ.mjs} +1 -2
  12. package/dist/.setup/{channel.setup-kNWMxlgu.mjs → channel.setup-DmGdG9BH.mjs} +7 -10
  13. package/dist/.setup/{command-deploy-store-DFkBTViB.mjs → command-deploy-store-DPWiBMks.mjs} +1 -2
  14. package/dist/.setup/{command-owners-C7rUdqUX.mjs → command-owners-BzlhNBxA.mjs} +1 -2
  15. package/dist/.setup/{components-C1Phe3uw.mjs → components-GePlato3.mjs} +10 -16
  16. package/dist/.setup/{components.base-CiS0h_XP.mjs → components.base-C5sAPHe4.mjs} +1 -2
  17. package/dist/.setup/config-DDwcUaxT.mjs +20 -0
  18. package/dist/.setup/{config-schema-BNKN1cu5.mjs → config-schema-D3M1livr.mjs} +5 -7
  19. package/dist/.setup/{conversation-binding-route-K_jFbvi5.mjs → conversation-binding-route-CAaWWJdQ.mjs} +2 -3
  20. package/dist/.setup/conversation-fork-B6PiUuln.mjs +197 -0
  21. package/dist/.setup/{directory-config-Ble81PWH.mjs → directory-config-BXJuh9-J.mjs} +3 -4
  22. package/dist/.setup/{directory-live-CY2-qrHI.mjs → directory-live-B9UoQG9g.mjs} +9 -64
  23. package/dist/.setup/{discord-BRVFhk09.mjs → discord-cXPUdHQi.mjs} +98 -77
  24. package/dist/.setup/{doctor-RqH-6JB0.mjs → doctor-MTAWTgRa.mjs} +7 -8
  25. package/dist/.setup/{doctor-contract-Bwv8EuQ_.mjs → doctor-contract-Dstl3cMg.mjs} +2 -3
  26. package/dist/.setup/{endpoint-runtime-lf4DeLas.mjs → endpoint-runtime-BM3x-m6O.mjs} +1 -2
  27. package/dist/.setup/{guilds-BSnrns-F.mjs → guilds-DYBhgnfq.mjs} +3 -4
  28. package/dist/.setup/{handle-action-uD87h2FK.mjs → handle-action-El1ok7Ak.mjs} +13 -12
  29. package/dist/.setup/{handle-action.guild-admin-CqBx_3mG.mjs → handle-action.guild-admin-CxYfg02j.mjs} +7 -5
  30. package/dist/.setup/identity-link-B7KOBo_l.mjs +74 -0
  31. package/dist/.setup/{listeners-DnHLrLIN.mjs → listeners-DIyynRvV.mjs} +2 -3
  32. package/dist/.setup/{live-policy-config-y0Qy36X3.mjs → live-policy-config-DjIHWFla.mjs} +3 -5
  33. package/dist/.setup/{message-handler-CWL_u0X8.mjs → message-handler-DP3cAQCZ.mjs} +18 -17
  34. package/dist/.setup/{message-handler.preflight-83tpEdBG.mjs → message-handler.preflight-S5yc9UdR.mjs} +20 -27
  35. package/dist/.setup/{message-handler.preflight-pluralkit-Dhcx7Ifz.mjs → message-handler.preflight-pluralkit-BFntgVKc.mjs} +10 -14
  36. package/dist/.setup/{message-handler.process-BC-wNZwK.mjs → message-handler.process-bXE_4sq5.mjs} +56 -67
  37. package/dist/.setup/oauth-http-DdVyzSbo.mjs +40 -0
  38. package/dist/.setup/{outbound-payload-CK3_bDvK.mjs → outbound-payload-Dh6xCO6z.mjs} +18 -13
  39. package/dist/.setup/{outbound-session-route-Ay_DnOOl.mjs → outbound-session-route-G_fK5RAh.mjs} +22 -34
  40. package/dist/.setup/{output-activity-uBpMSX75.mjs → output-activity-CDgs2s3O.mjs} +1 -2
  41. package/dist/.setup/{pluralkit-B64dfq_j.mjs → pluralkit-DcXbHTpQ.mjs} +2 -3
  42. package/dist/.setup/{preflight-audio-C6QtD6HX.mjs → preflight-audio-r4BbaJxh.mjs} +1 -2
  43. package/dist/.setup/{presence-cache-Dq-3nH7R.mjs → presence-cache-B3xj3b0l.mjs} +1 -2
  44. package/dist/.setup/{probe-CbDJojNV.mjs → probe-CfGMZwFD.mjs} +5 -6
  45. package/dist/.setup/{provider-CRb3Myky.mjs → provider-BA4ysXXm.mjs} +200 -249
  46. package/dist/.setup/{provider-session.runtime-3cZpps3H.mjs → provider-session.runtime-Cr2oPicL.mjs} +3 -3
  47. package/dist/.setup/provider.runtime-D4BlQKDq.mjs +1 -0
  48. package/dist/.setup/{proxy-fetch-BzXwBAXt.mjs → proxy-fetch-B8cK6FLQ.mjs} +1 -2
  49. package/dist/.setup/{realtime-session.runtime-BRYpjS9P.mjs → realtime-session.runtime-DQvAKxj9.mjs} +15 -25
  50. package/dist/.setup/{receive-recovery-C3Ks4wAQ.mjs → receive-recovery-DV_v5ROf.mjs} +3 -6
  51. package/dist/.setup/{resolve-allowlist-common-B-S0wRIw.mjs → resolve-allowlist-common-CYdqBUgV.mjs} +3 -4
  52. package/dist/.setup/{resolve-channels-g16NM6Ho.mjs → resolve-channels-BNnyfCR8.mjs} +6 -7
  53. package/dist/.setup/{resolve-users-DAfOOXdy.mjs → resolve-users-CDMAGrzv.mjs} +5 -6
  54. package/dist/.setup/{rolldown-runtime-B4FMCO8f.mjs → rolldown-runtime-nwUcYXjP.mjs} +1 -2
  55. package/dist/.setup/{runtime--HZ9r3tF.mjs → runtime-CkeNX7ic.mjs} +59 -50
  56. package/dist/.setup/{runtime-BMgTyuwg.mjs → runtime-DSaHEGJd.mjs} +4 -24
  57. package/dist/.setup/{runtime-DgnVQ7zW.mjs → runtime-DcBvHOm1.mjs} +1 -2
  58. package/dist/.setup/{runtime-doctor-migrations-BPV-R4G9.mjs → runtime-doctor-migrations-BpV1jKk0.mjs} +5 -9
  59. package/dist/.setup/{secret-config-contract-B1kE4sDv.mjs → secret-config-contract-CP6teHec.mjs} +1 -2
  60. package/dist/.setup/{security-audit-BFT84Uny.mjs → security-audit-CTwisG7c.mjs} +3 -4
  61. package/dist/.setup/{security-contract-DNyyjTZZ.mjs → security-contract-D-o0iWDk.mjs} +1 -2
  62. package/dist/.setup/{security-doctor-nGgPm65L.mjs → security-doctor-4s7omTZd.mjs} +1 -2
  63. package/dist/.setup/{send-CtvwfZQ2.mjs → send-DKzwsZkm.mjs} +26 -31
  64. package/dist/.setup/{send.components-CtLtE0yD.mjs → send.components-CIZALYDP.mjs} +12 -14
  65. package/dist/.setup/{send.outbound-D58xXPgs.mjs → send.outbound-cQ4Ohmsc.mjs} +11 -16
  66. package/dist/.setup/send.permissions-BvH_Dr8p.mjs +369 -0
  67. package/dist/.setup/{send.receipt-DLOV4qx6.mjs → send.receipt-CZ7ks6g7.mjs} +64 -17
  68. package/dist/.setup/send.shared-D2lh737v.mjs +259 -0
  69. package/dist/.setup/{sender-identity-BbA7FNbr.mjs → sender-identity-Dt5ELjRN.mjs} +2 -3
  70. package/dist/.setup/{session-contract-BO5tlIdl.mjs → session-contract-Bq71MS78.mjs} +1 -2
  71. package/dist/.setup/{session-key-normalization-CCHGNSQw.mjs → session-key-normalization-Cfvze5hd.mjs} +1 -2
  72. package/dist/.setup/setup-plugin-api-BJt8tAAC.mjs +2 -0
  73. package/dist/.setup/{shared-Dv2DamaK.mjs → shared-Bf7ifHlc.mjs} +14 -17
  74. package/dist/.setup/{shared-interactive-DmzaoKOM.mjs → shared-interactive-DKBw4SNV.mjs} +7 -12
  75. package/dist/.setup/{subagent-hooks-yT45eTyz.mjs → subagent-hooks-CVmIOrAR.mjs} +4 -5
  76. package/dist/.setup/{system-events-Dlzp9Jcj.mjs → system-events-DB6p2H4l.mjs} +3 -4
  77. package/dist/.setup/{target-parsing-C-HyNxcE.mjs → target-parsing-BiuhcK9Q.mjs} +1 -2
  78. package/dist/.setup/{target-resolver-BzaZPBm9.mjs → target-resolver-48znkzky.mjs} +6 -7
  79. package/dist/.setup/{thread-binding-api-BDZJD4na.mjs → thread-binding-api-Drd4Zu-5.mjs} +1 -2
  80. package/dist/.setup/{thread-bindings-DRWhgKCc.mjs → thread-bindings-DTHVdmvF.mjs} +7 -10
  81. package/dist/.setup/{thread-bindings.manager-CWJKirn1.mjs → thread-bindings.manager-6EnH3YZh.mjs} +45 -30
  82. package/dist/.setup/{thread-bindings.session-updates-DzJrXc4w.mjs → thread-bindings.session-updates-BPO6pPzd.mjs} +9 -12
  83. package/dist/.setup/{threading-BbsPuT5G.mjs → threading-PC3IIaHd.mjs} +5 -7
  84. package/dist/.setup/{timeouts-cIxzatmv.mjs → timeouts-CT9hnmo4.mjs} +1 -2
  85. package/dist/.setup/{transcripts-source-DIW1fU_P.mjs → transcripts-source-C3F_ErM1.mjs} +20 -33
  86. package/dist/.setup/{typing-CNlSKY5S.mjs → typing-DAv4S2fI.mjs} +2 -3
  87. package/dist/.setup/{voice-runtime-oJ6BZs5D.mjs → voice-runtime-CZGbraKC.mjs} +28 -46
  88. package/dist/.source-module-urls/d6c089460280c5a04184542d6712e04545caeb1ebb290d3504377b4cc5e22fea.json +1 -1
  89. package/dist/account-inspect-api.js +2 -3
  90. package/dist/action-runtime-api.js +1 -1
  91. package/dist/activities-api.js +10 -50
  92. package/dist/api.js +21 -22
  93. package/dist/assets/embedded-app-sdk.mjs +1 -1
  94. package/dist/channel-config-api.js +1 -1
  95. package/dist/channel-plugin-api.js +1 -1
  96. package/dist/contract-api.js +1 -1
  97. package/dist/directory-contract-api.js +2 -3
  98. package/dist/doctor-contract-api.js +7 -8
  99. package/dist/index.js +1 -2
  100. package/dist/runtime-api.js +23 -22
  101. package/dist/runtime-setter-api.js +1 -1
  102. package/dist/secret-contract-api.js +1 -1
  103. package/dist/security-audit-contract-api.js +1 -1
  104. package/dist/security-contract-api.js +1 -1
  105. package/dist/session-key-api.js +1 -1
  106. package/dist/setup-entry.js +2 -3
  107. package/dist/setup-plugin-api.js +1 -1
  108. package/dist/src/voice/audio-worker.runtime.js +14 -26
  109. package/dist/subagent-hooks-api.js +2 -3
  110. package/dist/thread-binding-api.js +1 -1
  111. package/dist/transcripts-source-api.js +2 -3
  112. package/node_modules/@discord/embedded-app-sdk/output/lib/zod/lib/index.cjs +2 -3
  113. package/node_modules/@discord/embedded-app-sdk/output/lib/zod/lib/index.mjs +2 -3
  114. package/node_modules/@types/node/README.md +1 -1
  115. package/node_modules/@types/node/package.json +2 -2
  116. package/node_modules/@types/node/zlib.d.ts +752 -0
  117. package/node_modules/typebox/build/format/date_time.d.mts +2 -1
  118. package/node_modules/typebox/build/format/date_time.mjs +12 -3
  119. package/node_modules/typebox/package.json +1 -1
  120. package/openclaw.plugin.json +7 -2
  121. package/package.json +5 -5
  122. package/dist/.setup/provider.runtime-tmkt3QOg.mjs +0 -1
  123. package/dist/.setup/send.shared-B_KKRrD7.mjs +0 -589
  124. package/dist/.setup/setup-plugin-api-ty5RJrMy.mjs +0 -2
@@ -0,0 +1,20 @@
1
+ import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
2
+ // extensions/discord/src/activities/config.ts
3
+ function resolveDiscordActivitiesConfig(account, env = process.env) {
4
+ if (!account.activities) return {
5
+ enabled: false,
6
+ reason: "not-configured"
7
+ };
8
+ const clientSecret = normalizeOptionalString(account.activities.clientSecret) ?? normalizeOptionalString(env.DISCORD_CLIENT_SECRET);
9
+ if (!clientSecret) return {
10
+ enabled: false,
11
+ reason: "missing-client-secret"
12
+ };
13
+ const applicationId = normalizeOptionalString(account.activities.applicationId);
14
+ return {
15
+ enabled: true,
16
+ clientSecret,
17
+ ...applicationId ? { applicationId } : {}
18
+ };
19
+ }
20
+ export { resolveDiscordActivitiesConfig as t };
@@ -1,11 +1,11 @@
1
- import { t as runtime_doctor_migrations_exports } from "./runtime-doctor-migrations-BPV-R4G9.mjs";
1
+ import { t as runtime_doctor_migrations_exports } from "./runtime-doctor-migrations-BpV1jKk0.mjs";
2
2
  import { buildSecretInputSchema, registerSensitiveConfigSchema } from "openclaw/plugin-sdk/secret-input";
3
3
  import { normalizeLegacyDmAliases } from "openclaw/plugin-sdk/channel-config-helpers";
4
4
  import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
5
5
  import { createChannelConfigUiHints } from "openclaw/plugin-sdk/channel-core";
6
6
  import { ChannelBotLoopProtectionSchema, ChannelDangerouslyAllowNameMatchingSchema, ChannelPreviewStreamingConfigSchema, ChannelThreadBindingsSchema, ProviderCommandsSchema, TtsConfigSchema, buildChannelAccountSchemaParts, buildChannelAllowBotsSchema, buildChannelConfigSchema, buildChannelExecApprovalsSchema, buildChannelReactionShape, buildGroupEntrySchema, refineChannelDmPolicy } from "openclaw/plugin-sdk/channel-config-schema";
7
7
  import { z } from "zod";
8
- //#region extensions/discord/src/config-ui-hints.ts
8
+ // extensions/discord/src/config-ui-hints.ts
9
9
  const discordChannelConfigUiHints = {
10
10
  "": {
11
11
  label: "Discord",
@@ -65,7 +65,7 @@ const discordChannelConfigUiHints = {
65
65
  },
66
66
  "thread.inheritParent": {
67
67
  label: "Discord Thread Parent Inheritance",
68
- help: "If true, Discord thread sessions inherit the parent channel transcript (default: false)."
68
+ help: "If true, Discord thread sessions inherit the parent channel chat history (default: false)."
69
69
  },
70
70
  "threadBindings.enabled": {
71
71
  label: "Discord Thread Binding Enabled",
@@ -85,7 +85,7 @@ const discordChannelConfigUiHints = {
85
85
  },
86
86
  "threadBindings.defaultSpawnContext": {
87
87
  label: "Discord Thread Spawn Context",
88
- help: "Default native subagent context for thread-bound spawns. \"fork\" starts from the requester transcript; \"isolated\" starts clean. Default: \"fork\"."
88
+ help: "Default native subagent context for thread-bound spawns. \"fork\" starts from the requester chat history; \"isolated\" starts clean. Default: \"fork\"."
89
89
  },
90
90
  "agentComponents.ttlMs": {
91
91
  label: "Discord Component TTL (ms)",
@@ -335,8 +335,7 @@ const discordChannelConfigUiHints = {
335
335
  help: "Optional Activity application ID. Defaults to the bot application ID learned at gateway startup."
336
336
  }
337
337
  };
338
- //#endregion
339
- //#region extensions/discord/src/config-schema.ts
338
+ // extensions/discord/src/config-schema.ts
340
339
  const SecretInputSchema = buildSecretInputSchema();
341
340
  const DiscordIdSchema = z.union([z.string(), z.number()]).transform((value, ctx) => {
342
341
  if (typeof value === "number") {
@@ -638,5 +637,4 @@ const DiscordConfigSchemaBase = DiscordAccountSchemaBase.safeExtend({
638
637
  });
639
638
  const DiscordConfigSchema = z.preprocess(normalizeShippedDiscordDmAliases, DiscordConfigSchemaBase);
640
639
  const DiscordChannelConfigSchema = buildChannelConfigSchema(DiscordConfigSchema, { uiHints: discordChannelConfigUiHints });
641
- //#endregion
642
640
  export { DiscordChannelConfigSchema as t };
@@ -1,7 +1,7 @@
1
- import { g as shouldIgnoreStaleDiscordRouteBinding } from "./outbound-session-route-Ay_DnOOl.mjs";
1
+ import { g as shouldIgnoreStaleDiscordRouteBinding } from "./outbound-session-route-G_fK5RAh.mjs";
2
2
  import { logVerbose } from "openclaw/plugin-sdk/runtime-env";
3
3
  import { inspectRuntimeConversationBindingRoute, resolveConfiguredBindingRoute, resolveRuntimeConversationBindingRouteAsync } from "openclaw/plugin-sdk/conversation-binding-runtime";
4
- //#region extensions/discord/src/monitor/conversation-binding-route.ts
4
+ // extensions/discord/src/monitor/conversation-binding-route.ts
5
5
  function prepareDiscordBindingRoute(params) {
6
6
  let baseRoute;
7
7
  return {
@@ -64,5 +64,4 @@ function applyDiscordBindingRoute(params, resolvedRuntimeRoute, baseRoute) {
64
64
  configuredRoute
65
65
  };
66
66
  }
67
- //#endregion
68
67
  export { resolveDiscordConversationBindingRouteAsync as n, resolveDiscordConversationBindingRoute as t };
@@ -0,0 +1,197 @@
1
+ import { i as listDiscordAccountIds, l as resolveDiscordAccount, r as isDiscordAccountEnabledForRuntime } from "./accounts-DtjvhJUj.mjs";
2
+ import { d as createDiscordRestClient, o as fetchThreadForkPermissionsDiscord, r as canViewDiscordGuildChannel } from "./send.permissions-BvH_Dr8p.mjs";
3
+ import { A as getThreadMember, O as getChannel, T as createThread, q as withDiscordRequestAuthority } from "./discord-cXPUdHQi.mjs";
4
+ import { v as classifyDiscordDeliveryFailure } from "./send.receipt-CZ7ks6g7.mjs";
5
+ import { n as resolveDiscordChannelId } from "./target-parsing-BiuhcK9Q.mjs";
6
+ import { createRuntimeConfigReader } from "openclaw/plugin-sdk/runtime-config-snapshot";
7
+ import { ChannelFlags, ChannelType, Routes } from "discord-api-types/v10";
8
+ import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
9
+ import { getSessionBindingService } from "openclaw/plugin-sdk/conversation-binding-runtime";
10
+ import { isDeepStrictEqual } from "node:util";
11
+ // extensions/discord/src/conversation-fork.ts
12
+ /** Native placement only: core owns transcript copying and excerpt selection. */
13
+ const prepareDiscordConversationFork = async (params) => {
14
+ const sourceId = params.source.conversationId;
15
+ const senderId = params.senderId;
16
+ if (!params.isGroup || !/^\d+$/u.test(sourceId) || !senderId || !/^\d+$/u.test(senderId)) return {
17
+ ok: false,
18
+ reason: "Discord /fork requires an existing server thread or forum post and an identified requester."
19
+ };
20
+ if (params.source.threadId && params.source.threadId !== sourceId) return {
21
+ ok: false,
22
+ reason: "Discord fork source does not match the current native thread."
23
+ };
24
+ let expectedParentId;
25
+ try {
26
+ expectedParentId = params.source.parentConversationId ? resolveDiscordChannelId(params.source.parentConversationId) : void 0;
27
+ } catch {
28
+ return {
29
+ ok: false,
30
+ reason: "Discord fork parent channel is invalid."
31
+ };
32
+ }
33
+ const readConfig = createRuntimeConfigReader(params.cfg);
34
+ const cfg = readConfig();
35
+ const account = resolveDiscordAccount({
36
+ cfg,
37
+ accountId: params.accountId
38
+ });
39
+ if (!listDiscordAccountIds(cfg).includes(account.accountId) || !isDiscordAccountEnabledForRuntime(account, cfg) || !account.token) return {
40
+ ok: false,
41
+ reason: "The selected Discord bot account is disabled or unavailable."
42
+ };
43
+ const assertCurrent = () => {
44
+ params.signal?.throwIfAborted();
45
+ params.assertCurrent();
46
+ const currentCfg = readConfig();
47
+ const current = resolveDiscordAccount({
48
+ cfg: currentCfg,
49
+ accountId: account.accountId
50
+ });
51
+ if (!listDiscordAccountIds(currentCfg).includes(account.accountId) || !isDiscordAccountEnabledForRuntime(current, currentCfg) || current.token !== account.token || !isDeepStrictEqual(current.config, account.config)) throw new Error("Discord fork account changed. Run /fork again with the current account.");
52
+ };
53
+ const opts = {
54
+ cfg: params.cfg,
55
+ accountId: account.accountId,
56
+ signal: params.signal
57
+ };
58
+ const rest = createDiscordRestClient(opts).rest;
59
+ const service = getSessionBindingService();
60
+ const assertBindingSupported = () => {
61
+ assertCurrent();
62
+ const capabilities = service.getCapabilities({
63
+ channel: "discord",
64
+ accountId: account.accountId
65
+ });
66
+ if (!capabilities.adapterAvailable || !capabilities.bindSupported || !capabilities.placements.includes("current")) throw new Error("Discord thread bindings are unavailable. Enable thread bindings for this bot account before using /fork.");
67
+ };
68
+ const qualify = async () => {
69
+ assertBindingSupported();
70
+ const source = await getChannel(rest, sourceId);
71
+ assertCurrent();
72
+ if (source.type !== ChannelType.PublicThread && source.type !== ChannelType.PrivateThread) throw new Error("Discord /fork supports existing text threads and forum posts, not DMs, unthreaded channels, announcement threads, or media posts.");
73
+ const parentId = source.parent_id;
74
+ const guildId = source.guild_id;
75
+ if (!parentId || !guildId || expectedParentId && expectedParentId !== parentId) throw new Error("Discord could not verify the source thread's parent server channel.");
76
+ const parent = await getChannel(rest, parentId);
77
+ assertCurrent();
78
+ if (parent.type !== ChannelType.GuildText && parent.type !== ChannelType.GuildForum || parent.guild_id !== guildId || source.type === ChannelType.PrivateThread && parent.type !== ChannelType.GuildText) throw new Error("Discord /fork supports text-channel threads and forum posts only; media and announcement parents are not supported.");
79
+ const { requesterCanRead, botPermissions } = await fetchThreadForkPermissionsDiscord(guildId, source, parent, senderId, {
80
+ ...opts,
81
+ rest
82
+ });
83
+ assertCurrent();
84
+ if (!requesterCanRead) throw new Error("Discord could not confirm your access to the source thread, its message history, and its parent channel.");
85
+ if ([
86
+ "ViewChannel",
87
+ "ReadMessageHistory",
88
+ "SendMessagesInThreads",
89
+ source.type === ChannelType.PrivateThread ? "CreatePrivateThreads" : parent.type === ChannelType.GuildForum ? "SendMessages" : "CreatePublicThreads"
90
+ ].some((permission) => !botPermissions.includes(permission))) throw new Error("The Discord bot needs View Channel, Read Message History, Send Messages in Threads, and permission to create this kind of thread or forum post in the parent channel.");
91
+ const tags = parent.type === ChannelType.GuildForum ? (source.applied_tags ?? []).filter((id) => parent.available_tags.some((tag) => tag.id === id && (!tag.moderated || botPermissions.includes("ManageThreads")))).slice(0, 5) : [];
92
+ if (parent.type === ChannelType.GuildForum && ((parent.flags ?? 0) & ChannelFlags.RequireTag) !== 0 && tags.length === 0) throw new Error("This Discord forum requires a tag, but no source tag can be reused. Add an available tag to the source post before forking.");
93
+ return {
94
+ source,
95
+ parent,
96
+ parentId,
97
+ guildId,
98
+ tags
99
+ };
100
+ };
101
+ let prepared;
102
+ try {
103
+ prepared = await withDiscordRequestAuthority(assertCurrent, qualify);
104
+ } catch (error) {
105
+ assertCurrent();
106
+ return {
107
+ ok: false,
108
+ reason: error instanceof Error ? error.message : "Discord could not verify this fork source."
109
+ };
110
+ }
111
+ let attempted = false;
112
+ return {
113
+ ok: true,
114
+ assertCurrent,
115
+ formatRecap: (text) => {
116
+ const literal = text.replace(/@/gu, "@​").replace(/</gu, "‹");
117
+ const runs = literal.match(/`+/gu) ?? [];
118
+ const fence = "`".repeat(Math.max(3, ...runs.map((run) => run.length + 1)));
119
+ return {
120
+ text: [
121
+ fence,
122
+ literal,
123
+ fence
124
+ ].join("\n"),
125
+ channelData: { discord: { literalText: true } }
126
+ };
127
+ },
128
+ create: async (targetSessionKey) => {
129
+ assertCurrent();
130
+ if (attempted) throw new Error("This Discord fork creation was already attempted. Inspect the parent channel before running /fork again.");
131
+ attempted = true;
132
+ const fresh = await withDiscordRequestAuthority(assertCurrent, qualify);
133
+ assertCurrent();
134
+ if (fresh.source.type !== prepared.source.type || fresh.parentId !== prepared.parentId || fresh.guildId !== prepared.guildId) throw new Error("The Discord fork source changed while copying the session. No sibling was created.");
135
+ const name = truncateUtf16Safe((params.title?.trim() || "Fork: " + fresh.source.name).replace(/[\r\n\t]/gu, " "), 100);
136
+ const privateThread = fresh.source.type === ChannelType.PrivateThread;
137
+ const forum = fresh.parent.type === ChannelType.GuildForum;
138
+ const body = {
139
+ name,
140
+ ...fresh.parent.default_auto_archive_duration !== void 0 ? { auto_archive_duration: fresh.parent.default_auto_archive_duration } : {},
141
+ ...forum ? {
142
+ message: {
143
+ content: "Forked conversation. Context follows.",
144
+ allowed_mentions: { parse: [] }
145
+ },
146
+ ...fresh.tags.length ? { applied_tags: fresh.tags } : {}
147
+ } : {
148
+ type: fresh.source.type,
149
+ ...privateThread ? { invitable: false } : {}
150
+ }
151
+ };
152
+ let created;
153
+ assertBindingSupported();
154
+ try {
155
+ created = await withDiscordRequestAuthority(assertCurrent, () => createThread(rest, fresh.parentId, { body }));
156
+ } catch (error) {
157
+ const outcome = classifyDiscordDeliveryFailure(error);
158
+ throw new Error(outcome === "rejected" || outcome === "pre-connect" ? "Discord did not create the fork. Check bot permissions and the parent channel's thread requirements." : "Discord fork creation is uncertain; a sibling may exist. Inspect the parent channel before retrying. No automatic retry was made.", { cause: error });
159
+ }
160
+ const url = /^\d+$/u.test(created.id ?? "") ? "https://discord.com/channels/" + fresh.guildId + "/" + created.id : void 0;
161
+ try {
162
+ assertCurrent();
163
+ if (!url || created.id === sourceId || created.id === fresh.parentId || created.parent_id !== fresh.parentId || created.guild_id !== fresh.guildId || created.type !== fresh.source.type || privateThread && created.thread_metadata?.invitable !== false) throw new Error("Discord did not confirm the expected sibling placement and privacy.");
164
+ if (privateThread) await withDiscordRequestAuthority(assertCurrent, async () => {
165
+ await rest.put(Routes.threadMembers(created.id, senderId));
166
+ assertCurrent();
167
+ const member = await getThreadMember(rest, created.id, senderId);
168
+ assertCurrent();
169
+ if (member.user_id !== senderId || !await canViewDiscordGuildChannel(fresh.guildId, created.id, senderId, opts)) throw new Error("Discord could not confirm requester access to the private fork.");
170
+ });
171
+ assertCurrent();
172
+ const binding = await withDiscordRequestAuthority(assertCurrent, () => service.bind({
173
+ targetSessionKey,
174
+ targetKind: "session",
175
+ placement: "current",
176
+ conversation: {
177
+ channel: "discord",
178
+ accountId: account.accountId,
179
+ conversationId: created.id,
180
+ parentConversationId: fresh.parentId
181
+ },
182
+ metadata: { boundBy: senderId },
183
+ assertCurrent
184
+ }));
185
+ assertCurrent();
186
+ return {
187
+ binding,
188
+ url,
189
+ ...privateThread ? { notice: "Private fork: only you and the bot are added; other source members are not automatically included. Server members with Manage Threads may still have access. Member invitations are disabled." } : {}
190
+ };
191
+ } catch (error) {
192
+ throw new Error("Discord created a sibling" + (url ? " at " + url : " with an unverified identity") + ", but fork setup did not complete. No recap was sent. Inspect this sibling before retrying.", { cause: error });
193
+ }
194
+ }
195
+ };
196
+ };
197
+ export { prepareDiscordConversationFork };
@@ -1,8 +1,8 @@
1
- import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.mjs";
2
- import { c as resolveDefaultDiscordAccountId, s as mergeDiscordAccountConfig, u as resolveDiscordAccountAllowFrom } from "./accounts-C_25wyxC.mjs";
1
+ import { t as __exportAll } from "./rolldown-runtime-nwUcYXjP.mjs";
2
+ import { c as resolveDefaultDiscordAccountId, s as mergeDiscordAccountConfig, u as resolveDiscordAccountAllowFrom } from "./accounts-DtjvhJUj.mjs";
3
3
  import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
4
4
  import { createResolvedDirectoryEntriesLister } from "openclaw/plugin-sdk/directory-config-runtime";
5
- //#region extensions/discord/src/directory-config.ts
5
+ // extensions/discord/src/directory-config.ts
6
6
  var directory_config_exports = /* @__PURE__ */ __exportAll({
7
7
  listDiscordDirectoryGroupsFromConfig: () => listDiscordDirectoryGroupsFromConfig,
8
8
  listDiscordDirectoryPeersFromConfig: () => listDiscordDirectoryPeersFromConfig
@@ -42,5 +42,4 @@ const listDiscordDirectoryGroupsFromConfig = createResolvedDirectoryEntriesListe
42
42
  return /^\d+$/.test(cleaned) ? `channel:${cleaned}` : null;
43
43
  }
44
44
  });
45
- //#endregion
46
45
  export { listDiscordDirectoryGroupsFromConfig as n, listDiscordDirectoryPeersFromConfig as r, directory_config_exports as t };
@@ -1,65 +1,11 @@
1
- import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.mjs";
2
- import { h as normalizeDiscordToken, l as resolveDiscordAccount } from "./accounts-C_25wyxC.mjs";
3
- import { a as normalizeDiscordDisplaySlug } from "./allow-list-C3j0qLDp.mjs";
4
- import { t as DISCORD_DIRECTORY_LOOKUP_TIMEOUT_MS } from "./api-DYRggUgK.mjs";
5
- import { n as listGuilds, r as searchDiscordGuildMembers, t as listDiscordGuildChannels } from "./guilds-BSnrns-F.mjs";
6
- import { normalizeAccountId } from "openclaw/plugin-sdk/routing";
7
- import { normalizeOptionalLowercaseString, normalizeOptionalString, normalizeOptionalStringifiedId } from "openclaw/plugin-sdk/string-coerce-runtime";
8
- import { pruneMapToMaxSize } from "openclaw/plugin-sdk/collection-runtime";
9
- //#region extensions/discord/src/directory-cache-state.ts
10
- const discordDirectoryCacheState = { handlesByAccount: /* @__PURE__ */ new Map() };
11
- //#endregion
12
- //#region extensions/discord/src/directory-cache.ts
13
- const DISCORD_DIRECTORY_CACHE_MAX_ENTRIES = 4e3;
14
- const DISCORD_DISCRIMINATOR_SUFFIX = /#\d{4}$/;
15
- function normalizeDiscordSnowflake(value) {
16
- const text = normalizeOptionalStringifiedId(value) ?? "";
17
- if (!/^\d+$/.test(text)) return null;
18
- return text;
19
- }
20
- function normalizeDiscordHandleKey(raw) {
21
- let handle = normalizeOptionalString(raw) ?? "";
22
- if (!handle) return null;
23
- if (handle.startsWith("@")) handle = normalizeOptionalString(handle.slice(1)) ?? "";
24
- if (!handle || /\s/.test(handle)) return null;
25
- return handle.toLowerCase();
26
- }
27
- function ensureAccountCache(accountId) {
28
- const cacheKey = normalizeAccountId(accountId);
29
- const existing = discordDirectoryCacheState.handlesByAccount.get(cacheKey);
30
- if (existing) return existing;
31
- const created = /* @__PURE__ */ new Map();
32
- discordDirectoryCacheState.handlesByAccount.set(cacheKey, created);
33
- return created;
34
- }
35
- function setCacheEntry(cache, key, userId) {
36
- const previous = cache.get(key);
37
- cache.delete(key);
38
- cache.set(key, previous === void 0 || previous === userId ? userId : null);
39
- pruneMapToMaxSize(cache, DISCORD_DIRECTORY_CACHE_MAX_ENTRIES);
40
- }
41
- function rememberDiscordDirectoryUser(params) {
42
- const userId = normalizeDiscordSnowflake(params.userId);
43
- if (!userId) return;
44
- const cache = ensureAccountCache(params.accountId);
45
- for (const candidate of params.handles) {
46
- if (typeof candidate !== "string") continue;
47
- const handle = normalizeDiscordHandleKey(candidate);
48
- if (!handle) continue;
49
- setCacheEntry(cache, handle, userId);
50
- const withoutDiscriminator = handle.replace(DISCORD_DISCRIMINATOR_SUFFIX, "");
51
- if (withoutDiscriminator && withoutDiscriminator !== handle) setCacheEntry(cache, withoutDiscriminator, userId);
52
- }
53
- }
54
- function resolveDiscordDirectoryUserId(params) {
55
- const cache = discordDirectoryCacheState.handlesByAccount.get(normalizeAccountId(params.accountId));
56
- if (!cache) return;
57
- const handle = normalizeDiscordHandleKey(params.handle);
58
- if (!handle) return;
59
- return cache.get(handle) ?? void 0;
60
- }
61
- //#endregion
62
- //#region extensions/discord/src/directory-live.ts
1
+ import { t as __exportAll } from "./rolldown-runtime-nwUcYXjP.mjs";
2
+ import { h as normalizeDiscordToken, l as resolveDiscordAccount } from "./accounts-DtjvhJUj.mjs";
3
+ import { a as normalizeDiscordDisplaySlug } from "./allow-list-CkqpzPvP.mjs";
4
+ import { f as rememberDiscordDirectoryUser } from "./send.receipt-CZ7ks6g7.mjs";
5
+ import { t as DISCORD_DIRECTORY_LOOKUP_TIMEOUT_MS } from "./api-C4j_kC-2.mjs";
6
+ import { n as listGuilds, r as searchDiscordGuildMembers, t as listDiscordGuildChannels } from "./guilds-DYBhgnfq.mjs";
7
+ import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/string-coerce-runtime";
8
+ // extensions/discord/src/directory-live.ts
63
9
  var directory_live_exports = /* @__PURE__ */ __exportAll({
64
10
  listDiscordDirectoryGroupsLive: () => listDiscordDirectoryGroupsLive,
65
11
  listDiscordDirectoryPeersLive: () => listDiscordDirectoryPeersLive
@@ -141,5 +87,4 @@ function listDiscordDirectoryGroupsLive(params) {
141
87
  function listDiscordDirectoryPeersLive(params) {
142
88
  return listDiscordDirectoryLive(params, "user");
143
89
  }
144
- //#endregion
145
- export { normalizeDiscordSnowflake as a, normalizeDiscordHandleKey as i, listDiscordDirectoryGroupsLive as n, rememberDiscordDirectoryUser as o, listDiscordDirectoryPeersLive as r, resolveDiscordDirectoryUserId as s, directory_live_exports as t };
90
+ export { listDiscordDirectoryGroupsLive as n, listDiscordDirectoryPeersLive as r, directory_live_exports as t };