123 lines
6.0 KiB
Vue
123 lines
6.0 KiB
Vue
<script setup lang="ts">
|
|
import { Label } from "@/components/ui/label";
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import PageHeader from "@/base/PageHeader.vue";
|
|
import { computed, onMounted, ref } from "vue";
|
|
import { Plus, Trash2 } from "@lucide/vue";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { Section } from "@/components/ui/section";
|
|
import { Input } from "@/components/ui/input";
|
|
import { useSettingsStore } from "@/stores/settings";
|
|
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 = useSettingsStore();
|
|
onMounted(() => store.load());
|
|
|
|
// 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 aliases = computed(() => store.draftValue("model-aliases") as Record<string, string> | undefined);
|
|
const providers = computed(() => store.draftValue("provider-settings") as Record<string, Provider> | undefined);
|
|
const aliasEntries = computed(() => Object.entries(aliases.value ?? {}));
|
|
const providerEntries = computed(() => Object.entries(providers.value ?? {}));
|
|
const errors = computed(() => ["model-aliases", "provider-settings"].map((k) => store.pageErrorFor(k)).filter(Boolean));
|
|
const aliasIssues = computed(() => store.issuesFor("model-aliases"));
|
|
const issue = (alias: string) => aliasIssues.value.find((entry) => entry.path === alias);
|
|
|
|
function setAlias(alias: string, model: string) {
|
|
store.setDraftEntry("model-aliases", alias, model.trim() || undefined);
|
|
}
|
|
function removeAlias(alias: string) {
|
|
store.setDraftEntry("model-aliases", alias, undefined);
|
|
}
|
|
const newAlias = ref("");
|
|
function addAlias() {
|
|
const name = newAlias.value.trim();
|
|
if (!aliases.value || !name || aliases.value[name] !== undefined) return;
|
|
store.setDraftEntry("model-aliases", name, "");
|
|
newAlias.value = "";
|
|
}
|
|
const newProvider = ref("");
|
|
function addProvider() {
|
|
const name = newProvider.value.trim();
|
|
if (!providers.value || !name || providers.value[name]) return;
|
|
store.setDraftEntry("provider-settings", name, { class: "openai", api_key_ref: { engine: "", key: "" } });
|
|
newProvider.value = "";
|
|
}
|
|
function setProvider(name: string, next: Partial<Provider>) {
|
|
const current = providers.value?.[name];
|
|
if (current) store.setDraftEntry("provider-settings", name, { ...current, ...next });
|
|
}
|
|
function removeProvider(name: string) {
|
|
store.setDraftEntry("provider-settings", name, undefined);
|
|
}
|
|
const bound = computed(() => new Set(((store.draftValue("credential-bindings") as { service: string }[] | null) ?? []).map((b) => b.service)));
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<PageHeader title="Models" />
|
|
<Alert v-for="e in errors" :key="String(e)" variant="destructive" class="mb-4"><AlertDescription>{{ e }}</AlertDescription></Alert>
|
|
|
|
<template v-if="aliases">
|
|
<Section title="Aliases">
|
|
<div v-for="[alias, model] in aliasEntries" :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="`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 max-sm:basis-full"
|
|
placeholder="provider/model"
|
|
:aria-invalid="!!issue(alias)"
|
|
@update:model-value="(v) => setAlias(alias, String(v))"
|
|
/>
|
|
<DraftHint kind="model-aliases" :path="alias" />
|
|
<span v-if="issue(alias)" class="text-xs text-danger">{{ issue(alias)?.message }}</span>
|
|
<Button variant="ghost" size="icon" class="ml-auto" :aria-label="`Remove alias ${alias}`" @click="removeAlias(alias)"><Trash2 /></Button>
|
|
</div>
|
|
<form class="flex gap-2 border-t border-border pt-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>
|
|
</Section>
|
|
</template>
|
|
|
|
<template v-if="providers">
|
|
<Section title="Providers">
|
|
<div v-for="[name, provider] in providerEntries" :key="name" 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 font-mono text-sm font-medium">{{ name }}</span>
|
|
<Input
|
|
:model-value="provider.class"
|
|
class="w-36 font-mono"
|
|
:aria-label="`Class for ${name}`"
|
|
@update:model-value="(v) => setProvider(name, { class: String(v) })"
|
|
/>
|
|
<Input
|
|
:model-value="provider.base_url ?? ''"
|
|
class="max-w-md flex-1 font-mono max-sm:basis-full"
|
|
placeholder="base URL (empty: class default)"
|
|
:aria-label="`Base URL for ${name}`"
|
|
@update:model-value="(v) => setProvider(name, { base_url: String(v) })"
|
|
/>
|
|
<RouterLink v-if="!bound.has(name)" to="/org/credential-bindings" class="text-xs text-warn hover:underline">Add a credential binding named "{{ name }}"</RouterLink>
|
|
<Button variant="ghost" size="icon" class="ml-auto" :aria-label="`Remove provider ${name}`" @click="removeProvider(name)"><Trash2 /></Button>
|
|
</div>
|
|
<form class="flex gap-2 border-t border-border pt-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>
|
|
</Section>
|
|
</template>
|
|
</div>
|
|
</template>
|