@sentry/junior 0.188.0 → 0.190.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 (115) hide show
  1. package/dist/{agent-hooks-5RQEVLQD.js → agent-hooks-3IG2FQW2.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 +44 -55
  6. package/dist/app.d.ts +1 -1
  7. package/dist/app.js +1025 -349
  8. package/dist/{catalog-runtime-L4A6BJ3U.js → catalog-runtime-2OT7S3ZC.js} +4 -4
  9. package/dist/chat/actor.d.ts +7 -2
  10. package/dist/chat/agent/resume.d.ts +0 -2
  11. package/dist/chat/agent/types.d.ts +8 -9
  12. package/dist/chat/agent-dispatch/work.d.ts +1 -10
  13. package/dist/chat/agent-invocations/spawn.d.ts +1 -1
  14. package/dist/chat/agent-invocations/types.d.ts +44 -108
  15. package/dist/chat/app/conversation-work.d.ts +16 -8
  16. package/dist/chat/conversation-privacy.d.ts +7 -7
  17. package/dist/chat/conversations/destination.d.ts +12 -0
  18. package/dist/chat/conversations/projection.d.ts +2 -2
  19. package/dist/chat/conversations/sql/location.d.ts +13 -4
  20. package/dist/chat/{api-turns → conversations}/stop.d.ts +2 -2
  21. package/dist/chat/conversations/store.d.ts +4 -4
  22. package/dist/chat/conversations/structured-events.d.ts +1 -1
  23. package/dist/chat/{api-turns/authorization.d.ts → conversations/web-authorization.d.ts} +1 -0
  24. package/dist/chat/conversations/web-input.d.ts +98 -0
  25. package/dist/chat/conversations/web-mailbox.d.ts +12 -0
  26. package/dist/chat/event-tasks/tool-support.d.ts +1 -7
  27. package/dist/chat/providers/slack/runtime.d.ts +1 -0
  28. package/dist/chat/providers/slack/system-turn.d.ts +8 -0
  29. package/dist/chat/resource-events/actor.d.ts +13 -12
  30. package/dist/chat/resource-events/notification.d.ts +1 -1
  31. package/dist/chat/services/guardian-action-policy.d.ts +1 -1
  32. package/dist/chat/services/turn-session-routing.d.ts +2 -2
  33. package/dist/chat/source.d.ts +3 -3
  34. package/dist/chat/task-execution/assistant-message.d.ts +32 -0
  35. package/dist/chat/task-execution/conversation-turn.d.ts +8 -0
  36. package/dist/chat/{api-turns → task-execution}/mailbox-input.d.ts +1 -2
  37. package/dist/chat/task-execution/mailbox-turn.d.ts +52 -0
  38. package/dist/chat/task-execution/paused-turn.d.ts +1 -1
  39. package/dist/chat/task-execution/slack-work.d.ts +0 -2
  40. package/dist/chat/task-execution/state.d.ts +2 -2
  41. package/dist/chat/task-execution/store.d.ts +1 -1
  42. package/dist/chat/task-execution/turn-cursor.d.ts +10 -1
  43. package/dist/chat/tools/types.d.ts +9 -2
  44. package/dist/{chunk-XJIPMHKI.js → chunk-2MKHYSYL.js} +3 -3
  45. package/dist/{chunk-QCGNHSMA.js → chunk-2MRF22J4.js} +25 -10
  46. package/dist/{chunk-HCIVBCP5.js → chunk-3J3BCB4J.js} +1 -1
  47. package/dist/chunk-4BLFIYVK.js +703 -0
  48. package/dist/{chunk-NZLZ4KYZ.js → chunk-4PKEJK5B.js} +1 -1
  49. package/dist/{chunk-VFZAUQ5V.js → chunk-62DRKZQU.js} +5 -183
  50. package/dist/{chunk-QIOUTXTZ.js → chunk-663DQH5W.js} +1 -1
  51. package/dist/{chunk-Z5SKZE5B.js → chunk-67MMSYSE.js} +4 -12
  52. package/dist/{chunk-ZX7RSBQ6.js → chunk-6BXUSF7J.js} +1 -1
  53. package/dist/{chunk-W42ENMJW.js → chunk-6H7YU6XH.js} +1 -1
  54. package/dist/{chunk-WGZJ5SU4.js → chunk-7UJ6IJCK.js} +1 -1
  55. package/dist/{chunk-QDHJTKPE.js → chunk-7Y7XMI6P.js} +8 -6
  56. package/dist/{chunk-6YGFBU3A.js → chunk-BGOLRC36.js} +62 -336
  57. package/dist/{chunk-CVBDVIF4.js → chunk-BUJU6C2J.js} +1 -1
  58. package/dist/{chunk-XI4PVY2T.js → chunk-CZXZKTAI.js} +5 -5
  59. package/dist/chunk-DA2KGZZI.js +13 -0
  60. package/dist/{chunk-RMB7CERI.js → chunk-DJZGQ7OL.js} +311 -137
  61. package/dist/{chunk-FIUCHYT6.js → chunk-DVX6U6GI.js} +1 -1
  62. package/dist/{chunk-AW77HH54.js → chunk-ECOR3OXY.js} +19 -299
  63. package/dist/{chunk-WW2Y7JIA.js → chunk-F3K2267N.js} +51 -50
  64. package/dist/{chunk-W2DDJCPS.js → chunk-FVFJ57RK.js} +8 -8
  65. package/dist/{chunk-UVUXFRYN.js → chunk-GWCFXTB6.js} +211 -7
  66. package/dist/{chunk-X55FOVZO.js → chunk-HI5KXE3C.js} +3 -3
  67. package/dist/{chunk-ERZMACYA.js → chunk-IRQ3RSX3.js} +3 -3
  68. package/dist/{chunk-32XSSFZV.js → chunk-JV7U4665.js} +1 -1
  69. package/dist/chunk-MNHJ4WLE.js +285 -0
  70. package/dist/{chunk-SC67CH3C.js → chunk-OJFX2FP7.js} +14 -17
  71. package/dist/{chunk-IUUQWIG2.js → chunk-OKAHLUSU.js} +70 -19
  72. package/dist/{chunk-PSHMPRIU.js → chunk-OON4IQHH.js} +2 -2
  73. package/dist/{chunk-6JZGXLL2.js → chunk-OYCOLHCR.js} +5 -7
  74. package/dist/{chunk-3HEZWDS5.js → chunk-REVH4BZU.js} +2 -2
  75. package/dist/{chunk-CDSLOYOR.js → chunk-RLYJYEIY.js} +6 -6
  76. package/dist/{chunk-CZRWU4ZM.js → chunk-T66GV7A3.js} +2 -5
  77. package/dist/{chunk-Q7O74WOO.js → chunk-VWNIDTFR.js} +2 -2
  78. package/dist/{chunk-CIG6WI7Q.js → chunk-W2C4TPLB.js} +5 -5
  79. package/dist/{chunk-QIMN3FXL.js → chunk-Y4WL4OYD.js} +1 -1
  80. package/dist/{chunk-MQDIIFZM.js → chunk-YFU4DGZY.js} +12 -5
  81. package/dist/chunk-YKIAUKYH.js +311 -0
  82. package/dist/{chunk-QVH6FW3T.js → chunk-ZFCO2TMB.js} +7 -3
  83. package/dist/cli/chat.js +34 -33
  84. package/dist/cli/check.js +5 -5
  85. package/dist/cli/plugins.js +12 -12
  86. package/dist/cli/snapshot-create.js +9 -9
  87. package/dist/cli/upgrade.js +6 -6
  88. package/dist/db/schema/agent-invocations.d.ts +18 -42
  89. package/dist/db/schema/conversations.d.ts +62 -0
  90. package/dist/db/schema.d.ts +49 -42
  91. package/dist/{db-YPRZAA2T.js → db-2IFDMDDY.js} +6 -6
  92. package/dist/instrumentation.js +3 -3
  93. package/dist/nitro.js +6 -6
  94. package/dist/{oauth-callback-server-DBBIR3XG.js → oauth-callback-server-SZSS2KH6.js} +30 -28
  95. package/dist/{runner-FKVFFPLO.js → runner-2N4QU77X.js} +25 -21
  96. package/dist/{skills-4RBAZEMV.js → skills-VU2LZAKX.js} +5 -5
  97. package/dist/spawn-3K7RV4T5.js +42 -0
  98. package/dist/task-runner-52DYFHW3.js +36 -0
  99. package/dist/{validation-E6Z5LHZM.js → validation-IJGHK7NI.js} +5 -5
  100. package/dist/version.js +1 -1
  101. package/dist/{work-OFTXWOK4.js → work-DI45MLRL.js} +22 -21
  102. package/dist/{worker-OMWNOKTJ.js → worker-FY7KWG2M.js} +10 -10
  103. package/migrations/0037_conversation_location.sql +23 -0
  104. package/migrations/meta/0037_snapshot.json +3192 -0
  105. package/migrations/meta/_journal.json +7 -0
  106. package/package.json +4 -4
  107. package/dist/chat/api-turns/assistant-message.d.ts +0 -12
  108. package/dist/chat/api-turns/cancellation.d.ts +0 -24
  109. package/dist/chat/api-turns/routing.d.ts +0 -51
  110. package/dist/chat/api-turns/work.d.ts +0 -99
  111. package/dist/chat/task-execution/slack-resource-event.d.ts +0 -55
  112. package/dist/chunk-6FGN7ZEG.js +0 -221
  113. package/dist/chunk-LODJKINF.js +0 -1502
  114. package/dist/spawn-CO7QFCNJ.js +0 -41
  115. package/dist/task-runner-DUGZGI7V.js +0 -34
@@ -0,0 +1,285 @@
1
+ import {
2
+ getDb
3
+ } from "./chunk-OKAHLUSU.js";
4
+ import {
5
+ juniorConversations,
6
+ juniorTaskExecutions
7
+ } from "./chunk-ZFCO2TMB.js";
8
+ import {
9
+ logWarn
10
+ } from "./chunk-Y4WL4OYD.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
+ };
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  AgentRunError,
3
3
  executeTurn
4
- } from "./chunk-ERZMACYA.js";
4
+ } from "./chunk-IRQ3RSX3.js";
5
5
  import {
6
6
  ConversationTurnLifecycleService
7
- } from "./chunk-W42ENMJW.js";
7
+ } from "./chunk-6H7YU6XH.js";
8
8
  import {
9
9
  getPersistedSandboxState,
10
10
  getPersistedThreadState,
11
11
  persistThreadStateById
12
- } from "./chunk-CIG6WI7Q.js";
12
+ } from "./chunk-W2C4TPLB.js";
13
13
  import {
14
14
  AgentInvocationBusyError,
15
15
  AgentInvocationLimitError,
@@ -18,32 +18,32 @@ import {
18
18
  agentBindingSchema,
19
19
  agentInvocationSchema,
20
20
  createAgentInvocationSchema
21
- } from "./chunk-6JZGXLL2.js";
22
- import {
23
- appendAndEnqueueInboundMessage
24
- } from "./chunk-MQDIIFZM.js";
21
+ } from "./chunk-OYCOLHCR.js";
25
22
  import {
26
23
  TurnInputCommitLostError,
27
24
  getAssistantReplyText,
28
25
  getConversationTurnBoundaryError,
29
26
  isTurnInputCommitLostError
30
- } from "./chunk-Z5SKZE5B.js";
27
+ } from "./chunk-67MMSYSE.js";
31
28
  import {
32
29
  failTurnRecord,
33
30
  getTerminalAssistantMessages,
34
31
  getTurnRecord,
35
32
  openConversationProjection,
36
33
  saveTurnCheckpoint
37
- } from "./chunk-6YGFBU3A.js";
34
+ } from "./chunk-BGOLRC36.js";
35
+ import {
36
+ appendAndEnqueueInboundMessage
37
+ } from "./chunk-YFU4DGZY.js";
38
38
  import {
39
39
  getConversationEventStore,
40
40
  getConversationStore,
41
41
  getSqlExecutor
42
- } from "./chunk-IUUQWIG2.js";
42
+ } from "./chunk-OKAHLUSU.js";
43
43
  import {
44
44
  juniorAgentBindings,
45
45
  juniorAgentInvocations
46
- } from "./chunk-QVH6FW3T.js";
46
+ } from "./chunk-ZFCO2TMB.js";
47
47
 
48
48
  // src/chat/agent-invocations/work.ts
49
49
  import { z } from "zod";
@@ -97,7 +97,6 @@ function invocationFromRow(row) {
97
97
  createdAtMs: row.createdAt.getTime(),
98
98
  ...row.credentialContext ? { credentialContext: row.credentialContext } : void 0,
99
99
  destination: row.destination,
100
- ...row.destinationVisibility ? { destinationVisibility: row.destinationVisibility } : void 0,
101
100
  ...row.errorMessage !== null ? { errorMessage: row.errorMessage } : void 0,
102
101
  input: row.input,
103
102
  invocationId: row.invocationId,
@@ -112,7 +111,7 @@ function invocationFromRow(row) {
112
111
  });
113
112
  }
114
113
  function sameCreateInput(invocation, input) {
115
- return invocation.parentConversationId === input.parentConversationId && invocation.agentName === input.agentName && invocation.input === input.input && invocation.reasoningLevel === input.reasoningLevel && JSON.stringify(invocation.actor) === JSON.stringify(input.actor) && JSON.stringify(invocation.credentialContext) === JSON.stringify(input.credentialContext) && JSON.stringify(invocation.destination) === JSON.stringify(input.destination) && invocation.destinationVisibility === input.destinationVisibility && JSON.stringify(invocation.source) === JSON.stringify(input.source);
114
+ return invocation.parentConversationId === input.parentConversationId && invocation.agentName === input.agentName && invocation.input === input.input && invocation.reasoningLevel === input.reasoningLevel && JSON.stringify(invocation.actor) === JSON.stringify(input.actor) && JSON.stringify(invocation.credentialContext) === JSON.stringify(input.credentialContext) && JSON.stringify(invocation.destination) === JSON.stringify(input.destination) && JSON.stringify(invocation.source) === JSON.stringify(input.source);
116
115
  }
117
116
  async function getAgentBinding(args) {
118
117
  const rows = await getSqlExecutor().db().select().from(juniorAgentBindings).where(
@@ -226,7 +225,6 @@ async function createAgentInvocation(rawInput, nowMs = Date.now()) {
226
225
  credentialContext: input.credentialContext ?? null,
227
226
  source: input.source,
228
227
  destination: input.destination,
229
- destinationVisibility: input.destinationVisibility ?? null,
230
228
  reasoningLevel: input.reasoningLevel ?? null,
231
229
  status: "pending",
232
230
  mailboxStatus: "pending",
@@ -458,7 +456,6 @@ async function saveAgentInvocationResult(args) {
458
456
  durationMs: args.result.diagnostics.durationMs,
459
457
  usage: args.result.diagnostics.usage,
460
458
  destination: args.invocation.destination,
461
- destinationVisibility: args.invocation.destinationVisibility,
462
459
  ...failed ? {
463
460
  errorMessage: args.result.diagnostics.errorMessage ?? "Agent invocation failed"
464
461
  } : void 0,
@@ -593,9 +590,9 @@ function createAgentInvocationWorker(agentRunner) {
593
590
  actor: invocation.actor,
594
591
  credentialContext: invocation.credentialContext,
595
592
  destination: invocation.destination,
596
- destinationVisibility: invocation.destinationVisibility,
597
593
  publishExternally: context.publishExternally,
598
- source: location ? { ...invocation.source, location } : invocation.source,
594
+ source: invocation.source,
595
+ ...location ? { location } : void 0,
599
596
  surface: "internal",
600
597
  // TODO(dcramer): Issues #881 and #883 track a path for child runs to
601
598
  // force interactive auth when a delegated tool requires credentials
@@ -8,7 +8,7 @@ import {
8
8
  juniorConversations,
9
9
  juniorIdentities,
10
10
  juniorUsers
11
- } from "./chunk-QVH6FW3T.js";
11
+ } from "./chunk-ZFCO2TMB.js";
12
12
  import {
13
13
  conversationEventDataSchema,
14
14
  decodeStoredConversationEvent,
@@ -20,7 +20,7 @@ import {
20
20
  } from "./chunk-VFUK3X5B.js";
21
21
  import {
22
22
  getChatConfig
23
- } from "./chunk-Q7O74WOO.js";
23
+ } from "./chunk-VWNIDTFR.js";
24
24
  import {
25
25
  parseActorUserId,
26
26
  parseSlackChannelReferenceId,
@@ -28,7 +28,7 @@ import {
28
28
  } from "./chunk-N7TMSOZH.js";
29
29
  import {
30
30
  normalizeIdentityEmail
31
- } from "./chunk-QIMN3FXL.js";
31
+ } from "./chunk-Y4WL4OYD.js";
32
32
 
33
33
  // src/chat/conversations/sql/store.ts
34
34
  import { randomUUID as randomUUID2 } from "crypto";
@@ -257,23 +257,26 @@ function normalizeSessionSource(value) {
257
257
  if (!value) {
258
258
  return void 0;
259
259
  }
260
- if (value.platform === "local") {
260
+ if (value.kind === "local") {
261
261
  return {
262
- platform: "local",
262
+ kind: "local",
263
263
  visibility: value.visibility,
264
264
  conversationId: value.conversationId
265
265
  };
266
266
  }
267
- if (value.platform === "web") {
267
+ if (value.kind === "web") {
268
268
  return {
269
- platform: "web",
269
+ kind: "web",
270
270
  visibility: value.visibility,
271
271
  conversationId: value.conversationId
272
272
  };
273
273
  }
274
+ if (value.kind === "resource_event") {
275
+ return void 0;
276
+ }
274
277
  const threadTs = value.threadTs?.trim();
275
278
  return {
276
- platform: "slack",
279
+ kind: "slack",
277
280
  visibility: value.visibility,
278
281
  teamId: value.teamId,
279
282
  channelId: value.channelId,
@@ -421,22 +424,57 @@ function mergeActor(current2, next) {
421
424
  import { locationSchema } from "@sentry/junior-plugin-api";
422
425
 
423
426
  // src/chat/conversations/sql/location.ts
424
- function locationFromRow(row) {
427
+ function locationForWrite(args) {
428
+ const location = args.location ? locationSchema.parse(args.location) : void 0;
429
+ const destination = args.destination?.platform === "slack" ? args.destination : void 0;
430
+ const source = args.sessionSource?.kind === "slack" ? args.sessionSource : void 0;
431
+ if (location) {
432
+ if (destination && (location.id !== args.destinationId || location.teamId !== destination.teamId || location.channelId !== destination.channelId) || source && (location.teamId !== source.teamId || location.channelId !== source.channelId)) {
433
+ throw new Error("Conversation Location changed");
434
+ }
435
+ return source?.threadTs && !location.threadTs ? { ...location, threadTs: source.threadTs } : location;
436
+ }
437
+ if (destination && source && (destination.teamId !== source.teamId || destination.channelId !== source.channelId)) {
438
+ throw new Error("Conversation Location does not match its session Source");
439
+ }
440
+ if (!destination || !args.destinationId) {
441
+ return void 0;
442
+ }
443
+ return locationSchema.parse({
444
+ id: args.destinationId,
445
+ provider: "slack",
446
+ teamId: destination.teamId,
447
+ channelId: destination.channelId,
448
+ ...source?.threadTs ? { threadTs: source.threadTs } : void 0
449
+ });
450
+ }
451
+ function locationFromRow(value, row, sessionSource) {
452
+ if (value !== void 0 && value !== null) {
453
+ return locationSchema.parse(value);
454
+ }
425
455
  if (!row || row.provider === "local") {
426
456
  return void 0;
427
457
  }
458
+ if (row.provider !== "slack") {
459
+ throw new Error("Conversation Location provider is not supported");
460
+ }
461
+ const slackSource = sessionSource?.kind === "slack" && sessionSource.teamId === row.providerTenantId && sessionSource.channelId === row.providerDestinationId ? sessionSource : void 0;
428
462
  return locationSchema.parse({
429
463
  id: row.id,
430
- provider: row.provider,
431
- ...row.providerTenantId ? { tenantId: row.providerTenantId } : void 0,
432
- providerId: row.providerDestinationId
464
+ provider: "slack",
465
+ teamId: row.providerTenantId,
466
+ channelId: row.providerDestinationId,
467
+ ...slackSource?.threadTs ? { threadTs: slackSource.threadTs } : void 0
433
468
  });
434
469
  }
435
- function privacyFromLocationRow(row) {
470
+ function visibilityFromLocationRow(row) {
436
471
  if (!row) {
437
472
  return void 0;
438
473
  }
439
- return row.visibility === "public" ? "public" : "private";
474
+ if (row.visibility === "public" || row.visibility === "private") {
475
+ return row.visibility;
476
+ }
477
+ return void 0;
440
478
  }
441
479
 
442
480
  // src/chat/conversations/sql/store.ts
@@ -537,7 +575,7 @@ function destinationFromRow(destination) {
537
575
  }
538
576
  function conversationFromRow(readRow) {
539
577
  const row = readRow.conversation;
540
- const visibility = privacyFromLocationRow(readRow.destination);
578
+ const visibility = visibilityFromLocationRow(readRow.destination);
541
579
  if (row.schemaVersion !== 1) {
542
580
  throw new Error("Conversation record schema version is invalid");
543
581
  }
@@ -570,7 +608,11 @@ function conversationFromRow(readRow) {
570
608
  ...row.runId ? { runId: row.runId } : void 0,
571
609
  updatedAtMs: msFromDate(row.executionUpdatedAt) ?? requiredMsFromDate(row.updatedAt)
572
610
  };
573
- const location = locationFromRow(readRow.destination);
611
+ const location = locationFromRow(
612
+ row.location,
613
+ readRow.destination,
614
+ sessionSource
615
+ );
574
616
  return {
575
617
  schemaVersion: 1,
576
618
  conversationId: row.conversationId,
@@ -777,6 +819,7 @@ var SqlStore = class {
777
819
  lastActivityAtMs: args.lastActivityAtMs,
778
820
  updatedAtMs: args.updatedAtMs,
779
821
  ...existing?.parentConversationId ? { parentConversationId: existing.parentConversationId } : void 0,
822
+ ...existing?.location ? { location: existing.location } : void 0,
780
823
  ...args.channelName ? { channelName: args.channelName } : void 0,
781
824
  ...args.destination ? { destination: args.destination } : void 0,
782
825
  ...args.actor ? { actor: args.actor } : void 0,
@@ -926,6 +969,12 @@ var SqlStore = class {
926
969
  }),
927
970
  conversation.updatedAtMs
928
971
  );
972
+ const location = locationForWrite({
973
+ destination: conversation.destination,
974
+ destinationId,
975
+ location: conversation.location,
976
+ sessionSource: conversation.sessionSource
977
+ });
929
978
  const actorIdentityObservation = actorIdentityForConversation(conversation);
930
979
  const actorIdentity = actorIdentityObservation ? await upsertIdentity(
931
980
  this.executor,
@@ -945,6 +994,7 @@ var SqlStore = class {
945
994
  originType: originTypeFromSource(conversation.source) ?? null,
946
995
  originId: null,
947
996
  originRunId: null,
997
+ location: location ?? null,
948
998
  destinationId: destinationId ?? null,
949
999
  destination: null,
950
1000
  actorIdentityId: actorIdentity?.id ?? null,
@@ -972,6 +1022,7 @@ var SqlStore = class {
972
1022
  originType: sql3`coalesce(excluded.origin_type, ${juniorConversations.originType})`,
973
1023
  originId: sql3`coalesce(excluded.origin_id, ${juniorConversations.originId})`,
974
1024
  originRunId: sql3`coalesce(excluded.origin_run_id, ${juniorConversations.originRunId})`,
1025
+ location: sql3`coalesce(excluded.location_json, ${juniorConversations.location})`,
975
1026
  destinationId: sql3`coalesce(excluded.destination_id, ${juniorConversations.destinationId})`,
976
1027
  actorIdentityId: sql3`coalesce(excluded.actor_identity_id, ${juniorConversations.actorIdentityId})`,
977
1028
  creatorIdentityId: sql3`coalesce(excluded.creator_identity_id, ${juniorConversations.creatorIdentityId})`,
@@ -1118,9 +1169,9 @@ async function loadConversationSlackTenantId(executor, conversationId) {
1118
1169
  if (destinationTenant) {
1119
1170
  return destinationTenant;
1120
1171
  }
1121
- const sessionSource = row?.sessionSource;
1122
- if (isRecord(sessionSource) && sessionSource.platform === "slack" && typeof sessionSource.teamId === "string" && sessionSource.teamId.trim()) {
1123
- return sessionSource.teamId.trim();
1172
+ const sessionSource = parseSessionSource(row?.sessionSource);
1173
+ if (sessionSource?.kind === "slack") {
1174
+ return sessionSource.teamId;
1124
1175
  }
1125
1176
  return void 0;
1126
1177
  }
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  getStateAdapter
3
- } from "./chunk-ZX7RSBQ6.js";
3
+ } from "./chunk-6BXUSF7J.js";
4
4
  import {
5
5
  getClient
6
6
  } from "./chunk-PEQXYSSE.js";
7
7
 
8
- // src/chat/api-turns/authorization.ts
8
+ // src/chat/conversations/web-authorization.ts
9
9
  import { randomUUID } from "crypto";
10
10
  var WEB_AUTHORIZATION_PREFIX = "junior:web_authorization:v1";
11
11
  var WEB_AUTHORIZATION_TTL_MS = 24 * 60 * 60 * 1e3;
@@ -7,23 +7,23 @@ import {
7
7
  import {
8
8
  formatProviderLabel,
9
9
  startOAuthFlow
10
- } from "./chunk-UVUXFRYN.js";
10
+ } from "./chunk-GWCFXTB6.js";
11
11
  import {
12
12
  abandonReplacedPendingAuth,
13
13
  canReusePendingAuthLink
14
- } from "./chunk-Z5SKZE5B.js";
14
+ } from "./chunk-67MMSYSE.js";
15
15
  import {
16
16
  recordAuthorizationRequested
17
- } from "./chunk-6YGFBU3A.js";
17
+ } from "./chunk-BGOLRC36.js";
18
18
  import {
19
19
  AGENT_INVOCATION_MAILBOX_STATUSES
20
- } from "./chunk-QVH6FW3T.js";
20
+ } from "./chunk-ZFCO2TMB.js";
21
21
  import {
22
22
  TURN_REASONING_LEVELS
23
23
  } from "./chunk-D4YV5TDV.js";
24
24
  import {
25
25
  pluginCatalogRuntime
26
- } from "./chunk-NZLZ4KYZ.js";
26
+ } from "./chunk-4PKEJK5B.js";
27
27
  import {
28
28
  credentialContextSchema
29
29
  } from "./chunk-CEMMLV5L.js";
@@ -271,7 +271,6 @@ var agentInvocationBaseSchema = z.object({
271
271
  createdAtMs: z.number().finite(),
272
272
  credentialContext: credentialContextSchema.optional(),
273
273
  destination: destinationSchema,
274
- destinationVisibility: z.enum(["public", "private"]).optional(),
275
274
  input: exactStringSchema,
276
275
  invocationId: exactStringSchema,
277
276
  mailboxStatus: agentInvocationMailboxStatusSchema,
@@ -300,7 +299,6 @@ var createAgentInvocationSchema = z.object({
300
299
  agentName: agentNameSchema.optional(),
301
300
  credentialContext: credentialContextSchema.optional(),
302
301
  destination: destinationSchema,
303
- destinationVisibility: z.enum(["public", "private"]).optional(),
304
302
  idempotencyKey: exactStringSchema,
305
303
  input: exactStringSchema,
306
304
  parentConversationId: exactStringSchema,
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  pluginCatalogRuntime
3
- } from "./chunk-NZLZ4KYZ.js";
3
+ } from "./chunk-4PKEJK5B.js";
4
4
  import {
5
5
  skillRoots
6
6
  } from "./chunk-TXKUKMVO.js";
7
7
  import {
8
8
  logWarn
9
- } from "./chunk-QIMN3FXL.js";
9
+ } from "./chunk-Y4WL4OYD.js";
10
10
 
11
11
  // src/chat/skills.ts
12
12
  import fs from "fs/promises";
@@ -19,23 +19,23 @@ import {
19
19
  releaseConversationWork,
20
20
  requestAnotherSlice,
21
21
  startConversationWork
22
- } from "./chunk-MQDIIFZM.js";
22
+ } from "./chunk-YFU4DGZY.js";
23
+ import {
24
+ getTurnRequestDeadline
25
+ } from "./chunk-7UJ6IJCK.js";
23
26
  import {
24
27
  ConversationQueueMessageRejectedError
25
28
  } from "./chunk-JAL3CH4G.js";
26
- import {
27
- getTurnRequestDeadline
28
- } from "./chunk-WGZJ5SU4.js";
29
29
  import {
30
30
  getChatConfig,
31
31
  isProviderRetryError
32
- } from "./chunk-Q7O74WOO.js";
32
+ } from "./chunk-VWNIDTFR.js";
33
33
  import {
34
34
  logException,
35
35
  logInfo,
36
36
  logWarn,
37
37
  withLogContext
38
- } from "./chunk-QIMN3FXL.js";
38
+ } from "./chunk-Y4WL4OYD.js";
39
39
 
40
40
  // src/chat/task-execution/worker.ts
41
41
  var CONVERSATION_WORK_DEFER_DELAY_MS = 15e3;