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

+21
View File
@@ -0,0 +1,21 @@
const stack: symbol[] = []
let savedOverflow = ''
export function pushDialog(id: symbol) {
if (stack.length === 0) {
savedOverflow = document.body.style.overflow
document.body.style.overflow = 'hidden'
}
stack.push(id)
}
export function removeDialog(id: symbol) {
const index = stack.indexOf(id)
if (index === -1) return
stack.splice(index, 1)
if (stack.length === 0) document.body.style.overflow = savedOverflow
}
export function isTopDialog(id: symbol) {
return stack[stack.length - 1] === id
}
+25
View File
@@ -52,3 +52,28 @@ export function formatCost(cost: number | null | undefined): string {
export function plural(count: number, one: string, many: string): string {
return count === 1 ? one : many
}
export function formatTokens(tokens: number | null | undefined): string {
if (tokens === null || tokens === undefined || tokens <= 0) return ''
if (tokens >= 1_000_000) {
const value = tokens / 1_000_000
return `${Number.isInteger(value) ? value : value.toFixed(1)}M`
}
if (tokens >= 1_000) {
const value = tokens / 1_000
return `${Number.isInteger(value) ? value : value.toFixed(0)}k`
}
return String(tokens)
}
export function formatModelPrice(value: number | null | undefined): string {
if (value === null || value === undefined) return ''
if (value === 0) return 'Free'
const digits = value < 0.01 ? 4 : 2
return new Intl.NumberFormat('en', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2,
maximumFractionDigits: digits,
}).format(value)
}