From b97933e35727b732a43103e8345bd5d1457b2b70 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 27 May 2025 12:07:41 +0800 Subject: [PATCH] Refactor Assistant struct to replace Flows with Workflow and update cloning logic - Replaced the Flows field in the Assistant struct with a Workflow field to better represent the assistant's functionality. - Updated the Clone method to perform a deep copy of the Workflow instead of Flows. - Adjusted related test cases to reflect the changes in the Assistant struct and ensure proper functionality. --- neo/assistant/assistant.go | 14 ++++------- neo/assistant/load_test.go | 8 +++---- neo/assistant/types.go | 48 +++++++++++++++++++------------------- 3 files changed, 33 insertions(+), 37 deletions(-) diff --git a/neo/assistant/assistant.go b/neo/assistant/assistant.go index 1be35738..2300254b 100644 --- a/neo/assistant/assistant.go +++ b/neo/assistant/assistant.go @@ -239,15 +239,11 @@ func (ast *Assistant) Clone() *Assistant { } } - // Deep copy flows - if ast.Flows != nil { - clone.Flows = make([]map[string]interface{}, len(ast.Flows)) - for i, flow := range ast.Flows { - cloneFlow := make(map[string]interface{}) - for k, v := range flow { - cloneFlow[k] = v - } - clone.Flows[i] = cloneFlow + // Deep copy workflow + if ast.Workflow != nil { + clone.Workflow = make(map[string]interface{}) + for k, v := range ast.Workflow { + clone.Workflow[k] = v } } diff --git a/neo/assistant/load_test.go b/neo/assistant/load_test.go index 17503e5b..7b620be0 100644 --- a/neo/assistant/load_test.go +++ b/neo/assistant/load_test.go @@ -196,7 +196,7 @@ func TestLoad_Clone(t *testing.T) { Automated: true, Options: map[string]interface{}{"key": "value"}, Prompts: []Prompt{{Role: "system", Content: "test"}}, - Flows: []map[string]interface{}{{"step": "test"}}, + Workflow: map[string]interface{}{"step": "test"}, } // Clone the assistant @@ -218,15 +218,15 @@ func TestLoad_Clone(t *testing.T) { assert.Equal(t, original.Automated, clone.Automated) assert.Equal(t, original.Options, clone.Options) assert.Equal(t, original.Prompts, clone.Prompts) - assert.Equal(t, original.Flows, clone.Flows) + assert.Equal(t, original.Workflow, clone.Workflow) // Verify deep copy by modifying original original.Tags[0] = "modified" original.Options["key"] = "modified" - original.Flows[0]["step"] = "modified" + original.Workflow["step"] = "modified" assert.NotEqual(t, original.Tags[0], clone.Tags[0]) assert.NotEqual(t, original.Options["key"], clone.Options["key"]) - assert.NotEqual(t, original.Flows[0]["step"], clone.Flows[0]["step"]) + assert.NotEqual(t, original.Workflow["step"], clone.Workflow["step"]) // Test nil case var nilAssistant *Assistant diff --git a/neo/assistant/types.go b/neo/assistant/types.go index 39fe92fc..6d261a32 100644 --- a/neo/assistant/types.go +++ b/neo/assistant/types.go @@ -122,30 +122,30 @@ type QueryParam struct { // Assistant the assistant type Assistant struct { - ID string `json:"assistant_id"` // Assistant ID - Type string `json:"type,omitempty"` // Assistant Type, default is assistant - Name string `json:"name,omitempty"` // Assistant Name - Avatar string `json:"avatar,omitempty"` // Assistant Avatar - Connector string `json:"connector"` // AI Connector - Path string `json:"path,omitempty"` // Assistant Path - BuiltIn bool `json:"built_in,omitempty"` // Whether this is a built-in assistant - Sort int `json:"sort,omitempty"` // Assistant Sort - Description string `json:"description,omitempty"` // Assistant Description - Tags []string `json:"tags,omitempty"` // Assistant Tags - Readonly bool `json:"readonly,omitempty"` // Whether this assistant is readonly - Mentionable bool `json:"mentionable,omitempty"` // Whether this assistant is mentionable - Automated bool `json:"automated,omitempty"` // Whether this assistant is automated - Options map[string]interface{} `json:"options,omitempty"` // AI Options - Prompts []Prompt `json:"prompts,omitempty"` // AI Prompts - Tools *ToolCalls `json:"tools,omitempty"` // Assistant Tools - Flows []map[string]interface{} `json:"flows,omitempty"` // Assistant Flows - Placeholder *Placeholder `json:"placeholder,omitempty"` // Assistant Placeholder - Locales i18n.Map `json:"locales,omitempty"` // Assistant Locales - Search *SearchOption `json:"search,omitempty" yaml:"search,omitempty"` // Whether this assistant supports search - Knowledge *KnowledgeOption `json:"knowledge,omitempty" yaml:"knowledge,omitempty"` // Whether this assistant supports knowledge - CreatedAt int64 `json:"created_at"` // Creation timestamp - UpdatedAt int64 `json:"updated_at"` // Last update timestamp - Script *v8.Script `json:"-" yaml:"-"` // Assistant Script + ID string `json:"assistant_id"` // Assistant ID + Type string `json:"type,omitempty"` // Assistant Type, default is assistant + Name string `json:"name,omitempty"` // Assistant Name + Avatar string `json:"avatar,omitempty"` // Assistant Avatar + Connector string `json:"connector"` // AI Connector + Path string `json:"path,omitempty"` // Assistant Path + BuiltIn bool `json:"built_in,omitempty"` // Whether this is a built-in assistant + Sort int `json:"sort,omitempty"` // Assistant Sort + Description string `json:"description,omitempty"` // Assistant Description + Tags []string `json:"tags,omitempty"` // Assistant Tags + Readonly bool `json:"readonly,omitempty"` // Whether this assistant is readonly + Mentionable bool `json:"mentionable,omitempty"` // Whether this assistant is mentionable + Automated bool `json:"automated,omitempty"` // Whether this assistant is automated + Options map[string]interface{} `json:"options,omitempty"` // AI Options + Prompts []Prompt `json:"prompts,omitempty"` // AI Prompts + Tools *ToolCalls `json:"tools,omitempty"` // Assistant Tools + Workflow map[string]interface{} `json:"workflow,omitempty"` // Assistant Workflow + Placeholder *Placeholder `json:"placeholder,omitempty"` // Assistant Placeholder + Locales i18n.Map `json:"locales,omitempty"` // Assistant Locales + Search *SearchOption `json:"search,omitempty" yaml:"search,omitempty"` // Whether this assistant supports search + Knowledge *KnowledgeOption `json:"knowledge,omitempty" yaml:"knowledge,omitempty"` // Whether this assistant supports knowledge + CreatedAt int64 `json:"created_at"` // Creation timestamp + UpdatedAt int64 `json:"updated_at"` // Last update timestamp + Script *v8.Script `json:"-" yaml:"-"` // Assistant Script // Internal // ===============================