@sentry/junior 0.310.0 → 0.312.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 (157) hide show
  1. package/dist/{adapter-context-BhKpjpGD.js → adapter-context-BRjEWRy1.js} +2 -2
  2. package/dist/adapter-iIq7ihf7.js +259 -0
  3. package/dist/{admin-tgZEZAk2.js → admin-DhInw5K9.js} +1 -2
  4. package/dist/{agent-runner-D9cvNlQl.js → agent-runner-C9iDurwX.js} +6507 -7721
  5. package/dist/api/schema.d.ts +2 -2
  6. package/dist/api/schema.js +7 -6
  7. package/dist/api.d.ts +21 -3
  8. package/dist/api.js +1625 -535
  9. package/dist/{app-B_7Wn0en.d.ts → app-DRFrC8Mw.d.ts} +14 -10
  10. package/dist/app.d.ts +2 -2
  11. package/dist/app.js +454 -994
  12. package/dist/{background-compaction-queue-BGHqkhkY.js → background-compaction-queue-DrKi7w3d.js} +10 -85
  13. package/dist/callback-mFlTUWWx.js +75 -0
  14. package/dist/{catalog-runtime-BxwzbLKY.js → catalog-runtime-D7xapBAX.js} +1 -1
  15. package/dist/channel-access-CJGfNTdn.js +221 -0
  16. package/dist/child-message-DcsritGf.js +179 -0
  17. package/dist/cli/chat.js +18 -19
  18. package/dist/cli/check.js +23 -29
  19. package/dist/cli/init.js +1 -7
  20. package/dist/cli/main.js +3 -7
  21. package/dist/cli/plugins.js +8 -7
  22. package/dist/cli/run.d.ts +1 -2
  23. package/dist/cli/run.js +1 -2
  24. package/dist/cli/snapshot-create.js +5 -5
  25. package/dist/cli/upgrade.d.ts +1 -1
  26. package/dist/cli/upgrade.js +3 -3
  27. package/dist/{config-Dkt2Le2b.js → config-kXB2Y5tl.js} +294 -28
  28. package/dist/{continue-in-slack-BWVwePKD.js → continue-in-slack-O6pV5004.js} +7 -7
  29. package/dist/{conversation-feed-Ci6YD1N-.js → conversation-feed-uNOv_x68.js} +87 -24
  30. package/dist/{conversation-privacy-C39g8BY4.js → conversation-privacy-L4ja1_W6.js} +1 -1
  31. package/dist/{conversation-turn-CBlZIH02.js → conversation-turn-CeLbHqdw.js} +56 -49
  32. package/dist/{credential-sync-vGnrB0BY.js → credential-sync-I8VBGk05.js} +16 -16
  33. package/dist/{projection-jZSlEAXG.js → credentialed-Cb6E2phL.js} +16268 -16821
  34. package/dist/{db-B4Hjxr-u.d.ts → db-BbC5stfa.d.ts} +13 -6
  35. package/dist/{db-CFZggNoy.js → db-LAyyX8tk.js} +1698 -1046
  36. package/dist/{executor-BPkZDx5-.js → executor-SCub-fAq.js} +552 -181
  37. package/dist/{html-2r2KmLwi.js → html-BCZ3Xtb_.js} +6 -6
  38. package/dist/{session-stop-BfY4rhJs.js → ingest-BDf3D50j.js} +2134 -2553
  39. package/dist/{install-C-oE6C_u.js → install-DCFJFkC0.js} +2 -2
  40. package/dist/instrumentation.js +4 -4
  41. package/dist/{lineage-CsvrEFQe.js → lineage-B_m-4TJw.js} +2 -2
  42. package/dist/{stop-DYzjRf2U.js → list-CN2QA2R9.js} +1656 -685
  43. package/dist/{logging-D5gkyvnK.js → logging-dQ9ZRGQ8.js} +47 -9
  44. package/dist/media-CYm1QD8T.js +2356 -0
  45. package/dist/{message-DwvJ-I3w.js → message-DSXGj1hM.js} +19 -29
  46. package/dist/{model-input-MAq2881y.js → model-input--TrP9hYV.js} +3 -3
  47. package/dist/nitro.d.ts +1 -1
  48. package/dist/nitro.js +4 -3
  49. package/dist/{oauth-callback-server-DIF6Li06.js → oauth-callback-server-DHCZC6B4.js} +2 -2
  50. package/dist/{oauth-relay-DPE-wrwO.js → oauth-relay-pPMGnDZt.js} +1 -1
  51. package/dist/{registry-BBkWFCl8.js → registry-CZOzddwu.js} +5 -8
  52. package/dist/{resolve-B38MkHXE.js → resolve-cKOQ14Dh.js} +3 -3
  53. package/dist/{result-BaqSZcJb.js → result-DcvEOe1r.js} +119 -93
  54. package/dist/result-event-type-BdIJuZxg.js +48 -0
  55. package/dist/rule-DAxQY-1h.js +20 -0
  56. package/dist/{runner-11h8PrHh.js → runner-DBfUW44l.js} +14 -16
  57. package/dist/{sandbox-egress-signals-CTcACAtJ.js → sandbox-egress-signals-BVF_xAm1.js} +1 -1
  58. package/dist/{schema-DriSvB40.d.ts → schema-BEHKxr4I.d.ts} +861 -298
  59. package/dist/{schema-obw5jvR4.js → schema-Bk9Nm2E8.js} +344 -153
  60. package/dist/{service-account-Bx93N1n1.js → service-account-CVYsFjty.js} +3 -3
  61. package/dist/{service-account-Zc5bUcIJ.js → service-account-Ts4ulcrV.js} +68 -68
  62. package/dist/{skills-C8Npu5zO.js → skills-VTnhAJWm.js} +2 -2
  63. package/dist/{slack-conversation-unfurl-DlRVA02H.js → slack-conversation-unfurl-fuLnF1jE.js} +9 -11
  64. package/dist/{spawn-CXr58R0x.js → spawn-vxAarlX5.js} +6 -6
  65. package/dist/start-conversation-CEn2KH1A.js +941 -0
  66. package/dist/{state-CGrGVeQC.js → state-C1P3_Ywk.js} +4 -4
  67. package/dist/statuses-_cRJHXK7.js +150 -0
  68. package/dist/store-DFZaN-Ix.js +492 -0
  69. package/dist/task-queue-Cx4Lmjyk.js +90 -0
  70. package/dist/task-runner-CbTwFA6k.js +1432 -0
  71. package/dist/{thread-context-Dyj1KWaY.js → thread-context-BkAZDTX2.js} +13 -11
  72. package/dist/thread-state-DhPndWi1.js +5625 -0
  73. package/dist/{validation-DxVNIxA0.js → validation-nIzMtAVJ.js} +1 -1
  74. package/dist/{task-queue-CaZffYaH.js → vercel-queue-hW90XzbG.js} +93 -172
  75. package/dist/{version-Cr7Z71yG.js → version-Brbtz4Qf.js} +1 -1
  76. package/dist/version.js +1 -1
  77. package/dist/{warmup-C6LOZ2d2.js → warmup-BDA5myRK.js} +5832 -4567
  78. package/dist/web-message-id-C6P83ans.js +10 -0
  79. package/dist/{worker-CUBtu1Li.js → worker-D63RcaVD.js} +20 -8
  80. package/migrations/0126_artifact_drop_public.sql +8 -0
  81. package/migrations/0127_artifact_path.sql +4 -0
  82. package/migrations/0128_artifact_path_index.sql +1 -0
  83. package/migrations/0129_review_item_answered_index.sql +1 -0
  84. package/migrations/0130_review_item_status_index.sql +1 -0
  85. package/migrations/0131_brief_outcome_status.sql +1 -0
  86. package/migrations/0132_brief_outcome_status_backfill.sql +7 -0
  87. package/migrations/0133_brief_created_at_index.sql +1 -0
  88. package/migrations/0134_slack_person_search_index.sql +1 -0
  89. package/migrations/0135_code_change_size.sql +3 -0
  90. package/migrations/0136_merge_conflict_notice_dismiss.sql +16 -0
  91. package/migrations/0137_inbox_snoozes.sql +27 -0
  92. package/migrations/0138_code_change_search_index.sql +2 -0
  93. package/migrations/0139_review_item_owner.sql +22 -0
  94. package/migrations/0140_review_item_owner_index.sql +1 -0
  95. package/migrations/0141_memory_core_adoption.sql +89 -0
  96. package/migrations/0142_memory_core_indexes.sql +17 -0
  97. package/migrations/0143_todos.sql +14 -0
  98. package/migrations/0144_inbox_items.sql +32 -0
  99. package/migrations/0145_todo_changed_by_agent.sql +1 -0
  100. package/migrations/0146_inbox_item_subject_title_parts.sql +1 -0
  101. package/migrations/0147_inbox_snooze_wake_reason.sql +1 -0
  102. package/migrations/0148_authorization_request_index.sql +1 -0
  103. package/migrations/0149_conversation_metadata.sql +10 -0
  104. package/migrations/0150_conversation_metadata_fill.sql +39 -0
  105. package/migrations/0151_conversation_search_index.sql +1 -0
  106. package/migrations/0152_inbox_item_legacy_automation_keys.sql +21 -0
  107. package/migrations/0153_artifact_expiry.sql +1 -0
  108. package/migrations/0154_artifact_permanent_sha_index.sql +1 -0
  109. package/migrations/0155_artifact_drop_public_sha_index.sql +3 -0
  110. package/migrations/0156_conversation_kind_lead.sql +6 -0
  111. package/migrations/0157_conversation_lead_actor_index.sql +1 -0
  112. package/migrations/meta/0126_snapshot.json +5488 -0
  113. package/migrations/meta/0127_snapshot.json +5519 -0
  114. package/migrations/meta/0128_snapshot.json +5519 -0
  115. package/migrations/meta/0129_snapshot.json +5547 -0
  116. package/migrations/meta/0130_snapshot.json +5563 -0
  117. package/migrations/meta/0131_snapshot.json +5569 -0
  118. package/migrations/meta/0132_snapshot.json +5569 -0
  119. package/migrations/meta/0133_snapshot.json +5590 -0
  120. package/migrations/meta/0134_snapshot.json +5606 -0
  121. package/migrations/meta/0135_snapshot.json +5624 -0
  122. package/migrations/meta/0136_snapshot.json +5624 -0
  123. package/migrations/meta/0137_snapshot.json +5864 -0
  124. package/migrations/meta/0138_snapshot.json +5894 -0
  125. package/migrations/meta/0139_snapshot.json +5898 -0
  126. package/migrations/meta/0140_snapshot.json +5919 -0
  127. package/migrations/meta/0141_snapshot.json +6429 -0
  128. package/migrations/meta/0142_snapshot.json +6457 -0
  129. package/migrations/meta/0143_snapshot.json +6434 -0
  130. package/migrations/meta/0144_snapshot.json +6434 -0
  131. package/migrations/meta/0145_snapshot.json +6440 -0
  132. package/migrations/meta/0146_snapshot.json +6446 -0
  133. package/migrations/meta/0147_snapshot.json +6452 -0
  134. package/migrations/meta/0148_snapshot.json +6474 -0
  135. package/migrations/meta/0149_snapshot.json +6490 -0
  136. package/migrations/meta/0150_snapshot.json +6490 -0
  137. package/migrations/meta/0151_snapshot.json +6505 -0
  138. package/migrations/meta/0152_snapshot.json +6505 -0
  139. package/migrations/meta/0153_snapshot.json +6511 -0
  140. package/migrations/meta/0154_snapshot.json +6533 -0
  141. package/migrations/meta/0155_snapshot.json +6511 -0
  142. package/migrations/meta/0156_snapshot.json +6511 -0
  143. package/migrations/meta/0157_snapshot.json +6527 -0
  144. package/migrations/meta/_journal.json +224 -0
  145. package/package.json +7 -8
  146. package/skills/design-automation-skill/SKILL.md +108 -0
  147. package/dist/briefs-DKxkoruh.js +0 -395
  148. package/dist/conversation-M9KZ5JxF.js +0 -1024
  149. package/dist/prompt-CaMyeCpA.js +0 -910
  150. package/dist/schedule-DWxZ3kja.js +0 -1146
  151. package/dist/store-D4FQ1Nml.js +0 -335
  152. package/dist/task-runner-Dm7BHbGp.js +0 -287
  153. package/dist/turn-session-routing-CD0BRCex.js +0 -263
  154. package/dist/turn-user-message-9IxeEv5v.js +0 -364
  155. package/dist/users-CaUAYMb3.js +0 -181
  156. package/dist/viewer-AHldghAD.js +0 -212
  157. package/dist/web-message-id-BT8Mg8LL.js +0 -418
@@ -1,418 +0,0 @@
1
- import * as z from "zod";
2
- // src/api/reporting-window.ts
3
- /** Shared UTC day/hour/six-hour windows for dashboard activity series. */
4
- const HOUR_MS = 36e5;
5
- const SIX_HOUR_MS = 6 * HOUR_MS;
6
- const DAY_MS = 24 * HOUR_MS;
7
- /** Start of the UTC calendar day containing `valueMs`. */
8
- function startOfUtcDay(valueMs) {
9
- const date = new Date(valueMs);
10
- date.setUTCHours(0, 0, 0, 0);
11
- return date;
12
- }
13
- /** Start of the UTC hour containing `valueMs`. */
14
- function startOfUtcHour(valueMs) {
15
- const date = new Date(valueMs);
16
- date.setUTCMinutes(0, 0, 0);
17
- return date;
18
- }
19
- /** Start of the UTC 6-hour bucket containing `valueMs` (00/06/12/18). */
20
- function startOfUtcSixHour(valueMs) {
21
- const date = startOfUtcHour(valueMs);
22
- date.setUTCHours(Math.floor(date.getUTCHours() / 6) * 6, 0, 0, 0);
23
- return date;
24
- }
25
- /** UTC day key `YYYY-MM-DD`. */
26
- function utcDayKey(value) {
27
- return (typeof value === "number" ? new Date(value) : value).toISOString().slice(0, 10);
28
- }
29
- /** UTC hour key `YYYY-MM-DDTHH`. */
30
- function utcHourKey(value) {
31
- return (typeof value === "number" ? new Date(value) : value).toISOString().slice(0, 13);
32
- }
33
- /** UTC 6-hour bucket key `YYYY-MM-DDTHH` at 00/06/12/18. */
34
- function utcSixHourKey(value) {
35
- return utcHourKey(startOfUtcSixHour(typeof value === "number" ? value : value.getTime()));
36
- }
37
- /** Inclusive trailing UTC day window ending on today's UTC day. */
38
- function trailingUtcDayWindow(nowMs, dayCount) {
39
- const end = startOfUtcDay(nowMs);
40
- const start = new Date(end);
41
- start.setUTCDate(start.getUTCDate() - (dayCount - 1));
42
- return {
43
- end,
44
- start
45
- };
46
- }
47
- /** Inclusive trailing UTC hour window ending on the current UTC hour. */
48
- function trailingUtcHourWindow(nowMs, hourCount = 24) {
49
- const end = startOfUtcHour(nowMs);
50
- return {
51
- end,
52
- start: /* @__PURE__ */ new Date(end.getTime() - (hourCount - 1) * HOUR_MS)
53
- };
54
- }
55
- /** Inclusive trailing UTC 6-hour window ending on the current 6h bucket. */
56
- function trailingUtcSixHourWindow(nowMs, bucketCount = 28) {
57
- const end = startOfUtcSixHour(nowMs);
58
- return {
59
- end,
60
- start: /* @__PURE__ */ new Date(end.getTime() - (bucketCount - 1) * SIX_HOUR_MS)
61
- };
62
- }
63
- /** Fill a fixed UTC day window from a sparse map. */
64
- function fillUtcDays(args) {
65
- const { end, start } = trailingUtcDayWindow(args.nowMs, args.count);
66
- const items = [];
67
- for (const cursor = new Date(start); cursor.getTime() <= end.getTime(); cursor.setUTCDate(cursor.getUTCDate() + 1)) {
68
- const date = utcDayKey(cursor);
69
- items.push(args.rows.get(date) ?? args.empty(date));
70
- }
71
- return items;
72
- }
73
- /** Fill a fixed UTC hour window from a sparse map. */
74
- function fillUtcHours(args) {
75
- const hourCount = args.count ?? 24;
76
- const { end, start } = trailingUtcHourWindow(args.nowMs, hourCount);
77
- const items = [];
78
- for (const cursor = new Date(start); cursor.getTime() <= end.getTime(); cursor.setTime(cursor.getTime() + HOUR_MS)) {
79
- const date = utcHourKey(cursor);
80
- items.push(args.rows.get(date) ?? args.empty(date));
81
- }
82
- return items;
83
- }
84
- /** Fill a fixed UTC 6-hour window from a map of known rows. */
85
- function fillUtcSixHours(args) {
86
- const bucketCount = args.count ?? 28;
87
- const { end, start } = trailingUtcSixHourWindow(args.nowMs, bucketCount);
88
- const items = [];
89
- for (const cursor = new Date(start); cursor.getTime() <= end.getTime(); cursor.setTime(cursor.getTime() + SIX_HOUR_MS)) {
90
- const date = utcSixHourKey(cursor);
91
- items.push(args.rows.get(date) ?? args.empty(date));
92
- }
93
- return items;
94
- }
95
- /**
96
- * Sum hour rows into trailing 6-hour buckets.
97
- * Adds number fields. Keeps other fields from the first row in the bucket.
98
- * Sets `date` to the 6-hour bucket key.
99
- */
100
- function sumUtcHoursIntoSixHours(args) {
101
- const bucketCount = args.count ?? 28;
102
- const bySix = /* @__PURE__ */ new Map();
103
- for (const hour of args.hours) {
104
- const key = utcSixHourKey(Date.parse(`${hour.date}:00:00.000Z`));
105
- const next = {
106
- ...bySix.get(key) ?? args.empty(key),
107
- date: key
108
- };
109
- for (const [field, value] of Object.entries(hour)) {
110
- if (field === "date") continue;
111
- if (typeof value === "number") {
112
- const prior = next[field];
113
- next[field] = (typeof prior === "number" ? prior : 0) + value;
114
- }
115
- }
116
- bySix.set(key, next);
117
- }
118
- return fillUtcSixHours({
119
- count: bucketCount,
120
- empty: args.empty,
121
- nowMs: args.nowMs,
122
- rows: bySix
123
- });
124
- }
125
- // src/api/schema/common.ts
126
- /** Stable error body returned by Junior-owned REST endpoints. */
127
- const apiErrorSchema = z.object({ error: z.string().min(1) }).strict();
128
- // src/chat/agent-invocations/result-event-type.ts
129
- /** Event namespace of the messages between a parent and its child agents. */
130
- const AGENT_INVOCATION_EVENT_NAMESPACE = "junior";
131
- const AGENT_INVOCATION_RESULT_EVENT_TYPE_PREFIX = "agent_invocation.";
132
- /** Build the Event type of the parent message for one agent invocation result. */
133
- function agentInvocationResultEventType(status) {
134
- return `${AGENT_INVOCATION_RESULT_EVENT_TYPE_PREFIX}${status}`;
135
- }
136
- /** True when an Event type names an agent invocation result. */
137
- function isAgentInvocationResultEventType(eventType) {
138
- return eventType.startsWith(AGENT_INVOCATION_RESULT_EVENT_TYPE_PREFIX);
139
- }
140
- /** Event type of the `reply` that ends a child agent's Turn. */
141
- const AGENT_REPLY_EVENT_TYPE = "agent.reply";
142
- /** Event type of a message that a child agent sends to its parent. */
143
- const AGENT_MESSAGE_EVENT_TYPE = "agent.message";
144
- /**
145
- * Event type of a parent agent task or message to a child that no agent
146
- * invocation names.
147
- */
148
- const AGENT_PARENT_MESSAGE_EVENT_TYPE = "agent.parent_message";
149
- // src/chat/plan/types.ts
150
- /** Statuses of a Plan item. `done` and `cancelled` close it. */
151
- const PLAN_ITEM_STATUSES = [
152
- "pending",
153
- "in_progress",
154
- "blocked",
155
- "done",
156
- "cancelled"
157
- ];
158
- /** Whether an item with this status is still work to do. */
159
- function isOpenPlanItemStatus(status) {
160
- return status !== "done" && status !== "cancelled";
161
- }
162
- /** Assignee text for the plan's own agent, in tool results and blocks. */
163
- const SELF_PLAN_ASSIGNEE = "self";
164
- // src/api/schema/user-customization.ts
165
- /** Longest customization text one user can save. */
166
- const USER_CUSTOMIZATION_MAX_CHARS = 1e3;
167
- /** Saved customization text. An empty string means none. */
168
- const userCustomizationTextSchema = z.string().trim().max(USER_CUSTOMIZATION_MAX_CHARS);
169
- /** Request and response body for the viewer's customization. */
170
- const userCustomizationSchema = z.object({ customization: userCustomizationTextSchema }).strict();
171
- // src/chat/attachments/media.ts
172
- const INPUT_IMAGE_TYPES = [
173
- "image/png",
174
- "image/jpeg",
175
- "image/gif",
176
- "image/webp"
177
- ];
178
- /** Video types that browsers play in a `<video>` element. */
179
- const INLINE_VIDEO_TYPES = ["video/mp4", "video/webm"];
180
- /** Leading bytes of each accepted image type. `null` matches any byte. */
181
- const IMAGE_SIGNATURES = [
182
- {
183
- mediaType: "image/png",
184
- bytes: [
185
- 137,
186
- 80,
187
- 78,
188
- 71,
189
- 13,
190
- 10,
191
- 26,
192
- 10
193
- ]
194
- },
195
- {
196
- mediaType: "image/jpeg",
197
- bytes: [
198
- 255,
199
- 216,
200
- 255
201
- ]
202
- },
203
- {
204
- mediaType: "image/gif",
205
- bytes: [
206
- 71,
207
- 73,
208
- 70,
209
- 56,
210
- 55,
211
- 97
212
- ]
213
- },
214
- {
215
- mediaType: "image/gif",
216
- bytes: [
217
- 71,
218
- 73,
219
- 70,
220
- 56,
221
- 57,
222
- 97
223
- ]
224
- },
225
- {
226
- mediaType: "image/webp",
227
- bytes: [
228
- 82,
229
- 73,
230
- 70,
231
- 70,
232
- null,
233
- null,
234
- null,
235
- null,
236
- 87,
237
- 69,
238
- 66,
239
- 80
240
- ]
241
- }
242
- ];
243
- /**
244
- * Detect an accepted image type from file bytes. Use this instead of a file
245
- * name or declared content type, which can be wrong.
246
- */
247
- function detectImageMediaType(data) {
248
- return IMAGE_SIGNATURES.find(({ bytes }) => data.length >= bytes.length && bytes.every((byte, index) => byte === null || data[index] === byte))?.mediaType;
249
- }
250
- /** Report whether a media type is a raster image accepted by vision models. */
251
- function isVisionImageMediaType(mediaType) {
252
- const normalized = mediaType.split(";", 1)[0]?.trim().toLowerCase();
253
- return normalized ? INPUT_IMAGE_TYPES.some((type) => type === normalized) : false;
254
- }
255
- // src/chat/tools/runtime/user-input-request.ts
256
- const USER_INPUT_LIMITS = {
257
- maxButtonOptions: 5,
258
- maxDescriptionChars: 200,
259
- maxFields: 4,
260
- maxLabelChars: 75,
261
- maxOptions: 10,
262
- maxTextChars: 3e3,
263
- maxQuestionChars: 3e3,
264
- minOptions: 2
265
- };
266
- const labelSchema = z.string().trim().min(1).max(USER_INPUT_LIMITS.maxLabelChars);
267
- const descriptionSchema = z.string().trim().min(1).max(USER_INPUT_LIMITS.maxDescriptionChars).optional();
268
- const optionSchema = z.object({
269
- label: labelSchema.describe("Short choice text, such as `Accept` or `Decline`. The answer uses this exact text."),
270
- description: descriptionSchema.describe("Optional short note about what this choice does."),
271
- recommended: z.boolean().optional().describe("Set true on the choice that you recommend, put that choice first, and say why in its description. A `choice` field can recommend one option.")
272
- });
273
- const fieldBase = {
274
- id: z.string().regex(/^[a-z][a-z0-9_]{0,31}$/).describe("Stable key for this field, such as `approach`."),
275
- label: labelSchema.describe("Short field name, such as `Approach`."),
276
- description: descriptionSchema.describe("Optional short help text for this field.")
277
- };
278
- const optionsSchema = z.array(optionSchema).min(USER_INPUT_LIMITS.minOptions).max(USER_INPUT_LIMITS.maxOptions).describe("Choices in display order.");
279
- const userInputFieldSchema = z.discriminatedUnion("kind", [
280
- z.object({
281
- ...fieldBase,
282
- kind: z.literal("choice").describe("The person picks one option."),
283
- options: optionsSchema
284
- }),
285
- z.object({
286
- ...fieldBase,
287
- kind: z.literal("multi_choice").describe("The person picks any number of options."),
288
- options: optionsSchema
289
- }),
290
- z.object({
291
- ...fieldBase,
292
- kind: z.literal("text").describe("The person types a short answer.")
293
- })
294
- ]);
295
- const userInputRequestSchema = z.object({
296
- question: z.string().trim().min(1).max(USER_INPUT_LIMITS.maxQuestionChars).describe("The question, in markdown. Include the facts the person needs to decide."),
297
- fields: z.array(userInputFieldSchema).min(1).max(USER_INPUT_LIMITS.maxFields).describe("What to ask, in display order. Use one `choice` field for a simple decision.")
298
- }).superRefine((request, context) => {
299
- const ids = /* @__PURE__ */ new Set();
300
- for (const field of request.fields) {
301
- if (ids.has(field.id)) context.addIssue({
302
- code: "custom",
303
- message: "Each field needs a different id."
304
- });
305
- ids.add(field.id);
306
- if (field.kind === "text") continue;
307
- const labels = field.options.map((option) => option.label.toLowerCase());
308
- if (new Set(labels).size !== labels.length) context.addIssue({
309
- code: "custom",
310
- message: "Each choice of a field needs a different label."
311
- });
312
- if (field.kind === "choice" && field.options.filter((option) => option.recommended).length > 1) context.addIssue({
313
- code: "custom",
314
- message: "A `choice` field can recommend only one option."
315
- });
316
- }
317
- });
318
- /**
319
- * Label and help text of the free-text input that every form adds after the
320
- * fields. The text goes with the picked answers and does not replace them, so
321
- * every surface says that in the same words.
322
- */
323
- const USER_INPUT_NOTE = {
324
- label: "Anything else?",
325
- description: "Optional. This note is sent together with your answers above."
326
- };
327
- /**
328
- * Return the single choice field of a request that a surface can show as
329
- * one row of buttons, where one click is the whole answer.
330
- */
331
- function buttonUserInputField(request) {
332
- const [field, ...rest] = request.fields;
333
- if (rest.length || field?.kind !== "choice") return void 0;
334
- return field.options.length <= USER_INPUT_LIMITS.maxButtonOptions ? field : void 0;
335
- }
336
- /**
337
- * Keep only answer values that match the request: known field ids, known
338
- * option labels, one value for a `choice` field, and trimmed text.
339
- */
340
- function normalizeUserInputAnswer(request, answer) {
341
- const values = {};
342
- for (const field of request.fields) {
343
- const raw = (answer.values[field.id] ?? []).map((value) => value.trim()).filter(Boolean);
344
- if (field.kind === "text") {
345
- const text = raw.join("\n").slice(0, USER_INPUT_LIMITS.maxTextChars);
346
- if (text) values[field.id] = [text];
347
- continue;
348
- }
349
- const picked = field.options.map((option) => option.label).filter((label) => raw.includes(label));
350
- const kept = field.kind === "choice" ? picked.slice(0, 1) : picked;
351
- if (kept.length) values[field.id] = kept;
352
- }
353
- const other = answer.other?.trim().slice(0, USER_INPUT_LIMITS.maxTextChars);
354
- return {
355
- requestId: answer.requestId,
356
- values,
357
- ...other ? { other } : void 0
358
- };
359
- }
360
- /** Return true when an answer has no value and no free text. */
361
- function isEmptyUserInputAnswer(answer) {
362
- return !answer.other && Object.keys(answer.values).length === 0;
363
- }
364
- function answerLine(text) {
365
- return text.split("\n").map((line) => line.trim()).filter(Boolean).join("\n");
366
- }
367
- /**
368
- * Write the fields of an answer, one `Label (field_id): value` line each.
369
- * Slack, the web dashboard, and the prompt all use this text, so the model
370
- * reads one format.
371
- */
372
- function formatUserInputAnswer(request, answer) {
373
- const normalized = normalizeUserInputAnswer(request, answer);
374
- const lines = [];
375
- for (const field of request.fields) {
376
- const values = normalized.values[field.id];
377
- const value = values?.length ? values.join(", ") : "(no answer)";
378
- lines.push(answerLine(`${field.label} (${field.id}): ${value}`));
379
- }
380
- if (normalized.other) lines.push(answerLine(`Other: ${normalized.other}`));
381
- return lines.join("\n");
382
- }
383
- // src/chat/agent-invocations/statuses.ts
384
- const AGENT_INVOCATION_STATUSES = [
385
- "pending",
386
- "running",
387
- "paused",
388
- "blocked",
389
- "completed",
390
- "failed",
391
- "stopped"
392
- ];
393
- const AGENT_INVOCATION_MAILBOX_STATUSES = ["pending", "appended"];
394
- /**
395
- * Parent mailbox append state. Only terminal invocations have a value.
396
- * `replaced` means the child still had open work, so a later agent invocation
397
- * on the same child sends the result instead. `skipped` means a stop ended
398
- * the work, so the result is never used. `steered` means the agent invocation
399
- * that was running read the input as a steering message, so its result covers
400
- * this one.
401
- */
402
- const AGENT_INVOCATION_PARENT_MAILBOX_STATUSES = [
403
- "pending",
404
- "appended",
405
- "replaced",
406
- "skipped",
407
- "steered"
408
- ];
409
- // src/chat/conversations/web-message-id.ts
410
- /**
411
- * Build the retry-stable Message id shared by web ingress and browser sends.
412
- * Keep the existing hash and prefix so retries still address stored Messages.
413
- */
414
- async function webMessageId(args) {
415
- const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${args.conversationId}\u0000${args.idempotencyKey}`));
416
- return `api-msg:${Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("").slice(0, 24)}`;
417
- }
418
- export { HOUR_MS as A, AGENT_MESSAGE_EVENT_TYPE as C, isAgentInvocationResultEventType as D, agentInvocationResultEventType as E, sumUtcHoursIntoSixHours as F, trailingUtcDayWindow as I, trailingUtcHourWindow as L, fillUtcHours as M, fillUtcSixHours as N, apiErrorSchema as O, startOfUtcHour as P, trailingUtcSixHourWindow as R, AGENT_INVOCATION_EVENT_NAMESPACE as S, AGENT_REPLY_EVENT_TYPE as T, userCustomizationSchema as _, USER_INPUT_LIMITS as a, SELF_PLAN_ASSIGNEE as b, formatUserInputAnswer as c, userInputRequestSchema as d, INLINE_VIDEO_TYPES as f, USER_CUSTOMIZATION_MAX_CHARS as g, isVisionImageMediaType as h, AGENT_INVOCATION_STATUSES as i, fillUtcDays as j, DAY_MS as k, isEmptyUserInputAnswer as l, detectImageMediaType as m, AGENT_INVOCATION_MAILBOX_STATUSES as n, USER_INPUT_NOTE as o, INPUT_IMAGE_TYPES as p, AGENT_INVOCATION_PARENT_MAILBOX_STATUSES as r, buttonUserInputField as s, webMessageId as t, normalizeUserInputAnswer as u, userCustomizationTextSchema as v, AGENT_PARENT_MESSAGE_EVENT_TYPE as w, isOpenPlanItemStatus as x, PLAN_ITEM_STATUSES as y, utcHourKey as z };