feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
74
backend/domain/plugin/repository/oauth_impl.go
Normal file
74
backend/domain/plugin/repository/oauth_impl.go
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
)
|
||||
|
||||
type OAuthRepoComponents struct {
|
||||
IDGen idgen.IDGenerator
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewOAuthRepo(components *OAuthRepoComponents) OAuthRepository {
|
||||
return &oauthRepoImpl{
|
||||
oauthAuth: dal.NewPluginOAuthAuthDAO(components.DB, components.IDGen),
|
||||
}
|
||||
}
|
||||
|
||||
type oauthRepoImpl struct {
|
||||
oauthAuth *dal.PluginOAuthAuthDAO
|
||||
}
|
||||
|
||||
func (o *oauthRepoImpl) GetAuthorizationCode(ctx context.Context, meta *entity.AuthorizationCodeMeta) (info *entity.AuthorizationCodeInfo, exist bool, err error) {
|
||||
return o.oauthAuth.Get(ctx, meta)
|
||||
}
|
||||
|
||||
func (o *oauthRepoImpl) UpsertAuthorizationCode(ctx context.Context, info *entity.AuthorizationCodeInfo) (err error) {
|
||||
return o.oauthAuth.Upsert(ctx, info)
|
||||
}
|
||||
|
||||
func (o *oauthRepoImpl) UpdateAuthorizationCodeLastActiveAt(ctx context.Context, meta *entity.AuthorizationCodeMeta, lastActiveAtMs int64) (err error) {
|
||||
return o.oauthAuth.UpdateLastActiveAt(ctx, meta, lastActiveAtMs)
|
||||
}
|
||||
|
||||
func (o *oauthRepoImpl) BatchDeleteAuthorizationCodeByIDs(ctx context.Context, ids []int64) (err error) {
|
||||
return o.oauthAuth.BatchDeleteByIDs(ctx, ids)
|
||||
}
|
||||
|
||||
func (o *oauthRepoImpl) DeleteAuthorizationCode(ctx context.Context, meta *entity.AuthorizationCodeMeta) (err error) {
|
||||
return o.oauthAuth.Delete(ctx, meta)
|
||||
}
|
||||
|
||||
func (o *oauthRepoImpl) GetAuthorizationCodeRefreshTokens(ctx context.Context, nextRefreshAt int64, limit int) (infos []*entity.AuthorizationCodeInfo, err error) {
|
||||
return o.oauthAuth.GetRefreshTokenList(ctx, nextRefreshAt, limit)
|
||||
}
|
||||
|
||||
func (o *oauthRepoImpl) DeleteExpiredAuthorizationCodeTokens(ctx context.Context, expireAt int64, limit int) (err error) {
|
||||
return o.oauthAuth.DeleteExpiredTokens(ctx, expireAt, limit)
|
||||
}
|
||||
|
||||
func (o *oauthRepoImpl) DeleteInactiveAuthorizationCodeTokens(ctx context.Context, lastActiveAt int64, limit int) (err error) {
|
||||
return o.oauthAuth.DeleteInactiveTokens(ctx, lastActiveAt, limit)
|
||||
}
|
||||
34
backend/domain/plugin/repository/oauth_repository.go
Normal file
34
backend/domain/plugin/repository/oauth_repository.go
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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 repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
)
|
||||
|
||||
type OAuthRepository interface {
|
||||
GetAuthorizationCode(ctx context.Context, meta *entity.AuthorizationCodeMeta) (info *entity.AuthorizationCodeInfo, exist bool, err error)
|
||||
UpsertAuthorizationCode(ctx context.Context, info *entity.AuthorizationCodeInfo) (err error)
|
||||
UpdateAuthorizationCodeLastActiveAt(ctx context.Context, meta *entity.AuthorizationCodeMeta, lastActiveAtMs int64) (err error)
|
||||
BatchDeleteAuthorizationCodeByIDs(ctx context.Context, ids []int64) (err error)
|
||||
DeleteAuthorizationCode(ctx context.Context, meta *entity.AuthorizationCodeMeta) (err error)
|
||||
GetAuthorizationCodeRefreshTokens(ctx context.Context, nextRefreshAt int64, limit int) (infos []*entity.AuthorizationCodeInfo, err error)
|
||||
DeleteExpiredAuthorizationCodeTokens(ctx context.Context, expireAt int64, limit int) (err error)
|
||||
DeleteInactiveAuthorizationCodeTokens(ctx context.Context, lastActiveAt int64, limit int) (err error)
|
||||
}
|
||||
85
backend/domain/plugin/repository/option.go
Normal file
85
backend/domain/plugin/repository/option.go
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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 repository
|
||||
|
||||
import (
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal"
|
||||
)
|
||||
|
||||
type PluginSelectedOptions func(*dal.PluginSelectedOption)
|
||||
|
||||
func WithPluginID() PluginSelectedOptions {
|
||||
return func(opts *dal.PluginSelectedOption) {
|
||||
opts.PluginID = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithPluginOpenapiDoc() PluginSelectedOptions {
|
||||
return func(opts *dal.PluginSelectedOption) {
|
||||
opts.OpenapiDoc = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithPluginManifest() PluginSelectedOptions {
|
||||
return func(opts *dal.PluginSelectedOption) {
|
||||
opts.Manifest = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithPluginIconURI() PluginSelectedOptions {
|
||||
return func(opts *dal.PluginSelectedOption) {
|
||||
opts.IconURI = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithPluginVersion() PluginSelectedOptions {
|
||||
return func(opts *dal.PluginSelectedOption) {
|
||||
opts.Version = true
|
||||
}
|
||||
}
|
||||
|
||||
type ToolSelectedOptions func(option *dal.ToolSelectedOption)
|
||||
|
||||
func WithToolID() ToolSelectedOptions {
|
||||
return func(opts *dal.ToolSelectedOption) {
|
||||
opts.ToolID = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithToolMethod() ToolSelectedOptions {
|
||||
return func(opts *dal.ToolSelectedOption) {
|
||||
opts.ToolMethod = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithToolSubURL() ToolSelectedOptions {
|
||||
return func(opts *dal.ToolSelectedOption) {
|
||||
opts.ToolSubURL = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithToolActivatedStatus() ToolSelectedOptions {
|
||||
return func(opts *dal.ToolSelectedOption) {
|
||||
opts.ActivatedStatus = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithToolDebugStatus() ToolSelectedOptions {
|
||||
return func(opts *dal.ToolSelectedOption) {
|
||||
opts.DebugStatus = true
|
||||
}
|
||||
}
|
||||
855
backend/domain/plugin/repository/plugin_impl.go
Normal file
855
backend/domain/plugin/repository/plugin_impl.go
Normal file
@@ -0,0 +1,855 @@
|
||||
/*
|
||||
* 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 repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/getkin/kin-openapi/openapi3"
|
||||
"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"
|
||||
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"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
type pluginRepoImpl struct {
|
||||
query *query.Query
|
||||
|
||||
pluginDraftDAO *dal.PluginDraftDAO
|
||||
pluginDAO *dal.PluginDAO
|
||||
pluginVersionDAO *dal.PluginVersionDAO
|
||||
|
||||
toolDraftDAO *dal.ToolDraftDAO
|
||||
toolDAO *dal.ToolDAO
|
||||
toolVersionDAO *dal.ToolVersionDAO
|
||||
}
|
||||
|
||||
type PluginRepoComponents struct {
|
||||
IDGen idgen.IDGenerator
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewPluginRepo(components *PluginRepoComponents) PluginRepository {
|
||||
return &pluginRepoImpl{
|
||||
query: query.Use(components.DB),
|
||||
pluginDraftDAO: dal.NewPluginDraftDAO(components.DB, components.IDGen),
|
||||
pluginDAO: dal.NewPluginDAO(components.DB, components.IDGen),
|
||||
pluginVersionDAO: dal.NewPluginVersionDAO(components.DB, components.IDGen),
|
||||
toolDraftDAO: dal.NewToolDraftDAO(components.DB, components.IDGen),
|
||||
toolDAO: dal.NewToolDAO(components.DB, components.IDGen),
|
||||
toolVersionDAO: dal.NewToolVersionDAO(components.DB, components.IDGen),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) CreateDraftPlugin(ctx context.Context, plugin *entity.PluginInfo) (pluginID int64, err error) {
|
||||
pluginID, err = p.pluginDraftDAO.Create(ctx, plugin)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return pluginID, nil
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) GetDraftPlugin(ctx context.Context, pluginID int64, opts ...PluginSelectedOptions) (plugin *entity.PluginInfo, exist bool, err error) {
|
||||
var opt *dal.PluginSelectedOption
|
||||
if len(opts) > 0 {
|
||||
opt = &dal.PluginSelectedOption{}
|
||||
for _, o := range opts {
|
||||
o(opt)
|
||||
}
|
||||
}
|
||||
|
||||
return p.pluginDraftDAO.Get(ctx, pluginID, opt)
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) MGetDraftPlugins(ctx context.Context, pluginIDs []int64, opts ...PluginSelectedOptions) (plugins []*entity.PluginInfo, err error) {
|
||||
var opt *dal.PluginSelectedOption
|
||||
if len(opts) > 0 {
|
||||
opt = &dal.PluginSelectedOption{}
|
||||
for _, o := range opts {
|
||||
o(opt)
|
||||
}
|
||||
}
|
||||
|
||||
return p.pluginDraftDAO.MGet(ctx, pluginIDs, opt)
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) GetAPPAllDraftPlugins(ctx context.Context, appID int64, opts ...PluginSelectedOptions) (plugins []*entity.PluginInfo, err error) {
|
||||
var opt *dal.PluginSelectedOption
|
||||
if len(opts) > 0 {
|
||||
opt = &dal.PluginSelectedOption{}
|
||||
for _, o := range opts {
|
||||
o(opt)
|
||||
}
|
||||
}
|
||||
|
||||
return p.pluginDraftDAO.GetAPPAllPlugins(ctx, appID, opt)
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) ListDraftPlugins(ctx context.Context, req *ListDraftPluginsRequest) (resp *ListDraftPluginsResponse, err error) {
|
||||
plugins, total, err := p.pluginDraftDAO.List(ctx, req.SpaceID, req.APPID, req.PageInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp = &ListDraftPluginsResponse{
|
||||
Plugins: plugins,
|
||||
Total: total,
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) UpdateDraftPlugin(ctx context.Context, plugin *entity.PluginInfo) (err error) {
|
||||
tx := p.query.Begin()
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
err = fmt.Errorf("catch panic: %v\nstack=%s", r, string(debug.Stack()))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err = p.pluginDraftDAO.UpdateWithTX(ctx, tx, plugin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = p.toolDraftDAO.ResetAllDebugStatusWithTX(ctx, tx, plugin.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) UpdateDraftPluginWithoutURLChanged(ctx context.Context, plugin *entity.PluginInfo) (err error) {
|
||||
return p.pluginDraftDAO.Update(ctx, plugin)
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) GetOnlinePlugin(ctx context.Context, pluginID int64, opts ...PluginSelectedOptions) (plugin *entity.PluginInfo, exist bool, err error) {
|
||||
pi, exist := pluginConf.GetPluginProduct(pluginID)
|
||||
if exist {
|
||||
return entity.NewPluginInfo(pi.Info), true, nil
|
||||
}
|
||||
|
||||
var opt *dal.PluginSelectedOption
|
||||
if len(opts) > 0 {
|
||||
opt = &dal.PluginSelectedOption{}
|
||||
for _, o := range opts {
|
||||
o(opt)
|
||||
}
|
||||
}
|
||||
|
||||
return p.pluginDAO.Get(ctx, pluginID, opt)
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) MGetOnlinePlugins(ctx context.Context, pluginIDs []int64, opts ...PluginSelectedOptions) (plugins []*entity.PluginInfo, err error) {
|
||||
pluginProducts := pluginConf.MGetPluginProducts(pluginIDs)
|
||||
plugins = slices.Transform(pluginProducts, func(pl *pluginConf.PluginInfo) *entity.PluginInfo {
|
||||
return entity.NewPluginInfo(pl.Info)
|
||||
})
|
||||
productPluginIDs := slices.ToMap(pluginProducts, func(plugin *pluginConf.PluginInfo) (int64, bool) {
|
||||
return plugin.Info.ID, true
|
||||
})
|
||||
|
||||
customPluginIDs := make([]int64, 0, len(pluginIDs))
|
||||
for _, id := range pluginIDs {
|
||||
_, ok := productPluginIDs[id]
|
||||
if ok {
|
||||
continue
|
||||
}
|
||||
customPluginIDs = append(customPluginIDs, id)
|
||||
}
|
||||
|
||||
var opt *dal.PluginSelectedOption
|
||||
if len(opts) > 0 {
|
||||
opt = &dal.PluginSelectedOption{}
|
||||
for _, o := range opts {
|
||||
o(opt)
|
||||
}
|
||||
}
|
||||
|
||||
customPlugins, err := p.pluginDAO.MGet(ctx, customPluginIDs, opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
plugins = append(plugins, customPlugins...)
|
||||
|
||||
return plugins, nil
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) ListCustomOnlinePlugins(ctx context.Context, spaceID int64, pageInfo entity.PageInfo) (plugins []*entity.PluginInfo, total int64, err error) {
|
||||
return p.pluginDAO.List(ctx, spaceID, pageInfo)
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) GetVersionPlugin(ctx context.Context, vPlugin entity.VersionPlugin) (plugin *entity.PluginInfo, exist bool, err error) {
|
||||
pi, exist := pluginConf.GetPluginProduct(vPlugin.PluginID)
|
||||
if exist {
|
||||
return entity.NewPluginInfo(pi.Info), true, nil
|
||||
}
|
||||
|
||||
return p.pluginVersionDAO.Get(ctx, vPlugin.PluginID, vPlugin.Version)
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) MGetVersionPlugins(ctx context.Context, vPlugins []entity.VersionPlugin, opts ...PluginSelectedOptions) (plugins []*entity.PluginInfo, err error) {
|
||||
pluginIDs := make([]int64, 0, len(vPlugins))
|
||||
for _, vPlugin := range vPlugins {
|
||||
pluginIDs = append(pluginIDs, vPlugin.PluginID)
|
||||
}
|
||||
|
||||
pluginProducts := pluginConf.MGetPluginProducts(pluginIDs)
|
||||
plugins = slices.Transform(pluginProducts, func(pl *pluginConf.PluginInfo) *entity.PluginInfo {
|
||||
return entity.NewPluginInfo(pl.Info)
|
||||
})
|
||||
productPluginIDs := slices.ToMap(pluginProducts, func(plugin *pluginConf.PluginInfo) (int64, bool) {
|
||||
return plugin.Info.ID, true
|
||||
})
|
||||
|
||||
vCustomPlugins := make([]entity.VersionPlugin, 0, len(pluginIDs))
|
||||
for _, v := range vPlugins {
|
||||
_, ok := productPluginIDs[v.PluginID]
|
||||
if ok {
|
||||
continue
|
||||
}
|
||||
vCustomPlugins = append(vCustomPlugins, v)
|
||||
}
|
||||
|
||||
var opt *dal.PluginSelectedOption
|
||||
if len(opts) > 0 {
|
||||
opt = &dal.PluginSelectedOption{}
|
||||
for _, o := range opts {
|
||||
o(opt)
|
||||
}
|
||||
}
|
||||
|
||||
customPlugins, err := p.pluginVersionDAO.MGet(ctx, vCustomPlugins, opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
plugins = append(plugins, customPlugins...)
|
||||
|
||||
return plugins, nil
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) PublishPlugin(ctx context.Context, draftPlugin *entity.PluginInfo) (err error) {
|
||||
draftTools, err := p.toolDraftDAO.GetAll(ctx, draftPlugin.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
activatedTools := make([]*entity.ToolInfo, 0, len(draftTools))
|
||||
for _, tool := range draftTools {
|
||||
if tool.GetActivatedStatus() == model.DeactivateTool {
|
||||
continue
|
||||
}
|
||||
|
||||
tool.Version = draftPlugin.Version
|
||||
|
||||
activatedTools = append(activatedTools, tool)
|
||||
}
|
||||
|
||||
if len(activatedTools) == 0 {
|
||||
return errorx.New(errno.ErrPluginToolsCheckFailed, errorx.KVf(errno.PluginMsgKey,
|
||||
"at least one activated tool is required in plugin '%s'", draftPlugin.GetName()))
|
||||
}
|
||||
|
||||
tx := p.query.Begin()
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
err = fmt.Errorf("catch panic: %v\nstack=%s", r, string(debug.Stack()))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err = p.pluginDAO.UpsertWithTX(ctx, tx, draftPlugin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = p.pluginVersionDAO.CreateWithTX(ctx, tx, draftPlugin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = p.toolDAO.DeleteAllWithTX(ctx, tx, draftPlugin.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = p.toolDAO.BatchCreateWithTX(ctx, tx, activatedTools)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = p.toolVersionDAO.BatchCreateWithTX(ctx, tx, activatedTools)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) PublishPlugins(ctx context.Context, draftPlugins []*entity.PluginInfo) (err error) {
|
||||
draftPluginMap := slices.ToMap(draftPlugins, func(plugin *entity.PluginInfo) (int64, *entity.PluginInfo) {
|
||||
return plugin.ID, plugin
|
||||
})
|
||||
|
||||
pluginTools := make(map[int64][]*entity.ToolInfo, len(draftPlugins))
|
||||
for _, draftPlugin := range draftPlugins {
|
||||
draftTools, err := p.toolDraftDAO.GetAll(ctx, draftPlugin.ID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
activatedTools := make([]*entity.ToolInfo, 0, len(draftTools))
|
||||
for _, tool := range draftTools {
|
||||
if tool.GetActivatedStatus() == model.DeactivateTool {
|
||||
continue
|
||||
}
|
||||
|
||||
if tool.DebugStatus == nil ||
|
||||
*tool.DebugStatus == common.APIDebugStatus_DebugWaiting {
|
||||
return errorx.New(errno.ErrPluginToolsCheckFailed, errorx.KVf(errno.PluginMsgKey,
|
||||
"tool '%s' in plugin '%s' has not debugged yet", tool.GetName(), draftPlugin.GetName()))
|
||||
}
|
||||
|
||||
tool.Version = draftPlugin.Version
|
||||
|
||||
activatedTools = append(activatedTools, tool)
|
||||
}
|
||||
|
||||
if len(activatedTools) == 0 {
|
||||
return errorx.New(errno.ErrPluginToolsCheckFailed, errorx.KVf(errno.PluginMsgKey,
|
||||
"at least one activated tool is required in plugin '%s'", draftPlugin.GetName()))
|
||||
}
|
||||
|
||||
pluginTools[draftPlugin.ID] = activatedTools
|
||||
}
|
||||
|
||||
tx := p.query.Begin()
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
err = fmt.Errorf("catch panic: %v\nstack=%s", r, string(debug.Stack()))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
for pluginID, tools := range pluginTools {
|
||||
draftPlugin := draftPluginMap[pluginID]
|
||||
|
||||
err = p.pluginDAO.UpsertWithTX(ctx, tx, draftPlugin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = p.pluginVersionDAO.CreateWithTX(ctx, tx, draftPlugin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = p.toolDAO.DeleteAllWithTX(ctx, tx, draftPlugin.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = p.toolDAO.BatchCreateWithTX(ctx, tx, tools)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = p.toolVersionDAO.BatchCreateWithTX(ctx, tx, tools)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) DeleteDraftPlugin(ctx context.Context, pluginID int64) (err error) {
|
||||
tx := p.query.Begin()
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
err = fmt.Errorf("catch panic: %v\nstack=%s", r, string(debug.Stack()))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err = p.pluginDraftDAO.DeleteWithTX(ctx, tx, pluginID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = p.pluginDAO.DeleteWithTX(ctx, tx, pluginID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = p.pluginVersionDAO.DeleteWithTX(ctx, tx, pluginID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = p.toolDraftDAO.DeleteAllWithTX(ctx, tx, pluginID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = p.toolDAO.DeleteAllWithTX(ctx, tx, pluginID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = p.toolVersionDAO.DeleteWithTX(ctx, tx, pluginID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) DeleteAPPAllPlugins(ctx context.Context, appID int64) (pluginIDs []int64, err error) {
|
||||
opt := &dal.PluginSelectedOption{
|
||||
PluginID: true,
|
||||
}
|
||||
plugins, err := p.pluginDraftDAO.GetAPPAllPlugins(ctx, appID, opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pluginIDs = slices.Transform(plugins, func(plugin *entity.PluginInfo) int64 {
|
||||
return plugin.ID
|
||||
})
|
||||
|
||||
tx := p.query.Begin()
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
err = fmt.Errorf("catch panic: %v\nstack=%s", r, string(debug.Stack()))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
for _, id := range pluginIDs {
|
||||
err = p.pluginDraftDAO.DeleteWithTX(ctx, tx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = p.pluginDAO.DeleteWithTX(ctx, tx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = p.pluginVersionDAO.DeleteWithTX(ctx, tx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = p.toolDraftDAO.DeleteAllWithTX(ctx, tx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = p.toolDAO.DeleteAllWithTX(ctx, tx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = p.toolVersionDAO.DeleteWithTX(ctx, tx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return pluginIDs, nil
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) UpdateDraftPluginWithCode(ctx context.Context, req *UpdatePluginDraftWithCode) (err error) {
|
||||
tx := p.query.Begin()
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
err = fmt.Errorf("catch panic: %v\nstack=%s", r, string(debug.Stack()))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
newDoc := &model.Openapi3T{}
|
||||
err = copier.CopyWithOption(newDoc, req.OpenapiDoc, copier.Option{DeepCopy: true, IgnoreEmpty: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
newDoc.Paths = openapi3.Paths{} // reset paths
|
||||
|
||||
updatedPlugin := entity.NewPluginInfo(&model.PluginInfo{
|
||||
ID: req.PluginID,
|
||||
ServerURL: ptr.Of(req.OpenapiDoc.Servers[0].URL),
|
||||
Manifest: req.Manifest,
|
||||
OpenapiDoc: req.OpenapiDoc,
|
||||
})
|
||||
err = p.pluginDraftDAO.UpdateWithTX(ctx, tx, updatedPlugin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, tool := range req.UpdatedTools {
|
||||
err = p.toolDraftDAO.UpdateWithTX(ctx, tx, tool)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if len(req.NewDraftTools) > 0 {
|
||||
_, err = p.toolDraftDAO.BatchCreateWithTX(ctx, tx, req.NewDraftTools)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) CreateDraftPluginWithCode(ctx context.Context, req *CreateDraftPluginWithCodeRequest) (resp *CreateDraftPluginWithCodeResponse, err error) {
|
||||
doc := req.OpenapiDoc
|
||||
mf := req.Manifest
|
||||
|
||||
pluginType, _ := model.ToThriftPluginType(mf.API.Type)
|
||||
|
||||
pl := entity.NewPluginInfo(&model.PluginInfo{
|
||||
PluginType: pluginType,
|
||||
SpaceID: req.SpaceID,
|
||||
DeveloperID: req.DeveloperID,
|
||||
APPID: req.ProjectID,
|
||||
IconURI: ptr.Of(mf.LogoURL),
|
||||
ServerURL: ptr.Of(doc.Servers[0].URL),
|
||||
Manifest: mf,
|
||||
OpenapiDoc: doc,
|
||||
})
|
||||
|
||||
tools := make([]*entity.ToolInfo, 0, len(doc.Paths))
|
||||
for subURL, pathItem := range doc.Paths {
|
||||
for method, op := range pathItem.Operations() {
|
||||
tools = append(tools, &entity.ToolInfo{
|
||||
ActivatedStatus: ptr.Of(model.ActivateTool),
|
||||
DebugStatus: ptr.Of(common.APIDebugStatus_DebugWaiting),
|
||||
SubURL: ptr.Of(subURL),
|
||||
Method: ptr.Of(method),
|
||||
Operation: model.NewOpenapi3Operation(op),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
tx := p.query.Begin()
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
err = fmt.Errorf("catch panic: %v\nstack=%s", r, string(debug.Stack()))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
pluginID, err := p.pluginDraftDAO.CreateWithTX(ctx, tx, pl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pl.ID = pluginID
|
||||
|
||||
for _, tool := range tools {
|
||||
tool.PluginID = pluginID
|
||||
}
|
||||
|
||||
_, err = p.toolDraftDAO.BatchCreateWithTX(ctx, tx, tools)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &CreateDraftPluginWithCodeResponse{
|
||||
Plugin: pl,
|
||||
Tools: tools,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) CopyPlugin(ctx context.Context, req *CopyPluginRequest) (plugin *entity.PluginInfo, tools []*entity.ToolInfo, err error) {
|
||||
tx := p.query.Begin()
|
||||
if tx.Error != nil {
|
||||
return nil, nil, tx.Error
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
err = fmt.Errorf("catch panic: %v\nstack=%s", r, string(debug.Stack()))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
plugin, tools = req.Plugin, req.Tools
|
||||
|
||||
newPluginID, err := p.pluginDraftDAO.CreateWithTX(ctx, tx, plugin)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
plugin.ID = newPluginID
|
||||
for _, tool := range tools {
|
||||
tool.PluginID = newPluginID
|
||||
}
|
||||
|
||||
toolIDs, err := p.toolDraftDAO.BatchCreateWithTX(ctx, tx, tools)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
for i, tool := range tools {
|
||||
tool.ID = toolIDs[i]
|
||||
}
|
||||
|
||||
if plugin.GetVersion() == "" {
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return plugin, tools, nil
|
||||
}
|
||||
|
||||
// publish plugin
|
||||
filteredTools := make([]*entity.ToolInfo, 0, len(tools))
|
||||
for _, tool := range tools {
|
||||
if tool.GetActivatedStatus() == model.DeactivateTool ||
|
||||
tool.GetDebugStatus() == common.APIDebugStatus_DebugWaiting {
|
||||
continue
|
||||
}
|
||||
filteredTools = append(filteredTools, tool)
|
||||
}
|
||||
|
||||
if len(filteredTools) == 0 {
|
||||
return nil, nil, fmt.Errorf("at least one activated tool is required in plugin '%d'", plugin.ID)
|
||||
}
|
||||
|
||||
err = p.pluginDAO.UpsertWithTX(ctx, tx, plugin)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
err = p.pluginVersionDAO.CreateWithTX(ctx, tx, plugin)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
err = p.toolDAO.BatchCreateWithTX(ctx, tx, filteredTools)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
err = p.toolVersionDAO.BatchCreateWithTX(ctx, tx, filteredTools)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return req.Plugin, req.Tools, nil
|
||||
}
|
||||
|
||||
func (p *pluginRepoImpl) MoveAPPPluginToLibrary(ctx context.Context, draftPlugin *entity.PluginInfo,
|
||||
draftTools []*entity.ToolInfo) (err error) {
|
||||
|
||||
tx := p.query.Begin()
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
err = fmt.Errorf("catch panic: %v\nstack=%s", r, string(debug.Stack()))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err = p.pluginDraftDAO.UpdateWithTX(ctx, tx, draftPlugin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = p.pluginDAO.DeleteWithTX(ctx, tx, draftPlugin.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = p.pluginVersionDAO.DeleteWithTX(ctx, tx, draftPlugin.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = p.toolDAO.DeleteAllWithTX(ctx, tx, draftPlugin.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = p.toolVersionDAO.DeleteWithTX(ctx, tx, draftPlugin.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// publish plugin
|
||||
err = p.pluginDAO.UpsertWithTX(ctx, tx, draftPlugin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = p.pluginVersionDAO.CreateWithTX(ctx, tx, draftPlugin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = p.toolDAO.BatchCreateWithTX(ctx, tx, draftTools)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = p.toolVersionDAO.BatchCreateWithTX(ctx, tx, draftTools)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
89
backend/domain/plugin/repository/plugin_repository.go
Normal file
89
backend/domain/plugin/repository/plugin_repository.go
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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 repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
)
|
||||
|
||||
type PluginRepository interface {
|
||||
CreateDraftPlugin(ctx context.Context, plugin *entity.PluginInfo) (pluginID int64, err error)
|
||||
CreateDraftPluginWithCode(ctx context.Context, req *CreateDraftPluginWithCodeRequest) (resp *CreateDraftPluginWithCodeResponse, err error)
|
||||
GetDraftPlugin(ctx context.Context, pluginID int64, opts ...PluginSelectedOptions) (plugin *entity.PluginInfo, exist bool, err error)
|
||||
MGetDraftPlugins(ctx context.Context, pluginIDs []int64, opts ...PluginSelectedOptions) (plugins []*entity.PluginInfo, err error)
|
||||
GetAPPAllDraftPlugins(ctx context.Context, appID int64, opts ...PluginSelectedOptions) (plugins []*entity.PluginInfo, err error)
|
||||
ListDraftPlugins(ctx context.Context, req *ListDraftPluginsRequest) (resp *ListDraftPluginsResponse, err error)
|
||||
UpdateDraftPlugin(ctx context.Context, plugin *entity.PluginInfo) (err error)
|
||||
UpdateDraftPluginWithoutURLChanged(ctx context.Context, plugin *entity.PluginInfo) (err error)
|
||||
UpdateDraftPluginWithCode(ctx context.Context, req *UpdatePluginDraftWithCode) (err error)
|
||||
DeleteDraftPlugin(ctx context.Context, pluginID int64) (err error)
|
||||
DeleteAPPAllPlugins(ctx context.Context, appID int64) (pluginIDs []int64, err error)
|
||||
|
||||
GetOnlinePlugin(ctx context.Context, pluginID int64, opts ...PluginSelectedOptions) (plugin *entity.PluginInfo, exist bool, err error)
|
||||
MGetOnlinePlugins(ctx context.Context, pluginIDs []int64, opts ...PluginSelectedOptions) (plugins []*entity.PluginInfo, err error)
|
||||
ListCustomOnlinePlugins(ctx context.Context, spaceID int64, pageInfo entity.PageInfo) (plugins []*entity.PluginInfo, total int64, err error)
|
||||
|
||||
GetVersionPlugin(ctx context.Context, vPlugin entity.VersionPlugin) (plugin *entity.PluginInfo, exist bool, err error)
|
||||
MGetVersionPlugins(ctx context.Context, vPlugins []entity.VersionPlugin, opts ...PluginSelectedOptions) (plugin []*entity.PluginInfo, err error)
|
||||
|
||||
PublishPlugin(ctx context.Context, draftPlugin *entity.PluginInfo) (err error)
|
||||
PublishPlugins(ctx context.Context, draftPlugins []*entity.PluginInfo) (err error)
|
||||
|
||||
CopyPlugin(ctx context.Context, req *CopyPluginRequest) (plugin *entity.PluginInfo, tools []*entity.ToolInfo, err error)
|
||||
MoveAPPPluginToLibrary(ctx context.Context, draftPlugin *entity.PluginInfo, draftTools []*entity.ToolInfo) (err error)
|
||||
}
|
||||
|
||||
type UpdatePluginDraftWithCode struct {
|
||||
PluginID int64
|
||||
OpenapiDoc *plugin.Openapi3T
|
||||
Manifest *entity.PluginManifest
|
||||
|
||||
UpdatedTools []*entity.ToolInfo
|
||||
NewDraftTools []*entity.ToolInfo
|
||||
}
|
||||
|
||||
type CreateDraftPluginWithCodeRequest struct {
|
||||
SpaceID int64
|
||||
DeveloperID int64
|
||||
ProjectID *int64
|
||||
Manifest *entity.PluginManifest
|
||||
OpenapiDoc *plugin.Openapi3T
|
||||
}
|
||||
|
||||
type CreateDraftPluginWithCodeResponse struct {
|
||||
Plugin *entity.PluginInfo
|
||||
Tools []*entity.ToolInfo
|
||||
}
|
||||
|
||||
type ListDraftPluginsRequest struct {
|
||||
SpaceID int64
|
||||
APPID int64
|
||||
PageInfo entity.PageInfo
|
||||
}
|
||||
|
||||
type ListDraftPluginsResponse struct {
|
||||
Plugins []*entity.PluginInfo
|
||||
Total int64
|
||||
}
|
||||
|
||||
type CopyPluginRequest struct {
|
||||
Plugin *entity.PluginInfo
|
||||
Tools []*entity.ToolInfo
|
||||
}
|
||||
429
backend/domain/plugin/repository/tool_impl.go
Normal file
429
backend/domain/plugin/repository/tool_impl.go
Normal file
@@ -0,0 +1,429 @@
|
||||
/*
|
||||
* 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 repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
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"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/internal/dal/query"
|
||||
"github.com/coze-dev/coze-studio/backend/infra/contract/idgen"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/slices"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/logs"
|
||||
)
|
||||
|
||||
type toolRepoImpl struct {
|
||||
query *query.Query
|
||||
|
||||
pluginDraftDAO *dal.PluginDraftDAO
|
||||
|
||||
toolDraftDAO *dal.ToolDraftDAO
|
||||
toolDAO *dal.ToolDAO
|
||||
toolVersionDAO *dal.ToolVersionDAO
|
||||
agentToolDraftDAO *dal.AgentToolDraftDAO
|
||||
agentToolVersionDAO *dal.AgentToolVersionDAO
|
||||
}
|
||||
|
||||
type ToolRepoComponents struct {
|
||||
IDGen idgen.IDGenerator
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewToolRepo(components *ToolRepoComponents) ToolRepository {
|
||||
return &toolRepoImpl{
|
||||
query: query.Use(components.DB),
|
||||
pluginDraftDAO: dal.NewPluginDraftDAO(components.DB, components.IDGen),
|
||||
toolDraftDAO: dal.NewToolDraftDAO(components.DB, components.IDGen),
|
||||
toolDAO: dal.NewToolDAO(components.DB, components.IDGen),
|
||||
toolVersionDAO: dal.NewToolVersionDAO(components.DB, components.IDGen),
|
||||
agentToolDraftDAO: dal.NewAgentToolDraftDAO(components.DB, components.IDGen),
|
||||
agentToolVersionDAO: dal.NewAgentToolVersionDAO(components.DB, components.IDGen),
|
||||
}
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) CreateDraftTool(ctx context.Context, tool *entity.ToolInfo) (toolID int64, err error) {
|
||||
return t.toolDraftDAO.Create(ctx, tool)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) UpsertDraftTools(ctx context.Context, pluginID int64, tools []*entity.ToolInfo) (err error) {
|
||||
apis := slices.Transform(tools, func(tool *entity.ToolInfo) entity.UniqueToolAPI {
|
||||
return entity.UniqueToolAPI{
|
||||
SubURL: tool.GetSubURL(),
|
||||
Method: tool.GetMethod(),
|
||||
}
|
||||
})
|
||||
|
||||
existTools, err := t.toolDraftDAO.MGetWithAPIs(ctx, pluginID, apis, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tx := t.query.Begin()
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
err = fmt.Errorf("catch panic: %v\nstack=%s", r, string(debug.Stack()))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
createdTools := make([]*entity.ToolInfo, 0, len(tools))
|
||||
updatedTools := make([]*entity.ToolInfo, 0, len(existTools))
|
||||
|
||||
for _, tool := range tools {
|
||||
existTool, exist := existTools[entity.UniqueToolAPI{
|
||||
SubURL: tool.GetSubURL(),
|
||||
Method: tool.GetMethod(),
|
||||
}]
|
||||
if !exist {
|
||||
createdTools = append(createdTools, tool)
|
||||
continue
|
||||
}
|
||||
|
||||
tool.ID = existTool.ID
|
||||
|
||||
updatedTools = append(updatedTools, tool)
|
||||
}
|
||||
|
||||
if len(createdTools) > 0 {
|
||||
_, err = t.toolDraftDAO.BatchCreateWithTX(ctx, tx, createdTools)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if len(updatedTools) > 0 {
|
||||
err = t.toolDraftDAO.BatchUpdateWithTX(ctx, tx, updatedTools)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) UpdateDraftTool(ctx context.Context, tool *entity.ToolInfo) (err error) {
|
||||
return t.toolDraftDAO.Update(ctx, tool)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetDraftTool(ctx context.Context, toolID int64) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
return t.toolDraftDAO.Get(ctx, toolID)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) MGetDraftTools(ctx context.Context, toolIDs []int64, opts ...ToolSelectedOptions) (tools []*entity.ToolInfo, err error) {
|
||||
var opt *dal.ToolSelectedOption
|
||||
if len(opts) > 0 {
|
||||
opt = &dal.ToolSelectedOption{}
|
||||
for _, o := range opts {
|
||||
o(opt)
|
||||
}
|
||||
}
|
||||
return t.toolDraftDAO.MGet(ctx, toolIDs, opt)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetPluginAllDraftTools(ctx context.Context, pluginID int64, opts ...ToolSelectedOptions) (tools []*entity.ToolInfo, err error) {
|
||||
var opt *dal.ToolSelectedOption
|
||||
if len(opts) > 0 {
|
||||
opt = &dal.ToolSelectedOption{}
|
||||
for _, o := range opts {
|
||||
o(opt)
|
||||
}
|
||||
}
|
||||
return t.toolDraftDAO.GetAll(ctx, pluginID, opt)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetPluginAllOnlineTools(ctx context.Context, pluginID int64) (tools []*entity.ToolInfo, err error) {
|
||||
pi, exist := pluginConf.GetPluginProduct(pluginID)
|
||||
if exist {
|
||||
tis := pi.GetPluginAllTools()
|
||||
tools = slices.Transform(tis, func(ti *pluginConf.ToolInfo) *entity.ToolInfo {
|
||||
return ti.Info
|
||||
})
|
||||
|
||||
return tools, nil
|
||||
}
|
||||
|
||||
tools, err = t.toolDAO.GetAll(ctx, pluginID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return tools, nil
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) ListPluginDraftTools(ctx context.Context, pluginID int64, pageInfo entity.PageInfo) (tools []*entity.ToolInfo, total int64, err error) {
|
||||
return t.toolDraftDAO.List(ctx, pluginID, pageInfo)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetDraftToolWithAPI(ctx context.Context, pluginID int64, api entity.UniqueToolAPI) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
return t.toolDraftDAO.GetWithAPI(ctx, pluginID, api)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) MGetDraftToolWithAPI(ctx context.Context, pluginID int64, apis []entity.UniqueToolAPI, opts ...ToolSelectedOptions) (tools map[entity.UniqueToolAPI]*entity.ToolInfo, err error) {
|
||||
var opt *dal.ToolSelectedOption
|
||||
if len(opts) > 0 {
|
||||
opt = &dal.ToolSelectedOption{}
|
||||
for _, o := range opts {
|
||||
o(opt)
|
||||
}
|
||||
}
|
||||
return t.toolDraftDAO.MGetWithAPIs(ctx, pluginID, apis, opt)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) DeleteDraftTool(ctx context.Context, toolID int64) (err error) {
|
||||
return t.toolDraftDAO.Delete(ctx, toolID)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetOnlineTool(ctx context.Context, toolID int64) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
ti, exist := pluginConf.GetToolProduct(toolID)
|
||||
if exist {
|
||||
return ti.Info, true, nil
|
||||
}
|
||||
|
||||
return t.toolDAO.Get(ctx, toolID)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) MGetOnlineTools(ctx context.Context, toolIDs []int64, opts ...ToolSelectedOptions) (tools []*entity.ToolInfo, err error) {
|
||||
toolProducts := pluginConf.MGetToolProducts(toolIDs)
|
||||
tools = slices.Transform(toolProducts, func(tool *pluginConf.ToolInfo) *entity.ToolInfo {
|
||||
return tool.Info
|
||||
})
|
||||
productToolIDs := slices.ToMap(toolProducts, func(tool *pluginConf.ToolInfo) (int64, bool) {
|
||||
return tool.Info.ID, true
|
||||
})
|
||||
|
||||
customToolIDs := make([]int64, 0, len(toolIDs))
|
||||
for _, id := range toolIDs {
|
||||
_, ok := productToolIDs[id]
|
||||
if ok {
|
||||
continue
|
||||
}
|
||||
customToolIDs = append(customToolIDs, id)
|
||||
}
|
||||
|
||||
var opt *dal.ToolSelectedOption
|
||||
if len(opts) > 0 {
|
||||
opt = &dal.ToolSelectedOption{}
|
||||
for _, o := range opts {
|
||||
o(opt)
|
||||
}
|
||||
}
|
||||
|
||||
customTools, err := t.toolDAO.MGet(ctx, customToolIDs, opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tools = append(tools, customTools...)
|
||||
|
||||
return tools, nil
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetVersionTool(ctx context.Context, vTool entity.VersionTool) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
ti, exist := pluginConf.GetToolProduct(vTool.ToolID)
|
||||
if exist {
|
||||
return ti.Info, true, nil
|
||||
}
|
||||
|
||||
return t.toolVersionDAO.Get(ctx, vTool)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) MGetVersionTools(ctx context.Context, versionTools []entity.VersionTool) (tools []*entity.ToolInfo, err error) {
|
||||
tools, err = t.toolVersionDAO.MGet(ctx, versionTools)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return tools, nil
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) BindDraftAgentTools(ctx context.Context, agentID int64, toolIDs []int64) (err error) {
|
||||
onlineTools, err := t.MGetOnlineTools(ctx, toolIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(onlineTools) == 0 {
|
||||
return t.agentToolDraftDAO.DeleteAll(ctx, agentID)
|
||||
}
|
||||
|
||||
tx := t.query.Begin()
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
err = fmt.Errorf("catch panic: %v\nstack=%s", r, string(debug.Stack()))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err = t.agentToolDraftDAO.DeleteAllWithTX(ctx, tx, agentID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = t.agentToolDraftDAO.BatchCreateWithTX(ctx, tx, agentID, onlineTools)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetAgentPluginIDs(ctx context.Context, agentID int64) (pluginIDs []int64, err error) {
|
||||
return t.agentToolDraftDAO.GetAllPluginIDs(ctx, agentID)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) DuplicateDraftAgentTools(ctx context.Context, fromAgentID, toAgentID int64) (err error) {
|
||||
tools, err := t.agentToolDraftDAO.GetAll(ctx, fromAgentID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(tools) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
tx := t.query.Begin()
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
err = fmt.Errorf("catch panic: %v\nstack=%s", r, string(debug.Stack()))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err = t.agentToolDraftDAO.BatchCreateWithTX(ctx, tx, toAgentID, tools)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetDraftAgentTool(ctx context.Context, agentID, toolID int64) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
return t.agentToolDraftDAO.Get(ctx, agentID, toolID)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetDraftAgentToolWithToolName(ctx context.Context, agentID int64, toolName string) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
return t.agentToolDraftDAO.GetWithToolName(ctx, agentID, toolName)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) MGetDraftAgentTools(ctx context.Context, agentID int64, toolIDs []int64) (tools []*entity.ToolInfo, err error) {
|
||||
return t.agentToolDraftDAO.MGet(ctx, agentID, toolIDs)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) UpdateDraftAgentTool(ctx context.Context, req *UpdateDraftAgentToolRequest) (err error) {
|
||||
return t.agentToolDraftDAO.UpdateWithToolName(ctx, req.AgentID, req.ToolName, req.Tool)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetSpaceAllDraftAgentTools(ctx context.Context, agentID int64) (tools []*entity.ToolInfo, err error) {
|
||||
return t.agentToolDraftDAO.GetAll(ctx, agentID)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetVersionAgentTool(ctx context.Context, agentID int64, vAgentTool entity.VersionAgentTool) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
return t.agentToolVersionDAO.Get(ctx, agentID, vAgentTool)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) GetVersionAgentToolWithToolName(ctx context.Context, req *GetVersionAgentToolWithToolNameRequest) (tool *entity.ToolInfo, exist bool, err error) {
|
||||
return t.agentToolVersionDAO.GetWithToolName(ctx, req.AgentID, req.ToolName, req.AgentVersion)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) MGetVersionAgentTool(ctx context.Context, agentID int64, vAgentTools []entity.VersionAgentTool) (tools []*entity.ToolInfo, err error) {
|
||||
return t.agentToolVersionDAO.MGet(ctx, agentID, vAgentTools)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) BatchCreateVersionAgentTools(ctx context.Context, agentID int64, agentVersion string, tools []*entity.ToolInfo) (err error) {
|
||||
return t.agentToolVersionDAO.BatchCreate(ctx, agentID, agentVersion, tools)
|
||||
}
|
||||
|
||||
func (t *toolRepoImpl) UpdateDraftToolAndDebugExample(ctx context.Context, pluginID int64, doc *plugin.Openapi3T, updatedTool *entity.ToolInfo) (err error) {
|
||||
tx := t.query.Begin()
|
||||
if tx.Error != nil {
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
err = fmt.Errorf("catch panic: %v\nstack=%s", r, string(debug.Stack()))
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if e := tx.Rollback(); e != nil {
|
||||
logs.CtxErrorf(ctx, "rollback failed, err=%v", e)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err = t.toolDraftDAO.UpdateWithTX(ctx, tx, updatedTool)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
updatedPlugin := entity.NewPluginInfo(&plugin.PluginInfo{
|
||||
ID: pluginID,
|
||||
OpenapiDoc: doc,
|
||||
})
|
||||
err = t.pluginDraftDAO.UpdateWithTX(ctx, tx, updatedPlugin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
74
backend/domain/plugin/repository/tool_repository.go
Normal file
74
backend/domain/plugin/repository/tool_repository.go
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/crossdomain/plugin"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/plugin/entity"
|
||||
)
|
||||
|
||||
type ToolRepository interface {
|
||||
CreateDraftTool(ctx context.Context, tool *entity.ToolInfo) (toolID int64, err error)
|
||||
UpsertDraftTools(ctx context.Context, pluginID int64, tools []*entity.ToolInfo) (err error)
|
||||
UpdateDraftTool(ctx context.Context, tool *entity.ToolInfo) (err error)
|
||||
GetDraftTool(ctx context.Context, toolID int64) (tool *entity.ToolInfo, exist bool, err error)
|
||||
MGetDraftTools(ctx context.Context, toolIDs []int64, opts ...ToolSelectedOptions) (tools []*entity.ToolInfo, err error)
|
||||
|
||||
GetDraftToolWithAPI(ctx context.Context, pluginID int64, api entity.UniqueToolAPI) (tool *entity.ToolInfo, exist bool, err error)
|
||||
MGetDraftToolWithAPI(ctx context.Context, pluginID int64, apis []entity.UniqueToolAPI, opts ...ToolSelectedOptions) (tools map[entity.UniqueToolAPI]*entity.ToolInfo, err error)
|
||||
DeleteDraftTool(ctx context.Context, toolID int64) (err error)
|
||||
|
||||
GetOnlineTool(ctx context.Context, toolID int64) (tool *entity.ToolInfo, exist bool, err error)
|
||||
MGetOnlineTools(ctx context.Context, toolIDs []int64, opts ...ToolSelectedOptions) (tools []*entity.ToolInfo, err error)
|
||||
|
||||
GetVersionTool(ctx context.Context, vTool entity.VersionTool) (tool *entity.ToolInfo, exist bool, err error)
|
||||
MGetVersionTools(ctx context.Context, vTools []entity.VersionTool) (tools []*entity.ToolInfo, err error)
|
||||
|
||||
BindDraftAgentTools(ctx context.Context, agentID int64, toolIDs []int64) (err error)
|
||||
DuplicateDraftAgentTools(ctx context.Context, fromAgentID, toAgentID int64) (err error)
|
||||
GetDraftAgentTool(ctx context.Context, agentID, toolID int64) (tool *entity.ToolInfo, exist bool, err error)
|
||||
GetDraftAgentToolWithToolName(ctx context.Context, agentID int64, toolName string) (tool *entity.ToolInfo, exist bool, err error)
|
||||
MGetDraftAgentTools(ctx context.Context, agentID int64, toolIDs []int64) (tools []*entity.ToolInfo, err error)
|
||||
UpdateDraftAgentTool(ctx context.Context, req *UpdateDraftAgentToolRequest) (err error)
|
||||
GetSpaceAllDraftAgentTools(ctx context.Context, agentID int64) (tools []*entity.ToolInfo, err error)
|
||||
GetAgentPluginIDs(ctx context.Context, agentID int64) (pluginIDs []int64, err error)
|
||||
|
||||
GetVersionAgentTool(ctx context.Context, agentID int64, vAgentTool entity.VersionAgentTool) (tool *entity.ToolInfo, exist bool, err error)
|
||||
GetVersionAgentToolWithToolName(ctx context.Context, req *GetVersionAgentToolWithToolNameRequest) (tool *entity.ToolInfo, exist bool, err error)
|
||||
MGetVersionAgentTool(ctx context.Context, agentID int64, vAgentTools []entity.VersionAgentTool) (tools []*entity.ToolInfo, err error)
|
||||
BatchCreateVersionAgentTools(ctx context.Context, agentID int64, agentVersion string, tools []*entity.ToolInfo) (err error)
|
||||
|
||||
UpdateDraftToolAndDebugExample(ctx context.Context, pluginID int64, doc *plugin.Openapi3T, updatedTool *entity.ToolInfo) (err error)
|
||||
|
||||
GetPluginAllDraftTools(ctx context.Context, pluginID int64, opts ...ToolSelectedOptions) (tools []*entity.ToolInfo, err error)
|
||||
GetPluginAllOnlineTools(ctx context.Context, pluginID int64) (tools []*entity.ToolInfo, err error)
|
||||
ListPluginDraftTools(ctx context.Context, pluginID int64, pageInfo entity.PageInfo) (tools []*entity.ToolInfo, total int64, err error)
|
||||
}
|
||||
|
||||
type GetVersionAgentToolWithToolNameRequest struct {
|
||||
AgentID int64
|
||||
ToolName string
|
||||
AgentVersion *string
|
||||
}
|
||||
|
||||
type UpdateDraftAgentToolRequest struct {
|
||||
AgentID int64
|
||||
ToolName string
|
||||
Tool *entity.ToolInfo
|
||||
}
|
||||
Reference in New Issue
Block a user