@openclaw/feishu 2026.11.5 → 2026.11.10-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.setup/{app-registration-DhnIp0Kd.mjs → app-registration-CBgQSu2L.mjs} +1 -2
- package/dist/.setup/async-WkOXCAZ1.mjs +32 -0
- package/dist/.setup/{channel-TBw3rO3z.mjs → channel-mDZxm2Gc.mjs} +125 -128
- package/dist/.setup/{channel.runtime-uAj58l3V.mjs → channel.runtime-DCooVws1.mjs} +10 -14
- package/dist/.setup/{chat-g8dTUdIb.mjs → chat-XINRHAOR.mjs} +3 -4
- package/dist/.setup/{client-DqGMyzOi.mjs → client-BAiJnY41.mjs} +4 -7
- package/dist/.setup/{conversation-id-BLsHZ7pf.mjs → conversation-id-N6q3vKm-.mjs} +2 -4
- package/dist/.setup/{doctor-contract-CPh2u5-o.mjs → doctor-contract-ItAh0keT.mjs} +10 -20
- package/dist/.setup/{message-action-contract-DMVMY_ng.mjs → message-action-contract-BZK6bpAl.mjs} +1 -2
- package/dist/.setup/{monitor-CqBu27Nc.mjs → monitor-DIBB2_Y_.mjs} +7 -10
- package/dist/.setup/{monitor.account-B6_SNuhx.mjs → monitor.account-B_qIOniw.mjs} +375 -296
- package/dist/.setup/{probe-CbNVGjv_.mjs → probe-DMOl26H9.mjs} +11 -41
- package/dist/.setup/{reply-delivery-result-BjOCvaPo.mjs → reply-delivery-result-Dcan9Dz_.mjs} +211 -150
- package/dist/.setup/{runtime-C5JxBWZp.mjs → runtime-6V3uDMw5.mjs} +1 -2
- package/dist/.setup/runtime-setter-api-DSLLnejl.mjs +2 -0
- package/dist/.setup/{secret-contract-Do6HTIFT.mjs → secret-contract-BAucuP6O.mjs} +1 -2
- package/dist/.setup/{secret-contract-api-LwCXK5Qg.mjs → secret-contract-api-DR5mIHhJ.mjs} +1 -1
- package/dist/.setup/{security-audit-b86aSgH2.mjs → security-audit-CYRW0D76.mjs} +1 -2
- package/dist/.setup/{session-conversation-CM3UgYZY.mjs → session-conversation-DLgXP0-H.mjs} +2 -3
- package/dist/.setup/{setup-api-DWvNh6et.mjs → setup-api-DR15GZv5.mjs} +1 -1
- package/dist/.setup/{subagent-hooks-DdiyEIi7.mjs → subagent-hooks-BRem84Mh.mjs} +4 -5
- package/dist/.setup/{thread-bindings-BxKmOara.mjs → thread-bindings-6eyktxK_.mjs} +1 -2
- package/dist/.source-module-urls/6579f1b33dd01f8f0aaea28311ed6df1a635f9ad1e6fa86dcba53bca46407e55.json +1 -1
- package/dist/api.js +28 -33
- package/dist/channel-entry.js +1 -2
- package/dist/channel-plugin-api.js +1 -1
- package/dist/configured-state.js +1 -2
- package/dist/contract-api.js +3 -3
- package/dist/doctor-contract-api.js +1 -1
- package/dist/index.js +1 -2
- package/dist/runtime-api.js +2 -2
- package/dist/runtime-setter-api.js +1 -1
- package/dist/secret-contract-api.js +1 -1
- package/dist/security-contract-api.js +1 -1
- package/dist/session-binding-contract-api.js +1 -1
- package/dist/session-key-api.js +1 -1
- package/dist/setup-api.js +1 -1
- package/dist/setup-entry.js +4 -5
- package/dist/subagent-hooks-api.js +2 -3
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/README.md +41 -106
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/axios.js +931 -278
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/axios.min.js +2 -2
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/axios.min.js.map +1 -1
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/browser/axios.cjs +948 -268
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/esm/axios.js +948 -268
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/esm/axios.min.js +2 -2
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/esm/axios.min.js.map +1 -1
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/dist/node/axios.cjs +925 -242
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/index.d.cts +20 -1
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/index.d.ts +18 -1
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/adapters/fetch.js +73 -20
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/adapters/http.js +145 -26
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/adapters/xhr.js +120 -13
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/Axios.js +67 -12
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/AxiosError.js +59 -0
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/AxiosHeaders.js +17 -4
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/InterceptorManager.js +13 -2
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/assertParamsAcyclic.js +49 -0
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/createMultipartBody.js +37 -0
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/dispatchRequest.js +20 -0
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/core/mergeConfig.js +183 -120
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/defaults/transitional.js +1 -0
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/env/data.js +1 -1
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/AxiosTransformStream.js +11 -2
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/Http2Sessions.js +2 -1
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/composeSignals.js +6 -3
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/cookies.js +30 -6
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js +34 -7
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/formDataToBlob.js +113 -0
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/formDataToJSON.js +25 -1
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/fromDataURI.js +8 -2
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/isURLSameOrigin.js +4 -9
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/parseHeaders.js +2 -1
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/parseProtocol.js +1 -1
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/resolveConfig.js +16 -3
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/helpers/shouldBypassProxy.js +16 -1
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/lib/utils.js +61 -10
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/axios/package.json +1 -2
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/follow-redirects/README.md +27 -1
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/follow-redirects/index.js +1 -5
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/follow-redirects/package.json +1 -1
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/.editorconfig +1 -1
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/CHANGELOG.md +87 -22
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/README.md +63 -10
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/dist/qs.js +17 -17
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/eslint.config.mjs +61 -50
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/lib/formats.js +7 -2
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/lib/parse.js +29 -10
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/lib/stringify.js +5 -3
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/lib/utils.js +28 -9
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/package.json +6 -6
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/test/parse.js +335 -2
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/test/stringify.js +222 -0
- package/node_modules/@larksuiteoapi/node-sdk/node_modules/qs/test/utils.js +61 -3
- package/node_modules/typebox/build/format/date_time.d.mts +2 -1
- package/node_modules/typebox/build/format/date_time.mjs +12 -3
- package/node_modules/typebox/package.json +1 -1
- package/openclaw.plugin.json +5 -0
- package/package.json +5 -5
- 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-
|
|
2
|
-
import { c as resolveFeishuLegacyWebhookListener, l as gateway_config_runtime_exports, s as describeFeishuWebhookPathConflict } from "./channel-
|
|
3
|
-
import { o as resolveConfiguredFeishuGroupSessionScope, t as buildFeishuConversationId, u as resolveReceiveIdType } from "./conversation-id-
|
|
4
|
-
import { A as sendMessageFeishu, At as
|
|
5
|
-
import { t as getFeishuRuntime } from "./runtime-
|
|
6
|
-
import { a as getFeishuUserAgent, f as resolveConfiguredHttpTimeoutMs, i as createFeishuWSClient, n as createEventDispatcher, r as createFeishuClient } from "./client-
|
|
7
|
-
import { t as
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { t as fetchBotIdentityForMonitor } from "./monitor-
|
|
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-mDZxm2Gc.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-DIBB2_Y_.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,12 +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";
|
|
40
|
+
import { resolveOutboundMediaAccessForConfig } from "openclaw/plugin-sdk/outbound-media";
|
|
39
41
|
import { readProviderJsonResponse } from "openclaw/plugin-sdk/provider-http";
|
|
40
|
-
import crypto, * as crypto$1 from "node:crypto";
|
|
41
42
|
import { createChannelHistoryWindow } from "openclaw/plugin-sdk/reply-history";
|
|
42
43
|
import { createChannelReplayGuard } from "openclaw/plugin-sdk/persistent-dedupe";
|
|
43
44
|
import { sha256Hex } from "openclaw/plugin-sdk/node-crypto-runtime";
|
|
@@ -45,6 +46,7 @@ import { resolveChannelConfigWrites } from "openclaw/plugin-sdk/channel-config-w
|
|
|
45
46
|
import { formatReasoningMessage, resolveHumanDelayConfig } from "openclaw/plugin-sdk/agent-runtime";
|
|
46
47
|
import { logTypingFailure } from "openclaw/plugin-sdk/channel-feedback";
|
|
47
48
|
import { getGlobalHookRunner } from "openclaw/plugin-sdk/plugin-runtime";
|
|
49
|
+
import { createDeferred as createDeferred$1 } from "openclaw/plugin-sdk/concurrency-runtime";
|
|
48
50
|
import { WEBHOOK_RATE_LIMIT_DEFAULTS, applyBasicWebhookRequestGuards, createFixedWindowRateLimiter, createWebhookAnomalyTracker, getWebhookLegacyListener, resolveRequestClientIp } from "openclaw/plugin-sdk/webhook-ingress";
|
|
49
51
|
import { enqueueKeyedTask } from "openclaw/plugin-sdk/keyed-async-queue";
|
|
50
52
|
import { createRuntimeConfigReader } from "openclaw/plugin-sdk/runtime-config-snapshot";
|
|
@@ -53,7 +55,7 @@ import { sendJson } from "openclaw/plugin-sdk/http-response-runtime";
|
|
|
53
55
|
import { createWebhookInFlightLimiter, readWebhookBodyOrReject, sendHttpRequestRejection } from "openclaw/plugin-sdk/webhook-request-guards";
|
|
54
56
|
import { canonicalizeWebhookRouteKey, registerPluginHttpRoute, registerWebhookTarget, resolveSingleWebhookTarget } from "openclaw/plugin-sdk/webhook-targets";
|
|
55
57
|
import { isAbortRequestText, isBtwRequestText } from "openclaw/plugin-sdk/command-primitives-runtime";
|
|
56
|
-
|
|
58
|
+
// src/channels/mention-gating.ts
|
|
57
59
|
function resolveBotThreadMentionPolicy(params) {
|
|
58
60
|
if (!params.isBotOwnedThread || params.requireMentionInBotThreads === void 0) return {
|
|
59
61
|
requireMention: params.requireMention,
|
|
@@ -64,8 +66,7 @@ function resolveBotThreadMentionPolicy(params) {
|
|
|
64
66
|
implicitMentionKinds: params.requireMentionInBotThreads ? params.implicitMentionKinds?.filter((kind) => kind === "native") : params.implicitMentionKinds
|
|
65
67
|
};
|
|
66
68
|
}
|
|
67
|
-
|
|
68
|
-
//#region extensions/feishu/src/bot-agent-body.ts
|
|
69
|
+
// extensions/feishu/src/bot-agent-body.ts
|
|
69
70
|
const MAX_MENTION_CONTEXT_NAME_LENGTH = 80;
|
|
70
71
|
function formatMentionNameForAgentContext(name) {
|
|
71
72
|
const normalized = Array.from(name, (char) => {
|
|
@@ -95,14 +96,73 @@ function buildFeishuAgentBody(params) {
|
|
|
95
96
|
}
|
|
96
97
|
return messageBody;
|
|
97
98
|
}
|
|
98
|
-
|
|
99
|
-
|
|
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
|
|
100
159
|
function createFeishuBroadcastIngressSettlement(params) {
|
|
101
160
|
const lanes = /* @__PURE__ */ new Set();
|
|
102
161
|
const failures = [];
|
|
103
162
|
const fallbackAbort = new AbortController();
|
|
104
163
|
let fanoutSettled = false;
|
|
105
164
|
let terminal;
|
|
165
|
+
let dropReason;
|
|
106
166
|
let terminalSettled = false;
|
|
107
167
|
let finalizing = false;
|
|
108
168
|
let deferred = false;
|
|
@@ -126,10 +186,19 @@ function createFeishuBroadcastIngressSettlement(params) {
|
|
|
126
186
|
params.onReplayCommitError?.(error);
|
|
127
187
|
} catch {}
|
|
128
188
|
};
|
|
189
|
+
const notifyAdopted = () => {
|
|
190
|
+
try {
|
|
191
|
+
params.onAdopted?.();
|
|
192
|
+
} catch {}
|
|
193
|
+
};
|
|
129
194
|
const abandon = async (error) => {
|
|
130
195
|
if (terminal) return;
|
|
131
|
-
terminal =
|
|
196
|
+
terminal = {
|
|
197
|
+
kind: "abandoned",
|
|
198
|
+
error
|
|
199
|
+
};
|
|
132
200
|
params.replayClaim?.release({ error });
|
|
201
|
+
for (const lane of lanes) if (lane.status === "dropped") lane.replayClaim?.release({ error });
|
|
133
202
|
try {
|
|
134
203
|
await params.lifecycle?.onAbandoned();
|
|
135
204
|
} finally {
|
|
@@ -138,15 +207,50 @@ function createFeishuBroadcastIngressSettlement(params) {
|
|
|
138
207
|
finishSettlement();
|
|
139
208
|
}
|
|
140
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
|
+
};
|
|
141
247
|
const adopt = async () => {
|
|
142
248
|
if (terminal) return;
|
|
143
|
-
terminal = "adopted";
|
|
249
|
+
terminal = { kind: "adopted" };
|
|
144
250
|
try {
|
|
145
251
|
beginFinalizing();
|
|
146
252
|
await params.lifecycle?.onAdopted();
|
|
147
|
-
|
|
148
|
-
params.onAdopted?.();
|
|
149
|
-
} catch {}
|
|
253
|
+
notifyAdopted();
|
|
150
254
|
try {
|
|
151
255
|
await params.replayClaim?.commit();
|
|
152
256
|
} catch (error) {
|
|
@@ -167,7 +271,11 @@ function createFeishuBroadcastIngressSettlement(params) {
|
|
|
167
271
|
await abandon(failures.length === 1 ? failures[0] : new AggregateError(failures, "Feishu broadcast dispatch failed"));
|
|
168
272
|
return;
|
|
169
273
|
}
|
|
170
|
-
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
|
+
}
|
|
171
279
|
await adopt();
|
|
172
280
|
};
|
|
173
281
|
return {
|
|
@@ -181,7 +289,7 @@ function createFeishuBroadcastIngressSettlement(params) {
|
|
|
181
289
|
lifecycle: {
|
|
182
290
|
abortSignal: params.lifecycle?.abortSignal ?? fallbackAbort.signal,
|
|
183
291
|
onAdopted: async () => {
|
|
184
|
-
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;
|
|
185
293
|
lane.adopting = true;
|
|
186
294
|
try {
|
|
187
295
|
beginFinalizing();
|
|
@@ -206,11 +314,21 @@ function createFeishuBroadcastIngressSettlement(params) {
|
|
|
206
314
|
deferredHeartbeatIntervalMs: params.lifecycle?.deferredHeartbeatIntervalMs,
|
|
207
315
|
onAdoptionFinalizing: beginFinalizing,
|
|
208
316
|
onAbandoned: async () => {
|
|
209
|
-
if (lane.adopting || lane.status === "completed" || lane.status === "failed") return;
|
|
317
|
+
if (lane.adopting || lane.status === "completed" || lane.status === "dropped" || lane.status === "failed") return;
|
|
210
318
|
lane.status = "failed";
|
|
211
319
|
lane.replayClaim?.release({ error: /* @__PURE__ */ new Error("feishu-broadcast-turn-abandoned") });
|
|
212
320
|
await maybeSettle();
|
|
213
|
-
}
|
|
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
|
|
214
332
|
},
|
|
215
333
|
onDispatchComplete: async (dispatched) => {
|
|
216
334
|
if (lane.adopting || lane.status !== "pending") return;
|
|
@@ -221,7 +339,7 @@ function createFeishuBroadcastIngressSettlement(params) {
|
|
|
221
339
|
},
|
|
222
340
|
onDispatchFailed: async (error) => {
|
|
223
341
|
failures.push(error);
|
|
224
|
-
if (!lane.adopting && lane.status !== "completed") {
|
|
342
|
+
if (!lane.adopting && lane.status !== "completed" && lane.status !== "dropped") {
|
|
225
343
|
lane.status = "failed";
|
|
226
344
|
lane.replayClaim?.release({ error });
|
|
227
345
|
}
|
|
@@ -241,6 +359,24 @@ function createFeishuBroadcastIngressSettlement(params) {
|
|
|
241
359
|
}
|
|
242
360
|
};
|
|
243
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
|
+
}
|
|
244
380
|
function resolveBroadcastAgents(cfg, peerId) {
|
|
245
381
|
const agents = cfg.broadcast?.[peerId];
|
|
246
382
|
return Array.isArray(agents) && agents.length > 0 ? agents : null;
|
|
@@ -249,8 +385,7 @@ function buildBroadcastSessionKey(baseSessionKey, originalAgentId, targetAgentId
|
|
|
249
385
|
const prefix = `agent:${originalAgentId}:`;
|
|
250
386
|
return baseSessionKey.startsWith(prefix) ? `agent:${targetAgentId}:${baseSessionKey.slice(prefix.length)}` : baseSessionKey;
|
|
251
387
|
}
|
|
252
|
-
|
|
253
|
-
//#region extensions/feishu/src/bot-content.ts
|
|
388
|
+
// extensions/feishu/src/bot-content.ts
|
|
254
389
|
function resolveFeishuGroupSession(params) {
|
|
255
390
|
const { chatId, senderOpenId, messageId, rootId, threadId, chatType, groupConfig, feishuCfg } = params;
|
|
256
391
|
const normalizedThreadId = threadId?.trim();
|
|
@@ -352,7 +487,8 @@ function checkBotMentioned(event, botOpenId) {
|
|
|
352
487
|
return false;
|
|
353
488
|
}
|
|
354
489
|
function normalizeFeishuCommandProbeBody(text) {
|
|
355
|
-
|
|
490
|
+
const body = text.replace(/<at\b[^>]*>[^<]*<\/at>/giu, " ").replace(/(^|\s)@[^/\s]+(?=\s|$|\/)/gu, "$1").trim();
|
|
491
|
+
return body.startsWith("/") && /[\r\n]/.test(body) ? body : body.replace(/\s+/g, " ");
|
|
356
492
|
}
|
|
357
493
|
function parseMediaResource(content, messageType) {
|
|
358
494
|
try {
|
|
@@ -439,15 +575,13 @@ async function resolveFeishuMediaList(params) {
|
|
|
439
575
|
}
|
|
440
576
|
return out;
|
|
441
577
|
}
|
|
442
|
-
|
|
443
|
-
//#region extensions/feishu/src/bot-group-name-state.ts
|
|
578
|
+
// extensions/feishu/src/bot-group-name-state.ts
|
|
444
579
|
const feishuGroupNameCache = createStaleWhileRevalidateCache({
|
|
445
580
|
maxEntries: 500,
|
|
446
581
|
maxPending: Infinity,
|
|
447
582
|
ttlMs: 18e5
|
|
448
583
|
});
|
|
449
|
-
|
|
450
|
-
//#region extensions/feishu/src/bot-group-name.ts
|
|
584
|
+
// extensions/feishu/src/bot-group-name.ts
|
|
451
585
|
async function resolveGroupName(params) {
|
|
452
586
|
const { account, chatId, log } = params;
|
|
453
587
|
if (!account.configured) return;
|
|
@@ -461,8 +595,7 @@ async function resolveGroupName(params) {
|
|
|
461
595
|
}, { allowStale: false });
|
|
462
596
|
return value;
|
|
463
597
|
}
|
|
464
|
-
|
|
465
|
-
//#region extensions/feishu/src/bot-name.ts
|
|
598
|
+
// extensions/feishu/src/bot-name.ts
|
|
466
599
|
const POSITIVE_TTL_MS = 6e5;
|
|
467
600
|
const NEGATIVE_TTL_MS = 6e4;
|
|
468
601
|
const MAX_CACHE_ENTRIES = 5e3;
|
|
@@ -474,7 +607,7 @@ const inflight = /* @__PURE__ */ new Map();
|
|
|
474
607
|
function readCache(key) {
|
|
475
608
|
const entry = cache.get(key);
|
|
476
609
|
if (!entry) return;
|
|
477
|
-
if (entry.expiresAt <=
|
|
610
|
+
if (entry.expiresAt <= performance.now()) {
|
|
478
611
|
cache.delete(key);
|
|
479
612
|
return;
|
|
480
613
|
}
|
|
@@ -492,7 +625,7 @@ async function resolveFeishuBotName(params) {
|
|
|
492
625
|
if (!params.account.configured || !openId) return;
|
|
493
626
|
const backoffUntil = backoffUntilByAccount.get(params.account.accountId);
|
|
494
627
|
if (backoffUntil !== void 0) {
|
|
495
|
-
if (backoffUntil >
|
|
628
|
+
if (backoffUntil > performance.now()) return;
|
|
496
629
|
backoffUntilByAccount.delete(params.account.accountId);
|
|
497
630
|
}
|
|
498
631
|
const key = `${params.account.accountId}::${openId}`;
|
|
@@ -519,13 +652,13 @@ async function resolveFeishuBotName(params) {
|
|
|
519
652
|
else log(`feishu[${account.accountId}]: bot name lookup failed: ${String(error)}`);
|
|
520
653
|
}
|
|
521
654
|
if (!result) {
|
|
522
|
-
backoffUntilByAccount.set(account.accountId,
|
|
655
|
+
backoffUntilByAccount.set(account.accountId, performance.now() + LOOKUP_BACKOFF_MS);
|
|
523
656
|
return;
|
|
524
657
|
}
|
|
525
658
|
const name = result.data?.bots?.[openId]?.name?.trim();
|
|
526
659
|
writeCache(key, {
|
|
527
660
|
...name ? { name } : {},
|
|
528
|
-
expiresAt:
|
|
661
|
+
expiresAt: performance.now() + (name ? POSITIVE_TTL_MS : NEGATIVE_TTL_MS)
|
|
529
662
|
});
|
|
530
663
|
return name;
|
|
531
664
|
})();
|
|
@@ -536,8 +669,7 @@ async function resolveFeishuBotName(params) {
|
|
|
536
669
|
inflight.delete(key);
|
|
537
670
|
}
|
|
538
671
|
}
|
|
539
|
-
|
|
540
|
-
//#region extensions/feishu/src/bot-thread-mentions.ts
|
|
672
|
+
// extensions/feishu/src/bot-thread-mentions.ts
|
|
541
673
|
async function prepareFeishuThreadRoot(params) {
|
|
542
674
|
let { cfg, account } = params;
|
|
543
675
|
const { ctx, botOpenId, log } = params;
|
|
@@ -582,69 +714,7 @@ async function prepareFeishuThreadRoot(params) {
|
|
|
582
714
|
getRootMessageInfo
|
|
583
715
|
};
|
|
584
716
|
}
|
|
585
|
-
|
|
586
|
-
//#region extensions/feishu/src/dedup-state.ts
|
|
587
|
-
const DEDUPE_NAMESPACE_PREFIX = "feishu.dedup";
|
|
588
|
-
const DEDUP_TTL_MS = 864e5;
|
|
589
|
-
const MEMORY_MAX_SIZE = 1e3;
|
|
590
|
-
const STORE_MAX_ENTRIES = 1e4;
|
|
591
|
-
function createFeishuDedupeGuard() {
|
|
592
|
-
return createChannelReplayGuard({
|
|
593
|
-
dedupe: {
|
|
594
|
-
pluginId: "feishu",
|
|
595
|
-
namespacePrefix: DEDUPE_NAMESPACE_PREFIX,
|
|
596
|
-
ttlMs: DEDUP_TTL_MS,
|
|
597
|
-
memoryMaxSize: MEMORY_MAX_SIZE,
|
|
598
|
-
stateMaxEntries: STORE_MAX_ENTRIES
|
|
599
|
-
},
|
|
600
|
-
buildReplayKey: (messageId) => messageId
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
const feishuDedupeState = {
|
|
604
|
-
guard: createFeishuDedupeGuard(),
|
|
605
|
-
reset() {
|
|
606
|
-
this.guard = createFeishuDedupeGuard();
|
|
607
|
-
}
|
|
608
|
-
};
|
|
609
|
-
//#endregion
|
|
610
|
-
//#region extensions/feishu/src/dedup.ts
|
|
611
|
-
function dedupeOptions(namespace, log) {
|
|
612
|
-
return {
|
|
613
|
-
...namespace ? { namespace } : {},
|
|
614
|
-
...log ? { onDiskError: (error) => log(`feishu-dedup: persistent state error: ${String(error)}`) } : {}
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Claims a dedupe key for exclusive handling. Duplicate (already committed)
|
|
619
|
-
* and in-flight keys are reported; blank keys fail open as invalid so an
|
|
620
|
-
* unidentifiable event is never suppressed.
|
|
621
|
-
*/
|
|
622
|
-
async function claimUnprocessedFeishuMessage(params) {
|
|
623
|
-
return await feishuDedupeState.guard.claim(params.messageId, dedupeOptions(params.namespace, params.log));
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* Claims (unless the caller already holds the claim) and commits a message.
|
|
627
|
-
* False means another handler owns it, it was already handled, or the key is
|
|
628
|
-
* blank; handlers must skip dispatch then.
|
|
629
|
-
*/
|
|
630
|
-
async function finalizeFeishuMessageProcessing(params) {
|
|
631
|
-
const key = params.messageId?.trim();
|
|
632
|
-
if (!key) return false;
|
|
633
|
-
const options = dedupeOptions(params.namespace, params.log);
|
|
634
|
-
const claim = params.processingClaim ?? await feishuDedupeState.guard.claim(key, options);
|
|
635
|
-
if ("kind" in claim && claim.kind !== "claimed") return false;
|
|
636
|
-
return await ("kind" in claim ? claim.handle : claim).commit();
|
|
637
|
-
}
|
|
638
|
-
/** Checks recency without claiming or recording. */
|
|
639
|
-
async function hasProcessedFeishuMessage(messageId, namespace = "global", log) {
|
|
640
|
-
return await feishuDedupeState.guard.hasRecent(messageId, dedupeOptions(namespace, log));
|
|
641
|
-
}
|
|
642
|
-
/** Loads recent persisted entries into memory at account start; returns the loaded count. */
|
|
643
|
-
async function warmupDedupFromPluginState(namespace, log) {
|
|
644
|
-
return await feishuDedupeState.guard.warmup(namespace, (error) => log?.(`feishu-dedup: warmup persistent state error: ${String(error)}`));
|
|
645
|
-
}
|
|
646
|
-
//#endregion
|
|
647
|
-
//#region extensions/feishu/src/dedupe-key.ts
|
|
717
|
+
// extensions/feishu/src/dedupe-key.ts
|
|
648
718
|
function resolvePostMediaParts(content) {
|
|
649
719
|
const { attachments } = parsePostContent(content, { includeTopLevelFiles: false });
|
|
650
720
|
return ["image", "file"].flatMap((kind) => attachments.filter((attachment) => attachment.kind === kind).map((attachment) => `${kind}_key:${attachment.key}`));
|
|
@@ -696,8 +766,7 @@ function resolveFeishuMessageDedupeKey(event) {
|
|
|
696
766
|
}
|
|
697
767
|
return messageId;
|
|
698
768
|
}
|
|
699
|
-
|
|
700
|
-
//#region extensions/feishu/src/dynamic-agent.ts
|
|
769
|
+
// extensions/feishu/src/dynamic-agent.ts
|
|
701
770
|
var DynamicAgentMutationSkipped = class extends Error {
|
|
702
771
|
constructor(cfg) {
|
|
703
772
|
super("dynamic agent mutation skipped");
|
|
@@ -846,8 +915,7 @@ function resolveUserPath(p) {
|
|
|
846
915
|
if (p.startsWith("~/")) return path.join(os.homedir(), p.slice(2));
|
|
847
916
|
return p;
|
|
848
917
|
}
|
|
849
|
-
|
|
850
|
-
//#region extensions/feishu/src/reasoning-preview.ts
|
|
918
|
+
// extensions/feishu/src/reasoning-preview.ts
|
|
851
919
|
async function resolveFeishuReasoningPreviewEnabled(params) {
|
|
852
920
|
const configDefault = resolveAgentConfig(params.cfg, params.agentId)?.reasoningDefault ?? params.cfg.agents?.defaults?.reasoningDefault ?? "off";
|
|
853
921
|
try {
|
|
@@ -862,11 +930,9 @@ async function resolveFeishuReasoningPreviewEnabled(params) {
|
|
|
862
930
|
}
|
|
863
931
|
return configDefault === "stream";
|
|
864
932
|
}
|
|
865
|
-
|
|
866
|
-
//#region extensions/feishu/src/reply-dispatcher-state.ts
|
|
933
|
+
// extensions/feishu/src/reply-dispatcher-state.ts
|
|
867
934
|
const streamingStartBackoffUntilByAccount = /* @__PURE__ */ new Map();
|
|
868
|
-
|
|
869
|
-
//#region extensions/feishu/src/streaming-card.ts
|
|
935
|
+
// extensions/feishu/src/streaming-card.ts
|
|
870
936
|
const STREAMING_UPDATE_THROTTLE_MS = 160;
|
|
871
937
|
const STREAMING_SIGNIFICANT_DELTA_CHARS = 18;
|
|
872
938
|
const FEISHU_STREAMING_TOKEN_DEFAULT_LIFETIME_SECONDS = 7200;
|
|
@@ -1032,23 +1098,15 @@ var FeishuStreamingSession = class {
|
|
|
1032
1098
|
type: "card",
|
|
1033
1099
|
data: { card_id: cardId }
|
|
1034
1100
|
});
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
}
|
|
1044
|
-
params: { receive_id_type: receiveIdType },
|
|
1045
|
-
data: {
|
|
1046
|
-
receive_id: receiveId,
|
|
1047
|
-
msg_type: "interactive",
|
|
1048
|
-
content: cardContent,
|
|
1049
|
-
...sendOptions.rootId ? { root_id: sendOptions.rootId } : {}
|
|
1050
|
-
}
|
|
1051
|
-
}), "Send card failed");
|
|
1101
|
+
const sendRes = await sendFeishuMessage({
|
|
1102
|
+
client: this.client,
|
|
1103
|
+
receiveId,
|
|
1104
|
+
receiveIdType
|
|
1105
|
+
}, {
|
|
1106
|
+
...options,
|
|
1107
|
+
content: cardContent,
|
|
1108
|
+
msgType: "interactive"
|
|
1109
|
+
}, "Send card failed");
|
|
1052
1110
|
if (sendRes.code !== 0) throw new Error(`Send card failed: ${sendRes.msg}`);
|
|
1053
1111
|
const messageId = sendRes.data?.message_id?.trim();
|
|
1054
1112
|
this.state = {
|
|
@@ -1212,8 +1270,7 @@ var FeishuStreamingSession = class {
|
|
|
1212
1270
|
return this.state !== null && !this.closed;
|
|
1213
1271
|
}
|
|
1214
1272
|
};
|
|
1215
|
-
|
|
1216
|
-
//#region extensions/feishu/src/streaming-update.ts
|
|
1273
|
+
// extensions/feishu/src/streaming-update.ts
|
|
1217
1274
|
/** Admit captured snapshots in order while the session owns provider writes. */
|
|
1218
1275
|
function queueFeishuStreamingUpdate(params) {
|
|
1219
1276
|
const { queue, session, startPromise, text, accountId, runtime } = params;
|
|
@@ -1222,8 +1279,7 @@ function queueFeishuStreamingUpdate(params) {
|
|
|
1222
1279
|
if (session?.isActive()) session.update(text).catch((error) => runtime.error(`feishu[${accountId}] streaming update failed: ${String(error)}`));
|
|
1223
1280
|
});
|
|
1224
1281
|
}
|
|
1225
|
-
|
|
1226
|
-
//#region extensions/feishu/src/typing-backoff.ts
|
|
1282
|
+
// extensions/feishu/src/typing-backoff.ts
|
|
1227
1283
|
/** Feishu API codes that should trip the typing circuit breaker. */
|
|
1228
1284
|
const FEISHU_BACKOFF_CODES = /* @__PURE__ */ new Set([
|
|
1229
1285
|
99991400,
|
|
@@ -1251,8 +1307,7 @@ function getBackoffCodeFromResponse(response) {
|
|
|
1251
1307
|
const code = response.code;
|
|
1252
1308
|
return typeof code === "number" && FEISHU_BACKOFF_CODES.has(code) ? code : void 0;
|
|
1253
1309
|
}
|
|
1254
|
-
|
|
1255
|
-
//#region extensions/feishu/src/typing.ts
|
|
1310
|
+
// extensions/feishu/src/typing.ts
|
|
1256
1311
|
const TYPING_EMOJI = "Typing";
|
|
1257
1312
|
async function requestTypingReaction(request, operation, readResponse, runtime) {
|
|
1258
1313
|
const indicator = `typing indicator${operation === "remove" ? " removal" : ""}`;
|
|
@@ -1320,8 +1375,7 @@ async function removeTypingIndicator(params) {
|
|
|
1320
1375
|
reaction_id: state.reactionId
|
|
1321
1376
|
} }), "remove", () => void 0, runtime);
|
|
1322
1377
|
}
|
|
1323
|
-
|
|
1324
|
-
//#region extensions/feishu/src/reply-dispatcher.ts
|
|
1378
|
+
// extensions/feishu/src/reply-dispatcher.ts
|
|
1325
1379
|
function mergeStreamingFinalText(previousText, nextText, appendError) {
|
|
1326
1380
|
if (!appendError || !previousText || nextText.startsWith(previousText)) return nextText;
|
|
1327
1381
|
if (previousText.endsWith(`\n\n${nextText}`)) return previousText;
|
|
@@ -1336,7 +1390,7 @@ const NO_VISIBLE_REPLY_FALLBACK_TEXT = "⚠️ This reply completed without visi
|
|
|
1336
1390
|
function isStreamingStartBackedOff(accountId) {
|
|
1337
1391
|
const backoffUntil = streamingStartBackoffUntilByAccount.get(accountId);
|
|
1338
1392
|
if (backoffUntil === void 0) return false;
|
|
1339
|
-
if (backoffUntil <=
|
|
1393
|
+
if (backoffUntil <= performance.now()) {
|
|
1340
1394
|
streamingStartBackoffUntilByAccount.delete(accountId);
|
|
1341
1395
|
return false;
|
|
1342
1396
|
}
|
|
@@ -1425,6 +1479,8 @@ function createFeishuReplyDispatcher(params) {
|
|
|
1425
1479
|
let streaming = null;
|
|
1426
1480
|
let streamText = "";
|
|
1427
1481
|
let lastPartial = "";
|
|
1482
|
+
let previewText = "";
|
|
1483
|
+
let previewBlockOffset = 0;
|
|
1428
1484
|
let reasoningText = "";
|
|
1429
1485
|
let statusLine = "";
|
|
1430
1486
|
let modelWaitLine = "";
|
|
@@ -1463,10 +1519,20 @@ function createFeishuReplyDispatcher(params) {
|
|
|
1463
1519
|
};
|
|
1464
1520
|
const queueStreamingUpdate = (nextText, mode) => {
|
|
1465
1521
|
if (!nextText) return;
|
|
1466
|
-
if (nextText === lastPartial) return;
|
|
1522
|
+
if (mode === "snapshot" && nextText === lastPartial) return;
|
|
1523
|
+
if (mode === "delta") {
|
|
1524
|
+
let offset = previewBlockOffset;
|
|
1525
|
+
if (!previewText.startsWith(nextText, offset)) while (/\s/u.test(previewText.charAt(offset))) offset++;
|
|
1526
|
+
if (previewText.startsWith(nextText, offset)) {
|
|
1527
|
+
previewBlockOffset = offset + nextText.length;
|
|
1528
|
+
return;
|
|
1529
|
+
}
|
|
1530
|
+
streamText = `${streamText}${nextText}`;
|
|
1531
|
+
} else {
|
|
1532
|
+
previewText = nextText;
|
|
1533
|
+
streamText = `${snapshotBaseText}${nextText}`;
|
|
1534
|
+
}
|
|
1467
1535
|
lastPartial = nextText;
|
|
1468
|
-
if (mode === "delta") streamText = `${streamText}${nextText}`;
|
|
1469
|
-
else streamText = `${snapshotBaseText}${nextText}`;
|
|
1470
1536
|
flushStreamingCardUpdate(buildCombinedStreamText(reasoningText, streamText));
|
|
1471
1537
|
};
|
|
1472
1538
|
const startStreaming = () => {
|
|
@@ -1494,7 +1560,7 @@ function createFeishuReplyDispatcher(params) {
|
|
|
1494
1560
|
});
|
|
1495
1561
|
streamingStartBackoffUntilByAccount.delete(account.accountId);
|
|
1496
1562
|
} catch (error) {
|
|
1497
|
-
streamingStartBackoffUntilByAccount.set(account.accountId,
|
|
1563
|
+
streamingStartBackoffUntilByAccount.set(account.accountId, performance.now() + STREAMING_START_FAILURE_BACKOFF_MS);
|
|
1498
1564
|
params.runtime.error(`feishu[${account.accountId}]: streaming start failed; using non-streaming card fallback for ${STREAMING_START_FAILURE_BACKOFF_MS / 1e3}s: ${String(error)}`);
|
|
1499
1565
|
if (streaming === session) {
|
|
1500
1566
|
streaming = null;
|
|
@@ -1687,6 +1753,7 @@ function createFeishuReplyDispatcher(params) {
|
|
|
1687
1753
|
const result = await sendMediaFeishu({
|
|
1688
1754
|
...replyTarget,
|
|
1689
1755
|
mediaUrl,
|
|
1756
|
+
mediaAccess: resolveOutboundMediaAccessForConfig(cfg),
|
|
1690
1757
|
...payload.audioAsVoice === true ? { audioAsVoice: true } : {}
|
|
1691
1758
|
});
|
|
1692
1759
|
results.push(createFeishuReplyDeliveryResult({
|
|
@@ -2068,6 +2135,8 @@ function createFeishuReplyDispatcher(params) {
|
|
|
2068
2135
|
onAssistantMessageStart: previewStreamingEnabled ? () => {
|
|
2069
2136
|
snapshotBaseText = streamText ? `${streamText}\n\n` : "";
|
|
2070
2137
|
lastPartial = "";
|
|
2138
|
+
previewText = "";
|
|
2139
|
+
previewBlockOffset = 0;
|
|
2071
2140
|
modelWaitLine = "";
|
|
2072
2141
|
return updateStreamingStatusLine("", false);
|
|
2073
2142
|
} : void 0,
|
|
@@ -2077,8 +2146,7 @@ function createFeishuReplyDispatcher(params) {
|
|
|
2077
2146
|
ensureNoVisibleReplyFallback
|
|
2078
2147
|
};
|
|
2079
2148
|
}
|
|
2080
|
-
|
|
2081
|
-
//#region extensions/feishu/src/synthetic-event-target.ts
|
|
2149
|
+
// extensions/feishu/src/synthetic-event-target.ts
|
|
2082
2150
|
const directPreDispatchTargets = /* @__PURE__ */ new WeakMap();
|
|
2083
2151
|
/** Keep synthetic-only routing metadata outside the public Feishu event shape. */
|
|
2084
2152
|
function setFeishuSyntheticDirectPreDispatchTarget(event, target) {
|
|
@@ -2088,32 +2156,12 @@ function setFeishuSyntheticDirectPreDispatchTarget(event, target) {
|
|
|
2088
2156
|
function getFeishuSyntheticDirectPreDispatchTarget(event) {
|
|
2089
2157
|
return directPreDispatchTargets.get(event);
|
|
2090
2158
|
}
|
|
2091
|
-
|
|
2092
|
-
//#region extensions/feishu/src/bot.ts
|
|
2159
|
+
// extensions/feishu/src/bot.ts
|
|
2093
2160
|
const permissionErrorNotifiedAt = /* @__PURE__ */ new Map();
|
|
2094
2161
|
const PERMISSION_ERROR_COOLDOWN_MS = 3e5;
|
|
2095
2162
|
function isFeishuTopicSessionScope(scope) {
|
|
2096
2163
|
return scope === "group_topic" || scope === "group_topic_sender";
|
|
2097
2164
|
}
|
|
2098
|
-
async function shouldIncludeFetchedGroupContextMessage(params) {
|
|
2099
|
-
let senderAllowed = !params.isGroup || params.allowFrom.length === 0 || params.senderType === "app";
|
|
2100
|
-
const senderId = params.senderId?.trim();
|
|
2101
|
-
if (!senderAllowed && senderId) senderAllowed = (await resolveFeishuGroupSenderActivationIngressAccess({
|
|
2102
|
-
cfg: params.cfg,
|
|
2103
|
-
accountId: params.accountId,
|
|
2104
|
-
chatId: params.chatId,
|
|
2105
|
-
allowFrom: params.allowFrom,
|
|
2106
|
-
senderOpenId: senderId,
|
|
2107
|
-
senderUserId: senderId,
|
|
2108
|
-
requireMention: false,
|
|
2109
|
-
mentionedBot: true
|
|
2110
|
-
})).senderAccess.decision === "allow";
|
|
2111
|
-
return evaluateSupplementalContextVisibility({
|
|
2112
|
-
mode: params.mode,
|
|
2113
|
-
kind: params.kind,
|
|
2114
|
-
senderAllowed
|
|
2115
|
-
}).include;
|
|
2116
|
-
}
|
|
2117
2165
|
async function handleFeishuMessage(params) {
|
|
2118
2166
|
const { event, preparedContent, botOpenId, runtime, channelRuntime, chatHistories, accountId, processingClaim, messageDedupeKey: messageDedupeKeyOverride, turnAdoptionLifecycle } = params;
|
|
2119
2167
|
let cfg = getFeishuRuntime().config.current();
|
|
@@ -2822,7 +2870,7 @@ async function handleFeishuMessage(params) {
|
|
|
2822
2870
|
readAllowFromStore: pairing.readAllowFromStore,
|
|
2823
2871
|
senderOpenId: ctx.senderOpenId,
|
|
2824
2872
|
senderUserId,
|
|
2825
|
-
conversationId: ctx.
|
|
2873
|
+
conversationId: ctx.chatId,
|
|
2826
2874
|
mayPair: false,
|
|
2827
2875
|
contextBinding
|
|
2828
2876
|
});
|
|
@@ -2873,6 +2921,11 @@ async function handleFeishuMessage(params) {
|
|
|
2873
2921
|
replyToId: ctx.parentId,
|
|
2874
2922
|
messageThreadId: ctx.rootId && isTopicSession ? ctx.rootId : void 0
|
|
2875
2923
|
},
|
|
2924
|
+
command: {
|
|
2925
|
+
kind: core.channel.commands.isControlCommandMessage(effectiveCommandProbeBody, effectiveCfg) ? "text-slash" : "normal",
|
|
2926
|
+
body: effectiveCommandProbeBody,
|
|
2927
|
+
authorized: commandAuthorized === true
|
|
2928
|
+
},
|
|
2876
2929
|
message: {
|
|
2877
2930
|
body: combinedBody,
|
|
2878
2931
|
bodyForAgent: messageBody,
|
|
@@ -3011,25 +3064,19 @@ async function handleFeishuMessage(params) {
|
|
|
3011
3064
|
log(`feishu[${account.accountId}]: broadcast agent ${agentId} not found in agents.entries; skipping`);
|
|
3012
3065
|
return;
|
|
3013
3066
|
}
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
await agentClaim.pending;
|
|
3067
|
+
const agentClaim = await claimFeishuBroadcastAgentMessage({
|
|
3068
|
+
messageId: broadcastDedupeKey,
|
|
3069
|
+
agentId,
|
|
3070
|
+
log,
|
|
3071
|
+
onPending: broadcastSettlement.onLanePending
|
|
3072
|
+
});
|
|
3073
|
+
if (!agentClaim) return;
|
|
3074
|
+
const lane = broadcastSettlement.createLane(agentClaim.kind === "claimed" ? agentClaim.handle : void 0);
|
|
3075
|
+
try {
|
|
3076
|
+
if (agentId !== activeAgentId && core.channel.commands.isControlCommandMessage(effectiveCommandProbeBody, effectiveCfg)) {
|
|
3077
|
+
await lane.lifecycle.onAdopted();
|
|
3026
3078
|
return;
|
|
3027
|
-
} catch (err) {
|
|
3028
|
-
if (attempt === 1) throw err;
|
|
3029
3079
|
}
|
|
3030
|
-
}
|
|
3031
|
-
const lane = broadcastSettlement.createLane(agentClaim?.kind === "claimed" ? agentClaim.handle : void 0);
|
|
3032
|
-
try {
|
|
3033
3080
|
const agentSessionKey = buildBroadcastSessionKey(route.sessionKey, route.agentId, agentId);
|
|
3034
3081
|
const agentStorePath = resolveStorePath(cfg.session?.store, { agentId });
|
|
3035
3082
|
const agentRecord = {
|
|
@@ -3055,7 +3102,11 @@ async function handleFeishuMessage(params) {
|
|
|
3055
3102
|
identity: resolveAgentOutboundIdentity(cfg, agentId),
|
|
3056
3103
|
sessionKey: agentSessionKey
|
|
3057
3104
|
}) : void 0;
|
|
3058
|
-
if (!dispatcher)
|
|
3105
|
+
if (!dispatcher) {
|
|
3106
|
+
agentCtx.CommandAuthorized = false;
|
|
3107
|
+
delete agentCtx.CommandTurn;
|
|
3108
|
+
delete agentCtx.CommandSource;
|
|
3109
|
+
}
|
|
3059
3110
|
const turnResult = await runAgentTurn(agentCtx, () => ({
|
|
3060
3111
|
cfg,
|
|
3061
3112
|
channel: "feishu",
|
|
@@ -3178,12 +3229,20 @@ async function handleFeishuMessage(params) {
|
|
|
3178
3229
|
error(`feishu[${account.accountId}]: failed to dispatch message: ${String(err)}`);
|
|
3179
3230
|
}
|
|
3180
3231
|
}
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
const
|
|
3232
|
+
// extensions/feishu/src/card-action-state.ts
|
|
3233
|
+
const TOKEN_TTL_MS = 9e5;
|
|
3234
|
+
const cardActionReplayGuard = createChannelReplayGuard({
|
|
3235
|
+
dedupe: {
|
|
3236
|
+
pluginId: "feishu",
|
|
3237
|
+
namespacePrefix: "feishu.card-actions",
|
|
3238
|
+
ttlMs: TOKEN_TTL_MS,
|
|
3239
|
+
memoryMaxSize: 1e3,
|
|
3240
|
+
stateMaxEntries: 1e4
|
|
3241
|
+
},
|
|
3242
|
+
buildReplayKey: (token) => resolveExpiresAtMsFromDurationMs(TOKEN_TTL_MS) === void 0 ? void 0 : token
|
|
3243
|
+
});
|
|
3184
3244
|
const resolvedCardActionChatTypes = /* @__PURE__ */ new Map();
|
|
3185
|
-
|
|
3186
|
-
//#region extensions/feishu/src/card-ux-shared.ts
|
|
3245
|
+
// extensions/feishu/src/card-ux-shared.ts
|
|
3187
3246
|
function buildFeishuActionCard(params) {
|
|
3188
3247
|
return {
|
|
3189
3248
|
schema: "2.0",
|
|
@@ -3231,8 +3290,7 @@ function buildFeishuCardInteractionContext(params) {
|
|
|
3231
3290
|
...params.chatType ? { t: params.chatType } : {}
|
|
3232
3291
|
};
|
|
3233
3292
|
}
|
|
3234
|
-
|
|
3235
|
-
//#region extensions/feishu/src/card-ux-approval.ts
|
|
3293
|
+
// extensions/feishu/src/card-ux-approval.ts
|
|
3236
3294
|
const FEISHU_APPROVAL_REQUEST_ACTION = "feishu.quick_actions.request_approval";
|
|
3237
3295
|
const FEISHU_APPROVAL_CONFIRM_ACTION = "feishu.approval.confirm";
|
|
3238
3296
|
const FEISHU_APPROVAL_CANCEL_ACTION = "feishu.approval.cancel";
|
|
@@ -3261,10 +3319,8 @@ function createApprovalCard(params) {
|
|
|
3261
3319
|
})]
|
|
3262
3320
|
});
|
|
3263
3321
|
}
|
|
3264
|
-
|
|
3265
|
-
//#region extensions/feishu/src/card-action.ts
|
|
3322
|
+
// extensions/feishu/src/card-action.ts
|
|
3266
3323
|
const FEISHU_APPROVAL_CARD_TTL_MS = 3e5;
|
|
3267
|
-
const FEISHU_CARD_ACTION_TOKEN_TTL_MS = 9e5;
|
|
3268
3324
|
function pruneExpiredCardEntries(cache, now) {
|
|
3269
3325
|
const validNow = asDateTimestampMs(now);
|
|
3270
3326
|
if (validNow === void 0) {
|
|
@@ -3273,29 +3329,8 @@ function pruneExpiredCardEntries(cache, now) {
|
|
|
3273
3329
|
}
|
|
3274
3330
|
for (const [key, entry] of cache) if (!isFutureDateTimestampMs(entry.expiresAt, { nowMs: validNow })) cache.delete(key);
|
|
3275
3331
|
}
|
|
3276
|
-
function refreshFeishuCardActionToken(key, now = Date.now()) {
|
|
3277
|
-
const expiresAt = resolveExpiresAtMsFromDurationMs(FEISHU_CARD_ACTION_TOKEN_TTL_MS, { nowMs: now });
|
|
3278
|
-
if (expiresAt === void 0) {
|
|
3279
|
-
processedCardActions.delete(key);
|
|
3280
|
-
return;
|
|
3281
|
-
}
|
|
3282
|
-
processedCardActions.set(key, { expiresAt });
|
|
3283
|
-
}
|
|
3284
|
-
function resolveCallbackTarget(event) {
|
|
3285
|
-
const chatId = event.context.chat_id?.trim();
|
|
3286
|
-
if (chatId) return `chat:${chatId}`;
|
|
3287
|
-
return `user:${event.operator.open_id}`;
|
|
3288
|
-
}
|
|
3289
3332
|
const CHAT_TYPE_CACHE_TTL_MS = 18e5;
|
|
3290
3333
|
const CHAT_TYPE_CACHE_MAX_SIZE = 5e3;
|
|
3291
|
-
function cacheResolvedCardActionChatType(cacheKey, value, now) {
|
|
3292
|
-
const expiresAt = resolveExpiresAtMsFromDurationMs(CHAT_TYPE_CACHE_TTL_MS, { nowMs: now });
|
|
3293
|
-
resolvedCardActionChatTypes.delete(cacheKey);
|
|
3294
|
-
if (expiresAt !== void 0) resolvedCardActionChatTypes.set(cacheKey, {
|
|
3295
|
-
value,
|
|
3296
|
-
expiresAt
|
|
3297
|
-
});
|
|
3298
|
-
}
|
|
3299
3334
|
async function handleFeishuCardAction(params) {
|
|
3300
3335
|
const { cfg, event, runtime, accountId } = params;
|
|
3301
3336
|
const account = resolveFeishuRuntimeAccount({
|
|
@@ -3303,9 +3338,17 @@ async function handleFeishuCardAction(params) {
|
|
|
3303
3338
|
accountId
|
|
3304
3339
|
});
|
|
3305
3340
|
const log = runtime?.log ?? console.log;
|
|
3341
|
+
const chatId = event.context.chat_id?.trim();
|
|
3342
|
+
const callbackTarget = chatId ? `chat:${chatId}` : `user:${event.operator.open_id}`;
|
|
3343
|
+
let commandDispatched = false;
|
|
3344
|
+
const sendNotice = (text) => sendMessageFeishu({
|
|
3345
|
+
cfg,
|
|
3346
|
+
to: callbackTarget,
|
|
3347
|
+
text,
|
|
3348
|
+
accountId
|
|
3349
|
+
});
|
|
3306
3350
|
async function resolveCardActionChatType(chatType) {
|
|
3307
3351
|
if (chatType) return chatType;
|
|
3308
|
-
const chatId = event.context.chat_id?.trim();
|
|
3309
3352
|
if (!chatId) return "p2p";
|
|
3310
3353
|
const cacheKey = `${account.accountId}:${chatId}`;
|
|
3311
3354
|
const now = Date.now();
|
|
@@ -3318,24 +3361,27 @@ async function handleFeishuCardAction(params) {
|
|
|
3318
3361
|
if (response.code === 0) {
|
|
3319
3362
|
const resolvedChatType = resolveFeishuChatType(response.data ?? {});
|
|
3320
3363
|
if (resolvedChatType) {
|
|
3321
|
-
|
|
3364
|
+
const expiresAt = resolveExpiresAtMsFromDurationMs(CHAT_TYPE_CACHE_TTL_MS, { nowMs: now });
|
|
3365
|
+
if (expiresAt !== void 0) resolvedCardActionChatTypes.set(cacheKey, {
|
|
3366
|
+
value: resolvedChatType,
|
|
3367
|
+
expiresAt
|
|
3368
|
+
});
|
|
3322
3369
|
return resolvedChatType;
|
|
3323
3370
|
}
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
}
|
|
3327
|
-
|
|
3328
|
-
}
|
|
3329
|
-
return "p2p";
|
|
3371
|
+
}
|
|
3372
|
+
} catch {}
|
|
3373
|
+
log(`feishu[${account.accountId}]: card action chat type unavailable; action refused`);
|
|
3374
|
+
await sendNotice("⚠️ Could not verify this chat's conversation type, so this action was not run. Try clicking again later.");
|
|
3330
3375
|
}
|
|
3331
3376
|
async function dispatchSyntheticCommand(command, chatType) {
|
|
3332
3377
|
const { trackTask, botOpenId, channelRuntime } = params;
|
|
3333
3378
|
const resolvedChatType = await resolveCardActionChatType(chatType);
|
|
3334
|
-
|
|
3379
|
+
if (!resolvedChatType) return;
|
|
3380
|
+
function buildSyntheticMessageEvent(knownChatType) {
|
|
3335
3381
|
const replyTargetMessageId = event.context.open_message_id ?? event.open_message_id;
|
|
3336
3382
|
const isTemporaryCardActionId = replyTargetMessageId?.startsWith("card-action-c-");
|
|
3337
3383
|
const validReplyTargetId = replyTargetMessageId && !isTemporaryCardActionId ? replyTargetMessageId : void 0;
|
|
3338
|
-
const normalizedBotOpenId =
|
|
3384
|
+
const normalizedBotOpenId = knownChatType === "group" ? botOpenId?.trim() : void 0;
|
|
3339
3385
|
return {
|
|
3340
3386
|
sender: { sender_id: {
|
|
3341
3387
|
open_id: event.operator.open_id,
|
|
@@ -3348,7 +3394,7 @@ async function handleFeishuCardAction(params) {
|
|
|
3348
3394
|
...validReplyTargetId ? { typing_target_message_id: validReplyTargetId } : {},
|
|
3349
3395
|
...!validReplyTargetId ? { suppress_reply_target: true } : {},
|
|
3350
3396
|
chat_id: event.context.chat_id || event.operator.open_id,
|
|
3351
|
-
chat_type:
|
|
3397
|
+
chat_type: knownChatType,
|
|
3352
3398
|
message_type: "text",
|
|
3353
3399
|
content: JSON.stringify({ text: command }),
|
|
3354
3400
|
...normalizedBotOpenId ? { mentions: [{
|
|
@@ -3359,10 +3405,11 @@ async function handleFeishuCardAction(params) {
|
|
|
3359
3405
|
}
|
|
3360
3406
|
};
|
|
3361
3407
|
}
|
|
3408
|
+
commandDispatched = true;
|
|
3362
3409
|
await handleFeishuMessage({
|
|
3363
3410
|
trackTask,
|
|
3364
3411
|
cfg,
|
|
3365
|
-
event: buildSyntheticMessageEvent(),
|
|
3412
|
+
event: buildSyntheticMessageEvent(resolvedChatType),
|
|
3366
3413
|
botOpenId,
|
|
3367
3414
|
runtime,
|
|
3368
3415
|
channelRuntime,
|
|
@@ -3370,13 +3417,7 @@ async function handleFeishuCardAction(params) {
|
|
|
3370
3417
|
});
|
|
3371
3418
|
}
|
|
3372
3419
|
const sendInvalidInteractionNotice = async (reason) => {
|
|
3373
|
-
|
|
3374
|
-
await sendMessageFeishu({
|
|
3375
|
-
cfg,
|
|
3376
|
-
to: resolveCallbackTarget(event),
|
|
3377
|
-
text: `⚠️ ${reasonText}`,
|
|
3378
|
-
accountId
|
|
3379
|
-
});
|
|
3420
|
+
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."}`);
|
|
3380
3421
|
};
|
|
3381
3422
|
const normalizedToken = event.token.trim();
|
|
3382
3423
|
if (!normalizedToken) {
|
|
@@ -3384,14 +3425,14 @@ async function handleFeishuCardAction(params) {
|
|
|
3384
3425
|
return;
|
|
3385
3426
|
}
|
|
3386
3427
|
const decoded = decodeFeishuCardAction(event);
|
|
3387
|
-
const
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3428
|
+
const claim = await cardActionReplayGuard.claim(normalizedToken, {
|
|
3429
|
+
namespace: account.accountId,
|
|
3430
|
+
onDiskError: (error) => log(`feishu-card-action: persistent state error: ${String(error)}`)
|
|
3431
|
+
});
|
|
3432
|
+
if (claim.kind === "duplicate" || claim.kind === "inflight") {
|
|
3391
3433
|
log(`feishu[${account.accountId}]: skipping duplicate card action token`);
|
|
3392
3434
|
return;
|
|
3393
3435
|
}
|
|
3394
|
-
refreshFeishuCardActionToken(tokenKey, now);
|
|
3395
3436
|
try {
|
|
3396
3437
|
if (decoded.kind === "invalid") {
|
|
3397
3438
|
log(`feishu[${account.accountId}]: rejected card action from ${event.operator.open_id}: ${decoded.reason}`);
|
|
@@ -3413,9 +3454,11 @@ async function handleFeishuCardAction(params) {
|
|
|
3413
3454
|
await sendInvalidInteractionNotice("malformed");
|
|
3414
3455
|
return;
|
|
3415
3456
|
}
|
|
3457
|
+
const chatType = await resolveCardActionChatType(envelope.c?.t);
|
|
3458
|
+
if (!chatType) return;
|
|
3416
3459
|
await sendCardFeishu({
|
|
3417
3460
|
cfg,
|
|
3418
|
-
to:
|
|
3461
|
+
to: callbackTarget,
|
|
3419
3462
|
card: createApprovalCard({
|
|
3420
3463
|
operatorOpenId: event.operator.open_id,
|
|
3421
3464
|
chatId: event.context.chat_id || void 0,
|
|
@@ -3423,7 +3466,7 @@ async function handleFeishuCardAction(params) {
|
|
|
3423
3466
|
prompt,
|
|
3424
3467
|
sessionKey: envelope.c?.s,
|
|
3425
3468
|
expiresAt,
|
|
3426
|
-
chatType
|
|
3469
|
+
chatType,
|
|
3427
3470
|
confirmLabel: command === "/reset" ? "Reset" : "Confirm"
|
|
3428
3471
|
}),
|
|
3429
3472
|
accountId
|
|
@@ -3431,12 +3474,7 @@ async function handleFeishuCardAction(params) {
|
|
|
3431
3474
|
return;
|
|
3432
3475
|
}
|
|
3433
3476
|
if (envelope.a === "feishu.approval.cancel") {
|
|
3434
|
-
await
|
|
3435
|
-
cfg,
|
|
3436
|
-
to: resolveCallbackTarget(event),
|
|
3437
|
-
text: "Cancelled.",
|
|
3438
|
-
accountId
|
|
3439
|
-
});
|
|
3477
|
+
await sendNotice("Cancelled.");
|
|
3440
3478
|
return;
|
|
3441
3479
|
}
|
|
3442
3480
|
if (envelope.a === "feishu.approval.confirm" || envelope.k === "quick") {
|
|
@@ -3452,12 +3490,14 @@ async function handleFeishuCardAction(params) {
|
|
|
3452
3490
|
return;
|
|
3453
3491
|
}
|
|
3454
3492
|
await dispatchSyntheticCommand(decoded.text);
|
|
3493
|
+
} catch (error) {
|
|
3494
|
+
if (claim.kind === "claimed" && !commandDispatched) claim.handle.release({ error });
|
|
3495
|
+
throw error;
|
|
3455
3496
|
} finally {
|
|
3456
|
-
|
|
3497
|
+
if (claim.kind === "claimed") await claim.handle.commit();
|
|
3457
3498
|
}
|
|
3458
3499
|
}
|
|
3459
|
-
|
|
3460
|
-
//#region extensions/feishu/src/feishu-ingress.ts
|
|
3500
|
+
// extensions/feishu/src/feishu-ingress.ts
|
|
3461
3501
|
const FEISHU_INGRESS_PAYLOAD_VERSION = 1;
|
|
3462
3502
|
const FEISHU_INGRESS_POLL_INTERVAL_MS = 500;
|
|
3463
3503
|
const FEISHU_DURABLE_EVENT_TYPES = /* @__PURE__ */ new Set(["drive.notice.comment_add_v1", "im.message.receive_v1"]);
|
|
@@ -3553,6 +3593,21 @@ function buildFeishuFlushIngressLifecycle(sources, options) {
|
|
|
3553
3593
|
releaseReplayClaims();
|
|
3554
3594
|
await transportLifecycle.onAbandoned();
|
|
3555
3595
|
};
|
|
3596
|
+
const commitReplayClaims = async () => {
|
|
3597
|
+
const results = await Promise.allSettled(replayClaims.map((claim) => claim.commit()));
|
|
3598
|
+
for (const result of results) if (result.status === "rejected") options?.onReplayCommitError?.(result.reason);
|
|
3599
|
+
};
|
|
3600
|
+
const dropAll = async (reason) => {
|
|
3601
|
+
if (settled) return;
|
|
3602
|
+
settled = true;
|
|
3603
|
+
try {
|
|
3604
|
+
await transportLifecycle.onDropped?.(reason);
|
|
3605
|
+
} catch (error) {
|
|
3606
|
+
releaseReplayClaims();
|
|
3607
|
+
throw error;
|
|
3608
|
+
}
|
|
3609
|
+
await commitReplayClaims();
|
|
3610
|
+
};
|
|
3556
3611
|
const adoptAll = async () => {
|
|
3557
3612
|
if (settled) return;
|
|
3558
3613
|
settled = true;
|
|
@@ -3563,8 +3618,7 @@ function buildFeishuFlushIngressLifecycle(sources, options) {
|
|
|
3563
3618
|
await Promise.resolve(transportLifecycle.onAbandoned()).catch(() => void 0);
|
|
3564
3619
|
throw error;
|
|
3565
3620
|
}
|
|
3566
|
-
|
|
3567
|
-
for (const result of results) if (result.status === "rejected") options?.onReplayCommitError?.(result.reason);
|
|
3621
|
+
await commitReplayClaims();
|
|
3568
3622
|
};
|
|
3569
3623
|
return {
|
|
3570
3624
|
lifecycle: {
|
|
@@ -3587,18 +3641,22 @@ function buildFeishuFlushIngressLifecycle(sources, options) {
|
|
|
3587
3641
|
onAbandoned: async () => {
|
|
3588
3642
|
handedOff = true;
|
|
3589
3643
|
await abandonAll();
|
|
3590
|
-
}
|
|
3644
|
+
},
|
|
3645
|
+
onDropped: transportLifecycle.onDropped ? async (reason) => {
|
|
3646
|
+
handedOff = true;
|
|
3647
|
+
await dropAll(reason);
|
|
3648
|
+
} : void 0
|
|
3591
3649
|
},
|
|
3592
3650
|
settle: async () => {
|
|
3593
3651
|
if (handedOff) return;
|
|
3594
3652
|
handedOff = true;
|
|
3653
|
+
settled = true;
|
|
3595
3654
|
releaseReplayClaims();
|
|
3596
3655
|
try {
|
|
3597
3656
|
transportLifecycle.onAdoptionFinalizing();
|
|
3598
3657
|
await transportLifecycle.onAdopted();
|
|
3599
|
-
settled = true;
|
|
3600
3658
|
} catch (error) {
|
|
3601
|
-
await
|
|
3659
|
+
await Promise.resolve(transportLifecycle.onAbandoned()).catch(() => void 0);
|
|
3602
3660
|
throw error;
|
|
3603
3661
|
}
|
|
3604
3662
|
}
|
|
@@ -3631,18 +3689,49 @@ function createFeishuDurableIngress(options) {
|
|
|
3631
3689
|
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.`)
|
|
3632
3690
|
},
|
|
3633
3691
|
deliver: async (rawEnvelope, lifecycle, claim) => {
|
|
3692
|
+
const handoff = createDeferred$1();
|
|
3634
3693
|
const wrappedLifecycle = {
|
|
3635
3694
|
...lifecycle,
|
|
3695
|
+
onDeferred: () => {
|
|
3696
|
+
lifecycle.onDeferred();
|
|
3697
|
+
handoff.resolve();
|
|
3698
|
+
},
|
|
3699
|
+
onAdopted: async () => {
|
|
3700
|
+
try {
|
|
3701
|
+
await lifecycle.onAdopted();
|
|
3702
|
+
} finally {
|
|
3703
|
+
handoff.resolve();
|
|
3704
|
+
}
|
|
3705
|
+
},
|
|
3636
3706
|
onAbandoned: async () => {
|
|
3637
|
-
|
|
3638
|
-
|
|
3707
|
+
try {
|
|
3708
|
+
await Promise.resolve().then(() => wrappedLifecycle.onBeforeAbandon?.()).catch(() => void 0);
|
|
3709
|
+
await lifecycle.onAbandoned();
|
|
3710
|
+
} finally {
|
|
3711
|
+
handoff.resolve();
|
|
3712
|
+
}
|
|
3713
|
+
},
|
|
3714
|
+
onDropped: async (reason) => {
|
|
3715
|
+
try {
|
|
3716
|
+
await lifecycle.onDropped?.(reason);
|
|
3717
|
+
} finally {
|
|
3718
|
+
handoff.resolve();
|
|
3719
|
+
}
|
|
3639
3720
|
}
|
|
3640
3721
|
};
|
|
3641
3722
|
activeLifecycles.set(claim.id, wrappedLifecycle);
|
|
3642
3723
|
try {
|
|
3643
3724
|
const result = await options.dispatcher.invoke(parseRawEnvelope(rawEnvelope), { needCheck: false });
|
|
3644
3725
|
if (!isRecord$1(result)) return;
|
|
3645
|
-
if (result.kind === "deferred")
|
|
3726
|
+
if (result.kind === "deferred") {
|
|
3727
|
+
try {
|
|
3728
|
+
await racePromiseWithAbortSignal(handoff.promise, lifecycle.abortSignal);
|
|
3729
|
+
} catch (error) {
|
|
3730
|
+
await wrappedLifecycle.onAbandoned();
|
|
3731
|
+
throw error;
|
|
3732
|
+
}
|
|
3733
|
+
return { kind: "deferred" };
|
|
3734
|
+
}
|
|
3646
3735
|
if (result.kind === "completed") return { kind: "completed" };
|
|
3647
3736
|
if (result.kind === "failed-retryable") return {
|
|
3648
3737
|
kind: "failed-retryable",
|
|
@@ -3657,6 +3746,7 @@ function createFeishuDurableIngress(options) {
|
|
|
3657
3746
|
pollIntervalMs: options.pollIntervalMs ?? FEISHU_INGRESS_POLL_INTERVAL_MS,
|
|
3658
3747
|
retention: "standard",
|
|
3659
3748
|
drain: {
|
|
3749
|
+
deferredLaneOccupancy: "release",
|
|
3660
3750
|
adoptionStallTimeoutMs: options.adoptionStallTimeoutMs ?? DEFAULT_INGRESS_ADOPTION_STALL_MS,
|
|
3661
3751
|
resolveNonRetryableFailure: resolveFeishuIngressNonRetryableFailure,
|
|
3662
3752
|
onLog: (message) => options.runtime.error?.(`feishu ingress: ${message}`)
|
|
@@ -3709,8 +3799,7 @@ function createFeishuDurableIngress(options) {
|
|
|
3709
3799
|
waitForIdle: monitor.waitForIdle
|
|
3710
3800
|
};
|
|
3711
3801
|
}
|
|
3712
|
-
|
|
3713
|
-
//#region extensions/feishu/src/monitor.state.ts
|
|
3802
|
+
// extensions/feishu/src/monitor.state.ts
|
|
3714
3803
|
const botOpenIds = /* @__PURE__ */ new Map();
|
|
3715
3804
|
const FEISHU_WEBHOOK_MAX_BODY_BYTES = 65536;
|
|
3716
3805
|
const FEISHU_WEBHOOK_BODY_TIMEOUT_MS = 5e3;
|
|
@@ -3731,8 +3820,7 @@ function recordWebhookStatus(runtime, accountId, path, statusCode) {
|
|
|
3731
3820
|
message: (count) => `${label}: webhook anomaly path=${path} status=${statusCode} count=${count}`
|
|
3732
3821
|
});
|
|
3733
3822
|
}
|
|
3734
|
-
|
|
3735
|
-
//#region extensions/feishu/src/monitor.bot-identity.ts
|
|
3823
|
+
// extensions/feishu/src/monitor.bot-identity.ts
|
|
3736
3824
|
const BOT_IDENTITY_RETRY_DELAYS_MS = [
|
|
3737
3825
|
6e4,
|
|
3738
3826
|
12e4,
|
|
@@ -3774,8 +3862,7 @@ function startBotIdentityRecovery(params) {
|
|
|
3774
3862
|
(runtime?.error ?? console.error)(`feishu[${accountId}]: bot identity background retry failed unexpectedly: ${String(err)}`);
|
|
3775
3863
|
});
|
|
3776
3864
|
}
|
|
3777
|
-
|
|
3778
|
-
//#region extensions/feishu/src/monitor.comment.ts
|
|
3865
|
+
// extensions/feishu/src/monitor.comment.ts
|
|
3779
3866
|
const FEISHU_COMMENT_VERIFY_TIMEOUT_MS = 3e3;
|
|
3780
3867
|
const FEISHU_COMMENT_PAGE_SIZE = 100;
|
|
3781
3868
|
const FEISHU_COMMENT_PAGE_LIMIT = 5;
|
|
@@ -3935,7 +4022,7 @@ async function resolveDriveCommentEventTurn(params) {
|
|
|
3935
4022
|
logger?.(`feishu[${accountId}]: ignoring self-authored drive comment notice event=${eventId} sender=${senderId}`);
|
|
3936
4023
|
return null;
|
|
3937
4024
|
}
|
|
3938
|
-
const client = createFeishuClient((await import("./doctor-contract-
|
|
4025
|
+
const client = createFeishuClient((await import("./doctor-contract-ItAh0keT.mjs").then((n) => n.l)).resolveFeishuAccount({
|
|
3939
4026
|
cfg,
|
|
3940
4027
|
accountId
|
|
3941
4028
|
}));
|
|
@@ -4201,8 +4288,7 @@ function parseFeishuDriveCommentNoticeEventPayload(value) {
|
|
|
4201
4288
|
type: readStringValue(value.type)
|
|
4202
4289
|
};
|
|
4203
4290
|
}
|
|
4204
|
-
|
|
4205
|
-
//#region extensions/feishu/src/comment-handler.ts
|
|
4291
|
+
// extensions/feishu/src/comment-handler.ts
|
|
4206
4292
|
function parseTimestampMs(value) {
|
|
4207
4293
|
return parseStrictNonNegativeInteger(value) ?? Date.now();
|
|
4208
4294
|
}
|
|
@@ -4511,8 +4597,7 @@ async function handleFeishuCommentEvent(params) {
|
|
|
4511
4597
|
typingReaction.cleanup();
|
|
4512
4598
|
}
|
|
4513
4599
|
}
|
|
4514
|
-
|
|
4515
|
-
//#region extensions/feishu/src/sequential-queue.ts
|
|
4600
|
+
// extensions/feishu/src/sequential-queue.ts
|
|
4516
4601
|
const DEFAULT_TASK_TIMEOUT_MS = 3e5;
|
|
4517
4602
|
function createSequentialQueue(options = {}) {
|
|
4518
4603
|
const queues = /* @__PURE__ */ new Map();
|
|
@@ -4525,8 +4610,7 @@ function createSequentialQueue(options = {}) {
|
|
|
4525
4610
|
})
|
|
4526
4611
|
});
|
|
4527
4612
|
}
|
|
4528
|
-
|
|
4529
|
-
//#region extensions/feishu/src/monitor.comment-notice-handler.ts
|
|
4613
|
+
// extensions/feishu/src/monitor.comment-notice-handler.ts
|
|
4530
4614
|
function createFeishuDriveCommentNoticeHandler(params) {
|
|
4531
4615
|
const { cfg, accountId, runtime, fireAndForget, abortSignal } = params;
|
|
4532
4616
|
const error = runtime?.error ?? console.error;
|
|
@@ -4574,8 +4658,7 @@ function createFeishuDriveCommentNoticeHandler(params) {
|
|
|
4574
4658
|
await settle();
|
|
4575
4659
|
};
|
|
4576
4660
|
}
|
|
4577
|
-
|
|
4578
|
-
//#region extensions/feishu/src/monitor.message-handler.ts
|
|
4661
|
+
// extensions/feishu/src/monitor.message-handler.ts
|
|
4579
4662
|
function parseFeishuMessageEventPayload(value) {
|
|
4580
4663
|
if (!isRecord(value)) return null;
|
|
4581
4664
|
const sender = value.sender;
|
|
@@ -4829,8 +4912,7 @@ function createFeishuMessageReceiveHandler({ cfg, channelRuntime, accountId, run
|
|
|
4829
4912
|
if (!fireAndForget) await processing;
|
|
4830
4913
|
};
|
|
4831
4914
|
}
|
|
4832
|
-
|
|
4833
|
-
//#region extensions/feishu/src/monitor-rate-limit-key.ts
|
|
4915
|
+
// extensions/feishu/src/monitor-rate-limit-key.ts
|
|
4834
4916
|
function normalizeFeishuWebhookRateLimitClient(clientIp) {
|
|
4835
4917
|
if (!clientIp) return "unknown";
|
|
4836
4918
|
if (clientIp === "::1" || clientIp.startsWith("127.")) return "loopback";
|
|
@@ -4839,8 +4921,7 @@ function normalizeFeishuWebhookRateLimitClient(clientIp) {
|
|
|
4839
4921
|
function buildFeishuWebhookRateLimitKey(params) {
|
|
4840
4922
|
return `${params.accountId === void 0 ? params.path : `${params.accountId}:${params.path}`}:${normalizeFeishuWebhookRateLimitClient(params.clientIp)}`;
|
|
4841
4923
|
}
|
|
4842
|
-
|
|
4843
|
-
//#region extensions/feishu/src/monitor.transport.ts
|
|
4924
|
+
// extensions/feishu/src/monitor.transport.ts
|
|
4844
4925
|
const FEISHU_WEBHOOK_ACCEPTED_HEADER = "x-openclaw-delivery-accepted";
|
|
4845
4926
|
const FEISHU_WEBHOOK_ACCEPTED_VALUE = "durable";
|
|
4846
4927
|
const FEISHU_PRE_AUTH_MAX_IN_FLIGHT = 64;
|
|
@@ -5214,8 +5295,7 @@ async function monitorWebhook(params) {
|
|
|
5214
5295
|
await cleanup();
|
|
5215
5296
|
}
|
|
5216
5297
|
}
|
|
5217
|
-
|
|
5218
|
-
//#region extensions/feishu/src/monitor.vc-meeting-invited-handler.ts
|
|
5298
|
+
// extensions/feishu/src/monitor.vc-meeting-invited-handler.ts
|
|
5219
5299
|
const FEISHU_MEETING_NUMBER_PATTERN = /^\d{9}$/;
|
|
5220
5300
|
function parseInviteTimestamp(value) {
|
|
5221
5301
|
const parsed = Number.parseInt(value ?? "", 10);
|
|
@@ -5343,8 +5423,7 @@ function createFeishuVcMeetingInvitedHandler(params) {
|
|
|
5343
5423
|
return fireAndForget ? Promise.resolve() : task;
|
|
5344
5424
|
};
|
|
5345
5425
|
}
|
|
5346
|
-
|
|
5347
|
-
//#region extensions/feishu/src/sequential-key.ts
|
|
5426
|
+
// extensions/feishu/src/sequential-key.ts
|
|
5348
5427
|
function getFeishuSequentialKey(params) {
|
|
5349
5428
|
const { accountId, event, botOpenId, preparedContent, isControlCommandMessage } = params;
|
|
5350
5429
|
const baseKey = `feishu:${accountId}:${event.message.chat_id?.trim() || "unknown"}`;
|
|
@@ -5353,8 +5432,7 @@ function getFeishuSequentialKey(params) {
|
|
|
5353
5432
|
if (isBtwRequestText(text)) return `${baseKey}:btw`;
|
|
5354
5433
|
return isControlCommandMessage(text) ? `${baseKey}:commands` : baseKey;
|
|
5355
5434
|
}
|
|
5356
|
-
|
|
5357
|
-
//#region extensions/feishu/src/monitor.account.ts
|
|
5435
|
+
// extensions/feishu/src/monitor.account.ts
|
|
5358
5436
|
const FEISHU_QUICK_ACTION_CARD_TTL_MS = 6e5;
|
|
5359
5437
|
const QUICK_ACTION_MENU_KEYS = /* @__PURE__ */ new Set([
|
|
5360
5438
|
"quick-actions",
|
|
@@ -5370,14 +5448,13 @@ async function resolveReactionSyntheticEvent(params) {
|
|
|
5370
5448
|
const senderUserId = event.user_id?.user_id?.trim();
|
|
5371
5449
|
const senderId = senderOpenId || senderUserId;
|
|
5372
5450
|
if (!emoji || !messageId || !senderId) return null;
|
|
5373
|
-
const { resolveFeishuAccount } = await import("./doctor-contract-
|
|
5374
|
-
const
|
|
5451
|
+
const { resolveFeishuAccount } = await import("./doctor-contract-ItAh0keT.mjs").then((n) => n.l);
|
|
5452
|
+
const account = resolveFeishuAccount({
|
|
5375
5453
|
cfg,
|
|
5376
5454
|
accountId
|
|
5377
|
-
})
|
|
5378
|
-
|
|
5379
|
-
if (event.operator_type === "app" || senderId === botOpenId) return null;
|
|
5380
|
-
if (emoji === "Typing") return null;
|
|
5455
|
+
});
|
|
5456
|
+
const reactionNotifications = account.config.reactionNotifications;
|
|
5457
|
+
if (reactionNotifications === "off" || event.operator_type === "app" || senderId === botOpenId || emoji === "Typing") return null;
|
|
5381
5458
|
if (reactionNotifications === "own" && !botOpenId) {
|
|
5382
5459
|
logger?.(`feishu[${accountId}]: bot open_id unavailable, skipping reaction ${emoji} on ${messageId}`);
|
|
5383
5460
|
return null;
|
|
@@ -5392,13 +5469,16 @@ async function resolveReactionSyntheticEvent(params) {
|
|
|
5392
5469
|
logger?.(`feishu[${accountId}]: ignoring reaction on non-bot/unverified message ${messageId} (sender: ${reactedMsg?.senderOpenId ?? "unknown"})`);
|
|
5393
5470
|
return null;
|
|
5394
5471
|
}
|
|
5395
|
-
const
|
|
5472
|
+
const syntheticChatIdRaw = event.chat_id?.trim() || reactedMsg.chatId?.trim();
|
|
5473
|
+
let resolvedChatType = normalizeFeishuEventChatType(event.chat_type) ?? reactedMsg.chatType;
|
|
5474
|
+
if (!resolvedChatType && syntheticChatIdRaw) {
|
|
5475
|
+
const chatInfo = await raceWithTimeoutAndAbort(getChatInfo(createFeishuClient(account), syntheticChatIdRaw), { timeoutMs: FEISHU_REACTION_VERIFY_TIMEOUT_MS }).catch(() => null);
|
|
5476
|
+
resolvedChatType = chatInfo?.status === "resolved" ? resolveFeishuChatType(chatInfo.value) : void 0;
|
|
5477
|
+
}
|
|
5396
5478
|
if (!resolvedChatType) {
|
|
5397
5479
|
logger?.(`feishu[${accountId}]: skipping reaction ${emoji} on ${messageId} without chat type context`);
|
|
5398
5480
|
return null;
|
|
5399
5481
|
}
|
|
5400
|
-
const syntheticChatIdRaw = event.chat_id ?? reactedMsg.chatId;
|
|
5401
|
-
const syntheticChatId = syntheticChatIdRaw?.trim() ? syntheticChatIdRaw : `p2p:${senderId}`;
|
|
5402
5482
|
return {
|
|
5403
5483
|
sender: {
|
|
5404
5484
|
sender_id: {
|
|
@@ -5413,7 +5493,7 @@ async function resolveReactionSyntheticEvent(params) {
|
|
|
5413
5493
|
typing_target_message_id: messageId,
|
|
5414
5494
|
...reactedMsg.rootId ? { root_id: reactedMsg.rootId } : {},
|
|
5415
5495
|
...reactedMsg.threadId ? { thread_id: reactedMsg.threadId } : {},
|
|
5416
|
-
chat_id:
|
|
5496
|
+
chat_id: syntheticChatIdRaw || `p2p:${senderId}`,
|
|
5417
5497
|
chat_type: resolvedChatType,
|
|
5418
5498
|
message_type: "text",
|
|
5419
5499
|
content: JSON.stringify({ text: action === "deleted" ? `[removed reaction ${emoji} from message ${messageId}]` : `[reacted with ${emoji} to message ${messageId}]` })
|
|
@@ -5792,5 +5872,4 @@ async function monitorSingleAccount(params) {
|
|
|
5792
5872
|
threadBindingManager?.stop();
|
|
5793
5873
|
}
|
|
5794
5874
|
}
|
|
5795
|
-
//#endregion
|
|
5796
5875
|
export { monitorSingleAccount, resolveReactionSyntheticEvent };
|