- R4:封存子进程 SIGTERM 宽限停、libraryctl 信号转 ctx;失败/超时后 agent 再做 有界 recover,恢复失败即降级阻断封存并给出原因;启动先恢复、关闭等恢复完成 - R5:封存闸口以已存 payload 为准,同作业号换范围 409 且不入新队;重放回显真实状态 - R6:作业列表按类型查询(ListByType),不再先取全局再过滤 - R7:根目录 libraryagent 二进制移出版本库,保留运行产物并精确忽略 - UI:发布管理只保留对内/对外两目标,整合快照/完整性/作业/存储;链路未接线项禁用 并标原因;整库版本独立导航并入;文档级旧流程折叠保留
This commit is contained in:
@@ -0,0 +1,446 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import {
|
||||
enqueueLibraryCapture,
|
||||
fetchLibraryCaptures,
|
||||
fetchLibrarySnapshots,
|
||||
formatBytes,
|
||||
scopeLabel,
|
||||
type LibraryCaptureJob,
|
||||
type LibrarySnapshot,
|
||||
type LibrarySnapshotList,
|
||||
} from './librarySnapshots'
|
||||
import { useOptionalAuth } from './auth'
|
||||
import './releaseTargets.css'
|
||||
|
||||
// 发布管理的主视图:只服务『对内 / 对外』两个整库目标。
|
||||
//
|
||||
// 这条链有四段:封存 → 生产预备份 → 同步 → 校验/恢复。目前只有第一段接通,
|
||||
// 其余三段一律禁用并写明"未接线/未授权"——不用假进度、不推算阶段、不显示假成功。
|
||||
// 文档级旧流程折叠保留在页面底部,它成功也不代表整库发布成功。
|
||||
|
||||
const stamp = (value: string) =>
|
||||
value && Number.isFinite(new Date(value).getTime())
|
||||
? new Date(value).toLocaleString('zh-CN', {
|
||||
timeZone: 'Asia/Shanghai',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
})
|
||||
: '—'
|
||||
|
||||
const jobStateLabel: Record<string, string> = {
|
||||
pending: '排队中',
|
||||
running: '执行中',
|
||||
retry: '重试中',
|
||||
completed: '已完成',
|
||||
failed: '失败',
|
||||
}
|
||||
|
||||
const ACTIVE_STATES = ['pending', 'running', 'retry']
|
||||
const metric = (snapshot: LibrarySnapshot, key: string) => snapshot.totals[key] ?? 0
|
||||
|
||||
interface StageProps {
|
||||
id: string
|
||||
label: string
|
||||
state: 'ready' | 'not-wired' | 'not-authorized'
|
||||
detail: string
|
||||
}
|
||||
|
||||
function Stage({ label, state, detail }: StageProps) {
|
||||
const chip =
|
||||
state === 'ready' ? '已接通' : state === 'not-authorized' ? '未授权' : '未接线'
|
||||
return (
|
||||
<li className={`release-stage ${state}`}>
|
||||
<span className="release-stage-name">{label}</span>
|
||||
<span className="release-stage-chip">{chip}</span>
|
||||
<span className="release-stage-detail">{detail}</span>
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
interface ReleaseTargetsViewProps {
|
||||
page: LibrarySnapshotList | null
|
||||
jobs: LibraryCaptureJob[]
|
||||
loading: boolean
|
||||
error: string | null
|
||||
notice: string | null
|
||||
expanded: string | null
|
||||
pendingScope: string | null
|
||||
canCapture: boolean
|
||||
onRefresh: () => void
|
||||
onCapture: (scope: string) => void
|
||||
onToggleExpanded: (snapshotID: string) => void
|
||||
}
|
||||
|
||||
export function ReleaseTargetsView(props: ReleaseTargetsViewProps) {
|
||||
const { page, jobs, loading, error, notice, expanded, pendingScope, canCapture, onRefresh, onCapture, onToggleExpanded } = props
|
||||
const latestByScope = useMemo(() => {
|
||||
const map: Record<string, LibrarySnapshot | undefined> = {}
|
||||
for (const snapshot of page?.snapshots ?? []) {
|
||||
if (!map[snapshot.scope]) map[snapshot.scope] = snapshot
|
||||
}
|
||||
return map
|
||||
}, [page])
|
||||
|
||||
return (
|
||||
<section className="release-targets" aria-label="整库发布">
|
||||
<header className="release-targets-head">
|
||||
<div>
|
||||
<h1>发布管理</h1>
|
||||
<p>
|
||||
两个目标:对内与对外。每个目标是一份<strong>完整封存</strong>的整库版本,不是若干单篇文档。
|
||||
这条链只有第一段接通,其余动作按真实状态禁用。
|
||||
</p>
|
||||
</div>
|
||||
<button type="button" className="secondary" onClick={() => onRefresh()} disabled={loading}>
|
||||
{loading ? '刷新中…' : '刷新'}
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<ol className="release-chain" aria-label="整库发布链路">
|
||||
<Stage id="seal" label="封存" state="ready" detail="停写入者→导出十表/索引/对象/Wiki→恢复;读取时重算摘要" />
|
||||
<Stage id="prebackup" label="生产预备份" state="not-wired" detail="生产独立备份与恢复演练未接线" />
|
||||
<Stage id="sync" label="同步到生产" state="not-authorized" detail="生产写入需要独立授权闸口,当前未开放" />
|
||||
<Stage id="verify" label="校验 / 恢复" state="not-wired" detail="同步后校验与按版本回退未接线" />
|
||||
</ol>
|
||||
|
||||
{error ? (
|
||||
<div className="release-blocked">
|
||||
<strong>读取失败</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
) : null}
|
||||
{page && !page.available ? (
|
||||
<div className="release-blocked">
|
||||
<strong>归档未接线</strong>
|
||||
<p>{page.reason || '整库归档根未配置'}</p>
|
||||
</div>
|
||||
) : null}
|
||||
{notice ? <p className="release-notice">{notice}</p> : null}
|
||||
|
||||
<div className="release-target-grid">
|
||||
{(['internal', 'external'] as const).map((scope) => {
|
||||
const snapshot = latestByScope[scope]
|
||||
const activeJob = jobs.find((job) => job.scope === scope && ACTIVE_STATES.includes(job.state))
|
||||
const lastJob = jobs.find((job) => job.scope === scope)
|
||||
const expandedHere = snapshot && expanded === snapshot.snapshot_id
|
||||
const blockedReason = !page
|
||||
? '正在读取归档'
|
||||
: !page.available
|
||||
? page.reason || '归档根未配置'
|
||||
: !page.capture_available
|
||||
? page.capture_reason || '主机侧封存 agent 未接线'
|
||||
: null
|
||||
return (
|
||||
<article key={scope} className="release-target">
|
||||
<header className="release-target-head">
|
||||
<h2>{scopeLabel(scope)}</h2>
|
||||
<span className={snapshot ? 'release-state ready' : 'release-state empty'}>
|
||||
{snapshot ? '已封存' : '尚无封存'}
|
||||
</span>
|
||||
</header>
|
||||
|
||||
{snapshot ? (
|
||||
<>
|
||||
<p className="release-target-meta">
|
||||
封存于 {stamp(snapshot.created_at)} · 快照 <code>{snapshot.snapshot_id.slice(0, 16)}</code>
|
||||
</p>
|
||||
<dl className="release-metrics">
|
||||
<div>
|
||||
<dt>文档</dt>
|
||||
<dd>{metric(snapshot, 'documents')}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>分块</dt>
|
||||
<dd>{metric(snapshot, 'chunks')}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>索引</dt>
|
||||
<dd>{metric(snapshot, 'index_documents')}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>资源</dt>
|
||||
<dd>{metric(snapshot, 'resources')}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Wiki 页</dt>
|
||||
<dd>{metric(snapshot, 'wiki_pages')}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>内容字节</dt>
|
||||
<dd>{formatBytes(snapshot.logical_bytes)}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<p className="release-integrity">
|
||||
完整性:读取时已重算 {snapshot.parts.length} 项摘要并逐项匹配(A04 口径)。
|
||||
模型 {snapshot.compatibility.embedding_model || '未知'} /{' '}
|
||||
{snapshot.compatibility.embedding_dimension || '?'} 维 · schema{' '}
|
||||
{snapshot.compatibility.schema_version || '?'} · 策略 {snapshot.validation_policy || '—'}
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
className="release-parts-toggle"
|
||||
onClick={() => onToggleExpanded(snapshot.snapshot_id)}
|
||||
aria-expanded={expandedHere}
|
||||
>
|
||||
{expandedHere ? '收起分项与校验结果' : '展开分项与校验结果'}
|
||||
</button>
|
||||
{expandedHere ? (
|
||||
<div className="release-parts">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>类别</th>
|
||||
<th>分项</th>
|
||||
<th>数量</th>
|
||||
<th>字节</th>
|
||||
<th>摘要(SHA256)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{snapshot.parts.map((part) => (
|
||||
<tr key={`${part.kind}-${part.name}`}>
|
||||
<td>{part.kind}</td>
|
||||
<td>{part.name}</td>
|
||||
<td>{part.count}</td>
|
||||
<td>{part.bytes.toLocaleString('zh-CN')}</td>
|
||||
<td>
|
||||
<code title={part.sha256}>{part.sha256.slice(0, 12)}</code>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<p className="release-parts-note">
|
||||
校验结果:{snapshot.parts.length} 项全部可读且摘要一致;未发现异常。
|
||||
这证明的是数据完整性,不是效果测试(A06 已取消)。
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
</>
|
||||
) : (
|
||||
<p className="release-target-empty">
|
||||
{blockedReason || '还没有封存产物。先发起一次封存,产出一份完整版本。'}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="release-target-job">
|
||||
{activeJob ? (
|
||||
<>
|
||||
<span className={`release-job-state ${activeJob.state}`}>
|
||||
{jobStateLabel[activeJob.state] ?? activeJob.state}
|
||||
</span>
|
||||
<code>{activeJob.capture_job}</code>
|
||||
<span className="release-job-owner">{activeJob.requested_by || '—'}</span>
|
||||
</>
|
||||
) : lastJob ? (
|
||||
<>
|
||||
<span className={`release-job-state ${lastJob.state}`}>
|
||||
{jobStateLabel[lastJob.state] ?? lastJob.state}
|
||||
</span>
|
||||
<span>上次作业 {lastJob.capture_job}</span>
|
||||
{lastJob.last_error ? (
|
||||
<span className="release-job-error" title={lastJob.last_error}>
|
||||
{lastJob.last_error.slice(0, 80)}
|
||||
</span>
|
||||
) : null}
|
||||
</>
|
||||
) : (
|
||||
<span className="release-job-idle">当前没有封存作业</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="release-actions">
|
||||
{page?.capture_available ? (
|
||||
canCapture ? (
|
||||
<button
|
||||
type="button"
|
||||
className="primary"
|
||||
onClick={() => onCapture(scope)}
|
||||
disabled={pendingScope === scope || Boolean(activeJob)}
|
||||
>
|
||||
{pendingScope === scope ? '投递中…' : `发起${scopeLabel(scope)}封存`}
|
||||
</button>
|
||||
) : (
|
||||
<span className="release-action-hint">发起封存需要知识工程师及以上权限</span>
|
||||
)
|
||||
) : (
|
||||
<span className="release-action-hint">{page?.capture_reason || '封存未接线'}</span>
|
||||
)}
|
||||
<button type="button" disabled title="生产独立预备份与恢复演练未接线">
|
||||
生产预备份
|
||||
</button>
|
||||
<button type="button" disabled title="生产写入需要独立授权闸口,当前未开放">
|
||||
同步到生产
|
||||
</button>
|
||||
<button type="button" disabled title="同步后校验与按版本回退未接线">
|
||||
校验 / 恢复
|
||||
</button>
|
||||
</div>
|
||||
<p className="release-target-foot">
|
||||
禁用项不是流程建议,而是能力状态:预备份、同步、校验恢复都没有接线,点击不会发生任何事。
|
||||
</p>
|
||||
</article>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{jobs.length > 0 ? (
|
||||
<section className="release-jobs" aria-label="封存作业">
|
||||
<h2>封存作业</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>投递时间</th>
|
||||
<th>目标</th>
|
||||
<th>状态</th>
|
||||
<th>作业号</th>
|
||||
<th>发起人</th>
|
||||
<th>最后错误</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{jobs.map((job) => (
|
||||
<tr key={job.job_id}>
|
||||
<td>{stamp(job.created_at)}</td>
|
||||
<td>{scopeLabel(job.scope)}</td>
|
||||
<td>{jobStateLabel[job.state] ?? job.state}</td>
|
||||
<td>
|
||||
<code>{job.capture_job}</code>
|
||||
</td>
|
||||
<td>{job.requested_by || '—'}</td>
|
||||
<td className="release-job-error">{job.last_error || '—'}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
<section className="release-storage" aria-label="存储">
|
||||
<h2>归档存储</h2>
|
||||
{page?.available ? (
|
||||
<>
|
||||
<dl className="release-storage-grid">
|
||||
<div>
|
||||
<dt>被版本引用的去重内容</dt>
|
||||
<dd>{formatBytes(page.content_bytes)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>blob 表观字节</dt>
|
||||
<dd>{formatBytes(page.blob_file_bytes)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>实际分配字节</dt>
|
||||
<dd>{formatBytes(page.blob_allocated_bytes)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>未被任何版本引用</dt>
|
||||
<dd>
|
||||
{page.unreferenced_blobs} 个 / {formatBytes(page.unreferenced_bytes)}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>清单文件</dt>
|
||||
<dd>{formatBytes(page.manifest_file_bytes)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>版本数</dt>
|
||||
<dd>{page.versions}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<p className="release-storage-note">
|
||||
去重内容按跨版本重新计算;这些都<strong>不是可回收空间</strong>。
|
||||
保留策略、依赖保护、清理预览都没有接线,自动清理保持关闭,页面不会删除任何东西。
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<p className="release-storage-note">{page?.reason || '归档未接线,存储口径不可读。'}</p>
|
||||
)}
|
||||
</section>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export function ReleaseTargets() {
|
||||
const auth = useOptionalAuth()
|
||||
const [page, setPage] = useState<LibrarySnapshotList | null>(null)
|
||||
const [jobs, setJobs] = useState<LibraryCaptureJob[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [expanded, setExpanded] = useState<string | null>(null)
|
||||
const [pendingScope, setPendingScope] = useState<string | null>(null)
|
||||
const [notice, setNotice] = useState<string | null>(null)
|
||||
|
||||
const load = useCallback(async (signal?: AbortSignal) => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const [snapshots, captures] = await Promise.all([
|
||||
fetchLibrarySnapshots(signal),
|
||||
fetchLibraryCaptures(signal),
|
||||
])
|
||||
setPage(snapshots)
|
||||
setJobs(captures)
|
||||
setError(null)
|
||||
} catch (loadError) {
|
||||
if ((loadError as Error).name === 'AbortError') return
|
||||
setError(loadError instanceof Error ? loadError.message : '加载整库发布状态失败')
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const controller = new AbortController()
|
||||
void load(controller.signal)
|
||||
return () => controller.abort()
|
||||
}, [load])
|
||||
|
||||
const busy = jobs.some((job) => ACTIVE_STATES.includes(job.state))
|
||||
useEffect(() => {
|
||||
if (!busy) return
|
||||
const timer = window.setInterval(() => {
|
||||
void load().catch(() => undefined)
|
||||
}, 3000)
|
||||
return () => window.clearInterval(timer)
|
||||
}, [busy, load])
|
||||
|
||||
const role = auth?.identity?.role
|
||||
const canCapture = (role === 'engineer' || role === 'admin') && page?.capture_available === true
|
||||
|
||||
const startCapture = async (scope: string) => {
|
||||
setPendingScope(scope)
|
||||
setNotice(null)
|
||||
try {
|
||||
const accepted = await enqueueLibraryCapture(scope)
|
||||
setNotice(
|
||||
accepted.reused
|
||||
? `该作业已存在:${scopeLabel(scope)} · ${accepted.capture_job}(状态 ${jobStateLabel[accepted.state] ?? accepted.state})`
|
||||
: `已投递封存作业:${scopeLabel(scope)} · ${accepted.capture_job}`
|
||||
)
|
||||
await load()
|
||||
} catch (captureError) {
|
||||
setNotice(captureError instanceof Error ? captureError.message : '发起封存失败')
|
||||
} finally {
|
||||
setPendingScope(null)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<ReleaseTargetsView
|
||||
page={page}
|
||||
jobs={jobs}
|
||||
loading={loading}
|
||||
error={error}
|
||||
notice={notice}
|
||||
expanded={expanded}
|
||||
pendingScope={pendingScope}
|
||||
canCapture={canCapture}
|
||||
onRefresh={() => void load()}
|
||||
onCapture={(scope) => void startCapture(scope)}
|
||||
onToggleExpanded={(snapshotID) => setExpanded(expanded === snapshotID ? null : snapshotID)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user