refactor(workflow): Move the variable component in the Workflow package into the common crossdomain package (#738)

main
Ryo 2 months ago committed by GitHub
parent 5d98e8ef93
commit dce313b8e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      backend/api/handler/coze/workflow_service_test.go
  2. 5
      backend/application/workflow/init.go
  3. 6
      backend/crossdomain/contract/variables/varibales.go
  4. 15
      backend/crossdomain/impl/variables/variables.go
  5. 2
      backend/domain/workflow/internal/canvas/validate/canvas_validate.go
  6. 2
      backend/domain/workflow/internal/compose/state.go
  7. 2
      backend/domain/workflow/internal/nodes/loop/break/break.go
  8. 3
      backend/domain/workflow/internal/nodes/parent_intermediate.go
  9. 2
      backend/domain/workflow/internal/nodes/variableassigner/variable_assign.go
  10. 2
      backend/domain/workflow/internal/nodes/variableassigner/variable_assign_in_loop.go
  11. 2
      backend/domain/workflow/service/utils.go
  12. 11
      backend/domain/workflow/variable/variable.go
  13. 58
      backend/domain/workflow/variable/variable_impl.go
  14. 20
      backend/domain/workflow/variable/varmock/var_mock.go
  15. 2
      docker/.env.debug.example
  16. 2
      docker/.env.example

@ -80,11 +80,11 @@ import (
search "github.com/coze-dev/coze-studio/backend/domain/search/entity"
userentity "github.com/coze-dev/coze-studio/backend/domain/user/entity"
workflow2 "github.com/coze-dev/coze-studio/backend/domain/workflow"
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/variable"
mockvar "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/variable/varmock"
"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/service"
"github.com/coze-dev/coze-studio/backend/domain/workflow/variable"
mockvar "github.com/coze-dev/coze-studio/backend/domain/workflow/variable/varmock"
"github.com/coze-dev/coze-studio/backend/infra/contract/coderunner"
"github.com/coze-dev/coze-studio/backend/infra/contract/modelmgr"
"github.com/coze-dev/coze-studio/backend/infra/impl/cache/redis"

@ -25,7 +25,6 @@ import (
"github.com/coze-dev/coze-studio/backend/application/internal"
"github.com/coze-dev/coze-studio/backend/crossdomain/impl/code"
"github.com/coze-dev/coze-studio/backend/crossdomain/workflow/variable"
knowledge "github.com/coze-dev/coze-studio/backend/domain/knowledge/service"
dbservice "github.com/coze-dev/coze-studio/backend/domain/memory/database/service"
variables "github.com/coze-dev/coze-studio/backend/domain/memory/variables/service"
@ -33,7 +32,6 @@ import (
search "github.com/coze-dev/coze-studio/backend/domain/search/service"
"github.com/coze-dev/coze-studio/backend/domain/workflow"
crossvariable "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/variable"
"github.com/coze-dev/coze-studio/backend/domain/workflow/service"
workflowservice "github.com/coze-dev/coze-studio/backend/domain/workflow/service"
"github.com/coze-dev/coze-studio/backend/infra/contract/cache"
@ -75,8 +73,7 @@ func InitService(ctx context.Context, components *ServiceComponents) (*Applicati
workflow.SetRepository(workflowRepo)
workflowDomainSVC := service.NewWorkflowService(workflowRepo)
crossvariable.SetVariableHandler(variable.NewVariableHandler(components.VariablesDomainSVC))
crossvariable.SetVariablesMetaGetter(variable.NewVariablesMetaGetter(components.VariablesDomainSVC))
code.SetCodeRunner(components.CodeRunner)
callbacks.AppendGlobalHandlers(workflowservice.GetTokenCallbackHandler())
setEventBus(components.DomainNotifier)

@ -21,12 +21,18 @@ import (
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/variables"
"github.com/coze-dev/coze-studio/backend/api/model/data/variable/kvmemory"
"github.com/coze-dev/coze-studio/backend/api/model/data/variable/project_memory"
"github.com/coze-dev/coze-studio/backend/domain/memory/variables/entity"
)
// TODO (@fanlv): Parameter references need to be modified.
type Variables interface {
GetVariableInstance(ctx context.Context, e *variables.UserVariableMeta, keywords []string) ([]*kvmemory.KVItem, error)
SetVariableInstance(ctx context.Context, e *variables.UserVariableMeta, items []*kvmemory.KVItem) ([]string, error)
DecryptSysUUIDKey(ctx context.Context, encryptSysUUIDKey string) *variables.UserVariableMeta
GetVariableChannelInstance(ctx context.Context, e *variables.UserVariableMeta, keywords []string, varChannel *project_memory.VariableChannel) ([]*kvmemory.KVItem, error)
GetProjectVariablesMeta(ctx context.Context, projectID, version string) (*entity.VariablesMeta, error)
GetAgentVariableMeta(ctx context.Context, agentID int64, version string) (*entity.VariablesMeta, error)
}
var defaultSVC Variables

@ -21,7 +21,7 @@ import (
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/variables"
"github.com/coze-dev/coze-studio/backend/api/model/data/variable/kvmemory"
"github.com/coze-dev/coze-studio/backend/api/model/data/variable/project_memory"
crossvariables "github.com/coze-dev/coze-studio/backend/crossdomain/contract/variables"
"github.com/coze-dev/coze-studio/backend/domain/memory/variables/entity"
variables "github.com/coze-dev/coze-studio/backend/domain/memory/variables/service"
@ -65,3 +65,16 @@ func (s *impl) DecryptSysUUIDKey(ctx context.Context, encryptSysUUIDKey string)
ConnectorID: m.ConnectorID,
}
}
func (s *impl) GetVariableChannelInstance(ctx context.Context, e *model.UserVariableMeta, keywords []string, varChannel *project_memory.VariableChannel) ([]*kvmemory.KVItem, error) {
m := entity.NewUserVariableMeta(e)
return s.DomainSVC.GetVariableChannelInstance(ctx, m, keywords, varChannel)
}
func (s *impl) GetProjectVariablesMeta(ctx context.Context, projectID string, version string) (*entity.VariablesMeta, error) {
return s.DomainSVC.GetProjectVariablesMeta(ctx, projectID, version)
}
func (s *impl) GetAgentVariableMeta(ctx context.Context, agentID int64, version string) (*entity.VariablesMeta, error) {
return s.DomainSVC.GetAgentVariableMeta(ctx, agentID, version)
}

@ -23,12 +23,12 @@ import (
"strconv"
"github.com/coze-dev/coze-studio/backend/domain/workflow"
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/variable"
"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/canvas/convert"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/schema"
"github.com/coze-dev/coze-studio/backend/domain/workflow/variable"
"github.com/coze-dev/coze-studio/backend/pkg/sonic"
"github.com/coze-dev/coze-studio/backend/types/errno"
)

@ -28,7 +28,6 @@ import (
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
workflow2 "github.com/coze-dev/coze-studio/backend/api/model/workflow"
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/variable"
"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/execute"
@ -37,6 +36,7 @@ import (
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes/qa"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes/receiver"
schema2 "github.com/coze-dev/coze-studio/backend/domain/workflow/internal/schema"
"github.com/coze-dev/coze-studio/backend/domain/workflow/variable"
"github.com/coze-dev/coze-studio/backend/pkg/sonic"
)

@ -21,11 +21,11 @@ import (
"github.com/cloudwego/eino/compose"
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/variable"
"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/nodes"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/schema"
"github.com/coze-dev/coze-studio/backend/domain/workflow/variable"
)
type Break struct {

@ -21,11 +21,10 @@ import (
"fmt"
"sync"
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/variable"
"github.com/cloudwego/eino/compose"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
"github.com/coze-dev/coze-studio/backend/domain/workflow/variable"
)
type ParentIntermediateStore struct {

@ -24,13 +24,13 @@ import (
"github.com/cloudwego/eino/compose"
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/variable"
"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/canvas/convert"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/execute"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/schema"
"github.com/coze-dev/coze-studio/backend/domain/workflow/variable"
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
"github.com/coze-dev/coze-studio/backend/types/errno"
)

@ -22,12 +22,12 @@ import (
einoCompose "github.com/cloudwego/eino/compose"
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/variable"
"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/canvas/convert"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/schema"
"github.com/coze-dev/coze-studio/backend/domain/workflow/variable"
)
type InLoopConfig struct {

@ -23,10 +23,10 @@ import (
"strings"
cloudworkflow "github.com/coze-dev/coze-studio/backend/api/model/workflow"
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/variable"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/canvas/adaptor"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/canvas/validate"
"github.com/coze-dev/coze-studio/backend/domain/workflow/variable"
"github.com/coze-dev/coze-studio/backend/pkg/sonic"
"github.com/coze-dev/coze-studio/backend/types/errno"
)

@ -28,10 +28,7 @@ import (
var variableHandlerSingleton *Handler
func GetVariableHandler() *Handler {
return variableHandlerSingleton
}
func SetVariableHandler(handler *Handler) {
variableHandlerSingleton = handler
return NewVariableHandler()
}
type Handler struct {
@ -111,11 +108,7 @@ type Store interface {
var variablesMetaGetterImpl VariablesMetaGetter
func GetVariablesMetaGetter() VariablesMetaGetter {
return variablesMetaGetterImpl
}
func SetVariablesMetaGetter(v VariablesMetaGetter) {
variablesMetaGetterImpl = v
return NewVariablesMetaGetter()
}
type VariablesMetaGetter interface {

@ -23,60 +23,53 @@ import (
"strconv"
"github.com/bytedance/sonic"
"github.com/cloudwego/eino/compose"
variablesModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/variables"
"github.com/coze-dev/coze-studio/backend/api/model/data/variable/kvmemory"
"github.com/coze-dev/coze-studio/backend/api/model/data/variable/project_memory"
crossvariables "github.com/coze-dev/coze-studio/backend/crossdomain/contract/variables"
"github.com/coze-dev/coze-studio/backend/domain/memory/variables/entity"
variables "github.com/coze-dev/coze-studio/backend/domain/memory/variables/service"
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/variable"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
"github.com/coze-dev/coze-studio/backend/types/errno"
"github.com/coze-dev/coze-studio/backend/pkg/lang/ternary"
"github.com/coze-dev/coze-studio/backend/types/errno"
)
type varStore struct {
variableChannel project_memory.VariableChannel
vs variables.Variables
}
func NewVariableHandler(vs variables.Variables) *variable.Handler {
return &variable.Handler{
UserVarStore: newUserVarStore(vs),
AppVarStore: newAppVarStore(vs),
SystemVarStore: newSystemVarStore(vs),
func NewVariableHandler() *Handler {
return &Handler{
UserVarStore: newUserVarStore(),
AppVarStore: newAppVarStore(),
SystemVarStore: newSystemVarStore(),
}
}
func newUserVarStore(vs variables.Variables) variable.Store {
func newUserVarStore() Store {
return &varStore{
variableChannel: project_memory.VariableChannel_Custom,
vs: vs,
}
}
func newAppVarStore(vs variables.Variables) variable.Store {
func newAppVarStore() Store {
return &varStore{
variableChannel: project_memory.VariableChannel_APP,
vs: vs,
}
}
func newSystemVarStore(vs variables.Variables) variable.Store {
func newSystemVarStore() Store {
return &varStore{
variableChannel: project_memory.VariableChannel_System,
vs: vs,
}
}
func (v *varStore) Init(ctx context.Context) {
}
func (v *varStore) Get(ctx context.Context, path compose.FieldPath, opts ...variable.OptionFn) (any, error) {
opt := &variable.StoreConfig{}
func (v *varStore) Get(ctx context.Context, path compose.FieldPath, opts ...OptionFn) (any, error) {
opt := &StoreConfig{}
for _, o := range opts {
o(opt)
}
@ -96,17 +89,17 @@ func (v *varStore) Get(ctx context.Context, path compose.FieldPath, opts ...vari
return nil, fmt.Errorf("there must be one of the App ID or Agent ID")
}
meta := entity.NewUserVariableMeta(&variablesModel.UserVariableMeta{
meta := &variablesModel.UserVariableMeta{
BizType: bizType,
BizID: bizID,
ConnectorID: opt.StoreInfo.ConnectorID,
ConnectorUID: opt.StoreInfo.ConnectorUID,
})
}
if len(path) == 0 {
return nil, errors.New("field path is required")
}
key := path[0]
kvItems, err := v.vs.GetVariableChannelInstance(ctx, meta, []string{key}, project_memory.VariableChannelPtr(v.variableChannel))
kvItems, err := crossvariables.DefaultSVC().GetVariableChannelInstance(ctx, meta, []string{key}, project_memory.VariableChannelPtr(v.variableChannel))
if err != nil {
return nil, err
}
@ -194,8 +187,8 @@ func (v *varStore) Get(ctx context.Context, path compose.FieldPath, opts ...vari
return value, nil
}
func (v *varStore) Set(ctx context.Context, path compose.FieldPath, value any, opts ...variable.OptionFn) (err error) {
opt := &variable.StoreConfig{}
func (v *varStore) Set(ctx context.Context, path compose.FieldPath, value any, opts ...OptionFn) (err error) {
opt := &StoreConfig{}
for _, o := range opts {
o(opt)
}
@ -215,12 +208,12 @@ func (v *varStore) Set(ctx context.Context, path compose.FieldPath, value any, o
return fmt.Errorf("there must be one of the App ID or Agent ID")
}
meta := entity.NewUserVariableMeta(&variablesModel.UserVariableMeta{
meta := &variablesModel.UserVariableMeta{
BizType: bizType,
BizID: bizID,
ConnectorID: opt.StoreInfo.ConnectorID,
ConnectorUID: opt.StoreInfo.ConnectorUID,
})
}
if len(path) == 0 {
return errors.New("field path is required")
@ -246,7 +239,7 @@ func (v *varStore) Set(ctx context.Context, path compose.FieldPath, value any, o
IsSystem: isSystem,
})
_, err = v.vs.SetVariableInstance(ctx, meta, kvItems)
_, err = crossvariables.DefaultSVC().SetVariableInstance(ctx, meta, kvItems)
if err != nil {
return err
}
@ -255,18 +248,15 @@ func (v *varStore) Set(ctx context.Context, path compose.FieldPath, value any, o
}
type variablesMetaGetter struct {
vs variables.Variables
}
func NewVariablesMetaGetter(vs variables.Variables) variable.VariablesMetaGetter {
return &variablesMetaGetter{
vs: vs,
}
func NewVariablesMetaGetter() VariablesMetaGetter {
return &variablesMetaGetter{}
}
func (v variablesMetaGetter) GetAppVariablesMeta(ctx context.Context, id, version string) (m map[string]*vo.TypeInfo, err error) {
var varMetas *entity.VariablesMeta
varMetas, err = v.vs.GetProjectVariablesMeta(ctx, id, version)
varMetas, err = crossvariables.DefaultSVC().GetProjectVariablesMeta(ctx, id, version)
if err != nil {
return nil, err
}
@ -291,7 +281,7 @@ func (v variablesMetaGetter) GetAppVariablesMeta(ctx context.Context, id, versio
func (v variablesMetaGetter) GetAgentVariablesMeta(ctx context.Context, id int64, version string) (m map[string]*vo.TypeInfo, err error) {
var varMetas *entity.VariablesMeta
varMetas, err = v.vs.GetAgentVariableMeta(ctx, id, version)
varMetas, err = crossvariables.DefaultSVC().GetAgentVariableMeta(ctx, id, version)
if err != nil {
return nil, err
}

@ -1,19 +1,3 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Code generated by MockGen. DO NOT EDIT.
// Source: variable.go
//
@ -29,9 +13,9 @@ import (
context "context"
reflect "reflect"
variable "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/variable"
vo "github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
compose "github.com/cloudwego/eino/compose"
vo "github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
variable "github.com/coze-dev/coze-studio/backend/domain/workflow/variable"
gomock "go.uber.org/mock/gomock"
)

@ -2,7 +2,7 @@
export RUN_MODE="debug" # Currently supports debug mode. When set to debug, it helps developers print raw error messages during development and debugging, such as agent debugging.
# Server
export LISTEN_ADDR="127.0.0.1:8888"
export LISTEN_ADDR=":8888"
export LOG_LEVEL="debug"
export MAX_REQUEST_BODY_SIZE=1073741824
export SERVER_HOST="http://localhost${LISTEN_ADDR}"

@ -1,5 +1,5 @@
# Server
export LISTEN_ADDR="127.0.0.1:8888"
export LISTEN_ADDR=":8888"
export LOG_LEVEL="debug"
export MAX_REQUEST_BODY_SIZE=1073741824
export SERVER_HOST="http://localhost${LISTEN_ADDR}"

Loading…
Cancel
Save