import { OpenRouterClient } from "../../lib/openrouter"; import { TradingGraph } from "../../agents/tradingGraph"; export async function action({ request }: { request: Request }) { const formData = await request.formData(); const ticker = formData.get("ticker") as string; const date = formData.get("date") as string; if (!ticker) { return Response.json({ error: "ticker is required" }, { status: 400 }); } const apiKey = process.env.OPENROUTER_API_KEY; if (!apiKey) { return Response.json({ error: "OPENROUTER_API_KEY not configured" }, { status: 500 }); } const client = new OpenRouterClient(apiKey); const graph = new TradingGraph(client); const input = { financialData: `Financial data for ${ticker} as of ${date || "latest"}`, technicalData: { prices: [100, 102, 101, 103, 105], sma: 102, ema: 103, rsi: 55, macd: 0.5, }, sentimentData: { headlines: [`${ticker} showing positive momentum`], source: "news" as const, }, }; try { const decision = await graph.propagate(ticker, input); return Response.json({ decision, ticker, date }); } catch (error) { const message = error instanceof Error ? error.message : "Unknown error"; return Response.json({ error: message }, { status: 500 }); } }