Fix(types): LLM types, execution LLM call safety, analyze defaults; skip tests in tsconfig for dev typecheck\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { OpenRouterClient } from "../../lib/openrouter";
|
||||
import { TradingGraph } from "../../agents/tradingGraph";
|
||||
import { db } from "../../lib/db.server";
|
||||
import { fetchAccount, fetchRecentCloses } from "../../lib/alpacaClient";
|
||||
|
||||
export async function action({ request }: { request: Request }) {
|
||||
console.log("[analyze] Request received:", request.method, request.url);
|
||||
@@ -56,19 +57,31 @@ export async function action({ request }: { request: Request }) {
|
||||
const client = new OpenRouterClient(apiKey);
|
||||
const graph = new TradingGraph(client);
|
||||
|
||||
// Fetch latest Alpaca account and recent prices; abort if unavailable
|
||||
let account: any = undefined;
|
||||
let prices: number[] = [];
|
||||
try {
|
||||
account = await fetchAccount();
|
||||
prices = await fetchRecentCloses(ticker);
|
||||
} catch (e) {
|
||||
console.error("[analyze] Failed to fetch Alpaca data before analysis:", e);
|
||||
return Response.json({ error: "Failed to fetch Alpaca data: " + String(e) }, { status: 502 });
|
||||
}
|
||||
|
||||
const input = {
|
||||
financialData: `Financial data for ${ticker} as of ${date}`,
|
||||
technicalData: {
|
||||
prices: [100, 102, 101, 103, 105],
|
||||
sma: 102,
|
||||
ema: 103,
|
||||
rsi: 55,
|
||||
macd: 0.5,
|
||||
prices,
|
||||
sma: 0,
|
||||
ema: 0,
|
||||
rsi: 0,
|
||||
macd: 0,
|
||||
},
|
||||
sentimentData: {
|
||||
headlines: [`${ticker} showing positive momentum`],
|
||||
source: "news" as const,
|
||||
},
|
||||
account,
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -86,7 +99,23 @@ export async function action({ request }: { request: Request }) {
|
||||
}
|
||||
}
|
||||
|
||||
const decision = await graph.propagate(ticker, input);
|
||||
let decision = await graph.propagate(ticker, input);
|
||||
// Enrich executionPlan deterministically on server-side
|
||||
try {
|
||||
const { enrichExecutionPlan, verifyExecutionPlanWithLLM } = await import("../../lib/execution");
|
||||
decision = enrichExecutionPlan(decision, input);
|
||||
// Optionally ask LLM to verify/adjust the computed plan if API key is present
|
||||
if (process.env.OPENROUTER_API_KEY) {
|
||||
try {
|
||||
decision = await verifyExecutionPlanWithLLM(decision, input);
|
||||
} catch (e) {
|
||||
console.warn("LLM verification failed:", e);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Failed to enrich execution plan:", e);
|
||||
}
|
||||
|
||||
console.log("[analyze] Decision received:", JSON.stringify(decision));
|
||||
return Response.json(decision);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user