diff --git a/src/lib/components/chat/ChatControls.svelte b/src/lib/components/chat/ChatControls.svelte index 31977f7eb7..f8b9c4746a 100644 --- a/src/lib/components/chat/ChatControls.svelte +++ b/src/lib/components/chat/ChatControls.svelte @@ -1,4 +1,5 @@ @@ -9,6 +10,7 @@ import { artifactContents, config, + embed, temporaryChatEnabled, terminalServers, showTabs, @@ -74,12 +76,12 @@ let viewportWidth = 0; // Tab state for the side panel - let activeTab: typeof savedTab = savedTab; + let activeTab: PanelTab = savedTab; $: if ($showTabs === 'files' || $showTabs === 'comments') activeTab = $showTabs; else if (typeof $showTabs === 'object') activeTab = $showTabs.tab; // svelte-ignore reactive_declaration_module_script_dependency $: { - if (activeTab !== 'comments') savedTab = activeTab; + if (activeTab === 'files') savedTab = activeTab; } $: hasMessages = history?.messages && Object.keys(history.messages).length > 0; @@ -150,8 +152,18 @@ $: if ($showTabs === 'files' || $showTabs === 'comments' || typeof $showTabs === 'object') { showArtifacts.set(false); showEmbeds.set(false); - showCallOverlay.set(false); } + $: if ($showArtifacts) activeTab = 'artifacts'; + $: if ($showEmbeds) activeTab = 'preview'; + $: if ($showCallOverlay) activeTab = 'voice'; + + const selectTab = (tab: PanelTab) => { + showTabs.set(tab === 'files' || tab === 'comments' ? tab : true); + showArtifacts.set(tab === 'artifacts'); + showEmbeds.set(tab === 'preview'); + activeTab = tab; + }; + beforeNavigate(({ from, to }) => { if (from?.url.pathname === to?.url.pathname) return; showOverview.set(false); @@ -164,20 +176,19 @@ }); $: showArtifactsTab = ($artifactContents ?? []).length > 0 && $visibleControls['chat.artifacts']; - $: sidePanelAvailable = showFilesTab || showCommentsTab || showArtifactsTab || specialPanel; - - // Keep the remaining side-pane tabs available after moving Controls into the composer. - $: if (!showCommentsTab && activeTab === 'comments') activeTab = 'files'; - $: if (!showFilesTab && showCommentsTab && activeTab === 'files') activeTab = 'comments'; - $: if ( - $showTabs && - !$showEmbeds && - !$showCallOverlay && - !showFilesTab && - !showCommentsTab && - showArtifactsTab - ) - showArtifacts.set(true); + $: showPreviewTab = !!$embed && $embed.chatId === chatId; + $: panelTabs = [ + { id: 'files', label: $i18n.t('Files'), available: showFilesTab }, + { id: 'artifacts', label: $i18n.t('Artifacts'), available: showArtifactsTab }, + { id: 'preview', label: $i18n.t('Preview'), available: showPreviewTab }, + { id: 'voice', label: $i18n.t('Voice'), available: $showCallOverlay }, + { id: 'comments', label: $i18n.t('Comments'), available: showCommentsTab } + ].filter((tab) => tab.available) as { id: PanelTab; label: string; available: boolean }[]; + $: sidePanelAvailable = panelTabs.length > 0; + $: if (sidePanelAvailable && !panelTabs.some((tab) => tab.id === activeTab)) { + activeTab = panelTabs[0].id; + if ($showTabs) selectTab(activeTab); + } $: if (!sidePanelAvailable) showTabs.set(false); // Auto-switch to Files tab when display_file is triggered @@ -267,9 +278,6 @@ }; $: if (mounted && !chatId) closeHandler(); - - // Helper: is a "special" full-screen panel active? - $: specialPanel = $showCallOverlay || $showArtifacts || $showEmbeds; @@ -309,6 +317,74 @@ +{#snippet panelContent()} +
+
+
+ {#each panelTabs as tab (tab.id)} + + {/each} +
+ +
+ +
+ {#if $showCallOverlay} + +
+ showTabs.set(false)} + /> +
+ {/if} + {#if activeTab === 'preview'} + + {:else if activeTab === 'artifacts'} + + {:else if activeTab === 'comments'} + {#if currentComments} + {#key `${$user.id}:${chatId}:${currentComments.comment_id ?? ''}`} + + {/key} + {/if} + {:else if activeTab === 'files' && terminalFilesAvailable && $selectedTerminalId} + + {:else if activeTab === 'files' && codeInterpreterEnabled} + + {/if} +
+
+{/snippet} + {#if !largeScreen}
- {#if $showCallOverlay} -
- showTabs.set(false)} - /> -
- {:else if $showEmbeds} - - {:else} - -
- -
-
- {#if showFilesTab} - - {/if} - {#if showArtifactsTab} - - {/if} - {#if showCommentsTab} - - {/if} -
- -
- -
- {#if $showArtifacts} - - {:else if activeTab === 'comments'} - {#if currentComments} - {#key `${$user.id}:${chatId}:${currentComments.comment_id ?? ''}`} - - {/key} - {/if} - {:else if activeTab === 'files' && terminalFilesAvailable && $selectedTerminalId} - - {:else if activeTab === 'files' && codeInterpreterEnabled} - - {/if} -
-
- {/if} + {@render panelContent()}
{/if} @@ -452,119 +424,8 @@ storageKey="chatControlsSize" className="h-full z-10 bg-white dark:bg-gray-900" > -
-
- {#if $showCallOverlay} -
- showTabs.set(false)} - /> -
- {:else if $showEmbeds} - - {:else} - -
- -
-
- {#if showFilesTab} - - {/if} - {#if showArtifactsTab} - - {/if} - {#if showCommentsTab} - - {/if} -
- -
- -
- {#if $showArtifacts} - - {:else if activeTab === 'comments'} - {#if currentComments} - {#key `${$user.id}:${chatId}:${currentComments.comment_id ?? ''}`} - - {/key} - {/if} - {:else if activeTab === 'files' && terminalFilesAvailable && $selectedTerminalId} - - {:else if activeTab === 'files' && codeInterpreterEnabled} - - {/if} -
-
- {/if} -
+
+ {@render panelContent()}
{/if} diff --git a/src/lib/components/chat/ChatControls/Embeds.svelte b/src/lib/components/chat/ChatControls/Embeds.svelte index 9fe71fb0c4..a32d3a99a5 100644 --- a/src/lib/components/chat/ChatControls/Embeds.svelte +++ b/src/lib/components/chat/ChatControls/Embeds.svelte @@ -1,14 +1,10 @@