@openclaw/slack 2026.9.8 → 2026.10.1-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/{account-inspect-DWBXpER6.mjs → account-inspect-Cs-7DXXW.mjs} +1 -1
- package/dist/.setup/{accounts-D_N9IqNA.mjs → accounts-CDgkV7Cm.mjs} +4 -16
- package/dist/.setup/{action-runtime-DfWvuiZd.mjs → action-runtime-DJ1daRAZ.mjs} +5 -7
- package/dist/.setup/action-runtime.runtime-CdWL2mLC.mjs +2 -0
- package/dist/.setup/{actions-Df0CzcDl.mjs → actions-DDoAJnrH.mjs} +16 -35
- package/dist/.setup/{approval-handler.runtime-Ed6Sw5VK.mjs → approval-handler.runtime-BcE_shWc.mjs} +5 -5
- package/dist/.setup/{approval-message-updates-BadvtA7R.mjs → approval-message-updates-EgKGmFXx.mjs} +1 -1
- package/dist/.setup/{channel-C7bgPSTE.mjs → channel-DgKSu8Iv.mjs} +46 -48
- package/dist/.setup/{channel-type-ClOttrZ5.mjs → channel-type-B9zYYzBU.mjs} +4 -4
- package/dist/.setup/{channel.setup-Dh2jzAjN.mjs → channel.setup-BYIlwbQ7.mjs} +27 -27
- package/dist/.setup/{config-schema-BZCxmHKG.mjs → config-schema-BH0K9-Um.mjs} +4 -0
- package/dist/.setup/{directory-config-BOUWH3hR.mjs → directory-config-B_by7zrc.mjs} +2 -2
- package/dist/.setup/{directory-live-B2O4B_Ho.mjs → directory-live-C48wazJt.mjs} +3 -3
- package/dist/.setup/{doctor-contract-CRN1Z_c7.mjs → doctor-contract-Cd4-VzIM.mjs} +28 -28
- package/dist/.setup/{message-tool-api-Cu4lwlGy.mjs → message-tool-api-CcjLPN3v.mjs} +2 -2
- package/dist/.setup/{monitor-BPVfkumU.mjs → monitor-BuYBDmm7.mjs} +190 -315
- package/dist/.setup/{outbound-adapter-Bv48XUjq.mjs → outbound-adapter-BZFkK-mw.mjs} +6 -17
- package/dist/.setup/{pipeline.runtime-B1H63Frf.mjs → pipeline.runtime-CIepKmZt.mjs} +241 -247
- package/dist/.setup/{policy-D-jfM174.mjs → policy-KKTqEiDv.mjs} +12 -22
- package/dist/.setup/{probe-B2Y9qc_z.mjs → probe-BVlJ3dp0.mjs} +4 -7
- package/dist/.setup/{relay-source-BpKdjsll.mjs → relay-source-CC3h6M7y.mjs} +2 -2
- package/dist/.setup/{replies-BAnUtr2f.mjs → replies-DHbuthIR.mjs} +12 -26
- package/dist/.setup/{reply-blocks-SE1kTE3I.mjs → reply-blocks-CKnO4BSG.mjs} +4 -29
- package/dist/.setup/{resolve-channels-XXBn8UU_.mjs → resolve-channels-HR0TgArR.mjs} +2 -2
- package/dist/.setup/{resolve-users-DW0ngD03.mjs → resolve-users-BNYBhF0q.mjs} +4 -4
- package/dist/.setup/rolldown-runtime-B4FMCO8f.mjs +28 -0
- package/dist/.setup/{scopes-CasuDvaa.mjs → scopes-DrDbyUH2.mjs} +1 -1
- package/dist/.setup/secret-contract-B-Qm6aQQ.mjs +65 -0
- package/dist/.setup/{secret-contract-api-Dp6290Vg.mjs → secret-contract-api-DmUVxIRs.mjs} +1 -1
- package/dist/.setup/{security-audit-BqDc-6VL.mjs → security-audit-C1nOGzJa.mjs} +1 -1
- package/dist/.setup/{send-BOVLQi3n.mjs → send-CgPI3Zj8.mjs} +22 -53
- package/dist/.setup/{session-status-DscajIsd.mjs → session-status-D46GHwOV.mjs} +39 -49
- package/dist/.setup/{setup-plugin-api-DTtbTKNk.mjs → setup-plugin-api-ZrHs0N4U.mjs} +1 -1
- package/dist/.setup/{setup-surface-Dn7QgWRE.mjs → setup-surface-83lxvE2y.mjs} +10 -13
- package/dist/.setup/{shared-qau-uDGl.mjs → shared-VtmYNj-v.mjs} +53 -57
- package/dist/.setup/{slash-dispatch.runtime--AEzLVBF.mjs → slash-dispatch.runtime-gBj_uaLM.mjs} +1 -1
- package/dist/account-inspect-api.js +1 -1
- package/dist/api.js +13 -13
- package/dist/channel-config-api.js +1 -1
- package/dist/channel-plugin-api.js +1 -1
- package/dist/control-ui/2f4b1e827be6b68ced2ea0d8b7da8529a4eafbe72be27ee37e1064bdd530ec10/index.js +1 -0
- package/dist/directory-contract-api.js +1 -1
- package/dist/doctor-contract-api.js +1 -1
- package/dist/message-tool-api.js +1 -1
- package/dist/runtime-api.js +10 -10
- package/dist/secret-contract-api.js +1 -1
- package/dist/security-contract-api.js +1 -1
- package/dist/setup-entry.js +2 -2
- package/dist/setup-plugin-api.js +1 -1
- package/node_modules/undici/README.md +10 -1
- package/node_modules/undici/docs/docs/api/Agent.md +8 -8
- package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +9 -6
- package/node_modules/undici/docs/docs/api/Dispatcher.md +9 -0
- package/node_modules/undici/docs/docs/api/Errors.md +25 -0
- package/node_modules/undici/docs/docs/api/Fetch.md +10 -0
- package/node_modules/undici/docs/docs/api/Interceptors.md +4 -3
- package/node_modules/undici/docs/docs/api/Pool.md +5 -6
- package/node_modules/undici/docs/docs/index.md +10 -1
- package/node_modules/undici/lib/api/readable.js +1 -2
- package/node_modules/undici/lib/core/request.js +23 -2
- package/node_modules/undici/lib/core/util.js +0 -39
- package/node_modules/undici/lib/dispatcher/client-h1.js +11 -4
- package/node_modules/undici/lib/dispatcher/client-h2.js +52 -8
- package/node_modules/undici/lib/dispatcher/client.js +6 -1
- package/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +21 -6
- package/node_modules/undici/lib/dispatcher/pool-base.js +63 -2
- package/node_modules/undici/lib/dispatcher/pool.js +90 -7
- package/node_modules/undici/lib/dispatcher/proxy-agent.js +16 -3
- package/node_modules/undici/lib/handler/deduplication-handler.js +24 -11
- package/node_modules/undici/lib/handler/redirect-handler.js +5 -0
- package/node_modules/undici/lib/handler/retry-handler.js +72 -13
- package/node_modules/undici/lib/interceptor/cache.js +4 -1
- package/node_modules/undici/lib/interceptor/decompress.js +236 -69
- package/node_modules/undici/lib/web/cache/cache.js +17 -8
- package/node_modules/undici/lib/web/cache/cachestorage.js +11 -5
- package/node_modules/undici/lib/web/cookies/index.js +19 -7
- package/node_modules/undici/lib/web/cookies/util.js +3 -1
- package/node_modules/undici/lib/web/eventsource/eventsource.js +25 -1
- package/node_modules/undici/lib/web/fetch/body.js +22 -15
- package/node_modules/undici/lib/web/fetch/data-url.js +6 -6
- package/node_modules/undici/lib/web/fetch/formdata.js +30 -36
- package/node_modules/undici/lib/web/fetch/headers.js +34 -31
- package/node_modules/undici/lib/web/fetch/index.js +46 -25
- package/node_modules/undici/lib/web/fetch/request.js +74 -79
- package/node_modules/undici/lib/web/fetch/response.js +43 -44
- package/node_modules/undici/lib/web/fetch/util.js +7 -7
- package/node_modules/undici/lib/web/infra/index.js +16 -1
- package/node_modules/undici/lib/web/webidl/index.js +2 -14
- package/node_modules/undici/lib/web/websocket/connection.js +33 -12
- package/node_modules/undici/lib/web/websocket/events.js +43 -26
- package/node_modules/undici/lib/web/websocket/receiver.js +2 -0
- package/node_modules/undici/lib/web/websocket/stream/websocketerror.js +13 -10
- package/node_modules/undici/lib/web/websocket/stream/websocketstream.js +19 -4
- package/node_modules/undici/lib/web/websocket/websocket.js +44 -41
- package/node_modules/undici/package.json +1 -1
- package/node_modules/undici/types/diagnostics-channel.d.ts +2 -1
- package/node_modules/undici/types/interceptors.d.ts +1 -1
- package/node_modules/undici/types/webidl.d.ts +13 -7
- package/openclaw.plugin.json +4 -1
- package/package.json +14 -6
- package/dist/.setup/action-runtime.runtime-Ck4bAWOX.mjs +0 -2
- package/dist/.setup/secret-contract-BaZcu6P_.mjs +0 -82
- package/dist/.setup/streaming-compat-C5Wut626.mjs +0 -62
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-B4FMCO8f.mjs";
|
|
2
2
|
import { n as registerSlackHttpHandler, r as normalizeSlackWebhookPath } from "./registry-CIbMfuf8.mjs";
|
|
3
|
-
import { a as mergeSlackAccountConfig, c as resolveSlackAccountAllowFrom, f as resolveSlackReplyToMode, h as resolveSlackBotToken, l as resolveSlackAccountDmPolicy, m as resolveSlackAppToken, o as resolveDefaultSlackAccountId, p as formatSlackBotTokenIdentityWarning, s as resolveSlackAccount } from "./accounts-
|
|
3
|
+
import { a as mergeSlackAccountConfig, c as resolveSlackAccountAllowFrom, f as resolveSlackReplyToMode, h as resolveSlackBotToken, l as resolveSlackAccountDmPolicy, m as resolveSlackAppToken, o as resolveDefaultSlackAccountId, p as formatSlackBotTokenIdentityWarning, s as resolveSlackAccount } from "./accounts-CDgkV7Cm.mjs";
|
|
4
4
|
import { a as parseSlackTarget, n as formatSlackTarget } from "./target-parsing-FFE26kOV.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import { A as resolveSlackUserAllowListForTeam, C as resolveSlackMonitorDispatchers, D as normalizeSlackAllowOwnerEntry, E as allowListMatches, O as normalizeSlackSlug, S as resolveSlackLookupClientOptions, a as slackIngressIdentity, c as collectSlackCursorPages, f as createSlackStartupAuthClient, g as getSlackListenerWriteClient, i as createSlackIngressSubject, k as resolveSlackAllowListMatch, m as createSlackWebClient, o as formatSlackError, v as readLruMapEntry, w as resolveSlackWebClientOptions, y as writeLruMapEntry } from "./probe-
|
|
5
|
+
import { B as isSlackApprovalActionId, H as isSlackQuestionActionId, K as resolveSlackQuestionAction, Mt as registerSlackInstallationState, Ot as isSlackPluginApprovalAuthorizedSender, Pt as isSlackExecApprovalAuthorizedSender, V as isSlackCallbackActionId, W as decodeSlackQuestionAction, c as qualifySlackRoutePeerId, ct as decodeSlackApprovalAction, d as resolveSlackConversationBindingRoute, gt as isSlackAnyNativeApprovalClientEnabled, j as truncateSlackText, k as SLACK_TEXT_LIMIT, l as resolveSlackEnterpriseMainDmSessionKey, n as setSlackSessionStatus, ot as escapeSlackMrkdwn, r as buildSlackChannelIdCandidates, s as qualifySlackConversationId, t as renameSlackSession, u as normalizeSlackRouteBindingConfig } from "./session-status-D46GHwOV.mjs";
|
|
6
|
+
import { A as resolveSlackUserAllowListForTeam, C as resolveSlackMonitorDispatchers, D as normalizeSlackAllowOwnerEntry, E as allowListMatches, O as normalizeSlackSlug, S as resolveSlackLookupClientOptions, a as slackIngressIdentity, c as collectSlackCursorPages, f as createSlackStartupAuthClient, g as getSlackListenerWriteClient, i as createSlackIngressSubject, k as resolveSlackAllowListMatch, m as createSlackWebClient, o as formatSlackError, v as readLruMapEntry, w as resolveSlackWebClientOptions, y as writeLruMapEntry } from "./probe-BVlJ3dp0.mjs";
|
|
7
7
|
import { n as getSlackRuntime, t as getOptionalSlackRuntime } from "./runtime-JSVZSWAj.mjs";
|
|
8
8
|
import { t as DEFAULT_SLACK_SUGGESTED_PROMPTS } from "./channel-meta-C443t-lI.mjs";
|
|
9
|
-
import { S as hasSlackMessageTableBlock, f as readSlackMessages, v as isGovSlackClient, y as saveRemoteMedia } from "./actions-
|
|
10
|
-
import { d as requireSlackPostMessageTimestamp, f as buildSlackMessageIdentityPayload, r as setSlackDefaultSendIdentity } from "./send-
|
|
11
|
-
import { n as resolveSlackChannelConfig, r as resolveSlackChannelLabel, t as isSlackChannelAllowedByPolicy } from "./policy-
|
|
12
|
-
import { t as resolveSlackChannelAllowlist } from "./resolve-channels-
|
|
13
|
-
import { t as resolveSlackUserAllowlist } from "./resolve-users-
|
|
14
|
-
import { n as runSlackApprovalMessageUpdate, t as hasSlackApprovalControl } from "./approval-message-updates-
|
|
9
|
+
import { S as hasSlackMessageTableBlock, f as readSlackMessages, v as isGovSlackClient, y as saveRemoteMedia } from "./actions-DDoAJnrH.mjs";
|
|
10
|
+
import { d as requireSlackPostMessageTimestamp, f as buildSlackMessageIdentityPayload, r as setSlackDefaultSendIdentity } from "./send-CgPI3Zj8.mjs";
|
|
11
|
+
import { n as resolveSlackChannelConfig, r as resolveSlackChannelLabel, t as isSlackChannelAllowedByPolicy } from "./policy-KKTqEiDv.mjs";
|
|
12
|
+
import { t as resolveSlackChannelAllowlist } from "./resolve-channels-HR0TgArR.mjs";
|
|
13
|
+
import { t as resolveSlackUserAllowlist } from "./resolve-users-BNYBhF0q.mjs";
|
|
14
|
+
import { n as runSlackApprovalMessageUpdate, t as hasSlackApprovalControl } from "./approval-message-updates-EgKGmFXx.mjs";
|
|
15
15
|
import { normalizeAccountId } from "openclaw/plugin-sdk/account-resolution";
|
|
16
16
|
import { normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input";
|
|
17
17
|
import { asNonArrayRecord, asOptionalRecord, isRecord, normalizeLowercaseStringOrEmpty, normalizeOptionalLowercaseString, normalizeOptionalString, normalizeStringEntries, normalizeUniqueTrimmedStringList } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
@@ -359,8 +359,8 @@ function isStableSlackToolsBySenderEntry(value) {
|
|
|
359
359
|
if (typeof value !== "string") return false;
|
|
360
360
|
const normalized = value.trim();
|
|
361
361
|
if (normalized === "*") return true;
|
|
362
|
-
const
|
|
363
|
-
return
|
|
362
|
+
const senderId = /^(?:id:|channel:slack:)(.+)$/.exec(normalized)?.[1];
|
|
363
|
+
return senderId !== void 0 && SLACK_USER_ID_RE.test(senderId);
|
|
364
364
|
}
|
|
365
365
|
function assertStableEntries(params) {
|
|
366
366
|
const invalid = params.values?.find((value) => !params.predicate(value));
|
|
@@ -732,7 +732,7 @@ function isSlackSocketSelfInflictedLoggerWarning(args) {
|
|
|
732
732
|
function formatSlackSdkLogArgs(args) {
|
|
733
733
|
return args.map((arg) => formatSlackError(arg, "")).filter(Boolean).join(" ");
|
|
734
734
|
}
|
|
735
|
-
function createSlackSocketModeLogger(
|
|
735
|
+
function createSlackSocketModeLogger() {
|
|
736
736
|
let level = "info";
|
|
737
737
|
let name = "socket-mode";
|
|
738
738
|
const prefix = () => `socket-mode:${name}`;
|
|
@@ -747,11 +747,11 @@ function createSlackSocketModeLogger(sink = console) {
|
|
|
747
747
|
warn: (...args) => {
|
|
748
748
|
if (isSlackSocketHeartbeatTimeoutWarning(args) || isSlackSocketSelfInflictedLoggerWarning(args)) return;
|
|
749
749
|
remember(args);
|
|
750
|
-
|
|
750
|
+
console.warn(prefix(), ...args);
|
|
751
751
|
},
|
|
752
752
|
error: (...args) => {
|
|
753
753
|
remember(args);
|
|
754
|
-
|
|
754
|
+
console.error(prefix(), ...args);
|
|
755
755
|
},
|
|
756
756
|
setLevel: (nextLevel) => {
|
|
757
757
|
level = nextLevel;
|
|
@@ -1689,15 +1689,12 @@ function createSlackThreadTsResolver(params) {
|
|
|
1689
1689
|
const getCached = (key, now) => {
|
|
1690
1690
|
const entry = cache.get(key);
|
|
1691
1691
|
if (!entry) return;
|
|
1692
|
-
if (entry.expiresAt
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
if (normalizedNow === void 0 || asDateTimestampMs(entry.expiresAt) === void 0 || entry.expiresAt <= normalizedNow) {
|
|
1699
|
-
cache.delete(key);
|
|
1700
|
-
return;
|
|
1692
|
+
if (entry.expiresAt !== 0) {
|
|
1693
|
+
const normalizedNow = asDateTimestampMs(now);
|
|
1694
|
+
if (normalizedNow === void 0 || asDateTimestampMs(entry.expiresAt) === void 0 || entry.expiresAt <= normalizedNow) {
|
|
1695
|
+
cache.delete(key);
|
|
1696
|
+
return;
|
|
1697
|
+
}
|
|
1701
1698
|
}
|
|
1702
1699
|
cache.delete(key);
|
|
1703
1700
|
cache.set(key, entry);
|
|
@@ -2522,15 +2519,15 @@ function resolveSlackInitialAgentRoute(params) {
|
|
|
2522
2519
|
accountId: params.account.accountId,
|
|
2523
2520
|
teamId: params.eventScope?.teamId || params.ctx.teamId || void 0,
|
|
2524
2521
|
peer: {
|
|
2525
|
-
kind: params.
|
|
2522
|
+
kind: params.chatType,
|
|
2526
2523
|
id: qualifySlackRoutePeerId({
|
|
2527
|
-
id: params.
|
|
2528
|
-
kind: params.
|
|
2524
|
+
id: params.chatType === "direct" ? params.message.user ?? "unknown" : params.message.channel,
|
|
2525
|
+
kind: params.chatType === "direct" ? "user" : "channel",
|
|
2529
2526
|
eventScope: params.eventScope
|
|
2530
2527
|
})
|
|
2531
2528
|
}
|
|
2532
2529
|
});
|
|
2533
|
-
if (!params.eventScope ||
|
|
2530
|
+
if (!params.eventScope || params.chatType !== "direct" || route.dmScope !== "main") return route;
|
|
2534
2531
|
const sessionKey = resolveSlackEnterpriseMainDmSessionKey({
|
|
2535
2532
|
baseSessionKey: route.sessionKey,
|
|
2536
2533
|
accountId: params.account.accountId,
|
|
@@ -2543,8 +2540,9 @@ function resolveSlackInitialAgentRoute(params) {
|
|
|
2543
2540
|
};
|
|
2544
2541
|
}
|
|
2545
2542
|
function resolveSlackRoutingContext(params) {
|
|
2546
|
-
const { ctx, account, message,
|
|
2547
|
-
const
|
|
2543
|
+
const { ctx, account, message, chatType, channelConfig, seedTopLevelRoomThread, assistantThreadTs, agentViewThreadTs, eventScope } = params;
|
|
2544
|
+
const isDirectMessage = chatType === "direct";
|
|
2545
|
+
const isRoom = chatType === "channel";
|
|
2548
2546
|
const replyToMode = channelConfig?.replyToMode ?? resolveSlackReplyToMode(account, chatType);
|
|
2549
2547
|
const threadContext = resolveSlackThreadContext({
|
|
2550
2548
|
message,
|
|
@@ -2553,9 +2551,8 @@ function resolveSlackRoutingContext(params) {
|
|
|
2553
2551
|
});
|
|
2554
2552
|
const threadTs = threadContext.incomingThreadTs;
|
|
2555
2553
|
const isThreadReply = threadContext.isThreadReply;
|
|
2556
|
-
const autoThreadId = !isThreadReply && replyToMode === "all" && threadContext.messageTs ? threadContext.messageTs : void 0;
|
|
2557
2554
|
const seedCandidateThreadId = threadContext.incomingThreadTs ?? threadContext.messageTs;
|
|
2558
|
-
const routedThreadId =
|
|
2555
|
+
const routedThreadId = isDirectMessage ? assistantThreadTs ?? agentViewThreadTs : (isThreadReply && threadTs ? threadTs : void 0) ?? (!isThreadReply && isRoom && seedTopLevelRoomThread && replyToMode !== "off" && seedCandidateThreadId ? seedCandidateThreadId : void 0);
|
|
2559
2556
|
const baseConversationId = qualifySlackConversationId(isDirectMessage ? `user:${message.user ?? "unknown"}` : message.channel, eventScope);
|
|
2560
2557
|
const runtimeBindingThreadId = routedThreadId ?? (isDirectMessage && isThreadReply ? threadTs : void 0);
|
|
2561
2558
|
const bindingRoute = resolveSlackConversationBindingRoute({
|
|
@@ -2565,8 +2562,7 @@ function resolveSlackRoutingContext(params) {
|
|
|
2565
2562
|
ctx,
|
|
2566
2563
|
account,
|
|
2567
2564
|
message,
|
|
2568
|
-
|
|
2569
|
-
isRoom,
|
|
2565
|
+
chatType,
|
|
2570
2566
|
eventScope
|
|
2571
2567
|
}),
|
|
2572
2568
|
accountId: account.accountId,
|
|
@@ -2613,8 +2609,8 @@ async function resolveSlackSessionEventRoutingContext(params) {
|
|
|
2613
2609
|
accountId: params.account.accountId,
|
|
2614
2610
|
kind: routing.chatType,
|
|
2615
2611
|
peerId: qualifySlackRoutePeerId({
|
|
2616
|
-
id: params.
|
|
2617
|
-
kind: params.
|
|
2612
|
+
id: params.chatType === "direct" ? message.user ?? "unknown" : message.channel,
|
|
2613
|
+
kind: params.chatType === "direct" ? "user" : "channel",
|
|
2618
2614
|
eventScope
|
|
2619
2615
|
})
|
|
2620
2616
|
};
|
|
@@ -2653,8 +2649,8 @@ async function resolveSlackSessionEventRoutingContext(params) {
|
|
|
2653
2649
|
} : void 0;
|
|
2654
2650
|
};
|
|
2655
2651
|
let owner = readOwner();
|
|
2656
|
-
if (owner?.source === "live" && params.
|
|
2657
|
-
if (!owner && params.
|
|
2652
|
+
if (owner?.source === "live" && params.chatType === "direct") allowDirectParent = getConversationSession(address)?.sessionKey === owner.route.sessionKey;
|
|
2653
|
+
if (!owner && params.chatType === "direct" && threadTs) {
|
|
2658
2654
|
const assistantContext = ctx.getSlackAssistantThreadContext(message.channel, threadTs, eventScope);
|
|
2659
2655
|
const managedThread = !eventScope && (await ctx.isSlackManagedViewThread(message.channel, threadTs) || await ctx.isSlackAgentView());
|
|
2660
2656
|
allowDirectParent = !(assistantContext ?? (managedThread ? void 0 : await readSlackAssistantThreadContext({
|
|
@@ -2854,9 +2850,6 @@ function createSlackExternalArgMenuStore() {
|
|
|
2854
2850
|
//#region extensions/slack/src/monitor/response-url-budget.ts
|
|
2855
2851
|
const SLACK_RESPONSE_URL_MAX_CALLS = 5;
|
|
2856
2852
|
var SlackResponseAlreadyReportedError = class extends Error {};
|
|
2857
|
-
function isSlackResponseAlreadyReportedError(error) {
|
|
2858
|
-
return error instanceof SlackResponseAlreadyReportedError;
|
|
2859
|
-
}
|
|
2860
2853
|
/** Count every response_url attempt, including requests Slack rejects. */
|
|
2861
2854
|
function createSlackResponseUrlBudget(respond, maxCalls = SLACK_RESPONSE_URL_MAX_CALLS) {
|
|
2862
2855
|
let remaining = maxCalls;
|
|
@@ -2898,7 +2891,7 @@ const SLACK_COMMAND_ARG_CONFIRM_TEXT_MAX = 300;
|
|
|
2898
2891
|
const SLACK_HEADER_TEXT_MAX = 150;
|
|
2899
2892
|
const SLACK_COMMAND_ARG_ACTION_BLOCKS_MAX = 47;
|
|
2900
2893
|
const loadSlashCommandsRuntime = createLazyRuntimeModule(() => import("openclaw/plugin-sdk/command-auth-native"));
|
|
2901
|
-
const loadSlashDispatchRuntime = createLazyRuntimeModule(() => import("./slash-dispatch.runtime
|
|
2894
|
+
const loadSlashDispatchRuntime = createLazyRuntimeModule(() => import("./slash-dispatch.runtime-gBj_uaLM.mjs"));
|
|
2902
2895
|
const loadPluginCommandRuntime = createLazyRuntimeModule(() => import("openclaw/plugin-sdk/plugin-command-runtime"));
|
|
2903
2896
|
function resolveSlackCommandMenuModelContext(params) {
|
|
2904
2897
|
if (!params.sessionKey.trim()) return {};
|
|
@@ -3016,64 +3009,47 @@ function buildSlackCommandArgMenuBlocks(params) {
|
|
|
3016
3009
|
const canUseStaticSelect = encodedChoices.every((choice) => choice.value.length <= SLACK_COMMAND_ARG_SELECT_OPTION_VALUE_MAX);
|
|
3017
3010
|
const canUseOverflow = canUseStaticSelect && encodedChoices.length >= SLACK_COMMAND_ARG_OVERFLOW_MIN && encodedChoices.length <= SLACK_COMMAND_ARG_OVERFLOW_MAX;
|
|
3018
3011
|
const canUseExternalSelect = params.supportsExternalSelect && canUseStaticSelect && encodedChoices.length > SLACK_COMMAND_ARG_SELECT_OPTIONS_MAX;
|
|
3019
|
-
const
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3012
|
+
const confirm = buildSlackArgMenuConfirm({
|
|
3013
|
+
command: params.command,
|
|
3014
|
+
arg: params.arg
|
|
3015
|
+
});
|
|
3016
|
+
const selectElement = {
|
|
3017
|
+
action_id: SLACK_COMMAND_ARG_ACTION_ID,
|
|
3018
|
+
confirm
|
|
3019
|
+
};
|
|
3020
|
+
const rows = canUseOverflow ? [{ elements: [{
|
|
3021
|
+
...selectElement,
|
|
3022
|
+
type: "overflow",
|
|
3023
|
+
options: buildSlackArgMenuOptions(encodedChoices)
|
|
3024
|
+
}] }] : canUseExternalSelect ? [{
|
|
3032
3025
|
block_id: `${SLACK_EXTERNAL_ARG_MENU_PREFIX}${params.createExternalMenuToken(encodedChoices)}`,
|
|
3033
3026
|
elements: [{
|
|
3027
|
+
...selectElement,
|
|
3034
3028
|
type: "external_select",
|
|
3035
|
-
action_id: SLACK_COMMAND_ARG_ACTION_ID,
|
|
3036
|
-
confirm: buildSlackArgMenuConfirm({
|
|
3037
|
-
command: params.command,
|
|
3038
|
-
arg: params.arg
|
|
3039
|
-
}),
|
|
3040
3029
|
min_query_length: 0,
|
|
3041
3030
|
placeholder: {
|
|
3042
3031
|
type: "plain_text",
|
|
3043
3032
|
text: `Search ${params.arg}`
|
|
3044
3033
|
}
|
|
3045
3034
|
}]
|
|
3046
|
-
}] : encodedChoices.length <= SLACK_COMMAND_ARG_BUTTON_ROW_SIZE || !canUseStaticSelect ? chunkItems(encodedChoices.filter((choice) => choice.value.length <= SLACK_COMMAND_ARG_BUTTON_VALUE_MAX), SLACK_COMMAND_ARG_BUTTON_ROW_SIZE).map((choices, rowIndex) => ({
|
|
3047
|
-
type: "
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
text:
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
type: "static_select",
|
|
3065
|
-
action_id: SLACK_COMMAND_ARG_ACTION_ID,
|
|
3066
|
-
confirm: buildSlackArgMenuConfirm({
|
|
3067
|
-
command: params.command,
|
|
3068
|
-
arg: params.arg
|
|
3069
|
-
}),
|
|
3070
|
-
placeholder: {
|
|
3071
|
-
type: "plain_text",
|
|
3072
|
-
text: index === 0 ? `Choose ${params.arg}` : `Choose ${params.arg} (${index + 1})`
|
|
3073
|
-
},
|
|
3074
|
-
options: buildSlackArgMenuOptions(choices)
|
|
3075
|
-
}]
|
|
3076
|
-
}));
|
|
3035
|
+
}] : encodedChoices.length <= SLACK_COMMAND_ARG_BUTTON_ROW_SIZE || !canUseStaticSelect ? chunkItems(encodedChoices.filter((choice) => choice.value.length <= SLACK_COMMAND_ARG_BUTTON_VALUE_MAX), SLACK_COMMAND_ARG_BUTTON_ROW_SIZE).map((choices, rowIndex) => ({ elements: choices.map((choice, colIndex) => ({
|
|
3036
|
+
type: "button",
|
|
3037
|
+
action_id: `${SLACK_COMMAND_ARG_ACTION_ID}_${rowIndex}_${colIndex}`,
|
|
3038
|
+
text: {
|
|
3039
|
+
type: "plain_text",
|
|
3040
|
+
text: truncateSlackText(choice.label, SLACK_COMMAND_ARG_BUTTON_TEXT_MAX)
|
|
3041
|
+
},
|
|
3042
|
+
value: choice.value,
|
|
3043
|
+
confirm
|
|
3044
|
+
})) })) : chunkItems(encodedChoices, SLACK_COMMAND_ARG_SELECT_OPTIONS_MAX).map((choices, index) => ({ elements: [{
|
|
3045
|
+
...selectElement,
|
|
3046
|
+
type: "static_select",
|
|
3047
|
+
placeholder: {
|
|
3048
|
+
type: "plain_text",
|
|
3049
|
+
text: index === 0 ? `Choose ${params.arg}` : `Choose ${params.arg} (${index + 1})`
|
|
3050
|
+
},
|
|
3051
|
+
options: buildSlackArgMenuOptions(choices)
|
|
3052
|
+
}] }));
|
|
3077
3053
|
const headerText = truncateSlackText(`/${params.command}: choose ${params.arg}`, SLACK_HEADER_TEXT_MAX);
|
|
3078
3054
|
const sectionText = truncateSlackText(params.title, 3e3);
|
|
3079
3055
|
const contextText = truncateSlackText(`Select one option to continue /${params.command} (${params.arg})`, 3e3);
|
|
@@ -3100,7 +3076,7 @@ function buildSlackCommandArgMenuBlocks(params) {
|
|
|
3100
3076
|
text: contextText
|
|
3101
3077
|
}]
|
|
3102
3078
|
},
|
|
3103
|
-
...visibleRows
|
|
3079
|
+
...visibleRows.map((row) => Object.assign({ type: "actions" }, row))
|
|
3104
3080
|
];
|
|
3105
3081
|
}
|
|
3106
3082
|
const NON_PLUGIN_COMMAND_DISPATCH = Object.freeze({ kind: "non-plugin" });
|
|
@@ -3185,35 +3161,16 @@ function createSlackCommandHandler(params) {
|
|
|
3185
3161
|
log: logVerbose
|
|
3186
3162
|
})) return false;
|
|
3187
3163
|
}
|
|
3188
|
-
if (isRoom) {
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
});
|
|
3199
|
-
if (ctx.useAccessGroups) {
|
|
3200
|
-
const channelAllowlistConfigured = (ctx.channelsConfigKeys?.length ?? 0) > 0;
|
|
3201
|
-
const channelAllowed = channelConfig?.allowed !== false;
|
|
3202
|
-
if (!isSlackChannelAllowedByPolicy({
|
|
3203
|
-
groupPolicy: ctx.groupPolicy,
|
|
3204
|
-
channelAllowlistConfigured,
|
|
3205
|
-
channelAllowed
|
|
3206
|
-
})) {
|
|
3207
|
-
await respondEphemeral("This channel is not allowed.");
|
|
3208
|
-
return false;
|
|
3209
|
-
}
|
|
3210
|
-
const hasExplicitConfig = Boolean(channelConfig?.matchSource);
|
|
3211
|
-
if (!channelAllowed && (ctx.groupPolicy !== "open" || hasExplicitConfig)) {
|
|
3212
|
-
await respondEphemeral("This channel is not allowed.");
|
|
3213
|
-
return false;
|
|
3214
|
-
}
|
|
3215
|
-
}
|
|
3216
|
-
}
|
|
3164
|
+
if (isRoom) channelConfig = resolveSlackChannelConfig({
|
|
3165
|
+
teamId: eventScope?.teamId ?? ctx.teamId,
|
|
3166
|
+
allowUnscoped: ctx.installationIdentity?.kind !== "enterprise",
|
|
3167
|
+
channelId: command.channel_id,
|
|
3168
|
+
channelName: channelInfo?.name,
|
|
3169
|
+
channels: ctx.channelsConfig,
|
|
3170
|
+
channelKeys: ctx.channelsConfigKeys,
|
|
3171
|
+
defaultRequireMention: ctx.defaultRequireMention,
|
|
3172
|
+
allowNameMatching: ctx.allowNameMatching
|
|
3173
|
+
});
|
|
3217
3174
|
const senderName = (await ctx.resolveUserName(command.user_id, eventScope))?.name ?? command.user_name ?? command.user_id;
|
|
3218
3175
|
const slashIngress = await resolveSlackCommandIngress({
|
|
3219
3176
|
ctx,
|
|
@@ -3268,10 +3225,7 @@ function createSlackCommandHandler(params) {
|
|
|
3268
3225
|
ts: p.eventTs,
|
|
3269
3226
|
thread_ts: p.threadTs
|
|
3270
3227
|
},
|
|
3271
|
-
|
|
3272
|
-
isGroupDm,
|
|
3273
|
-
isRoom,
|
|
3274
|
-
isRoomish,
|
|
3228
|
+
chatType,
|
|
3275
3229
|
channelConfig,
|
|
3276
3230
|
eventScope
|
|
3277
3231
|
});
|
|
@@ -3507,7 +3461,7 @@ function createSlackCommandHandler(params) {
|
|
|
3507
3461
|
return true;
|
|
3508
3462
|
} catch (err) {
|
|
3509
3463
|
runtime.error?.(danger(`slack slash handler failed: ${formatErrorMessage(err)}`));
|
|
3510
|
-
if (!
|
|
3464
|
+
if (!(err instanceof SlackResponseAlreadyReportedError) && responseBudget.remaining() !== 0) await respondEphemeral("Sorry, something went wrong handling that command.");
|
|
3511
3465
|
}
|
|
3512
3466
|
return false;
|
|
3513
3467
|
};
|
|
@@ -3568,7 +3522,6 @@ async function registerSlackMonitorSlashCommands(params) {
|
|
|
3568
3522
|
let nativeCommands = [];
|
|
3569
3523
|
let slashCommandsRuntime = null;
|
|
3570
3524
|
let pluginCommandRuntimeModule = null;
|
|
3571
|
-
let pluginCommandRuntime = null;
|
|
3572
3525
|
if (registration.mode === "disabled" && resolveNativeCommandsEnabled({
|
|
3573
3526
|
providerId: "slack",
|
|
3574
3527
|
providerSetting: account.config.commands?.native,
|
|
@@ -3585,7 +3538,7 @@ async function registerSlackMonitorSlashCommands(params) {
|
|
|
3585
3538
|
provider: "slack"
|
|
3586
3539
|
});
|
|
3587
3540
|
pluginCommandRuntimeModule = await loadPluginCommandRuntime();
|
|
3588
|
-
pluginCommandRuntime = pluginCommandRuntimeModule.createPluginCommandRuntime();
|
|
3541
|
+
const pluginCommandRuntime = pluginCommandRuntimeModule.createPluginCommandRuntime();
|
|
3589
3542
|
nativeCommands = mergeNativeCommandSpecs({
|
|
3590
3543
|
primary: nativeCommands,
|
|
3591
3544
|
secondary: pluginCommandRuntime.listNativeCandidates("slack")
|
|
@@ -3594,7 +3547,7 @@ async function registerSlackMonitorSlashCommands(params) {
|
|
|
3594
3547
|
}
|
|
3595
3548
|
if (registration.mode === "single") registerCommand(buildSlackSlashCommandMatcher(registration.name));
|
|
3596
3549
|
else if (registration.mode === "native") {
|
|
3597
|
-
if (!slashCommandsRuntime || !pluginCommandRuntimeModule
|
|
3550
|
+
if (!slashCommandsRuntime || !pluginCommandRuntimeModule) throw new Error("Missing command runtimes for native Slack commands.");
|
|
3598
3551
|
for (const command of nativeCommands) {
|
|
3599
3552
|
const pluginCommandCandidate = "prepareDispatch" in command ? command : void 0;
|
|
3600
3553
|
registerCommand(`/${command.name}`, (cmd) => {
|
|
@@ -3666,18 +3619,19 @@ async function registerSlackMonitorSlashCommands(params) {
|
|
|
3666
3619
|
}
|
|
3667
3620
|
const respondFn = respond ?? (async (message) => {
|
|
3668
3621
|
if (!body.channel?.id || !body.user?.id) return new Response(null, { status: 204 });
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
await args.client.chat.postEphemeral({
|
|
3622
|
+
return await deliverSlackSlashResponseWithWebApi({
|
|
3623
|
+
client: args.client,
|
|
3672
3624
|
token: ctx.botToken,
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3625
|
+
command: {
|
|
3626
|
+
channel_id: body.channel.id,
|
|
3627
|
+
user_id: body.user.id
|
|
3628
|
+
},
|
|
3629
|
+
threadTs: body.container?.thread_ts ?? body.message?.thread_ts,
|
|
3630
|
+
message: {
|
|
3631
|
+
...typeof message === "string" ? { text: message } : message,
|
|
3632
|
+
response_type: "ephemeral"
|
|
3633
|
+
}
|
|
3679
3634
|
});
|
|
3680
|
-
return new Response(null, { status: 200 });
|
|
3681
3635
|
});
|
|
3682
3636
|
const parsed = parseSlackCommandArgValue(action?.value ?? action?.selected_option?.value);
|
|
3683
3637
|
if (!parsed) {
|
|
@@ -3745,6 +3699,7 @@ async function deliverSlackSlashResponseWithWebApi(params) {
|
|
|
3745
3699
|
const blocks = "blocks" in payload && Array.isArray(payload.blocks) ? payload.blocks : void 0;
|
|
3746
3700
|
const mrkdwn = "mrkdwn" in payload && typeof payload.mrkdwn === "boolean" ? payload.mrkdwn : void 0;
|
|
3747
3701
|
const message = {
|
|
3702
|
+
...params.token !== void 0 ? { token: params.token } : {},
|
|
3748
3703
|
channel: params.command.channel_id,
|
|
3749
3704
|
...params.threadTs ? { thread_ts: params.threadTs } : {},
|
|
3750
3705
|
text,
|
|
@@ -3808,7 +3763,6 @@ function resolveSlackListenerEventScope(params) {
|
|
|
3808
3763
|
//#region extensions/slack/src/monitor/events/agent.ts
|
|
3809
3764
|
function registerSlackAgentEvents(params) {
|
|
3810
3765
|
const { ctx, trackEvent } = params;
|
|
3811
|
-
const slackApp = ctx.app;
|
|
3812
3766
|
const handleCommand = createSlackCommandHandler({
|
|
3813
3767
|
ctx,
|
|
3814
3768
|
account: resolveSlackAccount({
|
|
@@ -3817,12 +3771,12 @@ function registerSlackAgentEvents(params) {
|
|
|
3817
3771
|
}),
|
|
3818
3772
|
trackEvent
|
|
3819
3773
|
});
|
|
3820
|
-
|
|
3774
|
+
ctx.app.event("app_context_changed", async ({ body }) => {
|
|
3821
3775
|
if (ctx.shouldDropMismatchedSlackEvent(body)) return;
|
|
3822
3776
|
trackEvent?.();
|
|
3823
3777
|
await ctx.recordSlackAgentView();
|
|
3824
3778
|
});
|
|
3825
|
-
|
|
3779
|
+
ctx.app.event("agent_session_stopped", async ({ event, body, context, client }) => {
|
|
3826
3780
|
if (ctx.shouldDropMismatchedSlackEvent(body)) return;
|
|
3827
3781
|
const eventScope = resolveSlackListenerEventScope({
|
|
3828
3782
|
ctx,
|
|
@@ -3882,7 +3836,7 @@ function registerSlackAgentEvents(params) {
|
|
|
3882
3836
|
eventScope
|
|
3883
3837
|
});
|
|
3884
3838
|
});
|
|
3885
|
-
|
|
3839
|
+
ctx.app.event("agent_session_title_changed", async ({ event, body, context, client }) => {
|
|
3886
3840
|
const runtimeContext = await params.ctx.readRuntimeContext();
|
|
3887
3841
|
const runtimeAccount = resolveSlackAccount({
|
|
3888
3842
|
cfg: runtimeContext.cfg,
|
|
@@ -3905,9 +3859,6 @@ function registerSlackAgentEvents(params) {
|
|
|
3905
3859
|
eventScope
|
|
3906
3860
|
});
|
|
3907
3861
|
if (!auth.allowed) return;
|
|
3908
|
-
const isDirectMessage = auth.channelType === "im";
|
|
3909
|
-
const isGroupDm = auth.channelType === "mpim";
|
|
3910
|
-
const isRoom = auth.channelType === "channel" || auth.channelType === "group";
|
|
3911
3862
|
const routing = await resolveSlackSessionEventRoutingContext({
|
|
3912
3863
|
intent: "title",
|
|
3913
3864
|
ctx: runtimeContext,
|
|
@@ -3919,10 +3870,7 @@ function registerSlackAgentEvents(params) {
|
|
|
3919
3870
|
ts: event.event_ts,
|
|
3920
3871
|
thread_ts: event.thread_ts
|
|
3921
3872
|
},
|
|
3922
|
-
|
|
3923
|
-
isGroupDm,
|
|
3924
|
-
isRoom,
|
|
3925
|
-
isRoomish: isRoom || isGroupDm,
|
|
3873
|
+
chatType: resolveSlackChatType(auth.channelType),
|
|
3926
3874
|
eventScope
|
|
3927
3875
|
});
|
|
3928
3876
|
if (!await getSlackRuntime().agent.session.patchSessionEntry({
|
|
@@ -3958,18 +3906,14 @@ function normalizeAssistantThread(event, getPrevious) {
|
|
|
3958
3906
|
const threadContext = thread.context;
|
|
3959
3907
|
const eventContext = event.context;
|
|
3960
3908
|
const resolveContextString = (key, previousValue) => threadContext?.[key]?.trim() || eventContext?.[key]?.trim() || previousValue;
|
|
3961
|
-
const
|
|
3962
|
-
if (threadContext && "enterprise_id" in threadContext) return threadContext.enterprise_id === null ? null : threadContext.enterprise_id?.trim() || previous?.enterpriseId;
|
|
3963
|
-
if (eventContext && "enterprise_id" in eventContext) return eventContext.enterprise_id === null ? null : eventContext.enterprise_id?.trim() || previous?.enterpriseId;
|
|
3964
|
-
return previous?.enterpriseId;
|
|
3965
|
-
})();
|
|
3909
|
+
const enterpriseContext = threadContext && "enterprise_id" in threadContext ? threadContext : eventContext;
|
|
3966
3910
|
return {
|
|
3967
3911
|
assistantChannelId: channelId,
|
|
3968
3912
|
threadTs,
|
|
3969
3913
|
userId: thread.user_id?.trim() || previous?.userId,
|
|
3970
3914
|
channelId: resolveContextString("channel_id", previous?.channelId),
|
|
3971
3915
|
teamId: resolveContextString("team_id", previous?.teamId),
|
|
3972
|
-
enterpriseId
|
|
3916
|
+
enterpriseId: enterpriseContext?.enterprise_id === null ? null : enterpriseContext?.enterprise_id?.trim() || previous?.enterpriseId
|
|
3973
3917
|
};
|
|
3974
3918
|
}
|
|
3975
3919
|
async function persistAssistantThreadMetadata(params) {
|
|
@@ -4069,25 +4013,6 @@ function migrateSlackChannelConfig(params) {
|
|
|
4069
4013
|
//#region extensions/slack/src/monitor/events/channels.ts
|
|
4070
4014
|
function registerSlackChannelEvents(params) {
|
|
4071
4015
|
const { ctx, trackEvent } = params;
|
|
4072
|
-
const enqueueChannelSystemEvent = async (paramsLocal) => {
|
|
4073
|
-
const runtimeContext = await params.ctx.readRuntimeContext();
|
|
4074
|
-
if (!runtimeContext.isChannelAllowed({
|
|
4075
|
-
teamId: paramsLocal.eventScope?.teamId ?? runtimeContext.teamId,
|
|
4076
|
-
channelId: paramsLocal.channelId,
|
|
4077
|
-
channelName: paramsLocal.channelName,
|
|
4078
|
-
channelType: "channel"
|
|
4079
|
-
})) return;
|
|
4080
|
-
const label = resolveSlackChannelLabel({
|
|
4081
|
-
channelId: paramsLocal.channelId,
|
|
4082
|
-
channelName: paramsLocal.channelName
|
|
4083
|
-
});
|
|
4084
|
-
const route = runtimeContext.resolveSlackSystemEventRoute({
|
|
4085
|
-
channelId: paramsLocal.channelId,
|
|
4086
|
-
channelType: "channel",
|
|
4087
|
-
eventScope: paramsLocal.eventScope
|
|
4088
|
-
});
|
|
4089
|
-
enqueueRoutedSystemEvent(`Slack channel ${paramsLocal.kind}: ${label}.`, route, { contextKey: `slack:channel:${paramsLocal.eventScope ? `${paramsLocal.eventScope.teamId}:` : ""}${paramsLocal.kind}:${paramsLocal.channelId ?? paramsLocal.channelName ?? "unknown"}:${paramsLocal.eventId}` });
|
|
4090
|
-
};
|
|
4091
4016
|
for (const [eventName, kind] of [["channel_created", "created"], ["channel_rename", "renamed"]]) ctx.app.event(eventName, async (args) => {
|
|
4092
4017
|
const { event, body, context, client } = args;
|
|
4093
4018
|
const eventScope = resolveSlackListenerEventScope({
|
|
@@ -4099,13 +4024,26 @@ function registerSlackChannelEvents(params) {
|
|
|
4099
4024
|
if (eventScope === null || ctx.shouldDropMismatchedSlackEvent(body)) return;
|
|
4100
4025
|
trackEvent?.();
|
|
4101
4026
|
const channel = event.channel;
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4027
|
+
const channelId = channel?.id;
|
|
4028
|
+
const channelName = kind === "renamed" ? channel?.name_normalized ?? channel?.name : channel?.name;
|
|
4029
|
+
const eventId = body.event_id;
|
|
4030
|
+
const runtimeContext = await params.ctx.readRuntimeContext();
|
|
4031
|
+
if (!runtimeContext.isChannelAllowed({
|
|
4032
|
+
teamId: eventScope?.teamId ?? runtimeContext.teamId,
|
|
4033
|
+
channelId,
|
|
4034
|
+
channelName,
|
|
4035
|
+
channelType: "channel"
|
|
4036
|
+
})) return;
|
|
4037
|
+
const label = resolveSlackChannelLabel({
|
|
4038
|
+
channelId,
|
|
4039
|
+
channelName
|
|
4040
|
+
});
|
|
4041
|
+
const route = runtimeContext.resolveSlackSystemEventRoute({
|
|
4042
|
+
channelId,
|
|
4043
|
+
channelType: "channel",
|
|
4107
4044
|
eventScope
|
|
4108
4045
|
});
|
|
4046
|
+
enqueueRoutedSystemEvent(`Slack channel ${kind}: ${label}.`, route, { contextKey: `slack:channel:${eventScope ? `${eventScope.teamId}:` : ""}${kind}:${channelId ?? channelName ?? "unknown"}:${eventId}` });
|
|
4109
4047
|
});
|
|
4110
4048
|
}
|
|
4111
4049
|
function registerSlackChannelIdChangedEvent(params) {
|
|
@@ -4289,9 +4227,7 @@ function summarizeRichTextPreview(value) {
|
|
|
4289
4227
|
collectRichTextFragments(value, fragments);
|
|
4290
4228
|
if (fragments.length === 0) return;
|
|
4291
4229
|
const joined = fragments.join(" ").replace(/\s+/g, " ").trim();
|
|
4292
|
-
|
|
4293
|
-
const max = 120;
|
|
4294
|
-
return joined.length <= max ? joined : truncateSlackText(joined, max);
|
|
4230
|
+
return truncateSlackText(joined, 120);
|
|
4295
4231
|
}
|
|
4296
4232
|
function summarizeAction(action) {
|
|
4297
4233
|
const typed = action;
|
|
@@ -4355,7 +4291,7 @@ function formatInteractionSelectionLabel(params) {
|
|
|
4355
4291
|
return params.actionId;
|
|
4356
4292
|
}
|
|
4357
4293
|
function resolveSlackActionValue(summary) {
|
|
4358
|
-
return normalizeOptionalString(summary.value) ?? summary.selectedValues?.
|
|
4294
|
+
return normalizeOptionalString(summary.value) ?? summary.selectedValues?.[0];
|
|
4359
4295
|
}
|
|
4360
4296
|
function buildSlackPluginInteractionData(params) {
|
|
4361
4297
|
const actionId = normalizeOptionalString(params.actionId) ?? "";
|
|
@@ -4413,13 +4349,14 @@ async function respondEphemeral(respond, text) {
|
|
|
4413
4349
|
});
|
|
4414
4350
|
} catch {}
|
|
4415
4351
|
}
|
|
4416
|
-
async function updateSlackInteractionMessage(params) {
|
|
4417
|
-
|
|
4352
|
+
async function updateSlackInteractionMessage(params, message) {
|
|
4353
|
+
const { channelId, messageTs } = params.parsed;
|
|
4354
|
+
if (!channelId || !messageTs) return;
|
|
4418
4355
|
await (params.eventScope?.client ?? params.ctx.app.client).chat.update({
|
|
4419
|
-
channel:
|
|
4420
|
-
ts:
|
|
4421
|
-
text:
|
|
4422
|
-
...
|
|
4356
|
+
channel: channelId,
|
|
4357
|
+
ts: messageTs,
|
|
4358
|
+
text: message.text,
|
|
4359
|
+
...message.blocks ? { blocks: message.blocks } : {}
|
|
4423
4360
|
});
|
|
4424
4361
|
}
|
|
4425
4362
|
function resolveSlackApprovalTerminalLabel(approval) {
|
|
@@ -4477,11 +4414,7 @@ async function handleSlackPluginBindingApproval(params) {
|
|
|
4477
4414
|
senderId: params.parsed.userId
|
|
4478
4415
|
});
|
|
4479
4416
|
try {
|
|
4480
|
-
await updateSlackInteractionMessage({
|
|
4481
|
-
ctx: params.ctx,
|
|
4482
|
-
eventScope: params.eventScope,
|
|
4483
|
-
channelId: params.parsed.channelId,
|
|
4484
|
-
messageTs: params.parsed.messageTs,
|
|
4417
|
+
await updateSlackInteractionMessage(params, {
|
|
4485
4418
|
text: params.parsed.typedBody.message?.text ?? "",
|
|
4486
4419
|
blocks: []
|
|
4487
4420
|
});
|
|
@@ -4525,7 +4458,7 @@ async function handleSlackApprovalInteraction(params) {
|
|
|
4525
4458
|
channelId,
|
|
4526
4459
|
messageTs
|
|
4527
4460
|
}, async () => {
|
|
4528
|
-
const { readSlackMessages } = await import("./actions-
|
|
4461
|
+
const { readSlackMessages } = await import("./actions-DDoAJnrH.mjs").then((n) => n.t);
|
|
4529
4462
|
const { messages } = await readSlackMessages(channelId, {
|
|
4530
4463
|
client: params.eventScope?.client ?? params.ctx.app.client,
|
|
4531
4464
|
messageId: messageTs,
|
|
@@ -4533,11 +4466,7 @@ async function handleSlackApprovalInteraction(params) {
|
|
|
4533
4466
|
});
|
|
4534
4467
|
const current = messages[0];
|
|
4535
4468
|
if (!hasSlackApprovalControl(current?.blocks, params.approval)) return false;
|
|
4536
|
-
await updateSlackInteractionMessage({
|
|
4537
|
-
ctx: params.ctx,
|
|
4538
|
-
eventScope: params.eventScope,
|
|
4539
|
-
channelId,
|
|
4540
|
-
messageTs,
|
|
4469
|
+
await updateSlackInteractionMessage(params, {
|
|
4541
4470
|
text: truncateSlackText(`${prefix}: ${terminalLabel}`, 4e3),
|
|
4542
4471
|
blocks: buildSlackApprovalTerminalBlocks({
|
|
4543
4472
|
blocks: current?.blocks,
|
|
@@ -4592,11 +4521,7 @@ async function handleSlackLegacyApprovalInteraction(params) {
|
|
|
4592
4521
|
resolveMethod
|
|
4593
4522
|
});
|
|
4594
4523
|
try {
|
|
4595
|
-
await updateSlackInteractionMessage({
|
|
4596
|
-
ctx: params.ctx,
|
|
4597
|
-
eventScope: params.eventScope,
|
|
4598
|
-
channelId: params.parsed.channelId,
|
|
4599
|
-
messageTs: params.parsed.messageTs,
|
|
4524
|
+
await updateSlackInteractionMessage(params, {
|
|
4600
4525
|
text: params.parsed.typedBody.message?.text ?? "",
|
|
4601
4526
|
blocks: []
|
|
4602
4527
|
});
|
|
@@ -4650,11 +4575,7 @@ async function dispatchSlackPluginInteraction(params) {
|
|
|
4650
4575
|
reply,
|
|
4651
4576
|
followUp: reply,
|
|
4652
4577
|
editMessage: async ({ text, blocks }) => {
|
|
4653
|
-
await updateSlackInteractionMessage({
|
|
4654
|
-
ctx: params.ctx,
|
|
4655
|
-
eventScope: params.eventScope,
|
|
4656
|
-
channelId: params.parsed.channelId,
|
|
4657
|
-
messageTs: params.parsed.messageTs,
|
|
4578
|
+
await updateSlackInteractionMessage(params, {
|
|
4658
4579
|
text: text ?? params.parsed.typedBody.message?.text ?? "",
|
|
4659
4580
|
blocks: Array.isArray(blocks) ? blocks : void 0
|
|
4660
4581
|
});
|
|
@@ -4785,11 +4706,7 @@ async function updateSlackLegacyBlockAction(params) {
|
|
|
4785
4706
|
const originalBlocks = params.parsed.typedBody.message?.blocks;
|
|
4786
4707
|
if (!Array.isArray(originalBlocks) || !params.parsed.channelId || !params.parsed.messageTs || !params.parsed.blockId) return;
|
|
4787
4708
|
try {
|
|
4788
|
-
await updateSlackInteractionMessage({
|
|
4789
|
-
ctx: params.ctx,
|
|
4790
|
-
eventScope: params.eventScope,
|
|
4791
|
-
channelId: params.parsed.channelId,
|
|
4792
|
-
messageTs: params.parsed.messageTs,
|
|
4709
|
+
await updateSlackInteractionMessage(params, {
|
|
4793
4710
|
text: params.parsed.typedBody.message?.text ?? "",
|
|
4794
4711
|
blocks: buildSlackConfirmationBlocks({
|
|
4795
4712
|
parsed: params.parsed,
|
|
@@ -4932,11 +4849,6 @@ function shouldHandleSlackModalLifecycleBody(body) {
|
|
|
4932
4849
|
const metadata = parseSlackModalPrivateMetadata(typed.view?.private_metadata);
|
|
4933
4850
|
return Boolean(metadata.pluginInteractiveData?.trim());
|
|
4934
4851
|
}
|
|
4935
|
-
function resolveSlackModalPluginNamespace(data) {
|
|
4936
|
-
if (!data) return;
|
|
4937
|
-
const separatorIndex = data.indexOf(":");
|
|
4938
|
-
return separatorIndex >= 0 ? data.slice(0, separatorIndex) : data;
|
|
4939
|
-
}
|
|
4940
4852
|
function resolveSlackPluginSystemEventPayload(result) {
|
|
4941
4853
|
if (!result || typeof result !== "object") return;
|
|
4942
4854
|
const systemEvent = result.systemEvent;
|
|
@@ -5067,7 +4979,7 @@ async function dispatchSlackModalPluginInteractiveHandler(params) {
|
|
|
5067
4979
|
});
|
|
5068
4980
|
return {
|
|
5069
4981
|
...result,
|
|
5070
|
-
namespace: result.matched ?
|
|
4982
|
+
namespace: result.matched ? params.data.split(":", 1)[0] : void 0,
|
|
5071
4983
|
systemEvent: result.matched ? resolveSlackPluginSystemEventPayload(result.result) : void 0
|
|
5072
4984
|
};
|
|
5073
4985
|
}
|
|
@@ -5447,23 +5359,25 @@ function registerSlackInteractionEvents(params) {
|
|
|
5447
5359
|
//#region extensions/slack/src/monitor/events/members.ts
|
|
5448
5360
|
function registerSlackMemberEvents(params) {
|
|
5449
5361
|
const { ctx, trackEvent } = params;
|
|
5450
|
-
const
|
|
5362
|
+
for (const verb of ["joined", "left"]) ctx.app.event(`member_${verb}_channel`, async (args) => {
|
|
5363
|
+
const { event, body, context, client } = args;
|
|
5364
|
+
const eventId = body.event_id;
|
|
5451
5365
|
try {
|
|
5452
5366
|
const runtimeContext = await params.ctx.readRuntimeContext();
|
|
5453
5367
|
const eventScope = resolveSlackListenerEventScope({
|
|
5454
5368
|
ctx: runtimeContext,
|
|
5455
|
-
body
|
|
5456
|
-
context
|
|
5457
|
-
client
|
|
5369
|
+
body,
|
|
5370
|
+
context,
|
|
5371
|
+
client
|
|
5458
5372
|
});
|
|
5459
5373
|
if (eventScope === null) return;
|
|
5460
|
-
if (runtimeContext.shouldDropMismatchedSlackEvent(
|
|
5374
|
+
if (runtimeContext.shouldDropMismatchedSlackEvent(body)) return;
|
|
5461
5375
|
trackEvent?.();
|
|
5462
|
-
const payload =
|
|
5376
|
+
const payload = event;
|
|
5463
5377
|
const channelId = payload.channel;
|
|
5464
5378
|
const channelInfo = channelId ? await runtimeContext.resolveChannelName(channelId, eventScope) : {};
|
|
5465
5379
|
const channelType = payload.channel_type ?? channelInfo?.type;
|
|
5466
|
-
if (
|
|
5380
|
+
if (verb === "joined" && payload.user === runtimeContext.botUserId && channelId) {
|
|
5467
5381
|
const roomType = normalizeSlackChannelType(channelType, channelId);
|
|
5468
5382
|
if (roomType === "channel" || roomType === "group") {
|
|
5469
5383
|
const roomAllowed = runtimeContext.isChannelAllowed({
|
|
@@ -5517,23 +5431,16 @@ function registerSlackMemberEvents(params) {
|
|
|
5517
5431
|
senderId: payload.user,
|
|
5518
5432
|
channelId,
|
|
5519
5433
|
channelType,
|
|
5520
|
-
eventKind: `member-${
|
|
5434
|
+
eventKind: `member-${verb}`,
|
|
5521
5435
|
eventScope
|
|
5522
5436
|
});
|
|
5523
5437
|
if (!ingressContext) return;
|
|
5524
5438
|
const userLabel = (payload.user ? await runtimeContext.resolveUserName(payload.user, eventScope) : {})?.name ?? payload.user ?? "someone";
|
|
5525
|
-
enqueueRoutedSystemEvent(`Slack: ${userLabel} ${
|
|
5439
|
+
enqueueRoutedSystemEvent(`Slack: ${userLabel} ${verb} ${ingressContext.channelLabel}.`, ingressContext.route, { contextKey: `slack:member:${eventScope ? `${eventScope.teamId}:` : ""}${verb}:${channelId ?? "unknown"}:${payload.user ?? "unknown"}:${eventId}` });
|
|
5526
5440
|
} catch (err) {
|
|
5527
|
-
ctx.runtime.error?.(danger(`slack ${
|
|
5441
|
+
ctx.runtime.error?.(danger(`slack ${verb} handler failed: ${formatErrorMessage(err)}`));
|
|
5528
5442
|
if (err instanceof SlackSystemEventAuthRetryError) throw err;
|
|
5529
5443
|
}
|
|
5530
|
-
};
|
|
5531
|
-
for (const verb of ["joined", "left"]) ctx.app.event(`member_${verb}_channel`, async (args) => {
|
|
5532
|
-
await handleMemberChannelEvent({
|
|
5533
|
-
verb,
|
|
5534
|
-
...args,
|
|
5535
|
-
eventId: args.body.event_id
|
|
5536
|
-
});
|
|
5537
5444
|
});
|
|
5538
5445
|
}
|
|
5539
5446
|
//#endregion
|
|
@@ -5639,9 +5546,6 @@ function resolveSlackMessageSubtypeHandler(event) {
|
|
|
5639
5546
|
//#endregion
|
|
5640
5547
|
//#region extensions/slack/src/monitor/events/messages.ts
|
|
5641
5548
|
const slackInboundLog = createSubsystemLogger("gateway/channels/slack").child("inbound");
|
|
5642
|
-
function formatSlackInboundLogLine(params) {
|
|
5643
|
-
return `Inbound app_mention ${`slack:${params.workspaceId}:channel:${params.channelId}:user:${params.userId}`} -> bot:${params.botUserId} (${params.channelType}, ${params.bodyChars} chars)`;
|
|
5644
|
-
}
|
|
5645
5549
|
function isBotAuthoredEnterpriseEvent(event) {
|
|
5646
5550
|
return Boolean(normalizeOptionalString(event.bot_id)) || event.subtype === "bot_message";
|
|
5647
5551
|
}
|
|
@@ -5807,14 +5711,8 @@ function registerSlackMessageEvents(params) {
|
|
|
5807
5711
|
return;
|
|
5808
5712
|
}
|
|
5809
5713
|
if (channelType === "im" || channelType === "mpim") return;
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
channelId: mention.channel,
|
|
5813
|
-
channelType: channelType ?? "channel",
|
|
5814
|
-
userId: normalizeOptionalString(mention.user) ?? "unknown",
|
|
5815
|
-
botUserId: ctx.botUserId,
|
|
5816
|
-
bodyChars: normalizeOptionalString(mention.text)?.length ?? 0
|
|
5817
|
-
}));
|
|
5714
|
+
const from = `slack:${eventScope?.teamId ?? ctx.teamId}:channel:${mention.channel}:user:${normalizeOptionalString(mention.user) ?? "unknown"}`;
|
|
5715
|
+
slackInboundLog.info(`Inbound app_mention ${from} -> bot:${ctx.botUserId} (${channelType}, ${normalizeOptionalString(mention.text)?.length ?? 0} chars)`);
|
|
5818
5716
|
noteConversationMessage(mention, eventScope);
|
|
5819
5717
|
await handleSlackMessage(mention, {
|
|
5820
5718
|
source: "app_mention",
|
|
@@ -5890,7 +5788,17 @@ function shouldEmitSlackReactionNotification(params) {
|
|
|
5890
5788
|
function registerSlackReactionEvents(params) {
|
|
5891
5789
|
const { ctx, trackEvent } = params;
|
|
5892
5790
|
const resolveUserName = (userId, eventScope) => eventScope ? ctx.resolveUserName(userId, eventScope) : ctx.resolveUserName(userId);
|
|
5893
|
-
const
|
|
5791
|
+
for (const action of ["added", "removed"]) ctx.app.event(`reaction_${action}`, async (args) => {
|
|
5792
|
+
const { body, context, client } = args;
|
|
5793
|
+
const event = args.event;
|
|
5794
|
+
const eventScope = resolveSlackListenerEventScope({
|
|
5795
|
+
ctx,
|
|
5796
|
+
body,
|
|
5797
|
+
context,
|
|
5798
|
+
client
|
|
5799
|
+
});
|
|
5800
|
+
if (eventScope === null || ctx.shouldDropMismatchedSlackEvent(body)) return;
|
|
5801
|
+
const eventId = body.event_id;
|
|
5894
5802
|
try {
|
|
5895
5803
|
const runtimeContext = await params.ctx.readRuntimeContext();
|
|
5896
5804
|
const item = event.item;
|
|
@@ -5906,9 +5814,7 @@ function registerSlackReactionEvents(params) {
|
|
|
5906
5814
|
eventScope
|
|
5907
5815
|
});
|
|
5908
5816
|
if (!ingressContext) return;
|
|
5909
|
-
const
|
|
5910
|
-
const authorInfoPromise = event.item_user ? resolveUserName(event.item_user, eventScope) : Promise.resolve(void 0);
|
|
5911
|
-
const [actorInfo, authorInfo] = await Promise.all([actorInfoPromise, authorInfoPromise]);
|
|
5817
|
+
const [actorInfo, authorInfo] = await Promise.all([event.user, event.item_user].map((userId) => userId ? resolveUserName(userId, eventScope) : Promise.resolve(void 0)));
|
|
5912
5818
|
if (!shouldEmitSlackReactionNotification({
|
|
5913
5819
|
ctx: runtimeContext,
|
|
5914
5820
|
event,
|
|
@@ -5924,17 +5830,6 @@ function registerSlackReactionEvents(params) {
|
|
|
5924
5830
|
} catch (err) {
|
|
5925
5831
|
ctx.runtime.error?.(danger(`slack reaction handler failed: ${formatErrorMessage(err)}`));
|
|
5926
5832
|
}
|
|
5927
|
-
};
|
|
5928
|
-
for (const action of ["added", "removed"]) ctx.app.event(`reaction_${action}`, async (args) => {
|
|
5929
|
-
const { event, body, context, client } = args;
|
|
5930
|
-
const eventScope = resolveSlackListenerEventScope({
|
|
5931
|
-
ctx,
|
|
5932
|
-
body,
|
|
5933
|
-
context,
|
|
5934
|
-
client
|
|
5935
|
-
});
|
|
5936
|
-
if (eventScope === null || ctx.shouldDropMismatchedSlackEvent(body)) return;
|
|
5937
|
-
await handleReactionEvent(event, action, eventScope, body.event_id);
|
|
5938
5833
|
});
|
|
5939
5834
|
}
|
|
5940
5835
|
//#endregion
|
|
@@ -6092,7 +5987,7 @@ function buildSlackDebounceKey(message, accountId, teamId) {
|
|
|
6092
5987
|
}
|
|
6093
5988
|
//#endregion
|
|
6094
5989
|
//#region extensions/slack/src/monitor/message-handler.ts
|
|
6095
|
-
const loadSlackMessagePipeline = createLazyRuntimeModule(() => import("./pipeline.runtime-
|
|
5990
|
+
const loadSlackMessagePipeline = createLazyRuntimeModule(() => import("./pipeline.runtime-CIepKmZt.mjs"));
|
|
6096
5991
|
const RETRYABLE_FLUSH_MAX_ATTEMPTS = 3;
|
|
6097
5992
|
const RETRYABLE_FLUSH_RETRY_DELAY_MS = 1e3;
|
|
6098
5993
|
const REPLY_SESSION_INIT_CONFLICT_MESSAGE_RE = /reply session initialization conflicted for \S+/u;
|
|
@@ -6207,6 +6102,7 @@ function createSlackMessageHandler(params) {
|
|
|
6207
6102
|
...last.message,
|
|
6208
6103
|
text: combinedText
|
|
6209
6104
|
};
|
|
6105
|
+
const sourceMessageIds = surviving.flatMap((entry) => entry.message.ts ? [entry.message.ts] : []);
|
|
6210
6106
|
const { dispatchCompletion: _completion, awaitDispatch: _awaitDispatch, turnAdoptionLifecycle, ...lastOpts } = last.opts;
|
|
6211
6107
|
let visibleDrop = false;
|
|
6212
6108
|
let settlementHandedOff = false;
|
|
@@ -6225,7 +6121,7 @@ function createSlackMessageHandler(params) {
|
|
|
6225
6121
|
...lastOpts,
|
|
6226
6122
|
senderAuthentication: surviving.every((entry) => entry.opts.senderAuthentication === "verified") ? "verified" : "asserted",
|
|
6227
6123
|
wasMentioned: combinedMentioned || last.opts.wasMentioned,
|
|
6228
|
-
sourceMessageIds
|
|
6124
|
+
sourceMessageIds,
|
|
6229
6125
|
abortSignal: admissionLifecycle.abortSignal,
|
|
6230
6126
|
isRuntimePolicyCurrent: runtimeContext.isRuntimePolicyCurrent,
|
|
6231
6127
|
onVisibleDrop: () => {
|
|
@@ -6271,13 +6167,10 @@ function createSlackMessageHandler(params) {
|
|
|
6271
6167
|
}
|
|
6272
6168
|
};
|
|
6273
6169
|
onPrepared?.(prepared);
|
|
6274
|
-
if (surviving.length > 1) {
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
prepared.ctxPayload.MessageSidFirst = ids[0];
|
|
6279
|
-
prepared.ctxPayload.MessageSidLast = ids[ids.length - 1];
|
|
6280
|
-
}
|
|
6170
|
+
if (surviving.length > 1 && sourceMessageIds.length > 0) {
|
|
6171
|
+
prepared.ctxPayload.MessageSids = sourceMessageIds;
|
|
6172
|
+
prepared.ctxPayload.MessageSidFirst = sourceMessageIds[0];
|
|
6173
|
+
prepared.ctxPayload.MessageSidLast = sourceMessageIds.at(-1);
|
|
6281
6174
|
}
|
|
6282
6175
|
await dispatchPreparedSlackMessage(prepared);
|
|
6283
6176
|
if (!turnAdoptionLifecycle && !settlementHandedOff) await commitClaims();
|
|
@@ -6445,14 +6338,13 @@ function createSlackPresenceMonitor(params) {
|
|
|
6445
6338
|
if (!params.client && !params.resolveClient) throw new Error("Slack presence monitor requires a client or client resolver");
|
|
6446
6339
|
const targets = /* @__PURE__ */ new Map();
|
|
6447
6340
|
const presenceByUser = /* @__PURE__ */ new Map();
|
|
6448
|
-
const nowMs = params.
|
|
6341
|
+
const nowMs = params.scheduler.now;
|
|
6449
6342
|
const enqueue = params.enqueue ?? enqueueRoutedSystemEvent;
|
|
6450
6343
|
const wake = params.wake ?? requestHeartbeat;
|
|
6451
6344
|
let pollOffset = 0;
|
|
6452
|
-
|
|
6453
|
-
let
|
|
6345
|
+
const scheduler = params.scheduler.scope();
|
|
6346
|
+
let started = false;
|
|
6454
6347
|
const rateLimitedUntilByWorkspace = /* @__PURE__ */ new Map();
|
|
6455
|
-
let stopped = false;
|
|
6456
6348
|
const pruneTargets = (now) => {
|
|
6457
6349
|
for (const [key, target] of targets) if (!target.isPolicyCurrent() || now - target.lastActivityAtMs >= SLACK_PRESENCE_TARGET_TTL_MS) targets.delete(key);
|
|
6458
6350
|
pruneMapToMaxSize(targets, SLACK_PRESENCE_MAX_TARGETS);
|
|
@@ -6501,7 +6393,7 @@ function createSlackPresenceMonitor(params) {
|
|
|
6501
6393
|
}
|
|
6502
6394
|
if (!reserved) return;
|
|
6503
6395
|
pruneTargets(nowMs());
|
|
6504
|
-
const target =
|
|
6396
|
+
const target = scheduler.signal.aborted ? void 0 : resolveTarget();
|
|
6505
6397
|
if (!target) {
|
|
6506
6398
|
await params.cooldownStore.deleteIfEqual?.(cooldownKey, now);
|
|
6507
6399
|
return;
|
|
@@ -6550,7 +6442,7 @@ function createSlackPresenceMonitor(params) {
|
|
|
6550
6442
|
const count = Math.min(candidates.length, SLACK_PRESENCE_MAX_POLLS_PER_INTERVAL);
|
|
6551
6443
|
const selected = Array.from({ length: count }, (_, index) => candidates[(pollOffset + index) % candidates.length]).filter((subject) => Boolean(subject));
|
|
6552
6444
|
for (const subject of selected) {
|
|
6553
|
-
if (
|
|
6445
|
+
if (scheduler.signal.aborted) return;
|
|
6554
6446
|
const { teamId, userId } = subject;
|
|
6555
6447
|
const workspaceKey = teamId ?? "workspace";
|
|
6556
6448
|
const rateLimitedUntilMs = rateLimitedUntilByWorkspace.get(workspaceKey) ?? 0;
|
|
@@ -6561,7 +6453,7 @@ function createSlackPresenceMonitor(params) {
|
|
|
6561
6453
|
const client = resolveClient(teamId);
|
|
6562
6454
|
if (!client) throw new Error("Slack presence client is unavailable");
|
|
6563
6455
|
const response = await withTimeout(client.getPresence({ user: userId }), SLACK_PRESENCE_REQUEST_TIMEOUT_MS, { message: `Slack presence request timed out after ${SLACK_PRESENCE_REQUEST_TIMEOUT_MS}ms` });
|
|
6564
|
-
if (
|
|
6456
|
+
if (scheduler.signal.aborted) return;
|
|
6565
6457
|
consumed = true;
|
|
6566
6458
|
const next = response.presence === "active" || response.presence === "away" ? response.presence : void 0;
|
|
6567
6459
|
if (!next) continue;
|
|
@@ -6578,7 +6470,7 @@ function createSlackPresenceMonitor(params) {
|
|
|
6578
6470
|
observedActiveAtMs: observedAtMs
|
|
6579
6471
|
});
|
|
6580
6472
|
} catch (err) {
|
|
6581
|
-
if (
|
|
6473
|
+
if (scheduler.signal.aborted) return;
|
|
6582
6474
|
if (err instanceof WebAPIRateLimitedError) {
|
|
6583
6475
|
rateLimitedUntilByWorkspace.set(workspaceKey, Math.max(rateLimitedUntilMs, nowMs() + Math.max(0, err.retryAfter) * 1e3));
|
|
6584
6476
|
params.error?.(`slack presence polling rate limited; retrying after ${err.retryAfter}s`);
|
|
@@ -6591,33 +6483,20 @@ function createSlackPresenceMonitor(params) {
|
|
|
6591
6483
|
}
|
|
6592
6484
|
}
|
|
6593
6485
|
};
|
|
6594
|
-
const pollOnce = () => {
|
|
6595
|
-
if (stopped) return Promise.resolve();
|
|
6596
|
-
if (activePoll) return activePoll;
|
|
6597
|
-
const run = performPoll().finally(() => {
|
|
6598
|
-
if (activePoll === run) activePoll = void 0;
|
|
6599
|
-
});
|
|
6600
|
-
activePoll = run;
|
|
6601
|
-
return run;
|
|
6602
|
-
};
|
|
6603
6486
|
return {
|
|
6604
6487
|
observe,
|
|
6605
|
-
pollOnce,
|
|
6606
6488
|
start: () => {
|
|
6607
|
-
if (
|
|
6608
|
-
|
|
6489
|
+
if (started || scheduler.signal.aborted) return;
|
|
6490
|
+
started = true;
|
|
6609
6491
|
params.log?.(`slack presence polling enabled for account ${params.accountId}`);
|
|
6610
|
-
|
|
6611
|
-
|
|
6492
|
+
scheduler.schedule({
|
|
6493
|
+
id: "presence",
|
|
6494
|
+
delayMs: SLACK_PRESENCE_POLL_INTERVAL_MS,
|
|
6495
|
+
everyMs: SLACK_PRESENCE_POLL_INTERVAL_MS,
|
|
6496
|
+
run: performPoll
|
|
6497
|
+
});
|
|
6612
6498
|
},
|
|
6613
|
-
stop:
|
|
6614
|
-
stopped = true;
|
|
6615
|
-
if (timer) {
|
|
6616
|
-
clearInterval(timer);
|
|
6617
|
-
timer = void 0;
|
|
6618
|
-
}
|
|
6619
|
-
await activePoll;
|
|
6620
|
-
}
|
|
6499
|
+
stop: () => scheduler.stop()
|
|
6621
6500
|
};
|
|
6622
6501
|
}
|
|
6623
6502
|
function presenceSubjectKey(subject) {
|
|
@@ -6653,7 +6532,7 @@ async function getSlackBoltInterop() {
|
|
|
6653
6532
|
}
|
|
6654
6533
|
return slackBoltInterop;
|
|
6655
6534
|
}
|
|
6656
|
-
const loadSlackRelaySource = createLazyRuntimeModule(() => import("./relay-source-
|
|
6535
|
+
const loadSlackRelaySource = createLazyRuntimeModule(() => import("./relay-source-CC3h6M7y.mjs"));
|
|
6657
6536
|
function resolveSlackRuntimeIdentity(params) {
|
|
6658
6537
|
const botUserId = normalizeOptionalString(params.botUserId);
|
|
6659
6538
|
const botId = normalizeOptionalString(params.botId);
|
|
@@ -6710,7 +6589,8 @@ function resolveSlackRelayConfig(params) {
|
|
|
6710
6589
|
gatewayId
|
|
6711
6590
|
};
|
|
6712
6591
|
}
|
|
6713
|
-
async function monitorSlackProvider(opts
|
|
6592
|
+
async function monitorSlackProvider(opts) {
|
|
6593
|
+
const { scheduler } = opts;
|
|
6714
6594
|
const cfg = opts.config ?? getRuntimeConfig();
|
|
6715
6595
|
const runtime = opts.runtime ?? createNonExitingRuntime();
|
|
6716
6596
|
const account = resolveSlackAccount({
|
|
@@ -6907,13 +6787,7 @@ async function monitorSlackProvider(opts = {}) {
|
|
|
6907
6787
|
});
|
|
6908
6788
|
let presenceRequestAbort;
|
|
6909
6789
|
let presenceMonitor;
|
|
6910
|
-
let presenceMonitorStarted = false;
|
|
6911
6790
|
let runtimeStarted = false;
|
|
6912
|
-
const startPresenceMonitor = () => {
|
|
6913
|
-
if (!presenceMonitor || presenceMonitorStarted) return;
|
|
6914
|
-
presenceMonitor.start();
|
|
6915
|
-
presenceMonitorStarted = true;
|
|
6916
|
-
};
|
|
6917
6791
|
const installSlackPresenceRuntime = (identity) => {
|
|
6918
6792
|
if (!presenceEventsEnabled || presenceMonitor || identity.kind === "degraded" || opts.abortSignal?.aborted) return;
|
|
6919
6793
|
presenceRequestAbort = new AbortController();
|
|
@@ -6929,6 +6803,7 @@ async function monitorSlackProvider(opts = {}) {
|
|
|
6929
6803
|
installationIdentity: identity
|
|
6930
6804
|
});
|
|
6931
6805
|
presenceMonitor = createSlackPresenceMonitor({
|
|
6806
|
+
scheduler,
|
|
6932
6807
|
accountId: account.accountId,
|
|
6933
6808
|
accountConfig: slackCfg.presenceEvents,
|
|
6934
6809
|
resolveClient: (workspaceTeamId) => resolveClient(workspaceTeamId).users,
|
|
@@ -6936,7 +6811,7 @@ async function monitorSlackProvider(opts = {}) {
|
|
|
6936
6811
|
log: runtime.log,
|
|
6937
6812
|
error: runtime.error
|
|
6938
6813
|
});
|
|
6939
|
-
if (runtimeStarted)
|
|
6814
|
+
if (runtimeStarted) presenceMonitor.start();
|
|
6940
6815
|
};
|
|
6941
6816
|
const handleSlackMessage = createSlackMessageHandler({
|
|
6942
6817
|
ctx,
|
|
@@ -6965,7 +6840,7 @@ async function monitorSlackProvider(opts = {}) {
|
|
|
6965
6840
|
trackEvent
|
|
6966
6841
|
});
|
|
6967
6842
|
ctx.readRuntimeContext();
|
|
6968
|
-
if (runtimeStarted)
|
|
6843
|
+
if (runtimeStarted) presenceMonitor?.start();
|
|
6969
6844
|
})();
|
|
6970
6845
|
return await workspaceRuntimePromise;
|
|
6971
6846
|
};
|
|
@@ -7043,7 +6918,7 @@ async function monitorSlackProvider(opts = {}) {
|
|
|
7043
6918
|
await installSlackRuntimeForIdentity(installationIdentity);
|
|
7044
6919
|
durableIngress.start();
|
|
7045
6920
|
runtimeStarted = true;
|
|
7046
|
-
|
|
6921
|
+
presenceMonitor?.start();
|
|
7047
6922
|
if (slackMode === "http" && slackHttpHandler) {
|
|
7048
6923
|
unregisterHttpHandler = registerSlackHttpHandler({
|
|
7049
6924
|
path: slackWebhookPath,
|