mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-21 23:52:00 +00:00
结论句裁判改造:「不支持」拆成「证据相矛盾」和「证据不足」,补全交给裁判的证据,旧判定可按新规则重判
- 判定取值改为:支持 / 部分支持 / 证据相矛盾 / 证据不足 / 不是结论。只有证据和句子冲突才判相矛盾; 证据里没有相关信息判证据不足,并写明缺什么(比如 SQL、字段清单) - 出具判档不变松:证据相矛盾按 on_unsupported 降档或不予出具;证据不足记一条缺口,最多降档、不能判完整出具; 改造前的「证据不支持」照旧当相矛盾处理 - 补全证据摘录:表名附字段清单和类型(最多 60 个,快照不全时注明,遮罩列不列);口径卡指标附上每个输入 取自哪次查询、哪一格,以及那次查询的 SQL;一律只读封存范围内的工件 - 理由上限从 60 字放宽到 120 字,在句子边界截断,不再截在半句中间 - 裁判模型:按需裁判也判断是否和写作模型相同、是否在价格表里,证据面板里醒目提示; 设置页没配裁判模型时写明「未单独配置,将使用助手的模型」 - 新判定带规则版本:改造前的判定在界面上标「按旧规则判定」,可以请模型按当前规则重新判断 - 界面:证据相矛盾用红色;证据不足用中性色和 ○,写明缺什么;讲方法、讲结构的句子在证据面板里直接列出 对应的 SQL 和字段清单;出具横幅、审计表、报告节点印章的计数都分开这两档 - 顺带写稳 check-publish 里一条等按钮状态的断言(并行时偶发)
This commit is contained in:
@@ -12,7 +12,7 @@ import { datasourceTools, modelOptions, providerOfModel, useCatalog, useDatasour
|
||||
import { api } from '../api/client'
|
||||
import { IconButton, JsonInput, Modal, isComposing, useRadioGroup } from '../components/ui'
|
||||
import { formatShortcut } from '../lib/keys'
|
||||
import { JUDGE_FIELD_LABEL, JUDGE_ON_UNSUPPORTED_LABEL, JUDGE_SETTING_TEXT, SUBGRAPH_UPGRADE_HELP, judgeByModelText, upgradeNewerText } from '../lib/terms'
|
||||
import { JUDGE_FIELD_LABEL, JUDGE_ON_UNSUPPORTED_HINT, JUDGE_ON_UNSUPPORTED_LABEL, JUDGE_SETTING_TEXT, SUBGRAPH_UPGRADE_HELP, judgeByModelText, upgradeNewerText } from '../lib/terms'
|
||||
import { TemplateText } from './TemplateText'
|
||||
import type { NodeType, ValidationIssue, WorkflowVersion } from '../types'
|
||||
|
||||
@@ -624,7 +624,8 @@ function FieldInput({ field, id, nodeId, syntax, value, config, invalid, describ
|
||||
const JUDGE_SUB_KEYS = new Set(['provider', 'model', 'max_claims', 'max_cost_usd', 'timeout_s', 'rewrite_once', 'on_unsupported'])
|
||||
|
||||
/**
|
||||
* 结论句裁判(claims: judge)的子配置:裁判模型、三项上限(各自可以设成不限)、改写一次、证据不支持时怎么判档。
|
||||
* 结论句裁判(claims: judge)的子配置:裁判模型、三项上限(各自可以设成不限)、改写一次、证据相矛盾时怎么判档
|
||||
* (键名仍是 on_unsupported;证据不足的句子最多降档)。
|
||||
*
|
||||
* 上限有三种写法,得分得清:没写(跟随设置里「证据裁判」的默认值)、写数、写 null(不限)。勾「不限」写 null,
|
||||
* 清空数字框回到没写。全都没写时整个 judge 去掉,不留一个空对象。受管级别发布要求写了 max_cost_usd(数或 null)
|
||||
@@ -705,7 +706,7 @@ function JudgeConfig({ id, value, config, issues, onChange }: {
|
||||
<span>
|
||||
{JUDGE_FIELD_LABEL.rewrite_once}
|
||||
<span className="mt-0.5 block text-2xs leading-snug text-faint">
|
||||
默认关闭。开启后,裁判判定为证据不支持的句子会连同理由交回撰写模型,仅改写这些句子并重新判断一次,最多一轮。
|
||||
默认关闭。开启后,裁判判定为证据相矛盾或证据不足的句子会连同理由交回撰写模型,仅改写这些句子并重新判断一次,最多一轮。
|
||||
会额外产生一次撰写和裁判的费用;改写稿如出现原稿没有的问题,则不予采用
|
||||
</span>
|
||||
</span>
|
||||
@@ -724,7 +725,7 @@ function JudgeConfig({ id, value, config, issues, onChange }: {
|
||||
<option value={judge.on_unsupported} disabled>{judge.on_unsupported}:无法识别的值,请从上方选项中选择</option>
|
||||
)}
|
||||
</select>
|
||||
<div className="mt-1 text-2xs leading-snug text-faint">仅对正式运行生效;探索运行只做标注,不拦截</div>
|
||||
<div className="mt-1 text-2xs leading-snug text-faint" data-judge-hint="on_unsupported">{JUDGE_ON_UNSUPPORTED_HINT}</div>
|
||||
{lines('on_unsupported')}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -13,7 +13,7 @@ import { edgeKey, topology } from '../run/derive'
|
||||
import { exhaustedOf } from '../run/decode'
|
||||
import { api } from '../api/client'
|
||||
import { isComposing, StatusBadge, toast } from '../components/ui'
|
||||
import { matchedSource } from '../lib/evidence'
|
||||
import { claimCountsOf, matchedSource } from '../lib/evidence'
|
||||
import { explainRunError } from '../lib/explain'
|
||||
import { formatDuration, formatLapse, formatNumber, formatTokens, NONE, shortId } from '../lib/format'
|
||||
import { statusMeta } from '../lib/status'
|
||||
@@ -189,11 +189,12 @@ function matchedLines(matched: unknown): string {
|
||||
return `追溯明细:\n${lines.join('\n')}${more}`
|
||||
}
|
||||
|
||||
/** stats 里的裁判句数(claims 为 judge 时才有)→「结论 4 句(支持 1 · 不支持 1 · 未裁判 2)」 */
|
||||
/**
|
||||
* stats 里的裁判句数(claims 为 judge 时才有)→「结论 5 句(有依据 1 · 证据相矛盾 1 · 证据不足 1 · 未裁判 2)」。
|
||||
* 旧文档的 stats 里是 unsupported(拆档之前的取值),照样计入、照旧叫「证据不支持」
|
||||
*/
|
||||
function claimsLine(st: ReportStamp['stats']): string {
|
||||
const n = (v: unknown) => (typeof v === 'number' && Number.isFinite(v) ? v : 0)
|
||||
const c = { supported: n(st.supported), partial: n(st.partial), unsupported: n(st.unsupported), unjudged: n(st.unjudged), uncited: 0 }
|
||||
return claimTally({ ...c, total: c.supported + c.partial + c.unsupported + c.unjudged })
|
||||
return claimTally(claimCountsOf(st as Record<string, unknown>))
|
||||
}
|
||||
|
||||
/** 报告节点章的悬停说明:两个数怎么来的,缺口里各有什么 */
|
||||
|
||||
@@ -28,6 +28,7 @@ import evidenceFixture from '../run/__tests__/evidence-doc.json'
|
||||
import evidenceQuery from '../run/__tests__/evidence-query.json'
|
||||
import evidenceEntity from '../run/__tests__/evidence-entity.json'
|
||||
import evidenceJudge from '../run/__tests__/evidence-judge.json'
|
||||
import evidenceVerdict from '../run/__tests__/evidence-verdict.json'
|
||||
import { EvidenceGuessView } from '../run/EvidenceGuess'
|
||||
import { IssuanceBanner } from '../run/AssistantStream'
|
||||
import mdPinned from '../run/__tests__/markdown-pinned.json'
|
||||
@@ -199,6 +200,12 @@ const EV_ENTITY = evidenceEntity.doc as unknown as EvidenceDocData
|
||||
const EV_JUDGE = evidenceJudge.formal.doc as unknown as EvidenceDocData
|
||||
const EV_JUDGE_EXPLORE = evidenceJudge.explore.doc as unknown as EvidenceDocData
|
||||
const EV_JUDGE_PLAIN = evidenceJudge.plain.doc as unknown as EvidenceDocData
|
||||
/**
|
||||
* 裁判拆档(JR):证据相矛盾、证据不足(写明缺什么)、讲方法的句子(只挂表名字段名和整份查询)、裁判模型和写作
|
||||
* 模型相同、模型不在价格表里。探索运行那份的证据图里带着一条拆档之前留下的「证据不支持」(evidence-verdict.json)
|
||||
*/
|
||||
const EV_VERDICT = evidenceVerdict.formal.doc as unknown as EvidenceDocData
|
||||
const EV_VERDICT_EXPLORE = evidenceVerdict.explore.doc as unknown as EvidenceDocData
|
||||
/** 同一份旧契约的出具,去掉位置:老运行就是这样,只能按字符串标 */
|
||||
const LEGACY_LOOSE = {
|
||||
matched: EV_LEGACY.matched.map(({ start: _s, end: _e, ...m }) => m),
|
||||
@@ -339,18 +346,38 @@ function EvidenceOnly() {
|
||||
<EvidenceDoc doc={EV_JUDGE_PLAIN} artifact={evidenceJudge.plain.doc_artifact} runId={evidenceJudge.plain.run_id}
|
||||
label="answer" tally />
|
||||
</div>
|
||||
{/* 裁判拆档:证据相矛盾、证据不足(缺什么)、讲方法的句子挂的 SQL 和字段清单、裁判模型的两条提醒 */}
|
||||
<div id="evidence-verdict" className="rounded-lg border p-3">
|
||||
<div className="mb-1 text-2xs text-faint">正式运行 · 证据相矛盾、证据不足、讲方法的句子(裁判模型和写作模型相同,模型不在价格表里)</div>
|
||||
<EvidenceDoc doc={EV_VERDICT} artifact={evidenceVerdict.formal.doc_artifact} runId={evidenceVerdict.formal.run_id}
|
||||
runClass="formal" label="answer" tally />
|
||||
</div>
|
||||
<div id="evidence-verdict-narrow" className="rounded-lg border bg-panel p-2.5" style={{ width: 360, maxWidth: '100%' }}>
|
||||
<EvidenceDoc doc={EV_VERDICT} artifact={evidenceVerdict.formal.doc_artifact} runId={evidenceVerdict.formal.run_id}
|
||||
runClass="formal" label="answer" dense tally />
|
||||
</div>
|
||||
<div id="evidence-verdict-explore" className="rounded-lg border p-3">
|
||||
<div className="mb-1 text-2xs text-faint">探索运行 · 按需裁判,证据图里有一条拆档之前的「证据不支持」</div>
|
||||
<EvidenceDoc doc={EV_VERDICT_EXPLORE} artifact={evidenceVerdict.explore.doc_artifact}
|
||||
runId={evidenceVerdict.explore.run_id} label="answer" tally />
|
||||
</div>
|
||||
{/* 出具横幅那一行多一段结论句:「结论 4 句(支持 1 · 部分支持 1 · 不支持 1 · 未裁判 1)」 */}
|
||||
<div id="issuance-claims" className="flex flex-col gap-2 rounded-lg border p-3">
|
||||
{/*
|
||||
judge-uncited:开了裁判的文档,没挂依据的那句送了裁判、按判定数在「支持 3」里(或预筛放掉了不数),
|
||||
出具(io.py)照样按没挂依据记 1 句——横幅得另起「没挂依据的结论句 1」,不能被结论句那一段吞掉
|
||||
*/}
|
||||
{/*
|
||||
rework:裁判拆档之后的计数(证据相矛盾、证据不足);insufficient:只有证据不足一种问题,照样给「定位下一处」
|
||||
*/}
|
||||
{([
|
||||
['judged', { total: 4, supported: 1, partial: 1, unsupported: 1, unjudged: 1, uncited: 0 }, null],
|
||||
['cited', { total: 4, supported: 3, partial: 0, unsupported: 0, unjudged: 0, uncited: 1 }, null],
|
||||
['all', { total: 2, supported: 2, partial: 0, unsupported: 0, unjudged: 0, uncited: 0 }, null],
|
||||
['judge-uncited', { total: 3, supported: 3, partial: 0, unsupported: 0, unjudged: 0, uncited: 0 },
|
||||
['judged', { total: 4, supported: 1, partial: 1, contradicted: 0, insufficient: 0, unsupported: 1, unjudged: 1, uncited: 0 }, null],
|
||||
['cited', { total: 4, supported: 3, partial: 0, contradicted: 0, insufficient: 0, unsupported: 0, unjudged: 0, uncited: 1 }, null],
|
||||
['all', { total: 2, supported: 2, partial: 0, contradicted: 0, insufficient: 0, unsupported: 0, unjudged: 0, uncited: 0 }, null],
|
||||
['judge-uncited', { total: 3, supported: 3, partial: 0, contradicted: 0, insufficient: 0, unsupported: 0, unjudged: 0, uncited: 0 },
|
||||
{ policy: 'judge', uncited_claims: 1 }],
|
||||
['rework', { total: 7, supported: 1, partial: 1, contradicted: 2, insufficient: 1, unsupported: 1, unjudged: 1, uncited: 0 }, null],
|
||||
['insufficient', { total: 3, supported: 2, partial: 0, contradicted: 0, insufficient: 1, unsupported: 0, unjudged: 0, uncited: 0 }, null],
|
||||
] as const).map(([key, claims, issued]) => (
|
||||
<div key={key} data-issuance-case={key}>
|
||||
<IssuanceBanner
|
||||
@@ -659,6 +686,7 @@ function Harness() {
|
||||
evidenceQuery,
|
||||
evidenceEntity,
|
||||
evidenceJudge,
|
||||
evidenceVerdict,
|
||||
}
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
|
||||
+191
-13
@@ -14,8 +14,12 @@
|
||||
* 按数值猜的候选用最淡的点状线。
|
||||
*
|
||||
* 四期接上了概率性的几种:结论句的判定是模型给的,只在句末挂一枚小徽标(◆ 有依据、◇ 部分有依据、
|
||||
* ! 证据不支持且整句浅底、? 未裁判),整句的字不画线。判定有两个来源:封存的文档里节点当场判的,
|
||||
* ! 证据相矛盾且整句浅底、○ 证据不足、? 未裁判),整句的字不画线。判定有两个来源:封存的文档里节点当场判的,
|
||||
* 和探索运行里点开再判、封存之后追加的(后者盖过前者,另写「封存后追加」)。
|
||||
*
|
||||
* 裁判拆档(JR):原来的「证据不支持」拆成证据相矛盾(证据和原句冲突)和证据不足(证据里没有相关信息,
|
||||
* 裁判写明缺什么)。证据不足是中性的:不用红,字形用 ○,和未裁判的 ? 分得开。旧文档、旧事件里的
|
||||
* unsupported 原样保留,外观同证据相矛盾,叫法照旧「证据不支持」。
|
||||
*/
|
||||
|
||||
import {
|
||||
@@ -25,8 +29,9 @@ import {
|
||||
import { NONE, formatNumber, shortId } from './format'
|
||||
import type {
|
||||
EvidenceBlock, EvidenceCaliberSource, EvidenceCaliberUpgrade, EvidenceCandidate, EvidenceDocData, EvidenceFieldRef,
|
||||
EvidenceGraph, EvidenceGuess, EvidenceInput, EvidenceLocator, EvidenceSeal, EvidenceSegment, EvidenceSegmentDetail,
|
||||
EvidenceStats, EvidenceStep, EvidenceUnit, EvidenceVerdict, EvidenceViolation, ReviewResult,
|
||||
EvidenceGraph, EvidenceGuess, EvidenceInput, EvidenceJudgeMeta, EvidenceJudgeSummary, EvidenceLocator, EvidenceSeal,
|
||||
EvidenceSegment, EvidenceSegmentDetail, EvidenceStats, EvidenceStep, EvidenceUnit, EvidenceVerdict, EvidenceViolation,
|
||||
ReviewResult,
|
||||
} from '../types'
|
||||
import type { MarkSpec } from '../run/Markdown'
|
||||
|
||||
@@ -80,6 +85,21 @@ export const EVIDENCE_STATE: Record<EvidenceStateCode, EvidenceStateMeta> = {
|
||||
alert: true, phase: 4,
|
||||
hint: '裁判模型认为证据仅支持本句的一部分',
|
||||
},
|
||||
contradicted: {
|
||||
code: 'contradicted', label: EVIDENCE_STATE_LABEL.contradicted, line: 'badge', glyph: '!',
|
||||
color: 'var(--st-failed)', decoration: 'transparent', soft: 'var(--st-failed-soft)',
|
||||
alert: true, phase: 4,
|
||||
hint: '裁判模型认为附带的证据与本句相冲突',
|
||||
},
|
||||
// 证据不足:中性,不用红(不是证据说它错了,是摘录里没有能判断的信息)。字形用 ○,不和未裁判的 ? 混;
|
||||
// 仍算问题(进 n / N),排在证据相矛盾、部分有依据之后
|
||||
insufficient: {
|
||||
code: 'insufficient', label: EVIDENCE_STATE_LABEL.insufficient, line: 'badge', glyph: '○',
|
||||
color: 'var(--st-cancelled)', decoration: 'transparent', soft: 'var(--st-cancelled-soft)',
|
||||
alert: true, phase: 4,
|
||||
hint: '裁判模型认为附带的证据中没有判断本句所需的信息,既不能证实也不能否定',
|
||||
},
|
||||
// 拆档之前的取值:旧文档、旧事件里保留原样。外观同证据相矛盾
|
||||
unsupported: {
|
||||
code: 'unsupported', label: EVIDENCE_STATE_LABEL.unsupported, line: 'badge', glyph: '!',
|
||||
color: 'var(--st-failed)', decoration: 'transparent', soft: 'var(--st-failed-soft)',
|
||||
@@ -129,6 +149,19 @@ export const EVIDENCE_STATE: Record<EvidenceStateCode, EvidenceStateMeta> = {
|
||||
/** 图例、检查脚本按这个顺序列 */
|
||||
export const EVIDENCE_STATES = Object.keys(EVIDENCE_STATE) as EvidenceStateCode[]
|
||||
|
||||
/**
|
||||
* n / N 跳转按两轮走:先走第 1 轮(无证据、可疑名称、证据相矛盾、旧的证据不支持、部分有依据),再走第 2 轮
|
||||
* (证据不足),每一轮里按正文顺序。不进跳转的是 0
|
||||
*/
|
||||
export function alertTier(state: EvidenceStateCode | null | undefined): 0 | 1 | 2 {
|
||||
if (!state || !EVIDENCE_STATE[state].alert) return 0
|
||||
return state === 'insufficient' ? 2 : 1
|
||||
}
|
||||
|
||||
/** 证据和原句冲突的两种(新取值、拆档之前的旧取值):整句铺浅底 */
|
||||
export const conflicting = (state: EvidenceStateCode | null | undefined): boolean =>
|
||||
state === 'contradicted' || state === 'unsupported'
|
||||
|
||||
/**
|
||||
* 片段在正文里的状态。文字、结构片段(行首符号、表格竖线)是 null:不画线、不进键盘顺序。
|
||||
* 后端的 probabilistic 在裁判给出结论之前按「未裁判」画
|
||||
@@ -543,7 +576,7 @@ export function tallySummary(t: EvidenceTally, keys: boolean): string {
|
||||
t.unverified ? `${formatNumber(t.unverified)} 个名称${EVIDENCE_STATE.unverified.label}` : '',
|
||||
t.structural ? EVIDENCE_TEXT.structuralCount(t.structural) : '',
|
||||
t.noSegment ? EVIDENCE_TEXT.noSegmentCount(t.noSegment) : '',
|
||||
keys ? (t.claims?.unsupported || t.claims?.partial ? JUDGE_TEXT.keysHint : EVIDENCE_TEXT.keysHint) : '',
|
||||
keys ? (claimProblems(t.claims) ? JUDGE_TEXT.keysHint : EVIDENCE_TEXT.keysHint) : '',
|
||||
].filter(Boolean).join('。')
|
||||
}
|
||||
|
||||
@@ -843,8 +876,11 @@ export function stampCounts(stats: EvidenceStats | null | undefined, claims?: st
|
||||
// 四期:结论句裁判
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/** 判过了的四种(不含未裁判):同后端 judge.JUDGED。判过的不再给「请模型判断这句」 */
|
||||
const JUDGED = new Set(['supported', 'partial', 'unsupported', 'not_a_claim'])
|
||||
/**
|
||||
* 判过了的几种(不含未裁判):同后端 judge.JUDGED,另加拆档之前的 unsupported(旧文档、旧事件里还有)。
|
||||
* 判过的不再给「请模型判断这句」
|
||||
*/
|
||||
const JUDGED = new Set(['supported', 'partial', 'contradicted', 'insufficient', 'unsupported', 'not_a_claim'])
|
||||
/** 触顶的四个上限:同后端 judge.LIMITS,这几种没判的写「已到上限」和怎么调 */
|
||||
export const JUDGE_LIMITS: readonly string[] = ['max_claims', 'max_cost_usd', 'daily_max_usd', 'timeout_s']
|
||||
|
||||
@@ -862,12 +898,73 @@ export function verdictState(v: Pick<EvidenceVerdict, 'status'> | null | undefin
|
||||
switch (v?.status) {
|
||||
case 'supported': return 'supported'
|
||||
case 'partial': return 'partial'
|
||||
case 'contradicted': return 'contradicted'
|
||||
case 'insufficient': return 'insufficient'
|
||||
case 'unsupported': return 'unsupported'
|
||||
case 'unjudged': return 'unjudged'
|
||||
default: return null
|
||||
}
|
||||
}
|
||||
|
||||
/** 证据不足时缺的是什么(裁判给的);别的判定、没写的是空串 */
|
||||
export function verdictMissing(v: Pick<EvidenceVerdict, 'status' | 'missing'> | null | undefined): string {
|
||||
return v?.status === 'insufficient' && typeof v.missing === 'string' ? v.missing.trim() : ''
|
||||
}
|
||||
|
||||
/** 结论句的计数里有没有要提醒的:证据相矛盾、旧的证据不支持、部分有依据、证据不足(横幅、证据条的「定位下一处」) */
|
||||
export function claimProblems(c: ClaimTallyCounts | null | undefined): number {
|
||||
if (!c) return 0
|
||||
return (c.contradicted ?? 0) + (c.unsupported ?? 0) + (c.partial ?? 0) + (c.insufficient ?? 0)
|
||||
}
|
||||
|
||||
/** 计数表里认的几种判定(「不是结论句」不算进总数) */
|
||||
const COUNTED = ['supported', 'partial', 'contradicted', 'insufficient', 'unsupported', 'unjudged'] as const
|
||||
|
||||
/**
|
||||
* 按判定分好的句数(report.checked 的 judge.counts、文档 stats 里裁判那几个键、出具的 claims.counts)→ 横幅那种
|
||||
* 计数:总数不算「不是结论句」,旧数据的 unsupported 照样计入。一个判定都没有时总数是 0
|
||||
*/
|
||||
export function claimCountsOf(counts: Record<string, unknown> | null | undefined): ClaimTallyCounts {
|
||||
const n = (k: string) => {
|
||||
const v = counts?.[k]
|
||||
return typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : 0
|
||||
}
|
||||
const c: ClaimTallyCounts = { total: 0, supported: 0, partial: 0, contradicted: 0, insufficient: 0, unsupported: 0,
|
||||
unjudged: 0, uncited: 0 }
|
||||
for (const k of COUNTED) {
|
||||
c[k] = n(k)
|
||||
c.total += c[k]
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
/**
|
||||
* 这条判定该带的两条提醒:裁判模型和写作模型相同、模型不在价格表里(金额上限对它不生效)。只对模型判过的判定。
|
||||
* 按从近到远取:判定自己带着的 → 封存之后追加的看这一次按需裁判的答复、再看证据图里最近一次按需裁判
|
||||
* (reports[].judge_meta);节点里当场判的看报告文档的 judge。都没说的不提醒
|
||||
*/
|
||||
export function judgeFlags(v: EvidenceVerdict | null | undefined, from: {
|
||||
doc?: Pick<EvidenceJudgeSummary, 'same_model' | 'priced' | 'writer_model' | 'model'> | null
|
||||
reply?: { same_model?: unknown; priced?: unknown; writer_model?: unknown; model?: unknown } | null
|
||||
meta?: EvidenceJudgeMeta | null
|
||||
} = {}): { sameModel: boolean; unpriced: boolean; writer: string | null; model: string | null } {
|
||||
const none = { sameModel: false, unpriced: false, writer: null, model: null }
|
||||
if (!v || !isJudged(v)) return none
|
||||
const layers = (v.post_seal ? [v, from.reply, from.meta] : [v, from.doc]).filter(Boolean) as Record<string, unknown>[]
|
||||
const pick = <T,>(key: string, ok: (x: unknown) => x is T): T | undefined => {
|
||||
for (const l of layers) if (ok(l[key])) return l[key] as T
|
||||
return undefined
|
||||
}
|
||||
const isBool = (x: unknown): x is boolean => typeof x === 'boolean'
|
||||
const isText = (x: unknown): x is string => typeof x === 'string' && !!x
|
||||
return {
|
||||
sameModel: pick('same_model', isBool) === true,
|
||||
unpriced: pick('priced', isBool) === false,
|
||||
writer: pick('writer_model', isText) ?? null,
|
||||
model: (isText(v.judge) ? v.judge : pick('model', isText)) ?? null,
|
||||
}
|
||||
}
|
||||
|
||||
/** 一句的判定:封存之后按需追加的盖过文档里的(探索运行里文档记的是「未裁判 · 按需」) */
|
||||
export function unitVerdict(
|
||||
unit: Pick<EvidenceUnit, 'id' | 'verdict'>, overlay?: Record<string, EvidenceVerdict> | null,
|
||||
@@ -891,15 +988,17 @@ export function claimCounts(
|
||||
doc: Pick<EvidenceDocData, 'blocks' | 'judge'>, overlay?: Record<string, EvidenceVerdict> | null,
|
||||
): ClaimTallyCounts | null {
|
||||
const judged = !!doc.judge && typeof doc.judge === 'object'
|
||||
const c: ClaimTallyCounts = { total: 0, supported: 0, partial: 0, unsupported: 0, unjudged: 0, uncited: 0 }
|
||||
const c: ClaimTallyCounts = { total: 0, supported: 0, partial: 0, contradicted: 0, insufficient: 0, unsupported: 0,
|
||||
unjudged: 0, uncited: 0 }
|
||||
let seen = judged
|
||||
for (const block of doc.blocks ?? []) {
|
||||
for (const unit of block.units ?? []) {
|
||||
const v = unitVerdict(unit, overlay)
|
||||
if (v) seen = true
|
||||
if (v) {
|
||||
if (v.status === 'supported' || v.status === 'partial' || v.status === 'unsupported' || v.status === 'unjudged') {
|
||||
c[v.status] += 1
|
||||
const k = (COUNTED as readonly string[]).includes(v.status) ? v.status as typeof COUNTED[number] : null
|
||||
if (k) {
|
||||
c[k] += 1
|
||||
c.total += 1
|
||||
}
|
||||
continue
|
||||
@@ -932,12 +1031,13 @@ const clip = (text: string, n = 40) => (text.length > n ? `${text.slice(0, n - 1
|
||||
|
||||
/**
|
||||
* 句末徽标的 aria-label:句子、判定都写全,封存后追加的另说。「结论句「增长主要来自新客首单…」,
|
||||
* 模型判断:证据不支持」;到上限没判的说「未裁判:已到上限」
|
||||
* 模型判断:证据相矛盾」;证据不足的接着说缺什么;到上限没判的说「未裁判:已到上限」
|
||||
*/
|
||||
export function claimLabel(unit: Pick<EvidenceUnit, 'segments'>, v: EvidenceVerdict): string {
|
||||
const state = verdictState(v)
|
||||
const said = state ? EVIDENCE_STATE[state].label : JUDGE_TEXT.notClaim
|
||||
const why = limitOf(v) ? `${said}:${JUDGE_TEXT.limit}` : said
|
||||
const missing = verdictMissing(v)
|
||||
const why = limitOf(v) ? `${said}:${JUDGE_TEXT.limit}` : missing ? `${said},${JUDGE_TEXT.missing(missing)}` : said
|
||||
return JUDGE_TEXT.badgeLabel(clip(unitText(unit).trim()), why, !!v.post_seal)
|
||||
}
|
||||
|
||||
@@ -954,6 +1054,7 @@ function asVerdict(v: unknown, fallback: { model?: unknown; postSeal: boolean })
|
||||
post_seal: typeof o.post_seal === 'boolean' ? o.post_seal : fallback.postSeal,
|
||||
used: Array.isArray(o.used) ? o.used.map(String) : undefined,
|
||||
reason: typeof o.reason === 'string' ? o.reason : undefined,
|
||||
missing: typeof o.missing === 'string' && o.missing.trim() ? o.missing : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1007,6 +1108,68 @@ export function rewriteOf(doc: Pick<EvidenceDocData, 'judge'>, uid: string):
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* 讲方法、讲结构的句子(JR 第 3 条):写作者只挂了表名、字段名或整份查询([[see:Qn]]),没挂数字、值、口径卡、
|
||||
* 引文。这类句子的「挂的依据」下直接列出对应的 SQL 和字段清单——裁判看的就是这些,读的人也该看得到。
|
||||
*
|
||||
* 返回要列的东西:表(字段清单)、字段(类型)各自在句中的片段(字段清单、类型从这个片段的证据链取),
|
||||
* 要列 SQL 的查询(直接挂的在前,再补表名字段名出现过的查询,最多 BASIS_QUERIES 个,多的只写个数)。
|
||||
* 挂了别的依据、或者一个表名字段名和查询都没挂的,返回 null(照旧只列编号)
|
||||
*/
|
||||
export const BASIS_QUERIES = 3
|
||||
export interface ClaimBasis {
|
||||
tables: { alias: string; name: string; seg?: string }[]
|
||||
columns: { alias: string; name: string; seg?: string }[]
|
||||
queries: string[]
|
||||
more: number
|
||||
}
|
||||
export function claimBasis(
|
||||
unit: Pick<EvidenceUnit, 'cites' | 'see' | 'segments'>, doc: Pick<EvidenceDocData, 'catalog' | 'blocks'>,
|
||||
): ClaimBasis | null {
|
||||
const catalog = doc.catalog ?? {}
|
||||
const cites = (unit.cites ?? []).filter((a): a is string => typeof a === 'string' && !!a)
|
||||
if (!cites.length) return null
|
||||
const entity = (kind: unknown) => kind === 'table' || kind === 'column'
|
||||
// 句中写作者标的引用(自动链接的名字不算依据):数字、值、单元格、口径卡、引文都算「挂了数据」
|
||||
if ((unit.segments ?? []).some((s) => s.cite && !s.auto && s.cite.status === 'resolved' && !entity(s.cite.kind))) return null
|
||||
if ((unit.see ?? []).some((c) => c?.status === 'resolved' && !entity(c.kind) && c.kind !== 'query')) return null
|
||||
const out: ClaimBasis = { tables: [], columns: [], queries: [], more: 0 }
|
||||
const segOf = (alias: string): string | undefined => {
|
||||
const hit = (u: Pick<EvidenceUnit, 'segments'>) =>
|
||||
(u.segments ?? []).find((s) => s.cite?.alias === alias && s.state === 'deterministic')?.id
|
||||
return hit(unit) ?? (doc.blocks ?? []).flatMap((b) => b.units ?? []).map(hit).find(Boolean)
|
||||
}
|
||||
const nameOf = (alias: string, entry: Record<string, any> | undefined) => {
|
||||
const loc = entry?.locator ?? {}
|
||||
if (entry?.kind === 'column' && loc.table && loc.column) return `${loc.table}.${loc.column}`
|
||||
return typeof entry?.name === 'string' && entry.name ? entry.name : alias.replace(/^[tc]:/, '')
|
||||
}
|
||||
const queries: string[] = []
|
||||
for (const alias of cites) {
|
||||
const entry = catalog[alias]
|
||||
if (entry?.kind === 'table') out.tables.push({ alias, name: nameOf(alias, entry), seg: segOf(alias) })
|
||||
else if (entry?.kind === 'column') out.columns.push({ alias, name: nameOf(alias, entry), seg: segOf(alias) })
|
||||
else if (entry?.kind === 'query') queries.push(alias)
|
||||
else return null
|
||||
}
|
||||
for (const e of [...out.tables, ...out.columns]) {
|
||||
for (const q of Array.isArray(catalog[e.alias]?.queries) ? catalog[e.alias].queries : []) {
|
||||
if (typeof q === 'string' && catalog[q]?.kind === 'query' && !queries.includes(q)) queries.push(q)
|
||||
}
|
||||
}
|
||||
out.queries = queries.slice(0, BASIS_QUERIES)
|
||||
out.more = Math.max(0, queries.length - BASIS_QUERIES)
|
||||
return out
|
||||
}
|
||||
|
||||
/** 查询快照工件里的 SQL:快照本身带 sql;工具调用的快照({tool, args, result})在 args 或 result 里 */
|
||||
export function sqlOf(content: unknown): string | null {
|
||||
if (!content || typeof content !== 'object') return null
|
||||
const o = content as { sql?: unknown; args?: { sql?: unknown }; result?: { sql?: unknown } }
|
||||
const sql = [o.sql, o.args?.sql, o.result?.sql].find((x) => typeof x === 'string' && x.trim())
|
||||
return typeof sql === 'string' ? sql : null
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 旧运行的猜测
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -1082,11 +1245,22 @@ export interface AuditRow {
|
||||
sentence: string
|
||||
/** 这件证据在不在封存范围内(封存核对也通过);没有证据的是 null */
|
||||
sealed: boolean | null
|
||||
/** 结论句那几行:是哪一句(正文里有句末徽标时点这一行打开它的「模型的解释」) */
|
||||
unit?: string
|
||||
}
|
||||
|
||||
const GROUP_OF: Record<EvidenceStateCode, AuditGroup> = {
|
||||
deterministic: 'cited', none: 'none', suspect: 'suspicious', unverified: 'suspicious', candidate: 'candidate',
|
||||
supported: 'cited', partial: 'none', unsupported: 'none', unjudged: 'cited', connective: 'cited',
|
||||
supported: 'cited', partial: 'none', contradicted: 'none', insufficient: 'none', unsupported: 'none', unjudged: 'cited',
|
||||
connective: 'cited',
|
||||
}
|
||||
/** 审计行带的判定 → 行的状态:有问题的几种才有自己的行,认不出的交给后面按 state 认 */
|
||||
const claimRowState = (status: unknown): EvidenceStateCode | undefined =>
|
||||
status === 'contradicted' || status === 'insufficient' || status === 'unsupported' || status === 'partial' ? status : undefined
|
||||
/** 审计行的 issue → 结论句的判定(后端按约定给证据相矛盾、证据不足的结论句各一行;旧取值也认) */
|
||||
const CLAIM_ISSUE: Record<string, EvidenceStateCode> = {
|
||||
contradicted_claim: 'contradicted', insufficient_claim: 'insufficient', unsupported_claim: 'unsupported',
|
||||
partial_claim: 'partial',
|
||||
}
|
||||
const AUDIT_GROUP_SET = new Set<string>(['cited', 'none', 'suspicious', 'candidate'])
|
||||
|
||||
@@ -1111,7 +1285,10 @@ export function auditFromApi(body: unknown): AuditRow[] {
|
||||
for (const [ri, r] of (Array.isArray(g?.rows) ? g.rows : []).entries()) {
|
||||
if (!r || typeof r !== 'object') continue
|
||||
const kind = String(r.kind ?? '')
|
||||
const state = segmentState({ kind, state: r.state ?? 'none', issue: r.issue ?? undefined })
|
||||
// 结论句的判定行:按 issue 认成对应的判定(外观、叫法同句末徽标);issue 认不出时看行上带的 verdict
|
||||
const state = (kind === 'claim' && typeof r.issue === 'string' ? CLAIM_ISSUE[r.issue] : undefined)
|
||||
?? (kind === 'claim' && r.verdict && typeof r.verdict === 'object' ? claimRowState(r.verdict.status) : undefined)
|
||||
?? segmentState({ kind, state: r.state ?? 'none', issue: r.issue ?? undefined })
|
||||
?? (r.group === 'candidate' ? 'candidate' : 'none')
|
||||
const group: AuditGroup = AUDIT_GROUP_SET.has(r.group) ? r.group : AUDIT_GROUP_SET.has(g?.key) ? g.key : GROUP_OF[state]
|
||||
const report = String(r.report ?? r.field ?? '')
|
||||
@@ -1126,6 +1303,7 @@ export function auditFromApi(body: unknown): AuditRow[] {
|
||||
ref: typeof r.ref === 'string' ? r.ref : undefined,
|
||||
sentence: String(r.sentence ?? '').trim(),
|
||||
sealed: typeof r.sealed === 'boolean' ? r.sealed : null,
|
||||
...(kind === 'claim' && typeof r.unit === 'string' && r.unit ? { unit: r.unit } : {}),
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
+52
-10
@@ -155,13 +155,16 @@ export const APPROVAL_POLICY_LABEL: Record<'dangerous' | 'always' | 'never', str
|
||||
* 可点击证据:片段状态的叫法。正文里片段的 aria-label、面板标题、图例都用这一份。
|
||||
* 外观(线型、字形、颜色)在 lib/evidence.ts,和这里一一对应。
|
||||
*
|
||||
* 概率性的四种(四期的结论句裁判)挂在句末的徽标上:有依据、部分有依据、证据不支持都是模型的判断,
|
||||
* 概率性的几种(四期的结论句裁判)挂在句末的徽标上:有依据、部分有依据、证据相矛盾、证据不足都是模型的判断,
|
||||
* 叫法里写明「模型判断」;未裁判不带「有引用」——没挂依据、只有方向词的结论句也会送裁判、也会没判。
|
||||
* 证据不支持是裁判拆档之前的取值:已封存的文档、已有的事件里保留原样,照旧这样叫(新判的不再出现)。
|
||||
*/
|
||||
export const EVIDENCE_STATE_LABEL = {
|
||||
deterministic: '有出处',
|
||||
supported: '模型判断:有依据',
|
||||
partial: '模型判断:部分有依据',
|
||||
contradicted: '模型判断:证据相矛盾',
|
||||
insufficient: '模型判断:证据不足',
|
||||
unsupported: '模型判断:证据不支持',
|
||||
unjudged: '未裁判',
|
||||
none: '无证据',
|
||||
@@ -313,6 +316,10 @@ export const EVIDENCE_TEXT = {
|
||||
checked: (schemas: number, queries: number) =>
|
||||
`已核对 ${formatNumber(schemas)} 份表结构快照、${formatNumber(queries)} 次查询`,
|
||||
tableColumns: (n: number, view: boolean) => `${view ? '视图' : '表'} · ${formatNumber(n)} 个字段`,
|
||||
/** 表名实体步骤的字段清单(来自封存范围内的表结构快照,最多列 60 个,遮罩的列不列入) */
|
||||
fields: (n: number) => `字段清单(${formatNumber(n)} 个)`,
|
||||
fieldsMore: (n: number) => `另有 ${formatNumber(n)} 个字段未列出`,
|
||||
fieldsMasked: '部分字段已按数据源的遮罩设置隐藏,未列出',
|
||||
columnTypes: (types: Record<string, string>) =>
|
||||
`各表的类型:${Object.entries(types).map(([t, v]) => `${t} ${v}`).join('、')}`,
|
||||
quoteBad: '按记录的位置从原文中截取的内容与这句引文不一致:原文可能已被修改',
|
||||
@@ -342,6 +349,11 @@ export interface ClaimTallyCounts {
|
||||
total: number
|
||||
supported: number
|
||||
partial: number
|
||||
/** 证据和原句冲突 */
|
||||
contradicted: number
|
||||
/** 证据里没有判断所需的信息 */
|
||||
insufficient: number
|
||||
/** 拆档之前的取值(旧文档、旧事件),照旧计入 */
|
||||
unsupported: number
|
||||
/** 送了裁判、没判成(到上限、调用失败)或还没请模型判断的 */
|
||||
unjudged: number
|
||||
@@ -356,8 +368,9 @@ export interface ClaimTallyCounts {
|
||||
export function claimTally(c: ClaimTallyCounts): string {
|
||||
if (!c.total) return ''
|
||||
const parts = [
|
||||
['有依据', c.supported], ['部分有依据', c.partial], ['证据不支持', c.unsupported], ['未裁判', c.unjudged], ['无证据', c.uncited],
|
||||
].filter(([, n]) => (n as number) > 0).map(([k, n]) => `${k} ${formatNumber(n as number)}`)
|
||||
['有依据', c.supported], ['部分有依据', c.partial], ['证据相矛盾', c.contradicted], ['证据不支持', c.unsupported],
|
||||
['证据不足', c.insufficient], ['未裁判', c.unjudged], ['无证据', c.uncited],
|
||||
].filter(([, n]) => typeof n === 'number' && n > 0).map(([k, n]) => `${k} ${formatNumber(n as number)}`)
|
||||
return `结论 ${formatNumber(c.total)} 句${parts.length ? `(${parts.join(' · ')})` : ''}`
|
||||
}
|
||||
|
||||
@@ -368,8 +381,11 @@ export function claimTally(c: ClaimTallyCounts): string {
|
||||
export const JUDGE_TEXT = {
|
||||
section: '模型的解释',
|
||||
claim: '结论句',
|
||||
/** 读屏摘要末尾的操作说明:有证据不支持、部分支持的结论句时 n 也跳到它们的句末徽标 */
|
||||
keysHint: '用左右方向键逐个查看,上下方向键按句切换,n 跳到下一处无证据或证据不支持的句子,回车打开证据,Esc 关闭',
|
||||
/**
|
||||
* 读屏摘要末尾的操作说明:结论句有问题(证据相矛盾、部分有依据、证据不足)时 n 也跳到它们的句末徽标。
|
||||
* 证据不足的排在其余问题之后
|
||||
*/
|
||||
keysHint: '用左右方向键逐个查看,上下方向键按句切换,n 跳到下一处无证据或证据有问题的句子(证据不足的排在最后),回车打开证据,Esc 关闭',
|
||||
/** 面板里判断的徽标:谁判的、而且不是确定的 */
|
||||
badge: (model: string | null | undefined) => `模型判断 · ${model || '裁判模型'} · 非确定`,
|
||||
postSeal: '封存后追加',
|
||||
@@ -389,11 +405,30 @@ export const JUDGE_TEXT = {
|
||||
notClaim: '模型判断:不是结论句',
|
||||
ask: '请模型判断本句',
|
||||
askAgain: '再次请模型判断',
|
||||
/** 封存后追加的判定早于当前的裁判规则(片段接口的 on_demand.reason 为 outdated):旁边注明,按钮照常给 */
|
||||
outdated: '按旧规则判定',
|
||||
asking: '正在请模型判断…',
|
||||
askHint: '探索运行按需裁判:每次点击裁判一句,费用计入单次点击上限和每日上限',
|
||||
notAsked: '尚未请模型判断本句',
|
||||
screened: '预筛判定本句不陈述数据事实(短句或过渡语),未送裁判',
|
||||
noPrice: '裁判模型不在价格目录中,无法按 token 数估算金额:金额上限对其不生效',
|
||||
/** 证据不足时缺的是什么(裁判给的,如「SQL」「字段清单」):面板、句末徽标的悬停说明和读屏都写 */
|
||||
missingLead: '缺少:',
|
||||
missing: (what: string) => `缺少:${what}`,
|
||||
/** 裁判模型的两条提醒:判定照常给出,读的人要知道分量 */
|
||||
sameModel: '裁判模型和写作模型相同,结果仅供参考',
|
||||
sameModelTitle: (model: string) => `裁判模型与撰写这份报告的模型都是 ${model}:同一模型较难发现自身的错误`,
|
||||
noPrice: '该模型不在价格表中,金额上限不生效',
|
||||
noPriceTitle: '无法按 token 数估算这个模型的费用,裁判的金额上限(每份报告、每次点击、每日)对它不起作用;句数和时长上限照常生效',
|
||||
/** 讲方法、讲结构的句子(只挂了表名、字段名、整份查询):「挂的依据」下直接列出 SQL 和字段清单 */
|
||||
basisSql: (alias: string) => `查询 ${alias} 的 SQL`,
|
||||
basisFields: (table: string) => `表 ${table} 的字段清单`,
|
||||
basisFieldsCount: (table: string, n: number) => `表 ${table} 的字段清单(${formatNumber(n)} 个)`,
|
||||
basisColumns: '字段类型',
|
||||
basisPending: '正在加载 SQL 和字段清单…',
|
||||
sqlMissing: '未能获取这次查询的 SQL',
|
||||
fieldsMissing: '未能获取字段清单',
|
||||
basisNoRun: '这份报告不属于任何运行,无法获取 SQL 和字段清单',
|
||||
basisMoreQueries: (n: number) => `另有 ${formatNumber(n)} 次查询,点开句中的表名查看`,
|
||||
limit: '已达上限',
|
||||
/** 触顶之后怎么调。按需裁判(每次点击)和正式运行(每份报告)调的地方不一样 */
|
||||
limitHow: {
|
||||
@@ -437,10 +472,14 @@ export const JUDGE_FIELD_LABEL: Record<string, string> = {
|
||||
max_claims: '最多裁判句数',
|
||||
max_cost_usd: '金额上限(美元)',
|
||||
timeout_s: '时长上限(秒)',
|
||||
rewrite_once: '证据不支持的句子退回改写一次',
|
||||
on_unsupported: '证据不支持时',
|
||||
rewrite_once: '证据相矛盾或不足的句子退回改写一次',
|
||||
// 键名仍是 on_unsupported(兼容已有配置);裁判拆档后它管的是「证据相矛盾」(旧取值证据不支持照旧按它判),
|
||||
// 证据不足的句子最多降档
|
||||
on_unsupported: '证据相矛盾时',
|
||||
}
|
||||
/** judge.on_unsupported:正式运行里证据不支持的结论句怎么判档(探索运行只标注) */
|
||||
/** judge.on_unsupported 的说明:检查器里选项下面那一行 */
|
||||
export const JUDGE_ON_UNSUPPORTED_HINT = '仅对正式运行生效;证据不足的句子最多降档,不会因此不予出具。探索运行只做标注,不拦截'
|
||||
/** judge.on_unsupported:正式运行里证据相矛盾的结论句怎么判档(探索运行只标注) */
|
||||
export const JUDGE_ON_UNSUPPORTED_LABEL: Record<string, string> = {
|
||||
degrade: '出具降档',
|
||||
withhold: '不予出具',
|
||||
@@ -459,6 +498,9 @@ export const JUDGE_SETTING_TEXT = {
|
||||
modelDefault: '留空:用接入的默认模型',
|
||||
modelFollow: '留空:跟随助手的模型',
|
||||
differ: '建议与撰写报告的模型不同:由同一模型审核自身输出,不易发现其中的错误',
|
||||
/** 接入和模型都没填:后端依次用助手的模型、默认接入。醒目地说一句,并给出建议 */
|
||||
notSet: '未单独配置,将使用助手的模型',
|
||||
notSetAdvice: '建议配置一个与撰写报告的模型不同、能力更强的模型:同一模型审核自身输出时,结果仅供参考',
|
||||
limits: '上限(每一项都可以设成不限)',
|
||||
reportClaims: '每份报告最多裁判句数',
|
||||
reportCost: '每份报告的金额上限(美元)',
|
||||
@@ -532,7 +574,7 @@ export const EVIDENCE_AUDIT_TEXT = {
|
||||
candidate: '按数值猜测',
|
||||
} as Record<string, string>,
|
||||
groupHint: {
|
||||
none: '裸数字、无法解析的引用、未附依据的结论句',
|
||||
none: '裸数字、无法解析的引用、未附依据或模型判为证据有问题的结论句',
|
||||
suspicious: '表名、字段名在本次运行的表结构和查询中找不到',
|
||||
cited: '系统从证据中取值并核对过的片段',
|
||||
candidate: '按数值猜测的可能来源,不能作为证据,默认收起',
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react'
|
||||
import type { KeyboardEvent as ReactKeyboardEvent, ReactNode } from 'react'
|
||||
import { Navigate, useParams } from 'react-router-dom'
|
||||
import {
|
||||
Check, Cpu, Download, KeyRound, Monitor, Moon, Plug, Plus, Settings as SettingsIcon, Sun, X,
|
||||
AlertTriangle, Check, Cpu, Download, KeyRound, Monitor, Moon, Plug, Plus, Settings as SettingsIcon, Sun, X,
|
||||
} from 'lucide-react'
|
||||
import clsx from 'clsx'
|
||||
import { api } from '../api/client'
|
||||
@@ -777,6 +777,8 @@ function PrefsTab() {
|
||||
const judgeProviderMissing = !!cur.judgeProvider && providers.length > 0 && !judgeProvider
|
||||
const judgeModelName = cur.judgeModel.trim()
|
||||
const judgeByModel = !cur.judgeProvider && !!judgeModelName
|
||||
// 裁判模型没有单独配置(接入、模型都留空):后端依次用助手的模型、默认接入
|
||||
const judgeNotSet = !cur.judgeProvider && !judgeModelName
|
||||
const judgeOwner = judgeByModel ? providerOfModel(providers, judgeModelName) : undefined
|
||||
const judgeByModelHint = judgeByModel && providers.length > 0
|
||||
? judgeByModelText('settings', judgeModelName, judgeOwner && { name: judgeOwner.provider.name, enabled: judgeOwner.enabled },
|
||||
@@ -940,7 +942,21 @@ function PrefsTab() {
|
||||
<SectionBar title={JUDGE_SETTING_TEXT.label} hint={JUDGE_SETTING_TEXT.hint} />
|
||||
<div role="group" aria-labelledby="pref-judge-model-label" aria-describedby="pref-judge-model-hint" data-judge-model>
|
||||
<div id="pref-judge-model-label" className="text-xs font-medium">裁判模型</div>
|
||||
<p id="pref-judge-model-hint" className="mb-2 mt-0.5 text-2xs leading-relaxed text-faint">{JUDGE_SETTING_TEXT.differ}</p>
|
||||
{judgeNotSet ? (
|
||||
// 接入和模型都没填:裁判会用助手的模型(往往就是写报告的那个)。醒目地说,并给出建议;
|
||||
// 填了任何一项就换回平常那句建议
|
||||
<div id="pref-judge-model-hint" role="note" data-judge-not-set=""
|
||||
className="mb-2 mt-1 flex items-start gap-1.5 rounded border-l-2 py-0.5 pl-2 text-2xs leading-relaxed"
|
||||
style={{ borderColor: 'var(--st-waiting)' }}>
|
||||
<AlertTriangle size={12} aria-hidden className="mt-0.5 shrink-0" style={{ color: 'var(--st-waiting)' }} />
|
||||
<span>
|
||||
<span className="font-medium" data-judge-not-set-text="">{JUDGE_SETTING_TEXT.notSet}</span>
|
||||
<span className="block text-dim" data-judge-not-set-advice="">{JUDGE_SETTING_TEXT.notSetAdvice}</span>
|
||||
</span>
|
||||
</div>
|
||||
) : (
|
||||
<p id="pref-judge-model-hint" className="mb-2 mt-0.5 text-2xs leading-relaxed text-faint">{JUDGE_SETTING_TEXT.differ}</p>
|
||||
)}
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<Field label={JUDGE_SETTING_TEXT.provider} htmlFor="pref-judge-provider"
|
||||
error={judgeProviderMissing ? `模型接入「${cur.judgeProvider}」不存在:裁判调用将失败,所有结论句记为未裁判` : undefined}
|
||||
|
||||
@@ -8,8 +8,8 @@ import { ApiError, api } from '../../api/client'
|
||||
import { isUpgradeAdvice } from '../../canvas/issues'
|
||||
import { ErrorState, Skeleton, Spinner, StatusBadge, rovingTarget, toast, useRadioGroup } from '../../components/ui'
|
||||
import {
|
||||
EVIDENCE_STATE, PROBLEM_GROUPS, auditCsv, auditFromApi, auditRows, groupRows, guessRows, guessesOf, issuanceMarks,
|
||||
segmentState, type AuditFilter, type AuditGroup, type AuditRow,
|
||||
EVIDENCE_STATE, PROBLEM_GROUPS, auditCsv, auditFromApi, auditRows, graphVerdicts, groupRows, guessRows, guessesOf,
|
||||
issuanceMarks, segmentState, unitVerdict, verdictState, type AuditFilter, type AuditGroup, type AuditRow,
|
||||
} from '../../lib/evidence'
|
||||
import { formatNumber } from '../../lib/format'
|
||||
import { EVIDENCE_AUDIT_TEXT as T, UPGRADE_TEXT } from '../../lib/terms'
|
||||
@@ -87,20 +87,28 @@ export function EvidencePane({ run, output, labelOf, refreshKey }: {
|
||||
|
||||
// 哪些行能在正文里打开:`报告:片段` 的集合,一份文档算一次(长报告几千个片段,不能每行各扫一遍)。
|
||||
// 只收有状态的片段,和 EvidenceDoc 能打开的是同一批:违规行指着的文字片段(粗体、链接里的可疑名字)、
|
||||
// 结构片段(列表序号 100. 里的数字)在正文里没有能点的地方,画成按钮就是点了没反应
|
||||
// 结构片段(列表序号 100. 里的数字)在正文里没有能点的地方,画成按钮就是点了没反应。
|
||||
// 结论句的行(证据相矛盾、证据不足……)打开的是这一句的句末徽标(`报告:claim:句子`):句子有判定(封存的、
|
||||
// 证据图里封存后追加的)才有徽标
|
||||
const openable = useMemo(() => {
|
||||
const keys = new Set<string>()
|
||||
for (const r of reports) {
|
||||
const doc = docOf(r.node_id)
|
||||
for (const b of doc?.blocks ?? []) for (const u of b.units ?? []) for (const seg of u.segments ?? []) {
|
||||
if (segmentState(seg)) keys.add(`${r.node_id}:${seg.id}`)
|
||||
const late = graphVerdicts(graph, r.node_id)
|
||||
for (const b of doc?.blocks ?? []) for (const u of b.units ?? []) {
|
||||
for (const seg of u.segments ?? []) if (segmentState(seg)) keys.add(`${r.node_id}:${seg.id}`)
|
||||
if (verdictState(unitVerdict(u, late))) keys.add(`${r.node_id}:claim:${u.id}`)
|
||||
}
|
||||
}
|
||||
return keys
|
||||
}, [reports, docOf])
|
||||
const canOpen = useCallback((row: AuditRow) => !!row.seg && openable.has(`${row.report}:${row.seg}`), [openable])
|
||||
}, [reports, docOf, graph])
|
||||
const canOpen = useCallback((row: AuditRow) => {
|
||||
const key = openKey(row)
|
||||
return !!key && openable.has(`${row.report}:${key}`)
|
||||
}, [openable])
|
||||
const openRow = useCallback((row: AuditRow) => {
|
||||
if (row.seg) handles.current.get(row.report)?.open(row.seg)
|
||||
const key = openKey(row)
|
||||
if (key) handles.current.get(row.report)?.open(key)
|
||||
}, [])
|
||||
|
||||
const onView = useCallback((report: string, open: boolean) => {
|
||||
@@ -188,6 +196,10 @@ export function EvidencePane({ run, output, labelOf, refreshKey }: {
|
||||
)
|
||||
}
|
||||
|
||||
/** 审计行在正文里打开什么:片段的行是那个片段,结论句的行是那一句的句末徽标(EvidenceDoc 认 claim:<句子>) */
|
||||
const openKey = (row: AuditRow): string | undefined =>
|
||||
row.seg ?? (row.kind === 'claim' && row.unit ? `claim:${row.unit}` : undefined)
|
||||
|
||||
/** 已经收尾的运行:还在跑、停在审批上的,报告可能还没写,说「这次的报告没有逐段证据」太早 */
|
||||
const SETTLED = new Set(['succeeded', 'failed', 'cancelled'])
|
||||
|
||||
@@ -558,7 +570,7 @@ function AuditLine({ row, current, openable, multiReport, labelOf, onOpen, onFoc
|
||||
data-audit-seg={row.seg ?? ''}>
|
||||
<td className="px-3 py-1.5">
|
||||
{openable ? (
|
||||
<button type="button" {...common} aria-label={label} title={label} onClick={onOpen} data-audit-open={row.seg}
|
||||
<button type="button" {...common} aria-label={label} title={label} onClick={onOpen} data-audit-open={openKey(row)}
|
||||
className={clsx(common.className, 'block underline decoration-dotted underline-offset-2 hover:text-[var(--accent)]')}>
|
||||
{text}
|
||||
</button>
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
} from './decode'
|
||||
import { CODE_COLUMN, CopyChip, LEADING_ZERO, Markdown, type MarkSpec } from './Markdown'
|
||||
import { ClaimTally, EvidenceField, type EvidenceDocHandle } from './EvidenceDoc'
|
||||
import { EVIDENCE_STATE, docTally, evidenceFields, issuanceMarks, type EvidenceTally } from '../lib/evidence'
|
||||
import { EVIDENCE_STATE, claimProblems, docTally, evidenceFields, issuanceMarks, type EvidenceTally } from '../lib/evidence'
|
||||
import type { EvidenceDocData } from '../types'
|
||||
import { useRunClock } from './useRunClock'
|
||||
import type { ReviewResult } from '../types'
|
||||
@@ -2289,7 +2289,7 @@ export function IssuanceBanner({ issuance, runClass, evidence }: {
|
||||
{meta.hint && <div className="mt-1 text-2xs leading-relaxed text-dim">{meta.hint}</div>}
|
||||
{counts && (counts.total > 0 || counts.other > 0 || suspect > 0 || uncitedClaims > 0 || !!claims) && (
|
||||
// 逐段证据的计数:和报告核对那一行、证据条同一种说法。可疑名字、没挂依据的结论句不是数字,
|
||||
// 各自另起一句。有无证据的数字、可疑名字、证据不支持(或部分支持)的结论句时才给「定位下一处」——
|
||||
// 各自另起一句。有无证据的数字、可疑名字、证据有问题(相矛盾、部分有依据、证据不足)的结论句时才给「定位下一处」——
|
||||
// 结论句靠句末徽标定位;只是没挂依据的结论句没有徽标,定位不到
|
||||
<div className="mt-1 flex flex-wrap items-center gap-2 text-2xs" data-evidence-line="">
|
||||
{numbers && (
|
||||
@@ -2307,7 +2307,7 @@ export function IssuanceBanner({ issuance, runClass, evidence }: {
|
||||
{numbers || suspect > 0 || claims ? '· ' : ''}{EVIDENCE_TEXT.uncitedClaimsTag} {formatNumber(uncitedClaims)}
|
||||
</span>
|
||||
)}
|
||||
{(counts.none > 0 || counts.other > 0 || suspect > 0 || !!claims?.unsupported || !!claims?.partial) && evidence?.onNext && (
|
||||
{(counts.none > 0 || counts.other > 0 || suspect > 0 || claimProblems(claims) > 0) && evidence?.onNext && (
|
||||
<button type="button" className="btn btn-xs" data-evidence-next="" onClick={evidence.onNext}>
|
||||
{EVIDENCE_TEXT.locateNext}
|
||||
</button>
|
||||
|
||||
@@ -8,8 +8,9 @@ import { ListChecks } from 'lucide-react'
|
||||
import clsx from 'clsx'
|
||||
import { rovingTarget } from '../components/ui'
|
||||
import {
|
||||
EVIDENCE_STATE, claimCounts, claimLabel, docTally, segmentKind, segmentLabel, segmentState, tallySummary, unitText,
|
||||
isJudged, limitOf, unitVerdict, verdictState, withVerdicts, type EvidenceStateCode, type EvidenceTally as Tally,
|
||||
EVIDENCE_STATE, alertTier, claimCounts, claimLabel, claimProblems, conflicting, docTally, segmentKind, segmentLabel,
|
||||
segmentState, tallySummary, unitText, isJudged, limitOf, unitVerdict, verdictMissing, verdictState, withVerdicts,
|
||||
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'
|
||||
@@ -26,13 +27,13 @@ import { BlockView, Markdown, StyledSlice, inlineStyles, numericColumns, type In
|
||||
* BlockView,和普通答案长得一模一样;有出处的数字画细实线,没有出处的画点状线、
|
||||
* 句末挂「无证据」。
|
||||
*
|
||||
* 结论句的判定(四期)只在句末挂一枚小徽标(◆ ◇ ! ?),整句不画线;证据不支持的整句铺一层浅底。
|
||||
* 徽标也是按钮:点开是这一句的「模型的解释」。判定是模型给的,颜色一律不用确定性的绿。
|
||||
* 结论句的判定(四期)只在句末挂一枚小徽标(◆ ◇ ! ○ ?),整句不画线;证据相矛盾(和旧的证据不支持)的整句
|
||||
* 铺一层浅底。徽标也是按钮:点开是这一句的「模型的解释」。判定是模型给的,颜色一律不用确定性的绿。
|
||||
*
|
||||
* 键盘:整份报告只占一个 Tab 位(roving tabindex)。←/→ 在有状态的片段、句末徽标间走,↑/↓ 按
|
||||
* 句子走(表格里按列走到上一行 / 下一行,出了表格接着按句子走),n / N 跳到下一处 /
|
||||
* 上一处无证据、证据不支持的地方,回车打开证据面板,Esc 关掉并留在原片段;面板开着时方向键走到哪、
|
||||
* 面板跟到哪,Tab 进面板。
|
||||
* 上一处有问题的地方(无证据、可疑名称、证据相矛盾、部分有依据;证据不足的排在这些之后),回车打开证据面板,
|
||||
* Esc 关掉并留在原片段;面板开着时方向键走到哪、面板跟到哪,Tab 进面板。
|
||||
*
|
||||
* 长报告:事件都挂在容器上(片段只带 data-seg),块用 memo,外加
|
||||
* content-visibility: auto;超过 TEXT_CAP 的部分先折叠,跳转到折叠里的片段时自动展开。
|
||||
@@ -66,8 +67,13 @@ interface Model {
|
||||
/** 每个有可点片段的句子里第一个可点片段,按正文顺序(↑/↓ 用) */
|
||||
unitFirst: string[]
|
||||
unitOf: Map<string, number>
|
||||
/** 无证据的片段,按正文顺序(n / N 用) */
|
||||
/**
|
||||
* 有问题的片段和句末徽标(n / N 用):先第 1 轮(无证据、可疑名称、证据相矛盾、部分有依据),再第 2 轮
|
||||
* (证据不足),每一轮里按正文顺序
|
||||
*/
|
||||
alerts: string[]
|
||||
/** alerts 里每一处在第几轮 */
|
||||
tier: Map<string, 1 | 2>
|
||||
/** 每块到它为止的累计字数(折叠用) */
|
||||
chars: number[]
|
||||
/** 表格里的片段在第几行第几列(表头 row = -1 不进来);↑/↓ 在表格里按列走 */
|
||||
@@ -83,7 +89,7 @@ function buildModel(blocks: EvidenceBlock[], overlay?: Record<string, EvidenceVe
|
||||
const badge = new Map<string, Badge>()
|
||||
const unitFirst: string[] = []
|
||||
const unitOf = new Map<string, number>()
|
||||
const alerts: string[] = []
|
||||
const tiered: [string, 1 | 2][] = []
|
||||
const chars: number[] = []
|
||||
const cell = new Map<string, { block: number; row: number; col: number }>()
|
||||
const grid = new Map<string, string>()
|
||||
@@ -101,14 +107,15 @@ function buildModel(blocks: EvidenceBlock[], overlay?: Record<string, EvidenceVe
|
||||
order.push(s.id)
|
||||
if (first) { unitFirst.push(s.id); first = false }
|
||||
unitOf.set(s.id, unitFirst.length - 1)
|
||||
if (EVIDENCE_STATE[state].alert) alerts.push(s.id)
|
||||
const t = alertTier(state)
|
||||
if (t) tiered.push([s.id, t])
|
||||
if (loc) {
|
||||
cell.set(s.id, { block: b, row: loc.row, col: loc.col })
|
||||
const key = `${b}:${loc.row}:${loc.col}`
|
||||
if (!grid.has(key)) grid.set(key, s.id)
|
||||
}
|
||||
}
|
||||
// 句末徽标排在这一句的片段后面:←/→ 走到句尾就是它,证据不支持的也进 n / N
|
||||
// 句末徽标排在这一句的片段后面:←/→ 走到句尾就是它,证据相矛盾、部分有依据、证据不足的也进 n / N
|
||||
const verdict = unitVerdict(unit, overlay)
|
||||
const state = verdictState(verdict)
|
||||
if (verdict && state) {
|
||||
@@ -118,12 +125,16 @@ function buildModel(blocks: EvidenceBlock[], overlay?: Record<string, EvidenceVe
|
||||
order.push(key)
|
||||
if (first) { unitFirst.push(key); first = false }
|
||||
unitOf.set(key, unitFirst.length - 1)
|
||||
if (EVIDENCE_STATE[state].alert) alerts.push(key)
|
||||
const t = alertTier(state)
|
||||
if (t) tiered.push([key, t])
|
||||
}
|
||||
}
|
||||
chars.push(total)
|
||||
})
|
||||
return { order, index, seg, badge, unitFirst, unitOf, alerts, chars, cell, grid }
|
||||
// 按(轮次、正文顺序)排: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 }
|
||||
}
|
||||
|
||||
/** 片段或徽标在第几块 */
|
||||
@@ -311,11 +322,17 @@ export const EvidenceDoc = forwardRef<EvidenceDocHandle, {
|
||||
if (refocus && back) requestAnimationFrame(() => segEl(back)?.focus())
|
||||
}, [view, current, segEl])
|
||||
|
||||
/**
|
||||
* n / N 的下一处:按(轮次、正文位置)排的一圈,走到头接回开头。当前位置不是问题(普通片段、有依据的徽标)时
|
||||
* 按第 1 轮算——第 1 轮里它后面没有了,就接着走第 2 轮(证据不足)
|
||||
*/
|
||||
const step = useCallback((list: string[], from: string | null, dir: 1 | -1): string | null => {
|
||||
if (!list.length) return null
|
||||
const pos = from ? model.index.get(from) ?? -1 : -1
|
||||
if (dir > 0) return list.find((id) => (model.index.get(id) ?? 0) > pos) ?? list[0]
|
||||
for (let i = list.length - 1; i >= 0; i--) if ((model.index.get(list[i]) ?? 0) < pos) return list[i]
|
||||
const rank = (id: string | null): [number, number] => [id ? model.tier.get(id) ?? 1 : 1, id ? model.index.get(id) ?? -1 : -1]
|
||||
const cmp = (a: [number, number], b: [number, number]) => a[0] - b[0] || a[1] - b[1]
|
||||
const cur = rank(from)
|
||||
if (dir > 0) return list.find((id) => cmp(rank(id), cur) > 0) ?? list[0]
|
||||
for (let i = list.length - 1; i >= 0; i--) if (cmp(rank(list[i]), cur) < 0) return list[i]
|
||||
return list[list.length - 1]
|
||||
}, [model])
|
||||
|
||||
@@ -510,7 +527,7 @@ export function EvidenceTally({ counts, onNext, onList }: {
|
||||
}) {
|
||||
const suspect = counts.suspect ?? 0
|
||||
const claims = counts.claims
|
||||
const clean = !counts.none && !counts.other && !suspect && !claims?.unsupported && !claims?.partial
|
||||
const clean = !counts.none && !counts.other && !suspect && !claimProblems(claims)
|
||||
const numbers = evidenceTally(counts.cited, counts.total, counts.other)
|
||||
return (
|
||||
<div className="mb-1.5 flex flex-wrap items-center gap-x-2 gap-y-1 text-2xs" data-evidence-tally="">
|
||||
@@ -541,13 +558,14 @@ export function EvidenceTally({ counts, onNext, onList }: {
|
||||
}
|
||||
|
||||
/**
|
||||
* 「结论 4 句(支持 3 · 不支持 1)」:和数字那一段同一种说法。判定是模型给的:全都支持也不用确定性的绿,
|
||||
* 有不支持、部分支持、没挂依据的用提醒色,其余用暗字色(它是概率性的,不该和「有出处」一样笃定)
|
||||
* 「结论 4 句(有依据 3 · 证据相矛盾 1)」:和数字那一段同一种说法。判定是模型给的:全都支持也不用确定性的绿,
|
||||
* 有问题(证据相矛盾、旧的证据不支持、部分有依据、证据不足)、没挂依据的用提醒色,其余用暗字色(它是概率性的,
|
||||
* 不该和「有出处」一样笃定)
|
||||
*/
|
||||
export function ClaimTally({ claims, lead }: { claims: ClaimTallyCounts; lead: boolean }) {
|
||||
const text = claimTally(claims)
|
||||
if (!text) return null
|
||||
const warn = claims.unsupported > 0 || claims.partial > 0 || claims.uncited > 0
|
||||
const warn = claimProblems(claims) > 0 || claims.uncited > 0
|
||||
return (
|
||||
<span className="tnum" style={{ color: warn ? 'var(--st-waiting)' : 'var(--text-dim)' }} data-evidence-claims=""
|
||||
title={JUDGE_TEXT.badge(null)}>
|
||||
@@ -655,7 +673,7 @@ const DocBlock = memo(function DocBlock({ block, dense, doc, visual, current, ac
|
||||
/**
|
||||
* 一句话:文字按行内 Markdown 渲染(整句算一次样式,跨片段的 `code`、**粗体** 不会
|
||||
* 被切坏),有状态的片段包成按钮。含无证据片段的句子末尾挂「? 无证据」;有判定的结论句末尾挂
|
||||
* 一枚徽标(也是按钮),证据不支持的整句铺浅底——字本身不画线
|
||||
* 一枚徽标(也是按钮),证据相矛盾(和旧的证据不支持)的整句铺浅底——字本身不画线
|
||||
*/
|
||||
function UnitView({ unit, doc, current, active, panelId, code, tag, badge }: {
|
||||
unit: EvidenceUnit; doc: EvidenceDocData; current: string | null; active: string | null; panelId: string
|
||||
@@ -702,8 +720,8 @@ function UnitView({ unit, doc, current, active, panelId, code, tag, badge }: {
|
||||
const open = !!badge && active === key
|
||||
return (
|
||||
<>
|
||||
{badge?.state === 'unsupported'
|
||||
// 证据不支持:整句铺一层浅底(折行时每行各自带圆角),字色、字重都不动,也不画线
|
||||
{conflicting(badge?.state)
|
||||
// 证据相矛盾(和旧的证据不支持):整句铺一层浅底(折行时每行各自带圆角),字色、字重都不动,也不画线
|
||||
? <span className="ev-claim" data-ev-claim-shade={unit.id} style={{ '--ev-soft': meta!.soft } as CSSProperties}>{nodes}</span>
|
||||
: nodes}
|
||||
{tag && [...alerts].map((state) => (
|
||||
@@ -722,10 +740,11 @@ function UnitView({ unit, doc, current, active, panelId, code, tag, badge }: {
|
||||
aria-label={claimLabel(unit, badge.verdict)}
|
||||
aria-expanded={open}
|
||||
aria-controls={open ? panelId : undefined}
|
||||
// 模型判过的写明谁判的、非确定;模型没判过的(按需还没点、到上限、没跑成)只说这是什么状态——
|
||||
// 到上限没判的也记着裁判模型,但不能写成「(模型 · 非确定)」,像是它判过一样
|
||||
// 模型判过的写明谁判的、非确定(证据不足的接着写缺什么);模型没判过的(按需还没点、到上限、没跑成)只说
|
||||
// 这是什么状态——到上限没判的也记着裁判模型,但不能写成「(模型 · 非确定)」,像是它判过一样
|
||||
title={isJudged(badge.verdict)
|
||||
? `${meta.label}${badge.verdict.post_seal ? ` · ${JUDGE_TEXT.postSeal}` : ''}(${badge.verdict.judge || JUDGE_TEXT.judgeModel} · 非确定)`
|
||||
? `${meta.label}${badge.verdict.post_seal ? ` · ${JUDGE_TEXT.postSeal}` : ''}(${badge.verdict.judge || JUDGE_TEXT.judgeModel} · 非确定)${
|
||||
verdictMissing(badge.verdict) ? `。${JUDGE_TEXT.missing(verdictMissing(badge.verdict))}` : ''}`
|
||||
: limitOf(badge.verdict) ? `${meta.label}:${JUDGE_TEXT.limitNotJudged}` : `${meta.label}:${meta.hint}`}
|
||||
style={segStyle(badge.state)}
|
||||
>
|
||||
|
||||
@@ -4,16 +4,17 @@ import {
|
||||
} from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { ArrowLeft, CornerDownRight, ListChecks, Scale, ShieldCheck, X } from 'lucide-react'
|
||||
import { AlertTriangle, ArrowLeft, CornerDownRight, ListChecks, Scale, ShieldCheck, X } from 'lucide-react'
|
||||
import clsx from 'clsx'
|
||||
import { ApiError } from '../api/client'
|
||||
import { Spinner, StatusBadge, isComposing } from '../components/ui'
|
||||
import {
|
||||
EVIDENCE_KIND_STYLE, EVIDENCE_STATE, caliberSourceText, caliberUpgradeText, closestNames, docForeign, entitySources,
|
||||
evidenceTrace, evidenceValue as valueText, graphDoc, inputSource, integrityFailures, isJudged, isJudgeLimit, judgeLimitWords,
|
||||
judgeable, limitOf, pointsToSettings,
|
||||
EVIDENCE_KIND_STYLE, EVIDENCE_STATE, caliberSourceText, caliberUpgradeText, claimBasis, closestNames, docForeign,
|
||||
entitySources, evidenceTrace, evidenceValue as valueText, graphDoc, inputSource, integrityFailures, isJudged,
|
||||
isJudgeLimit, judgeFlags, judgeLimitWords, judgeable, judgedVerdicts, limitOf, pointsToSettings,
|
||||
locatable, locatorText, notableInput, queryOf, queryWindow, quoteWhere, quoteWindow, reasonOf, rewriteOf, sealVerdict,
|
||||
segName, segmentKind, segmentState, sourceOf, unitText, unitVerdict, verdictState, type SealStatus, type SourceTone,
|
||||
segName, segmentKind, segmentState, sourceOf, unitText, unitVerdict, verdictMissing, verdictState, type ClaimBasis as Basis,
|
||||
type SealStatus, type SourceTone,
|
||||
} from '../lib/evidence'
|
||||
import { humanizeError } from '../lib/errors'
|
||||
import { formatDateTime, formatNumber, NONE, shortId } from '../lib/format'
|
||||
@@ -54,6 +55,9 @@ import { CopyChip } from './Markdown'
|
||||
* 的徽标,封存之后按需追加的另写「封存后追加」。探索运行里还没判过的句子给「请模型判断这句」;到了上限
|
||||
* 写明是哪个上限、到哪里调。点句末徽标打开的是整句(kind: 'unit'):句子、模型的解释、挂的依据、封存。
|
||||
*
|
||||
* 裁判拆档(JR):证据不足的写明缺什么;裁判模型和写作模型相同、模型不在价格表里时在「模型的解释」下提醒;
|
||||
* 表名实体步骤列出字段清单;讲方法、讲结构的句子在「挂的依据」下直接列出 SQL 和字段清单。
|
||||
*
|
||||
* 四种摆法:side 从右侧弹出(宽屏),drawer 从底部抽出(窄屏),inline 在 360px 的
|
||||
* 画布右栏里直接栏内展开,dock 放进页面给的一块常驻位置(记录页的「证据」页签)。
|
||||
* 都不是模态的:开着面板照样能在正文里走。
|
||||
@@ -387,7 +391,7 @@ function SegmentBody({ panelId, doc, artifact, runId, runClass, seg, unit, block
|
||||
)}
|
||||
|
||||
<JudgePart doc={doc} unit={unit} block={block} runId={runId} runClass={runClass}
|
||||
onDemand={detail?.unit?.on_demand} pending={pending} />
|
||||
onDemand={detail?.unit?.on_demand} answered={detail?.unit?.verdict} pending={pending} />
|
||||
|
||||
{host.onNode && (trace.producers.length > 0 || trace.consumers.length > 0) && (
|
||||
// 画布右栏:这段证据经过的节点,点一下在画布上选中并对准
|
||||
@@ -465,6 +469,8 @@ function ClaimBody({ doc, artifact, runId, runClass, unit, block }: {
|
||||
const sealLabel = sealed.status !== 'done' ? sealed.label
|
||||
: verdict && !late && isJudged(verdict) ? JUDGE_TEXT.sealedWithDoc : JUDGE_TEXT.sealedDoc
|
||||
const cites = (unit.cites ?? []).map((alias) => ({ alias, label: doc.catalog?.[alias]?.label as string | undefined }))
|
||||
// 讲方法、讲结构的句子:SQL 和字段清单直接列在挂的依据下面。正文不是封存的那份时不列(链是另一份报告的)
|
||||
const basis = useMemo(() => (foreign ? null : claimBasis(unit, doc)), [foreign, unit, doc])
|
||||
return (
|
||||
<>
|
||||
{foreign && (
|
||||
@@ -476,6 +482,7 @@ function ClaimBody({ doc, artifact, runId, runClass, unit, block }: {
|
||||
</Part>
|
||||
<JudgePart doc={doc} unit={unit} block={block} runId={runId} runClass={runClass}
|
||||
onDemand={foreign ? undefined : answered?.unit?.on_demand}
|
||||
answered={foreign ? undefined : answered?.unit?.verdict}
|
||||
pending={!!runId && !!first && (!slot || slot.status === 'loading')} />
|
||||
<Part title={JUDGE_TEXT.cites} data-ev-cites="">
|
||||
{cites.length ? (
|
||||
@@ -488,6 +495,7 @@ function ClaimBody({ doc, artifact, runId, runClass, unit, block }: {
|
||||
))}
|
||||
</ul>
|
||||
) : <p className="text-dim">{JUDGE_TEXT.noCites}</p>}
|
||||
{basis && <BasisPart basis={basis} doc={doc} runId={runId} />}
|
||||
</Part>
|
||||
<Part title={EVIDENCE_TEXT.seal} data-ev-seal="">
|
||||
<SealLine status={sealed.status} label={sealLabel} />
|
||||
@@ -508,13 +516,15 @@ function ClaimBody({ doc, artifact, runId, runClass, unit, block }: {
|
||||
* 另写「封存后追加」;到上限没判的写明哪个上限、到哪里调;改写过一次的写明原句。探索运行里还没判过的
|
||||
* (没有判定、未裁判)给「请模型判断这句」。什么都说不上的(正式运行、没开裁判的文档)不画这一节
|
||||
*/
|
||||
function JudgePart({ doc, unit, block, runId, runClass, onDemand, pending }: {
|
||||
function JudgePart({ doc, unit, block, runId, runClass, onDemand, answered, pending }: {
|
||||
doc: EvidenceDocData; unit: EvidenceUnit; block: EvidenceBlock; runId?: string; runClass?: string
|
||||
/**
|
||||
* 片段接口答的「这句能不能请模型判断」:有它就照它(运行还没跑完封存、封存被改过这些前端认不出来);
|
||||
* 老后端没有时按运行类别和文档自己认
|
||||
*/
|
||||
onDemand?: EvidenceOnDemand
|
||||
/** 片段接口答这句时的判定:接口说它「早于当前规则」(outdated),指的就是这一条 */
|
||||
answered?: EvidenceVerdict
|
||||
/** 片段接口还在取:先不按运行类别另取一次 */
|
||||
pending?: boolean
|
||||
}) {
|
||||
@@ -532,7 +542,10 @@ function JudgePart({ doc, unit, block, runId, runClass, onDemand, pending }: {
|
||||
const late = !!verdict?.post_seal
|
||||
const rewrite = rewriteOf(doc, unit.id)
|
||||
const judgeDoc = !!doc.judge
|
||||
const canAsk = !!runId && !isJudged(verdict) && (known ? !!known.available : eligible && explore === true)
|
||||
// 片段接口说这句封存后追加的判定早于当前的裁判规则(旧取值、改造前判的):照常给按钮,旧判定旁边注明「按旧规则判定」。
|
||||
// 这一页里已经按当前规则重判过(眼前的判定不再是接口答的那一条)就不算了;重判没判成时答复交回的还是那条旧判定
|
||||
const outdated = known?.reason === 'outdated' && !!known.available && isJudged(verdict) && sameVerdict(verdict, answered)
|
||||
const canAsk = !!runId && (outdated || (!isJudged(verdict) && (known ? !!known.available : eligible && explore === true)))
|
||||
// 探索运行里暂时判不了(还没跑完封存、封存被改过、升级前的运行):照接口的原话说为什么没有按钮
|
||||
const blocked = known && !known.available && BLOCKED.has(known.reason ?? '') ? known.message || '' : ''
|
||||
// 这一次按需裁判的答复里没有这一句的判定:接口说了为什么(跳过了、触顶)就照说
|
||||
@@ -542,6 +555,16 @@ function JudgePart({ doc, unit, block, runId, runClass, onDemand, pending }: {
|
||||
: (Array.isArray(res?.limits_hit) && res.limits_hit.find((l) => typeof l === 'string')) || null
|
||||
const shownLimit = limit ?? resLimit
|
||||
const judged = isJudged(verdict)
|
||||
const missing = verdictMissing(verdict)
|
||||
// 裁判模型的两条提醒(和写作模型相同、不在价格表里):封存后追加的看这一次的答复(答复里有这一句时)、再看证据图里
|
||||
// 最近一次按需裁判;节点里当场判的看文档的裁判摘要
|
||||
const replied = res && judgedVerdicts(res)[unit.id] ? res : null
|
||||
const graph = useEvidence((s) => (runId ? s.graphs[runId] : undefined))
|
||||
const loadGraph = useEvidence((s) => s.loadGraph)
|
||||
const needMeta = !!runId && judged && late && !replied && !graph
|
||||
useEffect(() => { if (needMeta && runId) void loadGraph(runId) }, [needMeta, runId, loadGraph])
|
||||
const meta0 = (graph?.data?.reports ?? []).find((r) => !report || !r?.node_id || r.node_id === report)?.judge_meta
|
||||
const flags = judgeFlags(verdict, { doc: doc.judge, reply: replied, meta: meta0 })
|
||||
// 这一次答复的那句话(message):判定之外接口还想说的,照原话写出来。最要紧的是「运行已经接着跑了,这次的
|
||||
// 判定没有记进运行记录」——判定照样交回来、也标着封存后追加,只看徽标会以为它记进去了。已经由别处说过的不重复:
|
||||
// 跳过的那一行就是它、上限的那一框说的就是它、和判定里写的理由一字不差
|
||||
@@ -573,11 +596,43 @@ function JudgePart({ doc, unit, block, runId, runClass, onDemand, pending }: {
|
||||
</div>
|
||||
)}
|
||||
{verdict && (
|
||||
<p className="font-medium" style={{ color: meta?.color ?? 'var(--text-dim)' }} data-ev-verdict={verdict.status}>
|
||||
{meta?.glyph && <span aria-hidden className="mr-1">{meta.glyph}</span>}
|
||||
{meta ? meta.label : JUDGE_TEXT.notClaim}
|
||||
<div className="flex flex-wrap items-center gap-x-1.5 gap-y-0.5">
|
||||
<p className="font-medium" style={{ color: meta?.color ?? 'var(--text-dim)' }} data-ev-verdict={verdict.status}>
|
||||
{meta?.glyph && <span aria-hidden className="mr-1">{meta.glyph}</span>}
|
||||
{meta ? meta.label : JUDGE_TEXT.notClaim}
|
||||
</p>
|
||||
{outdated && (
|
||||
<span className="chip text-2xs text-faint" data-ev-judge-outdated="" title={known?.message ?? undefined}>
|
||||
{JUDGE_TEXT.outdated}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{missing && (
|
||||
// 证据不足:裁判写明缺的是什么(「SQL」「字段清单」)。说的是证据,不是结论错了:中性字色
|
||||
<p className="mt-0.5 [overflow-wrap:anywhere]" data-ev-missing="">
|
||||
<span className="text-faint">{JUDGE_TEXT.missingLead}</span>{missing}
|
||||
</p>
|
||||
)}
|
||||
{(flags.sameModel || flags.unpriced) && (
|
||||
// 判定照常给出,但读的人要知道它的分量:左侧一道提醒色的竖线加图标,字用正文色——醒目,不刺眼
|
||||
<div className="mt-1 space-y-0.5 border-l-2 py-px pl-2 text-2xs leading-relaxed" role="note" data-ev-judge-caution=""
|
||||
style={{ borderColor: 'var(--st-waiting)' }}>
|
||||
{flags.sameModel && (
|
||||
<p className="flex items-start gap-1" data-ev-judge-same=""
|
||||
title={flags.model ? JUDGE_TEXT.sameModelTitle(flags.writer ?? flags.model) : undefined}>
|
||||
<AlertTriangle size={11} aria-hidden className="mt-0.5 shrink-0" style={{ color: 'var(--st-waiting)' }} />
|
||||
<span>{JUDGE_TEXT.sameModel}</span>
|
||||
</p>
|
||||
)}
|
||||
{flags.unpriced && (
|
||||
<p className="flex items-start gap-1" data-ev-judge-unpriced="" title={JUDGE_TEXT.noPriceTitle}>
|
||||
<AlertTriangle size={11} aria-hidden className="mt-0.5 shrink-0" style={{ color: 'var(--st-waiting)' }} />
|
||||
<span>{JUDGE_TEXT.noPrice}</span>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{showMessage && (
|
||||
<p className="mb-1 mt-0.5 text-2xs leading-relaxed" role="note" style={{ color: 'var(--st-waiting)' }} data-ev-judge-message="">
|
||||
{resMessage}
|
||||
@@ -588,8 +643,9 @@ function JudgePart({ doc, unit, block, runId, runClass, onDemand, pending }: {
|
||||
<p className="mt-0.5 text-2xs text-faint" data-ev-judge-model="">{JUDGE_TEXT.notJudgedBy(verdict.judge)}</p>
|
||||
)}
|
||||
{verdict?.rationale && !shownLimit && (
|
||||
// 理由是模型写的话:斜体,和系统给的说明分开
|
||||
<p className="mt-0.5 italic text-dim" data-ev-rationale=""><em>{verdict.rationale}</em></p>
|
||||
// 理由是模型写的话:斜体,和系统给的说明分开。最长 120 字、可能夹着 SQL 片段和长的字段名:照原样折行,
|
||||
// 不截断,长串也在栏内断开
|
||||
<p className="mt-0.5 whitespace-pre-line italic text-dim [overflow-wrap:anywhere]" data-ev-rationale=""><em>{verdict.rationale}</em></p>
|
||||
)}
|
||||
{shownLimit && (
|
||||
<div className="mt-1 rounded border px-2 py-1" role="note" data-ev-judge-limit={shownLimit}
|
||||
@@ -656,6 +712,9 @@ function JudgePart({ doc, unit, block, runId, runClass, onDemand, pending }: {
|
||||
{asking ? <Spinner size={10} /> : <Scale size={11} aria-hidden />}
|
||||
{asking ? JUDGE_TEXT.asking : verdict && verdict.reason !== 'on_demand' ? JUDGE_TEXT.askAgain : JUDGE_TEXT.ask}
|
||||
</button>
|
||||
{outdated && known?.message && (
|
||||
<span className="basis-full text-2xs text-dim" data-ev-judge-outdated-why="">{known.message}</span>
|
||||
)}
|
||||
<span className="basis-full text-2xs text-faint">{JUDGE_TEXT.askHint}</span>
|
||||
</div>
|
||||
)}
|
||||
@@ -663,6 +722,13 @@ function JudgePart({ doc, unit, block, runId, runClass, onDemand, pending }: {
|
||||
)
|
||||
}
|
||||
|
||||
/** 两条判定是不是同一条(片段接口答的、页面上叠着的):按取值、理由、裁判模型、规则版本比,不按对象引用 */
|
||||
function sameVerdict(a: EvidenceVerdict | undefined, b: EvidenceVerdict | undefined): boolean {
|
||||
if (!a || !b) return false
|
||||
const sig = (v: EvidenceVerdict) => [v.status, v.rationale ?? '', v.judge ?? '', v.rule_version ?? ''].join('\u0001')
|
||||
return sig(a) === sig(b)
|
||||
}
|
||||
|
||||
/** 接口说这句暂时判不了、值得告诉人为什么的几种(正式运行、判过了、不是结论句不用说) */
|
||||
const BLOCKED = new Set(['unsealed', 'seal_broken', 'legacy'])
|
||||
|
||||
@@ -735,6 +801,9 @@ function EntityPart({ step, entry, cite, seal, pending, failed, catalog }: {
|
||||
<span className="text-2xs text-dim">{EVIDENCE_TEXT.tableColumns((step as any).columns, !!step?.is_view)}</span>
|
||||
)}
|
||||
</div>
|
||||
{kind === 'table' && !!step?.fields?.length && (
|
||||
<FieldList fields={step.fields} more={step.fields_more} masked={step.fields_masked === true} />
|
||||
)}
|
||||
{step?.comment && <p className="mt-0.5 text-2xs text-dim">{step.comment}</p>}
|
||||
{owners.length > 1 && <p className="mt-0.5 text-2xs text-dim">{EVIDENCE_TEXT.ownerTables(owners)}</p>}
|
||||
{step?.types && !step.type && Object.keys(step.types).length > 0 && (
|
||||
@@ -769,6 +838,125 @@ function EntityPart({ step, entry, cite, seal, pending, failed, catalog }: {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 表的字段清单:证据接口给的 fields(封存范围内的表结构快照,最多 60 个,遮罩的列不列入),多出来的写「另有 N 个」,
|
||||
* 快照只存了部分表时注明(partial,实体步骤那一节另有这句时不重复)。长名字、长类型都在栏内折行,不截断
|
||||
*/
|
||||
function FieldList({ fields, more, partial, masked, label }: {
|
||||
fields: NonNullable<EvidenceStep['fields']>; more?: number; partial?: boolean; masked?: boolean; label?: (n: number) => string
|
||||
}) {
|
||||
const list = fields.filter((f) => f && typeof f.name === 'string' && f.name)
|
||||
const extra = typeof more === 'number' && Number.isFinite(more) && more > 0 ? more : 0
|
||||
const total = list.length + extra
|
||||
return (
|
||||
<div className="mt-1.5" data-ev-fields="">
|
||||
<div className="mb-0.5 text-2xs font-medium text-faint">{label ? label(total) : EVIDENCE_TEXT.fields(total)}</div>
|
||||
<ul className="grid max-h-44 grid-cols-[repeat(auto-fill,minmax(8.5rem,1fr))] gap-x-3 gap-y-px overflow-y-auto rounded bg-bg px-1.5 py-1 text-2xs">
|
||||
{list.map((f) => (
|
||||
<li key={f.name} className="min-w-0 [overflow-wrap:anywhere]" data-ev-field={f.name}>
|
||||
<span className="mono">{f.name}</span>
|
||||
{f.type && <>{' '}<span className="mono ml-1 text-faint" data-ev-field-type="">{f.type}</span></>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{extra > 0 && <p className="mt-0.5 text-2xs text-dim" data-ev-fields-more="">{EVIDENCE_TEXT.fieldsMore(extra)}</p>}
|
||||
{masked && <p className="mt-0.5 text-2xs text-dim" data-ev-fields-masked="">{EVIDENCE_TEXT.fieldsMasked}</p>}
|
||||
{partial && (
|
||||
<p className="mt-0.5 text-2xs" style={{ color: 'var(--st-waiting)' }} data-ev-fields-partial="">{EVIDENCE_TEXT.snapshotPartial}</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 讲方法、讲结构的句子挂的依据:表的字段清单、字段的类型(取句中那个名字片段的证据链:封存范围内的表结构快照)、
|
||||
* 对应的 SQL(查询快照工件,取回时后端复验哈希)。直接摆出来,不用再点开句中的名字
|
||||
*/
|
||||
function BasisPart({ basis, doc, runId }: { basis: Basis; doc: EvidenceDocData; runId?: string }) {
|
||||
const report = doc.node_id || undefined
|
||||
const segments = useEvidence((s) => s.segments)
|
||||
const sqls = useEvidence((s) => s.sqls)
|
||||
const loadSegment = useEvidence((s) => s.loadSegment)
|
||||
const loadSql = useEvidence((s) => s.loadSql)
|
||||
const entities = [...basis.tables, ...basis.columns]
|
||||
const artifacts = basis.queries.map((q) => {
|
||||
const a = doc.catalog?.[q]?.artifact
|
||||
return typeof a === 'string' && a ? a : ''
|
||||
})
|
||||
const segKey = entities.map((e) => e.seg ?? '').join(',')
|
||||
const artKey = artifacts.join(',')
|
||||
useEffect(() => {
|
||||
if (!runId) return
|
||||
for (const e of entities) if (e.seg) void loadSegment(runId, e.seg, report)
|
||||
for (const a of artifacts) if (a) void loadSql(a)
|
||||
// 按内容比:同一句不重复取
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [runId, report, segKey, artKey, loadSegment, loadSql])
|
||||
if (!runId) return <p className="mt-1.5 text-2xs text-faint" data-ev-basis="none">{JUDGE_TEXT.basisNoRun}</p>
|
||||
const stepOf = (seg?: string) => {
|
||||
const slot = seg ? segments[segmentKey(runId, seg, report)] : undefined
|
||||
const step = slot?.status === 'ok' ? (slot.data?.chain ?? []).find((c) => c?.step === 'entity') : undefined
|
||||
return { step, pending: !!seg && (!slot || slot.status === 'loading') }
|
||||
}
|
||||
return (
|
||||
<div className="mt-2 space-y-2 border-t pt-2" data-ev-basis="">
|
||||
{basis.tables.map((t) => {
|
||||
const { step, pending } = stepOf(t.seg)
|
||||
return (
|
||||
<div key={t.alias} data-ev-basis-table={t.alias}>
|
||||
{step?.fields?.length ? (
|
||||
<FieldList fields={step.fields} more={step.fields_more} partial={step.snapshot_truncated === true}
|
||||
masked={step.fields_masked === true} label={(n) => JUDGE_TEXT.basisFieldsCount(t.name, n)} />
|
||||
) : (
|
||||
<p className="text-2xs text-faint">
|
||||
{JUDGE_TEXT.basisFields(t.name)}:{pending ? JUDGE_TEXT.basisPending : JUDGE_TEXT.fieldsMissing}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
{basis.columns.length > 0 && (
|
||||
<div data-ev-basis-columns="">
|
||||
<div className="mb-0.5 text-2xs font-medium text-faint">{JUDGE_TEXT.basisColumns}</div>
|
||||
<ul className="space-y-px text-2xs">
|
||||
{basis.columns.map((c) => {
|
||||
const { step, pending } = stepOf(c.seg)
|
||||
const type = step?.type ?? (step?.types ? Object.values(step.types)[0] : undefined)
|
||||
return (
|
||||
<li key={c.alias} className="min-w-0 [overflow-wrap:anywhere]" data-ev-basis-column={c.alias}>
|
||||
<span className="mono">{c.name}</span>{' '}
|
||||
<span className="mono ml-1 text-faint">{type || (pending ? '…' : NONE)}</span>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
{basis.queries.map((q, i) => {
|
||||
const slot = artifacts[i] ? sqls[artifacts[i]] : undefined
|
||||
const sql = slot?.status === 'ok' ? slot.data?.sql ?? null : null
|
||||
return (
|
||||
<div key={q} data-ev-basis-sql={q}>
|
||||
<div className="mb-0.5 flex items-center gap-2">
|
||||
<span className="min-w-0 flex-1 text-2xs font-medium text-faint">{JUDGE_TEXT.basisSql(q)}</span>
|
||||
{sql && <CopyChip label={EVIDENCE_TEXT.copySql} text={() => sql} />}
|
||||
</div>
|
||||
{sql ? (
|
||||
<pre className="mono max-h-28 overflow-auto whitespace-pre-wrap rounded bg-bg px-1.5 py-1 text-2xs leading-relaxed text-dim [overflow-wrap:anywhere]"
|
||||
data-ev-sql="">
|
||||
{sql}
|
||||
</pre>
|
||||
) : (
|
||||
<p className="text-2xs text-faint">{artifacts[i] && (!slot || slot.status === 'loading') ? JUDGE_TEXT.basisPending : JUDGE_TEXT.sqlMissing}</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
{basis.more > 0 && <p className="text-2xs text-faint" data-ev-basis-more="">{JUDGE_TEXT.basisMoreQueries(basis.more)}</p>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 逐字引文:原文所在的文档和片段,引文在原文里的位置高亮(前后带一截上下文)。检索快照哈希对不上时
|
||||
* 不摆原文——那一段不能当证据。原话对不上的引文也画这一节,只写目录里记着的是哪次检索
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+10
-10
@@ -1,8 +1,8 @@
|
||||
import type { RunEvent, TeamMember, TeamRound, TeamRun, ToolChange } from '../types'
|
||||
import type { NodeState, RunPhase } from './trace'
|
||||
import { formatDuration, formatNumber } from '../lib/format'
|
||||
import { TYPE_LABEL, claimTally, evidenceTally, issuanceLabel, nodeTypeLabel } from '../lib/terms'
|
||||
import { statsTally } from '../lib/evidence'
|
||||
import { JUDGE_TEXT, TYPE_LABEL, claimTally, evidenceTally, issuanceLabel, nodeTypeLabel } from '../lib/terms'
|
||||
import { claimCountsOf, isJudged, statsTally } from '../lib/evidence'
|
||||
|
||||
// 泳道数据画布也要用(supervisor 节点要展开成协作矩阵),所以类型放在
|
||||
// types.ts 里;这里再导出一遍,老引用不用改
|
||||
@@ -647,16 +647,13 @@ function queryTitle(sql: string, source: string): string {
|
||||
/** agent 开了 cite_fields 时循环结束后那次结构化抽取 */
|
||||
const EXTRACT_TITLE = '按出处抽取字段'
|
||||
/**
|
||||
* report.checked 带的裁判摘要 → 「结论 4 句(支持 1 · 不支持 1 · 未裁判 2)」,和出具横幅同一种说法。
|
||||
* 「不是结论句」不算;没有摘要(没开裁判、老后端)返回空串
|
||||
* report.checked 带的裁判摘要 → 「结论 4 句(有依据 1 · 证据相矛盾 1 · 未裁判 2)」,和出具横幅同一种说法。
|
||||
* 「不是结论句」不算,旧数据的 unsupported 照样计入;没有摘要(没开裁判、老后端)返回空串
|
||||
*/
|
||||
function judgeTally(judge: unknown): string {
|
||||
const c = judge && typeof judge === 'object' ? (judge as { counts?: Record<string, unknown> }).counts : undefined
|
||||
if (!c || typeof c !== 'object') return ''
|
||||
const n = (k: string) => (typeof c[k] === 'number' && Number.isFinite(c[k] as number) ? c[k] as number : 0)
|
||||
const counts = { supported: n('supported'), partial: n('partial'), unsupported: n('unsupported'), unjudged: n('unjudged'),
|
||||
uncited: 0 }
|
||||
return claimTally({ ...counts, total: counts.supported + counts.partial + counts.unsupported + counts.unjudged })
|
||||
return claimTally(claimCountsOf(c))
|
||||
}
|
||||
|
||||
/** 报告撰写节点请裁判模型判断结论句(四期,claims: judge):units 是这一批几句 */
|
||||
@@ -1785,14 +1782,17 @@ export function decodeRun(events: RunEvent[], final?: RunFinal, opts?: DecodeOpt
|
||||
case 'evidence.judged': {
|
||||
// 探索运行跑完、封存之后,有人点开结论句请模型判断:判定追加在封存之后,不改封存的报告
|
||||
const verdicts = d.verdicts && typeof d.verdicts === 'object' ? Object.values(d.verdicts as Record<string, any>) : []
|
||||
const judged = verdicts.filter((v) => ['supported', 'partial', 'unsupported', 'not_a_claim'].includes(v?.status)).length
|
||||
const judged = verdicts.filter((v) => isJudged(v)).length
|
||||
const hit: string[] = Array.isArray(d.limits_hit) ? d.limits_hit : []
|
||||
push({
|
||||
id: `ej-${seq}`, seq, kind: 'note', nodeId, status: 'done', code: 'evidence_judged',
|
||||
level: hit.length || (Array.isArray(d.gaps) && d.gaps.length) ? 'warn' : 'info',
|
||||
title: `封存后按需裁判了 ${formatNumber(judged)} 句结论${hit.length ? ',部分因达到上限未裁判' : ''}`,
|
||||
sub: '封存后追加 · 模型判断,非确定',
|
||||
...(d.model ? { detail: [`模型:${d.model}`, ...(Array.isArray(d.gaps) ? d.gaps.map(String) : [])].join('\n') } : {}),
|
||||
// 裁判模型和写作模型相同、模型不在价格表里:和证据面板「模型的解释」同样的两句提醒
|
||||
...(d.model ? { detail: [`模型:${d.model}`, ...(d.same_model === true ? [JUDGE_TEXT.sameModel] : []),
|
||||
...(d.priced === false ? [JUDGE_TEXT.noPrice] : []),
|
||||
...(Array.isArray(d.gaps) ? d.gaps.map(String) : [])].join('\n') } : {}),
|
||||
}, nodeId)
|
||||
break
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useEffect, useMemo } from 'react'
|
||||
import { create } from 'zustand'
|
||||
import { ApiError, api } from '../api/client'
|
||||
import { graphVerdicts, judgedVerdicts } from '../lib/evidence'
|
||||
import { graphVerdicts, judgedVerdicts, sqlOf } from '../lib/evidence'
|
||||
import type {
|
||||
EvidenceDocData, EvidenceGraph, EvidenceJudgeResult, EvidenceSegmentDetail, EvidenceStats, EvidenceVerdict,
|
||||
} from '../types'
|
||||
@@ -44,6 +44,12 @@ interface EvidenceState {
|
||||
docs: Record<string, Slot<EvidenceDocData>>
|
||||
graphs: Record<string, Slot<EvidenceGraph>>
|
||||
segments: Record<string, Slot<EvidenceSegmentDetail>>
|
||||
/**
|
||||
* 查询快照里的 SQL,按工件 id 缓存(内容寻址,永久):讲方法、讲结构的句子在「挂的依据」下直接列出。
|
||||
* 只留 SQL,不留整份快照的行
|
||||
*/
|
||||
sqls: Record<string, Slot<{ sql: string | null }>>
|
||||
loadSql: (artifact: string) => Promise<void>
|
||||
/** 按工作流:最近一次运行的报告统计。画布没挂着运行时,报告节点卡的章从这里取 */
|
||||
latest: Record<string, Slot<LatestReports>>
|
||||
loadDoc: (artifact: string) => Promise<void>
|
||||
@@ -100,7 +106,7 @@ export const useEvidence = create<EvidenceState>((set, get) => {
|
||||
* 取一次、记进 table[key];正在取或已经取到的不再发。取的途中这一格被清掉或换了(dropLatest 之后
|
||||
* 又起了一次),回来的结果作废:不能让早先发出的请求把后来那份盖掉
|
||||
*/
|
||||
async function fill<K extends 'docs' | 'graphs' | 'segments' | 'latest'>(
|
||||
async function fill<K extends 'docs' | 'graphs' | 'segments' | 'latest' | 'sqls'>(
|
||||
table: K, key: string, fetcher: () => Promise<NonNullable<EvidenceState[K][string]['data']>>, force = false,
|
||||
) {
|
||||
const cur = get()[table][key]
|
||||
@@ -124,6 +130,8 @@ export const useEvidence = create<EvidenceState>((set, get) => {
|
||||
graphs: {},
|
||||
segments: {},
|
||||
latest: {},
|
||||
sqls: {},
|
||||
loadSql: (artifact) => fill('sqls', artifact, async () => ({ sql: sqlOf((await api.artifact(artifact))?.content) })),
|
||||
loadDoc: (artifact) => fill('docs', artifact, async () => {
|
||||
const res = await api.artifact(artifact)
|
||||
const doc = asDoc(res?.content)
|
||||
|
||||
+44
-6
@@ -755,9 +755,20 @@ export interface EvidenceUnit {
|
||||
* timeout_s,rationale 以「已到上限(…)」开头)、error、format、missing、on_demand(探索运行按需)
|
||||
*/
|
||||
export interface EvidenceVerdict {
|
||||
status: 'supported' | 'partial' | 'unsupported' | 'not_a_claim' | 'unjudged' | string
|
||||
/** 理由,最多 60 字 */
|
||||
/**
|
||||
* contradicted:证据和原句冲突;insufficient:证据里没有相关信息(missing 写缺的是什么)。
|
||||
* unsupported 是拆档之前的取值:旧文档、旧事件里保留原样,界面上照旧写「证据不支持」
|
||||
*/
|
||||
status: 'supported' | 'partial' | 'contradicted' | 'insufficient' | 'unsupported' | 'not_a_claim' | 'unjudged' | string
|
||||
/** 理由,最多 120 字(后端在句子边界截断,加「…」) */
|
||||
rationale?: string
|
||||
/** insufficient 时缺的是什么:「SQL」「字段清单」「取数的查询」…,由裁判给出 */
|
||||
missing?: string
|
||||
/** 按哪一版裁判规则判的(新判的都带;拆档之前判的没有) */
|
||||
rule_version?: number
|
||||
/** 判定自己带着的模型提醒(有的话盖过报告、答复、证据图里的) */
|
||||
same_model?: boolean
|
||||
priced?: boolean | null
|
||||
/** 裁判模型 id;探索运行还没判的是 null */
|
||||
judge?: string | null
|
||||
/** 封存之后按需追加的(evidence.judged 事件) */
|
||||
@@ -780,7 +791,8 @@ export interface EvidenceJudgeSummary {
|
||||
candidates?: number
|
||||
/** 预筛放掉、没送裁判的结论句 */
|
||||
screened?: string[]
|
||||
counts?: Partial<Record<'supported' | 'partial' | 'unsupported' | 'not_a_claim' | 'unjudged', number>>
|
||||
counts?: Partial<Record<'supported' | 'partial' | 'contradicted' | 'insufficient' | 'unsupported' | 'not_a_claim'
|
||||
| 'unjudged', number>>
|
||||
unjudged?: Record<string, number>
|
||||
limits_hit?: string[]
|
||||
complete?: boolean
|
||||
@@ -792,6 +804,8 @@ export interface EvidenceJudgeSummary {
|
||||
gaps?: string[]
|
||||
notes?: string[]
|
||||
same_model?: boolean
|
||||
/** 撰写这份报告实际用的模型 id(裁判模型和它相同时 same_model 为真) */
|
||||
writer_model?: string | null
|
||||
/**
|
||||
* 不支持的句子交回写作者改写一次(rewrite_once)。units:交回的句子在封存文档里的编号(采用了改写稿时,
|
||||
* 改掉的句子是 null);sentences:交回的原句;changed:改写稿里新写的句子的编号(没采用时为空);
|
||||
@@ -822,13 +836,28 @@ export interface EvidenceJudgeResult {
|
||||
message?: string | null
|
||||
/** 触顶时怎么调,一个上限一句 */
|
||||
adjust?: string[]
|
||||
/** 这一次裁判模型和写作模型相同、模型在不在价格表里、写作模型 id */
|
||||
same_model?: boolean
|
||||
priced?: boolean | null
|
||||
writer_model?: string | null
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
/** 证据图 reports[].judge_meta:这份报告最近一次按需裁判用的模型 */
|
||||
export interface EvidenceJudgeMeta {
|
||||
model?: string | null
|
||||
same_model?: boolean
|
||||
priced?: boolean | null
|
||||
writer_model?: string | null
|
||||
}
|
||||
|
||||
/** 这句能不能「请模型判断」:片段接口按运行的实际情况答(和按需裁判接口同一套条件) */
|
||||
export interface EvidenceOnDemand {
|
||||
available?: boolean
|
||||
/** formal / legacy / not_a_claim / judged / unsealed / seal_broken */
|
||||
/**
|
||||
* formal / legacy / not_a_claim / judged / unsealed / seal_broken;outdated 是封存后追加的判定早于当前的裁判规则
|
||||
* (available 为真,照常给按钮)
|
||||
*/
|
||||
reason?: string | null
|
||||
message?: string | null
|
||||
}
|
||||
@@ -875,9 +904,11 @@ export interface EvidenceStats {
|
||||
quotes?: number
|
||||
unknown_entities?: number
|
||||
unverified_entities?: number
|
||||
/** 四期:claims 为 judge 时追加,候选句按判定的句数 */
|
||||
/** 四期:claims 为 judge 时追加,候选句按判定的句数(unsupported 是拆档之前的取值,旧文档里才有) */
|
||||
supported?: number
|
||||
partial?: number
|
||||
contradicted?: number
|
||||
insufficient?: number
|
||||
unsupported?: number
|
||||
not_a_claim?: number
|
||||
unjudged?: number
|
||||
@@ -947,7 +978,9 @@ export interface EvidenceGraph {
|
||||
*/
|
||||
post_seal_verdicts?: Record<string, EvidenceVerdict> | null
|
||||
/** 封存的裁判摘要(文档的 judge) */
|
||||
judge?: EvidenceJudgeSummary | null }[]
|
||||
judge?: EvidenceJudgeSummary | null
|
||||
/** 最近一次按需裁判用的模型:和写作模型相同没有、在不在价格表里 */
|
||||
judge_meta?: EvidenceJudgeMeta | null }[]
|
||||
evidence?: { alias?: string; eid?: string; kind?: string; label?: string; node_id?: string; artifact?: string
|
||||
sealed?: boolean; cited_by?: string[]; report?: string }[]
|
||||
edges?: { from: string; to: string; rel: string }[]
|
||||
@@ -1107,6 +1140,11 @@ export interface EvidenceStep extends Omit<EvidenceInput, 'status'> {
|
||||
snapshot_truncated?: boolean
|
||||
/** 好几张表都有的同名字段:各表的类型 */
|
||||
types?: Record<string, string>
|
||||
/** 表:字段清单和类型(封存范围内的表结构快照,最多 60 个,遮罩的列不列入);多出来的个数 */
|
||||
fields?: { name?: string; type?: string | null }[]
|
||||
fields_more?: number
|
||||
/** 有列按遮罩没列进字段清单 */
|
||||
fields_masked?: boolean
|
||||
/** 表:几个字段、是不是视图;表或字段的注释 */
|
||||
is_view?: boolean
|
||||
comment?: string
|
||||
|
||||
Reference in New Issue
Block a user