Refactor AI Agent configuration and workflow handling

- Removed runtime mode handling from AIAgentConfigWorkbench and related components.
- Updated tests to reflect changes in AI Agent policy copy and configuration.
- Changed terminology from "workflow" to "revision" in various components and API responses.
- Simplified agent binding logic in channel editing.
- Cleaned up unused variables and types related to runtime modes.
- Updated localization files for consistency with new terminology.
This commit is contained in:
mlogclub
2026-07-27 23:29:02 +08:00
parent 241f274927
commit 847f688398
97 changed files with 1666 additions and 5941 deletions
@@ -24,7 +24,6 @@ func AgentRunAnyList(ctx *gin.Context) {
params.QueryFilter{ParamName: "agentRevisionId"},
params.QueryFilter{ParamName: "sourceMessageId"},
params.QueryFilter{ParamName: "workflowRunId"},
params.QueryFilter{ParamName: "engineCode"},
params.QueryFilter{ParamName: "status"},
).Desc("id")
list, paging := services.AgentRunService.FindPageByParams(queryParams)
@@ -75,15 +74,6 @@ func AgentRunAnyMetrics(ctx *gin.Context) {
httpx.WriteJSON(ctx, services.AgentRunService.GetMetrics(aiAgentID))
}
func AgentRunAnyComparison(ctx *gin.Context) {
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionAIAgentView); err != nil {
httpx.WriteJSON(ctx, err)
return
}
aiAgentID, _ := params.GetInt64(ctx, "aiAgentId")
httpx.WriteJSON(ctx, services.AgentRunService.GetEngineComparisons(aiAgentID))
}
func AgentRunPostEvaluate(ctx *gin.Context) {
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionAIAgentView); err != nil {
httpx.WriteJSON(ctx, err)
@@ -237,10 +237,6 @@ func buildAIAgentResponse(item *models.AIAgent) response.AIAgentResponse {
}
func buildAIAgentResponseWithLocale(item *models.AIAgent, locale string) response.AIAgentResponse {
runtimeMode := item.RuntimeMode
if runtimeMode == "" {
runtimeMode = enums.AIAgentRuntimeModeWorkflow
}
ret := response.AIAgentResponse{
ID: item.ID,
Name: item.Name,
@@ -248,8 +244,6 @@ func buildAIAgentResponseWithLocale(item *models.AIAgent, locale string) respons
Status: item.Status,
StatusName: enums.GetStatusLabel(item.Status),
AIConfigID: item.AIConfigID,
RuntimeMode: runtimeMode,
RuntimeModeName: enums.GetAIAgentRuntimeModeLabel(runtimeMode),
MaxSteps: item.MaxSteps,
ContextWindow: item.ContextWindow,
ToolPolicy: item.ToolPolicy,
@@ -272,11 +266,7 @@ func buildAIAgentResponseWithLocale(item *models.AIAgent, locale string) respons
Teams: make([]response.AIAgentTeamResponse, 0),
MCPTools: make([]response.AIAgentMCPToolResponse, 0),
WorkflowBindings: make([]response.AIAgentWorkflowBindingResponse, 0),
WorkflowVersionID: item.WorkflowVersionID,
PublishedRevisionID: item.PublishedRevisionID,
WorkflowPublished: item.WorkflowVersionID > 0,
WorkflowState: aiAgentWorkflowState(item.WorkflowVersionID),
WorkflowStateText: aiAgentWorkflowStateText(item.WorkflowVersionID),
SortNo: item.SortNo,
CreatedAt: item.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: item.UpdatedAt.Format("2006-01-02 15:04:05"),
@@ -336,12 +326,14 @@ func buildAIAgentResponseWithLocale(item *models.AIAgent, locale string) respons
}
}
ret.MCPTools = append(ret.MCPTools, response.AIAgentMCPToolResponse{
ToolCode: toolCode,
ServerCode: serverCode,
ToolName: toolName,
Title: title,
Description: description,
Arguments: tool.Arguments,
ToolCode: toolCode,
ServerCode: serverCode,
ToolName: toolName,
Title: title,
Description: description,
RiskLevel: tool.RiskLevel,
RequireConfirmation: tool.RequireConfirmation,
Arguments: tool.Arguments,
})
}
}
@@ -358,17 +350,3 @@ func buildAIAgentResponseWithLocale(item *models.AIAgent, locale string) respons
}
return ret
}
func aiAgentWorkflowState(workflowVersionID int64) string {
if workflowVersionID > 0 {
return "published"
}
return "draft"
}
func aiAgentWorkflowStateText(workflowVersionID int64) string {
if workflowVersionID > 0 {
return "已发布"
}
return "未发布"
}
@@ -4,39 +4,18 @@ import (
"testing"
"agent-desk/internal/models"
"agent-desk/internal/pkg/enums"
"github.com/glebarez/sqlite"
"github.com/mlogclub/simple/sqls"
"gorm.io/gorm"
)
func TestBuildAIAgentResponseExposesWorkflowPublishState(t *testing.T) {
func TestBuildAIAgentResponseExposesPublishedRevision(t *testing.T) {
setupAIAgentHandlerTestDB(t)
draft := buildAIAgentResponse(&models.AIAgent{})
if draft.RuntimeMode != enums.AIAgentRuntimeModeWorkflow {
t.Fatalf("draft.RuntimeMode = %q, want %q", draft.RuntimeMode, enums.AIAgentRuntimeModeWorkflow)
}
if draft.WorkflowPublished {
t.Fatalf("draft.WorkflowPublished = true, want false")
}
if draft.WorkflowState != "draft" {
t.Fatalf("draft.WorkflowState = %q, want draft", draft.WorkflowState)
}
if draft.WorkflowStateText == "" {
t.Fatalf("expected draft workflow state text")
}
published := buildAIAgentResponse(&models.AIAgent{WorkflowVersionID: 12})
if !published.WorkflowPublished {
t.Fatalf("published.WorkflowPublished = false, want true")
}
if published.WorkflowState != "published" {
t.Fatalf("published.WorkflowState = %q, want published", published.WorkflowState)
}
if published.WorkflowStateText == "" {
t.Fatalf("expected published workflow state text")
published := buildAIAgentResponse(&models.AIAgent{PublishedRevisionID: 12})
if published.PublishedRevisionID != 12 {
t.Fatalf("published revision = %d, want 12", published.PublishedRevisionID)
}
rollout := buildAIAgentResponse(&models.AIAgent{RolloutPercent: 20, PreviousRolloutPercent: 100})
@@ -158,7 +158,7 @@ func AIWorkflowGetTemplateList(ctx *gin.Context) {
httpx.WriteJSON(ctx, err)
return
}
httpx.WriteJSON(ctx, builders.BuildAIWorkflowTemplates(services.AIWorkflowService.ListPlaybookTemplates()))
httpx.WriteJSON(ctx, builders.BuildAIWorkflowTemplates(services.AIWorkflowService.ListWorkflowTemplates()))
}
func AIWorkflowPostValidate(ctx *gin.Context) {