mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Hide image preview when it has an error in ToolCallDisplay
This commit is contained in:
2 files changed
+10
-2
No files matched your search
@@ -302,6 +302,7 @@ function parseToolError(result: string | undefined, expectedToolName: string): s
|
||||
export function ToolCallDisplay({ toolName, toolArgs, state, result }: ToolCallDisplayProps) {
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
const [expandedImageUrl, setExpandedImageUrl] = useState<string | null>(null);
|
||||
const [imageLoadError, setImageLoadError] = useState(false);
|
||||
|
||||
const toolInfo = getToolInfo(toolName, toolArgs);
|
||||
const IconComponent = toolInfo.icon;
|
||||
@@ -433,6 +434,9 @@ export function ToolCallDisplay({ toolName, toolArgs, state, result }: ToolCallD
|
||||
const imagePath = match[1];
|
||||
const filename = imagePath.split('/').pop() || imagePath;
|
||||
|
||||
// Hide the image section if there was a load error
|
||||
if (imageLoadError) return null;
|
||||
|
||||
return (
|
||||
<div className="mt-1 p-3 bg-muted/30 rounded border max-w-xs">
|
||||
<div
|
||||
@@ -443,6 +447,7 @@ export function ToolCallDisplay({ toolName, toolArgs, state, result }: ToolCallD
|
||||
path={imagePath}
|
||||
alt={filename}
|
||||
className="max-w-full h-auto rounded"
|
||||
onError={() => setImageLoadError(true)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -8,9 +8,10 @@ interface VFSImageProps {
|
||||
alt: string;
|
||||
className?: string;
|
||||
onClick?: () => void;
|
||||
onError?: (error: string) => void;
|
||||
}
|
||||
|
||||
export function VFSImage({ path, alt, className, onClick }: VFSImageProps) {
|
||||
export function VFSImage({ path, alt, className, onClick, onError }: VFSImageProps) {
|
||||
const { fs } = useFS();
|
||||
const [dataUri, setDataUri] = useState<string | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -58,8 +59,10 @@ export function VFSImage({ path, alt, className, onClick }: VFSImageProps) {
|
||||
}
|
||||
} catch (err) {
|
||||
if (isMounted) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to load image');
|
||||
const errorMessage = err instanceof Error ? err.message : 'Failed to load image';
|
||||
setError(errorMessage);
|
||||
setIsLoading(false);
|
||||
onError?.(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user