Files
archie/ui/src/settings/SystemTasksPage.vue
T

166 lines
7.9 KiB
Vue

<script setup lang="ts">
import ApplyStatusRows from "./ApplyStatusRows.vue";
import { computed, onMounted, ref } from "vue";
import { RotateCcw } from "@lucide/vue";
import { storeToRefs } from "pinia";
import { Button } from "@/components/ui/button";
import {Input} from "@/components/ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import PageHeader from "@/base/PageHeader.vue";
import { DurationInput, formatGoDuration, parseGoDuration } from "@/components/ui/duration-input";
import {
NumberField,
NumberFieldContent,
NumberFieldDecrement,
NumberFieldIncrement,
NumberFieldInput,
} from "@/components/ui/number-field";
import { SettingRow } from "@/components/ui/setting-row";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { cloneControlPlaneValue, resourcesForPage, useSettingsStore } from "@/stores/settings";
import { restoreShippedDefinitions, useWorkflowsStore } from "@/stores/workflows";
import DraftHint from "./DraftHint.vue";
import HistoryLink from "./HistoryLink.vue";
import SecretRefField from "./SecretRefField.vue";
const POLICY="task-policy";
const KIND = "workflow-execution-settings";
interface ExecutionSettings {
max_model_tool_steps: number;
max_runtime_seconds: number;
max_consecutive_gate_failures: number;
max_task_runtime_seconds: number | null;
}
const store = useSettingsStore();
const { catalog, catalogError } = storeToRefs(store);
onMounted(store.load);
const resources = computed(() => resourcesForPage(catalog.value, "tasks"));
const policy=computed(()=>store.drafts[POLICY]?.value as {diff_cap_lines:number;notify_webhook:string;notify_min_severity:string;notify_secret:{engine:string;key:string}}|undefined);
const limits = computed(() => store.drafts[KIND]?.value as ExecutionSettings | undefined);
const error = computed(() => store.pageErrorFor(KIND));
// The document counts seconds; the input speaks durations.
function seconds(key: "max_runtime_seconds" | "max_task_runtime_seconds") {
return computed({
get: () => formatGoDuration((limits.value?.[key] ?? 0) * 1000),
set: (text: string) => {
const ms = parseGoDuration(text);
if (limits.value && ms !== null) limits.value[key] = Math.round(ms / 1000);
},
});
}
const callRuntime = seconds("max_runtime_seconds");
const taskRuntime = seconds("max_task_runtime_seconds");
const workflows = useWorkflowsStore();
const confirmRestore = ref(false);
async function restoreWorkflows(): Promise<void> {
await workflows.save(cloneControlPlaneValue(restoreShippedDefinitions(workflows.collection, workflows.shipped)));
}
</script>
<template>
<div>
<PageHeader title="Task execution">
<HistoryLink :kinds="resources.map((r) => r.kind)" />
</PageHeader>
<ApplyStatusRows v-for="resource in resources" :key="resource.kind" :kind="resource.kind" class="mb-4" />
<p v-if="catalogError || error || store.pageErrorFor(POLICY)" class="mb-4 text-sm text-danger" role="alert">
{{ catalogError || error || store.pageErrorFor(POLICY) }}
</p>
<template v-if="policy">
<SettingRow label="Maximum changed lines" hint="Applied to new tasks. 0 disables the limit." for="task-diff-cap">
<div class="flex flex-wrap items-center gap-3"><Input id="task-diff-cap" v-model.number="policy.diff_cap_lines" type="number" min="0" class="max-w-40" /><DraftHint :kind="POLICY" path="diff_cap_lines" /></div>
</SettingRow>
<SettingRow label="Alert webhook" hint="Receives each raised and resolved alert. Empty disables." for="task-notify">
<div class="flex flex-wrap items-center gap-3"><Input id="task-notify" v-model="policy.notify_webhook" type="url" class="max-w-md" /><DraftHint :kind="POLICY" path="notify_webhook" /></div>
</SettingRow>
<SettingRow label="Webhook severity" hint="Minimum severity.">
<div class="flex flex-wrap items-center gap-3">
<Select :model-value="policy.notify_min_severity || 'warning'" @update:model-value="policy.notify_min_severity = String($event)">
<SelectTrigger class="w-40" aria-label="Webhook severity"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem value="info">Info</SelectItem>
<SelectItem value="warning">Warning</SelectItem>
<SelectItem value="action">Needs attention</SelectItem>
</SelectContent>
</Select>
<DraftHint :kind="POLICY" path="notify_min_severity" />
</div>
</SettingRow>
<SettingRow label="Webhook signing secret" hint="Signs each payload in X-Archie-Signature. Not set sends unsigned.">
<div class="flex flex-wrap items-center gap-3"><SecretRefField v-if="policy.notify_secret" v-model="policy.notify_secret" id-prefix="task-notify-secret" /><Button v-else variant="outline" size="sm" @click="policy.notify_secret = { engine: '', key: '' }">Set reference</Button><DraftHint :kind="POLICY" path="notify_secret" /></div>
</SettingRow>
</template>
<template v-if="limits">
<SettingRow label="Task time limit" for="te-task" hint="Parked after this. 0 disables.">
<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.">
<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.">
<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="Then parked.">
<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>
<SettingRow v-if="workflows.shipped.definitions.length" label="Workflows" hint="Resets every shipped workflow. Custom workflows are kept.">
<Button variant="outline" size="sm" :disabled="workflows.state.saving" @click="confirmRestore = true"><RotateCcw data-icon="inline-start" />Restore default</Button>
</SettingRow>
<AlertDialog v-model:open="confirmRestore">
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Restore default workflows?</AlertDialogTitle>
<AlertDialogDescription>Edits to shipped workflows are discarded.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction @click="restoreWorkflows">Restore</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<p v-if="workflows.state.error" class="text-sm text-danger" role="alert">{{ workflows.state.error }}</p>
</div>
</template>