feat(settings): 知识库绑定按环境一次保存连接与内外库

原「知识库映射 → WeKnora 连接」把地址、文件和绑定分散在多处,页面无法输入密钥,
也看不到候选实例真实可读的库。现在测试 090 / 生产 090 各自一个工作区:草稿填地址
与 API Key,服务器真实分页列库并区分空库/无权限/不可达,选内外库后一次保存连接与
绑定,回读真实生效值。

服务端以修订号 + 行锁 + 单事务写连接、绑定与待入库重排;旧部署无新行时继续使用文件
凭据/默认绑定。密钥只存 AES-256-GCM 密文,主密钥在独立文件;换地址必须重录,旧密钥
不转发、不跨环境取用。消费端(readiness/上传轮询/列库/探活/生产列库)统一从该存储
解析当前连接,避免只保存了页面数据。

验证:go test ./...;前端 606 项;隔离 PostgreSQL 集成用例覆盖保存/冲突/重排/拒错;
make verify 在本提交上执行(结果见交付说明)。
This commit is contained in:
姚章浩
2026-11-19 14:43:51 +08:00
parent df69b278ce
commit ce2a155ebc
53 changed files with 3367 additions and 601 deletions
+123
View File
@@ -3707,6 +3707,61 @@
}
}
},
"/api/v1/kb-bindings": {
"get": {
"tags": ["Settings"],
"operationId": "getKBBindings",
"summary": "读取测试/生产环境的 WeKnora 连接与内外库绑定(密钥不回显)",
"responses": {
"200": {"$ref": "#/components/responses/Envelope"},
"400": {"$ref": "#/components/responses/BadRequest"},
"500": {"$ref": "#/components/responses/InternalError"},
"503": {"$ref": "#/components/responses/ServiceUnavailable"}
}
}
},
"/api/v1/kb-bindings/{environment}/catalog": {
"post": {
"tags": ["Settings"],
"operationId": "catalogKBBindingConnection",
"summary": "用草稿地址与密钥真实列库(管理员,只读,分页)",
"parameters": [
{"name": "environment", "in": "path", "required": true, "schema": {"type": "string", "enum": ["test", "production"]}}
],
"requestBody": {
"required": true,
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/KBCatalogInput"}}}
},
"responses": {
"200": {"$ref": "#/components/responses/Envelope"},
"400": {"$ref": "#/components/responses/BadRequest"},
"409": {"$ref": "#/components/responses/Conflict"},
"500": {"$ref": "#/components/responses/InternalError"},
"503": {"$ref": "#/components/responses/ServiceUnavailable"}
}
}
},
"/api/v1/kb-bindings/{environment}": {
"put": {
"tags": ["Settings"],
"operationId": "saveKBBinding",
"summary": "一次保存当前环境的连接与内外库绑定(管理员)",
"parameters": [
{"name": "environment", "in": "path", "required": true, "schema": {"type": "string", "enum": ["test", "production"]}}
],
"requestBody": {
"required": true,
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/KBBindingSaveInput"}}}
},
"responses": {
"200": {"$ref": "#/components/responses/Envelope"},
"400": {"$ref": "#/components/responses/BadRequest"},
"409": {"$ref": "#/components/responses/Conflict"},
"500": {"$ref": "#/components/responses/InternalError"},
"503": {"$ref": "#/components/responses/ServiceUnavailable"}
}
}
},
"/api/v1/production-kb-bindings": {
"get": {
"tags": [
@@ -6084,6 +6139,74 @@
}
},
"schemas": {
"KBBindingEnvironmentView": {
"type": "object",
"additionalProperties": false,
"required": ["environment", "revision", "base_url", "key_configured", "internal_kb_id", "external_kb_id", "verification", "storage_ready", "source"],
"properties": {
"environment": {"type": "string", "enum": ["test", "production"]},
"revision": {"type": "integer", "minimum": 0},
"base_url": {"type": "string"},
"key_configured": {"type": "boolean"},
"key_source": {"type": "string", "enum": ["sealed", "file", "none"]},
"internal_kb_id": {"type": "string"},
"internal_kb_name": {"type": "string"},
"external_kb_id": {"type": "string"},
"external_kb_name": {"type": "string"},
"verification": {"type": "string"},
"checked_at": {"type": ["string", "null"]},
"updated_by": {"type": "string"},
"updated_at": {"type": ["string", "null"]},
"source": {"type": "string", "enum": ["web", "legacy"]},
"storage_ready": {"type": "boolean"},
"replanned": {"type": "integer", "minimum": 0},
"retired_duplicates": {"type": "integer", "minimum": 0}
}
},
"KBBindingSnapshot": {
"type": "object",
"additionalProperties": false,
"required": ["environments", "storage_ready"],
"properties": {
"environments": {"type": "array", "items": {"$ref": "#/components/schemas/KBBindingEnvironmentView"}},
"storage_ready": {"type": "boolean"}
}
},
"KBCatalogInput": {
"type": "object",
"additionalProperties": false,
"required": ["base_url", "key_action", "page", "page_size"],
"properties": {
"base_revision": {"type": "integer", "minimum": 0},
"base_url": {"type": "string"},
"key_action": {"type": "string", "enum": ["keep", "replace"]},
"api_key": {"type": "string", "writeOnly": true, "maxLength": 4096},
"page": {"type": "integer", "minimum": 1},
"page_size": {"type": "integer", "minimum": 1, "maximum": 100}
}
},
"KBBindingSaveInput": {
"type": "object",
"additionalProperties": false,
"required": ["base_url", "key_action", "internal_kb_id", "external_kb_id"],
"properties": {
"base_revision": {"type": "integer", "minimum": 0},
"base_url": {"type": "string"},
"key_action": {"type": "string", "enum": ["keep", "replace"]},
"api_key": {"type": "string", "writeOnly": true, "maxLength": 4096},
"internal_kb_id": {"type": "string"},
"external_kb_id": {"type": "string"}
}
},
"KBCatalogOption": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {"type": "string"},
"name": {"type": "string"},
"knowledge_count": {"type": "integer"}
}
},
"PPConnectionDraft": {
"type": "object",
"required": [