Enhance workflow execution with checkpoint data handling and introduce tests for human confirmation and ticket creation
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
applicationruntime "agent-desk/internal/ai/application/runtime"
|
||||
"agent-desk/internal/models"
|
||||
"agent-desk/internal/pkg/toolx"
|
||||
)
|
||||
|
||||
@@ -66,6 +67,22 @@ func TestExtractInterruptMessageAndCheckpointError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildConversationInterruptStoresWorkflowCheckpointData(t *testing.T) {
|
||||
item := buildConversationInterrupt(testConversation(1), testMessage(2), testAIAgent(3), &applicationruntime.Summary{
|
||||
CheckPointData: `{"confirmNodeId":"confirm_1"}`,
|
||||
Interrupted: true,
|
||||
Interrupts: []applicationruntime.InterruptContextSummary{
|
||||
{Type: "human_confirm", ID: "confirm_1", InfoPreview: `{"message":"请确认"}`},
|
||||
},
|
||||
})
|
||||
if item == nil {
|
||||
t.Fatalf("expected interrupt item")
|
||||
}
|
||||
if item.RequestData != `{"confirmNodeId":"confirm_1"}` {
|
||||
t.Fatalf("unexpected request data: %q", item.RequestData)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGraphPlanReason(t *testing.T) {
|
||||
summary := &applicationruntime.Summary{
|
||||
TraceData: `{
|
||||
@@ -109,3 +126,15 @@ type fakeErr string
|
||||
func (e fakeErr) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func testConversation(id int64) models.Conversation {
|
||||
return models.Conversation{ID: id}
|
||||
}
|
||||
|
||||
func testMessage(id int64) models.Message {
|
||||
return models.Message{ID: id}
|
||||
}
|
||||
|
||||
func testAIAgent(id int64) models.AIAgent {
|
||||
return models.AIAgent{ID: id}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ func buildConversationInterrupt(conversation models.Conversation, message models
|
||||
item.InterruptType = firstInterruptType(summary)
|
||||
item.Status = "pending"
|
||||
item.PromptText = resolveInterruptPrompt(summary)
|
||||
item.RequestData = strings.TrimSpace(summary.CheckPointData)
|
||||
item.UpdatedAt = now
|
||||
return item
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import (
|
||||
"agent-desk/internal/ai/workflow/dsl"
|
||||
workflowregistry "agent-desk/internal/ai/workflow/registry"
|
||||
"agent-desk/internal/models"
|
||||
"agent-desk/internal/pkg/dto"
|
||||
"agent-desk/internal/pkg/dto/request"
|
||||
"agent-desk/internal/pkg/utils"
|
||||
"agent-desk/internal/services"
|
||||
)
|
||||
@@ -36,6 +38,16 @@ type Result struct {
|
||||
CompletionTokens int
|
||||
RetrieverCount int
|
||||
TraceData string
|
||||
CheckPointID string
|
||||
CheckPointData string
|
||||
Interrupted bool
|
||||
Interrupts []InterruptSummary
|
||||
}
|
||||
|
||||
type InterruptSummary struct {
|
||||
Type string
|
||||
ID string
|
||||
InfoPreview string
|
||||
}
|
||||
|
||||
type Executor struct{}
|
||||
@@ -52,12 +64,66 @@ type runState struct {
|
||||
result Result
|
||||
}
|
||||
|
||||
type workflowCheckPoint struct {
|
||||
Definition dsl.Definition `json:"definition"`
|
||||
ConfirmNodeID string `json:"confirmNodeId"`
|
||||
Vars map[string]map[string]any `json:"vars"`
|
||||
}
|
||||
|
||||
func (e *Executor) Execute(ctx context.Context, input Input) (*Result, error) {
|
||||
state := newRunState(input)
|
||||
currentID := strings.TrimSpace(input.Definition.EntryNodeID)
|
||||
if currentID == "" {
|
||||
return nil, fmt.Errorf("workflow entry node is required")
|
||||
}
|
||||
return e.executeFrom(ctx, state, currentID)
|
||||
}
|
||||
|
||||
func (e *Executor) Resume(ctx context.Context, input Input, checkPointData string, resumeText string) (*Result, error) {
|
||||
var checkpoint workflowCheckPoint
|
||||
if err := json.Unmarshal([]byte(strings.TrimSpace(checkPointData)), &checkpoint); err != nil {
|
||||
return nil, fmt.Errorf("invalid workflow checkpoint: %w", err)
|
||||
}
|
||||
if len(checkpoint.Definition.Nodes) > 0 {
|
||||
input.Definition = checkpoint.Definition
|
||||
}
|
||||
state := newRunState(input)
|
||||
state.vars = checkpoint.Vars
|
||||
if state.vars == nil {
|
||||
state.vars = make(map[string]map[string]any)
|
||||
}
|
||||
confirmNodeID := strings.TrimSpace(checkpoint.ConfirmNodeID)
|
||||
if confirmNodeID == "" {
|
||||
return nil, fmt.Errorf("workflow checkpoint confirm node is required")
|
||||
}
|
||||
decision := graphs.ParseConfirmationDecision(resumeText)
|
||||
if decision == "" {
|
||||
node, ok := state.nodesByID[confirmNodeID]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("workflow node does not exist: %s", confirmNodeID)
|
||||
}
|
||||
if err := e.executeHumanConfirm(state, node); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
state.result.Status = "interrupted"
|
||||
return &state.result, nil
|
||||
}
|
||||
state.setNodeVars(confirmNodeID, map[string]any{
|
||||
"confirmed": decision == graphs.ConfirmationDecisionConfirm,
|
||||
"responseText": strings.TrimSpace(resumeText),
|
||||
})
|
||||
nextID, ok, err := state.nextNodeID(confirmNodeID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
state.result.Status = "completed"
|
||||
return &state.result, nil
|
||||
}
|
||||
return e.executeFrom(ctx, state, nextID)
|
||||
}
|
||||
|
||||
func (e *Executor) executeFrom(ctx context.Context, state *runState, currentID string) (*Result, error) {
|
||||
for step := 0; step < maxWorkflowSteps; step++ {
|
||||
node, ok := state.nodesByID[currentID]
|
||||
if !ok {
|
||||
@@ -67,6 +133,10 @@ func (e *Executor) Execute(ctx context.Context, input Input) (*Result, error) {
|
||||
if err := e.executeNode(ctx, state, node); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if state.result.Interrupted {
|
||||
state.result.Status = "interrupted"
|
||||
return &state.result, nil
|
||||
}
|
||||
if node.Type == workflowregistry.NodeTypeEnd {
|
||||
state.result.Status = "completed"
|
||||
return &state.result, nil
|
||||
@@ -127,6 +197,12 @@ func (e *Executor) executeNode(ctx context.Context, state *runState, node dsl.No
|
||||
state.setNodeVars(node.ID, map[string]any{"matched": true})
|
||||
case workflowregistry.NodeTypeAnalyzeConversation:
|
||||
return e.executeAnalyzeConversation(ctx, state, node)
|
||||
case workflowregistry.NodeTypePrepareTicketDraft:
|
||||
return e.executePrepareTicketDraft(ctx, state, node)
|
||||
case workflowregistry.NodeTypeHumanConfirm:
|
||||
return e.executeHumanConfirm(state, node)
|
||||
case workflowregistry.NodeTypeCreateTicket:
|
||||
return e.executeCreateTicket(state, node)
|
||||
case workflowregistry.NodeTypeLLMReply:
|
||||
return e.executeLLMReply(ctx, state, node)
|
||||
case workflowregistry.NodeTypeSendReply:
|
||||
@@ -146,6 +222,125 @@ func (e *Executor) executeNode(ctx context.Context, state *runState, node dsl.No
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Executor) executeCreateTicket(state *runState, node dsl.Node) error {
|
||||
confirmed := truthy(state.resolveInput(node, "confirmed"))
|
||||
if !confirmed {
|
||||
state.setNodeVars(node.ID, map[string]any{
|
||||
"ticketId": int64(0),
|
||||
"created": false,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
draft := asMap(state.resolveInput(node, "ticketDraft"))
|
||||
title := strings.TrimSpace(toString(draft["title"]))
|
||||
description := strings.TrimSpace(toString(draft["description"]))
|
||||
item, err := services.TicketService.CreateFromConversation(request.CreateTicketFromConversationRequest{
|
||||
ConversationID: state.input.Conversation.ID,
|
||||
Title: title,
|
||||
Description: description,
|
||||
}, workflowAIPrincipal(state.input.AIAgent))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
state.setNodeVars(node.ID, map[string]any{
|
||||
"ticketId": item.ID,
|
||||
"ticketNo": item.TicketNo,
|
||||
"created": true,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func workflowAIPrincipal(aiAgent models.AIAgent) *dto.AuthPrincipal {
|
||||
username := strings.TrimSpace(aiAgent.Name)
|
||||
if username == "" {
|
||||
username = "AI"
|
||||
}
|
||||
return &dto.AuthPrincipal{
|
||||
UserID: 0,
|
||||
Username: username,
|
||||
Nickname: username,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Executor) executeHumanConfirm(state *runState, node dsl.Node) error {
|
||||
prompt := strings.TrimSpace(toString(state.resolveInput(node, "prompt")))
|
||||
if prompt == "" {
|
||||
prompt = "请确认是否继续。"
|
||||
}
|
||||
infoPreview, err := json.Marshal(map[string]string{"message": prompt})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
state.result.Interrupted = true
|
||||
state.result.CheckPointID = buildWorkflowCheckPointID(state.input, node.ID)
|
||||
checkpoint, err := json.Marshal(workflowCheckPoint{
|
||||
Definition: state.input.Definition,
|
||||
ConfirmNodeID: node.ID,
|
||||
Vars: state.vars,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
state.result.CheckPointData = string(checkpoint)
|
||||
state.result.Interrupts = []InterruptSummary{
|
||||
{
|
||||
Type: workflowregistry.NodeTypeHumanConfirm,
|
||||
ID: node.ID,
|
||||
InfoPreview: string(infoPreview),
|
||||
},
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildWorkflowCheckPointID(input Input, nodeID string) string {
|
||||
return fmt.Sprintf("workflow:%d:%d:%s", input.Conversation.ID, input.UserMessage.ID, strings.TrimSpace(nodeID))
|
||||
}
|
||||
|
||||
func (e *Executor) executePrepareTicketDraft(ctx context.Context, state *runState, node dsl.Node) error {
|
||||
issue := strings.TrimSpace(toString(state.resolveInput(node, "issue")))
|
||||
input := graphs.PrepareTicketDraftInput{
|
||||
Issue: issue,
|
||||
}
|
||||
if title := strings.TrimSpace(readStringConfig(node.Config, "title")); title != "" {
|
||||
input.Title = title
|
||||
}
|
||||
if description := strings.TrimSpace(readStringConfig(node.Config, "description")); description != "" {
|
||||
input.Description = description
|
||||
}
|
||||
if impact := strings.TrimSpace(readStringConfig(node.Config, "impact")); impact != "" {
|
||||
input.Impact = impact
|
||||
}
|
||||
if expectedOutcome := strings.TrimSpace(readStringConfig(node.Config, "expectedOutcome")); expectedOutcome != "" {
|
||||
input.ExpectedOutcome = expectedOutcome
|
||||
}
|
||||
if currentAttempt := strings.TrimSpace(readStringConfig(node.Config, "currentAttempt")); currentAttempt != "" {
|
||||
input.CurrentAttempt = currentAttempt
|
||||
}
|
||||
args, err := json.Marshal(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
raw, err := graphs.NewPrepareTicketDraftGraph(state.input.Conversation).Run(ctx, string(args))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var result graphs.PrepareTicketDraftResult
|
||||
if err := json.Unmarshal([]byte(raw), &result); err != nil {
|
||||
return err
|
||||
}
|
||||
state.setNodeVars(node.ID, map[string]any{
|
||||
"ticketDraft": map[string]any{
|
||||
"ready": result.Ready,
|
||||
"title": strings.TrimSpace(result.Title),
|
||||
"description": strings.TrimSpace(result.Description),
|
||||
"missingFields": result.MissingFields,
|
||||
"followUpQuestions": result.FollowUpQuestions,
|
||||
"conversationFacts": result.ConversationFacts,
|
||||
},
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Executor) executeAnalyzeConversation(ctx context.Context, state *runState, node dsl.Node) error {
|
||||
userMessage := strings.TrimSpace(toString(state.resolveInput(node, "userMessage")))
|
||||
input := graphs.AnalyzeConversationInput{
|
||||
@@ -445,6 +640,25 @@ func toFloat(value any) float64 {
|
||||
}
|
||||
}
|
||||
|
||||
func asMap(value any) map[string]any {
|
||||
switch v := value.(type) {
|
||||
case map[string]any:
|
||||
return v
|
||||
case map[string]string:
|
||||
ret := make(map[string]any, len(v))
|
||||
for key, item := range v {
|
||||
ret[key] = item
|
||||
}
|
||||
return ret
|
||||
case string:
|
||||
var ret map[string]any
|
||||
if err := json.Unmarshal([]byte(strings.TrimSpace(v)), &ret); err == nil {
|
||||
return ret
|
||||
}
|
||||
}
|
||||
return map[string]any{}
|
||||
}
|
||||
|
||||
func truthy(value any) bool {
|
||||
switch v := value.(type) {
|
||||
case nil:
|
||||
|
||||
@@ -110,6 +110,131 @@ func TestExecutorAnalyzeConversationOutputsBranchVariables(t *testing.T) {
|
||||
assertPath(t, result.NodePath, []string{"start_1", "analyze_1", "handoff_end"})
|
||||
}
|
||||
|
||||
func TestExecutorPrepareTicketDraftOutputsDraftVariable(t *testing.T) {
|
||||
db := setupWorkflowExecutorHandoffDB(t)
|
||||
aiAgent := createWorkflowExecutorHandoffAIAgent(t, db, "1")
|
||||
conversation := createWorkflowExecutorHandoffConversation(t, db, aiAgent.ID)
|
||||
userMessage := createWorkflowExecutorCustomerMessage(t, db, conversation.ID, "订单支付失败,请帮我登记工单")
|
||||
|
||||
result, err := NewExecutor().Execute(context.Background(), Input{
|
||||
Definition: prepareTicketDraftWorkflowDefinition(),
|
||||
Conversation: conversation,
|
||||
UserMessage: userMessage,
|
||||
AIAgent: aiAgent,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("execute workflow: %v", err)
|
||||
}
|
||||
assertPath(t, result.NodePath, []string{"start_1", "draft_1", "ready_end"})
|
||||
}
|
||||
|
||||
func TestExecutorHumanConfirmInterruptsWithCheckpoint(t *testing.T) {
|
||||
result, err := NewExecutor().Execute(context.Background(), Input{
|
||||
Definition: humanConfirmWorkflowDefinition(),
|
||||
Conversation: models.Conversation{
|
||||
ID: 11,
|
||||
},
|
||||
UserMessage: models.Message{
|
||||
ID: 22,
|
||||
Content: "创建工单",
|
||||
},
|
||||
AIAgent: models.AIAgent{
|
||||
ID: 33,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("execute workflow: %v", err)
|
||||
}
|
||||
if !result.Interrupted {
|
||||
t.Fatalf("expected workflow to interrupt")
|
||||
}
|
||||
if result.CheckPointID == "" {
|
||||
t.Fatalf("expected checkpoint id")
|
||||
}
|
||||
if len(result.Interrupts) != 1 {
|
||||
t.Fatalf("expected one interrupt, got %#v", result.Interrupts)
|
||||
}
|
||||
if result.Interrupts[0].Type != "human_confirm" || result.Interrupts[0].ID != "confirm_1" {
|
||||
t.Fatalf("unexpected interrupt summary: %#v", result.Interrupts[0])
|
||||
}
|
||||
if !strings.Contains(result.Interrupts[0].InfoPreview, "请确认创建工单") {
|
||||
t.Fatalf("expected confirmation prompt, got %q", result.Interrupts[0].InfoPreview)
|
||||
}
|
||||
assertPath(t, result.NodePath, []string{"start_1", "prompt_1", "confirm_1"})
|
||||
}
|
||||
|
||||
func TestExecutorResumeHumanConfirmContinuesWithConfirmedVariable(t *testing.T) {
|
||||
executor := NewExecutor()
|
||||
input := Input{
|
||||
Definition: humanConfirmWorkflowDefinition(),
|
||||
Conversation: models.Conversation{
|
||||
ID: 11,
|
||||
},
|
||||
UserMessage: models.Message{
|
||||
ID: 22,
|
||||
Content: "创建工单",
|
||||
},
|
||||
AIAgent: models.AIAgent{
|
||||
ID: 33,
|
||||
},
|
||||
}
|
||||
interrupted, err := executor.Execute(context.Background(), input)
|
||||
if err != nil {
|
||||
t.Fatalf("execute workflow: %v", err)
|
||||
}
|
||||
result, err := executor.Resume(context.Background(), input, interrupted.CheckPointData, "确认")
|
||||
if err != nil {
|
||||
t.Fatalf("resume workflow: %v", err)
|
||||
}
|
||||
if result.Interrupted {
|
||||
t.Fatalf("expected workflow resume to complete")
|
||||
}
|
||||
assertPath(t, result.NodePath, []string{"end_1"})
|
||||
}
|
||||
|
||||
func TestExecutorResumeCreatesTicketAfterHumanConfirmation(t *testing.T) {
|
||||
db := setupWorkflowExecutorHandoffDB(t)
|
||||
aiAgent := createWorkflowExecutorHandoffAIAgent(t, db, "1")
|
||||
conversation := createWorkflowExecutorHandoffConversation(t, db, aiAgent.ID)
|
||||
userMessage := createWorkflowExecutorCustomerMessage(t, db, conversation.ID, "订单支付失败,请帮我登记工单")
|
||||
executor := NewExecutor()
|
||||
|
||||
interrupted, err := executor.Execute(context.Background(), Input{
|
||||
Definition: createTicketWorkflowDefinition(),
|
||||
Conversation: conversation,
|
||||
UserMessage: userMessage,
|
||||
AIAgent: aiAgent,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("execute workflow: %v", err)
|
||||
}
|
||||
if !interrupted.Interrupted {
|
||||
t.Fatalf("expected workflow to interrupt before creating ticket")
|
||||
}
|
||||
|
||||
result, err := executor.Resume(context.Background(), Input{
|
||||
Definition: createTicketWorkflowDefinition(),
|
||||
Conversation: conversation,
|
||||
UserMessage: userMessage,
|
||||
AIAgent: aiAgent,
|
||||
}, interrupted.CheckPointData, "确认")
|
||||
if err != nil {
|
||||
t.Fatalf("resume workflow: %v", err)
|
||||
}
|
||||
if result.Interrupted {
|
||||
t.Fatalf("expected workflow to complete")
|
||||
}
|
||||
assertPath(t, result.NodePath, []string{"create_ticket_1", "end_1"})
|
||||
|
||||
var ticket models.Ticket
|
||||
if err := db.First(&ticket, "conversation_id = ?", conversation.ID).Error; err != nil {
|
||||
t.Fatalf("expected created ticket: %v", err)
|
||||
}
|
||||
if ticket.Title == "" || !strings.Contains(ticket.Description, "订单支付失败") {
|
||||
t.Fatalf("unexpected ticket: %+v", ticket)
|
||||
}
|
||||
}
|
||||
|
||||
func conditionalReplyDefinition() dsl.Definition {
|
||||
return dsl.Definition{
|
||||
SchemaVersion: 1,
|
||||
@@ -148,6 +273,103 @@ func conditionalReplyDefinition() dsl.Definition {
|
||||
}
|
||||
}
|
||||
|
||||
func createTicketWorkflowDefinition() dsl.Definition {
|
||||
return dsl.Definition{
|
||||
SchemaVersion: 1,
|
||||
EntryNodeID: "start_1",
|
||||
Nodes: []dsl.Node{
|
||||
{ID: "start_1", Type: workflowregistry.NodeTypeStart, Name: "Start"},
|
||||
{ID: "draft_1", Type: workflowregistry.NodeTypePrepareTicketDraft, Name: "Draft", Inputs: map[string]dsl.VariableSelector{
|
||||
"issue": {NodeID: "start_1", Field: "userMessage"},
|
||||
}},
|
||||
{ID: "prompt_1", Type: workflowregistry.NodeTypeLLMReply, Name: "Prompt", Config: []byte(`{"staticReply":"请确认创建工单"}`)},
|
||||
{ID: "confirm_1", Type: workflowregistry.NodeTypeHumanConfirm, Name: "Confirm", Inputs: map[string]dsl.VariableSelector{
|
||||
"prompt": {NodeID: "prompt_1", Field: "replyText"},
|
||||
}},
|
||||
{ID: "create_ticket_1", Type: workflowregistry.NodeTypeCreateTicket, Name: "Create Ticket", Inputs: map[string]dsl.VariableSelector{
|
||||
"ticketDraft": {NodeID: "draft_1", Field: "ticketDraft"},
|
||||
"confirmed": {NodeID: "confirm_1", Field: "confirmed"},
|
||||
}},
|
||||
{ID: "end_1", Type: workflowregistry.NodeTypeEnd, Name: "End"},
|
||||
{ID: "cancel_end", Type: workflowregistry.NodeTypeEnd, Name: "Cancel"},
|
||||
},
|
||||
Edges: []dsl.Edge{
|
||||
{ID: "edge_start_draft", Source: "start_1", Target: "draft_1"},
|
||||
{ID: "edge_draft_prompt", Source: "draft_1", Target: "prompt_1"},
|
||||
{ID: "edge_prompt_confirm", Source: "prompt_1", Target: "confirm_1"},
|
||||
{
|
||||
ID: "edge_confirm_create",
|
||||
Source: "confirm_1",
|
||||
Target: "create_ticket_1",
|
||||
Condition: &dsl.Condition{
|
||||
Left: &dsl.VariableSelector{NodeID: "confirm_1", Field: "confirmed"},
|
||||
Operator: "is_true",
|
||||
},
|
||||
},
|
||||
{ID: "edge_confirm_cancel", Source: "confirm_1", Target: "cancel_end"},
|
||||
{ID: "edge_create_end", Source: "create_ticket_1", Target: "end_1"},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func humanConfirmWorkflowDefinition() dsl.Definition {
|
||||
return dsl.Definition{
|
||||
SchemaVersion: 1,
|
||||
EntryNodeID: "start_1",
|
||||
Nodes: []dsl.Node{
|
||||
{ID: "start_1", Type: workflowregistry.NodeTypeStart, Name: "Start"},
|
||||
{ID: "prompt_1", Type: workflowregistry.NodeTypeLLMReply, Name: "Prompt", Config: []byte(`{"staticReply":"请确认创建工单"}`)},
|
||||
{ID: "confirm_1", Type: workflowregistry.NodeTypeHumanConfirm, Name: "Confirm", Inputs: map[string]dsl.VariableSelector{
|
||||
"prompt": {NodeID: "prompt_1", Field: "replyText"},
|
||||
}},
|
||||
{ID: "end_1", Type: workflowregistry.NodeTypeEnd, Name: "End"},
|
||||
{ID: "cancel_end", Type: workflowregistry.NodeTypeEnd, Name: "Cancel"},
|
||||
},
|
||||
Edges: []dsl.Edge{
|
||||
{ID: "edge_start_prompt", Source: "start_1", Target: "prompt_1"},
|
||||
{ID: "edge_prompt_confirm", Source: "prompt_1", Target: "confirm_1"},
|
||||
{
|
||||
ID: "edge_confirm_yes",
|
||||
Source: "confirm_1",
|
||||
Target: "end_1",
|
||||
Condition: &dsl.Condition{
|
||||
Left: &dsl.VariableSelector{NodeID: "confirm_1", Field: "confirmed"},
|
||||
Operator: "is_true",
|
||||
},
|
||||
},
|
||||
{ID: "edge_confirm_cancel", Source: "confirm_1", Target: "cancel_end"},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func prepareTicketDraftWorkflowDefinition() dsl.Definition {
|
||||
return dsl.Definition{
|
||||
SchemaVersion: 1,
|
||||
EntryNodeID: "start_1",
|
||||
Nodes: []dsl.Node{
|
||||
{ID: "start_1", Type: workflowregistry.NodeTypeStart, Name: "Start"},
|
||||
{ID: "draft_1", Type: workflowregistry.NodeTypePrepareTicketDraft, Name: "Draft", Inputs: map[string]dsl.VariableSelector{
|
||||
"issue": {NodeID: "start_1", Field: "userMessage"},
|
||||
}},
|
||||
{ID: "ready_end", Type: workflowregistry.NodeTypeEnd, Name: "Ready"},
|
||||
{ID: "default_end", Type: workflowregistry.NodeTypeEnd, Name: "Default"},
|
||||
},
|
||||
Edges: []dsl.Edge{
|
||||
{ID: "edge_start_draft", Source: "start_1", Target: "draft_1"},
|
||||
{
|
||||
ID: "edge_draft_ready",
|
||||
Source: "draft_1",
|
||||
Target: "ready_end",
|
||||
Condition: &dsl.Condition{
|
||||
Left: &dsl.VariableSelector{NodeID: "draft_1", Field: "ticketDraft"},
|
||||
Operator: "exists",
|
||||
},
|
||||
},
|
||||
{ID: "edge_draft_default", Source: "draft_1", Target: "default_end"},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func analyzeConversationWorkflowDefinition() dsl.Definition {
|
||||
return dsl.Definition{
|
||||
SchemaVersion: 1,
|
||||
@@ -225,16 +447,23 @@ func setupWorkflowExecutorHandoffDB(t *testing.T) *gorm.DB {
|
||||
})
|
||||
if err := db.AutoMigrate(
|
||||
&models.User{},
|
||||
&models.Customer{},
|
||||
&models.CustomerIdentity{},
|
||||
&models.AIAgent{},
|
||||
&models.AgentTeam{},
|
||||
&models.AgentTeamSchedule{},
|
||||
&models.AgentProfile{},
|
||||
&models.Channel{},
|
||||
&models.Conversation{},
|
||||
&models.ConversationAssignment{},
|
||||
&models.ConversationEventLog{},
|
||||
&models.ConversationReadState{},
|
||||
&models.Message{},
|
||||
&models.ChannelMessageOutbox{},
|
||||
&models.Ticket{},
|
||||
&models.TicketNoSequence{},
|
||||
&models.TicketTag{},
|
||||
&models.TicketProgress{},
|
||||
); err != nil {
|
||||
t.Fatalf("auto migrate error = %v", err)
|
||||
}
|
||||
@@ -303,6 +532,13 @@ func createWorkflowExecutorHandoffAgentProfile(t *testing.T, db *gorm.DB, userID
|
||||
func createWorkflowExecutorHandoffConversation(t *testing.T, db *gorm.DB, aiAgentID int64) models.Conversation {
|
||||
t.Helper()
|
||||
now := time.Now()
|
||||
if err := db.FirstOrCreate(&models.Customer{
|
||||
ID: 1,
|
||||
Name: "测试访客",
|
||||
Status: enums.StatusOk,
|
||||
}).Error; err != nil {
|
||||
t.Fatalf("create customer error = %v", err)
|
||||
}
|
||||
item := models.Conversation{
|
||||
AIAgentID: aiAgentID,
|
||||
ChannelID: 1,
|
||||
|
||||
Reference in New Issue
Block a user