Go: refactor API route (#17139)

### Summary

As title.

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-07-21 12:18:47 +08:00
committed by GitHub
parent b288888050
commit 3cc6539c32
2 changed files with 13 additions and 74 deletions

View File

@@ -1,57 +0,0 @@
//
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package router
import (
"github.com/gin-gonic/gin"
"ragflow/internal/handler"
)
// RegisterChatbotRoutes wires the dialog (legacy chatbot) endpoints
// on the /api/v1/chatbots subtree. Mirrors python
//
// @manager.route("/chatbots/<dialog_id>/completions") bot_api.py:55
// @manager.route("/chatbots/<dialog_id>/info") bot_api.py:126
//
// The two bot route groups (chatbots + agentbots) cannot share a
// registrar because each carries a different <param_name>
// (dialog_id vs agent_id) and would otherwise register paths under
// the wrong group.
func RegisterChatbotRoutes(g *gin.RouterGroup, mw gin.HandlerFunc, h *handler.BotHandler) {
if g == nil || h == nil {
return
}
g.Use(mw)
g.POST("/:dialog_id/completions", h.ChatbotCompletion)
g.GET("/:dialog_id/info", h.ChatbotInfo)
}
// RegisterAgentbotRoutes wires the canvas-based agent endpoints on
// the /api/v1/agentbots subtree. Mirrors python
//
// @manager.route("/agentbots/<agent_id>/completions") bot_api.py:157
// @manager.route("/agentbots/<agent_id>/inputs") bot_api.py:239
// @manager.route("/agentbots/<shared_id>/logs/<message_id>") bot_api.py:251
func RegisterAgentbotRoutes(g *gin.RouterGroup, mw gin.HandlerFunc, h *handler.BotHandler) {
if g == nil || h == nil {
return
}
g.POST("/:agent_id/completions", h.AgentbotCompletion)
g.GET("/:agent_id/inputs", h.AgentbotInputs)
g.GET("/:agent_id/logs/:message_id", h.GetAgentbotLogs)
}

View File

@@ -169,10 +169,8 @@ func (r *Router) Setup(engine *gin.Engine) {
// no auth required. The front end uses it to populate the parser
// picker without hard-coding the parser_id list.
// Query: ?type=builtin returns built-in templates (default).
if r.pipelineHandler != nil {
apiNoAuth.GET("/pipelines", r.pipelineHandler.ListPipelines)
apiNoAuth.GET("/pipelines/:id", r.pipelineHandler.GetPipeline)
}
apiNoAuth.GET("/pipelines", r.pipelineHandler.ListPipelines)
apiNoAuth.GET("/pipelines/:id", r.pipelineHandler.GetPipeline)
// searchbots
apiNoAuth.GET("/searchbots/detail", r.searchBotHandler.SearchbotDetail)
@@ -222,13 +220,15 @@ func (r *Router) Setup(engine *gin.Engine) {
searchBotGroup.POST("/ask", r.searchBotHandler.Ask)
searchBotGroup.POST("/mindmap", r.searchBotHandler.MindMap)
if r.botHandler != nil {
chatbotGroup := apiBetaAuth.Group("/chatbots")
betaMW := r.authHandler.BetaAuthMiddleware()
RegisterChatbotRoutes(chatbotGroup, betaMW, r.botHandler)
agentbotGroup := apiBetaAuth.Group("/agentbots")
RegisterAgentbotRoutes(agentbotGroup, betaMW, r.botHandler)
}
chatBotGroup := apiBetaAuth.Group("/chatbots")
chatBotGroup.POST("/:dialog_id/completions", r.botHandler.ChatbotCompletion)
chatBotGroup.GET("/:dialog_id/info", r.botHandler.ChatbotInfo)
agentBotGroup := apiBetaAuth.Group("/agentbots")
agentBotGroup.POST("/:agent_id/completions", r.botHandler.AgentbotCompletion)
agentBotGroup.GET("/:agent_id/inputs", r.botHandler.AgentbotInputs)
agentBotGroup.GET("/:agent_id/logs/:message_id", r.botHandler.GetAgentbotLogs)
// Public bot endpoints (authenticated with an SDK beta token, not a session)
apiBetaAuth.GET("/documents/:id/preview", r.documentHandler.GetDocumentPreview)
apiBetaAuth.GET("/documents/images/:image_id", r.documentHandler.GetDocumentImage)
@@ -237,9 +237,7 @@ func (r *Router) Setup(engine *gin.Engine) {
// MCP server endpoint — exposes RAGFlow capabilities as MCP tools.
// Uses BetaAuthMiddleware to resolve the user from the
// Authorization header.
if r.mcpServerHandler != nil {
apiBetaAuth.POST("/mcp", r.mcpServerHandler.HandleMCP)
}
apiBetaAuth.POST("/mcp", r.mcpServerHandler.HandleMCP)
}
// Protected routes
@@ -594,9 +592,7 @@ func (r *Router) Setup(engine *gin.Engine) {
// ?category=ingestion,agent,shared filter; defaults to
// all categories. The data source is
// runtime.DefaultRegistry.
if r.componentsHandler != nil {
v1.GET("/components", r.componentsHandler.Get)
}
v1.GET("/components", r.componentsHandler.Get)
connectors := v1.Group("/connectors")
{