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
+1
-1
@@ -41,7 +41,7 @@ const orgSpecs: NavSpec[] = [
|
||||
},
|
||||
{
|
||||
label: "Automation",
|
||||
paths: ["/org/schedules", "/org/scheduling-policy", "/org/channels", "/org/playbooks", "/org/alerts"],
|
||||
paths: ["/org/schedules", "/org/scheduling-policy", "/org/issue-routing", "/org/channels", "/org/playbooks", "/org/alerts"],
|
||||
},
|
||||
{
|
||||
label: "Usage",
|
||||
|
||||
@@ -301,6 +301,12 @@ const routes = [
|
||||
component: SchedulingPolicyPage,
|
||||
meta: { section: "org_config", label: "Scheduling policy", navPath: "/org", description: "Work discovery and forge labels." },
|
||||
},
|
||||
{
|
||||
path: "issue-routing",
|
||||
name: "org-issue-routing",
|
||||
component: () => import("@/settings/IssueRoutingPage.vue"),
|
||||
meta: { section: "org_config", label: "Issue routing", navPath: "/org", description: "Which workflow an issue runs by its labels." },
|
||||
},
|
||||
{
|
||||
path: "alerts",
|
||||
name: "org-alerts",
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
<script setup lang="ts">
|
||||
import { ArrowDown, ArrowUp, Trash2 } from "@lucide/vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import OptionSelect from "@/components/OptionSelect.vue";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { useSettingsStore } from "@/stores/settings";
|
||||
import { useWorkflowsStore } from "@/stores/workflows";
|
||||
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
||||
import HistoryLink from "./HistoryLink.vue";
|
||||
import KindGate from "./KindGate.vue";
|
||||
|
||||
const KIND = "intake-routes";
|
||||
|
||||
interface IntakeRoutes {
|
||||
rules: { label: string; workflow: string }[];
|
||||
default: string;
|
||||
}
|
||||
|
||||
const store = useSettingsStore();
|
||||
const workflows = useWorkflowsStore();
|
||||
onMounted(store.load);
|
||||
|
||||
const form = computed(() => store.formFor(KIND));
|
||||
const routes = computed(() => store.draftValue(KIND) as IntakeRoutes | undefined);
|
||||
const rules = computed(() => routes.value?.rules ?? []);
|
||||
const error = computed(() => store.catalogError || store.pageErrorFor(KIND));
|
||||
const options = computed(() => workflows.collection.definitions.map(({ id }) => ({ value: id, label: id })));
|
||||
|
||||
const label = ref("");
|
||||
const workflow = ref("");
|
||||
const canAdd = computed(() => label.value.trim() !== "" && workflow.value !== "");
|
||||
|
||||
function edit(next: Partial<IntakeRoutes>) {
|
||||
if (routes.value) store.setDraftValue(KIND, { ...routes.value, ...next });
|
||||
}
|
||||
function add() {
|
||||
if (!canAdd.value) return;
|
||||
edit({ rules: [...rules.value, { label: label.value.trim(), workflow: workflow.value }] });
|
||||
label.value = "";
|
||||
}
|
||||
function remove(index: number) {
|
||||
edit({ rules: rules.value.filter((_, i) => i !== index) });
|
||||
}
|
||||
function move(index: number, by: -1 | 1) {
|
||||
const next = [...rules.value];
|
||||
const [rule] = next.splice(index, 1);
|
||||
next.splice(index + by, 0, rule!);
|
||||
edit({ rules: next });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Issue routing"><HistoryLink :kinds="[KIND]" /></PageHeader>
|
||||
<ApplyStatusRows :kind="KIND" class="mb-4" />
|
||||
<Alert v-if="error" variant="destructive" class="mb-4"><AlertDescription>{{ error }}</AlertDescription></Alert>
|
||||
|
||||
<KindGate v-if="!form" :kind="KIND" />
|
||||
<template v-else>
|
||||
<Section title="Rules">
|
||||
<form class="mb-4 flex flex-wrap items-center gap-2" @submit.prevent="add">
|
||||
<Input v-model="label" aria-label="Label" placeholder="Label" class="max-w-48 font-mono" />
|
||||
<OptionSelect v-model="workflow" :options="options" aria-label="Workflow" placeholder="Workflow" class="w-44" />
|
||||
<Button type="submit" :disabled="!canAdd">Add rule</Button>
|
||||
</form>
|
||||
<Empty v-if="!rules.length"><EmptyHeader><EmptyTitle>No rules</EmptyTitle></EmptyHeader></Empty>
|
||||
<ol v-else class="divide-y divide-border border-y border-border">
|
||||
<li v-for="(_, i) in rules" :key="i" class="flex flex-wrap items-center gap-2 py-2">
|
||||
<form.Field v-slot="{ field }" :name="`rules[${i}].label`">
|
||||
<Input
|
||||
:model-value="field.state.value"
|
||||
:aria-label="`Label of rule ${i + 1}`"
|
||||
class="max-w-48 font-mono"
|
||||
@blur="field.handleBlur"
|
||||
@update:model-value="field.handleChange"
|
||||
/>
|
||||
</form.Field>
|
||||
<form.Field v-slot="{ field }" :name="`rules[${i}].workflow`">
|
||||
<OptionSelect
|
||||
:model-value="field.state.value"
|
||||
:options="options"
|
||||
:aria-label="`Workflow of rule ${i + 1}`"
|
||||
class="w-44"
|
||||
@update:model-value="field.handleChange"
|
||||
/>
|
||||
</form.Field>
|
||||
<div class="ml-auto flex items-center">
|
||||
<Button variant="ghost" size="icon" :disabled="i === 0" :aria-label="`Move rule ${i + 1} up`" @click="move(i, -1)"><ArrowUp /></Button>
|
||||
<Button variant="ghost" size="icon" :disabled="i === rules.length - 1" :aria-label="`Move rule ${i + 1} down`" @click="move(i, 1)"><ArrowDown /></Button>
|
||||
<Button variant="ghost" size="icon" :aria-label="`Remove rule ${i + 1}`" @click="remove(i)"><Trash2 /></Button>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
</Section>
|
||||
|
||||
<Section title="Default">
|
||||
<SettingRow label="Default workflow" for="routing-default" class="border-t-0 py-0">
|
||||
<form.Field v-slot="{ field }" name="default">
|
||||
<OptionSelect
|
||||
id="routing-default"
|
||||
:model-value="field.state.value"
|
||||
:options="options"
|
||||
aria-label="Default workflow"
|
||||
class="w-44"
|
||||
@update:model-value="field.handleChange"
|
||||
/>
|
||||
</form.Field>
|
||||
</SettingRow>
|
||||
</Section>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -76,10 +76,6 @@ export const useWorkflowsStore = defineStore("workflows", () => {
|
||||
const stepTypes = computed(() =>
|
||||
parse<StepTypeInfo[]>(descriptor.value?.schema_json, (value) => value["x-step-types"], []),
|
||||
);
|
||||
/** Where issues are routed by label, served beside the step types. */
|
||||
const intakeRoutes = computed(() =>
|
||||
parse<Record<string, string>>(descriptor.value?.schema_json, (value) => value["x-intake-routes"], {}),
|
||||
);
|
||||
|
||||
/** Unpublished edits by workflow id; only a test run runs a draft. */
|
||||
const drafts = computed(
|
||||
@@ -102,7 +98,6 @@ export const useWorkflowsStore = defineStore("workflows", () => {
|
||||
collection,
|
||||
shipped,
|
||||
stepTypes,
|
||||
intakeRoutes,
|
||||
load: settings.load,
|
||||
save: (next: WorkflowDefinitionCollection) => settings.replace(KIND, next),
|
||||
};
|
||||
|
||||
@@ -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