package handler import ( "net/http" "github.com/gin-gonic/gin" "github.com/sundynix/sundynix-shared/contract" ) // KbIngest: POST /api/v1/kb/ingest —— 把文本入库到知识库(→ mcp-go kb_ingest → 切块/embedding/Milvus)。 // 供知识库管理页/脚本调用。 func (h *Handler) KbIngest(c *gin.Context) { var body struct { KB string `json:"kb"` Text string `json:"text"` } if err := c.ShouldBindJSON(&body); err != nil || body.Text == "" { c.JSON(http.StatusBadRequest, gin.H{"error": "text required"}) return } res, err := h.bus.CallTool(c.Request.Context(), contract.ToolSubjectGo("kb_ingest"), &contract.ToolCall{Tool: "kb_ingest", Args: map[string]any{"kb": body.KB, "text": body.Text}}) if err != nil { c.JSON(http.StatusBadGateway, gin.H{"error": err.Error()}) return } if !res.OK { c.JSON(http.StatusUnprocessableEntity, gin.H{"error": res.Error}) return } c.JSON(http.StatusOK, gin.H{"status": "ok", "message": res.Content}) }