refactor workflow
This commit is contained in:
@@ -7,6 +7,7 @@ const SchemaVersion = 2
|
||||
type Definition struct {
|
||||
SchemaVersion int `json:"schemaVersion"`
|
||||
Nodes []Node `json:"nodes"`
|
||||
Annotations []Node `json:"annotations,omitempty"`
|
||||
Edges []Edge `json:"edges"`
|
||||
}
|
||||
|
||||
@@ -187,3 +188,22 @@ func (d *NodeData) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d NodeData) MarshalJSON() ([]byte, error) {
|
||||
type alias NodeData
|
||||
base, err := json.Marshal(alias(d))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
values := make(map[string]json.RawMessage)
|
||||
if err := json.Unmarshal(base, &values); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for key, value := range d.Extra {
|
||||
if _, exists := values[key]; exists {
|
||||
continue
|
||||
}
|
||||
values[key] = value
|
||||
}
|
||||
return json.Marshal(values)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package dsl_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"agent-desk/internal/ai/workflow/dsl"
|
||||
@@ -81,3 +82,32 @@ func TestDefinitionUnmarshalsFlowGramStyleSchema(t *testing.T) {
|
||||
t.Fatalf("unexpected edge: %#v", edge)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefinitionPreservesCanvasAnnotations(t *testing.T) {
|
||||
var def dsl.Definition
|
||||
err := json.Unmarshal([]byte(`{
|
||||
"schemaVersion": 2,
|
||||
"nodes": [],
|
||||
"annotations": [{
|
||||
"id": "comment_1",
|
||||
"type": "comment",
|
||||
"meta": {"position": {"x": 12, "y": 34}},
|
||||
"data": {"note": "check this branch", "size": {"width": 240, "height": 150}}
|
||||
}],
|
||||
"edges": []
|
||||
}`), &def)
|
||||
if err != nil {
|
||||
t.Fatalf("unmarshal definition: %v", err)
|
||||
}
|
||||
if len(def.Annotations) != 1 || def.Annotations[0].ID != "comment_1" {
|
||||
t.Fatalf("expected annotation to be preserved, got %#v", def.Annotations)
|
||||
}
|
||||
encoded, err := json.Marshal(def)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal definition: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(encoded), `"annotations"`) ||
|
||||
!strings.Contains(string(encoded), `"check this branch"`) {
|
||||
t.Fatalf("expected annotation JSON to round trip, got %s", encoded)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user