fix(ui/workflows): failures read from the error catalogue
This commit is contained in:
31 files changed
+263
-104
No files matched your search
@@ -20,6 +20,7 @@ import {
|
||||
} from "@/components/ui/trace";
|
||||
import ChatMarkdown from "@/chat/ChatMarkdown.vue";
|
||||
import { api } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { keepValue } from "@/lib/keep-unchanged";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
import { duration } from "@/tasks/timeline-event";
|
||||
@@ -169,7 +170,7 @@ const conversations = computed(() => {
|
||||
<Trace>
|
||||
<TraceLine :status="row.step.model.error ? 'error' : undefined">
|
||||
<TraceIcon><CircleAlertIcon v-if="row.step.model.error" /><SparklesIcon v-else /></TraceIcon>
|
||||
<TraceTitle>{{ row.step.model.error ? `Step ${row.number} failed: ${row.step.model.error}` : `Step ${row.number}` }}</TraceTitle>
|
||||
<TraceTitle>{{ row.step.model.error ? errors.workflows.transcript.stepFailed(row.number, row.step.model.error) : `Step ${row.number}` }}</TraceTitle>
|
||||
<TraceDescription v-if="usage(row.step.model)">{{ usage(row.step.model) }}</TraceDescription>
|
||||
</TraceLine>
|
||||
<TranscriptTool v-for="tool in row.step.tools" :key="tool.seq" :tool="tool" />
|
||||
@@ -180,7 +181,7 @@ const conversations = computed(() => {
|
||||
</div>
|
||||
</DefineConversation>
|
||||
|
||||
<p v-if="failed" role="alert" class="text-danger">Could not load the transcript</p>
|
||||
<p v-if="failed" role="alert" class="text-danger">{{ errors.workflows.transcript.notLoaded }}</p>
|
||||
<Spinner v-else-if="!events" />
|
||||
<Empty v-else-if="!conversations.length"><EmptyHeader><EmptyTitle>No transcript recorded</EmptyTitle></EmptyHeader></Empty>
|
||||
<ConversationView v-else-if="conversations.length === 1" :conversation="conversations[0]!" />
|
||||
|
||||
@@ -12,7 +12,8 @@ import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { api } from "@/lib/api";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { keepRows } from "@/lib/keep-unchanged";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
import { statusKind, statusLabel, takesRepository, type Binding } from "@/bindings/binding-draft";
|
||||
@@ -90,10 +91,10 @@ async function loadAll(): Promise<void> {
|
||||
loading.value = true;
|
||||
let readError = "";
|
||||
const [listed, types, mapped, bound] = await Promise.all([
|
||||
api.sources<{ sources?: { path: string; name?: string }[] }>().catch((err) => { readError = String((err as Error).message || err); return null; }),
|
||||
api.eventTypes<{ event_types?: EventType[] }>().catch((err) => { readError = String((err as Error).message || err); return null; }),
|
||||
api.mappings<{ mappings?: Mapping[] }>().catch((err) => { readError = String((err as Error).message || err); return null; }),
|
||||
api.bindings<{ bindings?: Binding[] }>().catch((err) => { readError = String((err as Error).message || err); return null; }),
|
||||
api.sources<{ sources?: { path: string; name?: string }[] }>().catch((err) => { readError = describeError(err, errors.common.unknown); return null; }),
|
||||
api.eventTypes<{ event_types?: EventType[] }>().catch((err) => { readError = describeError(err, errors.common.unknown); return null; }),
|
||||
api.mappings<{ mappings?: Mapping[] }>().catch((err) => { readError = describeError(err, errors.common.unknown); return null; }),
|
||||
api.bindings<{ bindings?: Binding[] }>().catch((err) => { readError = describeError(err, errors.common.unknown); return null; }),
|
||||
loadCaptures(),
|
||||
]);
|
||||
sources.value = (listed?.sources ?? []).map((s) => s.path);
|
||||
@@ -102,7 +103,7 @@ async function loadAll(): Promise<void> {
|
||||
mappings.value = mapped?.mappings ?? [];
|
||||
bindings.value = bound?.bindings ?? [];
|
||||
bindingsLoaded.value = bound !== null;
|
||||
loadError.value = [listed, types, mapped, bound].some((leg) => leg === null) ? readError || "Couldn't load the bind form" : "";
|
||||
loadError.value = [listed, types, mapped, bound].some((leg) => leg === null) ? readError || errors.workflows.bindEvent.formNotLoaded : "";
|
||||
if (props.binding) {
|
||||
source.value = props.binding.matcher?.source ?? "";
|
||||
const mapping = mappings.value.find((m) => String(m.id) === props.binding?.mapping_id);
|
||||
@@ -145,10 +146,10 @@ watch([fields, captureId], () => {
|
||||
}, { deep: true, immediate: true });
|
||||
|
||||
const blockers = computed(() => {
|
||||
if (!sourcePath.value) return ["pick a source"];
|
||||
if (source.value === NEW_SOURCE) return ["create the source first"];
|
||||
if (!capture.value) return [`no event from ${sourcePath.value} yet to preview against`];
|
||||
if (payload.value === null) return ["the picked event's body is not JSON"];
|
||||
if (!sourcePath.value) return [errors.workflows.bindEvent.blocker.pickSource];
|
||||
if (source.value === NEW_SOURCE) return [errors.workflows.bindEvent.blocker.createSourceFirst];
|
||||
if (!capture.value) return [errors.workflows.bindEvent.blocker.noEvent(sourcePath.value)];
|
||||
if (payload.value === null) return [errors.workflows.bindEvent.blocker.bodyNotJson];
|
||||
return problems(inputs.value, rows.value, preview.value);
|
||||
});
|
||||
|
||||
@@ -189,7 +190,7 @@ async function createSource(): Promise<void> {
|
||||
source.value = created.path;
|
||||
newSource.value = "";
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : String(err);
|
||||
error.value = describeError(err, errors.common.unknown);
|
||||
} finally {
|
||||
creatingSource.value = false;
|
||||
}
|
||||
@@ -200,7 +201,7 @@ async function save(): Promise<void> {
|
||||
// Without the bindings list, sharedMapping() cannot tell whether the
|
||||
// mapping is shared, and mappingUpdate must not run on it.
|
||||
if (props.binding?.mapping_id && !bindingsLoaded.value) {
|
||||
error.value = "The bindings list did not load, so this edit cannot tell whether the mapping is shared. Retry the load first.";
|
||||
error.value = errors.workflows.bindEvent.bindingsNotLoaded;
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
@@ -230,7 +231,7 @@ async function save(): Promise<void> {
|
||||
else await api.bindingCreate(body);
|
||||
emit("saved");
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : String(err);
|
||||
error.value = describeError(err, errors.common.unknown);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
@@ -245,7 +246,7 @@ async function transition(command: (id: string) => Promise<unknown>, next: strin
|
||||
status.value = next;
|
||||
emit("saved");
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : String(err);
|
||||
error.value = describeError(err, errors.common.unknown);
|
||||
}
|
||||
}
|
||||
async function removeBinding(): Promise<void> {
|
||||
@@ -256,7 +257,7 @@ async function removeBinding(): Promise<void> {
|
||||
await api.bindingDelete(props.binding.id);
|
||||
emit("saved");
|
||||
} catch (cause) {
|
||||
error.value = cause instanceof Error ? cause.message : String(cause);
|
||||
error.value = describeError(cause, errors.common.unknown);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
@@ -365,7 +366,7 @@ const resume = () => transition(api.bindingResume, "pending_approval");
|
||||
|
||||
<div class="space-y-2">
|
||||
<Alert v-if="error" variant="destructive"><AlertDescription>{{ error }}</AlertDescription></Alert>
|
||||
<p v-else-if="blockers.length" class="text-caption text-fg-subtle">Cannot save: {{ blockers[0] }}</p>
|
||||
<p v-else-if="blockers.length" class="text-caption text-fg-subtle">{{ errors.workflows.bindingSave.cannotSave(blockers[0] ?? "") }}</p>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<Button type="submit" size="sm" :disabled="saving || !!blockers.length"><Spinner v-if="saving" />Save binding</Button>
|
||||
<Button v-if="binding && status === 'pending_approval'" type="button" size="sm" variant="outline" @click="approve">Approve</Button>
|
||||
|
||||
@@ -19,7 +19,8 @@ import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { api } from "@/lib/api";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { constantValue, statusKind, statusLabel, type Binding, type InputSource } from "@/bindings/binding-draft";
|
||||
import ScheduleEditor from "@/schedules/ScheduleEditor.vue";
|
||||
import { type Schedule } from "@/schedules/schedule";
|
||||
@@ -56,7 +57,7 @@ onMounted(async () => {
|
||||
try {
|
||||
schedules.value = (await api.schedules<{ schedules?: Schedule[] }>()).schedules ?? [];
|
||||
} catch (err) {
|
||||
loadError.value = err instanceof Error ? err.message : String(err);
|
||||
loadError.value = describeError(err, errors.common.unknown);
|
||||
}
|
||||
for (const [name] of inputs.value) {
|
||||
const src = props.binding?.inputs?.[name];
|
||||
@@ -104,10 +105,10 @@ function created(schedule: Schedule): void {
|
||||
|
||||
const schedule = computed(() => schedules.value.find((s) => s.id === scheduleId.value));
|
||||
const blockers = computed(() => {
|
||||
if (!scheduleId.value) return ["pick a schedule"];
|
||||
if (!scheduleId.value) return [errors.workflows.scheduleTrigger.pickSchedule];
|
||||
return inputs.value
|
||||
.filter(([name, spec]) => spec.required && rows.value[name]?.from === FIXED && rows.value[name]?.value === "")
|
||||
.map(([name]) => `${name} is required`);
|
||||
.map(([name]) => errors.workflows.bindingSave.inputRequired(name));
|
||||
});
|
||||
|
||||
function bindingInputs(): Record<string, InputSource> {
|
||||
@@ -141,7 +142,7 @@ async function save(): Promise<void> {
|
||||
else await api.bindingCreate(body);
|
||||
emit("saved");
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : String(err);
|
||||
error.value = describeError(err, errors.common.unknown);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
@@ -155,7 +156,7 @@ async function transition(command: (id: string) => Promise<unknown>, next: strin
|
||||
status.value = next;
|
||||
emit("saved");
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : String(err);
|
||||
error.value = describeError(err, errors.common.unknown);
|
||||
}
|
||||
}
|
||||
async function remove(): Promise<void> {
|
||||
@@ -164,7 +165,7 @@ async function remove(): Promise<void> {
|
||||
await api.bindingDelete(props.binding.id);
|
||||
emit("saved");
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : String(err);
|
||||
error.value = describeError(err, errors.common.unknown);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -215,7 +216,7 @@ async function remove(): Promise<void> {
|
||||
|
||||
<div class="space-y-2">
|
||||
<Alert v-if="error" variant="destructive"><AlertDescription>{{ error }}</AlertDescription></Alert>
|
||||
<p v-else-if="blockers.length" class="text-caption text-fg-subtle">Cannot save: {{ blockers[0] }}</p>
|
||||
<p v-else-if="blockers.length" class="text-caption text-fg-subtle">{{ errors.workflows.bindingSave.cannotSave(blockers[0] ?? "") }}</p>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<Button type="submit" size="sm" :disabled="saving || !!blockers.length"><Spinner v-if="saving" />Save trigger</Button>
|
||||
<Button v-if="binding && status === 'pending_approval'" type="button" size="sm" variant="outline" @click="transition(api.bindingApprove, 'armed')">Approve</Button>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { computed, ref, useId } from "vue";
|
||||
@@ -40,7 +42,7 @@ function changeBranch(action: "add" | "rename" | "delete", name: string, next =
|
||||
newBranch.value = "";
|
||||
branchError.value = "";
|
||||
} catch (error) {
|
||||
branchError.value = String((error as Error).message);
|
||||
branchError.value = describeError(error, errors.common.unknown);
|
||||
}
|
||||
}
|
||||
const info = computed(() => props.vocabulary.find((candidate) => candidate.name === type.value));
|
||||
@@ -145,7 +147,7 @@ function setYamlSetting(key: string, text: string): void {
|
||||
setSetting(key, text.trim() ? parse(text) : undefined);
|
||||
yamlErrors.value = { ...yamlErrors.value, [key]: "" };
|
||||
} catch (error) {
|
||||
yamlErrors.value = { ...yamlErrors.value, [key]: String((error as Error).message).split("\n")[0] };
|
||||
yamlErrors.value = { ...yamlErrors.value, [key]: describeError(error, errors.common.unknown).split("\n")[0] };
|
||||
}
|
||||
}
|
||||
const asYaml = (value: unknown) => (value === undefined ? "" : stringify(value).trimEnd());
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Item, ItemGroup } from "@/components/ui/item";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { computed, onUnmounted, ref, watch } from "vue";
|
||||
import { api } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { keepValue } from "@/lib/keep-unchanged";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
@@ -42,9 +43,9 @@ async function refresh(): Promise<void> {
|
||||
]);
|
||||
if (current !== generation) return;
|
||||
const [activity, capture, log] = results;
|
||||
activityError.value = activity.status === "rejected" ? "Could not load step activity" : "";
|
||||
activityError.value = activity.status === "rejected" ? errors.workflows.stepRun.activityNotLoaded : "";
|
||||
if (activity.status === "fulfilled") events.value = keepValue(events.value, activity.value.events ?? []);
|
||||
changesError.value = capture.status === "rejected" ? "Could not load captured changes" : "";
|
||||
changesError.value = capture.status === "rejected" ? errors.workflows.stepRun.changesNotLoaded : "";
|
||||
if (capture.status === "fulfilled") changes.value = keepValue(changes.value, capture.value);
|
||||
logs.value = log.status === "fulfilled" ? keepValue(logs.value, log.value) : null;
|
||||
loading = false;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { errors } from "@/copy/errors";
|
||||
import { ArrowUpRightIcon, CircleAlertIcon, CircleCheckIcon, FlagIcon, FlaskConicalIcon, GlobeIcon, SquareTerminalIcon } from "@lucide/vue";
|
||||
import { computed } from "vue";
|
||||
|
||||
@@ -58,11 +59,11 @@ const argument = computed(() => {
|
||||
});
|
||||
const title = computed(() => {
|
||||
switch (kind.value) {
|
||||
case "terminal": return `${failed.value ? "Failed to run" : "Ran"} ${command.value.split("\n", 1)[0]}`;
|
||||
case "tests": return failed.value ? "Gate failed" : "Ran the gate";
|
||||
case "source": return `${failed.value ? "Failed to read" : "Read"} ${host.value}`;
|
||||
case "terminal": return `${failed.value ? errors.workflows.transcript.tool.failedToRun : "Ran"} ${command.value.split("\n", 1)[0]}`;
|
||||
case "tests": return failed.value ? errors.workflows.transcript.tool.gateFailed : "Ran the gate";
|
||||
case "source": return `${failed.value ? errors.workflows.transcript.tool.failedToRead : "Read"} ${host.value}`;
|
||||
case "finish": return `Finished as ${String(args.value.status ?? "unknown")}`;
|
||||
default: return `${failed.value ? "Failed to run" : "Ran"} ${props.tool.tool} ${argument.value}`;
|
||||
default: return `${failed.value ? errors.workflows.transcript.tool.failedToRun : "Ran"} ${props.tool.tool} ${argument.value}`;
|
||||
}
|
||||
});
|
||||
const output = computed(() => withClip(props.tool.output, props.tool.output_bytes));
|
||||
|
||||
@@ -22,7 +22,8 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import StepRun from "./StepRun.vue";
|
||||
import { restartAt, withRuns, workflowGraph } from "./workflow-graph";
|
||||
import { api } from "@/lib/api";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { ago } from "@/lib/format";
|
||||
import { statusLabel } from "@/lib/task-meta";
|
||||
import StepEditor from "./StepEditor.vue";
|
||||
@@ -109,7 +110,7 @@ async function restartFrom(from: string): Promise<void> {
|
||||
await api.taskAction(watched.value, "retry", { resume_from: from });
|
||||
await refresh();
|
||||
} catch (err) {
|
||||
restartError.value = err instanceof Error ? err.message : "Restart failed";
|
||||
restartError.value = describeError(err, errors.workflows.editor.restartFailed);
|
||||
} finally {
|
||||
restarting.value = false;
|
||||
}
|
||||
@@ -203,7 +204,7 @@ async function persistDraft(target: string, value: string, attempt = 0): Promise
|
||||
} else if (target === selected.value) {
|
||||
// The write failed for good: the edit stays in the editor, and the alert
|
||||
// says the draft was not saved rather than dropping it silently.
|
||||
localError.value = workflows.draftState.error || "Draft not saved — your edit is still in the editor.";
|
||||
localError.value = workflows.draftState.error || errors.workflows.editor.draftNotSaved;
|
||||
}
|
||||
}
|
||||
// The last edit not yet written, flushed at once when the editor switches
|
||||
@@ -331,7 +332,7 @@ const nodeProblems = computed(() =>
|
||||
failedPath.value && !parsed.value.ok ? { ...problems.value, [JSON.stringify(failedPath.value)]: parsed.value.message } : problems.value,
|
||||
);
|
||||
// Every error the editor knows, each linked to its step when it has one.
|
||||
const errors = computed(() => {
|
||||
const issues = computed(() => {
|
||||
const list: { text: string; path?: StepPath }[] = [];
|
||||
if (!parsed.value.ok) list.push({ text: validationLabel(parsed.value), path: failedPath.value });
|
||||
for (const [key, text] of Object.entries(problems.value)) list.push({ text, path: JSON.parse(key) as StepPath });
|
||||
@@ -430,7 +431,7 @@ onBeforeUnmount(() => yamlObserver?.disconnect());
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="end" class="max-h-96 w-80 overflow-y-auto p-1">
|
||||
<ul class="text-caption text-danger">
|
||||
<li v-for="(error, i) in errors" :key="i">
|
||||
<li v-for="(error, i) in issues" :key="i">
|
||||
<Button v-if="error.path" type="button" variant="ghost" class="h-auto w-full justify-start whitespace-normal px-2 py-1.5 text-left text-caption font-normal text-danger hover:underline" @click="showError(error.path)">{{ error.text }}</Button>
|
||||
<p v-else class="px-2 py-1.5">{{ error.text }}</p>
|
||||
</li>
|
||||
@@ -457,11 +458,11 @@ onBeforeUnmount(() => yamlObserver?.disconnect());
|
||||
</div>
|
||||
<p v-if="runsLoading && !runs.length" class="flex items-center gap-2 text-caption text-fg-muted"><Spinner />Loading recent runs…</p>
|
||||
<div v-else-if="runsError" class="text-label text-danger" role="alert">
|
||||
<p>Could not load recent runs: {{ runsError }}</p>
|
||||
<p>{{ errors.workflows.editor.recentRunsNotLoaded(runsError) }}</p>
|
||||
<Button type="button" variant="outline" size="sm" @click="refresh">Retry runs</Button>
|
||||
</div>
|
||||
<div v-if="stagesError" class="text-label text-danger" role="alert">
|
||||
<p>Could not load the watched run's stages: {{ stagesError }}</p>
|
||||
<p>{{ errors.workflows.editor.watchedStagesNotLoaded(stagesError) }}</p>
|
||||
<Button type="button" variant="outline" size="sm" @click="refresh">Retry</Button>
|
||||
</div>
|
||||
<p v-if="view === 'canvas' && unpinned" class="text-caption text-fg-muted" role="status">No snapshot for this run.</p>
|
||||
|
||||
@@ -6,7 +6,8 @@ import { Textarea } from "@/components/ui/textarea";
|
||||
import { computed, ref, onMounted } from "vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { api } from "@/lib/api";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import type { Identity } from "@/stores/org";
|
||||
import { useOrgStore } from "@/stores/org";
|
||||
import { useSettingsStore } from "@/stores/settings";
|
||||
@@ -40,7 +41,7 @@ async function loadAgents(): Promise<void> {
|
||||
const response = await api.orgAgents<{ agents: Identity[] }>(identities.homeOrg);
|
||||
agents.value = response.agents.filter((agent) => agent.lifecycle === "active");
|
||||
} catch (cause) {
|
||||
identitiesError.value = String((cause as Error).message || cause);
|
||||
identitiesError.value = describeError(cause, errors.common.unknown);
|
||||
} finally { identitiesLoading.value = false; }
|
||||
}
|
||||
onMounted(loadAgents);
|
||||
|
||||
@@ -23,7 +23,8 @@ import { Section } from "@/components/ui/section";
|
||||
import { StatusDot } from "@/components/ui/status-dot";
|
||||
import { Table, TableBody, TableCell, TableRow } from "@/components/ui/table";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { api } from "@/lib/api";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { keepRows, keepValue } from "@/lib/keep-unchanged";
|
||||
import { delivered } from "@/lib/delivered";
|
||||
import { compact } from "@/lib/format";
|
||||
@@ -74,7 +75,7 @@ async function load() {
|
||||
// The runs page only changes when the workflow's own statistics do.
|
||||
if (runsFor !== selected.value || statsOf(selected.value) !== before) void loadWorkflowRuns();
|
||||
} catch (err) {
|
||||
error.value = String((err as Error).message || err);
|
||||
error.value = describeError(err, errors.common.unknown);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
@@ -135,7 +136,7 @@ async function setEnabled(id: string, value: boolean) {
|
||||
toast.success(`${id} ${value ? "enabled" : "disabled"}`);
|
||||
await load();
|
||||
} catch (err) {
|
||||
toast.error(`${id} not ${value ? "enabled" : "disabled"}: ${(err as Error).message || err}`);
|
||||
toast.error(value ? errors.workflows.page.notEnabled(id, describeError(err, errors.common.unknown)) : errors.workflows.page.notDisabled(id, describeError(err, errors.common.unknown)));
|
||||
}
|
||||
}
|
||||
const enabledOf = (id: string) => data.value.definitions?.find((d) => d.id === id)?.enabled;
|
||||
@@ -159,7 +160,7 @@ async function duplicate(id: string) {
|
||||
if (await store.save(upsertWorkflowDefinition(store.collection, { id: copy, yaml: setWorkflowField(source.yaml, "id", copy) }))) {
|
||||
selected.value = copy;
|
||||
toast.success(`${copy} created`);
|
||||
} else toast.error(`${id} not duplicated: ${store.error || "save failed"}`);
|
||||
} else toast.error(errors.workflows.page.notDuplicated(id, store.error || errors.workflows.page.saveFailed));
|
||||
}
|
||||
|
||||
interface RowAction {
|
||||
@@ -211,7 +212,7 @@ async function loadWorkflowRuns() {
|
||||
workflowRuns.value = keepRows(workflowRuns.value, page?.tasks ?? []);
|
||||
runsError.value = "";
|
||||
} catch (err) {
|
||||
if (request === runsRequest) runsError.value = String((err as Error).message || err);
|
||||
if (request === runsRequest) runsError.value = describeError(err, errors.common.unknown);
|
||||
} finally {
|
||||
if (request === runsRequest) runsLoading.value = false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { constantValue, type Binding, type InputSource } from "@/bindings/binding-draft";
|
||||
import type { Capture } from "@/captures/state";
|
||||
import { errors } from "../copy/errors/index.ts";
|
||||
import type { FieldType } from "@/mappings/mapping-fields";
|
||||
import type { MappingField, Preview } from "@/mappings/state";
|
||||
|
||||
@@ -52,18 +53,18 @@ export function problems(inputs: [string, InputSpec][], rows: Record<string, Inp
|
||||
const type = spec.type ?? "string";
|
||||
const set = row && (row.from === "path" ? row.path.trim() : row.value !== "");
|
||||
if (!set) {
|
||||
if (spec.required) out.push(`${name} is required`);
|
||||
if (spec.required) out.push(errors.workflows.bindingSave.inputRequired(name));
|
||||
continue;
|
||||
}
|
||||
if (row.from === "path") {
|
||||
const failure = preview?.failures?.find((f) => f.field_name === name);
|
||||
if (failure) out.push(`${name}: ${failure.reason}`);
|
||||
if (failure) out.push(errors.workflows.bindEvent.problem.inputFailed(name, failure.reason));
|
||||
continue;
|
||||
}
|
||||
const got = valueType(constantValue(row.value, type));
|
||||
if (type !== "any" && got !== type) out.push(`${name} is ${type}, but ${JSON.stringify(row.value)} is not`);
|
||||
if (type !== "any" && got !== type) out.push(errors.workflows.bindEvent.problem.inputType(name, type, JSON.stringify(row.value)));
|
||||
}
|
||||
if (preview?.failures?.some((f) => f.field_name === REPOSITORY_FIELD)) out.push("the repository path does not resolve");
|
||||
if (preview?.failures?.some((f) => f.field_name === REPOSITORY_FIELD)) out.push(errors.workflows.bindEvent.problem.repositoryUnresolved);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { isMap, isScalar, isSeq, parseDocument, visit } from "yaml";
|
||||
import { diffValues, pathSegments, type Change } from "../lib/changes.ts";
|
||||
import { errors } from "../copy/errors/index.ts";
|
||||
|
||||
/**
|
||||
* Canvas edits as edits to the workflow's YAML document. The text stays the
|
||||
@@ -61,7 +62,7 @@ export function insertStep(source: string, after: StepPath, type: string): { sou
|
||||
const document = parseDocument(source);
|
||||
const list = after.slice(0, -1);
|
||||
const inBranch = inParallel(list);
|
||||
if (inBranch && !["agent.run", "workflow.call"].includes(type)) throw new Error("Branches allow only read-only agents and workflow calls.");
|
||||
if (inBranch && !["agent.run", "workflow.call"].includes(type)) throw new Error(errors.workflows.edit.readOnlyBranch);
|
||||
let steps = document.getIn(list, true);
|
||||
if (!isSeq(steps)) {
|
||||
document.setIn(list, document.createNode([]));
|
||||
@@ -77,10 +78,10 @@ export function insertStep(source: string, after: StepPath, type: string): { sou
|
||||
|
||||
function checkBranchName(name: string, kind: Branching["kind"]): void {
|
||||
if (kind === "switch") {
|
||||
if (!name || name.includes("/")) throw new Error("A case is the value it matches, without a slash.");
|
||||
if (!name || name.includes("/")) throw new Error(errors.workflows.edit.caseValue);
|
||||
return;
|
||||
}
|
||||
if (!/^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/.test(name)) throw new Error("Use a lowercase branch name with letters, digits, dots or dashes.");
|
||||
if (!/^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/.test(name)) throw new Error(errors.workflows.edit.branchName);
|
||||
}
|
||||
|
||||
/** The map of a step's branches or cases, with what kind of step holds it. */
|
||||
@@ -88,7 +89,7 @@ function branchMap(document: ReturnType<typeof parseDocument>, path: StepPath) {
|
||||
const step = document.getIn(path, true);
|
||||
const branching = branchingOf(isMap(step) ? step.toJSON() : undefined);
|
||||
const branches = branching ? document.getIn([...path, ...branching.base], true) : undefined;
|
||||
if (!branching || !isMap(branches)) throw new Error("This step has no branches.");
|
||||
if (!branching || !isMap(branches)) throw new Error(errors.workflows.edit.noBranches);
|
||||
return { kind: branching.kind, branches };
|
||||
}
|
||||
|
||||
@@ -96,7 +97,7 @@ export function addBranch(source: string, path: StepPath, name: string): string
|
||||
const document = parseDocument(source);
|
||||
const { kind, branches } = branchMap(document, path);
|
||||
checkBranchName(name, kind);
|
||||
if (branches.has(name)) throw new Error(`Branch ${name} already exists.`);
|
||||
if (branches.has(name)) throw new Error(errors.workflows.edit.branchExists(name));
|
||||
branches.set(name, document.createNode([]));
|
||||
return document.toString();
|
||||
}
|
||||
@@ -105,9 +106,9 @@ export function renameBranch(source: string, path: StepPath, name: string, next:
|
||||
const document = parseDocument(source);
|
||||
const { kind, branches } = branchMap(document, path);
|
||||
checkBranchName(next, kind);
|
||||
if (name !== next && branches.has(next)) throw new Error(`Branch ${next} already exists.`);
|
||||
if (name !== next && branches.has(next)) throw new Error(errors.workflows.edit.branchExists(next));
|
||||
const pair = branches.items.find((pair) => isScalar(pair.key) && pair.key.value === name);
|
||||
if (!pair || !isScalar(pair.key)) throw new Error(`Branch ${name} does not exist.`);
|
||||
if (!pair || !isScalar(pair.key)) throw new Error(errors.workflows.edit.branchMissing(name));
|
||||
pair.key.value = next;
|
||||
return document.toString();
|
||||
}
|
||||
@@ -115,8 +116,8 @@ export function renameBranch(source: string, path: StepPath, name: string, next:
|
||||
export function deleteBranch(source: string, path: StepPath, name: string): string {
|
||||
const document = parseDocument(source);
|
||||
const { kind, branches } = branchMap(document, path);
|
||||
if (kind === "parallel" && branches.items.length <= 2) throw new Error("Parallel needs at least two branches.");
|
||||
if (branches.items.length <= 1) throw new Error("A switch needs at least one case.");
|
||||
if (kind === "parallel" && branches.items.length <= 2) throw new Error(errors.workflows.edit.parallelBranches);
|
||||
if (branches.items.length <= 1) throw new Error(errors.workflows.edit.switchCase);
|
||||
branches.delete(name);
|
||||
return document.toString();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import { computed, ref, watch, type Ref } from "vue";
|
||||
|
||||
import { useSettingsStore, type ResourceRevision } from "@/stores/settings";
|
||||
import { workflowRevisions } from "./workflow-revisions";
|
||||
import { describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
|
||||
const KIND = "workflow-definitions";
|
||||
|
||||
@@ -20,7 +22,7 @@ export function useWorkflowHistory(id: Ref<string>) {
|
||||
error.value = "";
|
||||
} catch (err) {
|
||||
if (current !== generation) return;
|
||||
error.value = err instanceof Error ? err.message : "Could not load history";
|
||||
error.value = describeError(err, errors.workflows.history.notLoaded);
|
||||
}
|
||||
}
|
||||
watch(() => store.stateFor(KIND).resource?.version, () => void reload(), { immediate: true });
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { computed, ref, shallowRef, watch, type Ref } from "vue";
|
||||
|
||||
import { api } from "@/lib/api";
|
||||
import { api, describeError } from "@/lib/api";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { keepRows } from "@/lib/keep-unchanged";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
import type { StageRun } from "./workflow-graph";
|
||||
@@ -51,7 +52,7 @@ export function useWorkflowRuns(workflow: Ref<string>) {
|
||||
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);
|
||||
if (workflow.value === requested && request === requestNumber) error.value = describeError(cause, errors.common.unknown);
|
||||
} finally {
|
||||
if (request === requestNumber) loading.value = false;
|
||||
}
|
||||
@@ -71,11 +72,11 @@ export function useWorkflowRuns(workflow: Ref<string>) {
|
||||
const requested = watched.value;
|
||||
let readError = "";
|
||||
const [view, debug] = await Promise.all([
|
||||
api.taskAttempts<AttemptsView>(requested).catch((err) => { readError = String((err as Error).message || err); return null; }),
|
||||
api.taskAttempts<AttemptsView>(requested).catch((err) => { readError = describeError(err, errors.common.unknown); return null; }),
|
||||
pinned.value === undefined ? api.taskDebug<DebugView>(requested).catch(() => null) : null,
|
||||
]);
|
||||
if (watched.value !== requested) return;
|
||||
stagesError.value = view === null ? readError || "Couldn't load the run's stages" : "";
|
||||
stagesError.value = view === null ? readError || errors.workflows.runs.stagesNotLoaded : "";
|
||||
if (debug) pinned.value = debug.task?.workflow_definition_yaml ?? "";
|
||||
const latest = [...(view?.attempts ?? [])].sort((a, b) => b.attempt - a.attempt)[0];
|
||||
// A live refresh that changed nothing must not redraw the canvas, which
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { computed, onMounted, ref, type Ref } from "vue";
|
||||
import { parse } from "yaml";
|
||||
|
||||
import { api } from "@/lib/api";
|
||||
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";
|
||||
@@ -148,12 +149,12 @@ export function useWorkflowTriggers(id: Ref<string>) {
|
||||
async function reload(): Promise<void> {
|
||||
let readError = "";
|
||||
const [response, listed] = await Promise.all([
|
||||
api.bindings<{ bindings?: Binding[] }>().catch((err) => { readError = String((err as Error).message || err); return null; }),
|
||||
api.schedules<{ schedules?: TriggerSources["schedules"] }>().catch((err) => { readError = String((err as Error).message || err); return null; }),
|
||||
api.bindings<{ bindings?: Binding[] }>().catch((err) => { readError = describeError(err, errors.common.unknown); return null; }),
|
||||
api.schedules<{ schedules?: TriggerSources["schedules"] }>().catch((err) => { readError = describeError(err, errors.common.unknown); return null; }),
|
||||
]);
|
||||
bindings.value = response?.bindings ?? [];
|
||||
schedules.value = listed?.schedules ?? [];
|
||||
error.value = response === null || listed === null ? readError || "Couldn't load triggers" : "";
|
||||
error.value = response === null || listed === null ? readError || errors.workflows.triggers.notLoaded : "";
|
||||
}
|
||||
onMounted(reload);
|
||||
const triggers = computed(() =>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { parseDocument } from "yaml";
|
||||
import { parseGoDuration } from "../components/ui/duration-input/duration.ts";
|
||||
import { branchingOf } from "./workflow-edit.ts";
|
||||
import { errors } from "../copy/errors/index.ts";
|
||||
|
||||
/**
|
||||
* The workflow YAML editor's reading of what is typed.
|
||||
@@ -46,7 +47,7 @@ export type WorkflowParse =
|
||||
/** What the editor's indicator reads. */
|
||||
export function validationLabel(parsed: WorkflowParse): string {
|
||||
if (parsed.ok) return "Valid";
|
||||
return parsed.line ? `Line ${parsed.line}: ${parsed.message}` : parsed.message;
|
||||
return parsed.line ? errors.workflows.yaml.line(parsed.line, parsed.message) : parsed.message;
|
||||
}
|
||||
|
||||
export function parseWorkflowYaml(
|
||||
@@ -65,7 +66,7 @@ export function parseWorkflowYaml(
|
||||
|
||||
const value: unknown = document.toJS();
|
||||
if (!isMapping(value)) {
|
||||
return { ok: false, message: "A workflow is a mapping with an id and steps." };
|
||||
return { ok: false, message: errors.workflows.yaml.notMapping };
|
||||
}
|
||||
|
||||
const id = typeof value.id === "string" ? value.id.trim() : "";
|
||||
@@ -172,12 +173,12 @@ function checkStepType(
|
||||
known: Map<string, StepTypeInfo>,
|
||||
repository: string,
|
||||
): string {
|
||||
if (!isMapping(step) || !isNonEmptyString(step.type)) return "Needs a type";
|
||||
if (!isMapping(step) || !isNonEmptyString(step.type)) return errors.workflows.yaml.stepNeedsType;
|
||||
const type = step.type.trim();
|
||||
const info = known.get(type);
|
||||
if (known.size && !info) return `Unknown step type "${type}"`;
|
||||
if (known.size && !info) return errors.workflows.yaml.unknownStepType(type);
|
||||
if (info?.needs_repository && repository !== "required")
|
||||
return `"${type}" needs a repository, but the workflow's repository is ${repository}`;
|
||||
return errors.workflows.yaml.needsRepository(type, repository);
|
||||
if (!info || step.settings === undefined || step.settings === null) return "";
|
||||
if (!info.settings) return `"${type}" takes no settings`;
|
||||
return settingsProblem(step.settings, info.settings, "settings");
|
||||
@@ -324,7 +325,7 @@ function scalarTokens(value: string): YamlToken[] {
|
||||
}
|
||||
|
||||
function firstLine(message: string): string {
|
||||
return message.split("\n")[0]?.trim() || "invalid YAML";
|
||||
return message.split("\n")[0]?.trim() || errors.workflows.yaml.invalid;
|
||||
}
|
||||
|
||||
function isMapping(value: unknown): value is Record<string, unknown> {
|
||||
|
||||
Reference in new issue
Block a user