220 lines
9.9 KiB
Vue
220 lines
9.9 KiB
Vue
<script setup lang="ts">
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import ApplyStatusRows from "@/settings/ApplyStatusRows.vue";
|
|
import KindGate from "@/settings/KindGate.vue";
|
|
import HistoryLink from "@/settings/HistoryLink.vue";
|
|
import { computed, onMounted, ref } from "vue";
|
|
import ExtensionChannelSettings from "@/settings/ExtensionChannelSettings.vue";
|
|
import { useExtensionsStore } from "@/stores/extensions";
|
|
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,
|
|
NumberFieldContent,
|
|
NumberFieldDecrement,
|
|
NumberFieldIncrement,
|
|
NumberFieldInput,
|
|
} from "@/components/ui/number-field";
|
|
import { Switch } from "@/components/ui/switch";
|
|
import {
|
|
TagsInput,
|
|
TagsInputInput,
|
|
TagsInputItem,
|
|
TagsInputItemDelete,
|
|
TagsInputItemText,
|
|
} from "@/components/ui/tags-input";
|
|
import { api } from "@/lib/api";
|
|
import { errors } from "@/copy/errors";
|
|
import { Section } from "@/components/ui/section";
|
|
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
|
|
import { useLiveResource } from "@/stores/session";
|
|
|
|
const KIND = "channel-settings";
|
|
|
|
interface ChannelSettings {
|
|
operator: string;
|
|
show_tool_calls: boolean;
|
|
max_steps: number;
|
|
models: string[] | null;
|
|
rate_limit: { window: string; max_requests: number };
|
|
unrestricted_filesystem: boolean;
|
|
workspace: string;
|
|
agent: string;
|
|
}
|
|
|
|
/** What the messaging service reports about a running channel. */
|
|
interface ChannelStatus {
|
|
id?: string;
|
|
state?: string;
|
|
detail?: string;
|
|
}
|
|
|
|
const store = useSettingsStore();
|
|
const { catalog, catalogError } = storeToRefs(store);
|
|
const resources = computed(() => resourcesForPage(catalog.value, "channels"));
|
|
const form = computed(() => store.formFor(KIND));
|
|
const chat = computed(() => store.draftValue(KIND) as ChannelSettings | undefined);
|
|
const error = computed(() => store.pageErrorFor(KIND));
|
|
|
|
// Channel packages declare their settings, and each form is built from them.
|
|
const extensions = useExtensionsStore();
|
|
const extensionChannels = computed(() =>
|
|
extensions.extensions.filter((e) => e.surfaces.includes("channel") && e.settings_schema.length),
|
|
);
|
|
|
|
const statuses = ref<ChannelStatus[]>([]);
|
|
// A failed status read keeps the last known badges and flags the error, so a
|
|
// transient failure neither clears every badge nor passes as "all idle".
|
|
const statusError = ref(false);
|
|
let statusGeneration = 0;
|
|
async function loadStatus() {
|
|
const current = ++statusGeneration;
|
|
try {
|
|
statuses.value = (await api.channels<{ channels?: ChannelStatus[] }>())?.channels ?? [];
|
|
if (current !== statusGeneration) return;
|
|
statusError.value = false;
|
|
} catch {
|
|
if (current !== statusGeneration) return;
|
|
statusError.value = true;
|
|
}
|
|
}
|
|
useLiveResource(null, () => void loadStatus());
|
|
onMounted(() => Promise.all([loadStatus(), store.load(), extensions.loadInstalled()]));
|
|
|
|
const models = computed(() => chat.value?.models ?? []);
|
|
|
|
function statusFor(id: string) {
|
|
return statuses.value.find((s) => s.id === id);
|
|
}
|
|
function setModels(list: string[]) {
|
|
form.value?.api.setFieldValue("models", list);
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<PageHeader title="Channels">
|
|
<HistoryLink :kinds="resources.map((r) => r.kind)" />
|
|
</PageHeader>
|
|
<ApplyStatusRows :kind="KIND" class="mb-4" />
|
|
<ApplyStatusRows kind="extension-settings" class="mb-4" />
|
|
|
|
<Alert v-if="catalogError || error" variant="destructive" class="mb-4"><AlertDescription>
|
|
{{ catalogError || error }}
|
|
</AlertDescription></Alert>
|
|
|
|
<Alert v-if="extensions.error" variant="destructive" class="mb-4"><AlertDescription>{{ extensions.error }}</AlertDescription></Alert>
|
|
|
|
<Alert v-if="statusError" variant="destructive" class="mb-4"><AlertDescription>
|
|
{{ errors.settings.channels.status }}
|
|
<Button variant="link" size="xs" @click="loadStatus">Retry</Button>
|
|
</AlertDescription></Alert>
|
|
|
|
<template v-if="chat">
|
|
<ExtensionChannelSettings v-for="extension in extensionChannels" :key="extension.name" :extension="extension" :status="statusFor(extension.name)" />
|
|
|
|
<Section title="Chat session defaults">
|
|
<KindGate v-if="!form" :kind="KIND" />
|
|
<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 for="channel-unrestricted">Unrestricted filesystem</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<Switch id="channel-unrestricted" :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 for="channel-show-tools">Show tool calls</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
|
<Switch id="channel-show-tools" :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 for="channel-max-steps">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 id="channel-max-steps" class="font-mono" aria-label="Max steps" />
|
|
<NumberFieldIncrement />
|
|
</NumberFieldContent>
|
|
</NumberField>
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
<Field orientation="responsive">
|
|
<FieldContent>
|
|
<FieldLabel id="channel-rate-label">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" role="group" aria-labelledby="channel-rate-label">
|
|
<div class="flex flex-wrap items-center gap-2 text-label 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 id="channel-models-label">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">
|
|
<div role="group" aria-labelledby="channel-models-label" class="contents"><TagsInput :model-value="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" aria-label="Models" />
|
|
</TagsInput></div>
|
|
</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>
|
|
</template>
|