@sentry/junior 0.115.0 → 0.116.1

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 (111) hide show
  1. package/dist/{agent-hooks-4EUUXP2F.js → agent-hooks-GUAAS3XH.js} +9 -9
  2. package/dist/api/conversations/detail.d.ts +18 -0
  3. package/dist/api/conversations/event-page.d.ts +1 -1
  4. package/dist/api/conversations/events.d.ts +1 -1
  5. package/dist/api/people/profile.d.ts +2 -2
  6. package/dist/api/people/shared.d.ts +1 -1
  7. package/dist/api/personal-tokens/create.d.ts +11 -0
  8. package/dist/api/personal-tokens/list.d.ts +12 -0
  9. package/dist/api/personal-tokens/revoke.d.ts +5 -0
  10. package/dist/api/personal-tokens/routes.d.ts +4 -0
  11. package/dist/api/plugins.d.ts +0 -1
  12. package/dist/api/route.d.ts +1 -1
  13. package/dist/api/schema/conversation.d.ts +18 -0
  14. package/dist/api/schema/person.d.ts +3 -3
  15. package/dist/api/schema/personal-token.d.ts +38 -0
  16. package/dist/api/schema.d.ts +2 -0
  17. package/dist/api/schema.js +15 -3
  18. package/dist/api.d.ts +1 -0
  19. package/dist/api.js +179 -39
  20. package/dist/app.js +1035 -853
  21. package/dist/{catalog-runtime-Y32UEQLB.js → catalog-runtime-WMPC4J4U.js} +5 -5
  22. package/dist/chat/agent/request.d.ts +1 -0
  23. package/dist/chat/agent/resume.d.ts +1 -0
  24. package/dist/chat/agent/sandbox.d.ts +1 -0
  25. package/dist/chat/agent/tools.d.ts +1 -0
  26. package/dist/chat/agent-dispatch/context.d.ts +2 -0
  27. package/dist/chat/agent-dispatch/heartbeat.d.ts +11 -5
  28. package/dist/chat/agent-dispatch/signing.d.ts +14 -5
  29. package/dist/chat/agent-dispatch/store.d.ts +36 -15
  30. package/dist/chat/agent-dispatch/types.d.ts +23 -10
  31. package/dist/chat/agent-dispatch/work.d.ts +58 -0
  32. package/dist/chat/app/factory.d.ts +12 -3
  33. package/dist/chat/conversations/history.d.ts +285 -290
  34. package/dist/chat/conversations/projection.d.ts +2 -2
  35. package/dist/chat/mcp/tool-manager.d.ts +2 -1
  36. package/dist/chat/pi/conversation-events.d.ts +6 -2
  37. package/dist/chat/plugins/annotations.d.ts +8 -0
  38. package/dist/chat/plugins/registry.d.ts +0 -3
  39. package/dist/chat/plugins/types.d.ts +0 -2
  40. package/dist/chat/runtime/agent-continue-runner.d.ts +4 -0
  41. package/dist/chat/runtime/reply-executor.d.ts +6 -1
  42. package/dist/chat/runtime/slack-resume.d.ts +5 -1
  43. package/dist/chat/runtime/turn-input.d.ts +3 -0
  44. package/dist/chat/sandbox/sandbox.d.ts +2 -1
  45. package/dist/chat/sandbox/session.d.ts +2 -11
  46. package/dist/chat/sandbox/workspace.d.ts +10 -2
  47. package/dist/chat/services/turn-session-record.d.ts +14 -1
  48. package/dist/chat/slack/dispatch-turn.d.ts +25 -0
  49. package/dist/chat/state/turn-session.d.ts +11 -0
  50. package/dist/chat/tool-support/text-range-result.d.ts +3 -0
  51. package/dist/chat/tool-support/zod-tool.d.ts +1 -0
  52. package/dist/chat/tools/definition.d.ts +3 -10
  53. package/dist/chat/tools/query-conversation-events.d.ts +68 -0
  54. package/dist/chat/tools/sandbox/file-utils.d.ts +8 -1
  55. package/dist/chat/tools/sandbox/find-files.d.ts +2 -1
  56. package/dist/chat/tools/sandbox/grep.d.ts +2 -1
  57. package/dist/{chunk-6V762AB4.js → chunk-2YYPXQNQ.js} +1 -1
  58. package/dist/{chunk-MIAKQNYX.js → chunk-6ZK6FZIV.js} +1 -1
  59. package/dist/{chunk-67CVNDJ7.js → chunk-7CSVG54J.js} +1 -1
  60. package/dist/{chunk-HWCQRGLL.js → chunk-BFYVIOTS.js} +105 -37
  61. package/dist/{chunk-LYA2AB5G.js → chunk-CGXLCMWI.js} +8 -52
  62. package/dist/{chunk-SYJT7AKB.js → chunk-CY7NXM32.js} +1 -1
  63. package/dist/{chunk-2QG4MZQ7.js → chunk-DLLW5ITL.js} +2 -2
  64. package/dist/{chunk-NVUQSFWX.js → chunk-F3SWGSPG.js} +3 -15
  65. package/dist/{chunk-CWEZEPD4.js → chunk-FAEALXEH.js} +68 -2
  66. package/dist/{chunk-43RYMWJ2.js → chunk-GDAXWEIJ.js} +809 -213
  67. package/dist/{chunk-AGLQYELI.js → chunk-H35BDAUS.js} +170 -170
  68. package/dist/{chunk-YCLO7D7M.js → chunk-JPKGW6L6.js} +77 -26
  69. package/dist/{chunk-G5SX4UPR.js → chunk-KNCELO2M.js} +2 -2
  70. package/dist/{chunk-FHC4JUSF.js → chunk-N3C4XCRE.js} +1 -2
  71. package/dist/{chunk-6FKLPVF3.js → chunk-OY2PQQ4P.js} +1 -1
  72. package/dist/{chunk-6OPTF4BQ.js → chunk-PE44LDDQ.js} +0 -1
  73. package/dist/{chunk-JQFJO5WH.js → chunk-RXRQJF7Y.js} +74 -17
  74. package/dist/{chunk-CEYOL62C.js → chunk-RYFAVWP3.js} +120 -20
  75. package/dist/{chunk-G36V2YGB.js → chunk-TC4ZEM2D.js} +33 -1
  76. package/dist/{chunk-PVZHG2XZ.js → chunk-VBMMMVVQ.js} +112 -35
  77. package/dist/{chunk-SG5WAA7H.js → chunk-WKU7TY22.js} +0 -3
  78. package/dist/{chunk-TVE25LPW.js → chunk-WLT72MRP.js} +1 -1
  79. package/dist/{chunk-EW5MLKT5.js → chunk-XA3VLFPK.js} +1 -55
  80. package/dist/{chunk-RAVKCKXA.js → chunk-ZYHLNTC2.js} +20 -5
  81. package/dist/cli/chat.js +23 -23
  82. package/dist/cli/check.js +6 -6
  83. package/dist/cli/plugins.js +13 -13
  84. package/dist/cli/snapshot-warmup.js +8 -8
  85. package/dist/cli/upgrade.js +7 -7
  86. package/dist/db/schema/api-tokens.d.ts +160 -0
  87. package/dist/db/schema/conversation-annotations.d.ts +142 -0
  88. package/dist/db/schema.d.ts +305 -1
  89. package/dist/{db-KBSJHAZU.js → db-FH4R5ZQ4.js} +6 -6
  90. package/dist/handlers/agent-dispatch.d.ts +7 -3
  91. package/dist/instrumentation.js +2 -2
  92. package/dist/nitro.js +5 -5
  93. package/dist/{oauth-callback-server-EYRMJTCS.js → oauth-callback-server-C2SSJ3FQ.js} +18 -18
  94. package/dist/personal-tokens/store.d.ts +27 -0
  95. package/dist/{plugins-PZMDS7AT.js → plugins-IUJA4VBU.js} +1 -1
  96. package/dist/reporting-schema.d.ts +0 -2
  97. package/dist/{runner-RQGZ5Z2S.js → runner-NAALFIXM.js} +12 -12
  98. package/dist/{skills-JJQIE3BT.js → skills-UN2JXYYF.js} +6 -6
  99. package/dist/{validation-MZ47PZP5.js → validation-EEF4ROHR.js} +6 -6
  100. package/dist/version.js +1 -1
  101. package/migrations/0008_sticky_rage.sql +14 -0
  102. package/migrations/0009_slippery_harrier.sql +12 -0
  103. package/migrations/0010_native_conversation_history.sql +142 -0
  104. package/migrations/meta/0008_snapshot.json +1076 -0
  105. package/migrations/meta/0009_snapshot.json +1146 -0
  106. package/migrations/meta/0010_snapshot.json +1190 -0
  107. package/migrations/meta/_journal.json +22 -1
  108. package/package.json +5 -6
  109. package/dist/chat/agent-dispatch/runner.d.ts +0 -13
  110. package/dist/chat/capabilities/catalog.d.ts +0 -16
  111. package/dist/{chunk-KNFROR7R.js → chunk-5I6ORJUY.js} +1 -1
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createPluginCatalogRuntime
3
- } from "./chunk-EW5MLKT5.js";
3
+ } from "./chunk-XA3VLFPK.js";
4
4
 
5
5
  // src/chat/plugins/catalog-runtime.ts
6
6
  var pluginCatalogRuntime = createPluginCatalogRuntime();
@@ -6,7 +6,6 @@ var healthReportSchema = z.object({
6
6
  timestamp: z.string()
7
7
  }).strict();
8
8
  var pluginSchema = z.object({
9
- capabilities: z.array(z.string()),
10
9
  configKeys: z.array(z.string()),
11
10
  description: z.string(),
12
11
  displayName: z.string(),
@@ -11,18 +11,14 @@ import {
11
11
  import { drizzle } from "drizzle-orm/neon-serverless";
12
12
  import { migrate } from "drizzle-orm/neon-serverless/migrator";
13
13
 
14
- // src/db/schema/conversation-events.ts
14
+ // src/db/schema/conversation-annotations.ts
15
15
  import {
16
16
  foreignKey,
17
- index as index3,
18
- integer as integer2,
19
17
  jsonb as jsonb3,
20
18
  pgTable as pgTable4,
21
19
  primaryKey,
22
- text as text4,
23
- uniqueIndex as uniqueIndex3
20
+ text as text4
24
21
  } from "drizzle-orm/pg-core";
25
- import { sql as sql3 } from "drizzle-orm";
26
22
 
27
23
  // src/db/schema/conversations.ts
28
24
  import { sql as sql2 } from "drizzle-orm";
@@ -178,41 +174,98 @@ var juniorConversations = pgTable3(
178
174
  ]
179
175
  );
180
176
 
177
+ // src/db/schema/conversation-annotations.ts
178
+ var juniorConversationAnnotations = pgTable4(
179
+ "junior_conversation_annotations",
180
+ {
181
+ conversationId: text4("conversation_id").notNull(),
182
+ plugin: text4("plugin").notNull(),
183
+ kind: text4("kind").notNull(),
184
+ key: text4("key").notNull(),
185
+ annotation: jsonb3("annotation_json").$type().notNull(),
186
+ createdAt: timestamptz("created_at").notNull(),
187
+ updatedAt: timestamptz("updated_at").notNull()
188
+ },
189
+ (table) => [
190
+ primaryKey({
191
+ name: "junior_conversation_annotations_pk",
192
+ columns: [table.conversationId, table.plugin, table.kind, table.key]
193
+ }),
194
+ foreignKey({
195
+ name: "junior_conversation_annotations_conversation_id_fk",
196
+ columns: [table.conversationId],
197
+ foreignColumns: [juniorConversations.conversationId]
198
+ }).onDelete("cascade")
199
+ ]
200
+ );
201
+
202
+ // src/db/schema/api-tokens.ts
203
+ import { index as index3, pgTable as pgTable5, text as text5, uniqueIndex as uniqueIndex3 } from "drizzle-orm/pg-core";
204
+ var juniorApiTokens = pgTable5(
205
+ "junior_api_tokens",
206
+ {
207
+ id: text5("id").primaryKey(),
208
+ ownerEmailNormalized: text5("owner_email_normalized").notNull(),
209
+ name: text5("name").notNull(),
210
+ tokenHash: text5("token_hash").notNull(),
211
+ tokenSuffix: text5("token_suffix").notNull(),
212
+ createdAt: timestamptz("created_at").notNull(),
213
+ expiresAt: timestamptz("expires_at").notNull(),
214
+ lastUsedAt: timestamptz("last_used_at"),
215
+ revokedAt: timestamptz("revoked_at")
216
+ },
217
+ (table) => [
218
+ uniqueIndex3("junior_api_tokens_token_hash_uidx").on(table.tokenHash),
219
+ index3("junior_api_tokens_owner_email_idx").on(table.ownerEmailNormalized)
220
+ ]
221
+ );
222
+
181
223
  // src/db/schema/conversation-events.ts
182
- var juniorConversationEvents = pgTable4(
224
+ import {
225
+ foreignKey as foreignKey2,
226
+ index as index4,
227
+ integer as integer2,
228
+ jsonb as jsonb4,
229
+ pgTable as pgTable6,
230
+ primaryKey as primaryKey2,
231
+ text as text6,
232
+ uniqueIndex as uniqueIndex4
233
+ } from "drizzle-orm/pg-core";
234
+ import { sql as sql3 } from "drizzle-orm";
235
+ var juniorConversationEvents = pgTable6(
183
236
  "junior_conversation_events",
184
237
  {
185
- conversationId: text4("conversation_id").notNull(),
238
+ conversationId: text6("conversation_id").notNull(),
186
239
  seq: integer2("seq").notNull(),
187
240
  historyVersion: integer2("history_version").notNull(),
188
241
  schemaVersion: integer2("schema_version").default(1).notNull(),
189
- idempotencyKey: text4("idempotency_key"),
190
- type: text4("type").notNull(),
191
- payload: jsonb3("payload").$type().notNull(),
242
+ idempotencyKey: text6("idempotency_key"),
243
+ type: text6("type").notNull(),
244
+ payload: jsonb4("payload").$type().notNull(),
192
245
  createdAt: timestamptz("created_at").notNull()
193
246
  },
194
247
  (table) => [
195
- primaryKey({
248
+ primaryKey2({
196
249
  name: "junior_conversation_events_conversation_id_seq_pk",
197
250
  columns: [table.conversationId, table.seq]
198
251
  }),
199
- foreignKey({
252
+ foreignKey2({
200
253
  name: "junior_conversation_events_conversation_id_junior_conversations_conversation_id_fk",
201
254
  columns: [table.conversationId],
202
255
  foreignColumns: [juniorConversations.conversationId]
203
256
  }),
204
- index3("junior_conversation_events_history_version_idx").on(
257
+ index4("junior_conversation_events_history_version_idx").on(
205
258
  table.conversationId,
206
259
  table.historyVersion,
207
260
  table.seq
208
261
  ),
209
- index3("junior_conversation_events_type_idx").on(
262
+ index4("junior_conversation_events_type_idx").on(
210
263
  table.conversationId,
211
264
  table.type,
212
265
  table.seq
213
266
  ),
214
- index3("junior_conversation_events_message_search_idx").using("gin", sql3`to_tsvector('english', ${table.payload}->>'text')`).where(sql3`${table.type} = 'message'`),
215
- uniqueIndex3("junior_conversation_events_idempotency_idx").on(
267
+ index4("junior_conversation_events_message_search_idx").using("gin", sql3`to_tsvector('english', ${table.payload}->>'text')`).where(sql3`${table.type} = 'message'`),
268
+ uniqueIndex4("junior_conversation_events_idempotency_idx").on(
216
269
  table.conversationId,
217
270
  table.idempotencyKey
218
271
  )
@@ -221,6 +274,8 @@ var juniorConversationEvents = pgTable4(
221
274
 
222
275
  // src/db/schema.ts
223
276
  var juniorSqlSchema = {
277
+ juniorConversationAnnotations,
278
+ juniorApiTokens,
224
279
  juniorConversationEvents,
225
280
  juniorConversations,
226
281
  juniorDestinations,
@@ -472,6 +527,8 @@ export {
472
527
  juniorUsers,
473
528
  juniorIdentities,
474
529
  juniorConversations,
530
+ juniorConversationAnnotations,
531
+ juniorApiTokens,
475
532
  juniorConversationEvents,
476
533
  createJuniorSqlExecutor
477
534
  };
@@ -4,8 +4,9 @@ import {
4
4
  } from "./chunk-MU6HHZEN.js";
5
5
  import {
6
6
  getStateAdapter
7
- } from "./chunk-67CVNDJ7.js";
7
+ } from "./chunk-7CSVG54J.js";
8
8
  import {
9
+ agentHistoryItemSchema,
9
10
  contextProvenance,
10
11
  createSqlConversationEventStore,
11
12
  getConversationEventStore,
@@ -15,7 +16,7 @@ import {
15
16
  instructionProvenanceFor,
16
17
  sanitizePostgresJson,
17
18
  withConversationEventLock
18
- } from "./chunk-HWCQRGLL.js";
19
+ } from "./chunk-BFYVIOTS.js";
19
20
  import {
20
21
  sleep
21
22
  } from "./chunk-4ZNGQH7C.js";
@@ -24,7 +25,7 @@ import {
24
25
  escapeXml,
25
26
  resolveGatewayModel,
26
27
  unwrapCurrentInstruction
27
- } from "./chunk-SYJT7AKB.js";
28
+ } from "./chunk-CY7NXM32.js";
28
29
  import {
29
30
  toStoredSlackActor
30
31
  } from "./chunk-HZF5P5UN.js";
@@ -33,7 +34,7 @@ import {
33
34
  logException,
34
35
  logWarn,
35
36
  setSpanAttributes
36
- } from "./chunk-NVUQSFWX.js";
37
+ } from "./chunk-F3SWGSPG.js";
37
38
  import {
38
39
  isRecord,
39
40
  toOptionalNumber,
@@ -175,11 +176,47 @@ function authorizationObservationMessage(data, createdAtMs) {
175
176
  timestamp: createdAtMs
176
177
  });
177
178
  }
178
- function messageEventProvenance(data) {
179
- return data.provenance ?? contextProvenance;
180
- }
181
179
  function durableMessages(message) {
182
- return stripRuntimeTurnContext([piMessageSchema.parse(message)]);
180
+ return stripRuntimeTurnContext([message]);
181
+ }
182
+ function historyItemFromPiMessage(message, provenance) {
183
+ const parsed = piMessageSchema.parse(message);
184
+ const { role, ...fields } = parsed;
185
+ if (role === "user") {
186
+ return agentHistoryItemSchema.parse({
187
+ ...fields,
188
+ type: "user_message",
189
+ provenance
190
+ });
191
+ }
192
+ if (role === "assistant") {
193
+ return agentHistoryItemSchema.parse({
194
+ ...fields,
195
+ type: "assistant_message"
196
+ });
197
+ }
198
+ if (role === "toolResult") {
199
+ return agentHistoryItemSchema.parse({
200
+ ...fields,
201
+ type: "tool_result"
202
+ });
203
+ }
204
+ throw new Error(`Unsupported durable agent message role "${role}"`);
205
+ }
206
+ function piMessageFromHistoryItem(data) {
207
+ if (data.type === "user_message") {
208
+ const { type: _2, provenance: __, ...fields2 } = data;
209
+ return piMessageSchema.parse({ ...fields2, role: "user" });
210
+ }
211
+ if (data.type === "assistant_message") {
212
+ const { type: _2, ...fields2 } = data;
213
+ return piMessageSchema.parse({ ...fields2, role: "assistant" });
214
+ }
215
+ const { type: _, ...fields } = data;
216
+ return piMessageSchema.parse({ ...fields, role: "toolResult" });
217
+ }
218
+ function historyItemProvenance(data) {
219
+ return data.type === "user_message" ? data.provenance : contextProvenance;
183
220
  }
184
221
  function projectConversationEvents(events, options) {
185
222
  const messages = [];
@@ -194,22 +231,26 @@ function projectConversationEvents(events, options) {
194
231
  `Unsupported conversation event "${event.data.originalType}" at seq ${event.seq} (schema version ${event.schemaVersion})`
195
232
  );
196
233
  }
197
- if (event.data.type === "compaction" || event.data.type === "handoff" || event.data.type === "rollback") {
234
+ if (event.data.type === "compaction" || event.data.type === "handoff") {
198
235
  modelProfile = event.data.modelProfile;
199
236
  modelId = event.data.modelId;
200
237
  for (const replacement of event.data.replacementHistory) {
201
- for (const message of durableMessages(replacement.message)) {
238
+ for (const message of durableMessages(
239
+ piMessageFromHistoryItem(replacement.item)
240
+ )) {
202
241
  messages.push(message);
203
- provenance.push(replacement.provenance ?? contextProvenance);
242
+ provenance.push(historyItemProvenance(replacement.item));
204
243
  seqs.push(replacement.sourceEventSeq ?? event.seq);
205
244
  }
206
245
  }
207
246
  continue;
208
247
  }
209
- if (event.data.type === "agent_step") {
210
- for (const message of durableMessages(event.data.message)) {
248
+ if (event.data.type === "user_message" || event.data.type === "assistant_message" || event.data.type === "tool_result") {
249
+ for (const message of durableMessages(
250
+ piMessageFromHistoryItem(event.data)
251
+ )) {
211
252
  messages.push(message);
212
- provenance.push(messageEventProvenance(event.data));
253
+ provenance.push(historyItemProvenance(event.data));
213
254
  seqs.push(event.seq);
214
255
  }
215
256
  continue;
@@ -259,9 +300,12 @@ function resolveCommitProvenance(args) {
259
300
  }
260
301
  return args.explicitProvenance;
261
302
  }
303
+ if (args.existing.provenance.length !== args.existing.messages.length) {
304
+ throw new Error("committed provenance must align one-to-one with messages");
305
+ }
262
306
  const matchingPrefix = args.matchingPrefix;
263
307
  const provenance = args.nextMessages.map(
264
- (_, index) => index < matchingPrefix ? args.existing.provenance[index] ?? contextProvenance : contextProvenance
308
+ (_, index) => index < matchingPrefix ? args.existing.provenance[index] : contextProvenance
265
309
  );
266
310
  if (args.newMessageProvenance) {
267
311
  for (let index = args.nextMessages.length - 1; index >= matchingPrefix; index -= 1) {
@@ -371,11 +415,10 @@ async function commitMessagesLocked(args, executor) {
371
415
  await eventStore.append(
372
416
  args.conversationId,
373
417
  newMessages.map((message, index) => ({
374
- data: {
375
- type: "agent_step",
418
+ data: historyItemFromPiMessage(
376
419
  message,
377
- provenance: nextLocalProvenance[matchingPrefix + index]
378
- },
420
+ nextLocalProvenance[matchingPrefix + index]
421
+ ),
379
422
  createdAtMs: messageTimestamp(message)
380
423
  }))
381
424
  );
@@ -650,6 +693,9 @@ var agentTurnSessionSummarySchema = z2.object({
650
693
  cumulativeDurationMs: nonNegativeNumberSchema,
651
694
  cumulativeUsage: agentTurnUsageSchema.optional(),
652
695
  destination: destinationSchema.optional(),
696
+ dispatchId: z2.string().min(1).optional(),
697
+ dispatchOutcome: z2.enum(["blocked", "completed", "failed"]).optional(),
698
+ resultMessageId: z2.string().min(1).optional(),
653
699
  source: sourceSchema.optional(),
654
700
  lastProgressAtMs: nonNegativeNumberSchema,
655
701
  loadedSkillNames: z2.array(z2.string()).optional(),
@@ -752,6 +798,9 @@ function materializeAgentTurnSessionRecord(stored, piProjection, turnStartMessag
752
798
  actors: stored.actors ?? instructionActors(piProjection.provenance),
753
799
  cumulativeDurationMs: stored.cumulativeDurationMs,
754
800
  ...stored.destination ? { destination: stored.destination } : {},
801
+ ...stored.dispatchId ? { dispatchId: stored.dispatchId } : {},
802
+ ...stored.dispatchOutcome ? { dispatchOutcome: stored.dispatchOutcome } : {},
803
+ ...stored.resultMessageId ? { resultMessageId: stored.resultMessageId } : {},
755
804
  ...stored.source ? { source: stored.source } : {},
756
805
  ...stored.cumulativeUsage ? { cumulativeUsage: stored.cumulativeUsage } : {},
757
806
  ...stored.resumeReason ? { resumeReason: stored.resumeReason } : {},
@@ -861,6 +910,9 @@ function buildStoredRecord(args) {
861
910
  cumulativeDurationMs: args.cumulativeDurationMs,
862
911
  ...args.cumulativeUsage ? { cumulativeUsage: args.cumulativeUsage } : {},
863
912
  ...args.destination ? { destination: args.destination } : {},
913
+ ...args.dispatchId ? { dispatchId: args.dispatchId } : {},
914
+ ...args.dispatchOutcome ? { dispatchOutcome: args.dispatchOutcome } : {},
915
+ ...args.resultMessageId ? { resultMessageId: args.resultMessageId } : {},
864
916
  ...args.source ? { source: args.source } : {},
865
917
  ...args.actor ? { actor: args.actor } : {},
866
918
  ...args.actors ? { actors: args.actors } : {},
@@ -936,6 +988,9 @@ async function updateAgentTurnSessionState(args) {
936
988
  cumulativeDurationMs: args.existing.cumulativeDurationMs,
937
989
  ...args.existing.cumulativeUsage ? { cumulativeUsage: args.existing.cumulativeUsage } : {},
938
990
  ...args.existing.destination ? { destination: args.existing.destination } : {},
991
+ ...args.existing.dispatchId ? { dispatchId: args.existing.dispatchId } : {},
992
+ ...args.existing.dispatchOutcome ? { dispatchOutcome: args.existing.dispatchOutcome } : {},
993
+ ...args.existing.resultMessageId ? { resultMessageId: args.existing.resultMessageId } : {},
939
994
  ...args.existing.source ? { source: args.existing.source } : {},
940
995
  ...args.existing.loadedSkillNames ? { loadedSkillNames: args.existing.loadedSkillNames } : {},
941
996
  ...args.existing.modelId ? { modelId: args.existing.modelId } : {},
@@ -955,6 +1010,12 @@ async function upsertAgentTurnSessionRecord(args) {
955
1010
  args.conversationId,
956
1011
  args.sessionId
957
1012
  );
1013
+ const existingDispatchId = existingRecord?.dispatchId ?? (await listAgentTurnSessionSummariesForConversation(args.conversationId)).find((summary) => summary.sessionId === args.sessionId)?.dispatchId;
1014
+ if (existingDispatchId && args.dispatchId && existingDispatchId !== args.dispatchId) {
1015
+ throw new Error(
1016
+ `Turn session ${args.sessionId} dispatchId cannot be changed`
1017
+ );
1018
+ }
958
1019
  const ttlMs = Math.max(1, args.ttlMs ?? AGENT_TURN_SESSION_TTL_MS);
959
1020
  const instructionActor = args.actor ?? existingRecord?.actor;
960
1021
  const commit = await commitMessages({
@@ -993,6 +1054,13 @@ async function upsertAgentTurnSessionRecord(args) {
993
1054
  cumulativeDurationMs: args.cumulativeDurationMs ?? existingRecord?.cumulativeDurationMs ?? 0,
994
1055
  ...args.cumulativeUsage ? { cumulativeUsage: args.cumulativeUsage } : {},
995
1056
  ...args.destination ?? existingRecord?.destination ? { destination: args.destination ?? existingRecord?.destination } : {},
1057
+ ...args.dispatchId ?? existingRecord?.dispatchId ? { dispatchId: args.dispatchId ?? existingRecord?.dispatchId } : {},
1058
+ ...args.dispatchOutcome ?? existingRecord?.dispatchOutcome ? {
1059
+ dispatchOutcome: args.dispatchOutcome ?? existingRecord?.dispatchOutcome
1060
+ } : {},
1061
+ ...args.resultMessageId ?? existingRecord?.resultMessageId ? {
1062
+ resultMessageId: args.resultMessageId ?? existingRecord?.resultMessageId
1063
+ } : {},
996
1064
  ...args.source ?? existingRecord?.source ? { source: args.source ?? existingRecord?.source } : {},
997
1065
  ...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : {},
998
1066
  modelId: args.modelId,
@@ -1014,10 +1082,20 @@ async function upsertAgentTurnSessionRecord(args) {
1014
1082
  });
1015
1083
  }
1016
1084
  async function recordAgentTurnSessionSummary(args) {
1017
- const existing = await getStoredAgentTurnSessionRecord(
1085
+ const stored = await getStoredAgentTurnSessionRecord(
1018
1086
  args.conversationId,
1019
1087
  args.sessionId
1020
1088
  );
1089
+ const priorSummary = (await listAgentTurnSessionSummariesForConversation(args.conversationId)).find((summary2) => summary2.sessionId === args.sessionId);
1090
+ const existing = stored ?? priorSummary;
1091
+ const existingDispatchId = existing?.dispatchId;
1092
+ const existingDispatchOutcome = priorSummary?.dispatchOutcome ?? stored?.dispatchOutcome;
1093
+ const existingResultMessageId = priorSummary?.resultMessageId ?? stored?.resultMessageId;
1094
+ if (existingDispatchId && args.dispatchId && existingDispatchId !== args.dispatchId) {
1095
+ throw new Error(
1096
+ `Turn session ${args.sessionId} dispatchId cannot be changed`
1097
+ );
1098
+ }
1021
1099
  const nowMs = Date.now();
1022
1100
  const ttlMs = Math.max(1, args.ttlMs ?? AGENT_TURN_SESSION_TTL_MS);
1023
1101
  const summary = {
@@ -1033,6 +1111,9 @@ async function recordAgentTurnSessionSummary(args) {
1033
1111
  cumulativeDurationMs: args.cumulativeDurationMs ?? existing?.cumulativeDurationMs ?? 0,
1034
1112
  ...args.cumulativeUsage ?? existing?.cumulativeUsage ? { cumulativeUsage: args.cumulativeUsage ?? existing?.cumulativeUsage } : {},
1035
1113
  ...args.destination ?? existing?.destination ? { destination: args.destination ?? existing?.destination } : {},
1114
+ ...args.dispatchId ?? existingDispatchId ? { dispatchId: args.dispatchId ?? existingDispatchId } : {},
1115
+ ...args.dispatchOutcome ?? existingDispatchOutcome ? { dispatchOutcome: args.dispatchOutcome ?? existingDispatchOutcome } : {},
1116
+ ...args.resultMessageId ?? existingResultMessageId ? { resultMessageId: args.resultMessageId ?? existingResultMessageId } : {},
1036
1117
  ...args.source ?? existing?.source ? { source: args.source ?? existing?.source } : {},
1037
1118
  ...args.actor ?? existing?.actor ? { actor: args.actor ?? existing?.actor } : {},
1038
1119
  ...args.loadedSkillNames ? { loadedSkillNames: args.loadedSkillNames } : existing?.loadedSkillNames ? { loadedSkillNames: existing.loadedSkillNames } : {},
@@ -1202,6 +1283,7 @@ async function persistRunningSessionRecord(args) {
1202
1283
  cumulativeDurationMs: latestSessionRecord?.cumulativeDurationMs,
1203
1284
  cumulativeUsage: latestSessionRecord?.cumulativeUsage,
1204
1285
  ...args.destination ?? latestSessionRecord?.destination ? { destination: args.destination ?? latestSessionRecord?.destination } : {},
1286
+ ...args.dispatchId ?? latestSessionRecord?.dispatchId ? { dispatchId: args.dispatchId ?? latestSessionRecord?.dispatchId } : {},
1205
1287
  ...args.source ?? latestSessionRecord?.source ? { source: args.source ?? latestSessionRecord?.source } : {},
1206
1288
  sessionId: args.sessionId,
1207
1289
  sliceId: args.sliceId,
@@ -1260,6 +1342,14 @@ async function persistCompletedSessionRecord(args) {
1260
1342
  args.currentUsage
1261
1343
  ),
1262
1344
  ...args.destination ?? latestSessionRecord?.destination ? { destination: args.destination ?? latestSessionRecord?.destination } : {},
1345
+ ...args.dispatchId ?? latestSessionRecord?.dispatchId ? { dispatchId: args.dispatchId ?? latestSessionRecord?.dispatchId } : {},
1346
+ ...args.dispatchOutcome ?? latestSessionRecord?.dispatchOutcome ? {
1347
+ dispatchOutcome: args.dispatchOutcome ?? latestSessionRecord?.dispatchOutcome
1348
+ } : {},
1349
+ ...args.errorMessage ? { errorMessage: args.errorMessage } : {},
1350
+ ...args.resultMessageId ?? latestSessionRecord?.resultMessageId ? {
1351
+ resultMessageId: args.resultMessageId ?? latestSessionRecord?.resultMessageId
1352
+ } : {},
1263
1353
  ...args.source ?? latestSessionRecord?.source ? { source: args.source ?? latestSessionRecord?.source } : {},
1264
1354
  ...args.destinationVisibility ? { destinationVisibility: args.destinationVisibility } : {},
1265
1355
  sessionId: args.sessionId,
@@ -1290,6 +1380,10 @@ async function completeDeliveredTurn(args) {
1290
1380
  currentUsage: args.usage,
1291
1381
  destination: args.destination,
1292
1382
  destinationVisibility: args.destinationVisibility,
1383
+ dispatchId: args.dispatchId,
1384
+ dispatchOutcome: args.dispatchOutcome,
1385
+ errorMessage: args.errorMessage,
1386
+ resultMessageId: args.resultMessageId,
1293
1387
  source: args.source,
1294
1388
  sessionId: args.sessionId,
1295
1389
  sliceId: args.sliceId,
@@ -1328,6 +1422,7 @@ async function persistAuthPauseSessionRecord(args) {
1328
1422
  args.currentUsage
1329
1423
  ),
1330
1424
  ...args.destination ?? latestSessionRecord?.destination ? { destination: args.destination ?? latestSessionRecord?.destination } : {},
1425
+ ...args.dispatchId ?? latestSessionRecord?.dispatchId ? { dispatchId: args.dispatchId ?? latestSessionRecord?.dispatchId } : {},
1331
1426
  ...args.source ?? latestSessionRecord?.source ? { source: args.source ?? latestSessionRecord?.source } : {},
1332
1427
  sessionId: args.sessionId,
1333
1428
  sliceId: nextSliceId,
@@ -1392,6 +1487,7 @@ async function persistContinuationSessionRecord(args) {
1392
1487
  ...args.destination ?? latestSessionRecord?.destination ? {
1393
1488
  destination: args.destination ?? latestSessionRecord?.destination
1394
1489
  } : {},
1490
+ ...args.dispatchId ?? latestSessionRecord?.dispatchId ? { dispatchId: args.dispatchId ?? latestSessionRecord?.dispatchId } : {},
1395
1491
  ...args.source ?? latestSessionRecord?.source ? { source: args.source ?? latestSessionRecord?.source } : {},
1396
1492
  sessionId: args.sessionId,
1397
1493
  sliceId: args.currentSliceId,
@@ -1418,6 +1514,7 @@ async function persistContinuationSessionRecord(args) {
1418
1514
  cumulativeDurationMs,
1419
1515
  cumulativeUsage,
1420
1516
  ...args.destination ?? latestSessionRecord?.destination ? { destination: args.destination ?? latestSessionRecord?.destination } : {},
1517
+ ...args.dispatchId ?? latestSessionRecord?.dispatchId ? { dispatchId: args.dispatchId ?? latestSessionRecord?.dispatchId } : {},
1421
1518
  ...args.source ?? latestSessionRecord?.source ? { source: args.source ?? latestSessionRecord?.source } : {},
1422
1519
  sessionId: args.sessionId,
1423
1520
  sliceId: nextSliceId,
@@ -1471,6 +1568,7 @@ async function persistYieldSessionRecord(args) {
1471
1568
  args.currentUsage
1472
1569
  ),
1473
1570
  ...args.destination ?? latestSessionRecord?.destination ? { destination: args.destination ?? latestSessionRecord?.destination } : {},
1571
+ ...args.dispatchId ?? latestSessionRecord?.dispatchId ? { dispatchId: args.dispatchId ?? latestSessionRecord?.dispatchId } : {},
1474
1572
  ...args.source ?? latestSessionRecord?.source ? { source: args.source ?? latestSessionRecord?.source } : {},
1475
1573
  sessionId: args.sessionId,
1476
1574
  sliceId: args.currentSliceId,
@@ -2680,6 +2778,8 @@ export {
2680
2778
  retainRuntimeTurnContext,
2681
2779
  instructionTextForProjection,
2682
2780
  stripRuntimeTurnContext,
2781
+ historyItemFromPiMessage,
2782
+ piMessageFromHistoryItem,
2683
2783
  loadProjection,
2684
2784
  loadConversationProjection,
2685
2785
  openConversationProjection,
@@ -39,6 +39,7 @@ function activityDays(days, nowMs, count) {
39
39
 
40
40
  // src/api/schema/conversation.ts
41
41
  import { z as z2 } from "zod";
42
+ import { conversationAnnotationInputSchema } from "@sentry/junior-plugin-api";
42
43
  var conversationReportStatusSchema = z2.enum([
43
44
  "active",
44
45
  "completed",
@@ -263,6 +264,15 @@ function validateConversationEvents(report, context) {
263
264
  }
264
265
  }
265
266
  var conversationDetailReportSchema = conversationSummaryReportSchema.extend({
267
+ annotations: z2.array(
268
+ conversationAnnotationInputSchema.and(
269
+ z2.object({
270
+ plugin: z2.string().min(1),
271
+ createdAt: z2.string().datetime(),
272
+ updatedAt: z2.string().datetime()
273
+ })
274
+ )
275
+ ).optional(),
266
276
  modelUsage: z2.array(conversationModelUsageSchema).optional(),
267
277
  events: z2.array(conversationReportEventSchema),
268
278
  eventHistory: conversationEventHistorySchema,
@@ -406,6 +416,22 @@ var locationDetailReportSchema = locationSummaryReportSchema.extend({
406
416
  import { z as z5 } from "zod";
407
417
  var apiErrorSchema = z5.object({ error: z5.string().min(1) }).strict();
408
418
 
419
+ // src/api/schema/personal-token.ts
420
+ import { z as z6 } from "zod";
421
+ var personalTokenMetadataSchema = z6.object({
422
+ id: z6.string().uuid(),
423
+ name: z6.string(),
424
+ tokenSuffix: z6.string(),
425
+ createdAt: z6.string().datetime(),
426
+ expiresAt: z6.string().datetime(),
427
+ lastUsedAt: z6.string().datetime().nullable()
428
+ }).strict();
429
+ var personalTokenListSchema = z6.object({ tokens: z6.array(personalTokenMetadataSchema) }).strict();
430
+ var createPersonalTokenBodySchema = z6.object({ name: z6.string().trim().min(1).max(80) }).strict();
431
+ var createdPersonalTokenSchema = personalTokenMetadataSchema.extend({ token: z6.string().startsWith("jr_pat_") }).strict();
432
+ var personalTokenParamsSchema = z6.object({ id: z6.string().uuid() }).strict();
433
+ var revokePersonalTokenResponseSchema = z6.object({ revoked: z6.literal(true) }).strict();
434
+
409
435
  export {
410
436
  apiErrorSchema,
411
437
  conversationParamsSchema,
@@ -430,5 +456,11 @@ export {
430
456
  locationParamsSchema,
431
457
  locationActivityDayReportSchema,
432
458
  locationDirectoryReportSchema,
433
- locationDetailReportSchema
459
+ locationDetailReportSchema,
460
+ personalTokenMetadataSchema,
461
+ personalTokenListSchema,
462
+ createPersonalTokenBodySchema,
463
+ createdPersonalTokenSchema,
464
+ personalTokenParamsSchema,
465
+ revokePersonalTokenResponseSchema
434
466
  };