@sentry/junior 0.144.0 → 0.146.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/{agent-hooks-GCUTGKY3.js → agent-hooks-SLJADYE5.js} +10 -10
  2. package/dist/api/conversations/detail.d.ts +1 -0
  3. package/dist/api/schema/conversation.d.ts +2 -0
  4. package/dist/api/schema.js +1 -1
  5. package/dist/api.js +40 -22
  6. package/dist/app.js +400 -461
  7. package/dist/{catalog-runtime-DWVYKDC6.js → catalog-runtime-RQIMSDPR.js} +5 -5
  8. package/dist/chat/agent/request.d.ts +1 -1
  9. package/dist/chat/agent/resume.d.ts +6 -18
  10. package/dist/chat/agent/skills.d.ts +0 -1
  11. package/dist/chat/agent/tools.d.ts +1 -2
  12. package/dist/chat/agent-dispatch/types.d.ts +1 -1
  13. package/dist/chat/app/conversation-work.d.ts +24 -0
  14. package/dist/chat/conversations/message-search.d.ts +32 -0
  15. package/dist/chat/conversations/projection.d.ts +11 -3
  16. package/dist/chat/conversations/sql/message-search.d.ts +4 -0
  17. package/dist/chat/conversations/store.d.ts +1 -1
  18. package/dist/chat/conversations/tool-source.d.ts +5 -0
  19. package/dist/chat/db.d.ts +2 -2
  20. package/dist/chat/runtime/agent-run-outcome.d.ts +1 -1
  21. package/dist/chat/runtime/reply-executor.d.ts +5 -5
  22. package/dist/chat/runtime/slack-resume.d.ts +12 -4
  23. package/dist/chat/slack/message/attachments.d.ts +2 -0
  24. package/dist/chat/slack/message/blocks.d.ts +2 -0
  25. package/dist/chat/slack/message/content.d.ts +18 -0
  26. package/dist/chat/slack/message/identity.d.ts +7 -0
  27. package/dist/chat/slack/tools/{conversation-search.d.ts → conversation-message-search.d.ts} +21 -14
  28. package/dist/chat/slack/tools/user-lookup.d.ts +2 -1
  29. package/dist/chat/state/locks.d.ts +28 -0
  30. package/dist/chat/task-execution/checkpoint.d.ts +84 -0
  31. package/dist/chat/task-execution/paused-turn.d.ts +29 -0
  32. package/dist/chat/task-execution/queue-signing.d.ts +1 -0
  33. package/dist/chat/task-execution/queue.d.ts +7 -1
  34. package/dist/chat/task-execution/slack-work.d.ts +1 -1
  35. package/dist/chat/task-execution/state.d.ts +4 -4
  36. package/dist/chat/task-execution/store.d.ts +2 -2
  37. package/dist/chat/task-execution/turn-cursor-keys.d.ts +6 -0
  38. package/dist/chat/{state/turn-session.d.ts → task-execution/turn-cursor.d.ts} +52 -51
  39. package/dist/chat/task-execution/turn-wake.d.ts +29 -0
  40. package/dist/chat/tools/{query-conversation-events.d.ts → search-conversation-events.d.ts} +3 -3
  41. package/dist/chat/tools/types.d.ts +1 -1
  42. package/dist/{chunk-SBZP2J5Q.js → chunk-37EVZP66.js} +48 -35
  43. package/dist/{chunk-A67GZN73.js → chunk-37JJDS4H.js} +1 -1
  44. package/dist/{chunk-BBCWYXHB.js → chunk-47OSH2ZO.js} +7 -7
  45. package/dist/{chunk-4X5KM7Z6.js → chunk-AISNSNDV.js} +14 -14
  46. package/dist/{chunk-RIFJUJSI.js → chunk-B63BF443.js} +1 -1
  47. package/dist/{chunk-SSDTQDYQ.js → chunk-BLETMLRX.js} +566 -268
  48. package/dist/{chunk-I44JB7HQ.js → chunk-F7REGDKO.js} +1 -1
  49. package/dist/{chunk-DVO5VKYQ.js → chunk-FEKQHPVA.js} +5 -5
  50. package/dist/{chunk-SUK7NC5A.js → chunk-FGHADGIC.js} +2 -2
  51. package/dist/{chunk-7KAW7UF4.js → chunk-FXDDDSPL.js} +4 -4
  52. package/dist/{chunk-BEGGFVFR.js → chunk-GDQEU4I7.js} +414 -542
  53. package/dist/{chunk-UDQMY6RS.js → chunk-GYEKOX7N.js} +43 -1
  54. package/dist/{chunk-W7JFV5SB.js → chunk-H6U2U3EP.js} +14 -17
  55. package/dist/{chunk-WTX2RFJG.js → chunk-HQE6EJS5.js} +1 -1
  56. package/dist/{chunk-IUFM5JWV.js → chunk-JAL3CH4G.js} +3 -0
  57. package/dist/{chunk-E7HCWOHG.js → chunk-JLMVCNXL.js} +2 -1
  58. package/dist/{chunk-PELZ2ZSY.js → chunk-JUA6VU2Z.js} +33 -63
  59. package/dist/{chunk-SHEEZSLY.js → chunk-LVW7BLLT.js} +2 -2
  60. package/dist/{chunk-GKA74DRA.js → chunk-M6ZWP4RI.js} +1 -1
  61. package/dist/{chunk-HNO2E5WB.js → chunk-MCFIXAV5.js} +1 -1
  62. package/dist/{chunk-3GU4PWA3.js → chunk-MKRIZ4VG.js} +29 -30
  63. package/dist/{chunk-QUZJDAQQ.js → chunk-OFPYOC3M.js} +93 -90
  64. package/dist/{chunk-ZF3N3JD6.js → chunk-PB222GIA.js} +1 -1
  65. package/dist/{chunk-PKH6762I.js → chunk-PH4Q3A6W.js} +1 -1
  66. package/dist/{chunk-STFCL3K4.js → chunk-QG7OOKIN.js} +1 -1
  67. package/dist/{chunk-WSOLZJJS.js → chunk-QSXZ42KX.js} +3 -3
  68. package/dist/{chunk-44RJWAND.js → chunk-SCGVWUZX.js} +6 -6
  69. package/dist/{chunk-CNTWB2SM.js → chunk-T5GXFFLA.js} +1 -1
  70. package/dist/{chunk-LDWNYCZ6.js → chunk-TCEJ7XXM.js} +1 -1
  71. package/dist/{chunk-QE3TICD4.js → chunk-V6SRLKUB.js} +2 -2
  72. package/dist/{chunk-54JMYQYS.js → chunk-W65V465O.js} +2 -2
  73. package/dist/{chunk-KCBZSJRU.js → chunk-WR76IVA5.js} +5 -2
  74. package/dist/{chunk-ZZCTGAIT.js → chunk-X22KCSCO.js} +4 -4
  75. package/dist/{chunk-HD6BHR25.js → chunk-X2WMBTS3.js} +32 -34
  76. package/dist/{chunk-KQBXT5B7.js → chunk-ZDGHGY74.js} +6 -6
  77. package/dist/cli/chat.js +32 -32
  78. package/dist/cli/check.js +6 -6
  79. package/dist/cli/plugins.js +13 -13
  80. package/dist/cli/snapshot-create.js +9 -9
  81. package/dist/cli/upgrade.js +7 -7
  82. package/dist/{db-EFLHTBU6.js → db-WWOMXWTT.js} +9 -9
  83. package/dist/instrumentation.js +4 -4
  84. package/dist/nitro.js +4 -4
  85. package/dist/{oauth-callback-server-RO3IQKWM.js → oauth-callback-server-A6ZZX74U.js} +25 -25
  86. package/dist/{runner-LOWW7JKA.js → runner-KSGB2UAV.js} +19 -20
  87. package/dist/{skills-ZLMUG7AE.js → skills-26QPWKVS.js} +6 -6
  88. package/dist/spawn-5LAJXZ2P.js +39 -0
  89. package/dist/{validation-MAKEZNTS.js → validation-OPSRGFGH.js} +6 -6
  90. package/dist/version.js +1 -1
  91. package/dist/{work-5OAGC3I4.js → work-VMSW7STJ.js} +17 -16
  92. package/dist/worker-2JNFB7C7.js +24 -0
  93. package/package.json +5 -5
  94. package/dist/chat/agent/session.d.ts +0 -19
  95. package/dist/chat/conversations/search.d.ts +0 -24
  96. package/dist/chat/conversations/sql/search.d.ts +0 -4
  97. package/dist/chat/runtime/agent-continue-runner.d.ts +0 -37
  98. package/dist/chat/services/agent-continue.d.ts +0 -29
  99. package/dist/chat/services/turn-session-record.d.ts +0 -164
  100. package/dist/chat/slack/legacy-attachments.d.ts +0 -4
  101. package/dist/chat/slack/message.d.ts +0 -12
  102. package/dist/chat/state/turn-session-keys.d.ts +0 -6
  103. package/dist/spawn-R3LUV6RF.js +0 -38
  104. package/dist/worker-KTGGRTTP.js +0 -24
@@ -1,16 +1,54 @@
1
1
  import {
2
2
  getChatConfig
3
- } from "./chunk-3GU4PWA3.js";
3
+ } from "./chunk-MKRIZ4VG.js";
4
4
 
5
5
  // src/chat/state/adapter.ts
6
6
  import { createMemoryState } from "@chat-adapter/state-memory";
7
7
  import { createRedisState } from "@chat-adapter/state-redis";
8
8
 
9
9
  // src/chat/state/locks.ts
10
+ import { setTimeout as sleep } from "timers/promises";
10
11
  var ACTIVE_LOCK_TTL_MS = 9e4;
12
+ var MUTATION_LOCK_TTL_MS = 1e4;
11
13
  async function acquireActiveLock(state, threadId) {
12
14
  return await state.acquireLock(threadId, ACTIVE_LOCK_TTL_MS);
13
15
  }
16
+ async function withLock(state, key, run, options = {}) {
17
+ const startedAtMs = Date.now();
18
+ let lock;
19
+ while (true) {
20
+ lock = await state.acquireLock(key, options.ttlMs ?? ACTIVE_LOCK_TTL_MS);
21
+ if (lock) break;
22
+ if (Date.now() - startedAtMs >= (options.waitMs ?? 0)) {
23
+ return { acquired: false };
24
+ }
25
+ await sleep(options.retryMs ?? 25, void 0, { ref: false });
26
+ }
27
+ const ttlMs = options.ttlMs ?? ACTIVE_LOCK_TTL_MS;
28
+ const heartbeat = options.keepAlive ? setInterval(
29
+ () => {
30
+ void state.extendLock(lock, ttlMs);
31
+ },
32
+ Math.max(1, Math.floor(ttlMs / 3))
33
+ ) : void 0;
34
+ heartbeat?.unref();
35
+ try {
36
+ return { acquired: true, value: await run(lock) };
37
+ } finally {
38
+ if (heartbeat) clearInterval(heartbeat);
39
+ await state.releaseLock(lock);
40
+ }
41
+ }
42
+ async function fenceLock(state, lock, ttlMs = MUTATION_LOCK_TTL_MS) {
43
+ if (!await state.extendLock(lock, ttlMs)) {
44
+ throw new Error(
45
+ `Lock ownership was lost before write for ${lock.threadId}`
46
+ );
47
+ }
48
+ }
49
+ async function withActiveLock(state, key, run) {
50
+ return await withLock(state, key, run);
51
+ }
14
52
 
15
53
  // src/chat/state/adapter.ts
16
54
  var ACTIVE_LOCK_HEARTBEAT_MS = 3e4;
@@ -272,7 +310,11 @@ async function disconnectStateAdapter() {
272
310
  }
273
311
 
274
312
  export {
313
+ MUTATION_LOCK_TTL_MS,
275
314
  acquireActiveLock,
315
+ withLock,
316
+ fenceLock,
317
+ withActiveLock,
276
318
  getDefaultRedisStateAdapterFor,
277
319
  getStateAdapter,
278
320
  disconnectStateAdapter
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recordTaskExecution
3
- } from "./chunk-WSOLZJJS.js";
3
+ } from "./chunk-QSXZ42KX.js";
4
4
  import {
5
5
  pluginTaskId,
6
6
  pluginTaskParamsSchema,
@@ -10,14 +10,14 @@ import {
10
10
  calculateContextCompactionTargetTokens,
11
11
  estimateTextTokens,
12
12
  getConversationContextCompactionTriggerTokens
13
- } from "./chunk-CNTWB2SM.js";
13
+ } from "./chunk-T5GXFFLA.js";
14
14
  import {
15
15
  buildDeterministicTurnId,
16
16
  clearPendingAuth,
17
17
  coerceThreadConversationState,
18
- getAgentTurnSessionRecord,
19
18
  getPersistedThreadState,
20
19
  getPiMessageRole,
20
+ getTurnRecord,
21
21
  hydrateConversationMessages,
22
22
  instructionTextForProjection,
23
23
  isToolResultError,
@@ -28,14 +28,14 @@ import {
28
28
  normalizeToolNameFromResult,
29
29
  persistThreadStateById,
30
30
  stripRuntimeTurnContext
31
- } from "./chunk-BEGGFVFR.js";
31
+ } from "./chunk-GDQEU4I7.js";
32
32
  import {
33
33
  JUNIOR_THREAD_STATE_TTL_MS
34
34
  } from "./chunk-3Y47VMHV.js";
35
35
  import {
36
36
  fallbackShortTitle,
37
37
  generateShortTitle
38
- } from "./chunk-54JMYQYS.js";
38
+ } from "./chunk-W65V465O.js";
39
39
  import {
40
40
  createPluginConversationEvents,
41
41
  createPluginEmbedder,
@@ -43,15 +43,15 @@ import {
43
43
  createPluginModel,
44
44
  createPluginState,
45
45
  getPlugins
46
- } from "./chunk-44RJWAND.js";
46
+ } from "./chunk-SCGVWUZX.js";
47
47
  import {
48
48
  getConversationStore,
49
49
  getDb,
50
50
  sameActorIdentity
51
- } from "./chunk-SBZP2J5Q.js";
51
+ } from "./chunk-37EVZP66.js";
52
52
  import {
53
53
  getStateAdapter
54
- } from "./chunk-UDQMY6RS.js";
54
+ } from "./chunk-GYEKOX7N.js";
55
55
  import {
56
56
  ProviderError,
57
57
  botConfig,
@@ -59,7 +59,7 @@ import {
59
59
  findProviderError,
60
60
  getProviderErrorAttributes,
61
61
  getProviderErrorUserMessage
62
- } from "./chunk-3GU4PWA3.js";
62
+ } from "./chunk-MKRIZ4VG.js";
63
63
  import {
64
64
  credentialSubjectSchema
65
65
  } from "./chunk-RUIXF3YQ.js";
@@ -70,7 +70,7 @@ import {
70
70
  buildTurnFailureResponse,
71
71
  logWarn,
72
72
  setSpanAttributes
73
- } from "./chunk-RIFJUJSI.js";
73
+ } from "./chunk-B63BF443.js";
74
74
 
75
75
  // src/chat/services/conversation-memory.ts
76
76
  var CONTEXT_MIN_LIVE_MESSAGES = 12;
@@ -410,7 +410,7 @@ import {
410
410
 
411
411
  // src/chat/services/turn-session-routing.ts
412
412
  async function resolveTurnSessionRouting(args) {
413
- const conversationStore = args.conversationStore ?? (await import("./db-EFLHTBU6.js")).getConversationStore();
413
+ const conversationStore = args.conversationStore ?? (await import("./db-WWOMXWTT.js")).getConversationStore();
414
414
  const conversation = await conversationStore.get({
415
415
  conversationId: args.conversationId
416
416
  });
@@ -998,10 +998,7 @@ async function withPluginTaskLock(taskId, callback) {
998
998
  }
999
999
  }
1000
1000
  async function loadPluginRun(params) {
1001
- const record = await getAgentTurnSessionRecord(
1002
- params.conversationId,
1003
- params.sessionId
1004
- );
1001
+ const record = await getTurnRecord(params.conversationId, params.sessionId);
1005
1002
  if (!record) {
1006
1003
  throw new Error("Completed plugin task session record is unavailable");
1007
1004
  }
@@ -1033,7 +1030,7 @@ async function loadPluginRun(params) {
1033
1030
  // stripped transcript, so it reflects every committed instruction actor.
1034
1031
  actors: record.actors,
1035
1032
  ...runActor ? { actor: runActor } : {},
1036
- runId: record.sessionId,
1033
+ runId: record.turnId,
1037
1034
  source: routing.source,
1038
1035
  transcript: [...contextEntries, ...runEntries]
1039
1036
  });
@@ -1085,7 +1082,7 @@ async function scheduleSessionCompletedPluginTasks(params, options = {}) {
1085
1082
  if (taskRegistrations.length === 0) {
1086
1083
  return;
1087
1084
  }
1088
- const record = await getAgentTurnSessionRecord(
1085
+ const record = await getTurnRecord(
1089
1086
  coreParams.conversationId,
1090
1087
  coreParams.sessionId
1091
1088
  );
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  JUNIOR_VERSION
3
- } from "./chunk-I44JB7HQ.js";
3
+ } from "./chunk-F7REGDKO.js";
4
4
 
5
5
  // src/deployment.ts
6
6
  var JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
@@ -1,6 +1,8 @@
1
1
  // src/chat/task-execution/queue.ts
2
2
  import { z } from "zod";
3
+ var CONVERSATION_QUEUE_SCHEMA_VERSION = 2;
3
4
  var conversationQueueMessageSchema = z.object({
5
+ schemaVersion: z.literal(CONVERSATION_QUEUE_SCHEMA_VERSION),
4
6
  conversationId: z.string().trim().min(1)
5
7
  }).strict();
6
8
  var ConversationQueueMessageRejectedError = class extends Error {
@@ -18,6 +20,7 @@ function isConversationQueueMessageRejectedError(error) {
18
20
  }
19
21
 
20
22
  export {
23
+ CONVERSATION_QUEUE_SCHEMA_VERSION,
21
24
  conversationQueueMessageSchema,
22
25
  ConversationQueueMessageRejectedError,
23
26
  isConversationQueueMessageRejectedError
@@ -88,7 +88,8 @@ var conversationAuxiliaryCostsSchema = z2.object({
88
88
  var conversationSourceTaskSchema = z2.object({
89
89
  id: z2.string().min(1).optional(),
90
90
  kind: z2.enum(["scheduled", "event"]),
91
- label: z2.string().min(1).optional()
91
+ label: z2.string().min(1).optional(),
92
+ title: z2.string().min(1).optional()
92
93
  }).strict().superRefine((value, context) => {
93
94
  if (Boolean(value.id) !== Boolean(value.label)) {
94
95
  context.addIssue({
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  appendAndEnqueueInboundMessage
3
- } from "./chunk-HD6BHR25.js";
3
+ } from "./chunk-X2WMBTS3.js";
4
4
  import {
5
5
  ConversationTurnLifecycleService
6
6
  } from "./chunk-Q6QZTTLS.js";
@@ -12,36 +12,31 @@ import {
12
12
  agentBindingSchema,
13
13
  agentInvocationSchema,
14
14
  createAgentInvocationSchema
15
- } from "./chunk-DVO5VKYQ.js";
15
+ } from "./chunk-FEKQHPVA.js";
16
16
  import {
17
17
  TurnInputCommitLostError,
18
18
  coerceThreadArtifactsState,
19
- failAgentTurnSessionRecord,
20
- getAgentTurnSessionRecord,
19
+ failTurnRecord,
21
20
  getAssistantReplyText,
22
21
  getConversationTurnBoundaryError,
23
22
  getPersistedSandboxState,
24
23
  getPersistedThreadState,
25
24
  getTerminalAssistantMessages,
25
+ getTurnRecord,
26
26
  isTurnInputCommitLostError,
27
27
  openConversationProjection,
28
- persistCompletedSessionRecord,
29
28
  persistThreadStateById,
30
- persistYieldSessionRecord
31
- } from "./chunk-BEGGFVFR.js";
29
+ saveTurnCheckpoint
30
+ } from "./chunk-GDQEU4I7.js";
32
31
  import {
33
32
  getConversationEventStore,
34
33
  getConversationStore,
35
34
  getSqlExecutor
36
- } from "./chunk-SBZP2J5Q.js";
35
+ } from "./chunk-37EVZP66.js";
37
36
  import {
38
37
  juniorAgentBindings,
39
38
  juniorAgentInvocations
40
- } from "./chunk-HNO2E5WB.js";
41
- import {
42
- botConfig,
43
- modelIdForProfile
44
- } from "./chunk-3GU4PWA3.js";
39
+ } from "./chunk-MCFIXAV5.js";
45
40
 
46
41
  // src/chat/agent-invocations/work.ts
47
42
  import { z } from "zod";
@@ -399,23 +394,34 @@ async function persistTerminalLifecycle(invocation) {
399
394
  });
400
395
  }
401
396
  }
402
- async function projectTerminalSession(invocation) {
403
- const session = await getAgentTurnSessionRecord(
397
+ async function projectTerminalTurn(invocation) {
398
+ let turn = await getTurnRecord(
404
399
  invocation.childConversationId,
405
400
  getAgentInvocationTurnId(invocation.invocationId)
406
401
  );
407
- if (!session) {
402
+ if (!turn) {
408
403
  return void 0;
409
404
  }
410
- if (session.state === "awaiting_resume" || session.state === "running") {
405
+ if (turn.state === "running") {
406
+ turn = await failTurnRecord({
407
+ conversationId: turn.conversationId,
408
+ expectedVersion: turn.version,
409
+ turnId: turn.turnId,
410
+ errorMessage: "Agent invocation lost its worker before it could pause"
411
+ });
412
+ if (!turn) {
413
+ return void 0;
414
+ }
415
+ }
416
+ if (turn.state === "paused") {
411
417
  return void 0;
412
418
  }
413
- const result = getTerminalAssistantMessages(session.piMessages).map(getAssistantReplyText).filter((text) => text !== void 0).join("\n\n");
414
- const failed = session.state !== "completed" || Boolean(session.errorMessage);
419
+ const result = getTerminalAssistantMessages(turn.piMessages).map(getAssistantReplyText).filter((text) => text !== void 0).join("\n\n");
420
+ const failed = turn.state !== "completed" || Boolean(turn.errorMessage);
415
421
  return await completeAgentInvocation({
416
422
  invocationId: invocation.invocationId,
417
423
  ...failed ? {
418
- errorMessage: session.errorMessage ?? "Agent invocation failed",
424
+ errorMessage: turn.errorMessage ?? "Agent invocation failed",
419
425
  status: "failed"
420
426
  } : {
421
427
  result,
@@ -423,40 +429,6 @@ async function projectTerminalSession(invocation) {
423
429
  }
424
430
  });
425
431
  }
426
- async function recoverRunningSession(invocation) {
427
- const session = await getAgentTurnSessionRecord(
428
- invocation.childConversationId,
429
- getAgentInvocationTurnId(invocation.invocationId)
430
- );
431
- if (!session || session.state !== "running") {
432
- return;
433
- }
434
- const projection = await openConversationProjection({
435
- conversationId: invocation.childConversationId
436
- });
437
- const parked = await persistYieldSessionRecord({
438
- conversationId: invocation.childConversationId,
439
- currentSliceId: session.sliceId,
440
- errorMessage: "Recovered running agent invocation after worker loss",
441
- messages: session.piMessages,
442
- modelId: modelIdForProfile(botConfig, projection.modelProfile),
443
- // Execution actor and reasoning live on the parent invocation, not Redis.
444
- actor: invocation.actor,
445
- reasoningLevel: invocation.reasoningLevel,
446
- sessionId: session.sessionId,
447
- surface: session.surface
448
- });
449
- if (!parked) {
450
- await failAgentTurnSessionRecord({
451
- conversationId: invocation.childConversationId,
452
- expectedVersion: session.version,
453
- sessionId: session.sessionId,
454
- errorMessage: `Running agent invocation had no resumable boundary for ${invocation.invocationId}`
455
- });
456
- return;
457
- }
458
- await markAgentInvocationAwaitingResume(invocation.invocationId);
459
- }
460
432
  function blockingInvocationError(error) {
461
433
  const cause = getConversationTurnBoundaryError(error)?.cause ?? error;
462
434
  return cause instanceof AuthorizationFlowDisabledError || cause instanceof PluginCredentialFailureError ? cause : void 0;
@@ -508,8 +480,7 @@ function createAgentInvocationWorker(options) {
508
480
  await acknowledge();
509
481
  return { status: "completed" };
510
482
  }
511
- await recoverRunningSession(invocation);
512
- const projected = await projectTerminalSession(invocation);
483
+ const projected = await projectTerminalTurn(invocation);
513
484
  if (projected && isTerminalAgentInvocation(projected)) {
514
485
  await persistTerminalLifecycle(projected);
515
486
  await acknowledge();
@@ -653,20 +624,19 @@ function createAgentInvocationWorker(options) {
653
624
  sandboxRef: result.sandboxRef ?? sandboxRef
654
625
  });
655
626
  if (result.piMessages?.length) {
656
- await persistCompletedSessionRecord({
627
+ await saveTurnCheckpoint({
628
+ mode: "completed",
657
629
  conversationId: invocation.childConversationId,
658
- currentDurationMs: result.diagnostics.durationMs,
659
- currentUsage: result.diagnostics.usage,
630
+ turnId,
631
+ durationMs: result.diagnostics.durationMs,
632
+ usage: result.diagnostics.usage,
660
633
  destination: invocation.destination,
661
634
  destinationVisibility: invocation.destinationVisibility,
662
635
  ...failed ? {
663
636
  errorMessage: result.diagnostics.errorMessage ?? "Agent invocation failed"
664
637
  } : {},
665
- sessionId: turnId,
666
- allMessages: result.piMessages,
667
- modelId: result.diagnostics.modelId,
638
+ messages: result.piMessages,
668
639
  actor: invocation.actor,
669
- reasoningLevel: result.diagnostics.reasoningLevel,
670
640
  source: invocation.source,
671
641
  surface: "internal"
672
642
  });
@@ -3,10 +3,10 @@ import {
3
3
  } from "./chunk-UTL3MHPC.js";
4
4
  import {
5
5
  parseSlackThreadId
6
- } from "./chunk-PKH6762I.js";
6
+ } from "./chunk-PH4Q3A6W.js";
7
7
  import {
8
8
  normalizeSlackConversationId
9
- } from "./chunk-QE3TICD4.js";
9
+ } from "./chunk-V6SRLKUB.js";
10
10
 
11
11
  // src/handlers/health.ts
12
12
  function readHealthReport() {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createAndEnqueueAgentInvocation
3
- } from "./chunk-PELZ2ZSY.js";
3
+ } from "./chunk-JUA6VU2Z.js";
4
4
  import {
5
5
  actorFromRouting,
6
6
  toolInvocationDestination
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DEFAULT_SQL_STATEMENT_TIMEOUT_MS
3
- } from "./chunk-3GU4PWA3.js";
3
+ } from "./chunk-MKRIZ4VG.js";
4
4
  import {
5
5
  juniorDestinations,
6
6
  timestamptz
@@ -3,7 +3,7 @@ import {
3
3
  toCanonicalInputMessage,
4
4
  toCanonicalOutputMessage,
5
5
  toGenAiMessagesTraceAttributes
6
- } from "./chunk-STFCL3K4.js";
6
+ } from "./chunk-QG7OOKIN.js";
7
7
  import {
8
8
  extractGenAiUsageAttributes,
9
9
  logException,
@@ -11,7 +11,7 @@ import {
11
11
  normalizeGenAiFinishReason,
12
12
  serializeGenAiAttribute,
13
13
  withSpan
14
- } from "./chunk-RIFJUJSI.js";
14
+ } from "./chunk-B63BF443.js";
15
15
 
16
16
  // src/chat/services/provider-error.ts
17
17
  var ProviderError = class extends Error {
@@ -195,31 +195,6 @@ function getProviderErrorAttributes(error) {
195
195
  };
196
196
  }
197
197
 
198
- // src/chat/model-profile.ts
199
- import { z } from "zod";
200
- var STANDARD_MODEL_PROFILE = "standard";
201
- var DEFAULT_HANDOFF_MODEL_PROFILE = "handoff";
202
- var modelProfileSchema = z.string().regex(/^[a-z][a-z0-9_-]*$/);
203
- var ModelProfileNotConfiguredError = class extends Error {
204
- constructor(profile) {
205
- super(`Model profile "${profile}" is not configured`);
206
- this.name = "ModelProfileNotConfiguredError";
207
- }
208
- };
209
- function modelIdForProfile(config, profile) {
210
- return profileConfig(config, profile).modelId;
211
- }
212
- function standardModelId(config) {
213
- return modelIdForProfile(config, STANDARD_MODEL_PROFILE);
214
- }
215
- function profileConfig(config, profile) {
216
- const profileConfig2 = Object.hasOwn(config.profiles, profile) ? config.profiles[profile] : void 0;
217
- if (!profileConfig2) {
218
- throw new ModelProfileNotConfiguredError(profile);
219
- }
220
- return profileConfig2;
221
- }
222
-
223
198
  // src/chat/config.ts
224
199
  import { getModel as getModel2 } from "@earendil-works/pi-ai/compat";
225
200
 
@@ -677,7 +652,7 @@ function normalizeSlackEmojiName(value) {
677
652
  }
678
653
 
679
654
  // src/chat/reasoning-level.ts
680
- import { z as z2 } from "zod";
655
+ import { z } from "zod";
681
656
  var TURN_REASONING_LEVELS = [
682
657
  "none",
683
658
  "low",
@@ -686,7 +661,32 @@ var TURN_REASONING_LEVELS = [
686
661
  "xhigh"
687
662
  ];
688
663
  function parseTurnReasoningLevel(value) {
689
- return z2.enum(TURN_REASONING_LEVELS).parse(value);
664
+ return z.enum(TURN_REASONING_LEVELS).parse(value);
665
+ }
666
+
667
+ // src/chat/model-profile.ts
668
+ import { z as z2 } from "zod";
669
+ var STANDARD_MODEL_PROFILE = "standard";
670
+ var DEFAULT_HANDOFF_MODEL_PROFILE = "handoff";
671
+ var modelProfileSchema = z2.string().regex(/^[a-z][a-z0-9_-]*$/);
672
+ var ModelProfileNotConfiguredError = class extends Error {
673
+ constructor(profile) {
674
+ super(`Model profile "${profile}" is not configured`);
675
+ this.name = "ModelProfileNotConfiguredError";
676
+ }
677
+ };
678
+ function modelIdForProfile(config, profile) {
679
+ return profileConfig(config, profile).modelId;
680
+ }
681
+ function standardModelId(config) {
682
+ return modelIdForProfile(config, STANDARD_MODEL_PROFILE);
683
+ }
684
+ function profileConfig(config, profile) {
685
+ const profileConfig2 = Object.hasOwn(config.profiles, profile) ? config.profiles[profile] : void 0;
686
+ if (!profileConfig2) {
687
+ throw new ModelProfileNotConfiguredError(profile);
688
+ }
689
+ return profileConfig2;
690
690
  }
691
691
 
692
692
  // src/chat/config.ts
@@ -1070,7 +1070,6 @@ export {
1070
1070
  embedTexts,
1071
1071
  normalizeSlackEmojiName,
1072
1072
  TURN_REASONING_LEVELS,
1073
- parseTurnReasoningLevel,
1074
1073
  STANDARD_MODEL_PROFILE,
1075
1074
  DEFAULT_HANDOFF_MODEL_PROFILE,
1076
1075
  modelProfileSchema,