@sentry/junior 0.179.0 → 0.181.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/{agent-hooks-32IDCLMW.js → agent-hooks-IQUW6ERD.js} +16 -18
- package/dist/api/schema/workspace.d.ts +2 -0
- package/dist/api/schema.js +1 -2
- package/dist/api.js +202 -199
- package/dist/app.d.ts +4 -0
- package/dist/app.js +300 -1259
- package/dist/catalog-runtime-PMQWNIXA.js +14 -0
- package/dist/chat/agent/sandbox.d.ts +0 -2
- package/dist/chat/api-turns/routing.d.ts +4 -0
- package/dist/chat/api-turns/work.d.ts +5 -0
- package/dist/chat/config.d.ts +5 -2
- package/dist/chat/configuration/defaults.d.ts +1 -1
- package/dist/chat/conversations/projection.d.ts +6 -4
- package/dist/chat/ingress/message-router.d.ts +3 -0
- package/dist/chat/model-profile.d.ts +8 -10
- package/dist/chat/pi/conversation-events.d.ts +3 -2
- package/dist/chat/plugins/agent-hooks.d.ts +1 -1
- package/dist/chat/plugins/task-queue.d.ts +40 -3
- package/dist/chat/plugins/task-runner.d.ts +1 -1
- package/dist/chat/queue/callback.d.ts +26 -0
- package/dist/chat/queue/sign.d.ts +30 -0
- package/dist/chat/sandbox/sandbox.d.ts +0 -2
- package/dist/chat/sandbox/session.d.ts +0 -2
- package/dist/chat/sandbox/skill-sync.d.ts +1 -1
- package/dist/chat/sandbox/snapshot/events.d.ts +23 -0
- package/dist/chat/sandbox/snapshot/job-callback.d.ts +5 -0
- package/dist/chat/sandbox/snapshot/job-queue.d.ts +26 -0
- package/dist/chat/sandbox/snapshot/job-runner.d.ts +11 -0
- package/dist/chat/sandbox/snapshot/not-ready-error.d.ts +6 -0
- package/dist/chat/sandbox/snapshot/workspace.d.ts +9 -3
- package/dist/chat/services/turn-router.d.ts +4 -3
- package/dist/chat/services/turn-session-routing.d.ts +1 -0
- package/dist/chat/task-execution/queue-signing.d.ts +10 -21
- package/dist/chat/task-execution/state.d.ts +48 -0
- package/dist/chat/task-execution/store.d.ts +28 -2
- package/dist/chat/task-execution/worker.d.ts +4 -1
- package/dist/chat/tools/handoff/tool.d.ts +1 -1
- package/dist/chat/tools/types.d.ts +2 -0
- package/dist/chat/workspaces/types.d.ts +2 -0
- package/dist/{chunk-Q5B3WTGG.js → chunk-3KCQEG6W.js} +42 -41
- package/dist/{chunk-XZY6G5YZ.js → chunk-3KSSALN4.js} +180 -87
- package/dist/{chunk-3AFVR5UC.js → chunk-3X55QRAG.js} +18 -16
- package/dist/{chunk-SLGGOASN.js → chunk-4IX32NSL.js} +46 -46
- package/dist/{chunk-6ZWRNC4D.js → chunk-6Y5B5PEX.js} +1 -1
- package/dist/chunk-7H2VZTWN.js +103 -0
- package/dist/{chunk-CGA4ERJ5.js → chunk-CEMMLV5L.js} +1 -1
- package/dist/{chunk-FIANEE7Z.js → chunk-CM5HNV2W.js} +6 -6
- package/dist/{chunk-TKB25A3L.js → chunk-CZYNWPWD.js} +2 -1
- package/dist/{chunk-3I7XE3PA.js → chunk-D6ZD7VXP.js} +49 -38
- package/dist/chunk-DKIJ2RP5.js +68 -0
- package/dist/{chunk-G2CAC4CV.js → chunk-DSA6WTRP.js} +74 -68
- package/dist/{chunk-OOUNJNMR.js → chunk-DWPN6SCH.js} +1 -1
- package/dist/{chunk-HQNE5APD.js → chunk-EBMRB6Z6.js} +100 -79
- package/dist/{chunk-ZQMG3CL5.js → chunk-EM7EECT5.js} +16 -16
- package/dist/{chunk-XSPSCWLH.js → chunk-ETJTXYHY.js} +4 -4
- package/dist/{chunk-FTGD2FBP.js → chunk-EU7KJDOG.js} +2 -2
- package/dist/{chunk-CJLBLELR.js → chunk-FWILPBVQ.js} +8 -61
- package/dist/{chunk-4GWXAILB.js → chunk-GPA3ZSYY.js} +1 -1
- package/dist/{chunk-U4TKB6F6.js → chunk-GREV5PJK.js} +108 -5
- package/dist/{chunk-KJLHIHFF.js → chunk-GWFRPQNP.js} +43 -230
- package/dist/{chunk-YFNAMRGE.js → chunk-HEBMSITT.js} +1 -1
- package/dist/chunk-HJ27A6YB.js +218 -0
- package/dist/{chunk-R5NWWYIS.js → chunk-HZHUMCNV.js} +5 -5
- package/dist/{chunk-RTRBYSF3.js → chunk-IJ6SS4WB.js} +1 -1
- package/dist/{chunk-B6ECUSVX.js → chunk-IKKETMQC.js} +8 -8
- package/dist/{chunk-R6U7N4FS.js → chunk-KKSVCHDO.js} +10 -3
- package/dist/{chunk-JMJNFEDC.js → chunk-KMBU4PJP.js} +9 -54
- package/dist/chunk-KQZX24QQ.js +164 -0
- package/dist/{chunk-GPLAT6H7.js → chunk-LCNPXLE7.js} +22 -18
- package/dist/{chunk-2HIPYNQI.js → chunk-LG5MYY6U.js} +33 -32
- package/dist/chunk-LZOQFC5F.js +209 -0
- package/dist/chunk-M3QYTBQ6.js +55 -0
- package/dist/{chunk-M63DETLL.js → chunk-N7TMSOZH.js} +6 -6
- package/dist/{chunk-FIDMHAO6.js → chunk-NQTA72Q3.js} +84 -274
- package/dist/{chunk-RZRYOLCE.js → chunk-PBKZQAUA.js} +2315 -1150
- package/dist/chunk-PEQXYSSE.js +45 -0
- package/dist/{chunk-3TM3FYLQ.js → chunk-PL57B6NC.js} +1 -1
- package/dist/{chunk-JT4WMD3C.js → chunk-PPYDHUEL.js} +144 -218
- package/dist/{chunk-5IRROPA5.js → chunk-Q2KY27IX.js} +129 -31
- package/dist/{chunk-VP4OVRDD.js → chunk-RNMASWLP.js} +69 -73
- package/dist/{chunk-FAS6AIMF.js → chunk-TDT2R77B.js} +8 -8
- package/dist/{chunk-TIEKUH4Q.js → chunk-TJHSAHQN.js} +4 -3
- package/dist/{chunk-H4HBKISO.js → chunk-TXKUKMVO.js} +1 -1
- package/dist/chunk-X6GDDWQH.js +60 -0
- package/dist/{chunk-GENV6KF2.js → chunk-XYTJUHRZ.js} +108 -76
- package/dist/cli/chat.js +47 -43
- package/dist/cli/check.js +13 -15
- package/dist/cli/env.js +0 -1
- package/dist/cli/init.js +0 -1
- package/dist/cli/main.js +2 -3
- package/dist/cli/plugins.js +18 -20
- package/dist/cli/run.js +0 -1
- package/dist/cli/snapshot-create.js +14 -16
- package/dist/cli/upgrade.js +16 -18
- package/dist/{conversation-work-KATFHLG3.js → conversation-work-VIOQ5ZF3.js} +0 -2
- package/dist/db/schema/snapshots.d.ts +17 -0
- package/dist/db/schema.d.ts +17 -0
- package/dist/{db-EJAV7JL6.js → db-QNPVCQPT.js} +8 -10
- package/dist/deployment.d.ts +1 -0
- package/dist/{discovery-GUFTFBTL.js → discovery-DWVDM7UK.js} +1 -2
- package/dist/{experimental-XVDOSRBS.js → experimental-SIJSRDJD.js} +0 -1
- package/dist/instrumentation.js +7 -9
- package/dist/nitro.js +39 -13
- package/dist/{oauth-callback-server-GAVSUBTQ.js → oauth-callback-server-KYMPJOTC.js} +34 -32
- package/dist/{oauth-relay-3ZU72UGL.js → oauth-relay-5XPVRPYB.js} +0 -1
- package/dist/{plugins-HW4VWW6G.js → plugins-YTYJMMJF.js} +1 -2
- package/dist/{runner-34JL64JF.js → runner-3RS2D2ZR.js} +39 -33
- package/dist/{sandbox-egress-signals-DXOOBSBI.js → sandbox-egress-signals-FIL7EGPR.js} +5 -6
- package/dist/{sentry-JMWTS32N.js → sentry-MB3NL3IR.js} +1 -2
- package/dist/skills-5B3Y6XX6.js +27 -0
- package/dist/spawn-VYARS3DU.js +37 -0
- package/dist/task-runner-4IXKKZHL.js +32 -0
- package/dist/validation-Q65QD27B.js +17 -0
- package/dist/vercel.js +0 -1
- package/dist/version.js +1 -2
- package/dist/work-DCMQWAAP.js +45 -0
- package/dist/worker-QL3CHLZL.js +22 -0
- package/migrations/0035_workspace_snapshot_size_bytes.sql +2 -0
- package/migrations/meta/0035_snapshot.json +3048 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +7 -6
- package/dist/catalog-runtime-FBVA6WAQ.js +0 -16
- package/dist/chat/plugins/task-callback.d.ts +0 -5
- package/dist/chat/plugins/task-message.d.ts +0 -23
- package/dist/chat/plugins/task-signing.d.ts +0 -31
- package/dist/chat/sandbox/snapshot/waiting-error.d.ts +0 -15
- package/dist/chat/services/workspace-snapshot-wait.d.ts +0 -27
- package/dist/chunk-5I6ORJUY.js +0 -127
- package/dist/chunk-6GWA276C.js +0 -72
- package/dist/chunk-MLKGABMK.js +0 -9
- package/dist/chunk-UT6X7XN7.js +0 -51
- package/dist/chunk-WR76IVA5.js +0 -130
- package/dist/skills-U545HALM.js +0 -29
- package/dist/spawn-I2S4IDUQ.js +0 -37
- package/dist/validation-EVXVGA44.js +0 -19
- package/dist/work-QOAUPDBU.js +0 -45
- package/dist/worker-5GX2IKLZ.js +0 -24
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
beginConversationResume,
|
|
6
6
|
checkInConversationWork,
|
|
7
7
|
clearConsumedConversationWake,
|
|
8
|
+
completeConversationStop,
|
|
8
9
|
completeConversationWork,
|
|
9
10
|
countPendingConversationMessages,
|
|
10
11
|
deadLetterAttempt,
|
|
@@ -18,26 +19,27 @@ import {
|
|
|
18
19
|
releaseConversationWork,
|
|
19
20
|
requestAnotherSlice,
|
|
20
21
|
startConversationWork
|
|
21
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-Q2KY27IX.js";
|
|
22
23
|
import {
|
|
23
24
|
ConversationQueueMessageRejectedError
|
|
24
25
|
} from "./chunk-JAL3CH4G.js";
|
|
25
26
|
import {
|
|
26
27
|
getTurnRequestDeadline
|
|
27
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-GPA3ZSYY.js";
|
|
28
29
|
import {
|
|
29
30
|
getChatConfig,
|
|
30
31
|
isProviderRetryError
|
|
31
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-XYTJUHRZ.js";
|
|
32
33
|
import {
|
|
33
34
|
logException,
|
|
34
35
|
logInfo,
|
|
35
36
|
logWarn,
|
|
36
37
|
withLogContext
|
|
37
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-EBMRB6Z6.js";
|
|
38
39
|
|
|
39
40
|
// src/chat/task-execution/worker.ts
|
|
40
41
|
var CONVERSATION_WORK_DEFER_DELAY_MS = 15e3;
|
|
42
|
+
var CONVERSATION_STOP_CHECK_INTERVAL_MS = 500;
|
|
41
43
|
function now(options) {
|
|
42
44
|
return options.nowMs?.() ?? Date.now();
|
|
43
45
|
}
|
|
@@ -182,6 +184,63 @@ function startLeaseCheckIn(args) {
|
|
|
182
184
|
timer.unref?.();
|
|
183
185
|
return timer;
|
|
184
186
|
}
|
|
187
|
+
function createConversationStopSignal(args) {
|
|
188
|
+
const controller = new AbortController();
|
|
189
|
+
let checking = false;
|
|
190
|
+
let failureCaptured = false;
|
|
191
|
+
let listening = false;
|
|
192
|
+
let timer;
|
|
193
|
+
const requestStop = () => {
|
|
194
|
+
if (!controller.signal.aborted) {
|
|
195
|
+
controller.abort(new Error("Conversation work stopped"));
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
if (args.initialStopRunId === args.runId) {
|
|
199
|
+
requestStop();
|
|
200
|
+
}
|
|
201
|
+
const check = async () => {
|
|
202
|
+
if (checking || controller.signal.aborted) return;
|
|
203
|
+
checking = true;
|
|
204
|
+
try {
|
|
205
|
+
const current = await getConversationWorkState({
|
|
206
|
+
conversationId: args.conversationId,
|
|
207
|
+
state: args.options.state
|
|
208
|
+
});
|
|
209
|
+
if (current?.execution.stop?.runId === args.runId) {
|
|
210
|
+
requestStop();
|
|
211
|
+
}
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (!failureCaptured) {
|
|
214
|
+
failureCaptured = true;
|
|
215
|
+
logException(error, "conversation.work.stop_check.failed");
|
|
216
|
+
}
|
|
217
|
+
} finally {
|
|
218
|
+
checking = false;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
return {
|
|
222
|
+
close() {
|
|
223
|
+
if (timer) clearInterval(timer);
|
|
224
|
+
},
|
|
225
|
+
isEnabled() {
|
|
226
|
+
return listening;
|
|
227
|
+
},
|
|
228
|
+
wasObserved() {
|
|
229
|
+
return listening && controller.signal.aborted;
|
|
230
|
+
},
|
|
231
|
+
signal() {
|
|
232
|
+
listening = true;
|
|
233
|
+
if (!timer && !controller.signal.aborted) {
|
|
234
|
+
timer = setInterval(
|
|
235
|
+
() => void check(),
|
|
236
|
+
CONVERSATION_STOP_CHECK_INTERVAL_MS
|
|
237
|
+
);
|
|
238
|
+
timer.unref?.();
|
|
239
|
+
}
|
|
240
|
+
return controller.signal;
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
185
244
|
async function processConversationWork(message, options) {
|
|
186
245
|
return withLogContext(
|
|
187
246
|
{ conversationId: message.conversationId },
|
|
@@ -336,6 +395,7 @@ async function processConversationWorkInContext(message, options) {
|
|
|
336
395
|
};
|
|
337
396
|
try {
|
|
338
397
|
let hasRun = false;
|
|
398
|
+
let resumeIfStopped = false;
|
|
339
399
|
while (true) {
|
|
340
400
|
attemptMessageIds = [];
|
|
341
401
|
const leasedWork = await getConversationWorkState({
|
|
@@ -355,6 +415,10 @@ async function processConversationWorkInContext(message, options) {
|
|
|
355
415
|
}
|
|
356
416
|
const resumePending = leasedWork.execution.status === "paused";
|
|
357
417
|
const attemptMessages = selectAttemptMessages(leasedWork);
|
|
418
|
+
const runId = leasedWork.execution.runId;
|
|
419
|
+
if (!runId) {
|
|
420
|
+
throw new Error(`Conversation run is missing for ${conversationId}`);
|
|
421
|
+
}
|
|
358
422
|
attemptStartMessageIds = new Set(
|
|
359
423
|
leasedWork.messages.map((message2) => message2.inboundMessageId)
|
|
360
424
|
);
|
|
@@ -405,6 +469,12 @@ async function processConversationWorkInContext(message, options) {
|
|
|
405
469
|
);
|
|
406
470
|
}
|
|
407
471
|
};
|
|
472
|
+
const stop = createConversationStopSignal({
|
|
473
|
+
conversationId,
|
|
474
|
+
initialStopRunId: leasedWork.execution.stop?.runId,
|
|
475
|
+
options,
|
|
476
|
+
runId
|
|
477
|
+
});
|
|
408
478
|
const workerContext = {
|
|
409
479
|
attempt: {
|
|
410
480
|
ack,
|
|
@@ -420,9 +490,16 @@ async function processConversationWorkInContext(message, options) {
|
|
|
420
490
|
destination,
|
|
421
491
|
publishExternally,
|
|
422
492
|
shouldYield,
|
|
493
|
+
stopSignal: stop.signal,
|
|
423
494
|
checkIn
|
|
424
495
|
};
|
|
425
|
-
|
|
496
|
+
let result;
|
|
497
|
+
try {
|
|
498
|
+
result = await options.run(workerContext);
|
|
499
|
+
} finally {
|
|
500
|
+
stop.close();
|
|
501
|
+
}
|
|
502
|
+
resumeIfStopped ||= stop.isEnabled();
|
|
426
503
|
hasRun = true;
|
|
427
504
|
if (result.status === "lost_lease") {
|
|
428
505
|
await requestLostLeaseRecovery({
|
|
@@ -444,6 +521,27 @@ async function processConversationWorkInContext(message, options) {
|
|
|
444
521
|
});
|
|
445
522
|
return { status: "lost_lease" };
|
|
446
523
|
}
|
|
524
|
+
if (result.status === "completed" && stop.wasObserved()) {
|
|
525
|
+
const stopped = await completeConversationStop({
|
|
526
|
+
conversationId,
|
|
527
|
+
conversationStore: options.conversationStore,
|
|
528
|
+
leaseToken: lease.leaseToken,
|
|
529
|
+
nowMs: now(options),
|
|
530
|
+
runId,
|
|
531
|
+
state: options.state
|
|
532
|
+
});
|
|
533
|
+
if (stopped.status === "lost_lease") {
|
|
534
|
+
markLeaseLost();
|
|
535
|
+
await requestLostLeaseRecovery({
|
|
536
|
+
conversationId,
|
|
537
|
+
destination,
|
|
538
|
+
leaseToken: lease.leaseToken,
|
|
539
|
+
nowMs: now(options),
|
|
540
|
+
options
|
|
541
|
+
});
|
|
542
|
+
return { status: "lost_lease" };
|
|
543
|
+
}
|
|
544
|
+
}
|
|
447
545
|
if (result.status === "yielded") {
|
|
448
546
|
const sliceRequested = await requestAnotherSlice({
|
|
449
547
|
conversationId,
|
|
@@ -519,6 +617,9 @@ async function processConversationWorkInContext(message, options) {
|
|
|
519
617
|
break;
|
|
520
618
|
}
|
|
521
619
|
}
|
|
620
|
+
if (result.status === "paused") {
|
|
621
|
+
break;
|
|
622
|
+
}
|
|
522
623
|
const next = await getConversationWorkState({
|
|
523
624
|
conversationId,
|
|
524
625
|
state: options.state
|
|
@@ -534,6 +635,8 @@ async function processConversationWorkInContext(message, options) {
|
|
|
534
635
|
conversationId,
|
|
535
636
|
leaseToken: lease.leaseToken,
|
|
536
637
|
madeProgress: !failedWithoutProgress,
|
|
638
|
+
// A stop that raced an external pause must reach the paused Turn.
|
|
639
|
+
resumeIfStopped,
|
|
537
640
|
conversationStore: options.conversationStore,
|
|
538
641
|
nowMs: now(options),
|
|
539
642
|
state: options.state
|
|
@@ -1,36 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
2
|
coerceThreadConversationState,
|
|
3
|
-
getPersistedThreadState
|
|
4
|
-
|
|
5
|
-
} from "./chunk-CJLBLELR.js";
|
|
3
|
+
getPersistedThreadState
|
|
4
|
+
} from "./chunk-FWILPBVQ.js";
|
|
6
5
|
import {
|
|
7
6
|
pluginTaskId,
|
|
8
7
|
pluginTaskParamsSchema,
|
|
9
8
|
sendVercelPluginTask
|
|
10
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-KQZX24QQ.js";
|
|
11
10
|
import {
|
|
12
|
-
buildDeterministicTurnId,
|
|
13
|
-
clearPendingAuth,
|
|
14
11
|
getPiMessageRole,
|
|
15
12
|
getTurnRecord,
|
|
16
13
|
hydrateConversationMessages,
|
|
17
14
|
instructionTextForProjection,
|
|
18
15
|
isToolResultError,
|
|
19
16
|
isToolResultMessage,
|
|
20
|
-
markConversationMessage,
|
|
21
|
-
markTurnClosed,
|
|
22
|
-
markTurnCompleted,
|
|
23
17
|
normalizeToolNameFromResult,
|
|
24
18
|
stripRuntimeTurnContext
|
|
25
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-NQTA72Q3.js";
|
|
26
20
|
import {
|
|
27
21
|
createPluginConversationEvents,
|
|
28
22
|
createPluginEmbedder,
|
|
29
23
|
createPluginLogger,
|
|
30
24
|
createPluginModel,
|
|
31
25
|
createPluginState,
|
|
32
|
-
getPlugins
|
|
33
|
-
|
|
26
|
+
getPlugins,
|
|
27
|
+
readActorIdentity
|
|
28
|
+
} from "./chunk-D6ZD7VXP.js";
|
|
34
29
|
import {
|
|
35
30
|
JUNIOR_THREAD_STATE_TTL_MS
|
|
36
31
|
} from "./chunk-3Y47VMHV.js";
|
|
@@ -38,56 +33,30 @@ import {
|
|
|
38
33
|
getConversationStore,
|
|
39
34
|
getDb,
|
|
40
35
|
sameActorIdentity
|
|
41
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-RNMASWLP.js";
|
|
42
37
|
import {
|
|
43
38
|
juniorConversations,
|
|
44
39
|
juniorTaskExecutions
|
|
45
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-KKSVCHDO.js";
|
|
46
41
|
import {
|
|
47
42
|
getStateAdapter
|
|
48
|
-
} from "./chunk-
|
|
49
|
-
import {
|
|
50
|
-
ProviderError,
|
|
51
|
-
findProviderError,
|
|
52
|
-
getProviderErrorAttributes,
|
|
53
|
-
getProviderErrorUserMessage
|
|
54
|
-
} from "./chunk-GENV6KF2.js";
|
|
43
|
+
} from "./chunk-PL57B6NC.js";
|
|
55
44
|
import {
|
|
56
45
|
credentialSubjectSchema
|
|
57
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-CEMMLV5L.js";
|
|
58
47
|
import {
|
|
59
48
|
parseSlackMessageTs
|
|
60
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-N7TMSOZH.js";
|
|
61
50
|
import {
|
|
62
|
-
buildTurnFailureResponse,
|
|
63
51
|
logWarn
|
|
64
|
-
} from "./chunk-
|
|
65
|
-
|
|
66
|
-
// src/chat/runtime/delivered-turn-state.ts
|
|
67
|
-
function buildDeliveredTurnStatePatch(args) {
|
|
68
|
-
const conversation = structuredClone(args.conversation);
|
|
69
|
-
clearPendingAuth(conversation, args.sessionId);
|
|
70
|
-
markConversationMessage(conversation, args.userMessageId, {
|
|
71
|
-
replied: true,
|
|
72
|
-
skippedReason: void 0
|
|
73
|
-
});
|
|
74
|
-
markTurnCompleted({
|
|
75
|
-
conversation,
|
|
76
|
-
nowMs: Date.now(),
|
|
77
|
-
sessionId: args.sessionId
|
|
78
|
-
});
|
|
79
|
-
return {
|
|
80
|
-
conversation,
|
|
81
|
-
sandboxRef: args.reply.sandboxRef
|
|
82
|
-
};
|
|
83
|
-
}
|
|
52
|
+
} from "./chunk-EBMRB6Z6.js";
|
|
84
53
|
|
|
85
54
|
// src/chat/plugins/task-runner.ts
|
|
86
55
|
import { pluginRunContextSchema } from "@sentry/junior-plugin-api";
|
|
87
56
|
|
|
88
57
|
// src/chat/services/turn-session-routing.ts
|
|
89
58
|
async function resolveTurnSessionRouting(args) {
|
|
90
|
-
const conversationStore = args.conversationStore ?? (await import("./db-
|
|
59
|
+
const conversationStore = args.conversationStore ?? (await import("./db-QNPVCQPT.js")).getConversationStore();
|
|
91
60
|
const conversation = await conversationStore.get({
|
|
92
61
|
conversationId: args.conversationId
|
|
93
62
|
});
|
|
@@ -98,6 +67,7 @@ async function resolveTurnSessionRouting(args) {
|
|
|
98
67
|
}
|
|
99
68
|
return {
|
|
100
69
|
destination: conversation.destination,
|
|
70
|
+
...conversation.location ? { locationId: conversation.location.id } : void 0,
|
|
101
71
|
source: conversation.sessionSource
|
|
102
72
|
};
|
|
103
73
|
}
|
|
@@ -148,7 +118,7 @@ async function recordTaskExecution(type, taskId, options) {
|
|
|
148
118
|
const status = options.status ?? "completed";
|
|
149
119
|
try {
|
|
150
120
|
await getDb().insert(juniorTaskExecutions).values({
|
|
151
|
-
...options.conversationId ? { conversationId: options.conversationId } :
|
|
121
|
+
...options.conversationId ? { conversationId: options.conversationId } : void 0,
|
|
152
122
|
executedAtMs: nowMs,
|
|
153
123
|
executionId: options.executionId,
|
|
154
124
|
kind: type,
|
|
@@ -205,8 +175,8 @@ async function readTaskExecutionSummaries(type, namespace, options = {}) {
|
|
|
205
175
|
rows.map((row) => [
|
|
206
176
|
row.taskId,
|
|
207
177
|
{
|
|
208
|
-
...row.lastConversationId ? { lastConversationId: row.lastConversationId } :
|
|
209
|
-
...row.lastExecutedAtMs !== null ? { lastExecutedAtMs: row.lastExecutedAtMs } :
|
|
178
|
+
...row.lastConversationId ? { lastConversationId: row.lastConversationId } : void 0,
|
|
179
|
+
...row.lastExecutedAtMs !== null ? { lastExecutedAtMs: row.lastExecutedAtMs } : void 0,
|
|
210
180
|
runsLast7Days: row.runsLast7Days,
|
|
211
181
|
totalRuns: row.totalRuns
|
|
212
182
|
}
|
|
@@ -290,11 +260,11 @@ async function readTaskExecutions(args) {
|
|
|
290
260
|
return rows.map((row) => {
|
|
291
261
|
const title = row.title?.trim();
|
|
292
262
|
return {
|
|
293
|
-
...row.conversationId ? { conversationId: row.conversationId } :
|
|
263
|
+
...row.conversationId ? { conversationId: row.conversationId } : void 0,
|
|
294
264
|
executedAt: new Date(row.executedAtMs).toISOString(),
|
|
295
265
|
executionId: row.executionId,
|
|
296
266
|
status: row.status,
|
|
297
|
-
...title ? { title } :
|
|
267
|
+
...title ? { title } : void 0
|
|
298
268
|
};
|
|
299
269
|
});
|
|
300
270
|
}
|
|
@@ -330,13 +300,13 @@ async function readTaskRuns(args) {
|
|
|
330
300
|
const title = row.title?.trim();
|
|
331
301
|
return [
|
|
332
302
|
{
|
|
333
|
-
...row.conversationId ? { conversationId: row.conversationId } :
|
|
303
|
+
...row.conversationId ? { conversationId: row.conversationId } : void 0,
|
|
334
304
|
executedAt: new Date(row.executedAtMs).toISOString(),
|
|
335
305
|
executionId: row.executionId,
|
|
336
306
|
kind: row.kind,
|
|
337
307
|
status: row.status,
|
|
338
308
|
taskId: row.taskId,
|
|
339
|
-
...title ? { title } :
|
|
309
|
+
...title ? { title } : void 0
|
|
340
310
|
}
|
|
341
311
|
];
|
|
342
312
|
});
|
|
@@ -499,8 +469,8 @@ function toDispatchProjection(record) {
|
|
|
499
469
|
return {
|
|
500
470
|
id: record.id,
|
|
501
471
|
status: record.status,
|
|
502
|
-
...record.resultMessageTs ? { resultMessageTs: record.resultMessageTs } :
|
|
503
|
-
...record.errorMessage ? { errorMessage: record.errorMessage } :
|
|
472
|
+
...record.resultMessageTs ? { resultMessageTs: record.resultMessageTs } : void 0,
|
|
473
|
+
...record.errorMessage ? { errorMessage: record.errorMessage } : void 0
|
|
504
474
|
};
|
|
505
475
|
}
|
|
506
476
|
function isTerminalDispatchStatus(status) {
|
|
@@ -580,15 +550,15 @@ async function createOrGetDispatch(args) {
|
|
|
580
550
|
const record = {
|
|
581
551
|
actor: { platform: "system", name: args.plugin },
|
|
582
552
|
createdAtMs: args.nowMs,
|
|
583
|
-
...args.options.credentialSubject ? { credentialSubject: args.options.credentialSubject } :
|
|
553
|
+
...args.options.credentialSubject ? { credentialSubject: args.options.credentialSubject } : void 0,
|
|
584
554
|
destination: args.options.destination,
|
|
585
555
|
destinationVisibility: args.options.destinationVisibility,
|
|
586
556
|
id,
|
|
587
557
|
idempotencyKey: args.options.idempotencyKey,
|
|
588
558
|
input: args.options.input,
|
|
589
|
-
...metadata ? { metadata } :
|
|
559
|
+
...metadata ? { metadata } : void 0,
|
|
590
560
|
plugin: args.plugin,
|
|
591
|
-
...args.options.replyAttribution ? { replyAttribution: args.options.replyAttribution } :
|
|
561
|
+
...args.options.replyAttribution ? { replyAttribution: args.options.replyAttribution } : void 0,
|
|
592
562
|
status: "pending",
|
|
593
563
|
source: args.options.source,
|
|
594
564
|
updatedAtMs: args.nowMs
|
|
@@ -644,7 +614,7 @@ async function recordEventTaskExecution(previous, next, status) {
|
|
|
644
614
|
const conversationId = getDispatchConversationId(next);
|
|
645
615
|
const conversation = await getConversationStore().get({ conversationId });
|
|
646
616
|
await recordTaskExecution("event", eventTaskId, {
|
|
647
|
-
...conversation ? { conversationId } :
|
|
617
|
+
...conversation ? { conversationId } : void 0,
|
|
648
618
|
executionId: next.id,
|
|
649
619
|
nowMs: next.updatedAtMs,
|
|
650
620
|
status
|
|
@@ -657,7 +627,7 @@ async function markDispatchBlocked(id, errorMessage, resultMessageTs) {
|
|
|
657
627
|
(record) => isTerminalDispatchStatus(record.status) ? record : {
|
|
658
628
|
...record,
|
|
659
629
|
errorMessage,
|
|
660
|
-
...resultMessageTs ? { resultMessageTs } :
|
|
630
|
+
...resultMessageTs ? { resultMessageTs } : void 0,
|
|
661
631
|
status: "blocked"
|
|
662
632
|
}
|
|
663
633
|
);
|
|
@@ -671,7 +641,7 @@ async function markDispatchCompleted(id, resultMessageTs) {
|
|
|
671
641
|
(record) => isTerminalDispatchStatus(record.status) ? record : {
|
|
672
642
|
...record,
|
|
673
643
|
errorMessage: void 0,
|
|
674
|
-
...resultMessageTs ? { resultMessageTs } :
|
|
644
|
+
...resultMessageTs ? { resultMessageTs } : void 0,
|
|
675
645
|
status: "completed"
|
|
676
646
|
}
|
|
677
647
|
);
|
|
@@ -685,7 +655,7 @@ async function markDispatchFailed(id, errorMessage, resultMessageTs) {
|
|
|
685
655
|
(record) => isTerminalDispatchStatus(record.status) ? record : {
|
|
686
656
|
...record,
|
|
687
657
|
errorMessage,
|
|
688
|
-
...resultMessageTs ? { resultMessageTs } :
|
|
658
|
+
...resultMessageTs ? { resultMessageTs } : void 0,
|
|
689
659
|
status: "failed"
|
|
690
660
|
}
|
|
691
661
|
);
|
|
@@ -766,7 +736,7 @@ function sanitizeText(text) {
|
|
|
766
736
|
function messageProvenance(provenance) {
|
|
767
737
|
return {
|
|
768
738
|
authority: provenance.authority,
|
|
769
|
-
...provenance.actor ? { actor: provenance.actor } :
|
|
739
|
+
...provenance.actor ? { actor: provenance.actor } : void 0
|
|
770
740
|
};
|
|
771
741
|
}
|
|
772
742
|
function runTranscriptEntry(message, provenance, runActor) {
|
|
@@ -799,7 +769,7 @@ function runTranscriptEntry(message, provenance, runActor) {
|
|
|
799
769
|
type: "toolResult",
|
|
800
770
|
toolName,
|
|
801
771
|
isError: isToolResultError(message),
|
|
802
|
-
...text ? { text } :
|
|
772
|
+
...text ? { text } : void 0
|
|
803
773
|
};
|
|
804
774
|
}
|
|
805
775
|
function turnMessagesWithProvenance(record) {
|
|
@@ -826,8 +796,8 @@ function slackContextAuthor(source, message) {
|
|
|
826
796
|
platform: "slack",
|
|
827
797
|
teamId: source.teamId,
|
|
828
798
|
userId,
|
|
829
|
-
...message.author?.userName ? { userName: message.author.userName } :
|
|
830
|
-
...message.author?.fullName ? { fullName: message.author.fullName } :
|
|
799
|
+
...message.author?.userName ? { userName: message.author.userName } : void 0,
|
|
800
|
+
...message.author?.fullName ? { fullName: message.author.fullName } : void 0
|
|
831
801
|
};
|
|
832
802
|
}
|
|
833
803
|
function slackTimestampMs(value) {
|
|
@@ -884,7 +854,7 @@ async function loadConversationContextTranscriptEntries(record, source, runActor
|
|
|
884
854
|
text,
|
|
885
855
|
provenance: {
|
|
886
856
|
authority: "context",
|
|
887
|
-
...author ? { actor: author } :
|
|
857
|
+
...author ? { actor: author } : void 0
|
|
888
858
|
},
|
|
889
859
|
isRunActor: sameActorIdentity(author, runActor)
|
|
890
860
|
});
|
|
@@ -919,6 +889,7 @@ async function loadPluginRun(params) {
|
|
|
919
889
|
conversationId: params.conversationId
|
|
920
890
|
});
|
|
921
891
|
const runActor = record.actors[0] ?? (record.dispatchId ? (await getDispatchRecord(record.dispatchId))?.actor : void 0);
|
|
892
|
+
const actorUser = runActor ? (await readActorIdentity(runActor))?.user : void 0;
|
|
922
893
|
const runEntries = turnMessagesWithProvenance(record).map(
|
|
923
894
|
({ message, provenance }) => runTranscriptEntry(message, provenance, runActor)
|
|
924
895
|
).filter((entry) => Boolean(entry));
|
|
@@ -933,13 +904,15 @@ async function loadPluginRun(params) {
|
|
|
933
904
|
(entry) => entry.type !== "message" || !runMessageTexts.has(entry.text)
|
|
934
905
|
);
|
|
935
906
|
return pluginRunContextSchema.parse({
|
|
907
|
+
...actorUser ? { actorUserId: actorUser.id } : void 0,
|
|
936
908
|
completedAtMs: record.updatedAtMs,
|
|
937
909
|
conversationId: record.conversationId,
|
|
938
910
|
destination: routing.destination,
|
|
939
|
-
|
|
940
|
-
//
|
|
911
|
+
...routing.locationId ? { locationId: routing.locationId } : void 0,
|
|
912
|
+
// Read Actors from the full run record, not the shorter transcript.
|
|
913
|
+
// This includes every Actor that supplied an instruction.
|
|
941
914
|
actors: record.actors,
|
|
942
|
-
...runActor ? { actor: runActor } :
|
|
915
|
+
...runActor ? { actor: runActor } : void 0,
|
|
943
916
|
runId: record.turnId,
|
|
944
917
|
source: routing.source,
|
|
945
918
|
transcript: [...contextEntries, ...runEntries]
|
|
@@ -1025,155 +998,6 @@ async function processPluginTask(message, options = {}) {
|
|
|
1025
998
|
});
|
|
1026
999
|
}
|
|
1027
1000
|
|
|
1028
|
-
// src/chat/interruption-marker.ts
|
|
1029
|
-
var INTERRUPTED_MARKER = "\n\n[Response interrupted before completion]";
|
|
1030
|
-
function getInterruptionMarker() {
|
|
1031
|
-
return INTERRUPTED_MARKER;
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
// src/chat/services/turn-failure-response.ts
|
|
1035
|
-
function requireTurnFailureEventId(eventId, eventName) {
|
|
1036
|
-
if (!eventId) {
|
|
1037
|
-
throw new Error(`Sentry did not return an event ID for ${eventName}`);
|
|
1038
|
-
}
|
|
1039
|
-
return eventId;
|
|
1040
|
-
}
|
|
1041
|
-
function getExecutionFailureReason(reply) {
|
|
1042
|
-
const errorMessage = reply.diagnostics.errorMessage?.trim();
|
|
1043
|
-
if (errorMessage) {
|
|
1044
|
-
return errorMessage;
|
|
1045
|
-
}
|
|
1046
|
-
if (reply.diagnostics.toolErrorCount > 0) {
|
|
1047
|
-
return `${reply.diagnostics.toolErrorCount} tool result error(s)`;
|
|
1048
|
-
}
|
|
1049
|
-
if (reply.diagnostics.assistantMessageCount > 0) {
|
|
1050
|
-
return "assistant returned no text";
|
|
1051
|
-
}
|
|
1052
|
-
return "empty assistant turn";
|
|
1053
|
-
}
|
|
1054
|
-
function getFailureCapture(reply) {
|
|
1055
|
-
if (reply.diagnostics.outcome === "provider_error") {
|
|
1056
|
-
const providerError = findProviderError(reply.diagnostics.providerError);
|
|
1057
|
-
return {
|
|
1058
|
-
eventName: "agent.turn.provider_error",
|
|
1059
|
-
error: reply.diagnostics.providerError ?? new Error(
|
|
1060
|
-
reply.diagnostics.errorMessage ?? "Provider error without explicit message"
|
|
1061
|
-
),
|
|
1062
|
-
attributes: providerError ? getProviderErrorAttributes(providerError) : {},
|
|
1063
|
-
body: "Agent turn failed with provider error"
|
|
1064
|
-
};
|
|
1065
|
-
}
|
|
1066
|
-
const failureReason = getExecutionFailureReason(reply);
|
|
1067
|
-
return {
|
|
1068
|
-
eventName: "agent.turn.execution.failed",
|
|
1069
|
-
error: new Error(`Agent turn execution failure: ${failureReason}`),
|
|
1070
|
-
attributes: {
|
|
1071
|
-
"app.ai.execution_failure_reason": failureReason
|
|
1072
|
-
},
|
|
1073
|
-
body: "Agent turn completed with execution failure"
|
|
1074
|
-
};
|
|
1075
|
-
}
|
|
1076
|
-
function getAgentTurnDiagnosticsAttributes(reply) {
|
|
1077
|
-
return {
|
|
1078
|
-
"app.ai.outcome": reply.diagnostics.outcome,
|
|
1079
|
-
"app.ai.assistant_messages": reply.diagnostics.assistantMessageCount,
|
|
1080
|
-
"app.ai.tool_results": reply.diagnostics.toolResultCount,
|
|
1081
|
-
"app.ai.tool_error_results": reply.diagnostics.toolErrorCount,
|
|
1082
|
-
"app.ai.tool_call_count": reply.diagnostics.toolCalls.length,
|
|
1083
|
-
"app.ai.used_primary_text": reply.diagnostics.usedPrimaryText,
|
|
1084
|
-
...reply.diagnostics.reasoningLevel ? {
|
|
1085
|
-
"gen_ai.request.reasoning.level": reply.diagnostics.reasoningLevel
|
|
1086
|
-
} : {},
|
|
1087
|
-
...reply.diagnostics.stopReason ? {
|
|
1088
|
-
"gen_ai.response.finish_reasons": [reply.diagnostics.stopReason]
|
|
1089
|
-
} : {},
|
|
1090
|
-
...reply.diagnostics.errorMessage && reply.diagnostics.outcome !== "provider_error" ? { "exception.message": reply.diagnostics.errorMessage } : {}
|
|
1091
|
-
};
|
|
1092
|
-
}
|
|
1093
|
-
function finalizeFailedTurnReplyWithEvent(args) {
|
|
1094
|
-
if (args.reply.diagnostics.outcome === "success") {
|
|
1095
|
-
return { reply: args.reply };
|
|
1096
|
-
}
|
|
1097
|
-
const capture = getFailureCapture(args.reply);
|
|
1098
|
-
const eventId = requireTurnFailureEventId(
|
|
1099
|
-
args.logException(capture.error, capture.eventName, {
|
|
1100
|
-
...getAgentTurnDiagnosticsAttributes(args.reply),
|
|
1101
|
-
...args.attributes,
|
|
1102
|
-
...capture.attributes
|
|
1103
|
-
}),
|
|
1104
|
-
capture.eventName
|
|
1105
|
-
);
|
|
1106
|
-
const providerPartialText = args.reply.diagnostics.outcome === "provider_error" && args.reply.diagnostics.assistantMessageCount > 0 ? args.reply.text.trim() : "";
|
|
1107
|
-
const providerUserMessage = args.reply.diagnostics.providerError instanceof ProviderError ? getProviderErrorUserMessage(args.reply.diagnostics.providerError) : "";
|
|
1108
|
-
const failureText = providerUserMessage ? `${providerUserMessage} Reference: \`event_id=${eventId}\`.` : buildTurnFailureResponse(eventId);
|
|
1109
|
-
return {
|
|
1110
|
-
eventId,
|
|
1111
|
-
reply: {
|
|
1112
|
-
...args.reply,
|
|
1113
|
-
text: providerPartialText ? `${providerPartialText}${getInterruptionMarker()}` : failureText
|
|
1114
|
-
}
|
|
1115
|
-
};
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
// src/chat/runtime/turn-user-message.ts
|
|
1119
|
-
function getTurnUserMessage(conversation, sessionId) {
|
|
1120
|
-
for (let index = conversation.messages.length - 1; index >= 0; index -= 1) {
|
|
1121
|
-
const message = conversation.messages[index];
|
|
1122
|
-
if (message?.role !== "user") {
|
|
1123
|
-
continue;
|
|
1124
|
-
}
|
|
1125
|
-
if (buildDeterministicTurnId(message.id) === sessionId) {
|
|
1126
|
-
return message;
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
return void 0;
|
|
1130
|
-
}
|
|
1131
|
-
function getTurnUserMessageId(conversation, sessionId) {
|
|
1132
|
-
return getTurnUserMessage(conversation, sessionId)?.id;
|
|
1133
|
-
}
|
|
1134
|
-
function getTurnUserSlackMessageTs(message) {
|
|
1135
|
-
return parseSlackMessageTs(message?.meta?.slackTs);
|
|
1136
|
-
}
|
|
1137
|
-
function getTurnUserReplyAttachmentContext(message) {
|
|
1138
|
-
const inboundAttachmentCount = message?.meta?.attachmentCount ?? 0;
|
|
1139
|
-
const imageAttachmentCount = message?.meta?.imageAttachmentCount ?? 0;
|
|
1140
|
-
const imagesHydrated = message?.meta?.imagesHydrated === true;
|
|
1141
|
-
return {
|
|
1142
|
-
...inboundAttachmentCount > 0 ? { inboundAttachmentCount } : {},
|
|
1143
|
-
...!imagesHydrated && imageAttachmentCount > 0 ? { omittedImageAttachmentCount: imageAttachmentCount } : {}
|
|
1144
|
-
};
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
// src/chat/runtime/auth-pause-state.ts
|
|
1148
|
-
function completeAuthPauseTurn(args) {
|
|
1149
|
-
markConversationMessage(
|
|
1150
|
-
args.conversation,
|
|
1151
|
-
getTurnUserMessageId(args.conversation, args.sessionId),
|
|
1152
|
-
{
|
|
1153
|
-
replied: true,
|
|
1154
|
-
skippedReason: void 0
|
|
1155
|
-
}
|
|
1156
|
-
);
|
|
1157
|
-
markTurnClosed({
|
|
1158
|
-
conversation: args.conversation,
|
|
1159
|
-
nowMs: Date.now(),
|
|
1160
|
-
sessionId: args.sessionId
|
|
1161
|
-
});
|
|
1162
|
-
}
|
|
1163
|
-
async function persistAuthPauseTurnState(args) {
|
|
1164
|
-
const currentState = await getPersistedThreadState(args.threadStateId);
|
|
1165
|
-
const conversation = coerceThreadConversationState(currentState);
|
|
1166
|
-
await hydrateConversationMessages({
|
|
1167
|
-
conversation,
|
|
1168
|
-
conversationId: args.threadStateId
|
|
1169
|
-
});
|
|
1170
|
-
completeAuthPauseTurn({
|
|
1171
|
-
conversation,
|
|
1172
|
-
sessionId: args.sessionId
|
|
1173
|
-
});
|
|
1174
|
-
await persistThreadStateById(args.threadStateId, { conversation });
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
1001
|
export {
|
|
1178
1002
|
recordTaskExecution,
|
|
1179
1003
|
readTaskExecutionSummaries,
|
|
@@ -1197,18 +1021,7 @@ export {
|
|
|
1197
1021
|
listPendingDispatchMailboxAppends,
|
|
1198
1022
|
claimDispatchMailboxAppend,
|
|
1199
1023
|
getPluginDispatchProjection,
|
|
1200
|
-
buildDeliveredTurnStatePatch,
|
|
1201
|
-
getTurnUserMessage,
|
|
1202
|
-
getTurnUserMessageId,
|
|
1203
|
-
getTurnUserSlackMessageTs,
|
|
1204
|
-
getTurnUserReplyAttachmentContext,
|
|
1205
1024
|
resolveTurnSessionRouting,
|
|
1206
1025
|
scheduleSessionCompletedPluginTasks,
|
|
1207
|
-
processPluginTask
|
|
1208
|
-
getInterruptionMarker,
|
|
1209
|
-
requireTurnFailureEventId,
|
|
1210
|
-
getAgentTurnDiagnosticsAttributes,
|
|
1211
|
-
finalizeFailedTurnReplyWithEvent,
|
|
1212
|
-
completeAuthPauseTurn,
|
|
1213
|
-
persistAuthPauseTurnState
|
|
1026
|
+
processPluginTask
|
|
1214
1027
|
};
|