- 新增计费模块:执行开始建单、终态结算/取消/失败处理,支持按条/按秒/按token计费 - 新增执行生命周期跟踪:优雅关停时取消运行中执行并等待落库 - 新增异步任务等待/通知机制(Wait/Notify) - 重构执行记录落库与进度上报,统一失败分类与重试语义 - 重命名文件:async_task.go→async.go、flow_checkpoint_store.go→exec_checkpoint.go、flow_graph_util.go→exec_record.go - 更新 .gitignore 与数据库密码配置
102 lines
4.6 KiB
Go
102 lines
4.6 KiB
Go
package session
|
||
|
||
import (
|
||
"ai-agent/workflow/model/entity"
|
||
|
||
"gitea.redpowerfuture.com/red-future/common/beans"
|
||
"github.com/gogf/gf/v2/frame/g"
|
||
"github.com/gogf/gf/v2/os/gtime"
|
||
)
|
||
|
||
// WebSocketConnectReq WebSocket 连接请求(query string 参数)
|
||
type WebSocketConnectReq struct {
|
||
g.Meta `path:"/wsExecute" method:"get" tags:"工作流执行" summary:"WebSocket执行工作流" dc:"通过WebSocket连接实时执行工作流,支持进度推送和取消"`
|
||
SessionId string `p:"sessionId" dc:"会话ID"`
|
||
}
|
||
|
||
type WebSocketExecChatReq struct {
|
||
Id int64 `json:"id" dc:"id"`
|
||
ModelId int64 `json:"modelId" dc:"模型ID" v:"required#模型ID不能为空"`
|
||
Question string `json:"question" dc:"用户提问" v:"required#用户提问不能为空"`
|
||
SystemPrompt string `json:"systemPrompt" dc:"系统提示词"`
|
||
}
|
||
|
||
type WebSocketExecWorkflowReq struct {
|
||
FlowId int64 `json:"flowId" dc:"用户流程ID" v:"required#用户流程ID不能为空"`
|
||
FlowContent *entity.FlowInfo `json:"flowContent" dc:"用户流程内容" v:"required#用户流程内容不能为空"`
|
||
}
|
||
|
||
type CreateSessionReq struct {
|
||
SessionId string `json:"sessionId" dc:"会话ID"`
|
||
SessionName string `json:"sessionName" dc:"会话名称"`
|
||
}
|
||
|
||
type ListSessionReq struct {
|
||
g.Meta `path:"/list" method:"get" tags:"会话管理" summary:"会话列表" dc:"会话列表"`
|
||
PageNum int64 `json:"pageNum" dc:"页码,从1开始"`
|
||
PageSize int64 `json:"pageSize" dc:"每页数量"`
|
||
}
|
||
|
||
type ListSessionRes struct {
|
||
List []*VOSession `json:"list"`
|
||
Total int `json:"total"`
|
||
}
|
||
|
||
type VOSession struct {
|
||
SessionId string `json:"sessionId" dc:"会话ID"`
|
||
SessionName string `json:"sessionName" dc:"会话名称"`
|
||
CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"`
|
||
}
|
||
|
||
type DeleteSessionReq struct {
|
||
g.Meta `path:"/delete" method:"delete" tags:"会话管理" summary:"删除会话" dc:"删除会话"`
|
||
SessionId string `json:"sessionId" v:"required#会话ID不能为空"`
|
||
}
|
||
|
||
type DeleteSessionRecordReq struct {
|
||
g.Meta `path:"/deleteRecord" method:"post" tags:"会话管理" summary:"删除会话记录" dc:"删除会话记录"`
|
||
Ids []struct {
|
||
Id int64 `json:"id" v:"required#ID不能为空"`
|
||
Type string `json:"type" v:"required#类型不能为空"`
|
||
}
|
||
}
|
||
|
||
type GetSessionInfoReq struct {
|
||
g.Meta `path:"/get" method:"get" tags:"会话管理" summary:"会话内结果列表" dc:"会话内结果列表,工作流+普通对话混排按时间倒序"`
|
||
PageNum int64 `json:"pageNum" dc:"页码,从1开始"`
|
||
PageSize int64 `json:"pageSize" dc:"每页数量"`
|
||
SessionId string `json:"sessionId" v:"required#会话ID不能为空"`
|
||
}
|
||
|
||
type GetSessionInfoRes struct {
|
||
List []*VOSessionInfoResult `json:"list"`
|
||
Total int `json:"total"`
|
||
}
|
||
|
||
// VOSessionInfoResult 会话内单条结果(工作流/普通对话混排)
|
||
type VOSessionInfoResult struct {
|
||
Id int64 `json:"id,string" dc:"结果ID"`
|
||
Type string `json:"type" dc:"workflow-工作流结果,chat-普通对话结果"`
|
||
Status int `json:"status" dc:"1-运行中,2-成功,3-失败"`
|
||
FlowId int64 `json:"flowId,string" dc:"工作流ID(chat类型为空)"`
|
||
RequestParams map[string]any `json:"requestParams" description:"请求参数"`
|
||
ResultFileUrl string `json:"resultFileUrl" description:"结果文件路径(供预览/下载)"`
|
||
ResultContent string `json:"resultContent" description:"结果文件内容(服务端已读取,前端直接展示)"`
|
||
TotalTokens int `json:"totalTokens" dc:"总token消耗"`
|
||
TotalFee float64 `json:"totalFee" dc:"模型扣费合计(各模型按次费用)"`
|
||
ActualAmount float64 `json:"actualAmount" dc:"业务扣费(用户钱包实际扣除,元)"`
|
||
ErrorMsg string `json:"errorMsg" dc:"错误信息(友好提示)"`
|
||
Error string `json:"error" dc:"错误明细(原始错误)"`
|
||
CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"`
|
||
}
|
||
|
||
type ListWorkflowResultReq struct {
|
||
g.Meta `path:"/resultList" method:"get" tags:"会话管理" summary:"工作流执行结果树" dc:"按创建人分页查询工作流执行结果,按天分组返回树结构(日期→流程→结果文件),pageSize=每页天数,不传返回全部"`
|
||
Page *beans.Page `json:"page"`
|
||
}
|
||
|
||
type DeleteWorkflowResultReq struct {
|
||
g.Meta `path:"/resultDelete" method:"delete" tags:"会话管理" summary:"删除工作流执行结果" dc:"删除工作流执行结果"`
|
||
Id int64 `json:"id" v:"required#ID不能为空"`
|
||
}
|