diff --git a/CHANGELOG.md b/CHANGELOG.md index 292cdde..39a7167 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## 开发快照 0.1.399(系统设置分区调整:AI 模型连接 / 知识库映射) + +### Changed + +- 原「系统设置 → 服务配置」改名为「AI 模型连接」,只保留问答四字段分析与中文翻译共用的 + 模型连接(地址、模型、密钥操作、测试连接、保存),不再混放 WeKnora 连接。 +- WeKnora 测试/生产地址、生产租户与知识库 ID 迁到「知识库映射」,与测试入库、封存源、 + 生产目标同屏;两个 ID 收进「生产核验参数」,并注明只用于核验、不决定发布写入目标。 +- 连接配置在独立组件内维护自己的草稿:保存只提交连接的四项,刷新参数取服务器当前值; + 保存刷新策略也不会带上未保存的连接地址。 +- 凭据仍是服务器文件引用,连接卡只报状态,页面不提供 API Key 录入。 +- 同步更新 README、运维手册、验收清单中的入口路径。 + ## 开发快照 0.1.384(系统设置审查修复:能力心跳、封存源对照、分区合并) ### Added diff --git a/README.md b/README.md index 23a485c..49b20ec 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ make list # 查看检查清单与适用范围 ## 问答运营模型配置 -管理员在「系统设置 → 服务配置 → 问答评估模型」填写 OpenAI 兼容基础地址、模型和 API Key。测试连接发送最小非业务请求;保存不会启动历史全量任务,自动分析/翻译默认关闭。密钥不回显,保留、更换和清除分别选择;录入只允许有效 HTTPS 或本机回环连接,不允许跳过证书校验。 +管理员在「系统设置 → AI 模型连接」填写 OpenAI 兼容基础地址、模型和 API Key。测试连接发送最小非业务请求;保存不会启动历史全量任务,自动分析/翻译默认关闭。密钥不回显,保留、更换和清除分别选择;录入只允许有效 HTTPS 或本机回环连接,不允许跳过证书校验。 API 和普通 worker 须只读挂载同一个独立的 **32 字节、0600 普通文件**,以 `QA_AI_MASTER_KEY_FILE` 指向容器内路径。文件属主应为实际运行 UID;不要复用 Agent 会话存储或把主密钥写进 Compose/Git。治理库只保存加密后的服务密钥;恢复时必须同时恢复治理库和这份独立主密钥。未配置主密钥时如实显示安全存储未就绪。 diff --git a/cmd/api/main.go b/cmd/api/main.go index 6a74e09..e41b7f8 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -94,7 +94,7 @@ func run(ctx context.Context, getenv func(string) string) error { // Production WeKnora is probed for liveness only: the console must show the // real state of that endpoint, while credentials and the publish target stay // in the release runtime config (RELEASE_CONFIG_FILE). - // 生产 WeKnora 端点:配置入口在网页「系统设置 → 服务配置」,管理员保存的值是 + // 生产 WeKnora 端点:配置入口在网页「系统设置 → 知识库映射」,管理员保存的值是 // 这里的真源;容器 env 只作为未在网页配置时的兜底。凭据与发布目标仍留在 // release 运行时配置(RELEASE_CONFIG_FILE)里,不经网页也不落明文。 actionStore := postgresstore.NewStore(pool) diff --git a/cmd/api/readiness.go b/cmd/api/readiness.go index bff2c7c..42abb29 100644 --- a/cmd/api/readiness.go +++ b/cmd/api/readiness.go @@ -12,7 +12,7 @@ import ( ) // newWeKnoraReadinessResolver 把「探测目标」收敛到与业务同一组真源: -// 端点来自网页保存的服务配置(endpoint 内部已做 env 兜底),知识库来自 +// 端点来自网页「知识库映射」保存的连接配置(endpoint 内部已做 env 兜底),知识库来自 // 当前持久化绑定(未绑定才用 env 引导值),凭据每次重新读同一份 key 文件。 // 任何一项读取失败都必须显式报错——静默退回旧值正是 F13 的成因。 func newWeKnoraReadinessResolver( diff --git a/docs/OPERATIONS_RUNBOOK.md b/docs/OPERATIONS_RUNBOOK.md index b689e52..6187b1d 100644 --- a/docs/OPERATIONS_RUNBOOK.md +++ b/docs/OPERATIONS_RUNBOOK.md @@ -10,7 +10,7 @@ ## 0. 开工前:环境与凭据自检 | 项 | 怎么做 | 成功标志 | |---|---|---| -| 测试/生产 WeKnora | 系统设置 → 服务配置 | 生产端"已启用 · 可提交生产请求";测试端探测正常 | +| 测试/生产 WeKnora | 系统设置 → 知识库映射 → WeKnora 连接 | 生产端"已启用 · 可提交生产请求";测试端探测正常 | | 钉钉取件凭据 **【新】** | 容器内 `HOME=/data/home dws auth status --readonly -f json` | `authenticated:true`、`refresh_token_valid:true`(**必须带 `HOME=/data/home`,否则误报未登录**) | | 备份主机接线 | 系统设置 → 存储与备份 | "目标主机 weknora-test · 已连接" | @@ -80,7 +80,7 @@ bash scripts/target_kb_snapshot.sh # 默认云内执行;PG 8 表 + | 分区 | 谁 | 现在要管什么 | |---|---|---| -| 服务配置 | 管理员 | 测试地址 / 生产地址 / 生产 ID / 知识库 ID(保存时真探活,无效才拒) | +| 知识库映射 → WeKnora 连接 | 管理员 | 测试地址 / 生产地址 / 生产 ID / 知识库 ID(保存时真探活,无效才拒) | | 测试知识库绑定 | 管理员 | 标注往哪个测试库路由(对内 ≠ 对外) | | 生产知识库绑定 | 管理员 | 源库 → 目标库映射(发布写哪个生产库) | | **存储与备份** **【新】** | 管理员 | **定时时间 + 储存天数**(+每月归档、启用开关)→ `保存并下发到主机`;另有 `重新下发当前设置`、`立即备份一次`;页面显示主机上**实际生效**的计划、cron 条目、最近一次结果与"已一致/待下发" | diff --git a/docs/USER_FLOWS_ACCEPTANCE.md b/docs/USER_FLOWS_ACCEPTANCE.md index 2f7a130..902038c 100644 --- a/docs/USER_FLOWS_ACCEPTANCE.md +++ b/docs/USER_FLOWS_ACCEPTANCE.md @@ -255,8 +255,8 @@ ## D. 系统设置 -### D1 服务配置(测试 / 生产端点与 ID) -- 入口:**系统设置 → 服务配置**(管理员) +### D1 知识库映射 → WeKnora 连接(测试 / 生产端点与 ID) +- 入口:**系统设置 → 知识库映射 → WeKnora 连接**(管理员) - 规则:只配四项(测试地址、生产地址、生产 ID、知识库 ID);**保存时真探测**,无效才拒;凭据只写不读 - 状态:✅(见 `P41/P42` 与 `ui_settings_*` 测试) diff --git a/internal/monitoring/real.go b/internal/monitoring/real.go index 6de783b..49776f9 100644 --- a/internal/monitoring/real.go +++ b/internal/monitoring/real.go @@ -31,7 +31,7 @@ type RealProviderConfig struct { WeKnoraBaseURL string MinerUBaseURL string // TestWeKnoraResolver reads the test endpoint an admin saved in the web - // settings, so 「服务配置」is the single place the console probes. The env + // settings, so 「知识库映射 → WeKnora 连接」is the single place the console probes. The env // value above stays the bootstrap fallback for containers wired before the // UI existed. TestWeKnoraResolver func(ctx context.Context) string diff --git a/web/src/App.test.tsx b/web/src/App.test.tsx index 1c73060..0c56688 100644 --- a/web/src/App.test.tsx +++ b/web/src/App.test.tsx @@ -125,7 +125,7 @@ describe('ModulePage', () => { expect(html).toContain('P2 · 知识治理总览') expect(html).toContain('PP历史来源清单已接管') expect(html).toContain('生产写入:关闭') - expect(html).toContain('以「系统设置 → 服务配置」的实时探测为准') + expect(html).toContain('以「系统设置 → 知识库映射」的实时探测为准') expect(html).not.toContain('本地测试WeKnora已连接') expect(html).not.toContain('生产WeKnora仍未连接') expect(html).not.toContain('尚未连接测试或生产WeKnora') diff --git a/web/src/App.tsx b/web/src/App.tsx index cf80378..ac993eb 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -505,7 +505,7 @@ export function ModulePage({ ? '已开启' : '已开启(快照恢复未验证,仍被阻断)' : '关闭'} - ;测试 / 生产 WeKnora 连接状态以「系统设置 → 服务配置」的实时探测为准。 + ;测试 / 生产 WeKnora 连接状态以「系统设置 → 知识库映射」的实时探测为准。 Release Worker 默认关闭 diff --git a/web/src/QAAI.tsx b/web/src/QAAI.tsx index ed22b3c..04c2bbc 100644 --- a/web/src/QAAI.tsx +++ b/web/src/QAAI.tsx @@ -288,7 +288,7 @@ export function QAAIWorkbench({ {status ? ( {status.worker_ready ? '执行器在线' : '执行器未在线,任务会持久保留'} - {!ready ? ';请先在系统设置 → 服务配置完成模型核验' : ''} + {!ready ? ';请先在系统设置 → AI 模型连接完成模型核验' : ''} ) : ( 读取后台状态… diff --git a/web/src/SystemSettings.test.tsx b/web/src/SystemSettings.test.tsx index 78a4287..5c295c4 100644 --- a/web/src/SystemSettings.test.tsx +++ b/web/src/SystemSettings.test.tsx @@ -119,57 +119,40 @@ const authValue = (role: 'admin' | 'engineer') => ({ signedOut: 0, notifySignedOut: () => {}, }) -describe('SystemSettingsView service configuration', () => { - it('lets an administrator edit exactly the four service fields in the web console', () => { - const configured: UISettings = { - ...settings, - test_weknora_base_url: 'https://weknora.test.example', - production_weknora_base_url: 'https://weknora.prod.example', - production_tenant_id: '10000', - production_knowledge_base_id: 'kb-abc123', - } - const view = (role: 'admin' | 'engineer') => - renderToStaticMarkup( - - - - ) +describe('SystemSettingsView AI 模型连接', () => { + const view = (role: 'admin' | 'engineer') => + renderToStaticMarkup( + + + + ) + it('keeps the model connection alone in AI 模型连接 and points WeKnora to 知识库映射', () => { const adminHtml = view('admin') - for (const text of [ - '测试地址', - '生产地址', - '生产租户 ID', - '知识库 ID', - '保存并启用服务配置', - 'https://weknora.test.example', - 'https://weknora.prod.example', - '10000', - 'kb-abc123', - '四项留空即表示未配置', - ]) + for (const text of ['AI 模型连接', '问答评估模型', 'WeKnora 的知识库连接已移到「知识库映射」']) { expect(adminHtml).toContain(text) - expect(adminHtml).not.toContain('仅管理员可修改') - // 界面只剩这四项:依赖探活矩阵与对内/对外绑定下拉不再出现在服务配置页。 - for (const removed of ['MinerU', 'Embedding', 'Redis / MQ', 'PostgreSQL', '测试知识库映射']) + } + // 地址类配置已迁走:这里不再出现 WeKnora 连接表单,也不出现旧的“服务配置”分区名。 + for (const removed of ['保存并校验连接', '保存并启用服务配置', '生产租户 ID', '服务配置']) expect(adminHtml).not.toContain(removed) const engineerHtml = view('engineer') - expect(engineerHtml).toContain('仅管理员可修改') - expect(engineerHtml).not.toContain('保存并启用服务配置') + expect(engineerHtml).toContain('仅管理员可修改模型连接') + // 工程师看不到模型编辑表单(QAModelSettings 只在管理员下挂载)。 + expect(engineerHtml).not.toContain('问答评估模型') }) }) describe('SystemSettingsView', () => { @@ -191,7 +174,8 @@ describe('SystemSettingsView', () => { onRefresh={vi.fn()} /> ) - for (const text of ['系统设置', '数据源配置', '服务配置', '存储与备份', '刷新策略']) expect(html).toContain(text) + for (const text of ['系统设置', '数据源配置', 'AI 模型连接', '知识库映射', '存储与备份', '刷新策略']) + expect(html).toContain(text) // 主人 2026-10-26 要求去掉的噪声:页头副标题、刷新状态、权限条、活动版本横幅。 for (const removed of [ '查看内容源、服务与备份状态', @@ -213,26 +197,41 @@ describe('SystemSettingsView', () => { expect(html).not.toContain(removed) // 需求(2026-10-10):新增入口只剩「可加入的来源」勾选,粘贴链接的按钮已下线。 for (const removed of ['+ 新增钉钉知识库', '新增钉钉知识库']) expect(html).not.toContain(removed) - const servicesHtml = renderToStaticMarkup( - + // WeKnora 连接已迁到「知识库映射」:地址与核验参数跟入库/封存/生产目标同屏。 + const mapHtml = renderToStaticMarkup( + + + ) - for (const text of ['测试 WeKnora', '生产 WeKnora', '测试地址', '生产地址', '生产 ID', '知识库 ID']) - expect(servicesHtml).toContain(text) + for (const text of [ + 'WeKnora 连接', + '测试 WeKnora', + '生产 WeKnora', + '测试地址', + '生产地址', + '生产租户 ID', + '知识库 ID', + '保存并校验连接', + '生产核验参数', + ]) + expect(mapHtml).toContain(text) + // 凭据是服务器文件引用:连接卡只报状态,页面不提供 API Key 录入。 + expect(mapHtml).not.toContain('API Key') const storageHtml = renderToStaticMarkup( { for (const forbidden of ['DATABASE_URL', 'RELEASE_CONFIG_FILE', 'API Key明文', 'secret_ref']) expect(html).not.toContain(forbidden) // 两个环境卡仍由真实探测驱动(依赖矩阵搬到总览页,本页不再渲染)。 - expect(servicesHtml).toContain('解析队列 对内 已配置 · 对外 已配置') - expect(servicesHtml).not.toContain('PostgreSQL') - expect(servicesHtml).toContain('端点探测:暂无真实探测结果') + expect(mapHtml).toContain('解析队列 对内 已配置 · 对外 已配置') + expect(mapHtml).not.toContain('PostgreSQL') + expect(mapHtml).toContain('端点探测:暂无真实探测结果') // V1: left-nav section controls, per-source schedule editing, danger modal & history affordances. expect(html).toContain('settings-nav') for (const kept of ['更多', '自动刷新中']) expect(html).toContain(kept) @@ -424,7 +423,7 @@ describe('SystemSettingsView', () => { onSave={vi.fn()} onSourcesChanged={vi.fn()} onRefresh={vi.fn()} - initialSection="services" + initialSection="knowledge-map" /> ) const on = view(true, true) @@ -433,7 +432,7 @@ describe('SystemSettingsView', () => { expect(on).toContain('延迟 86ms') expect(on).toContain('已启用 · 可提交生产请求') expect(on).toContain('生产写入:开启') - expect(on).toContain('发布目标与凭据:管理员受限配置') + expect(on).toContain('凭据:服务器文件引用,页面不回读') const off = view(false, false) expect(off).toContain('未启用') expect(off).toContain('生产写入:关闭') @@ -457,7 +456,7 @@ describe('SystemSettingsView', () => { onSave={vi.fn()} onSourcesChanged={vi.fn()} onRefresh={vi.fn()} - initialSection="services" + initialSection="knowledge-map" /> ) expect(blocked).toContain('已启用 · 被阻断') @@ -495,7 +494,7 @@ describe('SystemSettingsView', () => { onSave={vi.fn()} onSourcesChanged={vi.fn()} onRefresh={vi.fn()} - initialSection="services" + initialSection="knowledge-map" /> ) expect(unconfigured).toContain('端点探测:未配置') diff --git a/web/src/SystemSettings.tsx b/web/src/SystemSettings.tsx index f67c73a..81b6587 100644 --- a/web/src/SystemSettings.tsx +++ b/web/src/SystemSettings.tsx @@ -13,23 +13,23 @@ import { useOptionalAuth } from './auth' import { fetchMonitorOverview } from './monitor' import type { MonitorOverview } from './monitor' import { fetchReleaseCapabilities } from './reviewRelease' -import { fetchWorkerCapabilities, testUploadLabel } from './systemCapabilities' +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, - validKnowledgeBaseID, - validProductionTenantID, - validServiceEndpoint, -} from './uiSettings' +import { activateUISettings, createUISettingsCandidate, fetchActiveUISettings } from './uiSettings' import type { UISettings, UISettingsCandidateInput } from './uiSettings' +import { refreshSettingsInput } from './settingsInputs' +import { WeKnoraConnections } from './WeKnoraConnections' import './systemSettings.css' +// 连接配置已从「服务配置」迁到「知识库映射」。这两个纯函数仍从本模块导出, +// 既有调用与回归测试的导入路径不变。 +export { refreshSettingsInput, serviceSettingsInput } from './settingsInputs' +export type { RefreshDrafts, ServiceDrafts } from './settingsInputs' + interface Props { sources: CatalogSource[] connections: SourceConnectionListItem[] @@ -54,7 +54,7 @@ type SectionKey = 'sources' | 'services' | 'knowledge-map' | 'storage' | 'refres const sections: { key: SectionKey; label: string; adminOnly?: boolean }[] = [ { key: 'sources', label: '数据源配置' }, - { key: 'services', label: '服务配置' }, + { key: 'services', label: 'AI 模型连接' }, { key: 'knowledge-map', label: '知识库映射' }, { key: 'storage', label: '存储与备份' }, { key: 'refresh', label: '刷新策略' }, @@ -79,96 +79,6 @@ 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 interface ServiceDrafts { - testEndpoint: string - endpoint: string - productionTenantID: string - productionKnowledgeBaseID: string -} -export interface RefreshDrafts { - documentRefresh: 15 | 30 | 60 - resourceRefresh: 30 | 60 - stalled: 1800 | 3600 - finalizing: 7200 | 14400 - concurrency: number -} -export const serviceSettingsInput = (settings: UISettings, drafts: ServiceDrafts): UISettingsCandidateInput => ({ - document_refresh_seconds: settings.document_refresh_seconds, - resource_refresh_seconds: settings.resource_refresh_seconds, - stalled_after_seconds: settings.stalled_after_seconds, - finalizing_after_seconds: settings.finalizing_after_seconds, - ingestion_concurrency: settings.ingestion_concurrency, - test_weknora_base_url: drafts.testEndpoint.trim(), - production_weknora_base_url: drafts.endpoint.trim(), - production_tenant_id: drafts.productionTenantID.trim(), - production_knowledge_base_id: drafts.productionKnowledgeBaseID.trim(), -}) -export const refreshSettingsInput = (settings: UISettings, drafts: RefreshDrafts): UISettingsCandidateInput => ({ - document_refresh_seconds: drafts.documentRefresh, - resource_refresh_seconds: drafts.resourceRefresh, - stalled_after_seconds: drafts.stalled, - finalizing_after_seconds: drafts.finalizing, - ingestion_concurrency: drafts.concurrency, - test_weknora_base_url: settings.test_weknora_base_url, - production_weknora_base_url: settings.production_weknora_base_url, - production_tenant_id: settings.production_tenant_id, - production_knowledge_base_id: settings.production_knowledge_base_id, -}) - -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' ? '可达 · 不可接单' : '不可达 · 不可接单' -} - -// 测试 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 function SystemSettingsView({ sources, connections, @@ -198,12 +108,6 @@ export function SystemSettingsView({ 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 [endpoint, setEndpoint] = useState(settings?.production_weknora_base_url ?? '') - const [testEndpoint, setTestEndpoint] = useState(settings?.test_weknora_base_url ?? '') - const [productionTenantID, setProductionTenantID] = useState(settings?.production_tenant_id ?? '') - const [productionKnowledgeBaseID, setProductionKnowledgeBaseID] = useState( - settings?.production_knowledge_base_id ?? '' - ) const [dirty, setDirty] = useState(false) // 统一入口后,清单里列全部来源(钉钉知识库 / 钉盘 / PP),不再只显示 PP。 @@ -216,28 +120,11 @@ export function SystemSettingsView({ 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 refreshSettingsDirty = Boolean( settings && (documentRefresh !== settings.document_refresh_seconds || @@ -246,21 +133,12 @@ export function SystemSettingsView({ finalizing !== settings.finalizing_after_seconds || concurrency !== settings.ingestion_concurrency) ) - // 保存边界:服务分区只带上自己这一组的输入,另一组一律用服务器当前值。 - // 否则“改了地址没保存、切到刷新策略保存”会把未确认的地址一起写进去。 - // 两个分区都有独立草稿;缺 settings 时按钮本就不可点,这里只防一手。 - const serviceInput = (): UISettingsCandidateInput => - settings - ? serviceSettingsInput(settings, { testEndpoint, endpoint, productionTenantID, productionKnowledgeBaseID }) - : ({} as UISettingsCandidateInput) + // 保存边界:刷新分区只带刷新草稿;WeKnora 连接草稿在 WeKnoraConnections 内独立保存, + // 互不夹带(未保存的地址不会因为保存刷新策略被写进去)。 const refreshInput = (): UISettingsCandidateInput => settings ? refreshSettingsInput(settings, { documentRefresh, resourceRefresh, stalled, finalizing, concurrency }) : ({} as UISettingsCandidateInput) - const saveEndpoint = () => { - setDirty(false) - onSave(serviceInput()) - } return (
@@ -326,147 +204,35 @@ export function SystemSettingsView({ ) : null} {section === 'services' && settings ? ( -
+
-

服务配置

-

- 四项可写:测试地址、生产地址、生产租户、生产知识库。保存前会做真实探活与列库核验,凭据只写不读。 -

+

AI 模型连接

+

问答四字段分析与中文问题翻译共用的模型服务;WeKnora 的知识库连接已移到「知识库映射」。

- {isAdmin ? : null} -
-
- 测试 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}` : ''} - -
-
- 生产 WeKnora - - {!productionEnabled - ? '未启用' - : productionBackupRestoreVerified - ? '已启用 · 可提交生产请求' - : '已启用 · 被阻断'} - - {`${productionWeKnoraProbe(monitor)};生产写入:${productionEnabled ? '开启' : '关闭'};发布目标与凭据:管理员受限配置,本页不可回读`} -
-
-
- {isAdmin ? ( - <> - - - - - - ) : ( - <> - - - - - - )} -
- {isAdmin ? ( - <> - -
- 保存规则与核验说明 - - 四项留空即表示未配置。地址只接受 http(s) 源地址(不能带用户名密码、查询串或 # 片段, - 凭据一律走文件引用);生产租户 ID 为十进制数字;知识库 ID 粘贴 URL 不会通过。 - 保存会生成修订、真实验证后原子启用;端点回答“没有这个知识库”或租户不符会拒收, - 端点抖动、鉴权失败或未配置生产凭据只警告不拦。 - -
- {serviceSettingsValid ? null : ( -

- 格式不合法:地址需 http:// 或 https:// 开头的纯地址,不能带用户名密码、? 查询串或 # 片段;生产 - ID 需为十进制数字;知识库 ID 不能含空格、/、?、# 或 \。 -

- )} - - ) : ( - - 服务配置仅管理员可修改;当前值:测试地址 {settings.test_weknora_base_url || '未配置'} · 生产地址{' '} - {settings.production_weknora_base_url || '未配置'} · 生产 ID{' '} - {settings.production_tenant_id || '未配置'} · 知识库 ID{' '} - {settings.production_knowledge_base_id || '未配置'}。 - - )} + {isAdmin ? : 仅管理员可修改模型连接;密钥不回显。} +

+ 保存只更新这份模型连接;自动分析与自动翻译仍按问答运营里的任务开关执行,不会因为保存连接自动打开。 +

) : null} {section === 'knowledge-map' ? ( <> + {settings ? ( + + ) : null}

一张图看清三件事:入库目标(来源打标分发到此库)、 封存源(整库封存实际导出的库)、生产目标(同步写入的库)。 @@ -488,7 +254,7 @@ export function SystemSettingsView({

刷新策略

-

保存只改这一组参数,不会带上服务配置里未保存的地址。

+

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

当前活动版本
diff --git a/web/src/WeKnoraConnections.mounted.test.tsx b/web/src/WeKnoraConnections.mounted.test.tsx new file mode 100644 index 0000000..f3cdeac --- /dev/null +++ b/web/src/WeKnoraConnections.mounted.test.tsx @@ -0,0 +1,130 @@ +// @vitest-environment jsdom +import { act } from 'react' +import { createRoot, type Root } from 'react-dom/client' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { WeKnoraConnections } from './WeKnoraConnections' +import type { UISettings } from './uiSettings' + +const settings: UISettings = { + id: 'settings-live', + state: 'active', + document_refresh_seconds: 30, + resource_refresh_seconds: 60, + stalled_after_seconds: 3600, + finalizing_after_seconds: 14400, + ingestion_concurrency: 4, + test_weknora_base_url: 'https://server.test', + production_weknora_base_url: 'https://server.prod', + production_tenant_id: '10000', + production_knowledge_base_id: 'kb-server', + updated_by: 'admin-1', + created_at: '2026-11-18T08:00:00Z', + activated_at: '2026-11-18T08:00:00Z', + retired_at: null, + error_code: '', +} +let root: Root +let host: HTMLDivElement +const click = async (label: string) => { + const button = [...host.querySelectorAll('button')].find((x) => x.textContent?.trim() === label) + expect(button, label).toBeTruthy() + await act(async () => button!.click()) +} +const type = async (label: string, value: string) => { + const input = [...host.querySelectorAll('label')] + .find((x) => x.textContent?.startsWith(label)) + ?.querySelector('input') + expect(input, label).toBeTruthy() + await act(async () => { + Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(input, value) + input!.dispatchEvent(new Event('input', { bubbles: true })) + }) +} +beforeEach(() => { + Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true }) + host = document.createElement('div') + document.body.append(host) + root = createRoot(host) +}) +afterEach(async () => { + await act(async () => root.unmount()) + host.remove() +}) + +describe('WeKnoraConnections', () => { + it('保存只带连接草稿,刷新参数取服务器当前值', async () => { + const onSave = vi.fn() + await act(async () => + root.render( + + ) + ) + await type('测试地址', 'https://draft.test') + await click('保存并校验连接') + expect(onSave).toHaveBeenCalledTimes(1) + expect(onSave.mock.calls[0][0]).toMatchObject({ + test_weknora_base_url: 'https://draft.test', + production_weknora_base_url: 'https://server.prod', + production_tenant_id: '10000', + production_knowledge_base_id: 'kb-server', + document_refresh_seconds: 30, + ingestion_concurrency: 4, + }) + }) + + it('未修改时保存按钮不可点,非法地址也不允许提交', async () => { + const onSave = vi.fn() + await act(async () => + root.render( + + ) + ) + const saveButton = () => + [...host.querySelectorAll('button')].find((x) => x.textContent?.trim() === '保存并校验连接') as + HTMLButtonElement | undefined + expect(saveButton()?.disabled).toBe(true) + await type('生产地址', 'https://draft.prod/?token=x') + expect(saveButton()?.disabled).toBe(true) + expect(host.textContent).toContain('格式不合法') + await click('保存并校验连接') + expect(onSave).not.toHaveBeenCalled() + }) + + it('工程师只看到只读摘要,没有保存入口', async () => { + await act(async () => + root.render( + + ) + ) + expect(host.textContent).toContain('仅管理员可修改 WeKnora 连接') + expect(host.textContent).toContain('https://server.test') + expect([...host.querySelectorAll('button')]).toHaveLength(0) + }) +}) diff --git a/web/src/WeKnoraConnections.tsx b/web/src/WeKnoraConnections.tsx new file mode 100644 index 0000000..153cba5 --- /dev/null +++ b/web/src/WeKnoraConnections.tsx @@ -0,0 +1,242 @@ +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(settings.production_weknora_base_url ?? '') + const [testEndpoint, setTestEndpoint] = useState(settings.test_weknora_base_url ?? '') + const [productionTenantID, setProductionTenantID] = useState(settings.production_tenant_id ?? '') + const [productionKnowledgeBaseID, setProductionKnowledgeBaseID] = useState( + 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 ( +
+
+
+

WeKnora 连接

+

+ 测试与生产各自的地址在这里维护;保存前后端会真做一次探活与列库核验。凭据由服务器文件引用提供, + 页面只显示是否已配置,不回读、也不能在这里录入。 +

+
+
+
+
+ 测试 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}` : ''} + +
+
+ 生产 WeKnora + + {!productionEnabled + ? '未启用' + : productionBackupRestoreVerified + ? '已启用 · 可提交生产请求' + : '已启用 · 被阻断'} + + {`${productionWeKnoraProbe(monitor)};生产写入:${productionEnabled ? '开启' : '关闭'};凭据:服务器文件引用,页面不回读`} +
+
+ {isAdmin ? ( + <> +
+ + +
+
+ 生产核验参数(仅用于核验,不决定发布写入目标) +
+ + +
+ + 这两项用于确认生产端确实存在目标库、租户归属正确;整库发布的实际写入目标见下方「生产知识库绑定」, + 由部署配置决定,不在本页修改。 + +
+ +
+ 保存规则与核验说明 + + 四项留空即表示未配置。地址只接受 http(s) 源地址(不能带用户名密码、查询串或 # 片段, + 凭据一律走文件引用);生产租户 ID 为十进制数字;知识库 ID 粘贴 URL 不会通过。 + 保存会生成修订、真实验证后原子启用;端点回答“没有这个知识库”或租户不符会拒收, + 端点抖动、鉴权失败或未配置生产凭据只警告不拦。 + +
+ {valid ? null : ( +

+ 格式不合法:地址需 http:// 或 https:// 开头的纯地址,不能带用户名密码、? 查询串或 # 片段;生产 ID + 需为十进制数字;知识库 ID 不能含空格、/、?、# 或 \。 +

+ )} + {saveMessage ? ( +

+ {saveMessage} +

+ ) : null} + + ) : ( + + 仅管理员可修改 WeKnora 连接;当前值:测试地址 {settings.test_weknora_base_url || '未配置'} · 生产地址{' '} + {settings.production_weknora_base_url || '未配置'} · 生产 ID {settings.production_tenant_id || '未配置'} · + 知识库 ID {settings.production_knowledge_base_id || '未配置'}。 + + )} +
+ ) +} diff --git a/web/src/settingsInputs.ts b/web/src/settingsInputs.ts new file mode 100644 index 0000000..f56da20 --- /dev/null +++ b/web/src/settingsInputs.ts @@ -0,0 +1,39 @@ +import type { UISettings, UISettingsCandidateInput } from './uiSettings' + +// 保存边界是纯函数:连接分区只取连接草稿,刷新分区只取刷新草稿, +// 另一侧一律用服务器当前值。组件与测试共用同一实现。 +export interface ServiceDrafts { + testEndpoint: string + endpoint: string + productionTenantID: string + productionKnowledgeBaseID: string +} +export interface RefreshDrafts { + documentRefresh: 15 | 30 | 60 + resourceRefresh: 30 | 60 + stalled: 1800 | 3600 + finalizing: 7200 | 14400 + concurrency: number +} +export const serviceSettingsInput = (settings: UISettings, drafts: ServiceDrafts): UISettingsCandidateInput => ({ + document_refresh_seconds: settings.document_refresh_seconds, + resource_refresh_seconds: settings.resource_refresh_seconds, + stalled_after_seconds: settings.stalled_after_seconds, + finalizing_after_seconds: settings.finalizing_after_seconds, + ingestion_concurrency: settings.ingestion_concurrency, + test_weknora_base_url: drafts.testEndpoint.trim(), + production_weknora_base_url: drafts.endpoint.trim(), + production_tenant_id: drafts.productionTenantID.trim(), + production_knowledge_base_id: drafts.productionKnowledgeBaseID.trim(), +}) +export const refreshSettingsInput = (settings: UISettings, drafts: RefreshDrafts): UISettingsCandidateInput => ({ + document_refresh_seconds: drafts.documentRefresh, + resource_refresh_seconds: drafts.resourceRefresh, + stalled_after_seconds: drafts.stalled, + finalizing_after_seconds: drafts.finalizing, + ingestion_concurrency: drafts.concurrency, + test_weknora_base_url: settings.test_weknora_base_url, + production_weknora_base_url: settings.production_weknora_base_url, + production_tenant_id: settings.production_tenant_id, + production_knowledge_base_id: settings.production_knowledge_base_id, +}) diff --git a/web/src/styles.css b/web/src/styles.css index 5cc52d9..472e280 100644 --- a/web/src/styles.css +++ b/web/src/styles.css @@ -880,7 +880,8 @@ tbody tr:hover { #release-plan, #release-execution, #settings-sources, -#settings-services, +#settings-ai-model, +#settings-weknora-connections, #settings-storage, #settings-refresh { scroll-margin-top: 60px; diff --git a/web/src/uiSettings.ts b/web/src/uiSettings.ts index b2fc49d..194b61d 100644 --- a/web/src/uiSettings.ts +++ b/web/src/uiSettings.ts @@ -30,7 +30,7 @@ export interface UISettingsCandidateInput { production_knowledge_base_id: string } -// 保存服务配置时后端会用生产地址真查一次:找到了才写入,并把知识库名回显; +// 保存连接配置时后端会用生产地址真查一次:找到了才写入,并把知识库名回显; // 端点明确回答"不存在"会拒绝保存(HTTP 400 + 这句 message),端点抖动只警告不拦。 export interface ServiceEndpointStatus { status: string