fix(ui): repair settings editing and workflow diagnostics

This commit is contained in:
sam committed 2026-10-16 23:55:58 +11:00
1 parent ede967220e
commit b3fa386ae0
46 files changed
+708 -240

No files matched your search

+14 -7
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select";
import { computed, ref } from "vue";
import { computed, ref, useId } from "vue";
import { CircleHelp, Plus, Trash2, X } from "@lucide/vue";
import { parse, stringify } from "yaml";
@@ -16,8 +16,9 @@ import type { InputSpec } from "./bind-event";
import { inputValue } from "./work-request";
import WorkflowPicker from "./WorkflowPicker.vue";
import { stepTitle } from "./workflow-graph";
import { settingsProblem, type SettingsSchema, type StepTypeInfo } from "./workflow-yaml";
import { stepControlsProblem, settingsProblem, type SettingsSchema, type StepTypeInfo } from "./workflow-yaml";
const uid = useId();
const props = defineProps<{ yaml: string; path: StepPath; vocabulary: StepTypeInfo[]; workflows: WorkflowDefinitionEntry[]; modelAliases: string[] }>();
const emit = defineEmits<{ "update:yaml": [string]; close: []; remove: [] }>();
@@ -46,6 +47,7 @@ const settings = computed<Record<string, unknown>>(() =>
typeof step.value.settings === "object" && step.value.settings !== null ? (step.value.settings as Record<string, unknown>) : {},
);
const earlier = computed(() => earlierStepIDs(props.yaml, props.path));
const flowProblem = computed(() => stepControlsProblem(step.value));
const problem = computed(() =>
info.value?.settings && step.value.settings ? settingsProblem(step.value.settings, info.value.settings, "settings") : "",
);
@@ -90,7 +92,8 @@ function setField(key: string, value: unknown): void {
// Retry is one object: a field edit merges into it so attempts and backoff do
// not clobber each other, and clearing both drops the key.
function setRetry(next: { attempts?: number; backoff?: string }): void {
setField("retry", { ...(step.value.retry as object), ...next });
const policy = { ...(step.value.retry as { attempts?: number; backoff?: string }), ...next };
setField("retry", policy.attempts === undefined && !policy.backoff ? undefined : { ...policy, attempts: policy.attempts ?? 1 });
}
function setSetting(key: string, value: unknown): void {
const next = { ...settings.value, [key]: value };
@@ -325,12 +328,15 @@ const text = (key: string) => (typeof settings.value[key] === "string" ? (settin
<section class="space-y-2">
<div class="text-xs font-medium text-muted-foreground">Flow</div>
<p class="text-xs text-fg-muted">Leave the condition empty to always run. Use a field such as inputs.enabled, !inputs.skip, or steps.plan.result.ready == true.</p>
<p v-if="flowProblem" role="alert" class="text-xs text-danger">{{ flowProblem }}</p>
<div class="divide-y divide-border rounded-md border border-border">
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-[13px]">Run only when</span>
<Input
class="h-7 w-48 font-mono text-xs"
placeholder="always"
placeholder="inputs.enabled"
:aria-invalid="flowProblem && flowProblem.startsWith('when') ? true : undefined"
:model-value="(step.when as string) ?? ''"
@update:model-value="(value) => setField('when', String(value))"
/>
@@ -358,14 +364,15 @@ const text = (key: string) => (typeof settings.value[key] === "string" ? (settin
@update:model-value="(value) => setRetry({ attempts: String(value) === '' ? undefined : Number(String(value)) })"
/>
</label>
<label class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<span class="flex-1 text-[13px]">Retry backoff</span>
<div class="flex min-h-10 items-center gap-3 px-3 py-1.5">
<label :for="`${uid}-backoff`" class="flex-1 text-[13px]">Retry backoff</label>
<DurationInput
:id="`${uid}-backoff`"
:model-value="(step.retry as { backoff?: string } | undefined)?.backoff ?? ''"
:units="['s', 'm', 'h']"
@update:model-value="setRetry({ backoff: $event || undefined })"
/>
</label>
</div>
</div>
</section>
</div>
+15 -4
View File
@@ -67,6 +67,7 @@ const selected = defineModel<string>("selected", { required: true });
defineProps<{ runsCount?: number }>();
const id = ref("");
const yaml = ref("");
const loadedYaml = ref("");
const selectedStep = ref<StepPath | null>(null);
// The slide-in panel shows one thing: a step's editor, or the workflow's settings.
const settingsOpen = ref(false);
@@ -75,7 +76,7 @@ watch(selectedStep, (path) => {
});
const localError = ref("");
const { runs, watched, watchedRun, stages, attempt, pick, follow, refresh } = useWorkflowRuns(selected);
const { runs, error: runsError, loading: runsLoading, watched, watchedRun, stages, attempt, pick, follow, refresh } = useWorkflowRuns(selected);
const stepTab = ref("definition");
const selectedNode = computed(() => withRuns(workflowGraph(yaml.value), stages.value).nodes.find((node) => JSON.stringify(node.data.path) === JSON.stringify(selectedStep.value))?.data);
function openStep(path: StepPath): void {
@@ -157,15 +158,17 @@ function load(value: string): void {
);
id.value = entry?.id ?? value;
yaml.value = entry?.yaml ?? `id: ${value}\nsteps: []\n`;
loadedYaml.value = yaml.value;
selectedStep.value = null;
localError.value = "";
}
watch(selected, load, { immediate: true });
// The collection arrives after the first render; a later live update must not
// overwrite what is being typed, so it only fills an editor still empty.
// overwrite what is being typed, so it only refreshes an editor with no local edits.
watch(collection, () => {
if (!yaml.value) load(selected.value);
const incoming = collection.value.definitions.find((entry) => entry.id === selected.value);
if (incoming && yaml.value === loadedYaml.value && incoming.yaml !== loadedYaml.value) load(selected.value);
});
async function save(next: WorkflowDefinitionCollection): Promise<boolean> {
@@ -189,8 +192,10 @@ async function saveDraft(): Promise<void> {
next = removeWorkflowDefinition(next, previous);
if (
await save(upsertWorkflowDefinition(next, { id: nextID, yaml: yaml.value }))
)
) {
selected.value = nextID;
loadedYaml.value = yaml.value;
}
}
const confirmDelete = ref(false);
@@ -292,6 +297,12 @@ function syncScroll(event: Event): void {
<Spinner v-if="state.saving" data-icon="inline-start" />Save</Button>
</template>
</div>
<p v-if="runsLoading" class="text-xs text-fg-muted" role="status">Loading recent runs…</p>
<div v-else-if="runsError" class="text-sm text-danger" role="alert">
<p>Could not load recent runs: {{ runsError }}</p>
<Button type="button" variant="outline" size="sm" @click="refresh">Retry runs</Button>
</div>
<p v-if="watchedRun && !watchedRun.workflow_definition_yaml" class="text-xs text-fg-muted" role="status">No workflow snapshot was recorded for this run. Showing the current definition.</p>
<TabsContent value="canvas" class="space-y-2">
<!-- The canvas takes the height the viewport has left, so the page
itself does not scroll; the canvas pans. -->
+32 -6
View File
@@ -58,6 +58,7 @@ const store = useWorkflowsStore();
const data = ref<WorkflowsResponse>({});
const runs = ref<RunTask[]>([]);
const error = ref<string | null>(null);
const loading = ref(true);
async function load() {
try {
@@ -68,6 +69,8 @@ async function load() {
void loadWorkflowRuns();
} catch (err) {
error.value = String((err as Error).message || err);
} finally {
loading.value = false;
}
}
useLiveResource("tasks", () => void load(), 500);
@@ -138,11 +141,25 @@ const stages = computed(() => (data.value.stages ?? []).filter((s) => s.workflow
// The selected workflow's runs come from a workflow-filtered page: the global
// list above holds only the newest tasks of every workflow.
const workflowRuns = ref<RunTask[]>([]);
const runsLoading = ref(false);
const runsError = ref("");
let runsRequest = 0;
async function loadWorkflowRuns() {
const request = ++runsRequest;
const requested = selected.value;
const page = requested ? await api.taskPage<RunTask>({ workflow: requested }).catch(() => null) : null;
if (selected.value === requested) workflowRuns.value = page?.tasks ?? [];
runsLoading.value = true;
runsError.value = "";
workflowRuns.value = [];
try {
const page = requested ? await api.taskPage<RunTask>({ workflow: requested }) : null;
if (request === runsRequest) workflowRuns.value = page?.tasks ?? [];
} catch (err) {
if (request === runsRequest) runsError.value = String((err as Error).message || err);
} finally {
if (request === runsRequest) runsLoading.value = false;
}
}
watch(selected, () => void loadWorkflowRuns(), { immediate: true });
function create() {
@@ -190,7 +207,11 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
</AlertDialogContent>
</AlertDialog>
<p v-if="error" class="mb-4 text-sm text-danger" role="alert">Cannot reach archied: {{ error }}</p>
<div v-if="error || store.error" class="mb-4 text-sm text-danger" role="alert">
<p>{{ error || store.error }}</p>
<Button variant="outline" size="sm" @click="load(); store.load()">Retry</Button>
</div>
<p v-if="loading || (!store.state.resource && !store.error)" class="text-sm text-fg-muted" role="status">Loading workflows…</p>
<div class="grid items-start gap-6 lg:grid-cols-[24rem_minmax(0,1fr)]">
<ul class="flex gap-1 overflow-x-auto pb-2 lg:flex-col lg:gap-0.5 lg:overflow-visible lg:pb-0" aria-label="Workflows">
@@ -220,14 +241,14 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
</li>
</ul>
<section v-if="!selected" class="min-w-0 rounded-lg border border-border bg-card" aria-label="Workflow">
<section v-if="!selected && !loading && store.state.resource && !error" class="min-w-0 rounded-lg border border-border bg-card" aria-label="Workflow">
<Empty>
<EmptyHeader>
<EmptyTitle>No workflows</EmptyTitle>
</EmptyHeader>
</Empty>
</section>
<section v-else class="min-w-0 rounded-lg border border-border bg-card px-3 py-4 sm:px-5" aria-label="Workflow">
<section v-else-if="selected && store.state.resource" class="min-w-0 rounded-lg border border-border bg-card px-3 py-4 sm:px-5" aria-label="Workflow">
<header class="mb-2 flex flex-wrap items-center gap-2">
<h2 class="font-mono text-[15px] font-medium">{{ selected }}</h2>
<Badge v-if="provenance" variant="outline">{{ provenance }}</Badge>
@@ -251,7 +272,12 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
</template>
</template>
<template #runs>
<Empty v-if="!workflowRuns.length">
<p v-if="runsLoading" role="status" class="text-sm text-fg-muted">Loading runs…</p>
<div v-else-if="runsError" role="alert" class="text-sm text-danger">
<p>{{ runsError }}</p>
<Button variant="outline" size="sm" @click="loadWorkflowRuns">Retry</Button>
</div>
<Empty v-else-if="!workflowRuns.length">
<EmptyHeader>
<EmptyTitle>No runs yet</EmptyTitle>
</EmptyHeader>
+21 -8
View File
@@ -25,18 +25,28 @@ export function useWorkflowRuns(workflow: Ref<string>) {
const stages = ref<StageRun[]>([]);
const attempt = ref(0);
let picked = false;
const error = ref("");
const loading = ref(false);
let requestNumber = 0;
async function loadRuns(): Promise<void> {
// The server filters by workflow: filtering a global page here would miss
// every run older than that page.
const requested = workflow.value;
const page = requested
? await api.taskPage<WorkflowRun>({ workflow: requested, limit: RECENT_RUNS }).catch(() => null)
: null;
if (workflow.value !== requested) return;
runs.value = (page?.tasks ?? []).sort((a, b) => Number(b.id) - Number(a.id));
if (!picked || (watched.value && !runs.value.some((run) => String(run.id) === watched.value)))
watched.value = runs.value[0] ? String(runs.value[0].id) : "";
const request = ++requestNumber;
loading.value = true;
try {
const page = requested ? await api.taskPage<WorkflowRun>({ workflow: requested, limit: RECENT_RUNS }) : null;
if (workflow.value !== requested || request !== requestNumber) return;
runs.value = (page?.tasks ?? []).sort((a, b) => Number(b.id) - Number(a.id));
error.value = "";
if (!picked || (watched.value && !runs.value.some((run) => String(run.id) === watched.value)))
watched.value = runs.value[0] ? String(runs.value[0].id) : "";
} catch (cause) {
if (workflow.value === requested && request === requestNumber) error.value = String((cause as Error).message || cause);
} finally {
if (request === requestNumber) loading.value = false;
}
}
async function loadStages(): Promise<void> {
@@ -66,6 +76,9 @@ export function useWorkflowRuns(workflow: Ref<string>) {
watch(workflow, () => {
picked = false;
runs.value = [];
watched.value = "";
error.value = "";
void refresh();
}, { immediate: true });
watch(watched, () => {
@@ -84,5 +97,5 @@ export function useWorkflowRuns(workflow: Ref<string>) {
await refresh();
}
return { runs, watched, watchedRun, stages, attempt, pick, follow, refresh };
return { runs, error, loading, watched, watchedRun, stages, attempt, pick, follow, refresh };
}
+28
View File
@@ -1,4 +1,5 @@
import { parseDocument } from "yaml";
import { parseGoDuration } from "../components/ui/duration-input/duration.ts";
import { branchingOf } from "./workflow-edit.ts";
/**
@@ -87,6 +88,8 @@ export function parseWorkflowYaml(
const declared = new Set<string>();
for (const [i, step] of steps.entries()) {
const where = `workflow ${id} step ${i + 1}`;
const controls = stepControlsProblem(step);
if (controls) return { ok: false, message: `${where}: ${controls}` };
const branching = branchingOf(step);
if (branching) {
if (branching.kind === "switch" && !branching.on)
@@ -100,6 +103,7 @@ export function parseWorkflowYaml(
for (const [j, branchStep] of branchSteps.entries()) {
const branchWhere = `${where} branch ${branch} step ${j + 1}`;
const problem =
stepControlsProblem(branchStep) ||
checkStepType(branchStep, branchWhere, known, repository) ||
laterReference(branchStep, branchWhere, visible);
if (problem) return { ok: false, message: problem };
@@ -135,6 +139,30 @@ function declareID(step: unknown, declared: Set<string>): void {
if (isMapping(step) && typeof step.id === "string") declared.add(step.id);
}
/** The shared flow controls, checked in both the step panel and YAML editor. */
export function stepControlsProblem(step: unknown): string {
if (!isMapping(step)) return "";
if (step.when !== undefined && step.when !== "") {
if (typeof step.when !== "string") return "when must be a reference";
const operator = step.when.includes("==") ? "==" : step.when.includes("!=") ? "!=" : "";
const path = operator ? step.when.split(operator, 1)[0]!.trim() : step.when.trim().replace(/^!\s*/, "");
if (!/^(task|inputs|steps)\.[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*$/.test(path))
return "when must name a task, inputs or steps field, optionally prefixed with ! or compared using == or !=";
}
if (step.retry !== undefined) {
if (!isMapping(step.retry)) return "retry must be a mapping";
const { attempts, backoff } = step.retry;
if (typeof attempts !== "number" || !Number.isInteger(attempts) || attempts < 1 || attempts > 10)
return "retry.attempts must be a whole number from 1 to 10";
if (backoff !== undefined && backoff !== "") {
const duration = typeof backoff === "string" ? parseGoDuration(backoff) : null;
if (duration === null || duration < 0 || !Number.isFinite(duration))
return "retry.backoff must be a non-negative duration, such as 5s or 1m";
}
}
return "";
}
/** What is wrong with one typed step, or "" when nothing the page can see. */
function checkStepType(
step: unknown,