/** * 口径召回在画布上的两处(docs/design/next-round/02-口径账本.md 做法 7、8): * - 发布弹窗的召回预告(RecallPreviewRow):把这一版发布成新版本之后,旧版本被多少问数回答、导出、定时任务、应用用过, * 预计自动重算几组,超出上限的写明(GET /api/workflows/{id}/recall-preview)。和发布之后真的召回走同一份计划,规模一致; * - 版本历史里口径升到这一版之后的召回批次(RecallBatches):每组的结论(数变了 / 没变 / 无法重算:原因 / 重算失败 / 正在 * 重算 / 未重算),「另有 M 组未重算」和「接着算」(GET / POST /api/ledger/recall/{wf}/{v})。之后又发布了更新的版本的, * 旧的那一版不再给「接着算」,写服务端给的原因(continue_reason)。 * * 界面层不放逻辑:几组、能不能重算、为什么不能、能不能接着算都由服务端给。老服务端没有这两个接口(404)时不画。 */ import { useEffect, useState } from 'react' import { Link } from 'react-router-dom' import { ExternalLink, Play } from 'lucide-react' import { api } from '../api/client' import { Spinner, toast } from '../components/ui' import { formatDateTime } from '../lib/format' import { RECALL_TEXT } from '../lib/termsRecall' import type { RecallBatches as Batches, RecallGroup, RecallPreview } from '../typesRecall' const P = RECALL_TEXT.preview const B = RECALL_TEXT.batches /** 发布弹窗「召回」那一行。旧版本里没有口径、也没有用过的答案时不画(发布不牵涉召回) */ export function RecallPreviewRow({ workflowId, version }: { workflowId: string; version: number }) { const [preview, setPreview] = useState(null) const [failed, setFailed] = useState(false) useEffect(() => { let alive = true setPreview(null) setFailed(false) api.recall.preview(workflowId, version) .then((p) => { if (alive) setPreview(p) }) .catch(() => { if (alive) setFailed(true) }) return () => { alive = false } }, [workflowId, version]) if (failed || !preview) { return failed ? null : (
{P.label}
{P.loading}
) } if (!preview.caliber && !preview.groups) return null const uses = preview.versions.reduce((acc, v) => ({ answers: acc.answers + v.answers, exports: acc.exports + v.exports, schedules: acc.schedules + v.schedules, apps: acc.apps + v.apps, formal: acc.formal + v.formal, pinned: acc.pinned + v.pinned, }), { answers: 0, exports: 0, schedules: 0, apps: 0, formal: 0, pinned: 0 }) return (
{P.label}
{!preview.groups ?
{P.none}
: ( <>
{P.uses(uses)}
{P.groups(preview.groups, preview.will_recompute)} {preview.already > 0 && ({P.already(preview.already)})}
{preview.limit === 0 &&
{P.zero}
} {preview.limit > 0 && preview.over_limit > 0 && (
{P.over(preview.over_limit, preview.limit)}
)} {preview.not_recomputable > 0 && (
{P.notRecomputable(preview.not_recomputable)}:{preview.reasons.map((r) => r.reason).join(';')}
)} {preview.truncated &&
{P.truncated}
}
{P.hint}
)}
) } const STATE_COLOR: Record = { changed: 'var(--st-waiting)', failed: 'var(--err)', not_recomputable: 'var(--text-faint)', unchanged: 'var(--ok)', } /** 列表先列几组,其余收起 */ const SHOWN = 6 /** 版本历史里这一版的召回。还没有任何一组(旧版本没被用过、或者这是第一版)时不画 */ export function RecallBatches({ workflowId, version }: { workflowId: string; version: number }) { const [data, setData] = useState(null) const [failed, setFailed] = useState(false) const [busy, setBusy] = useState(false) const [all, setAll] = useState(false) useEffect(() => { let alive = true setData(null) setFailed(false) api.recall.batches(workflowId, version) .then((d) => { if (alive) setData(d) }) .catch(() => { if (alive) setFailed(true) }) return () => { alive = false } }, [workflowId, version]) const continueBatch = async () => { if (busy) return setBusy(true) try { const next = await api.recall.continueBatch(workflowId, version) setData(next) toast.ok(B.continued(next.launched?.length ?? 0)) } catch (e) { toast.error(e) } finally { setBusy(false) } } if (failed) return null if (!data) return
{B.loading}
if (!data.groups.length) return null const shown = all ? data.groups : data.groups.slice(0, SHOWN) const summary = B.summary(data.counts) return (
{B.title}
{summary &&
{summary}
}
    {shown.map((g) => )}
{!all && data.groups.length > SHOWN && ( )} {data.remaining > 0 && (
{B.remaining(data.remaining)}
{data.can_continue && ( )} {!data.can_continue && data.continue_reason && (
{B.cannotContinue(data.continue_reason)}
)}
)} {data.truncated &&
{B.truncated}
}
) } function GroupRow({ group }: { group: RecallGroup }) { return (
  • {B.state[group.state] ?? group.state} {B.from(group.from_version)} {B.uses(group.uses)} {group.latest && · {formatDateTime(group.latest)}}
    {group.binding.length ? group.binding.map((b) => {b.field}={String(b.value ?? '')}) : {B.noBinding}}
    {group.reason && (
    {B.reason(group.state, group.reason)}
    )} {!!group.changed_metrics?.length &&
    {B.changedMetrics(group.changed_metrics)}
    }
    {!!group.tasks && {B.tasks(group.tasks)}} {group.run_id && ( {B.openRun} )}
  • ) }