3da82d48d9
build / build (push) Failing after 2m22s
- 原「服务配置」更名为「AI 模型连接」,只保留问答分析与中文翻译共用的模型连接 - 测试/生产 WeKnora 地址、生产租户与知识库 ID 迁入「知识库映射」,与入库/封存/生产目标同屏 - 连接配置独立草稿与独立保存,刷新策略不夹带未保存地址 - 同步 README、运维手册、验收清单入口路径
243 lines
11 KiB
TypeScript
243 lines
11 KiB
TypeScript
import { useEffect, useState } from 'react'
|
||
|
||
import type { MonitorOverview } from './monitor'
|
||
import { serviceSettingsInput } from './settingsInputs'
|
||
import type { CatalogRoutingCapabilities } from './sourceCatalog'
|
||
import type { WorkerCapabilities } from './systemCapabilities'
|
||
import { testUploadLabel } from './systemCapabilities'
|
||
import { validKnowledgeBaseID, validProductionTenantID, validServiceEndpoint } from './uiSettings'
|
||
import type { UISettings, UISettingsCandidateInput } from './uiSettings'
|
||
|
||
type ServiceHealthView = MonitorOverview['health'][number]
|
||
type ServiceView = MonitorOverview['services'][number]
|
||
|
||
// 连接分区只保留四项可写值(测试地址、生产地址、生产 ID、知识库 ID),
|
||
// 依赖与解析队列的状态仍按真实探测呈现,不写死。
|
||
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' ? '可达 · 不可接单' : '不可达 · 不可接单'
|
||
}
|
||
|
||
// 测试 WeKnora 卡片只证明“接口就绪”:readiness 不覆盖上传/解析执行器,
|
||
// 所以不能沿用“可接单”这种承诺式措辞。
|
||
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(';')
|
||
}
|
||
|
||
// 生产 WeKnora 卡片:端点可达性来自真实探测,写入门禁来自生产开关,两者分开呈现。
|
||
// 生产侧只做探活(/health),不做一次真实读写,所以接单能力永远是「未做接单验证」,
|
||
// 不跟着别处的「可达 · 可接单」一起含糊过去。
|
||
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 WeKnoraConnectionsProps {
|
||
settings: UISettings
|
||
monitor: MonitorOverview | null
|
||
routingCapabilities: CatalogRoutingCapabilities
|
||
workerCapabilities?: WorkerCapabilities | null
|
||
productionEnabled: boolean
|
||
productionBackupRestoreVerified?: boolean
|
||
isAdmin: boolean
|
||
saving: boolean
|
||
saveMessage: string | null
|
||
onSave: (input: UISettingsCandidateInput) => void
|
||
}
|
||
|
||
// 「知识库映射 → WeKnora 连接」:地址由管理员在页面维护,保存前后端会真做一次
|
||
// 探活与列库核验;凭据仍是服务器文件引用,页面只显示状态、不回读也不接受录入。
|
||
export function WeKnoraConnections({
|
||
settings,
|
||
monitor,
|
||
routingCapabilities,
|
||
workerCapabilities = null,
|
||
productionEnabled,
|
||
productionBackupRestoreVerified = false,
|
||
isAdmin,
|
||
saving,
|
||
saveMessage,
|
||
onSave,
|
||
}: WeKnoraConnectionsProps) {
|
||
const [endpoint, setEndpoint] = useState<string>(settings.production_weknora_base_url ?? '')
|
||
const [testEndpoint, setTestEndpoint] = useState<string>(settings.test_weknora_base_url ?? '')
|
||
const [productionTenantID, setProductionTenantID] = useState<string>(settings.production_tenant_id ?? '')
|
||
const [productionKnowledgeBaseID, setProductionKnowledgeBaseID] = useState<string>(
|
||
settings.production_knowledge_base_id ?? ''
|
||
)
|
||
|
||
useEffect(() => {
|
||
setEndpoint(settings.production_weknora_base_url)
|
||
setTestEndpoint(settings.test_weknora_base_url)
|
||
setProductionTenantID(settings.production_tenant_id)
|
||
setProductionKnowledgeBaseID(settings.production_knowledge_base_id)
|
||
}, [settings])
|
||
|
||
const endpointValid = validServiceEndpoint(endpoint)
|
||
const testEndpointValid = validServiceEndpoint(testEndpoint)
|
||
const productionTenantIDValid = validProductionTenantID(productionTenantID)
|
||
const productionKnowledgeBaseIDValid = validKnowledgeBaseID(productionKnowledgeBaseID)
|
||
const valid = endpointValid && testEndpointValid && productionTenantIDValid && productionKnowledgeBaseIDValid
|
||
const dirty =
|
||
testEndpoint.trim() !== settings.test_weknora_base_url ||
|
||
endpoint.trim() !== settings.production_weknora_base_url ||
|
||
productionTenantID.trim() !== settings.production_tenant_id ||
|
||
productionKnowledgeBaseID.trim() !== settings.production_knowledge_base_id
|
||
|
||
return (
|
||
<section className="settings-panel wide" id="settings-weknora-connections">
|
||
<div className="settings-section-heading">
|
||
<div>
|
||
<h2>WeKnora 连接</h2>
|
||
<p>
|
||
测试与生产各自的地址在这里维护;保存前后端会真做一次探活与列库核验。凭据由服务器文件引用提供,
|
||
页面只显示是否已配置,不回读、也不能在这里录入。
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div className="environment-cards">
|
||
<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>
|
||
</article>
|
||
<article className="production">
|
||
<b>生产 WeKnora</b>
|
||
<span>
|
||
{!productionEnabled
|
||
? '未启用'
|
||
: productionBackupRestoreVerified
|
||
? '已启用 · 可提交生产请求'
|
||
: '已启用 · 被阻断'}
|
||
</span>
|
||
<small>{`${productionWeKnoraProbe(monitor)};生产写入:${productionEnabled ? '开启' : '关闭'};凭据:服务器文件引用,页面不回读`}</small>
|
||
</article>
|
||
</div>
|
||
{isAdmin ? (
|
||
<>
|
||
<div className="safe-setting-grid production-endpoint-form">
|
||
<label>
|
||
测试地址
|
||
<input
|
||
value={testEndpoint}
|
||
onChange={(event) => setTestEndpoint(event.target.value)}
|
||
placeholder="https://weknora.test.example"
|
||
aria-invalid={!testEndpointValid}
|
||
/>
|
||
</label>
|
||
<label>
|
||
生产地址
|
||
<input
|
||
value={endpoint}
|
||
onChange={(event) => setEndpoint(event.target.value)}
|
||
placeholder="https://weknora.prod.example"
|
||
aria-invalid={!endpointValid}
|
||
/>
|
||
</label>
|
||
</div>
|
||
<details className="settings-details">
|
||
<summary>生产核验参数(仅用于核验,不决定发布写入目标)</summary>
|
||
<div className="safe-setting-grid">
|
||
<label>
|
||
生产租户 ID
|
||
<input
|
||
value={productionTenantID}
|
||
onChange={(event) => setProductionTenantID(event.target.value)}
|
||
placeholder="10000"
|
||
aria-invalid={!productionTenantIDValid}
|
||
/>
|
||
</label>
|
||
<label>
|
||
知识库 ID
|
||
<input
|
||
value={productionKnowledgeBaseID}
|
||
onChange={(event) => setProductionKnowledgeBaseID(event.target.value)}
|
||
placeholder="生产知识库 ID"
|
||
aria-invalid={!productionKnowledgeBaseIDValid}
|
||
/>
|
||
</label>
|
||
</div>
|
||
<small>
|
||
这两项用于确认生产端确实存在目标库、租户归属正确;整库发布的实际写入目标见下方「生产知识库绑定」,
|
||
由部署配置决定,不在本页修改。
|
||
</small>
|
||
</details>
|
||
<button
|
||
onClick={() =>
|
||
onSave(
|
||
serviceSettingsInput(settings, {
|
||
testEndpoint,
|
||
endpoint,
|
||
productionTenantID,
|
||
productionKnowledgeBaseID,
|
||
})
|
||
)
|
||
}
|
||
disabled={saving || !valid || !dirty}
|
||
>
|
||
{saving ? '正在验证并启用…' : '保存并校验连接'}
|
||
</button>
|
||
<details className="settings-details">
|
||
<summary>保存规则与核验说明</summary>
|
||
<small>
|
||
四项留空即表示未配置。地址只接受 http(s) 源地址(不能带用户名密码、查询串或 # 片段,
|
||
凭据一律走文件引用);生产租户 ID 为十进制数字;知识库 ID 粘贴 URL 不会通过。
|
||
保存会生成修订、真实验证后原子启用;端点回答“没有这个知识库”或租户不符会拒收,
|
||
端点抖动、鉴权失败或未配置生产凭据只警告不拦。
|
||
</small>
|
||
</details>
|
||
{valid ? null : (
|
||
<p className="error-message" role="alert">
|
||
格式不合法:地址需 http:// 或 https:// 开头的纯地址,不能带用户名密码、? 查询串或 # 片段;生产 ID
|
||
需为十进制数字;知识库 ID 不能含空格、/、?、# 或 \。
|
||
</p>
|
||
)}
|
||
{saveMessage ? (
|
||
<p className="success-message" role="status">
|
||
{saveMessage}
|
||
</p>
|
||
) : null}
|
||
</>
|
||
) : (
|
||
<small>
|
||
仅管理员可修改 WeKnora 连接;当前值:测试地址 {settings.test_weknora_base_url || '未配置'} · 生产地址{' '}
|
||
{settings.production_weknora_base_url || '未配置'} · 生产 ID {settings.production_tenant_id || '未配置'} ·
|
||
知识库 ID {settings.production_knowledge_base_id || '未配置'}。
|
||
</small>
|
||
)}
|
||
</section>
|
||
)
|
||
}
|