From d32f1ea33539b3329caebfb6d9659336e3ea2687 Mon Sep 17 00:00:00 2001 From: Guilhem Lemouel Date: Thu, 15 Oct 2026 08:15:33 -0700 Subject: [PATCH] feat: home and empty ai sessions share one session composer --- frontend/src/lib/assets/app.css | 25 + .../lib/components/copilot/chat/AIChat.svelte | 12 +- .../copilot/chat/AIChatDisplay.svelte | 699 ++++++++++-------- .../copilot/chat/AIChatInput.svelte | 66 +- .../copilot/chat/AIChatManager.svelte.ts | 6 +- .../copilot/chat/AutonomyModePicker.svelte | 2 +- .../copilot/chat/ContextTextarea.svelte | 8 +- .../components/copilot/chat/chatViewHost.ts | 4 + .../copilot/chat/composerGlide.svelte.ts | 46 ++ .../chat/starter/BuildWithAIHeading.svelte | 10 - .../chat/starter/SessionGreeting.svelte | 30 + .../copilot/chat/starter/greeting.test.ts | 41 + .../copilot/chat/starter/greeting.ts | 37 + .../chat/starter/starterPrompts.svelte.ts | 49 +- .../conversations/flowChatViewHost.svelte.ts | 3 + .../src/lib/components/home/HomeAIChat.svelte | 302 ++------ .../components/sessions/ActingOnPicker.svelte | 34 - .../sessions/HomeSessionStarter.svelte | 84 +++ .../sessions/SessionWorkspaceBar.svelte | 18 +- .../components/sessions/SessionWrapper.svelte | 23 +- .../sessions/homeSessionsTransition.svelte.ts | 68 ++ .../sessions/homeSessionsTransition.test.ts | 14 + .../sessions/sessionRuntime.svelte.ts | 19 +- .../sessions/sessionState.svelte.ts | 83 ++- .../components/sessions/sessionState.test.ts | 63 ++ .../sessions/sessionSwitch.svelte.ts | 30 +- .../src/routes/(root)/(logged)/+layout.svelte | 5 +- .../src/routes/(root)/(logged)/+page.svelte | 8 +- .../(root)/(logged)/sessions/+page.svelte | 26 +- 29 files changed, 1135 insertions(+), 680 deletions(-) create mode 100644 frontend/src/lib/components/copilot/chat/composerGlide.svelte.ts delete mode 100644 frontend/src/lib/components/copilot/chat/starter/BuildWithAIHeading.svelte create mode 100644 frontend/src/lib/components/copilot/chat/starter/SessionGreeting.svelte create mode 100644 frontend/src/lib/components/copilot/chat/starter/greeting.test.ts create mode 100644 frontend/src/lib/components/copilot/chat/starter/greeting.ts delete mode 100644 frontend/src/lib/components/sessions/ActingOnPicker.svelte create mode 100644 frontend/src/lib/components/sessions/HomeSessionStarter.svelte create mode 100644 frontend/src/lib/components/sessions/homeSessionsTransition.svelte.ts create mode 100644 frontend/src/lib/components/sessions/homeSessionsTransition.test.ts diff --git a/frontend/src/lib/assets/app.css b/frontend/src/lib/assets/app.css index 4217c95831..beca747907 100644 --- a/frontend/src/lib/assets/app.css +++ b/frontend/src/lib/assets/app.css @@ -426,3 +426,28 @@ input[type='time']::-webkit-calendar-picker-indicator { .svelte-flow__edges { z-index: -10; } + +/* The composer's glide, defined once: the Home ↔ AI Sessions view transition below and the + in-page move on a session's first message (composerGlide.svelte.ts) both read it. */ +:root { + --composer-glide-duration: 200ms; + --composer-glide-easing: cubic-bezier(0.2, 0, 0, 1); +} + +/* Home ↔ AI Sessions (homeSessionsTransition.svelte.ts). The session heading and composer + glide from where they were to where they land; everything else, Home's list included, is + the page cross-fading, kept short. The pseudo-elements hang off :root itself, so no space + before `::view-transition-*`: with one, the selector looks for a descendant and never + matches. */ +:root[data-home-sessions-transition]::view-transition-group(session-heading), +:root[data-home-sessions-transition]::view-transition-group(session-composer) { + animation-duration: var(--composer-glide-duration); + animation-timing-function: var(--composer-glide-easing); +} +:root[data-home-sessions-transition]::view-transition-old(root), +:root[data-home-sessions-transition]::view-transition-new(root) { + animation-duration: 150ms; +} +:root[data-home-sessions-transition='fade'] * { + view-transition-name: none !important; +} diff --git a/frontend/src/lib/components/copilot/chat/AIChat.svelte b/frontend/src/lib/components/copilot/chat/AIChat.svelte index 4b42ea7364..e7973c9967 100644 --- a/frontend/src/lib/components/copilot/chat/AIChat.svelte +++ b/frontend/src/lib/components/copilot/chat/AIChat.svelte @@ -18,7 +18,9 @@ forceDisabledMessage = '', wideLayout = false, emptyHint, - starterPrompts = undefined, + starter = undefined, + viewTransitionNames = false, + onSent = undefined, inputPreface, initialInstructions = undefined, onDraftChange = undefined @@ -36,7 +38,9 @@ // in; the narrow global-chat panel leaves it off. wideLayout?: boolean emptyHint?: import('svelte').Snippet - starterPrompts?: import('$lib/onboardingProfile').StarterPrompt[] + starter?: import('./starter/starterPrompts.svelte').ChatStarter + viewTransitionNames?: boolean + onSent?: () => void inputPreface?: import('svelte').Snippet // Seed / observe the composer's draft text (forwarded to AIChatDisplay). initialInstructions?: string @@ -200,7 +204,9 @@ {hideModeSelector} {wideLayout} {emptyHint} - {starterPrompts} + {starter} + {viewTransitionNames} + {onSent} {inputPreface} {initialInstructions} {onDraftChange} diff --git a/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte b/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte index 6b6767a5c2..f4ec745ae3 100644 --- a/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte +++ b/frontend/src/lib/components/copilot/chat/AIChatDisplay.svelte @@ -68,9 +68,10 @@ import { sendUserToast } from '$lib/toast' import Alert from '$lib/components/common/alert/Alert.svelte' import { copilotInfo } from '$lib/aiStore' - import type { StarterPrompt } from '$lib/onboardingProfile' - import BuildWithAIHeading from './starter/BuildWithAIHeading.svelte' - import { RotatingPlaceholder } from './starter/starterPrompts.svelte' + import SessionGreeting from './starter/SessionGreeting.svelte' + import StarterPromptChips from './starter/StarterPromptChips.svelte' + import { RotatingPlaceholder, type ChatStarter } from './starter/starterPrompts.svelte' + import { glideOnLayoutChange } from './composerGlide.svelte' const MAX_YOLO_TOOLTIP_TOOLS = 8 const chatHost = getChatViewHost() @@ -109,7 +110,9 @@ hideModeSelector = false, wideLayout = false, emptyHint, - starterPrompts = undefined, + starter = undefined, + viewTransitionNames = false, + onSent = undefined, inputPreface, footerSettings, initialInstructions = undefined, @@ -142,10 +145,17 @@ // off there. wideLayout?: boolean emptyHint?: Snippet - /** Open an empty chat the way Home's composer looks: the "Build with AI" heading, a - * taller box cycling through these prompts as its placeholder. Sessions - * set it so the two read as the same entry point. Replaces `emptyHint`. */ - starterPrompts?: StarterPrompt[] + /** Open an empty chat as the block that starts a session: Home and an empty session + * both mount it, so the two are one entry point rather than look-alikes. Replaces + * `emptyHint`. */ + starter?: ChatStarter + /** Names the block for the view transition between Home and AI Sessions. Only one + * chat on the page may carry the names: a duplicate makes the browser skip the + * transition. Named only while the chat is empty: the glide carries Home's draft to + * the same draft's page and back, and a session already under way just cross-fades. */ + viewTransitionNames?: boolean + /** After the composer hands a new turn to the host. */ + onSent?: () => void inputPreface?: Snippet /** The settings control at the footer's right edge, where the copilot puts its * model picker. A host that configures its turn elsewhere replaces it here. */ @@ -293,13 +303,10 @@ } $effect(() => { - if (aiChatInput) { - chatHost.setAiChatInput(aiChatInput) - } - - return () => { - chatHost.setAiChatInput(null) - } + const input = aiChatInput + if (!input) return + chatHost.setAiChatInput(input) + return () => chatHost.releaseAiChatInput(input) }) // Also shown for a run held by another tab, labeled with where it is: the @@ -560,11 +567,21 @@ // A step name hangs its icon in the column's left padding (see AssistantMessage), so a // transcript carrying one widens the padding, on both sides to keep the column centred. const agentGutter = $derived(messages.some((m) => m.role === 'assistant' && m.stepName)) - const starterHero = $derived(!!starterPrompts && messages.length === 0 && !disabled) + // The block's layout holds while the chat is empty, usable or not; only the rotating + // placeholder, the taller box and the prompts need a composer that can send. + const starterLayout = $derived(!!starter && messages.length === 0) + const starterHero = $derived(starterLayout && !disabled) + // Home is a page, not a pane: nothing there to centre in. + const centreComposer = $derived(starterLayout && starter?.where === 'session') const starterPlaceholder = new RotatingPlaceholder( - () => (starterPrompts ?? []).map((p) => p.prompt), + () => (starter?.prompts ?? []).map((p) => p.prompt), () => starterHero ) + let composerEl: HTMLDivElement | undefined = $state() + glideOnLayoutChange( + () => composerEl, + () => starterLayout + ) const columnClass = $derived( wideLayout @@ -673,9 +690,7 @@
{/if} {#if messages.length === 0} - {#if starterPrompts} -
- + {#if starter} + +
+
+ +
{:else if emptyHint} {@render emptyHint()} @@ -909,8 +932,14 @@ the panel, or the Escape-to-stop focus check would wrongly reject them. --> - -
+
{#if showFlowPendingActionControls}
{/if} - {#if showAutonomyModeSelector} - - {/if} - {#if effectiveAutonomyMode === AIAutonomyMode.PLAN} - {PLAN_MODE_MESSAGES.modeNote} - {/if} - {#if effectiveAutonomyMode === AIAutonomyMode.YOLO && chatHost.autoAcceptToolConfirmationsAvailable} - - - {#snippet text()} -
-

- {chatHost.autoAcceptEditsAvailable - ? 'Bypass permissions auto-accepts edits and tool usage.' - : 'Bypass permissions auto-accepts tool usage.'} -

-

- {chatHost.autoAcceptEditsAvailable - ? 'This can result in edits being applied or tools being called without user confirmation.' - : 'This can result in tools being called without user confirmation.'} -

- {#if yoloBypassedTools.length > 0} -

Bypassed in current mode:

-
    - {#each visibleYoloBypassedTools as tool (tool.name)} -
  • {tool.label}
  • - {/each} -
- {#if hiddenYoloBypassedToolCount > 0} -

+ {hiddenYoloBypassedToolCount} more

- {/if} - {:else} -

No tools in the current mode require confirmation.

- {/if} -
- {/snippet} -
- {/if} - {#if chatHost.mode === AIMode.SCRIPT && hasDiff && !disabled} - - {/if} -
- {/if} - {#if footerMessageShown} -
- -
- {:else} -
- {#if chatHost.mode === AIMode.GLOBAL} - - {/if} - {#if !hideModeSelector} - - {/if} - {#if chatHost.mode === AIMode.APP} - - {/if} - - {#if chatHost.supportsModelSettings} - - - {/if} - {@render footerSettings?.()} - {#if chatHost.mode === AIMode.GLOBAL} - - {/if} + + {/if} + {@render footerSettings?.()} + {#if chatHost.mode === AIMode.GLOBAL} + + {/if} - {#if chatHost.mode === AIMode.APP && appContext && (appContext.inspectorElement || appContext.codeSelection)} - {#if appContext.inspectorElement} -
- - - {appContext.inspectorElement.tagName.toLowerCase()}{appContext.inspectorElement - .id - ? `#${appContext.inspectorElement.id}` - : ''}{appContext.inspectorElement.className - ? `.${appContext.inspectorElement.className.split(' ')[0]}` - : ''} - - -
- {/if} - {#if appContext.codeSelection} -
- - - L{appContext.codeSelection.startLine}-{appContext.codeSelection.endLine} - - -
- {/if} + {#if chatHost.mode === AIMode.APP && appContext && (appContext.inspectorElement || appContext.codeSelection)} + {#if appContext.inspectorElement} +
+ + + {appContext.inspectorElement.tagName.toLowerCase()}{appContext + .inspectorElement.id + ? `#${appContext.inspectorElement.id}` + : ''}{appContext.inspectorElement.className + ? `.${appContext.inspectorElement.className.split(' ')[0]}` + : ''} + + +
+ {/if} + {#if appContext.codeSelection} +
+ + + L{appContext.codeSelection.startLine}-{appContext.codeSelection.endLine} + + +
+ {/if} + {/if} +
{/if}
- {/if} -
+ {/snippet} + + {#if starterLayout && starter} + {#if showFreeTierUsage} +
+ {freeTierUsedPct}% of free AI used · + +
+ {/if} + {#if starter.chips && !disabled} +
+ aiChatInput?.setText(prompt)} + /> +
+ {/if} + {/if} {#if (chatHost.mode === AIMode.NAVIGATOR || chatHost.mode === AIMode.ASK) && suggestions.length > 0 && messages.filter((m) => m.role === 'user').length === 0 && !disabled}
@@ -1303,4 +1361,7 @@ the panel, or the Escape-to-stop focus check would wrongly reject them. -->
{/if}
+ {#if centreComposer} +
+ {/if} diff --git a/frontend/src/lib/components/copilot/chat/AIChatInput.svelte b/frontend/src/lib/components/copilot/chat/AIChatInput.svelte index e341c8de55..cf5111698c 100644 --- a/frontend/src/lib/components/copilot/chat/AIChatInput.svelte +++ b/frontend/src/lib/components/copilot/chat/AIChatInput.svelte @@ -14,6 +14,11 @@ import { CHAT_INPUT_PADDING, getAiChatManager } from './aiChatManagerContext' import { getChatViewHost } from './chatViewHost' import { composerBoxClass, COMPOSER_FIELD_RESET } from './composerBox' + + // The send button sits in the toolbar row, not over the field, so the text needs no + // room reserved on its right, and the row right below it stands in for most of its + // bottom padding. + const FIELD_PADDING_WITH_TOOLBAR = '!pr-3 !pb-1' import { formatMention, hasMention, removeMentionFromText } from './mention' import { twMerge } from 'tailwind-merge' import { tick, untrack, type Snippet } from 'svelte' @@ -93,9 +98,16 @@ // plain-text draft sent from here answers it instead of queueing behind a // turn that only the answer can resume. pendingQuestionToolCallId?: string - /** Forwarded to ContextTextarea: the composer that opens a session. */ + /** The composer that opens a session (Home, an empty session): `toolbar` is drawn in the + * box's bottom row with the send button at its end, and a usable box is taller. Otherwise + * the controls sit under the box and the send button floats over the field's corner, as a + * chat under way reads more clearly. */ hero?: boolean fadingPlaceholder?: { text: string; visible: boolean } + /** After a new turn is handed to the host — not an edit, a queued message or an answer. */ + onSent?: () => void + /** The composer's controls. */ + toolbar?: Snippet } let { @@ -120,10 +132,14 @@ onCancel, onDraftChange = undefined, pendingQuestionToolCallId = undefined, + onSent = undefined, + toolbar = undefined, hero = false, fadingPlaceholder = undefined }: Props = $props() + const toolbarInBox = $derived(!!toolbar && hero) + // GLOBAL-mode suggestion pool. We pick one at mount-time so each new // session lands on a different prompt; the choice stays stable for // the lifetime of this input so the placeholder doesn't shuffle as @@ -641,6 +657,13 @@ draft.text = removeMentionFromText(draft.text, title) } + /** Replace the draft's text, keeping its attachments: a starter prompt fills the box, it + * never sends. */ + export function setText(text: string) { + draft.text = text + focusInput() + } + export function focusInput() { if (isContextEnabledMode) { contextTextareaComponent?.focus() @@ -982,6 +1005,7 @@ // textarea still rely on the draft reset alone (no `@`-mention state to // coordinate). contextTextareaComponent?.clearForSend() + onSent?.() } } @@ -1212,7 +1236,18 @@ } -{#snippet sendStopButton()} +{#snippet toolbarRow()} + {#if toolbarInBox} + +
+
{@render toolbar?.()}
+ {@render sendStopButton('sm')} +
+ {/if} +{/snippet} + +{#snippet sendStopButton(size: 'sm' | 'md' = 'md')} @@ -1237,9 +1272,11 @@ (onSendRequest !== undefined || chatHost.mode !== AIMode.GLOBAL || selectedContext.length === 0))} + -
- (pickedAutonomyMode = mode)} - /> - -
- - {#if disabled} - -
-

- {#if $aiUserDisabled} - Windmill AI is disabled in your account settings - {:else if freeTierExhausted} - You have used all of your free Windmill AI tokens - {:else} - No AI provider is configured - {/if} -

-
- {#if $aiUserDisabled} - - - {:else} - - {/if} - -
-
- {/if} +
+ {#if hero} +
+
- {/if} - -
- {#if showComposer && !collapsed} - (value = p)} /> + + + {#if sessionState.hydrated && $copilotWorkspace !== undefined && (rulesReady || shownForRoot === $currentWorkspaceRootId)} + {#key $currentWorkspaceRootId} + (shownForRoot = $currentWorkspaceRootId)} /> + {/key} {/if} -
+ {/if}
diff --git a/frontend/src/lib/components/sessions/ActingOnPicker.svelte b/frontend/src/lib/components/sessions/ActingOnPicker.svelte deleted file mode 100644 index 7f8771a4dc..0000000000 --- a/frontend/src/lib/components/sessions/ActingOnPicker.svelte +++ /dev/null @@ -1,34 +0,0 @@ - - - -
- Acting on - - {#snippet trigger()} - - {/snippet} - -
diff --git a/frontend/src/lib/components/sessions/HomeSessionStarter.svelte b/frontend/src/lib/components/sessions/HomeSessionStarter.svelte new file mode 100644 index 0000000000..e9d59ed438 --- /dev/null +++ b/frontend/src/lib/components/sessions/HomeSessionStarter.svelte @@ -0,0 +1,84 @@ + + +{#snippet inputPreface()} + {#if session} + + {/if} +{/snippet} + +{#if session} + +{/if} diff --git a/frontend/src/lib/components/sessions/SessionWorkspaceBar.svelte b/frontend/src/lib/components/sessions/SessionWorkspaceBar.svelte index 26c6875839..1a992b818b 100644 --- a/frontend/src/lib/components/sessions/SessionWorkspaceBar.svelte +++ b/frontend/src/lib/components/sessions/SessionWorkspaceBar.svelte @@ -6,7 +6,8 @@ setSessionPendingWorkspace, type Session } from './sessionState.svelte' - import ActingOnPicker from './ActingOnPicker.svelte' + import WorkspaceFamilyPicker from './WorkspaceFamilyPicker.svelte' + import WorkspaceScopeTrigger from '$lib/components/WorkspaceScopeTrigger.svelte' let { session }: { session: Session } = $props() @@ -27,4 +28,17 @@ } - +
+ Acting on + + {#snippet trigger()} + + {/snippet} + +
diff --git a/frontend/src/lib/components/sessions/SessionWrapper.svelte b/frontend/src/lib/components/sessions/SessionWrapper.svelte index ed8d6a1571..532a888733 100644 --- a/frontend/src/lib/components/sessions/SessionWrapper.svelte +++ b/frontend/src/lib/components/sessions/SessionWrapper.svelte @@ -73,7 +73,14 @@ // Reactive session reference (mutations to summary/target propagate via the $state proxy) const session = $derived(sessionState.sessions.find((s) => s.id === sessionId)) - const starterPrompts = new StarterPrompts() + // Only a session that has never sent opens as the starter block. Read off the record, not + // the transcript: a cold session's history is still loading from storage when it mounts, + // and an empty transcript would show the greeting and then glide the composer away. + // The first send commits the workspace, so this flips only after the transcript has. + const opensSession = $derived(!session?.workspace_id) + const starterPrompts = new StarterPrompts(() => + opensSession ? (actingWorkspaceId ?? $workspaceStore ?? undefined) : undefined + ) // Seed the composer with the unsent prompt a reload preserved on the session // record (script-init: AIChatInput reads it once at mount). @@ -309,6 +316,10 @@ {#if !session || !runtime}
Session not found
{:else} + + {#snippet sessionEmptyHint()}{/snippet} + {#snippet inputPreface()} {#if showRecoveryNotice}