-
{#if !largeScreen}
showTabs.set(open)}
@@ -409,9 +774,7 @@
swipeSide={$mobile ? 'right' : undefined}
className="min-h-[100dvh] !bg-white dark:!bg-gray-850"
>
-
- {@render panelContent()}
-
+
{/if}
@@ -424,8 +787,15 @@
storageKey="chatControlsSize"
className="h-full z-10 bg-white dark:bg-gray-900"
>
-
- {@render panelContent()}
-
+
{/if}
+
+
diff --git a/src/lib/components/chat/ChatControls/UntitledFile.svelte b/src/lib/components/chat/ChatControls/UntitledFile.svelte
new file mode 100644
index 0000000000..b11d0711bc
--- /dev/null
+++ b/src/lib/components/chat/ChatControls/UntitledFile.svelte
@@ -0,0 +1,258 @@
+
+
+
+
+ {label}
+ {formatFileSize(byteCount)}
+
+
+
+ {
+ await save();
+ }}
+ />
+
+
+
+
{
+ if (!saving) finishSave(false);
+ }}
+ className="bg-white dark:bg-gray-900 rounded-2xl"
+>
+
+
+
+
closeChoice?.('save')}
+ on:cancel={() => closeChoice?.('cancel')}
+>
+
+
diff --git a/src/lib/components/chat/ChatControls/tabs.test.ts b/src/lib/components/chat/ChatControls/tabs.test.ts
new file mode 100644
index 0000000000..934dc7dda6
--- /dev/null
+++ b/src/lib/components/chat/ChatControls/tabs.test.ts
@@ -0,0 +1,38 @@
+import { describe, expect, it } from 'vitest';
+import { activateTab, emptyTabs, fileTabId, openTab, removeTab, type PanelTab } from './tabs';
+
+const tab = (id: string, kind: PanelTab['kind'] = 'file'): PanelTab => ({ id, kind, label: id });
+
+describe('chat panel tabs', () => {
+ it('reuses an open file and keeps files from different terminals separate', () => {
+ const a = tab(fileTabId('server-a', '/readme.md'));
+ const b = tab(fileTabId('server-b', '/readme.md'));
+ let state = openTab(openTab(emptyTabs(), a), b);
+ state = openTab(state, a);
+ expect(state.tabs).toHaveLength(2);
+ expect(state.activeId).toBe(a.id);
+ });
+ it('keeps independent shells and returns to the most recently used tab on close', () => {
+ let state = openTab(
+ openTab(openTab(emptyTabs(), tab('files', 'files')), tab('shell-1', 'terminal')),
+ tab('shell-2', 'terminal')
+ );
+ state = activateTab(state, 'files');
+ state = activateTab(state, 'shell-2');
+ state = removeTab(state, 'shell-2');
+ expect(state.activeId).toBe('files');
+ expect(state.tabs.map((item) => item.id)).toEqual(['files', 'shell-1']);
+ });
+ it('closes a feature view without automatically reopening it and can reopen it explicitly', () => {
+ let state = openTab(emptyTabs(), tab('artifacts', 'artifacts'));
+ state = removeTab(state, 'artifacts');
+ expect(state).toEqual(emptyTabs());
+ state = openTab(state, tab('artifacts', 'artifacts'));
+ expect(state.activeId).toBe('artifacts');
+ });
+ it('closing an inactive tab leaves the active tab selected', () => {
+ const state = removeTab(openTab(openTab(emptyTabs(), tab('a')), tab('b')), 'a');
+ expect(state.activeId).toBe('b');
+ expect(state.history).toEqual([]);
+ });
+});
diff --git a/src/lib/components/chat/ChatControls/tabs.ts b/src/lib/components/chat/ChatControls/tabs.ts
new file mode 100644
index 0000000000..ad9c56fd31
--- /dev/null
+++ b/src/lib/components/chat/ChatControls/tabs.ts
@@ -0,0 +1,66 @@
+import type { TerminalContext } from '$lib/types';
+import type { TerminalConnection } from '$lib/apis/terminal';
+
+export type PanelTabKind =
+ | 'files'
+ | 'file'
+ | 'terminal'
+ | 'artifacts'
+ | 'preview'
+ | 'voice'
+ | 'comments';
+export type PanelTab = {
+ id: string;
+ kind: PanelTabKind;
+ label: string;
+ terminalId?: string;
+ path?: string;
+ page?: number | null;
+ dirty?: boolean;
+ untitled?: boolean;
+ connection?: TerminalConnection;
+ context?: TerminalContext | null;
+};
+export type PanelTabs = { tabs: PanelTab[]; activeId: string; history: string[] };
+
+export const emptyTabs = (): PanelTabs => ({ tabs: [], activeId: '', history: [] });
+
+export function activateTab(state: PanelTabs, id: string): PanelTabs {
+ if (!state.tabs.some((tab) => tab.id === id) || state.activeId === id) return state;
+ return {
+ ...state,
+ activeId: id,
+ history: [
+ ...state.history.filter((entry) => entry !== id && entry !== state.activeId),
+ state.activeId
+ ].filter(Boolean)
+ };
+}
+
+export function openTab(state: PanelTabs, tab: PanelTab): PanelTabs {
+ return activateTab(
+ state.tabs.some((item) => item.id === tab.id)
+ ? state
+ : { ...state, tabs: [...state.tabs, tab] },
+ tab.id
+ );
+}
+
+export function removeTab(state: PanelTabs, id: string): PanelTabs {
+ const tabs = state.tabs.filter((tab) => tab.id !== id);
+ const history = state.history.filter(
+ (entry) => entry !== id && tabs.some((tab) => tab.id === entry)
+ );
+ const index = state.tabs.findIndex((tab) => tab.id === id);
+ return {
+ tabs,
+ activeId:
+ state.activeId === id
+ ? (history.at(-1) ?? tabs[Math.max(0, index - 1)]?.id ?? '')
+ : state.activeId,
+ history
+ };
+}
+
+export const fileTabId = (terminalId: string, path: string) =>
+ JSON.stringify(['file', terminalId, path]);
diff --git a/src/lib/components/chat/FileNav.svelte b/src/lib/components/chat/FileNav.svelte
index 898000cc61..7437e9d186 100644
--- a/src/lib/components/chat/FileNav.svelte
+++ b/src/lib/components/chat/FileNav.svelte
@@ -1,16 +1,3 @@
-
-
-