Skip to content

Commit 2b909e2

Browse files
committed
Fix Agent chat linter issues
1 parent 8b861d2 commit 2b909e2

File tree

1 file changed

+5
-58
lines changed

1 file changed

+5
-58
lines changed

ee/ui-component/components/chat/AgentChatMessages.tsx

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useEffect, useState } from "react";
2-
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
32
import { Badge } from "@/components/ui/badge";
43
import { PreviewMessage, UIMessage } from "./ChatMessages";
54
import ReactMarkdown from "react-markdown";
@@ -148,15 +147,6 @@ const ThinkingMessage = () => {
148147
);
149148
};
150149

151-
// Helper to render JSON content with syntax highlighting
152-
const renderJson = (obj: unknown) => {
153-
return (
154-
<pre className="max-h-[300px] overflow-auto whitespace-pre-wrap rounded-md bg-muted p-4 font-mono text-sm">
155-
{JSON.stringify(obj, null, 2)}
156-
</pre>
157-
);
158-
};
159-
160150
// Markdown content renderer component
161151
const MarkdownContent: React.FC<{ content: string }> = ({ content }) => {
162152
return (
@@ -227,22 +217,6 @@ const MarkdownContent: React.FC<{ content: string }> = ({ content }) => {
227217
);
228218
};
229219

230-
// Helper function to ensure image content is properly formatted
231-
const formatImageSource = (content: string): string => {
232-
// If already a data URI, use as is
233-
if (content.startsWith("data:image/")) {
234-
return content;
235-
}
236-
237-
// If it looks like base64 data without a prefix, add a PNG prefix
238-
if (/^[A-Za-z0-9+/=]+$/.test(content.substring(0, 20))) {
239-
return `data:image/png;base64,${content}`;
240-
}
241-
242-
// Otherwise assume it's a URL
243-
return content;
244-
};
245-
246220
// Component to render display objects
247221
const DisplayObjectRenderer: React.FC<{ object: DisplayObject; isInSourceView?: boolean }> = ({
248222
object,
@@ -266,9 +240,9 @@ const DisplayObjectRenderer: React.FC<{ object: DisplayObject; isInSourceView?:
266240
src={hasImagePrefix ? object.content : `data:image/png;base64,${object.content}`}
267241
alt={object.caption || "Image"}
268242
className="h-auto max-w-full"
269-
onError={e => {
270-
// Fallback chain: try JPEG if PNG fails
271-
const target = e.target as HTMLImageElement;
243+
onError={event => {
244+
// Correctly typed event parameter
245+
const target = event.target as HTMLImageElement;
272246
if (!hasImagePrefix && target.src.includes("image/png")) {
273247
target.src = `data:image/jpeg;base64,${object.content}`;
274248
}
@@ -283,35 +257,8 @@ const DisplayObjectRenderer: React.FC<{ object: DisplayObject; isInSourceView?:
283257
return null;
284258
};
285259

286-
// Helper function to detect image format from base64
287-
const detectImageFormat = (base64String: string): string => {
288-
// Check the first few bytes of the base64 to determine image format
289-
// See: https://en.wikipedia.org/wiki/List_of_file_signatures
290-
try {
291-
if (!base64String || base64String.length < 10) return "png";
292-
293-
// Decode the first few bytes of the base64 string
294-
const firstBytes = atob(base64String.substring(0, 20));
295-
296-
// Check for common image signatures
297-
if (firstBytes.startsWith("\xFF\xD8\xFF")) return "jpeg";
298-
if (firstBytes.startsWith("\x89PNG\r\n\x1A\n")) return "png";
299-
if (firstBytes.startsWith("GIF87a") || firstBytes.startsWith("GIF89a")) return "gif";
300-
if (firstBytes.startsWith("RIFF") && firstBytes.substring(8, 12) === "WEBP") return "webp";
301-
302-
// Default to PNG if signature not recognized
303-
return "png";
304-
} catch (e) {
305-
// If any error in detection, default to PNG
306-
return "png";
307-
}
308-
};
309-
310260
// Component to render sources as tags with dropdown content
311-
const SourcesRenderer: React.FC<{ sources: SourceObject[]; displayObjects?: DisplayObject[] }> = ({
312-
sources,
313-
displayObjects = [],
314-
}) => {
261+
const SourcesRenderer: React.FC<{ sources: SourceObject[] }> = ({ sources }) => {
315262
const [selectedSource, setSelectedSource] = useState<string | null>(null);
316263
const [animation, setAnimation] = useState<"open" | "close" | null>(null);
317264
const [visibleContent, setVisibleContent] = useState<string | null>(null);
@@ -470,7 +417,7 @@ export function AgentPreviewMessage({ message }: AgentMessageProps) {
470417
{/* Render sources if available */}
471418
{sources && sources.length > 0 && (
472419
<div className="mt-4 border-t border-border pt-3">
473-
<SourcesRenderer sources={sources} displayObjects={displayObjects} />
420+
<SourcesRenderer sources={sources} />
474421
</div>
475422
)}
476423
</div>

0 commit comments

Comments
 (0)