chore: remove verbose console.log output from analyze API, keep only error/warn logs

This commit is contained in:
2026-05-16 22:24:22 +02:00
parent 1eddb9173e
commit ff798abf04
-17
View File
@@ -3,16 +3,12 @@
// Server-only imports are loaded dynamically inside the action to avoid client bundling issues // Server-only imports are loaded dynamically inside the action to avoid client bundling issues
export async function action({ request }: { request: Request }) { export async function action({ request }: { request: Request }) {
console.log("[analyze] Request received:", request.method, request.url);
const body = await request.json(); const body = await request.json();
console.log("[analyze] Request body:", JSON.stringify(body));
const ticker = body.ticker?.toUpperCase(); const ticker = body.ticker?.toUpperCase();
const date = body.date || new Date().toISOString().split("T")[0]; const date = body.date || new Date().toISOString().split("T")[0];
if (!ticker) { if (!ticker) {
console.log("[analyze] Error: ticker missing");
return Response.json({ error: "ticker is required" }, { status: 400 }); return Response.json({ error: "ticker is required" }, { status: 400 });
} }
@@ -22,10 +18,8 @@ export async function action({ request }: { request: Request }) {
const { fetchAccount, fetchRecentCloses, fetchBars } = await import("../../lib/alpacaClient"); const { fetchAccount, fetchRecentCloses, fetchBars } = await import("../../lib/alpacaClient");
const apiKey = process.env.OPENROUTER_API_KEY; const apiKey = process.env.OPENROUTER_API_KEY;
console.log("[analyze] API key configured:", !!apiKey, apiKey?.substring(0, 10) + "...");
if (!apiKey || apiKey === "your_openrouter_api_key_here") { if (!apiKey || apiKey === "your_openrouter_api_key_here") {
console.log("[analyze] Using mock mode");
const mockDecision = { const mockDecision = {
action: "hold" as const, action: "hold" as const,
confidence: 0.75, confidence: 0.75,
@@ -54,12 +48,10 @@ export async function action({ request }: { request: Request }) {
}, },
], ],
}; };
console.log("[analyze] Returning mock decision");
return Response.json(mockDecision); return Response.json(mockDecision);
} }
const { graph, config } = await buildTradingGraph(apiKey); const { graph, config } = await buildTradingGraph(apiKey);
console.log("[analyze] Trading config:", config);
// Fetch latest Alpaca account and recent prices; abort if unavailable // Fetch latest Alpaca account and recent prices; abort if unavailable
let account: any = undefined; let account: any = undefined;
@@ -101,8 +93,6 @@ export async function action({ request }: { request: Request }) {
}; };
try { try {
console.log("[analyze] Running trading graph...");
if (body.background) { if (body.background) {
// Enqueue background analyze job and return 202 immediately // Enqueue background analyze job and return 202 immediately
try { try {
@@ -132,13 +122,6 @@ export async function action({ request }: { request: Request }) {
console.warn("Failed to enrich execution plan:", e); console.warn("Failed to enrich execution plan:", e);
} }
// Avoid logging potentially verbose debate rounds to server CLI
try {
const { debateRounds, ...decisionSafe } = decision as any;
console.log("[analyze] Decision received (debate redacted):", JSON.stringify(decisionSafe));
} catch (e) {
console.log("[analyze] Decision received");
}
return Response.json(decision); return Response.json(decision);
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : "Unknown error"; const message = error instanceof Error ? error.message : "Unknown error";