@sentry/junior 0.188.0 → 0.189.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 (109) hide show
  1. package/dist/{agent-hooks-5RQEVLQD.js → agent-hooks-6QRYH6PX.js} +11 -11
  2. package/dist/api/acp/conversations.d.ts +2 -2
  3. package/dist/api/conversations/list.d.ts +7 -0
  4. package/dist/api/people/shared.d.ts +54 -0
  5. package/dist/api.js +41 -52
  6. package/dist/app.d.ts +1 -1
  7. package/dist/app.js +1003 -346
  8. package/dist/{catalog-runtime-L4A6BJ3U.js → catalog-runtime-IETJLJFG.js} +4 -4
  9. package/dist/chat/agent/resume.d.ts +0 -2
  10. package/dist/chat/agent/types.d.ts +8 -9
  11. package/dist/chat/agent-dispatch/work.d.ts +1 -10
  12. package/dist/chat/agent-invocations/spawn.d.ts +1 -1
  13. package/dist/chat/agent-invocations/types.d.ts +296 -96
  14. package/dist/chat/app/conversation-work.d.ts +16 -8
  15. package/dist/chat/conversation-privacy.d.ts +7 -7
  16. package/dist/chat/conversations/destination.d.ts +12 -0
  17. package/dist/chat/conversations/projection.d.ts +2 -2
  18. package/dist/chat/conversations/sql/location.d.ts +13 -4
  19. package/dist/chat/{api-turns → conversations}/stop.d.ts +2 -2
  20. package/dist/chat/conversations/store.d.ts +4 -4
  21. package/dist/chat/conversations/structured-events.d.ts +1 -1
  22. package/dist/chat/{api-turns/authorization.d.ts → conversations/web-authorization.d.ts} +1 -0
  23. package/dist/chat/conversations/web-input.d.ts +98 -0
  24. package/dist/chat/conversations/web-mailbox.d.ts +12 -0
  25. package/dist/chat/event-tasks/tool-support.d.ts +0 -6
  26. package/dist/chat/providers/slack/runtime.d.ts +1 -0
  27. package/dist/chat/providers/slack/system-turn.d.ts +8 -0
  28. package/dist/chat/resource-events/actor.d.ts +13 -12
  29. package/dist/chat/resource-events/notification.d.ts +1 -1
  30. package/dist/chat/services/guardian-action-policy.d.ts +1 -1
  31. package/dist/chat/services/turn-session-routing.d.ts +2 -2
  32. package/dist/chat/task-execution/assistant-message.d.ts +32 -0
  33. package/dist/chat/task-execution/conversation-turn.d.ts +8 -0
  34. package/dist/chat/{api-turns → task-execution}/mailbox-input.d.ts +1 -2
  35. package/dist/chat/task-execution/mailbox-turn.d.ts +42 -0
  36. package/dist/chat/task-execution/paused-turn.d.ts +1 -1
  37. package/dist/chat/task-execution/slack-work.d.ts +0 -2
  38. package/dist/{chunk-AW77HH54.js → chunk-4RHJ3CXR.js} +14 -295
  39. package/dist/{chunk-ZX7RSBQ6.js → chunk-5CXCGDIL.js} +1 -1
  40. package/dist/{chunk-QVH6FW3T.js → chunk-5VWAY27R.js} +7 -3
  41. package/dist/{chunk-XJIPMHKI.js → chunk-6AUR6PWR.js} +3 -3
  42. package/dist/{chunk-QDHJTKPE.js → chunk-7R5JRPCY.js} +8 -6
  43. package/dist/{chunk-6JZGXLL2.js → chunk-AC7MDOJW.js} +5 -7
  44. package/dist/{chunk-Q7O74WOO.js → chunk-BYBSI5TI.js} +2 -2
  45. package/dist/{chunk-VFZAUQ5V.js → chunk-CMWIMFM6.js} +4 -182
  46. package/dist/{chunk-IUUQWIG2.js → chunk-CUYFCI4G.js} +59 -11
  47. package/dist/chunk-DA2KGZZI.js +13 -0
  48. package/dist/{chunk-FIUCHYT6.js → chunk-DYXVAO2E.js} +1 -1
  49. package/dist/{chunk-NZLZ4KYZ.js → chunk-E3PDZPGV.js} +1 -1
  50. package/dist/{chunk-Z5SKZE5B.js → chunk-GP32KD2J.js} +4 -12
  51. package/dist/{chunk-XI4PVY2T.js → chunk-KN32OWL2.js} +5 -5
  52. package/dist/chunk-LHKZKAZ4.js +285 -0
  53. package/dist/{chunk-6YGFBU3A.js → chunk-MFSET7Q7.js} +44 -334
  54. package/dist/{chunk-QCGNHSMA.js → chunk-MI6ZBDTS.js} +6 -6
  55. package/dist/{chunk-CIG6WI7Q.js → chunk-MRXMFB4L.js} +5 -5
  56. package/dist/{chunk-CVBDVIF4.js → chunk-MVPLEPSI.js} +1 -1
  57. package/dist/{chunk-32XSSFZV.js → chunk-NY2F7BZA.js} +1 -1
  58. package/dist/chunk-O35GZCKL.js +311 -0
  59. package/dist/{chunk-HCIVBCP5.js → chunk-OEIITG5F.js} +1 -1
  60. package/dist/{chunk-UVUXFRYN.js → chunk-PCPSX4ES.js} +209 -7
  61. package/dist/{chunk-QIMN3FXL.js → chunk-PY3EIEAF.js} +1 -1
  62. package/dist/{chunk-RMB7CERI.js → chunk-QNIOBNOY.js} +282 -121
  63. package/dist/{chunk-WGZJ5SU4.js → chunk-S3SGZUOI.js} +1 -1
  64. package/dist/chunk-SR6OMO5C.js +703 -0
  65. package/dist/{chunk-CDSLOYOR.js → chunk-UCWO5MKP.js} +6 -6
  66. package/dist/{chunk-PSHMPRIU.js → chunk-VKQWU4PO.js} +2 -2
  67. package/dist/{chunk-X55FOVZO.js → chunk-WDHPN2GH.js} +3 -3
  68. package/dist/{chunk-WW2Y7JIA.js → chunk-WMUAKAIF.js} +43 -44
  69. package/dist/{chunk-MQDIIFZM.js → chunk-WN6VLHOU.js} +12 -5
  70. package/dist/{chunk-W42ENMJW.js → chunk-WWYUYKKV.js} +1 -1
  71. package/dist/{chunk-ERZMACYA.js → chunk-WYDF6PGK.js} +3 -3
  72. package/dist/{chunk-SC67CH3C.js → chunk-YNZPOFF3.js} +14 -17
  73. package/dist/{chunk-3HEZWDS5.js → chunk-YYSEH2WC.js} +2 -2
  74. package/dist/{chunk-W2DDJCPS.js → chunk-YYZNESC3.js} +8 -8
  75. package/dist/{chunk-CZRWU4ZM.js → chunk-ZUPDSJUE.js} +2 -5
  76. package/dist/{chunk-QIOUTXTZ.js → chunk-ZV6PFUA4.js} +1 -1
  77. package/dist/cli/chat.js +34 -33
  78. package/dist/cli/check.js +5 -5
  79. package/dist/cli/plugins.js +12 -12
  80. package/dist/cli/snapshot-create.js +9 -9
  81. package/dist/cli/upgrade.js +6 -6
  82. package/dist/db/schema/agent-invocations.d.ts +0 -36
  83. package/dist/db/schema/conversations.d.ts +62 -0
  84. package/dist/db/schema.d.ts +31 -36
  85. package/dist/{db-YPRZAA2T.js → db-LPJKR2EO.js} +6 -6
  86. package/dist/instrumentation.js +3 -3
  87. package/dist/nitro.js +6 -6
  88. package/dist/{oauth-callback-server-DBBIR3XG.js → oauth-callback-server-DMXF4TTQ.js} +30 -28
  89. package/dist/{runner-FKVFFPLO.js → runner-L5DPVYCN.js} +25 -21
  90. package/dist/{skills-4RBAZEMV.js → skills-NXG3LBCK.js} +5 -5
  91. package/dist/spawn-VRUIGKWW.js +42 -0
  92. package/dist/task-runner-7YTBSPXW.js +36 -0
  93. package/dist/{validation-E6Z5LHZM.js → validation-CH36LTOS.js} +5 -5
  94. package/dist/version.js +1 -1
  95. package/dist/{work-OFTXWOK4.js → work-HBC5Y5VZ.js} +22 -21
  96. package/dist/{worker-OMWNOKTJ.js → worker-5RDZHLXH.js} +10 -10
  97. package/migrations/0037_conversation_location.sql +23 -0
  98. package/migrations/meta/0037_snapshot.json +3192 -0
  99. package/migrations/meta/_journal.json +7 -0
  100. package/package.json +5 -5
  101. package/dist/chat/api-turns/assistant-message.d.ts +0 -12
  102. package/dist/chat/api-turns/cancellation.d.ts +0 -24
  103. package/dist/chat/api-turns/routing.d.ts +0 -51
  104. package/dist/chat/api-turns/work.d.ts +0 -99
  105. package/dist/chat/task-execution/slack-resource-event.d.ts +0 -55
  106. package/dist/chunk-6FGN7ZEG.js +0 -221
  107. package/dist/chunk-LODJKINF.js +0 -1502
  108. package/dist/spawn-CO7QFCNJ.js +0 -41
  109. package/dist/task-runner-DUGZGI7V.js +0 -34
@@ -0,0 +1,285 @@
1
+ import {
2
+ getDb
3
+ } from "./chunk-CUYFCI4G.js";
4
+ import {
5
+ juniorConversations,
6
+ juniorTaskExecutions
7
+ } from "./chunk-5VWAY27R.js";
8
+ import {
9
+ logWarn
10
+ } from "./chunk-PY3EIEAF.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 } : void 0,
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 } : void 0,
105
+ ...row.lastExecutedAtMs !== null ? { lastExecutedAtMs: row.lastExecutedAtMs } : void 0,
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 } : void 0,
190
+ executedAt: new Date(row.executedAtMs).toISOString(),
191
+ executionId: row.executionId,
192
+ status: row.status,
193
+ ...title ? { title } : void 0
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 } : void 0,
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 } : void 0
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
+ };