Load research detail resources from API
This commit is contained in:
@@ -12,6 +12,44 @@ interface ApiResearchStatus {
|
|||||||
claim_count?: number;
|
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 {
|
function normalizeStatus(status: ApiResearchStatus): ResearchStatus {
|
||||||
return {
|
return {
|
||||||
id: status.research_id,
|
id: status.research_id,
|
||||||
@@ -65,8 +103,40 @@ export async function getResearchDetail(
|
|||||||
apiKey: string,
|
apiKey: string,
|
||||||
researchId: string
|
researchId: string
|
||||||
): Promise<ResearchDetail> {
|
): Promise<ResearchDetail> {
|
||||||
const response = await apiGet<ApiResearchStatus>(`/v1/research/${researchId}`, { apiKey });
|
const [status, sources, claims, evidence, report] = await Promise.all([
|
||||||
return normalizeDetail(response);
|
apiGet<ApiResearchStatus>(`/v1/research/${researchId}`, { apiKey }),
|
||||||
|
apiGet<ApiSourcesResponse>(`/v1/research/${researchId}/sources`, { apiKey }),
|
||||||
|
apiGet<ApiClaimsResponse>(`/v1/research/${researchId}/claims`, { apiKey }),
|
||||||
|
apiGet<ApiEvidenceResponse>(`/v1/research/${researchId}/evidence`, { apiKey }),
|
||||||
|
apiGet<ApiReportResponse>(`/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,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user