0f7b8987b4
为什么:测试机工作台要长时间盯着看。原配色是深色侧栏 + 三种"主按钮"
(全局深藏青、监控页蓝、问答页黑),各模块页头字号/边距/是否装卡片各不相同;
另有一处真缺陷:全局 button:hover:not(:disabled) 特异性高于 .nav-item:hover,
悬停导航时被刷成白底,选中项文字几乎看不见。
改了什么:
- 色板改取越疆官网 dobot.cn:品牌钴蓝 #0039C8 为全站唯一强调/主操作色,
文字与底色改为不带蓝紫偏色的中性灰(用户反馈紫色费眼);卡片细边 + 极轻投影。
- 侧栏改为明亮底,选中项浅钴蓝底 + 钴蓝字;悬停规则补 :not(:disabled) 修复白底。
导航字号/点击区保持 16px / 44px(沿用 8d44d54 的放大决定)。
- 新增唯一一份 .page-header / .page-title / .page-subtitle;版本记录、系统设置、
发布管理接入(版本记录页头不再装卡片),删掉各自重复的标题字号规则;
page-shell 改为 max-width,模块自己的 1800/1500 上限终于生效。
- 版本记录、系统设置、问答同步状态里的硬编码蓝/石板灰映射回令牌;顺带修正
6 个从未定义的变量(--border/--card/--accent/--brand 等)——它们此前只靠
回退值或干脆不生效。
不改业务语义、权限、确认流程与接口调用。
验证:npm run typecheck、vitest 全量(110 文件 / 568 用例)通过;浏览器只读核对
导航悬停色、六个模块页头左缘/字号/字重一致。
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
606 lines
28 KiB
TypeScript
606 lines
28 KiB
TypeScript
import { useCallback, useEffect, useState } from 'react'
|
||
|
||
import { BackupScheduleSection } from './BackupScheduleSection'
|
||
import { LibraryStorageSection } from './LibraryStorageSection'
|
||
import { QAModelSettings } from './QAModelSettings'
|
||
import { MembersSection } from './MembersSection'
|
||
import { DingtalkAccountStatus, SourceManagementDetails, SourceSettingsCard } from './SourceManagement'
|
||
import { RoutingBindingsSection } from './RoutingBindingsSection'
|
||
import { ProductionBindingsSection } from './ProductionBindingsSection'
|
||
import { SourceWizard } from './SourceWizard'
|
||
import { useOptionalAuth } from './auth'
|
||
import { fetchMonitorOverview } from './monitor'
|
||
import type { MonitorOverview } from './monitor'
|
||
import { fetchReleaseCapabilities } from './reviewRelease'
|
||
import { fetchCatalogRoutingCapabilities, fetchCatalogSources } from './sourceCatalog'
|
||
import type { CatalogRoutingCapabilities, CatalogSource } from './sourceCatalog'
|
||
import { archiveSourceConnection, fetchSourceConnectionList } from './sourceConnections'
|
||
import type { SourceConnectionListItem } from './sourceConnections'
|
||
import {
|
||
activateUISettings,
|
||
createUISettingsCandidate,
|
||
fetchActiveUISettings,
|
||
validKnowledgeBaseID,
|
||
validProductionTenantID,
|
||
validServiceEndpoint,
|
||
} from './uiSettings'
|
||
import type { UISettings, UISettingsCandidateInput } from './uiSettings'
|
||
import './systemSettings.css'
|
||
|
||
interface Props {
|
||
sources: CatalogSource[]
|
||
connections: SourceConnectionListItem[]
|
||
monitor: MonitorOverview | null
|
||
settings: UISettings | null
|
||
productionEnabled: boolean
|
||
productionBackupRestoreVerified?: boolean
|
||
routingCapabilities: CatalogRoutingCapabilities
|
||
loading: boolean
|
||
saving: boolean
|
||
error: string | null
|
||
saveMessage: string | null
|
||
onSave: (input: UISettingsCandidateInput) => void
|
||
onSourcesChanged: () => void
|
||
onRefresh: () => void
|
||
initialSection?: SectionKey
|
||
}
|
||
|
||
type SectionKey = 'sources' | 'services' | 'bindings' | 'production-bindings' | 'storage' | 'refresh' | 'members'
|
||
|
||
const sections: { key: SectionKey; label: string; adminOnly?: boolean }[] = [
|
||
{ key: 'sources', label: '数据源配置' },
|
||
{ key: 'services', label: '服务配置' },
|
||
{ key: 'bindings', label: '测试知识库绑定' },
|
||
{ key: 'production-bindings', label: '生产知识库绑定' },
|
||
{ key: 'storage', label: '存储与备份' },
|
||
{ key: 'refresh', label: '刷新策略' },
|
||
{ key: 'members', label: '成员与角色', adminOnly: true },
|
||
] as { key: SectionKey; label: string; adminOnly?: boolean }[]
|
||
|
||
const sourceTypeLabels: Record<string, string> = {
|
||
dingtalk: '钉钉知识库',
|
||
pp: 'PP 资料下载中心',
|
||
alist: 'AList 文件源',
|
||
manual: '本地手工导入',
|
||
}
|
||
|
||
// 「数据源配置」只保留两个入口:**dws 导入**(按当前钉钉账号发现知识库与钉盘空间)
|
||
// 与 **PP 导入**。AList 已由钉盘文件替代、钉钉知识库一律走当前账号发现、本地手工与
|
||
// PP legacy 也下架了:本页只列 PP 来源。下架用归档(archived_at)实现,不删数据 ——
|
||
// 需要时用 dws 重新登记同名来源即原地复活(见 postgres.RegisterDingtalkSpace)。
|
||
export const ppSourceConnections = (connections: SourceConnectionListItem[]) =>
|
||
connections.filter((item) => item.source_type === 'pp')
|
||
|
||
const secondsLabel = (value: number) =>
|
||
value < 60 ? `${value}秒` : value < 3600 ? `${value / 60}分钟` : `${value / 3600}小时`
|
||
export const visibleSaveMessage = (message: string | null, dirty: boolean) => (dirty ? null : message)
|
||
|
||
type ServiceHealthView = MonitorOverview['health'][number]
|
||
type ServiceView = MonitorOverview['services'][number]
|
||
|
||
// 服务配置只保留四项可写值(测试地址、生产地址、生产 ID、知识库 ID),
|
||
// 依赖与解析队列的状态仍按真实探测呈现,不写死。
|
||
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 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 function SystemSettingsView({
|
||
sources,
|
||
connections,
|
||
monitor,
|
||
settings,
|
||
productionEnabled,
|
||
productionBackupRestoreVerified = false,
|
||
routingCapabilities,
|
||
loading,
|
||
saving,
|
||
error,
|
||
saveMessage,
|
||
onSave,
|
||
onSourcesChanged,
|
||
initialSection = 'sources',
|
||
}: Props) {
|
||
const auth = useOptionalAuth()
|
||
const identity = auth?.identity ?? null
|
||
const [section, setSection] = useState<SectionKey>(initialSection)
|
||
const [documentRefresh, setDocumentRefresh] = useState<15 | 30 | 60>(settings?.document_refresh_seconds ?? 15)
|
||
const [resourceRefresh, setResourceRefresh] = useState<30 | 60>(settings?.resource_refresh_seconds ?? 30)
|
||
const [stalled, setStalled] = useState<1800 | 3600>(settings?.stalled_after_seconds ?? 1800)
|
||
const [finalizing, setFinalizing] = useState<7200 | 14400>(settings?.finalizing_after_seconds ?? 7200)
|
||
const [concurrency, setConcurrency] = useState<number>(settings?.ingestion_concurrency ?? 2)
|
||
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 ?? ''
|
||
)
|
||
const [dirty, setDirty] = useState(false)
|
||
|
||
// 统一入口后,清单里列全部来源(钉钉知识库 / 钉盘 / PP),不再只显示 PP。
|
||
const listedConnections = connections
|
||
|
||
useEffect(() => {
|
||
if (!settings) return
|
||
setDocumentRefresh(settings.document_refresh_seconds)
|
||
setResourceRefresh(settings.resource_refresh_seconds)
|
||
setStalled(settings.stalled_after_seconds)
|
||
setFinalizing(settings.finalizing_after_seconds)
|
||
setConcurrency(settings.ingestion_concurrency)
|
||
setEndpoint(settings.production_weknora_base_url)
|
||
setTestEndpoint(settings.test_weknora_base_url)
|
||
setProductionTenantID(settings.production_tenant_id)
|
||
setProductionKnowledgeBaseID(settings.production_knowledge_base_id)
|
||
setDirty(false)
|
||
}, [settings])
|
||
|
||
const canSave = Boolean(settings && !saving)
|
||
const isAdmin = identity?.role === 'admin'
|
||
const endpointValid = validServiceEndpoint(endpoint)
|
||
const testEndpointValid = validServiceEndpoint(testEndpoint)
|
||
const productionTenantIDValid = validProductionTenantID(productionTenantID)
|
||
const productionKnowledgeBaseIDValid = validKnowledgeBaseID(productionKnowledgeBaseID)
|
||
const serviceSettingsValid =
|
||
endpointValid && testEndpointValid && productionTenantIDValid && productionKnowledgeBaseIDValid
|
||
const serviceSettingsDirty = Boolean(
|
||
settings &&
|
||
(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)
|
||
)
|
||
const candidateInput = (overrides: Partial<UISettingsCandidateInput> = {}): UISettingsCandidateInput => ({
|
||
document_refresh_seconds: documentRefresh,
|
||
resource_refresh_seconds: resourceRefresh,
|
||
stalled_after_seconds: stalled,
|
||
finalizing_after_seconds: finalizing,
|
||
ingestion_concurrency: concurrency,
|
||
test_weknora_base_url: testEndpoint.trim(),
|
||
production_weknora_base_url: endpoint.trim(),
|
||
production_tenant_id: productionTenantID.trim(),
|
||
production_knowledge_base_id: productionKnowledgeBaseID.trim(),
|
||
...overrides,
|
||
})
|
||
const saveEndpoint = () => {
|
||
setDirty(false)
|
||
onSave(candidateInput())
|
||
}
|
||
return (
|
||
<main className="page-shell system-settings">
|
||
<header className="hero compact page-header">
|
||
<div>
|
||
<h1 className="page-title">系统设置</h1>
|
||
</div>
|
||
</header>
|
||
{error ? (
|
||
<div className="error-banner" role="alert">
|
||
{error}
|
||
</div>
|
||
) : null}
|
||
{monitor && settings ? (
|
||
<div className="settings-layout">
|
||
<nav className="settings-nav" aria-label="系统设置分区">
|
||
{sections
|
||
.filter((item) => !item.adminOnly || identity?.role === 'admin')
|
||
.map((item) => (
|
||
<button
|
||
key={item.key}
|
||
className={section === item.key ? 'active' : ''}
|
||
onClick={() => setSection(item.key)}
|
||
>
|
||
{item.label}
|
||
</button>
|
||
))}
|
||
</nav>
|
||
<div className="settings-content">
|
||
{section === 'sources' ? (
|
||
<section className="settings-panel wide source-settings-panel" id="settings-sources">
|
||
{identity?.role === 'admin' ? (
|
||
<SourceWizard
|
||
registeredNames={connections.map((item) => item.name)}
|
||
ppConnected={connections.some((item) => item.source_type === 'pp')}
|
||
onRegistered={onSourcesChanged}
|
||
/>
|
||
) : null}
|
||
{identity?.role === 'admin' ? <DingtalkAccountStatus /> : null}
|
||
<div className="settings-source-group" id="settings-sources-pp">
|
||
{listedConnections.length ? (
|
||
<div className="settings-source-list">
|
||
{listedConnections.map((connection) => (
|
||
<SourceSettingsCard
|
||
key={connection.id}
|
||
connection={connection}
|
||
onSourcesChanged={onSourcesChanged}
|
||
/>
|
||
))}
|
||
{sources.length ? null : (
|
||
<small className="empty-inline">尚无快照数据;快照将在来源首次刷新完成后出现。</small>
|
||
)}
|
||
</div>
|
||
) : (
|
||
<div className="empty-state">还没有已接入的来源:用上面的「+ 添加数据源」加入。</div>
|
||
)}
|
||
</div>
|
||
<SourceManagementDetails connections={listedConnections} onSourcesChanged={onSourcesChanged} />
|
||
</section>
|
||
) : null}
|
||
{section === 'services' ? (
|
||
<section className="settings-panel wide" id="settings-services">
|
||
<div className="settings-section-heading">
|
||
<div>
|
||
<h2>服务配置</h2>
|
||
<p>
|
||
只配四项:测试地址、生产地址、生产 ID、知识库
|
||
ID。保存会先生成修订、验证后原子启用,旧版本保留用于审计;凭据只写不读。
|
||
</p>
|
||
</div>
|
||
</div>
|
||
{isAdmin ? <QAModelSettings /> : null}
|
||
<div className="environment-cards">
|
||
<article>
|
||
<b>测试 WeKnora</b>
|
||
<span>{healthStateLabel(findHealth(monitor, 'WeKnora API'), undefined)}</span>
|
||
<small>{`${healthStateDetail(findHealth(monitor, 'WeKnora API'), undefined) || '端点探测:未配置'};解析队列 对内 ${routingCapabilities.internal_enabled ? '已配置' : '未配置'} · 对外 ${routingCapabilities.external_enabled ? '已配置' : '未配置'}`}</small>
|
||
</article>
|
||
<article className="production">
|
||
<b>生产 WeKnora</b>
|
||
<span>
|
||
{!productionEnabled
|
||
? '未启用'
|
||
: productionBackupRestoreVerified
|
||
? '已启用 · 可提交生产请求'
|
||
: '已启用 · 被阻断'}
|
||
</span>
|
||
<small>{`${productionWeKnoraProbe(monitor)};生产写入:${productionEnabled ? '开启' : '关闭'};发布目标与凭据:管理员受限配置,本页不可回读`}</small>
|
||
</article>
|
||
</div>
|
||
<div className="safe-setting-grid production-endpoint-form">
|
||
{isAdmin ? (
|
||
<>
|
||
<label>
|
||
测试地址
|
||
<input
|
||
value={testEndpoint}
|
||
onChange={(event) => {
|
||
setTestEndpoint(event.target.value)
|
||
setDirty(true)
|
||
}}
|
||
placeholder="https://weknora.test.example"
|
||
aria-invalid={!testEndpointValid}
|
||
/>
|
||
</label>
|
||
<label>
|
||
生产地址
|
||
<input
|
||
value={endpoint}
|
||
onChange={(event) => {
|
||
setEndpoint(event.target.value)
|
||
setDirty(true)
|
||
}}
|
||
placeholder="https://weknora.prod.example"
|
||
aria-invalid={!endpointValid}
|
||
/>
|
||
</label>
|
||
<label>
|
||
生产 ID
|
||
<input
|
||
value={productionTenantID}
|
||
onChange={(event) => {
|
||
setProductionTenantID(event.target.value)
|
||
setDirty(true)
|
||
}}
|
||
placeholder="10000"
|
||
aria-invalid={!productionTenantIDValid}
|
||
/>
|
||
</label>
|
||
<label>
|
||
知识库 ID
|
||
<input
|
||
value={productionKnowledgeBaseID}
|
||
onChange={(event) => {
|
||
setProductionKnowledgeBaseID(event.target.value)
|
||
setDirty(true)
|
||
}}
|
||
placeholder="生产知识库 ID"
|
||
aria-invalid={!productionKnowledgeBaseIDValid}
|
||
/>
|
||
</label>
|
||
</>
|
||
) : (
|
||
<>
|
||
<label>
|
||
测试地址
|
||
<input value={settings.test_weknora_base_url || '未配置'} readOnly disabled />
|
||
</label>
|
||
<label>
|
||
生产地址
|
||
<input value={settings.production_weknora_base_url || '未配置'} readOnly disabled />
|
||
</label>
|
||
<label>
|
||
生产 ID
|
||
<input value={settings.production_tenant_id || '未配置'} readOnly disabled />
|
||
</label>
|
||
<label>
|
||
知识库 ID
|
||
<input value={settings.production_knowledge_base_id || '未配置'} readOnly disabled />
|
||
</label>
|
||
</>
|
||
)}
|
||
</div>
|
||
{isAdmin ? (
|
||
<>
|
||
<button
|
||
onClick={saveEndpoint}
|
||
disabled={!canSave || !serviceSettingsValid || !serviceSettingsDirty}
|
||
>
|
||
{saving ? '正在验证并启用…' : '保存并启用服务配置'}
|
||
</button>
|
||
<small>
|
||
四项留空即表示未配置。地址只接受 http(s) 源地址(不能带用户名密码、查询串或 #
|
||
片段,凭据一律走文件引用);生产 ID 是发布契约里的租户 ID,十进制数字;知识库 ID
|
||
是生产知识库标识,粘贴 URL 不会通过。保存写入服务器活动版本(版本化 + 审计 +
|
||
原子切换);后端同时对测试地址/生产地址做真实探活,并用生产地址真查这两个 ID(WeKnora
|
||
列库接口):端点回答"没有这个知识库"或租户不符会拒绝保存,端点抖动、鉴权失败或未配置生产凭据只警告不拦,核验原话与知识库名在保存后显示。
|
||
</small>
|
||
{serviceSettingsValid ? null : (
|
||
<p className="error-message" role="alert">
|
||
格式不合法:地址需 http:// 或 https:// 开头的纯地址,不能带用户名密码、? 查询串或 # 片段;生产
|
||
ID 需为十进制数字;知识库 ID 不能含空格、/、?、# 或 \。
|
||
</p>
|
||
)}
|
||
</>
|
||
) : (
|
||
<small>
|
||
服务配置仅管理员可修改;当前值:测试地址 {settings.test_weknora_base_url || '未配置'} · 生产地址{' '}
|
||
{settings.production_weknora_base_url || '未配置'} · 生产 ID{' '}
|
||
{settings.production_tenant_id || '未配置'} · 知识库 ID{' '}
|
||
{settings.production_knowledge_base_id || '未配置'}。
|
||
</small>
|
||
)}
|
||
</section>
|
||
) : null}
|
||
{section === 'bindings' ? <RoutingBindingsSection /> : null}
|
||
{section === 'production-bindings' ? <ProductionBindingsSection /> : null}
|
||
{section === 'storage' ? (
|
||
<>
|
||
<LibraryStorageSection />
|
||
<BackupScheduleSection />
|
||
</>
|
||
) : null}
|
||
{section === 'members' && identity?.role === 'admin' ? <MembersSection /> : null}
|
||
{section === 'refresh' ? (
|
||
<section className="settings-panel wide" id="settings-refresh">
|
||
<div className="settings-section-heading">
|
||
<div>
|
||
<h2>刷新策略</h2>
|
||
<p>这些值保存在服务器活动版本中;保存不会修改端点、凭据或生产开关。</p>
|
||
</div>
|
||
<span className="safe-badge">当前活动版本</span>
|
||
</div>
|
||
<div className="safe-setting-grid">
|
||
<label>
|
||
文档状态刷新间隔
|
||
<select
|
||
value={documentRefresh}
|
||
onChange={(event) => {
|
||
setDocumentRefresh(Number(event.target.value) as 15 | 30 | 60)
|
||
setDirty(true)
|
||
}}
|
||
>
|
||
<option value={15}>15秒</option>
|
||
<option value={30}>30秒</option>
|
||
<option value={60}>1分钟</option>
|
||
</select>
|
||
</label>
|
||
<label>
|
||
资源刷新间隔
|
||
<select
|
||
value={resourceRefresh}
|
||
onChange={(event) => {
|
||
setResourceRefresh(Number(event.target.value) as 30 | 60)
|
||
setDirty(true)
|
||
}}
|
||
>
|
||
<option value={30}>30秒</option>
|
||
<option value={60}>1分钟</option>
|
||
</select>
|
||
</label>
|
||
<label>
|
||
解析停滞判定
|
||
<select
|
||
value={stalled}
|
||
onChange={(event) => {
|
||
setStalled(Number(event.target.value) as 1800 | 3600)
|
||
setDirty(true)
|
||
}}
|
||
>
|
||
<option value={1800}>30分钟</option>
|
||
<option value={3600}>1小时</option>
|
||
</select>
|
||
</label>
|
||
<label>
|
||
finalizing 告警
|
||
<select
|
||
value={finalizing}
|
||
onChange={(event) => {
|
||
setFinalizing(Number(event.target.value) as 7200 | 14400)
|
||
setDirty(true)
|
||
}}
|
||
>
|
||
<option value={7200}>2小时</option>
|
||
<option value={14400}>4小时</option>
|
||
</select>
|
||
</label>
|
||
<label>
|
||
入库并发上限
|
||
<select
|
||
value={concurrency}
|
||
onChange={(event) => {
|
||
setConcurrency(Number(event.target.value))
|
||
setDirty(true)
|
||
}}
|
||
>
|
||
<option value={1}>1(谨慎,MinerU 并发 1)</option>
|
||
<option value={2}>2</option>
|
||
<option value={3}>3</option>
|
||
<option value={4}>4</option>
|
||
<option value={6}>6</option>
|
||
<option value={8}>8</option>
|
||
</select>
|
||
</label>
|
||
</div>
|
||
<button
|
||
onClick={() => {
|
||
setDirty(false)
|
||
onSave(candidateInput())
|
||
}}
|
||
disabled={!canSave}
|
||
>
|
||
{saving ? '正在验证并应用…' : '保存并应用刷新与告警参数'}
|
||
</button>
|
||
{visibleSaveMessage(saveMessage, dirty) ? (
|
||
<p className="success-message" role="status">
|
||
{saveMessage}
|
||
</p>
|
||
) : null}
|
||
<small>
|
||
当前:文档 {secondsLabel(settings.document_refresh_seconds)}、资源{' '}
|
||
{secondsLabel(settings.resource_refresh_seconds)}、停滞 {secondsLabel(settings.stalled_after_seconds)}
|
||
、finalizing {secondsLabel(settings.finalizing_after_seconds)}、入库并发{' '}
|
||
{settings.ingestion_concurrency}。
|
||
</small>
|
||
</section>
|
||
) : null}
|
||
</div>
|
||
</div>
|
||
) : null}
|
||
</main>
|
||
)
|
||
}
|
||
|
||
export function SystemSettings() {
|
||
const [sources, setSources] = useState<CatalogSource[]>([])
|
||
const [connections, setConnections] = useState<SourceConnectionListItem[]>([])
|
||
const [monitor, setMonitor] = useState<MonitorOverview | null>(null)
|
||
const [settings, setSettings] = useState<UISettings | null>(null)
|
||
const [productionEnabled, setProductionEnabled] = useState(false)
|
||
const [productionBackupRestoreVerified, setProductionBackupRestoreVerified] = useState(false)
|
||
const [routingCapabilities, setRoutingCapabilities] = useState<CatalogRoutingCapabilities>({
|
||
internal_enabled: false,
|
||
external_enabled: false,
|
||
})
|
||
const [loading, setLoading] = useState(true)
|
||
const [saving, setSaving] = useState(false)
|
||
const [error, setError] = useState<string | null>(null)
|
||
const [saveMessage, setSaveMessage] = useState<string | null>(null)
|
||
const [revision, setRevision] = useState(0)
|
||
|
||
useEffect(() => {
|
||
const controller = new AbortController()
|
||
setLoading(true)
|
||
void Promise.all([
|
||
fetchCatalogSources(controller.signal),
|
||
fetchSourceConnectionList(controller.signal),
|
||
fetchMonitorOverview(controller.signal),
|
||
fetchReleaseCapabilities(controller.signal),
|
||
fetchCatalogRoutingCapabilities(controller.signal),
|
||
fetchActiveUISettings(controller.signal),
|
||
])
|
||
.then(([nextSources, nextConnections, overview, capabilities, routing, active]) => {
|
||
if (!controller.signal.aborted) {
|
||
setSources(nextSources)
|
||
setConnections(nextConnections)
|
||
setMonitor(overview)
|
||
setProductionEnabled(capabilities.production_release_requests_enabled)
|
||
setProductionBackupRestoreVerified(capabilities.production_backup_restore_verified)
|
||
setRoutingCapabilities(routing)
|
||
setSettings(active)
|
||
setError(null)
|
||
}
|
||
})
|
||
.catch((cause) => {
|
||
if (!controller.signal.aborted) setError(cause instanceof Error ? cause.message : '加载系统设置失败')
|
||
})
|
||
.finally(() => {
|
||
if (!controller.signal.aborted) setLoading(false)
|
||
})
|
||
return () => controller.abort()
|
||
}, [revision])
|
||
|
||
const save = async (input: UISettingsCandidateInput) => {
|
||
setSaving(true)
|
||
setSaveMessage(null)
|
||
setError(null)
|
||
try {
|
||
const candidate = await createUISettingsCandidate(input)
|
||
const activated = await activateUISettings(candidate.settings.id)
|
||
const active = activated.settings
|
||
const verification = activated.verification ?? candidate.verification
|
||
setSettings(active)
|
||
setSaveMessage(
|
||
`设置已验证并启用:文档${secondsLabel(active.document_refresh_seconds)}、资源${secondsLabel(active.resource_refresh_seconds)}、停滞${secondsLabel(active.stalled_after_seconds)}、finalizing ${secondsLabel(active.finalizing_after_seconds)}、入库并发 ${active.ingestion_concurrency}、测试地址 ${active.test_weknora_base_url || '未配置'}、生产地址 ${active.production_weknora_base_url || '未配置'}、生产 ID ${active.production_tenant_id || '未配置'}、知识库 ID ${active.production_knowledge_base_id || '未配置'};旧版本已保留用于审计。${verification ? `核验:${verification.message}` : ''}`
|
||
)
|
||
} catch (cause) {
|
||
setError(cause instanceof Error ? cause.message : '保存系统设置失败')
|
||
} finally {
|
||
setSaving(false)
|
||
}
|
||
}
|
||
const reloadSources = useCallback(() => {
|
||
setSaveMessage(null)
|
||
setRevision((value) => value + 1)
|
||
}, [])
|
||
return (
|
||
<SystemSettingsView
|
||
sources={sources}
|
||
connections={connections}
|
||
monitor={monitor}
|
||
settings={settings}
|
||
productionEnabled={productionEnabled}
|
||
productionBackupRestoreVerified={productionBackupRestoreVerified}
|
||
routingCapabilities={routingCapabilities}
|
||
loading={loading}
|
||
saving={saving}
|
||
error={error}
|
||
saveMessage={saveMessage}
|
||
onSave={(input) => void save(input)}
|
||
onSourcesChanged={reloadSources}
|
||
onRefresh={reloadSources}
|
||
/>
|
||
)
|
||
}
|