@sentry/junior 0.147.0 → 0.148.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 (155) hide show
  1. package/dist/{agent-hooks-HS6VGUPM.js → agent-hooks-VAUYT6PD.js} +10 -10
  2. package/dist/api/conversations/access.d.ts +2 -1
  3. package/dist/api/conversations/archive.d.ts +3 -5
  4. package/dist/api/conversations/create.d.ts +6 -0
  5. package/dist/api/conversations/detail.d.ts +2 -296
  6. package/dist/api/conversations/event-list.d.ts +2 -193
  7. package/dist/api/conversations/list.d.ts +4 -66
  8. package/dist/api/conversations/routes.d.ts +1 -1
  9. package/dist/api/conversations/stats.d.ts +0 -54
  10. package/dist/api/http.d.ts +2 -6
  11. package/dist/api/locations/detail.d.ts +3 -111
  12. package/dist/api/locations/list.d.ts +0 -45
  13. package/dist/api/locations/query.d.ts +2 -1
  14. package/dist/api/locations/routes.d.ts +1 -1
  15. package/dist/api/people/list.d.ts +0 -29
  16. package/dist/api/people/profile.d.ts +2 -106
  17. package/dist/api/people/profile.query.d.ts +2 -1
  18. package/dist/api/people/routes.d.ts +1 -1
  19. package/dist/api/people/shared.d.ts +1 -1
  20. package/dist/api/people/spend.d.ts +3 -4
  21. package/dist/api/personal-tokens/routes.d.ts +2 -2
  22. package/dist/api/route.d.ts +8 -14
  23. package/dist/api/schema/conversation.d.ts +60 -29
  24. package/dist/api/schema/location.d.ts +4 -0
  25. package/dist/api/schema/person.d.ts +7 -3
  26. package/dist/api/schema.d.ts +2 -2
  27. package/dist/api/schema.js +7 -1
  28. package/dist/api/stats.d.ts +0 -13
  29. package/dist/api/validation.d.ts +7 -0
  30. package/dist/api/viewer.d.ts +3 -0
  31. package/dist/api.d.ts +2 -1
  32. package/dist/api.js +624 -562
  33. package/dist/app.js +183 -105
  34. package/dist/{catalog-runtime-M6ZTPYRV.js → catalog-runtime-WADOZVTB.js} +5 -5
  35. package/dist/chat/actor.d.ts +4 -1
  36. package/dist/chat/agent/request.d.ts +2 -0
  37. package/dist/chat/agent/resume.d.ts +1 -0
  38. package/dist/chat/agent-dispatch/context.d.ts +2 -2
  39. package/dist/chat/agent-invocations/types.d.ts +52 -0
  40. package/dist/chat/api-turns/work.d.ts +103 -0
  41. package/dist/chat/conversations/history.d.ts +60 -0
  42. package/dist/chat/conversations/provenance.d.ts +6 -0
  43. package/dist/chat/conversations/sql/actor-identity.d.ts +19 -0
  44. package/dist/chat/conversations/store.d.ts +1 -1
  45. package/dist/chat/resource-events/store.d.ts +1 -1
  46. package/dist/chat/runtime/reply-executor.d.ts +1 -1
  47. package/dist/chat/runtime/slack-runtime.d.ts +2 -1
  48. package/dist/chat/runtime/turn-preparation.d.ts +9 -0
  49. package/dist/chat/scheduled-tasks/tool-support.d.ts +5 -5
  50. package/dist/chat/scheduled-tasks/tools/create.d.ts +2 -2
  51. package/dist/chat/scheduled-tasks/tools/delete.d.ts +2 -2
  52. package/dist/chat/scheduled-tasks/tools/list.d.ts +2 -2
  53. package/dist/chat/scheduled-tasks/tools/run-now.d.ts +2 -2
  54. package/dist/chat/scheduled-tasks/tools/update.d.ts +2 -2
  55. package/dist/chat/slack/channel.d.ts +26 -0
  56. package/dist/chat/slack/dispatch-turn.d.ts +1 -0
  57. package/dist/chat/slack/timestamp-param.d.ts +0 -2
  58. package/dist/chat/slack/{tools → tool-support}/canvas/api.d.ts +1 -1
  59. package/dist/chat/slack/{tools → tool-support}/canvas/context.d.ts +3 -0
  60. package/dist/chat/slack/tool-support/channel-access.d.ts +42 -0
  61. package/dist/chat/slack/tool-support/channel-target.d.ts +27 -0
  62. package/dist/chat/slack/tool-support/list/params.d.ts +5 -0
  63. package/dist/chat/slack/tools/canvas/create.d.ts +1 -1
  64. package/dist/chat/slack/tools/channel-join.d.ts +28 -0
  65. package/dist/chat/slack/tools/channel-list-messages.d.ts +3 -2
  66. package/dist/chat/slack/tools/conversation-message-search.d.ts +2 -8
  67. package/dist/chat/slack/tools/message-add-reaction.d.ts +1 -1
  68. package/dist/chat/slack/tools/public-search.d.ts +63 -2
  69. package/dist/chat/slack/tools/send-files.d.ts +1 -1
  70. package/dist/chat/slack/tools/thread-read.d.ts +2 -5
  71. package/dist/chat/source.d.ts +2 -0
  72. package/dist/chat/task-execution/checkpoint.d.ts +1 -0
  73. package/dist/chat/task-execution/state.d.ts +9 -4
  74. package/dist/chat/task-execution/store.d.ts +3 -2
  75. package/dist/chat/task-execution/turn-cursor.d.ts +2 -0
  76. package/dist/chat/task-execution/worker.d.ts +2 -0
  77. package/dist/chat/tasks/read.d.ts +1 -1
  78. package/dist/chat/tools/search-conversation-events.d.ts +1 -1
  79. package/dist/chat/tools/types.d.ts +11 -4
  80. package/dist/chat/tools/watch-resource-events.d.ts +2 -2
  81. package/dist/{chunk-ORO3PWKQ.js → chunk-2B3PT3V2.js} +1 -1
  82. package/dist/{chunk-SVHUEHUL.js → chunk-45LOR4PU.js} +21 -4
  83. package/dist/{chunk-YBVXBNSV.js → chunk-4AQZYNHM.js} +2 -2
  84. package/dist/{chunk-Z4YU7Z4L.js → chunk-4EA2SFK2.js} +65 -4
  85. package/dist/{chunk-7NVJVJID.js → chunk-4GXJUYJV.js} +2 -2
  86. package/dist/{chunk-IIOOO4FQ.js → chunk-55F4QU2V.js} +2 -1
  87. package/dist/{chunk-745QJ3ZA.js → chunk-7OEIXFC3.js} +2 -2
  88. package/dist/{chunk-DU74WPIC.js → chunk-D3WPMGEX.js} +1 -1
  89. package/dist/{chunk-PVNG6UMU.js → chunk-D6YX4NNN.js} +22 -10
  90. package/dist/chunk-DUY5CDAM.js +36 -0
  91. package/dist/{chunk-4LJO56OJ.js → chunk-EAI67NTM.js} +1 -1
  92. package/dist/{chunk-X5UY34KT.js → chunk-EINWQFXI.js} +8 -8
  93. package/dist/chunk-GDFF3BQG.js +136 -0
  94. package/dist/{chunk-EFLJ2WJH.js → chunk-GXYDVZKM.js} +5 -5
  95. package/dist/{chunk-CWP5RHVX.js → chunk-HLPLT3NY.js} +8 -5
  96. package/dist/{chunk-JUUKWRBE.js → chunk-HWQGBIH7.js} +1 -1
  97. package/dist/{chunk-AZ7EAOBE.js → chunk-IL4EDBMV.js} +5 -5
  98. package/dist/{chunk-DLDRQHG5.js → chunk-LAZGHEYU.js} +1 -1
  99. package/dist/{chunk-RXBVB2JM.js → chunk-LE5H7LMT.js} +1 -1
  100. package/dist/chunk-LNVEIJ2L.js +48 -0
  101. package/dist/{chunk-YEO3VX72.js → chunk-OJCP3C3J.js} +8 -6
  102. package/dist/{chunk-GGB4WL5A.js → chunk-POSZWRGL.js} +1 -1
  103. package/dist/{chunk-YNTTROJT.js → chunk-QOWHHM3F.js} +1 -1
  104. package/dist/{chunk-6H5SZR24.js → chunk-RRJV5UR5.js} +302 -59
  105. package/dist/{chunk-AYU72WO7.js → chunk-ULAU5ZGU.js} +41 -64
  106. package/dist/{chunk-SGZO7UWH.js → chunk-V2FXMOEA.js} +2 -2
  107. package/dist/{chunk-AIOK6LAG.js → chunk-VCYSOXON.js} +272 -41
  108. package/dist/{chunk-7A4M7PCV.js → chunk-VMNRXKAH.js} +1166 -540
  109. package/dist/{chunk-YSB2N563.js → chunk-VRHTNBA6.js} +121 -87
  110. package/dist/{chunk-AVZDSUFB.js → chunk-VY6W3T43.js} +4 -4
  111. package/dist/{chunk-7UQIVT6G.js → chunk-WCN4YSH7.js} +6 -6
  112. package/dist/{chunk-CSZINQJ2.js → chunk-WOONT5ZP.js} +1 -1
  113. package/dist/{chunk-Q4R73I43.js → chunk-XJ42NBP5.js} +58 -28
  114. package/dist/{chunk-YHDERDRO.js → chunk-ZCHIC2GM.js} +91 -75
  115. package/dist/chunk-ZPL2RR7F.js +798 -0
  116. package/dist/cli/chat.js +33 -35
  117. package/dist/cli/check.js +6 -6
  118. package/dist/cli/plugins.js +13 -13
  119. package/dist/cli/snapshot-create.js +9 -9
  120. package/dist/cli/upgrade.js +7 -7
  121. package/dist/db/schema/agent-invocations.d.ts +20 -0
  122. package/dist/db/schema/conversation-annotations.d.ts +2 -2
  123. package/dist/db/schema.d.ts +22 -2
  124. package/dist/{db-CSEW4RII.js → db-XUKZRFFK.js} +7 -7
  125. package/dist/instrumentation.js +4 -4
  126. package/dist/nitro.js +2 -2
  127. package/dist/{oauth-callback-server-FUEV5HNG.js → oauth-callback-server-LPZMMGFI.js} +25 -26
  128. package/dist/{runner-U3XHSKSH.js → runner-DGKUTMPX.js} +17 -18
  129. package/dist/{skills-AKE6W3WI.js → skills-P7YUFSXM.js} +6 -6
  130. package/dist/spawn-DSK3ZEVD.js +38 -0
  131. package/dist/{validation-WDTAULUF.js → validation-S7U5M5NR.js} +6 -6
  132. package/dist/version.js +1 -1
  133. package/dist/{work-C3HAO2BG.js → work-GAA7TVAD.js} +18 -19
  134. package/dist/{worker-LNP4YKBM.js → worker-JXPJH3QB.js} +11 -10
  135. package/package.json +5 -4
  136. package/dist/api/health.d.ts +0 -7
  137. package/dist/api/personal-tokens/create.d.ts +0 -11
  138. package/dist/api/personal-tokens/list.d.ts +0 -12
  139. package/dist/api/personal-tokens/revoke.d.ts +0 -5
  140. package/dist/api/plugin-reports.d.ts +0 -63
  141. package/dist/api/plugins.d.ts +0 -8
  142. package/dist/api/runtime.d.ts +0 -24
  143. package/dist/api/skills.d.ts +0 -6
  144. package/dist/chat/slack/tools/channel-access.d.ts +0 -30
  145. package/dist/chunk-34GS7B6L.js +0 -115
  146. package/dist/chunk-AVOCH2Z5.js +0 -285
  147. package/dist/chunk-HLXXQI5Q.js +0 -238
  148. package/dist/chunk-K4SZAP3K.js +0 -67
  149. package/dist/chunk-R776HKPK.js +0 -81
  150. package/dist/spawn-B6GDTWJ4.js +0 -39
  151. /package/dist/chat/slack/{tools → tool-support}/canvas/markdown.d.ts +0 -0
  152. /package/dist/chat/slack/{tools → tool-support}/channel-capabilities.d.ts +0 -0
  153. /package/dist/chat/slack/{tools → tool-support}/context.d.ts +0 -0
  154. /package/dist/chat/slack/{tools → tool-support}/list/api.d.ts +0 -0
  155. /package/dist/chat/slack/{tools → tool-support}/slack-message-url.d.ts +0 -0
@@ -1,285 +0,0 @@
1
- import {
2
- getDb
3
- } from "./chunk-YSB2N563.js";
4
- import {
5
- juniorConversations,
6
- juniorTaskExecutions
7
- } from "./chunk-DU74WPIC.js";
8
- import {
9
- logWarn
10
- } from "./chunk-4LJO56OJ.js";
11
-
12
- // src/chat/tasks/execution-stats.ts
13
- import {
14
- and,
15
- asc,
16
- count,
17
- desc,
18
- eq,
19
- gte,
20
- inArray,
21
- lte,
22
- max,
23
- or,
24
- sql
25
- } from "drizzle-orm";
26
- var TASK_EXECUTION_TYPES = ["scheduled", "event"];
27
- var TASK_EXECUTION_STATUSES = [
28
- "blocked",
29
- "completed",
30
- "failed"
31
- ];
32
- function utcDate(nowMs) {
33
- return new Date(nowMs).toISOString().slice(0, 10);
34
- }
35
- function emptyDay(date) {
36
- return { date, event: 0, scheduled: 0 };
37
- }
38
- function emptyStatusDay(date) {
39
- return { blocked: 0, completed: 0, date, failed: 0 };
40
- }
41
- async function recordTaskExecution(type, taskId, options) {
42
- const namespace = options.namespace ?? "junior";
43
- const nowMs = options.nowMs ?? Date.now();
44
- const status = options.status ?? "completed";
45
- try {
46
- await getDb().insert(juniorTaskExecutions).values({
47
- ...options.conversationId ? { conversationId: options.conversationId } : {},
48
- executedAtMs: nowMs,
49
- executionId: options.executionId,
50
- kind: type,
51
- namespace,
52
- status,
53
- taskId
54
- }).onConflictDoNothing({
55
- target: [
56
- juniorTaskExecutions.kind,
57
- juniorTaskExecutions.namespace,
58
- juniorTaskExecutions.executionId
59
- ]
60
- });
61
- } catch (error) {
62
- logWarn("task.execution.stat_failed", {
63
- error,
64
- "app.task.execution.id": options.executionId,
65
- "app.task.execution.namespace": namespace,
66
- "app.task.execution.status": status,
67
- "app.task.execution.task_id": taskId,
68
- "app.task.execution.type": type
69
- });
70
- }
71
- }
72
- async function readTaskExecutionSummaries(type, namespace, options = {}) {
73
- const sevenDaysAgoMs = (options.nowMs ?? Date.now()) - 7 * 24 * 60 * 60 * 1e3;
74
- const db = getDb();
75
- const latest = db.selectDistinctOn([juniorTaskExecutions.taskId], {
76
- conversationId: juniorTaskExecutions.conversationId,
77
- taskId: juniorTaskExecutions.taskId
78
- }).from(juniorTaskExecutions).where(
79
- and(
80
- eq(juniorTaskExecutions.kind, type),
81
- eq(juniorTaskExecutions.namespace, namespace)
82
- )
83
- ).orderBy(
84
- juniorTaskExecutions.taskId,
85
- desc(juniorTaskExecutions.executedAtMs),
86
- desc(juniorTaskExecutions.executionId)
87
- ).as("latest_task_execution");
88
- const rows = await db.select({
89
- lastConversationId: latest.conversationId,
90
- lastExecutedAtMs: max(juniorTaskExecutions.executedAtMs),
91
- runsLast7Days: sql`count(*) filter (where ${juniorTaskExecutions.executedAtMs} >= ${sevenDaysAgoMs})::int`,
92
- taskId: juniorTaskExecutions.taskId,
93
- totalRuns: sql`count(*)::int`
94
- }).from(juniorTaskExecutions).innerJoin(latest, eq(latest.taskId, juniorTaskExecutions.taskId)).where(
95
- and(
96
- eq(juniorTaskExecutions.kind, type),
97
- eq(juniorTaskExecutions.namespace, namespace)
98
- )
99
- ).groupBy(juniorTaskExecutions.taskId, latest.conversationId);
100
- return new Map(
101
- rows.map((row) => [
102
- row.taskId,
103
- {
104
- ...row.lastConversationId ? { lastConversationId: row.lastConversationId } : {},
105
- ...row.lastExecutedAtMs !== null ? { lastExecutedAtMs: row.lastExecutedAtMs } : {},
106
- runsLast7Days: row.runsLast7Days,
107
- totalRuns: row.totalRuns
108
- }
109
- ])
110
- );
111
- }
112
- async function readTaskExecutionDays(dayCount = 90, options = {}) {
113
- const nowMs = options.nowMs ?? Date.now();
114
- const end = utcDate(nowMs);
115
- const endMs = Date.parse(`${end}T23:59:59.999Z`);
116
- const startMs = Date.parse(`${end}T00:00:00.000Z`) - (dayCount - 1) * 864e5;
117
- const executionDate = sql`to_char(to_timestamp(${juniorTaskExecutions.executedAtMs} / 1000.0) at time zone 'UTC', 'YYYY-MM-DD')`;
118
- const rows = await getDb().select({
119
- count: count(),
120
- date: executionDate,
121
- kind: juniorTaskExecutions.kind
122
- }).from(juniorTaskExecutions).where(
123
- and(
124
- gte(juniorTaskExecutions.executedAtMs, startMs),
125
- lte(juniorTaskExecutions.executedAtMs, endMs),
126
- eq(juniorTaskExecutions.status, "completed")
127
- )
128
- ).groupBy(executionDate, juniorTaskExecutions.kind).orderBy(asc(executionDate), asc(juniorTaskExecutions.kind));
129
- const byDate = /* @__PURE__ */ new Map();
130
- for (let offset = 0; offset < dayCount; offset += 1) {
131
- const date = utcDate(startMs + offset * 864e5);
132
- byDate.set(date, emptyDay(date));
133
- }
134
- for (const row of rows) {
135
- const day = byDate.get(row.date);
136
- if (!day) continue;
137
- if (row.kind === "scheduled") day.scheduled = row.count;
138
- else if (row.kind === "event") day.event = row.count;
139
- }
140
- return [...byDate.values()];
141
- }
142
- async function readTaskExecutionByConversationId(args) {
143
- const namespace = args.namespace ?? "junior";
144
- const rows = await getDb().select({
145
- kind: juniorTaskExecutions.kind,
146
- taskId: juniorTaskExecutions.taskId
147
- }).from(juniorTaskExecutions).where(
148
- and(
149
- eq(juniorTaskExecutions.conversationId, args.conversationId),
150
- eq(juniorTaskExecutions.namespace, namespace),
151
- inArray(juniorTaskExecutions.kind, [...TASK_EXECUTION_TYPES])
152
- )
153
- ).orderBy(
154
- desc(juniorTaskExecutions.executedAtMs),
155
- desc(juniorTaskExecutions.executionId)
156
- ).limit(1);
157
- const row = rows[0];
158
- if (!row) return void 0;
159
- if (row.kind !== "scheduled" && row.kind !== "event") return void 0;
160
- return { kind: row.kind, taskId: row.taskId };
161
- }
162
- async function readTaskExecutions(args) {
163
- const namespace = args.namespace ?? "junior";
164
- const rows = await getDb().select({
165
- conversationId: juniorTaskExecutions.conversationId,
166
- executedAtMs: juniorTaskExecutions.executedAtMs,
167
- executionId: juniorTaskExecutions.executionId,
168
- status: juniorTaskExecutions.status,
169
- title: juniorConversations.title
170
- }).from(juniorTaskExecutions).leftJoin(
171
- juniorConversations,
172
- eq(
173
- juniorConversations.conversationId,
174
- juniorTaskExecutions.conversationId
175
- )
176
- ).where(
177
- and(
178
- eq(juniorTaskExecutions.kind, args.kind),
179
- eq(juniorTaskExecutions.namespace, namespace),
180
- eq(juniorTaskExecutions.taskId, args.taskId)
181
- )
182
- ).orderBy(
183
- desc(juniorTaskExecutions.executedAtMs),
184
- desc(juniorTaskExecutions.executionId)
185
- ).limit(args.limit);
186
- return rows.map((row) => {
187
- const title = row.title?.trim();
188
- return {
189
- ...row.conversationId ? { conversationId: row.conversationId } : {},
190
- executedAt: new Date(row.executedAtMs).toISOString(),
191
- executionId: row.executionId,
192
- status: row.status,
193
- ...title ? { title } : {}
194
- };
195
- });
196
- }
197
- async function readTaskRuns(args) {
198
- if (args.tasks.length === 0) return [];
199
- const namespace = args.namespace ?? "junior";
200
- const selectors = args.tasks.map(
201
- (task) => and(
202
- eq(juniorTaskExecutions.kind, task.kind),
203
- eq(juniorTaskExecutions.taskId, task.taskId)
204
- )
205
- );
206
- const rows = await getDb().select({
207
- conversationId: juniorTaskExecutions.conversationId,
208
- executedAtMs: juniorTaskExecutions.executedAtMs,
209
- executionId: juniorTaskExecutions.executionId,
210
- kind: juniorTaskExecutions.kind,
211
- status: juniorTaskExecutions.status,
212
- taskId: juniorTaskExecutions.taskId,
213
- title: juniorConversations.title
214
- }).from(juniorTaskExecutions).leftJoin(
215
- juniorConversations,
216
- eq(
217
- juniorConversations.conversationId,
218
- juniorTaskExecutions.conversationId
219
- )
220
- ).where(and(eq(juniorTaskExecutions.namespace, namespace), or(...selectors))).orderBy(
221
- desc(juniorTaskExecutions.executedAtMs),
222
- desc(juniorTaskExecutions.executionId)
223
- ).limit(args.limit);
224
- return rows.flatMap((row) => {
225
- if (row.kind !== "scheduled" && row.kind !== "event") return [];
226
- const title = row.title?.trim();
227
- return [
228
- {
229
- ...row.conversationId ? { conversationId: row.conversationId } : {},
230
- executedAt: new Date(row.executedAtMs).toISOString(),
231
- executionId: row.executionId,
232
- kind: row.kind,
233
- status: row.status,
234
- taskId: row.taskId,
235
- ...title ? { title } : {}
236
- }
237
- ];
238
- });
239
- }
240
- async function readTaskExecutionStatusDays(args) {
241
- const dayCount = args.dayCount ?? 90;
242
- const namespace = args.namespace ?? "junior";
243
- const nowMs = args.nowMs ?? Date.now();
244
- const end = utcDate(nowMs);
245
- const endMs = Date.parse(`${end}T23:59:59.999Z`);
246
- const startMs = Date.parse(`${end}T00:00:00.000Z`) - (dayCount - 1) * 864e5;
247
- const executionDate = sql`to_char(to_timestamp(${juniorTaskExecutions.executedAtMs} / 1000.0) at time zone 'UTC', 'YYYY-MM-DD')`;
248
- const rows = await getDb().select({
249
- count: count(),
250
- date: executionDate,
251
- status: juniorTaskExecutions.status
252
- }).from(juniorTaskExecutions).where(
253
- and(
254
- eq(juniorTaskExecutions.kind, args.kind),
255
- eq(juniorTaskExecutions.namespace, namespace),
256
- eq(juniorTaskExecutions.taskId, args.taskId),
257
- gte(juniorTaskExecutions.executedAtMs, startMs),
258
- lte(juniorTaskExecutions.executedAtMs, endMs),
259
- inArray(juniorTaskExecutions.status, [...TASK_EXECUTION_STATUSES])
260
- )
261
- ).groupBy(executionDate, juniorTaskExecutions.status).orderBy(asc(executionDate), asc(juniorTaskExecutions.status));
262
- const byDate = /* @__PURE__ */ new Map();
263
- for (let offset = 0; offset < dayCount; offset += 1) {
264
- const date = utcDate(startMs + offset * 864e5);
265
- byDate.set(date, emptyStatusDay(date));
266
- }
267
- for (const row of rows) {
268
- const day = byDate.get(row.date);
269
- if (!day) continue;
270
- if (row.status === "completed") day.completed = row.count;
271
- else if (row.status === "failed") day.failed = row.count;
272
- else if (row.status === "blocked") day.blocked = row.count;
273
- }
274
- return [...byDate.values()];
275
- }
276
-
277
- export {
278
- recordTaskExecution,
279
- readTaskExecutionSummaries,
280
- readTaskExecutionDays,
281
- readTaskExecutionByConversationId,
282
- readTaskExecutions,
283
- readTaskRuns,
284
- readTaskExecutionStatusDays
285
- };
@@ -1,238 +0,0 @@
1
- import {
2
- usageSchema
3
- } from "./chunk-PDO5BLNM.js";
4
-
5
- // src/chat/conversations/structured-events.ts
6
- import {
7
- conversationEventPresentationSchema,
8
- defineConversationEvent
9
- } from "@sentry/junior-plugin-api";
10
- import { z } from "zod";
11
- var JUNIOR_NATIVE_EVENT_NAMESPACE = "junior";
12
- var authenticationEventContentSchema = z.object({
13
- accountLabel: z.string().trim().min(1).max(120).optional(),
14
- actorId: z.string().min(1),
15
- authorizationId: z.string().min(1).optional(),
16
- provider: z.string().regex(/^[a-z][a-z0-9-]*$/),
17
- providerLabel: z.string().trim().min(1).max(80).optional()
18
- }).strict();
19
- var agentsInstructionsUpdatedContentSchema = z.object({
20
- action: z.enum(["loaded", "replaced", "cleared"]),
21
- directory: z.string().trim().min(1).max(500).optional(),
22
- fingerprint: z.string().trim().min(1).max(128),
23
- sources: z.array(
24
- z.object({
25
- content: z.string().min(1).max(32 * 1024),
26
- path: z.string().trim().min(1).max(500)
27
- }).strict()
28
- ).max(32),
29
- textBytes: z.number().int().nonnegative().optional()
30
- }).strict();
31
- function providerTitle(content) {
32
- return content.providerLabel?.trim() || content.provider;
33
- }
34
- function agentsInstructionsTitle(action) {
35
- if (action === "loaded") return "Loaded AGENTS.md";
36
- if (action === "replaced") return "Updated AGENTS.md";
37
- return "Cleared AGENTS.md";
38
- }
39
- function sourceFilename(sourcePath) {
40
- return sourcePath.split("/").at(-1) || sourcePath;
41
- }
42
- function formatBytes(bytes) {
43
- if (bytes < 1024) return `${bytes} bytes`;
44
- const kilobytes = bytes / 1024;
45
- return `${Number.isInteger(kilobytes) ? kilobytes : kilobytes.toFixed(1)} KB`;
46
- }
47
- function agentsInstructionsPreview(content) {
48
- const source = content.sources[0];
49
- if (!source) return void 0;
50
- const filename = sourceFilename(source.path);
51
- const label = content.sources.length === 1 ? filename : `${content.sources.length} AGENTS.md files`;
52
- return typeof content.textBytes === "number" ? `${label} \xB7 ${formatBytes(content.textBytes)}` : label;
53
- }
54
- var authenticationLinkedEvent = defineConversationEvent({
55
- name: "authentication_linked",
56
- version: 1,
57
- schema: authenticationEventContentSchema,
58
- renderEvent(event) {
59
- const provider = providerTitle(event);
60
- return {
61
- icon: "link",
62
- title: `${provider} connected`,
63
- ...event.accountLabel ? { preview: `Connected as \`${event.accountLabel}\`` } : {},
64
- details: [
65
- {
66
- title: `${provider} connected`,
67
- ...event.accountLabel ? { description: `Connected as \`${event.accountLabel}\`` } : {},
68
- metadata: [event.provider]
69
- }
70
- ]
71
- };
72
- }
73
- });
74
- var authenticationUnlinkedEvent = defineConversationEvent({
75
- name: "authentication_unlinked",
76
- version: 1,
77
- schema: authenticationEventContentSchema,
78
- renderEvent(event) {
79
- const provider = providerTitle(event);
80
- return {
81
- icon: "key",
82
- title: `${provider} disconnected`,
83
- details: [
84
- {
85
- title: `${provider} disconnected`,
86
- metadata: [event.provider]
87
- }
88
- ]
89
- };
90
- }
91
- });
92
- var agentsInstructionsUpdatedEvent = defineConversationEvent({
93
- name: "agents_instructions_updated",
94
- version: 1,
95
- schema: agentsInstructionsUpdatedContentSchema,
96
- renderEvent(event) {
97
- const title = agentsInstructionsTitle(event.action);
98
- const preview = agentsInstructionsPreview(event);
99
- return {
100
- icon: "brain",
101
- title,
102
- ...preview ? { preview } : {},
103
- ...event.sources.length > 0 ? {
104
- details: event.sources.map((source) => ({
105
- title: sourceFilename(source.path),
106
- content: source.content
107
- }))
108
- } : {}
109
- };
110
- }
111
- });
112
- var NATIVE_EVENT_DEFINITIONS = [
113
- authenticationLinkedEvent,
114
- authenticationUnlinkedEvent,
115
- agentsInstructionsUpdatedEvent
116
- ];
117
- function getJuniorNativeEventDefinition(args) {
118
- return NATIVE_EVENT_DEFINITIONS.find(
119
- (definition) => definition.eventName === args.name && definition.version === args.version
120
- );
121
- }
122
- function renderJuniorNativeConversationEvent(args) {
123
- if (args.namespace !== JUNIOR_NATIVE_EVENT_NAMESPACE) return void 0;
124
- const definition = getJuniorNativeEventDefinition(args);
125
- if (!definition) return void 0;
126
- const presentation = definition.renderEvent(definition.parse(args.content));
127
- return presentation === void 0 ? void 0 : conversationEventPresentationSchema.parse(presentation);
128
- }
129
-
130
- // src/chat/usage.ts
131
- var agentTurnUsageSchema = usageSchema;
132
- var COMPONENT_USAGE_FIELDS = [
133
- "inputTokens",
134
- "outputTokens",
135
- "cachedInputTokens",
136
- "cacheCreationTokens"
137
- ];
138
- var COST_COMPONENT_FIELDS = [
139
- "input",
140
- "output",
141
- "cacheRead",
142
- "cacheWrite"
143
- ];
144
- function hasAgentTurnUsage(usage) {
145
- return Boolean(
146
- usage && (Object.entries(usage).some(
147
- ([field, value]) => field !== "cost" && typeof value === "number" && Number.isFinite(value)
148
- ) || Object.values(usage.cost ?? {}).some(
149
- (value) => typeof value === "number" && Number.isFinite(value)
150
- ))
151
- );
152
- }
153
- function getFiniteCount(value) {
154
- return typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.floor(value)) : void 0;
155
- }
156
- function getFiniteCost(value) {
157
- return typeof value === "number" && Number.isFinite(value) ? Math.max(0, value) : void 0;
158
- }
159
- function addCost(left, right) {
160
- return Math.round(((left ?? 0) + right) * 1e12) / 1e12;
161
- }
162
- function getComponentTotal(usage) {
163
- let total;
164
- for (const field of COMPONENT_USAGE_FIELDS) {
165
- const value = getFiniteCount(usage[field]);
166
- if (value === void 0) continue;
167
- total = (total ?? 0) + value;
168
- }
169
- return total;
170
- }
171
- function addAgentTurnUsage(...usages) {
172
- const components = {};
173
- let componentTotal;
174
- let totalOnlyTokens;
175
- let reasoningTokens;
176
- const cost = {};
177
- for (const usage of usages) {
178
- if (!usage) continue;
179
- const reasoning = getFiniteCount(usage.reasoningTokens);
180
- if (reasoning !== void 0) {
181
- reasoningTokens = (reasoningTokens ?? 0) + reasoning;
182
- }
183
- if (usage.cost) {
184
- for (const field of [...COST_COMPONENT_FIELDS, "total"]) {
185
- const value = getFiniteCost(usage.cost[field]);
186
- if (value === void 0) continue;
187
- cost[field] = addCost(cost[field], value);
188
- }
189
- }
190
- const usageComponentTotal = getComponentTotal(usage);
191
- if (usageComponentTotal !== void 0) {
192
- componentTotal = (componentTotal ?? 0) + usageComponentTotal;
193
- for (const field of COMPONENT_USAGE_FIELDS) {
194
- const value = getFiniteCount(usage[field]);
195
- if (value === void 0) continue;
196
- components[field] = (components[field] ?? 0) + value;
197
- }
198
- continue;
199
- }
200
- const totalTokens = getFiniteCount(usage.totalTokens);
201
- if (totalTokens !== void 0) {
202
- totalOnlyTokens = (totalOnlyTokens ?? 0) + totalTokens;
203
- }
204
- }
205
- if (totalOnlyTokens !== void 0) {
206
- return {
207
- totalTokens: totalOnlyTokens + (componentTotal ?? 0),
208
- ...reasoningTokens !== void 0 ? { reasoningTokens } : {},
209
- ...Object.keys(cost).length > 0 ? { cost } : {}
210
- };
211
- }
212
- const result = {
213
- ...components,
214
- ...reasoningTokens !== void 0 ? { reasoningTokens } : {},
215
- ...Object.keys(cost).length > 0 ? { cost } : {}
216
- };
217
- return hasAgentTurnUsage(result) ? result : void 0;
218
- }
219
-
220
- // src/chat/tools/execution/tool-input-error.ts
221
- var ToolInputError = class extends Error {
222
- constructor(message, options) {
223
- super(message, options);
224
- this.name = "ToolInputError";
225
- }
226
- };
227
-
228
- export {
229
- JUNIOR_NATIVE_EVENT_NAMESPACE,
230
- authenticationLinkedEvent,
231
- authenticationUnlinkedEvent,
232
- agentsInstructionsUpdatedEvent,
233
- renderJuniorNativeConversationEvent,
234
- ToolInputError,
235
- agentTurnUsageSchema,
236
- hasAgentTurnUsage,
237
- addAgentTurnUsage
238
- };
@@ -1,67 +0,0 @@
1
- import {
2
- botConfig,
3
- resolveGatewayModel
4
- } from "./chunk-7NVJVJID.js";
5
-
6
- // src/chat/services/context-budget.ts
7
- var COMPACTION_TRIGGER_RATIO = 0.9;
8
- var CONTEXT_INPUT_LIMIT_RATIO = 0.95;
9
- var COMPACTION_TARGET_RATIO = 0.8;
10
- var FALLBACK_CONTEXT_WINDOW_TOKENS = 4e5;
11
- function positiveInteger(value, fallback) {
12
- return Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;
13
- }
14
- function estimateTextTokens(text) {
15
- return Math.ceil(text.length / 4);
16
- }
17
- function calculateContextCompactionTriggerTokens(model) {
18
- const contextWindow = positiveInteger(
19
- model.contextWindow,
20
- FALLBACK_CONTEXT_WINDOW_TOKENS
21
- );
22
- return Math.max(1, Math.floor(contextWindow * COMPACTION_TRIGGER_RATIO));
23
- }
24
- function calculateContextInputLimitTokens(model) {
25
- const contextWindow = positiveInteger(
26
- model.contextWindow,
27
- FALLBACK_CONTEXT_WINDOW_TOKENS
28
- );
29
- return Math.max(1, Math.floor(contextWindow * CONTEXT_INPUT_LIMIT_RATIO));
30
- }
31
- function calculateContextCompactionTargetTokens(triggerTokens) {
32
- return Math.max(1, Math.floor(triggerTokens * COMPACTION_TARGET_RATIO));
33
- }
34
- function getModelContextBudget(modelId) {
35
- const model = resolveGatewayModel(modelId);
36
- const advertisedContextWindow = positiveInteger(
37
- model.contextWindow,
38
- FALLBACK_CONTEXT_WINDOW_TOKENS
39
- );
40
- return {
41
- contextWindow: Math.min(
42
- botConfig.contextWindowTokens,
43
- advertisedContextWindow
44
- )
45
- };
46
- }
47
- function getAgentContextCompactionTriggerTokens(modelId) {
48
- return calculateContextCompactionTriggerTokens(
49
- getModelContextBudget(modelId)
50
- );
51
- }
52
- function getAgentContextInputLimitTokens(modelId) {
53
- return calculateContextInputLimitTokens(getModelContextBudget(modelId));
54
- }
55
- function getConversationContextCompactionTriggerTokens() {
56
- return calculateContextCompactionTriggerTokens(
57
- getModelContextBudget(botConfig.fastModelId)
58
- );
59
- }
60
-
61
- export {
62
- estimateTextTokens,
63
- calculateContextCompactionTargetTokens,
64
- getAgentContextCompactionTriggerTokens,
65
- getAgentContextInputLimitTokens,
66
- getConversationContextCompactionTriggerTokens
67
- };
@@ -1,81 +0,0 @@
1
- // src/chat/agent/request.ts
2
- function isAgentRunFeatureDisabled(policy, feature) {
3
- return policy?.disabledFeatures?.includes(feature) ?? false;
4
- }
5
- var RetryableDeliveryError = class extends Error {
6
- constructor(cause) {
7
- super("Assistant delivery was transient or ambiguous", { cause });
8
- this.name = "RetryableDeliveryError";
9
- }
10
- };
11
- function actorFromRouting(routing) {
12
- if (routing.dispatch?.actor) {
13
- return routing.dispatch.actor;
14
- }
15
- if (routing.actor) {
16
- return routing.actor;
17
- }
18
- if (routing.credentialContext && !("type" in routing.credentialContext.actor)) {
19
- return routing.credentialContext.actor;
20
- }
21
- return void 0;
22
- }
23
- function assertRunRoutingConsistency(request) {
24
- const { destination, source } = request.routing;
25
- if (source.platform !== destination.platform) {
26
- throw new TypeError("Run source and destination platforms do not match");
27
- }
28
- if (source.platform === "slack" && destination.platform === "slack") {
29
- if (source.teamId !== destination.teamId) {
30
- throw new TypeError("Slack source and destination teams do not match");
31
- }
32
- } else if (source.platform === "local" && destination.platform === "local") {
33
- if (source.conversationId !== destination.conversationId) {
34
- throw new TypeError(
35
- "Local source and destination conversation IDs do not match"
36
- );
37
- }
38
- if (request.routing.surface !== "internal" && destination.conversationId !== request.conversationId) {
39
- throw new TypeError(
40
- "Local source, destination, and run conversation IDs do not match"
41
- );
42
- }
43
- }
44
- const actor = request.routing.dispatch?.actor ?? request.routing.actor;
45
- if (!actor || actor.platform === "system") {
46
- return;
47
- }
48
- if (actor.platform !== destination.platform) {
49
- throw new TypeError(
50
- `Actor platform "${actor.platform}" does not match destination platform "${destination.platform}"`
51
- );
52
- }
53
- if (actor.platform === "slack" && destination.platform === "slack" && actor.teamId !== destination.teamId) {
54
- throw new TypeError("Slack actor team does not match destination team");
55
- }
56
- }
57
- function toolInvocationDestination(routing) {
58
- if (routing.destination.platform !== "slack" || !routing.toolChannelId) {
59
- return routing.destination;
60
- }
61
- return {
62
- platform: "slack",
63
- teamId: routing.destination.teamId,
64
- channelId: routing.toolChannelId
65
- };
66
- }
67
- function surfaceFromRouting(routing) {
68
- if (routing.surface) {
69
- return routing.surface;
70
- }
71
- return routing.source.platform === "slack" ? "slack" : "internal";
72
- }
73
-
74
- export {
75
- isAgentRunFeatureDisabled,
76
- RetryableDeliveryError,
77
- actorFromRouting,
78
- assertRunRoutingConsistency,
79
- toolInvocationDestination,
80
- surfaceFromRouting
81
- };