@sentry/junior 0.301.0 → 0.302.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.
- package/dist/adapter-context-Cx9fn9B3.js +43 -0
- package/dist/{admin-CRJHvCGg.js → admin-_poE5NKL.js} +2 -2
- package/dist/{agent-runner-H4YhvNBj.js → agent-runner-CY9RvsTX.js} +1380 -10601
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +4 -5
- package/dist/api.d.ts +1 -1
- package/dist/api.js +91 -68
- package/dist/{app-HDZglaIu.d.ts → app-BpY3wtRP.d.ts} +2 -2
- package/dist/app.d.ts +1 -1
- package/dist/app.js +66 -296
- package/dist/{background-compaction-queue-CNrZ3QcU.js → background-compaction-queue-CXFq1_Cz.js} +94 -203
- package/dist/{briefs-x6Mzwxmg.js → briefs-B3NG-pid.js} +2 -2
- package/dist/{catalog-runtime-BEY6EGRi.js → catalog-runtime-Dss0lSV6.js} +1 -1
- package/dist/cli/chat.js +15 -15
- package/dist/cli/check.js +3 -3
- package/dist/cli/main.js +3 -3
- package/dist/cli/plugins.js +4 -4
- package/dist/cli/snapshot-create.js +4 -4
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +3 -3
- package/dist/{config-CmjhyqgB.js → config-CzeZiMKs.js} +2 -2
- package/dist/{connections-CfIRm0xv.js → connections-CDYhMfrs.js} +6 -6
- package/dist/{continue-in-slack-DPoABVkB.js → continue-in-slack-7Uf05ndC.js} +5 -6
- package/dist/{conversation-feed-CfpyFMHP.js → conversation-feed-Clf_cv0n.js} +1 -0
- package/dist/{conversation-privacy-0CM0V2qK.js → conversation-privacy-D9xnM5mK.js} +1 -1
- package/dist/{conversation-turn-C0sxyvS-.js → conversation-turn-D7SEZgTG.js} +15 -16
- package/dist/{credential-sync-tEMKZ_8M.js → credential-sync-DoD0gW-j.js} +13 -15
- package/dist/{db-Czra10QW.js → db-B-gtnNjr.js} +314 -5
- package/dist/{db-BdUHQhrC.d.ts → db-BdsCzytP.d.ts} +1 -1
- package/dist/{executor-D_023K0H.js → executor-DZg20EqU.js} +39 -4
- package/dist/install-t1KQyTUs.js +228 -0
- package/dist/instrumentation.js +2 -2
- package/dist/{state-CEbZuZD6.js → legacy-web-actor-id-C-cEeWqL.js} +33 -4
- package/dist/{lineage-DmMIE0VL.js → lineage-C79GjoQr.js} +2 -2
- package/dist/{logging-DcjLDDqi.js → logging-C9oDAg4M.js} +7 -3
- package/dist/{message-C0JY9RJP.js → message-BLUCzJXN.js} +8 -8
- package/dist/{model-input-CBp-p24N.js → model-input-5jwNC45G.js} +3 -3
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +4 -3
- package/dist/{oauth-callback-server-BRq9QNhU.js → oauth-callback-server-BBl66vCb.js} +2 -2
- package/dist/{projection-CQNDOi82.js → projection-CIBwgD3s.js} +282 -64
- package/dist/{prompt-DLUB5m72.js → prompt-CRQbzp5e.js} +14 -4
- package/dist/queue-DtCDaIct.js +115 -0
- package/dist/{registry-Dj377ADs.js → registry-DdFQHZ_d.js} +1 -1
- package/dist/{resolve-DJkh9Fky.js → resolve-CdW4BdrK.js} +4 -229
- package/dist/{result-C8iIpDl1.js → result-oOMv1t4O.js} +9 -9
- package/dist/{runner-DZqrOy8C.js → runner-DqitLtm-.js} +8 -8
- package/dist/{sandbox-egress-signals-CGwH86S9.js → sandbox-egress-signals-Bw9I0yfJ.js} +1 -1
- package/dist/{schema-CdZFn7Qd.d.ts → schema-BIFM-U1a.d.ts} +441 -30
- package/dist/{schema-DyHXiQKI.js → schema-DnVQepWP.js} +66 -29
- package/dist/{service-account-D6jGR4a1.js → service-account-B6mKAPVo.js} +3 -3
- package/dist/{service-account-suY004dx.js → service-account-CrZftRTb.js} +257 -6
- package/dist/{session-stop-BLmfFI3d.js → session-stop-DW63Z3kj.js} +543 -548
- package/dist/{skills-CmNG0dHb.js → skills-C16fz60Z.js} +2 -2
- package/dist/{slack-conversation-unfurl-Bty-DlHe.js → slack-conversation-unfurl-BHhefEb7.js} +8 -7
- package/dist/{spawn-CNjkpXpk.js → spawn-D_RnFYfy.js} +6 -6
- package/dist/{stop-Bjy2-K4H.js → stop-7p1i08CY.js} +724 -106
- package/dist/{store-DmV4CoNr.js → store-C28I0CVW.js} +5 -5
- package/dist/{task-queue-AhG1tSXR.js → task-queue-BVUJbQ28.js} +3 -3
- package/dist/{task-runner-BMxZI3o7.js → task-runner-CWi8j7Z6.js} +6 -8
- package/dist/{thread-context-CXLnbg7g.js → thread-context-D3-yYUd0.js} +7 -7
- package/dist/{store-Epv6t4vV.js → turn-session-routing-BFMS9ATF.js} +381 -10
- package/dist/{turn-user-message-DsUZi9gn.js → turn-user-message-C3-O8Omt.js} +3 -3
- package/dist/{validation-DOz8X9BU.js → validation-BSFKUIb4.js} +1 -1
- package/dist/{version-CGMRmMPK.js → version-BHHXNi-0.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-H3EsMWtJ.js → viewer-B1SO21Qa.js} +3 -3
- package/dist/warmup-Bz9bzkzN.js +13927 -0
- package/dist/{statuses-Hn-HsOph.js → web-message-id-lNodcCOI.js} +136 -1
- package/dist/{worker-ClphajjD.js → worker-BspReIIK.js} +7 -7
- package/migrations/0108_conversation_embeddings.sql +13 -0
- package/migrations/meta/0108_snapshot.json +4688 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +8 -6
- package/dist/adapter-CNjGEJO9.js +0 -303
- package/dist/reporting-window-DopzcOHh.js +0 -137
- package/dist/turn-session-routing-BD3-jJl7.js +0 -380
- package/dist/users-BxvYclQg.js +0 -424
- package/dist/warmup-CdU5hR49.js +0 -3715
|
@@ -757,6 +757,13 @@
|
|
|
757
757
|
"when": 1794557567747,
|
|
758
758
|
"tag": "0107_attachment_deferred_download",
|
|
759
759
|
"breakpoints": true
|
|
760
|
+
},
|
|
761
|
+
{
|
|
762
|
+
"idx": 108,
|
|
763
|
+
"version": "7",
|
|
764
|
+
"when": 1794610551055,
|
|
765
|
+
"tag": "0108_conversation_embeddings",
|
|
766
|
+
"breakpoints": true
|
|
760
767
|
}
|
|
761
768
|
]
|
|
762
769
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/junior",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.302.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"@chat-adapter/slack": "4.29.0",
|
|
58
58
|
"@chat-adapter/state-memory": "4.29.0",
|
|
59
59
|
"@chat-adapter/state-redis": "4.29.0",
|
|
60
|
-
"@earendil-works/pi-agent-core": "0.
|
|
61
|
-
"@earendil-works/pi-ai": "0.
|
|
60
|
+
"@earendil-works/pi-agent-core": "0.99.2",
|
|
61
|
+
"@earendil-works/pi-ai": "0.99.2",
|
|
62
62
|
"@earendil-works/pi-codemode": "1.4.0",
|
|
63
63
|
"@hono/zod-validator": "^0.9.0",
|
|
64
64
|
"@logtape/logtape": "^2.1.1",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"web-push": "^3.6.7",
|
|
97
97
|
"yaml": "^2.9.0",
|
|
98
98
|
"zod": "^4.6.7",
|
|
99
|
-
"@sentry/junior-plugin-api": "0.
|
|
99
|
+
"@sentry/junior-plugin-api": "0.302.0"
|
|
100
100
|
},
|
|
101
101
|
"peerDependencies": {
|
|
102
102
|
"bullmq": "^6.5.0",
|
|
@@ -132,8 +132,10 @@
|
|
|
132
132
|
"typescript": "^7.0.2",
|
|
133
133
|
"vercel": "^54.4.0",
|
|
134
134
|
"vitest": "^4.1.12",
|
|
135
|
-
"@sentry/junior-github": "0.
|
|
136
|
-
"@sentry/junior-
|
|
135
|
+
"@sentry/junior-github": "0.302.0",
|
|
136
|
+
"@sentry/junior-sentry": "0.302.0",
|
|
137
|
+
"@sentry/junior-notion": "0.302.0",
|
|
138
|
+
"@sentry/junior-memory": "0.302.0",
|
|
137
139
|
"@sentry/junior-testing": "0.0.0"
|
|
138
140
|
},
|
|
139
141
|
"scripts": {
|
package/dist/adapter-CNjGEJO9.js
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import { i as getChatConfig } from "./config-CmjhyqgB.js";
|
|
2
|
-
import { createMemoryState } from "@chat-adapter/state-memory";
|
|
3
|
-
import { createRedisState } from "@chat-adapter/state-redis";
|
|
4
|
-
import { setTimeout } from "node:timers/promises";
|
|
5
|
-
// src/chat/state/locks.ts
|
|
6
|
-
const ACTIVE_LOCK_TTL_MS = 9e4;
|
|
7
|
-
const MUTATION_LOCK_TTL_MS = 1e4;
|
|
8
|
-
/**
|
|
9
|
-
* Acquire a lock for long-running work that the queued state adapter should
|
|
10
|
-
* keep alive while the owning invocation is still making progress.
|
|
11
|
-
*/
|
|
12
|
-
async function acquireActiveLock(state, threadId) {
|
|
13
|
-
return await state.acquireLock(threadId, ACTIVE_LOCK_TTL_MS);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Run work under one lock, optionally waiting for the current owner.
|
|
17
|
-
* `keepAlive` is for multi-store mutations that must retain ownership until all
|
|
18
|
-
* side effects finish; callers should still fence each blind write.
|
|
19
|
-
*/
|
|
20
|
-
async function withLock(state, key, run, options = {}) {
|
|
21
|
-
const ttlMs = options.ttlMs ?? 9e4;
|
|
22
|
-
const startedAtMs = Date.now();
|
|
23
|
-
let lock;
|
|
24
|
-
while (true) {
|
|
25
|
-
lock = await state.acquireLock(key, ttlMs);
|
|
26
|
-
if (lock) break;
|
|
27
|
-
if (Date.now() - startedAtMs >= (options.waitMs ?? 0)) return { acquired: false };
|
|
28
|
-
await setTimeout(options.retryMs ?? 25, void 0, { ref: false });
|
|
29
|
-
}
|
|
30
|
-
const heartbeat = options.keepAlive ? setInterval(() => void state.extendLock(lock, ttlMs).catch(() => void 0), Math.max(1, Math.floor(ttlMs / 3))) : void 0;
|
|
31
|
-
heartbeat?.unref();
|
|
32
|
-
try {
|
|
33
|
-
return {
|
|
34
|
-
acquired: true,
|
|
35
|
-
value: await run(lock)
|
|
36
|
-
};
|
|
37
|
-
} finally {
|
|
38
|
-
if (heartbeat) clearInterval(heartbeat);
|
|
39
|
-
await state.releaseLock(lock);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Prove lock ownership immediately before a blind write.
|
|
44
|
-
*
|
|
45
|
-
* Whole-record mutations must stop if their lock expired rather than overwrite
|
|
46
|
-
* state committed by a newer owner.
|
|
47
|
-
*/
|
|
48
|
-
async function fenceLock(state, lock, ttlMs = MUTATION_LOCK_TTL_MS) {
|
|
49
|
-
if (!await state.extendLock(lock, ttlMs)) throw new Error(`Lock ownership was lost before write for ${lock.threadId}`);
|
|
50
|
-
}
|
|
51
|
-
// src/chat/state/adapter.ts
|
|
52
|
-
const ACTIVE_LOCK_HEARTBEAT_MS = 3e4;
|
|
53
|
-
const REDIS_STATE_KEY_PREFIX = "chat-sdk";
|
|
54
|
-
let stateAdapter;
|
|
55
|
-
let redisStateAdapter;
|
|
56
|
-
/** Lazily connect state operations, including queued-adapter lock heartbeats. */
|
|
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) lock.expiresAt = prefixedLock.expiresAt;
|
|
110
|
-
return extended;
|
|
111
|
-
},
|
|
112
|
-
forceReleaseLock: (threadId) => base.forceReleaseLock(prefixed(threadId)),
|
|
113
|
-
enqueue: (threadId, entry, maxSize) => base.enqueue(prefixed(threadId), entry, maxSize),
|
|
114
|
-
dequeue: (threadId) => base.dequeue(prefixed(threadId)),
|
|
115
|
-
queueDepth: (threadId) => base.queueDepth(prefixed(threadId)),
|
|
116
|
-
get: (key) => base.get(prefixed(key)),
|
|
117
|
-
getList: (key) => base.getList(prefixed(key)),
|
|
118
|
-
set: (key, value, ttlMs) => base.set(prefixed(key), value, ttlMs),
|
|
119
|
-
setIfNotExists: (key, value, ttlMs) => base.setIfNotExists(prefixed(key), value, ttlMs),
|
|
120
|
-
delete: (key) => base.delete(prefixed(key))
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
function createQueuedStateAdapter(base, options) {
|
|
124
|
-
const heartbeats = /* @__PURE__ */ new Map();
|
|
125
|
-
const shouldHeartbeatLock = (ttlMs) => ttlMs === ACTIVE_LOCK_TTL_MS;
|
|
126
|
-
const heartbeatKey = (lock) => `${lock.threadId}:${lock.token}`;
|
|
127
|
-
const stopHeartbeatByKey = (key) => {
|
|
128
|
-
const heartbeat = heartbeats.get(key);
|
|
129
|
-
if (!heartbeat) return;
|
|
130
|
-
clearInterval(heartbeat.timer);
|
|
131
|
-
heartbeats.delete(key);
|
|
132
|
-
};
|
|
133
|
-
const stopHeartbeat = (lock) => {
|
|
134
|
-
stopHeartbeatByKey(heartbeatKey(lock));
|
|
135
|
-
};
|
|
136
|
-
const stopHeartbeatsForThread = (threadId) => {
|
|
137
|
-
for (const [key, heartbeat] of heartbeats) if (heartbeat.lock.threadId === threadId) stopHeartbeatByKey(key);
|
|
138
|
-
};
|
|
139
|
-
const stopAllHeartbeats = () => {
|
|
140
|
-
for (const key of heartbeats.keys()) stopHeartbeatByKey(key);
|
|
141
|
-
};
|
|
142
|
-
const runHeartbeat = async (key) => {
|
|
143
|
-
const heartbeat = heartbeats.get(key);
|
|
144
|
-
if (!heartbeat || heartbeat.inFlight) return;
|
|
145
|
-
heartbeat.inFlight = true;
|
|
146
|
-
try {
|
|
147
|
-
if (Date.now() - heartbeat.startedAtMs >= options.activeLockMaxAgeMs) {
|
|
148
|
-
stopHeartbeatByKey(key);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
if (!await base.extendLock(heartbeat.lock, heartbeat.ttlMs)) {
|
|
152
|
-
stopHeartbeatByKey(key);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
heartbeat.lock.expiresAt = Date.now() + heartbeat.ttlMs;
|
|
156
|
-
} catch {} finally {
|
|
157
|
-
const current = heartbeats.get(key);
|
|
158
|
-
if (current === heartbeat) current.inFlight = false;
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
const startOrUpdateHeartbeat = (lock, ttlMs) => {
|
|
162
|
-
const key = heartbeatKey(lock);
|
|
163
|
-
const existing = heartbeats.get(key);
|
|
164
|
-
if (existing) {
|
|
165
|
-
existing.ttlMs = ttlMs;
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const timer = setInterval(() => {
|
|
169
|
-
runHeartbeat(key);
|
|
170
|
-
}, ACTIVE_LOCK_HEARTBEAT_MS);
|
|
171
|
-
timer.unref?.();
|
|
172
|
-
heartbeats.set(key, {
|
|
173
|
-
inFlight: false,
|
|
174
|
-
lock,
|
|
175
|
-
startedAtMs: Date.now(),
|
|
176
|
-
timer,
|
|
177
|
-
ttlMs
|
|
178
|
-
});
|
|
179
|
-
};
|
|
180
|
-
const acquireLock = async (threadId, ttlMs) => {
|
|
181
|
-
const lock = await base.acquireLock(threadId, ttlMs);
|
|
182
|
-
if (lock && shouldHeartbeatLock(ttlMs)) startOrUpdateHeartbeat(lock, ttlMs);
|
|
183
|
-
return lock;
|
|
184
|
-
};
|
|
185
|
-
return {
|
|
186
|
-
appendToList: (key, value, options) => base.appendToList(key, value, options),
|
|
187
|
-
connect: () => base.connect(),
|
|
188
|
-
disconnect: async () => {
|
|
189
|
-
stopAllHeartbeats();
|
|
190
|
-
await base.disconnect();
|
|
191
|
-
},
|
|
192
|
-
subscribe: (threadId) => base.subscribe(threadId),
|
|
193
|
-
unsubscribe: (threadId) => base.unsubscribe(threadId),
|
|
194
|
-
isSubscribed: (threadId) => base.isSubscribed(threadId),
|
|
195
|
-
acquireLock,
|
|
196
|
-
releaseLock: async (lock) => {
|
|
197
|
-
stopHeartbeat(lock);
|
|
198
|
-
await base.releaseLock(lock);
|
|
199
|
-
},
|
|
200
|
-
extendLock: async (lock, ttlMs) => {
|
|
201
|
-
const extended = await base.extendLock(lock, ttlMs);
|
|
202
|
-
if (extended) {
|
|
203
|
-
lock.expiresAt = Date.now() + ttlMs;
|
|
204
|
-
if (shouldHeartbeatLock(ttlMs)) startOrUpdateHeartbeat(lock, ttlMs);
|
|
205
|
-
else stopHeartbeat(lock);
|
|
206
|
-
} else stopHeartbeat(lock);
|
|
207
|
-
return extended;
|
|
208
|
-
},
|
|
209
|
-
forceReleaseLock: async (threadId) => {
|
|
210
|
-
stopHeartbeatsForThread(threadId);
|
|
211
|
-
await base.forceReleaseLock(threadId);
|
|
212
|
-
},
|
|
213
|
-
enqueue: (threadId, entry, maxSize) => base.enqueue(threadId, entry, maxSize),
|
|
214
|
-
dequeue: (threadId) => base.dequeue(threadId),
|
|
215
|
-
queueDepth: (threadId) => base.queueDepth(threadId),
|
|
216
|
-
get: (key) => base.get(key),
|
|
217
|
-
getList: (key) => base.getList(key),
|
|
218
|
-
set: (key, value, ttlMs) => base.set(key, value, ttlMs),
|
|
219
|
-
setIfNotExists: (key, value, ttlMs) => base.setIfNotExists(key, value, ttlMs),
|
|
220
|
-
delete: (key) => base.delete(key)
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
function withOptionalPrefix(base, prefix) {
|
|
224
|
-
return prefix ? createPrefixedStateAdapter(base, prefix) : base;
|
|
225
|
-
}
|
|
226
|
-
function createStateAdapter() {
|
|
227
|
-
const config = getChatConfig();
|
|
228
|
-
const activeLockMaxAgeMs = config.bot.turnTimeoutMs + ACTIVE_LOCK_TTL_MS;
|
|
229
|
-
if (config.state.adapter === "memory") {
|
|
230
|
-
redisStateAdapter = void 0;
|
|
231
|
-
return createQueuedStateAdapter(createConnectingStateAdapter(withOptionalPrefix(createMemoryState(), config.state.keyPrefix)), { activeLockMaxAgeMs });
|
|
232
|
-
}
|
|
233
|
-
if (!config.state.redisUrl) throw new Error("REDIS_URL is required for durable Slack thread state");
|
|
234
|
-
const redisState = createRedisState({
|
|
235
|
-
keyPrefix: REDIS_STATE_KEY_PREFIX,
|
|
236
|
-
url: config.state.redisUrl
|
|
237
|
-
});
|
|
238
|
-
redisStateAdapter = redisState;
|
|
239
|
-
return createQueuedStateAdapter(createConnectingStateAdapter(withOptionalPrefix(redisState, config.state.keyPrefix)), { activeLockMaxAgeMs });
|
|
240
|
-
}
|
|
241
|
-
function getOptionalRedisStateAdapter() {
|
|
242
|
-
getStateAdapter();
|
|
243
|
-
return redisStateAdapter;
|
|
244
|
-
}
|
|
245
|
-
async function getConnectedStateContext() {
|
|
246
|
-
const adapter = getStateAdapter();
|
|
247
|
-
await adapter.connect();
|
|
248
|
-
return {
|
|
249
|
-
redisStateAdapter: getOptionalRedisStateAdapter(),
|
|
250
|
-
stateAdapter: adapter
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
/** Return the Redis adapter only when the caller is using the default state adapter. */
|
|
254
|
-
async function getDefaultRedisStateAdapterFor(adapter) {
|
|
255
|
-
if (adapter !== stateAdapter) return;
|
|
256
|
-
const context = await getConnectedStateContext();
|
|
257
|
-
return context.stateAdapter === adapter ? context.redisStateAdapter : void 0;
|
|
258
|
-
}
|
|
259
|
-
/** The Redis key that the default Redis adapter uses for one state value key. */
|
|
260
|
-
function redisStateKey(key) {
|
|
261
|
-
const prefix = getChatConfig().state.keyPrefix;
|
|
262
|
-
return `${REDIS_STATE_KEY_PREFIX}:cache:${prefix ? `${prefix}:` : ""}${key}`;
|
|
263
|
-
}
|
|
264
|
-
/** Read state values in one Redis round trip. Other adapters read each key. */
|
|
265
|
-
async function getStateValues(state, keys) {
|
|
266
|
-
if (keys.length === 0) return [];
|
|
267
|
-
const redis = await getDefaultRedisStateAdapterFor(state);
|
|
268
|
-
if (!redis) return await Promise.all(keys.map((key) => state.get(key)));
|
|
269
|
-
return (await redis.getClient().mGet(keys.map(redisStateKey))).map((value) => {
|
|
270
|
-
if (value === null) return null;
|
|
271
|
-
try {
|
|
272
|
-
return JSON.parse(value);
|
|
273
|
-
} catch {
|
|
274
|
-
return value;
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
/** Write state values with one TTL in one Redis round trip. */
|
|
279
|
-
async function setStateValues(state, entries, ttlMs) {
|
|
280
|
-
if (entries.length === 0) return;
|
|
281
|
-
const redis = await getDefaultRedisStateAdapterFor(state);
|
|
282
|
-
if (!redis) {
|
|
283
|
-
await Promise.all(entries.map(({ key, value }) => state.set(key, value, ttlMs)));
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
const pipeline = redis.getClient().multi();
|
|
287
|
-
for (const { key, value } of entries) pipeline.set(redisStateKey(key), JSON.stringify(value), { PX: ttlMs });
|
|
288
|
-
await pipeline.execAsPipeline();
|
|
289
|
-
}
|
|
290
|
-
function getStateAdapter() {
|
|
291
|
-
if (!stateAdapter) stateAdapter = createStateAdapter();
|
|
292
|
-
return stateAdapter;
|
|
293
|
-
}
|
|
294
|
-
async function disconnectStateAdapter() {
|
|
295
|
-
if (!stateAdapter) return;
|
|
296
|
-
try {
|
|
297
|
-
await stateAdapter.disconnect();
|
|
298
|
-
} finally {
|
|
299
|
-
stateAdapter = void 0;
|
|
300
|
-
redisStateAdapter = void 0;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
export { setStateValues as a, fenceLock as c, getStateValues as i, withLock as l, getDefaultRedisStateAdapterFor as n, MUTATION_LOCK_TTL_MS as o, getStateAdapter as r, acquireActiveLock as s, disconnectStateAdapter as t };
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import * as z from "zod";
|
|
2
|
-
// src/api/schema/common.ts
|
|
3
|
-
/** Stable error body returned by Junior-owned REST endpoints. */
|
|
4
|
-
const apiErrorSchema = z.object({ error: z.string().min(1) }).strict();
|
|
5
|
-
// src/chat/conversations/web-message-id.ts
|
|
6
|
-
/**
|
|
7
|
-
* Build the retry-stable Message id shared by web ingress and browser sends.
|
|
8
|
-
* Keep the existing hash and prefix so retries still address stored Messages.
|
|
9
|
-
*/
|
|
10
|
-
async function webMessageId(args) {
|
|
11
|
-
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${args.conversationId}\u0000${args.idempotencyKey}`));
|
|
12
|
-
return `api-msg:${Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("").slice(0, 24)}`;
|
|
13
|
-
}
|
|
14
|
-
// src/api/reporting-window.ts
|
|
15
|
-
/** Shared UTC day/hour/six-hour windows for dashboard activity series. */
|
|
16
|
-
const HOUR_MS = 36e5;
|
|
17
|
-
const SIX_HOUR_MS = 6 * HOUR_MS;
|
|
18
|
-
const DAY_MS = 24 * HOUR_MS;
|
|
19
|
-
/** Start of the UTC calendar day containing `valueMs`. */
|
|
20
|
-
function startOfUtcDay(valueMs) {
|
|
21
|
-
const date = new Date(valueMs);
|
|
22
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
23
|
-
return date;
|
|
24
|
-
}
|
|
25
|
-
/** Start of the UTC hour containing `valueMs`. */
|
|
26
|
-
function startOfUtcHour(valueMs) {
|
|
27
|
-
const date = new Date(valueMs);
|
|
28
|
-
date.setUTCMinutes(0, 0, 0);
|
|
29
|
-
return date;
|
|
30
|
-
}
|
|
31
|
-
/** Start of the UTC 6-hour bucket containing `valueMs` (00/06/12/18). */
|
|
32
|
-
function startOfUtcSixHour(valueMs) {
|
|
33
|
-
const date = startOfUtcHour(valueMs);
|
|
34
|
-
date.setUTCHours(Math.floor(date.getUTCHours() / 6) * 6, 0, 0, 0);
|
|
35
|
-
return date;
|
|
36
|
-
}
|
|
37
|
-
/** UTC day key `YYYY-MM-DD`. */
|
|
38
|
-
function utcDayKey(value) {
|
|
39
|
-
return (typeof value === "number" ? new Date(value) : value).toISOString().slice(0, 10);
|
|
40
|
-
}
|
|
41
|
-
/** UTC hour key `YYYY-MM-DDTHH`. */
|
|
42
|
-
function utcHourKey(value) {
|
|
43
|
-
return (typeof value === "number" ? new Date(value) : value).toISOString().slice(0, 13);
|
|
44
|
-
}
|
|
45
|
-
/** UTC 6-hour bucket key `YYYY-MM-DDTHH` at 00/06/12/18. */
|
|
46
|
-
function utcSixHourKey(value) {
|
|
47
|
-
return utcHourKey(startOfUtcSixHour(typeof value === "number" ? value : value.getTime()));
|
|
48
|
-
}
|
|
49
|
-
/** Inclusive trailing UTC day window ending on today's UTC day. */
|
|
50
|
-
function trailingUtcDayWindow(nowMs, dayCount) {
|
|
51
|
-
const end = startOfUtcDay(nowMs);
|
|
52
|
-
const start = new Date(end);
|
|
53
|
-
start.setUTCDate(start.getUTCDate() - (dayCount - 1));
|
|
54
|
-
return {
|
|
55
|
-
end,
|
|
56
|
-
start
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
/** Inclusive trailing UTC hour window ending on the current UTC hour. */
|
|
60
|
-
function trailingUtcHourWindow(nowMs, hourCount = 24) {
|
|
61
|
-
const end = startOfUtcHour(nowMs);
|
|
62
|
-
return {
|
|
63
|
-
end,
|
|
64
|
-
start: /* @__PURE__ */ new Date(end.getTime() - (hourCount - 1) * HOUR_MS)
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
/** Inclusive trailing UTC 6-hour window ending on the current 6h bucket. */
|
|
68
|
-
function trailingUtcSixHourWindow(nowMs, bucketCount = 28) {
|
|
69
|
-
const end = startOfUtcSixHour(nowMs);
|
|
70
|
-
return {
|
|
71
|
-
end,
|
|
72
|
-
start: /* @__PURE__ */ new Date(end.getTime() - (bucketCount - 1) * SIX_HOUR_MS)
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
/** Fill a fixed UTC day window from a sparse map. */
|
|
76
|
-
function fillUtcDays(args) {
|
|
77
|
-
const { end, start } = trailingUtcDayWindow(args.nowMs, args.count);
|
|
78
|
-
const items = [];
|
|
79
|
-
for (const cursor = new Date(start); cursor.getTime() <= end.getTime(); cursor.setUTCDate(cursor.getUTCDate() + 1)) {
|
|
80
|
-
const date = utcDayKey(cursor);
|
|
81
|
-
items.push(args.rows.get(date) ?? args.empty(date));
|
|
82
|
-
}
|
|
83
|
-
return items;
|
|
84
|
-
}
|
|
85
|
-
/** Fill a fixed UTC hour window from a sparse map. */
|
|
86
|
-
function fillUtcHours(args) {
|
|
87
|
-
const hourCount = args.count ?? 24;
|
|
88
|
-
const { end, start } = trailingUtcHourWindow(args.nowMs, hourCount);
|
|
89
|
-
const items = [];
|
|
90
|
-
for (const cursor = new Date(start); cursor.getTime() <= end.getTime(); cursor.setTime(cursor.getTime() + HOUR_MS)) {
|
|
91
|
-
const date = utcHourKey(cursor);
|
|
92
|
-
items.push(args.rows.get(date) ?? args.empty(date));
|
|
93
|
-
}
|
|
94
|
-
return items;
|
|
95
|
-
}
|
|
96
|
-
/** Fill a fixed UTC 6-hour window from a map of known rows. */
|
|
97
|
-
function fillUtcSixHours(args) {
|
|
98
|
-
const bucketCount = args.count ?? 28;
|
|
99
|
-
const { end, start } = trailingUtcSixHourWindow(args.nowMs, bucketCount);
|
|
100
|
-
const items = [];
|
|
101
|
-
for (const cursor = new Date(start); cursor.getTime() <= end.getTime(); cursor.setTime(cursor.getTime() + SIX_HOUR_MS)) {
|
|
102
|
-
const date = utcSixHourKey(cursor);
|
|
103
|
-
items.push(args.rows.get(date) ?? args.empty(date));
|
|
104
|
-
}
|
|
105
|
-
return items;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Sum hour rows into trailing 6-hour buckets.
|
|
109
|
-
* Adds number fields. Keeps other fields from the first row in the bucket.
|
|
110
|
-
* Sets `date` to the 6-hour bucket key.
|
|
111
|
-
*/
|
|
112
|
-
function sumUtcHoursIntoSixHours(args) {
|
|
113
|
-
const bucketCount = args.count ?? 28;
|
|
114
|
-
const bySix = /* @__PURE__ */ new Map();
|
|
115
|
-
for (const hour of args.hours) {
|
|
116
|
-
const key = utcSixHourKey(Date.parse(`${hour.date}:00:00.000Z`));
|
|
117
|
-
const next = {
|
|
118
|
-
...bySix.get(key) ?? args.empty(key),
|
|
119
|
-
date: key
|
|
120
|
-
};
|
|
121
|
-
for (const [field, value] of Object.entries(hour)) {
|
|
122
|
-
if (field === "date") continue;
|
|
123
|
-
if (typeof value === "number") {
|
|
124
|
-
const prior = next[field];
|
|
125
|
-
next[field] = (typeof prior === "number" ? prior : 0) + value;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
bySix.set(key, next);
|
|
129
|
-
}
|
|
130
|
-
return fillUtcSixHours({
|
|
131
|
-
count: bucketCount,
|
|
132
|
-
empty: args.empty,
|
|
133
|
-
nowMs: args.nowMs,
|
|
134
|
-
rows: bySix
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
export { fillUtcSixHours as a, trailingUtcDayWindow as c, utcDayKey as d, utcHourKey as f, fillUtcHours as i, trailingUtcHourWindow as l, apiErrorSchema as m, HOUR_MS as n, startOfUtcHour as o, webMessageId as p, fillUtcDays as r, sumUtcHoursIntoSixHours as s, DAY_MS as t, trailingUtcSixHourWindow as u };
|