Make the governed RAG evidence path executable end to end
Some checks failed
verify / verify (push) Has been cancelled

Separate local parsing from model indexing, bind review decisions to immutable manifests, persist vectors behind active profiles, and expose retrieval, chat, evaluation, and document workflows through the React workbench.

Constraint: Live Bailian authentication currently fails for all three configured capabilities

Rejected: Direct upload-to-embedding flow | bypasses local review and manifest binding

Confidence: high

Scope-risk: broad

Directive: Keep private-data deployment blocked until authentication, RBAC, and separate database roles land

Tested: make verify; fresh and replay Docker document smoke; worker recovery smoke; frozen synthetic evaluation; migration 0003-0004 roundtrip

Not-tested: Successful live Bailian calls, OCR, real multi-user authorization
This commit is contained in:
2026-07-13 05:58:11 +08:00
parent 75592af33a
commit ecdb10c37a
111 changed files with 25457 additions and 152 deletions

View File

@@ -0,0 +1,300 @@
import { useState } from "react";
import { getApiErrorMessage } from "../../../api/client";
import { Icon } from "../../../components/Icon";
import type { RejectionReason, ReviewBundle } from "../types";
interface DocumentReviewPanelProps {
bundle: ReviewBundle | undefined;
error: unknown;
isLoading: boolean;
isDecisionPending: boolean;
decisionError: unknown;
onApprove: () => void;
onReject: (reason: RejectionReason) => void;
onRetry: () => void;
}
const REJECTION_REASONS: { value: RejectionReason; label: string }[] = [
{ value: "RIGHTS_NOT_VERIFIED", label: "资料权利或授权未核实" },
{ value: "CONTENT_QUALITY_REJECTED", label: "内容质量不满足入库要求" },
{ value: "CLOUD_PROCESSING_REJECTED", label: "不允许提交云端处理" },
];
function reviewStateLabel(state: string): string {
const labels: Record<string, string> = {
LOCAL_PARSED_PENDING_CLOUD_REVIEW: "等待人工复核",
CLOUD_APPROVED: "已批准出域",
REJECTED: "已拒绝出域",
OCR_REQUIRED: "需要可靠 OCR",
};
return labels[state] ?? state;
}
export function DocumentReviewPanel({
bundle,
error,
isLoading,
isDecisionPending,
decisionError,
onApprove,
onReject,
onRetry,
}: DocumentReviewPanelProps) {
const [confirmed, setConfirmed] = useState(false);
const [rejectionReason, setRejectionReason] = useState<RejectionReason>("RIGHTS_NOT_VERIFIED");
if (isLoading) {
return (
<section className="document-panel document-review-panel" aria-live="polite">
<div className="document-review-state">
<span className="button-spinner button-spinner--forest" aria-hidden="true" />
<h2></h2>
<p> revision </p>
</div>
</section>
);
}
if (error !== null) {
return (
<section className="document-panel document-review-panel">
<div className="document-review-state document-review-state--error" role="alert">
<Icon name="alert" size={24} />
<h2></h2>
<p>{getApiErrorMessage(error)}</p>
<button className="secondary-button" onClick={onRetry} type="button">
</button>
</div>
</section>
);
}
if (bundle === undefined) {
return (
<section className="document-panel document-review-panel">
<div className="document-review-state">
<Icon name="document" size={28} />
<h2></h2>
<p></p>
</div>
</section>
);
}
const version = bundle.version;
if (version === null) {
return (
<section className="document-panel document-review-panel">
<div className="document-review-state">
<Icon name="layers" size={28} />
<h2>{bundle.document.filename}</h2>
<p> Worker </p>
</div>
</section>
);
}
const expectedChunksMatch = version.expected_chunk_count === bundle.chunks.length;
const reviewable =
version.review_state === "LOCAL_PARSED_PENDING_CLOUD_REVIEW" &&
version.status === "PROCESSING" &&
version.outbound_manifest_sha256 !== null &&
bundle.chunks.length > 0 &&
expectedChunksMatch;
return (
<section
className="document-panel document-review-panel"
aria-labelledby="document-review-title"
>
<div className="document-review-header">
<div>
<span className="eyebrow">MANIFEST-BOUND REVIEW</span>
<h2 id="document-review-title">{bundle.document.filename}</h2>
<span className="document-review-state-badge">
{reviewStateLabel(version.review_state)}
</span>
</div>
<dl>
<div>
<dt>Revision</dt>
<dd>{version.review_revision}</dd>
</div>
<div>
<dt></dt>
<dd>{version.status}</dd>
</div>
<div>
<dt> / / Chunk</dt>
<dd>
{bundle.pages.length} / {bundle.blocks.length} / {bundle.chunks.length}
</dd>
</div>
</dl>
</div>
<div className="document-manifest">
<div>
<span> SHA-256</span>
<code>{version.outbound_manifest_sha256 ?? "尚未生成"}</code>
</div>
<div>
<span>Parser / Chunk Profile</span>
<code>{version.parser_profile_hash}</code>
<code>{version.chunk_profile_hash}</code>
</div>
<div>
<span>Cloud Policy</span>
<code>{version.cloud_policy_id}</code>
</div>
</div>
{!expectedChunksMatch && (
<div className="document-review-warning" role="alert">
<Icon name="alert" size={18} />
<span>
{version.expected_chunk_count} Chunk {bundle.chunks.length}
</span>
</div>
)}
<div className="document-review-content">
<section aria-labelledby="review-pages-title">
<div className="document-subheading">
<h3 id="review-pages-title"></h3>
<span>{bundle.pages.length}</span>
</div>
{bundle.pages.length === 0 ? (
<p className="document-empty-copy">PDF OCR</p>
) : (
<div className="document-evidence-list">
{bundle.pages.map((page) => (
<details key={page.id}>
<summary>
{page.page_number ?? page.ordinal + 1} · {page.line_start}-
{page.line_end}
</summary>
<p>{page.text}</p>
<code>{page.text_sha256}</code>
</details>
))}
</div>
)}
<div className="document-subheading document-subheading--blocks">
<h3></h3>
<span>{bundle.blocks.length}</span>
</div>
{bundle.blocks.length === 0 ? (
<p className="document-empty-copy"></p>
) : (
<div className="document-evidence-list">
{bundle.blocks.map((block) => (
<details key={block.id}>
<summary>
{block.kind} · {block.section_path.join(" / ") || "未标注章节"} ·
{block.line_start}-{block.line_end}
</summary>
<p>{block.text}</p>
<code>{block.anchor_id}</code>
</details>
))}
</div>
)}
</section>
<section aria-labelledby="review-chunks-title">
<div className="document-subheading">
<h3 id="review-chunks-title"> Chunk</h3>
<span>{bundle.chunks.length}</span>
</div>
{bundle.chunks.length === 0 ? (
<p className="document-empty-copy"> Chunk</p>
) : (
<div className="document-chunk-list">
{bundle.chunks.map((chunk) => (
<article key={`${chunk.ordinal}:${chunk.cloud_text_sha256}`}>
<header>
<strong>Chunk {chunk.ordinal + 1}</strong>
<span>{chunk.token_count} tokens</span>
</header>
<p>{chunk.cloud_text}</p>
<footer>
<span>
{chunk.section_path.length === 0
? "未标注章节"
: chunk.section_path.join(" / ")}
</span>
<code>{chunk.cloud_text_sha256.slice(0, 18)}</code>
</footer>
</article>
))}
</div>
)}
</section>
</div>
<div className="document-human-gate">
<div className="document-human-gate__notice">
<Icon name="shield" size={20} />
<div>
<strong></strong>
<span>
revision
manifest
</span>
</div>
</div>
<label className="document-confirmation">
<input
checked={confirmed}
disabled={!reviewable || isDecisionPending}
onChange={(event) => setConfirmed(event.target.checked)}
type="checkbox"
/>
</label>
<div className="document-decision-actions">
<button
className="primary-button"
disabled={!reviewable || !confirmed || isDecisionPending}
onClick={onApprove}
type="button"
>
{isDecisionPending && <span className="button-spinner" aria-hidden="true" />}
</button>
<div className="document-reject-control">
<label htmlFor="rejection-reason"></label>
<select
disabled={!reviewable || isDecisionPending}
id="rejection-reason"
onChange={(event) => setRejectionReason(event.target.value as RejectionReason)}
value={rejectionReason}
>
{REJECTION_REASONS.map((reason) => (
<option key={reason.value} value={reason.value}>
{reason.label}
</option>
))}
</select>
<button
className="tertiary-button document-reject-button"
disabled={!reviewable || isDecisionPending}
onClick={() => onReject(rejectionReason)}
type="button"
>
</button>
</div>
</div>
{decisionError !== null && (
<p className="field-error document-decision-error" role="alert">
{getApiErrorMessage(decisionError)}
</p>
)}
</div>
</section>
);
}