diff --git a/frontend/src/lib/components/DropdownV2.svelte b/frontend/src/lib/components/DropdownV2.svelte index e9fbf71ab8..c2f56b7d44 100644 --- a/frontend/src/lib/components/DropdownV2.svelte +++ b/frontend/src/lib/components/DropdownV2.svelte @@ -13,7 +13,7 @@ import DropdownV2Inner from './DropdownV2Inner.svelte' import { pointerDownOutside } from '$lib/utils' import { createDropdownMenu, melt, createSync } from '@melt-ui/svelte' - import { overlayPortalTarget } from '$lib/components/common/overlayHost.svelte' + import { overlayPortalTarget, overlayShown } from '$lib/components/common/overlayHost.svelte' import type { MenubarMenuElements } from '@melt-ui/svelte' import ResolveOpen from '$lib/components/common/menu/ResolveOpen.svelte' import Button from '$lib/components/common/button/Button.svelte' @@ -89,6 +89,7 @@ // Overlays belong to the enclosing pane when there is one — see overlayHost. const hostPortal = overlayPortalTarget('body') + const shown = overlayShown() const { elements: { menu: menuEl, item, trigger }, @@ -198,7 +199,7 @@ {/if} -{#if open && !hidePopup} +{#if open && !hidePopup && shown()}
> - /** The folders above the name truncate too: even the name at its last floor does not fit. */ + /** Even the name at its last floor does not fit: the folders above it truncate too, and a + * section's own widget may shrink. */ scopesGive?: boolean /** Filled in for the bar to choose a stage with; left undefined, nothing is measured. */ measures?: TrailMeasures @@ -543,17 +544,21 @@ not this component) — so the lead can run the whole line. {#if section.content && measure} {:else} - + sectionContentWidth, (w) => !measure && section.content && (sectionContentWidth = w) + () => sectionContentWidth, + (w) => !measure && section.content && !scopesGive && (sectionContentWidth = w) } > - +{#if shown()} + +{/if} diff --git a/frontend/src/lib/components/common/confirmationModal/ConfirmationModal.svelte b/frontend/src/lib/components/common/confirmationModal/ConfirmationModal.svelte index 912d6e02e2..3ecb6a93f1 100644 --- a/frontend/src/lib/components/common/confirmationModal/ConfirmationModal.svelte +++ b/frontend/src/lib/components/common/confirmationModal/ConfirmationModal.svelte @@ -1,7 +1,11 @@ { + if (!hostActive()) return if ((e.ctrlKey || e.metaKey) && e.key === 'l') { e.preventDefault() aiChatDisplay?.focusInput() diff --git a/frontend/src/lib/components/copilot/chat/AssistantSettingsModal.svelte b/frontend/src/lib/components/copilot/chat/AssistantSettingsModal.svelte index 5315912fa2..d3a9d7982a 100644 --- a/frontend/src/lib/components/copilot/chat/AssistantSettingsModal.svelte +++ b/frontend/src/lib/components/copilot/chat/AssistantSettingsModal.svelte @@ -48,6 +48,7 @@ callers that already know which section they mean, such as the "+" menu's Manage import { useOperatingWorkspace } from '$lib/components/operatingWorkspace.svelte' import AssistantDangerZoneSection from './AssistantDangerZoneSection.svelte' import { useActingUser } from '$lib/actingUser.svelte' + import { overlayHostActive } from '$lib/components/common/overlayHost.svelte' // Prefilled title marks the issue as AI Sessions feedback for triage. const FEEDBACK_ISSUE_URL = @@ -64,6 +65,7 @@ callers that already know which section they mean, such as the "+" menu's Manage const operatingWorkspace = useOperatingWorkspace() const aiChatManager = getAiChatManager() + const hostActive = overlayHostActive() let isOpen = $state(false) let section = $state('tools') @@ -109,7 +111,8 @@ callers that already know which section they mean, such as the "+" menu's Manage * it would then answer the key it was revealed by — reverting the very draft the * user was brought here to see. */ function onKeydown(event: KeyboardEvent) { - if (!isOpen || event.key !== 'Escape') return + // Hidden hosts stay mounted and still receive window keys — see overlayHost. + if (!isOpen || event.key !== 'Escape' || !hostActive()) return const blocker = blockingSection if (!blocker || blocker === section) return event.preventDefault() @@ -132,7 +135,9 @@ callers that already know which section they mean, such as the "+" menu's Manage // assistant can call here, so it must not shift when the autonomy picker does. // The danger zone writes the workspace's AI config, which only its admins may change. const acting = useActingUser(() => ws) - let isWsAdmin = $derived(!!acting.current && (acting.current.is_admin || acting.current.is_super_admin)) + let isWsAdmin = $derived( + !!acting.current && (acting.current.is_admin || acting.current.is_super_admin) + ) let tools = $derived(summarizeTools(aiChatManager.availableTools)) let providerTools = $derived(aiChatManager.providerTools) @@ -326,9 +331,7 @@ callers that already know which section they mean, such as the "+" menu's Manage
{#if isWsAdmin} -
+
{/if} diff --git a/frontend/src/lib/components/meltComponents/Menu.svelte b/frontend/src/lib/components/meltComponents/Menu.svelte index 39b679765f..dd3e6d19ee 100644 --- a/frontend/src/lib/components/meltComponents/Menu.svelte +++ b/frontend/src/lib/components/meltComponents/Menu.svelte @@ -1,6 +1,6 @@ - isOpen && onKeyDown(e)} /> + isOpen && hostActive() && onKeyDown(e)} /> + + {/if} +{/snippet} + +
+ {#if !sessionState.hydrated} + +
+ +
+ {:else} + +
+ +
+ + + + + + +
+ {#each mountedChatSessions as s (s.id)} + +
+ + tabNameFor(tab, getEffectiveWorkspaceId(s) ?? $workspaceStore ?? '')} + /> +
+ {/each} +
+
+ + + + +
previewWidth, + (w) => { + previewWidth = w + if (!fullscreen && !panesAnimating && contentWidth > 0) + panelShare = w / contentWidth + } + } + class="flex-1 min-h-0 flex flex-col {bandFullscreen + ? `p-0 ${BAR_TOP_PAD}` + : fullscreen + ? `px-2 pb-2 ${BAR_TOP_PAD}` + : 'p-2 pl-0'}" + > + +
+ {#if !bandFullscreen} + + + {/if} + + + {#if !bandFullscreen} + +
+ {@render previewControls()} +
+ + {@render previewTabStrip(false)} + {/if} + + +
+ {#if shown && previewTabHostComponent.current} + {@const TabHost = previewTabHostComponent.current} + {#each warmHosts as { session: s, runtime: rt } (s.id)} + {@const tabs = rt.previewTabs} + {#each tabs?.tabs ?? [] as tab (tab.id)} + + + tabs && onTabLoad(tabs, tab, frame)} + /> + {/each} + {/each} + {/if} + {#if (owner?.tabs.length ?? 0) === 0} + +
+ +
+ No preview open + Open a page, flow, script or app to preview it alongside the chat. +
+ + {#snippet trigger()} + + Open a preview + + {/snippet} + {#snippet content()} + { + emptyStateNewTabOpen = false + openInNewTab(t) + }} + /> + {/snippet} + +
+ {/if} +
+
+
+
+
+
+ {#if awaitingSession || firstVerdictPending} +
+ +
+ {:else if aiHiddenVerdict} + + +
+

AI Sessions are hidden in this workspace

+

A workspace admin hid AI sessions in the workspace settings.

+ +
+ {/if} +
+ {/if} +
+ + +{#snippet previewControls()} + {#if activeWorkspaceHref} + + + + {/if} + {#if narrowScreen.current} + + {:else if fullscreen} + + + {:else} + + {/if} +{/snippet} + +{#snippet previewTabStrip(inBand: boolean)} + +
+ (activeTabPickerOpen = !activeTabPickerOpen)} + onClose={closeTab} + onReorder={reorderTabs} + size={inBand ? 'md' : 'sm'} + class={inBand + ? 'session-preview-tab-strip h-full bg-transparent min-w-0' + : 'session-preview-tab-strip h-8 border-b border-light bg-surface-secondary/50 pl-9 pr-[var(--preview-actions-w,4rem)]'} + > + {#snippet tabAccessory(_tab, isActive)} + {#if isActive} + + + (e.currentTarget as HTMLElement).closest('[role="tab"]')?.focus() + }} + > + {#snippet content()} + + {#key activePickerScope?.dir ?? ''} + { + activeTabPickerOpen = false + navigatePreviewTo(t) + }} + /> + {/key} + {/snippet} + + + {/if} + {/snippet} + {#snippet afterTabs()} + + {#snippet trigger()} + + {/snippet} + {#snippet content()} + { + newTabOpen = false + openInNewTab(t) + }} + /> + {/snippet} + + {/snippet} + +
+{/snippet} + + diff --git a/frontend/src/lib/components/sessions/WorkspaceFamilyPicker.svelte b/frontend/src/lib/components/sessions/WorkspaceFamilyPicker.svelte index bd8bc7081a..5940d18b53 100644 --- a/frontend/src/lib/components/sessions/WorkspaceFamilyPicker.svelte +++ b/frontend/src/lib/components/sessions/WorkspaceFamilyPicker.svelte @@ -18,6 +18,7 @@ workspaceSubtreeRows } from '$lib/utils/workspaceHierarchy' import { useForkableWorkspaces } from '$lib/utils/useForkableWorkspaces.svelte' + import { overlayHostActive } from '$lib/components/common/overlayHost.svelte' import { isNewTabClick } from '$lib/navigation' import { canCreateFork } from '$lib/utils/editInFork' import { canFork, capabilitiesIn } from '$lib/roleCapabilities' @@ -242,6 +243,9 @@ $effect(() => { if (!dropdownOpen) keyArrowPos = undefined }) + // A picker left open in a pane that went off screen would take the next page's arrows, and + // its Enter would pick a workspace there. + const hostActive = overlayHostActive() function activateRow(row: NavRow) { if (row.kind === 'create') { @@ -371,7 +375,7 @@ { - if (!dropdownOpen) return + if (!dropdownOpen || !hostActive()) return if (creatingFork) return if (navRows.length === 0) return if (e.key === 'ArrowDown') { diff --git a/frontend/src/lib/components/sessions/sessionState.svelte.ts b/frontend/src/lib/components/sessions/sessionState.svelte.ts index 69b6527720..af033c7d05 100644 --- a/frontend/src/lib/components/sessions/sessionState.svelte.ts +++ b/frontend/src/lib/components/sessions/sessionState.svelte.ts @@ -384,9 +384,23 @@ export const sessionState = $state<{ // Keyed per session: a single shared timer would let a keystroke in one draft // cancel a sibling draft's pending flush, dropping that draft's first-touch write. const draftPromptFlushHandles = new Map>() + +// The composer's unsent input in a session already sent, which a chat column mounted again +// reads back: the composer's draft is component-local, and the sessions view unmounts on the +// pages outside the logged layout (`/user/*`). Kept apart from `draftPrompt` and +// `draftAttachments`, which hold the first message until the commit consumes it. In memory +// only: a reload drops it. +const sentSessionDraftText = new Map() +const sentSessionDraftAttachments = new Map() + export function setSessionDraftPrompt(sessionId: string, text: string): void { const s = sessionState.sessions.find((x) => x.id === sessionId) - if (!s || s.workspace_id) return + if (!s) return + if (s.workspace_id) { + if (text === '') sentSessionDraftText.delete(sessionId) + else sentSessionDraftText.set(sessionId, text) + return + } // No-op on an unchanged prompt, so opening an untouched draft never persists // it. Writes of '' are real edits (a draft typed then erased is still a // session), which is why the composer reports edits only — see AIChatInput. @@ -406,12 +420,10 @@ export function setSessionDraftPrompt(sessionId: string, text: string): void { ) } -// Read back the persisted composer text when a pending session's chat mounts. -// Returns nothing once the session is committed (its draft prompt was consumed). export function getSessionDraftPrompt(sessionId: string): string | undefined { const s = sessionState.sessions.find((x) => x.id === sessionId) - if (!s || s.workspace_id) return undefined - return s.draftPrompt + if (!s) return undefined + return s.workspace_id ? sentSessionDraftText.get(sessionId) : s.draftPrompt } // The rest of an unsent draft (collapsed pastes, images, files), so a composer mounted again @@ -424,10 +436,15 @@ export function setSessionDraftAttachments(sessionId: string, attachments: Draft const empty = Object.values(attachments).every((lane) => lane.length === 0) if (empty) { draftAttachments.delete(sessionId) + sentSessionDraftAttachments.delete(sessionId) return } const s = sessionState.sessions.find((x) => x.id === sessionId) - if (!s || s.workspace_id) return + if (!s) return + if (s.workspace_id) { + sentSessionDraftAttachments.set(sessionId, attachments) + return + } draftAttachments.set(sessionId, attachments) // Attaching is a touch, as typing is: a draft holding only an image would otherwise still // read as a blank, be reused by the next hand-off with the image in it, or be dropped. @@ -436,8 +453,10 @@ export function setSessionDraftAttachments(sessionId: string, attachments: Draft export function getSessionDraftAttachments(sessionId: string): DraftAttachments | undefined { const s = sessionState.sessions.find((x) => x.id === sessionId) - if (!s || s.workspace_id) return undefined - return draftAttachments.get(sessionId) + if (!s) return undefined + return s.workspace_id + ? sentSessionDraftAttachments.get(sessionId) + : draftAttachments.get(sessionId) } // A hand-off arrives within a navigation; anything older than this is the debris @@ -1682,6 +1701,8 @@ export function deleteSession(id: string) { clearTimeout(draftPromptFlushHandles.get(id)) draftPromptFlushHandles.delete(id) draftAttachments.delete(id) + sentSessionDraftText.delete(id) + sentSessionDraftAttachments.delete(id) sessionState.sessions = sessionState.sessions.filter((x) => x.id !== id) if (sessionState.currentSessionId === id) { sessionState.currentSessionId = sessionState.sessions[0]?.id diff --git a/frontend/src/lib/components/sessions/sessionState.test.ts b/frontend/src/lib/components/sessions/sessionState.test.ts index 3c6d7f6d27..8241abcdeb 100644 --- a/frontend/src/lib/components/sessions/sessionState.test.ts +++ b/frontend/src/lib/components/sessions/sessionState.test.ts @@ -5,6 +5,7 @@ import { createSession, decideSessionLifecycle, getSessionDraftAttachments, + getSessionDraftPrompt, holdHomeDraft, holdSessionUntilStarted, homeDraft, @@ -690,6 +691,34 @@ describe('createSession — reuses an untouched draft, family-scoped', () => { }) }) +describe('composer draft of a sent session', () => { + it('reads back the follow-up, never the first message, and empties with the composer', () => { + sessionState.sessions.push(session({ id: 'sent-draft', draftPrompt: 'first message' })) + const pastes = [{} as PasteAttachment] + try { + setSessionDraftAttachments('sent-draft', { ...NO_ATTACHMENTS, pastes }) + sessionState.sessions.find((x) => x.id === 'sent-draft')!.workspace_id = 'ws' + // The record's draft prompt and the staged attachments are the first message: read + // back after the send, they would put it in the composer a second time. + expect(getSessionDraftPrompt('sent-draft')).toBeUndefined() + expect(getSessionDraftAttachments('sent-draft')).toBeUndefined() + + setSessionDraftPrompt('sent-draft', 'follow-up') + setSessionDraftAttachments('sent-draft', { ...NO_ATTACHMENTS, pastes }) + expect(getSessionDraftPrompt('sent-draft')).toBe('follow-up') + expect(getSessionDraftAttachments('sent-draft')).toEqual({ ...NO_ATTACHMENTS, pastes }) + + setSessionDraftPrompt('sent-draft', '') + setSessionDraftAttachments('sent-draft', NO_ATTACHMENTS) + expect(getSessionDraftPrompt('sent-draft')).toBeUndefined() + expect(getSessionDraftAttachments('sent-draft')).toBeUndefined() + } finally { + setSessionDraftAttachments('sent-draft', NO_ATTACHMENTS) + sessionState.sessions = sessionState.sessions.filter((s) => s.id !== 'sent-draft') + } + }) +}) + describe('withOpenSessionTeardown — the gate that holds recovery off during a delete', () => { it('stays shut until the outermost teardown finishes', async () => { let innerDone = false diff --git a/frontend/src/routes/(root)/(logged)/+layout.svelte b/frontend/src/routes/(root)/(logged)/+layout.svelte index ba66d10c3d..8a27dac8cc 100644 --- a/frontend/src/routes/(root)/(logged)/+layout.svelte +++ b/frontend/src/routes/(root)/(logged)/+layout.svelte @@ -978,6 +978,15 @@ } let devOnly = $derived(page.url.pathname.startsWith('/scripts/dev')) + // The desktop rail is fixed-positioned, so the content is offset by its width (in rem). + let contentInset = $derived(devOnly || menuHidden || useDrawer ? 0 : railWidth) + // The sessions view is mounted once opened and then kept, hidden on other pages, so its + // chats keep their scroll, composer and expanded tool cards when the user comes back. + // Never in a preview iframe: it would nest the sessions UI, with its iframes, in itself. + let sessionsViewOpened = false + const sessionsViewRequested = $derived.by( + () => (sessionsViewOpened ||= onSessionsPage && !embedded) + ) // A devops user who belongs to no workspace has no `$userStore`, and would otherwise wait on // "Loading user..." forever on the instance pages their role exists for. let instanceOnlyView = $derived( @@ -1739,17 +1748,45 @@ outside this layout, and their shortcut must reopen the URL that is their creden
{/if} - -
-
- {@render children?.()} + +
+ +
+
+ {@render children?.()} +
+ {#if sessionsViewRequested} + +
+
+ {#await import('$lib/components/sessions/SessionsView.svelte') then SessionsView} + + {/await} +
+
+ {/if}
diff --git a/frontend/src/routes/(root)/(logged)/sessions/+page.svelte b/frontend/src/routes/(root)/(logged)/sessions/+page.svelte index 645760f524..207f0a65fe 100644 --- a/frontend/src/routes/(root)/(logged)/sessions/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/sessions/+page.svelte @@ -1,1474 +1,28 @@ - - - - { - if (document.visibilityState === 'hidden') owner?.flushNow() - }} -/> - - - - - -{#snippet fullscreenBand()} - -
- {@render previewTabStrip(true)} -
-
- {@render previewControls()} -
+{#if embedded} +
+

Sessions can't open inside a preview

+

This page is being previewed in a session panel. Open it at the top level instead.

+
-{/snippet} - -{#snippet sessionPageActions()} - {#if previewCollapsed && !fullscreen} - - - - - {/if} -{/snippet} - -
- {#if embedded} - -
-

Sessions can't open inside a preview

-

This page is being previewed in a session panel. Open it at the top level instead.

- -
- {:else if !sessionState.hydrated} - -
- -
- {:else if !requestsSession || !activeSession || leaving} - -
- -
- {:else} - -
- -
- - - - - - -
- {#each mountedChatSessions as s (s.id)} -
- - tabNameFor(tab, getEffectiveWorkspaceId(s) ?? $workspaceStore ?? '')} - /> -
- {/each} -
-
- - - - -
previewWidth, - (w) => { - previewWidth = w - if (!fullscreen && !panesAnimating && contentWidth > 0) - panelShare = w / contentWidth - } - } - class="flex-1 min-h-0 flex flex-col {bandFullscreen - ? `p-0 ${BAR_TOP_PAD}` - : fullscreen - ? `px-2 pb-2 ${BAR_TOP_PAD}` - : 'p-2 pl-0'}" - > - -
- {#if !bandFullscreen} - - - {/if} - - - {#if !bandFullscreen} - -
- {@render previewControls()} -
- - {@render previewTabStrip(false)} - {/if} - - -
- {#if previewTabHostComponent.current} - {@const TabHost = previewTabHostComponent.current} - {#each warmHosts as { session: s, runtime: rt } (s.id)} - {@const tabs = rt.previewTabs} - {#each tabs?.tabs ?? [] as tab (tab.id)} - - - tabs && onTabLoad(tabs, tab, frame)} - /> - {/each} - {/each} - {/if} - {#if (owner?.tabs.length ?? 0) === 0} - -
- -
- No preview open - Open a page, flow, script or app to preview it alongside the chat. -
- - {#snippet trigger()} - - Open a preview - - {/snippet} - {#snippet content()} - { - emptyStateNewTabOpen = false - openInNewTab(t) - }} - /> - {/snippet} - -
- {/if} -
-
-
-
-
-
- {#if firstVerdictPending} -
- -
- {:else if aiHiddenVerdict} - - -
-

AI Sessions are hidden in this workspace

-

A workspace admin hid AI sessions in the workspace settings.

- -
- {/if} -
- {/if} -
- - -{#snippet previewControls()} - {#if activeWorkspaceHref} - - - - {/if} - {#if narrowScreen.current} - - {:else if fullscreen} - - - {:else} - - {/if} -{/snippet} - -{#snippet previewTabStrip(inBand: boolean)} - -
- (activeTabPickerOpen = !activeTabPickerOpen)} - onClose={closeTab} - onReorder={reorderTabs} - size={inBand ? 'md' : 'sm'} - class={inBand - ? 'session-preview-tab-strip h-full bg-transparent min-w-0' - : 'session-preview-tab-strip h-8 border-b border-light bg-surface-secondary/50 pl-9 pr-[var(--preview-actions-w,4rem)]'} - > - {#snippet tabAccessory(_tab, isActive)} - {#if isActive} - - - (e.currentTarget as HTMLElement).closest('[role="tab"]')?.focus() - }} - > - {#snippet content()} - - {#key activePickerScope?.dir ?? ''} - { - activeTabPickerOpen = false - navigatePreviewTo(t) - }} - /> - {/key} - {/snippet} - - - {/if} - {/snippet} - {#snippet afterTabs()} - - {#snippet trigger()} - - {/snippet} - {#snippet content()} - { - newTabOpen = false - openInNewTab(t) - }} - /> - {/snippet} - - {/snippet} - -
-{/snippet} - - +{/if}