fix(admin): 诊断解析放错了函数 + 补 kb_search 形状测试
上一个提交里,诊断解析被塞进了用户面的 KbSearch,而真正传 diag 的
AdminKbSearch 还在用老代码 —— 于是试验台永远拿不到 routes。写法上是
字符串替换只改了文件里第一处匹配,而这两个 handler 的收尾代码一模一样。
用户面已还原(它不传 diag,拿到的本就是裸数组,多一层解析是错的)。
补 3 组 mcp 层测试钉死 kb_search 的两种返回形状:
- 不带 diag(生产调用:dispatcher / Agent 工具链)→ 裸 JSON 数组,契约不变;
- 带 diag → {hits, routes} 对象;
- not ready 时不被总闸短路,仍逐路诊断。
这层是"改可观测性顺手改坏生产"的高风险位置:diag 分支若无条件生效,所有
调用方的解析都会静默失败。
真环境验证(本地 gateway + mcp-go + 真 PG/Milvus/bleve):
vector empty 该知识库在 Milvus 中没有向量(未入库或集合被重建过)
fulltext ok 15 命中
graph disabled Neo4j 未连接或未配置
以前这三行都只是"0 条"。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -18,9 +18,9 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/sundynix/sundynix-shared/blob"
|
||||
"github.com/sundynix/sundynix-gateway/internal/nats"
|
||||
"github.com/sundynix/sundynix-gateway/internal/store"
|
||||
"github.com/sundynix/sundynix-shared/blob"
|
||||
"github.com/sundynix/sundynix-shared/contract"
|
||||
)
|
||||
|
||||
@@ -548,18 +548,9 @@ func (h *Handler) KbSearch(c *gin.Context) {
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": res.Error})
|
||||
return
|
||||
}
|
||||
var out struct {
|
||||
Hits []map[string]any `json:"hits"`
|
||||
Routes []map[string]any `json:"routes"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(res.Content), &out); err != nil {
|
||||
// 兼容老 mcp-go(未部署新版时仍回裸数组),别因为这个把试验台整个打挂。
|
||||
var hits []map[string]any
|
||||
_ = json.Unmarshal([]byte(res.Content), &hits)
|
||||
c.JSON(http.StatusOK, gin.H{"hits": hits})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"hits": out.Hits, "routes": out.Routes})
|
||||
var hits []map[string]any
|
||||
_ = json.Unmarshal([]byte(res.Content), &hits)
|
||||
c.JSON(http.StatusOK, gin.H{"hits": hits})
|
||||
}
|
||||
|
||||
// AdminKbSearch: POST /api/v1/admin/kb/search —— 管理端「检索试验台」:按**完整作用域键**
|
||||
@@ -602,9 +593,19 @@ func (h *Handler) AdminKbSearch(c *gin.Context) {
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": res.Error})
|
||||
return
|
||||
}
|
||||
var hits []map[string]any
|
||||
_ = json.Unmarshal([]byte(res.Content), &hits)
|
||||
c.JSON(http.StatusOK, gin.H{"hits": hits})
|
||||
// 带 diag 时 mcp-go 回的是 {hits, routes} 对象;老版本回裸数组,做兼容降级
|
||||
// (少了诊断而已,不该让整个试验台打不开)。
|
||||
var out struct {
|
||||
Hits []map[string]any `json:"hits"`
|
||||
Routes []map[string]any `json:"routes"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(res.Content), &out); err != nil {
|
||||
var hits []map[string]any
|
||||
_ = json.Unmarshal([]byte(res.Content), &hits)
|
||||
c.JSON(http.StatusOK, gin.H{"hits": hits})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"hits": out.Hits, "routes": out.Routes})
|
||||
}
|
||||
|
||||
// KbGraph: GET /api/v1/kb/graph?kb= —— 某知识库的图谱三元组(→ mcp-go kb_graph,Neo4j)。
|
||||
|
||||
Reference in New Issue
Block a user