@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
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/** Runs inside QuickJS, before user code; cloned values never cross the host bridge. */
|
|
2
|
+
export const SANDBOX_STRUCTURED_CLONE = `(() => {
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
// Capture intrinsics before a script can replace methods, constructors or accessors.
|
|
6
|
+
const uncurry = (fn) => Function.prototype.call.bind(fn);
|
|
7
|
+
const descriptor = Object.getOwnPropertyDescriptor;
|
|
8
|
+
const define = Object.defineProperty;
|
|
9
|
+
const keys = Object.keys;
|
|
10
|
+
const hasOwn = uncurry(Object.prototype.hasOwnProperty);
|
|
11
|
+
const isArray = Array.isArray;
|
|
12
|
+
const isView = ArrayBuffer.isView;
|
|
13
|
+
const isError = Error.isError;
|
|
14
|
+
const instanceOf = uncurry(Function.prototype[Symbol.hasInstance]);
|
|
15
|
+
const NativeObject = Object;
|
|
16
|
+
const NativeArray = Array;
|
|
17
|
+
const NativeError = Error;
|
|
18
|
+
const NativeTypeError = TypeError;
|
|
19
|
+
const NativeMap = Map;
|
|
20
|
+
const NativeSet = Set;
|
|
21
|
+
const NativeWeakMap = WeakMap;
|
|
22
|
+
const NativeArrayBuffer = ArrayBuffer;
|
|
23
|
+
const NativeUint8Array = Uint8Array;
|
|
24
|
+
const NativeDataView = DataView;
|
|
25
|
+
const NativeDate = Date;
|
|
26
|
+
const NativeRegExp = RegExp;
|
|
27
|
+
const regexpPrototype = RegExp.prototype;
|
|
28
|
+
const toString = String;
|
|
29
|
+
const mapHas = uncurry(Map.prototype.has);
|
|
30
|
+
const mapSet = uncurry(Map.prototype.set);
|
|
31
|
+
const mapForEach = uncurry(Map.prototype.forEach);
|
|
32
|
+
const setHas = uncurry(Set.prototype.has);
|
|
33
|
+
const setAdd = uncurry(Set.prototype.add);
|
|
34
|
+
const setForEach = uncurry(Set.prototype.forEach);
|
|
35
|
+
const memoHas = uncurry(WeakMap.prototype.has);
|
|
36
|
+
const memoGet = uncurry(WeakMap.prototype.get);
|
|
37
|
+
const memoSet = uncurry(WeakMap.prototype.set);
|
|
38
|
+
const dateValue = uncurry(Date.prototype.getTime);
|
|
39
|
+
const regexpSource = uncurry(descriptor(RegExp.prototype, "source").get);
|
|
40
|
+
const bufferLength = uncurry(descriptor(ArrayBuffer.prototype, "byteLength").get);
|
|
41
|
+
const bufferResizable = uncurry(descriptor(ArrayBuffer.prototype, "resizable").get);
|
|
42
|
+
const dataBuffer = uncurry(descriptor(DataView.prototype, "buffer").get);
|
|
43
|
+
const dataOffset = uncurry(descriptor(DataView.prototype, "byteOffset").get);
|
|
44
|
+
const dataLength = uncurry(descriptor(DataView.prototype, "byteLength").get);
|
|
45
|
+
const typedPrototype = Object.getPrototypeOf(Uint8Array.prototype);
|
|
46
|
+
const typedName = uncurry(descriptor(typedPrototype, Symbol.toStringTag).get);
|
|
47
|
+
const typedBuffer = uncurry(descriptor(typedPrototype, "buffer").get);
|
|
48
|
+
const typedOffset = uncurry(descriptor(typedPrototype, "byteOffset").get);
|
|
49
|
+
const typedLength = uncurry(descriptor(typedPrototype, "length").get);
|
|
50
|
+
const typedValues = uncurry(typedPrototype.values);
|
|
51
|
+
const setBytes = uncurry(Uint8Array.prototype.set);
|
|
52
|
+
const errorTypes = { Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError };
|
|
53
|
+
const viewTypes = {
|
|
54
|
+
Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array,
|
|
55
|
+
Uint32Array, Float16Array, Float32Array, Float64Array, BigInt64Array, BigUint64Array,
|
|
56
|
+
};
|
|
57
|
+
const boxedValues = [Boolean, Number, String, BigInt, Symbol].map(Type => uncurry(Type.prototype.valueOf));
|
|
58
|
+
const regexpFlags = [
|
|
59
|
+
["hasIndices", "d"], ["global", "g"], ["ignoreCase", "i"], ["multiline", "m"],
|
|
60
|
+
["dotAll", "s"], ["unicode", "u"], ["unicodeSets", "v"], ["sticky", "y"],
|
|
61
|
+
].map(([name, flag]) => [uncurry(descriptor(RegExp.prototype, name).get), flag]);
|
|
62
|
+
const unsupportedTypes = [Promise, WeakMap, WeakSet, WeakRef, FinalizationRegistry, SharedArrayBuffer];
|
|
63
|
+
const brandKey = {};
|
|
64
|
+
const noBrand = {};
|
|
65
|
+
const probe = (read, value) => {
|
|
66
|
+
try { return read(value); } catch { return noBrand; }
|
|
67
|
+
};
|
|
68
|
+
const fail = (message = "Value cannot be cloned") => {
|
|
69
|
+
const error = new NativeError(message);
|
|
70
|
+
error.name = "DataCloneError";
|
|
71
|
+
throw error;
|
|
72
|
+
};
|
|
73
|
+
const property = (target, key, value) => define(target, key, {
|
|
74
|
+
value, enumerable: true, writable: true, configurable: true,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
function structuredClone(value, options) {
|
|
78
|
+
if (arguments.length === 0) throw new NativeTypeError("structuredClone requires a value");
|
|
79
|
+
// QuickJS has no transferable host objects. Reject rather than silently ignoring detachment.
|
|
80
|
+
const transfer = options == null ? undefined : options.transfer;
|
|
81
|
+
if (transfer !== undefined) {
|
|
82
|
+
for (const entry of transfer) fail("quickjs structuredClone does not support transfers");
|
|
83
|
+
}
|
|
84
|
+
const memory = new NativeWeakMap();
|
|
85
|
+
const remember = (source, target) => { memoSet(memory, source, target); return target; };
|
|
86
|
+
const clone = (source) => {
|
|
87
|
+
const type = typeof source;
|
|
88
|
+
if (type === "symbol" || type === "function") return fail();
|
|
89
|
+
if (source === null || type !== "object") return source;
|
|
90
|
+
if (memoHas(memory, source)) return memoGet(memory, source);
|
|
91
|
+
|
|
92
|
+
if (isView(source)) {
|
|
93
|
+
const name = typedName(source);
|
|
94
|
+
if (name !== undefined) {
|
|
95
|
+
// The intrinsic rejects detached or out-of-bounds views; property getters may lie.
|
|
96
|
+
try { typedValues(source); } catch { return fail(); }
|
|
97
|
+
return remember(source, new viewTypes[name](clone(typedBuffer(source)), typedOffset(source), typedLength(source)));
|
|
98
|
+
}
|
|
99
|
+
let buffer, offset, length;
|
|
100
|
+
try { buffer = dataBuffer(source); offset = dataOffset(source); length = dataLength(source); }
|
|
101
|
+
catch { return fail(); }
|
|
102
|
+
return remember(source, new NativeDataView(clone(buffer), offset, length));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const byteLength = probe(bufferLength, source);
|
|
106
|
+
if (byteLength !== noBrand) {
|
|
107
|
+
let bytes;
|
|
108
|
+
try { bytes = new NativeUint8Array(source); } catch { return fail(); }
|
|
109
|
+
// JS cannot recover whether a view over a resizable buffer tracks its length.
|
|
110
|
+
if (bufferResizable(source)) return fail("quickjs structuredClone does not support resizable buffers");
|
|
111
|
+
const target = new NativeArrayBuffer(byteLength);
|
|
112
|
+
setBytes(new NativeUint8Array(target), bytes);
|
|
113
|
+
return remember(source, target);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (isError(source)) {
|
|
117
|
+
const name = source.name;
|
|
118
|
+
const Type = typeof name === "string" && hasOwn(errorTypes, name) ? errorTypes[name] : NativeError;
|
|
119
|
+
const target = remember(source, new Type());
|
|
120
|
+
const message = descriptor(source, "message");
|
|
121
|
+
if (message && hasOwn(message, "value")) {
|
|
122
|
+
if (typeof message.value === "symbol") throw new NativeTypeError("Cannot convert a Symbol value to a string");
|
|
123
|
+
define(target, "message", { value: toString(message.value), writable: true, configurable: true });
|
|
124
|
+
}
|
|
125
|
+
const stack = descriptor(source, "stack");
|
|
126
|
+
if (stack && typeof stack.value === "string") {
|
|
127
|
+
define(target, "stack", { value: stack.value, writable: true, configurable: true });
|
|
128
|
+
}
|
|
129
|
+
return target;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (probe((value) => mapHas(value, brandKey), source) !== noBrand) {
|
|
133
|
+
const target = remember(source, new NativeMap());
|
|
134
|
+
// Snapshot entries before cloning any value: getters can mutate the original collection.
|
|
135
|
+
const entries = [];
|
|
136
|
+
mapForEach(source, (value, key) => { entries[entries.length] = [key, value]; });
|
|
137
|
+
for (let i = 0; i < entries.length; i++) mapSet(target, clone(entries[i][0]), clone(entries[i][1]));
|
|
138
|
+
return target;
|
|
139
|
+
}
|
|
140
|
+
if (probe((value) => setHas(value, brandKey), source) !== noBrand) {
|
|
141
|
+
const target = remember(source, new NativeSet());
|
|
142
|
+
const entries = [];
|
|
143
|
+
setForEach(source, value => { entries[entries.length] = value; });
|
|
144
|
+
for (let i = 0; i < entries.length; i++) setAdd(target, clone(entries[i]));
|
|
145
|
+
return target;
|
|
146
|
+
}
|
|
147
|
+
const time = probe(dateValue, source);
|
|
148
|
+
if (time !== noBrand) return remember(source, new NativeDate(time));
|
|
149
|
+
const pattern = source === regexpPrototype ? noBrand : probe(regexpSource, source);
|
|
150
|
+
if (pattern !== noBrand) {
|
|
151
|
+
let flags = "";
|
|
152
|
+
for (let i = 0; i < regexpFlags.length; i++) {
|
|
153
|
+
if (regexpFlags[i][0](source)) flags += regexpFlags[i][1];
|
|
154
|
+
}
|
|
155
|
+
return remember(source, new NativeRegExp(pattern, flags));
|
|
156
|
+
}
|
|
157
|
+
for (let i = 0; i < boxedValues.length; i++) {
|
|
158
|
+
const primitive = probe(boxedValues[i], source);
|
|
159
|
+
if (primitive !== noBrand) {
|
|
160
|
+
if (typeof primitive === "symbol") return fail();
|
|
161
|
+
return remember(source, NativeObject(primitive));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
for (let i = 0; i < unsupportedTypes.length; i++) {
|
|
165
|
+
if (instanceOf(unsupportedTypes[i], source)) return fail();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const target = remember(source, isArray(source) ? new NativeArray(source.length) : {});
|
|
169
|
+
const names = keys(source);
|
|
170
|
+
for (let i = 0; i < names.length; i++) {
|
|
171
|
+
const name = names[i];
|
|
172
|
+
// A prior getter can delete a later property. Symbol keys are never read.
|
|
173
|
+
if (hasOwn(source, name)) property(target, name, clone(source[name]));
|
|
174
|
+
}
|
|
175
|
+
return target;
|
|
176
|
+
};
|
|
177
|
+
return clone(value);
|
|
178
|
+
}
|
|
179
|
+
define(globalThis, "structuredClone", { value: structuredClone, writable: true, configurable: true });
|
|
180
|
+
})();`;
|
|
@@ -52,7 +52,6 @@ const UNSUPPORTED_GLOBALS = new Set([
|
|
|
52
52
|
"performance",
|
|
53
53
|
"queueMicrotask",
|
|
54
54
|
"setImmediate",
|
|
55
|
-
"structuredClone",
|
|
56
55
|
]);
|
|
57
56
|
const RESPONSE_BODY_METHODS = new Set(["arrayBuffer", "blob", "formData", "bytes"]);
|
|
58
57
|
const LOCALE_METHODS = new Set(["toLocaleString", "toLocaleDateString", "toLocaleTimeString"]);
|
package/src/slack/app.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { App, LogLevel, SocketModeReceiver } from "@slack/bolt";
|
|
2
2
|
import { emitBuiltInIntegrationConnectedOnce, ensureSlackRenderV2Activation } from "../be/db";
|
|
3
3
|
import { getNodeEnv } from "../utils/node-env";
|
|
4
|
+
import { scrubSecrets } from "../utils/secret-scrubber";
|
|
4
5
|
import { getSlackConfiguration } from "./config";
|
|
5
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
getSlackConnectionState,
|
|
8
|
+
type SlackConnectionState,
|
|
9
|
+
setSlackConnectionState,
|
|
10
|
+
} from "./connection-state";
|
|
6
11
|
import { installSlackEgressScrub } from "./egress-scrub";
|
|
7
12
|
import { installSlackExternalChannelGuard } from "./external-channel-egress";
|
|
8
13
|
import { recoverSlackInboundAfterRestart, slackInboundOutcomeMiddleware } from "./inbound-dispatch";
|
|
14
|
+
import { isSlackLifecycleBusy, runSlackLifecycleExclusive } from "./lifecycle-lock";
|
|
9
15
|
import { installSocketAckRecovery } from "./socket-ack";
|
|
16
|
+
import { fenceSocketModeClient, type SlackSocketFence } from "./socket-fence";
|
|
10
17
|
import { getSlackSocketModeBlockReason, SLACK_DEV_SOCKET_MODE_OPT_IN } from "./socket-mode-guard";
|
|
11
18
|
import { startTaskWatcher, stopTaskWatcher } from "./watcher";
|
|
12
19
|
|
|
@@ -14,6 +21,14 @@ let app: App | null = null;
|
|
|
14
21
|
let receiver: SocketModeReceiver | null = null;
|
|
15
22
|
let initialized = false;
|
|
16
23
|
let inboundDrain: ReturnType<typeof installSocketAckRecovery> | null = null;
|
|
24
|
+
// Retires the current client at teardown, so a reconnect it still has in
|
|
25
|
+
// flight cannot open a socket next to the replacement.
|
|
26
|
+
let socketFence: SlackSocketFence | null = null;
|
|
27
|
+
// Bumped at each teardown. A start that sees a new generation was abandoned
|
|
28
|
+
// by the watchdog (or overtaken by a stop) and must not touch shared state.
|
|
29
|
+
let lifecycleGeneration = 0;
|
|
30
|
+
// Last sign of life on the current socket: Slack's hello or any envelope.
|
|
31
|
+
let lastSocketActivityAt: number | null = null;
|
|
17
32
|
|
|
18
33
|
const SOCKET_EVENT_STATES: Record<string, SlackConnectionState> = {
|
|
19
34
|
connecting: "connecting",
|
|
@@ -27,9 +42,240 @@ function trackConnectionState(owner: SocketModeReceiver): void {
|
|
|
27
42
|
for (const [event, state] of Object.entries(SOCKET_EVENT_STATES)) {
|
|
28
43
|
owner.client.on(event, () => {
|
|
29
44
|
// Ignore late events from a receiver that stopSlackApp() already replaced.
|
|
30
|
-
if (receiver
|
|
45
|
+
if (receiver !== owner) return;
|
|
46
|
+
setSlackConnectionState(state);
|
|
47
|
+
if (state === "connected") lastSocketActivityAt = Date.now();
|
|
31
48
|
});
|
|
32
49
|
}
|
|
50
|
+
owner.client.on("slack_event", () => {
|
|
51
|
+
if (receiver === owner) lastSocketActivityAt = Date.now();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ─── Socket watchdog ──────────────────────────────────────────────────────────
|
|
56
|
+
// @slack/socket-mode treats a RequestError/HTTPError from apps.connections.open
|
|
57
|
+
// as unrecoverable during a reconnect, and its reconnect promise has no catch.
|
|
58
|
+
// The client then stops retrying for good and the state sticks in
|
|
59
|
+
// `connecting`. Upstream will not fix it (slackapi/node-slack-sdk#2656), so the
|
|
60
|
+
// watchdog rebuilds the whole Slack app when the socket stays down.
|
|
61
|
+
|
|
62
|
+
export interface SlackSocketWatchdogOptions {
|
|
63
|
+
/** How often the watchdog checks the socket. */
|
|
64
|
+
tickMs: number;
|
|
65
|
+
/** How long the socket must be down before the first restart. */
|
|
66
|
+
downAfterMs: number;
|
|
67
|
+
/** With no hello or envelope for this long, a `connected` socket also needs `isActive()`. */
|
|
68
|
+
staleActivityMs: number;
|
|
69
|
+
/** Delay after the first restart; it doubles after each further attempt. */
|
|
70
|
+
backoffBaseMs: number;
|
|
71
|
+
/** Cap on the delay between restarts. */
|
|
72
|
+
backoffMaxMs: number;
|
|
73
|
+
/**
|
|
74
|
+
* Bound on one restart (teardown + start) under the lifecycle lock. A
|
|
75
|
+
* restart still running then is abandoned, so a config reload or a shutdown
|
|
76
|
+
* waiting on the lock gets it.
|
|
77
|
+
*/
|
|
78
|
+
restartTimeoutMs: number;
|
|
79
|
+
/**
|
|
80
|
+
* Bound on stopSlackApp()'s wait for the lifecycle lock. Shutdown must
|
|
81
|
+
* finish inside the pod's termination grace, which is shorter than
|
|
82
|
+
* `restartTimeoutMs`.
|
|
83
|
+
*/
|
|
84
|
+
stopLockWaitMs: number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const SLACK_SOCKET_WATCHDOG_DEFAULTS: SlackSocketWatchdogOptions = {
|
|
88
|
+
tickMs: 5_000,
|
|
89
|
+
downAfterMs: 60_000,
|
|
90
|
+
staleActivityMs: 10 * 60_000,
|
|
91
|
+
backoffBaseMs: 30_000,
|
|
92
|
+
backoffMaxMs: 5 * 60_000,
|
|
93
|
+
restartTimeoutMs: 2 * 60_000,
|
|
94
|
+
stopLockWaitMs: 10_000,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export interface SlackSocketWatchdogDeps {
|
|
98
|
+
now: () => number;
|
|
99
|
+
getState: () => SlackConnectionState;
|
|
100
|
+
/** Last hello or envelope on the current socket, in epoch ms. */
|
|
101
|
+
getLastActivityAt: () => number | null;
|
|
102
|
+
/** The socket-mode client's own view: is its websocket open? */
|
|
103
|
+
isSocketActive: () => boolean;
|
|
104
|
+
/** True while a config reload (or another restart) holds the Slack lifecycle lock. */
|
|
105
|
+
isLifecycleBusy: () => boolean;
|
|
106
|
+
restart: () => Promise<void>;
|
|
107
|
+
log: (line: string) => void;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface SlackSocketWatchdog {
|
|
111
|
+
tick: () => Promise<void>;
|
|
112
|
+
/** Restart attempts since the socket was last healthy. */
|
|
113
|
+
attempts: () => number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Delay before restart attempt `attempt + 1`: base * 2^(attempt-1), capped. */
|
|
117
|
+
export function slackWatchdogBackoffMs(
|
|
118
|
+
attempt: number,
|
|
119
|
+
options: SlackSocketWatchdogOptions,
|
|
120
|
+
): number {
|
|
121
|
+
return Math.min(options.backoffBaseMs * 2 ** Math.max(0, attempt - 1), options.backoffMaxMs);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The watchdog state machine, with no timers of its own: the caller drives
|
|
126
|
+
* `tick()`. Operators search the two log lines, so keep their
|
|
127
|
+
* text stable.
|
|
128
|
+
*/
|
|
129
|
+
export function createSlackSocketWatchdog(
|
|
130
|
+
deps: SlackSocketWatchdogDeps,
|
|
131
|
+
options: SlackSocketWatchdogOptions = SLACK_SOCKET_WATCHDOG_DEFAULTS,
|
|
132
|
+
): SlackSocketWatchdog {
|
|
133
|
+
let downSince: number | null = null;
|
|
134
|
+
let attempts = 0;
|
|
135
|
+
let nextAttemptAt = 0;
|
|
136
|
+
let restarting = false;
|
|
137
|
+
|
|
138
|
+
function isHealthy(now: number): boolean {
|
|
139
|
+
if (deps.getState() !== "connected") return false;
|
|
140
|
+
// A quiet night is normal. Only a quiet socket that the client itself
|
|
141
|
+
// reports as closed counts as down.
|
|
142
|
+
const lastActivityAt = deps.getLastActivityAt();
|
|
143
|
+
if (lastActivityAt === null || now - lastActivityAt < options.staleActivityMs) return true;
|
|
144
|
+
return deps.isSocketActive();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function tick(): Promise<void> {
|
|
148
|
+
if (restarting || deps.isLifecycleBusy()) return;
|
|
149
|
+
const now = deps.now();
|
|
150
|
+
if (isHealthy(now)) {
|
|
151
|
+
if (attempts > 0 && downSince !== null) {
|
|
152
|
+
deps.log(`[Slack] watchdog: recovered after ${seconds(now - downSince)}s`);
|
|
153
|
+
}
|
|
154
|
+
downSince = null;
|
|
155
|
+
attempts = 0;
|
|
156
|
+
nextAttemptAt = 0;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
downSince ??= now;
|
|
160
|
+
if (now - downSince < options.downAfterMs || now < nextAttemptAt) return;
|
|
161
|
+
attempts += 1;
|
|
162
|
+
nextAttemptAt = now + slackWatchdogBackoffMs(attempts, options);
|
|
163
|
+
deps.log(
|
|
164
|
+
`[Slack] watchdog: socket down for ${seconds(now - downSince)}s, restarting (attempt ${attempts})`,
|
|
165
|
+
);
|
|
166
|
+
restarting = true;
|
|
167
|
+
try {
|
|
168
|
+
await deps.restart();
|
|
169
|
+
} catch (error) {
|
|
170
|
+
// The error can carry request config or a token; scrub before it leaves.
|
|
171
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
172
|
+
console.error(`[Slack] watchdog: restart failed: ${scrubSecrets(message)}`);
|
|
173
|
+
} finally {
|
|
174
|
+
restarting = false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return { tick, attempts: () => attempts };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function seconds(ms: number): number {
|
|
182
|
+
return Math.round(ms / 1000);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function isLiveSocketActive(): boolean {
|
|
186
|
+
return receiver?.client.websocket?.isActive() ?? false;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
let watchdogTimer: ReturnType<typeof setInterval> | null = null;
|
|
190
|
+
let watchdogOptions: SlackSocketWatchdogOptions = SLACK_SOCKET_WATCHDOG_DEFAULTS;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Rebuild the Slack app under the lifecycle lock, bounded by
|
|
194
|
+
* `restartTimeoutMs`. The web client can retry apps.connections.open for many
|
|
195
|
+
* minutes, and every config reload waits on the lock meanwhile. A restart
|
|
196
|
+
* that runs out of time is abandoned: its client is retired first, so it can
|
|
197
|
+
* never open a socket later, and the watchdog tries again after its backoff.
|
|
198
|
+
*/
|
|
199
|
+
async function restartSlackAppForWatchdog(owner: ReturnType<typeof setInterval>): Promise<void> {
|
|
200
|
+
await runSlackLifecycleExclusive(async () => {
|
|
201
|
+
// stopSlackApp() won the lock first and disarmed this watchdog (shutdown,
|
|
202
|
+
// or a reload that armed a new one). Restarting now would bring back an
|
|
203
|
+
// app that the caller already stopped.
|
|
204
|
+
if (watchdogTimer !== owner) return;
|
|
205
|
+
// A config reload that won the lock may have just brought the socket back.
|
|
206
|
+
if (getSlackConnectionState() === "connected" && isLiveSocketActive()) return;
|
|
207
|
+
let abandoned = false;
|
|
208
|
+
const restart = (async () => {
|
|
209
|
+
await teardownSlackApp();
|
|
210
|
+
// A teardown that outlived the timeout must not start an app outside the
|
|
211
|
+
// lock, and one that a forced stopSlackApp() disarmed must not start one at all.
|
|
212
|
+
if (!abandoned && watchdogTimer === owner) await startSlackApp();
|
|
213
|
+
})();
|
|
214
|
+
const timeoutMs = watchdogOptions.restartTimeoutMs;
|
|
215
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
216
|
+
const timedOut = new Promise<true>((resolve) => {
|
|
217
|
+
timer = setTimeout(() => resolve(true), timeoutMs);
|
|
218
|
+
});
|
|
219
|
+
try {
|
|
220
|
+
const outcome = await Promise.race([restart.then(() => false as const), timedOut]);
|
|
221
|
+
if (!outcome) return;
|
|
222
|
+
} finally {
|
|
223
|
+
clearTimeout(timer);
|
|
224
|
+
}
|
|
225
|
+
abandoned = true;
|
|
226
|
+
// The abandoned restart settles later, if ever; its error is no longer news.
|
|
227
|
+
void restart.catch(() => {});
|
|
228
|
+
abandonSlackApp();
|
|
229
|
+
throw new Error(`restart did not finish within ${seconds(timeoutMs)}s; abandoned it`);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function startSocketWatchdog(): void {
|
|
234
|
+
if (watchdogTimer) return;
|
|
235
|
+
let timer: ReturnType<typeof setInterval> | null = null;
|
|
236
|
+
const watchdog = createSlackSocketWatchdog(
|
|
237
|
+
{
|
|
238
|
+
now: Date.now,
|
|
239
|
+
getState: getSlackConnectionState,
|
|
240
|
+
getLastActivityAt: () => lastSocketActivityAt,
|
|
241
|
+
isSocketActive: isLiveSocketActive,
|
|
242
|
+
isLifecycleBusy: isSlackLifecycleBusy,
|
|
243
|
+
restart: () => (timer ? restartSlackAppForWatchdog(timer) : Promise.resolve()),
|
|
244
|
+
log: (line) => console.log(line),
|
|
245
|
+
},
|
|
246
|
+
watchdogOptions,
|
|
247
|
+
);
|
|
248
|
+
timer = setInterval(() => {
|
|
249
|
+
if (getSlackConfiguration().mode !== "socket") {
|
|
250
|
+
stopSocketWatchdog();
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
void watchdog.tick();
|
|
254
|
+
}, watchdogOptions.tickMs);
|
|
255
|
+
// Never keep the process (or a test run) alive for the watchdog alone.
|
|
256
|
+
timer.unref?.();
|
|
257
|
+
watchdogTimer = timer;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function stopSocketWatchdog(): void {
|
|
261
|
+
if (watchdogTimer) clearInterval(watchdogTimer);
|
|
262
|
+
watchdogTimer = null;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Test hook: shorter thresholds for the next watchdog start. Pass nothing to reset. */
|
|
266
|
+
export function _setSlackSocketWatchdogOptionsForTests(
|
|
267
|
+
options?: Partial<SlackSocketWatchdogOptions>,
|
|
268
|
+
): void {
|
|
269
|
+
watchdogOptions = { ...SLACK_SOCKET_WATCHDOG_DEFAULTS, ...options };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** Test hook: the live socket-mode client, to inject reconnect faults. */
|
|
273
|
+
export function _getSlackSocketClientForTests(): SocketModeReceiver["client"] | null {
|
|
274
|
+
return receiver?.client ?? null;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function isSlackSocketWatchdogRunning(): boolean {
|
|
278
|
+
return watchdogTimer !== null;
|
|
33
279
|
}
|
|
34
280
|
|
|
35
281
|
export function getSlackApp(): App | null {
|
|
@@ -99,6 +345,7 @@ export async function initSlackApp(): Promise<App | null> {
|
|
|
99
345
|
installerOptions: clientOptions ? { clientOptions } : {},
|
|
100
346
|
});
|
|
101
347
|
trackConnectionState(receiver);
|
|
348
|
+
socketFence = fenceSocketModeClient(receiver.client);
|
|
102
349
|
app = new App({
|
|
103
350
|
token: botToken,
|
|
104
351
|
receiver,
|
|
@@ -145,21 +392,31 @@ export async function initSlackApp(): Promise<App | null> {
|
|
|
145
392
|
}
|
|
146
393
|
|
|
147
394
|
export async function startSlackApp(): Promise<boolean> {
|
|
395
|
+
const generation = lifecycleGeneration;
|
|
148
396
|
if (!app) {
|
|
149
397
|
await initSlackApp();
|
|
150
398
|
}
|
|
151
399
|
|
|
152
|
-
|
|
400
|
+
const current = app;
|
|
401
|
+
if (current && generation === lifecycleGeneration) {
|
|
402
|
+
// Arm before app.start(): a start that throws is retried by the watchdog.
|
|
403
|
+
startSocketWatchdog();
|
|
153
404
|
// Establish the durable cutoff before Socket Mode can deliver new asks.
|
|
154
405
|
const { isSlackRenderV2Enabled } = await import("./render-v2");
|
|
155
406
|
if (isSlackRenderV2Enabled()) await ensureSlackRenderV2Activation();
|
|
156
407
|
// Receipts stored before the last restart: interrupted ones turn uncertain,
|
|
157
408
|
// pending ones are processed once the app can dispatch them.
|
|
158
409
|
await recoverSlackInboundAfterRestart();
|
|
159
|
-
|
|
410
|
+
if (generation !== lifecycleGeneration) return false;
|
|
411
|
+
await current.start();
|
|
412
|
+
// Abandoned while it waited: the app was already detached and retired.
|
|
413
|
+
if (generation !== lifecycleGeneration) return false;
|
|
160
414
|
console.log("[Slack] Bot connected via Socket Mode");
|
|
161
415
|
void inboundDrain?.wake();
|
|
162
416
|
await emitBuiltInIntegrationConnectedOnce("slack");
|
|
417
|
+
// Abandoned or stopped while telemetry was pending: a watcher started now
|
|
418
|
+
// would outlive the stop and leak its timer.
|
|
419
|
+
if (generation !== lifecycleGeneration) return false;
|
|
163
420
|
|
|
164
421
|
// Start watching for task completions
|
|
165
422
|
await startTaskWatcher();
|
|
@@ -169,17 +426,82 @@ export async function startSlackApp(): Promise<boolean> {
|
|
|
169
426
|
return false;
|
|
170
427
|
}
|
|
171
428
|
|
|
429
|
+
/**
|
|
430
|
+
* Stop the app and disarm the watchdog. Takes the Slack lifecycle lock, so a
|
|
431
|
+
* watchdog restart in flight finishes first and cannot bring the app back
|
|
432
|
+
* after this returns. The wait for the lock is bounded by `stopLockWaitMs`:
|
|
433
|
+
* after that, the stop disarms the watchdog and drops the app without the
|
|
434
|
+
* lock, and stops again once the lock frees.
|
|
435
|
+
*/
|
|
172
436
|
export async function stopSlackApp(): Promise<void> {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
437
|
+
const locked = runSlackLifecycleExclusive(stopSlackAppUnderLifecycleLock);
|
|
438
|
+
const waitMs = watchdogOptions.stopLockWaitMs;
|
|
439
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
440
|
+
const timedOut = new Promise<true>((resolve) => {
|
|
441
|
+
timer = setTimeout(() => resolve(true), waitMs);
|
|
442
|
+
});
|
|
443
|
+
try {
|
|
444
|
+
const outcome = await Promise.race([locked.then(() => false as const), timedOut]);
|
|
445
|
+
if (!outcome) return;
|
|
446
|
+
} finally {
|
|
447
|
+
clearTimeout(timer);
|
|
448
|
+
}
|
|
449
|
+
// The late stop under the lock still runs; its error is no longer news.
|
|
450
|
+
void locked.catch(() => {});
|
|
451
|
+
console.error(
|
|
452
|
+
`[Slack] stop: lifecycle lock still held after ${seconds(waitMs)}s; stopping without it`,
|
|
453
|
+
);
|
|
454
|
+
// The restart holding the lock sees the disarmed watchdog and starts nothing.
|
|
455
|
+
stopSocketWatchdog();
|
|
456
|
+
abandonSlackApp();
|
|
457
|
+
}
|
|
176
458
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
459
|
+
/**
|
|
460
|
+
* stopSlackApp() for a caller that already holds the lifecycle lock (the
|
|
461
|
+
* config reload). The lock is not reentrant: taking it again would deadlock.
|
|
462
|
+
*/
|
|
463
|
+
export async function stopSlackAppUnderLifecycleLock(): Promise<void> {
|
|
464
|
+
stopSocketWatchdog();
|
|
465
|
+
await teardownSlackApp();
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/** Stop the app but keep the watchdog armed; the watchdog restart uses this. */
|
|
469
|
+
async function teardownSlackApp(): Promise<void> {
|
|
470
|
+
const stopping = detachSlackApp();
|
|
471
|
+
if (stopping) {
|
|
472
|
+
await stopping.stop();
|
|
180
473
|
console.log("[Slack] Bot disconnected");
|
|
181
474
|
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Drop a restart that ran out of time, without waiting: app.stop() can block
|
|
479
|
+
* on the stalled client too. The retired client opens no socket, and the
|
|
480
|
+
* detached stop closes any socket it already has.
|
|
481
|
+
*/
|
|
482
|
+
function abandonSlackApp(): void {
|
|
483
|
+
const stalled = detachSlackApp();
|
|
484
|
+
void stalled?.stop().catch((error: unknown) => {
|
|
485
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
486
|
+
console.error(`[Slack] watchdog: stopping the abandoned app failed: ${scrubSecrets(message)}`);
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/** Clear the module state synchronously and return the app to stop. */
|
|
491
|
+
function detachSlackApp(): App | null {
|
|
492
|
+
// Retire the client first: app.stop() cannot cancel a start that is still
|
|
493
|
+
// waiting for apps.connections.open.
|
|
494
|
+
socketFence?.retire();
|
|
495
|
+
socketFence = null;
|
|
496
|
+
lifecycleGeneration += 1;
|
|
497
|
+
stopTaskWatcher();
|
|
498
|
+
inboundDrain?.stop();
|
|
499
|
+
inboundDrain = null;
|
|
500
|
+
const detached = app;
|
|
501
|
+
app = null;
|
|
182
502
|
receiver = null;
|
|
503
|
+
lastSocketActivityAt = null;
|
|
183
504
|
setSlackConnectionState("disconnected");
|
|
184
505
|
initialized = false;
|
|
506
|
+
return detached;
|
|
185
507
|
}
|
package/src/slack/handlers.ts
CHANGED
|
@@ -187,6 +187,7 @@ interface MessageEvent {
|
|
|
187
187
|
channel: string;
|
|
188
188
|
ts: string;
|
|
189
189
|
thread_ts?: string;
|
|
190
|
+
channel_type?: string;
|
|
190
191
|
files?: SlackFile[];
|
|
191
192
|
assistant_thread?: Record<string, unknown>;
|
|
192
193
|
}
|
|
@@ -572,11 +573,17 @@ export function registerMessageHandler(app: App): void {
|
|
|
572
573
|
// those — file uploads included — are handled in assistant.ts. An assistant-thread
|
|
573
574
|
// message that still lands here is treated as an implicit mention so it routes to
|
|
574
575
|
// the lead agent rather than being silently dropped.
|
|
576
|
+
// A top-level message in a 1:1 DM with the bot is addressed to the bot too: it has no
|
|
577
|
+
// `thread_ts`, so the Assistant middleware lets it through to this handler. Group DMs
|
|
578
|
+
// (`mpim`) and DM thread replies keep their existing rules.
|
|
575
579
|
// Guard: suppress implicit mention when the message @-mentions someone else but NOT us —
|
|
576
580
|
// those messages are addressed to a different agent/user (e.g. Devin) and must not spawn.
|
|
577
581
|
const isAssistantThread = !!msg.assistant_thread;
|
|
582
|
+
const isTopLevelDirectMessage = msg.channel_type === "im" && !msg.thread_ts;
|
|
578
583
|
const isImplicitMention =
|
|
579
|
-
isAssistantThread
|
|
584
|
+
(isAssistantThread || isTopLevelDirectMessage) &&
|
|
585
|
+
!botMentioned &&
|
|
586
|
+
!isAddressedToOtherUser(effectiveText, botUserId);
|
|
580
587
|
|
|
581
588
|
// ADDITIVE_SLACK: Check for !now command in threads
|
|
582
589
|
const additiveSlack = isEnvFlagEnabled("ADDITIVE_SLACK", false);
|
|
@@ -749,7 +756,7 @@ export function registerMessageHandler(app: App): void {
|
|
|
749
756
|
if (matches.length === 0) {
|
|
750
757
|
if (!botMentioned && !isImplicitMention) return ignoreSlackInbound("not_addressed");
|
|
751
758
|
|
|
752
|
-
// Bot was mentioned (or
|
|
759
|
+
// Bot was mentioned (or implicitly addressed) but no online agents matched — queue the request
|
|
753
760
|
if (!checkRateLimit(msg.user)) {
|
|
754
761
|
if (!isSlackRenderV2Enabled()) {
|
|
755
762
|
await say({
|
package/src/slack/index.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
getSlackApp,
|
|
3
|
+
initSlackApp,
|
|
4
|
+
startSlackApp,
|
|
5
|
+
stopSlackApp,
|
|
6
|
+
stopSlackAppUnderLifecycleLock,
|
|
7
|
+
} from "./app";
|
|
2
8
|
export type {
|
|
3
9
|
DownloadFileOptions,
|
|
4
10
|
DownloadFileResult,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One mutex for every path that tears down and rebuilds the Slack app: the
|
|
3
|
+
* config reload in `http/core.ts` and the socket watchdog in `app.ts`. A leaf
|
|
4
|
+
* module, because `http/core.ts` imports `app.ts` (an import back would cycle).
|
|
5
|
+
*/
|
|
6
|
+
let tail: Promise<void> = Promise.resolve();
|
|
7
|
+
let holders = 0;
|
|
8
|
+
|
|
9
|
+
/** Run `fn` after every earlier holder has finished. */
|
|
10
|
+
export async function runSlackLifecycleExclusive<T>(fn: () => Promise<T>): Promise<T> {
|
|
11
|
+
holders += 1;
|
|
12
|
+
const previous = tail;
|
|
13
|
+
let release!: () => void;
|
|
14
|
+
tail = new Promise<void>((resolve) => {
|
|
15
|
+
release = resolve;
|
|
16
|
+
});
|
|
17
|
+
try {
|
|
18
|
+
await previous;
|
|
19
|
+
return await fn();
|
|
20
|
+
} finally {
|
|
21
|
+
holders -= 1;
|
|
22
|
+
release();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** True while a holder runs or waits. The watchdog skips its tick then. */
|
|
27
|
+
export function isSlackLifecycleBusy(): boolean {
|
|
28
|
+
return holders > 0;
|
|
29
|
+
}
|