import { apiDownload } from './session' import type { RetrievalRunResult } from '../api' import type { RagContext } from './rag' export type ExportSelection = { run_ids: string[]; include_contexts?: boolean } export type ExportManifest = { record_type: 'manifest'; schema_version: 'nalati-retrieval-export-v1'; export_id: string; exported_at: string; selection: Required; counts: { retrieval_runs: number; rag_contexts: number }; records_sha256: string; snapshot_semantics: 'stored_history_not_current_corpus'; generation_measurements: { status: 'not_called'; usage: null; cost: null; currency: null } } export type ExportRecord = ExportManifest | { record_type: 'retrieval_run'; id: string; ranking_unit: 'knowledge_item' | 'chunk'; payload: RetrievalRunResult } | { record_type: 'rag_context'; id: string; payload: RagContext } // Returns bytes/metadata; callers explicitly choose whether and where to save the file. export const exportRetrievalHistory = (payload: ExportSelection) => apiDownload( '/api/retrieval/exports', { method: 'POST', body: JSON.stringify(payload) }, true, )