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

@@ -23,17 +23,18 @@ import (
"github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
)
type Executable interface {
SyncExecute(ctx context.Context, config vo.ExecuteConfig, input map[string]any) (*entity.WorkflowExecution, vo.TerminatePlan, error)
AsyncExecute(ctx context.Context, config vo.ExecuteConfig, input map[string]any) (int64, error)
AsyncExecuteNode(ctx context.Context, nodeID string, config vo.ExecuteConfig, input map[string]any) (int64, error)
AsyncResume(ctx context.Context, req *entity.ResumeRequest, config vo.ExecuteConfig) error
StreamExecute(ctx context.Context, config vo.ExecuteConfig, input map[string]any) (*schema.StreamReader[*entity.Message], error)
StreamResume(ctx context.Context, req *entity.ResumeRequest, config vo.ExecuteConfig) (
SyncExecute(ctx context.Context, config plugin.ExecuteConfig, input map[string]any) (*entity.WorkflowExecution, vo.TerminatePlan, error)
AsyncExecute(ctx context.Context, config plugin.ExecuteConfig, input map[string]any) (int64, error)
AsyncExecuteNode(ctx context.Context, nodeID string, config plugin.ExecuteConfig, input map[string]any) (int64, error)
AsyncResume(ctx context.Context, req *entity.ResumeRequest, config plugin.ExecuteConfig) error
StreamExecute(ctx context.Context, config plugin.ExecuteConfig, input map[string]any) (*schema.StreamReader[*entity.Message], error)
StreamResume(ctx context.Context, req *entity.ResumeRequest, config plugin.ExecuteConfig) (
*schema.StreamReader[*entity.Message], error)
GetExecution(ctx context.Context, wfExe *entity.WorkflowExecution, includeNodes bool) (*entity.WorkflowExecution, error)
@@ -48,7 +49,7 @@ type Executable interface {
type AsTool interface {
WorkflowAsModelTool(ctx context.Context, policies []*vo.GetPolicy) ([]ToolFromWorkflow, error)
WithMessagePipe() (compose.Option, *schema.StreamReader[*entity.Message])
WithExecuteConfig(cfg vo.ExecuteConfig) compose.Option
WithExecuteConfig(cfg plugin.ExecuteConfig) compose.Option
WithResumeToolWorkflow(resumingEvent *entity.ToolInterruptEvent, resumeData string,
allInterruptEvents map[string]*entity.ToolInterruptEvent) compose.Option
}

View File

@@ -1,121 +0,0 @@
/*
* 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 plugin
import (
"context"
"github.com/cloudwego/eino/components/tool"
"github.com/cloudwego/eino/schema"
workflow3 "github.com/coze-dev/coze-studio/backend/api/model/workflow"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/execute"
)
//go:generate mockgen -destination pluginmock/plugin_mock.go --package pluginmock -source plugin.go
type Service interface {
GetPluginToolsInfo(ctx context.Context, req *ToolsInfoRequest) (*ToolsInfoResponse, error)
GetPluginInvokableTools(ctx context.Context, req *ToolsInvokableRequest) (map[int64]InvokableTool, error)
ExecutePlugin(ctx context.Context, input map[string]any, pe *Entity,
toolID int64, cfg ExecConfig) (map[string]any, error)
}
func GetPluginService() Service {
return pluginSrvImpl
}
func SetPluginService(ts Service) {
pluginSrvImpl = ts
}
var pluginSrvImpl Service
type Entity = vo.PluginEntity
type WorkflowAPIParameters = []*workflow3.APIParameter
type ToolsInfoRequest struct {
PluginEntity Entity
ToolIDs []int64
IsDraft bool
}
type ToolsInvokableInfo struct {
ToolID int64
RequestAPIParametersConfig WorkflowAPIParameters
ResponseAPIParametersConfig WorkflowAPIParameters
}
type ToolsInvokableRequest struct {
PluginEntity Entity
ToolsInvokableInfo map[int64]*ToolsInvokableInfo
IsDraft bool
}
type DebugExample struct {
ReqExample string
RespExample string
}
type ToolInfo struct {
ToolName string
ToolID int64
Description string
DebugExample *DebugExample
Inputs []*workflow3.APIParameter
Outputs []*workflow3.APIParameter
}
type ToolsInfoResponse struct {
PluginID int64
SpaceID int64
Version string
PluginName string
Description string
IconURL string
PluginType int64
ToolInfoList map[int64]ToolInfo
LatestVersion *string
IsOfficial bool
AppID int64
}
type ExecConfig = vo.ExecuteConfig
type InvokableTool interface {
Info(ctx context.Context) (*schema.ToolInfo, error)
PluginInvoke(ctx context.Context, argumentsInJSON string, cfg ExecConfig) (string, error)
}
type pluginInvokableTool struct {
pluginInvokableTool InvokableTool
}
func NewInvokableTool(pl 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

@@ -1,159 +0,0 @@
/*
* 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: plugin.go
//
// Generated by this command:
//
// mockgen -destination pluginmock/plugin_mock.go --package pluginmock -source plugin.go
//
// Package pluginmock is a generated GoMock package.
package pluginmock
import (
context "context"
reflect "reflect"
schema "github.com/cloudwego/eino/schema"
plugin "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/plugin"
gomock "go.uber.org/mock/gomock"
)
// MockService is a mock of Service interface.
type MockService struct {
ctrl *gomock.Controller
recorder *MockServiceMockRecorder
isgomock struct{}
}
// MockServiceMockRecorder is the mock recorder for MockService.
type MockServiceMockRecorder struct {
mock *MockService
}
// NewMockService creates a new mock instance.
func NewMockService(ctrl *gomock.Controller) *MockService {
mock := &MockService{ctrl: ctrl}
mock.recorder = &MockServiceMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockService) EXPECT() *MockServiceMockRecorder {
return m.recorder
}
// ExecutePlugin mocks base method.
func (m *MockService) ExecutePlugin(ctx context.Context, input map[string]any, pe *plugin.Entity, toolID int64, cfg plugin.ExecConfig) (map[string]any, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ExecutePlugin", ctx, input, pe, toolID, cfg)
ret0, _ := ret[0].(map[string]any)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ExecutePlugin indicates an expected call of ExecutePlugin.
func (mr *MockServiceMockRecorder) ExecutePlugin(ctx, input, pe, toolID, cfg any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExecutePlugin", reflect.TypeOf((*MockService)(nil).ExecutePlugin), ctx, input, pe, toolID, cfg)
}
// GetPluginInvokableTools mocks base method.
func (m *MockService) GetPluginInvokableTools(ctx context.Context, req *plugin.ToolsInvokableRequest) (map[int64]plugin.InvokableTool, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPluginInvokableTools", ctx, req)
ret0, _ := ret[0].(map[int64]plugin.InvokableTool)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetPluginInvokableTools indicates an expected call of GetPluginInvokableTools.
func (mr *MockServiceMockRecorder) GetPluginInvokableTools(ctx, req any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPluginInvokableTools", reflect.TypeOf((*MockService)(nil).GetPluginInvokableTools), ctx, req)
}
// GetPluginToolsInfo mocks base method.
func (m *MockService) GetPluginToolsInfo(ctx context.Context, req *plugin.ToolsInfoRequest) (*plugin.ToolsInfoResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPluginToolsInfo", ctx, req)
ret0, _ := ret[0].(*plugin.ToolsInfoResponse)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetPluginToolsInfo indicates an expected call of GetPluginToolsInfo.
func (mr *MockServiceMockRecorder) GetPluginToolsInfo(ctx, req any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPluginToolsInfo", reflect.TypeOf((*MockService)(nil).GetPluginToolsInfo), ctx, req)
}
// MockInvokableTool is a mock of InvokableTool interface.
type MockInvokableTool struct {
ctrl *gomock.Controller
recorder *MockInvokableToolMockRecorder
isgomock struct{}
}
// MockInvokableToolMockRecorder is the mock recorder for MockInvokableTool.
type MockInvokableToolMockRecorder struct {
mock *MockInvokableTool
}
// NewMockInvokableTool creates a new mock instance.
func NewMockInvokableTool(ctrl *gomock.Controller) *MockInvokableTool {
mock := &MockInvokableTool{ctrl: ctrl}
mock.recorder = &MockInvokableToolMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockInvokableTool) EXPECT() *MockInvokableToolMockRecorder {
return m.recorder
}
// Info mocks base method.
func (m *MockInvokableTool) Info(ctx context.Context) (*schema.ToolInfo, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Info", ctx)
ret0, _ := ret[0].(*schema.ToolInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Info indicates an expected call of Info.
func (mr *MockInvokableToolMockRecorder) Info(ctx any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Info", reflect.TypeOf((*MockInvokableTool)(nil).Info), ctx)
}
// PluginInvoke mocks base method.
func (m *MockInvokableTool) PluginInvoke(ctx context.Context, argumentsInJSON string, cfg plugin.ExecConfig) (string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "PluginInvoke", ctx, argumentsInJSON, cfg)
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// PluginInvoke indicates an expected call of PluginInvoke.
func (mr *MockInvokableToolMockRecorder) PluginInvoke(ctx, argumentsInJSON, cfg any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PluginInvoke", reflect.TypeOf((*MockInvokableTool)(nil).PluginInvoke), ctx, argumentsInJSON, cfg)
}

View File

@@ -16,6 +16,10 @@
package vo
import (
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
)
type Page struct {
Size int32 `json:"size"`
Page int32 `json:"page"`
@@ -51,17 +55,9 @@ type QueryToolInfoOption struct {
IDs []int64
}
type Locator uint8
const (
FromDraft Locator = iota
FromSpecificVersion
FromLatestVersion
)
type GetPolicy struct {
ID int64
QType Locator
QType model.Locator
MetaOnly bool
Version string
CommitID string
@@ -76,7 +72,7 @@ type DeletePolicy struct {
type MGetPolicy struct {
MetaQuery
QType Locator
QType model.Locator
MetaOnly bool
Versions map[int64]string
}

View File

@@ -1,67 +0,0 @@
/*
* 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 vo
type ExecuteConfig struct {
ID int64
From Locator
Version string
CommitID string
Operator int64
Mode ExecuteMode
AppID *int64
AgentID *int64
ConnectorID int64
ConnectorUID string
TaskType TaskType
SyncPattern SyncPattern
InputFailFast bool // whether to fail fast if input conversion has warnings
BizType BizType
Cancellable bool
}
type ExecuteMode string
const (
ExecuteModeDebug ExecuteMode = "debug"
ExecuteModeRelease ExecuteMode = "release"
ExecuteModeNodeDebug ExecuteMode = "node_debug"
)
type TaskType string
const (
TaskTypeForeground TaskType = "foreground"
TaskTypeBackground TaskType = "background"
)
type SyncPattern string
const (
SyncPatternSync SyncPattern = "sync"
SyncPatternAsync SyncPattern = "async"
SyncPatternStream SyncPattern = "stream"
)
var DebugURLTpl = "http://127.0.0.1:3000/work_flow?execute_id=%d&space_id=%d&workflow_id=%d&execute_mode=2"
type BizType string
const (
BizTypeAgent BizType = "agent"
BizTypeWorkflow BizType = "workflow"
)

View File

@@ -23,6 +23,7 @@ import (
"github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
"github.com/coze-dev/coze-studio/backend/pkg/sonic"
"github.com/coze-dev/coze-studio/backend/types/errno"
@@ -92,7 +93,7 @@ type wfErr struct {
func (w *wfErr) DebugURL() string {
if w.StatusError.Extra() == nil {
return fmt.Sprintf(DebugURLTpl, w.exeID, w.spaceID, w.workflowID)
return fmt.Sprintf(plugin.DebugURLTpl, w.exeID, w.spaceID, w.workflowID)
}
debugURL, ok := w.StatusError.Extra()["debug_url"]
@@ -100,7 +101,7 @@ func (w *wfErr) DebugURL() string {
return debugURL
}
return fmt.Sprintf(DebugURLTpl, w.exeID, w.spaceID, w.workflowID)
return fmt.Sprintf(plugin.DebugURLTpl, w.exeID, w.spaceID, w.workflowID)
}
func (w *wfErr) Level() ErrorLevel {
@@ -169,7 +170,7 @@ func WrapError(code int, err error, opts ...errorx.Option) WorkflowError {
}
func WrapWithDebug(code int, err error, exeID, spaceID, workflowID int64, opts ...errorx.Option) WorkflowError {
debugURL := fmt.Sprintf(DebugURLTpl, exeID, spaceID, workflowID)
debugURL := fmt.Sprintf(plugin.DebugURLTpl, exeID, spaceID, workflowID)
opts = append(opts, errorx.Extra("debug_url", debugURL))
return WrapError(code, err, opts...)
}

View File

@@ -1,43 +0,0 @@
/*
* 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 vo
type PluginEntity struct {
PluginID int64
PluginVersion *string // nil or "0" means draft, "" means latest/online version, otherwise is specific version
}
type DependenceResource struct {
PluginIDs []int64
KnowledgeIDs []int64
DatabaseIDs []int64
}
type ExternalResourceRelated struct {
PluginMap map[int64]*PluginEntity
PluginToolMap map[int64]int64
KnowledgeMap map[int64]int64
DatabaseMap map[int64]int64
}
type CopyWorkflowPolicy struct {
TargetSpaceID *int64
TargetAppID *int64
ModifiedCanvasSchema *string
ShouldModifyWorkflowName bool
}

View File

@@ -19,8 +19,8 @@ package entity
import (
"time"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
"github.com/coze-dev/coze-studio/backend/api/model/workflow"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
)
type WorkflowExecuteStatus workflow.WorkflowExeStatus
@@ -31,7 +31,7 @@ type WorkflowExecution struct {
WorkflowID int64
Version string
SpaceID int64
vo.ExecuteConfig
model.ExecuteConfig
CreatedAt time.Time
LogID string
NodeCount int32

View File

@@ -22,6 +22,7 @@ import (
"github.com/cloudwego/eino/components/model"
"github.com/cloudwego/eino/compose"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
"github.com/coze-dev/coze-studio/backend/api/model/workflow"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
@@ -38,7 +39,7 @@ type Service interface {
Delete(ctx context.Context, policy *vo.DeletePolicy) (err error)
Publish(ctx context.Context, policy *vo.PublishPolicy) (err error)
UpdateMeta(ctx context.Context, id int64, metaUpdate *vo.MetaUpdate) (err error)
CopyWorkflow(ctx context.Context, workflowID int64, policy vo.CopyWorkflowPolicy) (*entity.Workflow, error)
CopyWorkflow(ctx context.Context, workflowID int64, policy plugin.CopyWorkflowPolicy) (*entity.Workflow, error)
QueryNodeProperties(ctx context.Context, id int64) (map[string]*vo.NodeProperty, error) // only draft
ValidateTree(ctx context.Context, id int64, validateConfig vo.ValidateTreeConfig) ([]*workflow.ValidateTreeInfo, error)
@@ -49,10 +50,10 @@ type Service interface {
AsTool
ReleaseApplicationWorkflows(ctx context.Context, appID int64, config *vo.ReleaseWorkflowConfig) ([]*vo.ValidateIssue, error)
CopyWorkflowFromAppToLibrary(ctx context.Context, workflowID int64, appID int64, related vo.ExternalResourceRelated) (map[int64]entity.IDVersionPair, []*vo.ValidateIssue, error)
DuplicateWorkflowsByAppID(ctx context.Context, sourceAPPID, targetAppID int64, related vo.ExternalResourceRelated) error
GetWorkflowDependenceResource(ctx context.Context, workflowID int64) (*vo.DependenceResource, error)
SyncRelatedWorkflowResources(ctx context.Context, appID int64, relatedWorkflows map[int64]entity.IDVersionPair, related vo.ExternalResourceRelated) error
CopyWorkflowFromAppToLibrary(ctx context.Context, workflowID int64, appID int64, related plugin.ExternalResourceRelated) (map[int64]entity.IDVersionPair, []*vo.ValidateIssue, error)
DuplicateWorkflowsByAppID(ctx context.Context, sourceAPPID, targetAppID int64, related plugin.ExternalResourceRelated) error
GetWorkflowDependenceResource(ctx context.Context, workflowID int64) (*plugin.DependenceResource, error)
SyncRelatedWorkflowResources(ctx context.Context, appID int64, relatedWorkflows map[int64]entity.IDVersionPair, related plugin.ExternalResourceRelated) error
}
type Repository interface {
@@ -87,7 +88,7 @@ type Repository interface {
WorkflowAsTool(ctx context.Context, policy vo.GetPolicy, wfToolConfig vo.WorkflowToolConfig) (ToolFromWorkflow, error)
CopyWorkflow(ctx context.Context, workflowID int64, policy vo.CopyWorkflowPolicy) (*entity.Workflow, error)
CopyWorkflow(ctx context.Context, workflowID int64, policy plugin.CopyWorkflowPolicy) (*entity.Workflow, error)
GetDraftWorkflowsByAppID(ctx context.Context, AppID int64) (map[int64]*vo.DraftInfo, map[int64]string, error)

View File

@@ -34,17 +34,18 @@ import (
crossmodel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/database"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/knowledge"
"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"
crossknowledge "github.com/coze-dev/coze-studio/backend/crossdomain/contract/knowledge"
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/knowledge/knowledgemock"
crossmodelmgr "github.com/coze-dev/coze-studio/backend/crossdomain/contract/modelmgr"
mockmodel "github.com/coze-dev/coze-studio/backend/crossdomain/contract/modelmgr/modelmock"
crossplugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin"
"github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/pluginmock"
"github.com/coze-dev/coze-studio/backend/crossdomain/impl/code"
userentity "github.com/coze-dev/coze-studio/backend/domain/user/entity"
"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/crossdomain/plugin/pluginmock"
"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/execute"
@@ -76,10 +77,10 @@ func TestIntentDetectorAndDatabase(t *testing.T) {
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()
@@ -236,10 +237,10 @@ func TestDatabaseCURD(t *testing.T) {
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()
@@ -759,8 +760,8 @@ func TestCodeAndPluginNodes(t *testing.T) {
},
}, nil)
mockToolService := pluginmock.NewMockService(ctrl)
mockey.Mock(plugin.GetPluginService).Return(mockToolService).Build()
mockToolService := pluginmock.NewMockPluginService(ctrl)
mockey.Mock(crossplugin.DefaultSVC).Return(mockToolService).Build()
mockToolService.EXPECT().ExecutePlugin(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(),
gomock.Any()).Return(map[string]any{
"log_id": "20240617191637796DF3F4453E16AF3615",

View File

@@ -26,6 +26,7 @@ import (
einoCompose "github.com/cloudwego/eino/compose"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
"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/entity/vo"
@@ -337,7 +338,7 @@ func toSubWorkflowNodeSchema(ctx context.Context, n *vo.Node) (*schema.NodeSchem
subWF, err := workflow.GetRepository().GetEntity(ctx, &vo.GetPolicy{
ID: id,
QType: ternary.IFElse(len(version) == 0, vo.FromDraft, vo.FromSpecificVersion),
QType: ternary.IFElse(len(version) == 0, model.FromDraft, model.FromSpecificVersion),
Version: version,
})
if err != nil {

View File

@@ -25,8 +25,9 @@ import (
einoCompose "github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
crossplugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin"
workflow2 "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/execute"
@@ -242,9 +243,9 @@ func llmToolCallbackOptions(ctx context.Context, ns *schema2.NodeSchema, eventCh
if err != nil {
return nil, fmt.Errorf("invalid workflow id: %s", wfIDStr)
}
locator := vo.FromDraft
locator := model.FromDraft
if wf.WorkflowVersion != "" {
locator = vo.FromSpecificVersion
locator = model.FromSpecificVersion
}
wfTool, err := workflow2.GetRepository().WorkflowAsTool(ctx, vo.GetPolicy{
@@ -290,8 +291,8 @@ func llmToolCallbackOptions(ctx context.Context, ns *schema2.NodeSchema, eventCh
return nil, err
}
toolInfoResponse, err := plugin.GetPluginService().GetPluginToolsInfo(ctx, &plugin.ToolsInfoRequest{
PluginEntity: plugin.Entity{
toolInfoResponse, err := crossplugin.DefaultSVC().GetPluginToolsInfo(ctx, &model.ToolsInfoRequest{
PluginEntity: model.PluginEntity{
PluginID: pluginID,
PluginVersion: ptr.Of(p.PluginVersion),
},

View File

@@ -26,6 +26,7 @@ import (
"github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
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"
@@ -79,12 +80,12 @@ func init() {
_ = compose.RegisterSerializableType[*entity.WorkflowBasic]("workflow_basic")
_ = compose.RegisterSerializableType[vo.TerminatePlan]("terminate_plan")
_ = compose.RegisterSerializableType[*entity.ToolInterruptEvent]("tool_interrupt_event")
_ = compose.RegisterSerializableType[vo.ExecuteConfig]("execute_config")
_ = compose.RegisterSerializableType[vo.ExecuteMode]("execute_mode")
_ = compose.RegisterSerializableType[vo.TaskType]("task_type")
_ = compose.RegisterSerializableType[vo.SyncPattern]("sync_pattern")
_ = compose.RegisterSerializableType[vo.Locator]("wf_locator")
_ = compose.RegisterSerializableType[vo.BizType]("biz_type")
_ = compose.RegisterSerializableType[plugin.ExecuteConfig]("execute_config")
_ = compose.RegisterSerializableType[plugin.ExecuteMode]("execute_mode")
_ = compose.RegisterSerializableType[plugin.TaskType]("task_type")
_ = compose.RegisterSerializableType[plugin.SyncPattern]("sync_pattern")
_ = compose.RegisterSerializableType[plugin.Locator]("wf_locator")
_ = compose.RegisterSerializableType[plugin.BizType]("biz_type")
_ = compose.RegisterSerializableType[*execute.AppVariables]("app_variables")
}
@@ -905,12 +906,12 @@ func streamStatePostHandlerForVars(s *schema2.NodeSchema) compose.StreamStatePos
func GenStateModifierByEventType(e entity.InterruptEventType,
nodeKey vo.NodeKey,
resumeData string,
exeCfg vo.ExecuteConfig) (stateModifier compose.StateModifier) {
exeCfg plugin.ExecuteConfig) (stateModifier compose.StateModifier) {
// TODO: can we unify them all to a map[NodeKey]resumeData?
switch e {
case entity.InterruptEventInput:
stateModifier = func(ctx context.Context, path compose.NodePath, state any) (err error) {
if exeCfg.BizType == vo.BizTypeAgent {
if exeCfg.BizType == plugin.BizTypeAgent {
m := make(map[string]any)
sList := strings.Split(resumeData, "\n")
for _, s := range sList {

View File

@@ -26,6 +26,7 @@ import (
einoCompose "github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
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/entity/vo"
@@ -45,7 +46,7 @@ type WorkflowRunner struct {
resumeReq *entity.ResumeRequest
schema *schema2.WorkflowSchema
streamWriter *schema.StreamWriter[*entity.Message]
config vo.ExecuteConfig
config model.ExecuteConfig
executeID int64
eventChan chan *execute.Event
@@ -77,7 +78,7 @@ func WithStreamWriter(sw *schema.StreamWriter[*entity.Message]) WorkflowRunnerOp
}
}
func NewWorkflowRunner(b *entity.WorkflowBasic, sc *schema2.WorkflowSchema, config vo.ExecuteConfig, opts ...WorkflowRunnerOption) *WorkflowRunner {
func NewWorkflowRunner(b *entity.WorkflowBasic, sc *schema2.WorkflowSchema, config model.ExecuteConfig, opts ...WorkflowRunnerOption) *WorkflowRunner {
options := &workflowRunOptions{}
for _, opt := range opts {
opt(options)
@@ -262,7 +263,7 @@ func (r *WorkflowRunner) Prepare(ctx context.Context) (
cancelCtx, cancelFn := context.WithCancel(ctx)
var timeoutFn context.CancelFunc
if s := execute.GetStaticConfig(); s != nil {
timeout := ternary.IFElse(config.TaskType == vo.TaskTypeBackground, s.BackgroundRunTimeout, s.ForegroundRunTimeout)
timeout := ternary.IFElse(config.TaskType == model.TaskTypeBackground, s.BackgroundRunTimeout, s.ForegroundRunTimeout)
if timeout > 0 {
cancelCtx, timeoutFn = context.WithTimeout(cancelCtx, timeout)
}

View File

@@ -35,6 +35,7 @@ import (
"github.com/cloudwego/eino/schema"
callbacks2 "github.com/cloudwego/eino/utils/callbacks"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
workflow2 "github.com/coze-dev/coze-studio/backend/api/model/workflow"
"github.com/coze-dev/coze-studio/backend/domain/workflow"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
@@ -64,7 +65,7 @@ type WorkflowHandler struct {
nodeCount int32
requireCheckpoint bool
resumeEvent *entity.InterruptEvent
exeCfg vo.ExecuteConfig
exeCfg plugin.ExecuteConfig
rootTokenCollector *TokenCollector
}
@@ -74,7 +75,7 @@ type ToolHandler struct {
}
func NewRootWorkflowHandler(wb *entity.WorkflowBasic, executeID int64, requireCheckpoint bool,
ch chan<- *Event, resumedEvent *entity.InterruptEvent, exeCfg vo.ExecuteConfig, nodeCount int32,
ch chan<- *Event, resumedEvent *entity.InterruptEvent, exeCfg plugin.ExecuteConfig, nodeCount int32,
) callbacks.Handler {
return &WorkflowHandler{
ch: ch,

View File

@@ -28,6 +28,7 @@ import (
"github.com/cloudwego/eino/compose"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
"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/entity/vo"
@@ -58,7 +59,7 @@ type RootCtx struct {
RootWorkflowBasic *entity.WorkflowBasic
RootExecuteID int64
ResumeEvent *entity.InterruptEvent
ExeCfg vo.ExecuteConfig
ExeCfg plugin.ExecuteConfig
}
type SubWorkflowCtx struct {

View File

@@ -27,6 +27,7 @@ import (
"github.com/bytedance/sonic"
"github.com/cloudwego/eino/schema"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
"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/entity/vo"
@@ -63,7 +64,7 @@ func setRootWorkflowSuccess(ctx context.Context, event *Event, repo workflow.Rep
rootWkID := event.RootWorkflowBasic.ID
exeCfg := event.ExeCfg
if exeCfg.Mode == vo.ExecuteModeDebug {
if exeCfg.Mode == plugin.ExecuteModeDebug {
if err := repo.UpdateWorkflowDraftTestRunSuccess(ctx, rootWkID); err != nil {
return fmt.Errorf("failed to save workflow draft test run success: %v", err)
}
@@ -725,7 +726,7 @@ func HandleExecuteEvent(ctx context.Context,
timeoutFn context.CancelFunc,
repo workflow.Repository,
sw *schema.StreamWriter[*entity.Message],
exeCfg vo.ExecuteConfig,
exeCfg plugin.ExecuteConfig,
) (event *Event) {
var (
wfSuccessEvent *Event
@@ -760,7 +761,7 @@ func HandleExecuteEvent(ctx context.Context,
return event
case workflowSuccess: // workflow success, wait for exit node to be done
wfSuccessEvent = event
if lastNodeIsDone || exeCfg.Mode == vo.ExecuteModeNodeDebug {
if lastNodeIsDone || exeCfg.Mode == plugin.ExecuteModeNodeDebug {
if err = setRootWorkflowSuccess(ctx, wfSuccessEvent, repo, sw); err != nil {
logs.CtxErrorf(ctx, "failed to set root workflow success for workflow %d: %v",
wfSuccessEvent.RootWorkflowBasic.ID, err)

View File

@@ -21,14 +21,14 @@ import (
"github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
)
type workflowToolOption struct {
resumeReq *entity.ResumeRequest
sw *schema.StreamWriter[*entity.Message]
exeCfg vo.ExecuteConfig
exeCfg plugin.ExecuteConfig
allInterruptEvents map[string]*entity.ToolInterruptEvent
parentTokenCollector *TokenCollector
}
@@ -46,7 +46,7 @@ func WithIntermediateStreamWriter(sw *schema.StreamWriter[*entity.Message]) tool
})
}
func WithExecuteConfig(cfg vo.ExecuteConfig) tool.Option {
func WithExecuteConfig(cfg plugin.ExecuteConfig) tool.Option {
return tool.WrapImplSpecificOptFn(func(opts *workflowToolOption) {
opts.exeCfg = cfg
})
@@ -62,7 +62,7 @@ func GetIntermediateStreamWriter(opts ...tool.Option) *schema.StreamWriter[*enti
return opt.sw
}
func GetExecuteConfig(opts ...tool.Option) vo.ExecuteConfig {
func GetExecuteConfig(opts ...tool.Option) plugin.ExecuteConfig {
opt := tool.GetImplSpecificOptions(&workflowToolOption{}, opts...)
return opt.exeCfg
}

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)

View File

@@ -25,6 +25,7 @@ import (
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/api/model/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/repo/dal/model"
@@ -51,21 +52,21 @@ func (e *executeHistoryStoreImpl) CreateWorkflowExecution(ctx context.Context, e
}()
var mode int32
if execution.Mode == vo.ExecuteModeDebug {
if execution.Mode == plugin.ExecuteModeDebug {
mode = 1
} else if execution.Mode == vo.ExecuteModeRelease {
} else if execution.Mode == plugin.ExecuteModeRelease {
mode = 2
} else if execution.Mode == vo.ExecuteModeNodeDebug {
} else if execution.Mode == plugin.ExecuteModeNodeDebug {
mode = 3
}
var syncPattern int32
switch execution.SyncPattern {
case vo.SyncPatternSync:
case plugin.SyncPatternSync:
syncPattern = 1
case vo.SyncPatternAsync:
case plugin.SyncPatternAsync:
syncPattern = 2
case vo.SyncPatternStream:
case plugin.SyncPatternStream:
syncPattern = 3
default:
}
@@ -211,23 +212,23 @@ func (e *executeHistoryStoreImpl) GetWorkflowExecution(ctx context.Context, id i
}
rootExe := rootExes[0]
var exeMode vo.ExecuteMode
var exeMode plugin.ExecuteMode
if rootExe.Mode == 1 {
exeMode = vo.ExecuteModeDebug
exeMode = plugin.ExecuteModeDebug
} else if rootExe.Mode == 2 {
exeMode = vo.ExecuteModeRelease
exeMode = plugin.ExecuteModeRelease
} else {
exeMode = vo.ExecuteModeNodeDebug
exeMode = plugin.ExecuteModeNodeDebug
}
var syncPattern vo.SyncPattern
var syncPattern plugin.SyncPattern
switch rootExe.SyncPattern {
case 1:
syncPattern = vo.SyncPatternSync
syncPattern = plugin.SyncPatternSync
case 2:
syncPattern = vo.SyncPatternAsync
syncPattern = plugin.SyncPatternAsync
case 3:
syncPattern = vo.SyncPatternStream
syncPattern = plugin.SyncPatternStream
default:
}
@@ -236,7 +237,7 @@ func (e *executeHistoryStoreImpl) GetWorkflowExecution(ctx context.Context, id i
WorkflowID: rootExe.WorkflowID,
Version: rootExe.Version,
SpaceID: rootExe.SpaceID,
ExecuteConfig: vo.ExecuteConfig{
ExecuteConfig: plugin.ExecuteConfig{
Operator: rootExe.OperatorID,
Mode: exeMode,
AppID: ternary.IFElse(rootExe.AppID > 0, ptr.Of(rootExe.AppID), nil),

View File

@@ -30,6 +30,7 @@ import (
"gorm.io/gen/field"
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
workflow3 "github.com/coze-dev/coze-studio/backend/api/model/workflow"
"github.com/coze-dev/coze-studio/backend/application/base/ctxutil"
"github.com/coze-dev/coze-studio/backend/domain/workflow"
@@ -536,7 +537,7 @@ func (r *RepositoryImpl) GetEntity(ctx context.Context, policy *vo.GetPolicy) (_
commitID string
)
switch policy.QType {
case vo.FromDraft:
case plugin.FromDraft:
draft, err := r.DraftV2(ctx, policy.ID, policy.CommitID)
if err != nil {
return nil, err
@@ -547,7 +548,7 @@ func (r *RepositoryImpl) GetEntity(ctx context.Context, policy *vo.GetPolicy) (_
outputParams = draft.OutputParamsStr
draftMeta = draft.DraftMeta
commitID = draft.CommitID
case vo.FromSpecificVersion:
case plugin.FromSpecificVersion:
v, err := r.GetVersion(ctx, policy.ID, policy.Version)
if err != nil {
return nil, err
@@ -557,7 +558,7 @@ func (r *RepositoryImpl) GetEntity(ctx context.Context, policy *vo.GetPolicy) (_
outputParams = v.OutputParamsStr
versionMeta = v.VersionMeta
commitID = v.CommitID
case vo.FromLatestVersion:
case plugin.FromLatestVersion:
v, err := r.GetLatestVersion(ctx, policy.ID)
if err != nil {
return nil, err
@@ -1410,7 +1411,7 @@ func (r *RepositoryImpl) WorkflowAsTool(ctx context.Context, policy vo.GetPolicy
), nil
}
func (r *RepositoryImpl) CopyWorkflow(ctx context.Context, workflowID int64, policy vo.CopyWorkflowPolicy) (
func (r *RepositoryImpl) CopyWorkflow(ctx context.Context, workflowID int64, policy plugin.CopyWorkflowPolicy) (
_ *entity.Workflow, err error) {
const (
copyWorkflowRedisKeyPrefix = "copy_workflow_redis_key_prefix"

View File

@@ -22,6 +22,7 @@ import (
einoCompose "github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
"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/entity/vo"
@@ -36,7 +37,7 @@ func (a *asToolImpl) WithMessagePipe() (einoCompose.Option, *schema.StreamReader
return execute.WithMessagePipe()
}
func (a *asToolImpl) WithExecuteConfig(cfg vo.ExecuteConfig) einoCompose.Option {
func (a *asToolImpl) WithExecuteConfig(cfg plugin.ExecuteConfig) einoCompose.Option {
return einoCompose.WithToolsNodeOption(einoCompose.WithToolOption(execute.WithExecuteConfig(cfg)))
}

View File

@@ -25,6 +25,8 @@ import (
einoCompose "github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
"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/entity/vo"
@@ -44,7 +46,7 @@ type executableImpl struct {
repo workflow.Repository
}
func (i *impl) SyncExecute(ctx context.Context, config vo.ExecuteConfig, input map[string]any) (*entity.WorkflowExecution, vo.TerminatePlan, error) {
func (i *impl) SyncExecute(ctx context.Context, config model.ExecuteConfig, input map[string]any) (*entity.WorkflowExecution, vo.TerminatePlan, error) {
var (
err error
wfEntity *entity.Workflow
@@ -62,7 +64,7 @@ func (i *impl) SyncExecute(ctx context.Context, config vo.ExecuteConfig, input m
}
isApplicationWorkflow := wfEntity.AppID != nil
if isApplicationWorkflow && config.Mode == vo.ExecuteModeRelease {
if isApplicationWorkflow && config.Mode == model.ExecuteModeRelease {
err = i.checkApplicationWorkflowReleaseVersion(ctx, *wfEntity.AppID, config.ConnectorID, config.ID, config.Version)
if err != nil {
return nil, "", err
@@ -189,7 +191,7 @@ func (i *impl) SyncExecute(ctx context.Context, config vo.ExecuteConfig, input m
// AsyncExecute executes the specified workflow asynchronously, returning the execution ID.
// Intermediate results are not emitted on the fly.
// The caller is expected to poll the execution status using the GetExecution method and the returned execution ID.
func (i *impl) AsyncExecute(ctx context.Context, config vo.ExecuteConfig, input map[string]any) (int64, error) {
func (i *impl) AsyncExecute(ctx context.Context, config plugin.ExecuteConfig, input map[string]any) (int64, error) {
var (
err error
wfEntity *entity.Workflow
@@ -207,7 +209,7 @@ func (i *impl) AsyncExecute(ctx context.Context, config vo.ExecuteConfig, input
}
isApplicationWorkflow := wfEntity.AppID != nil
if isApplicationWorkflow && config.Mode == vo.ExecuteModeRelease {
if isApplicationWorkflow && config.Mode == plugin.ExecuteModeRelease {
err = i.checkApplicationWorkflowReleaseVersion(ctx, *wfEntity.AppID, config.ConnectorID, config.ID, config.Version)
if err != nil {
return 0, err
@@ -264,7 +266,7 @@ func (i *impl) AsyncExecute(ctx context.Context, config vo.ExecuteConfig, input
return 0, err
}
if config.Mode == vo.ExecuteModeDebug {
if config.Mode == plugin.ExecuteModeDebug {
if err = i.repo.SetTestRunLatestExeID(ctx, wfEntity.ID, config.Operator, executeID); err != nil {
logs.CtxErrorf(ctx, "failed to set test run latest exe id: %v", err)
}
@@ -275,7 +277,7 @@ func (i *impl) AsyncExecute(ctx context.Context, config vo.ExecuteConfig, input
return executeID, nil
}
func (i *impl) AsyncExecuteNode(ctx context.Context, nodeID string, config vo.ExecuteConfig, input map[string]any) (int64, error) {
func (i *impl) AsyncExecuteNode(ctx context.Context, nodeID string, config plugin.ExecuteConfig, input map[string]any) (int64, error) {
var (
err error
wfEntity *entity.Workflow
@@ -292,7 +294,7 @@ func (i *impl) AsyncExecuteNode(ctx context.Context, nodeID string, config vo.Ex
}
isApplicationWorkflow := wfEntity.AppID != nil
if isApplicationWorkflow && config.Mode == vo.ExecuteModeRelease {
if isApplicationWorkflow && config.Mode == plugin.ExecuteModeRelease {
err = i.checkApplicationWorkflowReleaseVersion(ctx, *wfEntity.AppID, config.ConnectorID, config.ID, config.Version)
if err != nil {
return 0, err
@@ -343,7 +345,7 @@ func (i *impl) AsyncExecuteNode(ctx context.Context, nodeID string, config vo.Ex
return 0, err
}
if config.Mode == vo.ExecuteModeNodeDebug {
if config.Mode == plugin.ExecuteModeNodeDebug {
if err = i.repo.SetNodeDebugLatestExeID(ctx, wfEntity.ID, nodeID, config.Operator, executeID); err != nil {
logs.CtxErrorf(ctx, "failed to set node debug latest exe id: %v", err)
}
@@ -356,7 +358,7 @@ func (i *impl) AsyncExecuteNode(ctx context.Context, nodeID string, config vo.Ex
// StreamExecute executes the specified workflow, returning a stream of execution events.
// The caller is expected to receive from the returned stream immediately.
func (i *impl) StreamExecute(ctx context.Context, config vo.ExecuteConfig, input map[string]any) (*schema.StreamReader[*entity.Message], error) {
func (i *impl) StreamExecute(ctx context.Context, config plugin.ExecuteConfig, input map[string]any) (*schema.StreamReader[*entity.Message], error) {
var (
err error
wfEntity *entity.Workflow
@@ -375,7 +377,7 @@ func (i *impl) StreamExecute(ctx context.Context, config vo.ExecuteConfig, input
}
isApplicationWorkflow := wfEntity.AppID != nil
if isApplicationWorkflow && config.Mode == vo.ExecuteModeRelease {
if isApplicationWorkflow && config.Mode == plugin.ExecuteModeRelease {
err = i.checkApplicationWorkflowReleaseVersion(ctx, *wfEntity.AppID, config.ConnectorID, config.ID, config.Version)
if err != nil {
return nil, err
@@ -545,7 +547,7 @@ func (i *impl) GetNodeExecution(ctx context.Context, exeID int64, nodeID string)
return nil, nil, fmt.Errorf("try getting workflow exe for exeID : %d, but not found", exeID)
}
if wfExe.Mode != vo.ExecuteModeNodeDebug {
if wfExe.Mode != plugin.ExecuteModeNodeDebug {
return nodeExe, nil, nil
}
@@ -671,7 +673,7 @@ func mergeCompositeInnerNodes(nodeExes map[int]*entity.NodeExecution, maxIndex i
// AsyncResume resumes a workflow execution asynchronously, using the passed in executionID and eventID.
// Intermediate results during the resuming run are not emitted on the fly.
// Caller is expected to poll the execution status using the GetExecution method.
func (i *impl) AsyncResume(ctx context.Context, req *entity.ResumeRequest, config vo.ExecuteConfig) error {
func (i *impl) AsyncResume(ctx context.Context, req *entity.ResumeRequest, config plugin.ExecuteConfig) error {
wfExe, found, err := i.repo.GetWorkflowExecution(ctx, req.ExecuteID)
if err != nil {
return err
@@ -689,11 +691,11 @@ func (i *impl) AsyncResume(ctx context.Context, req *entity.ResumeRequest, confi
return fmt.Errorf("workflow execution %d is not interrupted, status is %v, cannot resume", req.ExecuteID, wfExe.Status)
}
var from vo.Locator
var from plugin.Locator
if wfExe.Version == "" {
from = vo.FromDraft
from = plugin.FromDraft
} else {
from = vo.FromSpecificVersion
from = plugin.FromSpecificVersion
}
wfEntity, err := i.Get(ctx, &vo.GetPolicy{
@@ -722,7 +724,7 @@ func (i *impl) AsyncResume(ctx context.Context, req *entity.ResumeRequest, confi
config.ConnectorID = wfExe.ConnectorID
}
if wfExe.Mode == vo.ExecuteModeNodeDebug {
if wfExe.Mode == plugin.ExecuteModeNodeDebug {
nodeExes, err := i.repo.GetNodeExecutionsByWfExeID(ctx, wfExe.ID)
if err != nil {
return err
@@ -751,7 +753,7 @@ func (i *impl) AsyncResume(ctx context.Context, req *entity.ResumeRequest, confi
return fmt.Errorf("failed to create workflow: %w", err)
}
config.Mode = vo.ExecuteModeNodeDebug
config.Mode = plugin.ExecuteModeNodeDebug
cancelCtx, _, opts, _, err := compose.NewWorkflowRunner(
wfEntity.GetBasic(), workflowSC, config, compose.WithResumeReq(req)).Prepare(ctx)
@@ -793,7 +795,7 @@ func (i *impl) AsyncResume(ctx context.Context, req *entity.ResumeRequest, confi
// StreamResume resumes a workflow execution, using the passed in executionID and eventID.
// Intermediate results during the resuming run are emitted using the returned StreamReader.
// Caller is expected to poll the execution status using the GetExecution method.
func (i *impl) StreamResume(ctx context.Context, req *entity.ResumeRequest, config vo.ExecuteConfig) (
func (i *impl) StreamResume(ctx context.Context, req *entity.ResumeRequest, config plugin.ExecuteConfig) (
*schema.StreamReader[*entity.Message], error) {
// must get the interrupt event
// generate the state modifier
@@ -814,11 +816,11 @@ func (i *impl) StreamResume(ctx context.Context, req *entity.ResumeRequest, conf
return nil, fmt.Errorf("workflow execution %d is not interrupted, status is %v, cannot resume", req.ExecuteID, wfExe.Status)
}
var from vo.Locator
var from plugin.Locator
if wfExe.Version == "" {
from = vo.FromDraft
from = plugin.FromDraft
} else {
from = vo.FromSpecificVersion
from = plugin.FromSpecificVersion
}
wfEntity, err := i.Get(ctx, &vo.GetPolicy{

View File

@@ -30,6 +30,7 @@ import (
"golang.org/x/sync/errgroup"
"gorm.io/gorm"
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
cloudworkflow "github.com/coze-dev/coze-studio/backend/api/model/workflow"
"github.com/coze-dev/coze-studio/backend/application/base/ctxutil"
"github.com/coze-dev/coze-studio/backend/domain/workflow"
@@ -386,7 +387,7 @@ func (i *impl) ValidateTree(ctx context.Context, id int64, validateConfig vo.Val
MetaQuery: vo.MetaQuery{
IDs: ids,
},
QType: vo.FromDraft,
QType: plugin.FromDraft,
})
if err != nil {
return nil, err
@@ -719,7 +720,7 @@ func (i *impl) UpdateMeta(ctx context.Context, id int64, metaUpdate *vo.MetaUpda
return nil
}
func (i *impl) CopyWorkflow(ctx context.Context, workflowID int64, policy vo.CopyWorkflowPolicy) (*entity.Workflow, error) {
func (i *impl) CopyWorkflow(ctx context.Context, workflowID int64, policy plugin.CopyWorkflowPolicy) (*entity.Workflow, error) {
wf, err := i.repo.CopyWorkflow(ctx, workflowID, policy)
if err != nil {
return nil, err
@@ -754,13 +755,13 @@ func (i *impl) ReleaseApplicationWorkflows(ctx context.Context, appID int64, con
MetaQuery: vo.MetaQuery{
AppID: &appID,
},
QType: vo.FromDraft,
QType: plugin.FromDraft,
})
if err != nil {
return nil, err
}
relatedPlugins := make(map[int64]*vo.PluginEntity, len(config.PluginIDs))
relatedPlugins := make(map[int64]*plugin.PluginEntity, len(config.PluginIDs))
relatedWorkflow := make(map[int64]entity.IDVersionPair, len(wfs))
for _, wf := range wfs {
@@ -770,7 +771,7 @@ func (i *impl) ReleaseApplicationWorkflows(ctx context.Context, appID int64, con
}
}
for _, id := range config.PluginIDs {
relatedPlugins[id] = &vo.PluginEntity{
relatedPlugins[id] = &plugin.PluginEntity{
PluginID: id,
PluginVersion: &config.Version,
}
@@ -803,7 +804,7 @@ func (i *impl) ReleaseApplicationWorkflows(ctx context.Context, appID int64, con
return nil, err
}
err = replaceRelatedWorkflowOrExternalResourceInWorkflowNodes(c.Nodes, relatedWorkflow, vo.ExternalResourceRelated{
err = replaceRelatedWorkflowOrExternalResourceInWorkflowNodes(c.Nodes, relatedWorkflow, plugin.ExternalResourceRelated{
PluginMap: relatedPlugins,
})
@@ -870,7 +871,7 @@ func (i *impl) ReleaseApplicationWorkflows(ctx context.Context, appID int64, con
return nil, nil
}
func (i *impl) CopyWorkflowFromAppToLibrary(ctx context.Context, workflowID int64, appID int64, related vo.ExternalResourceRelated) (map[int64]entity.IDVersionPair, []*vo.ValidateIssue, error) {
func (i *impl) CopyWorkflowFromAppToLibrary(ctx context.Context, workflowID int64, appID int64, related plugin.ExternalResourceRelated) (map[int64]entity.IDVersionPair, []*vo.ValidateIssue, error) {
type copiedWorkflow struct {
id int64
@@ -1084,7 +1085,7 @@ func (i *impl) CopyWorkflowFromAppToLibrary(ctx context.Context, workflowID int6
return err
}
cwf, err := i.repo.CopyWorkflow(ctx, wf.id, vo.CopyWorkflowPolicy{
cwf, err := i.repo.CopyWorkflow(ctx, wf.id, plugin.CopyWorkflowPolicy{
TargetAppID: ptr.Of(int64(0)),
ModifiedCanvasSchema: ptr.Of(modifiedCanvasString),
})
@@ -1144,7 +1145,7 @@ func (i *impl) CopyWorkflowFromAppToLibrary(ctx context.Context, workflowID int6
}
func (i *impl) DuplicateWorkflowsByAppID(ctx context.Context, sourceAppID, targetAppID int64, related vo.ExternalResourceRelated) error {
func (i *impl) DuplicateWorkflowsByAppID(ctx context.Context, sourceAppID, targetAppID int64, related plugin.ExternalResourceRelated) error {
type copiedWorkflow struct {
id int64
@@ -1276,7 +1277,7 @@ func (i *impl) DuplicateWorkflowsByAppID(ctx context.Context, sourceAppID, targe
return err
}
cwf, err := i.CopyWorkflow(ctx, wf.id, vo.CopyWorkflowPolicy{
cwf, err := i.CopyWorkflow(ctx, wf.id, plugin.CopyWorkflowPolicy{
TargetAppID: ptr.Of(targetAppID),
ModifiedCanvasSchema: ptr.Of(modifiedCanvasString),
})
@@ -1331,7 +1332,7 @@ func (i *impl) DuplicateWorkflowsByAppID(ctx context.Context, sourceAppID, targe
}
func (i *impl) SyncRelatedWorkflowResources(ctx context.Context, appID int64, relatedWorkflows map[int64]entity.IDVersionPair, related vo.ExternalResourceRelated) error {
func (i *impl) SyncRelatedWorkflowResources(ctx context.Context, appID int64, relatedWorkflows map[int64]entity.IDVersionPair, related plugin.ExternalResourceRelated) error {
draftVersions, _, err := i.repo.GetDraftWorkflowsByAppID(ctx, appID)
if err != nil {
return err
@@ -1380,10 +1381,10 @@ func (i *impl) SyncRelatedWorkflowResources(ctx context.Context, appID int64, re
}
func (i *impl) GetWorkflowDependenceResource(ctx context.Context, workflowID int64) (*vo.DependenceResource, error) {
func (i *impl) GetWorkflowDependenceResource(ctx context.Context, workflowID int64) (*plugin.DependenceResource, error) {
wf, err := i.Get(ctx, &vo.GetPolicy{
ID: workflowID,
QType: vo.FromDraft,
QType: plugin.FromDraft,
})
if err != nil {
return nil, err
@@ -1394,7 +1395,7 @@ func (i *impl) GetWorkflowDependenceResource(ctx context.Context, workflowID int
return nil, err
}
ds := &vo.DependenceResource{
ds := &plugin.DependenceResource{
PluginIDs: make([]int64, 0),
KnowledgeIDs: make([]int64, 0),
DatabaseIDs: make([]int64, 0),
@@ -1483,7 +1484,7 @@ func (i *impl) GetWorkflowDependenceResource(ctx context.Context, workflowID int
subWorkflow, err := i.repo.GetEntity(ctx, &vo.GetPolicy{
ID: wfID,
QType: vo.FromDraft,
QType: plugin.FromDraft,
})
if err != nil {
return err
@@ -1558,9 +1559,9 @@ func (i *impl) MGet(ctx context.Context, policy *vo.MGetPolicy) ([]*entity.Workf
}
switch policy.QType {
case vo.FromDraft:
case plugin.FromDraft:
return i.repo.MGetDrafts(ctx, policy)
case vo.FromSpecificVersion:
case plugin.FromSpecificVersion:
if len(policy.IDs) == 0 || len(policy.Versions) != len(policy.IDs) {
return nil, 0, fmt.Errorf("ids and versions are required when MGet from specific versions")
}
@@ -1602,7 +1603,7 @@ func (i *impl) MGet(ctx context.Context, policy *vo.MGetPolicy) ([]*entity.Workf
}
return result, total, nil
case vo.FromLatestVersion:
case plugin.FromLatestVersion:
return i.repo.MGetLatestVersion(ctx, policy)
default:
panic("not implemented")
@@ -1637,7 +1638,7 @@ func (i *impl) calculateTestRunSuccess(ctx context.Context, c *vo.Canvas, wid in
return existedDraft.TestRunSuccess, nil // inherit previous draft snapshot's test run success flag
}
func replaceRelatedWorkflowOrExternalResourceInWorkflowNodes(nodes []*vo.Node, relatedWorkflows map[int64]entity.IDVersionPair, related vo.ExternalResourceRelated) error {
func replaceRelatedWorkflowOrExternalResourceInWorkflowNodes(nodes []*vo.Node, relatedWorkflows map[int64]entity.IDVersionPair, related plugin.ExternalResourceRelated) error {
var (
hasWorkflowRelated = len(relatedWorkflows) > 0
hasPluginRelated = len(related.PluginMap) > 0