feat(ui/workflows): restore the workflow list and page on the archie binary (#2023)
The list and page keep the original layout and read the binary's API. Duplicate triggers are grouped. Runs and run pages use the shared table. The older editor stays on its hidden route as WorkflowEditorPage.
This commit is contained in:
11 files changed
+509
-207
No files matched your search
+4
-11
@@ -32,8 +32,7 @@ const SystemTasksPage = () => import("@/settings/SystemTasksPage.vue");
|
||||
const SkillsPage = () => import("@/skills/SkillsPage.vue");
|
||||
const TaskDetailPage = () => import("@/tasks/TaskDetailPage.vue");
|
||||
const TasksPage = () => import("@/tasks/TasksPage.vue");
|
||||
const WorkflowsPage = () => import("@/workflows/WorkflowsPage.vue");
|
||||
const WorkflowPage = () => import("@/workflows/WorkflowPage.vue");
|
||||
const WorkflowEditorPage = () => import("@/workflows/WorkflowEditorPage.vue");
|
||||
|
||||
// internal/gateway/dashboard_tools.go mirrors this table.
|
||||
//
|
||||
@@ -94,7 +93,7 @@ export const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: "/workflows",
|
||||
name: "workflows",
|
||||
component: () => import("@/workflows/WorkflowListPage.vue"),
|
||||
component: () => import("@/workflows/WorkflowsPage.vue"),
|
||||
// Links written as /workflows?workflow=<id> open that workflow's page.
|
||||
beforeEnter: (to: RouteLocationGeneric) => {
|
||||
const { workflow, ...query } = to.query;
|
||||
@@ -110,21 +109,15 @@ export const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: "/workflows/:id",
|
||||
name: "workflow",
|
||||
component: () => import("@/workflows/WorkflowDocumentPage.vue"),
|
||||
component: () => import("@/workflows/WorkflowPage.vue"),
|
||||
meta: { label: "Workflow", nav: false, navPath: "/workflows", section: "workflows" },
|
||||
},
|
||||
// The visual editor, with drafts, test runs and per-step statistics; it
|
||||
// needs workflow drafts and run stages the binary does not serve yet.
|
||||
{
|
||||
path: "/workflow-editor",
|
||||
name: "workflow-editor-list",
|
||||
component: WorkflowsPage,
|
||||
meta: { label: "Workflow editor", nav: false, navPath: "/workflows", section: "workflow_editor" },
|
||||
},
|
||||
{
|
||||
path: "/workflow-editor/:id",
|
||||
name: "workflow-editor",
|
||||
component: WorkflowPage,
|
||||
component: WorkflowEditorPage,
|
||||
meta: { label: "Workflow", nav: false, navPath: "/workflows", section: "workflow_editor" },
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<script setup lang="ts">
|
||||
import { ExternalLink, Workflow } from "@lucide/vue";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { ContextMenuItem } from "@/components/ui/context-menu";
|
||||
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { duration } from "@/lib/format";
|
||||
import type { Run } from "@/lib/api";
|
||||
import { stateLabel, stateTone } from "./state";
|
||||
|
||||
/** Workflow runs as a table. A workflow's own page leaves its name column out. */
|
||||
const props = defineProps<{ rows: Run[]; storageKey: string; withWorkflow?: boolean }>();
|
||||
const router = useRouter();
|
||||
|
||||
const time = (at?: string) => (at ? Date.parse(at) : 0);
|
||||
const took = (run: Run) => (run.finished_at ? time(run.finished_at) - time(run.created_at) : -1);
|
||||
const columns: DataTableColumn<Run>[] = [
|
||||
...(props.withWorkflow ? [{ id: "workflow", label: "Workflow", fixed: true, sort: (r: Run) => r.workflow }] : []),
|
||||
{ id: "state", label: "State", fixed: true, width: "11rem", sort: (r) => r.state },
|
||||
{ id: "created", label: "Started", width: "9rem", sort: (r) => time(r.created_at) },
|
||||
{ id: "duration", label: "Took", width: "8rem", sort: took },
|
||||
{ id: "attempts", label: "Attempts", hidden: true, width: "7rem", sort: (r) => r.attempts },
|
||||
{ id: "id", label: "Run", hidden: true, width: "14rem" },
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<DataTable
|
||||
:columns="columns"
|
||||
:rows="rows"
|
||||
:row-key="(r) => r.id"
|
||||
:row-link="(r) => `/runs/${r.id}`"
|
||||
:row-label="(r) => `${r.workflow} run`"
|
||||
:storage-key="storageKey"
|
||||
:initial-sort="{ id: 'created', desc: true }"
|
||||
>
|
||||
<template #cell-workflow="{ row }">
|
||||
<span class="font-medium">{{ row.workflow }}</span> <span class="text-caption text-fg-subtle">v{{ row.workflow_version }}</span>
|
||||
</template>
|
||||
<template #cell-state="{ row }"><Badge :variant="stateTone(row.state)" :title="row.error || undefined">{{ stateLabel(row.state) }}</Badge></template>
|
||||
<template #cell-created="{ row }"><Timestamp :at="row.created_at" /></template>
|
||||
<template #cell-duration="{ row }"><span class="text-caption text-fg-muted">{{ took(row) >= 0 ? duration(took(row)) : "" }}</span></template>
|
||||
<template #cell-attempts="{ row }">{{ row.attempts }}</template>
|
||||
<template #cell-id="{ row }"><span class="font-mono text-caption text-fg-muted">{{ row.id.slice(0, 8) }}</span></template>
|
||||
<template #menu="{ row }">
|
||||
<ContextMenuItem @select="router.push(`/runs/${row.id}`)"><ExternalLink />Open run</ContextMenuItem>
|
||||
<ContextMenuItem @select="router.push(`/workflows/${row.workflow}`)"><Workflow />Open workflow</ContextMenuItem>
|
||||
</template>
|
||||
<template #empty><slot name="empty" /></template>
|
||||
</DataTable>
|
||||
</template>
|
||||
+27
-50
@@ -1,75 +1,52 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { Search } from "@lucide/vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { X } from "@lucide/vue";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import type { Run } from "@/lib/api";
|
||||
import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { api } from "@/lib/api";
|
||||
import { usePoll, useRead } from "@/lib/use-read";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
import ApprovalsSection from "./ApprovalsSection.vue";
|
||||
import { stateTone } from "./state";
|
||||
import RunTable from "./RunTable.vue";
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { data, error, reload } = useRead(() => api.runs());
|
||||
onMounted(reload);
|
||||
useLiveResource(null, () => void reload());
|
||||
usePoll(reload);
|
||||
|
||||
// ?workflow= narrows the list to one workflow's runs, so a workflow links here.
|
||||
const workflow = computed(() => String(route.query.workflow ?? ""));
|
||||
const rows = computed(() => (data.value ?? []).filter((r) => !workflow.value || r.workflow === workflow.value));
|
||||
|
||||
const time = (at?: string) => (at ? Date.parse(at) : 0);
|
||||
const columns: DataTableColumn<Run>[] = [
|
||||
{ id: "workflow", label: "Workflow", fixed: true, sort: (r) => r.workflow },
|
||||
{ id: "state", label: "State", fixed: true, sort: (r) => r.state },
|
||||
{ id: "created", label: "Started", sort: (r) => time(r.created_at) },
|
||||
{ id: "finished", label: "Finished", sort: (r) => time(r.finished_at) },
|
||||
{ id: "attempts", label: "Attempts", hidden: true, sort: (r) => r.attempts },
|
||||
{ id: "id", label: "Run", hidden: true },
|
||||
];
|
||||
// A workflow links here with ?workflow=, which starts the filter on its name.
|
||||
const query = ref(String(route.query.workflow ?? ""));
|
||||
// A filter earns its place once the list outgrows a glance.
|
||||
const FILTER_FROM = 8;
|
||||
const filterable = computed(() => (data.value?.length ?? 0) > FILTER_FROM || !!query.value);
|
||||
const shown = computed(() => {
|
||||
const needle = query.value.trim().toLowerCase();
|
||||
return (data.value ?? []).filter((r) => !needle || r.workflow.toLowerCase().includes(needle) || r.state.includes(needle));
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Runs">
|
||||
<Button v-if="workflow" variant="outline" size="sm" title="Show every workflow's runs" @click="router.replace({ query: {} })">{{ workflow }}<X data-icon="inline-end" /></Button>
|
||||
<InputGroup v-if="filterable" class="w-56 max-sm:w-full">
|
||||
<InputGroupAddon><Search /></InputGroupAddon>
|
||||
<InputGroupInput v-model="query" type="search" aria-label="Filter runs" placeholder="Filter" />
|
||||
</InputGroup>
|
||||
</PageHeader>
|
||||
<ApprovalsSection @answered="reload" />
|
||||
<ReadError v-if="error" :message="error" retry-label="Retry" @retry="reload" />
|
||||
<div v-else-if="!data" role="status" aria-label="Loading runs" class="space-y-2"><Skeleton class="h-8 w-full" /><Skeleton class="h-8 w-full" /></div>
|
||||
<DataTable
|
||||
v-else
|
||||
:columns="columns"
|
||||
:rows="rows"
|
||||
:row-key="(r) => r.id"
|
||||
:row-link="(r) => `/runs/${r.id}`"
|
||||
:row-label="(r) => `${r.workflow} run`"
|
||||
storage-key="runs"
|
||||
:initial-sort="{ id: 'created', desc: true }"
|
||||
>
|
||||
<template #cell-workflow="{ row }"><span class="font-medium">{{ row.workflow }}</span> <span class="text-caption text-fg-subtle">v{{ row.workflow_version }}</span></template>
|
||||
<template #cell-state="{ row }">
|
||||
<Badge :variant="stateTone(row.state)" :title="row.error || undefined">{{ row.state }}</Badge>
|
||||
</template>
|
||||
<template #cell-created="{ row }"><Timestamp :at="row.created_at" /></template>
|
||||
<template #cell-finished="{ row }"><Timestamp :at="row.finished_at" /></template>
|
||||
<template #cell-attempts="{ row }">{{ row.attempts }}</template>
|
||||
<template #cell-id="{ row }"><span class="font-mono text-caption">{{ row.id }}</span></template>
|
||||
<template #empty>
|
||||
<Empty><EmptyHeader><EmptyTitle>No runs yet</EmptyTitle></EmptyHeader></Empty>
|
||||
</template>
|
||||
</DataTable>
|
||||
<div v-if="error" class="mb-4 text-label text-danger" role="alert">
|
||||
<p>{{ error }}</p>
|
||||
<Button variant="outline" size="sm" @click="reload">Retry</Button>
|
||||
</div>
|
||||
<p v-else-if="!data" class="flex items-center gap-2 text-label text-fg-muted"><Spinner />Loading runs…</p>
|
||||
<Empty v-else-if="!data.length"><EmptyHeader><EmptyTitle>No runs</EmptyTitle></EmptyHeader></Empty>
|
||||
<p v-else-if="!shown.length" class="text-label text-fg-muted">No run matches.</p>
|
||||
<RunTable v-else :rows="shown" storage-key="runs" with-workflow />
|
||||
</div>
|
||||
</template>
|
||||
@@ -25,6 +25,11 @@ export function stateTone(state: string): "ok" | "warn" | "danger" | "info" | "i
|
||||
}
|
||||
}
|
||||
|
||||
/** A run state in words: "waiting_approval" reads "waiting approval". */
|
||||
export function stateLabel(state: string): string {
|
||||
return state.replace(/_/g, " ");
|
||||
}
|
||||
|
||||
/** Whether a run state is terminal: the run has ended and cannot be cancelled. */
|
||||
export function ended(state: string): boolean {
|
||||
switch (state) {
|
||||
|
||||
@@ -20,7 +20,7 @@ const { store, data, error, loading, statsKnown, load, enabledOf, setEnabled, du
|
||||
// under another id or deleting, and the URL follows.
|
||||
const selected = computed({
|
||||
get: () => String(route.params.id ?? ""),
|
||||
set: (id: string) => void (id ? router.replace({ name: "workflow-editor", params: { id }, query: route.query }) : router.replace({ name: "workflow-editor-list" })),
|
||||
set: (id: string) => void (id ? router.replace({ name: "workflow-editor", params: { id }, query: route.query }) : router.replace({ name: "workflows" })),
|
||||
});
|
||||
|
||||
// ?view= opens a tab and ?run= opens the run dialog; a link carries them once.
|
||||
|
||||
@@ -54,7 +54,7 @@ const CHANGE_VARIANTS = { added: "default", edited: "secondary", removed: "destr
|
||||
<span class="font-mono text-caption text-fg-subtle">v{{ item.version }}</span>
|
||||
<Badge :variant="CHANGE_VARIANTS[item.change]">{{ item.change }}</Badge>
|
||||
</span>
|
||||
<span class="mt-0.5 block truncate text-caption text-fg-muted" :title="item.at">{{ item.actor || "unknown" }} · {{ item.source || "unknown" }} · <Timestamp :at="item.at" /></span>
|
||||
<span class="mt-0.5 block truncate text-caption text-fg-muted" :title="item.at">{{ item.actor || "unknown" }} · <template v-if="item.source">{{ item.source }} · </template><Timestamp :at="item.at" /></span>
|
||||
</button>
|
||||
</li>
|
||||
<!-- A failed reload says so even over an older list, which may be stale. -->
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { StatusDot } from "@/components/ui/status-dot";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { statusKind, statusLabel } from "@/lib/task-meta";
|
||||
import { stateLabel } from "@/runs/state";
|
||||
|
||||
/** A workflow's newest run: how it stands, when it started, and a link to it. */
|
||||
defineProps<{ runId?: number; status?: string; at?: string; running?: number; known: boolean }>();
|
||||
defineProps<{ to?: string; state?: string; tone?: "ok" | "warn" | "danger" | "info" | "idle"; at?: string; running?: number; known: boolean }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RouterLink v-if="runId" :to="{ name: 'task-detail', params: { id: runId } }" class="inline-flex min-w-0 flex-col gap-0.5 rounded-sm hover:underline focus-visible:outline-2 focus-visible:outline-ring" :aria-label="`Run #${runId}, ${statusLabel(status ?? '')}`" @click.stop>
|
||||
<RouterLink v-if="to" :to="to" class="inline-flex min-w-0 flex-col gap-0.5 rounded-sm hover:underline focus-visible:outline-2 focus-visible:outline-ring" :aria-label="`Latest run, ${stateLabel(state ?? '')}`" @click.stop>
|
||||
<span class="flex items-center gap-1.5 text-label">
|
||||
<StatusDot :tone="running ? 'info' : statusKind(status ?? '')" :live="!!running" />{{ running ? `${running} running` : statusLabel(status ?? "") }}
|
||||
<StatusDot :tone="running ? 'info' : tone" :live="!!running" />{{ running ? `${running} running` : stateLabel(state ?? "") }}
|
||||
</span>
|
||||
<Timestamp :at="at" class="text-caption text-fg-subtle" />
|
||||
</RouterLink>
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useSessionStorage } from "@vueuse/core";
|
||||
import { Copy, RotateCcw } from "@lucide/vue";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
|
||||
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { MoreMenu } from "@/components/ui/more-menu";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { usePoll, useRead } from "@/lib/use-read";
|
||||
import TriggerList from "@/events/TriggerList.vue";
|
||||
import RunTable from "@/runs/RunTable.vue";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
import { startedBy } from "./use-workflow-list";
|
||||
import WorkflowCanvas from "./WorkflowCanvas.vue";
|
||||
import WorkflowHistory from "./WorkflowHistory.vue";
|
||||
import WorkflowYaml from "./WorkflowYaml.vue";
|
||||
import type { WorkflowRevision } from "./workflow-revisions";
|
||||
import type { WorkflowTrigger } from "./workflow-triggers";
|
||||
|
||||
/** One workflow: its graph, its document, the versions it has been published
|
||||
* as, its runs and the triggers that start it. */
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const name = computed(() => String(route.params.id));
|
||||
|
||||
const latest = useRead(() => api.workflow(name.value));
|
||||
const triggers = useRead(() => api.triggers());
|
||||
const runs = useRead(() => api.runs());
|
||||
onMounted(() => {
|
||||
void latest.reload();
|
||||
void triggers.reload();
|
||||
void runs.reload();
|
||||
});
|
||||
useLiveResource(null, () => void runs.reload());
|
||||
usePoll(runs.reload);
|
||||
watch(name, () => {
|
||||
void latest.reload();
|
||||
void triggers.reload();
|
||||
void runs.reload();
|
||||
});
|
||||
|
||||
// The edit is kept per browser tab until it is published or discarded, so
|
||||
// leaving the page does not lose it.
|
||||
const edit = useSessionStorage<{ base: number; yaml: string } | null>(() => `archie.workflow-edit.${name.value}`, null, { serializer: { read: (v) => JSON.parse(v), write: (v) => JSON.stringify(v) } });
|
||||
const yaml = computed({
|
||||
get: () => (edit.value && edit.value.base === latest.data.value?.version ? edit.value.yaml : (latest.data.value?.body ?? "")),
|
||||
set: (value: string) => {
|
||||
const base = latest.data.value?.version ?? 0;
|
||||
edit.value = value === latest.data.value?.body ? null : { base, yaml: value };
|
||||
},
|
||||
});
|
||||
const edited = computed(() => !!latest.data.value && yaml.value !== latest.data.value.body);
|
||||
|
||||
const busy = ref(false);
|
||||
const publishError = ref("");
|
||||
async function publish(): Promise<void> {
|
||||
busy.value = true;
|
||||
publishError.value = "";
|
||||
try {
|
||||
// Another writer (a person, or Archie publishing a draft) may have
|
||||
// published since this copy was opened; never overwrite their version.
|
||||
const current = await api.workflow(name.value);
|
||||
if (current.version !== edit.value?.base) {
|
||||
publishError.value = `Version ${current.version} was published after you opened version ${edit.value?.base}. Copy your changes, then discard them to load it.`;
|
||||
return;
|
||||
}
|
||||
await api.putWorkflow(name.value, yaml.value);
|
||||
edit.value = null;
|
||||
await latest.reload();
|
||||
} catch (cause) {
|
||||
publishError.value = describeError(cause, errors.common.unknown);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
const discarding = ref(false);
|
||||
function discard(): void {
|
||||
edit.value = null;
|
||||
publishError.value = "";
|
||||
discarding.value = false;
|
||||
void latest.reload();
|
||||
}
|
||||
|
||||
async function duplicate(): Promise<void> {
|
||||
const taken = new Set((await api.workflowList()).map((w) => w.name));
|
||||
let next = `${name.value}-copy`;
|
||||
for (let n = 2; taken.has(next); n++) next = `${name.value}-copy-${n}`;
|
||||
try {
|
||||
await api.putWorkflow(next, yaml.value);
|
||||
void router.push(`/workflows/${next}`);
|
||||
} catch (cause) {
|
||||
publishError.value = describeError(cause, errors.common.unknown);
|
||||
}
|
||||
}
|
||||
|
||||
// ?view= opens a tab; a link carries it once.
|
||||
const VIEWS = ["yaml", "history", "runs", "triggers"];
|
||||
const view = computed({
|
||||
get: () => (VIEWS.includes(String(route.query.view)) ? String(route.query.view) : "canvas"),
|
||||
set: (v: string) => void router.replace({ query: { ...route.query, view: v === "canvas" ? undefined : v } }),
|
||||
});
|
||||
const open = ref<string | null>(null);
|
||||
|
||||
// Every published version, read when the history is first opened.
|
||||
const revisions = useRead<WorkflowRevision[]>(async () => {
|
||||
const count = latest.data.value?.version ?? 0;
|
||||
const versions = await Promise.all(Array.from({ length: count }, (_, i) => api.workflow(name.value, i + 1)));
|
||||
return versions
|
||||
.map((w) => ({ version: w.version, change: w.version === 1 ? ("added" as const) : ("edited" as const), yaml: w.body, actor: w.created_by ?? "", source: "", at: w.created_at }))
|
||||
.reverse();
|
||||
});
|
||||
const historyRevision = ref(0);
|
||||
const historyMode = ref("yaml");
|
||||
watch([view, () => latest.data.value?.version], ([v]) => v === "history" && void revisions.reload(), { immediate: true });
|
||||
function restore(body: string): void {
|
||||
yaml.value = body;
|
||||
view.value = "yaml";
|
||||
}
|
||||
|
||||
const own = computed(() => (runs.data.value ?? []).filter((r) => r.workflow === name.value));
|
||||
const starts = computed(() => [...new Set((triggers.data.value ?? []).filter((t) => t.workflow === name.value).map(startedBy))]);
|
||||
const canvasTriggers = computed<WorkflowTrigger[]>(() =>
|
||||
(triggers.data.value ?? [])
|
||||
.filter((t) => t.workflow === name.value)
|
||||
.map((t) => ({ kind: t.every ? "schedule" : "event", label: t.every ? startedBy(t) : t.name, detail: t.every ? undefined : startedBy(t) })),
|
||||
);
|
||||
const startsText = computed(() => starts.value[0] ?? (triggers.data.value ? "Manual" : ""));
|
||||
const startsMore = computed(() => starts.value.slice(1));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="max-md:flex max-md:min-h-0 max-md:flex-1 max-md:flex-col">
|
||||
<div v-if="latest.error.value" class="mb-4 text-label text-danger" role="alert">
|
||||
<p>{{ latest.error.value }}</p>
|
||||
<Button variant="outline" size="sm" @click="latest.reload">Retry</Button>
|
||||
</div>
|
||||
<p v-else-if="!latest.data.value" class="flex items-center gap-2 text-label text-fg-muted"><Spinner />Loading workflow…</p>
|
||||
<div v-else class="min-w-0 max-md:flex max-md:h-full max-md:min-h-0 max-md:flex-col" role="region" aria-label="Workflow">
|
||||
<header class="mb-2 flex shrink-0 flex-wrap items-center gap-x-3 gap-y-0.5 lg:hidden">
|
||||
<h1 class="min-w-0 truncate text-title font-medium">{{ name }}</h1>
|
||||
<Badge v-if="edited" variant="outline" class="shrink-0">Unpublished</Badge>
|
||||
<p v-if="startsText" class="flex min-w-0 basis-full items-center gap-1.5 text-caption text-fg-muted">
|
||||
<span class="truncate">{{ startsText }}</span>
|
||||
<Badge v-if="startsMore.length" variant="secondary" :title="startsMore.join('\n')">+{{ startsMore.length }}</Badge>
|
||||
</p>
|
||||
</header>
|
||||
<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="flex shrink-0 flex-wrap items-center gap-2 max-sm:grid max-sm:grid-cols-[1fr_auto]">
|
||||
<div class="flex min-w-0 shrink items-center gap-2 max-lg:hidden">
|
||||
<h1 class="min-w-0 truncate text-title font-medium">{{ name }}</h1>
|
||||
<span class="shrink-0 text-caption text-fg-subtle">v{{ latest.data.value.version }}</span>
|
||||
<Badge v-if="edited" variant="outline" class="shrink-0">Unpublished</Badge>
|
||||
<p v-if="startsText" class="flex min-w-0 max-w-64 items-center gap-1.5 text-caption text-fg-muted">
|
||||
<span class="truncate">{{ startsText }}</span>
|
||||
<Badge v-if="startsMore.length" variant="secondary" :title="startsMore.join('\n')">+{{ startsMore.length }}</Badge>
|
||||
</p>
|
||||
</div>
|
||||
<TabsList class="shrink-0 justify-start">
|
||||
<TabsTrigger value="canvas">Canvas</TabsTrigger>
|
||||
<TabsTrigger value="yaml">YAML</TabsTrigger>
|
||||
<TabsTrigger value="history">History</TabsTrigger>
|
||||
<TabsTrigger value="runs">Runs <span v-if="own.length" class="ml-1 font-mono text-caption text-fg-subtle">{{ own.length }}</span></TabsTrigger>
|
||||
<TabsTrigger value="triggers">Triggers</TabsTrigger>
|
||||
</TabsList>
|
||||
<div role="group" aria-label="Edit" class="ml-auto flex min-w-0 items-center gap-1 border-l pl-2 max-sm:col-start-2 max-sm:row-start-1">
|
||||
<span v-if="edited" class="shrink-0">
|
||||
<Button type="button" size="sm" :disabled="busy" @click="publish"><Spinner v-if="busy" data-icon="inline-start" />Publish</Button>
|
||||
</span>
|
||||
<MoreMenu>
|
||||
<DropdownMenuItem v-if="edited" @select="discarding = true"><RotateCcw />Discard changes</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="duplicate"><Copy />Duplicate</DropdownMenuItem>
|
||||
</MoreMenu>
|
||||
</div>
|
||||
</div>
|
||||
<Alert v-if="publishError" variant="destructive"><AlertDescription>{{ publishError }}</AlertDescription></Alert>
|
||||
<TabsContent value="canvas" class="space-y-2 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">
|
||||
<WorkflowCanvas class="h-auto min-h-0 flex-1" :yaml="yaml" readonly :open="open" :triggers="canvasTriggers" :title="name" @toggle="open = open === $event ? null : $event" />
|
||||
</div>
|
||||
</TabsContent>
|
||||
<TabsContent value="yaml" class="max-md:min-h-0 max-md:overflow-y-auto">
|
||||
<WorkflowYaml v-model="yaml" />
|
||||
</TabsContent>
|
||||
<TabsContent value="history" class="max-md:min-h-0 max-md:overflow-y-auto">
|
||||
<WorkflowHistory
|
||||
v-model:selected="historyRevision"
|
||||
v-model:mode="historyMode"
|
||||
v-model:current="yaml"
|
||||
:revisions="revisions.data.value ?? []"
|
||||
:error="revisions.error.value"
|
||||
:loaded="!!revisions.data.value"
|
||||
@restore="restore"
|
||||
@retry="revisions.reload"
|
||||
/>
|
||||
</TabsContent>
|
||||
<TabsContent value="runs" class="max-md:min-h-0 max-md:overflow-y-auto">
|
||||
<p v-if="runs.error.value" role="alert" class="text-label text-danger">{{ runs.error.value }}</p>
|
||||
<p v-else-if="!runs.data.value" class="flex items-center gap-2 text-label text-fg-muted"><Spinner />Loading runs…</p>
|
||||
<Empty v-else-if="!own.length"><EmptyHeader><EmptyTitle>No runs yet</EmptyTitle></EmptyHeader></Empty>
|
||||
<RunTable v-else :rows="own" storage-key="workflow-runs" />
|
||||
</TabsContent>
|
||||
<TabsContent value="triggers" class="max-md:min-h-0 max-md:overflow-y-auto">
|
||||
<TriggerList :workflow="name" />
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
</div>
|
||||
<AlertDialog v-model:open="discarding">
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Discard the unpublished changes to {{ name }}?</AlertDialogTitle>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction variant="destructive" @click="discard">Discard</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,24 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { Copy, ListChecks, Play, Trash2 } from "@lucide/vue";
|
||||
import { Copy, ListChecks } from "@lucide/vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||
import { MoreMenu } from "@/components/ui/more-menu";
|
||||
|
||||
/** Run, and the overflow menu, for one workflow row. */
|
||||
defineProps<{ id: string; canRun: boolean; stored: boolean }>();
|
||||
const emit = defineEmits<{ run: []; runs: []; duplicate: []; remove: [] }>();
|
||||
/** The overflow menu for one workflow row. */
|
||||
defineProps<{ id: string }>();
|
||||
const emit = defineEmits<{ runs: []; duplicate: [] }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center gap-1" @click.stop @keydown.stop>
|
||||
<Button v-if="stored" type="button" size="sm" variant="outline" :disabled="!canRun" :aria-label="`Run ${id}`" :title="canRun ? undefined : 'Disabled'" @click="emit('run')">
|
||||
<Play data-icon="inline-start" />Run
|
||||
</Button>
|
||||
<div class="flex items-center justify-end gap-1" @click.stop @keydown.stop>
|
||||
<MoreMenu :label="`${id} actions`">
|
||||
<DropdownMenuItem v-if="stored" @select="emit('runs')"><ListChecks />Open runs</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="stored" @select="emit('duplicate')"><Copy />Duplicate</DropdownMenuItem>
|
||||
<DropdownMenuItem variant="destructive" @select="emit('remove')"><Trash2 />Delete</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="emit('runs')"><ListChecks />Open runs</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="emit('duplicate')"><Copy />Duplicate</DropdownMenuItem>
|
||||
</MoreMenu>
|
||||
</div>
|
||||
</template>
|
||||
@@ -2,104 +2,80 @@
|
||||
import { computed, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { useMediaQuery } from "@vueuse/core";
|
||||
import { Copy, ListChecks, Play, Plus, Search, Trash2 } from "@lucide/vue";
|
||||
import { Copy, ListChecks, Plus, Search } from "@lucide/vue";
|
||||
import { toast } from "vue-sonner";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from "@/components/ui/context-menu";
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { compact } from "@/lib/format";
|
||||
import { SEEDED_AGENT_ID } from "./workflow-edit";
|
||||
import { workflowRows, type WorkflowRow } from "./workflow-rows";
|
||||
import { byActivity, stepCount } from "./workflow-summary";
|
||||
import { triggerSummary, useTriggerSources } from "./workflow-triggers";
|
||||
import { useWorkflowStats } from "./use-workflow-stats";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { stateTone } from "@/runs/state";
|
||||
import { useWorkflowList, type WorkflowRow } from "./use-workflow-list";
|
||||
import WorkflowDelivery from "./WorkflowDelivery.vue";
|
||||
import WorkflowLastRun from "./WorkflowLastRun.vue";
|
||||
import WorkflowRowActions from "./WorkflowRowActions.vue";
|
||||
import WorkflowYaml from "./WorkflowYaml.vue";
|
||||
|
||||
const router = useRouter();
|
||||
const { store, data, error, loading, statsKnown, load, enabledOf, setEnabled, duplicate, remove } = useWorkflowStats();
|
||||
const { rows, error, partial, loading, reload, triggersKnown, runsKnown } = useWorkflowList();
|
||||
const wide = useMediaQuery("(min-width: 1024px)");
|
||||
|
||||
const startedByOf = (id: string) => data.value.definitions?.find((d) => d.id === id)?.started_by ?? [];
|
||||
const { triggersOf, error: triggersError, known: triggersKnown, reload: reloadTriggers } = useTriggerSources(startedByOf);
|
||||
|
||||
interface ListRow extends WorkflowRow {
|
||||
draft: boolean;
|
||||
stored: boolean;
|
||||
steps?: number;
|
||||
trigger: { text: string; more: string[] };
|
||||
}
|
||||
|
||||
// Stored definitions are the source of truth for the list; statistics join
|
||||
// them by id, and a workflow seen only in statistics still gets a row.
|
||||
const stored = computed(() => store.collection.definitions);
|
||||
const rows = computed<ListRow[]>(() => {
|
||||
const drafts = store.drafts.filter((draft) => !stored.value.some((d) => d.id === draft.id));
|
||||
const sources = [...stored.value, ...drafts];
|
||||
return workflowRows(
|
||||
data.value.workflows,
|
||||
sources.map((d) => ({ id: d.id, name: d.id, origin: data.value.definitions?.find((x) => x.id === d.id)?.origin })),
|
||||
)
|
||||
.sort(byActivity)
|
||||
.map((row) => ({
|
||||
...row,
|
||||
draft: store.drafts.some((draft) => draft.id === row.id),
|
||||
stored: stored.value.some((d) => d.id === row.id),
|
||||
steps: stepCount((stored.value.find((d) => d.id === row.id) ?? store.drafts.find((d) => d.id === row.id))?.yaml ?? ""),
|
||||
trigger: triggerSummary(triggersOf(row.id)),
|
||||
}));
|
||||
});
|
||||
|
||||
// A filter earns its place once the list outgrows a glance.
|
||||
const FILTER_FROM = 8;
|
||||
const query = ref("");
|
||||
const shown = computed(() => {
|
||||
const needle = query.value.trim().toLowerCase();
|
||||
return needle ? rows.value.filter((row) => row.id.toLowerCase().includes(needle) || row.trigger.text.toLowerCase().includes(needle)) : rows.value;
|
||||
return needle ? rows.value.filter((row) => row.name.toLowerCase().includes(needle) || row.starts.some((s) => s.toLowerCase().includes(needle))) : rows.value;
|
||||
});
|
||||
|
||||
const open = (id: string, query?: Record<string, string>) => void router.push({ name: "workflow-editor", params: { id }, query });
|
||||
const run = (id: string) => open(id, { run: "1" });
|
||||
const openRuns = (id: string) => open(id, { view: "runs" });
|
||||
const copy = (id: string) => void duplicate(id).then((next) => next && open(next));
|
||||
const canRun = (row: ListRow) => row.stored && enabledOf(row.id) !== false;
|
||||
const open = (name: string, query?: Record<string, string>) => void router.push({ path: `/workflows/${name}`, query });
|
||||
const openRuns = (name: string) => void router.push({ path: "/runs", query: { workflow: name } });
|
||||
const startsText = (row: WorkflowRow) => row.starts[0] ?? "";
|
||||
const startsMore = (row: WorkflowRow) => row.starts.slice(1);
|
||||
const lastTo = (row: WorkflowRow) => (row.last ? `/runs/${row.last.id}` : undefined);
|
||||
const stepsLabel = (row: WorkflowRow) => `${row.steps} ${row.steps === 1 ? "step" : "steps"}`;
|
||||
|
||||
const deleting = ref("");
|
||||
async function confirmRemove() {
|
||||
const id = deleting.value;
|
||||
deleting.value = "";
|
||||
await remove(id);
|
||||
async function copy(row: WorkflowRow): Promise<void> {
|
||||
const taken = new Set(rows.value.map((r) => r.name));
|
||||
let next = `${row.name}-copy`;
|
||||
for (let n = 2; taken.has(next); n++) next = `${row.name}-copy-${n}`;
|
||||
try {
|
||||
const source = await api.workflow(row.name);
|
||||
await api.putWorkflow(next, source.body);
|
||||
open(next);
|
||||
} catch (cause) {
|
||||
toast.error(describeError(cause, errors.common.unknown));
|
||||
}
|
||||
}
|
||||
|
||||
// A new workflow starts as a draft, so it is in the list straight away and
|
||||
// nothing runs it until Publish.
|
||||
async function create() {
|
||||
let n = 1;
|
||||
while (rows.value.some((row) => row.id === `workflow-${n}`)) n++;
|
||||
const id = `workflow-${n}`;
|
||||
if (await store.putDraft(id, `id: ${id}\nidentity: ${SEEDED_AGENT_ID}\nsteps: []\n`)) open(id);
|
||||
else toast.error(store.draftState.error || errors.workflows.editor.draftNotSaved);
|
||||
const creating = ref(false);
|
||||
const draft = ref({ name: "", body: "steps:\n - id: first\n type: agent.run\n settings:\n mission: |\n \n" });
|
||||
const busy = ref(false);
|
||||
const createError = ref("");
|
||||
async function create(): Promise<void> {
|
||||
busy.value = true;
|
||||
createError.value = "";
|
||||
const name = draft.value.name.trim();
|
||||
try {
|
||||
await api.putWorkflow(name, draft.value.body);
|
||||
creating.value = false;
|
||||
open(name);
|
||||
} catch (cause) {
|
||||
createError.value = describeError(cause, errors.common.unknown);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const reload = () => {
|
||||
void load();
|
||||
void store.load();
|
||||
void reloadTriggers();
|
||||
};
|
||||
const anyTokens = computed(() => shown.value.some((row) => row.avg_tokens));
|
||||
const tokens = (row: ListRow) => (row.avg_tokens ? compact(row.avg_tokens) : "–");
|
||||
const stepsLabel = (row: ListRow) => (row.steps === undefined ? "" : `${row.steps} ${row.steps === 1 ? "step" : "steps"}`);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -109,119 +85,112 @@ const stepsLabel = (row: ListRow) => (row.steps === undefined ? "" : `${row.step
|
||||
<InputGroupAddon><Search /></InputGroupAddon>
|
||||
<InputGroupInput v-model="query" type="search" aria-label="Filter workflows" placeholder="Filter" />
|
||||
</InputGroup>
|
||||
<Button size="icon-sm" variant="ghost" aria-label="New workflow" title="New workflow" @click="create"><Plus /></Button>
|
||||
<Button size="icon-sm" variant="ghost" aria-label="New workflow" title="New workflow" @click="creating = true"><Plus /></Button>
|
||||
</PageHeader>
|
||||
|
||||
<div v-if="error || store.error" class="mb-4 text-label text-danger" role="alert">
|
||||
<p>{{ error || store.error }}</p>
|
||||
<div v-if="error" class="mb-4 text-label text-danger" role="alert">
|
||||
<p>{{ error }}</p>
|
||||
<Button variant="outline" size="sm" @click="reload">Retry</Button>
|
||||
</div>
|
||||
<p v-if="loading || (!store.state.resource && !store.error)" class="flex items-center gap-2 text-label text-fg-muted"><Spinner />Loading workflows…</p>
|
||||
<p v-if="partial" class="mb-2 text-caption text-danger" role="alert">{{ partial }}</p>
|
||||
<p v-if="loading" class="flex items-center gap-2 text-label text-fg-muted"><Spinner />Loading workflows…</p>
|
||||
|
||||
<Empty v-else-if="!rows.length && !error">
|
||||
<EmptyHeader>
|
||||
<EmptyTitle>No workflows</EmptyTitle>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
<p v-else-if="!shown.length" class="text-label text-fg-muted">No workflow matches.</p>
|
||||
<p v-else-if="rows.length && !shown.length" class="text-label text-fg-muted">No workflow matches.</p>
|
||||
|
||||
<Table v-else-if="wide" class="table-fixed" aria-label="Workflows">
|
||||
<Table v-else-if="wide && shown.length" class="table-fixed" aria-label="Workflows">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead class="w-[22%]">Workflow</TableHead>
|
||||
<TableHead class="w-[22%]">Starts from</TableHead>
|
||||
<TableHead class="w-[24%]">Workflow</TableHead>
|
||||
<TableHead class="w-[24%]">Starts from</TableHead>
|
||||
<TableHead class="w-16">Steps</TableHead>
|
||||
<TableHead class="w-20">Enabled</TableHead>
|
||||
<TableHead class="w-[13%]">Last run</TableHead>
|
||||
<TableHead class="w-[13%]">Runs</TableHead>
|
||||
<TableHead v-if="anyTokens" class="w-24 text-right">Tokens</TableHead>
|
||||
<TableHead class="w-40"><span class="sr-only">Actions</span></TableHead>
|
||||
<TableHead class="w-[16%]">Last run</TableHead>
|
||||
<TableHead class="w-[16%]">Runs</TableHead>
|
||||
<TableHead class="w-40">Published</TableHead>
|
||||
<TableHead class="w-16"><span class="sr-only">Actions</span></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<ContextMenu v-for="row in shown" :key="row.id">
|
||||
<ContextMenu v-for="row in shown" :key="row.name">
|
||||
<ContextMenuTrigger as-child>
|
||||
<TableRow class="cursor-pointer align-middle" @click="open(row.id)">
|
||||
<TableRow class="cursor-pointer align-middle" @click="open(row.name)">
|
||||
<TableCell class="whitespace-normal">
|
||||
<span class="flex min-w-0 items-center gap-2">
|
||||
<RouterLink :to="{ name: 'workflow', params: { id: row.id } }" class="min-w-0 truncate font-medium hover:underline focus-visible:outline-2 focus-visible:outline-ring" @click.stop>{{ row.id }}</RouterLink>
|
||||
<Badge v-if="row.draft" variant="outline">Draft</Badge>
|
||||
<RouterLink :to="`/workflows/${row.name}`" class="min-w-0 truncate font-medium hover:underline focus-visible:outline-2 focus-visible:outline-ring" @click.stop>{{ row.name }}</RouterLink>
|
||||
<span class="shrink-0 text-caption text-fg-subtle">v{{ row.version }}</span>
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell class="whitespace-normal">
|
||||
<span v-if="row.trigger.text" class="flex min-w-0 items-center gap-1.5">
|
||||
<span class="truncate">{{ row.trigger.text }}</span>
|
||||
<Badge v-if="row.trigger.more.length" variant="secondary" :title="row.trigger.more.join('\n')">+{{ row.trigger.more.length }}</Badge>
|
||||
<span v-if="startsText(row)" class="flex min-w-0 items-center gap-1.5">
|
||||
<span class="truncate">{{ startsText(row) }}</span>
|
||||
<Badge v-if="startsMore(row).length" variant="secondary" :title="startsMore(row).join('\n')">+{{ startsMore(row).length }}</Badge>
|
||||
</span>
|
||||
<span v-else-if="triggersKnown && !triggersError" class="text-fg-subtle">Manual</span>
|
||||
<span v-else-if="triggersKnown" class="text-fg-subtle">Manual</span>
|
||||
</TableCell>
|
||||
<TableCell class="tabular-nums">{{ row.steps ?? "–" }}</TableCell>
|
||||
<TableCell>
|
||||
<Switch v-if="enabledOf(row.id) !== undefined" size="sm" :model-value="enabledOf(row.id)" :aria-label="`${row.id} enabled`" @click.stop @update:model-value="setEnabled(row.id, $event)" />
|
||||
<TableCell class="tabular-nums">{{ row.steps }}</TableCell>
|
||||
<TableCell><WorkflowLastRun :to="lastTo(row)" :state="row.last?.state" :tone="row.last && stateTone(row.last.state)" :at="row.last?.created_at" :running="row.running" :known="runsKnown" /></TableCell>
|
||||
<TableCell><WorkflowDelivery :counts="{ completed: row.succeeded }" :runs="row.runs" /><span v-if="!row.runs && runsKnown" class="text-caption text-fg-subtle">No runs</span></TableCell>
|
||||
<TableCell class="whitespace-normal">
|
||||
<span class="flex flex-col gap-0.5"><Timestamp :at="row.published" /><span v-if="row.by" class="truncate text-caption text-fg-muted">{{ row.by }}</span></span>
|
||||
</TableCell>
|
||||
<TableCell><WorkflowLastRun :run-id="row.last_run_id" :status="row.last_status" :at="row.last_run_at" :running="row.running" :known="statsKnown" /></TableCell>
|
||||
<TableCell><WorkflowDelivery :counts="row" :runs="row.runs" /><span v-if="!row.runs && statsKnown" class="text-caption text-fg-subtle">No runs</span></TableCell>
|
||||
<TableCell v-if="anyTokens" class="text-right font-mono tabular-nums" :title="row.avg_tokens ? `${row.avg_tokens.toLocaleString()} tokens per run on average` : undefined">{{ tokens(row) }}</TableCell>
|
||||
<TableCell class="text-right">
|
||||
<WorkflowRowActions :id="row.id" :can-run="canRun(row)" :stored="row.stored" @run="run(row.id)" @runs="openRuns(row.id)" @duplicate="copy(row.id)" @remove="deleting = row.id" />
|
||||
<WorkflowRowActions :id="row.name" @runs="openRuns(row.name)" @duplicate="copy(row)" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</ContextMenuTrigger>
|
||||
<ContextMenuContent class="min-w-40">
|
||||
<ContextMenuItem v-if="canRun(row)" @select="run(row.id)"><Play />Run</ContextMenuItem>
|
||||
<ContextMenuItem v-if="row.stored" @select="openRuns(row.id)"><ListChecks />Open runs</ContextMenuItem>
|
||||
<ContextMenuItem v-if="row.stored" @select="copy(row.id)"><Copy />Duplicate</ContextMenuItem>
|
||||
<ContextMenuItem variant="destructive" @select="deleting = row.id"><Trash2 />Delete</ContextMenuItem>
|
||||
<ContextMenuItem @select="openRuns(row.name)"><ListChecks />Open runs</ContextMenuItem>
|
||||
<ContextMenuItem @select="copy(row)"><Copy />Duplicate</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
<ul v-else class="flex flex-col gap-2" aria-label="Workflows">
|
||||
<li v-for="row in shown" :key="row.id">
|
||||
<ul v-else-if="shown.length" class="flex flex-col gap-2" aria-label="Workflows">
|
||||
<li v-for="row in shown" :key="row.name">
|
||||
<ContextMenu>
|
||||
<ContextMenuTrigger as-child>
|
||||
<Card class="cursor-pointer gap-2.5 px-4 py-3 transition-colors hover:bg-secondary/60" @click="open(row.id)">
|
||||
<Card class="cursor-pointer gap-2.5 px-4 py-3 transition-colors hover:bg-secondary/60" @click="open(row.name)">
|
||||
<div class="flex items-center gap-2">
|
||||
<RouterLink :to="{ name: 'workflow', params: { id: row.id } }" class="min-w-0 truncate text-label font-medium focus-visible:outline-2 focus-visible:outline-ring" @click.stop>{{ row.id }}</RouterLink>
|
||||
<Badge v-if="row.draft" variant="outline">Draft</Badge>
|
||||
<Switch v-if="enabledOf(row.id) !== undefined" size="sm" class="ml-auto" :model-value="enabledOf(row.id)" :aria-label="`${row.id} enabled`" @click.stop @update:model-value="setEnabled(row.id, $event)" />
|
||||
<WorkflowRowActions :id="row.id" :can-run="canRun(row)" :stored="row.stored" @click.stop @run="run(row.id)" @runs="openRuns(row.id)" @duplicate="copy(row.id)" @remove="deleting = row.id" />
|
||||
<RouterLink :to="`/workflows/${row.name}`" class="min-w-0 truncate text-label font-medium focus-visible:outline-2 focus-visible:outline-ring" @click.stop>{{ row.name }}</RouterLink>
|
||||
<span class="shrink-0 text-caption text-fg-subtle">v{{ row.version }}</span>
|
||||
<WorkflowRowActions :id="row.name" class="ml-auto" @runs="openRuns(row.name)" @duplicate="copy(row)" />
|
||||
</div>
|
||||
<p class="flex min-w-0 items-center gap-1.5 text-caption text-fg-muted">
|
||||
<span class="truncate">{{ row.trigger.text || (triggersKnown && !triggersError ? "Manual" : "") }}</span>
|
||||
<Badge v-if="row.trigger.more.length" variant="secondary" :title="row.trigger.more.join('\n')">+{{ row.trigger.more.length }}</Badge>
|
||||
<span v-if="stepsLabel(row)" class="ml-auto shrink-0">{{ stepsLabel(row) }}</span>
|
||||
<span class="truncate">{{ startsText(row) || (triggersKnown ? "Manual" : "") }}</span>
|
||||
<Badge v-if="startsMore(row).length" variant="secondary" :title="startsMore(row).join('\n')">+{{ startsMore(row).length }}</Badge>
|
||||
<span class="ml-auto shrink-0">{{ stepsLabel(row) }}</span>
|
||||
</p>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<WorkflowLastRun :run-id="row.last_run_id" :status="row.last_status" :at="row.last_run_at" :running="row.running" :known="statsKnown" />
|
||||
<WorkflowLastRun :to="lastTo(row)" :state="row.last?.state" :tone="row.last && stateTone(row.last.state)" :at="row.last?.created_at" :running="row.running" :known="runsKnown" />
|
||||
<div class="flex flex-col items-end gap-1 text-caption text-fg-muted">
|
||||
<WorkflowDelivery :counts="row" :runs="row.runs" />
|
||||
<span v-if="row.avg_tokens" class="font-mono">{{ tokens(row) }} tok</span>
|
||||
<WorkflowDelivery :counts="{ completed: row.succeeded }" :runs="row.runs" />
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</ContextMenuTrigger>
|
||||
<ContextMenuContent class="min-w-40">
|
||||
<ContextMenuItem v-if="canRun(row)" @select="run(row.id)"><Play />Run</ContextMenuItem>
|
||||
<ContextMenuItem v-if="row.stored" @select="openRuns(row.id)"><ListChecks />Open runs</ContextMenuItem>
|
||||
<ContextMenuItem v-if="row.stored" @select="copy(row.id)"><Copy />Duplicate</ContextMenuItem>
|
||||
<ContextMenuItem variant="destructive" @select="deleting = row.id"><Trash2 />Delete</ContextMenuItem>
|
||||
<ContextMenuItem @select="openRuns(row.name)"><ListChecks />Open runs</ContextMenuItem>
|
||||
<ContextMenuItem @select="copy(row)"><Copy />Duplicate</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<AlertDialog :open="!!deleting" @update:open="(value: boolean) => !value && (deleting = '')">
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete the {{ deleting }} workflow?</AlertDialogTitle>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction variant="destructive" @click="confirmRemove">Delete</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
<Dialog v-model:open="creating">
|
||||
<DialogContent class="sm:max-w-2xl">
|
||||
<DialogHeader><DialogTitle>New workflow</DialogTitle></DialogHeader>
|
||||
<form id="new-workflow" class="flex min-h-0 flex-col gap-3" @submit.prevent="create">
|
||||
<Input v-model="draft.name" aria-label="Name" placeholder="Name" pattern="[a-z0-9]+([.\-][a-z0-9]+)*" required />
|
||||
<WorkflowYaml v-model="draft.body" class="max-h-[60dvh]" />
|
||||
<p v-if="createError" role="alert" class="text-caption text-danger">{{ createError }}</p>
|
||||
</form>
|
||||
<DialogFooter><Button type="submit" form="new-workflow" :disabled="busy || !draft.name">Publish</Button></DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,80 @@
|
||||
import { computed, onMounted } from "vue";
|
||||
|
||||
import { api, type Run, type Trigger } from "@/lib/api";
|
||||
import { usePoll, useRead } from "@/lib/use-read";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
|
||||
export interface WorkflowRow {
|
||||
name: string;
|
||||
version: number;
|
||||
steps: number;
|
||||
published: string;
|
||||
by?: string;
|
||||
/** What starts it, one entry per distinct way. */
|
||||
starts: string[];
|
||||
runs: number;
|
||||
succeeded: number;
|
||||
running: number;
|
||||
last?: Run;
|
||||
}
|
||||
|
||||
const time = (at?: string) => (at ? Date.parse(at) : 0);
|
||||
|
||||
/** "24h0m0s" as the server prints a Go duration, "24h" as a person reads it. */
|
||||
function every(duration: string): string {
|
||||
return duration.replace(/(?<=\D)0s$/, "").replace(/(?<=\D)0m$/, "");
|
||||
}
|
||||
|
||||
/** How a trigger starts its workflow, in words. */
|
||||
export function startedBy(trigger: Trigger): string {
|
||||
return trigger.every ? `Every ${every(trigger.every)}` : `${trigger.source} ${trigger.event_type}`;
|
||||
}
|
||||
|
||||
/** Running workflows first, then by how recently they ran, then by name. */
|
||||
export function byActivity(a: WorkflowRow, b: WorkflowRow): number {
|
||||
const live = (b.running ? 1 : 0) - (a.running ? 1 : 0);
|
||||
if (live) return live;
|
||||
return time(b.last?.created_at) - time(a.last?.created_at) || a.name.localeCompare(b.name);
|
||||
}
|
||||
|
||||
/** The published workflows with what starts each and how its runs went. */
|
||||
export function useWorkflowList() {
|
||||
const workflows = useRead(() => api.workflowList());
|
||||
const triggers = useRead(() => api.triggers());
|
||||
const runs = useRead(() => api.runs());
|
||||
const reload = () => Promise.all([workflows.reload(), triggers.reload(), runs.reload()]).then(() => undefined);
|
||||
onMounted(reload);
|
||||
useLiveResource(null, () => void reload());
|
||||
usePoll(reload);
|
||||
|
||||
const rows = computed<WorkflowRow[]>(() =>
|
||||
(workflows.data.value ?? [])
|
||||
.map((w) => {
|
||||
const own = (runs.data.value ?? []).filter((r) => r.workflow === w.name);
|
||||
return {
|
||||
name: w.name,
|
||||
version: w.version,
|
||||
steps: w.steps?.length ?? 0,
|
||||
published: w.created_at,
|
||||
by: w.created_by,
|
||||
starts: [...new Set((triggers.data.value ?? []).filter((t) => t.workflow === w.name).map(startedBy))],
|
||||
runs: own.length,
|
||||
succeeded: own.filter((r) => r.state === "succeeded").length,
|
||||
running: own.filter((r) => r.state === "running").length,
|
||||
last: own.reduce<Run | undefined>((a, b) => (!a || time(b.created_at) > time(a.created_at) ? b : a), undefined),
|
||||
};
|
||||
})
|
||||
.sort(byActivity),
|
||||
);
|
||||
/** Triggers or runs that failed to load: rows show without them, beside this. */
|
||||
const partial = computed(() => triggers.error.value || runs.error.value);
|
||||
return {
|
||||
rows,
|
||||
error: workflows.error,
|
||||
partial,
|
||||
loading: computed(() => !workflows.data.value && !workflows.error.value),
|
||||
reload,
|
||||
triggersKnown: computed(() => !!triggers.data.value),
|
||||
runsKnown: computed(() => !!runs.data.value),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user