622 lines
32 KiB
Vue
622 lines
32 KiB
Vue
<script setup lang="ts">
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
} from "@/components/ui/alert-dialog";
|
|
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
import { CircleAlert, Copy, ExternalLink, RotateCcw, Square, Trash2 } from "@lucide/vue";
|
|
import { isSending, setTurnHooks } from "@/chat/state";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
|
import { Spinner } from "@/components/ui/spinner";
|
|
import { MoreMenu } from "@/components/ui/more-menu";
|
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
|
import StepRun from "./StepRun.vue";
|
|
import { restartAt, withRuns, workflowGraph } from "./workflow-graph";
|
|
import { api, describeError } from "@/lib/api";
|
|
import { errors } from "@/copy/errors";
|
|
import type { WorkflowStats } from "@/lib/api";
|
|
import { ago } from "@/lib/format";
|
|
import { useRead } from "@/lib/use-read";
|
|
import { stateLabel } from "@/runs/state";
|
|
import StepEditor from "./StepEditor.vue";
|
|
import WorkflowSettings from "./WorkflowSettings.vue";
|
|
import TriggerList from "@/events/TriggerList.vue";
|
|
import WorkflowYaml from "./WorkflowYaml.vue";
|
|
import OptionSelect from "@/components/OptionSelect.vue";
|
|
import RunWorkflowButton from "./RunWorkflowButton.vue";
|
|
import WorkflowCanvas from "./WorkflowCanvas.vue";
|
|
import WorkflowHistory from "./WorkflowHistory.vue";
|
|
import { revisionOfRun, useWorkflowHistory, type WorkflowRevision } from "./workflow-revisions";
|
|
import { deleteStep, duplicateStep, insertStep, moveStep, normalizeStepIDs, replaceStep, revertWorkflowChange, stepAt, stepIDs, workflowChanges, type StepPath } from "./workflow-edit";
|
|
import ChangeList from "@/components/ChangeList.vue";
|
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
|
import { useWorkflowRuns } from "./workflow-runs";
|
|
import WorkflowRuns from "./WorkflowRuns.vue";
|
|
import type { WorkflowTrigger } from "./workflow-triggers";
|
|
import { useWorkflowsStore } from "@/stores/workflows";
|
|
import {
|
|
parseWorkflowYaml,
|
|
settingsProblem,
|
|
stepControlsProblem,
|
|
validationLabel,
|
|
} from "./workflow-yaml";
|
|
|
|
const workflows = useWorkflowsStore();
|
|
const state = computed(() => workflows.state);
|
|
const models = useRead(() => api.agentModels());
|
|
onMounted(() => void models.reload());
|
|
const modelAliases = computed(() => Object.keys(models.data.value ?? {}).sort());
|
|
const collection = computed(() => workflows.collection);
|
|
// Which definition is open belongs to the page, which also lists them.
|
|
const selected = defineModel<string>("selected", { required: true });
|
|
const emit = defineEmits<{ duplicate: [id: string]; deleted: [] }>();
|
|
const props = defineProps<{ stats?: WorkflowStats; triggers: WorkflowTrigger[] }>();
|
|
const id = ref("");
|
|
const yaml = ref("");
|
|
const loadedYaml = ref("");
|
|
// The one card open in place: "workflow", "start", or a step's path as JSON.
|
|
const open = ref<string | null>(null);
|
|
const openPath = computed<StepPath | null>(() => (open.value?.startsWith("[") ? (JSON.parse(open.value) as StepPath) : null));
|
|
function openStepAt(path: StepPath | null): void {
|
|
open.value = path ? JSON.stringify(path) : null;
|
|
}
|
|
const localError = ref("");
|
|
|
|
const { runs, error: runsError, loading: runsLoading, watched, watchedRun, trail, stages, stagesError, pick, follow, refresh } = useWorkflowRuns(selected);
|
|
const stepTab = ref("definition");
|
|
// A run without a pinned definition cannot be matched to the drawn steps, so
|
|
// the canvas draws the definition alone.
|
|
const unpinned = computed(() => Boolean(watchedRun.value && !watchedRun.value.workflow_definition_yaml));
|
|
const drawnStages = computed(() => unpinned.value ? [] : stages.value);
|
|
const pinnedYaml = computed(() => watchedRun.value?.workflow_definition_yaml);
|
|
const canvasYaml = computed(() => pinnedYaml.value || yaml.value);
|
|
const graph = computed(() => withRuns(workflowGraph(canvasYaml.value, workflows.stepTypes), drawnStages.value));
|
|
function toggle(key: string): void {
|
|
open.value = open.value === key ? null : key;
|
|
const run = graph.value.nodes.find((node) => JSON.stringify(node.data.path ?? null) === open.value)?.data.run;
|
|
stepTab.value = run && watchedRun.value ? "run" : "definition";
|
|
}
|
|
watch(watched, () => { open.value = null; restartError.value = ""; });
|
|
|
|
// A parked or ended run restarts at a step, keeping the results of the steps
|
|
// before it.
|
|
const restartable = computed(() => ["parked", "failed", "succeeded", "declined"].includes(watchedRun.value?.status ?? "") && !trail.value?.run.dry);
|
|
const openRestart = computed(() => restartable.value && openPath.value ? restartAt(graph.value, openPath.value) : null);
|
|
const restarting = ref(false);
|
|
const restartError = ref("");
|
|
async function restartFrom(from: string): Promise<void> {
|
|
restartError.value = "";
|
|
restarting.value = true;
|
|
try {
|
|
await api.retryRun(watched.value, from);
|
|
await refresh();
|
|
} catch (err) {
|
|
restartError.value = errors.workflows.editor.restartFailed(watched.value, from, describeError(err, errors.common.unknown));
|
|
} finally {
|
|
restarting.value = false;
|
|
}
|
|
}
|
|
const cancelling = computed(() => ["queued", "running", "waiting", "waiting_approval"].includes(watchedRun.value?.status ?? ""));
|
|
async function cancelWatched(): Promise<void> {
|
|
restartError.value = "";
|
|
try {
|
|
await api.cancelRun(watched.value);
|
|
await refresh();
|
|
} catch (err) {
|
|
restartError.value = describeError(err, errors.common.unknown);
|
|
}
|
|
}
|
|
// What the watched run recorded under one step: its transcript and results.
|
|
const entriesOf = (step: string) => (trail.value?.entries ?? []).filter((entry) => entry.step === step);
|
|
|
|
const published = computed(() => collection.value.definitions.find((entry) => entry.id === selected.value)?.version ?? 0);
|
|
const { revisions, error: historyError, loaded: historyLoaded, reload: reloadHistory } = useWorkflowHistory(selected, published);
|
|
const historyRevision = ref(0);
|
|
const historyMode = ref("yaml");
|
|
// The revision a run used, matched by the definition it pinned.
|
|
function runRevision(run?: { workflow_definition_yaml?: string; created_at?: string }): WorkflowRevision | undefined {
|
|
return run ? revisionOfRun(revisions.value, run.workflow_definition_yaml, run.created_at) : undefined;
|
|
}
|
|
const watchedRevision = computed(() => runRevision(watchedRun.value));
|
|
function openRevision(version: number): void {
|
|
historyRevision.value = version;
|
|
view.value = "history";
|
|
}
|
|
// A restored version becomes the draft: nothing runs it until Publish. It
|
|
// replaces unpublished edits, so with any it asks first; while Archie works it
|
|
// is refused, as Archie's proposal would replace it when the turn ends.
|
|
const pendingRestore = ref<string | null>(null);
|
|
function restoreRevision(restored: string): void {
|
|
if (archieWorking.value) return;
|
|
if (dirty.value) pendingRestore.value = restored;
|
|
else applyRestore(restored);
|
|
}
|
|
function applyRestore(restored: string): void {
|
|
pendingRestore.value = null;
|
|
yaml.value = restored;
|
|
open.value = null;
|
|
view.value = "canvas";
|
|
}
|
|
|
|
// Canvas edits are edits to the YAML; a newly placed step opens for editing.
|
|
const stepTypeNames = computed(() => vocabulary.value.map((info) => info.name));
|
|
function insertAt(after: StepPath, type: string): void {
|
|
stepTab.value = "definition";
|
|
const inserted = insertStep(yaml.value, after, type);
|
|
yaml.value = inserted.source;
|
|
openStepAt(inserted.path);
|
|
}
|
|
function duplicateAt(path: StepPath): void {
|
|
stepTab.value = "definition";
|
|
const copied = duplicateStep(yaml.value, path);
|
|
yaml.value = copied.source;
|
|
openStepAt(copied.path);
|
|
}
|
|
function moveAt(path: StepPath, delta: -1 | 1): void {
|
|
const moved = moveStep(yaml.value, path, delta);
|
|
yaml.value = moved.source;
|
|
// An open card follows its step: the moved one to its new place, the
|
|
// neighbour it swapped with to the old one. Nothing else opens.
|
|
const source = JSON.stringify(path);
|
|
const target = JSON.stringify(moved.path);
|
|
if (open.value === source) open.value = target;
|
|
else if (open.value === target) open.value = source;
|
|
}
|
|
function removeAt(path: StepPath): void {
|
|
yaml.value = deleteStep(yaml.value, path);
|
|
open.value = null;
|
|
}
|
|
function renameAt(path: StepPath, name: string): void {
|
|
const { id: current, type, ...rest } = stepAt(yaml.value, path) ?? {};
|
|
// References name steps by id, so two steps sharing one would be ambiguous.
|
|
if (name && name !== current && stepIDs(yaml.value).includes(name)) {
|
|
localError.value = errors.workflows.editor.stepIdTaken(name);
|
|
return;
|
|
}
|
|
yaml.value = replaceStep(yaml.value, path, { id: name || undefined, type, ...rest });
|
|
}
|
|
|
|
// The stored draft of the open workflow as this editor last saw it. A write
|
|
// that finds anything else stored would overwrite another tab's or Archie's
|
|
// edit, so it stops and says so instead.
|
|
const seenDraft = ref<string | undefined>();
|
|
const draftConflict = ref(false);
|
|
// The published version the open document was edited from.
|
|
const loadedVersion = ref(0);
|
|
// Set once the workflow is deleted, so nothing writes its draft back.
|
|
let removed = false;
|
|
function load(value: string): void {
|
|
removed = false;
|
|
const entry = collection.value.definitions.find(
|
|
(candidate) => candidate.id === value,
|
|
);
|
|
id.value = entry?.id ?? value;
|
|
seenDraft.value = workflows.drafts.find((draft) => draft.id === value)?.yaml;
|
|
draftConflict.value = false;
|
|
loadedVersion.value = entry?.version ?? 0;
|
|
loadedYaml.value = seenDraft.value ?? entry?.yaml ?? "steps: []\n";
|
|
yaml.value = normalizeStepIDs(loadedYaml.value);
|
|
open.value = null;
|
|
localError.value = "";
|
|
}
|
|
|
|
watch(selected, load, { immediate: true });
|
|
// The collection arrives after the first render; a later live update must not
|
|
// overwrite what is being typed, so it only refreshes an editor with no local edits.
|
|
watch([collection, () => workflows.drafts], () => {
|
|
if (removed) return;
|
|
const incoming =
|
|
workflows.drafts.find((draft) => draft.id === selected.value) ??
|
|
collection.value.definitions.find((entry) => entry.id === selected.value);
|
|
if (incoming && yaml.value === loadedYaml.value && incoming.yaml !== loadedYaml.value) load(selected.value);
|
|
});
|
|
|
|
// Every edit lands in the workflow's draft shortly after it is made, so work
|
|
// survives a reload and nothing reaches the running workflow until Publish.
|
|
// A draft equal to the published definition is removed.
|
|
let pending: ReturnType<typeof setTimeout> | undefined;
|
|
async function writeDraft(target: string, next: string | undefined, force = false): Promise<boolean> {
|
|
const stored = workflows.drafts.find((draft) => draft.id === target)?.yaml;
|
|
if (!force && target === selected.value && stored !== seenDraft.value) {
|
|
draftConflict.value = true;
|
|
return false;
|
|
}
|
|
// Replacing what another writer saved starts from the draft as stored now.
|
|
if (force) await workflows.reloadDrafts();
|
|
if (await workflows.putDraft(target, next)) {
|
|
if (target === selected.value) {
|
|
seenDraft.value = next;
|
|
draftConflict.value = false;
|
|
}
|
|
return true;
|
|
}
|
|
if (workflows.draftState.conflict && target === selected.value) draftConflict.value = true;
|
|
return false;
|
|
}
|
|
// Every edit lands in the workflow's draft shortly after it is made, so work
|
|
// survives a reload and nothing reaches the running workflow until Publish.
|
|
// A draft equal to the published definition is removed.
|
|
async function persistDraft(target: string, value: string, force = false): Promise<void> {
|
|
if (!target || removed) return;
|
|
const published = collection.value.definitions.find((entry) => entry.id === target)?.yaml ?? "";
|
|
const current = workflows.drafts.find((draft) => draft.id === target)?.yaml;
|
|
const next = value === published ? undefined : value;
|
|
if (next === current) {
|
|
if (target === selected.value) seenDraft.value = current;
|
|
return;
|
|
}
|
|
if (await writeDraft(target, next, force)) {
|
|
if (target === selected.value && value === yaml.value) loadedYaml.value = value;
|
|
} else if (target === selected.value && !draftConflict.value) {
|
|
// The edit stays in the editor; the alert says the draft was not saved.
|
|
localError.value = workflows.draftState.error || errors.workflows.editor.draftNotSaved;
|
|
}
|
|
}
|
|
// The last edit not yet written, flushed at once when the editor switches
|
|
// workflow so the switch cannot drop it.
|
|
let unsaved: { target: string; value: string } | undefined;
|
|
watch(yaml, (value) => {
|
|
clearTimeout(pending);
|
|
if (unsaved && unsaved.target !== selected.value) void persistDraft(unsaved.target, unsaved.value);
|
|
const edit = (unsaved = { target: selected.value, value });
|
|
pending = setTimeout(() => {
|
|
unsaved = undefined;
|
|
void persistDraft(edit.target, edit.value);
|
|
}, 800);
|
|
});
|
|
onMounted(() => setTurnHooks({ before: flushDraft, after: () => void takeProposal() }));
|
|
onBeforeUnmount(() => {
|
|
setTurnHooks({});
|
|
clearTimeout(pending);
|
|
void persistDraft(selected.value, yaml.value);
|
|
});
|
|
async function dropDraft(target: string): Promise<boolean> {
|
|
clearTimeout(pending);
|
|
unsaved = undefined;
|
|
return writeDraft(target, undefined);
|
|
}
|
|
// The conflict's two ways out: take what is stored, or write this edit over it.
|
|
function loadLatestDraft(): void {
|
|
load(selected.value);
|
|
}
|
|
function keepMyDraft(): void {
|
|
void persistDraft(selected.value, yaml.value, true);
|
|
}
|
|
// Edits made while Archie works would be overwritten by its draft, so the
|
|
// canvas and YAML go read-only until the turn ends; viewing stays open.
|
|
const archieWorking = isSending;
|
|
// Archie works from the saved draft, so pending edits are written first.
|
|
async function flushDraft(): Promise<void> {
|
|
clearTimeout(pending);
|
|
unsaved = undefined;
|
|
await persistDraft(selected.value, yaml.value);
|
|
}
|
|
// A test run runs the saved draft, so the edit is written first.
|
|
async function saveDraft(): Promise<boolean> {
|
|
await flushDraft();
|
|
return workflows.drafts.find((draft) => draft.id === selected.value)?.yaml === yaml.value;
|
|
}
|
|
const enabled = computed(() => collection.value.definitions.find((entry) => entry.id === selected.value)?.enabled ?? true);
|
|
// Archie's draft replaces what the editor shows; the review then lists its
|
|
// changes against the published workflow.
|
|
async function takeProposal(): Promise<void> {
|
|
await workflows.reloadDrafts();
|
|
const draft = workflows.drafts.find((entry) => entry.id === selected.value)?.yaml;
|
|
if (draft === undefined || draft === yaml.value) return;
|
|
clearTimeout(pending);
|
|
unsaved = undefined;
|
|
load(selected.value);
|
|
}
|
|
// Back to the published definition: the draft is dropped, not merged.
|
|
async function restorePublished(): Promise<void> {
|
|
if (await dropDraft(selected.value)) load(selected.value);
|
|
else if (!draftConflict.value) localError.value = workflows.draftState.error || errors.workflows.editor.draftNotSaved;
|
|
}
|
|
|
|
async function publish(): Promise<void> {
|
|
if (publishBlocked.value || state.value.saving) return;
|
|
localError.value = "";
|
|
clearTimeout(pending);
|
|
unsaved = undefined;
|
|
if (await workflows.publish(selected.value, yaml.value, loadedVersion.value)) {
|
|
loadedYaml.value = yaml.value;
|
|
seenDraft.value = undefined;
|
|
draftConflict.value = false;
|
|
loadedVersion.value = workflows.collection.definitions.find((entry) => entry.id === selected.value)?.version ?? loadedVersion.value;
|
|
}
|
|
}
|
|
|
|
// The run button and draft menu item each control their dialog.
|
|
// The page opens this too, from a list row's Run, so there is one run dialog.
|
|
const runOpen = defineModel<boolean>("runOpen", { default: false });
|
|
const draftOpen = ref(false);
|
|
const confirmDelete = ref(false);
|
|
const confirmDiscard = ref(false);
|
|
// A published workflow is deleted with its draft; one never published has only
|
|
// the draft to discard. The server refuses a delete while anything names it.
|
|
async function remove(): Promise<void> {
|
|
if (!selected.value) return;
|
|
clearTimeout(pending);
|
|
unsaved = undefined;
|
|
// The page unmounts the editor as the workflow disappears, and unmounting
|
|
// would write the draft back.
|
|
removed = true;
|
|
const done = stored.value === undefined ? await workflows.putDraft(selected.value, undefined) : await workflows.remove(selected.value);
|
|
if (!done) removed = false;
|
|
else emit("deleted");
|
|
}
|
|
|
|
// What is typed, read against the served step vocabulary (workflow-yaml.ts).
|
|
// The Steps preview, the gutter and the validity indicator are three readings
|
|
// of one parse, so they cannot disagree about the same text. Step settings are
|
|
// not served, so a save the server refuses still reports its own reason below.
|
|
const vocabulary = computed(() => workflows.stepTypes);
|
|
// The definitions loaded but carried no step types: cards can't open and YAML
|
|
// can't be checked, which must not look like an empty, valid workflow.
|
|
const stepTypesMissing = computed(() => !!workflows.state.resource && !vocabulary.value.length);
|
|
const parsed = computed(() => parseWorkflowYaml(yaml.value, vocabulary.value, selected.value));
|
|
const stored = computed(() => collection.value.definitions.find((entry) => entry.id === selected.value)?.yaml);
|
|
const dirty = computed(() => yaml.value !== (stored.value ?? ""));
|
|
const changes = computed(() => (dirty.value ? workflowChanges(stored.value ?? "", yaml.value) : []));
|
|
// Disabled buttons swallow hover, so the reason sits on a wrapper's title.
|
|
const publishBlocked = computed(() =>
|
|
archieWorking.value ? "Archie is editing" : !parsed.value.ok ? validationLabel(parsed.value) : !changes.value.length ? "No changes" : undefined);
|
|
const view = defineModel<string>("view", { default: "canvas" });
|
|
// What each step lacks, read the way its editor reads it.
|
|
const problems = computed(() =>
|
|
Object.fromEntries(
|
|
graph.value.nodes.flatMap((node) => {
|
|
const path = node.data.path;
|
|
const step = path && stepAt(yaml.value, path);
|
|
if (!step) return [];
|
|
const schema = vocabulary.value.find((info) => info.name === step.type)?.settings;
|
|
const problem = stepControlsProblem(step) || (schema && step.settings ? settingsProblem(step.settings, schema, "settings") : "");
|
|
return problem ? [[JSON.stringify(path), problem]] : [];
|
|
}),
|
|
),
|
|
);
|
|
// A parse failure on a step shows on that node too.
|
|
const failedPath = computed(() => (parsed.value.ok ? undefined : (parsed.value.path as StepPath | undefined)));
|
|
const nodeProblems = computed(() =>
|
|
failedPath.value && !parsed.value.ok ? { ...problems.value, [JSON.stringify(failedPath.value)]: parsed.value.message } : problems.value,
|
|
);
|
|
// Every error the editor knows, each linked to its step when it has one.
|
|
const issues = computed(() => {
|
|
const list: { text: string; path?: StepPath }[] = [];
|
|
if (!parsed.value.ok) list.push({ text: validationLabel(parsed.value), path: failedPath.value });
|
|
for (const [key, text] of Object.entries(problems.value)) list.push({ text, path: JSON.parse(key) as StepPath });
|
|
return list;
|
|
});
|
|
function showError(path?: StepPath): void {
|
|
if (!path) return;
|
|
view.value = "canvas";
|
|
openStepAt(path);
|
|
}
|
|
const runOptions = computed(() => [
|
|
{ value: "", label: "Definition" },
|
|
...runs.value.map((run) => ({
|
|
value: String(run.id),
|
|
label: [run.source === "test" ? "Test" : `Run ${run.id.slice(0, 8)}`, run.status && stateLabel(run.status), run.created_at ? ago(run.created_at) : ""].filter(Boolean).join(" · "),
|
|
})),
|
|
]);
|
|
</script>
|
|
|
|
<template>
|
|
<!-- Not a form: implicit submission turned Enter in any field, and every
|
|
button without a type, into a publish. Publish is its own button. -->
|
|
<div class="space-y-4 max-md:flex max-md:min-h-0 max-md:flex-1 max-md:flex-col">
|
|
<Tabs v-model="view" class="space-y-1.5 max-md:min-h-0 max-md:flex-1">
|
|
<div class="workflow-editor-toolbar flex shrink-0 flex-wrap items-center gap-2 max-sm:grid max-sm:grid-cols-[1fr_auto]">
|
|
<div v-if="$slots.title" class="flex min-w-0 shrink items-center gap-2 max-lg:hidden"><slot name="title" /></div>
|
|
<TabsList class="shrink-0 justify-start">
|
|
<TabsTrigger value="canvas">Canvas</TabsTrigger>
|
|
<TabsTrigger value="yaml">YAML</TabsTrigger>
|
|
<TabsTrigger value="history">History</TabsTrigger>
|
|
<TabsTrigger v-if="stored !== undefined" value="runs">Runs <span v-if="runs.length" class="ml-1 font-mono text-caption text-fg-subtle">{{ runs.length }}</span></TabsTrigger>
|
|
</TabsList>
|
|
<div role="group" aria-label="Runs" class="workflow-run-actions ml-auto flex min-w-0 items-center gap-1 max-sm:col-span-2 max-sm:row-start-2 max-sm:ml-0">
|
|
<div v-if="view === 'canvas' || view === 'yaml' || view === 'history'" class="shrink-0">
|
|
<RunWorkflowButton
|
|
v-model:open="runOpen"
|
|
:workflow="selected"
|
|
:yaml="yaml"
|
|
:test="dirty || stored === undefined"
|
|
:prepare="saveDraft"
|
|
:disabled="!parsed.ok || (!dirty && stored !== undefined && !enabled)"
|
|
:disabled-reason="parsed.ok ? 'Disabled' : validationLabel(parsed)"
|
|
@started="(runId) => { view = 'canvas'; void follow(runId); }"
|
|
/>
|
|
</div>
|
|
<div v-if="runs.length && view === 'canvas'" class="flex min-w-0 items-center gap-1 max-sm:flex-1">
|
|
<OptionSelect :key="`${watched}/${watchedRun?.status}`" :model-value="watched" :options="runOptions" aria-label="Run shown on the canvas" class="min-w-32 max-w-56 max-sm:w-full *:data-[slot=select-value]:block *:data-[slot=select-value]:truncate" @update:model-value="pick" />
|
|
<Badge v-if="watchedRun?.source === 'test'" variant="outline" class="shrink-0">Test</Badge>
|
|
</div>
|
|
</div>
|
|
<div role="group" aria-label="Edit" class="workflow-edit-actions flex min-w-0 items-center gap-1 border-l pl-2 max-sm:col-start-2 max-sm:row-start-1">
|
|
<slot name="toolbar" />
|
|
<Popover v-if="!parsed.ok">
|
|
<PopoverTrigger as-child>
|
|
<Button type="button" variant="ghost" size="sm" class="min-w-0 max-w-md text-caption text-danger" role="status" :aria-label="validationLabel(parsed)" :title="validationLabel(parsed)">
|
|
<CircleAlert /><span class="truncate max-sm:hidden">{{ validationLabel(parsed) }}</span></Button>
|
|
</PopoverTrigger>
|
|
<PopoverContent align="end" class="max-h-96 w-80 overflow-y-auto p-1">
|
|
<ul class="text-caption text-danger">
|
|
<li v-for="(error, i) in issues" :key="i">
|
|
<Button v-if="error.path" type="button" variant="ghost" class="h-auto w-full justify-start whitespace-normal px-2 py-1.5 text-left text-caption font-normal text-danger hover:underline" @click="showError(error.path)">{{ error.text }}</Button>
|
|
<p v-else class="px-2 py-1.5">{{ error.text }}</p>
|
|
</li>
|
|
</ul>
|
|
</PopoverContent>
|
|
</Popover>
|
|
<span v-if="dirty && (view === 'canvas' || view === 'yaml' || view === 'history')" class="shrink-0" :title="publishBlocked">
|
|
<Button type="button" size="sm" class="disabled:bg-muted disabled:text-fg-muted disabled:opacity-100" :disabled="state.saving || !!publishBlocked" @click="publish">
|
|
<Spinner v-if="state.saving" data-icon="inline-start" />Publish</Button>
|
|
</span>
|
|
<MoreMenu>
|
|
<!-- The run's page and the version it pinned are menu items, not
|
|
row controls: the row keeps the width for the picked run. -->
|
|
<DropdownMenuItem v-if="watchedRun" as-child><RouterLink :to="`/runs/${watchedRun.id}`"><ExternalLink />Open run</RouterLink></DropdownMenuItem>
|
|
<DropdownMenuItem v-if="cancelling" @select="cancelWatched"><Square />Cancel run</DropdownMenuItem>
|
|
<DropdownMenuItem v-if="watchedRevision" @select="openRevision(watchedRevision.version)">Version {{ watchedRevision.version }}</DropdownMenuItem>
|
|
<DropdownMenuItem v-if="changes.length" @select="draftOpen = true">Draft changes <span class="ml-auto font-mono text-caption text-fg-subtle">{{ changes.length }}</span></DropdownMenuItem>
|
|
<DropdownMenuItem v-if="dirty" :disabled="archieWorking" @select="confirmDiscard = true"><RotateCcw />Discard changes</DropdownMenuItem>
|
|
<DropdownMenuItem v-if="stored !== undefined" @select="emit('duplicate', selected)"><Copy />Duplicate</DropdownMenuItem>
|
|
<DropdownMenuItem variant="destructive" @select="confirmDelete = true"><Trash2 />{{ stored === undefined ? "Discard workflow" : "Delete workflow" }}</DropdownMenuItem>
|
|
</MoreMenu>
|
|
</div>
|
|
</div>
|
|
<p v-if="runsLoading && !runs.length" class="flex items-center gap-2 text-caption text-fg-muted"><Spinner />Loading recent runs…</p>
|
|
<div v-else-if="runsError" class="text-label text-danger" role="alert">
|
|
<p>{{ errors.workflows.editor.recentRunsNotLoaded(runsError) }}</p>
|
|
<Button type="button" variant="outline" size="sm" @click="refresh">Retry runs</Button>
|
|
</div>
|
|
<div v-if="stagesError" class="text-label text-danger" role="alert">
|
|
<p>{{ errors.workflows.editor.watchedStagesNotLoaded(stagesError) }}</p>
|
|
<Button type="button" variant="outline" size="sm" @click="refresh">Retry</Button>
|
|
</div>
|
|
<p v-if="view === 'canvas' && unpinned" class="text-caption text-fg-muted" role="status">No snapshot for this run.</p>
|
|
<!-- Kept mounted so an Archie turn started here still finishes, unlocks the
|
|
editor and loads its draft when the operator switches tabs. -->
|
|
<TabsContent value="canvas" force-mount class="space-y-2 data-[state=inactive]:hidden max-md:flex max-md:min-h-0 max-md:flex-col">
|
|
<div class="relative flex h-[calc(100dvh-14rem)] min-h-[26rem] flex-col max-md:h-auto max-md:min-h-0 max-md:flex-1">
|
|
<Alert v-if="restartError" variant="destructive" class="absolute bottom-16 left-14 z-10 max-w-xl rounded-md border border-danger/40 bg-card px-3 py-2 shadow-lg"><AlertDescription>{{ restartError }}</AlertDescription></Alert>
|
|
<WorkflowCanvas
|
|
class="h-auto min-h-0 flex-1"
|
|
:yaml="canvasYaml"
|
|
:stages="drawnStages"
|
|
:open="open"
|
|
:triggers="props.triggers"
|
|
:types="stepTypeNames"
|
|
:readonly="!!pinnedYaml || archieWorking"
|
|
:restartable="restartable"
|
|
:problems="pinnedYaml ? undefined : nodeProblems"
|
|
:title="selected"
|
|
@toggle="toggle"
|
|
@restart="restartFrom"
|
|
@insert="insertAt"
|
|
@duplicate="duplicateAt"
|
|
@move="moveAt"
|
|
@remove="removeAt"
|
|
@rename="renameAt"
|
|
>
|
|
<template #body="{ data }">
|
|
<fieldset v-if="data.kind === 'workflow'" :disabled="!!pinnedYaml" class="min-w-0"><WorkflowSettings :yaml="canvasYaml" @update:yaml="yaml = $event" /></fieldset>
|
|
<div v-else-if="data.kind === 'start'" class="min-w-0 p-3"><TriggerList :workflow="selected" /></div>
|
|
<template v-else-if="data.path">
|
|
<div v-if="data.run && watchedRun" class="flex items-center gap-2 border-b border-border px-3 py-2">
|
|
<Tabs v-model="stepTab"><TabsList><TabsTrigger value="run">Run</TabsTrigger><TabsTrigger value="definition">Definition</TabsTrigger></TabsList></Tabs>
|
|
<Button v-if="openRestart" type="button" size="sm" variant="outline" class="ml-auto" :disabled="restarting || openRestart.blocked" @click="restartFrom(openRestart.from)"><RotateCcw />{{ openRestart.label }}</Button>
|
|
</div>
|
|
<div v-if="data.run && watchedRun && stepTab === 'run'" class="max-h-[32rem] overflow-y-auto">
|
|
<StepRun :stage="data.run" :entries="entriesOf(data.run.name)" />
|
|
</div>
|
|
<fieldset v-else :disabled="!!pinnedYaml || archieWorking" class="min-w-0">
|
|
<StepEditor
|
|
:key="open ?? ''"
|
|
:yaml="canvasYaml"
|
|
@update:yaml="yaml = $event"
|
|
:workflows="collection.definitions"
|
|
:path="data.path"
|
|
:vocabulary="vocabulary"
|
|
:model-aliases="modelAliases"
|
|
/>
|
|
</fieldset>
|
|
</template>
|
|
</template>
|
|
</WorkflowCanvas>
|
|
</div>
|
|
</TabsContent>
|
|
<TabsContent value="yaml" class="max-md:min-h-0 max-md:overflow-y-auto">
|
|
<WorkflowYaml v-model="yaml" :readonly="archieWorking" />
|
|
</TabsContent>
|
|
<TabsContent value="history" class="max-md:min-h-0 max-md:overflow-y-auto">
|
|
<WorkflowHistory v-model:selected="historyRevision" v-model:mode="historyMode" :revisions="revisions" v-model:current="yaml" :error="historyError" :loaded="historyLoaded" :locked="archieWorking" @restore="restoreRevision" @retry="reloadHistory" />
|
|
</TabsContent>
|
|
<TabsContent value="runs" class="max-md:min-h-0 max-md:overflow-y-auto">
|
|
<WorkflowRuns :runs="runs" :loading="runsLoading" :error="runsError" :stats="props.stats" @retry="refresh" />
|
|
</TabsContent>
|
|
</Tabs>
|
|
<Alert v-if="stepTypesMissing" variant="destructive"><AlertDescription>{{ errors.workflows.editor.stepTypesUnavailable }}</AlertDescription></Alert>
|
|
<Alert v-if="draftConflict" variant="destructive">
|
|
<AlertDescription class="flex flex-wrap items-center justify-between gap-2">
|
|
{{ errors.workflows.editor.draftChangedElsewhere }}
|
|
<span class="flex gap-2">
|
|
<Button type="button" variant="outline" size="sm" @click="loadLatestDraft">Load latest</Button>
|
|
<Button type="button" variant="outline" size="sm" @click="keepMyDraft">Replace with mine</Button>
|
|
</span>
|
|
</AlertDescription>
|
|
</Alert>
|
|
<Alert v-else-if="localError || workflows.draftState.error || state.error" variant="destructive"><AlertDescription>
|
|
{{ localError || workflows.draftState.error || state.error }}
|
|
</AlertDescription></Alert>
|
|
<Dialog :open="draftOpen && changes.length > 0" @update:open="(open) => (draftOpen = open)">
|
|
<DialogContent class="sm:max-w-lg">
|
|
<DialogHeader>
|
|
<DialogTitle>Draft changes</DialogTitle>
|
|
</DialogHeader>
|
|
<div class="max-h-96 overflow-y-auto rounded-md border border-border">
|
|
<ChangeList :changes="changes" @revert="(change) => (yaml = revertWorkflowChange(yaml, change))" />
|
|
</div>
|
|
</DialogContent>
|
|
</Dialog>
|
|
<AlertDialog v-model:open="confirmDiscard">
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>Discard the unpublished changes to {{ selected }}?</AlertDialogTitle>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
<AlertDialogAction variant="destructive" :disabled="archieWorking" @click="restorePublished">Discard</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
<AlertDialog :open="pendingRestore !== null" @update:open="(value: boolean) => { if (!value) pendingRestore = null; }">
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>Replace the unpublished changes with this version?</AlertDialogTitle>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
<AlertDialogAction :disabled="archieWorking" @click="applyRestore(pendingRestore!)">Replace</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
<AlertDialog v-model:open="confirmDelete">
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>{{ stored === undefined ? "Discard" : "Delete" }} the {{ selected }} workflow?</AlertDialogTitle>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
<AlertDialogAction variant="destructive" @click="remove">{{ stored === undefined ? "Discard" : "Delete" }}</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
@media (max-width: 360px) {
|
|
.workflow-editor-toolbar {
|
|
grid-template-columns: minmax(0, 1fr);
|
|
}
|
|
.workflow-editor-toolbar > .workflow-edit-actions {
|
|
grid-area: 2 / 1;
|
|
justify-content: flex-end;
|
|
}
|
|
.workflow-editor-toolbar > .workflow-run-actions {
|
|
grid-area: 3 / 1;
|
|
}
|
|
}
|
|
</style>
|