Skip to content

Commit 64413a6

Browse files
committed
Replace console logs with a persistent and shared debug log
1 parent 45c7ba5 commit 64413a6

File tree

15 files changed

+1426
-200
lines changed

15 files changed

+1426
-200
lines changed

entrypoints/sidepanel/ChatInterface.tsx

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
MessageToSidebar,
1313
} from '~/utils/types';
1414
import { createStableId, isExtensionSettings } from '~/utils/types';
15+
import DebugLogViewer from './components/DebugLogViewer';
1516
import ManualToolInterface from './ManualToolInterface';
1617
import { MemoizedMarkdown } from './MemoizedMarkdown';
1718

@@ -278,6 +279,8 @@ const ChatInterface: React.FC = () => {
278279
const [isLoading, setIsLoading] = useState(false);
279280
const [status, setStatus] = useState<{ text: string; type?: 'error' | 'thinking' }>({ text: '' });
280281
const [tabId, setTabId] = useState<number | null>(null);
282+
const [showDebugLogs, setShowDebugLogs] = useState(false);
283+
const [showToolsPanel, setShowToolsPanel] = useState(false);
281284

282285
const messagesEndRef = useRef<HTMLDivElement>(null);
283286
const isRefreshingRef = useRef(false);
@@ -295,12 +298,6 @@ const ChatInterface: React.FC = () => {
295298

296299
const getTabChatHistory = useCallback(
297300
(settings: ExtensionSettings | null, currentTabId: number | null): ChatMessage[] => {
298-
sidepanelLogger.debug('getTabChatHistory called', {
299-
hasSettings: !!settings,
300-
currentTabId,
301-
settingsType: typeof settings,
302-
});
303-
304301
if (!settings) {
305302
sidepanelLogger.debug('No settings, returning empty array');
306303
return [];
@@ -314,12 +311,6 @@ const ChatInterface: React.FC = () => {
314311
}
315312

316313
const tabConversations = settings.tabConversations?.[currentTabId.toString()];
317-
sidepanelLogger.debug('Tab conversations lookup', {
318-
hasTabConversations: !!settings.tabConversations,
319-
tabKey: currentTabId.toString(),
320-
foundConversation: !!tabConversations,
321-
conversationLength: tabConversations?.length || 0,
322-
});
323314

324315
return tabConversations || [];
325316
},
@@ -560,18 +551,9 @@ const ChatInterface: React.FC = () => {
560551
};
561552

562553
const renderAssistantMessage = (message: ChatMessage) => {
563-
sidepanelLogger.debug('renderAssistantMessage called', {
564-
messageId: message.id,
565-
hasContent: !!message.content,
566-
});
567-
568554
// Process AI SDK UI parts structure
569555
const messageWithParts = message as StreamingChatMessageWithParts;
570556
if (messageWithParts.parts && Array.isArray(messageWithParts.parts)) {
571-
sidepanelLogger.debug('Processing message parts (AI SDK UI)', {
572-
partCount: messageWithParts.parts.length,
573-
});
574-
575557
return (
576558
<div className="assistant-message">
577559
{messageWithParts.parts.map((part: MessagePart, index: number) => (
@@ -601,23 +583,41 @@ const ChatInterface: React.FC = () => {
601583
<header className="chat-header">
602584
<h1>LLM Chat</h1>
603585
<div className="header-buttons">
586+
{settings?.debugMode && (
587+
<button
588+
type="button"
589+
onClick={() => setShowDebugLogs(!showDebugLogs)}
590+
className="header-btn"
591+
title="View debug logs"
592+
>
593+
🐛 Logs
594+
</button>
595+
)}
596+
<button
597+
type="button"
598+
onClick={() => setShowToolsPanel(!showToolsPanel)}
599+
className="header-btn"
600+
title="Toggle manual tools panel"
601+
>
602+
🛠️ Tools
603+
</button>
604604
<button
605605
type="button"
606606
id="clear-btn"
607607
onClick={clearChat}
608-
className="clear-btn"
608+
className="header-btn"
609609
title="Clear Chat"
610610
>
611-
🗑️
611+
🗑️ Clear
612612
</button>
613613
<button
614614
type="button"
615615
id="settings-btn"
616616
onClick={openSettings}
617-
className="settings-btn"
617+
className="header-btn"
618618
title="Open Settings"
619619
>
620-
⚙️
620+
⚙️ Settings
621621
</button>
622622
</div>
623623
</header>
@@ -637,13 +637,6 @@ const ChatInterface: React.FC = () => {
637637
</div>
638638
) : (
639639
(() => {
640-
sidepanelLogger.debug('Rendering messages', {
641-
messageCount: messages?.length || 0,
642-
isArray: Array.isArray(messages),
643-
messageTypes: Array.isArray(messages)
644-
? messages.filter((m) => m).map((m) => m.role)
645-
: [],
646-
});
647640
return (Array.isArray(messages) ? messages : [])
648641
.filter((message) => {
649642
if (!message) {
@@ -676,7 +669,11 @@ const ChatInterface: React.FC = () => {
676669
</span>
677670
</div>
678671

679-
<ManualToolInterface onExecuteTool={testFunction} isExecuting={isLoading} />
672+
{showToolsPanel && (
673+
<ManualToolInterface onExecuteTool={testFunction} isExecuting={isLoading} />
674+
)}
675+
676+
<DebugLogViewer isVisible={showDebugLogs} onClose={() => setShowDebugLogs(false)} />
680677

681678
<div className="input-container">
682679
<textarea

0 commit comments

Comments
 (0)