From d04c85d7b8508353a8fd369df8d570b00288bf0c Mon Sep 17 00:00:00 2001 From: mawkone Date: Mon, 1 Jun 2026 15:54:12 -0700 Subject: [PATCH] debug: write gemini raw response to disk-backed /tmp/last_gemini.json for accurate multinode diagnostics --- vibn-frontend/app/api/chat/debug/route.ts | 28 ++++++++++++++++------- vibn-frontend/lib/ai/gemini-chat.ts | 11 +++++---- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/vibn-frontend/app/api/chat/debug/route.ts b/vibn-frontend/app/api/chat/debug/route.ts index 580bad08..22411d41 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 b8f7f615..c3387cf7 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 = "";