diff --git a/vibn-frontend/app/api/chat/debug/route.ts b/vibn-frontend/app/api/chat/debug/route.ts index 580bad0..22411d4 100644 --- a/vibn-frontend/app/api/chat/debug/route.ts +++ b/vibn-frontend/app/api/chat/debug/route.ts @@ -1,14 +1,26 @@ -import { NextResponse } from 'next/server'; +import { NextResponse } from "next/server"; +import fs from "fs"; +import path from "path"; -// Global variable to store the last raw Gemini response for easy debugging -let lastGeminiResponse: any = null; - -export function setLastGeminiResponse(resp: any) { - lastGeminiResponse = resp; -} +const DEBUG_FILE = "/tmp/last_gemini.json"; export async function GET() { + try { + if (fs.existsSync(DEBUG_FILE)) { + const raw = fs.readFileSync(DEBUG_FILE, "utf8"); + return NextResponse.json({ + lastResponse: JSON.parse(raw), + }); + } + } catch (e) { + return NextResponse.json({ + error: "Failed to read debug file", + details: String(e), + }); + } + return NextResponse.json({ - lastResponse: lastGeminiResponse || "No requests captured yet since last deploy. Send a message from the desktop first." + lastResponse: + "No requests captured on disk yet since last deploy. Send a message from the desktop first.", }); } diff --git a/vibn-frontend/lib/ai/gemini-chat.ts b/vibn-frontend/lib/ai/gemini-chat.ts index b8f7f61..c3387cf 100644 --- a/vibn-frontend/lib/ai/gemini-chat.ts +++ b/vibn-frontend/lib/ai/gemini-chat.ts @@ -1,4 +1,5 @@ import { GoogleGenAI } from "@google/genai"; +import fs from "fs"; const GEMINI_API_KEY = process.env.GOOGLE_API_KEY || ""; const GEMINI_MODEL = process.env.VIBN_CHAT_MODEL || "gemini-3.1-pro-preview"; @@ -139,11 +140,13 @@ export async function callGeminiChat(opts: { ); try { - const { setLastGeminiResponse } = - await import("../../app/api/chat/debug/route"); - setLastGeminiResponse(response); + fs.writeFileSync( + "/tmp/last_gemini.json", + JSON.stringify(response, null, 2), + "utf8", + ); } catch (e) { - console.warn("Failed to set debug response:", e); + console.warn("Failed to write debug response to disk:", e); } let text = "";