@sentry/junior 0.179.0 → 0.180.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-DKDDRKZA.js} +16 -18
- package/dist/api/schema.js +0 -1
- package/dist/api.js +199 -197
- package/dist/app.d.ts +4 -0
- package/dist/app.js +300 -1259
- package/dist/catalog-runtime-WXKGUF3W.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/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/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/{chunk-B6ECUSVX.js → chunk-2AYEVN7K.js} +8 -8
- package/dist/{chunk-SLGGOASN.js → chunk-2YIRH4E3.js} +46 -46
- package/dist/{chunk-KJLHIHFF.js → chunk-3ILJBWP7.js} +35 -227
- package/dist/{chunk-RZRYOLCE.js → chunk-5PUMIMNQ.js} +2292 -1147
- package/dist/{chunk-CJLBLELR.js → chunk-5TUR4M3M.js} +8 -61
- package/dist/{chunk-6ZWRNC4D.js → chunk-6Y5B5PEX.js} +1 -1
- package/dist/{chunk-XSPSCWLH.js → chunk-6YCEWOLO.js} +4 -4
- package/dist/chunk-7H2VZTWN.js +103 -0
- package/dist/{chunk-FAS6AIMF.js → chunk-CCDXTDSY.js} +8 -8
- package/dist/{chunk-CGA4ERJ5.js → chunk-CEMMLV5L.js} +1 -1
- package/dist/{chunk-XZY6G5YZ.js → chunk-CK6EINVZ.js} +180 -87
- package/dist/{chunk-FIANEE7Z.js → chunk-CM5HNV2W.js} +6 -6
- package/dist/{chunk-JT4WMD3C.js → chunk-CP73FKME.js} +144 -218
- package/dist/{chunk-3I7XE3PA.js → chunk-DHLOGWYH.js} +36 -36
- package/dist/chunk-DKIJ2RP5.js +68 -0
- package/dist/{chunk-YFNAMRGE.js → chunk-DRHEGXTZ.js} +1 -1
- package/dist/{chunk-OOUNJNMR.js → chunk-DWPN6SCH.js} +1 -1
- package/dist/chunk-EWHP2IRG.js +209 -0
- package/dist/{chunk-R6U7N4FS.js → chunk-FGC3PHNH.js} +3 -3
- package/dist/{chunk-3TM3FYLQ.js → chunk-GA5NS74S.js} +1 -1
- package/dist/{chunk-FIDMHAO6.js → chunk-GPXAHUQH.js} +84 -274
- package/dist/chunk-GUKXEPMX.js +218 -0
- package/dist/{chunk-GENV6KF2.js → chunk-I6IFTAPF.js} +108 -76
- package/dist/{chunk-R5NWWYIS.js → chunk-IANUX7HX.js} +5 -5
- package/dist/{chunk-G2CAC4CV.js → chunk-KCL6AWYW.js} +74 -68
- package/dist/{chunk-5IRROPA5.js → chunk-L7LTGN4Z.js} +129 -31
- package/dist/{chunk-Q5B3WTGG.js → chunk-LGVQLNLS.js} +42 -41
- package/dist/chunk-M3QYTBQ6.js +55 -0
- package/dist/{chunk-FTGD2FBP.js → chunk-MXEUIGHO.js} +2 -2
- package/dist/{chunk-M63DETLL.js → chunk-N7TMSOZH.js} +6 -6
- package/dist/{chunk-2HIPYNQI.js → chunk-O4QYZTDK.js} +33 -32
- package/dist/chunk-PEQXYSSE.js +45 -0
- package/dist/{chunk-RTRBYSF3.js → chunk-QSO7B5JO.js} +1 -1
- package/dist/{chunk-HQNE5APD.js → chunk-RAZG3YHC.js} +100 -79
- package/dist/{chunk-VP4OVRDD.js → chunk-S7YRTOSQ.js} +69 -73
- package/dist/{chunk-U4TKB6F6.js → chunk-SDBKZ5LV.js} +108 -5
- package/dist/{chunk-GPLAT6H7.js → chunk-TC5DE5KJ.js} +22 -18
- package/dist/{chunk-H4HBKISO.js → chunk-TXKUKMVO.js} +1 -1
- package/dist/chunk-U5EUCUBH.js +164 -0
- package/dist/{chunk-3AFVR5UC.js → chunk-VG722ONZ.js} +18 -16
- package/dist/{chunk-ZQMG3CL5.js → chunk-VGPPWWHF.js} +16 -16
- package/dist/{chunk-JMJNFEDC.js → chunk-WVAMRKYG.js} +9 -54
- package/dist/chunk-X6GDDWQH.js +60 -0
- package/dist/{chunk-4GWXAILB.js → chunk-ZE2KOV3G.js} +1 -1
- package/dist/{chunk-TIEKUH4Q.js → chunk-ZM7ZURJS.js} +4 -3
- 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-EJAV7JL6.js → db-6SBHIAJK.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-WSDQPZZS.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-GWTSWESR.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-F32BPFYW.js +27 -0
- package/dist/spawn-X5BPP5OE.js +37 -0
- package/dist/task-runner-2FPBV5PP.js +32 -0
- package/dist/validation-62WO524A.js +17 -0
- package/dist/vercel.js +0 -1
- package/dist/version.js +1 -2
- package/dist/work-3C3CMZ24.js +45 -0
- package/dist/worker-MFAI6ZEK.js +22 -0
- package/package.json +8 -7
- 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
|
@@ -1,88 +1,90 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createWebAuthorization,
|
|
3
3
|
deleteWebAuthorization
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import {
|
|
6
|
-
appendAndEnqueueInboundMessage
|
|
7
|
-
} from "./chunk-5IRROPA5.js";
|
|
4
|
+
} from "./chunk-MXEUIGHO.js";
|
|
8
5
|
import {
|
|
9
6
|
buildDeliveredTurnStatePatch,
|
|
10
7
|
completeAuthPauseTurn,
|
|
11
8
|
finalizeFailedTurnReplyWithEvent,
|
|
12
|
-
getTurnUserMessage
|
|
9
|
+
getTurnUserMessage
|
|
10
|
+
} from "./chunk-EWHP2IRG.js";
|
|
11
|
+
import {
|
|
13
12
|
processPluginTask,
|
|
14
13
|
scheduleSessionCompletedPluginTasks
|
|
15
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-3ILJBWP7.js";
|
|
15
|
+
import {
|
|
16
|
+
ConversationTurnLifecycleService
|
|
17
|
+
} from "./chunk-M3QYTBQ6.js";
|
|
16
18
|
import {
|
|
17
|
-
ConversationTurnLifecycleService,
|
|
18
19
|
coerceThreadConversationState,
|
|
19
20
|
getPersistedSandboxState,
|
|
20
21
|
getPersistedThreadState,
|
|
21
22
|
persistThreadStateById
|
|
22
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-5TUR4M3M.js";
|
|
23
24
|
import {
|
|
24
25
|
healthReportSchema
|
|
25
26
|
} from "./chunk-UTL3MHPC.js";
|
|
26
27
|
import {
|
|
27
28
|
parseSlackThreadId
|
|
28
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-CCDXTDSY.js";
|
|
30
|
+
import {
|
|
31
|
+
appendAndEnqueueInboundMessage
|
|
32
|
+
} from "./chunk-L7LTGN4Z.js";
|
|
29
33
|
import {
|
|
30
34
|
TurnInputCommitLostError,
|
|
31
|
-
abandonTurnRecord,
|
|
32
|
-
buildConversationContext,
|
|
33
35
|
buildDeterministicTurnId,
|
|
34
36
|
clearPendingAuth,
|
|
35
37
|
getAssistantReplyText,
|
|
36
38
|
getConversationTurnBoundaryError,
|
|
39
|
+
isTurnInputCommitLostError,
|
|
40
|
+
markTurnClosed,
|
|
41
|
+
markTurnFailed,
|
|
42
|
+
startActiveTurn
|
|
43
|
+
} from "./chunk-GUKXEPMX.js";
|
|
44
|
+
import {
|
|
45
|
+
abandonTurnRecord,
|
|
46
|
+
buildConversationContext,
|
|
37
47
|
getTurnRecord,
|
|
38
48
|
hydrateConversationMessages,
|
|
39
|
-
isTurnInputCommitLostError,
|
|
40
49
|
listTurnSummaries,
|
|
41
50
|
loadProjection,
|
|
42
51
|
markConversationMessage,
|
|
43
|
-
markTurnClosed,
|
|
44
|
-
markTurnFailed,
|
|
45
52
|
normalizeConversationText,
|
|
46
53
|
persistConversationMessages,
|
|
47
54
|
persistWithRetry,
|
|
48
55
|
recordDeliveredAssistantMessage,
|
|
49
56
|
saveTurnCheckpoint,
|
|
50
|
-
startActiveTurn,
|
|
51
57
|
upsertConversationMessage
|
|
52
|
-
} from "./chunk-
|
|
58
|
+
} from "./chunk-GPXAHUQH.js";
|
|
53
59
|
import {
|
|
54
60
|
normalizeSlackConversationId
|
|
55
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-DHLOGWYH.js";
|
|
56
62
|
import {
|
|
57
63
|
getConversationEventStore,
|
|
58
64
|
getConversationStore,
|
|
59
65
|
getDb
|
|
60
|
-
} from "./chunk-
|
|
66
|
+
} from "./chunk-S7YRTOSQ.js";
|
|
61
67
|
import {
|
|
62
68
|
juniorApiTokens,
|
|
63
69
|
juniorConversationParticipants,
|
|
64
70
|
juniorConversations,
|
|
65
71
|
juniorIdentities,
|
|
66
72
|
juniorUsers
|
|
67
|
-
} from "./chunk-
|
|
68
|
-
import {
|
|
69
|
-
getSlackBotToken
|
|
70
|
-
} from "./chunk-GENV6KF2.js";
|
|
73
|
+
} from "./chunk-FGC3PHNH.js";
|
|
71
74
|
import {
|
|
72
75
|
juniorDestinations
|
|
73
76
|
} from "./chunk-VFUK3X5B.js";
|
|
74
77
|
import {
|
|
75
78
|
canExposeConversationPayload
|
|
76
|
-
} from "./chunk-
|
|
79
|
+
} from "./chunk-6YCEWOLO.js";
|
|
77
80
|
import {
|
|
78
81
|
credentialContextForActor
|
|
79
|
-
} from "./chunk-
|
|
82
|
+
} from "./chunk-CEMMLV5L.js";
|
|
80
83
|
import {
|
|
81
84
|
logException,
|
|
82
|
-
logWarn,
|
|
83
85
|
setTags,
|
|
84
86
|
withLogContext
|
|
85
|
-
} from "./chunk-
|
|
87
|
+
} from "./chunk-RAZG3YHC.js";
|
|
86
88
|
|
|
87
89
|
// src/handlers/health.ts
|
|
88
90
|
function readHealthReport() {
|
|
@@ -259,6 +261,7 @@ function createApiTurnCancellation() {
|
|
|
259
261
|
}
|
|
260
262
|
async function completeCancelledApiTurn(args) {
|
|
261
263
|
try {
|
|
264
|
+
const ownsPendingAuthorization = args.conversation.processing.pendingAuth?.sessionId === args.turnId;
|
|
262
265
|
await abandonTurnRecord({
|
|
263
266
|
conversationId: args.conversationId,
|
|
264
267
|
turnId: args.turnId,
|
|
@@ -274,10 +277,12 @@ async function completeCancelledApiTurn(args) {
|
|
|
274
277
|
nowMs: Date.now(),
|
|
275
278
|
sessionId: args.turnId
|
|
276
279
|
});
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
280
|
+
if (ownsPendingAuthorization) {
|
|
281
|
+
await deleteWebAuthorization({
|
|
282
|
+
actorId: args.actorId,
|
|
283
|
+
conversationId: args.conversationId
|
|
284
|
+
});
|
|
285
|
+
}
|
|
281
286
|
await persistThreadStateById(args.conversationId, {
|
|
282
287
|
conversation: args.conversation,
|
|
283
288
|
sandboxRef: args.sandboxRef
|
|
@@ -306,6 +311,21 @@ var apiTurnMailboxMetadataSchema = z.object({
|
|
|
306
311
|
kind: z.literal("api_turn"),
|
|
307
312
|
messageId: z.string().min(1)
|
|
308
313
|
}).strict();
|
|
314
|
+
async function getActiveApiTurnId(conversationId) {
|
|
315
|
+
const summaries = await listTurnSummaries(conversationId);
|
|
316
|
+
const active = summaries.filter(
|
|
317
|
+
(summary) => summary.surface === "api" && !summary.dispatchId && (summary.state === "paused" || summary.state === "running")
|
|
318
|
+
);
|
|
319
|
+
if (active.length > 1) {
|
|
320
|
+
throw new Error(
|
|
321
|
+
`Conversation ${conversationId} has multiple active web turns`
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
const turnId = active[0]?.turnId;
|
|
325
|
+
if (!turnId) return void 0;
|
|
326
|
+
const record = await getTurnRecord(conversationId, turnId);
|
|
327
|
+
return record && record.surface === "api" && !record.dispatchId && (record.state === "paused" || record.state === "running") ? turnId : void 0;
|
|
328
|
+
}
|
|
309
329
|
function parseApiTurnMessages(messages) {
|
|
310
330
|
if (messages.length === 0) {
|
|
311
331
|
return [];
|
|
@@ -335,24 +355,8 @@ async function resolveApiTurnWork(context) {
|
|
|
335
355
|
if (context.attempt.messages.length > 0) {
|
|
336
356
|
return void 0;
|
|
337
357
|
}
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
(summary) => summary.surface === "api" && !summary.dispatchId && (summary.state === "paused" || summary.state === "running")
|
|
341
|
-
);
|
|
342
|
-
if (active.length > 1) {
|
|
343
|
-
throw new Error(
|
|
344
|
-
`Conversation ${context.conversationId} has multiple active web turns`
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
const turnId = active[0]?.turnId;
|
|
348
|
-
if (!turnId) {
|
|
349
|
-
return void 0;
|
|
350
|
-
}
|
|
351
|
-
const record = await getTurnRecord(context.conversationId, turnId);
|
|
352
|
-
if (!record || record.surface !== "api" || Boolean(record.dispatchId) || record.state !== "paused" && record.state !== "running") {
|
|
353
|
-
return void 0;
|
|
354
|
-
}
|
|
355
|
-
return { kind: "resume", turnId };
|
|
358
|
+
const turnId = await getActiveApiTurnId(context.conversationId);
|
|
359
|
+
return turnId ? { kind: "resume", turnId } : void 0;
|
|
356
360
|
}
|
|
357
361
|
async function isApiTurnWork(context) {
|
|
358
362
|
return await resolveApiTurnWork(context) !== void 0;
|
|
@@ -371,7 +375,7 @@ function createApiConversationId(args) {
|
|
|
371
375
|
args.idempotencyKey
|
|
372
376
|
)}`;
|
|
373
377
|
}
|
|
374
|
-
function
|
|
378
|
+
function apiConversationMessageId(args) {
|
|
375
379
|
return `api-msg:${stableHex(args.conversationId, args.idempotencyKey)}`;
|
|
376
380
|
}
|
|
377
381
|
function apiTurnIdForMessage(messageId) {
|
|
@@ -404,14 +408,14 @@ function actorFromMetadata(metadata2) {
|
|
|
404
408
|
platform: "web",
|
|
405
409
|
userId: metadata2.authorUserId,
|
|
406
410
|
email: normalizeEmail2(metadata2.authorEmail),
|
|
407
|
-
...metadata2.authorFullName ? { fullName: metadata2.authorFullName } :
|
|
408
|
-
...metadata2.authorUserName ? { userName: metadata2.authorUserName } :
|
|
411
|
+
...metadata2.authorFullName ? { fullName: metadata2.authorFullName } : void 0,
|
|
412
|
+
...metadata2.authorUserName ? { userName: metadata2.authorUserName } : void 0
|
|
409
413
|
};
|
|
410
414
|
}
|
|
411
415
|
function storedActorFromApi(actor) {
|
|
412
416
|
return {
|
|
413
|
-
...actor.email ? { email: normalizeEmail2(actor.email) } :
|
|
414
|
-
...actor.fullName ? { fullName: actor.fullName } :
|
|
417
|
+
...actor.email ? { email: normalizeEmail2(actor.email) } : void 0,
|
|
418
|
+
...actor.fullName ? { fullName: actor.fullName } : void 0
|
|
415
419
|
};
|
|
416
420
|
}
|
|
417
421
|
function webActorFromEmail(email, profile) {
|
|
@@ -420,8 +424,8 @@ function webActorFromEmail(email, profile) {
|
|
|
420
424
|
platform: "web",
|
|
421
425
|
userId: `dashboard:${stableHex(normalized)}`,
|
|
422
426
|
email: normalized,
|
|
423
|
-
...profile?.fullName ? { fullName: profile.fullName } :
|
|
424
|
-
...profile?.userName ? { userName: profile.userName } :
|
|
427
|
+
...profile?.fullName ? { fullName: profile.fullName } : void 0,
|
|
428
|
+
...profile?.userName ? { userName: profile.userName } : void 0
|
|
425
429
|
};
|
|
426
430
|
}
|
|
427
431
|
function actorFromStoredConversation(stored) {
|
|
@@ -458,9 +462,9 @@ function buildApiTurnInboundMessage(args) {
|
|
|
458
462
|
text,
|
|
459
463
|
metadata: {
|
|
460
464
|
authorEmail: normalizeEmail2(args.actor.email),
|
|
461
|
-
...args.actor.fullName ? { authorFullName: args.actor.fullName } :
|
|
465
|
+
...args.actor.fullName ? { authorFullName: args.actor.fullName } : void 0,
|
|
462
466
|
authorUserId: args.actor.userId,
|
|
463
|
-
...args.actor.userName ? { authorUserName: args.actor.userName } :
|
|
467
|
+
...args.actor.userName ? { authorUserName: args.actor.userName } : void 0,
|
|
464
468
|
kind: "api_turn",
|
|
465
469
|
messageId: args.messageId
|
|
466
470
|
}
|
|
@@ -490,9 +494,9 @@ async function recordApiConversationActivity(args) {
|
|
|
490
494
|
actor: storedActorFromApi(args.actor),
|
|
491
495
|
// Do not rewrite a Slack root's origin source when a dashboard participant
|
|
492
496
|
// continues it. Mailbox entries still carry source "web" per turn.
|
|
493
|
-
...isNewRoot ? { source: "web" } :
|
|
494
|
-
...source ? { sessionSource: source } :
|
|
495
|
-
...isNewRoot ? { visibility } :
|
|
497
|
+
...isNewRoot ? { source: "web" } : void 0,
|
|
498
|
+
...source ? { sessionSource: source } : void 0,
|
|
499
|
+
...isNewRoot ? { visibility } : void 0
|
|
496
500
|
});
|
|
497
501
|
return destination;
|
|
498
502
|
}
|
|
@@ -524,7 +528,7 @@ async function appendAndEnqueueApiConversationMessage(input, options) {
|
|
|
524
528
|
throw new Error("API conversation actor requires a verified email");
|
|
525
529
|
}
|
|
526
530
|
const nowMs = options.nowMs ?? Date.now();
|
|
527
|
-
const messageId =
|
|
531
|
+
const messageId = apiConversationMessageId({
|
|
528
532
|
conversationId: input.conversationId,
|
|
529
533
|
idempotencyKey: input.idempotencyKey
|
|
530
534
|
});
|
|
@@ -533,7 +537,7 @@ async function appendAndEnqueueApiConversationMessage(input, options) {
|
|
|
533
537
|
conversationId: input.conversationId,
|
|
534
538
|
conversationStore: options.conversationStore,
|
|
535
539
|
nowMs,
|
|
536
|
-
...input.rootVisibility ? { rootVisibility: input.rootVisibility } :
|
|
540
|
+
...input.rootVisibility ? { rootVisibility: input.rootVisibility } : void 0
|
|
537
541
|
});
|
|
538
542
|
const result = await appendAndEnqueueInboundMessage({
|
|
539
543
|
message: buildApiTurnInboundMessage({
|
|
@@ -558,7 +562,7 @@ async function appendAndEnqueueApiConversationMessage(input, options) {
|
|
|
558
562
|
function captureApiBoundaryFailure(args) {
|
|
559
563
|
const eventId = logException(args.error, `api.turn.${args.failureCode}`, {
|
|
560
564
|
conversationId: args.conversationId,
|
|
561
|
-
...args.runId ? { runId: args.runId } :
|
|
565
|
+
...args.runId ? { runId: args.runId } : void 0,
|
|
562
566
|
turnId: args.turnId
|
|
563
567
|
});
|
|
564
568
|
return typeof eventId === "string" ? eventId : void 0;
|
|
@@ -628,7 +632,7 @@ function createApiTurnWorker(options) {
|
|
|
628
632
|
conversationId: context.conversationId,
|
|
629
633
|
platform: "web",
|
|
630
634
|
userId: actor.userId,
|
|
631
|
-
...actor.userName ? { userName: actor.userName } :
|
|
635
|
+
...actor.userName ? { userName: actor.userName } : void 0
|
|
632
636
|
},
|
|
633
637
|
async () => {
|
|
634
638
|
let acknowledged = isResume || context.attempt.messages.length === 0;
|
|
@@ -653,6 +657,36 @@ function createApiTurnWorker(options) {
|
|
|
653
657
|
});
|
|
654
658
|
let sandboxRef = getPersistedSandboxState(persisted);
|
|
655
659
|
const initialSandboxRef = sandboxRef;
|
|
660
|
+
const appSignal = options.cancellation?.signal(context.conversationId);
|
|
661
|
+
const stopSignal = context.stopSignal?.();
|
|
662
|
+
const cancellationSignal = appSignal && stopSignal ? AbortSignal.any([appSignal, stopSignal]) : appSignal ?? stopSignal;
|
|
663
|
+
const finishCancellation = () => {
|
|
664
|
+
if (appSignal) {
|
|
665
|
+
options.cancellation?.finish(context.conversationId, appSignal);
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
const completeCancelledTurn = async () => {
|
|
669
|
+
try {
|
|
670
|
+
await completeCancelledApiTurn({
|
|
671
|
+
acknowledge,
|
|
672
|
+
actorId: actor.userId,
|
|
673
|
+
cancellation: options.cancellation,
|
|
674
|
+
conversation,
|
|
675
|
+
conversationId: context.conversationId,
|
|
676
|
+
lifecycle,
|
|
677
|
+
sandboxRef,
|
|
678
|
+
signal: appSignal,
|
|
679
|
+
turnId,
|
|
680
|
+
userMessageId
|
|
681
|
+
});
|
|
682
|
+
} catch (error) {
|
|
683
|
+
if (hasLostTurnInputCommit(error)) {
|
|
684
|
+
return { status: "lost_lease" };
|
|
685
|
+
}
|
|
686
|
+
throw error;
|
|
687
|
+
}
|
|
688
|
+
return { status: "completed" };
|
|
689
|
+
};
|
|
656
690
|
if (isResume) {
|
|
657
691
|
const userMessage = getTurnUserMessage(conversation, turnId);
|
|
658
692
|
if (!userMessage) {
|
|
@@ -664,38 +698,20 @@ function createApiTurnWorker(options) {
|
|
|
664
698
|
text = userMessage.text;
|
|
665
699
|
startedAtMs = userMessage.createdAtMs;
|
|
666
700
|
inputMessageIds = [userMessageId];
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
(summary) => summary.surface === "api" && !summary.dispatchId && summary.state === "paused" && summary.resumeReason === "auth"
|
|
670
|
-
);
|
|
671
|
-
for (const parked of authParked) {
|
|
672
|
-
await abandonTurnRecord({
|
|
673
|
-
conversationId: context.conversationId,
|
|
674
|
-
turnId: parked.turnId,
|
|
675
|
-
errorMessage: "Auth-parked session superseded by a new user message"
|
|
676
|
-
});
|
|
677
|
-
markTurnClosed({
|
|
678
|
-
conversation,
|
|
679
|
-
nowMs: Date.now(),
|
|
680
|
-
sessionId: parked.turnId
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
if (authParked.length > 0) {
|
|
684
|
-
await deleteWebAuthorization({
|
|
685
|
-
actorId: actor.userId,
|
|
686
|
-
conversationId: context.conversationId
|
|
687
|
-
});
|
|
701
|
+
if (cancellationSignal?.aborted) {
|
|
702
|
+
return await completeCancelledTurn();
|
|
688
703
|
}
|
|
704
|
+
} else {
|
|
689
705
|
upsertConversationMessage(conversation, {
|
|
690
706
|
id: userMessageId,
|
|
691
707
|
role: "user",
|
|
692
708
|
text: normalizeConversationText(text),
|
|
693
709
|
createdAtMs: startedAtMs,
|
|
694
710
|
author: {
|
|
695
|
-
...actor.email ? { email: actor.email } :
|
|
696
|
-
...actor.fullName ? { fullName: actor.fullName } :
|
|
711
|
+
...actor.email ? { email: actor.email } : void 0,
|
|
712
|
+
...actor.fullName ? { fullName: actor.fullName } : void 0,
|
|
697
713
|
userId: actor.userId,
|
|
698
|
-
...actor.userName ? { userName: actor.userName } :
|
|
714
|
+
...actor.userName ? { userName: actor.userName } : void 0
|
|
699
715
|
},
|
|
700
716
|
meta: {
|
|
701
717
|
explicitMention: true,
|
|
@@ -714,6 +730,9 @@ function createApiTurnWorker(options) {
|
|
|
714
730
|
surface: "api",
|
|
715
731
|
turnId
|
|
716
732
|
});
|
|
733
|
+
if (cancellationSignal?.aborted) {
|
|
734
|
+
return await completeCancelledTurn();
|
|
735
|
+
}
|
|
717
736
|
startActiveTurn({
|
|
718
737
|
conversation,
|
|
719
738
|
nextTurnId: turnId
|
|
@@ -725,39 +744,6 @@ function createApiTurnWorker(options) {
|
|
|
725
744
|
let modelFailureEventId;
|
|
726
745
|
let modelFailureCaptureAttempted = false;
|
|
727
746
|
let reply;
|
|
728
|
-
const cancellationSignal = options.cancellation?.signal(
|
|
729
|
-
context.conversationId
|
|
730
|
-
);
|
|
731
|
-
const finishCancellation = () => {
|
|
732
|
-
if (cancellationSignal) {
|
|
733
|
-
options.cancellation?.finish(
|
|
734
|
-
context.conversationId,
|
|
735
|
-
cancellationSignal
|
|
736
|
-
);
|
|
737
|
-
}
|
|
738
|
-
};
|
|
739
|
-
const completeCancelledTurn = async () => {
|
|
740
|
-
try {
|
|
741
|
-
await completeCancelledApiTurn({
|
|
742
|
-
acknowledge,
|
|
743
|
-
actorId: actor.userId,
|
|
744
|
-
cancellation: options.cancellation,
|
|
745
|
-
conversation,
|
|
746
|
-
conversationId: context.conversationId,
|
|
747
|
-
lifecycle,
|
|
748
|
-
sandboxRef,
|
|
749
|
-
signal: cancellationSignal,
|
|
750
|
-
turnId,
|
|
751
|
-
userMessageId
|
|
752
|
-
});
|
|
753
|
-
} catch (error) {
|
|
754
|
-
if (hasLostTurnInputCommit(error)) {
|
|
755
|
-
return { status: "lost_lease" };
|
|
756
|
-
}
|
|
757
|
-
throw error;
|
|
758
|
-
}
|
|
759
|
-
return { status: "completed" };
|
|
760
|
-
};
|
|
761
747
|
const deliverAssistantMessage = async (value) => {
|
|
762
748
|
const replyText = typeof value === "string" ? value : getAssistantReplyText(value);
|
|
763
749
|
if (!replyText?.trim()) {
|
|
@@ -791,6 +777,35 @@ function createApiTurnWorker(options) {
|
|
|
791
777
|
failureCode = "agent_run_failed";
|
|
792
778
|
};
|
|
793
779
|
try {
|
|
780
|
+
if (cancellationSignal?.aborted) {
|
|
781
|
+
return await completeCancelledTurn();
|
|
782
|
+
}
|
|
783
|
+
if (!isResume) {
|
|
784
|
+
const authParked = (await listTurnSummaries(context.conversationId)).filter(
|
|
785
|
+
(summary) => summary.surface === "api" && !summary.dispatchId && summary.state === "paused" && summary.resumeReason === "auth"
|
|
786
|
+
);
|
|
787
|
+
for (const parked of authParked) {
|
|
788
|
+
if (cancellationSignal?.aborted) {
|
|
789
|
+
return await completeCancelledTurn();
|
|
790
|
+
}
|
|
791
|
+
await abandonTurnRecord({
|
|
792
|
+
conversationId: context.conversationId,
|
|
793
|
+
turnId: parked.turnId,
|
|
794
|
+
errorMessage: "Auth-parked session superseded by a new user message"
|
|
795
|
+
});
|
|
796
|
+
markTurnClosed({
|
|
797
|
+
conversation,
|
|
798
|
+
nowMs: Date.now(),
|
|
799
|
+
sessionId: parked.turnId
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
if (authParked.length > 0) {
|
|
803
|
+
await deleteWebAuthorization({
|
|
804
|
+
actorId: actor.userId,
|
|
805
|
+
conversationId: context.conversationId
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
}
|
|
794
809
|
await persistThreadStateById(context.conversationId, {
|
|
795
810
|
conversation
|
|
796
811
|
});
|
|
@@ -820,7 +835,7 @@ function createApiTurnWorker(options) {
|
|
|
820
835
|
publishExternally: false,
|
|
821
836
|
source,
|
|
822
837
|
surface: "api",
|
|
823
|
-
...cancellationSignal ? { signal: cancellationSignal } :
|
|
838
|
+
...cancellationSignal ? { signal: cancellationSignal } : void 0,
|
|
824
839
|
authorization: createWebAuthorization({
|
|
825
840
|
actorId: actor.userId,
|
|
826
841
|
conversationId: context.conversationId
|
|
@@ -864,14 +879,11 @@ function createApiTurnWorker(options) {
|
|
|
864
879
|
conversation,
|
|
865
880
|
sandboxRef
|
|
866
881
|
});
|
|
867
|
-
if (
|
|
868
|
-
options.cancellation?.park(
|
|
869
|
-
context.conversationId,
|
|
870
|
-
cancellationSignal
|
|
871
|
-
);
|
|
882
|
+
if (appSignal) {
|
|
883
|
+
options.cancellation?.park(context.conversationId, appSignal);
|
|
872
884
|
}
|
|
873
885
|
await acknowledge();
|
|
874
|
-
return { status: "
|
|
886
|
+
return { status: "paused" };
|
|
875
887
|
}
|
|
876
888
|
finishCancellation();
|
|
877
889
|
reply = outcome.result;
|
|
@@ -954,7 +966,7 @@ function createApiTurnWorker(options) {
|
|
|
954
966
|
await lifecycle.fail({
|
|
955
967
|
conversationId: context.conversationId,
|
|
956
968
|
createdAtMs: Date.now(),
|
|
957
|
-
...modelFailureEventId ? { eventId: modelFailureEventId } :
|
|
969
|
+
...modelFailureEventId ? { eventId: modelFailureEventId } : void 0,
|
|
958
970
|
failureCode: "model_execution_failed",
|
|
959
971
|
turnId
|
|
960
972
|
});
|
|
@@ -1002,7 +1014,7 @@ function createApiTurnWorker(options) {
|
|
|
1002
1014
|
await lifecycle.fail({
|
|
1003
1015
|
conversationId: context.conversationId,
|
|
1004
1016
|
createdAtMs: Date.now(),
|
|
1005
|
-
...failureEventId ? { eventId: failureEventId } :
|
|
1017
|
+
...failureEventId ? { eventId: failureEventId } : void 0,
|
|
1006
1018
|
failureCode,
|
|
1007
1019
|
turnId
|
|
1008
1020
|
});
|
|
@@ -1252,91 +1264,6 @@ async function readConversationAccessFromSql(db, conversationIds, viewer) {
|
|
|
1252
1264
|
);
|
|
1253
1265
|
}
|
|
1254
1266
|
|
|
1255
|
-
// src/chat/slack/user.ts
|
|
1256
|
-
import { z as z2 } from "zod";
|
|
1257
|
-
var slackUserInfoSchema = z2.object({
|
|
1258
|
-
ok: z2.literal(true),
|
|
1259
|
-
user: z2.object({
|
|
1260
|
-
name: z2.string().nullish(),
|
|
1261
|
-
profile: z2.object({
|
|
1262
|
-
email: z2.string().nullish(),
|
|
1263
|
-
real_name: z2.string().nullish()
|
|
1264
|
-
}).optional()
|
|
1265
|
-
})
|
|
1266
|
-
});
|
|
1267
|
-
var USER_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
1268
|
-
var userCache = /* @__PURE__ */ new Map();
|
|
1269
|
-
function userCacheKey(teamId, userId) {
|
|
1270
|
-
return `${teamId}:${userId}`;
|
|
1271
|
-
}
|
|
1272
|
-
function readFromCache(teamId, userId) {
|
|
1273
|
-
const hit = userCache.get(userCacheKey(teamId, userId));
|
|
1274
|
-
if (!hit) return null;
|
|
1275
|
-
if (hit.expiresAt < Date.now()) {
|
|
1276
|
-
userCache.delete(userCacheKey(teamId, userId));
|
|
1277
|
-
return null;
|
|
1278
|
-
}
|
|
1279
|
-
return hit.value;
|
|
1280
|
-
}
|
|
1281
|
-
function writeToCache(teamId, userId, value) {
|
|
1282
|
-
userCache.set(userCacheKey(teamId, userId), {
|
|
1283
|
-
value,
|
|
1284
|
-
expiresAt: Date.now() + USER_CACHE_TTL_MS
|
|
1285
|
-
});
|
|
1286
|
-
}
|
|
1287
|
-
async function lookupSlackUser(teamId, userId) {
|
|
1288
|
-
if (!teamId || !userId) {
|
|
1289
|
-
return null;
|
|
1290
|
-
}
|
|
1291
|
-
const cached = readFromCache(teamId, userId);
|
|
1292
|
-
if (cached) {
|
|
1293
|
-
return cached;
|
|
1294
|
-
}
|
|
1295
|
-
const token = getSlackBotToken();
|
|
1296
|
-
if (!token) {
|
|
1297
|
-
return null;
|
|
1298
|
-
}
|
|
1299
|
-
try {
|
|
1300
|
-
const response = await fetch(
|
|
1301
|
-
`https://slack.com/api/users.info?user=${encodeURIComponent(userId)}`,
|
|
1302
|
-
{
|
|
1303
|
-
headers: {
|
|
1304
|
-
authorization: `Bearer ${token}`
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
);
|
|
1308
|
-
if (!response.ok) {
|
|
1309
|
-
logWarn("slack.user.lookup.failed", {
|
|
1310
|
-
"enduser.id": userId,
|
|
1311
|
-
"app.slack.team_id": teamId,
|
|
1312
|
-
"http.response.status_code": response.status
|
|
1313
|
-
});
|
|
1314
|
-
return null;
|
|
1315
|
-
}
|
|
1316
|
-
const parsed = slackUserInfoSchema.safeParse(await response.json());
|
|
1317
|
-
if (!parsed.success) {
|
|
1318
|
-
return null;
|
|
1319
|
-
}
|
|
1320
|
-
const payload = parsed.data;
|
|
1321
|
-
const userName = payload.user.name?.trim() || void 0;
|
|
1322
|
-
const fullName = payload.user.profile?.real_name?.trim() || void 0;
|
|
1323
|
-
const result = {
|
|
1324
|
-
userName,
|
|
1325
|
-
fullName,
|
|
1326
|
-
email: payload.user.profile?.email?.trim() || void 0
|
|
1327
|
-
};
|
|
1328
|
-
writeToCache(teamId, userId, result);
|
|
1329
|
-
return result;
|
|
1330
|
-
} catch (error) {
|
|
1331
|
-
logWarn("slack.user.lookup.failed", {
|
|
1332
|
-
"enduser.id": userId,
|
|
1333
|
-
"app.slack.team_id": teamId,
|
|
1334
|
-
"exception.message": error instanceof Error ? error.message : String(error)
|
|
1335
|
-
});
|
|
1336
|
-
return null;
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
1267
|
// src/chat/slack/conversation-context.ts
|
|
1341
1268
|
function normalizeConversationName(type, channelName) {
|
|
1342
1269
|
const trimmed = channelName?.trim();
|
|
@@ -1390,8 +1317,8 @@ function resolveSlackConversationContext(input) {
|
|
|
1390
1317
|
);
|
|
1391
1318
|
return {
|
|
1392
1319
|
type,
|
|
1393
|
-
...name ? { name } :
|
|
1394
|
-
...visibility ? { visibility } :
|
|
1320
|
+
...name ? { name } : void 0,
|
|
1321
|
+
...visibility ? { visibility } : void 0
|
|
1395
1322
|
};
|
|
1396
1323
|
}
|
|
1397
1324
|
function resolveSlackConversationContextFromThreadId(input) {
|
|
@@ -1425,7 +1352,6 @@ export {
|
|
|
1425
1352
|
readHealthReport,
|
|
1426
1353
|
GET,
|
|
1427
1354
|
createVercelAttachmentStorage,
|
|
1428
|
-
lookupSlackUser,
|
|
1429
1355
|
conversationVisibilityFromSlackChannelType,
|
|
1430
1356
|
resolveSlackChannelTypeFromMessage,
|
|
1431
1357
|
resolveSlackConversationContext,
|