@sentry/junior 0.94.0 → 0.96.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 (127) hide show
  1. package/dist/{agent-hooks-ZG7IDOIN.js → agent-hooks-5URSMY3O.js} +10 -11
  2. package/dist/api/people/list.js +8 -8
  3. package/dist/api/people/profile.js +8 -8
  4. package/dist/api/people/shared.d.ts +2 -2
  5. package/dist/api-reference.d.ts +2 -2
  6. package/dist/app.js +434 -199
  7. package/dist/{catalog-runtime-NZHMSMYC.js → catalog-runtime-MSMAYYIK.js} +4 -4
  8. package/dist/chat/advisor-request.d.ts +4 -0
  9. package/dist/chat/agent/request.d.ts +2 -0
  10. package/dist/chat/agent/resume.d.ts +2 -0
  11. package/dist/chat/conversations/history.d.ts +128 -0
  12. package/dist/chat/conversations/legacy-import.d.ts +38 -0
  13. package/dist/chat/conversations/messages.d.ts +39 -0
  14. package/dist/chat/conversations/projection.d.ts +94 -0
  15. package/dist/chat/conversations/retention.d.ts +36 -0
  16. package/dist/chat/conversations/sql/conversation-row.d.ts +14 -0
  17. package/dist/chat/conversations/sql/history.d.ts +4 -0
  18. package/dist/chat/conversations/sql/legacy-history-import.d.ts +55 -0
  19. package/dist/chat/conversations/sql/messages.d.ts +4 -0
  20. package/dist/chat/conversations/sql/migrations.d.ts +14 -3
  21. package/dist/chat/conversations/sql/purge.d.ts +53 -0
  22. package/dist/chat/conversations/sql/store.d.ts +7 -2
  23. package/dist/chat/conversations/store.d.ts +19 -0
  24. package/dist/chat/conversations/visible-compactions.d.ts +11 -0
  25. package/dist/chat/conversations/visible-messages.d.ts +47 -0
  26. package/dist/chat/db.d.ts +12 -1
  27. package/dist/chat/identities/sql.d.ts +1 -1
  28. package/dist/chat/logging.d.ts +4 -3
  29. package/dist/chat/plugins/auth/oauth-request.d.ts +2 -0
  30. package/dist/chat/resource-events/notification.d.ts +2 -0
  31. package/dist/chat/resource-events/store.d.ts +2 -1
  32. package/dist/chat/runtime/agent-run-outcome.d.ts +3 -0
  33. package/dist/chat/runtime/reply-executor.d.ts +8 -0
  34. package/dist/chat/runtime/thread-state.d.ts +2 -0
  35. package/dist/chat/sandbox/resources.d.ts +4 -0
  36. package/dist/chat/sentry.d.ts +1 -1
  37. package/dist/chat/services/mcp-auth-orchestration.d.ts +8 -0
  38. package/dist/chat/services/plugin-auth-orchestration.d.ts +12 -0
  39. package/dist/chat/services/turn-session-record.d.ts +14 -2
  40. package/dist/chat/sleep.d.ts +2 -0
  41. package/dist/chat/state/conversation.d.ts +7 -4
  42. package/dist/chat/state/session-log.d.ts +23 -1
  43. package/dist/chat/state/turn-session.d.ts +9 -1
  44. package/dist/chat/tool-support/private-trace-result.d.ts +4 -0
  45. package/dist/chat/tool-support/zod-tool.d.ts +1 -0
  46. package/dist/chat/tools/advisor/tool.d.ts +9 -4
  47. package/dist/chat/tools/definition.d.ts +2 -0
  48. package/dist/chat/tools/execution/tool-error-handler.d.ts +2 -2
  49. package/dist/chat/tools/system-time.d.ts +8 -0
  50. package/dist/chat/usage.d.ts +27 -13
  51. package/dist/chat/xml.d.ts +2 -0
  52. package/dist/{chunk-TNUUATT7.js → chunk-2NAZZPPS.js} +2 -2
  53. package/dist/{chunk-NYWPISSO.js → chunk-2XXEKR44.js} +1 -1
  54. package/dist/chunk-5C6XTTFI.js +1037 -0
  55. package/dist/{chunk-3DA7X2U3.js → chunk-6GWA276C.js} +15 -0
  56. package/dist/{chunk-LFLTJQVR.js → chunk-7FBGKXPE.js} +4 -0
  57. package/dist/{chunk-LNCREA5Z.js → chunk-AAZXTVJT.js} +4 -128
  58. package/dist/{chunk-GHGPTPBL.js → chunk-B7PUBQQM.js} +1 -1
  59. package/dist/{chunk-6H4PP63X.js → chunk-BYZWPRJA.js} +24 -14
  60. package/dist/chunk-CM5EZD5F.js +17 -0
  61. package/dist/{chunk-G3E7SCME.js → chunk-CZEX6KIQ.js} +23 -0
  62. package/dist/{chunk-YJ4OPVNA.js → chunk-DZENG5ML.js} +1 -1
  63. package/dist/{chunk-QGEWC27H.js → chunk-GQ3GK22G.js} +5 -7
  64. package/dist/{chunk-YYBX2BD5.js → chunk-GY34VGP5.js} +1 -1
  65. package/dist/{chunk-S6QKIGRM.js → chunk-I35CTGPO.js} +71 -29
  66. package/dist/{chunk-KRMANDHI.js → chunk-IYM2SIVG.js} +1489 -355
  67. package/dist/{chunk-BTH37NCU.js → chunk-L7CDEIVJ.js} +12 -4
  68. package/dist/chunk-MNTINMWR.js +865 -0
  69. package/dist/{chunk-MAVOJ54A.js → chunk-P3YFQLEN.js} +25 -388
  70. package/dist/{chunk-YTNPU7I2.js → chunk-PMNN6ST4.js} +2 -2
  71. package/dist/{chunk-PFXC67GJ.js → chunk-RAIB6WSG.js} +6 -80
  72. package/dist/{chunk-NFXSLTYG.js → chunk-RITD7E5L.js} +864 -62
  73. package/dist/{chunk-UUB3D2XI.js → chunk-S5KZ5LPG.js} +8 -10
  74. package/dist/{chunk-HDNWZMUN.js → chunk-UKHVMPX5.js} +112 -103
  75. package/dist/chunk-WM6KHPBQ.js +48 -0
  76. package/dist/{chunk-MC4ZZE4Q.js → chunk-YDT7SNCN.js} +1 -1
  77. package/dist/{chunk-NAPITCZ6.js → chunk-YDVEH3SB.js} +251 -6
  78. package/dist/cli/chat.js +25 -24
  79. package/dist/cli/check.js +5 -5
  80. package/dist/cli/main.js +1 -1
  81. package/dist/cli/plugins.js +12 -13
  82. package/dist/cli/snapshot-warmup.js +8 -9
  83. package/dist/cli/upgrade.js +79 -18
  84. package/dist/db/schema/agent-steps.d.ts +134 -0
  85. package/dist/db/schema/conversation-messages.d.ts +153 -0
  86. package/dist/{chat/conversations/sql → db}/schema/conversations.d.ts +34 -0
  87. package/dist/{chat/conversations/sql → db}/schema.d.ts +319 -8
  88. package/dist/db-2D6RMG67.js +24 -0
  89. package/dist/deployment.d.ts +2 -0
  90. package/dist/handlers/retention.d.ts +6 -0
  91. package/dist/instrumentation.js +17 -4
  92. package/dist/legacy-import-VZ2MEGP7.js +17 -0
  93. package/dist/nitro.js +14 -4
  94. package/dist/reporting/conversations/activity.d.ts +40 -0
  95. package/dist/reporting/conversations/context.d.ts +8 -0
  96. package/dist/reporting/conversations/details.d.ts +6 -0
  97. package/dist/reporting/conversations/index.d.ts +4 -0
  98. package/dist/reporting/conversations/shared.d.ts +9 -0
  99. package/dist/reporting/conversations/statistics.d.ts +4 -0
  100. package/dist/reporting/conversations/summaries.d.ts +20 -0
  101. package/dist/reporting/conversations/transcript.d.ts +28 -0
  102. package/dist/reporting/conversations/types.d.ts +191 -0
  103. package/dist/reporting/conversations.d.ts +1 -178
  104. package/dist/reporting.d.ts +5 -4
  105. package/dist/reporting.js +703 -837
  106. package/dist/{runner-XAZPJNAQ.js → runner-JZBRQP4F.js} +36 -42
  107. package/dist/{sentry-EGFOV3DH.js → sentry-JMWTS32N.js} +11 -1
  108. package/dist/{validation-KYAWETI4.js → validation-6XOOQGME.js} +5 -5
  109. package/migrations/README.md +32 -0
  110. package/migrations/meta/0000_snapshot.json +978 -0
  111. package/migrations/meta/_journal.json +13 -0
  112. package/package.json +10 -7
  113. package/dist/chat/sql/schema.d.ts +0 -1049
  114. package/dist/chat/state/conversation-details.d.ts +0 -47
  115. package/dist/chunk-7STN2ZSK.js +0 -250
  116. package/dist/chunk-LE5ANBUZ.js +0 -1040
  117. package/dist/chunk-QL66APYJ.js +0 -1377
  118. package/dist/db-YDN6AFJH.js +0 -18
  119. /package/dist/{chat/sql → db}/db.d.ts +0 -0
  120. /package/dist/{chat/sql → db}/executor.d.ts +0 -0
  121. /package/dist/{chat/sql → db}/neon.d.ts +0 -0
  122. /package/dist/{chat/sql → db}/postgres.d.ts +0 -0
  123. /package/dist/{chat/conversations/sql → db}/schema/destinations.d.ts +0 -0
  124. /package/dist/{chat/conversations/sql → db}/schema/identities.d.ts +0 -0
  125. /package/dist/{chat/conversations/sql → db}/schema/migrations.d.ts +0 -0
  126. /package/dist/{chat/conversations/sql → db}/schema/timestamps.d.ts +0 -0
  127. /package/dist/{chat/conversations/sql → db}/schema/users.d.ts +0 -0
@@ -1,19 +1,20 @@
1
1
  import {
2
2
  createPluginLogger,
3
3
  createPluginState
4
- } from "./chunk-TNUUATT7.js";
4
+ } from "./chunk-2NAZZPPS.js";
5
5
  import {
6
- SANDBOX_WORKSPACE_ROOT
7
- } from "./chunk-G3E7SCME.js";
6
+ SANDBOX_WORKSPACE_ROOT,
7
+ sleep
8
+ } from "./chunk-CZEX6KIQ.js";
8
9
  import {
9
10
  getDb
10
- } from "./chunk-NFXSLTYG.js";
11
+ } from "./chunk-RITD7E5L.js";
11
12
  import {
12
13
  botConfig,
13
14
  completeObject,
14
15
  embedTexts,
15
16
  getSlackBotToken
16
- } from "./chunk-NAPITCZ6.js";
17
+ } from "./chunk-YDVEH3SB.js";
17
18
  import {
18
19
  isActorUserId,
19
20
  logInfo,
@@ -22,12 +23,12 @@ import {
22
23
  setSpanAttributes,
23
24
  setSpanStatus,
24
25
  withSpan
25
- } from "./chunk-S6QKIGRM.js";
26
+ } from "./chunk-I35CTGPO.js";
26
27
  import {
27
28
  parseSlackChannelReferenceId,
28
29
  parseSlackMessageTs,
29
30
  parseSlackTeamId
30
- } from "./chunk-LFLTJQVR.js";
31
+ } from "./chunk-7FBGKXPE.js";
31
32
 
32
33
  // src/chat/plugins/agent-hooks.ts
33
34
  import { promptMessageSchema } from "@sentry/junior-plugin-api";
@@ -314,9 +315,6 @@ function mapSlackError(error) {
314
315
  }
315
316
  return new SlackActionError(message, "internal_error", baseOptions);
316
317
  }
317
- function sleep(ms) {
318
- return new Promise((resolve) => setTimeout(resolve, ms));
319
- }
320
318
  var MAX_RETRY_DELAY_MS = 1e4;
321
319
  var MAX_TOTAL_RETRY_DELAY_MS = 2e4;
322
320
  var CONNECTION_ERROR_CODES = /* @__PURE__ */ new Set([
@@ -1,23 +1,28 @@
1
1
  import {
2
- JUNIOR_THREAD_STATE_TTL_MS,
3
2
  buildConversationStatePatch
4
- } from "./chunk-PFXC67GJ.js";
3
+ } from "./chunk-RAIB6WSG.js";
5
4
  import {
6
5
  abandonAgentTurnSessionRecord,
6
+ addAgentTurnUsage,
7
7
  getAgentTurnSessionRecord,
8
8
  upsertAgentTurnSessionRecord
9
- } from "./chunk-QL66APYJ.js";
9
+ } from "./chunk-MNTINMWR.js";
10
10
  import {
11
- getStateAdapter
12
- } from "./chunk-7STN2ZSK.js";
11
+ JUNIOR_THREAD_STATE_TTL_MS,
12
+ persistConversationMessages
13
+ } from "./chunk-5C6XTTFI.js";
14
+ import {
15
+ sleep
16
+ } from "./chunk-CZEX6KIQ.js";
13
17
  import {
14
18
  getPiMessageRole,
19
+ getStateAdapter,
15
20
  trimTrailingAssistantMessages
16
- } from "./chunk-NAPITCZ6.js";
21
+ } from "./chunk-YDVEH3SB.js";
17
22
  import {
18
23
  getActiveTraceId,
19
24
  logException
20
- } from "./chunk-S6QKIGRM.js";
25
+ } from "./chunk-I35CTGPO.js";
21
26
  import {
22
27
  isRecord,
23
28
  toOptionalString
@@ -89,59 +94,22 @@ function markTurnFailed(args) {
89
94
  args.updateConversationStats(args.conversation);
90
95
  }
91
96
 
92
- // src/chat/usage.ts
93
- var COMPONENT_USAGE_FIELDS = [
94
- "inputTokens",
95
- "outputTokens",
96
- "cachedInputTokens",
97
- "cacheCreationTokens"
98
- ];
99
- function hasAgentTurnUsage(usage) {
100
- return Boolean(
101
- usage && Object.values(usage).some(
102
- (value) => typeof value === "number" && Number.isFinite(value)
103
- )
104
- );
105
- }
106
- function getFiniteCount(value) {
107
- return typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.floor(value)) : void 0;
108
- }
109
- function getComponentTotal(usage) {
110
- let total;
111
- for (const field of COMPONENT_USAGE_FIELDS) {
112
- const value = getFiniteCount(usage[field]);
113
- if (value === void 0) continue;
114
- total = (total ?? 0) + value;
115
- }
116
- return total;
117
- }
118
- function addAgentTurnUsage(...usages) {
119
- const components = {};
120
- let componentTotal;
121
- let totalOnlyTokens;
122
- for (const usage of usages) {
123
- if (!usage) continue;
124
- const usageComponentTotal = getComponentTotal(usage);
125
- if (usageComponentTotal !== void 0) {
126
- componentTotal = (componentTotal ?? 0) + usageComponentTotal;
127
- for (const field of COMPONENT_USAGE_FIELDS) {
128
- const value = getFiniteCount(usage[field]);
129
- if (value === void 0) continue;
130
- components[field] = (components[field] ?? 0) + value;
97
+ // src/chat/services/persist-retry.ts
98
+ var PERSIST_ATTEMPTS = 3;
99
+ async function persistWithRetry(persist) {
100
+ let lastError;
101
+ for (let attempt = 1; attempt <= PERSIST_ATTEMPTS; attempt += 1) {
102
+ try {
103
+ await persist();
104
+ return;
105
+ } catch (error) {
106
+ lastError = error;
107
+ if (attempt < PERSIST_ATTEMPTS) {
108
+ await sleep(attempt * 100);
131
109
  }
132
- continue;
133
- }
134
- const totalTokens = getFiniteCount(usage.totalTokens);
135
- if (totalTokens !== void 0) {
136
- totalOnlyTokens = (totalOnlyTokens ?? 0) + totalTokens;
137
110
  }
138
111
  }
139
- if (totalOnlyTokens !== void 0) {
140
- return {
141
- totalTokens: totalOnlyTokens + (componentTotal ?? 0)
142
- };
143
- }
144
- return hasAgentTurnUsage(components) ? components : void 0;
112
+ throw lastError;
145
113
  }
146
114
 
147
115
  // src/chat/services/turn-session-record.ts
@@ -222,6 +190,8 @@ async function persistRunningSessionRecord(args) {
222
190
  ...args.trailingMessageProvenance ? { trailingMessageProvenance: args.trailingMessageProvenance } : {},
223
191
  ...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
224
192
  ...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
193
+ ...args.modelId ? { modelId: args.modelId } : {},
194
+ ...args.reasoningLevel ? { reasoningLevel: args.reasoningLevel } : {},
225
195
  ...args.actor ?? latestSessionRecord?.actor ? { actor: args.actor ?? latestSessionRecord?.actor } : {},
226
196
  ...getActiveTraceId() ?? latestSessionRecord?.traceId ? { traceId: getActiveTraceId() ?? latestSessionRecord?.traceId } : {},
227
197
  ...(args.turnStartMessageIndex ?? latestSessionRecord?.turnStartMessageIndex) !== void 0 ? {
@@ -243,55 +213,54 @@ async function persistRunningSessionRecord(args) {
243
213
  }
244
214
  }
245
215
  async function persistCompletedSessionRecord(args) {
246
- let sliceId = args.sliceId;
247
- try {
248
- const latestSessionRecord = await getAgentTurnSessionRecord(
216
+ let latestSessionRecord;
217
+ await persistWithRetry(async () => {
218
+ latestSessionRecord = await getAgentTurnSessionRecord(
249
219
  args.conversationId,
250
220
  args.sessionId
251
221
  );
252
- sliceId = sliceId ?? latestSessionRecord?.sliceId;
253
- if (sliceId === void 0) {
254
- throw new Error(
255
- "Completed session record requires a slice id from the caller or the latest stored record"
256
- );
257
- }
258
- await upsertAgentTurnSessionRecord({
259
- ...args.channelName ?? latestSessionRecord?.channelName ? { channelName: args.channelName ?? latestSessionRecord?.channelName } : {},
260
- conversationId: args.conversationId,
261
- cumulativeDurationMs: addDurationMs(
262
- latestSessionRecord?.cumulativeDurationMs,
263
- args.currentDurationMs
264
- ),
265
- cumulativeUsage: addAgentTurnUsage(
266
- latestSessionRecord?.cumulativeUsage,
267
- args.currentUsage
268
- ),
269
- ...args.destination ?? latestSessionRecord?.destination ? { destination: args.destination ?? latestSessionRecord?.destination } : {},
270
- ...args.source ?? latestSessionRecord?.source ? { source: args.source ?? latestSessionRecord?.source } : {},
271
- ...args.destinationVisibility ? { destinationVisibility: args.destinationVisibility } : {},
272
- sessionId: args.sessionId,
273
- sliceId,
274
- state: "completed",
275
- piMessages: args.allMessages,
276
- ...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
277
- ...args.loadedSkillNames ?? latestSessionRecord?.loadedSkillNames ? {
278
- loadedSkillNames: args.loadedSkillNames ?? latestSessionRecord?.loadedSkillNames
279
- } : {},
280
- ...args.actor ?? latestSessionRecord?.actor ? { actor: args.actor ?? latestSessionRecord?.actor } : {},
281
- ...getActiveTraceId() ?? latestSessionRecord?.traceId ? { traceId: getActiveTraceId() ?? latestSessionRecord?.traceId } : {},
282
- ...(args.turnStartMessageIndex ?? latestSessionRecord?.turnStartMessageIndex) !== void 0 ? {
283
- turnStartMessageIndex: args.turnStartMessageIndex ?? latestSessionRecord?.turnStartMessageIndex
284
- } : {}
285
- });
286
- } catch (recordError) {
287
- logSessionRecordError(
288
- recordError,
289
- "agent_turn_completed_session_record_failed",
290
- args,
291
- sliceId !== void 0 ? { "app.ai.resume_slice_id": sliceId } : {},
292
- "Failed to persist completed turn session record"
222
+ });
223
+ const sliceId = args.sliceId ?? latestSessionRecord?.sliceId;
224
+ if (sliceId === void 0) {
225
+ throw new Error(
226
+ "Completed session record requires a slice id from the caller or the latest stored record"
293
227
  );
294
228
  }
229
+ const modelId = latestSessionRecord?.modelId ?? args.modelId ?? args.logContext.modelId;
230
+ const reasoningLevel = args.reasoningLevel ?? latestSessionRecord?.reasoningLevel;
231
+ const target = {
232
+ ...args.channelName ?? latestSessionRecord?.channelName ? { channelName: args.channelName ?? latestSessionRecord?.channelName } : {},
233
+ conversationId: args.conversationId,
234
+ cumulativeDurationMs: addDurationMs(
235
+ latestSessionRecord?.cumulativeDurationMs,
236
+ args.currentDurationMs
237
+ ),
238
+ cumulativeUsage: addAgentTurnUsage(
239
+ latestSessionRecord?.cumulativeUsage,
240
+ args.currentUsage
241
+ ),
242
+ ...args.destination ?? latestSessionRecord?.destination ? { destination: args.destination ?? latestSessionRecord?.destination } : {},
243
+ ...args.source ?? latestSessionRecord?.source ? { source: args.source ?? latestSessionRecord?.source } : {},
244
+ ...args.destinationVisibility ? { destinationVisibility: args.destinationVisibility } : {},
245
+ sessionId: args.sessionId,
246
+ sliceId,
247
+ state: "completed",
248
+ piMessages: args.allMessages,
249
+ ...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
250
+ ...args.loadedSkillNames ?? latestSessionRecord?.loadedSkillNames ? {
251
+ loadedSkillNames: args.loadedSkillNames ?? latestSessionRecord?.loadedSkillNames
252
+ } : {},
253
+ ...modelId ? { modelId } : {},
254
+ ...reasoningLevel ? { reasoningLevel } : {},
255
+ ...args.actor ?? latestSessionRecord?.actor ? { actor: args.actor ?? latestSessionRecord?.actor } : {},
256
+ ...getActiveTraceId() ?? latestSessionRecord?.traceId ? { traceId: getActiveTraceId() ?? latestSessionRecord?.traceId } : {},
257
+ ...(args.turnStartMessageIndex ?? latestSessionRecord?.turnStartMessageIndex) !== void 0 ? {
258
+ turnStartMessageIndex: args.turnStartMessageIndex ?? latestSessionRecord?.turnStartMessageIndex
259
+ } : {}
260
+ };
261
+ await persistWithRetry(async () => {
262
+ await upsertAgentTurnSessionRecord(target);
263
+ });
295
264
  }
296
265
  async function completeDeliveredTurn(args) {
297
266
  await persistCompletedSessionRecord({
@@ -307,7 +276,9 @@ async function completeDeliveredTurn(args) {
307
276
  allMessages: args.messages,
308
277
  loadedSkillNames: args.loadedSkillNames,
309
278
  logContext: args.logContext,
279
+ modelId: args.logContext.modelId,
310
280
  actor: args.actor,
281
+ reasoningLevel: args.reasoningLevel,
311
282
  surface: args.surface,
312
283
  turnStartMessageIndex: args.turnStartMessageIndex
313
284
  });
@@ -345,6 +316,10 @@ async function persistAuthPauseSessionRecord(args) {
345
316
  piMessages,
346
317
  ...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
347
318
  ...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
319
+ ...args.modelId ?? latestSessionRecord?.modelId ? { modelId: args.modelId ?? latestSessionRecord?.modelId } : {},
320
+ ...args.reasoningLevel ?? latestSessionRecord?.reasoningLevel ? {
321
+ reasoningLevel: args.reasoningLevel ?? latestSessionRecord?.reasoningLevel
322
+ } : {},
348
323
  resumeReason: "auth",
349
324
  resumedFromSliceId: args.currentSliceId,
350
325
  errorMessage: args.errorMessage,
@@ -405,6 +380,10 @@ async function persistTimeoutSessionRecord(args) {
405
380
  piMessages,
406
381
  ...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
407
382
  ...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
383
+ ...args.modelId ?? latestSessionRecord?.modelId ? { modelId: args.modelId ?? latestSessionRecord?.modelId } : {},
384
+ ...args.reasoningLevel ?? latestSessionRecord?.reasoningLevel ? {
385
+ reasoningLevel: args.reasoningLevel ?? latestSessionRecord?.reasoningLevel
386
+ } : {},
408
387
  resumeReason: "timeout",
409
388
  resumedFromSliceId: latestSessionRecord?.resumedFromSliceId,
410
389
  errorMessage: `Agent continuation exceeded slice limit (${AGENT_CONTINUE_MAX_SLICES})`,
@@ -425,6 +404,10 @@ async function persistTimeoutSessionRecord(args) {
425
404
  piMessages,
426
405
  ...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
427
406
  ...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
407
+ ...args.modelId ?? latestSessionRecord?.modelId ? { modelId: args.modelId ?? latestSessionRecord?.modelId } : {},
408
+ ...args.reasoningLevel ?? latestSessionRecord?.reasoningLevel ? {
409
+ reasoningLevel: args.reasoningLevel ?? latestSessionRecord?.reasoningLevel
410
+ } : {},
428
411
  resumeReason: "timeout",
429
412
  resumedFromSliceId: args.currentSliceId,
430
413
  errorMessage: args.errorMessage,
@@ -477,6 +460,10 @@ async function persistYieldSessionRecord(args) {
477
460
  piMessages,
478
461
  ...args.surface ?? latestSessionRecord?.surface ? { surface: args.surface ?? latestSessionRecord?.surface } : {},
479
462
  ...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
463
+ ...args.modelId ?? latestSessionRecord?.modelId ? { modelId: args.modelId ?? latestSessionRecord?.modelId } : {},
464
+ ...args.reasoningLevel ?? latestSessionRecord?.reasoningLevel ? {
465
+ reasoningLevel: args.reasoningLevel ?? latestSessionRecord?.reasoningLevel
466
+ } : {},
480
467
  resumeReason: "yield",
481
468
  resumedFromSliceId: latestSessionRecord?.resumedFromSliceId,
482
469
  errorMessage: args.errorMessage,
@@ -791,6 +778,15 @@ function getPersistedSandboxState(state) {
791
778
  };
792
779
  }
793
780
  async function persistThreadState(thread, patch) {
781
+ if (patch.conversation) {
782
+ await persistConversationMessages({
783
+ conversation: patch.conversation,
784
+ conversationId: toOptionalString(thread.id) ?? toOptionalString(thread.runId)
785
+ });
786
+ }
787
+ await persistThreadRuntimeState(thread, patch);
788
+ }
789
+ async function persistThreadRuntimeState(thread, patch) {
794
790
  const payload = buildThreadStatePayload(patch);
795
791
  if (Object.keys(payload).length === 0) {
796
792
  return;
@@ -812,6 +808,12 @@ async function getPersistedChannelState(channelId) {
812
808
  ) ?? {};
813
809
  }
814
810
  async function persistThreadStateById(threadId, patch) {
811
+ if (patch.conversation) {
812
+ await persistConversationMessages({
813
+ conversation: patch.conversation,
814
+ conversationId: threadId
815
+ });
816
+ }
815
817
  const payload = buildThreadStatePayload(patch);
816
818
  if (Object.keys(payload).length === 0) {
817
819
  return;
@@ -854,6 +856,12 @@ function getChannelConfigurationServiceById(channelId) {
854
856
  });
855
857
  }
856
858
 
859
+ // src/chat/interruption-marker.ts
860
+ var INTERRUPTED_MARKER = "\n\n[Response interrupted before completion]";
861
+ function getInterruptionMarker() {
862
+ return INTERRUPTED_MARKER;
863
+ }
864
+
857
865
  // src/chat/services/pending-auth.ts
858
866
  var AUTH_LINK_REUSE_WINDOW_MS = 10 * 60 * 1e3;
859
867
  var NON_REQUEST_SKIPPED_REASON_PREFIXES = [
@@ -931,8 +939,7 @@ export {
931
939
  markTurnClosed,
932
940
  markTurnCompleted,
933
941
  markTurnFailed,
934
- hasAgentTurnUsage,
935
- addAgentTurnUsage,
942
+ persistWithRetry,
936
943
  loadTurnSessionRecord,
937
944
  persistRunningSessionRecord,
938
945
  persistCompletedSessionRecord,
@@ -940,6 +947,7 @@ export {
940
947
  persistAuthPauseSessionRecord,
941
948
  persistTimeoutSessionRecord,
942
949
  persistYieldSessionRecord,
950
+ getInterruptionMarker,
943
951
  canReusePendingAuthLink,
944
952
  getConversationPendingAuth,
945
953
  clearPendingAuth,
@@ -949,6 +957,7 @@ export {
949
957
  mergeArtifactsState,
950
958
  getPersistedSandboxState,
951
959
  persistThreadState,
960
+ persistThreadRuntimeState,
952
961
  getPersistedThreadState,
953
962
  persistThreadStateById,
954
963
  getChannelConfigurationService,
@@ -0,0 +1,48 @@
1
+ import {
2
+ escapeXml,
3
+ unescapeXml
4
+ } from "./chunk-YDVEH3SB.js";
5
+
6
+ // src/chat/advisor-request.ts
7
+ var TASK_OPEN = "<advisor-task>\n";
8
+ var TASK_CLOSE = "\n</advisor-task>";
9
+ var CONTEXT_OPEN = "<executor-context>\n";
10
+ var CONTEXT_CLOSE = "\n</executor-context>";
11
+ function renderAdvisorRequest(question, context) {
12
+ return [
13
+ TASK_OPEN,
14
+ escapeXml(question),
15
+ TASK_CLOSE,
16
+ "\n\n",
17
+ CONTEXT_OPEN,
18
+ escapeXml(context),
19
+ CONTEXT_CLOSE
20
+ ].join("");
21
+ }
22
+ function unwrapAdvisorRequest(text) {
23
+ if (!text.startsWith(TASK_OPEN) || !text.endsWith(CONTEXT_CLOSE)) {
24
+ return void 0;
25
+ }
26
+ const taskEnd = text.indexOf(TASK_CLOSE, TASK_OPEN.length);
27
+ if (taskEnd < 0) {
28
+ return void 0;
29
+ }
30
+ const contextStart = taskEnd + TASK_CLOSE.length + 2;
31
+ if (!text.startsWith(CONTEXT_OPEN, contextStart)) {
32
+ return void 0;
33
+ }
34
+ const task = text.slice(TASK_OPEN.length, taskEnd);
35
+ const context = text.slice(
36
+ contextStart + CONTEXT_OPEN.length,
37
+ -CONTEXT_CLOSE.length
38
+ );
39
+ return `${unescapeXml(task)}
40
+
41
+ Executor context:
42
+ ${unescapeXml(context)}`;
43
+ }
44
+
45
+ export {
46
+ renderAdvisorRequest,
47
+ unwrapAdvisorRequest
48
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  pluginCatalogRuntime
3
- } from "./chunk-BTH37NCU.js";
3
+ } from "./chunk-L7CDEIVJ.js";
4
4
 
5
5
  // src/chat/plugins/validation.ts
6
6
  import { isDeepStrictEqual } from "util";