From ec15ac06fc4fb7ecfa6a39b3865342796343c195 Mon Sep 17 00:00:00 2001 From: Ryo Date: Tue, 23 Sep 2025 11:17:26 +0800 Subject: [PATCH] chore(plugin): move interface request to dto pkg (#2242) --- .../api/handler/coze/workflow_service_test.go | 28 +- .../crossdomain/singleagent/single_agent.go | 4 +- backend/application/app/app.go | 7 +- backend/application/base/pluginutil/api.go | 2 +- backend/application/plugin/plugin.go | 98 ++--- backend/application/singleagent/get.go | 33 +- .../application/singleagent/single_agent.go | 2 +- backend/application/workflow/workflow.go | 34 +- .../contract/plugin/dto}/consts.go | 2 +- .../contract/plugin/dto}/convert.go | 2 +- .../contract/plugin/dto}/openapi.go | 2 +- .../contract/plugin/dto}/option.go | 2 +- .../contract/plugin/dto}/plugin.go | 2 +- .../contract/plugin/dto}/plugin_manifest.go | 2 +- .../contract/plugin/dto}/toolinfo.go | 9 +- .../contract/plugin/dto}/workflow.go | 2 +- backend/crossdomain/contract/plugin/plugin.go | 2 +- .../contract/plugin/pluginmock/plugin_mock.go | 2 +- backend/crossdomain/impl/plugin/plugin.go | 6 +- .../agentflow/callback_reply_chunk.go | 2 +- .../internal/agentflow/node_tool_plugin.go | 33 +- .../agentflow/node_tool_pre_retriever.go | 20 +- backend/domain/app/service/publish_app.go | 2 +- backend/domain/plugin/conf/load_plugin.go | 2 +- .../model.go => domain/plugin/dto/auth.go} | 29 +- backend/domain/plugin/dto/plugin.go | 97 +++++ backend/domain/plugin/dto/plugin_author.go | 176 +++++++++ backend/domain/plugin/dto/tool.go | 73 ++++ backend/domain/plugin/entity/oauth.go | 2 +- backend/domain/plugin/entity/plugin.go | 2 +- .../dal/model/agent_tool_draft.gen.go | 22 +- .../dal/model/agent_tool_version.gen.go | 24 +- .../plugin/internal/dal/model/plugin.gen.go | 28 +- .../internal/dal/model/plugin_draft.gen.go | 26 +- .../dal/model/plugin_oauth_auth.gen.go | 2 +- .../internal/dal/model/plugin_version.gen.go | 30 +- .../plugin/internal/dal/model/tool.gen.go | 20 +- .../internal/dal/model/tool_draft.gen.go | 20 +- .../internal/dal/model/tool_version.gen.go | 20 +- backend/domain/plugin/internal/dal/plugin.go | 60 +-- .../plugin/internal/dal/plugin_draft.go | 2 +- .../plugin/internal/dal/plugin_version.go | 4 +- backend/domain/plugin/internal/dal/tool.go | 4 +- .../domain/plugin/internal/dal/tool_draft.go | 4 +- .../plugin/internal/encoder/req_encode.go | 2 +- .../internal/openapi/convert_protocol.go | 2 +- .../domain/plugin/repository/plugin_impl.go | 2 +- .../plugin/repository/plugin_repository.go | 2 +- backend/domain/plugin/service/agent_tool.go | 7 +- backend/domain/plugin/service/exec_tool.go | 18 +- .../domain/plugin/service/exec_tool_test.go | 2 +- backend/domain/plugin/service/plugin_draft.go | 45 +-- backend/domain/plugin/service/plugin_oauth.go | 13 +- .../domain/plugin/service/plugin_online.go | 17 +- .../domain/plugin/service/plugin_release.go | 8 +- backend/domain/plugin/service/service.go | 355 +----------------- .../plugin/service/tool/invocation_args.go | 2 +- .../plugin/service/tool/invocation_http.go | 2 +- .../workflow/entity/vo/workflow_copy.go | 2 +- .../internal/compose/designate_option.go | 2 +- .../domain/workflow/internal/nodes/llm/llm.go | 2 +- .../workflow/internal/nodes/plugin/plugin.go | 2 +- .../domain/workflow/service/service_impl.go | 2 +- backend/go.sum | 6 - .../internal/mock/domain/plugin/interface.go | 68 ++-- backend/types/ddl/gen_orm_query.go | 2 +- 66 files changed, 748 insertions(+), 760 deletions(-) rename backend/{api/model/crossdomain/plugin => crossdomain/contract/plugin/dto}/consts.go (99%) rename backend/{api/model/crossdomain/plugin => crossdomain/contract/plugin/dto}/convert.go (99%) rename backend/{api/model/crossdomain/plugin => crossdomain/contract/plugin/dto}/openapi.go (99%) rename backend/{api/model/crossdomain/plugin => crossdomain/contract/plugin/dto}/option.go (99%) rename backend/{api/model/crossdomain/plugin => crossdomain/contract/plugin/dto}/plugin.go (99%) rename backend/{api/model/crossdomain/plugin => crossdomain/contract/plugin/dto}/plugin_manifest.go (99%) rename backend/{api/model/crossdomain/plugin => crossdomain/contract/plugin/dto}/toolinfo.go (99%) rename backend/{api/model/crossdomain/plugin => crossdomain/contract/plugin/dto}/workflow.go (99%) rename backend/{application/plugin/model.go => domain/plugin/dto/auth.go} (56%) create mode 100644 backend/domain/plugin/dto/plugin.go create mode 100644 backend/domain/plugin/dto/plugin_author.go create mode 100644 backend/domain/plugin/dto/tool.go diff --git a/backend/api/handler/coze/workflow_service_test.go b/backend/api/handler/coze/workflow_service_test.go index 19d94f4d1..805da1eec 100644 --- a/backend/api/handler/coze/workflow_service_test.go +++ b/backend/api/handler/coze/workflow_service_test.go @@ -56,8 +56,6 @@ import ( modelknowledge "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/knowledge" "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/message" model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/modelmgr" - plugin2 "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" - pluginmodel "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/playground" pluginAPI "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop" @@ -81,6 +79,7 @@ import ( 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" + pluginmodel "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/pluginmock" crossuser "github.com/coze-dev/coze-studio/backend/crossdomain/contract/user" "github.com/coze-dev/coze-studio/backend/crossdomain/impl/code" @@ -90,6 +89,7 @@ import ( msgentity "github.com/coze-dev/coze-studio/backend/domain/conversation/message/entity" entity4 "github.com/coze-dev/coze-studio/backend/domain/memory/database/entity" entity2 "github.com/coze-dev/coze-studio/backend/domain/openauth/openapiauth/entity" + "github.com/coze-dev/coze-studio/backend/domain/plugin/dto" entity3 "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" entity5 "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" search "github.com/coze-dev/coze-studio/backend/domain/search/entity" @@ -2961,16 +2961,16 @@ func TestLLMWithSkills(t *testing.T) { } r.modelManage.EXPECT().GetModel(gomock.Any(), gomock.Any()).Return(utChatModel, nil, nil).AnyTimes() - r.plugin.EXPECT().ExecuteTool(gomock.Any(), gomock.Any(), gomock.Any()).Return(&plugin2.ExecuteToolResponse{ + r.plugin.EXPECT().ExecuteTool(gomock.Any(), gomock.Any(), gomock.Any()).Return(&pluginmodel.ExecuteToolResponse{ TrimmedResp: `{"data":"ok","err_msg":"error","data_structural":{"content":"ok","title":"title","weburl":"weburl"}}`, }, nil).AnyTimes() r.plugin.EXPECT().MGetOnlinePlugins(gomock.Any(), gomock.Any()).Return([]*entity3.PluginInfo{ - {PluginInfo: &plugin2.PluginInfo{ID: 7509353177339133952}}, + {PluginInfo: &pluginmodel.PluginInfo{ID: 7509353177339133952}}, }, nil).AnyTimes() r.plugin.EXPECT().MGetDraftPlugins(gomock.Any(), gomock.Any()).Return([]*entity3.PluginInfo{{ - PluginInfo: &plugin2.PluginInfo{ID: 7509353177339133952}, + PluginInfo: &pluginmodel.PluginInfo{ID: 7509353177339133952}, }}, nil).AnyTimes() operationString := `{ @@ -3041,7 +3041,7 @@ func TestLLMWithSkills(t *testing.T) { } }` - operation := &plugin2.Openapi3Operation{} + operation := &pluginmodel.Openapi3Operation{} _ = sonic.UnmarshalString(operationString, operation) r.plugin.EXPECT().MGetOnlineTools(gomock.Any(), gomock.Any()).Return([]*entity3.ToolInfo{ @@ -3569,7 +3569,7 @@ func TestGetLLMNodeFCSettingsDetailAndMerged(t *testing.T) { } } }` - operation := &plugin2.Openapi3Operation{} + operation := &pluginmodel.Openapi3Operation{} _ = sonic.UnmarshalString(operationString, operation) r := newWfTestRunner(t) @@ -3577,11 +3577,11 @@ func TestGetLLMNodeFCSettingsDetailAndMerged(t *testing.T) { r.plugin.EXPECT().MGetOnlinePlugins(gomock.Any(), gomock.Any()).Return([]*entity3.PluginInfo{ { - PluginInfo: &plugin2.PluginInfo{ + PluginInfo: &pluginmodel.PluginInfo{ ID: 123, SpaceID: 123, Version: ptr.Of("v0.0.1"), - Manifest: &plugin2.PluginManifest{NameForHuman: "p1", DescriptionForHuman: "desc"}, + Manifest: &pluginmodel.PluginManifest{NameForHuman: "p1", DescriptionForHuman: "desc"}, }, }, }, nil).AnyTimes() @@ -3687,18 +3687,18 @@ func TestGetLLMNodeFCSettingsDetailAndMerged(t *testing.T) { } }` - operation := &plugin2.Openapi3Operation{} + operation := &pluginmodel.Openapi3Operation{} _ = sonic.UnmarshalString(operationString, operation) r := newWfTestRunner(t) defer r.closeFn() r.plugin.EXPECT().MGetOnlinePlugins(gomock.Any(), gomock.Any()).Return([]*entity3.PluginInfo{ { - PluginInfo: &plugin2.PluginInfo{ + PluginInfo: &pluginmodel.PluginInfo{ ID: 123, SpaceID: 123, Version: ptr.Of("v0.0.1"), - Manifest: &plugin2.PluginManifest{NameForHuman: "p1", DescriptionForHuman: "desc"}, + Manifest: &pluginmodel.PluginManifest{NameForHuman: "p1", DescriptionForHuman: "desc"}, }, }, }, nil).AnyTimes() @@ -4347,7 +4347,7 @@ func TestCopyWorkflowAppToLibrary(t *testing.T) { defer mockey.Mock((*appmemory.DatabaseApplicationService).CopyDatabase).To(mockCopyDatabase).Build().UnPatch() - defer mockey.Mock((*appplugin.PluginApplicationService).CopyPlugin).Return(&appplugin.CopyPluginResponse{ + defer mockey.Mock((*appplugin.PluginApplicationService).CopyPlugin).Return(&dto.CopyPluginResponse{ Plugin: &entity5.PluginInfo{ PluginInfo: &pluginmodel.PluginInfo{ ID: 100100, @@ -4450,7 +4450,7 @@ func TestCopyWorkflowAppToLibrary(t *testing.T) { defer mockey.Mock((*appmemory.DatabaseApplicationService).CopyDatabase).To(mockCopyDatabase).Build().UnPatch() - defer mockey.Mock((*appplugin.PluginApplicationService).CopyPlugin).Return(&appplugin.CopyPluginResponse{ + defer mockey.Mock((*appplugin.PluginApplicationService).CopyPlugin).Return(&dto.CopyPluginResponse{ Plugin: &entity5.PluginInfo{ PluginInfo: &pluginmodel.PluginInfo{ ID: time.Now().Unix(), diff --git a/backend/api/model/crossdomain/singleagent/single_agent.go b/backend/api/model/crossdomain/singleagent/single_agent.go index fe754593e..8f363e2ef 100644 --- a/backend/api/model/crossdomain/singleagent/single_agent.go +++ b/backend/api/model/crossdomain/singleagent/single_agent.go @@ -22,7 +22,7 @@ import ( "github.com/coze-dev/coze-studio/backend/api/model/app/bot_common" "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/agentrun" - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" + plugindto "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" crossworkflow "github.com/coze-dev/coze-studio/backend/crossdomain/contract/workflow" ) @@ -95,7 +95,7 @@ const ( ) type InterruptInfo struct { - AllToolInterruptData map[string]*plugin.ToolInterruptEvent + AllToolInterruptData map[string]*plugindto.ToolInterruptEvent AllWfInterruptData map[string]*crossworkflow.ToolInterruptEvent ToolCallID string InterruptType InterruptEventType diff --git a/backend/application/app/app.go b/backend/application/app/app.go index dda64b082..afe8feef7 100644 --- a/backend/application/app/app.go +++ b/backend/application/app/app.go @@ -34,7 +34,6 @@ import ( taskAPI "github.com/coze-dev/coze-studio/backend/api/model/app/intelligence/task" connectorModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/connector" knowledgeModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/knowledge" - pluginModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" "github.com/coze-dev/coze-studio/backend/api/model/data/database/table" "github.com/coze-dev/coze-studio/backend/api/model/data/variable/project_memory" "github.com/coze-dev/coze-studio/backend/api/model/playground" @@ -46,11 +45,13 @@ import ( "github.com/coze-dev/coze-studio/backend/application/memory" "github.com/coze-dev/coze-studio/backend/application/plugin" "github.com/coze-dev/coze-studio/backend/application/workflow" + pluginModel "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/app/entity" "github.com/coze-dev/coze-studio/backend/domain/app/repository" "github.com/coze-dev/coze-studio/backend/domain/app/service" connector "github.com/coze-dev/coze-studio/backend/domain/connector/service" variables "github.com/coze-dev/coze-studio/backend/domain/memory/variables/service" + "github.com/coze-dev/coze-studio/backend/domain/plugin/dto" searchEntity "github.com/coze-dev/coze-studio/backend/domain/search/entity" search "github.com/coze-dev/coze-studio/backend/domain/search/service" user "github.com/coze-dev/coze-studio/backend/domain/user/service" @@ -790,7 +791,7 @@ func pluginCopyDispatchHandler(ctx context.Context, metaInfo *copyMetaInfo, res } } -func copyPlugin(ctx context.Context, metaInfo *copyMetaInfo, res *entity.Resource) (resp *plugin.CopyPluginResponse, err error) { +func copyPlugin(ctx context.Context, metaInfo *copyMetaInfo, res *entity.Resource) (resp *dto.CopyPluginResponse, err error) { var copyScene pluginModel.CopyScene switch metaInfo.scene { case resourceCommon.ResourceCopyScene_CopyProjectResource: @@ -805,7 +806,7 @@ func copyPlugin(ctx context.Context, metaInfo *copyMetaInfo, res *entity.Resourc return nil, fmt.Errorf("unsupported copy scene '%s'", metaInfo.scene) } - resp, err = plugin.PluginApplicationSVC.CopyPlugin(ctx, &plugin.CopyPluginRequest{ + resp, err = plugin.PluginApplicationSVC.CopyPlugin(ctx, &dto.CopyPluginRequest{ CopyScene: copyScene, PluginID: res.ResID, UserID: metaInfo.userID, diff --git a/backend/application/base/pluginutil/api.go b/backend/application/base/pluginutil/api.go index 300709187..d39152d9d 100644 --- a/backend/application/base/pluginutil/api.go +++ b/backend/application/base/pluginutil/api.go @@ -24,8 +24,8 @@ import ( "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + plugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/pkg/errorx" "github.com/coze-dev/coze-studio/backend/types/errno" ) diff --git a/backend/application/plugin/plugin.go b/backend/application/plugin/plugin.go index 2cdae72ac..4819c49df 100644 --- a/backend/application/plugin/plugin.go +++ b/backend/application/plugin/plugin.go @@ -34,8 +34,6 @@ import ( "gopkg.in/yaml.v3" botOpenAPI "github.com/coze-dev/coze-studio/backend/api/model/app/bot_open_api" - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" - searchModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/search" productCommon "github.com/coze-dev/coze-studio/backend/api/model/marketplace/product_common" productAPI "github.com/coze-dev/coze-studio/backend/api/model/marketplace/product_public_api" pluginAPI "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop" @@ -43,8 +41,9 @@ import ( resCommon "github.com/coze-dev/coze-studio/backend/api/model/resource/common" "github.com/coze-dev/coze-studio/backend/application/base/ctxutil" "github.com/coze-dev/coze-studio/backend/application/base/pluginutil" - crosssearch "github.com/coze-dev/coze-studio/backend/crossdomain/contract/search" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" pluginConf "github.com/coze-dev/coze-studio/backend/domain/plugin/conf" + "github.com/coze-dev/coze-studio/backend/domain/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/encrypt" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/domain/plugin/repository" @@ -91,6 +90,10 @@ func (p *PluginApplicationService) GetPlaygroundPluginList(ctx context.Context, plugins, total, err = p.getPlaygroundPluginList(ctx, req) } + if err != nil { + return nil, errorx.Wrapf(err, "getPlaygroundPluginList failed, req=%v", req) + } + pluginList := make([]*common.PluginInfoForPlayground, 0, len(plugins)) for _, pl := range plugins { tools, err := p.toolRepo.GetPluginAllOnlineTools(ctx, pl.ID) @@ -257,7 +260,7 @@ func (p *PluginApplicationService) RegisterPluginMeta(ctx context.Context, req * } } - r := &service.CreateDraftPluginRequest{ + r := &dto.CreateDraftPluginRequest{ PluginType: req.GetPluginType(), SpaceID: req.GetSpaceID(), DeveloperID: *userID, @@ -267,7 +270,7 @@ func (p *PluginApplicationService) RegisterPluginMeta(ctx context.Context, req * Desc: req.GetDesc(), ServerURL: req.GetURL(), CommonParams: req.CommonParams, - AuthInfo: &service.PluginAuthInfo{ + AuthInfo: &dto.PluginAuthInfo{ AuthzType: authType, Location: ptr.Of(loc), Key: req.Key, @@ -326,7 +329,7 @@ func (p *PluginApplicationService) RegisterPlugin(ctx context.Context, req *plug return nil, errorx.New(errno.ErrPluginInvalidOpenapi3Doc, errorx.KV(errno.PluginMsgKey, err.Error())) } - res, err := p.DomainSVC.CreateDraftPluginWithCode(ctx, &service.CreateDraftPluginWithCodeRequest{ + res, err := p.DomainSVC.CreateDraftPluginWithCode(ctx, &dto.CreateDraftPluginWithCodeRequest{ SpaceID: req.GetSpaceID(), DeveloperID: *userID, ProjectID: req.ProjectID, @@ -823,7 +826,7 @@ func (p *PluginApplicationService) UpdateAPI(ctx context.Context, req *pluginAPI method = &m } - updateReq := &service.UpdateDraftToolRequest{ + updateReq := &dto.UpdateDraftToolRequest{ PluginID: req.PluginID, ToolID: req.APIID, Name: req.Name, @@ -882,7 +885,7 @@ func (p *PluginApplicationService) UpdatePlugin(ctx context.Context, req *plugin return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KV(errno.PluginMsgKey, err.Error())) } - err = p.DomainSVC.UpdateDraftPluginWithCode(ctx, &service.UpdateDraftPluginWithCodeRequest{ + err = p.DomainSVC.UpdateDraftPluginWithCode(ctx, &dto.UpdateDraftPluginWithCodeRequest{ UserID: *userID, PluginID: req.PluginID, OpenapiDoc: doc, @@ -964,7 +967,7 @@ func (p *PluginApplicationService) PublishPlugin(ctx context.Context, req *plugi return nil, errorx.Wrapf(err, "validatePublishPluginRequest failed") } - err = p.DomainSVC.PublishPlugin(ctx, &service.PublishPluginRequest{ + err = p.DomainSVC.PublishPlugin(ctx, &model.PublishPluginRequest{ PluginID: req.PluginID, Version: req.VersionName, VersionDesc: req.VersionDesc, @@ -1002,7 +1005,7 @@ func (p *PluginApplicationService) UpdatePluginMeta(ctx context.Context, req *pl return nil, err } - updateReq := &service.UpdateDraftPluginRequest{ + updateReq := &dto.UpdateDraftPluginRequest{ PluginID: req.PluginID, Name: req.Name, Desc: req.Desc, @@ -1034,7 +1037,7 @@ func (p *PluginApplicationService) UpdatePluginMeta(ctx context.Context, req *pl return resp, nil } -func getUpdateAuthInfo(ctx context.Context, req *pluginAPI.UpdatePluginMetaRequest) (authInfo *service.PluginAuthInfo, err error) { +func getUpdateAuthInfo(ctx context.Context, req *pluginAPI.UpdatePluginMetaRequest) (authInfo *dto.PluginAuthInfo, err error) { if req.AuthType == nil { return nil, nil } @@ -1065,7 +1068,7 @@ func getUpdateAuthInfo(ctx context.Context, req *pluginAPI.UpdatePluginMetaReque } } - authInfo = &service.PluginAuthInfo{ + authInfo = &dto.PluginAuthInfo{ AuthzType: authType, Location: location, Key: req.Key, @@ -1115,7 +1118,7 @@ func (p *PluginApplicationService) UpdateBotDefaultParams(ctx context.Context, r return nil, err } - err = p.DomainSVC.UpdateBotDefaultParams(ctx, &service.UpdateBotDefaultParamsRequest{ + err = p.DomainSVC.UpdateBotDefaultParams(ctx, &dto.UpdateBotDefaultParamsRequest{ PluginID: req.PluginID, ToolName: req.APIName, AgentID: req.BotID, @@ -1162,7 +1165,7 @@ func (p *PluginApplicationService) DebugAPI(ctx context.Context, req *pluginAPI. ) } - res, err := p.DomainSVC.ExecuteTool(ctx, &service.ExecuteToolRequest{ + res, err := p.DomainSVC.ExecuteTool(ctx, &model.ExecuteToolRequest{ UserID: conv.Int64ToStr(*userID), PluginID: req.PluginID, ToolID: req.APIID, @@ -1215,7 +1218,7 @@ func (p *PluginApplicationService) UnlockPluginEdit(ctx context.Context, req *pl } func (p *PluginApplicationService) PublicGetProductList(ctx context.Context, req *productAPI.GetProductListRequest) (resp *productAPI.GetProductListResponse, err error) { - res, err := p.DomainSVC.ListPluginProducts(ctx, &service.ListPluginProductsRequest{}) + res, err := p.DomainSVC.ListPluginProducts(ctx, &dto.ListPluginProductsRequest{}) if err != nil { return nil, errorx.Wrapf(err, "ListPluginProducts failed") } @@ -1416,7 +1419,7 @@ func (p *PluginApplicationService) GetDevPluginList(ctx context.Context, req *pl pageInfo.SortBy = ptr.Of(entity.SortByCreatedAt) } - res, err := p.DomainSVC.ListDraftPlugins(ctx, &service.ListDraftPluginsRequest{ + res, err := p.DomainSVC.ListDraftPlugins(ctx, &dto.ListDraftPluginsRequest{ SpaceID: req.SpaceID, APPID: req.ProjectID, PageInfo: pageInfo, @@ -1449,59 +1452,6 @@ func (p *PluginApplicationService) GetDevPluginList(ctx context.Context, req *pl return resp, nil } -func (p *PluginApplicationService) getDevPluginListByName(ctx context.Context, req *pluginAPI.GetDevPluginListRequest) (pluginList []*common.PluginInfoForPlayground, total int64, err error) { - limit := req.GetSize() - if limit == 0 { - limit = 10 - } - - res, err := crosssearch.DefaultSVC().SearchResources(ctx, &searchModel.SearchResourcesRequest{ - SpaceID: req.SpaceID, - APPID: req.ProjectID, - Name: req.GetName(), - OrderAsc: false, - ResTypeFilter: []resCommon.ResType{ - resCommon.ResType_Plugin, - }, - Page: req.Page, - Limit: limit, - }) - if err != nil { - return nil, 0, errorx.Wrapf(err, "SearchResources failed, spaceID=%d, appID=%d", req.SpaceID, req.ProjectID) - } - - pluginList = make([]*common.PluginInfoForPlayground, 0, len(res.Data)) - for _, pl := range res.Data { - draftPlugin, exist, err := p.pluginRepo.GetDraftPlugin(ctx, pl.ResID) - if err != nil { - return nil, 0, errorx.Wrapf(err, "GetDraftPlugin failed, pluginID=%d", pl.ResID) - } - if !exist { - logs.CtxWarnf(ctx, "plugin not exist, pluginID=%d", pl.ResID) - continue - } - - tools, err := p.toolRepo.GetPluginAllDraftTools(ctx, draftPlugin.ID) - if err != nil { - return nil, 0, errorx.Wrapf(err, "GetPluginAllDraftTools failed, pluginID=%d", draftPlugin.ID) - } - - pluginInfo, err := p.toPluginInfoForPlayground(ctx, draftPlugin, tools) - if err != nil { - return nil, 0, err - } - - pluginInfo.VersionTs = "0" // when you get the plugin information in the project, version ts is set to 0 by default - pluginList = append(pluginList, pluginInfo) - } - - if res.TotalHits != nil { - total = *res.TotalHits - } - - return pluginList, total, nil -} - func (p *PluginApplicationService) DeleteAPPAllPlugins(ctx context.Context, appID int64) (err error) { pluginIDs, err := p.DomainSVC.DeleteAPPAllPlugins(ctx, appID) if err != nil { @@ -1525,7 +1475,7 @@ func (p *PluginApplicationService) DeleteAPPAllPlugins(ctx context.Context, appI } func (p *PluginApplicationService) Convert2OpenAPI(ctx context.Context, req *pluginAPI.Convert2OpenAPIRequest) (resp *pluginAPI.Convert2OpenAPIResponse, err error) { - res := p.DomainSVC.ConvertToOpenapi3Doc(ctx, &service.ConvertToOpenapi3DocRequest{ + res := p.DomainSVC.ConvertToOpenapi3Doc(ctx, &dto.ConvertToOpenapi3DocRequest{ RawInput: req.Data, PluginServerURL: req.PluginURL, }) @@ -1570,7 +1520,7 @@ func (p *PluginApplicationService) BatchCreateAPI(ctx context.Context, req *plug return nil, errorx.New(errno.ErrPluginInvalidOpenapi3Doc, errorx.KV(errno.PluginMsgKey, err.Error())) } - res, err := p.DomainSVC.CreateDraftToolsWithCode(ctx, &service.CreateDraftToolsWithCodeRequest{ + res, err := p.DomainSVC.CreateDraftToolsWithCode(ctx, &dto.CreateDraftToolsWithCodeRequest{ PluginID: req.PluginID, OpenapiDoc: ptr.Of(model.Openapi3T(*doc)), ConflictAndUpdate: req.ReplaceSamePaths, @@ -1618,8 +1568,8 @@ func (p *PluginApplicationService) RevokeAuthToken(ctx context.Context, req *plu return resp, nil } -func (p *PluginApplicationService) CopyPlugin(ctx context.Context, req *CopyPluginRequest) (resp *CopyPluginResponse, err error) { - res, err := p.DomainSVC.CopyPlugin(ctx, &service.CopyPluginRequest{ +func (p *PluginApplicationService) CopyPlugin(ctx context.Context, req *dto.CopyPluginRequest) (resp *dto.CopyPluginResponse, err error) { + res, err := p.DomainSVC.CopyPlugin(ctx, &dto.CopyPluginRequest{ UserID: req.UserID, PluginID: req.PluginID, CopyScene: req.CopyScene, @@ -1656,7 +1606,7 @@ func (p *PluginApplicationService) CopyPlugin(ctx context.Context, req *CopyPlug return nil, errorx.Wrapf(err, "publish resource '%d' failed", plugin.ID) } - resp = &CopyPluginResponse{ + resp = &dto.CopyPluginResponse{ Plugin: res.Plugin, Tools: res.Tools, } diff --git a/backend/application/singleagent/get.go b/backend/application/singleagent/get.go index 8c01ce871..12724dad0 100644 --- a/backend/application/singleagent/get.go +++ b/backend/application/singleagent/get.go @@ -24,16 +24,15 @@ import ( "github.com/coze-dev/coze-studio/backend/api/model/app/bot_common" knowledgeModel "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" "github.com/coze-dev/coze-studio/backend/api/model/playground" "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" plugin_develop_common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" "github.com/coze-dev/coze-studio/backend/api/model/workflow" + plugindto "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity" knowledge "github.com/coze-dev/coze-studio/backend/domain/knowledge/service" pluginEntity "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" - "github.com/coze-dev/coze-studio/backend/domain/plugin/service" shortcutCMDEntity "github.com/coze-dev/coze-studio/backend/domain/shortcutcmd/entity" workflowEntity "github.com/coze-dev/coze-studio/backend/domain/workflow/entity" "github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo" @@ -201,7 +200,7 @@ func (s *SingleAgentApplicationService) fetchKnowledgeDetails(ctx context.Contex } func (s *SingleAgentApplicationService) fetchToolDetails(ctx context.Context, agentInfo *entity.SingleAgent, req *playground.GetDraftBotInfoAgwRequest) ([]*pluginEntity.ToolInfo, error) { - return s.appContext.PluginDomainSVC.MGetAgentTools(ctx, &service.MGetAgentToolsRequest{ + return s.appContext.PluginDomainSVC.MGetAgentTools(ctx, &plugindto.MGetAgentToolsRequest{ SpaceID: agentInfo.SpaceID, AgentID: req.GetBotID(), IsDraft: true, @@ -331,7 +330,7 @@ func (s *SingleAgentApplicationService) pluginInfoDo2Vo(ctx context.Context, plu }) } -func parametersDo2Vo(op *plugin.Openapi3Operation) []*playground.PluginParameter { +func parametersDo2Vo(op *plugindto.Openapi3Operation) []*playground.PluginParameter { var convertReqBody func(paramName string, isRequired bool, sc *openapi3.Schema) *playground.PluginParameter convertReqBody = func(paramName string, isRequired bool, sc *openapi3.Schema) *playground.PluginParameter { if disabledParam(sc) { @@ -339,7 +338,7 @@ func parametersDo2Vo(op *plugin.Openapi3Operation) []*playground.PluginParameter } var assistType *int64 - if v, ok := sc.Extensions[plugin.APISchemaExtendAssistType]; ok { + if v, ok := sc.Extensions[plugindto.APISchemaExtendAssistType]; ok { if _v, ok := v.(string); ok { assistType = toParameterAssistType(_v) } @@ -410,7 +409,7 @@ func parametersDo2Vo(op *plugin.Openapi3Operation) []*playground.PluginParameter } var assistType *int64 - if v, ok := schemaVal.Extensions[plugin.APISchemaExtendAssistType]; ok { + if v, ok := schemaVal.Extensions[plugindto.APISchemaExtendAssistType]; ok { if _v, ok := v.(string); ok { assistType = toParameterAssistType(_v) } @@ -456,26 +455,26 @@ func toParameterAssistType(assistType string) *int64 { if assistType == "" { return nil } - switch plugin.APIFileAssistType(assistType) { - case plugin.AssistTypeFile: + switch plugindto.APIFileAssistType(assistType) { + case plugindto.AssistTypeFile: return ptr.Of(int64(plugin_develop_common.AssistParameterType_CODE)) - case plugin.AssistTypeImage: + case plugindto.AssistTypeImage: return ptr.Of(int64(plugin_develop_common.AssistParameterType_IMAGE)) - case plugin.AssistTypeDoc: + case plugindto.AssistTypeDoc: return ptr.Of(int64(plugin_develop_common.AssistParameterType_DOC)) - case plugin.AssistTypePPT: + case plugindto.AssistTypePPT: return ptr.Of(int64(plugin_develop_common.AssistParameterType_PPT)) - case plugin.AssistTypeCode: + case plugindto.AssistTypeCode: return ptr.Of(int64(plugin_develop_common.AssistParameterType_CODE)) - case plugin.AssistTypeExcel: + case plugindto.AssistTypeExcel: return ptr.Of(int64(plugin_develop_common.AssistParameterType_EXCEL)) - case plugin.AssistTypeZIP: + case plugindto.AssistTypeZIP: return ptr.Of(int64(plugin_develop_common.AssistParameterType_ZIP)) - case plugin.AssistTypeVideo: + case plugindto.AssistTypeVideo: return ptr.Of(int64(plugin_develop_common.AssistParameterType_VIDEO)) - case plugin.AssistTypeAudio: + case plugindto.AssistTypeAudio: return ptr.Of(int64(plugin_develop_common.AssistParameterType_AUDIO)) - case plugin.AssistTypeTXT: + case plugindto.AssistTypeTXT: return ptr.Of(int64(plugin_develop_common.AssistParameterType_TXT)) default: return nil diff --git a/backend/application/singleagent/single_agent.go b/backend/application/singleagent/single_agent.go index 3faed9909..5ab364647 100644 --- a/backend/application/singleagent/single_agent.go +++ b/backend/application/singleagent/single_agent.go @@ -34,12 +34,12 @@ import ( "github.com/coze-dev/coze-studio/backend/api/model/app/developer_api" intelligence "github.com/coze-dev/coze-studio/backend/api/model/app/intelligence/common" "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/api/model/data/database/table" "github.com/coze-dev/coze-studio/backend/api/model/playground" "github.com/coze-dev/coze-studio/backend/application/base/ctxutil" "github.com/coze-dev/coze-studio/backend/crossdomain/contract/agent" crossdatabase "github.com/coze-dev/coze-studio/backend/crossdomain/contract/database" + plugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity" singleagent "github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/service" variableEntity "github.com/coze-dev/coze-studio/backend/domain/memory/variables/entity" diff --git a/backend/application/workflow/workflow.go b/backend/application/workflow/workflow.go index cd502618f..47f822e87 100644 --- a/backend/application/workflow/workflow.go +++ b/backend/application/workflow/workflow.go @@ -32,8 +32,6 @@ import ( "github.com/coze-dev/coze-studio/backend/api/model/app/bot_common" model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/knowledge" - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" - pluginmodel "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/data/database/table" "github.com/coze-dev/coze-studio/backend/api/model/playground" @@ -48,7 +46,9 @@ import ( "github.com/coze-dev/coze-studio/backend/application/user" crossknowledge "github.com/coze-dev/coze-studio/backend/crossdomain/contract/knowledge" crossplugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin" + plugindto "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" crossuser "github.com/coze-dev/coze-studio/backend/crossdomain/contract/user" + "github.com/coze-dev/coze-studio/backend/domain/plugin/dto" search "github.com/coze-dev/coze-studio/backend/domain/search/entity" domainWorkflow "github.com/coze-dev/coze-studio/backend/domain/workflow" "github.com/coze-dev/coze-studio/backend/domain/workflow/entity" @@ -976,22 +976,22 @@ func (w *ApplicationService) CopyWorkflowFromAppToLibrary(ctx context.Context, w return 0, nil, err } - pluginMap := make(map[int64]*plugin.PluginEntity) + pluginMap := make(map[int64]*plugindto.PluginEntity) pluginToolMap := make(map[int64]int64) if len(ds.PluginIDs) > 0 { for idx := range ds.PluginIDs { id := ds.PluginIDs[idx] - response, err := appplugin.PluginApplicationSVC.CopyPlugin(ctx, &appplugin.CopyPluginRequest{ + response, err := appplugin.PluginApplicationSVC.CopyPlugin(ctx, &dto.CopyPluginRequest{ PluginID: id, UserID: ctxutil.MustGetUIDFromCtx(ctx), - CopyScene: pluginmodel.CopySceneOfToLibrary, + CopyScene: plugindto.CopySceneOfToLibrary, }) if err != nil { return 0, nil, err } pInfo := response.Plugin - pluginMap[id] = &plugin.PluginEntity{ + pluginMap[id] = &plugindto.PluginEntity{ PluginID: pInfo.ID, PluginVersion: pInfo.Version, } @@ -1109,9 +1109,9 @@ func (w *ApplicationService) DuplicateWorkflowsByAppID(ctx context.Context, sour } }() - pluginMap := make(map[int64]*plugin.PluginEntity) + pluginMap := make(map[int64]*plugindto.PluginEntity) for o, n := range externalResource.PluginMap { - pluginMap[o] = &plugin.PluginEntity{ + pluginMap[o] = &plugindto.PluginEntity{ PluginID: n, } } @@ -1209,7 +1209,7 @@ func (w *ApplicationService) MoveWorkflowFromAppToLibrary(ctx context.Context, w return 0, nil, err } - pluginMap := make(map[int64]*plugin.PluginEntity) + pluginMap := make(map[int64]*plugindto.PluginEntity) if len(ds.PluginIDs) > 0 { for idx := range ds.PluginIDs { id := ds.PluginIDs[idx] @@ -1217,7 +1217,7 @@ func (w *ApplicationService) MoveWorkflowFromAppToLibrary(ctx context.Context, w if err != nil { return 0, nil, err } - pluginMap[id] = &plugin.PluginEntity{ + pluginMap[id] = &plugindto.PluginEntity{ PluginID: pInfo.ID, PluginVersion: pInfo.Version, } @@ -2650,8 +2650,8 @@ func (w *ApplicationService) GetApiDetail(ctx context.Context, req *workflow.Get return nil, err } - toolInfoResponse, err := crossplugin.DefaultSVC().GetPluginToolsInfo(ctx, &plugin.ToolsInfoRequest{ - PluginEntity: plugin.PluginEntity{ + toolInfoResponse, err := crossplugin.DefaultSVC().GetPluginToolsInfo(ctx, &plugindto.ToolsInfoRequest{ + PluginEntity: plugindto.PluginEntity{ PluginID: pluginID, PluginVersion: req.PluginVersion, }, @@ -2718,7 +2718,7 @@ func (w *ApplicationService) GetLLMNodeFCSettingDetail(ctx context.Context, req var ( pluginSvc = crossplugin.DefaultSVC() - pluginToolsInfoReqs = make(map[int64]*plugin.ToolsInfoRequest) + pluginToolsInfoReqs = make(map[int64]*plugindto.ToolsInfoRequest) pluginDetailMap = make(map[string]*workflow.PluginDetail) toolsDetailInfo = make(map[string]*workflow.APIDetail) workflowDetailMap = make(map[string]*workflow.WorkflowDetail) @@ -2740,8 +2740,8 @@ func (w *ApplicationService) GetLLMNodeFCSettingDetail(ctx context.Context, req if r, ok := pluginToolsInfoReqs[pluginID]; ok { r.ToolIDs = append(r.ToolIDs, toolID) } else { - pluginToolsInfoReqs[pluginID] = &plugin.ToolsInfoRequest{ - PluginEntity: plugin.PluginEntity{ + pluginToolsInfoReqs[pluginID] = &plugindto.ToolsInfoRequest{ + PluginEntity: plugindto.PluginEntity{ PluginID: pluginID, PluginVersion: pl.PluginVersion, }, @@ -2940,8 +2940,8 @@ func (w *ApplicationService) GetLLMNodeFCSettingsMerged(ctx context.Context, req return nil, err } - pluginReq := &plugin.ToolsInfoRequest{ - PluginEntity: plugin.PluginEntity{ + pluginReq := &plugindto.ToolsInfoRequest{ + PluginEntity: plugindto.PluginEntity{ PluginID: pluginID, }, ToolIDs: []int64{toolID}, diff --git a/backend/api/model/crossdomain/plugin/consts.go b/backend/crossdomain/contract/plugin/dto/consts.go similarity index 99% rename from backend/api/model/crossdomain/plugin/consts.go rename to backend/crossdomain/contract/plugin/dto/consts.go index c0a860063..dd1fa7f75 100644 --- a/backend/api/model/crossdomain/plugin/consts.go +++ b/backend/crossdomain/contract/plugin/dto/consts.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package plugin +package dto import "github.com/getkin/kin-openapi/openapi3" diff --git a/backend/api/model/crossdomain/plugin/convert.go b/backend/crossdomain/contract/plugin/dto/convert.go similarity index 99% rename from backend/api/model/crossdomain/plugin/convert.go rename to backend/crossdomain/contract/plugin/dto/convert.go index eca816029..7e1597da1 100644 --- a/backend/api/model/crossdomain/plugin/convert.go +++ b/backend/crossdomain/contract/plugin/dto/convert.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package plugin +package dto import ( "net/http" diff --git a/backend/api/model/crossdomain/plugin/openapi.go b/backend/crossdomain/contract/plugin/dto/openapi.go similarity index 99% rename from backend/api/model/crossdomain/plugin/openapi.go rename to backend/crossdomain/contract/plugin/dto/openapi.go index 08b22740e..c3ec14ca3 100644 --- a/backend/api/model/crossdomain/plugin/openapi.go +++ b/backend/crossdomain/contract/plugin/dto/openapi.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package plugin +package dto import ( "context" diff --git a/backend/api/model/crossdomain/plugin/option.go b/backend/crossdomain/contract/plugin/dto/option.go similarity index 99% rename from backend/api/model/crossdomain/plugin/option.go rename to backend/crossdomain/contract/plugin/dto/option.go index 3e79fba06..0d55372d0 100644 --- a/backend/api/model/crossdomain/plugin/option.go +++ b/backend/crossdomain/contract/plugin/dto/option.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package plugin +package dto type ExecuteToolOption struct { ProjectInfo *ProjectInfo diff --git a/backend/api/model/crossdomain/plugin/plugin.go b/backend/crossdomain/contract/plugin/dto/plugin.go similarity index 99% rename from backend/api/model/crossdomain/plugin/plugin.go rename to backend/crossdomain/contract/plugin/dto/plugin.go index 078661385..8a12c4f27 100644 --- a/backend/api/model/crossdomain/plugin/plugin.go +++ b/backend/crossdomain/contract/plugin/dto/plugin.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package plugin +package dto import ( "github.com/getkin/kin-openapi/openapi3" diff --git a/backend/api/model/crossdomain/plugin/plugin_manifest.go b/backend/crossdomain/contract/plugin/dto/plugin_manifest.go similarity index 99% rename from backend/api/model/crossdomain/plugin/plugin_manifest.go rename to backend/crossdomain/contract/plugin/dto/plugin_manifest.go index 7d2894cf9..1b960d21e 100644 --- a/backend/api/model/crossdomain/plugin/plugin_manifest.go +++ b/backend/crossdomain/contract/plugin/dto/plugin_manifest.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package plugin +package dto import ( "encoding/json" diff --git a/backend/api/model/crossdomain/plugin/toolinfo.go b/backend/crossdomain/contract/plugin/dto/toolinfo.go similarity index 99% rename from backend/api/model/crossdomain/plugin/toolinfo.go rename to backend/crossdomain/contract/plugin/dto/toolinfo.go index dbe802502..f673e8656 100644 --- a/backend/api/model/crossdomain/plugin/toolinfo.go +++ b/backend/crossdomain/contract/plugin/dto/toolinfo.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package plugin +package dto import ( "fmt" @@ -22,12 +22,13 @@ import ( "strconv" "strings" + "github.com/getkin/kin-openapi/openapi3" + gonanoid "github.com/matoous/go-nanoid" + productAPI "github.com/coze-dev/coze-studio/backend/api/model/marketplace/product_public_api" "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" "github.com/coze-dev/coze-studio/backend/pkg/lang/ptr" "github.com/coze-dev/coze-studio/backend/pkg/lang/slices" - "github.com/getkin/kin-openapi/openapi3" - gonanoid "github.com/matoous/go-nanoid" ) type ToolInfo struct { @@ -397,7 +398,7 @@ func (t ToolInfo) ToPluginParameters() ([]*common.PluginParameter, error) { continue } f, ok := AssistTypeToThriftFormat(APIFileAssistType(_v)) - if ok { + if !ok { return nil, fmt.Errorf("the assist type '%s' of field '%s' is invalid", _v, paramVal.Name) } assistType = ptr.Of(f) diff --git a/backend/api/model/crossdomain/plugin/workflow.go b/backend/crossdomain/contract/plugin/dto/workflow.go similarity index 99% rename from backend/api/model/crossdomain/plugin/workflow.go rename to backend/crossdomain/contract/plugin/dto/workflow.go index 76e8fa51b..11020c0e7 100644 --- a/backend/api/model/crossdomain/plugin/workflow.go +++ b/backend/crossdomain/contract/plugin/dto/workflow.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package plugin +package dto import ( "github.com/coze-dev/coze-studio/backend/api/model/workflow" diff --git a/backend/crossdomain/contract/plugin/plugin.go b/backend/crossdomain/contract/plugin/plugin.go index f29f3f29f..aacc42055 100644 --- a/backend/crossdomain/contract/plugin/plugin.go +++ b/backend/crossdomain/contract/plugin/plugin.go @@ -21,8 +21,8 @@ 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" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" ) //go:generate mockgen -destination pluginmock/plugin_mock.go --package pluginmock -source plugin.go diff --git a/backend/crossdomain/contract/plugin/pluginmock/plugin_mock.go b/backend/crossdomain/contract/plugin/pluginmock/plugin_mock.go index bf5e621f5..981a6fd5a 100644 --- a/backend/crossdomain/contract/plugin/pluginmock/plugin_mock.go +++ b/backend/crossdomain/contract/plugin/pluginmock/plugin_mock.go @@ -14,9 +14,9 @@ import ( reflect "reflect" 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" + plugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" gomock "go.uber.org/mock/gomock" ) diff --git a/backend/crossdomain/impl/plugin/plugin.go b/backend/crossdomain/impl/plugin/plugin.go index b96b1544b..4f37ce77e 100644 --- a/backend/crossdomain/impl/plugin/plugin.go +++ b/backend/crossdomain/impl/plugin/plugin.go @@ -26,12 +26,12 @@ import ( "github.com/getkin/kin-openapi/openapi3" "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" crossplugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/domain/plugin/service" plugin "github.com/coze-dev/coze-studio/backend/domain/plugin/service" @@ -355,7 +355,7 @@ func (s *impl) ExecutePlugin(ctx context.Context, input map[string]any, pe *mode uID = conv.Int64ToStr(cfg.Operator) } - req := &service.ExecuteToolRequest{ + req := &model.ExecuteToolRequest{ UserID: uID, PluginID: pe.PluginID, ToolID: toolID, @@ -449,7 +449,7 @@ func (p *pluginInvokeTool) Info(ctx context.Context) (_ *schema.ToolInfo, err er } func (p *pluginInvokeTool) PluginInvoke(ctx context.Context, argumentsInJSON string, cfg workflowModel.ExecuteConfig) (string, error) { - req := &service.ExecuteToolRequest{ + req := &model.ExecuteToolRequest{ UserID: conv.Int64ToStr(cfg.Operator), PluginID: p.pluginEntity.PluginID, ToolID: p.toolInfo.ID, diff --git a/backend/domain/agent/singleagent/internal/agentflow/callback_reply_chunk.go b/backend/domain/agent/singleagent/internal/agentflow/callback_reply_chunk.go index ea876c213..d0ea1d597 100644 --- a/backend/domain/agent/singleagent/internal/agentflow/callback_reply_chunk.go +++ b/backend/domain/agent/singleagent/internal/agentflow/callback_reply_chunk.go @@ -29,8 +29,8 @@ 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/api/model/crossdomain/singleagent" + plugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" crossworkflow "github.com/coze-dev/coze-studio/backend/crossdomain/contract/workflow" "github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity" "github.com/coze-dev/coze-studio/backend/pkg/lang/conv" diff --git a/backend/domain/agent/singleagent/internal/agentflow/node_tool_plugin.go b/backend/domain/agent/singleagent/internal/agentflow/node_tool_plugin.go index 71ebdf2f8..1d99351b0 100644 --- a/backend/domain/agent/singleagent/internal/agentflow/node_tool_plugin.go +++ b/backend/domain/agent/singleagent/internal/agentflow/node_tool_plugin.go @@ -16,20 +16,19 @@ package agentflow +// TODO(fanlv): remove pluginEntity import ( "context" "github.com/cloudwego/eino/components/tool" "github.com/cloudwego/eino/schema" - "github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity" - "github.com/coze-dev/coze-studio/backend/pkg/lang/ptr" - "github.com/coze-dev/coze-studio/backend/api/model/app/bot_common" - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" crossplugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" + "github.com/coze-dev/coze-studio/backend/domain/agent/singleagent/entity" pluginEntity "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" - "github.com/coze-dev/coze-studio/backend/domain/plugin/service" + "github.com/coze-dev/coze-studio/backend/pkg/lang/ptr" "github.com/coze-dev/coze-studio/backend/pkg/lang/slices" ) @@ -43,7 +42,7 @@ type toolConfig struct { } func newPluginTools(ctx context.Context, conf *toolConfig) ([]tool.InvokableTool, error) { - req := &service.MGetAgentToolsRequest{ + req := &model.MGetAgentToolsRequest{ SpaceID: conf.spaceID, AgentID: conf.agentIdentity.AgentID, IsDraft: conf.agentIdentity.IsDraft, @@ -59,9 +58,9 @@ func newPluginTools(ctx context.Context, conf *toolConfig) ([]tool.InvokableTool return nil, err } - projectInfo := &plugin.ProjectInfo{ + projectInfo := &model.ProjectInfo{ ProjectID: conf.agentIdentity.AgentID, - ProjectType: plugin.ProjectTypeOfAgent, + ProjectType: model.ProjectTypeOfAgent, ProjectVersion: ptr.Of(conf.agentIdentity.Version), ConnectorID: conf.agentIdentity.ConnectorID, } @@ -85,7 +84,7 @@ type pluginInvokableTool struct { userID string isDraft bool toolInfo *pluginEntity.ToolInfo - projectInfo *plugin.ProjectInfo + projectInfo *model.ProjectInfo conversationID int64 } @@ -112,25 +111,25 @@ func (p *pluginInvokableTool) Info(ctx context.Context) (*schema.ToolInfo, error } func (p *pluginInvokableTool) InvokableRun(ctx context.Context, argumentsInJSON string, _ ...tool.Option) (string, error) { - req := &service.ExecuteToolRequest{ + req := &model.ExecuteToolRequest{ UserID: p.userID, PluginID: p.toolInfo.PluginID, ToolID: p.toolInfo.ID, ExecDraftTool: false, ArgumentsInJson: argumentsInJSON, - ExecScene: func() plugin.ExecuteScene { + ExecScene: func() model.ExecuteScene { if p.isDraft { - return plugin.ExecSceneOfDraftAgent + return model.ExecSceneOfDraftAgent } - return plugin.ExecSceneOfOnlineAgent + return model.ExecSceneOfOnlineAgent }(), } opts := []pluginEntity.ExecuteToolOpt{ - plugin.WithInvalidRespProcessStrategy(plugin.InvalidResponseProcessStrategyOfReturnDefault), - plugin.WithToolVersion(p.toolInfo.GetVersion()), - plugin.WithProjectInfo(p.projectInfo), - plugin.WithPluginHTTPHeader(p.conversationID), + model.WithInvalidRespProcessStrategy(model.InvalidResponseProcessStrategyOfReturnDefault), + model.WithToolVersion(p.toolInfo.GetVersion()), + model.WithProjectInfo(p.projectInfo), + model.WithPluginHTTPHeader(p.conversationID), } resp, err := crossplugin.DefaultSVC().ExecuteTool(ctx, req, opts...) diff --git a/backend/domain/agent/singleagent/internal/agentflow/node_tool_pre_retriever.go b/backend/domain/agent/singleagent/internal/agentflow/node_tool_pre_retriever.go index 099498f41..61f723f97 100644 --- a/backend/domain/agent/singleagent/internal/agentflow/node_tool_pre_retriever.go +++ b/backend/domain/agent/singleagent/internal/agentflow/node_tool_pre_retriever.go @@ -20,17 +20,15 @@ import ( "context" "encoding/json" + "github.com/cloudwego/eino/schema" "github.com/google/uuid" - "github.com/cloudwego/eino/schema" - "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" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" crossworkflow "github.com/coze-dev/coze-studio/backend/crossdomain/contract/workflow" pluginEntity "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" - "github.com/coze-dev/coze-studio/backend/domain/plugin/service" "github.com/coze-dev/coze-studio/backend/pkg/lang/ptr" "github.com/coze-dev/coze-studio/backend/pkg/logs" ) @@ -53,26 +51,26 @@ func (pr *toolPreCallConf) toolPreRetrieve(ctx context.Context, ar *AgentRequest switch item.Type { case agentrun.ToolTypePlugin: - etr := &service.ExecuteToolRequest{ + etr := &model.ExecuteToolRequest{ UserID: ar.UserID, ExecDraftTool: false, PluginID: item.PluginID, ToolID: item.ToolID, ArgumentsInJson: item.Arguments, - ExecScene: func(isDraft bool) plugin.ExecuteScene { + ExecScene: func(isDraft bool) model.ExecuteScene { if isDraft { - return plugin.ExecSceneOfDraftAgent + return model.ExecSceneOfDraftAgent } else { - return plugin.ExecSceneOfOnlineAgent + return model.ExecSceneOfOnlineAgent } }(ar.Identity.IsDraft), } opts := []pluginEntity.ExecuteToolOpt{ - plugin.WithInvalidRespProcessStrategy(plugin.InvalidResponseProcessStrategyOfReturnDefault), - plugin.WithProjectInfo(&plugin.ProjectInfo{ + model.WithInvalidRespProcessStrategy(model.InvalidResponseProcessStrategyOfReturnDefault), + model.WithProjectInfo(&model.ProjectInfo{ ProjectID: ar.Identity.AgentID, - ProjectType: plugin.ProjectTypeOfAgent, + ProjectType: model.ProjectTypeOfAgent, ProjectVersion: ptr.Of(ar.Identity.Version), }), } diff --git a/backend/domain/app/service/publish_app.go b/backend/domain/app/service/publish_app.go index ddbf7c793..c746e7cbb 100644 --- a/backend/domain/app/service/publish_app.go +++ b/backend/domain/app/service/publish_app.go @@ -20,9 +20,9 @@ import ( "context" "time" - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" resourceCommon "github.com/coze-dev/coze-studio/backend/api/model/resource/common" crossplugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin" + plugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" crossworkflow "github.com/coze-dev/coze-studio/backend/crossdomain/contract/workflow" "github.com/coze-dev/coze-studio/backend/domain/app/entity" "github.com/coze-dev/coze-studio/backend/domain/app/repository" diff --git a/backend/domain/plugin/conf/load_plugin.go b/backend/domain/plugin/conf/load_plugin.go index 30e8b1d06..4559c5ea9 100644 --- a/backend/domain/plugin/conf/load_plugin.go +++ b/backend/domain/plugin/conf/load_plugin.go @@ -28,8 +28,8 @@ import ( "golang.org/x/mod/semver" "gopkg.in/yaml.v3" - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/pkg/lang/ptr" "github.com/coze-dev/coze-studio/backend/pkg/logs" diff --git a/backend/application/plugin/model.go b/backend/domain/plugin/dto/auth.go similarity index 56% rename from backend/application/plugin/model.go rename to backend/domain/plugin/dto/auth.go index 474b979cb..611d834fe 100644 --- a/backend/application/plugin/model.go +++ b/backend/domain/plugin/dto/auth.go @@ -14,21 +14,30 @@ * limitations under the License. */ -package plugin +package dto import ( - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" + "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" ) -type CopyPluginRequest struct { - PluginID int64 - UserID int64 - CopyScene model.CopyScene - TargetAPPID *int64 +type GetOAuthStatusResponse struct { + IsOauth bool + Status common.OAuthStatus + OAuthURL string } -type CopyPluginResponse struct { - Plugin *entity.PluginInfo - Tools map[int64]*entity.ToolInfo // old tool id -> new tool id +type AgentPluginOAuthStatus struct { + PluginID int64 + PluginName string + PluginIconURL string + Status common.OAuthStatus +} + +type GetAccessTokenRequest struct { + UserID string + PluginID *int64 + Mode model.AuthzSubType + OAuthInfo *entity.OAuthInfo } diff --git a/backend/domain/plugin/dto/plugin.go b/backend/domain/plugin/dto/plugin.go new file mode 100644 index 000000000..e30f2efcc --- /dev/null +++ b/backend/domain/plugin/dto/plugin.go @@ -0,0 +1,97 @@ +/* + * 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 dto + +import ( + "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" + "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" +) + +type CreateDraftPluginRequest struct { + PluginType common.PluginType + IconURI string + SpaceID int64 + DeveloperID int64 + ProjectID *int64 + Name string + Desc string + ServerURL string + CommonParams map[common.ParameterLocation][]*common.CommonParamSchema + AuthInfo *PluginAuthInfo +} + +type UpdateDraftPluginWithCodeRequest struct { + UserID int64 + PluginID int64 + OpenapiDoc *model.Openapi3T + Manifest *entity.PluginManifest +} + +type UpdateDraftPluginRequest struct { + PluginID int64 + Name *string + Desc *string + URL *string + Icon *common.PluginIcon + CommonParams map[common.ParameterLocation][]*common.CommonParamSchema + AuthInfo *PluginAuthInfo +} + +type ListDraftPluginsRequest struct { + SpaceID int64 + APPID int64 + PageInfo entity.PageInfo +} + +type ListDraftPluginsResponse struct { + Plugins []*entity.PluginInfo + Total int64 +} + +type CreateDraftPluginWithCodeRequest struct { + SpaceID int64 + DeveloperID int64 + ProjectID *int64 + Manifest *entity.PluginManifest + OpenapiDoc *model.Openapi3T +} + +type CreateDraftPluginWithCodeResponse struct { + Plugin *entity.PluginInfo + Tools []*entity.ToolInfo +} + +type ListPluginProductsRequest struct{} + +type ListPluginProductsResponse struct { + Plugins []*entity.PluginInfo + Total int64 +} + +type CopyPluginRequest struct { + UserID int64 + PluginID int64 + CopyScene model.CopyScene + + TargetAPPID *int64 +} + +type CopyPluginResponse struct { + Plugin *entity.PluginInfo + Tools map[int64]*entity.ToolInfo // old tool id -> new tool +} diff --git a/backend/domain/plugin/dto/plugin_author.go b/backend/domain/plugin/dto/plugin_author.go new file mode 100644 index 000000000..0c4d969f3 --- /dev/null +++ b/backend/domain/plugin/dto/plugin_author.go @@ -0,0 +1,176 @@ +/* + * 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 dto + +import ( + "fmt" + "strings" + + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" + "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" +) + +type PluginAuthInfo struct { + AuthzType *model.AuthzType + Location *model.HTTPParamLocation + Key *string + ServiceToken *string + OAuthInfo *string + AuthzSubType *model.AuthzSubType + AuthzPayload *string +} + +// TODO(@fanlv): change to DTO + Service +func (p PluginAuthInfo) ToAuthV2() (*model.AuthV2, error) { + if p.AuthzType == nil { + return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KV(errno.PluginMsgKey, "auth type is required")) + } + + switch *p.AuthzType { + case model.AuthzTypeOfNone: + return &model.AuthV2{ + Type: model.AuthzTypeOfNone, + }, nil + + case model.AuthzTypeOfOAuth: + m, err := p.authOfOAuthToAuthV2() + if err != nil { + return nil, err + } + return m, nil + + case model.AuthzTypeOfService: + m, err := p.authOfServiceToAuthV2() + if err != nil { + return nil, err + } + return m, nil + + default: + return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KVf(errno.PluginMsgKey, + "the type '%s' of auth is invalid", *p.AuthzType)) + } +} + +func (p PluginAuthInfo) authOfOAuthToAuthV2() (*model.AuthV2, error) { + if p.AuthzSubType == nil { + return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KV(errno.PluginMsgKey, "sub-auth type is required")) + } + + if p.OAuthInfo == nil || *p.OAuthInfo == "" { + return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KV(errno.PluginMsgKey, "oauth info is required")) + } + + oauthInfo := make(map[string]string) + err := sonic.Unmarshal([]byte(*p.OAuthInfo), &oauthInfo) + if err != nil { + return nil, errorx.WrapByCode(err, errno.ErrPluginInvalidManifest, errorx.KV(errno.PluginMsgKey, "invalid oauth info")) + } + + if *p.AuthzSubType == model.AuthzSubTypeOfOAuthClientCredentials { + _oauthInfo := &model.OAuthClientCredentialsConfig{ + ClientID: oauthInfo["client_id"], + ClientSecret: oauthInfo["client_secret"], + TokenURL: oauthInfo["token_url"], + } + + str, err := sonic.MarshalString(_oauthInfo) + if err != nil { + return nil, fmt.Errorf("marshal oauth info failed, err=%v", err) + } + + return &model.AuthV2{ + Type: model.AuthzTypeOfOAuth, + SubType: model.AuthzSubTypeOfOAuthClientCredentials, + Payload: str, + AuthOfOAuthClientCredentials: _oauthInfo, + }, nil + } + + if *p.AuthzSubType == model.AuthzSubTypeOfOAuthAuthorizationCode { + contentType := oauthInfo["authorization_content_type"] + if contentType != model.MediaTypeJson { // only support application/json + return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KVf(errno.PluginMsgKey, + "the type '%s' of authorization content is invalid", contentType)) + } + + _oauthInfo := &model.OAuthAuthorizationCodeConfig{ + ClientID: oauthInfo["client_id"], + ClientSecret: oauthInfo["client_secret"], + ClientURL: oauthInfo["client_url"], + Scope: oauthInfo["scope"], + AuthorizationURL: oauthInfo["authorization_url"], + AuthorizationContentType: contentType, + } + + str, err := sonic.MarshalString(_oauthInfo) + if err != nil { + return nil, fmt.Errorf("marshal oauth info failed, err=%v", err) + } + + return &model.AuthV2{ + Type: model.AuthzTypeOfOAuth, + SubType: model.AuthzSubTypeOfOAuthAuthorizationCode, + Payload: str, + AuthOfOAuthAuthorizationCode: _oauthInfo, + }, nil + } + + return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KVf(errno.PluginMsgKey, + "the type '%s' of sub-auth is invalid", *p.AuthzSubType)) +} + +func (p PluginAuthInfo) authOfServiceToAuthV2() (*model.AuthV2, error) { + if p.AuthzSubType == nil { + return nil, fmt.Errorf("sub-auth type is required") + } + + if *p.AuthzSubType == model.AuthzSubTypeOfServiceAPIToken { + if p.Location == nil { + return nil, fmt.Errorf("'Location' of sub-auth is required") + } + if p.ServiceToken == nil { + return nil, fmt.Errorf("'ServiceToken' of sub-auth is required") + } + if p.Key == nil { + return nil, fmt.Errorf("'Key' of sub-auth is required") + } + + tokenAuth := &model.AuthOfAPIToken{ + ServiceToken: *p.ServiceToken, + Location: model.HTTPParamLocation(strings.ToLower(string(*p.Location))), + Key: *p.Key, + } + + str, err := sonic.MarshalString(tokenAuth) + if err != nil { + return nil, fmt.Errorf("marshal token auth failed, err=%v", err) + } + + return &model.AuthV2{ + Type: model.AuthzTypeOfService, + SubType: model.AuthzSubTypeOfServiceAPIToken, + Payload: str, + AuthOfAPIToken: tokenAuth, + }, nil + } + + return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KVf(errno.PluginMsgKey, + "the type '%s' of sub-auth is invalid", *p.AuthzSubType)) +} diff --git a/backend/domain/plugin/dto/tool.go b/backend/domain/plugin/dto/tool.go new file mode 100644 index 000000000..5447f5405 --- /dev/null +++ b/backend/domain/plugin/dto/tool.go @@ -0,0 +1,73 @@ +/* + * 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 dto + +import ( + "github.com/getkin/kin-openapi/openapi3" + + "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" + "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" +) + +type CreateDraftToolsWithCodeRequest struct { + PluginID int64 + OpenapiDoc *model.Openapi3T + + ConflictAndUpdate bool +} + +type CreateDraftToolsWithCodeResponse struct { + DuplicatedTools []entity.UniqueToolAPI +} + +type UpdateDraftToolRequest struct { + PluginID int64 + ToolID int64 + Name *string + Desc *string + SubURL *string + Method *string + Parameters openapi3.Parameters + RequestBody *openapi3.RequestBodyRef + Responses openapi3.Responses + Disabled *bool + SaveExample *bool + DebugExample *common.DebugExample + APIExtend *common.APIExtend +} + +type ConvertToOpenapi3DocRequest struct { + RawInput string + PluginServerURL *string +} + +type ConvertToOpenapi3DocResponse struct { + OpenapiDoc *model.Openapi3T + Manifest *entity.PluginManifest + Format common.PluginDataFormat + ErrMsg string +} + +type UpdateBotDefaultParamsRequest struct { + PluginID int64 + AgentID int64 + ToolName string + Parameters openapi3.Parameters + RequestBody *openapi3.RequestBodyRef + Responses openapi3.Responses +} diff --git a/backend/domain/plugin/entity/oauth.go b/backend/domain/plugin/entity/oauth.go index 1159e2cf1..829ab42ce 100644 --- a/backend/domain/plugin/entity/oauth.go +++ b/backend/domain/plugin/entity/oauth.go @@ -17,7 +17,7 @@ package entity import ( - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/pkg/lang/ptr" ) diff --git a/backend/domain/plugin/entity/plugin.go b/backend/domain/plugin/entity/plugin.go index 8718f4251..18f49fbc0 100644 --- a/backend/domain/plugin/entity/plugin.go +++ b/backend/domain/plugin/entity/plugin.go @@ -24,8 +24,8 @@ import ( "github.com/bytedance/sonic" "github.com/getkin/kin-openapi/openapi3" - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/pkg/lang/ptr" "github.com/coze-dev/coze-studio/backend/pkg/logs" ) diff --git a/backend/domain/plugin/internal/dal/model/agent_tool_draft.gen.go b/backend/domain/plugin/internal/dal/model/agent_tool_draft.gen.go index 66cb2e1bb..77439858a 100644 --- a/backend/domain/plugin/internal/dal/model/agent_tool_draft.gen.go +++ b/backend/domain/plugin/internal/dal/model/agent_tool_draft.gen.go @@ -4,22 +4,22 @@ package model -import "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" +import "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" const TableNameAgentToolDraft = "agent_tool_draft" // AgentToolDraft Draft Agent Tool type AgentToolDraft struct { - ID int64 `gorm:"column:id;primaryKey;comment:Primary Key ID" json:"id"` // Primary Key ID - AgentID int64 `gorm:"column:agent_id;not null;comment:Agent ID" json:"agent_id"` // Agent ID - PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID - ToolID int64 `gorm:"column:tool_id;not null;comment:Tool ID" json:"tool_id"` // Tool ID - CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds - SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path - Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method - ToolName string `gorm:"column:tool_name;not null;comment:Tool Name" json:"tool_name"` // Tool Name - ToolVersion string `gorm:"column:tool_version;not null;comment:Tool Version, e.g. v1.0.0" json:"tool_version"` // Tool Version, e.g. v1.0.0 - Operation *plugin.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema + ID int64 `gorm:"column:id;primaryKey;comment:Primary Key ID" json:"id"` // Primary Key ID + AgentID int64 `gorm:"column:agent_id;not null;comment:Agent ID" json:"agent_id"` // Agent ID + PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID + ToolID int64 `gorm:"column:tool_id;not null;comment:Tool ID" json:"tool_id"` // Tool ID + CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds + SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path + Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method + ToolName string `gorm:"column:tool_name;not null;comment:Tool Name" json:"tool_name"` // Tool Name + ToolVersion string `gorm:"column:tool_version;not null;comment:Tool Version, e.g. v1.0.0" json:"tool_version"` // Tool Version, e.g. v1.0.0 + Operation *dto.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema } // TableName AgentToolDraft's table name diff --git a/backend/domain/plugin/internal/dal/model/agent_tool_version.gen.go b/backend/domain/plugin/internal/dal/model/agent_tool_version.gen.go index 0ea38779c..2fef4ad4a 100644 --- a/backend/domain/plugin/internal/dal/model/agent_tool_version.gen.go +++ b/backend/domain/plugin/internal/dal/model/agent_tool_version.gen.go @@ -4,23 +4,23 @@ package model -import "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" +import "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" const TableNameAgentToolVersion = "agent_tool_version" // AgentToolVersion Agent Tool Version type AgentToolVersion struct { - ID int64 `gorm:"column:id;primaryKey;comment:Primary Key ID" json:"id"` // Primary Key ID - AgentID int64 `gorm:"column:agent_id;not null;comment:Agent ID" json:"agent_id"` // Agent ID - PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID - ToolID int64 `gorm:"column:tool_id;not null;comment:Tool ID" json:"tool_id"` // Tool ID - AgentVersion string `gorm:"column:agent_version;not null;comment:Agent Tool Version" json:"agent_version"` // Agent Tool Version - ToolName string `gorm:"column:tool_name;not null;comment:Tool Name" json:"tool_name"` // Tool Name - ToolVersion string `gorm:"column:tool_version;not null;comment:Tool Version, e.g. v1.0.0" json:"tool_version"` // Tool Version, e.g. v1.0.0 - SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path - Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method - Operation *plugin.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema - CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds + ID int64 `gorm:"column:id;primaryKey;comment:Primary Key ID" json:"id"` // Primary Key ID + AgentID int64 `gorm:"column:agent_id;not null;comment:Agent ID" json:"agent_id"` // Agent ID + PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID + ToolID int64 `gorm:"column:tool_id;not null;comment:Tool ID" json:"tool_id"` // Tool ID + AgentVersion string `gorm:"column:agent_version;not null;comment:Agent Tool Version" json:"agent_version"` // Agent Tool Version + ToolName string `gorm:"column:tool_name;not null;comment:Tool Name" json:"tool_name"` // Tool Name + ToolVersion string `gorm:"column:tool_version;not null;comment:Tool Version, e.g. v1.0.0" json:"tool_version"` // Tool Version, e.g. v1.0.0 + SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path + Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method + Operation *dto.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema + CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds } // TableName AgentToolVersion's table name diff --git a/backend/domain/plugin/internal/dal/model/plugin.gen.go b/backend/domain/plugin/internal/dal/model/plugin.gen.go index fb5d7d31c..d8ebfb491 100644 --- a/backend/domain/plugin/internal/dal/model/plugin.gen.go +++ b/backend/domain/plugin/internal/dal/model/plugin.gen.go @@ -4,25 +4,25 @@ package model -import "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" +import "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" const TableNamePlugin = "plugin" // Plugin Latest Plugin type Plugin struct { - ID int64 `gorm:"column:id;primaryKey;comment:Plugin ID" json:"id"` // Plugin ID - SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID - DeveloperID int64 `gorm:"column:developer_id;not null;comment:Developer ID" json:"developer_id"` // Developer ID - AppID int64 `gorm:"column:app_id;not null;comment:Application ID" json:"app_id"` // Application ID - IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI - ServerURL string `gorm:"column:server_url;not null;comment:Server URL" json:"server_url"` // Server URL - PluginType int32 `gorm:"column:plugin_type;not null;comment:Plugin Type, 1:http, 6:local" json:"plugin_type"` // Plugin Type, 1:http, 6:local - CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds - UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds - Version string `gorm:"column:version;not null;comment:Plugin Version, e.g. v1.0.0" json:"version"` // Plugin Version, e.g. v1.0.0 - VersionDesc string `gorm:"column:version_desc;comment:Plugin Version Description" json:"version_desc"` // Plugin Version Description - Manifest *plugin.PluginManifest `gorm:"column:manifest;comment:Plugin Manifest;serializer:json" json:"manifest"` // Plugin Manifest - OpenapiDoc *plugin.Openapi3T `gorm:"column:openapi_doc;comment:OpenAPI Document, only stores the root;serializer:json" json:"openapi_doc"` // OpenAPI Document, only stores the root + ID int64 `gorm:"column:id;primaryKey;comment:Plugin ID" json:"id"` // Plugin ID + SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID + DeveloperID int64 `gorm:"column:developer_id;not null;comment:Developer ID" json:"developer_id"` // Developer ID + AppID int64 `gorm:"column:app_id;not null;comment:Application ID" json:"app_id"` // Application ID + IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI + ServerURL string `gorm:"column:server_url;not null;comment:Server URL" json:"server_url"` // Server URL + PluginType int32 `gorm:"column:plugin_type;not null;comment:Plugin Type, 1:http, 6:local" json:"plugin_type"` // Plugin Type, 1:http, 6:local + CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds + UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds + Version string `gorm:"column:version;not null;comment:Plugin Version, e.g. v1.0.0" json:"version"` // Plugin Version, e.g. v1.0.0 + VersionDesc string `gorm:"column:version_desc;comment:Plugin Version Description" json:"version_desc"` // Plugin Version Description + Manifest *dto.PluginManifest `gorm:"column:manifest;comment:Plugin Manifest;serializer:json" json:"manifest"` // Plugin Manifest + OpenapiDoc *dto.Openapi3T `gorm:"column:openapi_doc;comment:OpenAPI Document, only stores the root;serializer:json" json:"openapi_doc"` // OpenAPI Document, only stores the root } // TableName Plugin's table name diff --git a/backend/domain/plugin/internal/dal/model/plugin_draft.gen.go b/backend/domain/plugin/internal/dal/model/plugin_draft.gen.go index 19e16014f..9282cf0bb 100644 --- a/backend/domain/plugin/internal/dal/model/plugin_draft.gen.go +++ b/backend/domain/plugin/internal/dal/model/plugin_draft.gen.go @@ -5,7 +5,7 @@ package model import ( - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" + "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "gorm.io/gorm" ) @@ -13,18 +13,18 @@ const TableNamePluginDraft = "plugin_draft" // PluginDraft Draft Plugin type PluginDraft struct { - ID int64 `gorm:"column:id;primaryKey;comment:Plugin ID" json:"id"` // Plugin ID - SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID - DeveloperID int64 `gorm:"column:developer_id;not null;comment:Developer ID" json:"developer_id"` // Developer ID - AppID int64 `gorm:"column:app_id;not null;comment:Application ID" json:"app_id"` // Application ID - IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI - ServerURL string `gorm:"column:server_url;not null;comment:Server URL" json:"server_url"` // Server URL - PluginType int32 `gorm:"column:plugin_type;not null;comment:Plugin Type, 1:http, 6:local" json:"plugin_type"` // Plugin Type, 1:http, 6:local - CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds - UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds - DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:Delete Time" json:"deleted_at"` // Delete Time - Manifest *plugin.PluginManifest `gorm:"column:manifest;comment:Plugin Manifest;serializer:json" json:"manifest"` // Plugin Manifest - OpenapiDoc *plugin.Openapi3T `gorm:"column:openapi_doc;comment:OpenAPI Document, only stores the root;serializer:json" json:"openapi_doc"` // OpenAPI Document, only stores the root + ID int64 `gorm:"column:id;primaryKey;comment:Plugin ID" json:"id"` // Plugin ID + SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID + DeveloperID int64 `gorm:"column:developer_id;not null;comment:Developer ID" json:"developer_id"` // Developer ID + AppID int64 `gorm:"column:app_id;not null;comment:Application ID" json:"app_id"` // Application ID + IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI + ServerURL string `gorm:"column:server_url;not null;comment:Server URL" json:"server_url"` // Server URL + PluginType int32 `gorm:"column:plugin_type;not null;comment:Plugin Type, 1:http, 6:local" json:"plugin_type"` // Plugin Type, 1:http, 6:local + CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds + UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds + DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:Delete Time" json:"deleted_at"` // Delete Time + Manifest *dto.PluginManifest `gorm:"column:manifest;comment:Plugin Manifest;serializer:json" json:"manifest"` // Plugin Manifest + OpenapiDoc *dto.Openapi3T `gorm:"column:openapi_doc;comment:OpenAPI Document, only stores the root;serializer:json" json:"openapi_doc"` // OpenAPI Document, only stores the root } // TableName PluginDraft's table name diff --git a/backend/domain/plugin/internal/dal/model/plugin_oauth_auth.gen.go b/backend/domain/plugin/internal/dal/model/plugin_oauth_auth.gen.go index e92e744e1..0310def73 100644 --- a/backend/domain/plugin/internal/dal/model/plugin_oauth_auth.gen.go +++ b/backend/domain/plugin/internal/dal/model/plugin_oauth_auth.gen.go @@ -4,7 +4,7 @@ package model -import "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" +import plugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" const TableNamePluginOauthAuth = "plugin_oauth_auth" diff --git a/backend/domain/plugin/internal/dal/model/plugin_version.gen.go b/backend/domain/plugin/internal/dal/model/plugin_version.gen.go index f532c05a6..59538fef1 100644 --- a/backend/domain/plugin/internal/dal/model/plugin_version.gen.go +++ b/backend/domain/plugin/internal/dal/model/plugin_version.gen.go @@ -5,7 +5,7 @@ package model import ( - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" + "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "gorm.io/gorm" ) @@ -13,20 +13,20 @@ const TableNamePluginVersion = "plugin_version" // PluginVersion Plugin Version type PluginVersion struct { - ID int64 `gorm:"column:id;primaryKey;comment:Primary Key ID" json:"id"` // Primary Key ID - SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID - DeveloperID int64 `gorm:"column:developer_id;not null;comment:Developer ID" json:"developer_id"` // Developer ID - PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID - AppID int64 `gorm:"column:app_id;not null;comment:Application ID" json:"app_id"` // Application ID - IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI - ServerURL string `gorm:"column:server_url;not null;comment:Server URL" json:"server_url"` // Server URL - PluginType int32 `gorm:"column:plugin_type;not null;comment:Plugin Type, 1:http, 6:local" json:"plugin_type"` // Plugin Type, 1:http, 6:local - Version string `gorm:"column:version;not null;comment:Plugin Version, e.g. v1.0.0" json:"version"` // Plugin Version, e.g. v1.0.0 - VersionDesc string `gorm:"column:version_desc;comment:Plugin Version Description" json:"version_desc"` // Plugin Version Description - Manifest *plugin.PluginManifest `gorm:"column:manifest;comment:Plugin Manifest;serializer:json" json:"manifest"` // Plugin Manifest - OpenapiDoc *plugin.Openapi3T `gorm:"column:openapi_doc;comment:OpenAPI Document, only stores the root;serializer:json" json:"openapi_doc"` // OpenAPI Document, only stores the root - CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds - DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:Delete Time" json:"deleted_at"` // Delete Time + ID int64 `gorm:"column:id;primaryKey;comment:Primary Key ID" json:"id"` // Primary Key ID + SpaceID int64 `gorm:"column:space_id;not null;comment:Space ID" json:"space_id"` // Space ID + DeveloperID int64 `gorm:"column:developer_id;not null;comment:Developer ID" json:"developer_id"` // Developer ID + PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID + AppID int64 `gorm:"column:app_id;not null;comment:Application ID" json:"app_id"` // Application ID + IconURI string `gorm:"column:icon_uri;not null;comment:Icon URI" json:"icon_uri"` // Icon URI + ServerURL string `gorm:"column:server_url;not null;comment:Server URL" json:"server_url"` // Server URL + PluginType int32 `gorm:"column:plugin_type;not null;comment:Plugin Type, 1:http, 6:local" json:"plugin_type"` // Plugin Type, 1:http, 6:local + Version string `gorm:"column:version;not null;comment:Plugin Version, e.g. v1.0.0" json:"version"` // Plugin Version, e.g. v1.0.0 + VersionDesc string `gorm:"column:version_desc;comment:Plugin Version Description" json:"version_desc"` // Plugin Version Description + Manifest *dto.PluginManifest `gorm:"column:manifest;comment:Plugin Manifest;serializer:json" json:"manifest"` // Plugin Manifest + OpenapiDoc *dto.Openapi3T `gorm:"column:openapi_doc;comment:OpenAPI Document, only stores the root;serializer:json" json:"openapi_doc"` // OpenAPI Document, only stores the root + CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds + DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:Delete Time" json:"deleted_at"` // Delete Time } // TableName PluginVersion's table name diff --git a/backend/domain/plugin/internal/dal/model/tool.gen.go b/backend/domain/plugin/internal/dal/model/tool.gen.go index 9d6d648ca..e7bd23673 100644 --- a/backend/domain/plugin/internal/dal/model/tool.gen.go +++ b/backend/domain/plugin/internal/dal/model/tool.gen.go @@ -4,21 +4,21 @@ package model -import "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" +import "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" const TableNameTool = "tool" // Tool Latest Tool type Tool struct { - ID int64 `gorm:"column:id;primaryKey;comment:Tool ID" json:"id"` // Tool ID - PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID - CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds - UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds - Version string `gorm:"column:version;not null;comment:Tool Version, e.g. v1.0.0" json:"version"` // Tool Version, e.g. v1.0.0 - SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path - Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method - Operation *plugin.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema - ActivatedStatus int32 `gorm:"column:activated_status;not null;comment:0:activated; 1:deactivated" json:"activated_status"` // 0:activated; 1:deactivated + ID int64 `gorm:"column:id;primaryKey;comment:Tool ID" json:"id"` // Tool ID + PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID + CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds + UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds + Version string `gorm:"column:version;not null;comment:Tool Version, e.g. v1.0.0" json:"version"` // Tool Version, e.g. v1.0.0 + SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path + Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method + Operation *dto.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema + ActivatedStatus int32 `gorm:"column:activated_status;not null;comment:0:activated; 1:deactivated" json:"activated_status"` // 0:activated; 1:deactivated } // TableName Tool's table name diff --git a/backend/domain/plugin/internal/dal/model/tool_draft.gen.go b/backend/domain/plugin/internal/dal/model/tool_draft.gen.go index fba630e2f..9f0ec2473 100644 --- a/backend/domain/plugin/internal/dal/model/tool_draft.gen.go +++ b/backend/domain/plugin/internal/dal/model/tool_draft.gen.go @@ -4,21 +4,21 @@ package model -import "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" +import "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" const TableNameToolDraft = "tool_draft" // ToolDraft Draft Tool type ToolDraft struct { - ID int64 `gorm:"column:id;primaryKey;comment:Tool ID" json:"id"` // Tool ID - PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID - CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds - UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds - SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path - Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method - Operation *plugin.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema - DebugStatus int32 `gorm:"column:debug_status;not null;comment:0:not pass; 1:pass" json:"debug_status"` // 0:not pass; 1:pass - ActivatedStatus int32 `gorm:"column:activated_status;not null;comment:0:activated; 1:deactivated" json:"activated_status"` // 0:activated; 1:deactivated + ID int64 `gorm:"column:id;primaryKey;comment:Tool ID" json:"id"` // Tool ID + PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID + CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds + UpdatedAt int64 `gorm:"column:updated_at;not null;autoUpdateTime:milli;comment:Update Time in Milliseconds" json:"updated_at"` // Update Time in Milliseconds + SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path + Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method + Operation *dto.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema + DebugStatus int32 `gorm:"column:debug_status;not null;comment:0:not pass; 1:pass" json:"debug_status"` // 0:not pass; 1:pass + ActivatedStatus int32 `gorm:"column:activated_status;not null;comment:0:activated; 1:deactivated" json:"activated_status"` // 0:activated; 1:deactivated } // TableName ToolDraft's table name diff --git a/backend/domain/plugin/internal/dal/model/tool_version.gen.go b/backend/domain/plugin/internal/dal/model/tool_version.gen.go index f31ed7f86..ce5f39cfe 100644 --- a/backend/domain/plugin/internal/dal/model/tool_version.gen.go +++ b/backend/domain/plugin/internal/dal/model/tool_version.gen.go @@ -5,7 +5,7 @@ package model import ( - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" + "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "gorm.io/gorm" ) @@ -13,15 +13,15 @@ const TableNameToolVersion = "tool_version" // ToolVersion Tool Version type ToolVersion struct { - ID int64 `gorm:"column:id;primaryKey;comment:Primary Key ID" json:"id"` // Primary Key ID - ToolID int64 `gorm:"column:tool_id;not null;comment:Tool ID" json:"tool_id"` // Tool ID - PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID - Version string `gorm:"column:version;not null;comment:Tool Version, e.g. v1.0.0" json:"version"` // Tool Version, e.g. v1.0.0 - SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path - Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method - Operation *plugin.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema - CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds - DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:Delete Time" json:"deleted_at"` // Delete Time + ID int64 `gorm:"column:id;primaryKey;comment:Primary Key ID" json:"id"` // Primary Key ID + ToolID int64 `gorm:"column:tool_id;not null;comment:Tool ID" json:"tool_id"` // Tool ID + PluginID int64 `gorm:"column:plugin_id;not null;comment:Plugin ID" json:"plugin_id"` // Plugin ID + Version string `gorm:"column:version;not null;comment:Tool Version, e.g. v1.0.0" json:"version"` // Tool Version, e.g. v1.0.0 + SubURL string `gorm:"column:sub_url;not null;comment:Sub URL Path" json:"sub_url"` // Sub URL Path + Method string `gorm:"column:method;not null;comment:HTTP Request Method" json:"method"` // HTTP Request Method + Operation *dto.Openapi3Operation `gorm:"column:operation;comment:Tool Openapi Operation Schema;serializer:json" json:"operation"` // Tool Openapi Operation Schema + CreatedAt int64 `gorm:"column:created_at;not null;autoCreateTime:milli;comment:Create Time in Milliseconds" json:"created_at"` // Create Time in Milliseconds + DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;comment:Delete Time" json:"deleted_at"` // Delete Time } // TableName ToolVersion's table name diff --git a/backend/domain/plugin/internal/dal/plugin.go b/backend/domain/plugin/internal/dal/plugin.go index 7c519188f..097126c26 100644 --- a/backend/domain/plugin/internal/dal/plugin.go +++ b/backend/domain/plugin/internal/dal/plugin.go @@ -25,8 +25,8 @@ import ( "gorm.io/gen/field" "gorm.io/gorm" - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" plugin_develop_common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + plugindto "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/model" "github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/query" @@ -49,7 +49,7 @@ type PluginDAO struct { type pluginPO model.Plugin func (p pluginPO) ToDO() *entity.PluginInfo { - return entity.NewPluginInfo(&plugin.PluginInfo{ + return entity.NewPluginInfo(&plugindto.PluginInfo{ ID: p.ID, SpaceID: p.SpaceID, DeveloperID: p.DeveloperID, @@ -174,56 +174,56 @@ func (p *PluginDAO) List(ctx context.Context, spaceID int64, pageInfo entity.Pag return plugins, total, nil } -func (p *PluginDAO) UpsertWithTX(ctx context.Context, tx *query.QueryTx, plugin *entity.PluginInfo) (err error) { +func (p *PluginDAO) UpsertWithTX(ctx context.Context, tx *query.QueryTx, pluginInfo *entity.PluginInfo) (err error) { table := tx.Plugin - _, err = table.WithContext(ctx).Select(table.ID).Where(table.ID.Eq(plugin.ID)).First() + _, err = table.WithContext(ctx).Select(table.ID).Where(table.ID.Eq(pluginInfo.ID)).First() if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { return err } m := &model.Plugin{ - ID: plugin.ID, - SpaceID: plugin.SpaceID, - DeveloperID: plugin.DeveloperID, - AppID: plugin.GetAPPID(), - Manifest: plugin.Manifest, - OpenapiDoc: plugin.OpenapiDoc, - PluginType: int32(plugin.PluginType), - IconURI: plugin.GetIconURI(), - ServerURL: plugin.GetServerURL(), - Version: plugin.GetVersion(), - VersionDesc: plugin.GetVersionDesc(), + ID: pluginInfo.ID, + SpaceID: pluginInfo.SpaceID, + DeveloperID: pluginInfo.DeveloperID, + AppID: pluginInfo.GetAPPID(), + Manifest: pluginInfo.Manifest, + OpenapiDoc: pluginInfo.OpenapiDoc, + PluginType: int32(pluginInfo.PluginType), + IconURI: pluginInfo.GetIconURI(), + ServerURL: pluginInfo.GetServerURL(), + Version: pluginInfo.GetVersion(), + VersionDesc: pluginInfo.GetVersionDesc(), } return table.WithContext(ctx).Create(m) } updateMap := map[string]any{} - if plugin.APPID != nil { - updateMap[table.AppID.ColumnName().String()] = *plugin.APPID + if pluginInfo.APPID != nil { + updateMap[table.AppID.ColumnName().String()] = *pluginInfo.APPID } - if plugin.IconURI != nil { - updateMap[table.IconURI.ColumnName().String()] = *plugin.IconURI + if pluginInfo.IconURI != nil { + updateMap[table.IconURI.ColumnName().String()] = *pluginInfo.IconURI } - if plugin.Version != nil { - updateMap[table.Version.ColumnName().String()] = *plugin.Version + if pluginInfo.Version != nil { + updateMap[table.Version.ColumnName().String()] = *pluginInfo.Version } - if plugin.VersionDesc != nil { - updateMap[table.VersionDesc.ColumnName().String()] = *plugin.VersionDesc + if pluginInfo.VersionDesc != nil { + updateMap[table.VersionDesc.ColumnName().String()] = *pluginInfo.VersionDesc } - if plugin.ServerURL != nil { - updateMap[table.ServerURL.ColumnName().String()] = *plugin.ServerURL + if pluginInfo.ServerURL != nil { + updateMap[table.ServerURL.ColumnName().String()] = *pluginInfo.ServerURL } - if plugin.Manifest != nil { - b, err := json.Marshal(plugin.Manifest) + if pluginInfo.Manifest != nil { + b, err := json.Marshal(pluginInfo.Manifest) if err != nil { return err } updateMap[table.Manifest.ColumnName().String()] = b } - if plugin.OpenapiDoc != nil { - b, err := json.Marshal(plugin.OpenapiDoc) + if pluginInfo.OpenapiDoc != nil { + b, err := json.Marshal(pluginInfo.OpenapiDoc) if err != nil { return err } @@ -231,7 +231,7 @@ func (p *PluginDAO) UpsertWithTX(ctx context.Context, tx *query.QueryTx, plugin } _, err = table.WithContext(ctx). - Where(table.ID.Eq(plugin.ID)). + Where(table.ID.Eq(pluginInfo.ID)). Updates(updateMap) if err != nil { return err diff --git a/backend/domain/plugin/internal/dal/plugin_draft.go b/backend/domain/plugin/internal/dal/plugin_draft.go index b231a312c..76b0ddd7a 100644 --- a/backend/domain/plugin/internal/dal/plugin_draft.go +++ b/backend/domain/plugin/internal/dal/plugin_draft.go @@ -25,8 +25,8 @@ import ( "gorm.io/gen/field" "gorm.io/gorm" - pluginModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" plugin_develop_common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + pluginModel "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/conf" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/model" diff --git a/backend/domain/plugin/internal/dal/plugin_version.go b/backend/domain/plugin/internal/dal/plugin_version.go index c1acfd7a9..e875e080c 100644 --- a/backend/domain/plugin/internal/dal/plugin_version.go +++ b/backend/domain/plugin/internal/dal/plugin_version.go @@ -24,8 +24,8 @@ import ( "gorm.io/gen/field" "gorm.io/gorm" - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" plugin_develop_common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/model" "github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/query" @@ -48,7 +48,7 @@ type PluginVersionDAO struct { type pluginVersionPO model.PluginVersion func (p pluginVersionPO) ToDO() *entity.PluginInfo { - return entity.NewPluginInfo(&plugin.PluginInfo{ + return entity.NewPluginInfo(&dto.PluginInfo{ ID: p.PluginID, SpaceID: p.SpaceID, APPID: &p.AppID, diff --git a/backend/domain/plugin/internal/dal/tool.go b/backend/domain/plugin/internal/dal/tool.go index 7df4f31b5..cbe4354d6 100644 --- a/backend/domain/plugin/internal/dal/tool.go +++ b/backend/domain/plugin/internal/dal/tool.go @@ -24,7 +24,7 @@ import ( "gorm.io/gen/field" "gorm.io/gorm" - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" + plugindto "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/model" "github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/query" @@ -57,7 +57,7 @@ func (t toolPO) ToDO() *entity.ToolInfo { SubURL: &t.SubURL, Method: ptr.Of(t.Method), Operation: t.Operation, - ActivatedStatus: ptr.Of(plugin.ActivatedStatus(t.ActivatedStatus)), + ActivatedStatus: ptr.Of(plugindto.ActivatedStatus(t.ActivatedStatus)), } } diff --git a/backend/domain/plugin/internal/dal/tool_draft.go b/backend/domain/plugin/internal/dal/tool_draft.go index e12746ce4..492563492 100644 --- a/backend/domain/plugin/internal/dal/tool_draft.go +++ b/backend/domain/plugin/internal/dal/tool_draft.go @@ -25,8 +25,8 @@ import ( "gorm.io/gen/field" "gorm.io/gorm" - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + plugindto "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/conf" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/model" @@ -60,7 +60,7 @@ func (t toolDraftPO) ToDO() *entity.ToolInfo { Method: ptr.Of(t.Method), Operation: t.Operation, DebugStatus: ptr.Of(common.APIDebugStatus(t.DebugStatus)), - ActivatedStatus: ptr.Of(plugin.ActivatedStatus(t.ActivatedStatus)), + ActivatedStatus: ptr.Of(plugindto.ActivatedStatus(t.ActivatedStatus)), } } diff --git a/backend/domain/plugin/internal/encoder/req_encode.go b/backend/domain/plugin/internal/encoder/req_encode.go index 1a7e1525f..079acef59 100644 --- a/backend/domain/plugin/internal/encoder/req_encode.go +++ b/backend/domain/plugin/internal/encoder/req_encode.go @@ -27,7 +27,7 @@ import ( "github.com/shopspring/decimal" "gopkg.in/yaml.v3" - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" + plugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" ) func EncodeBodyWithContentType(contentType string, body map[string]any) ([]byte, error) { diff --git a/backend/domain/plugin/internal/openapi/convert_protocol.go b/backend/domain/plugin/internal/openapi/convert_protocol.go index bb35e34ba..90e2feabf 100644 --- a/backend/domain/plugin/internal/openapi/convert_protocol.go +++ b/backend/domain/plugin/internal/openapi/convert_protocol.go @@ -34,7 +34,7 @@ import ( postman "github.com/rbretecher/go-postman-collection" "gopkg.in/yaml.v3" - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/pkg/errorx" "github.com/coze-dev/coze-studio/backend/pkg/lang/ptr" diff --git a/backend/domain/plugin/repository/plugin_impl.go b/backend/domain/plugin/repository/plugin_impl.go index 2c2949c5e..1ff36b2d5 100644 --- a/backend/domain/plugin/repository/plugin_impl.go +++ b/backend/domain/plugin/repository/plugin_impl.go @@ -25,8 +25,8 @@ import ( "github.com/jinzhu/copier" "gorm.io/gorm" - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" pluginConf "github.com/coze-dev/coze-studio/backend/domain/plugin/conf" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal" diff --git a/backend/domain/plugin/repository/plugin_repository.go b/backend/domain/plugin/repository/plugin_repository.go index 56e52d4bb..0b27cff37 100644 --- a/backend/domain/plugin/repository/plugin_repository.go +++ b/backend/domain/plugin/repository/plugin_repository.go @@ -19,7 +19,7 @@ package repository import ( "context" - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" + plugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" ) diff --git a/backend/domain/plugin/service/agent_tool.go b/backend/domain/plugin/service/agent_tool.go index 9c0899716..45ded75f4 100644 --- a/backend/domain/plugin/service/agent_tool.go +++ b/backend/domain/plugin/service/agent_tool.go @@ -24,7 +24,8 @@ import ( "github.com/getkin/kin-openapi/openapi3" - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" + "github.com/coze-dev/coze-studio/backend/domain/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/domain/plugin/repository" "github.com/coze-dev/coze-studio/backend/pkg/errorx" @@ -64,7 +65,7 @@ func (p *pluginServiceImpl) GetDraftAgentToolByName(ctx context.Context, agentID return draftAgentTool, nil } -func (p *pluginServiceImpl) MGetAgentTools(ctx context.Context, req *MGetAgentToolsRequest) (tools []*entity.ToolInfo, err error) { +func (p *pluginServiceImpl) MGetAgentTools(ctx context.Context, req *model.MGetAgentToolsRequest) (tools []*entity.ToolInfo, err error) { toolIDs := make([]int64, 0, len(req.VersionAgentTools)) for _, v := range req.VersionAgentTools { toolIDs = append(toolIDs, v.ToolID) @@ -129,7 +130,7 @@ func (p *pluginServiceImpl) PublishAgentTools(ctx context.Context, agentID int64 return nil } -func (p *pluginServiceImpl) UpdateBotDefaultParams(ctx context.Context, req *UpdateBotDefaultParamsRequest) (err error) { +func (p *pluginServiceImpl) UpdateBotDefaultParams(ctx context.Context, req *dto.UpdateBotDefaultParamsRequest) (err error) { _, exist, err := p.pluginRepo.GetOnlinePlugin(ctx, req.PluginID, repository.WithPluginID()) if err != nil { return errorx.Wrapf(err, "GetOnlinePlugin failed, pluginID=%d", req.PluginID) diff --git a/backend/domain/plugin/service/exec_tool.go b/backend/domain/plugin/service/exec_tool.go index 9b5b5d65a..bdbbc6280 100644 --- a/backend/domain/plugin/service/exec_tool.go +++ b/backend/domain/plugin/service/exec_tool.go @@ -28,8 +28,8 @@ import ( "github.com/bytedance/sonic" "github.com/getkin/kin-openapi/openapi3" - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/domain/plugin/service/tool" "github.com/coze-dev/coze-studio/backend/infra/contract/storage" @@ -39,7 +39,7 @@ import ( "github.com/coze-dev/coze-studio/backend/types/errno" ) -func (p *pluginServiceImpl) ExecuteTool(ctx context.Context, req *ExecuteToolRequest, opts ...entity.ExecuteToolOpt) (resp *ExecuteToolResponse, err error) { +func (p *pluginServiceImpl) ExecuteTool(ctx context.Context, req *model.ExecuteToolRequest, opts ...entity.ExecuteToolOpt) (resp *model.ExecuteToolResponse, err error) { opt := &model.ExecuteToolOption{} for _, fn := range opts { fn(opt) @@ -79,7 +79,7 @@ func (p *pluginServiceImpl) ExecuteTool(ctx context.Context, req *ExecuteToolReq } } - resp = &ExecuteToolResponse{ + resp = &model.ExecuteToolResponse{ Tool: executor.tool, Request: result.Request, RawResp: result.RawResp, @@ -90,7 +90,7 @@ func (p *pluginServiceImpl) ExecuteTool(ctx context.Context, req *ExecuteToolReq return resp, nil } -func (p *pluginServiceImpl) acquireAccessTokenIfNeed(ctx context.Context, req *ExecuteToolRequest, authInfo *model.AuthV2, +func (p *pluginServiceImpl) acquireAccessTokenIfNeed(ctx context.Context, req *model.ExecuteToolRequest, authInfo *model.AuthV2, schema *model.Openapi3Operation) (accessToken string, authURL string, err error) { if authInfo.Type == model.AuthzTypeOfNone { return "", "", nil @@ -132,7 +132,7 @@ func (p *pluginServiceImpl) acquireAccessTokenIfNeed(ctx context.Context, req *E return accessToken, authURL, nil } -func (p *pluginServiceImpl) buildToolExecutor(ctx context.Context, req *ExecuteToolRequest, opt *model.ExecuteToolOption) (impl *toolExecutor, err error) { +func (p *pluginServiceImpl) buildToolExecutor(ctx context.Context, req *model.ExecuteToolRequest, opt *model.ExecuteToolOption) (impl *toolExecutor, err error) { if req.UserID == "" { return nil, errorx.New(errno.ErrPluginExecuteToolFailed, errorx.KV(errno.PluginMsgKey, "userID is required")) } @@ -175,7 +175,7 @@ func (p *pluginServiceImpl) buildToolExecutor(ctx context.Context, req *ExecuteT return impl, nil } -func (p *pluginServiceImpl) getDraftAgentPluginInfo(ctx context.Context, req *ExecuteToolRequest, +func (p *pluginServiceImpl) getDraftAgentPluginInfo(ctx context.Context, req *model.ExecuteToolRequest, execOpt *model.ExecuteToolOption) (onlinePlugin *entity.PluginInfo, onlineTool *entity.ToolInfo, err error) { if req.ExecDraftTool { @@ -227,7 +227,7 @@ func (p *pluginServiceImpl) getDraftAgentPluginInfo(ctx context.Context, req *Ex return onlinePlugin, onlineTool, nil } -func (p *pluginServiceImpl) getOnlineAgentPluginInfo(ctx context.Context, req *ExecuteToolRequest, +func (p *pluginServiceImpl) getOnlineAgentPluginInfo(ctx context.Context, req *model.ExecuteToolRequest, execOpt *model.ExecuteToolOption) (onlinePlugin *entity.PluginInfo, onlineTool *entity.ToolInfo, err error) { if req.ExecDraftTool { @@ -283,7 +283,7 @@ func (p *pluginServiceImpl) getOnlineAgentPluginInfo(ctx context.Context, req *E return onlinePlugin, onlineTool, nil } -func (p *pluginServiceImpl) getWorkflowPluginInfo(ctx context.Context, req *ExecuteToolRequest, +func (p *pluginServiceImpl) getWorkflowPluginInfo(ctx context.Context, req *model.ExecuteToolRequest, execOpt *model.ExecuteToolOption) (pl *entity.PluginInfo, tl *entity.ToolInfo, err error) { if req.ExecDraftTool { @@ -351,7 +351,7 @@ func (p *pluginServiceImpl) getWorkflowPluginInfo(ctx context.Context, req *Exec return pl, tl, nil } -func (p *pluginServiceImpl) getToolDebugPluginInfo(ctx context.Context, req *ExecuteToolRequest, +func (p *pluginServiceImpl) getToolDebugPluginInfo(ctx context.Context, req *model.ExecuteToolRequest, _ *model.ExecuteToolOption) (pl *entity.PluginInfo, tl *entity.ToolInfo, err error) { if req.ExecDraftTool { diff --git a/backend/domain/plugin/service/exec_tool_test.go b/backend/domain/plugin/service/exec_tool_test.go index e5ccfc79a..ef7fb7dfa 100644 --- a/backend/domain/plugin/service/exec_tool_test.go +++ b/backend/domain/plugin/service/exec_tool_test.go @@ -27,7 +27,7 @@ import ( "github.com/getkin/kin-openapi/openapi3" "github.com/stretchr/testify/assert" - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/pkg/errorx" ) diff --git a/backend/domain/plugin/service/plugin_draft.go b/backend/domain/plugin/service/plugin_draft.go index 392425868..5627247d6 100644 --- a/backend/domain/plugin/service/plugin_draft.go +++ b/backend/domain/plugin/service/plugin_draft.go @@ -28,12 +28,13 @@ import ( "github.com/getkin/kin-openapi/openapi3" "gopkg.in/yaml.v3" - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" searchModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/search" common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" plugin_develop_common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" resCommon "github.com/coze-dev/coze-studio/backend/api/model/resource/common" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" crosssearch "github.com/coze-dev/coze-studio/backend/crossdomain/contract/search" + "github.com/coze-dev/coze-studio/backend/domain/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/domain/plugin/internal/openapi" "github.com/coze-dev/coze-studio/backend/domain/plugin/repository" @@ -44,7 +45,7 @@ import ( "github.com/coze-dev/coze-studio/backend/types/errno" ) -func (p *pluginServiceImpl) CreateDraftPlugin(ctx context.Context, req *CreateDraftPluginRequest) (pluginID int64, err error) { +func (p *pluginServiceImpl) CreateDraftPlugin(ctx context.Context, req *dto.CreateDraftPluginRequest) (pluginID int64, err error) { mf := entity.NewDefaultPluginManifest() mf.CommonParams = map[model.HTTPParamLocation][]*plugin_develop_common.CommonParamSchema{} mf.NameForHuman = req.Name @@ -54,7 +55,7 @@ func (p *pluginServiceImpl) CreateDraftPlugin(ctx context.Context, req *CreateDr mf.API.Type, _ = model.ToPluginType(req.PluginType) mf.LogoURL = req.IconURI - authV2, err := req.AuthInfo.toAuthV2() + authV2, err := req.AuthInfo.ToAuthV2() if err != nil { return 0, err } @@ -130,7 +131,7 @@ func (p *pluginServiceImpl) MGetDraftPlugins(ctx context.Context, pluginIDs []in return plugins, nil } -func (p *pluginServiceImpl) ListDraftPlugins(ctx context.Context, req *ListDraftPluginsRequest) (resp *ListDraftPluginsResponse, err error) { +func (p *pluginServiceImpl) ListDraftPlugins(ctx context.Context, req *dto.ListDraftPluginsRequest) (resp *dto.ListDraftPluginsResponse, err error) { if req.PageInfo.Name == nil || *req.PageInfo.Name == "" { res, err := p.pluginRepo.ListDraftPlugins(ctx, &repository.ListDraftPluginsRequest{ SpaceID: req.SpaceID, @@ -141,7 +142,7 @@ func (p *pluginServiceImpl) ListDraftPlugins(ctx context.Context, req *ListDraft return nil, errorx.Wrapf(err, "ListDraftPlugins failed, spaceID=%d, appID=%d", req.SpaceID, req.APPID) } - return &ListDraftPluginsResponse{ + return &dto.ListDraftPluginsResponse{ Plugins: res.Plugins, Total: res.Total, }, nil @@ -186,13 +187,13 @@ func (p *pluginServiceImpl) ListDraftPlugins(ctx context.Context, req *ListDraft total = *res.TotalHits } - return &ListDraftPluginsResponse{ + return &dto.ListDraftPluginsResponse{ Plugins: plugins, Total: total, }, nil } -func (p *pluginServiceImpl) CreateDraftPluginWithCode(ctx context.Context, req *CreateDraftPluginWithCodeRequest) (resp *CreateDraftPluginWithCodeResponse, err error) { +func (p *pluginServiceImpl) CreateDraftPluginWithCode(ctx context.Context, req *dto.CreateDraftPluginWithCodeRequest) (resp *dto.CreateDraftPluginWithCodeResponse, err error) { err = req.OpenapiDoc.Validate(ctx) if err != nil { return nil, err @@ -213,7 +214,7 @@ func (p *pluginServiceImpl) CreateDraftPluginWithCode(ctx context.Context, req * return nil, errorx.Wrapf(err, "CreateDraftPluginWithCode failed") } - resp = &CreateDraftPluginWithCodeResponse{ + resp = &dto.CreateDraftPluginWithCodeResponse{ Plugin: res.Plugin, Tools: res.Tools, } @@ -221,7 +222,7 @@ func (p *pluginServiceImpl) CreateDraftPluginWithCode(ctx context.Context, req * return resp, nil } -func (p *pluginServiceImpl) UpdateDraftPluginWithCode(ctx context.Context, req *UpdateDraftPluginWithCodeRequest) (err error) { +func (p *pluginServiceImpl) UpdateDraftPluginWithCode(ctx context.Context, req *dto.UpdateDraftPluginWithCodeRequest) (err error) { doc := req.OpenapiDoc mf := req.Manifest @@ -451,7 +452,7 @@ func isJsonSchemaEqual(nsc, osc *openapi3.Schema) bool { return true } -func (p *pluginServiceImpl) UpdateDraftPlugin(ctx context.Context, req *UpdateDraftPluginRequest) (err error) { +func (p *pluginServiceImpl) UpdateDraftPlugin(ctx context.Context, req *dto.UpdateDraftPluginRequest) (err error) { oldPlugin, exist, err := p.pluginRepo.GetDraftPlugin(ctx, req.PluginID) if err != nil { return errorx.Wrapf(err, "GetDraftPlugin failed, pluginID=%d", req.PluginID) @@ -494,7 +495,7 @@ func (p *pluginServiceImpl) UpdateDraftPlugin(ctx context.Context, req *UpdateDr return nil } -func updatePluginOpenapiDoc(_ context.Context, doc *model.Openapi3T, req *UpdateDraftPluginRequest) (*model.Openapi3T, error) { +func updatePluginOpenapiDoc(_ context.Context, doc *model.Openapi3T, req *dto.UpdateDraftPluginRequest) (*model.Openapi3T, error) { if req.Name != nil { doc.Info.Title = *req.Name } @@ -518,7 +519,7 @@ func updatePluginOpenapiDoc(_ context.Context, doc *model.Openapi3T, req *Update return doc, nil } -func updatePluginManifest(_ context.Context, mf *entity.PluginManifest, req *UpdateDraftPluginRequest) (*entity.PluginManifest, error) { +func updatePluginManifest(_ context.Context, mf *entity.PluginManifest, req *dto.UpdateDraftPluginRequest) (*entity.PluginManifest, error) { if req.Name != nil { mf.NameForHuman = *req.Name mf.NameForModel = *req.Name @@ -554,7 +555,7 @@ func updatePluginManifest(_ context.Context, mf *entity.PluginManifest, req *Upd } if req.AuthInfo != nil { - authV2, err := req.AuthInfo.toAuthV2() + authV2, err := req.AuthInfo.ToAuthV2() if err != nil { return nil, err } @@ -578,7 +579,7 @@ func (p *pluginServiceImpl) MGetDraftTools(ctx context.Context, toolIDs []int64) return tools, nil } -func (p *pluginServiceImpl) UpdateDraftTool(ctx context.Context, req *UpdateDraftToolRequest) (err error) { +func (p *pluginServiceImpl) UpdateDraftTool(ctx context.Context, req *dto.UpdateDraftToolRequest) (err error) { draftPlugin, exist, err := p.pluginRepo.GetDraftPlugin(ctx, req.PluginID) if err != nil { return errorx.Wrapf(err, "GetDraftPlugin failed, pluginID=%d", req.PluginID) @@ -602,7 +603,7 @@ func (p *pluginServiceImpl) UpdateDraftTool(ctx context.Context, req *UpdateDraf return p.updateDraftTool(ctx, req, draftTool) } -func (p *pluginServiceImpl) updateDraftTool(ctx context.Context, req *UpdateDraftToolRequest, draftTool *entity.ToolInfo) (err error) { +func (p *pluginServiceImpl) updateDraftTool(ctx context.Context, req *dto.UpdateDraftToolRequest, draftTool *entity.ToolInfo) (err error) { if req.Method != nil && req.SubURL != nil { api := entity.UniqueToolAPI{ SubURL: ptr.FromOrDefault(req.SubURL, ""), @@ -778,7 +779,7 @@ func (p *pluginServiceImpl) updateDraftToolDebugExample(ctx context.Context, dra return nil } -func (p *pluginServiceImpl) ConvertToOpenapi3Doc(ctx context.Context, req *ConvertToOpenapi3DocRequest) (resp *ConvertToOpenapi3DocResponse) { +func (p *pluginServiceImpl) ConvertToOpenapi3Doc(ctx context.Context, req *dto.ConvertToOpenapi3DocRequest) (resp *dto.ConvertToOpenapi3DocResponse) { var err error defer func() { if err != nil { @@ -793,7 +794,7 @@ func (p *pluginServiceImpl) ConvertToOpenapi3Doc(ctx context.Context, req *Conve } }() - resp = &ConvertToOpenapi3DocResponse{} + resp = &dto.ConvertToOpenapi3DocResponse{} cvt, format, err := getConvertFunc(ctx, req.RawInput) if err != nil { @@ -813,7 +814,7 @@ func (p *pluginServiceImpl) ConvertToOpenapi3Doc(ctx context.Context, req *Conve return resp } - return &ConvertToOpenapi3DocResponse{ + return &dto.ConvertToOpenapi3DocResponse{ OpenapiDoc: doc, Manifest: mf, Format: format, @@ -856,7 +857,7 @@ func getConvertFunc(ctx context.Context, rawInput string) (convertFunc, common.P return nil, 0, fmt.Errorf("invalid schema") } -func validateConvertResult(ctx context.Context, req *ConvertToOpenapi3DocRequest, doc *model.Openapi3T, mf *entity.PluginManifest) error { +func validateConvertResult(ctx context.Context, req *dto.ConvertToOpenapi3DocRequest, doc *model.Openapi3T, mf *entity.PluginManifest) error { if req.PluginServerURL != nil { if doc.Servers[0].URL != *req.PluginServerURL { return errorx.New(errno.ErrPluginConvertProtocolFailed, errorx.KV(errno.PluginMsgKey, "inconsistent API URL prefix")) @@ -876,7 +877,7 @@ func validateConvertResult(ctx context.Context, req *ConvertToOpenapi3DocRequest return nil } -func (p *pluginServiceImpl) CreateDraftToolsWithCode(ctx context.Context, req *CreateDraftToolsWithCodeRequest) (resp *CreateDraftToolsWithCodeResponse, err error) { +func (p *pluginServiceImpl) CreateDraftToolsWithCode(ctx context.Context, req *dto.CreateDraftToolsWithCodeRequest) (resp *dto.CreateDraftToolsWithCodeResponse, err error) { err = req.OpenapiDoc.Validate(ctx) if err != nil { return nil, err @@ -908,7 +909,7 @@ func (p *pluginServiceImpl) CreateDraftToolsWithCode(ctx context.Context, req *C } if !req.ConflictAndUpdate && len(duplicatedTools) > 0 { - return &CreateDraftToolsWithCodeResponse{ + return &dto.CreateDraftToolsWithCodeResponse{ DuplicatedTools: duplicatedTools, }, nil } @@ -932,7 +933,7 @@ func (p *pluginServiceImpl) CreateDraftToolsWithCode(ctx context.Context, req *C return nil, errorx.Wrapf(err, "UpsertDraftTools failed, pluginID=%d", req.PluginID) } - resp = &CreateDraftToolsWithCodeResponse{} + resp = &dto.CreateDraftToolsWithCodeResponse{} return resp, nil } diff --git a/backend/domain/plugin/service/plugin_oauth.go b/backend/domain/plugin/service/plugin_oauth.go index 8e5390e34..2325abeb9 100644 --- a/backend/domain/plugin/service/plugin_oauth.go +++ b/backend/domain/plugin/service/plugin_oauth.go @@ -27,9 +27,10 @@ import ( "golang.org/x/oauth2" - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/conf" + "github.com/coze-dev/coze-studio/backend/domain/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/encrypt" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/pkg/errorx" @@ -363,7 +364,7 @@ func (p *pluginServiceImpl) RevokeAccessToken(ctx context.Context, meta *entity. return p.oauthRepo.DeleteAuthorizationCode(ctx, meta) } -func (p *pluginServiceImpl) GetOAuthStatus(ctx context.Context, userID, pluginID int64) (resp *GetOAuthStatusResponse, err error) { +func (p *pluginServiceImpl) GetOAuthStatus(ctx context.Context, userID, pluginID int64) (resp *dto.GetOAuthStatusResponse, err error) { pl, exist, err := p.pluginRepo.GetDraftPlugin(ctx, pluginID) if err != nil { return nil, err @@ -374,7 +375,7 @@ func (p *pluginServiceImpl) GetOAuthStatus(ctx context.Context, userID, pluginID authInfo := pl.GetAuthInfo() if authInfo.Type == model.AuthzTypeOfNone || authInfo.Type == model.AuthzTypeOfService { - return &GetOAuthStatusResponse{ + return &dto.GetOAuthStatusResponse{ IsOauth: false, }, nil } @@ -389,7 +390,7 @@ func (p *pluginServiceImpl) GetOAuthStatus(ctx context.Context, userID, pluginID status = common.OAuthStatus_Unauthorized } - resp = &GetOAuthStatusResponse{ + resp = &dto.GetOAuthStatusResponse{ IsOauth: true, Status: status, OAuthURL: authURL, @@ -480,7 +481,7 @@ func getStanderOAuthConfig(config *model.OAuthAuthorizationCodeConfig) *oauth2.C } } -func (p *pluginServiceImpl) GetAgentPluginsOAuthStatus(ctx context.Context, userID, agentID int64) (status []*AgentPluginOAuthStatus, err error) { +func (p *pluginServiceImpl) GetAgentPluginsOAuthStatus(ctx context.Context, userID, agentID int64) (status []*dto.AgentPluginOAuthStatus, err error) { pluginIDs, err := p.toolRepo.GetAgentPluginIDs(ctx, agentID) if err != nil { return nil, errorx.Wrapf(err, "GetAgentPluginIDs failed, agentID=%d", agentID) @@ -517,7 +518,7 @@ func (p *pluginServiceImpl) GetAgentPluginsOAuthStatus(ctx context.Context, user authStatus = common.OAuthStatus_Unauthorized } - status = append(status, &AgentPluginOAuthStatus{ + status = append(status, &dto.AgentPluginOAuthStatus{ PluginID: plugin.ID, PluginName: plugin.GetName(), PluginIconURL: iconURL, diff --git a/backend/domain/plugin/service/plugin_online.go b/backend/domain/plugin/service/plugin_online.go index 18c07c0be..fc6964c75 100644 --- a/backend/domain/plugin/service/plugin_online.go +++ b/backend/domain/plugin/service/plugin_online.go @@ -21,12 +21,13 @@ import ( "fmt" "sort" - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" searchModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/search" pluginCommon "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" resCommon "github.com/coze-dev/coze-studio/backend/api/model/resource/common" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" crosssearch "github.com/coze-dev/coze-studio/backend/crossdomain/contract/search" pluginConf "github.com/coze-dev/coze-studio/backend/domain/plugin/conf" + "github.com/coze-dev/coze-studio/backend/domain/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/domain/plugin/repository" "github.com/coze-dev/coze-studio/backend/pkg/errorx" @@ -92,7 +93,7 @@ func (p *pluginServiceImpl) MGetVersionTools(ctx context.Context, versionTools [ return tools, nil } -func (p *pluginServiceImpl) ListPluginProducts(ctx context.Context, req *ListPluginProductsRequest) (resp *ListPluginProductsResponse, err error) { +func (p *pluginServiceImpl) ListPluginProducts(ctx context.Context, req *dto.ListPluginProductsRequest) (resp *dto.ListPluginProductsResponse, err error) { plugins := slices.Transform(pluginConf.GetAllPluginProducts(), func(p *pluginConf.PluginInfo) *entity.PluginInfo { return entity.NewPluginInfo(p.Info) }) @@ -100,7 +101,7 @@ func (p *pluginServiceImpl) ListPluginProducts(ctx context.Context, req *ListPlu return plugins[i].GetRefProductID() < plugins[j].GetRefProductID() }) - return &ListPluginProductsResponse{ + return &dto.ListPluginProductsResponse{ Plugins: plugins, Total: int64(len(plugins)), }, nil @@ -186,7 +187,7 @@ func (p *pluginServiceImpl) ListCustomOnlinePlugins(ctx context.Context, spaceID return plugins, total, nil } -func (p *pluginServiceImpl) MGetPluginLatestVersion(ctx context.Context, pluginIDs []int64) (resp *MGetPluginLatestVersionResponse, err error) { +func (p *pluginServiceImpl) MGetPluginLatestVersion(ctx context.Context, pluginIDs []int64) (resp *model.MGetPluginLatestVersionResponse, err error) { plugins, err := p.pluginRepo.MGetOnlinePlugins(ctx, pluginIDs, repository.WithPluginID(), repository.WithPluginVersion()) @@ -199,14 +200,14 @@ func (p *pluginServiceImpl) MGetPluginLatestVersion(ctx context.Context, pluginI versions[pl.ID] = pl.GetVersion() } - resp = &MGetPluginLatestVersionResponse{ + resp = &model.MGetPluginLatestVersionResponse{ Versions: versions, } return resp, nil } -func (p *pluginServiceImpl) CopyPlugin(ctx context.Context, req *CopyPluginRequest) (resp *CopyPluginResponse, err error) { +func (p *pluginServiceImpl) CopyPlugin(ctx context.Context, req *dto.CopyPluginRequest) (resp *dto.CopyPluginResponse, err error) { err = p.checkCanCopyPlugin(ctx, req.PluginID, req.CopyScene) if err != nil { return nil, err @@ -232,7 +233,7 @@ func (p *pluginServiceImpl) CopyPlugin(ctx context.Context, req *CopyPluginReque return nil, errorx.Wrapf(err, "CopyPlugin failed, pluginID=%d", req.PluginID) } - resp = &CopyPluginResponse{ + resp = &dto.CopyPluginResponse{ Plugin: plugin, Tools: toolMap, } @@ -240,7 +241,7 @@ func (p *pluginServiceImpl) CopyPlugin(ctx context.Context, req *CopyPluginReque return resp, nil } -func (p *pluginServiceImpl) changePluginAndToolsInfoForCopy(req *CopyPluginRequest, plugin *entity.PluginInfo, tools []*entity.ToolInfo) { +func (p *pluginServiceImpl) changePluginAndToolsInfoForCopy(req *dto.CopyPluginRequest, plugin *entity.PluginInfo, tools []*entity.ToolInfo) { plugin.Version = nil plugin.VersionDesc = nil diff --git a/backend/domain/plugin/service/plugin_release.go b/backend/domain/plugin/service/plugin_release.go index 3f0a85902..b36c7f055 100644 --- a/backend/domain/plugin/service/plugin_release.go +++ b/backend/domain/plugin/service/plugin_release.go @@ -24,8 +24,8 @@ import ( "golang.org/x/mod/semver" - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/domain/plugin/repository" "github.com/coze-dev/coze-studio/backend/pkg/errorx" @@ -64,7 +64,7 @@ func (p *pluginServiceImpl) GetPluginNextVersion(ctx context.Context, pluginID i return nextVersion, nil } -func (p *pluginServiceImpl) PublishPlugin(ctx context.Context, req *PublishPluginRequest) (err error) { +func (p *pluginServiceImpl) PublishPlugin(ctx context.Context, req *model.PublishPluginRequest) (err error) { draftPlugin, exist, err := p.pluginRepo.GetDraftPlugin(ctx, req.PluginID) if err != nil { return errorx.Wrapf(err, "GetDraftPlugin failed, pluginID=%d", req.PluginID) @@ -101,8 +101,8 @@ func (p *pluginServiceImpl) PublishPlugin(ctx context.Context, req *PublishPlugi return nil } -func (p *pluginServiceImpl) PublishAPPPlugins(ctx context.Context, req *PublishAPPPluginsRequest) (resp *PublishAPPPluginsResponse, err error) { - resp = &PublishAPPPluginsResponse{} +func (p *pluginServiceImpl) PublishAPPPlugins(ctx context.Context, req *model.PublishAPPPluginsRequest) (resp *model.PublishAPPPluginsResponse, err error) { + resp = &model.PublishAPPPluginsResponse{} draftPlugins, err := p.pluginRepo.GetAPPAllDraftPlugins(ctx, req.APPID) if err != nil { diff --git a/backend/domain/plugin/service/service.go b/backend/domain/plugin/service/service.go index 01ec2b94e..eab2bd210 100644 --- a/backend/domain/plugin/service/service.go +++ b/backend/domain/plugin/service/service.go @@ -18,383 +18,68 @@ package service import ( "context" - "fmt" - "strings" - "github.com/bytedance/sonic" - "github.com/getkin/kin-openapi/openapi3" - - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" - common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" + "github.com/coze-dev/coze-studio/backend/domain/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" - "github.com/coze-dev/coze-studio/backend/pkg/errorx" - "github.com/coze-dev/coze-studio/backend/types/errno" ) //go:generate mockgen -destination ../../../internal/mock/domain/plugin/interface.go --package mockPlugin -source service.go type PluginService interface { // Draft Plugin - CreateDraftPlugin(ctx context.Context, req *CreateDraftPluginRequest) (pluginID int64, err error) - CreateDraftPluginWithCode(ctx context.Context, req *CreateDraftPluginWithCodeRequest) (resp *CreateDraftPluginWithCodeResponse, err error) + CreateDraftPlugin(ctx context.Context, req *dto.CreateDraftPluginRequest) (pluginID int64, err error) + CreateDraftPluginWithCode(ctx context.Context, req *dto.CreateDraftPluginWithCodeRequest) (resp *dto.CreateDraftPluginWithCodeResponse, err error) GetDraftPlugin(ctx context.Context, pluginID int64) (plugin *entity.PluginInfo, err error) MGetDraftPlugins(ctx context.Context, pluginIDs []int64) (plugins []*entity.PluginInfo, err error) - ListDraftPlugins(ctx context.Context, req *ListDraftPluginsRequest) (resp *ListDraftPluginsResponse, err error) - UpdateDraftPlugin(ctx context.Context, plugin *UpdateDraftPluginRequest) (err error) - UpdateDraftPluginWithCode(ctx context.Context, req *UpdateDraftPluginWithCodeRequest) (err error) + ListDraftPlugins(ctx context.Context, req *dto.ListDraftPluginsRequest) (resp *dto.ListDraftPluginsResponse, err error) + UpdateDraftPlugin(ctx context.Context, plugin *dto.UpdateDraftPluginRequest) (err error) + UpdateDraftPluginWithCode(ctx context.Context, req *dto.UpdateDraftPluginWithCodeRequest) (err error) DeleteDraftPlugin(ctx context.Context, pluginID int64) (err error) DeleteAPPAllPlugins(ctx context.Context, appID int64) (pluginIDs []int64, err error) GetAPPAllPlugins(ctx context.Context, appID int64) (plugins []*entity.PluginInfo, err error) // Online Plugin - PublishPlugin(ctx context.Context, req *PublishPluginRequest) (err error) - PublishAPPPlugins(ctx context.Context, req *PublishAPPPluginsRequest) (resp *PublishAPPPluginsResponse, err error) + PublishPlugin(ctx context.Context, req *model.PublishPluginRequest) (err error) + PublishAPPPlugins(ctx context.Context, req *model.PublishAPPPluginsRequest) (resp *model.PublishAPPPluginsResponse, err error) GetOnlinePlugin(ctx context.Context, pluginID int64) (plugin *entity.PluginInfo, err error) MGetOnlinePlugins(ctx context.Context, pluginIDs []int64) (plugins []*entity.PluginInfo, err error) - MGetPluginLatestVersion(ctx context.Context, pluginIDs []int64) (resp *MGetPluginLatestVersionResponse, err error) + MGetPluginLatestVersion(ctx context.Context, pluginIDs []int64) (resp *model.MGetPluginLatestVersionResponse, err error) GetPluginNextVersion(ctx context.Context, pluginID int64) (version string, err error) MGetVersionPlugins(ctx context.Context, versionPlugins []entity.VersionPlugin) (plugins []*entity.PluginInfo, err error) ListCustomOnlinePlugins(ctx context.Context, spaceID int64, pageInfo entity.PageInfo) (plugins []*entity.PluginInfo, total int64, err error) // Draft Tool MGetDraftTools(ctx context.Context, toolIDs []int64) (tools []*entity.ToolInfo, err error) - UpdateDraftTool(ctx context.Context, req *UpdateDraftToolRequest) (err error) - ConvertToOpenapi3Doc(ctx context.Context, req *ConvertToOpenapi3DocRequest) (resp *ConvertToOpenapi3DocResponse) - CreateDraftToolsWithCode(ctx context.Context, req *CreateDraftToolsWithCodeRequest) (resp *CreateDraftToolsWithCodeResponse, err error) + UpdateDraftTool(ctx context.Context, req *dto.UpdateDraftToolRequest) (err error) + ConvertToOpenapi3Doc(ctx context.Context, req *dto.ConvertToOpenapi3DocRequest) (resp *dto.ConvertToOpenapi3DocResponse) + CreateDraftToolsWithCode(ctx context.Context, req *dto.CreateDraftToolsWithCodeRequest) (resp *dto.CreateDraftToolsWithCodeResponse, err error) CheckPluginToolsDebugStatus(ctx context.Context, pluginID int64) (err error) // Online Tool GetOnlineTool(ctx context.Context, toolID int64) (tool *entity.ToolInfo, err error) MGetOnlineTools(ctx context.Context, toolIDs []int64) (tools []*entity.ToolInfo, err error) MGetVersionTools(ctx context.Context, versionTools []entity.VersionTool) (tools []*entity.ToolInfo, err error) - CopyPlugin(ctx context.Context, req *CopyPluginRequest) (resp *CopyPluginResponse, err error) + CopyPlugin(ctx context.Context, req *dto.CopyPluginRequest) (resp *dto.CopyPluginResponse, err error) MoveAPPPluginToLibrary(ctx context.Context, pluginID int64) (plugin *entity.PluginInfo, err error) // Agent Tool BindAgentTools(ctx context.Context, agentID int64, toolIDs []int64) (err error) DuplicateDraftAgentTools(ctx context.Context, fromAgentID, toAgentID int64) (err error) GetDraftAgentToolByName(ctx context.Context, agentID int64, toolName string) (tool *entity.ToolInfo, err error) - MGetAgentTools(ctx context.Context, req *MGetAgentToolsRequest) (tools []*entity.ToolInfo, err error) - UpdateBotDefaultParams(ctx context.Context, req *UpdateBotDefaultParamsRequest) (err error) + MGetAgentTools(ctx context.Context, req *model.MGetAgentToolsRequest) (tools []*entity.ToolInfo, err error) + UpdateBotDefaultParams(ctx context.Context, req *dto.UpdateBotDefaultParamsRequest) (err error) PublishAgentTools(ctx context.Context, agentID int64, agentVersion string) (err error) - ExecuteTool(ctx context.Context, req *ExecuteToolRequest, opts ...entity.ExecuteToolOpt) (resp *ExecuteToolResponse, err error) + ExecuteTool(ctx context.Context, req *model.ExecuteToolRequest, opts ...entity.ExecuteToolOpt) (resp *model.ExecuteToolResponse, err error) // Product - ListPluginProducts(ctx context.Context, req *ListPluginProductsRequest) (resp *ListPluginProductsResponse, err error) + ListPluginProducts(ctx context.Context, req *dto.ListPluginProductsRequest) (resp *dto.ListPluginProductsResponse, err error) GetPluginProductAllTools(ctx context.Context, pluginID int64) (tools []*entity.ToolInfo, err error) - GetOAuthStatus(ctx context.Context, userID, pluginID int64) (resp *GetOAuthStatusResponse, err error) - GetAgentPluginsOAuthStatus(ctx context.Context, userID, agentID int64) (status []*AgentPluginOAuthStatus, err error) + GetOAuthStatus(ctx context.Context, userID, pluginID int64) (resp *dto.GetOAuthStatusResponse, err error) + GetAgentPluginsOAuthStatus(ctx context.Context, userID, agentID int64) (status []*dto.AgentPluginOAuthStatus, err error) OAuthCode(ctx context.Context, code string, state *entity.OAuthState) (err error) GetAccessToken(ctx context.Context, oa *entity.OAuthInfo) (accessToken string, err error) RevokeAccessToken(ctx context.Context, meta *entity.AuthorizationCodeMeta) (err error) } - -type CreateDraftPluginRequest struct { - PluginType common.PluginType - IconURI string - SpaceID int64 - DeveloperID int64 - ProjectID *int64 - Name string - Desc string - ServerURL string - CommonParams map[common.ParameterLocation][]*common.CommonParamSchema - AuthInfo *PluginAuthInfo -} - -type UpdateDraftPluginWithCodeRequest struct { - UserID int64 - PluginID int64 - OpenapiDoc *model.Openapi3T - Manifest *entity.PluginManifest -} - -type UpdateDraftPluginRequest struct { - PluginID int64 - Name *string - Desc *string - URL *string - Icon *common.PluginIcon - CommonParams map[common.ParameterLocation][]*common.CommonParamSchema - AuthInfo *PluginAuthInfo -} - -type ListDraftPluginsRequest struct { - SpaceID int64 - APPID int64 - PageInfo entity.PageInfo -} - -type ListDraftPluginsResponse struct { - Plugins []*entity.PluginInfo - Total int64 -} - -type CreateDraftPluginWithCodeRequest struct { - SpaceID int64 - DeveloperID int64 - ProjectID *int64 - Manifest *entity.PluginManifest - OpenapiDoc *model.Openapi3T -} - -type CreateDraftPluginWithCodeResponse struct { - Plugin *entity.PluginInfo - Tools []*entity.ToolInfo -} - -type CreateDraftToolsWithCodeRequest struct { - PluginID int64 - OpenapiDoc *model.Openapi3T - - ConflictAndUpdate bool -} - -type CreateDraftToolsWithCodeResponse struct { - DuplicatedTools []entity.UniqueToolAPI -} - -type PluginAuthInfo struct { - AuthzType *model.AuthzType - Location *model.HTTPParamLocation - Key *string - ServiceToken *string - OAuthInfo *string - AuthzSubType *model.AuthzSubType - AuthzPayload *string -} - -func (p PluginAuthInfo) toAuthV2() (*model.AuthV2, error) { - if p.AuthzType == nil { - return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KV(errno.PluginMsgKey, "auth type is required")) - } - - switch *p.AuthzType { - case model.AuthzTypeOfNone: - return &model.AuthV2{ - Type: model.AuthzTypeOfNone, - }, nil - - case model.AuthzTypeOfOAuth: - m, err := p.authOfOAuthToAuthV2() - if err != nil { - return nil, err - } - return m, nil - - case model.AuthzTypeOfService: - m, err := p.authOfServiceToAuthV2() - if err != nil { - return nil, err - } - return m, nil - - default: - return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KVf(errno.PluginMsgKey, - "the type '%s' of auth is invalid", *p.AuthzType)) - } -} - -func (p PluginAuthInfo) authOfOAuthToAuthV2() (*model.AuthV2, error) { - if p.AuthzSubType == nil { - return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KV(errno.PluginMsgKey, "sub-auth type is required")) - } - - if p.OAuthInfo == nil || *p.OAuthInfo == "" { - return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KV(errno.PluginMsgKey, "oauth info is required")) - } - - oauthInfo := make(map[string]string) - err := sonic.Unmarshal([]byte(*p.OAuthInfo), &oauthInfo) - if err != nil { - return nil, errorx.WrapByCode(err, errno.ErrPluginInvalidManifest, errorx.KV(errno.PluginMsgKey, "invalid oauth info")) - } - - if *p.AuthzSubType == model.AuthzSubTypeOfOAuthClientCredentials { - _oauthInfo := &model.OAuthClientCredentialsConfig{ - ClientID: oauthInfo["client_id"], - ClientSecret: oauthInfo["client_secret"], - TokenURL: oauthInfo["token_url"], - } - - str, err := sonic.MarshalString(_oauthInfo) - if err != nil { - return nil, fmt.Errorf("marshal oauth info failed, err=%v", err) - } - - return &model.AuthV2{ - Type: model.AuthzTypeOfOAuth, - SubType: model.AuthzSubTypeOfOAuthClientCredentials, - Payload: str, - AuthOfOAuthClientCredentials: _oauthInfo, - }, nil - } - - if *p.AuthzSubType == model.AuthzSubTypeOfOAuthAuthorizationCode { - contentType := oauthInfo["authorization_content_type"] - if contentType != model.MediaTypeJson { // only support application/json - return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KVf(errno.PluginMsgKey, - "the type '%s' of authorization content is invalid", contentType)) - } - - _oauthInfo := &model.OAuthAuthorizationCodeConfig{ - ClientID: oauthInfo["client_id"], - ClientSecret: oauthInfo["client_secret"], - ClientURL: oauthInfo["client_url"], - Scope: oauthInfo["scope"], - AuthorizationURL: oauthInfo["authorization_url"], - AuthorizationContentType: contentType, - } - - str, err := sonic.MarshalString(_oauthInfo) - if err != nil { - return nil, fmt.Errorf("marshal oauth info failed, err=%v", err) - } - - return &model.AuthV2{ - Type: model.AuthzTypeOfOAuth, - SubType: model.AuthzSubTypeOfOAuthAuthorizationCode, - Payload: str, - AuthOfOAuthAuthorizationCode: _oauthInfo, - }, nil - } - - return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KVf(errno.PluginMsgKey, - "the type '%s' of sub-auth is invalid", *p.AuthzSubType)) -} - -func (p PluginAuthInfo) authOfServiceToAuthV2() (*model.AuthV2, error) { - if p.AuthzSubType == nil { - return nil, fmt.Errorf("sub-auth type is required") - } - - if *p.AuthzSubType == model.AuthzSubTypeOfServiceAPIToken { - if p.Location == nil { - return nil, fmt.Errorf("'Location' of sub-auth is required") - } - if p.ServiceToken == nil { - return nil, fmt.Errorf("'ServiceToken' of sub-auth is required") - } - if p.Key == nil { - return nil, fmt.Errorf("'Key' of sub-auth is required") - } - - tokenAuth := &model.AuthOfAPIToken{ - ServiceToken: *p.ServiceToken, - Location: model.HTTPParamLocation(strings.ToLower(string(*p.Location))), - Key: *p.Key, - } - - str, err := sonic.MarshalString(tokenAuth) - if err != nil { - return nil, fmt.Errorf("marshal token auth failed, err=%v", err) - } - - return &model.AuthV2{ - Type: model.AuthzTypeOfService, - SubType: model.AuthzSubTypeOfServiceAPIToken, - Payload: str, - AuthOfAPIToken: tokenAuth, - }, nil - } - - return nil, errorx.New(errno.ErrPluginInvalidManifest, errorx.KVf(errno.PluginMsgKey, - "the type '%s' of sub-auth is invalid", *p.AuthzSubType)) -} - -type PublishPluginRequest = model.PublishPluginRequest - -type PublishAPPPluginsRequest = model.PublishAPPPluginsRequest - -type PublishAPPPluginsResponse = model.PublishAPPPluginsResponse - -type MGetPluginLatestVersionResponse = model.MGetPluginLatestVersionResponse - -type UpdateDraftToolRequest struct { - PluginID int64 - ToolID int64 - Name *string - Desc *string - SubURL *string - Method *string - Parameters openapi3.Parameters - RequestBody *openapi3.RequestBodyRef - Responses openapi3.Responses - Disabled *bool - SaveExample *bool - DebugExample *common.DebugExample - APIExtend *common.APIExtend -} - -type MGetAgentToolsRequest = model.MGetAgentToolsRequest - -type UpdateBotDefaultParamsRequest struct { - PluginID int64 - AgentID int64 - ToolName string - Parameters openapi3.Parameters - RequestBody *openapi3.RequestBodyRef - Responses openapi3.Responses -} - -type ExecuteToolRequest = model.ExecuteToolRequest - -type ExecuteToolResponse = model.ExecuteToolResponse - -type ListPluginProductsRequest struct{} - -type ListPluginProductsResponse struct { - Plugins []*entity.PluginInfo - Total int64 -} - -type ConvertToOpenapi3DocRequest struct { - RawInput string - PluginServerURL *string -} - -type ConvertToOpenapi3DocResponse struct { - OpenapiDoc *model.Openapi3T - Manifest *entity.PluginManifest - Format common.PluginDataFormat - ErrMsg string -} - -type GetOAuthStatusResponse struct { - IsOauth bool - Status common.OAuthStatus - OAuthURL string -} - -type AgentPluginOAuthStatus struct { - PluginID int64 - PluginName string - PluginIconURL string - Status common.OAuthStatus -} - -type CopyPluginRequest struct { - UserID int64 - PluginID int64 - CopyScene model.CopyScene - - TargetAPPID *int64 -} - -type CopyPluginResponse struct { - Plugin *entity.PluginInfo - Tools map[int64]*entity.ToolInfo // old tool id -> new tool -} - -type MoveAPPPluginToLibRequest struct { - PluginID int64 -} - -type GetAccessTokenRequest struct { - UserID string - PluginID *int64 - Mode model.AuthzSubType - OAuthInfo *entity.OAuthInfo -} diff --git a/backend/domain/plugin/service/tool/invocation_args.go b/backend/domain/plugin/service/tool/invocation_args.go index e583b3b7f..eb8802393 100644 --- a/backend/domain/plugin/service/tool/invocation_args.go +++ b/backend/domain/plugin/service/tool/invocation_args.go @@ -26,10 +26,10 @@ import ( "github.com/bytedance/sonic" "github.com/getkin/kin-openapi/openapi3" - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/variables" "github.com/coze-dev/coze-studio/backend/api/model/data/variable/project_memory" api "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" crossvariables "github.com/coze-dev/coze-studio/backend/crossdomain/contract/variables" "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" "github.com/coze-dev/coze-studio/backend/infra/contract/storage" diff --git a/backend/domain/plugin/service/tool/invocation_http.go b/backend/domain/plugin/service/tool/invocation_http.go index 0e377e651..a843bb2d0 100644 --- a/backend/domain/plugin/service/tool/invocation_http.go +++ b/backend/domain/plugin/service/tool/invocation_http.go @@ -31,7 +31,7 @@ import ( "github.com/go-resty/resty/v2" "github.com/tidwall/sjson" - model "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "github.com/coze-dev/coze-studio/backend/domain/plugin/internal/encoder" "github.com/coze-dev/coze-studio/backend/pkg/errorx" "github.com/coze-dev/coze-studio/backend/pkg/i18n" diff --git a/backend/domain/workflow/entity/vo/workflow_copy.go b/backend/domain/workflow/entity/vo/workflow_copy.go index cf3673a9e..4f9688888 100644 --- a/backend/domain/workflow/entity/vo/workflow_copy.go +++ b/backend/domain/workflow/entity/vo/workflow_copy.go @@ -17,7 +17,7 @@ package vo import ( - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" + plugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" ) type ExternalResourceRelated struct { diff --git a/backend/domain/workflow/internal/compose/designate_option.go b/backend/domain/workflow/internal/compose/designate_option.go index 1b350f1dd..5845ad8c3 100644 --- a/backend/domain/workflow/internal/compose/designate_option.go +++ b/backend/domain/workflow/internal/compose/designate_option.go @@ -24,9 +24,9 @@ import ( einoCompose "github.com/cloudwego/eino/compose" - "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" + plugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" workflow2 "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" diff --git a/backend/domain/workflow/internal/nodes/llm/llm.go b/backend/domain/workflow/internal/nodes/llm/llm.go index b5dac67a8..f314ea7d1 100644 --- a/backend/domain/workflow/internal/nodes/llm/llm.go +++ b/backend/domain/workflow/internal/nodes/llm/llm.go @@ -36,13 +36,13 @@ 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" crossmessage "github.com/coze-dev/coze-studio/backend/crossdomain/contract/message" crossmodelmgr "github.com/coze-dev/coze-studio/backend/crossdomain/contract/modelmgr" crossplugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin" + plugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "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" diff --git a/backend/domain/workflow/internal/nodes/plugin/plugin.go b/backend/domain/workflow/internal/nodes/plugin/plugin.go index 697b87fee..ffa37cc16 100644 --- a/backend/domain/workflow/internal/nodes/plugin/plugin.go +++ b/backend/domain/workflow/internal/nodes/plugin/plugin.go @@ -23,9 +23,9 @@ 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" + model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "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" diff --git a/backend/domain/workflow/service/service_impl.go b/backend/domain/workflow/service/service_impl.go index 50b3ab019..8b2d5b107 100644 --- a/backend/domain/workflow/service/service_impl.go +++ b/backend/domain/workflow/service/service_impl.go @@ -30,10 +30,10 @@ import ( einoCompose "github.com/cloudwego/eino/compose" - "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin" workflowModel "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/workflow" cloudworkflow "github.com/coze-dev/coze-studio/backend/api/model/workflow" "github.com/coze-dev/coze-studio/backend/application/base/ctxutil" + plugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" "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" diff --git a/backend/go.sum b/backend/go.sum index ddf518364..21765160d 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -234,14 +234,10 @@ github.com/cloudwego/eino-ext/components/model/gemini v0.1.2 h1:bt9xftOQhP0Nuh1P github.com/cloudwego/eino-ext/components/model/gemini v0.1.2/go.mod h1:1tv89uZ9hR/4AyQ+9yxFWLn52GaJDKtPXdEY7WZdyZc= github.com/cloudwego/eino-ext/components/model/ollama v0.1.0 h1:FW067iMfg3EZbUaZIo8v3i2ILBAZDzY23/9pbprvE0M= github.com/cloudwego/eino-ext/components/model/ollama v0.1.0/go.mod h1:+qA5kkUCM0mIrXGSNzxLcjxh6K1AghPNigtEyyMdkOc= -github.com/cloudwego/eino-ext/components/model/openai v0.0.0-20250715055739-0d0e28441a2f h1:ovS39vuN2JW+C/O9jtEmOUuLEY4fw0yYh8//yhMfJNM= -github.com/cloudwego/eino-ext/components/model/openai v0.0.0-20250715055739-0d0e28441a2f/go.mod h1:2mFQQnlhJrNgbW6YX1MOUUfXkGSbTz9Ylx37fbR0xBo= github.com/cloudwego/eino-ext/components/model/openai v0.1.1 h1:VRdUDcnfi/T8F0jcuovhdADU9Io/oMqiKpY2ZJTBc1o= github.com/cloudwego/eino-ext/components/model/openai v0.1.1/go.mod h1:VwAXEY1ik2K9KFPZvymnkfBQQKgLHbpg90yg+7hrTt8= github.com/cloudwego/eino-ext/components/model/qwen v0.0.0-20250612061754-5a3deb091dc5 h1:4zAZiNo/PkeVc0Gw8YLpzpbR8zDzccL7H5PLqTuGhv4= github.com/cloudwego/eino-ext/components/model/qwen v0.0.0-20250612061754-5a3deb091dc5/go.mod h1:vgQ3m0LtrdQbnganW9y3j3aTJpVgJnCLp9y80tTM9hA= -github.com/cloudwego/eino-ext/libs/acl/openai v0.0.0-20250626133421-3c142631c961 h1:fGE3RFHaAsrLjA+2fkE0YMsPrkFI6pEKKZmbhD42L7E= -github.com/cloudwego/eino-ext/libs/acl/openai v0.0.0-20250626133421-3c142631c961/go.mod h1:iB0W8l+OqKNL5LtJQ9JaGYXekhsxVxrDMfnfD9L+5gc= github.com/cloudwego/eino-ext/libs/acl/openai v0.0.0-20250918130948-16e3a249e721 h1:5Hd8GxNEmu+ppTGCRBU6kLKfCQNXPMwi31xA83PzEqo= github.com/cloudwego/eino-ext/libs/acl/openai v0.0.0-20250918130948-16e3a249e721/go.mod h1:fHn/6OqPPY1iLLx9wzz+MEVT5Dl9gwuZte1oLEnCoYw= github.com/cloudwego/gopkg v0.1.4 h1:EoQiCG4sTonTPHxOGE0VlQs+sQR+Hsi2uN0qqwu8O50= @@ -798,8 +794,6 @@ github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mediocregopher/radix/v3 v3.4.2/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i4n7wVopoX3x7Bv8= -github.com/meguminnnnnnnnn/go-openai v0.0.0-20250620092828-0d508a1dcdde h1:pq2I0uxUR4lfr4OmqvE8QdHj9UML9b1jZu8L3dI2eu8= -github.com/meguminnnnnnnnn/go-openai v0.0.0-20250620092828-0d508a1dcdde/go.mod h1:CqSFsV6AkkL2fixd25WYjRAolns+gQrY1x/Cz9c30v8= github.com/meguminnnnnnnnn/go-openai v0.0.0-20250821095446-07791bea23a0 h1:nIohpHs1ViKR0SVgW/cbBstHjmnqFZDM9RqgX9m9Xu8= github.com/meguminnnnnnnnn/go-openai v0.0.0-20250821095446-07791bea23a0/go.mod h1:qs96ysDmxhE4BZoU45I43zcyfnaYxU3X+aRzLko/htY= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= diff --git a/backend/internal/mock/domain/plugin/interface.go b/backend/internal/mock/domain/plugin/interface.go index c55b29216..6876b8c4e 100644 --- a/backend/internal/mock/domain/plugin/interface.go +++ b/backend/internal/mock/domain/plugin/interface.go @@ -13,8 +13,9 @@ import ( context "context" reflect "reflect" + plugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" + dto "github.com/coze-dev/coze-studio/backend/domain/plugin/dto" entity "github.com/coze-dev/coze-studio/backend/domain/plugin/entity" - service "github.com/coze-dev/coze-studio/backend/domain/plugin/service" gomock "go.uber.org/mock/gomock" ) @@ -22,6 +23,7 @@ import ( type MockPluginService struct { ctrl *gomock.Controller recorder *MockPluginServiceMockRecorder + isgomock struct{} } // MockPluginServiceMockRecorder is the mock recorder for MockPluginService. @@ -70,10 +72,10 @@ func (mr *MockPluginServiceMockRecorder) CheckPluginToolsDebugStatus(ctx, plugin } // ConvertToOpenapi3Doc mocks base method. -func (m *MockPluginService) ConvertToOpenapi3Doc(ctx context.Context, req *service.ConvertToOpenapi3DocRequest) *service.ConvertToOpenapi3DocResponse { +func (m *MockPluginService) ConvertToOpenapi3Doc(ctx context.Context, req *dto.ConvertToOpenapi3DocRequest) *dto.ConvertToOpenapi3DocResponse { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ConvertToOpenapi3Doc", ctx, req) - ret0, _ := ret[0].(*service.ConvertToOpenapi3DocResponse) + ret0, _ := ret[0].(*dto.ConvertToOpenapi3DocResponse) return ret0 } @@ -84,10 +86,10 @@ func (mr *MockPluginServiceMockRecorder) ConvertToOpenapi3Doc(ctx, req any) *gom } // CopyPlugin mocks base method. -func (m *MockPluginService) CopyPlugin(ctx context.Context, req *service.CopyPluginRequest) (*service.CopyPluginResponse, error) { +func (m *MockPluginService) CopyPlugin(ctx context.Context, req *dto.CopyPluginRequest) (*dto.CopyPluginResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CopyPlugin", ctx, req) - ret0, _ := ret[0].(*service.CopyPluginResponse) + ret0, _ := ret[0].(*dto.CopyPluginResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -99,7 +101,7 @@ func (mr *MockPluginServiceMockRecorder) CopyPlugin(ctx, req any) *gomock.Call { } // CreateDraftPlugin mocks base method. -func (m *MockPluginService) CreateDraftPlugin(ctx context.Context, req *service.CreateDraftPluginRequest) (int64, error) { +func (m *MockPluginService) CreateDraftPlugin(ctx context.Context, req *dto.CreateDraftPluginRequest) (int64, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateDraftPlugin", ctx, req) ret0, _ := ret[0].(int64) @@ -114,10 +116,10 @@ func (mr *MockPluginServiceMockRecorder) CreateDraftPlugin(ctx, req any) *gomock } // CreateDraftPluginWithCode mocks base method. -func (m *MockPluginService) CreateDraftPluginWithCode(ctx context.Context, req *service.CreateDraftPluginWithCodeRequest) (*service.CreateDraftPluginWithCodeResponse, error) { +func (m *MockPluginService) CreateDraftPluginWithCode(ctx context.Context, req *dto.CreateDraftPluginWithCodeRequest) (*dto.CreateDraftPluginWithCodeResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateDraftPluginWithCode", ctx, req) - ret0, _ := ret[0].(*service.CreateDraftPluginWithCodeResponse) + ret0, _ := ret[0].(*dto.CreateDraftPluginWithCodeResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -129,10 +131,10 @@ func (mr *MockPluginServiceMockRecorder) CreateDraftPluginWithCode(ctx, req any) } // CreateDraftToolsWithCode mocks base method. -func (m *MockPluginService) CreateDraftToolsWithCode(ctx context.Context, req *service.CreateDraftToolsWithCodeRequest) (*service.CreateDraftToolsWithCodeResponse, error) { +func (m *MockPluginService) CreateDraftToolsWithCode(ctx context.Context, req *dto.CreateDraftToolsWithCodeRequest) (*dto.CreateDraftToolsWithCodeResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateDraftToolsWithCode", ctx, req) - ret0, _ := ret[0].(*service.CreateDraftToolsWithCodeResponse) + ret0, _ := ret[0].(*dto.CreateDraftToolsWithCodeResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -187,14 +189,14 @@ func (mr *MockPluginServiceMockRecorder) DuplicateDraftAgentTools(ctx, fromAgent } // ExecuteTool mocks base method. -func (m *MockPluginService) ExecuteTool(ctx context.Context, req *service.ExecuteToolRequest, opts ...entity.ExecuteToolOpt) (*service.ExecuteToolResponse, error) { +func (m *MockPluginService) ExecuteTool(ctx context.Context, req *plugin.ExecuteToolRequest, opts ...entity.ExecuteToolOpt) (*plugin.ExecuteToolResponse, error) { m.ctrl.T.Helper() varargs := []any{ctx, req} for _, a := range opts { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "ExecuteTool", varargs...) - ret0, _ := ret[0].(*service.ExecuteToolResponse) + ret0, _ := ret[0].(*plugin.ExecuteToolResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -237,10 +239,10 @@ func (mr *MockPluginServiceMockRecorder) GetAccessToken(ctx, oa any) *gomock.Cal } // GetAgentPluginsOAuthStatus mocks base method. -func (m *MockPluginService) GetAgentPluginsOAuthStatus(ctx context.Context, userID, agentID int64) ([]*service.AgentPluginOAuthStatus, error) { +func (m *MockPluginService) GetAgentPluginsOAuthStatus(ctx context.Context, userID, agentID int64) ([]*dto.AgentPluginOAuthStatus, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetAgentPluginsOAuthStatus", ctx, userID, agentID) - ret0, _ := ret[0].([]*service.AgentPluginOAuthStatus) + ret0, _ := ret[0].([]*dto.AgentPluginOAuthStatus) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -282,10 +284,10 @@ func (mr *MockPluginServiceMockRecorder) GetDraftPlugin(ctx, pluginID any) *gomo } // GetOAuthStatus mocks base method. -func (m *MockPluginService) GetOAuthStatus(ctx context.Context, userID, pluginID int64) (*service.GetOAuthStatusResponse, error) { +func (m *MockPluginService) GetOAuthStatus(ctx context.Context, userID, pluginID int64) (*dto.GetOAuthStatusResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetOAuthStatus", ctx, userID, pluginID) - ret0, _ := ret[0].(*service.GetOAuthStatusResponse) + ret0, _ := ret[0].(*dto.GetOAuthStatusResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -373,10 +375,10 @@ func (mr *MockPluginServiceMockRecorder) ListCustomOnlinePlugins(ctx, spaceID, p } // ListDraftPlugins mocks base method. -func (m *MockPluginService) ListDraftPlugins(ctx context.Context, req *service.ListDraftPluginsRequest) (*service.ListDraftPluginsResponse, error) { +func (m *MockPluginService) ListDraftPlugins(ctx context.Context, req *dto.ListDraftPluginsRequest) (*dto.ListDraftPluginsResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ListDraftPlugins", ctx, req) - ret0, _ := ret[0].(*service.ListDraftPluginsResponse) + ret0, _ := ret[0].(*dto.ListDraftPluginsResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -388,10 +390,10 @@ func (mr *MockPluginServiceMockRecorder) ListDraftPlugins(ctx, req any) *gomock. } // ListPluginProducts mocks base method. -func (m *MockPluginService) ListPluginProducts(ctx context.Context, req *service.ListPluginProductsRequest) (*service.ListPluginProductsResponse, error) { +func (m *MockPluginService) ListPluginProducts(ctx context.Context, req *dto.ListPluginProductsRequest) (*dto.ListPluginProductsResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ListPluginProducts", ctx, req) - ret0, _ := ret[0].(*service.ListPluginProductsResponse) + ret0, _ := ret[0].(*dto.ListPluginProductsResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -403,7 +405,7 @@ func (mr *MockPluginServiceMockRecorder) ListPluginProducts(ctx, req any) *gomoc } // MGetAgentTools mocks base method. -func (m *MockPluginService) MGetAgentTools(ctx context.Context, req *service.MGetAgentToolsRequest) ([]*entity.ToolInfo, error) { +func (m *MockPluginService) MGetAgentTools(ctx context.Context, req *plugin.MGetAgentToolsRequest) ([]*entity.ToolInfo, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "MGetAgentTools", ctx, req) ret0, _ := ret[0].([]*entity.ToolInfo) @@ -478,10 +480,10 @@ func (mr *MockPluginServiceMockRecorder) MGetOnlineTools(ctx, toolIDs any) *gomo } // MGetPluginLatestVersion mocks base method. -func (m *MockPluginService) MGetPluginLatestVersion(ctx context.Context, pluginIDs []int64) (*service.MGetPluginLatestVersionResponse, error) { +func (m *MockPluginService) MGetPluginLatestVersion(ctx context.Context, pluginIDs []int64) (*plugin.MGetPluginLatestVersionResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "MGetPluginLatestVersion", ctx, pluginIDs) - ret0, _ := ret[0].(*service.MGetPluginLatestVersionResponse) + ret0, _ := ret[0].(*plugin.MGetPluginLatestVersionResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -552,10 +554,10 @@ func (mr *MockPluginServiceMockRecorder) OAuthCode(ctx, code, state any) *gomock } // PublishAPPPlugins mocks base method. -func (m *MockPluginService) PublishAPPPlugins(ctx context.Context, req *service.PublishAPPPluginsRequest) (*service.PublishAPPPluginsResponse, error) { +func (m *MockPluginService) PublishAPPPlugins(ctx context.Context, req *plugin.PublishAPPPluginsRequest) (*plugin.PublishAPPPluginsResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "PublishAPPPlugins", ctx, req) - ret0, _ := ret[0].(*service.PublishAPPPluginsResponse) + ret0, _ := ret[0].(*plugin.PublishAPPPluginsResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -581,7 +583,7 @@ func (mr *MockPluginServiceMockRecorder) PublishAgentTools(ctx, agentID, agentVe } // PublishPlugin mocks base method. -func (m *MockPluginService) PublishPlugin(ctx context.Context, req *service.PublishPluginRequest) error { +func (m *MockPluginService) PublishPlugin(ctx context.Context, req *plugin.PublishPluginRequest) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "PublishPlugin", ctx, req) ret0, _ := ret[0].(error) @@ -609,7 +611,7 @@ func (mr *MockPluginServiceMockRecorder) RevokeAccessToken(ctx, meta any) *gomoc } // UpdateBotDefaultParams mocks base method. -func (m *MockPluginService) UpdateBotDefaultParams(ctx context.Context, req *service.UpdateBotDefaultParamsRequest) error { +func (m *MockPluginService) UpdateBotDefaultParams(ctx context.Context, req *dto.UpdateBotDefaultParamsRequest) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateBotDefaultParams", ctx, req) ret0, _ := ret[0].(error) @@ -623,21 +625,21 @@ func (mr *MockPluginServiceMockRecorder) UpdateBotDefaultParams(ctx, req any) *g } // UpdateDraftPlugin mocks base method. -func (m *MockPluginService) UpdateDraftPlugin(ctx context.Context, plugin *service.UpdateDraftPluginRequest) error { +func (m *MockPluginService) UpdateDraftPlugin(ctx context.Context, arg1 *dto.UpdateDraftPluginRequest) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateDraftPlugin", ctx, plugin) + ret := m.ctrl.Call(m, "UpdateDraftPlugin", ctx, arg1) ret0, _ := ret[0].(error) return ret0 } // UpdateDraftPlugin indicates an expected call of UpdateDraftPlugin. -func (mr *MockPluginServiceMockRecorder) UpdateDraftPlugin(ctx, plugin any) *gomock.Call { +func (mr *MockPluginServiceMockRecorder) UpdateDraftPlugin(ctx, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateDraftPlugin", reflect.TypeOf((*MockPluginService)(nil).UpdateDraftPlugin), ctx, plugin) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateDraftPlugin", reflect.TypeOf((*MockPluginService)(nil).UpdateDraftPlugin), ctx, arg1) } // UpdateDraftPluginWithCode mocks base method. -func (m *MockPluginService) UpdateDraftPluginWithCode(ctx context.Context, req *service.UpdateDraftPluginWithCodeRequest) error { +func (m *MockPluginService) UpdateDraftPluginWithCode(ctx context.Context, req *dto.UpdateDraftPluginWithCodeRequest) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateDraftPluginWithCode", ctx, req) ret0, _ := ret[0].(error) @@ -651,7 +653,7 @@ func (mr *MockPluginServiceMockRecorder) UpdateDraftPluginWithCode(ctx, req any) } // UpdateDraftTool mocks base method. -func (m *MockPluginService) UpdateDraftTool(ctx context.Context, req *service.UpdateDraftToolRequest) error { +func (m *MockPluginService) UpdateDraftTool(ctx context.Context, req *dto.UpdateDraftToolRequest) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateDraftTool", ctx, req) ret0, _ := ret[0].(error) diff --git a/backend/types/ddl/gen_orm_query.go b/backend/types/ddl/gen_orm_query.go index ecd5fe64f..8403a4288 100644 --- a/backend/types/ddl/gen_orm_query.go +++ b/backend/types/ddl/gen_orm_query.go @@ -33,8 +33,8 @@ import ( "github.com/coze-dev/coze-studio/backend/api/model/app/bot_common" "github.com/coze-dev/coze-studio/backend/api/model/crossdomain/agentrun" "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/api/model/playground" + plugin "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto" appEntity "github.com/coze-dev/coze-studio/backend/domain/app/entity" variableEntity "github.com/coze-dev/coze-studio/backend/domain/memory/variables/entity" )