@sentry/junior 0.183.0 → 0.185.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 (122) hide show
  1. package/dist/{agent-hooks-SNRBZYAU.js → agent-hooks-NGZQLL5O.js} +13 -11
  2. package/dist/api/acp/auth.d.ts +46 -0
  3. package/dist/api/acp/authorization-page.d.ts +11 -0
  4. package/dist/api/acp/conversations.d.ts +70 -0
  5. package/dist/api/acp/errors.d.ts +6 -0
  6. package/dist/api/acp/route.d.ts +16 -0
  7. package/dist/api/acp/schema.d.ts +115 -0
  8. package/dist/api/acp/sleep.d.ts +2 -0
  9. package/dist/api/acp/state.d.ts +22 -0
  10. package/dist/api/acp/transport.d.ts +113 -0
  11. package/dist/api/code/overview.d.ts +39 -0
  12. package/dist/api/locations/detail.d.ts +1 -1
  13. package/dist/api/people/code.d.ts +22 -0
  14. package/dist/api/schema/code.d.ts +46 -0
  15. package/dist/api/schema/conversation.d.ts +100 -20
  16. package/dist/api/schema/location.d.ts +1 -1
  17. package/dist/api/schema/person.d.ts +1 -1
  18. package/dist/api/schema.d.ts +4 -4
  19. package/dist/api/schema.js +12 -1
  20. package/dist/api.js +358 -76
  21. package/dist/app.d.ts +0 -4
  22. package/dist/app.js +2450 -493
  23. package/dist/{catalog-runtime-3I3JOIIH.js → catalog-runtime-AAEAO2RL.js} +4 -4
  24. package/dist/chat/api-turns/accepted-reply.d.ts +11 -0
  25. package/dist/chat/api-turns/cancellation.d.ts +3 -5
  26. package/dist/chat/api-turns/work.d.ts +4 -9
  27. package/dist/chat/app/conversation-work.d.ts +1 -1
  28. package/dist/chat/app/factory.d.ts +4 -0
  29. package/dist/chat/app/services.d.ts +4 -3
  30. package/dist/chat/conversations/history.d.ts +83 -9
  31. package/dist/chat/conversations/turn-lifecycle.d.ts +4 -3
  32. package/dist/chat/providers/slack/input.d.ts +32 -0
  33. package/dist/chat/{runtime → providers/slack}/processing-reaction.d.ts +6 -8
  34. package/dist/chat/{runtime/slack-resume.d.ts → providers/slack/resume.d.ts} +16 -19
  35. package/dist/chat/providers/slack/runtime.d.ts +1 -10
  36. package/dist/chat/providers/slack/turn.d.ts +11 -24
  37. package/dist/chat/resource-events/store.d.ts +1 -1
  38. package/dist/chat/resource-events/tool-support.d.ts +0 -5
  39. package/dist/chat/runtime/turn-execution.d.ts +7 -2
  40. package/dist/chat/sandbox/egress/credentials.d.ts +3 -3
  41. package/dist/chat/sandbox/egress/session.d.ts +5 -6
  42. package/dist/chat/scheduled-tasks/tool-support.d.ts +5 -5
  43. package/dist/chat/scheduled-tasks/tools/create.d.ts +2 -2
  44. package/dist/chat/scheduled-tasks/tools/delete.d.ts +2 -2
  45. package/dist/chat/scheduled-tasks/tools/list.d.ts +2 -2
  46. package/dist/chat/scheduled-tasks/tools/run-now.d.ts +2 -2
  47. package/dist/chat/scheduled-tasks/tools/update.d.ts +2 -2
  48. package/dist/chat/scheduled-tasks/types.d.ts +1 -1
  49. package/dist/chat/services/provider-retry.d.ts +2 -0
  50. package/dist/chat/services/turn-failure-response.d.ts +4 -0
  51. package/dist/chat/task-execution/paused-turn.d.ts +0 -2
  52. package/dist/chat/task-execution/state.d.ts +2 -2
  53. package/dist/chat/task-execution/store.d.ts +1 -1
  54. package/dist/chat/task-execution/turn-wake.d.ts +12 -0
  55. package/dist/chat/tool-support/action-review.d.ts +1 -1
  56. package/dist/chat/tools/resource-events.d.ts +1 -1
  57. package/dist/chat/tools/search-conversation-events.d.ts +1 -1
  58. package/dist/chat/tools/types.d.ts +1 -1
  59. package/dist/chat/tools/watch-resource-events.d.ts +2 -2
  60. package/dist/{chunk-2EPYYVJC.js → chunk-4HA36IWS.js} +9 -94
  61. package/dist/{chunk-WVIA7V3M.js → chunk-4K25ODAO.js} +27 -1
  62. package/dist/{chunk-V64JCZUV.js → chunk-4S47VHJR.js} +3 -3
  63. package/dist/{chunk-QZV76CM4.js → chunk-6DOAUXLD.js} +231 -198
  64. package/dist/{chunk-M3QYTBQ6.js → chunk-6Q7YZLCL.js} +2 -1
  65. package/dist/{chunk-W46NIB5H.js → chunk-7GAP2XG4.js} +2 -3
  66. package/dist/{chunk-EENQGEIP.js → chunk-7MHNIGHP.js} +1 -1
  67. package/dist/{chunk-AX3UDIMA.js → chunk-ABAX75GG.js} +10 -384
  68. package/dist/{chunk-KTXOGLNE.js → chunk-ATUWN6Z3.js} +2 -2
  69. package/dist/{chunk-3HJ4F4L7.js → chunk-C6TS47CQ.js} +4 -4
  70. package/dist/chunk-D4YV5TDV.js +45 -0
  71. package/dist/{chunk-HUK5XIZL.js → chunk-D63IUQQE.js} +4 -4
  72. package/dist/{chunk-WOKJRLM2.js → chunk-DAPC2HTM.js} +24 -6
  73. package/dist/{chunk-2ADFGSUS.js → chunk-EIJCPJOY.js} +1 -1
  74. package/dist/{chunk-X52ESOBP.js → chunk-EJYP3NQ4.js} +4 -4
  75. package/dist/{chunk-35PM4YY5.js → chunk-EWEH2PJW.js} +6 -6
  76. package/dist/{chunk-W5JMPEBO.js → chunk-FFHXG2FX.js} +13 -11
  77. package/dist/{chunk-FJMTMGBC.js → chunk-FTVMXDNN.js} +1 -1
  78. package/dist/chunk-GFBR4S3Q.js +406 -0
  79. package/dist/{chunk-E3OBGRHN.js → chunk-GJTIZQGJ.js} +1 -1
  80. package/dist/{chunk-IO6KFXYE.js → chunk-HJPC32TQ.js} +12 -50
  81. package/dist/{chunk-RF6J3DIO.js → chunk-INQHUE72.js} +84 -1
  82. package/dist/{chunk-LMNMMESF.js → chunk-LRI5IRGY.js} +19 -44
  83. package/dist/{chunk-6UXDTPEN.js → chunk-LVK4WJKM.js} +1 -1
  84. package/dist/{chunk-AYW7J6K4.js → chunk-MWOH6CIK.js} +178 -148
  85. package/dist/{chunk-LZBPGX5A.js → chunk-OMQ2J6F6.js} +1 -1
  86. package/dist/{chunk-G2B2XZQW.js → chunk-PNYJOEVV.js} +1 -1
  87. package/dist/{chunk-37IQ6DGU.js → chunk-QCT4226Q.js} +3 -3
  88. package/dist/{chunk-R767Y7QV.js → chunk-QZKHHG3B.js} +34 -8
  89. package/dist/{chunk-VOV3SCM3.js → chunk-TVVAMOLS.js} +2 -2
  90. package/dist/{chunk-56XONJPF.js → chunk-U4CTAVWN.js} +1 -1
  91. package/dist/{chunk-4WGFWHWP.js → chunk-UUULGCKK.js} +1 -1
  92. package/dist/{chunk-AHMWPFIW.js → chunk-VH4IU3UC.js} +928 -984
  93. package/dist/chunk-W7GCLNIV.js +58 -0
  94. package/dist/{chunk-24OJZ5OU.js → chunk-WLKWN4CD.js} +22 -12
  95. package/dist/{chunk-T5MTGX2E.js → chunk-X2SS6BF7.js} +201 -210
  96. package/dist/{chunk-SQHFVIMZ.js → chunk-X7NCJQAA.js} +1 -1
  97. package/dist/{chunk-PLZT45VC.js → chunk-Y5G23T2D.js} +5 -5
  98. package/dist/{chunk-3L7CWDQQ.js → chunk-ZIF2S464.js} +1 -1
  99. package/dist/{chunk-QI5JW5AG.js → chunk-ZKKGFUWM.js} +6 -6
  100. package/dist/cli/chat.js +35 -33
  101. package/dist/cli/check.js +5 -5
  102. package/dist/cli/plugins.js +14 -12
  103. package/dist/cli/snapshot-create.js +10 -9
  104. package/dist/cli/upgrade.js +7 -6
  105. package/dist/{db-K2VMNLHQ.js → db-TRJ77FAU.js} +8 -6
  106. package/dist/instrumentation.js +3 -3
  107. package/dist/nitro.js +7 -6
  108. package/dist/{oauth-callback-server-DZZMTKSS.js → oauth-callback-server-XD5SV3MS.js} +30 -27
  109. package/dist/{runner-IIAKWDXI.js → runner-KFX7NG6D.js} +24 -19
  110. package/dist/{skills-EXIQ7BP5.js → skills-J2AH26CW.js} +5 -5
  111. package/dist/spawn-VU3CSRI6.js +41 -0
  112. package/dist/task-runner-5JG3VIIY.js +34 -0
  113. package/dist/{validation-XUGIWBJF.js → validation-O5J4VOPF.js} +5 -5
  114. package/dist/version.js +1 -1
  115. package/dist/{work-G4RLJ634.js → work-ECPQTG3U.js} +24 -19
  116. package/dist/worker-RS3DXUDO.js +24 -0
  117. package/package.json +5 -6
  118. package/dist/app-adapter.d.ts +0 -85
  119. package/dist/chat/api-turns/adapter-conversations.d.ts +0 -15
  120. package/dist/spawn-ZR6OOEAN.js +0 -37
  121. package/dist/task-runner-C52HYCVD.js +0 -32
  122. package/dist/worker-R2JEHK67.js +0 -22
@@ -1,36 +1,40 @@
1
1
  import {
2
2
  createWebAuthorization,
3
3
  deleteWebAuthorization
4
- } from "./chunk-4WGFWHWP.js";
4
+ } from "./chunk-UUULGCKK.js";
5
+ import {
6
+ AgentRunError,
7
+ executeTurn
8
+ } from "./chunk-W7GCLNIV.js";
5
9
  import {
6
10
  buildDeliveredTurnStatePatch,
7
11
  completeAuthPauseTurn,
8
12
  finalizeFailedTurnReplyWithEvent,
9
13
  getTurnUserMessage
10
- } from "./chunk-WOKJRLM2.js";
14
+ } from "./chunk-DAPC2HTM.js";
11
15
  import {
12
16
  processPluginTask,
13
17
  scheduleSessionCompletedPluginTasks
14
- } from "./chunk-W5JMPEBO.js";
18
+ } from "./chunk-FFHXG2FX.js";
15
19
  import {
16
20
  ConversationTurnLifecycleService
17
- } from "./chunk-M3QYTBQ6.js";
21
+ } from "./chunk-6Q7YZLCL.js";
18
22
  import {
19
23
  coerceThreadConversationState,
20
24
  getPersistedSandboxState,
21
25
  getPersistedThreadState,
22
26
  persistThreadStateById
23
- } from "./chunk-PLZT45VC.js";
27
+ } from "./chunk-Y5G23T2D.js";
24
28
  import {
25
29
  healthReportSchema
26
30
  } from "./chunk-UTL3MHPC.js";
27
31
  import {
28
32
  parseSlackThreadId
29
- } from "./chunk-SQHFVIMZ.js";
33
+ } from "./chunk-X7NCJQAA.js";
30
34
  import {
31
35
  appendAndEnqueueExclusiveInboundMessage,
32
36
  appendAndEnqueueInboundMessage
33
- } from "./chunk-HUK5XIZL.js";
37
+ } from "./chunk-D63IUQQE.js";
34
38
  import {
35
39
  TurnInputCommitLostError,
36
40
  buildDeterministicTurnId,
@@ -41,10 +45,11 @@ import {
41
45
  markTurnClosed,
42
46
  markTurnFailed,
43
47
  startActiveTurn
44
- } from "./chunk-56XONJPF.js";
48
+ } from "./chunk-U4CTAVWN.js";
45
49
  import {
46
50
  abandonTurnRecord,
47
51
  buildConversationContext,
52
+ commitAcceptedReply,
48
53
  getTurnRecord,
49
54
  hydrateConversationMessages,
50
55
  listTurnSummaries,
@@ -56,27 +61,27 @@ import {
56
61
  recordDeliveredAssistantMessage,
57
62
  saveTurnCheckpoint,
58
63
  upsertConversationMessage
59
- } from "./chunk-24OJZ5OU.js";
64
+ } from "./chunk-WLKWN4CD.js";
60
65
  import {
61
66
  normalizeSlackConversationId
62
- } from "./chunk-AHMWPFIW.js";
67
+ } from "./chunk-VH4IU3UC.js";
63
68
  import {
64
69
  getConversationEventStore,
65
70
  getConversationStore,
66
71
  getDb
67
- } from "./chunk-AX3UDIMA.js";
72
+ } from "./chunk-ABAX75GG.js";
68
73
  import {
69
74
  juniorConversationParticipants,
70
75
  juniorConversations,
71
76
  juniorIdentities,
72
77
  juniorUsers
73
- } from "./chunk-6UXDTPEN.js";
78
+ } from "./chunk-LVK4WJKM.js";
74
79
  import {
75
80
  juniorDestinations
76
81
  } from "./chunk-VFUK3X5B.js";
77
82
  import {
78
83
  canExposeConversationPayload
79
- } from "./chunk-2ADFGSUS.js";
84
+ } from "./chunk-EIJCPJOY.js";
80
85
  import {
81
86
  credentialContextForActor
82
87
  } from "./chunk-CEMMLV5L.js";
@@ -84,7 +89,7 @@ import {
84
89
  logException,
85
90
  setTags,
86
91
  withLogContext
87
- } from "./chunk-LZBPGX5A.js";
92
+ } from "./chunk-OMQ2J6F6.js";
88
93
 
89
94
  // src/handlers/health.ts
90
95
  function readHealthReport() {
@@ -196,6 +201,35 @@ import {
196
201
  localDestinationSchema
197
202
  } from "@sentry/junior-plugin-api";
198
203
 
204
+ // src/chat/api-turns/accepted-reply.ts
205
+ async function commitWebAcceptedReply(args) {
206
+ const conversationMessageId = recordDeliveredAssistantMessage({
207
+ conversation: args.conversation,
208
+ sessionId: args.sessionId,
209
+ source: "web",
210
+ text: args.text,
211
+ userMessageId: args.userMessageId
212
+ });
213
+ try {
214
+ await persistWithRetry(
215
+ () => commitAcceptedReply({
216
+ ...args.agentMessage ? { agentMessage: args.agentMessage } : void 0,
217
+ conversation: args.conversation,
218
+ conversationMessageId,
219
+ conversationId: args.conversationId
220
+ })
221
+ );
222
+ } catch (error) {
223
+ logException(
224
+ new Error("Accepted assistant message persistence failed"),
225
+ "api.assistant.message_post_delivery_persist.failed",
226
+ {
227
+ "error.type": error instanceof Error ? error.name : typeof error
228
+ }
229
+ );
230
+ }
231
+ }
232
+
199
233
  // src/chat/api-turns/cancellation.ts
200
234
  function createApiTurnCancellation() {
201
235
  const active = /* @__PURE__ */ new Map();
@@ -217,7 +251,7 @@ function createApiTurnCancellation() {
217
251
  if (!entry) {
218
252
  return false;
219
253
  }
220
- entry.controller.abort(new Error("API Turn cancelled"));
254
+ entry.controller.abort(new DOMException("Turn cancelled", "AbortError"));
221
255
  return true;
222
256
  },
223
257
  disconnect(conversationId, signal) {
@@ -257,7 +291,7 @@ async function completeCancelledApiTurn(args) {
257
291
  await abandonTurnRecord({
258
292
  conversationId: args.conversationId,
259
293
  turnId: args.turnId,
260
- errorMessage: "API Turn cancelled"
294
+ errorMessage: "Turn cancelled"
261
295
  });
262
296
  clearPendingAuth(args.conversation, args.turnId);
263
297
  markConversationMessage(args.conversation, args.userMessageId, {
@@ -279,7 +313,9 @@ async function completeCancelledApiTurn(args) {
279
313
  conversation: args.conversation,
280
314
  sandboxRef: args.sandboxRef
281
315
  });
282
- await args.lifecycle.complete({
316
+ await new ConversationTurnLifecycleService(
317
+ getConversationEventStore()
318
+ ).complete({
283
319
  conversationId: args.conversationId,
284
320
  createdAtMs: Date.now(),
285
321
  outcome: "cancelled",
@@ -504,20 +540,22 @@ function hasLostTurnInputCommit(error) {
504
540
  const cause = getConversationTurnBoundaryError(error)?.cause ?? error;
505
541
  return isTurnInputCommitLostError(error) || isTurnInputCommitLostError(cause);
506
542
  }
507
- function createApiTurnWorker(options) {
543
+ function createApiTurnWorker(agentRunner, cancellation) {
508
544
  return async (context) => {
509
545
  const resolved = await resolveApiTurnWork(context);
510
546
  if (!resolved) {
511
547
  throw new Error(
512
- `API turn worker received non-API work for ${context.conversationId}`
548
+ `Conversation API worker received other work for ${context.conversationId}`
513
549
  );
514
550
  }
515
551
  if (context.publishExternally) {
516
552
  throw new Error(
517
- `API turn work must not publish externally for ${context.conversationId}`
553
+ `Conversation API work cannot publish to a provider for ${context.conversationId}`
518
554
  );
519
555
  }
520
- const lifecycle = options.turnLifecycle ?? new ConversationTurnLifecycleService(getConversationEventStore());
556
+ const lifecycle = new ConversationTurnLifecycleService(
557
+ getConversationEventStore()
558
+ );
521
559
  const isResume = resolved.kind === "resume";
522
560
  let actor;
523
561
  let text;
@@ -543,7 +581,7 @@ function createApiTurnWorker(options) {
543
581
  );
544
582
  if (!resumedActor) {
545
583
  throw new Error(
546
- `API turn resume missing actor for ${context.conversationId}`
584
+ `Conversation API resume missing actor for ${context.conversationId}`
547
585
  );
548
586
  }
549
587
  actor = resumedActor;
@@ -577,7 +615,7 @@ function createApiTurnWorker(options) {
577
615
  await context.attempt.ack();
578
616
  } catch {
579
617
  throw new TurnInputCommitLostError(
580
- `Conversation work lease lost before API turn inbox ack for ${context.conversationId}`
618
+ `Conversation work lease lost before Conversation API message acknowledgement for ${context.conversationId}`
581
619
  );
582
620
  }
583
621
  acknowledged = true;
@@ -590,12 +628,12 @@ function createApiTurnWorker(options) {
590
628
  });
591
629
  let sandboxRef = getPersistedSandboxState(persisted);
592
630
  const initialSandboxRef = sandboxRef;
593
- const appSignal = options.cancellation?.signal(context.conversationId);
631
+ const appSignal = cancellation?.signal(context.conversationId);
594
632
  const stopSignal = context.stopSignal?.();
595
633
  const cancellationSignal = appSignal && stopSignal ? AbortSignal.any([appSignal, stopSignal]) : appSignal ?? stopSignal;
596
634
  const finishCancellation = () => {
597
635
  if (appSignal) {
598
- options.cancellation?.finish(context.conversationId, appSignal);
636
+ cancellation?.finish(context.conversationId, appSignal);
599
637
  }
600
638
  };
601
639
  const completeCancelledTurn = async () => {
@@ -603,10 +641,9 @@ function createApiTurnWorker(options) {
603
641
  await completeCancelledApiTurn({
604
642
  acknowledge,
605
643
  actorId: actor.userId,
606
- cancellation: options.cancellation,
644
+ cancellation,
607
645
  conversation,
608
646
  conversationId: context.conversationId,
609
- lifecycle,
610
647
  sandboxRef,
611
648
  signal: appSignal,
612
649
  turnId,
@@ -624,7 +661,7 @@ function createApiTurnWorker(options) {
624
661
  const userMessage = getTurnUserMessage(conversation, turnId);
625
662
  if (!userMessage) {
626
663
  throw new Error(
627
- `Unable to locate the persisted user message for API turn "${turnId}"`
664
+ `Unable to locate the persisted user message for Turn "${turnId}"`
628
665
  );
629
666
  }
630
667
  userMessageId = userMessage.id;
@@ -676,37 +713,23 @@ function createApiTurnWorker(options) {
676
713
  let failureCode = "persistence_failed";
677
714
  let modelFailureEventId;
678
715
  let modelFailureCaptureAttempted = false;
679
- let reply;
716
+ let completedSuccessfully = false;
680
717
  const deliverAssistantMessage = async (value) => {
718
+ const agentMessage = typeof value === "string" ? void 0 : value;
681
719
  const replyText = typeof value === "string" ? value : getAssistantReplyText(value);
682
720
  if (!replyText?.trim()) {
683
721
  return;
684
722
  }
685
723
  failureCode = "delivery_failed";
686
724
  assistantMessageDelivered = true;
687
- recordDeliveredAssistantMessage({
725
+ await commitWebAcceptedReply({
726
+ ...agentMessage ? { agentMessage } : void 0,
688
727
  conversation,
728
+ conversationId: context.conversationId,
689
729
  sessionId: turnId,
690
- source: "web",
691
730
  text: replyText,
692
731
  userMessageId
693
732
  });
694
- try {
695
- await persistWithRetry(
696
- () => persistConversationMessages({
697
- conversation,
698
- conversationId: context.conversationId
699
- })
700
- );
701
- } catch (error) {
702
- logException(
703
- new Error("Accepted assistant message persistence failed"),
704
- "api.assistant.message_post_delivery_persist.failed",
705
- {
706
- "error.type": error instanceof Error ? error.name : typeof error
707
- }
708
- );
709
- }
710
733
  failureCode = "agent_run_failed";
711
734
  };
712
735
  try {
@@ -751,53 +774,112 @@ function createApiTurnWorker(options) {
751
774
  failureCode = "agent_run_failed";
752
775
  currentRunId = `api-run:${stableHex(turnId, String(startedAtMs))}`;
753
776
  setTags({ runId: currentRunId });
754
- const outcome = await options.agentRunner.run({
755
- conversationId: context.conversationId,
756
- turnId,
757
- runId: currentRunId,
758
- instruction: {
759
- text,
760
- context: buildConversationContext(conversation, {
761
- excludeMessageId: userMessageId
762
- })
763
- },
764
- history: piMessages,
765
- actor,
766
- credentialContext: credentialContextForActor(actor),
767
- destination,
768
- publishExternally: false,
769
- source,
770
- surface: "api",
771
- ...cancellationSignal ? { signal: cancellationSignal } : void 0,
772
- authorization: createWebAuthorization({
773
- actorId: actor.userId,
774
- conversationId: context.conversationId
775
- }),
776
- state: {
777
- pendingAuth: conversation.processing.pendingAuth,
778
- sandboxRef
779
- },
780
- delivery: deliverAssistantMessage,
781
- durability: {
782
- onInputCommitted: acknowledge,
783
- shouldYield: context.shouldYield,
784
- onSandboxRefChanged: async (nextSandboxRef) => {
785
- sandboxRef = nextSandboxRef;
786
- await persistThreadStateById(context.conversationId, {
787
- conversation,
788
- sandboxRef
789
- });
777
+ const outcome = await executeTurn(
778
+ agentRunner,
779
+ {
780
+ conversationId: context.conversationId,
781
+ turnId,
782
+ runId: currentRunId,
783
+ instruction: {
784
+ text,
785
+ context: buildConversationContext(conversation, {
786
+ excludeMessageId: userMessageId
787
+ })
788
+ },
789
+ history: piMessages,
790
+ actor,
791
+ credentialContext: credentialContextForActor(actor),
792
+ destination,
793
+ publishExternally: false,
794
+ source,
795
+ surface: "api",
796
+ ...cancellationSignal ? { signal: cancellationSignal } : void 0,
797
+ authorization: createWebAuthorization({
798
+ actorId: actor.userId,
799
+ conversationId: context.conversationId
800
+ }),
801
+ state: {
802
+ pendingAuth: conversation.processing.pendingAuth,
803
+ sandboxRef
790
804
  },
791
- recordPendingAuth: async (pendingAuth) => {
792
- conversation.processing.pendingAuth = pendingAuth;
793
- await persistThreadStateById(context.conversationId, {
794
- conversation,
795
- sandboxRef
805
+ delivery: deliverAssistantMessage,
806
+ durability: {
807
+ onInputCommitted: acknowledge,
808
+ shouldYield: context.shouldYield,
809
+ onSandboxRefChanged: async (nextSandboxRef) => {
810
+ sandboxRef = nextSandboxRef;
811
+ await persistThreadStateById(context.conversationId, {
812
+ conversation,
813
+ sandboxRef
814
+ });
815
+ },
816
+ recordPendingAuth: async (pendingAuth) => {
817
+ conversation.processing.pendingAuth = pendingAuth;
818
+ await persistThreadStateById(context.conversationId, {
819
+ conversation,
820
+ sandboxRef
821
+ });
822
+ }
823
+ }
824
+ },
825
+ async (result) => {
826
+ if (cancellationSignal?.aborted) {
827
+ throw cancellationSignal.reason ?? new DOMException("Turn cancelled", "AbortError");
828
+ }
829
+ finishCancellation();
830
+ modelFailureCaptureAttempted = result.diagnostics.outcome !== "success";
831
+ const finalized = finalizeFailedTurnReplyWithEvent({
832
+ reply: result,
833
+ logException
834
+ });
835
+ const modelFailureReason = finalized.failureReason;
836
+ const reply = finalized.reply;
837
+ modelFailureEventId = finalized.eventId;
838
+ if (reply.diagnostics.outcome !== "success") {
839
+ await deliverAssistantMessage(reply.text);
840
+ }
841
+ const completedState = buildDeliveredTurnStatePatch({
842
+ conversation,
843
+ reply,
844
+ sessionId: turnId,
845
+ userMessageId
846
+ });
847
+ await persistThreadStateById(context.conversationId, {
848
+ conversation: completedState.conversation,
849
+ sandboxRef: reply.sandboxRef ?? sandboxRef
850
+ });
851
+ if (reply.piMessages?.length) {
852
+ const latest = await getTurnRecord(
853
+ context.conversationId,
854
+ turnId
855
+ );
856
+ await saveTurnCheckpoint({
857
+ mode: "completed",
858
+ conversationId: context.conversationId,
859
+ turnId,
860
+ sliceId: latest?.sliceId ?? 1,
861
+ messages: reply.piMessages,
862
+ durationMs: reply.diagnostics.durationMs,
863
+ usage: reply.diagnostics.usage,
864
+ destination,
865
+ publishExternally: false,
866
+ source,
867
+ actor,
868
+ surface: "api"
796
869
  });
797
870
  }
871
+ completedSuccessfully = reply.diagnostics.outcome === "success";
872
+ return completedSuccessfully ? {
873
+ outcome: assistantMessageDelivered ? "success" : "no_reply"
874
+ } : {
875
+ ...modelFailureEventId ? { eventId: modelFailureEventId } : void 0,
876
+ failureCode: "model_execution_failed",
877
+ ...modelFailureReason ? { failureReason: modelFailureReason } : void 0,
878
+ outcome: "failed"
879
+ };
798
880
  }
799
- });
800
- if (cancellationSignal?.aborted) {
881
+ );
882
+ if (outcome.status !== "completed" && cancellationSignal?.aborted) {
801
883
  return await completeCancelledTurn();
802
884
  }
803
885
  if (outcome.status === "suspended") {
@@ -813,57 +895,12 @@ function createApiTurnWorker(options) {
813
895
  sandboxRef
814
896
  });
815
897
  if (appSignal) {
816
- options.cancellation?.park(context.conversationId, appSignal);
898
+ cancellation?.park(context.conversationId, appSignal);
817
899
  }
818
900
  await acknowledge();
819
901
  return { status: "paused" };
820
902
  }
821
- finishCancellation();
822
- reply = outcome.result;
823
- modelFailureCaptureAttempted = reply.diagnostics.outcome !== "success";
824
- const finalized = finalizeFailedTurnReplyWithEvent({
825
- reply,
826
- logException
827
- });
828
- reply = finalized.reply;
829
- modelFailureEventId = finalized.eventId;
830
- if (reply.diagnostics.outcome !== "success") {
831
- await deliverAssistantMessage(reply.text);
832
- }
833
- const completedState = buildDeliveredTurnStatePatch({
834
- conversation,
835
- reply,
836
- sessionId: turnId,
837
- userMessageId
838
- });
839
- await persistThreadStateById(context.conversationId, {
840
- conversation: completedState.conversation,
841
- sandboxRef: reply.sandboxRef ?? sandboxRef
842
- });
843
- if (reply.piMessages?.length) {
844
- const latest = await getTurnRecord(context.conversationId, turnId);
845
- await saveTurnCheckpoint({
846
- mode: "completed",
847
- conversationId: context.conversationId,
848
- turnId,
849
- sliceId: latest?.sliceId ?? 1,
850
- messages: reply.piMessages,
851
- durationMs: reply.diagnostics.durationMs,
852
- usage: reply.diagnostics.usage,
853
- destination,
854
- publishExternally: false,
855
- source,
856
- actor,
857
- surface: "api"
858
- });
859
- }
860
- if (reply.diagnostics.outcome === "success") {
861
- await lifecycle.complete({
862
- conversationId: context.conversationId,
863
- createdAtMs: Date.now(),
864
- outcome: assistantMessageDelivered ? "success" : "no_reply",
865
- turnId
866
- });
903
+ if (completedSuccessfully) {
867
904
  try {
868
905
  await scheduleSessionCompletedPluginTasks(
869
906
  {
@@ -895,30 +932,23 @@ function createApiTurnWorker(options) {
895
932
  turnId
896
933
  });
897
934
  }
898
- } else {
899
- await lifecycle.fail({
900
- conversationId: context.conversationId,
901
- createdAtMs: Date.now(),
902
- ...modelFailureEventId ? { eventId: modelFailureEventId } : void 0,
903
- failureCode: "model_execution_failed",
904
- turnId
905
- });
906
935
  }
907
936
  await acknowledge();
908
937
  return { status: "completed" };
909
938
  } catch (error) {
910
- if (hasLostTurnInputCommit(error)) {
939
+ const failure = error instanceof AgentRunError ? error.cause : error;
940
+ if (hasLostTurnInputCommit(failure)) {
911
941
  return { status: "lost_lease" };
912
942
  }
913
943
  if (cancellationSignal?.aborted) {
914
944
  return await completeCancelledTurn();
915
945
  }
916
946
  if (!context.attempt.isFinalAttempt) {
917
- throw error;
947
+ throw failure;
918
948
  }
919
949
  const failureEventId = modelFailureCaptureAttempted && failureCode === "agent_run_failed" ? modelFailureEventId : captureApiBoundaryFailure({
920
950
  conversationId: context.conversationId,
921
- error,
951
+ error: failure,
922
952
  failureCode,
923
953
  runId: currentRunId,
924
954
  turnId
@@ -12,7 +12,7 @@ import {
12
12
  } from "./chunk-PEQXYSSE.js";
13
13
  import {
14
14
  JUNIOR_VERSION
15
- } from "./chunk-W46NIB5H.js";
15
+ } from "./chunk-7GAP2XG4.js";
16
16
 
17
17
  // src/deployment.ts
18
18
  var JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getChatConfig
3
- } from "./chunk-LMNMMESF.js";
3
+ } from "./chunk-LRI5IRGY.js";
4
4
 
5
5
  // src/chat/state/adapter.ts
6
6
  import { createMemoryState } from "@chat-adapter/state-memory";
@@ -6,14 +6,14 @@ import {
6
6
  isStale,
7
7
  runNonInteractiveCommand,
8
8
  sleep
9
- } from "./chunk-X52ESOBP.js";
9
+ } from "./chunk-EJYP3NQ4.js";
10
10
  import {
11
11
  getStateAdapter
12
- } from "./chunk-G2B2XZQW.js";
12
+ } from "./chunk-PNYJOEVV.js";
13
13
  import {
14
14
  setSpanAttributes,
15
15
  withSpan
16
- } from "./chunk-LZBPGX5A.js";
16
+ } from "./chunk-OMQ2J6F6.js";
17
17
 
18
18
  // src/chat/sandbox/resources.ts
19
19
  var configuredResources;
@@ -1,11 +1,13 @@
1
1
  import {
2
- ToolInputError,
3
- canRouteResourceEvents,
4
- getPlugins
5
- } from "./chunk-AHMWPFIW.js";
2
+ ToolInputError
3
+ } from "./chunk-WLKWN4CD.js";
4
+ import {
5
+ getPlugins,
6
+ getSlackClient
7
+ } from "./chunk-VH4IU3UC.js";
6
8
  import {
7
9
  getDb
8
- } from "./chunk-AX3UDIMA.js";
10
+ } from "./chunk-ABAX75GG.js";
9
11
  import {
10
12
  juniorAttachments,
11
13
  juniorConversations,
@@ -13,16 +15,38 @@ import {
13
15
  juniorSchedulerRuns,
14
16
  juniorSchedulerTasks,
15
17
  juniorStats
16
- } from "./chunk-6UXDTPEN.js";
18
+ } from "./chunk-LVK4WJKM.js";
17
19
  import {
18
20
  juniorDestinations
19
21
  } from "./chunk-VFUK3X5B.js";
20
22
  import {
21
23
  getSlackBotToken
22
- } from "./chunk-LMNMMESF.js";
24
+ } from "./chunk-LRI5IRGY.js";
23
25
  import {
24
26
  logWarn
25
- } from "./chunk-LZBPGX5A.js";
27
+ } from "./chunk-OMQ2J6F6.js";
28
+
29
+ // src/chat/resource-events/workspace.ts
30
+ function canRouteResourceEvents() {
31
+ return Boolean(getSlackBotToken());
32
+ }
33
+ function createResourceEventTeamIdResolver() {
34
+ let pending;
35
+ return async () => {
36
+ if (!canRouteResourceEvents()) return void 0;
37
+ pending ??= getSlackClient().auth.test().then((result) => {
38
+ const teamId = result.team_id?.trim();
39
+ if (!teamId) {
40
+ throw new Error("Slack auth.test did not return a workspace team id");
41
+ }
42
+ return teamId;
43
+ }).catch((error) => {
44
+ pending = void 0;
45
+ throw error;
46
+ });
47
+ return await pending;
48
+ };
49
+ }
26
50
 
27
51
  // src/chat/event-tasks/store.ts
28
52
  import {
@@ -1250,6 +1274,8 @@ export {
1250
1274
  registeredResourceEventMatchSchema,
1251
1275
  requireSupportedResourceEventMatch,
1252
1276
  normalizeEventIdentifier,
1277
+ canRouteResourceEvents,
1278
+ createResourceEventTeamIdResolver,
1253
1279
  getResourceEventCatalog,
1254
1280
  getEventTask,
1255
1281
  createEventTask,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  createAndEnqueueAgentInvocation
3
- } from "./chunk-IO6KFXYE.js";
3
+ } from "./chunk-HJPC32TQ.js";
4
4
  import {
5
5
  actorFromRun,
6
6
  toolInvocationDestination
7
- } from "./chunk-RF6J3DIO.js";
7
+ } from "./chunk-INQHUE72.js";
8
8
 
9
9
  // src/chat/agent-invocations/spawn.ts
10
10
  function bindSpawnAgent(run, options) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  abandonTurnRecord,
3
3
  extractAssistantText
4
- } from "./chunk-24OJZ5OU.js";
4
+ } from "./chunk-WLKWN4CD.js";
5
5
 
6
6
  // src/chat/state/turn-id.ts
7
7
  function buildDeterministicTurnId(messageId) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getStateAdapter
3
- } from "./chunk-G2B2XZQW.js";
3
+ } from "./chunk-PNYJOEVV.js";
4
4
  import {
5
5
  getClient
6
6
  } from "./chunk-PEQXYSSE.js";