Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Make the Assistant panel resizable and keep its composer chrome visible

rcourtmana318c287c68d
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/assistantPanelWidth.test.ts b/frontend-modern/src/components/AI/Chat/__tests__/assistantPanelWidth.test.ts
new file mode 100644
index 0000000000..09cfc2d294
--- /dev/null
+++ b/frontend-modern/src/components/AI/Chat/__tests__/assistantPanelWidth.test.ts
@@ -0,0 +1,90 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ ASSISTANT_PANEL_DEFAULT_WIDTH,
+ ASSISTANT_PANEL_MAX_WIDTH,
+ ASSISTANT_PANEL_MIN_WIDTH,
+ ASSISTANT_PANEL_WIDTH_STORAGE_KEY,
+ clampAssistantPanelWidth,
+ loadStoredAssistantPanelWidth,
+ persistAssistantPanelWidth,
+} from '../assistantPanelWidth';
+
+describe('clampAssistantPanelWidth', () => {
+ it('passes through an in-range width', () => {
+ expect(clampAssistantPanelWidth(600, 1920)).toBe(600);
+ });
+
+ it('rounds fractional widths', () => {
+ expect(clampAssistantPanelWidth(600.6, 1920)).toBe(601);
+ });
+
+ it('clamps below the minimum', () => {
+ expect(clampAssistantPanelWidth(100, 1920)).toBe(ASSISTANT_PANEL_MIN_WIDTH);
+ });
+
+ it('clamps above the maximum on wide viewports', () => {
+ expect(clampAssistantPanelWidth(5000, 3000)).toBe(ASSISTANT_PANEL_MAX_WIDTH);
+ });
+
+ it('keeps room for the rest of the app on narrow viewports', () => {
+ expect(clampAssistantPanelWidth(900, 1000)).toBe(680);
+ });
+
+ it('never clamps below the minimum even when the viewport is tiny', () => {
+ expect(clampAssistantPanelWidth(900, 600)).toBe(ASSISTANT_PANEL_MIN_WIDTH);
+ });
+
+ it('falls back to the default for non-finite input', () => {
+ expect(clampAssistantPanelWidth(Number.NaN, 1920)).toBe(ASSISTANT_PANEL_DEFAULT_WIDTH);
+ expect(clampAssistantPanelWidth(Number.POSITIVE_INFINITY, 1920)).toBe(
+ ASSISTANT_PANEL_DEFAULT_WIDTH,
+ );
+ });
+});
+
+describe('loadStoredAssistantPanelWidth', () => {
+ it('reads a stored integer', () => {
+ expect(loadStoredAssistantPanelWidth({ getItem: () => '640' })).toBe(640);
+ });
+
+ it('returns null for missing or blank values', () => {
+ expect(loadStoredAssistantPanelWidth({ getItem: () => null })).toBeNull();
+ expect(loadStoredAssistantPanelWidth({ getItem: () => ' ' })).toBeNull();
+ });
+
+ it('returns null for garbage', () => {
+ expect(loadStoredAssistantPanelWidth({ getItem: () => 'wide' })).toBeNull();
+ });
+
+ it('returns null when storage throws', () => {
+ expect(
+ loadStoredAssistantPanelWidth({
+ getItem: () => {
+ throw new Error('denied');
+ },
+ }),
+ ).toBeNull();
+ });
+});
+
+describe('persistAssistantPanelWidth', () => {
+ it('writes the rounded width under the storage key', () => {
+ const writes: Array<[string, string]> = [];
+ persistAssistantPanelWidth({ setItem: (key, value) => writes.push([key, value]) }, 640.4);
+ expect(writes).toEqual([[ASSISTANT_PANEL_WIDTH_STORAGE_KEY, '640']]);
+ });
+
+ it('swallows storage failures', () => {
+ expect(() =>
+ persistAssistantPanelWidth(
+ {
+ setItem: () => {
+ throw new Error('quota');
+ },
+ },
+ 640,
+ ),
+ ).not.toThrow();
+ });
+});
diff --git a/frontend-modern/src/components/AI/Chat/assistantPanelWidth.ts b/frontend-modern/src/components/AI/Chat/assistantPanelWidth.ts
new file mode 100644
index 0000000000..c721b9fcac
--- /dev/null
+++ b/frontend-modern/src/components/AI/Chat/assistantPanelWidth.ts
@@ -0,0 +1,45 @@
+// Width state for the Assistant side panel's drag-to-resize handle.
+//
+// The panel historically rendered at a fixed 560px, which both wasted space
+// on wide screens and squeezed the composer chrome into overflow glitches.
+// The width is user-adjustable within bounds and persists across sessions.
+
+export const ASSISTANT_PANEL_DEFAULT_WIDTH = 560;
+export const ASSISTANT_PANEL_MIN_WIDTH = 420;
+export const ASSISTANT_PANEL_MAX_WIDTH = 960;
+export const ASSISTANT_PANEL_WIDTH_STORAGE_KEY = 'pulse.assistant.panelWidth';
+
+// Keep the rest of the app usable while the panel is docked: never let the
+// panel eat the viewport down to less than this remainder.
+const MIN_REMAINING_VIEWPORT = 320;
+
+export function clampAssistantPanelWidth(value: number, viewportWidth: number): number {
+ if (!Number.isFinite(value)) return ASSISTANT_PANEL_DEFAULT_WIDTH;
+ const viewportCap = Math.max(ASSISTANT_PANEL_MIN_WIDTH, viewportWidth - MIN_REMAINING_VIEWPORT);
+ const upperBound = Math.min(ASSISTANT_PANEL_MAX_WIDTH, viewportCap);
+ return Math.min(upperBound, Math.max(ASSISTANT_PANEL_MIN_WIDTH, Math.round(value)));
+}
+
+export function loadStoredAssistantPanelWidth(storage: Pick<Storage, 'getItem'>): number | null {
+ let raw: string | null = null;
+ try {
+ raw = storage.getItem(ASSISTANT_PANEL_WIDTH_STORAGE_KEY);
+ } catch {
+ return null;
+ }
+ if (raw === null || raw.trim() === '') return null;
+ const parsed = Number.parseInt(raw, 10);
+ return Number.isFinite(parsed) ? parsed : null;
+}
+
+export function persistAssistantPanelWidth(
+ storage: Pick<Storage, 'setItem'>,
+ width: number,
+): void {
+ try {
+ storage.setItem(ASSISTANT_PANEL_WIDTH_STORAGE_KEY, String(Math.round(width)));
+ } catch {
+ // Storage may be unavailable (private mode, quota); resizing still works
+ // for the session.
+ }
+}
diff --git a/frontend-modern/src/components/AI/Chat/index.tsx b/frontend-modern/src/components/AI/Chat/index.tsx
index 5b304b84a5..37dd818da0 100644
--- a/frontend-modern/src/components/AI/Chat/index.tsx
+++ b/frontend-modern/src/components/AI/Chat/index.tsx
@@ -147,6 +147,12 @@ import { normalizeChatMentionKeyPart } from '@/utils/chatIdentifiers';
import { getGlobalWebSocketStore } from '@/stores/websocket-global';
import { copyToClipboard } from '@/utils/clipboard';
import { getAssistantTurnSummary } from './assistantTurnSummary';
+import {
+ ASSISTANT_PANEL_DEFAULT_WIDTH,
+ clampAssistantPanelWidth,
+ loadStoredAssistantPanelWidth,
+ persistAssistantPanelWidth,
+} from './assistantPanelWidth';
import {
getPreferredResourceDisplayName,
getPreferredResourceHostname,
@@ -2208,6 +2214,48 @@ export const AIChat: Component<AIChatProps> = (props) => {
};
const isOverlayLayout = createMemo(() => width() < AI_CHAT_MIN_DOCKED_VIEWPORT_WIDTH);
+
+ const [panelWidth, setPanelWidth] = createSignal(
+ loadStoredAssistantPanelWidth(window.localStorage) ?? ASSISTANT_PANEL_DEFAULT_WIDTH,
+ );
+ const effectivePanelWidth = createMemo(() => clampAssistantPanelWidth(panelWidth(), width()));
+ // Below Tailwind's sm breakpoint the panel is w-full; the custom width only
+ // applies from sm up, matching the class fallbacks it overrides.
+ const panelWidthStyle = createMemo(() =>
+ isOpen() && width() >= 640 ? { width: `${effectivePanelWidth()}px` } : undefined,
+ );
+
+ const commitPanelWidth = (nextWidth: number) => {
+ const clamped = clampAssistantPanelWidth(nextWidth, window.innerWidth);
+ setPanelWidth(clamped);
+ persistAssistantPanelWidth(window.localStorage, clamped);
+ };
+
+ const stopPanelResize = () => {
+ window.removeEventListener('pointermove', handlePanelResizeMove);
+ window.removeEventListener('pointerup', stopPanelResize);
+ persistAssistantPanelWidth(window.localStorage, effectivePanelWidth());
+ };
+
+ const handlePanelResizeMove = (event: PointerEvent) => {
+ setPanelWidth(clampAssistantPanelWidth(window.innerWidth - event.clientX, window.innerWidth));
+ };
+
+ const startPanelResize = (event: PointerEvent) => {
+ event.preventDefault();
+ window.addEventListener('pointermove', handlePanelResizeMove);
+ window.addEventListener('pointerup', stopPanelResize);
+ };
+
+ const handlePanelResizeKeyDown = (event: KeyboardEvent) => {
+ if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
+ event.preventDefault();
+ const delta = event.key === 'ArrowLeft' ? 32 : -32;
+ commitPanelWidth(effectivePanelWidth() + delta);
+ }
+ };
+
+ onCleanup(stopPanelResize);
const rootClassName = createMemo(() => {
if (isOverlayLayout()) {
return `fixed inset-y-0 right-0 z-50 flex h-full w-full flex-col bg-surface transition-transform duration-300 sm:w-[560px] sm:max-w-[calc(100vw-1rem)] ${
@@ -4181,8 +4229,25 @@ export const AIChat: Component<AIChatProps> = (props) => {
aria-label="Close Pulse Assistant backdrop"
/>
</Show>
- <div class={rootClassName()} data-layout-mode={isOverlayLayout() ? 'overlay' : 'docked'}>
+ <div
+ class={rootClassName()}
+ style={panelWidthStyle()}
+ data-layout-mode={isOverlayLayout() ? 'overlay' : 'docked'}
+ >
<Show when={isOpen()}>
+ {/* Drag handle to resize the panel (desktop widths only) */}
+ <div
+ class="absolute inset-y-0 left-0 z-50 hidden w-1.5 cursor-col-resize touch-none hover:bg-blue-400/40 focus:bg-blue-400/60 focus:outline-none sm:block"
+ role="separator"
+ aria-orientation="vertical"
+ aria-label="Resize Assistant panel"
+ tabindex="0"
+ title="Drag to resize. Double-click to reset."
+ onPointerDown={startPanelResize}
+ onKeyDown={handlePanelResizeKeyDown}
+ onDblClick={() => commitPanelWidth(ASSISTANT_PANEL_DEFAULT_WIDTH)}
+ data-testid="assistant-panel-resize-handle"
+ />
{/* Floating Close Handle (Desktop docked layout only) */}
<Show when={!isOverlayLayout()}>
<button
@@ -5303,7 +5368,7 @@ export const AIChat: Component<AIChatProps> = (props) => {
data-testid="assistant-composer-chrome"
>
<div
- class="flex min-w-0 flex-wrap items-center gap-1.5 sm:flex-1 sm:flex-nowrap sm:overflow-hidden"
+ class="flex min-w-0 flex-wrap items-center gap-1.5 sm:flex-1"
data-testid="assistant-composer-route-controls"
>
<ModelSelector
@@ -5391,7 +5456,7 @@ export const AIChat: Component<AIChatProps> = (props) => {
<RotateCwIcon class="h-3.5 w-3.5" aria-hidden="true" />
</ActionIconButton>
- <div class="relative" data-dropdown>
+ <div class="relative shrink-0" data-dropdown>
<button
type="button"
ref={controlModeButtonRef}
@@ -5407,7 +5472,7 @@ export const AIChat: Component<AIChatProps> = (props) => {
<span
class={`h-1.5 w-1.5 rounded-full ${controlPresentation().dotClassName}`}
/>
- <span>Chat: {controlPresentation().label}</span>
+ <span class="whitespace-nowrap">Chat: {controlPresentation().label}</span>
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
stroke-linecap="round"