feat(release): 发布目标知识库可选(源库 → 目标库映射)
- 迁移 000044:production_kb_bindings + release_item_executions.target_knowledge_base_id - 系统设置新增「生产知识库绑定(对内/对外)」:从生产 WeKnora 实际列表选库, 保存时真校验(不存在拒收;生产端不可达只提示并如实回报),仅管理员可改 - 执行计划按绑定解析目标库并冻结进 release_item_executions;空目标直接拒收; 已发布过的条目保留原目标(重试/回滚回到同一处) - DocumentBundle.RemapKnowledgeBase:knowledges/chunks/knowledge_tags/wiki_pages/ wiki_folders 的 knowledge_base_id 与 ES 文档字段改写为目标库,重算表/文档摘要并重新封装 - 契约比对改为「声明的映射对」(KnowledgeBaseMapping),其余字段继续 fail-closed - 契约检查器 / 目标身份 / 验证器全部走映射后的目标库;对象通道无需改写 - Compose 拆分:数据面接线 compose.release-sim.yaml + 两道门禁 compose.release-gates.yaml - 测试:RemapKnowledgeBase 全通道/无操作/fail-closed、映射契约、绑定接口、RBAC、真实 PG 集成
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
|
||||
import { useOptionalAuth } from './auth'
|
||||
import { fetchProductionBindingOptions, fetchProductionBindings, saveProductionBindings } from './productionBindings'
|
||||
import type { ProductionBindings } from './productionBindings'
|
||||
import type { KnowledgeBaseOption } from './routingBindings'
|
||||
|
||||
// 「生产知识库绑定」:发布链路的 源库 → 目标库 映射。这里选的是发布要写入的
|
||||
// 生产(目标)知识库,与上面的「知识库绑定」(测试端收件库)是两件事。
|
||||
export function ProductionBindingsSection() {
|
||||
const auth = useOptionalAuth()
|
||||
const isAdmin = auth?.identity?.role === 'admin'
|
||||
const [bindings, setBindings] = useState<ProductionBindings | null>(null)
|
||||
const [options, setOptions] = useState<KnowledgeBaseOption[]>([])
|
||||
const [internalDraft, setInternalDraft] = useState('')
|
||||
const [externalDraft, setExternalDraft] = useState('')
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [message, setMessage] = useState('')
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true); setError(null)
|
||||
try {
|
||||
const next = await fetchProductionBindings()
|
||||
setBindings(next)
|
||||
setInternalDraft(next.internal_kb_id)
|
||||
setExternalDraft(next.external_kb_id)
|
||||
try { setOptions(await fetchProductionBindingOptions()) } catch { setOptions([]) }
|
||||
} catch (cause) { setError(cause instanceof Error ? cause.message : '读取生产知识库绑定失败') }
|
||||
finally { setLoading(false) }
|
||||
}, [])
|
||||
useEffect(() => { void load() }, [load])
|
||||
|
||||
const dirty = bindings !== null && (internalDraft !== bindings.internal_kb_id || externalDraft !== bindings.external_kb_id)
|
||||
const sameSelection = internalDraft !== '' && internalDraft === externalDraft
|
||||
|
||||
const save = async () => {
|
||||
setSaving(true); setError(null); setMessage('')
|
||||
try {
|
||||
const next = await saveProductionBindings({ internal_kb_id: internalDraft, external_kb_id: externalDraft })
|
||||
setBindings(next)
|
||||
const where = `对内 ${next.internal_kb_name || next.internal_kb_id.slice(0, 8) || '未绑定'} · 对外 ${next.external_kb_name || next.external_kb_id.slice(0, 8) || '未绑定'}`
|
||||
setMessage(next.production_connected
|
||||
? `发布目标已更新:${where}。之后新发布的“对内/对外”内容会写入这两个生产库(已发布过的条目仍回到原目标)。`
|
||||
: `发布目标已保存:${where};但当前核对不了生产端(${next.production_message}),下次发布前请确认。`)
|
||||
} catch (cause) { setError(cause instanceof Error ? cause.message : '保存生产知识库绑定失败') }
|
||||
finally { setSaving(false) }
|
||||
}
|
||||
|
||||
const optionLabel = (base: KnowledgeBaseOption) => `${base.name}(${base.knowledge_count} 文档)`
|
||||
const renderSide = (label: string, boundID: string, boundName: string) => (
|
||||
<div className={`kb-binding-side ${boundID ? 'bound' : 'warn'}`}>
|
||||
<b>{label}</b>
|
||||
<span>{boundID ? (boundName || `${boundID.slice(0, 8)}…`) : '未绑定 · 按同 ID 语义发布(目标端须存在同 ID 库)'}</span>
|
||||
<small>{boundID ? 'UI 绑定 · 发布写入此库' : '未绑定:沿用测试库 ID'}</small>
|
||||
</div>
|
||||
)
|
||||
const editorFor = (value: string, onChange: (next: string) => void, placeholder: string) => (
|
||||
options.length > 0
|
||||
? <select value={value} onChange={(event) => onChange(event.target.value)} aria-label={placeholder}>
|
||||
<option value="">{placeholder}</option>
|
||||
{options.map((base) => <option key={base.id} value={base.id}>{optionLabel(base)}</option>)}
|
||||
</select>
|
||||
: <input value={value} onChange={(event) => onChange(event.target.value.trim())} placeholder={`${placeholder}(输入生产知识库 ID)`} aria-label={placeholder} />
|
||||
)
|
||||
|
||||
return <section className="settings-panel wide" id="settings-production-bindings">
|
||||
<div className="settings-section-heading"><div><h2>生产知识库绑定</h2><p>发布链路的“源库 → 目标库”:新发布的对内 / 对外内容按这里的绑定写入生产 WeKnora 的对应知识库。留空表示未绑定,按同 ID 语义发布。</p></div><button onClick={() => void load()} disabled={loading}>{loading ? '读取中…' : '重新读取'}</button></div>
|
||||
{error ? <p className="error-message" role="alert">{error}</p> : null}
|
||||
{bindings ? <div className="kb-binding-grid">
|
||||
{renderSide('对内生产知识库', bindings.internal_kb_id, bindings.internal_kb_name)}
|
||||
{renderSide('对外生产知识库', bindings.external_kb_id, bindings.external_kb_name)}
|
||||
</div> : null}
|
||||
{bindings && !bindings.production_connected ? <p className="hint">生产端核对不可用:{bindings.production_message}。{bindings.production_base_url ? `(生产地址:${bindings.production_base_url})` : ''}</p> : null}
|
||||
{bindings && bindings.production_connected && bindings.production_base_url ? <p className="hint">生产端:{bindings.production_base_url}{bindings.updated_by ? ` · 最近修改:${bindings.updated_by}` : ''}</p> : null}
|
||||
{isAdmin && bindings ? <div className="kb-binding-editor">
|
||||
<label>对内目标库 {editorFor(internalDraft, setInternalDraft, '选择对内生产知识库')}</label>
|
||||
<label>对外目标库 {editorFor(externalDraft, setExternalDraft, '选择对外生产知识库')}</label>
|
||||
<p className="hint">保存时会向生产端核对所选的库是否真实存在;对不上会拒收,生产端不可达则只提示。</p>
|
||||
{sameSelection ? <p className="error-message">对内与对外必须绑定不同的生产知识库</p> : null}
|
||||
<button onClick={() => void save()} disabled={saving || !dirty || sameSelection}>{saving ? '正在核对并保存…' : '保存发布目标'}</button>
|
||||
{message ? <p className="success-message" role="status">{message}</p> : null}
|
||||
</div> : null}
|
||||
{!isAdmin ? <p className="hint">仅管理员可修改发布目标。</p> : null}
|
||||
</section>
|
||||
}
|
||||
Reference in New Issue
Block a user