refactor(workflow): Move the plugin component in the Workflow package into the common crossdomain package (#717)

This commit is contained in:
Ryo
2025-08-13 11:06:53 +08:00
committed by GitHub
parent b38ab95623
commit 99c759addc
47 changed files with 1330 additions and 1407 deletions

View File

@@ -26,6 +26,7 @@ import (
"github.com/cloudwego/eino/compose"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/database"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/execute"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes"
@@ -412,7 +413,7 @@ func isDebugExecute(ctx context.Context) bool {
if execCtx == nil {
panic(fmt.Errorf("unable to get exe context"))
}
return execCtx.RootCtx.ExeCfg.Mode == vo.ExecuteModeDebug || execCtx.RootCtx.ExeCfg.Mode == vo.ExecuteModeNodeDebug
return execCtx.RootCtx.ExeCfg.Mode == plugin.ExecuteModeDebug || execCtx.RootCtx.ExeCfg.Mode == plugin.ExecuteModeNodeDebug
}
func getExecUserID(ctx context.Context) string {

View File

@@ -25,6 +25,7 @@ import (
"go.uber.org/mock/gomock"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/database"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
crossdatabase "github.com/coze-dev/coze-studio/backend/crossdomain/contract/database"
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/database/databasemock"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
@@ -71,10 +72,10 @@ func TestCustomSQL_Execute(t *testing.T) {
defer mockey.Mock(execute.GetExeCtx).Return(&execute.Context{
RootCtx: execute.RootCtx{
ExeCfg: vo.ExecuteConfig{
Mode: vo.ExecuteModeDebug,
ExeCfg: plugin.ExecuteConfig{
Mode: plugin.ExecuteModeDebug,
Operator: 123,
BizType: vo.BizTypeWorkflow,
BizType: plugin.BizTypeWorkflow,
},
},
}).Build().UnPatch()

View File

@@ -27,6 +27,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/database"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
crossdatabase "github.com/coze-dev/coze-studio/backend/crossdomain/contract/database"
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/database/databasemock"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
@@ -56,10 +57,10 @@ func (m *mockDsSelect) Query() func(ctx context.Context, request *database.Query
func TestDataset_Query(t *testing.T) {
defer mockey.Mock(execute.GetExeCtx).Return(&execute.Context{
RootCtx: execute.RootCtx{
ExeCfg: vo.ExecuteConfig{
Mode: vo.ExecuteModeDebug,
ExeCfg: plugin.ExecuteConfig{
Mode: plugin.ExecuteModeDebug,
Operator: 123,
BizType: vo.BizTypeWorkflow,
BizType: plugin.BizTypeWorkflow,
},
},
}).Build().UnPatch()

View File

@@ -36,11 +36,12 @@ import (
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/knowledge"
crossmodel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
workflow3 "github.com/coze-dev/coze-studio/backend/api/model/workflow"
crossknowledge "github.com/coze-dev/coze-studio/backend/crossdomain/contract/knowledge"
crossmodelmgr "github.com/coze-dev/coze-studio/backend/crossdomain/contract/modelmgr"
crossplugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin"
"github.com/coze-dev/coze-studio/backend/domain/workflow"
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/plugin"
"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"
@@ -399,9 +400,9 @@ func (c *Config) Build(ctx context.Context, ns *schema2.NodeSchema, _ ...schema2
workflowToolConfig.OutputParametersConfig = wf.FCSetting.ResponseParameters
}
locator := vo.FromDraft
locator := plugin.FromDraft
if wf.WorkflowVersion != "" {
locator = vo.FromSpecificVersion
locator = plugin.FromSpecificVersion
}
wfTool, err := workflow.GetRepository().WorkflowAsTool(ctx, vo.GetPolicy{
@@ -455,7 +456,7 @@ func (c *Config) Build(ctx context.Context, ns *schema2.NodeSchema, _ ...schema2
}
} else {
pluginToolsInfoRequest := &plugin.ToolsInvokableRequest{
PluginEntity: plugin.Entity{
PluginEntity: plugin.PluginEntity{
PluginID: pid,
PluginVersion: ptr.Of(p.PluginVersion),
},
@@ -473,12 +474,12 @@ func (c *Config) Build(ctx context.Context, ns *schema2.NodeSchema, _ ...schema2
}
inInvokableTools := make([]tool.BaseTool, 0, len(fcParams.PluginFCParam.PluginList))
for _, req := range pluginToolsInvokableReq {
toolMap, err := plugin.GetPluginService().GetPluginInvokableTools(ctx, req)
toolMap, err := crossplugin.DefaultSVC().GetPluginInvokableTools(ctx, req)
if err != nil {
return nil, err
}
for _, t := range toolMap {
inInvokableTools = append(inInvokableTools, plugin.NewInvokableTool(t))
inInvokableTools = append(inInvokableTools, newInvokableTool(t))
}
}
if len(inInvokableTools) > 0 {

View File

@@ -0,0 +1,45 @@
/*
* 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 llm
import (
"context"
"github.com/cloudwego/eino/components/tool"
"github.com/cloudwego/eino/schema"
crossplugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/execute"
)
type pluginInvokableTool struct {
pluginInvokableTool crossplugin.InvokableTool
}
func newInvokableTool(pl crossplugin.InvokableTool) tool.InvokableTool {
return &pluginInvokableTool{
pluginInvokableTool: pl,
}
}
func (p pluginInvokableTool) Info(ctx context.Context) (*schema.ToolInfo, error) {
return p.pluginInvokableTool.Info(ctx)
}
func (p pluginInvokableTool) InvokableRun(ctx context.Context, argumentsInJSON string, opts ...tool.Option) (string, error) {
execCfg := execute.GetExecuteConfig(opts...)
return p.pluginInvokableTool.PluginInvoke(ctx, argumentsInJSON, execCfg)
}

View File

@@ -23,7 +23,8 @@ import (
"github.com/cloudwego/eino/compose"
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/plugin"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
crossplugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin"
"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"
@@ -100,7 +101,6 @@ func (c *Config) Build(_ context.Context, _ *schema.NodeSchema, _ ...schema.Buil
pluginID: c.PluginID,
toolID: c.ToolID,
pluginVersion: c.PluginVersion,
pluginService: plugin.GetPluginService(),
}, nil
}
@@ -108,16 +108,14 @@ type Plugin struct {
pluginID int64
toolID int64
pluginVersion string
pluginService plugin.Service
}
func (p *Plugin) Invoke(ctx context.Context, parameters map[string]any) (ret map[string]any, err error) {
var exeCfg vo.ExecuteConfig
var exeCfg model.ExecuteConfig
if ctxExeCfg := execute.GetExeCtx(ctx); ctxExeCfg != nil {
exeCfg = ctxExeCfg.ExeCfg
}
result, err := p.pluginService.ExecutePlugin(ctx, parameters, &vo.PluginEntity{
result, err := crossplugin.DefaultSVC().ExecutePlugin(ctx, parameters, &model.PluginEntity{
PluginID: p.pluginID,
PluginVersion: ptr.Of(p.pluginVersion),
}, p.toolID, exeCfg)