feat(webui): block invalid settings and show a field's former value
The Settings save flow tracked dirty fields but did not consult validity:
each page validated in a local computed the save bar could not see, so an
invalid draft could be saved and the server refused it a round-trip later.
The rules now live once in ui/src/settings/validation.ts, the store derives
invalidFields from the same draft diff as dirtyKinds, and the save bar lists
the invalid fields and refuses Save. The route-leave guard still reads the
one dirty model, so the two can never disagree.
Every edited field also shows its former value inline ("was 1m0s") from the
same per-kind diff, via a new DraftHint component.
The per-kind diff is now a cached computed, so the hint, the save bar and
the guard share one computation per change instead of one per consumer.
This commit is contained in:
1 parent
97b8424f75
commit
ef82d6b8fa
15 files changed
+667
-208
No files matched your search
@@ -24,6 +24,7 @@ import {
|
||||
TagsInputItemText,
|
||||
} from "@/components/ui/tags-input";
|
||||
import { resourcesForPage, useControlPlaneStore } from "@/stores/control-plane";
|
||||
import DraftHint from "./DraftHint.vue";
|
||||
import HistoryLink from "./HistoryLink.vue";
|
||||
|
||||
const KIND = "container-runtime-policies";
|
||||
@@ -80,28 +81,46 @@ function addProfile() {
|
||||
|
||||
<template v-if="runtime">
|
||||
<SettingRow label="Image" for="cr-image">
|
||||
<Input id="cr-image" v-model="runtime.Image" class="font-mono" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input id="cr-image" v-model="runtime.Image" class="font-mono" />
|
||||
<DraftHint :kind="KIND" path="Image" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Pull policy">
|
||||
<SegmentedControl v-model="pullPolicy" label="Pull policy" :options="pullPolicies" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<SegmentedControl v-model="pullPolicy" label="Pull policy" :options="pullPolicies" />
|
||||
<DraftHint :kind="KIND" path="PullPolicy" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Max concurrency" hint="0 = no limit.">
|
||||
<NumberField v-model="runtime.MaxConcurrency" :min="0" class="w-32">
|
||||
<NumberFieldContent>
|
||||
<NumberFieldDecrement />
|
||||
<NumberFieldInput class="font-mono" aria-label="Max concurrency" />
|
||||
<NumberFieldIncrement />
|
||||
</NumberFieldContent>
|
||||
</NumberField>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<NumberField v-model="runtime.MaxConcurrency" :min="0" class="w-32">
|
||||
<NumberFieldContent>
|
||||
<NumberFieldDecrement />
|
||||
<NumberFieldInput class="font-mono" aria-label="Max concurrency" />
|
||||
<NumberFieldIncrement />
|
||||
</NumberFieldContent>
|
||||
</NumberField>
|
||||
<DraftHint :kind="KIND" path="MaxConcurrency" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Max uptime" for="cr-uptime">
|
||||
<DurationInput id="cr-uptime" v-model="runtime.MaxUptime" :units="['m', 'h']" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<DurationInput id="cr-uptime" v-model="runtime.MaxUptime" :units="['m', 'h']" />
|
||||
<DraftHint :kind="KIND" path="MaxUptime" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Volume retention" for="cr-ttl">
|
||||
<DurationInput id="cr-ttl" v-model="runtime.VolumeTTL" :units="['h']" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<DurationInput id="cr-ttl" v-model="runtime.VolumeTTL" :units="['h']" />
|
||||
<DraftHint :kind="KIND" path="VolumeTTL" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Network" for="cr-network" hint="Empty: auto-detect.">
|
||||
<Input id="cr-network" v-model="runtime.Network" class="max-w-sm font-mono" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input id="cr-network" v-model="runtime.Network" class="max-w-sm font-mono" />
|
||||
<DraftHint :kind="KIND" path="Network" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
|
||||
<h2 class="mt-10 mb-1 text-[11px] font-medium tracking-[0.06em] text-fg-subtle uppercase">Profiles</h2>
|
||||
@@ -116,21 +135,27 @@ function addProfile() {
|
||||
<Button variant="ghost" size="icon" :aria-label="`Remove profile ${name}`" @click="delete runtime.Profiles![name]"><Trash2 /></Button>
|
||||
</header>
|
||||
<SettingRow label="Image" :for="`prof-${name}-image`" hint="Empty: default image.">
|
||||
<Input :id="`prof-${name}-image`" v-model="profile.Image" class="font-mono" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input :id="`prof-${name}-image`" v-model="profile.Image" class="font-mono" />
|
||||
<DraftHint :kind="KIND" :path="`Profiles.${name}.Image`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Tools" hint="Empty allows all.">
|
||||
<TagsInput
|
||||
:model-value="profile.Tools ?? []"
|
||||
class="font-mono"
|
||||
:aria-label="`Tools for ${name}`"
|
||||
@update:model-value="(v) => (profile.Tools = v as string[])"
|
||||
>
|
||||
<TagsInputItem v-for="tool in profile.Tools ?? []" :key="tool" :value="tool">
|
||||
<TagsInputItemText />
|
||||
<TagsInputItemDelete />
|
||||
</TagsInputItem>
|
||||
<TagsInputInput placeholder="tool name" />
|
||||
</TagsInput>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<TagsInput
|
||||
:model-value="profile.Tools ?? []"
|
||||
class="font-mono"
|
||||
:aria-label="`Tools for ${name}`"
|
||||
@update:model-value="(v) => (profile.Tools = v as string[])"
|
||||
>
|
||||
<TagsInputItem v-for="tool in profile.Tools ?? []" :key="tool" :value="tool">
|
||||
<TagsInputItemText />
|
||||
<TagsInputItemDelete />
|
||||
</TagsInputItem>
|
||||
<TagsInputInput placeholder="tool name" />
|
||||
</TagsInput>
|
||||
<DraftHint :kind="KIND" :path="`Profiles.${name}.Tools`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
</section>
|
||||
<div class="flex gap-2">
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
|
||||
import { useControlPlaneStore } from "@/stores/control-plane";
|
||||
import { formatValue } from "./changes";
|
||||
|
||||
/**
|
||||
* The previous value of an edited field, inline at the control: "was 1m0s".
|
||||
*
|
||||
* It reads the same per-kind diff the save bar and the route guard read, so
|
||||
* the hint, the review drawer and the dirty count can never disagree about
|
||||
* whether a field changed.
|
||||
*/
|
||||
const props = defineProps<{ kind: string; path: string }>();
|
||||
const store = useControlPlaneStore();
|
||||
const change = computed(() => store.changeFor(props.kind, props.path));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span v-if="change" class="text-xs whitespace-nowrap text-fg-subtle">
|
||||
was <s class="font-mono">{{ formatValue(change.before) }}</s>
|
||||
</span>
|
||||
</template>
|
||||
@@ -6,6 +6,7 @@ import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { resourcesForPage, useControlPlaneStore } from "@/stores/control-plane";
|
||||
import DraftHint from "./DraftHint.vue";
|
||||
import HistoryLink from "./HistoryLink.vue";
|
||||
|
||||
const KIND = "plugin-settings";
|
||||
@@ -36,16 +37,28 @@ const error = computed(() => store.stateFor(KIND).error);
|
||||
|
||||
<template v-if="dirs">
|
||||
<SettingRow label="Plugin directory" for="pl-plugins">
|
||||
<Input id="pl-plugins" v-model="dirs.plugin_dir" class="max-w-md font-mono" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input id="pl-plugins" v-model="dirs.plugin_dir" class="max-w-md font-mono" />
|
||||
<DraftHint :kind="KIND" path="plugin_dir" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Module directory" for="pl-modules">
|
||||
<Input id="pl-modules" v-model="dirs.module_dir" class="max-w-md font-mono" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input id="pl-modules" v-model="dirs.module_dir" class="max-w-md font-mono" />
|
||||
<DraftHint :kind="KIND" path="module_dir" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Secret engine directory" for="pl-secrets" hint="Empty: built-in engines only.">
|
||||
<Input id="pl-secrets" v-model="dirs.secret_engine_dir" class="max-w-md font-mono" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input id="pl-secrets" v-model="dirs.secret_engine_dir" class="max-w-md font-mono" />
|
||||
<DraftHint :kind="KIND" path="secret_engine_dir" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Skills directory" for="pl-skills" hint="Empty: work directory.">
|
||||
<Input id="pl-skills" v-model="dirs.skills_dir" class="max-w-md font-mono" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input id="pl-skills" v-model="dirs.skills_dir" class="max-w-md font-mono" />
|
||||
<DraftHint :kind="KIND" path="skills_dir" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
@@ -18,6 +18,7 @@ import { SegmentedControl } from "@/components/ui/segmented-control";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { resourcesForPage, useControlPlaneStore } from "@/stores/control-plane";
|
||||
import DraftHint from "./DraftHint.vue";
|
||||
import HistoryLink from "./HistoryLink.vue";
|
||||
|
||||
const KIND = "schedules";
|
||||
@@ -41,6 +42,8 @@ onMounted(store.load);
|
||||
const resources = computed(() => resourcesForPage(catalog.value, "schedules"));
|
||||
const jobs = computed(() => store.drafts[KIND]?.value as Job[] | undefined);
|
||||
const error = computed(() => store.stateFor(KIND).error);
|
||||
const issues = computed(() => store.issuesFor(KIND));
|
||||
const jobIssue = (i: number) => issues.value.find((entry) => entry.path === `${i}.id`);
|
||||
|
||||
const whenKinds = [
|
||||
{ value: "interval", label: "Every" },
|
||||
@@ -114,13 +117,21 @@ const whenKind = (job: Job) => job.schedule.kind || "interval";
|
||||
<Button variant="ghost" size="icon" aria-label="Delete schedule" @click="jobs.splice(i, 1)"><Trash2 /></Button>
|
||||
</header>
|
||||
<SettingRow label="ID" :for="`job-${i}-id`">
|
||||
<Input :id="`job-${i}-id`" v-model="job.id" class="max-w-sm font-mono" :aria-invalid="!job.id.trim() || undefined" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input :id="`job-${i}-id`" v-model="job.id" class="max-w-sm font-mono" :aria-invalid="jobIssue(i) ? true : undefined" />
|
||||
<DraftHint :kind="KIND" :path="`${i}.id`" />
|
||||
</div>
|
||||
<p v-if="jobIssue(i)" class="mt-1.5 text-xs text-danger">{{ jobIssue(i)?.message }}</p>
|
||||
</SettingRow>
|
||||
<SettingRow label="Task title" :for="`job-${i}-title`" hint="Empty: the ID.">
|
||||
<Input :id="`job-${i}-title`" v-model="job.detail" class="max-w-md" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input :id="`job-${i}-title`" v-model="job.detail" class="max-w-md" />
|
||||
<DraftHint :kind="KIND" :path="`${i}.detail`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Instructions" :for="`job-${i}-text`">
|
||||
<Textarea :id="`job-${i}-text`" v-model="job.payload.text" :rows="3" />
|
||||
<DraftHint :kind="KIND" :path="`${i}.payload.text`" />
|
||||
</SettingRow>
|
||||
<SettingRow label="When">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
@@ -146,10 +157,18 @@ const whenKind = (job: Job) => job.schedule.kind || "interval";
|
||||
:model-value="toLocalInput(job.schedule.at)"
|
||||
@update:model-value="(v) => (job.schedule.at = fromLocalInput(String(v)))"
|
||||
/>
|
||||
<DraftHint
|
||||
:kind="KIND"
|
||||
:path="whenKind(job) === 'cron' ? `${i}.schedule.cron` : whenKind(job) === 'once' ? `${i}.schedule.at` : `${i}.schedule.interval`"
|
||||
/>
|
||||
<DraftHint :kind="KIND" :path="`${i}.schedule.kind`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Overlap">
|
||||
<SegmentedControl :model-value="job.pool ?? ''" label="Overlap" :options="pools" @update:model-value="(p: string) => (job.pool = p)" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<SegmentedControl :model-value="job.pool ?? ''" label="Overlap" :options="pools" @update:model-value="(p: string) => (job.pool = p)" />
|
||||
<DraftHint :kind="KIND" :path="`${i}.pool`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { computed, onMounted } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { DurationInput, parseGoDuration } from "@/components/ui/duration-input";
|
||||
import { DurationInput } from "@/components/ui/duration-input";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
NumberField,
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
import { SegmentedControl } from "@/components/ui/segmented-control";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { resourcesForPage, useControlPlaneStore } from "@/stores/control-plane";
|
||||
import DraftHint from "./DraftHint.vue";
|
||||
|
||||
const KIND = "scheduling-policy";
|
||||
|
||||
@@ -51,13 +52,10 @@ const states = [
|
||||
{ key: "dead", name: "Dead", swatch: "bg-danger" },
|
||||
];
|
||||
|
||||
const intervalInvalid = computed(() => {
|
||||
const ms = parseGoDuration(policy.value?.poll_interval ?? "");
|
||||
return ms === null || ms <= 0;
|
||||
});
|
||||
const labelMissing = computed(
|
||||
() => policy.value !== undefined && policy.value.dispatch.trigger !== "assignee" && !policy.value.label,
|
||||
);
|
||||
const issues = computed(() => store.issuesFor(KIND));
|
||||
const issue = (path: string) => issues.value.find((entry) => entry.path === path);
|
||||
const intervalIssue = computed(() => issue("poll_interval"));
|
||||
const labelIssue = computed(() => issue("label"));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -73,26 +71,35 @@ const labelMissing = computed(
|
||||
<template v-if="policy">
|
||||
<h2 class="mb-1 text-[11px] font-medium tracking-[0.06em] text-fg-subtle uppercase">Dispatch</h2>
|
||||
<SettingRow label="Trigger">
|
||||
<SegmentedControl v-model="policy.dispatch.trigger" label="Trigger" :options="triggers" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<SegmentedControl v-model="policy.dispatch.trigger" label="Trigger" :options="triggers" />
|
||||
<DraftHint :kind="KIND" path="dispatch.trigger" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow
|
||||
v-if="policy.dispatch.trigger !== 'assignee'"
|
||||
label="Label"
|
||||
for="sp-label"
|
||||
>
|
||||
<Input
|
||||
id="sp-label"
|
||||
:model-value="policy.label ?? ''"
|
||||
class="max-w-sm font-mono"
|
||||
:aria-invalid="labelMissing || undefined"
|
||||
@update:model-value="policy.label = String($event)"
|
||||
/>
|
||||
<p v-if="labelMissing" class="mt-1.5 text-xs text-danger">
|
||||
Required: an empty label matches every open issue.
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input
|
||||
id="sp-label"
|
||||
:model-value="policy.label ?? ''"
|
||||
class="max-w-sm font-mono"
|
||||
:aria-invalid="labelIssue ? true : undefined"
|
||||
@update:model-value="policy.label = String($event)"
|
||||
/>
|
||||
<DraftHint :kind="KIND" path="label" />
|
||||
</div>
|
||||
<p v-if="labelIssue" class="mt-1.5 text-xs text-danger">
|
||||
{{ labelIssue.message }}
|
||||
</p>
|
||||
</SettingRow>
|
||||
<SettingRow label="Ack reaction" for="sp-ack" hint="Empty: none.">
|
||||
<Input id="sp-ack" v-model="policy.dispatch.ack_reaction" class="max-w-xs font-mono" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input id="sp-ack" v-model="policy.dispatch.ack_reaction" class="max-w-xs font-mono" />
|
||||
<DraftHint :kind="KIND" path="dispatch.ack_reaction" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
|
||||
<h2 class="mt-10 mb-1 text-[11px] font-medium tracking-[0.06em] text-fg-subtle uppercase">State labels</h2>
|
||||
@@ -107,12 +114,15 @@ const labelMissing = computed(
|
||||
</span>
|
||||
</td>
|
||||
<td class="py-1.5">
|
||||
<Input
|
||||
:id="`sp-state-${state.key}`"
|
||||
:model-value="policy.dispatch.labels[state.key] ?? ''"
|
||||
class="font-mono"
|
||||
@update:model-value="policy.dispatch.labels[state.key] = String($event)"
|
||||
/>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input
|
||||
:id="`sp-state-${state.key}`"
|
||||
:model-value="policy.dispatch.labels[state.key] ?? ''"
|
||||
class="font-mono"
|
||||
@update:model-value="policy.dispatch.labels[state.key] = String($event)"
|
||||
/>
|
||||
<DraftHint :kind="KIND" :path="`dispatch.labels.${state.key}`" />
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -121,17 +131,23 @@ const labelMissing = computed(
|
||||
|
||||
<h2 class="mt-10 mb-1 text-[11px] font-medium tracking-[0.06em] text-fg-subtle uppercase">Retries and polling</h2>
|
||||
<SettingRow label="Max retries" hint="Then marked dead.">
|
||||
<NumberField v-model="policy.max_retries" :min="0" class="w-32">
|
||||
<NumberFieldContent>
|
||||
<NumberFieldDecrement />
|
||||
<NumberFieldInput class="font-mono" aria-label="Max retries" />
|
||||
<NumberFieldIncrement />
|
||||
</NumberFieldContent>
|
||||
</NumberField>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<NumberField v-model="policy.max_retries" :min="0" class="w-32">
|
||||
<NumberFieldContent>
|
||||
<NumberFieldDecrement />
|
||||
<NumberFieldInput class="font-mono" aria-label="Max retries" />
|
||||
<NumberFieldIncrement />
|
||||
</NumberFieldContent>
|
||||
</NumberField>
|
||||
<DraftHint :kind="KIND" path="max_retries" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Poll interval" for="sp-poll">
|
||||
<DurationInput id="sp-poll" v-model="policy.poll_interval" :units="['s', 'm', 'h']" />
|
||||
<p v-if="intervalInvalid" class="mt-1.5 text-xs text-danger">Must be longer than zero.</p>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<DurationInput id="sp-poll" v-model="policy.poll_interval" :units="['s', 'm', 'h']" />
|
||||
<DraftHint :kind="KIND" path="poll_interval" />
|
||||
</div>
|
||||
<p v-if="intervalIssue" class="mt-1.5 text-xs text-danger">{{ intervalIssue.message }}</p>
|
||||
</SettingRow>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ const sections = computed(() =>
|
||||
kind,
|
||||
title: titleOf(kind),
|
||||
changes: store.changesFor(kind),
|
||||
issues: store.issuesFor(kind),
|
||||
error: store.stateFor(kind).error,
|
||||
restart:
|
||||
store.catalog.find((item) => item.kind === kind)?.apply_mode ===
|
||||
@@ -35,6 +36,9 @@ const sections = computed(() =>
|
||||
const count = computed(() =>
|
||||
sections.value.reduce((n, s) => n + s.changes.length, 0),
|
||||
);
|
||||
// Invalid fields block Save, and are listed in the bar so the operator knows
|
||||
// before opening the review. Both read the store's one draft diff.
|
||||
const invalid = computed(() => store.invalidFields);
|
||||
const needsRestart = computed(() => sections.value.some((s) => s.restart));
|
||||
|
||||
function discardAll() {
|
||||
@@ -43,6 +47,7 @@ function discardAll() {
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (invalid.value.length) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
const outcome = await store.saveDrafts();
|
||||
@@ -56,17 +61,33 @@ async function save() {
|
||||
<template>
|
||||
<div
|
||||
v-if="count > 0"
|
||||
class="sticky bottom-4 z-30 mt-6 flex items-center gap-3 rounded-lg border border-border bg-popover px-4 py-3 shadow-[var(--shadow-md)]"
|
||||
class="sticky bottom-4 z-30 mt-6 rounded-lg border border-border bg-popover shadow-[var(--shadow-md)]"
|
||||
role="region"
|
||||
aria-label="Unsaved changes"
|
||||
>
|
||||
<span class="size-2 shrink-0 rounded-full bg-primary" aria-hidden="true" />
|
||||
<p class="min-w-0 flex-1 truncate text-sm">
|
||||
<span class="font-medium">{{ count }} unsaved {{ count === 1 ? "change" : "changes" }}</span>
|
||||
<span class="text-fg-subtle"> · {{ sections.map((s) => s.title).join(", ") }}</span>
|
||||
</p>
|
||||
<Button variant="ghost" size="sm" @click="discardAll">Discard</Button>
|
||||
<Button size="sm" @click="reviewing = true">Review and save</Button>
|
||||
<div class="flex items-center gap-3 px-4 py-3">
|
||||
<span
|
||||
class="size-2 shrink-0 rounded-full"
|
||||
:class="invalid.length ? 'bg-danger' : 'bg-primary'"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<p class="min-w-0 flex-1 truncate text-sm">
|
||||
<span class="font-medium">{{ count }} unsaved {{ count === 1 ? "change" : "changes" }}</span>
|
||||
<span class="text-fg-subtle"> · {{ sections.map((s) => s.title).join(", ") }}</span>
|
||||
</p>
|
||||
<Button variant="ghost" size="sm" @click="discardAll">Discard</Button>
|
||||
<Button size="sm" @click="reviewing = true">Review and save</Button>
|
||||
</div>
|
||||
<ul
|
||||
v-if="invalid.length"
|
||||
class="space-y-0.5 border-t border-danger/30 px-4 py-2 text-xs text-danger"
|
||||
role="alert"
|
||||
>
|
||||
<li v-for="issue in invalid" :key="`${issue.kind}.${issue.path}`">
|
||||
<span class="font-medium">{{ titleOf(issue.kind) }} · {{ issue.label }}</span>:
|
||||
{{ issue.message }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<Sheet v-model:open="reviewing">
|
||||
@@ -85,6 +106,13 @@ async function save() {
|
||||
>
|
||||
Some changes apply after restart.
|
||||
</p>
|
||||
<p
|
||||
v-if="invalid.length"
|
||||
class="rounded-md border border-danger/40 bg-danger-soft px-3 py-2 text-sm text-danger"
|
||||
role="alert"
|
||||
>
|
||||
{{ invalid.length }} invalid {{ invalid.length === 1 ? "field" : "fields" }} must be fixed before saving.
|
||||
</p>
|
||||
<section
|
||||
v-for="section in sections"
|
||||
:key="section.kind"
|
||||
@@ -104,6 +132,15 @@ async function save() {
|
||||
<p class="truncate text-ok">+ {{ formatValue(change.after) }}</p>
|
||||
</li>
|
||||
</ul>
|
||||
<ul
|
||||
v-if="section.issues.length"
|
||||
class="space-y-0.5 border-t border-border px-3 py-2 text-xs text-danger"
|
||||
role="alert"
|
||||
>
|
||||
<li v-for="issue in section.issues" :key="issue.path">
|
||||
<span class="font-medium">{{ issue.label }}</span>: {{ issue.message }}
|
||||
</li>
|
||||
</ul>
|
||||
<p v-if="section.error" class="border-t border-border px-3 py-2 text-sm text-danger" role="alert">
|
||||
{{ section.error }}
|
||||
</p>
|
||||
@@ -111,7 +148,7 @@ async function save() {
|
||||
</div>
|
||||
<SheetFooter class="flex-row justify-end gap-2 border-t border-border">
|
||||
<Button variant="ghost" @click="discardAll">Discard all</Button>
|
||||
<Button :disabled="saving" @click="save">
|
||||
<Button :disabled="saving || invalid.length > 0" @click="save">
|
||||
<Spinner v-if="saving" data-icon="inline-start" /> Save
|
||||
</Button>
|
||||
</SheetFooter>
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
} from "@/components/ui/select";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { resourcesForPage, useControlPlaneStore } from "@/stores/control-plane";
|
||||
import DraftHint from "./DraftHint.vue";
|
||||
import HistoryLink from "./HistoryLink.vue";
|
||||
import { availableProviders, roleModelOptions } from "./model-choices";
|
||||
import SecretRefField from "./SecretRefField.vue";
|
||||
@@ -85,8 +86,9 @@ function setEmbedding(provider: string, model: string) {
|
||||
embeddingModel.value = model;
|
||||
setRole("embedding", provider && model ? `${provider}/${model}` : "");
|
||||
}
|
||||
const roleValid = (model: string) => /^[^/\s]+\/\S+$/.test(model);
|
||||
const providerKnown = (model: string) => configuredIds.value.includes(model.split("/")[0]!);
|
||||
const roleIssues = computed(() => store.issuesFor("model-role-assignments"));
|
||||
const roleIssue = (role: string) => roleIssues.value.find((entry) => entry.path === role);
|
||||
|
||||
const newRole = ref("");
|
||||
function addRole() {
|
||||
@@ -158,10 +160,11 @@ const eyebrow = "mb-2 text-[11px] font-medium tracking-[0.06em] text-fg-subtle u
|
||||
list="role-models"
|
||||
class="max-w-md flex-1 font-mono"
|
||||
placeholder="unset"
|
||||
:aria-invalid="(roles[role] && !roleValid(roles[role])) || undefined"
|
||||
:aria-invalid="roleIssue(role) ? true : undefined"
|
||||
@update:model-value="(v) => setRole(role, String(v))"
|
||||
/>
|
||||
<span v-if="roles[role] && !roleValid(roles[role])" class="text-xs text-danger">Use provider/model.</span>
|
||||
<DraftHint kind="model-role-assignments" :path="role" />
|
||||
<span v-if="roleIssue(role)" class="text-xs text-danger">{{ roleIssue(role)?.message }}</span>
|
||||
<span v-else-if="roles[role] && !providerKnown(roles[role])" class="text-xs text-warn">Provider not configured.</span>
|
||||
</template>
|
||||
<Button v-if="!KNOWN_ROLES.includes(role)" variant="ghost" size="icon" class="ml-auto" :aria-label="`Remove role ${role}`" @click="delete roles[role]">
|
||||
@@ -192,15 +195,21 @@ const eyebrow = "mb-2 text-[11px] font-medium tracking-[0.06em] text-fg-subtle u
|
||||
</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
<SettingRow label="Class" class="border-t-0 pt-0">
|
||||
<Select v-model="provider.class">
|
||||
<SelectTrigger class="w-48 font-mono" :aria-label="`Class for ${name}`"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="c in CLASSES.includes(provider.class) ? CLASSES : [provider.class, ...CLASSES]" :key="c" :value="c">{{ c }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Select v-model="provider.class">
|
||||
<SelectTrigger class="w-48 font-mono" :aria-label="`Class for ${name}`"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="c in CLASSES.includes(provider.class) ? CLASSES : [provider.class, ...CLASSES]" :key="c" :value="c">{{ c }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<DraftHint kind="provider-settings" :path="`${name}.class`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Base URL" :for="`prov-${name}-url`" hint="Empty: provider default.">
|
||||
<Input :id="`prov-${name}-url`" v-model="provider.base_url" class="max-w-md font-mono" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input :id="`prov-${name}-url`" v-model="provider.base_url" class="max-w-md font-mono" />
|
||||
<DraftHint kind="provider-settings" :path="`${name}.base_url`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="API key">
|
||||
<SecretRefField
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
} from "@/components/ui/tags-input";
|
||||
import { resourcesForPage, useControlPlaneStore } from "@/stores/control-plane";
|
||||
import CommandListEditor from "./CommandListEditor.vue";
|
||||
import DraftHint from "./DraftHint.vue";
|
||||
import HistoryLink from "./HistoryLink.vue";
|
||||
|
||||
const KIND = "repository-policies";
|
||||
@@ -92,60 +93,86 @@ const protectOf = (repo: Repo) => repo.protect ?? [];
|
||||
<Button variant="ghost" size="icon" :aria-label="`Remove ${repo.owner}/${repo.name}`" @click="repos.splice(i, 1)"><Trash2 /></Button>
|
||||
</header>
|
||||
<SettingRow label="Base branch" :for="`repo-${i}-base`">
|
||||
<Input :id="`repo-${i}-base`" v-model="repo.base" class="max-w-56 font-mono" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input :id="`repo-${i}-base`" v-model="repo.base" class="max-w-56 font-mono" />
|
||||
<DraftHint :kind="KIND" :path="`${i}.base`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Ecosystem">
|
||||
<Select v-model="repo.ecosystem">
|
||||
<SelectTrigger class="w-40 font-mono" :aria-label="`Ecosystem for ${repo.name}`"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="e in ecosystems" :key="e" :value="e">{{ e }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Select v-model="repo.ecosystem">
|
||||
<SelectTrigger class="w-40 font-mono" :aria-label="`Ecosystem for ${repo.name}`"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="e in ecosystems" :key="e" :value="e">{{ e }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<DraftHint :kind="KIND" :path="`${i}.ecosystem`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Quality gate" hint="Last command runs the tests.">
|
||||
<CommandListEditor v-model="repo.gate" label="Gate" empty-text="No gate." />
|
||||
<DraftHint :kind="KIND" :path="`${i}.gate`" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Preflight" hint="Empty: ecosystem default.">
|
||||
<CommandListEditor v-model="repo.preflight" label="Preflight" empty-text="Ecosystem default." />
|
||||
<DraftHint :kind="KIND" :path="`${i}.preflight`" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Test files" :for="`repo-${i}-glob`" hint="Empty: ecosystem default.">
|
||||
<Input :id="`repo-${i}-glob`" v-model="repo.test_glob" class="max-w-56 font-mono" placeholder="*_test.go" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input :id="`repo-${i}-glob`" v-model="repo.test_glob" class="max-w-56 font-mono" placeholder="*_test.go" />
|
||||
<DraftHint :kind="KIND" :path="`${i}.test_glob`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Protected paths" hint="Suffixes agents never write.">
|
||||
<TagsInput
|
||||
:model-value="protectOf(repo)"
|
||||
class="font-mono"
|
||||
:aria-label="`Protected paths for ${repo.name}`"
|
||||
@update:model-value="(v) => (repo.protect = v as string[])"
|
||||
>
|
||||
<TagsInputItem v-for="p in protectOf(repo)" :key="p" :value="p">
|
||||
<TagsInputItemText />
|
||||
<TagsInputItemDelete />
|
||||
</TagsInputItem>
|
||||
<TagsInputInput placeholder="_templ.go" />
|
||||
</TagsInput>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<TagsInput
|
||||
:model-value="protectOf(repo)"
|
||||
class="font-mono"
|
||||
:aria-label="`Protected paths for ${repo.name}`"
|
||||
@update:model-value="(v) => (repo.protect = v as string[])"
|
||||
>
|
||||
<TagsInputItem v-for="p in protectOf(repo)" :key="p" :value="p">
|
||||
<TagsInputItemText />
|
||||
<TagsInputItemDelete />
|
||||
</TagsInputItem>
|
||||
<TagsInputInput placeholder="_templ.go" />
|
||||
</TagsInput>
|
||||
<DraftHint :kind="KIND" :path="`${i}.protect`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Max retries" hint="0 = scheduling policy value.">
|
||||
<NumberField v-model="repo.max_retries" :min="0" class="w-32">
|
||||
<NumberFieldContent>
|
||||
<NumberFieldDecrement />
|
||||
<NumberFieldInput class="font-mono" :aria-label="`Max retries for ${repo.name}`" />
|
||||
<NumberFieldIncrement />
|
||||
</NumberFieldContent>
|
||||
</NumberField>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<NumberField v-model="repo.max_retries" :min="0" class="w-32">
|
||||
<NumberFieldContent>
|
||||
<NumberFieldDecrement />
|
||||
<NumberFieldInput class="font-mono" :aria-label="`Max retries for ${repo.name}`" />
|
||||
<NumberFieldIncrement />
|
||||
</NumberFieldContent>
|
||||
</NumberField>
|
||||
<DraftHint :kind="KIND" :path="`${i}.max_retries`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Adversarial review">
|
||||
<Switch v-model="repo.review_enabled" :aria-label="`Adversarial review for ${repo.name}`" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Switch v-model="repo.review_enabled" :aria-label="`Adversarial review for ${repo.name}`" />
|
||||
<DraftHint :kind="KIND" :path="`${i}.review_enabled`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Persistent storage" hint="Kept across tasks.">
|
||||
<Switch v-model="repo.persistent_storage" :aria-label="`Persistent storage for ${repo.name}`" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Switch v-model="repo.persistent_storage" :aria-label="`Persistent storage for ${repo.name}`" />
|
||||
<DraftHint :kind="KIND" :path="`${i}.persistent_storage`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow
|
||||
label="Concurrent tasks"
|
||||
hint="Only if worktrees cannot collide."
|
||||
:tone="repo.allow_concurrent ? 'danger' : 'default'"
|
||||
>
|
||||
<Switch v-model="repo.allow_concurrent" :aria-label="`Concurrent tasks for ${repo.name}`" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Switch v-model="repo.allow_concurrent" :aria-label="`Concurrent tasks for ${repo.name}`" />
|
||||
<DraftHint :kind="KIND" :path="`${i}.allow_concurrent`" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
} from "@/components/ui/number-field";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { resourcesForPage, useControlPlaneStore } from "@/stores/control-plane";
|
||||
import DraftHint from "./DraftHint.vue";
|
||||
import HistoryLink from "./HistoryLink.vue";
|
||||
|
||||
const KIND = "workflow-execution-settings";
|
||||
@@ -58,28 +59,40 @@ const taskRuntime = seconds("max_task_runtime_seconds");
|
||||
|
||||
<template v-if="limits">
|
||||
<SettingRow label="Task time limit" for="te-task" hint="Parked after this. 0 disables.">
|
||||
<DurationInput id="te-task" v-model="taskRuntime" :units="['m', 'h']" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<DurationInput id="te-task" v-model="taskRuntime" :units="['m', 'h']" />
|
||||
<DraftHint :kind="KIND" path="max_task_runtime_seconds" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Agent call time limit" for="te-call" hint="0 disables.">
|
||||
<DurationInput id="te-call" v-model="callRuntime" :units="['s', 'm', 'h']" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<DurationInput id="te-call" v-model="callRuntime" :units="['s', 'm', 'h']" />
|
||||
<DraftHint :kind="KIND" path="max_runtime_seconds" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Model tool steps" hint="Per agent call. 0 disables.">
|
||||
<NumberField v-model="limits.max_model_tool_steps" :min="0" class="w-32">
|
||||
<NumberFieldContent>
|
||||
<NumberFieldDecrement />
|
||||
<NumberFieldInput class="font-mono" aria-label="Model tool steps" />
|
||||
<NumberFieldIncrement />
|
||||
</NumberFieldContent>
|
||||
</NumberField>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<NumberField v-model="limits.max_model_tool_steps" :min="0" class="w-32">
|
||||
<NumberFieldContent>
|
||||
<NumberFieldDecrement />
|
||||
<NumberFieldInput class="font-mono" aria-label="Model tool steps" />
|
||||
<NumberFieldIncrement />
|
||||
</NumberFieldContent>
|
||||
</NumberField>
|
||||
<DraftHint :kind="KIND" path="max_model_tool_steps" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Gate failures in a row" hint="In a row, then parked.">
|
||||
<NumberField v-model="limits.max_consecutive_gate_failures" :min="0" class="w-32">
|
||||
<NumberFieldContent>
|
||||
<NumberFieldDecrement />
|
||||
<NumberFieldInput class="font-mono" aria-label="Gate failures in a row" />
|
||||
<NumberFieldIncrement />
|
||||
</NumberFieldContent>
|
||||
</NumberField>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<NumberField v-model="limits.max_consecutive_gate_failures" :min="0" class="w-32">
|
||||
<NumberFieldContent>
|
||||
<NumberFieldDecrement />
|
||||
<NumberFieldInput class="font-mono" aria-label="Gate failures in a row" />
|
||||
<NumberFieldIncrement />
|
||||
</NumberFieldContent>
|
||||
</NumberField>
|
||||
<DraftHint :kind="KIND" path="max_consecutive_gate_failures" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { resourcesForPage, useControlPlaneStore } from "@/stores/control-plane";
|
||||
import DraftHint from "./DraftHint.vue";
|
||||
import McpServerEditor, { type McpServer } from "./McpServerEditor.vue";
|
||||
import SecretRefField from "./SecretRefField.vue";
|
||||
|
||||
@@ -95,7 +96,10 @@ const eyebrow = "mb-1 text-[11px] font-medium tracking-[0.06em] text-fg-subtle u
|
||||
|
||||
<h2 :class="[eyebrow, 'mt-10']">MiniMax</h2>
|
||||
<SettingRow label="Enabled">
|
||||
<Switch v-model="tools.minimax.enabled" aria-label="MiniMax enabled" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Switch v-model="tools.minimax.enabled" aria-label="MiniMax enabled" />
|
||||
<DraftHint :kind="KIND" path="minimax.enabled" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="API key">
|
||||
<SecretRefField
|
||||
@@ -107,37 +111,55 @@ const eyebrow = "mb-1 text-[11px] font-medium tracking-[0.06em] text-fg-subtle u
|
||||
|
||||
<h2 :class="[eyebrow, 'mt-10']">Web fetch</h2>
|
||||
<SettingRow label="Enabled">
|
||||
<Switch v-model="webFetchOn" aria-label="Web fetch enabled" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Switch v-model="webFetchOn" aria-label="Web fetch enabled" />
|
||||
<DraftHint :kind="KIND" path="web_fetch.enabled" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Max download" for="wf-bytes">
|
||||
<ByteSizeInput id="wf-bytes" v-model="tools.web_fetch.max_bytes" :disabled="!webFetchOn" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<ByteSizeInput id="wf-bytes" v-model="tools.web_fetch.max_bytes" :disabled="!webFetchOn" />
|
||||
<DraftHint :kind="KIND" path="web_fetch.max_bytes" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Timeout" for="wf-timeout">
|
||||
<DurationInput id="wf-timeout" v-model="tools.web_fetch.timeout" :units="['s', 'm']" :disabled="!webFetchOn" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<DurationInput id="wf-timeout" v-model="tools.web_fetch.timeout" :units="['s', 'm']" :disabled="!webFetchOn" />
|
||||
<DraftHint :kind="KIND" path="web_fetch.timeout" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow
|
||||
label="Allow private networks"
|
||||
hint="Reaches this host's dashboard and Docker API."
|
||||
:tone="tools.web_fetch.allow_private_networks ? 'danger' : 'default'"
|
||||
>
|
||||
<Switch
|
||||
v-model="tools.web_fetch.allow_private_networks"
|
||||
aria-label="Allow private networks"
|
||||
:disabled="!webFetchOn"
|
||||
/>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Switch
|
||||
v-model="tools.web_fetch.allow_private_networks"
|
||||
aria-label="Allow private networks"
|
||||
:disabled="!webFetchOn"
|
||||
/>
|
||||
<DraftHint :kind="KIND" path="web_fetch.allow_private_networks" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
|
||||
<h2 :class="[eyebrow, 'mt-10']">Tool output</h2>
|
||||
<SettingRow label="Max result length" for="tp-chars" :hint="`≈ ${Math.round(tools.policy.max_result_chars / 4).toLocaleString()} tokens`">
|
||||
<InputGroup class="w-48">
|
||||
<InputGroupInput id="tp-chars" v-model.number="tools.policy.max_result_chars" type="number" min="0" class="font-mono" />
|
||||
<InputGroupAddon align="inline-end">
|
||||
<InputGroupText class="font-mono text-xs">chars</InputGroupText>
|
||||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<InputGroup class="w-48">
|
||||
<InputGroupInput id="tp-chars" v-model.number="tools.policy.max_result_chars" type="number" min="0" class="font-mono" />
|
||||
<InputGroupAddon align="inline-end">
|
||||
<InputGroupText class="font-mono text-xs">chars</InputGroupText>
|
||||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
<DraftHint :kind="KIND" path="policy.max_result_chars" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
<SettingRow label="Spill directory" for="tp-spill" hint="Empty: truncate.">
|
||||
<Input id="tp-spill" v-model="tools.policy.spill_dir" class="max-w-md font-mono" />
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Input id="tp-spill" v-model="tools.policy.spill_dir" class="max-w-md font-mono" />
|
||||
<DraftHint :kind="KIND" path="policy.spill_dir" />
|
||||
</div>
|
||||
</SettingRow>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
import { parseGoDuration } from "../components/ui/duration-input/duration.ts";
|
||||
|
||||
/**
|
||||
* Client-side validation for the settings drafts.
|
||||
*
|
||||
* The server validates every replace, so this is not the only line of
|
||||
* defence: it exists so Save can be refused before the round-trip and the
|
||||
* operator sees the reason beside the field. The rules mirror the server's
|
||||
* (internal/app/controlplane), and the same map is read by the store, the
|
||||
* save bar and the pages' inline messages, so a rule is written once.
|
||||
*/
|
||||
|
||||
/** One field that must be fixed before its section can be saved. `path` is the
|
||||
* dotted leaf path diffValues reports, so an issue lines up with its change. */
|
||||
export interface FieldIssue {
|
||||
path: string;
|
||||
label: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
/** A section's rule: the draft value in, everything blocking a save out. */
|
||||
export type DraftValidator = (value: unknown) => FieldIssue[];
|
||||
|
||||
/** An issue with the section it was found in. */
|
||||
export interface BlockingField extends FieldIssue {
|
||||
kind: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* collectIssues runs each dirty section's validator against its draft. It is
|
||||
* driven by the dirty list on purpose: a section with no changes is not
|
||||
* blocked, so a value the server already accepted can never stop an unrelated
|
||||
* save.
|
||||
*/
|
||||
export function collectIssues(
|
||||
dirtyKinds: readonly string[],
|
||||
draftValue: (kind: string) => unknown,
|
||||
validators: Record<string, DraftValidator | undefined>,
|
||||
): BlockingField[] {
|
||||
return dirtyKinds.flatMap((kind) => {
|
||||
const validate = validators[kind];
|
||||
if (!validate) return [];
|
||||
return validate(draftValue(kind)).map((issue) => ({ ...issue, kind }));
|
||||
});
|
||||
}
|
||||
|
||||
interface SchedulingDraft {
|
||||
poll_interval?: string;
|
||||
label?: string | null;
|
||||
dispatch?: { trigger?: string };
|
||||
}
|
||||
|
||||
/** validateSchedulingPolicy mirrors validateScheduling: a positive interval
|
||||
* and the label a label/either trigger requires. */
|
||||
export function validateSchedulingPolicy(value: unknown): FieldIssue[] {
|
||||
const policy = (value ?? {}) as SchedulingDraft;
|
||||
const issues: FieldIssue[] = [];
|
||||
const ms = parseGoDuration(policy.poll_interval ?? "");
|
||||
if (ms === null || ms <= 0)
|
||||
issues.push({
|
||||
path: "poll_interval",
|
||||
label: "Poll interval",
|
||||
message: "Must be longer than zero.",
|
||||
});
|
||||
const trigger = policy.dispatch?.trigger;
|
||||
if (trigger && trigger !== "assignee" && !policy.label?.trim())
|
||||
issues.push({
|
||||
path: "label",
|
||||
label: "Label",
|
||||
message: "Required when the trigger is label or either.",
|
||||
});
|
||||
return issues;
|
||||
}
|
||||
|
||||
interface ScheduleDraft {
|
||||
id?: string;
|
||||
}
|
||||
|
||||
/** validateSchedules mirrors validateSchedules: an ID on every job, and no two
|
||||
* jobs sharing one. */
|
||||
export function validateSchedules(value: unknown): FieldIssue[] {
|
||||
const jobs = Array.isArray(value) ? (value as ScheduleDraft[]) : [];
|
||||
const issues: FieldIssue[] = [];
|
||||
const seen = new Set<string>();
|
||||
jobs.forEach((job, i) => {
|
||||
const id = job.id?.trim() ?? "";
|
||||
if (!id) {
|
||||
issues.push({ path: `${i}.id`, label: `Schedule ${i + 1}`, message: "ID is required." });
|
||||
return;
|
||||
}
|
||||
if (seen.has(id))
|
||||
issues.push({ path: `${i}.id`, label: `Schedule ${i + 1}`, message: `Duplicate schedule "${id}".` });
|
||||
seen.add(id);
|
||||
});
|
||||
return issues;
|
||||
}
|
||||
|
||||
/** The runtime resolves a role as provider/model, so a value with no "/" is
|
||||
* one the server will refuse. */
|
||||
const ROLE_MODEL = /^[^/\s]+\/\S+$/;
|
||||
|
||||
/** validateModelRoles mirrors validateModelRoles: every role names a model as
|
||||
* provider/model. */
|
||||
export function validateModelRoles(value: unknown): FieldIssue[] {
|
||||
const roles = (value ?? {}) as Record<string, string>;
|
||||
return Object.entries(roles)
|
||||
.filter(([, model]) => model && !ROLE_MODEL.test(model))
|
||||
.map(([role]) => ({ path: role, label: role, message: "Use provider/model." }));
|
||||
}
|
||||
|
||||
/** The rules the store applies to a dirty draft, keyed by resource kind. */
|
||||
export const draftValidators: Record<string, DraftValidator> = {
|
||||
"scheduling-policy": validateSchedulingPolicy,
|
||||
schedules: validateSchedules,
|
||||
"model-role-assignments": validateModelRoles,
|
||||
};
|
||||
@@ -3,6 +3,12 @@ import { computed, onScopeDispose, reactive, ref, watch } from "vue";
|
||||
import { useLiveUpdatesStore } from "./live-updates.ts";
|
||||
|
||||
import { diffValues, saveInOrder, type Change } from "../settings/changes.ts";
|
||||
import {
|
||||
collectIssues,
|
||||
draftValidators,
|
||||
type BlockingField,
|
||||
type FieldIssue,
|
||||
} from "../settings/validation.ts";
|
||||
|
||||
export interface ResourceDescriptor {
|
||||
kind: string;
|
||||
@@ -288,9 +294,24 @@ export const useControlPlaneStore = defineStore("control-plane", () => {
|
||||
drafts[kind] = { base: resource, value: cloneControlPlaneValue(resource.value) };
|
||||
}
|
||||
|
||||
// The diff for every draft, computed once per change. The save bar, the
|
||||
// inline "was old" hint, the inline errors and the route guard all read
|
||||
// this one map, so no consumer forks its own notion of what is dirty.
|
||||
const changesByKind = computed<Record<string, Change[]>>(() => {
|
||||
const byKind: Record<string, Change[]> = {};
|
||||
for (const [kind, draft] of Object.entries(drafts))
|
||||
byKind[kind] = diffValues(draft.base.value, draft.value);
|
||||
return byKind;
|
||||
});
|
||||
|
||||
function changesFor(kind: string): Change[] {
|
||||
const draft = drafts[kind];
|
||||
return draft ? diffValues(draft.base.value, draft.value) : [];
|
||||
return changesByKind.value[kind] ?? [];
|
||||
}
|
||||
|
||||
/** The change for one dotted leaf path, the lookup the inline "was old"
|
||||
* hint uses. */
|
||||
function changeFor(kind: string, path: string): Change | undefined {
|
||||
return changesFor(kind).find((change) => change.path === path);
|
||||
}
|
||||
|
||||
const dirtyKinds = computed(() =>
|
||||
@@ -299,6 +320,20 @@ export const useControlPlaneStore = defineStore("control-plane", () => {
|
||||
.filter((kind) => changesFor(kind).length > 0),
|
||||
);
|
||||
|
||||
/** Invalid fields across every dirty section. Derived from dirtyKinds, so a
|
||||
* save can only be blocked by a section that has something to save. */
|
||||
const invalidFields = computed<BlockingField[]>(() =>
|
||||
collectIssues(dirtyKinds.value, (kind) => drafts[kind]?.value, draftValidators),
|
||||
);
|
||||
|
||||
/** The issues for one section, empty unless it has unsaved changes. The
|
||||
* pages read this, so an inline error and the save bar can never disagree. */
|
||||
function issuesFor(kind: string): FieldIssue[] {
|
||||
if (changesFor(kind).length === 0) return [];
|
||||
const validate = draftValidators[kind];
|
||||
return validate ? validate(drafts[kind]?.value) : [];
|
||||
}
|
||||
|
||||
async function saveDraft(kind: string): Promise<boolean> {
|
||||
const draft = drafts[kind];
|
||||
if (!draft) return true;
|
||||
@@ -450,7 +485,10 @@ export const useControlPlaneStore = defineStore("control-plane", () => {
|
||||
return {
|
||||
applyStatusFor,
|
||||
changesFor,
|
||||
changeFor,
|
||||
dirtyKinds,
|
||||
invalidFields,
|
||||
issuesFor,
|
||||
drafts,
|
||||
resetDraft,
|
||||
saveDrafts,
|
||||
|
||||
Reference in new issue
Block a user