refactor: make AI workflows agent-centric

This commit is contained in:
mlogclub
2026-06-22 10:08:51 +08:00
parent 14f50e064f
commit 32ab43e7c2
18 changed files with 436 additions and 400 deletions
@@ -21,8 +21,7 @@ func AIWorkflowAnyList(ctx *gin.Context) {
cnd := params.NewPagedSqlCnd(ctx,
params.QueryFilter{ParamName: "status"},
params.QueryFilter{ParamName: "name", Op: params.Like},
params.QueryFilter{ParamName: "ownerType"},
params.QueryFilter{ParamName: "ownerId"},
params.QueryFilter{ParamName: "agentId"},
).Desc("id")
list, paging := services.AIWorkflowService.FindPageByCnd(cnd)
httpx.WriteJSON(ctx, &web.PageResult{Results: builders.BuildAIWorkflowList(list), Page: paging})
@@ -144,6 +143,62 @@ func AIWorkflowPostPublish(ctx *gin.Context) {
httpx.WriteJSON(ctx, builders.BuildAIWorkflowVersion(item))
}
func AIWorkflowGetByAgent(ctx *gin.Context) {
agentID, ok := httpx.GetPathInt64(ctx, "id")
if !ok {
return
}
operator, err := services.AuthService.RequirePermission(ctx, constants.PermissionAIAgentView)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
item, err := services.AIWorkflowService.GetOrCreateAgentWorkflow(agentID, operator)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
httpx.WriteJSON(ctx, builders.BuildAIWorkflow(item))
}
func AIWorkflowPostSaveAgent(ctx *gin.Context) {
operator, err := services.AuthService.RequirePermission(ctx, constants.PermissionAIAgentUpdate)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
req := request.SaveAIWorkflowRequest{}
if err := params.ReadJSON(ctx, &req); err != nil {
httpx.WriteJSON(ctx, err)
return
}
item, err := services.AIWorkflowService.SaveAgentWorkflow(req, operator)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
httpx.WriteJSON(ctx, builders.BuildAIWorkflow(item))
}
func AIWorkflowPostPublishAgent(ctx *gin.Context) {
operator, err := services.AuthService.RequirePermission(ctx, constants.PermissionAIAgentUpdate)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
req := request.PublishAIWorkflowRequest{}
if err := params.ReadJSON(ctx, &req); err != nil {
httpx.WriteJSON(ctx, err)
return
}
item, err := services.AIWorkflowService.PublishAgentWorkflow(req, operator)
if err != nil {
httpx.WriteJSON(ctx, err)
return
}
httpx.WriteJSON(ctx, builders.BuildAIWorkflowVersion(item))
}
func AIWorkflowAnyVersionList(ctx *gin.Context) {
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionAIAgentView); err != nil {
httpx.WriteJSON(ctx, err)