refactor(workflow): Move domain resources events into the application layer (#729)
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/agentrun"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
crossplugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin"
|
||||
crossworkflow "github.com/coze-dev/coze-studio/backend/crossdomain/contract/workflow"
|
||||
pluginEntity "github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
@@ -88,7 +89,7 @@ func (pr *toolPreCallConf) toolPreRetrieve(ctx context.Context, ar *AgentRequest
|
||||
logs.CtxErrorf(ctx, "Failed to unmarshal json arguments: %s", item.Arguments)
|
||||
return nil, err
|
||||
}
|
||||
execResp, _, err := crossworkflow.DefaultSVC().SyncExecuteWorkflow(ctx, plugin.ExecuteConfig{
|
||||
execResp, _, err := crossworkflow.DefaultSVC().SyncExecuteWorkflow(ctx, workflowModel.ExecuteConfig{
|
||||
ID: item.PluginID,
|
||||
ConnectorID: ar.Identity.ConnectorID,
|
||||
ConnectorUID: ar.UserID,
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/app/bot_common"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
crossworkflow "github.com/coze-dev/coze-studio/backend/crossdomain/contract/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
@@ -37,7 +37,7 @@ func newWorkflowTools(ctx context.Context, conf *workflowConfig) ([]workflow.Too
|
||||
id := info.GetWorkflowId()
|
||||
policies = append(policies, &vo.GetPolicy{
|
||||
ID: id,
|
||||
QType: plugin.FromLatestVersion,
|
||||
QType: workflowModel.FromLatestVersion,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -23,18 +23,18 @@ import (
|
||||
"github.com/cloudwego/eino/compose"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
"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 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) (
|
||||
SyncExecute(ctx context.Context, config workflowModel.ExecuteConfig, input map[string]any) (*entity.WorkflowExecution, vo.TerminatePlan, error)
|
||||
AsyncExecute(ctx context.Context, config workflowModel.ExecuteConfig, input map[string]any) (int64, error)
|
||||
AsyncExecuteNode(ctx context.Context, nodeID string, config workflowModel.ExecuteConfig, input map[string]any) (int64, error)
|
||||
AsyncResume(ctx context.Context, req *entity.ResumeRequest, config workflowModel.ExecuteConfig) error
|
||||
StreamExecute(ctx context.Context, config workflowModel.ExecuteConfig, input map[string]any) (*schema.StreamReader[*entity.Message], error)
|
||||
StreamResume(ctx context.Context, req *entity.ResumeRequest, config workflowModel.ExecuteConfig) (
|
||||
*schema.StreamReader[*entity.Message], error)
|
||||
|
||||
GetExecution(ctx context.Context, wfExe *entity.WorkflowExecution, includeNodes bool) (*entity.WorkflowExecution, error)
|
||||
@@ -49,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 plugin.ExecuteConfig) compose.Option
|
||||
WithExecuteConfig(cfg workflowModel.ExecuteConfig) compose.Option
|
||||
WithResumeToolWorkflow(resumingEvent *entity.ToolInterruptEvent, resumeData string,
|
||||
allInterruptEvents map[string]*entity.ToolInterruptEvent) compose.Option
|
||||
}
|
||||
|
||||
@@ -1,66 +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 search
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type OpType string
|
||||
|
||||
const (
|
||||
Created OpType = "created"
|
||||
Updated OpType = "updated"
|
||||
Deleted OpType = "deleted"
|
||||
)
|
||||
|
||||
type PublishStatus int64
|
||||
|
||||
const (
|
||||
UnPublished PublishStatus = 1
|
||||
Published PublishStatus = 2
|
||||
)
|
||||
|
||||
type Resource struct {
|
||||
WorkflowID int64
|
||||
Name *string
|
||||
URI *string
|
||||
Desc *string
|
||||
APPID *int64
|
||||
SpaceID *int64
|
||||
OwnerID *int64
|
||||
PublishStatus *PublishStatus
|
||||
Mode *int32 // 0 workflow 3 chat_workflow
|
||||
CreatedAt *int64
|
||||
UpdatedAt *int64
|
||||
PublishedAt *int64
|
||||
}
|
||||
|
||||
func SetNotifier(n Notifier) {
|
||||
notifierImpl = n
|
||||
}
|
||||
|
||||
func GetNotifier() Notifier {
|
||||
return notifierImpl
|
||||
}
|
||||
|
||||
var notifierImpl Notifier
|
||||
|
||||
//go:generate mockgen -destination searchmock/search_mock.go --package searchmock -source search.go
|
||||
type Notifier interface {
|
||||
PublishWorkflowResource(ctx context.Context, OpType OpType, event *Resource) error
|
||||
}
|
||||
@@ -1,72 +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: search.go
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
// mockgen -destination searchmock/search_mock.go --package searchmock -source search.go
|
||||
//
|
||||
|
||||
// Package searchmock is a generated GoMock package.
|
||||
package searchmock
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
search "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/search"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockNotifier is a mock of Notifier interface.
|
||||
type MockNotifier struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockNotifierMockRecorder
|
||||
isgomock struct{}
|
||||
}
|
||||
|
||||
// MockNotifierMockRecorder is the mock recorder for MockNotifier.
|
||||
type MockNotifierMockRecorder struct {
|
||||
mock *MockNotifier
|
||||
}
|
||||
|
||||
// NewMockNotifier creates a new mock instance.
|
||||
func NewMockNotifier(ctrl *gomock.Controller) *MockNotifier {
|
||||
mock := &MockNotifier{ctrl: ctrl}
|
||||
mock.recorder = &MockNotifierMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockNotifier) EXPECT() *MockNotifierMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// PublishWorkflowResource mocks base method.
|
||||
func (m *MockNotifier) PublishWorkflowResource(ctx context.Context, OpType search.OpType, event *search.Resource) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "PublishWorkflowResource", ctx, OpType, event)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// PublishWorkflowResource indicates an expected call of PublishWorkflowResource.
|
||||
func (mr *MockNotifierMockRecorder) PublishWorkflowResource(ctx, OpType, event any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PublishWorkflowResource", reflect.TypeOf((*MockNotifier)(nil).PublishWorkflowResource), ctx, OpType, event)
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
package vo
|
||||
|
||||
import (
|
||||
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
)
|
||||
|
||||
type Page struct {
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"github.com/cloudwego/eino/compose"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
"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"
|
||||
@@ -93,7 +93,7 @@ type wfErr struct {
|
||||
|
||||
func (w *wfErr) DebugURL() string {
|
||||
if w.StatusError.Extra() == nil {
|
||||
return fmt.Sprintf(plugin.DebugURLTpl, w.exeID, w.spaceID, w.workflowID)
|
||||
return fmt.Sprintf(workflowModel.DebugURLTpl, w.exeID, w.spaceID, w.workflowID)
|
||||
}
|
||||
|
||||
debugURL, ok := w.StatusError.Extra()["debug_url"]
|
||||
@@ -101,7 +101,7 @@ func (w *wfErr) DebugURL() string {
|
||||
return debugURL
|
||||
}
|
||||
|
||||
return fmt.Sprintf(plugin.DebugURLTpl, w.exeID, w.spaceID, w.workflowID)
|
||||
return fmt.Sprintf(workflowModel.DebugURLTpl, w.exeID, w.spaceID, w.workflowID)
|
||||
}
|
||||
|
||||
func (w *wfErr) Level() ErrorLevel {
|
||||
@@ -170,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(plugin.DebugURLTpl, exeID, spaceID, workflowID)
|
||||
debugURL := fmt.Sprintf(workflowModel.DebugURLTpl, exeID, spaceID, workflowID)
|
||||
opts = append(opts, errorx.Extra("debug_url", debugURL))
|
||||
return WrapError(code, err, opts...)
|
||||
}
|
||||
|
||||
42
backend/domain/workflow/entity/vo/workflow_copy.go
Normal file
42
backend/domain/workflow/entity/vo/workflow_copy.go
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
import (
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
)
|
||||
|
||||
type ExternalResourceRelated struct {
|
||||
PluginMap map[int64]*plugin.PluginEntity
|
||||
PluginToolMap map[int64]int64
|
||||
|
||||
KnowledgeMap map[int64]int64
|
||||
DatabaseMap map[int64]int64
|
||||
}
|
||||
|
||||
type CopyWorkflowPolicy struct {
|
||||
TargetSpaceID *int64
|
||||
TargetAppID *int64
|
||||
ModifiedCanvasSchema *string
|
||||
ShouldModifyWorkflowName bool
|
||||
}
|
||||
|
||||
type DependenceResource struct {
|
||||
PluginIDs []int64
|
||||
KnowledgeIDs []int64
|
||||
DatabaseIDs []int64
|
||||
}
|
||||
@@ -76,3 +76,9 @@ type WorkflowBasic struct {
|
||||
AppID *int64
|
||||
CommitID string
|
||||
}
|
||||
|
||||
type CopyWorkflowFromAppToLibraryResult struct {
|
||||
WorkflowIDVersionMap map[int64]IDVersionPair
|
||||
ValidateIssues []*vo.ValidateIssue
|
||||
CopiedWorkflows []*Workflow
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package entity
|
||||
import (
|
||||
"time"
|
||||
|
||||
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/workflow"
|
||||
)
|
||||
|
||||
@@ -31,7 +31,7 @@ type WorkflowExecution struct {
|
||||
WorkflowID int64
|
||||
Version string
|
||||
SpaceID int64
|
||||
model.ExecuteConfig
|
||||
workflowModel.ExecuteConfig
|
||||
CreatedAt time.Time
|
||||
LogID string
|
||||
NodeCount int32
|
||||
|
||||
@@ -22,7 +22,6 @@ 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"
|
||||
@@ -36,10 +35,10 @@ type Service interface {
|
||||
Save(ctx context.Context, id int64, schema string) error
|
||||
Get(ctx context.Context, policy *vo.GetPolicy) (*entity.Workflow, error)
|
||||
MGet(ctx context.Context, policy *vo.MGetPolicy) ([]*entity.Workflow, int64, error)
|
||||
Delete(ctx context.Context, policy *vo.DeletePolicy) (err error)
|
||||
Delete(ctx context.Context, policy *vo.DeletePolicy) (ids []int64, 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 plugin.CopyWorkflowPolicy) (*entity.Workflow, error)
|
||||
CopyWorkflow(ctx context.Context, workflowID int64, policy vo.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)
|
||||
@@ -50,10 +49,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 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
|
||||
CopyWorkflowFromAppToLibrary(ctx context.Context, workflowID int64, appID int64, related vo.ExternalResourceRelated) (*entity.CopyWorkflowFromAppToLibraryResult, error)
|
||||
DuplicateWorkflowsByAppID(ctx context.Context, sourceAPPID, targetAppID int64, related vo.ExternalResourceRelated) ([]*entity.Workflow, 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
|
||||
}
|
||||
|
||||
type Repository interface {
|
||||
@@ -88,7 +87,7 @@ type Repository interface {
|
||||
|
||||
WorkflowAsTool(ctx context.Context, policy vo.GetPolicy, wfToolConfig vo.WorkflowToolConfig) (ToolFromWorkflow, error)
|
||||
|
||||
CopyWorkflow(ctx context.Context, workflowID int64, policy plugin.CopyWorkflowPolicy) (*entity.Workflow, error)
|
||||
CopyWorkflow(ctx context.Context, workflowID int64, policy vo.CopyWorkflowPolicy) (*entity.Workflow, error)
|
||||
|
||||
GetDraftWorkflowsByAppID(ctx context.Context, AppID int64) (map[int64]*vo.DraftInfo, map[int64]string, error)
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ 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"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
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"
|
||||
@@ -77,10 +77,10 @@ func TestIntentDetectorAndDatabase(t *testing.T) {
|
||||
|
||||
mockey.Mock(execute.GetExeCtx).Return(&execute.Context{
|
||||
RootCtx: execute.RootCtx{
|
||||
ExeCfg: plugin.ExecuteConfig{
|
||||
Mode: plugin.ExecuteModeDebug,
|
||||
ExeCfg: workflowModel.ExecuteConfig{
|
||||
Mode: workflowModel.ExecuteModeDebug,
|
||||
Operator: 123,
|
||||
BizType: plugin.BizTypeWorkflow,
|
||||
BizType: workflowModel.BizTypeWorkflow,
|
||||
},
|
||||
},
|
||||
}).Build()
|
||||
@@ -237,10 +237,10 @@ func TestDatabaseCURD(t *testing.T) {
|
||||
|
||||
mockey.Mock(execute.GetExeCtx).Return(&execute.Context{
|
||||
RootCtx: execute.RootCtx{
|
||||
ExeCfg: plugin.ExecuteConfig{
|
||||
Mode: plugin.ExecuteModeDebug,
|
||||
ExeCfg: workflowModel.ExecuteConfig{
|
||||
Mode: workflowModel.ExecuteModeDebug,
|
||||
Operator: 123,
|
||||
BizType: plugin.BizTypeWorkflow,
|
||||
BizType: workflowModel.BizTypeWorkflow,
|
||||
},
|
||||
},
|
||||
}).Build()
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
|
||||
einoCompose "github.com/cloudwego/eino/compose"
|
||||
|
||||
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
"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"
|
||||
|
||||
@@ -25,7 +25,8 @@ import (
|
||||
einoCompose "github.com/cloudwego/eino/compose"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
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/entity"
|
||||
@@ -291,8 +292,8 @@ func llmToolCallbackOptions(ctx context.Context, ns *schema2.NodeSchema, eventCh
|
||||
return nil, err
|
||||
}
|
||||
|
||||
toolInfoResponse, err := crossplugin.DefaultSVC().GetPluginToolsInfo(ctx, &model.ToolsInfoRequest{
|
||||
PluginEntity: model.PluginEntity{
|
||||
toolInfoResponse, err := crossplugin.DefaultSVC().GetPluginToolsInfo(ctx, &plugin.ToolsInfoRequest{
|
||||
PluginEntity: plugin.PluginEntity{
|
||||
PluginID: pluginID,
|
||||
PluginVersion: ptr.Of(p.PluginVersion),
|
||||
},
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
"github.com/cloudwego/eino/compose"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
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"
|
||||
@@ -80,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[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[workflowModel.ExecuteConfig]("execute_config")
|
||||
_ = compose.RegisterSerializableType[workflowModel.ExecuteMode]("execute_mode")
|
||||
_ = compose.RegisterSerializableType[workflowModel.TaskType]("task_type")
|
||||
_ = compose.RegisterSerializableType[workflowModel.SyncPattern]("sync_pattern")
|
||||
_ = compose.RegisterSerializableType[workflowModel.Locator]("wf_locator")
|
||||
_ = compose.RegisterSerializableType[workflowModel.BizType]("biz_type")
|
||||
_ = compose.RegisterSerializableType[*execute.AppVariables]("app_variables")
|
||||
}
|
||||
|
||||
@@ -906,12 +906,12 @@ func streamStatePostHandlerForVars(s *schema2.NodeSchema) compose.StreamStatePos
|
||||
func GenStateModifierByEventType(e entity.InterruptEventType,
|
||||
nodeKey vo.NodeKey,
|
||||
resumeData string,
|
||||
exeCfg plugin.ExecuteConfig) (stateModifier compose.StateModifier) {
|
||||
exeCfg workflowModel.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 == plugin.BizTypeAgent {
|
||||
if exeCfg.BizType == workflowModel.BizTypeAgent {
|
||||
m := make(map[string]any)
|
||||
sList := strings.Split(resumeData, "\n")
|
||||
for _, s := range sList {
|
||||
|
||||
@@ -26,7 +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"
|
||||
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
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"
|
||||
|
||||
@@ -35,7 +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"
|
||||
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"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
|
||||
@@ -65,7 +65,7 @@ type WorkflowHandler struct {
|
||||
nodeCount int32
|
||||
requireCheckpoint bool
|
||||
resumeEvent *entity.InterruptEvent
|
||||
exeCfg plugin.ExecuteConfig
|
||||
exeCfg workflowModel.ExecuteConfig
|
||||
rootTokenCollector *TokenCollector
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ type ToolHandler struct {
|
||||
}
|
||||
|
||||
func NewRootWorkflowHandler(wb *entity.WorkflowBasic, executeID int64, requireCheckpoint bool,
|
||||
ch chan<- *Event, resumedEvent *entity.InterruptEvent, exeCfg plugin.ExecuteConfig, nodeCount int32,
|
||||
ch chan<- *Event, resumedEvent *entity.InterruptEvent, exeCfg workflowModel.ExecuteConfig, nodeCount int32,
|
||||
) callbacks.Handler {
|
||||
return &WorkflowHandler{
|
||||
ch: ch,
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
|
||||
"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"
|
||||
"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"
|
||||
@@ -59,7 +59,7 @@ type RootCtx struct {
|
||||
RootWorkflowBasic *entity.WorkflowBasic
|
||||
RootExecuteID int64
|
||||
ResumeEvent *entity.InterruptEvent
|
||||
ExeCfg plugin.ExecuteConfig
|
||||
ExeCfg workflowModel.ExecuteConfig
|
||||
}
|
||||
|
||||
type SubWorkflowCtx struct {
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
"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"
|
||||
@@ -64,7 +64,7 @@ func setRootWorkflowSuccess(ctx context.Context, event *Event, repo workflow.Rep
|
||||
|
||||
rootWkID := event.RootWorkflowBasic.ID
|
||||
exeCfg := event.ExeCfg
|
||||
if exeCfg.Mode == plugin.ExecuteModeDebug {
|
||||
if exeCfg.Mode == workflowModel.ExecuteModeDebug {
|
||||
if err := repo.UpdateWorkflowDraftTestRunSuccess(ctx, rootWkID); err != nil {
|
||||
return fmt.Errorf("failed to save workflow draft test run success: %v", err)
|
||||
}
|
||||
@@ -726,7 +726,7 @@ func HandleExecuteEvent(ctx context.Context,
|
||||
timeoutFn context.CancelFunc,
|
||||
repo workflow.Repository,
|
||||
sw *schema.StreamWriter[*entity.Message],
|
||||
exeCfg plugin.ExecuteConfig,
|
||||
exeCfg workflowModel.ExecuteConfig,
|
||||
) (event *Event) {
|
||||
var (
|
||||
wfSuccessEvent *Event
|
||||
@@ -761,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 == plugin.ExecuteModeNodeDebug {
|
||||
if lastNodeIsDone || exeCfg.Mode == workflowModel.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)
|
||||
|
||||
@@ -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"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
|
||||
)
|
||||
|
||||
type workflowToolOption struct {
|
||||
resumeReq *entity.ResumeRequest
|
||||
sw *schema.StreamWriter[*entity.Message]
|
||||
exeCfg plugin.ExecuteConfig
|
||||
exeCfg workflowModel.ExecuteConfig
|
||||
allInterruptEvents map[string]*entity.ToolInterruptEvent
|
||||
parentTokenCollector *TokenCollector
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func WithIntermediateStreamWriter(sw *schema.StreamWriter[*entity.Message]) tool
|
||||
})
|
||||
}
|
||||
|
||||
func WithExecuteConfig(cfg plugin.ExecuteConfig) tool.Option {
|
||||
func WithExecuteConfig(cfg workflowModel.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) plugin.ExecuteConfig {
|
||||
func GetExecuteConfig(opts ...tool.Option) workflowModel.ExecuteConfig {
|
||||
opt := tool.GetImplSpecificOptions(&workflowToolOption{}, opts...)
|
||||
return opt.exeCfg
|
||||
}
|
||||
|
||||
@@ -26,7 +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"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
"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"
|
||||
@@ -413,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 == plugin.ExecuteModeDebug || execCtx.RootCtx.ExeCfg.Mode == plugin.ExecuteModeNodeDebug
|
||||
return execCtx.RootCtx.ExeCfg.Mode == workflowModel.ExecuteModeDebug || execCtx.RootCtx.ExeCfg.Mode == workflowModel.ExecuteModeNodeDebug
|
||||
}
|
||||
|
||||
func getExecUserID(ctx context.Context) string {
|
||||
|
||||
@@ -25,7 +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"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
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"
|
||||
@@ -72,10 +72,10 @@ func TestCustomSQL_Execute(t *testing.T) {
|
||||
|
||||
defer mockey.Mock(execute.GetExeCtx).Return(&execute.Context{
|
||||
RootCtx: execute.RootCtx{
|
||||
ExeCfg: plugin.ExecuteConfig{
|
||||
Mode: plugin.ExecuteModeDebug,
|
||||
ExeCfg: workflowModel.ExecuteConfig{
|
||||
Mode: workflowModel.ExecuteModeDebug,
|
||||
Operator: 123,
|
||||
BizType: plugin.BizTypeWorkflow,
|
||||
BizType: workflowModel.BizTypeWorkflow,
|
||||
},
|
||||
},
|
||||
}).Build().UnPatch()
|
||||
|
||||
@@ -27,7 +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"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
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"
|
||||
@@ -57,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: plugin.ExecuteConfig{
|
||||
Mode: plugin.ExecuteModeDebug,
|
||||
ExeCfg: workflowModel.ExecuteConfig{
|
||||
Mode: workflowModel.ExecuteModeDebug,
|
||||
Operator: 123,
|
||||
BizType: plugin.BizTypeWorkflow,
|
||||
BizType: workflowModel.BizTypeWorkflow,
|
||||
},
|
||||
},
|
||||
}).Build().UnPatch()
|
||||
|
||||
@@ -37,6 +37,7 @@ 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"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
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"
|
||||
@@ -401,9 +402,9 @@ func (c *Config) Build(ctx context.Context, ns *schema2.NodeSchema, _ ...schema2
|
||||
workflowToolConfig.OutputParametersConfig = wf.FCSetting.ResponseParameters
|
||||
}
|
||||
|
||||
locator := plugin.FromDraft
|
||||
locator := workflowModel.FromDraft
|
||||
if wf.WorkflowVersion != "" {
|
||||
locator = plugin.FromSpecificVersion
|
||||
locator = workflowModel.FromSpecificVersion
|
||||
}
|
||||
|
||||
wfTool, err := workflow.GetRepository().WorkflowAsTool(ctx, vo.GetPolicy{
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/cloudwego/eino/compose"
|
||||
|
||||
model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
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"
|
||||
@@ -111,7 +112,7 @@ type Plugin struct {
|
||||
}
|
||||
|
||||
func (p *Plugin) Invoke(ctx context.Context, parameters map[string]any) (ret map[string]any, err error) {
|
||||
var exeCfg model.ExecuteConfig
|
||||
var exeCfg workflowModel.ExecuteConfig
|
||||
if ctxExeCfg := execute.GetExeCtx(ctx); ctxExeCfg != nil {
|
||||
exeCfg = ctxExeCfg.ExeCfg
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
"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"
|
||||
@@ -52,21 +52,21 @@ func (e *executeHistoryStoreImpl) CreateWorkflowExecution(ctx context.Context, e
|
||||
}()
|
||||
|
||||
var mode int32
|
||||
if execution.Mode == plugin.ExecuteModeDebug {
|
||||
if execution.Mode == workflowModel.ExecuteModeDebug {
|
||||
mode = 1
|
||||
} else if execution.Mode == plugin.ExecuteModeRelease {
|
||||
} else if execution.Mode == workflowModel.ExecuteModeRelease {
|
||||
mode = 2
|
||||
} else if execution.Mode == plugin.ExecuteModeNodeDebug {
|
||||
} else if execution.Mode == workflowModel.ExecuteModeNodeDebug {
|
||||
mode = 3
|
||||
}
|
||||
|
||||
var syncPattern int32
|
||||
switch execution.SyncPattern {
|
||||
case plugin.SyncPatternSync:
|
||||
case workflowModel.SyncPatternSync:
|
||||
syncPattern = 1
|
||||
case plugin.SyncPatternAsync:
|
||||
case workflowModel.SyncPatternAsync:
|
||||
syncPattern = 2
|
||||
case plugin.SyncPatternStream:
|
||||
case workflowModel.SyncPatternStream:
|
||||
syncPattern = 3
|
||||
default:
|
||||
}
|
||||
@@ -212,23 +212,23 @@ func (e *executeHistoryStoreImpl) GetWorkflowExecution(ctx context.Context, id i
|
||||
}
|
||||
|
||||
rootExe := rootExes[0]
|
||||
var exeMode plugin.ExecuteMode
|
||||
var exeMode workflowModel.ExecuteMode
|
||||
if rootExe.Mode == 1 {
|
||||
exeMode = plugin.ExecuteModeDebug
|
||||
exeMode = workflowModel.ExecuteModeDebug
|
||||
} else if rootExe.Mode == 2 {
|
||||
exeMode = plugin.ExecuteModeRelease
|
||||
exeMode = workflowModel.ExecuteModeRelease
|
||||
} else {
|
||||
exeMode = plugin.ExecuteModeNodeDebug
|
||||
exeMode = workflowModel.ExecuteModeNodeDebug
|
||||
}
|
||||
|
||||
var syncPattern plugin.SyncPattern
|
||||
var syncPattern workflowModel.SyncPattern
|
||||
switch rootExe.SyncPattern {
|
||||
case 1:
|
||||
syncPattern = plugin.SyncPatternSync
|
||||
syncPattern = workflowModel.SyncPatternSync
|
||||
case 2:
|
||||
syncPattern = plugin.SyncPatternAsync
|
||||
syncPattern = workflowModel.SyncPatternAsync
|
||||
case 3:
|
||||
syncPattern = plugin.SyncPatternStream
|
||||
syncPattern = workflowModel.SyncPatternStream
|
||||
default:
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ func (e *executeHistoryStoreImpl) GetWorkflowExecution(ctx context.Context, id i
|
||||
WorkflowID: rootExe.WorkflowID,
|
||||
Version: rootExe.Version,
|
||||
SpaceID: rootExe.SpaceID,
|
||||
ExecuteConfig: plugin.ExecuteConfig{
|
||||
ExecuteConfig: workflowModel.ExecuteConfig{
|
||||
Operator: rootExe.OperatorID,
|
||||
Mode: exeMode,
|
||||
AppID: ternary.IFElse(rootExe.AppID > 0, ptr.Of(rootExe.AppID), nil),
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
"gorm.io/gen/field"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
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"
|
||||
@@ -537,7 +537,7 @@ func (r *RepositoryImpl) GetEntity(ctx context.Context, policy *vo.GetPolicy) (_
|
||||
commitID string
|
||||
)
|
||||
switch policy.QType {
|
||||
case plugin.FromDraft:
|
||||
case workflowModel.FromDraft:
|
||||
draft, err := r.DraftV2(ctx, policy.ID, policy.CommitID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -548,7 +548,7 @@ func (r *RepositoryImpl) GetEntity(ctx context.Context, policy *vo.GetPolicy) (_
|
||||
outputParams = draft.OutputParamsStr
|
||||
draftMeta = draft.DraftMeta
|
||||
commitID = draft.CommitID
|
||||
case plugin.FromSpecificVersion:
|
||||
case workflowModel.FromSpecificVersion:
|
||||
v, err := r.GetVersion(ctx, policy.ID, policy.Version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -558,7 +558,7 @@ func (r *RepositoryImpl) GetEntity(ctx context.Context, policy *vo.GetPolicy) (_
|
||||
outputParams = v.OutputParamsStr
|
||||
versionMeta = v.VersionMeta
|
||||
commitID = v.CommitID
|
||||
case plugin.FromLatestVersion:
|
||||
case workflowModel.FromLatestVersion:
|
||||
v, err := r.GetLatestVersion(ctx, policy.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1411,7 +1411,7 @@ func (r *RepositoryImpl) WorkflowAsTool(ctx context.Context, policy vo.GetPolicy
|
||||
), nil
|
||||
}
|
||||
|
||||
func (r *RepositoryImpl) CopyWorkflow(ctx context.Context, workflowID int64, policy plugin.CopyWorkflowPolicy) (
|
||||
func (r *RepositoryImpl) CopyWorkflow(ctx context.Context, workflowID int64, policy vo.CopyWorkflowPolicy) (
|
||||
_ *entity.Workflow, err error) {
|
||||
const (
|
||||
copyWorkflowRedisKeyPrefix = "copy_workflow_redis_key_prefix"
|
||||
|
||||
@@ -22,7 +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"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
"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"
|
||||
@@ -37,7 +37,7 @@ func (a *asToolImpl) WithMessagePipe() (einoCompose.Option, *schema.StreamReader
|
||||
return execute.WithMessagePipe()
|
||||
}
|
||||
|
||||
func (a *asToolImpl) WithExecuteConfig(cfg plugin.ExecuteConfig) einoCompose.Option {
|
||||
func (a *asToolImpl) WithExecuteConfig(cfg workflowModel.ExecuteConfig) einoCompose.Option {
|
||||
return einoCompose.WithToolsNodeOption(einoCompose.WithToolOption(execute.WithExecuteConfig(cfg)))
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,7 @@ 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"
|
||||
workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
|
||||
"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"
|
||||
@@ -46,7 +45,7 @@ type executableImpl struct {
|
||||
repo workflow.Repository
|
||||
}
|
||||
|
||||
func (i *impl) SyncExecute(ctx context.Context, config model.ExecuteConfig, input map[string]any) (*entity.WorkflowExecution, vo.TerminatePlan, error) {
|
||||
func (i *impl) SyncExecute(ctx context.Context, config workflowModel.ExecuteConfig, input map[string]any) (*entity.WorkflowExecution, vo.TerminatePlan, error) {
|
||||
var (
|
||||
err error
|
||||
wfEntity *entity.Workflow
|
||||
@@ -64,7 +63,7 @@ func (i *impl) SyncExecute(ctx context.Context, config model.ExecuteConfig, inpu
|
||||
}
|
||||
|
||||
isApplicationWorkflow := wfEntity.AppID != nil
|
||||
if isApplicationWorkflow && config.Mode == model.ExecuteModeRelease {
|
||||
if isApplicationWorkflow && config.Mode == workflowModel.ExecuteModeRelease {
|
||||
err = i.checkApplicationWorkflowReleaseVersion(ctx, *wfEntity.AppID, config.ConnectorID, config.ID, config.Version)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
@@ -191,7 +190,7 @@ func (i *impl) SyncExecute(ctx context.Context, config model.ExecuteConfig, inpu
|
||||
// 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 plugin.ExecuteConfig, input map[string]any) (int64, error) {
|
||||
func (i *impl) AsyncExecute(ctx context.Context, config workflowModel.ExecuteConfig, input map[string]any) (int64, error) {
|
||||
var (
|
||||
err error
|
||||
wfEntity *entity.Workflow
|
||||
@@ -209,7 +208,7 @@ func (i *impl) AsyncExecute(ctx context.Context, config plugin.ExecuteConfig, in
|
||||
}
|
||||
|
||||
isApplicationWorkflow := wfEntity.AppID != nil
|
||||
if isApplicationWorkflow && config.Mode == plugin.ExecuteModeRelease {
|
||||
if isApplicationWorkflow && config.Mode == workflowModel.ExecuteModeRelease {
|
||||
err = i.checkApplicationWorkflowReleaseVersion(ctx, *wfEntity.AppID, config.ConnectorID, config.ID, config.Version)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -266,7 +265,7 @@ func (i *impl) AsyncExecute(ctx context.Context, config plugin.ExecuteConfig, in
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if config.Mode == plugin.ExecuteModeDebug {
|
||||
if config.Mode == workflowModel.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)
|
||||
}
|
||||
@@ -277,7 +276,7 @@ func (i *impl) AsyncExecute(ctx context.Context, config plugin.ExecuteConfig, in
|
||||
return executeID, nil
|
||||
}
|
||||
|
||||
func (i *impl) AsyncExecuteNode(ctx context.Context, nodeID string, config plugin.ExecuteConfig, input map[string]any) (int64, error) {
|
||||
func (i *impl) AsyncExecuteNode(ctx context.Context, nodeID string, config workflowModel.ExecuteConfig, input map[string]any) (int64, error) {
|
||||
var (
|
||||
err error
|
||||
wfEntity *entity.Workflow
|
||||
@@ -294,7 +293,7 @@ func (i *impl) AsyncExecuteNode(ctx context.Context, nodeID string, config plugi
|
||||
}
|
||||
|
||||
isApplicationWorkflow := wfEntity.AppID != nil
|
||||
if isApplicationWorkflow && config.Mode == plugin.ExecuteModeRelease {
|
||||
if isApplicationWorkflow && config.Mode == workflowModel.ExecuteModeRelease {
|
||||
err = i.checkApplicationWorkflowReleaseVersion(ctx, *wfEntity.AppID, config.ConnectorID, config.ID, config.Version)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -345,7 +344,7 @@ func (i *impl) AsyncExecuteNode(ctx context.Context, nodeID string, config plugi
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if config.Mode == plugin.ExecuteModeNodeDebug {
|
||||
if config.Mode == workflowModel.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)
|
||||
}
|
||||
@@ -358,7 +357,7 @@ func (i *impl) AsyncExecuteNode(ctx context.Context, nodeID string, config plugi
|
||||
|
||||
// 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 plugin.ExecuteConfig, input map[string]any) (*schema.StreamReader[*entity.Message], error) {
|
||||
func (i *impl) StreamExecute(ctx context.Context, config workflowModel.ExecuteConfig, input map[string]any) (*schema.StreamReader[*entity.Message], error) {
|
||||
var (
|
||||
err error
|
||||
wfEntity *entity.Workflow
|
||||
@@ -377,7 +376,7 @@ func (i *impl) StreamExecute(ctx context.Context, config plugin.ExecuteConfig, i
|
||||
}
|
||||
|
||||
isApplicationWorkflow := wfEntity.AppID != nil
|
||||
if isApplicationWorkflow && config.Mode == plugin.ExecuteModeRelease {
|
||||
if isApplicationWorkflow && config.Mode == workflowModel.ExecuteModeRelease {
|
||||
err = i.checkApplicationWorkflowReleaseVersion(ctx, *wfEntity.AppID, config.ConnectorID, config.ID, config.Version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -547,7 +546,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 != plugin.ExecuteModeNodeDebug {
|
||||
if wfExe.Mode != workflowModel.ExecuteModeNodeDebug {
|
||||
return nodeExe, nil, nil
|
||||
}
|
||||
|
||||
@@ -673,7 +672,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 plugin.ExecuteConfig) error {
|
||||
func (i *impl) AsyncResume(ctx context.Context, req *entity.ResumeRequest, config workflowModel.ExecuteConfig) error {
|
||||
wfExe, found, err := i.repo.GetWorkflowExecution(ctx, req.ExecuteID)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -691,11 +690,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 plugin.Locator
|
||||
var from workflowModel.Locator
|
||||
if wfExe.Version == "" {
|
||||
from = plugin.FromDraft
|
||||
from = workflowModel.FromDraft
|
||||
} else {
|
||||
from = plugin.FromSpecificVersion
|
||||
from = workflowModel.FromSpecificVersion
|
||||
}
|
||||
|
||||
wfEntity, err := i.Get(ctx, &vo.GetPolicy{
|
||||
@@ -724,7 +723,7 @@ func (i *impl) AsyncResume(ctx context.Context, req *entity.ResumeRequest, confi
|
||||
config.ConnectorID = wfExe.ConnectorID
|
||||
}
|
||||
|
||||
if wfExe.Mode == plugin.ExecuteModeNodeDebug {
|
||||
if wfExe.Mode == workflowModel.ExecuteModeNodeDebug {
|
||||
nodeExes, err := i.repo.GetNodeExecutionsByWfExeID(ctx, wfExe.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -753,7 +752,7 @@ func (i *impl) AsyncResume(ctx context.Context, req *entity.ResumeRequest, confi
|
||||
return fmt.Errorf("failed to create workflow: %w", err)
|
||||
}
|
||||
|
||||
config.Mode = plugin.ExecuteModeNodeDebug
|
||||
config.Mode = workflowModel.ExecuteModeNodeDebug
|
||||
|
||||
cancelCtx, _, opts, _, err := compose.NewWorkflowRunner(
|
||||
wfEntity.GetBasic(), workflowSC, config, compose.WithResumeReq(req)).Prepare(ctx)
|
||||
@@ -795,7 +794,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 plugin.ExecuteConfig) (
|
||||
func (i *impl) StreamResume(ctx context.Context, req *entity.ResumeRequest, config workflowModel.ExecuteConfig) (
|
||||
*schema.StreamReader[*entity.Message], error) {
|
||||
// must get the interrupt event
|
||||
// generate the state modifier
|
||||
@@ -816,11 +815,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 plugin.Locator
|
||||
var from workflowModel.Locator
|
||||
if wfExe.Version == "" {
|
||||
from = plugin.FromDraft
|
||||
from = workflowModel.FromDraft
|
||||
} else {
|
||||
from = plugin.FromSpecificVersion
|
||||
from = workflowModel.FromSpecificVersion
|
||||
}
|
||||
|
||||
wfEntity, err := i.Get(ctx, &vo.GetPolicy{
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
einoCompose "github.com/cloudwego/eino/compose"
|
||||
|
||||
@@ -31,10 +30,10 @@ import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
"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"
|
||||
"github.com/coze-dev/coze-studio/backend/application/base/ctxutil"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/search"
|
||||
"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/adaptor"
|
||||
@@ -124,21 +123,6 @@ func (i *impl) Create(ctx context.Context, meta *vo.MetaCreate) (int64, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
err = search.GetNotifier().PublishWorkflowResource(ctx, search.Created, &search.Resource{
|
||||
WorkflowID: id,
|
||||
URI: &meta.IconURI,
|
||||
Name: &meta.Name,
|
||||
Desc: &meta.Desc,
|
||||
APPID: meta.AppID,
|
||||
SpaceID: &meta.SpaceID,
|
||||
OwnerID: &meta.CreatorID,
|
||||
Mode: ptr.Of(int32(meta.Mode)),
|
||||
PublishStatus: ptr.Of(search.UnPublished),
|
||||
CreatedAt: ptr.Of(time.Now().UnixMilli()),
|
||||
})
|
||||
if err != nil {
|
||||
return 0, vo.WrapError(errno.ErrNotifyWorkflowResourceChangeErr, err)
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
@@ -234,7 +218,7 @@ func extractInputsAndOutputsNamedInfoList(c *vo.Canvas) (inputs []*vo.NamedTypeI
|
||||
return inputs, outputs
|
||||
}
|
||||
|
||||
func (i *impl) Delete(ctx context.Context, policy *vo.DeletePolicy) (err error) {
|
||||
func (i *impl) Delete(ctx context.Context, policy *vo.DeletePolicy) (ids []int64, err error) {
|
||||
if policy.ID != nil || len(policy.IDs) == 1 {
|
||||
var id int64
|
||||
if policy.ID != nil {
|
||||
@@ -244,48 +228,28 @@ func (i *impl) Delete(ctx context.Context, policy *vo.DeletePolicy) (err error)
|
||||
}
|
||||
|
||||
if err = i.repo.Delete(ctx, id); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = search.GetNotifier().PublishWorkflowResource(ctx, search.Deleted, &search.Resource{
|
||||
WorkflowID: id,
|
||||
}); err != nil {
|
||||
return vo.WrapError(errno.ErrNotifyWorkflowResourceChangeErr, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
return []int64{id}, nil
|
||||
}
|
||||
|
||||
ids := policy.IDs
|
||||
ids = policy.IDs
|
||||
if policy.AppID != nil {
|
||||
metas, _, err := i.repo.MGetMetas(ctx, &vo.MetaQuery{
|
||||
AppID: policy.AppID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
ids = maps.Keys(metas)
|
||||
}
|
||||
|
||||
if err = i.repo.MDelete(ctx, ids); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
g := errgroup.Group{}
|
||||
for i := range ids {
|
||||
wid := ids[i]
|
||||
g.Go(func() error {
|
||||
return search.GetNotifier().PublishWorkflowResource(ctx, search.Deleted, &search.Resource{
|
||||
WorkflowID: wid,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if err = g.Wait(); err != nil {
|
||||
return vo.WrapError(errno.ErrNotifyWorkflowResourceChangeErr, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (i *impl) Get(ctx context.Context, policy *vo.GetPolicy) (*entity.Workflow, error) {
|
||||
@@ -387,7 +351,7 @@ func (i *impl) ValidateTree(ctx context.Context, id int64, validateConfig vo.Val
|
||||
MetaQuery: vo.MetaQuery{
|
||||
IDs: ids,
|
||||
},
|
||||
QType: plugin.FromDraft,
|
||||
QType: workflowModel.FromDraft,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -687,16 +651,6 @@ func (i *impl) Publish(ctx context.Context, policy *vo.PublishPolicy) (err error
|
||||
return err
|
||||
}
|
||||
|
||||
now := time.Now().UnixMilli()
|
||||
if err = search.GetNotifier().PublishWorkflowResource(ctx, search.Updated, &search.Resource{
|
||||
WorkflowID: policy.ID,
|
||||
PublishStatus: ptr.Of(search.Published),
|
||||
UpdatedAt: ptr.Of(now),
|
||||
PublishedAt: ptr.Of(now),
|
||||
}); err != nil {
|
||||
return vo.WrapError(errno.ErrNotifyWorkflowResourceChangeErr, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -706,42 +660,15 @@ func (i *impl) UpdateMeta(ctx context.Context, id int64, metaUpdate *vo.MetaUpda
|
||||
return err
|
||||
}
|
||||
|
||||
err = search.GetNotifier().PublishWorkflowResource(ctx, search.Updated, &search.Resource{
|
||||
WorkflowID: id,
|
||||
URI: metaUpdate.IconURI,
|
||||
Name: metaUpdate.Name,
|
||||
Desc: metaUpdate.Desc,
|
||||
UpdatedAt: ptr.Of(time.Now().UnixMilli()),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *impl) CopyWorkflow(ctx context.Context, workflowID int64, policy plugin.CopyWorkflowPolicy) (*entity.Workflow, error) {
|
||||
func (i *impl) CopyWorkflow(ctx context.Context, workflowID int64, policy vo.CopyWorkflowPolicy) (*entity.Workflow, error) {
|
||||
wf, err := i.repo.CopyWorkflow(ctx, workflowID, policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO(zhuangjie): publish workflow resource logic should move to application
|
||||
err = search.GetNotifier().PublishWorkflowResource(ctx, search.Created, &search.Resource{
|
||||
WorkflowID: wf.ID,
|
||||
URI: &wf.IconURI,
|
||||
Name: &wf.Name,
|
||||
Desc: &wf.Desc,
|
||||
APPID: wf.AppID,
|
||||
SpaceID: &wf.SpaceID,
|
||||
OwnerID: &wf.CreatorID,
|
||||
PublishStatus: ptr.Of(search.UnPublished),
|
||||
CreatedAt: ptr.Of(time.Now().UnixMilli()),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wf, nil
|
||||
|
||||
}
|
||||
@@ -755,7 +682,7 @@ func (i *impl) ReleaseApplicationWorkflows(ctx context.Context, appID int64, con
|
||||
MetaQuery: vo.MetaQuery{
|
||||
AppID: &appID,
|
||||
},
|
||||
QType: plugin.FromDraft,
|
||||
QType: workflowModel.FromDraft,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -804,7 +731,7 @@ func (i *impl) ReleaseApplicationWorkflows(ctx context.Context, appID int64, con
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = replaceRelatedWorkflowOrExternalResourceInWorkflowNodes(c.Nodes, relatedWorkflow, plugin.ExternalResourceRelated{
|
||||
err = replaceRelatedWorkflowOrExternalResourceInWorkflowNodes(c.Nodes, relatedWorkflow, vo.ExternalResourceRelated{
|
||||
PluginMap: relatedPlugins,
|
||||
})
|
||||
|
||||
@@ -871,8 +798,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 plugin.ExternalResourceRelated) (map[int64]entity.IDVersionPair, []*vo.ValidateIssue, error) {
|
||||
|
||||
func (i *impl) CopyWorkflowFromAppToLibrary(ctx context.Context, workflowID int64, appID int64, related vo.ExternalResourceRelated) (*entity.CopyWorkflowFromAppToLibraryResult, error) {
|
||||
type copiedWorkflow struct {
|
||||
id int64
|
||||
draftInfo *vo.DraftInfo
|
||||
@@ -887,7 +813,7 @@ func (i *impl) CopyWorkflowFromAppToLibrary(ctx context.Context, workflowID int6
|
||||
|
||||
draftVersion, err = i.repo.DraftV2(ctx, workflowID, "")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
issues, err := validateWorkflowTree(ctx, vo.ValidateTreeConfig{
|
||||
@@ -895,12 +821,12 @@ func (i *impl) CopyWorkflowFromAppToLibrary(ctx context.Context, workflowID int6
|
||||
AppID: ptr.Of(appID),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
draftWorkflows, wid2Named, err := i.repo.GetDraftWorkflowsByAppID(ctx, appID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(issues) > 0 {
|
||||
@@ -1039,22 +965,24 @@ func (i *impl) CopyWorkflowFromAppToLibrary(ctx context.Context, workflowID int6
|
||||
draftCanvas := &vo.Canvas{}
|
||||
err = sonic.UnmarshalString(draftVersion.Canvas, &draftCanvas)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = validateAndBuildWorkflowReference(draftCanvas.Nodes, copiedWf)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(vIssues) > 0 {
|
||||
return nil, vIssues, nil
|
||||
return &entity.CopyWorkflowFromAppToLibraryResult{
|
||||
ValidateIssues: vIssues,
|
||||
}, nil
|
||||
}
|
||||
|
||||
var copyAndPublishWorkflowProcess func(wf *copiedWorkflow) error
|
||||
|
||||
hasPublishedWorkflows := make(map[int64]entity.IDVersionPair)
|
||||
|
||||
copiedWorkflowArray := make([]*entity.Workflow, 0)
|
||||
copyAndPublishWorkflowProcess = func(wf *copiedWorkflow) error {
|
||||
for _, refWorkflow := range wf.refWfs {
|
||||
err := copyAndPublishWorkflowProcess(refWorkflow)
|
||||
@@ -1085,7 +1013,7 @@ func (i *impl) CopyWorkflowFromAppToLibrary(ctx context.Context, workflowID int6
|
||||
return err
|
||||
}
|
||||
|
||||
cwf, err := i.repo.CopyWorkflow(ctx, wf.id, plugin.CopyWorkflowPolicy{
|
||||
cwf, err := i.repo.CopyWorkflow(ctx, wf.id, vo.CopyWorkflowPolicy{
|
||||
TargetAppID: ptr.Of(int64(0)),
|
||||
ModifiedCanvasSchema: ptr.Of(modifiedCanvasString),
|
||||
})
|
||||
@@ -1114,19 +1042,7 @@ func (i *impl) CopyWorkflowFromAppToLibrary(ctx context.Context, workflowID int6
|
||||
return err
|
||||
}
|
||||
|
||||
err = search.GetNotifier().PublishWorkflowResource(ctx, search.Created, &search.Resource{
|
||||
WorkflowID: cwf.ID,
|
||||
URI: &cwf.IconURI,
|
||||
Name: &cwf.Name,
|
||||
Desc: &cwf.Desc,
|
||||
SpaceID: &cwf.SpaceID,
|
||||
OwnerID: &cwf.CreatorID,
|
||||
PublishStatus: ptr.Of(search.Published),
|
||||
CreatedAt: ptr.Of(time.Now().UnixMilli()),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
copiedWorkflowArray = append(copiedWorkflowArray, cwf)
|
||||
|
||||
hasPublishedWorkflows[wf.id] = entity.IDVersionPair{
|
||||
ID: cwf.ID,
|
||||
@@ -1138,14 +1054,17 @@ func (i *impl) CopyWorkflowFromAppToLibrary(ctx context.Context, workflowID int6
|
||||
|
||||
err = copyAndPublishWorkflowProcess(copiedWf)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return hasPublishedWorkflows, nil, nil
|
||||
return &entity.CopyWorkflowFromAppToLibraryResult{
|
||||
WorkflowIDVersionMap: hasPublishedWorkflows,
|
||||
CopiedWorkflows: copiedWorkflowArray,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (i *impl) DuplicateWorkflowsByAppID(ctx context.Context, sourceAppID, targetAppID int64, related plugin.ExternalResourceRelated) error {
|
||||
func (i *impl) DuplicateWorkflowsByAppID(ctx context.Context, sourceAppID, targetAppID int64, related vo.ExternalResourceRelated) ([]*entity.Workflow, error) {
|
||||
|
||||
type copiedWorkflow struct {
|
||||
id int64
|
||||
@@ -1157,7 +1076,7 @@ func (i *impl) DuplicateWorkflowsByAppID(ctx context.Context, sourceAppID, targe
|
||||
|
||||
draftWorkflows, _, err := i.repo.GetDraftWorkflowsByAppID(ctx, sourceAppID)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var duplicateWorkflowProcess func(workflowID int64, info *vo.DraftInfo) error
|
||||
@@ -1252,6 +1171,8 @@ func (i *impl) DuplicateWorkflowsByAppID(ctx context.Context, sourceAppID, targe
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
copiedWorkflowArray := make([]*entity.Workflow, 0)
|
||||
var duplicateWorkflow func(wf *copiedWorkflow) error
|
||||
duplicateWorkflow = func(wf *copiedWorkflow) error {
|
||||
for _, refWorkflow := range wf.refWfs {
|
||||
@@ -1277,7 +1198,7 @@ func (i *impl) DuplicateWorkflowsByAppID(ctx context.Context, sourceAppID, targe
|
||||
return err
|
||||
}
|
||||
|
||||
cwf, err := i.CopyWorkflow(ctx, wf.id, plugin.CopyWorkflowPolicy{
|
||||
cwf, err := i.CopyWorkflow(ctx, wf.id, vo.CopyWorkflowPolicy{
|
||||
TargetAppID: ptr.Of(targetAppID),
|
||||
ModifiedCanvasSchema: ptr.Of(modifiedCanvasString),
|
||||
})
|
||||
@@ -1285,9 +1206,7 @@ func (i *impl) DuplicateWorkflowsByAppID(ctx context.Context, sourceAppID, targe
|
||||
return err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
copiedWorkflowArray = append(copiedWorkflowArray, cwf)
|
||||
|
||||
hasCopiedWorkflows[wf.id] = entity.IDVersionPair{
|
||||
ID: cwf.ID,
|
||||
@@ -1324,15 +1243,15 @@ func (i *impl) DuplicateWorkflowsByAppID(ctx context.Context, sourceAppID, targe
|
||||
}
|
||||
err = duplicateWorkflowProcess(workflowID, draftVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return copiedWorkflowArray, nil
|
||||
|
||||
}
|
||||
|
||||
func (i *impl) SyncRelatedWorkflowResources(ctx context.Context, appID int64, relatedWorkflows map[int64]entity.IDVersionPair, related plugin.ExternalResourceRelated) error {
|
||||
func (i *impl) SyncRelatedWorkflowResources(ctx context.Context, appID int64, relatedWorkflows map[int64]entity.IDVersionPair, related vo.ExternalResourceRelated) error {
|
||||
draftVersions, _, err := i.repo.GetDraftWorkflowsByAppID(ctx, appID)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1381,10 +1300,10 @@ func (i *impl) SyncRelatedWorkflowResources(ctx context.Context, appID int64, re
|
||||
|
||||
}
|
||||
|
||||
func (i *impl) GetWorkflowDependenceResource(ctx context.Context, workflowID int64) (*plugin.DependenceResource, error) {
|
||||
func (i *impl) GetWorkflowDependenceResource(ctx context.Context, workflowID int64) (*vo.DependenceResource, error) {
|
||||
wf, err := i.Get(ctx, &vo.GetPolicy{
|
||||
ID: workflowID,
|
||||
QType: plugin.FromDraft,
|
||||
QType: workflowModel.FromDraft,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1395,7 +1314,7 @@ func (i *impl) GetWorkflowDependenceResource(ctx context.Context, workflowID int
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ds := &plugin.DependenceResource{
|
||||
ds := &vo.DependenceResource{
|
||||
PluginIDs: make([]int64, 0),
|
||||
KnowledgeIDs: make([]int64, 0),
|
||||
DatabaseIDs: make([]int64, 0),
|
||||
@@ -1486,7 +1405,7 @@ func (i *impl) GetWorkflowDependenceResource(ctx context.Context, workflowID int
|
||||
|
||||
wfe, err := i.repo.GetEntity(ctx, &vo.GetPolicy{
|
||||
ID: wID,
|
||||
QType: plugin.FromDraft,
|
||||
QType: workflowModel.FromDraft,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1517,7 +1436,7 @@ func (i *impl) GetWorkflowDependenceResource(ctx context.Context, workflowID int
|
||||
|
||||
subWorkflow, err := i.repo.GetEntity(ctx, &vo.GetPolicy{
|
||||
ID: wfID,
|
||||
QType: plugin.FromDraft,
|
||||
QType: workflowModel.FromDraft,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1593,9 +1512,9 @@ func (i *impl) MGet(ctx context.Context, policy *vo.MGetPolicy) ([]*entity.Workf
|
||||
}
|
||||
|
||||
switch policy.QType {
|
||||
case plugin.FromDraft:
|
||||
case workflowModel.FromDraft:
|
||||
return i.repo.MGetDrafts(ctx, policy)
|
||||
case plugin.FromSpecificVersion:
|
||||
case workflowModel.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")
|
||||
}
|
||||
@@ -1637,7 +1556,7 @@ func (i *impl) MGet(ctx context.Context, policy *vo.MGetPolicy) ([]*entity.Workf
|
||||
}
|
||||
|
||||
return result, total, nil
|
||||
case plugin.FromLatestVersion:
|
||||
case workflowModel.FromLatestVersion:
|
||||
return i.repo.MGetLatestVersion(ctx, policy)
|
||||
default:
|
||||
panic("not implemented")
|
||||
@@ -1672,7 +1591,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 plugin.ExternalResourceRelated) error {
|
||||
func replaceRelatedWorkflowOrExternalResourceInWorkflowNodes(nodes []*vo.Node, relatedWorkflows map[int64]entity.IDVersionPair, related vo.ExternalResourceRelated) error {
|
||||
var (
|
||||
hasWorkflowRelated = len(relatedWorkflows) > 0
|
||||
hasPluginRelated = len(related.PluginMap) > 0
|
||||
|
||||
Reference in New Issue
Block a user