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 dev stream fixture
rcourtman2b747f5dbbd8
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex 08aa04edac..b2abdcddba 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -385,6 +385,16 @@ runtime cost control, and shared AI transport surfaces.content and hidden reasoning may continue to opt out of those checkpoints soanswer streaming remains fast, while session, workflow, model-switch, tool,approval, and question events remain user-visible progress checkpoints.+ That same frontend stream boundary owns the deterministic dev/test fixture+ used for fast Assistant UX iteration: `frontend-modern/src/api/aiChat.ts`+ may short-circuit an explicit local fixture prompt only when+ `import.meta.env.DEV` or test mode is active, and the fixture must emit the+ same typed `StreamEvent` objects (`session`, `workflow_state`, `thinking`,+ `tool_start`, `tool_progress`, `tool_end`, `content`, `done`) through the+ normal `useChat` reducer rather than rendering a separate mock transcript.+ This fixture is a local development primitive, not a product mode: it must+ not bypass backend governance in production, persist as a server session, or+ introduce any UI-only event shape that real providers cannot emit.Live answer text must be paced in the presentation layer, not throttled ormutated in the canonical stream state: appended content is revealed in shortreadable slices while the turn is streaming, and completed/restored messagesdiff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex 219c0e6e1c..646d96c61a 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -546,6 +546,17 @@ payload shape change when the portal presents compact client rows.fixture must pace its browser-facing status/tool/content events enough toprove the visible stream contract, while tests may disable that pace to keepbackend proof fast.+ The frontend API client may also own an explicit local dev/test Assistant+ stream fixture at `frontend-modern/src/api/aiChatDevStreamFixture.ts` for+ fast UX iteration against the real stream reducer. That fixture may+ short-circuit `frontend-modern/src/api/aiChat.ts` only in Vite dev or test+ mode, only for reserved `/fixture ...` prompts, and only by calling the+ normal `AIChatAPI.chat` event callback with the generated+ `AIChatStreamEvent` union (`session`, `workflow_state`, `thinking`,+ `tool_start`, `tool_progress`, `tool_end`, `content`, `done`). It must not+ open a backend session, mutate persisted chat history, add browser-only+ stream event shapes, or become a production fallback for provider or VPN+ failures.34. `internal/api/ai_handlers.go` shared with `ai-runtime`: AI settings and remediation handlers are both an AI runtime control surface and a canonical API payload contract boundary.Legacy Assistant SSE routes in this handler that still use the olderexecute envelope, including `/api/ai/execute/stream` anddiff --git a/frontend-modern/src/api/__tests__/aiChat.test.ts b/frontend-modern/src/api/__tests__/aiChat.test.tsindex a701c22699..c67c08875b 100644--- a/frontend-modern/src/api/__tests__/aiChat.test.ts+++ b/frontend-modern/src/api/__tests__/aiChat.test.ts@@ -98,6 +98,55 @@ describe('AIChatAPI', () => {expect(shouldYield({ type: 'thinking' })).toBe(false);});+ it('runs the local dev stream fixture without opening a provider request', async () => {+ const onEvent = vi.fn();++ await AIChatAPI.chat(+ ' /fixture devices ',+ undefined,+ 'openrouter:deepseek/deepseek-chat',+ onEvent,+ );++ expect(apiFetchMock).not.toHaveBeenCalled();+ expect(onEvent.mock.calls.map(([event]) => event.type)).toEqual([+ 'session',+ 'workflow_state',+ 'workflow_state',+ 'thinking',+ 'tool_start',+ 'tool_progress',+ 'tool_end',+ 'content',+ 'done',+ ]);+ expect(onEvent.mock.calls[1][0]).toMatchObject({+ type: 'workflow_state',+ data: { phase: 'request_start', message: 'Preparing Pulse context.' },+ });+ expect(onEvent.mock.calls[4][0]).toMatchObject({+ type: 'tool_start',+ data: {+ id: 'fixture-tool-devices',+ name: 'pulse_read',+ },+ });+ expect(onEvent.mock.calls[7][0]).toMatchObject({+ type: 'content',+ data: {+ text: expect.stringContaining('4,358 entries'),+ },+ });+ expect(onEvent.mock.calls[8][0]).toMatchObject({+ type: 'done',+ data: {+ model: 'openrouter:deepseek/deepseek-chat',+ input_tokens: 4358,+ output_tokens: 943,+ },+ });+ });+it('lets the browser paint the first visible text delta before draining a coalesced chat chunk', async () => {vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });const requestAnimationFrame = installAnimationFrame();diff --git a/frontend-modern/src/api/aiChat.ts b/frontend-modern/src/api/aiChat.tsindex 7bfbf21eb8..94d087f418 100644--- a/frontend-modern/src/api/aiChat.ts+++ b/frontend-modern/src/api/aiChat.ts@@ -3,6 +3,7 @@ import { assertAPIResponseOK } from './responseUtils';import { logger } from '@/utils/logger';import type { AIChatStreamEvent } from './generated/aiChatEvents';import { consumeJSONEventStream } from './streaming';+import { maybeRunAIChatDevStreamFixture } from './aiChatDevStreamFixture';// AI Chat API - Simplified AI interface@@ -366,6 +367,10 @@ export class AIChatAPI {): Promise<void> {logger.debug('[AI Chat] Starting chat stream', { prompt: prompt.substring(0, 50) });+ if (await maybeRunAIChatDevStreamFixture({ prompt, model, onEvent, signal })) {+ return;+ }+const body: Record<string, unknown> = {prompt,session_id: sessionId,diff --git a/frontend-modern/src/api/aiChatDevStreamFixture.ts b/frontend-modern/src/api/aiChatDevStreamFixture.tsnew file mode 100644index 0000000000..2750c7e93c--- /dev/null+++ b/frontend-modern/src/api/aiChatDevStreamFixture.ts@@ -0,0 +1,170 @@+import type { AIChatStreamEvent } from './generated/aiChatEvents';++export const AI_CHAT_DEV_STREAM_FIXTURE_PROMPTS = [+ '/fixture devices',+ '/fixture assistant-stream',+] as const;++const DEFAULT_DEV_FIXTURE_STEP_DELAY_MS = 140;+const TEST_FIXTURE_STEP_DELAY_MS = 0;++export interface AIChatDevStreamFixtureOptions {+ model?: string;+ onEvent: (event: AIChatStreamEvent) => void;+ prompt: string;+ signal?: AbortSignal;+ stepDelayMs?: number;+}++const normalizeFixturePrompt = (prompt: string) => prompt.trim().toLowerCase().replace(/\s+/g, ' ');++export const isAIChatDevStreamFixturePrompt = (prompt: string): boolean => {+ const normalized = normalizeFixturePrompt(prompt);+ return AI_CHAT_DEV_STREAM_FIXTURE_PROMPTS.some((fixturePrompt) => fixturePrompt === normalized);+};++const isAIChatDevStreamFixtureAvailable = () =>+ import.meta.env.DEV || import.meta.env.MODE === 'test';++const abortError = () => {+ const error = new Error('The operation was aborted.');+ error.name = 'AbortError';+ return error;+};++const throwIfAborted = (signal?: AbortSignal) => {+ if (signal?.aborted) {+ throw abortError();+ }+};++const waitForFixtureStep = (delayMs: number, signal?: AbortSignal) => {+ throwIfAborted(signal);+ if (delayMs <= 0) return Promise.resolve();++ return new Promise<void>((resolve, reject) => {+ let timeoutId: ReturnType<typeof setTimeout> | undefined;+ const cleanup = () => {+ if (timeoutId !== undefined) {+ clearTimeout(timeoutId);+ }+ signal?.removeEventListener('abort', handleAbort);+ };+ const handleAbort = () => {+ cleanup();+ reject(abortError());+ };++ timeoutId = setTimeout(() => {+ cleanup();+ resolve();+ }, delayMs);+ signal?.addEventListener('abort', handleAbort, { once: true });+ });+};++const assistantFixtureModel = (model?: string) => model?.trim() || 'dev:assistant-stream-fixture';++const buildDeviceCountFixtureEvents = (model?: string): AIChatStreamEvent[] => [+ {+ type: 'session',+ data: { id: 'dev-fixture-assistant-stream' },+ },+ {+ type: 'workflow_state',+ data: {+ phase: 'request_start',+ message: 'Preparing Pulse context.',+ },+ },+ {+ type: 'workflow_state',+ data: {+ phase: 'context',+ message: 'Reading current Pulse inventory with pulse_query.',+ tool: 'pulse_query',+ },+ },+ {+ type: 'thinking',+ data: { text: 'Checking device-node and block-device evidence before answering.' },+ },+ {+ type: 'tool_start',+ data: {+ id: 'fixture-tool-devices',+ name: 'pulse_read',+ input:+ '{"target_host":"current_resource","command":"ls /dev | wc -l && lsblk -d -o NAME,TYPE,SIZE"}',+ raw_input:+ 'pulse_read(target_host="current_resource", command="ls /dev | wc -l && lsblk -d -o NAME,TYPE,SIZE")',+ },+ },+ {+ type: 'tool_progress',+ data: {+ id: 'fixture-tool-devices',+ name: 'pulse_read',+ phase: 'running',+ message: 'Running command.',+ input:+ '{"target_host":"current_resource","command":"ls /dev | wc -l && lsblk -d -o NAME,TYPE,SIZE"}',+ raw_input:+ 'pulse_read(target_host="current_resource", command="ls /dev | wc -l && lsblk -d -o NAME,TYPE,SIZE")',+ },+ },+ {+ type: 'tool_end',+ data: {+ id: 'fixture-tool-devices',+ name: 'pulse_read',+ input:+ '{"target_host":"current_resource","command":"ls /dev | wc -l && lsblk -d -o NAME,TYPE,SIZE"}',+ raw_input:+ 'pulse_read(target_host="current_resource", command="ls /dev | wc -l && lsblk -d -o NAME,TYPE,SIZE")',+ output: ['4358', 'NAME TYPE SIZE', 'sda disk 1.8T', 'nvme0n1 disk 931.5G'].join('\n'),+ success: true,+ },+ },+ {+ type: 'content',+ data: {+ text: 'There are 4,358 entries under `/dev`. The block-device view shows 2 disk devices: `sda` and `nvme0n1`.',+ },+ },+ {+ type: 'done',+ data: {+ session_id: 'dev-fixture-assistant-stream',+ model: assistantFixtureModel(model),+ input_tokens: 4358,+ output_tokens: 943,+ },+ },+];++export const maybeRunAIChatDevStreamFixture = async (+ options: AIChatDevStreamFixtureOptions,+): Promise<boolean> => {+ if (!isAIChatDevStreamFixtureAvailable() || !isAIChatDevStreamFixturePrompt(options.prompt)) {+ return false;+ }++ const delayMs =+ options.stepDelayMs ??+ (import.meta.env.MODE === 'test'+ ? TEST_FIXTURE_STEP_DELAY_MS+ : DEFAULT_DEV_FIXTURE_STEP_DELAY_MS);+ const events = buildDeviceCountFixtureEvents(options.model);++ for (let index = 0; index < events.length; index += 1) {+ const event = events[index];+ throwIfAborted(options.signal);+ options.onEvent(event);+ if (index < events.length - 1) {+ await waitForFixtureStep(delayMs, options.signal);+ }+ }++ return true;+};