@@ -3,7 +3,7 @@ import { useContext, useEffect, useMemo, useState } from 'react'
import { fetchMonitorFiles , fetchMonitorOverview , fetchRunMetrics } from './monitor'
import type { RunMetrics } from './monitor'
import type { KnowledgeProgress , MonitorFilePage , MonitorOverview , MonitorStatus } from './monitor'
import { fetchJobFailures , fetchTestPublications , retryPublication , retryPublicationsBatch , startTestPublications } from './testPublications'
import { fetchJobFailures , fetchTestPublications , retryPublication , retryPublicationsBatch , cancelPublicationsBatch , startTestPublications } from './testPublications'
import type { JobFailure , ProcessingState , TestPublication , TestPublicationPage } from './testPublications'
import { fetchActiveUISettings , settingsRefreshDelays } from './uiSettings'
import { WorkspaceContextTabsSetter } from './workspaceContext'
@@ -14,7 +14,7 @@ const gb = (value: number) => `${(value / 1073741824).toFixed(1)}`
const scope = ( value : string ) = > value === 'internal' ? '对内' : value === 'external' ? '对外' : '混合'
const duration = ( seconds : number ) = > seconds <= 0 ? '完成' : seconds < 60 ? ` ${ seconds } 秒 ` : seconds < 3600 ? ` ${ Math . floor ( seconds / 60 ) } 分钟 ` : ` ${ ( seconds / 3600 ) . toFixed ( 1 ) } 小时 `
const statusLabels : Record < MonitorStatus , string > = { completed : 'completed' , pending : 'pending' , processing : 'processing' , finalizing : 'finalizing' , failed : 'failed' , cancelled : 'cancelled' }
const processingLabels : Record < ProcessingState , string > = { planned : '待入库' , pending : '等待解析' , processing : '解析中' , finalizing : '索引与增强' , completed : '成功' , failed : '失败' , stalled : '停滞' }
const processingLabels : Record < ProcessingState , string > = { planned : '待入库' , pending : '等待解析' , processing : '解析中' , finalizing : '索引与增强' , completed : '成功' , failed : '失败' , stalled : '停滞' , cancelled : '已取消' }
const secondsSince = ( iso : string ) = > Math . max ( 0 , Math . round ( ( Date . now ( ) - new Date ( iso ) . getTime ( ) ) / 1000 ) )
const adviceFor = ( stage : string , code : string ) = > {
@@ -85,6 +85,7 @@ interface ViewProps {
loading : boolean
error : string | null
retryingIDs? : string [ ]
cancellingIDs? : string [ ]
starting? : boolean
startMessage? : string
batchMessage? : string
@@ -98,6 +99,7 @@ interface ViewProps {
onLaneChange ? : ( lane : string ) = > void
onRetry ? : ( id : string ) = > void
onBatchRetry ? : ( ids : string [ ] ) = > void
onBatchCancel ? : ( ids : string [ ] ) = > void
onStart ? : ( ids : string [ ] ) = > void
onRefresh : ( ) = > void
}
@@ -116,6 +118,7 @@ export function WeKnoraMonitorView({
loading ,
error ,
retryingIDs = [ ] ,
cancellingIDs = [ ] ,
starting = false ,
startMessage = '' ,
batchMessage = '' ,
@@ -127,6 +130,7 @@ export function WeKnoraMonitorView({
onQueueScope = ( ) = > undefined ,
onRetry = ( ) = > undefined ,
onBatchRetry = ( ) = > undefined ,
onBatchCancel = ( ) = > undefined ,
onStart = ( ) = > undefined ,
onRefresh ,
} : ViewProps ) {
@@ -169,7 +173,7 @@ export function WeKnoraMonitorView({
< div className = "task-chain" aria-label = { ` 处理链 ${ item . title } ` } > { chainSteps ( item ) . map ( ( step ) = > < span key = { step . stage } className = { ` chain-step ${ step . state } ` } > { step . stage } { step . state === 'done' ? ' ✓' : step . state === 'bad' ? ' ✗' : step . state === 'active' ? ` 中 ${ duration ( secondsSince ( item . updated_at ) ) } ` : '' } < / span > ) } < / div >
< div className = { item . processing_state === 'failed' || item . processing_state === 'stalled' ? 'errline' : 'tiny muted-line' } > { item . processing_state === 'failed' || item . processing_state === 'stalled' ? adviceFor ( failureStage ( item ) , item . last_error ) : item . processing_state === 'planned' && ! item . can_start ? '正在从源头取回文件,完成后自动进入可处理状态' : item . can_start ? '文件已就绪,等待开始处理' : '无需操作,等待自动处理' } · < code > { item . id } < / code > < / div >
< / div >
< div className = "inbox-task-actions" > { item . can_retry ? < button className = "primary" disabled = { retryingIDs . includes ( item . id ) } onClick = { ( ) = > onRetry ( item . id ) } > { retryingIDs . includes ( item . id ) ? '重试中…' : '重试' } < / button > : null } < / div >
< div className = "inbox-task-actions" > { item . can_retry ? < button className = "primary" disabled = { retryingIDs . includes ( item . id ) } onClick = { ( ) = > onRetry ( item . id ) } > { retryingIDs . includes ( item . id ) ? '重试中…' : '重试' } < / button > : null } { item . can_retry ? < button disabled = { cancellingIDs . includes ( item . id ) || retryingIDs . length > 0 } title = "不再自动重试;原始记录保留,重新标记入库可再次处理" onClick = { ( ) = > onBatchCancel ( [ item . id ] ) } > { cancellingIDs . includes ( item . id ) ? '取消中…' : '不再处理' } < / button > : null } < / div >
< / article >
const emptyLane = ( text : string ) = > < div className = "empty-state" > { text } < / div >
return < main className = "page-shell weknora-monitor inbox-layout" >
@@ -191,7 +195,7 @@ export function WeKnoraMonitorView({
{ fetchingPlanned . length ? < p className = "tiny" > 其 中 { fetchingPlanned . length } 项 仍 在 从 源 头 取 件 , 取 回 后 自 动 可 处 理 。 < / p > : null }
< / section > : null }
{ lane === 'attention' ? < section className = "inbox-section" aria-label = "需人工处理" >
< div className = "section-head" > < h2 > 需 要 你 出 手 ( { attentionItems . length } ) < / h2 > < span className = "spacer" / > < button className = "danger" disabled = { ! batchTargets . length || retryingIDs . length > 0 } onClick = { ( ) = > onBatchRetry ( batchTargets ) } > { retryingIDs . length ? '重试中…' : ` 批量重试所选( ${ batchTargets . length } ) ` } < / button > < / div >
< div className = "section-head" > < h2 > 需 要 你 出 手 ( { attentionItems . length } ) < / h2 > < span className = "spacer" / > < button disabled = { ! batchTargets . length || cancellingIDs . length > 0 || retryingIDs . length > 0 } title = "不再自动重试(如源头就是空文档);原始记录保留,重新标记入库可再次处理" onClick = { ( ) = > onBatchCancel ( batchTargets ) } > { cancellingIDs . length ? '取消中…' : ` 批量取消所选( ${ batchTargets . length } ) ` } < / button > < button className = "danger" disabled = { ! batchTargets . length || retryingIDs . length > 0 } onClick = { ( ) = > onBatchRetry ( batchTargets ) } > { retryingIDs . length ? '重试中…' : ` 批量重试所选( ${ batchTargets . length } ) ` } < / button > < / div >
{ batchMessage ? < p className = "queue-batch-message" role = "status" > { batchMessage } < / p > : null }
{ attentionItems . length ? attentionItems . map ( actionTask ) : emptyLane ( '没有失败或停滞的任务。' ) }
< div className = "section-head sub" > < h3 > 死 信 ( 重 试 次 数 用 完 , 系 统 不 再 自 动 处 理 ) < / h3 > < span className = "tiny" > “ 源 头 取 件 ” = 从 钉 钉 / AList 把 原 始 文 件 拉 回 本 地 ; “ 上 传 解 析 ” = 把 文 件 送 进 知 识 库 做 解 析 。 死 信 只 是 失 败 任 务 的 登 记 表 , 不 会 改 动 原 始 记 录 ; 重 新 入 队 = 再 给 它 一 次 机 会 < / span > < / div >
@@ -224,7 +228,7 @@ export function WeKnoraMonitorView({
{ doneItems . length ? doneItems . map ( actionTask ) : emptyLane ( '当前页没有已完成任务;用全部任务视图翻页查看。' ) }
< / section > : null }
{ lane === 'queue' ? < section className = "inbox-section" aria-label = "全部任务" >
< div className = "section-head" > < h2 > 全 部 任 务 ( { queue . total } ) < / h2 > < span className = "spacer" / > < label > 目 标 知 识 库 < select aria-label = "队列目标知识库" value = { queueScope } onChange = { ( event ) = > onQueueScope ( event . target . value as 'internal' | 'external' | '' ) } > < option value = "" > 内 / 外 全 部 < / option > < option value = "internal" > 对 内 知 识 库 < / option > < option value = "external" > 对 外 知 识 库 < / option > < / select > < select aria-label = "队列状态" value = { queueStatus } onChange = { ( event ) = > onQueueStatus ( event . target . value as ProcessingState | '' ) } > < option value = "" > 全 部 状 态 < / option > < option value = "planned" > 待 入 库 < / option > < option value = "pending" > 等 待 解 析 < / option > < option value = "processing" > 解 析 中 < / option > < option value = "finalizing" > 索 引 与 增 强 < / option > < option value = "completed" > 成 功 < / option > < option value = "failed" > 失 败 < / option > < option value = "stalled" > 停 滞 < / option > < / select > < / label > < / div >
< div className = "section-head" > < h2 > 全 部 任 务 ( { queue . total } ) < / h2 > < span className = "spacer" / > < label > 目 标 知 识 库 < select aria-label = "队列目标知识库" value = { queueScope } onChange = { ( event ) = > onQueueScope ( event . target . value as 'internal' | 'external' | '' ) } > < option value = "" > 内 / 外 全 部 < / option > < option value = "internal" > 对 内 知 识 库 < / option > < option value = "external" > 对 外 知 识 库 < / option > < / select > < select aria-label = "队列状态" value = { queueStatus } onChange = { ( event ) = > onQueueStatus ( event . target . value as ProcessingState | '' ) } > < option value = "" > 全 部 状 态 < / option > < option value = "planned" > 待 入 库 < / option > < option value = "pending" > 等 待 解 析 < / option > < option value = "processing" > 解 析 中 < / option > < option value = "finalizing" > 索 引 与 增 强 < / option > < option value = "completed" > 成 功 < / option > < option value = "failed" > 失 败 < / option > < option value = "stalled" > 停 滞 < / option > < option value = "cancelled" > 已 取 消 < / option > < / select > < / label > < / div >
{ orderedQueue . length ? orderedQueue . map ( actionTask ) : ! loading ? emptyLane ( '当前筛选没有解析任务。' ) : null }
< / section > : null }
{ metrics ? < footer className = "monitor-strip" aria-label = "真实运行指标" > < div > 1 小 时 · 成 功 < b className = { metrics . short_window . failure_rate !== null && metrics . short_window . failure_rate > 5 ? 'bad' : 'good' } > { metrics . short_window . success_rate === null ? '数据不足' : ` ${ metrics . short_window . success_rate } % ` } < / b > < / div > < div > 24 小 时 · 成 功 < b > { metrics . long_window . success_rate === null ? '数据不足' : ` ${ metrics . long_window . success_rate } % ` } < / b > < / div > < div > p50 { metrics . short_window . duration_p50_seconds === null ? '—' : duration ( Math . round ( metrics . short_window . duration_p50_seconds ) ) } · p95 { metrics . short_window . duration_p95_seconds === null ? '—' : duration ( Math . round ( metrics . short_window . duration_p95_seconds ) ) } < / div > < div > Worker { metrics . active_workers } · 等 待 { metrics . queue . pending } · 运 行 { metrics . queue . running } { metrics . queue . failed ? < span className = "bad" > · 失 败 { metrics . queue . failed } < / span > : null } < / div > { overview ? . health . map ( ( service ) = > < div key = { service . key } > { service . name } < b className = { service . readiness === 'ready' ? 'good' : service . readiness === 'blocked' || service . readiness === 'down' ? 'bad' : '' } > { service . readiness === 'ready' ? '可接单' : service . readiness === 'degraded' ? '降级' : service . readiness === 'not_configured' ? '未配置' : service . readiness === 'down' ? '不可达' : '阻断' } < / b > < / div > ) } { overview ? < div > CPU { overview . host . cpu_percent . toFixed ( 0 ) } % · 内 存 { gb ( overview . host . memory_used_bytes ) } / { gb ( overview . host . memory_total_bytes ) } GB < / div > : null } < / footer > : null }
@@ -250,6 +254,7 @@ export function WeKnoraMonitor() {
const [ documentRefreshMs , setDocumentRefreshMs ] = useState ( 15000 )
const [ resourceRefreshMs , setResourceRefreshMs ] = useState ( 30000 )
const [ retryingIDs , setRetryingIDs ] = useState < string [ ] > ( [ ] )
const [ cancellingIDs , setCancellingIDs ] = useState < string [ ] > ( [ ] )
const [ starting , setStarting ] = useState ( false )
const [ startMessage , setStartMessage ] = useState ( '' )
const [ batchMessage , setBatchMessage ] = useState ( '' )
@@ -353,6 +358,21 @@ export function WeKnoraMonitor() {
setRetryingIDs ( [ ] )
}
}
const cancelBatch = async ( ids : string [ ] ) = > {
setCancellingIDs ( ids )
setBatchMessage ( '' )
try {
const result = await cancelPublicationsBatch ( ids , '解析队列批量取消(不再重试)' )
setError ( null )
const skipped = result . already_running + result . not_retryable
setBatchMessage ( ` 已取消 ${ result . started } 项,不再自动重试 ${ skipped ? ` ,跳过 ${ skipped } 项(处理中或不可取消) ` : '' } ;原始记录未删除,重新标记入库可再次处理 ` )
setDocumentRevision ( ( value ) = > value + 1 )
} catch ( cause ) {
setError ( cause instanceof Error ? cause . message : '批量取消失败' )
} finally {
setCancellingIDs ( [ ] )
}
}
const startPlans = async ( ids : string [ ] ) = > {
setStarting ( true )
@@ -368,5 +388,5 @@ export function WeKnoraMonitor() {
setStarting ( false )
}
}
return < WeKnoraMonitorView overview = { overview } files = { files } queue = { queue } plans = { plans } selectedKB = { selected } status = { status } queueStatus = { queueStatus } queueScope = { queueScope } loading = { loading } error = { error } retryingIDs = { retryingIDs } starting = { starting } startMessage = { startMessage } batchMessage = { batchMessage } failures = { failures } metrics = { metrics } onSelectKB = { ( kb ) = > { setSelected ( kb ) ; setStatus ( '' ) ; setFiles ( null ) } } onStatus = { ( value ) = > { setStatus ( value ) ; setFiles ( null ) } } onQueueStatus = { setQueueStatus } onQueueScope = { setQueueScope } lane = { lane } onLaneChange = { ( value ) = > setLane ( value as typeof lane ) } onRetry = { ( id ) = > void retryOne ( id ) } onBatchRetry = { ( ids ) = > void retryBatch ( ids ) } onStart = { ( ids ) = > void startPlans ( ids ) } onRefresh = { ( ) = > { setDocumentRevision ( ( value ) = > value + 1 ) ; setResourceRevision ( ( value ) = > value + 1 ) } } / >
return < WeKnoraMonitorView overview = { overview } files = { files } queue = { queue } plans = { plans } selectedKB = { selected } status = { status } queueStatus = { queueStatus } queueScope = { queueScope } loading = { loading } error = { error } retryingIDs = { retryingIDs } cancellingIDs = { cancellingIDs } starting = { starting } startMessage = { startMessage } batchMessage = { batchMessage } failures = { failures } metrics = { metrics } onSelectKB = { ( kb ) = > { setSelected ( kb ) ; setStatus ( '' ) ; setFiles ( null ) } } onStatus = { ( value ) = > { setStatus ( value ) ; setFiles ( null ) } } onQueueStatus = { setQueueStatus } onQueueScope = { setQueueScope } lane = { lane } onLaneChange = { ( value ) = > setLane ( value as typeof lane ) } onRetry = { ( id ) = > void retryOne ( id ) } onBatchRetry = { ( ids ) = > void retryBatch ( ids ) } onBatchCancel = { ( ids ) = > void cancelBatch ( ids ) } onStart = { ( ids ) = > void startPlans ( ids ) } onRefresh = { ( ) = > { setDocumentRevision ( ( value ) = > value + 1 ) ; setResourceRevision ( ( value ) = > value + 1 ) } } / >
}