feat(reconciliation): 冻结导入对账接口契约

为什么:T6a 第一个提交只含 OpenAPI,先冻结 runs/findings/actions/progress 与 overview 队列字段,后端与前端按契约实现。
契约用 kb_id/document_id 作为 API 字段名,数据库列名保持 test_kb_id/knowledge_id;现有 OpenAPI 安全门禁不允许后者出现在契约里。
验证:go test ./internal/httpapi -run TestOpenAPI 通过。
This commit is contained in:
Zhero & Rin
2026-12-01 11:58:05 +08:00
committed by 姚章浩
parent 5af9b14a11
commit 580695ca2e
+12
View File
@@ -44,6 +44,13 @@
}
],
"paths": {
"/api/v1/reconciliation/runs": {"post":{"tags":["Reconciliation"],"operationId":"createReconciliationRun","summary":"手动触发一个测试库的对账批次;同一知识库已有 running 批次时返回 409","parameters":[{"name":"X-Governance-Action","in":"header","required":true,"schema":{"const":"reconciliation-action"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":false,"required":["kb_id"],"properties":{"kb_id":{"type":"string","minLength":1,"maxLength":255}}}}}},"responses":{"202":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"403":{"description":"仅管理员或文档工程师"},"409":{"description":"reconciliation_run_in_progress"},"500":{"$ref":"#/components/responses/InternalError"}}},"get":{"tags":["Reconciliation"],"operationId":"listReconciliationRuns","summary":"按开始时间倒序列出对账批次","parameters":[{"name":"kb_id","in":"query","required":false,"schema":{"type":"string","maxLength":255}},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","minimum":1,"maximum":100,"default":20}},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","minimum":0,"maximum":1000000,"default":0}}],"responses":{"200":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"403":{"description":"角色或写入意图不足"},"500":{"$ref":"#/components/responses/InternalError"}}}},
"/api/v1/reconciliation/runs/{id}": {"get":{"tags":["Reconciliation"],"operationId":"getReconciliationRun","summary":"读取单个对账批次","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"404":{"$ref":"#/components/responses/NotFound"},"500":{"$ref":"#/components/responses/InternalError"}}}},
"/api/v1/reconciliation/runs/{id}/findings": {"get":{"tags":["Reconciliation"],"operationId":"listReconciliationFindings","summary":"按类型和关键词筛选批次差异明细","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"type","in":"query","required":false,"schema":{"type":"string","enum":["R1","R2","R3","R4","R5","R6","R7","R8"]}},{"name":"q","in":"query","required":false,"schema":{"type":"string","maxLength":512}},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","minimum":1,"maximum":100,"default":20}},{"name":"offset","in":"query","required":false,"schema":{"type":"integer","minimum":0,"maximum":1000000,"default":0}}],"responses":{"200":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"404":{"$ref":"#/components/responses/NotFound"},"500":{"$ref":"#/components/responses/InternalError"}}}},
"/api/v1/reconciliation/findings/{id}/writeback": {"post":{"tags":["Reconciliation"],"operationId":"writebackReconciliationFinding","summary":"仅限 R5:以 WeKnora 状态回写台账 processing_state,写审计;completed 不可降级","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"X-Governance-Action","in":"header","required":true,"schema":{"const":"reconciliation-action"}}],"responses":{"200":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"403":{"description":"仅管理员或文档工程师"},"404":{"$ref":"#/components/responses/NotFound"},"409":{"description":"reconciliation_writeback_stale 或迁移不允许"},"500":{"$ref":"#/components/responses/InternalError"}}}},
"/api/v1/reconciliation/findings/{id}/requeue": {"post":{"tags":["Reconciliation"],"operationId":"requeueReconciliationFinding","summary":"仅限 R1/R4:R1 清空 document_id 后重排上传;R4 先删旧知识再重传,删除失败则台账不变","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"X-Governance-Action","in":"header","required":true,"schema":{"const":"reconciliation-action"}}],"responses":{"200":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"403":{"description":"仅管理员或文档工程师"},"404":{"$ref":"#/components/responses/NotFound"},"409":{"description":"finding 状态或台账身份已变化"},"500":{"$ref":"#/components/responses/InternalError"}}}},
"/api/v1/reconciliation/findings/{id}/remove": {"post":{"tags":["Reconciliation"],"operationId":"removeReconciliationFinding","summary":"仅限 R2:按远端 document_id 从测试库删除;404 视为已删除;重复点击幂等","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"X-Governance-Action","in":"header","required":true,"schema":{"const":"reconciliation-action"}}],"responses":{"200":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"403":{"description":"仅管理员"},"404":{"$ref":"#/components/responses/NotFound"},"409":{"description":"该文档已被现行台账收养"},"500":{"$ref":"#/components/responses/InternalError"}}}},
"/api/v1/reconciliation/documents/{document_id}/progress": {"get":{"tags":["Reconciliation"],"operationId":"getReconciliationDocumentProgress","summary":"实时转发并脱敏 WeKnora 文档处理阶段与历史失败;未配置平台只读 Key 时返回 503 runtime_read_unavailable","parameters":[{"name":"document_id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"404":{"$ref":"#/components/responses/NotFound"},"500":{"$ref":"#/components/responses/InternalError"},"503":{"$ref":"#/components/responses/ServiceUnavailable"}}}},
"/api/v1/qa-ops/master/field-options": {"get":{"operationId":"getQAMasterFieldOptions","tags":["QA operations"],"summary":"只读主表五字段的正式可选范围,与模型共享同一分类字典;不返回业务问答","parameters":[],"responses":{"200":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"403":{"description":"仅管理员且写入须同源操作意图"},"409":{"description":"版本、输入或nonce冲突,未覆盖现有数据"},"500":{"$ref":"#/components/responses/InternalError"},"503":{"description":"独立治理存储不可用,不将失败伪装为已保存"}}}},
"/api/v1/qa-ops/master/records/{id}/fields": {"post":{"operationId":"patchQAMasterFields","tags":["QA operations"],"summary":"只更新明确选择的字段并留幂等审计;不改原始正文、其他空白、旧复核或冻结证据。未覆盖的是否正确固定为待确认,拒绝是或否;已覆盖点踩固定为否。quality.correctness_rule=coverage-correctness-v1标记覆盖/正确性固定投影,原字段和复核证据保留","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"X-Governance-Action","in":"header","required":true,"schema":{"const":"qa-master-fields"}}],"responses":{"200":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"403":{"description":"仅管理员且写入须同源操作意图"},"409":{"description":"版本、输入或nonce冲突,未覆盖现有数据"},"500":{"$ref":"#/components/responses/InternalError"},"503":{"description":"独立治理存储不可用,不将失败伪装为已保存"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":false,"required":["input_hash","input_epoch","base_revision","base_review_revision","nonce","fields"],"properties":{"input_hash":{"type":"string","pattern":"^[a-f0-9]{64}$"},"input_epoch":{"type":"integer","minimum":1},"base_revision":{"type":"integer","minimum":0},"base_review_revision":{"type":"integer","minimum":0},"nonce":{"type":"string","pattern":"^[a-zA-Z0-9][a-zA-Z0-9_.:-]{15,127}$"},"fields":{"type":"object","additionalProperties":false,"minProperties":1,"maxProperties":5,"properties":{"is_correct":{"type":"string","enum":["是","否","待确认"]},"product_category":{"type":"string","enum":["CR/CRA/H/AP","CRV","CR配件","Nova及系列","Nova配件","MG400","MG400配件","M1 Pro","VX500","新示教器","DobotStudio Pro","仿真软件","维护工具","教育所有产品","人形机器人","四六足机器人","X-Trainer","码垛解决方案","码垛插件","焊接解决方案","焊接插件","移动复合机器人","生态插件","生态合作","安全皮肤","未知"]},"problem_type":{"type":"string","enum":["参数","故障","使用配置","二次开发","资料获取","咨询","认证","案例","售后","培训与学习","其他"]},"root_cause":{"type":"string","enum":["知识缺失","检索不到","结果不清","答案生成错误","问题质量差","非知识范围","知识过期"]},"coverage":{"type":"string","enum":["是","否","否但不计入"]}}}}}}}}}},
"/api/v1/qa-ops/master/weekly-drafts/{week}": {"get":{"operationId":"getQAWeeklyDraft","tags":["QA operations"],"summary":"读取租户指定北京时间ISO周的持久草稿;不存在时revision=0且不创建记录","parameters":[{"name":"week","in":"path","required":true,"schema":{"type":"string","pattern":"^[0-9]{4}-W[0-9]{2}$"}}],"responses":{"200":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"403":{"description":"仅管理员且写入须同源操作意图"},"409":{"description":"版本、输入或nonce冲突,未覆盖现有数据"},"500":{"$ref":"#/components/responses/InternalError"},"503":{"description":"独立治理存储不可用,不将失败伪装为已保存"}}},"post":{"operationId":"saveQAWeeklyDraft","tags":["QA operations"],"summary":"防抖编辑保存:版本锁、逐版历史及同nonce重放;正文不会触发外发/归档","parameters":[{"name":"week","in":"path","required":true,"schema":{"type":"string","pattern":"^[0-9]{4}-W[0-9]{2}$"}},{"name":"X-Governance-Action","in":"header","required":true,"schema":{"const":"qa-weekly-draft"}}],"responses":{"200":{"$ref":"#/components/responses/Envelope"},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"description":"需要登录"},"403":{"description":"仅管理员且写入须同源操作意图"},"409":{"description":"版本、输入或nonce冲突,未覆盖现有数据"},"500":{"$ref":"#/components/responses/InternalError"},"503":{"description":"独立治理存储不可用,不将失败伪装为已保存"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":false,"required":["base_revision","nonce","markdown"],"properties":{"base_revision":{"type":"integer","minimum":0},"nonce":{"type":"string","pattern":"^[a-zA-Z0-9][a-zA-Z0-9_.:-]{15,127}$"},"markdown":{"type":"string","maxLength":262144,"description":"UTF-8正文最多256KiB;允许空正文,保存草稿不等于发布"}}}}}}}},
@@ -6162,6 +6169,11 @@
}
},
"schemas": {
"ReconciliationRun": {"type":"object","additionalProperties":false,"required":["id","kb_id","state","trigger","started_at","finished_at","ledger_count","kb_count","counts","previous_counts","window_overlapped","error_code"],"properties":{"id":{"type":"string"},"kb_id":{"type":"string","minLength":1,"maxLength":255},"state":{"type":"string","enum":["running","succeeded","failed"]},"trigger":{"type":"string","enum":["schedule","manual"]},"started_at":{"type":"string","format":"date-time"},"finished_at":{"type":["string","null"],"format":"date-time"},"ledger_count":{"type":"integer","minimum":0},"kb_count":{"type":"integer","minimum":0},"counts":{"type":"object","additionalProperties":false,"required":["R1","R2","R3","R4","R5","R6","R7","R8"],"properties":{"R1":{"type":"integer","minimum":0},"R2":{"type":"integer","minimum":0},"R3":{"type":"integer","minimum":0},"R4":{"type":"integer","minimum":0},"R5":{"type":"integer","minimum":0},"R6":{"type":"integer","minimum":0},"R7":{"type":"integer","minimum":0},"R8":{"type":"integer","minimum":0}}},"previous_counts":{"type":["object","null"],"additionalProperties":{"type":"integer","minimum":0}},"window_overlapped":{"type":"boolean"},"error_code":{"type":"string"}}},
"ReconciliationFinding": {"type":"object","additionalProperties":false,"required":["id","run_id","type","publication_id","document_id","title","path","source","target_scope","ledger_state","weknora_parse_status","normalized_state","ledger_sha256","declared_sha256","weknora_file_md5","evidence_level","confirmation_state","detail","suggested_action","action_state","weknora_url"],"properties":{"id":{"type":"string"},"run_id":{"type":"string"},"type":{"type":"string","enum":["R1","R2","R3","R4","R5","R6","R7","R8"]},"publication_id":{"type":"string"},"document_id":{"type":"string"},"title":{"type":"string"},"path":{"type":"string"},"source":{"type":"string"},"target_scope":{"type":"string","enum":["internal","external","unknown"]},"ledger_state":{"type":"string"},"weknora_parse_status":{"type":"string"},"normalized_state":{"type":"string"},"ledger_sha256":{"type":"string"},"declared_sha256":{"type":"string"},"weknora_file_md5":{"type":"string"},"evidence_level":{"type":"string","enum":["independent","declared_only","none"]},"confirmation_state":{"type":"string","enum":["confirmed","pending"]},"detail":{"type":"string"},"suggested_action":{"type":"string","enum":["requeue_upload","remove_from_test","writeback_state","enter_removal","none"]},"action_state":{"type":"string","enum":["open","done"]},"weknora_url":{"type":"string"}}},
"ReconciliationRunPage": {"type":"object","additionalProperties":false,"required":["items","total","limit","offset"],"properties":{"items":{"type":"array","items":{"$ref":"#/components/schemas/ReconciliationRun"}},"total":{"type":"integer","minimum":0},"limit":{"type":"integer","minimum":1,"maximum":100},"offset":{"type":"integer","minimum":0}}},
"ReconciliationFindingPage": {"type":"object","additionalProperties":false,"required":["items","total","limit","offset"],"properties":{"items":{"type":"array","items":{"$ref":"#/components/schemas/ReconciliationFinding"}},"total":{"type":"integer","minimum":0},"limit":{"type":"integer","minimum":1,"maximum":100},"offset":{"type":"integer","minimum":0}}},
"ReconciliationProgress": {"type":"object","additionalProperties":false,"required":["document_id","parse_status","ingestion_status","wiki_status","stages","failures","has_more_failures","observed_at"],"properties":{"document_id":{"type":"string"},"parse_status":{"type":"string"},"ingestion_status":{"type":"string"},"wiki_status":{"type":"string"},"stages":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["name","status"],"properties":{"name":{"type":"string"},"status":{"type":"string"},"error_code":{"type":"string"},"finished_at":{"type":["string","null"],"format":"date-time"}}}},"failures":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["task_type","fail_count","failed_at","last_error"],"properties":{"task_type":{"type":"string"},"fail_count":{"type":"integer","minimum":0},"failed_at":{"type":"string","format":"date-time"},"last_error":{"type":"string","maxLength":500}}}},"has_more_failures":{"type":"boolean"},"observed_at":{"type":"string","format":"date-time"}}},
"KBBindingEnvironmentView": {
"type": "object",
"additionalProperties": false,