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
Use policy-aware AI chat mention labels
rcourtmanc0f7a7fe0bea
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsxindex 6db7fde9f5..3b74998a02 100644--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx@@ -83,7 +83,7 @@ const {notifySettingsChanged: vi.fn(),};- const mockByType = vi.fn((): Array<{ name: string }> => []);+ const mockByType = vi.fn((_type: string): Array<{ name: string }> => []);const mockResources = vi.fn((): Array<{ id: string; type: string }> => []);return {@@ -124,12 +124,31 @@ vi.mock('../ModelSelector', () => ({}));vi.mock('../MentionAutocomplete', () => ({- MentionAutocomplete: (props: { visible: boolean; query: string }) => (+ MentionAutocomplete: (props: {+ visible: boolean;+ query: string;+ resources: Array<{ id: string; name: string }>;+ onSelect: (resource: { id: string; name: string }) => void;+ }) => (<divdata-testid="mention-autocomplete"data-visible={String(props.visible)}data-query={props.query}- />+ data-resource-count={String(props.resources.length)}+ data-resource-labels={props.resources.map((resource) => resource.name).join('|')}+ >+ <button+ type="button"+ data-testid="mention-select-first"+ onClick={() => {+ if (props.resources[0]) {+ props.onSelect(props.resources[0]);+ }+ }}+ >+ select-first+ </button>+ </div>),}));@@ -499,6 +518,101 @@ describe('AIChat', () => {const autocomplete = screen.getByTestId('mention-autocomplete');expect(autocomplete).toHaveAttribute('data-visible', 'false');});++ it('uses policy-aware labels and preserves distinct governed mention candidates', async () => {+ const governedPolicy = {+ sensitivity: 'restricted' as const,+ routing: { scope: 'local-only' as const, redact: ['hostname'] as const },+ };+ const governedResources = [+ {+ id: 'agent-1',+ name: 'secret-node-1',+ displayName: 'secret-node-1',+ type: 'agent' as const,+ status: 'online',+ policy: governedPolicy,+ aiSafeSummary: 'redacted by policy',+ },+ {+ id: 'agent-2',+ name: 'secret-node-2',+ displayName: 'secret-node-2',+ type: 'agent' as const,+ status: 'online',+ policy: governedPolicy,+ aiSafeSummary: 'redacted by policy',+ },+ ];+ mockByType.mockImplementation((type: string) => (type === 'agent' ? governedResources : []));+ mockResources.mockReturnValue(governedResources);++ renderChat();+ const textarea = screen.getByPlaceholderText(+ 'Ask about your infrastructure...',+ ) as HTMLTextAreaElement;+ Object.defineProperty(textarea, 'selectionStart', { value: 1, writable: true });+ fireEvent.input(textarea, { target: { value: '@' } });++ const autocomplete = await screen.findByTestId('mention-autocomplete');+ expect(autocomplete).toHaveAttribute('data-resource-count', '2');+ expect(autocomplete).toHaveAttribute(+ 'data-resource-labels',+ 'redacted by policy|redacted by policy',+ );+ });++ it('inserts the governed display label into the prompt when a mention is selected', async () => {+ const governedPolicy = {+ sensitivity: 'restricted' as const,+ routing: { scope: 'local-only' as const, redact: ['hostname'] as const },+ };+ const governedResources = [+ {+ id: 'agent-1',+ name: 'secret-node-1',+ displayName: 'secret-node-1',+ type: 'agent' as const,+ status: 'online',+ policy: governedPolicy,+ aiSafeSummary: 'redacted by policy',+ },+ ];+ mockByType.mockImplementation((type: string) => (type === 'agent' ? governedResources : []));+ mockResources.mockReturnValue(governedResources);++ renderChat();+ const textarea = screen.getByPlaceholderText(+ 'Ask about your infrastructure...',+ ) as HTMLTextAreaElement;+ Object.defineProperty(textarea, 'selectionStart', { value: 1, writable: true });+ fireEvent.input(textarea, { target: { value: '@' } });++ await waitFor(() => {+ expect(screen.getByTestId('mention-autocomplete')).toHaveAttribute(+ 'data-resource-count',+ '1',+ );+ });++ fireEvent.click(screen.getByTestId('mention-select-first'));+ await waitFor(() => {+ expect(textarea.value).toBe('@redacted by policy ');+ });++ fireEvent.keyDown(textarea, { key: 'Enter' });+ expect(mockChat.sendMessage).toHaveBeenCalledWith(+ '@redacted by policy',+ [+ expect.objectContaining({+ id: 'node::secret-node-1',+ name: 'redacted by policy',+ type: 'agent',+ }),+ ],+ undefined,+ );+ });});// ── Model persistence ────────────────────────────────────────────────diff --git a/frontend-modern/src/components/AI/Chat/index.tsx b/frontend-modern/src/components/AI/Chat/index.tsxindex 74285a97ff..804363dd85 100644--- a/frontend-modern/src/components/AI/Chat/index.tsx+++ b/frontend-modern/src/components/AI/Chat/index.tsx@@ -341,7 +341,8 @@ export const AIChat: Component<AIChatProps> = (props) => {};const dedupeMentionResources = (resources: MentionResource[]) => {- // Only dedupe agent mentions: VMs/containers/docker containers can legitimately share names across nodes/agents.+ // Only dedupe agent mentions, and use the stable mention id so redacted labels+ // do not collapse distinct resources into one suggestion.const byKey = new Map<string, { resource: MentionResource; index: number }>();const out: MentionResource[] = [];@@ -351,7 +352,7 @@ export const AIChat: Component<AIChatProps> = (props) => {continue;}- const key = `${normalizeChatMentionKeyPart(resource.name)}:${resource.type}`;+ const key = resource.id;const existing = byKey.get(key);if (!existing) {const index = out.length;@@ -437,7 +438,7 @@ export const AIChat: Component<AIChatProps> = (props) => {const vmid = parseLegacyVmid(vm, platformData);mentionCandidates.push({id: `vm:${node}:${vmid}`,- name: vm.name,+ name: getPreferredResourceDisplayName(vm),type: 'vm',status: vm.status === 'running' ? 'running' : 'stopped',node,@@ -452,7 +453,7 @@ export const AIChat: Component<AIChatProps> = (props) => {const vmid = parseLegacyVmid(container, platformData);mentionCandidates.push({id: `system-container:${node}:${vmid}`,- name: container.name,+ name: getPreferredResourceDisplayName(container),type: 'system-container',status: container.status === 'running' ? 'running' : 'stopped',node,@@ -493,7 +494,7 @@ export const AIChat: Component<AIChatProps> = (props) => {: container.id;mentionCandidates.push({id: `docker:${dockerActionId}:${originalContainerId}`,- name: container.name,+ name: getPreferredResourceDisplayName(container),type: 'app-container',status: container.status === 'running' ? 'running' : 'exited',node: hostnameOrId,@@ -505,7 +506,7 @@ export const AIChat: Component<AIChatProps> = (props) => {for (const node of nodes) {mentionCandidates.push({id: `node:${node.platformId || ''}:${node.name}`,- name: node.name,+ name: getPreferredResourceDisplayName(node),type: 'agent',status: node.status,});