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 { PPConnection } from './PPConnection' import { KnowledgeBaseBinding } from './KnowledgeBaseBinding' import { WeKnoraConnectionDiagnostics } from './weKnoraDiagnostics' import { useOptionalAuth } from './auth' import { fetchMonitorOverview } from './monitor' import type { MonitorOverview } from './monitor' import { fetchReleaseCapabilities } from './reviewRelease' import { fetchWorkerCapabilities } from './systemCapabilities' import type { WorkerCapabilities } from './systemCapabilities' 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 } from './uiSettings' import type { UISettings, UISettingsCandidateInput } from './uiSettings' import { refreshSettingsInput } from './settingsInputs' import './systemSettings.css' // 连接配置已从「服务配置」迁到「知识库绑定」。这两个纯函数仍从本模块导出, // 既有调用与回归测试的导入路径不变。 export { refreshSettingsInput, serviceSettingsInput } from './settingsInputs' export type { RefreshDrafts, ServiceDrafts } from './settingsInputs' interface Props { sources: CatalogSource[] connections: SourceConnectionListItem[] monitor: MonitorOverview | null settings: UISettings | null productionEnabled: boolean productionBackupRestoreVerified?: boolean routingCapabilities: CatalogRoutingCapabilities workerCapabilities?: WorkerCapabilities | null loading: boolean saving: boolean error: string | null saveMessage: string | null onSave: (input: UISettingsCandidateInput) => void onSourcesChanged: () => void onRefresh: () => void // 兼容旧入口:'bindings'/'production-bindings'/'knowledge-map' 都落到「知识库绑定」。 initialSection?: SectionKey | 'bindings' | 'production-bindings' | 'knowledge-map' } type SectionKey = 'sources' | 'services' | 'knowledge-bindings' | 'storage' | 'refresh' | 'members' const sections: { key: SectionKey; label: string; adminOnly?: boolean }[] = [ { key: 'sources', label: '数据源配置' }, { key: 'services', label: 'AI 模型连接' }, { key: 'knowledge-bindings', label: '知识库绑定' }, { key: 'storage', label: '存储与备份' }, { key: 'refresh', label: '刷新策略' }, { key: 'members', label: '成员与角色', adminOnly: true }, ] as { key: SectionKey; label: string; adminOnly?: boolean }[] const sourceTypeLabels: Record = { 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) export function SystemSettingsView({ sources, connections, monitor, settings, productionEnabled, productionBackupRestoreVerified = false, routingCapabilities, workerCapabilities = null, loading, saving, error, saveMessage, onSave, onSourcesChanged, initialSection = 'sources', }: Props) { const auth = useOptionalAuth() const identity = auth?.identity ?? null const [section, setSection] = useState( initialSection === 'bindings' || initialSection === 'production-bindings' || initialSection === 'knowledge-map' ? 'knowledge-bindings' : (initialSection as SectionKey) ) 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(settings?.ingestion_concurrency ?? 2) 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) setDirty(false) }, [settings]) const canSave = Boolean(settings && !saving) const isAdmin = identity?.role === 'admin' const refreshSettingsDirty = Boolean( settings && (documentRefresh !== settings.document_refresh_seconds || resourceRefresh !== settings.resource_refresh_seconds || stalled !== settings.stalled_after_seconds || finalizing !== settings.finalizing_after_seconds || concurrency !== settings.ingestion_concurrency) ) // 保存边界:刷新分区只带刷新草稿;知识库绑定的连接/选库草稿在独立组件内一次保存, // 互不夹带(未保存的地址不会因为保存刷新策略被写进去)。 const refreshInput = (): UISettingsCandidateInput => settings ? refreshSettingsInput(settings, { documentRefresh, resourceRefresh, stalled, finalizing, concurrency }) : ({} as UISettingsCandidateInput) return (

系统设置

{error ? (
{error}
) : null} {settings || monitor ? (
{section === 'sources' ? (
{identity?.role === 'admin' ? ( item.name)} ppConnected={connections.some((item) => item.source_type === 'pp')} onRegistered={onSourcesChanged} /> ) : null} {identity?.role === 'admin' ? ( <> ) : null}
{listedConnections.length ? (
{listedConnections.map((connection) => ( ))} {sources.length ? null : ( 尚无快照数据;快照将在来源首次刷新完成后出现。 )}
) : (
还没有已接入的来源:用上面的「+ 添加数据源」加入。
)}
) : null} {section === 'services' && settings ? (

AI 模型连接

问答四字段分析与中文问题翻译共用此连接;保存只更新这份连接,不会自动开启自动分析或自动翻译。 WeKnora 的知识库连接已移到「知识库绑定」。

{isAdmin ? : 仅管理员可修改模型连接;密钥不回显。}
) : null} {section === 'knowledge-bindings' ? ( <>
连接与绑定诊断(探活、封存源、整库发布目标) {settings ? ( ) : null}

封存源是整库封存实际导出的库;整库发布目标由部署配置决定、只读。两者与上面的入库绑定不一致时, 发布页显示的名字与封存出来的内容会对不上。

) : null} {section === 'storage' ? ( <> ) : null} {section === 'members' && identity?.role === 'admin' ? : null} {section === 'refresh' && settings ? (

刷新策略

保存只改这一组参数,不会带上「知识库绑定」里未保存的连接地址。

当前活动版本
{visibleSaveMessage(saveMessage, dirty) ? (

{saveMessage}

) : null}

解析停滞阈值保存后由 worker 在 1 分钟内生效;收尾超时告警目前只保存配置,判定尚未接入。

当前:文档 {secondsLabel(settings.document_refresh_seconds)}、资源{' '} {secondsLabel(settings.resource_refresh_seconds)}、停滞 {secondsLabel(settings.stalled_after_seconds)} 、finalizing {secondsLabel(settings.finalizing_after_seconds)}、入库并发{' '} {settings.ingestion_concurrency}。
) : null}
) : null}
) } export function SystemSettings() { const [sources, setSources] = useState([]) const [connections, setConnections] = useState([]) const [monitor, setMonitor] = useState(null) const [settings, setSettings] = useState(null) const [productionEnabled, setProductionEnabled] = useState(false) const [productionBackupRestoreVerified, setProductionBackupRestoreVerified] = useState(false) const [routingCapabilities, setRoutingCapabilities] = useState({ internal_enabled: false, external_enabled: false, }) // 执行器能力单独加载:读不到只是这一行显示未知,不影响其它分区。 const [workerCapabilities, setWorkerCapabilities] = useState(null) const [loading, setLoading] = useState(true) const [saving, setSaving] = useState(false) const [error, setError] = useState(null) const [saveMessage, setSaveMessage] = useState(null) const [revision, setRevision] = useState(0) // 六个请求彼此独立:任何一块失败只影响它自己,不能让成员、备份这些 // 互不相干的入口一起消失。设置本身读不到才阻断“设置”相关分区。 useEffect(() => { const controller = new AbortController() const failures: string[] = [] const track = (promise: Promise, apply: (value: T) => void, label: string) => promise .then((value) => { if (!controller.signal.aborted) apply(value) }) .catch((cause) => { failures.push(`${label}:${cause instanceof Error ? cause.message : '读取失败'}`) }) setLoading(true) void Promise.all([ track(fetchCatalogSources(controller.signal), setSources, '数据源'), track(fetchSourceConnectionList(controller.signal), setConnections, '来源连接'), track(fetchMonitorOverview(controller.signal), setMonitor, '监控'), track( fetchReleaseCapabilities(controller.signal), (capabilities) => { setProductionEnabled(capabilities.production_release_requests_enabled) setProductionBackupRestoreVerified(capabilities.production_backup_restore_verified) }, '发布能力' ), track(fetchCatalogRoutingCapabilities(controller.signal), setRoutingCapabilities, '路由能力'), track(fetchWorkerCapabilities(controller.signal), setWorkerCapabilities, '执行器能力'), track(fetchActiveUISettings(controller.signal), setSettings, '系统设置'), ]).finally(() => { if (controller.signal.aborted) return setError(failures.length ? failures.join(';') : null) 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) // 保存成功后重新探测一次,卡片上的“最近检查”才不会停在旧结果。 try { setMonitor(await fetchMonitorOverview()) } catch { // 探测失败不影响保存结果,页面保留上一次观测。 } 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 ( void save(input)} onSourcesChanged={reloadSources} onRefresh={reloadSources} /> ) }