feat(ui): extensions and models pages run on the binary's API (#2063)
This commit is contained in:
10 files changed
+655
-505
No files matched your search
+1
-11
@@ -77,7 +77,7 @@
|
||||
{
|
||||
"path": "/settings/models",
|
||||
"label": "Models",
|
||||
"description": "The models agent loops use, by alias."
|
||||
"description": "Model aliases, their providers and the organisation's policy."
|
||||
},
|
||||
{
|
||||
"path": "/settings/organisations",
|
||||
@@ -197,18 +197,8 @@
|
||||
{
|
||||
"path": "/settings/extensions",
|
||||
"label": "Extensions",
|
||||
"description": "Connectors, guards and MCP servers."
|
||||
},
|
||||
{
|
||||
"path": "/settings/extension-catalogue",
|
||||
"label": "Extension catalogue",
|
||||
"description": "Installed extensions, grants and the marketplace."
|
||||
},
|
||||
{
|
||||
"path": "/settings/model-aliases",
|
||||
"label": "Model aliases",
|
||||
"description": "Model aliases and providers."
|
||||
},
|
||||
{
|
||||
"path": "/settings/plugins",
|
||||
"label": "Plugins",
|
||||
|
||||
+131
-6
@@ -234,6 +234,29 @@ export const api = {
|
||||
workflowStepTypes: () => request<{ name: string; needs_repository: boolean; settings?: unknown }[]>("/api/workflow-step-types"),
|
||||
extensionKinds: () => request<ExtensionKindInfo[]>("/api/extension-kinds"),
|
||||
extensions: (kind: ExtensionKind) => request<Extension[]>(`/api/${kind}`),
|
||||
allExtensions: () => request<Extension[]>("/api/extensions"),
|
||||
removeAnyExtension: (name: string) =>
|
||||
request<{ name: string; state: string }>(`/api/extensions/${encodeURIComponent(name)}`, { method: "DELETE" }),
|
||||
catalogue: () => request<CatalogueEntry[]>("/api/extensions/catalogue"),
|
||||
installCatalogue: (name: string) =>
|
||||
request<ExtensionLifecycle>(`/api/extensions/catalogue/${encodeURIComponent(name)}/install`, { method: "POST", timeoutMs: 120_000 }),
|
||||
acceptGrants: (name: string, body?: ExtensionGrantsInput) =>
|
||||
request<ExtensionLifecycle>(`/api/extensions/${encodeURIComponent(name)}/accept`, { method: "POST", body: body ?? {} }),
|
||||
updateExtension: (name: string) =>
|
||||
request<ExtensionLifecycle>(`/api/extensions/${encodeURIComponent(name)}/update`, { method: "POST", timeoutMs: 120_000 }),
|
||||
approveExtensionUpdate: (name: string) =>
|
||||
request<ExtensionLifecycle>(`/api/extensions/${encodeURIComponent(name)}/approve-update`, { method: "POST" }),
|
||||
rollbackExtension: (name: string) =>
|
||||
request<ExtensionLifecycle>(`/api/extensions/${encodeURIComponent(name)}/rollback`, { method: "POST" }),
|
||||
setExtensionPolicy: (name: string, policy: "manual" | "auto") =>
|
||||
request<ExtensionLifecycle>(`/api/extensions/${encodeURIComponent(name)}/update-policy`, { method: "PUT", body: { policy } }),
|
||||
setExtensionEnabled: (name: string, enabled: boolean) =>
|
||||
request<ExtensionLifecycle>(`/api/extensions/${encodeURIComponent(name)}/enabled`, { method: "PUT", body: { enabled } }),
|
||||
putExtensionSettings: (name: string, settings: Record<string, string>) =>
|
||||
request<ExtensionLifecycle>(`/api/extensions/${encodeURIComponent(name)}/settings`, { method: "PUT", body: { settings }, timeoutMs: 60_000 }),
|
||||
catalogueSource: () => request<CatalogueSourceView>("/api/extensions/catalogue-source"),
|
||||
putCatalogueSource: (source: CatalogueSourceInput) =>
|
||||
request<CatalogueSourceView>("/api/extensions/catalogue-source", { method: "PUT", body: source }),
|
||||
acceptExtension: (kind: ExtensionKind, name: string, body: ExtensionInput) =>
|
||||
request<{ name: string; state: string }>(`/api/${kind}/${encodeURIComponent(name)}`, { method: "PUT", body, timeoutMs: 60_000 }),
|
||||
removeExtension: (kind: ExtensionKind, name: string) =>
|
||||
@@ -245,6 +268,15 @@ export const api = {
|
||||
instructions: () => request<{ text: string }>("/api/settings/instructions"),
|
||||
saveInstructions: (text: string) =>
|
||||
request<{ text: string }>("/api/settings/instructions", { method: "PUT", body: { text } }),
|
||||
modelProviders: () => request<Record<string, ModelProvider>>("/api/settings/model-providers"),
|
||||
putModelProvider: (name: string, provider: ModelProvider) =>
|
||||
request<ModelProvider>(`/api/settings/model-providers/${encodeURIComponent(name)}`, { method: "PUT", body: provider }),
|
||||
deleteModelProvider: (name: string) =>
|
||||
request<void>(`/api/settings/model-providers/${encodeURIComponent(name)}`, { method: "DELETE", parse: false }),
|
||||
modelClasses: () => request<ModelClass[]>("/api/settings/model-classes"),
|
||||
modelPolicy: () => request<ModelPolicy>("/api/settings/model-policy"),
|
||||
putModelPolicy: (policy: ModelPolicy) =>
|
||||
request<ModelPolicy>("/api/settings/model-policy", { method: "PUT", body: policy }),
|
||||
agentModels: () => request<Record<string, AgentModel>>("/api/settings/agent-models"),
|
||||
putAgentModel: (alias: string, model: AgentModel) =>
|
||||
request<AgentModel>("/api/settings/agent-model" + qs({ alias }), { method: "PUT", body: model }),
|
||||
@@ -993,17 +1025,89 @@ export interface Extension {
|
||||
version?: string;
|
||||
contract?: string;
|
||||
group?: ExtensionGroup;
|
||||
egress?: string[];
|
||||
env?: string[];
|
||||
settings?: Record<string, string>;
|
||||
settings_schema?: SettingField[];
|
||||
credentials?: Record<string, string>;
|
||||
egress: string[];
|
||||
env: string[];
|
||||
settings: Record<string, string>;
|
||||
settings_schema: SettingField[];
|
||||
credentials: Record<string, string>;
|
||||
/** An MCP server's declared tools, as it was accepted with them. */
|
||||
tools?: unknown;
|
||||
/** An MCP server's declared privileged effects; absent until declared. */
|
||||
effects?: ServerEffects;
|
||||
/** A connector's declarations; absent until it has loaded. */
|
||||
capabilities?: Capabilities;
|
||||
/** Whether an accepted package runs. */
|
||||
enabled?: boolean;
|
||||
/** Installed from the catalogue rather than accepted by path. */
|
||||
managed?: boolean;
|
||||
display_name?: string;
|
||||
description?: string;
|
||||
declared?: Grants | null;
|
||||
accepted?: Grants | null;
|
||||
pending?: PendingUpdate | null;
|
||||
can_rollback?: boolean;
|
||||
update_policy?: "manual" | "auto";
|
||||
}
|
||||
|
||||
/** What an extension may use: hosts it reaches, host variables it sees and
|
||||
* credential slots it is configured with. */
|
||||
export interface Grants {
|
||||
egress: string[];
|
||||
env: string[];
|
||||
credentials: string[];
|
||||
}
|
||||
|
||||
export interface PendingUpdate {
|
||||
version: string;
|
||||
digest: string;
|
||||
added: Grants;
|
||||
}
|
||||
|
||||
export interface ExtensionLifecycle {
|
||||
name: string;
|
||||
version: string;
|
||||
digest: string;
|
||||
pending: boolean;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
export interface ExtensionGrantsInput {
|
||||
egress?: string[];
|
||||
env?: string[];
|
||||
credentials?: Record<string, string>;
|
||||
settings?: Record<string, string>;
|
||||
}
|
||||
|
||||
/** One extension a signed catalogue offers. */
|
||||
export interface CatalogueEntry {
|
||||
name: string;
|
||||
display_name: string;
|
||||
description: string;
|
||||
contract: string;
|
||||
group: ExtensionGroup;
|
||||
version: string;
|
||||
digest: string;
|
||||
grants: Grants;
|
||||
installed: boolean;
|
||||
installed_version?: string;
|
||||
update_available: boolean;
|
||||
}
|
||||
|
||||
/** Where the catalogue is read from and the key that signs it. */
|
||||
export interface CatalogueSource {
|
||||
location: string;
|
||||
public_key: string;
|
||||
newest?: string;
|
||||
}
|
||||
|
||||
export interface CatalogueSourceView {
|
||||
configured: boolean;
|
||||
source?: CatalogueSource;
|
||||
}
|
||||
|
||||
export interface CatalogueSourceInput {
|
||||
location: string;
|
||||
public_key: string;
|
||||
}
|
||||
|
||||
export interface ServerEffects {
|
||||
@@ -1044,12 +1148,33 @@ export interface CredentialField {
|
||||
}
|
||||
|
||||
export interface AgentModel {
|
||||
class: string;
|
||||
provider: string;
|
||||
model: string;
|
||||
/** Read from the provider, never sent when saving an alias. */
|
||||
class?: string;
|
||||
base_url?: string;
|
||||
api_key_credential?: string;
|
||||
}
|
||||
|
||||
/** An endpoint models are called on. */
|
||||
export interface ModelProvider {
|
||||
name: string;
|
||||
class: string;
|
||||
base_url?: string;
|
||||
api_key_credential?: string;
|
||||
}
|
||||
|
||||
export interface ModelClass {
|
||||
class: string;
|
||||
default_base_url?: string;
|
||||
}
|
||||
|
||||
/** Which aliases workflows and chat may use; null lets them use any. */
|
||||
export interface ModelPolicy {
|
||||
workflow_aliases: string[] | null;
|
||||
chat_aliases: string[] | null;
|
||||
}
|
||||
|
||||
export type PolicyKind = "hard-rules" | "change-request";
|
||||
|
||||
export interface PolicyText {
|
||||
|
||||
@@ -63,7 +63,6 @@ const settings: NavSpec = {
|
||||
label: "Models & prompts",
|
||||
paths: [
|
||||
"/settings/models",
|
||||
"/settings/model-aliases",
|
||||
"/settings/skills",
|
||||
"/settings/curators",
|
||||
"/settings/memory",
|
||||
@@ -75,7 +74,6 @@ const settings: NavSpec = {
|
||||
"/settings/channels",
|
||||
"/settings/tools",
|
||||
"/settings/extensions",
|
||||
"/settings/extension-catalogue",
|
||||
"/settings/plugins",
|
||||
"/settings/secret-engines",
|
||||
"/settings/credentials",
|
||||
|
||||
+6
-18
@@ -218,13 +218,13 @@ export const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: "/settings/models",
|
||||
name: "system-models",
|
||||
component: () => import("@/settings/AgentModelsPage.vue"),
|
||||
component: () => import("@/settings/SystemModelsPage.vue"),
|
||||
meta: {
|
||||
navPath: "/settings",
|
||||
settings: true,
|
||||
label: "Models",
|
||||
description: "The models agent loops use, by alias.",
|
||||
section: "models",
|
||||
description: "Model aliases, their providers and the organisation's policy.",
|
||||
section: "model_aliases",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -426,27 +426,15 @@ export const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: "/settings/extensions",
|
||||
name: "settings-extensions",
|
||||
component: () => import("@/settings/AcceptedExtensionsPage.vue"),
|
||||
component: ExtensionsPage,
|
||||
meta: {
|
||||
navPath: "/settings",
|
||||
settings: true,
|
||||
label: "Extensions",
|
||||
description: "Connectors, guards and MCP servers.",
|
||||
section: "extensions",
|
||||
description: "Installed extensions, grants and the marketplace.",
|
||||
section: "extension_catalogue",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/settings/extension-catalogue",
|
||||
name: "settings-extension-catalogue",
|
||||
component: ExtensionsPage,
|
||||
meta: { navPath: "/settings", settings: true, label: "Extension catalogue", description: "Installed extensions, grants and the marketplace.", section: "extension_catalogue" },
|
||||
},
|
||||
{
|
||||
path: "/settings/model-aliases",
|
||||
name: "settings-model-aliases",
|
||||
component: () => import("@/settings/SystemModelsPage.vue"),
|
||||
meta: { navPath: "/settings", settings: true, label: "Model aliases", description: "Model aliases and providers.", section: "model_aliases" },
|
||||
},
|
||||
{
|
||||
path: "/settings/plugins",
|
||||
name: "settings-plugins",
|
||||
|
||||
@@ -64,7 +64,7 @@ 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),
|
||||
extensions.extensions.filter((e) => e.capabilities?.deliveries?.length && e.settings_schema?.length),
|
||||
);
|
||||
|
||||
const statuses = ref<ChannelStatus[]>([]);
|
||||
|
||||
@@ -170,7 +170,7 @@ async function remove(): Promise<void> {
|
||||
<template #cell-egress="{ row }"><span class="font-mono text-caption">{{ (row.egress ?? []).join(", ") }}</span></template>
|
||||
<template #actions="{ row }">
|
||||
<MoreMenu :label="`${row.name} actions`">
|
||||
<DropdownMenuItem @select="open(row)">Edit</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="!row.managed" @select="open(row)">Edit</DropdownMenuItem>
|
||||
<DropdownMenuItem class="text-danger" @select="removing = row">Remove</DropdownMenuItem>
|
||||
</MoreMenu>
|
||||
</template>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, type Component } from "vue";
|
||||
import { BookOpen, GitPullRequest, KeyRound, MessageSquare, Package, Plus, Search, UserCog, Workflow, Zap } from "@lucide/vue";
|
||||
import { Package, Plus, Search, Workflow, Zap } from "@lucide/vue";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -10,36 +10,32 @@ import { Item, ItemActions, ItemContent, ItemDescription, ItemMedia, ItemTitle }
|
||||
import { useExtensionsStore, type CatalogueEntry } from "@/stores/extensions";
|
||||
|
||||
/**
|
||||
* The catalogue, grouped by what each package extends. Installed packages stay
|
||||
* listed so the catalogue reads whole; they offer an update when one exists.
|
||||
* The catalogue, grouped by the group each extension belongs to. Installed
|
||||
* packages stay listed so the catalogue reads whole; they offer an update when
|
||||
* one exists.
|
||||
*/
|
||||
const props = defineProps<{ updates: Map<string, CatalogueEntry> }>();
|
||||
const store = useExtensionsStore();
|
||||
|
||||
// Surfaces in the order an operator sets archie up: where work comes from and
|
||||
// goes, then credentials, then what agents do.
|
||||
const SURFACES: { id: string; label: string; icon: Component }[] = [
|
||||
{ id: "forge", label: "Forges", icon: GitPullRequest },
|
||||
{ id: "channels", label: "Channels", icon: MessageSquare },
|
||||
{ id: "secret-engines", label: "Secret engines", icon: KeyRound },
|
||||
{ id: "workflows", label: "Workflows", icon: Workflow },
|
||||
{ id: "playbooks", label: "Playbooks", icon: Zap },
|
||||
{ id: "skills", label: "Skills", icon: BookOpen },
|
||||
{ id: "profiles", label: "Agent profiles", icon: UserCog },
|
||||
// The server names each extension's group; these are its icons.
|
||||
const GROUPS: { id: string; label: string; icon: Component }[] = [
|
||||
{ id: "platform", label: "Platform", icon: Package },
|
||||
{ id: "integration", label: "Integrations", icon: Zap },
|
||||
{ id: "agent", label: "Agent", icon: Workflow },
|
||||
];
|
||||
|
||||
const query = ref("");
|
||||
const groups = computed(() => {
|
||||
const q = query.value.trim().toLowerCase();
|
||||
const matching = store.catalogue.filter(
|
||||
(entry) => !q || entry.name.toLowerCase().includes(q) || entry.description.toLowerCase().includes(q),
|
||||
(entry) => !q || entry.name.toLowerCase().includes(q) || entry.display_name.toLowerCase().includes(q) || entry.description.toLowerCase().includes(q),
|
||||
);
|
||||
const known = new Set(SURFACES.map((s) => s.id));
|
||||
const known = new Set(GROUPS.map((group) => group.id));
|
||||
const other = { id: "other", label: "Other", icon: Package };
|
||||
return [...SURFACES, other]
|
||||
.map((surface) => ({
|
||||
...surface,
|
||||
entries: matching.filter((e) => (surface.id === "other" ? !known.has(e.surface) : e.surface === surface.id)),
|
||||
return [...GROUPS, other]
|
||||
.map((group) => ({
|
||||
...group,
|
||||
entries: matching.filter((entry) => (group.id === "other" ? !known.has(entry.group) : entry.group === group.id)),
|
||||
}))
|
||||
.filter((group) => group.entries.length > 0);
|
||||
});
|
||||
@@ -52,8 +48,8 @@ const groups = computed(() => {
|
||||
<InputGroupInput v-model="query" type="search" placeholder="Search extensions" aria-label="Search extensions" />
|
||||
</InputGroup>
|
||||
|
||||
<section v-for="group in groups" :key="group.id" :aria-labelledby="`surface-${group.id}`">
|
||||
<h2 :id="`surface-${group.id}`" class="mb-2 flex items-center gap-2 text-label font-semibold">
|
||||
<section v-for="group in groups" :key="group.id" :aria-labelledby="`group-${group.id}`">
|
||||
<h2 :id="`group-${group.id}`" class="mb-2 flex items-center gap-2 text-label font-semibold">
|
||||
<component :is="group.icon" class="size-4 text-fg-subtle" aria-hidden="true" />
|
||||
{{ group.label }}
|
||||
<span class="font-normal text-fg-subtle">{{ group.entries.length }}</span>
|
||||
@@ -66,7 +62,7 @@ const groups = computed(() => {
|
||||
</ItemMedia>
|
||||
<ItemContent class="min-w-0">
|
||||
<ItemTitle>
|
||||
{{ entry.name }}
|
||||
{{ entry.display_name || entry.name }}
|
||||
<span class="font-mono text-caption font-normal text-fg-subtle">{{ entry.version }}</span>
|
||||
</ItemTitle>
|
||||
<ItemDescription class="text-caption" :title="entry.description">{{ entry.description }}</ItemDescription>
|
||||
|
||||
@@ -3,8 +3,8 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Item, ItemGroup } from "@/components/ui/item";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { ChevronRight, Plus, Trash2 } from "@lucide/vue";
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { ChevronRight, Plus, Settings2, Trash2 } from "@lucide/vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import {
|
||||
@@ -20,17 +20,23 @@ import {
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { grants, stage, useExtensionsStore, type Extension } from "@/stores/extensions";
|
||||
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { grants, stage, useExtensionsStore } from "@/stores/extensions";
|
||||
import { api, type Extension, type SettingField } from "@/lib/api";
|
||||
import { useRead } from "@/lib/use-read";
|
||||
import { fromLines, toLines } from "@/lib/lines";
|
||||
import ExtensionList from "./ExtensionList.vue";
|
||||
import ExtensionsMarketplace from "./ExtensionsMarketplace.vue";
|
||||
|
||||
const KIND = "extension-settings";
|
||||
const store = useExtensionsStore();
|
||||
const loading = ref(true);
|
||||
onMounted(async () => {
|
||||
@@ -40,32 +46,73 @@ onMounted(async () => {
|
||||
|
||||
// The catalogue entry an installed package would move to on Update, when the
|
||||
// catalogue pins a different digest than the one installed.
|
||||
const updates = computed(() => {
|
||||
const byName = new Map(store.catalogue.map((entry) => [entry.name, entry]));
|
||||
return new Map(
|
||||
store.extensions.flatMap((extension) => {
|
||||
const entry = byName.get(extension.name);
|
||||
return entry && entry.digest !== extension.digest ? [[extension.name, entry] as const] : [];
|
||||
}),
|
||||
);
|
||||
});
|
||||
const updates = computed(() => new Map(store.catalogue.filter((entry) => entry.update_available).map((entry) => [entry.name, entry])));
|
||||
|
||||
const name = ref("");
|
||||
const reference = ref("");
|
||||
const digest = ref("");
|
||||
async function install(): Promise<void> {
|
||||
if (await store.install(name.value, reference.value, digest.value)) {
|
||||
name.value = reference.value = digest.value = "";
|
||||
const sourceLocation = ref("");
|
||||
const sourceKey = ref("");
|
||||
watch(
|
||||
() => store.source,
|
||||
(view) => {
|
||||
sourceLocation.value = view.source?.location ?? "";
|
||||
sourceKey.value = view.source?.public_key ?? "";
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
async function saveSource(): Promise<void> {
|
||||
if (await store.saveSource(sourceLocation.value.trim(), sourceKey.value.trim())) {
|
||||
sourceLocation.value = store.source.source?.location ?? "";
|
||||
sourceKey.value = store.source.source?.public_key ?? "";
|
||||
}
|
||||
}
|
||||
|
||||
// The dialog's action closes it before its click handler runs, so the
|
||||
// target outlives the open flag rather than being cleared on close.
|
||||
// Credentials a declared slot may resolve through.
|
||||
const credentials = useRead(() => api.credentials());
|
||||
onMounted(credentials.reload);
|
||||
const credentialNames = computed(() => (credentials.data.value ?? []).map((c) => c.name));
|
||||
|
||||
// The dialog's action closes it before its click handler runs, so the target
|
||||
// outlives the open flag rather than being cleared on close.
|
||||
const accepting = ref<Extension | null>(null);
|
||||
const acceptOpen = ref(false);
|
||||
async function accept(): Promise<void> {
|
||||
if (accepting.value) await store.accept(accepting.value.name);
|
||||
const acceptKeys = ref<Record<string, string>>({});
|
||||
function openAccept(extension: Extension): void {
|
||||
accepting.value = extension;
|
||||
acceptKeys.value = {};
|
||||
acceptOpen.value = true;
|
||||
}
|
||||
async function accept(): Promise<void> {
|
||||
const extension = accepting.value;
|
||||
if (!extension) return;
|
||||
const declared = extension.declared;
|
||||
await store.accept(extension.name, {
|
||||
egress: declared?.egress ?? [],
|
||||
env: declared?.env ?? [],
|
||||
credentials: acceptKeys.value,
|
||||
});
|
||||
}
|
||||
|
||||
const editing = ref<Extension | null>(null);
|
||||
const settingsOpen = ref(false);
|
||||
const schema = ref<SettingField[]>([]);
|
||||
const values = ref<Record<string, string>>({});
|
||||
const other = ref("");
|
||||
function openSettings(extension: Extension): void {
|
||||
editing.value = extension;
|
||||
schema.value = extension.settings_schema ?? [];
|
||||
const known = new Set(schema.value.map((field) => field.key));
|
||||
values.value = Object.fromEntries(Object.entries(extension.settings ?? {}).filter(([key]) => known.has(key)));
|
||||
other.value = toLines(Object.fromEntries(Object.entries(extension.settings ?? {}).filter(([key]) => !known.has(key))));
|
||||
settingsOpen.value = true;
|
||||
}
|
||||
async function saveSettings(): Promise<void> {
|
||||
if (!editing.value) return;
|
||||
const settings = {
|
||||
...fromLines(other.value),
|
||||
...Object.fromEntries(Object.entries(values.value).filter(([, value]) => value !== "")),
|
||||
};
|
||||
if (await store.saveSettings(editing.value.name, settings)) settingsOpen.value = false;
|
||||
}
|
||||
|
||||
const removing = ref<Extension | null>(null);
|
||||
const removeOpen = ref(false);
|
||||
async function remove(): Promise<void> {
|
||||
@@ -76,8 +123,22 @@ const tones = {
|
||||
accept: { tone: "warn", label: "Authority not accepted" },
|
||||
disabled: { tone: "idle", label: "Disabled" },
|
||||
enabled: { tone: undefined, label: "" },
|
||||
inert: { tone: "idle", label: "No extensions" },
|
||||
} as const;
|
||||
|
||||
// Path-accepted packages keep their editor: one tab lists each kind.
|
||||
const kinds = useRead(() => api.extensionKinds());
|
||||
onMounted(kinds.reload);
|
||||
const pathGroups = computed(() => {
|
||||
const byGroup = new Map<string, { id: string; label: string; kinds: { kind: string; label: string; singular: string }[] }>();
|
||||
for (const kind of kinds.data.value ?? []) {
|
||||
const group = byGroup.get(kind.group) ?? { id: kind.group, label: kind.group[0]!.toUpperCase() + kind.group.slice(1), kinds: [] };
|
||||
group.kinds.push(kind);
|
||||
byGroup.set(kind.group, group);
|
||||
}
|
||||
return [...byGroup.values()];
|
||||
});
|
||||
const activeKind = ref("");
|
||||
const active = computed(() => (kinds.data.value ?? []).find((kind) => kind.kind === activeKind.value) ?? kinds.data.value?.[0]);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -90,6 +151,7 @@ const tones = {
|
||||
<TabsList>
|
||||
<TabsTrigger value="installed">Installed</TabsTrigger>
|
||||
<TabsTrigger value="marketplace">Marketplace</TabsTrigger>
|
||||
<TabsTrigger value="path">By path</TabsTrigger>
|
||||
</TabsList>
|
||||
<TabsContent value="installed">
|
||||
<Section>
|
||||
@@ -100,8 +162,21 @@ const tones = {
|
||||
{{ extension.display_name || extension.name }}
|
||||
<span class="font-mono text-caption text-fg-subtle">{{ extension.version }}</span>
|
||||
</p>
|
||||
<p class="text-caption text-fg-subtle">{{ extension.description }}</p>
|
||||
<p v-if="extension.description" class="text-caption text-fg-subtle">{{ extension.description }}</p>
|
||||
<p class="truncate font-mono text-caption text-fg-subtle">{{ extension.digest }}</p>
|
||||
<Collapsible v-if="extension.declared">
|
||||
<CollapsibleTrigger as-child>
|
||||
<Button variant="ghost" size="sm" class="-ml-2 h-6 px-2 text-caption font-normal text-fg-subtle">
|
||||
<ChevronRight class="transition-transform group-data-[state=open]/button:rotate-90" />
|
||||
Declared authority
|
||||
</Button>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent>
|
||||
<ul class="font-mono text-caption text-fg-subtle">
|
||||
<li v-for="line in grants(extension.declared)" :key="line">{{ line }}</li>
|
||||
</ul>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
<Collapsible v-if="extension.accepted">
|
||||
<CollapsibleTrigger as-child>
|
||||
<Button variant="ghost" size="sm" class="-ml-2 h-6 px-2 text-caption font-normal text-fg-subtle">
|
||||
@@ -120,7 +195,7 @@ const tones = {
|
||||
<Card v-if="extension.pending" size="sm" class="w-full">
|
||||
<p class="text-caption font-medium">Update awaiting approval. It adds:</p>
|
||||
<ul class="font-mono text-caption">
|
||||
<li v-for="line in grants(extension.pending.added).filter((l) => !l.startsWith('network:'))" :key="line">{{ line }}</li>
|
||||
<li v-for="line in grants(extension.pending.added).filter((line) => !line.startsWith('network:'))" :key="line">{{ line }}</li>
|
||||
</ul>
|
||||
<Button size="sm" class="mt-2" :disabled="!!store.busy" @click="store.approveUpdate(extension.name)">Approve</Button>
|
||||
</Card>
|
||||
@@ -133,6 +208,7 @@ const tones = {
|
||||
>Update to {{ updates.get(extension.name)?.version }}</Button
|
||||
>
|
||||
<Switch
|
||||
v-if="extension.managed"
|
||||
:model-value="extension.update_policy === 'auto'"
|
||||
:disabled="!!store.busy"
|
||||
:aria-label="`Auto-update ${extension.name}`"
|
||||
@@ -146,16 +222,24 @@ const tones = {
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
:disabled="!!store.busy"
|
||||
@click="(accepting = extension), (acceptOpen = true)"
|
||||
@click="openAccept(extension)"
|
||||
>Review authority</Button
|
||||
>
|
||||
<Switch
|
||||
v-else-if="stage(extension) !== 'inert'"
|
||||
:model-value="extension.enabled"
|
||||
v-else-if="extension.managed"
|
||||
:model-value="!!extension.enabled"
|
||||
:disabled="!!store.busy"
|
||||
:aria-label="`Enable ${extension.name}`"
|
||||
@update:model-value="(value: boolean) => store.setEnabled(extension.name, value)"
|
||||
/>
|
||||
<Tooltip v-if="extension.managed">
|
||||
<TooltipTrigger as-child>
|
||||
<Button variant="ghost" size="icon" :aria-label="`Settings for ${extension.name}`" :disabled="!!store.busy" @click="openSettings(extension)"
|
||||
><Settings2
|
||||
/></Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Settings</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button
|
||||
@@ -180,21 +264,38 @@ const tones = {
|
||||
</li>
|
||||
</ItemGroup>
|
||||
</Section>
|
||||
|
||||
<ApplyStatusRows :kind="KIND" class="mt-6 border-t border-border py-4" />
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="marketplace">
|
||||
<ReadError v-if="store.catalogueError" :message="store.catalogueError" retry-label="Retry" @retry="store.load()" />
|
||||
<ExtensionsMarketplace v-else :updates="updates" />
|
||||
<Collapsible class="mt-3">
|
||||
<CollapsibleTrigger class="cursor-pointer text-caption text-fg-muted">Install by reference</CollapsibleTrigger>
|
||||
<CollapsibleContent><form class="mt-2 flex flex-wrap gap-2" @submit.prevent="install">
|
||||
<Input v-model="name" class="max-w-40" placeholder="Name" aria-label="Name" required />
|
||||
<Input v-model="reference" class="max-w-80 font-mono" placeholder="registry/repo:tag" aria-label="Reference" required />
|
||||
<Input v-model="digest" class="max-w-96 font-mono" placeholder="sha256:…" aria-label="Digest" required />
|
||||
<Button type="submit" size="sm" :disabled="!!store.busy"><Plus data-icon="inline-start" />Install</Button>
|
||||
</form></CollapsibleContent>
|
||||
</Collapsible>
|
||||
<Collapsible class="mb-3" default-open>
|
||||
<CollapsibleTrigger class="cursor-pointer text-caption text-fg-muted">Catalogue source</CollapsibleTrigger>
|
||||
<CollapsibleContent>
|
||||
<form class="mt-2 flex flex-wrap items-end gap-2" @submit.prevent="saveSource">
|
||||
<Input v-model="sourceLocation" class="max-w-96 font-mono" placeholder="https://… or /path/to/catalogue.json" aria-label="Catalogue location" />
|
||||
<Input v-model="sourceKey" class="max-w-96 font-mono" placeholder="base64 Ed25519 public key" aria-label="Catalogue public key" />
|
||||
<Button type="submit" size="sm" :disabled="!!store.busy"><Plus data-icon="inline-start" />Save</Button>
|
||||
</form>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
<ReadError v-if="store.catalogueError" :message="store.catalogueError" retry-label="Retry" @retry="store.load()" />
|
||||
<ExtensionsMarketplace v-else :updates="updates" />
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="path">
|
||||
<ReadError v-if="kinds.error.value" :message="kinds.error.value" retry-label="Retry" @retry="kinds.reload" />
|
||||
<template v-else-if="active">
|
||||
<Tabs :model-value="active.kind" class="mb-4" @update:model-value="(value) => (activeKind = String(value))">
|
||||
<div class="flex flex-wrap gap-x-6 gap-y-3">
|
||||
<div v-for="group in pathGroups" :key="group.id">
|
||||
<h2 class="mb-1 text-caption text-fg-subtle">{{ group.label }}</h2>
|
||||
<TabsList variant="line" class="justify-start">
|
||||
<TabsTrigger v-for="kind in group.kinds" :key="kind.kind" :value="kind.kind" class="flex-none px-3">{{ kind.label }}</TabsTrigger>
|
||||
</TabsList>
|
||||
</div>
|
||||
</div>
|
||||
</Tabs>
|
||||
<ExtensionList :key="active.kind" :kind="active.kind" :noun="active.singular" />
|
||||
</template>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
|
||||
@@ -205,8 +306,17 @@ const tones = {
|
||||
<AlertDialogDescription>It runs as a process on this host and sees only these.</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<ul class="font-mono text-caption">
|
||||
<li v-for="line in accepting ? grants(accepting.declared) : []" :key="line">{{ line }}</li>
|
||||
<li v-for="line in grants(accepting?.declared)" :key="line">{{ line }}</li>
|
||||
</ul>
|
||||
<div v-for="slot in accepting?.declared?.credentials ?? []" :key="slot" class="flex items-center gap-3">
|
||||
<span class="w-40 truncate font-mono text-caption">{{ slot }}</span>
|
||||
<Select :model-value="acceptKeys[slot]" @update:model-value="(value) => (acceptKeys = { ...acceptKeys, [slot]: String(value) })">
|
||||
<SelectTrigger class="w-56" :aria-label="`Credential for ${slot}`"><SelectValue placeholder="no credential" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="name in credentialNames" :key="name" :value="name">{{ name }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction @click="accept">Accept</AlertDialogAction>
|
||||
@@ -214,11 +324,30 @@ const tones = {
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
<Dialog v-model:open="settingsOpen">
|
||||
<DialogContent class="max-h-[90dvh] overflow-y-auto sm:max-w-2xl">
|
||||
<DialogHeader><DialogTitle>Settings for {{ editing?.name }}</DialogTitle></DialogHeader>
|
||||
<form id="extension-settings" @submit.prevent="saveSettings">
|
||||
<SettingRow v-for="field in schema" :key="field.key" :label="field.label || field.key" :for="`ext-set-${field.key}`" :hint="field.description">
|
||||
<Select v-if="field.options?.length" v-model="values[field.key]">
|
||||
<SelectTrigger :id="`ext-set-${field.key}`" class="w-full"><SelectValue /></SelectTrigger>
|
||||
<SelectContent><SelectItem v-for="option in field.options" :key="option" :value="option">{{ option }}</SelectItem></SelectContent>
|
||||
</Select>
|
||||
<Input v-else :id="`ext-set-${field.key}`" v-model="values[field.key]" :required="field.required" :placeholder="field.secret ? 'engine:key' : undefined" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Other settings" for="ext-settings" hint="key=value, one per line. A key ending in _ref takes engine:key.">
|
||||
<Textarea id="ext-settings" v-model="other" class="font-mono" rows="3" />
|
||||
</SettingRow>
|
||||
</form>
|
||||
<DialogFooter><Button type="submit" form="extension-settings" :disabled="!!store.busy">Save and restart</Button></DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
<AlertDialog v-model:open="removeOpen">
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Remove {{ removing?.name }}?</AlertDialogTitle>
|
||||
<AlertDialogDescription>Its process stops on the next sync.</AlertDialogDescription>
|
||||
<AlertDialogDescription>Its process stops.</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
|
||||
@@ -1,325 +1,306 @@
|
||||
<script setup lang="ts">
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
||||
import KindGate from "./KindGate.vue";
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { Plus, Trash2 } from "@lucide/vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { SuggestInput } from "@/components/ui/suggest-input";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { useOrgStore } from "@/stores/org";
|
||||
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
|
||||
import DraftHint from "./DraftHint.vue";
|
||||
import HistoryLink from "./HistoryLink.vue";
|
||||
import { availableProviders, aliasModelOptions } from "./model-choices";
|
||||
import SecretRefField from "./SecretRefField.vue";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { api, describeError, type AgentModel, type ModelProvider } from "@/lib/api";
|
||||
import { useRead } from "@/lib/use-read";
|
||||
import { errors } from "@/copy/errors";
|
||||
|
||||
interface Provider {
|
||||
class: string;
|
||||
api_key_env?: string;
|
||||
api_key_ref: { engine: string; key: string };
|
||||
base_url?: string;
|
||||
const providers = useRead(() => api.modelProviders());
|
||||
const models = useRead(() => api.agentModels());
|
||||
const classes = useRead(() => api.modelClasses());
|
||||
const credentials = useRead(() => api.credentials());
|
||||
const policy = useRead(() => api.modelPolicy());
|
||||
onMounted(() => {
|
||||
void providers.reload();
|
||||
void models.reload();
|
||||
void classes.reload();
|
||||
void credentials.reload();
|
||||
void policy.reload();
|
||||
});
|
||||
|
||||
const NONE = "__none__";
|
||||
const providerMap = computed(() => providers.data.value ?? {});
|
||||
const providerNames = computed(() => Object.keys(providerMap.value).sort());
|
||||
const classList = computed(() => classes.data.value ?? []);
|
||||
const classNames = computed(() => classList.value.map((entry) => entry.class));
|
||||
const credentialNames = computed(() => (credentials.data.value ?? []).map((entry) => entry.name));
|
||||
const modelMap = computed(() => models.data.value ?? {});
|
||||
const hasModels = computed(() => models.data.value !== undefined);
|
||||
const hasProviders = computed(() => providers.data.value !== undefined);
|
||||
const policyData = computed(() => policy.data.value);
|
||||
const errorOf = (...reads: { error: { value: string } }[]) => reads.map((read) => read.error.value).find(Boolean) ?? "";
|
||||
|
||||
const error = ref("");
|
||||
async function run(act: () => Promise<void>): Promise<boolean> {
|
||||
error.value = "";
|
||||
try {
|
||||
await act();
|
||||
return true;
|
||||
} catch (cause) {
|
||||
error.value = describeError(cause, errors.common.unknown);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// default runs agent steps and chat when none is named; embedding and
|
||||
// transcription serve their own purposes. Others are named by steps and chat.
|
||||
const KNOWN_ALIASES = ["default", "embedding", "transcription"];
|
||||
// Provider classes come from the server's model catalog (the classes the
|
||||
// runtime SDK found usable), not a local list.
|
||||
|
||||
const store = useSettingsStore();
|
||||
const orgStore = useOrgStore();
|
||||
const { catalog: resourceCatalog, catalogError } = storeToRefs(store);
|
||||
onMounted(() => Promise.all([store.load(), store.loadConfig(), orgStore.loadOrg()]));
|
||||
|
||||
// Map keys are free text, so entries are read from the draft and written whole
|
||||
// through setDraftEntry; a key is never a form field path.
|
||||
const resources = computed(() => resourcesForPage(resourceCatalog.value, "models"));
|
||||
const providers = computed(() => store.draftValue("provider-settings") as Record<string, Provider> | undefined);
|
||||
const aliases = computed(() => store.draftValue("model-aliases") as Record<string, string> | undefined);
|
||||
const errors = computed(() =>
|
||||
["provider-settings", "model-aliases"].map((k) => store.pageErrorFor(k)).filter(Boolean),
|
||||
);
|
||||
|
||||
const providerEntries = computed(() => Object.entries(providers.value ?? {}));
|
||||
const configuredIds = computed(() => providerEntries.value.map(([id]) => id));
|
||||
|
||||
const modelCatalog = computed(() => store.config?.catalog ?? []);
|
||||
const catalogClasses = computed(() => [...new Set(modelCatalog.value.map((p) => p.class).filter(Boolean))]);
|
||||
const modelOptions = computed(() => aliasModelOptions(modelCatalog.value, configuredIds.value));
|
||||
const available = computed(() => availableProviders(modelCatalog.value, configuredIds.value));
|
||||
|
||||
const aliasNames = computed(() => [
|
||||
...KNOWN_ALIASES,
|
||||
...Object.keys(aliases.value ?? {}).filter((a) => !KNOWN_ALIASES.includes(a)),
|
||||
]);
|
||||
// An unset alias is an absent key: the server refuses an empty model.
|
||||
function setAlias(alias: string, model: string) {
|
||||
store.setDraftEntry("model-aliases", alias, model.trim() || undefined);
|
||||
// Aliases: which provider and model each name resolves to.
|
||||
interface AliasForm {
|
||||
provider: string;
|
||||
model: string;
|
||||
}
|
||||
function removeAlias(alias: string) {
|
||||
store.setDraftEntry("model-aliases", alias, undefined);
|
||||
const aliasEdits = ref<Record<string, AliasForm>>({});
|
||||
const addedAliases = ref<string[]>([]);
|
||||
const formOf = (model?: AgentModel): AliasForm => ({ provider: model?.provider ?? "", model: model?.model ?? "" });
|
||||
watch(models.data, (rows) => {
|
||||
const next: Record<string, AliasForm> = {};
|
||||
for (const [alias, model] of Object.entries(rows ?? {})) next[alias] = aliasEdits.value[alias] ?? formOf(model);
|
||||
for (const alias of ["default", ...addedAliases.value]) next[alias] ??= aliasEdits.value[alias] ?? formOf();
|
||||
aliasEdits.value = next;
|
||||
});
|
||||
const aliases = computed(() => [...new Set(["default", ...Object.keys(models.data.value ?? {}), ...addedAliases.value])]);
|
||||
const aliasField = (alias: string): AliasForm => (aliasEdits.value[alias] ??= formOf());
|
||||
const aliasBusy = ref("");
|
||||
const aliasError = ref<Record<string, string>>({});
|
||||
const tested = ref<Record<string, string>>({});
|
||||
async function aliasRun(alias: string, act: () => Promise<void>): Promise<void> {
|
||||
aliasBusy.value = alias;
|
||||
aliasError.value = { ...aliasError.value, [alias]: "" };
|
||||
try {
|
||||
await act();
|
||||
} catch (cause) {
|
||||
aliasError.value = { ...aliasError.value, [alias]: describeError(cause, errors.common.unknown) };
|
||||
} finally {
|
||||
aliasBusy.value = "";
|
||||
}
|
||||
}
|
||||
// Embedding runs through the SDK's embed package, which only these classes
|
||||
// implement (internal/infrastructure/embedding).
|
||||
const EMBED_CLASSES = ["openai", "openai-compatible", "gemini", "ollama", "cohere", "mistral"];
|
||||
const embeddingProviders = computed(() =>
|
||||
providerEntries.value.filter(([, p]) => EMBED_CLASSES.includes(p.class)).map(([id]) => id),
|
||||
);
|
||||
// The provider is held locally until a model is typed: the alias itself is
|
||||
// only stored once both halves exist.
|
||||
const embeddingProvider = ref("");
|
||||
const embeddingModel = ref("");
|
||||
watch(
|
||||
() => aliases.value?.embedding,
|
||||
(value) => {
|
||||
if (!value) return;
|
||||
embeddingProvider.value = value.split("/")[0] ?? "";
|
||||
embeddingModel.value = value.split("/").slice(1).join("/");
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
function setEmbedding(provider: string, model: string) {
|
||||
embeddingProvider.value = provider;
|
||||
embeddingModel.value = model;
|
||||
setAlias("embedding", provider && model ? `${provider}/${model}` : "");
|
||||
}
|
||||
const providerKnown = (model: string) => configuredIds.value.includes(model.split("/")[0]!);
|
||||
const aliasIssues = computed(() => store.issuesFor("model-aliases"));
|
||||
const aliasIssue = (alias: string) => aliasIssues.value.find((entry) => entry.path === alias);
|
||||
|
||||
const saveAlias = (alias: string) =>
|
||||
aliasRun(alias, async () => {
|
||||
const field = aliasField(alias);
|
||||
await api.putAgentModel(alias === "default" ? "" : alias, { provider: field.provider, model: field.model });
|
||||
addedAliases.value = addedAliases.value.filter((name) => name !== alias);
|
||||
await models.reload();
|
||||
});
|
||||
const testAlias = (alias: string) =>
|
||||
aliasRun(alias, async () => {
|
||||
const field = aliasField(alias);
|
||||
const answer = await api.testAgentModel({ provider: field.provider, model: field.model });
|
||||
tested.value = { ...tested.value, [alias]: `${answer.model} answered “${answer.answer.trim()}”` };
|
||||
});
|
||||
const removeAlias = (alias: string) =>
|
||||
aliasRun(alias, async () => {
|
||||
if (models.data.value?.[alias]) await api.deleteAgentModel(alias === "default" ? "" : alias);
|
||||
addedAliases.value = addedAliases.value.filter((name) => name !== alias);
|
||||
delete aliasEdits.value[alias];
|
||||
await models.reload();
|
||||
});
|
||||
const newAlias = ref("");
|
||||
function addAlias() {
|
||||
function addAlias(): void {
|
||||
const name = newAlias.value.trim();
|
||||
if (!aliases.value || !name || aliasNames.value.includes(name)) return;
|
||||
store.setDraftEntry("model-aliases", name, modelOptions.value[0] ?? "");
|
||||
if (!name || aliases.value.includes(name)) return;
|
||||
addedAliases.value = [...addedAliases.value, name];
|
||||
aliasEdits.value = { ...aliasEdits.value, [name]: formOf() };
|
||||
newAlias.value = "";
|
||||
}
|
||||
|
||||
// Adding a provider the catalog found usable carries its class, key variable
|
||||
// and endpoint; any other name starts blank.
|
||||
// Providers: the endpoints aliases call.
|
||||
interface ProviderForm {
|
||||
class: string;
|
||||
base_url: string;
|
||||
key: string;
|
||||
}
|
||||
const providerEdits = ref<Record<string, ProviderForm>>({});
|
||||
const providerForm = (provider?: ModelProvider): ProviderForm => ({
|
||||
class: provider?.class ?? classNames.value[0] ?? "",
|
||||
base_url: provider?.base_url ?? "",
|
||||
key: provider?.api_key_credential || NONE,
|
||||
});
|
||||
watch(providers.data, (rows) => {
|
||||
for (const [name, provider] of Object.entries(rows ?? {})) providerEdits.value[name] ??= providerForm(provider);
|
||||
});
|
||||
const providerField = (name: string): ProviderForm => (providerEdits.value[name] ??= providerForm());
|
||||
const providerBusy = ref("");
|
||||
const saveProvider = async (name: string): Promise<void> => {
|
||||
providerBusy.value = name;
|
||||
try {
|
||||
const field = providerField(name);
|
||||
await run(async () => {
|
||||
await api.putModelProvider(name, {
|
||||
name,
|
||||
class: field.class,
|
||||
base_url: field.base_url.trim() || undefined,
|
||||
api_key_credential: field.key === NONE ? undefined : field.key,
|
||||
});
|
||||
await providers.reload();
|
||||
});
|
||||
} finally {
|
||||
providerBusy.value = "";
|
||||
}
|
||||
};
|
||||
const removeProvider = async (name: string): Promise<void> => {
|
||||
providerBusy.value = name;
|
||||
try {
|
||||
await run(async () => {
|
||||
await api.deleteModelProvider(name);
|
||||
delete providerEdits.value[name];
|
||||
await providers.reload();
|
||||
});
|
||||
} finally {
|
||||
providerBusy.value = "";
|
||||
}
|
||||
};
|
||||
const newProvider = ref("");
|
||||
function addProvider() {
|
||||
const id = newProvider.value.trim();
|
||||
if (!providers.value || !id || providers.value[id]) return;
|
||||
const found = modelCatalog.value.find((p) => p.id === id);
|
||||
store.setDraftEntry("provider-settings", id, {
|
||||
class: found?.class || (catalogClasses.value.includes(id) ? id : "openai"),
|
||||
api_key_env: found?.api_key_env,
|
||||
base_url: found?.base_url,
|
||||
api_key_ref: { engine: "", key: "" },
|
||||
const newClass = ref("");
|
||||
watch(
|
||||
classNames,
|
||||
(names) => {
|
||||
if (!newClass.value) newClass.value = names[0] ?? "";
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
function addProvider(): void {
|
||||
const name = newProvider.value.trim();
|
||||
const classId = newClass.value || classNames.value[0];
|
||||
if (!name || !classId) return;
|
||||
void run(async () => {
|
||||
await api.putModelProvider(name, { name, class: classId });
|
||||
providerEdits.value[name] = providerForm();
|
||||
newProvider.value = "";
|
||||
await providers.reload();
|
||||
});
|
||||
newProvider.value = "";
|
||||
}
|
||||
function setProvider(name: string, next: Partial<Provider>) {
|
||||
const current = providers.value?.[name];
|
||||
if (current) store.setDraftEntry("provider-settings", name, { ...current, ...next });
|
||||
|
||||
// Policy: which aliases workflows and chat may name. Empty means any.
|
||||
const workflowText = ref("");
|
||||
const chatText = ref("");
|
||||
watch(policy.data, (current) => {
|
||||
workflowText.value = current?.workflow_aliases?.join(", ") ?? "";
|
||||
chatText.value = current?.chat_aliases?.join(", ") ?? "";
|
||||
});
|
||||
function aliasList(text: string): string[] | null {
|
||||
const list = text.split(",").map((alias) => alias.trim()).filter(Boolean);
|
||||
return list.length ? list : null;
|
||||
}
|
||||
function removeProvider(name: string) {
|
||||
store.setDraftEntry("provider-settings", name, undefined);
|
||||
}
|
||||
const keySource = (p: Provider) =>
|
||||
p.api_key_ref.key ? `${p.api_key_ref.engine} / ${p.api_key_ref.key}` : p.api_key_env ? `env ${p.api_key_env}` : "no key";
|
||||
// Org access: which instance models each other org may use, and whether it may
|
||||
// add its own providers. An org with no entry may use nothing.
|
||||
interface OrgPolicy {
|
||||
allowed: string[];
|
||||
own_providers: boolean;
|
||||
}
|
||||
const policies = computed(() => store.draftValue("org-model-policy") as Record<string, OrgPolicy> | undefined);
|
||||
const otherOrgs = computed(() => (orgStore.instanceAdmin ? orgStore.orgs.filter((o) => o.id !== "org-sys") : []));
|
||||
function policyFor(id: string): OrgPolicy {
|
||||
return policies.value?.[id] ?? { allowed: [], own_providers: false };
|
||||
}
|
||||
function setPolicy(id: string, next: Partial<OrgPolicy>) {
|
||||
if (!policies.value) return;
|
||||
const merged = { ...policyFor(id), ...next };
|
||||
const empty = !merged.allowed.length && !merged.own_providers;
|
||||
store.setDraftEntry("org-model-policy", id, empty ? undefined : merged);
|
||||
}
|
||||
const allowedText = (id: string) => policyFor(id).allowed.join(", ");
|
||||
function setAllowed(id: string, text: string) {
|
||||
setPolicy(id, { allowed: text.split(",").map((ref) => ref.trim()).filter(Boolean) });
|
||||
const policyBusy = ref(false);
|
||||
async function savePolicy(): Promise<void> {
|
||||
policyBusy.value = true;
|
||||
try {
|
||||
await run(async () => {
|
||||
await api.putModelPolicy({ workflow_aliases: aliasList(workflowText.value), chat_aliases: aliasList(chatText.value) });
|
||||
await policy.reload();
|
||||
});
|
||||
} finally {
|
||||
policyBusy.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Models">
|
||||
<HistoryLink :kinds="resources.map((r) => r.kind)" />
|
||||
</PageHeader>
|
||||
<ApplyStatusRows v-for="resource in resources" :key="resource.kind" :kind="resource.kind" class="mb-4" />
|
||||
<PageHeader title="Models" />
|
||||
|
||||
<Alert v-for="e in [catalogError, ...errors].filter(Boolean)" :key="String(e)" variant="destructive" class="mb-4"><AlertDescription>
|
||||
{{ e }}
|
||||
</AlertDescription></Alert>
|
||||
<Alert v-if="error || errorOf(models, providers, classes, credentials, policy)" variant="destructive" class="mb-4">
|
||||
<AlertDescription>{{ error || errorOf(models, providers, classes, credentials, policy) }}</AlertDescription>
|
||||
</Alert>
|
||||
|
||||
<KindGate v-if="!aliases && !providers" kind="provider-settings" />
|
||||
<p v-if="!hasModels && !models.error.value" class="flex items-center gap-2 text-label text-fg-muted" role="status"><Spinner />Loading models…</p>
|
||||
|
||||
<template v-if="aliases">
|
||||
<Section title="Aliases">
|
||||
<p v-if="!aliases.default" class="mb-3 text-label text-warn" role="alert">Set the default alias.</p>
|
||||
<div v-for="alias in aliasNames" :key="alias" class="flex flex-wrap items-center gap-3 border-b border-border py-2.5 last-of-type:border-b-0">
|
||||
<Label :for="`alias-${alias}`" class="w-28 text-label font-medium @max-xl:w-full">{{ alias }}</Label>
|
||||
<template v-if="alias === 'embedding'">
|
||||
<Select :model-value="embeddingProvider" @update:model-value="(v) => setEmbedding(String(v), embeddingModel)">
|
||||
<SelectTrigger class="w-44 font-mono" aria-label="Embedding provider"><SelectValue placeholder="unset" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="id in embeddingProviders" :key="id" :value="id">{{ id }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input
|
||||
:id="`alias-${alias}`"
|
||||
:model-value="embeddingModel"
|
||||
class="min-w-0 max-w-64 flex-1 font-mono"
|
||||
placeholder="model"
|
||||
:disabled="!embeddingProvider"
|
||||
@update:model-value="(v) => setEmbedding(embeddingProvider, String(v))"
|
||||
/>
|
||||
<span v-if="!embeddingProviders.length" class="text-caption text-fg-subtle">Needs an openai, gemini, ollama, cohere or mistral provider.</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
<SuggestInput
|
||||
:id="`alias-${alias}`"
|
||||
:model-value="aliases[alias] ?? ''"
|
||||
:options="modelOptions"
|
||||
class="min-w-0 max-w-md flex-1 font-mono @max-xl:max-w-none @max-xl:basis-full"
|
||||
placeholder="unset"
|
||||
:aria-invalid="!!aliasIssue(alias)"
|
||||
@update:model-value="(v) => setAlias(alias, String(v))"
|
||||
/>
|
||||
<DraftHint kind="model-aliases" :path="alias" />
|
||||
<span v-if="aliasIssue(alias)" class="text-caption text-danger">{{ aliasIssue(alias)?.message }}</span>
|
||||
<span v-else-if="aliases[alias] && !providerKnown(aliases[alias])" class="text-caption text-warn">Provider not configured.</span>
|
||||
</template>
|
||||
<Button v-if="!KNOWN_ALIASES.includes(alias)" variant="ghost" size="icon" class="ml-auto" :aria-label="`Remove alias ${alias}`" @click="removeAlias(alias)">
|
||||
<Trash2 />
|
||||
</Button>
|
||||
</div>
|
||||
<form class="flex flex-wrap gap-2 border-t border-border pt-3" @submit.prevent="addAlias">
|
||||
<Input v-model="newAlias" class="max-w-56 font-mono" placeholder="alias" aria-label="New alias" />
|
||||
<Button type="submit" variant="outline" size="sm" :disabled="!newAlias.trim()"><Plus data-icon="inline-start" />Add alias</Button>
|
||||
</form>
|
||||
</Section>
|
||||
</template>
|
||||
|
||||
<template v-if="policies && otherOrgs.length">
|
||||
<Section title="Org access">
|
||||
<div v-for="o in otherOrgs" :key="o.id" class="flex flex-wrap items-center gap-3 border-b border-border py-2.5 last-of-type:border-b-0">
|
||||
<span class="w-28 truncate text-label font-medium @max-xl:w-full" :title="o.id">{{ o.name }}</span>
|
||||
<Input
|
||||
:model-value="allowedText(o.id)"
|
||||
class="min-w-0 max-w-md flex-1 font-mono @max-xl:max-w-none @max-xl:basis-full"
|
||||
placeholder="no models"
|
||||
:aria-label="`Models ${o.name} may use`"
|
||||
@update:model-value="(v) => setAllowed(o.id, String(v))"
|
||||
/>
|
||||
<Label class="flex items-center gap-2 text-caption text-fg-muted">
|
||||
<Switch :model-value="policyFor(o.id).own_providers" @update:model-value="(v) => setPolicy(o.id, { own_providers: !!v })" />
|
||||
Own providers</Label>
|
||||
<DraftHint kind="org-model-policy" :path="o.id" />
|
||||
</div>
|
||||
</Section>
|
||||
</template>
|
||||
|
||||
<template v-if="providers">
|
||||
<Section title="Providers">
|
||||
<Accordion type="multiple">
|
||||
<AccordionItem v-for="[name, provider] in providerEntries" :key="name" :value="name">
|
||||
<AccordionTrigger class="hover:no-underline">
|
||||
<span class="flex min-w-0 flex-1 flex-wrap items-center gap-x-3">
|
||||
<span class="w-28 text-left font-mono text-label font-medium">{{ name }}</span>
|
||||
<span v-if="provider.class !== name" class="font-mono text-caption text-fg-muted">{{ provider.class }}</span>
|
||||
<span class="min-w-0 truncate font-mono text-caption text-fg-subtle">{{ keySource(provider) }}</span>
|
||||
</span>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
<FieldGroup class="@container/field-group">
|
||||
<Field orientation="responsive" class="border-t-0 pt-0">
|
||||
<FieldContent><FieldLabel>Class</FieldLabel></FieldContent>
|
||||
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
||||
<Select :model-value="provider.class" @update:model-value="(v) => setProvider(name, { class: String(v) })">
|
||||
<SelectTrigger class="w-48 font-mono" :aria-label="`Class for ${name}`"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="c in catalogClasses.includes(provider.class) ? catalogClasses : [provider.class, ...catalogClasses]" :key="c" :value="c">{{ c }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<DraftHint kind="provider-settings" :path="`${name}.class`" />
|
||||
</div>
|
||||
</Field>
|
||||
<Field orientation="responsive">
|
||||
<FieldContent>
|
||||
<FieldLabel :for="`prov-${name}-url`">Base URL</FieldLabel>
|
||||
<FieldDescription>Empty: provider default.</FieldDescription>
|
||||
</FieldContent>
|
||||
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
||||
<Input
|
||||
:id="`prov-${name}-url`"
|
||||
:model-value="provider.base_url ?? ''"
|
||||
class="max-w-md font-mono"
|
||||
@update:model-value="(v) => setProvider(name, { base_url: String(v) })"
|
||||
/>
|
||||
<DraftHint kind="provider-settings" :path="`${name}.base_url`" />
|
||||
</div>
|
||||
</Field>
|
||||
<Field orientation="responsive">
|
||||
<FieldContent>
|
||||
<FieldLabel :for="`prov-${name}-env`">API key environment variable</FieldLabel>
|
||||
<FieldDescription>Used when no secret reference is set.</FieldDescription>
|
||||
</FieldContent>
|
||||
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
||||
<Input
|
||||
:id="`prov-${name}-env`"
|
||||
:model-value="provider.api_key_env ?? ''"
|
||||
aria-label="API key environment variable"
|
||||
placeholder="API key environment variable"
|
||||
class="max-w-md font-mono"
|
||||
@update:model-value="(v) => setProvider(name, { api_key_env: String(v) })"
|
||||
/>
|
||||
<DraftHint kind="provider-settings" :path="`${name}.api_key_env`" />
|
||||
</div>
|
||||
</Field>
|
||||
<Field orientation="responsive">
|
||||
<FieldContent><FieldLabel>API key</FieldLabel></FieldContent>
|
||||
<div class="flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1">
|
||||
<SecretRefField
|
||||
:model-value="provider.api_key_ref"
|
||||
:id-prefix="`prov-${name}-key`"
|
||||
:fallback="provider.api_key_env ? `env ${provider.api_key_env}` : undefined"
|
||||
@update:model-value="(v) => setProvider(name, { api_key_ref: v })"
|
||||
/>
|
||||
</div>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
<div class="flex justify-end pb-1">
|
||||
<Button variant="ghost" size="sm" class="text-danger" @click="removeProvider(name)"><Trash2 data-icon="inline-start" />Remove</Button>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
<form class="flex flex-wrap items-center gap-2 border-t border-border pt-3" @submit.prevent="addProvider">
|
||||
<SuggestInput v-model="newProvider" :options="available.map((p) => p.id)" class="max-w-56 font-mono" placeholder="provider" aria-label="New provider" />
|
||||
<Button type="submit" variant="outline" size="sm" :disabled="!newProvider.trim()"><Plus data-icon="inline-start" />Add provider</Button>
|
||||
<span v-if="available.length" class="text-caption text-fg-subtle">Available:
|
||||
<Button v-for="p in available" :key="p.id" type="button" variant="link" size="xs" class="h-auto px-1 font-mono text-fg-subtle" @click="newProvider = p.id; addProvider()">{{ p.id }}</Button>
|
||||
<Section v-else title="Aliases">
|
||||
<p v-if="hasModels && !modelMap.default" class="mb-3 text-label text-warn" role="alert">Set the default alias.</p>
|
||||
<div v-for="alias in aliases" :key="alias" class="border-b border-border py-2.5 last-of-type:border-b-0">
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<Label :for="`model-${alias}`" class="w-28 text-label font-medium @max-xl:w-full">{{ alias }}</Label>
|
||||
<Select v-model="aliasField(alias).provider">
|
||||
<SelectTrigger class="w-44 font-mono" :aria-label="`${alias} provider`"><SelectValue placeholder="provider" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="name in providerNames" :key="name" :value="name">{{ name }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input :id="`model-${alias}`" v-model="aliasField(alias).model" class="min-w-40 flex-1 basis-40 font-mono" placeholder="model" />
|
||||
<span class="ml-auto flex items-center gap-1">
|
||||
<Button variant="outline" size="sm" :disabled="!!aliasBusy || !aliasField(alias).provider || !aliasField(alias).model" @click="testAlias(alias)">Test</Button>
|
||||
<Button size="sm" :disabled="!!aliasBusy || !aliasField(alias).provider || !aliasField(alias).model" @click="saveAlias(alias)">Save</Button>
|
||||
<Button v-if="alias !== 'default' || modelMap[alias]" variant="ghost" size="icon" :aria-label="`Remove alias ${alias}`" :disabled="!!aliasBusy" @click="removeAlias(alias)"><Trash2 /></Button>
|
||||
</span>
|
||||
</form>
|
||||
</Section>
|
||||
</template>
|
||||
</div>
|
||||
<p v-if="tested[alias]" role="status" class="pt-1.5 text-caption text-ok">{{ tested[alias] }}</p>
|
||||
<p v-if="aliasError[alias]" role="alert" class="pt-1.5 text-caption text-danger">{{ aliasError[alias] }}</p>
|
||||
</div>
|
||||
<form class="flex flex-wrap gap-2 border-t border-border pt-3" @submit.prevent="addAlias">
|
||||
<Input v-model="newAlias" class="max-w-56 font-mono" placeholder="alias" aria-label="New alias" />
|
||||
<Button type="submit" variant="outline" size="sm" :disabled="!newAlias.trim()"><Plus data-icon="inline-start" />Add alias</Button>
|
||||
</form>
|
||||
</Section>
|
||||
|
||||
<Section v-if="hasProviders" title="Providers">
|
||||
<Accordion type="multiple">
|
||||
<AccordionItem v-for="name in providerNames" :key="name" :value="name">
|
||||
<AccordionTrigger class="hover:no-underline">
|
||||
<span class="flex min-w-0 flex-1 flex-wrap items-center gap-x-3">
|
||||
<span class="w-28 text-left font-mono text-label font-medium">{{ name }}</span>
|
||||
<span class="font-mono text-caption text-fg-muted">{{ providerField(name).class }}</span>
|
||||
<span class="min-w-0 truncate font-mono text-caption text-fg-subtle">{{
|
||||
providerField(name).key === NONE ? "no key" : providerField(name).key
|
||||
}}</span>
|
||||
</span>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
<div class="flex flex-wrap items-center gap-3 border-t-0 py-2">
|
||||
<Label :for="`prov-${name}-class`" class="w-28 text-label font-medium @max-xl:w-full">Class</Label>
|
||||
<Select v-model="providerField(name).class">
|
||||
<SelectTrigger :id="`prov-${name}-class`" class="w-48 font-mono" :aria-label="`Class for ${name}`"><SelectValue /></SelectTrigger>
|
||||
<SelectContent><SelectItem v-for="classId in classNames" :key="classId" :value="classId">{{ classId }}</SelectItem></SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3 border-t-0 py-2">
|
||||
<Label :for="`prov-${name}-url`" class="w-28 text-label font-medium @max-xl:w-full">Base URL</Label>
|
||||
<Input :id="`prov-${name}-url`" v-model="providerField(name).base_url" class="max-w-md font-mono" :placeholder="classList.find((entry) => entry.class === providerField(name).class)?.default_base_url || 'class default'" />
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3 border-t-0 py-2">
|
||||
<Label :for="`prov-${name}-key`" class="w-28 text-label font-medium @max-xl:w-full">API key</Label>
|
||||
<Select v-model="providerField(name).key">
|
||||
<SelectTrigger :id="`prov-${name}-key`" class="w-56" :aria-label="`API key for ${name}`"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem :value="NONE">No key</SelectItem>
|
||||
<SelectItem v-for="credential in credentialNames" :key="credential" :value="credential">{{ credential }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div class="flex justify-end gap-1 pb-1">
|
||||
<Button variant="ghost" size="sm" class="text-danger" :disabled="!!providerBusy" @click="removeProvider(name)"><Trash2 data-icon="inline-start" />Remove</Button>
|
||||
<Button size="sm" :disabled="!!providerBusy || !providerField(name).class" @click="saveProvider(name)">Save</Button>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
<form class="flex flex-wrap items-center gap-2 border-t border-border pt-3" @submit.prevent="addProvider">
|
||||
<Input v-model="newProvider" class="max-w-56 font-mono" placeholder="provider" aria-label="New provider" />
|
||||
<Select v-model="newClass">
|
||||
<SelectTrigger class="w-44 font-mono" aria-label="Provider class"><SelectValue placeholder="class" /></SelectTrigger>
|
||||
<SelectContent><SelectItem v-for="classId in classNames" :key="classId" :value="classId">{{ classId }}</SelectItem></SelectContent>
|
||||
</Select>
|
||||
<Button type="submit" variant="outline" size="sm" :disabled="!newProvider.trim() || !newClass"><Plus data-icon="inline-start" />Add provider</Button>
|
||||
</form>
|
||||
</Section>
|
||||
|
||||
<Section v-if="policyData" title="Policy">
|
||||
<div class="flex flex-wrap items-center gap-3 py-2">
|
||||
<Label for="policy-workflows" class="w-28 text-label font-medium @max-xl:w-full">Workflows</Label>
|
||||
<Input id="policy-workflows" v-model="workflowText" class="min-w-40 flex-1 basis-40 font-mono" placeholder="any alias" aria-label="Aliases workflows may use" />
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3 py-2">
|
||||
<Label for="policy-chat" class="w-28 text-label font-medium @max-xl:w-full">Chat</Label>
|
||||
<Input id="policy-chat" v-model="chatText" class="min-w-40 flex-1 basis-40 font-mono" placeholder="any alias" aria-label="Aliases chat may use" />
|
||||
</div>
|
||||
<div class="flex justify-end pt-2"><Button size="sm" :disabled="policyBusy" @click="savePolicy">Save</Button></div>
|
||||
</Section>
|
||||
</div>
|
||||
</template>
|
||||
+51
-108
@@ -1,94 +1,28 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
import { errors } from "../copy/errors/index.ts";
|
||||
import { describeError } from "../lib/api.ts";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { api, describeError, type CatalogueEntry, type CatalogueSourceView, type Extension, type ExtensionGrantsInput, type Grants, type SettingField } from "@/lib/api";
|
||||
|
||||
export interface Authority {
|
||||
credential_services: string[];
|
||||
egress_hosts: string[];
|
||||
forge_permissions: string[];
|
||||
triggers: string[];
|
||||
tools: string[];
|
||||
env: string[];
|
||||
}
|
||||
export type { CatalogueEntry, Extension } from "@/lib/api";
|
||||
/** One setting a package declares. */
|
||||
export type ExtensionSettingSpec = SettingField;
|
||||
|
||||
export interface Extension {
|
||||
name: string;
|
||||
display_name: string;
|
||||
description: string;
|
||||
version: string;
|
||||
reference: string;
|
||||
digest: string;
|
||||
surfaces: string[];
|
||||
declared: Authority;
|
||||
accepted: Authority | null;
|
||||
enabled: boolean;
|
||||
/** An update waiting for approval, with only the grants it adds. */
|
||||
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;
|
||||
/** Absent means string. */
|
||||
type?: "string" | "number" | "boolean" | "duration" | "list" | "select" | "text";
|
||||
/** Choices for a select. */
|
||||
options?: string[];
|
||||
}
|
||||
|
||||
/** A package the verified catalogue offers. */
|
||||
export interface CatalogueEntry {
|
||||
name: string;
|
||||
surface: string;
|
||||
version: string;
|
||||
description: string;
|
||||
reference: string;
|
||||
digest: string;
|
||||
installed: boolean;
|
||||
}
|
||||
|
||||
async function call<T>(path: string, init: RequestInit = {}): Promise<T> {
|
||||
const response = await fetch(path, {
|
||||
...init,
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"X-Archie-CSRF": "1",
|
||||
...init.headers,
|
||||
},
|
||||
});
|
||||
if (!response.ok) throw new Error((await response.text()).trim());
|
||||
return response.json() as Promise<T>;
|
||||
}
|
||||
|
||||
/** The grants an authority record names, as "kind: value" lines. */
|
||||
export function grants(authority: Authority): string[] {
|
||||
const labelled: [string, string[]][] = [
|
||||
["credential", authority.credential_services],
|
||||
["egress", authority.egress_hosts],
|
||||
["forge", authority.forge_permissions],
|
||||
["trigger", authority.triggers],
|
||||
["tool", authority.tools],
|
||||
["env", authority.env],
|
||||
/** The grants an extension record names, as "kind: value" lines. */
|
||||
export function grants(g: Grants | null | undefined): string[] {
|
||||
if (!g) return [];
|
||||
const lines = [
|
||||
...g.egress.map((host) => `egress: ${host}`),
|
||||
...g.env.map((name) => `env: ${name}`),
|
||||
...g.credentials.map((slot) => `credential: ${slot}`),
|
||||
];
|
||||
const lines = labelled.flatMap(([label, values]) => values.map((value) => `${label}: ${value}`));
|
||||
// A package that declares no egress hosts runs on the host's network.
|
||||
return authority.egress_hosts.length ? lines : ["network: unrestricted", ...lines];
|
||||
// An extension that declares no egress hosts runs on the host's network.
|
||||
return g.egress.length ? lines : ["network: unrestricted", ...lines];
|
||||
}
|
||||
|
||||
/** What an extension needs from the operator next, in the order it happens. */
|
||||
export function stage(extension: Extension): "accept" | "disabled" | "enabled" | "inert" {
|
||||
if (!extension.surfaces.length) return "inert";
|
||||
/** What an extension needs from the operator next. */
|
||||
export function stage(extension: Extension): "accept" | "disabled" | "enabled" {
|
||||
if (!extension.managed) return "enabled";
|
||||
if (!extension.accepted) return "accept";
|
||||
return extension.enabled ? "enabled" : "disabled";
|
||||
}
|
||||
@@ -96,24 +30,40 @@ export function stage(extension: Extension): "accept" | "disabled" | "enabled" |
|
||||
export const useExtensionsStore = defineStore("extensions", () => {
|
||||
const extensions = ref<Extension[]>([]);
|
||||
const catalogue = ref<CatalogueEntry[]>([]);
|
||||
const source = ref<CatalogueSourceView>({ configured: false });
|
||||
const catalogueError = ref("");
|
||||
const catalogueLoaded = ref(false);
|
||||
const error = ref("");
|
||||
const busy = ref("");
|
||||
// The binary carries no per-extension surface, so a connection cannot yet
|
||||
// name an installed forge.
|
||||
const forges = computed<Extension[]>(() => []);
|
||||
function forgeName(type: string): string {
|
||||
return `${type} · not enabled`;
|
||||
}
|
||||
|
||||
async function loadInstalled(): Promise<void> {
|
||||
try {
|
||||
extensions.value = (await call<{ extensions: Extension[] }>("/api/extensions")).extensions;
|
||||
extensions.value = await api.allExtensions();
|
||||
error.value = "";
|
||||
} catch (cause) {
|
||||
error.value = describeError(cause, errors.common.unknown);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadSource(): Promise<void> {
|
||||
try {
|
||||
source.value = await api.catalogueSource();
|
||||
} catch {
|
||||
source.value = { configured: false };
|
||||
}
|
||||
}
|
||||
|
||||
async function load(): Promise<void> {
|
||||
await loadInstalled();
|
||||
await Promise.all([loadInstalled(), loadSource()]);
|
||||
// The catalogue is remote; its failure leaves the installed list usable.
|
||||
try {
|
||||
catalogue.value = await call<CatalogueEntry[]>("/api/extensions/catalogue");
|
||||
catalogue.value = await api.catalogue();
|
||||
catalogueError.value = "";
|
||||
} catch (cause) {
|
||||
catalogueError.value = describeError(cause, errors.common.unknown);
|
||||
@@ -121,6 +71,7 @@ export const useExtensionsStore = defineStore("extensions", () => {
|
||||
catalogueLoaded.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
async function mutate(key: string, action: () => Promise<unknown>): Promise<boolean> {
|
||||
busy.value = key;
|
||||
try {
|
||||
@@ -134,37 +85,29 @@ export const useExtensionsStore = defineStore("extensions", () => {
|
||||
busy.value = "";
|
||||
}
|
||||
}
|
||||
const forges = computed(() => extensions.value.filter((e) => e.enabled && e.surfaces.includes("forge")));
|
||||
function forgeName(type: string): string {
|
||||
const forge = forges.value.find((e) => e.name === type);
|
||||
return forge ? forge.display_name || forge.name : `${type} · not enabled`;
|
||||
}
|
||||
const path = (name: string) => `/api/extensions/${encodeURIComponent(name)}`;
|
||||
|
||||
return {
|
||||
catalogueLoaded,
|
||||
forges,
|
||||
forgeName,
|
||||
extensions,
|
||||
catalogue,
|
||||
source,
|
||||
catalogueLoaded,
|
||||
catalogueError,
|
||||
error,
|
||||
busy,
|
||||
load,
|
||||
loadInstalled,
|
||||
install: (name: string, reference: string, digest: string) =>
|
||||
mutate("install", () => call("/api/extensions", { method: "POST", body: JSON.stringify({ name, reference, digest }) })),
|
||||
installFromCatalogue: (name: string) =>
|
||||
mutate(name, () => call(`/api/extensions/catalogue/${encodeURIComponent(name)}/install`, { method: "POST" })),
|
||||
accept: (name: string) => mutate(name, () => call(`${path(name)}/accept`, { method: "POST" })),
|
||||
update: (name: string) => mutate(name, () => call(`${path(name)}/update`, { method: "POST" })),
|
||||
approveUpdate: (name: string) => mutate(name, () => call(`${path(name)}/approve-update`, { method: "POST" })),
|
||||
setUpdatePolicy: (name: string, policy: "manual" | "auto") =>
|
||||
mutate(name, () => call(`${path(name)}/update-policy`, { method: "PUT", body: JSON.stringify({ policy }) })),
|
||||
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" })),
|
||||
loadSource,
|
||||
installFromCatalogue: (name: string) => mutate(name, () => api.installCatalogue(name)),
|
||||
accept: (name: string, body?: ExtensionGrantsInput) => mutate(name, () => api.acceptGrants(name, body)),
|
||||
update: (name: string) => mutate(name, () => api.updateExtension(name)),
|
||||
approveUpdate: (name: string) => mutate(name, () => api.approveExtensionUpdate(name)),
|
||||
setUpdatePolicy: (name: string, policy: "manual" | "auto") => mutate(name, () => api.setExtensionPolicy(name, policy)),
|
||||
rollback: (name: string) => mutate(name, () => api.rollbackExtension(name)),
|
||||
setEnabled: (name: string, enabled: boolean) => mutate(name, () => api.setExtensionEnabled(name, enabled)),
|
||||
saveSettings: (name: string, settings: Record<string, string>) => mutate(name, () => api.putExtensionSettings(name, settings)),
|
||||
remove: (name: string) => mutate(name, () => api.removeAnyExtension(name)),
|
||||
saveSource: (location: string, publicKey: string) => mutate("source", () => api.putCatalogueSource({ location, public_key: publicKey })),
|
||||
};
|
||||
});
|
||||
Reference in new issue
Block a user