feat(workflow): issue routing is a control-plane setting edited in the dashboard (#1959)
Label to workflow rules and a default workflow are the intake-routes resource: ordered, case-insensitive, first rule wins, seeded with bug to tdd, feature to feasibility, default triage. A write naming an undefined workflow or an empty label is refused. The daemon reads it through the workflow definitions client when pinning a task and at intake. The kind indirection only carried this routing, so it is removed: the per-kind NATS subjects (every consumer already bound archie.task.>) are one subject, the envelope and playbook triggers lose their kind, and x-intake-routes is dropped. The dashboard gets an Issue routing page under Automation; the trigger card reads the same setting.
This commit is contained in:
28 files changed
+395
-234
No files matched your search
@@ -4,7 +4,6 @@ import { parse } from "yaml";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { useSettingsStore } from "@/stores/settings";
|
||||
import { useWorkflowsStore } from "@/stores/workflows";
|
||||
import type { Binding } from "@/bindings/binding-draft";
|
||||
|
||||
/** One way a workflow gets started. */
|
||||
@@ -17,8 +16,8 @@ export interface WorkflowTrigger {
|
||||
}
|
||||
|
||||
export interface TriggerSources {
|
||||
/** Issue label kind to workflow, with "default" for an unlabelled issue. */
|
||||
routes: Record<string, string>;
|
||||
/** The issue routing setting. */
|
||||
routes: { rules: { label: string; workflow: string }[]; default: string };
|
||||
bindings: Binding[];
|
||||
playbooks: { id: string; yaml: string }[];
|
||||
/** The workflows that start this one, as the server works them out. */
|
||||
@@ -66,14 +65,10 @@ function parseQuietly(source: string): unknown {
|
||||
/** 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" }
|
||||
: { kind: "issue", label: `Issues labelled ${kind}` },
|
||||
);
|
||||
for (const rule of sources.routes.rules) {
|
||||
if (rule.workflow === id) triggers.push({ kind: "issue", label: `Issues labelled ${rule.label}` });
|
||||
}
|
||||
if (sources.routes.default === id) triggers.push({ kind: "issue", label: "Other issues" });
|
||||
for (const binding of sources.bindings) {
|
||||
if (binding.workflow !== id) continue;
|
||||
if (binding.matcher?.source === SCHEDULE_SOURCE) {
|
||||
@@ -90,7 +85,7 @@ export function triggersFor(id: string, sources: TriggerSources): WorkflowTrigge
|
||||
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(" · ") });
|
||||
triggers.push({ kind: "playbook", label: playbook.id, detail: labels });
|
||||
}
|
||||
for (const starter of sources.startedBy) {
|
||||
triggers.push({ kind: "workflow", label: starter.workflow, detail: STARTED_VIA[starter.via] ?? starter.via });
|
||||
@@ -99,13 +94,14 @@ export function triggersFor(id: string, sources: TriggerSources): WorkflowTrigge
|
||||
}
|
||||
|
||||
// The words for the server's start kinds.
|
||||
const ROUTES = "intake-routes";
|
||||
|
||||
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>, startedBy: Readonly<Ref<{ workflow: string; via: string }[]>>) {
|
||||
const store = useSettingsStore();
|
||||
const workflows = useWorkflowsStore();
|
||||
const bindings = ref<TriggerSources["bindings"]>([]);
|
||||
const schedules = ref<TriggerSources["schedules"]>([]);
|
||||
// A failed read is an error, not an empty trigger list: "Manual runs only"
|
||||
@@ -119,6 +115,7 @@ export function useWorkflowTriggers(id: Ref<string>, startedBy: Readonly<Ref<{ w
|
||||
// Playbook triggers come from that resource; it is read here rather
|
||||
// than trusting another page to have loaded it.
|
||||
store.stateFor("eda-playbooks").resource ? null : store.loadResource("eda-playbooks").catch(() => null),
|
||||
store.stateFor(ROUTES).resource ? null : store.loadResource(ROUTES).catch(() => null),
|
||||
]);
|
||||
// A failed read keeps what was shown, beside the error.
|
||||
if (response) bindings.value = response.bindings ?? [];
|
||||
@@ -128,7 +125,7 @@ export function useWorkflowTriggers(id: Ref<string>, startedBy: Readonly<Ref<{ w
|
||||
onMounted(reload);
|
||||
const triggers = computed(() =>
|
||||
triggersFor(id.value, {
|
||||
routes: workflows.intakeRoutes,
|
||||
routes: (store.stateFor(ROUTES).resource?.value as TriggerSources["routes"] | undefined) ?? { rules: [], default: "" },
|
||||
bindings: bindings.value,
|
||||
playbooks: (store.stateFor("eda-playbooks").resource?.value as { playbooks?: TriggerSources["playbooks"] } | undefined)?.playbooks ?? [],
|
||||
startedBy: startedBy.value,
|
||||
|
||||
Reference in new issue
Block a user