feat: 新增主动拉取与多类型回调功能
- 新增 ActivePull 实体、DAO、DTO 及 Service,支持主动拉取任务管理 - 新增 ComposeCallback、VideoCallback、HttpNodeCallback 多类型回调接口 - FlowExecution 增加 NodeGroupId 和 TotalTokens 字段,支持节点组追踪与 Token 统计 - ExecutedNodes 结构由字符串列表改为包含执行状态的节点对象列表 - 重构回调通知机制,统一 Notify 函数调用 - 优化输出项类型判断逻辑,新增文件类型标识
This commit is contained in:
101
workflow/service/active_pull/active_pull_service.go
Normal file
101
workflow/service/active_pull/active_pull_service.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package pull
|
||||
|
||||
import (
|
||||
pullDao "ai-agent/workflow/dao/pull"
|
||||
pullDto "ai-agent/workflow/model/dto/pull"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var ActivePullService = &activePullService{}
|
||||
|
||||
type activePullService struct{}
|
||||
|
||||
func (s *activePullService) Create(ctx context.Context, req *pullDto.CreateActivePullReq) (res *pullDto.CreateActivePullRes, err error) {
|
||||
id, err := pullDao.ActivePullDao.Insert(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return &pullDto.CreateActivePullRes{Id: id}, nil
|
||||
}
|
||||
|
||||
func (s *activePullService) Update(ctx context.Context, req *pullDto.UpdateActivePullReq) (err error) {
|
||||
_, err = pullDao.ActivePullDao.Update(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *activePullService) Delete(ctx context.Context, req *pullDto.DeleteActivePullReq) (err error) {
|
||||
_, err = pullDao.ActivePullDao.Delete(ctx, req)
|
||||
return
|
||||
}
|
||||
|
||||
//func (s *activePullService) AllList(ctx context.Context) (err error) {
|
||||
// ctx = context.WithValue(ctx, "user", &beans.User{
|
||||
// UserName: "admin",
|
||||
// })
|
||||
// for {
|
||||
// select {
|
||||
// case <-ctx.Done():
|
||||
// return ctx.Err()
|
||||
// default:
|
||||
// }
|
||||
//
|
||||
// var list []*entity.ActivePull
|
||||
// list, _, err = pullDao.ActivePullDao.ListNative(ctx, &pullDto.ListActivePullReq{})
|
||||
// if err != nil {
|
||||
// g.Log().Error(ctx, "AllList query failed: %v", err)
|
||||
// time.Sleep(time.Second * 3)
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// // Get all active pull tasks and check each one for results
|
||||
// for _, item := range list {
|
||||
// var result map[string]any
|
||||
// result, err = flow.PullTaskResult(ctx, item.RequestParament, item.Extension)
|
||||
// if err != nil {
|
||||
// g.Log().Error(ctx, "PullTaskResult failed for item %d: %v", item.Id, err)
|
||||
// continue
|
||||
// }
|
||||
// if !g.IsEmpty(result) {
|
||||
// // Find the task ID that matches the creation pattern
|
||||
// // When created in CreateGatewayTask (flow/lambda_node_util.go),
|
||||
// // the last parameter value extracted from the response becomes the waiting task ID
|
||||
// var id string
|
||||
// if taskId, ok := item.RequestParament["task_id"]; ok {
|
||||
// id = gconv.String(taskId)
|
||||
// } else if requestId, ok := item.RequestParament["id"]; ok {
|
||||
// id = gconv.String(requestId)
|
||||
// } else if jobId, ok := item.RequestParament["job_id"]; ok {
|
||||
// id = gconv.String(jobId)
|
||||
// } else {
|
||||
// // Fallback to original behavior: use last value (matches creation logic)
|
||||
// for _, v := range item.RequestParament {
|
||||
// id = gconv.String(v)
|
||||
// }
|
||||
// }
|
||||
// if id != "" {
|
||||
// flow.Notify(id, result)
|
||||
// // Delete after successful notification
|
||||
// _, _ = pullDao.ActivePullDao.Delete(ctx, &pullDto.DeleteActivePullReq{Id: item.Id})
|
||||
// } else {
|
||||
// g.Log().Warning(ctx, "AllList: could not extract task ID for item %d", item.Id)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// time.Sleep(time.Second * 10)
|
||||
// }
|
||||
//}
|
||||
|
||||
func (s *activePullService) List(ctx context.Context, req *pullDto.ListActivePullReq) (res *pullDto.ListActivePullRes, err error) {
|
||||
list, total, err := pullDao.ActivePullDao.List(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res = &pullDto.ListActivePullRes{
|
||||
Total: total,
|
||||
}
|
||||
err = gconv.Struct(list, &res.List)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user