feat(ui): settings pages edit through TanStack Form with shadcn-vue Field

Each control-plane kind has one store-owned TanStack form, so edits survive
navigation and the save bar submits every dirty section. Shared editors emit
new values, map entries are written whole, unset resources stay null, and the
container runtime page warns when max uptime is under the task limit.
This commit is contained in:
sam committed 2026-10-26 19:17:03 +11:00
1 parent 424a6e4f01
commit cc2f3a46b9
57 files changed
+2323 -863

No files matched your search

+135 -73
View File
@@ -7,6 +7,7 @@ import { storeToRefs } from "pinia";
import PageHeader from "@/base/PageHeader.vue";
import { Button } from "@/components/ui/button";
import { DurationInput } from "@/components/ui/duration-input";
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import {
NumberField,
@@ -15,7 +16,6 @@ import {
NumberFieldIncrement,
NumberFieldInput,
} from "@/components/ui/number-field";
import { SettingRow } from "@/components/ui/setting-row";
import { Badge } from "@/components/ui/badge";
import { Switch } from "@/components/ui/switch";
import {
@@ -58,7 +58,8 @@ interface ChannelStatus {
const store = useSettingsStore();
const { catalog, catalogError } = storeToRefs(store);
const resources = computed(() => resourcesForPage(catalog.value, "channels"));
const chat = computed(() => store.drafts[KIND]?.value as ChannelSettings | undefined);
const form = computed(() => store.formFor(KIND));
const chat = computed(() => store.draftValue(KIND) as ChannelSettings | undefined);
const error = computed(() => store.pageErrorFor(KIND));
const statuses = ref<ChannelStatus[]>([]);
@@ -95,19 +96,17 @@ const channels = [
{ id: "telegram", title: "Telegram" },
] as const;
const allowedUsers = computed({
get: () => (chat.value?.telegram.allowed_user_ids ?? []).map(String),
set: (ids: string[]) => {
if (chat.value)
chat.value.telegram.allowed_user_ids = ids.filter((id) => /^\d+$/.test(id)).map(Number);
},
});
const models = computed({
get: () => chat.value?.models ?? [],
set: (list: string[]) => {
if (chat.value) chat.value.models = list;
},
});
const allowedUsers = computed(() => (chat.value?.telegram.allowed_user_ids ?? []).map(String));
const models = computed(() => chat.value?.models ?? []);
// Tag lists are edited in script, so they go through the form's API rather
// than a field's handleChange.
function setAllowedUsers(ids: string[]) {
form.value?.api.setFieldValue("telegram.allowed_user_ids", ids.filter((id) => /^\d+$/.test(id)).map(Number));
}
function setModels(list: string[]) {
form.value?.api.setFieldValue("models", list);
}
</script>
<template>
@@ -131,67 +130,130 @@ const models = computed({
<Button v-if="!configured[channel.id] && !opened[channel.id]" variant="outline" size="sm" @click="opened[channel.id] = true">Set up</Button>
</div>
</template>
<template v-if="shown(channel.id) && channel.id === 'telegram'">
<SettingRow label="Bot token" hint="Empty disables Telegram.">
<SecretRefField v-model="chat.telegram.token_ref" id-prefix="tg-token" />
</SettingRow>
<SettingRow label="Allowed users" hint="Everyone else is ignored.">
<TagsInput v-model="allowedUsers" aria-label="Allowed users" class="font-mono">
<TagsInputItem v-for="id in allowedUsers" :key="id" :value="id">
<TagsInputItemText />
<TagsInputItemDelete />
</TagsInputItem>
<TagsInputInput placeholder="Add user ID" />
</TagsInput>
</SettingRow>
</template>
<FieldGroup v-if="form && shown(channel.id) && channel.id === 'telegram'" class="@container/field-group">
<form.Field v-slot="{ field }" name="telegram.token_ref">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Bot token</FieldLabel>
<FieldDescription>Empty disables Telegram.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<SecretRefField :model-value="field.state.value" id-prefix="tg-token" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Allowed users</FieldLabel>
<FieldDescription>Everyone else is ignored.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<TagsInput :model-value="allowedUsers" aria-label="Allowed users" class="font-mono" @update:model-value="(ids) => setAllowedUsers(ids.map(String))">
<TagsInputItem v-for="id in allowedUsers" :key="id" :value="id">
<TagsInputItemText />
<TagsInputItemDelete />
</TagsInputItem>
<TagsInputInput placeholder="Add user ID" />
</TagsInput>
</div>
</Field>
</FieldGroup>
</Section>
<Section title="Chat session defaults">
<SettingRow label="Workspace" for="cs-workspace" hint="Empty disables file tools.">
<Input id="cs-workspace" v-model="chat.workspace" class="max-w-md font-mono" />
</SettingRow>
<SettingRow
label="Unrestricted filesystem"
:tone="chat.unrestricted_filesystem ? 'danger' : 'default'"
>
<Switch v-model="chat.unrestricted_filesystem" aria-label="Unrestricted filesystem" />
</SettingRow>
<SettingRow label="Show tool calls">
<Switch v-model="chat.show_tool_calls" aria-label="Show tool calls" />
</SettingRow>
<SettingRow label="Max steps" hint="0 = default (100).">
<NumberField v-model="chat.max_steps" :min="0" class="w-32">
<NumberFieldContent>
<NumberFieldDecrement />
<NumberFieldInput class="font-mono" aria-label="Max steps" />
<NumberFieldIncrement />
</NumberFieldContent>
</NumberField>
</SettingRow>
<SettingRow label="Rate limit" hint="Per sender. Off while either is 0.">
<div class="flex flex-wrap items-center gap-2 text-sm text-fg-muted">
<NumberField v-model="chat.rate_limit.max_requests" :min="0" class="w-28">
<NumberFieldContent>
<NumberFieldInput class="font-mono" aria-label="Requests" />
</NumberFieldContent>
</NumberField>
requests per
<DurationInput v-model="chat.rate_limit.window" :units="['s', 'm', 'h']" />
</div>
</SettingRow>
<SettingRow label="Models" hint="Empty: role models.">
<TagsInput v-model="models" aria-label="Models" class="font-mono">
<TagsInputItem v-for="model in models" :key="model" :value="model">
<TagsInputItemText />
<TagsInputItemDelete />
</TagsInputItem>
<TagsInputInput placeholder="provider/model" />
</TagsInput>
</SettingRow>
<SettingRow label="Operator" for="cs-operator">
<Input id="cs-operator" v-model="chat.operator" class="max-w-sm" />
</SettingRow>
<FieldGroup v-if="form" class="@container/field-group">
<form.Field v-slot="{ field }" name="workspace">
<Field orientation="responsive">
<FieldContent>
<FieldLabel for="cs-workspace">Workspace</FieldLabel>
<FieldDescription>Empty disables file tools.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input id="cs-workspace" :model-value="field.state.value" class="max-w-md font-mono" @blur="field.handleBlur" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="unrestricted_filesystem">
<Field
orientation="responsive"
:class="field.state.value && 'relative isolate before:pointer-events-none before:absolute before:inset-y-0 before:-inset-x-3 before:-z-10 before:rounded-md before:border before:border-danger/40 before:bg-danger-soft'"
>
<FieldContent><FieldLabel>Unrestricted filesystem</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Switch :model-value="field.state.value" aria-label="Unrestricted filesystem" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="show_tool_calls">
<Field orientation="responsive">
<FieldContent><FieldLabel>Show tool calls</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Switch :model-value="field.state.value" aria-label="Show tool calls" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="max_steps">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Max steps</FieldLabel>
<FieldDescription>0 = default (100).</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="Max steps" />
<NumberFieldIncrement />
</NumberFieldContent>
</NumberField>
</div>
</Field>
</form.Field>
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Rate limit</FieldLabel>
<FieldDescription>Per sender. Off while either is 0.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<div class="flex flex-wrap items-center gap-2 text-sm text-fg-muted">
<form.Field v-slot="{ field }" name="rate_limit.max_requests">
<NumberField :model-value="field.state.value" :min="0" class="w-28" @update:model-value="field.handleChange">
<NumberFieldContent>
<NumberFieldInput class="font-mono" aria-label="Requests" />
</NumberFieldContent>
</NumberField>
</form.Field>
requests per
<form.Field v-slot="{ field }" name="rate_limit.window">
<DurationInput :model-value="field.state.value" :units="['s', 'm', 'h']" @update:model-value="field.handleChange" />
</form.Field>
</div>
</div>
</Field>
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Models</FieldLabel>
<FieldDescription>Empty: role models.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<TagsInput :model-value="models" aria-label="Models" class="font-mono" @update:model-value="(list) => setModels(list.map(String))">
<TagsInputItem v-for="model in models" :key="model" :value="model">
<TagsInputItemText />
<TagsInputItemDelete />
</TagsInputItem>
<TagsInputInput placeholder="provider/model" />
</TagsInput>
</div>
</Field>
<form.Field v-slot="{ field }" name="operator">
<Field orientation="responsive">
<FieldContent><FieldLabel for="cs-operator">Operator</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input id="cs-operator" :model-value="field.state.value" class="max-w-sm" @blur="field.handleBlur" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
</FieldGroup>
</Section>
</template>
</div>
@@ -0,0 +1,20 @@
<script setup lang="ts">
import type { ComboboxRootEmits, ComboboxRootProps } from 'reka-ui'
import { ComboboxRoot, useForwardPropsEmits } from 'reka-ui'
const props = defineProps<ComboboxRootProps>()
const emits = defineEmits<ComboboxRootEmits>()
const forwarded = useForwardPropsEmits(props, emits)
</script>
<template>
<ComboboxRoot
v-slot="slotProps"
data-slot="combobox"
v-bind="forwarded"
>
<slot v-bind="slotProps" />
</ComboboxRoot>
</template>
@@ -0,0 +1,24 @@
<script setup lang="ts">
import type { ComboboxAnchorProps } from 'reka-ui'
import type { HTMLAttributes } from 'vue'
import { reactiveOmit } from '@vueuse/core'
import { cn } from '@/lib/utils'
import { ComboboxAnchor, useForwardProps } from 'reka-ui'
const props = defineProps<ComboboxAnchorProps & { class?: HTMLAttributes['class'] }>()
const delegatedProps = reactiveOmit(props, 'class')
const forwarded = useForwardProps(delegatedProps)
</script>
<template>
<ComboboxAnchor
data-slot="combobox-anchor"
v-bind="forwarded"
:class="cn('', props.class)"
>
<slot />
</ComboboxAnchor>
</template>
@@ -0,0 +1,22 @@
<script setup lang="ts">
import type { ComboboxEmptyProps } from 'reka-ui'
import type { HTMLAttributes } from 'vue'
import { reactiveOmit } from '@vueuse/core'
import { cn } from '@/lib/utils'
import { ComboboxEmpty } from 'reka-ui'
const props = defineProps<ComboboxEmptyProps & { class?: HTMLAttributes['class'] }>()
const delegatedProps = reactiveOmit(props, 'class')
</script>
<template>
<ComboboxEmpty
data-slot="combobox-empty"
v-bind="delegatedProps"
:class="cn('text-muted-foreground hidden w-full justify-center py-2 text-center text-sm group-data-empty/combobox-content:flex', props.class)"
>
<slot />
</ComboboxEmpty>
</template>
@@ -0,0 +1,28 @@
<script setup lang="ts">
import type { ComboboxGroupProps } from 'reka-ui'
import type { HTMLAttributes } from 'vue'
import { reactiveOmit } from '@vueuse/core'
import { cn } from '@/lib/utils'
import { ComboboxGroup, ComboboxLabel } from 'reka-ui'
const props = defineProps<ComboboxGroupProps & {
class?: HTMLAttributes['class']
heading?: string
}>()
const delegatedProps = reactiveOmit(props, 'class')
</script>
<template>
<ComboboxGroup
data-slot="combobox-group"
v-bind="delegatedProps"
:class="cn('overflow-hidden text-foreground', props.class)"
>
<ComboboxLabel v-if="heading" class="text-muted-foreground px-2 py-1.5 text-xs">
{{ heading }}
</ComboboxLabel>
<slot />
</ComboboxGroup>
</template>
@@ -0,0 +1,38 @@
<script setup lang="ts">
import type { ComboboxInputEmits, ComboboxInputProps } from 'reka-ui'
import type { HTMLAttributes } from 'vue'
import { SearchIcon } from '@lucide/vue'
import { reactiveOmit } from '@vueuse/core'
import { cn } from '@/lib/utils'
import { ComboboxInput, useForwardPropsEmits } from 'reka-ui'
import { InputGroup, InputGroupAddon } from '@/components/ui/input-group'
defineOptions({
inheritAttrs: false,
})
const props = defineProps<ComboboxInputProps & {
class?: HTMLAttributes['class']
}>()
const emits = defineEmits<ComboboxInputEmits>()
const delegatedProps = reactiveOmit(props, 'class')
const forwarded = useForwardPropsEmits(delegatedProps, emits)
</script>
<template>
<InputGroup>
<InputGroupAddon>
<SearchIcon class="size-4 shrink-0 opacity-50" />
</InputGroupAddon>
<ComboboxInput
data-slot="combobox-input"
:class="cn('flex-1 outline-hidden disabled:cursor-not-allowed disabled:opacity-50', props.class)"
v-bind="{ ...$attrs, ...forwarded }"
/>
</InputGroup>
</template>
@@ -0,0 +1,25 @@
<script setup lang="ts">
import type { ComboboxItemEmits, ComboboxItemProps } from 'reka-ui'
import type { HTMLAttributes } from 'vue'
import { reactiveOmit } from '@vueuse/core'
import { cn } from '@/lib/utils'
import { ComboboxItem, useForwardPropsEmits } from 'reka-ui'
const props = defineProps<ComboboxItemProps & { class?: HTMLAttributes['class'] }>()
const emits = defineEmits<ComboboxItemEmits>()
const delegatedProps = reactiveOmit(props, 'class')
const forwarded = useForwardPropsEmits(delegatedProps, emits)
</script>
<template>
<ComboboxItem
data-slot="combobox-item"
v-bind="forwarded"
:class="cn('data-highlighted:bg-accent data-highlighted:text-accent-foreground not-data-[variant=destructive]:data-highlighted:**:text-accent-foreground gap-2 rounded-md py-1 pr-8 pl-1.5 text-sm [&_svg:not([class*=size-])]:size-4 relative flex w-full cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0', props.class)"
>
<slot />
</ComboboxItem>
</template>
@@ -0,0 +1,24 @@
<script setup lang="ts">
import type { ComboboxItemIndicatorProps } from 'reka-ui'
import type { HTMLAttributes } from 'vue'
import { reactiveOmit } from '@vueuse/core'
import { cn } from '@/lib/utils'
import { ComboboxItemIndicator, useForwardProps } from 'reka-ui'
const props = defineProps<ComboboxItemIndicatorProps & { class?: HTMLAttributes['class'] }>()
const delegatedProps = reactiveOmit(props, 'class')
const forwarded = useForwardProps(delegatedProps)
</script>
<template>
<ComboboxItemIndicator
data-slot="combobox-item-indicator"
v-bind="forwarded"
:class="cn('pointer-events-none absolute right-2 flex size-4 items-center justify-center', props.class)"
>
<slot />
</ComboboxItemIndicator>
</template>
@@ -0,0 +1,34 @@
<script setup lang="ts">
import type { ComboboxContentEmits, ComboboxContentProps } from 'reka-ui'
import type { HTMLAttributes } from 'vue'
import { reactiveOmit } from '@vueuse/core'
import { cn } from '@/lib/utils'
import { ComboboxContent, ComboboxPortal, useForwardPropsEmits } from 'reka-ui'
defineOptions({
inheritAttrs: false,
})
const props = withDefaults(defineProps<ComboboxContentProps & { class?: HTMLAttributes['class'] }>(), {
position: 'popper',
align: 'center',
sideOffset: 4,
})
const emits = defineEmits<ComboboxContentEmits>()
const delegatedProps = reactiveOmit(props, 'class')
const forwarded = useForwardPropsEmits(delegatedProps, emits)
</script>
<template>
<ComboboxPortal>
<ComboboxContent
data-slot="combobox-content"
v-bind="{ ...$attrs, ...forwarded }"
:class="cn('bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 *:data-[slot=input-group]:bg-input/30 *:data-[slot=input-group]:border-input/30 max-h-72 min-w-36 overflow-hidden rounded-lg shadow-md ring-1 duration-100 *:data-[slot=input-group]:m-1 *:data-[slot=input-group]:mb-0 *:data-[slot=input-group]:h-8 *:data-[slot=input-group]:shadow-none data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 cn-menu-target cn-menu-translucent group/combobox-content z-50 w-(--reka-combobox-trigger-width)', props.class)"
>
<slot />
</ComboboxContent>
</ComboboxPortal>
</template>
@@ -0,0 +1,22 @@
<script setup lang="ts">
import type { ComboboxSeparatorProps } from 'reka-ui'
import type { HTMLAttributes } from 'vue'
import { reactiveOmit } from '@vueuse/core'
import { cn } from '@/lib/utils'
import { ComboboxSeparator } from 'reka-ui'
const props = defineProps<ComboboxSeparatorProps & { class?: HTMLAttributes['class'] }>()
const delegatedProps = reactiveOmit(props, 'class')
</script>
<template>
<ComboboxSeparator
data-slot="combobox-separator"
v-bind="delegatedProps"
:class="cn('bg-border -mx-1 my-1 h-px', props.class)"
>
<slot />
</ComboboxSeparator>
</template>
@@ -0,0 +1,25 @@
<script setup lang="ts">
import type { ComboboxTriggerProps } from 'reka-ui'
import type { HTMLAttributes } from 'vue'
import { reactiveOmit } from '@vueuse/core'
import { cn } from '@/lib/utils'
import { ComboboxTrigger, useForwardProps } from 'reka-ui'
const props = defineProps<ComboboxTriggerProps & { class?: HTMLAttributes['class'] }>()
const delegatedProps = reactiveOmit(props, 'class')
const forwarded = useForwardProps(delegatedProps)
</script>
<template>
<ComboboxTrigger
data-slot="combobox-trigger"
v-bind="forwarded"
:class="cn('[&_svg:not([class*=size-])]:size-4', props.class)"
tabindex="0"
>
<slot />
</ComboboxTrigger>
</template>
@@ -0,0 +1,24 @@
<script setup lang="ts">
import type { ComboboxViewportProps } from 'reka-ui'
import type { HTMLAttributes } from 'vue'
import { reactiveOmit } from '@vueuse/core'
import { cn } from '@/lib/utils'
import { ComboboxViewport, useForwardProps } from 'reka-ui'
const props = defineProps<ComboboxViewportProps & { class?: HTMLAttributes['class'] }>()
const delegatedProps = reactiveOmit(props, 'class')
const forwarded = useForwardProps(delegatedProps)
</script>
<template>
<ComboboxViewport
data-slot="combobox-viewport"
v-bind="forwarded"
:class="cn('no-scrollbar max-h-[min(calc(--spacing(72)---spacing(9)),calc(var(--available-height)---spacing(9)))] scroll-py-1 overflow-y-auto p-1 data-empty:p-0', props.class)"
>
<slot />
</ComboboxViewport>
</template>
+14
View File
@@ -0,0 +1,14 @@
export { default as Combobox } from './Combobox.vue'
export { default as ComboboxAnchor } from './ComboboxAnchor.vue'
export { default as ComboboxEmpty } from './ComboboxEmpty.vue'
export { default as ComboboxGroup } from './ComboboxGroup.vue'
export { default as ComboboxInput } from './ComboboxInput.vue'
export { default as ComboboxItem } from './ComboboxItem.vue'
export { default as ComboboxItemIndicator } from './ComboboxItemIndicator.vue'
export { default as ComboboxList } from './ComboboxList.vue'
export { default as ComboboxSeparator } from './ComboboxSeparator.vue'
export { default as ComboboxTrigger } from './ComboboxTrigger.vue'
export { default as ComboboxViewport } from './ComboboxViewport.vue'
export { ComboboxCancel } from 'reka-ui'
@@ -10,7 +10,13 @@ import {
splitDuration,
} from "./duration";
const props = defineProps<{ id?: string; disabled?: boolean; units?: DurationUnit[] }>();
const props = defineProps<{
id?: string;
disabled?: boolean;
units?: DurationUnit[];
/** Set by a Field in an error state; reaches the input, not the wrapper. */
ariaInvalid?: boolean | "true" | "false";
}>();
const model = defineModel<string>({ required: true });
const units = computed(() => props.units ?? DURATION_UNITS);
@@ -47,7 +53,7 @@ function emitChange() {
:id="id"
:model-value="amount"
type="text"
:aria-invalid="invalid ? true : undefined"
:aria-invalid="invalid || ariaInvalid === true || ariaInvalid === 'true' ? true : undefined"
@update:model-value="(value: string | number) => { amount = value; emitChange(); }"
inputmode="decimal"
class="font-mono"
@@ -0,0 +1,26 @@
<script setup lang="ts">
import type { RadioGroupRootEmits, RadioGroupRootProps } from 'reka-ui'
import type { HTMLAttributes } from 'vue'
import { reactiveOmit } from '@vueuse/core'
import { cn } from '@/lib/utils'
import { RadioGroupRoot, useForwardPropsEmits } from 'reka-ui'
const props = defineProps<RadioGroupRootProps & { class?: HTMLAttributes['class'] }>()
const emits = defineEmits<RadioGroupRootEmits>()
const delegatedProps = reactiveOmit(props, 'class')
const forwarded = useForwardPropsEmits(delegatedProps, emits)
</script>
<template>
<RadioGroupRoot
v-slot="slotProps"
data-slot="radio-group"
:class="cn('grid gap-2 w-full', props.class)"
v-bind="forwarded"
>
<slot v-bind="slotProps" />
</RadioGroupRoot>
</template>
@@ -0,0 +1,42 @@
<script setup lang="ts">
import type { RadioGroupItemProps } from 'reka-ui'
import type { HTMLAttributes } from 'vue'
import { CircleIcon } from '@lucide/vue'
import { reactiveOmit } from '@vueuse/core'
import { cn } from '@/lib/utils'
import {
RadioGroupIndicator,
RadioGroupItem,
useForwardProps,
} from 'reka-ui'
const props = defineProps<RadioGroupItemProps & { class?: HTMLAttributes['class'] }>()
const delegatedProps = reactiveOmit(props, 'class')
const forwardedProps = useForwardProps(delegatedProps)
</script>
<template>
<RadioGroupItem
data-slot="radio-group-item"
v-bind="forwardedProps"
:class="
cn(
'border-input dark:bg-input/30 data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary data-checked:border-primary aria-invalid:aria-checked:border-primary aria-invalid:border-destructive focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 dark:aria-invalid:border-destructive/50 flex size-4 rounded-full focus-visible:ring-3 aria-invalid:ring-3 group/radio-group-item peer relative aspect-square shrink-0 border outline-none after:absolute after:-inset-x-3 after:-inset-y-2 disabled:cursor-not-allowed disabled:opacity-50',
props.class,
)
"
>
<RadioGroupIndicator
data-slot="radio-group-indicator"
class="flex size-4 items-center justify-center"
>
<slot>
<CircleIcon class="bg-primary-foreground absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2 rounded-full" />
</slot>
</RadioGroupIndicator>
</RadioGroupItem>
</template>
@@ -0,0 +1,3 @@
export { default as RadioGroup } from './RadioGroup.vue'
export { default as RadioGroupItem } from './RadioGroupItem.vue'
+110 -18
View File
@@ -7,7 +7,7 @@ import { Textarea } from "@/components/ui/textarea";
import { Switch } from "@/components/ui/switch";
import { DurationInput } from "@/components/ui/duration-input";
import { Section } from "@/components/ui/section";
import { SettingRow } from "@/components/ui/setting-row";
import { Field, FieldContent, FieldGroup, FieldLabel } from "@/components/ui/field";
import { useSettingsStore } from "@/stores/settings";
import ApplyStatusRows from "@/settings/ApplyStatusRows.vue";
import HistoryLink from "@/settings/HistoryLink.vue";
@@ -35,19 +35,25 @@ interface Definition {
const KIND = "curators";
const store = useSettingsStore();
onMounted(store.load);
const definitions = computed(() => store.drafts[KIND]?.value as Definition[] | null);
const form = computed(() => store.formFor(KIND));
const definitions = computed(() => store.draftValue(KIND) as Definition[] | null);
const editing = ref(false);
const newName = ref("");
// The list is the whole document, so adding or removing rebuilds it.
function add() {
const name = newName.value.trim();
if (!name || definitions.value?.some(def => def.name === name)) return;
const draft = store.drafts[KIND];
if (!draft) return;
if (!draft.value) draft.value = [];
(draft.value as Definition[]).push({name,enabled:false,instructions:"",interval:"1h",cooldown:"0s",on_input:false,tools:[],skills:false,memory_engine:"",conversations:false,model:""});
if (!form.value) return;
const def: Definition = {name,enabled:false,instructions:"",interval:"1h",cooldown:"0s",on_input:false,tools:[],skills:false,memory_engine:"",conversations:false,model:""};
store.setDraftValue(KIND, [...(definitions.value ?? []), def]);
newName.value = "";
}
function setTools(def: Definition, value: string | number) { def.tools = String(value).split(",").map(tool => tool.trim()).filter(Boolean); }
function remove(index: number) {
store.setDraftValue(KIND, (definitions.value ?? []).filter((_, i) => i !== index));
}
function toolsFromText(value: string | number): string[] {
return String(value).split(",").map(tool => tool.trim()).filter(Boolean);
}
watch(() => store.applyStatusFor(KIND).map(row => row.version).join(","), () => void load());
const curators = ref<Curator[]>([]);
const loadError = ref<string | null>(null);
@@ -75,17 +81,103 @@ onMounted(load);
<form class="mb-4 flex gap-2" @submit.prevent="add"><Input v-model="newName" aria-label="Curator name" placeholder="Curator name" class="max-w-xs" /><Button type="submit" :disabled="!newName.trim() || definitions?.some(def => def.name === newName.trim())">Add curator</Button></form>
<Empty v-if="!definitions?.length"><EmptyHeader><EmptyTitle>No custom curator definitions</EmptyTitle></EmptyHeader></Empty>
<Section v-for="(def, index) in definitions" :key="index" :title="def.name">
<template #action><Button variant="ghost" size="sm" @click="definitions!.splice(index, 1)">Remove curator</Button></template>
<SettingRow label="Enabled"><Switch v-model="def.enabled" :aria-label="`${def.name} enabled`" /></SettingRow>
<SettingRow label="Instructions" :for="`curator-${index}-instructions`"><Textarea :id="`curator-${index}-instructions`" v-model="def.instructions" /></SettingRow>
<SettingRow label="Interval"><DurationInput v-model="def.interval" :units="['s', 'm', 'h']" /></SettingRow>
<SettingRow label="Cooldown"><DurationInput v-model="def.cooldown" :units="['s', 'm', 'h']" /></SettingRow>
<SettingRow label="Wake on input"><Switch v-model="def.on_input" :aria-label="`${def.name} wake on input`" /></SettingRow>
<SettingRow label="Tools" :for="`curator-${index}-tools`"><Input :id="`curator-${index}-tools`" :model-value="(def.tools ?? []).join(', ')" @update:model-value="setTools(def, $event)" /></SettingRow>
<SettingRow label="Skills"><Switch v-model="def.skills" :aria-label="`${def.name} skills`" /></SettingRow>
<SettingRow label="Memory engine" :for="`curator-${index}-memory`"><Input :id="`curator-${index}-memory`" v-model="def.memory_engine" /></SettingRow>
<SettingRow label="Conversations"><Switch v-model="def.conversations" :aria-label="`${def.name} conversations`" /></SettingRow>
<SettingRow label="Model" :for="`curator-${index}-model`"><Input :id="`curator-${index}-model`" v-model="def.model" placeholder="Default model" /></SettingRow>
<template #action><Button variant="ghost" size="sm" @click="remove(index)">Remove curator</Button></template>
<FieldGroup v-if="form" class="@container/field-group">
<form.Field v-slot="{ field }" :name="`${index}.enabled`">
<Field orientation="responsive">
<FieldContent><FieldLabel>Enabled</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Switch :model-value="field.state.value" :aria-label="`${def.name} enabled`" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${index}.instructions`">
<Field orientation="responsive">
<FieldContent><FieldLabel :for="`curator-${index}-instructions`">Instructions</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Textarea :id="`curator-${index}-instructions`" :model-value="field.state.value" @blur="field.handleBlur" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${index}.interval`">
<Field orientation="responsive">
<FieldContent><FieldLabel>Interval</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<DurationInput :model-value="field.state.value" :units="['s', 'm', 'h']" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${index}.cooldown`">
<Field orientation="responsive">
<FieldContent><FieldLabel>Cooldown</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<DurationInput :model-value="field.state.value" :units="['s', 'm', 'h']" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${index}.on_input`">
<Field orientation="responsive">
<FieldContent><FieldLabel>Wake on input</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Switch :model-value="field.state.value" :aria-label="`${def.name} wake on input`" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${index}.tools`">
<Field orientation="responsive">
<FieldContent><FieldLabel :for="`curator-${index}-tools`">Tools</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input
:id="`curator-${index}-tools`"
:model-value="(field.state.value ?? []).join(', ')"
@blur="field.handleBlur"
@update:model-value="(value) => field.handleChange(toolsFromText(value))"
/>
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${index}.skills`">
<Field orientation="responsive">
<FieldContent><FieldLabel>Skills</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Switch :model-value="field.state.value" :aria-label="`${def.name} skills`" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${index}.memory_engine`">
<Field orientation="responsive">
<FieldContent><FieldLabel :for="`curator-${index}-memory`">Memory engine</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input :id="`curator-${index}-memory`" :model-value="field.state.value" @blur="field.handleBlur" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${index}.conversations`">
<Field orientation="responsive">
<FieldContent><FieldLabel>Conversations</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Switch :model-value="field.state.value" :aria-label="`${def.name} conversations`" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${index}.model`">
<Field orientation="responsive">
<FieldContent><FieldLabel :for="`curator-${index}-model`">Model</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input :id="`curator-${index}-model`" :model-value="field.state.value" placeholder="Default model" @blur="field.handleBlur" @update:model-value="field.handleChange" />
</div>
</Field>
</form.Field>
</FieldGroup>
</Section>
</div>
+46 -22
View File
@@ -22,31 +22,44 @@ interface Provider {
const store = useSettingsStore();
onMounted(() => store.load());
const aliases = computed(() => store.drafts["model-aliases"]?.value as Record<string, string> | undefined);
const providers = computed(() => store.drafts["provider-settings"]?.value as Record<string, Provider> | undefined);
// Map keys are free text, so entries are read from the draft and written whole
// through setDraftEntry; a key is never a form field path.
const aliases = computed(() => store.draftValue("model-aliases") as Record<string, string> | undefined);
const providers = computed(() => store.draftValue("provider-settings") as Record<string, Provider> | undefined);
const aliasEntries = computed(() => Object.entries(aliases.value ?? {}));
const providerEntries = computed(() => Object.entries(providers.value ?? {}));
const errors = computed(() => ["model-aliases", "provider-settings"].map((k) => store.pageErrorFor(k)).filter(Boolean));
const issue = (alias: string) => store.issuesFor("model-aliases").find((entry) => entry.path === alias);
const aliasIssues = computed(() => store.issuesFor("model-aliases"));
const issue = (alias: string) => aliasIssues.value.find((entry) => entry.path === alias);
function setAlias(alias: string, model: string) {
if (!aliases.value) return;
if (model.trim()) aliases.value[alias] = model.trim();
else delete aliases.value[alias];
store.setDraftEntry("model-aliases", alias, model.trim() || undefined);
}
function removeAlias(alias: string) {
store.setDraftEntry("model-aliases", alias, undefined);
}
const newAlias = ref("");
function addAlias() {
const name = newAlias.value.trim();
if (!aliases.value || !name || name in aliases.value) return;
aliases.value[name] = "";
if (!aliases.value || !name || aliases.value[name] !== undefined) return;
store.setDraftEntry("model-aliases", name, "");
newAlias.value = "";
}
const newProvider = ref("");
function addProvider() {
const name = newProvider.value.trim();
if (!providers.value || !name || providers.value[name]) return;
providers.value[name] = { class: "openai", api_key_ref: { engine: "", key: "" } };
store.setDraftEntry("provider-settings", name, { class: "openai", api_key_ref: { engine: "", key: "" } });
newProvider.value = "";
}
const bound = computed(() => new Set(((store.drafts["credential-bindings"]?.value as { service: string }[] | null) ?? []).map((b) => b.service)));
function setProvider(name: string, next: Partial<Provider>) {
const current = providers.value?.[name];
if (current) store.setDraftEntry("provider-settings", name, { ...current, ...next });
}
function removeProvider(name: string) {
store.setDraftEntry("provider-settings", name, undefined);
}
const bound = computed(() => new Set(((store.draftValue("credential-bindings") as { service: string }[] | null) ?? []).map((b) => b.service)));
</script>
<template>
@@ -56,19 +69,19 @@ const bound = computed(() => new Set(((store.drafts["credential-bindings"]?.valu
<template v-if="aliases">
<Section title="Aliases">
<div v-for="(model, alias) in aliases" :key="alias" class="flex flex-wrap items-center gap-3 border-b border-border py-2.5 last-of-type:border-b-0">
<div v-for="[alias, model] in aliasEntries" :key="alias" class="flex flex-wrap items-center gap-3 border-b border-border py-2.5 last-of-type:border-b-0">
<label :for="`org-alias-${alias}`" class="w-28 font-mono text-sm font-medium">{{ alias }}</label>
<Input
:id="`org-alias-${alias}`"
:model-value="model"
:model-value="model ?? ''"
class="max-w-md flex-1 font-mono max-sm:basis-full"
placeholder="provider/model"
:aria-invalid="issue(String(alias)) ? true : undefined"
@update:model-value="(v) => setAlias(String(alias), String(v))"
:aria-invalid="!!issue(alias)"
@update:model-value="(v) => setAlias(alias, String(v))"
/>
<DraftHint kind="model-aliases" :path="String(alias)" />
<span v-if="issue(String(alias))" class="text-xs text-danger">{{ issue(String(alias))?.message }}</span>
<Button variant="ghost" size="icon" class="ml-auto" :aria-label="`Remove alias ${alias}`" @click="delete aliases[alias]"><Trash2 /></Button>
<DraftHint kind="model-aliases" :path="alias" />
<span v-if="issue(alias)" class="text-xs text-danger">{{ issue(alias)?.message }}</span>
<Button variant="ghost" size="icon" class="ml-auto" :aria-label="`Remove alias ${alias}`" @click="removeAlias(alias)"><Trash2 /></Button>
</div>
<form class="flex gap-2 border-t border-border pt-3" @submit.prevent="addAlias">
<Input v-model="newAlias" class="max-w-56 font-mono" placeholder="alias, e.g. default" aria-label="New alias" />
@@ -79,12 +92,23 @@ const bound = computed(() => new Set(((store.drafts["credential-bindings"]?.valu
<template v-if="providers">
<Section title="Providers">
<div v-for="(provider, name) in providers" :key="name" class="flex flex-wrap items-center gap-3 border-b border-border py-2.5 last-of-type:border-b-0">
<div v-for="[name, provider] in providerEntries" :key="name" class="flex flex-wrap items-center gap-3 border-b border-border py-2.5 last-of-type:border-b-0">
<span class="w-28 font-mono text-sm font-medium">{{ name }}</span>
<Input v-model="provider.class" class="w-36 font-mono" :aria-label="`Class for ${name}`" />
<Input v-model="provider.base_url" class="max-w-md flex-1 font-mono max-sm:basis-full" placeholder="base URL (empty: class default)" :aria-label="`Base URL for ${name}`" />
<RouterLink v-if="!bound.has(String(name))" to="/org/credential-bindings" class="text-xs text-warn hover:underline">Add a credential binding named "{{ name }}"</RouterLink>
<Button variant="ghost" size="icon" class="ml-auto" :aria-label="`Remove provider ${name}`" @click="delete providers[name]"><Trash2 /></Button>
<Input
:model-value="provider.class"
class="w-36 font-mono"
:aria-label="`Class for ${name}`"
@update:model-value="(v) => setProvider(name, { class: String(v) })"
/>
<Input
:model-value="provider.base_url ?? ''"
class="max-w-md flex-1 font-mono max-sm:basis-full"
placeholder="base URL (empty: class default)"
:aria-label="`Base URL for ${name}`"
@update:model-value="(v) => setProvider(name, { base_url: String(v) })"
/>
<RouterLink v-if="!bound.has(name)" to="/org/credential-bindings" class="text-xs text-warn hover:underline">Add a credential binding named "{{ name }}"</RouterLink>
<Button variant="ghost" size="icon" class="ml-auto" :aria-label="`Remove provider ${name}`" @click="removeProvider(name)"><Trash2 /></Button>
</div>
<form class="flex gap-2 border-t border-border pt-3" @submit.prevent="addProvider">
<Input v-model="newProvider" class="max-w-56 font-mono" placeholder="provider name" aria-label="New provider" />
+45 -16
View File
@@ -19,6 +19,7 @@ import { Button } from "@/components/ui/button";
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
import { DropdownMenuItem, DropdownMenuSeparator } from "@/components/ui/dropdown-menu";
import { DurationInput } from "@/components/ui/duration-input";
import { Field, FieldContent, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Empty, EmptyContent, EmptyHeader, EmptyMedia, EmptyTitle } from "@/components/ui/empty";
import { MoreMenu } from "@/components/ui/more-menu";
import {
@@ -29,7 +30,6 @@ import {
NumberFieldInput,
} from "@/components/ui/number-field";
import { Section } from "@/components/ui/section";
import { SettingRow } from "@/components/ui/setting-row";
import { Skeleton } from "@/components/ui/skeleton";
import { Switch } from "@/components/ui/switch";
import { Timestamp } from "@/components/ui/timestamp";
@@ -70,7 +70,8 @@ const store = useSettingsStore();
const { catalog } = storeToRefs(store);
onMounted(store.load);
const resources = computed(() => resourcesForPage(catalog.value, "schedules"));
const settings = computed(() => store.drafts[SETTINGS]?.value as ScheduleSettings | undefined);
const form = computed(() => store.formFor(SETTINGS));
const settings = computed(() => store.draftValue(SETTINGS) as ScheduleSettings | undefined);
const settingsError = computed(() => store.pageErrorFor(SETTINGS));
const zone = computed(() => settings.value?.time_zone || "UTC");
@@ -217,20 +218,48 @@ const remove = () =>
<Section v-if="settings" title="Settings" class="mt-6">
<p v-if="settingsError" class="text-sm text-danger" role="alert">{{ settingsError }}</p>
<SettingRow label="Cron time zone" for="schedule-zone">
<ZoneSelect id="schedule-zone" v-model="settings.time_zone" aria-label="Cron time zone" />
<DraftHint :kind="SETTINGS" path="time_zone" />
</SettingRow>
<SettingRow label="Keep runs for">
<DurationInput v-model="settings.run_retention" :units="['h']" />
<DraftHint :kind="SETTINGS" path="run_retention" />
</SettingRow>
<SettingRow label="Runs kept per schedule" for="schedule-keep">
<NumberField id="schedule-keep" v-model="settings.run_retention_count" :min="1" class="w-32">
<NumberFieldContent><NumberFieldDecrement /><NumberFieldInput /><NumberFieldIncrement /></NumberFieldContent>
</NumberField>
<DraftHint :kind="SETTINGS" path="run_retention_count" />
</SettingRow>
<FieldGroup v-if="form" class="@container/field-group">
<form.Field v-slot="{ field }" name="time_zone">
<Field orientation="responsive">
<FieldContent><FieldLabel for="schedule-zone">Cron time zone</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<ZoneSelect
id="schedule-zone"
:model-value="field.state.value"
aria-label="Cron time zone"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="SETTINGS" path="time_zone" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="run_retention">
<Field orientation="responsive">
<FieldContent><FieldLabel>Keep runs for</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<DurationInput :model-value="field.state.value" :units="['h']" @update:model-value="field.handleChange" />
<DraftHint :kind="SETTINGS" path="run_retention" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="run_retention_count">
<Field orientation="responsive">
<FieldContent><FieldLabel for="schedule-keep">Runs kept per schedule</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<NumberField
id="schedule-keep"
:model-value="field.state.value"
:min="1"
class="w-32"
@update:model-value="field.handleChange"
>
<NumberFieldContent><NumberFieldDecrement /><NumberFieldInput /><NumberFieldIncrement /></NumberFieldContent>
</NumberField>
<DraftHint :kind="SETTINGS" path="run_retention_count" />
</div>
</Field>
</form.Field>
</FieldGroup>
</Section>
<ScheduleEditor v-model:open="editorOpen" :schedule="editing" :title="editorTitle" @saved="replace" />
+52 -15
View File
@@ -3,8 +3,8 @@ import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { computed, onMounted, ref } from "vue";
import PageHeader from "@/base/PageHeader.vue";
import { Button } from "@/components/ui/button";
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { SettingRow } from "@/components/ui/setting-row";
import { useSettingsStore } from "@/stores/settings";
import ApplyStatusRows from "./ApplyStatusRows.vue";
import CardAccordion from "./CardAccordion.vue";
@@ -14,24 +14,33 @@ interface Profile { image?: string; kit?: string; adapter?: string; tools?: stri
const KIND = "agent-profiles";
const store = useSettingsStore();
onMounted(store.load);
const profiles = computed(() => store.drafts[KIND]?.value as Record<string, Profile> | null);
const profiles = computed(() => store.draftValue(KIND) as Record<string, Profile> | null);
const name = ref("");
const open = ref("");
const unsaved = computed(() => store.changesFor(KIND).length > 0);
const entries = computed(() => Object.entries(profiles.value ?? {}));
// Profile names are free text, so a profile is written as a whole map entry
// rather than by a dotted per-profile path.
function add() {
if (unsaved.value) return;
if (unsaved.value || !store.formFor(KIND)) return;
const key = name.value.trim();
if (!key || profiles.value?.[key]) return;
const draft = store.drafts[KIND];
if (!draft) return;
if (!draft.value) draft.value = {};
(draft.value as Record<string, Profile>)[key] = { image: "", kit: "", adapter: "", tools: [] };
store.setDraftEntry(KIND, key, { image: "", kit: "", adapter: "", tools: [] });
// Integer-like names sort first in a JS object, so find where the key landed.
open.value = String(entries.value.findIndex(([k]) => k === key));
name.value = "";
open.value = String(Object.keys(draft.value as Record<string, Profile>).indexOf(key));
}
function tools(profile: Profile, value: string | number) {
profile.tools = String(value).split(",").map(tool => tool.trim()).filter(Boolean);
function removeProfile(index: number) {
const key = entries.value[index]?.[0];
if (!key) return;
store.setDraftEntry(KIND, key, undefined);
}
function patch(key: string, changes: Partial<Profile>) {
store.setDraftEntry(KIND, key, { ...profiles.value?.[key], ...changes });
}
function parseTools(value: string | number): string[] {
return String(value).split(",").map(tool => tool.trim()).filter(Boolean);
}
</script>
<template>
@@ -44,12 +53,40 @@ function tools(profile: Profile, value: string | number) {
<Button type="submit" :disabled="unsaved || !name.trim() || !!profiles?.[name.trim()]">Add profile</Button>
</form>
<Empty v-if="!Object.keys(profiles ?? {}).length"><EmptyHeader><EmptyTitle>No agent profiles</EmptyTitle></EmptyHeader></Empty>
<CardAccordion v-model:open="open" :items="entries" :title="([key]) => key" remove-label="Remove" mono @remove="delete profiles![entries[$event]![0]]">
<CardAccordion v-model:open="open" :items="entries" :title="([key]) => key" remove-label="Remove" mono @remove="removeProfile">
<template #default="{ item: [key, profile] }">
<SettingRow label="Image" :for="`${key}-image`"><Input :id="`${key}-image`" v-model="profile.image" placeholder="Container image" /></SettingRow>
<SettingRow label="Kit" :for="`${key}-kit`" hint="Pinned digest. Used only when Image is empty."><Input :id="`${key}-kit`" v-model="profile.kit" placeholder="registry/kit@sha256:…" /></SettingRow>
<SettingRow label="Adapter" :for="`${key}-adapter`"><Input :id="`${key}-adapter`" v-model="profile.adapter" /></SettingRow>
<SettingRow label="Tools" :for="`${key}-tools`" hint="Comma-separated tool names."><Input :id="`${key}-tools`" :model-value="(profile.tools ?? []).join(', ')" @update:model-value="tools(profile, $event)" /></SettingRow>
<FieldGroup class="@container/field-group">
<Field orientation="responsive">
<FieldContent><FieldLabel :for="`${key}-image`">Image</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input :id="`${key}-image`" :model-value="profile.image" placeholder="Container image" @update:model-value="(v) => patch(key, { image: String(v) })" />
</div>
</Field>
<Field orientation="responsive">
<FieldContent>
<FieldLabel :for="`${key}-kit`">Kit</FieldLabel>
<FieldDescription>Pinned digest. Used only when Image is empty.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input :id="`${key}-kit`" :model-value="profile.kit" placeholder="registry/kit@sha256:…" @update:model-value="(v) => patch(key, { kit: String(v) })" />
</div>
</Field>
<Field orientation="responsive">
<FieldContent><FieldLabel :for="`${key}-adapter`">Adapter</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input :id="`${key}-adapter`" :model-value="profile.adapter" @update:model-value="(v) => patch(key, { adapter: String(v) })" />
</div>
</Field>
<Field orientation="responsive">
<FieldContent>
<FieldLabel :for="`${key}-tools`">Tools</FieldLabel>
<FieldDescription>Comma-separated tool names.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input :id="`${key}-tools`" :model-value="(profile.tools ?? []).join(', ')" @update:model-value="(v) => patch(key, { tools: parseTools(v) })" />
</div>
</Field>
</FieldGroup>
</template>
</CardAccordion>
</div>
+27 -18
View File
@@ -24,12 +24,17 @@ import {
// The card mutates the draft object it is given, the way every settings page
// edits its draft in place; it never reassigns the prop.
const props = defineProps<{ connection: Connection; index: number }>();
const props = defineProps<{ index: number }>();
const connection = defineModel<Connection>({ required: true });
// The bound connection belongs to a settings form, so an edit emits a new one.
function patch(change: Partial<Connection>): void {
connection.value = { ...connection.value, ...change };
}
const extensions = useExtensionsStore();
onMounted(() => void extensions.loadInstalled());
const org = useOrgStore();
const unavailable = computed(() => !!props.connection.type && !extensions.forges.some((e) => e.name === props.connection.type));
const unavailable = computed(() => !!connection.value.type && !extensions.forges.some((e) => e.name === connection.value.type));
</script>
<template>
@@ -37,7 +42,8 @@ const unavailable = computed(() => !!props.connection.type && !extensions.forges
<div class="flex flex-wrap items-center gap-3">
<Input
:id="`connection-${props.index}-id`"
v-model="props.connection.id"
:model-value="connection.id"
@update:model-value="(value: string | number) => patch({ id: String(value) })"
class="max-w-56 font-mono"
aria-label="Connection ID"
/>
@@ -48,7 +54,8 @@ const unavailable = computed(() => !!props.connection.type && !extensions.forges
<div class="flex flex-wrap items-center gap-3">
<Input
:id="`connection-${props.index}-name`"
v-model="props.connection.name"
:model-value="connection.name"
@update:model-value="(value: string | number) => patch({ name: String(value) })"
class="max-w-72"
placeholder="GitHub (platform team)"
/>
@@ -57,11 +64,11 @@ const unavailable = computed(() => !!props.connection.type && !extensions.forges
</SettingRow>
<SettingRow label="Forge" :for="`connection-${props.index}-type`">
<div class="flex flex-wrap items-center gap-3">
<Select v-model="props.connection.type">
<SelectTrigger :id="`connection-${props.index}-type`" class="max-w-56"><SelectValue>{{ props.connection.type ? extensions.forgeName(props.connection.type) : "Choose" }}</SelectValue></SelectTrigger>
<Select :model-value="connection.type" @update:model-value="(type) => patch({ type: String(type ?? '') })">
<SelectTrigger :id="`connection-${props.index}-type`" class="max-w-56"><SelectValue>{{ connection.type ? extensions.forgeName(connection.type) : "Choose" }}</SelectValue></SelectTrigger>
<SelectContent><SelectGroup>
<SelectItem v-for="forge in extensions.forges" :key="forge.name" :value="forge.name">{{ forge.display_name || forge.name }}</SelectItem>
<SelectItem v-if="unavailable" :value="props.connection.type">{{ props.connection.type }} · not enabled</SelectItem>
<SelectItem v-if="unavailable" :value="connection.type">{{ connection.type }} · not enabled</SelectItem>
</SelectGroup></SelectContent>
</Select>
</div>
@@ -70,7 +77,8 @@ const unavailable = computed(() => !!props.connection.type && !extensions.forges
<div class="flex flex-wrap items-center gap-3">
<Input
:id="`connection-${props.index}-host`"
v-model="props.connection.host"
:model-value="connection.host"
@update:model-value="(value: string | number) => patch({ host: String(value) })"
class="max-w-72 font-mono"
placeholder="https://github.com"
/>
@@ -79,32 +87,33 @@ const unavailable = computed(() => !!props.connection.type && !extensions.forges
</SettingRow>
<SettingRow label="External account">
<Input
v-model="props.connection.account"
:model-value="connection.account"
@update:model-value="(value: string | number) => patch({ account: String(value) })"
class="max-w-56 font-mono"
placeholder="acme-bot"
aria-label="External account"
/>
</SettingRow>
<SettingRow label="Credential">
<SecretRefField v-model="props.connection.token" :id-prefix="`connection-${props.index}-token`" />
<SecretRefField :model-value="connection.token" @update:model-value="(token) => patch({ token })" :id-prefix="`connection-${props.index}-token`" />
</SettingRow>
<SettingRow label="Permitted operations">
<div class="w-full space-y-2">
<div
v-for="[identity, operations] in permits(props.connection)"
v-for="[identity, operations] in permits(connection)"
:key="`${props.index}-${identity}`"
class="flex flex-wrap items-center gap-3"
>
<Select
:model-value="identity || undefined"
@update:model-value="(to) => renamePermit(props.connection, identity, String(to))"
@update:model-value="(to) => (connection = renamePermit(connection, identity, String(to)))"
>
<SelectTrigger class="max-w-72" :aria-label="`Permitted identity for ${props.connection.id}`">
<SelectTrigger class="max-w-72" :aria-label="`Permitted identity for ${connection.id}`">
<SelectValue>{{ identity ? org.identityName(identity) : "Choose" }}</SelectValue>
</SelectTrigger>
<SelectContent><SelectGroup>
<SelectItem v-for="actor in choosableIdentities(props.connection, org.activeIdentities, identity)" :key="actor.id" :value="actor.id">{{ actor.display_name || actor.id }}</SelectItem>
<SelectItem v-if="identity && !choosableIdentities(props.connection, org.activeIdentities, identity).some((a) => a.id === identity)" :value="identity">{{ org.identityName(identity) }} · unavailable</SelectItem>
<SelectItem v-for="actor in choosableIdentities(connection, org.activeIdentities, identity)" :key="actor.id" :value="actor.id">{{ actor.display_name || actor.id }}</SelectItem>
<SelectItem v-if="identity && !choosableIdentities(connection, org.activeIdentities, identity).some((a) => a.id === identity)" :value="identity">{{ org.identityName(identity) }} · unavailable</SelectItem>
</SelectGroup></SelectContent>
</Select>
<label
@@ -115,15 +124,15 @@ const unavailable = computed(() => !!props.connection.type && !extensions.forges
<Switch
:model-value="operations.includes(operation)"
:aria-label="`${operation} for ${identity || 'the identity'}`"
@update:model-value="(on: boolean) => toggleOperation(props.connection, identity, operation, on)"
@update:model-value="(on: boolean) => (connection = toggleOperation(connection, identity, operation, on))"
/>
<span class="font-mono text-xs">{{ operation }}</span>
</label>
<Button variant="ghost" size="sm" @click="removePermit(props.connection, identity)">
<Button variant="ghost" size="sm" @click="connection = removePermit(connection, identity)">
Remove
</Button>
</div>
<Button variant="outline" size="sm" @click="addPermit(props.connection)">
<Button variant="outline" size="sm" @click="connection = addPermit(connection)">
<Plus data-icon="inline-start" />Add identity
</Button>
</div>
+37 -16
View File
@@ -25,28 +25,45 @@ onMounted(() => {
});
const resources = computed(() => resourcesForPage(catalog.value, "connections"));
const draft = computed(() => store.drafts[KIND]);
const connections = computed(() => (draft.value?.value ?? []) as Connection[]);
const form = computed(() => store.formFor(KIND));
const connections = computed(() => (store.draftValue(KIND) ?? []) as Connection[]);
const error = computed(() => store.pageErrorFor(KIND));
const open = ref("0");
const unsaved = computed(() => store.changesFor(KIND).length > 0);
// Each edit writes a new array: the document is a root list, and the draft
// value is read-only outside the store.
function setConnections(next: Connection[]) {
store.setDraftValue(KIND, next);
}
function updateConnection(index: number, next: Connection) {
setConnections(connections.value.map((c, j) => (j === index ? next : c)));
}
function removeConnection(index: number) {
setConnections(connections.value.filter((_, j) => j !== index));
}
function addConnection() {
if (unsaved.value) return;
draft.value.value ??= [];
const used = new Set(connections.value.map((c) => c.id));
let id = "connection";
for (let n = 2; used.has(id); n++) id = `connection-${n}`;
connections.value.push({
id,
name: "",
type: "github",
host: "",
account: "",
token: { engine: "", key: "" },
permits: {},
});
open.value = String(connections.value.length - 1);
const next = [
...connections.value,
{
id,
name: "",
type: "github",
host: "",
account: "",
token: { engine: "", key: "" },
permits: {},
},
];
setConnections(next);
open.value = String(next.length - 1);
}
</script>
@@ -66,7 +83,7 @@ function addConnection() {
{{ catalogError || error }}
</p>
<template v-if="draft">
<template v-if="form">
<div class="mb-4 flex flex-wrap items-center gap-2">
<Button size="sm" :disabled="unsaved" @click="addConnection">
<Plus data-icon="inline-start" />Add connection
@@ -82,10 +99,14 @@ function addConnection() {
:title="(item) => item.name || item.id"
remove-label="Remove"
mono
@remove="connections.splice($event, 1)"
@remove="removeConnection"
>
<template #default="slot">
<ConnectionCard :connection="slot.item" :index="slot.index" />
<ConnectionCard
:model-value="slot.item"
:index="slot.index"
@update:model-value="(next: Connection) => updateConnection(slot.index, next)"
/>
</template>
</CardAccordion>
+132 -53
View File
@@ -2,9 +2,12 @@
import ApplyStatusRows from "./ApplyStatusRows.vue";
import { computed, onMounted } from "vue";
import { storeToRefs } from "pinia";
import { TriangleAlert } from "@lucide/vue";
import PageHeader from "@/base/PageHeader.vue";
import { DurationInput } from "@/components/ui/duration-input";
import { parseGoDuration } from "@/components/ui/duration-input/duration";
import { Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import {
NumberField,
@@ -14,12 +17,15 @@ import {
NumberFieldInput,
} from "@/components/ui/number-field";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
import { SettingRow } from "@/components/ui/setting-row";
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
import DraftHint from "./DraftHint.vue";
import HistoryLink from "./HistoryLink.vue";
import { fieldInvalid } from "./settings-form";
const KIND = "container-runtime-policies";
const EXECUTION_KIND = "workflow-execution-settings";
// The server's own default when execution settings predate the task limit.
const DEFAULT_TASK_RUNTIME_SECONDS = 4 * 60 * 60;
// The stored document is containerRuntimePolicies on the wire: snake_case keys
// and durations as Go duration strings.
@@ -37,19 +43,30 @@ const { catalog, catalogError } = storeToRefs(store);
onMounted(store.load);
const resources = computed(() => resourcesForPage(catalog.value, "containers"));
const runtime = computed(() => store.drafts[KIND]?.value as ContainerRuntime | undefined);
const form = computed(() => store.formFor(KIND));
const runtime = computed(() => store.draftValue(KIND) as ContainerRuntime | undefined);
const error = computed(() => store.pageErrorFor(KIND));
const pullPolicies = [
{ value: "missing", label: "If missing" },
{ value: "always", label: "Always" },
];
const pullPolicy = computed({
get: () => runtime.value?.pull_policy || "missing",
set: (value: string) => {
if (runtime.value) runtime.value.pull_policy = value;
},
// The daemon kills a container at max uptime, so a task limit longer than it
// can never be reached. Mirrors the warning archied logs when it applies them.
const uptimeWarning = computed(() => {
const uptime = parseGoDuration(runtime.value?.max_uptime ?? "");
if (!uptime) return "";
const execution = store.draftValue(EXECUTION_KIND) as { max_task_runtime_seconds?: number | null } | undefined;
const limitSeconds = execution?.max_task_runtime_seconds ?? DEFAULT_TASK_RUNTIME_SECONDS;
if (limitSeconds > 0 && limitSeconds * 1000 <= uptime) return "";
const limit = limitSeconds > 0 ? `the ${formatHours(limitSeconds)} task limit` : "the task limit, which is off";
return `Shorter than ${limit}, so containers are killed before a task can finish.`;
});
function formatHours(seconds: number): string {
return seconds % 3600 === 0 ? `${seconds / 3600}h` : `${Math.round(seconds / 60)}m`;
}
</script>
<template>
@@ -61,51 +78,113 @@ const pullPolicy = computed({
<p v-if="catalogError || error" class="mb-4 text-sm text-danger" role="alert">{{ catalogError || error }}</p>
<template v-if="runtime">
<SettingRow label="Image" for="cr-image">
<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">
<div class="flex flex-wrap items-center gap-3">
<ToggleGroup type="single" variant="outline" size="sm" :model-value="pullPolicy" aria-label="Pull policy" @update:model-value="(value) => { if (value) pullPolicy = value as typeof pullPolicy; }">
<ToggleGroupItem v-for="option in pullPolicies" :key="option.value" :value="option.value">{{ option.label }}</ToggleGroupItem>
</ToggleGroup>
<DraftHint :kind="KIND" path="pull_policy" />
</div>
</SettingRow>
<SettingRow label="Max concurrency" hint="0 = no limit.">
<div class="flex flex-wrap items-center gap-3">
<NumberField v-model="runtime.max_concurrency" :min="0" class="w-32">
<NumberFieldContent>
<NumberFieldDecrement />
<NumberFieldInput class="font-mono" aria-label="Max concurrency" />
<NumberFieldIncrement />
</NumberFieldContent>
</NumberField>
<DraftHint :kind="KIND" path="max_concurrency" />
</div>
</SettingRow>
<SettingRow label="Max uptime" for="cr-uptime">
<div class="flex flex-wrap items-center gap-3">
<DurationInput id="cr-uptime" v-model="runtime.max_uptime" :units="['m', 'h']" />
<DraftHint :kind="KIND" path="max_uptime" />
</div>
</SettingRow>
<SettingRow label="Volume retention" for="cr-ttl">
<div class="flex flex-wrap items-center gap-3">
<DurationInput id="cr-ttl" v-model="runtime.volume_ttl" :units="['h']" />
<DraftHint :kind="KIND" path="volume_ttl" />
</div>
</SettingRow>
<SettingRow label="Network" for="cr-network" hint="Empty: auto-detect.">
<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>
</template>
<FieldGroup v-if="form" class="@container/field-group">
<form.Field v-slot="{ field }" name="image">
<Field orientation="responsive" :data-invalid="fieldInvalid(field)">
<FieldContent><FieldLabel for="cr-image">Image</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input
id="cr-image"
:model-value="field.state.value"
class="font-mono"
:aria-invalid="fieldInvalid(field)"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="image" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="pull_policy">
<Field orientation="responsive">
<FieldContent><FieldLabel>Pull policy</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<ToggleGroup
type="single"
variant="outline"
size="sm"
:model-value="field.state.value || 'missing'"
aria-label="Pull policy"
@update:model-value="(value) => { if (value) field.handleChange(value); }"
>
<ToggleGroupItem v-for="option in pullPolicies" :key="option.value" :value="option.value">{{ option.label }}</ToggleGroupItem>
</ToggleGroup>
<DraftHint :kind="KIND" path="pull_policy" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="max_concurrency">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Max concurrency</FieldLabel>
<FieldDescription>0 = no limit.</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="Max concurrency" />
<NumberFieldIncrement />
</NumberFieldContent>
</NumberField>
<DraftHint :kind="KIND" path="max_concurrency" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="max_uptime">
<Field orientation="responsive" :data-invalid="fieldInvalid(field)">
<FieldContent><FieldLabel for="cr-uptime">Max uptime</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-col gap-2 @md/field-group:flex-1">
<FieldDescription v-if="uptimeWarning" class="flex items-start gap-1.5 text-warn" role="status">
<TriangleAlert class="mt-0.5 size-3.5 shrink-0" />
<span>{{ uptimeWarning }}</span>
</FieldDescription>
<div class="flex flex-wrap items-center gap-3">
<DurationInput
id="cr-uptime"
:model-value="field.state.value"
:units="['m', 'h']"
:aria-invalid="fieldInvalid(field)"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="max_uptime" />
</div>
<FieldError v-if="fieldInvalid(field)" :errors="field.state.meta.errors" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="volume_ttl">
<Field orientation="responsive">
<FieldContent><FieldLabel for="cr-ttl">Volume retention</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<DurationInput id="cr-ttl" :model-value="field.state.value" :units="['h']" @update:model-value="field.handleChange" />
<DraftHint :kind="KIND" path="volume_ttl" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="network">
<Field orientation="responsive">
<FieldContent>
<FieldLabel for="cr-network">Network</FieldLabel>
<FieldDescription>Empty: auto-detect.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input
id="cr-network"
:model-value="field.state.value"
class="max-w-sm font-mono"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="network" />
</div>
</Field>
</form.Field>
</FieldGroup>
</div>
</template>
+37 -12
View File
@@ -4,7 +4,7 @@ import { computed, onMounted, ref } from "vue";
import PageHeader from "@/base/PageHeader.vue";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { SettingRow } from "@/components/ui/setting-row";
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
import { useSettingsStore } from "@/stores/settings";
import ApplyStatusRows from "./ApplyStatusRows.vue";
import CardAccordion from "./CardAccordion.vue";
@@ -14,16 +14,21 @@ interface Binding { service: string; org?: string; secret: { engine: string; key
const KIND = "credential-bindings";
const store = useSettingsStore();
onMounted(store.load);
const bindings = computed(() => store.drafts[KIND]?.value as Binding[] | null);
// A root array: each edit builds a new array, since the draft is read-only.
const bindings = computed(() => store.draftValue(KIND) as Binding[] | null);
const open = ref("");
const unsaved = computed(() => store.changesFor(KIND).length > 0);
function add() {
if (unsaved.value) return;
const draft = store.drafts[KIND];
if (!draft) return;
if (!draft.value) draft.value = [];
(draft.value as Binding[]).push({ service: "", org: "", secret: { engine: "", key: "" } });
open.value = String((draft.value as Binding[]).length - 1);
if (unsaved.value || !store.formFor(KIND)) return;
const items = bindings.value ?? [];
store.setDraftValue(KIND, [...items, { service: "", org: "", secret: { engine: "", key: "" } }]);
open.value = String(items.length);
}
function remove(index: number) {
store.setDraftValue(KIND, (bindings.value ?? []).filter((_, i) => i !== index));
}
function patch(index: number, changes: Partial<Binding>) {
store.setDraftValue(KIND, (bindings.value ?? []).map((binding, i) => (i === index ? { ...binding, ...changes } : binding)));
}
</script>
<template>
@@ -32,11 +37,31 @@ function add() {
<ApplyStatusRows :kind="KIND" class="mb-4" />
<p v-if="store.catalogError || store.pageErrorFor(KIND)" class="mb-4 text-sm text-danger" role="alert">{{ store.catalogError || store.pageErrorFor(KIND) }}</p>
<Empty v-if="!bindings?.length"><EmptyHeader><EmptyTitle>No credential bindings</EmptyTitle></EmptyHeader></Empty>
<CardAccordion v-model:open="open" :items="bindings ?? []" :title="(b) => b.service || 'New binding'" remove-label="Remove" mono @remove="bindings!.splice($event, 1)">
<CardAccordion v-model:open="open" :items="bindings ?? []" :title="(b) => b.service || 'New binding'" remove-label="Remove" mono @remove="remove">
<template #default="{ item: binding, index }">
<SettingRow label="Service" :for="`binding-${index}-service`"><Input :id="`binding-${index}-service`" v-model="binding.service" /></SettingRow>
<SettingRow label="Organisation" :for="`binding-${index}-org`" hint="Empty uses the default organisation."><Input :id="`binding-${index}-org`" v-model="binding.org" /></SettingRow>
<SettingRow label="Secret"><SecretRefField v-model="binding.secret" :id-prefix="`binding-${index}-secret`" /></SettingRow>
<FieldGroup class="@container/field-group">
<Field orientation="responsive">
<FieldContent><FieldLabel :for="`binding-${index}-service`">Service</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input :id="`binding-${index}-service`" :model-value="binding.service" @update:model-value="(v) => patch(index, { service: String(v) })" />
</div>
</Field>
<Field orientation="responsive">
<FieldContent>
<FieldLabel :for="`binding-${index}-org`">Organisation</FieldLabel>
<FieldDescription>Empty uses the default organisation.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input :id="`binding-${index}-org`" :model-value="binding.org" @update:model-value="(v) => patch(index, { org: String(v) })" />
</div>
</Field>
<Field orientation="responsive">
<FieldContent><FieldLabel>Secret</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<SecretRefField :model-value="binding.secret" :id-prefix="`binding-${index}-secret`" @update:model-value="(secret) => patch(index, { secret })" />
</div>
</Field>
</FieldGroup>
</template>
</CardAccordion>
</div>
+10 -6
View File
@@ -25,22 +25,26 @@ onMounted(() => {
org.watchIdentities();
});
const grants = computed(() => store.drafts[KIND]?.value as IdentityGrants | undefined);
const form = computed(() => store.formFor(KIND));
const grants = computed(() => store.draftValue(KIND) as IdentityGrants | undefined);
const error = computed(() => store.pageErrorFor(KIND));
const addable = computed(() =>
org.activeIdentities.filter((a) => a.kind !== "user" && a.kind !== "system" && !(a.id in (grants.value?.identities ?? {}))),
);
// Identity ids are free text, so identities are written as whole maps rather
// than by a dotted per-id path.
function setRoot(services: string[]) {
if (grants.value) grants.value.root = services;
form.value?.api.setFieldValue("root", services);
}
function setIdentity(id: string, services: string[]) {
if (grants.value) grants.value.identities = { ...grants.value.identities, [id]: services };
form.value?.api.setFieldValue("identities", (prev: Record<string, string[]> | undefined) => ({ ...prev, [id]: services }));
}
function removeIdentity(id: string) {
if (!grants.value?.identities) return;
const { [id]: _, ...rest } = grants.value.identities;
grants.value.identities = rest;
form.value?.api.setFieldValue("identities", (prev: Record<string, string[]> | undefined) => {
const { [id]: _, ...rest } = prev ?? {};
return rest;
});
}
</script>
+19 -12
View File
@@ -9,6 +9,7 @@ import { resourcesForPage, useSettingsStore } from "@/stores/settings";
import { Section } from "@/components/ui/section";
import DraftHint from "./DraftHint.vue";
import HistoryLink from "./HistoryLink.vue";
import { fieldInvalid } from "./settings-form";
const KIND = "soul";
@@ -17,7 +18,8 @@ const { catalog, catalogError } = storeToRefs(store);
onMounted(store.load);
const resources = computed(() => resourcesForPage(catalog.value, "soul"));
const soul = computed(() => store.drafts[KIND]?.value as { text: string } | undefined);
const form = computed(() => store.formFor(KIND));
const soul = computed(() => store.draftValue(KIND) as { text: string } | undefined);
const error = computed(() => store.pageErrorFor(KIND));
const chars = computed(() => soul.value?.text.length ?? 0);
</script>
@@ -33,17 +35,22 @@ const chars = computed(() => soul.value?.text.length ?? 0);
{{ catalogError || error }}
</p>
<Section v-if="soul">
<div class="flex justify-end">
<DraftHint :kind="KIND" path="text" />
</div>
<Textarea
id="soul-text"
v-model="soul.text"
:rows="18"
class="mt-1 font-mono text-label"
aria-label="Instructions"
/>
<Section v-if="form && soul">
<form.Field v-slot="{ field }" name="text">
<div class="flex justify-end">
<DraftHint :kind="KIND" path="text" />
</div>
<Textarea
id="soul-text"
:model-value="field.state.value"
:rows="18"
class="mt-1 font-mono text-label"
aria-label="Instructions"
:aria-invalid="fieldInvalid(field)"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
</form.Field>
<p class="mt-1.5 text-xs text-fg-subtle">
{{ chars.toLocaleString() }} chars · ~{{ Math.round(chars / 4).toLocaleString() }} tokens</p>
</Section>
+20 -9
View File
@@ -29,6 +29,11 @@ export interface McpServer {
}
const server = defineModel<McpServer>({ required: true });
// The bound server belongs to a settings form, so an edit emits a new one
// rather than writing into it: a write in place never reaches the form.
function patch(change: Partial<McpServer>): void {
server.value = { ...server.value, ...change };
}
defineEmits<{ remove: [] }>();
const id = useId();
@@ -37,7 +42,7 @@ const id = useId();
const transport = computed({
get: () =>
server.value.transport === "" ? "stdio" : server.value.transport === "streamablehttp" ? "http" : server.value.transport,
set: (value: string) => (server.value.transport = value),
set: (value: string) => patch({ transport: value }),
});
const transports = [
{ value: "stdio", label: "stdio" },
@@ -46,7 +51,7 @@ const transports = [
];
const args = computed({
get: () => server.value.args ?? [],
set: (value: string[]) => (server.value.args = value),
set: (value: string[]) => patch({ args: value }),
});
</script>
@@ -56,7 +61,8 @@ const args = computed({
<div class="flex items-center gap-3">
<Input
:id="`${id}-name`"
v-model="server.name"
:model-value="server.name"
@update:model-value="(value: string | number) => patch({ name: String(value) })"
aria-label="Server name"
placeholder="name"
class="max-w-56 font-mono"
@@ -71,7 +77,8 @@ const args = computed({
<template v-if="transport === 'stdio'">
<label class="grid gap-1 text-xs text-fg-subtle">Command
<Input v-model="server.command" class="font-mono" placeholder="npx" />
<Input :model-value="server.command"
@update:model-value="(value: string | number) => patch({ command: String(value) })" class="font-mono" placeholder="npx" />
</label>
<div class="grid gap-1 text-xs text-fg-subtle">
<span :id="`${id}-args`">Arguments</span>
@@ -84,23 +91,27 @@ const args = computed({
</TagsInput>
</div>
<label class="grid gap-1 text-xs text-fg-subtle">Working directory
<Input v-model="server.work_dir" class="font-mono" placeholder="the daemon's working directory" />
<Input :model-value="server.work_dir"
@update:model-value="(value: string | number) => patch({ work_dir: String(value) })" class="font-mono" placeholder="the daemon's working directory" />
</label>
</template>
<label v-else-if="transport === 'http'" class="grid gap-1 text-xs text-fg-subtle">URL
<Input v-model="server.url" class="font-mono" placeholder="https://host/mcp" />
<Input :model-value="server.url"
@update:model-value="(value: string | number) => patch({ url: String(value) })" class="font-mono" placeholder="https://host/mcp" />
</label>
<template v-else>
<label class="grid gap-1 text-xs text-fg-subtle">SSE endpoint
<Input v-model="server.sse_endpoint" class="font-mono" />
<Input :model-value="server.sse_endpoint"
@update:model-value="(value: string | number) => patch({ sse_endpoint: String(value) })" class="font-mono" />
</label>
<label class="grid gap-1 text-xs text-fg-subtle">Message endpoint
<Input v-model="server.message_endpoint" class="font-mono" />
<Input :model-value="server.message_endpoint"
@update:model-value="(value: string | number) => patch({ message_endpoint: String(value) })" class="font-mono" />
</label>
</template>
<label class="flex items-center gap-2 text-sm">
<Switch v-model="server.parallel_tool_calls" />
<Switch :model-value="server.parallel_tool_calls" @update:model-value="(value: boolean) => patch({ parallel_tool_calls: value })" />
Parallel tool calls</label>
</div>
</Section>
+23 -8
View File
@@ -13,7 +13,8 @@ interface Playbook { id: string; yaml: string }
const KIND = "eda-playbooks";
const store = useSettingsStore();
onMounted(store.load);
const collection = computed(() => store.drafts[KIND]?.value as { playbooks: Playbook[] } | null);
const form = computed(() => store.formFor(KIND));
const collection = computed(() => store.draftValue(KIND) as { playbooks: Playbook[] } | null);
const id = ref("");
const open = ref("");
const unsaved = computed(() => store.changesFor(KIND).length > 0);
@@ -21,14 +22,18 @@ function add() {
if (unsaved.value) return;
const key = id.value.trim();
if (!key || collection.value?.playbooks.some(entry => entry.id === key)) return;
const draft = store.drafts[KIND];
if (!draft) return;
if (!draft.value) draft.value = { playbooks: [] };
(draft.value as { playbooks: Playbook[] }).playbooks.push({ id: key, yaml: "" });
if (!form.value) return;
const playbooks = collection.value?.playbooks ?? [];
store.setDraftValue(KIND, { playbooks: [...playbooks, { id: key, yaml: "" }] });
id.value = "";
open.value = String((draft.value as { playbooks: Playbook[] }).playbooks.length - 1);
open.value = String(playbooks.length);
}
function remove(index: number) {
const playbooks = collection.value?.playbooks ?? [];
store.setDraftValue(KIND, { playbooks: playbooks.filter((_, i) => i !== index) });
}
</script>
<template>
<div>
<PageHeader title="Playbooks"><HistoryLink :kinds="[KIND]" /></PageHeader>
@@ -36,9 +41,19 @@ function add() {
<p v-if="store.catalogError || store.pageErrorFor(KIND)" class="mb-4 text-sm text-danger" role="alert">{{ store.catalogError || store.pageErrorFor(KIND) }}</p>
<form class="mb-4 flex flex-wrap gap-2" @submit.prevent="add"><Input v-model="id" aria-label="Playbook ID" placeholder="Playbook ID" class="max-w-xs" :disabled="unsaved" /><Button type="submit" :disabled="unsaved || !id.trim() || collection?.playbooks.some(entry => entry.id === id.trim())">Add playbook</Button></form>
<Empty v-if="!collection?.playbooks.length"><EmptyHeader><EmptyTitle>No playbooks installed</EmptyTitle></EmptyHeader></Empty>
<CardAccordion v-model:open="open" :items="collection?.playbooks ?? []" :title="(entry) => entry.id" remove-label="Remove" mono @remove="collection!.playbooks.splice($event, 1)">
<CardAccordion v-model:open="open" :items="collection?.playbooks ?? []" :title="(entry) => entry.id" remove-label="Remove" mono @remove="remove">
<template #default="{ item: entry, index }">
<Textarea :id="`playbook-${index}`" v-model="entry.yaml" :aria-label="`${entry.id} YAML`" class="mb-3 min-h-64 font-mono" spellcheck="false" />
<form.Field v-if="form" v-slot="{ field }" :name="`playbooks[${index}].yaml`">
<Textarea
:id="`playbook-${index}`"
:model-value="field.state.value"
:aria-label="`${entry.id} YAML`"
class="mb-3 min-h-64 font-mono"
spellcheck="false"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
</form.Field>
</template>
</CardAccordion>
</div>
+25 -13
View File
@@ -3,25 +3,22 @@ import { computed, onMounted } from "vue";
import { storeToRefs } from "pinia";
import PageHeader from "@/base/PageHeader.vue";
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { SettingRow } from "@/components/ui/setting-row";
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
import ApplyStatusRows from "./ApplyStatusRows.vue";
import DraftHint from "./DraftHint.vue";
import HistoryLink from "./HistoryLink.vue";
import { fieldInvalid } from "./settings-form";
const KIND = "plugin-settings";
interface PluginSettings {
skills_dir: string;
}
const store = useSettingsStore();
const { catalog, catalogError } = storeToRefs(store);
onMounted(store.load);
const resources = computed(() => resourcesForPage(catalog.value, "plugins"));
const dirs = computed(() => store.drafts[KIND]?.value as PluginSettings | undefined);
const form = computed(() => store.formFor(KIND));
const error = computed(() => store.pageErrorFor(KIND));
</script>
@@ -33,13 +30,28 @@ const error = computed(() => store.pageErrorFor(KIND));
<p v-if="catalogError || error" class="mb-4 text-sm text-danger" role="alert">{{ catalogError || error }}</p>
<template v-if="dirs">
<SettingRow label="Skills directory" for="pl-skills" hint="Empty: work directory. Applies on restart.">
<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 v-if="form">
<FieldGroup class="@container/field-group">
<form.Field v-slot="{ field }" name="skills_dir">
<Field orientation="responsive" :data-invalid="fieldInvalid(field)">
<FieldContent>
<FieldLabel for="pl-skills">Skills directory</FieldLabel>
<FieldDescription>Empty: work directory. Applies on restart.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input
id="pl-skills"
:model-value="field.state.value"
class="max-w-md font-mono"
:aria-invalid="fieldInvalid(field)"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="skills_dir" />
</div>
</Field>
</form.Field>
</FieldGroup>
<!-- A restart-required kind can only be applied by a restart, so its
per-process versions live below: a process on an older one is the
restart owed. -->
+103 -60
View File
@@ -6,6 +6,7 @@ import { storeToRefs } from "pinia";
import PageHeader from "@/base/PageHeader.vue";
import { DurationInput } from "@/components/ui/duration-input";
import { Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import {
NumberField,
@@ -16,9 +17,9 @@ import {
} from "@/components/ui/number-field";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
import { Section } from "@/components/ui/section";
import { SettingRow } from "@/components/ui/setting-row";
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
import DraftHint from "./DraftHint.vue";
import { fieldInvalid } from "./settings-form";
const KIND = "scheduling-policy";
@@ -34,7 +35,8 @@ const { catalog, catalogError } = storeToRefs(store);
onMounted(store.load);
const resources = computed(() => resourcesForPage(catalog.value, "scheduling"));
const policy = computed(() => store.drafts[KIND]?.value as SchedulingPolicy | undefined);
const form = computed(() => store.formFor(KIND));
const policy = computed(() => store.draftValue(KIND) as SchedulingPolicy | undefined);
const error = computed(() => store.pageErrorFor(KIND));
const triggers = [
@@ -42,11 +44,6 @@ const triggers = [
{ value: "label", label: "Label" },
{ value: "either", label: "Either" },
];
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>
@@ -60,63 +57,109 @@ const labelIssue = computed(() => issue("label"));
{{ catalogError || error }}
</p>
<template v-if="policy">
<template v-if="form">
<Section title="Dispatch">
<SettingRow label="Trigger">
<div class="flex flex-wrap items-center gap-3">
<ToggleGroup type="single" variant="outline" size="sm" :model-value="policy.dispatch.trigger" aria-label="Trigger" @update:model-value="(value) => { if (value && policy) policy.dispatch.trigger = value as string; }">
<ToggleGroupItem v-for="option in triggers" :key="option.value" :value="option.value">{{ option.label }}</ToggleGroupItem>
</ToggleGroup>
<DraftHint :kind="KIND" path="dispatch.trigger" />
</div>
</SettingRow>
<SettingRow
v-if="policy.dispatch.trigger !== 'assignee'"
label="Label"
for="sp-label"
>
<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.">
<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>
<FieldGroup class="@container/field-group">
<form.Field v-slot="{ field }" name="dispatch.trigger">
<Field orientation="responsive">
<FieldContent><FieldLabel>Trigger</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<ToggleGroup
type="single"
variant="outline"
size="sm"
:model-value="field.state.value"
aria-label="Trigger"
@update:model-value="(value) => { if (value) field.handleChange(value as string); }"
>
<ToggleGroupItem v-for="option in triggers" :key="option.value" :value="option.value">{{ option.label }}</ToggleGroupItem>
</ToggleGroup>
<DraftHint :kind="KIND" path="dispatch.trigger" />
</div>
</Field>
</form.Field>
<form.Field v-if="policy?.dispatch.trigger !== 'assignee'" v-slot="{ field }" name="label">
<Field orientation="responsive" :data-invalid="fieldInvalid(field)">
<FieldContent><FieldLabel for="sp-label">Label</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-col gap-2 @md/field-group:flex-1">
<div class="flex flex-wrap items-center gap-3">
<Input
id="sp-label"
:model-value="field.state.value ?? ''"
class="max-w-sm font-mono"
:aria-invalid="fieldInvalid(field)"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="label" />
</div>
<FieldError v-if="fieldInvalid(field)" :errors="field.state.meta.errors" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="dispatch.ack_reaction">
<Field orientation="responsive">
<FieldContent>
<FieldLabel for="sp-ack">Ack reaction</FieldLabel>
<FieldDescription>Empty: none.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input
id="sp-ack"
:model-value="field.state.value"
class="max-w-xs font-mono"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="dispatch.ack_reaction" />
</div>
</Field>
</form.Field>
</FieldGroup>
</Section>
<Section title="Retries and polling">
<SettingRow label="Max retries" hint="Then marked dead.">
<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">
<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>
<FieldGroup class="@container/field-group">
<form.Field v-slot="{ field }" name="max_retries">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Max retries</FieldLabel>
<FieldDescription>Then marked dead.</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="Max retries" />
<NumberFieldIncrement />
</NumberFieldContent>
</NumberField>
<DraftHint :kind="KIND" path="max_retries" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="poll_interval">
<Field orientation="responsive" :data-invalid="fieldInvalid(field)">
<FieldContent><FieldLabel for="sp-poll">Poll interval</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-col gap-2 @md/field-group:flex-1">
<div class="flex flex-wrap items-center gap-3">
<DurationInput
id="sp-poll"
:model-value="field.state.value"
:units="['s', 'm', 'h']"
:aria-invalid="fieldInvalid(field)"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="poll_interval" />
</div>
<FieldError v-if="fieldInvalid(field)" :errors="field.state.meta.errors" />
</div>
</Field>
</form.Field>
</FieldGroup>
</Section>
</template>
</div>
+7 -2
View File
@@ -24,6 +24,11 @@ withDefaults(
{ resolved: undefined, fallback: undefined },
);
const model = defineModel<SecretRef>({ required: true });
// The bound reference belongs to a settings form, so an edit emits a new one
// rather than writing into it: a write in place never reaches the form.
function patch(change: Partial<SecretRef>): void {
model.value = { ...model.value, ...change };
}
const editing = ref(false);
const engines = useSecretEnginesStore();
const missing = computed(() => !!engines.engines && !!model.value.engine && !engines.engines.some((engine) => engine.name === model.value.engine));
@@ -63,7 +68,7 @@ async function check() {
</div>
<div v-else class="flex flex-wrap items-end gap-2">
<label class="grid gap-1 text-xs text-fg-subtle">Engine
<Select v-model="model.engine" :disabled="disabled">
<Select :model-value="model.engine" :disabled="disabled" @update:model-value="(engine) => patch({ engine: String(engine ?? '') })">
<SelectTrigger :id="`${idPrefix}-engine`" class="font-mono"><SelectValue placeholder="Choose engine" /></SelectTrigger>
<SelectContent><SelectGroup>
<SelectItem v-for="engine in engines.engines ?? []" :key="engine.name" :value="engine.name">{{ engine.name }}</SelectItem>
@@ -72,7 +77,7 @@ async function check() {
</Select>
</label>
<label class="grid min-w-48 flex-1 gap-1 text-xs text-fg-subtle">Key
<Input :id="`${idPrefix}-key`" v-model="model.key" class="font-mono" :disabled="disabled" />
<Input :id="`${idPrefix}-key`" :model-value="model.key" class="font-mono" :disabled="disabled" @update:model-value="(key) => patch({ key: String(key) })" />
</label>
<Button variant="ghost" size="sm" @click="editing = false">Done</Button>
</div>
+88 -52
View File
@@ -7,6 +7,7 @@ import { Plus, Trash2 } from "@lucide/vue";
import PageHeader from "@/base/PageHeader.vue";
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
import { Button } from "@/components/ui/button";
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import {
Select,
@@ -16,7 +17,6 @@ import {
SelectValue,
} from "@/components/ui/select";
import { Section } from "@/components/ui/section";
import { SettingRow } from "@/components/ui/setting-row";
import { Switch } from "@/components/ui/switch";
import { useOrgStore } from "@/stores/org";
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
@@ -43,15 +43,19 @@ const orgStore = useOrgStore();
const { catalog: resourceCatalog, catalogError } = storeToRefs(store);
onMounted(() => Promise.all([store.load(), store.loadConfig(), orgStore.loadOrg()]));
// Map keys are free text, so entries are read from the draft and written whole
// through setDraftEntry; a key is never a form field path.
const resources = computed(() => resourcesForPage(resourceCatalog.value, "models"));
const providers = computed(() => store.drafts["provider-settings"]?.value as Record<string, Provider> | undefined);
const aliases = computed(() => store.drafts["model-aliases"]?.value as Record<string, string> | undefined);
const providers = computed(() => store.draftValue("provider-settings") as Record<string, Provider> | undefined);
const aliases = computed(() => store.draftValue("model-aliases") as Record<string, string> | undefined);
const errors = computed(() =>
["provider-settings", "model-aliases"].map((k) => store.pageErrorFor(k)).filter(Boolean),
);
const providerEntries = computed(() => Object.entries(providers.value ?? {}));
const configuredIds = computed(() => providerEntries.value.map(([id]) => id));
const modelCatalog = computed(() => store.config?.catalog ?? []);
const configuredIds = computed(() => Object.keys(providers.value ?? {}));
const modelOptions = computed(() => aliasModelOptions(modelCatalog.value, configuredIds.value));
const available = computed(() => availableProviders(modelCatalog.value, configuredIds.value));
@@ -61,17 +65,16 @@ const aliasNames = computed(() => [
]);
// An unset alias is an absent key: the server refuses an empty model.
function setAlias(alias: string, model: string) {
if (!aliases.value) return;
if (model.trim()) aliases.value[alias] = model.trim();
else delete aliases.value[alias];
store.setDraftEntry("model-aliases", alias, model.trim() || undefined);
}
function removeAlias(alias: string) {
store.setDraftEntry("model-aliases", alias, undefined);
}
// Embedding runs through the SDK's embed package, which only these classes
// implement (internal/infrastructure/embedding).
const EMBED_CLASSES = ["openai", "openai-compatible", "gemini", "ollama", "cohere", "mistral"];
const embeddingProviders = computed(() =>
Object.entries(providers.value ?? {})
.filter(([, p]) => EMBED_CLASSES.includes(p.class))
.map(([id]) => id),
providerEntries.value.filter(([, p]) => EMBED_CLASSES.includes(p.class)).map(([id]) => id),
);
// The provider is held locally until a model is typed: the alias itself is
// only stored once both halves exist.
@@ -99,7 +102,7 @@ const newAlias = ref("");
function addAlias() {
const name = newAlias.value.trim();
if (!aliases.value || !name || aliasNames.value.includes(name)) return;
aliases.value[name] = modelOptions.value[0] ?? "";
store.setDraftEntry("model-aliases", name, modelOptions.value[0] ?? "");
newAlias.value = "";
}
@@ -110,14 +113,21 @@ function addProvider() {
const id = newProvider.value.trim();
if (!providers.value || !id || providers.value[id]) return;
const found = modelCatalog.value.find((p) => p.id === id);
providers.value[id] = {
store.setDraftEntry("provider-settings", id, {
class: found?.class || (CLASSES.includes(id) ? id : "openai"),
api_key_env: found?.api_key_env,
base_url: found?.base_url,
api_key_ref: { engine: "", key: "" },
};
});
newProvider.value = "";
}
function setProvider(name: string, next: Partial<Provider>) {
const current = providers.value?.[name];
if (current) store.setDraftEntry("provider-settings", name, { ...current, ...next });
}
function removeProvider(name: string) {
store.setDraftEntry("provider-settings", name, undefined);
}
const keySource = (p: Provider) =>
p.api_key_ref.key ? `${p.api_key_ref.engine} / ${p.api_key_ref.key}` : p.api_key_env ? `env ${p.api_key_env}` : "no key";
// Org access: which instance models each other org may use, and whether it may
@@ -126,7 +136,7 @@ interface OrgPolicy {
allowed: string[];
own_providers: boolean;
}
const policies = computed(() => store.drafts["org-model-policy"]?.value as Record<string, OrgPolicy> | undefined);
const policies = computed(() => store.draftValue("org-model-policy") as Record<string, OrgPolicy> | undefined);
const otherOrgs = computed(() => (orgStore.instanceAdmin ? orgStore.orgs.filter((o) => o.id !== "org-sys") : []));
const providerWildcards = computed(() => configuredIds.value.map((id) => `${id}/*`));
function policyFor(id: string): OrgPolicy {
@@ -135,8 +145,8 @@ function policyFor(id: string): OrgPolicy {
function setPolicy(id: string, next: Partial<OrgPolicy>) {
if (!policies.value) return;
const merged = { ...policyFor(id), ...next };
if (!merged.allowed.length && !merged.own_providers) delete policies.value[id];
else policies.value[id] = merged;
const empty = !merged.allowed.length && !merged.own_providers;
store.setDraftEntry("org-model-policy", id, empty ? undefined : merged);
}
const allowedText = (id: string) => policyFor(id).allowed.join(", ");
function setAllowed(id: string, text: string) {
@@ -187,14 +197,14 @@ function setAllowed(id: string, text: string) {
list="alias-models"
class="min-w-0 max-w-md flex-1 font-mono max-sm:max-w-none max-sm:basis-full"
placeholder="unset"
:aria-invalid="aliasIssue(alias) ? true : undefined"
:aria-invalid="!!aliasIssue(alias)"
@update:model-value="(v) => setAlias(alias, String(v))"
/>
<DraftHint kind="model-aliases" :path="alias" />
<span v-if="aliasIssue(alias)" class="text-xs text-danger">{{ aliasIssue(alias)?.message }}</span>
<span v-else-if="aliases[alias] && !providerKnown(aliases[alias])" class="text-xs text-warn">Provider not configured.</span>
</template>
<Button v-if="!KNOWN_ALIASES.includes(alias)" variant="ghost" size="icon" class="ml-auto" :aria-label="`Remove alias ${alias}`" @click="delete aliases[alias]">
<Button v-if="!KNOWN_ALIASES.includes(alias)" variant="ghost" size="icon" class="ml-auto" :aria-label="`Remove alias ${alias}`" @click="removeAlias(alias)">
<Trash2 />
</Button>
</div>
@@ -234,48 +244,74 @@ function setAllowed(id: string, text: string) {
</datalist>
<Section title="Providers">
<Accordion type="multiple">
<AccordionItem v-for="(provider, name) in providers" :key="name" :value="String(name)">
<AccordionItem v-for="[name, provider] in providerEntries" :key="name" :value="name">
<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-sm font-medium">{{ name }}</span>
<span v-if="provider.class !== String(name)" class="font-mono text-xs text-fg-muted">{{ provider.class }}</span>
<span v-if="provider.class !== name" class="font-mono text-xs text-fg-muted">{{ provider.class }}</span>
<span class="min-w-0 truncate font-mono text-xs text-fg-subtle">{{ keySource(provider) }}</span>
</span>
</AccordionTrigger>
<AccordionContent>
<SettingRow label="Class" class="border-t-0 pt-0">
<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.">
<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 environment variable" :for="`prov-${name}-env`" hint="Used when no secret reference is set.">
<div class="flex flex-wrap items-center gap-3">
<Input :id="`prov-${name}-env`" v-model="provider.api_key_env" aria-label="API key environment variable" placeholder="API key environment variable" class="max-w-md font-mono" />
<DraftHint kind="provider-settings" :path="`${name}.api_key_env`" />
</div>
</SettingRow>
<SettingRow label="API key">
<SecretRefField
v-model="provider.api_key_ref"
:id-prefix="`prov-${name}-key`"
:fallback="provider.api_key_env ? `env ${provider.api_key_env}` : undefined"
/>
</SettingRow>
<FieldGroup class="@container/field-group">
<Field orientation="responsive" class="border-t-0 pt-0">
<FieldContent><FieldLabel>Class</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Select :model-value="provider.class" @update:model-value="(v) => setProvider(name, { class: String(v) })">
<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>
</Field>
<Field orientation="responsive">
<FieldContent>
<FieldLabel :for="`prov-${name}-url`">Base URL</FieldLabel>
<FieldDescription>Empty: provider default.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input
:id="`prov-${name}-url`"
:model-value="provider.base_url ?? ''"
class="max-w-md font-mono"
@update:model-value="(v) => setProvider(name, { base_url: String(v) })"
/>
<DraftHint kind="provider-settings" :path="`${name}.base_url`" />
</div>
</Field>
<Field orientation="responsive">
<FieldContent>
<FieldLabel :for="`prov-${name}-env`">API key environment variable</FieldLabel>
<FieldDescription>Used when no secret reference is set.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input
:id="`prov-${name}-env`"
:model-value="provider.api_key_env ?? ''"
aria-label="API key environment variable"
placeholder="API key environment variable"
class="max-w-md font-mono"
@update:model-value="(v) => setProvider(name, { api_key_env: String(v) })"
/>
<DraftHint kind="provider-settings" :path="`${name}.api_key_env`" />
</div>
</Field>
<Field orientation="responsive">
<FieldContent><FieldLabel>API key</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<SecretRefField
:model-value="provider.api_key_ref"
:id-prefix="`prov-${name}-key`"
:fallback="provider.api_key_env ? `env ${provider.api_key_env}` : undefined"
@update:model-value="(v) => setProvider(name, { api_key_ref: v })"
/>
</div>
</Field>
</FieldGroup>
<div class="flex justify-end pb-1">
<Button variant="ghost" size="sm" class="text-danger" @click="delete providers[name]"><Trash2 data-icon="inline-start" />Remove</Button>
<Button variant="ghost" size="sm" class="text-danger" @click="removeProvider(name)"><Trash2 data-icon="inline-start" />Remove</Button>
</div>
</AccordionContent>
</AccordionItem>
+190 -110
View File
@@ -7,6 +7,7 @@ import { Plus } from "@lucide/vue";
import PageHeader from "@/base/PageHeader.vue";
import { Button } from "@/components/ui/button";
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { api } from "@/lib/api";
@@ -25,7 +26,6 @@ import {
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { SettingRow } from "@/components/ui/setting-row";
import { Switch } from "@/components/ui/switch";
import {
TagsInput,
@@ -41,6 +41,8 @@ import DraftHint from "./DraftHint.vue";
import HistoryLink from "./HistoryLink.vue";
const KIND = "repository-policies";
const DANGER_ROW =
"relative isolate before:pointer-events-none before:absolute before:inset-y-0 before:-inset-x-3 before:-z-10 before:rounded-md before:border before:border-danger/40 before:bg-danger-soft";
interface Repo {
connection: string;
@@ -74,28 +76,35 @@ onMounted(async()=>{
});
const resources = computed(() => resourcesForPage(catalog.value, "repositories"));
const draft = computed(() => store.drafts[KIND]);
const repos = computed(() => (draft.value?.value ?? []) as Repo[]);
const connections = computed(() => (store.drafts["forge-connections"]?.value ?? []) as { id: string; name: string }[]);
const form = computed(() => store.formFor(KIND));
const repos = computed(() => (store.draftValue(KIND) ?? []) as Repo[]);
const connections = computed(() => (store.draftValue("forge-connections") ?? []) as { id: string; name: string }[]);
const error = computed(() => store.pageErrorFor(KIND));
const ecosystems = ["go", "python", "node", "rust", "custom"];
const newRepo = ref("");
const open = ref("0");
const unsaved = computed(() => store.changesFor(KIND).length > 0);
// The repository list is the whole document, so adding and removing rebuild it.
function addRepo() {
if (unsaved.value) return;
const [owner, name] = newRepo.value.trim().split("/");
if (!draft.value || !owner || !name) return;
draft.value.value ??= [];
(draft.value.value as Repo[]).push({
owner, name, connection: "", base: "main", ecosystem: "go", gate: [], tooling: null, preflight: null, protect: null,
test_glob: "", persistent_storage: false, max_retries: 0, allow_concurrent: false,
});
if (!form.value || !owner || !name) return;
const next: Repo[] = [
...repos.value,
{
owner, name, connection: "", base: "main", ecosystem: "go", gate: [], tooling: null, preflight: null, protect: null,
test_glob: "", persistent_storage: false, max_retries: 0, allow_concurrent: false,
},
];
store.setDraftValue(KIND, next);
newRepo.value = "";
open.value = String((draft.value.value as Repo[]).length - 1);
open.value = String(next.length - 1);
}
function removeRepo(index: number) {
store.setDraftValue(KIND, repos.value.filter((_, i) => i !== index));
}
const protectOf = (repo: Repo) => repo.protect ?? [];
interface AccessCheck { verified?: boolean; account?: string; base_branch?: string; operations?: string[]; message?: string }
const checkAgent=ref("");
const checking=ref("");
@@ -126,19 +135,27 @@ async function checkAccess(repo:Repo):Promise<void>{
<p v-if="catalogError || error" class="mb-4 text-sm text-danger" role="alert">{{ catalogError || error }}</p>
<template v-if="draft">
<CardAccordion v-model:open="open" :items="repos" :title="(r) => `${r.owner}/${r.name}`" remove-label="Remove" mono @remove="repos.splice($event, 1)">
<template v-if="form">
<CardAccordion v-model:open="open" :items="repos" :title="(r) => `${r.owner}/${r.name}`" remove-label="Remove" mono @remove="removeRepo">
<template #default="{ item: repo, index: i }">
<SettingRow label="Connection">
<Select v-model="repo.connection">
<SelectTrigger class="w-64" :aria-label="`Connection for ${repo.name}`"><SelectValue placeholder="Choose a connection" /></SelectTrigger>
<SelectContent>
<SelectItem v-for="connection in connections" :key="connection.id" :value="connection.id">{{ connection.name || connection.id }}</SelectItem>
<SelectItem v-if="repo.connection && !connections.some((connection) => connection.id === repo.connection)" :value="repo.connection" disabled>Unavailable connection</SelectItem>
</SelectContent>
</Select>
</SettingRow>
<SettingRow label="Check access">
<FieldGroup class="@container/field-group">
<Field orientation="responsive">
<FieldContent><FieldLabel>Connection</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<form.Field v-slot="{ field }" :name="`${i}.connection`">
<Select :model-value="field.state.value" @update:model-value="field.handleChange">
<SelectTrigger class="w-64" :aria-label="`Connection for ${repo.name}`"><SelectValue placeholder="Choose a connection" /></SelectTrigger>
<SelectContent>
<SelectItem v-for="connection in connections" :key="connection.id" :value="connection.id">{{ connection.name || connection.id }}</SelectItem>
<SelectItem v-if="repo.connection && !connections.some((connection) => connection.id === repo.connection)" :value="repo.connection" disabled>Unavailable connection</SelectItem>
</SelectContent>
</Select>
</form.Field>
</div>
</Field>
<Field orientation="responsive">
<FieldContent><FieldLabel>Check access</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<div class="grid gap-2">
<Select v-model="checkAgent">
<SelectTrigger class="w-64" :aria-label="`Check ${repo.name} access as`"><SelectValue placeholder="Choose an agent" /></SelectTrigger>
@@ -152,93 +169,156 @@ async function checkAccess(repo:Repo):Promise<void>{
<template v-else>{{ results[`${repo.owner}/${repo.name}`].message }}</template>
</p>
</div>
</SettingRow>
<SettingRow label="Base branch" :for="`repo-${i}-base`">
<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">
<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="Tooling" hint="Installs the gate needs; runs before it.">
<CommandListEditor v-model="repo.tooling" label="Tooling" empty-text="Nothing to install." />
<DraftHint :kind="KIND" :path="`${i}.tooling`" />
</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.">
<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="Instructions" :for="`repo-${i}-instructions`">
<div class="grid gap-1">
<Textarea :id="`repo-${i}-instructions`" v-model="repo.instructions" :rows="5" class="font-mono text-label" />
<DraftHint :kind="KIND" :path="`${i}.instructions`" />
</div>
</SettingRow>
<SettingRow label="Protected paths" hint="Suffixes agents never write.">
<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.">
<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="Persistent storage" hint="Kept across tasks.">
<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'"
>
<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>
</Field>
<form.Field v-slot="{ field }" :name="`${i}.base`">
<Field orientation="responsive">
<FieldContent><FieldLabel :for="`repo-${i}-base`">Base branch</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input :id="`repo-${i}-base`" :model-value="field.state.value" class="max-w-56 font-mono" @blur="field.handleBlur" @update:model-value="field.handleChange" />
<DraftHint :kind="KIND" :path="`${i}.base`" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${i}.ecosystem`">
<Field orientation="responsive">
<FieldContent><FieldLabel>Ecosystem</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Select :model-value="field.state.value" @update:model-value="field.handleChange">
<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>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${i}.gate`">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Quality gate</FieldLabel>
<FieldDescription>Last command runs the tests.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<CommandListEditor :model-value="field.state.value" label="Gate" empty-text="No gate." @update:model-value="field.handleChange" />
<DraftHint :kind="KIND" :path="`${i}.gate`" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${i}.tooling`">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Tooling</FieldLabel>
<FieldDescription>Installs the gate needs; runs before it.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<CommandListEditor :model-value="field.state.value" label="Tooling" empty-text="Nothing to install." @update:model-value="field.handleChange" />
<DraftHint :kind="KIND" :path="`${i}.tooling`" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${i}.preflight`">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Preflight</FieldLabel>
<FieldDescription>Empty: ecosystem default.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<CommandListEditor :model-value="field.state.value" label="Preflight" empty-text="Ecosystem default." @update:model-value="field.handleChange" />
<DraftHint :kind="KIND" :path="`${i}.preflight`" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${i}.test_glob`">
<Field orientation="responsive">
<FieldContent>
<FieldLabel :for="`repo-${i}-glob`">Test files</FieldLabel>
<FieldDescription>Empty: ecosystem default.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input :id="`repo-${i}-glob`" :model-value="field.state.value" class="max-w-56 font-mono" placeholder="*_test.go" @blur="field.handleBlur" @update:model-value="field.handleChange" />
<DraftHint :kind="KIND" :path="`${i}.test_glob`" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${i}.instructions`">
<Field orientation="responsive">
<FieldContent><FieldLabel :for="`repo-${i}-instructions`">Instructions</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<div class="grid w-full gap-1">
<Textarea :id="`repo-${i}-instructions`" :model-value="field.state.value" :rows="5" class="font-mono text-label" @blur="field.handleBlur" @update:model-value="field.handleChange" />
<DraftHint :kind="KIND" :path="`${i}.instructions`" />
</div>
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${i}.protect`">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Protected paths</FieldLabel>
<FieldDescription>Suffixes agents never write.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<TagsInput
:model-value="field.state.value ?? []"
class="font-mono"
:aria-label="`Protected paths for ${repo.name}`"
@update:model-value="(v) => field.handleChange(v as string[])"
>
<TagsInputItem v-for="p in field.state.value ?? []" :key="p" :value="p">
<TagsInputItemText />
<TagsInputItemDelete />
</TagsInputItem>
<TagsInputInput placeholder="_templ.go" />
</TagsInput>
<DraftHint :kind="KIND" :path="`${i}.protect`" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${i}.max_retries`">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Max retries</FieldLabel>
<FieldDescription>0 = scheduling policy value.</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="`Max retries for ${repo.name}`" />
<NumberFieldIncrement />
</NumberFieldContent>
</NumberField>
<DraftHint :kind="KIND" :path="`${i}.max_retries`" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${i}.persistent_storage`">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Persistent storage</FieldLabel>
<FieldDescription>Kept across tasks.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Switch :model-value="field.state.value" :aria-label="`Persistent storage for ${repo.name}`" @update:model-value="field.handleChange" />
<DraftHint :kind="KIND" :path="`${i}.persistent_storage`" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" :name="`${i}.allow_concurrent`">
<Field orientation="responsive" :class="repo.allow_concurrent ? DANGER_ROW : undefined">
<FieldContent>
<FieldLabel>Concurrent tasks</FieldLabel>
<FieldDescription>Only if worktrees cannot collide.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Switch :model-value="field.state.value" :aria-label="`Concurrent tasks for ${repo.name}`" @update:model-value="field.handleChange" />
<DraftHint :kind="KIND" :path="`${i}.allow_concurrent`" />
</div>
</Field>
</form.Field>
</FieldGroup>
</template>
</CardAccordion>
+170 -76
View File
@@ -5,10 +5,11 @@ import { RotateCcw } from "@lucide/vue";
import { storeToRefs } from "pinia";
import { Button } from "@/components/ui/button";
import {Input} from "@/components/ui/input";
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 { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
import {
NumberField,
NumberFieldContent,
@@ -16,7 +17,6 @@ import {
NumberFieldIncrement,
NumberFieldInput,
} from "@/components/ui/number-field";
import { SettingRow } from "@/components/ui/setting-row";
import {
AlertDialog,
AlertDialogAction,
@@ -33,9 +33,15 @@ import DraftHint from "./DraftHint.vue";
import HistoryLink from "./HistoryLink.vue";
import SecretRefField from "./SecretRefField.vue";
const POLICY="task-policy";
const POLICY = "task-policy";
const KIND = "workflow-execution-settings";
interface TaskPolicy {
notify_webhook: string;
notify_min_severity: string;
notify_secret: { engine: string; key: string };
}
interface ExecutionSettings {
max_model_tool_steps: number;
max_runtime_seconds: number;
@@ -48,22 +54,21 @@ const { catalog, catalogError } = storeToRefs(store);
onMounted(store.load);
const resources = computed(() => resourcesForPage(catalog.value, "tasks"));
const policy=computed(()=>store.drafts[POLICY]?.value as {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 policyForm = computed(() => store.formFor(POLICY));
const policy = computed(() => store.draftValue(POLICY) as TaskPolicy | undefined);
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 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);
},
});
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.
function durationSeconds(text: string): number | undefined {
const ms = parseGoDuration(text);
return ms === null ? undefined : Math.round(ms / 1000);
}
const callRuntime = seconds("max_runtime_seconds");
const taskRuntime = seconds("max_task_runtime_seconds");
const workflows = useWorkflowsStore();
const confirmRestore = ref(false);
@@ -83,68 +88,157 @@ async function restoreWorkflows(): Promise<void> {
{{ catalogError || error || store.pageErrorFor(POLICY) }}
</p>
<template v-if="policy">
<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" />
<FieldGroup v-if="policyForm && policy" class="@container/field-group">
<policyForm.Field v-slot="{ field }" name="notify_webhook">
<Field orientation="responsive">
<FieldContent>
<FieldLabel for="task-notify">Alert webhook</FieldLabel>
<FieldDescription>Receives each raised and resolved alert. Empty disables.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input
id="task-notify"
:model-value="field.state.value"
type="url"
class="max-w-md"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="POLICY" path="notify_webhook" />
</div>
</Field>
</policyForm.Field>
<policyForm.Field v-slot="{ field }" name="notify_min_severity">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Webhook severity</FieldLabel>
<FieldDescription>Minimum severity.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Select
:model-value="field.state.value || 'warning'"
@update:model-value="field.handleChange(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>
</Field>
</policyForm.Field>
<policyForm.Field v-slot="{ field }" name="notify_secret">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Webhook signing secret</FieldLabel>
<FieldDescription>Signs each payload in X-Archie-Signature. Not set sends unsigned.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<SecretRefField
v-if="field.state.value"
:model-value="field.state.value"
id-prefix="task-notify-secret"
@update:model-value="field.handleChange"
/>
<Button v-else variant="outline" size="sm" @click="field.handleChange({ engine: '', key: '' })">Set reference</Button>
<DraftHint :kind="POLICY" path="notify_secret" />
</div>
</Field>
</policyForm.Field>
</FieldGroup>
<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) => { const s = durationSeconds(text); if (s !== undefined) field.handleChange(s); }"
/>
<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) => { const s = durationSeconds(text); if (s !== undefined) field.handleChange(s); }"
/>
<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>
<FieldGroup v-if="workflows.shipped.definitions.length" class="@container/field-group">
<Field orientation="responsive">
<FieldContent>
<FieldLabel>Workflows</FieldLabel>
<FieldDescription>Resets every shipped workflow. Custom workflows are kept.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Button variant="outline" size="sm" :disabled="workflows.state.saving" @click="confirmRestore = true"><RotateCcw data-icon="inline-start" />Restore default</Button>
</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>
</Field>
</FieldGroup>
<AlertDialog v-model:open="confirmRestore">
<AlertDialogContent>
<AlertDialogHeader>
+167 -89
View File
@@ -2,7 +2,7 @@
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import ApplyStatusRows from "./ApplyStatusRows.vue";
import HistoryLink from "@/settings/HistoryLink.vue";
import { computed, onMounted, ref, toRaw, watch } from "vue";
import { computed, onMounted, ref, watch } from "vue";
import { storeToRefs } from "pinia";
import { Plus } from "@lucide/vue";
@@ -10,6 +10,7 @@ import PageHeader from "@/base/PageHeader.vue";
import { Button } from "@/components/ui/button";
import { ByteSizeInput } from "@/components/ui/byte-size-input";
import { DurationInput } from "@/components/ui/duration-input";
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import {
InputGroup,
@@ -18,7 +19,6 @@ import {
InputGroupText,
} from "@/components/ui/input-group";
import { Section } from "@/components/ui/section";
import { SettingRow } from "@/components/ui/setting-row";
import { Switch } from "@/components/ui/switch";
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
import DraftHint from "./DraftHint.vue";
@@ -39,40 +39,32 @@ const { catalog, catalogError } = storeToRefs(store);
onMounted(store.load);
const resources = computed(() => resourcesForPage(catalog.value, "tools"));
const tools = computed(() => store.drafts[KIND]?.value as ToolSettings | undefined);
const form = computed(() => store.formFor(KIND));
const tools = computed(() => store.draftValue(KIND) as ToolSettings | undefined);
const error = computed(() => store.pageErrorFor(KIND));
// An unset web_fetch.enabled means on.
const webFetchOn = computed({
get: () => tools.value?.web_fetch.enabled !== false,
set: (on: boolean) => {
if (tools.value) tools.value.web_fetch.enabled = on;
},
});
const webFetchOn = computed(() => tools.value?.web_fetch.enabled !== false);
// A new server is held here, outside the draft, until it is named: opening
// the form is not yet a change to save.
const pending = ref<McpServer | null>(null);
const shown = computed(() => {
const servers = tools.value?.mcp_servers ?? [];
return pending.value ? [...servers, pending.value] : servers;
});
// Keyed by identity, so the pending editor keeps its focus when it joins the draft.
const keys = new WeakMap<object, number>();
let nextKey = 0;
function keyOf(server: McpServer): number {
const raw = toRaw(server);
if (!keys.has(raw)) keys.set(raw, nextKey++);
return keys.get(raw)!;
const servers = computed(() => tools.value?.mcp_servers ?? []);
const shown = computed(() => (pending.value ? [...servers.value, pending.value] : servers.value));
// The list is written whole: the draft's servers are replaced, not edited in place.
function setServers(next: McpServer[]): void {
if (tools.value) store.setDraftValue(KIND, { ...tools.value, mcp_servers: next });
}
function removeServer(server: McpServer) {
if (pending.value && toRaw(pending.value) === toRaw(server)) {
pending.value = null;
return;
}
const servers = tools.value?.mcp_servers;
const i = servers?.findIndex((s) => toRaw(s) === toRaw(server)) ?? -1;
if (i >= 0) servers!.splice(i, 1);
// Rows are keyed by position, so a pending server keeps its row (and focus)
// when it joins the draft at the same position.
function editAt(i: number, next: McpServer): void {
if (i < servers.value.length) setServers(servers.value.map((s, j) => (j === i ? next : s)));
else pending.value = next;
}
function removeAt(i: number): void {
if (i < servers.value.length) setServers(servers.value.filter((_, j) => j !== i));
else pending.value = null;
}
function addServer() {
pending.value = { name: "", transport: "stdio", parallel_tool_calls: false, headers_configured: false };
@@ -81,11 +73,17 @@ watch(
() => pending.value?.name,
(name) => {
if (!name?.trim() || !pending.value || !tools.value) return;
tools.value.mcp_servers.push(pending.value);
setServers([...servers.value, { ...pending.value }]);
pending.value = null;
},
);
// Only numeric text becomes a number, as v-model.number did.
function looseNumber(value: string | number): number | string {
if (typeof value === "number") return value;
const n = parseFloat(value);
return Number.isNaN(n) ? value : n;
}
</script>
<template>
@@ -99,16 +97,17 @@ watch(
{{ catalogError || error }}
</p>
<template v-if="tools">
<template v-if="form && tools">
<Section title="MCP servers">
<div class="grid gap-3">
<McpServerEditor
v-for="server in shown"
:key="keyOf(server)"
v-for="(server, i) in shown"
:key="i"
:model-value="server"
@remove="removeServer(server)"
@update:model-value="(next: McpServer) => editAt(i, next)"
@remove="removeAt(i)"
/>
<Empty v-if="!tools.mcp_servers.length && !pending"><EmptyHeader><EmptyTitle>No MCP servers</EmptyTitle></EmptyHeader></Empty>
<Empty v-if="!servers.length && !pending"><EmptyHeader><EmptyTitle>No MCP servers</EmptyTitle></EmptyHeader></Empty>
<div v-if="!pending">
<Button variant="outline" size="sm" @click="addServer">
<Plus data-icon="inline-start" /> Add MCP server</Button>
@@ -120,75 +119,154 @@ watch(
<template #action>
<div class="flex items-center gap-3">
<DraftHint :kind="KIND" path="minimax.enabled" />
<Switch v-model="tools.minimax.enabled" aria-label="MiniMax enabled" />
<form.Field v-slot="{ field }" name="minimax.enabled">
<Switch :model-value="field.state.value" aria-label="MiniMax enabled" @update:model-value="field.handleChange" />
</form.Field>
</div>
</template>
<SettingRow label="API key">
<SecretRefField
v-model="tools.minimax.api_key_ref"
id-prefix="minimax-key"
:disabled="!tools.minimax.enabled"
/>
</SettingRow>
<FieldGroup class="@container/field-group">
<form.Field v-slot="{ field }" name="minimax.api_key_ref">
<Field orientation="responsive">
<FieldContent><FieldLabel>API key</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<SecretRefField
:model-value="field.state.value"
id-prefix="minimax-key"
:disabled="!tools.minimax.enabled"
@update:model-value="field.handleChange"
/>
</div>
</Field>
</form.Field>
<SettingRow label="URL" for="minimax-url">
<div class="flex flex-wrap items-center gap-3"><Input id="minimax-url" v-model="tools.minimax.base_url" class="max-w-md font-mono" /><DraftHint :kind="KIND" path="minimax.base_url" /></div>
</SettingRow>
<form.Field v-slot="{ field }" name="minimax.base_url">
<Field orientation="responsive">
<FieldContent><FieldLabel for="minimax-url">URL</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input
id="minimax-url"
:model-value="field.state.value"
class="max-w-md font-mono"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="minimax.base_url" />
</div>
</Field>
</form.Field>
</FieldGroup>
</Section>
<Section title="Web fetch">
<template #action>
<div class="flex items-center gap-3">
<DraftHint :kind="KIND" path="web_fetch.enabled" />
<Switch v-model="webFetchOn" aria-label="Web fetch enabled" />
<form.Field v-slot="{ field }" name="web_fetch.enabled">
<Switch :model-value="webFetchOn" aria-label="Web fetch enabled" @update:model-value="field.handleChange" />
</form.Field>
</div>
</template>
<SettingRow label="Max download" for="wf-bytes">
<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">
<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="Host dashboard and Docker API access."
:tone="tools.web_fetch.allow_private_networks ? 'danger' : 'default'"
>
<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>
<FieldGroup class="@container/field-group">
<form.Field v-slot="{ field }" name="web_fetch.max_bytes">
<Field orientation="responsive">
<FieldContent><FieldLabel for="wf-bytes">Max download</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<ByteSizeInput
id="wf-bytes"
:model-value="field.state.value"
:disabled="!webFetchOn"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="web_fetch.max_bytes" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="web_fetch.timeout">
<Field orientation="responsive">
<FieldContent><FieldLabel for="wf-timeout">Timeout</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<DurationInput
id="wf-timeout"
:model-value="field.state.value"
:units="['s', 'm']"
:disabled="!webFetchOn"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="web_fetch.timeout" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="web_fetch.allow_private_networks">
<Field
orientation="responsive"
:class="field.state.value ? 'relative isolate before:pointer-events-none before:absolute before:inset-y-0 before:-inset-x-3 before:-z-10 before:rounded-md before:border before:border-danger/40 before:bg-danger-soft' : undefined"
>
<FieldContent>
<FieldLabel>Allow private networks</FieldLabel>
<FieldDescription>Host dashboard and Docker API access.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Switch
:model-value="field.state.value"
aria-label="Allow private networks"
:disabled="!webFetchOn"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="web_fetch.allow_private_networks" />
</div>
</Field>
</form.Field>
</FieldGroup>
</Section>
<Section title="Tool output">
<SettingRow label="Max result length" for="tp-chars" :hint="`≈ ${Math.round(tools.policy.max_result_chars / 4).toLocaleString()} tokens`">
<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.">
<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>
<FieldGroup class="@container/field-group">
<form.Field v-slot="{ field }" name="policy.max_result_chars">
<Field orientation="responsive">
<FieldContent>
<FieldLabel for="tp-chars">Max result length</FieldLabel>
<FieldDescription>{{ `≈ ${Math.round(field.state.value / 4).toLocaleString()} tokens` }}</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<InputGroup class="w-48">
<InputGroupInput
id="tp-chars"
:model-value="field.state.value"
type="number"
min="0"
class="font-mono"
@update:model-value="(value: string | number) => field.handleChange(looseNumber(value))"
/>
<InputGroupAddon align="inline-end">
<InputGroupText class="font-mono text-xs">chars</InputGroupText>
</InputGroupAddon>
</InputGroup>
<DraftHint :kind="KIND" path="policy.max_result_chars" />
</div>
</Field>
</form.Field>
<form.Field v-slot="{ field }" name="policy.spill_dir">
<Field orientation="responsive">
<FieldContent>
<FieldLabel for="tp-spill">Spill directory</FieldLabel>
<FieldDescription>Empty: truncate.</FieldDescription>
</FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input
id="tp-spill"
:model-value="field.state.value"
class="max-w-md font-mono"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
<DraftHint :kind="KIND" path="policy.spill_dir" />
</div>
</Field>
</form.Field>
</FieldGroup>
</Section>
</template>
</div>
+40 -21
View File
@@ -1,11 +1,12 @@
<script setup lang="ts">
import { computed, onMounted } from "vue";
import { Field, FieldContent, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Section } from "@/components/ui/section";
import { Input } from "@/components/ui/input";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
import { SettingRow } from "@/components/ui/setting-row";
import { useSettingsStore } from "@/stores/settings";
import { fieldInvalid } from "./settings-form";
const KIND = "update-settings";
type UpdateSettings = { channel: string; pin: string };
@@ -13,7 +14,8 @@ type UpdateSettings = { channel: string; pin: string };
const store = useSettingsStore();
onMounted(store.load);
const draft = computed(() => store.drafts[KIND]?.value as UpdateSettings | undefined);
const form = computed(() => store.formFor(KIND));
const channel = computed(() => (store.draftValue(KIND) as UpdateSettings | undefined)?.channel || "stable");
const error = computed(() => store.pageErrorFor(KIND));
const channels = [
@@ -21,28 +23,45 @@ const channels = [
{ value: "next", label: "Prereleases" },
{ value: "exact-pin", label: "Pinned" },
];
const channel = computed({
get: () => draft.value?.channel || "stable",
set: (value: string) => {
if (draft.value) draft.value.channel = value;
},
});
</script>
<template>
<Section v-if="draft" title="Updates">
<Section v-if="form" title="Updates">
<p v-if="error" class="mb-2 text-sm text-danger" role="alert">{{ error }}</p>
<SettingRow label="Release channel">
<div class="flex justify-end">
<ToggleGroup type="single" variant="outline" size="sm" :model-value="channel" aria-label="Release channel" @update:model-value="(value) => { if (value) channel = value as typeof channel; }">
<ToggleGroupItem v-for="option in channels" :key="option.value" :value="option.value">{{ option.label }}</ToggleGroupItem>
</ToggleGroup>
</div>
</SettingRow>
<SettingRow v-if="channel === 'exact-pin'" label="Version" for="update-pin">
<div class="flex justify-end">
<Input id="update-pin" v-model="draft.pin" class="max-w-40 font-mono" placeholder="1.48.0" />
</div>
</SettingRow>
<FieldGroup class="@container/field-group">
<form.Field v-slot="{ field }" name="channel">
<Field orientation="responsive">
<FieldContent><FieldLabel>Release channel</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<ToggleGroup
type="single"
variant="outline"
size="sm"
:model-value="channel"
aria-label="Release channel"
@update:model-value="(value) => { if (value) field.handleChange(value); }"
>
<ToggleGroupItem v-for="option in channels" :key="option.value" :value="option.value">{{ option.label }}</ToggleGroupItem>
</ToggleGroup>
</div>
</Field>
</form.Field>
<form.Field v-if="channel === 'exact-pin'" v-slot="{ field }" name="pin">
<Field orientation="responsive" :data-invalid="fieldInvalid(field)">
<FieldContent><FieldLabel for="update-pin">Version</FieldLabel></FieldContent>
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
<Input
id="update-pin"
:model-value="field.state.value"
class="max-w-40 font-mono"
placeholder="1.48.0"
:aria-invalid="fieldInvalid(field)"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
</div>
</Field>
</form.Field>
</FieldGroup>
</Section>
</template>
+14 -13
View File
@@ -17,21 +17,23 @@ export interface Connection {
export const permits = (c: Connection): [string, string[]][] =>
Object.entries(c.permits ?? {});
export function addPermit(c: Connection): void {
c.permits ??= {};
c.permits[""] = ["clone"];
// Each edit returns a new connection: the one passed in belongs to a settings
// form, and a write in place never reaches it.
export function addPermit(c: Connection): Connection {
return { ...c, permits: { ...c.permits, "": ["clone"] } };
}
export function removePermit(c: Connection, id: string): void {
if (c.permits) delete c.permits[id];
export function removePermit(c: Connection, id: string): Connection {
const { [id]: _, ...rest } = c.permits ?? {};
return { ...c, permits: rest };
}
// Renaming rebuilds the entry: the identity reference is the map key.
export function renamePermit(c: Connection, from: string, to: string): void {
if (!c.permits || from === to) return;
const operations = c.permits[from];
delete c.permits[from];
if (to) c.permits[to] = operations;
export function renamePermit(c: Connection, from: string, to: string): Connection {
if (!c.permits || from === to) return c;
const { [from]: operations = [], ...rest } = c.permits;
return { ...c, permits: to ? { ...rest, [to]: operations } : rest };
}
export function toggleOperation(
@@ -39,12 +41,11 @@ export function toggleOperation(
id: string,
operation: string,
on: boolean,
): void {
): Connection {
const current = new Set(c.permits?.[id] ?? []);
if (on) current.add(operation);
else current.delete(operation);
c.permits ??= {};
c.permits[id] = OPERATIONS.filter((o) => current.has(o));
return { ...c, permits: { ...c.permits, [id]: OPERATIONS.filter((o) => current.has(o)) } };
}
/** Identities a permit row may pick: any not already permitted on another row. */
+105
View File
@@ -0,0 +1,105 @@
import { Field, FormApi, type AnyFormApi } from "@tanstack/vue-form";
import { defineComponent, h, shallowRef, type Component, type ShallowRef } from "vue";
import type { DraftValidator } from "./validation.ts";
/**
* The edit form for one control-plane resource kind.
*
* The settings store owns these, not the pages: an edit survives in-app
* navigation and the save bar reviews every section at once, so a form cannot
* live and die with the page that renders it. Pages bind fields through
* `Field`, the same slot component useForm returns.
*/
export interface SettingsForm {
api: AnyFormApi;
/** form.Field, bound to this form. */
Field: ReturnType<typeof defineComponent>;
/** The current values, mirrored into Vue so diffs and pages react to edits. */
values: ShallowRef<unknown>;
/** Validates and saves. False when validation blocked it or the save failed. */
submit: () => Promise<boolean>;
/** Replaces the values; keepDefaultValues leaves the edit dirty against them. */
reset: (value: unknown, opts?: { keepDefaultValues?: boolean }) => void;
dispose: () => void;
}
/** createSettingsForm builds the form for one kind. `validate` is the kind's
* draft rule; its issues land on the fields they name, so a field's own error
* and the save bar's list come from one function. `submit` performs the save
* and reports whether it landed. */
export function createSettingsForm(
initial: unknown,
validate: DraftValidator | undefined,
submit: (value: unknown) => Promise<boolean>,
): SettingsForm {
let saved = false;
// TanStack turns a null document into {}. An unset resource is stored as
// null, so while the form is still empty it reports, diffs and saves null;
// otherwise opening an unset section would read as an edit, and saving it
// would store {} where nothing was set, even for a list-shaped kind.
let unset = initial === null;
const current = (value: unknown) => (unset && isEmptyObject(value) ? null : value);
const api = new FormApi({
defaultValues: initial ?? {},
validators: validate
? {
onChange: ({ value }: { value: unknown }) => {
const issues = validate(value);
if (!issues.length) return undefined;
return { fields: Object.fromEntries(issues.map((issue) => [issue.path, issue.message])) };
},
}
: undefined,
onSubmit: async ({ value }: { value: unknown }) => {
saved = await submit(current(value));
},
}) as AnyFormApi;
const unmount = api.mount();
const values = shallowRef<unknown>(current(api.state.values));
const { unsubscribe } = api.store.subscribe(() => {
const next = current(api.state.values);
if (values.value !== next) values.value = next;
});
const BoundField = defineComponent(
// Field is typed generically over the form; bound here, it is any field of it.
(_props, context) => () => h(Field as Component, { ...context.attrs, form: api }, context.slots),
{ name: "SettingsField", inheritAttrs: false },
);
return {
api,
Field: BoundField,
values,
reset: (value, opts) => {
unset = value === null;
api.reset(value ?? {}, opts);
},
submit: async () => {
saved = false;
await api.handleSubmit();
return saved;
},
dispose: () => {
unsubscribe();
unmount();
},
};
}
function isEmptyObject(value: unknown): boolean {
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 0;
}
interface FieldMetaLike {
state: { meta: { isValid: boolean; isTouched: boolean; isDirty: boolean } };
}
/** fieldInvalid is the shadcn-vue isInvalid check: show an error once the
* operator has touched or changed the field, not on a value they never edited. */
export function fieldInvalid(field: FieldMetaLike): boolean {
const { isValid, isTouched, isDirty } = field.state.meta;
return !isValid && (isTouched || isDirty);
}
+75 -30
View File
@@ -1,5 +1,5 @@
import { defineStore } from "pinia";
import { computed, onScopeDispose, reactive, ref, watch } from "vue";
import { computed, onScopeDispose, reactive, ref, shallowReactive, watch } from "vue";
import { useSessionStore } from "./session.ts";
import { api } from "../lib/api.ts";
import type { ConfigView } from "../settings/types.ts";
@@ -11,6 +11,7 @@ import {
type BlockingField,
type FieldIssue,
} from "../settings/validation.ts";
import { createSettingsForm, type SettingsForm } from "../settings/settings-form.ts";
export interface ResourceDescriptor {
kind: string;
@@ -209,11 +210,6 @@ export function commandBody(value: unknown, expectedVersion: number): string {
return JSON.stringify({ value, expected_version: expectedVersion });
}
interface Draft {
base: ControlPlaneResource;
value: unknown;
}
export const useSettingsStore = defineStore("settings", () => {
/** The daemon's published configuration projection: what is in force. */
const config = ref<ConfigView | null>(null);
@@ -263,42 +259,81 @@ export const useSettingsStore = defineStore("settings", () => {
state.resource = resource;
state.error = undefined;
state.conflict = false;
if (changesFor(resource.kind).length === 0) resetDraft(resource.kind);
if (!forms[resource.kind]) createForm(resource);
else if (changesFor(resource.kind).length === 0) resetDraft(resource.kind);
}
// An edit in progress, against the version it started from. A save sends
// that version, so a change made elsewhere meanwhile is a conflict rather
// than silently overwritten.
const drafts = reactive<Record<string, Draft>>({});
// One edit form per kind, against the version its edit started from. A save
// sends that version, so a change made elsewhere meanwhile is a conflict
// rather than silently overwritten.
const forms = shallowReactive<Record<string, SettingsForm>>({});
const bases = shallowReactive<Record<string, ControlPlaneResource>>({});
function createForm(resource: ControlPlaneResource): void {
const kind = resource.kind;
bases[kind] = resource;
forms[kind] = createSettingsForm(
cloneControlPlaneValue(resource.value),
draftValidators[kind],
(value) => saveValue(kind, value),
);
}
/** The form a page binds its fields to; undefined until the kind loads. */
function formFor(kind: string): SettingsForm | undefined {
return forms[kind];
}
/** The edited value of a kind, read-only: edits go through its form. */
function draftValue(kind: string): unknown {
return forms[kind]?.values.value;
}
/** Replaces a form's values, keeping the version the edit started from. */
function setDraftValue(kind: string, value: unknown): void {
forms[kind]?.reset(cloneControlPlaneValue(value), { keepDefaultValues: true });
}
/** Sets or, with undefined, removes one entry of a map-shaped kind. Map keys
* are free text (alias names, profile names, identity IDs), and a key holding
* "." or "[" is not a usable TanStack field path, so map entries are written
* through the whole value rather than setFieldValue. */
function setDraftEntry(kind: string, key: string, value: unknown): void {
const current = (draftValue(kind) ?? {}) as Record<string, unknown>;
const { [key]: _, ...rest } = current;
setDraftValue(kind, value === undefined ? rest : { ...current, [key]: value });
}
function resetDraft(kind: string): void {
const resource = stateFor(kind).resource;
if (resource)
drafts[kind] = { base: resource, value: cloneControlPlaneValue(resource.value) };
const form = forms[kind];
if (!resource || !form) return;
bases[kind] = resource;
form.reset(cloneControlPlaneValue(resource.value));
}
/** Undoes one change in a draft and keeps the rest. */
function revertDraftChange(kind: string, change: Change): void {
const draft = drafts[kind];
if (draft) draft.value = revertChange(draft.value, change);
if (forms[kind]) setDraftValue(kind, revertChange(draftValue(kind), change));
}
/** Loads an earlier version into the draft and opens the review, so a restore
* is applied the same deliberate way an edit is. */
function stageRestore(kind: string, value: unknown): void {
const resource = stateFor(kind).resource;
if (!resource) return;
drafts[kind] = { base: resource, value: cloneControlPlaneValue(value) };
if (!resource || !forms[kind]) return;
bases[kind] = resource;
setDraftValue(kind, value);
reviewing.value = true;
}
// The diff for every draft, computed once per change. The save bar, the
// The diff for every form, 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);
for (const [kind, form] of Object.entries(forms))
byKind[kind] = diffValues(bases[kind]!.value, form.values.value);
return byKind;
});
@@ -331,7 +366,7 @@ export const useSettingsStore = defineStore("settings", () => {
/** 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),
collectIssues(dirtyKinds.value, draftValue, draftValidators),
);
/** The issues for one section, empty unless it has unsaved changes. The
@@ -339,19 +374,26 @@ export const useSettingsStore = defineStore("settings", () => {
function issuesFor(kind: string): FieldIssue[] {
if (changesFor(kind).length === 0) return [];
const validate = draftValidators[kind];
return validate ? validate(drafts[kind]?.value) : [];
return validate ? validate(draftValue(kind)) : [];
}
async function saveDraft(kind: string): Promise<boolean> {
const draft = drafts[kind];
if (!draft) return true;
const saved = await replace(kind, cloneControlPlaneValue(draft.value), draft.base.version);
// The form's submit handler: validation has passed by the time this runs.
async function saveValue(kind: string, value: unknown): Promise<boolean> {
const base = bases[kind];
if (!base) return false;
const saved = await replace(kind, cloneControlPlaneValue(value), base.version);
if (saved) resetDraft(kind);
else if (stateFor(kind).conflict && stateFor(kind).resource)
drafts[kind] = { base: stateFor(kind).resource!, value: draft.value };
// A conflict keeps the operator's values against the latest version, so a
// second save is a deliberate overwrite of what they have now seen.
else if (stateFor(kind).conflict && stateFor(kind).resource) bases[kind] = stateFor(kind).resource!;
return saved;
}
function saveDraft(kind: string): Promise<boolean> {
const form = forms[kind];
return form ? form.submit() : Promise.resolve(true);
}
function saveDrafts() {
return saveInOrder(dirtyKinds.value, saveDraft);
}
@@ -466,7 +508,7 @@ export const useSettingsStore = defineStore("settings", () => {
/** Services the credential bindings define, which identity grants choose from. */
const credentialServices = computed(() => {
const bindings = (drafts["credential-bindings"]?.value ?? []) as { service: string }[];
const bindings = (draftValue("credential-bindings") ?? []) as { service: string }[];
return [...new Set(bindings.map((b) => b.service))].sort();
});
return {
@@ -481,7 +523,10 @@ export const useSettingsStore = defineStore("settings", () => {
dirtyKinds,
invalidFields,
issuesFor,
drafts,
formFor,
draftValue,
setDraftValue,
setDraftEntry,
resetDraft,
revertDraftChange,
stageRestore,