feat: Add debug mode to inspect LLM prompts and responses

- Add DebugContext to track all LLM interactions
- Create DebugPanel component with floating UI
- Track prompts/responses in Tutor component (move analysis, hints, questions)
- Track prompts/responses in Analysis page (move commentary)
- Add NEXT_PUBLIC_DEBUG environment variable to enable/disable
- Include metadata (FEN, personality, language, etc.) in debug entries
- Add copy-to-clipboard and clear functionality
- Add DEBUG_MODE.md documentation
This commit is contained in:
Stefan
2025-11-27 18:20:12 +01:00
parent 54d92eaae5
commit c319904f00
6 changed files with 352 additions and 3 deletions
+20
View File
@@ -14,6 +14,7 @@ import ReactMarkdown from "react-markdown";
import { useTranslation } from '@/lib/i18n/useTranslation';
import { SupportedLanguage } from '@/lib/i18n/translations';
import { DetectedTactic } from '@/lib/tacticDetection';
import { useDebug } from '@/contexts/DebugContext';
interface TutorProps {
game: Chess;
@@ -45,6 +46,7 @@ export function Tutor({ game, currentFen, userMove, computerMove, stockfish, eva
const [isLoading, setIsLoading] = useState(false);
const [chatSession, setChatSession] = useState<ChatSession | null>(null);
const messagesContainerRef = useRef<HTMLDivElement>(null);
const { addEntry } = useDebug();
const t = useTranslation(language);
@@ -372,6 +374,24 @@ INSTRUCTIONS:
const response = await result.response;
const textResponse = response.text();
// Track debug entry
const actionType = isSystemMessage ? "Move Analysis" :
text.toLowerCase().includes("best move") ? "Best Move Request" :
text.toLowerCase().includes("hint") ? "Hint Request" :
"General Question";
addEntry({
type: 'tutor',
action: actionType,
prompt: finalPrompt,
response: textResponse,
metadata: {
fen: currentFen,
personality: personality.name,
language,
}
});
setMessages(prev => [...prev, { role: "model", text: textResponse, timestamp: Date.now() }]);
} catch (error) {
console.error("Chat Error:", error);