refactor: how to add a node type in workflow (#558)

This commit is contained in:
shentongmartin
2025-08-05 14:02:33 +08:00
committed by GitHub
parent 5dafd81a3f
commit bb6ff0026b
96 changed files with 8305 additions and 8717 deletions

View File

@@ -58,6 +58,11 @@ import (
"github.com/coze-dev/coze-studio/backend/types/consts"
)
func TestMain(m *testing.M) {
RegisterAllNodeAdaptors()
m.Run()
}
func TestIntentDetectorAndDatabase(t *testing.T) {
mockey.PatchConvey("intent detector & database custom sql", t, func() {
data, err := os.ReadFile("../examples/intent_detector_database_custom_sql.json")

View File

@@ -26,10 +26,11 @@ import (
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/compose"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/schema"
)
func WorkflowSchemaFromNode(ctx context.Context, c *vo.Canvas, nodeID string) (
*compose.WorkflowSchema, error) {
*schema.WorkflowSchema, error) {
var (
n *vo.Node
nodeFinder func(nodes []*vo.Node) *vo.Node
@@ -62,35 +63,27 @@ func WorkflowSchemaFromNode(ctx context.Context, c *vo.Canvas, nodeID string) (
n = batchN
}
implicitDependencies, err := extractImplicitDependency(n, c.Nodes)
if err != nil {
return nil, err
}
opts := make([]OptionFn, 0, 1)
if len(implicitDependencies) > 0 {
opts = append(opts, WithImplicitNodeDependencies(implicitDependencies))
}
nsList, hierarchy, err := NodeToNodeSchema(ctx, n, opts...)
nsList, hierarchy, err := NodeToNodeSchema(ctx, n, c)
if err != nil {
return nil, err
}
var (
ns *compose.NodeSchema
innerNodes map[vo.NodeKey]*compose.NodeSchema // inner nodes of the composite node if nodeKey is composite
connections []*compose.Connection
ns *schema.NodeSchema
innerNodes map[vo.NodeKey]*schema.NodeSchema // inner nodes of the composite node if nodeKey is composite
connections []*schema.Connection
)
if len(nsList) == 1 {
ns = nsList[0]
} else {
innerNodes = make(map[vo.NodeKey]*compose.NodeSchema)
innerNodes = make(map[vo.NodeKey]*schema.NodeSchema)
for i := range nsList {
one := nsList[i]
if _, ok := hierarchy[one.Key]; ok {
innerNodes[one.Key] = one
if one.Type == entity.NodeTypeContinue || one.Type == entity.NodeTypeBreak {
connections = append(connections, &compose.Connection{
connections = append(connections, &schema.Connection{
FromNode: one.Key,
ToNode: vo.NodeKey(nodeID),
})
@@ -106,13 +99,13 @@ func WorkflowSchemaFromNode(ctx context.Context, c *vo.Canvas, nodeID string) (
}
const inputFillerKey = "input_filler"
connections = append(connections, &compose.Connection{
connections = append(connections, &schema.Connection{
FromNode: einoCompose.START,
ToNode: inputFillerKey,
}, &compose.Connection{
}, &schema.Connection{
FromNode: inputFillerKey,
ToNode: ns.Key,
}, &compose.Connection{
}, &schema.Connection{
FromNode: ns.Key,
ToNode: einoCompose.END,
})
@@ -209,7 +202,7 @@ func WorkflowSchemaFromNode(ctx context.Context, c *vo.Canvas, nodeID string) (
return newOutput, nil
}
inputFiller := &compose.NodeSchema{
inputFiller := &schema.NodeSchema{
Key: inputFillerKey,
Type: entity.NodeTypeLambda,
Lambda: einoCompose.InvokableLambda(i),
@@ -227,10 +220,16 @@ func WorkflowSchemaFromNode(ctx context.Context, c *vo.Canvas, nodeID string) (
OutputTypes: startOutputTypes,
}
trimmedSC := &compose.WorkflowSchema{
Nodes: append([]*compose.NodeSchema{ns, inputFiller}, maps.Values(innerNodes)...),
branches, err := schema.BuildBranches(connections)
if err != nil {
return nil, err
}
trimmedSC := &schema.WorkflowSchema{
Nodes: append([]*schema.NodeSchema{ns, inputFiller}, maps.Values(innerNodes)...),
Connections: connections,
Hierarchy: hierarchy,
Branches: branches,
}
if enabled {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff