095aa3ed68
build / build (push) Failing after 26s
- 为什么:白盒复检 P1——平台侧文件详情抽屉 503 只有文案,需求 §8 要求跳转链接;/monitor/tasks 行没有 URL。 - 做什么:抽出 KnowledgeBaseConsoleURL,finding 与 /monitor/tasks 共用同一拼接;handler 用当前生效测试端点填 weknora_url,前端抽屉透传给 WeKnoraProgress;openapi/需求 §7 同步。 - 补证据:stage=weknora 真库合并用例;对账扫描改为真实 HTTP 桩断言零写;progress 投影断言上游密钥字段不外泄。 - 验证:make verify 17 项 success;go test ./... exit 0;web 648 测试 + build;monitor_tasks 真库集成用例 PASS。
167 lines
5.3 KiB
TypeScript
167 lines
5.3 KiB
TypeScript
export interface MonitorTask {
|
||
history?: { at: string; kind: string; detail: string }[]
|
||
id: string
|
||
title: string
|
||
path: string
|
||
node_id: string
|
||
parent_node_id: string
|
||
source_id: string
|
||
source_name: string
|
||
target_scope: string
|
||
target_kb: string
|
||
document_id?: string
|
||
// 目标测试知识库的控制台链接;后端按当前生效测试端点生成,未配置时为空。
|
||
weknora_url?: string
|
||
action: string
|
||
stage: string
|
||
status: string
|
||
detail: string
|
||
updated_at: string
|
||
retry_kind: string
|
||
failure_id: string
|
||
retry_count: number
|
||
version_id: string
|
||
}
|
||
export interface MonitorTaskPage {
|
||
items: MonitorTask[]
|
||
total: number
|
||
limit: number
|
||
offset: number
|
||
sources: { id: string; name: string }[]
|
||
targets: { id: string; name: string; scope?: string }[]
|
||
bindings: MonitorBindings
|
||
retryable: number
|
||
}
|
||
export interface MonitorBindings {
|
||
internal: string
|
||
external: string
|
||
}
|
||
export const shortID = (id: string) => (id.length > 8 ? id.slice(0, 8) : id)
|
||
export const isCurrentTarget = (id: string, scope: string, bindings: MonitorBindings) =>
|
||
Boolean(id) &&
|
||
(scope === 'external' ? bindings.external === id : scope === 'internal' ? bindings.internal === id : false)
|
||
// 同名目标(例如两个“对内知识库”)只靠名称无法区分:名称 + 短 ID,
|
||
// 并明确当前绑定/历史;完整 ID 留在详情里。
|
||
export const targetLabel = (name: string, id: string, scope: string, bindings: MonitorBindings) =>
|
||
`${name || '目标知识库'} · ${shortID(id)}${isCurrentTarget(id, scope, bindings) ? ' · 当前绑定' : ' · 历史'}`
|
||
export interface MonitorFilters {
|
||
q: string
|
||
source: string
|
||
scope: string
|
||
target: string
|
||
action: string
|
||
status: string
|
||
stage: string
|
||
since: string
|
||
until: string
|
||
}
|
||
export const defaultMonitorFilters: MonitorFilters = {
|
||
q: '',
|
||
source: '',
|
||
scope: '',
|
||
target: '',
|
||
action: '',
|
||
status: 'active',
|
||
stage: '',
|
||
since: '',
|
||
until: '',
|
||
}
|
||
export const actionLabels: Record<string, string> = { add: '新增', update: '更新', remove: '移除' }
|
||
export const stageLabels: Record<string, string> = {
|
||
waiting: '等待调度',
|
||
fetch: '取件',
|
||
upload: '上传',
|
||
parsing: '解析',
|
||
indexing: '索引增强',
|
||
removal: '测试库移除',
|
||
finished: '结束',
|
||
}
|
||
// 阶段筛选按需求 §8 合并「解析」「索引增强」为「WeKnora 处理中」;行内展示仍用
|
||
// stageLabels 的细粒度阶段,两者不要互相替代。
|
||
export const stageFilterLabels: Record<string, string> = {
|
||
waiting: '等待调度',
|
||
fetch: '取件',
|
||
upload: '上传',
|
||
weknora: 'WeKnora 处理中',
|
||
removal: '测试库移除',
|
||
finished: '结束',
|
||
}
|
||
export const taskStatusLabels: Record<string, string> = {
|
||
waiting: '等待中',
|
||
running: '执行中',
|
||
retrying: '重试中',
|
||
attention: '需人工处理',
|
||
completed: '已完成',
|
||
cancelled: '已取消',
|
||
}
|
||
export const canRetryTask = (item: MonitorTask) =>
|
||
item.status === 'attention' && ['upload', 'fetch', 'remove'].includes(item.retry_kind)
|
||
const record = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null
|
||
export async function fetchMonitorTasks(
|
||
filters: Partial<MonitorFilters> & { id?: string },
|
||
offset = 0,
|
||
limit = 20,
|
||
signal?: AbortSignal
|
||
): Promise<MonitorTaskPage> {
|
||
const query = new URLSearchParams({ limit: String(limit), offset: String(offset) })
|
||
Object.entries(filters).forEach(([k, v]) => {
|
||
if (v) query.set(k, v)
|
||
})
|
||
const response = await fetch(`/api/v1/monitor/tasks?${query}`, { headers: { Accept: 'application/json' }, signal })
|
||
if (!response.ok) throw new Error(`加载文件处理状态失败(HTTP ${response.status})`)
|
||
const value: unknown = await response.json()
|
||
if (!record(value) || !record(value.data)) throw new Error('文件处理响应无效')
|
||
const d = value.data
|
||
const count = (v: unknown) => Number.isInteger(v) && Number(v) >= 0
|
||
if (
|
||
!Array.isArray(d.items) ||
|
||
!count(d.total) ||
|
||
!count(d.limit) ||
|
||
!count(d.offset) ||
|
||
!count(d.retryable) ||
|
||
!Array.isArray(d.sources) ||
|
||
!Array.isArray(d.targets)
|
||
)
|
||
throw new Error('文件处理分页响应无效')
|
||
for (const item of d.items) {
|
||
if (
|
||
!record(item) ||
|
||
![
|
||
'id',
|
||
'title',
|
||
'path',
|
||
'node_id',
|
||
'parent_node_id',
|
||
'source_id',
|
||
'source_name',
|
||
'target_scope',
|
||
'target_kb',
|
||
'action',
|
||
'stage',
|
||
'status',
|
||
'detail',
|
||
'updated_at',
|
||
'retry_kind',
|
||
'failure_id',
|
||
'version_id',
|
||
].every((k) => typeof item[k] === 'string') ||
|
||
!count(item.retry_count) ||
|
||
!Object.hasOwn(actionLabels, String(item.action)) ||
|
||
!Object.hasOwn(stageLabels, String(item.stage)) ||
|
||
!Object.hasOwn(taskStatusLabels, String(item.status))
|
||
)
|
||
throw new Error('文件处理条目无效')
|
||
}
|
||
for (const option of [...d.sources, ...d.targets])
|
||
if (!record(option) || typeof option.id !== 'string' || typeof option.name !== 'string')
|
||
throw new Error('文件处理筛选项无效')
|
||
const bindings = record(d.bindings) ? d.bindings : {}
|
||
return {
|
||
...d,
|
||
bindings: {
|
||
internal: typeof bindings.internal === 'string' ? bindings.internal : '',
|
||
external: typeof bindings.external === 'string' ? bindings.external : '',
|
||
},
|
||
} as unknown as MonitorTaskPage
|
||
}
|