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.
This commit is contained in:
Max 2025-05-27 12:07:41 +08:00
parent 1058598be3
commit b97933e357
3 changed files with 33 additions and 37 deletions

View file

@ -239,15 +239,11 @@ func (ast *Assistant) Clone() *Assistant {
} }
} }
// Deep copy flows // Deep copy workflow
if ast.Flows != nil { if ast.Workflow != nil {
clone.Flows = make([]map[string]interface{}, len(ast.Flows)) clone.Workflow = make(map[string]interface{})
for i, flow := range ast.Flows { for k, v := range ast.Workflow {
cloneFlow := make(map[string]interface{}) clone.Workflow[k] = v
for k, v := range flow {
cloneFlow[k] = v
}
clone.Flows[i] = cloneFlow
} }
} }

View file

@ -196,7 +196,7 @@ func TestLoad_Clone(t *testing.T) {
Automated: true, Automated: true,
Options: map[string]interface{}{"key": "value"}, Options: map[string]interface{}{"key": "value"},
Prompts: []Prompt{{Role: "system", Content: "test"}}, Prompts: []Prompt{{Role: "system", Content: "test"}},
Flows: []map[string]interface{}{{"step": "test"}}, Workflow: map[string]interface{}{"step": "test"},
} }
// Clone the assistant // Clone the assistant
@ -218,15 +218,15 @@ func TestLoad_Clone(t *testing.T) {
assert.Equal(t, original.Automated, clone.Automated) assert.Equal(t, original.Automated, clone.Automated)
assert.Equal(t, original.Options, clone.Options) assert.Equal(t, original.Options, clone.Options)
assert.Equal(t, original.Prompts, clone.Prompts) 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 // Verify deep copy by modifying original
original.Tags[0] = "modified" original.Tags[0] = "modified"
original.Options["key"] = "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.Tags[0], clone.Tags[0])
assert.NotEqual(t, original.Options["key"], clone.Options["key"]) 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 // Test nil case
var nilAssistant *Assistant var nilAssistant *Assistant

View file

@ -138,7 +138,7 @@ type Assistant struct {
Options map[string]interface{} `json:"options,omitempty"` // AI Options Options map[string]interface{} `json:"options,omitempty"` // AI Options
Prompts []Prompt `json:"prompts,omitempty"` // AI Prompts Prompts []Prompt `json:"prompts,omitempty"` // AI Prompts
Tools *ToolCalls `json:"tools,omitempty"` // Assistant Tools Tools *ToolCalls `json:"tools,omitempty"` // Assistant Tools
Flows []map[string]interface{} `json:"flows,omitempty"` // Assistant Flows Workflow map[string]interface{} `json:"workflow,omitempty"` // Assistant Workflow
Placeholder *Placeholder `json:"placeholder,omitempty"` // Assistant Placeholder Placeholder *Placeholder `json:"placeholder,omitempty"` // Assistant Placeholder
Locales i18n.Map `json:"locales,omitempty"` // Assistant Locales Locales i18n.Map `json:"locales,omitempty"` // Assistant Locales
Search *SearchOption `json:"search,omitempty" yaml:"search,omitempty"` // Whether this assistant supports search Search *SearchOption `json:"search,omitempty" yaml:"search,omitempty"` // Whether this assistant supports search