feat(web): manage independent schedules and restore recorded stage navigation

This commit is contained in:
2026-10-21 02:06:15 +01:00
parent 4ab49a2749
commit 1e4654381e
31 changed files with 843 additions and 52 deletions
+24 -7
View File
@@ -9,13 +9,14 @@ export function scheduleDraft({ pipeline, schedule = null, run = null, workspace
const { prompt = '', ...other } = input;
const rule = source.rule ?? {};
return {
name: schedule?.name ?? '', prompt, version: String(source.version ?? pipeline?.Version ?? pipeline?.version ?? pipeline?.Pipeline?.version ?? ''),
name: schedule?.name ?? run?.title ?? '', prompt, version: String(source.version ?? pipeline?.Version ?? pipeline?.version ?? pipeline?.Pipeline?.version ?? ''),
workspace: source.workspace ?? workspace, enabled: schedule?.enabled ?? true,
mode: rule.times?.length ? 'clock' : 'interval', every: rule.every ?? '24h',
times: (rule.times ?? []).join(', '), days: [...(rule.days ?? [])],
timezone: rule.timezone ?? (schedule ? '' : (timezone ?? Intl.DateTimeFormat().resolvedOptions().timeZone)),
model: source.model ?? '', stageModels: JSON.stringify(source.stage_models ?? {}, null, 2),
otherInput: JSON.stringify(other, null, 2), title: source.title ?? '',
writePaths: JSON.stringify(source.write_paths ?? [], null, 2), allowTools: source.allow_tools === true,
otherInput: JSON.stringify(other, null, 2), title: run?.title_source && !['explicit', 'user'].includes(run.title_source) ? '' : source.title ?? '',
notifyMode: source.notify_mode ?? 'auto', outputFormat: source.output_format ?? '',
};
}
@@ -39,6 +40,12 @@ export function serializeSchedule(draft, { pipelineId, schedule = null } = {}) {
if (!draft.workspace?.startsWith('/') || /[\0\r\n]/.test(draft.workspace)) throw new Error('Enter an absolute workspace path on the server.');
const input = parseScheduleObject(draft.otherInput, 'Other input');
const stageModels = parseScheduleObject(draft.stageModels, 'Stage models');
let writePaths;
try { writePaths = JSON.parse(draft.writePaths ?? '[]'); } catch { throw new Error('Write paths must be a JSON array.'); }
if (!Array.isArray(writePaths) || writePaths.length > 20 || writePaths.some(path =>
typeof path !== 'string' || !path || path.startsWith('/') || /[*?\\\0]/.test(path) || path.split('/').some(part => !part || part === '.' || part === '..'))) {
throw new Error('Write paths must be a JSON array of at most 20 exact server-workspace-relative paths.');
}
if (draft.model && !validScheduleModel(draft.model)) throw new Error('Model must be provider/model.');
for (const [key, model] of Object.entries(stageModels)) {
if (!key || !validScheduleModel(model)) throw new Error('Each stage model must be provider/model.');
@@ -60,9 +67,13 @@ export function serializeSchedule(draft, { pipelineId, schedule = null } = {}) {
if (!times.length || times.some(time => !/^([01]\d|2[0-3]):[0-5]\d$/.test(time)) || new Set(times).size !== times.length) throw new Error('Enter distinct 24-hour times, such as 09:00, 17:30.');
rule.times = times;
} else throw new Error('Choose an interval or clock times.');
if (draft.days.length) rule.days = [...draft.days];
if (draft.days.length) {
const prior = schedule?.rule?.days ?? [];
const unchanged = prior.length === draft.days.length && prior.every(day => draft.days.includes(day));
rule.days = unchanged ? [...prior] : [...draft.days];
}
if (draft.timezone.trim()) {
try { new Intl.DateTimeFormat('en', { timeZone: draft.timezone.trim() }); }
try { if (draft.timezone.trim() !== 'Local') new Intl.DateTimeFormat('en', { timeZone: draft.timezone.trim() }); }
catch { throw new Error('Enter a valid IANA timezone.'); }
rule.timezone = draft.timezone.trim();
}
@@ -70,6 +81,8 @@ export function serializeSchedule(draft, { pipelineId, schedule = null } = {}) {
name: draft.name.trim(), pipeline_id: schedule?.pipeline_id ?? pipelineId,
version, enabled: Boolean(draft.enabled), input: { ...input, prompt: draft.prompt },
workspace: draft.workspace, rule, notify_mode: draft.notifyMode };
if (writePaths.length) record.write_paths = writePaths; else delete record.write_paths;
if (draft.allowTools) record.allow_tools = true; else delete record.allow_tools;
for (const [key, value] of Object.entries({ model: draft.model, stage_models: stageModels, title: draft.title, output_format: draft.outputFormat })) {
if (typeof value === 'object' ? Object.keys(value).length : value !== '') record[key] = value;
else delete record[key];
@@ -79,11 +92,15 @@ export function serializeSchedule(draft, { pipelineId, schedule = null } = {}) {
export function scheduleRuleLabel(rule = {}) {
return [rule.every ? `Every ${rule.every}` : (rule.times ?? []).join(', '),
(rule.days ?? []).join(', '), rule.timezone || 'Server timezone'].filter(Boolean).join(' · ');
(rule.days ?? []).join(', '), rule.timezone && rule.timezone !== 'Local' ? rule.timezone : 'Server timezone'].filter(Boolean).join(' · ');
}
export function scheduleDueLabel(value) {
export function scheduleDueLabel(value, timeZone = '') {
if (!value) return 'Not scheduled';
const date = new Date(value);
return Number.isNaN(date.getTime()) ? 'Next time unavailable' : date.toLocaleString();
if (Number.isNaN(date.getTime())) return 'Next time unavailable';
if (timeZone && timeZone !== 'Local') {
try { return `${date.toLocaleString(undefined, { timeZone })} (${timeZone})`; } catch { /* Keep the absolute occurrence visible in local time. */ }
}
return `${date.toLocaleString()} (your local time)`;
}