Skip to content

Commit f7b5096

Browse files
feat: allow more customizability for custom workflow node (#1930)
1 parent 8db69fd commit f7b5096

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1562
-1528
lines changed

backend/api/handler/coze/workflow_service_test.go

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -719,12 +719,13 @@ func withSpecificNodeID(id string) func(options *getProcessOptions) {
719719
}
720720

721721
type exeResult struct {
722-
output string
723-
status workflow.WorkflowExeStatus
724-
event *workflow.NodeEvent
725-
token *workflow.TokenAndCost
726-
t *testing.T
727-
reason string
722+
output string
723+
status workflow.WorkflowExeStatus
724+
event *workflow.NodeEvent
725+
token *workflow.TokenAndCost
726+
t *testing.T
727+
reason string
728+
nodeResults []*workflow.NodeResult
728729
}
729730

730731
func (e *exeResult) assertSuccess() {
@@ -743,6 +744,26 @@ func (e *exeResult) tokenEqual(in, out int) {
743744
assert.Equal(e.t, out, outputI)
744745
}
745746

747+
func (e *exeResult) nodeResultHasResponseExtra(nodeID string, k string, v any) {
748+
var n *workflow.NodeResult
749+
750+
for _, nr := range e.nodeResults {
751+
if nr.NodeId == nodeID {
752+
n = nr
753+
break
754+
}
755+
}
756+
757+
if n == nil {
758+
e.t.Fatal("node key: ", nodeID, "not found")
759+
return
760+
}
761+
extra := mustUnmarshalToMap(e.t, n.Extra)
762+
assert.NotEmpty(e.t, extra)
763+
assert.Contains(e.t, extra, "response_extra")
764+
assert.Equal(e.t, extra["response_extra"].(map[string]any)[k], v)
765+
}
766+
746767
func (r *wfTestRunner) getProcess(id, exeID string, opts ...func(options *getProcessOptions)) *exeResult {
747768
options := &getProcessOptions{}
748769
for _, opt := range opts {
@@ -756,6 +777,7 @@ func (r *wfTestRunner) getProcess(id, exeID string, opts ...func(options *getPro
756777
var nodeType string
757778
var token *workflow.TokenAndCost
758779
var reason string
780+
var nodeResults []*workflow.NodeResult
759781
var count int
760782
for {
761783
if nodeEvent != nil {
@@ -808,18 +830,22 @@ func (r *wfTestRunner) getProcess(id, exeID string, opts ...func(options *getPro
808830
if nodeEvent != nil {
809831
eventID = nodeEvent.ID
810832
}
833+
834+
nodeResults = getProcessResp.Data.NodeResults
835+
811836
r.t.Logf("getProcess output= %s, status= %v, eventID= %s, nodeType= %s", output, workflowStatus, eventID, nodeType)
812837

813838
count++
814839
}
815840

816841
return &exeResult{
817-
output: output,
818-
status: workflowStatus,
819-
event: nodeEvent,
820-
token: token,
821-
t: r.t,
822-
reason: reason,
842+
output: output,
843+
status: workflowStatus,
844+
event: nodeEvent,
845+
token: token,
846+
t: r.t,
847+
reason: reason,
848+
nodeResults: nodeResults,
823849
}
824850
}
825851

@@ -1140,7 +1166,8 @@ func TestTestRunAndGetProcess(t *testing.T) {
11401166

11411167
mockey.PatchConvey("test run success, then cancel", func() {
11421168
exeID := r.testRun(id, input)
1143-
r.getProcess(id, exeID)
1169+
exeResult := r.getProcess(id, exeID)
1170+
exeResult.nodeResultHasResponseExtra(entity.ExitNodeKey, "terminal_plan", int64(2))
11441171

11451172
// cancel after success, nothing happens
11461173
r.cancel(id, exeID)
@@ -1374,6 +1401,7 @@ func TestTestResumeWithInputNode(t *testing.T) {
13741401

13751402
result := r.getNodeExeHistory(id, exeID, "154951", nil)
13761403
assert.Equal(t, mustUnmarshalToMap(t, e2.output), mustUnmarshalToMap(t, result.Output))
1404+
assert.Equal(t, mustUnmarshalToMap(t, e2.output), mustUnmarshalToMap(t, result.Input))
13771405
})
13781406

13791407
mockey.PatchConvey("sync run does not support interrupt", func() {
@@ -2589,6 +2617,7 @@ func TestAggregateStreamVariables(t *testing.T) {
25892617
e := r.getProcess(id, exeID)
25902618
e.assertSuccess()
25912619
assert.Equal(t, "I won't tell you.\nI won't tell you.\n{\"Group1\":\"I won't tell you.\",\"input\":\"I've got an important question\"}", e.output)
2620+
e.nodeResultHasResponseExtra(entity.ExitNodeKey, "terminal_plan", int64(2))
25922621

25932622
defer r.runServer()()
25942623

backend/application/base/appinfra/app_infra.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,13 +590,13 @@ func getVectorStore(ctx context.Context) (searchstore.Manager, error) {
590590
}
591591

592592
managerConfig := &oceanbase.ManagerConfig{
593-
Client: client,
594-
Embedding: emb,
595-
BatchSize: batchSize,
596-
EnableCache: enableCache,
597-
CacheTTL: cacheTTL,
593+
Client: client,
594+
Embedding: emb,
595+
BatchSize: batchSize,
596+
EnableCache: enableCache,
597+
CacheTTL: cacheTTL,
598598
MaxConnections: maxConnections,
599-
ConnTimeout: connTimeout,
599+
ConnTimeout: connTimeout,
600600
}
601601
mgr, err := oceanbase.NewManager(managerConfig)
602602
if err != nil {

backend/application/workflow/chatflow.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -628,14 +628,10 @@ func (w *ApplicationService) OpenAPIChatFlowRun(ctx context.Context, req *workfl
628628
}
629629

630630
if existed {
631-
var data = lastUserMessage.Content
632-
if info.NodeType == entity.NodeTypeInputReceiver {
633-
data = parserInput(lastUserMessage.Content)
634-
}
635631
sr, err := GetWorkflowDomainSVC().StreamResume(ctx, &entity.ResumeRequest{
636632
EventID: info.EventID,
637633
ExecuteID: info.ExecID,
638-
ResumeData: data,
634+
ResumeData: lastUserMessage.Content,
639635
}, workflowModel.ExecuteConfig{
640636
Operator: userID,
641637
Mode: ternary.IFElse(isDebug, workflowModel.ExecuteModeDebug, workflowModel.ExecuteModeRelease),

backend/application/workflow/workflow_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ import (
2121
"strings"
2222
"testing"
2323

24+
"github.com/stretchr/testify/assert"
25+
"github.com/stretchr/testify/require"
26+
2427
"github.com/coze-dev/coze-studio/backend/api/model/workflow"
2528
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
2629
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
27-
"github.com/stretchr/testify/assert"
28-
"github.com/stretchr/testify/require"
2930
)
3031

3132
func TestToVariable(t *testing.T) {

backend/crossdomain/impl/plugin/plugin_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ package plugin
1919
import (
2020
"testing"
2121

22+
"github.com/stretchr/testify/assert"
23+
2224
"github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common"
2325
workflow3 "github.com/coze-dev/coze-studio/backend/api/model/workflow"
2426
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
25-
"github.com/stretchr/testify/assert"
2627
)
2728

2829
func TestToWorkflowAPIParameter(t *testing.T) {

0 commit comments

Comments
 (0)