@desplega.ai/agent-swarm 2.7.9 → 2.7.10
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/{acp-adapter-dn4gdsgr.js → acp-adapter-srfhs1s9.js} +5 -5
- package/dist/{actions-g563mbn2.js → actions-b8aqhrsg.js} +19 -18
- package/dist/{amp-adapter-q61w05eb.js → amp-adapter-4c165vgn.js} +1 -1
- package/dist/app-m9khefrh.js +20 -0
- package/dist/{assistant-p477rjwj.js → assistant-rh4v3ntz.js} +21 -20
- package/dist/{boot-args-schema-h4qj462e.js → boot-args-schema-hwkc8bzv.js} +1 -1
- package/dist/{boot-reembed-n1ehfbsw.js → boot-reembed-5y6yw9sj.js} +1 -1
- package/dist/{boot-reembed-qw4mc0pt.js → boot-reembed-fdyk55h4.js} +1 -1
- package/dist/{boot-scrub-sweep-9w9jp4sm.js → boot-scrub-sweep-r5r8kqsn.js} +3 -3
- package/dist/{boot-seeds-qdaf3sdy.js → boot-seeds-8f9zt5cm.js} +5 -5
- package/dist/{claude-adapter-348p5hx9.js → claude-adapter-s5df247c.js} +5 -5
- package/dist/{claude-managed-setup-7787fxtp.js → claude-managed-setup-9gsmwzyx.js} +1 -1
- package/dist/{claude-sdk-session-hbszbt8a.js → claude-sdk-session-dq1j4nz9.js} +5 -5
- package/dist/{cli-btf6fw39.js → cli-0m7rtm11.js} +1 -1
- package/dist/{cli-cseh6f8w.js → cli-16phend6.js} +1 -1
- package/dist/{cli-ms5m5r1y.js → cli-18qt3few.js} +1 -1
- package/dist/{cli-sgs5k6yd.js → cli-2tsfpc70.js} +1 -1
- package/dist/{cli-rwymrnaz.js → cli-36wdfzgn.js} +8 -8
- package/dist/{cli-qzt90yze.js → cli-38yww4e9.js} +8 -8
- package/dist/{cli-2a8py3sx.js → cli-3xddv0rk.js} +4 -4
- package/dist/{cli-p0m0p34z.js → cli-4vwxp550.js} +2 -2
- package/dist/{cli-bc779n4v.js → cli-55bkx8hh.js} +1 -1
- package/dist/{cli-21159vea.js → cli-5wfz00be.js} +2 -2
- package/dist/{cli-9aezs55w.js → cli-5xcb8gxq.js} +4 -4
- package/dist/{cli-12xyjhws.js → cli-6m6b4bep.js} +2 -2
- package/dist/{cli-fayav105.js → cli-7wz05bx3.js} +292 -83
- package/dist/{cli-y8nbefpb.js → cli-8ewkreqd.js} +9 -5
- package/dist/{cli-0whpms1z.js → cli-an1knn2k.js} +4 -4
- package/dist/{cli-qmd3mse0.js → cli-bxz823sz.js} +1 -1
- package/dist/{cli-a0657jmf.js → cli-bzvs88tv.js} +1 -1
- package/dist/{cli-agyaeef4.js → cli-cr14kftt.js} +2 -2
- package/dist/{cli-715t1gx6.js → cli-eb2azq8n.js} +3 -3
- package/dist/{cli-530hkwdy.js → cli-ed6yqpf1.js} +2 -2
- package/dist/{cli-k70e3x9e.js → cli-eqk5p56g.js} +3 -3
- package/dist/{cli-4t0fmf3z.js → cli-g1px1g2e.js} +1 -1
- package/dist/{cli-09kmfkmq.js → cli-h49ejvmc.js} +1 -1
- package/dist/{cli-cvs2r2vq.js → cli-hfkwwy1h.js} +39 -5
- package/dist/{cli-neyag5p6.js → cli-j7d73g1y.js} +371 -116
- package/dist/{cli-p17970qv.js → cli-jg24scat.js} +2 -2
- package/dist/{cli-varqt4d1.js → cli-kx4c8j05.js} +16 -13
- package/dist/{cli-jfx48xrj.js → cli-mp9aa8g5.js} +1 -1
- package/dist/{cli-605nn699.js → cli-mr97t7cc.js} +644 -225
- package/dist/{cli-v3cf1ts9.js → cli-n07eecjs.js} +3 -3
- package/dist/{cli-y5rbvxhc.js → cli-n515ex5z.js} +14 -14
- package/dist/{cli-3tqcamp6.js → cli-n9abj89w.js} +13 -12
- package/dist/{cli-ypff1qwp.js → cli-n9ftpys4.js} +7 -7
- package/dist/{cli-xk879m3k.js → cli-nj3x45rw.js} +27 -27
- package/dist/{cli-9r5gtwjr.js → cli-pyrxt9gw.js} +196 -1
- package/dist/{cli-mnrkgg60.js → cli-q581b386.js} +2 -2
- package/dist/{cli-hwprv9e4.js → cli-rjyghzg4.js} +2 -2
- package/dist/{cli-650zv9q9.js → cli-rt0ag4x1.js} +3 -3
- package/dist/{cli-vxh6acp7.js → cli-td33w98c.js} +2 -2
- package/dist/{cli-tqq0hspb.js → cli-tmft5dz2.js} +1 -1
- package/dist/{cli-q26b9wre.js → cli-tph5wt3y.js} +4 -4
- package/dist/{cli-qkdmz8c8.js → cli-ttbqe3q4.js} +1 -1
- package/dist/{cli-zgv8gxgs.js → cli-v2fwbnsk.js} +6 -6
- package/dist/{cli-b932gexn.js → cli-w3bk0dgv.js} +1 -1
- package/dist/{cli-serm8zrx.js → cli-x9exydey.js} +1 -1
- package/dist/{cli-hae9j8sv.js → cli-xbtq4d6s.js} +3 -3
- package/dist/{cli-587857ys.js → cli-xd5ebp64.js} +3 -3
- package/dist/{cli-ejkvvqbe.js → cli-xncjscpm.js} +10 -10
- package/dist/{cli-gce09r66.js → cli-xvymtmv4.js} +2 -2
- package/dist/{cli-btc9cb4c.js → cli-yz7v0sh4.js} +2 -2
- package/dist/{cli-sya22y84.js → cli-z9cs5m0w.js} +3 -3
- package/dist/{cli-2ccpqyyf.js → cli-zjphdj1a.js} +71 -10
- package/dist/cli.js +15 -15
- package/dist/{codex-adapter-ysq6bzha.js → codex-adapter-yr60sme6.js} +3 -3
- package/dist/{codex-session-runner-qakzfx93.js → codex-session-runner-pch8x584.js} +3 -3
- package/dist/{commands-rs7hkv9r.js → commands-phjfbkv0.js} +3 -3
- package/dist/{controller-r5x9bg6e.js → controller-jkx994pz.js} +2 -2
- package/dist/{controllers-connect-498hrxvk.js → controllers-connect-c4448kwa.js} +20 -19
- package/dist/{cursor-adapter-d46qszer.js → cursor-adapter-ndebqnm8.js} +1 -1
- package/dist/{db-pm96nhdb.js → db-ef32tbfc.js} +4 -2
- package/dist/{db-s13dqhr6.js → db-ez6egt6v.js} +3 -3
- package/dist/{dispatcher-j3h81t7m.js → dispatcher-g3tt9hs9.js} +18 -17
- package/dist/{dsh-adapter-rw0d5rc4.js → dsh-adapter-tcyn3099.js} +1 -1
- package/dist/{easter-egg-3d-qtgfxgze.js → easter-egg-3d-e36hk5td.js} +1 -1
- package/dist/{embedding-space-xh8p4q4x.js → embedding-space-4kyh5qqj.js} +6 -6
- package/dist/{embeddings-wp745m91.js → embeddings-6a8v4a6t.js} +1 -1
- package/dist/{execute-2fzb9z74.js → execute-3cbg0twf.js} +1 -1
- package/dist/{external-channel-ys21h3sy.js → external-channel-se646snz.js} +2 -2
- package/dist/{fx-adapter-vz0b9z3g.js → fx-adapter-yw795hqq.js} +6 -6
- package/dist/{google-generative-ai-ytpgncx9.js → google-generative-ai-h7s3e9kk.js} +1 -1
- package/dist/{google-vertex-tqhze5j7.js → google-vertex-fhxaafzw.js} +1 -1
- package/dist/{grok-adapter-spea7zkj.js → grok-adapter-ttmcss2j.js} +6 -6
- package/dist/handlers-17wha3ze.js +33 -0
- package/dist/{heartbeat-8phn1kdq.js → heartbeat-gwewgdms.js} +21 -20
- package/dist/{hook-amcj4s10.js → hook-g3nhexsy.js} +5 -5
- package/dist/{hook-bc6n49qn.js → hook-hq93y5ej.js} +4 -4
- package/dist/{http-7374brv5.js → http-5a9p4h6y.js} +210 -69
- package/dist/{index-pxn30mse.js → index-0eny15vj.js} +8 -8
- package/dist/{index-5a9jtqde.js → index-0rvk3vd4.js} +46 -46
- package/dist/{index-fvzke5kx.js → index-1qw6f2dc.js} +10 -10
- package/dist/{index-p4hjwbvw.js → index-3c5pxbge.js} +1 -1
- package/dist/{index-q5cmtbz5.js → index-6haqt3v5.js} +12296 -11042
- package/dist/index-8arwq8mw.js +34 -0
- package/dist/{index-h7f61sy9.js → index-e5pfbsys.js} +3 -3
- package/dist/{index-c9y31ytf.js → index-hgn3c961.js} +12 -11
- package/dist/{index-hsad2t3r.js → index-m5gx1xd6.js} +38 -38
- package/dist/{index-5fx3b3kw.js → index-rvccek1w.js} +9 -9
- package/dist/{index-w4m9z29z.js → index-s72rqgsx.js} +1 -1
- package/dist/index-tpw054az.js +38 -0
- package/dist/{index-514d9pf6.js → index-w7em4ktq.js} +8 -8
- package/dist/index-waq75j2j.js +31 -0
- package/dist/{keepalive-wy29kbrg.js → keepalive-1j4n4dmk.js} +3 -3
- package/dist/lead-re73kdgc.js +72 -0
- package/dist/{maintenance-h2ds9w6c.js → maintenance-dmghacy5.js} +1 -1
- package/dist/{oauth-refresh-sweep-q7mtbyp3.js → oauth-refresh-sweep-yy06c03c.js} +2 -2
- package/dist/{onboard-vw8r2fdw.js → onboard-52f9t5dm.js} +3 -3
- package/dist/{opencode-adapter-mtb0953j.js → opencode-adapter-krnh9jkn.js} +4 -4
- package/dist/{otel-impl-j42czw3r.js → otel-impl-xjqz6wjj.js} +1 -1
- package/dist/{pi-mono-adapter-zk8pg9jr.js → pi-mono-adapter-dbxyp0qv.js} +6 -6
- package/dist/{pricing-refresh-x7nhv23d.js → pricing-refresh-ctdr74pd.js} +3 -3
- package/dist/{rbac-roles-bzvee6cf.js → rbac-roles-ehv8s10n.js} +3 -3
- package/dist/{rbac-roles-9044425x.js → rbac-roles-q0gr8eyj.js} +2 -2
- package/dist/{render-v2-t7bn4skz.js → render-v2-5b6chvcq.js} +9 -4
- package/dist/{resume-x94gemep.js → resume-5a5d2845.js} +6 -6
- package/dist/{runtime-breq6fmv.js → runtime-khxszyfp.js} +1 -1
- package/dist/{session-access-q7dmqjvt.js → session-access-gj0bjhqg.js} +4 -4
- package/dist/{session-source-backfill-440ysamr.js → session-source-backfill-2sy0krfk.js} +2 -2
- package/dist/{setup-07n4727s.js → setup-7ssfakk1.js} +1 -1
- package/dist/{virtual-modules-z5h6mcyf.js → virtual-modules-pjj0knwf.js} +3 -3
- package/dist/{work-objects-pnq5y534.js → work-objects-bf3syvhq.js} +22 -21
- package/dist/{worker-follow-up-7z1gfkr8.js → worker-follow-up-38xevga6.js} +18 -17
- package/dist/worker-r8mz7a65.js +72 -0
- package/openapi.json +1 -1
- package/package.json +3 -3
- package/src/apps/catalog.generated.json +55 -0
- package/src/apps/page-validator.ts +19 -0
- package/src/assets/key.ts +77 -4
- package/src/be/db/session-labels.ts +57 -0
- package/src/be/db/session-tree.ts +51 -7
- package/src/be/db/slack-trees.ts +146 -0
- package/src/be/db/tasks/read.ts +102 -7
- package/src/be/db-client.ts +8 -2
- package/src/be/db.ts +95 -84
- package/src/be/event-loop-lag.ts +146 -0
- package/src/be/mcp-overflow-sweep.ts +2 -1
- package/src/be/memory/providers/sqlite-store.ts +39 -8
- package/src/be/migrations/278_slack_render_v2_reconcile.sql +108 -0
- package/src/be/swarm-config-guard.ts +2 -0
- package/src/commands/context-preamble.ts +258 -0
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/extensions/catalog.generated.json +3 -3
- package/src/heartbeat/heartbeat.ts +5 -4
- package/src/http/core.ts +9 -3
- package/src/http/index.ts +10 -6
- package/src/http/memory.ts +9 -4
- package/src/http/sessions.ts +16 -3
- package/src/http/utils.ts +18 -0
- package/src/http/webhooks.ts +48 -0
- package/src/integrations/chat-sdk/commands.ts +167 -31
- package/src/integrations/chat-sdk/inbound.ts +10 -8
- package/src/integrations/chat-sdk/message-text.ts +117 -0
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/cursor-adapter.ts +1 -1
- package/src/providers/dsh-adapter.ts +1 -1
- package/src/scheduler/scheduler.ts +4 -1
- package/src/scripts-runtime/executors/quickjs-runner.ts +2 -0
- package/src/scripts-runtime/executors/quickjs-structured-clone.ts +180 -0
- package/src/scripts-runtime/quickjs-compat.ts +0 -1
- package/src/slack/app.ts +332 -10
- package/src/slack/handlers.ts +9 -2
- package/src/slack/index.ts +7 -1
- package/src/slack/lifecycle-lock.ts +29 -0
- package/src/slack/render-v2.ts +424 -212
- package/src/slack/socket-fence.ts +64 -0
- package/src/slack/watcher.ts +42 -8
- package/src/tests/apps-schema-form.test.ts +151 -0
- package/src/tests/chat-sdk-commands.test.ts +359 -2
- package/src/tests/chat-sdk-inbound.test.ts +20 -0
- package/src/tests/chat-sdk-slack.test.ts +189 -1
- package/src/tests/db-client-busy-retry.test.ts +69 -18
- package/src/tests/db-client.test.ts +26 -1
- package/src/tests/db-task-read-contract.test.ts +2 -0
- package/src/tests/db-task-write-contract.test.ts +1 -0
- package/src/tests/dsh-adapter.test.ts +1 -1
- package/src/tests/event-loop-lag.test.ts +184 -0
- package/src/tests/extensions-example-comms-adherence-gate.test.ts +115 -0
- package/src/tests/github-webhook-early-ack.test.ts +144 -0
- package/src/tests/http-api-integration.test.ts +2 -0
- package/src/tests/http-log-scrubbing.test.ts +68 -2
- package/src/tests/kv-storage.test.ts +92 -1
- package/src/tests/memory-key-paths.test.ts +57 -0
- package/src/tests/memory-retrieval-purge.test.ts +19 -0
- package/src/tests/quickjs-compat.test.ts +1 -1
- package/src/tests/runner-context-preamble.test.ts +552 -0
- package/src/tests/script-connections.test.ts +3 -0
- package/src/tests/script-executor-conformance.test.ts +188 -0
- package/src/tests/sessions-tree.test.ts +133 -2
- package/src/tests/slack-app-icon.test.ts +4 -0
- package/src/tests/slack-dm-implicit-mention.test.ts +236 -0
- package/src/tests/slack-file-tools-attachments.test.ts +1 -0
- package/src/tests/slack-read-boundaries.test.ts +4 -3
- package/src/tests/slack-render-v2-query-plans.test.ts +262 -3
- package/src/tests/slack-render-v2-reconcile.test.ts +201 -0
- package/src/tests/slack-socket-watchdog.test.ts +748 -0
- package/src/tests/vcs-identity-inheritance.test.ts +85 -0
- package/src/tools/utils.ts +16 -7
- package/templates/extensions/comms-adherence-gate/README.md +25 -0
- package/templates/extensions/comms-adherence-gate/hooks.ts +100 -11
- package/templates/extensions/comms-adherence-gate/manifest.json +1 -1
- package/templates/skills/apps/SKILL.md +7 -0
- package/templates/skills/apps/content.md +7 -0
- package/dist/app-a66ssc4k.js +0 -17
- package/dist/handlers-crckt5dq.js +0 -32
- package/dist/index-4x08sjtk.js +0 -30
- package/dist/index-8ybffts4.js +0 -37
- package/dist/index-nfy4kkg5.js +0 -33
- package/dist/lead-zdqxsvjn.js +0 -71
- package/dist/worker-y62rvvq3.js +0 -71
- package/dist/{cli-gxy8y1dt.js → cli-8bpgbr8k.js} +3 -3
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
decryptSecret,
|
|
6
6
|
getEncryptionKey,
|
|
7
7
|
init_crypto,
|
|
8
|
+
bindLoopPath,
|
|
9
|
+
init_event_loop_lag,
|
|
8
10
|
getDbClient2,
|
|
9
11
|
SLACK_REACTION_DEFAULTS,
|
|
10
12
|
SLACK_REACTION_CONFIG_KEYS,
|
|
@@ -20,6 +22,10 @@ import {
|
|
|
20
22
|
markFinalizedSlackRelaysDelivered2,
|
|
21
23
|
getInProgressSlackTasks2,
|
|
22
24
|
getSlackTasksMissingTree2,
|
|
25
|
+
closeSlackTreeIfSettled,
|
|
26
|
+
getSlackThreadsOfTasks,
|
|
27
|
+
slackThreadHasOutcomeWork,
|
|
28
|
+
init_slack_trees,
|
|
23
29
|
ensureSlackRenderV2Activation2,
|
|
24
30
|
ensureSlackDelegationActivation2,
|
|
25
31
|
isPendingSlackMessage2,
|
|
@@ -50,11 +56,15 @@ import {
|
|
|
50
56
|
checkDependencies2,
|
|
51
57
|
emitBuiltInIntegrationConnectedOnce2,
|
|
52
58
|
init_db4
|
|
53
|
-
} from "./cli-
|
|
59
|
+
} from "./cli-j7d73g1y.js";
|
|
54
60
|
import {
|
|
55
61
|
getChannelBlockReason2,
|
|
56
62
|
init_external_channel
|
|
57
|
-
} from "./cli-
|
|
63
|
+
} from "./cli-bxz823sz.js";
|
|
64
|
+
import {
|
|
65
|
+
workflowEventBus2,
|
|
66
|
+
init_event_bus
|
|
67
|
+
} from "./cli-eddnyg3t.js";
|
|
58
68
|
import {
|
|
59
69
|
require_jsonwebtoken,
|
|
60
70
|
require_dist6,
|
|
@@ -80,11 +90,11 @@ import {
|
|
|
80
90
|
import {
|
|
81
91
|
isTerminalTaskStatus,
|
|
82
92
|
init_types4
|
|
83
|
-
} from "./cli-
|
|
93
|
+
} from "./cli-hfkwwy1h.js";
|
|
84
94
|
import {
|
|
85
95
|
taskAttachmentDisplayUrl,
|
|
86
96
|
init_task_attachment_links
|
|
87
|
-
} from "./cli-
|
|
97
|
+
} from "./cli-pyrxt9gw.js";
|
|
88
98
|
import {
|
|
89
99
|
getSlackConfiguration,
|
|
90
100
|
init_config4
|
|
@@ -11734,6 +11744,30 @@ var init_inbound_dispatch = __esm(() => {
|
|
|
11734
11744
|
};
|
|
11735
11745
|
});
|
|
11736
11746
|
|
|
11747
|
+
// src/slack/lifecycle-lock.ts
|
|
11748
|
+
async function runSlackLifecycleExclusive(fn) {
|
|
11749
|
+
holders += 1;
|
|
11750
|
+
const previous = tail;
|
|
11751
|
+
let release;
|
|
11752
|
+
tail = new Promise((resolve) => {
|
|
11753
|
+
release = resolve;
|
|
11754
|
+
});
|
|
11755
|
+
try {
|
|
11756
|
+
await previous;
|
|
11757
|
+
return await fn();
|
|
11758
|
+
} finally {
|
|
11759
|
+
holders -= 1;
|
|
11760
|
+
release();
|
|
11761
|
+
}
|
|
11762
|
+
}
|
|
11763
|
+
function isSlackLifecycleBusy() {
|
|
11764
|
+
return holders > 0;
|
|
11765
|
+
}
|
|
11766
|
+
var tail, holders = 0;
|
|
11767
|
+
var init_lifecycle_lock = __esm(() => {
|
|
11768
|
+
tail = Promise.resolve();
|
|
11769
|
+
});
|
|
11770
|
+
|
|
11737
11771
|
// src/slack/socket-ack.ts
|
|
11738
11772
|
function isSocketNotReadyError(error) {
|
|
11739
11773
|
return error instanceof Error && error.message === NOT_READY_MESSAGE;
|
|
@@ -11848,6 +11882,53 @@ var init_socket_ack = __esm(() => {
|
|
|
11848
11882
|
ORDER_DEPENDENT_EVENTS = new Set(["assistant_thread_context_changed"]);
|
|
11849
11883
|
});
|
|
11850
11884
|
|
|
11885
|
+
// src/slack/socket-fence.ts
|
|
11886
|
+
function fenceSocketModeClient(client) {
|
|
11887
|
+
let retired = false;
|
|
11888
|
+
const retrieveWSSURL = Reflect.get(client, "retrieveWSSURL");
|
|
11889
|
+
if (typeof retrieveWSSURL !== "function") {
|
|
11890
|
+
throw new Error("@slack/socket-mode changed: SocketModeClient.retrieveWSSURL is missing");
|
|
11891
|
+
}
|
|
11892
|
+
const start = client.start;
|
|
11893
|
+
Reflect.set(client, "retrieveWSSURL", async function() {
|
|
11894
|
+
if (retired)
|
|
11895
|
+
throw new SlackSocketClientRetiredError;
|
|
11896
|
+
let url;
|
|
11897
|
+
try {
|
|
11898
|
+
url = await retrieveWSSURL.call(this);
|
|
11899
|
+
} catch (error) {
|
|
11900
|
+
if (retired)
|
|
11901
|
+
throw new SlackSocketClientRetiredError;
|
|
11902
|
+
throw error;
|
|
11903
|
+
}
|
|
11904
|
+
if (retired)
|
|
11905
|
+
throw new SlackSocketClientRetiredError;
|
|
11906
|
+
return url;
|
|
11907
|
+
});
|
|
11908
|
+
Reflect.set(client, "start", function() {
|
|
11909
|
+
return start.call(this).catch((error) => {
|
|
11910
|
+
if (error instanceof SlackSocketClientRetiredError)
|
|
11911
|
+
return;
|
|
11912
|
+
throw error;
|
|
11913
|
+
});
|
|
11914
|
+
});
|
|
11915
|
+
return {
|
|
11916
|
+
retire: () => {
|
|
11917
|
+
retired = true;
|
|
11918
|
+
},
|
|
11919
|
+
isRetired: () => retired
|
|
11920
|
+
};
|
|
11921
|
+
}
|
|
11922
|
+
var SlackSocketClientRetiredError;
|
|
11923
|
+
var init_socket_fence = __esm(() => {
|
|
11924
|
+
SlackSocketClientRetiredError = class SlackSocketClientRetiredError extends Error {
|
|
11925
|
+
constructor() {
|
|
11926
|
+
super("Slack socket-mode client was retired; it opens no new socket");
|
|
11927
|
+
this.name = "SlackSocketClientRetiredError";
|
|
11928
|
+
}
|
|
11929
|
+
};
|
|
11930
|
+
});
|
|
11931
|
+
|
|
11851
11932
|
// src/slack/socket-mode-guard.ts
|
|
11852
11933
|
function getSlackSocketModeBlockReason(env) {
|
|
11853
11934
|
if (env.NODE_ENV !== "development")
|
|
@@ -11886,7 +11967,7 @@ async function initOtel(serviceRole = process.env.AGENT_ROLE || "api") {
|
|
|
11886
11967
|
return;
|
|
11887
11968
|
initialized = true;
|
|
11888
11969
|
try {
|
|
11889
|
-
const impl = await import("./otel-impl-
|
|
11970
|
+
const impl = await import("./otel-impl-xjqz6wjj.js");
|
|
11890
11971
|
await impl.boot(serviceRole, {
|
|
11891
11972
|
exportConsoleLogs: serviceRole === "api" && isApiLogExportEnabled()
|
|
11892
11973
|
});
|
|
@@ -14866,6 +14947,7 @@ async function refreshResolvedDeferralCards() {
|
|
|
14866
14947
|
} else {
|
|
14867
14948
|
await markSlackDeferralResolved2(card.id);
|
|
14868
14949
|
}
|
|
14950
|
+
markSlackThreadDirty(card.channelId, card.threadTs);
|
|
14869
14951
|
deferralRefreshAttempts.delete(card.id);
|
|
14870
14952
|
if (!isDeferredTask(wake))
|
|
14871
14953
|
await finalizeTerminalSlackReactions([wake]);
|
|
@@ -14883,240 +14965,373 @@ async function refreshResolvedDeferralCards() {
|
|
|
14883
14965
|
}
|
|
14884
14966
|
}
|
|
14885
14967
|
}
|
|
14886
|
-
async function
|
|
14968
|
+
async function renderStoredTree(storedTree, { activatedAt, delegationEnabled, delegationActivatedAt, statusTick }) {
|
|
14887
14969
|
if (!isSlackRenderV2Enabled2())
|
|
14888
|
-
return;
|
|
14889
|
-
|
|
14890
|
-
const
|
|
14891
|
-
|
|
14892
|
-
const statusTick = beginSlackStatusTick();
|
|
14893
|
-
for (const task of await getSlackTasksMissingTree2()) {
|
|
14894
|
-
if (!isSlackRenderV2Enabled2())
|
|
14895
|
-
return;
|
|
14896
|
-
if (!task.slackChannelId || !task.slackThreadTs)
|
|
14897
|
-
continue;
|
|
14970
|
+
return "stop";
|
|
14971
|
+
let tree = storedTree;
|
|
14972
|
+
const initialTasks = await getSlackTasksInThread2(tree.channelId, tree.threadTs);
|
|
14973
|
+
if (isPendingSlackMessage2(tree)) {
|
|
14898
14974
|
try {
|
|
14899
|
-
await ensureSlackThreadTree2(
|
|
14975
|
+
const recovered = await ensureSlackThreadTree2(initialTasks.map((task) => task.id), statusTick.budget);
|
|
14976
|
+
if (!recovered)
|
|
14977
|
+
return "skipped";
|
|
14978
|
+
tree = recovered;
|
|
14900
14979
|
} catch (error) {
|
|
14901
|
-
console.error(`[Slack] Failed to
|
|
14980
|
+
console.error(`[Slack] Failed to recover pending v2 tree ${tree.id}:`, error);
|
|
14981
|
+
return "skipped";
|
|
14902
14982
|
}
|
|
14903
14983
|
}
|
|
14904
|
-
|
|
14905
|
-
|
|
14906
|
-
|
|
14907
|
-
|
|
14908
|
-
|
|
14909
|
-
|
|
14910
|
-
try {
|
|
14911
|
-
const recovered = await ensureSlackThreadTree2(initialTasks.map((task) => task.id), statusTick.budget);
|
|
14912
|
-
if (!recovered)
|
|
14913
|
-
continue;
|
|
14914
|
-
tree = recovered;
|
|
14915
|
-
} catch (error) {
|
|
14916
|
-
console.error(`[Slack] Failed to recover pending v2 tree ${tree.id}:`, error);
|
|
14917
|
-
continue;
|
|
14918
|
-
}
|
|
14919
|
-
}
|
|
14920
|
-
const app = getSlackApp2();
|
|
14921
|
-
if (app && !tree.permalink) {
|
|
14922
|
-
try {
|
|
14923
|
-
tree = await ensureTreePermalink(app.client, tree);
|
|
14924
|
-
} catch (error) {
|
|
14925
|
-
if (isSlackMessageNotFound(error)) {
|
|
14926
|
-
try {
|
|
14927
|
-
await replaceMissingTree(tree, statusTick.budget);
|
|
14928
|
-
} catch (replacementError) {
|
|
14929
|
-
console.error(`[Slack] Failed to replace missing v2 tree ${tree.id}:`, replacementError);
|
|
14930
|
-
}
|
|
14931
|
-
continue;
|
|
14932
|
-
}
|
|
14933
|
-
console.error(`[Slack] Failed to resolve v2 tree permalink ${tree.id}:`, error);
|
|
14934
|
-
continue;
|
|
14935
|
-
}
|
|
14936
|
-
}
|
|
14937
|
-
let tasks = await getSlackTasksInThread2(tree.channelId, tree.threadTs);
|
|
14938
|
-
let needsOutcome = false;
|
|
14939
|
-
for (const task of tasks) {
|
|
14940
|
-
const card = await getSlackOutcomeMessage2(task.id);
|
|
14941
|
-
if (card && isSettledSlackMessage2(card))
|
|
14942
|
-
continue;
|
|
14943
|
-
const isDirectCandidate = await taskNeedsDirectOutcome(task, activatedAt) && isOutcomeStatus(task.status) && !await isAnsweredByDeferralCard(task, tasks);
|
|
14944
|
-
const isChildCandidate = delegationEnabled && delegationActivatedAt !== null && isChildCardCandidate(task, delegationActivatedAt) && !task.slackReplySent;
|
|
14945
|
-
if (isDirectCandidate || isChildCandidate) {
|
|
14946
|
-
needsOutcome = true;
|
|
14947
|
-
break;
|
|
14948
|
-
}
|
|
14949
|
-
}
|
|
14950
|
-
if (needsOutcome && app) {
|
|
14951
|
-
try {
|
|
14952
|
-
await resolvePermalink(app.client, tree.channelId, tree.ts);
|
|
14953
|
-
} catch (error) {
|
|
14954
|
-
if (!isSlackMessageNotFound(error)) {
|
|
14955
|
-
console.error(`[Slack] Failed to verify v2 tree ${tree.id}:`, error);
|
|
14956
|
-
continue;
|
|
14957
|
-
}
|
|
14984
|
+
const app = getSlackApp2();
|
|
14985
|
+
if (app && !tree.permalink) {
|
|
14986
|
+
try {
|
|
14987
|
+
tree = await ensureTreePermalink(app.client, tree);
|
|
14988
|
+
} catch (error) {
|
|
14989
|
+
if (isSlackMessageNotFound(error)) {
|
|
14958
14990
|
try {
|
|
14959
|
-
|
|
14960
|
-
if (!replacement)
|
|
14961
|
-
continue;
|
|
14962
|
-
tree = replacement;
|
|
14963
|
-
tasks = await getSlackTasksInThread2(tree.channelId, tree.threadTs);
|
|
14991
|
+
await replaceMissingTree(tree, statusTick.budget);
|
|
14964
14992
|
} catch (replacementError) {
|
|
14965
14993
|
console.error(`[Slack] Failed to replace missing v2 tree ${tree.id}:`, replacementError);
|
|
14966
|
-
continue;
|
|
14967
14994
|
}
|
|
14995
|
+
return "skipped";
|
|
14968
14996
|
}
|
|
14997
|
+
console.error(`[Slack] Failed to resolve v2 tree permalink ${tree.id}:`, error);
|
|
14998
|
+
return "skipped";
|
|
14969
14999
|
}
|
|
14970
|
-
|
|
14971
|
-
|
|
14972
|
-
|
|
14973
|
-
|
|
14974
|
-
|
|
14975
|
-
|
|
14976
|
-
|
|
14977
|
-
|
|
14978
|
-
|
|
14979
|
-
|
|
14980
|
-
|
|
14981
|
-
|
|
15000
|
+
}
|
|
15001
|
+
let tasks = await getSlackTasksInThread2(tree.channelId, tree.threadTs);
|
|
15002
|
+
let needsOutcome = false;
|
|
15003
|
+
for (const task of tasks) {
|
|
15004
|
+
const card = await getSlackOutcomeMessage2(task.id);
|
|
15005
|
+
if (card && isSettledSlackMessage2(card))
|
|
15006
|
+
continue;
|
|
15007
|
+
const isDirectCandidate = await taskNeedsDirectOutcome(task, activatedAt) && isOutcomeStatus(task.status) && !await isAnsweredByDeferralCard(task, tasks);
|
|
15008
|
+
const isChildCandidate = delegationEnabled && delegationActivatedAt !== null && isChildCardCandidate(task, delegationActivatedAt) && !task.slackReplySent;
|
|
15009
|
+
if (isDirectCandidate || isChildCandidate) {
|
|
15010
|
+
needsOutcome = true;
|
|
15011
|
+
break;
|
|
15012
|
+
}
|
|
15013
|
+
}
|
|
15014
|
+
if (needsOutcome && app) {
|
|
15015
|
+
try {
|
|
15016
|
+
await resolvePermalink(app.client, tree.channelId, tree.ts);
|
|
15017
|
+
} catch (error) {
|
|
15018
|
+
if (!isSlackMessageNotFound(error)) {
|
|
15019
|
+
console.error(`[Slack] Failed to verify v2 tree ${tree.id}:`, error);
|
|
15020
|
+
return "skipped";
|
|
15021
|
+
}
|
|
15022
|
+
try {
|
|
15023
|
+
const replacement = await replaceMissingTree(tree, statusTick.budget);
|
|
15024
|
+
if (!replacement)
|
|
15025
|
+
return "skipped";
|
|
15026
|
+
tree = replacement;
|
|
15027
|
+
tasks = await getSlackTasksInThread2(tree.channelId, tree.threadTs);
|
|
15028
|
+
} catch (replacementError) {
|
|
15029
|
+
console.error(`[Slack] Failed to replace missing v2 tree ${tree.id}:`, replacementError);
|
|
15030
|
+
return "skipped";
|
|
14982
15031
|
}
|
|
14983
15032
|
}
|
|
14984
|
-
|
|
14985
|
-
|
|
14986
|
-
|
|
14987
|
-
|
|
14988
|
-
|
|
14989
|
-
|
|
14990
|
-
|
|
15033
|
+
}
|
|
15034
|
+
const settleSec = Number(process.env.SLACK_CONCLUSION_SETTLE_SEC) || 10;
|
|
15035
|
+
const timeoutMin = Number(process.env.SLACK_CONCLUSION_TIMEOUT_MIN) || 240;
|
|
15036
|
+
const closuresByAskId = new Map;
|
|
15037
|
+
const ownerAskId = new Map;
|
|
15038
|
+
if (delegationEnabled) {
|
|
15039
|
+
for (const ask of tasks.filter((candidate) => candidate.source === "slack")) {
|
|
15040
|
+
const closure = buildAskClosure(ask, tasks);
|
|
15041
|
+
closuresByAskId.set(ask.id, closure);
|
|
14991
15042
|
for (const member of closure) {
|
|
14992
|
-
if (
|
|
14993
|
-
|
|
15043
|
+
if (!ownerAskId.has(member.id))
|
|
15044
|
+
ownerAskId.set(member.id, ask.id);
|
|
14994
15045
|
}
|
|
14995
|
-
childCardCounts.set(askId, count);
|
|
14996
|
-
return count;
|
|
14997
15046
|
}
|
|
14998
|
-
|
|
14999
|
-
|
|
15000
|
-
|
|
15001
|
-
|
|
15002
|
-
|
|
15003
|
-
|
|
15004
|
-
|
|
15005
|
-
|
|
15006
|
-
|
|
15007
|
-
|
|
15008
|
-
|
|
15009
|
-
|
|
15010
|
-
|
|
15011
|
-
|
|
15012
|
-
|
|
15013
|
-
|
|
15014
|
-
|
|
15015
|
-
|
|
15016
|
-
|
|
15017
|
-
|
|
15018
|
-
|
|
15019
|
-
|
|
15047
|
+
}
|
|
15048
|
+
const childCardCounts = new Map;
|
|
15049
|
+
async function childCardCountFor(askId) {
|
|
15050
|
+
const cached = childCardCounts.get(askId);
|
|
15051
|
+
if (cached !== undefined)
|
|
15052
|
+
return cached;
|
|
15053
|
+
const closure = closuresByAskId.get(askId) ?? [];
|
|
15054
|
+
let count = 0;
|
|
15055
|
+
for (const member of closure) {
|
|
15056
|
+
if (await getSlackOutcomeMessage2(member.id))
|
|
15057
|
+
count++;
|
|
15058
|
+
}
|
|
15059
|
+
childCardCounts.set(askId, count);
|
|
15060
|
+
return count;
|
|
15061
|
+
}
|
|
15062
|
+
let outcomeCreated = false;
|
|
15063
|
+
let childCardsThisTick = 0;
|
|
15064
|
+
for (const task of tasks) {
|
|
15065
|
+
if (!isSlackRenderV2Enabled2())
|
|
15066
|
+
return "stop";
|
|
15067
|
+
if (task.source === "slack")
|
|
15068
|
+
continue;
|
|
15069
|
+
const card = await getSlackOutcomeMessage2(task.id);
|
|
15070
|
+
if (card && isSettledSlackMessage2(card))
|
|
15071
|
+
continue;
|
|
15072
|
+
if (!delegationEnabled || delegationActivatedAt === null)
|
|
15073
|
+
continue;
|
|
15074
|
+
if (!isChildCardCandidate(task, delegationActivatedAt) || task.slackReplySent)
|
|
15075
|
+
continue;
|
|
15076
|
+
const askId = ownerAskId.get(task.id);
|
|
15077
|
+
const ownerAsk = askId ? tasks.find((candidate) => candidate.id === askId) : undefined;
|
|
15078
|
+
if (!ownerAsk || ownerAsk.createdAt < delegationActivatedAt)
|
|
15079
|
+
continue;
|
|
15080
|
+
if (childCardsThisTick >= CHILD_CARDS_PER_TICK)
|
|
15081
|
+
continue;
|
|
15082
|
+
if (askId && await childCardCountFor(askId) >= CHILD_CARDS_PER_ASK)
|
|
15083
|
+
continue;
|
|
15084
|
+
if (!await checkOutcomeDeliveryGate(task, card, statusTick.budget))
|
|
15085
|
+
continue;
|
|
15086
|
+
try {
|
|
15087
|
+
const outcome = await streamOutcomeCard(task, tree, {
|
|
15088
|
+
buildContent: childOutcomeContent,
|
|
15089
|
+
statusBudget: statusTick.budget
|
|
15090
|
+
});
|
|
15091
|
+
if (outcome) {
|
|
15092
|
+
noteOutcomeDeliverySuccess(task.id);
|
|
15093
|
+
childCardsThisTick++;
|
|
15094
|
+
if (askId)
|
|
15095
|
+
childCardCounts.set(askId, (childCardCounts.get(askId) ?? 0) + 1);
|
|
15096
|
+
await recordSlackDelivery(task, outcome, "child_outcome");
|
|
15097
|
+
}
|
|
15098
|
+
outcomeCreated ||= !!outcome;
|
|
15099
|
+
} catch (error) {
|
|
15100
|
+
await noteOutcomeDeliveryFailure(task, tree, error, statusTick.budget);
|
|
15101
|
+
}
|
|
15102
|
+
}
|
|
15103
|
+
for (const task of tasks) {
|
|
15104
|
+
if (!isSlackRenderV2Enabled2())
|
|
15105
|
+
return "stop";
|
|
15106
|
+
if (!await taskNeedsDirectOutcome(task, activatedAt))
|
|
15107
|
+
continue;
|
|
15108
|
+
const card = await getSlackOutcomeMessage2(task.id);
|
|
15109
|
+
if (card && isSettledSlackMessage2(card))
|
|
15110
|
+
continue;
|
|
15111
|
+
if (await isAnsweredByDeferralCard(task, tasks))
|
|
15112
|
+
continue;
|
|
15113
|
+
const deferByClosure = task.source === "slack" && delegationEnabled && delegationActivatedAt !== null && task.createdAt >= delegationActivatedAt;
|
|
15114
|
+
if (!deferByClosure) {
|
|
15020
15115
|
if (!await checkOutcomeDeliveryGate(task, card, statusTick.budget))
|
|
15021
15116
|
continue;
|
|
15022
15117
|
try {
|
|
15023
|
-
const outcome = await streamOutcomeCard(task, tree, {
|
|
15024
|
-
buildContent: childOutcomeContent,
|
|
15025
|
-
statusBudget: statusTick.budget
|
|
15026
|
-
});
|
|
15118
|
+
const outcome = await streamOutcomeCard(task, tree, { statusBudget: statusTick.budget });
|
|
15027
15119
|
if (outcome) {
|
|
15028
15120
|
noteOutcomeDeliverySuccess(task.id);
|
|
15029
|
-
|
|
15030
|
-
if (askId)
|
|
15031
|
-
childCardCounts.set(askId, (childCardCounts.get(askId) ?? 0) + 1);
|
|
15032
|
-
await recordSlackDelivery(task, outcome, "child_outcome");
|
|
15121
|
+
await finalizeTerminalSlackReactions([task]);
|
|
15033
15122
|
}
|
|
15034
15123
|
outcomeCreated ||= !!outcome;
|
|
15035
15124
|
} catch (error) {
|
|
15036
15125
|
await noteOutcomeDeliveryFailure(task, tree, error, statusTick.budget);
|
|
15037
15126
|
}
|
|
15127
|
+
continue;
|
|
15038
15128
|
}
|
|
15039
|
-
|
|
15040
|
-
|
|
15041
|
-
|
|
15042
|
-
|
|
15043
|
-
|
|
15044
|
-
const card = await getSlackOutcomeMessage2(task.id);
|
|
15045
|
-
if (card && isSettledSlackMessage2(card))
|
|
15129
|
+
const closure = closuresByAskId.get(task.id) ?? buildAskClosure(task, tasks);
|
|
15130
|
+
let childCardPending = false;
|
|
15131
|
+
const existingChildCards = await childCardCountFor(task.id);
|
|
15132
|
+
for (const member of closure) {
|
|
15133
|
+
if (!isChildCardCandidate(member, delegationActivatedAt) || member.slackReplySent)
|
|
15046
15134
|
continue;
|
|
15047
|
-
if (
|
|
15048
|
-
|
|
15049
|
-
const
|
|
15050
|
-
if (!
|
|
15051
|
-
|
|
15052
|
-
|
|
15053
|
-
try {
|
|
15054
|
-
const outcome = await streamOutcomeCard(task, tree, { statusBudget: statusTick.budget });
|
|
15055
|
-
if (outcome) {
|
|
15056
|
-
noteOutcomeDeliverySuccess(task.id);
|
|
15057
|
-
await finalizeTerminalSlackReactions([task]);
|
|
15058
|
-
}
|
|
15059
|
-
outcomeCreated ||= !!outcome;
|
|
15060
|
-
} catch (error) {
|
|
15061
|
-
await noteOutcomeDeliveryFailure(task, tree, error, statusTick.budget);
|
|
15062
|
-
}
|
|
15063
|
-
continue;
|
|
15064
|
-
}
|
|
15065
|
-
const closure = closuresByAskId.get(task.id) ?? buildAskClosure(task, tasks);
|
|
15066
|
-
let childCardPending = false;
|
|
15067
|
-
const existingChildCards = await childCardCountFor(task.id);
|
|
15068
|
-
for (const member of closure) {
|
|
15069
|
-
if (!isChildCardCandidate(member, delegationActivatedAt) || member.slackReplySent)
|
|
15070
|
-
continue;
|
|
15071
|
-
if (existingChildCards >= CHILD_CARDS_PER_ASK)
|
|
15072
|
-
break;
|
|
15073
|
-
const memberCard = await getSlackOutcomeMessage2(member.id);
|
|
15074
|
-
if (!memberCard || !isSettledSlackMessage2(memberCard)) {
|
|
15075
|
-
childCardPending = true;
|
|
15076
|
-
break;
|
|
15077
|
-
}
|
|
15135
|
+
if (existingChildCards >= CHILD_CARDS_PER_ASK)
|
|
15136
|
+
break;
|
|
15137
|
+
const memberCard = await getSlackOutcomeMessage2(member.id);
|
|
15138
|
+
if (!memberCard || !isSettledSlackMessage2(memberCard)) {
|
|
15139
|
+
childCardPending = true;
|
|
15140
|
+
break;
|
|
15078
15141
|
}
|
|
15079
|
-
|
|
15080
|
-
|
|
15081
|
-
|
|
15082
|
-
|
|
15083
|
-
|
|
15084
|
-
|
|
15085
|
-
|
|
15086
|
-
|
|
15087
|
-
|
|
15088
|
-
|
|
15089
|
-
|
|
15090
|
-
|
|
15091
|
-
|
|
15092
|
-
|
|
15093
|
-
|
|
15094
|
-
|
|
15095
|
-
|
|
15096
|
-
|
|
15097
|
-
|
|
15098
|
-
|
|
15099
|
-
|
|
15100
|
-
await recordSlackDelivery(task, outcome, state === "timedOut" ? "conclusion_timeout" : "conclusion");
|
|
15142
|
+
}
|
|
15143
|
+
if (childCardPending)
|
|
15144
|
+
continue;
|
|
15145
|
+
const state = closureState(task, closure, new Date, settleSec, timeoutMin);
|
|
15146
|
+
if (state === "open")
|
|
15147
|
+
continue;
|
|
15148
|
+
if (!await checkOutcomeDeliveryGate(task, card, statusTick.budget))
|
|
15149
|
+
continue;
|
|
15150
|
+
try {
|
|
15151
|
+
const outcome = await streamOutcomeCard(task, tree, {
|
|
15152
|
+
buildContent: (_t, slackReplySent) => askConclusionContent(task, closure, state, slackReplySent),
|
|
15153
|
+
conclusionKind: state === "timedOut" ? "timeout" : "complete",
|
|
15154
|
+
statusBudget: statusTick.budget
|
|
15155
|
+
});
|
|
15156
|
+
if (outcome) {
|
|
15157
|
+
noteOutcomeDeliverySuccess(task.id);
|
|
15158
|
+
const app = getSlackApp2();
|
|
15159
|
+
if (app && task.slackChannelId && task.slackTriggerMessageTs) {
|
|
15160
|
+
const reaction = conclusionReactionChoice(state, task, closure);
|
|
15161
|
+
await finalizeSlackMessageReaction(app.client, task.slackChannelId, task.slackTriggerMessageTs, reaction.name, reaction.event);
|
|
15162
|
+
await finalizeSlackSteerReactions([task], () => reaction);
|
|
15101
15163
|
}
|
|
15102
|
-
|
|
15103
|
-
} catch (error) {
|
|
15104
|
-
await noteOutcomeDeliveryFailure(task, tree, error, statusTick.budget);
|
|
15164
|
+
await recordSlackDelivery(task, outcome, state === "timedOut" ? "conclusion_timeout" : "conclusion");
|
|
15105
15165
|
}
|
|
15166
|
+
outcomeCreated ||= !!outcome;
|
|
15167
|
+
} catch (error) {
|
|
15168
|
+
await noteOutcomeDeliveryFailure(task, tree, error, statusTick.budget);
|
|
15106
15169
|
}
|
|
15170
|
+
}
|
|
15171
|
+
try {
|
|
15172
|
+
await updateThreadTree(tree, outcomeCreated, statusTick.budget);
|
|
15173
|
+
} catch (error) {
|
|
15174
|
+
console.error(`[Slack] Failed to update v2 tree ${tree.id}:`, error);
|
|
15175
|
+
}
|
|
15176
|
+
await statusTick.reconcile(tree.channelId, tree.threadTs);
|
|
15177
|
+
try {
|
|
15178
|
+
if (await closeSlackTreeIfSettled(tree.id))
|
|
15179
|
+
return "closed";
|
|
15180
|
+
} catch (error) {
|
|
15181
|
+
console.error(`[Slack] Failed to close settled v2 tree ${tree.id}:`, error);
|
|
15182
|
+
}
|
|
15183
|
+
return "open";
|
|
15184
|
+
}
|
|
15185
|
+
function yieldToEventLoop() {
|
|
15186
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
15187
|
+
}
|
|
15188
|
+
function scheduleDirtyFlush(delayMs) {
|
|
15189
|
+
if (!renderEventsSubscribed)
|
|
15190
|
+
return;
|
|
15191
|
+
const at = Date.now() + delayMs;
|
|
15192
|
+
if (dirtyFlushTimer && dirtyFlushAt <= at)
|
|
15193
|
+
return;
|
|
15194
|
+
if (dirtyFlushTimer)
|
|
15195
|
+
clearTimeout(dirtyFlushTimer);
|
|
15196
|
+
dirtyFlushAt = at;
|
|
15197
|
+
dirtyFlushTimer = setTimeout(() => {
|
|
15198
|
+
dirtyFlushTimer = null;
|
|
15199
|
+
flushSlackRenderV2DirtyThreads().catch((error) => {
|
|
15200
|
+
console.error("[Slack] Event-driven v2 render failed:", error);
|
|
15201
|
+
});
|
|
15202
|
+
}, delayMs);
|
|
15203
|
+
}
|
|
15204
|
+
function markSlackThreadDirty(channelId, threadTs, delayMs = DIRTY_FLUSH_DEBOUNCE_MS) {
|
|
15205
|
+
dirtyThreads.set(`${channelId}\x00${threadTs}`, { channelId, threadTs });
|
|
15206
|
+
scheduleDirtyFlush(delayMs);
|
|
15207
|
+
}
|
|
15208
|
+
function onSlackRenderTaskEvent(data) {
|
|
15209
|
+
const taskId = data?.taskId;
|
|
15210
|
+
if (typeof taskId !== "string")
|
|
15211
|
+
return;
|
|
15212
|
+
dirtyTaskIds.add(taskId);
|
|
15213
|
+
scheduleDirtyFlush(DIRTY_FLUSH_DEBOUNCE_MS);
|
|
15214
|
+
}
|
|
15215
|
+
function startSlackRenderV2Events2() {
|
|
15216
|
+
if (renderEventsSubscribed)
|
|
15217
|
+
return;
|
|
15218
|
+
for (const event of SLACK_RENDER_TASK_EVENTS)
|
|
15219
|
+
workflowEventBus2.on(event, onSlackRenderTaskEvent);
|
|
15220
|
+
renderEventsSubscribed = true;
|
|
15221
|
+
}
|
|
15222
|
+
function stopSlackRenderV2Events2() {
|
|
15223
|
+
if (!renderEventsSubscribed)
|
|
15224
|
+
return;
|
|
15225
|
+
for (const event of SLACK_RENDER_TASK_EVENTS)
|
|
15226
|
+
workflowEventBus2.off(event, onSlackRenderTaskEvent);
|
|
15227
|
+
renderEventsSubscribed = false;
|
|
15228
|
+
if (dirtyFlushTimer)
|
|
15229
|
+
clearTimeout(dirtyFlushTimer);
|
|
15230
|
+
dirtyFlushTimer = null;
|
|
15231
|
+
}
|
|
15232
|
+
function runExclusive(work) {
|
|
15233
|
+
if (renderInFlight)
|
|
15234
|
+
return renderInFlight;
|
|
15235
|
+
const run = (async () => {
|
|
15107
15236
|
try {
|
|
15108
|
-
await
|
|
15237
|
+
await work();
|
|
15238
|
+
} finally {
|
|
15239
|
+
renderInFlight = null;
|
|
15240
|
+
}
|
|
15241
|
+
})();
|
|
15242
|
+
renderInFlight = run;
|
|
15243
|
+
return run;
|
|
15244
|
+
}
|
|
15245
|
+
async function beginRenderPass() {
|
|
15246
|
+
const activatedAt = await ensureSlackRenderV2Activation2();
|
|
15247
|
+
const delegationEnabled = isSlackDelegationEnabled();
|
|
15248
|
+
const delegationActivatedAt = delegationEnabled ? await ensureSlackDelegationActivation2() : null;
|
|
15249
|
+
return {
|
|
15250
|
+
activatedAt,
|
|
15251
|
+
delegationEnabled,
|
|
15252
|
+
delegationActivatedAt,
|
|
15253
|
+
statusTick: beginSlackStatusTick()
|
|
15254
|
+
};
|
|
15255
|
+
}
|
|
15256
|
+
async function flushSlackRenderV2DirtyThreads() {
|
|
15257
|
+
if (!isSlackRenderV2Enabled2() || !getSlackApp2())
|
|
15258
|
+
return;
|
|
15259
|
+
if (renderInFlight) {
|
|
15260
|
+
await renderInFlight;
|
|
15261
|
+
if (dirtyTaskIds.size === 0 && dirtyThreads.size === 0)
|
|
15262
|
+
return;
|
|
15263
|
+
}
|
|
15264
|
+
await runExclusive(renderDirtyThreads);
|
|
15265
|
+
}
|
|
15266
|
+
function processSlackRenderV22() {
|
|
15267
|
+
if (!isSlackRenderV2Enabled2())
|
|
15268
|
+
return Promise.resolve();
|
|
15269
|
+
return runExclusive(reconcileAllThreads);
|
|
15270
|
+
}
|
|
15271
|
+
async function reconcileAllThreads() {
|
|
15272
|
+
dirtyTaskIds.clear();
|
|
15273
|
+
dirtyThreads.clear();
|
|
15274
|
+
const context = await beginRenderPass();
|
|
15275
|
+
for (const task of await getSlackTasksMissingTree2()) {
|
|
15276
|
+
if (!isSlackRenderV2Enabled2())
|
|
15277
|
+
return;
|
|
15278
|
+
if (!task.slackChannelId || !task.slackThreadTs)
|
|
15279
|
+
continue;
|
|
15280
|
+
try {
|
|
15281
|
+
await ensureSlackThreadTree2([task.id], context.statusTick.budget);
|
|
15109
15282
|
} catch (error) {
|
|
15110
|
-
console.error(`[Slack] Failed to
|
|
15283
|
+
console.error(`[Slack] Failed to create v2 tree for task ${task.id}:`, error);
|
|
15111
15284
|
}
|
|
15112
|
-
|
|
15285
|
+
}
|
|
15286
|
+
await yieldToEventLoop();
|
|
15287
|
+
for (const storedTree of await getSlackTreeMessages2()) {
|
|
15288
|
+
if (await renderStoredTree(storedTree, context) === "stop")
|
|
15289
|
+
return;
|
|
15290
|
+
await yieldToEventLoop();
|
|
15113
15291
|
}
|
|
15114
15292
|
await refreshResolvedDeferralCards();
|
|
15115
|
-
await
|
|
15293
|
+
await yieldToEventLoop();
|
|
15294
|
+
await context.statusTick.finish();
|
|
15295
|
+
}
|
|
15296
|
+
async function renderDirtyThreads() {
|
|
15297
|
+
const taskIds = [...dirtyTaskIds];
|
|
15298
|
+
dirtyTaskIds.clear();
|
|
15299
|
+
const threads = new Map(dirtyThreads);
|
|
15300
|
+
dirtyThreads.clear();
|
|
15301
|
+
const touched = await getSlackThreadsOfTasks(taskIds);
|
|
15302
|
+
for (const thread of touched.threads) {
|
|
15303
|
+
threads.set(`${thread.channelId}\x00${thread.threadTs}`, thread);
|
|
15304
|
+
}
|
|
15305
|
+
if (threads.size === 0 && !touched.wakeTouched)
|
|
15306
|
+
return;
|
|
15307
|
+
const context = await beginRenderPass();
|
|
15308
|
+
for (const thread of threads.values()) {
|
|
15309
|
+
if (!isSlackRenderV2Enabled2())
|
|
15310
|
+
return;
|
|
15311
|
+
for (const task of await getSlackTasksMissingTree2({ thread })) {
|
|
15312
|
+
try {
|
|
15313
|
+
await ensureSlackThreadTree2([task.id], context.statusTick.budget);
|
|
15314
|
+
} catch (error) {
|
|
15315
|
+
console.error(`[Slack] Failed to create v2 tree for task ${task.id}:`, error);
|
|
15316
|
+
}
|
|
15317
|
+
}
|
|
15318
|
+
for (const storedTree of await getSlackTreeMessages2({ thread })) {
|
|
15319
|
+
const result = await renderStoredTree(storedTree, context);
|
|
15320
|
+
if (result === "stop")
|
|
15321
|
+
return;
|
|
15322
|
+
if (result !== "closed" && await slackThreadHasOutcomeWork(thread)) {
|
|
15323
|
+
markSlackThreadDirty(thread.channelId, thread.threadTs, DIRTY_REVISIT_MS);
|
|
15324
|
+
}
|
|
15325
|
+
}
|
|
15326
|
+
await yieldToEventLoop();
|
|
15327
|
+
}
|
|
15328
|
+
if (touched.wakeTouched)
|
|
15329
|
+
await refreshResolvedDeferralCards();
|
|
15116
15330
|
}
|
|
15117
|
-
var TREE_UPDATE_DEBOUNCE_MS = 500, TREE_UPDATE_MIN_INTERVAL_MS = 3000, MAX_SLACK_RETRIES = 3, MAX_RETRY_DELAY_MS = 30000, MAX_TITLE_LENGTH = 72, MAX_OUTCOME_MARKDOWN_LENGTH = 12000, MAX_TREE_NODE_LINE_LENGTH = 1000, MAX_TREE_PREFIX_LENGTH = 120, MAX_TREE_PROGRESS_LENGTH = 60, CHILD_CARDS_PER_TICK = 3, CHILD_CARDS_PER_ASK = 10, CONCLUSION_DIGEST_LENGTH = 300, TREE_INDENT, FIGURE_SPACE = " ", SLACK_RENDER_METADATA_EVENT = "agent_swarm_render_v2", treeCreationPromises, pendingTreeUpdates, treeUpdateTails, lastTreeText, lastTreeUpdateAt, cachedTeamId, OUTCOME_DELIVERY_MAX_ATTEMPTS = 5, OUTCOME_DELIVERY_BASE_DELAY_MS = 30000, OUTCOME_DELIVERY_MAX_DELAY_MS, outcomeDeliveryNextAttemptAt, outcomeReservedWithoutAttempt, LINE_START_BLOCK, TRANSIENT_SLACK_ERROR_CODES, DEFERRAL_REFRESH_MAX_ATTEMPTS = 5, deferralRefreshAttempts;
|
|
15331
|
+
var TREE_UPDATE_DEBOUNCE_MS = 500, TREE_UPDATE_MIN_INTERVAL_MS = 3000, MAX_SLACK_RETRIES = 3, MAX_RETRY_DELAY_MS = 30000, MAX_TITLE_LENGTH = 72, MAX_OUTCOME_MARKDOWN_LENGTH = 12000, MAX_TREE_NODE_LINE_LENGTH = 1000, MAX_TREE_PREFIX_LENGTH = 120, MAX_TREE_PROGRESS_LENGTH = 60, CHILD_CARDS_PER_TICK = 3, CHILD_CARDS_PER_ASK = 10, CONCLUSION_DIGEST_LENGTH = 300, TREE_INDENT, FIGURE_SPACE = " ", SLACK_RENDER_METADATA_EVENT = "agent_swarm_render_v2", treeCreationPromises, pendingTreeUpdates, treeUpdateTails, lastTreeText, lastTreeUpdateAt, cachedTeamId, OUTCOME_DELIVERY_MAX_ATTEMPTS = 5, OUTCOME_DELIVERY_BASE_DELAY_MS = 30000, OUTCOME_DELIVERY_MAX_DELAY_MS, outcomeDeliveryNextAttemptAt, outcomeReservedWithoutAttempt, LINE_START_BLOCK, TRANSIENT_SLACK_ERROR_CODES, DEFERRAL_REFRESH_MAX_ATTEMPTS = 5, deferralRefreshAttempts, SLACK_RENDER_TASK_EVENTS, DIRTY_FLUSH_DEBOUNCE_MS = 500, DIRTY_REVISIT_MS = 3000, dirtyTaskIds, dirtyThreads, renderInFlight = null, renderEventsSubscribed = false, dirtyFlushTimer = null, dirtyFlushAt = 0;
|
|
15118
15332
|
var init_render_v2 = __esm(() => {
|
|
15119
15333
|
init_db4();
|
|
15334
|
+
init_slack_trees();
|
|
15120
15335
|
init_task_citations2();
|
|
15121
15336
|
init_context_key();
|
|
15122
15337
|
init_business_use();
|
|
@@ -15124,6 +15339,7 @@ var init_render_v2 = __esm(() => {
|
|
|
15124
15339
|
init_secret_scrubber();
|
|
15125
15340
|
init_task_attachment_links();
|
|
15126
15341
|
init_task_citations();
|
|
15342
|
+
init_event_bus();
|
|
15127
15343
|
init_ack();
|
|
15128
15344
|
init_app3();
|
|
15129
15345
|
init_blocks();
|
|
@@ -15153,6 +15369,17 @@ var init_render_v2 = __esm(() => {
|
|
|
15153
15369
|
"external_channel_unverified"
|
|
15154
15370
|
]);
|
|
15155
15371
|
deferralRefreshAttempts = new Map;
|
|
15372
|
+
SLACK_RENDER_TASK_EVENTS = [
|
|
15373
|
+
"task.created",
|
|
15374
|
+
"task.completed",
|
|
15375
|
+
"task.failed",
|
|
15376
|
+
"task.cancelled",
|
|
15377
|
+
"task.skipped",
|
|
15378
|
+
"task.superseded",
|
|
15379
|
+
"task.progress"
|
|
15380
|
+
];
|
|
15381
|
+
dirtyTaskIds = new Set;
|
|
15382
|
+
dirtyThreads = new Map;
|
|
15156
15383
|
});
|
|
15157
15384
|
|
|
15158
15385
|
// src/slack/watcher.ts
|
|
@@ -15504,18 +15731,25 @@ async function processPendingSlackRelays(now = Date.now()) {
|
|
|
15504
15731
|
}
|
|
15505
15732
|
}
|
|
15506
15733
|
}
|
|
15507
|
-
|
|
15734
|
+
function slackTaskWatcherIntervalMs() {
|
|
15735
|
+
const raw = process.env.SLACK_TASK_WATCHER_INTERVAL_MS?.trim();
|
|
15736
|
+
const parsed = raw ? Number(raw) : Number.NaN;
|
|
15737
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : DEFAULT_SLACK_TASK_WATCHER_INTERVAL_MS;
|
|
15738
|
+
}
|
|
15739
|
+
async function startTaskWatcher(intervalMs = slackTaskWatcherIntervalMs()) {
|
|
15508
15740
|
if (watcherInterval) {
|
|
15509
15741
|
console.log("[Slack] Task watcher already running");
|
|
15510
15742
|
return;
|
|
15511
15743
|
}
|
|
15744
|
+
const epoch = watcherEpoch;
|
|
15512
15745
|
let hydratedTrees = 0;
|
|
15513
15746
|
let hydratedFlat = 0;
|
|
15514
15747
|
const hydrationTasks = new Map;
|
|
15515
|
-
|
|
15516
|
-
|
|
15517
|
-
|
|
15518
|
-
|
|
15748
|
+
const inProgress = await getInProgressSlackTasks2();
|
|
15749
|
+
const pendingRelays = await getPendingSlackRelayTasks2();
|
|
15750
|
+
if (epoch !== watcherEpoch || watcherInterval)
|
|
15751
|
+
return;
|
|
15752
|
+
for (const task of [...inProgress, ...pendingRelays]) {
|
|
15519
15753
|
hydrationTasks.set(task.id, task);
|
|
15520
15754
|
}
|
|
15521
15755
|
for (const task of hydrationTasks.values()) {
|
|
@@ -15558,7 +15792,8 @@ async function startTaskWatcher(intervalMs = 3000) {
|
|
|
15558
15792
|
if (hydratedTrees > 0 || hydratedFlat > 0) {
|
|
15559
15793
|
console.log(`[Slack] Hydrated ${hydratedTrees} tree task(s) and ${hydratedFlat} flat task(s) from DB`);
|
|
15560
15794
|
}
|
|
15561
|
-
|
|
15795
|
+
startSlackRenderV2Events2();
|
|
15796
|
+
const watcherTick = async () => {
|
|
15562
15797
|
if (isProcessing || !getSlackApp2())
|
|
15563
15798
|
return;
|
|
15564
15799
|
isProcessing = true;
|
|
@@ -15696,20 +15931,24 @@ async function startTaskWatcher(intervalMs = 3000) {
|
|
|
15696
15931
|
} finally {
|
|
15697
15932
|
isProcessing = false;
|
|
15698
15933
|
}
|
|
15699
|
-
}
|
|
15934
|
+
};
|
|
15935
|
+
watcherInterval = setInterval(bindLoopPath("slack.watcher.tick", watcherTick), intervalMs);
|
|
15700
15936
|
console.log(`[Slack] Task watcher started (interval: ${intervalMs}ms)`);
|
|
15701
15937
|
}
|
|
15702
15938
|
function stopTaskWatcher() {
|
|
15939
|
+
watcherEpoch += 1;
|
|
15703
15940
|
if (watcherInterval) {
|
|
15704
15941
|
clearInterval(watcherInterval);
|
|
15705
15942
|
watcherInterval = null;
|
|
15706
15943
|
isProcessing = false;
|
|
15944
|
+
stopSlackRenderV2Events2();
|
|
15707
15945
|
console.log("[Slack] Task watcher stopped");
|
|
15708
15946
|
}
|
|
15709
15947
|
}
|
|
15710
|
-
var watcherInterval = null, isProcessing = false, notifiedCompletions, sentProgress, pendingSends, lastSendTime, MIN_SEND_INTERVAL = 1000, treeMessages, taskToTree, taskMessages, lastRenderedTree, treeLastUpdateTime;
|
|
15948
|
+
var watcherInterval = null, isProcessing = false, watcherEpoch = 0, notifiedCompletions, sentProgress, pendingSends, lastSendTime, MIN_SEND_INTERVAL = 1000, treeMessages, taskToTree, taskMessages, lastRenderedTree, treeLastUpdateTime, DEFAULT_SLACK_TASK_WATCHER_INTERVAL_MS = 1e4;
|
|
15711
15949
|
var init_watcher = __esm(() => {
|
|
15712
15950
|
init_db4();
|
|
15951
|
+
init_event_loop_lag();
|
|
15713
15952
|
init_ack();
|
|
15714
15953
|
init_app3();
|
|
15715
15954
|
init_blocks();
|
|
@@ -15732,10 +15971,128 @@ var init_watcher = __esm(() => {
|
|
|
15732
15971
|
function trackConnectionState(owner) {
|
|
15733
15972
|
for (const [event, state] of Object.entries(SOCKET_EVENT_STATES)) {
|
|
15734
15973
|
owner.client.on(event, () => {
|
|
15735
|
-
if (receiver
|
|
15736
|
-
|
|
15974
|
+
if (receiver !== owner)
|
|
15975
|
+
return;
|
|
15976
|
+
setSlackConnectionState(state);
|
|
15977
|
+
if (state === "connected")
|
|
15978
|
+
lastSocketActivityAt = Date.now();
|
|
15737
15979
|
});
|
|
15738
15980
|
}
|
|
15981
|
+
owner.client.on("slack_event", () => {
|
|
15982
|
+
if (receiver === owner)
|
|
15983
|
+
lastSocketActivityAt = Date.now();
|
|
15984
|
+
});
|
|
15985
|
+
}
|
|
15986
|
+
function slackWatchdogBackoffMs(attempt, options) {
|
|
15987
|
+
return Math.min(options.backoffBaseMs * 2 ** Math.max(0, attempt - 1), options.backoffMaxMs);
|
|
15988
|
+
}
|
|
15989
|
+
function createSlackSocketWatchdog(deps, options = SLACK_SOCKET_WATCHDOG_DEFAULTS) {
|
|
15990
|
+
let downSince = null;
|
|
15991
|
+
let attempts = 0;
|
|
15992
|
+
let nextAttemptAt = 0;
|
|
15993
|
+
let restarting = false;
|
|
15994
|
+
function isHealthy(now) {
|
|
15995
|
+
if (deps.getState() !== "connected")
|
|
15996
|
+
return false;
|
|
15997
|
+
const lastActivityAt = deps.getLastActivityAt();
|
|
15998
|
+
if (lastActivityAt === null || now - lastActivityAt < options.staleActivityMs)
|
|
15999
|
+
return true;
|
|
16000
|
+
return deps.isSocketActive();
|
|
16001
|
+
}
|
|
16002
|
+
async function tick() {
|
|
16003
|
+
if (restarting || deps.isLifecycleBusy())
|
|
16004
|
+
return;
|
|
16005
|
+
const now = deps.now();
|
|
16006
|
+
if (isHealthy(now)) {
|
|
16007
|
+
if (attempts > 0 && downSince !== null) {
|
|
16008
|
+
deps.log(`[Slack] watchdog: recovered after ${seconds(now - downSince)}s`);
|
|
16009
|
+
}
|
|
16010
|
+
downSince = null;
|
|
16011
|
+
attempts = 0;
|
|
16012
|
+
nextAttemptAt = 0;
|
|
16013
|
+
return;
|
|
16014
|
+
}
|
|
16015
|
+
downSince ??= now;
|
|
16016
|
+
if (now - downSince < options.downAfterMs || now < nextAttemptAt)
|
|
16017
|
+
return;
|
|
16018
|
+
attempts += 1;
|
|
16019
|
+
nextAttemptAt = now + slackWatchdogBackoffMs(attempts, options);
|
|
16020
|
+
deps.log(`[Slack] watchdog: socket down for ${seconds(now - downSince)}s, restarting (attempt ${attempts})`);
|
|
16021
|
+
restarting = true;
|
|
16022
|
+
try {
|
|
16023
|
+
await deps.restart();
|
|
16024
|
+
} catch (error) {
|
|
16025
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
16026
|
+
console.error(`[Slack] watchdog: restart failed: ${scrubSecrets(message)}`);
|
|
16027
|
+
} finally {
|
|
16028
|
+
restarting = false;
|
|
16029
|
+
}
|
|
16030
|
+
}
|
|
16031
|
+
return { tick, attempts: () => attempts };
|
|
16032
|
+
}
|
|
16033
|
+
function seconds(ms) {
|
|
16034
|
+
return Math.round(ms / 1000);
|
|
16035
|
+
}
|
|
16036
|
+
function isLiveSocketActive() {
|
|
16037
|
+
return receiver?.client.websocket?.isActive() ?? false;
|
|
16038
|
+
}
|
|
16039
|
+
async function restartSlackAppForWatchdog(owner) {
|
|
16040
|
+
await runSlackLifecycleExclusive(async () => {
|
|
16041
|
+
if (watchdogTimer !== owner)
|
|
16042
|
+
return;
|
|
16043
|
+
if (getSlackConnectionState() === "connected" && isLiveSocketActive())
|
|
16044
|
+
return;
|
|
16045
|
+
let abandoned = false;
|
|
16046
|
+
const restart = (async () => {
|
|
16047
|
+
await teardownSlackApp();
|
|
16048
|
+
if (!abandoned && watchdogTimer === owner)
|
|
16049
|
+
await startSlackApp2();
|
|
16050
|
+
})();
|
|
16051
|
+
const timeoutMs = watchdogOptions.restartTimeoutMs;
|
|
16052
|
+
let timer;
|
|
16053
|
+
const timedOut = new Promise((resolve) => {
|
|
16054
|
+
timer = setTimeout(() => resolve(true), timeoutMs);
|
|
16055
|
+
});
|
|
16056
|
+
try {
|
|
16057
|
+
const outcome = await Promise.race([restart.then(() => false), timedOut]);
|
|
16058
|
+
if (!outcome)
|
|
16059
|
+
return;
|
|
16060
|
+
} finally {
|
|
16061
|
+
clearTimeout(timer);
|
|
16062
|
+
}
|
|
16063
|
+
abandoned = true;
|
|
16064
|
+
restart.catch(() => {});
|
|
16065
|
+
abandonSlackApp();
|
|
16066
|
+
throw new Error(`restart did not finish within ${seconds(timeoutMs)}s; abandoned it`);
|
|
16067
|
+
});
|
|
16068
|
+
}
|
|
16069
|
+
function startSocketWatchdog() {
|
|
16070
|
+
if (watchdogTimer)
|
|
16071
|
+
return;
|
|
16072
|
+
let timer = null;
|
|
16073
|
+
const watchdog = createSlackSocketWatchdog({
|
|
16074
|
+
now: Date.now,
|
|
16075
|
+
getState: getSlackConnectionState,
|
|
16076
|
+
getLastActivityAt: () => lastSocketActivityAt,
|
|
16077
|
+
isSocketActive: isLiveSocketActive,
|
|
16078
|
+
isLifecycleBusy: isSlackLifecycleBusy,
|
|
16079
|
+
restart: () => timer ? restartSlackAppForWatchdog(timer) : Promise.resolve(),
|
|
16080
|
+
log: (line) => console.log(line)
|
|
16081
|
+
}, watchdogOptions);
|
|
16082
|
+
timer = setInterval(() => {
|
|
16083
|
+
if (getSlackConfiguration().mode !== "socket") {
|
|
16084
|
+
stopSocketWatchdog();
|
|
16085
|
+
return;
|
|
16086
|
+
}
|
|
16087
|
+
watchdog.tick();
|
|
16088
|
+
}, watchdogOptions.tickMs);
|
|
16089
|
+
timer.unref?.();
|
|
16090
|
+
watchdogTimer = timer;
|
|
16091
|
+
}
|
|
16092
|
+
function stopSocketWatchdog() {
|
|
16093
|
+
if (watchdogTimer)
|
|
16094
|
+
clearInterval(watchdogTimer);
|
|
16095
|
+
watchdogTimer = null;
|
|
15739
16096
|
}
|
|
15740
16097
|
function getSlackApp2() {
|
|
15741
16098
|
return app;
|
|
@@ -15780,6 +16137,7 @@ async function initSlackApp2() {
|
|
|
15780
16137
|
installerOptions: clientOptions ? { clientOptions } : {}
|
|
15781
16138
|
});
|
|
15782
16139
|
trackConnectionState(receiver);
|
|
16140
|
+
socketFence = fenceSocketModeClient(receiver.client);
|
|
15783
16141
|
app = new import_bolt4.App({
|
|
15784
16142
|
token: botToken,
|
|
15785
16143
|
receiver,
|
|
@@ -15790,17 +16148,17 @@ async function initSlackApp2() {
|
|
|
15790
16148
|
inboundDrain = installSocketAckRecovery(receiver.client, app);
|
|
15791
16149
|
initialized2 = true;
|
|
15792
16150
|
app.use(slackInboundOutcomeMiddleware());
|
|
15793
|
-
const { registerMessageHandler } = await import("./handlers-
|
|
15794
|
-
const { registerCommandHandler } = await import("./commands-
|
|
15795
|
-
const { registerActionHandlers } = await import("./actions-
|
|
15796
|
-
const { registerWorkObjectHandlers } = await import("./work-objects-
|
|
16151
|
+
const { registerMessageHandler } = await import("./handlers-17wha3ze.js");
|
|
16152
|
+
const { registerCommandHandler } = await import("./commands-phjfbkv0.js");
|
|
16153
|
+
const { registerActionHandlers } = await import("./actions-b8aqhrsg.js");
|
|
16154
|
+
const { registerWorkObjectHandlers } = await import("./work-objects-bf3syvhq.js");
|
|
15797
16155
|
registerMessageHandler(app);
|
|
15798
16156
|
registerCommandHandler(app);
|
|
15799
16157
|
registerActionHandlers(app);
|
|
15800
16158
|
registerWorkObjectHandlers(app);
|
|
15801
|
-
const { createAssistant } = await import("./assistant-
|
|
16159
|
+
const { createAssistant } = await import("./assistant-rh4v3ntz.js");
|
|
15802
16160
|
app.assistant(createAssistant());
|
|
15803
|
-
const { isBlockExternalEnabled, scanExternalChannelsOnBoot } = await import("./external-channel-
|
|
16161
|
+
const { isBlockExternalEnabled, scanExternalChannelsOnBoot } = await import("./external-channel-se646snz.js");
|
|
15804
16162
|
if (isBlockExternalEnabled()) {
|
|
15805
16163
|
scanExternalChannelsOnBoot(app.client).catch((error) => {
|
|
15806
16164
|
console.error("[Slack] External channel boot scan failed:", error);
|
|
@@ -15809,46 +16167,97 @@ async function initSlackApp2() {
|
|
|
15809
16167
|
return app;
|
|
15810
16168
|
}
|
|
15811
16169
|
async function startSlackApp2() {
|
|
16170
|
+
const generation = lifecycleGeneration;
|
|
15812
16171
|
if (!app) {
|
|
15813
16172
|
await initSlackApp2();
|
|
15814
16173
|
}
|
|
15815
|
-
|
|
15816
|
-
|
|
16174
|
+
const current = app;
|
|
16175
|
+
if (current && generation === lifecycleGeneration) {
|
|
16176
|
+
startSocketWatchdog();
|
|
16177
|
+
const { isSlackRenderV2Enabled } = await import("./render-v2-5b6chvcq.js");
|
|
15817
16178
|
if (isSlackRenderV2Enabled())
|
|
15818
16179
|
await ensureSlackRenderV2Activation2();
|
|
15819
16180
|
await recoverSlackInboundAfterRestart();
|
|
15820
|
-
|
|
16181
|
+
if (generation !== lifecycleGeneration)
|
|
16182
|
+
return false;
|
|
16183
|
+
await current.start();
|
|
16184
|
+
if (generation !== lifecycleGeneration)
|
|
16185
|
+
return false;
|
|
15821
16186
|
console.log("[Slack] Bot connected via Socket Mode");
|
|
15822
16187
|
inboundDrain?.wake();
|
|
15823
16188
|
await emitBuiltInIntegrationConnectedOnce2("slack");
|
|
16189
|
+
if (generation !== lifecycleGeneration)
|
|
16190
|
+
return false;
|
|
15824
16191
|
await startTaskWatcher();
|
|
15825
16192
|
return true;
|
|
15826
16193
|
}
|
|
15827
16194
|
return false;
|
|
15828
16195
|
}
|
|
15829
16196
|
async function stopSlackApp2() {
|
|
16197
|
+
const locked = runSlackLifecycleExclusive(stopSlackAppUnderLifecycleLock2);
|
|
16198
|
+
const waitMs = watchdogOptions.stopLockWaitMs;
|
|
16199
|
+
let timer;
|
|
16200
|
+
const timedOut = new Promise((resolve) => {
|
|
16201
|
+
timer = setTimeout(() => resolve(true), waitMs);
|
|
16202
|
+
});
|
|
16203
|
+
try {
|
|
16204
|
+
const outcome = await Promise.race([locked.then(() => false), timedOut]);
|
|
16205
|
+
if (!outcome)
|
|
16206
|
+
return;
|
|
16207
|
+
} finally {
|
|
16208
|
+
clearTimeout(timer);
|
|
16209
|
+
}
|
|
16210
|
+
locked.catch(() => {});
|
|
16211
|
+
console.error(`[Slack] stop: lifecycle lock still held after ${seconds(waitMs)}s; stopping without it`);
|
|
16212
|
+
stopSocketWatchdog();
|
|
16213
|
+
abandonSlackApp();
|
|
16214
|
+
}
|
|
16215
|
+
async function stopSlackAppUnderLifecycleLock2() {
|
|
16216
|
+
stopSocketWatchdog();
|
|
16217
|
+
await teardownSlackApp();
|
|
16218
|
+
}
|
|
16219
|
+
async function teardownSlackApp() {
|
|
16220
|
+
const stopping = detachSlackApp();
|
|
16221
|
+
if (stopping) {
|
|
16222
|
+
await stopping.stop();
|
|
16223
|
+
console.log("[Slack] Bot disconnected");
|
|
16224
|
+
}
|
|
16225
|
+
}
|
|
16226
|
+
function abandonSlackApp() {
|
|
16227
|
+
const stalled = detachSlackApp();
|
|
16228
|
+
stalled?.stop().catch((error) => {
|
|
16229
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
16230
|
+
console.error(`[Slack] watchdog: stopping the abandoned app failed: ${scrubSecrets(message)}`);
|
|
16231
|
+
});
|
|
16232
|
+
}
|
|
16233
|
+
function detachSlackApp() {
|
|
16234
|
+
socketFence?.retire();
|
|
16235
|
+
socketFence = null;
|
|
16236
|
+
lifecycleGeneration += 1;
|
|
15830
16237
|
stopTaskWatcher();
|
|
15831
16238
|
inboundDrain?.stop();
|
|
15832
16239
|
inboundDrain = null;
|
|
15833
|
-
|
|
15834
|
-
|
|
15835
|
-
app = null;
|
|
15836
|
-
console.log("[Slack] Bot disconnected");
|
|
15837
|
-
}
|
|
16240
|
+
const detached = app;
|
|
16241
|
+
app = null;
|
|
15838
16242
|
receiver = null;
|
|
16243
|
+
lastSocketActivityAt = null;
|
|
15839
16244
|
setSlackConnectionState("disconnected");
|
|
15840
16245
|
initialized2 = false;
|
|
16246
|
+
return detached;
|
|
15841
16247
|
}
|
|
15842
|
-
var import_bolt4, app = null, receiver = null, initialized2 = false, inboundDrain = null, SOCKET_EVENT_STATES;
|
|
16248
|
+
var import_bolt4, app = null, receiver = null, initialized2 = false, inboundDrain = null, socketFence = null, lifecycleGeneration = 0, lastSocketActivityAt = null, SOCKET_EVENT_STATES, SLACK_SOCKET_WATCHDOG_DEFAULTS, watchdogTimer = null, watchdogOptions;
|
|
15843
16249
|
var init_app3 = __esm(() => {
|
|
15844
16250
|
init_db4();
|
|
15845
16251
|
init_node_env();
|
|
16252
|
+
init_secret_scrubber();
|
|
15846
16253
|
init_config4();
|
|
15847
16254
|
init_connection_state();
|
|
15848
16255
|
init_egress_scrub();
|
|
15849
16256
|
init_external_channel_egress();
|
|
15850
16257
|
init_inbound_dispatch();
|
|
16258
|
+
init_lifecycle_lock();
|
|
15851
16259
|
init_socket_ack();
|
|
16260
|
+
init_socket_fence();
|
|
15852
16261
|
init_socket_mode_guard();
|
|
15853
16262
|
init_watcher();
|
|
15854
16263
|
import_bolt4 = __toESM(require_dist5(), 1);
|
|
@@ -15859,6 +16268,16 @@ var init_app3 = __esm(() => {
|
|
|
15859
16268
|
disconnecting: "disconnected",
|
|
15860
16269
|
disconnected: "disconnected"
|
|
15861
16270
|
};
|
|
16271
|
+
SLACK_SOCKET_WATCHDOG_DEFAULTS = {
|
|
16272
|
+
tickMs: 5000,
|
|
16273
|
+
downAfterMs: 60000,
|
|
16274
|
+
staleActivityMs: 10 * 60000,
|
|
16275
|
+
backoffBaseMs: 30000,
|
|
16276
|
+
backoffMaxMs: 5 * 60000,
|
|
16277
|
+
restartTimeoutMs: 2 * 60000,
|
|
16278
|
+
stopLockWaitMs: 1e4
|
|
16279
|
+
};
|
|
16280
|
+
watchdogOptions = SLACK_SOCKET_WATCHDOG_DEFAULTS;
|
|
15862
16281
|
});
|
|
15863
16282
|
|
|
15864
|
-
export { require_dist4, require_dist5, getSlackConnectionState, init_connection_state, noteSlackInboundSideEffect, ignoreSlackInbound, reportSlackInboundFailure, isAdmittedSlackDelivery, getSlackInboundDiagnostics, init_inbound_dispatch, terminalReactionEvent, init_reaction_events, isPollTracingEnabled, initOtel, withSpan2, startSpan2, withSpanContext2, withRemoteContext2, injectTraceContext2, recordSessionCost2, recordDbRetentionSweep2, recordDbRetentionStatement2, init_otel, slackTaskOutput, init_task_output, ackSlackMessage, skipSlackMessageReaction, finalizeTerminalSlackReactions, init_ack, getTaskLink, getTaskUrl, markdownToSlack, buildMrkdwnSectionBlocks, buildCaptionBlock, buildCancelledBlocks, buildBufferFlushBlocks, buildTreeBlocks, init_blocks, taskCitationIssues, stripInvalidTaskCitations, taskCitationSourceGroups, renderTaskCitations, taskCitationWarnings, init_task_citations, MAX_TASK_CITATIONS, CitationInputSchema, TaskCitationSchema, upsertTaskCitations, getTaskCitations, getTaskCitationsForTasks, hasTaskCitationCheckRefusal, init_task_citations2, initialize, ensure, init_business_use, getAgentDisplayName, getAgentSlackIcon, init_responses, markSlackSessionProcessing, init_session_status, isSlackRenderV2Enabled2, callSlackWithRetry2, ensureSlackThreadTree2, slackErrorCode2, processSlackRenderV22, init_render_v2, registerTreeMessage, init_watcher, getSlackApp2, initSlackApp2, startSlackApp2, stopSlackApp2, init_app3 };
|
|
16283
|
+
export { require_dist4, require_dist5, getSlackConnectionState, init_connection_state, noteSlackInboundSideEffect, ignoreSlackInbound, reportSlackInboundFailure, isAdmittedSlackDelivery, getSlackInboundDiagnostics, init_inbound_dispatch, runSlackLifecycleExclusive, init_lifecycle_lock, terminalReactionEvent, init_reaction_events, isPollTracingEnabled, initOtel, withSpan2, startSpan2, withSpanContext2, withRemoteContext2, injectTraceContext2, recordSessionCost2, recordDbRetentionSweep2, recordDbRetentionStatement2, init_otel, slackTaskOutput, init_task_output, ackSlackMessage, skipSlackMessageReaction, finalizeTerminalSlackReactions, init_ack, getTaskLink, getTaskUrl, markdownToSlack, buildMrkdwnSectionBlocks, buildCaptionBlock, buildCancelledBlocks, buildBufferFlushBlocks, buildTreeBlocks, init_blocks, taskCitationIssues, stripInvalidTaskCitations, taskCitationSourceGroups, renderTaskCitations, taskCitationWarnings, init_task_citations, MAX_TASK_CITATIONS, CitationInputSchema, TaskCitationSchema, upsertTaskCitations, getTaskCitations, getTaskCitationsForTasks, hasTaskCitationCheckRefusal, init_task_citations2, initialize, ensure, init_business_use, getAgentDisplayName, getAgentSlackIcon, init_responses, markSlackSessionProcessing, init_session_status, isSlackRenderV2Enabled2, callSlackWithRetry2, ensureSlackThreadTree2, slackErrorCode2, startSlackRenderV2Events2, stopSlackRenderV2Events2, processSlackRenderV22, init_render_v2, registerTreeMessage, init_watcher, getSlackApp2, initSlackApp2, startSlackApp2, stopSlackApp2, stopSlackAppUnderLifecycleLock2, init_app3 };
|