refactor(workflow): Move domain resources events into the application layer (#729)

This commit is contained in:
Ryo
2025-08-13 21:06:56 +08:00
committed by GitHub
parent 8c3ae99643
commit 5d98e8ef93
47 changed files with 661 additions and 761 deletions

View File

@@ -22,8 +22,10 @@ import (
"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/workflow"
)
//go:generate mockgen -destination pluginmock/plugin_mock.go --package pluginmock -source plugin.go
type PluginService interface {
MGetVersionPlugins(ctx context.Context, versionPlugins []model.VersionPlugin) (plugins []*model.PluginInfo, err error)
MGetPluginLatestVersion(ctx context.Context, pluginIDs []int64) (resp *model.MGetPluginLatestVersionResponse, err error)
@@ -39,12 +41,12 @@ type PluginService interface {
MGetVersionTools(ctx context.Context, versionTools []model.VersionTool) (tools []*model.ToolInfo, err error)
GetPluginToolsInfo(ctx context.Context, req *model.ToolsInfoRequest) (*model.ToolsInfoResponse, error)
GetPluginInvokableTools(ctx context.Context, req *model.ToolsInvokableRequest) (map[int64]InvokableTool, error)
ExecutePlugin(ctx context.Context, input map[string]any, pe *model.PluginEntity, toolID int64, cfg model.ExecuteConfig) (map[string]any, error)
ExecutePlugin(ctx context.Context, input map[string]any, pe *model.PluginEntity, toolID int64, cfg workflow.ExecuteConfig) (map[string]any, error)
}
type InvokableTool interface {
Info(ctx context.Context) (*schema.ToolInfo, error)
PluginInvoke(ctx context.Context, argumentsInJSON string, cfg model.ExecuteConfig) (string, error)
PluginInvoke(ctx context.Context, argumentsInJSON string, cfg workflow.ExecuteConfig) (string, error)
}
var defaultSVC PluginService

View File

@@ -15,6 +15,7 @@ import (
schema "github.com/cloudwego/eino/schema"
plugin "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
workflow "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow"
plugin0 "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin"
gomock "go.uber.org/mock/gomock"
)
@@ -86,7 +87,7 @@ func (mr *MockPluginServiceMockRecorder) DuplicateDraftAgentTools(ctx, fromAgent
}
// ExecutePlugin mocks base method.
func (m *MockPluginService) ExecutePlugin(ctx context.Context, input map[string]any, pe *plugin.PluginEntity, toolID int64, cfg plugin.ExecuteConfig) (map[string]any, error) {
func (m *MockPluginService) ExecutePlugin(ctx context.Context, input map[string]any, pe *plugin.PluginEntity, toolID int64, cfg workflow.ExecuteConfig) (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)
@@ -308,7 +309,7 @@ func (mr *MockInvokableToolMockRecorder) Info(ctx any) *gomock.Call {
}
// PluginInvoke mocks base method.
func (m *MockInvokableTool) PluginInvoke(ctx context.Context, argumentsInJSON string, cfg plugin.ExecuteConfig) (string, error) {
func (m *MockInvokableTool) PluginInvoke(ctx context.Context, argumentsInJSON string, cfg workflow.ExecuteConfig) (string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "PluginInvoke", ctx, argumentsInJSON, cfg)
ret0, _ := ret[0].(string)

View File

@@ -23,29 +23,28 @@ import (
einoCompose "github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema"
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"
workflowEntity "github.com/coze-dev/coze-studio/backend/domain/workflow/entity"
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
)
// TODO (@fanlv): Parameter references need to be modified.
type Workflow interface {
WorkflowAsModelTool(ctx context.Context, policies []*vo.GetPolicy) ([]workflow.ToolFromWorkflow, error)
DeleteWorkflow(ctx context.Context, id int64) error
PublishWorkflow(ctx context.Context, info *vo.PublishPolicy) (err error)
WithResumeToolWorkflow(resumingEvent *workflowEntity.ToolInterruptEvent, resumeData string,
allInterruptEvents map[string]*workflowEntity.ToolInterruptEvent) einoCompose.Option
ReleaseApplicationWorkflows(ctx context.Context, appID int64, config *ReleaseWorkflowConfig) ([]*vo.ValidateIssue, error)
GetWorkflowIDsByAppID(ctx context.Context, appID int64) ([]int64, error)
SyncExecuteWorkflow(ctx context.Context, config model.ExecuteConfig, input map[string]any) (*workflowEntity.WorkflowExecution, vo.TerminatePlan, error)
WithExecuteConfig(cfg model.ExecuteConfig) einoCompose.Option
SyncExecuteWorkflow(ctx context.Context, config workflowModel.ExecuteConfig, input map[string]any) (*workflowEntity.WorkflowExecution, vo.TerminatePlan, error)
WithExecuteConfig(cfg workflowModel.ExecuteConfig) einoCompose.Option
WithMessagePipe() (compose.Option, *schema.StreamReader[*entity.Message])
}
type ExecuteConfig = model.ExecuteConfig
type ExecuteMode = model.ExecuteMode
type ExecuteConfig = workflowModel.ExecuteConfig
type ExecuteMode = workflowModel.ExecuteMode
type NodeType = entity.NodeType
type WorkflowMessage = entity.Message
@@ -60,14 +59,14 @@ const (
ExecuteModeNodeDebug ExecuteMode = "node_debug"
)
type TaskType = model.TaskType
type TaskType = workflowModel.TaskType
const (
TaskTypeForeground TaskType = "foreground"
TaskTypeBackground TaskType = "background"
)
type BizType = model.BizType
type BizType = workflowModel.BizType
const (
BizTypeAgent BizType = "agent"

View File

@@ -27,6 +27,7 @@ import (
"golang.org/x/exp/maps"
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/plugin_develop/common"
workflow3 "github.com/coze-dev/coze-studio/backend/api/model/workflow"
"github.com/coze-dev/coze-studio/backend/application/base/pluginutil"
@@ -341,7 +342,7 @@ func (s *impl) GetPluginInvokableTools(ctx context.Context, req *model.ToolsInvo
}
func (s *impl) ExecutePlugin(ctx context.Context, input map[string]any, pe *model.PluginEntity,
toolID int64, cfg model.ExecuteConfig) (map[string]any, error) {
toolID int64, cfg workflowModel.ExecuteConfig) (map[string]any, error) {
args, err := sonic.MarshalString(input)
if err != nil {
return nil, vo.WrapError(errno.ErrSerializationDeserializationFail, err)
@@ -447,7 +448,7 @@ func (p *pluginInvokeTool) Info(ctx context.Context) (_ *schema.ToolInfo, err er
}, nil
}
func (p *pluginInvokeTool) PluginInvoke(ctx context.Context, argumentsInJSON string, cfg model.ExecuteConfig) (string, error) {
func (p *pluginInvokeTool) PluginInvoke(ctx context.Context, argumentsInJSON string, cfg workflowModel.ExecuteConfig) (string, error) {
req := &service.ExecuteToolRequest{
UserID: conv.Int64ToStr(cfg.Operator),
PluginID: p.pluginEntity.PluginID,

View File

@@ -23,7 +23,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"
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"
@@ -51,16 +51,6 @@ func (i *impl) WorkflowAsModelTool(ctx context.Context, policies []*vo.GetPolicy
return i.DomainSVC.WorkflowAsModelTool(ctx, policies)
}
func (i *impl) PublishWorkflow(ctx context.Context, info *vo.PublishPolicy) (err error) {
return i.DomainSVC.Publish(ctx, info)
}
func (i *impl) DeleteWorkflow(ctx context.Context, id int64) error {
return i.DomainSVC.Delete(ctx, &vo.DeletePolicy{
ID: ptr.Of(id),
})
}
func (i *impl) ReleaseApplicationWorkflows(ctx context.Context, appID int64, config *vo.ReleaseWorkflowConfig) ([]*vo.ValidateIssue, error) {
return i.DomainSVC.ReleaseApplicationWorkflows(ctx, appID, config)
}
@@ -68,11 +58,11 @@ func (i *impl) ReleaseApplicationWorkflows(ctx context.Context, appID int64, con
func (i *impl) WithResumeToolWorkflow(resumingEvent *workflowEntity.ToolInterruptEvent, resumeData string, allInterruptEvents map[string]*workflowEntity.ToolInterruptEvent) einoCompose.Option {
return i.DomainSVC.WithResumeToolWorkflow(resumingEvent, resumeData, allInterruptEvents)
}
func (i *impl) SyncExecuteWorkflow(ctx context.Context, config model.ExecuteConfig, input map[string]any) (*workflowEntity.WorkflowExecution, vo.TerminatePlan, error) {
func (i *impl) SyncExecuteWorkflow(ctx context.Context, config workflowModel.ExecuteConfig, input map[string]any) (*workflowEntity.WorkflowExecution, vo.TerminatePlan, error) {
return i.DomainSVC.SyncExecute(ctx, config, input)
}
func (i *impl) WithExecuteConfig(cfg model.ExecuteConfig) einoCompose.Option {
func (i *impl) WithExecuteConfig(cfg workflowModel.ExecuteConfig) einoCompose.Option {
return i.DomainSVC.WithExecuteConfig(cfg)
}

View File

@@ -1,74 +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"
"github.com/coze-dev/coze-studio/backend/api/model/resource/common"
"github.com/coze-dev/coze-studio/backend/domain/search/entity"
search "github.com/coze-dev/coze-studio/backend/domain/search/service"
crosssearch "github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/search"
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
)
type Notifier interface {
PublishWorkflowResource(ctx context.Context, OpType crosssearch.OpType, event *crosssearch.Resource) error
}
type Notify struct {
client search.ResourceEventBus
}
func NewNotify(client search.ResourceEventBus) *Notify {
return &Notify{client: client}
}
func (n *Notify) PublishWorkflowResource(ctx context.Context, op crosssearch.OpType, r *crosssearch.Resource) error {
entityResource := &entity.ResourceDocument{
ResType: common.ResType_Workflow,
ResID: r.WorkflowID,
ResSubType: r.Mode,
Name: r.Name,
SpaceID: r.SpaceID,
OwnerID: r.OwnerID,
APPID: r.APPID,
}
if r.PublishStatus != nil {
publishStatus := *r.PublishStatus
entityResource.PublishStatus = ptr.Of(common.PublishStatus(publishStatus))
entityResource.PublishTimeMS = r.PublishedAt
}
resource := &entity.ResourceDomainEvent{
OpType: entity.OpType(op),
Resource: entityResource,
}
if op == crosssearch.Created {
resource.Resource.CreateTimeMS = r.CreatedAt
resource.Resource.UpdateTimeMS = r.UpdatedAt
} else if op == crosssearch.Updated {
resource.Resource.UpdateTimeMS = r.UpdatedAt
}
err := n.client.PublishResources(ctx, resource)
if err != nil {
return err
}
return nil
}