97 lines
4.9 KiB
Vue
97 lines
4.9 KiB
Vue
<script setup lang="ts">
|
|
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());
|
|
|
|
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 bound = computed(() => new Set(((store.drafts["credential-bindings"]?.value as { service: string }[] | null) ?? []).map((b) => b.service)));
|
|
</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">
|
|
<Section title="Aliases">
|
|
<div v-for="(model, alias) in aliases" :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(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 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="(provider, name) in providers" :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 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 max-sm:basis-full" placeholder="base URL (empty: class default)" :aria-label="`Base URL for ${name}`" />
|
|
<RouterLink v-if="!bound.has(String(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="delete providers[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>
|