Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(workbench): render diagnostics entries in diagnostics widget

joshistoasta6b35ea85ff7
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/diagnostics/DiagnosticsHeaderActions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/diagnostics/DiagnosticsHeaderActions.tsx
index 63a7dc15fd..c5492af372 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/diagnostics/DiagnosticsHeaderActions.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/diagnostics/DiagnosticsHeaderActions.tsx
@@ -1,23 +1,24 @@
import { Badge } from '@chakra-ui/react';
import { Button } from '@workbench/components/ui';
-import { useWorkbenchDispatch, useWorkbenchSelector } from '@workbench/WorkbenchContext';
+import { clearProjectDiagnostics, useProjectDiagnostics } from '@workbench/diagnostics/logger';
+import { useActiveProjectSelector } from '@workbench/WorkbenchContext';
import { BugIcon } from 'lucide-react';
import { useCallback } from 'react';
export const DiagnosticsHeaderActions = () => {
- const errorCount = useWorkbenchSelector((snapshot) => snapshot.state.errorLog.length);
- const dispatch = useWorkbenchDispatch();
- const clearErrorLog = useCallback(() => dispatch({ type: 'clearErrorLog' }), [dispatch]);
+ const projectId = useActiveProjectSelector((project) => project.id);
+ const entries = useProjectDiagnostics(projectId);
+ const clearEntries = useCallback(() => clearProjectDiagnostics(projectId), [projectId]);
return (
<>
- {errorCount ? (
+ {entries.length ? (
<Badge colorPalette="red" size="xs">
<BugIcon />
- {errorCount}
+ {entries.length}
</Badge>
) : null}
- <Button disabled={errorCount === 0} size="2xs" variant="outline" onClick={clearErrorLog}>
+ <Button disabled={entries.length === 0} size="2xs" variant="outline" onClick={clearEntries}>
Clear
</Button>
</>
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/diagnostics/DiagnosticsWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/diagnostics/DiagnosticsWidgetView.tsx
index 2874698f4e..dcf0e02273 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/diagnostics/DiagnosticsWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/diagnostics/DiagnosticsWidgetView.tsx
@@ -1,38 +1,55 @@
+import type { DiagnosticEntry } from '@workbench/diagnostics/logger';
import type { WidgetViewProps } from '@workbench/types';
-import { HStack, Stack, Text } from '@chakra-ui/react';
+import { Badge, Box, HStack, Stack, Text } from '@chakra-ui/react';
import { Button, Panel } from '@workbench/components/ui';
+import { clearProjectDiagnostics, useProjectDiagnostics } from '@workbench/diagnostics/logger';
import { StatusWidgetChip } from '@workbench/widget-frame';
-import { useWorkbenchSelector } from '@workbench/WorkbenchContext';
+import { useActiveProjectSelector } from '@workbench/WorkbenchContext';
import { BugIcon, ClipboardListIcon } from 'lucide-react';
-import { useCallback } from 'react';
+import { memo, useCallback, useState } from 'react';
export const DiagnosticsWidgetView = ({ presentation, region }: WidgetViewProps) => {
- const errorCount = useWorkbenchSelector((snapshot) => snapshot.state.errorLog.length);
- const label = errorCount === 0 ? 'Clean' : `${errorCount} issue${errorCount === 1 ? '' : 's'}`;
+ const projectId = useActiveProjectSelector((project) => project.id);
+ const entries = useProjectDiagnostics(projectId);
+ const label = entries.length === 0 ? 'Clean' : `${entries.length} event${entries.length === 1 ? '' : 's'}`;
if (region === 'bottom' && presentation !== 'expanded') {
return (
- <StatusWidgetChip icon={errorCount > 0 ? BugIcon : ClipboardListIcon}>Diagnostics: {label}</StatusWidgetChip>
+ <StatusWidgetChip icon={entries.length > 0 ? BugIcon : ClipboardListIcon}>Diagnostics: {label}</StatusWidgetChip>
);
}
- return <DiagnosticsPanel />;
+ return <DiagnosticsPanel entries={entries} projectId={projectId} />;
};
-const DiagnosticsPanel = () => {
- const errorLog = useWorkbenchSelector((snapshot) => snapshot.state.errorLog);
+const DiagnosticsPanel = ({ entries, projectId }: { entries: DiagnosticEntry[]; projectId: string }) => {
+ const copyAll = useCallback(() => void navigator.clipboard?.writeText(JSON.stringify(entries, null, 2)), [entries]);
+ const clearEntries = useCallback(() => clearProjectDiagnostics(projectId), [projectId]);
return (
<Stack gap="3" p="2">
- {errorLog.length === 0 ? (
+ <HStack justify="space-between">
<Text color="fg.subtle" fontSize="2xs">
- Shell errors and debugging details will appear here without covering the workbench.
+ Project-scoped diagnostic events from workbench and widget loggers.
+ </Text>
+ <HStack gap="2">
+ <Button disabled={entries.length === 0} size="2xs" variant="outline" onClick={copyAll}>
+ Copy JSON
+ </Button>
+ <Button disabled={entries.length === 0} size="2xs" variant="outline" onClick={clearEntries}>
+ Clear
+ </Button>
+ </HStack>
+ </HStack>
+ {entries.length === 0 ? (
+ <Text color="fg.subtle" fontSize="2xs">
+ Logger events and performance timings will appear here without covering the workbench.
</Text>
) : (
<Stack gap="2">
- {errorLog.map((message, index) => (
- <DiagnosticsErrorRow key={`${message}-${index}`} message={message} />
+ {entries.map((entry) => (
+ <DiagnosticsEntryRow key={entry.id} entry={entry} />
))}
</Stack>
)}
@@ -40,19 +57,91 @@ const DiagnosticsPanel = () => {
);
};
-const DiagnosticsErrorRow = ({ message }: { message: string }) => {
- const copyMessage = useCallback(() => void navigator.clipboard?.writeText(message), [message]);
+const DiagnosticsEntryRow = memo(({ entry }: { entry: DiagnosticEntry }) => {
+ const [isRawVisible, setIsRawVisible] = useState(false);
+ const copyEntry = useCallback(() => void navigator.clipboard?.writeText(JSON.stringify(entry, null, 2)), [entry]);
+ const toggleRaw = useCallback(() => setIsRawVisible((current) => !current), []);
return (
<Panel gap="2" p="2">
- <Text color="fg.muted" fontFamily="mono" fontSize="2xs" whiteSpace="pre-wrap">
- {message}
- </Text>
- <HStack justify="end">
- <Button size="2xs" variant="outline" onClick={copyMessage}>
- Copy
+ <Stack gap="2">
+ <HStack align="start" gap="2" justify="space-between">
+ <Stack gap="1" minW="0">
+ <HStack gap="1.5" wrap="wrap">
+ <Badge colorPalette={getLevelColorPalette(entry.level)} size="xs">
+ {entry.level}
+ </Badge>
+ <Badge colorPalette="gray" size="xs">
+ {entry.namespace}
+ </Badge>
+ {entry.durationMs !== undefined ? (
+ <Badge colorPalette="purple" size="xs">
+ {entry.durationMs.toFixed(1)}ms
+ </Badge>
+ ) : null}
+ <Text color="fg.muted" fontFamily="mono" fontSize="2xs">
+ {formatSource(entry)}
+ </Text>
+ </HStack>
+ <Text color="fg" fontSize="xs" fontWeight="600">
+ {entry.message || '(no message)'}
+ </Text>
+ <Text color="fg.subtle" fontSize="2xs">
+ {new Date(entry.createdAt).toLocaleTimeString()}
+ </Text>
+ </Stack>
+ <Button size="2xs" variant="outline" onClick={copyEntry}>
+ Copy
+ </Button>
+ </HStack>
+ <Button alignSelf="start" size="2xs" variant="ghost" onClick={toggleRaw}>
+ {isRawVisible ? 'Hide raw entry' : 'Raw entry'}
</Button>
- </HStack>
+ {isRawVisible ? (
+ <Box
+ as="pre"
+ bg="bg.inset"
+ borderColor="border.subtle"
+ borderWidth="1px"
+ color="fg.muted"
+ fontFamily="mono"
+ fontSize="2xs"
+ maxH="16rem"
+ overflow="auto"
+ p="2"
+ rounded="md"
+ whiteSpace="pre-wrap"
+ >
+ {JSON.stringify(entry, null, 2)}
+ </Box>
+ ) : null}
+ </Stack>
</Panel>
);
+});
+
+DiagnosticsEntryRow.displayName = 'DiagnosticsEntryRow';
+
+const formatSource = (entry: DiagnosticEntry): string => {
+ if (entry.source.kind === 'widget') {
+ return `${entry.source.typeId}:${entry.source.instanceId}:${entry.source.region}`;
+ }
+
+ return `workbench:${entry.source.area}`;
+};
+
+const getLevelColorPalette = (level: DiagnosticEntry['level']): string => {
+ switch (level) {
+ case 'fatal':
+ case 'error':
+ return 'red';
+ case 'warn':
+ return 'orange';
+ case 'info':
+ return 'blue';
+ case 'debug':
+ return 'purple';
+ case 'trace':
+ return 'gray';
+ }
};