feat: 新增主动拉取与多类型回调功能

- 新增 ActivePull 实体、DAO、DTO 及 Service,支持主动拉取任务管理
- 新增 ComposeCallback、VideoCallback、HttpNodeCallback 多类型回调接口
- FlowExecution 增加 NodeGroupId 和 TotalTokens 字段,支持节点组追踪与 Token 统计
- ExecutedNodes 结构由字符串列表改为包含执行状态的节点对象列表
- 重构回调通知机制,统一 Notify 函数调用
- 优化输出项类型判断逻辑,新增文件类型标识
This commit is contained in:
2026-06-10 14:23:55 +08:00
parent ab3a2d967e
commit 03c95c3601
33 changed files with 3207 additions and 615 deletions

View File

@@ -2,6 +2,7 @@ package flow
import (
"ai-agent/workflow/consts/flow"
"ai-agent/workflow/consts/node"
"ai-agent/workflow/model/entity"
"gitea.com/red-future/common/beans"
@@ -11,12 +12,20 @@ import (
// NodeExecutionInput 节点执行入参(包含配置+表单架构)
type NodeExecutionInput struct {
Config *entity.FlowNode // 节点配置
Global *FlowExecutionInput `json:"-"`
Config *entity.FlowNode `json:"config"` // 节点配置
Global *FlowExecutionInput `json:"global"`
NodeExecutionId int64 `json:"nodeExecutionId"`
}
// ExecutedNode 已执行节点记录包含节点ID和执行状态
type ExecutedNode struct {
NodeId string `json:"nodeId"`
Status node.NodeExecutionStatus `json:"status"` // 执行状态:成功/失败
}
// FlowExecutionInput 工作流执行入参(全程不变)
type FlowExecutionInput struct {
NodeGroupId string `json:"nodeGroupId"`
IsDialogue bool `json:"isDialogue"`
ExecutionId int64 `json:"executionId"`
ConfigMap map[string]*entity.FlowNode `json:"configMap"`
@@ -24,27 +33,74 @@ type FlowExecutionInput struct {
Desc string `json:"desc"`
SkillName string `json:"skillName"`
FileUrl []string `json:"fileUrl"`
ExecutedNodes []string `json:"executedNodes"`
ExecutedNodes []ExecutedNode `json:"executedNodes"` // 已执行节点列表,包含执行状态
}
type GetIsChatModelRes struct {
Model struct {
ModelName string `json:"modelName"`
ResponseBody map[string]any `json:"responseBody"`
}
}
type GetModelInfoReq struct {
ModelName string `json:"modelName"`
}
type GetModelInfoRes struct {
Model struct {
LastFrame string `json:"lastFrame"`
ResponseTokenField string `json:"responseTokenField"`
ResponseMapping map[string]any `json:"responseMapping"`
ResponseBody string `json:"responseBody"`
//QueryConfig struct {
// ResponseType string `json:"responseType"`
// CallbackUrl string `json:"callbackUrl"`
// Method string `json:"method"`
// Url string `json:"url"`
// Headers map[string]any `json:"headers"`
// Body map[string]any `json:"body"`
// Response []map[string]any `json:"response"`
// ResponseBody string `json:"responseBody"`
// ResponseTokenField string `json:"responseTokenField"`
//} `json:"queryConfig"`
} `json:"model"`
}
type ComposeMessagesReq struct {
BuildType int `json:"buildType"`
ModelName string `json:"modelName"`
SkillName string `json:"skillName"`
Form map[string]any `json:"form"`
UserForm map[string]any `json:"userForm"`
UserFiles []string `json:"userFiles"`
SessionId string `json:"sessionId" dc:"会话ID"`
IsBuild bool `json:"isBuild"`
Cause string `json:"cause"`
BuildType int `json:"buildType"`
ModelName string `json:"modelName"`
SkillName string `json:"skillName"`
CallbackUrl string `json:"callbackUrl"`
Form []map[string]any `json:"form"`
UserForm []map[string]any `json:"userForm"`
Consult []Consult `json:"consult"`
SessionId string `json:"sessionId" dc:"会话ID"`
NodeId string `json:"nodeId"`
Cause string `json:"cause"`
}
type Consult struct {
Type string `json:"type"`
Url string `json:"url"`
}
type ComposeMessagesRes struct {
Messages map[string]any `json:"messages"`
EpicycleId int64 `json:"epicycleId" dc:"轮次ID"`
TaskId string `json:"taskId"`
}
type CreateTaskReq struct {
type VideoConcatReq struct {
VideoUrls []string `json:"video_urls"`
Method string `json:"method"`
Upload bool `json:"upload"`
CallbackUrl string `json:"callback_url"`
}
type VideoConcatRes struct {
TaskId string `json:"taskId"`
}
type ModelGatewayReq struct {
ModelName string `json:"modelName"`
ModelKey string `json:"modelKey"`
BizName string `json:"bizName"`
@@ -54,83 +110,74 @@ type CreateTaskReq struct {
EpicycleId int64 `json:"epicycleId" dc:"轮次ID"`
}
type CreateTaskRes struct {
type ModelGatewayRes struct {
TaskId string `json:"taskId"`
}
type GetIsChatModelRes struct {
ModelName string `json:"modelName"`
ResponseBody map[string]any `json:"responseBody"`
type ComposeCallbackReq struct {
g.Meta `path:"/composeCallBack" method:"post" tags:"提示词处理" summary:"提示词 回调" dc:"提示词 成功后 GET 回调callbackUrl/{bizName}"`
TaskId string `json:"taskId"`
Status string `json:"status"`
Messages struct {
TotalRounds int `json:"total_rounds"` // 总轮数
Rounds []map[string]any `json:"rounds"` // 每轮详情(动态类型)
} `json:"messages,omitempty"`
EpicycleId int64 `json:"epicycleId"`
ErrorMsg string `json:"errorMsg,omitempty"`
}
type ModelCallbackReq struct {
g.Meta `path:"/modelCallback" method:"post" tags:"提示词处理" summary:"model-gateway 回调" dc:"model-gateway 成功后 GET 回调callbackUrl/{bizName}"`
TaskId string `p:"task_id" json:"task_id" v:"required#task_id不能为空" dc:"网关任务ID"`
State int `p:"state" json:"state" dc:"网关任务状态"`
OssFile string `p:"oss_file" json:"oss_file" dc:"结果文件地址"`
FileType string `p:"file_type" json:"file_type" dc:"结果文件类型"`
Text string `p:"text" json:"text" dc:"文本结果(可选,最多约 2000 字符)"`
TaskId string `p:"task_id" json:"task_id" v:"required#task_id不能为空" dc:"网关任务ID"`
State int `p:"state" json:"state" dc:"网关任务状态"`
OssFile string `p:"oss_file" json:"oss_file" dc:"结果文件地址"`
FileType string `p:"file_type" json:"file_type" dc:"结果文件类型"`
Messages map[string]any `json:"messages"`
ErrorMsg string `json:"error_msg"`
}
type TaskCallback struct {
TaskID string `json:"taskId"`
State int `json:"state"` // 0排队中/1执行中/2成功/3失败/4已下载
OssFile string `json:"ossFile"`
FileType string `json:"fileType"`
Text string `json:"text"`
//ImgContent *Image `json:"imgContent"`
}
type Text struct {
Choices []struct {
FinishReason string `json:"finish_reason"`
Index int `json:"index"`
Message struct {
Content string `json:"content"`
Role string `json:"role"`
} `json:"message"`
} `json:"choices"`
Created int `json:"created"`
Id string `json:"id"`
Model string `json:"model"`
Object string `json:"object"`
Usage struct {
CompletionTokens int `json:"completion_tokens"`
PromptTokens int `json:"prompt_tokens"`
PromptTokensDetails struct {
CachedTokens int `json:"cached_tokens"`
}
TotalTokens int `json:"total_tokens"`
} `json:"usage"`
}
type Image struct {
Output struct {
Choices []struct {
FinishReason string `json:"finish_reason"`
Message struct {
Content []struct {
Image string `json:"image"`
} `json:"content"`
Role string `json:"role"`
} `json:"message"`
} `json:"choices"`
} `json:"output"`
Usage struct {
Height int `json:"height"`
ImageCount int `json:"image_count"`
Width int `json:"width"`
} `json:"usage"`
RequestId string `json:"request_id"`
type VideoCallbackReq struct {
g.Meta `path:"/videoCallback" method:"post" tags:"视频处理" summary:"media 回调" dc:"media 成功后 GET 回调callbackUrl/{bizName}"`
TaskId string `json:"taskId"`
FileURL string `json:"fileUrl"`
}
//=============================================================================
// 原始入参结构体
type Word struct {
Confidence float64 `json:"confidence"`
StartTime float64 `json:"startTime"`
EndTime float64 `json:"endTime"`
Word string `json:"word"`
}
type Sentence struct {
EndTime float64 `json:"endTime"`
StartTime float64 `json:"startTime"`
Text string `json:"text"`
Words []Word `json:"words"`
}
type InputData struct {
Data struct {
Sentences []Sentence `json:"sentences"`
} `json:"data"`
}
// 输出目标结构体对应截图subtitles格式
type Subtitle struct {
Start float64 `json:"start"`
End float64 `json:"end"`
Text string `json:"text"`
}
//==============================================================================
type ExecuteReq struct {
g.Meta `path:"/execute" method:"post" tags:"任务管理" summary:"执行任务" dc:"执行任务"`
FlowId int64 `json:"flowId" dc:"用户流程ID"`
FlowName string `json:"flowName"`
NodeGroupId string `json:"nodeGroupId"`
FlowContent *entity.FlowInfo `json:"flowContent" description:"流程内容"`
NodeInputParams []*entity.FlowNode `json:"nodeInputParams" description:"节点输入参数"`
SessionId string `json:"sessionId" dc:"会话ID"`
@@ -153,6 +200,7 @@ type CancelReq struct {
type CreateFlowExecutionReq struct {
FlowUserId int64 `json:"flowUserId" description:"流程ID"`
FlowName string `json:"flowName"`
NodeGroupId string `json:"nodeGroupId"`
TriggerType flow.FlowExecutionTriggerType `json:"triggerType" description:"触发类型"`
DurationMs int64 `json:"durationMs" description:"执行时长(毫秒)"`
Status flow.FlowExecutionStatus `json:"status" description:"状态:1-运行中,2-成功,3-失败"`
@@ -170,6 +218,7 @@ type CreateFlowExecutionRes struct {
type UpdateFlowExecutionReq struct {
Id int64 `json:"id" v:"required#ID不能为空"`
NodeGroupId string `json:"nodeGroupId"`
DurationMs int64 `json:"durationMs" description:"执行时长(毫秒)"`
Status flow.FlowExecutionStatus `json:"status" description:"状态:1-运行中,2-成功,3-失败"`
OutputParams []map[string]interface{} `json:"outputParams" description:"输出参数"`
@@ -219,6 +268,7 @@ type VOFlowExecution struct {
type OutputItem struct {
Timestamp string `json:"timestamp" description:"时间戳key"`
Content string `json:"content" description:"内容值"`
Type string `json:"type" description:"类型"`
Label string `json:"label" description:"后缀+数字标号"`
}
type FlowNode struct {
@@ -232,7 +282,6 @@ type DateNode struct {
Flows []FlowNode `json:"flows" description:"流程列表"`
}
// 最终树结构返回体
type ListFlowExecutionTreeRes struct {
Tree []DateNode `json:"tree"`
ImgAddressPrefix string `json:"imgAddressPrefix"`

View File

@@ -0,0 +1,68 @@
package node
import (
"ai-agent/workflow/consts/node"
flowDto "ai-agent/workflow/model/dto/flow"
"ai-agent/workflow/model/entity"
"gitea.com/red-future/common/beans"
"github.com/gogf/gf/v2/frame/g"
)
// CreateNodeExecutionReq 创建节点执行记录请求
type CreateNodeExecutionReq struct {
g.Meta `path:"/create" method:"post" tags:"节点执行记录" summary:"创建节点执行记录" dc:"创建节点执行记录"`
FlowExecutionId int64 `json:"flowExecutionId" v:"required#流程执行ID不能为空"`
NodeId string `json:"nodeId" v:"required#节点ID不能为空"`
NodeName string `json:"nodeName"`
NodeGroupId string `json:"nodeGroupId"`
Status node.NodeExecutionStatus `json:"status"`
InputParams *flowDto.NodeExecutionInput `json:"inputParams"`
}
type CreateNodeExecutionRes struct {
Id int64 `json:"id,string"`
}
// UpdateNodeExecutionReq 更新节点执行记录请求
type UpdateNodeExecutionReq struct {
g.Meta `path:"/update" method:"put" tags:"节点执行记录" summary:"更新节点执行记录" dc:"更新节点执行记录状态和结果"`
Id int64 `json:"id" v:"required#ID不能为空"`
InputParams *flowDto.NodeExecutionInput `json:"inputParams"`
PromptTokens int `json:"promptTokens"`
CompletionTokens int `json:"completionTokens"`
TotalTokens int `json:"totalTokens"`
Status node.NodeExecutionStatus `json:"status"`
DurationMs int64 `json:"durationMs"`
ErrorMessage string `json:"errorMessage"`
}
// DeleteNodeExecutionReq 删除节点执行记录请求
type DeleteNodeExecutionReq struct {
g.Meta `path:"/delete" method:"delete" tags:"节点执行记录" summary:"删除节点执行记录" dc:"删除节点执行记录"`
Id int64 `json:"id" v:"required#ID不能为空"`
}
// GetNodeExecutionReq 根据ID查询节点执行记录请求
type GetNodeExecutionReq struct {
g.Meta `path:"/get" method:"get" tags:"节点执行记录" summary:"查询节点执行记录详情" dc:"根据ID查询节点执行记录详情"`
Id int64 `json:"id" v:"required#ID不能为空"`
}
// ListNodeExecutionByFlowReq 查询流程下所有节点执行记录请求
type ListNodeExecutionByFlowReq struct {
g.Meta `path:"/listByFlow" method:"get" tags:"节点执行记录" summary:"查询流程节点执行列表" dc:"查询指定流程执行下的所有节点执行记录"`
Page *beans.Page `json:"page"`
FlowExecutionId int64 `json:"flowExecutionId" v:"required#流程执行ID不能为空"`
}
// NodeExecutionResp 节点执行记录响应
type NodeExecutionResp struct {
*entity.NodeExecution
}
// ListNodeExecutionResp 节点执行记录列表响应
type ListNodeExecutionResp struct {
List []*entity.NodeExecution `json:"list"`
Total int `json:"total"`
}

View File

@@ -27,3 +27,7 @@ type ModelItem struct {
Name string `json:"name"`
Form []node.NodeFormField `json:"form"`
}
type ModelTypeResponse struct {
Type map[int]string `json:"type"` // key 自动解析为整数 100/200/300...
}

View File

@@ -0,0 +1,70 @@
package node
import (
"ai-agent/workflow/consts/node"
"ai-agent/workflow/model/entity"
"gitea.com/red-future/common/beans"
"github.com/gogf/gf/v2/frame/g"
)
// CreateNodePromptReq 创建节点提示词请求
type CreateNodePromptReq struct {
g.Meta `path:"/create" method:"post" tags:"节点提示词管理" summary:"创建节点提示词" dc:"创建用户自定义节点提示词"`
NodeType node.NodeType `json:"nodeType" v:"required#节点类型不能为空"`
Prompt string `json:"prompt" v:"required#提示词不能为空"`
SourceType node.SourceType `json:"sourceType"`
}
type CreateNodePromptRes struct {
Id int64 `json:"id,string"`
}
// UpdateNodePromptReq 更新节点提示词请求
type UpdateNodePromptReq struct {
g.Meta `path:"/update" method:"put" tags:"节点提示词管理" summary:"更新节点提示词" dc:"更新用户自定义节点提示词"`
Id int64 `json:"id" v:"required#ID不能为空"`
NodeType node.NodeType `json:"nodeType"`
Prompt string `json:"prompt"`
}
// DeleteNodePromptReq 删除节点提示词请求
type DeleteNodePromptReq struct {
g.Meta `path:"/delete" method:"delete" tags:"节点提示词管理" summary:"删除节点提示词" dc:"删除用户自定义节点提示词"`
Id int64 `json:"id" v:"required#ID不能为空"`
}
// GetNodePromptReq 根据ID查询节点提示词请求
type GetNodePromptReq struct {
g.Meta `path:"/get" method:"get" tags:"节点提示词管理" summary:"查询节点提示词详情" dc:"根据ID查询节点提示词详情"`
Id int64 `json:"id"`
Prompt string `json:"prompt"`
Creator string `json:"creator"`
}
// ListNodePromptReq 查询节点提示词列表请求
type ListNodePromptReq struct {
g.Meta `path:"/list" method:"get" tags:"节点提示词管理" summary:"查询节点提示词列表" dc:"查询当前创建人的节点提示词,包含系统和用户自定义"`
Page *beans.Page `json:"page"`
Creator string `json:"creator"`
NodeType node.NodeType `json:"nodeType"`
}
// ListMyNodePromptReq 查询当前用户节点提示词列表请求
type ListMyNodePromptReq struct {
g.Meta `path:"/listMy" method:"get" tags:"节点提示词管理" summary:"查询当前用户节点提示词列表" dc:"查询当前创建人自己创建的节点提示词列表"`
Page *beans.Page `json:"page"`
NodeType node.NodeType `json:"nodeType"`
Creator string `json:"creator"`
}
// NodePromptResp 节点提示词响应
type NodePromptResp struct {
*entity.NodePrompt
}
// ListNodePromptResp 节点提示词列表响应
type ListNodePromptResp struct {
List []*entity.NodePrompt `json:"list"`
Total int `json:"total"`
}

View File

@@ -0,0 +1,54 @@
package pull
import (
"ai-agent/workflow/consts/flow"
"ai-agent/workflow/model/entity"
"gitea.com/red-future/common/beans"
"github.com/gogf/gf/v2/os/gtime"
)
type CreateActivePullReq struct {
Type string `json:"type"`
RequestParament map[string]any `json:"requestParament"`
ResponseParament map[string]any `json:"responseParament"`
Extension map[string]any `json:"extension"`
}
type CreateActivePullRes struct {
Id int64 `json:"id,string"`
}
type UpdateActivePullReq struct {
Id int64 `json:"id" v:"required#ID不能为空"`
Type string `json:"type"`
RequestParament map[string]any `json:"requestParament"`
ResponseParament map[string]any `json:"responseParament"`
Extension map[string]any `json:"extension"`
}
type DeleteActivePullReq struct {
Id int64 `json:"id" v:"required#ID不能为空"`
}
type ListActivePullReq struct {
Page *beans.Page `json:"page"`
Type string `json:"type"`
}
type ListActivePullRes struct {
List []*ActivePullVO `json:"list"`
Total int `json:"total"`
}
type ActivePullVO struct {
Id int64 `json:"id,string" dc:"id"`
FlowName string `json:"flowName" description:"流程名称"`
Description string `json:"description" description:"流程描述"`
FlowContent *entity.FlowInfo `json:"flowContent" description:"流程内容"`
NodeInputParams []*entity.FlowNode `json:"nodeInputParams" description:"节点输入参数"`
AccessLevel flow.FlowUserAccessLevel `json:"accessLevel" description:"访问权限1私有2团队3公开"`
SourceFlowTemplateId int64 `json:"sourceFlowTemplateId,string" description:"来源流程模板ID"`
CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"`
UpdatedAt *gtime.Time `json:"updatedAt" dc:"更新时间"`
}