@eum-agent/automation-schedule 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/dist/index.js +1367 -0
  2. package/package.json +49 -3
  3. package/ui/ui.js +2716 -0
  4. package/README.md +0 -3
package/ui/ui.js ADDED
@@ -0,0 +1,2716 @@
1
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ /** Browser translations keyed by the product's supported language-region IDs. */
4
+ var CATALOGUES$1 = {
5
+ "zh-CN": {
6
+ locale: "zh-CN",
7
+ nav: "计划",
8
+ heading: "计划任务",
9
+ creation: "智能体创建",
10
+ agentLimit: "创建上限",
11
+ agentLimitHelp: "每个智能体在单个工作空间内可创建的计划任务数量上限。设为 0 表示不限制。手动创建的任务不计入此上限,降低上限不会删除已有任务。",
12
+ invalidLimit: "须为 0 到 1000 之间的整数。",
13
+ retry: "重试",
14
+ increase: "增加",
15
+ decrease: "减少",
16
+ add: "添加",
17
+ remove: "移除",
18
+ close: "关闭",
19
+ untitled: "未命名会话",
20
+ noWorkspace: "先选择或创建一个工作空间。",
21
+ loadFailed: "计划任务读取失败。",
22
+ offline: "未连接到网关服务",
23
+ authenticationRequired: "认证不可用,请重新打开页面",
24
+ create: "新建计划任务",
25
+ createTitle: "新建计划任务",
26
+ editTitle: "编辑计划任务",
27
+ edit: "编辑",
28
+ delete: "删除",
29
+ confirmDelete: "确认删除",
30
+ pause: "暂停",
31
+ resume: "恢复",
32
+ save: "保存",
33
+ createAction: "创建",
34
+ cancel: "取消",
35
+ loading: "加载中…",
36
+ saving: "保存中…",
37
+ empty: "暂无计划任务",
38
+ emptyHint: "让智能体按时间自动执行工作,例如每天早上汇总变更。",
39
+ list: "计划任务列表",
40
+ backToList: "返回计划任务列表",
41
+ overview: "概览",
42
+ nextRun: "下次执行",
43
+ lastRun: "最近一次",
44
+ runs: "运行记录",
45
+ creator: "创建者",
46
+ on: "开启",
47
+ off: "关闭",
48
+ scopeNone: "无",
49
+ noRuns: "暂无运行记录",
50
+ openSession: "打开会话",
51
+ paused: "已暂停",
52
+ sectionBasics: "基本信息",
53
+ sectionTiming: "执行计划",
54
+ required: "此项为必填项。",
55
+ scopeUnavailable: "使用已有会话时,任务在该会话里执行并沿用它已有的授权,不设预授权。",
56
+ sectionScope: "预授权",
57
+ name: "任务名称",
58
+ namePlaceholder: "例如:每日构建检查",
59
+ agent: "执行智能体",
60
+ mode: "执行方式",
61
+ modeOnce: "单次",
62
+ modeRepeat: "重复",
63
+ modeCron: "Cron",
64
+ runAt: "执行时间",
65
+ frequency: "重复频率",
66
+ frequencyInterval: "按间隔",
67
+ frequencyDaily: "每天",
68
+ frequencyWeekly: "每周",
69
+ frequencyMonthly: "每月",
70
+ interval: "间隔",
71
+ every: "每",
72
+ unit: "单位",
73
+ unitMinute: "分钟",
74
+ unitHour: "小时",
75
+ weekdays: "星期",
76
+ listSeparator: "、",
77
+ monthDay: "日期",
78
+ monthDaySuffix: "日",
79
+ monthDayHelp: "当月没有该日期时不执行。",
80
+ timeOfDay: "时间",
81
+ expression: "表达式",
82
+ expressionHelp: "五段式:分 时 日 月 周。例如 0 9 * * 1-5 表示工作日 9:00。",
83
+ timezone: "时区",
84
+ timezoneEmpty: "没有匹配的时区",
85
+ upcoming: "近期执行",
86
+ inTimezone: "时区:{{zone}}",
87
+ "invalid.amount": "请输入有效的间隔。",
88
+ "invalid.tooOften": "间隔不能少于 5 分钟。",
89
+ "invalid.weekdays": "请至少选择一天。",
90
+ "invalid.monthDay": "请输入 1 到 31 之间的日期。",
91
+ "invalid.expression": "请输入 Cron 表达式。",
92
+ "invalid.past": "执行时间已过,请选择之后的时间。",
93
+ "invalid.neverRuns": "这个表达式永远不会执行。",
94
+ "invalid.timezone": "无法识别这个时区。",
95
+ "invalid.syntax": "Cron 表达式格式不正确。",
96
+ catchUp: "错过执行",
97
+ catchUpRun: "恢复后补执行一次",
98
+ catchUpSkip: "跳过",
99
+ catchUpHelp: "网关停止或设备休眠期间错过的执行,恢复后补执行一次。",
100
+ instruction: "执行指令",
101
+ instructionPlaceholder: "描述每次执行时智能体要完成的工作",
102
+ target: "运行会话",
103
+ targetNew: "每次新建会话",
104
+ targetSession: "使用已有会话",
105
+ session: "会话",
106
+ sessionPlaceholder: "选择会话",
107
+ scopeHelp: "任务执行时可直接使用以下权限,无需等待审批。仅对每次新建的会话生效。",
108
+ scopePaths: "路径",
109
+ scopePathAdd: "添加路径",
110
+ scopePathsEmpty: "未添加路径。",
111
+ scopePathTitle: "添加预授权路径",
112
+ scopeAccess: "访问权限",
113
+ scopeRead: "只读",
114
+ scopeWrite: "读写",
115
+ scopeReadWarning: "允许任务免审批读取此路径及其子路径。",
116
+ scopeWriteWarning: "允许任务免审批读取和修改此路径及其子路径。",
117
+ scopeNetwork: "命令联网",
118
+ scopeNetworkPolicy: "遵循审批策略",
119
+ scopeNetworkAuthorized: "预先授权",
120
+ scopeNetworkHelp: "预先授权后,任务执行的命令无需审批即可访问任意外部地址。",
121
+ scopeHosts: "网站",
122
+ scopeHost: "主机名",
123
+ scopeHostAdd: "添加网站",
124
+ scopeHostsEmpty: "未添加网站。",
125
+ scopeHostTitle: "添加预授权网站",
126
+ scopeHostHelp: "只填主机名,不含协议和路径。",
127
+ ruleNone: "未设置执行计划",
128
+ ruleOnce: "{{at}} 执行一次",
129
+ ruleEveryMinutes: "每 {{amount}} 分钟",
130
+ ruleEveryHours: "每 {{amount}} 小时",
131
+ ruleDaily: "每天 {{time}}",
132
+ ruleWeekly: "每{{days}} {{time}}",
133
+ ruleMonthly: "每月 {{day}} 日 {{time}}",
134
+ ruleCron: "Cron {{expression}}({{timezone}})",
135
+ next: "下次执行 {{at}}",
136
+ noNext: "不再执行",
137
+ byYou: "由你创建",
138
+ byAgent: "由 {{name}} 创建",
139
+ "runKind.scheduled": "按计划",
140
+ "runKind.catch-up": "补执行",
141
+ "runKind.fired": "外部触发",
142
+ "state.running": "运行中",
143
+ "state.waiting": "等待处理",
144
+ "state.completed": "已完成",
145
+ "state.failed": "失败",
146
+ "state.skipped": "已跳过",
147
+ "reason.previous-running": "上次执行尚未结束",
148
+ "reason.target-busy": "目标会话繁忙",
149
+ "reason.missed": "已错过",
150
+ "reason.agent-removed": "智能体已删除",
151
+ "reason.workspace-removed": "工作空间已删除",
152
+ "reason.session-missing": "目标会话不存在",
153
+ "reason.no-model": "没有可用模型",
154
+ "reason.turn-failed": "执行失败",
155
+ "reason.turn-interrupted": "执行中断",
156
+ "reason.gateway-stopped": "网关已停止",
157
+ "problem.agent-removed": "异常:智能体已删除",
158
+ "problem.workspace-removed": "异常:工作空间已删除",
159
+ "problem.session-missing": "异常:目标会话不存在",
160
+ "problem.no-model": "异常:没有可用模型",
161
+ "problem.source-unavailable": "异常:触发源不可用"
162
+ },
163
+ "en-US": {
164
+ locale: "en-US",
165
+ nav: "Schedules",
166
+ heading: "Scheduled tasks",
167
+ creation: "Agent-created tasks",
168
+ agentLimit: "Limit",
169
+ agentLimitHelp: "Maximum number of scheduled tasks each agent can create per workspace. Set to 0 for no limit. Manually created tasks do not count toward this limit. Lowering the limit does not delete existing tasks.",
170
+ invalidLimit: "Must be a whole number from 0 to 1000.",
171
+ retry: "Retry",
172
+ increase: "Increase",
173
+ decrease: "Decrease",
174
+ add: "Add",
175
+ remove: "Remove",
176
+ close: "Close",
177
+ untitled: "Untitled session",
178
+ noWorkspace: "Choose or create a workspace first.",
179
+ loadFailed: "The scheduled tasks could not be read.",
180
+ offline: "Not connected to the gateway",
181
+ authenticationRequired: "Authentication is unavailable; reopen the page",
182
+ create: "New scheduled task",
183
+ createTitle: "New scheduled task",
184
+ editTitle: "Edit scheduled task",
185
+ edit: "Edit",
186
+ delete: "Delete",
187
+ confirmDelete: "Confirm delete",
188
+ pause: "Pause",
189
+ resume: "Resume",
190
+ save: "Save",
191
+ createAction: "Create",
192
+ cancel: "Cancel",
193
+ loading: "Loading…",
194
+ saving: "Saving…",
195
+ empty: "No scheduled tasks",
196
+ emptyHint: "Have an agent do work on a schedule, such as summarizing changes every morning.",
197
+ list: "Scheduled tasks",
198
+ backToList: "Back to scheduled tasks",
199
+ overview: "Overview",
200
+ nextRun: "Next run",
201
+ lastRun: "Last run",
202
+ runs: "Run history",
203
+ creator: "Created by",
204
+ on: "On",
205
+ off: "Off",
206
+ scopeNone: "None",
207
+ noRuns: "No runs yet",
208
+ openSession: "Open session",
209
+ paused: "Paused",
210
+ sectionBasics: "Basics",
211
+ sectionTiming: "Schedule",
212
+ required: "This field is required.",
213
+ scopeUnavailable: "Runs delivered into an existing session use the permissions that session already holds; no pre-authorization applies.",
214
+ sectionScope: "Pre-authorization",
215
+ name: "Task name",
216
+ namePlaceholder: "e.g. Daily build check",
217
+ agent: "Agent",
218
+ mode: "Runs",
219
+ modeOnce: "Once",
220
+ modeRepeat: "Repeating",
221
+ modeCron: "Cron",
222
+ runAt: "Date and time",
223
+ frequency: "Frequency",
224
+ frequencyInterval: "At an interval",
225
+ frequencyDaily: "Daily",
226
+ frequencyWeekly: "Weekly",
227
+ frequencyMonthly: "Monthly",
228
+ interval: "Interval",
229
+ every: "Every",
230
+ unit: "Unit",
231
+ unitMinute: "minutes",
232
+ unitHour: "hours",
233
+ weekdays: "Days",
234
+ listSeparator: ", ",
235
+ monthDay: "Day",
236
+ monthDaySuffix: "of the month",
237
+ monthDayHelp: "Months without this day are skipped.",
238
+ timeOfDay: "Time",
239
+ expression: "Expression",
240
+ expressionHelp: "Five fields: minute hour day month weekday. 0 9 * * 1-5 is weekdays at 9:00.",
241
+ timezone: "Time zone",
242
+ timezoneEmpty: "No matching time zone",
243
+ upcoming: "Upcoming",
244
+ inTimezone: "Time zone: {{zone}}",
245
+ "invalid.amount": "Enter a valid interval.",
246
+ "invalid.tooOften": "The interval must be at least 5 minutes.",
247
+ "invalid.weekdays": "Choose at least one day.",
248
+ "invalid.monthDay": "Enter a day from 1 to 31.",
249
+ "invalid.expression": "Enter a cron expression.",
250
+ "invalid.past": "That time has passed; choose a later one.",
251
+ "invalid.neverRuns": "This expression never runs.",
252
+ "invalid.timezone": "This time zone is not recognized.",
253
+ "invalid.syntax": "The cron expression is not valid.",
254
+ catchUp: "Missed runs",
255
+ catchUpRun: "Run once on resume",
256
+ catchUpSkip: "Skip",
257
+ catchUpHelp: "A run missed while the gateway was stopped or the device asleep runs once on resume.",
258
+ instruction: "Instruction",
259
+ instructionPlaceholder: "Describe what the agent should do on each run",
260
+ target: "Session",
261
+ targetNew: "New session each run",
262
+ targetSession: "Existing session",
263
+ session: "Target session",
264
+ sessionPlaceholder: "Choose a session",
265
+ scopeHelp: "Runs use these permissions without waiting for approval. Applies to runs that open a new session.",
266
+ scopePaths: "Paths",
267
+ scopePathAdd: "Add path",
268
+ scopePathsEmpty: "No paths added.",
269
+ scopePathTitle: "Add pre-authorized path",
270
+ scopeAccess: "Access",
271
+ scopeRead: "Read",
272
+ scopeWrite: "Read & write",
273
+ scopeReadWarning: "Runs may read this path and everything under it without asking.",
274
+ scopeWriteWarning: "Runs may read and change this path and everything under it without asking.",
275
+ scopeNetwork: "Command network",
276
+ scopeNetworkPolicy: "Follow approval policy",
277
+ scopeNetworkAuthorized: "Pre-authorize",
278
+ scopeNetworkHelp: "Pre-authorized commands may reach any outside address without approval.",
279
+ scopeHosts: "Websites",
280
+ scopeHost: "Host",
281
+ scopeHostAdd: "Add website",
282
+ scopeHostsEmpty: "No websites added.",
283
+ scopeHostTitle: "Add pre-authorized website",
284
+ scopeHostHelp: "A host name alone, without scheme or path.",
285
+ ruleNone: "No schedule",
286
+ ruleOnce: "Once at {{at}}",
287
+ ruleEveryMinutes: "Every {{amount}} min",
288
+ ruleEveryHours: "Every {{amount}} h",
289
+ ruleDaily: "Daily at {{time}}",
290
+ ruleWeekly: "Every {{days}} at {{time}}",
291
+ ruleMonthly: "Monthly on day {{day}} at {{time}}",
292
+ ruleCron: "Cron {{expression}} ({{timezone}})",
293
+ next: "Next run {{at}}",
294
+ noNext: "No further runs",
295
+ byYou: "Created by you",
296
+ byAgent: "Created by {{name}}",
297
+ "runKind.scheduled": "Scheduled",
298
+ "runKind.catch-up": "Catch-up",
299
+ "runKind.fired": "Triggered",
300
+ "state.running": "Running",
301
+ "state.waiting": "Needs attention",
302
+ "state.completed": "Completed",
303
+ "state.failed": "Failed",
304
+ "state.skipped": "Skipped",
305
+ "reason.previous-running": "previous run still in progress",
306
+ "reason.target-busy": "target session busy",
307
+ "reason.missed": "missed",
308
+ "reason.agent-removed": "agent deleted",
309
+ "reason.workspace-removed": "workspace deleted",
310
+ "reason.session-missing": "target session not found",
311
+ "reason.no-model": "no model available",
312
+ "reason.turn-failed": "run failed",
313
+ "reason.turn-interrupted": "run interrupted",
314
+ "reason.gateway-stopped": "gateway stopped",
315
+ "problem.agent-removed": "Error: agent deleted",
316
+ "problem.workspace-removed": "Error: workspace deleted",
317
+ "problem.session-missing": "Error: target session not found",
318
+ "problem.no-model": "Error: no model available",
319
+ "problem.source-unavailable": "Error: trigger source unavailable"
320
+ }
321
+ };
322
+ /** `{{name}}` placeholders filled from `values`. */
323
+ function fill(text, values) {
324
+ return text.replace(/\{\{(\w+)\}\}/g, (whole, key) => key in values ? String(values[key]) : whole);
325
+ }
326
+ function localTimezone() {
327
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
328
+ }
329
+ function dateOf(at) {
330
+ const date = new Date(at);
331
+ return {
332
+ year: date.getFullYear(),
333
+ month: date.getMonth() + 1,
334
+ day: date.getDate()
335
+ };
336
+ }
337
+ function timeOf(at) {
338
+ const date = new Date(at);
339
+ return {
340
+ hour: date.getHours(),
341
+ minute: date.getMinutes()
342
+ };
343
+ }
344
+ /** The local instant a date and time name. */
345
+ function instantOf(date, time) {
346
+ return new Date(date.year, date.month - 1, date.day, time.hour, time.minute).getTime();
347
+ }
348
+ /** Where a new task starts: once, an hour from now on the hour, and every
349
+ * repeating field filled with something a person would plausibly want. */
350
+ function defaultCadence(now) {
351
+ const soon = new Date(now + 36e5);
352
+ soon.setMinutes(0, 0, 0);
353
+ return {
354
+ mode: "once",
355
+ date: dateOf(soon.getTime()),
356
+ time: timeOf(soon.getTime()),
357
+ frequency: "daily",
358
+ amount: 1,
359
+ unit: "hour",
360
+ weekdays: [
361
+ 1,
362
+ 2,
363
+ 3,
364
+ 4,
365
+ 5
366
+ ],
367
+ monthDay: 1,
368
+ expression: "0 9 * * 1-5",
369
+ timezone: localTimezone()
370
+ };
371
+ }
372
+ var NUMBER = "(\\d{1,2})";
373
+ var DAILY = new RegExp(`^${NUMBER} ${NUMBER} \\* \\* \\*$`);
374
+ var DAYS = "[0-6](?:-[0-6])?";
375
+ var WEEKLY = new RegExp(`^${NUMBER} ${NUMBER} \\* \\* (${DAYS}(?:,${DAYS})*)$`);
376
+ var MONTHLY = new RegExp(`^${NUMBER} ${NUMBER} ${NUMBER} \\* \\*$`);
377
+ function clock(minute, hour) {
378
+ const m = Number(minute);
379
+ const h = Number(hour);
380
+ return m <= 59 && h <= 23 ? {
381
+ hour: h,
382
+ minute: m
383
+ } : null;
384
+ }
385
+ /** The frequency a cron expression was written from, when it is one. */
386
+ function frequencyOf(expression) {
387
+ const daily = DAILY.exec(expression);
388
+ if (daily !== null) {
389
+ const time = clock(daily[1], daily[2]);
390
+ return time && {
391
+ frequency: "daily",
392
+ time,
393
+ weekdays: [
394
+ 1,
395
+ 2,
396
+ 3,
397
+ 4,
398
+ 5
399
+ ],
400
+ monthDay: 1
401
+ };
402
+ }
403
+ const weekly = WEEKLY.exec(expression);
404
+ if (weekly !== null) {
405
+ const time = clock(weekly[1], weekly[2]);
406
+ const days = /* @__PURE__ */ new Set();
407
+ for (const part of weekly[3].split(",")) {
408
+ const [from, to = from] = part.split("-").map(Number);
409
+ if (to < from) return null;
410
+ for (let day = from; day <= to; day++) days.add(day);
411
+ }
412
+ const weekdays = [...days].sort();
413
+ return time && {
414
+ frequency: "weekly",
415
+ time,
416
+ weekdays,
417
+ monthDay: 1
418
+ };
419
+ }
420
+ const monthly = MONTHLY.exec(expression);
421
+ if (monthly !== null) {
422
+ const time = clock(monthly[1], monthly[2]);
423
+ const day = Number(monthly[3]);
424
+ if (day < 1 || day > 31) return null;
425
+ return time && {
426
+ frequency: "monthly",
427
+ time,
428
+ weekdays: [
429
+ 1,
430
+ 2,
431
+ 3,
432
+ 4,
433
+ 5
434
+ ],
435
+ monthDay: day
436
+ };
437
+ }
438
+ return null;
439
+ }
440
+ function cadenceOf(rule, now) {
441
+ const base = defaultCadence(now);
442
+ if (rule === null) return base;
443
+ switch (rule.kind) {
444
+ case "once": return {
445
+ ...base,
446
+ mode: "once",
447
+ date: dateOf(rule.at),
448
+ time: timeOf(rule.at)
449
+ };
450
+ case "interval": {
451
+ const hours = rule.everyMinutes % 60 === 0;
452
+ return {
453
+ ...base,
454
+ mode: "repeat",
455
+ frequency: "interval",
456
+ amount: hours ? rule.everyMinutes / 60 : rule.everyMinutes,
457
+ unit: hours ? "hour" : "minute"
458
+ };
459
+ }
460
+ case "cron": {
461
+ const written = {
462
+ ...base,
463
+ expression: rule.expression,
464
+ timezone: rule.timezone
465
+ };
466
+ const frequency = rule.timezone === localTimezone() ? frequencyOf(rule.expression) : null;
467
+ return frequency === null ? {
468
+ ...written,
469
+ mode: "cron"
470
+ } : {
471
+ ...written,
472
+ mode: "repeat",
473
+ ...frequency
474
+ };
475
+ }
476
+ }
477
+ }
478
+ /** What is wrong with a cadence before the gateway is asked, as a catalogue
479
+ * key under `invalid.`; null when there is nothing. */
480
+ function problemOf(cadence, now = Date.now()) {
481
+ switch (cadence.mode) {
482
+ case "once": return instantOf(cadence.date, cadence.time) <= now ? "past" : null;
483
+ case "repeat":
484
+ switch (cadence.frequency) {
485
+ case "interval": {
486
+ const minutes = intervalMinutes(cadence);
487
+ if (minutes === null) return "amount";
488
+ return minutes < 5 ? "tooOften" : null;
489
+ }
490
+ case "weekly": return cadence.weekdays.length === 0 ? "weekdays" : null;
491
+ case "monthly": return cadence.monthDay === null ? "monthDay" : null;
492
+ case "daily": return null;
493
+ }
494
+ break;
495
+ case "cron": return cadence.expression.trim() === "" ? "expression" : null;
496
+ }
497
+ return null;
498
+ }
499
+ function intervalMinutes(cadence) {
500
+ if (cadence.amount === null || !Number.isInteger(cadence.amount) || cadence.amount < 1) return null;
501
+ return cadence.unit === "hour" ? cadence.amount * 60 : cadence.amount;
502
+ }
503
+ /** Collapses consecutive days into ranges, the way cron is usually written
504
+ * by hand: Monday to Friday reads `1-5`. */
505
+ function weekdayField(days) {
506
+ const sorted = [...new Set(days)].sort();
507
+ const parts = [];
508
+ let start = sorted[0];
509
+ let previous = start;
510
+ for (const day of [...sorted.slice(1), NaN]) {
511
+ if (day === previous + 1) {
512
+ previous = day;
513
+ continue;
514
+ }
515
+ parts.push(previous - start >= 2 ? `${start}-${previous}` : previous === start ? `${start}` : `${start},${previous}`);
516
+ start = day;
517
+ previous = day;
518
+ }
519
+ return parts.join(",");
520
+ }
521
+ /** The rule a valid cadence stands for; null while `problemOf` names one. */
522
+ function ruleOf(cadence, anchor, now = Date.now()) {
523
+ if (problemOf(cadence, now) !== null) return null;
524
+ const { hour, minute } = cadence.time;
525
+ const timezone = localTimezone();
526
+ switch (cadence.mode) {
527
+ case "once": return {
528
+ kind: "once",
529
+ at: instantOf(cadence.date, cadence.time)
530
+ };
531
+ case "cron": return {
532
+ kind: "cron",
533
+ expression: cadence.expression.trim(),
534
+ timezone: cadence.timezone
535
+ };
536
+ case "repeat": switch (cadence.frequency) {
537
+ case "interval": return {
538
+ kind: "interval",
539
+ everyMinutes: intervalMinutes(cadence),
540
+ anchor
541
+ };
542
+ case "daily": return {
543
+ kind: "cron",
544
+ expression: `${minute} ${hour} * * *`,
545
+ timezone
546
+ };
547
+ case "weekly": return {
548
+ kind: "cron",
549
+ expression: `${minute} ${hour} * * ${weekdayField(cadence.weekdays)}`,
550
+ timezone
551
+ };
552
+ case "monthly": return {
553
+ kind: "cron",
554
+ expression: `${minute} ${hour} ${cadence.monthDay} * *`,
555
+ timezone
556
+ };
557
+ }
558
+ }
559
+ }
560
+ /**
561
+ * The problem a gateway refusal of a rule names, so the page says it in its
562
+ * own words. Every rule refusal starts `invalid rule:` (`src/source/rules.ts`);
563
+ * one this page does not recognise is the expression's syntax,
564
+ * the only refusal whose words come from the cron parser. Null for a refusal
565
+ * that is not about the rule.
566
+ */
567
+ function problemOfRefusal(reason) {
568
+ const match = /invalid rule: (.*)$/.exec(reason);
569
+ if (match === null) return null;
570
+ const detail = match[1];
571
+ if (detail === "the time has passed") return "past";
572
+ if (detail === "runs less than 5 minutes apart") return "tooOften";
573
+ if (detail === "the expression never runs") return "neverRuns";
574
+ if (detail.startsWith("unknown time zone")) return "timezone";
575
+ return "syntax";
576
+ }
577
+ //#endregion
578
+ //#region src/ui/describe.ts
579
+ function wordsOf(ctx) {
580
+ return {
581
+ t: (key, values) => values === void 0 ? ctx.i18n.t(key) : fill(ctx.i18n.t(key), values),
582
+ get locale() {
583
+ return ctx.i18n.t("locale");
584
+ }
585
+ };
586
+ }
587
+ function when(at, locale) {
588
+ return new Intl.DateTimeFormat(locale, {
589
+ dateStyle: "medium",
590
+ timeStyle: "short"
591
+ }).format(at);
592
+ }
593
+ function pad(value) {
594
+ return String(value).padStart(2, "0");
595
+ }
596
+ function timeText(time) {
597
+ return `${pad(time.hour)}:${pad(time.minute)}`;
598
+ }
599
+ /** A Sunday, from which a weekday's date is counted to name it. */
600
+ var SUNDAY = new Date(2026, 8, 27);
601
+ /** Days of the week in the order the page's language reads a week. */
602
+ function weekdayOrder(locale) {
603
+ return locale.startsWith("en") ? [
604
+ 0,
605
+ 1,
606
+ 2,
607
+ 3,
608
+ 4,
609
+ 5,
610
+ 6
611
+ ] : [
612
+ 1,
613
+ 2,
614
+ 3,
615
+ 4,
616
+ 5,
617
+ 6,
618
+ 0
619
+ ];
620
+ }
621
+ function weekdayName(day, locale) {
622
+ const date = new Date(SUNDAY.getFullYear(), SUNDAY.getMonth(), SUNDAY.getDate() + day);
623
+ return new Intl.DateTimeFormat(locale, { weekday: "short" }).format(date);
624
+ }
625
+ function ruleText(rule, words) {
626
+ const { t, locale } = words;
627
+ if (rule === null) return t("ruleNone");
628
+ const cadence = cadenceOf(rule, Date.now());
629
+ const time = timeText(cadence.time);
630
+ switch (cadence.mode) {
631
+ case "once": return t("ruleOnce", { at: when(instantOf(cadence.date, cadence.time), locale) });
632
+ case "cron": return t("ruleCron", {
633
+ expression: cadence.expression,
634
+ timezone: cadence.timezone
635
+ });
636
+ case "repeat": switch (cadence.frequency) {
637
+ case "interval": return t(cadence.unit === "hour" ? "ruleEveryHours" : "ruleEveryMinutes", { amount: cadence.amount ?? "" });
638
+ case "daily": return t("ruleDaily", { time });
639
+ case "weekly": return t("ruleWeekly", {
640
+ days: weekdayOrder(locale).filter((day) => cadence.weekdays.includes(day)).map((day) => weekdayName(day, locale)).join(t("listSeparator")),
641
+ time
642
+ });
643
+ case "monthly": return t("ruleMonthly", {
644
+ day: cadence.monthDay ?? "",
645
+ time
646
+ });
647
+ }
648
+ }
649
+ }
650
+ function runStateText(run, words) {
651
+ const state = words.t(`state.${run.state}`);
652
+ return run.reason === null ? state : `${state} · ${words.t(`reason.${run.reason}`)}`;
653
+ }
654
+ /** A task's state as its row and its detail name it; null while it simply runs. */
655
+ function stateOf(trigger, next, words) {
656
+ if (trigger.problem !== null) return {
657
+ text: words.t(`problem.${trigger.problem}`),
658
+ tone: "destructive"
659
+ };
660
+ if (!trigger.enabled) return {
661
+ text: words.t("paused"),
662
+ tone: "muted"
663
+ };
664
+ if (next === null) return {
665
+ text: words.t("noNext"),
666
+ tone: "muted"
667
+ };
668
+ return null;
669
+ }
670
+ //#endregion
671
+ //#region src/ui/wire.ts
672
+ /** The minted source this plugin's definitions carry. */
673
+ var SOURCE = "plugin:@eum-agent/automation-schedule:schedule";
674
+ /** A definition's config read back; `null` for one that is not a rule. */
675
+ function configOf(raw) {
676
+ if (typeof raw !== "object" || raw === null) return null;
677
+ const { rule, catchUp } = raw;
678
+ if (typeof rule !== "object" || rule === null) return null;
679
+ const kind = rule.kind;
680
+ if (kind !== "once" && kind !== "interval" && kind !== "cron") return null;
681
+ return {
682
+ rule,
683
+ catchUp: catchUp !== false
684
+ };
685
+ }
686
+ //#endregion
687
+ //#region src/ui/store.ts
688
+ var EMPTY = {
689
+ tasks: null,
690
+ tasksFailed: false,
691
+ pendingActions: {},
692
+ agents: [],
693
+ sessions: [],
694
+ next: {},
695
+ pictures: {}
696
+ };
697
+ /** A picture revision belongs to its agent and cannot address another agent's bytes. */
698
+ function pictureKey(agentId, rev) {
699
+ return JSON.stringify([agentId, rev]);
700
+ }
701
+ /** One list's reader: at most one read in flight and one queued behind it. */
702
+ function reader(read) {
703
+ let running = false;
704
+ let again = false;
705
+ const run = () => {
706
+ if (running) {
707
+ again = true;
708
+ return;
709
+ }
710
+ running = true;
711
+ read().finally(() => {
712
+ running = false;
713
+ if (again) {
714
+ again = false;
715
+ run();
716
+ }
717
+ });
718
+ };
719
+ return run;
720
+ }
721
+ function createScheduleStore(ctx) {
722
+ let state = EMPTY;
723
+ const listeners = /* @__PURE__ */ new Set();
724
+ const inflight = /* @__PURE__ */ new Set();
725
+ const actionIntents = /* @__PURE__ */ new Map();
726
+ const pictureQueue = [];
727
+ let picturesRunning = false;
728
+ let connectionEpoch = 0;
729
+ let connectionStatus = ctx.gateway.connection.status;
730
+ const stopConnection = ctx.gateway.watchConnection((connection) => {
731
+ if (connection.status === connectionStatus) return;
732
+ connectionStatus = connection.status;
733
+ connectionEpoch += 1;
734
+ });
735
+ ctx.signal.addEventListener("abort", stopConnection, { once: true });
736
+ let holders = 0;
737
+ let stop = null;
738
+ const set = (patch) => {
739
+ state = {
740
+ ...state,
741
+ ...patch
742
+ };
743
+ for (const listener of [...listeners]) listener();
744
+ };
745
+ const readPictures = async () => {
746
+ if (picturesRunning) return;
747
+ picturesRunning = true;
748
+ try {
749
+ while (pictureQueue.length) {
750
+ const group = pictureQueue.splice(0, 4);
751
+ const epoch = connectionEpoch;
752
+ const pictures = {};
753
+ try {
754
+ const answer = await ctx.call("config.agent.avatars", { agentIds: group.map((one) => one.agentId) });
755
+ for (const [index, one] of group.entries()) {
756
+ const result = answer.results[index];
757
+ const image = result?.ok ? result.value : null;
758
+ pictures[pictureKey(one.agentId, one.rev)] = image !== null && image.rev === one.rev ? `data:${image.mediaType};base64,${image.data}` : null;
759
+ }
760
+ } catch {
761
+ for (const one of group) pictures[pictureKey(one.agentId, one.rev)] = null;
762
+ } finally {
763
+ for (const one of group) inflight.delete(pictureKey(one.agentId, one.rev));
764
+ }
765
+ if (!ctx.signal.aborted && connectionEpoch === epoch) set({ pictures: {
766
+ ...state.pictures,
767
+ ...pictures
768
+ } });
769
+ }
770
+ } finally {
771
+ picturesRunning = false;
772
+ }
773
+ };
774
+ const loadTasks = reader(() => ctx.call("trigger.list", {}).then(({ triggers }) => set({
775
+ tasks: triggers.filter((one) => one.source === SOURCE),
776
+ tasksFailed: false
777
+ })).catch((error) => set({ tasksFailed: state.tasks === null && failureText$1(ctx, error) !== null })).then(() => void 0));
778
+ const loadAgents = reader(() => ctx.call("config.agent.list", {}).then((agents) => set({ agents })).catch(() => void 0));
779
+ const loadSessions = reader(() => ctx.call("session.list", {}).then((sessions) => set({ sessions })).catch(() => void 0));
780
+ const loadNext = reader(() => ctx.invoke("nextRuns", {}).then(({ next }) => set({ next })).catch(() => void 0));
781
+ const loadAll = () => {
782
+ loadTasks();
783
+ loadAgents();
784
+ loadSessions();
785
+ loadNext();
786
+ };
787
+ function start() {
788
+ let connection = ctx.host.get().connection;
789
+ const offs = [
790
+ ctx.onCore("trigger.changed", loadTasks),
791
+ ctx.onCore("config.agentChanged", loadAgents),
792
+ ctx.onCore("config.agentRemoved", loadAgents),
793
+ ctx.onCore("session.created", loadSessions),
794
+ ctx.onCore("session.updated", loadSessions),
795
+ ctx.on("nextRunsChanged", (event) => set({ next: event.payload.next })),
796
+ ctx.host.subscribe(() => {
797
+ const now = ctx.host.get().connection;
798
+ if (now === "online" && connection !== "online") loadAll();
799
+ connection = now;
800
+ })
801
+ ];
802
+ loadAll();
803
+ return () => {
804
+ for (const off of offs) off();
805
+ };
806
+ }
807
+ return {
808
+ get: () => state,
809
+ subscribe(listener) {
810
+ listeners.add(listener);
811
+ return () => {
812
+ listeners.delete(listener);
813
+ };
814
+ },
815
+ retain() {
816
+ holders += 1;
817
+ if (holders === 1) stop = start();
818
+ let released = false;
819
+ return () => {
820
+ if (released) return;
821
+ released = true;
822
+ holders -= 1;
823
+ if (holders === 0) {
824
+ stop?.();
825
+ stop = null;
826
+ }
827
+ };
828
+ },
829
+ reloadTasks: loadTasks,
830
+ async runTaskAction(id, intent, action) {
831
+ if (state.pendingActions[id]) return;
832
+ const key = JSON.stringify([id, intent]);
833
+ const operationId = actionIntents.get(key) ?? ctx.uuid();
834
+ actionIntents.set(key, operationId);
835
+ set({ pendingActions: {
836
+ ...state.pendingActions,
837
+ [id]: true
838
+ } });
839
+ try {
840
+ const receipt = await action(operationId);
841
+ if (receipt.operationId !== operationId) throw new Error("task operation identity mismatch");
842
+ if (receipt.operationState === "admitted") throw new Error("task operation is awaiting settlement; retry the original intent");
843
+ if (receipt.operationState === "cleanup-pending") throw new Error("task change committed but cleanup is pending; retry the original intent");
844
+ actionIntents.delete(key);
845
+ } finally {
846
+ const pendingActions = { ...state.pendingActions };
847
+ delete pendingActions[id];
848
+ set({ pendingActions });
849
+ }
850
+ },
851
+ requestPicture(agentId, rev) {
852
+ const key = pictureKey(agentId, rev);
853
+ if (key in state.pictures || inflight.has(key)) return;
854
+ inflight.add(key);
855
+ pictureQueue.push({
856
+ agentId,
857
+ rev
858
+ });
859
+ queueMicrotask(() => void readPictures());
860
+ }
861
+ };
862
+ }
863
+ //#endregion
864
+ //#region src/ui/env.tsx
865
+ var EnvContext = createContext(null);
866
+ var EnvProvider = EnvContext.Provider;
867
+ function envOf(ctx, store) {
868
+ return {
869
+ ctx,
870
+ store,
871
+ words: wordsOf(ctx)
872
+ };
873
+ }
874
+ function useEnv() {
875
+ const env = useContext(EnvContext);
876
+ if (env === null) throw new Error("scheduled tasks page rendered outside its provider");
877
+ return env;
878
+ }
879
+ function useSchedule(pick) {
880
+ const { store } = useEnv();
881
+ return useSyncExternalStore(store.subscribe, () => pick(store.get()));
882
+ }
883
+ /** The workspace the page is in, or `null` while there is none. */
884
+ function useWorkspaceId() {
885
+ const { ctx } = useEnv();
886
+ return useSyncExternalStore(ctx.host.subscribe, () => ctx.host.get().workspaceId ?? null);
887
+ }
888
+ /** Returns feature failures; the global dialog owns gateway connectivity and authentication. */
889
+ function failureText$1(_ctx, error) {
890
+ const failure = error?.failure;
891
+ if (failure === "offline" || failure === "authentication") return null;
892
+ return (error instanceof Error ? error.message : String(error)).replace(/^plugin "[^"]+" failed in \w+: /, "");
893
+ }
894
+ /** Shows a failure outside a form as a toast; offline says nothing, because
895
+ * the host's connection dialog owns the outage. */
896
+ function useFailureToast() {
897
+ const { ctx } = useEnv();
898
+ const toast = ctx.ui.useToast();
899
+ return useCallback((error) => {
900
+ const text = failureText$1(ctx, error);
901
+ if (text === null) return;
902
+ toast.add({
903
+ id: `failure::${text}`,
904
+ tone: "destructive",
905
+ title: text
906
+ });
907
+ }, [ctx, toast]);
908
+ }
909
+ /** What a session is called: the person's name, else the topic title, else
910
+ * the name of the task that opened it, else the untitled wording. */
911
+ function sessionTitle(session, tasks, untitled) {
912
+ if (session === void 0) return untitled;
913
+ if (session.name !== null) return session.name;
914
+ const ref = session.origin?.ref ?? null;
915
+ const origin = ref === null ? void 0 : tasks.find((one) => one.id === ref)?.name;
916
+ return session.title ?? origin ?? untitled;
917
+ }
918
+ /** An agent's face: its uploaded picture, else initials over a colour seeded
919
+ * by its id, the way the host draws one. */
920
+ function AgentFace({ agentId, size = "md", className }) {
921
+ const { ctx, store } = useEnv();
922
+ const agent = useSchedule((state) => state.agents.find((one) => one.agentId === agentId));
923
+ const rev = agent?.avatar ?? null;
924
+ const src = useSchedule((state) => rev === null ? null : state.pictures[pictureKey(agentId, rev)] ?? null);
925
+ useEffect(() => {
926
+ if (rev !== null) store.requestPicture(agentId, rev);
927
+ }, [
928
+ store,
929
+ agentId,
930
+ rev
931
+ ]);
932
+ const name = agent?.name ?? agentId;
933
+ return /* @__PURE__ */ jsx(ctx.ui.Tooltip, {
934
+ content: name,
935
+ children: /* @__PURE__ */ jsx(ctx.ui.Avatar, {
936
+ alt: name,
937
+ name,
938
+ seed: agentId,
939
+ algorithm: "initials",
940
+ size,
941
+ shape: "circle",
942
+ ...src === null ? {} : { src },
943
+ className
944
+ })
945
+ });
946
+ }
947
+ //#endregion
948
+ //#region src/tool-names.ts
949
+ /** Canonical names shared by tool registration and browser presentation. */
950
+ var TOOL_NAMES = [
951
+ "schedule_create",
952
+ "schedule_list",
953
+ "schedule_read",
954
+ "schedule_update",
955
+ "schedule_delete"
956
+ ];
957
+ //#endregion
958
+ //#region src/ui/metadata.ts
959
+ var CATALOGUES = {
960
+ "en-US": {
961
+ section: "Built-in plugins",
962
+ group: "Schedules",
963
+ schedule_create: "Create scheduled task",
964
+ schedule_list: "List scheduled tasks",
965
+ schedule_read: "Read scheduled task",
966
+ schedule_update: "Edit scheduled task",
967
+ schedule_delete: "Delete scheduled task"
968
+ },
969
+ "zh-CN": {
970
+ section: "内置插件",
971
+ group: "计划任务",
972
+ schedule_create: "新建计划任务",
973
+ schedule_list: "查看计划任务",
974
+ schedule_read: "读取计划任务",
975
+ schedule_update: "修改计划任务",
976
+ schedule_delete: "删除计划任务"
977
+ }
978
+ };
979
+ var names = new Set(TOOL_NAMES);
980
+ /** Registers presentation facets with the same activation lifetime as the tools. */
981
+ function registerMetadata(ctx) {
982
+ ctx.i18n.register(CATALOGUES, "en-US");
983
+ ctx.i18n.contribute(Object.fromEntries(Object.entries(CATALOGUES).map(([language, catalogue]) => [language, Object.fromEntries([...names].map((tool) => [`transcript.actions.${tool}`, catalogue[tool] ?? tool]))])), "en-US");
984
+ ctx.slots.register("chat.tool.presentation", {
985
+ id: "tool-metadata",
986
+ describe: ({ call }) => {
987
+ if (!names.has(call.name)) return void 0;
988
+ const input = call.input !== null && typeof call.input === "object" ? call.input : {};
989
+ const summary = [
990
+ "path",
991
+ "url",
992
+ "query",
993
+ "command",
994
+ "skill",
995
+ "id",
996
+ "name",
997
+ "task",
998
+ "prompt"
999
+ ].flatMap((key) => typeof input[key] === "string" ? [input[key]] : []).slice(0, 2).join(" · ").replace(/\s+/g, " ").slice(0, 240);
1000
+ return {
1001
+ label: names.has(call.name) ? ctx.i18n.t(call.name) : call.name,
1002
+ icon: "hammer",
1003
+ summary
1004
+ };
1005
+ }
1006
+ });
1007
+ ctx.slots.register("shell.tools.group", {
1008
+ id: "tool-groups",
1009
+ describe: (tool) => {
1010
+ if (tool.plugin !== ctx.plugin) return void 0;
1011
+ return {
1012
+ key: `plugin:${ctx.plugin}`,
1013
+ label: ctx.i18n.t("group"),
1014
+ source: ctx.plugin,
1015
+ sectionLabel: ctx.i18n.t("section"),
1016
+ sectionOrder: 1,
1017
+ order: 6
1018
+ };
1019
+ }
1020
+ });
1021
+ }
1022
+ //#endregion
1023
+ //#region src/ui/scope.tsx
1024
+ function RemoveButton({ label, onClick }) {
1025
+ const { ctx } = useEnv();
1026
+ return /* @__PURE__ */ jsx(ctx.ui.Button, {
1027
+ variant: "ghost",
1028
+ size: "sm",
1029
+ type: "button",
1030
+ icon: "trash",
1031
+ "aria-label": label,
1032
+ title: label,
1033
+ onClick,
1034
+ className: "sch-row-action"
1035
+ });
1036
+ }
1037
+ function AddPathDialog({ open, onOpenChange, onAdd }) {
1038
+ const { ctx, words } = useEnv();
1039
+ const { t } = words;
1040
+ const ui = ctx.ui;
1041
+ const [path, setPath] = useState("");
1042
+ const [access, setAccess] = useState("read");
1043
+ useEffect(() => {
1044
+ if (!open) {
1045
+ setPath("");
1046
+ setAccess("read");
1047
+ }
1048
+ }, [open]);
1049
+ return /* @__PURE__ */ jsx(ui.Dialog, {
1050
+ size: "sm",
1051
+ open,
1052
+ onOpenChange,
1053
+ title: t("scopePathTitle"),
1054
+ closeLabel: t("close"),
1055
+ children: /* @__PURE__ */ jsxs("form", {
1056
+ onSubmit: (event) => {
1057
+ event.preventDefault();
1058
+ event.stopPropagation();
1059
+ if (path === "") return;
1060
+ onAdd({
1061
+ kind: access,
1062
+ target: path
1063
+ });
1064
+ onOpenChange(false);
1065
+ },
1066
+ className: "sch-stack sch-path-form",
1067
+ children: [
1068
+ /* @__PURE__ */ jsx(ui.Field, {
1069
+ label: t("scopePaths"),
1070
+ inline: true,
1071
+ children: (binding) => /* @__PURE__ */ jsx(ui.PathInput, {
1072
+ ...binding,
1073
+ value: path,
1074
+ onValueChange: setPath,
1075
+ placeholder: "/"
1076
+ })
1077
+ }),
1078
+ /* @__PURE__ */ jsx(ui.Field, {
1079
+ label: t("scopeAccess"),
1080
+ inline: true,
1081
+ children: () => /* @__PURE__ */ jsx(ui.Segmented, {
1082
+ fullWidth: true,
1083
+ label: t("scopeAccess"),
1084
+ value: access,
1085
+ onSelect: (value) => setAccess(value),
1086
+ options: [{
1087
+ value: "read",
1088
+ label: t("scopeRead")
1089
+ }, {
1090
+ value: "write",
1091
+ label: t("scopeWrite")
1092
+ }]
1093
+ })
1094
+ }),
1095
+ /* @__PURE__ */ jsx(ui.Alert, {
1096
+ tone: "warning",
1097
+ children: t(access === "read" ? "scopeReadWarning" : "scopeWriteWarning")
1098
+ }),
1099
+ /* @__PURE__ */ jsx("div", {
1100
+ className: "sch-foot",
1101
+ children: /* @__PURE__ */ jsx(ui.Button, {
1102
+ type: "submit",
1103
+ variant: "primary",
1104
+ disabled: path === "",
1105
+ children: t("add")
1106
+ })
1107
+ })
1108
+ ]
1109
+ })
1110
+ });
1111
+ }
1112
+ function AddHostDialog({ open, onOpenChange, onAdd }) {
1113
+ const { ctx, words } = useEnv();
1114
+ const { t } = words;
1115
+ const ui = ctx.ui;
1116
+ const [host, setHost] = useState("");
1117
+ useEffect(() => {
1118
+ if (!open) setHost("");
1119
+ }, [open]);
1120
+ return /* @__PURE__ */ jsx(ui.Dialog, {
1121
+ size: "sm",
1122
+ open,
1123
+ onOpenChange,
1124
+ title: t("scopeHostTitle"),
1125
+ closeLabel: t("close"),
1126
+ children: /* @__PURE__ */ jsxs("form", {
1127
+ onSubmit: (event) => {
1128
+ event.preventDefault();
1129
+ event.stopPropagation();
1130
+ const wanted = host.trim().toLowerCase();
1131
+ if (wanted === "") return;
1132
+ onAdd(wanted);
1133
+ onOpenChange(false);
1134
+ },
1135
+ className: "sch-stack",
1136
+ children: [/* @__PURE__ */ jsx(ui.Field, {
1137
+ label: t("scopeHost"),
1138
+ help: t("scopeHostHelp"),
1139
+ inline: true,
1140
+ children: (binding) => /* @__PURE__ */ jsx(ui.Input, {
1141
+ ...binding,
1142
+ value: host,
1143
+ spellCheck: false,
1144
+ autoComplete: "off",
1145
+ placeholder: "example.com",
1146
+ className: "sch-mono",
1147
+ onChange: (event) => setHost(event.target.value)
1148
+ })
1149
+ }), /* @__PURE__ */ jsx("div", {
1150
+ className: "sch-foot",
1151
+ children: /* @__PURE__ */ jsx(ui.Button, {
1152
+ type: "submit",
1153
+ variant: "primary",
1154
+ disabled: host.trim() === "",
1155
+ children: t("add")
1156
+ })
1157
+ })]
1158
+ })
1159
+ });
1160
+ }
1161
+ /** One kind of scope as a list: its name and add action, then a row per item. */
1162
+ function ScopeList({ title, addLabel, emptyLabel, onAdd, children }) {
1163
+ const { ctx } = useEnv();
1164
+ return /* @__PURE__ */ jsxs("div", {
1165
+ className: "sch-scope-list",
1166
+ children: [/* @__PURE__ */ jsxs("div", {
1167
+ className: "sch-scope-head",
1168
+ children: [/* @__PURE__ */ jsx("span", { children: title }), /* @__PURE__ */ jsx(ctx.ui.Button, {
1169
+ variant: "outline",
1170
+ size: "sm",
1171
+ icon: "plus",
1172
+ type: "button",
1173
+ onClick: onAdd,
1174
+ children: addLabel
1175
+ })]
1176
+ }), children.length === 0 ? /* @__PURE__ */ jsx("p", {
1177
+ className: "sch-muted-text",
1178
+ children: emptyLabel
1179
+ }) : /* @__PURE__ */ jsx("ul", {
1180
+ className: "sch-rows",
1181
+ children
1182
+ })]
1183
+ });
1184
+ }
1185
+ function Row$1({ icon, target, badge, onRemove }) {
1186
+ const { ctx, words } = useEnv();
1187
+ return /* @__PURE__ */ jsxs("li", {
1188
+ className: "sch-row",
1189
+ children: [
1190
+ /* @__PURE__ */ jsx(ctx.ui.Icon, {
1191
+ name: icon,
1192
+ className: "sch-row-icon"
1193
+ }),
1194
+ /* @__PURE__ */ jsx(ctx.ui.Tooltip, {
1195
+ content: target,
1196
+ children: /* @__PURE__ */ jsx("span", {
1197
+ className: "sch-row-target sch-mono",
1198
+ children: target
1199
+ })
1200
+ }),
1201
+ badge,
1202
+ /* @__PURE__ */ jsx(RemoveButton, {
1203
+ label: `${words.t("remove")} ${target}`,
1204
+ onClick: onRemove
1205
+ })
1206
+ ]
1207
+ });
1208
+ }
1209
+ /** Edits exact path targets, web hosts, and network pre-authorization for scheduled runs. */
1210
+ function Scope({ value, onChange }) {
1211
+ const { ctx, words } = useEnv();
1212
+ const { t } = words;
1213
+ const ui = ctx.ui;
1214
+ const [adding, setAdding] = useState(null);
1215
+ const paths = value.filter((item) => item.kind === "read" || item.kind === "write");
1216
+ const hosts = value.filter((item) => item.kind === "web-host");
1217
+ const network = value.some((item) => item.kind === "network");
1218
+ const without = (gone) => value.filter((item) => item.kind !== gone.kind || item.target !== gone.target);
1219
+ const addPath = (item) => onChange([...value.filter((one) => !((one.kind === "read" || one.kind === "write") && one.target === item.target)), item]);
1220
+ const addHost = (host) => {
1221
+ if (!hosts.some((one) => one.target === host)) onChange([...value, {
1222
+ kind: "web-host",
1223
+ target: host
1224
+ }]);
1225
+ };
1226
+ return /* @__PURE__ */ jsxs("div", {
1227
+ "data-slot": "schedule-scope",
1228
+ className: "sch-stack",
1229
+ children: [
1230
+ /* @__PURE__ */ jsx(ScopeList, {
1231
+ title: t("scopePaths"),
1232
+ addLabel: t("scopePathAdd"),
1233
+ emptyLabel: t("scopePathsEmpty"),
1234
+ onAdd: () => setAdding("path"),
1235
+ children: paths.map((item) => /* @__PURE__ */ jsx(Row$1, {
1236
+ icon: "folder",
1237
+ target: item.target,
1238
+ badge: /* @__PURE__ */ jsx(ui.Badge, {
1239
+ size: "sm",
1240
+ tone: item.kind === "write" ? "warning" : "neutral",
1241
+ children: t(item.kind === "write" ? "scopeWrite" : "scopeRead")
1242
+ }),
1243
+ onRemove: () => onChange(without(item))
1244
+ }, `${item.kind}:${item.target}`))
1245
+ }),
1246
+ /* @__PURE__ */ jsx(ScopeList, {
1247
+ title: t("scopeHosts"),
1248
+ addLabel: t("scopeHostAdd"),
1249
+ emptyLabel: t("scopeHostsEmpty"),
1250
+ onAdd: () => setAdding("host"),
1251
+ children: hosts.map((item) => /* @__PURE__ */ jsx(Row$1, {
1252
+ icon: "globe",
1253
+ target: item.target,
1254
+ onRemove: () => onChange(without(item))
1255
+ }, item.target))
1256
+ }),
1257
+ /* @__PURE__ */ jsx(ui.Field, {
1258
+ label: t("scopeNetwork"),
1259
+ help: t("scopeNetworkHelp"),
1260
+ inline: true,
1261
+ children: () => /* @__PURE__ */ jsx(ui.Segmented, {
1262
+ fullWidth: true,
1263
+ label: t("scopeNetwork"),
1264
+ value: network ? "authorized" : "policy",
1265
+ onSelect: (choice) => onChange(choice === "authorized" ? [...value.filter((item) => item.kind !== "network"), {
1266
+ kind: "network",
1267
+ target: "*"
1268
+ }] : value.filter((item) => item.kind !== "network")),
1269
+ options: [{
1270
+ value: "policy",
1271
+ label: t("scopeNetworkPolicy")
1272
+ }, {
1273
+ value: "authorized",
1274
+ label: t("scopeNetworkAuthorized")
1275
+ }]
1276
+ })
1277
+ }),
1278
+ /* @__PURE__ */ jsx(AddPathDialog, {
1279
+ open: adding === "path",
1280
+ onOpenChange: (open) => setAdding(open ? "path" : null),
1281
+ onAdd: addPath
1282
+ }),
1283
+ /* @__PURE__ */ jsx(AddHostDialog, {
1284
+ open: adding === "host",
1285
+ onOpenChange: (open) => setAdding(open ? "host" : null),
1286
+ onAdd: addHost
1287
+ })
1288
+ ]
1289
+ });
1290
+ }
1291
+ //#endregion
1292
+ //#region src/ui/timing.tsx
1293
+ /**
1294
+ * The 执行计划 tab of the schedule editor: how a task is timed, as a mode
1295
+ * (单次 / 重复 / Cron) and the fields that mode needs, then the next runs this
1296
+ * plugin's `preview` computes for it and whether a missed run is caught up.
1297
+ *
1298
+ * The rows are inline fields, label beside control, so the tab reads as a
1299
+ * form of one rhythm whatever the mode. The preview is asked for every valid
1300
+ * rule; a rule the page already knows is incomplete says why instead, and a
1301
+ * rule the gateway refuses shows the gateway's sentence.
1302
+ */
1303
+ /** Every IANA zone the browser knows, the local one first. */
1304
+ function timezones() {
1305
+ const local = localTimezone();
1306
+ return [local, ...(typeof Intl.supportedValuesOf === "function" ? Intl.supportedValuesOf("timeZone") : []).filter((zone) => zone !== local)];
1307
+ }
1308
+ function isToday(date) {
1309
+ const today = dateOf(Date.now());
1310
+ return today.year === date.year && today.month === date.month && today.day === date.day;
1311
+ }
1312
+ /** The earliest time a one-off run can still take today: the next minute. */
1313
+ function nowTime() {
1314
+ const next = new Date(Date.now() + 6e4);
1315
+ return {
1316
+ hour: next.getHours(),
1317
+ minute: next.getMinutes()
1318
+ };
1319
+ }
1320
+ function usePreview(rule) {
1321
+ const { ctx } = useEnv();
1322
+ const [preview, setPreview] = useState(null);
1323
+ const key = rule === null ? null : JSON.stringify(rule);
1324
+ useEffect(() => {
1325
+ if (key === null) {
1326
+ setPreview(null);
1327
+ return;
1328
+ }
1329
+ let live = true;
1330
+ ctx.invoke("preview", { rule: JSON.parse(key) }).then((result) => live && setPreview({ next: result.times })).catch((error) => {
1331
+ const failure = error?.failure;
1332
+ if (live) setPreview({ error: failure === void 0 ? failureText$1(ctx, error) ?? "" : "" });
1333
+ });
1334
+ return () => {
1335
+ live = false;
1336
+ };
1337
+ }, [ctx, key]);
1338
+ return preview;
1339
+ }
1340
+ function Timing({ cadence, anchor, catchUp, onCadence, onCatchUp }) {
1341
+ const { ctx, words } = useEnv();
1342
+ const { t, locale } = words;
1343
+ const ui = ctx.ui;
1344
+ const zones = useMemo(() => timezones().map((zone) => ({
1345
+ value: zone,
1346
+ label: zone
1347
+ })), []);
1348
+ const problem = problemOf(cadence);
1349
+ const rule = ruleOf(cadence, anchor);
1350
+ const preview = usePreview(rule);
1351
+ const zone = rule?.kind === "cron" ? rule.timezone : null;
1352
+ const at = useMemo(() => {
1353
+ try {
1354
+ return new Intl.DateTimeFormat(locale, {
1355
+ ...zone === null ? {} : { timeZone: zone },
1356
+ month: "short",
1357
+ day: "numeric",
1358
+ weekday: "short",
1359
+ hour: "2-digit",
1360
+ minute: "2-digit"
1361
+ });
1362
+ } catch (error) {
1363
+ if (zone === null) throw error;
1364
+ return null;
1365
+ }
1366
+ }, [locale, zone]);
1367
+ return /* @__PURE__ */ jsxs("div", {
1368
+ "data-slot": "schedule-timing",
1369
+ className: "sch-stack",
1370
+ children: [
1371
+ /* @__PURE__ */ jsx(ui.Field, {
1372
+ label: t("mode"),
1373
+ inline: true,
1374
+ children: () => /* @__PURE__ */ jsx(ui.Segmented, {
1375
+ fullWidth: true,
1376
+ label: t("mode"),
1377
+ value: cadence.mode,
1378
+ onSelect: (mode) => onCadence({ mode }),
1379
+ options: [
1380
+ {
1381
+ value: "once",
1382
+ label: t("modeOnce")
1383
+ },
1384
+ {
1385
+ value: "repeat",
1386
+ label: t("modeRepeat")
1387
+ },
1388
+ {
1389
+ value: "cron",
1390
+ label: t("modeCron")
1391
+ }
1392
+ ]
1393
+ })
1394
+ }),
1395
+ cadence.mode === "once" && /* @__PURE__ */ jsx(ui.Field, {
1396
+ label: t("runAt"),
1397
+ inline: true,
1398
+ children: (binding) => /* @__PURE__ */ jsxs("div", {
1399
+ className: "sch-date-time",
1400
+ children: [/* @__PURE__ */ jsx(ui.DatePicker, {
1401
+ id: binding.id,
1402
+ labelledBy: binding["aria-labelledby"],
1403
+ value: cadence.date,
1404
+ min: dateOf(Date.now()),
1405
+ onChange: (date) => {
1406
+ const earliest = nowTime();
1407
+ onCadence(isToday(date) && (cadence.time.hour < earliest.hour || cadence.time.hour === earliest.hour && cadence.time.minute < earliest.minute) ? {
1408
+ date,
1409
+ time: earliest
1410
+ } : { date });
1411
+ }
1412
+ }), /* @__PURE__ */ jsx(ui.TimePicker, {
1413
+ labelledBy: binding["aria-labelledby"],
1414
+ value: cadence.time,
1415
+ ...isToday(cadence.date) ? { min: nowTime() } : {},
1416
+ onChange: (time) => onCadence({ time })
1417
+ })]
1418
+ })
1419
+ }),
1420
+ cadence.mode === "repeat" && /* @__PURE__ */ jsxs(Fragment, { children: [
1421
+ /* @__PURE__ */ jsx(ui.Field, {
1422
+ label: t("frequency"),
1423
+ inline: true,
1424
+ children: (binding) => /* @__PURE__ */ jsx("div", {
1425
+ className: "sch-select",
1426
+ children: /* @__PURE__ */ jsxs(ui.Select, {
1427
+ className: "sch-full-width",
1428
+ ...binding,
1429
+ value: cadence.frequency,
1430
+ onValueChange: (frequency) => onCadence({ frequency }),
1431
+ children: [
1432
+ /* @__PURE__ */ jsx("option", {
1433
+ value: "interval",
1434
+ children: t("frequencyInterval")
1435
+ }),
1436
+ /* @__PURE__ */ jsx("option", {
1437
+ value: "daily",
1438
+ children: t("frequencyDaily")
1439
+ }),
1440
+ /* @__PURE__ */ jsx("option", {
1441
+ value: "weekly",
1442
+ children: t("frequencyWeekly")
1443
+ }),
1444
+ /* @__PURE__ */ jsx("option", {
1445
+ value: "monthly",
1446
+ children: t("frequencyMonthly")
1447
+ })
1448
+ ]
1449
+ })
1450
+ })
1451
+ }),
1452
+ cadence.frequency === "interval" && /* @__PURE__ */ jsx(ui.Field, {
1453
+ label: t("interval"),
1454
+ inline: true,
1455
+ children: (binding) => /* @__PURE__ */ jsxs("div", {
1456
+ className: "sch-inline",
1457
+ children: [
1458
+ /* @__PURE__ */ jsx("span", {
1459
+ className: "sch-muted-text",
1460
+ children: t("every")
1461
+ }),
1462
+ /* @__PURE__ */ jsx("div", {
1463
+ className: "sch-number",
1464
+ children: /* @__PURE__ */ jsx(ui.InputNumber, {
1465
+ id: binding.id,
1466
+ label: t("interval"),
1467
+ incrementLabel: t("increase"),
1468
+ decrementLabel: t("decrease"),
1469
+ min: 1,
1470
+ step: 1,
1471
+ value: cadence.amount,
1472
+ onValueChange: (amount) => onCadence({ amount })
1473
+ })
1474
+ }),
1475
+ /* @__PURE__ */ jsx("div", {
1476
+ className: "sch-unit",
1477
+ children: /* @__PURE__ */ jsxs(ui.Select, {
1478
+ className: "sch-full-width",
1479
+ "aria-label": t("unit"),
1480
+ value: cadence.unit,
1481
+ onValueChange: (unit) => onCadence({ unit }),
1482
+ children: [/* @__PURE__ */ jsx("option", {
1483
+ value: "minute",
1484
+ children: t("unitMinute")
1485
+ }), /* @__PURE__ */ jsx("option", {
1486
+ value: "hour",
1487
+ children: t("unitHour")
1488
+ })]
1489
+ })
1490
+ })
1491
+ ]
1492
+ })
1493
+ }),
1494
+ cadence.frequency === "weekly" && /* @__PURE__ */ jsx(ui.Field, {
1495
+ label: t("weekdays"),
1496
+ inline: true,
1497
+ children: (binding) => /* @__PURE__ */ jsx(ui.WeekdayPicker, {
1498
+ labelledBy: binding["aria-labelledby"],
1499
+ value: cadence.weekdays,
1500
+ onChange: (weekdays) => onCadence({ weekdays })
1501
+ })
1502
+ }),
1503
+ cadence.frequency === "monthly" && /* @__PURE__ */ jsx(ui.Field, {
1504
+ label: t("monthDay"),
1505
+ help: t("monthDayHelp"),
1506
+ inline: true,
1507
+ children: (binding) => /* @__PURE__ */ jsxs("div", {
1508
+ className: "sch-inline",
1509
+ children: [/* @__PURE__ */ jsx("div", {
1510
+ className: "sch-number",
1511
+ children: /* @__PURE__ */ jsx(ui.InputNumber, {
1512
+ id: binding.id,
1513
+ label: t("monthDay"),
1514
+ incrementLabel: t("increase"),
1515
+ decrementLabel: t("decrease"),
1516
+ min: 1,
1517
+ max: 31,
1518
+ step: 1,
1519
+ value: cadence.monthDay,
1520
+ onValueChange: (monthDay) => onCadence({ monthDay })
1521
+ })
1522
+ }), /* @__PURE__ */ jsx("span", {
1523
+ className: "sch-muted-text",
1524
+ children: t("monthDaySuffix")
1525
+ })]
1526
+ })
1527
+ }),
1528
+ cadence.frequency !== "interval" && /* @__PURE__ */ jsx(ui.Field, {
1529
+ label: t("timeOfDay"),
1530
+ inline: true,
1531
+ children: (binding) => /* @__PURE__ */ jsx(ui.TimePicker, {
1532
+ id: binding.id,
1533
+ labelledBy: binding["aria-labelledby"],
1534
+ value: cadence.time,
1535
+ onChange: (time) => onCadence({ time })
1536
+ })
1537
+ })
1538
+ ] }),
1539
+ cadence.mode === "cron" && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(ui.Field, {
1540
+ label: t("expression"),
1541
+ help: t("expressionHelp"),
1542
+ inline: true,
1543
+ children: (binding) => /* @__PURE__ */ jsx(ui.Input, {
1544
+ ...binding,
1545
+ value: cadence.expression,
1546
+ spellCheck: false,
1547
+ autoComplete: "off",
1548
+ placeholder: "0 9 * * 1-5",
1549
+ className: "sch-mono",
1550
+ onChange: (event) => onCadence({ expression: event.target.value })
1551
+ })
1552
+ }), /* @__PURE__ */ jsx(ui.Field, {
1553
+ label: t("timezone"),
1554
+ inline: true,
1555
+ children: (binding) => /* @__PURE__ */ jsx(ui.Combobox, {
1556
+ id: binding.id,
1557
+ "aria-labelledby": binding["aria-labelledby"],
1558
+ label: t("timezone"),
1559
+ options: zones,
1560
+ value: cadence.timezone,
1561
+ onValueChange: (timezone) => timezone !== null && onCadence({ timezone }),
1562
+ emptyLabel: t("timezoneEmpty"),
1563
+ toggleLabel: t("timezone")
1564
+ })
1565
+ })] }),
1566
+ /* @__PURE__ */ jsxs("div", {
1567
+ "data-slot": "schedule-preview",
1568
+ className: "sch-preview",
1569
+ children: [/* @__PURE__ */ jsx("span", {
1570
+ className: "sch-muted-text sch-preview-term",
1571
+ children: t("upcoming")
1572
+ }), problem !== null ? /* @__PURE__ */ jsx("span", {
1573
+ className: "sch-danger",
1574
+ children: t(`invalid.${problem}`)
1575
+ }) : preview === null ? /* @__PURE__ */ jsx("span", {
1576
+ className: "sch-muted-text",
1577
+ children: "—"
1578
+ }) : "error" in preview ? /* @__PURE__ */ jsx("span", {
1579
+ className: "sch-danger",
1580
+ children: (() => {
1581
+ const named = problemOfRefusal(preview.error);
1582
+ return named === null ? preview.error : t(`invalid.${named}`);
1583
+ })()
1584
+ }) : at === null ? /* @__PURE__ */ jsx("span", {
1585
+ className: "sch-danger",
1586
+ children: t("invalid.timezone")
1587
+ }) : /* @__PURE__ */ jsxs("ul", {
1588
+ className: "sch-preview-list",
1589
+ children: [preview.next.map((next) => /* @__PURE__ */ jsx("li", {
1590
+ className: "sch-tabular",
1591
+ children: at.format(next)
1592
+ }, next)), zone !== null && /* @__PURE__ */ jsx("li", {
1593
+ className: "sch-muted-text",
1594
+ children: t("inTimezone", { zone })
1595
+ })]
1596
+ })]
1597
+ }),
1598
+ /* @__PURE__ */ jsx(ui.Field, {
1599
+ label: t("catchUp"),
1600
+ help: t("catchUpHelp"),
1601
+ inline: true,
1602
+ children: () => /* @__PURE__ */ jsx(ui.Segmented, {
1603
+ fullWidth: true,
1604
+ label: t("catchUp"),
1605
+ value: catchUp ? "catch-up" : "skip",
1606
+ onSelect: (value) => onCatchUp(value === "catch-up"),
1607
+ options: [{
1608
+ value: "catch-up",
1609
+ label: t("catchUpRun")
1610
+ }, {
1611
+ value: "skip",
1612
+ label: t("catchUpSkip")
1613
+ }]
1614
+ })
1615
+ })
1616
+ ]
1617
+ });
1618
+ }
1619
+ //#endregion
1620
+ //#region src/ui/editor.tsx
1621
+ /**
1622
+ * The dialog that creates or changes a scheduled task.
1623
+ *
1624
+ * Three tabs: 基本信息 (name, agent, instruction, where it runs), 执行计划
1625
+ * (`timing.tsx`) and 预授权 (`scope.tsx`), which says why it is empty while
1626
+ * runs go into an existing session — such a run carries no scope. Saving with
1627
+ * something missing marks each tab that still needs attention and opens the
1628
+ * first of them; a refusal stays in the footer beside the action that caused
1629
+ * it.
1630
+ *
1631
+ * It writes through the core's `trigger.create` / `trigger.update`, the
1632
+ * definition's `config` being this plugin's `{ rule, catchUp }`.
1633
+ */
1634
+ var TABS = [
1635
+ "basics",
1636
+ "timing",
1637
+ "scope"
1638
+ ];
1639
+ function draftOf(trigger, agentId) {
1640
+ const now = Date.now();
1641
+ const config = trigger === null ? null : configOf(trigger.config);
1642
+ const rule = config?.rule ?? null;
1643
+ return {
1644
+ name: trigger?.name ?? "",
1645
+ agentId: trigger?.agentId ?? agentId,
1646
+ cadence: cadenceOf(rule, now),
1647
+ anchor: rule?.kind === "interval" ? rule.anchor : now,
1648
+ instruction: trigger?.instruction ?? "",
1649
+ targetKind: trigger?.target.kind ?? "new-session",
1650
+ sessionId: trigger?.target.kind === "session" ? trigger.target.sessionId : "",
1651
+ catchUp: config?.catchUp ?? true,
1652
+ scope: [...trigger?.scope ?? []]
1653
+ };
1654
+ }
1655
+ /** The input a complete draft stands for; null while something is missing. */
1656
+ function inputOf(draft, workspaceId) {
1657
+ const rule = ruleOf(draft.cadence, draft.anchor);
1658
+ if (rule === null || draft.name.trim() === "" || draft.instruction.trim() === "" || draft.targetKind === "session" && draft.sessionId === "") return null;
1659
+ return {
1660
+ name: draft.name.trim(),
1661
+ agentId: draft.agentId,
1662
+ workspaceId,
1663
+ config: {
1664
+ rule,
1665
+ catchUp: draft.catchUp
1666
+ },
1667
+ instruction: draft.instruction.trim(),
1668
+ target: draft.targetKind === "session" ? {
1669
+ kind: "session",
1670
+ sessionId: draft.sessionId
1671
+ } : { kind: "new-session" },
1672
+ scope: draft.targetKind === "session" ? [] : [...draft.scope]
1673
+ };
1674
+ }
1675
+ function EditorBody({ trigger, workspaceId, onClose }) {
1676
+ const { ctx, words } = useEnv();
1677
+ const { t } = words;
1678
+ const ui = ctx.ui;
1679
+ const agents = useSchedule((state) => state.agents);
1680
+ const sessions = useSchedule((state) => state.sessions);
1681
+ const tasks = useSchedule((state) => state.tasks) ?? [];
1682
+ const [draft, setDraft] = useState(() => draftOf(trigger, agents.find((one) => one.startsSessions)?.agentId ?? agents[0]?.agentId ?? ""));
1683
+ const [pending, setPending] = useState(false);
1684
+ const saving = useRef(false);
1685
+ const [failure, setFailure] = useState(null);
1686
+ const [tab, setTab] = useState("basics");
1687
+ const [attempted, setAttempted] = useState(false);
1688
+ const set = (patch) => setDraft((current) => ({
1689
+ ...current,
1690
+ ...patch
1691
+ }));
1692
+ const input = inputOf(draft, trigger?.workspaceId ?? workspaceId);
1693
+ const optionLabel = (one) => {
1694
+ const title = sessionTitle(one, tasks, t("untitled"));
1695
+ return one.name !== null && one.title !== null ? `${title} · ${one.title}` : title;
1696
+ };
1697
+ const workspaceSessions = sessions.filter((one) => one.workspaceId === (trigger?.workspaceId ?? workspaceId) && one.parentSessionId === void 0);
1698
+ async function save(ready) {
1699
+ if (saving.current) return;
1700
+ saving.current = true;
1701
+ setPending(true);
1702
+ setFailure(null);
1703
+ try {
1704
+ if (trigger === null) await ctx.call("trigger.create", {
1705
+ ...ready,
1706
+ source: SOURCE
1707
+ });
1708
+ else await ctx.call("trigger.update", {
1709
+ ...ready,
1710
+ id: trigger.id
1711
+ });
1712
+ onClose();
1713
+ } catch (error) {
1714
+ const text = failureText$1(ctx, error);
1715
+ const named = text === null ? null : problemOfRefusal(text);
1716
+ setFailure(named === null ? text : t(`invalid.${named}`));
1717
+ } finally {
1718
+ saving.current = false;
1719
+ setPending(false);
1720
+ }
1721
+ }
1722
+ const missing = {
1723
+ name: draft.name.trim() === "",
1724
+ instruction: draft.instruction.trim() === "",
1725
+ session: draft.targetKind === "session" && draft.sessionId === ""
1726
+ };
1727
+ const incomplete = {
1728
+ basics: missing.name || missing.instruction || missing.session,
1729
+ timing: problemOf(draft.cadence) !== null,
1730
+ scope: false
1731
+ };
1732
+ const required = (gap) => attempted && gap ? t("required") : void 0;
1733
+ const tabLabel = (key, label) => /* @__PURE__ */ jsxs(Fragment, { children: [label, attempted && incomplete[key] && /* @__PURE__ */ jsx("span", {
1734
+ "aria-hidden": "true",
1735
+ className: "sch-tab-mark"
1736
+ })] });
1737
+ return /* @__PURE__ */ jsxs("form", {
1738
+ "data-slot": "schedule-editor",
1739
+ className: "sch-editor",
1740
+ noValidate: true,
1741
+ onSubmit: (event) => {
1742
+ event.preventDefault();
1743
+ if (input === null) {
1744
+ setAttempted(true);
1745
+ setTab(TABS.find((key) => incomplete[key]) ?? tab);
1746
+ return;
1747
+ }
1748
+ save(input);
1749
+ },
1750
+ children: [/* @__PURE__ */ jsxs(ui.Tabs, {
1751
+ value: tab,
1752
+ onValueChange: (next) => setTab(next),
1753
+ children: [
1754
+ /* @__PURE__ */ jsxs(ui.TabsList, {
1755
+ "aria-label": trigger === null ? t("createTitle") : t("editTitle"),
1756
+ children: [
1757
+ /* @__PURE__ */ jsx(ui.TabsTrigger, {
1758
+ value: "basics",
1759
+ children: tabLabel("basics", t("sectionBasics"))
1760
+ }),
1761
+ /* @__PURE__ */ jsx(ui.TabsTrigger, {
1762
+ value: "timing",
1763
+ children: tabLabel("timing", t("sectionTiming"))
1764
+ }),
1765
+ /* @__PURE__ */ jsx(ui.TabsTrigger, {
1766
+ value: "scope",
1767
+ children: tabLabel("scope", t("sectionScope"))
1768
+ })
1769
+ ]
1770
+ }),
1771
+ /* @__PURE__ */ jsx(ui.TabsContent, {
1772
+ value: "basics",
1773
+ children: /* @__PURE__ */ jsxs("div", {
1774
+ className: "sch-panel",
1775
+ children: [
1776
+ /* @__PURE__ */ jsx(ui.Field, {
1777
+ label: t("name"),
1778
+ required: true,
1779
+ inline: true,
1780
+ error: required(missing.name),
1781
+ children: (binding) => /* @__PURE__ */ jsx(ui.Input, {
1782
+ ...binding,
1783
+ value: draft.name,
1784
+ maxLength: 80,
1785
+ placeholder: t("namePlaceholder"),
1786
+ onChange: (event) => set({ name: event.target.value })
1787
+ })
1788
+ }),
1789
+ /* @__PURE__ */ jsx(ui.Field, {
1790
+ label: t("agent"),
1791
+ required: true,
1792
+ inline: true,
1793
+ children: (binding) => /* @__PURE__ */ jsx(ui.Select, {
1794
+ className: "sch-full-width",
1795
+ ...binding,
1796
+ value: draft.agentId,
1797
+ onValueChange: (agentId) => set({ agentId }),
1798
+ children: agents.map((agent) => /* @__PURE__ */ jsx("option", {
1799
+ value: agent.agentId,
1800
+ children: /* @__PURE__ */ jsxs("span", {
1801
+ className: "sch-agent-option",
1802
+ children: [/* @__PURE__ */ jsx(AgentFace, {
1803
+ agentId: agent.agentId,
1804
+ size: "sm"
1805
+ }), /* @__PURE__ */ jsx("span", {
1806
+ className: "sch-agent-name",
1807
+ children: agent.name
1808
+ })]
1809
+ })
1810
+ }, agent.agentId))
1811
+ })
1812
+ }),
1813
+ /* @__PURE__ */ jsx(ui.Field, {
1814
+ label: t("instruction"),
1815
+ required: true,
1816
+ inline: true,
1817
+ error: required(missing.instruction),
1818
+ children: (binding) => /* @__PURE__ */ jsx(ui.Textarea, {
1819
+ ...binding,
1820
+ rows: 6,
1821
+ maxLength: 8e3,
1822
+ value: draft.instruction,
1823
+ placeholder: t("instructionPlaceholder"),
1824
+ onChange: (event) => set({ instruction: event.target.value })
1825
+ })
1826
+ }),
1827
+ /* @__PURE__ */ jsx(ui.Field, {
1828
+ label: t("target"),
1829
+ inline: true,
1830
+ children: () => /* @__PURE__ */ jsx(ui.Segmented, {
1831
+ fullWidth: true,
1832
+ label: t("target"),
1833
+ value: draft.targetKind,
1834
+ onSelect: (targetKind) => set({ targetKind }),
1835
+ options: [{
1836
+ value: "new-session",
1837
+ label: t("targetNew")
1838
+ }, {
1839
+ value: "session",
1840
+ label: t("targetSession")
1841
+ }]
1842
+ })
1843
+ }),
1844
+ draft.targetKind === "session" && /* @__PURE__ */ jsx(ui.Field, {
1845
+ label: t("session"),
1846
+ required: true,
1847
+ inline: true,
1848
+ error: required(missing.session),
1849
+ children: (binding) => /* @__PURE__ */ jsxs(ui.Select, {
1850
+ className: "sch-full-width",
1851
+ ...binding,
1852
+ value: draft.sessionId,
1853
+ onValueChange: (sessionId) => set({ sessionId }),
1854
+ children: [/* @__PURE__ */ jsx("option", {
1855
+ value: "",
1856
+ disabled: true,
1857
+ children: t("sessionPlaceholder")
1858
+ }), workspaceSessions.map((one) => /* @__PURE__ */ jsx("option", {
1859
+ value: one.sessionId,
1860
+ children: optionLabel(one)
1861
+ }, one.sessionId))]
1862
+ })
1863
+ })
1864
+ ]
1865
+ })
1866
+ }),
1867
+ /* @__PURE__ */ jsx(ui.TabsContent, {
1868
+ value: "timing",
1869
+ children: /* @__PURE__ */ jsx("div", {
1870
+ className: "sch-panel",
1871
+ children: /* @__PURE__ */ jsx(Timing, {
1872
+ cadence: draft.cadence,
1873
+ anchor: draft.anchor,
1874
+ catchUp: draft.catchUp,
1875
+ onCadence: (patch) => setDraft((current) => ({
1876
+ ...current,
1877
+ cadence: {
1878
+ ...current.cadence,
1879
+ ...patch
1880
+ }
1881
+ })),
1882
+ onCatchUp: (catchUp) => set({ catchUp })
1883
+ })
1884
+ })
1885
+ }),
1886
+ /* @__PURE__ */ jsx(ui.TabsContent, {
1887
+ value: "scope",
1888
+ children: /* @__PURE__ */ jsxs("div", {
1889
+ className: "sch-panel",
1890
+ children: [/* @__PURE__ */ jsx("p", {
1891
+ className: "sch-muted-text",
1892
+ children: t(draft.targetKind === "session" ? "scopeUnavailable" : "scopeHelp")
1893
+ }), draft.targetKind === "new-session" && /* @__PURE__ */ jsx(Scope, {
1894
+ value: draft.scope,
1895
+ onChange: (scope) => set({ scope })
1896
+ })]
1897
+ })
1898
+ })
1899
+ ]
1900
+ }), /* @__PURE__ */ jsxs("div", {
1901
+ className: "sch-editor-foot",
1902
+ children: [failure !== null && /* @__PURE__ */ jsx("p", {
1903
+ role: "alert",
1904
+ className: "sch-danger sch-grow",
1905
+ children: failure
1906
+ }), /* @__PURE__ */ jsxs("div", {
1907
+ className: "sch-foot-actions",
1908
+ children: [/* @__PURE__ */ jsx(ui.Button, {
1909
+ type: "button",
1910
+ variant: "ghost",
1911
+ onClick: onClose,
1912
+ children: t("cancel")
1913
+ }), /* @__PURE__ */ jsx(ui.Button, {
1914
+ type: "submit",
1915
+ variant: "primary",
1916
+ disabled: pending,
1917
+ loading: pending,
1918
+ children: t(trigger === null ? "createAction" : "save")
1919
+ })]
1920
+ })]
1921
+ })]
1922
+ });
1923
+ }
1924
+ /** `editing` is the task being changed, `'new'` for a new one, null for closed. */
1925
+ function ScheduleEditor({ editing, workspaceId, onClose }) {
1926
+ const { ctx, words } = useEnv();
1927
+ return /* @__PURE__ */ jsx(ctx.ui.Dialog, {
1928
+ open: editing !== null,
1929
+ onOpenChange: (open) => !open && onClose(),
1930
+ title: editing === "new" ? words.t("createTitle") : words.t("editTitle"),
1931
+ closeLabel: words.t("close"),
1932
+ children: editing !== null && /* @__PURE__ */ jsx(EditorBody, {
1933
+ trigger: editing === "new" ? null : editing,
1934
+ workspaceId,
1935
+ onClose
1936
+ })
1937
+ });
1938
+ }
1939
+ //#endregion
1940
+ //#region src/ui/page.tsx
1941
+ /** Pause or resume, and delete: from the list and from the detail alike. */
1942
+ function useTaskActions(trigger) {
1943
+ const { ctx, store } = useEnv();
1944
+ const pending = useSchedule((state) => !!state.pendingActions[trigger.id]);
1945
+ const fail = useFailureToast();
1946
+ const run = (intent, call) => {
1947
+ store.runTaskAction(trigger.id, intent, call).catch((error) => fail(error));
1948
+ };
1949
+ return {
1950
+ pending,
1951
+ toggle: () => run(`enabled:${!trigger.enabled}`, (operationId) => ctx.call("trigger.setEnabled", {
1952
+ operationId,
1953
+ ids: [trigger.id],
1954
+ enabled: !trigger.enabled
1955
+ })),
1956
+ remove: () => run("remove", (operationId) => ctx.call("trigger.remove", {
1957
+ operationId,
1958
+ ids: [trigger.id]
1959
+ }))
1960
+ };
1961
+ }
1962
+ function IconAction({ label, icon, onClick, onBlur, className, pending = false }) {
1963
+ const { ctx } = useEnv();
1964
+ return /* @__PURE__ */ jsx(ctx.ui.Tooltip, {
1965
+ content: label,
1966
+ children: /* @__PURE__ */ jsx(ctx.ui.Button, {
1967
+ variant: "ghost",
1968
+ size: "sm",
1969
+ type: "button",
1970
+ "aria-label": label,
1971
+ disabled: pending,
1972
+ loading: pending,
1973
+ "aria-busy": pending,
1974
+ onClick,
1975
+ ...onBlur === void 0 ? {} : { onBlur },
1976
+ className: `sch-icon-action${className === void 0 ? "" : ` ${className}`}`,
1977
+ children: /* @__PURE__ */ jsx(ctx.ui.Icon, { name: icon })
1978
+ })
1979
+ });
1980
+ }
1981
+ function Row({ trigger, selected, onSelect }) {
1982
+ const { ctx, words } = useEnv();
1983
+ const { t, locale } = words;
1984
+ const next = useSchedule((state) => state.next[trigger.id]);
1985
+ const state = stateOf(trigger, next, words);
1986
+ const actions = useTaskActions(trigger);
1987
+ const rule = configOf(trigger.config)?.rule ?? null;
1988
+ const [confirming, setConfirming] = useState(false);
1989
+ return /* @__PURE__ */ jsxs("li", {
1990
+ "data-trigger": trigger.id,
1991
+ "data-selected": selected || void 0,
1992
+ "data-confirming": confirming || void 0,
1993
+ className: "sch-task",
1994
+ children: [
1995
+ /* @__PURE__ */ jsx(AgentFace, {
1996
+ agentId: trigger.agentId,
1997
+ size: "lg"
1998
+ }),
1999
+ /* @__PURE__ */ jsxs(ctx.ui.Button, {
2000
+ variant: "plain",
2001
+ type: "button",
2002
+ "aria-current": selected || void 0,
2003
+ onClick: onSelect,
2004
+ className: "sch-task-main",
2005
+ children: [/* @__PURE__ */ jsxs("span", {
2006
+ className: "sch-task-line",
2007
+ children: [/* @__PURE__ */ jsx("span", {
2008
+ className: "sch-task-name",
2009
+ "data-paused": !trigger.enabled || void 0,
2010
+ children: trigger.name
2011
+ }), state !== null && /* @__PURE__ */ jsx("span", {
2012
+ className: "sch-task-state",
2013
+ "data-tone": state.tone,
2014
+ children: state.text
2015
+ })]
2016
+ }), /* @__PURE__ */ jsx("span", {
2017
+ className: "sch-task-rule",
2018
+ children: [ruleText(rule, words), trigger.enabled && typeof next === "number" && rule?.kind !== "once" ? t("next", { at: when(next, locale) }) : null].filter((part) => part !== null).join(" · ")
2019
+ })]
2020
+ }),
2021
+ /* @__PURE__ */ jsxs("div", {
2022
+ "data-slot": "schedule-actions",
2023
+ className: "sch-task-actions",
2024
+ children: [/* @__PURE__ */ jsx(IconAction, {
2025
+ label: trigger.enabled ? t("pause") : t("resume"),
2026
+ icon: trigger.enabled ? "pause" : "play",
2027
+ pending: actions.pending,
2028
+ onClick: actions.toggle
2029
+ }), /* @__PURE__ */ jsx(IconAction, {
2030
+ label: confirming ? t("confirmDelete") : t("delete"),
2031
+ icon: "trash",
2032
+ pending: actions.pending,
2033
+ onClick: () => confirming ? actions.remove() : setConfirming(true),
2034
+ onBlur: () => setConfirming(false),
2035
+ className: confirming ? "sch-danger-action sch-armed" : "sch-danger-action"
2036
+ })]
2037
+ })
2038
+ ]
2039
+ });
2040
+ }
2041
+ function TaskList({ tasks, selectedId, onSelect, onCreate, hidden }) {
2042
+ const { words } = useEnv();
2043
+ const { t } = words;
2044
+ return /* @__PURE__ */ jsxs("aside", {
2045
+ "data-slot": "schedule-list",
2046
+ "aria-label": t("list"),
2047
+ className: "sch-list",
2048
+ "data-narrow-hidden": hidden || void 0,
2049
+ children: [/* @__PURE__ */ jsxs("div", {
2050
+ className: "sch-list-head",
2051
+ children: [/* @__PURE__ */ jsx("h2", { children: t("nav") }), /* @__PURE__ */ jsx(IconAction, {
2052
+ label: t("create"),
2053
+ icon: "plus",
2054
+ onClick: onCreate
2055
+ })]
2056
+ }), /* @__PURE__ */ jsx("div", {
2057
+ className: "sch-list-body",
2058
+ children: tasks.length > 0 && /* @__PURE__ */ jsx("ul", {
2059
+ className: "sch-tasks",
2060
+ children: tasks.map((trigger) => /* @__PURE__ */ jsx(Row, {
2061
+ trigger,
2062
+ selected: trigger.id === selectedId,
2063
+ onSelect: () => onSelect(trigger.id)
2064
+ }, trigger.id))
2065
+ })
2066
+ })]
2067
+ });
2068
+ }
2069
+ /** A term and what it is, as one row of the overview. */
2070
+ function Fact({ term, children }) {
2071
+ return /* @__PURE__ */ jsxs("div", {
2072
+ className: "sch-fact",
2073
+ children: [/* @__PURE__ */ jsx("dt", { children: term }), /* @__PURE__ */ jsx("dd", { children })]
2074
+ });
2075
+ }
2076
+ function ScopeLine({ item }) {
2077
+ const { ctx, words } = useEnv();
2078
+ const { t } = words;
2079
+ const icon = item.kind === "network" ? "network" : item.kind === "web-host" ? "globe" : "folder";
2080
+ return /* @__PURE__ */ jsxs("li", {
2081
+ className: "sch-scope-line",
2082
+ children: [
2083
+ /* @__PURE__ */ jsx(ctx.ui.Icon, {
2084
+ name: icon,
2085
+ className: "sch-row-icon"
2086
+ }),
2087
+ item.kind === "network" ? /* @__PURE__ */ jsx("span", {
2088
+ className: "sch-row-target",
2089
+ children: t("scopeNetwork")
2090
+ }) : /* @__PURE__ */ jsx("span", {
2091
+ className: "sch-row-target sch-mono",
2092
+ children: item.target
2093
+ }),
2094
+ (item.kind === "read" || item.kind === "write") && /* @__PURE__ */ jsx(ctx.ui.Badge, {
2095
+ size: "sm",
2096
+ tone: item.kind === "write" ? "warning" : "neutral",
2097
+ children: t(item.kind === "write" ? "scopeWrite" : "scopeRead")
2098
+ })
2099
+ ]
2100
+ });
2101
+ }
2102
+ function Runs({ trigger }) {
2103
+ const { ctx, words } = useEnv();
2104
+ const { t, locale } = words;
2105
+ const fail = useFailureToast();
2106
+ const [runs, setRuns] = useState(null);
2107
+ const [failed, setFailed] = useState(false);
2108
+ useEffect(() => {
2109
+ let live = true;
2110
+ setRuns(null);
2111
+ setFailed(false);
2112
+ const read = (first) => ctx.call("trigger.runs", { ids: [trigger.id] }).then((answer) => {
2113
+ const item = answer.results[0];
2114
+ if (!item) throw new Error("missing task run result");
2115
+ if (!item.ok) throw new Error(item.error.message);
2116
+ if (live) setRuns(item.value.runs);
2117
+ }).catch((error) => {
2118
+ if (!live || !first) return;
2119
+ setFailed(true);
2120
+ fail(error);
2121
+ });
2122
+ read(true);
2123
+ const off = ctx.onCore("trigger.runChanged", () => void read(false));
2124
+ return () => {
2125
+ live = false;
2126
+ off();
2127
+ };
2128
+ }, [
2129
+ ctx,
2130
+ trigger.id,
2131
+ fail
2132
+ ]);
2133
+ if (runs === null) return failed ? null : /* @__PURE__ */ jsx("p", {
2134
+ className: "sch-muted-text",
2135
+ children: t("loading")
2136
+ });
2137
+ if (runs.length === 0) return /* @__PURE__ */ jsx("p", {
2138
+ className: "sch-muted-text",
2139
+ children: t("noRuns")
2140
+ });
2141
+ return /* @__PURE__ */ jsx("ul", {
2142
+ "data-slot": "schedule-runs",
2143
+ className: "sch-runs",
2144
+ children: runs.map((run) => /* @__PURE__ */ jsxs("li", {
2145
+ "data-run": run.id,
2146
+ className: "sch-run",
2147
+ children: [
2148
+ /* @__PURE__ */ jsx("span", {
2149
+ className: "sch-run-at sch-tabular",
2150
+ children: when(run.startedAt, locale)
2151
+ }),
2152
+ /* @__PURE__ */ jsx("span", {
2153
+ className: "sch-run-kind",
2154
+ children: t(`runKind.${run.kind}`)
2155
+ }),
2156
+ /* @__PURE__ */ jsx("span", {
2157
+ className: "sch-run-state",
2158
+ "data-state": run.state,
2159
+ children: runStateText(run, words)
2160
+ }),
2161
+ run.sessionId !== null && /* @__PURE__ */ jsx(ctx.ui.Button, {
2162
+ size: "sm",
2163
+ variant: "ghost",
2164
+ type: "button",
2165
+ onClick: () => ctx.navigation.openSession(run.sessionId),
2166
+ children: t("openSession")
2167
+ })
2168
+ ]
2169
+ }, run.id))
2170
+ });
2171
+ }
2172
+ function TaskDetail({ trigger, onEdit, onBack }) {
2173
+ const { ctx, words } = useEnv();
2174
+ const { t, locale } = words;
2175
+ const ui = ctx.ui;
2176
+ const agents = useSchedule((state) => state.agents);
2177
+ const sessions = useSchedule((state) => state.sessions);
2178
+ const tasks = useSchedule((state) => state.tasks);
2179
+ const next = useSchedule((state) => state.next[trigger.id]);
2180
+ const [confirming, setConfirming] = useState(false);
2181
+ const [tab, setTab] = useState("overview");
2182
+ const agentName = (id) => agents.find((one) => one.agentId === id)?.name ?? id;
2183
+ const state = stateOf(trigger, next, words);
2184
+ const config = configOf(trigger.config);
2185
+ const actions = useTaskActions(trigger);
2186
+ useEffect(() => setConfirming(false), [trigger.id]);
2187
+ const target = trigger.target.kind === "new-session" ? t("targetNew") : (() => {
2188
+ const { sessionId } = trigger.target;
2189
+ const session = sessions.find((one) => one.sessionId === sessionId);
2190
+ return session === void 0 ? t("targetSession") : sessionTitle(session, tasks ?? [], t("untitled"));
2191
+ })();
2192
+ const nextText = trigger.enabled && typeof next === "number" ? when(next, locale) : null;
2193
+ return /* @__PURE__ */ jsxs("div", {
2194
+ "data-slot": "schedule-detail",
2195
+ className: "sch-detail",
2196
+ children: [/* @__PURE__ */ jsx("header", {
2197
+ className: "sch-detail-head",
2198
+ children: /* @__PURE__ */ jsxs("div", {
2199
+ className: "sch-detail-title",
2200
+ children: [
2201
+ /* @__PURE__ */ jsx("span", {
2202
+ className: "sch-narrow-only",
2203
+ children: /* @__PURE__ */ jsx(ui.BackButton, {
2204
+ "aria-label": t("backToList"),
2205
+ onClick: onBack
2206
+ })
2207
+ }),
2208
+ /* @__PURE__ */ jsx(AgentFace, {
2209
+ agentId: trigger.agentId,
2210
+ size: "md"
2211
+ }),
2212
+ /* @__PURE__ */ jsxs("div", {
2213
+ className: "sch-grow",
2214
+ children: [/* @__PURE__ */ jsx("h1", { children: trigger.name }), /* @__PURE__ */ jsx("p", {
2215
+ "data-tone": state?.tone,
2216
+ children: state?.text ?? (nextText === null ? "—" : t("next", { at: nextText }))
2217
+ })]
2218
+ }),
2219
+ /* @__PURE__ */ jsxs("div", {
2220
+ className: "sch-detail-actions",
2221
+ children: [
2222
+ /* @__PURE__ */ jsx(IconAction, {
2223
+ label: trigger.enabled ? t("pause") : t("resume"),
2224
+ icon: trigger.enabled ? "pause" : "play",
2225
+ pending: actions.pending,
2226
+ onClick: actions.toggle
2227
+ }),
2228
+ /* @__PURE__ */ jsx(IconAction, {
2229
+ label: t("edit"),
2230
+ icon: "pencil",
2231
+ pending: actions.pending,
2232
+ onClick: onEdit
2233
+ }),
2234
+ confirming ? /* @__PURE__ */ jsx(ui.Button, {
2235
+ type: "button",
2236
+ variant: "ghost",
2237
+ size: "sm",
2238
+ className: "sch-danger-action sch-armed",
2239
+ onBlur: () => setConfirming(false),
2240
+ disabled: actions.pending,
2241
+ loading: actions.pending,
2242
+ "aria-busy": actions.pending,
2243
+ onClick: actions.remove,
2244
+ children: t("confirmDelete")
2245
+ }) : /* @__PURE__ */ jsx(IconAction, {
2246
+ label: t("delete"),
2247
+ icon: "trash",
2248
+ pending: actions.pending,
2249
+ onClick: () => setConfirming(true),
2250
+ className: "sch-danger-action"
2251
+ })
2252
+ ]
2253
+ })
2254
+ ]
2255
+ })
2256
+ }), /* @__PURE__ */ jsx("div", {
2257
+ className: "sch-detail-body",
2258
+ children: /* @__PURE__ */ jsxs(ui.Tabs, {
2259
+ value: tab,
2260
+ onValueChange: (value) => setTab(value),
2261
+ children: [
2262
+ /* @__PURE__ */ jsxs(ui.TabsList, {
2263
+ "aria-label": trigger.name,
2264
+ children: [/* @__PURE__ */ jsx(ui.TabsTrigger, {
2265
+ value: "overview",
2266
+ children: t("overview")
2267
+ }), /* @__PURE__ */ jsx(ui.TabsTrigger, {
2268
+ value: "runs",
2269
+ children: t("runs")
2270
+ })]
2271
+ }),
2272
+ /* @__PURE__ */ jsx(ui.TabsContent, {
2273
+ value: "overview",
2274
+ children: /* @__PURE__ */ jsxs("div", {
2275
+ className: "sch-page",
2276
+ children: [/* @__PURE__ */ jsxs("dl", {
2277
+ className: "sch-facts",
2278
+ children: [
2279
+ /* @__PURE__ */ jsx(Fact, {
2280
+ term: t("sectionTiming"),
2281
+ children: ruleText(config?.rule ?? null, words)
2282
+ }),
2283
+ /* @__PURE__ */ jsx(Fact, {
2284
+ term: t("nextRun"),
2285
+ children: nextText ?? t("noNext")
2286
+ }),
2287
+ /* @__PURE__ */ jsx(Fact, {
2288
+ term: t("lastRun"),
2289
+ children: trigger.lastRun === null ? "—" : `${when(trigger.lastRun.startedAt, locale)} · ${runStateText(trigger.lastRun, words)}`
2290
+ }),
2291
+ /* @__PURE__ */ jsx(Fact, {
2292
+ term: t("agent"),
2293
+ children: agentName(trigger.agentId)
2294
+ }),
2295
+ /* @__PURE__ */ jsx(Fact, {
2296
+ term: t("target"),
2297
+ children: target
2298
+ }),
2299
+ /* @__PURE__ */ jsx(Fact, {
2300
+ term: t("catchUp"),
2301
+ children: t(config?.catchUp === false ? "off" : "on")
2302
+ }),
2303
+ trigger.target.kind === "new-session" && /* @__PURE__ */ jsx(Fact, {
2304
+ term: t("sectionScope"),
2305
+ children: trigger.scope.length === 0 ? t("scopeNone") : /* @__PURE__ */ jsx("ul", {
2306
+ className: "sch-scope-lines",
2307
+ children: trigger.scope.map((item) => /* @__PURE__ */ jsx(ScopeLine, { item }, `${item.kind}:${item.target}`))
2308
+ })
2309
+ }),
2310
+ /* @__PURE__ */ jsx(Fact, {
2311
+ term: t("creator"),
2312
+ children: trigger.createdBy.kind === "user" ? t("byYou") : t("byAgent", { name: agentName(trigger.createdBy.agentId) })
2313
+ })
2314
+ ]
2315
+ }), /* @__PURE__ */ jsxs("section", {
2316
+ className: "sch-section",
2317
+ children: [/* @__PURE__ */ jsx("h3", { children: t("instruction") }), /* @__PURE__ */ jsx("p", {
2318
+ className: "sch-instruction",
2319
+ children: trigger.instruction
2320
+ })]
2321
+ })]
2322
+ })
2323
+ }),
2324
+ /* @__PURE__ */ jsx(ui.TabsContent, {
2325
+ value: "runs",
2326
+ children: /* @__PURE__ */ jsx("div", {
2327
+ className: "sch-page",
2328
+ children: /* @__PURE__ */ jsx(Runs, { trigger })
2329
+ })
2330
+ })
2331
+ ]
2332
+ })
2333
+ })]
2334
+ });
2335
+ }
2336
+ /** Lists the selected workspace's tasks and offers the first-task action in its full-page empty state. */
2337
+ function SchedulesPage() {
2338
+ const { ctx, store, words } = useEnv();
2339
+ const { t } = words;
2340
+ const ui = ctx.ui;
2341
+ const workspaceId = useWorkspaceId();
2342
+ const tasks = useSchedule((state) => state.tasks);
2343
+ const failed = useSchedule((state) => state.tasksFailed);
2344
+ const [editing, setEditing] = useState(null);
2345
+ const [picked, setPicked] = useState(null);
2346
+ const [backed, setBacked] = useState(false);
2347
+ useEffect(() => store.retain(), [store]);
2348
+ if (workspaceId === null) return /* @__PURE__ */ jsx("div", {
2349
+ "data-slot": "schedules-page",
2350
+ className: "sch-page-root sch-centre",
2351
+ children: /* @__PURE__ */ jsx(ui.EmptyState, {
2352
+ title: t("empty"),
2353
+ description: t("noWorkspace")
2354
+ })
2355
+ });
2356
+ const shown = (tasks ?? []).filter((one) => one.workspaceId === workspaceId);
2357
+ const current = shown.find((one) => one.id === picked) ?? (backed ? null : shown[0] ?? null);
2358
+ return /* @__PURE__ */ jsxs("div", {
2359
+ "data-slot": "schedules-page",
2360
+ className: "sch-page-root",
2361
+ children: [
2362
+ /* @__PURE__ */ jsx(TaskList, {
2363
+ tasks: shown,
2364
+ selectedId: current?.id ?? null,
2365
+ onSelect: (id) => {
2366
+ setPicked(id);
2367
+ setBacked(false);
2368
+ },
2369
+ onCreate: () => setEditing("new"),
2370
+ hidden: current !== null || shown.length === 0
2371
+ }),
2372
+ /* @__PURE__ */ jsx("div", {
2373
+ className: "sch-main",
2374
+ "data-narrow-hidden": current === null && shown.length > 0 || void 0,
2375
+ children: current !== null ? /* @__PURE__ */ jsx(TaskDetail, {
2376
+ trigger: current,
2377
+ onEdit: () => setEditing(current),
2378
+ onBack: () => {
2379
+ setPicked(null);
2380
+ setBacked(true);
2381
+ }
2382
+ }) : failed ? /* @__PURE__ */ jsx("div", {
2383
+ className: "sch-centre",
2384
+ children: /* @__PURE__ */ jsx(ui.Alert, {
2385
+ tone: "destructive",
2386
+ role: "alert",
2387
+ children: /* @__PURE__ */ jsxs("div", {
2388
+ className: "sch-failure",
2389
+ children: [/* @__PURE__ */ jsx("p", { children: t("loadFailed") }), /* @__PURE__ */ jsx(ui.Button, {
2390
+ variant: "ghost",
2391
+ type: "button",
2392
+ onClick: store.reloadTasks,
2393
+ children: t("retry")
2394
+ })]
2395
+ })
2396
+ })
2397
+ }) : /* @__PURE__ */ jsx("div", {
2398
+ className: `sch-centre${shown.length === 0 ? " sch-page-empty" : ""}`,
2399
+ children: /* @__PURE__ */ jsx(ui.EmptyState, {
2400
+ title: t("empty"),
2401
+ description: t("emptyHint"),
2402
+ variant: shown.length === 0 ? "page" : "default",
2403
+ icon: shown.length === 0 ? "calendar-clock" : void 0,
2404
+ children: /* @__PURE__ */ jsx(ui.Button, {
2405
+ variant: "primary",
2406
+ icon: "plus",
2407
+ type: "button",
2408
+ onClick: () => setEditing("new"),
2409
+ children: t("create")
2410
+ })
2411
+ })
2412
+ })
2413
+ }),
2414
+ /* @__PURE__ */ jsx(ui.StatusBarArea, { className: "sch-status-area" }),
2415
+ /* @__PURE__ */ jsx(ScheduleEditor, {
2416
+ editing,
2417
+ workspaceId,
2418
+ onClose: () => setEditing(null)
2419
+ })
2420
+ ]
2421
+ });
2422
+ }
2423
+ //#endregion
2424
+ //#region src/ui/settings.tsx
2425
+ /** The bound `src/schedule/settings.ts` holds, restated for the page because
2426
+ * the browser module imports nothing from the Node half. */
2427
+ var AGENT_LIMIT_CEILING = 1e3;
2428
+ /** How long the field stays still before a value is written. */
2429
+ var SAVE_DELAY_MS = 500;
2430
+ function failureText(_ctx, error) {
2431
+ const failure = error?.failure;
2432
+ if (failure === "offline" || failure === "authentication") return null;
2433
+ return error instanceof Error ? error.message : String(error);
2434
+ }
2435
+ function valid(limit) {
2436
+ return limit !== null && Number.isInteger(limit) && limit >= 0 && limit <= AGENT_LIMIT_CEILING;
2437
+ }
2438
+ function settingsFor(ctx) {
2439
+ return function ScheduleSettingsPanel() {
2440
+ const connection = useSyncExternalStore(ctx.host.subscribe, () => ctx.host.get().connection);
2441
+ const t = ctx.i18n.t;
2442
+ const toast = ctx.ui.useToast();
2443
+ const [draft, setDraft] = useState(void 0);
2444
+ const [readFailure, setReadFailure] = useState(null);
2445
+ const [attempt, setAttempt] = useState(0);
2446
+ const [saving, setSaving] = useState(false);
2447
+ const writes = useRef(Promise.resolve());
2448
+ const sequence = useRef(0);
2449
+ const alive = useRef(true);
2450
+ const submitted = useRef(void 0);
2451
+ const stored = useRef(void 0);
2452
+ const waiting = useRef(null);
2453
+ useEffect(() => {
2454
+ let live = true;
2455
+ setReadFailure(null);
2456
+ if (connection !== "online") return;
2457
+ ctx.invoke("getScheduleSettings", {}).then((settings) => {
2458
+ if (!live) return;
2459
+ stored.current = settings.agentLimit;
2460
+ setDraft(settings.agentLimit);
2461
+ }, (error) => {
2462
+ if (live) setReadFailure(failureText(ctx, error));
2463
+ });
2464
+ return () => {
2465
+ live = false;
2466
+ };
2467
+ }, [attempt, connection]);
2468
+ const write = (value, mounted) => {
2469
+ if (value === submitted.current || submitted.current === void 0 && value === stored.current) return;
2470
+ submitted.current = value;
2471
+ const request = ++sequence.current;
2472
+ if (mounted) setSaving(true);
2473
+ writes.current = writes.current.then(async () => {
2474
+ try {
2475
+ const settings = await ctx.invoke("setScheduleSettings", { agentLimit: value });
2476
+ stored.current = settings.agentLimit;
2477
+ } catch (error) {
2478
+ if (request === sequence.current) {
2479
+ submitted.current = void 0;
2480
+ if (mounted && alive.current && waiting.current === null && stored.current !== void 0) setDraft(stored.current);
2481
+ }
2482
+ const text = failureText(ctx, error);
2483
+ if (text !== null) toast.add({
2484
+ tone: "destructive",
2485
+ title: text
2486
+ });
2487
+ } finally {
2488
+ if (request === sequence.current && mounted && alive.current) setSaving(false);
2489
+ }
2490
+ });
2491
+ };
2492
+ useEffect(() => {
2493
+ alive.current = true;
2494
+ return () => {
2495
+ alive.current = false;
2496
+ const pending = waiting.current;
2497
+ if (pending === null) return;
2498
+ clearTimeout(pending.timer);
2499
+ waiting.current = null;
2500
+ write(pending.value, false);
2501
+ };
2502
+ }, []);
2503
+ const edit = (value) => {
2504
+ setDraft(value);
2505
+ if (waiting.current !== null) clearTimeout(waiting.current.timer);
2506
+ waiting.current = null;
2507
+ if (!valid(value)) return;
2508
+ const timer = setTimeout(() => {
2509
+ waiting.current = null;
2510
+ write(value, true);
2511
+ }, 500);
2512
+ waiting.current = {
2513
+ timer,
2514
+ value
2515
+ };
2516
+ };
2517
+ return /* @__PURE__ */ jsxs(ctx.ui.SettingsPanel, {
2518
+ title: t("creation"),
2519
+ children: [
2520
+ draft === void 0 && readFailure === null && /* @__PURE__ */ jsx("p", {
2521
+ role: "status",
2522
+ className: "sch-muted-text",
2523
+ children: t("loading")
2524
+ }),
2525
+ readFailure !== null && /* @__PURE__ */ jsx(ctx.ui.Alert, {
2526
+ tone: "destructive",
2527
+ role: "alert",
2528
+ children: /* @__PURE__ */ jsxs("div", {
2529
+ className: "schedule-error",
2530
+ children: [/* @__PURE__ */ jsx("p", { children: readFailure }), /* @__PURE__ */ jsx(ctx.ui.Button, {
2531
+ variant: "ghost",
2532
+ type: "button",
2533
+ onClick: () => setAttempt((n) => n + 1),
2534
+ children: t("retry")
2535
+ })]
2536
+ })
2537
+ }),
2538
+ draft !== void 0 && /* @__PURE__ */ jsx(ctx.ui.SettingsPanel, {
2539
+ title: t("agentLimit"),
2540
+ hint: t("agentLimitHelp"),
2541
+ level: "field",
2542
+ inline: true,
2543
+ children: /* @__PURE__ */ jsxs("div", {
2544
+ className: "schedule-control",
2545
+ children: [/* @__PURE__ */ jsxs("div", {
2546
+ className: "schedule-input-row",
2547
+ children: [/* @__PURE__ */ jsx(ctx.ui.InputNumber, {
2548
+ label: t("agentLimit"),
2549
+ incrementLabel: t("increase"),
2550
+ decrementLabel: t("decrease"),
2551
+ min: 0,
2552
+ max: AGENT_LIMIT_CEILING,
2553
+ step: 1,
2554
+ value: draft,
2555
+ onValueChange: edit
2556
+ }), /* @__PURE__ */ jsx("span", {
2557
+ className: "schedule-save-indicator",
2558
+ children: saving && /* @__PURE__ */ jsx(ctx.ui.Spinner, {
2559
+ size: "sm",
2560
+ label: t("saving")
2561
+ })
2562
+ })]
2563
+ }), !valid(draft) && /* @__PURE__ */ jsx("p", {
2564
+ className: "schedule-invalid",
2565
+ children: t("invalidLimit")
2566
+ })]
2567
+ })
2568
+ })
2569
+ ]
2570
+ });
2571
+ };
2572
+ }
2573
+ //#endregion
2574
+ //#region src/ui/index.tsx
2575
+ /** The host compares this against its own before calling `register`. */
2576
+ var runtimeVersion = 5;
2577
+ var STYLES = `
2578
+ .schedule-control { display: flex; min-width: 0; flex-direction: column; align-items: flex-end; gap: .25rem; }
2579
+ .schedule-control > * { width: 10.25rem; }
2580
+ .schedule-input-row { display: flex; align-items: center; gap: .5rem; }
2581
+ .schedule-input-row > :first-child { min-width: 0; width: 9rem; }
2582
+ .schedule-save-indicator { display: inline-flex; width: .75rem; flex: none; }
2583
+ .schedule-invalid { font-size: .75rem; color: var(--destructive); text-align: end; }
2584
+ .schedule-error, .sch-failure { display: flex; min-width: 0; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .5rem; }
2585
+
2586
+ .sch-page-root { display: grid; grid-template-columns: 18rem minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; height: 100%; min-height: 0; width: 100%; font-size: .875rem; }
2587
+ .sch-centre { display: flex; min-height: 0; flex: 1; align-items: center; justify-content: center; padding: 0 2rem; }
2588
+ .sch-page-empty { padding: 0; }
2589
+ .sch-list { grid-column: 1; grid-row: 1 / span 2; z-index: 10; display: flex; height: 100%; width: 18rem; flex-shrink: 0; flex-direction: column; border-inline-end: 1px solid var(--border); background: var(--background); }
2590
+ .sch-list-head { display: flex; height: 3.5rem; flex-shrink: 0; align-items: center; justify-content: space-between; gap: .75rem; padding: 0 .75rem; }
2591
+ .sch-list-head h2 { margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .875rem; font-weight: 600; line-height: 1.25rem; }
2592
+ .sch-list-body { min-height: 0; flex: 1; overflow-y: auto; padding: 0 .75rem .5rem; }
2593
+ .sch-tasks { display: flex; flex-direction: column; gap: .25rem; margin: 0; padding: 0; list-style: none; }
2594
+ .sch-task { --row-fill: var(--background); position: relative; display: flex; align-items: center; gap: .625rem; overflow: hidden; padding: .5rem; border-radius: var(--radius-control); transition: background-color 150ms ease; }
2595
+ .sch-task:hover { --row-fill: var(--muted); background: var(--muted); }
2596
+ .sch-task[data-selected] { --row-fill: var(--accent); background: var(--accent); }
2597
+ .sch-task-main { display: flex; min-width: 0; flex: 1; flex-direction: column; align-items: stretch; text-align: start; outline: none; }
2598
+ .sch-task-line { display: flex; min-width: 0; align-items: baseline; gap: .5rem; }
2599
+ .sch-task-name { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.25rem; color: var(--foreground); }
2600
+ .sch-task-name[data-paused] { color: var(--muted-foreground); }
2601
+ .sch-task-state { flex-shrink: 0; font-size: .75rem; color: var(--muted-foreground); }
2602
+ .sch-task-state[data-tone=destructive] { color: var(--destructive); }
2603
+ .sch-task-rule { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .75rem; line-height: 1.25rem; color: var(--muted-foreground); }
2604
+ .sch-task-actions { pointer-events: none; position: absolute; inset-block: 0; inset-inline-end: 0; display: flex; align-items: center; padding-inline: 4rem .5rem; background: linear-gradient(to right, transparent, var(--row-fill) 1.75rem); opacity: 0; transition: opacity 150ms ease; }
2605
+ .sch-task-actions > * { pointer-events: auto; }
2606
+ .sch-task:is(:hover, :focus-within, [data-confirming]) .sch-task-actions { opacity: 1; }
2607
+ @media (hover: none) { .sch-task-actions { opacity: 1; } }
2608
+ .sch-icon-action { aspect-ratio: 1; padding: 0; color: var(--muted-foreground); }
2609
+ .sch-icon-action:hover { color: var(--foreground); }
2610
+ .sch-danger-action:hover, .sch-armed { color: var(--destructive); }
2611
+
2612
+ .sch-main { grid-column: 2; grid-row: 1; position: relative; display: flex; height: 100%; min-height: 0; min-width: 0; flex: 1; flex-direction: column; }
2613
+ .sch-status-area { grid-column: 2; grid-row: 2; }
2614
+ .sch-detail { display: flex; min-height: 0; min-width: 0; flex: 1; flex-direction: column; }
2615
+ .sch-detail-head { flex-shrink: 0; padding: 0 1rem; border-bottom: 1px solid var(--border); background: var(--background); }
2616
+ .sch-detail-title { display: flex; height: 4rem; align-items: center; gap: .75rem; }
2617
+ .sch-detail-title h1 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1rem; font-weight: 500; }
2618
+ .sch-detail-title p { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .75rem; color: var(--muted-foreground); }
2619
+ .sch-detail-title p[data-tone=destructive] { color: var(--destructive); }
2620
+ .sch-detail-actions { display: flex; flex-shrink: 0; align-items: center; gap: .25rem; }
2621
+ .sch-detail-body { min-height: 0; flex: 1; overflow-y: auto; padding: .75rem 1rem 0; }
2622
+ .sch-page { margin: 0 auto; display: flex; width: 100%; max-width: 48rem; flex-direction: column; gap: 2rem; padding: 1.5rem .5rem; }
2623
+ .sch-facts { display: flex; flex-direction: column; margin: 0; }
2624
+ .sch-fact { display: grid; gap: .25rem 1rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
2625
+ .sch-fact:last-child { border-bottom: 0; }
2626
+ .sch-fact dt { color: var(--muted-foreground); }
2627
+ .sch-fact dd { min-width: 0; margin: 0; color: var(--foreground); }
2628
+ @media (min-width: 640px) { .sch-fact { grid-template-columns: 7rem minmax(0, 1fr); } }
2629
+ .sch-section { display: flex; min-width: 0; flex-direction: column; gap: .5rem; }
2630
+ .sch-section h3 { margin: 0; font-size: .875rem; font-weight: 600; }
2631
+ .sch-instruction { margin: 0; white-space: pre-wrap; padding: .5rem .75rem; border-radius: var(--radius-control); background: var(--muted); line-height: 1.5rem; }
2632
+ .sch-scope-lines { display: flex; flex-direction: column; gap: .375rem; margin: 0; padding: 0; list-style: none; }
2633
+ .sch-scope-line { display: flex; min-width: 0; align-items: center; gap: .5rem; }
2634
+ .sch-runs { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
2635
+ .sch-run { display: flex; align-items: center; gap: .75rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
2636
+ .sch-run:last-child { border-bottom: 0; }
2637
+ .sch-run-at { width: 11rem; flex-shrink: 0; color: var(--muted-foreground); }
2638
+ .sch-run-kind { width: 4rem; flex-shrink: 0; color: var(--muted-foreground); }
2639
+ .sch-run-state { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
2640
+ .sch-run-state[data-state=failed] { color: var(--destructive); }
2641
+ .sch-narrow-only { display: none; }
2642
+ @media (max-width: 767px) {
2643
+ .sch-page-root { grid-template-columns: minmax(0, 1fr); }
2644
+ .sch-list { grid-column: 1; grid-row: 1; width: 100%; }
2645
+ .sch-main { grid-column: 1; }
2646
+ .sch-status-area { grid-column: 1; }
2647
+ .sch-list[data-narrow-hidden], .sch-main[data-narrow-hidden] { display: none; }
2648
+ .sch-narrow-only { display: contents; }
2649
+ }
2650
+
2651
+ :scope[data-slot="dialog-content"]:has(.sch-path-form) { width: 32rem; }
2652
+ .sch-editor { display: flex; min-width: 0; flex-direction: column; gap: 1rem; }
2653
+ .sch-panel, .sch-stack { display: flex; min-width: 0; flex-direction: column; gap: 1rem; padding-top: .75rem; }
2654
+ .sch-stack { padding-top: 0; }
2655
+ .sch-tab-mark { display: inline-block; width: .375rem; height: .375rem; margin-inline-start: .375rem; border-radius: 999px; background: var(--destructive); vertical-align: middle; }
2656
+ .sch-editor-foot { display: flex; align-items: center; gap: .75rem; padding-top: 1rem; border-top: 1px solid var(--border); }
2657
+ .sch-foot-actions, .sch-foot { display: flex; flex-shrink: 0; justify-content: flex-end; gap: .5rem; margin-inline-start: auto; }
2658
+ .sch-grow { min-width: 0; flex: 1; }
2659
+ .sch-inline { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
2660
+ .sch-select, .sch-full-width { width: 100%; }
2661
+ .sch-agent-option { display: inline-flex; min-width: 0; max-width: 100%; align-items: center; gap: .5rem; vertical-align: middle; }
2662
+ .sch-agent-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
2663
+ .sch-date-time { display: flex; flex-wrap: wrap; gap: .5rem; }
2664
+ .sch-date-time > button { flex: 1 1 10rem; }
2665
+ .sch-number { width: 8rem; }
2666
+ .sch-unit { width: 6rem; }
2667
+ .sch-preview { display: grid; gap: 0 1rem; font-size: .75rem; line-height: 1.25rem; }
2668
+ @media (min-width: 640px) { .sch-preview { grid-template-columns: 7rem minmax(0, 1fr); } }
2669
+ @media (max-width: 639px) { .sch-preview-term { display: none; } }
2670
+ .sch-preview-list { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; color: var(--foreground); }
2671
+ .sch-scope-list { display: flex; min-width: 0; flex-direction: column; gap: .5rem; }
2672
+ .sch-scope-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
2673
+ .sch-rows { display: flex; flex-direction: column; gap: .125rem; margin: 0 -.75rem; padding: 0; list-style: none; }
2674
+ .sch-row { display: flex; min-width: 0; align-items: center; gap: .75rem; padding: .375rem .75rem; border-radius: var(--radius-control); }
2675
+ .sch-row:hover { background: var(--muted); }
2676
+ .sch-row-icon { width: 1rem; height: 1rem; flex-shrink: 0; color: var(--muted-foreground); }
2677
+ .sch-row-target { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
2678
+ .sch-row-action { aspect-ratio: 1; padding: 0; color: var(--muted-foreground); opacity: 0; transition: opacity 150ms ease; }
2679
+ .sch-row:is(:hover, :focus-within) .sch-row-action { opacity: 1; }
2680
+ .sch-row-action:hover { color: var(--destructive); }
2681
+ @media (hover: none) { .sch-row-action { opacity: 1; } }
2682
+
2683
+ .sch-mono { font-family: var(--font-mono, ui-monospace, monospace); font-size: .75rem; }
2684
+ .sch-muted-text { margin: 0; font-size: .75rem; line-height: 1.6; color: var(--muted-foreground); }
2685
+ .sch-danger { margin: 0; font-size: .75rem; color: var(--destructive); }
2686
+ .sch-tabular { font-variant-numeric: tabular-nums; }
2687
+ `;
2688
+ /** Registers the page, the settings category and their scoped presentation. */
2689
+ var register = (ctx) => {
2690
+ registerMetadata(ctx);
2691
+ ctx.i18n.register(CATALOGUES$1, "en-US");
2692
+ ctx.styles.add(STYLES);
2693
+ const env = envOf(ctx, createScheduleStore(ctx));
2694
+ ctx.slots.register("shell.nav.page", {
2695
+ id: "schedules",
2696
+ order: 10,
2697
+ label: () => ctx.i18n.t("nav"),
2698
+ icon: "calendar-clock",
2699
+ component: function SchedulesNavPage() {
2700
+ return /* @__PURE__ */ jsx(EnvProvider, {
2701
+ value: env,
2702
+ children: /* @__PURE__ */ jsx(SchedulesPage, {})
2703
+ });
2704
+ }
2705
+ });
2706
+ ctx.slots.register("shell.settings.category", {
2707
+ id: "schedule",
2708
+ label: () => ctx.i18n.t("heading"),
2709
+ region: "preset",
2710
+ order: 65,
2711
+ icon: "clock",
2712
+ component: settingsFor(ctx)
2713
+ });
2714
+ };
2715
+ //#endregion
2716
+ export { SAVE_DELAY_MS, register, runtimeVersion };