@sentry/junior 0.100.0 → 0.102.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 (80) hide show
  1. package/README.md +0 -1
  2. package/dist/{agent-hooks-V6KU7PQN.js → agent-hooks-I4I2DHSW.js} +7 -7
  3. package/dist/api/conversations/schema.d.ts +2 -2
  4. package/dist/api/people/schema.d.ts +13 -0
  5. package/dist/api/schema.d.ts +1 -1
  6. package/dist/api/schema.js +3 -3
  7. package/dist/api.js +16 -16
  8. package/dist/app.js +165 -104
  9. package/dist/{catalog-runtime-PFHVMHDR.js → catalog-runtime-5CVM2DOF.js} +2 -2
  10. package/dist/chat/agent/prompt.d.ts +1 -1
  11. package/dist/chat/agent/request.d.ts +1 -1
  12. package/dist/chat/agent-dispatch/validation.d.ts +1 -1
  13. package/dist/chat/conversation-privacy.d.ts +2 -6
  14. package/dist/chat/conversations/store.d.ts +1 -1
  15. package/dist/chat/credentials/context.d.ts +33 -6
  16. package/dist/chat/credentials/subject.d.ts +15 -1
  17. package/dist/chat/logging.d.ts +4 -2
  18. package/dist/chat/mcp/auth-store.d.ts +1 -0
  19. package/dist/chat/mcp/client.d.ts +2 -0
  20. package/dist/chat/mcp/oauth-provider.d.ts +4 -1
  21. package/dist/chat/mcp/oauth.d.ts +3 -1
  22. package/dist/chat/mcp/tool-manager.d.ts +3 -1
  23. package/dist/chat/sandbox/egress/schemas.d.ts +13 -2
  24. package/dist/chat/services/context-compaction-marker.d.ts +8 -0
  25. package/dist/chat/services/mcp-auth-orchestration.d.ts +1 -1
  26. package/dist/chat/services/pending-auth.d.ts +17 -9
  27. package/dist/chat/state/conversation.d.ts +7 -3
  28. package/dist/{chunk-XJA7BPHS.js → chunk-3OABPOHR.js} +3 -3
  29. package/dist/{chunk-2T7DCRAW.js → chunk-3UK5DFKW.js} +3 -3
  30. package/dist/{chunk-IDZBM3NW.js → chunk-4YN2ZXKB.js} +10 -2
  31. package/dist/{chunk-NSOCZGOH.js → chunk-5K4N73TP.js} +9 -11
  32. package/dist/{chunk-LMJPRYHP.js → chunk-77LHNQK4.js} +32 -8
  33. package/dist/{chunk-I35CTGPO.js → chunk-AEWZ7F65.js} +41 -17
  34. package/dist/{chunk-IQIBZXGB.js → chunk-B5QS4AVO.js} +2 -2
  35. package/dist/{chunk-XSBIISXS.js → chunk-DTUSCR2Y.js} +9 -12
  36. package/dist/{chunk-GEUUJRQF.js → chunk-E4EMFKGB.js} +1 -1
  37. package/dist/{chunk-VVIXK2BX.js → chunk-EMUZSROX.js} +2 -2
  38. package/dist/{chunk-IVXL57YF.js → chunk-EOB77KME.js} +4 -4
  39. package/dist/{chunk-PGGEOCQY.js → chunk-F4CQEUTP.js} +1 -1
  40. package/dist/{chunk-4AQUWWEM.js → chunk-HNIT4HXU.js} +1 -1
  41. package/dist/{chunk-MM5UFDAC.js → chunk-HYDQULR2.js} +1 -1
  42. package/dist/{chunk-FP5N5OWZ.js → chunk-IQ36I3DF.js} +2 -2
  43. package/dist/{chunk-JSAANELJ.js → chunk-LJB2TLVT.js} +3 -3
  44. package/dist/{chunk-D5KZYS4T.js → chunk-MJSJAHBW.js} +1 -1
  45. package/dist/{chunk-QSBQJ3PA.js → chunk-MR6H67P2.js} +3 -3
  46. package/dist/{chunk-VY7BT4SM.js → chunk-NSP6OGL2.js} +9 -8
  47. package/dist/{chunk-VHRM6GNH.js → chunk-QZGVPPIJ.js} +27 -3
  48. package/dist/{chunk-LVA4I4H7.js → chunk-RT5BUHR5.js} +15 -44
  49. package/dist/{chunk-A7X2FDUO.js → chunk-SHBPSE7A.js} +88 -66
  50. package/dist/{chunk-CM5EZD5F.js → chunk-UIE3R5XU.js} +1 -1
  51. package/dist/{chunk-JPQISMMJ.js → chunk-VSAFV2GI.js} +7 -6
  52. package/dist/{chunk-3ECW2K2O.js → chunk-WR7H7VLJ.js} +2 -2
  53. package/dist/{chunk-TPTJEHUE.js → chunk-X2IPNCB5.js} +61 -25
  54. package/dist/{chunk-6DTVCPLO.js → chunk-XIMUQ4IU.js} +4 -3
  55. package/dist/{chunk-45DMFMY2.js → chunk-ZIX4PNBI.js} +348 -200
  56. package/dist/{chunk-PWC24W5F.js → chunk-ZSHL44IQ.js} +2 -2
  57. package/dist/cli/chat.js +22 -22
  58. package/dist/cli/check.js +3 -3
  59. package/dist/cli/plugins.js +9 -9
  60. package/dist/cli/snapshot-warmup.js +5 -5
  61. package/dist/cli/upgrade.js +203 -14
  62. package/dist/db/postgres-json.d.ts +5 -0
  63. package/dist/{db-RCZB7KNM.js → db-6QP6HY7U.js} +4 -4
  64. package/dist/{detail-LU6COZO6.js → detail-OEIVZYXS.js} +12 -12
  65. package/dist/{detail-5SLCGT6J.js → detail-U6IP2Z4N.js} +8 -8
  66. package/dist/instrumentation.js +2 -2
  67. package/dist/{legacy-import-VCYLWT2V.js → legacy-import-R3BMM2GH.js} +5 -5
  68. package/dist/{list-KHRAWZWU.js → list-AJ6RWBOG.js} +8 -8
  69. package/dist/list-UMZKA5AI.js +121 -0
  70. package/dist/{list-4ALSU6ZW.js → list-Z3CC52CZ.js} +8 -8
  71. package/dist/{plugin-conversations-JANXC4GA.js → plugin-conversations-F3IBVNFX.js} +7 -7
  72. package/dist/{profile-3O3OVENT.js → profile-CQMPFKED.js} +8 -8
  73. package/dist/{runner-BM7D35YW.js → runner-C2ZTIOUD.js} +13 -13
  74. package/dist/{skills-MAZXZ2KE.js → skills-722AXRV5.js} +3 -3
  75. package/dist/{stats-J3YGCYDF.js → stats-ZYFQFCTL.js} +6 -6
  76. package/dist/{subagent-P7HOSMVC.js → subagent-X3ZWJHR4.js} +11 -11
  77. package/dist/{validation-FMEAEKCY.js → validation-EUI2UFRM.js} +3 -3
  78. package/package.json +6 -6
  79. package/dist/api-reference.d.ts +0 -14
  80. package/dist/list-2FI5SFV7.js +0 -80
@@ -70,7 +70,7 @@ var LEGACY_KEY_MAP = {
70
70
  inferredScore: "app.skill.score"
71
71
  };
72
72
  function normalizeGenAiFinishReason(reason) {
73
- return reason === "toolUse" ? "tool_use" : reason;
73
+ return reason === "toolUse" ? "tool_call" : reason;
74
74
  }
75
75
  function summarizeMessageText(text) {
76
76
  const normalized = text.trim().replace(/\s+/g, " ");
@@ -1021,6 +1021,21 @@ function setLogContext(context) {
1021
1021
  function getLogContextAttributes() {
1022
1022
  return contextStorage.getStore() ?? {};
1023
1023
  }
1024
+ function getLogContextAttributesForSpan(op) {
1025
+ const attributes = { ...getLogContextAttributes() };
1026
+ if (op === "gen_ai.invoke_agent" || op === "gen_ai.execute_tool") {
1027
+ delete attributes["gen_ai.request.model"];
1028
+ return attributes;
1029
+ }
1030
+ if (op === "gen_ai.chat" || op === "gen_ai.embeddings") {
1031
+ delete attributes["gen_ai.agent.name"];
1032
+ delete attributes["gen_ai.request.model"];
1033
+ return attributes;
1034
+ }
1035
+ delete attributes["gen_ai.agent.name"];
1036
+ delete attributes["gen_ai.request.model"];
1037
+ return attributes;
1038
+ }
1024
1039
  function createLogContextFromRequest(request, context = {}) {
1025
1040
  const url = new URL(request.url);
1026
1041
  return {
@@ -1155,7 +1170,7 @@ async function withContext(context, callback) {
1155
1170
  async function withSpan(name, op, context, callback, attributes = {}) {
1156
1171
  const normalizedAttributes = normalizeSpanAttributes(attributes);
1157
1172
  return withLogContext(context, () => {
1158
- const inheritedAttributes = getLogContextAttributes();
1173
+ const inheritedAttributes = getLogContextAttributesForSpan(op);
1159
1174
  return startSpan(
1160
1175
  {
1161
1176
  name,
@@ -1165,7 +1180,18 @@ async function withSpan(name, op, context, callback, attributes = {}) {
1165
1180
  ...normalizedAttributes
1166
1181
  }
1167
1182
  },
1168
- (span) => callback((attributes2) => setAttributesOnSpan(span, attributes2))
1183
+ async (span) => {
1184
+ try {
1185
+ return await callback(
1186
+ (attributes2) => setAttributesOnSpan(span, attributes2)
1187
+ );
1188
+ } catch (error) {
1189
+ setAttributesOnSpan(span, {
1190
+ "error.type": error instanceof Error ? error.name : typeof error
1191
+ });
1192
+ throw error;
1193
+ }
1194
+ }
1169
1195
  );
1170
1196
  });
1171
1197
  }
@@ -1223,7 +1249,7 @@ var GEN_AI_DEFAULT_MAX_ATTRIBUTE_CHARS = 1e5;
1223
1249
  var GEN_AI_MAX_ARRAY_ITEMS = 50;
1224
1250
  var GEN_AI_MAX_OBJECT_KEYS = 50;
1225
1251
  function truncateGenAiString(value, maxChars) {
1226
- return value.length > maxChars ? `${value.slice(0, maxChars)}...` : value;
1252
+ return value.length > maxChars ? "" : value;
1227
1253
  }
1228
1254
  function sanitizeGenAiValue(value, seen, depth, keyName) {
1229
1255
  if (value === null || value === void 0) {
@@ -1277,7 +1303,7 @@ function serializeGenAiAttribute(value, maxChars = GEN_AI_DEFAULT_MAX_ATTRIBUTE_
1277
1303
  if (!serialized) {
1278
1304
  return void 0;
1279
1305
  }
1280
- return truncateGenAiString(redactSecrets(serialized), maxChars);
1306
+ return truncateGenAiString(redactSecrets(serialized), maxChars) || void 0;
1281
1307
  }
1282
1308
  function asRecord(value) {
1283
1309
  return value && typeof value === "object" ? value : void 0;
@@ -1385,7 +1411,6 @@ function extractGenAiUsageAttributes(...sources) {
1385
1411
  cachedInputTokens,
1386
1412
  cacheCreationTokens,
1387
1413
  reasoningTokens,
1388
- totalTokens,
1389
1414
  cost
1390
1415
  } = extractGenAiUsageSummary(...sources);
1391
1416
  const semanticInputTokens = sumTokenCounts(
@@ -1393,19 +1418,18 @@ function extractGenAiUsageAttributes(...sources) {
1393
1418
  cachedInputTokens,
1394
1419
  cacheCreationTokens
1395
1420
  );
1396
- const semanticTotalTokens = totalTokens ?? sumTokenCounts(semanticInputTokens, outputTokens);
1397
1421
  return {
1398
1422
  ...semanticInputTokens !== void 0 ? { "gen_ai.usage.input_tokens": semanticInputTokens } : {},
1399
1423
  ...outputTokens !== void 0 ? { "gen_ai.usage.output_tokens": outputTokens } : {},
1400
- ...semanticTotalTokens !== void 0 ? { "gen_ai.usage.total_tokens": semanticTotalTokens } : {},
1401
- ...cachedInputTokens !== void 0 ? { "gen_ai.usage.input_tokens.cached": cachedInputTokens } : {},
1402
- ...cacheCreationTokens !== void 0 ? { "gen_ai.usage.input_tokens.cache_write": cacheCreationTokens } : {},
1403
- ...reasoningTokens !== void 0 ? { "app.ai.reasoning_tokens": reasoningTokens } : {},
1404
- ...cost?.input !== void 0 ? { "app.ai.cost.input_usd": cost.input } : {},
1405
- ...cost?.output !== void 0 ? { "app.ai.cost.output_usd": cost.output } : {},
1406
- ...cost?.cacheRead !== void 0 ? { "app.ai.cost.cache_read_usd": cost.cacheRead } : {},
1407
- ...cost?.cacheWrite !== void 0 ? { "app.ai.cost.cache_write_usd": cost.cacheWrite } : {},
1408
- ...cost?.total !== void 0 ? { "app.ai.cost.total_usd": cost.total } : {}
1424
+ // OTel has no monetary cost attributes, so report accounting generically.
1425
+ ...cachedInputTokens !== void 0 ? { "gen_ai.usage.cache_read.input_tokens": cachedInputTokens } : {},
1426
+ ...cacheCreationTokens !== void 0 ? { "gen_ai.usage.cache_creation.input_tokens": cacheCreationTokens } : {},
1427
+ ...reasoningTokens !== void 0 ? { "gen_ai.usage.reasoning.output_tokens": reasoningTokens } : {},
1428
+ ...cost?.input !== void 0 ? { "app.cost.input_usd": cost.input } : {},
1429
+ ...cost?.output !== void 0 ? { "app.cost.output_usd": cost.output } : {},
1430
+ ...cost?.cacheRead !== void 0 ? { "app.cost.cache_read_usd": cost.cacheRead } : {},
1431
+ ...cost?.cacheWrite !== void 0 ? { "app.cost.cache_write_usd": cost.cacheWrite } : {},
1432
+ ...cost?.total !== void 0 ? { "app.cost.total_usd": cost.total } : {}
1409
1433
  };
1410
1434
  }
1411
1435
 
@@ -1581,7 +1605,7 @@ export {
1581
1605
  normalizeGenAiFinishReason,
1582
1606
  summarizeMessageText,
1583
1607
  createChatSdkLogger,
1584
- getLogContextAttributes,
1608
+ getLogContextAttributesForSpan,
1585
1609
  setSentryUser,
1586
1610
  logInfo,
1587
1611
  logWarn,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  ensureLegacyConversationImport
3
- } from "./chunk-JPQISMMJ.js";
3
+ } from "./chunk-VSAFV2GI.js";
4
4
  import {
5
5
  contextProvenance,
6
6
  getAgentStepStore
7
- } from "./chunk-VHRM6GNH.js";
7
+ } from "./chunk-QZGVPPIJ.js";
8
8
 
9
9
  // src/chat/conversations/projection.ts
10
10
  import { isDeepStrictEqual } from "util";
@@ -9,13 +9,13 @@ import {
9
9
  getPersistedThreadState,
10
10
  markTurnCompleted,
11
11
  mergeArtifactsState
12
- } from "./chunk-NSOCZGOH.js";
12
+ } from "./chunk-5K4N73TP.js";
13
13
  import {
14
14
  coerceThreadConversationState
15
- } from "./chunk-6DTVCPLO.js";
15
+ } from "./chunk-XIMUQ4IU.js";
16
16
  import {
17
17
  getAgentTurnSessionRecord
18
- } from "./chunk-IVXL57YF.js";
18
+ } from "./chunk-EOB77KME.js";
19
19
  import {
20
20
  generateConversationId,
21
21
  hydrateConversationMessages,
@@ -23,21 +23,20 @@ import {
23
23
  normalizeConversationText,
24
24
  updateConversationStats,
25
25
  upsertConversationMessage
26
- } from "./chunk-JPQISMMJ.js";
26
+ } from "./chunk-VSAFV2GI.js";
27
27
  import {
28
28
  createPluginEmbedder,
29
29
  createPluginModel,
30
30
  getPlugins
31
- } from "./chunk-TPTJEHUE.js";
31
+ } from "./chunk-X2IPNCB5.js";
32
32
  import {
33
33
  createPluginLogger,
34
34
  createPluginState
35
- } from "./chunk-PWC24W5F.js";
35
+ } from "./chunk-ZSHL44IQ.js";
36
36
  import {
37
37
  getDb
38
- } from "./chunk-VHRM6GNH.js";
38
+ } from "./chunk-QZGVPPIJ.js";
39
39
  import {
40
- GEN_AI_PROVIDER_NAME,
41
40
  botConfig,
42
41
  getPiMessageRole,
43
42
  getStateAdapter,
@@ -46,10 +45,10 @@ import {
46
45
  isToolResultMessage,
47
46
  normalizeToolNameFromResult,
48
47
  stripRuntimeTurnContext
49
- } from "./chunk-A7X2FDUO.js";
48
+ } from "./chunk-SHBPSE7A.js";
50
49
  import {
51
50
  buildTurnFailureResponse
52
- } from "./chunk-I35CTGPO.js";
51
+ } from "./chunk-AEWZ7F65.js";
53
52
  import {
54
53
  parseSlackMessageTs
55
54
  } from "./chunk-7FBGKXPE.js";
@@ -97,8 +96,6 @@ function getFailureCapture(reply) {
97
96
  }
98
97
  function getAgentTurnDiagnosticsAttributes(reply) {
99
98
  return {
100
- "gen_ai.provider.name": GEN_AI_PROVIDER_NAME,
101
- "gen_ai.operation.name": "invoke_agent",
102
99
  "app.ai.outcome": reply.diagnostics.outcome,
103
100
  "app.ai.assistant_messages": reply.diagnostics.assistantMessageCount,
104
101
  "app.ai.tool_results": reply.diagnostics.toolResultCount,
@@ -3,7 +3,7 @@ import {
3
3
  juniorConversations,
4
4
  juniorIdentities,
5
5
  juniorUsers
6
- } from "./chunk-VHRM6GNH.js";
6
+ } from "./chunk-QZGVPPIJ.js";
7
7
  import {
8
8
  juniorDestinations
9
9
  } from "./chunk-FXFQNHRU.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  normalizeSlackConversationId
3
- } from "./chunk-FP5N5OWZ.js";
3
+ } from "./chunk-IQ36I3DF.js";
4
4
  import {
5
5
  parseSlackThreadId
6
- } from "./chunk-LVA4I4H7.js";
6
+ } from "./chunk-RT5BUHR5.js";
7
7
 
8
8
  // src/chat/slack/conversation-context.ts
9
9
  function normalizeConversationName(type, channelName) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  commitMessages,
3
3
  loadTurnProjection
4
- } from "./chunk-IQIBZXGB.js";
4
+ } from "./chunk-B5QS4AVO.js";
5
5
  import {
6
6
  usageSchema
7
7
  } from "./chunk-PDO5BLNM.js";
@@ -9,13 +9,13 @@ import {
9
9
  getConversationStore,
10
10
  instructionActors,
11
11
  instructionProvenanceFor
12
- } from "./chunk-VHRM6GNH.js";
12
+ } from "./chunk-QZGVPPIJ.js";
13
13
  import {
14
14
  getStateAdapter
15
- } from "./chunk-A7X2FDUO.js";
15
+ } from "./chunk-SHBPSE7A.js";
16
16
  import {
17
17
  toStoredSlackActor
18
- } from "./chunk-I35CTGPO.js";
18
+ } from "./chunk-AEWZ7F65.js";
19
19
 
20
20
  // src/chat/usage.ts
21
21
  var agentTurnUsageSchema = usageSchema;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  juniorConversations
3
- } from "./chunk-VHRM6GNH.js";
3
+ } from "./chunk-QZGVPPIJ.js";
4
4
 
5
5
  // src/api/conversations/aggregate.ts
6
6
  import { sql } from "drizzle-orm";
@@ -2,7 +2,7 @@ import {
2
2
  actorIdentitySchema,
3
3
  conversationStatsItemSchema,
4
4
  conversationSummaryReportSchema
5
- } from "./chunk-MM5UFDAC.js";
5
+ } from "./chunk-HYDQULR2.js";
6
6
  import {
7
7
  juniorDestinationKindSchema
8
8
  } from "./chunk-FXFQNHRU.js";
@@ -131,7 +131,7 @@ var conversationContextEventSchema = z.discriminatedUnion("type", [
131
131
  type: z.literal("model_handoff"),
132
132
  createdAt: z.string(),
133
133
  fromModelId: z.string().optional(),
134
- summary: z.string().optional(),
134
+ message: z.string().optional(),
135
135
  toModelId: z.string(),
136
136
  transcriptIndex: z.number().int().nonnegative()
137
137
  }).strict()
@@ -3,13 +3,13 @@ import {
3
3
  } from "./chunk-4ZNGQH7C.js";
4
4
  import {
5
5
  getSlackBotToken
6
- } from "./chunk-A7X2FDUO.js";
6
+ } from "./chunk-SHBPSE7A.js";
7
7
  import {
8
8
  logWarn,
9
9
  setSpanAttributes,
10
10
  setSpanStatus,
11
11
  withSpan
12
- } from "./chunk-I35CTGPO.js";
12
+ } from "./chunk-AEWZ7F65.js";
13
13
  import {
14
14
  parseSlackChannelReferenceId
15
15
  } from "./chunk-7FBGKXPE.js";
@@ -1,19 +1,19 @@
1
1
  import {
2
2
  formatSlackConversationRedactedLabel,
3
3
  resolveSlackConversationContextFromThreadId
4
- } from "./chunk-VVIXK2BX.js";
4
+ } from "./chunk-EMUZSROX.js";
5
5
  import {
6
6
  getDb,
7
7
  juniorConversations,
8
8
  juniorIdentities
9
- } from "./chunk-VHRM6GNH.js";
9
+ } from "./chunk-QZGVPPIJ.js";
10
10
  import {
11
11
  juniorDestinations
12
12
  } from "./chunk-FXFQNHRU.js";
13
13
  import {
14
14
  parseSlackThreadId,
15
15
  resolveConversationPrivacy
16
- } from "./chunk-LVA4I4H7.js";
16
+ } from "./chunk-RT5BUHR5.js";
17
17
 
18
18
  // src/api/conversations/list.query.ts
19
19
  import { and, asc, desc, eq, isNull } from "drizzle-orm";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  pluginCatalogRuntime
3
- } from "./chunk-LMJPRYHP.js";
3
+ } from "./chunk-77LHNQK4.js";
4
4
 
5
5
  // src/chat/plugins/validation.ts
6
6
  import { isDeepStrictEqual } from "util";
@@ -4,16 +4,16 @@ import {
4
4
  import {
5
5
  conversationAggregateColumns,
6
6
  conversationRangeColumns
7
- } from "./chunk-PGGEOCQY.js";
7
+ } from "./chunk-F4CQEUTP.js";
8
8
  import {
9
9
  activityDays
10
- } from "./chunk-4AQUWWEM.js";
10
+ } from "./chunk-HNIT4HXU.js";
11
11
  import {
12
12
  getDb,
13
13
  juniorConversations,
14
14
  juniorIdentities,
15
15
  juniorUsers
16
- } from "./chunk-VHRM6GNH.js";
16
+ } from "./chunk-QZGVPPIJ.js";
17
17
  import {
18
18
  juniorDestinations
19
19
  } from "./chunk-FXFQNHRU.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  conversationSummaryFromStoredConversation
3
- } from "./chunk-JSAANELJ.js";
3
+ } from "./chunk-LJB2TLVT.js";
4
4
  import {
5
5
  buildSentryConversationUrl,
6
6
  buildSentryTraceUrl
@@ -8,19 +8,19 @@ import {
8
8
  import {
9
9
  loadProjection,
10
10
  projectSteps
11
- } from "./chunk-IQIBZXGB.js";
11
+ } from "./chunk-B5QS4AVO.js";
12
12
  import {
13
13
  getAgentStepStore,
14
14
  getConversationMessageStore
15
- } from "./chunk-VHRM6GNH.js";
15
+ } from "./chunk-QZGVPPIJ.js";
16
16
  import {
17
17
  stripRuntimeTurnContext,
18
18
  unescapeXml,
19
19
  unwrapCurrentInstruction
20
- } from "./chunk-A7X2FDUO.js";
20
+ } from "./chunk-SHBPSE7A.js";
21
21
  import {
22
22
  canExposeConversationPayload
23
- } from "./chunk-LVA4I4H7.js";
23
+ } from "./chunk-RT5BUHR5.js";
24
24
  import {
25
25
  isRecord
26
26
  } from "./chunk-OB42YVAE.js";
@@ -465,10 +465,11 @@ function historyContent(args) {
465
465
  ) : marker?.entry.reason === "handoff" ? summaryIndex(projected, projectedProvenance, [
466
466
  MODEL_HANDOFF_SUMMARY_PREFIX
467
467
  ]) : -1;
468
- const summary = replacementSummaryIndex >= 0 ? summaryAfterPrefix(
468
+ const summary = marker?.entry.reason === "compaction" && replacementSummaryIndex >= 0 ? summaryAfterPrefix(
469
469
  projected[replacementSummaryIndex],
470
- marker?.entry.reason === "handoff" ? [MODEL_HANDOFF_SUMMARY_PREFIX] : COMPACTION_SUMMARY_PREFIXES
470
+ COMPACTION_SUMMARY_PREFIXES
471
471
  ) : void 0;
472
+ const handoffMessage = marker?.entry.reason === "handoff" && replacementSummaryIndex >= 0 ? messageText(projected[replacementSummaryIndex]) || void 0 : void 0;
472
473
  if (marker?.entry.reason === "compaction") {
473
474
  contextEvents.push({
474
475
  type: "context_compacted",
@@ -483,7 +484,7 @@ function historyContent(args) {
483
484
  createdAt: new Date(marker.createdAtMs).toISOString(),
484
485
  ...previousModelId ? { fromModelId: previousModelId } : {},
485
486
  toModelId: marker.entry.modelId,
486
- ...args.canExposePayload && summary ? { summary } : {},
487
+ ...args.canExposePayload && handoffMessage ? { message: handoffMessage } : {},
487
488
  transcriptIndex: messages.length
488
489
  });
489
490
  }
@@ -3,7 +3,7 @@ import {
3
3
  getConnectedStateContext,
4
4
  getStateAdapter,
5
5
  modelProfileSchema
6
- } from "./chunk-A7X2FDUO.js";
6
+ } from "./chunk-SHBPSE7A.js";
7
7
  import {
8
8
  juniorDestinations,
9
9
  timestamptz
@@ -15,7 +15,7 @@ import {
15
15
  import {
16
16
  normalizeIdentityEmail,
17
17
  storedSlackActorSchema
18
- } from "./chunk-I35CTGPO.js";
18
+ } from "./chunk-AEWZ7F65.js";
19
19
 
20
20
  // src/chat/conversations/sql/store.ts
21
21
  import { randomUUID as randomUUID2 } from "crypto";
@@ -1452,6 +1452,29 @@ async function ensureConversationRow(executor, conversationId, atMs) {
1452
1452
  });
1453
1453
  }
1454
1454
 
1455
+ // src/db/postgres-json.ts
1456
+ function sanitizePostgresJson(value) {
1457
+ if (typeof value === "string") {
1458
+ return value.replaceAll("\0", " ");
1459
+ }
1460
+ if (Array.isArray(value)) {
1461
+ return value.map((item) => sanitizePostgresJson(item));
1462
+ }
1463
+ if (value === null || typeof value !== "object") {
1464
+ return value;
1465
+ }
1466
+ const prototype = Object.getPrototypeOf(value);
1467
+ if (prototype !== Object.prototype && prototype !== null) {
1468
+ return value;
1469
+ }
1470
+ return Object.fromEntries(
1471
+ Object.entries(value).map(([key2, item]) => [
1472
+ key2,
1473
+ sanitizePostgresJson(item)
1474
+ ])
1475
+ );
1476
+ }
1477
+
1455
1478
  // src/chat/conversations/sql/history.ts
1456
1479
  function messageRole(entry) {
1457
1480
  if (entry.type !== "pi_message") {
@@ -1468,7 +1491,7 @@ function insertFromStep(conversationId, seq, contextEpoch, step) {
1468
1491
  contextEpoch,
1469
1492
  type,
1470
1493
  role: messageRole(step.entry),
1471
- payload,
1494
+ payload: sanitizePostgresJson(payload),
1472
1495
  createdAt: new Date(step.createdAtMs)
1473
1496
  };
1474
1497
  }
@@ -2033,6 +2056,7 @@ export {
2033
2056
  instructionProvenanceFor,
2034
2057
  contextProvenance,
2035
2058
  agentStepEntrySchema,
2059
+ sanitizePostgresJson,
2036
2060
  createSqlAgentStepStore,
2037
2061
  createSqlConversationMessageStore,
2038
2062
  createJuniorSqlExecutor,
@@ -133,40 +133,6 @@ function getCurrentConversationPrivacy() {
133
133
  function runWithConversationPrivacy(privacy, callback) {
134
134
  return conversationPrivacyStorage.run(privacy, callback);
135
135
  }
136
- function contentMetadata(content) {
137
- if (typeof content === "string") {
138
- return [{ type: "text", chars: content.length }];
139
- }
140
- if (!Array.isArray(content)) {
141
- return { type: typeof content };
142
- }
143
- return content.map((part) => {
144
- if (!part || typeof part !== "object") {
145
- return { type: typeof part };
146
- }
147
- const record = part;
148
- const type = canonicalContentPartType(
149
- typeof record.type === "string" ? record.type : "unknown"
150
- );
151
- return {
152
- type,
153
- ...typeof record.text === "string" ? { chars: record.text.length } : typeof record.thinking === "string" && record.thinking.length > 0 ? { chars: record.thinking.length } : {},
154
- ...typeof record.mimeType === "string" ? { mimeType: record.mimeType } : {},
155
- ...typeof record.mediaType === "string" ? { mediaType: record.mediaType } : {},
156
- ...typeof record.data === "string" ? { dataChars: record.data.length } : {}
157
- };
158
- });
159
- }
160
- function toGenAiMessageMetadata(message) {
161
- const record = message && typeof message === "object" ? message : {};
162
- return {
163
- role: record.role,
164
- content: contentMetadata(record.content)
165
- };
166
- }
167
- function toGenAiTextMetadata(text) {
168
- return { type: "text", chars: text.length };
169
- }
170
136
  function payloadType(payload) {
171
137
  return Array.isArray(payload) ? "array" : typeof payload;
172
138
  }
@@ -245,7 +211,7 @@ function summarizeContent(content) {
245
211
  return { chars, partTypes: [...partTypes] };
246
212
  }
247
213
  function normalizeFinishReason(reason) {
248
- return reason === "toolUse" ? "tool_use" : reason;
214
+ return reason === "toolUse" ? "tool_call" : reason;
249
215
  }
250
216
  function canonicalContentPartType(type) {
251
217
  if (type === "thinking") return "reasoning";
@@ -258,7 +224,7 @@ function toCanonicalPart(part) {
258
224
  }
259
225
  if (part.type === "thinking") {
260
226
  if (part.redacted) {
261
- return { type: "reasoning", redacted: true };
227
+ return void 0;
262
228
  }
263
229
  return { type: "reasoning", content: part.thinking };
264
230
  }
@@ -270,26 +236,33 @@ function toCanonicalPart(part) {
270
236
  arguments: part.arguments
271
237
  };
272
238
  }
273
- return { type: "image", mimeType: part.mimeType };
239
+ return void 0;
240
+ }
241
+ function toCanonicalParts(parts) {
242
+ return parts.map(toCanonicalPart).filter((part) => part !== void 0);
274
243
  }
275
244
  function toCanonicalOutputMessage(message) {
276
245
  return {
277
246
  role: "assistant",
278
- parts: message.content.map(toCanonicalPart),
247
+ parts: toCanonicalParts(message.content),
279
248
  finish_reason: normalizeFinishReason(message.stopReason)
280
249
  };
281
250
  }
282
251
  function toCanonicalInputMessage(message) {
283
252
  if (message.role === "user") {
284
- const parts = typeof message.content === "string" ? [{ type: "text", content: message.content }] : message.content.map(toCanonicalPart);
253
+ const parts = typeof message.content === "string" ? [{ type: "text", content: message.content }] : toCanonicalParts(message.content);
285
254
  return { role: "user", parts };
286
255
  }
287
256
  if (message.role === "toolResult") {
288
257
  return {
289
258
  role: "tool",
290
- id: message.toolCallId,
291
- name: message.toolName,
292
- parts: message.content.map(toCanonicalPart)
259
+ parts: [
260
+ {
261
+ type: "tool_call_response",
262
+ id: message.toolCallId,
263
+ response: toCanonicalParts(message.content)
264
+ }
265
+ ]
293
266
  };
294
267
  }
295
268
  return toCanonicalOutputMessage(message);
@@ -330,8 +303,6 @@ export {
330
303
  canExposeConversationPayload,
331
304
  getCurrentConversationPrivacy,
332
305
  runWithConversationPrivacy,
333
- toGenAiMessageMetadata,
334
- toGenAiTextMetadata,
335
306
  toGenAiPayloadMetadata,
336
307
  toGenAiPayloadTraceAttributes,
337
308
  toCanonicalOutputMessage,