Prioritize SEC financials for 10-K/10-Q and keep other filings qualitative
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Elysia, t } from 'elysia';
|
||||
import type { TaskStatus } from '@/lib/types';
|
||||
import type { Filing, TaskStatus } from '@/lib/types';
|
||||
import { auth } from '@/lib/auth';
|
||||
import { requireAuthenticatedSession } from '@/lib/server/auth-session';
|
||||
import { asErrorMessage, jsonError } from '@/lib/server/http';
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
} from '@/lib/server/tasks';
|
||||
|
||||
const ALLOWED_STATUSES: TaskStatus[] = ['queued', 'running', 'completed', 'failed'];
|
||||
const FINANCIAL_FORMS: ReadonlySet<Filing['filing_type']> = new Set(['10-K', '10-Q']);
|
||||
|
||||
function asRecord(value: unknown): Record<string, unknown> {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
||||
@@ -41,6 +42,17 @@ function asPositiveNumber(value: unknown) {
|
||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
|
||||
}
|
||||
|
||||
function withFinancialMetricsPolicy(filing: Filing): Filing {
|
||||
if (FINANCIAL_FORMS.has(filing.filing_type)) {
|
||||
return filing;
|
||||
}
|
||||
|
||||
return {
|
||||
...filing,
|
||||
metrics: null
|
||||
};
|
||||
}
|
||||
|
||||
const authHandler = ({ request }: { request: Request }) => auth.handler(request);
|
||||
|
||||
export const app = new Elysia({ prefix: '/api' })
|
||||
@@ -333,7 +345,9 @@ export const app = new Elysia({ prefix: '/api' })
|
||||
getQuote(ticker),
|
||||
getPriceHistory(ticker)
|
||||
]);
|
||||
const redactedFilings = filings.map(redactInternalFilingAnalysisFields);
|
||||
const redactedFilings = filings
|
||||
.map(redactInternalFilingAnalysisFields)
|
||||
.map(withFinancialMetricsPolicy);
|
||||
|
||||
const latestFiling = redactedFilings[0] ?? null;
|
||||
const holding = holdings.find((entry) => entry.ticker === ticker) ?? null;
|
||||
@@ -344,7 +358,7 @@ export const app = new Elysia({ prefix: '/api' })
|
||||
?? ticker;
|
||||
|
||||
const financials = redactedFilings
|
||||
.filter((entry) => entry.metrics)
|
||||
.filter((entry) => entry.metrics && FINANCIAL_FORMS.has(entry.filing_type))
|
||||
.map((entry) => ({
|
||||
filingDate: entry.filing_date,
|
||||
filingType: entry.filing_type,
|
||||
@@ -448,7 +462,7 @@ export const app = new Elysia({ prefix: '/api' })
|
||||
limit: Number.isFinite(limit) ? limit : 50
|
||||
});
|
||||
|
||||
return Response.json({ filings: filings.map(redactInternalFilingAnalysisFields) });
|
||||
return Response.json({ filings: filings.map(redactInternalFilingAnalysisFields).map(withFinancialMetricsPolicy) });
|
||||
}, {
|
||||
query: t.Object({
|
||||
ticker: t.Optional(t.String()),
|
||||
|
||||
@@ -25,6 +25,10 @@ function filingWithExtraction(): Filing {
|
||||
redFlags: ['b'],
|
||||
followUpQuestions: ['c'],
|
||||
portfolioSignals: ['d'],
|
||||
segmentSpecificData: ['e'],
|
||||
geographicRevenueBreakdown: ['f'],
|
||||
companySpecificData: ['g'],
|
||||
secApiCrossChecks: ['h'],
|
||||
confidence: 0.4
|
||||
},
|
||||
extractionMeta: {
|
||||
|
||||
Reference in New Issue
Block a user