Files
knowledge-governance/web/src/weKnoraDiagnostics.tsx
T
姚章浩 ce2a155ebc feat(settings): 知识库绑定按环境一次保存连接与内外库
原「知识库映射 → WeKnora 连接」把地址、文件和绑定分散在多处,页面无法输入密钥,
也看不到候选实例真实可读的库。现在测试 090 / 生产 090 各自一个工作区:草稿填地址
与 API Key,服务器真实分页列库并区分空库/无权限/不可达,选内外库后一次保存连接与
绑定,回读真实生效值。

服务端以修订号 + 行锁 + 单事务写连接、绑定与待入库重排;旧部署无新行时继续使用文件
凭据/默认绑定。密钥只存 AES-256-GCM 密文,主密钥在独立文件;换地址必须重录,旧密钥
不转发、不跨环境取用。消费端(readiness/上传轮询/列库/探活/生产列库)统一从该存储
解析当前连接,避免只保存了页面数据。

验证:go test ./...;前端 606 项;隔离 PostgreSQL 集成用例覆盖保存/冲突/重排/拒错;
make verify 在本提交上执行(结果见交付说明)。
2026-11-19 14:51:47 +08:00

102 lines
4.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 (
<div className="environment-cards" id="settings-weknora-diagnostics">
<article>
<b>测试 WeKnora</b>
<span>{testWeKnoraLabel(findHealth(monitor, 'WeKnora API'), undefined)}</span>
<small>{`${healthStateDetail(findHealth(monitor, 'WeKnora API'), undefined) || '端点探测:未配置'};解析队列 对内 ${
routingCapabilities.internal_enabled ? '已配置' : '未配置'
} · 对外 ${routingCapabilities.external_enabled ? '已配置' : '未配置'}`}</small>
<small className={`worker-capability ${workerCapabilities?.test_upload.state ?? 'unknown'}`}>
{testUploadLabel(workerCapabilities)}
{workerCapabilities ? `:${workerCapabilities.test_upload.detail}` : ''}
</small>
<small>{settings.test_weknora_base_url || '未配置地址'} · 凭据:服务器文件/加密存储,页面不回读</small>
</article>
<article className="production">
<b>生产 WeKnora</b>
<span>
{!productionEnabled
? '未启用'
: productionBackupRestoreVerified
? '已启用 · 可提交生产请求'
: '已启用 · 被阻断'}
</span>
<small>{`${productionWeKnoraProbe(monitor)};生产写入:${productionEnabled ? '开启' : '关闭'}`}</small>
<small>{settings.production_weknora_base_url || '未配置地址'} · 凭据:服务器文件/加密存储,页面不回读</small>
</article>
</div>
)
}