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 slash command picker
rcourtman086b6d5e6a3b
diff --git a/frontend-modern/src/components/AI/Chat/SlashCommandAutocomplete.tsx b/frontend-modern/src/components/AI/Chat/SlashCommandAutocomplete.tsxnew file mode 100644index 0000000000..ca48c04d41--- /dev/null+++ b/frontend-modern/src/components/AI/Chat/SlashCommandAutocomplete.tsx@@ -0,0 +1,152 @@+import { For, Show, createEffect, createMemo, createSignal, onCleanup } from 'solid-js';+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 PlusIcon from 'lucide-solid/icons/plus';+import SettingsIcon from 'lucide-solid/icons/settings';+import type { AssistantSlashCommand, AssistantSlashCommandAction } from './assistantSlashCommands';+import {+ filterAssistantSlashCommands,+ getAssistantSlashCommandTokens,+} from './assistantSlashCommands';++interface SlashCommandAutocompleteProps {+ query: string;+ visible: boolean;+ position: { top: number; left: number };+ onClose: () => void;+ onSelect: (command: AssistantSlashCommand) => void;+}++const commandIcon = (action: AssistantSlashCommandAction) => {+ switch (action) {+ case 'new':+ return <PlusIcon class="h-4 w-4" aria-hidden="true" />;+ case 'sessions':+ return <ClockIcon class="h-4 w-4" aria-hidden="true" />;+ case 'models':+ return <SettingsIcon class="h-4 w-4" aria-hidden="true" />;+ case 'copy':+ return <CopyIcon class="h-4 w-4" aria-hidden="true" />;+ case 'export':+ return <DownloadIcon class="h-4 w-4" aria-hidden="true" />;+ case 'fork':+ return <GitForkIcon class="h-4 w-4" aria-hidden="true" />;+ }+};++export function SlashCommandAutocomplete(props: SlashCommandAutocompleteProps) {+ const [selectedIndex, setSelectedIndex] = createSignal(0);+ const commands = createMemo(() => filterAssistantSlashCommands(props.query, 8));++ createEffect(() => {+ props.query;+ setSelectedIndex(0);+ });++ const selectCommand = (command?: AssistantSlashCommand) => {+ if (!command) return;+ props.onSelect(command);+ };++ const handleKeyDown = (event: KeyboardEvent) => {+ if (!props.visible) return;++ const options = commands();+ switch (event.key) {+ case 'ArrowDown':+ event.preventDefault();+ setSelectedIndex((index) => Math.min(index + 1, Math.max(0, options.length - 1)));+ break;+ case 'ArrowUp':+ event.preventDefault();+ setSelectedIndex((index) => Math.max(index - 1, 0));+ break;+ case 'Enter':+ event.preventDefault();+ selectCommand(options[selectedIndex()]);+ break;+ case 'Tab':+ event.preventDefault();+ selectCommand(options[selectedIndex()]);+ break;+ case 'Escape':+ event.preventDefault();+ props.onClose();+ break;+ }+ };++ createEffect(() => {+ if (!props.visible) return;+ document.addEventListener('keydown', handleKeyDown);+ onCleanup(() => document.removeEventListener('keydown', handleKeyDown));+ });++ return (+ <Show when={props.visible && commands().length > 0}>+ <div+ class="absolute z-50 min-w-[280px] max-w-[420px] overflow-hidden rounded-md border border-border bg-surface shadow-sm"+ style={{+ bottom: `${props.position.top}px`,+ left: `${props.position.left}px`,+ }}+ data-slash-command-autocomplete+ onClick={(event) => event.stopPropagation()}+ >+ <div class="border-b border-border px-3 py-2 text-xs font-medium text-muted">+ Commands+ </div>+ <div class="max-h-[260px] overflow-y-auto" role="listbox" aria-label="Assistant commands">+ <For each={commands()}>+ {(command, index) => (+ <button+ type="button"+ role="option"+ aria-selected={index() === selectedIndex()}+ aria-label={`Run /${command.name}: ${command.description}`}+ class={`flex w-full items-start gap-3 px-3 py-2.5 text-left transition-colors hover:bg-surface-hover ${+ index() === selectedIndex() ? 'bg-surface-hover' : ''+ }`}+ onClick={(event) => {+ event.stopPropagation();+ selectCommand(command);+ }}+ onMouseEnter={() => setSelectedIndex(index())}+ >+ <span class="mt-0.5 text-muted">{commandIcon(command.action)}</span>+ <span class="min-w-0 flex-1">+ <span class="flex min-w-0 items-center gap-2">+ <span class="font-mono text-xs font-semibold text-base-content">+ /{command.name}+ </span>+ <Show when={command.aliases?.length}>+ <span class="truncate text-[10px] text-muted">+ {getAssistantSlashCommandTokens(command)+ .slice(1)+ .map((alias) => `/${alias}`)+ .join(', ')}+ </span>+ </Show>+ </span>+ <span class="mt-0.5 block truncate text-xs text-muted">+ {command.description}+ </span>+ </span>+ </button>+ )}+ </For>+ </div>+ <div class="flex items-center gap-2 border-t border-border px-3 py-1.5 text-xs text-muted">+ <span class="rounded bg-surface-hover px-1.5 py-0.5 text-[10px]">up/down</span>+ navigate+ <span class="rounded bg-surface-hover px-1.5 py-0.5 text-[10px]">enter</span>+ run+ <span class="rounded bg-surface-hover px-1.5 py-0.5 text-[10px]">esc</span>+ close+ </div>+ </div>+ </Show>+ );+}diff --git a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsxindex 66ba63e559..f9451fdd2b 100644--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx@@ -1576,6 +1576,62 @@ describe('AIChat', () => {expect(mockChat.sendMessage).toHaveBeenCalledWith('hello world', undefined, undefined);});+ it('shows slash command suggestions and runs the selected command with Enter', async () => {+ renderChat();+ const textarea = screen.getByPlaceholderText('Ask about your infrastructure...');++ fireEvent.input(textarea, { target: { value: '/mo' } });++ expect(screen.getByRole('listbox', { name: 'Assistant commands' })).toBeInTheDocument();+ expect(screen.getByRole('option', { name: /Run \/models/ })).toBeInTheDocument();++ fireEvent.keyDown(textarea, { key: 'Enter' });++ await waitFor(() => {+ expect(screen.getByTestId('model-selector')).toHaveAttribute('data-open-request', '1');+ });+ expect(screen.queryByRole('listbox', { name: 'Assistant commands' })).not.toBeInTheDocument();+ expect(mockChat.sendMessage).not.toHaveBeenCalled();+ });++ it('filters slash command suggestions by alias and runs clicked commands', async () => {+ renderChat();+ await waitFor(() => {+ expect(mockAIChatAPI.listSessions).toHaveBeenCalledWith({ limit: 30 });+ });+ mockAIChatAPI.listSessions.mockClear();+ const textarea = screen.getByPlaceholderText('Ask about your infrastructure...');++ fireEvent.input(textarea, { target: { value: '/res' } });+ expect(screen.getByRole('option', { name: /Run \/sessions/ })).toBeInTheDocument();++ fireEvent.click(screen.getByRole('option', { name: /Run \/sessions/ }));++ await waitFor(() => {+ expect(screen.getByRole('dialog', { name: 'Pulse Assistant sessions' })).toBeInTheDocument();+ });+ expect(mockAIChatAPI.listSessions).toHaveBeenCalledWith({ limit: 30 });+ expect(mockChat.sendMessage).not.toHaveBeenCalled();+ });++ it('closes slash command suggestions with Escape without submitting', async () => {+ renderChat();+ const textarea = screen.getByPlaceholderText(+ 'Ask about your infrastructure...',+ ) as HTMLTextAreaElement;++ fireEvent.input(textarea, { target: { value: '/' } });+ expect(screen.getByRole('listbox', { name: 'Assistant commands' })).toBeInTheDocument();++ fireEvent.keyDown(textarea, { key: 'Escape' });++ await waitFor(() => {+ expect(screen.queryByRole('listbox', { name: 'Assistant commands' })).not.toBeInTheDocument();+ });+ expect(textarea.value).toBe('/');+ expect(mockChat.sendMessage).not.toHaveBeenCalled();+ });+it('runs /new locally without sending a provider prompt', async () => {renderChat();const textarea = screen.getByPlaceholderText(@@ -1663,6 +1719,7 @@ describe('AIChat', () => {const textarea = screen.getByPlaceholderText('Ask about your infrastructure...');fireEvent.input(textarea, { target: { value: '/explain /dev devices' } });+ expect(screen.queryByRole('listbox', { name: 'Assistant commands' })).not.toBeInTheDocument();fireEvent.keyDown(textarea, { key: 'Enter' });expect(mockChat.sendMessage).toHaveBeenCalledWith(diff --git a/frontend-modern/src/components/AI/Chat/__tests__/assistantSlashCommands.test.ts b/frontend-modern/src/components/AI/Chat/__tests__/assistantSlashCommands.test.tsindex e706ba7db7..a01c18437b 100644--- a/frontend-modern/src/components/AI/Chat/__tests__/assistantSlashCommands.test.ts+++ b/frontend-modern/src/components/AI/Chat/__tests__/assistantSlashCommands.test.ts@@ -1,5 +1,9 @@import { describe, expect, it } from 'vitest';-import { parseAssistantSlashCommand } from '../assistantSlashCommands';+import {+ filterAssistantSlashCommands,+ getAssistantSlashCommandTokens,+ parseAssistantSlashCommand,+} from '../assistantSlashCommands';describe('assistantSlashCommands', () => {it('maps OpenCode-style session commands to local Assistant actions', () => {@@ -25,4 +29,26 @@ describe('assistantSlashCommands', () => {expect(parseAssistantSlashCommand('/ copy')).toBeNull();expect(parseAssistantSlashCommand('/copy this sentence')).toBeNull();});++ it('filters commands by canonical name, alias, and description', () => {+ expect(filterAssistantSlashCommands('').map((command) => command.name)).toEqual([+ 'new',+ 'sessions',+ 'models',+ 'copy',+ 'export',+ 'fork',+ ]);+ expect(filterAssistantSlashCommands('res').map((command) => command.name)).toEqual([+ 'sessions',+ ]);+ expect(filterAssistantSlashCommands('provider').map((command) => command.name)).toEqual([+ 'models',+ ]);+ });++ it('exposes canonical and alias tokens for the picker', () => {+ const sessions = filterAssistantSlashCommands('resume')[0];+ expect(getAssistantSlashCommandTokens(sessions)).toEqual(['sessions', 'resume', 'continue']);+ });});diff --git a/frontend-modern/src/components/AI/Chat/assistantSlashCommands.ts b/frontend-modern/src/components/AI/Chat/assistantSlashCommands.tsindex 2f928e6cce..da6bead59c 100644--- a/frontend-modern/src/components/AI/Chat/assistantSlashCommands.ts+++ b/frontend-modern/src/components/AI/Chat/assistantSlashCommands.ts@@ -9,16 +9,44 @@ export type AssistantSlashCommandAction =export interface AssistantSlashCommand {action: AssistantSlashCommandAction;aliases?: string[];+ description: string;name: string;}export const ASSISTANT_SLASH_COMMANDS: AssistantSlashCommand[] = [- { name: 'new', aliases: ['clear'], action: 'new' },- { name: 'sessions', aliases: ['resume', 'continue'], action: 'sessions' },- { name: 'models', aliases: ['model'], action: 'models' },- { name: 'copy', action: 'copy' },- { name: 'export', action: 'export' },- { name: 'fork', action: 'fork' },+ {+ name: 'new',+ aliases: ['clear'],+ action: 'new',+ description: 'Start a blank Assistant session',+ },+ {+ name: 'sessions',+ aliases: ['resume', 'continue'],+ action: 'sessions',+ description: 'Open Assistant session history',+ },+ {+ name: 'models',+ aliases: ['model'],+ action: 'models',+ description: 'Choose the model and provider route',+ },+ {+ name: 'copy',+ action: 'copy',+ description: 'Copy the current transcript',+ },+ {+ name: 'export',+ action: 'export',+ description: 'Download the current transcript',+ },+ {+ name: 'fork',+ action: 'fork',+ description: 'Fork this session into a new copy',+ },];const commandByToken = new Map<string, AssistantSlashCommandAction>(@@ -39,3 +67,47 @@ export const parseAssistantSlashCommand = (return commandByToken.get(token) ?? null;};++const normalizeSlashQuery = (query: string) => query.trim().toLowerCase();++const commandAliases = (command: AssistantSlashCommand): string[] => command.aliases || [];++const commandMatchesQuery = (command: AssistantSlashCommand, query: string) => {+ if (!query) return true;+ if (command.name.toLowerCase().includes(query)) return true;+ if (command.description.toLowerCase().includes(query)) return true;+ return commandAliases(command).some((alias) => alias.toLowerCase().includes(query));+};++const commandMatchScore = (command: AssistantSlashCommand, query: string) => {+ if (!query) return 0;+ if (command.name.toLowerCase().startsWith(query)) return 0;+ if (commandAliases(command).some((alias) => alias.toLowerCase().startsWith(query))) return 1;+ if (command.name.toLowerCase().includes(query)) return 2;+ if (commandAliases(command).some((alias) => alias.toLowerCase().includes(query))) return 3;+ return 4;+};++export const getAssistantSlashCommandTokens = (command: AssistantSlashCommand): string[] => [+ command.name,+ ...commandAliases(command),+];++export const filterAssistantSlashCommands = (+ query: string,+ limit = ASSISTANT_SLASH_COMMANDS.length,+): AssistantSlashCommand[] => {+ const normalizedQuery = normalizeSlashQuery(query);+ return ASSISTANT_SLASH_COMMANDS.filter((command) =>+ commandMatchesQuery(command, normalizedQuery),+ )+ .map((command, index) => ({ command, index }))+ .sort((left, right) => {+ const scoreDelta =+ commandMatchScore(left.command, normalizedQuery) -+ commandMatchScore(right.command, normalizedQuery);+ return scoreDelta || left.index - right.index;+ })+ .slice(0, limit)+ .map(({ command }) => command);+};diff --git a/frontend-modern/src/components/AI/Chat/index.tsx b/frontend-modern/src/components/AI/Chat/index.tsxindex 2465c19600..17af1ca4bb 100644--- a/frontend-modern/src/components/AI/Chat/index.tsx+++ b/frontend-modern/src/components/AI/Chat/index.tsx@@ -114,9 +114,15 @@ import { useChat, type QueuedFollowUp, type SendMessageOptions } from './hooks/uimport { ChatMessages } from './ChatMessages';import { ModelSelector } from './ModelSelector';import { MentionAutocomplete, type MentionResource } from './MentionAutocomplete';+import { SlashCommandAutocomplete } from './SlashCommandAutocomplete';import { getAssistantActiveTurnStatus } from './activeTurnStatus';import { getLastAssistantAnswerText } from './assistantAnswerText';-import { parseAssistantSlashCommand, type AssistantSlashCommandAction } from './assistantSlashCommands';+import {+ filterAssistantSlashCommands,+ parseAssistantSlashCommand,+ type AssistantSlashCommand,+ type AssistantSlashCommandAction,+} from './assistantSlashCommands';import {buildAssistantTranscriptFilename,downloadAssistantTranscriptFile,@@ -615,6 +621,8 @@ export const AIChat: Component<AIChatProps> = (props) => {const [mentionStartIndex, setMentionStartIndex] = createSignal(0);const [mentionResources, setMentionResources] = createSignal<MentionResource[]>([]);const [accumulatedMentions, setAccumulatedMentions] = createSignal<MentionResource[]>([]);+ const [slashCommandActive, setSlashCommandActive] = createSignal(false);+ const [slashCommandQuery, setSlashCommandQuery] = createSignal('');let textareaRef: HTMLTextAreaElement | undefined;let transcriptFallbackTextareaRef: HTMLTextAreaElement | undefined;let interruptArmTimeout: ReturnType<typeof setTimeout> | undefined;@@ -762,6 +770,7 @@ export const AIChat: Component<AIChatProps> = (props) => {draft.editingQueuedFollowUp ? cloneQueuedFollowUp(draft.editingQueuedFollowUp) : null,);setMentionActive(false);+ setSlashCommandActive(false);resetPromptHistoryNavigation();queueMicrotask(() => {resizeTextarea();@@ -776,6 +785,7 @@ export const AIChat: Component<AIChatProps> = (props) => {setInput(entry.prompt);setAccumulatedMentions(cloneMentions(entry.mentions));setMentionActive(false);+ setSlashCommandActive(false);queueMicrotask(() => {resizeTextarea();textareaRef?.focus();@@ -1855,8 +1865,14 @@ export const AIChat: Component<AIChatProps> = (props) => {const isInsideDropdown = path.some((node) => node instanceof Element && Boolean(node.closest('[data-dropdown]')),);+ const isInsideComposerPopup = path.some(+ (node) =>+ node instanceof Element &&+ (Boolean(node.closest('[data-mention-autocomplete]')) ||+ Boolean(node.closest('[data-slash-command-autocomplete]'))),+ );// Only close if click is outside dropdown containers- if (!isInsideDropdown) {+ if (!isInsideDropdown && !isInsideComposerPopup) {setShowSessions(false);setSessionRefreshLoading(false);resetSessionSearch();@@ -1866,6 +1882,9 @@ export const AIChat: Component<AIChatProps> = (props) => {if (!target.closest('[data-mention-autocomplete]') && !target.closest('textarea')) {setMentionActive(false);}+ if (!target.closest('[data-slash-command-autocomplete]') && !target.closest('textarea')) {+ setSlashCommandActive(false);+ }};document.addEventListener('click', handleClickOutside);onCleanup(() => {@@ -2157,6 +2176,7 @@ export const AIChat: Component<AIChatProps> = (props) => {setInput(draft);setAccumulatedMentions(cloneMentions(mentions));setMentionActive(false);+ setSlashCommandActive(false);queueMicrotask(() => {resizeTextarea();focusComposer();@@ -2176,6 +2196,8 @@ export const AIChat: Component<AIChatProps> = (props) => {setInput('');setAccumulatedMentions([]);setMentionActive(false);+ setSlashCommandActive(false);+ setSlashCommandQuery('');resetPromptHistoryNavigation();queueMicrotask(() => {resizeTextarea();@@ -2230,6 +2252,8 @@ export const AIChat: Component<AIChatProps> = (props) => {executeSlashCommand(slashCommand);return;}+ setSlashCommandActive(false);+ setSlashCommandQuery('');const mentions = accumulatedMentions();const submittedMentions = cloneMentions(mentions);const mentionsForAPI =@@ -2311,9 +2335,35 @@ export const AIChat: Component<AIChatProps> = (props) => {setInput('');setAccumulatedMentions([]);setMentionActive(false);+ setSlashCommandActive(false);+ setSlashCommandQuery('');focusComposer();};+ const updateSlashCommandAutocomplete = (value: string, cursorPos: number) => {+ const textBeforeCursor = value.slice(0, cursorPos);+ const textAfterCursor = value.slice(cursorPos);++ if (+ textBeforeCursor.startsWith('/') &&+ !/\s/.test(textBeforeCursor) &&+ !textAfterCursor.trim()+ ) {+ const query = textBeforeCursor.slice(1);+ setSlashCommandQuery(query);+ const hasMatches = filterAssistantSlashCommands(query, 1).length > 0;+ setSlashCommandActive(hasMatches);+ if (hasMatches) {+ setMentionActive(false);+ }+ return hasMatches;+ }++ setSlashCommandActive(false);+ setSlashCommandQuery('');+ return false;+ };+// Handle input change with @ mention detectionconst handleInputChange = (e: InputEvent & { currentTarget: HTMLTextAreaElement }) => {const value = e.currentTarget.value;@@ -2326,6 +2376,10 @@ export const AIChat: Component<AIChatProps> = (props) => {const cursorPos = e.currentTarget.selectionStart || 0;const textBeforeCursor = value.slice(0, cursorPos);+ if (updateSlashCommandAutocomplete(value, cursorPos)) {+ return;+ }+// Find the last @ before cursorconst lastAtIndex = textBeforeCursor.lastIndexOf('@');@@ -2347,6 +2401,13 @@ export const AIChat: Component<AIChatProps> = (props) => {setMentionActive(false);};+ const handleSlashCommandSelect = (command: AssistantSlashCommand) => {+ setSlashCommandActive(false);+ setSlashCommandQuery('');+ setInput(`/${command.name}`);+ executeSlashCommand(command.action);+ };+// Handle mention selectionconst handleMentionSelect = (resource: MentionResource) => {const currentInput = input();@@ -2360,6 +2421,8 @@ export const AIChat: Component<AIChatProps> = (props) => {setInput(newValue);setMentionActive(false);+ setSlashCommandActive(false);+ setSlashCommandQuery('');// Accumulate the structured mention data so we can send it with the promptsetAccumulatedMentions((prev) => {@@ -2387,6 +2450,12 @@ export const AIChat: Component<AIChatProps> = (props) => {return;}}+ if (slashCommandActive()) {+ if (['ArrowDown', 'ArrowUp', 'Enter', 'Tab', 'Escape'].includes(e.key)) {+ // These are handled by SlashCommandAutocomplete.+ return;+ }+ }if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;@@ -3376,7 +3445,7 @@ export const AIChat: Component<AIChatProps> = (props) => {><divclass={`relative flex min-h-[56px] items-end rounded-lg border bg-surface-alt shadow-sm transition-colors ${- mentionActive()+ mentionActive() || slashCommandActive()? 'border-blue-400 ring-2 ring-blue-500/20': 'border-border focus-within:border-blue-500 focus-within:ring-2 focus-within:ring-blue-500/20'}`}@@ -3400,6 +3469,13 @@ export const AIChat: Component<AIChatProps> = (props) => {visible={mentionActive()}/></div>+ <SlashCommandAutocomplete+ query={slashCommandQuery()}+ position={{ top: 58, left: 0 }}+ onSelect={handleSlashCommandSelect}+ onClose={() => setSlashCommandActive(false)}+ visible={slashCommandActive()}+ /><div class="absolute bottom-2 right-2 flex items-center gap-1.5"><Show when={chat.isLoading()}><button