@sentry/junior 0.122.0 → 0.123.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 (72) hide show
  1. package/dist/{agent-hooks-HJMLQLCB.js → agent-hooks-7JCABN73.js} +7 -7
  2. package/dist/api/conversations/detail.d.ts +55 -0
  3. package/dist/api/conversations/event-list.d.ts +55 -0
  4. package/dist/api/conversations/events.d.ts +1 -1
  5. package/dist/api/conversations/stats.d.ts +15 -0
  6. package/dist/api/schema/conversation.d.ts +260 -0
  7. package/dist/api/schema.d.ts +1 -1
  8. package/dist/api/schema.js +1 -1
  9. package/dist/api.js +134 -20
  10. package/dist/app.js +32 -19
  11. package/dist/{catalog-runtime-CYPZUYJD.js → catalog-runtime-SZAS6EVH.js} +5 -5
  12. package/dist/chat/agent/action-confirmation-retry.d.ts +6 -0
  13. package/dist/chat/agent/tools.d.ts +12 -0
  14. package/dist/chat/config.d.ts +1 -0
  15. package/dist/chat/conversations/history.d.ts +91 -1
  16. package/dist/chat/conversations/projection.d.ts +11 -0
  17. package/dist/chat/conversations/provenance.d.ts +2 -0
  18. package/dist/chat/mcp/tool-manager.d.ts +12 -1
  19. package/dist/chat/pi/client.d.ts +6 -0
  20. package/dist/chat/pi/sdk.d.ts +1 -1
  21. package/dist/chat/pi/transcript.d.ts +2 -0
  22. package/dist/chat/plugins/agent-hooks.d.ts +10 -0
  23. package/dist/chat/plugins/conversation-events.d.ts +15 -0
  24. package/dist/chat/services/guardian-action-policy.d.ts +12 -0
  25. package/dist/chat/services/guardian-action-review.d.ts +9 -0
  26. package/dist/chat/tool-support/action-review-evidence.d.ts +4 -0
  27. package/dist/chat/tool-support/action-review-history.d.ts +117 -0
  28. package/dist/chat/tool-support/action-review.d.ts +142 -0
  29. package/dist/chat/tool-support/pi-tool-adapter.d.ts +2 -1
  30. package/dist/chat/tool-support/skill/mcp-tool-summary.d.ts +1 -6
  31. package/dist/chat/tool-support/zod-tool.d.ts +1 -0
  32. package/dist/chat/tools/definition.d.ts +23 -1
  33. package/dist/chat/tools/query-conversation-events.d.ts +1 -1
  34. package/dist/chat/tools/search-tools.d.ts +0 -20
  35. package/dist/chat/tools/skill/search-mcp-tools.d.ts +0 -20
  36. package/dist/{chunk-CYW4M6IV.js → chunk-2DZD6HX2.js} +4 -4
  37. package/dist/{chunk-NIJG6G6X.js → chunk-3S2K7SYY.js} +1465 -594
  38. package/dist/{chunk-32FPGM2V.js → chunk-5EUADEG3.js} +1 -1
  39. package/dist/{chunk-4TGVC42X.js → chunk-5P4QBMTY.js} +11 -11
  40. package/dist/{chunk-ISQYBTPG.js → chunk-7YOBVIHY.js} +3 -2
  41. package/dist/{chunk-GFTZKOTP.js → chunk-A3TUEGKH.js} +1 -1
  42. package/dist/{chunk-E5SRLZQV.js → chunk-DAMUPWYR.js} +2 -2
  43. package/dist/{chunk-V6XPIKYA.js → chunk-DQQCWMA2.js} +17 -19
  44. package/dist/{chunk-DOB5RVMH.js → chunk-DVPWU77W.js} +30 -2
  45. package/dist/{chunk-2RFM7STT.js → chunk-JCJN6TPV.js} +55 -4
  46. package/dist/{chunk-O2ULQJWR.js → chunk-JMUPEYKC.js} +47 -1
  47. package/dist/{chunk-4SPRQJOW.js → chunk-JPG43UG7.js} +1 -1
  48. package/dist/{chunk-NNGYYGX5.js → chunk-K5DCMBUV.js} +33 -4
  49. package/dist/{chunk-BDE5RZVF.js → chunk-LEQXDCWK.js} +1 -1
  50. package/dist/{chunk-OKUZIXQM.js → chunk-QKYO7ZNS.js} +1 -1
  51. package/dist/{chunk-VCC7XFX2.js → chunk-RQ6BLJJD.js} +7 -7
  52. package/dist/chunk-THYOK2SL.js +55 -0
  53. package/dist/{chunk-L2KJ2GNL.js → chunk-VTWLP6YS.js} +1 -1
  54. package/dist/{chunk-GN6WW7WR.js → chunk-XLPETJXX.js} +1 -1
  55. package/dist/{chunk-USKP7IM2.js → chunk-ZO4TL4OK.js} +53 -11
  56. package/dist/{chunk-TZVZCIYL.js → chunk-ZOOZ25BO.js} +1 -1
  57. package/dist/cli/chat.js +21 -21
  58. package/dist/cli/check.js +6 -6
  59. package/dist/cli/init.js +2 -1
  60. package/dist/cli/plugins.js +10 -10
  61. package/dist/cli/snapshot-create.js +8 -8
  62. package/dist/cli/upgrade.js +5 -5
  63. package/dist/{db-E6O2DXUQ.js → db-XKB2CHDW.js} +5 -5
  64. package/dist/instrumentation.js +2 -2
  65. package/dist/nitro.js +2 -2
  66. package/dist/{oauth-callback-server-6SCPUFFD.js → oauth-callback-server-EVMACH4G.js} +15 -14
  67. package/dist/{runner-JFKCMVVY.js → runner-BVHV5Y6L.js} +10 -9
  68. package/dist/{skills-RD66F2OB.js → skills-QTI6GGJ4.js} +6 -6
  69. package/dist/{validation-XVRNX6IU.js → validation-SCQUYIUU.js} +6 -6
  70. package/dist/version.js +1 -1
  71. package/package.json +8 -7
  72. package/dist/chat/tool-support/schema-summary.d.ts +0 -2
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getDb
3
- } from "./chunk-DOB5RVMH.js";
3
+ } from "./chunk-DVPWU77W.js";
4
4
  import {
5
5
  juniorStats
6
6
  } from "./chunk-GCGJGSQL.js";
@@ -13,7 +13,7 @@ import {
13
13
  persistAuthPauseTurnState,
14
14
  requireTurnFailureEventId,
15
15
  scheduleSessionCompletedPluginTasks
16
- } from "./chunk-V6XPIKYA.js";
16
+ } from "./chunk-DQQCWMA2.js";
17
17
  import {
18
18
  buildSentryConversationUrl
19
19
  } from "./chunk-4CODA7P5.js";
@@ -40,7 +40,7 @@ import {
40
40
  resolveBaseUrl,
41
41
  resolvePluginOAuthAccount,
42
42
  truncateStatusText
43
- } from "./chunk-VCC7XFX2.js";
43
+ } from "./chunk-RQ6BLJJD.js";
44
44
  import {
45
45
  JUNIOR_THREAD_STATE_TTL_MS,
46
46
  TurnSliceLimitExceededError,
@@ -72,7 +72,7 @@ import {
72
72
  recordDeliveredAssistantMessage,
73
73
  turnHasReply,
74
74
  updateConversationStats
75
- } from "./chunk-NNGYYGX5.js";
75
+ } from "./chunk-K5DCMBUV.js";
76
76
  import {
77
77
  SlackActionError,
78
78
  getDashboardConversationLink,
@@ -81,19 +81,19 @@ import {
81
81
  getSlackClient,
82
82
  isDmChannel,
83
83
  normalizeSlackConversationId
84
- } from "./chunk-USKP7IM2.js";
84
+ } from "./chunk-ZO4TL4OK.js";
85
85
  import {
86
86
  getConversationEventStore,
87
87
  getConversationStore,
88
88
  parseDestination,
89
89
  requireSlackDestination,
90
90
  sameDestination
91
- } from "./chunk-DOB5RVMH.js";
91
+ } from "./chunk-DVPWU77W.js";
92
92
  import {
93
93
  acquireActiveLock,
94
94
  getDefaultRedisStateAdapterFor,
95
95
  getStateAdapter
96
- } from "./chunk-TZVZCIYL.js";
96
+ } from "./chunk-ZOOZ25BO.js";
97
97
  import {
98
98
  FUNCTION_TIMEOUT_BUFFER_SECONDS,
99
99
  botConfig,
@@ -102,7 +102,7 @@ import {
102
102
  getRuntimeMetadata,
103
103
  normalizeSlackEmojiName,
104
104
  standardModelId
105
- } from "./chunk-2RFM7STT.js";
105
+ } from "./chunk-JCJN6TPV.js";
106
106
  import {
107
107
  parseSlackThreadId,
108
108
  readSlackRawMessageContext,
@@ -111,15 +111,15 @@ import {
111
111
  } from "./chunk-S7G34U75.js";
112
112
  import {
113
113
  discoverSkills
114
- } from "./chunk-E5SRLZQV.js";
114
+ } from "./chunk-DAMUPWYR.js";
115
115
  import {
116
116
  pluginCatalogRuntime
117
- } from "./chunk-OKUZIXQM.js";
117
+ } from "./chunk-QKYO7ZNS.js";
118
118
  import {
119
119
  buildOAuthTokenRequest,
120
120
  hasRequiredOAuthScope,
121
121
  parseOAuthTokenResponse
122
- } from "./chunk-GN6WW7WR.js";
122
+ } from "./chunk-XLPETJXX.js";
123
123
  import {
124
124
  createSlackResumeActor,
125
125
  isUserActor,
@@ -132,7 +132,7 @@ import {
132
132
  logWarn,
133
133
  setTags,
134
134
  withLogContext
135
- } from "./chunk-4SPRQJOW.js";
135
+ } from "./chunk-JPG43UG7.js";
136
136
  import {
137
137
  isRecord,
138
138
  toOptionalNumber,
@@ -1,7 +1,7 @@
1
1
  // package.json
2
2
  var package_default = {
3
3
  name: "@sentry/junior",
4
- version: "0.122.0",
4
+ version: "0.123.0",
5
5
  private: false,
6
6
  publishConfig: {
7
7
  access: "public"
@@ -63,6 +63,7 @@ var package_default = {
63
63
  "test:watch": "vitest",
64
64
  typecheck: "tsc --noEmit",
65
65
  "skills:check": "node --test scripts/check-skills.test.mjs && node scripts/check-skills.mjs",
66
+ "tool-annotations:check": "node --test scripts/check-tool-annotations.test.mjs && node scripts/check-tool-annotations.mjs",
66
67
  "test:coverage": "vitest run --maxWorkers=4 --coverage --reporter=default --reporter=junit --outputFile.junit=coverage/results.junit.xml"
67
68
  },
68
69
  dependencies: {
@@ -86,7 +87,7 @@ var package_default = {
86
87
  chat: "4.29.0",
87
88
  commander: "^14.0.3",
88
89
  "drizzle-orm": "catalog:",
89
- hono: "^4.12.22",
90
+ hono: "^4.12.27",
90
91
  jiti: "^2.7.0",
91
92
  jose: "^6.2.3",
92
93
  "just-bash": "3.0.1",
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  pluginCatalogRuntime
3
- } from "./chunk-OKUZIXQM.js";
3
+ } from "./chunk-QKYO7ZNS.js";
4
4
 
5
5
  // src/chat/plugins/validation.ts
6
6
  import { isDeepStrictEqual } from "util";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  pluginCatalogRuntime
3
- } from "./chunk-OKUZIXQM.js";
3
+ } from "./chunk-QKYO7ZNS.js";
4
4
  import {
5
5
  logWarn
6
- } from "./chunk-4SPRQJOW.js";
6
+ } from "./chunk-JPG43UG7.js";
7
7
  import {
8
8
  skillRoots
9
9
  } from "./chunk-H4HBKISO.js";
@@ -1,3 +1,6 @@
1
+ import {
2
+ createPluginConversationEvents
3
+ } from "./chunk-THYOK2SL.js";
1
4
  import {
2
5
  pluginTaskId,
3
6
  pluginTaskParamsSchema,
@@ -22,28 +25,29 @@ import {
22
25
  persistThreadStateById,
23
26
  stripRuntimeTurnContext,
24
27
  updateConversationStats
25
- } from "./chunk-NNGYYGX5.js";
28
+ } from "./chunk-K5DCMBUV.js";
26
29
  import {
27
30
  createPluginEmbedder,
28
31
  createPluginLogger,
29
32
  createPluginModel,
30
33
  createPluginState,
31
34
  getPlugins
32
- } from "./chunk-USKP7IM2.js";
35
+ } from "./chunk-ZO4TL4OK.js";
33
36
  import {
34
- getDb
35
- } from "./chunk-DOB5RVMH.js";
37
+ getDb,
38
+ sameActorIdentity
39
+ } from "./chunk-DVPWU77W.js";
36
40
  import {
37
41
  getStateAdapter
38
- } from "./chunk-TZVZCIYL.js";
42
+ } from "./chunk-ZOOZ25BO.js";
39
43
  import {
40
44
  ProviderError,
41
45
  getProviderErrorAttributes,
42
46
  getProviderErrorUserMessage
43
- } from "./chunk-2RFM7STT.js";
47
+ } from "./chunk-JCJN6TPV.js";
44
48
  import {
45
49
  buildTurnFailureResponse
46
- } from "./chunk-4SPRQJOW.js";
50
+ } from "./chunk-JPG43UG7.js";
47
51
  import {
48
52
  parseSlackMessageTs
49
53
  } from "./chunk-F3B2YJ76.js";
@@ -122,18 +126,6 @@ function sanitizeText(text) {
122
126
  "[image data omitted]"
123
127
  ).replaceAll("\0", " ").trim();
124
128
  }
125
- function sameActorIdentity(left, right) {
126
- if (!left || !right || left.platform !== right.platform) {
127
- return false;
128
- }
129
- if (left.platform === "system" || right.platform === "system") {
130
- return left.platform === "system" && right.platform === "system" && left.name === right.name;
131
- }
132
- if (left.platform === "slack" && right.platform === "slack") {
133
- return left.teamId === right.teamId && left.userId === right.userId;
134
- }
135
- return left.userId === right.userId;
136
- }
137
129
  function messageProvenance(provenance) {
138
130
  return {
139
131
  authority: provenance.authority,
@@ -318,6 +310,12 @@ function taskPluginContext(plugin, message, options = {}) {
318
310
  embedder: createPluginEmbedder(pluginName, {
319
311
  signal: options.signal
320
312
  }),
313
+ events: createPluginConversationEvents({
314
+ conversationId: sessionParams.conversationId,
315
+ operationId: pluginTaskId(message),
316
+ plugin,
317
+ turnId: sessionParams.sessionId
318
+ }),
321
319
  id: pluginTaskId(message),
322
320
  log: createPluginLogger(pluginName),
323
321
  model: createPluginModel(pluginName, plugin.model, {
@@ -9,13 +9,13 @@ import {
9
9
  TURN_REASONING_LEVELS,
10
10
  getChatConfig,
11
11
  modelProfileSchema
12
- } from "./chunk-2RFM7STT.js";
12
+ } from "./chunk-JCJN6TPV.js";
13
13
  import {
14
14
  juniorDestinations
15
15
  } from "./chunk-VFUK3X5B.js";
16
16
  import {
17
17
  normalizeIdentityEmail
18
- } from "./chunk-4SPRQJOW.js";
18
+ } from "./chunk-JPG43UG7.js";
19
19
  import {
20
20
  parseSlackChannelReferenceId,
21
21
  parseSlackTeamId
@@ -770,6 +770,11 @@ function actorIdentityKey(actor) {
770
770
  }
771
771
  return actor.platform === "slack" ? `slack\0${actor.teamId}\0${actor.userId}` : `${actor.platform}\0${actor.userId}`;
772
772
  }
773
+ function sameActorIdentity(left, right) {
774
+ return Boolean(
775
+ left && right && actorIdentityKey(left) === actorIdentityKey(right)
776
+ );
777
+ }
773
778
  function instructionActors(provenance) {
774
779
  const seen = /* @__PURE__ */ new Set();
775
780
  const actors = [];
@@ -881,6 +886,16 @@ var toolExecutionStartedEventDataSchema = z2.object({
881
886
  toolCallId: z2.string().min(1),
882
887
  toolName: z2.string().min(1)
883
888
  }).strict();
889
+ var guardianActionReviewedEventDataSchema = z2.object({
890
+ type: z2.literal("guardian_action_reviewed"),
891
+ turnId: z2.string().min(1),
892
+ toolCallId: z2.string().min(1),
893
+ toolName: z2.string().min(1),
894
+ costUsd: z2.number().finite().nonnegative().optional(),
895
+ decision: z2.enum(["allow", "ask", "deny"]),
896
+ riskLevel: z2.enum(["low", "medium", "high", "critical"]),
897
+ userAuthorization: z2.enum(["high", "medium", "low", "unknown"])
898
+ }).strict();
884
899
  var conversationMessageRoleSchema = z2.union([
885
900
  z2.literal("user"),
886
901
  z2.literal("assistant"),
@@ -951,6 +966,14 @@ var turnContextEventDataSchema = z2.object({
951
966
  version: z2.number().int().positive(),
952
967
  content: z2.record(z2.string(), z2.unknown())
953
968
  }).strict();
969
+ var pluginConversationEventDataSchema = z2.object({
970
+ type: z2.literal("plugin_event"),
971
+ namespace: z2.string().regex(/^[a-z][a-z0-9-]*$/),
972
+ name: z2.string().regex(/^[a-z][a-z0-9_]*$/),
973
+ version: z2.number().int().positive(),
974
+ turnId: z2.string().min(1),
975
+ content: z2.record(z2.string(), z2.unknown())
976
+ }).strict();
954
977
  var turnCompletedEventDataSchema = z2.object({
955
978
  type: z2.literal("turn_completed"),
956
979
  turnId: z2.string().min(1),
@@ -989,10 +1012,12 @@ var appendableConversationEventDataSchema = z2.union([
989
1012
  authorizationRequestedEventDataSchema,
990
1013
  authorizationCompletedEventDataSchema,
991
1014
  toolExecutionStartedEventDataSchema,
1015
+ guardianActionReviewedEventDataSchema,
992
1016
  messageHandledEventDataSchema,
993
1017
  messagesSummarizedEventDataSchema,
994
1018
  turnStartedEventDataSchema,
995
1019
  turnContextEventDataSchema,
1020
+ pluginConversationEventDataSchema,
996
1021
  turnRoutedEventDataSchema,
997
1022
  turnCompletedEventDataSchema,
998
1023
  turnFailedEventDataSchema,
@@ -1013,10 +1038,12 @@ var KNOWN_CONVERSATION_EVENT_TYPES = [
1013
1038
  "authorization_requested",
1014
1039
  "authorization_completed",
1015
1040
  "tool_execution_started",
1041
+ "guardian_action_reviewed",
1016
1042
  "message_handled",
1017
1043
  "messages_summarized",
1018
1044
  "turn_started",
1019
1045
  "turn_context",
1046
+ "plugin_event",
1020
1047
  "turn_routed",
1021
1048
  "turn_completed",
1022
1049
  "turn_failed",
@@ -1515,6 +1542,7 @@ export {
1515
1542
  sameDestination,
1516
1543
  instructionProvenanceFor,
1517
1544
  contextProvenance,
1545
+ sameActorIdentity,
1518
1546
  instructionActors,
1519
1547
  agentHistoryItemSchema,
1520
1548
  KNOWN_CONVERSATION_EVENT_TYPES,
@@ -12,7 +12,7 @@ import {
12
12
  normalizeGenAiFinishReason,
13
13
  serializeGenAiAttribute,
14
14
  withSpan
15
- } from "./chunk-4SPRQJOW.js";
15
+ } from "./chunk-JPG43UG7.js";
16
16
 
17
17
  // src/chat/config.ts
18
18
  import { getModel as getModel2 } from "@earendil-works/pi-ai/compat";
@@ -28,6 +28,7 @@ function toOptionalTrimmed(value) {
28
28
 
29
29
  // src/chat/pi/sdk.ts
30
30
  import {
31
+ calculateCost,
31
32
  completeSimple,
32
33
  getEnvApiKey,
33
34
  getModel,
@@ -42,7 +43,11 @@ import {
42
43
 
43
44
  // src/chat/pi/client.ts
44
45
  import { createGatewayProvider } from "@ai-sdk/gateway";
45
- import { embedMany, generateObject, NoObjectGeneratedError } from "ai";
46
+ import {
47
+ embedMany,
48
+ generateObject,
49
+ NoObjectGeneratedError
50
+ } from "ai";
46
51
 
47
52
  // src/chat/services/provider-error.ts
48
53
  var ProviderError = class extends Error {
@@ -434,11 +439,40 @@ function logContextFromMetadata(modelId, metadata) {
434
439
  ...runId ? { runId } : {}
435
440
  };
436
441
  }
442
+ function objectCompletionCost(modelId, usage) {
443
+ const cacheRead = usage.inputTokenDetails.cacheReadTokens;
444
+ const cacheWrite = usage.inputTokenDetails.cacheWriteTokens;
445
+ const input = usage.inputTokenDetails.noCacheTokens ?? (usage.inputTokens === void 0 ? void 0 : Math.max(0, usage.inputTokens - (cacheRead ?? 0) - (cacheWrite ?? 0)));
446
+ if (input === void 0 && usage.outputTokens === void 0 && cacheRead === void 0 && cacheWrite === void 0) {
447
+ return void 0;
448
+ }
449
+ return calculateCost(resolveGatewayModel(modelId), {
450
+ input: input ?? 0,
451
+ output: usage.outputTokens ?? 0,
452
+ cacheRead: cacheRead ?? 0,
453
+ cacheWrite: cacheWrite ?? 0,
454
+ ...usage.outputTokenDetails.reasoningTokens !== void 0 ? { reasoning: usage.outputTokenDetails.reasoningTokens } : {},
455
+ totalTokens: usage.totalTokens ?? (input ?? 0) + (usage.outputTokens ?? 0) + (cacheRead ?? 0) + (cacheWrite ?? 0),
456
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
457
+ }).total;
458
+ }
459
+ function bestEffortObjectCompletionCost(modelId, usage) {
460
+ try {
461
+ return objectCompletionCost(modelId, usage);
462
+ } catch (error) {
463
+ logWarn("ai.completion.cost_estimate.failed", {
464
+ "exception.message": error instanceof Error ? error.message : String(error),
465
+ "gen_ai.request.model": modelId
466
+ });
467
+ return void 0;
468
+ }
469
+ }
437
470
  async function completeObject(params) {
438
471
  const apiKey = getGatewayApiKey();
439
472
  const provider = createGatewayProvider(apiKey ? { apiKey } : {});
473
+ let result;
440
474
  try {
441
- const result = await withSpan(
475
+ result = await withSpan(
442
476
  `${GEN_AI_OPERATION_CHAT} ${params.modelId}`,
443
477
  "gen_ai.chat",
444
478
  logContextFromMetadata(params.modelId, params.metadata),
@@ -450,6 +484,13 @@ async function completeObject(params) {
450
484
  ...params.system !== void 0 ? { system: params.system } : {},
451
485
  ...params.temperature !== void 0 ? { temperature: params.temperature } : {},
452
486
  ...params.maxTokens !== void 0 ? { maxOutputTokens: params.maxTokens } : {},
487
+ ...params.recordTelemetryPayloads === false ? {
488
+ experimental_telemetry: {
489
+ isEnabled: true,
490
+ recordInputs: false,
491
+ recordOutputs: false
492
+ }
493
+ } : {},
453
494
  ...params.signal !== void 0 ? { abortSignal: params.signal } : {}
454
495
  });
455
496
  setSpanAttributes({
@@ -470,7 +511,6 @@ async function completeObject(params) {
470
511
  ...params.maxTokens !== void 0 ? { "gen_ai.request.max_tokens": params.maxTokens } : {}
471
512
  }
472
513
  );
473
- return { object: result.object };
474
514
  } catch (error) {
475
515
  const providerError = createProviderError(error, {
476
516
  ...NoObjectGeneratedError.isInstance(error) ? { kind: "invalid_response" } : {},
@@ -478,6 +518,11 @@ async function completeObject(params) {
478
518
  });
479
519
  throw providerError;
480
520
  }
521
+ const costUsd = bestEffortObjectCompletionCost(params.modelId, result.usage);
522
+ return {
523
+ object: result.object,
524
+ ...costUsd !== void 0 ? { costUsd } : {}
525
+ };
481
526
  }
482
527
  async function embedTexts(params) {
483
528
  const texts = params.texts.map((text) => text.trim());
@@ -695,6 +740,10 @@ var DEFAULT_FAST_MODEL_ID = getModel2(
695
740
  "vercel-ai-gateway",
696
741
  "anthropic/claude-haiku-4.5"
697
742
  ).id;
743
+ var DEFAULT_GUARDIAN_MODEL_ID = getModel2(
744
+ "vercel-ai-gateway",
745
+ "openai/gpt-5.6-luna"
746
+ ).id;
698
747
  var DEFAULT_HANDOFF_MODEL_ID = getModel2(
699
748
  "vercel-ai-gateway",
700
749
  "openai/gpt-5.6-sol"
@@ -773,6 +822,7 @@ function readBotConfig(env, functionMaxDurationSeconds) {
773
822
  const modelId = validateGatewayModelId(env.AI_MODEL) ?? DEFAULT_MODEL_ID;
774
823
  const reasoningLevel = toOptionalTrimmed(env.AI_REASONING_LEVEL);
775
824
  const fastModelId = validateGatewayModelId(env.AI_FAST_MODEL ?? env.AI_MODEL) ?? DEFAULT_FAST_MODEL_ID;
825
+ const guardianModelId = validateGatewayModelId(env.AI_GUARDIAN_MODEL) ?? DEFAULT_GUARDIAN_MODEL_ID;
776
826
  const handoffModelId = validateGatewayModelId(env.AI_HANDOFF_MODEL) ?? DEFAULT_HANDOFF_MODEL_ID;
777
827
  return {
778
828
  userName: toOptionalTrimmed(env.JUNIOR_BOT_NAME) ?? "junior",
@@ -786,6 +836,7 @@ function readBotConfig(env, functionMaxDurationSeconds) {
786
836
  ) ?? DEFAULT_MODEL_CONTEXT_WINDOW_TOKENS,
787
837
  reasoningLevel: reasoningLevel === void 0 ? void 0 : parseTurnReasoningLevel(reasoningLevel),
788
838
  fastModelId,
839
+ guardianModelId,
789
840
  imageGenerationModelId: toOptionalTrimmed(env.AI_IMAGE_MODEL) ?? DEFAULT_IMAGE_GENERATION_MODEL_ID,
790
841
  embeddingModelId: validateEmbeddingModelId(env.AI_EMBEDDING_MODEL) ?? DEFAULT_EMBEDDING_MODEL_ID,
791
842
  loadingMessages: parseLoadingMessages(env.JUNIOR_LOADING_MESSAGES),
@@ -39,7 +39,10 @@ function activityDays(days, nowMs, count) {
39
39
 
40
40
  // src/api/schema/conversation.ts
41
41
  import { z as z2 } from "zod";
42
- import { conversationAnnotationInputSchema } from "@sentry/junior-plugin-api";
42
+ import {
43
+ conversationAnnotationInputSchema,
44
+ conversationEventPresentationSchema
45
+ } from "@sentry/junior-plugin-api";
43
46
  var conversationReportStatusSchema = z2.enum([
44
47
  "active",
45
48
  "completed",
@@ -95,6 +98,7 @@ var conversationReportMessageEventDataSchema = z2.object({
95
98
  type: z2.literal("message"),
96
99
  messageId: z2.string().min(1),
97
100
  role: z2.enum(["assistant", "system", "user"]),
101
+ actorIdentity: actorIdentitySchema.optional(),
98
102
  eventType: z2.string().min(1).optional(),
99
103
  text: z2.string().optional(),
100
104
  redacted: z2.literal(true).optional()
@@ -105,6 +109,12 @@ var conversationReportMessageEventDataSchema = z2.object({
105
109
  message: "message content must be text or explicitly redacted"
106
110
  });
107
111
  }
112
+ if (data.redacted && data.actorIdentity) {
113
+ context.addIssue({
114
+ code: "custom",
115
+ message: "redacted messages must not expose actor identity"
116
+ });
117
+ }
108
118
  });
109
119
  var conversationReportMessageHandledEventDataSchema = z2.object({
110
120
  type: z2.literal("message_handled"),
@@ -210,6 +220,15 @@ var conversationReportTurnRoutedEventDataSchema = z2.object({
210
220
  confidence: z2.number().min(0).max(1).optional(),
211
221
  source: z2.enum(["configured", "inherited", "router"])
212
222
  }).strict();
223
+ var conversationReportGuardianActionReviewedEventDataSchema = z2.object({
224
+ type: z2.literal("guardian_action_reviewed"),
225
+ turnId: z2.string().min(1),
226
+ toolCallId: z2.string().min(1),
227
+ toolName: z2.string().min(1),
228
+ decision: z2.enum(["allow", "ask", "deny"]),
229
+ riskLevel: z2.enum(["low", "medium", "high", "critical"]),
230
+ userAuthorization: z2.enum(["high", "medium", "low", "unknown"])
231
+ }).strict();
213
232
  var conversationReportTurnContextEventDataSchema = z2.object({
214
233
  type: z2.literal("turn_context"),
215
234
  turnId: z2.string().min(1),
@@ -218,6 +237,14 @@ var conversationReportTurnContextEventDataSchema = z2.object({
218
237
  version: z2.number().int().positive(),
219
238
  content: z2.record(z2.string(), z2.unknown())
220
239
  }).strict();
240
+ var conversationReportPluginEventDataSchema = z2.object({
241
+ type: z2.literal("plugin_event"),
242
+ namespace: z2.string().min(1),
243
+ name: z2.string().min(1),
244
+ version: z2.number().int().positive(),
245
+ turnId: z2.string().min(1),
246
+ presentation: conversationEventPresentationSchema
247
+ }).strict();
221
248
  var conversationReportCompactionEventDataSchema = z2.object({
222
249
  type: z2.literal("compaction"),
223
250
  modelProfile: z2.string().min(1).optional(),
@@ -258,7 +285,9 @@ var conversationReportEventDataSchema = z2.discriminatedUnion("type", [
258
285
  conversationReportToolCallsEventDataSchema,
259
286
  conversationReportTurnLifecycleEventDataSchema,
260
287
  conversationReportTurnContextEventDataSchema,
288
+ conversationReportPluginEventDataSchema,
261
289
  conversationReportTurnRoutedEventDataSchema,
290
+ conversationReportGuardianActionReviewedEventDataSchema,
262
291
  conversationReportCompactionEventDataSchema,
263
292
  conversationReportHandoffEventDataSchema,
264
293
  conversationReportSubagentEventDataSchema
@@ -396,12 +425,29 @@ var conversationMetricDaySchema = z2.object({
396
425
  durationMs: z2.number(),
397
426
  tokens: z2.number().optional()
398
427
  }).strict();
428
+ var guardianMetricDaySchema = z2.object({
429
+ allow: z2.number(),
430
+ ask: z2.number(),
431
+ costUsd: z2.number().optional(),
432
+ date: z2.string(),
433
+ deny: z2.number(),
434
+ requests: z2.number()
435
+ }).strict();
436
+ var guardianStatsSchema = z2.object({
437
+ allow: z2.number(),
438
+ ask: z2.number(),
439
+ costUsd: z2.number().optional(),
440
+ deny: z2.number(),
441
+ metricDays: z2.array(guardianMetricDaySchema),
442
+ requests: z2.number()
443
+ }).strict();
399
444
  var conversationStatsReportSchema = z2.object({
400
445
  active: z2.number(),
401
446
  conversations: z2.number(),
402
447
  durationMs: z2.number(),
403
448
  failed: z2.number(),
404
449
  generatedAt: z2.string(),
450
+ guardian: guardianStatsSchema,
405
451
  metricDays: z2.array(conversationMetricDaySchema),
406
452
  locations: z2.array(conversationStatsItemSchema),
407
453
  actors: z2.array(conversationStatsItemSchema),
@@ -13,7 +13,7 @@ import {
13
13
  } from "./chunk-6GWA276C.js";
14
14
  import {
15
15
  getDeploymentTelemetryAttributes
16
- } from "./chunk-L2KJ2GNL.js";
16
+ } from "./chunk-VTWLP6YS.js";
17
17
 
18
18
  // src/chat/logging.ts
19
19
  import path from "path";
@@ -13,17 +13,17 @@ import {
13
13
  instructionProvenanceFor,
14
14
  sanitizePostgresJson,
15
15
  withConversationEventLock
16
- } from "./chunk-DOB5RVMH.js";
16
+ } from "./chunk-DVPWU77W.js";
17
17
  import {
18
18
  getStateAdapter,
19
19
  sleep
20
- } from "./chunk-TZVZCIYL.js";
20
+ } from "./chunk-ZOOZ25BO.js";
21
21
  import {
22
22
  botConfig,
23
23
  escapeXml,
24
24
  resolveGatewayModel,
25
25
  unwrapCurrentInstruction
26
- } from "./chunk-2RFM7STT.js";
26
+ } from "./chunk-JCJN6TPV.js";
27
27
  import {
28
28
  toStoredSlackActor
29
29
  } from "./chunk-HZF5P5UN.js";
@@ -32,7 +32,7 @@ import {
32
32
  logException,
33
33
  logWarn,
34
34
  setSpanAttributes
35
- } from "./chunk-4SPRQJOW.js";
35
+ } from "./chunk-JPG43UG7.js";
36
36
  import {
37
37
  isRecord,
38
38
  toOptionalNumber,
@@ -134,6 +134,16 @@ function instructionTextForProjection(text) {
134
134
  const withoutContext = text.replace(EMBEDDED_THREAD_CONTEXT_PATTERN, "").trim();
135
135
  return unwrapCurrentInstruction(withoutContext) ?? withoutContext;
136
136
  }
137
+ function getUserMessageInstructionText(message) {
138
+ if (getPiMessageRole(message) !== "user") {
139
+ return "";
140
+ }
141
+ const content = message.content;
142
+ const text = typeof content === "string" ? content : Array.isArray(content) ? content.flatMap(
143
+ (part) => part && typeof part === "object" && part.type === "text" && typeof part.text === "string" ? [part.text] : []
144
+ ).join("\n") : "";
145
+ return instructionTextForProjection(text).trim();
146
+ }
137
147
  function stripRuntimeTurnContext(messages) {
138
148
  return messages.flatMap((message) => {
139
149
  const content = userMessageContent(message);
@@ -1169,6 +1179,23 @@ async function recordToolExecutionStarted(args) {
1169
1179
  }
1170
1180
  ]);
1171
1181
  }
1182
+ async function recordGuardianActionReviewed(args) {
1183
+ await getConversationEventStore().append(args.conversationId, [
1184
+ {
1185
+ data: {
1186
+ type: "guardian_action_reviewed",
1187
+ turnId: args.turnId,
1188
+ toolCallId: args.toolCallId,
1189
+ toolName: args.toolName,
1190
+ ...args.costUsd !== void 0 ? { costUsd: args.costUsd } : {},
1191
+ decision: args.decision,
1192
+ riskLevel: args.riskLevel,
1193
+ userAuthorization: args.userAuthorization
1194
+ },
1195
+ createdAtMs: Date.now()
1196
+ }
1197
+ ]);
1198
+ }
1172
1199
 
1173
1200
  // src/chat/state/turn-id.ts
1174
1201
  function buildDeterministicTurnId(messageId) {
@@ -2829,6 +2856,7 @@ export {
2829
2856
  hasRuntimeTurnContext,
2830
2857
  retainRuntimeTurnContext,
2831
2858
  instructionTextForProjection,
2859
+ getUserMessageInstructionText,
2832
2860
  stripRuntimeTurnContext,
2833
2861
  historyItemFromPiMessage,
2834
2862
  piMessageFromHistoryItem,
@@ -2861,6 +2889,7 @@ export {
2861
2889
  loadTurnRoute,
2862
2890
  recordTurnRoute,
2863
2891
  recordToolExecutionStarted,
2892
+ recordGuardianActionReviewed,
2864
2893
  buildDeterministicTurnId,
2865
2894
  buildDeterministicAssistantMessageId,
2866
2895
  ConversationTurnBoundaryError,
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-PE44LDDQ.js";
4
4
  import {
5
5
  normalizeSlackConversationId
6
- } from "./chunk-USKP7IM2.js";
6
+ } from "./chunk-ZO4TL4OK.js";
7
7
  import {
8
8
  parseSlackThreadId
9
9
  } from "./chunk-S7G34U75.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createPluginCatalogRuntime
3
- } from "./chunk-GN6WW7WR.js";
3
+ } from "./chunk-XLPETJXX.js";
4
4
 
5
5
  // src/chat/plugins/catalog-runtime.ts
6
6
  var pluginCatalogRuntime = createPluginCatalogRuntime();