@sentry/junior 0.73.0 → 0.74.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/api-reference.d.ts +1 -1
- package/dist/app.js +258 -62
- package/dist/chat/app/production.d.ts +3 -0
- package/dist/chat/config.d.ts +3 -0
- package/dist/chat/conversations/configured.d.ts +5 -0
- package/dist/chat/conversations/sql/migrations.d.ts +11 -0
- package/dist/chat/conversations/sql/schema/conversations.d.ts +435 -0
- package/dist/chat/conversations/sql/schema/destinations.d.ts +200 -0
- package/dist/chat/conversations/sql/schema/identities.d.ts +214 -0
- package/dist/chat/conversations/sql/schema/migrations.d.ts +58 -0
- package/dist/chat/conversations/sql/schema/timestamps.d.ts +1 -0
- package/dist/chat/conversations/sql/schema.d.ts +910 -0
- package/dist/chat/conversations/sql/store.d.ts +52 -0
- package/dist/chat/conversations/state.d.ts +4 -0
- package/dist/chat/conversations/store.d.ts +57 -0
- package/dist/chat/ingress/slack-webhook.d.ts +2 -0
- package/dist/chat/plugins/agent-hooks.d.ts +2 -2
- package/dist/chat/respond.d.ts +1 -1
- package/dist/chat/services/mcp-auth-orchestration.d.ts +6 -5
- package/dist/chat/services/pending-auth.d.ts +2 -0
- package/dist/chat/services/plugin-auth-orchestration.d.ts +7 -6
- package/dist/chat/sql/db.d.ts +20 -0
- package/dist/chat/sql/neon.d.ts +9 -0
- package/dist/chat/sql/schema.d.ts +906 -0
- package/dist/chat/state/turn-session.d.ts +3 -0
- package/dist/chat/task-execution/slack-work.d.ts +2 -0
- package/dist/chat/task-execution/state.d.ts +209 -0
- package/dist/chat/task-execution/store.d.ts +30 -114
- package/dist/chat/task-execution/vercel-callback.d.ts +2 -0
- package/dist/chat/task-execution/worker.d.ts +2 -0
- package/dist/{chunk-ZDA2HYX5.js → chunk-2LUZA3LY.js} +3 -3
- package/dist/{chunk-RY6AL5C7.js → chunk-6UP2Z2RZ.js} +2 -2
- package/dist/{chunk-DIMX5F3T.js → chunk-F6HWCPOC.js} +1 -1
- package/dist/{chunk-WS2EG3GW.js → chunk-GM7HTXYC.js} +6 -0
- package/dist/{chunk-UZVHXZ7V.js → chunk-HYHKTFG2.js} +59 -15
- package/dist/chunk-JL2SLRAT.js +1970 -0
- package/dist/{chunk-OQSYYOLM.js → chunk-SQGMG7OD.js} +128 -114
- package/dist/{chunk-QUXPUKBH.js → chunk-Y7X25LFY.js} +1 -1
- package/dist/{chunk-UOTZ3EEQ.js → chunk-YOHFWWBV.js} +1 -1
- package/dist/{chunk-V4VYUY4A.js → chunk-YRDS7VKO.js} +1 -1
- package/dist/cli/chat.js +2 -2
- package/dist/cli/init.js +1 -1
- package/dist/cli/snapshot-warmup.js +3 -3
- package/dist/cli/upgrade.js +77 -7
- package/dist/instrumentation.js +0 -1
- package/dist/nitro.js +3 -3
- package/dist/reporting/conversations.d.ts +13 -3
- package/dist/reporting.d.ts +9 -2
- package/dist/reporting.js +101 -37
- package/dist/{runner-LMAM4OGD.js → runner-27NP2TEO.js} +7 -7
- package/dist/vercel.d.ts +6 -1
- package/dist/vercel.js +1 -1
- package/package.json +9 -4
- package/dist/chunk-AL5T52ZD.js +0 -1119
package/dist/app.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
pluginHookRegistrationsFromPluginSet,
|
|
6
6
|
resolveConversationWorkQueueTopic,
|
|
7
7
|
verifyConversationQueueMessage
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-YOHFWWBV.js";
|
|
9
9
|
import {
|
|
10
10
|
GET,
|
|
11
11
|
buildSentryConversationUrl,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
resolveSlackChannelTypeFromMessage,
|
|
14
14
|
resolveSlackConversationContext,
|
|
15
15
|
setConversationTitle
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-2LUZA3LY.js";
|
|
17
17
|
import {
|
|
18
18
|
AuthorizationFlowDisabledError,
|
|
19
19
|
PluginCredentialFailureError,
|
|
@@ -85,7 +85,7 @@ import {
|
|
|
85
85
|
updateConversationStats,
|
|
86
86
|
uploadFilesToThread,
|
|
87
87
|
upsertConversationMessage
|
|
88
|
-
} from "./chunk-
|
|
88
|
+
} from "./chunk-SQGMG7OD.js";
|
|
89
89
|
import {
|
|
90
90
|
abandonAgentTurnSessionRecord,
|
|
91
91
|
bindSlackDirectCredentialSubject,
|
|
@@ -99,6 +99,7 @@ import {
|
|
|
99
99
|
getAgentPluginSlackConversationLink,
|
|
100
100
|
getAgentPlugins,
|
|
101
101
|
getAgentTurnSessionRecord,
|
|
102
|
+
getConfiguredConversationStore,
|
|
102
103
|
getInterruptionMarker,
|
|
103
104
|
listAgentTurnSessionSummariesForConversation,
|
|
104
105
|
loadProjection,
|
|
@@ -110,7 +111,7 @@ import {
|
|
|
110
111
|
truncateStatusText,
|
|
111
112
|
validateAgentPlugins,
|
|
112
113
|
verifySlackDirectCredentialSubject
|
|
113
|
-
} from "./chunk-
|
|
114
|
+
} from "./chunk-HYHKTFG2.js";
|
|
114
115
|
import {
|
|
115
116
|
discoverSkills
|
|
116
117
|
} from "./chunk-OR6NQJ5E.js";
|
|
@@ -121,14 +122,13 @@ import {
|
|
|
121
122
|
CONVERSATION_WORK_CHECK_IN_INTERVAL_MS,
|
|
122
123
|
CONVERSATION_WORK_STALE_ENQUEUE_MS,
|
|
123
124
|
JUNIOR_THREAD_STATE_TTL_MS,
|
|
124
|
-
|
|
125
|
+
appendInboundMessage,
|
|
125
126
|
checkInConversationWork,
|
|
126
127
|
clearExpiredConversationLease,
|
|
127
128
|
completeConversationWork,
|
|
128
|
-
countPendingConversationMessages,
|
|
129
129
|
drainConversationMailbox,
|
|
130
|
+
getConversation,
|
|
130
131
|
getConversationWorkState,
|
|
131
|
-
hasRunnableConversationWork,
|
|
132
132
|
listActiveConversationIds,
|
|
133
133
|
markConversationMessagesInjected,
|
|
134
134
|
markConversationWorkEnqueued,
|
|
@@ -137,7 +137,7 @@ import {
|
|
|
137
137
|
requestConversationContinuation,
|
|
138
138
|
requestConversationWork,
|
|
139
139
|
startConversationWork
|
|
140
|
-
} from "./chunk-
|
|
140
|
+
} from "./chunk-JL2SLRAT.js";
|
|
141
141
|
import {
|
|
142
142
|
createSlackDestination,
|
|
143
143
|
destinationKey,
|
|
@@ -149,8 +149,8 @@ import {
|
|
|
149
149
|
parseDestination,
|
|
150
150
|
requireSlackDestination,
|
|
151
151
|
sameDestination
|
|
152
|
-
} from "./chunk-
|
|
153
|
-
import "./chunk-
|
|
152
|
+
} from "./chunk-YRDS7VKO.js";
|
|
153
|
+
import "./chunk-6UP2Z2RZ.js";
|
|
154
154
|
import "./chunk-G3E7SCME.js";
|
|
155
155
|
import {
|
|
156
156
|
CredentialUnavailableError,
|
|
@@ -169,7 +169,7 @@ import {
|
|
|
169
169
|
import {
|
|
170
170
|
ACTIVE_LOCK_TTL_MS,
|
|
171
171
|
getStateAdapter
|
|
172
|
-
} from "./chunk-
|
|
172
|
+
} from "./chunk-F6HWCPOC.js";
|
|
173
173
|
import {
|
|
174
174
|
FUNCTION_TIMEOUT_BUFFER_SECONDS,
|
|
175
175
|
GEN_AI_PROVIDER_NAME,
|
|
@@ -191,7 +191,7 @@ import {
|
|
|
191
191
|
setSlackReactionConfig,
|
|
192
192
|
stripRuntimeTurnContext,
|
|
193
193
|
trimTrailingAssistantMessages
|
|
194
|
-
} from "./chunk-
|
|
194
|
+
} from "./chunk-GM7HTXYC.js";
|
|
195
195
|
import {
|
|
196
196
|
createRequester,
|
|
197
197
|
createRequesterFromStoredSlackRequester,
|
|
@@ -1215,6 +1215,173 @@ async function POST(request, waitUntil, options = {}) {
|
|
|
1215
1215
|
// src/handlers/heartbeat.ts
|
|
1216
1216
|
import { timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
1217
1217
|
|
|
1218
|
+
// src/chat/task-execution/store.ts
|
|
1219
|
+
function metadataStore(options) {
|
|
1220
|
+
return options.conversationStore ?? getConfiguredConversationStore();
|
|
1221
|
+
}
|
|
1222
|
+
function duplicateInboundNudgeIdempotencyKey(message, nowMs) {
|
|
1223
|
+
return `duplicate:${message.conversationId}:${message.inboundMessageId}:${nowMs}`;
|
|
1224
|
+
}
|
|
1225
|
+
function hasRecentEnqueueMarker(conversation, nowMs) {
|
|
1226
|
+
const lastEnqueuedAtMs = conversation.execution.lastEnqueuedAtMs;
|
|
1227
|
+
return typeof lastEnqueuedAtMs === "number" && lastEnqueuedAtMs + CONVERSATION_WORK_STALE_ENQUEUE_MS > nowMs;
|
|
1228
|
+
}
|
|
1229
|
+
function now() {
|
|
1230
|
+
return Date.now();
|
|
1231
|
+
}
|
|
1232
|
+
async function recordExecutionMetadata(args) {
|
|
1233
|
+
try {
|
|
1234
|
+
const conversation = await getConversation({
|
|
1235
|
+
conversationId: args.conversationId,
|
|
1236
|
+
state: args.state
|
|
1237
|
+
});
|
|
1238
|
+
if (!conversation) {
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
await metadataStore(args).recordExecution({
|
|
1242
|
+
channelName: conversation.channelName,
|
|
1243
|
+
conversationId: conversation.conversationId,
|
|
1244
|
+
createdAtMs: conversation.createdAtMs,
|
|
1245
|
+
destination: conversation.destination,
|
|
1246
|
+
execution: {
|
|
1247
|
+
lastCheckpointAtMs: conversation.execution.lastCheckpointAtMs,
|
|
1248
|
+
lastEnqueuedAtMs: conversation.execution.lastEnqueuedAtMs,
|
|
1249
|
+
runId: conversation.execution.runId,
|
|
1250
|
+
status: conversation.execution.status,
|
|
1251
|
+
updatedAtMs: conversation.execution.updatedAtMs
|
|
1252
|
+
},
|
|
1253
|
+
lastActivityAtMs: conversation.lastActivityAtMs,
|
|
1254
|
+
requester: conversation.requester,
|
|
1255
|
+
source: conversation.source,
|
|
1256
|
+
title: conversation.title,
|
|
1257
|
+
updatedAtMs: conversation.updatedAtMs
|
|
1258
|
+
});
|
|
1259
|
+
} catch (error) {
|
|
1260
|
+
logWarn(
|
|
1261
|
+
"conversation_execution_metadata_update_failed",
|
|
1262
|
+
{ conversationId: args.conversationId },
|
|
1263
|
+
{
|
|
1264
|
+
"exception.message": error instanceof Error ? error.message : String(error)
|
|
1265
|
+
},
|
|
1266
|
+
"Failed to update conversation execution metadata"
|
|
1267
|
+
);
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
async function getConversationWorkState2(args) {
|
|
1271
|
+
return await getConversationWorkState(args);
|
|
1272
|
+
}
|
|
1273
|
+
function countPendingConversationMessages(conversation) {
|
|
1274
|
+
return conversation.execution.pendingMessages.length;
|
|
1275
|
+
}
|
|
1276
|
+
function hasRunnableConversationWork(conversation) {
|
|
1277
|
+
return conversation.execution.status !== "idle" || countPendingConversationMessages(conversation) > 0;
|
|
1278
|
+
}
|
|
1279
|
+
async function appendAndEnqueueInboundMessage(args) {
|
|
1280
|
+
const nowMs = args.nowMs ?? now();
|
|
1281
|
+
const appendResult = await appendInboundMessage({
|
|
1282
|
+
message: args.message,
|
|
1283
|
+
nowMs,
|
|
1284
|
+
state: args.state
|
|
1285
|
+
});
|
|
1286
|
+
let idempotencyKey = args.message.inboundMessageId;
|
|
1287
|
+
if (appendResult.status === "duplicate") {
|
|
1288
|
+
const conversation = await getConversation({
|
|
1289
|
+
conversationId: args.message.conversationId,
|
|
1290
|
+
state: args.state
|
|
1291
|
+
});
|
|
1292
|
+
if (!conversation || hasRecentEnqueueMarker(conversation, nowMs)) {
|
|
1293
|
+
return appendResult;
|
|
1294
|
+
}
|
|
1295
|
+
const duplicateStillPending = conversation.execution.pendingMessages.some(
|
|
1296
|
+
(message) => message.inboundMessageId === args.message.inboundMessageId
|
|
1297
|
+
);
|
|
1298
|
+
if (!duplicateStillPending) {
|
|
1299
|
+
return appendResult;
|
|
1300
|
+
}
|
|
1301
|
+
idempotencyKey = duplicateInboundNudgeIdempotencyKey(args.message, nowMs);
|
|
1302
|
+
}
|
|
1303
|
+
const queueResult = await args.queue.send(
|
|
1304
|
+
{
|
|
1305
|
+
conversationId: args.message.conversationId,
|
|
1306
|
+
destination: args.message.destination
|
|
1307
|
+
},
|
|
1308
|
+
{ idempotencyKey }
|
|
1309
|
+
);
|
|
1310
|
+
await markConversationWorkEnqueued2({
|
|
1311
|
+
conversationId: args.message.conversationId,
|
|
1312
|
+
conversationStore: args.conversationStore,
|
|
1313
|
+
nowMs,
|
|
1314
|
+
state: args.state
|
|
1315
|
+
});
|
|
1316
|
+
return {
|
|
1317
|
+
...appendResult,
|
|
1318
|
+
queueMessageId: queueResult?.messageId
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
async function requestConversationWork2(args) {
|
|
1322
|
+
const result = await requestConversationWork(args);
|
|
1323
|
+
await recordExecutionMetadata({
|
|
1324
|
+
conversationId: args.conversationId,
|
|
1325
|
+
conversationStore: args.conversationStore,
|
|
1326
|
+
state: args.state
|
|
1327
|
+
});
|
|
1328
|
+
return result;
|
|
1329
|
+
}
|
|
1330
|
+
async function markConversationWorkEnqueued2(args) {
|
|
1331
|
+
await markConversationWorkEnqueued(args);
|
|
1332
|
+
await recordExecutionMetadata(args);
|
|
1333
|
+
}
|
|
1334
|
+
async function startConversationWork2(args) {
|
|
1335
|
+
const result = await startConversationWork(args);
|
|
1336
|
+
await recordExecutionMetadata(args);
|
|
1337
|
+
return result;
|
|
1338
|
+
}
|
|
1339
|
+
async function checkInConversationWork2(args) {
|
|
1340
|
+
const result = await checkInConversationWork(args);
|
|
1341
|
+
if (result) {
|
|
1342
|
+
await recordExecutionMetadata(args);
|
|
1343
|
+
}
|
|
1344
|
+
return result;
|
|
1345
|
+
}
|
|
1346
|
+
async function drainConversationMailbox2(args) {
|
|
1347
|
+
const result = await drainConversationMailbox(args);
|
|
1348
|
+
if (result.length > 0) {
|
|
1349
|
+
await recordExecutionMetadata(args);
|
|
1350
|
+
}
|
|
1351
|
+
return result;
|
|
1352
|
+
}
|
|
1353
|
+
async function markConversationMessagesInjected2(args) {
|
|
1354
|
+
const result = await markConversationMessagesInjected(args);
|
|
1355
|
+
await recordExecutionMetadata(args);
|
|
1356
|
+
return result;
|
|
1357
|
+
}
|
|
1358
|
+
async function requestConversationContinuation2(args) {
|
|
1359
|
+
const result = await requestConversationContinuation(args);
|
|
1360
|
+
await recordExecutionMetadata(args);
|
|
1361
|
+
return result;
|
|
1362
|
+
}
|
|
1363
|
+
async function releaseConversationWork2(args) {
|
|
1364
|
+
const result = await releaseConversationWork(args);
|
|
1365
|
+
await recordExecutionMetadata(args);
|
|
1366
|
+
return result;
|
|
1367
|
+
}
|
|
1368
|
+
async function completeConversationWork2(args) {
|
|
1369
|
+
const result = await completeConversationWork(args);
|
|
1370
|
+
await recordExecutionMetadata(args);
|
|
1371
|
+
return result;
|
|
1372
|
+
}
|
|
1373
|
+
async function clearExpiredConversationLease2(args) {
|
|
1374
|
+
const result = await clearExpiredConversationLease(args);
|
|
1375
|
+
await recordExecutionMetadata(args);
|
|
1376
|
+
return result;
|
|
1377
|
+
}
|
|
1378
|
+
async function removeActiveConversation2(args) {
|
|
1379
|
+
return await removeActiveConversation(args);
|
|
1380
|
+
}
|
|
1381
|
+
async function listActiveConversationIds2(args = {}) {
|
|
1382
|
+
return await listActiveConversationIds(args);
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1218
1385
|
// src/chat/task-execution/heartbeat.ts
|
|
1219
1386
|
var DEFAULT_RECOVERY_LIMIT = 25;
|
|
1220
1387
|
function heartbeatIdempotencyKey(reason, conversationId, nowMs) {
|
|
@@ -1228,7 +1395,7 @@ async function sendRecoveryNudge(args) {
|
|
|
1228
1395
|
},
|
|
1229
1396
|
{ idempotencyKey: args.idempotencyKey }
|
|
1230
1397
|
);
|
|
1231
|
-
await
|
|
1398
|
+
await markConversationWorkEnqueued2({
|
|
1232
1399
|
conversationId: args.conversationId,
|
|
1233
1400
|
nowMs: args.nowMs,
|
|
1234
1401
|
state: args.state
|
|
@@ -1240,26 +1407,26 @@ async function recoverConversationWork(args) {
|
|
|
1240
1407
|
pendingCount: 0
|
|
1241
1408
|
};
|
|
1242
1409
|
const staleBeforeMs = args.nowMs - CONVERSATION_WORK_STALE_ENQUEUE_MS;
|
|
1243
|
-
const ids = await
|
|
1410
|
+
const ids = await listActiveConversationIds2({
|
|
1244
1411
|
limit: args.limit ?? DEFAULT_RECOVERY_LIMIT,
|
|
1245
1412
|
staleBeforeMs,
|
|
1246
1413
|
state: args.state
|
|
1247
1414
|
});
|
|
1248
1415
|
for (const conversationId of ids) {
|
|
1249
1416
|
try {
|
|
1250
|
-
const work = await
|
|
1417
|
+
const work = await getConversationWorkState2({
|
|
1251
1418
|
conversationId,
|
|
1252
1419
|
state: args.state
|
|
1253
1420
|
});
|
|
1254
1421
|
if (!work) {
|
|
1255
|
-
await
|
|
1422
|
+
await removeActiveConversation2({
|
|
1256
1423
|
conversationId,
|
|
1257
1424
|
state: args.state
|
|
1258
1425
|
});
|
|
1259
1426
|
continue;
|
|
1260
1427
|
}
|
|
1261
1428
|
if (work.execution.status === "idle") {
|
|
1262
|
-
await
|
|
1429
|
+
await removeActiveConversation2({
|
|
1263
1430
|
conversationId,
|
|
1264
1431
|
state: args.state
|
|
1265
1432
|
});
|
|
@@ -1270,7 +1437,7 @@ async function recoverConversationWork(args) {
|
|
|
1270
1437
|
continue;
|
|
1271
1438
|
}
|
|
1272
1439
|
if (work.execution.lease && work.execution.lease.expiresAtMs <= args.nowMs) {
|
|
1273
|
-
const cleared = await
|
|
1440
|
+
const cleared = await clearExpiredConversationLease2({
|
|
1274
1441
|
conversationId,
|
|
1275
1442
|
nowMs: args.nowMs,
|
|
1276
1443
|
state: args.state
|
|
@@ -1804,7 +1971,7 @@ var STATUS_UPDATE_DEBOUNCE_MS = 1e3;
|
|
|
1804
1971
|
var STATUS_MIN_VISIBLE_MS = 1200;
|
|
1805
1972
|
var STATUS_ROTATION_INTERVAL_MS = 3e4;
|
|
1806
1973
|
function createAssistantStatusScheduler(args) {
|
|
1807
|
-
const
|
|
1974
|
+
const now3 = args.now ?? (() => Date.now());
|
|
1808
1975
|
const setTimer = args.setTimer ?? ((callback, delayMs) => setTimeout(callback, delayMs));
|
|
1809
1976
|
const clearTimer = args.clearTimer ?? ((timer) => clearTimeout(timer));
|
|
1810
1977
|
const random = args.random ?? Math.random;
|
|
@@ -1868,7 +2035,7 @@ function createAssistantStatusScheduler(args) {
|
|
|
1868
2035
|
}
|
|
1869
2036
|
currentVisibleStatus = text;
|
|
1870
2037
|
currentLoadingMessages = nextLoadingMessages;
|
|
1871
|
-
lastStatusAt =
|
|
2038
|
+
lastStatusAt = now3();
|
|
1872
2039
|
scheduleRotation();
|
|
1873
2040
|
await enqueueStatusUpdate(async () => {
|
|
1874
2041
|
await args.sendStatus(text, nextLoadingMessages);
|
|
@@ -1951,7 +2118,7 @@ function createAssistantStatusScheduler(args) {
|
|
|
1951
2118
|
}
|
|
1952
2119
|
return;
|
|
1953
2120
|
}
|
|
1954
|
-
const elapsed =
|
|
2121
|
+
const elapsed = now3() - lastStatusAt;
|
|
1955
2122
|
const waitMs = Math.max(
|
|
1956
2123
|
STATUS_UPDATE_DEBOUNCE_MS - elapsed,
|
|
1957
2124
|
STATUS_MIN_VISIBLE_MS - elapsed,
|
|
@@ -2773,7 +2940,7 @@ async function getAwaitingAgentContinueRequest(args) {
|
|
|
2773
2940
|
}
|
|
2774
2941
|
async function scheduleAgentContinue(request, options = {}) {
|
|
2775
2942
|
const nowMs = options.nowMs ?? Date.now();
|
|
2776
|
-
await
|
|
2943
|
+
await requestConversationWork2({
|
|
2777
2944
|
conversationId: request.conversationId,
|
|
2778
2945
|
destination: request.destination,
|
|
2779
2946
|
nowMs,
|
|
@@ -2795,7 +2962,7 @@ async function scheduleAgentContinue(request, options = {}) {
|
|
|
2795
2962
|
].join(":")
|
|
2796
2963
|
}
|
|
2797
2964
|
);
|
|
2798
|
-
await
|
|
2965
|
+
await markConversationWorkEnqueued2({
|
|
2799
2966
|
conversationId: request.conversationId,
|
|
2800
2967
|
nowMs,
|
|
2801
2968
|
state: options.state
|
|
@@ -3066,7 +3233,7 @@ async function resumeAuthorizedMcpTurn(args) {
|
|
|
3066
3233
|
pendingAuth: lockedPendingAuth,
|
|
3067
3234
|
channelConfiguration: lockedChannelConfiguration,
|
|
3068
3235
|
sandbox: getPersistedSandboxState(lockedState),
|
|
3069
|
-
|
|
3236
|
+
recordPendingAuth: async (nextPendingAuth) => {
|
|
3070
3237
|
await applyPendingAuthUpdate({
|
|
3071
3238
|
conversation: lockedConversation,
|
|
3072
3239
|
conversationId: authSession.conversationId,
|
|
@@ -3851,7 +4018,7 @@ async function resumeOAuthSessionRecordTurn(stored, options) {
|
|
|
3851
4018
|
channelConfiguration: lockedChannelConfiguration,
|
|
3852
4019
|
piMessages: lockedConversation.piMessages,
|
|
3853
4020
|
sandbox: getPersistedSandboxState(lockedState),
|
|
3854
|
-
|
|
4021
|
+
recordPendingAuth: async (nextPendingAuth) => {
|
|
3855
4022
|
await applyPendingAuthUpdate({
|
|
3856
4023
|
conversation: lockedConversation,
|
|
3857
4024
|
conversationId: stored.resumeConversationId,
|
|
@@ -4367,9 +4534,9 @@ function buildJwksUrl(value) {
|
|
|
4367
4534
|
return url;
|
|
4368
4535
|
}
|
|
4369
4536
|
async function getJwks(issuer) {
|
|
4370
|
-
const
|
|
4537
|
+
const now3 = Date.now();
|
|
4371
4538
|
const cached = jwksByIssuer.get(issuer);
|
|
4372
|
-
if (cached && cached.expiresAtMs >
|
|
4539
|
+
if (cached && cached.expiresAtMs > now3) {
|
|
4373
4540
|
return cached.jwks;
|
|
4374
4541
|
}
|
|
4375
4542
|
if (cached) {
|
|
@@ -4394,7 +4561,7 @@ async function getJwks(issuer) {
|
|
|
4394
4561
|
}
|
|
4395
4562
|
jwksByIssuer.set(issuer, {
|
|
4396
4563
|
jwks,
|
|
4397
|
-
expiresAtMs:
|
|
4564
|
+
expiresAtMs: now3 + OIDC_DISCOVERY_CACHE_TTL_MS
|
|
4398
4565
|
});
|
|
4399
4566
|
return jwks;
|
|
4400
4567
|
}
|
|
@@ -7956,7 +8123,7 @@ function createReplyToThread(deps) {
|
|
|
7956
8123
|
artifacts: latestArtifacts
|
|
7957
8124
|
});
|
|
7958
8125
|
},
|
|
7959
|
-
|
|
8126
|
+
recordPendingAuth: async (pendingAuth) => {
|
|
7960
8127
|
await applyPendingAuthUpdate({
|
|
7961
8128
|
conversation: preparedState.conversation,
|
|
7962
8129
|
conversationId,
|
|
@@ -8875,7 +9042,7 @@ function createSlackConversationWorker(options) {
|
|
|
8875
9042
|
const state = getConnectedState2(options.state);
|
|
8876
9043
|
await state.connect();
|
|
8877
9044
|
const records = getPendingRecords(
|
|
8878
|
-
await
|
|
9045
|
+
await getConversationWorkState2({
|
|
8879
9046
|
conversationId: context.conversationId,
|
|
8880
9047
|
state
|
|
8881
9048
|
})
|
|
@@ -8939,10 +9106,11 @@ function createSlackConversationWorker(options) {
|
|
|
8939
9106
|
if (initialMessagesPersisted) {
|
|
8940
9107
|
return true;
|
|
8941
9108
|
}
|
|
8942
|
-
const marked = await
|
|
9109
|
+
const marked = await markConversationMessagesInjected2({
|
|
8943
9110
|
conversationId: context.conversationId,
|
|
8944
9111
|
inboundMessageIds: initialInboundMessageIds,
|
|
8945
9112
|
leaseToken: context.leaseToken,
|
|
9113
|
+
conversationStore: options.conversationStore,
|
|
8946
9114
|
state
|
|
8947
9115
|
});
|
|
8948
9116
|
initialMessagesPersisted = marked;
|
|
@@ -9219,7 +9387,7 @@ async function continueSlackAgentRun(payload, options = {}) {
|
|
|
9219
9387
|
channelConfiguration,
|
|
9220
9388
|
piMessages: conversation.piMessages,
|
|
9221
9389
|
sandbox,
|
|
9222
|
-
|
|
9390
|
+
recordPendingAuth: async (nextPendingAuth) => {
|
|
9223
9391
|
await applyPendingAuthUpdate({
|
|
9224
9392
|
conversation,
|
|
9225
9393
|
conversationId: payload.conversationId,
|
|
@@ -9394,7 +9562,11 @@ function getProductionSlackRuntime() {
|
|
|
9394
9562
|
});
|
|
9395
9563
|
return productionSlackRuntime;
|
|
9396
9564
|
}
|
|
9565
|
+
function getProductionConversationStore() {
|
|
9566
|
+
return getConfiguredConversationStore();
|
|
9567
|
+
}
|
|
9397
9568
|
function createProductionSlackWebhookServices(options) {
|
|
9569
|
+
const conversationStore = getProductionConversationStore();
|
|
9398
9570
|
const runtime = createSlackRuntime({
|
|
9399
9571
|
getSlackAdapter: getProductionSlackAdapter,
|
|
9400
9572
|
services: options?.services
|
|
@@ -9402,27 +9574,33 @@ function createProductionSlackWebhookServices(options) {
|
|
|
9402
9574
|
return {
|
|
9403
9575
|
getSlackAdapter: getProductionSlackAdapter,
|
|
9404
9576
|
getUserTokenStore: createUserTokenStore,
|
|
9577
|
+
conversationStore,
|
|
9405
9578
|
queue: getVercelConversationWorkQueue(),
|
|
9406
9579
|
runtime
|
|
9407
9580
|
};
|
|
9408
9581
|
}
|
|
9409
9582
|
function getProductionSlackWebhookServices() {
|
|
9583
|
+
const conversationStore = getProductionConversationStore();
|
|
9410
9584
|
return {
|
|
9411
9585
|
getSlackAdapter: getProductionSlackAdapter,
|
|
9412
9586
|
getUserTokenStore: createUserTokenStore,
|
|
9587
|
+
conversationStore,
|
|
9413
9588
|
queue: getVercelConversationWorkQueue(),
|
|
9414
9589
|
runtime: getProductionSlackRuntime()
|
|
9415
9590
|
};
|
|
9416
9591
|
}
|
|
9417
9592
|
function createProductionConversationWorkOptions(options) {
|
|
9593
|
+
const conversationStore = getProductionConversationStore();
|
|
9418
9594
|
const runtime = createSlackRuntime({
|
|
9419
9595
|
getSlackAdapter: getProductionSlackAdapter,
|
|
9420
9596
|
services: options?.services
|
|
9421
9597
|
});
|
|
9422
9598
|
return {
|
|
9599
|
+
conversationStore,
|
|
9423
9600
|
queue: getVercelConversationWorkQueue(),
|
|
9424
9601
|
run: createSlackConversationWorker({
|
|
9425
9602
|
getSlackAdapter: getProductionSlackAdapter,
|
|
9603
|
+
conversationStore,
|
|
9426
9604
|
resumeAwaitingContinuation: async (conversationId) => await resumeAwaitingSlackContinuation(conversationId, {
|
|
9427
9605
|
generateReply: withSandboxTracePropagation(
|
|
9428
9606
|
generateAssistantReply,
|
|
@@ -9733,6 +9911,7 @@ async function persistSlackMessage(args) {
|
|
|
9733
9911
|
});
|
|
9734
9912
|
await appendAndEnqueueInboundMessage({
|
|
9735
9913
|
message: inbound,
|
|
9914
|
+
conversationStore: args.conversationStore,
|
|
9736
9915
|
queue: args.queue,
|
|
9737
9916
|
state: args.state
|
|
9738
9917
|
});
|
|
@@ -9754,6 +9933,7 @@ async function routeParsedMessage(args) {
|
|
|
9754
9933
|
adapter: args.adapter,
|
|
9755
9934
|
installation: args.installation,
|
|
9756
9935
|
message: args.message,
|
|
9936
|
+
conversationStore: args.conversationStore,
|
|
9757
9937
|
queue: args.queue,
|
|
9758
9938
|
receivedAtMs: args.receivedAtMs,
|
|
9759
9939
|
route,
|
|
@@ -9780,6 +9960,7 @@ async function handleMessageChanged(args) {
|
|
|
9780
9960
|
adapter: args.adapter,
|
|
9781
9961
|
installation: args.installation,
|
|
9782
9962
|
message: result.message,
|
|
9963
|
+
conversationStore: args.conversationStore,
|
|
9783
9964
|
queue: args.queue,
|
|
9784
9965
|
receivedAtMs: args.receivedAtMs,
|
|
9785
9966
|
route: "mention",
|
|
@@ -9821,6 +10002,7 @@ async function handleSlackEvent(args) {
|
|
|
9821
10002
|
adapter,
|
|
9822
10003
|
body: args.body,
|
|
9823
10004
|
installation,
|
|
10005
|
+
conversationStore: args.services.conversationStore,
|
|
9824
10006
|
queue: args.services.queue,
|
|
9825
10007
|
receivedAtMs,
|
|
9826
10008
|
state
|
|
@@ -9870,6 +10052,7 @@ async function handleSlackEvent(args) {
|
|
|
9870
10052
|
event,
|
|
9871
10053
|
installation,
|
|
9872
10054
|
message,
|
|
10055
|
+
conversationStore: args.services.conversationStore,
|
|
9873
10056
|
queue: args.services.queue,
|
|
9874
10057
|
receivedAtMs,
|
|
9875
10058
|
state
|
|
@@ -10301,7 +10484,7 @@ function isConversationQueueMessageRejectedError(error) {
|
|
|
10301
10484
|
// src/chat/task-execution/worker.ts
|
|
10302
10485
|
var CONVERSATION_WORK_DEFER_DELAY_MS = 15e3;
|
|
10303
10486
|
var CONVERSATION_WORK_SOFT_YIELD_AFTER_MS = 24e4;
|
|
10304
|
-
function
|
|
10487
|
+
function now2(options) {
|
|
10305
10488
|
return options.nowMs?.() ?? Date.now();
|
|
10306
10489
|
}
|
|
10307
10490
|
function nudgeIdempotencyKey(reason, conversationId, nowMs) {
|
|
@@ -10318,26 +10501,29 @@ async function sendWakeNudge(args) {
|
|
|
10318
10501
|
idempotencyKey: args.idempotencyKey
|
|
10319
10502
|
}
|
|
10320
10503
|
);
|
|
10321
|
-
await
|
|
10504
|
+
await markConversationWorkEnqueued2({
|
|
10322
10505
|
conversationId: args.conversationId,
|
|
10506
|
+
conversationStore: args.options.conversationStore,
|
|
10323
10507
|
nowMs: args.nowMs,
|
|
10324
10508
|
state: args.options.state
|
|
10325
10509
|
});
|
|
10326
10510
|
}
|
|
10327
10511
|
async function requestLostLeaseRecovery(args) {
|
|
10328
|
-
const continuationMarked = await
|
|
10512
|
+
const continuationMarked = await requestConversationContinuation2({
|
|
10329
10513
|
conversationId: args.conversationId,
|
|
10330
10514
|
destination: args.destination,
|
|
10331
10515
|
leaseToken: args.leaseToken,
|
|
10516
|
+
conversationStore: args.options.conversationStore,
|
|
10332
10517
|
nowMs: args.nowMs,
|
|
10333
10518
|
state: args.options.state
|
|
10334
10519
|
});
|
|
10335
10520
|
if (!continuationMarked) {
|
|
10336
10521
|
return;
|
|
10337
10522
|
}
|
|
10338
|
-
const released = await
|
|
10523
|
+
const released = await releaseConversationWork2({
|
|
10339
10524
|
conversationId: args.conversationId,
|
|
10340
10525
|
leaseToken: args.leaseToken,
|
|
10526
|
+
conversationStore: args.options.conversationStore,
|
|
10341
10527
|
nowMs: args.nowMs,
|
|
10342
10528
|
state: args.options.state
|
|
10343
10529
|
});
|
|
@@ -10358,10 +10544,11 @@ async function requestLostLeaseRecovery(args) {
|
|
|
10358
10544
|
}
|
|
10359
10545
|
function startLeaseCheckIn(args) {
|
|
10360
10546
|
const timer = setInterval(() => {
|
|
10361
|
-
const nowMs =
|
|
10362
|
-
void
|
|
10547
|
+
const nowMs = now2(args.options);
|
|
10548
|
+
void checkInConversationWork2({
|
|
10363
10549
|
conversationId: args.conversationId,
|
|
10364
10550
|
leaseToken: args.leaseToken,
|
|
10551
|
+
conversationStore: args.options.conversationStore,
|
|
10365
10552
|
nowMs,
|
|
10366
10553
|
state: args.options.state
|
|
10367
10554
|
}).then(
|
|
@@ -10392,7 +10579,7 @@ function startLeaseCheckIn(args) {
|
|
|
10392
10579
|
}
|
|
10393
10580
|
async function processConversationWork(message, options) {
|
|
10394
10581
|
const conversationId = message.conversationId;
|
|
10395
|
-
const initial = await
|
|
10582
|
+
const initial = await getConversationWorkState2({
|
|
10396
10583
|
conversationId,
|
|
10397
10584
|
state: options.state
|
|
10398
10585
|
});
|
|
@@ -10407,16 +10594,17 @@ async function processConversationWork(message, options) {
|
|
|
10407
10594
|
);
|
|
10408
10595
|
}
|
|
10409
10596
|
const destination = initial.destination;
|
|
10410
|
-
const lease = await
|
|
10597
|
+
const lease = await startConversationWork2({
|
|
10411
10598
|
conversationId,
|
|
10412
|
-
|
|
10599
|
+
conversationStore: options.conversationStore,
|
|
10600
|
+
nowMs: now2(options),
|
|
10413
10601
|
state: options.state
|
|
10414
10602
|
});
|
|
10415
10603
|
if (lease.status === "no_work") {
|
|
10416
10604
|
return { status: "no_work" };
|
|
10417
10605
|
}
|
|
10418
10606
|
if (lease.status === "active") {
|
|
10419
|
-
const nudgeNowMs =
|
|
10607
|
+
const nudgeNowMs = now2(options);
|
|
10420
10608
|
await sendWakeNudge({
|
|
10421
10609
|
conversationId,
|
|
10422
10610
|
destination,
|
|
@@ -10435,7 +10623,7 @@ async function processConversationWork(message, options) {
|
|
|
10435
10623
|
);
|
|
10436
10624
|
return { status: "active" };
|
|
10437
10625
|
}
|
|
10438
|
-
const startedAtMs =
|
|
10626
|
+
const startedAtMs = now2(options);
|
|
10439
10627
|
const softYieldDeadlineMs = startedAtMs + (options.softYieldAfterMs ?? CONVERSATION_WORK_SOFT_YIELD_AFTER_MS);
|
|
10440
10628
|
let leaseLost = false;
|
|
10441
10629
|
const markLeaseLost = () => {
|
|
@@ -10460,12 +10648,13 @@ async function processConversationWork(message, options) {
|
|
|
10460
10648
|
conversationId,
|
|
10461
10649
|
destination,
|
|
10462
10650
|
leaseToken: lease.leaseToken,
|
|
10463
|
-
shouldYield: () => leaseLost ||
|
|
10651
|
+
shouldYield: () => leaseLost || now2(options) >= softYieldDeadlineMs,
|
|
10464
10652
|
checkIn: async () => {
|
|
10465
|
-
const checkedIn = await
|
|
10653
|
+
const checkedIn = await checkInConversationWork2({
|
|
10466
10654
|
conversationId,
|
|
10467
10655
|
leaseToken: lease.leaseToken,
|
|
10468
|
-
|
|
10656
|
+
conversationStore: options.conversationStore,
|
|
10657
|
+
nowMs: now2(options),
|
|
10469
10658
|
state: options.state
|
|
10470
10659
|
});
|
|
10471
10660
|
if (!checkedIn) {
|
|
@@ -10473,11 +10662,12 @@ async function processConversationWork(message, options) {
|
|
|
10473
10662
|
}
|
|
10474
10663
|
return checkedIn;
|
|
10475
10664
|
},
|
|
10476
|
-
drainMailbox: (inject) =>
|
|
10665
|
+
drainMailbox: (inject) => drainConversationMailbox2({
|
|
10477
10666
|
conversationId,
|
|
10478
10667
|
leaseToken: lease.leaseToken,
|
|
10668
|
+
conversationStore: options.conversationStore,
|
|
10479
10669
|
inject,
|
|
10480
|
-
nowMs:
|
|
10670
|
+
nowMs: now2(options),
|
|
10481
10671
|
state: options.state
|
|
10482
10672
|
})
|
|
10483
10673
|
};
|
|
@@ -10488,7 +10678,7 @@ async function processConversationWork(message, options) {
|
|
|
10488
10678
|
conversationId,
|
|
10489
10679
|
destination,
|
|
10490
10680
|
leaseToken: lease.leaseToken,
|
|
10491
|
-
nowMs:
|
|
10681
|
+
nowMs: now2(options),
|
|
10492
10682
|
options
|
|
10493
10683
|
});
|
|
10494
10684
|
return { status: "lost_lease" };
|
|
@@ -10498,17 +10688,18 @@ async function processConversationWork(message, options) {
|
|
|
10498
10688
|
conversationId,
|
|
10499
10689
|
destination,
|
|
10500
10690
|
leaseToken: lease.leaseToken,
|
|
10501
|
-
nowMs:
|
|
10691
|
+
nowMs: now2(options),
|
|
10502
10692
|
options
|
|
10503
10693
|
});
|
|
10504
10694
|
return { status: "lost_lease" };
|
|
10505
10695
|
}
|
|
10506
10696
|
if (result.status === "yielded") {
|
|
10507
|
-
const yieldNowMs =
|
|
10508
|
-
const continuationMarked = await
|
|
10697
|
+
const yieldNowMs = now2(options);
|
|
10698
|
+
const continuationMarked = await requestConversationContinuation2({
|
|
10509
10699
|
conversationId,
|
|
10510
10700
|
destination,
|
|
10511
10701
|
leaseToken: lease.leaseToken,
|
|
10702
|
+
conversationStore: options.conversationStore,
|
|
10512
10703
|
nowMs: yieldNowMs,
|
|
10513
10704
|
state: options.state
|
|
10514
10705
|
});
|
|
@@ -10526,9 +10717,10 @@ async function processConversationWork(message, options) {
|
|
|
10526
10717
|
nowMs: yieldNowMs,
|
|
10527
10718
|
options
|
|
10528
10719
|
});
|
|
10529
|
-
await
|
|
10720
|
+
await releaseConversationWork2({
|
|
10530
10721
|
conversationId,
|
|
10531
10722
|
leaseToken: lease.leaseToken,
|
|
10723
|
+
conversationStore: options.conversationStore,
|
|
10532
10724
|
nowMs: yieldNowMs,
|
|
10533
10725
|
state: options.state
|
|
10534
10726
|
});
|
|
@@ -10536,24 +10728,25 @@ async function processConversationWork(message, options) {
|
|
|
10536
10728
|
"conversation_work_cooperative_yield",
|
|
10537
10729
|
{ conversationId },
|
|
10538
10730
|
{
|
|
10539
|
-
"app.worker.elapsed_ms":
|
|
10731
|
+
"app.worker.elapsed_ms": now2(options) - startedAtMs,
|
|
10540
10732
|
"app.worker.soft_yield_deadline_ms": softYieldDeadlineMs
|
|
10541
10733
|
},
|
|
10542
10734
|
"Conversation work yielded cooperatively"
|
|
10543
10735
|
);
|
|
10544
10736
|
return { status: "yielded" };
|
|
10545
10737
|
}
|
|
10546
|
-
const completion = await
|
|
10738
|
+
const completion = await completeConversationWork2({
|
|
10547
10739
|
conversationId,
|
|
10548
10740
|
leaseToken: lease.leaseToken,
|
|
10549
|
-
|
|
10741
|
+
conversationStore: options.conversationStore,
|
|
10742
|
+
nowMs: now2(options),
|
|
10550
10743
|
state: options.state
|
|
10551
10744
|
});
|
|
10552
10745
|
if (completion === "lost_lease") {
|
|
10553
10746
|
return { status: "lost_lease" };
|
|
10554
10747
|
}
|
|
10555
10748
|
if (completion === "pending") {
|
|
10556
|
-
const nudgeNowMs =
|
|
10749
|
+
const nudgeNowMs = now2(options);
|
|
10557
10750
|
await sendWakeNudge({
|
|
10558
10751
|
conversationId,
|
|
10559
10752
|
destination,
|
|
@@ -10571,18 +10764,19 @@ async function processConversationWork(message, options) {
|
|
|
10571
10764
|
"conversation_work_completed",
|
|
10572
10765
|
{ conversationId },
|
|
10573
10766
|
{
|
|
10574
|
-
"app.worker.elapsed_ms":
|
|
10767
|
+
"app.worker.elapsed_ms": now2(options) - startedAtMs
|
|
10575
10768
|
},
|
|
10576
10769
|
"Conversation work completed"
|
|
10577
10770
|
);
|
|
10578
10771
|
return { status: "completed" };
|
|
10579
10772
|
} catch (error) {
|
|
10580
|
-
const errorNowMs =
|
|
10773
|
+
const errorNowMs = now2(options);
|
|
10581
10774
|
try {
|
|
10582
|
-
const continuationMarked = await
|
|
10775
|
+
const continuationMarked = await requestConversationContinuation2({
|
|
10583
10776
|
conversationId,
|
|
10584
10777
|
destination,
|
|
10585
10778
|
leaseToken: lease.leaseToken,
|
|
10779
|
+
conversationStore: options.conversationStore,
|
|
10586
10780
|
nowMs: errorNowMs,
|
|
10587
10781
|
state: options.state
|
|
10588
10782
|
});
|
|
@@ -10609,9 +10803,10 @@ async function processConversationWork(message, options) {
|
|
|
10609
10803
|
);
|
|
10610
10804
|
}
|
|
10611
10805
|
try {
|
|
10612
|
-
await
|
|
10806
|
+
await releaseConversationWork2({
|
|
10613
10807
|
conversationId,
|
|
10614
10808
|
leaseToken: lease.leaseToken,
|
|
10809
|
+
conversationStore: options.conversationStore,
|
|
10615
10810
|
nowMs: errorNowMs,
|
|
10616
10811
|
state: options.state
|
|
10617
10812
|
});
|
|
@@ -10630,7 +10825,7 @@ async function processConversationWork(message, options) {
|
|
|
10630
10825
|
"conversation_work_failed",
|
|
10631
10826
|
{ conversationId },
|
|
10632
10827
|
{
|
|
10633
|
-
"app.worker.elapsed_ms":
|
|
10828
|
+
"app.worker.elapsed_ms": now2(options) - startedAtMs
|
|
10634
10829
|
},
|
|
10635
10830
|
"Conversation work failed"
|
|
10636
10831
|
);
|
|
@@ -10665,6 +10860,7 @@ async function processConversationQueueMessage(message, options) {
|
|
|
10665
10860
|
const parsed = parseConversationQueueMessage(message);
|
|
10666
10861
|
return await processConversationWork(parsed, {
|
|
10667
10862
|
checkInIntervalMs: options.checkInIntervalMs,
|
|
10863
|
+
conversationStore: options.conversationStore,
|
|
10668
10864
|
nowMs: options.nowMs,
|
|
10669
10865
|
queue: options.queue ?? getVercelConversationWorkQueue(),
|
|
10670
10866
|
run: options.run,
|