debug: write gemini raw response to disk-backed /tmp/last_gemini.json for accurate multinode diagnostics
This commit is contained in:
@@ -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.",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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 = "";
|
||||
|
||||
Reference in New Issue
Block a user