feat(workflow): serve which workflows start each one; the trigger card stops re-deriving it (#1960)

This commit is contained in:
sam committed 2026-11-13 18:01:33 +11:00
1 parent fb330f350d
commit 841c6aea16
7 files changed
+122 -48

No files matched your search

+3 -3
View File
@@ -9,7 +9,7 @@ import {
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue";
import { computed, nextTick, onBeforeUnmount, onMounted, ref, toRef, watch } from "vue";
import { CircleAlert, Copy, RotateCcw, Trash2 } from "@lucide/vue";
import { isSending, setTurnHooks } from "@/chat/state";
@@ -71,7 +71,7 @@ const collection = computed(() => workflows.collection);
const selected = defineModel<string>("selected", { required: true });
const emit = defineEmits<{ duplicate: [id: string] }>();
// Stage statistics are read by the page with the rest of the workflow stats.
defineProps<{ stageStats: StageStats[]; statsKnown: boolean; statsError: string }>();
const props = defineProps<{ stageStats: StageStats[]; statsKnown: boolean; statsError: string; startedBy: { workflow: string; via: string }[] }>();
const id = ref("");
const yaml = ref("");
const loadedYaml = ref("");
@@ -117,7 +117,7 @@ async function restartFrom(from: string): Promise<void> {
restarting.value = false;
}
}
const { triggers, reload: reloadTriggers, error: triggersError } = useWorkflowTriggers(selected);
const { triggers, reload: reloadTriggers, error: triggersError } = useWorkflowTriggers(selected, toRef(() => props.startedBy));
const { revisions, error: historyError, loaded: historyLoaded, reload: reloadHistory } = useWorkflowHistory(selected);
const historyRevision = ref(0);
+1 -1
View File
@@ -267,7 +267,7 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
<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" :stats-known="statsKnown" :stats-error="error ?? ''">
<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>
+2
View File
@@ -31,6 +31,8 @@ export interface WorkflowDefinition {
inputs?: Record<string, { type: string; required?: boolean }>;
/** none, optional or required; a workflow that declares none needs a repository. */
repository?: string;
/** The other workflows whose steps start this one, and how. */
started_by?: { workflow: string; via: string }[];
}
/** One table row: a definition, its statistics, or both. */
+8 -43
View File
@@ -3,7 +3,6 @@ import { parse } from "yaml";
import { api, describeError } from "@/lib/api";
import { errors } from "@/copy/errors";
import { branchingOf } from "./workflow-edit.ts";
import { useSettingsStore } from "@/stores/settings";
import { useWorkflowsStore } from "@/stores/workflows";
import type { Binding } from "@/bindings/binding-draft";
@@ -22,7 +21,8 @@ export interface TriggerSources {
routes: Record<string, string>;
bindings: Binding[];
playbooks: { id: string; yaml: string }[];
definitions: { id: string; yaml: string }[];
/** The workflows that start this one, as the server works them out. */
startedBy: { workflow: string; via: string }[];
/** Schedules by id, to name schedule triggers. */
schedules: { id: string; name: string }[];
}
@@ -92,53 +92,18 @@ export function triggersFor(id: string, sources: TriggerSources): WorkflowTrigge
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 });
for (const starter of sources.startedBy) {
triggers.push({ kind: "workflow", label: starter.workflow, detail: STARTED_VIA[starter.via] ?? starter.via });
}
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) =>
branchingOf(step)?.branches.flatMap(([, branch]) => branch) ?? [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 "workflow.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 words for the server's start kinds.
const STARTED_VIA: Record<string, string> = { call: "calls it", handoff: "hands off to it", approve: "runs it once approved" };
/** 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>) {
export function useWorkflowTriggers(id: Ref<string>, startedBy: Readonly<Ref<{ workflow: string; via: string }[]>>) {
const store = useSettingsStore();
const workflows = useWorkflowsStore();
const bindings = ref<TriggerSources["bindings"]>([]);
@@ -166,7 +131,7 @@ export function useWorkflowTriggers(id: Ref<string>) {
routes: workflows.intakeRoutes,
bindings: bindings.value,
playbooks: (store.stateFor("eda-playbooks").resource?.value as { playbooks?: TriggerSources["playbooks"] } | undefined)?.playbooks ?? [],
definitions: workflows.collection.definitions,
startedBy: startedBy.value,
schedules: schedules.value,
}),
);