2bbf42b741
Remove Agent Desk users, roles, login sessions, tokens, and local permission persistence. Expose the backend as an embeddable ai-agent module with host-provided subject lookup and operation authorization callbacks, and complete the frontend/backend repository split.
96 lines
2.4 KiB
Go
96 lines
2.4 KiB
Go
package dashboard
|
|
|
|
import (
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx"
|
|
"context"
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/ai/rag"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/constants"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/dto/request"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/services"
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx/params"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
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, httpx.JsonErrorMsg(ctx, "error.e0066"))
|
|
}
|