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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Add Assistant session fork action
rcourtmance339371da9a
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsxindex caa4e194bf..617abe3148 100644--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx@@ -88,6 +88,13 @@ const {message_count: 0,}),deleteSession: vi.fn().mockResolvedValue(undefined),+ forkSession: vi.fn().mockResolvedValue({+ id: 'forked-session',+ title: 'Forked session',+ created_at: '2026-06-06T12:45:00Z',+ updated_at: '2026-06-06T12:45:00Z',+ message_count: 2,+ }),approveCommand: vi.fn().mockResolvedValue({ approved: true, message: 'ok' }),denyCommand: vi.fn().mockResolvedValue({ denied: true, message: 'ok' }),};@@ -415,6 +422,13 @@ beforeEach(() => {});mockAIChatAPI.getStatus.mockResolvedValue({ running: true });mockAIChatAPI.listSessions.mockResolvedValue([]);+ mockAIChatAPI.forkSession.mockResolvedValue({+ id: 'forked-session',+ title: 'Forked session',+ created_at: '2026-06-06T12:45:00Z',+ updated_at: '2026-06-06T12:45:00Z',+ message_count: 2,+ });Element.prototype.scrollIntoView = vi.fn();localStorage.clear();});@@ -435,6 +449,7 @@ describe('AIChat', () => {it('disables transcript actions until the current session has messages', () => {renderChat();+ expect(screen.getByRole('button', { name: 'Fork current Assistant session' })).toBeDisabled();expect(screen.getByRole('button', { name: 'Copy Assistant transcript' })).toBeDisabled();expect(screen.getByRole('button', { name: 'Export Assistant transcript' })).toBeDisabled();});@@ -2070,6 +2085,77 @@ describe('AIChat', () => {expect(mockAiChatStore.context.findingId).toBe('finding-old');});+ it('forks the current saved Assistant session from the header', async () => {+ mockChat.sessionId.mockReturnValue('source-session');+ mockChat.messages.mockReturnValue([+ {+ id: 'user-1',+ role: 'user',+ content: 'compare these tool outputs',+ timestamp: new Date('2026-06-06T12:34:56Z'),+ },+ {+ id: 'assistant-1',+ role: 'assistant',+ content: 'The first node has stale discovery data.',+ timestamp: new Date('2026-06-06T12:35:01Z'),+ },+ ]);+ mockChat.model.mockReturnValue('openrouter:deepseek/deepseek-chat');+ mockAIChatAPI.listSessions.mockResolvedValue([+ {+ id: 'source-session',+ title: 'Source session',+ created_at: '2026-06-06T12:30:00Z',+ updated_at: '2026-06-06T12:35:00Z',+ message_count: 2,+ },+ ]);+ mockAIChatAPI.forkSession.mockResolvedValue({+ id: 'forked-session',+ title: 'Forked session',+ created_at: '2026-06-06T12:45:00Z',+ updated_at: '2026-06-06T12:45:00Z',+ message_count: 2,+ });++ renderChat();+ fireEvent.click(screen.getByRole('button', { name: 'Fork current Assistant session' }));++ await waitFor(() => {+ expect(mockAIChatAPI.forkSession).toHaveBeenCalledWith('source-session');+ expect(mockChat.loadSession).toHaveBeenCalledWith('forked-session');+ });+ expect(mockAiChatStore.clearContext).toHaveBeenCalled();+ expect(mockNotificationStore.success).toHaveBeenCalledWith('Assistant session forked', 2000);+ expect(JSON.parse(localStorage.getItem('pulse:ai_chat_models_by_session') || '{}')).toEqual({+ 'source-session': 'openrouter:deepseek/deepseek-chat',+ 'forked-session': 'openrouter:deepseek/deepseek-chat',+ });+ });++ it('keeps the current session loaded when forking fails', async () => {+ mockChat.sessionId.mockReturnValue('source-session');+ mockChat.messages.mockReturnValue([+ {+ id: 'user-1',+ role: 'user',+ content: 'branch from this point',+ timestamp: new Date('2026-06-06T12:34:56Z'),+ },+ ]);+ mockAIChatAPI.forkSession.mockRejectedValueOnce(new Error('fork failed'));++ renderChat();+ fireEvent.click(screen.getByRole('button', { name: 'Fork current Assistant session' }));++ await waitFor(() => {+ expect(mockAIChatAPI.forkSession).toHaveBeenCalledWith('source-session');+ });+ expect(mockChat.loadSession).not.toHaveBeenCalled();+ expect(mockNotificationStore.error).toHaveBeenCalledWith('Failed to fork Assistant session');+ });+it('opens session picker on click', async () => {renderChat();const sessionButton = screen.getByRole('button', { name: 'Pulse Assistant sessions' });diff --git a/frontend-modern/src/components/AI/Chat/index.tsx b/frontend-modern/src/components/AI/Chat/index.tsxindex 8f5e7bd342..e1db827526 100644--- a/frontend-modern/src/components/AI/Chat/index.tsx+++ b/frontend-modern/src/components/AI/Chat/index.tsx@@ -14,6 +14,7 @@ import SquareIcon from 'lucide-solid/icons/square';import ClockIcon from 'lucide-solid/icons/clock';import CopyIcon from 'lucide-solid/icons/copy';import DownloadIcon from 'lucide-solid/icons/download';+import GitForkIcon from 'lucide-solid/icons/git-fork';import PencilIcon from 'lucide-solid/icons/pencil';import RefreshCwIcon from 'lucide-solid/icons/refresh-cw';import SettingsIcon from 'lucide-solid/icons/settings';@@ -49,6 +50,12 @@ import {AI_CHAT_DISCOVERY_HINT_TITLE,AI_CHAT_DRAWER_TITLE,AI_CHAT_EXPORT_TRANSCRIPT_LABEL,+ AI_CHAT_FORK_SESSION_EMPTY_MESSAGE,+ AI_CHAT_FORK_SESSION_ERROR_MESSAGE,+ AI_CHAT_FORK_SESSION_LABEL,+ AI_CHAT_FORK_SESSION_LOAD_ERROR_MESSAGE,+ AI_CHAT_FORK_SESSION_LOADING_MESSAGE,+ AI_CHAT_FORK_SESSION_SUCCESS_MESSAGE,AI_CHAT_INPUT_PLACEHOLDER,AI_CHAT_LAST_TURN_USAGE_LABEL,AI_CHAT_NEW_SESSION_BUTTON_TITLE,@@ -564,6 +571,7 @@ export const AIChat: Component<AIChatProps> = (props) => {const [sessionSearchLoading, setSessionSearchLoading] = createSignal(false);const [sessionSearchError, setSessionSearchError] = createSignal('');const [sessionDropdownPosition, setSessionDropdownPosition] = createSignal({ top: 0, right: 0 });+ const [forkingSession, setForkingSession] = createSignal(false);let sessionButtonRef: HTMLButtonElement | undefined;let sessionSearchInputRef: HTMLInputElement | undefined;const sessionOptionRefs = new Map<string, HTMLButtonElement>();@@ -1264,6 +1272,13 @@ export const AIChat: Component<AIChatProps> = (props) => {};const hasCurrentTranscript = createMemo(() => hasAssistantTranscriptContent(chat.messages()));+ const canForkCurrentSession = createMemo(+ () =>+ Boolean(chat.sessionId().trim()) &&+ hasCurrentTranscript() &&+ !chat.isLoading() &&+ !forkingSession(),+ );const buildCurrentTranscript = (generatedAt = new Date()) => {const sessionId = chat.sessionId().trim();@@ -1321,6 +1336,14 @@ export const AIChat: Component<AIChatProps> = (props) => {}};+ const upsertSession = (session: ChatSession) => {+ setSessions((prev) => [session, ...prev.filter((candidate) => candidate.id !== session.id)]);+ setSessionSearchResults(+ (prev) =>+ prev && [session, ...prev.filter((candidate) => candidate.id !== session.id)],+ );+ };+const downloadFallbackTranscript = () => {const fallback = transcriptCopyFallback();if (!fallback) return;@@ -2338,6 +2361,54 @@ export const AIChat: Component<AIChatProps> = (props) => {focusComposer();};+ const handleForkSession = async () => {+ if (forkingSession()) return;+ const sourceSessionId = chat.sessionId().trim();+ if (!sourceSessionId || !hasCurrentTranscript()) {+ notificationStore.info(AI_CHAT_FORK_SESSION_EMPTY_MESSAGE, 2000);+ return;+ }+ if (chat.isLoading()) {+ notificationStore.info(AI_CHAT_FORK_SESSION_LOADING_MESSAGE, 2000);+ return;+ }++ setForkingSession(true);+ try {+ const sourceModel = getStoredModel(sourceSessionId) || chat.model().trim();+ const forkedSession = await AIChatAPI.forkSession(sourceSessionId);+ upsertSession(forkedSession);+ if (sourceModel) {+ updateStoredModel(forkedSession.id, sourceModel);+ }++ const loaded = await chat.loadSession(forkedSession.id);+ if (!loaded) {+ notificationStore.error(AI_CHAT_FORK_SESSION_LOAD_ERROR_MESSAGE);+ return;+ }++ resetPromptHistoryNavigation();+ setEditingQueuedFollowUp(null);+ const restoredContext = buildSessionHandoffContext(forkedSession);+ if (restoredContext) {+ aiChatStore.setContext(restoredContext);+ } else {+ aiChatStore.clearContext?.();+ }+ setShowSessions(false);+ setSessionRefreshLoading(false);+ resetSessionSearch();+ notificationStore.success(AI_CHAT_FORK_SESSION_SUCCESS_MESSAGE, 2000);+ focusComposer();+ } catch (error) {+ logger.error('[AIChat] Failed to fork Assistant session:', error);+ notificationStore.error(AI_CHAT_FORK_SESSION_ERROR_MESSAGE);+ } finally {+ setForkingSession(false);+ }+ };+const handleToggleSessions = async () => {const next = !showSessions();if (!next) {@@ -2570,6 +2641,25 @@ export const AIChat: Component<AIChatProps> = (props) => {<span class="font-medium">{AI_CHAT_NEW_SESSION_SHORT_LABEL}</span></button>+ <button+ type="button"+ onClick={() => {+ void handleForkSession();+ }}+ disabled={!canForkCurrentSession()}+ class="flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md border border-border bg-surface text-muted transition-colors hover:border-border hover:bg-surface-hover hover:text-base-content disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-surface disabled:hover:text-muted"+ title={AI_CHAT_FORK_SESSION_LABEL}+ aria-label={AI_CHAT_FORK_SESSION_LABEL}+ aria-busy={forkingSession()}+ >+ <Show+ when={forkingSession()}+ fallback={<GitForkIcon class="h-4 w-4" aria-hidden="true" />}+ >+ <LoaderCircleIcon class="h-4 w-4 animate-spin" aria-hidden="true" />+ </Show>+ </button>+<buttontype="button"onClick={() => {diff --git a/frontend-modern/src/utils/aiChatPresentation.ts b/frontend-modern/src/utils/aiChatPresentation.tsindex 05a3bebf71..766e819ea0 100644--- a/frontend-modern/src/utils/aiChatPresentation.ts+++ b/frontend-modern/src/utils/aiChatPresentation.ts@@ -9,6 +9,13 @@ export const AI_CHAT_NEW_SESSION_SHORT_LABEL = 'New';export const AI_CHAT_NEW_SESSION_BUTTON_TITLE = 'Start new Assistant session';export const AI_CHAT_NEW_SESSION_MENU_LABEL = 'New session';export const AI_CHAT_NEW_SESSION_MENU_ARIA_LABEL = 'Start new Assistant session';+export const AI_CHAT_FORK_SESSION_LABEL = 'Fork current Assistant session';+export const AI_CHAT_FORK_SESSION_EMPTY_MESSAGE = 'No saved Assistant session to fork';+export const AI_CHAT_FORK_SESSION_LOADING_MESSAGE = 'Assistant is still working';+export const AI_CHAT_FORK_SESSION_LOAD_ERROR_MESSAGE =+ 'Forked Assistant session but failed to load it';+export const AI_CHAT_FORK_SESSION_ERROR_MESSAGE = 'Failed to fork Assistant session';+export const AI_CHAT_FORK_SESSION_SUCCESS_MESSAGE = 'Assistant session forked';export const AI_CHAT_COPY_TRANSCRIPT_LABEL = 'Copy Assistant transcript';export const AI_CHAT_EXPORT_TRANSCRIPT_LABEL = 'Export Assistant transcript';export const AI_CHAT_TRANSCRIPT_FALLBACK_CLOSE_LABEL = 'Close Assistant transcript copy panel';