fix: unable to open filter in agent page(no agent tags...) (#16531)

### Summary

As title
This commit is contained in:
Haruko386
2026-07-01 19:07:15 +08:00
committed by GitHub
parent fcf2ca869b
commit 9eacbb418f
6 changed files with 230 additions and 24 deletions

View File

@@ -167,6 +167,15 @@ func (h *AgentHandler) ListAgents(c *gin.Context) {
}
}
}
var tags []string
if raw := c.Query("tags"); raw != "" {
for _, tag := range strings.Split(raw, ",") {
tag = strings.TrimSpace(tag)
if tag != "" {
tags = append(tags, tag)
}
}
}
result, code, err := h.agentService.ListAgents(
user.ID,
@@ -177,6 +186,7 @@ func (h *AgentHandler) ListAgents(c *gin.Context) {
desc,
ownerIDs,
canvasCategory,
tags,
)
if err != nil {
c.JSON(http.StatusOK, gin.H{
@@ -682,16 +692,23 @@ func (h *AgentHandler) Prompts(c *gin.Context) {
})
}
// ListAgentTags GET /api/v1/agents/tags — out of scope (no test depends on
// it); return 501 to keep the surface honest.
// ListAgentTags list agent tags.
func (h *AgentHandler) ListAgentTags(c *gin.Context) {
if _, code, msg := GetUser(c); code != common.CodeSuccess {
user, code, msg := GetUser(c)
if code != common.CodeSuccess {
jsonError(c, code, msg)
return
}
rows, errCode, err := h.agentService.ListAgentTags(user.ID, strings.TrimSpace(c.Query("canvas_category")))
if err != nil {
jsonError(c, errCode, err.Error())
return
}
c.JSON(http.StatusOK, gin.H{
"code": common.CodeSuccess,
"data": []string{},
"data": rows,
"message": "success",
})
}

View File

@@ -320,7 +320,7 @@ type fakeAgentService struct {
// agentServiceIface is the minimum interface the handler depends on.
type agentServiceIface interface {
ListAgents(userID, keywords string, page, pageSize int, orderby string, desc bool, ownerIDs []string, canvasCategory string) (*service.ListAgentsResponse, common.ErrorCode, error)
ListAgents(userID, keywords string, page, pageSize int, orderby string, desc bool, ownerIDs []string, canvasCategory string, tags []string) (*service.ListAgentsResponse, common.ErrorCode, error)
ListTemplates() ([]*entity.CanvasTemplate, error)
}
@@ -335,7 +335,7 @@ func (h *agentHandlerTestable) listAgents(c *gin.Context) {
jsonError(c, errorCode, errorMessage)
return
}
result, code, err := h.svc.ListAgents(user.ID, "", 0, 0, "create_time", true, nil, "")
result, code, err := h.svc.ListAgents(user.ID, "", 0, 0, "create_time", true, nil, "", nil)
if err != nil {
c.JSON(http.StatusOK, gin.H{"code": code, "data": false, "message": err.Error()})
return
@@ -359,7 +359,7 @@ func (h *agentHandlerTestable) listTemplates(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"code": common.CodeSuccess, "data": templates, "message": "success"})
}
func (f *fakeAgentService) ListAgents(userID, keywords string, page, pageSize int, orderby string, desc bool, ownerIDs []string, canvasCategory string) (*service.ListAgentsResponse, common.ErrorCode, error) {
func (f *fakeAgentService) ListAgents(userID, keywords string, page, pageSize int, orderby string, desc bool, ownerIDs []string, canvasCategory string, tags []string) (*service.ListAgentsResponse, common.ErrorCode, error) {
return f.result, f.code, f.err
}
@@ -429,7 +429,7 @@ type fullFakeAgentService struct {
versions []*entity.UserCanvasVersion
}
func (f *fullFakeAgentService) ListAgents(string, string, int, int, string, bool, []string, string) (*service.ListAgentsResponse, common.ErrorCode, error) {
func (f *fullFakeAgentService) ListAgents(string, string, int, int, string, bool, []string, string, []string) (*service.ListAgentsResponse, common.ErrorCode, error) {
return &service.ListAgentsResponse{}, common.CodeSuccess, nil
}
func (f *fullFakeAgentService) CreateAgent(context.Context, *service.CreateAgentRequest) (*entity.UserCanvas, common.ErrorCode, error) {

View File

@@ -75,7 +75,7 @@ func newWaitFakeAgentService(stub func(call int, root map[string]any) (*runtime.
}
}
func (f *waitFakeAgentService) ListAgents(string, string, int, int, string, bool, []string, string) (*service.ListAgentsResponse, common.ErrorCode, error) {
func (f *waitFakeAgentService) ListAgents(string, string, int, int, string, bool, []string, string, []string) (*service.ListAgentsResponse, common.ErrorCode, error) {
return &service.ListAgentsResponse{}, common.CodeSuccess, nil
}
func (f *waitFakeAgentService) CreateAgent(context.Context, *service.CreateAgentRequest) (*entity.UserCanvas, common.ErrorCode, error) {