@sentry/junior 0.187.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 (108) hide show
  1. package/dist/{agent-hooks-XVAE2554.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 +1001 -338
  8. package/dist/{catalog-runtime-DWFAC562.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 +9 -14
  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 -24
  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/location.d.ts +3 -8
  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 +8 -11
  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/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 +5 -5
  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-WL3R2KTS.js → chunk-4RHJ3CXR.js} +90 -289
  39. package/dist/{chunk-U6ZQHRIP.js → chunk-5CXCGDIL.js} +1 -1
  40. package/dist/{chunk-HXR3FHTE.js → chunk-5VWAY27R.js} +7 -3
  41. package/dist/{chunk-D3GDGREI.js → chunk-6AUR6PWR.js} +3 -3
  42. package/dist/{chunk-EIWYZXSM.js → chunk-7R5JRPCY.js} +8 -6
  43. package/dist/{chunk-WRDW3A3D.js → chunk-AC7MDOJW.js} +5 -7
  44. package/dist/{chunk-URZ7UD4P.js → chunk-BYBSI5TI.js} +2 -2
  45. package/dist/{chunk-MUPPP7A7.js → chunk-CMWIMFM6.js} +4 -182
  46. package/dist/{chunk-WKIS4VRK.js → chunk-CUYFCI4G.js} +70 -39
  47. package/dist/chunk-DA2KGZZI.js +13 -0
  48. package/dist/{chunk-Q6OCUQ7W.js → chunk-DYXVAO2E.js} +1 -1
  49. package/dist/{chunk-QH3I7ZOK.js → chunk-E3PDZPGV.js} +1 -1
  50. package/dist/{chunk-NU775DLU.js → chunk-GP32KD2J.js} +4 -12
  51. package/dist/{chunk-STF4GSK4.js → chunk-KN32OWL2.js} +5 -5
  52. package/dist/chunk-LHKZKAZ4.js +285 -0
  53. package/dist/{chunk-D5BWM37G.js → chunk-MFSET7Q7.js} +51 -341
  54. package/dist/{chunk-DUE4EUNL.js → chunk-MI6ZBDTS.js} +6 -6
  55. package/dist/{chunk-27T5HZHO.js → chunk-MRXMFB4L.js} +6 -87
  56. package/dist/{chunk-4A2R3AQB.js → chunk-MVPLEPSI.js} +1 -1
  57. package/dist/{chunk-7LRRVMPH.js → chunk-NY2F7BZA.js} +1 -1
  58. package/dist/chunk-O35GZCKL.js +311 -0
  59. package/dist/{chunk-U3KMII5Y.js → chunk-OEIITG5F.js} +1 -1
  60. package/dist/{chunk-6FKNNUSN.js → chunk-PCPSX4ES.js} +209 -7
  61. package/dist/{chunk-6YCIYOVA.js → chunk-PY3EIEAF.js} +1 -1
  62. package/dist/{chunk-U5POFCKM.js → chunk-QNIOBNOY.js} +284 -123
  63. package/dist/{chunk-JCRXXEMC.js → chunk-S3SGZUOI.js} +1 -1
  64. package/dist/chunk-SR6OMO5C.js +703 -0
  65. package/dist/{chunk-TQHCZXN7.js → chunk-UCWO5MKP.js} +7 -7
  66. package/dist/{chunk-ITLYUKGZ.js → chunk-VKQWU4PO.js} +2 -2
  67. package/dist/{chunk-JZPDYKRG.js → chunk-WDHPN2GH.js} +3 -3
  68. package/dist/{chunk-P2VU5JNH.js → chunk-WMUAKAIF.js} +42 -42
  69. package/dist/{chunk-NIKLTFBP.js → chunk-WN6VLHOU.js} +12 -5
  70. package/dist/{chunk-VC343WHM.js → chunk-WWYUYKKV.js} +1 -1
  71. package/dist/{chunk-OM4SFFJK.js → chunk-WYDF6PGK.js} +3 -3
  72. package/dist/{chunk-KRYJ5VOD.js → chunk-YNZPOFF3.js} +16 -21
  73. package/dist/{chunk-Z6OHCDXP.js → chunk-YYSEH2WC.js} +2 -2
  74. package/dist/{chunk-BITZUBPJ.js → chunk-YYZNESC3.js} +8 -8
  75. package/dist/{chunk-2VUDJGB6.js → chunk-ZUPDSJUE.js} +2 -5
  76. package/dist/{chunk-X5SXFVZT.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/conversations.d.ts +62 -0
  83. package/dist/db/schema.d.ts +31 -0
  84. package/dist/{db-FBHAWVXU.js → db-LPJKR2EO.js} +6 -6
  85. package/dist/instrumentation.js +3 -3
  86. package/dist/nitro.js +6 -6
  87. package/dist/{oauth-callback-server-5HS5ULC6.js → oauth-callback-server-DMXF4TTQ.js} +30 -28
  88. package/dist/{runner-46W6NV6B.js → runner-L5DPVYCN.js} +24 -20
  89. package/dist/{skills-TG3QC4B6.js → skills-NXG3LBCK.js} +5 -5
  90. package/dist/spawn-VRUIGKWW.js +42 -0
  91. package/dist/task-runner-7YTBSPXW.js +36 -0
  92. package/dist/{validation-GMRIDBC5.js → validation-CH36LTOS.js} +5 -5
  93. package/dist/version.js +1 -1
  94. package/dist/{work-W4ULBJTU.js → work-HBC5Y5VZ.js} +22 -21
  95. package/dist/{worker-M6NVACS2.js → worker-5RDZHLXH.js} +10 -10
  96. package/migrations/0037_conversation_location.sql +23 -0
  97. package/migrations/meta/0037_snapshot.json +3192 -0
  98. package/migrations/meta/_journal.json +7 -0
  99. package/package.json +4 -4
  100. package/dist/chat/api-turns/assistant-message.d.ts +0 -12
  101. package/dist/chat/api-turns/cancellation.d.ts +0 -24
  102. package/dist/chat/api-turns/routing.d.ts +0 -51
  103. package/dist/chat/api-turns/work.d.ts +0 -99
  104. package/dist/chat/task-execution/slack-resource-event.d.ts +0 -47
  105. package/dist/chunk-4YD3DET6.js +0 -1503
  106. package/dist/chunk-6FGN7ZEG.js +0 -221
  107. package/dist/spawn-Y6YWBIJS.js +0 -41
  108. package/dist/task-runner-YSGBPN4U.js +0 -34
@@ -1,13 +1,15 @@
1
1
  import {
2
2
  coerceThreadConversationState,
3
- getPersistedThreadState,
4
- resolveTurnSessionRouting
5
- } from "./chunk-27T5HZHO.js";
3
+ getPersistedThreadState
4
+ } from "./chunk-MRXMFB4L.js";
5
+ import {
6
+ recordTaskExecution
7
+ } from "./chunk-LHKZKAZ4.js";
6
8
  import {
7
9
  pluginTaskId,
8
10
  pluginTaskParamsSchema,
9
11
  sendVercelPluginTask
10
- } from "./chunk-STF4GSK4.js";
12
+ } from "./chunk-KN32OWL2.js";
11
13
  import {
12
14
  getPiMessageRole,
13
15
  getTurnRecord,
@@ -17,7 +19,7 @@ import {
17
19
  isToolResultMessage,
18
20
  normalizeToolNameFromResult,
19
21
  stripRuntimeTurnContext
20
- } from "./chunk-D5BWM37G.js";
22
+ } from "./chunk-MFSET7Q7.js";
21
23
  import {
22
24
  createPluginConversationEvents,
23
25
  createPluginEmbedder,
@@ -26,21 +28,17 @@ import {
26
28
  createPluginState,
27
29
  getPlugins,
28
30
  readActorIdentity
29
- } from "./chunk-DUE4EUNL.js";
31
+ } from "./chunk-MI6ZBDTS.js";
30
32
  import {
31
33
  JUNIOR_THREAD_STATE_TTL_MS
32
34
  } from "./chunk-3Y47VMHV.js";
33
35
  import {
34
36
  getConversationStore,
35
37
  getDb
36
- } from "./chunk-WKIS4VRK.js";
37
- import {
38
- juniorConversations,
39
- juniorTaskExecutions
40
- } from "./chunk-HXR3FHTE.js";
38
+ } from "./chunk-CUYFCI4G.js";
41
39
  import {
42
40
  getStateAdapter
43
- } from "./chunk-U6ZQHRIP.js";
41
+ } from "./chunk-5CXCGDIL.js";
44
42
  import {
45
43
  sameActorIdentity
46
44
  } from "./chunk-GFBR4S3Q.js";
@@ -50,290 +48,99 @@ import {
50
48
  import {
51
49
  parseSlackMessageTs
52
50
  } from "./chunk-N7TMSOZH.js";
53
- import {
54
- logWarn
55
- } from "./chunk-6YCIYOVA.js";
56
51
 
57
52
  // src/chat/plugins/task-runner.ts
58
53
  import { pluginRunContextSchema } from "@sentry/junior-plugin-api";
59
54
 
60
- // src/chat/agent-dispatch/store.ts
61
- import { createHash } from "crypto";
62
- import {
63
- destinationSchema,
64
- destinationVisibilitySchema,
65
- isSlackDestination,
66
- replyAttributionSchema,
67
- sourceSchema
68
- } from "@sentry/junior-plugin-api";
69
- import { z } from "zod";
70
-
71
- // src/chat/tasks/execution-stats.ts
72
- import {
73
- and,
74
- asc,
75
- count,
76
- desc,
77
- eq,
78
- gte,
79
- inArray,
80
- lte,
81
- max,
82
- or,
83
- sql
84
- } from "drizzle-orm";
85
- var TASK_EXECUTION_TYPES = ["scheduled", "event"];
86
- var TASK_EXECUTION_STATUSES = [
87
- "blocked",
88
- "completed",
89
- "failed"
90
- ];
91
- function utcDate(nowMs) {
92
- return new Date(nowMs).toISOString().slice(0, 10);
93
- }
94
- function emptyDay(date) {
95
- return { date, event: 0, scheduled: 0 };
96
- }
97
- function emptyStatusDay(date) {
98
- return { blocked: 0, completed: 0, date, failed: 0 };
99
- }
100
- async function recordTaskExecution(type, taskId, options) {
101
- const namespace = options.namespace ?? "junior";
102
- const nowMs = options.nowMs ?? Date.now();
103
- const status = options.status ?? "completed";
104
- try {
105
- await getDb().insert(juniorTaskExecutions).values({
106
- ...options.conversationId ? { conversationId: options.conversationId } : void 0,
107
- executedAtMs: nowMs,
108
- executionId: options.executionId,
109
- kind: type,
110
- namespace,
111
- status,
112
- taskId
113
- }).onConflictDoNothing({
114
- target: [
115
- juniorTaskExecutions.kind,
116
- juniorTaskExecutions.namespace,
117
- juniorTaskExecutions.executionId
118
- ]
119
- });
120
- } catch (error) {
121
- logWarn("task.execution.stat_failed", {
122
- error,
123
- "app.task.execution.id": options.executionId,
124
- "app.task.execution.namespace": namespace,
125
- "app.task.execution.status": status,
126
- "app.task.execution.task_id": taskId,
127
- "app.task.execution.type": type
55
+ // src/chat/services/turn-session-routing.ts
56
+ async function loadConversationChain(conversationId, conversationStore) {
57
+ const chain = [];
58
+ const seen = /* @__PURE__ */ new Set();
59
+ let cursor = conversationId;
60
+ while (cursor && !seen.has(cursor)) {
61
+ seen.add(cursor);
62
+ const conversation = await conversationStore.get({
63
+ conversationId: cursor
128
64
  });
65
+ if (!conversation) {
66
+ break;
67
+ }
68
+ chain.push(conversation);
69
+ cursor = conversation.parentConversationId;
129
70
  }
71
+ return chain;
130
72
  }
131
- async function readTaskExecutionSummaries(type, namespace, options = {}) {
132
- const sevenDaysAgoMs = (options.nowMs ?? Date.now()) - 7 * 24 * 60 * 60 * 1e3;
133
- const db = getDb();
134
- const latest = db.selectDistinctOn([juniorTaskExecutions.taskId], {
135
- conversationId: juniorTaskExecutions.conversationId,
136
- taskId: juniorTaskExecutions.taskId
137
- }).from(juniorTaskExecutions).where(
138
- and(
139
- eq(juniorTaskExecutions.kind, type),
140
- eq(juniorTaskExecutions.namespace, namespace)
141
- )
142
- ).orderBy(
143
- juniorTaskExecutions.taskId,
144
- desc(juniorTaskExecutions.executedAtMs),
145
- desc(juniorTaskExecutions.executionId)
146
- ).as("latest_task_execution");
147
- const rows = await db.select({
148
- lastConversationId: latest.conversationId,
149
- lastExecutedAtMs: max(juniorTaskExecutions.executedAtMs),
150
- runsLast7Days: sql`count(*) filter (where ${juniorTaskExecutions.executedAtMs} >= ${sevenDaysAgoMs})::int`,
151
- taskId: juniorTaskExecutions.taskId,
152
- totalRuns: sql`count(*)::int`
153
- }).from(juniorTaskExecutions).innerJoin(latest, eq(latest.taskId, juniorTaskExecutions.taskId)).where(
154
- and(
155
- eq(juniorTaskExecutions.kind, type),
156
- eq(juniorTaskExecutions.namespace, namespace)
157
- )
158
- ).groupBy(juniorTaskExecutions.taskId, latest.conversationId);
159
- return new Map(
160
- rows.map((row) => [
161
- row.taskId,
162
- {
163
- ...row.lastConversationId ? { lastConversationId: row.lastConversationId } : void 0,
164
- ...row.lastExecutedAtMs !== null ? { lastExecutedAtMs: row.lastExecutedAtMs } : void 0,
165
- runsLast7Days: row.runsLast7Days,
166
- totalRuns: row.totalRuns
167
- }
168
- ])
169
- );
73
+ function slackSourceForDestination(args) {
74
+ if (args.source?.platform !== "slack" || args.source.channelId !== args.destination.channelId) {
75
+ return void 0;
76
+ }
77
+ const threadTs = args.source.threadTs?.trim();
78
+ return {
79
+ platform: "slack",
80
+ visibility: args.source.visibility ?? "public",
81
+ teamId: args.source.teamId?.trim() || args.destination.teamId,
82
+ channelId: args.source.channelId,
83
+ ...threadTs ? { threadTs } : void 0
84
+ };
170
85
  }
171
- async function readTaskExecutionDays(dayCount = 90, options = {}) {
172
- const nowMs = options.nowMs ?? Date.now();
173
- const end = utcDate(nowMs);
174
- const endMs = Date.parse(`${end}T23:59:59.999Z`);
175
- const startMs = Date.parse(`${end}T00:00:00.000Z`) - (dayCount - 1) * 864e5;
176
- const executionDate = sql`to_char(to_timestamp(${juniorTaskExecutions.executedAtMs} / 1000.0) at time zone 'UTC', 'YYYY-MM-DD')`;
177
- const rows = await getDb().select({
178
- count: count(),
179
- date: executionDate,
180
- kind: juniorTaskExecutions.kind
181
- }).from(juniorTaskExecutions).where(
182
- and(
183
- gte(juniorTaskExecutions.executedAtMs, startMs),
184
- lte(juniorTaskExecutions.executedAtMs, endMs),
185
- eq(juniorTaskExecutions.status, "completed")
186
- )
187
- ).groupBy(executionDate, juniorTaskExecutions.kind).orderBy(asc(executionDate), asc(juniorTaskExecutions.kind));
188
- const byDate = /* @__PURE__ */ new Map();
189
- for (let offset = 0; offset < dayCount; offset += 1) {
190
- const date = utcDate(startMs + offset * 864e5);
191
- byDate.set(date, emptyDay(date));
192
- }
193
- for (const row of rows) {
194
- const day = byDate.get(row.date);
195
- if (!day) continue;
196
- if (row.kind === "scheduled") day.scheduled = row.count;
197
- else if (row.kind === "event") day.event = row.count;
198
- }
199
- return [...byDate.values()];
200
- }
201
- async function readTaskExecutionByConversationId(args) {
202
- const namespace = args.namespace ?? "junior";
203
- const rows = await getDb().select({
204
- kind: juniorTaskExecutions.kind,
205
- taskId: juniorTaskExecutions.taskId
206
- }).from(juniorTaskExecutions).where(
207
- and(
208
- eq(juniorTaskExecutions.conversationId, args.conversationId),
209
- eq(juniorTaskExecutions.namespace, namespace),
210
- inArray(juniorTaskExecutions.kind, [...TASK_EXECUTION_TYPES])
211
- )
212
- ).orderBy(
213
- desc(juniorTaskExecutions.executedAtMs),
214
- desc(juniorTaskExecutions.executionId)
215
- ).limit(1);
216
- const row = rows[0];
217
- if (!row) return void 0;
218
- if (row.kind !== "scheduled" && row.kind !== "event") return void 0;
219
- return { kind: row.kind, taskId: row.taskId };
220
- }
221
- async function readTaskExecutions(args) {
222
- const namespace = args.namespace ?? "junior";
223
- const rows = await getDb().select({
224
- conversationId: juniorTaskExecutions.conversationId,
225
- executedAtMs: juniorTaskExecutions.executedAtMs,
226
- executionId: juniorTaskExecutions.executionId,
227
- status: juniorTaskExecutions.status,
228
- title: juniorConversations.title
229
- }).from(juniorTaskExecutions).leftJoin(
230
- juniorConversations,
231
- eq(
232
- juniorConversations.conversationId,
233
- juniorTaskExecutions.conversationId
234
- )
235
- ).where(
236
- and(
237
- eq(juniorTaskExecutions.kind, args.kind),
238
- eq(juniorTaskExecutions.namespace, namespace),
239
- eq(juniorTaskExecutions.taskId, args.taskId)
240
- )
241
- ).orderBy(
242
- desc(juniorTaskExecutions.executedAtMs),
243
- desc(juniorTaskExecutions.executionId)
244
- ).limit(args.limit);
245
- return rows.map((row) => {
246
- const title = row.title?.trim();
86
+ async function resolveConversationRouting(args) {
87
+ const conversationStore = args.conversationStore ?? (await import("./db-LPJKR2EO.js")).getConversationStore();
88
+ const chain = await loadConversationChain(
89
+ args.conversationId,
90
+ conversationStore
91
+ );
92
+ let destination;
93
+ let source;
94
+ let location;
95
+ for (const conversation of chain) {
96
+ destination ??= conversation.destination;
97
+ source ??= conversation.sessionSource;
98
+ location ??= conversation.location;
99
+ if (destination && source) {
100
+ break;
101
+ }
102
+ }
103
+ if (!destination) {
104
+ return void 0;
105
+ }
106
+ if (destination.platform === "slack") {
107
+ const slackSource = slackSourceForDestination({ destination, source });
247
108
  return {
248
- ...row.conversationId ? { conversationId: row.conversationId } : void 0,
249
- executedAt: new Date(row.executedAtMs).toISOString(),
250
- executionId: row.executionId,
251
- status: row.status,
252
- ...title ? { title } : void 0
109
+ destination,
110
+ ...location ? { location } : void 0,
111
+ ...slackSource ? { source: slackSource } : void 0
253
112
  };
254
- });
255
- }
256
- async function readTaskRuns(args) {
257
- if (args.tasks.length === 0) return [];
258
- const namespace = args.namespace ?? "junior";
259
- const selectors = args.tasks.map(
260
- (task) => and(
261
- eq(juniorTaskExecutions.kind, task.kind),
262
- eq(juniorTaskExecutions.taskId, task.taskId)
263
- )
264
- );
265
- const rows = await getDb().select({
266
- conversationId: juniorTaskExecutions.conversationId,
267
- executedAtMs: juniorTaskExecutions.executedAtMs,
268
- executionId: juniorTaskExecutions.executionId,
269
- kind: juniorTaskExecutions.kind,
270
- status: juniorTaskExecutions.status,
271
- taskId: juniorTaskExecutions.taskId,
272
- title: juniorConversations.title
273
- }).from(juniorTaskExecutions).leftJoin(
274
- juniorConversations,
275
- eq(
276
- juniorConversations.conversationId,
277
- juniorTaskExecutions.conversationId
278
- )
279
- ).where(and(eq(juniorTaskExecutions.namespace, namespace), or(...selectors))).orderBy(
280
- desc(juniorTaskExecutions.executedAtMs),
281
- desc(juniorTaskExecutions.executionId)
282
- ).limit(args.limit);
283
- return rows.flatMap((row) => {
284
- if (row.kind !== "scheduled" && row.kind !== "event") return [];
285
- const title = row.title?.trim();
286
- return [
287
- {
288
- ...row.conversationId ? { conversationId: row.conversationId } : void 0,
289
- executedAt: new Date(row.executedAtMs).toISOString(),
290
- executionId: row.executionId,
291
- kind: row.kind,
292
- status: row.status,
293
- taskId: row.taskId,
294
- ...title ? { title } : void 0
295
- }
296
- ];
297
- });
113
+ }
114
+ return {
115
+ destination,
116
+ ...location ? { location } : void 0,
117
+ ...source ? { source } : void 0
118
+ };
298
119
  }
299
- async function readTaskExecutionStatusDays(args) {
300
- const dayCount = args.dayCount ?? 90;
301
- const namespace = args.namespace ?? "junior";
302
- const nowMs = args.nowMs ?? Date.now();
303
- const end = utcDate(nowMs);
304
- const endMs = Date.parse(`${end}T23:59:59.999Z`);
305
- const startMs = Date.parse(`${end}T00:00:00.000Z`) - (dayCount - 1) * 864e5;
306
- const executionDate = sql`to_char(to_timestamp(${juniorTaskExecutions.executedAtMs} / 1000.0) at time zone 'UTC', 'YYYY-MM-DD')`;
307
- const rows = await getDb().select({
308
- count: count(),
309
- date: executionDate,
310
- status: juniorTaskExecutions.status
311
- }).from(juniorTaskExecutions).where(
312
- and(
313
- eq(juniorTaskExecutions.kind, args.kind),
314
- eq(juniorTaskExecutions.namespace, namespace),
315
- eq(juniorTaskExecutions.taskId, args.taskId),
316
- gte(juniorTaskExecutions.executedAtMs, startMs),
317
- lte(juniorTaskExecutions.executedAtMs, endMs),
318
- inArray(juniorTaskExecutions.status, [...TASK_EXECUTION_STATUSES])
319
- )
320
- ).groupBy(executionDate, juniorTaskExecutions.status).orderBy(asc(executionDate), asc(juniorTaskExecutions.status));
321
- const byDate = /* @__PURE__ */ new Map();
322
- for (let offset = 0; offset < dayCount; offset += 1) {
323
- const date = utcDate(startMs + offset * 864e5);
324
- byDate.set(date, emptyStatusDay(date));
325
- }
326
- for (const row of rows) {
327
- const day = byDate.get(row.date);
328
- if (!day) continue;
329
- if (row.status === "completed") day.completed = row.count;
330
- else if (row.status === "failed") day.failed = row.count;
331
- else if (row.status === "blocked") day.blocked = row.count;
332
- }
333
- return [...byDate.values()];
120
+ async function resolveTurnSessionRouting(args) {
121
+ const routing = await resolveConversationRouting(args);
122
+ if (!routing?.destination || !routing.source) {
123
+ throw new Error(
124
+ `Conversation ${args.conversationId} is missing durable routing metadata`
125
+ );
126
+ }
127
+ return {
128
+ destination: routing.destination,
129
+ ...routing.location ? { location: routing.location } : void 0,
130
+ source: routing.source
131
+ };
334
132
  }
335
133
 
336
134
  // src/chat/agent-dispatch/store.ts
135
+ import { createHash } from "crypto";
136
+ import {
137
+ destinationSchema,
138
+ destinationVisibilitySchema,
139
+ isSlackDestination,
140
+ replyAttributionSchema,
141
+ sourceSchema
142
+ } from "@sentry/junior-plugin-api";
143
+ import { z } from "zod";
337
144
  var DISPATCH_PREFIX = "junior:agent_dispatch";
338
145
  var DISPATCH_LOCK_TTL_MS = 10 * 60 * 1e3;
339
146
  var DISPATCH_MAILBOX_APPEND_INDEX_LOCK_TTL_MS = 1e4;
@@ -984,13 +791,6 @@ async function processPluginTask(message, options = {}) {
984
791
  }
985
792
 
986
793
  export {
987
- recordTaskExecution,
988
- readTaskExecutionSummaries,
989
- readTaskExecutionDays,
990
- readTaskExecutionByConversationId,
991
- readTaskExecutions,
992
- readTaskRuns,
993
- readTaskExecutionStatusDays,
994
794
  getDispatchConversationId,
995
795
  getDispatchInputMessageId,
996
796
  getDispatchTurnId,
@@ -1006,6 +806,7 @@ export {
1006
806
  listPendingDispatchMailboxAppends,
1007
807
  claimDispatchMailboxAppend,
1008
808
  getPluginDispatchProjection,
809
+ resolveTurnSessionRouting,
1009
810
  scheduleSessionCompletedPluginTasks,
1010
811
  processPluginTask
1011
812
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getChatConfig
3
- } from "./chunk-URZ7UD4P.js";
3
+ } from "./chunk-BYBSI5TI.js";
4
4
 
5
5
  // src/chat/state/adapter.ts
6
6
  import { createMemoryState } from "@chat-adapter/state-memory";
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-VFUK3X5B.js";
5
5
  import {
6
6
  DEFAULT_SQL_STATEMENT_TIMEOUT_MS
7
- } from "./chunk-URZ7UD4P.js";
7
+ } from "./chunk-BYBSI5TI.js";
8
8
 
9
9
  // src/db/neon.ts
10
10
  import { AsyncLocalStorage } from "async_hooks";
@@ -137,12 +137,14 @@ var juniorConversations = pgTable4(
137
137
  schemaVersion: integer2("schema_version").notNull().default(1),
138
138
  source: text4("source").$type(),
139
139
  /** Structured session Source locator; set-once on the conversation root. */
140
- // TODO(dcramer): Remove source_json after every stored Conversation has a
141
- // complete Location and all readers use it for provider context.
140
+ // TODO(dcramer): Remove source_json after resume reads the saved Turn Source
141
+ // and all provider context readers use Conversation Location.
142
142
  sessionSource: jsonb2("source_json").$type(),
143
143
  originType: text4("origin_type"),
144
144
  originId: text4("origin_id"),
145
145
  originRunId: text4("origin_run_id"),
146
+ /** Complete Location associated with this Conversation. */
147
+ location: jsonb2("location_json").$type(),
146
148
  // TODO(dcramer): Rename destination_id to location_id after all deployed
147
149
  // readers and writers use the singular Conversation Location contract.
148
150
  destinationId: text4("destination_id").references(
@@ -518,6 +520,8 @@ var juniorAgentInvocations = pgTable12(
518
520
  ).$type(),
519
521
  source: jsonb5("source_json").$type().notNull(),
520
522
  destination: jsonb5("destination_json").$type().notNull(),
523
+ // TODO(dcramer): Remove destinationVisibility after all deployed Agent
524
+ // invocation readers ignore the destination_visibility SQL column.
521
525
  destinationVisibility: text12(
522
526
  "destination_visibility"
523
527
  ).$type(),
@@ -6,14 +6,14 @@ import {
6
6
  isStale,
7
7
  runNonInteractiveCommand,
8
8
  sleep
9
- } from "./chunk-JZPDYKRG.js";
9
+ } from "./chunk-WDHPN2GH.js";
10
10
  import {
11
11
  getStateAdapter
12
- } from "./chunk-U6ZQHRIP.js";
12
+ } from "./chunk-5CXCGDIL.js";
13
13
  import {
14
14
  setSpanAttributes,
15
15
  withSpan
16
- } from "./chunk-6YCIYOVA.js";
16
+ } from "./chunk-PY3EIEAF.js";
17
17
 
18
18
  // src/chat/sandbox/resources.ts
19
19
  var configuredResources;
@@ -2,29 +2,31 @@ import {
2
2
  coerceThreadConversationState,
3
3
  getPersistedThreadState,
4
4
  persistThreadStateById
5
- } from "./chunk-27T5HZHO.js";
5
+ } from "./chunk-MRXMFB4L.js";
6
6
  import {
7
- buildDeterministicTurnId,
8
7
  clearPendingAuth,
9
8
  markTurnClosed,
10
9
  markTurnCompleted
11
- } from "./chunk-NU775DLU.js";
10
+ } from "./chunk-GP32KD2J.js";
12
11
  import {
13
12
  hydrateConversationMessages,
14
13
  markConversationMessage
15
- } from "./chunk-D5BWM37G.js";
14
+ } from "./chunk-MFSET7Q7.js";
15
+ import {
16
+ buildDeterministicTurnId
17
+ } from "./chunk-DA2KGZZI.js";
16
18
  import {
17
19
  ProviderError,
18
20
  findProviderError,
19
21
  getProviderErrorAttributes,
20
22
  getProviderErrorUserMessage
21
- } from "./chunk-URZ7UD4P.js";
23
+ } from "./chunk-BYBSI5TI.js";
22
24
  import {
23
25
  parseSlackMessageTs
24
26
  } from "./chunk-N7TMSOZH.js";
25
27
  import {
26
28
  buildTurnFailureResponse
27
- } from "./chunk-6YCIYOVA.js";
29
+ } from "./chunk-PY3EIEAF.js";
28
30
 
29
31
  // src/chat/runtime/delivered-turn-state.ts
30
32
  function buildDeliveredTurnStatePatch(args) {
@@ -7,23 +7,23 @@ import {
7
7
  import {
8
8
  formatProviderLabel,
9
9
  startOAuthFlow
10
- } from "./chunk-6FKNNUSN.js";
10
+ } from "./chunk-PCPSX4ES.js";
11
11
  import {
12
12
  abandonReplacedPendingAuth,
13
13
  canReusePendingAuthLink
14
- } from "./chunk-NU775DLU.js";
14
+ } from "./chunk-GP32KD2J.js";
15
15
  import {
16
16
  recordAuthorizationRequested
17
- } from "./chunk-D5BWM37G.js";
17
+ } from "./chunk-MFSET7Q7.js";
18
18
  import {
19
19
  AGENT_INVOCATION_MAILBOX_STATUSES
20
- } from "./chunk-HXR3FHTE.js";
20
+ } from "./chunk-5VWAY27R.js";
21
21
  import {
22
22
  TURN_REASONING_LEVELS
23
23
  } from "./chunk-D4YV5TDV.js";
24
24
  import {
25
25
  pluginCatalogRuntime
26
- } from "./chunk-QH3I7ZOK.js";
26
+ } from "./chunk-E3PDZPGV.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,
@@ -7,7 +7,7 @@ import {
7
7
  toCanonicalInputMessage,
8
8
  toCanonicalOutputMessage,
9
9
  toGenAiMessagesTraceAttributes
10
- } from "./chunk-Q6OCUQ7W.js";
10
+ } from "./chunk-DYXVAO2E.js";
11
11
  import {
12
12
  extractGenAiUsageAttributes,
13
13
  logException,
@@ -15,7 +15,7 @@ import {
15
15
  normalizeGenAiFinishReason,
16
16
  serializeGenAiAttribute,
17
17
  withSpan
18
- } from "./chunk-6YCIYOVA.js";
18
+ } from "./chunk-PY3EIEAF.js";
19
19
 
20
20
  // src/chat/services/provider-error.ts
21
21
  var ProviderError = class extends Error {