@sentry/junior 0.181.1 → 0.183.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 (107) hide show
  1. package/dist/{agent-hooks-KO56HJ74.js → agent-hooks-SNRBZYAU.js} +11 -11
  2. package/dist/api/code/overview.d.ts +35 -0
  3. package/dist/api/code/routes.d.ts +4 -0
  4. package/dist/api/schema/code.d.ts +75 -0
  5. package/dist/api/schema.d.ts +2 -0
  6. package/dist/api/schema.js +9 -1
  7. package/dist/api.js +347 -149
  8. package/dist/app-adapter.d.ts +85 -0
  9. package/dist/app.d.ts +6 -1
  10. package/dist/app.js +380 -501
  11. package/dist/{catalog-runtime-CJTFLCK3.js → catalog-runtime-3I3JOIIH.js} +4 -4
  12. package/dist/chat/agent-invocations/store.d.ts +4 -2
  13. package/dist/chat/agent-invocations/work.d.ts +1 -3
  14. package/dist/chat/api-turns/adapter-conversations.d.ts +15 -0
  15. package/dist/chat/api-turns/stop.d.ts +12 -0
  16. package/dist/chat/api-turns/work.d.ts +9 -1
  17. package/dist/chat/app/conversation-work.d.ts +1 -1
  18. package/dist/chat/app/factory.d.ts +3 -3
  19. package/dist/chat/app/services.d.ts +3 -3
  20. package/dist/chat/code/publisher.d.ts +3 -0
  21. package/dist/chat/code/store.d.ts +9 -0
  22. package/dist/chat/event-tasks/store.d.ts +10 -0
  23. package/dist/chat/event-tasks/tool-support.d.ts +7 -1
  24. package/dist/chat/event-tasks/types.d.ts +1 -0
  25. package/dist/chat/experimental.d.ts +1 -1
  26. package/dist/chat/ingress/slack-webhook.d.ts +1 -1
  27. package/dist/chat/plugins/agent-hooks.d.ts +5 -0
  28. package/dist/chat/{runtime/slack-runtime.d.ts → providers/slack/runtime.d.ts} +2 -2
  29. package/dist/chat/{runtime/reply-executor.d.ts → providers/slack/turn.d.ts} +10 -9
  30. package/dist/chat/resource-events/catalog.d.ts +11 -1
  31. package/dist/chat/resource-events/store.d.ts +17 -1
  32. package/dist/chat/runtime/turn-execution.d.ts +30 -0
  33. package/dist/chat/services/subscribed-decision.d.ts +2 -1
  34. package/dist/chat/slack/dispatch-turn.d.ts +12 -14
  35. package/dist/chat/task-execution/slack-work.d.ts +1 -1
  36. package/dist/chat/tools/create-event-task.d.ts +3 -0
  37. package/dist/chat/tools/delete-event-task.d.ts +2 -0
  38. package/dist/chat/tools/list-event-tasks.d.ts +2 -0
  39. package/dist/chat/tools/list-resource-event-subscriptions.d.ts +2 -0
  40. package/dist/chat/tools/search-resource-event-types.d.ts +10 -0
  41. package/dist/chat/tools/update-event-task.d.ts +3 -0
  42. package/dist/chat/tools/watch-resource-events.d.ts +3 -0
  43. package/dist/{chunk-DTRCZOHE.js → chunk-24OJZ5OU.js} +6 -6
  44. package/dist/{chunk-Z2UG4FBT.js → chunk-2ADFGSUS.js} +1 -1
  45. package/dist/{chunk-RULGB5NX.js → chunk-2EPYYVJC.js} +9 -9
  46. package/dist/{chunk-VRS6WDK5.js → chunk-2LYHWMR4.js} +1 -1
  47. package/dist/{chunk-XQ56HNH5.js → chunk-35PM4YY5.js} +6 -6
  48. package/dist/{chunk-6TB7JN63.js → chunk-37IQ6DGU.js} +3 -3
  49. package/dist/{chunk-MR36BRPE.js → chunk-3HJ4F4L7.js} +4 -4
  50. package/dist/{chunk-4WYHL4EH.js → chunk-3L7CWDQQ.js} +1 -1
  51. package/dist/{chunk-CJRUBOJI.js → chunk-4WGFWHWP.js} +1 -1
  52. package/dist/{chunk-VHSBLFNT.js → chunk-56XONJPF.js} +1 -1
  53. package/dist/{chunk-ULM7P4EQ.js → chunk-6UXDTPEN.js} +233 -173
  54. package/dist/{chunk-WDNA4LML.js → chunk-AHMWPFIW.js} +188 -11
  55. package/dist/{chunk-YCW6RZGX.js → chunk-AX3UDIMA.js} +3 -3
  56. package/dist/{chunk-HG6HNOTQ.js → chunk-AYW7J6K4.js} +130 -200
  57. package/dist/{chunk-DXK3VTVP.js → chunk-E3OBGRHN.js} +1 -1
  58. package/dist/{chunk-7UF37LNL.js → chunk-EENQGEIP.js} +1 -1
  59. package/dist/{chunk-HRTW7FFX.js → chunk-FJMTMGBC.js} +1 -1
  60. package/dist/{chunk-H6MPFFBE.js → chunk-G2B2XZQW.js} +1 -1
  61. package/dist/{chunk-4GOZBB22.js → chunk-HUK5XIZL.js} +63 -7
  62. package/dist/{chunk-DINF4LMR.js → chunk-IO6KFXYE.js} +160 -97
  63. package/dist/{chunk-KH2SL2HT.js → chunk-KTXOGLNE.js} +2 -2
  64. package/dist/{chunk-S63LNPIV.js → chunk-LMNMMESF.js} +2 -2
  65. package/dist/{chunk-2CZ63QCL.js → chunk-LZBPGX5A.js} +1 -1
  66. package/dist/{chunk-PJ7EGFME.js → chunk-PLZT45VC.js} +5 -5
  67. package/dist/{chunk-ZQQWJMHE.js → chunk-QI5JW5AG.js} +6 -6
  68. package/dist/{chunk-IWRPJ3J5.js → chunk-QZV76CM4.js} +58 -32
  69. package/dist/{chunk-YFJDRORU.js → chunk-R767Y7QV.js} +202 -90
  70. package/dist/{chunk-4OSVTPYQ.js → chunk-SQHFVIMZ.js} +1 -1
  71. package/dist/{chunk-J4ID4ZI6.js → chunk-T5MTGX2E.js} +19 -19
  72. package/dist/{chunk-NRF23QZ4.js → chunk-V64JCZUV.js} +3 -3
  73. package/dist/{chunk-GITIZ6TZ.js → chunk-VOV3SCM3.js} +1 -1
  74. package/dist/{chunk-S5X2VQOD.js → chunk-W46NIB5H.js} +3 -2
  75. package/dist/{chunk-XL3C4NAR.js → chunk-W5JMPEBO.js} +9 -9
  76. package/dist/{chunk-HPFHC7YR.js → chunk-WOKJRLM2.js} +5 -5
  77. package/dist/chunk-WVIA7V3M.js +975 -0
  78. package/dist/{chunk-QA6RE6IB.js → chunk-X52ESOBP.js} +3 -3
  79. package/dist/cli/chat.js +35 -37
  80. package/dist/cli/check.js +5 -5
  81. package/dist/cli/plugins.js +12 -12
  82. package/dist/cli/snapshot-create.js +9 -9
  83. package/dist/cli/upgrade.js +6 -6
  84. package/dist/db/schema/code.d.ts +367 -0
  85. package/dist/db/schema.d.ts +367 -1
  86. package/dist/{db-4PXTD3OH.js → db-K2VMNLHQ.js} +6 -6
  87. package/dist/{experimental-SIJSRDJD.js → experimental-P5FZM4CU.js} +1 -1
  88. package/dist/instrumentation.js +3 -3
  89. package/dist/nitro.js +6 -6
  90. package/dist/{oauth-callback-server-TQWNEVR6.js → oauth-callback-server-DZZMTKSS.js} +26 -26
  91. package/dist/{runner-G5HLQA43.js → runner-IIAKWDXI.js} +18 -18
  92. package/dist/{skills-BNNNRYNT.js → skills-EXIQ7BP5.js} +5 -5
  93. package/dist/spawn-ZR6OOEAN.js +37 -0
  94. package/dist/task-runner-C52HYCVD.js +32 -0
  95. package/dist/{validation-IJSBB6JR.js → validation-XUGIWBJF.js} +5 -5
  96. package/dist/version.js +1 -1
  97. package/dist/{work-5FQI4P2A.js → work-G4RLJ634.js} +18 -18
  98. package/dist/worker-R2JEHK67.js +22 -0
  99. package/migrations/0036_complex_rage.sql +32 -0
  100. package/migrations/meta/0036_snapshot.json +3186 -0
  101. package/migrations/meta/_journal.json +8 -1
  102. package/package.json +6 -5
  103. package/dist/api/acp/route.d.ts +0 -13
  104. package/dist/chunk-CZYNWPWD.js +0 -930
  105. package/dist/spawn-U2RKOFP2.js +0 -37
  106. package/dist/task-runner-CDZJBEXP.js +0 -32
  107. package/dist/worker-KJ362GVB.js +0 -22
@@ -8,14 +8,14 @@ import {
8
8
  getConversationStore,
9
9
  parseDestination,
10
10
  sameDestination
11
- } from "./chunk-YCW6RZGX.js";
11
+ } from "./chunk-AX3UDIMA.js";
12
12
  import {
13
13
  getDefaultRedisStateAdapterFor,
14
14
  getStateAdapter
15
- } from "./chunk-H6MPFFBE.js";
15
+ } from "./chunk-G2B2XZQW.js";
16
16
  import {
17
17
  getChatConfig
18
- } from "./chunk-S63LNPIV.js";
18
+ } from "./chunk-LMNMMESF.js";
19
19
  import {
20
20
  parseStoredSlackActor
21
21
  } from "./chunk-N7TMSOZH.js";
@@ -23,7 +23,7 @@ import {
23
23
  isRecord,
24
24
  toOptionalNumber,
25
25
  toOptionalString
26
- } from "./chunk-2CZ63QCL.js";
26
+ } from "./chunk-LZBPGX5A.js";
27
27
 
28
28
  // src/chat/task-execution/state.ts
29
29
  import { randomUUID } from "crypto";
@@ -671,6 +671,9 @@ async function getConversationWorkState(args) {
671
671
  const conversation = await getConversation(args);
672
672
  return conversation ? conversationWorkState(conversation) : void 0;
673
673
  }
674
+ function hasRunnableConversationWork(conversation) {
675
+ return hasRunnableWork(conversation);
676
+ }
674
677
  async function appendInboundMessageWithAdmission(args) {
675
678
  const nowMs = args.nowMs ?? now();
676
679
  return await withConversationMutation(
@@ -765,6 +768,12 @@ async function appendInboundMessage(args) {
765
768
  }
766
769
  return result;
767
770
  }
771
+ async function appendExclusiveInboundMessage(args) {
772
+ return await appendInboundMessageWithAdmission({
773
+ ...args,
774
+ exclusive: true
775
+ });
776
+ }
768
777
  async function requestConversationWork(args) {
769
778
  const nowMs = args.nowMs ?? now();
770
779
  return await withConversationMutation(args, async (state, lock) => {
@@ -1016,6 +1025,31 @@ async function ackMessages(args) {
1016
1025
  function isHumanFacingMessage(message) {
1017
1026
  return message.source === "web" || message.source === "slack";
1018
1027
  }
1028
+ async function stopConversationWork(args) {
1029
+ const nowMs = args.nowMs ?? now();
1030
+ return await withConversationMutation(args, async (state, lock) => {
1031
+ const current = await readConversation(state, args.conversationId);
1032
+ if (!current || !hasRunnableWork(current)) {
1033
+ return { status: "no_work" };
1034
+ }
1035
+ const runId = current.execution.runId ?? randomUUID();
1036
+ const inboundMessageIds = current.execution.pendingMessages.filter(isHumanFacingMessage).map((message) => message.inboundMessageId);
1037
+ await writeConversation(
1038
+ state,
1039
+ lock,
1040
+ withExecutionUpdate(
1041
+ current,
1042
+ {
1043
+ ...current.execution,
1044
+ runId,
1045
+ stop: { inboundMessageIds, runId }
1046
+ },
1047
+ nowMs
1048
+ )
1049
+ );
1050
+ return { runId, status: "requested" };
1051
+ });
1052
+ }
1019
1053
  async function completeConversationStop(args) {
1020
1054
  const nowMs = args.nowMs ?? now();
1021
1055
  return await withConversationMutation(args, async (state, lock) => {
@@ -1434,7 +1468,7 @@ async function recordConversationRetry2(args) {
1434
1468
  function countPendingConversationMessages(conversation) {
1435
1469
  return conversation.execution.pendingMessages.length;
1436
1470
  }
1437
- function hasRunnableConversationWork(conversation) {
1471
+ function hasRunnableConversationWork2(conversation) {
1438
1472
  return conversation.execution.status !== "idle" || countPendingConversationMessages(conversation) > 0;
1439
1473
  }
1440
1474
  async function ensureConversationWake(args) {
@@ -1443,7 +1477,7 @@ async function ensureConversationWake(args) {
1443
1477
  conversationId: args.conversationId,
1444
1478
  state: args.state
1445
1479
  });
1446
- if (!conversation || !hasRunnableConversationWork(conversation)) {
1480
+ if (!conversation || !hasRunnableConversationWork2(conversation)) {
1447
1481
  return { status: "no_work" };
1448
1482
  }
1449
1483
  if (args.replaceExistingWake !== true && conversation.execution.lease && conversation.execution.lease.expiresAtMs > nowMs) {
@@ -1540,6 +1574,25 @@ async function appendAndEnqueueInboundMessage(args) {
1540
1574
  }
1541
1575
  return result;
1542
1576
  }
1577
+ async function appendAndEnqueueExclusiveInboundMessage(args) {
1578
+ const nowMs = args.nowMs ?? now2();
1579
+ return await enqueueAfterAppend({
1580
+ ...args,
1581
+ appendResult: await appendExclusiveInboundMessage({
1582
+ message: args.message,
1583
+ nowMs,
1584
+ state: args.state
1585
+ }),
1586
+ nowMs
1587
+ });
1588
+ }
1589
+ async function stopConversationWork2(args) {
1590
+ const result = await stopConversationWork(args);
1591
+ if (result.status === "requested") {
1592
+ await recordExecutionMetadata(args);
1593
+ }
1594
+ return result;
1595
+ }
1543
1596
  async function completeConversationStop2(args) {
1544
1597
  const result = await completeConversationStop(args);
1545
1598
  if (result.status === "cleared") {
@@ -1650,13 +1703,16 @@ export {
1650
1703
  CONVERSATION_WORK_STALE_ENQUEUE_MS,
1651
1704
  CONVERSATION_WORK_MAX_RETRIES,
1652
1705
  isFinalAttempt,
1706
+ hasRunnableConversationWork,
1653
1707
  getConversation2 as getConversation,
1654
1708
  getConversationWorkState2 as getConversationWorkState,
1655
1709
  recordConversationRetry2 as recordConversationRetry,
1656
1710
  countPendingConversationMessages,
1657
- hasRunnableConversationWork,
1711
+ hasRunnableConversationWork2,
1658
1712
  ensureConversationWake,
1659
1713
  appendAndEnqueueInboundMessage,
1714
+ appendAndEnqueueExclusiveInboundMessage,
1715
+ stopConversationWork2 as stopConversationWork,
1660
1716
  completeConversationStop2 as completeConversationStop,
1661
1717
  clearConsumedConversationWake2 as clearConsumedConversationWake,
1662
1718
  requestConversationWork2 as requestConversationWork,
@@ -5,7 +5,7 @@ import {
5
5
  getPersistedSandboxState,
6
6
  getPersistedThreadState,
7
7
  persistThreadStateById
8
- } from "./chunk-PJ7EGFME.js";
8
+ } from "./chunk-PLZT45VC.js";
9
9
  import {
10
10
  AgentInvocationBusyError,
11
11
  AgentInvocationLimitError,
@@ -14,36 +14,78 @@ import {
14
14
  agentBindingSchema,
15
15
  agentInvocationSchema,
16
16
  createAgentInvocationSchema
17
- } from "./chunk-XQ56HNH5.js";
17
+ } from "./chunk-35PM4YY5.js";
18
18
  import {
19
19
  appendAndEnqueueInboundMessage
20
- } from "./chunk-4GOZBB22.js";
20
+ } from "./chunk-HUK5XIZL.js";
21
21
  import {
22
22
  TurnInputCommitLostError,
23
23
  getAssistantReplyText,
24
24
  getConversationTurnBoundaryError,
25
25
  isTurnInputCommitLostError
26
- } from "./chunk-VHSBLFNT.js";
26
+ } from "./chunk-56XONJPF.js";
27
27
  import {
28
28
  failTurnRecord,
29
29
  getTerminalAssistantMessages,
30
30
  getTurnRecord,
31
31
  openConversationProjection,
32
32
  saveTurnCheckpoint
33
- } from "./chunk-DTRCZOHE.js";
33
+ } from "./chunk-24OJZ5OU.js";
34
34
  import {
35
35
  getConversationEventStore,
36
36
  getConversationStore,
37
37
  getSqlExecutor
38
- } from "./chunk-YCW6RZGX.js";
38
+ } from "./chunk-AX3UDIMA.js";
39
39
  import {
40
40
  juniorAgentBindings,
41
41
  juniorAgentInvocations
42
- } from "./chunk-ULM7P4EQ.js";
42
+ } from "./chunk-6UXDTPEN.js";
43
43
 
44
44
  // src/chat/agent-invocations/work.ts
45
45
  import { z } from "zod";
46
46
 
47
+ // src/chat/runtime/turn-execution.ts
48
+ var AgentRunError = class extends Error {
49
+ constructor(cause) {
50
+ super(cause instanceof Error ? cause.message : "Agent Run failed", {
51
+ cause
52
+ });
53
+ this.name = "AgentRunError";
54
+ }
55
+ };
56
+ async function executeTurn(agentRunner, run, saveResult) {
57
+ let outcome;
58
+ try {
59
+ outcome = await agentRunner.run(run);
60
+ } catch (error) {
61
+ throw new AgentRunError(error);
62
+ }
63
+ if (outcome.status !== "completed") {
64
+ return outcome;
65
+ }
66
+ const saved = await saveResult(outcome.result);
67
+ const lifecycle = new ConversationTurnLifecycleService(
68
+ getConversationEventStore()
69
+ );
70
+ const common = {
71
+ conversationId: run.conversationId,
72
+ createdAtMs: saved.finishedAtMs ?? Date.now(),
73
+ turnId: run.turnId
74
+ };
75
+ if (saved.outcome === "failed") {
76
+ await lifecycle.fail({
77
+ ...common,
78
+ failureCode: saved.failureCode
79
+ });
80
+ } else {
81
+ await lifecycle.complete({
82
+ ...common,
83
+ outcome: saved.outcome
84
+ });
85
+ }
86
+ return { status: "completed" };
87
+ }
88
+
47
89
  // src/chat/agent-invocations/store.ts
48
90
  import { createHash } from "crypto";
49
91
  import { and, asc, count, eq, inArray } from "drizzle-orm";
@@ -441,7 +483,54 @@ function isInvocationInputCommitLost(error) {
441
483
  const cause = getConversationTurnBoundaryError(error)?.cause ?? error;
442
484
  return isTurnInputCommitLostError(cause);
443
485
  }
444
- function createAgentInvocationWorker(options) {
486
+ async function saveAgentInvocationResult(args) {
487
+ const failed = args.result.diagnostics.outcome !== "success";
488
+ await persistThreadStateById(args.invocation.childConversationId, {
489
+ sandboxRef: args.result.sandboxRef ?? args.sandboxRef
490
+ });
491
+ if (args.result.piMessages?.length) {
492
+ await saveTurnCheckpoint({
493
+ mode: "completed",
494
+ conversationId: args.invocation.childConversationId,
495
+ turnId: args.turnId,
496
+ durationMs: args.result.diagnostics.durationMs,
497
+ usage: args.result.diagnostics.usage,
498
+ destination: args.invocation.destination,
499
+ destinationVisibility: args.invocation.destinationVisibility,
500
+ ...failed ? {
501
+ errorMessage: args.result.diagnostics.errorMessage ?? "Agent invocation failed"
502
+ } : void 0,
503
+ messages: args.result.piMessages,
504
+ actor: args.invocation.actor,
505
+ source: args.invocation.source,
506
+ surface: "internal"
507
+ });
508
+ }
509
+ const terminal = await completeAgentInvocation({
510
+ invocationId: args.invocation.invocationId,
511
+ ...failed ? {
512
+ errorMessage: args.result.diagnostics.errorMessage ?? "Agent invocation failed",
513
+ status: "failed"
514
+ } : {
515
+ result: args.result.text,
516
+ status: "completed"
517
+ }
518
+ });
519
+ if (!terminal || !isTerminalAgentInvocation(terminal)) {
520
+ throw new Error(
521
+ `Agent invocation did not finish for ${args.invocation.invocationId}`
522
+ );
523
+ }
524
+ return terminal.status === "completed" ? {
525
+ finishedAtMs: terminal.terminalAtMs,
526
+ outcome: terminal.result.trim() ? "success" : "no_reply"
527
+ } : {
528
+ finishedAtMs: terminal.terminalAtMs,
529
+ failureCode: "model_execution_failed",
530
+ outcome: "failed"
531
+ };
532
+ }
533
+ function createAgentInvocationWorker(agentRunner) {
445
534
  return async (context, invocationId) => {
446
535
  let invocation = await getAgentInvocation(invocationId);
447
536
  if (!invocation) {
@@ -512,81 +601,94 @@ function createAgentInvocationWorker(options) {
512
601
  if (!context.attempt.isFinalAttempt) {
513
602
  throw error;
514
603
  }
515
- const terminal2 = await completeAgentInvocation({
604
+ const terminal = await completeAgentInvocation({
516
605
  invocationId: invocation.invocationId,
517
606
  errorMessage: error instanceof Error ? error.message : "Agent invocation failed",
518
607
  status: "failed"
519
608
  });
520
- if (terminal2) {
521
- await persistTerminalLifecycle(terminal2);
609
+ if (terminal) {
610
+ await persistTerminalLifecycle(terminal);
522
611
  }
523
612
  await acknowledge();
524
613
  return { status: "completed" };
525
614
  }
526
615
  let outcome;
527
616
  try {
528
- outcome = await options.agentRunner.run({
529
- conversationId: invocation.childConversationId,
530
- turnId,
531
- runId: invocation.invocationId,
532
- instruction: {
533
- text: invocation.input
534
- },
535
- history,
536
- actor: invocation.actor,
537
- credentialContext: invocation.credentialContext,
538
- destination: invocation.destination,
539
- destinationVisibility: invocation.destinationVisibility,
540
- publishExternally: context.publishExternally,
541
- source: invocation.source,
542
- surface: "internal",
543
- // TODO(#881, #883): Child runs may still need a path to force
544
- // interactive auth when a delegated tool requires credentials the
545
- // parent already has authority to request. Today background children
546
- // hard-fail instead of pausing for an OAuth link.
547
- disabledFeatures: ["handoff", "interactive-auth", "subagents"],
548
- reasoning: invocation.reasoningLevel,
549
- state: {
550
- sandboxRef
551
- },
552
- durability: {
553
- onInputCommitted: acknowledge,
554
- shouldYield: context.shouldYield,
555
- onSandboxRefChanged: async (nextSandboxRef) => {
556
- sandboxRef = nextSandboxRef;
557
- await persistThreadStateById(invocation.childConversationId, {
558
- sandboxRef
559
- });
617
+ outcome = await executeTurn(
618
+ agentRunner,
619
+ {
620
+ conversationId: invocation.childConversationId,
621
+ turnId,
622
+ runId: invocation.invocationId,
623
+ instruction: {
624
+ text: invocation.input
625
+ },
626
+ history,
627
+ actor: invocation.actor,
628
+ credentialContext: invocation.credentialContext,
629
+ destination: invocation.destination,
630
+ destinationVisibility: invocation.destinationVisibility,
631
+ publishExternally: context.publishExternally,
632
+ source: invocation.source,
633
+ surface: "internal",
634
+ // TODO(#881, #883): Child runs may still need a path to force
635
+ // interactive auth when a delegated tool requires credentials the
636
+ // parent already has authority to request. Today background children
637
+ // hard-fail instead of pausing for an OAuth link.
638
+ disabledFeatures: ["handoff", "interactive-auth", "subagents"],
639
+ reasoning: invocation.reasoningLevel,
640
+ state: {
641
+ sandboxRef
642
+ },
643
+ durability: {
644
+ onInputCommitted: acknowledge,
645
+ shouldYield: context.shouldYield,
646
+ onSandboxRefChanged: async (nextSandboxRef) => {
647
+ sandboxRef = nextSandboxRef;
648
+ await persistThreadStateById(invocation.childConversationId, {
649
+ sandboxRef
650
+ });
651
+ }
560
652
  }
561
- }
562
- });
653
+ },
654
+ async (result) => await saveAgentInvocationResult({
655
+ invocation,
656
+ result,
657
+ sandboxRef,
658
+ turnId
659
+ })
660
+ );
563
661
  } catch (error) {
564
- if (isInvocationInputCommitLost(error)) {
662
+ if (!(error instanceof AgentRunError)) {
663
+ throw error;
664
+ }
665
+ const runError = error.cause;
666
+ if (isInvocationInputCommitLost(runError)) {
565
667
  return { status: "lost_lease" };
566
668
  }
567
- const blocking = blockingInvocationError(error);
669
+ const blocking = blockingInvocationError(runError);
568
670
  if (blocking) {
569
- const terminal3 = await completeAgentInvocation({
671
+ const terminal2 = await completeAgentInvocation({
570
672
  invocationId: invocation.invocationId,
571
673
  errorMessage: blocking.message,
572
674
  status: "blocked"
573
675
  });
574
- if (terminal3) {
575
- await persistTerminalLifecycle(terminal3);
676
+ if (terminal2) {
677
+ await persistTerminalLifecycle(terminal2);
576
678
  }
577
679
  await acknowledge();
578
680
  return { status: "completed" };
579
681
  }
580
682
  if (!context.attempt.isFinalAttempt) {
581
- throw error;
683
+ throw runError;
582
684
  }
583
- const terminal2 = await completeAgentInvocation({
685
+ const terminal = await completeAgentInvocation({
584
686
  invocationId: invocation.invocationId,
585
- errorMessage: error instanceof Error ? error.message : "Agent invocation failed",
687
+ errorMessage: runError instanceof Error ? runError.message : "Agent invocation failed",
586
688
  status: "failed"
587
689
  });
588
- if (terminal2) {
589
- await persistTerminalLifecycle(terminal2);
690
+ if (terminal) {
691
+ await persistTerminalLifecycle(terminal);
590
692
  }
591
693
  await acknowledge();
592
694
  return { status: "completed" };
@@ -596,56 +698,17 @@ function createAgentInvocationWorker(options) {
596
698
  return { status: "yielded" };
597
699
  }
598
700
  if (outcome.status === "awaiting_auth") {
599
- const terminal2 = await completeAgentInvocation({
701
+ const terminal = await completeAgentInvocation({
600
702
  invocationId: invocation.invocationId,
601
703
  errorMessage: `Agent invocation requires ${outcome.providerDisplayName} authorization`,
602
704
  status: "blocked"
603
705
  });
604
- if (terminal2) {
605
- await persistTerminalLifecycle(terminal2);
706
+ if (terminal) {
707
+ await persistTerminalLifecycle(terminal);
606
708
  }
607
709
  await acknowledge();
608
710
  return { status: "completed" };
609
711
  }
610
- const result = outcome.result;
611
- const failed = result.diagnostics.outcome !== "success";
612
- await persistThreadStateById(invocation.childConversationId, {
613
- sandboxRef: result.sandboxRef ?? sandboxRef
614
- });
615
- if (result.piMessages?.length) {
616
- await saveTurnCheckpoint({
617
- mode: "completed",
618
- conversationId: invocation.childConversationId,
619
- turnId,
620
- durationMs: result.diagnostics.durationMs,
621
- usage: result.diagnostics.usage,
622
- destination: invocation.destination,
623
- destinationVisibility: invocation.destinationVisibility,
624
- ...failed ? {
625
- errorMessage: result.diagnostics.errorMessage ?? "Agent invocation failed"
626
- } : void 0,
627
- messages: result.piMessages,
628
- actor: invocation.actor,
629
- source: invocation.source,
630
- surface: "internal"
631
- });
632
- }
633
- const terminal = await completeAgentInvocation({
634
- invocationId: invocation.invocationId,
635
- ...failed ? {
636
- errorMessage: result.diagnostics.errorMessage ?? "Agent invocation failed",
637
- status: "failed"
638
- } : {
639
- result: result.text,
640
- status: "completed"
641
- }
642
- });
643
- if (!terminal) {
644
- throw new Error(
645
- `Agent invocation disappeared during completion for ${invocation.invocationId}`
646
- );
647
- }
648
- await persistTerminalLifecycle(terminal);
649
712
  await acknowledge();
650
713
  return { status: "completed" };
651
714
  };
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  pluginCatalogRuntime
3
- } from "./chunk-DXK3VTVP.js";
3
+ } from "./chunk-E3OBGRHN.js";
4
4
  import {
5
5
  skillRoots
6
6
  } from "./chunk-TXKUKMVO.js";
7
7
  import {
8
8
  logWarn
9
- } from "./chunk-2CZ63QCL.js";
9
+ } from "./chunk-LZBPGX5A.js";
10
10
 
11
11
  // src/chat/skills.ts
12
12
  import fs from "fs/promises";
@@ -3,7 +3,7 @@ import {
3
3
  toCanonicalInputMessage,
4
4
  toCanonicalOutputMessage,
5
5
  toGenAiMessagesTraceAttributes
6
- } from "./chunk-Z2UG4FBT.js";
6
+ } from "./chunk-2ADFGSUS.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-2CZ63QCL.js";
14
+ } from "./chunk-LZBPGX5A.js";
15
15
 
16
16
  // src/chat/services/provider-error.ts
17
17
  var ProviderError = class extends Error {
@@ -12,7 +12,7 @@ import {
12
12
  } from "./chunk-PEQXYSSE.js";
13
13
  import {
14
14
  JUNIOR_VERSION
15
- } from "./chunk-S5X2VQOD.js";
15
+ } from "./chunk-W46NIB5H.js";
16
16
 
17
17
  // src/deployment.ts
18
18
  var JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  persistConversationMessages
3
- } from "./chunk-DTRCZOHE.js";
3
+ } from "./chunk-24OJZ5OU.js";
4
4
  import {
5
5
  JUNIOR_THREAD_STATE_TTL_MS
6
6
  } from "./chunk-3Y47VMHV.js";
7
7
  import {
8
8
  getDb
9
- } from "./chunk-YCW6RZGX.js";
9
+ } from "./chunk-AX3UDIMA.js";
10
10
  import {
11
11
  juniorLocationConfigurations
12
- } from "./chunk-ULM7P4EQ.js";
12
+ } from "./chunk-6UXDTPEN.js";
13
13
  import {
14
14
  getStateAdapter
15
- } from "./chunk-H6MPFFBE.js";
15
+ } from "./chunk-G2B2XZQW.js";
16
16
  import {
17
17
  juniorDestinations
18
18
  } from "./chunk-VFUK3X5B.js";
@@ -20,7 +20,7 @@ import {
20
20
  isRecord,
21
21
  toOptionalNumber,
22
22
  toOptionalString
23
- } from "./chunk-2CZ63QCL.js";
23
+ } from "./chunk-LZBPGX5A.js";
24
24
 
25
25
  // src/chat/state/conversation.ts
26
26
  function defaultConversationState() {
@@ -5,19 +5,19 @@ import {
5
5
  isDmChannel,
6
6
  normalizeSlackConversationId,
7
7
  withSlackRetries
8
- } from "./chunk-WDNA4LML.js";
8
+ } from "./chunk-AHMWPFIW.js";
9
9
  import {
10
10
  parseDestination
11
- } from "./chunk-YCW6RZGX.js";
11
+ } from "./chunk-AX3UDIMA.js";
12
12
  import {
13
13
  getStateAdapter
14
- } from "./chunk-H6MPFFBE.js";
14
+ } from "./chunk-G2B2XZQW.js";
15
15
  import {
16
16
  normalizeSlackEmojiName
17
- } from "./chunk-S63LNPIV.js";
17
+ } from "./chunk-LMNMMESF.js";
18
18
  import {
19
19
  pluginCatalogRuntime
20
- } from "./chunk-DXK3VTVP.js";
20
+ } from "./chunk-E3OBGRHN.js";
21
21
  import {
22
22
  parseSlackMessageTs,
23
23
  parseSlackUserId
@@ -26,7 +26,7 @@ import {
26
26
  isRecord,
27
27
  logInfo,
28
28
  logWarn
29
- } from "./chunk-2CZ63QCL.js";
29
+ } from "./chunk-LZBPGX5A.js";
30
30
 
31
31
  // src/chat/slack/outbound.ts
32
32
  var MAX_SLACK_MESSAGE_TEXT_CHARS = 4e4;