Files
henry 3340fd11ca feat: add stock database with prisma for portfolio persistence
- Initialize Prisma with SQLite and Stock model
- Create database service layer with singleton client
- Add API routes for stock CRUD operations
- Integrate database with analyze page to persist ticker entries
- Add Playwright tests for stock database functionality
2026-05-14 10:23:56 +02:00

80 lines
2.3 KiB
TypeScript

import { OpenRouterClient } from "../lib/openrouter";
import type { AnalystReport, DebateRound } from "../types/agents";
type ChatResponse = {
choices?: Array<{ message?: { content?: string } }>;
};
export class BullishResearcher {
private client: OpenRouterClient;
private model: string;
constructor(client: OpenRouterClient, model?: string) {
this.client = client;
this.model = model ?? "openai/gpt-oss-120b:free";
}
async research(ticker: string, reports: AnalystReport[]): Promise<DebateRound> {
const reportSummaries = reports
.map((r) => `${r.analyst}: ${r.signal.signal} - ${r.report}`)
.join("\n");
const prompt = `Analyze these analyst reports for ${ticker} and synthesize a bullish thesis:
${reportSummaries}
Provide a bullish view based on the positive signals and reasoning.`;
const response = await this.client.createChatCompletion(
[
{ role: "system", content: "You are a bullish equity researcher who finds the positive investment case." },
{ role: "user", content: prompt },
],
this.model
);
const content = ((response as ChatResponse).choices?.[0]?.message?.content) ?? "";
return {
bullishView: content,
bearishView: "",
researcher: "bullish",
};
}
}
export class BearishResearcher {
private client: OpenRouterClient;
private model: string;
constructor(client: OpenRouterClient, model?: string) {
this.client = client;
this.model = model ?? "openai/gpt-oss-120b:free";
}
async research(ticker: string, reports: AnalystReport[]): Promise<DebateRound> {
const reportSummaries = reports
.map((r) => `${r.analyst}: ${r.signal.signal} - ${r.report}`)
.join("\n");
const prompt = `Analyze these analyst reports for ${ticker} and synthesize a bearish thesis:
${reportSummaries}
Provide a bearish view based on the risks and negative signals.`;
const response = await this.client.createChatCompletion(
[
{ role: "system", content: "You are a bearish equity researcher who identifies investment risks." },
{ role: "user", content: prompt },
],
this.model
);
const content = ((response as ChatResponse).choices?.[0]?.message?.content) ?? "";
return {
bullishView: "",
bearishView: content,
researcher: "bearish",
};
}
}