@sentry/junior 0.305.0 → 0.307.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 (98) hide show
  1. package/dist/{adapter-context-BpvbUki8.js → adapter-context-B69WPn6b.js} +2 -2
  2. package/dist/{admin-CoDt35ny.js → admin-nCJXMgkp.js} +2 -2
  3. package/dist/{agent-runner-C5d6rY5g.js → agent-runner-DdFcxAxG.js} +463 -303
  4. package/dist/api/schema.d.ts +2 -2
  5. package/dist/api/schema.js +7 -8
  6. package/dist/api.d.ts +19 -4
  7. package/dist/api.js +437 -310
  8. package/dist/{app-Cs157Zc5.d.ts → app-EZur8cVC.d.ts} +12 -3
  9. package/dist/app.d.ts +2 -2
  10. package/dist/app.js +532 -439
  11. package/dist/background-compaction-queue-BhEe4UfU.js +231 -0
  12. package/dist/{briefs-BRdznF7c.js → briefs-Dl9lxi7J.js} +3 -3
  13. package/dist/{catalog-runtime-J52Tej47.js → catalog-runtime-OXrv2Ewn.js} +1 -1
  14. package/dist/cli/chat.d.ts +1 -1
  15. package/dist/cli/chat.js +17 -16
  16. package/dist/cli/check.js +58 -48
  17. package/dist/cli/main.js +3 -3
  18. package/dist/cli/plugins.d.ts +1 -1
  19. package/dist/cli/plugins.js +4 -4
  20. package/dist/cli/snapshot-create.js +5 -5
  21. package/dist/cli/upgrade.d.ts +2 -2
  22. package/dist/cli/upgrade.js +3 -8
  23. package/dist/{config-CBZp0udd.js → config-362yMSIz.js} +183 -49
  24. package/dist/{connections-BYmuJ6Vm.js → connections-BJv3EjmB.js} +10 -8
  25. package/dist/{continue-in-slack-Cvot6S38.js → continue-in-slack-CFEevC7z.js} +5 -5
  26. package/dist/{conversation-BOqdRtUx.js → conversation--f85g4zL.js} +132 -132
  27. package/dist/{conversation-feed-CgpgP7yi.js → conversation-feed-BNs9KiqC.js} +1 -1
  28. package/dist/{conversation-privacy-D2pOzBNl.js → conversation-privacy-Tjj5P2W6.js} +1 -1
  29. package/dist/{conversation-turn-CI8WDpnK.js → conversation-turn-DU0_WDAr.js} +26 -72
  30. package/dist/{credential-sync-COqnZ1Dx.js → credential-sync-D6aFARKE.js} +28 -27
  31. package/dist/{db-DU84dCVu.js → db-Bcbd9zQc.js} +226 -18
  32. package/dist/{db-zbN5ZV_o.d.ts → db-C41UgdBj.d.ts} +1 -1
  33. package/dist/{executor-CFyrgOu1.js → executor-DBMBrpNV.js} +137 -33
  34. package/dist/{history-m2-ceTTX.js → history-N7IVbUom.js} +5 -1
  35. package/dist/{install-CQ76CfRw.js → install-CgoAbzfF.js} +2 -2
  36. package/dist/instrumentation.js +2 -2
  37. package/dist/{lineage-DLd2UxVP.js → lineage-CsZDmz3e.js} +2 -2
  38. package/dist/{logging-BPNTQVFu.js → logging-CHCuQ5iz.js} +1 -1
  39. package/dist/{message-BWJLeQ5e.js → message-B8vCbZZB.js} +8 -8
  40. package/dist/{model-input-DoM9Ht-d.js → model-input-Xluiy-1W.js} +3 -3
  41. package/dist/nitro.d.ts +2 -2
  42. package/dist/nitro.js +3 -4
  43. package/dist/{oauth-callback-server-DeHbnAQl.js → oauth-callback-server-BUuNvfvu.js} +2 -2
  44. package/dist/{oauth-relay-DAmfVmJu.js → oauth-relay-DGAZzg9m.js} +1 -1
  45. package/dist/{plugins-B_0Cr0MO.d.ts → plugins-fBrz8PCV.d.ts} +2 -0
  46. package/dist/{projection-CcFBVFUo.js → projection-xPpvqexa.js} +13423 -11432
  47. package/dist/{prompt-C5LREK2p.js → prompt-D8u4jFs_.js} +15 -7
  48. package/dist/{registry-BjZZqKqi.js → registry-D20hG3r6.js} +19 -9
  49. package/dist/{resolve-CeJgXuH1.js → resolve-BhCySRCW.js} +3 -3
  50. package/dist/{result-icDrueyB.js → result-DddO63S9.js} +13 -11
  51. package/dist/{runner-nVfMkMMB.js → runner-DQR9vYce.js} +13 -15
  52. package/dist/{sandbox-egress-signals-H9vQ5qRf.js → sandbox-egress-signals-DFlNUOnK.js} +1 -1
  53. package/dist/{automation-CuA3yEcD.js → schedule-BG1tEbRF.js} +380 -8
  54. package/dist/{schema-CKcu-IK6.d.ts → schema-CRXcj4fj.d.ts} +420 -143
  55. package/dist/{schema-Bx0Mlo32.js → schema-D4jdesIu.js} +62 -8
  56. package/dist/{service-account-DU5865XA.js → service-account-Bv5QwrEq.js} +8 -6
  57. package/dist/{service-account-Dw06p3zm.js → service-account-CNfycv0z.js} +3 -3
  58. package/dist/{session-stop-uotLtp4g.js → session-stop-BDdwyZaa.js} +878 -171
  59. package/dist/{skills-Bex1EaO5.js → skills-63i1Bcv1.js} +32 -28
  60. package/dist/{slack-conversation-unfurl-EPG3riWF.js → slack-conversation-unfurl-DtpBUlUu.js} +10 -9
  61. package/dist/{spawn-CoD3vDuS.js → spawn-mwimEY9_.js} +6 -6
  62. package/dist/{state-nCR4Muhn.js → state-BBn9L6gC.js} +4 -4
  63. package/dist/{stop-BFVd0P0m.js → stop-Da-Ug7tg.js} +172 -239
  64. package/dist/{store-Ca6G962n.js → store-CdWg2r2L.js} +5 -5
  65. package/dist/{background-compaction-queue-BTqMIfTA.js → task-queue-BcjAYWyB.js} +164 -180
  66. package/dist/{task-runner-xsOPIxCZ.js → task-runner-CoXmMlsW.js} +13 -11
  67. package/dist/{thread-context-BOvZhsKK.js → thread-context-ZPGqOjW7.js} +8 -91
  68. package/dist/turn-session-routing-DFYak28Q.js +263 -0
  69. package/dist/{turn-user-message-BrhuyYrH.js → turn-user-message-B1S8nOnG.js} +3 -3
  70. package/dist/users-DDbENg-I.js +181 -0
  71. package/dist/{validation-BnY9K5WB.js → validation-fl21ps-k.js} +1 -1
  72. package/dist/{version-qROlRQGF.js → version-DCdMMx_0.js} +1 -1
  73. package/dist/version.js +1 -1
  74. package/dist/{viewer-CxUiOraX.js → viewer-DN_xzVKj.js} +3 -3
  75. package/dist/{warmup--Gkz7iB-.js → warmup-CxhEhm71.js} +842 -532
  76. package/dist/{web-message-id-lNodcCOI.js → web-message-id-BT8Mg8LL.js} +16 -1
  77. package/dist/{worker-DJ8d9fmD.js → worker-Btb1SB5h.js} +8 -7
  78. package/migrations/0114_plan_items.sql +22 -0
  79. package/migrations/0115_automation_creator_slack_index.sql +1 -0
  80. package/migrations/0116_conversation_event_search.sql +25 -0
  81. package/migrations/0117_automation_last_run.sql +46 -0
  82. package/migrations/0118_automation_last_run_index.sql +1 -0
  83. package/migrations/0119_money_micro_usd.sql +29 -0
  84. package/migrations/0120_conversation_cost_micro_usd.sql +8 -0
  85. package/migrations/meta/0114_snapshot.json +5203 -0
  86. package/migrations/meta/0115_snapshot.json +5225 -0
  87. package/migrations/meta/0116_snapshot.json +5388 -0
  88. package/migrations/meta/0117_snapshot.json +5413 -0
  89. package/migrations/meta/0118_snapshot.json +5428 -0
  90. package/migrations/meta/0119_snapshot.json +5441 -0
  91. package/migrations/meta/0120_snapshot.json +5441 -0
  92. package/migrations/meta/_journal.json +49 -0
  93. package/package.json +10 -9
  94. package/dist/queue-B2AAL3ym.js +0 -115
  95. package/dist/schedule-cP0AACm1.js +0 -344
  96. package/dist/secrets-DHaJ5TTn.js +0 -18
  97. package/dist/task-queue-BLPZU6kC.js +0 -89
  98. package/dist/turn-session-routing-2bW2qfeb.js +0 -1792
@@ -1,5 +1,4 @@
1
- import { c as resolveLocalScheduleAtMs, i as getFirstRunAtMs, o as getZonedDateTimeParts, s as isValidTimeZone } from "./schedule-cP0AACm1.js";
2
- import { i as actorIdentitySchema } from "./conversation-BOqdRtUx.js";
1
+ import { i as actorIdentitySchema } from "./conversation--f85g4zL.js";
3
2
  import * as z from "zod";
4
3
  import { actorUserIdSchema, destinationVisibilitySchema, eventMatchFieldsSchema, eventMatchSchema, eventReachSchema, eventTypeSchema, pluginEventTypeSchema, slackDestinationSchema, taskOutcomeSchema } from "@sentry/junior-plugin-api";
5
4
  // src/chat/automations/task.ts
@@ -44,6 +43,260 @@ function automationTaskColumns(task) {
44
43
  skill: task.skill
45
44
  };
46
45
  }
46
+ // src/chat/scheduled-automations/cadence.ts
47
+ const FORMATTERS = /* @__PURE__ */ new Map();
48
+ function getFormatter(timezone) {
49
+ const existing = FORMATTERS.get(timezone);
50
+ if (existing) return existing;
51
+ const formatter = new Intl.DateTimeFormat("en-US", {
52
+ timeZone: timezone,
53
+ hour12: false,
54
+ year: "numeric",
55
+ month: "2-digit",
56
+ day: "2-digit",
57
+ hour: "2-digit",
58
+ minute: "2-digit",
59
+ second: "2-digit"
60
+ });
61
+ FORMATTERS.set(timezone, formatter);
62
+ return formatter;
63
+ }
64
+ function normalizeHour(hour) {
65
+ return hour === 24 ? 0 : hour;
66
+ }
67
+ function getLocalDateWeekday(date) {
68
+ return new Date(Date.UTC(date.year, date.month - 1, date.day)).getUTCDay();
69
+ }
70
+ function getWeekStart(date) {
71
+ return addDays(date, -((getLocalDateWeekday(date) + 6) % 7));
72
+ }
73
+ /**
74
+ * Check that a value is an IANA time zone that this runtime knows. This module
75
+ * has no runtime imports, so the dashboard client bundle can use it.
76
+ */
77
+ function isValidTimeZone(timezone) {
78
+ try {
79
+ new Intl.DateTimeFormat("en-US", { timeZone: timezone }).format();
80
+ return true;
81
+ } catch {
82
+ return false;
83
+ }
84
+ }
85
+ /** Resolve a UTC timestamp into calendar parts for a named time zone. */
86
+ function getZonedDateTimeParts(timestampMs, timezone) {
87
+ const parts = getFormatter(timezone).formatToParts(new Date(timestampMs));
88
+ const values = new Map(parts.map((part) => [part.type, part.value]));
89
+ const year = Number(values.get("year"));
90
+ const month = Number(values.get("month"));
91
+ const day = Number(values.get("day"));
92
+ return {
93
+ year,
94
+ month,
95
+ day,
96
+ hour: normalizeHour(Number(values.get("hour"))),
97
+ minute: Number(values.get("minute")),
98
+ second: Number(values.get("second")),
99
+ weekday: getLocalDateWeekday({
100
+ year,
101
+ month,
102
+ day
103
+ })
104
+ };
105
+ }
106
+ function getTimeZoneOffsetMs(timestampMs, timezone) {
107
+ const parts = getZonedDateTimeParts(timestampMs, timezone);
108
+ return Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second) - timestampMs;
109
+ }
110
+ function localDateTimeToTimestampMs(args) {
111
+ const localAsUtcMs = Date.UTC(args.date.year, args.date.month - 1, args.date.day, args.time.hour, args.time.minute, 0);
112
+ const offsets = /* @__PURE__ */ new Set();
113
+ for (const probeDeltaMs of [
114
+ -1296e5,
115
+ -432e5,
116
+ 0,
117
+ 432e5,
118
+ 1296e5
119
+ ]) offsets.add(getTimeZoneOffsetMs(localAsUtcMs + probeDeltaMs, args.timezone));
120
+ const matches = [...offsets].map((offsetMs) => localAsUtcMs - offsetMs).filter((timestampMs) => {
121
+ const parts = getZonedDateTimeParts(timestampMs, args.timezone);
122
+ return parts.year === args.date.year && parts.month === args.date.month && parts.day === args.date.day && parts.hour === args.time.hour && parts.minute === args.time.minute;
123
+ });
124
+ if (matches.length === 0) return;
125
+ return Math.min(...matches);
126
+ }
127
+ /** Resolve local time, rejecting DST gaps and choosing the earlier instant in a fold. */
128
+ function resolveLocalScheduleAtMs(args) {
129
+ const date = parseLocalDate(args.date);
130
+ if (!date) return;
131
+ return localDateTimeToTimestampMs({
132
+ date,
133
+ time: args.time,
134
+ timezone: args.timezone
135
+ });
136
+ }
137
+ function daysBetween(left, right) {
138
+ return Math.floor((Date.UTC(right.year, right.month - 1, right.day) - Date.UTC(left.year, left.month - 1, left.day)) / 864e5);
139
+ }
140
+ function weeklyRecurrenceMatchesDate(date, start, recurrence) {
141
+ if (compareDate(date, start) < 0) return false;
142
+ return normalizeWeekdays(recurrence.weekdays).includes(getLocalDateWeekday(date)) && Math.floor(daysBetween(getWeekStart(start), getWeekStart(date)) / 7) % recurrence.interval === 0;
143
+ }
144
+ function greatestCommonDivisor(left, right) {
145
+ let a = Math.abs(left);
146
+ let b = Math.abs(right);
147
+ while (b !== 0) [a, b] = [b, a % b];
148
+ return a;
149
+ }
150
+ function findNextRunAtMs(args) {
151
+ const start = parseLocalDate(args.recurrence.startDate);
152
+ const interval = args.recurrence.interval;
153
+ if (!start || !Number.isInteger(interval) || interval <= 0) return;
154
+ const searchFrom = compareDate(args.searchFrom, start) < 0 ? start : args.searchFrom;
155
+ if (args.recurrence.frequency === "daily") {
156
+ const offsetDays = daysBetween(start, searchFrom);
157
+ let candidateDate = addDays(start, Math.ceil(offsetDays / interval) * interval);
158
+ const gregorianCycleDays = 146097;
159
+ const candidateCount = gregorianCycleDays / greatestCommonDivisor(gregorianCycleDays, interval);
160
+ for (let attempts = 0; attempts < candidateCount; attempts += 1) {
161
+ const candidate = buildCandidate({
162
+ date: candidateDate,
163
+ recurrence: args.recurrence,
164
+ timezone: args.timezone
165
+ });
166
+ if (candidate !== void 0 && candidate > args.afterMs) return candidate;
167
+ candidateDate = addDays(candidateDate, interval);
168
+ }
169
+ return;
170
+ }
171
+ if (args.recurrence.frequency === "weekly") {
172
+ if (normalizeWeekdays(args.recurrence.weekdays).length === 0) return;
173
+ let candidateDate = searchFrom;
174
+ const gregorianCycleDays = 146097;
175
+ const cadenceDays = interval * 7;
176
+ const searchDays = gregorianCycleDays * cadenceDays / greatestCommonDivisor(gregorianCycleDays, cadenceDays);
177
+ for (let attempts = 0; attempts < searchDays; attempts += 1) {
178
+ if (weeklyRecurrenceMatchesDate(candidateDate, start, args.recurrence)) {
179
+ const candidate = buildCandidate({
180
+ date: candidateDate,
181
+ recurrence: args.recurrence,
182
+ timezone: args.timezone
183
+ });
184
+ if (candidate !== void 0 && candidate > args.afterMs) return candidate;
185
+ }
186
+ candidateDate = addDays(candidateDate, 1);
187
+ }
188
+ return;
189
+ }
190
+ if (args.recurrence.frequency === "monthly") {
191
+ const startMonth = start.year * 12 + start.month - 1;
192
+ const searchMonth = searchFrom.year * 12 + searchFrom.month - 1;
193
+ let candidateMonth = startMonth + Math.ceil((searchMonth - startMonth) / interval) * interval;
194
+ const gregorianCycleMonths = 4800;
195
+ const candidateCount = gregorianCycleMonths / greatestCommonDivisor(gregorianCycleMonths, interval);
196
+ for (let attempts = 0; attempts < candidateCount; attempts += 1) {
197
+ const candidateDate = {
198
+ year: Math.floor(candidateMonth / 12),
199
+ month: candidateMonth % 12 + 1,
200
+ day: args.recurrence.dayOfMonth ?? 0
201
+ };
202
+ if (compareDate(candidateDate, searchFrom) >= 0) {
203
+ const candidate = buildCandidate({
204
+ date: candidateDate,
205
+ recurrence: args.recurrence,
206
+ timezone: args.timezone
207
+ });
208
+ if (candidate !== void 0 && candidate > args.afterMs) return candidate;
209
+ }
210
+ candidateMonth += interval;
211
+ }
212
+ return;
213
+ }
214
+ let candidateYear = start.year + Math.ceil((searchFrom.year - start.year) / interval) * interval;
215
+ const candidateCount = 400 / greatestCommonDivisor(400, interval);
216
+ for (let attempts = 0; attempts < candidateCount; attempts += 1) {
217
+ const candidateDate = {
218
+ year: candidateYear,
219
+ month: args.recurrence.month ?? 0,
220
+ day: args.recurrence.dayOfMonth ?? 0
221
+ };
222
+ if (compareDate(candidateDate, searchFrom) >= 0) {
223
+ const candidate = buildCandidate({
224
+ date: candidateDate,
225
+ recurrence: args.recurrence,
226
+ timezone: args.timezone
227
+ });
228
+ if (candidate !== void 0 && candidate > args.afterMs) return candidate;
229
+ }
230
+ candidateYear += interval;
231
+ }
232
+ }
233
+ /** Compute the first recurring calendar occurrence strictly after a timestamp. */
234
+ function getFirstRunAtMs(args) {
235
+ return findNextRunAtMs({
236
+ ...args,
237
+ searchFrom: getLocalDate(args.afterMs, args.timezone)
238
+ });
239
+ }
240
+ function compareDate(left, right) {
241
+ return Date.UTC(left.year, left.month - 1, left.day) - Date.UTC(right.year, right.month - 1, right.day);
242
+ }
243
+ function addDays(date, days) {
244
+ const next = new Date(Date.UTC(date.year, date.month - 1, date.day + days));
245
+ return {
246
+ year: next.getUTCFullYear(),
247
+ month: next.getUTCMonth() + 1,
248
+ day: next.getUTCDate()
249
+ };
250
+ }
251
+ function daysInMonth(year, month) {
252
+ return new Date(Date.UTC(year, month, 0)).getUTCDate();
253
+ }
254
+ function parseLocalDate(value) {
255
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
256
+ if (!match) return;
257
+ const year = Number(match[1]);
258
+ const month = Number(match[2]);
259
+ const day = Number(match[3]);
260
+ if (!Number.isInteger(year) || !Number.isInteger(month) || !Number.isInteger(day) || month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month)) return;
261
+ return {
262
+ year,
263
+ month,
264
+ day
265
+ };
266
+ }
267
+ function getLocalDate(timestampMs, timezone) {
268
+ const parts = getZonedDateTimeParts(timestampMs, timezone);
269
+ return {
270
+ year: parts.year,
271
+ month: parts.month,
272
+ day: parts.day
273
+ };
274
+ }
275
+ function normalizeWeekdays(values) {
276
+ return [...new Set((values ?? []).filter((value) => value >= 0 && value <= 6))].sort((a, b) => a - b);
277
+ }
278
+ function buildCandidate(args) {
279
+ return localDateTimeToTimestampMs({
280
+ date: args.date,
281
+ time: args.recurrence.time,
282
+ timezone: args.timezone
283
+ });
284
+ }
285
+ /** Return the next fire time after a completed run, when the task recurs. */
286
+ function getNextRunAtMs(task, scheduledForMs, afterMs = scheduledForMs) {
287
+ if (task.schedule.kind !== "recurring") return;
288
+ const recurrence = task.schedule.recurrence;
289
+ if (!recurrence || !Number.isFinite(recurrence.interval) || recurrence.interval <= 0) return;
290
+ const timezone = task.schedule.timezone;
291
+ const afterDate = getLocalDate(afterMs, timezone);
292
+ const nextScheduledDate = addDays(getLocalDate(scheduledForMs, timezone), 1);
293
+ return findNextRunAtMs({
294
+ afterMs,
295
+ recurrence,
296
+ searchFrom: compareDate(afterDate, nextScheduledDate) < 0 ? nextScheduledDate : afterDate,
297
+ timezone
298
+ });
299
+ }
47
300
  // src/chat/scheduled-automations/schedule-intent.ts
48
301
  /**
49
302
  * Owns model-facing schedule intent and materializes it against the trusted
@@ -435,9 +688,10 @@ const automationTitleSchema = z.string().trim().min(1).max(60);
435
688
  /**
436
689
  * Instruction input for agent tools. The run does not see the request, so the
437
690
  * instruction names exact targets. It calls the creator "the Automation
438
- * creator". It names every other person with their mention.
691
+ * creator". It names every other person with their mention, also a requester
692
+ * who says "me".
439
693
  */
440
- const automationInstructionToolSchema = automationTaskTextSchema.describe("Work to perform when the Automation runs. Say what to do, what to post, and when to post nothing. Do not say where to post: the outcomes set that, a run triggered by a Slack message replies in its thread, and each run ends with one message at most. The run does not see this conversation, so words like \"this channel\" or \"here\" will mean nothing then. Where the run reads or changes something, write the exact target, such as a channel mention, a repo, or a link. Call the person who created the Automation \"the Automation creator\", not \"me\"; each run knows who that is. Name every other person with their Slack mention, such as <@U123>, including a requester who did not create the Automation. Preserve the user's scope, targets, and constraints. Do not add permissions or side effects the user did not request.");
694
+ const automationInstructionToolSchema = automationTaskTextSchema.describe("Work to perform when the Automation runs. Say what to do, what to post, and when to post nothing. Do not say where to post: the outcomes set that, a run triggered by a Slack message replies in its thread, and each run ends with one message at most. The run does not see this conversation, so words like \"this channel\" or \"here\" will mean nothing then. Where the run reads or changes something, write the exact target, such as a channel mention, a repo, or a link. Keep every person the user means, including \"me\". Write the creator as \"the Automation creator\"; each run knows who that is. Write anyone else, including a requester who is not the creator, as their Slack mention, such as <@U123>. Preserve the user's scope, targets, and constraints. Do not add permissions or side effects the user did not request.");
441
695
  /** Context input for agent tools. It follows the same rules as an instruction. */
442
696
  const automationContextToolSchema = automationTaskTextSchema.describe("What a skill run needs beyond the skill, such as a repo, a threshold, or who to tag. Leave out what the skill says. Use instruction rules: do not say where to post, write exact targets, call the creator \"the Automation creator\", and tag others as <@U123>.");
443
697
  const automationEditFieldsSchema = z.object({
@@ -544,6 +798,18 @@ const eventAutomationSummarySchema = automationSummaryBaseSchema.extend({
544
798
  ])
545
799
  }).strict();
546
800
  const automationSummarySchema = z.discriminatedUnion("kind", [scheduledAutomationSummarySchema, eventAutomationSummarySchema]);
801
+ /**
802
+ * Totals that read every run of an Automation. Only the Automation page
803
+ * shows them, so list rows leave them out.
804
+ */
805
+ const AUTOMATION_TOTAL_FIELDS = {
806
+ costUsd: true,
807
+ runs: true,
808
+ totalCostUsd: true,
809
+ totalRuns: true
810
+ };
811
+ /** One list row: a summary without the totals that read every run. */
812
+ const automationListItemSchema = z.discriminatedUnion("kind", [scheduledAutomationSummarySchema.omit(AUTOMATION_TOTAL_FIELDS), eventAutomationSummarySchema.omit(AUTOMATION_TOTAL_FIELDS)]);
547
813
  /** UTC day (`YYYY-MM-DD`) or hour (`YYYY-MM-DDTHH`) execution bucket key. */
548
814
  const automationMetricBucketSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}(T\d{2})?$/);
549
815
  const automationListQuerySchema = z.object({
@@ -573,11 +839,18 @@ const automationListQuerySchema = z.object({
573
839
  destination: z.string().max(300).optional(),
574
840
  /** Only Automations that run this skill. */
575
841
  skill: automationSkillNameSchema.optional(),
842
+ /**
843
+ * `activity` lists the latest run or creation first, and pages with
844
+ * `cursor`. The other orders page with `page`.
845
+ */
576
846
  sort: z.enum([
577
847
  "newest",
578
848
  "oldest",
579
- "title"
849
+ "title",
850
+ "activity"
580
851
  ]).default("newest"),
852
+ /** `nextCursor` of the page before, with `sort=activity`. */
853
+ cursor: z.string().min(1).max(1e3).optional(),
581
854
  page: z.coerce.number().int().min(1).max(1e6).default(1),
582
855
  pageSize: z.coerce.number().int().min(1).max(100).default(25)
583
856
  }).strict();
@@ -586,7 +859,9 @@ const automationFilterOptionSchema = z.object({
586
859
  label: z.string()
587
860
  }).strict();
588
861
  const automationListSchema = z.object({
589
- automations: z.array(automationSummarySchema),
862
+ automations: z.array(automationListItemSchema),
863
+ /** Set when more rows follow `sort=activity`. Pass it as `cursor`. */
864
+ nextCursor: z.string().min(1).optional(),
590
865
  total: z.number().int().nonnegative(),
591
866
  page: z.number().int().positive(),
592
867
  pageSize: z.number().int().positive(),
@@ -599,6 +874,16 @@ const automationListSchema = z.object({
599
874
  creators: z.array(automationFilterOptionSchema),
600
875
  destinations: z.array(automationFilterOptionSchema)
601
876
  }).strict();
877
+ /**
878
+ * One `sort=activity` page. A page after the first omits the total, counts,
879
+ * and filter options, because the first page already has them.
880
+ */
881
+ const automationListPageSchema = automationListSchema.partial({
882
+ total: true,
883
+ counts: true,
884
+ creators: true,
885
+ destinations: true
886
+ });
602
887
  const automationParamsSchema = z.object({ id: z.string().min(1) }).strict();
603
888
  const automationExecutionStatusSchema = z.enum([
604
889
  "blocked",
@@ -641,7 +926,6 @@ const automationExecutionListSchema = z.object({
641
926
  executionHours: z.array(automationExecutionStatusDaySchema).optional(),
642
927
  executionSixHours: z.array(automationExecutionStatusDaySchema).optional(),
643
928
  executions: z.array(automationExecutionSchema),
644
- automation: automationSummarySchema,
645
929
  truncated: z.boolean()
646
930
  }).strict();
647
931
  const automationRunSchema = automationExecutionSchema.extend({
@@ -771,4 +1055,92 @@ const automationEventCatalogSchema = z.array(z.object({
771
1055
  }).strict());
772
1056
  const automationScheduleIntentSchema = scheduleIntentSchema;
773
1057
  const automationSchedulePreviewSchema = scheduledAutomationSchema.pick({ schedule: true }).extend({ nextRunAtMs: z.number() }).strict();
774
- export { eventAutomationTriggerSchema as A, automationTaskColumns as B, eventAutomationSummarySchema as C, automationTitleSchema as D, automationInstructionToolSchema as E, compileScheduleIntent as F, automationTaskSchema as H, scheduleIntentFromTool as I, toolScheduleIntentSchema as L, scheduledAutomationSchema as M, scheduledRunSchema as N, taskOutcomeInputSchema as O, ScheduleIntentError as P, weekdaySchema as R, automationVersionSchema as S, automationContextToolSchema as T, automationTaskText as U, automationTaskDescription as V, automationSummarySchema as _, automationExecutionSchema as a, automationVersionListSchema as b, automationLifecycleSchema as c, automationParamsSchema as d, automationRunListSchema as f, automationSchedulePreviewSchema as g, automationScheduleIntentSchema as h, automationExecutionListSchema as i, SCHEDULED_AUTOMATION_SYSTEM_ACTOR as j, eventAutomationSchema as k, automationListQuerySchema as l, automationRunWindowsSchema as m, automationEditSchema as n, automationExecutionStatusDaySchema as o, automationRunSchema as p, automationEventCatalogSchema as r, automationExecutionStatusSchema as s, automationEditErrorSchema as t, automationListSchema as u, automationUpdateSchema as v, scheduledAutomationSummarySchema as w, automationVersionParamsSchema as x, automationVersionActivateSchema as y, automationSkillNameSchema as z };
1058
+ // src/chat/notifications/schedule.ts
1059
+ /**
1060
+ * Notification hours for one user.
1061
+ *
1062
+ * This module imports only zod and the browser-safe cadence helpers, so the
1063
+ * dashboard client bundle can use it.
1064
+ */
1065
+ const clockTimePattern = /^([01]\d|2[0-3]):[0-5]\d$/;
1066
+ /** Saved notification hours. Weekdays use 0 for Sunday, like `Date#getDay`. */
1067
+ const notificationScheduleSchema = z.object({
1068
+ /**
1069
+ * Follow the linked Slack user's notification schedule. The fields below
1070
+ * apply only when Junior cannot read it. Absent means on.
1071
+ */
1072
+ followSlack: z.boolean().optional(),
1073
+ /** When false, Junior sends push notifications at any time. */
1074
+ workingHoursOnly: z.boolean(),
1075
+ days: z.array(z.number().int().min(0).max(6)).max(7).refine((days) => new Set(days).size === days.length, { message: "Days must be unique." }),
1076
+ /** Local start time, `HH:MM`. */
1077
+ start: z.string().regex(clockTimePattern),
1078
+ /** Local end time, `HH:MM`. An end before the start crosses midnight. */
1079
+ end: z.string().regex(clockTimePattern),
1080
+ /** IANA timezone set by the user. Absent means the profile timezone. */
1081
+ timezone: z.string().min(1).max(64).refine(isValidTimeZone, { message: "Unknown timezone." }).optional()
1082
+ }).strict().refine((schedule) => schedule.start !== schedule.end, {
1083
+ message: "Start and end must differ.",
1084
+ path: ["end"]
1085
+ });
1086
+ /**
1087
+ * Default when a user has not saved a schedule: follow Slack, else
1088
+ * 09:00–18:00, Mon–Fri.
1089
+ */
1090
+ const DEFAULT_NOTIFICATION_SCHEDULE = {
1091
+ followSlack: true,
1092
+ workingHoursOnly: true,
1093
+ days: [
1094
+ 1,
1095
+ 2,
1096
+ 3,
1097
+ 4,
1098
+ 5
1099
+ ],
1100
+ start: "09:00",
1101
+ end: "18:00"
1102
+ };
1103
+ function clockMinutes(value) {
1104
+ const [hours, minutes] = value.split(":").map(Number);
1105
+ return hours * 60 + minutes;
1106
+ }
1107
+ const weekdayIndex = {
1108
+ Sun: 0,
1109
+ Mon: 1,
1110
+ Tue: 2,
1111
+ Wed: 3,
1112
+ Thu: 4,
1113
+ Fri: 5,
1114
+ Sat: 6
1115
+ };
1116
+ function localWeekdayAndMinutes(nowMs, timezone) {
1117
+ const parts = new Intl.DateTimeFormat("en-US", {
1118
+ hour: "2-digit",
1119
+ hourCycle: "h23",
1120
+ minute: "2-digit",
1121
+ timeZone: timezone,
1122
+ weekday: "short"
1123
+ }).formatToParts(new Date(nowMs));
1124
+ const value = (type) => parts.find((part) => part.type === type)?.value ?? "";
1125
+ const weekday = weekdayIndex[value("weekday")];
1126
+ if (weekday === void 0) throw new Error(`Could not read the weekday for timezone ${timezone}`);
1127
+ return {
1128
+ minutes: Number(value("hour")) % 24 * 60 + Number(value("minute")),
1129
+ weekday
1130
+ };
1131
+ }
1132
+ /**
1133
+ * Return whether a notification may be sent now. A window that crosses
1134
+ * midnight belongs to the day on which it starts.
1135
+ */
1136
+ function isWithinNotificationSchedule(schedule, timezone, nowMs) {
1137
+ if (!schedule.workingHoursOnly) return true;
1138
+ const { minutes, weekday } = localWeekdayAndMinutes(nowMs, timezone);
1139
+ const start = clockMinutes(schedule.start);
1140
+ const end = clockMinutes(schedule.end);
1141
+ if (start < end) return schedule.days.includes(weekday) && minutes >= start && minutes < end;
1142
+ if (minutes >= start) return schedule.days.includes(weekday);
1143
+ if (minutes < end) return schedule.days.includes((weekday + 6) % 7);
1144
+ return false;
1145
+ }
1146
+ export { automationContextToolSchema as A, compileScheduleIntent as B, automationUpdateSchema as C, automationVersionSchema as D, automationVersionParamsSchema as E, eventAutomationTriggerSchema as F, getNextRunAtMs as G, toolScheduleIntentSchema as H, SCHEDULED_AUTOMATION_SYSTEM_ACTOR as I, automationSkillNameSchema as J, getZonedDateTimeParts as K, scheduledAutomationSchema as L, automationTitleSchema as M, taskOutcomeInputSchema as N, eventAutomationSummarySchema as O, eventAutomationSchema as P, automationTaskText as Q, scheduledRunSchema as R, automationSummarySchema as S, automationVersionListSchema as T, weekdaySchema as U, scheduleIntentFromTool as V, getFirstRunAtMs as W, automationTaskDescription as X, automationTaskColumns as Y, automationTaskSchema as Z, automationRunListSchema as _, automationEditSchema as a, automationScheduleIntentSchema as b, automationExecutionSchema as c, automationLifecycleSchema as d, automationListItemSchema as f, automationParamsSchema as g, automationListSchema as h, automationEditErrorSchema as i, automationInstructionToolSchema as j, scheduledAutomationSummarySchema as k, automationExecutionStatusDaySchema as l, automationListQuerySchema as m, isWithinNotificationSchedule as n, automationEventCatalogSchema as o, automationListPageSchema as p, isValidTimeZone as q, notificationScheduleSchema as r, automationExecutionListSchema as s, DEFAULT_NOTIFICATION_SCHEDULE as t, automationExecutionStatusSchema as u, automationRunSchema as v, automationVersionActivateSchema as w, automationSchedulePreviewSchema as x, automationRunWindowsSchema as y, ScheduleIntentError as z };