import React from "react"; import { MacroStrategyReport } from "../contracts/report_schema.js"; import { ShieldCheck, ShieldAlert, CheckCircle2, XCircle, Download } from "lucide-react"; import { useLanguage } from "../context/LanguageContext.js"; interface AuditVerificationPanelProps { report?: MacroStrategyReport | null; } export const AuditVerificationPanel: React.FC = ({ report }) => { const { language, t } = useLanguage(); const isAr = language === "ar"; const handleExportJson = () => { if (!report) return; const blob = new Blob([JSON.stringify(report, null, 2)], { type: "application/json" }); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = `GEO_STRAT_REPORT_${report.country_iso3}_${Date.now()}.json`; a.click(); URL.revokeObjectURL(url); }; const audit = report?.audit_verification; const checks = audit ? [ { ok: audit.zero_ungrounded_numbers, title: t.audit.zeroUngrounded, detail: audit.zero_ungrounded_numbers ? isAr ? "كل الأرقام غير البديهية تظهر في المصادر أو البيانات أو نتائج المحاكاة." : "Every non-trivial number appears in the sources, data inputs or simulation output." : `${isAr ? "أرقام غير موجودة في السياق" : "Not found in the context"}: ${audit.ungrounded_numbers?.join(", ") || ""}`, }, { ok: audit.citation_integrity_verified, title: t.audit.citationIntegrity, detail: audit.citation_integrity_verified ? isAr ? "كل معرف مستشهد به موجود في المصادر المسترجعة." : "Every cited id is in the retrieved source set." : `${isAr ? "معرفات غير معروفة" : "Unknown ids"}: ${audit.unknown_citations?.join(", ") || ""}`, }, { ok: audit.sandbox_id_matched, title: t.audit.sandboxVerification, detail: report?.sandbox_execution_id || (isAr ? "لم تُجرَ محاكاة" : "No simulation run"), }, { ok: Boolean(audit.probability_sum_valid ?? true), title: t.audit.probabilitySum, detail: report?.scenarios.map((s) => `${s.scenario_type}: ${s.probability_pct ?? "n/a"}`).join(" · ") || "", }, ] : []; return (

{t.audit.title}

{t.audit.subtitle}

{report && audit ? (
{audit.passed ? : }

{audit.passed ? isAr ? "اجتاز التدقيق" : "Audit passed" : isAr ? "رصد التدقيق محتوى غير موثق في التقرير" : "Audit flagged unsourced content in this report"}

{isAr ? "تم التحقق من مطابقة جميع مؤشرات المخرجات المباشرة مع السياق الموثق." : "All report parameters verified against grounding context."}

{checks.map((c) => (
{c.ok ? : } {c.title}

{c.detail}

))}
{isAr ? "سجل التدقيق" : "Audit log"}
    {(audit.log || []).map((line: string, i: number) => (
  • {line}
  • ))}

{isAr ? "يتحقق التدقيق من أن الأرقام والمراجع مستمدة من السياق المقدَّم للنموذج، ولا يتحقق من صحة الاستنتاجات النوعية. الأعداد الصغيرة (حتى 10) والسنوات مستثناة." : "The audit checks that numbers and citations come from the context given to the model; it does not verify qualitative conclusions. Small counts (up to 10) and calendar years are exempt."}

) : (
{isAr ? "لا يوجد تقرير نشط حالياً. نفّذ توقعاً في تبويب 'منصة التوقعات' لعرض نتائج التدقيق." : "No active report. Run a forecast in the Forecast Workbench tab to see its audit results."}
)}
); };