Files
AgentLab/frontend/src/run/ApprovalReport.tsx
T
ThearchyHelios eb71513924 审批质询(前端)复核整改(第 1 轮):同一张卡挂两处、换了审批、报告改写前的问答各归其位,句末入口不再挤动正文
- 提问框记下打开它的那一处(host)和那张审批:画布的审批浮层和右栏同时挂着同一张卡时,提问框只画在点的那一处,焦点不跳到另一处;另一处写明「提问框已在另一处打开」,可「在这里继续」;浮层关了由右栏接过去,不抢焦点。换了审批(同一份报告的下一级审批、驳回改写后再审)旧的提问框不再显示,提交一律带页面此刻的审批 id,不会再拿旧 id 一直 409
- 问答串按每条问的是哪一稿报告分开:别的审批里问的,按审批列表里那张审批审的文档对一下,对上了才按句子编号挂;改写前的、对不上的单独一组「报告其他版本上的质询」,不拿当前报告同编号的句子当抬头,回答里引用报告出处的数也不去当前这一稿里找。运行详情同理(封存之后问的认封存的那一稿)
- 句末的「质询」改成固定宽度的淡色图标,悬停、聚焦只换颜色和描边,不再从宽 0 撑开:后文不右移、表格列不跳;表格格子不挂(问表里的数划选或就整份报告提问)
- Esc、「取消」之后焦点回到那一句的「质询」并滚回视野(页面和限高的报告框都滚)
- 回答期间另开的提问框不再被失败的那一条覆盖:失败的问题和原因挂在原来那一句下面,提问框关着时可以放回提问框重问
- 写进运行记录后:画布正显示这次运行、流已收尾时按已有的最大序号补接一次;运行详情补拉一次事件(pages/runs/useRunDetail.ts 订阅一个计数)。时间线因此出现「审批人质询」
- 运行详情对所有运行只读列出已有问答(正式运行审批时问过的随运行封存,审批处理后也看得到查过的 SQL、行数、快照),入口仍只给封存了的探索运行;设置里关了审批质询就不给入口,已有问答照列并写明已关闭
- 小项:读屏连续两次回答都播报;「已等待 N 秒」挪出播报区;花费照 runCostText 写(估不出不写 $0);查询列表收着时也写有几次被截断;报告没有逐段证据时提示只说可以就整份报告提问;列表取回来之前不出「还没有问答」的提示;回答里核对不了的名称、猜测的来源照报告的线型画;回答期间批准 / 驳回下面那句原因在浅色主题下对比度够了
- RunPanel 改传这张卡的审批 id 和是否待处理(处理过的卡也认得哪几条问的是卡上这一稿);check-all 里 check-inquiry 的预计时长按实测改成 60 秒
- check-inquiry 补上各项:悬停前后正文和表格不移位、焦点回去后在视野里、同一张卡挂两处、先后两张审批、改写前的问答单独一组、失败不覆盖新写的、连续播报、花费、截断、无文档、设置关闭、遮罩原值不外露(含导出的 CSV)、补接事件流;新增预览用例 inquiry-approval-twice / -steps / -steps-same / -nodoc
2026-10-06 09:57:34 +08:00

172 lines
8.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useCallback, useEffect, useId, useRef, useState, type Ref } from 'react'
import { ChevronRight, ShieldCheck } from 'lucide-react'
import { EVIDENCE_STATE, claimCountsOf, claimProblems, statsTally } from '../lib/evidence'
import { formatNumber } from '../lib/format'
import { APPROVAL_TEXT, EVIDENCE_TEXT, JUDGE_TEXT, evidenceTally, runClassLabel } from '../lib/terms'
import { useEvidence } from '../store/evidence'
import type { ApprovalReport, EvidenceSegment } from '../types'
import { EvidenceDoc, type EvidenceDocHandle } from './EvidenceDoc'
import { ReportInquiry, reportSegmentFor, useInquiryAccess, type InquiryAccess } from './Inquiry'
type RunClass = 'formal' | 'exploratory' | null | undefined
/**
* 人工审批这次是探索运行还是正式运行,批了会怎样。
*
* 真实运行里审批说明写着「批准后才会正式出具」,那却是一次探索运行:出具只发生在成果节点配了出具契约、从已发布
* 版本发起的正式运行里。审批卡自己标明运行类别,不靠模型写的说明
*/
export function ApprovalRunClass({ runClass, approve }: { runClass: RunClass; approve: boolean }) {
const formal = runClass === 'formal'
return (
<div className="mb-2 flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-2xs leading-relaxed"
data-approval-run-class={formal ? 'formal' : 'exploratory'}>
<span className="chip shrink-0" style={formal ? { color: 'var(--accent)' } : undefined}>{runClassLabel(runClass)}</span>
<span className="text-dim">{APPROVAL_TEXT.outcome(runClass, approve)}</span>
</div>
)
}
/** 结论句那一句:节点里判过的说判了几句、几句相矛盾;没判过的说尚未核对,并说什么时候能核对 */
function claimsLine(report: ApprovalReport, runClass: RunClass): { text: string; sub?: string; warn: boolean } {
const judge = report.judge
if (judge?.mode === 'inline' && judge.counts && typeof judge.counts === 'object') {
const c = claimCountsOf(judge.counts)
if (!c.total) return { text: APPROVAL_TEXT.claimsNone, warn: false }
const contradicted = c.contradicted + c.unsupported
return {
text: APPROVAL_TEXT.claimsJudged(c.total - c.unjudged, contradicted, c.unjudged),
warn: claimProblems(c) > 0 || c.unjudged > 0,
}
}
return {
text: APPROVAL_TEXT.claimsPending,
sub: runClass === 'formal' ? (report.claims === 'judge' ? undefined : APPROVAL_TEXT.claimsOff)
// 开了裁判却没在节点里判的,只会是这条规则之前的探索运行(现在交给审批的报告探索运行也当场判)
: report.claims === 'judge' ? APPROVAL_TEXT.claimsAfterRun : APPROVAL_TEXT.claimsLater,
warn: true,
}
}
/**
* 审批审的报告的核对概况:几个数字有出处(同证据条的说法),结论句判没判过、几句证据相矛盾,再给一个查看逐段证据
* 的入口——点开是和成果里同一份可逐段点开的报告文档,点数字、句末徽标打开证据面板。
*
* 真实运行里报告有一句结论和证据相矛盾,审批人批准时完全不知道:卡上只有正文
*/
export function ApprovalReports({ reports, runId, runClass, approvalId, askable = false }: {
reports: ApprovalReport[]
runId: string
runClass: RunClass
/** 这张审批卡的审批(处理过的也给):问答串据此认哪几条问的就是卡上这一稿报告 */
approvalId?: string
/**
* 审批待处理:审批人可以就报告提出质询——报告上的句子、划选的原文挂「质询」,核对概况下面是问答串和提问框
* (run/Inquiry.tsx)。设置里关了审批质询时照样不给
*/
askable?: boolean
}) {
const { access, disabled } = useInquiryAccess(askable && !!approvalId, approvalId ?? null)
if (!reports.length) return null
return (
<>
{reports.map((r) => (
<ReportCheck key={r.node_id} report={r} runId={runId} runClass={runClass} access={access} disabled={disabled}
approvalId={approvalId ?? null} />
))}
</>
)
}
function ReportCheck({ report, runId, runClass, access, disabled, approvalId }: {
report: ApprovalReport; runId: string; runClass: RunClass; access: InquiryAccess | null; disabled: boolean
approvalId: string | null
}) {
const [open, setOpen] = useState(false)
// 回答里引用了报告已有的出处:在逐段证据里打开那一处的证据面板。逐段证据收着的先展开,挂上之后再打开
const docRef = useRef<EvidenceDocHandle>(null)
const opening = useRef<string | null>(null)
const docSlot = useEvidence((s) => (report.doc_artifact ? s.docs[report.doc_artifact] : undefined))
const locate = useCallback((seg: EvidenceSegment) => {
const id = reportSegmentFor(docSlot?.status === 'ok' ? docSlot.data : null, seg)
if (!id) return false
if (open && docRef.current) return docRef.current.open(id, { focus: true })
opening.current = id
setOpen(true)
return true
}, [docSlot, open])
useEffect(() => {
if (!open || !opening.current || !docRef.current) return
docRef.current.open(opening.current, { focus: true })
opening.current = null
})
const docId = useId()
const counts = statsTally(report.stats)
const suspect = typeof report.stats?.unknown_entities === 'number' ? report.stats.unknown_entities : 0
const numbers = counts ? evidenceTally(counts.cited, counts.total, counts.other) : ''
const claims = claimsLine(report, runClass)
const gaps = !!counts && (counts.none > 0 || counts.other > 0)
return (
<div className="mb-2 rounded border bg-bg p-2" data-approval-report={report.node_id}>
<div className="mb-1 flex items-center gap-1 text-2xs font-medium text-faint">
<ShieldCheck size={11} aria-hidden /> {APPROVAL_TEXT.reportHead(report.label || report.node_id)}
</div>
<div className="flex flex-wrap items-center gap-x-2 gap-y-1 text-2xs">
<span className="tnum" data-approval-report-numbers=""
style={{ color: !counts ? 'var(--text-dim)' : gaps ? 'var(--st-waiting)' : 'var(--st-done)' }}>
{numbers || APPROVAL_TEXT.noNumbers}
</span>
{suspect > 0 && (
<span className="tnum" style={{ color: 'var(--st-waiting)' }}>
· {EVIDENCE_STATE.suspect.glyph} {EVIDENCE_TEXT.suspectTag} {formatNumber(suspect)}
</span>
)}
{/* 判定是模型给的:全都有依据也不用确定性的绿,有问题、没核对的用提醒色 */}
<span className="tnum" data-approval-report-claims="" title={report.judge?.mode === 'inline' ? JUDGE_TEXT.badge(null) : undefined}
style={{ color: claims.warn ? 'var(--st-waiting)' : 'var(--text-dim)' }}>
· {claims.text}
</span>
</div>
{claims.sub && <div className="mt-0.5 text-2xs leading-relaxed text-dim">{claims.sub}</div>}
{report.doc_artifact && (
<>
<button type="button" className="btn btn-xs mt-1.5" data-approval-evidence="" aria-expanded={open}
aria-controls={docId} onClick={() => setOpen((v) => !v)}>
<ChevronRight size={11} aria-hidden style={{ transform: open ? 'rotate(90deg)' : 'none', transition: 'transform .15s' }} />
{open ? APPROVAL_TEXT.closeEvidence : APPROVAL_TEXT.openEvidence}
</button>
{open && (
<div id={docId} className="mt-1.5">
<ReportDoc artifact={report.doc_artifact} runId={runId} runClass={runClass} inquiry={access} handle={docRef} />
</div>
)}
</>
)}
{/* 审批质询:问答串(进入审批卡时按列表接口恢复)、提问框和「就整份报告提问」 */}
<ReportInquiry runId={runId} report={report.node_id} docArtifact={report.doc_artifact} access={access} disabled={disabled}
cardId={approvalId} onLocate={locate} />
</div>
)
}
/** 报告文档:和成果里同一份可逐段点开的文档,自带证据条(定位下一处、违规清单),点开的证据面板在卡内展开 */
function ReportDoc({ artifact, runId, runClass, inquiry, handle }: {
artifact: string; runId: string; runClass: RunClass
/** 审批质询:句子、划选的原文上挂「质询」 */
inquiry: InquiryAccess | null
handle: Ref<EvidenceDocHandle>
}) {
const slot = useEvidence((s) => s.docs[artifact])
const loadDoc = useEvidence((s) => s.loadDoc)
useEffect(() => { void loadDoc(artifact) }, [artifact, loadDoc])
if (slot?.status === 'error') return <div className="text-2xs text-faint">{APPROVAL_TEXT.docMissing}</div>
const doc = slot?.status === 'ok' ? slot.data : undefined
if (!doc) return <div className="text-2xs text-faint">{APPROVAL_TEXT.docLoading}</div>
return (
<div className="max-h-96 overflow-y-auto rounded border p-2" data-approval-evidence-doc="">
<EvidenceDoc ref={handle} doc={doc} artifact={artifact} runId={runId} dense tally runClass={runClass ?? undefined}
inquiry={inquiry} />
</div>
)
}