chore: commit all current changes
This commit is contained in:
@@ -286,6 +286,15 @@ function AnalysisPageContent() {
|
|||||||
<BrainCircuit className="size-4 text-[color:var(--accent)]" />
|
<BrainCircuit className="size-4 text-[color:var(--accent)]" />
|
||||||
</div>
|
</div>
|
||||||
<p className="mt-3 line-clamp-6 whitespace-pre-wrap text-sm leading-6 text-[color:var(--terminal-bright)]">{report.summary}</p>
|
<p className="mt-3 line-clamp-6 whitespace-pre-wrap text-sm leading-6 text-[color:var(--terminal-bright)]">{report.summary}</p>
|
||||||
|
<div className="mt-4 flex items-center justify-between gap-2">
|
||||||
|
<p className="text-xs text-[color:var(--terminal-muted)]">{report.accessionNumber}</p>
|
||||||
|
<Link
|
||||||
|
href={`/analysis/reports/${analysis.company.ticker}/${encodeURIComponent(report.accessionNumber)}`}
|
||||||
|
className="text-xs uppercase tracking-[0.12em] text-[color:var(--accent)] hover:text-[color:var(--accent-strong)]"
|
||||||
|
>
|
||||||
|
Open summary
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
</article>
|
</article>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
154
app/analysis/reports/[ticker]/[accessionNumber]/page.tsx
Normal file
154
app/analysis/reports/[ticker]/[accessionNumber]/page.tsx
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
|
import { format } from 'date-fns';
|
||||||
|
import { ArrowLeft, BrainCircuit, RefreshCcw } from 'lucide-react';
|
||||||
|
import { useParams } from 'next/navigation';
|
||||||
|
import { AppShell } from '@/components/shell/app-shell';
|
||||||
|
import { useAuthGuard } from '@/hooks/use-auth-guard';
|
||||||
|
import { getCompanyAiReport } from '@/lib/api';
|
||||||
|
import type { CompanyAiReportDetail } from '@/lib/types';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Panel } from '@/components/ui/panel';
|
||||||
|
|
||||||
|
function formatFilingDate(value: string) {
|
||||||
|
const date = new Date(value);
|
||||||
|
|
||||||
|
if (Number.isNaN(date.getTime())) {
|
||||||
|
return 'Unknown';
|
||||||
|
}
|
||||||
|
|
||||||
|
return format(date, 'MMM dd, yyyy');
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AnalysisReportPage() {
|
||||||
|
const { isPending, isAuthenticated } = useAuthGuard();
|
||||||
|
const params = useParams<{ ticker: string; accessionNumber: string }>();
|
||||||
|
|
||||||
|
const tickerFromRoute = useMemo(() => {
|
||||||
|
const value = typeof params.ticker === 'string' ? params.ticker : '';
|
||||||
|
return value.toUpperCase();
|
||||||
|
}, [params.ticker]);
|
||||||
|
|
||||||
|
const accessionNumber = useMemo(() => {
|
||||||
|
const value = typeof params.accessionNumber === 'string' ? params.accessionNumber : '';
|
||||||
|
return decodeURIComponent(value);
|
||||||
|
}, [params.accessionNumber]);
|
||||||
|
|
||||||
|
const [report, setReport] = useState<CompanyAiReportDetail | null>(null);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const loadReport = useCallback(async () => {
|
||||||
|
if (!accessionNumber) {
|
||||||
|
setError('Invalid accession number.');
|
||||||
|
setReport(null);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await getCompanyAiReport(accessionNumber);
|
||||||
|
setReport(response.report);
|
||||||
|
} catch (err) {
|
||||||
|
setReport(null);
|
||||||
|
setError(err instanceof Error ? err.message : 'Unable to load AI summary');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, [accessionNumber]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isPending && isAuthenticated) {
|
||||||
|
void loadReport();
|
||||||
|
}
|
||||||
|
}, [isPending, isAuthenticated, loadReport]);
|
||||||
|
|
||||||
|
if (isPending || !isAuthenticated) {
|
||||||
|
return <div className="flex min-h-screen items-center justify-center text-sm text-[color:var(--terminal-muted)]">Loading summary detail...</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolvedTicker = report?.ticker ?? tickerFromRoute;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AppShell
|
||||||
|
title="AI Summary"
|
||||||
|
subtitle={`Detailed filing analysis${resolvedTicker ? ` for ${resolvedTicker}` : ''}.`}
|
||||||
|
actions={(
|
||||||
|
<Button variant="secondary" onClick={() => void loadReport()} disabled={loading}>
|
||||||
|
<RefreshCcw className="size-4" />
|
||||||
|
Refresh
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Panel>
|
||||||
|
<div className="flex flex-wrap items-center gap-3">
|
||||||
|
<Link
|
||||||
|
href={`/analysis?ticker=${resolvedTicker}`}
|
||||||
|
className="inline-flex items-center gap-1 text-xs uppercase tracking-[0.12em] text-[color:var(--accent)] hover:text-[color:var(--accent-strong)]"
|
||||||
|
>
|
||||||
|
<ArrowLeft className="size-3" />
|
||||||
|
Back to analysis
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
href={`/filings?ticker=${resolvedTicker}`}
|
||||||
|
className="inline-flex items-center gap-1 text-xs uppercase tracking-[0.12em] text-[color:var(--accent)] hover:text-[color:var(--accent-strong)]"
|
||||||
|
>
|
||||||
|
<ArrowLeft className="size-3" />
|
||||||
|
Back to filings
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</Panel>
|
||||||
|
|
||||||
|
{loading ? (
|
||||||
|
<Panel>
|
||||||
|
<p className="text-sm text-[color:var(--terminal-muted)]">Loading AI summary...</p>
|
||||||
|
</Panel>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{!loading && error ? (
|
||||||
|
<Panel>
|
||||||
|
<p className="text-sm text-[#ffb5b5]">{error}</p>
|
||||||
|
</Panel>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{!loading && !error && report ? (
|
||||||
|
<>
|
||||||
|
<Panel
|
||||||
|
title={`${report.companyName} (${report.ticker})`}
|
||||||
|
subtitle={`${report.filingType} filed ${formatFilingDate(report.filingDate)} · ${report.provider} / ${report.model}`}
|
||||||
|
>
|
||||||
|
<div className="grid grid-cols-1 gap-3 text-sm md:grid-cols-2 xl:grid-cols-3">
|
||||||
|
<div className="rounded-md border border-[color:var(--line-weak)] bg-[color:var(--panel-soft)] px-3 py-2">
|
||||||
|
<p className="text-xs uppercase tracking-[0.12em] text-[color:var(--terminal-muted)]">Accession</p>
|
||||||
|
<p className="mt-1 break-all text-[color:var(--terminal-bright)]">{report.accessionNumber}</p>
|
||||||
|
</div>
|
||||||
|
<div className="rounded-md border border-[color:var(--line-weak)] bg-[color:var(--panel-soft)] px-3 py-2">
|
||||||
|
<p className="text-xs uppercase tracking-[0.12em] text-[color:var(--terminal-muted)]">Provider</p>
|
||||||
|
<p className="mt-1 text-[color:var(--terminal-bright)]">{report.provider}</p>
|
||||||
|
</div>
|
||||||
|
<div className="rounded-md border border-[color:var(--line-weak)] bg-[color:var(--panel-soft)] px-3 py-2">
|
||||||
|
<p className="text-xs uppercase tracking-[0.12em] text-[color:var(--terminal-muted)]">Model</p>
|
||||||
|
<p className="mt-1 text-[color:var(--terminal-bright)]">{report.model}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Panel>
|
||||||
|
|
||||||
|
<Panel title="Summary" subtitle="Full AI-generated filing analysis.">
|
||||||
|
<div className="mb-3 inline-flex items-center gap-2 rounded-md border border-[color:var(--line-weak)] bg-[color:var(--panel-soft)] px-2 py-1 text-xs text-[color:var(--terminal-muted)]">
|
||||||
|
<BrainCircuit className="size-3.5" />
|
||||||
|
Full text view
|
||||||
|
</div>
|
||||||
|
<p className="whitespace-pre-wrap text-sm leading-7 text-[color:var(--terminal-bright)]">
|
||||||
|
{report.summary}
|
||||||
|
</p>
|
||||||
|
</Panel>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</AppShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import Link from 'next/link';
|
||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { Suspense } from 'react';
|
import { Suspense } from 'react';
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
@@ -300,6 +301,14 @@ function FilingsPageContent() {
|
|||||||
<Bot className="size-3" />
|
<Bot className="size-3" />
|
||||||
Analyze
|
Analyze
|
||||||
</Button>
|
</Button>
|
||||||
|
{hasAnalysis ? (
|
||||||
|
<Link
|
||||||
|
href={`/analysis/reports/${filing.ticker}/${encodeURIComponent(filing.accession_number)}`}
|
||||||
|
className="inline-flex items-center rounded-md border border-[color:var(--line-weak)] px-2 py-1 text-xs text-[color:var(--accent)] transition hover:border-[color:var(--line-strong)] hover:text-[color:var(--accent-strong)]"
|
||||||
|
>
|
||||||
|
Open summary
|
||||||
|
</Link>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
);
|
);
|
||||||
@@ -350,6 +359,7 @@ function FilingsPageContent() {
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={() => void triggerAnalysis(filing.accession_number)}
|
onClick={() => void triggerAnalysis(filing.accession_number)}
|
||||||
@@ -358,6 +368,15 @@ function FilingsPageContent() {
|
|||||||
<Bot className="size-3" />
|
<Bot className="size-3" />
|
||||||
Analyze
|
Analyze
|
||||||
</Button>
|
</Button>
|
||||||
|
{hasAnalysis ? (
|
||||||
|
<Link
|
||||||
|
href={`/analysis/reports/${filing.ticker}/${encodeURIComponent(filing.accession_number)}`}
|
||||||
|
className="inline-flex items-center rounded-md border border-[color:var(--line-weak)] px-2 py-1 text-xs text-[color:var(--accent)] transition hover:border-[color:var(--line-strong)] hover:text-[color:var(--accent-strong)]"
|
||||||
|
>
|
||||||
|
Summary
|
||||||
|
</Link>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { edenTreaty } from '@elysiajs/eden';
|
import { edenTreaty } from '@elysiajs/eden';
|
||||||
import type { App } from '@/lib/server/api/app';
|
import type { App } from '@/lib/server/api/app';
|
||||||
import type {
|
import type {
|
||||||
|
CompanyAiReportDetail,
|
||||||
CompanyAnalysis,
|
CompanyAnalysis,
|
||||||
Filing,
|
Filing,
|
||||||
Holding,
|
Holding,
|
||||||
@@ -184,6 +185,13 @@ export async function getCompanyAnalysis(ticker: string) {
|
|||||||
return await unwrapData<{ analysis: CompanyAnalysis }>(result, 'Unable to fetch company analysis');
|
return await unwrapData<{ analysis: CompanyAnalysis }>(result, 'Unable to fetch company analysis');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getCompanyAiReport(accessionNumber: string) {
|
||||||
|
const normalizedAccession = accessionNumber.trim();
|
||||||
|
|
||||||
|
const result = await client.api.analysis.reports[normalizedAccession].get();
|
||||||
|
return await unwrapData<{ report: CompanyAiReportDetail }>(result, 'Unable to fetch AI summary');
|
||||||
|
}
|
||||||
|
|
||||||
export async function queueFilingSync(input: { ticker: string; limit?: number }) {
|
export async function queueFilingSync(input: { ticker: string; limit?: number }) {
|
||||||
const result = await client.api.filings.sync.post(input);
|
const result = await client.api.filings.sync.post(input);
|
||||||
return await unwrapData<{ task: Task }>(result, 'Unable to queue filing sync');
|
return await unwrapData<{ task: Task }>(result, 'Unable to queue filing sync');
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { auth } from '@/lib/auth';
|
|||||||
import { requireAuthenticatedSession } from '@/lib/server/auth-session';
|
import { requireAuthenticatedSession } from '@/lib/server/auth-session';
|
||||||
import { asErrorMessage, jsonError } from '@/lib/server/http';
|
import { asErrorMessage, jsonError } from '@/lib/server/http';
|
||||||
import { buildPortfolioSummary } from '@/lib/server/portfolio';
|
import { buildPortfolioSummary } from '@/lib/server/portfolio';
|
||||||
import { listFilingsRecords } from '@/lib/server/repos/filings';
|
import { getFilingByAccession, listFilingsRecords } from '@/lib/server/repos/filings';
|
||||||
import {
|
import {
|
||||||
deleteHoldingByIdRecord,
|
deleteHoldingByIdRecord,
|
||||||
listUserHoldings,
|
listUserHoldings,
|
||||||
@@ -386,6 +386,47 @@ export const app = new Elysia({ prefix: '/api' })
|
|||||||
ticker: t.String({ minLength: 1 })
|
ticker: t.String({ minLength: 1 })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.get('/analysis/reports/:accessionNumber', async ({ params }) => {
|
||||||
|
const { response } = await requireAuthenticatedSession();
|
||||||
|
if (response) {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
const accessionNumber = params.accessionNumber?.trim() ?? '';
|
||||||
|
if (accessionNumber.length < 4) {
|
||||||
|
return jsonError('Invalid accession number');
|
||||||
|
}
|
||||||
|
|
||||||
|
const filing = await getFilingByAccession(accessionNumber);
|
||||||
|
if (!filing) {
|
||||||
|
return jsonError('AI summary not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
const summary = filing.analysis?.text ?? filing.analysis?.legacyInsights ?? '';
|
||||||
|
if (!summary) {
|
||||||
|
return jsonError('AI summary not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
report: {
|
||||||
|
accessionNumber: filing.accession_number,
|
||||||
|
ticker: filing.ticker,
|
||||||
|
companyName: filing.company_name,
|
||||||
|
filingDate: filing.filing_date,
|
||||||
|
filingType: filing.filing_type,
|
||||||
|
provider: filing.analysis?.provider ?? 'unknown',
|
||||||
|
model: filing.analysis?.model ?? 'unknown',
|
||||||
|
summary,
|
||||||
|
filingUrl: filing.filing_url,
|
||||||
|
submissionUrl: filing.submission_url ?? null,
|
||||||
|
primaryDocument: filing.primary_document ?? null
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, {
|
||||||
|
params: t.Object({
|
||||||
|
accessionNumber: t.String({ minLength: 4 })
|
||||||
|
})
|
||||||
|
})
|
||||||
.get('/filings', async ({ query }) => {
|
.get('/filings', async ({ query }) => {
|
||||||
const { response } = await requireAuthenticatedSession();
|
const { response } = await requireAuthenticatedSession();
|
||||||
if (response) {
|
if (response) {
|
||||||
|
|||||||
@@ -113,6 +113,14 @@ export type CompanyAiReport = {
|
|||||||
summary: string;
|
summary: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type CompanyAiReportDetail = CompanyAiReport & {
|
||||||
|
ticker: string;
|
||||||
|
companyName: string;
|
||||||
|
filingUrl: string | null;
|
||||||
|
submissionUrl: string | null;
|
||||||
|
primaryDocument: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
export type CompanyAnalysis = {
|
export type CompanyAnalysis = {
|
||||||
company: {
|
company: {
|
||||||
ticker: string;
|
ticker: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user