@sentry/junior 0.192.0 → 0.194.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 (97) hide show
  1. package/dist/{agent-hooks-3JY76L5X.js → agent-hooks-IDX764FD.js} +11 -11
  2. package/dist/api/conversations/aggregate.d.ts +2 -0
  3. package/dist/api/conversations/list.d.ts +1 -1
  4. package/dist/api/conversations/projection.d.ts +1 -1
  5. package/dist/api/locations/detail.d.ts +1 -1
  6. package/dist/api/schema/conversation.d.ts +3 -3
  7. package/dist/api/schema/location.d.ts +1 -1
  8. package/dist/api/schema/person.d.ts +1 -1
  9. package/dist/api/schema/task.d.ts +71 -8
  10. package/dist/api/schema.d.ts +2 -2
  11. package/dist/api/schema.js +3 -1
  12. package/dist/api.js +106 -187
  13. package/dist/app.js +55 -83
  14. package/dist/{catalog-runtime-5JVLWXRY.js → catalog-runtime-MICXEBLK.js} +4 -4
  15. package/dist/chat/agent/prompt.d.ts +1 -1
  16. package/dist/chat/agent/resume.d.ts +2 -0
  17. package/dist/chat/agent-dispatch/types.d.ts +2 -1
  18. package/dist/chat/agent-dispatch/validation.d.ts +1 -1
  19. package/dist/chat/agent-invocations/types.d.ts +24 -28
  20. package/dist/chat/config.d.ts +1 -0
  21. package/dist/chat/conversations/history.d.ts +4 -2
  22. package/dist/chat/event-tasks/tool-support.d.ts +10 -1
  23. package/dist/chat/plugins/agent-hooks.d.ts +2 -2
  24. package/dist/chat/prompt.d.ts +4 -5
  25. package/dist/chat/services/turn-limit.d.ts +11 -1
  26. package/dist/chat/services/turn-session-routing.d.ts +4 -3
  27. package/dist/chat/slack/{source-link.d.ts → location-url.d.ts} +1 -1
  28. package/dist/chat/slack/tool-support/context.d.ts +3 -6
  29. package/dist/chat/source.d.ts +4 -6
  30. package/dist/chat/task-execution/checkpoint.d.ts +2 -0
  31. package/dist/chat/task-execution/turn-cursor.d.ts +3 -0
  32. package/dist/chat/tasks/execution-stats.d.ts +13 -1
  33. package/dist/chat/tools/delete-event-task.d.ts +1 -1
  34. package/dist/chat/tools/types.d.ts +10 -9
  35. package/dist/chat/tools/update-event-task.d.ts +1 -1
  36. package/dist/chat/usage.d.ts +4 -0
  37. package/dist/{chunk-YRWGJ5OO.js → chunk-2NL3Y47F.js} +5 -5
  38. package/dist/{chunk-BGLMT6KP.js → chunk-53IEEFFP.js} +3 -3
  39. package/dist/{chunk-PXUBRZBU.js → chunk-6H2MKVV5.js} +1 -1
  40. package/dist/{chunk-47JFLZSF.js → chunk-73JEAQRT.js} +4 -4
  41. package/dist/{chunk-6LX6KV5C.js → chunk-7ANA7PBB.js} +3 -3
  42. package/dist/{chunk-AKR6W7VV.js → chunk-ADEACKAH.js} +82 -69
  43. package/dist/{chunk-YE6DVM43.js → chunk-AWZS5SVX.js} +8 -8
  44. package/dist/{chunk-BUTAWPUV.js → chunk-CCTYK5RH.js} +37 -31
  45. package/dist/{chunk-RWBZZMW6.js → chunk-CFGBKPWQ.js} +3 -3
  46. package/dist/{chunk-G4E5WIRL.js → chunk-E53C73ML.js} +4 -4
  47. package/dist/{chunk-3UJSII43.js → chunk-ELCYG6UU.js} +3 -3
  48. package/dist/{chunk-SSR6YBWW.js → chunk-ENWIHU54.js} +11 -7
  49. package/dist/{chunk-4CCQZHD3.js → chunk-F2KSURTJ.js} +11 -11
  50. package/dist/{chunk-7XO7PTZE.js → chunk-G35QGPO2.js} +1 -1
  51. package/dist/{chunk-4B4DQGOM.js → chunk-G4RARFNT.js} +101 -66
  52. package/dist/{chunk-Z4DNJI5F.js → chunk-GY5SEFVL.js} +5 -5
  53. package/dist/{chunk-KR5F3QSP.js → chunk-H4DCWLTR.js} +8 -8
  54. package/dist/{chunk-ARSUYYQG.js → chunk-IME5OW4Y.js} +1 -1
  55. package/dist/{chunk-3O2NXVGB.js → chunk-INTBMGNX.js} +23 -25
  56. package/dist/{chunk-4WIA45WD.js → chunk-IOGDKPVU.js} +1 -1
  57. package/dist/{chunk-EYNUOZCN.js → chunk-JOI3DHML.js} +1 -1
  58. package/dist/{chunk-5V4BAUCH.js → chunk-KNIAWMBU.js} +1 -1
  59. package/dist/{chunk-ITTEDZGY.js → chunk-NPO24LAN.js} +32 -25
  60. package/dist/{chunk-SZ2O3CGS.js → chunk-NWWDFHXP.js} +1 -1
  61. package/dist/{chunk-VF3EDS7P.js → chunk-OEQOAONV.js} +60 -29
  62. package/dist/{chunk-PYVGXGKC.js → chunk-P2P6MUQ4.js} +2 -2
  63. package/dist/{chunk-PXP2M32M.js → chunk-QMEF4Z7R.js} +6 -7
  64. package/dist/{chunk-OBN7UEQJ.js → chunk-RFE7DCZK.js} +24 -2
  65. package/dist/{chunk-6FCKJDKS.js → chunk-S7GX44BU.js} +1 -1
  66. package/dist/{chunk-4Z7B5WVV.js → chunk-U76RWMFR.js} +4 -2
  67. package/dist/{chunk-LRTEMMCZ.js → chunk-V4HXV5MY.js} +1 -1
  68. package/dist/{chunk-MB2CTEPD.js → chunk-VOB2DKO6.js} +174 -34
  69. package/dist/{chunk-EIYOABL4.js → chunk-WMJS5DDV.js} +12 -8
  70. package/dist/{chunk-FGYWKKTJ.js → chunk-WWXJUURQ.js} +1 -1
  71. package/dist/{chunk-3ADPXQBL.js → chunk-X76JVHQ4.js} +1 -1
  72. package/dist/{chunk-IBO4YFFZ.js → chunk-XLWZRHX5.js} +1 -1
  73. package/dist/{chunk-H5Q2T5VC.js → chunk-XND3J6AT.js} +1 -1
  74. package/dist/{chunk-4AFSQJD6.js → chunk-XRDSML3K.js} +3 -4
  75. package/dist/{chunk-EYIMZY5O.js → chunk-YSLIB7ER.js} +18 -3
  76. package/dist/cli/chat.js +33 -33
  77. package/dist/cli/check.js +5 -5
  78. package/dist/cli/plugins.js +12 -12
  79. package/dist/cli/snapshot-create.js +9 -9
  80. package/dist/cli/upgrade.js +6 -6
  81. package/dist/db/schema/agent-invocations.d.ts +16 -0
  82. package/dist/db/schema.d.ts +16 -0
  83. package/dist/{db-LRM6AP66.js → db-3IEVINAY.js} +6 -6
  84. package/dist/instrumentation.js +3 -3
  85. package/dist/nitro.js +6 -6
  86. package/dist/{oauth-callback-server-BKCDVYVH.js → oauth-callback-server-N7L2BB4L.js} +29 -29
  87. package/dist/{runner-RUXGS3E6.js → runner-PTTZV3WU.js} +21 -21
  88. package/dist/{skills-DXP2RCJF.js → skills-POMWS2RR.js} +5 -5
  89. package/dist/spawn-R75MXXKE.js +42 -0
  90. package/dist/task-runner-OQLRHADB.js +36 -0
  91. package/dist/{validation-F4KYLIF2.js → validation-U6LOMXR7.js} +5 -5
  92. package/dist/version.js +1 -1
  93. package/dist/{work-UUNMNSML.js → work-FHA3BS4L.js} +21 -21
  94. package/dist/{worker-PMIJ5NLD.js → worker-GR4UNVVP.js} +10 -10
  95. package/package.json +5 -5
  96. package/dist/spawn-HH7GH7XT.js +0 -42
  97. package/dist/task-runner-H5I7R3LJ.js +0 -36
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  AgentRunError,
6
6
  executeTurn
7
- } from "./chunk-BGLMT6KP.js";
7
+ } from "./chunk-53IEEFFP.js";
8
8
  import {
9
9
  buildDeliveredTurnStatePatch,
10
10
  finalizeFailedTurnReplyWithEvent,
@@ -15,14 +15,14 @@ import {
15
15
  getTurnUserSlackMessageTs,
16
16
  persistAuthPauseTurnState,
17
17
  requireTurnFailureEventId
18
- } from "./chunk-YRWGJ5OO.js";
18
+ } from "./chunk-2NL3Y47F.js";
19
19
  import {
20
20
  resolveTurnSessionRouting,
21
21
  scheduleSessionCompletedPluginTasks
22
- } from "./chunk-ITTEDZGY.js";
22
+ } from "./chunk-NPO24LAN.js";
23
23
  import {
24
24
  getTurnLifecycle
25
- } from "./chunk-PXUBRZBU.js";
25
+ } from "./chunk-6H2MKVV5.js";
26
26
  import {
27
27
  coerceThreadConversationState,
28
28
  configValueSchema,
@@ -30,11 +30,11 @@ import {
30
30
  getPersistedSandboxState,
31
31
  getPersistedThreadState,
32
32
  persistThreadStateById
33
- } from "./chunk-Z4DNJI5F.js";
33
+ } from "./chunk-GY5SEFVL.js";
34
34
  import {
35
35
  buildSentryConversationUrl,
36
36
  deleteWebAuthorization
37
- } from "./chunk-H5Q2T5VC.js";
37
+ } from "./chunk-XND3J6AT.js";
38
38
  import {
39
39
  createUserTokenStore,
40
40
  deleteMcpAuthSession,
@@ -45,7 +45,7 @@ import {
45
45
  lookupSlackUserProfile,
46
46
  putMcpStoredOAuthCredentials,
47
47
  resolvePluginOAuthAccount
48
- } from "./chunk-YE6DVM43.js";
48
+ } from "./chunk-AWZS5SVX.js";
49
49
  import {
50
50
  RetryableDeliveryError,
51
51
  addReactionToMessage,
@@ -59,7 +59,7 @@ import {
59
59
  removeReactionFromMessage,
60
60
  resolveBaseUrl,
61
61
  truncateStatusText
62
- } from "./chunk-SSR6YBWW.js";
62
+ } from "./chunk-ENWIHU54.js";
63
63
  import {
64
64
  CooperativeTurnYieldError,
65
65
  clearPendingAuth,
@@ -68,12 +68,11 @@ import {
68
68
  isCooperativeTurnYieldError,
69
69
  isPendingAuthLatestRequest,
70
70
  markTurnFailed
71
- } from "./chunk-7XO7PTZE.js";
71
+ } from "./chunk-G35QGPO2.js";
72
72
  import {
73
- TurnSliceLimitExceededError,
74
73
  abandonTurnRecord,
75
74
  buildConversationContext,
76
- buildTurnLimitResponse,
75
+ buildTurnErrorResponse,
77
76
  commitAcceptedReply,
78
77
  failTurnRecord,
79
78
  getTurnRecord,
@@ -88,20 +87,20 @@ import {
88
87
  recordTurnSummary,
89
88
  saveTurnCheckpoint,
90
89
  turnHasReply
91
- } from "./chunk-VF3EDS7P.js";
90
+ } from "./chunk-OEQOAONV.js";
92
91
  import {
93
92
  parseSlackThreadId,
94
93
  readSlackRawMessageContext,
95
94
  resolveSlackChannelIdFromMessage,
96
95
  resolveSlackChannelIdFromThreadId
97
- } from "./chunk-4WIA45WD.js";
96
+ } from "./chunk-IOGDKPVU.js";
98
97
  import {
99
98
  ensureConversationWake,
100
99
  requestConversationWork
101
- } from "./chunk-G4E5WIRL.js";
100
+ } from "./chunk-E53C73ML.js";
102
101
  import {
103
102
  getTurnRequestDeadline
104
- } from "./chunk-SZ2O3CGS.js";
103
+ } from "./chunk-NWWDFHXP.js";
105
104
  import {
106
105
  getVercelConversationWorkQueue
107
106
  } from "./chunk-DKIJ2RP5.js";
@@ -113,39 +112,39 @@ import {
113
112
  getSlackClient,
114
113
  isDmChannel,
115
114
  normalizeSlackConversationId
116
- } from "./chunk-BUTAWPUV.js";
115
+ } from "./chunk-CCTYK5RH.js";
117
116
  import {
118
117
  getConversationStore,
119
118
  getSqlExecutor,
120
119
  requireSlackDestination,
121
120
  upsertIdentity,
122
121
  upsertLinkedIdentity
123
- } from "./chunk-AKR6W7VV.js";
122
+ } from "./chunk-ADEACKAH.js";
124
123
  import {
125
124
  acquireActiveLock,
126
125
  getStateAdapter
127
- } from "./chunk-LRTEMMCZ.js";
126
+ } from "./chunk-V4HXV5MY.js";
128
127
  import {
129
128
  botConfig,
130
129
  escapeXml,
131
130
  getChatConfig,
132
131
  getRuntimeMetadata,
133
132
  normalizeSlackEmojiName
134
- } from "./chunk-4Z7B5WVV.js";
133
+ } from "./chunk-U76RWMFR.js";
135
134
  import {
136
135
  defaultModelId
137
136
  } from "./chunk-D4YV5TDV.js";
138
137
  import {
139
138
  discoverSkills
140
- } from "./chunk-PYVGXGKC.js";
139
+ } from "./chunk-P2P6MUQ4.js";
141
140
  import {
142
141
  pluginCatalogRuntime
143
- } from "./chunk-FGYWKKTJ.js";
142
+ } from "./chunk-WWXJUURQ.js";
144
143
  import {
145
144
  buildOAuthTokenRequest,
146
145
  hasRequiredOAuthScope,
147
146
  parseOAuthTokenResponse
148
- } from "./chunk-6FCKJDKS.js";
147
+ } from "./chunk-S7GX44BU.js";
149
148
  import {
150
149
  createSlackResumeActor,
151
150
  isUserActor,
@@ -156,7 +155,6 @@ import {
156
155
  homeDir
157
156
  } from "./chunk-TXKUKMVO.js";
158
157
  import {
159
- buildTurnFailureResponse,
160
158
  logException,
161
159
  logInfo,
162
160
  logWarn,
@@ -164,7 +162,7 @@ import {
164
162
  setTags,
165
163
  toOptionalString,
166
164
  withLogContext
167
- } from "./chunk-3ADPXQBL.js";
165
+ } from "./chunk-X76JVHQ4.js";
168
166
 
169
167
  // src/chat/slack/assistant-thread/status-render.ts
170
168
  var DEFAULT_STATUS_CONTEXTS = {
@@ -1171,7 +1169,7 @@ async function postResumeFailureReply(args) {
1171
1169
  await postSlackMessage({
1172
1170
  channelId: args.channelId,
1173
1171
  threadTs: args.threadTs,
1174
- text: args.error instanceof TurnSliceLimitExceededError ? buildTurnLimitResponse(args.eventId) : buildTurnFailureResponse(args.eventId)
1172
+ text: buildTurnErrorResponse(args.error, args.eventId)
1175
1173
  });
1176
1174
  }
1177
1175
  async function handleResumeFailure(args) {
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-N7TMSOZH.js";
6
6
  import {
7
7
  toOptionalString
8
- } from "./chunk-3ADPXQBL.js";
8
+ } from "./chunk-X76JVHQ4.js";
9
9
 
10
10
  // src/chat/slack/context.ts
11
11
  import { z } from "zod";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logWarn
3
- } from "./chunk-3ADPXQBL.js";
3
+ } from "./chunk-X76JVHQ4.js";
4
4
 
5
5
  // src/chat/conversation-privacy.ts
6
6
  import { AsyncLocalStorage } from "async_hooks";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  pluginCatalogRuntime
3
- } from "./chunk-FGYWKKTJ.js";
3
+ } from "./chunk-WWXJUURQ.js";
4
4
 
5
5
  // src/chat/plugins/validation.ts
6
6
  import { isDeepStrictEqual } from "util";
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  coerceThreadConversationState,
3
3
  getPersistedThreadState
4
- } from "./chunk-Z4DNJI5F.js";
4
+ } from "./chunk-GY5SEFVL.js";
5
5
  import {
6
6
  recordTaskExecution
7
- } from "./chunk-MB2CTEPD.js";
7
+ } from "./chunk-VOB2DKO6.js";
8
8
  import {
9
9
  pluginTaskId,
10
10
  pluginTaskParamsSchema,
11
11
  sendVercelPluginTask
12
- } from "./chunk-RWBZZMW6.js";
12
+ } from "./chunk-CFGBKPWQ.js";
13
13
  import {
14
14
  getPiMessageRole,
15
15
  getTurnRecord,
@@ -19,7 +19,7 @@ import {
19
19
  isToolResultMessage,
20
20
  normalizeToolNameFromResult,
21
21
  stripRuntimeTurnContext
22
- } from "./chunk-VF3EDS7P.js";
22
+ } from "./chunk-OEQOAONV.js";
23
23
  import {
24
24
  createPluginConversationEvents,
25
25
  createPluginEmbedder,
@@ -28,17 +28,17 @@ import {
28
28
  createPluginState,
29
29
  getPlugins,
30
30
  readActorIdentity
31
- } from "./chunk-BUTAWPUV.js";
31
+ } from "./chunk-CCTYK5RH.js";
32
32
  import {
33
33
  JUNIOR_THREAD_STATE_TTL_MS
34
34
  } from "./chunk-3Y47VMHV.js";
35
35
  import {
36
36
  getConversationStore,
37
37
  getDb
38
- } from "./chunk-AKR6W7VV.js";
38
+ } from "./chunk-ADEACKAH.js";
39
39
  import {
40
40
  getStateAdapter
41
- } from "./chunk-LRTEMMCZ.js";
41
+ } from "./chunk-V4HXV5MY.js";
42
42
  import {
43
43
  sameActorIdentity
44
44
  } from "./chunk-GFBR4S3Q.js";
@@ -84,7 +84,7 @@ function slackSourceForDestination(args) {
84
84
  };
85
85
  }
86
86
  async function resolveConversationRouting(args) {
87
- const conversationStore = args.conversationStore ?? (await import("./db-LRM6AP66.js")).getConversationStore();
87
+ const conversationStore = args.conversationStore ?? (await import("./db-3IEVINAY.js")).getConversationStore();
88
88
  const chain = await loadConversationChain(
89
89
  args.conversationId,
90
90
  conversationStore
@@ -579,14 +579,14 @@ function turnMessagesWithProvenance(record) {
579
579
  }
580
580
  return paired;
581
581
  }
582
- function slackContextAuthor(source, message) {
582
+ function slackContextAuthor(location, message) {
583
583
  const userId = message.author?.userId?.trim();
584
584
  if (!userId) {
585
585
  return void 0;
586
586
  }
587
587
  return {
588
588
  platform: "slack",
589
- teamId: source.teamId,
589
+ teamId: location.teamId,
590
590
  userId,
591
591
  ...message.author?.userName ? { userName: message.author.userName } : void 0,
592
592
  ...message.author?.fullName ? { fullName: message.author.fullName } : void 0
@@ -610,17 +610,9 @@ function messageExistedAtRunCompletion(message, completedAtMs) {
610
610
  const messageTimestampMs = conversationMessageTimestampMs(message);
611
611
  return messageTimestampMs !== void 0 && messageTimestampMs <= completedAtMs;
612
612
  }
613
- async function loadConversationContextTranscriptEntries(record, source, runActor) {
614
- switch (source.kind) {
615
- case "slack":
616
- if (source.visibility === "private") {
617
- return [];
618
- }
619
- break;
620
- case "web":
621
- case "local":
622
- case "resource_event":
623
- return [];
613
+ async function loadConversationContextTranscriptEntries(record, location, visibility, runActor) {
614
+ if (location?.provider !== "slack" || visibility !== "public") {
615
+ return [];
624
616
  }
625
617
  const state = await getPersistedThreadState(record.conversationId);
626
618
  const conversation = coerceThreadConversationState(state);
@@ -640,7 +632,7 @@ async function loadConversationContextTranscriptEntries(record, source, runActor
640
632
  if (!text) {
641
633
  continue;
642
634
  }
643
- const author = slackContextAuthor(source, message);
635
+ const author = slackContextAuthor(location, message);
644
636
  entries.push({
645
637
  type: "message",
646
638
  role: "user",
@@ -678,7 +670,21 @@ async function loadPluginRun(params) {
678
670
  if (record.state !== "completed") {
679
671
  throw new Error("Completed plugin task session record is not completed");
680
672
  }
681
- const routing = await resolveTurnSessionRouting({
673
+ const conversationStore = getConversationStore();
674
+ const routing = await resolveConversationRouting({
675
+ conversationId: params.conversationId,
676
+ conversationStore
677
+ });
678
+ if (!routing) {
679
+ throw new Error(
680
+ `Conversation ${params.conversationId} is missing durable routing metadata`
681
+ );
682
+ }
683
+ const source = record.source ?? routing.source;
684
+ if (!source) {
685
+ throw new Error("Completed plugin task session record is missing Source");
686
+ }
687
+ const conversation = await conversationStore.get({
682
688
  conversationId: params.conversationId
683
689
  });
684
690
  const runActor = record.actor ?? record.actors[0] ?? (record.dispatchId ? (await getDispatchRecord(record.dispatchId))?.actor : void 0);
@@ -691,7 +697,8 @@ async function loadPluginRun(params) {
691
697
  );
692
698
  const contextEntries = (await loadConversationContextTranscriptEntries(
693
699
  record,
694
- routing.source,
700
+ conversation?.location,
701
+ conversation?.visibility,
695
702
  runActor
696
703
  )).filter(
697
704
  (entry) => entry.type !== "message" || !runMessageTexts.has(entry.text)
@@ -707,7 +714,7 @@ async function loadPluginRun(params) {
707
714
  actors: record.actors,
708
715
  ...runActor ? { actor: runActor } : void 0,
709
716
  runId: record.turnId,
710
- source: routing.source,
717
+ source,
711
718
  transcript: [...contextEntries, ...runEntries]
712
719
  });
713
720
  }
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  FUNCTION_TIMEOUT_BUFFER_SECONDS,
3
3
  getChatConfig
4
- } from "./chunk-4Z7B5WVV.js";
4
+ } from "./chunk-U76RWMFR.js";
5
5
 
6
6
  // src/chat/runtime/request-deadline.ts
7
7
  import { AsyncLocalStorage } from "async_hooks";
@@ -7,7 +7,7 @@ import {
7
7
  authenticationUnlinkedEvent,
8
8
  fallbackShortTitle,
9
9
  generateShortTitle
10
- } from "./chunk-OBN7UEQJ.js";
10
+ } from "./chunk-RFE7DCZK.js";
11
11
  import {
12
12
  bindProviderConversation,
13
13
  createSqlConversationEventStore,
@@ -16,18 +16,18 @@ import {
16
16
  getSqlExecutor,
17
17
  sanitizePostgresJson,
18
18
  withConversationEventLock
19
- } from "./chunk-AKR6W7VV.js";
19
+ } from "./chunk-ADEACKAH.js";
20
20
  import {
21
21
  SANDBOX_REPOS_ROOT,
22
22
  SANDBOX_WORKSPACE_ROOT,
23
23
  sleep
24
- } from "./chunk-6LX6KV5C.js";
24
+ } from "./chunk-7ANA7PBB.js";
25
25
  import {
26
26
  MUTATION_LOCK_TTL_MS,
27
27
  fenceLock,
28
28
  getStateAdapter,
29
29
  withLock
30
- } from "./chunk-LRTEMMCZ.js";
30
+ } from "./chunk-V4HXV5MY.js";
31
31
  import {
32
32
  agentHistoryItemSchema,
33
33
  contextProvenance,
@@ -40,17 +40,18 @@ import {
40
40
  escapeXml,
41
41
  resolveGatewayModel,
42
42
  unwrapCurrentInstruction
43
- } from "./chunk-4Z7B5WVV.js";
43
+ } from "./chunk-U76RWMFR.js";
44
44
  import {
45
45
  parseSlackMessageTs,
46
46
  toStoredSlackActor
47
47
  } from "./chunk-N7TMSOZH.js";
48
48
  import {
49
+ buildTurnFailureResponse,
49
50
  getActiveTraceId,
50
51
  logException,
51
52
  logWarn,
52
53
  setSpanAttributes
53
- } from "./chunk-3ADPXQBL.js";
54
+ } from "./chunk-X76JVHQ4.js";
54
55
 
55
56
  // src/chat/turn-context-tag.ts
56
57
  var TURN_CONTEXT_TAG = "runtime-turn-context";
@@ -1241,7 +1242,7 @@ async function commitMessagesLocked(args, executor) {
1241
1242
  content: context.content
1242
1243
  }
1243
1244
  })) ?? [];
1244
- await eventStore.append(args.conversationId, [
1245
+ const appendedEvents = await eventStore.append(args.conversationId, [
1245
1246
  ...newMessages.map((message, index) => ({
1246
1247
  data: historyItemFromPiMessage(
1247
1248
  message,
@@ -1251,22 +1252,19 @@ async function commitMessagesLocked(args, executor) {
1251
1252
  })),
1252
1253
  ...turnContextEvents
1253
1254
  ]);
1254
- } else {
1255
- throw new AgentHistoryBranchError(args.conversationId);
1255
+ const cursor = appendedEvents.at(-1) ?? currentEvents.at(-1);
1256
+ return {
1257
+ committedSeq: cursor?.seq ?? -1,
1258
+ historyVersion: cursor?.historyVersion ?? 0,
1259
+ messageSeqs: [
1260
+ ...current.seqs,
1261
+ ...appendedEvents.slice(0, newMessages.length).map((event) => event.seq)
1262
+ ],
1263
+ messages: nextLocalMessages,
1264
+ provenance: nextLocalProvenance
1265
+ };
1256
1266
  }
1257
- const committedEvents = await eventStore.loadCurrentHistory(
1258
- args.conversationId
1259
- );
1260
- const committed = projectConversationEvents(committedEvents, {
1261
- defaultProfile: botConfig.defaultProfile
1262
- });
1263
- return {
1264
- committedSeq: committedEvents.at(-1)?.seq ?? -1,
1265
- historyVersion: committedEvents.at(-1)?.historyVersion ?? 0,
1266
- messageSeqs: committed.seqs,
1267
- messages: nextLocalMessages,
1268
- provenance: nextLocalProvenance
1269
- };
1267
+ throw new AgentHistoryBranchError(args.conversationId);
1270
1268
  }
1271
1269
  async function recordMcpProviderConnected(args) {
1272
1270
  const eventStore = getConversationEventStore();
@@ -2074,6 +2072,7 @@ var storedTurnRecordSchema = z2.object({
2074
2072
  committedSeq: seqCursorSchema,
2075
2073
  historyVersion: z2.number().int().nonnegative().optional(),
2076
2074
  errorMessage: z2.string().optional(),
2075
+ cumulativeToolCallCount: z2.number().int().nonnegative().optional(),
2077
2076
  turnStartSeq: seqCursorSchema.optional(),
2078
2077
  runtimeContext: z2.array(piMessageSchema).optional()
2079
2078
  }).strip();
@@ -2175,6 +2174,7 @@ function materializeTurnRecord(stored, piProjection, turnStartMessageIndex, rest
2175
2174
  cumulativeDurationMs: runtimeMetrics?.cumulativeDurationMs ?? 0,
2176
2175
  ...definedProps({
2177
2176
  channelName: runtimeMetrics?.channelName,
2177
+ cumulativeToolCallCount: stored.cumulativeToolCallCount,
2178
2178
  cumulativeUsage: runtimeMetrics?.cumulativeUsage,
2179
2179
  dispatchId: stored.dispatchId,
2180
2180
  dispatchOutcome: stored.dispatchOutcome,
@@ -2246,12 +2246,13 @@ async function materializeStoredTurnRecord(conversationId, turnId, followCurrent
2246
2246
  if (!pinnedProjection) {
2247
2247
  return void 0;
2248
2248
  }
2249
- const currentHistory = await getConversationEventStore().loadCurrentHistory(conversationId);
2250
- const currentHistoryVersion = currentHistory.at(-1)?.historyVersion ?? parsed.historyVersion ?? 0;
2249
+ const eventStore = getConversationEventStore();
2250
+ const currentHistoryVersion = await eventStore.loadCurrentHistoryVersion(conversationId);
2251
2251
  const followsReplacement = followCurrentReplacement && (parsed.state === "running" || parsed.state === "paused") && parsed.historyVersion !== void 0 && parsed.historyVersion !== currentHistoryVersion;
2252
- const piProjection = followsReplacement ? projectConversationEvents(currentHistory, {
2253
- defaultProfile: botConfig.defaultProfile
2254
- }) : pinnedProjection;
2252
+ const piProjection = followsReplacement ? projectConversationEvents(
2253
+ await eventStore.loadCurrentHistory(conversationId),
2254
+ { defaultProfile: botConfig.defaultProfile }
2255
+ ) : pinnedProjection;
2255
2256
  const turnStartMessageIndex = followsReplacement ? 0 : parsed.turnStartSeq === void 0 ? void 0 : piProjection.seqs.filter((seq) => seq <= parsed.turnStartSeq).length;
2256
2257
  const conversation = await getConversationStore().get({ conversationId });
2257
2258
  const executionMetrics = executionMetricsForTurn(conversation, turnId);
@@ -2288,6 +2289,7 @@ function buildStoredRecord(args) {
2288
2289
  committedSeq: args.committedSeq,
2289
2290
  ...definedProps({
2290
2291
  actor: args.actor,
2292
+ cumulativeToolCallCount: args.cumulativeToolCallCount,
2291
2293
  dispatchId: args.dispatchId,
2292
2294
  dispatchOutcome: args.dispatchOutcome,
2293
2295
  errorMessage: args.errorMessage,
@@ -2379,6 +2381,7 @@ async function updateTurnState(args) {
2379
2381
  lastProgressAtMs: parsed.lastProgressAtMs,
2380
2382
  previousVersion: parsed.version,
2381
2383
  ...definedProps({
2384
+ cumulativeToolCallCount: args.existing.cumulativeToolCallCount,
2382
2385
  dispatchId: args.existing.dispatchId,
2383
2386
  dispatchOutcome: args.existing.dispatchOutcome,
2384
2387
  errorMessage: args.errorMessage ?? args.existing.errorMessage,
@@ -2473,6 +2476,7 @@ async function upsertTurnRecordLocked(args, fence) {
2473
2476
  historyVersion: commit.historyVersion,
2474
2477
  previousVersion: existingRecord?.version,
2475
2478
  ...definedProps({
2479
+ cumulativeToolCallCount: args.cumulativeToolCallCount ?? existingRecord?.cumulativeToolCallCount,
2476
2480
  dispatchId,
2477
2481
  dispatchOutcome: args.dispatchOutcome ?? existingRecord?.dispatchOutcome,
2478
2482
  errorMessage: args.errorMessage,
@@ -2643,9 +2647,33 @@ var TurnSliceLimitExceededError = class extends Error {
2643
2647
  this.name = "TurnSliceLimitExceededError";
2644
2648
  }
2645
2649
  };
2650
+ var TurnToolCallLimitExceededError = class extends Error {
2651
+ constructor(maxToolCalls) {
2652
+ super(`Agent turn exceeded execution limit (${maxToolCalls} tool calls)`);
2653
+ this.name = "TurnToolCallLimitExceededError";
2654
+ }
2655
+ };
2656
+ function isDirectTurnExecutionLimitError(error) {
2657
+ return error instanceof TurnSliceLimitExceededError || error instanceof TurnToolCallLimitExceededError;
2658
+ }
2659
+ function isTurnExecutionLimitExceededError(error) {
2660
+ if (isDirectTurnExecutionLimitError(error)) {
2661
+ return true;
2662
+ }
2663
+ return error instanceof Error && isDirectTurnExecutionLimitError(error.cause);
2664
+ }
2665
+ function assertTurnToolCallLimit(toolCallCount, maxToolCalls) {
2666
+ if (toolCallCount <= maxToolCalls) {
2667
+ return;
2668
+ }
2669
+ throw new TurnToolCallLimitExceededError(maxToolCalls);
2670
+ }
2646
2671
  function buildTurnLimitResponse(eventId) {
2647
2672
  return `I couldn't finish this request because this turn reached its execution limit. Please try again with a smaller or more specific request. Reference: \`event_id=${eventId}\`.`;
2648
2673
  }
2674
+ function buildTurnErrorResponse(error, eventId) {
2675
+ return isTurnExecutionLimitExceededError(error) ? buildTurnLimitResponse(eventId) : buildTurnFailureResponse(eventId);
2676
+ }
2649
2677
 
2650
2678
  // src/chat/task-execution/checkpoint.ts
2651
2679
  function definedProps2(values) {
@@ -2699,7 +2727,8 @@ function sharedWrite(args, latest) {
2699
2727
  source: args.source,
2700
2728
  surface: args.surface ?? latest?.surface,
2701
2729
  traceId: getActiveTraceId() ?? latest?.traceId,
2702
- turnStartMessageIndex: args.turnStartMessageIndex ?? latest?.turnStartMessageIndex
2730
+ turnStartMessageIndex: args.turnStartMessageIndex ?? latest?.turnStartMessageIndex,
2731
+ cumulativeToolCallCount: args.cumulativeToolCallCount ?? latest?.cumulativeToolCallCount
2703
2732
  })
2704
2733
  };
2705
2734
  }
@@ -2896,7 +2925,9 @@ export {
2896
2925
  buildAgentsInstructionsMessage,
2897
2926
  findVisibleAgentsInstructions,
2898
2927
  TurnSliceLimitExceededError,
2899
- buildTurnLimitResponse,
2928
+ isTurnExecutionLimitExceededError,
2929
+ assertTurnToolCallLimit,
2930
+ buildTurnErrorResponse,
2900
2931
  persistWithRetry,
2901
2932
  getTurnRecord,
2902
2933
  getTurnRecordForResume,
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  pluginCatalogRuntime
3
- } from "./chunk-FGYWKKTJ.js";
3
+ } from "./chunk-WWXJUURQ.js";
4
4
  import {
5
5
  skillRoots
6
6
  } from "./chunk-TXKUKMVO.js";
7
7
  import {
8
8
  logWarn
9
- } from "./chunk-3ADPXQBL.js";
9
+ } from "./chunk-X76JVHQ4.js";
10
10
 
11
11
  // src/chat/skills.ts
12
12
  import fs from "fs/promises";
@@ -7,23 +7,23 @@ import {
7
7
  import {
8
8
  formatProviderLabel,
9
9
  startOAuthFlow
10
- } from "./chunk-SSR6YBWW.js";
10
+ } from "./chunk-ENWIHU54.js";
11
11
  import {
12
12
  abandonReplacedPendingAuth,
13
13
  canReusePendingAuthLink
14
- } from "./chunk-7XO7PTZE.js";
14
+ } from "./chunk-G35QGPO2.js";
15
15
  import {
16
16
  recordAuthorizationRequested
17
- } from "./chunk-VF3EDS7P.js";
17
+ } from "./chunk-OEQOAONV.js";
18
18
  import {
19
19
  AGENT_INVOCATION_MAILBOX_STATUSES
20
- } from "./chunk-IBO4YFFZ.js";
20
+ } from "./chunk-XLWZRHX5.js";
21
21
  import {
22
22
  TURN_REASONING_LEVELS
23
23
  } from "./chunk-D4YV5TDV.js";
24
24
  import {
25
25
  pluginCatalogRuntime
26
- } from "./chunk-FGYWKKTJ.js";
26
+ } from "./chunk-WWXJUURQ.js";
27
27
  import {
28
28
  credentialContextSchema
29
29
  } from "./chunk-CEMMLV5L.js";
@@ -302,8 +302,7 @@ var createAgentInvocationSchema = z.object({
302
302
  idempotencyKey: exactStringSchema,
303
303
  input: exactStringSchema,
304
304
  parentConversationId: exactStringSchema,
305
- reasoningLevel: z.enum(TURN_REASONING_LEVELS).optional(),
306
- source: sourceSchema
305
+ reasoningLevel: z.enum(TURN_REASONING_LEVELS).optional()
307
306
  }).strict();
308
307
 
309
308
  export {
@@ -3,10 +3,10 @@ import {
3
3
  } from "./chunk-PDO5BLNM.js";
4
4
  import {
5
5
  botConfig
6
- } from "./chunk-4Z7B5WVV.js";
6
+ } from "./chunk-U76RWMFR.js";
7
7
  import {
8
8
  logWarn
9
- } from "./chunk-3ADPXQBL.js";
9
+ } from "./chunk-X76JVHQ4.js";
10
10
 
11
11
  // src/chat/conversations/structured-events.ts
12
12
  import {
@@ -174,6 +174,26 @@ function getComponentTotal(usage) {
174
174
  }
175
175
  return total;
176
176
  }
177
+ function agentTurnCostUsd(usage) {
178
+ if (!usage?.cost) return void 0;
179
+ const total = getFiniteCost(usage.cost.total);
180
+ if (total !== void 0) return total;
181
+ let componentTotal = 0;
182
+ let hasComponent = false;
183
+ for (const field of COST_COMPONENT_FIELDS) {
184
+ const value = getFiniteCost(usage.cost[field]);
185
+ if (value === void 0) continue;
186
+ hasComponent = true;
187
+ componentTotal = addCost(componentTotal, value);
188
+ }
189
+ return hasComponent ? componentTotal : void 0;
190
+ }
191
+ function agentTurnTotalTokens(usage) {
192
+ if (!usage) return void 0;
193
+ const componentTotal = getComponentTotal(usage);
194
+ if (componentTotal !== void 0) return componentTotal;
195
+ return getFiniteCount(usage.totalTokens);
196
+ }
177
197
  function addAgentTurnUsage(...usages) {
178
198
  const components = {};
179
199
  let componentTotal;
@@ -307,5 +327,7 @@ export {
307
327
  ToolInputError,
308
328
  agentTurnUsageSchema,
309
329
  hasAgentTurnUsage,
330
+ agentTurnCostUsd,
331
+ agentTurnTotalTokens,
310
332
  addAgentTurnUsage
311
333
  };
@@ -12,7 +12,7 @@ import {
12
12
  logInfo,
13
13
  logWarn,
14
14
  setSpanAttributes
15
- } from "./chunk-3ADPXQBL.js";
15
+ } from "./chunk-X76JVHQ4.js";
16
16
 
17
17
  // src/chat/plugins/manifest.ts
18
18
  import { z } from "zod";