@openclaw/feishu 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 (100) hide show
  1. package/dist/.setup/{app-registration-DhnIp0Kd.mjs → app-registration-CBgQSu2L.mjs} +1 -2
  2. package/dist/.setup/async-WkOXCAZ1.mjs +32 -0
  3. package/dist/.setup/{channel-FEEIr2Sd.mjs → channel-Dig34MUl.mjs} +125 -128
  4. package/dist/.setup/{channel.runtime-D0haxEQL.mjs → channel.runtime-DtdoPtQ3.mjs} +10 -14
  5. package/dist/.setup/{chat-g8dTUdIb.mjs → chat-XINRHAOR.mjs} +3 -4
  6. package/dist/.setup/{client-DqGMyzOi.mjs → client-BAiJnY41.mjs} +4 -7
  7. package/dist/.setup/{conversation-id-BLsHZ7pf.mjs → conversation-id-N6q3vKm-.mjs} +2 -4
  8. package/dist/.setup/{doctor-contract-CPh2u5-o.mjs → doctor-contract-ItAh0keT.mjs} +10 -20
  9. package/dist/.setup/{message-action-contract-DMVMY_ng.mjs → message-action-contract-BZK6bpAl.mjs} +1 -2
  10. package/dist/.setup/{monitor-Bu-H1IvN.mjs → monitor-DGgVDZZK.mjs} +7 -10
  11. package/dist/.setup/{monitor.account-CTBV_Rk9.mjs → monitor.account-Doce9cKt.mjs} +337 -282
  12. package/dist/.setup/{probe-CbNVGjv_.mjs → probe-DMOl26H9.mjs} +11 -41
  13. package/dist/.setup/{reply-delivery-result-BjOCvaPo.mjs → reply-delivery-result-Dcan9Dz_.mjs} +211 -150
  14. package/dist/.setup/{runtime-C5JxBWZp.mjs → runtime-6V3uDMw5.mjs} +1 -2
  15. package/dist/.setup/runtime-setter-api-DSLLnejl.mjs +2 -0
  16. package/dist/.setup/{secret-contract-Do6HTIFT.mjs → secret-contract-BAucuP6O.mjs} +1 -2
  17. package/dist/.setup/{secret-contract-api-LwCXK5Qg.mjs → secret-contract-api-DR5mIHhJ.mjs} +1 -1
  18. package/dist/.setup/{security-audit-b86aSgH2.mjs → security-audit-CYRW0D76.mjs} +1 -2
  19. package/dist/.setup/{session-conversation-CM3UgYZY.mjs → session-conversation-DLgXP0-H.mjs} +2 -3
  20. package/dist/.setup/{setup-api-L7UpEkae.mjs → setup-api-qmezzejF.mjs} +1 -1
  21. package/dist/.setup/{subagent-hooks-DdiyEIi7.mjs → subagent-hooks-BRem84Mh.mjs} +4 -5
  22. package/dist/.setup/{thread-bindings-BxKmOara.mjs → thread-bindings-6eyktxK_.mjs} +1 -2
  23. package/dist/.source-module-urls/6579f1b33dd01f8f0aaea28311ed6df1a635f9ad1e6fa86dcba53bca46407e55.json +1 -1
  24. package/dist/api.js +20 -30
  25. package/dist/channel-entry.js +1 -2
  26. package/dist/channel-plugin-api.js +1 -1
  27. package/dist/configured-state.js +1 -2
  28. package/dist/contract-api.js +3 -3
  29. package/dist/doctor-contract-api.js +1 -1
  30. package/dist/index.js +1 -2
  31. package/dist/runtime-api.js +2 -2
  32. package/dist/runtime-setter-api.js +1 -1
  33. package/dist/secret-contract-api.js +1 -1
  34. package/dist/security-contract-api.js +1 -1
  35. package/dist/session-binding-contract-api.js +1 -1
  36. package/dist/session-key-api.js +1 -1
  37. package/dist/setup-api.js +1 -1
  38. package/dist/setup-entry.js +4 -5
  39. package/dist/subagent-hooks-api.js +2 -3
  40. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/README.md +41 -106
  41. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/axios.js +931 -278
  42. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/axios.min.js +2 -2
  43. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/axios.min.js.map +1 -1
  44. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/browser/axios.cjs +948 -268
  45. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/esm/axios.js +948 -268
  46. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/esm/axios.min.js +2 -2
  47. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/esm/axios.min.js.map +1 -1
  48. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/node/axios.cjs +925 -242
  49. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/index.d.cts +20 -1
  50. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/index.d.ts +18 -1
  51. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/adapters/fetch.js +73 -20
  52. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/adapters/http.js +145 -26
  53. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/adapters/xhr.js +120 -13
  54. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/Axios.js +67 -12
  55. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/AxiosError.js +59 -0
  56. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/AxiosHeaders.js +17 -4
  57. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/InterceptorManager.js +13 -2
  58. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/assertParamsAcyclic.js +49 -0
  59. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/createMultipartBody.js +37 -0
  60. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/dispatchRequest.js +20 -0
  61. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/mergeConfig.js +183 -120
  62. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/defaults/transitional.js +1 -0
  63. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/env/data.js +1 -1
  64. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/AxiosTransformStream.js +11 -2
  65. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/Http2Sessions.js +2 -1
  66. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/composeSignals.js +6 -3
  67. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/cookies.js +30 -6
  68. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js +34 -7
  69. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/formDataToBlob.js +113 -0
  70. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/formDataToJSON.js +25 -1
  71. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/fromDataURI.js +8 -2
  72. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/isURLSameOrigin.js +4 -9
  73. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/parseHeaders.js +2 -1
  74. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/parseProtocol.js +1 -1
  75. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/resolveConfig.js +16 -3
  76. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/shouldBypassProxy.js +16 -1
  77. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/utils.js +61 -10
  78. package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/package.json +1 -2
  79. package/node_modules/@larksuiteoapi/node-sdk/node_modules/follow-redirects/README.md +27 -1
  80. package/node_modules/@larksuiteoapi/node-sdk/node_modules/follow-redirects/index.js +1 -5
  81. package/node_modules/@larksuiteoapi/node-sdk/node_modules/follow-redirects/package.json +1 -1
  82. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/.editorconfig +1 -1
  83. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/CHANGELOG.md +87 -22
  84. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/README.md +63 -10
  85. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/dist/qs.js +17 -17
  86. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/eslint.config.mjs +61 -50
  87. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/lib/formats.js +7 -2
  88. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/lib/parse.js +29 -10
  89. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/lib/stringify.js +5 -3
  90. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/lib/utils.js +28 -9
  91. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/package.json +6 -6
  92. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/test/parse.js +335 -2
  93. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/test/stringify.js +222 -0
  94. package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/test/utils.js +61 -3
  95. package/node_modules/typebox/build/format/date_time.d.mts +2 -1
  96. package/node_modules/typebox/build/format/date_time.mjs +12 -3
  97. package/node_modules/typebox/package.json +1 -1
  98. package/openclaw.plugin.json +5 -0
  99. package/package.json +5 -5
  100. package/dist/.setup/runtime-setter-api-BrQHE03y.mjs +0 -2
@@ -1,14 +1,14 @@
1
- import { c as normalizeFeishuExternalKey, g as resolveFeishuRuntimeAccount, h as resolveFeishuAccount, s as normalizeFeishuWebhookPath } from "./doctor-contract-CPh2u5-o.mjs";
2
- import { c as resolveFeishuLegacyWebhookListener, l as gateway_config_runtime_exports, s as describeFeishuWebhookPathConflict } from "./channel-FEEIr2Sd.mjs";
3
- import { o as resolveConfiguredFeishuGroupSessionScope, t as buildFeishuConversationId, u as resolveReceiveIdType } from "./conversation-id-BLsHZ7pf.mjs";
4
- import { A as sendMessageFeishu, At as resolveFeishuGroupConfig, B as parseInteractiveCardContent, D as getMessageFeishu, Dt as hasExplicitFeishuGroupConfig, F as isFeishuBroadcastMention, G as resolveCardHeader, H as resolveFeishuSenderName, I as isMentionForwardRequest, It as resolveFeishuChatType, J as deliverCommentThreadText, K as resolveCardNote, L as normalizeMentions, Mt as resolveFeishuGroupSenderActivationIngressAccess, N as formatFeishuMediaContent, O as listFeishuThreadMessages, Ot as normalizeFeishuAllowEntry, P as extractMentionTargets, Pt as resolveFeishuReplyPolicy, R as isFeishuGroupChatType, Rt as createFeishuCardInteractionEnvelope, S as sendMediaFeishu, T as chunkFeishuCardMarkdown, V as parsePostContent, W as buildFeishuMediaFallbackText, _t as shouldUseFeishuCard, a as shouldSendNoVisibleReplyFallback, at as formatFeishuApiError, b as withinCardTableLimit, ct as buildFeishuCommentTarget, d as consumeFeishuPresentationFallbackMarker, ft as resolveFeishuCardTemplate, ht as materializeFeishuPostMarkdownSoftBreaks, i as noVisibleFeishuReplyDelivery, it as extractFeishuApiErrorMeta, j as sendStructuredCardFeishu, jt as resolveFeishuGroupConversationIngressAccess, k as sendCardFeishu, kt as resolveFeishuDmIngressAccess, lt as normalizeCommentFileType, mt as chunkFeishuPostMarkdown, n as createFeishuReplyDeliveryResult, nt as createCommentTypingReactionLifecycle, ot as parseCommentContentElements, r as mergeFeishuReplyDeliveryResults, rt as encodeQuery, st as requestFeishuApi, t as createFeishuPartialReplyDeliveryError, u as buildFeishuPresentationFallback, v as renderFeishuReplyPayload, w as shouldSuppressFeishuTextForVoiceMedia, x as saveMessageResourceFeishu, y as resolveFeishuRichReply, z as normalizeFeishuEventChatType, zt as decodeFeishuCardAction } from "./reply-delivery-result-BjOCvaPo.mjs";
5
- import { t as getFeishuRuntime } from "./runtime-C5JxBWZp.mjs";
6
- import { a as getFeishuUserAgent, f as resolveConfiguredHttpTimeoutMs, i as createFeishuWSClient, n as createEventDispatcher, r as createFeishuClient } from "./client-DqGMyzOi.mjs";
7
- import { t as createFeishuThreadBindingManager } from "./thread-bindings-BxKmOara.mjs";
8
- import { r as getChatInfo } from "./chat-g8dTUdIb.mjs";
9
- import { evaluateSupplementalContextVisibility, normalizeAgentId as normalizeAgentId$1, resolveChannelContextVisibilityMode } from "../runtime-api.js";
10
- import { a as waitForAbortableDelay, i as raceWithTimeoutAndAbort } from "./probe-CbNVGjv_.mjs";
11
- import { t as fetchBotIdentityForMonitor } from "./monitor-Bu-H1IvN.mjs";
1
+ import { c as normalizeFeishuExternalKey, g as resolveFeishuRuntimeAccount, h as resolveFeishuAccount, s as normalizeFeishuWebhookPath } from "./doctor-contract-ItAh0keT.mjs";
2
+ import { c as resolveFeishuLegacyWebhookListener, l as gateway_config_runtime_exports, s as describeFeishuWebhookPathConflict } from "./channel-Dig34MUl.mjs";
3
+ import { o as resolveConfiguredFeishuGroupSessionScope, t as buildFeishuConversationId, u as resolveReceiveIdType } from "./conversation-id-N6q3vKm-.mjs";
4
+ import { A as sendMessageFeishu, At as resolveFeishuGroupConversationIngressAccess, B as parseInteractiveCardContent, D as getMessageFeishu, Dt as normalizeFeishuAllowEntry, Et as hasExplicitFeishuGroupConfig, F as isFeishuBroadcastMention, G as resolveCardHeader, H as resolveFeishuSenderName, I as isMentionForwardRequest, It as resolveFeishuChatType, J as deliverCommentThreadText, K as resolveCardNote, L as normalizeMentions, M as sendFeishuMessage, N as formatFeishuMediaContent, Nt as resolveFeishuReplyPolicy, O as listFeishuThreadMessages, Ot as resolveFeishuDmIngressAccess, P as extractMentionTargets, Pt as shouldIncludeFetchedGroupContextMessage, R as isFeishuGroupChatType, Rt as createFeishuCardInteractionEnvelope, S as sendMediaFeishu, T as chunkFeishuCardMarkdown, V as parsePostContent, W as buildFeishuMediaFallbackText, a as shouldSendNoVisibleReplyFallback, at as formatFeishuApiError, b as withinCardTableLimit, ct as normalizeCommentFileType, d as consumeFeishuPresentationFallbackMarker, dt as resolveFeishuCardTemplate, gt as shouldUseFeishuCard, i as noVisibleFeishuReplyDelivery, it as extractFeishuApiErrorMeta, j as sendStructuredCardFeishu, jt as resolveFeishuGroupSenderActivationIngressAccess, k as sendCardFeishu, kt as resolveFeishuGroupConfig, mt as materializeFeishuPostMarkdownSoftBreaks, n as createFeishuReplyDeliveryResult, nt as createCommentTypingReactionLifecycle, ot as parseCommentContentElements, pt as chunkFeishuPostMarkdown, r as mergeFeishuReplyDeliveryResults, rt as encodeQuery, st as buildFeishuCommentTarget, t as createFeishuPartialReplyDeliveryError, u as buildFeishuPresentationFallback, v as renderFeishuReplyPayload, w as shouldSuppressFeishuTextForVoiceMedia, x as saveMessageResourceFeishu, y as resolveFeishuRichReply, z as normalizeFeishuEventChatType, zt as decodeFeishuCardAction } from "./reply-delivery-result-Dcan9Dz_.mjs";
5
+ import { t as getFeishuRuntime } from "./runtime-6V3uDMw5.mjs";
6
+ import { a as getFeishuUserAgent, f as resolveConfiguredHttpTimeoutMs, i as createFeishuWSClient, n as createEventDispatcher, r as createFeishuClient } from "./client-BAiJnY41.mjs";
7
+ import { n as waitForAbortableDelay, t as raceWithTimeoutAndAbort } from "./async-WkOXCAZ1.mjs";
8
+ import { t as createFeishuThreadBindingManager } from "./thread-bindings-6eyktxK_.mjs";
9
+ import { r as getChatInfo } from "./chat-XINRHAOR.mjs";
10
+ import { normalizeAgentId as normalizeAgentId$1, resolveChannelContextVisibilityMode } from "../runtime-api.js";
11
+ import { t as fetchBotIdentityForMonitor } from "./monitor-DGgVDZZK.mjs";
12
12
  import { resolveAgentConfig } from "openclaw/plugin-sdk/agent-scope-runtime";
13
13
  import { DEFAULT_INGRESS_ADOPTION_STALL_MS, bindIngressLifecycleToReplyOptions, createChannelIngressError, createChannelIngressMonitor, createChannelMessageReplyPipeline, createReplyPrefixContext, formatChannelProgressDraftLineForEntry, resolveAgentOutboundIdentity, resolveChannelPreviewStreamMode, resolveChannelStreamingBlockEnabled, waitUntilAbort } from "openclaw/plugin-sdk/channel-outbound";
14
14
  import { createChannelPairingController } from "openclaw/plugin-sdk/channel-pairing";
@@ -32,13 +32,13 @@ import { isRecord as isRecord$1 } from "openclaw/plugin-sdk/channel-secret-basic
32
32
  import { createDeferred } from "openclaw/plugin-sdk/extension-shared";
33
33
  import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime";
34
34
  import { truncateWithMarker } from "openclaw/plugin-sdk/string-normalization-runtime";
35
- import { raceWithTimeout } from "openclaw/plugin-sdk/time-runtime";
35
+ import { racePromiseWithAbortSignal, raceWithTimeout } from "openclaw/plugin-sdk/time-runtime";
36
36
  import { createStaleWhileRevalidateCache, pruneMapToMaxSize } from "openclaw/plugin-sdk/collection-runtime";
37
37
  import { safeParseJson, sliceUtf16Safe, truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
38
+ import crypto, * as crypto$1 from "node:crypto";
38
39
  import { ensureConfiguredBindingRouteReady, resolveConfiguredBindingRoute, resolveRuntimeConversationBindingRouteAsync } from "openclaw/plugin-sdk/conversation-binding-runtime";
39
40
  import { resolveOutboundMediaAccessForConfig } from "openclaw/plugin-sdk/outbound-media";
40
41
  import { readProviderJsonResponse } from "openclaw/plugin-sdk/provider-http";
41
- import crypto, * as crypto$1 from "node:crypto";
42
42
  import { createChannelHistoryWindow } from "openclaw/plugin-sdk/reply-history";
43
43
  import { createChannelReplayGuard } from "openclaw/plugin-sdk/persistent-dedupe";
44
44
  import { sha256Hex } from "openclaw/plugin-sdk/node-crypto-runtime";
@@ -46,6 +46,7 @@ import { resolveChannelConfigWrites } from "openclaw/plugin-sdk/channel-config-w
46
46
  import { formatReasoningMessage, resolveHumanDelayConfig } from "openclaw/plugin-sdk/agent-runtime";
47
47
  import { logTypingFailure } from "openclaw/plugin-sdk/channel-feedback";
48
48
  import { getGlobalHookRunner } from "openclaw/plugin-sdk/plugin-runtime";
49
+ import { createDeferred as createDeferred$1 } from "openclaw/plugin-sdk/concurrency-runtime";
49
50
  import { WEBHOOK_RATE_LIMIT_DEFAULTS, applyBasicWebhookRequestGuards, createFixedWindowRateLimiter, createWebhookAnomalyTracker, getWebhookLegacyListener, resolveRequestClientIp } from "openclaw/plugin-sdk/webhook-ingress";
50
51
  import { enqueueKeyedTask } from "openclaw/plugin-sdk/keyed-async-queue";
51
52
  import { createRuntimeConfigReader } from "openclaw/plugin-sdk/runtime-config-snapshot";
@@ -54,7 +55,7 @@ import { sendJson } from "openclaw/plugin-sdk/http-response-runtime";
54
55
  import { createWebhookInFlightLimiter, readWebhookBodyOrReject, sendHttpRequestRejection } from "openclaw/plugin-sdk/webhook-request-guards";
55
56
  import { canonicalizeWebhookRouteKey, registerPluginHttpRoute, registerWebhookTarget, resolveSingleWebhookTarget } from "openclaw/plugin-sdk/webhook-targets";
56
57
  import { isAbortRequestText, isBtwRequestText } from "openclaw/plugin-sdk/command-primitives-runtime";
57
- //#region src/channels/mention-gating.ts
58
+ // src/channels/mention-gating.ts
58
59
  function resolveBotThreadMentionPolicy(params) {
59
60
  if (!params.isBotOwnedThread || params.requireMentionInBotThreads === void 0) return {
60
61
  requireMention: params.requireMention,
@@ -65,8 +66,7 @@ function resolveBotThreadMentionPolicy(params) {
65
66
  implicitMentionKinds: params.requireMentionInBotThreads ? params.implicitMentionKinds?.filter((kind) => kind === "native") : params.implicitMentionKinds
66
67
  };
67
68
  }
68
- //#endregion
69
- //#region extensions/feishu/src/bot-agent-body.ts
69
+ // extensions/feishu/src/bot-agent-body.ts
70
70
  const MAX_MENTION_CONTEXT_NAME_LENGTH = 80;
71
71
  function formatMentionNameForAgentContext(name) {
72
72
  const normalized = Array.from(name, (char) => {
@@ -96,14 +96,73 @@ function buildFeishuAgentBody(params) {
96
96
  }
97
97
  return messageBody;
98
98
  }
99
- //#endregion
100
- //#region extensions/feishu/src/bot-broadcast.ts
99
+ // extensions/feishu/src/dedup-state.ts
100
+ const DEDUPE_NAMESPACE_PREFIX = "feishu.dedup";
101
+ const DEDUP_TTL_MS = 864e5;
102
+ const MEMORY_MAX_SIZE = 1e3;
103
+ const STORE_MAX_ENTRIES = 1e4;
104
+ function createFeishuDedupeGuard() {
105
+ return createChannelReplayGuard({
106
+ dedupe: {
107
+ pluginId: "feishu",
108
+ namespacePrefix: DEDUPE_NAMESPACE_PREFIX,
109
+ ttlMs: DEDUP_TTL_MS,
110
+ memoryMaxSize: MEMORY_MAX_SIZE,
111
+ stateMaxEntries: STORE_MAX_ENTRIES
112
+ },
113
+ buildReplayKey: (messageId) => messageId
114
+ });
115
+ }
116
+ const feishuDedupeState = {
117
+ guard: createFeishuDedupeGuard(),
118
+ reset() {
119
+ this.guard = createFeishuDedupeGuard();
120
+ }
121
+ };
122
+ // extensions/feishu/src/dedup.ts
123
+ function dedupeOptions(namespace, log) {
124
+ return {
125
+ ...namespace ? { namespace } : {},
126
+ ...log ? { onDiskError: (error) => log(`feishu-dedup: persistent state error: ${String(error)}`) } : {}
127
+ };
128
+ }
129
+ /**
130
+ * Claims a dedupe key for exclusive handling. Duplicate (already committed)
131
+ * and in-flight keys are reported; blank keys fail open as invalid so an
132
+ * unidentifiable event is never suppressed.
133
+ */
134
+ async function claimUnprocessedFeishuMessage(params) {
135
+ return await feishuDedupeState.guard.claim(params.messageId, dedupeOptions(params.namespace, params.log));
136
+ }
137
+ /**
138
+ * Claims (unless the caller already holds the claim) and commits a message.
139
+ * False means another handler owns it, it was already handled, or the key is
140
+ * blank; handlers must skip dispatch then.
141
+ */
142
+ async function finalizeFeishuMessageProcessing(params) {
143
+ const key = params.messageId?.trim();
144
+ if (!key) return false;
145
+ const options = dedupeOptions(params.namespace, params.log);
146
+ const claim = params.processingClaim ?? await feishuDedupeState.guard.claim(key, options);
147
+ if ("kind" in claim && claim.kind !== "claimed") return false;
148
+ return await ("kind" in claim ? claim.handle : claim).commit();
149
+ }
150
+ /** Checks recency without claiming or recording. */
151
+ async function hasProcessedFeishuMessage(messageId, namespace = "global", log) {
152
+ return await feishuDedupeState.guard.hasRecent(messageId, dedupeOptions(namespace, log));
153
+ }
154
+ /** Loads recent persisted entries into memory at account start; returns the loaded count. */
155
+ async function warmupDedupFromPluginState(namespace, log) {
156
+ return await feishuDedupeState.guard.warmup(namespace, (error) => log?.(`feishu-dedup: warmup persistent state error: ${String(error)}`));
157
+ }
158
+ // extensions/feishu/src/bot-broadcast.ts
101
159
  function createFeishuBroadcastIngressSettlement(params) {
102
160
  const lanes = /* @__PURE__ */ new Set();
103
161
  const failures = [];
104
162
  const fallbackAbort = new AbortController();
105
163
  let fanoutSettled = false;
106
164
  let terminal;
165
+ let dropReason;
107
166
  let terminalSettled = false;
108
167
  let finalizing = false;
109
168
  let deferred = false;
@@ -127,10 +186,19 @@ function createFeishuBroadcastIngressSettlement(params) {
127
186
  params.onReplayCommitError?.(error);
128
187
  } catch {}
129
188
  };
189
+ const notifyAdopted = () => {
190
+ try {
191
+ params.onAdopted?.();
192
+ } catch {}
193
+ };
130
194
  const abandon = async (error) => {
131
195
  if (terminal) return;
132
- terminal = "abandoned";
196
+ terminal = {
197
+ kind: "abandoned",
198
+ error
199
+ };
133
200
  params.replayClaim?.release({ error });
201
+ for (const lane of lanes) if (lane.status === "dropped") lane.replayClaim?.release({ error });
134
202
  try {
135
203
  await params.lifecycle?.onAbandoned();
136
204
  } finally {
@@ -139,15 +207,50 @@ function createFeishuBroadcastIngressSettlement(params) {
139
207
  finishSettlement();
140
208
  }
141
209
  };
210
+ const drop = async (reason) => {
211
+ if (terminal) return;
212
+ terminal = { kind: "dropped" };
213
+ try {
214
+ beginFinalizing();
215
+ if (params.lifecycle?.onDropped) {
216
+ await params.lifecycle.onDropped(reason);
217
+ for (const lane of lanes) {
218
+ if (lane.status !== "dropped") continue;
219
+ try {
220
+ await lane.replayClaim?.commit();
221
+ } catch (error) {
222
+ reportReplayCommitError(error);
223
+ }
224
+ }
225
+ try {
226
+ await params.replayClaim?.commit();
227
+ } catch (error) {
228
+ reportReplayCommitError(error);
229
+ }
230
+ } else {
231
+ const error = /* @__PURE__ */ new Error(`feishu-broadcast-${reason}`);
232
+ params.replayClaim?.release({ error });
233
+ for (const lane of lanes) if (lane.status === "dropped") lane.replayClaim?.release({ error });
234
+ await params.lifecycle?.onAbandoned();
235
+ }
236
+ if ([...lanes].some((lane) => lane.status === "completed")) notifyAdopted();
237
+ } catch (error) {
238
+ terminal = void 0;
239
+ await abandon(error).catch(() => void 0);
240
+ throw error;
241
+ } finally {
242
+ fallbackAbort.abort(reason);
243
+ terminalSettled = true;
244
+ finishSettlement();
245
+ }
246
+ };
142
247
  const adopt = async () => {
143
248
  if (terminal) return;
144
- terminal = "adopted";
249
+ terminal = { kind: "adopted" };
145
250
  try {
146
251
  beginFinalizing();
147
252
  await params.lifecycle?.onAdopted();
148
- try {
149
- params.onAdopted?.();
150
- } catch {}
253
+ notifyAdopted();
151
254
  try {
152
255
  await params.replayClaim?.commit();
153
256
  } catch (error) {
@@ -168,7 +271,11 @@ function createFeishuBroadcastIngressSettlement(params) {
168
271
  await abandon(failures.length === 1 ? failures[0] : new AggregateError(failures, "Feishu broadcast dispatch failed"));
169
272
  return;
170
273
  }
171
- if ([...lanes].some((lane) => lane.status !== "completed")) return;
274
+ if ([...lanes].some((lane) => lane.status !== "completed" && lane.status !== "dropped")) return;
275
+ if (dropReason !== void 0) {
276
+ await drop(dropReason);
277
+ return;
278
+ }
172
279
  await adopt();
173
280
  };
174
281
  return {
@@ -182,7 +289,7 @@ function createFeishuBroadcastIngressSettlement(params) {
182
289
  lifecycle: {
183
290
  abortSignal: params.lifecycle?.abortSignal ?? fallbackAbort.signal,
184
291
  onAdopted: async () => {
185
- if (terminal || lane.adopting || lane.status === "completed" || lane.status === "failed") return;
292
+ if (terminal || lane.adopting || lane.status === "completed" || lane.status === "dropped" || lane.status === "failed") return;
186
293
  lane.adopting = true;
187
294
  try {
188
295
  beginFinalizing();
@@ -207,11 +314,21 @@ function createFeishuBroadcastIngressSettlement(params) {
207
314
  deferredHeartbeatIntervalMs: params.lifecycle?.deferredHeartbeatIntervalMs,
208
315
  onAdoptionFinalizing: beginFinalizing,
209
316
  onAbandoned: async () => {
210
- if (lane.adopting || lane.status === "completed" || lane.status === "failed") return;
317
+ if (lane.adopting || lane.status === "completed" || lane.status === "dropped" || lane.status === "failed") return;
211
318
  lane.status = "failed";
212
319
  lane.replayClaim?.release({ error: /* @__PURE__ */ new Error("feishu-broadcast-turn-abandoned") });
213
320
  await maybeSettle();
214
- }
321
+ },
322
+ onDropped: params.lifecycle?.onDropped ? async (reason) => {
323
+ if (lane.adopting || lane.status === "completed" || lane.status === "dropped" || lane.status === "failed") return;
324
+ lane.status = "dropped";
325
+ dropReason ??= reason;
326
+ await maybeSettle();
327
+ if (terminal?.kind === "abandoned") {
328
+ lane.replayClaim?.release({ error: terminal.error });
329
+ throw terminal.error;
330
+ }
331
+ } : void 0
215
332
  },
216
333
  onDispatchComplete: async (dispatched) => {
217
334
  if (lane.adopting || lane.status !== "pending") return;
@@ -222,7 +339,7 @@ function createFeishuBroadcastIngressSettlement(params) {
222
339
  },
223
340
  onDispatchFailed: async (error) => {
224
341
  failures.push(error);
225
- if (!lane.adopting && lane.status !== "completed") {
342
+ if (!lane.adopting && lane.status !== "completed" && lane.status !== "dropped") {
226
343
  lane.status = "failed";
227
344
  lane.replayClaim?.release({ error });
228
345
  }
@@ -242,6 +359,24 @@ function createFeishuBroadcastIngressSettlement(params) {
242
359
  }
243
360
  };
244
361
  }
362
+ async function claimFeishuBroadcastAgentMessage(params) {
363
+ for (let attempt = 0; attempt < 2; attempt += 1) {
364
+ const claim = await claimUnprocessedFeishuMessage({
365
+ messageId: params.messageId,
366
+ namespace: `broadcast:${params.agentId}`,
367
+ log: params.log
368
+ });
369
+ if (claim.kind === "duplicate") return;
370
+ if (claim.kind !== "inflight") return claim;
371
+ params.onPending();
372
+ try {
373
+ await claim.pending;
374
+ return;
375
+ } catch (err) {
376
+ if (attempt === 1) throw err;
377
+ }
378
+ }
379
+ }
245
380
  function resolveBroadcastAgents(cfg, peerId) {
246
381
  const agents = cfg.broadcast?.[peerId];
247
382
  return Array.isArray(agents) && agents.length > 0 ? agents : null;
@@ -250,8 +385,7 @@ function buildBroadcastSessionKey(baseSessionKey, originalAgentId, targetAgentId
250
385
  const prefix = `agent:${originalAgentId}:`;
251
386
  return baseSessionKey.startsWith(prefix) ? `agent:${targetAgentId}:${baseSessionKey.slice(prefix.length)}` : baseSessionKey;
252
387
  }
253
- //#endregion
254
- //#region extensions/feishu/src/bot-content.ts
388
+ // extensions/feishu/src/bot-content.ts
255
389
  function resolveFeishuGroupSession(params) {
256
390
  const { chatId, senderOpenId, messageId, rootId, threadId, chatType, groupConfig, feishuCfg } = params;
257
391
  const normalizedThreadId = threadId?.trim();
@@ -441,15 +575,13 @@ async function resolveFeishuMediaList(params) {
441
575
  }
442
576
  return out;
443
577
  }
444
- //#endregion
445
- //#region extensions/feishu/src/bot-group-name-state.ts
578
+ // extensions/feishu/src/bot-group-name-state.ts
446
579
  const feishuGroupNameCache = createStaleWhileRevalidateCache({
447
580
  maxEntries: 500,
448
581
  maxPending: Infinity,
449
582
  ttlMs: 18e5
450
583
  });
451
- //#endregion
452
- //#region extensions/feishu/src/bot-group-name.ts
584
+ // extensions/feishu/src/bot-group-name.ts
453
585
  async function resolveGroupName(params) {
454
586
  const { account, chatId, log } = params;
455
587
  if (!account.configured) return;
@@ -463,8 +595,7 @@ async function resolveGroupName(params) {
463
595
  }, { allowStale: false });
464
596
  return value;
465
597
  }
466
- //#endregion
467
- //#region extensions/feishu/src/bot-name.ts
598
+ // extensions/feishu/src/bot-name.ts
468
599
  const POSITIVE_TTL_MS = 6e5;
469
600
  const NEGATIVE_TTL_MS = 6e4;
470
601
  const MAX_CACHE_ENTRIES = 5e3;
@@ -476,7 +607,7 @@ const inflight = /* @__PURE__ */ new Map();
476
607
  function readCache(key) {
477
608
  const entry = cache.get(key);
478
609
  if (!entry) return;
479
- if (entry.expiresAt <= Date.now()) {
610
+ if (entry.expiresAt <= performance.now()) {
480
611
  cache.delete(key);
481
612
  return;
482
613
  }
@@ -494,7 +625,7 @@ async function resolveFeishuBotName(params) {
494
625
  if (!params.account.configured || !openId) return;
495
626
  const backoffUntil = backoffUntilByAccount.get(params.account.accountId);
496
627
  if (backoffUntil !== void 0) {
497
- if (backoffUntil > Date.now()) return;
628
+ if (backoffUntil > performance.now()) return;
498
629
  backoffUntilByAccount.delete(params.account.accountId);
499
630
  }
500
631
  const key = `${params.account.accountId}::${openId}`;
@@ -521,13 +652,13 @@ async function resolveFeishuBotName(params) {
521
652
  else log(`feishu[${account.accountId}]: bot name lookup failed: ${String(error)}`);
522
653
  }
523
654
  if (!result) {
524
- backoffUntilByAccount.set(account.accountId, Date.now() + LOOKUP_BACKOFF_MS);
655
+ backoffUntilByAccount.set(account.accountId, performance.now() + LOOKUP_BACKOFF_MS);
525
656
  return;
526
657
  }
527
658
  const name = result.data?.bots?.[openId]?.name?.trim();
528
659
  writeCache(key, {
529
660
  ...name ? { name } : {},
530
- expiresAt: Date.now() + (name ? POSITIVE_TTL_MS : NEGATIVE_TTL_MS)
661
+ expiresAt: performance.now() + (name ? POSITIVE_TTL_MS : NEGATIVE_TTL_MS)
531
662
  });
532
663
  return name;
533
664
  })();
@@ -538,8 +669,7 @@ async function resolveFeishuBotName(params) {
538
669
  inflight.delete(key);
539
670
  }
540
671
  }
541
- //#endregion
542
- //#region extensions/feishu/src/bot-thread-mentions.ts
672
+ // extensions/feishu/src/bot-thread-mentions.ts
543
673
  async function prepareFeishuThreadRoot(params) {
544
674
  let { cfg, account } = params;
545
675
  const { ctx, botOpenId, log } = params;
@@ -584,69 +714,7 @@ async function prepareFeishuThreadRoot(params) {
584
714
  getRootMessageInfo
585
715
  };
586
716
  }
587
- //#endregion
588
- //#region extensions/feishu/src/dedup-state.ts
589
- const DEDUPE_NAMESPACE_PREFIX = "feishu.dedup";
590
- const DEDUP_TTL_MS = 864e5;
591
- const MEMORY_MAX_SIZE = 1e3;
592
- const STORE_MAX_ENTRIES = 1e4;
593
- function createFeishuDedupeGuard() {
594
- return createChannelReplayGuard({
595
- dedupe: {
596
- pluginId: "feishu",
597
- namespacePrefix: DEDUPE_NAMESPACE_PREFIX,
598
- ttlMs: DEDUP_TTL_MS,
599
- memoryMaxSize: MEMORY_MAX_SIZE,
600
- stateMaxEntries: STORE_MAX_ENTRIES
601
- },
602
- buildReplayKey: (messageId) => messageId
603
- });
604
- }
605
- const feishuDedupeState = {
606
- guard: createFeishuDedupeGuard(),
607
- reset() {
608
- this.guard = createFeishuDedupeGuard();
609
- }
610
- };
611
- //#endregion
612
- //#region extensions/feishu/src/dedup.ts
613
- function dedupeOptions(namespace, log) {
614
- return {
615
- ...namespace ? { namespace } : {},
616
- ...log ? { onDiskError: (error) => log(`feishu-dedup: persistent state error: ${String(error)}`) } : {}
617
- };
618
- }
619
- /**
620
- * Claims a dedupe key for exclusive handling. Duplicate (already committed)
621
- * and in-flight keys are reported; blank keys fail open as invalid so an
622
- * unidentifiable event is never suppressed.
623
- */
624
- async function claimUnprocessedFeishuMessage(params) {
625
- return await feishuDedupeState.guard.claim(params.messageId, dedupeOptions(params.namespace, params.log));
626
- }
627
- /**
628
- * Claims (unless the caller already holds the claim) and commits a message.
629
- * False means another handler owns it, it was already handled, or the key is
630
- * blank; handlers must skip dispatch then.
631
- */
632
- async function finalizeFeishuMessageProcessing(params) {
633
- const key = params.messageId?.trim();
634
- if (!key) return false;
635
- const options = dedupeOptions(params.namespace, params.log);
636
- const claim = params.processingClaim ?? await feishuDedupeState.guard.claim(key, options);
637
- if ("kind" in claim && claim.kind !== "claimed") return false;
638
- return await ("kind" in claim ? claim.handle : claim).commit();
639
- }
640
- /** Checks recency without claiming or recording. */
641
- async function hasProcessedFeishuMessage(messageId, namespace = "global", log) {
642
- return await feishuDedupeState.guard.hasRecent(messageId, dedupeOptions(namespace, log));
643
- }
644
- /** Loads recent persisted entries into memory at account start; returns the loaded count. */
645
- async function warmupDedupFromPluginState(namespace, log) {
646
- return await feishuDedupeState.guard.warmup(namespace, (error) => log?.(`feishu-dedup: warmup persistent state error: ${String(error)}`));
647
- }
648
- //#endregion
649
- //#region extensions/feishu/src/dedupe-key.ts
717
+ // extensions/feishu/src/dedupe-key.ts
650
718
  function resolvePostMediaParts(content) {
651
719
  const { attachments } = parsePostContent(content, { includeTopLevelFiles: false });
652
720
  return ["image", "file"].flatMap((kind) => attachments.filter((attachment) => attachment.kind === kind).map((attachment) => `${kind}_key:${attachment.key}`));
@@ -698,8 +766,7 @@ function resolveFeishuMessageDedupeKey(event) {
698
766
  }
699
767
  return messageId;
700
768
  }
701
- //#endregion
702
- //#region extensions/feishu/src/dynamic-agent.ts
769
+ // extensions/feishu/src/dynamic-agent.ts
703
770
  var DynamicAgentMutationSkipped = class extends Error {
704
771
  constructor(cfg) {
705
772
  super("dynamic agent mutation skipped");
@@ -848,8 +915,7 @@ function resolveUserPath(p) {
848
915
  if (p.startsWith("~/")) return path.join(os.homedir(), p.slice(2));
849
916
  return p;
850
917
  }
851
- //#endregion
852
- //#region extensions/feishu/src/reasoning-preview.ts
918
+ // extensions/feishu/src/reasoning-preview.ts
853
919
  async function resolveFeishuReasoningPreviewEnabled(params) {
854
920
  const configDefault = resolveAgentConfig(params.cfg, params.agentId)?.reasoningDefault ?? params.cfg.agents?.defaults?.reasoningDefault ?? "off";
855
921
  try {
@@ -864,11 +930,9 @@ async function resolveFeishuReasoningPreviewEnabled(params) {
864
930
  }
865
931
  return configDefault === "stream";
866
932
  }
867
- //#endregion
868
- //#region extensions/feishu/src/reply-dispatcher-state.ts
933
+ // extensions/feishu/src/reply-dispatcher-state.ts
869
934
  const streamingStartBackoffUntilByAccount = /* @__PURE__ */ new Map();
870
- //#endregion
871
- //#region extensions/feishu/src/streaming-card.ts
935
+ // extensions/feishu/src/streaming-card.ts
872
936
  const STREAMING_UPDATE_THROTTLE_MS = 160;
873
937
  const STREAMING_SIGNIFICANT_DELTA_CHARS = 18;
874
938
  const FEISHU_STREAMING_TOKEN_DEFAULT_LIFETIME_SECONDS = 7200;
@@ -1035,23 +1099,15 @@ var FeishuStreamingSession = class {
1035
1099
  type: "card",
1036
1100
  data: { card_id: cardId }
1037
1101
  });
1038
- const sendOptions = options ?? {};
1039
- const sendRes = await requestFeishuApi(() => sendOptions.replyToMessageId ? this.client.im.message.reply({
1040
- path: { message_id: sendOptions.replyToMessageId },
1041
- data: {
1042
- msg_type: "interactive",
1043
- content: cardContent,
1044
- ...sendOptions.replyInThread ? { reply_in_thread: true } : {}
1045
- }
1046
- }) : this.client.im.message.create({
1047
- params: { receive_id_type: receiveIdType },
1048
- data: {
1049
- receive_id: receiveId,
1050
- msg_type: "interactive",
1051
- content: cardContent,
1052
- ...sendOptions.rootId ? { root_id: sendOptions.rootId } : {}
1053
- }
1054
- }), "Send card failed");
1102
+ const sendRes = await sendFeishuMessage({
1103
+ client: this.client,
1104
+ receiveId,
1105
+ receiveIdType
1106
+ }, {
1107
+ ...options,
1108
+ content: cardContent,
1109
+ msgType: "interactive"
1110
+ }, "Send card failed");
1055
1111
  if (sendRes.code !== 0) throw new Error(`Send card failed: ${sendRes.msg}`);
1056
1112
  const messageId = sendRes.data?.message_id?.trim();
1057
1113
  this.state = {
@@ -1230,8 +1286,7 @@ var FeishuStreamingSession = class {
1230
1286
  return this.state !== null && !this.closed;
1231
1287
  }
1232
1288
  };
1233
- //#endregion
1234
- //#region extensions/feishu/src/streaming-update.ts
1289
+ // extensions/feishu/src/streaming-update.ts
1235
1290
  /** Admit captured snapshots in order while the session owns provider writes. */
1236
1291
  function queueFeishuStreamingUpdate(params) {
1237
1292
  const { queue, session, startPromise, text, accountId, runtime } = params;
@@ -1240,8 +1295,7 @@ function queueFeishuStreamingUpdate(params) {
1240
1295
  if (session?.isActive()) session.update(text).catch((error) => runtime.error(`feishu[${accountId}] streaming update failed: ${String(error)}`));
1241
1296
  });
1242
1297
  }
1243
- //#endregion
1244
- //#region extensions/feishu/src/typing-backoff.ts
1298
+ // extensions/feishu/src/typing-backoff.ts
1245
1299
  /** Feishu API codes that should trip the typing circuit breaker. */
1246
1300
  const FEISHU_BACKOFF_CODES = /* @__PURE__ */ new Set([
1247
1301
  99991400,
@@ -1269,8 +1323,7 @@ function getBackoffCodeFromResponse(response) {
1269
1323
  const code = response.code;
1270
1324
  return typeof code === "number" && FEISHU_BACKOFF_CODES.has(code) ? code : void 0;
1271
1325
  }
1272
- //#endregion
1273
- //#region extensions/feishu/src/typing.ts
1326
+ // extensions/feishu/src/typing.ts
1274
1327
  const TYPING_EMOJI = "Typing";
1275
1328
  async function requestTypingReaction(request, operation, readResponse, runtime) {
1276
1329
  const indicator = `typing indicator${operation === "remove" ? " removal" : ""}`;
@@ -1338,8 +1391,7 @@ async function removeTypingIndicator(params) {
1338
1391
  reaction_id: state.reactionId
1339
1392
  } }), "remove", () => void 0, runtime);
1340
1393
  }
1341
- //#endregion
1342
- //#region extensions/feishu/src/reply-dispatcher.ts
1394
+ // extensions/feishu/src/reply-dispatcher.ts
1343
1395
  function mergeStreamingFinalText(previousText, nextText, appendError) {
1344
1396
  if (!appendError || !previousText || nextText.startsWith(previousText)) return nextText;
1345
1397
  if (previousText.endsWith(`\n\n${nextText}`)) return previousText;
@@ -1354,7 +1406,7 @@ const NO_VISIBLE_REPLY_FALLBACK_TEXT = "⚠️ This reply completed without visi
1354
1406
  function isStreamingStartBackedOff(accountId) {
1355
1407
  const backoffUntil = streamingStartBackoffUntilByAccount.get(accountId);
1356
1408
  if (backoffUntil === void 0) return false;
1357
- if (backoffUntil <= Date.now()) {
1409
+ if (backoffUntil <= performance.now()) {
1358
1410
  streamingStartBackoffUntilByAccount.delete(accountId);
1359
1411
  return false;
1360
1412
  }
@@ -1524,7 +1576,7 @@ function createFeishuReplyDispatcher(params) {
1524
1576
  });
1525
1577
  streamingStartBackoffUntilByAccount.delete(account.accountId);
1526
1578
  } catch (error) {
1527
- streamingStartBackoffUntilByAccount.set(account.accountId, Date.now() + STREAMING_START_FAILURE_BACKOFF_MS);
1579
+ streamingStartBackoffUntilByAccount.set(account.accountId, performance.now() + STREAMING_START_FAILURE_BACKOFF_MS);
1528
1580
  params.runtime.error(`feishu[${account.accountId}]: streaming start failed; using non-streaming card fallback for ${STREAMING_START_FAILURE_BACKOFF_MS / 1e3}s: ${String(error)}`);
1529
1581
  if (streaming === session) {
1530
1582
  streaming = null;
@@ -2110,8 +2162,7 @@ function createFeishuReplyDispatcher(params) {
2110
2162
  ensureNoVisibleReplyFallback
2111
2163
  };
2112
2164
  }
2113
- //#endregion
2114
- //#region extensions/feishu/src/synthetic-event-target.ts
2165
+ // extensions/feishu/src/synthetic-event-target.ts
2115
2166
  const directPreDispatchTargets = /* @__PURE__ */ new WeakMap();
2116
2167
  /** Keep synthetic-only routing metadata outside the public Feishu event shape. */
2117
2168
  function setFeishuSyntheticDirectPreDispatchTarget(event, target) {
@@ -2121,32 +2172,12 @@ function setFeishuSyntheticDirectPreDispatchTarget(event, target) {
2121
2172
  function getFeishuSyntheticDirectPreDispatchTarget(event) {
2122
2173
  return directPreDispatchTargets.get(event);
2123
2174
  }
2124
- //#endregion
2125
- //#region extensions/feishu/src/bot.ts
2175
+ // extensions/feishu/src/bot.ts
2126
2176
  const permissionErrorNotifiedAt = /* @__PURE__ */ new Map();
2127
2177
  const PERMISSION_ERROR_COOLDOWN_MS = 3e5;
2128
2178
  function isFeishuTopicSessionScope(scope) {
2129
2179
  return scope === "group_topic" || scope === "group_topic_sender";
2130
2180
  }
2131
- async function shouldIncludeFetchedGroupContextMessage(params) {
2132
- let senderAllowed = !params.isGroup || params.allowFrom.length === 0 || params.senderType === "app";
2133
- const senderId = params.senderId?.trim();
2134
- if (!senderAllowed && senderId) senderAllowed = (await resolveFeishuGroupSenderActivationIngressAccess({
2135
- cfg: params.cfg,
2136
- accountId: params.accountId,
2137
- chatId: params.chatId,
2138
- allowFrom: params.allowFrom,
2139
- senderOpenId: senderId,
2140
- senderUserId: senderId,
2141
- requireMention: false,
2142
- mentionedBot: true
2143
- })).senderAccess.decision === "allow";
2144
- return evaluateSupplementalContextVisibility({
2145
- mode: params.mode,
2146
- kind: params.kind,
2147
- senderAllowed
2148
- }).include;
2149
- }
2150
2181
  async function handleFeishuMessage(params) {
2151
2182
  const { event, preparedContent, botOpenId, runtime, channelRuntime, chatHistories, accountId, processingClaim, messageDedupeKey: messageDedupeKeyOverride, turnAdoptionLifecycle } = params;
2152
2183
  let cfg = getFeishuRuntime().config.current();
@@ -2855,7 +2886,7 @@ async function handleFeishuMessage(params) {
2855
2886
  readAllowFromStore: pairing.readAllowFromStore,
2856
2887
  senderOpenId: ctx.senderOpenId,
2857
2888
  senderUserId,
2858
- conversationId: ctx.senderOpenId,
2889
+ conversationId: ctx.chatId,
2859
2890
  mayPair: false,
2860
2891
  contextBinding
2861
2892
  });
@@ -2906,6 +2937,11 @@ async function handleFeishuMessage(params) {
2906
2937
  replyToId: ctx.parentId,
2907
2938
  messageThreadId: ctx.rootId && isTopicSession ? ctx.rootId : void 0
2908
2939
  },
2940
+ command: {
2941
+ kind: core.channel.commands.isControlCommandMessage(effectiveCommandProbeBody, effectiveCfg) ? "text-slash" : "normal",
2942
+ body: effectiveCommandProbeBody,
2943
+ authorized: commandAuthorized === true
2944
+ },
2909
2945
  message: {
2910
2946
  body: combinedBody,
2911
2947
  bodyForAgent: messageBody,
@@ -3044,25 +3080,19 @@ async function handleFeishuMessage(params) {
3044
3080
  log(`feishu[${account.accountId}]: broadcast agent ${agentId} not found in agents.entries; skipping`);
3045
3081
  return;
3046
3082
  }
3047
- let agentClaim;
3048
- for (let attempt = 0; attempt < 2; attempt += 1) {
3049
- agentClaim = await claimUnprocessedFeishuMessage({
3050
- messageId: broadcastDedupeKey,
3051
- namespace: `broadcast:${agentId}`,
3052
- log
3053
- });
3054
- if (agentClaim.kind === "duplicate") return;
3055
- if (agentClaim.kind !== "inflight") break;
3056
- broadcastSettlement.onLanePending();
3057
- try {
3058
- await agentClaim.pending;
3083
+ const agentClaim = await claimFeishuBroadcastAgentMessage({
3084
+ messageId: broadcastDedupeKey,
3085
+ agentId,
3086
+ log,
3087
+ onPending: broadcastSettlement.onLanePending
3088
+ });
3089
+ if (!agentClaim) return;
3090
+ const lane = broadcastSettlement.createLane(agentClaim.kind === "claimed" ? agentClaim.handle : void 0);
3091
+ try {
3092
+ if (agentId !== activeAgentId && core.channel.commands.isControlCommandMessage(effectiveCommandProbeBody, effectiveCfg)) {
3093
+ await lane.lifecycle.onAdopted();
3059
3094
  return;
3060
- } catch (err) {
3061
- if (attempt === 1) throw err;
3062
3095
  }
3063
- }
3064
- const lane = broadcastSettlement.createLane(agentClaim?.kind === "claimed" ? agentClaim.handle : void 0);
3065
- try {
3066
3096
  const agentSessionKey = buildBroadcastSessionKey(route.sessionKey, route.agentId, agentId);
3067
3097
  const agentStorePath = resolveStorePath(cfg.session?.store, { agentId });
3068
3098
  const agentRecord = {
@@ -3088,7 +3118,11 @@ async function handleFeishuMessage(params) {
3088
3118
  identity: resolveAgentOutboundIdentity(cfg, agentId),
3089
3119
  sessionKey: agentSessionKey
3090
3120
  }) : void 0;
3091
- if (!dispatcher) delete agentCtx.CommandAuthorized;
3121
+ if (!dispatcher) {
3122
+ agentCtx.CommandAuthorized = false;
3123
+ delete agentCtx.CommandTurn;
3124
+ delete agentCtx.CommandSource;
3125
+ }
3092
3126
  const turnResult = await runAgentTurn(agentCtx, () => ({
3093
3127
  cfg,
3094
3128
  channel: "feishu",
@@ -3211,12 +3245,20 @@ async function handleFeishuMessage(params) {
3211
3245
  error(`feishu[${account.accountId}]: failed to dispatch message: ${String(err)}`);
3212
3246
  }
3213
3247
  }
3214
- //#endregion
3215
- //#region extensions/feishu/src/card-action-state.ts
3216
- const processedCardActions = /* @__PURE__ */ new Map();
3248
+ // extensions/feishu/src/card-action-state.ts
3249
+ const TOKEN_TTL_MS = 9e5;
3250
+ const cardActionReplayGuard = createChannelReplayGuard({
3251
+ dedupe: {
3252
+ pluginId: "feishu",
3253
+ namespacePrefix: "feishu.card-actions",
3254
+ ttlMs: TOKEN_TTL_MS,
3255
+ memoryMaxSize: 1e3,
3256
+ stateMaxEntries: 1e4
3257
+ },
3258
+ buildReplayKey: (token) => resolveExpiresAtMsFromDurationMs(TOKEN_TTL_MS) === void 0 ? void 0 : token
3259
+ });
3217
3260
  const resolvedCardActionChatTypes = /* @__PURE__ */ new Map();
3218
- //#endregion
3219
- //#region extensions/feishu/src/card-ux-shared.ts
3261
+ // extensions/feishu/src/card-ux-shared.ts
3220
3262
  function buildFeishuActionCard(params) {
3221
3263
  return {
3222
3264
  schema: "2.0",
@@ -3264,8 +3306,7 @@ function buildFeishuCardInteractionContext(params) {
3264
3306
  ...params.chatType ? { t: params.chatType } : {}
3265
3307
  };
3266
3308
  }
3267
- //#endregion
3268
- //#region extensions/feishu/src/card-ux-approval.ts
3309
+ // extensions/feishu/src/card-ux-approval.ts
3269
3310
  const FEISHU_APPROVAL_REQUEST_ACTION = "feishu.quick_actions.request_approval";
3270
3311
  const FEISHU_APPROVAL_CONFIRM_ACTION = "feishu.approval.confirm";
3271
3312
  const FEISHU_APPROVAL_CANCEL_ACTION = "feishu.approval.cancel";
@@ -3294,10 +3335,8 @@ function createApprovalCard(params) {
3294
3335
  })]
3295
3336
  });
3296
3337
  }
3297
- //#endregion
3298
- //#region extensions/feishu/src/card-action.ts
3338
+ // extensions/feishu/src/card-action.ts
3299
3339
  const FEISHU_APPROVAL_CARD_TTL_MS = 3e5;
3300
- const FEISHU_CARD_ACTION_TOKEN_TTL_MS = 9e5;
3301
3340
  function pruneExpiredCardEntries(cache, now) {
3302
3341
  const validNow = asDateTimestampMs(now);
3303
3342
  if (validNow === void 0) {
@@ -3306,29 +3345,8 @@ function pruneExpiredCardEntries(cache, now) {
3306
3345
  }
3307
3346
  for (const [key, entry] of cache) if (!isFutureDateTimestampMs(entry.expiresAt, { nowMs: validNow })) cache.delete(key);
3308
3347
  }
3309
- function refreshFeishuCardActionToken(key, now = Date.now()) {
3310
- const expiresAt = resolveExpiresAtMsFromDurationMs(FEISHU_CARD_ACTION_TOKEN_TTL_MS, { nowMs: now });
3311
- if (expiresAt === void 0) {
3312
- processedCardActions.delete(key);
3313
- return;
3314
- }
3315
- processedCardActions.set(key, { expiresAt });
3316
- }
3317
- function resolveCallbackTarget(event) {
3318
- const chatId = event.context.chat_id?.trim();
3319
- if (chatId) return `chat:${chatId}`;
3320
- return `user:${event.operator.open_id}`;
3321
- }
3322
3348
  const CHAT_TYPE_CACHE_TTL_MS = 18e5;
3323
3349
  const CHAT_TYPE_CACHE_MAX_SIZE = 5e3;
3324
- function cacheResolvedCardActionChatType(cacheKey, value, now) {
3325
- const expiresAt = resolveExpiresAtMsFromDurationMs(CHAT_TYPE_CACHE_TTL_MS, { nowMs: now });
3326
- resolvedCardActionChatTypes.delete(cacheKey);
3327
- if (expiresAt !== void 0) resolvedCardActionChatTypes.set(cacheKey, {
3328
- value,
3329
- expiresAt
3330
- });
3331
- }
3332
3350
  async function handleFeishuCardAction(params) {
3333
3351
  const { cfg, event, runtime, accountId } = params;
3334
3352
  const account = resolveFeishuRuntimeAccount({
@@ -3336,15 +3354,17 @@ async function handleFeishuCardAction(params) {
3336
3354
  accountId
3337
3355
  });
3338
3356
  const log = runtime?.log ?? console.log;
3357
+ const chatId = event.context.chat_id?.trim();
3358
+ const callbackTarget = chatId ? `chat:${chatId}` : `user:${event.operator.open_id}`;
3359
+ let commandDispatched = false;
3339
3360
  const sendNotice = (text) => sendMessageFeishu({
3340
3361
  cfg,
3341
- to: resolveCallbackTarget(event),
3362
+ to: callbackTarget,
3342
3363
  text,
3343
3364
  accountId
3344
3365
  });
3345
3366
  async function resolveCardActionChatType(chatType) {
3346
3367
  if (chatType) return chatType;
3347
- const chatId = event.context.chat_id?.trim();
3348
3368
  if (!chatId) return "p2p";
3349
3369
  const cacheKey = `${account.accountId}:${chatId}`;
3350
3370
  const now = Date.now();
@@ -3357,7 +3377,11 @@ async function handleFeishuCardAction(params) {
3357
3377
  if (response.code === 0) {
3358
3378
  const resolvedChatType = resolveFeishuChatType(response.data ?? {});
3359
3379
  if (resolvedChatType) {
3360
- cacheResolvedCardActionChatType(cacheKey, resolvedChatType, now);
3380
+ const expiresAt = resolveExpiresAtMsFromDurationMs(CHAT_TYPE_CACHE_TTL_MS, { nowMs: now });
3381
+ if (expiresAt !== void 0) resolvedCardActionChatTypes.set(cacheKey, {
3382
+ value: resolvedChatType,
3383
+ expiresAt
3384
+ });
3361
3385
  return resolvedChatType;
3362
3386
  }
3363
3387
  }
@@ -3397,6 +3421,7 @@ async function handleFeishuCardAction(params) {
3397
3421
  }
3398
3422
  };
3399
3423
  }
3424
+ commandDispatched = true;
3400
3425
  await handleFeishuMessage({
3401
3426
  trackTask,
3402
3427
  cfg,
@@ -3408,13 +3433,7 @@ async function handleFeishuCardAction(params) {
3408
3433
  });
3409
3434
  }
3410
3435
  const sendInvalidInteractionNotice = async (reason) => {
3411
- const reasonText = reason === "stale" ? "This card action has expired. Open a fresh launcher card and try again." : reason === "wrong_user" ? "This card action belongs to a different user." : reason === "wrong_conversation" ? "This card action belongs to a different conversation." : "This card action payload is invalid.";
3412
- await sendMessageFeishu({
3413
- cfg,
3414
- to: resolveCallbackTarget(event),
3415
- text: `⚠️ ${reasonText}`,
3416
- accountId
3417
- });
3436
+ await sendNotice(`⚠️ ${reason === "stale" ? "This card action has expired. Open a fresh launcher card and try again." : reason === "wrong_user" ? "This card action belongs to a different user." : reason === "wrong_conversation" ? "This card action belongs to a different conversation." : "This card action payload is invalid."}`);
3418
3437
  };
3419
3438
  const normalizedToken = event.token.trim();
3420
3439
  if (!normalizedToken) {
@@ -3422,14 +3441,14 @@ async function handleFeishuCardAction(params) {
3422
3441
  return;
3423
3442
  }
3424
3443
  const decoded = decodeFeishuCardAction(event);
3425
- const now = Date.now();
3426
- pruneExpiredCardEntries(processedCardActions, now);
3427
- const tokenKey = `${account.accountId}:${normalizedToken}`;
3428
- if (processedCardActions.has(tokenKey)) {
3444
+ const claim = await cardActionReplayGuard.claim(normalizedToken, {
3445
+ namespace: account.accountId,
3446
+ onDiskError: (error) => log(`feishu-card-action: persistent state error: ${String(error)}`)
3447
+ });
3448
+ if (claim.kind === "duplicate" || claim.kind === "inflight") {
3429
3449
  log(`feishu[${account.accountId}]: skipping duplicate card action token`);
3430
3450
  return;
3431
3451
  }
3432
- refreshFeishuCardActionToken(tokenKey, now);
3433
3452
  try {
3434
3453
  if (decoded.kind === "invalid") {
3435
3454
  log(`feishu[${account.accountId}]: rejected card action from ${event.operator.open_id}: ${decoded.reason}`);
@@ -3455,7 +3474,7 @@ async function handleFeishuCardAction(params) {
3455
3474
  if (!chatType) return;
3456
3475
  await sendCardFeishu({
3457
3476
  cfg,
3458
- to: resolveCallbackTarget(event),
3477
+ to: callbackTarget,
3459
3478
  card: createApprovalCard({
3460
3479
  operatorOpenId: event.operator.open_id,
3461
3480
  chatId: event.context.chat_id || void 0,
@@ -3471,12 +3490,7 @@ async function handleFeishuCardAction(params) {
3471
3490
  return;
3472
3491
  }
3473
3492
  if (envelope.a === "feishu.approval.cancel") {
3474
- await sendMessageFeishu({
3475
- cfg,
3476
- to: resolveCallbackTarget(event),
3477
- text: "Cancelled.",
3478
- accountId
3479
- });
3493
+ await sendNotice("Cancelled.");
3480
3494
  return;
3481
3495
  }
3482
3496
  if (envelope.a === "feishu.approval.confirm" || envelope.k === "quick") {
@@ -3492,12 +3506,14 @@ async function handleFeishuCardAction(params) {
3492
3506
  return;
3493
3507
  }
3494
3508
  await dispatchSyntheticCommand(decoded.text);
3509
+ } catch (error) {
3510
+ if (claim.kind === "claimed" && !commandDispatched) claim.handle.release({ error });
3511
+ throw error;
3495
3512
  } finally {
3496
- refreshFeishuCardActionToken(tokenKey);
3513
+ if (claim.kind === "claimed") await claim.handle.commit();
3497
3514
  }
3498
3515
  }
3499
- //#endregion
3500
- //#region extensions/feishu/src/feishu-ingress.ts
3516
+ // extensions/feishu/src/feishu-ingress.ts
3501
3517
  const FEISHU_INGRESS_PAYLOAD_VERSION = 1;
3502
3518
  const FEISHU_INGRESS_POLL_INTERVAL_MS = 500;
3503
3519
  const FEISHU_DURABLE_EVENT_TYPES = /* @__PURE__ */ new Set(["drive.notice.comment_add_v1", "im.message.receive_v1"]);
@@ -3593,6 +3609,21 @@ function buildFeishuFlushIngressLifecycle(sources, options) {
3593
3609
  releaseReplayClaims();
3594
3610
  await transportLifecycle.onAbandoned();
3595
3611
  };
3612
+ const commitReplayClaims = async () => {
3613
+ const results = await Promise.allSettled(replayClaims.map((claim) => claim.commit()));
3614
+ for (const result of results) if (result.status === "rejected") options?.onReplayCommitError?.(result.reason);
3615
+ };
3616
+ const dropAll = async (reason) => {
3617
+ if (settled) return;
3618
+ settled = true;
3619
+ try {
3620
+ await transportLifecycle.onDropped?.(reason);
3621
+ } catch (error) {
3622
+ releaseReplayClaims();
3623
+ throw error;
3624
+ }
3625
+ await commitReplayClaims();
3626
+ };
3596
3627
  const adoptAll = async () => {
3597
3628
  if (settled) return;
3598
3629
  settled = true;
@@ -3603,8 +3634,7 @@ function buildFeishuFlushIngressLifecycle(sources, options) {
3603
3634
  await Promise.resolve(transportLifecycle.onAbandoned()).catch(() => void 0);
3604
3635
  throw error;
3605
3636
  }
3606
- const results = await Promise.allSettled(replayClaims.map((claim) => claim.commit()));
3607
- for (const result of results) if (result.status === "rejected") options?.onReplayCommitError?.(result.reason);
3637
+ await commitReplayClaims();
3608
3638
  };
3609
3639
  return {
3610
3640
  lifecycle: {
@@ -3627,18 +3657,22 @@ function buildFeishuFlushIngressLifecycle(sources, options) {
3627
3657
  onAbandoned: async () => {
3628
3658
  handedOff = true;
3629
3659
  await abandonAll();
3630
- }
3660
+ },
3661
+ onDropped: transportLifecycle.onDropped ? async (reason) => {
3662
+ handedOff = true;
3663
+ await dropAll(reason);
3664
+ } : void 0
3631
3665
  },
3632
3666
  settle: async () => {
3633
3667
  if (handedOff) return;
3634
3668
  handedOff = true;
3669
+ settled = true;
3635
3670
  releaseReplayClaims();
3636
3671
  try {
3637
3672
  transportLifecycle.onAdoptionFinalizing();
3638
3673
  await transportLifecycle.onAdopted();
3639
- settled = true;
3640
3674
  } catch (error) {
3641
- await abandonAll().catch(() => void 0);
3675
+ await Promise.resolve(transportLifecycle.onAbandoned()).catch(() => void 0);
3642
3676
  throw error;
3643
3677
  }
3644
3678
  }
@@ -3671,18 +3705,49 @@ function createFeishuDurableIngress(options) {
3671
3705
  createClaimError: (kind, claim) => new FeishuIngressPermanentError("invalid-event", kind === "invalid-version" ? `Feishu ingress row ${claim.id} has an unsupported version.` : `Feishu ingress row ${claim.id} has invalid delivery identity.`)
3672
3706
  },
3673
3707
  deliver: async (rawEnvelope, lifecycle, claim) => {
3708
+ const handoff = createDeferred$1();
3674
3709
  const wrappedLifecycle = {
3675
3710
  ...lifecycle,
3711
+ onDeferred: () => {
3712
+ lifecycle.onDeferred();
3713
+ handoff.resolve();
3714
+ },
3715
+ onAdopted: async () => {
3716
+ try {
3717
+ await lifecycle.onAdopted();
3718
+ } finally {
3719
+ handoff.resolve();
3720
+ }
3721
+ },
3676
3722
  onAbandoned: async () => {
3677
- await Promise.resolve().then(() => wrappedLifecycle.onBeforeAbandon?.()).catch(() => void 0);
3678
- await lifecycle.onAbandoned();
3723
+ try {
3724
+ await Promise.resolve().then(() => wrappedLifecycle.onBeforeAbandon?.()).catch(() => void 0);
3725
+ await lifecycle.onAbandoned();
3726
+ } finally {
3727
+ handoff.resolve();
3728
+ }
3729
+ },
3730
+ onDropped: async (reason) => {
3731
+ try {
3732
+ await lifecycle.onDropped?.(reason);
3733
+ } finally {
3734
+ handoff.resolve();
3735
+ }
3679
3736
  }
3680
3737
  };
3681
3738
  activeLifecycles.set(claim.id, wrappedLifecycle);
3682
3739
  try {
3683
3740
  const result = await options.dispatcher.invoke(parseRawEnvelope(rawEnvelope), { needCheck: false });
3684
3741
  if (!isRecord$1(result)) return;
3685
- if (result.kind === "deferred") return { kind: "deferred" };
3742
+ if (result.kind === "deferred") {
3743
+ try {
3744
+ await racePromiseWithAbortSignal(handoff.promise, lifecycle.abortSignal);
3745
+ } catch (error) {
3746
+ await wrappedLifecycle.onAbandoned();
3747
+ throw error;
3748
+ }
3749
+ return { kind: "deferred" };
3750
+ }
3686
3751
  if (result.kind === "completed") return { kind: "completed" };
3687
3752
  if (result.kind === "failed-retryable") return {
3688
3753
  kind: "failed-retryable",
@@ -3697,6 +3762,7 @@ function createFeishuDurableIngress(options) {
3697
3762
  pollIntervalMs: options.pollIntervalMs ?? FEISHU_INGRESS_POLL_INTERVAL_MS,
3698
3763
  retention: "standard",
3699
3764
  drain: {
3765
+ deferredLaneOccupancy: "release",
3700
3766
  adoptionStallTimeoutMs: options.adoptionStallTimeoutMs ?? DEFAULT_INGRESS_ADOPTION_STALL_MS,
3701
3767
  resolveNonRetryableFailure: resolveFeishuIngressNonRetryableFailure,
3702
3768
  onLog: (message) => options.runtime.error?.(`feishu ingress: ${message}`)
@@ -3749,8 +3815,7 @@ function createFeishuDurableIngress(options) {
3749
3815
  waitForIdle: monitor.waitForIdle
3750
3816
  };
3751
3817
  }
3752
- //#endregion
3753
- //#region extensions/feishu/src/monitor.state.ts
3818
+ // extensions/feishu/src/monitor.state.ts
3754
3819
  const botOpenIds = /* @__PURE__ */ new Map();
3755
3820
  const FEISHU_WEBHOOK_MAX_BODY_BYTES = 65536;
3756
3821
  const FEISHU_WEBHOOK_BODY_TIMEOUT_MS = 5e3;
@@ -3771,8 +3836,7 @@ function recordWebhookStatus(runtime, accountId, path, statusCode) {
3771
3836
  message: (count) => `${label}: webhook anomaly path=${path} status=${statusCode} count=${count}`
3772
3837
  });
3773
3838
  }
3774
- //#endregion
3775
- //#region extensions/feishu/src/monitor.bot-identity.ts
3839
+ // extensions/feishu/src/monitor.bot-identity.ts
3776
3840
  const BOT_IDENTITY_RETRY_DELAYS_MS = [
3777
3841
  6e4,
3778
3842
  12e4,
@@ -3814,8 +3878,7 @@ function startBotIdentityRecovery(params) {
3814
3878
  (runtime?.error ?? console.error)(`feishu[${accountId}]: bot identity background retry failed unexpectedly: ${String(err)}`);
3815
3879
  });
3816
3880
  }
3817
- //#endregion
3818
- //#region extensions/feishu/src/monitor.comment.ts
3881
+ // extensions/feishu/src/monitor.comment.ts
3819
3882
  const FEISHU_COMMENT_VERIFY_TIMEOUT_MS = 3e3;
3820
3883
  const FEISHU_COMMENT_PAGE_SIZE = 100;
3821
3884
  const FEISHU_COMMENT_PAGE_LIMIT = 5;
@@ -3975,7 +4038,7 @@ async function resolveDriveCommentEventTurn(params) {
3975
4038
  logger?.(`feishu[${accountId}]: ignoring self-authored drive comment notice event=${eventId} sender=${senderId}`);
3976
4039
  return null;
3977
4040
  }
3978
- const client = createFeishuClient((await import("./doctor-contract-CPh2u5-o.mjs").then((n) => n.l)).resolveFeishuAccount({
4041
+ const client = createFeishuClient((await import("./doctor-contract-ItAh0keT.mjs").then((n) => n.l)).resolveFeishuAccount({
3979
4042
  cfg,
3980
4043
  accountId
3981
4044
  }));
@@ -4241,8 +4304,7 @@ function parseFeishuDriveCommentNoticeEventPayload(value) {
4241
4304
  type: readStringValue(value.type)
4242
4305
  };
4243
4306
  }
4244
- //#endregion
4245
- //#region extensions/feishu/src/comment-handler.ts
4307
+ // extensions/feishu/src/comment-handler.ts
4246
4308
  function parseTimestampMs(value) {
4247
4309
  return parseStrictNonNegativeInteger(value) ?? Date.now();
4248
4310
  }
@@ -4551,8 +4613,7 @@ async function handleFeishuCommentEvent(params) {
4551
4613
  typingReaction.cleanup();
4552
4614
  }
4553
4615
  }
4554
- //#endregion
4555
- //#region extensions/feishu/src/sequential-queue.ts
4616
+ // extensions/feishu/src/sequential-queue.ts
4556
4617
  const DEFAULT_TASK_TIMEOUT_MS = 3e5;
4557
4618
  function createSequentialQueue(options = {}) {
4558
4619
  const queues = /* @__PURE__ */ new Map();
@@ -4565,8 +4626,7 @@ function createSequentialQueue(options = {}) {
4565
4626
  })
4566
4627
  });
4567
4628
  }
4568
- //#endregion
4569
- //#region extensions/feishu/src/monitor.comment-notice-handler.ts
4629
+ // extensions/feishu/src/monitor.comment-notice-handler.ts
4570
4630
  function createFeishuDriveCommentNoticeHandler(params) {
4571
4631
  const { cfg, accountId, runtime, fireAndForget, abortSignal } = params;
4572
4632
  const error = runtime?.error ?? console.error;
@@ -4614,8 +4674,7 @@ function createFeishuDriveCommentNoticeHandler(params) {
4614
4674
  await settle();
4615
4675
  };
4616
4676
  }
4617
- //#endregion
4618
- //#region extensions/feishu/src/monitor.message-handler.ts
4677
+ // extensions/feishu/src/monitor.message-handler.ts
4619
4678
  function parseFeishuMessageEventPayload(value) {
4620
4679
  if (!isRecord(value)) return null;
4621
4680
  const sender = value.sender;
@@ -4869,8 +4928,7 @@ function createFeishuMessageReceiveHandler({ cfg, channelRuntime, accountId, run
4869
4928
  if (!fireAndForget) await processing;
4870
4929
  };
4871
4930
  }
4872
- //#endregion
4873
- //#region extensions/feishu/src/monitor-rate-limit-key.ts
4931
+ // extensions/feishu/src/monitor-rate-limit-key.ts
4874
4932
  function normalizeFeishuWebhookRateLimitClient(clientIp) {
4875
4933
  if (!clientIp) return "unknown";
4876
4934
  if (clientIp === "::1" || clientIp.startsWith("127.")) return "loopback";
@@ -4879,8 +4937,7 @@ function normalizeFeishuWebhookRateLimitClient(clientIp) {
4879
4937
  function buildFeishuWebhookRateLimitKey(params) {
4880
4938
  return `${params.accountId === void 0 ? params.path : `${params.accountId}:${params.path}`}:${normalizeFeishuWebhookRateLimitClient(params.clientIp)}`;
4881
4939
  }
4882
- //#endregion
4883
- //#region extensions/feishu/src/monitor.transport.ts
4940
+ // extensions/feishu/src/monitor.transport.ts
4884
4941
  const FEISHU_WEBHOOK_ACCEPTED_HEADER = "x-openclaw-delivery-accepted";
4885
4942
  const FEISHU_WEBHOOK_ACCEPTED_VALUE = "durable";
4886
4943
  const FEISHU_PRE_AUTH_MAX_IN_FLIGHT = 64;
@@ -5254,8 +5311,7 @@ async function monitorWebhook(params) {
5254
5311
  await cleanup();
5255
5312
  }
5256
5313
  }
5257
- //#endregion
5258
- //#region extensions/feishu/src/monitor.vc-meeting-invited-handler.ts
5314
+ // extensions/feishu/src/monitor.vc-meeting-invited-handler.ts
5259
5315
  const FEISHU_MEETING_NUMBER_PATTERN = /^\d{9}$/;
5260
5316
  function parseInviteTimestamp(value) {
5261
5317
  const parsed = Number.parseInt(value ?? "", 10);
@@ -5383,8 +5439,7 @@ function createFeishuVcMeetingInvitedHandler(params) {
5383
5439
  return fireAndForget ? Promise.resolve() : task;
5384
5440
  };
5385
5441
  }
5386
- //#endregion
5387
- //#region extensions/feishu/src/sequential-key.ts
5442
+ // extensions/feishu/src/sequential-key.ts
5388
5443
  function getFeishuSequentialKey(params) {
5389
5444
  const { accountId, event, botOpenId, preparedContent, isControlCommandMessage } = params;
5390
5445
  const baseKey = `feishu:${accountId}:${event.message.chat_id?.trim() || "unknown"}`;
@@ -5393,8 +5448,7 @@ function getFeishuSequentialKey(params) {
5393
5448
  if (isBtwRequestText(text)) return `${baseKey}:btw`;
5394
5449
  return isControlCommandMessage(text) ? `${baseKey}:commands` : baseKey;
5395
5450
  }
5396
- //#endregion
5397
- //#region extensions/feishu/src/monitor.account.ts
5451
+ // extensions/feishu/src/monitor.account.ts
5398
5452
  const FEISHU_QUICK_ACTION_CARD_TTL_MS = 6e5;
5399
5453
  const QUICK_ACTION_MENU_KEYS = /* @__PURE__ */ new Set([
5400
5454
  "quick-actions",
@@ -5410,14 +5464,13 @@ async function resolveReactionSyntheticEvent(params) {
5410
5464
  const senderUserId = event.user_id?.user_id?.trim();
5411
5465
  const senderId = senderOpenId || senderUserId;
5412
5466
  if (!emoji || !messageId || !senderId) return null;
5413
- const { resolveFeishuAccount } = await import("./doctor-contract-CPh2u5-o.mjs").then((n) => n.l);
5414
- const reactionNotifications = resolveFeishuAccount({
5467
+ const { resolveFeishuAccount } = await import("./doctor-contract-ItAh0keT.mjs").then((n) => n.l);
5468
+ const account = resolveFeishuAccount({
5415
5469
  cfg,
5416
5470
  accountId
5417
- }).config.reactionNotifications;
5418
- if (reactionNotifications === "off") return null;
5419
- if (event.operator_type === "app" || senderId === botOpenId) return null;
5420
- if (emoji === "Typing") return null;
5471
+ });
5472
+ const reactionNotifications = account.config.reactionNotifications;
5473
+ if (reactionNotifications === "off" || event.operator_type === "app" || senderId === botOpenId || emoji === "Typing") return null;
5421
5474
  if (reactionNotifications === "own" && !botOpenId) {
5422
5475
  logger?.(`feishu[${accountId}]: bot open_id unavailable, skipping reaction ${emoji} on ${messageId}`);
5423
5476
  return null;
@@ -5432,13 +5485,16 @@ async function resolveReactionSyntheticEvent(params) {
5432
5485
  logger?.(`feishu[${accountId}]: ignoring reaction on non-bot/unverified message ${messageId} (sender: ${reactedMsg?.senderOpenId ?? "unknown"})`);
5433
5486
  return null;
5434
5487
  }
5435
- const resolvedChatType = normalizeFeishuEventChatType(event.chat_type) ?? reactedMsg.chatType;
5488
+ const syntheticChatIdRaw = event.chat_id?.trim() || reactedMsg.chatId?.trim();
5489
+ let resolvedChatType = normalizeFeishuEventChatType(event.chat_type) ?? reactedMsg.chatType;
5490
+ if (!resolvedChatType && syntheticChatIdRaw) {
5491
+ const chatInfo = await raceWithTimeoutAndAbort(getChatInfo(createFeishuClient(account), syntheticChatIdRaw), { timeoutMs: FEISHU_REACTION_VERIFY_TIMEOUT_MS }).catch(() => null);
5492
+ resolvedChatType = chatInfo?.status === "resolved" ? resolveFeishuChatType(chatInfo.value) : void 0;
5493
+ }
5436
5494
  if (!resolvedChatType) {
5437
5495
  logger?.(`feishu[${accountId}]: skipping reaction ${emoji} on ${messageId} without chat type context`);
5438
5496
  return null;
5439
5497
  }
5440
- const syntheticChatIdRaw = event.chat_id ?? reactedMsg.chatId;
5441
- const syntheticChatId = syntheticChatIdRaw?.trim() ? syntheticChatIdRaw : `p2p:${senderId}`;
5442
5498
  return {
5443
5499
  sender: {
5444
5500
  sender_id: {
@@ -5453,7 +5509,7 @@ async function resolveReactionSyntheticEvent(params) {
5453
5509
  typing_target_message_id: messageId,
5454
5510
  ...reactedMsg.rootId ? { root_id: reactedMsg.rootId } : {},
5455
5511
  ...reactedMsg.threadId ? { thread_id: reactedMsg.threadId } : {},
5456
- chat_id: syntheticChatId,
5512
+ chat_id: syntheticChatIdRaw || `p2p:${senderId}`,
5457
5513
  chat_type: resolvedChatType,
5458
5514
  message_type: "text",
5459
5515
  content: JSON.stringify({ text: action === "deleted" ? `[removed reaction ${emoji} from message ${messageId}]` : `[reacted with ${emoji} to message ${messageId}]` })
@@ -5832,5 +5888,4 @@ async function monitorSingleAccount(params) {
5832
5888
  threadBindingManager?.stop();
5833
5889
  }
5834
5890
  }
5835
- //#endregion
5836
5891
  export { monitorSingleAccount, resolveReactionSyntheticEvent };