diff --git a/cptr/frontend/src/lib/components/chat/ChatInput.svelte b/cptr/frontend/src/lib/components/chat/ChatInput.svelte index 79a8e94..01420ae 100644 --- a/cptr/frontend/src/lib/components/chat/ChatInput.svelte +++ b/cptr/frontend/src/lib/components/chat/ChatInput.svelte @@ -142,6 +142,7 @@ let voiceCaptureChunks: Blob[] = []; let voiceCaptureMimeType = 'audio/webm'; let selectedSlashCommandIndex = $state(0); + let modelSelector: ModelSelector | undefined = $state(); const voiceModeAvailable = $derived( $ttsEnabled && $ttsConfigured && ($voiceModeSttMode === 'browser' || $sttConfigured) ); @@ -979,6 +980,7 @@ if (onplan && '/plan'.startsWith(slashCommandQuery)) ids.push('plan'); if (hasChatContent && onfork && '/fork'.startsWith(slashCommandQuery)) ids.push('fork'); if (hasChatContent && onstatus && '/status'.startsWith(slashCommandQuery)) ids.push('status'); + if ('/model'.startsWith(slashCommandQuery)) ids.push('model'); if ( hasChatContent && onskillslist && @@ -1093,6 +1095,11 @@ onstatus(); return; } + if (commandId === 'model') { + inputText = ''; + void modelSelector?.openSelector(); + return; + } if (commandId === 'skills:list' && onskillslist) { inputText = ''; onskillslist(); @@ -1331,6 +1338,31 @@ {/if} + {#if slashCommandIds.includes('model')} + e.preventDefault()} + onclick={() => { + runSlashCommand('model'); + }} + onmouseenter={() => selectSlashCommand('model')} + > + + + + + {$t('chat.commandModel')} + /model + + + {/if} {#if slashCommandIds.includes('skills:list')} - + { inputText += text; diff --git a/cptr/frontend/src/lib/components/common/ModelSelector.svelte b/cptr/frontend/src/lib/components/common/ModelSelector.svelte index e6eb0a3..b7df9d4 100644 --- a/cptr/frontend/src/lib/components/common/ModelSelector.svelte +++ b/cptr/frontend/src/lib/components/common/ModelSelector.svelte @@ -76,18 +76,26 @@ }; }); - async function toggle() { + async function focusSearchInput() { + await tick(); + await tick(); + searchInputEl?.focus(); + searchInputEl?.select(); + } + + export async function openSelector() { if ($chatModels.length === 0 && !nullable) return; + open = true; + search = ''; + await focusSearchInput(); + } + + async function toggle() { if (open) { open = false; return; } - open = true; - search = ''; - await tick(); - // Focus search after DropdownMenu renders - await tick(); - searchInputEl?.focus(); + await openSelector(); } diff --git a/cptr/frontend/src/lib/i18n/locales/en.json b/cptr/frontend/src/lib/i18n/locales/en.json index 2a8f0d0..4bbe4b0 100644 --- a/cptr/frontend/src/lib/i18n/locales/en.json +++ b/cptr/frontend/src/lib/i18n/locales/en.json @@ -773,6 +773,8 @@ "chat.commandForkDesc": "Clone chat", "chat.commandStatus": "Status", "chat.commandStatusDesc": "Context usage, chat id", + "chat.commandModel": "Model", + "chat.commandModelDesc": "Open model selector", "chat.statusContextUsage": "Context usage", "chat.statusEstimated": "Estimated context", "chat.statusChatId": "Chat id",