Files
AgentLab/frontend/src/canvas/versionUsage.tsx
T
ThearchyHelios 35583ba1d8 口径召回前端(W4-a):版本用量加问数回答和召回、发布弹窗预告召回规模、版本历史看召回批次、recall 待办卡、时间线认两个新事件
为什么:前三波召回只有接口;这一波收口,口径升版之后谁的答案受影响、重算了几组、数变没变、怎么处置都要在界面上走得通。

- canvas/versionUsage:使用情况那一行加问数回答、导出、定时任务、召回(老服务端不给就不写)
- canvas/RecallPanel(新):发布弹窗「召回」一行——旧版本被谁用过、按参数去重几组、发布后自动重算几组、超出上限几组(可在
  版本历史接着算)、上限为 0 时只列不算、不能重算的原因;版本历史展开一版——每组结论(数变了 / 没变 / 无法重算:原因 /
  重算失败 / 正在重算 / 未重算)、变了的指标、开了几条待办、召回运行链接,「另有 M 组未重算」+ 接着算
- run/RecallTask(新)+ TaskCard:recall 待办卡——旧口径、新口径、两版之差一行一个指标,每个数点得开召回卡的指标链;每个答案
  当时的值点得开(正式运行的口径卡、问数回答的查询快照),问数回答链回对话;「按新版重新出具」(不能时停用并写服务端给的
  原因)、「知道了」;遮罩值写已遮罩、点不开;目录有变、表结构变了两种只有「知道了」
- run/decode:ledger.recalled(已按 vN 核对,不影响;召回核对数变没变;试算结果)、ledger.basis_changed(依据有变、依据的
  表结构已变);缺字段不猜
- 文案进 lib/termsRecall.ts;接口 api/recall.ts、形状 typesRecall.ts;TaskKind 加 recall
- 检查:check-inbox 加 recall 卡两段,check-publish 加召回预告和召回批次两段(版本历史、发布弹窗都在这里测;check-versions
  测的是上传表格的版本页,和召回无关),check-decode 加两个新事件的夹具,check-capabilities 的可订阅事件跟上 ledger.recall
2026-10-16 20:05:24 +08:00

110 lines
4.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
import { api } from '../api/client'
import { confirmDialog, promptDialog, toast } from '../components/ui'
import { formatDateTime } from '../lib/format'
import { VERSION_USAGE_TEXT as T } from '../lib/terms'
import { RECALL_TEXT } from '../lib/termsRecall'
/*
* 工作流版本的使用情况与退役(A1、L4):发布弹窗、版本历史、退役确认三处共用。
*
* 使用情况取账本的只读接口(/api/ledger/workflow-versions/{wf}/{v}):被哪些应用固定、生效记录数、正式运行数;口径账本另加
* 问数回答、导出、定时任务、召回(next-round 02 做法 8,老服务端不给就不写)。
* 退役只给管理员(Q8);关登录时所有人等同管理员。当前发布版不能退役,服务端回 409,这里先不给按钮
*/
export type VersionUsage = Awaited<ReturnType<typeof api.ledger.version>>
/** 一个版本的使用情况。version 为空时不取;取不到(老服务端、网络)时是 null,界面不画这一行 */
export function useVersionUsage(workflowId: string, version: number | null, epoch = 0): VersionUsage | null {
const [usage, setUsage] = useState<VersionUsage | null>(null)
useEffect(() => {
setUsage(null)
if (version == null) return
let alive = true
api.ledger.version(workflowId, version).then((u) => { if (alive) setUsage(u) }).catch(() => undefined)
return () => { alive = false }
}, [workflowId, version, epoch])
return usage
}
/**
* 「被 2 个应用固定:报销审批、周报看板 · 生效记录 3 条 · 正式运行 14 次 · 问数回答 5 次 · 导出 2 次 · 召回 3 组(数变了
* 1 组)」,应用名可点开编辑。账本另加的几项老服务端不给就不写;召回两头都是 0 的不写
*/
export function VersionUsageLine({ usage }: { usage: VersionUsage }) {
const U = RECALL_TEXT.usage
const extra = [
usage.answers != null ? U.answers(usage.answers) : null,
usage.exports != null ? U.exports(usage.exports) : null,
usage.schedules ? U.schedules(usage.schedules) : null,
usage.recall?.groups ? U.recall(usage.recall.groups, usage.recall.changed) : null,
usage.recall?.recalled_from ? U.recalledFrom(usage.recall.recalled_from) : null,
].filter((x): x is string => !!x)
return (
<span className="text-dim" data-version-usage="">
{T.apps(usage.apps.length)}
{usage.apps.length > 0 && (
<>
{':'}
{usage.apps.map((a, i) => (
<span key={a.app_id}>
{i > 0 && '、'}
<Link to={`/apps/${encodeURIComponent(a.app_id)}/edit`} className="underline-offset-2 hover:underline">
{a.name}
</Link>
<span className="text-faint"> v{a.app_version}</span>
</span>
))}
</>
)}
<span className="text-faint"> · {T.effects(usage.effects)} · {T.formalRuns(usage.formal_runs)}</span>
{extra.length > 0 && <span className="text-faint" data-version-usage-ledger=""> · {extra.join(' · ')}</span>}
</span>
)
}
/** 退役这个按钮现在能不能点:不能时返回为什么(给按钮的 title 和下面那一行) */
export function retireBlocked(opts: { current: boolean; publishedLevel: boolean; retired: boolean; admin: boolean }): string | null {
if (opts.retired) return T.retired
if (!opts.publishedLevel) return T.retireDraft
if (opts.current) return T.retireCurrent
if (!opts.admin) return T.retireAdmin
return null
}
/**
* 退役一个版本:先确认(写明受影响的应用和后果),再问一句可选的说明。成功返回 true。
* 服务端的拒绝(当前发布版、没有权限)照它的原话弹出
*/
export async function retireVersion(workflowId: string, version: number, usage: VersionUsage | null): Promise<boolean> {
const ok = await confirmDialog({
title: T.retireTitle(version),
body: T.retireBody,
consequences: usage?.apps.length ? [T.retireAffected(usage.apps.map((a) => `${a.name} v${a.app_version}`))] : undefined,
confirmLabel: T.retire,
danger: true,
})
if (!ok) return false
const note = await promptDialog({ title: T.retireTitle(version), label: T.retireNote, allowEmpty: true, confirmLabel: T.retire })
if (note == null) return false
try {
await api.workflows.retire(workflowId, version, note.trim() || undefined)
toast.ok(T.retired_ok(version))
return true
} catch (e) {
toast.error(e)
return false
}
}
/** 已退役的版本那一行:谁、什么时候退的,说明 */
export function RetiredNote({ by, at, note }: { by?: string | null; at: string; note?: string | null }) {
return (
<span className="text-2xs" style={{ color: 'var(--st-waiting)' }} data-version-retired="">
{T.retiredBy(by, formatDateTime(at))}{note ? ` · ${note}` : ''}
</span>
)
}