From 7acf1b9dd52340f219dd99e0ccd3d3189751e76f Mon Sep 17 00:00:00 2001 From: faligam Date: Sun, 6 Sep 2026 17:52:05 +0200 Subject: [PATCH] Load research detail resources from API --- src/lib/research-api.ts | 74 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/src/lib/research-api.ts b/src/lib/research-api.ts index 8b5a5fc..97b8f1a 100644 --- a/src/lib/research-api.ts +++ b/src/lib/research-api.ts @@ -12,6 +12,44 @@ interface ApiResearchStatus { claim_count?: number; } +interface ApiSourcesResponse { + sources: Array<{ + id: string; + url: string; + title?: string | null; + domain?: string; + source_type?: string | null; + }>; +} + +interface ApiClaimsResponse { + claims: Array<{ + id: string; + claim_text: string; + claim_type: string; + confidence: number; + source_id?: string; + evidence_span?: string; + }>; +} + +interface ApiEvidenceResponse { + evidence: Array<{ + source_independence_score: number; + primary_source_proximity: number; + cross_source_support: number; + contradiction_level: number; + evidence_directness: number; + date_relevance_score: number; + }>; +} + +interface ApiReportResponse { + summary: string; + findings: Array<{ text: string }>; + methodology: string; +} + function normalizeStatus(status: ApiResearchStatus): ResearchStatus { return { id: status.research_id, @@ -65,8 +103,40 @@ export async function getResearchDetail( apiKey: string, researchId: string ): Promise { - const response = await apiGet(`/v1/research/${researchId}`, { apiKey }); - return normalizeDetail(response); + const [status, sources, claims, evidence, report] = await Promise.all([ + apiGet(`/v1/research/${researchId}`, { apiKey }), + apiGet(`/v1/research/${researchId}/sources`, { apiKey }), + apiGet(`/v1/research/${researchId}/claims`, { apiKey }), + apiGet(`/v1/research/${researchId}/evidence`, { apiKey }), + apiGet(`/v1/research/${researchId}/report`, { apiKey }), + ]); + return { + ...normalizeDetail(status), + sources: sources.sources.map(source => ({ + ...source, + title: source.title ?? source.url, + })), + claims: claims.claims.map(claim => ({ + id: claim.id, + claim: claim.claim_text, + claim_type: claim.claim_type, + confidence: claim.confidence, + source_id: claim.source_id, + evidence_span: claim.evidence_span, + })), + evidence: evidence.evidence.map(score => ({ + source_independence: score.source_independence_score, + primary_source_proximity: score.primary_source_proximity, + cross_source_support: score.cross_source_support, + contradiction_level: score.contradiction_level, + evidence_directness: score.evidence_directness, + date_relevance: score.date_relevance_score, + })), + report: [report.summary, ...report.findings.map(finding => finding.text)] + .filter(Boolean) + .join('\n\n'), + methodology: report.methodology, + }; } /**