import { useState, type JSX } from 'react' import { ReactFlow, ReactFlowProvider } from '@xyflow/react' import { Inspector } from '../../canvas/Inspector' import { NodeCard } from '../../canvas/NodeCard' import { ApprovalCard } from '../../run/RunPanel' import { ChallengeSummary } from '../../run/ChallengeSummary' import { useCatalog } from '../../store/catalog' import { useStudio } from '../../store/studio' import type { Approval, ApprovalChallenge, ApprovalReport, Provider, Workflow } from '../../types' import fx from './challenge.json' /** * 反方审稿的预览用例,scripts/check-challenge.mjs 按它们检查。夹具在 challenge.json(检查脚本读同一份):理由文档是后端 * run_verify_agent + compose_doc 真跑出来的,库、表名、地名、数字都是虚构的。 * * 审批卡(payload.reports[0].challenge): * - ?syn=challenge-approval:正式运行,没写 on_refuted(按降档),四种判断各一句,有被推翻的 →「出具会降档」 * - ?syn=challenge-approval-flag:正式运行,只标注,不写降档 * - ?syn=challenge-approval-explore:探索运行,不说任何和出具有关的话 * - ?syn=challenge-approval-none:审的报告没有经过反方审稿,什么都不画 * - ?syn=challenge-approval-many:十二句,条目只列前十句,「显示全部」从工件里补齐 * - ?syn=challenge-approval-broken:工件取不到(检查脚本先答 404,再改成能取到,测重试) * - ?syn=challenge-approval-dense:同第一个,摆在 360px 的右栏里 * - ?syn=challenge-approval-clear / -clear-flag:正式运行,没有被推翻的结论(降档 / 只标注),两种都不写降档、不写只标注 * - ?syn=challenge-approval-explore-flag:探索运行配只标注,同样不说任何和出具有关的话 * - ?syn=challenge-approval-runfail:老服务端的审批(不带 run_class),运行类别也取不到(检查脚本先答 500):不说任何 * 和出具有关的话。审批带着运行类别时照它说、不另取,见 challenge-summary-given * - ?syn=challenge-approval-unreviewed:正式运行,四句里有两句未能反查(unreviewed:被削弱、经受住的那两句换成数据源 * 已停用、记为无法判断,计数跟着改成无法判断 3 句;工件由检查脚本按同样的改法合成),被推翻的会降档(degrades) * - ?syn=challenge-approval-unreviewed-over:服务端给的 unreviewed(5)比「无法判断」的句数(1)还多(不该出现): * 卡上按「无法判断」的句数说,两个数不打架 * - ?syn=challenge-approval-offpath:正式运行,按降档处置,但反方审稿不在带出具契约的成果节点上游(degrades 为假) * - ?syn=challenge-summary-given:反方审稿那一块单独画,审批自带的运行类别(正式运行)由调用方传进来;检查脚本让这次运行的 * GET 失败,卡上照样写「出具会降档」,也不另发这次请求。审批卡(RunPanel 的 ApprovalCard)把 approval.run_class * 传给它之后,卡上走的就是这条路 * - ?syn=challenge-approval-dup:同 many,工件里补出来的一句和条目里的一句原文相同、unit 不同(工件由检查脚本合成) * - ?syn=challenge-approval-norecord:同 many,审稿记录没存上(artifact 为 null) * * 运行类别(GET /api/runs/{id})、工件(GET /api/artifacts/{id})都由检查脚本用 page.route 伪造;直接打开时取不到, * 卡上照实不说降档、点开一句说无法获取。 * * 检查器:选中反方审稿节点,旁边是同一张图的节点卡片和节点配置的实时内容。 * - ?syn=challenge-inspector:两个上游报告、一个下游报告 * - ?syn=challenge-inspector-chain:「初稿 → 终稿 → 反方审稿」,留空时审直接连着的终稿,反方模型和终稿的模型相同 */ const report = fx.report as unknown as ApprovalReport const challenge = fx.challenge as unknown as ApprovalChallenge /** runClass 为 null:老服务端的审批,不带运行类别 */ function approvalOf(id: string, runId: string, runClass: 'formal' | 'exploratory' | null, reviewed: ApprovalReport): Approval { return { id, run_id: runId, node_id: 'review', mode: 'approve', title: '本月月报可以发出吗?', status: 'pending', response: {}, payload: { kind: 'human_node', message: '请审核本月月报。', reports: [reviewed] }, created_at: new Date(Date.now() - 300_000).toISOString().replace('Z', ''), workflow_name: '月报', node_label: '主管审批', ...(runClass ? { run_class: runClass } : {}), } } function Card({ approval, name, dense = false }: { approval: Approval; name: string; dense?: boolean }) { return (
undefined} />
) } const RUNS = fx.runs /** 期 4 起服务端另带的两项:unreviewed(没能反查的句数)、degrades(被推翻的会不会让出具降档) */ type Challenge = ApprovalChallenge & { unreviewed?: number; degrades?: boolean } const withChallenge = (c: Partial): ApprovalReport => ({ ...report, challenge: { ...challenge, ...c } as ApprovalChallenge }) const many = fx.many as unknown as ApprovalChallenge /** 没有被推翻的结论:同第一个用例去掉被推翻的那句,计数跟着改 */ const clear: Partial = { counts: { stands: 1, weakened: 1, refuted: 0, inconclusive: 1 }, items: challenge.items.filter((it) => it.verdict !== 'refuted'), } /** * 有两句未能反查:被削弱(u5)、经受住(u8)的那两句换成数据源已停用、没查成,记为无法判断(服务端未能反查的每一句都 * 记为无法判断,unreviewed 不会多于 inconclusive)。原来无法判断的 u11 是查过了、数据不够,不算未能反查 */ const UNREVIEWED_UNITS = ['u5', 'u8'] const unreviewed: Partial = { counts: { stands: 0, weakened: 0, refuted: 1, inconclusive: 3 }, items: challenge.items.map((it) => (UNREVIEWED_UNITS.includes(it.unit) ? { ...it, verdict: 'inconclusive' } : it)), artifact: 'f'.repeat(64), unreviewed: 2, degrades: true, } // ---------------------------------------------------------------- 检查器 const PROVIDERS = [ { id: 'pv-main', name: '主力接入', kind: 'anthropic', base_url: null, default_model: 'writer-large', models: [{ id: 'writer-large' }, { id: 'critic-large' }], enabled: true, extra: {}, api_key_masked: '', has_key: true, }, { id: 'pv-spare', name: '备用接入', kind: 'openai', base_url: null, default_model: 'spare-mini', models: [{ id: 'spare-mini' }], enabled: false, extra: {}, api_key_masked: '', has_key: true, }, ] as Provider[] const at = (x: number, y: number) => ({ x, y }) const WORKFLOW = { id: 'wf-challenge-preview', name: '月报(预览)', description: '', tags: [], version: 1, is_template: false, status: 'draft', graph: { nodes: [ { id: 'input', type: 'input', position: at(0, 120), data: { label: '输入', config: { fields: [{ name: 'month', required: true }] } } }, { id: 'write', type: 'report', position: at(260, 0), data: { label: '写月报', config: { instructions: '写本月月报', model: 'writer-large' } } }, { id: 'write2', type: 'report', position: at(260, 240), data: { label: '写周报', config: { instructions: '写本周周报' } } }, { id: 'critic', type: 'challenge', position: at(540, 120), data: { label: '反方审稿', config: {} } }, { id: 'later', type: 'report', position: at(820, 120), data: { label: '写摘要', config: { instructions: '写一段摘要' } } }, { id: 'out', type: 'output', position: at(1100, 120), data: { label: '输出', config: {} } }, ], edges: [ { source: 'input', target: 'write' }, { source: 'input', target: 'write2' }, { source: 'write', target: 'critic' }, { source: 'write2', target: 'critic' }, { source: 'critic', target: 'later' }, { source: 'later', target: 'out' }, ], }, } as unknown as Workflow /** 链式接法:初稿、终稿都在上游,直接连着的只有终稿。终稿和反方审稿写的是同一个模型 */ const CHAIN = { id: 'wf-challenge-chain', name: '月报(链式,预览)', description: '', tags: [], version: 1, is_template: false, status: 'draft', graph: { nodes: [ { id: 'input', type: 'input', position: at(0, 120), data: { label: '输入', config: { fields: [{ name: 'month', required: true }] } } }, { id: 'draft', type: 'report', position: at(260, 120), data: { label: '初稿', config: { instructions: '写初稿', model: 'spare-mini' } } }, { id: 'final', type: 'report', position: at(520, 120), data: { label: '终稿', config: { instructions: '改成终稿', model: 'writer-large' } } }, { id: 'critic', type: 'challenge', position: at(780, 120), data: { label: '反方审稿', config: { model: 'writer-large' } } }, { id: 'out', type: 'output', position: at(1040, 120), data: { label: '输出', config: {} } }, ], edges: [ { source: 'input', target: 'draft' }, { source: 'draft', target: 'final' }, { source: 'final', target: 'critic' }, { source: 'critic', target: 'out' }, ], }, } as unknown as Workflow const nodeTypes = { card: NodeCard } /** 同一张图的节点卡片:看反方审稿节点的摘要跟着配置变 */ function MiniCanvas() { const nodes = useStudio((s) => s.nodes) const edges = useStudio((s) => s.edges) return ( ) } function ConfigView() { const config = useStudio((s) => s.nodes.find((n) => n.id === 'critic')?.data.config) return (
      {JSON.stringify(config ?? null, null, 1)}
    
) } function InspectorCase({ name, workflow }: { name: string; workflow: Workflow }) { // 首次渲染前装好图和接入:检查器、卡片一挂上就是选中反方审稿节点的样子 useState(() => { useCatalog.setState({ providers: PROVIDERS }) useStudio.getState().load(workflow) useStudio.getState().select('critic') return true }) return (
) } export const cases: Record JSX.Element> = { 'challenge-approval': () => ( ), 'challenge-approval-flag': () => ( ), 'challenge-approval-explore': () => ( ), 'challenge-approval-none': () => ( ), 'challenge-approval-many': () => ( ), 'challenge-approval-broken': () => ( ), 'challenge-approval-dense': () => ( ), 'challenge-approval-clear': () => ( ), 'challenge-approval-clear-flag': () => ( ), 'challenge-approval-explore-flag': () => ( ), 'challenge-approval-runfail': () => ( ), 'challenge-approval-dup': () => ( ), 'challenge-approval-norecord': () => ( ), 'challenge-approval-unreviewed': () => ( ), 'challenge-approval-unreviewed-over': () => ( ), 'challenge-summary-given': () => (
), 'challenge-approval-offpath': () => ( ), 'challenge-inspector': () => , 'challenge-inspector-chain': () => , }