feat(channels): package-declared channel settings on an instance Channels page (#1796)
This commit is contained in:
12 files changed
+621
-139
No files matched your search
@@ -1,23 +1,14 @@
|
||||
<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, reactive, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
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 { Badge } from "@/components/ui/badge";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import {
|
||||
@@ -31,7 +22,6 @@ import { api } from "@/lib/api";
|
||||
import OptionSelect from "@/workflows/OptionSelect.vue";
|
||||
import { useOrgStore, type Identity } from "@/stores/org";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import SecretRefField from "@/settings/SecretRefField.vue";
|
||||
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
|
||||
import { useLiveResource, useSessionStore } from "@/stores/session";
|
||||
|
||||
@@ -67,10 +57,11 @@ const form = computed(() => store.formFor(KIND));
|
||||
const chat = computed(() => store.draftValue(KIND) as ChannelSettings | undefined);
|
||||
const error = computed(() => store.pageErrorFor(KIND));
|
||||
|
||||
// The instance's workspace, filesystem, rate limit and bot token are the
|
||||
// system org's; another org runs its own bot as one of its agents, with its
|
||||
// token bound as a credential.
|
||||
const instance = computed(() => useSessionStore().sections?.settings !== false);
|
||||
// The instance's own bot, its connection and the session defaults are
|
||||
// Instance settings; another org runs its own bot as one of its agents, with
|
||||
// its token bound as a credential, and chooses here which agent answers.
|
||||
const session = useSessionStore();
|
||||
const router = useRouter();
|
||||
const identities = useOrgStore();
|
||||
const agents = ref<Identity[]>([]);
|
||||
const agentsError = ref("");
|
||||
@@ -111,7 +102,14 @@ async function loadStatus() {
|
||||
}
|
||||
}
|
||||
useLiveResource(null, () => void loadStatus());
|
||||
onMounted(() => Promise.all([loadStatus(), store.load(), instance.value ? undefined : loadAgents()]));
|
||||
onMounted(async () => {
|
||||
await session.loadCapabilities();
|
||||
if (session.systemOrg) {
|
||||
await router.replace("/settings/channels");
|
||||
return;
|
||||
}
|
||||
await Promise.all([loadStatus(), store.load(), loadAgents()]);
|
||||
});
|
||||
|
||||
// Running state comes only from the messaging service's report; a channel it
|
||||
// does not mention shows none rather than one guessed from its settings.
|
||||
@@ -127,7 +125,7 @@ function statusOf(id: string) {
|
||||
// A channel is set up once its enabling field is filled in, the rule the
|
||||
// daemon applies when it decides what to start.
|
||||
const configured = computed(() => ({
|
||||
telegram: instance.value ? !!chat.value?.telegram.token_ref.key : !!chat.value?.agent,
|
||||
telegram: !!chat.value?.agent,
|
||||
}));
|
||||
const opened = reactive({ telegram: false });
|
||||
const shown = (id: keyof typeof opened) => configured.value[id] || opened[id];
|
||||
@@ -137,16 +135,12 @@ const channels = [
|
||||
] as const;
|
||||
|
||||
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>
|
||||
@@ -176,7 +170,7 @@ function setModels(list: string[]) {
|
||||
</div>
|
||||
</template>
|
||||
<FieldGroup v-if="form && shown(channel.id) && channel.id === 'telegram'" class="@container/field-group">
|
||||
<form.Field v-if="!instance" v-slot="{ field }" name="agent">
|
||||
<form.Field v-slot="{ field }" name="agent">
|
||||
<Field orientation="responsive">
|
||||
<FieldContent><FieldLabel for="channel-agent">Runs as</FieldLabel></FieldContent>
|
||||
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
||||
@@ -193,17 +187,6 @@ function setModels(list: string[]) {
|
||||
<Alert v-if="agentsError" variant="destructive"><AlertDescription>{{ agentsError }} <Button variant="link" size="xs" @click="loadAgents">Retry</Button></AlertDescription></Alert>
|
||||
</Field>
|
||||
</form.Field>
|
||||
<form.Field v-if="instance" v-slot="{ field }" name="telegram.token_ref">
|
||||
<Field orientation="responsive">
|
||||
<FieldContent>
|
||||
<FieldLabel for="tg-token-field">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">
|
||||
<div id="tg-token-field" role="group" aria-label="Bot token" class="contents"><SecretRefField :model-value="field.state.value" id-prefix="tg-token" @update:model-value="field.handleChange" /></div>
|
||||
</div>
|
||||
</Field>
|
||||
</form.Field>
|
||||
<Field orientation="responsive">
|
||||
<FieldContent>
|
||||
<FieldLabel id="channel-allowed-label">Allowed users</FieldLabel>
|
||||
@@ -219,113 +202,17 @@ function setModels(list: string[]) {
|
||||
</TagsInput></div>
|
||||
</div>
|
||||
</Field>
|
||||
<form.Field v-if="!instance" v-slot="{ field }" name="show_tool_calls">
|
||||
<form.Field v-slot="{ field }" name="show_tool_calls">
|
||||
<Field orientation="responsive">
|
||||
<FieldContent><FieldLabel :for="`channel-show-tools-${instance ? 'instance' : 'channel'}`">Show tool calls</FieldLabel></FieldContent>
|
||||
<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-${instance ? 'instance' : 'channel'}`" :model-value="field.state.value" aria-label="Show tool calls" @update:model-value="field.handleChange" />
|
||||
<Switch id="channel-show-tools" :model-value="field.state.value" aria-label="Show tool calls" @update:model-value="field.handleChange" />
|
||||
</div>
|
||||
</Field>
|
||||
</form.Field>
|
||||
</FieldGroup>
|
||||
</Section>
|
||||
|
||||
<Section v-if="instance" 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-${instance ? 'instance' : 'channel'}`">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-${instance ? 'instance' : 'channel'}`" :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>
|
||||
@@ -64,6 +64,7 @@ const settings: NavSpec = {
|
||||
{
|
||||
label: "Connections & channels",
|
||||
paths: [
|
||||
"/settings/channels",
|
||||
"/settings/tools",
|
||||
"/settings/extensions",
|
||||
"/settings/plugins",
|
||||
|
||||
@@ -328,7 +328,6 @@ const routes = [
|
||||
"/settings/schedules": "/org/schedules",
|
||||
"/settings/playbooks": "/org/playbooks",
|
||||
"/settings/scheduling-policy": "/org/scheduling-policy",
|
||||
"/settings/channels": "/org/channels",
|
||||
"/settings/appearance": "/account/appearance",
|
||||
}).map(([path, redirect]) => ({ path, redirect, meta: { nav: false } })),
|
||||
{
|
||||
@@ -343,6 +342,12 @@ const routes = [
|
||||
section: "settings",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/settings/channels",
|
||||
name: "settings-channels",
|
||||
component: () => import("@/settings/ChannelSettingsPage.vue"),
|
||||
meta: { navPath: "/settings", settings: true, label: "Channels", description: "Chat channel connections and session defaults.", section: "channels" },
|
||||
},
|
||||
{
|
||||
path: "/settings/extensions",
|
||||
name: "settings-extensions",
|
||||
|
||||
@@ -0,0 +1,294 @@
|
||||
<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, reactive, 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 { Badge } from "@/components/ui/badge";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import {
|
||||
TagsInput,
|
||||
TagsInputInput,
|
||||
TagsInputItem,
|
||||
TagsInputItemDelete,
|
||||
TagsInputItemText,
|
||||
} from "@/components/ui/tags-input";
|
||||
import { api } from "@/lib/api";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import SecretRefField from "@/settings/SecretRefField.vue";
|
||||
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
|
||||
const KIND = "channel-settings";
|
||||
|
||||
interface SecretRef {
|
||||
engine: string;
|
||||
key: string;
|
||||
}
|
||||
interface ChannelSettings {
|
||||
operator: string;
|
||||
show_tool_calls: boolean;
|
||||
max_steps: number;
|
||||
models: string[] | null;
|
||||
telegram: { allowed_user_ids: number[] | null; token_ref: SecretRef; credential_configured: boolean };
|
||||
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));
|
||||
|
||||
// Telegram's connection is the core channel-settings resource; every other
|
||||
// channel package declares its settings, and the form is built from them.
|
||||
const extensions = useExtensionsStore();
|
||||
const extensionChannels = computed(() =>
|
||||
extensions.extensions.filter((e) => e.surfaces.includes("channel") && e.name !== "telegram" && 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()]));
|
||||
|
||||
// Running state comes only from the messaging service's report; a channel it
|
||||
// does not mention shows none rather than one guessed from its settings.
|
||||
function statusOf(id: string) {
|
||||
const state = statuses.value.find((s) => s.id === id)?.state;
|
||||
if (!state) return undefined;
|
||||
if (state === "running") return undefined;
|
||||
if (state === "failed") return { label: "Failed", tone: "danger" } as const;
|
||||
if (state === "degraded") return { label: "Degraded", tone: "warn" } as const;
|
||||
return { label: state[0]!.toUpperCase() + state.slice(1), tone: "idle" } as const;
|
||||
}
|
||||
|
||||
// A channel is set up once its enabling field is filled in, the rule the
|
||||
// daemon applies when it decides what to start.
|
||||
const configured = computed(() => ({
|
||||
telegram: !!chat.value?.telegram.token_ref.key,
|
||||
}));
|
||||
const opened = reactive({ telegram: false });
|
||||
const shown = (id: keyof typeof opened) => configured.value[id] || opened[id];
|
||||
|
||||
const channels = [
|
||||
{ id: "telegram", title: "Telegram" },
|
||||
] as const;
|
||||
|
||||
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 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>
|
||||
Couldn't load channel status
|
||||
<Button variant="link" size="xs" @click="loadStatus">Retry</Button>
|
||||
</AlertDescription></Alert>
|
||||
|
||||
<template v-if="chat">
|
||||
<Section v-for="channel in channels" :key="channel.id" :title="channel.title" :class="!shown(channel.id) && 'gap-0'">
|
||||
<template #action>
|
||||
<div class="flex items-center gap-2">
|
||||
<Badge v-if="configured[channel.id] && statusOf(channel.id)" :variant="statusOf(channel.id)!.tone">{{
|
||||
statusOf(channel.id)!.label
|
||||
}}</Badge>
|
||||
<Button v-if="!configured[channel.id] && !opened[channel.id]" variant="outline" size="sm" @click="opened[channel.id] = true">Set up</Button>
|
||||
</div>
|
||||
</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 for="tg-token-field">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">
|
||||
<div id="tg-token-field" role="group" aria-label="Bot token" class="contents"><SecretRefField :model-value="field.state.value" id-prefix="tg-token" @update:model-value="field.handleChange" /></div>
|
||||
</div>
|
||||
</Field>
|
||||
</form.Field>
|
||||
<Field orientation="responsive">
|
||||
<FieldContent>
|
||||
<FieldLabel id="channel-allowed-label">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">
|
||||
<div role="group" aria-labelledby="channel-allowed-label" class="contents"><TagsInput :model-value="allowedUsers" 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" aria-label="Allowed users" />
|
||||
</TagsInput></div>
|
||||
</div>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
</Section>
|
||||
|
||||
<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>
|
||||
@@ -0,0 +1,86 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { useExtensionsStore, type Extension } from "@/stores/extensions";
|
||||
import SecretRefField from "./SecretRefField.vue";
|
||||
|
||||
const props = defineProps<{
|
||||
extension: Extension;
|
||||
/** The messaging service's report for this channel, when it has one. */
|
||||
status?: { state?: string; detail?: string };
|
||||
}>();
|
||||
|
||||
const store = useExtensionsStore();
|
||||
const draft = ref<Record<string, string>>({});
|
||||
watch(() => props.extension.settings, (saved) => { draft.value = { ...saved }; }, { immediate: true });
|
||||
|
||||
const dirty = computed(() => {
|
||||
const saved = props.extension.settings;
|
||||
return props.extension.settings_schema.some((spec) => (draft.value[spec.key] ?? "").trim() !== (saved[spec.key] ?? ""));
|
||||
});
|
||||
const missing = computed(() =>
|
||||
props.extension.settings_schema.filter((spec) => spec.required && !(draft.value[spec.key] ?? "").trim()).map((spec) => spec.label),
|
||||
);
|
||||
|
||||
function secretRef(key: string): { engine: string; key: string } {
|
||||
const [engine = "", ...rest] = (draft.value[key] ?? "").split(":");
|
||||
return { engine, key: rest.join(":") };
|
||||
}
|
||||
function setSecretRef(key: string, value: { engine: string; key: string }): void {
|
||||
draft.value = { ...draft.value, [key]: value.engine || value.key ? `${value.engine}:${value.key}` : "" };
|
||||
}
|
||||
function setValue(key: string, value: string | number): void {
|
||||
draft.value = { ...draft.value, [key]: String(value) };
|
||||
}
|
||||
|
||||
const badge = computed(() => {
|
||||
if (!props.extension.enabled) return { label: "Off", tone: "idle" } as const;
|
||||
const state = props.status?.state;
|
||||
if (state === "failed") return { label: "Failed", tone: "danger" } as const;
|
||||
if (state === "degraded") return { label: "Degraded", tone: "warn" } as const;
|
||||
if (state === "stopped") return { label: "Stopped", tone: "idle" } as const;
|
||||
return undefined;
|
||||
});
|
||||
// The service reports why an enabled channel did not start: missing settings,
|
||||
// or the error its last run ended with.
|
||||
const problem = computed(() => (props.extension.enabled && props.status?.state !== "running" ? props.status?.detail : ""));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Section :title="extension.display_name || extension.name">
|
||||
<template #action>
|
||||
<Badge v-if="badge" :variant="badge.tone">{{ badge.label }}</Badge>
|
||||
</template>
|
||||
<Alert v-if="problem" variant="destructive"><AlertDescription>{{ problem }}</AlertDescription></Alert>
|
||||
<FieldGroup class="@container/field-group">
|
||||
<Field v-for="spec in extension.settings_schema" :key="spec.key" orientation="responsive">
|
||||
<FieldContent>
|
||||
<FieldLabel :for="`${extension.name}-${spec.key}`">{{ spec.label }}</FieldLabel>
|
||||
<FieldDescription v-if="spec.description">{{ spec.description }}</FieldDescription>
|
||||
</FieldContent>
|
||||
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
||||
<div v-if="spec.secret" :id="`${extension.name}-${spec.key}`" role="group" :aria-label="spec.label" class="contents">
|
||||
<SecretRefField :model-value="secretRef(spec.key)" :id-prefix="`${extension.name}-${spec.key}`" @update:model-value="(value) => setSecretRef(spec.key, value)" />
|
||||
</div>
|
||||
<Input
|
||||
v-else
|
||||
:id="`${extension.name}-${spec.key}`"
|
||||
:model-value="draft[spec.key] ?? ''"
|
||||
class="max-w-md font-mono"
|
||||
@update:model-value="(value) => setValue(spec.key, value)"
|
||||
/>
|
||||
</div>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
<div class="flex flex-wrap items-center justify-end gap-3">
|
||||
<span v-if="dirty && missing.length" class="text-caption text-fg-muted">Missing {{ missing.join(", ") }}</span>
|
||||
<Button size="sm" :disabled="!dirty || store.busy === extension.name" @click="store.saveSettings(extension.name, draft)">Save</Button>
|
||||
</div>
|
||||
</Section>
|
||||
</template>
|
||||
@@ -25,6 +25,18 @@ export interface Extension {
|
||||
pending: { digest: string; added: Authority } | null;
|
||||
can_rollback: boolean;
|
||||
update_policy: "manual" | "auto";
|
||||
/** What the package declares an operator enters, and what was entered. A
|
||||
* secret's value is its engine:key reference. */
|
||||
settings_schema: ExtensionSettingSpec[];
|
||||
settings: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface ExtensionSettingSpec {
|
||||
key: string;
|
||||
label: string;
|
||||
description?: string;
|
||||
secret?: boolean;
|
||||
required?: boolean;
|
||||
}
|
||||
|
||||
/** A package the verified catalogue offers. */
|
||||
@@ -144,6 +156,8 @@ export const useExtensionsStore = defineStore("extensions", () => {
|
||||
rollback: (name: string) => mutate(name, () => call(`${path(name)}/rollback`, { method: "POST" })),
|
||||
setEnabled: (name: string, enabled: boolean) =>
|
||||
mutate(name, () => call(`${path(name)}/enabled`, { method: "PUT", body: JSON.stringify({ enabled }) })),
|
||||
saveSettings: (name: string, settings: Record<string, string>) =>
|
||||
mutate(name, () => call(`${path(name)}/settings`, { method: "PUT", body: JSON.stringify({ settings }) })),
|
||||
remove: (name: string) => mutate(name, () => call(path(name), { method: "DELETE" })),
|
||||
};
|
||||
});
|
||||
Reference in new issue
Block a user