feat(dashboard): expose cron job execution fields

This commit is contained in:
Versun 2026-06-27 15:57:50 +08:00 committed by Teknium
parent 50f6855217
commit c655cdf2c1
9 changed files with 1589 additions and 366 deletions

View file

@ -471,7 +471,8 @@ export const api = {
getDefaults: () => fetchJSON<Record<string, unknown>>("/api/config/defaults"),
getSchema: () => fetchJSON<{ fields: Record<string, unknown>; category_order: string[] }>("/api/config/schema"),
getModelInfo: () => fetchJSON<ModelInfoResponse>("/api/model/info"),
getModelOptions: () => fetchJSON<ModelOptionsResponse>("/api/model/options"),
getModelOptions: (profile?: string) =>
fetchJSON<ModelOptionsResponse>(`/api/model/options${profileQuery(profile)}`),
getAuxiliaryModels: () => fetchJSON<AuxiliaryModelsResponse>("/api/model/auxiliary"),
getMoaModels: () => fetchJSON<MoaConfigResponse>("/api/model/moa"),
saveMoaModels: (body: MoaConfigResponse) =>
@ -529,7 +530,7 @@ export const api = {
fetchJSON<CronJob[]>(`/api/cron/jobs?profile=${encodeURIComponent(profile)}`),
getCronDeliveryTargets: () =>
fetchJSON<{ targets: CronDeliveryTarget[] }>("/api/cron/delivery-targets"),
createCronJob: (job: { prompt: string; schedule: string; name?: string; deliver?: string; skills?: string[] }, profile = "default") =>
createCronJob: (job: CronJobMutation, profile = "default") =>
fetchJSON<CronJob>(`/api/cron/jobs?profile=${encodeURIComponent(profile)}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
@ -539,7 +540,7 @@ export const api = {
fetchJSON<CronJob>(`/api/cron/jobs/${encodeURIComponent(id)}/pause?profile=${encodeURIComponent(profile)}`, { method: "POST" }),
updateCronJob: (
id: string,
updates: { prompt?: string; schedule?: string; name?: string; deliver?: string; skills?: string[] },
updates: CronJobMutation,
profile = "default",
) =>
fetchJSON<CronJob>(
@ -1895,6 +1896,27 @@ export interface ModelsAnalyticsResponse {
period_days: number;
}
export interface CronJobRepeat {
times: number | null;
completed?: number;
}
export interface CronJobMutation {
name?: string;
prompt?: string;
schedule?: string;
deliver?: string;
skills?: string[];
provider?: string | null;
model?: string | null;
base_url?: string | null;
script?: string | null;
no_agent?: boolean;
context_from?: string[] | null;
enabled_toolsets?: string[] | null;
workdir?: string | null;
}
export interface CronJob {
id: string;
profile?: string | null;
@ -1905,14 +1927,24 @@ export interface CronJob {
prompt?: string | null;
script?: string | null;
skills?: string[] | null;
schedule?: { kind?: string; expr?: string; display?: string };
schedule?: { kind?: string; expr?: string; run_at?: string; display?: string };
schedule_display?: string | null;
repeat?: CronJobRepeat | null;
enabled: boolean;
state?: string | null;
deliver?: string | null;
model?: string | null;
provider?: string | null;
base_url?: string | null;
no_agent?: boolean | null;
context_from?: string[] | string | null;
enabled_toolsets?: string[] | null;
workdir?: string | null;
last_run_at?: string | null;
next_run_at?: string | null;
last_status?: string | null;
last_error?: string | null;
last_delivery_error?: string | null;
}
export interface CronDeliveryTarget {
@ -2049,6 +2081,7 @@ export interface ModelOptionProvider {
is_user_defined?: boolean;
source?: string;
warning?: string;
authenticated?: boolean;
}
export interface ModelOptionsResponse {

View file

@ -0,0 +1,123 @@
import { describe, expect, it } from "vitest";
import {
buildCronJobPayload,
cronJobHasExecutionContent,
cronJobFormFromJob,
splitCronList,
type CronJobFormState,
} from "./cron-job";
import type { CronJob } from "./api";
function form(overrides: Partial<CronJobFormState> = {}): CronJobFormState {
return {
name: "",
prompt: "prompt",
schedule: "every 1h",
deliver: "local",
skills: [],
provider: "",
model: "",
base_url: "",
script: "",
no_agent: false,
context_from: "",
enabled_toolsets: [],
workdir: "",
...overrides,
};
}
describe("splitCronList", () => {
it("normalizes comma and newline separated cron list fields", () => {
expect(splitCronList(" web, terminal\nfile ,, ")).toEqual([
"web",
"terminal",
"file",
]);
});
});
describe("buildCronJobPayload", () => {
it("normalizes list fields and base URLs", () => {
const payload = buildCronJobPayload(
form({
base_url: "https://example.invalid/v1/",
enabled_toolsets: ["web", ""],
context_from: "upstream-a\nupstream-b",
}),
);
expect(payload).toMatchObject({
base_url: "https://example.invalid/v1",
context_from: ["upstream-a", "upstream-b"],
enabled_toolsets: ["web"],
});
});
it("keeps clear operations explicit for update payloads", () => {
const payload = buildCronJobPayload(form({ schedule: "every 2h" }));
expect(payload).toMatchObject({
schedule: "every 2h",
provider: null,
model: null,
base_url: null,
script: null,
no_agent: false,
context_from: null,
enabled_toolsets: null,
workdir: null,
});
});
});
describe("cronJobHasExecutionContent", () => {
it("treats a script as execution content for agent-backed cron jobs", () => {
const payload = buildCronJobPayload(
form({ prompt: "", skills: [], script: "collect-status.py" }),
);
expect(cronJobHasExecutionContent(payload)).toBe(true);
});
it("rejects payloads with no prompt, skills, or script", () => {
const payload = buildCronJobPayload(form({ prompt: "", skills: [], script: "" }));
expect(cronJobHasExecutionContent(payload)).toBe(false);
});
});
describe("cronJobFormFromJob", () => {
it("preserves schedule fallback and editable list fields", () => {
const job: CronJob = {
id: "abc",
enabled: true,
schedule_display: "every 1h",
context_from: ["upstream-a", "upstream-b"],
enabled_toolsets: ["web"],
};
expect(cronJobFormFromJob(job)).toMatchObject({
schedule: "every 1h",
context_from: "upstream-a\nupstream-b",
enabled_toolsets: ["web"],
});
});
it("prefers one-shot run_at over the human display string", () => {
const job: CronJob = {
id: "once-job",
enabled: true,
schedule: {
kind: "once",
run_at: "2026-02-03T14:00:00+08:00",
},
schedule_display: "once at 2026-02-03 14:00",
};
expect(cronJobFormFromJob(job)).toMatchObject({
schedule: "2026-02-03T14:00:00+08:00",
});
});
});

99
web/src/lib/cron-job.ts Normal file
View file

@ -0,0 +1,99 @@
import type { CronJob, CronJobMutation } from "./api";
export interface CronJobFormState {
name: string;
prompt: string;
schedule: string;
deliver: string;
skills: string[];
provider: string;
model: string;
base_url: string;
script: string;
no_agent: boolean;
context_from: string;
enabled_toolsets: string[];
workdir: string;
}
export function splitCronList(value: unknown): string[] {
if (Array.isArray(value)) {
return value.map((item) => String(item).trim()).filter(Boolean);
}
if (typeof value !== "string") return [];
return value
.split(/[\n,]/)
.map((item) => item.trim())
.filter(Boolean);
}
function optionalText(value: string): string | null {
const text = value.trim();
return text || null;
}
function optionalBaseUrl(value: string): string | null {
const text = optionalText(value);
return text ? text.replace(/\/+$/, "") : null;
}
function listToText(value: unknown, separator: string): string {
if (Array.isArray(value)) {
return value.map((item) => String(item).trim()).filter(Boolean).join(separator);
}
return typeof value === "string" ? value : "";
}
export function buildCronJobPayload(form: CronJobFormState): CronJobMutation {
const contextFrom = splitCronList(form.context_from);
const enabledToolsets = form.enabled_toolsets.filter(Boolean);
return {
name: form.name.trim(),
prompt: form.prompt.trim(),
schedule: form.schedule.trim(),
deliver: form.deliver.trim() || "local",
skills: form.skills.filter(Boolean),
provider: optionalText(form.provider),
model: optionalText(form.model),
base_url: optionalBaseUrl(form.base_url),
script: optionalText(form.script),
no_agent: Boolean(form.no_agent),
context_from: contextFrom.length > 0 ? contextFrom : null,
enabled_toolsets: enabledToolsets.length > 0 ? enabledToolsets : null,
workdir: optionalText(form.workdir),
};
}
export function cronJobHasExecutionContent(
job: Pick<CronJobMutation, "prompt" | "skills" | "script">,
): boolean {
const prompt = typeof job.prompt === "string" ? job.prompt.trim() : "";
const script = typeof job.script === "string" ? job.script.trim() : "";
const skills = Array.isArray(job.skills)
? job.skills.map((skill) => String(skill).trim()).filter(Boolean)
: [];
return Boolean(prompt || script || skills.length > 0);
}
export function cronJobFormFromJob(job: CronJob): CronJobFormState {
return {
name: typeof job.name === "string" ? job.name : "",
prompt: typeof job.prompt === "string" ? job.prompt : "",
schedule:
(typeof job.schedule?.expr === "string" && job.schedule.expr) ||
(typeof job.schedule?.run_at === "string" && job.schedule.run_at) ||
(typeof job.schedule_display === "string" ? job.schedule_display : ""),
deliver: typeof job.deliver === "string" && job.deliver ? job.deliver : "local",
skills: Array.isArray(job.skills) ? job.skills.filter(Boolean) : [],
provider: typeof job.provider === "string" ? job.provider : "",
model: typeof job.model === "string" ? job.model : "",
base_url: typeof job.base_url === "string" ? job.base_url : "",
script: typeof job.script === "string" ? job.script : "",
no_agent: Boolean(job.no_agent),
context_from: listToText(job.context_from, "\n"),
enabled_toolsets: Array.isArray(job.enabled_toolsets)
? job.enabled_toolsets.filter(Boolean)
: splitCronList(job.enabled_toolsets),
workdir: typeof job.workdir === "string" ? job.workdir : "",
};
}

View file

@ -0,0 +1,123 @@
import { describe, expect, it } from "vitest";
import {
buildScheduleString,
DEFAULT_SCHEDULE_STATE,
parseScheduleString,
} from "./schedule";
describe("parseScheduleString", () => {
it("parses recurring interval strings", () => {
expect(parseScheduleString("every 30m")).toMatchObject({
mode: "interval",
intervalValue: 30,
intervalUnit: "minutes",
});
expect(parseScheduleString("every 2h")).toMatchObject({
mode: "interval",
intervalValue: 2,
intervalUnit: "hours",
});
expect(parseScheduleString("every 1d")).toMatchObject({
mode: "interval",
intervalValue: 1,
intervalUnit: "days",
});
});
it("parses ISO timestamps into once mode", () => {
expect(parseScheduleString("2026-02-03T14:00:00")).toMatchObject({
mode: "once",
onceAt: "2026-02-03T14:00",
});
expect(parseScheduleString("2026-02-03T14:00")).toMatchObject({
mode: "once",
onceAt: "2026-02-03T14:00",
});
});
it("parses daily cron expressions", () => {
expect(parseScheduleString("0 9 * * *")).toMatchObject({
mode: "daily",
timeOfDay: "09:00",
});
});
it("parses weekly cron expressions", () => {
expect(parseScheduleString("30 14 * * 1,3,5")).toMatchObject({
mode: "weekly",
timeOfDay: "14:30",
weekdays: [1, 3, 5],
});
});
it("normalizes cron Sunday 7 into the builder's Sunday 0", () => {
expect(parseScheduleString("30 14 * * 1,7")).toMatchObject({
mode: "weekly",
timeOfDay: "14:30",
weekdays: [1, 0],
});
});
it("parses monthly cron expressions", () => {
expect(parseScheduleString("0 9 15 * *")).toMatchObject({
mode: "monthly",
timeOfDay: "09:00",
dayOfMonth: 15,
});
});
it("falls back to custom for unsupported schedule strings", () => {
expect(parseScheduleString("0 9 * * 1-5")).toMatchObject({
mode: "custom",
custom: "0 9 * * 1-5",
});
expect(parseScheduleString("@daily")).toMatchObject({
mode: "custom",
custom: "@daily",
});
expect(parseScheduleString("2026-02-03T14:00:00Z")).toMatchObject({
mode: "custom",
custom: "2026-02-03T14:00:00Z",
});
expect(parseScheduleString("2026-02-03T14:00:00+08:00")).toMatchObject({
mode: "custom",
custom: "2026-02-03T14:00:00+08:00",
});
expect(parseScheduleString("0 9 * * 1,8")).toMatchObject({
mode: "custom",
custom: "0 9 * * 1,8",
});
expect(parseScheduleString("0 9 1,15 * *")).toMatchObject({
mode: "custom",
custom: "0 9 1,15 * *",
});
});
it("returns the default state for empty input", () => {
expect(parseScheduleString("")).toEqual(DEFAULT_SCHEDULE_STATE);
});
});
describe("buildScheduleString round-trip", () => {
it("rebuilds the schedule string from parsed state", () => {
const cases: [string, string][] = [
["every 30m", "every 30m"],
["every 2h", "every 2h"],
["every 1d", "every 1d"],
["0 9 * * *", "0 9 * * *"],
["30 14 * * 1,3,5", "30 14 * * 1,3,5"],
["30 14 * * 1,7", "30 14 * * 0,1"],
["0 9 15 * *", "0 9 15 * *"],
["0 9 1,15 * *", "0 9 1,15 * *"],
["2026-02-03T14:00:00", "2026-02-03T14:00:00"],
["2026-02-03T14:00", "2026-02-03T14:00:00"],
["2026-02-03T14:00:00Z", "2026-02-03T14:00:00Z"],
["2026-02-03T14:00:00+08:00", "2026-02-03T14:00:00+08:00"],
];
for (const [input, expected] of cases) {
const state = parseScheduleString(input);
expect(buildScheduleString(state)).toBe(expected);
}
});
});

View file

@ -147,6 +147,134 @@ export function buildScheduleString(state: ScheduleBuilderState): string {
}
}
/** Parse schedules emitted by buildScheduleString; unknown strings stay custom. */
export function parseScheduleString(
schedule: string,
): ScheduleBuilderState {
const trimmed = schedule.trim();
if (!trimmed) return { ...DEFAULT_SCHEDULE_STATE };
// ISO timestamp (one-shot).
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2})?$/.test(trimmed)) {
return {
...DEFAULT_SCHEDULE_STATE,
mode: "once",
onceAt: trimmed.slice(0, 16),
};
}
// Recurring interval.
const intervalMatch = /^every\s+(\d+)\s*([mhd])$/i.exec(trimmed);
if (intervalMatch) {
const value = Number.parseInt(intervalMatch[1], 10);
const suffix = intervalMatch[2].toLowerCase();
const unit: IntervalUnit =
suffix === "d" ? "days" : suffix === "h" ? "hours" : "minutes";
return {
...DEFAULT_SCHEDULE_STATE,
mode: "interval",
intervalValue: Number.isFinite(value) && value > 0 ? value : 1,
intervalUnit: unit,
};
}
// 5-field cron expression.
const parsedCron = parseSimpleCronExpression(trimmed);
if (parsedCron) {
if (parsedCron.mode === "daily") {
return { ...DEFAULT_SCHEDULE_STATE, mode: "daily", timeOfDay: parsedCron.time };
}
if (parsedCron.mode === "weekly") {
return {
...DEFAULT_SCHEDULE_STATE,
mode: "weekly",
timeOfDay: parsedCron.time,
weekdays: parsedCron.weekdays ?? [],
};
}
return {
...DEFAULT_SCHEDULE_STATE,
mode: "monthly",
timeOfDay: parsedCron.time,
dayOfMonth: parsedCron.dayOfMonth ?? 1,
};
}
// Fallback: preserve the raw string in custom mode.
return { ...DEFAULT_SCHEDULE_STATE, mode: "custom", custom: trimmed };
}
/**
* Shared helper: recognise the simple, well-shaped 5-field cron patterns
* that both the human-readable describer and the schedule builder care
* about. Returns a structured result or ``null`` when the expression has
* ranges, steps, per-month rules, or other complexity.
*/
function parseSimpleCronExpression(
expr: string,
): { mode: "daily" | "weekly" | "monthly"; time: string; weekdays?: Weekday[]; dayOfMonth?: number } | null {
const parts = expr.trim().split(/\s+/);
if (parts.length !== 5) return null;
const [minField, hourField, domField, monField, dowField] = parts;
if (monField !== "*") return null;
const isLiteralOrList = (f: string) => /^\d+(,\d+)*$|^\*$/.test(f);
if (
!isLiteralOrList(minField) ||
!isLiteralOrList(hourField) ||
!isLiteralOrList(domField) ||
!isLiteralOrList(dowField)
) {
return null;
}
if (minField === "*" || hourField === "*") return null;
const minutes = minField.split(",").map((n) => parseInt(n, 10));
const hours = hourField.split(",").map((n) => parseInt(n, 10));
if (minutes.length !== 1 || hours.length !== 1) return null;
if (
!Number.isFinite(minutes[0]) ||
!Number.isFinite(hours[0]) ||
hours[0] < 0 ||
hours[0] > 23 ||
minutes[0] < 0 ||
minutes[0] > 59
) {
return null;
}
const time = `${pad2(hours[0])}:${pad2(minutes[0])}`;
const domAll = domField === "*";
const dowAll = dowField === "*";
if (domAll && dowAll) {
return { mode: "daily", time };
}
if (domAll && !dowAll) {
const weekdays: Weekday[] = [];
for (const part of dowField.split(",")) {
const day = parseInt(part, 10);
if (!Number.isFinite(day) || day < 0 || day > 7) return null;
const normalized = (day === 7 ? 0 : day) as Weekday;
if (!weekdays.includes(normalized)) weekdays.push(normalized);
}
if (weekdays.length === 0) return null;
return { mode: "weekly", time, weekdays };
}
if (!domAll && dowAll) {
if (!/^\d+$/.test(domField)) return null;
const dom = parseInt(domField, 10);
if (!Number.isFinite(dom) || dom < 1 || dom > 31) return null;
return { mode: "monthly", time, dayOfMonth: dom };
}
return null;
}
function parseTimeOfDay(value: string): { hour: number; minute: number } | null {
if (!value || !/^\d{1,2}:\d{2}$/.test(value)) return null;
const [hh, mm] = value.split(":");
@ -273,71 +401,26 @@ function describeCronExpression(
expr: string,
strings: ScheduleDescribeStrings,
): string | null {
const parts = expr.trim().split(/\s+/);
if (parts.length !== 5) return null;
const [minField, hourField, domField, monField, dowField] = parts;
const parsed = parseSimpleCronExpression(expr);
if (!parsed) return null;
const month = monField === "*";
if (!month) return null; // we don't try to humanize per-month rules
const isLiteralOrList = (f: string) =>
/^\d+(,\d+)*$/.test(f) || /^\*$/.test(f);
if (!isLiteralOrList(minField) || !isLiteralOrList(hourField)) return null;
if (!isLiteralOrList(domField) || !isLiteralOrList(dowField)) return null;
// Star minutes/hours would mean "every minute" / "every hour" — we'd
// need a step-value handler ("*/15") to describe that cleanly, and
// that path is power-user territory. Bail to raw display.
if (minField === "*" || hourField === "*") return null;
const minutes = minField.split(",").map((n) => parseInt(n, 10));
const hours = hourField.split(",").map((n) => parseInt(n, 10));
if (minutes.length !== 1 || hours.length !== 1) return null;
if (
!Number.isFinite(minutes[0]) ||
!Number.isFinite(hours[0]) ||
hours[0] < 0 ||
hours[0] > 23 ||
minutes[0] < 0 ||
minutes[0] > 59
) {
return null;
}
const time = `${pad2(hours[0])}:${pad2(minutes[0])}`;
const domAll = domField === "*";
const dowAll = dowField === "*";
if (domAll && dowAll) {
return strings.dailyAt.replace("{time}", time);
if (parsed.mode === "daily") {
return strings.dailyAt.replace("{time}", parsed.time);
}
if (domAll && !dowAll) {
const days = dowField
.split(",")
.map((n) => parseInt(n, 10))
.filter((n) => Number.isFinite(n) && n >= 0 && n <= 6) as Weekday[];
if (days.length === 0) return null;
const labels = days
if (parsed.mode === "weekly") {
const labels = (parsed.weekdays ?? [])
.map((d) => strings.weekdaysShort[d])
.filter(Boolean)
.join(", ");
return strings.weeklyAt
.replace("{days}", labels)
.replace("{time}", time);
.replace("{time}", parsed.time);
}
if (!domAll && dowAll) {
const dom = parseInt(domField, 10);
if (!Number.isFinite(dom) || dom < 1 || dom > 31) return null;
return strings.monthlyAt
.replace("{day}", strings.ordinal(dom))
.replace("{time}", time);
}
// Both day-of-month AND day-of-week set is unusual and cron's
// OR-semantics for that combo are confusing — fall back to raw.
return null;
return strings.monthlyAt
.replace("{day}", strings.ordinal(parsed.dayOfMonth ?? 1))
.replace("{time}", parsed.time);
}
function pad2(n: number): string {

View file

@ -6,7 +6,20 @@ import { Select, SelectOption } from "@nous-research/ui/ui/components/select";
import { Spinner } from "@nous-research/ui/ui/components/spinner";
import { H2 } from "@nous-research/ui/ui/components/typography/h2";
import { api } from "@/lib/api";
import type { CronJob, CronDeliveryTarget, ProfileInfo, SkillInfo } from "@/lib/api";
import type {
CronJob,
CronDeliveryTarget,
ModelOptionsResponse,
ProfileInfo,
SkillInfo,
ToolsetInfo,
} from "@/lib/api";
import {
buildCronJobPayload,
cronJobHasExecutionContent,
cronJobFormFromJob,
type CronJobFormState,
} from "@/lib/cron-job";
import { DeleteConfirmDialog } from "@/components/DeleteConfirmDialog";
import {
DEFAULT_SCHEDULE_STATE,
@ -16,6 +29,7 @@ import {
buildScheduleString,
describeSchedule,
englishOrdinal,
parseScheduleString,
type ScheduleBuilderState,
type ScheduleDescribeStrings,
} from "@/lib/schedule";
@ -53,14 +67,7 @@ function getJobPrompt(job: CronJob): string {
return asText(job.prompt);
}
/** Compact multi-select for attaching skills to a cron job.
*
* A checkbox list (native inputs the `onValueChange` rule is Select-only)
* capped to a scrollable box. Skills already on the job but missing from the
* available list (e.g. removed from disk, or the job was created via CLI in
* another profile) are still rendered so saving doesn't silently drop them.
*/
function SkillsPicker({
function NameCheckboxPicker({
id,
available,
selected,
@ -68,12 +75,12 @@ function SkillsPicker({
emptyLabel,
}: {
id: string;
available: SkillInfo[];
available: Array<{ name: string; description?: string | null }>;
selected: string[];
onChange: (skills: string[]) => void;
onChange: (names: string[]) => void;
emptyLabel: string;
}) {
const names = available.map((s) => s.name);
const names = available.map((item) => item.name);
const orphaned = selected.filter((s) => !names.includes(s));
const all = [...orphaned.map((name) => ({ name, description: "" })), ...available];
@ -91,25 +98,332 @@ function SkillsPicker({
id={id}
className="max-h-36 overflow-y-auto border border-border bg-background/40 p-1"
>
{all.map((skill) => (
{all.map((item) => (
<label
key={skill.name}
key={item.name}
className="flex cursor-pointer items-center gap-2 px-2 py-1 text-xs hover:bg-muted/40"
title={skill.description || undefined}
title={item.description || undefined}
>
<input
type="checkbox"
className="accent-foreground"
checked={selected.includes(skill.name)}
onChange={(e) => toggle(skill.name, e.target.checked)}
checked={selected.includes(item.name)}
onChange={(e) => toggle(item.name, e.target.checked)}
/>
<span className="font-mono-ui truncate">{skill.name}</span>
<span className="font-mono-ui truncate">{item.name}</span>
</label>
))}
</div>
);
}
interface CronJobEditorState extends CronJobFormState {
scheduleState: ScheduleBuilderState;
}
interface CronJobFormResources {
availableSkills: SkillInfo[];
availableToolsets: ToolsetInfo[];
modelOptions: ModelOptionsResponse | null;
deliveryTargets: CronDeliveryTarget[];
}
function emptyCronJobForm(): CronJobEditorState {
return {
name: "",
prompt: "",
schedule: "",
deliver: "local",
skills: [],
provider: "",
model: "",
base_url: "",
script: "",
no_agent: false,
context_from: "",
enabled_toolsets: [],
workdir: "",
scheduleState: { ...DEFAULT_SCHEDULE_STATE },
};
}
function editorFormFromJob(job: CronJob): CronJobEditorState {
const form = cronJobFormFromJob(job);
return { ...form, scheduleState: parseScheduleString(form.schedule) };
}
function buildCronJobPayloadFromEditor(form: CronJobEditorState) {
const { scheduleState, ...payloadForm } = form;
return buildCronJobPayload({
...payloadForm,
schedule: buildScheduleString(scheduleState),
});
}
function selectOptions(
current: string,
options: Array<{ value: string; label: string }>,
) {
const known = new Set(options.map((option) => option.value));
return [
...options.map((option) => (
<SelectOption key={option.value} value={option.value}>
{option.label}
</SelectOption>
)),
...(current && !known.has(current)
? [
<SelectOption key={current} value={current}>
{current}
</SelectOption>,
]
: []),
];
}
function CronAdvancedFields({
idPrefix,
form,
onChange,
modelOptions,
availableToolsets,
}: {
idPrefix: string;
form: CronJobEditorState;
onChange: (form: CronJobEditorState) => void;
modelOptions: ModelOptionsResponse | null;
availableToolsets: ToolsetInfo[];
}) {
const update = <K extends keyof CronJobEditorState,>(
key: K,
next: CronJobEditorState[K],
) => {
onChange({ ...form, [key]: next });
};
const providers = (modelOptions?.providers ?? []).filter(
(p) => p.authenticated !== false,
);
const selectedProvider = providers.find((p) => p.slug === form.provider);
const models = selectedProvider?.models ?? [];
return (
<details className="border border-border bg-background/30 p-3" open>
<summary className="cursor-pointer text-xs font-medium uppercase tracking-wide text-muted-foreground">
Advanced fields
</summary>
<div className="mt-3 grid gap-3">
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div className="grid gap-1">
<Label htmlFor={`${idPrefix}-provider`}>Provider</Label>
<Select
id={`${idPrefix}-provider`}
value={form.provider}
onValueChange={(v) => {
onChange({ ...form, provider: v, model: "" });
}}
>
<SelectOption value="">Default</SelectOption>
{selectOptions(
form.provider,
providers.map((p) => ({ value: p.slug, label: p.name })),
)}
</Select>
</div>
<div className="grid gap-1">
<Label htmlFor={`${idPrefix}-model`}>Model</Label>
<Select
id={`${idPrefix}-model`}
value={form.model}
onValueChange={(v) => update("model", v)}
>
<SelectOption value="">Default</SelectOption>
{selectOptions(
form.model,
models.map((model) => ({ value: model, label: model })),
)}
</Select>
</div>
</div>
<div className="grid gap-1">
<Label htmlFor={`${idPrefix}-base-url`}>Base URL override</Label>
<Input
id={`${idPrefix}-base-url`}
placeholder="https://api.example.com/v1"
value={form.base_url}
onChange={(e) => update("base_url", e.target.value)}
/>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3 items-end">
<label className="flex items-center gap-2 text-xs text-muted-foreground">
<input
type="checkbox"
className="accent-foreground"
checked={form.no_agent}
onChange={(e) => update("no_agent", e.target.checked)}
/>
no_agent: run the script only and deliver stdout verbatim
</label>
<div className="grid gap-1">
<Label htmlFor={`${idPrefix}-script`}>Script</Label>
<Input
id={`${idPrefix}-script`}
value={form.script}
onChange={(e) => update("script", e.target.value)}
placeholder="relative/path/in/scripts"
/>
</div>
</div>
<div className="grid gap-1">
<Label htmlFor={`${idPrefix}-workdir`}>Workdir</Label>
<Input
id={`${idPrefix}-workdir`}
value={form.workdir}
onChange={(e) => update("workdir", e.target.value)}
placeholder="/absolute/project/path"
/>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div className="grid gap-1">
<Label htmlFor={`${idPrefix}-context-from`}>context_from job IDs</Label>
<textarea
id={`${idPrefix}-context-from`}
className="flex min-h-[64px] w-full border border-border bg-background/40 px-3 py-2 text-xs font-courier shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-foreground/30 focus-visible:border-foreground/25"
placeholder="one job id per line"
value={form.context_from}
onChange={(e) => update("context_from", e.target.value)}
/>
</div>
<div className="grid gap-1">
<Label htmlFor={`${idPrefix}-toolsets`}>enabled_toolsets</Label>
<NameCheckboxPicker
id={`${idPrefix}-toolsets`}
available={availableToolsets}
selected={form.enabled_toolsets}
onChange={(v) => update("enabled_toolsets", v)}
emptyLabel="No toolsets available."
/>
</div>
</div>
</div>
</details>
);
}
interface CronJobFormFieldsProps {
idPrefix: string;
autoFocus?: boolean;
form: CronJobEditorState;
resources: CronJobFormResources;
onChange: (form: CronJobEditorState) => void;
}
function CronJobFormFields({
idPrefix,
autoFocus,
form,
resources,
onChange,
}: CronJobFormFieldsProps) {
const { t } = useI18n();
const { availableSkills, availableToolsets, deliveryTargets, modelOptions } = resources;
const update = <K extends keyof CronJobEditorState,>(
key: K,
next: CronJobEditorState[K],
) => {
onChange({ ...form, [key]: next });
};
const onlyLocalAvailable =
deliveryTargets.filter((target) => target.id !== "local").length === 0;
const deliveryOptions = selectOptions(
form.deliver,
deliveryTargets.map((target) => {
const base = target.id === "local" ? t.cron.delivery.local : target.name;
if (target.id !== "local" && !target.home_target_set) {
const hint = t.cron.delivery.needsHomeChannel ?? "set a home channel first";
return { value: target.id, label: `${base}${hint}` };
}
return { value: target.id, label: base };
}),
);
return (
<>
<div className="grid gap-2">
<Label htmlFor={`${idPrefix}-name`}>{t.cron.nameOptional}</Label>
<Input
id={`${idPrefix}-name`}
autoFocus={autoFocus}
placeholder={t.cron.namePlaceholder}
value={form.name}
onChange={(e) => update("name", e.target.value)}
/>
</div>
<div className="grid gap-2">
<Label htmlFor={`${idPrefix}-prompt`}>{t.cron.prompt}</Label>
<textarea
id={`${idPrefix}-prompt`}
className="flex min-h-[80px] w-full border border-border bg-background/40 px-3 py-2 text-sm font-courier shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-foreground/30 focus-visible:border-foreground/25"
placeholder={t.cron.promptPlaceholder}
value={form.prompt}
onChange={(e) => update("prompt", e.target.value)}
/>
</div>
<ScheduleBuilder
value={form.scheduleState}
onChange={(state) => update("scheduleState", state)}
/>
<div className="grid gap-2">
<Label htmlFor={`${idPrefix}-deliver`}>{t.cron.deliverTo}</Label>
<Select
id={`${idPrefix}-deliver`}
value={form.deliver}
onValueChange={(v) => update("deliver", v)}
>
{deliveryOptions}
</Select>
{onlyLocalAvailable && (
<p className="text-xs text-muted-foreground">
{t.cron.delivery.noneConfigured ??
"No messaging platforms configured. Set one up under Channels to deliver reports."}
</p>
)}
</div>
<div className="grid gap-2">
<Label htmlFor={`${idPrefix}-skills`}>Skills (optional)</Label>
<NameCheckboxPicker
id={`${idPrefix}-skills`}
available={availableSkills}
selected={form.skills}
onChange={(skills) => update("skills", skills)}
emptyLabel="No skills installed for this profile."
/>
<p className="text-xs text-muted-foreground">
Selected skills are loaded before the prompt runs the cron
sets when, the skill sets how.
</p>
</div>
<CronAdvancedFields
idPrefix={`${idPrefix}-advanced`}
form={form}
onChange={onChange}
modelOptions={modelOptions}
availableToolsets={availableToolsets}
/>
</>
);
}
function getJobName(job: CronJob): string {
return asText(job.name).trim();
}
@ -148,6 +462,26 @@ function getJobState(job: CronJob): string {
return asText(job.state) || (job.enabled === false ? "disabled" : "scheduled");
}
function getRepeatDisplay(job: CronJob): string {
const repeat = job.repeat;
if (!repeat || repeat.times == null) return "forever";
const completed = repeat.completed ?? 0;
return completed > 0 ? `${completed}/${repeat.times}` : `${repeat.times} times`;
}
function getJobMode(job: CronJob): string {
if (job.no_agent) return "no_agent";
if (job.script) return "script+agent";
return "agent";
}
function getModelDisplay(job: CronJob): string {
const provider = asText(job.provider);
const model = asText(job.model);
if (provider && model) return `${provider}/${model}`;
return model || provider;
}
function getJobProfile(job: CronJob): string {
return asText(job.profile) || asText(job.profile_name) || "default";
}
@ -201,36 +535,25 @@ export default function CronPage() {
// New job modal state
const [createModalOpen, setCreateModalOpen] = useState(false);
const [prompt, setPrompt] = useState("");
// The schedule is now constructed via the ScheduleBuilder; we keep
// the full builder state so flipping between modes during edit
// doesn't erase the user's intermediate inputs. The actual string
// sent to the backend is derived via ``buildScheduleString`` at
// submit time.
const [scheduleState, setScheduleState] = useState<ScheduleBuilderState>(
DEFAULT_SCHEDULE_STATE,
const [createProfile, setCreateProfile] = useState("default");
const [createForm, setCreateForm] = useState<CronJobEditorState>(
emptyCronJobForm,
);
const [name, setName] = useState("");
const closeCreateModal = useCallback(() => setCreateModalOpen(false), []);
const createModalRef = useModalBehavior({
open: createModalOpen,
onClose: closeCreateModal,
});
const [deliver, setDeliver] = useState("local");
const [jobSkills, setJobSkills] = useState<string[]>([]);
const [deliveryTargets, setDeliveryTargets] = useState<CronDeliveryTarget[]>([
{ id: "local", name: "Local", home_target_set: true, home_env_var: null },
]);
const [creating, setCreating] = useState(false);
const createProfile = selectedProfile === "all" ? "default" : selectedProfile;
// Edit job modal state
const [editJob, setEditJob] = useState<CronJob | null>(null);
const [editPrompt, setEditPrompt] = useState("");
const [editSchedule, setEditSchedule] = useState("");
const [editName, setEditName] = useState("");
const [editDeliver, setEditDeliver] = useState("local");
const [editSkills, setEditSkills] = useState<string[]>([]);
const [editForm, setEditForm] = useState<CronJobEditorState>(
emptyCronJobForm,
);
const [saving, setSaving] = useState(false);
const closeEditModal = useCallback(() => setEditJob(null), []);
const editModalRef = useModalBehavior({
@ -243,16 +566,14 @@ export default function CronPage() {
// Keyed on the create-modal profile; the edit modal reuses the list —
// a job's current skills are always shown even if not in it.
const [availableSkills, setAvailableSkills] = useState<SkillInfo[]>([]);
const [availableToolsets, setAvailableToolsets] = useState<ToolsetInfo[]>([]);
const [modelOptions, setModelOptions] = useState<ModelOptionsResponse | null>(null);
const resourceProfile = editJob ? getJobProfile(editJob) : createProfile;
const openEditModal = useCallback((job: CronJob) => {
setEditJob(job);
setEditPrompt(getJobPrompt(job));
setEditSchedule(
asText(job.schedule?.expr) || asText(job.schedule_display) || "",
);
setEditName(getJobName(job));
setEditDeliver(asText(job.deliver) || "local");
setEditSkills(Array.isArray(job.skills) ? job.skills.filter(Boolean) : []);
setEditForm(editorFormFromJob(job));
}, []);
const loadJobs = useCallback(() => {
@ -286,102 +607,44 @@ export default function CronPage() {
loadJobs();
}, [loadJobs]);
// Load installed skills for the profile new jobs will be created under.
// "" / "default" maps to the dashboard's own profile via the optional
// ?profile= scoping on /api/skills.
// Load resources from the profile the create/edit form actually targets.
// Pass "default" explicitly so the global dashboard profile switch cannot
// redirect a default-profile cron form to some other profile.
useEffect(() => {
let cancelled = false;
api
.getSkills(createProfile === "default" ? undefined : createProfile)
.then((s) => {
if (!cancelled)
setAvailableSkills(
[...s].sort((a, b) => a.name.localeCompare(b.name)),
);
})
.catch(() => !cancelled && setAvailableSkills([]));
Promise.all([
api.getSkills(resourceProfile).catch(() => []),
api.getToolsets(resourceProfile).catch(() => []),
api.getModelOptions(resourceProfile).catch(() => null),
]).then(([skills, toolsets, options]) => {
if (cancelled) return;
setAvailableSkills([...skills].sort((a, b) => a.name.localeCompare(b.name)));
setAvailableToolsets([...toolsets].sort((a, b) => a.name.localeCompare(b.name)));
setModelOptions(options);
});
return () => {
cancelled = true;
};
}, [createProfile]);
const scheduleString = buildScheduleString(scheduleState);
// Label for a delivery option. Configured platforms missing their cron home
// channel are still offered (option B), annotated so the user knows what to
// fix rather than wondering why delivery silently no-ops.
const deliverLabel = useCallback(
(target: CronDeliveryTarget): string => {
const base = target.id === "local" ? t.cron.delivery.local : target.name;
if (target.id !== "local" && !target.home_target_set) {
const hint = t.cron.delivery.needsHomeChannel ?? "set a home channel first";
return `${base}${hint}`;
}
return base;
},
[t.cron.delivery],
);
const renderDeliverOptions = useCallback(
() =>
deliveryTargets.map((target) => (
<SelectOption key={target.id} value={target.id}>
{deliverLabel(target)}
</SelectOption>
)),
[deliveryTargets, deliverLabel],
);
// The edit modal must always show the job's current target, even if that
// platform is no longer configured (e.g. job created via CLI, or the
// gateway was later removed) — otherwise the value would silently vanish
// from the dropdown and saving would drop it.
const renderEditDeliverOptions = useCallback(
(current: string) => {
const known = new Set(deliveryTargets.map((target) => target.id));
const options = deliveryTargets.map((target) => (
<SelectOption key={target.id} value={target.id}>
{deliverLabel(target)}
</SelectOption>
));
if (current && !known.has(current)) {
options.push(
<SelectOption key={current} value={current}>
{current}
</SelectOption>,
);
}
return options;
},
[deliveryTargets, deliverLabel],
);
const onlyLocalAvailable =
deliveryTargets.filter((target) => target.id !== "local").length === 0;
}, [resourceProfile]);
const handleCreate = async () => {
if (!prompt.trim() || !scheduleString) {
const payload = buildCronJobPayloadFromEditor(createForm);
if (
!payload.schedule ||
(!payload.no_agent && !cronJobHasExecutionContent(payload))
) {
showToast(`${t.cron.prompt} & ${t.cron.schedule} required`, "error");
return;
}
if (payload.no_agent && !payload.script) {
showToast("no_agent jobs require a script", "error");
return;
}
setCreating(true);
try {
await api.createCronJob(
{
prompt: prompt.trim(),
schedule: scheduleString,
name: name.trim() || undefined,
deliver,
skills: jobSkills.length > 0 ? jobSkills : undefined,
},
createProfile,
);
await api.createCronJob(payload, createProfile);
showToast(t.common.create + " ✓", "success");
setPrompt("");
setScheduleState(DEFAULT_SCHEDULE_STATE);
setName("");
setDeliver("local");
setJobSkills([]);
setCreateForm(emptyCronJobForm());
setCreateModalOpen(false);
loadJobs();
} catch (e) {
@ -393,21 +656,23 @@ export default function CronPage() {
const handleEdit = async () => {
if (!editJob) return;
if (!editPrompt.trim() || !editSchedule.trim()) {
const payload = buildCronJobPayloadFromEditor(editForm);
if (
!payload.schedule ||
(!payload.no_agent && !cronJobHasExecutionContent(payload))
) {
showToast(`${t.cron.prompt} & ${t.cron.schedule} required`, "error");
return;
}
if (payload.no_agent && !payload.script) {
showToast("no_agent jobs require a script", "error");
return;
}
setSaving(true);
try {
await api.updateCronJob(
editJob.id,
{
prompt: editPrompt.trim(),
schedule: editSchedule.trim(),
name: editName.trim(),
deliver: editDeliver,
skills: editSkills,
},
payload,
getJobProfile(editJob),
);
showToast("Saved changes ✓", "success");
@ -483,7 +748,10 @@ export default function CronPage() {
<Button
className="uppercase"
size="sm"
onClick={() => setCreateModalOpen(true)}
onClick={() => {
setCreateProfile(selectedProfile === "all" ? "default" : selectedProfile);
setCreateModalOpen(true);
}}
>
{t.common.create}
</Button>,
@ -491,7 +759,7 @@ export default function CronPage() {
return () => {
setEnd(null);
};
}, [setEnd, t.common.create, loading]);
}, [setEnd, t.common.create, loading, selectedProfile]);
if (loading) {
return (
@ -552,7 +820,7 @@ export default function CronPage() {
aria-modal="true"
aria-labelledby="create-cron-title"
>
<div className={cn(themedBody, "relative w-full max-w-lg border border-border bg-card shadow-2xl flex flex-col")}>
<div className={cn(themedBody, "relative w-full max-w-3xl max-h-[90vh] border border-border bg-card shadow-2xl flex flex-col")}>
<Button
ghost
size="icon"
@ -572,13 +840,13 @@ export default function CronPage() {
</h2>
</header>
<div className="p-5 grid gap-4">
<div className="min-h-0 overflow-y-auto p-5 grid gap-4">
<div className="grid gap-2">
<Label htmlFor="cron-profile">Profile</Label>
<Select
id="cron-profile"
value={createProfile}
onValueChange={(v) => setSelectedProfile(v)}
onValueChange={(v) => setCreateProfile(v)}
>
{profiles.map((profile) => (
<SelectOption key={profile.name} value={profile.name}>
@ -588,65 +856,19 @@ export default function CronPage() {
</Select>
</div>
<div className="grid gap-2">
<Label htmlFor="cron-name">{t.cron.nameOptional}</Label>
<Input
id="cron-name"
autoFocus
placeholder={t.cron.namePlaceholder}
value={name}
onChange={(e) => setName(e.target.value)}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="cron-prompt">{t.cron.prompt}</Label>
<textarea
id="cron-prompt"
className="flex min-h-[80px] w-full border border-border bg-background/40 px-3 py-2 text-sm font-courier shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-foreground/30 focus-visible:border-foreground/25"
placeholder={t.cron.promptPlaceholder}
value={prompt}
onChange={(e) => setPrompt(e.target.value)}
/>
</div>
<ScheduleBuilder
value={scheduleState}
onChange={setScheduleState}
<CronJobFormFields
idPrefix="cron"
autoFocus
form={createForm}
onChange={setCreateForm}
resources={{
availableSkills,
availableToolsets,
modelOptions,
deliveryTargets,
}}
/>
<div className="grid gap-2">
<Label htmlFor="cron-deliver">{t.cron.deliverTo}</Label>
<Select
id="cron-deliver"
value={deliver}
onValueChange={(v) => setDeliver(v)}
>
{renderDeliverOptions()}
</Select>
{onlyLocalAvailable && (
<p className="text-xs text-muted-foreground">
{t.cron.delivery.noneConfigured ??
"No messaging platforms configured. Set one up under Channels to deliver reports."}
</p>
)}
</div>
<div className="grid gap-2">
<Label htmlFor="cron-skills">Skills (optional)</Label>
<SkillsPicker
id="cron-skills"
available={availableSkills}
selected={jobSkills}
onChange={setJobSkills}
emptyLabel="No skills installed for this profile."
/>
<p className="text-xs text-muted-foreground">
Selected skills are loaded before the prompt runs the cron
sets when, the skill sets how.
</p>
</div>
<div className="flex justify-end">
<Button
className="uppercase"
@ -673,7 +895,7 @@ export default function CronPage() {
aria-modal="true"
aria-labelledby="edit-cron-title"
>
<div className={cn(themedBody, "relative w-full max-w-lg border border-border bg-card shadow-2xl flex flex-col")}>
<div className={cn(themedBody, "relative w-full max-w-3xl max-h-[90vh] border border-border bg-card shadow-2xl flex flex-col")}>
<Button
ghost
size="icon"
@ -693,64 +915,24 @@ export default function CronPage() {
</h2>
</header>
<div className="p-5 grid gap-4">
<div className="grid gap-2">
<Label htmlFor="edit-cron-name">{t.cron.nameOptional}</Label>
<Input
id="edit-cron-name"
autoFocus
placeholder={t.cron.namePlaceholder}
value={editName}
onChange={(e) => setEditName(e.target.value)}
/>
</div>
<div className="min-h-0 overflow-y-auto p-5 grid gap-4">
<CronJobFormFields
idPrefix="edit-cron"
autoFocus
form={editForm}
onChange={setEditForm}
resources={{
availableSkills,
availableToolsets,
modelOptions,
deliveryTargets,
}}
/>
<div className="grid gap-2">
<Label htmlFor="edit-cron-prompt">{t.cron.prompt}</Label>
<textarea
id="edit-cron-prompt"
className="flex min-h-[80px] w-full border border-border bg-background/40 px-3 py-2 text-sm font-courier shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-foreground/30 focus-visible:border-foreground/25"
placeholder={t.cron.promptPlaceholder}
value={editPrompt}
onChange={(e) => setEditPrompt(e.target.value)}
/>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div className="grid gap-2">
<Label htmlFor="edit-cron-schedule">{t.cron.schedule}</Label>
<Input
id="edit-cron-schedule"
placeholder={t.cron.schedulePlaceholder}
value={editSchedule}
onChange={(e) => setEditSchedule(e.target.value)}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="edit-cron-deliver">{t.cron.deliverTo}</Label>
<Select
id="edit-cron-deliver"
value={editDeliver}
onValueChange={(v) => setEditDeliver(v)}
>
{renderEditDeliverOptions(editDeliver)}
</Select>
</div>
</div>
<div className="grid gap-2">
<Label htmlFor="edit-cron-skills">Skills</Label>
<SkillsPicker
id="edit-cron-skills"
available={availableSkills}
selected={editSkills}
onChange={setEditSkills}
emptyLabel="No skills installed for this profile."
/>
</div>
<div className="flex justify-end">
<div className="flex items-center justify-between">
<span className="text-xs text-muted-foreground font-mono-ui truncate pr-4">
{editJob.id}
</span>
<Button
className="uppercase"
size="sm"
@ -810,6 +992,11 @@ export default function CronPage() {
const deliver = asText(job.deliver);
const profile = getJobProfile(job);
const jobKey = getJobKey(job);
const mode = getJobMode(job);
const modelDisplay = getModelDisplay(job);
const toolsets = Array.isArray(job.enabled_toolsets)
? job.enabled_toolsets.filter(Boolean)
: [];
return (
<Card key={jobKey}>
@ -833,6 +1020,19 @@ export default function CronPage() {
: `${job.skills.length} skills`}
</Badge>
)}
{mode !== "agent" && (
<Badge tone="outline">{mode}</Badge>
)}
{modelDisplay && (
<Badge tone="outline" title={modelDisplay}>
model
</Badge>
)}
{toolsets.length > 0 && (
<Badge tone="outline" title={toolsets.join(", ")}>
{toolsets.length} toolsets
</Badge>
)}
</div>
{hasName && promptText && (
<p className="text-xs text-muted-foreground truncate mb-1">
@ -843,6 +1043,7 @@ export default function CronPage() {
<span className="font-mono-ui">
{getJobScheduleDisplay(job, scheduleDescribeStrings)}
</span>
<span>repeat: {getRepeatDisplay(job)}</span>
<span>
{t.cron.last}: {formatTime(job.last_run_at)}
</span>
@ -850,6 +1051,11 @@ export default function CronPage() {
{t.cron.next}: {formatTime(job.next_run_at)}
</span>
</div>
{job.last_delivery_error && (
<p className="text-xs text-destructive mt-1">
delivery: {job.last_delivery_error}
</p>
)}
{job.last_error && (
<p className="text-xs text-destructive mt-1">
{job.last_error}