feat: pick the room model from a catalog dialog

The room model was a free-text field. It now opens a dialog that lists the provider's live catalog through the same adapter a turn uses, with context, output, price, and vision from models.dev. Rows filter by text, vision, or free price, and a custom id remains available when the provider lists nothing.

The dialog is nested over room settings, so BaseDialog now gives Escape and the focus trap to the top dialog only. Clearing the model stores NULL, which returns the room to the provider's default.
This commit is contained in:
vhaudiquet committed 2026-11-28 17:21:48 +01:00
1 parent 2d36790fe1
commit 2216f37422
13 files changed
+724 -20

No files matched your search

+11 -4
View File
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { nextTick, onBeforeUnmount, onMounted, ref, useId } from 'vue'
import { X } from 'lucide-vue-next'
import { isTopDialog, pushDialog, removeDialog } from '~/utils/dialogStack'
const props = withDefaults(defineProps<{ title: string; description?: string; wide?: boolean }>(), {
description: '',
@@ -13,7 +14,12 @@ const titleId = useId()
const descId = useId()
const panel = ref<HTMLElement | null>(null)
let previousFocus: HTMLElement | null = null
let previousOverflow = ''
// A dialog can open another one (the model picker over room settings).
// Only the top of the stack answers Escape and Tab, so closing the
// inner dialog leaves the outer one open. The stack lives in its own
// module because every `<script setup>` binding is per instance.
const dialogId = Symbol('dialog')
function focusable(): HTMLElement[] {
if (!panel.value) return []
@@ -31,6 +37,7 @@ function focusable(): HTMLElement[] {
}
function onKeydown(event: KeyboardEvent) {
if (!isTopDialog(dialogId)) return
if (event.key === 'Escape') {
event.preventDefault()
emit('close')
@@ -58,13 +65,13 @@ function onKeydown(event: KeyboardEvent) {
}
function onBackdrop(event: MouseEvent) {
if (!isTopDialog(dialogId)) return
if (event.target === event.currentTarget) emit('close')
}
onMounted(async () => {
pushDialog(dialogId)
previousFocus = document.activeElement as HTMLElement | null
previousOverflow = document.body.style.overflow
document.body.style.overflow = 'hidden'
document.addEventListener('keydown', onKeydown)
await nextTick()
const preferred = panel.value?.querySelector<HTMLElement>('[autofocus]')
@@ -73,8 +80,8 @@ onMounted(async () => {
})
onBeforeUnmount(() => {
removeDialog(dialogId)
document.removeEventListener('keydown', onKeydown)
document.body.style.overflow = previousOverflow
previousFocus?.focus?.()
})
</script>