@sentry/junior 0.106.0 → 0.107.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 (132) hide show
  1. package/dist/{agent-hooks-KR5BCWOK.js → agent-hooks-ICPIJAFY.js} +9 -7
  2. package/dist/api/conversations/detail.d.ts +1 -1
  3. package/dist/api/conversations/events.d.ts +14 -0
  4. package/dist/api/conversations/schema.d.ts +196 -463
  5. package/dist/api/schema.d.ts +2 -7
  6. package/dist/api/schema.js +10 -8
  7. package/dist/api.js +377 -810
  8. package/dist/app.js +3586 -3614
  9. package/dist/{catalog-runtime-5CVM2DOF.js → catalog-runtime-FOFNPR3P.js} +3 -2
  10. package/dist/chat/agent/prompt.d.ts +1 -1
  11. package/dist/chat/agent/request.d.ts +28 -29
  12. package/dist/chat/agent/resume.d.ts +7 -7
  13. package/dist/chat/agent/session.d.ts +5 -6
  14. package/dist/chat/agent/tools.d.ts +3 -3
  15. package/dist/chat/agent-dispatch/runner.d.ts +2 -0
  16. package/dist/chat/config.d.ts +2 -2
  17. package/dist/chat/conversations/history.d.ts +582 -167
  18. package/dist/chat/conversations/message-projection.d.ts +6 -0
  19. package/dist/chat/conversations/message-summaries.d.ts +9 -0
  20. package/dist/chat/conversations/messages.d.ts +13 -27
  21. package/dist/chat/conversations/projection.d.ts +30 -53
  22. package/dist/chat/conversations/provenance.d.ts +42 -0
  23. package/dist/chat/conversations/search.d.ts +2 -2
  24. package/dist/chat/conversations/sql/conversation-row.d.ts +1 -1
  25. package/dist/chat/conversations/sql/event-lock.d.ts +3 -0
  26. package/dist/chat/conversations/sql/history.d.ts +3 -3
  27. package/dist/chat/conversations/sql/privacy.d.ts +27 -0
  28. package/dist/chat/conversations/sql/purge.d.ts +2 -10
  29. package/dist/chat/conversations/sql/store.d.ts +0 -5
  30. package/dist/chat/conversations/store.d.ts +8 -13
  31. package/dist/chat/conversations/turn-lifecycle.d.ts +41 -0
  32. package/dist/chat/db.d.ts +4 -10
  33. package/dist/chat/model-profile.d.ts +10 -0
  34. package/dist/chat/oauth-flow.d.ts +0 -5
  35. package/dist/chat/pi/conversation-events.d.ts +33 -0
  36. package/dist/chat/pi/sql-model-usage.d.ts +10 -0
  37. package/dist/chat/plugins/agent-hooks.d.ts +4 -2
  38. package/dist/chat/resource-events/ingest.d.ts +0 -13
  39. package/dist/chat/runtime/delivered-turn-state.d.ts +1 -1
  40. package/dist/chat/runtime/generated-artifacts.d.ts +1 -1
  41. package/dist/chat/runtime/reply-executor.d.ts +2 -0
  42. package/dist/chat/runtime/slack-resume.d.ts +23 -28
  43. package/dist/chat/runtime/slack-runtime.d.ts +2 -0
  44. package/dist/chat/runtime/turn.d.ts +14 -1
  45. package/dist/chat/services/context-compaction-marker.d.ts +0 -1
  46. package/dist/chat/services/context-compaction.d.ts +1 -0
  47. package/dist/chat/services/conversation-memory.d.ts +9 -0
  48. package/dist/chat/services/plugin-auth-orchestration.d.ts +1 -4
  49. package/dist/chat/services/subscribed-decision.d.ts +1 -1
  50. package/dist/chat/services/turn-failure-response.d.ts +10 -3
  51. package/dist/chat/services/turn-result.d.ts +7 -12
  52. package/dist/chat/services/{turn-reasoning-level.d.ts → turn-router.d.ts} +12 -8
  53. package/dist/chat/services/turn-session-record.d.ts +15 -16
  54. package/dist/chat/slack/adapter.d.ts +2 -2
  55. package/dist/chat/slack/errors.d.ts +2 -0
  56. package/dist/chat/slack/outbound.d.ts +0 -1
  57. package/dist/chat/slack/reply.d.ts +2 -8
  58. package/dist/chat/slack/tools/channel-capabilities.d.ts +2 -2
  59. package/dist/chat/slack/tools/{send-message.d.ts → send-files.d.ts} +27 -19
  60. package/dist/chat/state/conversation.d.ts +4 -4
  61. package/dist/chat/state/turn-id.d.ts +2 -0
  62. package/dist/chat/state/turn-session-keys.d.ts +6 -0
  63. package/dist/chat/state/turn-session.d.ts +11 -9
  64. package/dist/chat/task-execution/state.d.ts +6 -1
  65. package/dist/chat/task-execution/store.d.ts +1 -1
  66. package/dist/chat/tool-support/pi-tool-adapter.d.ts +1 -1
  67. package/dist/chat/tool-support/tool-execution-report.d.ts +1 -0
  68. package/dist/chat/tools/handoff/tool.d.ts +2 -2
  69. package/dist/chat/tools/sandbox/file-uploads.d.ts +28 -6
  70. package/dist/chat/tools/types.d.ts +6 -9
  71. package/dist/chat/tools/web/image-generate.d.ts +4 -6
  72. package/dist/{chunk-DDRQ4U7I.js → chunk-4YF7Z6IA.js} +390 -270
  73. package/dist/{chunk-AZ5OMSN5.js → chunk-AUUOHQAT.js} +2 -2
  74. package/dist/chunk-B2Z2H66D.js +250 -0
  75. package/dist/{chunk-4W4O4DCV.js → chunk-CQ7KSO2B.js} +75 -45
  76. package/dist/{chunk-MJSJAHBW.js → chunk-DY7TRYB5.js} +1 -1
  77. package/dist/{chunk-GPPUTY5M.js → chunk-EDLNHZH3.js} +861 -891
  78. package/dist/{chunk-R5BFYK2O.js → chunk-IGHMVDWI.js} +134 -18
  79. package/dist/chunk-MU6HHZEN.js +99 -0
  80. package/dist/{chunk-XTKJPSMF.js → chunk-NVOTGWYX.js} +458 -684
  81. package/dist/{chunk-AEWZ7F65.js → chunk-O24R4DCK.js} +2 -179
  82. package/dist/{chunk-CCFROYAV.js → chunk-PUAMO4PI.js} +115 -125
  83. package/dist/{chunk-ZMRLBBD5.js → chunk-RMVOAJRL.js} +30 -13
  84. package/dist/{chunk-3NYUCBLE.js → chunk-SPUAJVVH.js} +6 -4
  85. package/dist/{chunk-4UYIRWDW.js → chunk-SS67LUOK.js} +41 -290
  86. package/dist/{chunk-FXFQNHRU.js → chunk-VFUK3X5B.js} +4 -2
  87. package/dist/{chunk-3MPPVPGZ.js → chunk-VH6KWKG2.js} +2 -2
  88. package/dist/chunk-VIXFG2VC.js +182 -0
  89. package/dist/{chunk-BKM4UXUD.js → chunk-YFQ7CQDE.js} +669 -18
  90. package/dist/{chunk-77LHNQK4.js → chunk-YIPD3L6L.js} +4 -2
  91. package/dist/{chunk-3OUSJPR7.js → chunk-YNP2ATQX.js} +6 -4
  92. package/dist/{chunk-WR7H7VLJ.js → chunk-YT72TOEK.js} +2 -2
  93. package/dist/cli/chat.js +21 -20
  94. package/dist/cli/check.js +4 -3
  95. package/dist/cli/plugins.js +11 -9
  96. package/dist/cli/snapshot-warmup.js +7 -5
  97. package/dist/cli/upgrade.js +2046 -105
  98. package/dist/db/schema/{agent-steps.d.ts → conversation-events.d.ts} +37 -21
  99. package/dist/db/schema.d.ts +28 -159
  100. package/dist/{db-S33LFWG2.js → db-DIGO4TGW.js} +6 -8
  101. package/dist/{runner-HA5XAL6K.js → runner-ACR2HAIC.js} +209 -101
  102. package/dist/{skills-722AXRV5.js → skills-ITNHBARB.js} +4 -3
  103. package/dist/{validation-EUI2UFRM.js → validation-AGQ46ZGV.js} +4 -3
  104. package/migrations/0005_conversation_events.sql +122 -0
  105. package/migrations/README.md +23 -10
  106. package/migrations/meta/0005_snapshot.json +948 -0
  107. package/migrations/meta/_journal.json +7 -0
  108. package/package.json +5 -5
  109. package/dist/api/conversations/activity.d.ts +0 -40
  110. package/dist/api/conversations/detail-projection.d.ts +0 -11
  111. package/dist/api/conversations/detail.query.d.ts +0 -3
  112. package/dist/api/conversations/subagent.d.ts +0 -10
  113. package/dist/api/conversations/transcript.d.ts +0 -28
  114. package/dist/chat/conversations/legacy-advisor-session.d.ts +0 -7
  115. package/dist/chat/conversations/legacy-import.d.ts +0 -38
  116. package/dist/chat/conversations/sql/legacy-history-import.d.ts +0 -55
  117. package/dist/chat/conversations/sql/messages.d.ts +0 -4
  118. package/dist/chat/conversations/visible-compactions.d.ts +0 -11
  119. package/dist/chat/conversations/visible-messages.d.ts +0 -47
  120. package/dist/chat/services/reply-delivery-plan.d.ts +0 -5
  121. package/dist/chat/state/session-log.d.ts +0 -384
  122. package/dist/chunk-P4P7O5WG.js +0 -1072
  123. package/dist/chunk-XIMUQ4IU.js +0 -147
  124. package/dist/db/schema/conversation-messages.d.ts +0 -153
  125. package/dist/handlers/github-webhook/check-suite.d.ts +0 -3
  126. package/dist/handlers/github-webhook/issue-comment.d.ts +0 -3
  127. package/dist/handlers/github-webhook/pull-request-review-comment.d.ts +0 -3
  128. package/dist/handlers/github-webhook/pull-request-review.d.ts +0 -3
  129. package/dist/handlers/github-webhook/pull-request.d.ts +0 -3
  130. package/dist/handlers/github-webhook/resource.d.ts +0 -10
  131. package/dist/handlers/github-webhook.d.ts +0 -15
  132. package/dist/legacy-import-TMJISRKO.js +0 -18
@@ -3,7 +3,14 @@ import {
3
3
  } from "./chunk-CEA3A3UA.js";
4
4
  import {
5
5
  normalizeSlackConversationId
6
- } from "./chunk-3MPPVPGZ.js";
6
+ } from "./chunk-VH6KWKG2.js";
7
+ import {
8
+ juniorConversationEvents,
9
+ juniorConversations
10
+ } from "./chunk-NVOTGWYX.js";
11
+ import {
12
+ juniorDestinations
13
+ } from "./chunk-VFUK3X5B.js";
7
14
  import {
8
15
  parseSlackThreadId
9
16
  } from "./chunk-RT5BUHR5.js";
@@ -58,24 +65,132 @@ function buildSentryConversationUrl(conversationId) {
58
65
  }
59
66
  return `${buildSentryWebBaseUrl(dsn)}/organizations/${orgSlug}/${path}`;
60
67
  }
61
- function buildSentryTraceUrl(traceId) {
62
- const client = getClient();
63
- const dsn = client?.getDsn();
64
- if (!dsn?.host || !dsn.projectId) {
65
- return void 0;
66
- }
67
- const orgSlug = getSentryOrgSlug();
68
- if (!orgSlug) {
69
- return void 0;
68
+
69
+ // src/chat/conversations/sql/privacy.ts
70
+ import { and, asc, eq, getTableColumns, inArray, sql } from "drizzle-orm";
71
+ var MAX_LINEAGE_DEPTH = 32;
72
+ var conversationEventColumns = getTableColumns(juniorConversationEvents);
73
+ function rootVisibilitySnapshotSql(conversationId) {
74
+ return sql`(
75
+ with recursive lineage(
76
+ conversation_id,
77
+ parent_conversation_id,
78
+ destination_id,
79
+ path,
80
+ depth
81
+ ) as (
82
+ select
83
+ requested.conversation_id,
84
+ requested.parent_conversation_id,
85
+ requested.destination_id,
86
+ array[requested.conversation_id]::text[],
87
+ 1
88
+ from junior_conversations requested
89
+ where requested.conversation_id = ${conversationId}
90
+
91
+ union all
92
+
93
+ select
94
+ parent.conversation_id,
95
+ parent.parent_conversation_id,
96
+ parent.destination_id,
97
+ lineage.path || parent.conversation_id,
98
+ lineage.depth + 1
99
+ from lineage
100
+ join junior_conversations parent
101
+ on parent.conversation_id = lineage.parent_conversation_id
102
+ where lineage.depth < ${MAX_LINEAGE_DEPTH}
103
+ and not (parent.conversation_id = any(lineage.path))
104
+ ),
105
+ root_candidate as (
106
+ select lineage.conversation_id, lineage.destination_id
107
+ from lineage
108
+ where lineage.parent_conversation_id is null
109
+ and lineage.destination_id is not null
110
+ limit 1
111
+ )
112
+ select jsonb_build_object(
113
+ 'rootConversationId', coalesce(root.conversation_id, ${conversationId}),
114
+ 'visibility', destination.visibility
115
+ )
116
+ from (select 1) seed
117
+ left join root_candidate root on true
118
+ left join junior_destinations destination
119
+ on destination.id = root.destination_id
120
+ )`;
121
+ }
122
+ async function readConversationEventPrivacySnapshot(executor, args) {
123
+ const rows = await executor.db().select({
124
+ privacy: rootVisibilitySnapshotSql(args.conversationId),
125
+ event: {
126
+ ...conversationEventColumns,
127
+ // Replacement history is model context, never dashboard report data.
128
+ // Keep the required replacement field while redacting its contents.
129
+ payload: sql`case
130
+ when ${juniorConversationEvents.type} in ('compaction', 'handoff')
131
+ then jsonb_set(
132
+ ${juniorConversationEvents.payload},
133
+ '{replacementHistory}',
134
+ '[]'::jsonb
135
+ )
136
+ else ${juniorConversationEvents.payload}
137
+ end`
138
+ }
139
+ }).from(juniorConversations).leftJoin(
140
+ juniorConversationEvents,
141
+ and(
142
+ eq(juniorConversationEvents.conversationId, args.conversationId),
143
+ inArray(juniorConversationEvents.type, [...args.eventTypes])
144
+ )
145
+ ).where(eq(juniorConversations.conversationId, args.conversationId)).orderBy(asc(juniorConversationEvents.seq));
146
+ const first = rows[0];
147
+ if (!first) return void 0;
148
+ return {
149
+ ...first.privacy,
150
+ events: rows.flatMap(({ event }) => event ? [event] : [])
151
+ };
152
+ }
153
+ async function readLineageRow(executor, conversationId) {
154
+ const rows = await executor.db().select({
155
+ parentId: juniorConversations.parentConversationId,
156
+ destinationId: juniorConversations.destinationId
157
+ }).from(juniorConversations).where(eq(juniorConversations.conversationId, conversationId));
158
+ return rows[0];
159
+ }
160
+ async function traceLineage(executor, conversationId) {
161
+ let currentId = conversationId;
162
+ const seen = /* @__PURE__ */ new Set();
163
+ while (!seen.has(currentId) && seen.size < MAX_LINEAGE_DEPTH) {
164
+ seen.add(currentId);
165
+ const row = await readLineageRow(executor, currentId);
166
+ if (!row) return void 0;
167
+ if (row.parentId) {
168
+ currentId = row.parentId;
169
+ continue;
170
+ }
171
+ if (!row.destinationId) {
172
+ return void 0;
173
+ }
174
+ return {
175
+ destinationId: row.destinationId,
176
+ rootConversationId: currentId
177
+ };
70
178
  }
71
- const encodedTraceId = encodeURIComponent(traceId);
72
- const params = new URLSearchParams();
73
- params.set("project", dsn.projectId);
74
- const path = `performance/trace/${encodedTraceId}/?${params.toString()}`;
75
- if (isSentrySaasDsnHost(dsn.host)) {
76
- return `https://${orgSlug}.sentry.io/${path}`;
179
+ return void 0;
180
+ }
181
+ async function readCandidateVisibility(executor, candidate) {
182
+ const destinations = await executor.db().select({ visibility: juniorDestinations.visibility }).from(juniorDestinations).where(eq(juniorDestinations.id, candidate.destinationId)).for("share");
183
+ return {
184
+ rootConversationId: candidate.rootConversationId,
185
+ visibility: destinations[0]?.visibility ?? null
186
+ };
187
+ }
188
+ async function resolveRootVisibility(executor, conversationId) {
189
+ const candidate = await traceLineage(executor, conversationId);
190
+ if (!candidate) {
191
+ return { rootConversationId: conversationId, visibility: null };
77
192
  }
78
- return `${buildSentryWebBaseUrl(dsn)}/organizations/${orgSlug}/${path}`;
193
+ return readCandidateVisibility(executor, candidate);
79
194
  }
80
195
 
81
196
  // src/chat/slack/conversation-context.ts
@@ -164,7 +279,8 @@ export {
164
279
  readHealthReport,
165
280
  GET,
166
281
  buildSentryConversationUrl,
167
- buildSentryTraceUrl,
282
+ readConversationEventPrivacySnapshot,
283
+ resolveRootVisibility,
168
284
  conversationVisibilityFromSlackChannelType,
169
285
  resolveSlackChannelTypeFromMessage,
170
286
  resolveSlackConversationContext,
@@ -0,0 +1,99 @@
1
+ import {
2
+ usageSchema
3
+ } from "./chunk-PDO5BLNM.js";
4
+
5
+ // src/chat/usage.ts
6
+ var agentTurnUsageSchema = usageSchema;
7
+ var COMPONENT_USAGE_FIELDS = [
8
+ "inputTokens",
9
+ "outputTokens",
10
+ "cachedInputTokens",
11
+ "cacheCreationTokens"
12
+ ];
13
+ var COST_COMPONENT_FIELDS = [
14
+ "input",
15
+ "output",
16
+ "cacheRead",
17
+ "cacheWrite"
18
+ ];
19
+ function hasAgentTurnUsage(usage) {
20
+ return Boolean(
21
+ usage && (Object.entries(usage).some(
22
+ ([field, value]) => field !== "cost" && typeof value === "number" && Number.isFinite(value)
23
+ ) || Object.values(usage.cost ?? {}).some(
24
+ (value) => typeof value === "number" && Number.isFinite(value)
25
+ ))
26
+ );
27
+ }
28
+ function getFiniteCount(value) {
29
+ return typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.floor(value)) : void 0;
30
+ }
31
+ function getFiniteCost(value) {
32
+ return typeof value === "number" && Number.isFinite(value) ? Math.max(0, value) : void 0;
33
+ }
34
+ function addCost(left, right) {
35
+ return Math.round(((left ?? 0) + right) * 1e12) / 1e12;
36
+ }
37
+ function getComponentTotal(usage) {
38
+ let total;
39
+ for (const field of COMPONENT_USAGE_FIELDS) {
40
+ const value = getFiniteCount(usage[field]);
41
+ if (value === void 0) continue;
42
+ total = (total ?? 0) + value;
43
+ }
44
+ return total;
45
+ }
46
+ function addAgentTurnUsage(...usages) {
47
+ const components = {};
48
+ let componentTotal;
49
+ let totalOnlyTokens;
50
+ let reasoningTokens;
51
+ const cost = {};
52
+ for (const usage of usages) {
53
+ if (!usage) continue;
54
+ const reasoning = getFiniteCount(usage.reasoningTokens);
55
+ if (reasoning !== void 0) {
56
+ reasoningTokens = (reasoningTokens ?? 0) + reasoning;
57
+ }
58
+ if (usage.cost) {
59
+ for (const field of [...COST_COMPONENT_FIELDS, "total"]) {
60
+ const value = getFiniteCost(usage.cost[field]);
61
+ if (value === void 0) continue;
62
+ cost[field] = addCost(cost[field], value);
63
+ }
64
+ }
65
+ const usageComponentTotal = getComponentTotal(usage);
66
+ if (usageComponentTotal !== void 0) {
67
+ componentTotal = (componentTotal ?? 0) + usageComponentTotal;
68
+ for (const field of COMPONENT_USAGE_FIELDS) {
69
+ const value = getFiniteCount(usage[field]);
70
+ if (value === void 0) continue;
71
+ components[field] = (components[field] ?? 0) + value;
72
+ }
73
+ continue;
74
+ }
75
+ const totalTokens = getFiniteCount(usage.totalTokens);
76
+ if (totalTokens !== void 0) {
77
+ totalOnlyTokens = (totalOnlyTokens ?? 0) + totalTokens;
78
+ }
79
+ }
80
+ if (totalOnlyTokens !== void 0) {
81
+ return {
82
+ totalTokens: totalOnlyTokens + (componentTotal ?? 0),
83
+ ...reasoningTokens !== void 0 ? { reasoningTokens } : {},
84
+ ...Object.keys(cost).length > 0 ? { cost } : {}
85
+ };
86
+ }
87
+ const result = {
88
+ ...components,
89
+ ...reasoningTokens !== void 0 ? { reasoningTokens } : {},
90
+ ...Object.keys(cost).length > 0 ? { cost } : {}
91
+ };
92
+ return hasAgentTurnUsage(result) ? result : void 0;
93
+ }
94
+
95
+ export {
96
+ agentTurnUsageSchema,
97
+ hasAgentTurnUsage,
98
+ addAgentTurnUsage
99
+ };