c753c67608
将 swag 注解覆盖率从 ~88% 提升到 100%,并修复审计中发现的若干既有
注解 bug。
新增注解(24 个):
- im.go: 4 (UpdateIMChannel/DeleteIMChannel/ToggleIMChannel/IMCallback)
其中 IMCallback 同时注册 GET 和 POST,两个方法都加了 @Router 声明。
- web_search.go: 1 (GetProviders)
- web_search_provider.go: 6
- wechat_qrcode.go: 2
- weknoracloud.go: 2
- knowledge.go: 2 (MoveKnowledge/GetKnowledgeMoveProgress)
- knowledgebase.go: 1 (ListMoveTargets)
- organization.go: 3 (ListSharedAgents/ListOrgAgentShares/RemoveAgentShare)
- mcp_service.go: 2 (SetMCPToolApproval/ResolveToolApproval)
- chunker_debug.go: 1 (PreviewChunking)
修复既有注解 bug(12 处):
- initialization.go: 10 个 @Router 路径与真实路由不符
(e.g. /initialization/kb/{kbId}/config → /initialization/config/{kbId}
/initialization/fabri/tag GET → /initialization/extract/fabri-tag POST)
- session/stream.go: ContinueStream 路径
/sessions/{session_id}/continue → /sessions/continue-stream/{session_id}
- mcp_service.go: ResolveToolApproval 请求体 {approve: bool}
→ {decision: "approve"|"reject", reason?, modified_args?}
收敛响应 schema 到已有命名 struct(之前用 map[string]interface{}):
- knowledge.go MoveKnowledge → handler.MoveKnowledgeResponse
- knowledge.go GetKnowledgeMoveProgress → types.KnowledgeMoveProgress
- web_search_provider.go GetProvider/UpdateProvider → types.WebSearchProviderEntity
- initialization.go InitializeByKB → handler.InitializationRequest
- initialization.go 三个 model-test endpoint → handler.ModelTestRequest
修正 organization.go 中 errors.AppError 应使用 apperrors 别名(该文件
stdlib errors 未别名化)。
不补 /files 和 /api/v1/files/presigned 内联闭包路由(文件服务,非业务 REST)。
Refs #890 #1049 #1168
76 lines
2.6 KiB
Go
76 lines
2.6 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/Tencent/WeKnora/internal/types/interfaces"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// WeKnoraCloudHandler 处理 WeKnoraCloud 凭证管理
|
|
type WeKnoraCloudHandler struct {
|
|
svc interfaces.WeKnoraCloudService
|
|
}
|
|
|
|
// NewWeKnoraCloudHandler 构造函数
|
|
func NewWeKnoraCloudHandler(svc interfaces.WeKnoraCloudService) *WeKnoraCloudHandler {
|
|
return &WeKnoraCloudHandler{svc: svc}
|
|
}
|
|
|
|
type weKnoraCloudCredentialsRequest struct {
|
|
AppID string `json:"app_id" binding:"required"`
|
|
AppSecret string `json:"app_secret" binding:"required"`
|
|
}
|
|
|
|
// SaveCredentials POST /api/v1/weknoracloud/credentials
|
|
// 仅保存 APPID/APPSECRET 凭证到租户配置,不自动创建模型
|
|
//
|
|
// SaveCredentials godoc
|
|
// @Summary 保存 WeKnoraCloud 凭证
|
|
// @Description 保存 APPID/APPSECRET 到当前租户配置(不自动创建模型)
|
|
// @Tags WeKnoraCloud
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param request body map[string]interface{} true "{app_id, app_secret}"
|
|
// @Success 200 {object} map[string]interface{} "success: true"
|
|
// @Failure 400 {object} map[string]interface{} "请求参数错误"
|
|
// @Security Bearer
|
|
// @Security ApiKeyAuth
|
|
// @Router /weknoracloud/credentials [post]
|
|
func (h *WeKnoraCloudHandler) SaveCredentials(c *gin.Context) {
|
|
var req weKnoraCloudCredentialsRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
if err := h.svc.SaveCredentials(c.Request.Context(), req.AppID, req.AppSecret); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "message": "凭证保存成功"})
|
|
}
|
|
|
|
// Status GET /api/v1/models/weknoracloud/status
|
|
// 检查当前租户的 WeKnoraCloud 凭证是否完好,如需重新初始化则返回 needs_reinit=true
|
|
//
|
|
// Status godoc
|
|
// @Summary 检查 WeKnoraCloud 凭证状态
|
|
// @Description 检查当前租户的 WeKnoraCloud 凭证是否完好;needs_reinit=true 表示需要重新保存
|
|
// @Tags WeKnoraCloud
|
|
// @Produce json
|
|
// @Success 200 {object} map[string]interface{} "凭证状态"
|
|
// @Failure 500 {object} map[string]interface{} "服务器错误"
|
|
// @Security Bearer
|
|
// @Security ApiKeyAuth
|
|
// @Router /models/weknoracloud/status [get]
|
|
func (h *WeKnoraCloudHandler) Status(c *gin.Context) {
|
|
result, err := h.svc.CheckStatus(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, result)
|
|
}
|