feat: add config for workflow domain (#1847)
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/config"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
)
|
||||
@@ -91,3 +92,7 @@ type ToolFromWorkflow interface {
|
||||
TerminatePlan() vo.TerminatePlan
|
||||
GetWorkflow() *entity.Workflow
|
||||
}
|
||||
|
||||
type WorkflowConfig interface {
|
||||
GetNodeOfCodeConfig() *config.NodeOfCodeConfig
|
||||
}
|
||||
|
||||
33
backend/domain/workflow/config/workflow_config.go
Normal file
33
backend/domain/workflow/config/workflow_config.go
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package config
|
||||
|
||||
type WorkflowConfig struct {
|
||||
NodeOfCodeConfig *NodeOfCodeConfig `yaml:"NodeOfCodeConfig"`
|
||||
}
|
||||
|
||||
func (w WorkflowConfig) GetNodeOfCodeConfig() *NodeOfCodeConfig {
|
||||
return w.NodeOfCodeConfig
|
||||
}
|
||||
|
||||
type NodeOfCodeConfig struct {
|
||||
SupportThirdPartModules []string `yaml:"SupportThirdPartModules"`
|
||||
}
|
||||
|
||||
func (n *NodeOfCodeConfig) GetSupportThirdPartModules() []string {
|
||||
return n.SupportThirdPartModules
|
||||
}
|
||||
@@ -99,6 +99,8 @@ type Repository interface {
|
||||
idgen.IDGenerator
|
||||
|
||||
GetKnowledgeRecallChatModel() model.BaseChatModel
|
||||
|
||||
WorkflowConfig
|
||||
}
|
||||
|
||||
var repositorySingleton Repository
|
||||
|
||||
@@ -18,6 +18,7 @@ package adaptor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/config"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -752,6 +753,15 @@ func TestCodeAndPluginNodes(t *testing.T) {
|
||||
defer ctrl.Finish()
|
||||
mockCodeRunner := mockcode.NewMockRunner(ctrl)
|
||||
mockey.Mock(code.GetCodeRunner).Return(mockCodeRunner).Build()
|
||||
|
||||
mockRepo := mockWorkflow.NewMockRepository(ctrl)
|
||||
|
||||
mockRepo.EXPECT().GetNodeOfCodeConfig().Return(&config.NodeOfCodeConfig{
|
||||
SupportThirdPartModules: []string{"httpx", "numpy"},
|
||||
}).AnyTimes()
|
||||
|
||||
mockey.Mock(workflow.GetRepository).Return(mockRepo).Build()
|
||||
|
||||
mockCodeRunner.EXPECT().Run(gomock.Any(), gomock.Any()).Return(&coderunner.RunResponse{
|
||||
Result: map[string]any{
|
||||
"key0": "value0",
|
||||
|
||||
@@ -104,7 +104,7 @@ func TestQuestionAnswer(t *testing.T) {
|
||||
mockTos := storageMock.NewMockStorage(ctrl)
|
||||
mockTos.EXPECT().GetObjectUrl(gomock.Any(), gomock.Any(), gomock.Any()).Return("", nil).AnyTimes()
|
||||
repo := repo2.NewRepository(mockIDGen, db, redisClient, mockTos,
|
||||
checkpoint.NewRedisStore(redisClient), nil)
|
||||
checkpoint.NewRedisStore(redisClient), nil, nil)
|
||||
mockey.Mock(workflow.GetRepository).Return(repo).Build()
|
||||
|
||||
t.Run("answer directly, no structured output", func(t *testing.T) {
|
||||
|
||||
@@ -26,10 +26,12 @@ import (
|
||||
"golang.org/x/exp/maps"
|
||||
|
||||
code2 "github.com/coze-dev/coze-studio/backend/crossdomain/impl/code"
|
||||
wf "github.com/coze-dev/coze-studio/backend/domain/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/canvas/convert"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/schema"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/coderunner"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes"
|
||||
@@ -107,15 +109,6 @@ var pythonBuiltinBlacklist = map[string]struct{}{
|
||||
"tty": {},
|
||||
}
|
||||
|
||||
// pythonThirdPartyWhitelist is the whitelist of python third-party modules,
|
||||
// see: https://www.coze.cn/open/docs/guides/code_node#7f41f073
|
||||
// If you want to use other third-party libraries, you can add them to this whitelist.
|
||||
// And you also need to install them in `/scripts/setup/python.sh` and `/backend/Dockerfile` via `pip install`.
|
||||
var pythonThirdPartyWhitelist = map[string]struct{}{
|
||||
"httpx": {},
|
||||
"numpy": {},
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Code string
|
||||
Language coderunner.Language
|
||||
@@ -192,6 +185,9 @@ func validatePythonImports(code string) error {
|
||||
imports := parsePythonImports(code)
|
||||
importErrors := make([]string, 0)
|
||||
|
||||
pythonThirdPartyWhitelist := slices.ToMap(wf.GetRepository().GetNodeOfCodeConfig().GetSupportThirdPartModules(), func(e string) (string, bool) {
|
||||
return e, true
|
||||
})
|
||||
var blacklistedModules []string
|
||||
var nonWhitelistedModules []string
|
||||
for _, imp := range imports {
|
||||
|
||||
@@ -69,10 +69,11 @@ type RepositoryImpl struct {
|
||||
workflow.CancelSignalStore
|
||||
workflow.ExecuteHistoryStore
|
||||
builtinModel cm.BaseChatModel
|
||||
workflow.WorkflowConfig
|
||||
}
|
||||
|
||||
func NewRepository(idgen idgen.IDGenerator, db *gorm.DB, redis cache.Cmdable, tos storage.Storage,
|
||||
cpStore einoCompose.CheckPointStore, chatModel cm.BaseChatModel) workflow.Repository {
|
||||
cpStore einoCompose.CheckPointStore, chatModel cm.BaseChatModel, workflowConfig workflow.WorkflowConfig) workflow.Repository {
|
||||
return &RepositoryImpl{
|
||||
IDGenerator: idgen,
|
||||
query: query.Use(db),
|
||||
@@ -89,7 +90,8 @@ func NewRepository(idgen idgen.IDGenerator, db *gorm.DB, redis cache.Cmdable, to
|
||||
query: query.Use(db),
|
||||
redis: redis,
|
||||
},
|
||||
builtinModel: chatModel,
|
||||
builtinModel: chatModel,
|
||||
WorkflowConfig: workflowConfig,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,13 +22,12 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
einoCompose "github.com/cloudwego/eino/compose"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
"golang.org/x/exp/maps"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"gorm.io/gorm"
|
||||
|
||||
einoCompose "github.com/cloudwego/eino/compose"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
cloudworkflow "github.com/coze-dev/coze-studio/backend/api/model/workflow"
|
||||
@@ -72,8 +71,8 @@ func NewWorkflowService(repo workflow.Repository) workflow.Service {
|
||||
}
|
||||
|
||||
func NewWorkflowRepository(idgen idgen.IDGenerator, db *gorm.DB, redis cache.Cmdable, tos storage.Storage,
|
||||
cpStore einoCompose.CheckPointStore, chatModel chatmodel.BaseChatModel) workflow.Repository {
|
||||
return repo.NewRepository(idgen, db, redis, tos, cpStore, chatModel)
|
||||
cpStore einoCompose.CheckPointStore, chatModel chatmodel.BaseChatModel, workflowConfig workflow.WorkflowConfig) workflow.Repository {
|
||||
return repo.NewRepository(idgen, db, redis, tos, cpStore, chatModel, workflowConfig)
|
||||
}
|
||||
|
||||
func (i *impl) ListNodeMeta(_ context.Context, nodeTypes map[entity.NodeType]bool) (map[string][]*entity.NodeTypeMeta, []entity.Category, error) {
|
||||
|
||||
Reference in New Issue
Block a user