@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.
- package/dist/{adapter-context-BhKpjpGD.js → adapter-context-BRjEWRy1.js} +2 -2
- package/dist/adapter-iIq7ihf7.js +259 -0
- package/dist/{admin-tgZEZAk2.js → admin-DhInw5K9.js} +1 -2
- package/dist/{agent-runner-D9cvNlQl.js → agent-runner-C9iDurwX.js} +6507 -7721
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +7 -6
- package/dist/api.d.ts +21 -3
- package/dist/api.js +1625 -535
- package/dist/{app-B_7Wn0en.d.ts → app-DRFrC8Mw.d.ts} +14 -10
- package/dist/app.d.ts +2 -2
- package/dist/app.js +454 -994
- package/dist/{background-compaction-queue-BGHqkhkY.js → background-compaction-queue-DrKi7w3d.js} +10 -85
- package/dist/callback-mFlTUWWx.js +75 -0
- package/dist/{catalog-runtime-BxwzbLKY.js → catalog-runtime-D7xapBAX.js} +1 -1
- package/dist/channel-access-CJGfNTdn.js +221 -0
- package/dist/child-message-DcsritGf.js +179 -0
- package/dist/cli/chat.js +18 -19
- package/dist/cli/check.js +23 -29
- package/dist/cli/init.js +1 -7
- package/dist/cli/main.js +3 -7
- package/dist/cli/plugins.js +8 -7
- package/dist/cli/run.d.ts +1 -2
- package/dist/cli/run.js +1 -2
- package/dist/cli/snapshot-create.js +5 -5
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +3 -3
- package/dist/{config-Dkt2Le2b.js → config-kXB2Y5tl.js} +294 -28
- package/dist/{continue-in-slack-BWVwePKD.js → continue-in-slack-O6pV5004.js} +7 -7
- package/dist/{conversation-feed-Ci6YD1N-.js → conversation-feed-uNOv_x68.js} +87 -24
- package/dist/{conversation-privacy-C39g8BY4.js → conversation-privacy-L4ja1_W6.js} +1 -1
- package/dist/{conversation-turn-CBlZIH02.js → conversation-turn-CeLbHqdw.js} +56 -49
- package/dist/{credential-sync-vGnrB0BY.js → credential-sync-I8VBGk05.js} +16 -16
- package/dist/{projection-jZSlEAXG.js → credentialed-Cb6E2phL.js} +16268 -16821
- package/dist/{db-B4Hjxr-u.d.ts → db-BbC5stfa.d.ts} +13 -6
- package/dist/{db-CFZggNoy.js → db-LAyyX8tk.js} +1698 -1046
- package/dist/{executor-BPkZDx5-.js → executor-SCub-fAq.js} +552 -181
- package/dist/{html-2r2KmLwi.js → html-BCZ3Xtb_.js} +6 -6
- package/dist/{session-stop-BfY4rhJs.js → ingest-BDf3D50j.js} +2134 -2553
- package/dist/{install-C-oE6C_u.js → install-DCFJFkC0.js} +2 -2
- package/dist/instrumentation.js +4 -4
- package/dist/{lineage-CsvrEFQe.js → lineage-B_m-4TJw.js} +2 -2
- package/dist/{stop-DYzjRf2U.js → list-CN2QA2R9.js} +1656 -685
- package/dist/{logging-D5gkyvnK.js → logging-dQ9ZRGQ8.js} +47 -9
- package/dist/media-CYm1QD8T.js +2356 -0
- package/dist/{message-DwvJ-I3w.js → message-DSXGj1hM.js} +19 -29
- package/dist/{model-input-MAq2881y.js → model-input--TrP9hYV.js} +3 -3
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +4 -3
- package/dist/{oauth-callback-server-DIF6Li06.js → oauth-callback-server-DHCZC6B4.js} +2 -2
- package/dist/{oauth-relay-DPE-wrwO.js → oauth-relay-pPMGnDZt.js} +1 -1
- package/dist/{registry-BBkWFCl8.js → registry-CZOzddwu.js} +5 -8
- package/dist/{resolve-B38MkHXE.js → resolve-cKOQ14Dh.js} +3 -3
- package/dist/{result-BaqSZcJb.js → result-DcvEOe1r.js} +119 -93
- package/dist/result-event-type-BdIJuZxg.js +48 -0
- package/dist/rule-DAxQY-1h.js +20 -0
- package/dist/{runner-11h8PrHh.js → runner-DBfUW44l.js} +14 -16
- package/dist/{sandbox-egress-signals-CTcACAtJ.js → sandbox-egress-signals-BVF_xAm1.js} +1 -1
- package/dist/{schema-DriSvB40.d.ts → schema-BEHKxr4I.d.ts} +861 -298
- package/dist/{schema-obw5jvR4.js → schema-Bk9Nm2E8.js} +344 -153
- package/dist/{service-account-Bx93N1n1.js → service-account-CVYsFjty.js} +3 -3
- package/dist/{service-account-Zc5bUcIJ.js → service-account-Ts4ulcrV.js} +68 -68
- package/dist/{skills-C8Npu5zO.js → skills-VTnhAJWm.js} +2 -2
- package/dist/{slack-conversation-unfurl-DlRVA02H.js → slack-conversation-unfurl-fuLnF1jE.js} +9 -11
- package/dist/{spawn-CXr58R0x.js → spawn-vxAarlX5.js} +6 -6
- package/dist/start-conversation-CEn2KH1A.js +941 -0
- package/dist/{state-CGrGVeQC.js → state-C1P3_Ywk.js} +4 -4
- package/dist/statuses-_cRJHXK7.js +150 -0
- package/dist/store-DFZaN-Ix.js +492 -0
- package/dist/task-queue-Cx4Lmjyk.js +90 -0
- package/dist/task-runner-CbTwFA6k.js +1432 -0
- package/dist/{thread-context-Dyj1KWaY.js → thread-context-BkAZDTX2.js} +13 -11
- package/dist/thread-state-DhPndWi1.js +5625 -0
- package/dist/{validation-DxVNIxA0.js → validation-nIzMtAVJ.js} +1 -1
- package/dist/{task-queue-CaZffYaH.js → vercel-queue-hW90XzbG.js} +93 -172
- package/dist/{version-Cr7Z71yG.js → version-Brbtz4Qf.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{warmup-C6LOZ2d2.js → warmup-BDA5myRK.js} +5832 -4567
- package/dist/web-message-id-C6P83ans.js +10 -0
- package/dist/{worker-CUBtu1Li.js → worker-D63RcaVD.js} +20 -8
- package/migrations/0126_artifact_drop_public.sql +8 -0
- package/migrations/0127_artifact_path.sql +4 -0
- package/migrations/0128_artifact_path_index.sql +1 -0
- package/migrations/0129_review_item_answered_index.sql +1 -0
- package/migrations/0130_review_item_status_index.sql +1 -0
- package/migrations/0131_brief_outcome_status.sql +1 -0
- package/migrations/0132_brief_outcome_status_backfill.sql +7 -0
- package/migrations/0133_brief_created_at_index.sql +1 -0
- package/migrations/0134_slack_person_search_index.sql +1 -0
- package/migrations/0135_code_change_size.sql +3 -0
- package/migrations/0136_merge_conflict_notice_dismiss.sql +16 -0
- package/migrations/0137_inbox_snoozes.sql +27 -0
- package/migrations/0138_code_change_search_index.sql +2 -0
- package/migrations/0139_review_item_owner.sql +22 -0
- package/migrations/0140_review_item_owner_index.sql +1 -0
- package/migrations/0141_memory_core_adoption.sql +89 -0
- package/migrations/0142_memory_core_indexes.sql +17 -0
- package/migrations/0143_todos.sql +14 -0
- package/migrations/0144_inbox_items.sql +32 -0
- package/migrations/0145_todo_changed_by_agent.sql +1 -0
- package/migrations/0146_inbox_item_subject_title_parts.sql +1 -0
- package/migrations/0147_inbox_snooze_wake_reason.sql +1 -0
- package/migrations/0148_authorization_request_index.sql +1 -0
- package/migrations/0149_conversation_metadata.sql +10 -0
- package/migrations/0150_conversation_metadata_fill.sql +39 -0
- package/migrations/0151_conversation_search_index.sql +1 -0
- package/migrations/0152_inbox_item_legacy_automation_keys.sql +21 -0
- package/migrations/0153_artifact_expiry.sql +1 -0
- package/migrations/0154_artifact_permanent_sha_index.sql +1 -0
- package/migrations/0155_artifact_drop_public_sha_index.sql +3 -0
- package/migrations/0156_conversation_kind_lead.sql +6 -0
- package/migrations/0157_conversation_lead_actor_index.sql +1 -0
- package/migrations/meta/0126_snapshot.json +5488 -0
- package/migrations/meta/0127_snapshot.json +5519 -0
- package/migrations/meta/0128_snapshot.json +5519 -0
- package/migrations/meta/0129_snapshot.json +5547 -0
- package/migrations/meta/0130_snapshot.json +5563 -0
- package/migrations/meta/0131_snapshot.json +5569 -0
- package/migrations/meta/0132_snapshot.json +5569 -0
- package/migrations/meta/0133_snapshot.json +5590 -0
- package/migrations/meta/0134_snapshot.json +5606 -0
- package/migrations/meta/0135_snapshot.json +5624 -0
- package/migrations/meta/0136_snapshot.json +5624 -0
- package/migrations/meta/0137_snapshot.json +5864 -0
- package/migrations/meta/0138_snapshot.json +5894 -0
- package/migrations/meta/0139_snapshot.json +5898 -0
- package/migrations/meta/0140_snapshot.json +5919 -0
- package/migrations/meta/0141_snapshot.json +6429 -0
- package/migrations/meta/0142_snapshot.json +6457 -0
- package/migrations/meta/0143_snapshot.json +6434 -0
- package/migrations/meta/0144_snapshot.json +6434 -0
- package/migrations/meta/0145_snapshot.json +6440 -0
- package/migrations/meta/0146_snapshot.json +6446 -0
- package/migrations/meta/0147_snapshot.json +6452 -0
- package/migrations/meta/0148_snapshot.json +6474 -0
- package/migrations/meta/0149_snapshot.json +6490 -0
- package/migrations/meta/0150_snapshot.json +6490 -0
- package/migrations/meta/0151_snapshot.json +6505 -0
- package/migrations/meta/0152_snapshot.json +6505 -0
- package/migrations/meta/0153_snapshot.json +6511 -0
- package/migrations/meta/0154_snapshot.json +6533 -0
- package/migrations/meta/0155_snapshot.json +6511 -0
- package/migrations/meta/0156_snapshot.json +6511 -0
- package/migrations/meta/0157_snapshot.json +6527 -0
- package/migrations/meta/_journal.json +224 -0
- package/package.json +7 -8
- package/skills/design-automation-skill/SKILL.md +108 -0
- package/dist/briefs-DKxkoruh.js +0 -395
- package/dist/conversation-M9KZ5JxF.js +0 -1024
- package/dist/prompt-CaMyeCpA.js +0 -910
- package/dist/schedule-DWxZ3kja.js +0 -1146
- package/dist/store-D4FQ1Nml.js +0 -335
- package/dist/task-runner-Dm7BHbGp.js +0 -287
- package/dist/turn-session-routing-CD0BRCex.js +0 -263
- package/dist/turn-user-message-9IxeEv5v.js +0 -364
- package/dist/users-CaUAYMb3.js +0 -181
- package/dist/viewer-AHldghAD.js +0 -212
- package/dist/web-message-id-BT8Mg8LL.js +0 -418
|
@@ -1,1146 +0,0 @@
|
|
|
1
|
-
import { i as actorIdentitySchema } from "./conversation-M9KZ5JxF.js";
|
|
2
|
-
import * as z from "zod";
|
|
3
|
-
import { actorUserIdSchema, destinationVisibilitySchema, eventMatchFieldsSchema, eventMatchSchema, eventReachSchema, eventTypeSchema, pluginEventTypeSchema, slackDestinationSchema, taskOutcomeSchema } from "@sentry/junior-plugin-api";
|
|
4
|
-
// src/chat/automations/task.ts
|
|
5
|
-
/**
|
|
6
|
-
* The work of an Automation run. An Automation runs either a written
|
|
7
|
-
* instruction or a skill. A skill can have context: what the Automation
|
|
8
|
-
* needs beyond the skill.
|
|
9
|
-
*/
|
|
10
|
-
/** A skill name, in the form that skill frontmatter allows. */
|
|
11
|
-
const automationSkillNameSchema = z.string().max(64).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Use a skill name, such as tpm.");
|
|
12
|
-
/** Text of an instruction or a context, trimmed and not empty. */
|
|
13
|
-
const automationTaskTextSchema = z.string().trim().min(1, "Write at least one word.").max(4e3);
|
|
14
|
-
/** Validate the stored task of either Automation kind. */
|
|
15
|
-
const automationTaskSchema = z.discriminatedUnion("kind", [z.object({
|
|
16
|
-
kind: z.literal("instruction"),
|
|
17
|
-
instruction: automationTaskTextSchema
|
|
18
|
-
}).strict(), z.object({
|
|
19
|
-
kind: z.literal("skill"),
|
|
20
|
-
skill: automationSkillNameSchema,
|
|
21
|
-
/** Absent when the skill needs nothing more. */
|
|
22
|
-
context: automationTaskTextSchema.optional()
|
|
23
|
-
}).strict()]);
|
|
24
|
-
/** Return the written text of a task: its instruction or its context. */
|
|
25
|
-
function automationTaskText(task) {
|
|
26
|
-
return task.kind === "instruction" ? task.instruction : task.context;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Describe the work in one plain text for title fallback, title generation,
|
|
30
|
-
* and cards, so a skill-mode Automation shows its skill. Do not store it.
|
|
31
|
-
*/
|
|
32
|
-
function automationTaskDescription(task) {
|
|
33
|
-
if (task.kind === "instruction") return task.instruction;
|
|
34
|
-
return task.context ? `Run the ${task.skill} skill. ${task.context}` : `Run the ${task.skill} skill.`;
|
|
35
|
-
}
|
|
36
|
-
/** Return the `instruction` and `skill` columns of a task. One is null. */
|
|
37
|
-
function automationTaskColumns(task) {
|
|
38
|
-
return task.kind === "instruction" ? {
|
|
39
|
-
instruction: task.instruction,
|
|
40
|
-
skill: null
|
|
41
|
-
} : {
|
|
42
|
-
instruction: null,
|
|
43
|
-
skill: task.skill
|
|
44
|
-
};
|
|
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
|
-
}
|
|
300
|
-
// src/chat/scheduled-automations/schedule-intent.ts
|
|
301
|
-
/**
|
|
302
|
-
* Owns model-facing schedule intent and materializes it against the trusted
|
|
303
|
-
* server clock into the canonical schedule persisted by core.
|
|
304
|
-
*/
|
|
305
|
-
const localDateSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Use a local date in YYYY-MM-DD format.");
|
|
306
|
-
const localTimeSchema = z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "Use local time in HH:MM format.");
|
|
307
|
-
const timezoneSchema = z.string().min(1).max(80).describe("IANA timezone the user asked for, for example America/New_York. Omit or use null to use the creator's timezone on create, or to keep the saved timezone on update. Do not guess it from office locations.").nullable().optional();
|
|
308
|
-
/** Weekday names in `Date#getDay` order. */
|
|
309
|
-
const weekdaySchema = z.enum([
|
|
310
|
-
"sunday",
|
|
311
|
-
"monday",
|
|
312
|
-
"tuesday",
|
|
313
|
-
"wednesday",
|
|
314
|
-
"thursday",
|
|
315
|
-
"friday",
|
|
316
|
-
"saturday"
|
|
317
|
-
]);
|
|
318
|
-
const oneOffScheduleIntentSchema = z.object({
|
|
319
|
-
kind: z.literal("one_off").describe("A schedule that runs once."),
|
|
320
|
-
timezone: timezoneSchema,
|
|
321
|
-
timing: z.discriminatedUnion("type", [z.object({
|
|
322
|
-
type: z.literal("after").describe("Run after a relative delay from the server clock."),
|
|
323
|
-
value: z.number().int().positive().max(1e5),
|
|
324
|
-
unit: z.enum([
|
|
325
|
-
"second",
|
|
326
|
-
"minute",
|
|
327
|
-
"hour",
|
|
328
|
-
"day",
|
|
329
|
-
"week"
|
|
330
|
-
])
|
|
331
|
-
}).strict(), z.object({
|
|
332
|
-
type: z.literal("at").describe("Run at an explicit local calendar date and time."),
|
|
333
|
-
date: localDateSchema.describe("Requested local calendar date in YYYY-MM-DD format."),
|
|
334
|
-
time: localTimeSchema.describe("Requested local wall-clock time in HH:MM format.")
|
|
335
|
-
}).strict()]).describe("Relative delay or explicit local time for the one-off run.")
|
|
336
|
-
}).strict();
|
|
337
|
-
const recurringScheduleFields = {
|
|
338
|
-
kind: z.literal("recurring").describe("A repeating calendar schedule."),
|
|
339
|
-
frequency: z.enum([
|
|
340
|
-
"daily",
|
|
341
|
-
"weekly",
|
|
342
|
-
"monthly",
|
|
343
|
-
"yearly"
|
|
344
|
-
]).describe("Recurring tasks can run at most once per day."),
|
|
345
|
-
interval: z.number().int().positive().max(365).describe("Repeat every N frequency units. Defaults to 1.").nullable().optional(),
|
|
346
|
-
time: localTimeSchema.describe("Local wall-clock time for each occurrence in HH:MM format."),
|
|
347
|
-
weekdays: z.array(weekdaySchema).min(1).max(7).describe("Required for weekly schedules.").nullable().optional(),
|
|
348
|
-
month: z.number().int().min(1).max(12).describe("Required for yearly schedules, where January is 1.").nullable().optional(),
|
|
349
|
-
timezone: timezoneSchema
|
|
350
|
-
};
|
|
351
|
-
const dayOfMonthSchema = z.number().int().min(1).max(31).describe("Required for monthly and yearly schedules.").nullable().optional();
|
|
352
|
-
const startDateSchema = localDateSchema.describe("Optional local calendar date that anchors the recurrence. Omit to start with the next matching occurrence.").nullable().optional();
|
|
353
|
-
function checkRecurringSchedule(schedule, dayOfMonth, context) {
|
|
354
|
-
if (schedule.frequency === "weekly" && schedule.weekdays == null) context.addIssue({
|
|
355
|
-
code: "custom",
|
|
356
|
-
message: "Weekly schedules require weekdays.",
|
|
357
|
-
path: ["weekdays"]
|
|
358
|
-
});
|
|
359
|
-
if ((schedule.frequency === "monthly" || schedule.frequency === "yearly") && dayOfMonth.value == null) context.addIssue({
|
|
360
|
-
code: "custom",
|
|
361
|
-
message: `${schedule.frequency} schedules require ${dayOfMonth.key}.`,
|
|
362
|
-
path: [dayOfMonth.key]
|
|
363
|
-
});
|
|
364
|
-
if (schedule.frequency === "yearly" && schedule.month == null) context.addIssue({
|
|
365
|
-
code: "custom",
|
|
366
|
-
message: "Yearly schedules require month.",
|
|
367
|
-
path: ["month"]
|
|
368
|
-
});
|
|
369
|
-
if (schedule.frequency !== "weekly" && schedule.weekdays != null) context.addIssue({
|
|
370
|
-
code: "custom",
|
|
371
|
-
message: "weekdays applies only to weekly schedules.",
|
|
372
|
-
path: ["weekdays"]
|
|
373
|
-
});
|
|
374
|
-
if (schedule.frequency !== "monthly" && schedule.frequency !== "yearly" && dayOfMonth.value != null) context.addIssue({
|
|
375
|
-
code: "custom",
|
|
376
|
-
message: `${dayOfMonth.key} applies only to monthly or yearly schedules.`,
|
|
377
|
-
path: [dayOfMonth.key]
|
|
378
|
-
});
|
|
379
|
-
if (schedule.frequency !== "yearly" && schedule.month != null) context.addIssue({
|
|
380
|
-
code: "custom",
|
|
381
|
-
message: "month applies only to yearly schedules.",
|
|
382
|
-
path: ["month"]
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
const recurringScheduleIntentSchema = z.object({
|
|
386
|
-
...recurringScheduleFields,
|
|
387
|
-
dayOfMonth: dayOfMonthSchema,
|
|
388
|
-
startDate: startDateSchema
|
|
389
|
-
}).strict().superRefine((schedule, context) => checkRecurringSchedule(schedule, {
|
|
390
|
-
key: "dayOfMonth",
|
|
391
|
-
value: schedule.dayOfMonth
|
|
392
|
-
}, context));
|
|
393
|
-
const recurringToolScheduleIntentSchema = z.object({
|
|
394
|
-
...recurringScheduleFields,
|
|
395
|
-
day_of_month: dayOfMonthSchema,
|
|
396
|
-
start_date: startDateSchema
|
|
397
|
-
}).strict().superRefine((schedule, context) => checkRecurringSchedule(schedule, {
|
|
398
|
-
key: "day_of_month",
|
|
399
|
-
value: schedule.day_of_month
|
|
400
|
-
}, context));
|
|
401
|
-
const scheduleIntentSchema = z.union([oneOffScheduleIntentSchema, recurringScheduleIntentSchema]);
|
|
402
|
-
/** Model-facing schedule intent of the Automation tools. */
|
|
403
|
-
const toolScheduleIntentSchema = z.union([oneOffScheduleIntentSchema, recurringToolScheduleIntentSchema]);
|
|
404
|
-
/** Map a tool schedule intent to the shape that core compiles and saves. */
|
|
405
|
-
function scheduleIntentFromTool(intent) {
|
|
406
|
-
if (intent.kind === "one_off") return intent;
|
|
407
|
-
const { day_of_month, start_date, ...rest } = intent;
|
|
408
|
-
return {
|
|
409
|
-
...rest,
|
|
410
|
-
dayOfMonth: day_of_month,
|
|
411
|
-
startDate: start_date
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
const WEEKDAY_INDEX = {
|
|
415
|
-
sunday: 0,
|
|
416
|
-
monday: 1,
|
|
417
|
-
tuesday: 2,
|
|
418
|
-
wednesday: 3,
|
|
419
|
-
thursday: 4,
|
|
420
|
-
friday: 5,
|
|
421
|
-
saturday: 6
|
|
422
|
-
};
|
|
423
|
-
const DURATION_MS = {
|
|
424
|
-
second: 1e3,
|
|
425
|
-
minute: 6e4,
|
|
426
|
-
hour: 36e5,
|
|
427
|
-
day: 864e5,
|
|
428
|
-
week: 6048e5
|
|
429
|
-
};
|
|
430
|
-
function parseLocalTime(value) {
|
|
431
|
-
const [hour, minute] = value.split(":").map(Number);
|
|
432
|
-
return {
|
|
433
|
-
hour,
|
|
434
|
-
minute
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
function localDateAt(timestampMs, timezone) {
|
|
438
|
-
const parts = getZonedDateTimeParts(timestampMs, timezone);
|
|
439
|
-
return [
|
|
440
|
-
parts.year,
|
|
441
|
-
parts.month,
|
|
442
|
-
parts.day
|
|
443
|
-
].map((value, index) => index === 0 ? String(value).padStart(4, "0") : String(value).padStart(2, "0")).join("-");
|
|
444
|
-
}
|
|
445
|
-
function plural(value, unit) {
|
|
446
|
-
return value === 1 ? unit : `${unit}s`;
|
|
447
|
-
}
|
|
448
|
-
function formatWeekdays(weekdays) {
|
|
449
|
-
const labels = weekdays.map((weekday) => `${weekday[0].toUpperCase()}${weekday.slice(1)}`);
|
|
450
|
-
if (labels.length < 2) return labels[0] ?? "";
|
|
451
|
-
return `${labels.slice(0, -1).join(", ")} and ${labels.at(-1)}`;
|
|
452
|
-
}
|
|
453
|
-
function recurringDescription(schedule, timezone) {
|
|
454
|
-
const interval = schedule.interval ?? 1;
|
|
455
|
-
const cadenceUnit = {
|
|
456
|
-
daily: "day",
|
|
457
|
-
weekly: "week",
|
|
458
|
-
monthly: "month",
|
|
459
|
-
yearly: "year"
|
|
460
|
-
}[schedule.frequency];
|
|
461
|
-
const cadence = interval === 1 ? cadenceUnit : `${interval} ${cadenceUnit}s`;
|
|
462
|
-
let detail = "";
|
|
463
|
-
if (schedule.frequency === "weekly") detail = ` on ${formatWeekdays(schedule.weekdays)}`;
|
|
464
|
-
else if (schedule.frequency === "monthly") detail = ` on day ${schedule.dayOfMonth}`;
|
|
465
|
-
else if (schedule.frequency === "yearly") detail = ` on ${String(schedule.month).padStart(2, "0")}-${String(schedule.dayOfMonth).padStart(2, "0")}`;
|
|
466
|
-
return `Every ${cadence}${detail} at ${schedule.time} (${timezone})`;
|
|
467
|
-
}
|
|
468
|
-
var ScheduleIntentError = class extends Error {};
|
|
469
|
-
/** Materialize model-interpreted schedule intent against the trusted server clock. */
|
|
470
|
-
function compileScheduleIntent(args) {
|
|
471
|
-
const timezone = args.intent.timezone ?? args.defaultTimezone;
|
|
472
|
-
if (!isValidTimeZone(timezone)) throw new ScheduleIntentError("timezone must be a valid IANA time zone.");
|
|
473
|
-
if (args.intent.kind === "one_off") {
|
|
474
|
-
if (args.intent.timing.type === "after") return {
|
|
475
|
-
nextRunAtMs: args.nowMs + args.intent.timing.value * DURATION_MS[args.intent.timing.unit],
|
|
476
|
-
schedule: {
|
|
477
|
-
description: `In ${args.intent.timing.value} ${plural(args.intent.timing.value, args.intent.timing.unit)}`,
|
|
478
|
-
kind: "one_off",
|
|
479
|
-
timezone
|
|
480
|
-
}
|
|
481
|
-
};
|
|
482
|
-
const nextRunAtMs = resolveLocalScheduleAtMs({
|
|
483
|
-
date: args.intent.timing.date,
|
|
484
|
-
time: parseLocalTime(args.intent.timing.time),
|
|
485
|
-
timezone
|
|
486
|
-
});
|
|
487
|
-
if (nextRunAtMs === void 0) throw new ScheduleIntentError("The requested local date or time does not exist in that timezone.");
|
|
488
|
-
if (nextRunAtMs <= args.nowMs) throw new ScheduleIntentError("The requested one-off schedule must be in the future.");
|
|
489
|
-
return {
|
|
490
|
-
nextRunAtMs,
|
|
491
|
-
schedule: {
|
|
492
|
-
description: `Once on ${args.intent.timing.date} at ${args.intent.timing.time} (${timezone})`,
|
|
493
|
-
kind: "one_off",
|
|
494
|
-
timezone
|
|
495
|
-
}
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
const recurrence = {
|
|
499
|
-
frequency: args.intent.frequency,
|
|
500
|
-
interval: args.intent.interval ?? 1,
|
|
501
|
-
startDate: args.intent.startDate ?? localDateAt(args.nowMs, timezone),
|
|
502
|
-
time: parseLocalTime(args.intent.time),
|
|
503
|
-
...args.intent.frequency === "weekly" ? { weekdays: [...new Set(args.intent.weekdays.map((weekday) => WEEKDAY_INDEX[weekday]))].sort((left, right) => left - right) } : void 0,
|
|
504
|
-
...args.intent.frequency === "monthly" || args.intent.frequency === "yearly" ? { dayOfMonth: args.intent.dayOfMonth ?? void 0 } : void 0,
|
|
505
|
-
...args.intent.frequency === "yearly" ? { month: args.intent.month ?? void 0 } : void 0
|
|
506
|
-
};
|
|
507
|
-
const searchRecurrence = args.intent.startDate ? recurrence : {
|
|
508
|
-
...recurrence,
|
|
509
|
-
interval: 1
|
|
510
|
-
};
|
|
511
|
-
const nextRunAtMs = getFirstRunAtMs({
|
|
512
|
-
afterMs: args.nowMs,
|
|
513
|
-
recurrence: searchRecurrence,
|
|
514
|
-
timezone
|
|
515
|
-
});
|
|
516
|
-
if (nextRunAtMs === void 0) throw new ScheduleIntentError("The recurring schedule has no valid future occurrence.");
|
|
517
|
-
const materializedRecurrence = args.intent.startDate ? recurrence : {
|
|
518
|
-
...recurrence,
|
|
519
|
-
startDate: localDateAt(nextRunAtMs, timezone)
|
|
520
|
-
};
|
|
521
|
-
return {
|
|
522
|
-
nextRunAtMs,
|
|
523
|
-
schedule: {
|
|
524
|
-
description: recurringDescription(args.intent, timezone),
|
|
525
|
-
kind: "recurring",
|
|
526
|
-
recurrence: materializedRecurrence,
|
|
527
|
-
timezone
|
|
528
|
-
}
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
// src/chat/scheduled-automations/types.ts
|
|
532
|
-
/** Durable scheduled-automation domain types owned by Junior core. */
|
|
533
|
-
const scheduledAutomationStatusSchema = z.enum([
|
|
534
|
-
"active",
|
|
535
|
-
"blocked",
|
|
536
|
-
"paused",
|
|
537
|
-
"completed",
|
|
538
|
-
"deleted"
|
|
539
|
-
]);
|
|
540
|
-
const scheduledAutomationCredentialModeSchema = z.enum(["system", "creator"]);
|
|
541
|
-
const scheduledRunStatusSchema = z.enum([
|
|
542
|
-
"pending",
|
|
543
|
-
"running",
|
|
544
|
-
"completed",
|
|
545
|
-
"failed",
|
|
546
|
-
"blocked",
|
|
547
|
-
"skipped"
|
|
548
|
-
]);
|
|
549
|
-
const scheduledAutomationPrincipalSchema = z.object({
|
|
550
|
-
slackUserId: actorUserIdSchema,
|
|
551
|
-
fullName: z.string().optional(),
|
|
552
|
-
userName: z.string().optional()
|
|
553
|
-
}).strict();
|
|
554
|
-
const scheduledAutomationRecurrenceSchema = z.object({
|
|
555
|
-
dayOfMonth: z.number().optional(),
|
|
556
|
-
frequency: z.enum([
|
|
557
|
-
"daily",
|
|
558
|
-
"weekly",
|
|
559
|
-
"monthly",
|
|
560
|
-
"yearly"
|
|
561
|
-
]),
|
|
562
|
-
interval: z.number(),
|
|
563
|
-
month: z.number().optional(),
|
|
564
|
-
startDate: z.string(),
|
|
565
|
-
time: z.object({
|
|
566
|
-
hour: z.number(),
|
|
567
|
-
minute: z.number()
|
|
568
|
-
}).strict(),
|
|
569
|
-
weekdays: z.array(z.number()).optional()
|
|
570
|
-
}).strict();
|
|
571
|
-
const scheduledAutomationScheduleSchema = z.object({
|
|
572
|
-
description: z.string(),
|
|
573
|
-
kind: z.enum(["one_off", "recurring"]),
|
|
574
|
-
recurrence: scheduledAutomationRecurrenceSchema.optional(),
|
|
575
|
-
timezone: z.string()
|
|
576
|
-
}).strict();
|
|
577
|
-
const scheduledAutomationExecutionActorSchema = z.object({
|
|
578
|
-
platform: z.literal("system"),
|
|
579
|
-
name: z.string()
|
|
580
|
-
}).strict();
|
|
581
|
-
/** Scheduled automations target a Slack conversation, never one message thread. */
|
|
582
|
-
const scheduledAutomationDestinationSchema = slackDestinationSchema.omit({ threadTs: true });
|
|
583
|
-
const scheduledAutomationOutcomeSchema = z.object({
|
|
584
|
-
action: z.literal("send_message"),
|
|
585
|
-
destination: scheduledAutomationDestinationSchema
|
|
586
|
-
}).strict();
|
|
587
|
-
/** Validate the current scheduled-automation domain shape. */
|
|
588
|
-
const scheduledAutomationSchema = z.object({
|
|
589
|
-
id: z.string(),
|
|
590
|
-
conversationAccess: z.object({
|
|
591
|
-
audience: z.enum([
|
|
592
|
-
"direct",
|
|
593
|
-
"group",
|
|
594
|
-
"channel"
|
|
595
|
-
]),
|
|
596
|
-
visibility: z.enum(["private", "public"])
|
|
597
|
-
}).strict(),
|
|
598
|
-
createdAtMs: z.number(),
|
|
599
|
-
createdBy: scheduledAutomationPrincipalSchema,
|
|
600
|
-
/** Authoritative provider identity that created the task. */
|
|
601
|
-
creatorIdentityId: z.string(),
|
|
602
|
-
/** Selects system credentials or task-bound creator credential delegation. */
|
|
603
|
-
credentialMode: scheduledAutomationCredentialModeSchema,
|
|
604
|
-
destination: scheduledAutomationDestinationSchema,
|
|
605
|
-
executionActor: scheduledAutomationExecutionActorSchema.optional(),
|
|
606
|
-
lastRunAtMs: z.number().optional(),
|
|
607
|
-
nextRunAtMs: z.number().optional(),
|
|
608
|
-
originalRequest: z.string().optional(),
|
|
609
|
-
runNowAtMs: z.number().optional(),
|
|
610
|
-
schedule: scheduledAutomationScheduleSchema,
|
|
611
|
-
status: scheduledAutomationStatusSchema,
|
|
612
|
-
statusReason: z.string().optional(),
|
|
613
|
-
/** Explicit visible effects after successful work. An empty list is silent. */
|
|
614
|
-
outcomes: z.array(scheduledAutomationOutcomeSchema).max(5),
|
|
615
|
-
task: automationTaskSchema,
|
|
616
|
-
/** SQL-backed short display title generated from the task instruction. */
|
|
617
|
-
title: z.string().optional(),
|
|
618
|
-
updatedAtMs: z.number()
|
|
619
|
-
}).strict();
|
|
620
|
-
/** Validate the current scheduled-run domain shape. */
|
|
621
|
-
const scheduledRunSchema = z.object({
|
|
622
|
-
id: z.string(),
|
|
623
|
-
attempt: z.number(),
|
|
624
|
-
claimedAtMs: z.number(),
|
|
625
|
-
completedAtMs: z.number().optional(),
|
|
626
|
-
dispatchId: z.string().optional(),
|
|
627
|
-
errorMessage: z.string().optional(),
|
|
628
|
-
resultMessageTs: z.string().optional(),
|
|
629
|
-
scheduledForMs: z.number(),
|
|
630
|
-
startedAtMs: z.number().optional(),
|
|
631
|
-
status: scheduledRunStatusSchema,
|
|
632
|
-
taskId: z.string()
|
|
633
|
-
}).strict();
|
|
634
|
-
const SCHEDULED_AUTOMATION_SYSTEM_ACTOR = Object.freeze({
|
|
635
|
-
platform: "system",
|
|
636
|
-
name: "scheduled-automation"
|
|
637
|
-
});
|
|
638
|
-
/** Validate the persisted Slack creator identity for an event automation. */
|
|
639
|
-
const eventAutomationPrincipalSchema = z.object({
|
|
640
|
-
slackUserId: actorUserIdSchema,
|
|
641
|
-
fullName: z.string().optional(),
|
|
642
|
-
userName: z.string().optional()
|
|
643
|
-
}).strict();
|
|
644
|
-
/**
|
|
645
|
-
* Validate one persisted event-automation selector and its presentation
|
|
646
|
-
* metadata. A trigger names one resource with a resource type and an
|
|
647
|
-
* identifier, or it names neither. With neither, it runs for every resource
|
|
648
|
-
* of the namespace that its filters match.
|
|
649
|
-
*/
|
|
650
|
-
const eventAutomationTriggerSchema = z.object({
|
|
651
|
-
events: z.array(eventTypeSchema).min(1),
|
|
652
|
-
label: z.string().min(1),
|
|
653
|
-
match: eventMatchSchema.optional(),
|
|
654
|
-
namespace: z.string().min(1),
|
|
655
|
-
identifier: z.string().min(1).max(300).optional(),
|
|
656
|
-
resourceType: z.string().min(1).optional()
|
|
657
|
-
}).strict().refine((trigger) => trigger.identifier === void 0 === (trigger.resourceType === void 0), {
|
|
658
|
-
message: "Set both a resource type and an identifier, or leave out both to run for every resource.",
|
|
659
|
-
path: ["identifier"]
|
|
660
|
-
});
|
|
661
|
-
/** Event automations target a Slack channel or DM, never a message thread. */
|
|
662
|
-
const eventAutomationDestinationSchema = slackDestinationSchema.omit({ threadTs: true });
|
|
663
|
-
const eventAutomationOutcomeSchema = taskOutcomeSchema.extend({ destination: eventAutomationDestinationSchema });
|
|
664
|
-
/** Validate one persisted event automation. */
|
|
665
|
-
const eventAutomationSchema = z.object({
|
|
666
|
-
id: z.string().min(1),
|
|
667
|
-
createdAtMs: z.number().finite(),
|
|
668
|
-
createdBy: eventAutomationPrincipalSchema,
|
|
669
|
-
/** Junior identity that created the automation. It decides ownership. */
|
|
670
|
-
creatorIdentityId: z.string().min(1),
|
|
671
|
-
credentialMode: z.enum(["system", "creator"]),
|
|
672
|
-
destination: eventAutomationDestinationSchema,
|
|
673
|
-
destinationVisibility: destinationVisibilitySchema,
|
|
674
|
-
/** Explicit visible effects after successful work. An empty list is silent. */
|
|
675
|
-
outcomes: z.array(eventAutomationOutcomeSchema).max(5),
|
|
676
|
-
task: automationTaskSchema,
|
|
677
|
-
trigger: eventAutomationTriggerSchema
|
|
678
|
-
}).strict();
|
|
679
|
-
// src/chat/task-outcomes-schema.ts
|
|
680
|
-
const taskMessageDestinationInputSchema = z.enum(["current_conversation", "task_creator"]).describe("Where to send the message. Use current_conversation for posts, digests, summaries, and channel reminders. Use task_creator only when the user asks for a direct reminder or notification.");
|
|
681
|
-
/** Input accepted by task authoring tools before a user becomes a DM Destination. */
|
|
682
|
-
const taskOutcomeInputSchema = z.object({
|
|
683
|
-
action: z.literal("send_message"),
|
|
684
|
-
destination: taskMessageDestinationInputSchema
|
|
685
|
-
}).strict();
|
|
686
|
-
// src/chat/automations/edit-schema.ts
|
|
687
|
-
const automationTitleSchema = z.string().trim().min(1).max(60);
|
|
688
|
-
/**
|
|
689
|
-
* Instruction input for agent tools. The run does not see the request, so the
|
|
690
|
-
* instruction names exact targets. It calls the creator "the Automation
|
|
691
|
-
* creator". It names every other person with their mention, also a requester
|
|
692
|
-
* who says "me".
|
|
693
|
-
*/
|
|
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.");
|
|
695
|
-
/** Context input for agent tools. It follows the same rules as an instruction. */
|
|
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>.");
|
|
697
|
-
const automationEditFieldsSchema = z.object({
|
|
698
|
-
title: automationTitleSchema.optional(),
|
|
699
|
-
/** Replaces the whole task, so a mode switch drops the other mode's text. */
|
|
700
|
-
task: automationTaskSchema.optional(),
|
|
701
|
-
credentialMode: z.enum(["system", "creator"]).optional(),
|
|
702
|
-
outcomes: z.array(z.union([taskOutcomeInputSchema, taskOutcomeSchema])).max(5).optional()
|
|
703
|
-
});
|
|
704
|
-
const scheduledAutomationEditSchema = automationEditFieldsSchema.extend({ schedule: scheduleIntentSchema.optional() }).strict();
|
|
705
|
-
const eventAutomationEditSchema = automationEditFieldsSchema.extend({ trigger: eventAutomationTriggerSchema.safeExtend({
|
|
706
|
-
identifier: z.string().trim().min(1).max(300).optional(),
|
|
707
|
-
label: z.string().trim().min(1).max(500)
|
|
708
|
-
}).optional() }).strict();
|
|
709
|
-
// src/api/schema/automation.ts
|
|
710
|
-
const automationDestinationSchema = z.object({
|
|
711
|
-
channelId: z.string().min(1),
|
|
712
|
-
label: z.string().min(1),
|
|
713
|
-
teamId: z.string().min(1),
|
|
714
|
-
visibility: z.enum(["private", "public"])
|
|
715
|
-
}).strict();
|
|
716
|
-
/** Automation run counts for the dashboard range control (24h/7d/30d/90d). */
|
|
717
|
-
const automationRunWindowsSchema = z.object({
|
|
718
|
-
1: z.number().int().nonnegative(),
|
|
719
|
-
7: z.number().int().nonnegative(),
|
|
720
|
-
30: z.number().int().nonnegative(),
|
|
721
|
-
90: z.number().int().nonnegative()
|
|
722
|
-
}).strict();
|
|
723
|
-
/** Linked Conversation cost in USD for each dashboard range. */
|
|
724
|
-
const automationCostWindowsSchema = z.object({
|
|
725
|
-
1: z.number().finite().nonnegative(),
|
|
726
|
-
7: z.number().finite().nonnegative(),
|
|
727
|
-
30: z.number().finite().nonnegative(),
|
|
728
|
-
90: z.number().finite().nonnegative()
|
|
729
|
-
}).strict();
|
|
730
|
-
const automationSummaryBaseSchema = z.object({
|
|
731
|
-
costUsd: automationCostWindowsSchema,
|
|
732
|
-
credentialMode: z.enum(["creator", "system"]),
|
|
733
|
-
createdAt: z.string().datetime(),
|
|
734
|
-
createdBy: z.string().min(1),
|
|
735
|
-
createdByAvatarUrl: z.string().optional(),
|
|
736
|
-
createdByEmail: z.string().trim().email().optional(),
|
|
737
|
-
destination: automationDestinationSchema,
|
|
738
|
-
id: z.string().min(1),
|
|
739
|
-
task: automationTaskSchema,
|
|
740
|
-
/** People mentioned in the task text, resolved at read time. */
|
|
741
|
-
mentions: z.array(actorIdentitySchema).optional(),
|
|
742
|
-
lastConversationId: z.string().min(1).optional(),
|
|
743
|
-
lastRunAt: z.string().datetime().optional(),
|
|
744
|
-
lastRunStatus: z.enum([
|
|
745
|
-
"blocked",
|
|
746
|
-
"completed",
|
|
747
|
-
"failed"
|
|
748
|
-
]).optional(),
|
|
749
|
-
ownedByViewer: z.boolean(),
|
|
750
|
-
/** Newest terminal runs, oldest first, so the list can show recent health. */
|
|
751
|
-
recentRuns: z.array(z.object({
|
|
752
|
-
durationMs: z.number().finite().nonnegative().optional(),
|
|
753
|
-
executedAt: z.string().datetime(),
|
|
754
|
-
status: z.enum([
|
|
755
|
-
"blocked",
|
|
756
|
-
"completed",
|
|
757
|
-
"failed"
|
|
758
|
-
])
|
|
759
|
-
}).strict()).max(20),
|
|
760
|
-
runs: automationRunWindowsSchema,
|
|
761
|
-
outcomes: z.array(taskOutcomeSchema).max(5),
|
|
762
|
-
/** Short display title; falls back from the task when unset. */
|
|
763
|
-
title: z.string().min(1),
|
|
764
|
-
/** Linked Conversation cost of every run, since the Automation was created. */
|
|
765
|
-
totalCostUsd: z.number().finite().nonnegative(),
|
|
766
|
-
totalRuns: z.number().int().nonnegative()
|
|
767
|
-
});
|
|
768
|
-
const scheduledAutomationSummarySchema = automationSummaryBaseSchema.extend({
|
|
769
|
-
kind: z.literal("scheduled"),
|
|
770
|
-
nextRunAt: z.string().datetime().optional(),
|
|
771
|
-
schedule: z.string().min(1),
|
|
772
|
-
timezone: z.string().min(1),
|
|
773
|
-
statusReason: z.string().optional(),
|
|
774
|
-
status: z.enum([
|
|
775
|
-
"active",
|
|
776
|
-
"blocked",
|
|
777
|
-
"paused",
|
|
778
|
-
"completed"
|
|
779
|
-
])
|
|
780
|
-
}).strict();
|
|
781
|
-
/** An Event trigger in plain words, the same in the dashboard and Slack. */
|
|
782
|
-
const eventTriggerDescriptionSchema = z.object({
|
|
783
|
-
events: z.array(z.string().min(1)).min(1),
|
|
784
|
-
filters: z.array(z.string().min(1)),
|
|
785
|
-
/** Why the trigger cannot work. The trigger is available when empty. */
|
|
786
|
-
problems: z.array(z.string().min(1))
|
|
787
|
-
}).strict();
|
|
788
|
-
const eventAutomationSummarySchema = automationSummaryBaseSchema.extend({
|
|
789
|
-
trigger: eventTriggerDescriptionSchema,
|
|
790
|
-
kind: z.literal("event"),
|
|
791
|
-
resource: z.string().min(1),
|
|
792
|
-
source: z.string().min(1),
|
|
793
|
-
statusReason: z.string().optional(),
|
|
794
|
-
status: z.enum([
|
|
795
|
-
"active",
|
|
796
|
-
"blocked",
|
|
797
|
-
"paused"
|
|
798
|
-
])
|
|
799
|
-
}).strict();
|
|
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)]);
|
|
813
|
-
/** UTC day (`YYYY-MM-DD`) or hour (`YYYY-MM-DDTHH`) execution bucket key. */
|
|
814
|
-
const automationMetricBucketSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}(T\d{2})?$/);
|
|
815
|
-
const automationListQuerySchema = z.object({
|
|
816
|
-
q: z.string().trim().max(200).optional(),
|
|
817
|
-
scope: z.enum([
|
|
818
|
-
"all",
|
|
819
|
-
"mine",
|
|
820
|
-
"public",
|
|
821
|
-
"attention"
|
|
822
|
-
]).default("all"),
|
|
823
|
-
type: z.enum([
|
|
824
|
-
"all",
|
|
825
|
-
"scheduled",
|
|
826
|
-
"event"
|
|
827
|
-
]).default("all"),
|
|
828
|
-
state: z.enum([
|
|
829
|
-
"all",
|
|
830
|
-
"active",
|
|
831
|
-
"blocked",
|
|
832
|
-
"paused",
|
|
833
|
-
"completed",
|
|
834
|
-
"unavailable"
|
|
835
|
-
]).default("all"),
|
|
836
|
-
creator: z.string().max(300).optional(),
|
|
837
|
-
/** Only the viewer's own Automations, inside any scope. */
|
|
838
|
-
owner: z.literal("me").optional(),
|
|
839
|
-
destination: z.string().max(300).optional(),
|
|
840
|
-
/** Only Automations that run this skill. */
|
|
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
|
-
*/
|
|
846
|
-
sort: z.enum([
|
|
847
|
-
"newest",
|
|
848
|
-
"oldest",
|
|
849
|
-
"title",
|
|
850
|
-
"activity"
|
|
851
|
-
]).default("newest"),
|
|
852
|
-
/** `nextCursor` of the page before, with `sort=activity`. */
|
|
853
|
-
cursor: z.string().min(1).max(1e3).optional(),
|
|
854
|
-
page: z.coerce.number().int().min(1).max(1e6).default(1),
|
|
855
|
-
pageSize: z.coerce.number().int().min(1).max(100).default(25)
|
|
856
|
-
}).strict();
|
|
857
|
-
const automationFilterOptionSchema = z.object({
|
|
858
|
-
value: z.string(),
|
|
859
|
-
label: z.string()
|
|
860
|
-
}).strict();
|
|
861
|
-
const automationListSchema = z.object({
|
|
862
|
-
automations: z.array(automationListItemSchema),
|
|
863
|
-
/** Set when more rows follow `sort=activity`. Pass it as `cursor`. */
|
|
864
|
-
nextCursor: z.string().min(1).optional(),
|
|
865
|
-
total: z.number().int().nonnegative(),
|
|
866
|
-
page: z.number().int().positive(),
|
|
867
|
-
pageSize: z.number().int().positive(),
|
|
868
|
-
counts: z.object({
|
|
869
|
-
all: z.number().int().nonnegative(),
|
|
870
|
-
mine: z.number().int().nonnegative(),
|
|
871
|
-
public: z.number().int().nonnegative(),
|
|
872
|
-
private: z.number().int().nonnegative()
|
|
873
|
-
}).strict(),
|
|
874
|
-
creators: z.array(automationFilterOptionSchema),
|
|
875
|
-
destinations: z.array(automationFilterOptionSchema)
|
|
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
|
-
});
|
|
887
|
-
const automationParamsSchema = z.object({ id: z.string().min(1) }).strict();
|
|
888
|
-
const automationExecutionStatusSchema = z.enum([
|
|
889
|
-
"blocked",
|
|
890
|
-
"completed",
|
|
891
|
-
"failed"
|
|
892
|
-
]);
|
|
893
|
-
const automationExecutionSchema = z.object({
|
|
894
|
-
/** Automation version that the run dispatched, when recorded. */
|
|
895
|
-
automationVersion: z.number().int().positive().optional(),
|
|
896
|
-
conversationId: z.string().min(1).optional(),
|
|
897
|
-
/** Estimated model cost for the linked conversation, when known. */
|
|
898
|
-
costUsd: z.number().finite().nonnegative().optional(),
|
|
899
|
-
/** Accounts that the dispatched version could use. */
|
|
900
|
-
credentialMode: z.enum(["creator", "system"]).optional(),
|
|
901
|
-
/** Cumulative conversation runtime in milliseconds, when known. */
|
|
902
|
-
durationMs: z.number().finite().nonnegative().optional(),
|
|
903
|
-
/** Reason that the run failed or was blocked, when recorded. */
|
|
904
|
-
error: z.string().min(1).optional(),
|
|
905
|
-
executedAt: z.string().datetime(),
|
|
906
|
-
executionId: z.string().min(1),
|
|
907
|
-
/** Planned occurrence of a Scheduled automation run. */
|
|
908
|
-
scheduledFor: z.string().datetime().optional(),
|
|
909
|
-
startedAt: z.string().datetime().optional(),
|
|
910
|
-
status: automationExecutionStatusSchema,
|
|
911
|
-
title: z.string().min(1).optional(),
|
|
912
|
-
/** Cumulative conversation token total, when known. */
|
|
913
|
-
totalTokens: z.number().int().nonnegative().optional()
|
|
914
|
-
}).strict();
|
|
915
|
-
/** One UTC day/hour of terminal executions for a single automation, stacked by status. */
|
|
916
|
-
const automationExecutionStatusDaySchema = z.object({
|
|
917
|
-
blocked: z.number().int().nonnegative(),
|
|
918
|
-
completed: z.number().int().nonnegative(),
|
|
919
|
-
/** Linked Conversation cost of the runs in this bucket. */
|
|
920
|
-
costUsd: z.number().finite().nonnegative(),
|
|
921
|
-
date: automationMetricBucketSchema,
|
|
922
|
-
failed: z.number().int().nonnegative()
|
|
923
|
-
}).strict();
|
|
924
|
-
const automationExecutionListSchema = z.object({
|
|
925
|
-
executionDays: z.array(automationExecutionStatusDaySchema),
|
|
926
|
-
executionHours: z.array(automationExecutionStatusDaySchema).optional(),
|
|
927
|
-
executionSixHours: z.array(automationExecutionStatusDaySchema).optional(),
|
|
928
|
-
executions: z.array(automationExecutionSchema),
|
|
929
|
-
truncated: z.boolean()
|
|
930
|
-
}).strict();
|
|
931
|
-
const automationRunSchema = automationExecutionSchema.extend({
|
|
932
|
-
kind: z.enum(["scheduled", "event"]),
|
|
933
|
-
automationId: z.string().min(1),
|
|
934
|
-
automationTitle: z.string().min(1)
|
|
935
|
-
}).strict();
|
|
936
|
-
const automationRunListSchema = z.object({
|
|
937
|
-
runs: z.array(automationRunSchema),
|
|
938
|
-
truncated: z.boolean()
|
|
939
|
-
}).strict();
|
|
940
|
-
const automationDefinitionFields = {
|
|
941
|
-
title: z.string().nullable(),
|
|
942
|
-
task: automationTaskSchema
|
|
943
|
-
};
|
|
944
|
-
const automationVersionFields = {
|
|
945
|
-
version: z.number().int().positive(),
|
|
946
|
-
createdAt: z.string().datetime(),
|
|
947
|
-
/** Null for versions saved by the upgrade, because the editor is unknown. */
|
|
948
|
-
editedBy: eventAutomationPrincipalSchema.nullable()
|
|
949
|
-
};
|
|
950
|
-
const scheduledAutomationVersionSchema = z.object({
|
|
951
|
-
...automationVersionFields,
|
|
952
|
-
kind: z.literal("scheduled"),
|
|
953
|
-
definition: scheduledAutomationSchema.pick({
|
|
954
|
-
credentialMode: true,
|
|
955
|
-
destination: true,
|
|
956
|
-
outcomes: true,
|
|
957
|
-
schedule: true
|
|
958
|
-
}).extend(automationDefinitionFields).strict()
|
|
959
|
-
}).strict();
|
|
960
|
-
const eventAutomationVersionSchema = z.object({
|
|
961
|
-
...automationVersionFields,
|
|
962
|
-
kind: z.literal("event"),
|
|
963
|
-
definition: eventAutomationSchema.pick({
|
|
964
|
-
credentialMode: true,
|
|
965
|
-
destination: true,
|
|
966
|
-
outcomes: true,
|
|
967
|
-
trigger: true
|
|
968
|
-
}).extend(automationDefinitionFields).strict()
|
|
969
|
-
}).strict();
|
|
970
|
-
/** One saved Automation definition. Newer versions have larger numbers. */
|
|
971
|
-
const automationVersionSchema = z.discriminatedUnion("kind", [scheduledAutomationVersionSchema, eventAutomationVersionSchema]);
|
|
972
|
-
/**
|
|
973
|
-
* One version in the version history. An Event version also has its saved
|
|
974
|
-
* trigger in plain words. The definition stays as saved, so it can be made
|
|
975
|
-
* active again.
|
|
976
|
-
*/
|
|
977
|
-
const listedAutomationVersionSchema = z.discriminatedUnion("kind", [scheduledAutomationVersionSchema, eventAutomationVersionSchema.extend({ trigger: eventTriggerDescriptionSchema }).strict()]);
|
|
978
|
-
/** Newest versions first. */
|
|
979
|
-
const automationVersionListSchema = z.object({
|
|
980
|
-
versions: z.array(listedAutomationVersionSchema),
|
|
981
|
-
/** Newest version that matches the current definition. Null when none match. */
|
|
982
|
-
activeVersion: z.number().int().positive().nullable(),
|
|
983
|
-
truncated: z.boolean()
|
|
984
|
-
}).strict();
|
|
985
|
-
const automationVersionParamsSchema = automationParamsSchema.extend({ version: z.coerce.number().int().positive() }).strict();
|
|
986
|
-
const automationRevisionSchema = z.string().regex(/^[a-f0-9]{64}$/);
|
|
987
|
-
/** Make a saved version active. The revision is the edit read revision. */
|
|
988
|
-
const automationVersionActivateSchema = z.object({ revision: automationRevisionSchema }).strict();
|
|
989
|
-
/** Pause and resume do not start work. */
|
|
990
|
-
const automationLifecycleSchema = z.object({
|
|
991
|
-
action: z.enum(["pause", "resume"]),
|
|
992
|
-
revision: automationRevisionSchema
|
|
993
|
-
}).strict();
|
|
994
|
-
const automationEditBaseSchema = scheduledAutomationSchema.pick({
|
|
995
|
-
destination: true,
|
|
996
|
-
createdBy: true
|
|
997
|
-
}).extend({
|
|
998
|
-
id: z.string().min(1),
|
|
999
|
-
revision: automationRevisionSchema,
|
|
1000
|
-
title: z.string().nullable(),
|
|
1001
|
-
task: automationTaskSchema,
|
|
1002
|
-
credentialMode: z.enum(["system", "creator"]),
|
|
1003
|
-
outcomes: z.array(taskOutcomeSchema).max(5),
|
|
1004
|
-
/** Creator-only rules apply when false. */
|
|
1005
|
-
ownedByViewer: z.boolean()
|
|
1006
|
-
});
|
|
1007
|
-
/** Edit values for owners and public readers. Read schemas also retain legacy values. */
|
|
1008
|
-
const automationEditSchema = z.discriminatedUnion("kind", [automationEditBaseSchema.merge(scheduledAutomationSchema.pick({ schedule: true })).extend({
|
|
1009
|
-
kind: z.literal("scheduled"),
|
|
1010
|
-
nextRunAtMs: z.number().optional(),
|
|
1011
|
-
status: z.enum([
|
|
1012
|
-
"active",
|
|
1013
|
-
"blocked",
|
|
1014
|
-
"paused",
|
|
1015
|
-
"completed"
|
|
1016
|
-
])
|
|
1017
|
-
}).strict(), automationEditBaseSchema.extend({
|
|
1018
|
-
kind: z.literal("event"),
|
|
1019
|
-
trigger: eventAutomationTriggerSchema,
|
|
1020
|
-
status: z.enum([
|
|
1021
|
-
"active",
|
|
1022
|
-
"blocked",
|
|
1023
|
-
"paused"
|
|
1024
|
-
])
|
|
1025
|
-
}).strict()]);
|
|
1026
|
-
/** Partial edits require the revision returned by the edit read. */
|
|
1027
|
-
const automationUpdateSchema = z.discriminatedUnion("kind", [scheduledAutomationEditSchema.extend({
|
|
1028
|
-
kind: z.literal("scheduled"),
|
|
1029
|
-
revision: automationRevisionSchema
|
|
1030
|
-
}).strict(), eventAutomationEditSchema.extend({
|
|
1031
|
-
kind: z.literal("event"),
|
|
1032
|
-
revision: automationRevisionSchema
|
|
1033
|
-
}).strict()]);
|
|
1034
|
-
const automationEditErrorSchema = z.object({
|
|
1035
|
-
error: z.string(),
|
|
1036
|
-
code: z.enum([
|
|
1037
|
-
"invalid_edit",
|
|
1038
|
-
"conflict",
|
|
1039
|
-
"not_found"
|
|
1040
|
-
]),
|
|
1041
|
-
fields: z.record(z.string(), z.array(z.string())).optional()
|
|
1042
|
-
}).strict();
|
|
1043
|
-
/**
|
|
1044
|
-
* Catalog metadata only, one entry for each namespace. Callbacks, guidance,
|
|
1045
|
-
* and provider connections stay on the server. `events` gives the reach of
|
|
1046
|
-
* each event once, and `anyResourceFields` gives the filters of every
|
|
1047
|
-
* resource type, for a trigger with no identifier.
|
|
1048
|
-
*/
|
|
1049
|
-
const automationEventCatalogSchema = z.array(z.object({
|
|
1050
|
-
namespace: z.string(),
|
|
1051
|
-
displayName: z.string(),
|
|
1052
|
-
events: z.record(z.string(), z.object({ reach: eventReachSchema })),
|
|
1053
|
-
anyResourceFields: eventMatchFieldsSchema,
|
|
1054
|
-
resourceTypes: z.array(pluginEventTypeSchema)
|
|
1055
|
-
}).strict());
|
|
1056
|
-
const automationScheduleIntentSchema = scheduleIntentSchema;
|
|
1057
|
-
const automationSchedulePreviewSchema = scheduledAutomationSchema.pick({ schedule: true }).extend({ nextRunAtMs: z.number() }).strict();
|
|
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 };
|