F01:新增 /api/v1/system/worker-capabilities,按 job_types 判定 test.upload 执行器是否注册, 服务卡片分「地址可达 / 凭据与库读取 / 执行器能力」三行。 F04:routing-bindings 返回 LIBRARY_SOURCE_KB_* 与一致性,设置页同屏显示入库目标与封存源。 结构:测试绑定与生产目标合并为「知识库映射」。
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
// Worker 能力心跳:页面的“执行器能力”只信 worker 自己上报的记录。
|
||||
export interface WorkerCapability {
|
||||
worker_id: string
|
||||
job_types: string[]
|
||||
alive: boolean
|
||||
last_seen_at: string
|
||||
}
|
||||
|
||||
export interface WorkerCapabilities {
|
||||
test_upload: { state: 'enabled' | 'disabled' | 'stale' | 'unknown'; consumers: number; detail: string }
|
||||
workers: WorkerCapability[]
|
||||
}
|
||||
|
||||
const record = (value: unknown): value is Record<string, unknown> =>
|
||||
Boolean(value) && typeof value === 'object' && !Array.isArray(value)
|
||||
|
||||
export async function fetchWorkerCapabilities(signal?: AbortSignal): Promise<WorkerCapabilities> {
|
||||
const response = await fetch('/api/v1/system/worker-capabilities', { credentials: 'include', signal })
|
||||
if (!response.ok) throw new Error(`读取执行器能力失败(${response.status})`)
|
||||
const body = (await response.json()) as { data?: unknown }
|
||||
const data = record(body.data) ? body.data : {}
|
||||
const upload = record(data.test_upload) ? data.test_upload : {}
|
||||
const state = upload.state
|
||||
const workers = Array.isArray(data.workers)
|
||||
? data.workers.filter(record).map((item) => ({
|
||||
worker_id: typeof item.worker_id === 'string' ? item.worker_id : '',
|
||||
job_types: Array.isArray(item.job_types)
|
||||
? item.job_types.filter((t): t is string => typeof t === 'string')
|
||||
: [],
|
||||
alive: item.alive === true,
|
||||
last_seen_at: typeof item.last_seen_at === 'string' ? item.last_seen_at : '',
|
||||
}))
|
||||
: []
|
||||
return {
|
||||
test_upload: {
|
||||
state: state === 'enabled' || state === 'disabled' || state === 'stale' ? state : 'unknown',
|
||||
consumers: typeof upload.consumers === 'number' ? upload.consumers : 0,
|
||||
detail: typeof upload.detail === 'string' ? upload.detail : '能力心跳不可用',
|
||||
},
|
||||
workers,
|
||||
}
|
||||
}
|
||||
|
||||
export const testUploadLabel = (capabilities: WorkerCapabilities | null): string => {
|
||||
if (!capabilities) return '执行器:未知'
|
||||
switch (capabilities.test_upload.state) {
|
||||
case 'enabled':
|
||||
return `执行器:已启用(${capabilities.test_upload.consumers} 个 worker)`
|
||||
case 'disabled':
|
||||
return '执行器:已停用(不会消费上传/解析)'
|
||||
case 'stale':
|
||||
return '执行器:无心跳(worker 未运行)'
|
||||
default:
|
||||
return '执行器:未知'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user