feat: bind AI agents to workflow versions
This commit is contained in:
@@ -108,6 +108,8 @@ func (s *aIAgentService) UpdateAIAgent(req request.UpdateAIAgentRequest, operato
|
||||
"skill_ids": item.SkillIDs,
|
||||
"allowed_mcp_tools": item.AllowedMCPTools,
|
||||
"allowed_graph_tools": item.AllowedGraphTools,
|
||||
"runtime_mode": item.RuntimeMode,
|
||||
"workflow_version_id": item.WorkflowVersionID,
|
||||
"update_user_id": operator.UserID,
|
||||
"update_user_name": operator.Username,
|
||||
"updated_at": time.Now(),
|
||||
@@ -191,6 +193,10 @@ func (s *aIAgentService) buildAIAgentModel(id int64, req request.CreateAIAgentRe
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
runtimeMode, workflowVersionID, err := s.normalizeRuntimeMode(req.RuntimeMode, req.WorkflowVersionID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
directToolsJSON := ""
|
||||
if len(directTools) > 0 {
|
||||
buf, marshalErr := json.Marshal(directTools)
|
||||
@@ -223,6 +229,8 @@ func (s *aIAgentService) buildAIAgentModel(id int64, req request.CreateAIAgentRe
|
||||
SkillIDs: utils.JoinInt64s(skillIDs),
|
||||
AllowedMCPTools: directToolsJSON,
|
||||
AllowedGraphTools: graphToolsJSON,
|
||||
RuntimeMode: runtimeMode,
|
||||
WorkflowVersionID: workflowVersionID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -349,6 +357,26 @@ func (s *aIAgentService) normalizeGraphTools(input []string) ([]string, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (s *aIAgentService) normalizeRuntimeMode(input enums.AIAgentRuntimeMode, workflowVersionID int64) (enums.AIAgentRuntimeMode, int64, error) {
|
||||
if input == 0 {
|
||||
input = enums.AIAgentRuntimeModeBuiltinGraph
|
||||
}
|
||||
if !slices.Contains(enums.AIAgentRuntimeModeValues, input) {
|
||||
return 0, 0, errorsx.InvalidParam("invalid ai agent runtime mode")
|
||||
}
|
||||
if input != enums.AIAgentRuntimeModeWorkflow {
|
||||
return input, 0, nil
|
||||
}
|
||||
if workflowVersionID <= 0 {
|
||||
return 0, 0, errorsx.InvalidParam("workflow version is required")
|
||||
}
|
||||
version := AIWorkflowService.GetVersion(workflowVersionID)
|
||||
if version == nil || version.Status != enums.StatusOk {
|
||||
return 0, 0, errorsx.InvalidParam("workflow version does not exist")
|
||||
}
|
||||
return input, workflowVersionID, nil
|
||||
}
|
||||
|
||||
func (s *aIAgentService) UpdateSort(ids []int64) error {
|
||||
return sqls.WithTransaction(func(ctx *sqls.TxContext) error {
|
||||
for i, id := range ids {
|
||||
|
||||
Reference in New Issue
Block a user