The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
feat(assistant): TREK Studio's assistant floats in the planner's window instead of a column
Maurice51c59e28b861
diff --git a/client/src/components/Assistant/AssistantFrameEdges.tsx b/client/src/components/Assistant/AssistantFrameEdges.tsxnew file mode 100644index 000000000..c51c6784e--- /dev/null+++ b/client/src/components/Assistant/AssistantFrameEdges.tsx@@ -0,0 +1,39 @@+import type { ResizeEdge, useDragResize } from '../../hooks/useDragResize';++/** The invisible grips of the floating assistant window (assistantFrame.ts) along its edges and corners. */++const EDGES: { edge: ResizeEdge; className: string; cursor: 'ns' | 'ew' | 'corner-start' | 'corner-end' }[] = [+ { edge: 'n', className: 'inset-x-3 -top-1 h-2', cursor: 'ns' },+ { edge: 's', className: 'inset-x-3 -bottom-1 h-2', cursor: 'ns' },+ { edge: 'start', className: 'inset-y-3 -start-1 w-2', cursor: 'ew' },+ { edge: 'end', className: 'inset-y-3 -end-1 w-2', cursor: 'ew' },+ { edge: 'n-start', className: '-start-1 -top-1 h-4 w-4', cursor: 'corner-start' },+ { edge: 's-end', className: '-bottom-1 -end-1 h-4 w-4', cursor: 'corner-start' },+ { edge: 'n-end', className: '-end-1 -top-1 h-4 w-4', cursor: 'corner-end' },+ { edge: 's-start', className: '-bottom-1 -start-1 h-4 w-4', cursor: 'corner-end' },+];++function edgeCursor(kind: (typeof EDGES)[number]['cursor'], rtl: boolean): string {+ if (kind === 'ns') return 'ns-resize';+ if (kind === 'ew') return 'ew-resize';+ // The top-start corner is the top left in a left-to-right page and the top right in Arabic.+ return (kind === 'corner-start') !== rtl ? 'nwse-resize' : 'nesw-resize';+}++/** The invisible grips along the frame's edges and corners. */+export default function AssistantFrameEdges({ frame }: { frame: ReturnType<typeof useDragResize> }) {+ const rtl = typeof document !== 'undefined' && document.documentElement.dir === 'rtl';+ return (+ <>+ {EDGES.map(({ edge, className, cursor }) => (+ <div+ key={edge}+ aria-hidden="true"+ {...frame.edgeProps(edge)}+ className={`absolute z-10 touch-none ${className}`}+ style={{ cursor: edgeCursor(cursor, rtl) }}+ />+ ))}+ </>+ );+}diff --git a/client/src/components/Assistant/AssistantWindow.tsx b/client/src/components/Assistant/AssistantWindow.tsxindex 48b986ba9..e38b57bf1 100644--- a/client/src/components/Assistant/AssistantWindow.tsx+++ b/client/src/components/Assistant/AssistantWindow.tsx@@ -4,13 +4,15 @@ import { Sparkles, X } from 'lucide-react';import { type CSSProperties, type KeyboardEvent, useCallback, useEffect, useRef, useState } from 'react';import { useNavigate } from 'react-router';-import { type ResizeEdge, type WindowRect, type WindowSize, useDragResize } from '../../hooks/useDragResize';+import type { WindowRect } from '../../hooks/useDragResize';import { useTranslation } from '../../i18n';import { useAssistantStore } from '../../store/assistantStore';+import AssistantFrameEdges from './AssistantFrameEdges';import AssistantHeader from './AssistantHeader';import AssistantLauncher, { LAUNCHER_INSET, LAUNCHER_SIZE } from './AssistantLauncher';import AssistantSurfaceLazy from './AssistantSurfaceLazy';import AssistantTripPicker from './AssistantTripPicker';+import { FRAME_CLASS, useAssistantFrame } from './assistantFrame';import { plannerSearchOf } from './assistantShowOnMap';import type { EntityTarget } from './cards/cardTypes';import { useAssistantHotkey } from './useAssistantHotkey';@@ -44,6 +46,8 @@ interface AssistantWindowProps {onOpen?: (target: EntityTarget) => void;/** Selects a day in the planner on screen. */onFocusDay?: (dayId: number) => void;+ /** Brings the planner's map on screen, from whichever of its tabs is open. */+ onRevealMap?: () => void;}/** Narrower than this, the chat lays its cards out compact. */@@ -51,45 +55,6 @@ const ROOMY_WIDTH = 480;/** Where the window's place and size are kept between visits. */const WINDOW_STORAGE = 'trek.assistantWindow';-const MIN_SIZE: WindowSize = { width: 340, height: 420 };-const DEFAULT_SIZE: WindowSize = { width: 400, height: 600 };-/** Never closer to the screen's edge than this. */-const MARGIN = 16;-/** The default distance from the edges, and how near a corner a released window snaps into it. */-const GAP = 24;-const expandedSize = (viewport: WindowSize): WindowSize => ({- width: Math.min(720, viewport.width - 2 * MARGIN),- height: Math.round(viewport.height * 0.8),-});--const EDGES: { edge: ResizeEdge; className: string; cursor: 'ns' | 'ew' | 'corner-start' | 'corner-end' }[] = [- { edge: 'n', className: 'inset-x-3 -top-1 h-2', cursor: 'ns' },- { edge: 's', className: 'inset-x-3 -bottom-1 h-2', cursor: 'ns' },- { edge: 'start', className: 'inset-y-3 -start-1 w-2', cursor: 'ew' },- { edge: 'end', className: 'inset-y-3 -end-1 w-2', cursor: 'ew' },- { edge: 'n-start', className: '-start-1 -top-1 h-4 w-4', cursor: 'corner-start' },- { edge: 's-end', className: '-bottom-1 -end-1 h-4 w-4', cursor: 'corner-start' },- { edge: 'n-end', className: '-end-1 -top-1 h-4 w-4', cursor: 'corner-end' },- { edge: 's-start', className: '-bottom-1 -start-1 h-4 w-4', cursor: 'corner-end' },-];--function edgeCursor(kind: (typeof EDGES)[number]['cursor'], rtl: boolean): string {- if (kind === 'ns') return 'ns-resize';- if (kind === 'ew') return 'ew-resize';- // The top-start corner is the top left in a left-to-right page and the top right in Arabic.- return (kind === 'corner-start') !== rtl ? 'nwse-resize' : 'nesw-resize';-}--/** The fixed navbar's height (`--nav-h`, a calc() and 0 where there is none), measured. */-function navbarHeight(): number {- if (typeof document === 'undefined') return 0;- const probe = document.createElement('div');- probe.style.cssText = 'position:fixed;visibility:hidden;height:var(--nav-h, 0px)';- document.body.appendChild(probe);- const height = probe.offsetHeight;- probe.remove();- return height;-}/** Where the floating button's middle sits inside the window, so the window grows out of it. */function originFrom(rect: WindowRect, rtl: boolean): string {@@ -104,28 +69,20 @@ function ChatWindow({hidden,onOpen,onFocusDay,+ onRevealMap,}: {trip: WindowTrip;hidden: boolean;onOpen?: (target: EntityTarget) => void;onFocusDay?: (dayId: number) => void;+ onRevealMap?: () => void;}) {const { t } = useTranslation();const thread = useAssistantThread(trip.id);const close = useAssistantStore((s) => s.close);const setMinimized = useAssistantStore((s) => s.setMinimized);const setWindowRect = useAssistantStore((s) => s.setWindowRect);- // The navbar sits on the same layer and later in the page: the head never goes under it.- const [topInset] = useState(navbarHeight);- const frame = useDragResize({- storageKey: WINDOW_STORAGE,- minSize: MIN_SIZE,- defaultSize: DEFAULT_SIZE,- expandedSize,- margin: MARGIN,- gap: GAP,- topInset,- });+ const frame = useAssistantFrame(WINDOW_STORAGE);const rtl = typeof document !== 'undefined' && document.documentElement.dir === 'rtl';const [origin] = useState(() => originFrom(frame.rect, rtl));const returnFocus = useRef<Element | null>(typeof document !== 'undefined' ? document.activeElement : null);@@ -182,19 +139,11 @@ function ChatWindow({hidden={hidden}onKeyDown={onKeyDown}style={style}- className={`trek-assistant-pop fixed z-[var(--z-nav)] ${hidden ? 'hidden' : 'flex'} flex-col overflow-visible rounded-xl border border-edge-faint bg-surface-elevated shadow-[var(--sidebar-shadow)] backdrop-blur-2xl backdrop-saturate-150 ${+ className={`trek-assistant-pop ${FRAME_CLASS} ${hidden ? 'hidden' : 'flex'} ${frame.active ? 'select-none' : 'trek-assistant-settle'}`}>- {EDGES.map(({ edge, className, cursor }) => (- <div- key={edge}- aria-hidden="true"- {...frame.edgeProps(edge)}- className={`absolute z-10 touch-none ${className}`}- style={{ cursor: edgeCursor(cursor, rtl) }}- />- ))}+ <AssistantFrameEdges frame={frame} /><div className="flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl"><AssistantHeadertripId={trip.id}@@ -212,13 +161,14 @@ function ChatWindow({density={width < ROOMY_WIDTH ? 'compact' : 'roomy'}onOpen={onOpen}onFocusDay={onFocusDay}+ onRevealMap={onRevealMap}/></div></section>);}-export default function AssistantWindow({ trip, onOpen, onFocusDay }: AssistantWindowProps) {+export default function AssistantWindow({ trip, onOpen, onFocusDay, onRevealMap }: AssistantWindowProps) {const navigate = useNavigate();const available = useAssistantStore((s) => s.status?.available === true);const open = useAssistantStore((s) => s.window.open);@@ -268,8 +218,9 @@ export default function AssistantWindow({ trip, onOpen, onFocusDay }: AssistantWtrip={current}hidden={minimized}onOpen={onScreen ? onOpen && openOnScreen : openPicked}- // Only the planner on screen has days to select.+ // Only the planner on screen has days to select and a map to bring back.onFocusDay={onScreen ? onFocusDay : undefined}+ onRevealMap={onScreen ? onRevealMap : undefined}/>{minimized && trip && <AssistantLauncher variant="floating" tripId={trip.id} focusOnMount />}</>diff --git a/client/src/components/Assistant/assistantFrame.ts b/client/src/components/Assistant/assistantFrame.tsnew file mode 100644index 000000000..ad2c119dd--- /dev/null+++ b/client/src/components/Assistant/assistantFrame.ts@@ -0,0 +1,50 @@+import { useState } from 'react';++import { type WindowSize, useDragResize } from '../../hooks/useDragResize';++/**+ * The floating window's frame, shared by the planner's window and TREK+ * Studio's: moved by its head, resized from any edge or corner, kept inside+ * the screen and below the navbar, remembered under its own key.+ */++const MIN_SIZE: WindowSize = { width: 340, height: 420 };+const DEFAULT_SIZE: WindowSize = { width: 400, height: 600 };+/** Never closer to the screen's edge than this. */+const MARGIN = 16;+/** The default distance from the edges, and how near a corner a released window snaps into it. */+const GAP = 24;+const expandedSize = (viewport: WindowSize): WindowSize => ({+ width: Math.min(720, viewport.width - 2 * MARGIN),+ height: Math.round(viewport.height * 0.8),+});++/** The fixed navbar's height (`--nav-h`, a calc() and 0 where there is none), measured. */+function navbarHeight(): number {+ if (typeof document === 'undefined') return 0;+ const probe = document.createElement('div');+ probe.style.cssText = 'position:fixed;visibility:hidden;height:var(--nav-h, 0px)';+ document.body.appendChild(probe);+ const height = probe.offsetHeight;+ probe.remove();+ return height;+}++/** The frame of a floating assistant window, its place and size kept under `storageKey`. */+export function useAssistantFrame(storageKey: string, topInsetPx?: number) {+ // The navbar sits on the same layer and later in the page: the head never goes under it.+ const [topInset] = useState(() => topInsetPx ?? navbarHeight());+ return useDragResize({+ storageKey,+ minSize: MIN_SIZE,+ defaultSize: DEFAULT_SIZE,+ expandedSize,+ margin: MARGIN,+ gap: GAP,+ topInset,+ });+}++/** The glass window's own classes; `active` while it is being moved or resized. */+export const FRAME_CLASS =+ 'fixed z-[var(--z-nav)] flex-col overflow-visible rounded-xl border border-edge-faint bg-surface-elevated shadow-[var(--sidebar-shadow)] backdrop-blur-2xl backdrop-saturate-150';diff --git a/client/src/components/Studio/StudioAssistantPanel.test.tsx b/client/src/components/Studio/StudioAssistantPanel.test.tsxindex 044b7fe8a..42c8dcc48 100644--- a/client/src/components/Studio/StudioAssistantPanel.test.tsx+++ b/client/src/components/Studio/StudioAssistantPanel.test.tsx@@ -1,15 +1,15 @@/*** FE-STUDIO-ASTPANEL-001 to FE-STUDIO-ASTPANEL-009*- * The assistant's column in TREK Studio (journey-studio.md 3.4, 4.5): the+ * The assistant's floating window in TREK Studio (journey-studio.md 3.4, 4.5): the* journey's chat with its own question; the notice that images of a page* leave only once the user agreed, for the connection on screen, that "Not* now" keeps it text for the visit, and that a model reading no images is- * never asked; every key inside the column belongs to the chat, so Studio+ * never asked; every key inside the window belongs to the chat, so Studio* neither closes nor edits the page's selection, and Escape stops a running* answer first, while Escape in the header's menu only closes the menu; the* journey's chat offers no trip notes, and its privacy banner speaks of the- * journey; the bar's switch and the column it opens.+ * journey; the bar's switch and the window it opens.*/import type { AiStatusResponse } from '@trek/shared';import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';@@ -101,7 +101,7 @@ describe('StudioAssistantPanel', () => {expect(screen.queryByRole('note')).toBeNull();});- it('FE-STUDIO-ASTPANEL-003: keys in the column stay there, Escape stops a running answer first', () => {+ it('FE-STUDIO-ASTPANEL-003: keys in the window stay there, Escape stops a running answer first', () => {const cancel = running();const studioKeys = vi.fn();window.addEventListener('keydown', studioKeys);@@ -200,7 +200,7 @@ describe('StudioAssistantPanel', () => {expect(screen.getByRole('button', { name: 'Assistant' })).toHaveClass('is-on');});- it('FE-STUDIO-ASTPANEL-009: the column mounts only while it is open, named after the journey or as one', async () => {+ it('FE-STUDIO-ASTPANEL-009: the window mounts only while it is open, named after the journey or as one', async () => {const { unmount } = render(<StudioAssistantColumn assistant={assistant({ open: false })} title="Lisbon" />);expect(screen.queryByRole('complementary', { name: 'Book assistant' })).toBeNull();unmount();diff --git a/client/src/components/Studio/StudioAssistantPanel.tsx b/client/src/components/Studio/StudioAssistantPanel.tsxindex a42d3dc47..df1fd0770 100644--- a/client/src/components/Studio/StudioAssistantPanel.tsx+++ b/client/src/components/Studio/StudioAssistantPanel.tsx@@ -1,34 +1,42 @@import '../../styles/studio-assistant.css';+import '../Assistant/assistant.css';import { ImageIcon, MessageSquare } from 'lucide-react';-import { type HTMLAttributes, type KeyboardEvent, useCallback, useEffect, useRef, useState } from 'react';+import { type KeyboardEvent, useCallback, useEffect, useRef, useState } from 'react';import { useNavigate } from 'react-router';import { useTranslation } from '../../i18n';import { useAssistantStore } from '../../store/assistantStore';+import { FRAME_CLASS, useAssistantFrame } from '../Assistant/assistantFrame';+import AssistantFrameEdges from '../Assistant/AssistantFrameEdges';import AssistantHeader from '../Assistant/AssistantHeader';import AssistantSurfaceLazy from '../Assistant/AssistantSurfaceLazy';import type { EntityTarget } from '../Assistant/cards/cardTypes';import { providerLabel } from '../Assistant/providerCatalog';import { useAssistantThread } from '../Assistant/useAssistantThread';import { useToast } from '../shared/Toast';-import { SpreadView } from './SpreadView';import { sheetSizePx } from './pageSnapshot';+import { SpreadView } from './SpreadView';import type { StudioAssistant, StudioRenderJob } from './useStudioAssistant';/**- * The assistant as a column of TREK Studio (journey-studio.md 4.5): the same- * chat as the planner's window, on the journey's conversations, beside the- * page it talks about. Desktop only, like the Studio itself.+ * The assistant in TREK Studio (journey-studio.md 4.5): the same chat as the+ * planner's window, on the journey's conversations, in the same floating+ * window, moved by its head and resized from its edges, so it never takes+ * room from the page it talks about. Desktop only, like the Studio itself.** Studio closes on Escape and edits the selection on Delete, copy and paste.- * Inside the column every key belongs to the chat, so it stops here, and+ * Inside the window every key belongs to the chat, so it stops here, and* Escape stops a running answer first. A key from the header's menu, which* sits in a portal, is not the chat's to act on.*/-/** The column is not a window: its head moves nothing. */-const NO_DRAG: HTMLAttributes<HTMLElement> = { style: { cursor: 'default' } };+/** Where the Studio's window is kept between visits, apart from the planner's. */+const STUDIO_WINDOW_STORAGE = 'trek.studioAssistantWindow';+/** The Studio's own bar at the top, which the window's head never goes under. */+const STUDIO_BAR_PX = 56;+/** Narrower than this, the chat lays its cards out compact, as in the planner's window. */+const ROOMY_WIDTH = 480;/*** Images of a page leave only once the user agreed, per connection. Until@@ -147,6 +155,7 @@ export default function StudioAssistantPanel({const navigate = useNavigate();const thread = useAssistantThread(assistant.chatKey);const { isRunning, stop } = thread;+ const frame = useAssistantFrame(STUDIO_WINDOW_STORAGE, STUDIO_BAR_PX);// A card points at a page of this book (`?page=`) or somewhere else in the app.const onOpen = useCallback(@@ -156,7 +165,7 @@ export default function StudioAssistantPanel({[navigate]);- // Every key pressed in the column is the chat's: the editor's own keys+ // Every key pressed in the window is the chat's: the editor's own keys// (Delete, Backspace, copy, paste, undo, Escape) listen on the window and// would otherwise act on the page's selection from a focused chat button.// Keys from a portal (the header's menu) bubble here through React too;@@ -164,32 +173,42 @@ export default function StudioAssistantPanel({const onKeyDown = (e: KeyboardEvent<HTMLElement>) => {const inside = e.currentTarget.contains(e.target as Node);e.stopPropagation();- if (inside && e.key === 'Escape' && isRunning && !e.defaultPrevented) stop();+ if (!inside) return;+ frame.onKeyDown(e);+ if (e.key === 'Escape' && isRunning && !e.defaultPrevented) stop();};return (- <aside className="st-panel st-assistant" aria-label={t('journey.studio.assistant.panel')} onKeyDown={onKeyDown}>- <AssistantHeader- tripId={assistant.chatKey}- thread={thread}- tripTitle={title}- dragProps={NO_DRAG}- onClose={assistant.toggle}- />- <StudioImagesNotice />- <AssistantSurfaceLazy- tripId={assistant.chatKey}- tripTitle={title}- variant="window"- density="compact"- onOpen={onOpen}- bookVersion={bookVersion}- />+ <aside+ className={`st-assistant ${FRAME_CLASS} flex ${frame.active ? 'select-none' : 'trek-assistant-settle'}`}+ aria-label={t('journey.studio.assistant.panel')}+ onKeyDown={onKeyDown}+ style={{ insetInlineStart: frame.rect.x, top: frame.rect.y, width: frame.rect.width, height: frame.rect.height }}+ >+ <AssistantFrameEdges frame={frame} />+ <div className="flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl">+ <AssistantHeader+ tripId={assistant.chatKey}+ thread={thread}+ tripTitle={title}+ dragProps={frame.handleProps}+ onClose={assistant.toggle}+ />+ <StudioImagesNotice />+ <AssistantSurfaceLazy+ tripId={assistant.chatKey}+ tripTitle={title}+ variant="window"+ density={frame.rect.width < ROOMY_WIDTH ? 'compact' : 'roomy'}+ onOpen={onOpen}+ bookVersion={bookVersion}+ />+ </div></aside>);}-/** The Studio bar's switch for the column; only where the assistant can run for this user. */+/** The Studio bar's switch for the window; only where the assistant can run for this user. */export function StudioAssistantToggle({ assistant }: { assistant: StudioAssistant }) {const { t } = useTranslation();if (!assistant.available) return null;@@ -207,7 +226,7 @@ export function StudioAssistantToggle({ assistant }: { assistant: StudioAssistan);}-/** The chat column at the end of the Studio's body, while it is open, named after the journey. */+/** The chat window over the Studio, while it is open, named after the journey. */export function StudioAssistantColumn({assistant,title,diff --git a/client/src/components/Studio/StudioShell.tsx b/client/src/components/Studio/StudioShell.tsxindex 5d61cf7ae..e0fbf29e9 100644--- a/client/src/components/Studio/StudioShell.tsx+++ b/client/src/components/Studio/StudioShell.tsx@@ -107,7 +107,7 @@ export default function StudioShell() {/>)}- <div className={`st-body ${assistant.open ? 'has-assistant' : ''}`}>+ <div className="st-body"><StudioSidebarpage={s.page}pxPerMm={s.pxPerMm}@@ -134,8 +134,8 @@ export default function StudioShell() {t={s.t}locale={s.locale}/>- <StudioAssistantColumn assistant={assistant} title={s.journey?.title} bookVersion={s.bookVersion} /></div>+ <StudioAssistantColumn assistant={assistant} title={s.journey?.title} bookVersion={s.bookVersion} /><StudioPageStage assistant={assistant} />{exporting && s.doc && (diff --git a/client/src/styles/studio-assistant.css b/client/src/styles/studio-assistant.cssindex 564ef7214..86e92225a 100644--- a/client/src/styles/studio-assistant.css+++ b/client/src/styles/studio-assistant.css@@ -1,29 +1,6 @@-/* The assistant as a column of TREK Studio (journey-studio.md 4.5).- It takes the inspector's place at the end of the body; the inspector then- floats over the workbench beside it, as it does under 1280px, so the page- keeps the room it needs to stay legible. */--.trek-dash .st-body.has-assistant {- grid-template-columns: 64px 236px minmax(0, 1fr) 360px;-}--.trek-dash .st-body.has-assistant .st-inspector {- position: absolute;- top: 56px;- inset-inline-end: 360px;- bottom: 0;- width: 300px;- box-shadow: var(--sh-lg);- /* Over the page the glass would show the page through it, and in the dark- scheme the inspector's light text would sit on white paper. */- background: var(--surface);-}--@media (max-width: 1079px) {- .trek-dash .st-body.has-assistant {- grid-template-columns: 64px minmax(0, 1fr) 360px;- }-}+/* The assistant in TREK Studio (journey-studio.md 4.5) floats over the+ Studio in the planner's window (assistantFrame.tsx), so the page and the+ inspector keep all their room. *//* The toggle is the bar's newest tool, so it gives up its label first: from 1360to 1519 it is an icon while the others keep theirs, and the bar fits where it@@ -46,12 +23,6 @@flex: none;}-.trek-dash .st-assistant {- min-width: 0;- overflow: hidden;- border-inline-start: 1px solid var(--glass-border);-}-.trek-dash .st-assistant-notice {margin: 8px 12px 0;}