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

156 lines
6.4 KiB
Vue

<script setup lang="ts">
import { Alert, AlertDescription } from "@/components/ui/alert";
import ApplyStatusRows from "./ApplyStatusRows.vue";
import KindGate from "./KindGate.vue";
import { computed, onMounted, ref } from "vue";
import { storeToRefs } from "pinia";
import PageHeader from "@/base/PageHeader.vue";
import { DurationInput, formatGoDuration, parseGoDuration } from "@/components/ui/duration-input";
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
import {
NumberField,
NumberFieldContent,
NumberFieldDecrement,
NumberFieldIncrement,
NumberFieldInput,
} from "@/components/ui/number-field";
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
import DraftHint from "./DraftHint.vue";
import HistoryLink from "./HistoryLink.vue";
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 limitsForm = computed(() => store.formFor(KIND));
const limits = computed(() => store.draftValue(KIND) as ExecutionSettings | undefined);
const error = computed(() => store.pageErrorFor(KIND));
// The document counts seconds; the input speaks durations.
function durationText(seconds: number | null | undefined): string {
return formatGoDuration((seconds ?? 0) * 1000);
}
// Undefined for text that is not a duration, so the draft keeps its last value.
const durationErrors = ref<Record<string, string>>({});
function commitDuration(field: { handleChange: (value: number) => void }, id: string, text: string): void {
const seconds = durationSeconds(text);
if (seconds === undefined) {
durationErrors.value = { ...durationErrors.value, [id]: "Enter a duration like 30m or 2h." };
return;
}
const next = { ...durationErrors.value };
delete next[id];
durationErrors.value = next;
field.handleChange(seconds);
}
function durationSeconds(text: string): number | undefined {
const ms = parseGoDuration(text);
return ms === null ? undefined : Math.round(ms / 1000);
}
</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" />
<Alert v-if="catalogError || error" variant="destructive" class="mb-4"><AlertDescription>
{{ catalogError || error }}
</AlertDescription></Alert>
<KindGate v-if="!limitsForm" :kind="KIND" />
<FieldGroup v-if="limitsForm && limits" class="@container/field-group">
<limitsForm.Field v-slot="{ field }" name="max_task_runtime_seconds">
<Field orientation="responsive">
<FieldContent>
<FieldLabel for="te-task">Task time limit</FieldLabel>
<FieldDescription>Parked after this. 0 disables.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<DurationInput
id="te-task"
:model-value="durationText(field.state.value)"
:units="['m', 'h']"
@update:model-value="(text: string) => commitDuration(field, 'te-task', text)"
/>
<p v-if="durationErrors['te-task']" class="text-caption text-danger" role="alert">{{ durationErrors['te-task'] }}</p>
<DraftHint :kind="KIND" path="max_task_runtime_seconds" />
</div>
</Field>
</limitsForm.Field>
<limitsForm.Field v-slot="{ field }" name="max_runtime_seconds">
<Field orientation="responsive">
<FieldContent>
<FieldLabel for="te-call">Agent call time limit</FieldLabel>
<FieldDescription>0 disables.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<DurationInput
id="te-call"
:model-value="durationText(field.state.value)"
:units="['s', 'm', 'h']"
@update:model-value="(text: string) => commitDuration(field, 'te-call', text)"
/>
<p v-if="durationErrors['te-call']" class="text-caption text-danger" role="alert">{{ durationErrors['te-call'] }}</p>
<DraftHint :kind="KIND" path="max_runtime_seconds" />
</div>
</Field>
</limitsForm.Field>
<limitsForm.Field v-slot="{ field }" name="max_model_tool_steps">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Model tool steps</FieldLabel>
<FieldDescription>Per agent call. 0 disables.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<NumberField :model-value="field.state.value" :min="0" class="w-32" @update:model-value="field.handleChange">
<NumberFieldContent>
<NumberFieldDecrement />
<NumberFieldInput class="font-mono" aria-label="Model tool steps" />
<NumberFieldIncrement />
</NumberFieldContent>
</NumberField>
<DraftHint :kind="KIND" path="max_model_tool_steps" />
</div>
</Field>
</limitsForm.Field>
<limitsForm.Field v-slot="{ field }" name="max_consecutive_gate_failures">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Gate failures in a row</FieldLabel>
<FieldDescription>Then parked.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<NumberField :model-value="field.state.value" :min="0" class="w-32" @update:model-value="field.handleChange">
<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>
</Field>
</limitsForm.Field>
</FieldGroup>
</div>
</template>