feat(controlplane): per-org model access, org aliases and org providers

The system org sets each org's allowed models and whether it may add its
own providers (org-model-policy); an org with no entry may use nothing.
An org's aliases and providers are checked against that policy on save
and filtered by it at resolution. Tasks get their org's providers, keyed
by the org's credential binding through the egress proxy. Org Settings
gains a Models tab; instance Models gains Org access.
This commit is contained in:
sam committed 2026-10-10 18:48:40 +11:00
1 parent ea52c8622e
commit 75b4eecfde
25 files changed
+1135 -516

No files matched your search

+98
View File
@@ -0,0 +1,98 @@
<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import { Plus, Trash2 } from "@lucide/vue";
import PageHeader from "@/base/PageHeader.vue";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { useControlPlaneStore } from "@/stores/control-plane";
import DraftHint from "@/settings/DraftHint.vue";
/**
* The org's own models: aliases over the instance's, and providers the
* instance admin lets it add. The server refuses a model the org may not use,
* and an org provider's key is the org's credential binding named after it.
*/
interface Provider {
class: string;
base_url?: string;
api_key_ref: { engine: string; key: string };
}
const store = useControlPlaneStore();
onMounted(() => store.load());
const aliases = computed(() => store.drafts["model-aliases"]?.value as Record<string, string> | undefined);
const providers = computed(() => store.drafts["provider-settings"]?.value as Record<string, Provider> | undefined);
const errors = computed(() => ["model-aliases", "provider-settings"].map((k) => store.pageErrorFor(k)).filter(Boolean));
const issue = (alias: string) => store.issuesFor("model-aliases").find((entry) => entry.path === alias);
function setAlias(alias: string, model: string) {
if (!aliases.value) return;
if (model.trim()) aliases.value[alias] = model.trim();
else delete aliases.value[alias];
}
const newAlias = ref("");
function addAlias() {
const name = newAlias.value.trim();
if (!aliases.value || !name || name in aliases.value) return;
aliases.value[name] = "";
newAlias.value = "";
}
const newProvider = ref("");
function addProvider() {
const name = newProvider.value.trim();
if (!providers.value || !name || providers.value[name]) return;
providers.value[name] = { class: "openai", api_key_ref: { engine: "", key: "" } };
newProvider.value = "";
}
const eyebrow = "mb-2 text-[11px] font-medium tracking-[0.06em] text-fg-subtle uppercase";
</script>
<template>
<div>
<PageHeader title="Models" />
<p v-for="e in errors" :key="String(e)" class="mb-4 text-sm text-danger" role="alert">{{ e }}</p>
<template v-if="aliases">
<h2 :class="eyebrow">Aliases</h2>
<div class="rounded-lg border border-border bg-card">
<div v-for="(model, alias) in aliases" :key="alias" class="flex flex-wrap items-center gap-3 border-b border-border px-4 py-2.5 last-of-type:border-b-0">
<label :for="`org-alias-${alias}`" class="w-28 font-mono text-sm font-medium">{{ alias }}</label>
<Input
:id="`org-alias-${alias}`"
:model-value="model"
class="max-w-md flex-1 font-mono"
placeholder="provider/model"
:aria-invalid="issue(String(alias)) ? true : undefined"
@update:model-value="(v) => setAlias(String(alias), String(v))"
/>
<DraftHint kind="model-aliases" :path="String(alias)" />
<span v-if="issue(String(alias))" class="text-xs text-danger">{{ issue(String(alias))?.message }}</span>
<Button variant="ghost" size="icon" class="ml-auto" :aria-label="`Remove alias ${alias}`" @click="delete aliases[alias]"><Trash2 /></Button>
</div>
<form class="flex gap-2 border-t border-border px-4 py-3" @submit.prevent="addAlias">
<Input v-model="newAlias" class="max-w-56 font-mono" placeholder="alias, e.g. default" aria-label="New alias" />
<Button type="submit" variant="outline" size="sm" :disabled="!newAlias.trim()"><Plus data-icon="inline-start" />Add alias</Button>
</form>
</div>
</template>
<template v-if="providers">
<h2 :class="[eyebrow, 'mt-10']">Providers</h2>
<div class="rounded-lg border border-border bg-card">
<div v-for="(provider, name) in providers" :key="name" class="flex flex-wrap items-center gap-3 border-b border-border px-4 py-2.5 last-of-type:border-b-0">
<span class="w-28 font-mono text-sm font-medium">{{ name }}</span>
<Input v-model="provider.class" class="w-36 font-mono" :aria-label="`Class for ${name}`" />
<Input v-model="provider.base_url" class="max-w-md flex-1 font-mono" placeholder="base URL (empty: class default)" :aria-label="`Base URL for ${name}`" />
<span class="text-xs text-fg-subtle">Key: credential binding "{{ name }}"</span>
<Button variant="ghost" size="icon" class="ml-auto" :aria-label="`Remove provider ${name}`" @click="delete providers[name]"><Trash2 /></Button>
</div>
<form class="flex gap-2 border-t border-border px-4 py-3" @submit.prevent="addProvider">
<Input v-model="newProvider" class="max-w-56 font-mono" placeholder="provider name" aria-label="New provider" />
<Button type="submit" variant="outline" size="sm" :disabled="!newProvider.trim()"><Plus data-icon="inline-start" />Add provider</Button>
</form>
</div>
</template>
</div>
</template>
+5 -1
View File
@@ -28,6 +28,7 @@ const TABS = [
{ path: "/org/workspaces", label: "Workspaces" },
{ path: "/org/access", label: "Access", home: true },
{ path: "/org/tokens", label: "Tokens", home: true },
{ path: "/org/models", label: "Models", home: true, member: true },
];
const route = useRoute();
@@ -37,7 +38,10 @@ const router = useRouter();
// hidden while an instance admin views another org rather than editing the
// wrong one.
const away = computed(() => !!org.value && org.value.id !== homeOrg.value);
const tabs = computed(() => TABS.filter((tab) => !(away.value && tab.home)));
// Models is an org's own; the system org configures models in Settings.
const tabs = computed(() =>
TABS.filter((tab) => !(away.value && tab.home) && !(tab.member && homeOrg.value === "org-sys")),
);
watch(away, (isAway) => {
if (isAway && TABS.some((tab) => tab.home && route.path.startsWith(tab.path))) {
void router.replace("/org");
+7
View File
@@ -11,6 +11,7 @@ import OrgAgentsPage from "@/org/OrgAgentsPage.vue";
import OrgWorkspacesPage from "@/org/OrgWorkspacesPage.vue";
import OrgAccessPage from "@/org/OrgAccessPage.vue";
import OrgTokensPage from "@/org/OrgTokensPage.vue";
import OrgModelsPage from "@/org/OrgModelsPage.vue";
import SchedulingPolicyPage from "@/settings/SchedulingPolicyPage.vue";
import ReviewSettingsPage from "@/settings/ReviewSettingsPage.vue";
import ToolsPage from "@/settings/ToolsPage.vue";
@@ -219,6 +220,12 @@ const routes = [
component: OrgTokensPage,
meta: { label: "Tokens", navPath: "/org" },
},
{
path: "models",
name: "org-models",
component: OrgModelsPage,
meta: { label: "Models", navPath: "/org" },
},
],
},
// Identities and access policies moved into Org; old bookmarks still resolve.
+50 -1
View File
@@ -16,6 +16,8 @@ import {
SelectValue,
} from "@/components/ui/select";
import { SettingRow } from "@/components/ui/setting-row";
import { Switch } from "@/components/ui/switch";
import { instanceAdmin, loadOrg, orgs } from "@/org/org";
import { resourcesForPage, useControlPlaneStore } from "@/stores/control-plane";
import DraftHint from "./DraftHint.vue";
import HistoryLink from "./HistoryLink.vue";
@@ -38,7 +40,7 @@ const CLASSES = ["openai", "anthropic", "azure", "cohere", "deepseek", "gemini",
const store = useControlPlaneStore();
const { catalog: resourceCatalog, catalogError } = storeToRefs(store);
onMounted(() => Promise.all([store.load(), loadConfig()]));
onMounted(() => Promise.all([store.load(), loadConfig(), loadOrg()]));
const resources = computed(() => resourcesForPage(resourceCatalog.value, "models"));
const providers = computed(() => store.drafts["provider-settings"]?.value as Record<string, Provider> | undefined);
@@ -117,6 +119,28 @@ function addProvider() {
}
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.drafts["org-model-policy"]?.value as Record<string, OrgPolicy> | undefined);
const otherOrgs = computed(() => (instanceAdmin.value ? orgs.value.filter((o) => o.id !== "org-sys") : []));
const providerWildcards = computed(() => configuredIds.value.map((id) => `${id}/*`));
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 };
if (!merged.allowed.length && !merged.own_providers) delete policies.value[id];
else policies.value[id] = 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 eyebrow = "mb-2 text-[11px] font-medium tracking-[0.06em] text-fg-subtle uppercase";
</script>
@@ -184,6 +208,31 @@ const eyebrow = "mb-2 text-[11px] font-medium tracking-[0.06em] text-fg-subtle u
</div>
</template>
<template v-if="policies && otherOrgs.length">
<h2 :class="[eyebrow, 'mt-10']">Org access</h2>
<datalist id="org-allowed">
<option v-for="m in [...providerWildcards, ...modelOptions]" :key="m" :value="m" />
</datalist>
<div class="rounded-lg border border-border bg-card">
<div v-for="o in otherOrgs" :key="o.id" class="flex flex-wrap items-center gap-3 border-b border-border px-4 py-2.5 last-of-type:border-b-0">
<span class="w-28 truncate text-sm font-medium" :title="o.id">{{ o.name }}</span>
<Input
:model-value="allowedText(o.id)"
list="org-allowed"
class="max-w-md flex-1 font-mono"
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-xs 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>
</div>
</template>
<template v-if="providers">
<h2 :class="[eyebrow, 'mt-10']">Providers</h2>
<datalist id="available-providers">
+3 -5
View File
@@ -106,10 +106,11 @@ const MODEL_ALIAS_NAME = /^[a-z0-9][a-z0-9._-]*$/;
/** validateModelAliases mirrors the server's validateModelAliases: alias
* names are lowercase tokens, each value splits on its first slash into a
* non-empty provider and model, and a non-empty table has a default alias. */
* non-empty provider and model. The instance table's default alias is
* checked on save by the server, which knows whose table it is. */
export function validateModelAliases(value: unknown): FieldIssue[] {
const aliases = (value ?? {}) as Record<string, string>;
const issues: FieldIssue[] = Object.entries(aliases).flatMap(([alias, model]): FieldIssue[] => {
return Object.entries(aliases).flatMap(([alias, model]): FieldIssue[] => {
if (!MODEL_ALIAS_NAME.test(alias))
return [{ path: alias, label: alias || "Alias", message: "Use lowercase letters, digits, '.', '_' or '-'." }];
const slash = String(model).indexOf("/");
@@ -117,9 +118,6 @@ export function validateModelAliases(value: unknown): FieldIssue[] {
return [{ path: alias, label: alias, message: "Use provider/model." }];
return [];
});
if (Object.keys(aliases).length > 0 && !("default" in aliases))
issues.push({ path: "default", label: "default", message: "The default alias is required." });
return issues;
}
/** The rules the store applies to a dirty draft, keyed by resource kind. */
+1 -1
View File
@@ -200,7 +200,7 @@ const PAGE_RESOURCES: Record<ControlPlanePage, string[]> = {
credentials: ["credential-bindings"],
playbooks: ["eda-playbooks"],
tasks: ["workflow-execution-settings","task-policy"],
models: ["provider-settings", "model-aliases"],
models: ["provider-settings", "model-aliases", "org-model-policy"],
repositories: ["repository-policies"],
channels: ["channel-settings"],
scheduling: ["scheduling-policy"],