89 lines
2.5 KiB
TypeScript
89 lines
2.5 KiB
TypeScript
import type { Job } from "./comfy/types";
|
|
import { progressFor } from "./jobProgress";
|
|
import { t } from "./i18n.svelte";
|
|
|
|
export type JobStatusTone = "ok" | "run" | "queue" | "fail";
|
|
|
|
export interface JobStatusInfo {
|
|
tone: JobStatusTone;
|
|
/** Short label for status columns. */
|
|
label: string;
|
|
/** Full sentence for the task card / tooltip. */
|
|
detail: string;
|
|
}
|
|
|
|
/**
|
|
* What a generation job really is — "done" only when ComfyUI returned files.
|
|
* A dry-run placeholder or a done row without outputs never reads as done.
|
|
*/
|
|
export function jobStatusInfo(job: Job): JobStatusInfo {
|
|
const live = progressFor(job.id);
|
|
const phase = live?.phase ?? job.phase ?? null;
|
|
const idSuffix = job.comfy_prompt_id
|
|
? t("jobst.idSuffix", { id: job.comfy_prompt_id })
|
|
: "";
|
|
switch (job.status) {
|
|
case "done":
|
|
if (phase === "dry_run")
|
|
return {
|
|
tone: "queue",
|
|
label: t("jobst.dryRun"),
|
|
detail: t("jobst.dryRunDetail"),
|
|
};
|
|
if (!(job.output_paths?.length ?? 0))
|
|
return {
|
|
tone: "fail",
|
|
label: t("jobst.noOutput"),
|
|
detail: t("jobst.noOutputDetail"),
|
|
};
|
|
return {
|
|
tone: "ok",
|
|
label: t("jobst.done"),
|
|
detail: t("jobst.doneDetail") + idSuffix,
|
|
};
|
|
case "pending":
|
|
return {
|
|
tone: "queue",
|
|
label: t("jobst.queued"),
|
|
detail: t("jobst.queuedDetail"),
|
|
};
|
|
case "running":
|
|
if (phase === "comfy_queued") {
|
|
const ahead = live?.queueAhead;
|
|
const detail =
|
|
ahead != null && ahead > 0
|
|
? t("jobst.comfyQueuedAhead", { n: ahead })
|
|
: t("jobst.comfyQueuedDetail");
|
|
return {
|
|
tone: "queue",
|
|
label: t("jobst.comfyQueued"),
|
|
detail: detail + idSuffix,
|
|
};
|
|
}
|
|
if (phase === "comfy_running")
|
|
return {
|
|
tone: "run",
|
|
label: t("jobst.comfyRunning"),
|
|
detail: t("jobst.comfyRunningDetail") + idSuffix,
|
|
};
|
|
if (phase === "saving")
|
|
return {
|
|
tone: "run",
|
|
label: t("jobst.saving"),
|
|
detail: t("jobst.savingDetail") + idSuffix,
|
|
};
|
|
return {
|
|
tone: "run",
|
|
label: t("jobst.connecting"),
|
|
detail: t("jobst.connectingDetail"),
|
|
};
|
|
default:
|
|
return {
|
|
tone: "fail",
|
|
label:
|
|
job.error === "cancelled" ? t("jobst.cancelled") : t("jobst.failed"),
|
|
detail: job.error ?? t("jobst.failed"),
|
|
};
|
|
}
|
|
}
|