fix(ui): restore staged review for models and instructions

Apply reviewed edits through the module APIs one request at a time. Keep failed and untouched drafts for retry, and remove successful edits from the review.

(cherry picked from commit 952215e36325b76f6e3364d713263f502acf6d02)
This commit is contained in:
sam committed 2026-11-27 15:51:34 +11:00
1 parent a2141ed4bb
commit f6eff43ca4
7 files changed
+420 -198

No files matched your search

+41 -60
View File
@@ -1,76 +1,57 @@
<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import { Check } from "@lucide/vue";
import { computed, onMounted, watch } from "vue";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { Section } from "@/components/ui/section";
import { Textarea } from "@/components/ui/textarea";
import PageHeader from "@/base/PageHeader.vue";
import { api, describeError } from "@/lib/api";
import { api } from "@/lib/api";
import { useRead } from "@/lib/use-read";
import { useSettingsStore } from "@/stores/settings";
// The server refuses more than this; it joins every agent's system prompt.
const KIND = "org-instructions";
const MAX_BYTES = 8192;
const store = useSettingsStore();
const { data, error, reload } = useRead(api.instructions);
watch(data, (saved) => {
if (saved === undefined) return;
store.trackModuleSetting(KIND, {
title: "Instructions",
saved,
read: api.instructions,
write: ({ text }) => api.saveInstructions(text),
validate: ({ text }) => new TextEncoder().encode(text).length <= MAX_BYTES ? [] : [
{ path: "text", label: "Instructions", message: "Must be at most 8 KiB." },
],
});
});
onMounted(reload);
const saved = ref<string | null>(null);
const text = ref("");
const error = ref("");
const busy = ref(false);
const justSaved = ref(false);
const dirty = computed(() => saved.value !== null && text.value !== saved.value);
const draft = computed(() => store.draftValue(KIND) as { text: string } | undefined);
const text = computed({
get: () => draft.value?.text ?? "",
set: (value: string) => store.setDraftValue(KIND, { text: value }),
});
const chars = computed(() => text.value.length);
const tooLong = computed(() => new TextEncoder().encode(text.value).length > MAX_BYTES);
async function load() {
try {
const body = await api.instructions();
saved.value = text.value = body.text;
} catch (cause) {
error.value = describeError(cause, "Could not load the instructions.");
}
}
async function save() {
busy.value = true;
error.value = "";
justSaved.value = false;
try {
const body = await api.saveInstructions(text.value);
saved.value = text.value = body.text;
justSaved.value = true;
} catch (cause) {
error.value = describeError(cause, "Could not save the instructions.");
} finally {
busy.value = false;
}
}
onMounted(load);
const saveError = computed(() => store.pageErrorFor(KIND));
</script>
<template>
<div>
<PageHeader title="Instructions" />
<Alert v-if="error" variant="destructive" class="mb-4"><AlertDescription>{{ error }}</AlertDescription></Alert>
<form v-if="saved !== null" @submit.prevent="save">
<Section>
<Textarea
id="instructions-text"
v-model="text"
:rows="18"
class="mt-1 font-mono text-label"
aria-label="Instructions"
:aria-invalid="tooLong"
@input="justSaved = false"
/>
<p class="mt-1.5 text-caption text-fg-subtle">
{{ chars.toLocaleString() }} chars · ~{{ Math.round(chars / 4).toLocaleString() }} tokens
</p>
</Section>
<div class="mt-3 flex items-center justify-end gap-2">
<Check v-if="justSaved" role="status" aria-label="Saved" class="size-4 text-fg-muted" />
<Button type="submit" :disabled="busy || !dirty || tooLong">Save</Button>
</div>
</form>
<Alert v-if="error || saveError" variant="destructive" class="mb-4"><AlertDescription>{{ error || saveError }}</AlertDescription></Alert>
<Section v-if="draft">
<Textarea
id="instructions-text"
v-model="text"
:rows="18"
class="mt-1 font-mono text-label"
aria-label="Instructions"
:aria-invalid="store.issuesFor(KIND).length > 0"
:disabled="store.savingDrafts"
/>
<p class="mt-1.5 text-caption text-fg-subtle">
{{ chars.toLocaleString() }} chars · ~{{ Math.round(chars / 4).toLocaleString() }} tokens
</p>
</Section>
</div>
</template>
+11 -15
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { Alert, AlertDescription } from "@/components/ui/alert";
import { computed, onUnmounted, ref } from "vue";
import { computed, onUnmounted } from "vue";
import { storeToRefs } from "pinia";
import { Button } from "@/components/ui/button";
@@ -22,12 +22,11 @@ import { diffValues } from "@/lib/changes";
import type { SettingsSchema } from "@/workflows/workflow-yaml";
const store = useSettingsStore();
const { reviewing } = storeToRefs(store);
const { reviewing, savingDrafts: saving } = storeToRefs(store);
onUnmounted(() => { reviewing.value = false; });
const saving = ref(false);
const titleOf = (kind: string) =>
store.catalog.find((item) => item.kind === kind)?.title ?? kind;
store.moduleTitle(kind) ?? store.catalog.find((item) => item.kind === kind)?.title ?? kind;
function fieldLabel(kind: string, path: string): string {
let schema: SettingsSchema;
try { schema = JSON.parse(store.catalog.find((item) => item.kind === kind)?.schema_json || "{}"); }
@@ -68,14 +67,9 @@ function discardAll() {
}
async function save() {
if (invalid.value.length) return;
saving.value = true;
try {
const outcome = await store.saveDrafts();
if (!outcome.failed) reviewing.value = false;
} finally {
saving.value = false;
}
if (saving.value || invalid.value.length) return;
const outcome = await store.saveDrafts();
if (!outcome.failed) reviewing.value = false;
}
</script>
@@ -92,7 +86,7 @@ async function save() {
<span class="font-medium">{{ count }} unsaved settings {{ 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 variant="ghost" size="sm" :disabled="saving" @click="discardAll">Discard</Button>
<Button size="sm" @click="reviewing = true">Review and save</Button>
</div>
<ul
@@ -113,6 +107,7 @@ async function save() {
<SheetTitle>Review {{ count }} {{ count === 1 ? "change" : "changes" }}</SheetTitle>
<SheetDescription>
{{ sections.length }} {{ sections.length === 1 ? "section" : "sections" }}
<template v-if="sections.length > 1"> · Saved separately; stops at the first failure.</template>
</SheetDescription>
</SheetHeader>
<div class="flex-1 space-y-3 overflow-y-auto px-4 pb-4">
@@ -123,12 +118,13 @@ async function save() {
<template #action>
<div class="flex items-center gap-2">
<Badge v-if="section.restart" variant="warn">After restart</Badge>
<Button variant="ghost" size="sm" @click="store.resetDraft(section.kind)">Revert</Button>
<Button variant="ghost" size="sm" :disabled="saving" @click="store.resetDraft(section.kind)">Revert</Button>
</div>
</template>
<ChangeList
:changes="section.changes"
:label="(path) => fieldLabel(section.kind, path)"
:revertable="!saving"
@revert="(change) => store.revertDraftChange(section.kind, change)"
/>
<ul v-if="section.issues.length" class="mt-2 space-y-0.5 text-caption text-danger" role="alert">
@@ -140,7 +136,7 @@ async function save() {
</Section>
</div>
<SheetFooter class="flex-row justify-end gap-2 border-t border-border">
<Button variant="ghost" @click="discardAll">Discard all</Button>
<Button variant="ghost" :disabled="saving" @click="discardAll">Discard all</Button>
<Button :disabled="saving || invalid.length > 0" @click="save">
<Spinner v-if="saving" data-icon="inline-start" />Save</Button>
</SheetFooter>
+118 -97
View File
@@ -11,11 +11,13 @@ import { Label } from "@/components/ui/label";
import { Section } from "@/components/ui/section";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Spinner } from "@/components/ui/spinner";
import { api, describeError, type AgentModel, type ModelProvider } from "@/lib/api";
import { api, describeError, type AgentModel, type ModelPolicy, type ModelProvider } from "@/lib/api";
import { useRead } from "@/lib/use-read";
import { errors } from "@/copy/errors";
import { useSettingsStore } from "@/stores/settings";
import { canCreateProvider, providerInput } from "./provider-input.ts";
const store = useSettingsStore();
const providers = useRead(() => api.modelProviders());
const models = useRead(() => api.agentModels());
const classes = useRead(() => api.modelClasses());
@@ -37,11 +39,14 @@ const classNames = computed(() => classList.value.map((entry) => entry.class));
const bearerCredentials = computed(() =>
(credentials.data.value ?? []).filter((entry) => entry.kind === "bearer" && entry.scope !== "person"),
);
const modelMap = computed(() => models.data.value ?? {});
const hasModels = computed(() => models.data.value !== undefined);
const hasProviders = computed(() => providers.data.value !== undefined);
const policyData = computed(() => policy.data.value);
const errorOf = (...reads: { error: { value: string } }[]) => reads.map((read) => read.error.value).find(Boolean) ?? "";
const saveError = computed(() => store.moduleKinds
.filter((kind) => kind.startsWith("model"))
.map(store.pageErrorFor)
.find(Boolean));
const error = ref("");
async function run(act: () => Promise<void>): Promise<boolean> {
@@ -60,17 +65,37 @@ interface AliasForm {
provider_id: string;
model: string;
}
const aliasEdits = ref<Record<string, AliasForm>>({});
const addedAliases = ref<string[]>([]);
const formOf = (model?: AgentModel): AliasForm => ({ provider_id: model?.provider_id ?? "", model: model?.model ?? "" });
const aliasPrefix = "model-alias/";
const aliasKind = (alias: string) => `${aliasPrefix}${alias}`;
const storedAlias = (alias: string) => store.moduleSaved(aliasKind(alias)) as AliasForm | undefined;
function trackAlias(alias: string, model?: AgentModel): void {
store.trackModuleSetting(aliasKind(alias), {
title: `Model alias: ${alias}`,
saved: formOf(model),
read: async () => formOf((await api.agentModels())[alias]),
write: async (value) => formOf(await api.putAgentModel(alias === "default" ? "" : alias, value)),
validate: (value) => [
...(!value.provider_id ? [{ path: "provider_id", label: "Provider", message: "Select a provider." }] : []),
...(!value.model.trim() ? [{ path: "model", label: "Model", message: "Enter a model." }] : []),
],
});
}
const trackedAliases = computed(() => store.moduleKinds
.filter((kind) => kind.startsWith(aliasPrefix)).map((kind) => kind.slice(aliasPrefix.length)));
watch(models.data, (rows) => {
const next: Record<string, AliasForm> = {};
for (const [alias, model] of Object.entries(rows ?? {})) next[alias] = aliasEdits.value[alias] ?? formOf(model);
for (const alias of ["default", ...addedAliases.value]) next[alias] ??= aliasEdits.value[alias] ?? formOf();
aliasEdits.value = next;
if (!rows) return;
for (const alias of new Set(["default", ...Object.keys(rows), ...trackedAliases.value])) trackAlias(alias, rows[alias]);
});
const aliases = computed(() => [...new Set(["default", ...Object.keys(models.data.value ?? {}), ...addedAliases.value])]);
const aliasField = (alias: string): AliasForm => (aliasEdits.value[alias] ??= formOf());
const aliases = computed(() => [...new Set(["default", ...addedAliases.value,
...trackedAliases.value.filter((alias) => storedAlias(alias)?.model || store.changesFor(aliasKind(alias)).length),
])]);
const aliasField = (alias: string) => (store.draftValue(aliasKind(alias)) as AliasForm | undefined) ?? formOf();
function editAlias(alias: string, field: keyof AliasForm, value: string): void {
if (!hasModels.value || aliasBusy.value) return;
store.setDraftValue(aliasKind(alias), { ...aliasField(alias), [field]: value });
}
const aliasBusy = ref("");
const aliasError = ref<Record<string, string>>({});
const tested = ref<Record<string, string>>({});
@@ -85,13 +110,6 @@ async function aliasRun(alias: string, act: () => Promise<void>): Promise<void>
aliasBusy.value = "";
}
}
const saveAlias = (alias: string) =>
aliasRun(alias, async () => {
const field = aliasField(alias);
await api.putAgentModel(alias === "default" ? "" : alias, { provider_id: field.provider_id, model: field.model });
addedAliases.value = addedAliases.value.filter((name) => name !== alias);
await models.reload();
});
const testAlias = (alias: string) =>
aliasRun(alias, async () => {
const field = aliasField(alias);
@@ -100,17 +118,17 @@ const testAlias = (alias: string) =>
});
const removeAlias = (alias: string) =>
aliasRun(alias, async () => {
if (models.data.value?.[alias]) await api.deleteAgentModel(alias === "default" ? "" : alias);
if (storedAlias(alias)?.model) await api.deleteAgentModel(alias === "default" ? "" : alias);
addedAliases.value = addedAliases.value.filter((name) => name !== alias);
delete aliasEdits.value[alias];
store.forgetModuleSetting(aliasKind(alias));
await models.reload();
});
const newAlias = ref("");
function addAlias(): void {
const name = newAlias.value.trim();
if (!name || aliases.value.includes(name)) return;
if (!hasModels.value || !name || aliases.value.includes(name)) return;
trackAlias(name);
addedAliases.value = [...addedAliases.value, name];
aliasEdits.value = { ...aliasEdits.value, [name]: formOf() };
newAlias.value = "";
}
@@ -119,22 +137,46 @@ interface ProviderForm {
name: string;
class: string;
base_url: string;
key: string;
api_key_credential: string;
}
const providerEdits = ref<Record<string, ProviderForm>>({});
const providerForm = (provider?: ModelProvider): ProviderForm => ({
name: provider?.name ?? "",
class: provider?.class ?? classNames.value[0] ?? "",
base_url: provider?.base_url ?? "",
key: provider?.api_key_credential_id || NONE,
const providerKind = (id: string) => `model-provider/${id}`;
const providerForm = (provider: ModelProvider): ProviderForm => ({
name: provider.name,
class: provider.class,
base_url: provider.base_url ?? "",
api_key_credential: provider.api_key_credential_id ?? "",
});
function trackProvider(provider: ModelProvider): void {
const { id } = provider;
store.trackModuleSetting(providerKind(id), {
title: (saved) => `Model provider: ${saved.name}`,
saved: providerForm(provider),
read: async () => {
const current = (await api.modelProviders()).find((row) => row.id === id);
if (!current) throw new Error("This provider was removed. Discard its draft.");
return providerForm(current);
},
write: async (field) => providerForm(await api.putModelProvider(id, providerInput({
name: field.name,
class: field.class,
base_url: field.base_url,
api_key_credential_id: field.api_key_credential || undefined,
}))),
validate: (field) => !field.name.trim() ? [{ path: "name", label: "Name", message: "Enter a name." }] : [],
});
}
watch(providers.data, (rows) => {
for (const provider of rows ?? []) providerEdits.value[provider.id] ??= providerForm(provider);
for (const provider of rows ?? []) trackProvider(provider);
});
const providerField = (id: string): ProviderForm => (providerEdits.value[id] ??= providerForm());
const providerField = (id: string) => (store.draftValue(providerKind(id)) as ProviderForm | undefined) ?? providerForm(providerById.value.get(id)!);
const storedProviderName = (provider: ModelProvider) => (store.moduleSaved(providerKind(provider.id)) as ProviderForm | undefined)?.name ?? provider.name;
function editProvider(id: string, field: keyof ProviderForm, value: string): void {
if (providerBusy.value) return;
store.setDraftValue(providerKind(id), { ...providerField(id), [field]: value });
}
function credentialLabel(id: string): string {
const key = providerField(id).key;
if (key === NONE) return "no key";
const key = providerField(id).api_key_credential;
if (!key) return "no key";
const found = bearerCredentials.value.find((entry) => entry.id === key);
if (found) return found.name;
const saved = providerById.value.get(id);
@@ -142,35 +184,17 @@ function credentialLabel(id: string): string {
return "missing credential";
}
function hasUnknownCredential(id: string): boolean {
const key = providerField(id).key;
return key !== NONE && !bearerCredentials.value.some((entry) => entry.id === key);
const key = providerField(id).api_key_credential;
return !!key && !bearerCredentials.value.some((entry) => entry.id === key);
}
const providerBusy = ref("");
const saveProvider = async (id: string): Promise<void> => {
providerBusy.value = id;
try {
const field = providerField(id);
await run(async () => {
const saved = await api.putModelProvider(id, providerInput({
name: field.name,
class: field.class,
base_url: field.base_url,
api_key_credential_id: field.key === NONE ? undefined : field.key,
}));
providerEdits.value[id] = providerForm(saved);
await Promise.all([providers.reload(), models.reload()]);
});
} finally {
providerBusy.value = "";
}
};
const removeProvider = async (id: string): Promise<void> => {
providerBusy.value = id;
try {
await run(async () => {
await api.deleteModelProvider(id);
delete providerEdits.value[id];
await providers.reload();
store.forgetModuleSetting(providerKind(id));
});
} finally {
providerBusy.value = "";
@@ -193,8 +217,7 @@ function addProvider(): void {
const classId = newClass.value || classNames.value[0];
if (!classId || !canCreateProvider(name, classId, newProviderBaseURL.value, newProviderDefaultBaseURL.value)) return;
void run(async () => {
const created = await api.createModelProvider(providerInput({ name, class: classId, base_url: newProviderBaseURL.value }));
providerEdits.value[created.id] = providerForm(created);
await api.createModelProvider(providerInput({ name, class: classId, base_url: newProviderBaseURL.value }));
newProvider.value = "";
newProviderBaseURL.value = "";
await providers.reload();
@@ -202,27 +225,27 @@ function addProvider(): void {
}
// Policy: which aliases workflows and chat may name. Empty means any.
const workflowText = ref("");
const chatText = ref("");
watch(policy.data, (current) => {
workflowText.value = current?.workflow_aliases?.join(", ") ?? "";
chatText.value = current?.chat_aliases?.join(", ") ?? "";
const POLICY = "models-policy";
const policyForm = (current: ModelPolicy) => ({
workflows: current.workflow_aliases?.join(", ") ?? "",
chat: current.chat_aliases?.join(", ") ?? "",
});
function aliasList(text: string): string[] | null {
const list = text.split(",").map((alias) => alias.trim()).filter(Boolean);
return list.length ? list : null;
}
const policyBusy = ref(false);
async function savePolicy(): Promise<void> {
policyBusy.value = true;
try {
await run(async () => {
await api.putModelPolicy({ workflow_aliases: aliasList(workflowText.value), chat_aliases: aliasList(chatText.value) });
await policy.reload();
});
} finally {
policyBusy.value = false;
}
watch(policy.data, (current) => {
if (!current) return;
store.trackModuleSetting(POLICY, {
title: "Model policy",
saved: policyForm(current),
read: async () => policyForm(await api.modelPolicy()),
write: async ({ workflows, chat }) => policyForm(await api.putModelPolicy({ workflow_aliases: aliasList(workflows), chat_aliases: aliasList(chat) })),
});
});
const policyFields = computed(() => (store.draftValue(POLICY) as ReturnType<typeof policyForm> | undefined));
function editPolicy(field: keyof ReturnType<typeof policyForm>, value: string): void {
if (policyFields.value) store.setDraftValue(POLICY, { ...policyFields.value, [field]: value });
}
</script>
@@ -230,28 +253,27 @@ async function savePolicy(): Promise<void> {
<div>
<PageHeader title="Models" />
<Alert v-if="error || errorOf(models, providers, classes, credentials, policy)" variant="destructive" class="mb-4">
<AlertDescription>{{ error || errorOf(models, providers, classes, credentials, policy) }}</AlertDescription>
<Alert v-if="error || saveError || errorOf(models, providers, classes, credentials, policy)" variant="destructive" class="mb-4">
<AlertDescription>{{ error || saveError || errorOf(models, providers, classes, credentials, policy) }}</AlertDescription>
</Alert>
<p v-if="!hasModels && !models.error.value" class="flex items-center gap-2 text-label text-fg-muted" role="status"><Spinner />Loading models…</p>
<Section v-else title="Aliases">
<p v-if="hasModels && !modelMap.default" class="mb-3 text-label text-warn" role="alert">Set the default alias.</p>
<Section v-else-if="hasModels" title="Aliases">
<p v-if="!storedAlias('default')?.model" class="mb-3 text-label text-warn" role="alert">Set the default alias.</p>
<div v-for="alias in aliases" :key="alias" class="border-b border-border py-2.5 last-of-type:border-b-0">
<div class="flex flex-wrap items-center gap-3">
<Label :for="`model-${alias}`" class="w-28 text-label font-medium @max-xl:w-full">{{ alias }}</Label>
<Select v-model="aliasField(alias).provider_id">
<Select :model-value="aliasField(alias).provider_id" :disabled="store.savingDrafts || !!aliasBusy" @update:model-value="(value) => editAlias(alias, 'provider_id', String(value ?? ''))">
<SelectTrigger class="w-44 font-mono" :aria-label="`${alias} provider`"><SelectValue placeholder="provider" /></SelectTrigger>
<SelectContent>
<SelectItem v-for="provider in providerList" :key="provider.id" :value="provider.id">{{ provider.name }}</SelectItem>
<SelectItem v-for="provider in providerList" :key="provider.id" :value="provider.id">{{ storedProviderName(provider) }}</SelectItem>
</SelectContent>
</Select>
<Input :id="`model-${alias}`" v-model="aliasField(alias).model" class="min-w-40 flex-1 basis-40 font-mono" placeholder="model" />
<Input :id="`model-${alias}`" :model-value="aliasField(alias).model" :disabled="store.savingDrafts || !!aliasBusy" class="min-w-40 flex-1 basis-40 font-mono" placeholder="model" @update:model-value="(value) => editAlias(alias, 'model', String(value))" />
<span class="ml-auto flex items-center gap-1">
<Button variant="outline" size="sm" :disabled="!!aliasBusy || !aliasField(alias).provider_id || !aliasField(alias).model" @click="testAlias(alias)">Test</Button>
<Button size="sm" :disabled="!!aliasBusy || !aliasField(alias).provider_id || !aliasField(alias).model" @click="saveAlias(alias)">Save</Button>
<Button v-if="alias !== 'default' || modelMap[alias]" variant="ghost" size="icon" :aria-label="`Remove alias ${alias}`" :disabled="!!aliasBusy" @click="removeAlias(alias)"><Trash2 /></Button>
<Button variant="outline" size="sm" :disabled="store.savingDrafts || !!aliasBusy || !aliasField(alias).provider_id || !aliasField(alias).model" @click="testAlias(alias)">Test</Button>
<Button v-if="alias !== 'default' || storedAlias(alias)?.model" variant="ghost" size="icon" :aria-label="`Remove alias ${alias}`" :disabled="store.savingDrafts || !!aliasBusy || (!!storedAlias(alias)?.model && store.changesFor(aliasKind(alias)).length > 0)" @click="removeAlias(alias)"><Trash2 /></Button>
</span>
</div>
<p v-if="tested[alias]" role="status" class="pt-1.5 text-caption text-ok">{{ tested[alias] }}</p>
@@ -259,7 +281,7 @@ async function savePolicy(): Promise<void> {
</div>
<form class="flex flex-wrap gap-2 border-t border-border pt-3" @submit.prevent="addAlias">
<Input v-model="newAlias" class="max-w-56 font-mono" placeholder="alias" aria-label="New alias" />
<Button type="submit" variant="outline" size="sm" :disabled="!newAlias.trim()"><Plus data-icon="inline-start" />Add alias</Button>
<Button type="submit" variant="outline" size="sm" :disabled="store.savingDrafts || !newAlias.trim()"><Plus data-icon="inline-start" />Add alias</Button>
</form>
</Section>
@@ -268,7 +290,7 @@ async function savePolicy(): Promise<void> {
<AccordionItem v-for="provider in providerList" :key="provider.id" :value="provider.id">
<AccordionTrigger class="hover:no-underline">
<span class="flex min-w-0 flex-1 flex-wrap items-center gap-x-3">
<span class="w-28 text-left font-mono text-label font-medium">{{ provider.name }}</span>
<span class="w-28 text-left font-mono text-label font-medium">{{ storedProviderName(provider) }}</span>
<span class="font-mono text-caption text-fg-muted">{{ providerField(provider.id).class }}</span>
<span class="min-w-0 truncate font-mono text-caption text-fg-subtle">{{ credentialLabel(provider.id) }}</span>
</span>
@@ -276,33 +298,32 @@ async function savePolicy(): Promise<void> {
<AccordionContent>
<div class="flex flex-wrap items-center gap-3 border-t-0 py-2">
<Label :for="`prov-${provider.id}-name`" class="w-28 text-label font-medium @max-xl:w-full">Name</Label>
<Input :id="`prov-${provider.id}-name`" v-model="providerField(provider.id).name" class="max-w-md font-mono" :aria-label="`Name for ${provider.name}`" />
<Input :id="`prov-${provider.id}-name`" :model-value="providerField(provider.id).name" class="max-w-md font-mono" :aria-label="`Name for ${storedProviderName(provider)}`" :disabled="store.savingDrafts || !!providerBusy" @update:model-value="(value) => editProvider(provider.id, 'name', String(value))" />
</div>
<div class="flex flex-wrap items-center gap-3 border-t-0 py-2">
<Label :for="`prov-${provider.id}-class`" class="w-28 text-label font-medium @max-xl:w-full">Class</Label>
<Select v-model="providerField(provider.id).class">
<SelectTrigger :id="`prov-${provider.id}-class`" class="w-48 font-mono" :aria-label="`Class for ${provider.name}`"><SelectValue /></SelectTrigger>
<Select :model-value="providerField(provider.id).class" :disabled="store.savingDrafts || !!providerBusy" @update:model-value="(value) => editProvider(provider.id, 'class', String(value ?? ''))">
<SelectTrigger :id="`prov-${provider.id}-class`" class="w-48 font-mono" :aria-label="`Class for ${storedProviderName(provider)}`"><SelectValue /></SelectTrigger>
<SelectContent><SelectItem v-for="classId in classNames" :key="classId" :value="classId">{{ classId }}</SelectItem></SelectContent>
</Select>
</div>
<div class="flex flex-wrap items-center gap-3 border-t-0 py-2">
<Label :for="`prov-${provider.id}-url`" class="w-28 text-label font-medium @max-xl:w-full">Base URL</Label>
<Input :id="`prov-${provider.id}-url`" v-model="providerField(provider.id).base_url" class="max-w-md font-mono" :placeholder="classList.find((entry) => entry.class === providerField(provider.id).class)?.default_base_url || 'class default'" />
<Input :id="`prov-${provider.id}-url`" :model-value="providerField(provider.id).base_url" class="max-w-md font-mono" :placeholder="classList.find((entry) => entry.class === providerField(provider.id).class)?.default_base_url || 'class default'" :disabled="store.savingDrafts || !!providerBusy" @update:model-value="(value) => editProvider(provider.id, 'base_url', String(value))" />
</div>
<div class="flex flex-wrap items-center gap-3 border-t-0 py-2">
<Label :for="`prov-${provider.id}-key`" class="w-28 text-label font-medium @max-xl:w-full">API key</Label>
<Select v-model="providerField(provider.id).key">
<SelectTrigger :id="`prov-${provider.id}-key`" class="w-56" :aria-label="`API key for ${provider.name}`"><SelectValue /></SelectTrigger>
<Select :model-value="providerField(provider.id).api_key_credential || NONE" :disabled="store.savingDrafts || !!providerBusy" @update:model-value="(value) => editProvider(provider.id, 'api_key_credential', value === NONE ? '' : String(value ?? ''))">
<SelectTrigger :id="`prov-${provider.id}-key`" class="w-56" :aria-label="`API key for ${storedProviderName(provider)}`"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem :value="NONE">No key</SelectItem>
<SelectItem v-if="hasUnknownCredential(provider.id)" :value="providerField(provider.id).key" disabled>{{ credentialLabel(provider.id) }}</SelectItem>
<SelectItem v-if="hasUnknownCredential(provider.id)" :value="providerField(provider.id).api_key_credential" disabled>{{ credentialLabel(provider.id) }}</SelectItem>
<SelectItem v-for="credential in bearerCredentials" :key="credential.id" :value="credential.id">{{ credential.name }}</SelectItem>
</SelectContent>
</Select>
</div>
<div class="flex justify-end gap-1 pb-1">
<Button variant="ghost" size="sm" class="text-danger" :disabled="!!providerBusy" @click="removeProvider(provider.id)"><Trash2 data-icon="inline-start" />Remove</Button>
<Button size="sm" :disabled="!!providerBusy || !providerField(provider.id).name.trim() || !providerField(provider.id).class" @click="saveProvider(provider.id)">Save</Button>
<Button variant="ghost" size="sm" class="text-danger" :disabled="store.savingDrafts || !!providerBusy || store.changesFor(providerKind(provider.id)).length > 0" @click="removeProvider(provider.id)"><Trash2 data-icon="inline-start" />Remove</Button>
</div>
</AccordionContent>
</AccordionItem>
@@ -314,20 +335,20 @@ async function savePolicy(): Promise<void> {
<SelectContent><SelectItem v-for="classId in classNames" :key="classId" :value="classId">{{ classId }}</SelectItem></SelectContent>
</Select>
<Input v-model="newProviderBaseURL" class="min-w-56 flex-1 basis-56 font-mono" :placeholder="newProviderDefaultBaseURL || 'Base URL'" aria-label="Base URL for new provider" />
<Button type="submit" variant="outline" size="sm" :disabled="!canAddProvider"><Plus data-icon="inline-start" />Add provider</Button>
<Button type="submit" variant="outline" size="sm" :disabled="store.savingDrafts || !canAddProvider"><Plus data-icon="inline-start" />Add provider</Button>
</form>
</Section>
<Section v-if="policyData" title="Policy">
<Section v-if="policyFields" title="Policy">
<div class="flex flex-wrap items-center gap-3 py-2">
<Label for="policy-workflows" class="w-28 text-label font-medium @max-xl:w-full">Workflows</Label>
<Input id="policy-workflows" v-model="workflowText" class="min-w-40 flex-1 basis-40 font-mono" placeholder="any alias" aria-label="Aliases workflows may use" />
<Input id="policy-workflows" :model-value="policyFields.workflows" class="min-w-40 flex-1 basis-40 font-mono" placeholder="any alias" aria-label="Aliases workflows may use" :disabled="store.savingDrafts" @update:model-value="(value) => editPolicy('workflows', String(value))" />
</div>
<div class="flex flex-wrap items-center gap-3 py-2">
<Label for="policy-chat" class="w-28 text-label font-medium @max-xl:w-full">Chat</Label>
<Input id="policy-chat" v-model="chatText" class="min-w-40 flex-1 basis-40 font-mono" placeholder="any alias" aria-label="Aliases chat may use" />
<Input id="policy-chat" :model-value="policyFields.chat" class="min-w-40 flex-1 basis-40 font-mono" placeholder="any alias" aria-label="Aliases chat may use" :disabled="store.savingDrafts" @update:model-value="(value) => editPolicy('chat', String(value))" />
</div>
<div class="flex justify-end pt-2"><Button size="sm" :disabled="policyBusy" @click="savePolicy">Save</Button></div>
</Section>
</div>
</template>
-18
View File
@@ -32,24 +32,6 @@ 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;