feat(ui): step roles, numbers and run trace on workflow canvas

This commit is contained in:
sam committed 2026-10-10 10:37:47 +11:00
1 parent 91bfb0ee44
commit 8a2354447e
6 files changed
+117 -66

No files matched your search

+2 -2
View File
@@ -5,7 +5,7 @@ import { BaseEdge, EdgeLabelRenderer, getSmoothStepPath, type EdgeProps } from "
import AddStepMenu from "./AddStepMenu.vue";
import type { StepPath } from "./workflow-edit";
const props = defineProps<EdgeProps<{ insertAfter?: StepPath; types: string[]; editable: boolean; onInsert: (after: StepPath, type: string) => void }>>();
const props = defineProps<EdgeProps<{ trace?: string; insertAfter?: StepPath; types: string[]; editable: boolean; onInsert: (after: StepPath, type: string) => void }>>();
const path = computed(() =>
getSmoothStepPath({
@@ -21,7 +21,7 @@ const path = computed(() =>
</script>
<template>
<BaseEdge :id="id" :path="path[0]" class="workflow-flow-edge" />
<BaseEdge :id="id" :path="path[0]" :class="['workflow-flow-edge', data?.trace && `trace-${data.trace}`]" />
<EdgeLabelRenderer v-if="data?.editable && data.insertAfter !== undefined">
<div
class="workflow-insert absolute"
+8 -1
View File
@@ -21,6 +21,12 @@ const stateClass = computed(() => {
return STATE_CLASSES[props.data.run?.status ?? ""] ?? "border-border";
});
const ROLE_CLASSES: Record<string, string> = {
decision: "border-l-4 border-l-warn",
waiting: "border-l-4 border-l-info",
exit: "border-l-4 border-l-primary",
};
const TRIGGER_ICONS = { issue: CircleDot, event: Webhook, playbook: BookOpen, workflow: Workflow };
const STATE_LABELS: Record<string, string> = {
@@ -42,13 +48,14 @@ function duration(ms?: number): string {
<template>
<div
class="w-60 rounded-lg border bg-card px-3 py-2 text-left shadow-sm"
:class="[stateClass, data.selected && 'ring-2 ring-ring', 'cursor-pointer transition-colors hover:border-muted-foreground']"
:class="[stateClass, ROLE_CLASSES[data.role ?? ''], data.selected && 'ring-2 ring-ring', 'cursor-pointer transition-colors hover:border-muted-foreground']"
>
<Handle v-if="data.kind !== 'start'" type="target" :position="Position.Top" />
<Handle id="data-in" type="target" :position="Position.Right" class="!opacity-0" />
<div class="flex items-center gap-1.5">
<Play v-if="data.kind === 'start'" class="size-3.5 text-primary" aria-hidden="true" />
<component :is="stepIcon(data.type)" v-else class="size-3.5 shrink-0 text-muted-foreground" aria-hidden="true" />
<span v-if="data.step" class="font-mono text-[11px] text-fg-subtle">{{ data.step }}</span>
<span class="truncate text-sm font-medium" :title="data.title">{{ data.title }}</span>
<span v-if="data.branch" class="ml-auto flex items-center gap-0.5 text-[11px] text-fg-subtle">
<GitBranch class="size-3" aria-hidden="true" />{{ data.branch }}
+29 -1
View File
@@ -69,13 +69,16 @@ const nodes = computed(() =>
: node;
}),
);
// The run's trace: an edge lights once the run has reached its target, in the
// colour of how that step went, and moves while the step is running.
const runs = computed(() => new Map(graph.value.nodes.map((node) => [node.id, node.data.run?.status])));
const edges = computed(() =>
graph.value.edges.map(({ label, offset, insertAfter, ...edge }) =>
edge.kind === "flow"
? {
...edge,
type: "insert",
data: { insertAfter, types: typesAt(insertAfter), editable: editable.value, onInsert: (after: StepPath, type: string) => emit("insert", after, type) },
data: { trace: runs.value.get(edge.target), insertAfter, types: typesAt(insertAfter), editable: editable.value, onInsert: (after: StepPath, type: string) => emit("insert", after, type) },
}
: {
...edge,
@@ -202,6 +205,31 @@ const beforePath = computed(() => menuPath.value ? [...menuPath.value.slice(0, -
stroke: var(--color-muted-foreground);
stroke-width: 1.5;
}
.workflow-flow-edge.trace-ok path {
stroke: var(--color-ok);
}
.workflow-flow-edge.trace-failed path {
stroke: var(--color-danger);
}
.workflow-flow-edge.trace-interrupted path {
stroke: var(--color-warn);
}
.workflow-flow-edge.trace-running path {
stroke: var(--color-info);
stroke-dasharray: 6 4;
animation: edge-trace 0.8s linear infinite;
}
@keyframes edge-trace {
to {
stroke-dashoffset: -10;
}
}
@media (prefers-reduced-motion: reduce) {
.workflow-flow-edge.trace-running path,
.step-running {
animation: none;
}
}
.workflow-data-edge path {
stroke: var(--color-primary);
stroke-dasharray: 5 4;
+16
View File
@@ -10,6 +10,11 @@ import type { WorkflowTrigger } from "./workflow-triggers";
export interface StepNodeData {
kind: "start" | "step";
/** What the step means to the run: work, a gate that decides, a pause for a
* person, or an exit that ends or hands off the run. */
role?: StepRole;
/** The top-level step's position in run order, as shown on the node. */
step?: string;
/** The step's id, or its 1-based position when it has none. */
key: string;
title: string;
@@ -37,6 +42,15 @@ export interface StepNodeData {
insertAfter?: (string | number)[];
}
export type StepRole = "work" | "decision" | "waiting" | "exit";
function stepRole(type: string): StepRole {
if (type.startsWith("gate.")) return "decision";
if (type === "human.approve") return "waiting";
if (type === "workflow.finish" || type === "workflow.handoff") return "exit";
return "work";
}
/** One recorded run of a step, from the task's attempts view. */
export interface AgentRun {
id: number;
@@ -260,6 +274,8 @@ export function workflowGraph(source: string): WorkflowGraph {
key: stepID || key,
title: stepID || stepTitle(type),
type,
role: stepRole(type),
step: path?.length === 2 ? String(Number(path[1]) + 1).padStart(2, "0") : undefined,
detail: stepDetail(type, settings),
summary: stepSummary(settings),
when: typeof record.when === "string" ? record.when : undefined,