* fix(ui/topbar): replace Jump to with a command palette, drop filler chrome Jump to opens a shadcn-vue Command dialog that finds pages, tasks and workflows by name. The connection indicator shows only when the stream is lost, the dead documentation link is gone, and the profile menu label has no stray whitespace. * fix(ui): trim stray whitespace from template text and drop em dashes from copy Element text that started or ended with a line break rendered with leading and trailing spaces. Also removes the unused 'soon' nav state and the nav group components no route reaches. * fix(ui): drop the space a hidden spinner left before button text * fix(ui/status): one dense Status page, full-width settings, problems-only apply status Status drops its tabs and the duplicate health card; services list only what is wrong. Settings pages use the full width, the resizable sidebar handle is gone, and apply status shows only processes that have not applied a change. PageHeader puts the title and actions on one line. * refactor(ui): use shadcn ToggleGroup and Badge, drop SegmentedControl and StatusPill Status badges show only when a state needs attention: no Running, Enabled, Active, Listening or live pills next to healthy rows. Removes the unused pagination, radio-group and scroll-area components. * fix(ui/history): use the shadcn Table with fixed columns so nothing is clipped * fix(ui/workflows): apply ?workflow= only once the workflow is listed Selecting it before the definitions loaded opened an empty canvas. * refactor(ui/workflows): use shadcn Input, NativeSelect, Checkbox and Button in editors Replaces hand-rolled inputs, selects, the repository mode switch and icon buttons in the workflow editor, bind dialog, harness page, sources panel and review gate. Adds the upstream shadcn-vue NativeSelect. * style(ui): rounded-rectangle controls instead of pills Halves the radius scale so inputs, selects and buttons stop reading as pills, and badges and chips lose their full rounding. * fix(ui/alerts): centre the bell's failed state and stop it contradicting Needs you * fix(ui/tasks): one header line, aligned columns, no placeholder issue numbers Tasks puts its filters beside the title and drops the stat tiles the dashboard already shows. Sort headers align with their cells, chat tasks no longer show their synthetic issue number, and Logs and the task not-found page use the shared header. * fix(ui/dashboard): shared header and cards, empty cards stay silent Needs you uses the shadcn Card and drops its duplicate Open button; quality gates and token outlook render only when there is something to show; the throughput strip moves into the dashboard, its only user. * refactor(ui/stores): one Pinia store per feature Splits the site-wide control-plane store and the module-level refs into settings, workflows, tasks, events, org and session stores. Identity requests move into lib/api. Drops store fields nothing read: per-resource stream state, the states map and loadApplyStatus. * fix(ui/org): one header for the org area, sections drop their repeated titles The org name is the page title with the admin's org switcher and New org beside it; Members and Workspaces tables sit in cards like other pages. * fix(ui/events): shadcn Tabs for the capture, map and bind steps Replaces the numbered step strip with line tabs that carry each step's count; the Listening pill is gone and Capture off shows only when it is. * fix(ui/workflows): confirm a workflow delete in an AlertDialog, not window.confirm * style(ui/settings): denser setting rows
129 lines
5.2 KiB
TypeScript
129 lines
5.2 KiB
TypeScript
import { computed, onMounted, ref, type Ref } from "vue";
|
|
import { parse } from "yaml";
|
|
|
|
import { api } from "@/lib/api";
|
|
import { branchingOf } from "./workflow-edit.ts";
|
|
import { useSettingsStore } from "@/stores/settings";
|
|
import { useWorkflowsStore } from "@/stores/workflows";
|
|
import type { Binding } from "@/bindings/binding-draft";
|
|
|
|
/** One way a workflow gets started. */
|
|
export interface WorkflowTrigger {
|
|
kind: "issue" | "event" | "playbook" | "workflow";
|
|
label: string;
|
|
detail?: string;
|
|
/** The event binding this trigger is, for editing it. */
|
|
binding?: Binding;
|
|
}
|
|
|
|
export interface TriggerSources {
|
|
/** Issue label kind to workflow, with "default" for an unlabelled issue. */
|
|
routes: Record<string, string>;
|
|
bindings: Binding[];
|
|
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, binding });
|
|
}
|
|
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) =>
|
|
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 "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 = useSettingsStore();
|
|
const workflows = useWorkflowsStore();
|
|
const bindings = ref<TriggerSources["bindings"]>([]);
|
|
async function reload(): Promise<void> {
|
|
const response = await api.bindings<{ bindings?: Binding[] }>().catch(() => null);
|
|
bindings.value = response?.bindings ?? [];
|
|
}
|
|
onMounted(reload);
|
|
const triggers = computed(() =>
|
|
triggersFor(id.value, {
|
|
routes: workflows.intakeRoutes,
|
|
bindings: bindings.value,
|
|
playbooks: (store.stateFor("eda-playbooks").resource?.value as { playbooks?: TriggerSources["playbooks"] } | undefined)?.playbooks ?? [],
|
|
definitions: workflows.collection.definitions,
|
|
}),
|
|
);
|
|
return { triggers, reload };
|
|
}
|