@sentry/junior 0.147.0 → 0.149.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 (162) hide show
  1. package/dist/{agent-hooks-HS6VGUPM.js → agent-hooks-CWMCXAMT.js} +10 -10
  2. package/dist/api/conversations/access.d.ts +2 -1
  3. package/dist/api/conversations/aggregate.d.ts +2 -0
  4. package/dist/api/conversations/archive.d.ts +3 -5
  5. package/dist/api/conversations/create.d.ts +6 -0
  6. package/dist/api/conversations/detail.d.ts +2 -296
  7. package/dist/api/conversations/event-list.d.ts +2 -193
  8. package/dist/api/conversations/list.d.ts +4 -66
  9. package/dist/api/conversations/pending-messages.d.ts +15 -0
  10. package/dist/api/conversations/routes.d.ts +1 -1
  11. package/dist/api/conversations/stats.d.ts +0 -54
  12. package/dist/api/http.d.ts +2 -6
  13. package/dist/api/locations/detail.d.ts +3 -111
  14. package/dist/api/locations/list.d.ts +0 -45
  15. package/dist/api/locations/query.d.ts +2 -1
  16. package/dist/api/locations/routes.d.ts +1 -1
  17. package/dist/api/people/list.d.ts +0 -29
  18. package/dist/api/people/profile.d.ts +2 -106
  19. package/dist/api/people/profile.query.d.ts +2 -1
  20. package/dist/api/people/routes.d.ts +1 -1
  21. package/dist/api/people/shared.d.ts +3 -1
  22. package/dist/api/people/spend.d.ts +3 -4
  23. package/dist/api/personal-tokens/routes.d.ts +2 -2
  24. package/dist/api/route.d.ts +8 -14
  25. package/dist/api/schema/conversation.d.ts +130 -25
  26. package/dist/api/schema/location.d.ts +4 -0
  27. package/dist/api/schema/person.d.ts +7 -3
  28. package/dist/api/schema.d.ts +2 -2
  29. package/dist/api/schema.js +13 -1
  30. package/dist/api/stats.d.ts +0 -13
  31. package/dist/api/validation.d.ts +7 -0
  32. package/dist/api/viewer.d.ts +3 -0
  33. package/dist/api.d.ts +2 -1
  34. package/dist/api.js +772 -561
  35. package/dist/app.js +241 -204
  36. package/dist/{catalog-runtime-M6ZTPYRV.js → catalog-runtime-GAW5APVI.js} +5 -5
  37. package/dist/chat/actor.d.ts +4 -1
  38. package/dist/chat/agent/request.d.ts +2 -0
  39. package/dist/chat/agent/resume.d.ts +1 -0
  40. package/dist/chat/agent-dispatch/context.d.ts +2 -2
  41. package/dist/chat/agent-invocations/types.d.ts +52 -0
  42. package/dist/chat/api-turns/work.d.ts +108 -0
  43. package/dist/chat/app/services.d.ts +1 -1
  44. package/dist/chat/conversations/history.d.ts +60 -0
  45. package/dist/chat/conversations/provenance.d.ts +6 -0
  46. package/dist/chat/conversations/sql/actor-identity.d.ts +19 -0
  47. package/dist/chat/conversations/store.d.ts +1 -1
  48. package/dist/chat/resource-events/store.d.ts +1 -1
  49. package/dist/chat/runtime/reply-executor.d.ts +1 -3
  50. package/dist/chat/runtime/slack-runtime.d.ts +2 -1
  51. package/dist/chat/runtime/turn-preparation.d.ts +9 -0
  52. package/dist/chat/scheduled-tasks/tool-support.d.ts +5 -5
  53. package/dist/chat/scheduled-tasks/tools/create.d.ts +2 -2
  54. package/dist/chat/scheduled-tasks/tools/delete.d.ts +2 -2
  55. package/dist/chat/scheduled-tasks/tools/list.d.ts +2 -2
  56. package/dist/chat/scheduled-tasks/tools/run-now.d.ts +2 -2
  57. package/dist/chat/scheduled-tasks/tools/update.d.ts +2 -2
  58. package/dist/chat/services/conversation-memory.d.ts +2 -2
  59. package/dist/chat/services/conversation-title.d.ts +20 -0
  60. package/dist/chat/slack/assistant-thread/title.d.ts +10 -27
  61. package/dist/chat/slack/channel.d.ts +26 -0
  62. package/dist/chat/slack/dispatch-turn.d.ts +1 -0
  63. package/dist/chat/slack/timestamp-param.d.ts +0 -2
  64. package/dist/chat/slack/{tools → tool-support}/canvas/api.d.ts +1 -1
  65. package/dist/chat/slack/{tools → tool-support}/canvas/context.d.ts +3 -0
  66. package/dist/chat/slack/tool-support/channel-access.d.ts +42 -0
  67. package/dist/chat/slack/tool-support/channel-target.d.ts +27 -0
  68. package/dist/chat/slack/tool-support/list/params.d.ts +5 -0
  69. package/dist/chat/slack/tools/canvas/create.d.ts +1 -1
  70. package/dist/chat/slack/tools/channel-join.d.ts +28 -0
  71. package/dist/chat/slack/tools/channel-list-messages.d.ts +3 -2
  72. package/dist/chat/slack/tools/conversation-message-search.d.ts +2 -8
  73. package/dist/chat/slack/tools/message-add-reaction.d.ts +1 -1
  74. package/dist/chat/slack/tools/public-search.d.ts +63 -2
  75. package/dist/chat/slack/tools/send-files.d.ts +1 -1
  76. package/dist/chat/slack/tools/thread-read.d.ts +2 -5
  77. package/dist/chat/source.d.ts +2 -0
  78. package/dist/chat/state/conversation.d.ts +1 -0
  79. package/dist/chat/task-execution/checkpoint.d.ts +1 -0
  80. package/dist/chat/task-execution/state.d.ts +9 -4
  81. package/dist/chat/task-execution/store.d.ts +3 -2
  82. package/dist/chat/task-execution/turn-cursor.d.ts +2 -0
  83. package/dist/chat/task-execution/worker.d.ts +2 -0
  84. package/dist/chat/tasks/read.d.ts +1 -1
  85. package/dist/chat/tools/search-conversation-events.d.ts +1 -1
  86. package/dist/chat/tools/types.d.ts +11 -4
  87. package/dist/chat/tools/watch-resource-events.d.ts +2 -2
  88. package/dist/{chunk-ORO3PWKQ.js → chunk-25SC7D6Z.js} +1 -1
  89. package/dist/{chunk-GGB4WL5A.js → chunk-2JHKISQA.js} +1 -1
  90. package/dist/{chunk-AVZDSUFB.js → chunk-2P6BQQER.js} +4 -4
  91. package/dist/{chunk-7NVJVJID.js → chunk-32CXPIZE.js} +2 -2
  92. package/dist/{chunk-YSB2N563.js → chunk-3GYZ5YEH.js} +121 -87
  93. package/dist/{chunk-DU74WPIC.js → chunk-3I2IVWSZ.js} +1 -1
  94. package/dist/{chunk-SVHUEHUL.js → chunk-3JVUWLR7.js} +65 -4
  95. package/dist/{chunk-RXBVB2JM.js → chunk-3KGQOKIG.js} +1 -1
  96. package/dist/{chunk-YBVXBNSV.js → chunk-4JGM7FXO.js} +2 -2
  97. package/dist/{chunk-AZ7EAOBE.js → chunk-4YKPOYRV.js} +5 -5
  98. package/dist/chunk-5CWUQXXT.js +806 -0
  99. package/dist/{chunk-DLDRQHG5.js → chunk-6G5RCDKP.js} +1 -1
  100. package/dist/{chunk-AYU72WO7.js → chunk-75DSYFFB.js} +47 -70
  101. package/dist/{chunk-YHDERDRO.js → chunk-7BH46NB4.js} +91 -75
  102. package/dist/{chunk-745QJ3ZA.js → chunk-ALJG73MQ.js} +2 -2
  103. package/dist/chunk-ART7P442.js +48 -0
  104. package/dist/{chunk-7A4M7PCV.js → chunk-DK5UT6PQ.js} +1180 -556
  105. package/dist/{chunk-AIOK6LAG.js → chunk-EW2LNCRL.js} +813 -44
  106. package/dist/chunk-EXW76GW4.js +36 -0
  107. package/dist/chunk-GDFF3BQG.js +136 -0
  108. package/dist/{chunk-7UQIVT6G.js → chunk-JMH3DBM5.js} +6 -6
  109. package/dist/{chunk-CWP5RHVX.js → chunk-JMSMXXED.js} +12 -5
  110. package/dist/{chunk-CSZINQJ2.js → chunk-MEMURSBG.js} +1 -1
  111. package/dist/{chunk-YNTTROJT.js → chunk-QIW7OQEO.js} +1 -1
  112. package/dist/{chunk-Q4R73I43.js → chunk-RB26T3LU.js} +58 -28
  113. package/dist/{chunk-4LJO56OJ.js → chunk-RLVZIWNQ.js} +1 -1
  114. package/dist/{chunk-SGZO7UWH.js → chunk-SWHPVZBV.js} +2 -2
  115. package/dist/{chunk-PVNG6UMU.js → chunk-TFBNBXPU.js} +22 -10
  116. package/dist/{chunk-EFLJ2WJH.js → chunk-URDCZAL4.js} +5 -5
  117. package/dist/{chunk-6H5SZR24.js → chunk-UZGASGOD.js} +300 -383
  118. package/dist/{chunk-YEO3VX72.js → chunk-W7UONUIZ.js} +8 -6
  119. package/dist/{chunk-JUUKWRBE.js → chunk-X22XXSZA.js} +1 -1
  120. package/dist/{chunk-X5UY34KT.js → chunk-XPYWWMHR.js} +8 -8
  121. package/dist/{chunk-IIOOO4FQ.js → chunk-ZYMYLLWG.js} +2 -1
  122. package/dist/cli/chat.js +32 -35
  123. package/dist/cli/check.js +6 -6
  124. package/dist/cli/plugins.js +13 -13
  125. package/dist/cli/snapshot-create.js +9 -9
  126. package/dist/cli/upgrade.js +7 -7
  127. package/dist/db/schema/agent-invocations.d.ts +20 -0
  128. package/dist/db/schema/conversation-annotations.d.ts +2 -2
  129. package/dist/db/schema.d.ts +22 -2
  130. package/dist/{db-CSEW4RII.js → db-JBZLRIVY.js} +7 -7
  131. package/dist/instrumentation.js +4 -4
  132. package/dist/nitro.js +2 -2
  133. package/dist/{oauth-callback-server-FUEV5HNG.js → oauth-callback-server-MNTVYY2I.js} +24 -26
  134. package/dist/{runner-U3XHSKSH.js → runner-K24BWZSZ.js} +23 -25
  135. package/dist/{skills-AKE6W3WI.js → skills-AU5ST2CG.js} +6 -6
  136. package/dist/spawn-6PO7CVJ6.js +38 -0
  137. package/dist/{validation-WDTAULUF.js → validation-IXGZCFRO.js} +6 -6
  138. package/dist/version.js +1 -1
  139. package/dist/{work-C3HAO2BG.js → work-WCZIYILX.js} +18 -19
  140. package/dist/{worker-LNP4YKBM.js → worker-U2AACBEY.js} +11 -10
  141. package/package.json +6 -5
  142. package/dist/api/health.d.ts +0 -7
  143. package/dist/api/personal-tokens/create.d.ts +0 -11
  144. package/dist/api/personal-tokens/list.d.ts +0 -12
  145. package/dist/api/personal-tokens/revoke.d.ts +0 -5
  146. package/dist/api/plugin-reports.d.ts +0 -63
  147. package/dist/api/plugins.d.ts +0 -8
  148. package/dist/api/runtime.d.ts +0 -24
  149. package/dist/api/skills.d.ts +0 -6
  150. package/dist/chat/slack/tools/channel-access.d.ts +0 -30
  151. package/dist/chunk-34GS7B6L.js +0 -115
  152. package/dist/chunk-AVOCH2Z5.js +0 -285
  153. package/dist/chunk-HLXXQI5Q.js +0 -238
  154. package/dist/chunk-K4SZAP3K.js +0 -67
  155. package/dist/chunk-R776HKPK.js +0 -81
  156. package/dist/chunk-Z4YU7Z4L.js +0 -76
  157. package/dist/spawn-B6GDTWJ4.js +0 -39
  158. /package/dist/chat/slack/{tools → tool-support}/canvas/markdown.d.ts +0 -0
  159. /package/dist/chat/slack/{tools → tool-support}/channel-capabilities.d.ts +0 -0
  160. /package/dist/chat/slack/{tools → tool-support}/context.d.ts +0 -0
  161. /package/dist/chat/slack/{tools → tool-support}/list/api.d.ts +0 -0
  162. /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
- };