feat(workflow): enhance AI agent workflow state management and response handling
This commit is contained in:
@@ -190,6 +190,9 @@ func buildAIAgentResponseWithLocale(item *models.AIAgent, locale string) respons
|
||||
DirectTools: make([]response.AIAgentMCPToolResponse, 0),
|
||||
GraphTools: make([]string, 0),
|
||||
WorkflowVersionID: item.WorkflowVersionID,
|
||||
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"),
|
||||
@@ -283,6 +286,20 @@ 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 "未发布"
|
||||
}
|
||||
|
||||
func appendGraphToolCodeIfMissing(items []string, toolCode string) []string {
|
||||
toolCode = strings.TrimSpace(toolCode)
|
||||
if toolCode == "" {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"agent-desk/internal/models"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestBuildAIAgentResponseExposesWorkflowPublishState(t *testing.T) {
|
||||
setupAIAgentHandlerTestDB(t)
|
||||
|
||||
draft := buildAIAgentResponse(&models.AIAgent{})
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
func setupAIAgentHandlerTestDB(t *testing.T) {
|
||||
t.Helper()
|
||||
db, err := gorm.Open(sqlite.Open("file:"+t.Name()+"?mode=memory&cache=shared"), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatalf("open sqlite db: %v", err)
|
||||
}
|
||||
sqlDB, err := db.DB()
|
||||
if err != nil {
|
||||
t.Fatalf("get sqlite db: %v", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := sqlDB.Close(); err != nil {
|
||||
t.Fatalf("close sqlite db: %v", err)
|
||||
}
|
||||
})
|
||||
if err := db.AutoMigrate(
|
||||
&models.AIConfig{},
|
||||
&models.AgentTeam{},
|
||||
&models.KnowledgeBase{},
|
||||
&models.SkillDefinition{},
|
||||
); err != nil {
|
||||
t.Fatalf("auto migrate: %v", err)
|
||||
}
|
||||
sqls.SetDB(db)
|
||||
}
|
||||
Reference in New Issue
Block a user