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
@@ -64,6 +64,9 @@ type channelInstance struct {
|
||||
chat messaging.ChatContract
|
||||
// plan is what an org's channel was built from.
|
||||
plan *orgChannelPlan
|
||||
// needs names the required settings an enabled channel lacks; such a
|
||||
// channel is reported stopped with it rather than started to fail.
|
||||
needs string
|
||||
|
||||
mu sync.Mutex
|
||||
channel channels.Channel
|
||||
|
||||
@@ -2,6 +2,7 @@ package archiemessaging
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"maps"
|
||||
@@ -114,6 +115,17 @@ func openExtensionChannels(ctx context.Context, source extension.Source, secrets
|
||||
if index < 0 {
|
||||
continue
|
||||
}
|
||||
if missing := pkg.Descriptor.MissingSettings(setting.Settings); len(missing) > 0 {
|
||||
needs := "Missing " + strings.Join(missing, ", ")
|
||||
log.WarnContext(ctx, "channel extension not started: required settings missing", "channel", pkg.Name, "missing", missing)
|
||||
instances = append(instances, &channelInstance{
|
||||
name: pkg.Name,
|
||||
needs: needs,
|
||||
rebuild: func(ResolvedConfig) (channels.Channel, error) { return nil, errors.New(needs) },
|
||||
})
|
||||
built[pkg.Name] = true
|
||||
continue
|
||||
}
|
||||
ch, err := factory.build(ctx, pkg, pkg.Descriptor.Contributes.Extensions[index].Path, pkg.Name, setting.Settings)
|
||||
if err != nil {
|
||||
log.WarnContext(ctx, "channel extension not started", "channel", pkg.Name, "err", err)
|
||||
|
||||
@@ -26,7 +26,7 @@ func (s *Service) runChannel(ctx context.Context, c *channelInstance) {
|
||||
if ch == nil {
|
||||
// Disabled: there is no channel to run until an enable builds one.
|
||||
c.mu.Unlock()
|
||||
s.status.MarkStopped(c.name, "")
|
||||
s.status.MarkStopped(c.name, c.needs)
|
||||
if s.awaitChannel(ctx, c, 0) == channelShutdown {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -27,6 +27,51 @@ type Descriptor struct {
|
||||
Requires []PackageRef `yaml:"requires"`
|
||||
Authority Authority `yaml:"authority"`
|
||||
Files []File `yaml:"files"`
|
||||
// Settings are what an operator enters for the package's extensions to
|
||||
// run, which the dashboard renders as a form.
|
||||
Settings []Setting `yaml:"settings"`
|
||||
}
|
||||
|
||||
// Setting is one value an extension reads from its operator-entered settings.
|
||||
// A secret setting holds an engine:key reference, never the secret, and its
|
||||
// key ends in "_ref" so the host resolves it before the extension starts.
|
||||
type Setting struct {
|
||||
Key string `yaml:"key" json:"key"`
|
||||
Label string `yaml:"label" json:"label"`
|
||||
Description string `yaml:"description" json:"description,omitempty"`
|
||||
Secret bool `yaml:"secret" json:"secret,omitempty"`
|
||||
Required bool `yaml:"required" json:"required,omitempty"`
|
||||
}
|
||||
|
||||
var settingKeyPattern = regexp.MustCompile(`^[a-z][a-z0-9_]*$`)
|
||||
|
||||
// MissingSettings returns the labels of the required settings values lacks.
|
||||
func (d Descriptor) MissingSettings(values map[string]string) []string {
|
||||
var missing []string
|
||||
for _, setting := range d.Settings {
|
||||
if setting.Required && strings.TrimSpace(values[setting.Key]) == "" {
|
||||
missing = append(missing, setting.Label)
|
||||
}
|
||||
}
|
||||
return missing
|
||||
}
|
||||
|
||||
func (d Descriptor) validateSettings() error {
|
||||
seen := make(map[string]bool, len(d.Settings))
|
||||
for i, setting := range d.Settings {
|
||||
switch {
|
||||
case !settingKeyPattern.MatchString(setting.Key):
|
||||
return fmt.Errorf("setting %d: key %q must be lower-case letters, digits and underscores", i, setting.Key)
|
||||
case seen[setting.Key]:
|
||||
return fmt.Errorf("setting %q is declared twice", setting.Key)
|
||||
case strings.TrimSpace(setting.Label) == "":
|
||||
return fmt.Errorf("setting %q: label is required", setting.Key)
|
||||
case setting.Secret != strings.HasSuffix(setting.Key, "_ref"):
|
||||
return fmt.Errorf("setting %q: a secret setting's key ends in _ref, and only a secret's does", setting.Key)
|
||||
}
|
||||
seen[setting.Key] = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Contributions names the declarative families supplied by a package.
|
||||
@@ -138,6 +183,9 @@ func (d Descriptor) Validate() error {
|
||||
if err := d.Authority.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := d.validateSettings(); err != nil {
|
||||
return err
|
||||
}
|
||||
executable, err := d.validateExtensions()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"slices"
|
||||
@@ -37,6 +38,7 @@ func (a *extensionsAPI) register(mux *http.ServeMux) {
|
||||
mux.HandleFunc("POST /api/extensions/{name}/rollback", a.handleExtensionRollback)
|
||||
mux.HandleFunc("PUT /api/extensions/{name}/update-policy", a.handleExtensionUpdatePolicy)
|
||||
mux.HandleFunc("PUT /api/extensions/{name}/enabled", a.handleExtensionEnabled)
|
||||
mux.HandleFunc("PUT /api/extensions/{name}/settings", a.handleExtensionSettings)
|
||||
mux.HandleFunc("DELETE /api/extensions/{name}", a.handleExtensionRemove)
|
||||
}
|
||||
|
||||
@@ -57,9 +59,9 @@ func authorityOf(a storepkg.Authority) authorityView {
|
||||
}
|
||||
}
|
||||
|
||||
func orEmpty(s []string) []string {
|
||||
func orEmpty[T any](s []T) []T {
|
||||
if s == nil {
|
||||
return []string{}
|
||||
return []T{}
|
||||
}
|
||||
return s
|
||||
}
|
||||
@@ -83,6 +85,10 @@ type ExtensionView struct {
|
||||
CanRollback bool `json:"can_rollback"`
|
||||
// UpdatePolicy is "manual" or "auto".
|
||||
UpdatePolicy string `json:"update_policy"`
|
||||
// SettingsSchema is what the package declares an operator enters, and
|
||||
// Settings the values entered; a secret's value is its reference.
|
||||
SettingsSchema []storepkg.Setting `json:"settings_schema"`
|
||||
Settings map[string]string `json:"settings"`
|
||||
}
|
||||
|
||||
type pendingView struct {
|
||||
@@ -114,6 +120,7 @@ func extensionView(p storepkg.Installed, enabled bool) ExtensionView {
|
||||
Name: p.Name, DisplayName: p.Descriptor.DisplayName, Description: p.Descriptor.Description,
|
||||
Version: p.Descriptor.Version, Reference: p.Reference, Digest: p.Digest,
|
||||
Surfaces: []string{}, Declared: authorityOf(p.Descriptor.Authority), Enabled: enabled,
|
||||
SettingsSchema: orEmpty(p.Descriptor.Settings), Settings: map[string]string{},
|
||||
}
|
||||
for _, extension := range p.Descriptor.Contributes.Extensions {
|
||||
if !slices.Contains(view.Surfaces, extension.Surface) {
|
||||
@@ -227,13 +234,17 @@ func (a *extensionsAPI) handleExtensions(w http.ResponseWriter, r *http.Request)
|
||||
writeControlPlaneError(w, err)
|
||||
return
|
||||
}
|
||||
enabled := make(map[string]bool, len(doc.Extensions))
|
||||
stored := make(map[string]controlplanerpc.ExtensionSetting, len(doc.Extensions))
|
||||
for _, setting := range doc.Extensions {
|
||||
enabled[setting.Name] = setting.Enabled
|
||||
stored[setting.Name] = setting
|
||||
}
|
||||
views := make([]ExtensionView, 0, len(installed))
|
||||
for _, p := range installed {
|
||||
views = append(views, extensionView(p, enabled[p.Name]))
|
||||
view := extensionView(p, stored[p.Name].Enabled)
|
||||
if values := stored[p.Name].Settings; values != nil {
|
||||
view.Settings = values
|
||||
}
|
||||
views = append(views, view)
|
||||
}
|
||||
writeJSON(w, map[string]any{"extensions": views})
|
||||
}
|
||||
@@ -365,6 +376,86 @@ func (a *extensionsAPI) handleExtensionEnabled(w http.ResponseWriter, r *http.Re
|
||||
writeJSON(w, map[string]any{"name": name, "enabled": request.Enabled})
|
||||
}
|
||||
|
||||
type extensionSettingsRequest struct {
|
||||
Settings map[string]string `json:"settings"`
|
||||
}
|
||||
|
||||
// handleExtensionSettings replaces the settings an installed extension runs
|
||||
// with. Only the keys its package declares are accepted, and a secret is
|
||||
// accepted only as an engine:key reference.
|
||||
func (a *extensionsAPI) handleExtensionSettings(w http.ResponseWriter, r *http.Request) {
|
||||
if !a.extensionsReady(w) {
|
||||
return
|
||||
}
|
||||
request, ok := decodeBody[extensionSettingsRequest](w, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
name := r.PathValue("name")
|
||||
installed, err := a.packages.GetInstalled(r.Context(), name)
|
||||
if err != nil {
|
||||
writePackageError(w, err)
|
||||
return
|
||||
}
|
||||
values, err := declaredSettings(installed.Descriptor.Settings, request.Settings)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
doc, version, err := a.extensionSettings(r.Context())
|
||||
if err != nil {
|
||||
writeControlPlaneError(w, err)
|
||||
return
|
||||
}
|
||||
if err := a.putExtensionSettings(r.Context(), withSettings(doc, name, values), version); err != nil {
|
||||
writeControlPlaneError(w, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, map[string]any{"name": name, "settings": values})
|
||||
}
|
||||
|
||||
// declaredSettings checks values against the package's declared settings and
|
||||
// returns them trimmed, with empty values dropped.
|
||||
func declaredSettings(schema []storepkg.Setting, values map[string]string) (map[string]string, error) {
|
||||
declared := make(map[string]storepkg.Setting, len(schema))
|
||||
for _, setting := range schema {
|
||||
declared[setting.Key] = setting
|
||||
}
|
||||
out := make(map[string]string, len(values))
|
||||
for key, value := range values {
|
||||
setting, ok := declared[key]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("setting %q is not declared by the package", key)
|
||||
}
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
if setting.Secret {
|
||||
engine, ref, found := strings.Cut(value, ":")
|
||||
if !found || engine == "" || ref == "" {
|
||||
return nil, fmt.Errorf("%s must be a secret reference (engine:key)", setting.Label)
|
||||
}
|
||||
}
|
||||
out[key] = value
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// withSettings returns doc with the named extension's settings replaced,
|
||||
// keeping whether it is enabled.
|
||||
func withSettings(doc controlplanerpc.ExtensionSettings, name string, values map[string]string) controlplanerpc.ExtensionSettings {
|
||||
next := controlplanerpc.ExtensionSettings{Extensions: slices.Clone(doc.Extensions)}
|
||||
for i := range next.Extensions {
|
||||
if next.Extensions[i].Name == name {
|
||||
next.Extensions[i].Settings = values
|
||||
return next
|
||||
}
|
||||
}
|
||||
next.Extensions = append(next.Extensions, controlplanerpc.ExtensionSetting{Name: name, Settings: values})
|
||||
return next
|
||||
}
|
||||
|
||||
// handleExtensionRemove uninstalls an extension and drops its setting, so a
|
||||
// later reinstall does not start enabled.
|
||||
func (a *extensionsAPI) handleExtensionRemove(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/storepkg"
|
||||
)
|
||||
|
||||
// An extension's settings accept only what its package declares, and a secret
|
||||
// only as a reference: a pasted credential must never reach stored settings.
|
||||
func TestDeclaredSettings(t *testing.T) {
|
||||
schema := []storepkg.Setting{
|
||||
{Key: "imap_addr", Label: "IMAP address", Required: true},
|
||||
{Key: "password_ref", Label: "Password", Secret: true, Required: true},
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
give map[string]string
|
||||
want map[string]string
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "declared values are trimmed", give: map[string]string{"imap_addr": " mail:993 ", "password_ref": "bws:mail"}, want: map[string]string{"imap_addr": "mail:993", "password_ref": "bws:mail"}},
|
||||
{name: "empty values are dropped", give: map[string]string{"imap_addr": "", "password_ref": " "}, want: map[string]string{}},
|
||||
{name: "undeclared key", give: map[string]string{"smtp_addr": "mail:587"}, wantErr: true},
|
||||
{name: "raw secret", give: map[string]string{"password_ref": "hunter2"}, wantErr: true},
|
||||
{name: "reference without a key", give: map[string]string{"password_ref": "bws:"}, wantErr: true},
|
||||
{name: "reference without an engine", give: map[string]string{"password_ref": ":mail"}, wantErr: true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := declaredSettings(schema, tt.give)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Fatalf("err = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
if !tt.wantErr && !maps.Equal(got, tt.want) {
|
||||
t.Fatalf("got %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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