feat(connectors): separate packages from scoped installations (#2027)

Packages are accepted once by the instance. Installations configure them at the instance, an organisation or a person; bindings and credentials resolve the person's, then their organisation's, then the instance's. Decisions, approval requests and held chat actions record the installation and scope that acted.

The dashboard lists packages separately from installations, shows every installation's scope, and creates, edits and disables installations at their scope.
This commit is contained in:
sam committed 2026-11-24 03:05:27 +11:00
1 parent 7e701f9a50
commit f24c2b4455
57 files changed
+3358 -1264

No files matched your search

+70 -2
View File
@@ -258,6 +258,15 @@ export const api = {
extensionKinds: () => request<ExtensionKindInfo[]>("/api/extension-kinds"),
extensions: (kind: ExtensionKind) => request<Extension[]>(`/api/${kind}`),
allExtensions: () => request<Extension[]>("/api/extensions"),
packages: () => request<PackageView[]>("/api/packages"),
createInstallation: (body: InstallationInput) =>
request<Extension>("/api/installations", { method: "POST", body, timeoutMs: 120_000 }),
updateInstallation: (id: string, body: InstallationUpdate) =>
request<Extension>(`/api/installations/${id}`, { method: "PUT", body, timeoutMs: 120_000 }),
removeInstallation: (id: string) =>
request<{ name: string; state: string }>(`/api/installations/${id}`, { method: "DELETE" }),
putInstallationOverride: (id: string, scope: "org" | "person", off: boolean) =>
request<{ name: string; state: string }>(`/api/installations/${id}/override`, { method: "PUT", body: { scope, off } }),
removeAnyExtension: (name: string) =>
request<{ name: string; state: string }>(`/api/extensions/${encodeURIComponent(name)}`, { method: "DELETE" }),
catalogue: () => request<CatalogueEntry[]>("/api/extensions/catalogue"),
@@ -286,8 +295,8 @@ export const api = {
request<{ name: string; state: string }>(`/api/${kind}/${encodeURIComponent(name)}`, { method: "DELETE" }),
credentials: () => request<Credential[]>("/api/credentials"),
credentialKinds: () => request<CredentialKind[]>("/api/credential-kinds"),
putCredential: (name: string, kind: string, fields: Record<string, CredentialField>) =>
request<{ name: string; kind: string; restarted: string[] }>(`/api/credentials/${encodeURIComponent(name)}`, { method: "PUT", body: { kind, fields }, timeoutMs: 60_000 }),
putCredential: (name: string, kind: string, fields: Record<string, CredentialField>, scope: ExtensionScope = "instance") =>
request<{ name: string; kind: string; scope: ExtensionScope; restarted: string[] }>(`/api/credentials/${encodeURIComponent(name)}`, { method: "PUT", body: { kind, fields, scope }, timeoutMs: 60_000 }),
orgSettings: () => request<OrgSettings>("/api/settings"),
putOrgSettings: (settings: OrgSettings) =>
request<OrgSettings>("/api/settings", { method: "PUT", body: settings }),
@@ -1084,11 +1093,17 @@ export interface StepType {
export type ExtensionGroup = "platform" | "integration" | "agent";
/** Who owns an installation or a credential: the instance, an organisation or
* a person. */
export type ExtensionScope = "instance" | "org" | "person";
/** An accepted-package kind, as the server lists it: the path segment of its API. */
export type ExtensionKind = string;
export interface ExtensionKindInfo {
kind: ExtensionKind;
/** The package contract this kind accepts. */
contract: string;
label: string;
singular: string;
group: ExtensionGroup;
@@ -1122,7 +1137,22 @@ export interface Capabilities {
}
export interface Extension {
/** The installation's ID, which a decision records. */
id: string;
name: string;
/** The package the installation configures. */
package: string;
scope: ExtensionScope;
/** The organisation or person that owns the installation; empty for the instance. */
owner_id?: string;
/** Whether the caller may change the installation. */
editable: boolean;
/** Whether the caller's organisation or person switched an inherited installation off. */
overridden: boolean;
/** The caller's scopes that switched it off. */
overridden_by?: ExtensionScope[];
/** The scopes the caller may switch an inherited installation off at. */
can_override?: ExtensionScope[];
state: string;
error?: string;
path?: string;
@@ -1156,6 +1186,43 @@ export interface Extension {
update_policy?: "manual" | "auto";
}
/** One package the instance accepted: the binary and manifest, without the
* configuration an installation gives it. */
export interface PackageView {
id: string;
name: string;
contract: string;
group: ExtensionGroup;
display_name?: string;
description?: string;
version?: string;
digest: string;
/** Installed from the catalogue rather than accepted by path. */
managed: boolean;
/** Whether the instance accepted the package's grants, so another scope can install it. */
installed: boolean;
accepted_at: string;
}
/** One installation's configuration. A create names the package and the scope
* that owns it; an update changes only what the installation is configured
* with. */
export interface InstallationInput {
package: string;
name?: string;
scope: ExtensionScope;
settings?: Record<string, string>;
egress?: string[];
env?: string[];
credentials?: Record<string, string>;
args?: string[];
url?: string;
tools?: unknown;
enabled: boolean;
}
export type InstallationUpdate = Omit<InstallationInput, "package" | "name" | "scope">;
/** What an extension may use: hosts it reaches, host variables it sees and
* credential slots it is configured with. */
export interface Grants {
@@ -1255,6 +1322,7 @@ export interface OrgSettings {
export interface Credential {
name: string;
kind: string;
scope: ExtensionScope;
/** Per field: "stored", or "engine:key" for one a secret engine resolves. */
fields: Record<string, string>;
}
+29 -4
View File
@@ -18,8 +18,9 @@ import { Skeleton } from "@/components/ui/skeleton";
import { Textarea } from "@/components/ui/textarea";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
import { errors } from "@/copy/errors";
import { api, describeError, type Credential, type CredentialField } from "@/lib/api";
import { api, describeError, type Credential, type CredentialField, type ExtensionScope } from "@/lib/api";
import { useRead } from "@/lib/use-read";
import { useOrgStore } from "@/stores/org";
/** Credentials are sealed and never read back: the list says only where each
* field comes from, and a save replaces every field. */
@@ -35,17 +36,32 @@ onMounted(() => {
const columns: DataTableColumn<Credential>[] = [
{ id: "name", label: "Credential", fixed: true, sort: (c) => c.name },
{ id: "kind", label: "Kind", hide: "sm", width: "10rem", sort: (c) => c.kind },
{ id: "scope", label: "Scope", hide: "sm", width: "9rem", sort: (c) => c.scope },
{ id: "fields", label: "Fields", hide: "md", width: "24rem" },
];
const scopeLabels: Record<ExtensionScope, string> = { instance: "Instance", org: "Organisation", person: "Person" };
const org = useOrgStore();
onMounted(org.loadOrg);
// Who may own a new credential: the instance when the caller administers it,
// their organisation when they own it, and always themselves.
const scopes = computed<ExtensionScope[]>(() => {
const out: ExtensionScope[] = [];
if (org.instanceAdmin) out.push("instance");
if (org.org?.role === "owner") out.push("org");
out.push("person");
return out;
});
interface FieldForm { from: "value" | "engine"; value: string; engine: string; key: string }
const editing = ref(false);
const isNew = ref(true);
const name = ref("");
const kind = ref("");
const scope = ref<ExtensionScope>("instance");
const fields = ref<Record<string, FieldForm>>({});
const kindSpec = computed(() => kinds.data.value?.find((k) => k.kind === kind.value));
const fieldNames = computed(() => [...(kindSpec.value?.required ?? []), ...(kindSpec.value?.optional ?? [])]);
const availableEngines = computed(() => (engines.data.value ?? []).filter((e) => e.scope === "instance" || e.scope === scope.value));
function pickKind(next: unknown): void {
kind.value = String(next);
fields.value = Object.fromEntries(fieldNames.value.map((f) => [f, fields.value[f] ?? { from: "value", value: "", engine: "", key: "" }]));
@@ -54,6 +70,7 @@ function open(cred?: Credential): void {
isNew.value = !cred;
actionError.value = "";
name.value = cred?.name ?? "";
scope.value = cred?.scope ?? "instance";
fields.value = {};
for (const [field, from] of Object.entries(cred?.fields ?? {})) {
const at = from.indexOf(":");
@@ -80,7 +97,7 @@ async function submit(): Promise<void> {
else if (f.from === "value" && f.value) body[field] = { value: f.value };
}
try {
restarted.value = (await api.putCredential(name.value.trim(), kind.value, body)).restarted ?? [];
restarted.value = (await api.putCredential(name.value.trim(), kind.value, body, scope.value)).restarted ?? [];
editing.value = false;
} catch (cause) {
actionError.value = describeError(cause, errors.common.unknown);
@@ -102,6 +119,7 @@ async function submit(): Promise<void> {
<DataTable v-else :columns="columns" :rows="data" :row-key="(c) => c.name" storage-key="credentials">
<template #cell-name="{ row }"><span class="font-medium">{{ row.name }}</span></template>
<template #cell-kind="{ row }"><Badge variant="outline">{{ row.kind }}</Badge></template>
<template #cell-scope="{ row }"><Badge variant="outline">{{ scopeLabels[row.scope] }}</Badge></template>
<template #cell-fields="{ row }">
<span class="font-mono text-caption">{{ Object.entries(row.fields).map(([f, from]) => from === "stored" ? f : `${f} ← ${from}`).join(", ") }}</span>
</template>
@@ -122,16 +140,23 @@ async function submit(): Promise<void> {
<SelectContent><SelectItem v-for="k in kinds.data.value ?? []" :key="k.kind" :value="k.kind">{{ k.kind }}</SelectItem></SelectContent>
</Select>
</SettingRow>
<SettingRow label="Scope" for="cred-scope" hint="Who owns the credential. Installations resolve the person's, then the organisation's, then the instance's.">
<Select v-if="isNew" v-model="scope">
<SelectTrigger id="cred-scope" class="w-full"><SelectValue /></SelectTrigger>
<SelectContent><SelectItem v-for="value in scopes" :key="value" :value="value">{{ scopeLabels[value] }}</SelectItem></SelectContent>
</Select>
<span v-else class="text-label">{{ scopeLabels[scope] }}</span>
</SettingRow>
<SettingRow v-for="field in fieldNames" :key="field" :label="field" :for="`cred-${field}`" :hint="optional(field) ? 'Optional' : undefined">
<div class="space-y-2">
<ToggleGroup v-if="engines.data.value?.length" v-model="fields[field].from" type="single" variant="outline" size="sm" :aria-label="`${field} from`">
<ToggleGroup v-if="availableEngines.length" v-model="fields[field].from" type="single" variant="outline" size="sm" :aria-label="`${field} from`">
<ToggleGroupItem value="value">Value</ToggleGroupItem>
<ToggleGroupItem value="engine">Secret engine</ToggleGroupItem>
</ToggleGroup>
<template v-if="fields[field].from === 'engine'">
<Select v-model="fields[field].engine">
<SelectTrigger class="w-full" :aria-label="`${field} engine`"><SelectValue placeholder="Engine" /></SelectTrigger>
<SelectContent><SelectItem v-for="e in engines.data.value ?? []" :key="e.name" :value="e.name">{{ e.name }}</SelectItem></SelectContent>
<SelectContent><SelectItem v-for="e in availableEngines" :key="e.name" :value="e.name">{{ e.name }}</SelectItem></SelectContent>
</Select>
<Input v-model="fields[field].key" :aria-label="`${field} key`" placeholder="Key" class="font-mono" :required="!optional(field)" />
</template>
-226
View File
@@ -1,226 +0,0 @@
<script setup lang="ts">
import { Plus } from "@lucide/vue";
import { computed, onMounted, ref } from "vue";
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { Input } from "@/components/ui/input";
import { MoreMenu } from "@/components/ui/more-menu";
import { ReadError } from "@/components/ui/read-error";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { SettingRow } from "@/components/ui/setting-row";
import { Skeleton } from "@/components/ui/skeleton";
import { Textarea } from "@/components/ui/textarea";
import { errors } from "@/copy/errors";
import { api, describeError, type Extension, type ExtensionInput, type ExtensionKind } from "@/lib/api";
import { useRead } from "@/lib/use-read";
import { stateTone } from "@/runs/state";
import { fromLines, toLines } from "@/lib/lines";
/** The packages of one kind the binary runs: each is accepted by path and
* digest, and runs only while its digest matches. */
const props = defineProps<{ kind: ExtensionKind; noun: string }>();
const { data, error, reload } = useRead(() => api.extensions(props.kind));
onMounted(reload);
const columns = computed<DataTableColumn<Extension>[]>(() => [
{ id: "name", label: "Name", fixed: true, sort: (e) => e.name },
{ id: "state", label: "State", fixed: true, width: "9rem", sort: (e) => e.state },
{ id: "version", label: "Version", hide: "sm", width: "8rem", sort: (e) => e.version ?? "" },
...(props.kind === "connectors" ? [{ id: "capabilities", label: "Declares", hide: "md" as const, width: "14rem" }] : []),
{ id: "path", label: "Path", hidden: true, hide: "md", width: "18rem" },
{ id: "egress", label: "Egress", hidden: true, hide: "md", width: "14rem" },
]);
const CAPABILITY_GROUPS = [
{ key: "events", label: "Events" },
{ key: "actions", label: "Actions" },
{ key: "deliveries", label: "Deliveries" },
{ key: "lookups", label: "Lookups" },
] as const;
function declared(ext: Extension) {
return CAPABILITY_GROUPS.map((g) => ({ ...g, items: ext.capabilities?.[g.key] ?? [] })).filter((g) => g.items.length);
}
const mcp = computed(() => props.kind === "mcp-servers");
/** What an operator declares about an MCP server's tools. Chat offers a server
* only when its effects are declared and neither one applies. */
const EFFECT_OPTIONS = [
{ value: "unset", label: "Not declared", effects: undefined },
{ value: "none", label: "No privileged effects", effects: { privilege_change: false, secret_access: false } },
{ value: "privilege_change", label: "Changes privileges", effects: { privilege_change: true, secret_access: false } },
{ value: "secret_access", label: "Accesses secrets", effects: { privilege_change: false, secret_access: true } },
{ value: "both", label: "Changes privileges and accesses secrets", effects: { privilege_change: true, secret_access: true } },
] as const;
function effectOf(ext?: Extension): string {
const e = ext?.effects;
if (!e) return "unset";
if (e.privilege_change && e.secret_access) return "both";
return e.privilege_change ? "privilege_change" : e.secret_access ? "secret_access" : "none";
}
const editing = ref(false);
const isNew = ref(true);
const schema = ref<Extension["settings_schema"]>([]);
const form = ref({ name: "", path: "", sha256: "", url: "", args: "", egress: "", env: "", credentials: "", tools: "", effects: "unset", settings: {} as Record<string, string>, other: "" });
function open(ext?: Extension): void {
isNew.value = !ext;
actionError.value = "";
schema.value = ext?.settings_schema ?? [];
const known = new Set(schema.value.map((f) => f.key));
const settings = ext?.settings ?? {};
form.value = {
name: ext?.name ?? "",
path: ext?.path ?? "",
sha256: ext?.digest ?? "",
url: ext?.url ?? "",
args: (ext?.args ?? []).join("\n"),
egress: (ext?.egress ?? []).join("\n"),
env: (ext?.env ?? []).join("\n"),
credentials: toLines(ext?.credentials ?? {}),
tools: ext?.tools ? JSON.stringify(ext.tools, null, 2) : "[]",
effects: effectOf(ext),
settings: Object.fromEntries(Object.entries(settings).filter(([k]) => known.has(k))),
other: toLines(Object.fromEntries(Object.entries(settings).filter(([k]) => !known.has(k)))),
};
editing.value = true;
}
const list = (text: string) => text.split("\n").map((l) => l.trim()).filter(Boolean);
const busy = ref(false);
const actionError = ref("");
async function submit(): Promise<void> {
const f = form.value;
busy.value = true;
actionError.value = "";
try {
const settings = { ...fromLines(f.other), ...Object.fromEntries(Object.entries(f.settings).filter(([, v]) => v !== "")) };
const body: ExtensionInput = {
path: f.path.trim() || undefined,
sha256: f.sha256.trim() || undefined,
egress: list(f.egress),
env: list(f.env),
settings,
credentials: fromLines(f.credentials),
};
if (mcp.value) {
body.url = f.url.trim() || undefined;
body.args = list(f.args);
body.tools = JSON.parse(f.tools || "[]");
body.effects = EFFECT_OPTIONS.find((o) => o.value === f.effects)?.effects;
}
await api.acceptExtension(props.kind, f.name.trim(), body);
editing.value = false;
} catch (cause) {
actionError.value = cause instanceof SyntaxError ? `Tools: ${cause.message}` : describeError(cause, errors.common.unknown);
} finally {
busy.value = false;
await reload();
}
}
const removing = ref<Extension | null>(null);
async function remove(): Promise<void> {
if (!removing.value) return;
busy.value = true;
actionError.value = "";
try {
await api.removeExtension(props.kind, removing.value.name);
} catch (cause) {
actionError.value = describeError(cause, errors.common.unknown);
} finally {
removing.value = null;
busy.value = false;
await reload();
}
}
</script>
<template>
<div>
<p v-if="actionError && !editing" role="alert" class="mb-2 text-caption text-danger">{{ actionError }}</p>
<ReadError v-if="error" :message="error" retry-label="Retry" @retry="reload" />
<div v-else-if="!data" role="status" :aria-label="`Loading ${noun}s`" class="space-y-2"><Skeleton class="h-8 w-full" /></div>
<template v-else>
<div class="mb-2 flex justify-end">
<Button size="icon-sm" variant="ghost" :aria-label="`Add ${noun}`" :title="`Add ${noun}`" @click="open()"><Plus /></Button>
</div>
<DataTable :columns="columns" :rows="data" :row-key="(e) => e.name" :storage-key="`extensions-${kind}`">
<template #cell-name="{ row }"><span class="font-medium">{{ row.name }}</span></template>
<template #cell-state="{ row }">
<Badge :variant="stateTone(row.state === 'running' ? 'succeeded' : row.state)" :title="row.error || undefined">{{ row.state }}</Badge>
<p v-if="row.error" class="mt-1 text-caption text-danger">{{ row.error }}</p>
</template>
<template #cell-version="{ row }">{{ row.version }}</template>
<template #cell-capabilities="{ row }">
<dl v-for="group in declared(row)" :key="group.key" class="mb-1 text-caption">
<dt class="text-fg-subtle">{{ group.label }}</dt>
<dd v-for="item in group.items" :key="item.name"><span class="font-mono">{{ item.name }}</span><span v-if="item.description" class="text-fg-subtle"> {{ item.description }}</span></dd>
</dl>
</template>
<template #cell-path="{ row }"><span class="font-mono text-caption [overflow-wrap:anywhere]">{{ row.path || row.url }}</span></template>
<template #cell-egress="{ row }"><span class="font-mono text-caption">{{ (row.egress ?? []).join(", ") }}</span></template>
<template #actions="{ row }">
<MoreMenu :label="`${row.name} actions`">
<DropdownMenuItem v-if="!row.managed" @select="open(row)">Edit</DropdownMenuItem>
<DropdownMenuItem class="text-danger" @select="removing = row">Remove</DropdownMenuItem>
</MoreMenu>
</template>
<template #empty><Empty><EmptyHeader><EmptyTitle>No {{ noun }}s</EmptyTitle></EmptyHeader></Empty></template>
</DataTable>
</template>
<Dialog v-model:open="editing">
<DialogContent class="max-h-[90dvh] overflow-y-auto sm:max-w-2xl">
<DialogHeader><DialogTitle>{{ isNew ? `Add ${noun}` : `Edit ${form.name}` }}</DialogTitle></DialogHeader>
<form :id="`extension-${kind}`" @submit.prevent="submit">
<SettingRow v-if="isNew" label="Name" for="ext-name"><Input id="ext-name" v-model="form.name" pattern="[a-z0-9][a-z0-9-]*" required /></SettingRow>
<SettingRow label="Path" for="ext-path" hint="The binary on this host."><Input id="ext-path" v-model="form.path" class="font-mono" :required="!mcp" /></SettingRow>
<SettingRow label="SHA-256" for="ext-sha" hint="It runs only while the binary has this digest."><Input id="ext-sha" v-model="form.sha256" class="font-mono" :required="!mcp" /></SettingRow>
<template v-if="mcp">
<SettingRow label="URL" for="ext-url" hint="For a server reached over HTTP instead of run from a path."><Input id="ext-url" v-model="form.url" type="url" /></SettingRow>
<SettingRow label="Arguments" for="ext-args" hint="One per line."><Textarea id="ext-args" v-model="form.args" class="font-mono" rows="2" /></SettingRow>
<SettingRow label="Tools" for="ext-tools" hint="The tools it may offer, as JSON: name, kind, read_only, reversibility, summary."><Textarea id="ext-tools" v-model="form.tools" class="font-mono" rows="5" /></SettingRow>
</template>
<SettingRow v-if="mcp" label="Effects" for="ext-effects" hint="Chat offers a server only once this says its tools change no privileges and access no secrets.">
<Select v-model="form.effects">
<SelectTrigger id="ext-effects" class="w-full"><SelectValue /></SelectTrigger>
<SelectContent><SelectItem v-for="o in EFFECT_OPTIONS" :key="o.value" :value="o.value">{{ o.label }}</SelectItem></SelectContent>
</Select>
</SettingRow>
<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="form.settings[field.key]">
<SelectTrigger :id="`ext-set-${field.key}`" class="w-full"><SelectValue /></SelectTrigger>
<SelectContent><SelectItem v-for="o in field.options" :key="o" :value="o">{{ o }}</SelectItem></SelectContent>
</Select>
<Input v-else :id="`ext-set-${field.key}`" v-model="form.settings[field.key]" :required="field.required" :placeholder="field.secret ? 'engine:key' : undefined" />
</SettingRow>
<SettingRow :label="schema?.length ? 'Other settings' : 'Settings'" for="ext-settings" hint="key=value, one per line. A key ending in _ref takes engine:key."><Textarea id="ext-settings" v-model="form.other" class="font-mono" rows="3" /></SettingRow>
<SettingRow label="Credentials" for="ext-creds" hint="slot=credential, one per line."><Textarea id="ext-creds" v-model="form.credentials" class="font-mono" rows="2" /></SettingRow>
<SettingRow label="Egress" for="ext-egress" hint="Hosts it may reach, one per line."><Textarea id="ext-egress" v-model="form.egress" class="font-mono" rows="2" /></SettingRow>
<SettingRow label="Environment" for="ext-env" hint="Host variables it may see, one per line."><Textarea id="ext-env" v-model="form.env" class="font-mono" rows="2" /></SettingRow>
<p v-if="actionError" role="alert" class="pt-2 text-caption text-danger">{{ actionError }}</p>
</form>
<DialogFooter><Button type="submit" :form="`extension-${kind}`" :disabled="busy">{{ isNew ? "Accept and start" : "Save and restart" }}</Button></DialogFooter>
</DialogContent>
</Dialog>
<AlertDialog :open="!!removing" @update:open="(o) => { if (!o) removing = null; }">
<AlertDialogContent>
<AlertDialogHeader><AlertDialogTitle>Stop and remove {{ removing?.name }}?</AlertDialogTitle></AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction :disabled="busy" @click="remove">Remove</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</template>
+240 -141
View File
@@ -4,7 +4,7 @@ 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, watch } from "vue";
import { ChevronRight, Plus, Settings2, Trash2 } from "@lucide/vue";
import { ChevronRight, Pencil, Plus, Settings2, Trash2 } from "@lucide/vue";
import PageHeader from "@/base/PageHeader.vue";
import {
@@ -21,9 +21,11 @@ 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 { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { Input } from "@/components/ui/input";
import { Badge } from "@/components/ui/badge";
import { MoreMenu } from "@/components/ui/more-menu";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { SettingRow } from "@/components/ui/setting-row";
import { Switch } from "@/components/ui/switch";
@@ -31,16 +33,20 @@ import { Section } from "@/components/ui/section";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Textarea } from "@/components/ui/textarea";
import { grants, stage, useExtensionsStore } from "@/stores/extensions";
import { api, type Extension, type SettingField } from "@/lib/api";
import { useOrgStore } from "@/stores/org";
import { api, type Extension, type ExtensionScope, type SettingField } from "@/lib/api";
import { useRead } from "@/lib/use-read";
import { fromLines, toLines } from "@/lib/lines";
import ExtensionList from "./ExtensionList.vue";
import { stateTone } from "@/runs/state";
import InstallationDialog from "./InstallationDialog.vue";
import PackageList from "./PackageList.vue";
import ExtensionsMarketplace from "./ExtensionsMarketplace.vue";
const store = useExtensionsStore();
const org = useOrgStore();
const loading = ref(true);
onMounted(async () => {
await store.load();
await Promise.all([store.load(), org.loadOrg()]);
loading.value = false;
});
@@ -48,6 +54,17 @@ onMounted(async () => {
// catalogue pins a different digest than the one installed.
const updates = computed(() => new Map(store.catalogue.filter((entry) => entry.update_available).map((entry) => [entry.name, entry])));
// A new installation may be owned by the instance when the caller administers
// it, by their organisation when they own it, and always by themselves.
const scopes = computed<ExtensionScope[]>(() => {
const out: ExtensionScope[] = [];
if (org.instanceAdmin) out.push("instance");
if (org.org?.role === "owner") out.push("org");
out.push("person");
return out;
});
const scopeLabels: Record<ExtensionScope, string> = { instance: "Instance", org: "Organisation", person: "Person" };
const sourceLocation = ref("");
const sourceKey = ref("");
watch(
@@ -65,10 +82,10 @@ async function saveSource(): Promise<void> {
}
}
// Credentials a declared slot may resolve through.
// Credentials a declared slot may resolve through at the instance scope.
const credentials = useRead(() => api.credentials());
onMounted(credentials.reload);
const credentialNames = computed(() => (credentials.data.value ?? []).map((c) => c.name));
const instanceCredentials = computed(() => (credentials.data.value ?? []).filter((c) => c.scope === "instance").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.
@@ -91,6 +108,41 @@ async function accept(): Promise<void> {
});
}
// A managed package's instance installation changes through its lifecycle
// routes; every other installation changes through its own configuration.
const managedInstance = (extension: Extension) => extension.editable && extension.managed === true && extension.scope === "instance";
const installation = ref<Extension | null>(null);
const installationOpen = ref(false);
function openInstallation(extension: Extension | null = null): void {
installation.value = extension;
installationOpen.value = true;
}
async function reload(): Promise<void> {
await store.load();
}
async function setEnabled(extension: Extension, enabled: boolean): Promise<void> {
await store.updateInstallation(extension.id, {
settings: extension.settings,
egress: extension.egress,
env: extension.env,
credentials: extension.credentials,
args: extension.args ?? [],
url: extension.url ?? "",
tools: extension.tools ?? [],
enabled,
});
}
async function overrideInstallation(extension: Extension, scope: "org" | "person", off: boolean): Promise<void> {
await store.overrideInstallation(extension.id, scope, off);
}
function overrideScope(extension: Extension, scope: ExtensionScope, off: boolean): Promise<void> {
return scope === "org" || scope === "person" ? overrideInstallation(extension, scope, off) : Promise.resolve();
}
const editing = ref<Extension | null>(null);
const settingsOpen = ref(false);
const schema = ref<SettingField[]>([]);
@@ -114,9 +166,17 @@ async function saveSettings(): Promise<void> {
}
const removing = ref<Extension | null>(null);
const removeOpen = ref(false);
const removePackage = ref(false);
function askRemove(extension: Extension): void {
removing.value = extension;
// An instance installation is what makes the package usable, so removing it
// removes the package too. A narrower installation is its own configuration.
removePackage.value = extension.scope === "instance";
}
async function remove(): Promise<void> {
if (removing.value) await store.remove(removing.value.name);
if (!removing.value) return;
if (removePackage.value) await store.remove(removing.value.name);
else await store.removeInstallation(removing.value.id);
}
const tones = {
@@ -125,11 +185,11 @@ const tones = {
enabled: { tone: undefined, label: "" },
} as const;
// Path-accepted packages keep their editor: one tab lists each kind.
// Packages are accepted per kind; the tab lists one kind at a time.
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 }[] }>();
const byGroup = new Map<string, { id: string; label: string; kinds: { kind: string; label: string; singular: string; contract: 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);
@@ -147,125 +207,178 @@ const active = computed(() => (kinds.data.value ?? []).find((kind) => kind.kind
<Alert v-if="store.error" variant="destructive" class="mb-4"><AlertDescription>{{ store.error }}</AlertDescription></Alert>
<Tabs default-value="installed" class="space-y-4">
<Tabs default-value="installations" class="space-y-4">
<TabsList>
<TabsTrigger value="installed">Installed</TabsTrigger>
<TabsTrigger value="installations">Installations</TabsTrigger>
<TabsTrigger value="packages">Packages</TabsTrigger>
<TabsTrigger value="marketplace">Marketplace</TabsTrigger>
<TabsTrigger value="path">By path</TabsTrigger>
</TabsList>
<TabsContent value="installed">
<TabsContent value="installations">
<Section>
<ItemGroup aria-label="Extensions">
<Item v-for="extension in store.extensions" :key="extension.name" as="li" variant="outline">
<div class="min-w-0 w-full @3xl:w-auto @3xl:flex-1">
<p class="truncate text-label font-medium">
{{ extension.display_name || extension.name }}
<span class="font-mono text-caption text-fg-subtle">{{ extension.version }}</span>
</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
<div class="mb-2 flex justify-end">
<Button size="icon-sm" variant="ghost" aria-label="New installation" title="New installation" @click="openInstallation()"><Plus /></Button>
</div>
<ItemGroup aria-label="Installations">
<Item v-for="extension in store.extensions" :key="extension.id" as="li" variant="outline">
<div class="min-w-0 w-full @3xl:w-auto @3xl:flex-1">
<p class="truncate text-label font-medium">
{{ extension.display_name || extension.name }}
<span class="font-mono text-caption text-fg-subtle">{{ extension.version }}</span>
</p>
<p v-if="extension.package !== extension.name" class="truncate font-mono text-caption text-fg-subtle">{{ extension.package }}</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">
<ChevronRight class="transition-transform group-data-[state=open]/button:rotate-90" />
Accepted authority
</Button>
</CollapsibleTrigger>
<CollapsibleContent>
<ul class="font-mono text-caption text-fg-subtle">
<li v-for="line in grants(extension.accepted)" :key="line">{{ line }}</li>
</ul>
</CollapsibleContent>
</Collapsible>
</div>
<Badge variant="outline">{{ scopeLabels[extension.scope] }}</Badge>
<Badge v-if="extension.overridden" variant="idle">Switched off</Badge>
<Badge v-if="tones[stage(extension)].tone" :variant="tones[stage(extension)].tone">{{ tones[stage(extension)].label }}</Badge>
<Badge :variant="stateTone(extension.state === 'running' ? 'succeeded' : extension.state)" :title="extension.error || undefined">{{ extension.state }}</Badge>
<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((line) => !line.startsWith('network:'))" :key="line">{{ line }}</li>
</ul>
<Button v-if="managedInstance(extension)" size="sm" class="mt-2" :disabled="!!store.busy" @click="store.approveUpdate(extension.name)">Approve</Button>
</Card>
<Button
v-if="managedInstance(extension) && updates.has(extension.name) && !extension.pending"
variant="outline"
size="sm"
:disabled="!!store.busy"
@click="store.update(extension.name)"
>Update to {{ updates.get(extension.name)?.version }}</Button
>
<Switch
v-if="managedInstance(extension)"
:model-value="extension.update_policy === 'auto'"
:disabled="!!store.busy"
:aria-label="`Auto-update ${extension.name}`"
@update:model-value="(value: boolean) => store.setUpdatePolicy(extension.name, value ? 'auto' : 'manual')"
/>
<Button v-if="managedInstance(extension) && extension.can_rollback" variant="ghost" size="sm" :disabled="!!store.busy" @click="store.rollback(extension.name)"
>Roll back</Button
>
<Button
v-if="managedInstance(extension) && stage(extension) === 'accept'"
variant="ghost"
size="sm"
:disabled="!!store.busy"
@click="openAccept(extension)"
>Review authority</Button
>
<Switch
v-if="extension.editable && !managedInstance(extension)"
:model-value="!!extension.enabled"
:disabled="!!store.busy"
:aria-label="`Enable ${extension.name}`"
@update:model-value="(value: boolean) => setEnabled(extension, value)"
/>
<Switch
v-if="managedInstance(extension) && stage(extension) !== 'accept'"
: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.editable">
<TooltipTrigger as-child>
<Button
variant="ghost"
size="icon"
:aria-label="`Edit ${extension.name}`"
:disabled="!!store.busy"
@click="managedInstance(extension) ? openSettings(extension) : openInstallation(extension)"
>
<Settings2 v-if="managedInstance(extension)" /><Pencil v-else />
</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">
<ChevronRight class="transition-transform group-data-[state=open]/button:rotate-90" />
Accepted authority
</Button>
</CollapsibleTrigger>
<CollapsibleContent>
<ul class="font-mono text-caption text-fg-subtle">
<li v-for="line in grants(extension.accepted)" :key="line">{{ line }}</li>
</ul>
</CollapsibleContent>
</Collapsible>
</div>
<Badge v-if="tones[stage(extension)].tone" :variant="tones[stage(extension)].tone">{{ tones[stage(extension)].label }}</Badge>
<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((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>
<Button
v-if="updates.has(extension.name) && !extension.pending"
variant="outline"
size="sm"
:disabled="!!store.busy"
@click="store.update(extension.name)"
>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}`"
@update:model-value="(value: boolean) => store.setUpdatePolicy(extension.name, value ? 'auto' : 'manual')"
/>
<Button v-if="extension.can_rollback" variant="ghost" size="sm" :disabled="!!store.busy" @click="store.rollback(extension.name)"
>Roll back</Button
>
<Button
v-if="stage(extension) === 'accept'"
variant="ghost"
size="sm"
:disabled="!!store.busy"
@click="openAccept(extension)"
>Review authority</Button
>
<Switch
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
variant="ghost"
size="icon"
:aria-label="`Remove ${extension.name}`"
:disabled="!!store.busy"
@click="(removing = extension), (removeOpen = true)"
><Trash2
/></Button>
</TooltipTrigger>
<TooltipContent>Remove</TooltipContent>
</Tooltip>
</Item>
<li v-if="loading" class="py-3 text-label text-fg-muted" role="status">Loading extensions…</li>
<li v-else-if="!store.extensions.length && !store.error">
<Empty class="py-6">
<EmptyHeader>
<EmptyTitle>Nothing installed</EmptyTitle>
</EmptyHeader>
</Empty>
</li>
</ItemGroup>
</TooltipTrigger>
<TooltipContent>{{ managedInstance(extension) ? "Settings" : "Edit" }}</TooltipContent>
</Tooltip>
<MoreMenu
v-if="!extension.editable && ((extension.overridden_by?.length ?? 0) > 0 || (extension.can_override?.length ?? 0) > 0)"
:label="`${extension.name} use`"
>
<template v-for="scope in extension.overridden_by ?? []" :key="`restore-${scope}`">
<DropdownMenuItem @select="overrideScope(extension, scope, false)"
>Use again {{ scope === 'org' ? 'for the organisation' : 'for me' }}</DropdownMenuItem
>
</template>
<template v-for="scope in extension.can_override ?? []" :key="`off-${scope}`">
<DropdownMenuItem v-if="!(extension.overridden_by?.length)" @select="overrideScope(extension, scope, true)"
>Switch off {{ scope === 'org' ? 'for the organisation' : 'for me' }}</DropdownMenuItem
>
</template>
</MoreMenu>
<Tooltip v-if="extension.editable">
<TooltipTrigger as-child>
<Button
variant="ghost"
size="icon"
:aria-label="`Remove ${extension.name}`"
:disabled="!!store.busy"
@click="askRemove(extension)"
><Trash2
/></Button>
</TooltipTrigger>
<TooltipContent>Remove</TooltipContent>
</Tooltip>
</Item>
<li v-if="loading" class="py-3 text-label text-fg-muted" role="status">Loading installations…</li>
<li v-else-if="!store.extensions.length && !store.error">
<Empty class="py-6">
<EmptyHeader>
<EmptyTitle>Nothing installed</EmptyTitle>
</EmptyHeader>
</Empty>
</li>
</ItemGroup>
</Section>
</TabsContent>
<TabsContent value="packages">
<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>
<PackageList :key="active.kind" :kind="active.kind" :contract="active.contract" :noun="active.singular" />
</template>
</TabsContent>
<TabsContent value="marketplace">
<Collapsible class="mb-3" default-open>
<CollapsibleTrigger class="cursor-pointer text-caption text-fg-muted">Catalogue source</CollapsibleTrigger>
@@ -280,25 +393,10 @@ const active = computed(() => (kinds.data.value ?? []).find((kind) => kind.kind
<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>
<InstallationDialog v-model:open="installationOpen" :extension="installation" :packages="store.packages" :scopes="scopes" @saved="reload" />
<AlertDialog v-model:open="acceptOpen">
<AlertDialogContent>
<AlertDialogHeader>
@@ -313,7 +411,7 @@ const active = computed(() => (kinds.data.value ?? []).find((kind) => kind.kind
<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>
<SelectItem v-for="name in instanceCredentials" :key="name" :value="name">{{ name }}</SelectItem>
</SelectContent>
</Select>
</div>
@@ -343,11 +441,12 @@ const active = computed(() => (kinds.data.value ?? []).find((kind) => kind.kind
</DialogContent>
</Dialog>
<AlertDialog v-model:open="removeOpen">
<AlertDialog :open="!!removing" @update:open="(value) => { if (!value) removing = null; }">
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Remove {{ removing?.name }}?</AlertDialogTitle>
<AlertDialogDescription>Its process stops.</AlertDialogDescription>
<AlertDialogDescription v-if="removePackage">Its process stops and the package is no longer accepted.</AlertDialogDescription>
<AlertDialogDescription v-else>Its process stops and its configuration is deleted. The package stays accepted.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
+173
View File
@@ -0,0 +1,173 @@
<script setup lang="ts">
import { computed, onMounted, ref, watch } from "vue";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { SettingRow } from "@/components/ui/setting-row";
import { Switch } from "@/components/ui/switch";
import { Textarea } from "@/components/ui/textarea";
import { errors } from "@/copy/errors";
import { api, describeError, type Extension, type ExtensionScope, type InstallationInput, type InstallationUpdate, type PackageView, type SettingField } from "@/lib/api";
import { fromLines, toLines } from "@/lib/lines";
import { useRead } from "@/lib/use-read";
/** One installation's configuration. A new installation names the accepted
* package and the scope that owns it; an existing one changes only its
* settings, grants and state. */
const props = defineProps<{
extension: Extension | null;
packages: PackageView[];
scopes: ExtensionScope[];
}>();
const open = defineModel<boolean>("open", { required: true });
const emit = defineEmits<{ saved: [] }>();
const credentials = useRead(() => api.credentials());
onMounted(credentials.reload);
const creating = computed(() => !props.extension);
const schema = computed<SettingField[]>(() => props.extension?.settings_schema ?? []);
const selected = computed(() => props.packages.find((p) => p.name === packageName.value));
const contract = computed(() => props.extension?.contract ?? selected.value?.contract ?? "");
const isMCP = computed(() => contract.value === "mcp");
const scope = ref<ExtensionScope>("person");
const packageName = ref("");
const name = ref("");
const settings = ref<Record<string, string>>({});
const other = ref("");
const credentialSlots = ref("");
const egress = ref("");
const env = ref("");
const args = ref("");
const url = ref("");
const tools = ref("[]");
const enabled = ref(true);
const busy = ref(false);
const actionError = ref("");
/** The credentials this installation may name: the instance's, plus its own
* scope's. The server returns only the caller's organisation and person, so
* the scope is enough to tell them apart. */
const credentialNames = computed(() =>
(credentials.data.value ?? [])
.filter((c) => c.scope === "instance" || c.scope === scope.value)
.map((c) => c.name),
);
// A dialog's action closes it before its click handler runs, so the target
// outlives the open flag rather than being reset on close.
watch(open, (value) => {
if (value) reset();
});
function reset(): void {
const e = props.extension;
const known = new Set((e?.settings_schema ?? []).map((field) => field.key));
settings.value = Object.fromEntries(Object.entries(e?.settings ?? {}).filter(([key]) => known.has(key)));
other.value = toLines(Object.fromEntries(Object.entries(e?.settings ?? {}).filter(([key]) => !known.has(key))));
credentialSlots.value = toLines(e?.credentials ?? {});
egress.value = (e?.egress ?? []).join("\n");
env.value = (e?.env ?? []).join("\n");
args.value = (e?.args ?? []).join("\n");
url.value = e?.url ?? "";
tools.value = e?.tools ? JSON.stringify(e.tools, null, 2) : "[]";
enabled.value = e?.enabled ?? true;
packageName.value = e?.package ?? props.packages.find((p) => p.installed)?.name ?? "";
scope.value = "person";
name.value = "";
actionError.value = "";
}
const list = (text: string) => text.split("\n").map((line) => line.trim()).filter(Boolean);
async function submit(): Promise<void> {
busy.value = true;
actionError.value = "";
try {
const body: InstallationUpdate = {
settings: { ...fromLines(other.value), ...Object.fromEntries(Object.entries(settings.value).filter(([, value]) => value !== "")) },
credentials: fromLines(credentialSlots.value),
egress: list(egress.value),
env: list(env.value),
enabled: enabled.value,
};
if (isMCP.value) {
body.url = url.value.trim();
body.args = list(args.value);
body.tools = JSON.parse(tools.value || "[]");
}
if (props.extension) {
await api.updateInstallation(props.extension.id, body);
} else {
const create: InstallationInput = { package: packageName.value, scope: scope.value, ...body };
if (name.value.trim()) create.name = name.value.trim();
await api.createInstallation(create);
}
emit("saved");
open.value = false;
} catch (cause) {
actionError.value = cause instanceof SyntaxError ? `Tools: ${cause.message}` : describeError(cause, errors.common.unknown);
} finally {
busy.value = false;
}
}
</script>
<template>
<Dialog v-model:open="open">
<DialogContent class="max-h-[90dvh] overflow-y-auto sm:max-w-2xl">
<DialogHeader><DialogTitle>{{ creating ? "New installation" : `Edit ${extension?.name}` }}</DialogTitle></DialogHeader>
<form id="installation-form" @submit.prevent="submit">
<SettingRow v-if="creating" label="Package" for="installation-package">
<Select v-model="packageName">
<SelectTrigger id="installation-package" class="w-full"><SelectValue placeholder="Accepted package" /></SelectTrigger>
<SelectContent>
<SelectItem v-for="pkg in packages.filter((p) => p.installed)" :key="pkg.name" :value="pkg.name">
{{ pkg.display_name || pkg.name }}<span v-if="pkg.display_name" class="text-fg-subtle"> ({{ pkg.name }})</span>
</SelectItem>
</SelectContent>
</Select>
</SettingRow>
<SettingRow v-else label="Package" for="installation-package-name">{{ extension?.package }}</SettingRow>
<SettingRow v-if="creating" label="Scope" for="installation-scope" hint="Who owns the installation and its configuration.">
<Select v-model="scope">
<SelectTrigger id="installation-scope" class="w-full"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem v-for="value in scopes" :key="value" :value="value">{{ value === "org" ? "Organisation" : value === "instance" ? "Instance" : "Person" }}</SelectItem>
</SelectContent>
</Select>
</SettingRow>
<SettingRow v-if="creating" label="Name" for="installation-name" hint="What a binding calls it. Default: the package's name.">
<Input id="installation-name" v-model="name" pattern="[a-z0-9][a-z0-9-]*" :placeholder="selected?.name" />
</SettingRow>
<template v-if="isMCP">
<SettingRow label="URL" for="installation-url" hint="For a server reached over HTTP instead of run from a path."><Input id="installation-url" v-model="url" type="url" /></SettingRow>
<SettingRow label="Arguments" for="installation-args" hint="One per line."><Textarea id="installation-args" v-model="args" class="font-mono" rows="2" /></SettingRow>
<SettingRow label="Tools" for="installation-tools" hint="The tools it may offer, as JSON: name, kind, read_only, reversibility, summary.">
<Textarea id="installation-tools" v-model="tools" class="font-mono" rows="5" />
</SettingRow>
</template>
<SettingRow v-for="field in schema" :key="field.key" :label="field.label || field.key" :for="`installation-set-${field.key}`" :hint="field.description">
<Select v-if="field.options?.length" v-model="settings[field.key]">
<SelectTrigger :id="`installation-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="`installation-set-${field.key}`" v-model="settings[field.key]" :required="field.required" :placeholder="field.secret ? 'engine:key' : undefined" />
</SettingRow>
<SettingRow :label="schema.length ? 'Other settings' : 'Settings'" for="installation-settings" hint="key=value, one per line. A key ending in _ref takes engine:key.">
<Textarea id="installation-settings" v-model="other" class="font-mono" rows="3" />
</SettingRow>
<SettingRow label="Credentials" for="installation-credentials" hint="slot=credential, one per line.">
<Textarea id="installation-credentials" v-model="credentialSlots" class="font-mono" rows="2" :placeholder="credentialNames.join('\n')" />
</SettingRow>
<SettingRow label="Egress" for="installation-egress" hint="Hosts it may reach, one per line."><Textarea id="installation-egress" v-model="egress" class="font-mono" rows="2" /></SettingRow>
<SettingRow label="Environment" for="installation-env" hint="Host variables it may see, one per line."><Textarea id="installation-env" v-model="env" class="font-mono" rows="2" /></SettingRow>
<SettingRow label="Run" for="installation-enabled" hint="Start it when it is saved."><Switch id="installation-enabled" v-model="enabled" /></SettingRow>
<p v-if="actionError" role="alert" class="pt-2 text-caption text-danger">{{ actionError }}</p>
</form>
<DialogFooter><Button type="submit" form="installation-form" :disabled="busy || (creating && !packageName)">{{ creating ? "Install" : "Save and restart" }}</Button></DialogFooter>
</DialogContent>
</Dialog>
</template>
+175
View File
@@ -0,0 +1,175 @@
<script setup lang="ts">
import { Plus } from "@lucide/vue";
import { computed, onMounted, ref } from "vue";
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { Input } from "@/components/ui/input";
import { MoreMenu } from "@/components/ui/more-menu";
import { ReadError } from "@/components/ui/read-error";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { SettingRow } from "@/components/ui/setting-row";
import { Skeleton } from "@/components/ui/skeleton";
import { Textarea } from "@/components/ui/textarea";
import { errors } from "@/copy/errors";
import { api, describeError, type ExtensionInput, type ExtensionKind, type PackageView } from "@/lib/api";
import { useRead } from "@/lib/use-read";
import { fromLines } from "@/lib/lines";
/** The packages of one contract the instance accepted: each is accepted by
* path and digest, and runs only while its digest matches. */
const props = defineProps<{ kind: ExtensionKind; contract: string; noun: string }>();
const { data, error, reload } = useRead(() => api.packages());
onMounted(reload);
const rows = computed(() => (data.value ?? []).filter((pkg) => pkg.contract === props.contract));
const columns = computed<DataTableColumn<PackageView>[]>(() => [
{ id: "name", label: "Package", fixed: true, sort: (pkg) => pkg.name },
{ id: "version", label: "Version", hide: "sm", width: "8rem", sort: (pkg) => pkg.version ?? "" },
{ id: "managed", label: "Source", hide: "sm", width: "10rem" },
{ id: "digest", label: "Digest", hidden: true, hide: "md", width: "18rem" },
]);
const mcp = computed(() => props.contract === "mcp");
/** What an operator declares about an MCP server's tools. Chat offers a server
* only when its effects are declared and neither one applies. */
const EFFECT_OPTIONS = [
{ value: "unset", label: "Not declared", effects: undefined },
{ value: "none", label: "No privileged effects", effects: { privilege_change: false, secret_access: false } },
{ value: "privilege_change", label: "Changes privileges", effects: { privilege_change: true, secret_access: false } },
{ value: "secret_access", label: "Accesses secrets", effects: { privilege_change: false, secret_access: true } },
{ value: "both", label: "Changes privileges and accesses secrets", effects: { privilege_change: true, secret_access: true } },
] as const;
const editing = ref(false);
const form = ref({ name: "", path: "", sha256: "", url: "", args: "", egress: "", env: "", credentials: "", tools: "", effects: "unset", settings: "", other: "" });
function open(): void {
actionError.value = "";
form.value = { name: "", path: "", sha256: "", url: "", args: "", egress: "", env: "", credentials: "", tools: "[]", effects: "unset", settings: "", other: "" };
editing.value = true;
}
const list = (text: string) => text.split("\n").map((line) => line.trim()).filter(Boolean);
const busy = ref(false);
const actionError = ref("");
async function submit(): Promise<void> {
const f = form.value;
busy.value = true;
actionError.value = "";
try {
const body: ExtensionInput = {
path: f.path.trim() || undefined,
sha256: f.sha256.trim() || undefined,
egress: list(f.egress),
env: list(f.env),
settings: fromLines(f.settings),
credentials: fromLines(f.credentials),
};
if (mcp.value) {
body.url = f.url.trim() || undefined;
body.args = list(f.args);
body.tools = JSON.parse(f.tools || "[]");
body.effects = EFFECT_OPTIONS.find((option) => option.value === f.effects)?.effects;
}
await api.acceptExtension(props.kind, f.name.trim(), body);
editing.value = false;
} catch (cause) {
actionError.value = cause instanceof SyntaxError ? `Tools: ${cause.message}` : describeError(cause, errors.common.unknown);
} finally {
busy.value = false;
await reload();
}
}
const removing = ref<PackageView | null>(null);
async function remove(): Promise<void> {
if (!removing.value) return;
busy.value = true;
actionError.value = "";
try {
await api.removeExtension(props.kind, removing.value.name);
} catch (cause) {
actionError.value = describeError(cause, errors.common.unknown);
} finally {
removing.value = null;
busy.value = false;
await reload();
}
}
</script>
<template>
<div>
<p v-if="actionError && !editing" role="alert" class="mb-2 text-caption text-danger">{{ actionError }}</p>
<ReadError v-if="error" :message="error" retry-label="Retry" @retry="reload" />
<div v-else-if="!data" role="status" :aria-label="`Loading ${noun}s`" class="space-y-2"><Skeleton class="h-8 w-full" /></div>
<template v-else>
<div class="mb-2 flex justify-end">
<Button size="icon-sm" variant="ghost" :aria-label="`Accept ${noun}`" :title="`Accept ${noun}`" @click="open()"><Plus /></Button>
</div>
<DataTable :columns="columns" :rows="rows" :row-key="(pkg) => pkg.name" :storage-key="`packages-${kind}`">
<template #cell-name="{ row }">
<span class="font-medium">{{ row.display_name || row.name }}</span>
<span v-if="row.display_name" class="font-mono text-caption text-fg-subtle"> {{ row.name }}</span>
</template>
<template #cell-version="{ row }">{{ row.version || "–" }}</template>
<template #cell-managed="{ row }">
<Badge :variant="row.managed ? 'outline' : 'idle'">{{ row.managed ? "Catalogue" : "By path" }}</Badge>
</template>
<template #cell-digest="{ row }"><span class="font-mono text-caption [overflow-wrap:anywhere]">{{ row.digest }}</span></template>
<template #actions="{ row }">
<MoreMenu :label="`${row.name} actions`">
<DropdownMenuItem class="text-danger" @select="removing = row">Remove</DropdownMenuItem>
</MoreMenu>
</template>
<template #empty><Empty><EmptyHeader><EmptyTitle>No {{ noun }}s</EmptyTitle></EmptyHeader></Empty></template>
</DataTable>
</template>
<Dialog v-model:open="editing">
<DialogContent class="max-h-[90dvh] overflow-y-auto sm:max-w-2xl">
<DialogHeader><DialogTitle>Accept {{ noun }}</DialogTitle></DialogHeader>
<form :id="`package-${kind}`" @submit.prevent="submit">
<SettingRow label="Name" for="package-name"><Input id="package-name" v-model="form.name" pattern="[a-z0-9][a-z0-9-]*" required /></SettingRow>
<SettingRow label="Path" for="package-path" hint="The binary on this host."><Input id="package-path" v-model="form.path" class="font-mono" :required="!mcp" /></SettingRow>
<SettingRow label="SHA-256" for="package-sha" hint="It runs only while the binary has this digest."><Input id="package-sha" v-model="form.sha256" class="font-mono" :required="!mcp" /></SettingRow>
<template v-if="mcp">
<SettingRow label="URL" for="package-url" hint="For a server reached over HTTP instead of run from a path."><Input id="package-url" v-model="form.url" type="url" /></SettingRow>
<SettingRow label="Arguments" for="package-args" hint="One per line."><Textarea id="package-args" v-model="form.args" class="font-mono" rows="2" /></SettingRow>
<SettingRow label="Tools" for="package-tools" hint="The tools it may offer, as JSON: name, kind, read_only, reversibility, summary."><Textarea id="package-tools" v-model="form.tools" class="font-mono" rows="5" /></SettingRow>
<SettingRow label="Effects" for="package-effects" hint="Chat offers a server only once this says its tools change no privileges and access no secrets.">
<Select v-model="form.effects">
<SelectTrigger id="package-effects" class="w-full"><SelectValue /></SelectTrigger>
<SelectContent><SelectItem v-for="option in EFFECT_OPTIONS" :key="option.value" :value="option.value">{{ option.label }}</SelectItem></SelectContent>
</Select>
</SettingRow>
</template>
<SettingRow label="Settings" for="package-settings" hint="key=value, one per line. A key ending in _ref takes engine:key."><Textarea id="package-settings" v-model="form.settings" class="font-mono" rows="3" /></SettingRow>
<SettingRow label="Credentials" for="package-credentials" hint="slot=credential, one per line."><Textarea id="package-credentials" v-model="form.credentials" class="font-mono" rows="2" /></SettingRow>
<SettingRow label="Egress" for="package-egress" hint="Hosts it may reach, one per line."><Textarea id="package-egress" v-model="form.egress" class="font-mono" rows="2" /></SettingRow>
<SettingRow label="Environment" for="package-env" hint="Host variables it may see, one per line."><Textarea id="package-env" v-model="form.env" class="font-mono" rows="2" /></SettingRow>
<p v-if="actionError" role="alert" class="pt-2 text-caption text-danger">{{ actionError }}</p>
</form>
<DialogFooter><Button type="submit" :form="`package-${kind}`" :disabled="busy">Accept and start</Button></DialogFooter>
</DialogContent>
</Dialog>
<AlertDialog :open="!!removing" @update:open="(value) => { if (!value) removing = null; }">
<AlertDialogContent>
<AlertDialogHeader><AlertDialogTitle>Remove {{ removing?.name }}?</AlertDialogTitle></AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction :disabled="busy" @click="remove">Remove</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
</template>
+18 -3
View File
@@ -2,9 +2,9 @@ import { defineStore } from "pinia";
import { ref } from "vue";
import { errors } from "@/copy/errors";
import { api, describeError, type CatalogueEntry, type CatalogueSourceView, type Extension, type ExtensionGrantsInput, type Grants, type SettingField } from "@/lib/api";
import { api, describeError, type CatalogueEntry, type CatalogueSourceView, type Extension, type ExtensionGrantsInput, type Grants, type InstallationInput, type InstallationUpdate, type PackageView, type SettingField } from "@/lib/api";
export type { CatalogueEntry, Extension } from "@/lib/api";
export type { CatalogueEntry, Extension, PackageView } from "@/lib/api";
/** One setting a package declares. */
export type ExtensionSettingSpec = SettingField;
@@ -29,6 +29,7 @@ export function stage(extension: Extension): "accept" | "disabled" | "enabled" {
export const useExtensionsStore = defineStore("extensions", () => {
const extensions = ref<Extension[]>([]);
const packages = ref<PackageView[]>([]);
const catalogue = ref<CatalogueEntry[]>([]);
const source = ref<CatalogueSourceView>({ configured: false });
const catalogueError = ref("");
@@ -44,6 +45,14 @@ export const useExtensionsStore = defineStore("extensions", () => {
}
}
async function loadPackages(): Promise<void> {
try {
packages.value = await api.packages();
} catch (cause) {
error.value = describeError(cause, errors.common.unknown);
}
}
async function loadSource(): Promise<void> {
try {
source.value = await api.catalogueSource();
@@ -53,7 +62,7 @@ export const useExtensionsStore = defineStore("extensions", () => {
}
async function load(): Promise<void> {
await Promise.all([loadInstalled(), loadSource()]);
await Promise.all([loadInstalled(), loadPackages(), loadSource()]);
// The catalogue is remote; its failure leaves the installed list usable.
try {
catalogue.value = await api.catalogue();
@@ -81,6 +90,7 @@ export const useExtensionsStore = defineStore("extensions", () => {
return {
extensions,
packages,
catalogue,
source,
catalogueLoaded,
@@ -89,7 +99,12 @@ export const useExtensionsStore = defineStore("extensions", () => {
busy,
load,
loadInstalled,
loadPackages,
loadSource,
createInstallation: (body: InstallationInput) => mutate("new-installation", () => api.createInstallation(body)),
updateInstallation: (id: string, body: InstallationUpdate) => mutate(id, () => api.updateInstallation(id, body)),
removeInstallation: (id: string) => mutate(id, () => api.removeInstallation(id)),
overrideInstallation: (id: string, scope: "org" | "person", off: boolean) => mutate(id, () => api.putInstallationOverride(id, scope, off)),
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)),