@sentry/junior 0.108.0 → 0.109.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 (62) hide show
  1. package/dist/{agent-hooks-NU5HK3PS.js → agent-hooks-FHHVLNPA.js} +12 -12
  2. package/dist/api/conversations/events.d.ts +1 -1
  3. package/dist/api/conversations/schema.d.ts +57 -6
  4. package/dist/api/schema.js +1 -1
  5. package/dist/api.js +108 -22
  6. package/dist/app.d.ts +1 -0
  7. package/dist/app.js +1481 -420
  8. package/dist/{catalog-runtime-FOFNPR3P.js → catalog-runtime-DMGJSLV2.js} +6 -4
  9. package/dist/chat/conversations/sql/store.d.ts +0 -7
  10. package/dist/chat/log-context.d.ts +40 -0
  11. package/dist/chat/logging.d.ts +3 -26
  12. package/dist/chat/runtime/slack-resume.d.ts +2 -2
  13. package/dist/chat/services/turn-session-record.d.ts +0 -2
  14. package/dist/chat/slack/reply.d.ts +7 -19
  15. package/dist/chat/state/conversation.d.ts +1 -0
  16. package/dist/chat/task-execution/slack-work.d.ts +2 -2
  17. package/dist/chunk-3SXUV423.js +10 -0
  18. package/dist/{chunk-3RGQLX2F.js → chunk-72OMGPDS.js} +1010 -26
  19. package/dist/{chunk-2XXEKR44.js → chunk-7Q6WCISF.js} +1 -1
  20. package/dist/{chunk-TE4QHJH4.js → chunk-FENLIFJD.js} +72 -591
  21. package/dist/{chunk-XKB7LGIW.js → chunk-FWJRXN4F.js} +3 -3
  22. package/dist/{chunk-PUAMO4PI.js → chunk-HHVY4SMP.js} +41 -7
  23. package/dist/{chunk-B5I5LMSP.js → chunk-HO5NT6OE.js} +5 -7
  24. package/dist/{chunk-O24R4DCK.js → chunk-ISMWX44P.js} +93 -55
  25. package/dist/{chunk-7FBGKXPE.js → chunk-IVVGFRQQ.js} +5 -0
  26. package/dist/{chunk-KPMPQ6AA.js → chunk-IXKSQGIO.js} +90 -100
  27. package/dist/{chunk-SS67LUOK.js → chunk-JNAVF45E.js} +6 -7
  28. package/dist/{chunk-DY7TRYB5.js → chunk-MGUMR35T.js} +1 -1
  29. package/dist/{chunk-A5CO2EHL.js → chunk-MXW4GL53.js} +11 -15
  30. package/dist/{chunk-RT5BUHR5.js → chunk-O3JMSZLI.js} +1 -1
  31. package/dist/chunk-OCD3OZRK.js +125 -0
  32. package/dist/{chunk-H3QYZL7K.js → chunk-OUHNWH46.js} +28 -3
  33. package/dist/{chunk-VIXFG2VC.js → chunk-PLB7MRCQ.js} +1 -2
  34. package/dist/{chunk-UD6THJ2I.js → chunk-QY636HZU.js} +114 -12
  35. package/dist/{chunk-VH6KWKG2.js → chunk-RGX4V75M.js} +3 -3
  36. package/dist/{chunk-B7PUBQQM.js → chunk-SYAQIR5Z.js} +1 -1
  37. package/dist/chunk-TMBRFULF.js +471 -0
  38. package/dist/{chunk-YIPD3L6L.js → chunk-TT6GMXNA.js} +8 -10
  39. package/dist/{chunk-YT72TOEK.js → chunk-WHMOBKT7.js} +2 -2
  40. package/dist/cli/chat.js +23 -23
  41. package/dist/cli/check.js +8 -6
  42. package/dist/cli/plugins.js +16 -16
  43. package/dist/cli/snapshot-warmup.js +10 -9
  44. package/dist/cli/upgrade.js +314 -3505
  45. package/dist/db/db.d.ts +1 -1
  46. package/dist/{db-AMRBAT5D.js → db-V3NU72O2.js} +8 -6
  47. package/dist/instrumentation.js +3 -2
  48. package/dist/nitro.js +5 -4
  49. package/dist/{runner-TQH5GAJ4.js → runner-JYBCQBLK.js} +17 -20
  50. package/dist/{skills-ITNHBARB.js → skills-U6MDAST7.js} +7 -5
  51. package/dist/{validation-AGQ46ZGV.js → validation-72N3JVRU.js} +7 -5
  52. package/dist/version.d.ts +2 -0
  53. package/dist/version.js +7 -0
  54. package/migrations/0006_drop_legacy_conversation_messages.sql +1 -0
  55. package/migrations/README.md +12 -9
  56. package/migrations/meta/0006_snapshot.json +948 -0
  57. package/migrations/meta/_journal.json +7 -0
  58. package/package.json +9 -5
  59. package/dist/chunk-AHJR2IFF.js +0 -115
  60. package/dist/chunk-G3E7SCME.js +0 -28
  61. package/dist/chunk-J3B3FPP2.js +0 -1061
  62. package/dist/chunk-TWINAEZQ.js +0 -1283
@@ -3,17 +3,17 @@ import {
3
3
  } from "./chunk-CEA3A3UA.js";
4
4
  import {
5
5
  normalizeSlackConversationId
6
- } from "./chunk-VH6KWKG2.js";
6
+ } from "./chunk-RGX4V75M.js";
7
7
  import {
8
8
  juniorConversationEvents,
9
9
  juniorConversations
10
- } from "./chunk-TE4QHJH4.js";
10
+ } from "./chunk-TMBRFULF.js";
11
11
  import {
12
12
  juniorDestinations
13
13
  } from "./chunk-VFUK3X5B.js";
14
14
  import {
15
15
  parseSlackThreadId
16
- } from "./chunk-RT5BUHR5.js";
16
+ } from "./chunk-O3JMSZLI.js";
17
17
  import {
18
18
  getClient
19
19
  } from "./chunk-6GWA276C.js";
@@ -80,6 +80,7 @@ var conversationReportMessageEventDataSchema = z2.object({
80
80
  type: z2.literal("message"),
81
81
  messageId: z2.string().min(1),
82
82
  role: z2.enum(["assistant", "system", "user"]),
83
+ eventType: z2.string().min(1).optional(),
83
84
  text: z2.string().optional(),
84
85
  redacted: z2.literal(true).optional()
85
86
  }).strict().superRefine((data, context) => {
@@ -96,8 +97,24 @@ var conversationReportMessageHandledEventDataSchema = z2.object({
96
97
  }).strict();
97
98
  var conversationReportToolStartedEventDataSchema = z2.object({
98
99
  type: z2.literal("tool_started"),
100
+ toolCallId: z2.string().min(1),
99
101
  name: z2.string().min(1)
100
102
  }).strict();
103
+ var conversationReportToolCallSchema = z2.object({
104
+ toolCallId: z2.string().min(1),
105
+ name: z2.string().min(1),
106
+ input: z2.unknown().optional()
107
+ }).strict();
108
+ var conversationReportToolCallsEventDataSchema = z2.object({
109
+ type: z2.literal("tool_calls"),
110
+ calls: z2.array(conversationReportToolCallSchema).min(1)
111
+ }).strict();
112
+ var conversationReportToolResultEventDataSchema = z2.object({
113
+ type: z2.literal("tool_result"),
114
+ toolCallId: z2.string().min(1),
115
+ outcome: z2.enum(["completed", "error"]),
116
+ output: z2.unknown().optional()
117
+ }).strict();
101
118
  var conversationReportTurnLifecycleEventDataSchema = z2.discriminatedUnion(
102
119
  "state",
103
120
  [
@@ -117,13 +134,13 @@ var conversationReportTurnLifecycleEventDataSchema = z2.discriminatedUnion(
117
134
  var conversationReportCompactionEventDataSchema = z2.object({ type: z2.literal("compaction") }).strict();
118
135
  var conversationReportHandoffEventDataSchema = z2.object({
119
136
  type: z2.literal("handoff"),
120
- toolStartedSeq: z2.number().int().nonnegative().optional()
137
+ triggeringToolCallId: z2.string().min(1).optional()
121
138
  }).strict();
122
139
  var conversationReportSubagentStartedEventDataSchema = z2.object({
123
140
  type: z2.literal("subagent_started"),
124
141
  childConversationId: z2.string().min(1),
125
142
  subagentKind: z2.string().min(1),
126
- toolStartedSeq: z2.number().int().nonnegative().optional()
143
+ parentToolCallId: z2.string().min(1).optional()
127
144
  }).strict();
128
145
  var conversationReportSubagentEndedEventDataSchema = z2.object({
129
146
  type: z2.literal("subagent_ended"),
@@ -134,6 +151,8 @@ var conversationReportEventDataSchema = z2.discriminatedUnion("type", [
134
151
  conversationReportMessageEventDataSchema,
135
152
  conversationReportMessageHandledEventDataSchema,
136
153
  conversationReportToolStartedEventDataSchema,
154
+ conversationReportToolCallsEventDataSchema,
155
+ conversationReportToolResultEventDataSchema,
137
156
  conversationReportTurnLifecycleEventDataSchema,
138
157
  conversationReportCompactionEventDataSchema,
139
158
  conversationReportHandoffEventDataSchema,
@@ -184,19 +203,34 @@ var conversationDetailReportSchema = conversationSummaryReportSchema.extend({
184
203
  }
185
204
  }
186
205
  for (const [index, event] of report.events.entries()) {
187
- if (event.data.type !== "message") continue;
188
- if (report.eventHistory.status === "redacted" && event.data.redacted !== true) {
206
+ if (event.data.type === "message") {
207
+ if (report.eventHistory.status === "redacted" && event.data.redacted !== true) {
208
+ context.addIssue({
209
+ code: "custom",
210
+ path: ["events", index, "data"],
211
+ message: "redacted event history must redact messages"
212
+ });
213
+ }
214
+ if (report.eventHistory.status === "available" && event.data.redacted === true) {
215
+ context.addIssue({
216
+ code: "custom",
217
+ path: ["events", index, "data"],
218
+ message: "available event history must expose messages"
219
+ });
220
+ }
221
+ }
222
+ if (report.eventHistory.status === "redacted" && event.data.type === "tool_calls" && event.data.calls.some((call) => call.input !== void 0)) {
189
223
  context.addIssue({
190
224
  code: "custom",
191
225
  path: ["events", index, "data"],
192
- message: "redacted event history must redact messages"
226
+ message: "redacted event history must redact tool inputs"
193
227
  });
194
228
  }
195
- if (report.eventHistory.status === "available" && event.data.redacted === true) {
229
+ if (report.eventHistory.status === "redacted" && event.data.type === "tool_result" && event.data.output !== void 0) {
196
230
  context.addIssue({
197
231
  code: "custom",
198
232
  path: ["events", index, "data"],
199
- message: "available event history must expose messages"
233
+ message: "redacted event history must redact tool outputs"
200
234
  });
201
235
  }
202
236
  }
@@ -1,21 +1,19 @@
1
1
  import {
2
- SANDBOX_WORKSPACE_ROOT
3
- } from "./chunk-G3E7SCME.js";
4
- import {
2
+ SANDBOX_WORKSPACE_ROOT,
5
3
  getStateAdapter
6
- } from "./chunk-H3QYZL7K.js";
4
+ } from "./chunk-OUHNWH46.js";
7
5
  import {
8
6
  sleep
9
7
  } from "./chunk-4ZNGQH7C.js";
10
8
  import {
11
9
  toOptionalTrimmed
12
- } from "./chunk-SS67LUOK.js";
10
+ } from "./chunk-JNAVF45E.js";
13
11
  import {
14
12
  pluginCatalogRuntime
15
- } from "./chunk-YIPD3L6L.js";
13
+ } from "./chunk-3SXUV423.js";
16
14
  import {
17
15
  withSpan
18
- } from "./chunk-O24R4DCK.js";
16
+ } from "./chunk-ISMWX44P.js";
19
17
 
20
18
  // src/chat/sandbox/runtime-dependencies.ts
21
19
  var GLOBAL_RUNTIME_DEPENDENCIES = [
@@ -13,10 +13,9 @@ import {
13
13
  } from "./chunk-6GWA276C.js";
14
14
  import {
15
15
  getDeploymentTelemetryAttributes
16
- } from "./chunk-7FBGKXPE.js";
16
+ } from "./chunk-IVVGFRQQ.js";
17
17
 
18
18
  // src/chat/logging.ts
19
- import { AsyncLocalStorage } from "async_hooks";
20
19
  import path from "path";
21
20
  import { styleText } from "util";
22
21
  import {
@@ -26,6 +25,73 @@ import {
26
25
  getLogger
27
26
  } from "@logtape/logtape";
28
27
 
28
+ // src/chat/log-context.ts
29
+ import { AsyncLocalStorage } from "async_hooks";
30
+ var logContextStorage = new AsyncLocalStorage();
31
+ var typedLogContextStorage = new AsyncLocalStorage();
32
+ function definedLogContext(context) {
33
+ return Object.fromEntries(
34
+ Object.entries(context).filter(([, value]) => value !== void 0)
35
+ );
36
+ }
37
+ function definedAttributes(attributes) {
38
+ return Object.fromEntries(
39
+ Object.entries(attributes).filter(
40
+ (entry) => entry[1] !== void 0
41
+ )
42
+ );
43
+ }
44
+ function logContextToAttributes(context) {
45
+ return definedAttributes({
46
+ "gen_ai.conversation.id": context.conversationId,
47
+ "app.platform": context.platform,
48
+ "app.request.id": context.requestId,
49
+ "messaging.system": context.platform === "slack" ? "slack" : context.platform,
50
+ "messaging.message.conversation_id": context.messageConversationId,
51
+ "messaging.destination.name": context.destinationName,
52
+ "enduser.id": context.userId,
53
+ "enduser.pseudo.id": context.userName,
54
+ "app.run.id": context.runId,
55
+ "app.actor.type": context.actorType,
56
+ "app.actor.id": context.actorId,
57
+ "gen_ai.agent.name": context.assistantUserName,
58
+ "gen_ai.request.model": context.modelId,
59
+ "app.skill.name": context.skillName,
60
+ "http.request.method": context.httpMethod,
61
+ "url.path": context.httpPath,
62
+ "url.full": context.urlFull,
63
+ "user_agent.original": context.userAgent
64
+ });
65
+ }
66
+ function runWithLogContext(context, attributes, callback) {
67
+ return typedLogContextStorage.run(
68
+ {
69
+ ...typedLogContextStorage.getStore(),
70
+ ...definedLogContext(context)
71
+ },
72
+ () => logContextStorage.run(
73
+ { ...logContextStorage.getStore(), ...attributes },
74
+ callback
75
+ )
76
+ );
77
+ }
78
+ function updateLogContext(context, attributes) {
79
+ const currentContext = typedLogContextStorage.getStore();
80
+ if (currentContext) {
81
+ Object.assign(currentContext, definedLogContext(context));
82
+ }
83
+ const currentAttributes = logContextStorage.getStore();
84
+ if (currentAttributes) {
85
+ Object.assign(currentAttributes, attributes);
86
+ }
87
+ }
88
+ function getBoundLogContext() {
89
+ return typedLogContextStorage.getStore() ?? {};
90
+ }
91
+ function getBoundLogAttributes() {
92
+ return logContextStorage.getStore() ?? {};
93
+ }
94
+
29
95
  // src/chat/identities/identity.ts
30
96
  function normalizeIdentityEmail(email) {
31
97
  const normalized = email?.trim().toLowerCase();
@@ -89,7 +155,6 @@ function normalizeGenAiFinishReasons(value) {
89
155
  (reason) => typeof reason === "string" ? normalizeGenAiFinishReason(reason) : reason
90
156
  );
91
157
  }
92
- var contextStorage = new AsyncLocalStorage();
93
158
  var logRecordSinks = /* @__PURE__ */ new Set();
94
159
  var deploymentLogAttributes = getDeploymentTelemetryAttributes();
95
160
  var LOGTAPE_BODY_KEY = "__logtape_body";
@@ -322,32 +387,7 @@ function sanitizeValue(value) {
322
387
  return sanitizePrimitive(value);
323
388
  }
324
389
  function contextToAttributes(context) {
325
- const attributes = {
326
- "gen_ai.conversation.id": context.conversationId,
327
- "app.platform": context.platform,
328
- "app.request.id": context.requestId,
329
- "messaging.system": context.platform === "slack" ? "slack" : context.platform,
330
- "messaging.message.conversation_id": context.slackThreadId,
331
- "messaging.destination.name": context.slackChannelId,
332
- "enduser.id": context.slackUserId,
333
- "enduser.pseudo.id": context.slackUserName,
334
- "app.run.id": context.runId,
335
- "app.actor.type": context.actorType,
336
- "app.actor.id": context.actorId,
337
- "gen_ai.agent.name": context.assistantUserName,
338
- "gen_ai.request.model": context.modelId,
339
- "app.skill.name": context.skillName,
340
- "http.request.method": context.httpMethod,
341
- "url.path": context.httpPath,
342
- "url.full": context.urlFull,
343
- "user_agent.original": context.userAgent
344
- };
345
- const normalized = {};
346
- for (const [key, value] of Object.entries(attributes)) {
347
- const sanitized = sanitizeValue(value);
348
- if (sanitized !== void 0) normalized[key] = sanitized;
349
- }
350
- return normalized;
390
+ return mergeAttributes(logContextToAttributes(context));
351
391
  }
352
392
  function getTraceCorrelationAttributes() {
353
393
  const sentry = sentry_exports;
@@ -479,7 +519,7 @@ function ensureLoggerBackend() {
479
519
  lowestLevel: "error"
480
520
  }
481
521
  ],
482
- contextLocalStorage: contextStorage
522
+ contextLocalStorage: logContextStorage
483
523
  });
484
524
  ownsLogTapeBackend = true;
485
525
  rootLogger = getLogger([...ROOT_LOGGER_CATEGORY]);
@@ -835,7 +875,7 @@ function emitRecord(category, level, eventName, attrs = {}, body) {
835
875
  const normalizedEventName = toSnakeCase(eventName);
836
876
  const message = body ? redactSecrets(body) : normalizedEventName;
837
877
  const source = getLogSource([...ROOT_LOGGER_CATEGORY, ...category]);
838
- const contextAttributes = ownsLogTapeBackend ? void 0 : contextStorage.getStore();
878
+ const contextAttributes = ownsLogTapeBackend ? void 0 : getBoundLogAttributes();
839
879
  const attributes = mergeAttributes(
840
880
  contextAttributes,
841
881
  traceAttributes,
@@ -905,11 +945,12 @@ var log = {
905
945
  const sentryCaptureException = captureException;
906
946
  if (typeof sentryWithScope === "function" && typeof sentryCaptureException === "function") {
907
947
  sentryWithScope((scope) => {
908
- if (context) {
909
- setSentryScopeContext(scope, context);
910
- }
948
+ setSentryScopeContext(scope, {
949
+ ...getBoundLogContext(),
950
+ ...context
951
+ });
911
952
  for (const [key, value] of Object.entries(
912
- mergeAttributes(contextStorage.getStore(), attrs)
953
+ mergeAttributes(getBoundLogAttributes(), attrs)
913
954
  )) {
914
955
  scope.setExtra(key, value);
915
956
  }
@@ -918,9 +959,12 @@ var log = {
918
959
  return eventId;
919
960
  }
920
961
  if (typeof sentryCaptureException === "function") {
921
- if (context) {
922
- setSentryUser(sentryUserIdentityFromContext(context));
923
- }
962
+ setSentryUser(
963
+ sentryUserIdentityFromContext({
964
+ ...getBoundLogContext(),
965
+ ...context
966
+ })
967
+ );
924
968
  eventId = sentryCaptureException(normalizedError);
925
969
  }
926
970
  return eventId;
@@ -1004,21 +1048,14 @@ function createChatSdkLogger() {
1004
1048
  return createChatSdkLoggerImpl(["chat-sdk"], resolveChatSdkLogLevel());
1005
1049
  }
1006
1050
  function withLogContext(context, callback) {
1007
- const next = mergeAttributes(
1008
- contextStorage.getStore(),
1009
- contextToAttributes(context)
1010
- );
1011
- return contextStorage.run(next, callback);
1012
- }
1013
- function setLogContext(context) {
1014
- const merged = mergeAttributes(
1015
- contextStorage.getStore(),
1016
- contextToAttributes(context)
1051
+ return runWithLogContext(
1052
+ context,
1053
+ contextToAttributes(context),
1054
+ callback
1017
1055
  );
1018
- contextStorage.enterWith(merged);
1019
1056
  }
1020
1057
  function getLogContextAttributes() {
1021
- return contextStorage.getStore() ?? {};
1058
+ return getBoundLogAttributes();
1022
1059
  }
1023
1060
  function getLogContextAttributesForSpan(op) {
1024
1061
  const attributes = { ...getLogContextAttributes() };
@@ -1066,11 +1103,11 @@ function setSentryTagsFromContext(context) {
1066
1103
  }
1067
1104
  }
1068
1105
  function sentryUserIdentityFromContext(context) {
1069
- if (context.slackUserId) {
1070
- const email = normalizeIdentityEmail(context.slackUserEmail);
1106
+ if (context.userId) {
1107
+ const email = normalizeIdentityEmail(context.userEmail);
1071
1108
  return {
1072
- id: context.slackUserId,
1073
- ...context.slackUserName ? { username: context.slackUserName } : {},
1109
+ id: context.userId,
1110
+ ...context.userName ? { username: context.userName } : {},
1074
1111
  ...email ? { email } : {}
1075
1112
  };
1076
1113
  }
@@ -1156,7 +1193,7 @@ function logException(error, eventName, context = {}, attributes = {}, body) {
1156
1193
  );
1157
1194
  }
1158
1195
  function setTags(context = {}) {
1159
- setLogContext(context);
1196
+ updateLogContext(context, contextToAttributes(context));
1160
1197
  setSentryTagsFromContext(context);
1161
1198
  setSentryUser(sentryUserIdentityFromContext(context));
1162
1199
  }
@@ -1437,6 +1474,7 @@ export {
1437
1474
  normalizeGenAiFinishReason,
1438
1475
  summarizeMessageText,
1439
1476
  createChatSdkLogger,
1477
+ withLogContext,
1440
1478
  getLogContextAttributesForSpan,
1441
1479
  setSentryUser,
1442
1480
  logInfo,
@@ -1,3 +1,7 @@
1
+ import {
2
+ JUNIOR_VERSION
3
+ } from "./chunk-OCD3OZRK.js";
4
+
1
5
  // src/deployment.ts
2
6
  var JUNIOR_HEARTBEAT_ROUTE = "/api/internal/heartbeat";
3
7
  var JUNIOR_HEARTBEAT_CRON_SCHEDULE = "* * * * *";
@@ -17,6 +21,7 @@ function getDeploymentTelemetryAttributes() {
17
21
  const attributes = {};
18
22
  const serviceVersion = getDeploymentServiceVersion();
19
23
  const deploymentId = toOptionalTrimmed(process.env.VERCEL_DEPLOYMENT_ID);
24
+ attributes["app.junior.version"] = JUNIOR_VERSION;
20
25
  if (serviceVersion) {
21
26
  attributes["service.version"] = serviceVersion;
22
27
  }