mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-16 19:52:00 +00:00
合入期 4 审批质询(前端):报告句末与划选原文浮出「质询」,问答串与提问框挂在审批卡和运行详情,回答按片段与出处渲染;同一张卡挂两处、换了审批、报告改写前的问答各归其位;时间线解读 approval.inquiry,等待中来质询阶段仍是等待
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { useEffect, useId, useState } from 'react'
|
||||
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 } from '../types'
|
||||
import { EvidenceDoc } from './EvidenceDoc'
|
||||
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
|
||||
|
||||
@@ -53,21 +54,52 @@ function claimsLine(report: ApprovalReport, runClass: RunClass): { text: string;
|
||||
*
|
||||
* 真实运行里报告有一句结论和证据相矛盾,审批人批准时完全不知道:卡上只有正文
|
||||
*/
|
||||
export function ApprovalReports({ reports, runId, runClass }: {
|
||||
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} />)}
|
||||
{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 }: { report: ApprovalReport; runId: string; runClass: RunClass }) {
|
||||
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
|
||||
@@ -105,17 +137,25 @@ function ReportCheck({ report, runId, runClass }: { report: ApprovalReport; runI
|
||||
</button>
|
||||
{open && (
|
||||
<div id={docId} className="mt-1.5">
|
||||
<ReportDoc artifact={report.doc_artifact} runId={runId} runClass={runClass} />
|
||||
<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 }: { artifact: string; runId: string; runClass: RunClass }) {
|
||||
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])
|
||||
@@ -124,7 +164,8 @@ function ReportDoc({ artifact, runId, runClass }: { artifact: string; runId: str
|
||||
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 doc={doc} artifact={artifact} runId={runId} dense tally runClass={runClass ?? undefined} />
|
||||
<EvidenceDoc ref={handle} doc={doc} artifact={artifact} runId={runId} dense tally runClass={runClass ?? undefined}
|
||||
inquiry={inquiry} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import {
|
||||
Fragment, forwardRef, memo, useCallback, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo,
|
||||
useRef, useState, type CSSProperties, type FocusEvent as ReactFocusEvent,
|
||||
type KeyboardEvent as ReactKeyboardEvent, type MouseEvent as ReactMouseEvent,
|
||||
type KeyboardEvent as ReactKeyboardEvent, type MouseEvent as ReactMouseEvent, type RefObject,
|
||||
} from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { ListChecks } from 'lucide-react'
|
||||
import { ListChecks, MessageCircleQuestion } from 'lucide-react'
|
||||
import clsx from 'clsx'
|
||||
import { rovingTarget } from '../components/ui'
|
||||
import {
|
||||
@@ -13,10 +13,11 @@ import {
|
||||
type EvidenceStateCode, type EvidenceTally as Tally,
|
||||
} from '../lib/evidence'
|
||||
import { formatNumber } from '../lib/format'
|
||||
import { EVIDENCE_STATE_LABEL, EVIDENCE_TEXT, JUDGE_TEXT, claimTally, evidenceTally, type ClaimTallyCounts } from '../lib/terms'
|
||||
import { EVIDENCE_STATE_LABEL, EVIDENCE_TEXT, INQUIRY_TEXT, JUDGE_TEXT, claimTally, evidenceTally, type ClaimTallyCounts } from '../lib/terms'
|
||||
import { useEvidence, useVerdicts } from '../store/evidence'
|
||||
import type { EvidenceBlock, EvidenceDocData, EvidenceSegment, EvidenceUnit, EvidenceVerdict } from '../types'
|
||||
import { EvidencePanel, type PanelMode, type PanelView } from './EvidencePanel'
|
||||
import { askAbout, type InquiryAccess } from './Inquiry'
|
||||
import { BlockView, Markdown, StyledSlice, inlineStyles, numericColumns, type InlineStyles } from './Markdown'
|
||||
|
||||
/**
|
||||
@@ -54,6 +55,19 @@ const TEXT_CAP = 3000
|
||||
/** 句末徽标在键盘顺序里的键:片段 id 是 s0…,不会撞 */
|
||||
const badgeKey = (unit: string) => `claim:${unit}`
|
||||
const unitOfKey = (key: string) => (key.startsWith('claim:') ? key.slice(6) : null)
|
||||
/**
|
||||
* 审批质询的「质询」在键盘顺序里的键。只有没有可点片段、也没有徽标的句子,「质询」本身进键盘顺序(方向键走得到这一句);
|
||||
* 别的句子的「质询」跟在这一句后面,焦点在这一句上时按 Tab 到达,不多占键盘顺序
|
||||
*/
|
||||
const askKey = (unit: string) => `ask:${unit}`
|
||||
const unitOfAsk = (key: string) => (key.startsWith('ask:') ? key.slice(4) : null)
|
||||
|
||||
/**
|
||||
* 哪些句子挂「质询」:结论句(老文档没有 kind 的按有字的句子),标题、代码块里的不挂。表格里的格子也不挂:每格一个
|
||||
* 图标会把列撑宽、满表都是图标;问表里的数可以划选那一格,或者就整份报告提问
|
||||
*/
|
||||
const askable = (unit: EvidenceUnit, block: EvidenceBlock) =>
|
||||
(unit.kind ? unit.kind === 'claim' : !!unitText(unit).trim()) && !['heading', 'code', 'hr', 'table'].includes(block.type)
|
||||
|
||||
interface Badge { unit: EvidenceUnit; block: number; verdict: EvidenceVerdict; state: EvidenceStateCode }
|
||||
|
||||
@@ -64,6 +78,8 @@ interface Model {
|
||||
seg: Map<string, { seg: EvidenceSegment; unit: EvidenceUnit; block: number }>
|
||||
/** 句末徽标:键是 claim:<unit>,带着这一句眼下的判定 */
|
||||
badge: Map<string, Badge>
|
||||
/** 进了键盘顺序的「质询」(审批质询):键是 ask:<unit> */
|
||||
ask: Map<string, { unit: EvidenceUnit; block: number }>
|
||||
/** 每个有可点片段的句子里第一个可点片段,按正文顺序(↑/↓ 用) */
|
||||
unitFirst: string[]
|
||||
unitOf: Map<string, number>
|
||||
@@ -82,11 +98,12 @@ interface Model {
|
||||
grid: Map<string, string>
|
||||
}
|
||||
|
||||
function buildModel(blocks: EvidenceBlock[], overlay?: Record<string, EvidenceVerdict>): Model {
|
||||
function buildModel(blocks: EvidenceBlock[], overlay?: Record<string, EvidenceVerdict>, ask = false): Model {
|
||||
const order: string[] = []
|
||||
const index = new Map<string, number>()
|
||||
const seg = new Map<string, { seg: EvidenceSegment; unit: EvidenceUnit; block: number }>()
|
||||
const badge = new Map<string, Badge>()
|
||||
const asks = new Map<string, { unit: EvidenceUnit; block: number }>()
|
||||
const unitFirst: string[] = []
|
||||
const unitOf = new Map<string, number>()
|
||||
const tiered: [string, 1 | 2][] = []
|
||||
@@ -128,18 +145,27 @@ function buildModel(blocks: EvidenceBlock[], overlay?: Record<string, EvidenceVe
|
||||
const t = alertTier(state)
|
||||
if (t) tiered.push([key, t])
|
||||
}
|
||||
// 审批质询:一个可点的都没有的结论句,「质询」本身进键盘顺序,不然键盘用户问不了这一句
|
||||
if (ask && first && askable(unit, block)) {
|
||||
const key = askKey(unit.id)
|
||||
asks.set(key, { unit, block: b })
|
||||
index.set(key, order.length)
|
||||
order.push(key)
|
||||
unitFirst.push(key)
|
||||
unitOf.set(key, unitFirst.length - 1)
|
||||
}
|
||||
}
|
||||
chars.push(total)
|
||||
})
|
||||
// 按(轮次、正文顺序)排:tiered 本来就是正文顺序,稳定排序只按轮次挪
|
||||
const sorted = [...tiered].sort((a, b) => a[1] - b[1])
|
||||
return { order, index, seg, badge, unitFirst, unitOf, alerts: sorted.map(([k]) => k), tier: new Map(sorted), chars, cell,
|
||||
grid }
|
||||
return { order, index, seg, badge, ask: asks, unitFirst, unitOf, alerts: sorted.map(([k]) => k), tier: new Map(sorted), chars,
|
||||
cell, grid }
|
||||
}
|
||||
|
||||
/** 片段或徽标在第几块 */
|
||||
const blockOf = (model: Model, key: string | null | undefined): number =>
|
||||
(key ? model.seg.get(key)?.block ?? model.badge.get(key)?.block : undefined) ?? -1
|
||||
(key ? model.seg.get(key)?.block ?? model.badge.get(key)?.block ?? model.ask.get(key)?.block : undefined) ?? -1
|
||||
|
||||
/**
|
||||
* ↑/↓ 该去哪。表格里按列走:下一行同一列(那一格空着就找这一行离它最近的一格);
|
||||
@@ -217,13 +243,21 @@ export const EvidenceDoc = forwardRef<EvidenceDocHandle, {
|
||||
* 数字的出处都对得上,档位却因为别的原因(比如查询没通过 SQL 检查)降了
|
||||
*/
|
||||
tier?: string
|
||||
/**
|
||||
* 审批质询(期 4):给了就在每句结论后面挂「质询」(悬停、焦点在这一句上时出现),划选原文时浮出「质询」,点了打开
|
||||
* 这份报告的提问框。能不能问由页面按运行状态定(审批卡:运行停在审批上;运行详情:封存了的探索运行),approvalId 是
|
||||
* 运行停在的那张审批。给了它,页面上要同时挂这份报告的 ReportInquiry(问答串和提问框在那里)
|
||||
*/
|
||||
inquiry?: InquiryAccess | null
|
||||
}>(function EvidenceDoc({ doc, artifact, runId, dense = false, label, panel = 'auto', dock, onView, tally = false, runClass,
|
||||
tier }, ref) {
|
||||
tier, inquiry }, ref) {
|
||||
const blocks = useMemo(() => doc.blocks ?? [], [doc])
|
||||
const report = doc.node_id || undefined
|
||||
// 质询要知道是哪次运行的哪份报告:两样缺一样就不挂入口
|
||||
const ask = !!inquiry && !!runId && !!report
|
||||
// 封存之后按需追加的判定:盖过文档里的「未裁判 · 按需」。只换句末徽标,封存的文档一个字不改
|
||||
const overlay = useVerdicts(runId, report)
|
||||
const model = useMemo(() => buildModel(blocks, overlay), [blocks, overlay])
|
||||
const model = useMemo(() => buildModel(blocks, overlay, ask), [blocks, overlay, ask])
|
||||
const counts = useMemo(() => docTally(doc), [doc])
|
||||
const claims = useMemo(() => claimCounts(doc, overlay), [doc, overlay])
|
||||
// 探索运行的报告(开了裁判的按需文档,或调用方说了是探索运行):证据图带着这次运行里之前按需判过的句子
|
||||
@@ -272,7 +306,9 @@ export const EvidenceDoc = forwardRef<EvidenceDocHandle, {
|
||||
|
||||
const segEl = useCallback((id: string) => {
|
||||
const unit = unitOfKey(id)
|
||||
const sel = unit ? `[data-ev-claim="${CSS.escape(unit)}"]` : `[data-seg="${CSS.escape(id)}"]`
|
||||
const asked = unitOfAsk(id)
|
||||
const sel = unit ? `[data-ev-claim="${CSS.escape(unit)}"]`
|
||||
: asked ? `[data-inquiry-ask="${CSS.escape(asked)}"]` : `[data-seg="${CSS.escape(id)}"]`
|
||||
return rootRef.current?.querySelector<HTMLElement>(sel) ?? null
|
||||
}, [])
|
||||
|
||||
@@ -373,13 +409,29 @@ export const EvidenceDoc = forwardRef<EvidenceDocHandle, {
|
||||
},
|
||||
}), [step, model, viewKey, current, focusSeg, openSeg, openViolations, doc])
|
||||
|
||||
// 事件委托:片段只带 data-seg、句末徽标只带 data-ev-claim,点击和按键都在容器上认
|
||||
// 事件委托:片段只带 data-seg、句末徽标只带 data-ev-claim,点击和按键都在容器上认。「质询」只有进了键盘顺序的才算
|
||||
// (跟在有可点片段的句子后面的那种不算:方向键在它上面不动,Tab 照常离开)
|
||||
const segOf = (target: EventTarget | null): string | null => {
|
||||
const el = (target as HTMLElement | null)?.closest?.<HTMLElement>('[data-seg], [data-ev-claim]')
|
||||
const el = (target as HTMLElement | null)?.closest?.<HTMLElement>('[data-seg], [data-ev-claim], [data-inquiry-ask]')
|
||||
if (!el || !rootRef.current?.contains(el)) return null
|
||||
if (el.dataset.inquiryAsk) return model.index.has(askKey(el.dataset.inquiryAsk)) ? askKey(el.dataset.inquiryAsk) : null
|
||||
return el.dataset.seg ?? (el.dataset.evClaim ? badgeKey(el.dataset.evClaim) : null)
|
||||
}
|
||||
/** 点了句末的「质询」:打开这份报告的提问框,问的是这一句 */
|
||||
const askUnit = (el: HTMLElement) => {
|
||||
const id = el.dataset.inquiryAsk
|
||||
if (!id || !inquiry || !runId || !report) return
|
||||
const unit = blocks.flatMap((b) => b.units ?? []).find((u) => u.id === id)
|
||||
if (model.index.has(askKey(id))) setCurrent(askKey(id))
|
||||
askAbout(runId, report, inquiry, { unit: id, quote: null, text: unit ? unitText(unit).trim() : '' }, el)
|
||||
}
|
||||
const onClick = (e: ReactMouseEvent) => {
|
||||
const asking = (e.target as HTMLElement | null)?.closest?.<HTMLElement>('[data-inquiry-ask]')
|
||||
if (asking && rootRef.current?.contains(asking)) {
|
||||
e.preventDefault()
|
||||
askUnit(asking)
|
||||
return
|
||||
}
|
||||
const id = segOf(e.target)
|
||||
if (!id) return
|
||||
e.preventDefault()
|
||||
@@ -445,11 +497,40 @@ export const EvidenceDoc = forwardRef<EvidenceDocHandle, {
|
||||
/>
|
||||
)
|
||||
|
||||
// 审批质询:划选一段原文,浮出「质询」,问的是选中的这段(带上它起头的那一句)
|
||||
const pickAnchor = useRef<HTMLDivElement>(null)
|
||||
const [pick, dropPick] = useSelectionPick(rootRef, pickAnchor, ask)
|
||||
const askPick = () => {
|
||||
if (!pick || !inquiry || !runId || !report) return
|
||||
// 浮出的按钮点完就没了:Esc 之后焦点回到那一句的「质询」
|
||||
const back = pick.unit ? rootRef.current?.querySelector<HTMLElement>(`[data-inquiry-ask="${CSS.escape(pick.unit)}"]`) : null
|
||||
document.getSelection()?.removeAllRanges()
|
||||
dropPick()
|
||||
askAbout(runId, report, inquiry, { unit: pick.unit, quote: pick.quote, text: pick.quote }, back)
|
||||
}
|
||||
|
||||
// 画不了线的两种分开说:列表序号、代码块标签里的数字,和正文里根本没有对应字的(句末依据里的引用)
|
||||
const summary = tallySummary({ ...counts, claims }, model.order.length > 0)
|
||||
const summary = [tallySummary({ ...counts, claims }, model.order.length > 0), ask ? INQUIRY_TEXT.keysHint : '']
|
||||
.filter(Boolean).join('。')
|
||||
|
||||
return (
|
||||
<div ref={rootRef} data-evidence-doc="" className="min-w-0">
|
||||
{ask && (
|
||||
// 划选原文浮出的「质询」挂在文档里(高度为 0 的定位锚点下面,按锚点算坐标),不挂到页面末尾:画布上的审批浮层
|
||||
// 按下在它外面就收起,挂在外面的按钮一按,浮层连同报告一起收掉。也因此会被报告框裁切,位置按可见范围摆(见
|
||||
// useSelectionPick)
|
||||
<div ref={pickAnchor} className="relative" data-inquiry-pick-anchor="">
|
||||
{pick && (
|
||||
// 按下时不抢焦点、不清掉选区:点下去才读选区
|
||||
<button type="button" className="btn btn-xs absolute z-20 whitespace-nowrap shadow-elev-3" data-inquiry-selection=""
|
||||
style={{ left: pick.left, top: pick.top }} aria-label={INQUIRY_TEXT.askSelection}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={(e) => { e.stopPropagation(); askPick() }}>
|
||||
<MessageCircleQuestion size={11} aria-hidden /> {INQUIRY_TEXT.ask}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<p id={summaryId} className="sr-only" data-evidence-summary="">{summary}</p>
|
||||
<div className="sr-only" aria-live="polite" aria-atomic="true">{announce}</div>
|
||||
{tally && (counts.total > 0 || counts.other > 0 || !!counts.suspect || !!claims?.total) && (
|
||||
@@ -473,7 +554,7 @@ export const EvidenceDoc = forwardRef<EvidenceDocHandle, {
|
||||
<DocBlock block={block} dense={dense} doc={doc} visual={visual}
|
||||
current={b === currentBlock ? current : null}
|
||||
active={b === activeBlock ? activeSeg : null}
|
||||
panelId={panelId} model={model} />
|
||||
panelId={panelId} model={model} ask={ask} />
|
||||
{mode === 'inline' && b === activeBlock && panelNode}
|
||||
</Fragment>
|
||||
))}
|
||||
@@ -498,6 +579,103 @@ export const EvidenceDoc = forwardRef<EvidenceDocHandle, {
|
||||
)
|
||||
})
|
||||
|
||||
/** 划选的一段原文:要问的字、它起头的那一句、浮出按钮的位置(相对定位锚点) */
|
||||
interface SelectionPick { quote: string; unit: string | null; left: number; top: number }
|
||||
/** 浮出按钮的大致尺寸(宁大勿小):放在选区末尾下方,贴边时收进可见范围,下方放不下时放到选区上方 */
|
||||
const PICK_W = 64
|
||||
const PICK_H = 26
|
||||
/** 按钮和选区、和可见范围边上留的空 */
|
||||
const PICK_GAP = 6
|
||||
|
||||
/**
|
||||
* 一个元素眼下看得见的范围(视口坐标):视口,再和每一层会裁切内容的祖先(overflow 不是 visible 的,比如审批卡里
|
||||
* 限高滚动的报告框)取交集。浮出的按钮挂在文档里,超出这个范围的部分会被裁掉
|
||||
*/
|
||||
function visibleBox(el: Element): { top: number; bottom: number; left: number; right: number } {
|
||||
const box = { top: 0, left: 0, bottom: window.innerHeight, right: window.innerWidth }
|
||||
for (let p: Element | null = el; p && p !== document.documentElement; p = p.parentElement) {
|
||||
const style = getComputedStyle(p)
|
||||
if (style.overflowX === 'visible' && style.overflowY === 'visible') continue
|
||||
const r = p.getBoundingClientRect()
|
||||
box.top = Math.max(box.top, r.top)
|
||||
box.left = Math.max(box.left, r.left)
|
||||
box.bottom = Math.min(box.bottom, r.bottom)
|
||||
box.right = Math.min(box.right, r.right)
|
||||
}
|
||||
return box
|
||||
}
|
||||
|
||||
/**
|
||||
* 报告正文里划选了一段原文:返回要问的字和浮出按钮的位置,选区收起、移出正文、滚出可见范围时为 null。只认报告正文
|
||||
* 里的字——栏内展开的证据面板也在这个容器里,那里的字不算。要问的字按选区克隆出来算,去掉句末徽标、「无证据」小标签、
|
||||
* 读屏文字和「质询」本身(它们在 DOM 里,却不是报告的原文)。
|
||||
*
|
||||
* 位置相对 anchor(文档里高度为 0 的定位锚点)算:按钮挂在文档里,会被限高滚动的报告框裁切,所以按可见范围摆——
|
||||
* 默认在选区末尾下方,下方放不下放到选区上方,左右收进文档的宽度(不把报告框撑出横向滚动)和可见范围
|
||||
*/
|
||||
function useSelectionPick(root: RefObject<HTMLElement | null>, anchor: RefObject<HTMLElement | null>,
|
||||
enabled: boolean): [SelectionPick | null, () => void] {
|
||||
const [pick, setPick] = useState<SelectionPick | null>(null)
|
||||
useEffect(() => {
|
||||
if (!enabled) { setPick(null); return }
|
||||
let frame = 0
|
||||
const read = () => {
|
||||
frame = 0
|
||||
const el = root.current
|
||||
const origin = anchor.current
|
||||
const sel = document.getSelection()
|
||||
if (!el || !origin || !sel || sel.isCollapsed || !sel.rangeCount) { setPick(null); return }
|
||||
const range = sel.getRangeAt(0)
|
||||
const at = (n: Node) => (n instanceof Element ? n : n.parentElement)
|
||||
const inside = (x: Element | null) => !!x && el.contains(x) && !!x.closest('[data-block]') && !x.closest('[data-evidence-panel]')
|
||||
const start = at(range.startContainer)
|
||||
if (!inside(start) || !inside(at(range.endContainer))) { setPick(null); return }
|
||||
const frag = range.cloneContents()
|
||||
frag.querySelectorAll('[data-inquiry-ask], .ev-tag, .ev-badge, .sr-only').forEach((n) => n.remove())
|
||||
const quote = (frag.textContent ?? '').replace(/\s+/g, ' ').trim()
|
||||
if ([...quote].length < 2) { setPick(null); return }
|
||||
const rects = range.getClientRects()
|
||||
const last = rects[rects.length - 1] ?? range.getBoundingClientRect()
|
||||
const first = rects[0] ?? last
|
||||
const view = visibleBox(el)
|
||||
// 选区整个滚出了可见范围:按钮也不留(滚回来再量出来)
|
||||
if (last.bottom <= view.top || first.top >= view.bottom) { setPick(null); return }
|
||||
const doc = el.getBoundingClientRect()
|
||||
const lo = Math.max(doc.left, view.left)
|
||||
const hi = Math.min(doc.right, view.right) - PICK_W
|
||||
const x = Math.max(lo, Math.min(last.right - PICK_W / 2, hi))
|
||||
const fitsBelow = last.bottom + PICK_GAP + PICK_H <= view.bottom
|
||||
const fitsAbove = first.top - PICK_GAP - PICK_H >= view.top
|
||||
const y = fitsBelow || !fitsAbove ? Math.min(last.bottom + PICK_GAP, Math.max(view.top, view.bottom - PICK_H))
|
||||
: first.top - PICK_GAP - PICK_H
|
||||
const o = origin.getBoundingClientRect()
|
||||
const next: SelectionPick = {
|
||||
quote, unit: start?.closest('[data-ev-unit]')?.getAttribute('data-ev-unit') ?? null,
|
||||
left: Math.round(x - o.left), top: Math.round(y - o.top),
|
||||
}
|
||||
// 滚动时每一帧都会量一次:没变就不换对象,整份报告不跟着重画
|
||||
setPick((cur) => (cur && cur.quote === next.quote && cur.unit === next.unit && cur.left === next.left && cur.top === next.top
|
||||
? cur : next))
|
||||
}
|
||||
// 选区一变、页面或报告框一滚、窗口一变都重新量:可见范围变了,按钮放上方还是下方跟着变。文档自己的尺寸变了也量:
|
||||
// 悬停一句时它的「质询」出现、那一段多折一行,下面的字整体下移,既不滚动也不改选区,按钮却得跟着挪
|
||||
const schedule = () => { if (!frame) frame = requestAnimationFrame(read) }
|
||||
document.addEventListener('selectionchange', schedule)
|
||||
window.addEventListener('scroll', schedule, true)
|
||||
window.addEventListener('resize', schedule)
|
||||
const resized = typeof ResizeObserver === 'function' ? new ResizeObserver(schedule) : null
|
||||
if (root.current) resized?.observe(root.current)
|
||||
return () => {
|
||||
cancelAnimationFrame(frame)
|
||||
document.removeEventListener('selectionchange', schedule)
|
||||
window.removeEventListener('scroll', schedule, true)
|
||||
window.removeEventListener('resize', schedule)
|
||||
resized?.disconnect()
|
||||
}
|
||||
}, [root, anchor, enabled])
|
||||
return [pick, useCallback(() => setPick(null), [])]
|
||||
}
|
||||
|
||||
/** 定位到的片段描一下边(CSS 的 [data-flash]),同 AssistantStream 的 flash */
|
||||
function flashOnce(el: HTMLElement) {
|
||||
el.dataset.flash = 'focus'
|
||||
@@ -590,12 +768,14 @@ export function ClaimTally({ claims, lead }: { claims: ClaimTallyCounts; lead: b
|
||||
/** 列表项的开头:结构片段里带着行首的 - / 1. 。列表项被分成几句时,后面几句接在同一项里 */
|
||||
const ITEM_START = /(^|\n)[ \t]*([-*+]|\d+[.)])[ \t]+$/
|
||||
|
||||
const DocBlock = memo(function DocBlock({ block, dense, doc, visual, current, active, panelId, model }: {
|
||||
const DocBlock = memo(function DocBlock({ block, dense, doc, visual, current, active, panelId, model, ask }: {
|
||||
block: EvidenceBlock
|
||||
dense: boolean
|
||||
doc: EvidenceDocData
|
||||
/** 句末徽标从这里取:这一句眼下的判定(封存后追加的盖过文档里的) */
|
||||
model: Model
|
||||
/** 审批质询:结论句后面挂「质询」 */
|
||||
ask: boolean
|
||||
/**
|
||||
* 长文档:块上加 content-visibility,屏幕外的块不排版不绘制。短文档不加:它自带 paint
|
||||
* containment,贴着块边的片段的焦点描边会被裁掉一截,而短文档本来就不慢
|
||||
@@ -614,7 +794,8 @@ const DocBlock = memo(function DocBlock({ block, dense, doc, visual, current, ac
|
||||
}
|
||||
const unit = (u: EvidenceUnit, opts?: { code?: boolean; tag?: boolean }) => (
|
||||
<UnitView key={u.id} unit={u} doc={doc} current={current} active={active} panelId={panelId}
|
||||
code={opts?.code} tag={opts?.tag ?? true} badge={model.badge.get(badgeKey(u.id))} />
|
||||
code={opts?.code} tag={opts?.tag ?? true} badge={model.badge.get(badgeKey(u.id))}
|
||||
ask={ask && askable(u, block) ? (model.ask.has(askKey(u.id)) ? 'roving' : 'follow') : undefined} />
|
||||
)
|
||||
|
||||
switch (block.type) {
|
||||
@@ -684,9 +865,14 @@ const DocBlock = memo(function DocBlock({ block, dense, doc, visual, current, ac
|
||||
* 被切坏),有状态的片段包成按钮。含无证据片段的句子末尾挂「? 无证据」;有判定的结论句末尾挂
|
||||
* 一枚徽标(也是按钮),证据相矛盾(和旧的证据不支持)的整句铺浅底——字本身不画线
|
||||
*/
|
||||
function UnitView({ unit, doc, current, active, panelId, code, tag, badge }: {
|
||||
function UnitView({ unit, doc, current, active, panelId, code, tag, badge, ask }: {
|
||||
unit: EvidenceUnit; doc: EvidenceDocData; current: string | null; active: string | null; panelId: string
|
||||
code?: boolean; tag: boolean; badge?: Badge
|
||||
/**
|
||||
* 审批质询的「质询」:roving 是这一句一个可点的都没有,「质询」本身进键盘顺序;follow 跟在这一句后面,焦点在这一句上时
|
||||
* 按 Tab 到达
|
||||
*/
|
||||
ask?: 'roving' | 'follow'
|
||||
}) {
|
||||
const segs = (unit.segments ?? []).filter((s) => s.kind !== 'structural')
|
||||
const text = segs.map((s) => s.text).join('')
|
||||
@@ -727,7 +913,7 @@ function UnitView({ unit, doc, current, active, panelId, code, tag, badge }: {
|
||||
const key = badge ? badgeKey(unit.id) : ''
|
||||
const meta = badge ? EVIDENCE_STATE[badge.state] : null
|
||||
const open = !!badge && active === key
|
||||
return (
|
||||
const body = (
|
||||
<>
|
||||
{conflicting(badge?.state)
|
||||
// 证据相矛盾(和旧的证据不支持):整句铺一层浅底(折行时每行各自带圆角),字色、字重都不动,也不画线
|
||||
@@ -762,6 +948,29 @@ function UnitView({ unit, doc, current, active, panelId, code, tag, badge }: {
|
||||
)}
|
||||
</>
|
||||
)
|
||||
if (!ask) return body
|
||||
// 「质询」跟在句末,是一个固定宽度的小图标:平时淡淡的,悬停这一句、焦点落在这一句上时显出来(强调色、描边)。
|
||||
// 显没显出来只换颜色,宽度一直是那么宽——悬停时撑开的话,后面的字整体右移,鼠标底下的数字跟着挪走,点不到。
|
||||
// 触屏没有悬停,一直显出来,并写上「质询」两个字。
|
||||
// 跟随的那种只在焦点在这一句上时进 Tab 顺序,整份报告不因此多出一串 Tab 位
|
||||
const here = current != null && (current === key || current === askKey(unit.id)
|
||||
|| (unit.segments ?? []).some((sg) => sg.id === current))
|
||||
return (
|
||||
<span className="group/evu" data-ev-unit={unit.id}>
|
||||
{body}
|
||||
<button type="button" data-inquiry-ask={unit.id} tabIndex={here ? 0 : -1}
|
||||
aria-label={INQUIRY_TEXT.askUnit(unitText(unit).trim())} title={INQUIRY_TEXT.askTitle}
|
||||
className={'ml-1 inline-flex select-none items-center gap-0.5 whitespace-nowrap rounded border border-transparent px-[3px] '
|
||||
+ 'align-middle text-[10px] font-medium leading-[1.4] text-faint opacity-60 outline-none '
|
||||
+ 'hover:bg-hover group-hover/evu:border-[color:var(--border)] group-hover/evu:text-[color:var(--accent)] group-hover/evu:opacity-100 '
|
||||
+ 'group-focus-within/evu:border-[color:var(--border)] group-focus-within/evu:text-[color:var(--accent)] group-focus-within/evu:opacity-100 '
|
||||
+ 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-[color:var(--accent)] '
|
||||
+ 'pointer-coarse:border-[color:var(--border)] pointer-coarse:text-[color:var(--accent)] pointer-coarse:opacity-100'}>
|
||||
<MessageCircleQuestion size={11} aria-hidden />
|
||||
<span aria-hidden="true" className="hidden pointer-coarse:inline">{INQUIRY_TEXT.ask}</span>
|
||||
</button>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,15 +5,16 @@ import { api } from '../api/client'
|
||||
import { useStudio } from '../store/studio'
|
||||
import { useCatalog } from '../store/catalog'
|
||||
import { NODE_DEFS } from '../canvas/nodeDefs'
|
||||
import { StatusDot, useToast } from '../components/ui'
|
||||
import { Spinner, StatusDot, useToast } from '../components/ui'
|
||||
import { useLocalActor } from '../lib/actor'
|
||||
import { formatDateTime, formatSpan, formatTime, parseServerTime } from '../lib/format'
|
||||
import { runClassLabel, runName, TOOL_TRUST_TEXT } from '../lib/terms'
|
||||
import { INQUIRY_TEXT, runClassLabel, runName, TOOL_TRUST_TEXT } from '../lib/terms'
|
||||
import { useRunClock } from './useRunClock'
|
||||
import { Markdown } from './Markdown'
|
||||
import { ApprovalReports, ApprovalRunClass } from './ApprovalReport'
|
||||
import { ChallengeSummary } from './ChallengeSummary'
|
||||
import { DualCheckApproval } from './DualCheckApproval'
|
||||
import { useInquiryBusy } from './Inquiry'
|
||||
import type { Approval, ApprovalReport } from '../types'
|
||||
|
||||
// 发起运行的表单搬去了 run/RunControl.tsx 的工具栏控件里。它原先常驻在
|
||||
@@ -48,6 +49,8 @@ export function ApprovalCard({ approval, onResolved, showWorkflow = true }: {
|
||||
approval.payload?.draft != null ? String(approval.payload.draft) : '',
|
||||
)
|
||||
const [busy, setBusy] = useState(false)
|
||||
// 审批质询正在回答:服务端这时拒绝审批回复(409),批准 / 驳回先停用,并说明原因
|
||||
const inquiring = useInquiryBusy(approval.run_id)
|
||||
const payload = approval.payload ?? {}
|
||||
// 本机署名随 X-Actor 发给后端、写进审批留痕;在设置或发布弹窗里改了,卡底这句跟着变
|
||||
const actor = useLocalActor()
|
||||
@@ -152,7 +155,8 @@ export function ApprovalCard({ approval, onResolved, showWorkflow = true }: {
|
||||
{/* 双盲复算对不上、交给人裁决的审批,卡上画两路结果的对照 */}
|
||||
{dualCheck && <DualCheckApproval approval={approval} onResolved={onResolved} />}
|
||||
|
||||
<ApprovalReports reports={reports} runId={approval.run_id} runClass={approval.run_class} />
|
||||
<ApprovalReports reports={reports} runId={approval.run_id} runClass={approval.run_class}
|
||||
approvalId={approval.id} askable={approval.status === 'pending'} />
|
||||
<ChallengeSummary reports={reports} runId={approval.run_id} />
|
||||
|
||||
{payload.tool && (
|
||||
@@ -193,20 +197,28 @@ export function ApprovalCard({ approval, onResolved, showWorkflow = true }: {
|
||||
/>
|
||||
|
||||
<div className="flex gap-2">
|
||||
<button className="btn btn-primary flex-1 justify-center" disabled={busy} onClick={() => decide(true)}>
|
||||
<button className="btn btn-primary flex-1 justify-center" disabled={busy || inquiring} onClick={() => decide(true)}>
|
||||
<Check size={12} aria-hidden /> {approveMode ? '批准' : '提交'}
|
||||
</button>
|
||||
{trustKey && (
|
||||
<button className="btn flex-1 justify-center" disabled={busy} data-approval-always
|
||||
<button className="btn flex-1 justify-center" disabled={busy || inquiring} data-approval-always
|
||||
title={TOOL_TRUST_TEXT.alwaysHint(trustKey)} aria-describedby={`approval-always-${approval.id}`}
|
||||
onClick={() => decide(true, true)}>
|
||||
<CheckCheck size={12} aria-hidden /> {TOOL_TRUST_TEXT.alwaysButton}
|
||||
</button>
|
||||
)}
|
||||
<button className="btn btn-danger flex-1 justify-center" disabled={busy} onClick={() => decide(false)}>
|
||||
<button className="btn btn-danger flex-1 justify-center" disabled={busy || inquiring} onClick={() => decide(false)}>
|
||||
<Ban size={12} aria-hidden /> {approveMode ? '驳回' : '驳回并终止'}
|
||||
</button>
|
||||
</div>
|
||||
{inquiring && (
|
||||
// 字用正文色:审批卡铺着一层提醒色的底,提醒色的字在浅色主题下对比度不够;提醒色交给转圈的图标
|
||||
<div className="mt-1.5 flex items-start gap-1 text-2xs font-medium leading-relaxed text-fg" role="status"
|
||||
data-approval-inquiry-busy="">
|
||||
<span className="mt-[3px] shrink-0" style={{ color: 'var(--st-waiting)' }}><Spinner size={11} /></span>
|
||||
<span>{INQUIRY_TEXT.decideBlocked}</span>
|
||||
</div>
|
||||
)}
|
||||
{/* 批了会怎样,常显而不是藏在 hover 里:审批人得在按下去之前知道 */}
|
||||
<div className="mt-1.5 text-2xs leading-relaxed text-dim">
|
||||
{approveMode
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { NodeState, RunPhase } from './trace'
|
||||
import { formatDuration, formatNumber } from '../lib/format'
|
||||
import {
|
||||
ABSENCE_CLAIM_TEXT, CATALOG_DRIFT_TEXT, CATALOG_PATCH_TEXT, COPILOT_CONTEXT_TEXT, JUDGE_TEXT, MERGE_TEXT, RUN_SQL_CHECK_TEXT, SCHEMA_PARTIAL_TEXT, SQL_CHECK_TEXT, TYPE_LABEL,
|
||||
CATALOG_TABLE_FIELD_LABEL, CHALLENGE_TEXT, DUAL_CHECK_TEXT, NODE_TYPE_LABEL,
|
||||
CATALOG_TABLE_FIELD_LABEL, CHALLENGE_TEXT, DUAL_CHECK_TEXT, INQUIRY_TEXT, NODE_TYPE_LABEL,
|
||||
claimTally,
|
||||
evidenceTally, issuanceLabel, nodeTypeLabel,
|
||||
} from '../lib/terms'
|
||||
@@ -704,6 +704,52 @@ const JUDGE_FAILED_TITLE = '结论句裁判未能执行'
|
||||
/** 审批行末尾:批的时候点了「始终允许」,这个工具之后不再问人 */
|
||||
const ALWAYS_NOTE = ',并设为「始终允许 · 门控把关」'
|
||||
|
||||
/** 「审批人质询」那一行的标题里,问题最多带几个字(按字数,不按 UTF-16 码元) */
|
||||
const INQUIRY_TITLE = 40
|
||||
|
||||
/**
|
||||
* approval.inquiry → 一行「审批人质询」:标题带问题的前 40 字,副标题说回答是否完成、查了几次(封存之后问的另写一句)。
|
||||
*
|
||||
* 只认服务端给的:ok 为真才说「回答完成」,带着触顶原因的说不完整、写明是哪个上限;没说成没成(缺字段)又有回答正文的
|
||||
* 只说「已回答」。查了几次认 queries,没有再认 inquiry_artifacts,两样都没有就不说次数——不拿 0 去顶。字段类型不对的
|
||||
* 当没给:问题不是字符串就只写「审批人质询」
|
||||
*/
|
||||
function inquiryStep(d: Record<string, any>, seq: number): Step {
|
||||
const T = INQUIRY_TEXT
|
||||
const str = (v: unknown) => (typeof v === 'string' ? v.trim() : '')
|
||||
const question = str(d.question)
|
||||
const chars = [...question]
|
||||
const head = chars.length > INQUIRY_TITLE ? `${chars.slice(0, INQUIRY_TITLE).join('')}…` : question
|
||||
const limit = str(d.limit)
|
||||
const limitText = limit ? T.limit[limit] ?? T.limitOther : ''
|
||||
const answer = str(d.answer_text)
|
||||
const error = str(d.error)
|
||||
const state = d.ok === true ? (limit ? T.incomplete(limitText) : T.complete)
|
||||
: d.ok === false || !answer ? T.failed(limitText || null) : T.answered
|
||||
const runs = Array.isArray(d.queries) ? d.queries.length
|
||||
: Array.isArray(d.inquiry_artifacts) ? d.inquiry_artifacts.length : null
|
||||
const fine = !limit && !error && (d.ok === true || (d.ok !== false && !!answer))
|
||||
const quote = str(d.quote)
|
||||
const model = str(d.model)
|
||||
const doc = str(d.answer_doc)
|
||||
const detail = [
|
||||
question ? T.detail.question(question) : '',
|
||||
quote ? T.detail.quote(quote) : '',
|
||||
answer ? T.detail.answer(answer) : '',
|
||||
error ? T.detail.error(error) : '',
|
||||
model ? T.detail.model(model) : '',
|
||||
].filter(Boolean).join('\n')
|
||||
return {
|
||||
id: `iq-${seq}`, seq, kind: 'human', status: 'done', code: 'approval_inquiry',
|
||||
level: fine ? 'info' : 'warn',
|
||||
title: T.timeline(head),
|
||||
sub: [state, runs != null ? T.queries(runs) : '', d.post_seal === true ? T.postSeal : ''].filter(Boolean).join(' · '),
|
||||
...(detail ? { detail } : {}),
|
||||
// 回答组装成的文档(数字带出处):展开区可以下钻
|
||||
...(doc ? { artifact: doc } : {}),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 门控模型(工具信任档「始终允许 · 门控把关」)对一次调用的结论。team:协作团队里拦下的,
|
||||
* 成员停不下来等人,这次调用不执行。没有工具名(老数据、字段缺了)就说「一次工具调用」
|
||||
@@ -2176,6 +2222,12 @@ export function decodeRun(events: RunEvent[], final?: RunFinal, opts?: DecodeOpt
|
||||
break
|
||||
}
|
||||
|
||||
case 'approval.inquiry':
|
||||
// 审批人在批准前就待审的报告提问(审批质询):运行停在审批上时服务端追加这一条,node_id 为空,运行本身没动、
|
||||
// 报告也不改(相位照旧,见 nextPhase)。封存之后探索运行也能问,带 post_seal。一条事件就是一问一答,挂在顶层
|
||||
out.push(inquiryStep(d, seq))
|
||||
break
|
||||
|
||||
case 'catalog.drift': {
|
||||
// 从发布版本发起的正式运行:发布之后数据目录有变化。只提醒、运行照常,所以是一条警告,不是失败
|
||||
const drift = catalogDrift(d)
|
||||
|
||||
Reference in New Issue
Block a user