@sentry/junior 0.311.0 → 0.313.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 (120) hide show
  1. package/dist/{adapter-B1wujchl.js → adapter-CYAvJzZS.js} +1 -1
  2. package/dist/{adapter-context-G2M0y6rP.js → adapter-context-CVsHoVSf.js} +2 -2
  3. package/dist/{admin-DCiBhUT1.js → admin-Cyhb4TwZ.js} +1 -1
  4. package/dist/{agent-runner-BVHPUIc8.js → agent-runner-B5y9MsT-.js} +3487 -3493
  5. package/dist/api/schema.d.ts +2 -2
  6. package/dist/api/schema.js +6 -6
  7. package/dist/api.d.ts +2 -2
  8. package/dist/api.js +294 -311
  9. package/dist/{app-Cw5Vy6H6.d.ts → app-DA8-hCMj.d.ts} +2 -9
  10. package/dist/app.d.ts +1 -1
  11. package/dist/app.js +336 -604
  12. package/dist/{background-compaction-queue-CJDnWVOJ.js → background-compaction-queue-iZXadLV3.js} +60 -85
  13. package/dist/{catalog-runtime-DMY3VV-D.js → catalog-runtime-kkE3hvCX.js} +1 -1
  14. package/dist/channel-access-mt7K6dPh.js +221 -0
  15. package/dist/cli/chat.js +18 -19
  16. package/dist/cli/check.js +3 -3
  17. package/dist/cli/init.js +0 -1
  18. package/dist/cli/main.js +3 -7
  19. package/dist/cli/plugins.js +4 -4
  20. package/dist/cli/run.d.ts +1 -2
  21. package/dist/cli/run.js +1 -2
  22. package/dist/cli/snapshot-create.js +5 -5
  23. package/dist/cli/upgrade.d.ts +1 -1
  24. package/dist/cli/upgrade.js +3 -3
  25. package/dist/{config-BrXDQefC.js → config-CWbwKj0j.js} +59 -27
  26. package/dist/{continue-in-slack-DNXSC9So.js → continue-in-slack-CxyFzdlF.js} +7 -8
  27. package/dist/{conversation-feed-DkinDu5o.js → conversation-feed-BEXLD3Me.js} +86 -21
  28. package/dist/{conversation-privacy-DxttrKb9.js → conversation-privacy-BrMiDN61.js} +1 -1
  29. package/dist/{conversation-turn-DWw7Xhdr.js → conversation-turn-B35eu0uz.js} +78 -56
  30. package/dist/{credential-sync-Bk8wGb8Y.js → credential-sync-DWTOEQrm.js} +15 -15
  31. package/dist/{projection-Cns7XwWa.js → credentialed-Dyv8b-lu.js} +16306 -20732
  32. package/dist/{db-7ETESH44.d.ts → db-DYGcXYl3.d.ts} +11 -6
  33. package/dist/{db-DTxzH7u5.js → db-PwSRzWWn.js} +181 -100
  34. package/dist/{executor-DqTiYj9S.js → executor-CgWyWfYz.js} +117 -99
  35. package/dist/{html-B9Sl4Axb.js → html-DidUcRhI.js} +6 -6
  36. package/dist/ingest-B0AggUEC.js +7931 -0
  37. package/dist/{install-Sg4ePfLl.js → install-2urLLXNt.js} +2 -2
  38. package/dist/instrumentation.js +3 -3
  39. package/dist/{lineage-BHAMpNKr.js → lineage-BXplQAVH.js} +2 -2
  40. package/dist/{stop-CYsfc0Ed.js → list-DyIyReSV.js} +709 -475
  41. package/dist/{logging-FjclQsXu.js → logging-DNt-qOIO.js} +1 -1
  42. package/dist/{schedule-BLJ476XQ.js → media-B0pZJ0bG.js} +1058 -11
  43. package/dist/{message-CJ7_RL50.js → message-Z5YKC-Af.js} +35 -28
  44. package/dist/{model-input-CMLh4Cwq.js → model-input-BhPJYdSV.js} +3 -3
  45. package/dist/nitro.d.ts +1 -1
  46. package/dist/nitro.js +4 -3
  47. package/dist/{oauth-callback-server-RVcbiDjL.js → oauth-callback-server-ByvDdcdY.js} +2 -2
  48. package/dist/{oauth-relay-Bu9kkaQu.js → oauth-relay-D-kK0yoN.js} +1 -1
  49. package/dist/{registry-BPwuOP2O.js → registry-POH4bZC4.js} +1 -1
  50. package/dist/reporting-window-C4dbzDiR.js +124 -0
  51. package/dist/request-deadline-BUiRYQYj.js +24 -0
  52. package/dist/{resolve-BK29bBry.js → resolve-CWtBNSKP.js} +3 -3
  53. package/dist/{runner-BcAE-cJm.js → runner-CsZ_VRxp.js} +14 -16
  54. package/dist/{sandbox-egress-signals-C-q0go5b.js → sandbox-egress-signals-FbCk1FkN.js} +1 -1
  55. package/dist/{schema-DYcJeV7d.d.ts → schema-DBf18QPS.d.ts} +2773 -3630
  56. package/dist/{schema-BLgSZXcL.js → schema-DojR2uCL.js} +106 -121
  57. package/dist/{service-account-iJoCtkHR.js → service-account-CDYb9hfX.js} +3 -3
  58. package/dist/{service-account-gN0zqf0S.js → service-account-o15pZWcJ.js} +5 -5
  59. package/dist/{skills-BoZ80epJ.js → skills-B0jP4whm.js} +2 -2
  60. package/dist/{slack-conversation-unfurl-CogYrITA.js → slack-conversation-unfurl-D26t9kBC.js} +9 -9
  61. package/dist/{spawn-Dk92r7mX.js → spawn-BjljgExZ.js} +14 -32
  62. package/dist/start-conversation-DbVujrwO.js +755 -0
  63. package/dist/{state-DH3Cmgp3.js → state-BTawTCme.js} +4 -4
  64. package/dist/statuses-BKwqCPhj.js +69 -0
  65. package/dist/store-CjXrp-Up.js +492 -0
  66. package/dist/task-queue-Cwlatjz3.js +90 -0
  67. package/dist/task-runner--Ke8KSMf.js +1432 -0
  68. package/dist/{thread-context-BW2BsQbH.js → thread-context-B8exINEe.js} +6 -7
  69. package/dist/turn-membership-DTR3SaKD.js +5859 -0
  70. package/dist/{validation-DrJd0nnq.js → validation-Ce0qbMlT.js} +1 -1
  71. package/dist/{task-queue-C_zldF5J.js → vercel-queue-q4z8w5QO.js} +93 -172
  72. package/dist/{version-CNKZ8owc.js → version-DFh4n9nr.js} +1 -1
  73. package/dist/version.js +1 -1
  74. package/dist/{warmup-BWdHew2H.js → warmup-D5hzqTcp.js} +4853 -13605
  75. package/dist/web-message-id-C6P83ans.js +10 -0
  76. package/dist/{worker-t9qpu_Zx.js → worker-CDg9Lbpg.js} +20 -7
  77. package/migrations/0143_todos.sql +14 -0
  78. package/migrations/0144_inbox_items.sql +32 -0
  79. package/migrations/0145_todo_changed_by_agent.sql +1 -0
  80. package/migrations/0146_inbox_item_subject_title_parts.sql +1 -0
  81. package/migrations/0147_inbox_snooze_wake_reason.sql +1 -0
  82. package/migrations/0148_authorization_request_index.sql +1 -0
  83. package/migrations/0149_conversation_metadata.sql +10 -0
  84. package/migrations/0150_conversation_metadata_fill.sql +39 -0
  85. package/migrations/0151_conversation_search_index.sql +1 -0
  86. package/migrations/0152_inbox_item_legacy_automation_keys.sql +21 -0
  87. package/migrations/0153_artifact_expiry.sql +1 -0
  88. package/migrations/0154_artifact_permanent_sha_index.sql +1 -0
  89. package/migrations/0155_artifact_drop_public_sha_index.sql +3 -0
  90. package/migrations/0156_conversation_kind_lead.sql +6 -0
  91. package/migrations/0157_conversation_lead_actor_index.sql +1 -0
  92. package/migrations/0158_keep_legacy_archive_columns.sql +5 -0
  93. package/migrations/0159_conversation_embeddings_fk_validate.sql +5 -0
  94. package/migrations/meta/0143_snapshot.json +6434 -0
  95. package/migrations/meta/0144_snapshot.json +6434 -0
  96. package/migrations/meta/0145_snapshot.json +6440 -0
  97. package/migrations/meta/0146_snapshot.json +6446 -0
  98. package/migrations/meta/0147_snapshot.json +6452 -0
  99. package/migrations/meta/0148_snapshot.json +6474 -0
  100. package/migrations/meta/0149_snapshot.json +6490 -0
  101. package/migrations/meta/0150_snapshot.json +6490 -0
  102. package/migrations/meta/0151_snapshot.json +6505 -0
  103. package/migrations/meta/0152_snapshot.json +6505 -0
  104. package/migrations/meta/0153_snapshot.json +6511 -0
  105. package/migrations/meta/0154_snapshot.json +6533 -0
  106. package/migrations/meta/0155_snapshot.json +6511 -0
  107. package/migrations/meta/0156_snapshot.json +6511 -0
  108. package/migrations/meta/0157_snapshot.json +6527 -0
  109. package/migrations/meta/0158_snapshot.json +6515 -0
  110. package/migrations/meta/0159_snapshot.json +6515 -0
  111. package/migrations/meta/_journal.json +120 -1
  112. package/package.json +6 -6
  113. package/skills/design-automation-skill/SKILL.md +108 -0
  114. package/dist/briefs-BDjnug6Y.js +0 -395
  115. package/dist/conversation-ca__NDQW.js +0 -1063
  116. package/dist/prompt-CDqcsDYC.js +0 -910
  117. package/dist/store-DmmMIrQi.js +0 -335
  118. package/dist/task-runner-C7oCJQIx.js +0 -294
  119. package/dist/turn-session-routing-Xh_2nSQe.js +0 -261
  120. package/dist/web-message-id-Ch5dPq-a.js +0 -306
@@ -1,1063 +0,0 @@
1
- import { a as conversationTurnFailureReasonSchema, h as usageSchema, i as conversationTurnFailureCodeSchema } from "./history-CYstOMKX.js";
2
- import * as z from "zod";
3
- import { codeChangeStateSchema, conversationAnnotationInputSchema, conversationEventPresentationSchema, conversationSidebarAnnotationSchema, objectFactFields, objectTypeSchema } from "@sentry/junior-plugin-api";
4
- // src/chat/attachments/input.ts
5
- /**
6
- * Largest file that Junior stores from Slack or the web, or loads into the
7
- * sandbox.
8
- *
9
- * Every path streams the bytes, so this cap does not depend on function
10
- * memory. It bounds transfer time and sandbox disk use.
11
- */
12
- const MAX_ATTACHMENT_BYTES = 262144e3;
13
- /** Most files on one web Message, as in one Slack message. */
14
- const MAX_INPUT_ATTACHMENTS = 10;
15
- /** File facts that a browser declares before it uploads the bytes. */
16
- const inputFileSchema = z.object({
17
- filename: z.string().trim().min(1).max(255),
18
- contentType: z.string().trim().toLowerCase().max(127).regex(/^[a-z0-9][\w.+-]*\/[a-z0-9][\w.+-]*$/),
19
- bytes: z.number().int().min(1).max(MAX_ATTACHMENT_BYTES)
20
- }).strict();
21
- /** Safe attachment facts shared by mailbox input and transcript messages. */
22
- const messageAttachmentSchema = z.object({
23
- id: z.string().min(1),
24
- filename: z.string().min(1),
25
- contentType: z.string().min(1),
26
- bytes: z.number().int().nonnegative(),
27
- /**
28
- * True for a large Slack file that Junior has not stored yet. A
29
- * dashboard read downloads it from Slack, so it has no preview.
30
- */
31
- pending: z.literal(true).optional()
32
- }).strict();
33
- /** Read attachment metadata without exposing object storage keys or bytes. */
34
- function readMessageAttachments(value) {
35
- return messageAttachmentSchema.array().parse(value ?? []);
36
- }
37
- // src/chat/automations/card.ts
38
- /** Saved automation facts shown with a Message, not a live status view. */
39
- const automationCardSchema = z.object({
40
- kind: z.literal("automation"),
41
- id: z.string().min(1),
42
- title: z.string().min(1).max(160),
43
- url: z.string().url().nullable(),
44
- instruction: z.string().max(4e3),
45
- trigger: z.string().min(1),
46
- warning: z.string().nullable()
47
- }).strict();
48
- /** Render saved card facts for text-only delivery and accessible fallbacks. */
49
- function automationCardText(card) {
50
- return [
51
- card.title,
52
- card.warning,
53
- card.trigger,
54
- card.instruction,
55
- card.url,
56
- `Automation ID: ${card.id}`
57
- ].filter(Boolean).join("\n");
58
- }
59
- // src/chat/conversations/cards.ts
60
- const storedCardSchema = automationCardSchema.extend({ operation: z.enum([
61
- "created",
62
- "updated",
63
- "deleted"
64
- ]).optional() });
65
- /** Render each built-in card with its own text format. */
66
- function messageCardText(card) {
67
- switch (card.kind) {
68
- case "object": return [
69
- card.title,
70
- card.label !== card.title ? card.label : void 0,
71
- card.description,
72
- card.status,
73
- ...objectFactFields(card.facts).map((field) => `${field.label}: ${field.value}`),
74
- card.trigger,
75
- card.warning,
76
- card.url
77
- ].filter(Boolean).join("\n");
78
- case "automation": return automationCardText(card);
79
- }
80
- }
81
- /** Identify a deleted object whose pending card must be omitted. */
82
- const removedCardSchema = z.object({
83
- plugin: z.string().min(1),
84
- key: z.string().min(1)
85
- }).strict();
86
- /** Store only the annotation identity with a Message. */
87
- const messageCardRefSchema = removedCardSchema.extend({ kind: z.literal("object") });
88
- /** Remove display facts before saving or reporting a Message card. */
89
- function messageCardRef(card) {
90
- return card.kind === "object" ? {
91
- kind: "object",
92
- plugin: card.plugin,
93
- key: card.key
94
- } : {
95
- kind: "object",
96
- plugin: "junior",
97
- key: card.id
98
- };
99
- }
100
- /** Read references, including identities from older saved card snapshots. */
101
- function readMessageCardRefs(value) {
102
- return [...storedCardSchema.array().parse(value.cards ?? []).flatMap(({ operation, ...card }) => operation === "deleted" ? [] : [messageCardRef(card)]), ...messageCardRefSchema.strip().array().parse(value.objectCards ?? [])];
103
- }
104
- /** Resolve current saved facts without fetching providers or changing history. */
105
- function resolveMessageCards(refs, annotations) {
106
- return refs.map((ref) => {
107
- const annotation = annotations.find((item) => item.kind === ref.kind && item.plugin === ref.plugin && item.key === ref.key);
108
- return annotation ? annotationCard(annotation) : {
109
- ...ref,
110
- objectType: "item",
111
- title: ref.key,
112
- label: ref.key,
113
- url: null,
114
- warning: "Saved annotation is unavailable."
115
- };
116
- });
117
- }
118
- /** Copy saved annotation facts without storage timestamps for Message delivery. */
119
- function annotationCard(annotation) {
120
- const { createdAt: _createdAt, updatedAt: _updatedAt, ...value } = annotation;
121
- return value.kind === "object" ? value : {
122
- ...value,
123
- kind: "object",
124
- objectType: value.objectType ?? "item",
125
- title: value.label
126
- };
127
- }
128
- // src/chat/review-items/change-record.ts
129
- /**
130
- * The person change to a Review item that one message records. Each inbound
131
- * message and saved Message that reports a take, answer, or dismiss carries
132
- * its own record, so the dashboard shows what that message did, not what the
133
- * item looks like now.
134
- */
135
- const reviewItemChangeRecordSchema = z.object({
136
- kind: z.enum([
137
- "submitted",
138
- "dismissed",
139
- "taken"
140
- ]),
141
- reviewItemId: z.string().min(1)
142
- }).strict();
143
- // src/api/schema/conversation-read-position.ts
144
- /**
145
- * How far the signed-in viewer has read a Conversation transcript.
146
- *
147
- * `lastReadSeq` is the event sequence of the last transcript row the viewer
148
- * saw. Reports only move it forward: the server keeps the highest value it
149
- * receives. It is never before the viewer's own latest Message.
150
- */
151
- const conversationReadPositionSchema = z.object({ lastReadSeq: z.number().int().nonnegative() }).strict();
152
- // src/api/schema/conversation-title.ts
153
- /** Longest Conversation title that a rename can save. */
154
- const CONVERSATION_TITLE_MAX_LENGTH = 200;
155
- /** A Conversation title that a caller chooses, at creation or on rename. */
156
- const conversationTitleSchema = z.string().trim().min(1).max(200);
157
- /** A participant's new title for one Conversation. Every viewer sees it. */
158
- const renameConversationBodySchema = z.object({ title: conversationTitleSchema }).strict();
159
- /** The stored title after the rename. */
160
- const renameConversationResponseSchema = z.object({ title: z.string().min(1) }).strict();
161
- // src/api/schema/conversation-tree-state.ts
162
- /**
163
- * What a Conversation and its child Conversations need, for one viewer.
164
- * See "Viewer state" in `TERMINOLOGY.md`.
165
- */
166
- const conversationTreeStateSchema = z.enum([
167
- "needs_you",
168
- "working",
169
- "done"
170
- ]);
171
- // src/chat/briefs/schema.ts
172
- /**
173
- * Runtime schemas for the Brief record and the generator input. Both cross a
174
- * durable or CLI edge, so these schemas own the exported types.
175
- */
176
- const LINE_MAX = 400;
177
- const lineSchema = z.string().trim().min(1).max(LINE_MAX);
178
- const urlSchema = z.string().url().max(2048);
179
- const timestampSchema = z.string().datetime();
180
- const briefLocationSchema = z.object({
181
- provider: z.string().trim().min(1).max(100),
182
- channelName: lineSchema.optional()
183
- }).strict();
184
- const briefOutcomeStatusSchema = z.enum([
185
- "in_progress",
186
- "answered",
187
- "done",
188
- "partial",
189
- "blocked",
190
- "abandoned"
191
- ]);
192
- const briefCodeChangeSchema = z.object({
193
- repository: lineSchema,
194
- number: z.number().int().positive(),
195
- title: lineSchema.optional(),
196
- url: urlSchema,
197
- state: codeChangeStateSchema,
198
- openedAt: timestampSchema.optional(),
199
- mergedAt: timestampSchema.optional(),
200
- closedAt: timestampSchema.optional()
201
- }).strict();
202
- const briefLinkSchema = z.object({
203
- kind: z.enum([
204
- "code_change",
205
- "resource",
206
- "url"
207
- ]),
208
- label: lineSchema,
209
- url: urlSchema,
210
- status: lineSchema.optional()
211
- }).strict();
212
- const briefRecordSchema = z.object({
213
- startedAt: timestampSchema,
214
- lastActivityAt: timestampSchema,
215
- durationMs: z.number().int().nonnegative(),
216
- participants: z.array(z.object({
217
- name: lineSchema,
218
- messages: z.number().int().positive()
219
- }).strict()),
220
- userMessages: z.number().int().nonnegative(),
221
- assistantMessages: z.number().int().nonnegative(),
222
- toolResults: z.number().int().nonnegative(),
223
- events: z.number().int().nonnegative(),
224
- turns: z.number().int().positive().optional(),
225
- location: briefLocationSchema.optional(),
226
- codeChanges: z.array(briefCodeChangeSchema)
227
- }).strict();
228
- const conversationBriefSchema = z.object({
229
- schemaVersion: z.literal(1),
230
- record: briefRecordSchema,
231
- summary: z.string().trim().min(1).max(600),
232
- intent: lineSchema,
233
- outcome: z.object({
234
- status: briefOutcomeStatusSchema,
235
- text: z.string().trim().min(1).max(600)
236
- }).strict(),
237
- decisions: z.array(z.object({
238
- text: lineSchema,
239
- by: lineSchema.optional(),
240
- kind: z.enum([
241
- "stated",
242
- "confirmed",
243
- "assumed"
244
- ])
245
- }).strict()).max(20),
246
- facts: z.array(lineSchema).max(30),
247
- links: z.array(briefLinkSchema).max(40),
248
- keywords: z.array(z.string().trim().toLowerCase().min(1).max(400)).max(12)
249
- }).strict();
250
- /** Parse a stored Brief row, dropping fields that older versions wrote. */
251
- function parseStoredBrief(content) {
252
- if (content && typeof content === "object" && "openDecisions" in content) {
253
- const { openDecisions: _openDecisions, ...rest } = content;
254
- return conversationBriefSchema.parse(rest);
255
- }
256
- return conversationBriefSchema.parse(content);
257
- }
258
- const briefEntrySchema = z.object({
259
- index: z.number().int().nonnegative(),
260
- role: z.enum([
261
- "user",
262
- "assistant",
263
- "tool",
264
- "event"
265
- ]),
266
- author: lineSchema.optional(),
267
- text: z.string().min(1),
268
- createdAtMs: z.number().int().nonnegative(),
269
- turnId: z.string().min(1).optional()
270
- }).strict();
271
- const briefResourceSchema = z.object({
272
- label: lineSchema,
273
- url: urlSchema,
274
- status: lineSchema.optional()
275
- }).strict();
276
- const briefInputSchema = z.object({
277
- conversationId: z.string().min(1),
278
- title: lineSchema.optional(),
279
- visibility: z.enum(["private", "public"]),
280
- location: briefLocationSchema.optional(),
281
- entries: z.array(briefEntrySchema),
282
- codeChanges: z.array(briefCodeChangeSchema),
283
- resources: z.array(briefResourceSchema)
284
- }).strict();
285
- /**
286
- * Label an annotation as a Brief resource. An object label is only its id,
287
- * such as `owner/repo#123`, so keep its title: Brief search matches labels,
288
- * and a later Conversation must find the object by its topic.
289
- */
290
- function briefResourceLabel(annotation) {
291
- return (annotation.kind === "object" && annotation.title !== annotation.label ? `${annotation.label} · ${annotation.title}` : annotation.label).slice(0, LINE_MAX).trim();
292
- }
293
- /** Parse the provider-neutral input used by every Brief generator adapter. */
294
- function parseBriefInput(input) {
295
- const parsed = briefInputSchema.parse(input);
296
- return {
297
- ...parsed,
298
- entries: [...parsed.entries].sort((left, right) => left.index - right.index || left.createdAtMs - right.createdAtMs)
299
- };
300
- }
301
- // src/chat/agent-invocations/agent-types.ts
302
- /**
303
- * Child agent types. A type is plain data: when to pick it and what the child
304
- * reads with its task. Runtime code reads only these fields, never a type
305
- * name, so types can later come from configuration. Types do not limit tools:
306
- * Guardian reviews each child action against the root user's messages, as for
307
- * any child. A child keeps its type for later agent invocations. How a child
308
- * starts, fresh or forked from its parent's history, is not a type: see
309
- * `fork` on the agent invocation.
310
- */
311
- const AGENT_TYPES = ["explore", "reviewer"];
312
- /**
313
- * Stored name of a child agent type. A stored name stays readable after its
314
- * type is removed; the runtime then treats the child as a
315
- * child without a type.
316
- */
317
- const agentTypeSchema = z.string().regex(/^[a-z][a-z0-9_-]*$/);
318
- const AGENT_TYPE_DEFINITIONS = {
319
- explore: {
320
- whenToUse: "Investigation across code, docs, logs, telemetry, or the web. Use it when an answer needs reading across many files or sources and you need the conclusion with evidence, not the raw output.",
321
- instructions: "You are an explore agent. Your job is to investigate and report, so do not change anything outside your sandbox unless the task asks for it. Report what you found with exact evidence, such as paths, lines, links, and ids, and say what you could not verify."
322
- },
323
- reviewer: {
324
- whenToUse: "An independent second opinion on a change, plan, or claim. Give it the evidence to judge, not your conclusion.",
325
- instructions: "You are a reviewer agent. Give an independent assessment. Do not assume that the parent's framing is correct: verify each claim against the evidence. Do not change anything outside your own sandbox. Report concrete problems ranked by severity, each with its evidence, and say clearly when you found none."
326
- }
327
- };
328
- function agentTypeDefinition(type) {
329
- return type && Object.hasOwn(AGENT_TYPE_DEFINITIONS, type) ? AGENT_TYPE_DEFINITIONS[type] : void 0;
330
- }
331
- /** Model-facing list of child agent types. */
332
- function formatAgentTypes() {
333
- return AGENT_TYPES.map((type) => `- "${type}": ${AGENT_TYPE_DEFINITIONS[type].whenToUse}`).join("\n");
334
- }
335
- /** Return the instructions that a child of this type reads with its task. */
336
- function agentTypeInstructions(type) {
337
- return agentTypeDefinition(type)?.instructions;
338
- }
339
- // src/api/schema/child-agent-totals.ts
340
- /**
341
- * The part of a Conversation total that its child agents spent, at any depth.
342
- * Present only when the Conversation has child agents. The Conversation's own
343
- * part is the total minus this part.
344
- */
345
- const conversationChildAgentTotalsSchema = z.object({
346
- auxiliaryCostUsd: z.number().finite().nonnegative().optional(),
347
- count: z.number().int().positive(),
348
- cumulativeDurationMs: z.number(),
349
- cumulativeUsage: usageSchema.optional()
350
- }).strict();
351
- // src/api/schema/object-preview-image.ts
352
- /**
353
- * One saved preview image of an object, such as a pull request screenshot,
354
- * at 1x and 2x. Both name the Junior image route, never the image host.
355
- */
356
- const objectPreviewImageSchema = z.object({
357
- src: z.string().startsWith("/api/images/"),
358
- srcSet: z.string().min(1)
359
- }).strict();
360
- const CUT_TOKEN_RE = /<(?:[@#!][^<>]*|[a-z]+:[^\s<>|]*(?:\|[^<>]*)?|[a-z]*)$/i;
361
- /**
362
- * Cut preview text to the schema limit. The cut ends with "…" at a word
363
- * break, and never leaves half a surrogate pair or an unclosed Slack token
364
- * such as `<@U1` or `<https://…`, so mentions and links still parse.
365
- */
366
- function activityPreviewText(text) {
367
- if (text.length <= 400) return text;
368
- let cut = text.slice(0, 399);
369
- const space = cut.search(/\s\S*$/);
370
- if (space > 0 && /\S/.test(text[cut.length])) cut = cut.slice(0, space);
371
- const last = cut.charCodeAt(cut.length - 1);
372
- if (last >= 55296 && last <= 56319) cut = cut.slice(0, -1);
373
- return `${cut.replace(CUT_TOKEN_RE, "").trimEnd()}…`;
374
- }
375
- // src/api/schema/conversation.ts
376
- /**
377
- * The status of one Conversation's own work. See `TERMINOLOGY.md` and
378
- * `conversationStatusSql`, the only place that derives it.
379
- */
380
- const conversationReportStatusSchema = z.enum([
381
- "needs_input",
382
- "working",
383
- "done"
384
- ]);
385
- /** Where a Conversation sits in its tree. See `TERMINOLOGY.md`. */
386
- const conversationKindSchema = z.enum([
387
- "root",
388
- "automation",
389
- "thread",
390
- "task"
391
- ]);
392
- const conversationSurfaceSchema = z.enum([
393
- "api",
394
- "internal",
395
- "scheduler",
396
- "slack"
397
- ]);
398
- const conversationUsageSchema = usageSchema;
399
- const conversationParamsSchema = z.object({ conversationId: z.string().min(1) }).strict();
400
- const conversationAttachmentParamsSchema = z.object({
401
- attachmentId: z.string().min(1),
402
- conversationId: z.string().min(1)
403
- }).strict();
404
- const conversationAttachmentQuerySchema = z.object({
405
- /**
406
- * Send `Content-Disposition: attachment` even for a type that previews
407
- * inline, so a same-window download link saves the file.
408
- */
409
- download: z.stringbool().optional() }).strict();
410
- const conversationDetailQuerySchema = z.object({
411
- /** Omit to get the latest three Turns, up to the default page limit. */
412
- limit: z.coerce.number().int().min(1).max(1e3).optional(),
413
- /** Also return `unreadPage` when the detail has an `unreadCursor`. */
414
- unreadPage: z.stringbool().optional(),
415
- /**
416
- * Also return `mailbox`, read before history. A sent version that still
417
- * matches gets `{ unchanged: true, mailbox }` instead of 304, so a poll
418
- * needs one request.
419
- */
420
- mailbox: z.stringbool().optional(),
421
- /**
422
- * An `appendCursor` from an earlier detail. Events then hold only newer
423
- * events, with `appended: true`, while the cursor still applies.
424
- */
425
- after: z.string().min(1).optional()
426
- }).strict();
427
- const conversationEventsLimitSchema = z.coerce.number().int().min(1).max(1e3).default(150);
428
- /**
429
- * Page toward the start with `before`, toward the latest with `after`, or
430
- * both ways from one event with `around`. A link target asks for the page
431
- * around one event by its `event` seq, around one `message` by its id, or
432
- * around the start of a `turn`.
433
- */
434
- const conversationEventsQuerySchema = z.union([
435
- z.object({
436
- before: z.string().min(1),
437
- limit: conversationEventsLimitSchema
438
- }).strict(),
439
- z.object({
440
- after: z.string().min(1),
441
- limit: conversationEventsLimitSchema
442
- }).strict(),
443
- z.object({
444
- around: z.string().min(1),
445
- limit: conversationEventsLimitSchema
446
- }).strict(),
447
- z.object({
448
- event: z.coerce.number().int().min(0),
449
- limit: conversationEventsLimitSchema
450
- }).strict(),
451
- z.object({
452
- turn: z.string().min(1),
453
- limit: conversationEventsLimitSchema
454
- }).strict(),
455
- z.object({
456
- message: z.string().min(1),
457
- limit: conversationEventsLimitSchema
458
- }).strict()
459
- ]);
460
- /** Client key that makes a retried send the same Message. */
461
- const idempotencyKeySchema = z.string().trim().min(1).max(200);
462
- const createConversationMessageBodySchema = z.object({
463
- idempotencyKey: idempotencyKeySchema,
464
- message: z.string().trim().max(32e3),
465
- /** Uploads from `POST /api/conversations/attachment-uploads`. */
466
- uploadIds: z.array(z.string().min(1).max(64)).max(10).optional()
467
- }).strict().refine((body) => Boolean(body.message || body.uploadIds?.length), "Add a message or a file.");
468
- const createConversationBodySchema = createConversationMessageBodySchema.safeExtend({
469
- /** Saved title. Title generation runs only when it is omitted. */
470
- title: conversationTitleSchema.optional(),
471
- /** New roots default public. Private roots stay participant-only. */
472
- visibility: z.enum(["private", "public"]).optional()
473
- });
474
- const acceptedConversationMessageSchema = z.object({
475
- conversationId: z.string().min(1),
476
- messageId: z.string().min(1),
477
- status: z.enum(["accepted", "duplicate"])
478
- }).strict();
479
- const actorIdentitySchema = z.object({
480
- /**
481
- * Junior API path of the profile photo: the person's Slack photo, then
482
- * their Google photo.
483
- */
484
- avatarUrl: z.string().optional(),
485
- email: z.string().optional(),
486
- fullName: z.string().optional(),
487
- slackUserId: z.string().optional(),
488
- slackUserName: z.string().optional()
489
- }).strict();
490
- const conversationAuxiliaryCostsSchema = z.object({
491
- costUsd: z.number().finite().nonnegative(),
492
- operations: z.array(z.object({
493
- costUsd: z.number().finite().nonnegative(),
494
- events: z.number().int().positive(),
495
- name: z.string().min(1),
496
- namespace: z.string().min(1)
497
- }).strict()).min(1)
498
- }).strict();
499
- /** Optional reverse link from a task-triggered conversation back to its task. */
500
- const conversationSourceTaskSchema = z.object({
501
- id: z.string().min(1).optional(),
502
- kind: z.enum(["scheduled", "event"]),
503
- label: z.string().min(1).optional(),
504
- title: z.string().min(1).optional(),
505
- /** Message id of the run's trigger input, which is not from a person. */
506
- triggerMessageId: z.string().min(1).optional(),
507
- /** Short trigger text, such as an event or a schedule. */
508
- triggerLabel: z.string().min(1).optional(),
509
- /** Credential mode this run used. Unset when the run record is gone. */
510
- credentialMode: z.enum(["creator", "system"]).optional(),
511
- /** Name of the creator whose credentials this run used. */
512
- credentialUser: z.string().min(1).optional()
513
- }).strict().superRefine((value, context) => {
514
- if (Boolean(value.id) !== Boolean(value.label)) context.addIssue({
515
- code: "custom",
516
- message: "sourceTask id and label must both be set or both omitted"
517
- });
518
- });
519
- const conversationAnnotationReportSchema = conversationAnnotationInputSchema.and(z.object({
520
- plugin: z.string().min(1),
521
- createdAt: z.string().datetime(),
522
- updatedAt: z.string().datetime(),
523
- previewImages: z.array(objectPreviewImageSchema).optional()
524
- }));
525
- const conversationActivityPreviewSchema = z.object({
526
- createdAt: z.string().datetime(),
527
- mentions: z.array(actorIdentitySchema).optional(),
528
- role: z.enum(["assistant", "user"]),
529
- text: z.string().min(1).max(400)
530
- }).strict();
531
- const conversationSummaryReportSchema = z.object({
532
- displayTitle: z.string(),
533
- activityPreview: conversationActivityPreviewSchema.optional(),
534
- cumulativeDurationMs: z.number(),
535
- cumulativeUsage: conversationUsageSchema.optional(),
536
- auxiliaryCosts: conversationAuxiliaryCostsSchema.optional(),
537
- childAgentTotals: conversationChildAgentTotalsSchema.optional(),
538
- conversationId: z.string(),
539
- kind: conversationKindSchema,
540
- /** Present on Threads and Tasks. */
541
- parentConversationId: z.string().min(1).optional(),
542
- isParticipant: z.boolean(),
543
- visibility: z.enum(["private", "public"]).optional(),
544
- status: conversationReportStatusSchema,
545
- /** Feed rows and the detail only. */
546
- treeState: conversationTreeStateSchema.optional(),
547
- /**
548
- * A Conversation in the tree has an active Watch or a pending Timer.
549
- * Feed rows and the detail only.
550
- */
551
- watching: z.boolean().optional(),
552
- /**
553
- * A Turn is queued or running. Live views poll and show thinking on it,
554
- * since `status` can read `needs_input` while a Turn runs.
555
- */
556
- turnActive: z.boolean(),
557
- startedAt: z.string(),
558
- lastSeenAt: z.string(),
559
- lastProgressAt: z.string(),
560
- lastMessageAt: z.string().datetime().optional(),
561
- surface: conversationSurfaceSchema,
562
- actorIdentity: actorIdentitySchema.optional(),
563
- participants: z.array(actorIdentitySchema).optional(),
564
- /**
565
- * When this Conversation was archived for everyone, or null. It shows
566
- * only while it and every ancestor are unarchived.
567
- */
568
- archivedAt: z.string().datetime().nullable().optional(),
569
- pinnedAt: z.string().datetime().nullable().optional(),
570
- /** The viewer's place in Pinned. Unset until they reorder their pins. */
571
- pinPosition: z.number().int().optional(),
572
- channel: z.string().optional(),
573
- channelName: z.string().optional(),
574
- channelNameRedacted: z.boolean().optional(),
575
- locationId: z.string().optional(),
576
- sentryTraceUrl: z.string().optional(),
577
- locationUrl: z.string().url().optional(),
578
- traceId: z.string().optional(),
579
- /**
580
- * Plugin-owned resource links for this conversation.
581
- * Present on the conversation feed when the viewer can see private content.
582
- * Clients must not fetch provider state while rendering these links.
583
- */
584
- annotations: z.array(conversationAnnotationReportSchema).optional(),
585
- /** Plugin-selected annotations for the compact conversation row. */
586
- sidebarAnnotations: z.array(conversationSidebarAnnotationSchema).optional(),
587
- assignedWork: z.boolean().optional(),
588
- finishedWorkAt: z.string().datetime().optional(),
589
- /**
590
- * Dashboard Priority membership for this conversation summary.
591
- * Present on the conversation feed. Clients must not recompute it.
592
- *
593
- * True only when:
594
- * - unfinished work was last seen within 48 hours
595
- * - finished assigned work has conversation activity after the finish time
596
- * - there is no known work and the conversation was last seen within 3 hours
597
- */
598
- isPriority: z.boolean().optional(),
599
- unfinishedWork: z.boolean().optional(),
600
- /**
601
- * True on the conversation feed when a Turn in the conversation or a
602
- * child waits on a person to finish an authorization that has not
603
- * expired.
604
- */
605
- awaitingAuthorization: z.boolean().optional()
606
- }).strict();
607
- /** One Event listed on a message that holds several Events. */
608
- const conversationReportMessageEventSchema = z.object({
609
- eventType: z.string().min(1),
610
- label: z.string().min(1).optional(),
611
- objectType: objectTypeSchema.optional(),
612
- trustedSummary: z.string().min(1).optional()
613
- }).strict();
614
- const conversationReportMessageEventDataSchema = z.object({
615
- type: z.literal("message"),
616
- messageId: z.string().min(1),
617
- role: z.enum([
618
- "assistant",
619
- "system",
620
- "user"
621
- ]),
622
- source: z.enum(["slack", "web"]).optional(),
623
- actorIdentity: actorIdentitySchema.optional(),
624
- /** Identity id of the author. Detail `authors` maps it to the person. */
625
- actorIdentityId: z.string().min(1).optional(),
626
- /** Agent invocation whose input this is. An agent wrote it, not a person. */
627
- agentInvocationId: z.string().min(1).optional(),
628
- eventType: z.string().min(1).optional(),
629
- /** Namespace of the first Event, such as `github`. */
630
- eventNamespace: z.string().min(1).optional(),
631
- eventObjectType: objectTypeSchema.optional(),
632
- explicitMention: z.boolean().optional(),
633
- quiet: z.literal(true).optional(),
634
- trustedSummary: z.string().min(1).optional(),
635
- /**
636
- * The Watch Events when several arrived together. A message that also
637
- * records Review item changes lists its own Event here even when it has
638
- * one.
639
- */
640
- events: z.array(conversationReportMessageEventSchema).optional(),
641
- cards: z.array(messageCardRefSchema).optional(),
642
- /** Person changes to Review items that this message records. */
643
- reviewItemChanges: z.array(reviewItemChangeRecordSchema).min(1).optional(),
644
- text: z.string().optional(),
645
- attachments: z.array(messageAttachmentSchema).optional(),
646
- redacted: z.literal(true).optional()
647
- }).strict().superRefine((data, context) => {
648
- if (data.text === void 0 === (data.redacted !== true)) context.addIssue({
649
- code: "custom",
650
- message: "message content must be text or explicitly redacted"
651
- });
652
- if (data.redacted && (data.actorIdentity || data.cards || data.attachments || data.events || data.reviewItemChanges)) context.addIssue({
653
- code: "custom",
654
- message: "redacted messages must not expose actor identity, cards, attachments, events, or review item changes"
655
- });
656
- });
657
- const conversationReportMessageHandledEventDataSchema = z.object({
658
- type: z.literal("message_handled"),
659
- messageId: z.string().min(1)
660
- }).strict();
661
- const conversationReportToolCallSchema = z.object({
662
- toolCallId: z.string().min(1),
663
- name: z.string().min(1),
664
- status: z.enum([
665
- "running",
666
- "completed",
667
- "error"
668
- ]),
669
- startedAt: z.string().datetime().optional(),
670
- startedSeq: z.number().int().nonnegative().optional(),
671
- input: z.unknown().optional(),
672
- output: z.unknown().optional()
673
- }).strict().superRefine((call, context) => {
674
- if (call.startedAt === void 0 !== (call.startedSeq === void 0)) context.addIssue({
675
- code: "custom",
676
- message: "tool start sequence and timestamp must be provided together"
677
- });
678
- });
679
- const conversationReportReasoningPartSchema = z.object({
680
- type: z.literal("reasoning"),
681
- text: z.string().min(1).optional(),
682
- redacted: z.literal(true).optional()
683
- }).strict().superRefine((data, context) => {
684
- if (data.text === void 0 === (data.redacted !== true)) context.addIssue({
685
- code: "custom",
686
- message: "reasoning content must be text or explicitly redacted"
687
- });
688
- });
689
- const conversationReportAssistantToolCallPartSchema = z.object({
690
- type: z.literal("tool_call"),
691
- toolCallId: z.string().min(1)
692
- }).strict();
693
- const conversationReportAssistantMetadataSchema = z.object({ parts: z.array(z.discriminatedUnion("type", [conversationReportReasoningPartSchema, conversationReportAssistantToolCallPartSchema])).min(1) }).strict();
694
- const conversationReportToolCallsEventDataSchema = z.object({
695
- type: z.literal("tool_calls"),
696
- calls: z.array(conversationReportToolCallSchema).min(1),
697
- assistant: conversationReportAssistantMetadataSchema.optional()
698
- }).strict().superRefine((data, context) => {
699
- if (!data.assistant) return;
700
- const callCounts = /* @__PURE__ */ new Map();
701
- for (const call of data.calls) callCounts.set(call.toolCallId, (callCounts.get(call.toolCallId) ?? 0) + 1);
702
- const partCounts = /* @__PURE__ */ new Map();
703
- for (const part of data.assistant.parts) {
704
- if (part.type !== "tool_call") continue;
705
- partCounts.set(part.toolCallId, (partCounts.get(part.toolCallId) ?? 0) + 1);
706
- }
707
- if (callCounts.size !== partCounts.size || [...callCounts].some(([toolCallId, count]) => partCounts.get(toolCallId) !== count)) context.addIssue({
708
- code: "custom",
709
- path: ["assistant", "parts"],
710
- message: "assistant tool parts must reference every call exactly once"
711
- });
712
- });
713
- const conversationReportAssistantMessageEventDataSchema = z.object({
714
- type: z.literal("assistant_message"),
715
- parts: z.array(conversationReportReasoningPartSchema)
716
- }).strict();
717
- const conversationReportTurnLifecycleEventDataSchema = z.discriminatedUnion("state", [
718
- z.object({
719
- type: z.literal("turn_lifecycle"),
720
- turnId: z.string().min(1),
721
- state: z.enum([
722
- "succeeded",
723
- "no_reply",
724
- "blocked"
725
- ])
726
- }).strict(),
727
- z.object({
728
- type: z.literal("turn_lifecycle"),
729
- turnId: z.string().min(1),
730
- state: z.literal("started"),
731
- inputMessageIds: z.array(z.string().min(1)).min(1).optional()
732
- }).strict(),
733
- z.object({
734
- type: z.literal("turn_lifecycle"),
735
- turnId: z.string().min(1),
736
- state: z.literal("failed"),
737
- failureCode: conversationTurnFailureCodeSchema,
738
- failureReason: conversationTurnFailureReasonSchema.optional(),
739
- eventId: z.string().regex(/^[a-f0-9]{32}$/i).optional(),
740
- sentryEventUrl: z.string().url().optional()
741
- }).strict()
742
- ]);
743
- const conversationReportGuardianActionReviewedEventDataSchema = z.object({
744
- type: z.literal("guardian_action_reviewed"),
745
- turnId: z.string().min(1),
746
- toolCallId: z.string().min(1),
747
- toolName: z.string().min(1),
748
- decision: z.enum([
749
- "allow",
750
- "ask",
751
- "deny"
752
- ]),
753
- riskLevel: z.enum([
754
- "low",
755
- "medium",
756
- "high",
757
- "critical"
758
- ]),
759
- userAuthorization: z.enum([
760
- "high",
761
- "medium",
762
- "low",
763
- "unknown"
764
- ])
765
- }).strict();
766
- const conversationReportTurnContextEventDataSchema = z.object({
767
- type: z.literal("turn_context"),
768
- turnId: z.string().min(1),
769
- pluginName: z.string().min(1),
770
- kind: z.string().min(1),
771
- version: z.number().int().positive(),
772
- content: z.record(z.string(), z.unknown())
773
- }).strict();
774
- const conversationReportStructuredEventDataSchema = z.object({
775
- type: z.literal("structured_event"),
776
- namespace: z.string().min(1),
777
- name: z.string().min(1),
778
- version: z.number().int().positive(),
779
- turnId: z.string().min(1).optional(),
780
- presentation: conversationEventPresentationSchema
781
- }).strict();
782
- const conversationReportAttachmentsDeliveredEventDataSchema = z.object({
783
- type: z.literal("attachments_delivered"),
784
- attachments: z.array(messageAttachmentSchema).min(1)
785
- }).strict();
786
- /** Junior text that a plugin tool posted to its provider. */
787
- const conversationReportReplyPostedEventDataSchema = z.object({
788
- type: z.literal("reply_posted"),
789
- plugin: z.string().min(1),
790
- text: z.string().min(1),
791
- url: z.string().url().optional()
792
- }).strict();
793
- const conversationReportCompactionEventDataSchema = z.object({
794
- type: z.literal("compaction"),
795
- modelId: z.string().min(1).optional(),
796
- summary: z.string().min(1).optional(),
797
- details: z.object({
798
- reason: z.literal("capacity"),
799
- estimatedInputTokens: z.number().int().nonnegative(),
800
- replacementInputTokens: z.number().int().nonnegative().optional(),
801
- triggerTokens: z.number().int().nonnegative(),
802
- inputLimitTokens: z.number().int().positive(),
803
- inputMessageCount: z.number().int().nonnegative(),
804
- retainedMessageCount: z.number().int().nonnegative(),
805
- summaryChars: z.number().int().nonnegative()
806
- }).strict().optional()
807
- }).strict();
808
- const conversationReportSubagentEventDataSchema = z.object({
809
- type: z.literal("subagent"),
810
- startedSeq: z.number().int().nonnegative(),
811
- startedAt: z.string().datetime(),
812
- childConversationId: z.string().min(1),
813
- /** The child's Conversation kind. Only a Thread has its own page link. */
814
- childKind: z.enum(["thread", "task"]),
815
- subagentKind: z.string().min(1),
816
- agentName: z.string().min(1).optional(),
817
- task: z.string().min(1).optional(),
818
- title: z.string().min(1).optional(),
819
- parentToolCallId: z.string().min(1).optional(),
820
- status: z.enum([
821
- "running",
822
- "completed",
823
- "blocked",
824
- "error",
825
- "aborted"
826
- ])
827
- }).strict();
828
- /** Privacy-safe event variants owned by the conversation reporting API. */
829
- const conversationReportEventDataSchema = z.discriminatedUnion("type", [
830
- conversationReportMessageEventDataSchema,
831
- conversationReportMessageHandledEventDataSchema,
832
- conversationReportAssistantMessageEventDataSchema,
833
- conversationReportToolCallsEventDataSchema,
834
- conversationReportTurnLifecycleEventDataSchema,
835
- conversationReportTurnContextEventDataSchema,
836
- conversationReportStructuredEventDataSchema,
837
- conversationReportAttachmentsDeliveredEventDataSchema,
838
- conversationReportReplyPostedEventDataSchema,
839
- conversationReportGuardianActionReviewedEventDataSchema,
840
- conversationReportCompactionEventDataSchema,
841
- conversationReportSubagentEventDataSchema
842
- ]);
843
- /** One ordered, privacy-safe canonical event projected for API consumers. */
844
- const conversationReportEventSchema = z.object({
845
- seq: z.number().int().nonnegative(),
846
- createdAt: z.string().datetime(),
847
- data: conversationReportEventDataSchema,
848
- /** People mentioned in the event text, resolved at read time. */
849
- mentions: z.array(actorIdentitySchema).optional(),
850
- model: z.object({ modelId: z.string().min(1) }).strict().optional(),
851
- modelCall: z.object({
852
- provider: z.string().min(1).optional(),
853
- api: z.string().min(1).optional(),
854
- stopReason: z.string().min(1).optional(),
855
- usage: conversationUsageSchema.optional()
856
- }).strict().optional()
857
- }).strict();
858
- /** Availability of the canonical event history attached to a detail report. */
859
- const conversationEventHistorySchema = z.discriminatedUnion("status", [
860
- z.object({ status: z.literal("available") }).strict(),
861
- z.object({
862
- status: z.literal("redacted"),
863
- reason: z.literal("non_public_conversation")
864
- }).strict(),
865
- z.object({
866
- status: z.literal("expired"),
867
- expiredAt: z.string().datetime()
868
- }).strict()
869
- ]);
870
- const conversationModelUsageSchema = z.object({
871
- modelId: z.string(),
872
- usage: conversationUsageSchema
873
- }).strict();
874
- /** Enforce event ordering and history visibility across paginated wire payloads. */
875
- function validateConversationEvents(report, context) {
876
- if (report.eventHistory.status === "expired" && report.events.length > 0) context.addIssue({
877
- code: "custom",
878
- path: ["events"],
879
- message: "expired event history must not contain events"
880
- });
881
- for (let index = 1; index < report.events.length; index += 1) if (report.events[index].seq <= report.events[index - 1].seq) context.addIssue({
882
- code: "custom",
883
- path: [
884
- "events",
885
- index,
886
- "seq"
887
- ],
888
- message: "report event sequences must be strictly increasing"
889
- });
890
- for (const [index, event] of report.events.entries()) {
891
- if (event.data.type === "message") {
892
- if (report.eventHistory.status === "redacted" && event.data.redacted !== true) context.addIssue({
893
- code: "custom",
894
- path: [
895
- "events",
896
- index,
897
- "data"
898
- ],
899
- message: "redacted event history must redact messages"
900
- });
901
- if (report.eventHistory.status === "available" && event.data.redacted === true) context.addIssue({
902
- code: "custom",
903
- path: [
904
- "events",
905
- index,
906
- "data"
907
- ],
908
- message: "available event history must expose messages"
909
- });
910
- }
911
- if (report.eventHistory.status === "redacted" && event.data.type === "tool_calls" && event.data.calls.some((call) => call.input !== void 0 || call.output !== void 0)) context.addIssue({
912
- code: "custom",
913
- path: [
914
- "events",
915
- index,
916
- "data"
917
- ],
918
- message: "redacted event history must redact tool payloads"
919
- });
920
- if (report.eventHistory.status === "redacted" && event.data.type === "assistant_message" && event.data.parts.some((part) => part.text !== void 0)) context.addIssue({
921
- code: "custom",
922
- path: [
923
- "events",
924
- index,
925
- "data"
926
- ],
927
- message: "redacted event history must redact assistant messages"
928
- });
929
- if (report.eventHistory.status === "available" && event.data.type === "assistant_message" && event.data.parts.some((part) => part.redacted === true)) context.addIssue({
930
- code: "custom",
931
- path: [
932
- "events",
933
- index,
934
- "data"
935
- ],
936
- message: "available event history must expose reasoning"
937
- });
938
- if (event.data.type === "tool_calls" && (report.eventHistory.status === "redacted" && event.data.assistant?.parts.some((part) => part.type === "reasoning" && part.text !== void 0) || report.eventHistory.status === "available" && event.data.assistant?.parts.some((part) => part.type === "reasoning" && part.redacted === true))) context.addIssue({
939
- code: "custom",
940
- path: [
941
- "events",
942
- index,
943
- "data",
944
- "assistant"
945
- ],
946
- message: "assistant reasoning must match event history visibility"
947
- });
948
- }
949
- }
950
- const forkConversationBodySchema = z.object({
951
- /** Assistant reply that ends the copied history. */
952
- messageId: z.string().min(1).max(500),
953
- idempotencyKey: z.string().trim().min(1).max(200),
954
- /** Start a hidden, read-only Quick question about this reply text. */
955
- quickQuestion: z.object({ quote: z.string().trim().min(1).max(4e3) }).strict().optional()
956
- }).strict();
957
- const forkConversationResponseSchema = z.object({ conversationId: z.string() }).strict();
958
- /** One Conversation in the agent tree of a child Conversation. */
959
- const conversationAgentTreeNodeSchema = z.object({
960
- conversationId: z.string().min(1),
961
- kind: conversationKindSchema,
962
- label: z.string().min(1),
963
- /**
964
- * Agent type of a child, such as `explore`. Absent for a root, a child
965
- * without a type, or a viewer who cannot see private content.
966
- */
967
- agentType: agentTypeSchema.optional(),
968
- /**
969
- * The child started with its parent's history. Absent like `agentType`,
970
- * or when the child started fresh.
971
- */
972
- fork: z.literal(true).optional()
973
- }).strict();
974
- const conversationEventPageSchema = z.object({
975
- events: z.array(conversationReportEventSchema),
976
- eventHistory: conversationEventHistorySchema,
977
- previousCursor: z.string().min(1).optional(),
978
- /** Present on `after` and `around` pages when newer events follow. */
979
- nextCursor: z.string().min(1).optional(),
980
- generatedAt: z.string()
981
- }).strict().superRefine(validateConversationEvents);
982
- /**
983
- * Carries the detail version token in both directions. A custom header, not
984
- * `ETag`, for the reason on `CONTENT_VERSION_HEADER`.
985
- */
986
- const CONVERSATION_DETAIL_VERSION_HEADER = "x-junior-detail-version";
987
- /**
988
- * Carries the change token of the Conversation tree that a detail report was
989
- * built from. The dashboard compares it with the token of `GET /api/versions`
990
- * and asks for the report only when they differ.
991
- */
992
- const CONVERSATION_VERSION_HEADER = "x-junior-conversation-version";
993
- const conversationDetailReportSchema = conversationSummaryReportSchema.extend({
994
- /**
995
- * The parent chain of a child Conversation, root first, with this
996
- * Conversation last. Root Conversations omit it.
997
- */
998
- agentTree: z.array(conversationAgentTreeNodeSchema).min(2).optional(),
999
- /** The viewer's effective auto-archive choice. Participants only. */
1000
- autoArchive: z.boolean().optional(),
1001
- /** The viewer can fork this conversation from an assistant reply. */
1002
- canFork: z.boolean().optional(),
1003
- /** The viewer can move this dashboard conversation to a Slack thread. */
1004
- canContinueInSlack: z.literal(true).optional(),
1005
- /**
1006
- * Event Turn replies stay out of the Location. Set only for a root with
1007
- * a Location, when the viewer is a participant, who can change it.
1008
- */
1009
- deliveryPaused: z.boolean().optional(),
1010
- /**
1011
- * The viewer gets this conversation in their active feed. Participants
1012
- * only. False after an unsubscribe, until they mention Junior again.
1013
- */
1014
- subscribed: z.boolean().optional(),
1015
- /** How far the signed-in viewer has read. Absent until they read. */
1016
- readPosition: conversationReadPositionSchema.optional(),
1017
- /**
1018
- * Pass as `after` to the events API to read from the read position.
1019
- * Present only when unread events start before `events`.
1020
- */
1021
- unreadCursor: z.string().min(1).optional(),
1022
- /**
1023
- * The `around` page of `unreadCursor`, when the request asks for it. A
1024
- * reader who opens at the read position needs no second request.
1025
- */
1026
- unreadPage: conversationEventPageSchema.optional(),
1027
- forkedFromConversationId: z.string().optional(),
1028
- /** Title of the fork source, when the viewer can open it. */
1029
- forkedFromTitle: z.string().optional(),
1030
- forks: z.array(z.string()).optional(),
1031
- brief: z.object({
1032
- content: conversationBriefSchema,
1033
- /** People mentioned in the Brief text, resolved at read time. */
1034
- mentions: z.array(actorIdentitySchema).optional(),
1035
- updatedAt: z.string().datetime(),
1036
- version: z.number().int().positive()
1037
- }).strict().optional(),
1038
- modelUsage: z.array(conversationModelUsageSchema).optional(),
1039
- /**
1040
- * Each person who wrote in the Conversation, by each of their Identity
1041
- * ids. Messages and pending messages name their author with
1042
- * `actorIdentityId`.
1043
- */
1044
- authors: z.record(z.string(), actorIdentitySchema).optional(),
1045
- events: z.array(conversationReportEventSchema),
1046
- /**
1047
- * Events hold only the events after the request's `after` cursor. The
1048
- * report omits `previousCursor` and `unreadCursor`: the reader keeps its
1049
- * own.
1050
- */
1051
- appended: z.literal(true).optional(),
1052
- /**
1053
- * Pass as `after` on the next detail read to get only newer events.
1054
- * Absent after a purge.
1055
- */
1056
- appendCursor: z.string().min(1).optional(),
1057
- eventHistory: conversationEventHistorySchema,
1058
- previousCursor: z.string().min(1).optional(),
1059
- generatedAt: z.string(),
1060
- sentryConversationUrl: z.string().optional(),
1061
- sourceTask: conversationSourceTaskSchema.optional()
1062
- }).strict().superRefine(validateConversationEvents);
1063
- export { MAX_ATTACHMENT_BYTES as $, agentTypeInstructions as A, conversationTreeStateSchema as B, createConversationMessageBodySchema as C, activityPreviewText as D, idempotencyKeySchema as E, briefOutcomeStatusSchema as F, conversationReadPositionSchema as G, conversationTitleSchema as H, briefResourceLabel as I, messageCardRef as J, reviewItemChangeRecordSchema as K, conversationBriefSchema as L, formatAgentTypes as M, briefCodeChangeSchema as N, conversationChildAgentTotalsSchema as O, briefLinkSchema as P, resolveMessageCards as Q, parseBriefInput as R, createConversationBodySchema as S, forkConversationResponseSchema as T, renameConversationBodySchema as U, CONVERSATION_TITLE_MAX_LENGTH as V, renameConversationResponseSchema as W, readMessageCardRefs as X, messageCardText as Y, removedCardSchema as Z, conversationReportMessageEventSchema as _, conversationActivityPreviewSchema as a, conversationSurfaceSchema as b, conversationAuxiliaryCostsSchema as c, conversationEventHistorySchema as d, MAX_INPUT_ATTACHMENTS as et, conversationEventPageSchema as f, conversationReportEventSchema as g, conversationReportEventDataSchema as h, actorIdentitySchema as i, agentTypeSchema as j, AGENT_TYPES as k, conversationDetailQuerySchema as l, conversationParamsSchema as m, CONVERSATION_VERSION_HEADER as n, messageAttachmentSchema as nt, conversationAttachmentParamsSchema as o, conversationEventsQuerySchema as p, annotationCard as q, acceptedConversationMessageSchema as r, readMessageAttachments as rt, conversationAttachmentQuerySchema as s, CONVERSATION_DETAIL_VERSION_HEADER as t, inputFileSchema as tt, conversationDetailReportSchema as u, conversationReportStatusSchema as v, forkConversationBodySchema as w, conversationUsageSchema as x, conversationSummaryReportSchema as y, parseStoredBrief as z };