import type { MonitorOverview } from './monitor' import type { CatalogRoutingCapabilities } from './sourceCatalog' import type { WorkerCapabilities } from './systemCapabilities' import { testUploadLabel } from './systemCapabilities' import type { UISettings } from './uiSettings' type ServiceHealthView = MonitorOverview['health'][number] type ServiceView = MonitorOverview['services'][number] // 连接卡只读诊断:知识库绑定的保存入口已收敛到「知识库绑定」主表单, // 这里保留原链路需要的探活/执行器状态,不再提供第二个保存路径。 export const findHealth = (monitor: MonitorOverview | null, name: string): ServiceHealthView | undefined => (monitor?.health || []).find((item) => item.name === name || item.name.startsWith(name)) export const healthStateLabel = (health: ServiceHealthView | undefined, service: ServiceView | undefined): string => { if (!health) { if (!service) return '待配置' return service.state === 'healthy' ? '正常' : service.state === 'unknown' ? '未接入' : '需关注' } if (health.readiness === 'ready') return '可达 · 可接单' if (health.readiness === 'not_configured') return '状态未知 · 未配置' if (health.readiness === 'not_applicable') return '未部署' return health.liveness === 'up' ? '可达 · 不可接单' : '不可达 · 不可接单' } export const testWeKnoraLabel = (health: ServiceHealthView | undefined, service: ServiceView | undefined): string => { const label = healthStateLabel(health, service) return label === '可达 · 可接单' ? '接口可达 · 执行器未验证' : label } export const healthStateDetail = (health: ServiceHealthView | undefined, service: ServiceView | undefined): string => { if (!health) return service?.detail || '真实 Provider 未接入' const success = health.last_success_at ? `最近成功 ${new Date(health.last_success_at).toLocaleTimeString('zh-CN', { hour12: false })}` : '' if (health.readiness === 'ready') return [`延迟 ${health.latency_ms}ms`, success].filter(Boolean).join(';') const failures = health.consecutive_failures ? `连续失败${health.consecutive_failures}次` : '' return [health.reason, success, failures].filter(Boolean).join(';') } export const productionWeKnoraProbe = (monitor: MonitorOverview | null): string => { const health = findHealth(monitor, '生产 WeKnora') if (!health) return '端点探测:暂无真实探测结果' if (!health.configured) return '端点探测:未配置' const label = health.liveness === 'up' ? health.readiness === 'ready' ? '端点可达 · 未做接单验证' : '端点可达 · 不可接单' : '端点不可达' const detail = healthStateDetail(health, undefined) return `端点探测:${label}${detail ? `(${detail})` : ''}` } export interface WeKnoraConnectionDiagnosticsProps { settings: UISettings monitor: MonitorOverview | null routingCapabilities: CatalogRoutingCapabilities workerCapabilities?: WorkerCapabilities | null productionEnabled: boolean productionBackupRestoreVerified?: boolean } export function WeKnoraConnectionDiagnostics({ settings, monitor, routingCapabilities, workerCapabilities = null, productionEnabled, productionBackupRestoreVerified = false, }: WeKnoraConnectionDiagnosticsProps) { return (
测试 WeKnora {testWeKnoraLabel(findHealth(monitor, 'WeKnora API'), undefined)} {`${healthStateDetail(findHealth(monitor, 'WeKnora API'), undefined) || '端点探测:未配置'};解析队列 对内 ${ routingCapabilities.internal_enabled ? '已配置' : '未配置' } · 对外 ${routingCapabilities.external_enabled ? '已配置' : '未配置'}`} {testUploadLabel(workerCapabilities)} {workerCapabilities ? `:${workerCapabilities.test_upload.detail}` : ''} {settings.test_weknora_base_url || '未配置地址'} · 凭据:服务器文件/加密存储,页面不回读
生产 WeKnora {!productionEnabled ? '未启用' : productionBackupRestoreVerified ? '已启用 · 可提交生产请求' : '已启用 · 被阻断'} {`${productionWeKnoraProbe(monitor)};生产写入:${productionEnabled ? '开启' : '关闭'}`} {settings.production_weknora_base_url || '未配置地址'} · 凭据:服务器文件/加密存储,页面不回读
) }