Files
archie/ui/src/chat/ChatSettings.vue
T
sam f6e9d48da6 fix(chat): mount the model list only while it is open
reka-ui mounts every item of a closed Select to resolve the selected label, so opening the More menu rendered the whole model catalogue first. With 400 models the menu took about 400 ms to open; it now takes about 30 ms.
2026-11-21 22:36:30 +11:00

72 lines
2.7 KiB
Vue

<script setup lang="ts">
import { computed, ref } from "vue";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { selectedModel, selectorData, setModel, statusText } from "./state";
/**
* The chat's own settings: what the panel is doing right now, and the model it
* runs on. A model id already names its provider, so there is one control. It
* sits in the session menu.
*
* reka-ui refuses an empty string as an item value (that is how it spells
* "nothing selected") while the wire reads an absent value as "use the
* default", so the sentinel converts at this boundary and the state below keeps
* the empty string.
*/
const DEFAULT = "__default__";
const modelValue = computed(() => selectedModel.value || DEFAULT);
// reka-ui mounts every item of a closed Select to find the selected label, so a
// catalogue of hundreds of models stalled the menu that holds this control.
// The items mount only while the list is open and the label is written here.
const listOpen = ref(false);
const label = computed(() => (selectedModel.value ? selectedModel.value : "Default"));
// The server groups models by provider; one flat list stands in when it does not.
const groups = computed(() => {
const grouped = selectorData.value.models_by_provider || {};
const entries = Object.entries(grouped).filter(([, models]) => models.length);
return entries.length
? entries
: [["", selectorData.value.models || []] as [string, string[]]];
});
// The model is chosen here only when the server offers a choice.
const choosable = computed(() => groups.value.some(([, models]) => models.length));
</script>
<template>
<div class="grid gap-1 p-1">
<span v-if="statusText !== 'Ready'" class="text-caption text-fg-subtle">{{ statusText }}</span>
<span v-if="selectorData.model_error" class="text-caption text-destructive">{{ selectorData.model_error }}</span>
<Select
v-if="choosable"
v-model:open="listOpen"
:model-value="modelValue"
@update:model-value="setModel($event === DEFAULT ? '' : String($event ?? ''))"
>
<SelectTrigger size="sm" class="w-full" aria-label="Model">
<SelectValue>{{ label }}</SelectValue>
</SelectTrigger>
<SelectContent>
<template v-if="listOpen">
<SelectItem :value="DEFAULT">Default</SelectItem>
<SelectGroup v-for="[provider, models] in groups" :key="provider">
<SelectLabel v-if="provider">{{ provider }}</SelectLabel>
<SelectItem v-for="model in models" :key="model" :value="model">{{ model }}</SelectItem>
</SelectGroup>
</template>
</SelectContent>
</Select>
</div>
</template>