c6c1c00141
- Implement role management endpoints including listing, creating, updating, and deleting roles. - Add session management endpoints for viewing and revoking sessions. - Create skill definition management endpoints for CRUD operations and status updates. - Introduce tag management endpoints for handling tags with sorting and status updates. - Develop ticket management endpoints for viewing, creating, updating, and managing ticket progress. - Implement user management endpoints for CRUD operations, role assignments, and password resets. - Add WeChat callback handlers for verifying and processing messages.
97 lines
2.3 KiB
Go
97 lines
2.3 KiB
Go
package dashboard
|
|
|
|
import (
|
|
"context"
|
|
"cs-agent/internal/pkg/httpx"
|
|
|
|
"cs-agent/internal/ai/rag"
|
|
"cs-agent/internal/pkg/constants"
|
|
"cs-agent/internal/pkg/dto/request"
|
|
"cs-agent/internal/services"
|
|
|
|
"cs-agent/internal/pkg/httpx/params"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/mlogclub/simple/web"
|
|
)
|
|
|
|
func KnowledgeRetrievePostDebugSearch(ctx *gin.Context) {
|
|
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionKnowledgeDocumentView); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
|
|
req := request.KnowledgeSearchRequest{}
|
|
if err := params.ReadJSON(ctx, &req); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
|
|
resp, err := rag.Answer.DebugSearch(context.Background(), req)
|
|
if err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
httpx.WriteJSON(ctx, resp)
|
|
}
|
|
|
|
func KnowledgeRetrievePostDebugAnswer(ctx *gin.Context) {
|
|
operator, err := services.AuthService.RequirePermission(ctx, constants.PermissionKnowledgeDocumentView)
|
|
if err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
|
|
req := request.KnowledgeAnswerRequest{}
|
|
if err := params.ReadJSON(ctx, &req); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
|
|
resp, err := rag.Answer.DebugAnswer(context.Background(), req, operator)
|
|
if err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
httpx.WriteJSON(ctx, resp)
|
|
}
|
|
|
|
func KnowledgeRetrievePostBuild(ctx *gin.Context) {
|
|
req := struct {
|
|
DocumentID int64 `json:"documentId"`
|
|
FAQID int64 `json:"faqId"`
|
|
}{}
|
|
if err := params.ReadJSON(ctx, &req); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
|
|
if req.DocumentID > 0 {
|
|
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionKnowledgeDocumentUpdate); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
if err := rag.Answer.BuildDocumentIndex(context.Background(), req.DocumentID); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
httpx.WriteJSON(ctx, nil)
|
|
return
|
|
}
|
|
|
|
if req.FAQID > 0 {
|
|
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionKnowledgeFAQUpdate); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
if err := rag.Index.IndexFAQByID(context.Background(), req.FAQID); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
httpx.WriteJSON(ctx, nil)
|
|
return
|
|
}
|
|
|
|
httpx.WriteJSON(ctx, web.JsonErrorMsg("documentId或faqId不能为空"))
|
|
}
|