From 91659e997ae250cfaa50b49fadca4af13a69a616 Mon Sep 17 00:00:00 2001 From: Henry Winkel Date: Sat, 16 May 2026 17:58:25 +0200 Subject: [PATCH] Build: make server-only imports dynamic in analyze route to avoid client bundling errors\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- app/routes/api/analyze.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/routes/api/analyze.ts b/app/routes/api/analyze.ts index 0822a57..ab6c06b 100644 --- a/app/routes/api/analyze.ts +++ b/app/routes/api/analyze.ts @@ -1,7 +1,4 @@ -import { OpenRouterClient } from "../../lib/openrouter"; -import { TradingGraph } from "../../agents/tradingGraph"; -import { db } from "../../lib/db.server"; -import { fetchAccount, fetchRecentCloses } from "../../lib/alpacaClient"; +// Server-only imports are loaded dynamically inside the action to avoid client bundling issues export async function action({ request }: { request: Request }) { console.log("[analyze] Request received:", request.method, request.url); @@ -17,6 +14,12 @@ export async function action({ request }: { request: Request }) { return Response.json({ error: "ticker is required" }, { status: 400 }); } + // Load server-only modules dynamically to prevent them from being included in client bundles + const { OpenRouterClient } = await import("../../lib/openrouter"); + const { TradingGraph } = await import("../../agents/tradingGraph"); + const { db } = await import("../../lib/db.server"); + const { fetchAccount, fetchRecentCloses } = await import("../../lib/alpacaClient"); + const apiKey = process.env.OPENROUTER_API_KEY; console.log("[analyze] API key configured:", !!apiKey, apiKey?.substring(0, 10) + "...");