New settings/KindGate renders the store's per-kind loading/error state where the form would be: a skeleton while loading, ReadError with Retry on a failed read. Wired into Tools, SystemModels, SystemRepos, SchedulingPolicy, ContainerRuntime, OrgAlerts, Instructions, Plugins, SystemTasks, UpdateSettings, IdentityGrants, OrgModels, Channels and Authentication pages, which no longer render blank until the draft exists.
274 lines
11 KiB
Vue
274 lines
11 KiB
Vue
<script setup lang="ts">
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
|
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
|
import HistoryLink from "@/settings/HistoryLink.vue";
|
|
import { computed, onMounted, ref, watch } from "vue";
|
|
import { storeToRefs } from "pinia";
|
|
import { Plus } from "@lucide/vue";
|
|
|
|
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 { SettingRow } from "@/components/ui/setting-row";
|
|
import { Input } from "@/components/ui/input";
|
|
import {
|
|
InputGroup,
|
|
InputGroupAddon,
|
|
InputGroupInput,
|
|
InputGroupText,
|
|
} from "@/components/ui/input-group";
|
|
import { Section } from "@/components/ui/section";
|
|
import { Switch } from "@/components/ui/switch";
|
|
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
|
|
import DraftHint from "./DraftHint.vue";
|
|
import McpServerEditor, { type McpServer } from "./McpServerEditor.vue";
|
|
import SecretRefField from "./SecretRefField.vue";
|
|
|
|
const KIND = "tool-settings";
|
|
|
|
interface ToolSettings {
|
|
mcp_servers: McpServer[];
|
|
minimax: { base_url?:string; enabled: boolean; api_key_ref: { engine: string; key: string }; credential_configured?: boolean };
|
|
policy: { max_result_chars: number; spill_dir: string };
|
|
web_fetch: { enabled: boolean | null; timeout: string; max_bytes: number; allow_private_networks: boolean };
|
|
}
|
|
|
|
const store = useSettingsStore();
|
|
const { catalog, catalogError } = storeToRefs(store);
|
|
onMounted(store.load);
|
|
|
|
const resources = computed(() => resourcesForPage(catalog.value, "tools"));
|
|
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(() => 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 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 });
|
|
}
|
|
// 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 };
|
|
}
|
|
watch(
|
|
() => pending.value?.name,
|
|
(name) => {
|
|
if (!name?.trim() || !pending.value || !tools.value) return;
|
|
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>
|
|
<div>
|
|
<PageHeader title="Tools & MCP">
|
|
<HistoryLink :kinds="resources.map((r) => r.kind)" />
|
|
</PageHeader>
|
|
<ApplyStatusRows v-for="resource in resources" :key="resource.kind" :kind="resource.kind" class="mb-4" />
|
|
|
|
<Alert v-if="catalogError || error" variant="destructive" class="mb-4"><AlertDescription>
|
|
{{ catalogError || error }}
|
|
</AlertDescription></Alert>
|
|
|
|
<KindGate v-if="!form" :kind="KIND" />
|
|
<template v-if="form && tools">
|
|
<Section title="MCP servers">
|
|
<div class="grid gap-3">
|
|
<McpServerEditor
|
|
v-for="(server, i) in shown"
|
|
:key="i"
|
|
:model-value="server"
|
|
@update:model-value="(next: McpServer) => editAt(i, next)"
|
|
@remove="removeAt(i)"
|
|
/>
|
|
<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>
|
|
</div>
|
|
</div>
|
|
</Section>
|
|
|
|
<Section title="MiniMax">
|
|
<template #action>
|
|
<div class="flex items-center gap-3">
|
|
<DraftHint :kind="KIND" path="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>
|
|
<FieldGroup class="@container/field-group">
|
|
<form.Field v-slot="{ field }" name="minimax.api_key_ref">
|
|
<Field orientation="responsive">
|
|
<FieldContent><FieldLabel id="tools-api-key-label">API key</FieldLabel></FieldContent>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1" role="group" aria-labelledby="tools-api-key-label">
|
|
<SecretRefField
|
|
:model-value="field.state.value"
|
|
id-prefix="minimax-key"
|
|
:disabled="!tools.minimax.enabled"
|
|
@update:model-value="field.handleChange"
|
|
/>
|
|
</div>
|
|
</Field>
|
|
</form.Field>
|
|
|
|
<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" />
|
|
<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>
|
|
<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">
|
|
<SettingRow
|
|
:tone="field.state.value ? 'danger' : 'default'"
|
|
label="Allow private networks"
|
|
hint="Host dashboard and Docker API access."
|
|
>
|
|
<div class="flex min-w-0 flex-wrap items-center gap-3">
|
|
<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>
|
|
</SettingRow>
|
|
</form.Field>
|
|
</FieldGroup>
|
|
</Section>
|
|
|
|
<Section title="Tool output">
|
|
<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-caption">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>
|
|
</template>
|