@sentry/junior 0.202.0 → 0.204.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/dist/agent-CMyTD4DD.js +17509 -0
  2. package/dist/agent-hooks-Bbcp9e33.js +4040 -0
  3. package/dist/agent-runner-DNb1A49M.js +678 -0
  4. package/dist/api/schema.d.ts +2728 -2639
  5. package/dist/api/schema.js +4 -169
  6. package/dist/api.d.ts +23 -17
  7. package/dist/api.js +3881 -5326
  8. package/dist/app-B1TOqBI8.d.ts +246 -0
  9. package/dist/app.d.ts +4 -520
  10. package/dist/app.js +9522 -11875
  11. package/dist/auth-pause-state-DosEalIG.js +168 -0
  12. package/dist/catalog-runtime-BReos-D4.js +7 -0
  13. package/dist/checkpoint-CNrPyRJN.js +2450 -0
  14. package/dist/cli/chat.d.ts +20 -0
  15. package/dist/cli/chat.js +229 -336
  16. package/dist/cli/check.d.ts +8 -0
  17. package/dist/cli/check.js +513 -806
  18. package/dist/cli/env.d.ts +13 -0
  19. package/dist/cli/env.js +63 -12
  20. package/dist/cli/init.d.ts +3 -0
  21. package/dist/cli/init.js +90 -159
  22. package/dist/cli/main.d.ts +6 -0
  23. package/dist/cli/main.js +43 -64
  24. package/dist/cli/plugins.d.ts +13 -0
  25. package/dist/cli/plugins.js +148 -227
  26. package/dist/cli/run.d.ts +16 -0
  27. package/dist/cli/run.js +52 -8
  28. package/dist/cli/snapshot-create.d.ts +4 -0
  29. package/dist/cli/snapshot-create.js +71 -125
  30. package/dist/cli/upgrade.d.ts +15 -0
  31. package/dist/cli/upgrade.js +232 -335
  32. package/dist/config-nGCW1OTG.js +941 -0
  33. package/dist/context-B45_WqVX.js +298 -0
  34. package/dist/conversation-privacy-B4voFRSm.js +182 -0
  35. package/dist/conversation-work-C6y3T5Hx.js +51 -0
  36. package/dist/credential-sync-kXr1hvO1.js +2660 -0
  37. package/dist/db-BeyXKJOI.d.ts +5 -0
  38. package/dist/destinations-BeBiJeEM.js +29 -0
  39. package/dist/execution-stats-DWfSihcH.js +373 -0
  40. package/dist/executor-DcMSlI5c.js +721 -0
  41. package/dist/experimental-CIXf7Uye.js +46 -0
  42. package/dist/history-ClE4toxe.d.ts +32 -0
  43. package/dist/history-CqTuSAdI.js +441 -0
  44. package/dist/instrumentation.d.ts +3 -3
  45. package/dist/instrumentation.js +130 -176
  46. package/dist/job-queue-Drn_LXlM.js +63 -0
  47. package/dist/logging-BzAk1S_s.js +1210 -0
  48. package/dist/model-profile-CZmVoGdX.js +49 -0
  49. package/dist/nitro.d.ts +31 -36
  50. package/dist/nitro.js +275 -456
  51. package/dist/oauth-callback-server-JiftokvA.js +130 -0
  52. package/dist/oauth-relay-CdCnu80W.js +62 -0
  53. package/dist/package-discovery-7a9YqLhE.js +455 -0
  54. package/dist/pending-auth-CWmSdZVg.js +185 -0
  55. package/dist/plugin-module-BKGOXca2.js +81 -0
  56. package/dist/plugins-BI9A1vKA.d.ts +95 -0
  57. package/dist/plugins-egKWjgue.js +99 -0
  58. package/dist/private-trace-result-BLvBjy_e.js +16 -0
  59. package/dist/profile-CrT5nXbw.js +861 -0
  60. package/dist/registry-DH1xUo2N.js +1419 -0
  61. package/dist/reporting-schema-DosTN__Q.js +105 -0
  62. package/dist/resolve-CZHnfxaS.js +546 -0
  63. package/dist/rolldown-runtime-B4FMCO8f.js +28 -0
  64. package/dist/runner-CZV2sC46.js +392 -0
  65. package/dist/sandbox-egress-signals-bHZfmhbd.js +46 -0
  66. package/dist/schema-Rn8-XEaN.js +1140 -0
  67. package/dist/sentry-CD3SdJl-.js +26 -0
  68. package/dist/skills-CIcDQSgM.js +316 -0
  69. package/dist/spawn-DdkUFRmq.js +29 -0
  70. package/dist/stats-DTUbAb88.js +2634 -0
  71. package/dist/store-C5qxF2ac.d.ts +208 -0
  72. package/dist/task-queue-CJIR4RF7.js +136 -0
  73. package/dist/task-runner-D-O3A-Cp.js +639 -0
  74. package/dist/thread-state-CRc9jTJS.js +431 -0
  75. package/dist/turn-execution-BkinIdJF.js +47 -0
  76. package/dist/turn-lifecycle-DQV19VTW.js +54 -0
  77. package/dist/usage-D3EbSO7w.js +296 -0
  78. package/dist/usage-schema-CKaDkH_j.js +20 -0
  79. package/dist/validation-C2CR-OX3.js +40 -0
  80. package/dist/vercel-queue-DIkVcfK4.js +167 -0
  81. package/dist/vercel.d.ts +6 -6
  82. package/dist/vercel.js +14 -6
  83. package/dist/version-CnXZ614E.d.ts +5 -0
  84. package/dist/version-DxcWdoKa.js +8 -0
  85. package/dist/version.d.ts +2 -4
  86. package/dist/version.js +2 -6
  87. package/dist/web-authorization-RMBxAR_t.js +76 -0
  88. package/dist/web-input-3EPfpf55.js +494 -0
  89. package/dist/work-fGofI7Op.js +509 -0
  90. package/dist/worker-CsOLq-mR.js +625 -0
  91. package/package.json +9 -9
  92. package/dist/agent-hooks-UXITLYOK.js +0 -51
  93. package/dist/catalog-runtime-BG3JLLK2.js +0 -14
  94. package/dist/chunk-2LYHWMR4.js +0 -46
  95. package/dist/chunk-2MK3QBGA.js +0 -321
  96. package/dist/chunk-3PGQSKJV.js +0 -692
  97. package/dist/chunk-3UI3WFTX.js +0 -519
  98. package/dist/chunk-3Y47VMHV.js +0 -6
  99. package/dist/chunk-4UO6FK4G.js +0 -64
  100. package/dist/chunk-5NOPO64K.js +0 -198
  101. package/dist/chunk-5PKWYPFT.js +0 -2943
  102. package/dist/chunk-63NKKFJL.js +0 -1228
  103. package/dist/chunk-6AYH6252.js +0 -787
  104. package/dist/chunk-6Y5B5PEX.js +0 -80
  105. package/dist/chunk-7DHZP5KJ.js +0 -333
  106. package/dist/chunk-7H2VZTWN.js +0 -103
  107. package/dist/chunk-7NL7T6VU.js +0 -406
  108. package/dist/chunk-A76OIMYN.js +0 -102
  109. package/dist/chunk-AWMS3SPP.js +0 -58
  110. package/dist/chunk-B3LY5RCL.js +0 -229
  111. package/dist/chunk-BD2KT3OB.js +0 -36
  112. package/dist/chunk-BXCX5QKA.js +0 -2086
  113. package/dist/chunk-C6VVF43U.js +0 -81
  114. package/dist/chunk-CEMMLV5L.js +0 -98
  115. package/dist/chunk-CM5HNV2W.js +0 -131
  116. package/dist/chunk-DA2KGZZI.js +0 -13
  117. package/dist/chunk-DBVY6HLX.js +0 -64
  118. package/dist/chunk-DIB4GX3G.js +0 -8
  119. package/dist/chunk-DKIJ2RP5.js +0 -68
  120. package/dist/chunk-DL2KLKVH.js +0 -931
  121. package/dist/chunk-DWPN6SCH.js +0 -172
  122. package/dist/chunk-ELWOYVOY.js +0 -206
  123. package/dist/chunk-EWT7H65X.js +0 -506
  124. package/dist/chunk-FA6POGLH.js +0 -70
  125. package/dist/chunk-HMREVIO2.js +0 -135
  126. package/dist/chunk-IIWUT4FO.js +0 -820
  127. package/dist/chunk-JAL3CH4G.js +0 -27
  128. package/dist/chunk-JSJQEWBJ.js +0 -3295
  129. package/dist/chunk-KHKKHDLD.js +0 -387
  130. package/dist/chunk-LA6R4A7Q.js +0 -706
  131. package/dist/chunk-LOOU2DUR.js +0 -20428
  132. package/dist/chunk-M6FHWXE3.js +0 -700
  133. package/dist/chunk-M76HMB7M.js +0 -1856
  134. package/dist/chunk-MAGNK5J4.js +0 -1520
  135. package/dist/chunk-MTM5IFCY.js +0 -1190
  136. package/dist/chunk-N7TMSOZH.js +0 -235
  137. package/dist/chunk-NHJU2ZAL.js +0 -56
  138. package/dist/chunk-NSXKRGRT.js +0 -717
  139. package/dist/chunk-OWMPFXJA.js +0 -1764
  140. package/dist/chunk-PDO5BLNM.js +0 -22
  141. package/dist/chunk-PEQXYSSE.js +0 -45
  142. package/dist/chunk-PW4P4JYF.js +0 -1135
  143. package/dist/chunk-QB54UQUS.js +0 -320
  144. package/dist/chunk-QP3OGJXF.js +0 -105
  145. package/dist/chunk-RC745GGZ.js +0 -122
  146. package/dist/chunk-REOIRYPR.js +0 -37
  147. package/dist/chunk-SCOZRLZ4.js +0 -164
  148. package/dist/chunk-TXJSXBV5.js +0 -1433
  149. package/dist/chunk-TXKUKMVO.js +0 -417
  150. package/dist/chunk-U2GPUYAL.js +0 -3656
  151. package/dist/chunk-UIE3R5XU.js +0 -17
  152. package/dist/chunk-UXPG6ZIN.js +0 -84
  153. package/dist/chunk-VFUK3X5B.js +0 -50
  154. package/dist/chunk-WQSHDTTI.js +0 -1163
  155. package/dist/chunk-X6GDDWQH.js +0 -60
  156. package/dist/chunk-Y2CM7HXH.js +0 -111
  157. package/dist/chunk-Y7X25LFY.js +0 -15
  158. package/dist/chunk-YDUR3ZYW.js +0 -10
  159. package/dist/conversation-work-VIOQ5ZF3.js +0 -54
  160. package/dist/db-3L2MCVRI.js +0 -26
  161. package/dist/discovery-DWVDM7UK.js +0 -44
  162. package/dist/experimental-P5FZM4CU.js +0 -12
  163. package/dist/oauth-callback-server-YVV6C6T2.js +0 -243
  164. package/dist/oauth-relay-5XPVRPYB.js +0 -8
  165. package/dist/plugins-YTYJMMJF.js +0 -14
  166. package/dist/runner-LQ7RETDP.js +0 -522
  167. package/dist/sandbox-egress-signals-FIL7EGPR.js +0 -73
  168. package/dist/sentry-MB3NL3IR.js +0 -42
  169. package/dist/skills-XRWYEDCD.js +0 -27
  170. package/dist/spawn-RC6SJUAI.js +0 -42
  171. package/dist/task-runner-7DY7ARYH.js +0 -36
  172. package/dist/validation-7MNQGCJA.js +0 -17
  173. package/dist/work-COALHUCG.js +0 -51
  174. package/dist/worker-6MURZIPD.js +0 -24
@@ -1,51 +0,0 @@
1
- import {
2
- PluginHookDeniedError,
3
- applyPluginFormatMarkdown,
4
- createPluginHookRunner,
5
- getPluginApiRoutes,
6
- getPluginOperationalReports,
7
- getPluginProfileReports,
8
- getPluginRoutes,
9
- getPluginSlackConversationLink,
10
- getPluginSystemPromptContributions,
11
- getPluginTools,
12
- getPluginUserPromptContributions,
13
- getPlugins,
14
- setPlugins,
15
- validatePlugins
16
- } from "./chunk-U2GPUYAL.js";
17
- import "./chunk-3Y47VMHV.js";
18
- import "./chunk-M76HMB7M.js";
19
- import "./chunk-PW4P4JYF.js";
20
- import "./chunk-NSXKRGRT.js";
21
- import "./chunk-2MK3QBGA.js";
22
- import "./chunk-7NL7T6VU.js";
23
- import "./chunk-VFUK3X5B.js";
24
- import "./chunk-63NKKFJL.js";
25
- import "./chunk-NHJU2ZAL.js";
26
- import "./chunk-5NOPO64K.js";
27
- import "./chunk-YDUR3ZYW.js";
28
- import "./chunk-BXCX5QKA.js";
29
- import "./chunk-CEMMLV5L.js";
30
- import "./chunk-N7TMSOZH.js";
31
- import "./chunk-DWPN6SCH.js";
32
- import "./chunk-TXKUKMVO.js";
33
- import "./chunk-MAGNK5J4.js";
34
- import "./chunk-PEQXYSSE.js";
35
- import "./chunk-HMREVIO2.js";
36
- export {
37
- PluginHookDeniedError,
38
- applyPluginFormatMarkdown,
39
- createPluginHookRunner,
40
- getPluginApiRoutes,
41
- getPluginOperationalReports,
42
- getPluginProfileReports,
43
- getPluginRoutes,
44
- getPluginSlackConversationLink,
45
- getPluginSystemPromptContributions,
46
- getPluginTools,
47
- getPluginUserPromptContributions,
48
- getPlugins,
49
- setPlugins,
50
- validatePlugins
51
- };
@@ -1,14 +0,0 @@
1
- import {
2
- pluginCatalogRuntime
3
- } from "./chunk-YDUR3ZYW.js";
4
- import "./chunk-BXCX5QKA.js";
5
- import "./chunk-CEMMLV5L.js";
6
- import "./chunk-N7TMSOZH.js";
7
- import "./chunk-DWPN6SCH.js";
8
- import "./chunk-TXKUKMVO.js";
9
- import "./chunk-MAGNK5J4.js";
10
- import "./chunk-PEQXYSSE.js";
11
- import "./chunk-HMREVIO2.js";
12
- export {
13
- pluginCatalogRuntime
14
- };
@@ -1,46 +0,0 @@
1
- // src/chat/experimental.ts
2
- var EXPERIMENTAL_FEATURES = ["passive-routing", "subagents"];
3
- var EXPERIMENTAL_FEATURE_SET = new Set(EXPERIMENTAL_FEATURES);
4
- var configuredExperimental = {};
5
- function isExperimentalFeature(value) {
6
- return EXPERIMENTAL_FEATURE_SET.has(value);
7
- }
8
- function setExperimentalFeatures(config) {
9
- const previous = { ...configuredExperimental };
10
- if (config === void 0) {
11
- configuredExperimental = {};
12
- return previous;
13
- }
14
- const next = {};
15
- for (const [rawName, enabled] of Object.entries(config)) {
16
- if (enabled === void 0) {
17
- continue;
18
- }
19
- if (typeof enabled !== "boolean") {
20
- throw new Error(
21
- `experimental.${rawName} must be a boolean when provided`
22
- );
23
- }
24
- if (!isExperimentalFeature(rawName)) {
25
- throw new Error(
26
- `experimental.${rawName} is not a known experimental feature. Known features: ${EXPERIMENTAL_FEATURES.join(", ")}`
27
- );
28
- }
29
- next[rawName] = enabled;
30
- }
31
- configuredExperimental = next;
32
- return previous;
33
- }
34
- function getExperimentalFeatures() {
35
- return { ...configuredExperimental };
36
- }
37
- function isExperimentalFeatureEnabled(feature) {
38
- return configuredExperimental[feature] === true;
39
- }
40
-
41
- export {
42
- EXPERIMENTAL_FEATURES,
43
- setExperimentalFeatures,
44
- getExperimentalFeatures,
45
- isExperimentalFeatureEnabled
46
- };
@@ -1,321 +0,0 @@
1
- import {
2
- getChatConfig
3
- } from "./chunk-63NKKFJL.js";
4
-
5
- // src/chat/state/adapter.ts
6
- import { createMemoryState } from "@chat-adapter/state-memory";
7
- import { createRedisState } from "@chat-adapter/state-redis";
8
-
9
- // src/chat/state/locks.ts
10
- import { setTimeout as sleep } from "timers/promises";
11
- var ACTIVE_LOCK_TTL_MS = 9e4;
12
- var MUTATION_LOCK_TTL_MS = 1e4;
13
- async function acquireActiveLock(state, threadId) {
14
- return await state.acquireLock(threadId, ACTIVE_LOCK_TTL_MS);
15
- }
16
- async function withLock(state, key, run, options = {}) {
17
- const startedAtMs = Date.now();
18
- let lock;
19
- while (true) {
20
- lock = await state.acquireLock(key, options.ttlMs ?? ACTIVE_LOCK_TTL_MS);
21
- if (lock) break;
22
- if (Date.now() - startedAtMs >= (options.waitMs ?? 0)) {
23
- return { acquired: false };
24
- }
25
- await sleep(options.retryMs ?? 25, void 0, { ref: false });
26
- }
27
- const ttlMs = options.ttlMs ?? ACTIVE_LOCK_TTL_MS;
28
- const heartbeat = options.keepAlive ? setInterval(
29
- () => {
30
- void state.extendLock(lock, ttlMs);
31
- },
32
- Math.max(1, Math.floor(ttlMs / 3))
33
- ) : void 0;
34
- heartbeat?.unref();
35
- try {
36
- return { acquired: true, value: await run(lock) };
37
- } finally {
38
- if (heartbeat) clearInterval(heartbeat);
39
- await state.releaseLock(lock);
40
- }
41
- }
42
- async function fenceLock(state, lock, ttlMs = MUTATION_LOCK_TTL_MS) {
43
- if (!await state.extendLock(lock, ttlMs)) {
44
- throw new Error(
45
- `Lock ownership was lost before write for ${lock.threadId}`
46
- );
47
- }
48
- }
49
- async function withActiveLock(state, key, run) {
50
- return await withLock(state, key, run);
51
- }
52
-
53
- // src/chat/state/adapter.ts
54
- var ACTIVE_LOCK_HEARTBEAT_MS = 3e4;
55
- var stateAdapter;
56
- var redisStateAdapter;
57
- function createConnectingStateAdapter(base) {
58
- const connected = async (operation) => {
59
- await base.connect();
60
- return await operation();
61
- };
62
- return {
63
- appendToList: (key, value, options) => connected(() => base.appendToList(key, value, options)),
64
- connect: () => base.connect(),
65
- disconnect: () => base.disconnect(),
66
- subscribe: (threadId) => connected(() => base.subscribe(threadId)),
67
- unsubscribe: (threadId) => connected(() => base.unsubscribe(threadId)),
68
- isSubscribed: (threadId) => connected(() => base.isSubscribed(threadId)),
69
- acquireLock: (threadId, ttlMs) => connected(() => base.acquireLock(threadId, ttlMs)),
70
- releaseLock: (lock) => connected(() => base.releaseLock(lock)),
71
- extendLock: (lock, ttlMs) => connected(() => base.extendLock(lock, ttlMs)),
72
- forceReleaseLock: (threadId) => connected(() => base.forceReleaseLock(threadId)),
73
- enqueue: (threadId, entry, maxSize) => connected(() => base.enqueue(threadId, entry, maxSize)),
74
- dequeue: (threadId) => connected(() => base.dequeue(threadId)),
75
- queueDepth: (threadId) => connected(() => base.queueDepth(threadId)),
76
- get: (key) => connected(() => base.get(key)),
77
- getList: (key) => connected(() => base.getList(key)),
78
- set: (key, value, ttlMs) => connected(() => base.set(key, value, ttlMs)),
79
- setIfNotExists: (key, value, ttlMs) => connected(() => base.setIfNotExists(key, value, ttlMs)),
80
- delete: (key) => connected(() => base.delete(key))
81
- };
82
- }
83
- function createPrefixedStateAdapter(base, prefix) {
84
- const prefixed = (value) => `${prefix}:${value}`;
85
- const unprefixed = (value) => value.startsWith(`${prefix}:`) ? value.slice(prefix.length + 1) : value;
86
- const prefixLock = (lock) => ({
87
- ...lock,
88
- threadId: prefixed(lock.threadId)
89
- });
90
- const unprefixLock = (lock) => ({
91
- ...lock,
92
- threadId: unprefixed(lock.threadId)
93
- });
94
- return {
95
- appendToList: (key, value, options) => base.appendToList(prefixed(key), value, options),
96
- connect: () => base.connect(),
97
- disconnect: () => base.disconnect(),
98
- subscribe: (threadId) => base.subscribe(prefixed(threadId)),
99
- unsubscribe: (threadId) => base.unsubscribe(prefixed(threadId)),
100
- isSubscribed: (threadId) => base.isSubscribed(prefixed(threadId)),
101
- acquireLock: async (threadId, ttlMs) => {
102
- const lock = await base.acquireLock(prefixed(threadId), ttlMs);
103
- return lock ? unprefixLock(lock) : null;
104
- },
105
- releaseLock: (lock) => base.releaseLock(prefixLock(lock)),
106
- extendLock: async (lock, ttlMs) => {
107
- const prefixedLock = prefixLock(lock);
108
- const extended = await base.extendLock(prefixedLock, ttlMs);
109
- if (extended) {
110
- lock.expiresAt = prefixedLock.expiresAt;
111
- }
112
- return extended;
113
- },
114
- forceReleaseLock: (threadId) => base.forceReleaseLock(prefixed(threadId)),
115
- enqueue: (threadId, entry, maxSize) => base.enqueue(prefixed(threadId), entry, maxSize),
116
- dequeue: (threadId) => base.dequeue(prefixed(threadId)),
117
- queueDepth: (threadId) => base.queueDepth(prefixed(threadId)),
118
- get: (key) => base.get(prefixed(key)),
119
- getList: (key) => base.getList(prefixed(key)),
120
- set: (key, value, ttlMs) => base.set(prefixed(key), value, ttlMs),
121
- setIfNotExists: (key, value, ttlMs) => base.setIfNotExists(prefixed(key), value, ttlMs),
122
- delete: (key) => base.delete(prefixed(key))
123
- };
124
- }
125
- function createQueuedStateAdapter(base, options) {
126
- const heartbeats = /* @__PURE__ */ new Map();
127
- const shouldHeartbeatLock = (ttlMs) => ttlMs === ACTIVE_LOCK_TTL_MS;
128
- const heartbeatKey = (lock) => `${lock.threadId}:${lock.token}`;
129
- const stopHeartbeatByKey = (key) => {
130
- const heartbeat = heartbeats.get(key);
131
- if (!heartbeat) {
132
- return;
133
- }
134
- clearInterval(heartbeat.timer);
135
- heartbeats.delete(key);
136
- };
137
- const stopHeartbeat = (lock) => {
138
- stopHeartbeatByKey(heartbeatKey(lock));
139
- };
140
- const stopHeartbeatsForThread = (threadId) => {
141
- for (const [key, heartbeat] of heartbeats) {
142
- if (heartbeat.lock.threadId === threadId) {
143
- stopHeartbeatByKey(key);
144
- }
145
- }
146
- };
147
- const stopAllHeartbeats = () => {
148
- for (const key of heartbeats.keys()) {
149
- stopHeartbeatByKey(key);
150
- }
151
- };
152
- const runHeartbeat = async (key) => {
153
- const heartbeat = heartbeats.get(key);
154
- if (!heartbeat || heartbeat.inFlight) {
155
- return;
156
- }
157
- heartbeat.inFlight = true;
158
- try {
159
- if (Date.now() - heartbeat.startedAtMs >= options.activeLockMaxAgeMs) {
160
- stopHeartbeatByKey(key);
161
- return;
162
- }
163
- const extended = await base.extendLock(heartbeat.lock, heartbeat.ttlMs);
164
- if (!extended) {
165
- stopHeartbeatByKey(key);
166
- return;
167
- }
168
- heartbeat.lock.expiresAt = Date.now() + heartbeat.ttlMs;
169
- } catch {
170
- } finally {
171
- const current = heartbeats.get(key);
172
- if (current === heartbeat) {
173
- current.inFlight = false;
174
- }
175
- }
176
- };
177
- const startOrUpdateHeartbeat = (lock, ttlMs) => {
178
- const key = heartbeatKey(lock);
179
- const existing = heartbeats.get(key);
180
- if (existing) {
181
- existing.ttlMs = ttlMs;
182
- return;
183
- }
184
- const timer = setInterval(() => {
185
- void runHeartbeat(key);
186
- }, ACTIVE_LOCK_HEARTBEAT_MS);
187
- timer.unref?.();
188
- heartbeats.set(key, {
189
- inFlight: false,
190
- lock,
191
- startedAtMs: Date.now(),
192
- timer,
193
- ttlMs
194
- });
195
- };
196
- const acquireLock = async (threadId, ttlMs) => {
197
- const lock = await base.acquireLock(threadId, ttlMs);
198
- if (lock && shouldHeartbeatLock(ttlMs)) {
199
- startOrUpdateHeartbeat(lock, ttlMs);
200
- }
201
- return lock;
202
- };
203
- return {
204
- appendToList: (key, value, options2) => base.appendToList(key, value, options2),
205
- connect: () => base.connect(),
206
- disconnect: async () => {
207
- stopAllHeartbeats();
208
- await base.disconnect();
209
- },
210
- subscribe: (threadId) => base.subscribe(threadId),
211
- unsubscribe: (threadId) => base.unsubscribe(threadId),
212
- isSubscribed: (threadId) => base.isSubscribed(threadId),
213
- acquireLock,
214
- releaseLock: async (lock) => {
215
- stopHeartbeat(lock);
216
- await base.releaseLock(lock);
217
- },
218
- extendLock: async (lock, ttlMs) => {
219
- const extended = await base.extendLock(lock, ttlMs);
220
- if (extended) {
221
- lock.expiresAt = Date.now() + ttlMs;
222
- if (shouldHeartbeatLock(ttlMs)) {
223
- startOrUpdateHeartbeat(lock, ttlMs);
224
- } else {
225
- stopHeartbeat(lock);
226
- }
227
- } else {
228
- stopHeartbeat(lock);
229
- }
230
- return extended;
231
- },
232
- forceReleaseLock: async (threadId) => {
233
- stopHeartbeatsForThread(threadId);
234
- await base.forceReleaseLock(threadId);
235
- },
236
- enqueue: (threadId, entry, maxSize) => base.enqueue(threadId, entry, maxSize),
237
- dequeue: (threadId) => base.dequeue(threadId),
238
- queueDepth: (threadId) => base.queueDepth(threadId),
239
- get: (key) => base.get(key),
240
- getList: (key) => base.getList(key),
241
- set: (key, value, ttlMs) => base.set(key, value, ttlMs),
242
- setIfNotExists: (key, value, ttlMs) => base.setIfNotExists(key, value, ttlMs),
243
- delete: (key) => base.delete(key)
244
- };
245
- }
246
- function withOptionalPrefix(base, prefix) {
247
- return prefix ? createPrefixedStateAdapter(base, prefix) : base;
248
- }
249
- function createStateAdapter() {
250
- const config = getChatConfig();
251
- const activeLockMaxAgeMs = config.bot.turnTimeoutMs + ACTIVE_LOCK_TTL_MS;
252
- if (config.state.adapter === "memory") {
253
- redisStateAdapter = void 0;
254
- return createQueuedStateAdapter(
255
- createConnectingStateAdapter(
256
- withOptionalPrefix(createMemoryState(), config.state.keyPrefix)
257
- ),
258
- { activeLockMaxAgeMs }
259
- );
260
- }
261
- if (!config.state.redisUrl) {
262
- throw new Error("REDIS_URL is required for durable Slack thread state");
263
- }
264
- const redisState = createRedisState({
265
- url: config.state.redisUrl
266
- });
267
- redisStateAdapter = redisState;
268
- return createQueuedStateAdapter(
269
- createConnectingStateAdapter(
270
- withOptionalPrefix(redisState, config.state.keyPrefix)
271
- ),
272
- { activeLockMaxAgeMs }
273
- );
274
- }
275
- function getOptionalRedisStateAdapter() {
276
- getStateAdapter();
277
- return redisStateAdapter;
278
- }
279
- async function getConnectedStateContext() {
280
- const adapter = getStateAdapter();
281
- await adapter.connect();
282
- return {
283
- redisStateAdapter: getOptionalRedisStateAdapter(),
284
- stateAdapter: adapter
285
- };
286
- }
287
- async function getDefaultRedisStateAdapterFor(adapter) {
288
- if (adapter !== stateAdapter) {
289
- return void 0;
290
- }
291
- const context = await getConnectedStateContext();
292
- return context.stateAdapter === adapter ? context.redisStateAdapter : void 0;
293
- }
294
- function getStateAdapter() {
295
- if (!stateAdapter) {
296
- stateAdapter = createStateAdapter();
297
- }
298
- return stateAdapter;
299
- }
300
- async function disconnectStateAdapter() {
301
- if (!stateAdapter) {
302
- return;
303
- }
304
- try {
305
- await stateAdapter.disconnect();
306
- } finally {
307
- stateAdapter = void 0;
308
- redisStateAdapter = void 0;
309
- }
310
- }
311
-
312
- export {
313
- MUTATION_LOCK_TTL_MS,
314
- acquireActiveLock,
315
- withLock,
316
- fenceLock,
317
- withActiveLock,
318
- getDefaultRedisStateAdapterFor,
319
- getStateAdapter,
320
- disconnectStateAdapter
321
- };