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:
姚章浩
2026-10-08 15:41:13 +08:00
parent cddc4c90d1
commit 6440e3f679
40 changed files with 1823 additions and 92 deletions
+65
View File
@@ -0,0 +1,65 @@
import { newOperationID } from './operationKey'
import type { KnowledgeBaseOption } from './routingBindings'
// 源库 → 目标库(生产)映射:系统设置里选择发布要写入的生产知识库。
export interface ProductionBindings {
internal_kb_id: string
external_kb_id: string
internal_kb_name: string
external_kb_name: string
updated_by: string
production_base_url: string
production_connected: boolean
production_message: string
}
const record = (value: unknown): value is Record<string, unknown> => Boolean(value) && typeof value === 'object' && !Array.isArray(value)
function projection(item: Record<string, unknown>): ProductionBindings {
return {
internal_kb_id: typeof item.internal_kb_id === 'string' ? item.internal_kb_id : '',
external_kb_id: typeof item.external_kb_id === 'string' ? item.external_kb_id : '',
internal_kb_name: typeof item.internal_kb_name === 'string' ? item.internal_kb_name : '',
external_kb_name: typeof item.external_kb_name === 'string' ? item.external_kb_name : '',
updated_by: typeof item.updated_by === 'string' ? item.updated_by : '',
production_base_url: typeof item.production_base_url === 'string' ? item.production_base_url : '',
production_connected: item.production_connected === true,
production_message: typeof item.production_message === 'string' ? item.production_message : '',
}
}
export async function fetchProductionBindings(signal?: AbortSignal): Promise<ProductionBindings> {
const response = await fetch('/api/v1/production-kb-bindings', { signal, headers: { Accept: 'application/json' } })
if (!response.ok) throw new Error(`读取生产知识库绑定失败(HTTP ${response.status})`)
const value = await response.json() as unknown
if (!record(value) || !record(value.data)) throw new Error('生产知识库绑定响应无效')
return projection(value.data)
}
export async function fetchProductionBindingOptions(signal?: AbortSignal): Promise<KnowledgeBaseOption[]> {
const response = await fetch('/api/v1/production-kb-bindings/options', { signal, headers: { Accept: 'application/json' } })
if (!response.ok) throw new Error(`读取生产知识库列表失败(HTTP ${response.status})`)
const value = await response.json() as unknown
if (!record(value) || !Array.isArray(value.data)) throw new Error('生产知识库列表响应无效')
return value.data.filter(record).map((item) => ({
id: typeof item.id === 'string' ? item.id : '',
name: typeof item.name === 'string' ? item.name : '',
knowledge_count: typeof item.knowledge_count === 'number' ? item.knowledge_count : 0,
})).filter((item) => item.id)
}
export async function saveProductionBindings(input: { internal_kb_id: string; external_kb_id: string }, signal?: AbortSignal): Promise<ProductionBindings> {
const response = await fetch('/api/v1/production-kb-bindings', {
method: 'PUT', signal,
headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'Idempotency-Key': newOperationID() },
body: JSON.stringify(input),
})
if (!response.ok) {
let reason = `保存生产知识库绑定失败(HTTP ${response.status})`
try { const body = await response.json() as unknown; if (record(body) && typeof body.error === 'string') reason = body.error } catch { /* keep status text */ }
throw new Error(reason)
}
const value = await response.json() as unknown
if (!record(value) || !record(value.data)) throw new Error('生产知识库绑定响应无效')
return projection(value.data)
}