614 lines
30 KiB
Vue
614 lines
30 KiB
Vue
<script setup lang="ts">
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
} from "@/components/ui/alert-dialog";
|
|
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
import { CircleAlert, RotateCcw, Trash2 } from "@lucide/vue";
|
|
import { isSending, setTurnHooks } from "@/chat/state";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
|
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 { Textarea } from "@/components/ui/textarea";
|
|
import StepRun from "./StepRun.vue";
|
|
import { restartAt, withRuns, workflowGraph } from "./workflow-graph";
|
|
import { api } from "@/lib/api";
|
|
import { ago } from "@/lib/format";
|
|
import { statusLabel } from "@/lib/task-meta";
|
|
import StepEditor from "./StepEditor.vue";
|
|
import WorkflowSettings from "./WorkflowSettings.vue";
|
|
import TriggerSettings from "./TriggerSettings.vue";
|
|
import OptionSelect from "./OptionSelect.vue";
|
|
import RunWorkflowButton from "./RunWorkflowButton.vue";
|
|
import TaskRowActions from "@/tasks/TaskRowActions.vue";
|
|
import WorkflowCanvas from "./WorkflowCanvas.vue";
|
|
import WorkflowHistory from "./WorkflowHistory.vue";
|
|
import { useWorkflowHistory } from "./workflow-history";
|
|
import { revisionOfRun, type WorkflowRevision } from "./workflow-revisions";
|
|
import { deleteStep, duplicateStep, insertStep, moveStep, normalizeStepIDs, replaceStep, revertWorkflowChange, stepAt, workflowChanges, workflowField, 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 { useWorkflowTriggers } from "./workflow-triggers";
|
|
import { useSettingsStore } from "@/stores/settings";
|
|
import {
|
|
removeWorkflowDefinition,
|
|
upsertWorkflowDefinition,
|
|
useWorkflowsStore,
|
|
type WorkflowDefinitionCollection,
|
|
} from "@/stores/workflows";
|
|
import {
|
|
parseWorkflowYaml,
|
|
settingsProblem,
|
|
stepControlsProblem,
|
|
validationLabel,
|
|
yamlLines,
|
|
yamlTokenClass,
|
|
} from "./workflow-yaml";
|
|
|
|
const store = useSettingsStore();
|
|
const workflows = useWorkflowsStore();
|
|
const state = computed(() => workflows.state);
|
|
// Chat and agent aliases: embedding and transcription have their own purposes.
|
|
const modelAliases = computed(() =>
|
|
Object.keys((store.stateFor("model-aliases").resource?.value ?? {}) as Record<string, string>)
|
|
.filter((alias) => alias !== "embedding" && alias !== "transcription")
|
|
.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 });
|
|
defineProps<{ runsCount?: number }>();
|
|
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, stages, attempt, 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), 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 run restarts at a step through the retry action, keeping the
|
|
// results of the steps before it.
|
|
const restartable = computed(() => watchedRun.value?.status === "parked");
|
|
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.taskAction(watched.value, "retry", { resume_from: from });
|
|
await refresh();
|
|
} catch (err) {
|
|
restartError.value = err instanceof Error ? err.message : "Restart failed";
|
|
} finally {
|
|
restarting.value = false;
|
|
}
|
|
}
|
|
const { triggers, reload: reloadTriggers } = useWorkflowTriggers(selected);
|
|
|
|
const { revisions, error: historyError } = useWorkflowHistory(selected);
|
|
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.
|
|
function restoreRevision(restored: string): void {
|
|
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;
|
|
if (openPath.value) openStepAt(moved.path);
|
|
}
|
|
function removeAt(path: StepPath): void {
|
|
yaml.value = deleteStep(yaml.value, path);
|
|
open.value = null;
|
|
}
|
|
function renameAt(path: StepPath, name: string): void {
|
|
const { id: _id, type, ...rest } = stepAt(yaml.value, path) ?? {};
|
|
yaml.value = replaceStep(yaml.value, path, { id: name || undefined, type, ...rest });
|
|
}
|
|
|
|
function load(value: string): void {
|
|
const entry = collection.value.definitions.find(
|
|
(candidate) => candidate.id === value,
|
|
);
|
|
id.value = entry?.id ?? value;
|
|
loadedYaml.value = workflows.drafts.find((draft) => draft.id === value)?.yaml ?? entry?.yaml ?? `id: ${value}\nsteps: []\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], () => {
|
|
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 persistDraft(target: string, value: string): Promise<void> {
|
|
if (!target) 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) return;
|
|
if (await workflows.putDraft(target, next)) {
|
|
if (target === selected.value && value === yaml.value) loadedYaml.value = value;
|
|
} else if (workflows.draftState.saving) {
|
|
pending = setTimeout(() => void persistDraft(target, value), 500);
|
|
}
|
|
}
|
|
// 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<void> {
|
|
clearTimeout(pending);
|
|
unsaved = undefined;
|
|
await workflows.putDraft(target, undefined);
|
|
}
|
|
// 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);
|
|
}
|
|
// 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> {
|
|
await dropDraft(selected.value);
|
|
load(selected.value);
|
|
}
|
|
|
|
async function save(next: WorkflowDefinitionCollection): Promise<boolean> {
|
|
localError.value = "";
|
|
return workflows.save(next);
|
|
}
|
|
|
|
async function publish(): Promise<void> {
|
|
// The id is the one the YAML declares; renaming is editing it there.
|
|
const nextID = parsed.value.ok ? parsed.value.id : "";
|
|
if (!nextID) return;
|
|
const previous = selected.value;
|
|
// Saving replaces the entry with that id, so a rename onto another
|
|
// workflow's id would silently overwrite it.
|
|
if (previous !== nextID && collection.value.definitions.some((entry) => entry.id === nextID)) {
|
|
localError.value = `A workflow with id "${nextID}" already exists; choose another id.`;
|
|
return;
|
|
}
|
|
let next = collection.value;
|
|
if (previous && previous !== nextID)
|
|
next = removeWorkflowDefinition(next, previous);
|
|
if (
|
|
await save(upsertWorkflowDefinition(next, { id: nextID, yaml: yaml.value }))
|
|
) {
|
|
await dropDraft(previous);
|
|
if (previous !== nextID) await dropDraft(nextID);
|
|
selected.value = nextID;
|
|
loadedYaml.value = yaml.value;
|
|
}
|
|
}
|
|
|
|
// The run button and draft menu item each control their dialog.
|
|
const runOpen = ref(false);
|
|
const draftOpen = ref(false);
|
|
const confirmDelete = ref(false);
|
|
async function remove(): Promise<void> {
|
|
if (!selected.value) return;
|
|
if (
|
|
!(await save(removeWorkflowDefinition(collection.value, selected.value)))
|
|
)
|
|
return;
|
|
await dropDraft(selected.value);
|
|
selected.value = "";
|
|
id.value = "";
|
|
yaml.value = "";
|
|
}
|
|
|
|
// 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);
|
|
const parsed = computed(() => parseWorkflowYaml(yaml.value, vocabulary.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 = ref("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 errors = 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 workflowSummary = computed(() => String(workflowField(canvasYaml.value, "profile") ?? ""));
|
|
const runOptions = computed(() => [
|
|
{ value: "", label: "Definition" },
|
|
...runs.value.map((run) => ({
|
|
value: String(run.id),
|
|
label: [`${run.source === "test" ? "Test" : "Run"} #${run.id}`, run.status && statusLabel(run.status), run.created_at ? ago(run.created_at) : ""].filter(Boolean).join(" · "),
|
|
})),
|
|
]);
|
|
const lines = computed(() => yamlLines(yaml.value));
|
|
// The sections that sit beside Canvas and YAML once the editor has the width
|
|
// for them (the workflow list takes 24rem of it), and otherwise the one menu,
|
|
// which names the section in view beside the tabs.
|
|
const SECTIONS: Record<string, string> = { history: "History", performance: "Performance", runs: "Runs" };
|
|
|
|
// The highlight layer sits behind the textarea and never scrolls by itself, so
|
|
// it follows the textarea's own scroll. Lines wrap at the editor's width, and
|
|
// each wrapped line's gutter cell lists a continuation mark per extra row, so
|
|
// the numbers still count lines of the file. A row's wrapped height is measured
|
|
// from the layer, which breaks exactly where the textarea does.
|
|
const scrolled = ref({ top: 0 });
|
|
const scrollbar = ref(0);
|
|
const rowEls = ref<HTMLElement[]>([]);
|
|
const wraps = ref<number[]>([]);
|
|
const yamlBox = ref<InstanceType<typeof Textarea> | null>(null);
|
|
function syncScroll(event: Event): void {
|
|
scrolled.value = { top: (event.target as HTMLTextAreaElement).scrollTop };
|
|
}
|
|
function measureWraps(): void {
|
|
const field = document.getElementById("workflow-yaml");
|
|
scrollbar.value = field ? field.offsetWidth - field.clientWidth : 0;
|
|
wraps.value = rowEls.value.map((row) =>
|
|
Math.max(1, Math.round(row.offsetHeight / (parseFloat(getComputedStyle(row).lineHeight) || 24))),
|
|
);
|
|
}
|
|
let yamlObserver: ResizeObserver | undefined;
|
|
watch(yamlBox, (box) => {
|
|
yamlObserver?.disconnect();
|
|
const field = box ? document.getElementById("workflow-yaml") : null;
|
|
if (!field) return;
|
|
yamlObserver = new ResizeObserver(measureWraps);
|
|
yamlObserver.observe(field);
|
|
});
|
|
watch(lines, () => nextTick(measureWraps), { flush: "post" });
|
|
onBeforeUnmount(() => yamlObserver?.disconnect());
|
|
|
|
</script>
|
|
|
|
<template>
|
|
<form class="space-y-4 max-md:flex max-md:min-h-0 max-md:flex-1 max-md:flex-col" @submit.prevent="publish">
|
|
<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 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 v-if="stored !== undefined" value="history" class="max-xl:hidden">History</TabsTrigger>
|
|
<TabsTrigger v-if="$slots.performance" value="performance" class="max-xl:hidden">Performance</TabsTrigger>
|
|
<TabsTrigger v-if="$slots.runs && stored !== undefined" value="runs" class="max-xl:hidden">Runs <span class="ml-1 font-mono text-xs text-fg-subtle">{{ runsCount ?? 0 }}</span></TabsTrigger>
|
|
</TabsList>
|
|
<span v-if="SECTIONS[view]" class="shrink-0 text-xs font-medium text-fg-muted xl:hidden">{{ SECTIONS[view] }}</span>
|
|
<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="stored !== undefined && (view === 'canvas' || view === 'yaml')" class="shrink-0">
|
|
<RunWorkflowButton
|
|
v-model:open="runOpen"
|
|
:workflow="selected"
|
|
:draft="dirty ? yaml : undefined"
|
|
:disabled="!parsed.ok"
|
|
@started="(id) => { view = 'canvas'; void follow(id); }"
|
|
/>
|
|
</div>
|
|
<div v-if="runs.length && view === 'canvas'" class="flex min-w-0 items-center gap-1 max-sm:flex-1">
|
|
<OptionSelect :model-value="watched" :options="runOptions" aria-label="Run shown on the canvas" class="min-w-0 max-w-56 max-sm:w-full *:data-[slot=select-value]:block *:data-[slot=select-value]:truncate" @update:model-value="pick" />
|
|
<template v-if="watchedRun">
|
|
<!-- One run control keeps the row short; the run's other actions
|
|
are on the run, behind Open run in this menu. -->
|
|
<TaskRowActions :task="watchedRun" :only="watchedRun.actions?.slice(0, 1)" secondary class="max-md:hidden" @done="refresh" />
|
|
</template>
|
|
</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-xs 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-xs text-danger">
|
|
<li v-for="(error, i) in errors" :key="i">
|
|
<button v-if="error.path" type="button" class="w-full rounded px-2 py-1.5 text-left hover:bg-muted 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="view === 'canvas' || view === 'yaml'" class="shrink-0" :title="publishBlocked">
|
|
<Button type="submit" size="sm" class="disabled:bg-muted disabled:text-fg-muted disabled:opacity-100" :disabled="state.saving || !!publishBlocked">
|
|
<Spinner v-if="state.saving" data-icon="inline-start" />Publish</Button>
|
|
</span>
|
|
<MoreMenu>
|
|
<DropdownMenuItem v-if="stored !== undefined" class="xl:hidden" @select="view = 'history'">History</DropdownMenuItem>
|
|
<DropdownMenuItem v-if="$slots.performance" class="xl:hidden" @select="view = 'performance'">Performance</DropdownMenuItem>
|
|
<DropdownMenuItem v-if="$slots.runs && stored !== undefined" class="xl:hidden" @select="view = 'runs'">Runs <span class="ml-auto font-mono text-xs text-fg-subtle">{{ runsCount ?? 0 }}</span></DropdownMenuItem>
|
|
<!-- 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="`/tasks/${watchedRun.id}`">Open run</RouterLink></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-xs text-fg-subtle">{{ changes.length }}</span></DropdownMenuItem>
|
|
<DropdownMenuItem v-if="dirty" :disabled="archieWorking" @select="restorePublished"><RotateCcw />Restore</DropdownMenuItem>
|
|
<DropdownMenuItem v-if="view === 'canvas' || view === 'yaml'" variant="destructive" @select="confirmDelete = true"><Trash2 />Delete workflow</DropdownMenuItem>
|
|
</MoreMenu>
|
|
</div>
|
|
</div>
|
|
<p v-if="runsLoading && !runs.length" class="text-xs text-fg-muted" role="status">Loading recent runs…</p>
|
|
<div v-else-if="runsError" class="text-sm text-danger" role="alert">
|
|
<p>Could not load recent runs: {{ runsError }}</p>
|
|
<Button type="button" variant="outline" size="sm" @click="refresh">Retry runs</Button>
|
|
</div>
|
|
<p v-if="view === 'canvas' && unpinned" class="text-xs 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-22rem)] min-h-[26rem] flex-col max-md:h-auto max-md:min-h-0 max-md:flex-1">
|
|
<p v-if="restartError" role="alert" class="absolute bottom-16 left-14 z-10 max-w-xl rounded-md border border-danger/40 bg-card px-3 py-2 text-sm text-danger shadow-lg">{{ restartError }}</p>
|
|
<WorkflowCanvas
|
|
class="h-auto min-h-0 flex-1"
|
|
:yaml="canvasYaml"
|
|
:stages="drawnStages"
|
|
:open="open"
|
|
:triggers="triggers"
|
|
:types="stepTypeNames"
|
|
:readonly="!!pinnedYaml || archieWorking"
|
|
:restartable="restartable"
|
|
:problems="pinnedYaml ? undefined : nodeProblems"
|
|
:title="parsed.ok ? parsed.id : id"
|
|
:summary="workflowSummary"
|
|
@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>
|
|
<fieldset v-else-if="data.kind === 'start'" :disabled="!!pinnedYaml" class="min-w-0"><TriggerSettings :yaml="canvasYaml" :triggers="triggers" @update:yaml="yaml = $event" @bound="reloadTriggers" /></fieldset>
|
|
<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 :task="watchedRun" :attempt="attempt" :stage="data.run" :stages="stages" />
|
|
</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="history" class="max-md:min-h-0 max-md:overflow-y-auto">
|
|
<WorkflowHistory v-model:selected="historyRevision" v-model:mode="historyMode" :revisions="revisions" :current="yaml" :error="historyError" @restore="restoreRevision" />
|
|
</TabsContent>
|
|
<TabsContent value="performance" class="grid gap-4 max-md:min-h-0 max-md:overflow-y-auto"><slot name="performance" /></TabsContent>
|
|
<TabsContent value="runs" class="max-md:min-h-0 max-md:overflow-y-auto"><slot name="runs" /></TabsContent>
|
|
<TabsContent value="yaml" class="max-md:min-h-0 max-md:overflow-y-auto">
|
|
<!--
|
|
A gutter and a highlighted layer behind the live textarea, so the YAML
|
|
is numbered and coloured where it is edited rather than in a second,
|
|
read-only pane beside it. The layer is aria-hidden and never focusable:
|
|
the textarea in front of it stays the only thing the operator and a
|
|
screen reader reach.
|
|
-->
|
|
<div
|
|
class="relative overflow-hidden rounded-lg border border-input font-mono max-md:h-full text-label leading-6 focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50"
|
|
>
|
|
<div
|
|
aria-hidden="true"
|
|
class="pointer-events-none absolute inset-y-0 left-0 w-11 select-none border-r border-border bg-secondary/40"
|
|
></div>
|
|
<div
|
|
aria-hidden="true"
|
|
class="pointer-events-none absolute inset-0 overflow-hidden py-3 pr-3"
|
|
:style="{ paddingRight: `calc(0.75rem + ${scrollbar}px)` }"
|
|
>
|
|
<div :style="`transform:translateY(${-scrolled.top}px)`">
|
|
<div
|
|
v-for="(line, i) in lines"
|
|
:key="line.number"
|
|
:ref="(el) => { if (el) rowEls[i] = el as HTMLElement }"
|
|
class="flex min-h-6"
|
|
>
|
|
<div class="w-11 shrink-0 select-none pr-2 text-right text-fg-subtle">
|
|
<div>{{ line.number }}</div>
|
|
<div v-for="n in (wraps[i] ?? 1) - 1" :key="n">↳</div>
|
|
</div>
|
|
<div class="max-w-[calc(var(--code-print-width)+0.75rem)] min-w-0 flex-1 pl-3 break-words whitespace-pre-wrap">
|
|
<span
|
|
v-for="(token, j) in line.tokens"
|
|
:key="j"
|
|
:class="yamlTokenClass(token.kind)"
|
|
>{{ token.text }}</span
|
|
>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<Textarea
|
|
id="workflow-yaml"
|
|
ref="yamlBox"
|
|
aria-label="Workflow YAML"
|
|
v-model="yaml"
|
|
name="workflow-yaml"
|
|
required
|
|
:readonly="archieWorking"
|
|
class="relative min-h-96 resize-y max-md:h-full max-md:min-h-0 max-md:resize-none rounded-none border-0 bg-transparent pt-3 pr-3 pb-[calc(0.75rem+var(--code-overscroll))] pl-14 text-label leading-6 break-words whitespace-pre-wrap text-transparent caret-foreground shadow-none md:text-label focus-visible:ring-0"
|
|
spellcheck="false"
|
|
wrap="soft"
|
|
:style="{ maxWidth: `calc(3.5rem + var(--code-print-width) + 0.75rem + ${scrollbar}px)` }"
|
|
@scroll="syncScroll"
|
|
/>
|
|
</div>
|
|
</TabsContent>
|
|
</Tabs>
|
|
<p v-if="localError || state.error" class="text-sm text-danger" role="alert">
|
|
{{ localError || state.error }}
|
|
</p>
|
|
<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="confirmDelete">
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>Delete the {{ selected }} workflow?</AlertDialogTitle>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
<AlertDialogAction variant="destructive" @click="remove">Delete</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
</form>
|
|
</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>
|