feat(ui): the canvas Start node lists what starts the workflow: issue routes, event bindings, playbooks and other workflows
This commit is contained in:
1 parent
53934b942c
commit
b9720eada8
9 files changed
+249
-82
No files matched your search
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { Handle, Position } from "@vue-flow/core";
|
||||
import { Flag, GitBranch, Play, Repeat, SkipForward } from "@lucide/vue";
|
||||
import { Flag, GitBranch, Play, Repeat, SkipForward, Webhook, CircleDot, BookOpen, Workflow } from "@lucide/vue";
|
||||
|
||||
import type { StepNodeData } from "./workflow-graph";
|
||||
|
||||
@@ -19,6 +19,8 @@ const stateClass = computed(() => {
|
||||
return STATE_CLASSES[props.data.run?.status ?? ""] ?? "border-border";
|
||||
});
|
||||
|
||||
const TRIGGER_ICONS = { issue: CircleDot, event: Webhook, playbook: BookOpen, workflow: Workflow };
|
||||
|
||||
const STATE_LABELS: Record<string, string> = {
|
||||
ok: "Done",
|
||||
failed: "Failed",
|
||||
@@ -49,7 +51,15 @@ function duration(ms?: number): string {
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="data.type && data.type !== data.title" class="truncate font-mono text-[11px] text-fg-subtle">{{ data.type }}</div>
|
||||
<div v-if="data.detail" class="mt-0.5 truncate text-xs text-muted-foreground" :title="data.detail">{{ data.detail }}</div>
|
||||
<ul v-if="data.kind === 'start' && data.triggers?.length" class="mt-1 space-y-0.5">
|
||||
<li v-for="trigger in data.triggers" :key="trigger.kind + trigger.label" class="flex items-center gap-1.5 text-xs" :title="trigger.detail">
|
||||
<component :is="TRIGGER_ICONS[trigger.kind]" class="size-3 shrink-0 text-primary" aria-hidden="true" />
|
||||
<span class="truncate">{{ trigger.label }}</span>
|
||||
<span v-if="trigger.detail" class="truncate text-fg-subtle">{{ trigger.detail }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
<div v-else-if="data.kind === 'start'" class="mt-0.5 text-xs text-muted-foreground">Nothing starts it yet; run it by hand or bind an event to it.</div>
|
||||
<div v-else-if="data.detail" class="mt-0.5 truncate text-xs text-muted-foreground" :title="data.detail">{{ data.detail }}</div>
|
||||
<div v-if="data.when || data.retry || data.continues" class="mt-1 flex flex-wrap gap-1 text-[11px]">
|
||||
<span v-if="data.when" class="flex max-w-full min-w-0 items-center gap-0.5 rounded bg-secondary px-1 font-mono" :title="`Runs only when ${data.when}`">
|
||||
<Flag class="size-3 shrink-0" aria-hidden="true" /><span class="truncate">{{ data.when }}</span>
|
||||
|
||||
@@ -8,8 +8,14 @@ import "@vue-flow/controls/dist/style.css";
|
||||
|
||||
import StepNode from "./StepNode.vue";
|
||||
import { withRuns, workflowGraph, type StageRun } from "./workflow-graph";
|
||||
import type { WorkflowTrigger } from "./workflow-triggers";
|
||||
|
||||
const props = defineProps<{ yaml: string; stages?: StageRun[]; selected?: (string | number)[] | null }>();
|
||||
const props = defineProps<{
|
||||
yaml: string;
|
||||
stages?: StageRun[];
|
||||
selected?: (string | number)[] | null;
|
||||
triggers?: WorkflowTrigger[];
|
||||
}>();
|
||||
const emit = defineEmits<{ select: [(string | number)[] | null] }>();
|
||||
|
||||
const NODE_WIDTH = 240;
|
||||
@@ -18,11 +24,15 @@ const container = ref<HTMLElement | null>(null);
|
||||
const graph = computed(() => withRuns(workflowGraph(props.yaml), props.stages ?? []));
|
||||
const selectedKey = computed(() => JSON.stringify(props.selected ?? null));
|
||||
const nodes = computed(() =>
|
||||
graph.value.nodes.map((node) =>
|
||||
JSON.stringify(node.data.path ?? null) === selectedKey.value && props.selected
|
||||
graph.value.nodes.map((node) => {
|
||||
if (node.data.kind === "start") return { ...node, data: { ...node.data, triggers: props.triggers ?? [] } };
|
||||
// Each trigger past the second makes the start node a line taller.
|
||||
const drop = Math.max(0, (props.triggers?.length ?? 0) - 2) * 18;
|
||||
if (drop) node = { ...node, position: { ...node.position, y: node.position.y + drop } };
|
||||
return JSON.stringify(node.data.path ?? null) === selectedKey.value && props.selected
|
||||
? { ...node, data: { ...node.data, selected: true } }
|
||||
: node,
|
||||
),
|
||||
: node;
|
||||
}),
|
||||
);
|
||||
const edges = computed(() =>
|
||||
graph.value.edges.map(({ label, offset, ...edge }) => ({
|
||||
|
||||
@@ -12,6 +12,7 @@ import StepPanel from "./StepPanel.vue";
|
||||
import WorkflowCanvas from "./WorkflowCanvas.vue";
|
||||
import type { StepPath } from "./workflow-edit";
|
||||
import { useWorkflowRuns } from "./workflow-runs";
|
||||
import { useWorkflowTriggers } from "./workflow-triggers";
|
||||
import {
|
||||
cloneControlPlaneValue,
|
||||
removeWorkflowDefinition,
|
||||
@@ -44,6 +45,7 @@ const selectedStep = ref<StepPath | null>(null);
|
||||
const localError = ref("");
|
||||
|
||||
const { runs, watched, stages, pick } = useWorkflowRuns(selected);
|
||||
const triggers = useWorkflowTriggers(selected);
|
||||
|
||||
const shippedEntry = computed(() =>
|
||||
shipped.value.definitions.find((entry) => entry.id === id.value),
|
||||
@@ -162,7 +164,7 @@ function syncScroll(event: Event): void {
|
||||
<span v-if="!runs.length" class="text-xs text-fg-subtle">This workflow has not run yet.</span>
|
||||
</label>
|
||||
<div class="grid gap-3 lg:grid-cols-[1fr_20rem]">
|
||||
<WorkflowCanvas :yaml="yaml" :stages="stages" :selected="selectedStep" @select="selectedStep = $event" />
|
||||
<WorkflowCanvas :yaml="yaml" :stages="stages" :selected="selectedStep" :triggers="triggers" @select="selectedStep = $event" />
|
||||
<StepPanel v-model:yaml="yaml" :path="selectedStep" :vocabulary="vocabulary" @select="selectedStep = $event" />
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { parseDocument } from "yaml";
|
||||
|
||||
import type { WorkflowTrigger } from "./workflow-triggers";
|
||||
|
||||
/**
|
||||
* A workflow definition laid out as a graph: a start node, each step as a
|
||||
* node in run order, parallel branches side by side, and a dashed edge from
|
||||
@@ -25,6 +27,7 @@ export interface StepNodeData {
|
||||
/** Where the step lives in the YAML document, for editing it. */
|
||||
path?: (string | number)[];
|
||||
selected?: boolean;
|
||||
triggers?: WorkflowTrigger[];
|
||||
}
|
||||
|
||||
/** One recorded run of a step, from the task's attempts view. */
|
||||
@@ -152,7 +155,7 @@ export function workflowGraph(source: string): WorkflowGraph {
|
||||
id: start,
|
||||
type: "step",
|
||||
position: { x: 0, y: 0 },
|
||||
data: { kind: "start", key: "start", title: "Start", type: "", detail: "an event or a task starts the run" },
|
||||
data: { kind: "start", key: "start", title: "Starts when", type: "", detail: "" },
|
||||
});
|
||||
|
||||
let previous = [start];
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import { computed, onMounted, ref, type Ref } from "vue";
|
||||
import { parse } from "yaml";
|
||||
|
||||
import { api } from "@/lib/api";
|
||||
import { useControlPlaneStore } from "@/stores/control-plane";
|
||||
|
||||
/** One way a workflow gets started. */
|
||||
export interface WorkflowTrigger {
|
||||
kind: "issue" | "event" | "playbook" | "workflow";
|
||||
label: string;
|
||||
detail?: string;
|
||||
}
|
||||
|
||||
export interface TriggerSources {
|
||||
/** Issue label kind to workflow, with "default" for an unlabelled issue. */
|
||||
routes: Record<string, string>;
|
||||
bindings: { name?: string; workflow?: string; matcher?: { source?: string } }[];
|
||||
playbooks: { id: string; yaml: string }[];
|
||||
definitions: { id: string; yaml: string }[];
|
||||
}
|
||||
|
||||
type Mapping = Record<string, unknown>;
|
||||
|
||||
function isMapping(value: unknown): value is Mapping {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function parseQuietly(source: string): unknown {
|
||||
try {
|
||||
return parse(source);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Everything that starts the workflow named id. */
|
||||
export function triggersFor(id: string, sources: TriggerSources): WorkflowTrigger[] {
|
||||
const triggers: WorkflowTrigger[] = [];
|
||||
for (const [kind, workflow] of Object.entries(sources.routes)) {
|
||||
if (workflow !== id) continue;
|
||||
triggers.push(
|
||||
kind === "default"
|
||||
? { kind: "issue", label: "Unlabelled issues", detail: "anything no label routes elsewhere" }
|
||||
: { kind: "issue", label: `Issues labelled ${kind}` },
|
||||
);
|
||||
}
|
||||
for (const binding of sources.bindings) {
|
||||
if (binding.workflow !== id) continue;
|
||||
triggers.push({ kind: "event", label: binding.name || "Event binding", detail: binding.matcher?.source });
|
||||
}
|
||||
for (const playbook of sources.playbooks) {
|
||||
const value = parseQuietly(playbook.yaml);
|
||||
if (!isMapping(value) || !Array.isArray(value.actions)) continue;
|
||||
if (!value.actions.some((action) => isMapping(action) && action.workflow === id)) continue;
|
||||
const trigger = isMapping(value.trigger) ? value.trigger : {};
|
||||
const labels = Array.isArray(trigger.labels) ? trigger.labels.join(", ") : "";
|
||||
triggers.push({ kind: "playbook", label: playbook.id, detail: [trigger.kind, labels].filter(Boolean).join(" · ") });
|
||||
}
|
||||
for (const definition of sources.definitions) {
|
||||
if (definition.id === id) continue;
|
||||
const how = startsVia(parseQuietly(definition.yaml), id);
|
||||
if (how) triggers.push({ kind: "workflow", label: definition.id, detail: how });
|
||||
}
|
||||
return triggers;
|
||||
}
|
||||
|
||||
/** How a workflow's steps start the target: a call, a handoff (including one
|
||||
* whose target an earlier agent picks from a fixed list), or an approval. */
|
||||
function startsVia(value: unknown, target: string): string {
|
||||
const steps = isMapping(value) && Array.isArray(value.steps) ? value.steps : [];
|
||||
const all = steps.flatMap((step) =>
|
||||
isMapping(step) && isMapping(step.parallel) ? Object.values(step.parallel).flat() : [step],
|
||||
);
|
||||
for (const step of all) {
|
||||
if (!isMapping(step) || !isMapping(step.settings)) continue;
|
||||
const settings = step.settings;
|
||||
switch (step.type) {
|
||||
case "workflow.call":
|
||||
if (settings.workflow === target) return "calls it";
|
||||
break;
|
||||
case "workflow.handoff":
|
||||
if (settings.workflow === target || resultChoices(all, settings.workflow).includes(target)) return "hands off to it";
|
||||
break;
|
||||
case "human.approve":
|
||||
if (settings.then === target) return "runs it once approved";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/** The fixed choices an agent's result field allows, for a reference like
|
||||
* {{ steps.classify.result.workflow }}. */
|
||||
function resultChoices(steps: unknown[], reference: unknown): string[] {
|
||||
const match = typeof reference === "string" ? /\{\{\s*steps\.([\w-]+)\.result\.([\w-]+)\s*\}\}/.exec(reference) : null;
|
||||
if (!match) return [];
|
||||
const source = steps.find((step) => isMapping(step) && step.id === match[1]);
|
||||
const result = isMapping(source) && isMapping(source.settings) ? source.settings.result : undefined;
|
||||
const field = isMapping(result) && isMapping(result.properties) ? result.properties[match[2]] : undefined;
|
||||
return isMapping(field) && Array.isArray(field.enum) ? field.enum.map(String) : [];
|
||||
}
|
||||
|
||||
/** The triggers of the workflow named id, from the routes and definitions the
|
||||
* control plane serves, the stored playbooks, and the event bindings. */
|
||||
export function useWorkflowTriggers(id: Ref<string>) {
|
||||
const store = useControlPlaneStore();
|
||||
const bindings = ref<TriggerSources["bindings"]>([]);
|
||||
onMounted(async () => {
|
||||
const response = await api.bindings<{ bindings?: TriggerSources["bindings"] }>().catch(() => null);
|
||||
bindings.value = response?.bindings ?? [];
|
||||
});
|
||||
return computed(() =>
|
||||
triggersFor(id.value, {
|
||||
routes: store.intakeRoutes(),
|
||||
bindings: bindings.value,
|
||||
playbooks: (store.stateFor("eda-playbooks").resource?.value as { playbooks?: TriggerSources["playbooks"] } | undefined)?.playbooks ?? [],
|
||||
definitions: (store.stateFor("workflow-definitions").resource?.value as { definitions?: TriggerSources["definitions"] } | undefined)?.definitions ?? [],
|
||||
}),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user