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
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
}
}

View file

@ -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

View file

@ -138,7 +138,7 @@ type Assistant struct {
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
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