feat(ui): split Workflows into a list page and a workflow page

This commit is contained in:
sam committed 2026-11-14 22:49:36 +11:00
1 parent 5d620461fe
commit c7ce32df3e
16 files changed
+294 -225

No files matched your search

+1 -2
View File
@@ -12,8 +12,7 @@ module.exports = async ({ page, go, shot }) => {
agent = await response.json();
};
const openSettings = async () => {
await go('/workflows');
await page.getByRole('button', { name: /^implement/ }).click();
await go('/workflows/implement');
const runPicker = page.getByRole('combobox', { name: 'Run shown on the canvas' });
if (await runPicker.count()) { await runPicker.click(); await page.getByRole('option', { name: 'Definition', exact: true }).click(); }
await page.locator('.vue-flow__node').filter({ hasText: 'Workflow' }).first().click();
+1 -1
View File
@@ -10,7 +10,7 @@ module.exports=async({page,go,shot,tolerate})=>{
if(new URL(route.request().url()).searchParams.has('workflow')) await route.fulfill({status:200,contentType:'application/json',body:'unreadable response'});
else await route.continue();
});
await go('/workflows');
await go('/workflows/implement');
await page.getByRole('alert').filter({hasText:'Could not load recent runs'}).waitFor();
await page.getByRole('tab',{name:/^Runs/}).click();
assert.equal(await page.getByText('No runs yet',{exact:true}).count(),0);
+2 -2
View File
@@ -8,7 +8,7 @@ module.exports = async ({ page, go, shot, tolerate }) => {
tolerate(ABSENT);
await go('/');
assert.equal((await selectOrg(page, ORG.beta)).status(), 204);
await go('/workflows?workflow=feasibility');
await go('/workflows/feasibility');
const origin = new URL(page.url()).origin;
const headers = { 'X-Archie-CSRF': '1', Origin: origin };
const created = await page.request.post(`${origin}/api/bindings`, {
@@ -22,7 +22,7 @@ module.exports = async ({ page, go, shot, tolerate }) => {
assert.equal(created.status(), 201, `binding on the built-in schedule mapping refused: ${await created.text()}`);
const binding = await created.json();
assert.equal(binding.org_id, ORG.beta);
await go('/workflows?workflow=feasibility');
await go('/workflows/feasibility');
await page.getByText('Starts when').first().waitFor();
await shot('beta-trigger');
} finally {
+1 -1
View File
@@ -7,7 +7,7 @@ module.exports = async ({ page, go, shot }) => {
await go('/workflows');
assert.equal(await page.getByText('No workflows', { exact: true }).count(), 0, 'loading presented as empty');
await page.getByText('Loading workflows…', { exact: true }).waitFor({ state: 'hidden' });
await page.getByRole('button', { name: /^implement/ }).click();
await page.getByRole('link', { name: /^implement/ }).click();
assert.equal(await page.getByText(/workflow implement has no steps/).count(), 0, 'late definition left an empty canvas');
await page.locator('.vue-flow__node').filter({ hasText: 'Repository' }).first().waitFor();
await shot('loaded');
+3 -3
View File
@@ -29,7 +29,7 @@ module.exports = async ({ page, go, shot, settled }) => {
const definition = resource.resource.value.definitions.find(entry => entry.id === 'feasibility');
definition.yaml = definition.yaml.replace(/\bid: assess\b/, 'id: Write a Product Requirement Document').replaceAll('steps.assess.', 'steps.Write a Product Requirement Document.');
await page.route('**/api/control-plane/resources/workflow-definitions', route => route.fulfill({ json: resource }));
await go('/workflows?workflow=feasibility');
await go('/workflows/feasibility');
await page.getByRole('tab', { name: 'History', exact: true }).click();
const yaml = await page.getByLabel('Workflow YAML', { exact: true }).inputValue();
assert.ok(yaml.includes('id: write-a-product-requirement-document'));
@@ -71,7 +71,7 @@ module.exports = async ({ page, go, shot, settled }) => {
await page.route('**/api/tasks/999999/*?*', route => route.fulfill({ json: {} }));
await page.route('**/api/tasks/999999/debug', route => route.fulfill({ json: {} }));
await page.route('**/api/tasks/999999/attempts', route => route.fulfill({ json: { attempts: [{ attempt: 1, stages: [{ name: 'Write a Product Requirement Document', status: 'failed', error: 'Historical failure' }] }] } }));
await go('/workflows?workflow=feasibility');
await go('/workflows/feasibility');
const picker = page.getByRole('combobox', { name: 'Run shown on the canvas' });
await picker.waitFor();
assert.match(await picker.innerText(), /Run #999999/);
@@ -92,7 +92,7 @@ module.exports = async ({ page, go, shot, settled }) => {
await page.getByRole('option', { name: 'Definition', exact: true }).click();
assert.equal(await picker.innerText(), 'Definition');
await shot('definition-picker');
await go('/workflows?workflow=triage');
await go('/workflows/triage');
const runPicker = page.getByRole('combobox', { name: 'Run shown on the canvas' });
if (await runPicker.count()) { await runPicker.click(); await page.getByRole('option', { name: 'Definition', exact: true }).click(); }
await page.locator('.vue-flow').hover();
+22 -3
View File
@@ -6,8 +6,27 @@ const assert = require('node:assert/strict');
module.exports = async ({ page, go, shot, settled }) => {
await page.setViewportSize({ width: 390, height: 844 });
// The list is a page at phone width: rows open the workflow, and Enable or
// Disable is reachable from the row menu and from the workflow page.
await go('/workflows');
const row = page.getByRole('link', { name: /^implement/ });
await row.waitFor();
const listWidth = await page.evaluate(() => ({ scrollWidth: document.documentElement.scrollWidth, width: innerWidth }));
assert.equal(listWidth.scrollWidth, listWidth.width, 'workflow list scrolls horizontally');
await shot('list');
await page.getByRole('button', { name: 'implement actions' }).click();
await page.getByRole('menuitem', { name: /^(Enable|Disable)$/ }).waitFor();
await page.keyboard.press('Escape');
await row.click();
await page.waitForURL(/\/workflows\/implement$/);
await page.locator('.workflow-canvas').waitFor();
await page.getByRole('button', { name: 'More', exact: true }).click();
await page.getByRole('menuitem', { name: /^(Enable|Disable)$/ }).waitFor();
await page.keyboard.press('Escape');
await go('/workflows?workflow=implement');
assert.match(page.url(), /\/workflows\/implement$/, 'legacy ?workflow= link did not reach the workflow page');
for (const workflow of ['implement', 'feasibility']) {
await go(`/workflows?workflow=${workflow}`);
await go(`/workflows/${workflow}`);
const canvas = page.locator('.workflow-canvas');
await canvas.waitFor();
const dimensions = await page.evaluate(() => ({
@@ -55,7 +74,7 @@ module.exports = async ({ page, go, shot, settled }) => {
await page.keyboard.press('Escape');
}
// YAML must not make the page scroll at phone width.
await go('/workflows?workflow=feasibility');
await go('/workflows/feasibility');
await page.getByRole('tab', { name: 'History', exact: true }).click();
await settled();
const yamlPage = await page.evaluate(() => ({
@@ -76,7 +95,7 @@ module.exports = async ({ page, go, shot, settled }) => {
await page.route('**/api/tasks/999999/*?*', route => route.fulfill({ json: {} }));
await page.route('**/api/tasks/999999/debug', route => route.fulfill({ json: {} }));
await page.route('**/api/tasks/999999/attempts', route => route.fulfill({ json: { attempts: [{ attempt: 1, stages: [] }] } }));
await go('/workflows?workflow=feasibility');
await go('/workflows/feasibility');
const picker = page.getByRole('combobox', { name: 'Run shown on the canvas' });
await picker.waitFor();
assert.match(await picker.innerText(), /Run #999999/);
+1 -2
View File
@@ -1,7 +1,6 @@
const assert = require('node:assert/strict');
module.exports = async ({ page, go, shot }) => {
await go('/workflows');
await page.getByRole('button', {name:/^implement(?! actions)/}).click();
await go('/workflows/implement');
const runPicker = page.getByRole('combobox', { name: 'Run shown on the canvas' });
if (await runPicker.count()) { await runPicker.click(); await page.getByRole('option', { name: 'Definition', exact: true }).click(); }
await page.locator('.vue-flow__node').filter({hasText:'Prepare worktree'}).first().click();
+7 -3
View File
@@ -16,7 +16,7 @@ import SectionCrumb from "@/components/topbar/SectionCrumb.vue";
import Brand from "@/components/topbar/Brand.vue";
import Logo from "@/components/topbar/Logo.vue";
import ConnectionPill from "@/components/topbar/ConnectionPill.vue";
import { Breadcrumb, BreadcrumbItem, BreadcrumbList, BreadcrumbSeparator } from "@/components/ui/breadcrumb";
import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbSeparator } from "@/components/ui/breadcrumb";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Card } from "@/components/ui/card";
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar";
@@ -34,7 +34,7 @@ const accounts=useAccountsStore();
const session = useSessionStore();
const route = useRoute();
const router = useRouter();
const workflowsPage = computed(() => route.path === "/workflows");
const workflowsPage = computed(() => route.name === "workflow");
const hidden = computed(() => hiddenPaths(session.sections));
const main = ref<HTMLElement | null>(null);
const newTaskOpen = ref(false);
@@ -42,7 +42,7 @@ const newTaskOpen = ref(false);
// it, so a bookmark or a chat link must not land on a form whose saves the
// control plane refuses.
watch([() => route.path, hidden], () => {
if (hidden.value.includes(route.path)) void router.replace("/");
if (hidden.value.includes(typeof route.meta.navPath === "string" ? route.meta.navPath : route.path)) void router.replace("/");
});
watch(() => [route.path, accounts.instance], () => {
const scope = route.meta.org ? "Organisation" : route.meta.settings ? "Instance" : "";
@@ -108,6 +108,10 @@ watch(() => accounts.status?.user, (user) => {
<BreadcrumbItem><OrgCrumb /></BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem><SectionCrumb :hidden="hidden" /></BreadcrumbItem>
<template v-if="route.name === 'workflow'">
<BreadcrumbSeparator />
<BreadcrumbItem class="min-w-0"><BreadcrumbLink as-child><RouterLink to="/workflows" class="truncate">All workflows</RouterLink></BreadcrumbLink></BreadcrumbItem>
</template>
</BreadcrumbList>
</Breadcrumb>
<div class="ml-auto flex shrink-0 items-center gap-4 max-sm:gap-1">
+2 -2
View File
@@ -663,8 +663,8 @@ export const pageTag = computed(() => {
const label =
route.name === "task-detail"
? `Task #${route.params.id}`
: route.name === "workflows" && typeof route.query.workflow === "string"
? `Workflow ${route.query.workflow}`
: route.name === "workflow"
? `Workflow ${route.params.id}`
: typeof route.meta.label === "string"
? route.meta.label
: page;
@@ -133,7 +133,7 @@ onUnmounted(() => document.removeEventListener("keydown", onGlobalKeydown));
v-for="id in workflows"
:key="id"
:value="`workflow:${id}`"
@select="go(`/workflows?workflow=${encodeURIComponent(id)}`)"
@select="go(`/workflows/${encodeURIComponent(id)}`)"
>
{{ id }}
</CommandItem>
+13
View File
@@ -32,6 +32,7 @@ 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");
// internal/gateway/dashboard_tools.go mirrors this table.
//
@@ -73,12 +74,24 @@ const routes = [
path: "/workflows",
name: "workflows",
component: WorkflowsPage,
// Links written as /workflows?workflow=<id> open that workflow's page.
beforeEnter: (to: RouteLocationGeneric) => {
const { workflow, ...query } = to.query;
if (typeof workflow === "string" && workflow) return { name: "workflow", params: { id: workflow }, query, replace: true };
return true;
},
meta: {
label: "Workflows",
description: "Workflows and run history.",
section: "workflows",
},
},
{
path: "/workflows/:id",
name: "workflow",
component: WorkflowPage,
meta: { label: "Workflow", nav: false, navPath: "/workflows" },
},
{
path: "/settings/skills",
name: "skills",
+1 -1
View File
@@ -43,7 +43,7 @@ function open(trigger: WorkflowTrigger): void {
<Badge v-if="trigger.binding.status !== 'armed'" :variant="statusKind(trigger.binding.status)">{{ statusLabel(trigger.binding.status) }}</Badge>
<span v-if="trigger.detail" class="ml-auto truncate text-caption text-fg-subtle">{{ trigger.detail }}</span>
</Button>
<RouterLink v-else-if="trigger.kind === 'workflow' || trigger.kind === 'playbook'" :to="trigger.kind === 'workflow' ? { path: '/workflows', query: { workflow: trigger.label } } : { path: '/org/playbooks' }" class="flex items-center gap-2 px-3 py-2 hover:bg-secondary">
<RouterLink v-else-if="trigger.kind === 'workflow' || trigger.kind === 'playbook'" :to="trigger.kind === 'workflow' ? { name: 'workflow', params: { id: trigger.label } } : { path: '/org/playbooks' }" class="flex items-center gap-2 px-3 py-2 hover:bg-secondary">
<span class="truncate">{{ trigger.label }}</span><span class="ml-auto truncate text-caption text-fg-subtle">{{ trigger.detail }}</span>
</RouterLink>
<div v-else class="flex items-center gap-2 px-3 py-2">
+4 -3
View File
@@ -10,7 +10,7 @@ import {
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { computed, onBeforeUnmount, onMounted, ref, toRef, watch } from "vue";
import { CircleAlert, Copy, RotateCcw, Trash2 } from "@lucide/vue";
import { CircleAlert, Copy, Power, RotateCcw, Trash2 } from "@lucide/vue";
import { isSending, setTurnHooks } from "@/chat/state";
import { Button } from "@/components/ui/button";
@@ -66,9 +66,9 @@ const modelAliases = computed(() =>
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] }>();
const emit = defineEmits<{ duplicate: [id: string]; setEnabled: [value: boolean] }>();
// Stage statistics are read by the page with the rest of the workflow stats.
const props = defineProps<{ stageStats: StageStats[]; statsKnown: boolean; statsError: string; startedBy: { workflow: string; via: string }[] }>();
const props = defineProps<{ stageStats: StageStats[]; statsKnown: boolean; statsError: string; startedBy: { workflow: string; via: string }[]; enabled?: boolean }>();
const id = ref("");
const yaml = ref("");
const loadedYaml = ref("");
@@ -475,6 +475,7 @@ const runOptions = computed(() => [
<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="props.enabled !== undefined" @select="emit('setEnabled', !props.enabled)"><Power />{{ props.enabled ? "Disable" : "Enable" }}</DropdownMenuItem>
<DropdownMenuItem v-if="stored !== undefined" @select="emit('duplicate', selected)"><Copy />Duplicate</DropdownMenuItem>
<DropdownMenuItem variant="destructive" @select="confirmDelete = true"><Trash2 />Delete workflow</DropdownMenuItem>
</MoreMenu>
+102
View File
@@ -0,0 +1,102 @@
<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import { Badge } from "@/components/ui/badge";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { Spinner } from "@/components/ui/spinner";
import { Button } from "@/components/ui/button";
import ApplyStatusRows from "@/settings/ApplyStatusRows.vue";
import WorkflowEditor from "./WorkflowEditor.vue";
import { useWorkflowStats } from "./use-workflow-stats";
const route = useRoute();
const router = useRouter();
const { store, data, error, loading, statsKnown, load, enabledOf, setEnabled, duplicate } = useWorkflowStats();
// The path names the workflow; the editor renames or clears it by publishing
// 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", params: { id }, query: route.query }) : router.replace({ name: "workflows" })),
});
// ?view= opens a tab and ?run= opens the run dialog; a link carries them once.
const view = ref(["history", "runs"].includes(String(route.query.view)) ? String(route.query.view) : "canvas");
const runOpen = ref(route.query.run !== undefined);
onMounted(() => {
if (route.query.run !== undefined) void router.replace({ query: { ...route.query, run: undefined } });
});
const stored = computed(() => store.collection.definitions);
const known = computed(
() =>
stored.value.some((d) => d.id === selected.value) ||
store.drafts.some((d) => d.id === selected.value) ||
(data.value.workflows ?? []).some((w) => w.workflow === selected.value),
);
const enabled = computed(() => enabledOf(selected.value));
const draft = computed(() => store.drafts.some((d) => d.id === selected.value));
// Whether this workflow is still the one archie ships: "Edited" when it has
// been changed, "Custom" when archie ships nothing by that name.
const provenance = computed(() => {
const shippedYAML = store.shipped.definitions.find((d) => d.id === selected.value)?.yaml;
const storedYAML = stored.value.find((d) => d.id === selected.value)?.yaml;
if (storedYAML === undefined) return "";
if (shippedYAML === undefined) return "Custom";
return shippedYAML === storedYAML ? "" : "Edited";
});
const stages = computed(() => (data.value.stages ?? []).filter((s) => s.workflow === selected.value));
const startedBy = computed(() => data.value.definitions?.find((d) => d.id === selected.value)?.started_by ?? []);
async function copy(id: string) {
const next = await duplicate(id);
if (next) selected.value = next;
}
</script>
<template>
<div class="max-md:flex max-md:min-h-0 max-md:flex-1 max-md:flex-col">
<div v-if="error || store.error" class="mb-4 text-label text-danger" role="alert">
<p>{{ error || store.error }}</p>
<Button variant="outline" size="sm" @click="load(); store.load()">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 workflow…</p>
<Empty v-else-if="!known && !error">
<EmptyHeader>
<EmptyTitle>Workflow not found</EmptyTitle>
</EmptyHeader>
</Empty>
<!-- No card around the editor: the canvas draws its own frame. -->
<div v-else-if="known" 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">
<!-- The editor's toolbar carries the title from lg up; below it the title stands alone. -->
<header class="mb-2 flex shrink-0 items-center gap-2 lg:hidden">
<h1 class="min-w-0 flex-1 truncate text-title font-medium">{{ selected }}</h1>
<Badge v-if="draft" variant="outline" class="shrink-0">Draft</Badge>
<Badge v-if="enabled === false" variant="secondary" class="shrink-0">Disabled</Badge>
<Badge v-if="provenance" variant="outline" class="shrink-0">{{ provenance }}</Badge>
<ApplyStatusRows kind="workflow-definitions" compact />
</header>
<WorkflowEditor
v-model:selected="selected"
v-model:view="view"
v-model:run-open="runOpen"
:stage-stats="stages"
:started-by="startedBy"
:stats-known="statsKnown"
:stats-error="error ?? ''"
:enabled="enabled"
@duplicate="copy"
@set-enabled="setEnabled(selected, $event)"
>
<template #title>
<h1 class="min-w-0 truncate text-title font-medium">{{ selected }}</h1>
<Badge v-if="draft" variant="outline" class="shrink-0">Draft</Badge>
<Badge v-if="enabled === false" variant="secondary" class="shrink-0">Disabled</Badge>
<Badge v-if="provenance" variant="outline" class="shrink-0">{{ provenance }}</Badge>
<ApplyStatusRows kind="workflow-definitions" compact />
</template>
</WorkflowEditor>
</div>
</div>
</template>
+50 -201
View File
@@ -1,76 +1,29 @@
<script setup lang="ts">
import { toast } from "vue-sonner";
import { Spinner } from "@/components/ui/spinner";
import { computed, onMounted, ref, shallowRef, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import { computed } from "vue";
import { useRouter } from "vue-router";
import { Copy, ListChecks, Play, Plus, Power } from "@lucide/vue";
import { toast } from "vue-sonner";
import PageHeader from "@/base/PageHeader.vue";
import { Button } from "@/components/ui/button";
import {
Empty,
EmptyHeader,
EmptyTitle,
} from "@/components/ui/empty";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from "@/components/ui/context-menu";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { MoreMenu } from "@/components/ui/more-menu";
import { Progress } from "@/components/ui/progress";
import { Section } from "@/components/ui/section";
import { Spinner } from "@/components/ui/spinner";
import { StatusDot } from "@/components/ui/status-dot";
import { api, describeError } from "@/lib/api";
import { errors } from "@/copy/errors";
import { keepValue } from "@/lib/keep-unchanged";
import { delivered } from "@/lib/delivered";
import { compact } from "@/lib/format";
import { cn } from "@/lib/utils";
import { statusLabel } from "@/lib/task-meta";
import { upsertWorkflowDefinition, useWorkflowsStore } from "@/stores/workflows";
import { useLiveResource } from "@/stores/session";
import ApplyStatusRows from "@/settings/ApplyStatusRows.vue";
import type { StageStats } from "./WorkflowRuns.vue";
import WorkflowEditor from "./WorkflowEditor.vue";
import WorkflowPicker from "./WorkflowPicker.vue";
import { SEEDED_AGENT_ID, setWorkflowField } from "./workflow-edit";
import { workflowRows, type WorkflowDefinition, type WorkflowStats } from "./workflow-rows";
import { SEEDED_AGENT_ID } from "./workflow-edit";
import { workflowRows } from "./workflow-rows";
import { useWorkflowStats } from "./use-workflow-stats";
interface WorkflowsResponse {
definitions?: WorkflowDefinition[];
workflows?: WorkflowStats[];
stages?: StageStats[];
}
const store = useWorkflowsStore();
const data = shallowRef<WorkflowsResponse>({});
const error = ref<string | null>(null);
const loading = ref(true);
// Statistics are known once a read has returned them; until then, or after a
// failed read, a row says nothing about its runs rather than "Never run".
const statsKnown = ref(false);
// Live reloads and actions overlap; only the newest read may land.
let loadGeneration = 0;
async function load() {
const current = ++loadGeneration;
try {
// The sidebar's running count and last status come from the per-workflow
// statistics: a page of the newest tasks across every workflow would show
// nothing for a workflow whose runs are older than that page.
const response = (await api.workflows<WorkflowsResponse>()) ?? {};
if (current !== loadGeneration) return;
data.value = keepValue(data.value, response);
error.value = null;
statsKnown.value = true;
} catch (err) {
if (current === loadGeneration) error.value = describeError(err, errors.common.unknown);
} finally {
if (current === loadGeneration) loading.value = false;
}
}
useLiveResource("tasks", () => void load(), 5000);
onMounted(() => Promise.all([load(), store.load()]));
const router = useRouter();
const { store, data, error, loading, statsKnown, load, enabledOf, setEnabled, duplicate } = useWorkflowStats();
// 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.
@@ -85,73 +38,8 @@ const rows = computed(() =>
})),
),
);
// ?workflow= names the selection, so Jump to can open a workflow directly. It
// applies once the workflow is listed: selecting it before the definitions load
// would open an empty editor.
const route = useRoute();
const selected = ref("");
let applied = "";
watch(
[() => route.query.workflow, rows, selected],
([wanted]) => {
if (typeof wanted === "string" && wanted !== applied && rows.value.some((row) => row.id === wanted)) {
selected.value = applied = wanted;
} else if (!selected.value && rows.value.length) selected.value = rows.value[0]!.id;
},
{ immediate: true },
);
// The selection goes back into ?workflow= so the URL names it: a reload keeps
// it, and the chat's page context tells Archie which workflow is open.
watch(selected, (id) => {
if (!id || route.query.workflow === id) return;
// A workflow named in the URL but not listed yet is still coming; the
// stand-in selected meanwhile must not replace it.
const wanted = route.query.workflow;
if (typeof wanted === "string" && wanted !== applied && !rows.value.some((row) => row.id === wanted)) return;
applied = id;
void router.replace({ query: { ...route.query, workflow: id } });
});
// Whether this workflow is still the one archie ships: "Edited" when it has
// been changed, "Custom" when archie ships nothing by that name.
const provenance = computed(() => {
const shippedYAML = store.shipped.definitions.find((d) => d.id === selected.value)?.yaml;
const storedYAML = stored.value.find((d) => d.id === selected.value)?.yaml;
if (storedYAML === undefined) return "";
if (shippedYAML === undefined) return "Custom";
return shippedYAML === storedYAML ? "" : "Edited";
});
async function setEnabled(id: string, value: boolean) {
try {
await api.workflowEnabled(id, value);
toast.success(`${id} ${value ? "enabled" : "disabled"}`);
await load();
} catch (err) {
toast.error(value ? errors.workflows.page.notEnabled(id, describeError(err, errors.common.unknown)) : errors.workflows.page.notDisabled(id, describeError(err, errors.common.unknown)));
}
}
const enabledOf = (id: string) => data.value.definitions?.find((d) => d.id === id)?.enabled;
// The editor's tab, so a row can open straight onto its runs.
const view = ref("canvas");
const router = useRouter();
// A row's Run opens the editor's run dialog on that workflow.
const runOpen = ref(false);
function runWorkflow(id: string): void {
selected.value = id;
view.value = "canvas";
runOpen.value = true;
}
async function duplicate(id: string) {
const source = stored.value.find((d) => d.id === id);
if (!source) return;
let copy = `${id}-copy`;
for (let n = 2; stored.value.some((d) => d.id === copy); n++) copy = `${id}-copy-${n}`;
if (await store.save(upsertWorkflowDefinition(store.collection, { id: copy, yaml: setWorkflowField(source.yaml, "id", copy) }))) {
selected.value = copy;
toast.success(`${copy} created`);
} else toast.error(errors.workflows.page.notDuplicated(id, store.error || errors.workflows.page.saveFailed));
}
const open = (id: string, query?: Record<string, string>) => void router.push({ name: "workflow", params: { id }, query });
interface RowAction {
label: string;
@@ -159,37 +47,26 @@ interface RowAction {
run: () => void;
}
function rowActions(id: string): RowAction[] {
const saved = stored.value.some((d) => d.id === id);
const enabled = enabledOf(id);
const actions: RowAction[] = [];
if (enabled !== undefined) actions.push({ label: enabled ? "Disable" : "Enable", icon: Power, run: () => void setEnabled(id, !enabled) });
if (saved) {
if (stored.value.some((d) => d.id === id)) {
actions.push(
{ label: "Run", icon: Play, run: () => runWorkflow(id) },
{
label: "Open runs",
icon: ListChecks,
run: () => {
selected.value = id;
view.value = "runs";
},
},
{ label: "Duplicate", icon: Copy, run: () => void duplicate(id) },
{ label: "Run", icon: Play, run: () => open(id, { run: "1" }) },
{ label: "Open runs", icon: ListChecks, run: () => open(id, { view: "runs" }) },
{ label: "Duplicate", icon: Copy, run: () => void duplicate(id).then((copy) => copy && open(copy)) },
);
}
return actions;
}
const stages = computed(() => (data.value.stages ?? []).filter((s) => s.workflow === selected.value));
// 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;
const taken = (id: string) => rows.value.some((row) => row.id === id);
while (taken(`workflow-${n}`)) n++;
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`)) selected.value = id;
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);
}
// The share of a workflow's runs whose work is finished: merged, or ended
@@ -198,8 +75,8 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
</script>
<template>
<div class="max-md:flex max-md:min-h-0 max-md:flex-1 max-md:flex-col">
<PageHeader title="Workflows" class="shrink-0">
<div>
<PageHeader title="Workflows">
<Button size="icon-sm" variant="ghost" aria-label="New workflow" title="New workflow" @click="create"><Plus /></Button>
</PageHeader>
@@ -209,72 +86,44 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
</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>
<div class="grid items-start gap-6 lg:grid-cols-[24rem_minmax(0,1fr)] max-md:min-h-0 max-md:flex-1 max-md:grid-rows-[minmax(0,1fr)]">
<div class="hidden min-w-0 flex-col gap-1 lg:flex">
<ul class="hidden max-h-[calc(100dvh-10rem)] flex-col gap-0.5 overflow-y-auto lg:flex" aria-label="Workflows">
<li v-for="row in rows" :key="row.id" class="relative min-w-0">
<ContextMenu>
<Empty v-else-if="!rows.length && !error">
<EmptyHeader>
<EmptyTitle>No workflows</EmptyTitle>
</EmptyHeader>
</Empty>
<ul v-else class="flex max-w-3xl flex-col gap-0.5" aria-label="Workflows">
<li v-for="row in rows" :key="row.id" class="relative min-w-0">
<ContextMenu>
<ContextMenuTrigger as-child>
<button
type="button"
:aria-current="row.id === selected ? 'true' : undefined"
:class="cn('w-full rounded-md py-2.5 pr-10 pl-3 text-left transition-colors hover:bg-secondary', row.id === selected && 'bg-secondary')"
@click="selected = row.id"
>
<span class="flex items-baseline gap-2">
<span class="min-w-0 flex-1 truncate text-label" :class="row.id === selected && 'font-medium'">{{ row.id }}</span>
<Badge v-if="store.drafts.some((draft) => draft.id === row.id)" variant="outline">Draft</Badge>
<Badge v-if="enabledOf(row.id) === false" variant="secondary">Disabled</Badge>
<span v-if="row.avg_tokens" class="font-mono text-caption text-fg-subtle" :title="`${row.avg_tokens.toLocaleString()} tokens per run on average`">{{ compact(row.avg_tokens) }} tok</span>
</span>
<span class="mt-1.5 flex items-center gap-2 text-caption text-fg-subtle">
<span v-if="row.running" class="flex w-20 shrink-0 items-center gap-1.5 text-info">
<StatusDot tone="info" live />{{ row.running }} running
<RouterLink :to="{ name: 'workflow', params: { id: row.id } }" class="block w-full rounded-md py-2.5 pr-10 pl-3 text-left transition-colors hover:bg-secondary">
<span class="flex items-baseline gap-2">
<span class="min-w-0 flex-1 truncate text-label">{{ row.id }}</span>
<Badge v-if="store.drafts.some((draft) => draft.id === row.id)" variant="outline">Draft</Badge>
<Badge v-if="enabledOf(row.id) === false" variant="secondary">Disabled</Badge>
<span v-if="row.avg_tokens" class="font-mono text-caption text-fg-subtle" :title="`${row.avg_tokens.toLocaleString()} tokens per run on average`">{{ compact(row.avg_tokens) }} tok</span>
</span>
<span v-else-if="row.last_status" class="w-20 shrink-0 truncate" :title="`Latest run: ${statusLabel(row.last_status)}`">{{ statusLabel(row.last_status) }}</span>
<span v-else-if="statsKnown" class="shrink-0">Never run</span>
<Progress v-if="row.runs" :model-value="Math.round(rate(delivered(row), row.runs) * 100)" :aria-label="`${delivered(row)} of ${row.runs ?? 0} runs delivered`" class="h-1 flex-1" />
<span v-if="row.runs" class="w-16 shrink-0 text-right font-mono" aria-hidden="true">{{ delivered(row) }}/{{ row.runs }}</span>
</span>
</button>
<span class="mt-1.5 flex items-center gap-2 text-caption text-fg-subtle">
<span v-if="row.running" class="flex w-20 shrink-0 items-center gap-1.5 text-info">
<StatusDot tone="info" live />{{ row.running }} running
</span>
<span v-else-if="row.last_status" class="w-20 shrink-0 truncate" :title="`Latest run: ${statusLabel(row.last_status)}`">{{ statusLabel(row.last_status) }}</span>
<span v-else-if="statsKnown" class="shrink-0">Never run</span>
<Progress v-if="row.runs" :model-value="Math.round(rate(delivered(row), row.runs) * 100)" :aria-label="`${delivered(row)} of ${row.runs ?? 0} runs delivered`" class="h-1 flex-1" />
<span v-if="row.runs" class="w-16 shrink-0 text-right font-mono" aria-hidden="true">{{ delivered(row) }}/{{ row.runs }}</span>
</span>
</RouterLink>
</ContextMenuTrigger>
<ContextMenuContent v-if="rowActions(row.id).length" class="min-w-40">
<ContextMenuItem v-for="action in rowActions(row.id)" :key="action.label" @select="action.run"><component :is="action.icon" />{{ action.label }}</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
<!-- MoreMenu renders no element of its own, so the wrapper places it. -->
<div v-if="rowActions(row.id).length" class="absolute top-1.5 right-1.5">
</ContextMenu>
<!-- MoreMenu renders no element of its own, so the wrapper places it. -->
<div v-if="rowActions(row.id).length" class="absolute top-1.5 right-1.5">
<MoreMenu :label="`${row.id} actions`">
<DropdownMenuItem v-for="action in rowActions(row.id)" :key="action.label" @select="action.run"><component :is="action.icon" />{{ action.label }}</DropdownMenuItem>
</MoreMenu>
</div>
</li>
</ul>
</div>
<Section v-if="!selected && !loading && store.state.resource && !error" class="mb-0 min-w-0" role="region" aria-label="Workflow">
<Empty>
<EmptyHeader>
<EmptyTitle>No workflows</EmptyTitle>
</EmptyHeader>
</Empty>
</Section>
<!-- No card around the editor: the canvas draws its own frame. -->
<div v-else-if="selected && store.state.resource" 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">
<!-- Below lg the list is gone: this picks the workflow instead. -->
<header class="mb-2 flex shrink-0 items-center gap-2 lg:hidden">
<div class="min-w-0 flex-1"><WorkflowPicker class="w-full" :value="selected" :workflows="rows" label="Workflow" @pick="selected = $event" /></div>
<Badge v-if="provenance" variant="outline" class="shrink-0">{{ provenance }}</Badge>
<ApplyStatusRows kind="workflow-definitions" compact />
</header>
<WorkflowEditor v-model:selected="selected" v-model:view="view" v-model:run-open="runOpen" @duplicate="duplicate" :stage-stats="stages" :started-by="data.definitions?.find((d) => d.id === selected)?.started_by ?? []" :stats-known="statsKnown" :stats-error="error ?? ''">
<template #title>
<h2 class="min-w-0 truncate text-title font-medium">{{ selected }}</h2>
<Badge v-if="provenance" variant="outline" class="shrink-0">{{ provenance }}</Badge>
<ApplyStatusRows kind="workflow-definitions" compact />
</template>
</WorkflowEditor>
</div>
</div>
</div>
</li>
</ul>
</div>
</template>
+83
View File
@@ -0,0 +1,83 @@
import { onMounted, ref, shallowRef } from "vue";
import { toast } from "vue-sonner";
import { api, describeError } from "@/lib/api";
import { errors } from "@/copy/errors";
import { keepValue } from "@/lib/keep-unchanged";
import { upsertWorkflowDefinition, useWorkflowsStore } from "@/stores/workflows";
import { useLiveResource } from "@/stores/session";
import type { StageStats } from "./WorkflowRuns.vue";
import { setWorkflowField } from "./workflow-edit";
import type { WorkflowDefinition, WorkflowStats } from "./workflow-rows";
interface WorkflowsResponse {
definitions?: WorkflowDefinition[];
workflows?: WorkflowStats[];
stages?: StageStats[];
}
/**
* The workflow list and the workflow page read the same statistics and offer
* the same Enable/Disable and Duplicate, so both take them from here.
*/
export function useWorkflowStats() {
const store = useWorkflowsStore();
const data = shallowRef<WorkflowsResponse>({});
const error = ref<string | null>(null);
const loading = ref(true);
// Statistics are known once a read has returned them; until then, or after a
// failed read, a row says nothing about its runs rather than "Never run".
const statsKnown = ref(false);
// Live reloads and actions overlap; only the newest read may land.
let generation = 0;
async function load() {
const current = ++generation;
try {
// Running count and last status come from the per-workflow statistics: a
// page of the newest tasks would show nothing for a workflow whose runs
// are older than that page.
const response = (await api.workflows<WorkflowsResponse>()) ?? {};
if (current !== generation) return;
data.value = keepValue(data.value, response);
error.value = null;
statsKnown.value = true;
} catch (err) {
if (current === generation) error.value = describeError(err, errors.common.unknown);
} finally {
if (current === generation) loading.value = false;
}
}
useLiveResource("tasks", () => void load(), 5000);
onMounted(() => Promise.all([load(), store.load()]));
const enabledOf = (id: string) => data.value.definitions?.find((d) => d.id === id)?.enabled;
async function setEnabled(id: string, value: boolean) {
try {
await api.workflowEnabled(id, value);
toast.success(`${id} ${value ? "enabled" : "disabled"}`);
await load();
} catch (err) {
const reason = describeError(err, errors.common.unknown);
toast.error(value ? errors.workflows.page.notEnabled(id, reason) : errors.workflows.page.notDisabled(id, reason));
}
}
/** Saves a copy of a workflow and returns its id, or "" when it was not saved. */
async function duplicate(id: string): Promise<string> {
const stored = store.collection.definitions;
const source = stored.find((d) => d.id === id);
if (!source) return "";
let copy = `${id}-copy`;
for (let n = 2; stored.some((d) => d.id === copy); n++) copy = `${id}-copy-${n}`;
if (await store.save(upsertWorkflowDefinition(store.collection, { id: copy, yaml: setWorkflowField(source.yaml, "id", copy) }))) {
toast.success(`${copy} created`);
return copy;
}
toast.error(errors.workflows.page.notDuplicated(id, store.error || errors.workflows.page.saveFailed));
return "";
}
return { store, data, error, loading, statsKnown, load, enabledOf, setEnabled, duplicate };
}