@@ -40,8 +40,11 @@ import (
4040 common "github.com/coze-dev/coze-studio/backend/api/model/plugin_develop/common"
4141 resCommon "github.com/coze-dev/coze-studio/backend/api/model/resource/common"
4242 "github.com/coze-dev/coze-studio/backend/application/base/ctxutil"
43- "github.com/coze-dev/coze-studio/backend/application/base/pluginutil"
43+ "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/builder"
44+ "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/consts"
45+ "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/convert"
4446 model "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto"
47+ pluginDTO "github.com/coze-dev/coze-studio/backend/crossdomain/contract/plugin/dto"
4548 pluginConf "github.com/coze-dev/coze-studio/backend/domain/plugin/conf"
4649 "github.com/coze-dev/coze-studio/backend/domain/plugin/dto"
4750 "github.com/coze-dev/coze-studio/backend/domain/plugin/encrypt"
@@ -140,15 +143,15 @@ func (p *PluginApplicationService) getPlaygroundPluginListByIDs(ctx context.Cont
140143}
141144
142145func (p * PluginApplicationService ) getPlaygroundPluginList (ctx context.Context , req * pluginAPI.GetPlaygroundPluginListRequest ) (plugins []* entity.PluginInfo , total int64 , err error ) {
143- pageInfo := entity .PageInfo {
146+ pageInfo := dto .PageInfo {
144147 Name : req .Name ,
145148 Page : int (req .GetPage ()),
146149 Size : int (req .GetSize ()),
147- SortBy : func () * entity .SortField {
150+ SortBy : func () * dto .SortField {
148151 if req .GetOrderBy () == 0 {
149- return ptr .Of (entity .SortByUpdatedAt )
152+ return ptr .Of (dto .SortByUpdatedAt )
150153 }
151- return ptr .Of (entity .SortByCreatedAt )
154+ return ptr .Of (dto .SortByCreatedAt )
152155 }(),
153156 OrderByACS : ptr .Of (false ),
154157 }
@@ -198,7 +201,7 @@ func (p *PluginApplicationService) toPluginInfoForPlayground(ctx context.Context
198201 logs .Errorf ("get plugin icon url failed, err=%v" , err )
199202 }
200203
201- authType , ok := model .ToThriftAuthType (pl .GetAuthInfo ().Type )
204+ authType , ok := convert .ToThriftAuthType (pl .GetAuthInfo ().Type )
202205 if ! ok {
203206 return nil , fmt .Errorf ("invalid auth type '%s'" , pl .GetAuthInfo ().Type )
204207 }
@@ -234,27 +237,27 @@ func (p *PluginApplicationService) RegisterPluginMeta(ctx context.Context, req *
234237 return nil , errorx .New (errno .ErrPluginPermissionCode , errorx .KV (errno .PluginMsgKey , "session is required" ))
235238 }
236239
237- _authType , ok := model .ToAuthType (req .GetAuthType ())
240+ _authType , ok := convert .ToAuthType (req .GetAuthType ())
238241 if ! ok {
239242 return nil , fmt .Errorf ("invalid auth type '%d'" , req .GetAuthType ())
240243 }
241244 authType := ptr .Of (_authType )
242245
243- var authSubType * model .AuthzSubType
246+ var authSubType * consts .AuthzSubType
244247 if req .SubAuthType != nil {
245- _authSubType , ok := model .ToAuthSubType (req .GetSubAuthType ())
248+ _authSubType , ok := convert .ToAuthSubType (req .GetSubAuthType ())
246249 if ! ok {
247250 return nil , fmt .Errorf ("invalid sub authz type '%d'" , req .GetSubAuthType ())
248251 }
249252 authSubType = ptr .Of (_authSubType )
250253 }
251254
252- var loc model .HTTPParamLocation
253- if * authType == model .AuthzTypeOfService {
255+ var loc consts .HTTPParamLocation
256+ if * authType == consts .AuthzTypeOfService {
254257 if req .GetLocation () == common .AuthorizationServiceLocation_Query {
255- loc = model .ParamInQuery
258+ loc = consts .ParamInQuery
256259 } else if req .GetLocation () == common .AuthorizationServiceLocation_Header {
257- loc = model .ParamInHeader
260+ loc = consts .ParamInHeader
258261 } else {
259262 return nil , fmt .Errorf ("invalid location '%s'" , req .GetLocation ())
260263 }
@@ -396,10 +399,10 @@ func (p *PluginApplicationService) GetPluginAPIs(ctx context.Context, req *plugi
396399 total = int64 (len (draftTools ))
397400
398401 } else {
399- pageInfo := entity .PageInfo {
402+ pageInfo := dto .PageInfo {
400403 Page : int (req .Page ),
401404 Size : int (req .Size ),
402- SortBy : ptr .Of (entity .SortByCreatedAt ),
405+ SortBy : ptr .Of (dto .SortByCreatedAt ),
403406 OrderByACS : ptr .Of (false ),
404407 }
405408 draftTools , total , err = p .toolRepo .ListPluginDraftTools (ctx , req .PluginID , pageInfo )
@@ -425,7 +428,7 @@ func (p *PluginApplicationService) GetPluginAPIs(ctx context.Context, req *plugi
425428
426429 apis := make ([]* common.PluginAPIInfo , 0 , len (draftTools ))
427430 for _ , tool := range draftTools {
428- method , ok := model .ToThriftAPIMethod (tool .GetMethod ())
431+ method , ok := convert .ToThriftAPIMethod (tool .GetMethod ())
429432 if ! ok {
430433 return nil , fmt .Errorf ("invalid method '%s'" , tool .GetMethod ())
431434 }
@@ -439,8 +442,8 @@ func (p *PluginApplicationService) GetPluginAPIs(ctx context.Context, req *plugi
439442 }
440443
441444 var apiExtend * common.APIExtend
442- if tmp , ok := tool .Operation .Extensions [model .APISchemaExtendAuthMode ].(string ); ok {
443- if mode , ok := model .ToThriftAPIAuthMode (model .ToolAuthMode (tmp )); ok {
445+ if tmp , ok := tool .Operation .Extensions [consts .APISchemaExtendAuthMode ].(string ); ok {
446+ if mode , ok := convert .ToThriftAPIAuthMode (consts .ToolAuthMode (tmp )); ok {
444447 apiExtend = & common.APIExtend {
445448 AuthMode : mode ,
446449 }
@@ -453,7 +456,7 @@ func (p *PluginApplicationService) GetPluginAPIs(ctx context.Context, req *plugi
453456 DebugStatus : tool .GetDebugStatus (),
454457 Desc : tool .GetDesc (),
455458 Disabled : func () bool {
456- if tool .GetActivatedStatus () == model .DeactivateTool {
459+ if tool .GetActivatedStatus () == consts .DeactivateTool {
457460 return true
458461 }
459462 return false
@@ -544,7 +547,7 @@ func (p *PluginApplicationService) getPluginCodeInfo(ctx context.Context, draftP
544547
545548 paths := openapi3.Paths {}
546549 for _ , tool := range tools {
547- if tool .GetActivatedStatus () == model .DeactivateTool {
550+ if tool .GetActivatedStatus () == consts .DeactivateTool {
548551 continue
549552 }
550553 item := & openapi3.PathItem {}
@@ -574,7 +577,7 @@ func (p *PluginApplicationService) getPluginCodeInfo(ctx context.Context, draftP
574577func (p * PluginApplicationService ) getPluginMetaInfo (ctx context.Context , draftPlugin * entity.PluginInfo ) (* common.PluginMetaInfo , error ) {
575578 commonParams := make (map [common.ParameterLocation ][]* common.CommonParamSchema , len (draftPlugin .Manifest .CommonParams ))
576579 for loc , params := range draftPlugin .Manifest .CommonParams {
577- location , ok := model .ToThriftHTTPParamLocation (loc )
580+ location , ok := convert .ToThriftHTTPParamLocation (loc )
578581 if ! ok {
579582 return nil , fmt .Errorf ("invalid location '%s'" , loc )
580583 }
@@ -613,14 +616,14 @@ func (p *PluginApplicationService) getPluginMetaInfo(ctx context.Context, draftP
613616
614617func (p * PluginApplicationService ) fillAuthInfoInMetaInfo (ctx context.Context , draftPlugin * entity.PluginInfo , metaInfo * common.PluginMetaInfo ) (err error ) {
615618 authInfo := draftPlugin .GetAuthInfo ()
616- authType , ok := model .ToThriftAuthType (authInfo .Type )
619+ authType , ok := convert .ToThriftAuthType (authInfo .Type )
617620 if ! ok {
618621 return fmt .Errorf ("invalid auth type '%s'" , authInfo .Type )
619622 }
620623
621624 var subAuthType * int32
622625 if authInfo .SubType != "" {
623- _subAuthType , ok := model .ToThriftAuthSubType (authInfo .SubType )
626+ _subAuthType , ok := convert .ToThriftAuthSubType (authInfo .SubType )
624627 if ! ok {
625628 return fmt .Errorf ("invalid sub authz type '%s'" , authInfo .SubType )
626629 }
@@ -636,10 +639,10 @@ func (p *PluginApplicationService) fillAuthInfoInMetaInfo(ctx context.Context, d
636639
637640 if authType == common .AuthorizationType_Service {
638641 var loc common.AuthorizationServiceLocation
639- _loc := model .HTTPParamLocation (strings .ToLower (string (authInfo .AuthOfAPIToken .Location )))
640- if _loc == model .ParamInHeader {
642+ _loc := consts .HTTPParamLocation (strings .ToLower (string (authInfo .AuthOfAPIToken .Location )))
643+ if _loc == consts .ParamInHeader {
641644 loc = common .AuthorizationServiceLocation_Header
642- } else if _loc == model .ParamInQuery {
645+ } else if _loc == consts .ParamInQuery {
643646 loc = common .AuthorizationServiceLocation_Query
644647 } else {
645648 return fmt .Errorf ("invalid location '%s'" , authInfo .AuthOfAPIToken .Location )
@@ -784,16 +787,16 @@ func (p *PluginApplicationService) CreateAPI(ctx context.Context, req *pluginAPI
784787
785788 tool := & entity.ToolInfo {
786789 PluginID : req .PluginID ,
787- ActivatedStatus : ptr .Of (model .ActivateTool ),
790+ ActivatedStatus : ptr .Of (consts .ActivateTool ),
788791 DebugStatus : ptr .Of (common .APIDebugStatus_DebugWaiting ),
789792 SubURL : ptr .Of ("/" + defaultSubURL ),
790793 Method : ptr .Of (http .MethodGet ),
791794 Operation : model .NewOpenapi3Operation (& openapi3.Operation {
792795 Summary : req .Desc ,
793796 OperationID : req .Name ,
794797 Parameters : []* openapi3.ParameterRef {},
795- RequestBody : entity .DefaultOpenapi3RequestBody (),
796- Responses : entity .DefaultOpenapi3Responses (),
798+ RequestBody : pluginDTO .DefaultOpenapi3RequestBody (),
799+ Responses : pluginDTO .DefaultOpenapi3Responses (),
797800 Extensions : map [string ]any {},
798801 }),
799802 }
@@ -816,13 +819,13 @@ func (p *PluginApplicationService) UpdateAPI(ctx context.Context, req *pluginAPI
816819 return nil , errorx .Wrapf (err , "validateUpdateAPIRequest failed" )
817820 }
818821
819- op , err := pluginutil .APIParamsToOpenapiOperation (req .RequestParams , req .ResponseParams )
822+ op , err := builder .APIParamsToOpenapiOperation (req .RequestParams , req .ResponseParams )
820823 if err != nil {
821824 return nil , err
822825 }
823826
824827 var method * string
825- if m , ok := model .ToHTTPMethod (req .GetMethod ()); ok {
828+ if m , ok := convert .ToHTTPMethod (req .GetMethod ()); ok {
826829 method = & m
827830 }
828831
@@ -1042,27 +1045,27 @@ func getUpdateAuthInfo(ctx context.Context, req *pluginAPI.UpdatePluginMetaReque
10421045 return nil , nil
10431046 }
10441047
1045- _authType , ok := model .ToAuthType (req .GetAuthType ())
1048+ _authType , ok := convert .ToAuthType (req .GetAuthType ())
10461049 if ! ok {
10471050 return nil , fmt .Errorf ("invalid auth type '%d'" , req .GetAuthType ())
10481051 }
10491052 authType := & _authType
10501053
1051- var authSubType * model .AuthzSubType
1054+ var authSubType * consts .AuthzSubType
10521055 if req .SubAuthType != nil {
1053- _authSubType , ok := model .ToAuthSubType (req .GetSubAuthType ())
1056+ _authSubType , ok := convert .ToAuthSubType (req .GetSubAuthType ())
10541057 if ! ok {
10551058 return nil , fmt .Errorf ("invalid sub authz type '%d'" , req .GetSubAuthType ())
10561059 }
10571060 authSubType = & _authSubType
10581061 }
10591062
1060- var location * model .HTTPParamLocation
1063+ var location * consts .HTTPParamLocation
10611064 if req .Location != nil {
10621065 if * req .Location == common .AuthorizationServiceLocation_Header {
1063- location = ptr .Of (model .ParamInHeader )
1066+ location = ptr .Of (consts .ParamInHeader )
10641067 } else if * req .Location == common .AuthorizationServiceLocation_Query {
1065- location = ptr .Of (model .ParamInQuery )
1068+ location = ptr .Of (consts .ParamInQuery )
10661069 } else {
10671070 return nil , fmt .Errorf ("invalid location '%d'" , req .GetLocation ())
10681071 }
@@ -1113,7 +1116,7 @@ func (p *PluginApplicationService) GetBotDefaultParams(ctx context.Context, req
11131116}
11141117
11151118func (p * PluginApplicationService ) UpdateBotDefaultParams (ctx context.Context , req * pluginAPI.UpdateBotDefaultParamsRequest ) (resp * pluginAPI.UpdateBotDefaultParamsResponse , err error ) {
1116- op , err := pluginutil .APIParamsToOpenapiOperation (req .RequestParams , req .ResponseParams )
1119+ op , err := builder .APIParamsToOpenapiOperation (req .RequestParams , req .ResponseParams )
11171120 if err != nil {
11181121 return nil , err
11191122 }
@@ -1158,18 +1161,18 @@ func (p *PluginApplicationService) DebugAPI(ctx context.Context, req *pluginAPI.
11581161 opts := []model.ExecuteToolOpt {}
11591162 switch req .Operation {
11601163 case common .DebugOperation_Debug :
1161- opts = append (opts , model .WithInvalidRespProcessStrategy (model .InvalidResponseProcessStrategyOfReturnErr ))
1164+ opts = append (opts , model .WithInvalidRespProcessStrategy (consts .InvalidResponseProcessStrategyOfReturnErr ))
11621165 case common .DebugOperation_Parse :
11631166 opts = append (opts , model .WithAutoGenRespSchema (),
1164- model .WithInvalidRespProcessStrategy (model .InvalidResponseProcessStrategyOfReturnRaw ),
1167+ model .WithInvalidRespProcessStrategy (consts .InvalidResponseProcessStrategyOfReturnRaw ),
11651168 )
11661169 }
11671170
11681171 res , err := p .DomainSVC .ExecuteTool (ctx , & model.ExecuteToolRequest {
11691172 UserID : conv .Int64ToStr (* userID ),
11701173 PluginID : req .PluginID ,
11711174 ToolID : req .APIID ,
1172- ExecScene : model .ExecSceneOfToolDebug ,
1175+ ExecScene : consts .ExecSceneOfToolDebug ,
11731176 ExecDraftTool : true ,
11741177 ArgumentsInJson : req .Parameters ,
11751178 }, opts ... )
@@ -1346,7 +1349,7 @@ func (p *PluginApplicationService) buildPluginProductExtraInfo(ctx context.Conte
13461349
13471350 authMode := ptr .Of (productAPI .PluginAuthMode_NoAuth )
13481351 if authInfo != nil {
1349- if authInfo .Type == model .AuthzTypeOfService || authInfo .Type == model .AuthzTypeOfOAuth {
1352+ if authInfo .Type == consts .AuthzTypeOfService || authInfo .Type == consts .AuthzTypeOfOAuth {
13501353 authMode = ptr .Of (productAPI .PluginAuthMode_Required )
13511354 err := plugin .Manifest .Validate (false )
13521355 if err != nil {
@@ -1407,16 +1410,16 @@ func (p *PluginApplicationService) GetPluginNextVersion(ctx context.Context, req
14071410}
14081411
14091412func (p * PluginApplicationService ) GetDevPluginList (ctx context.Context , req * pluginAPI.GetDevPluginListRequest ) (resp * pluginAPI.GetDevPluginListResponse , err error ) {
1410- pageInfo := entity .PageInfo {
1413+ pageInfo := dto .PageInfo {
14111414 Name : req .Name ,
14121415 Page : int (req .GetPage ()),
14131416 Size : int (req .GetSize ()),
14141417 OrderByACS : ptr .Of (false ),
14151418 }
14161419 if req .GetOrderBy () == common .OrderBy_UpdateTime {
1417- pageInfo .SortBy = ptr .Of (entity .SortByUpdatedAt )
1420+ pageInfo .SortBy = ptr .Of (dto .SortByUpdatedAt )
14181421 } else {
1419- pageInfo .SortBy = ptr .Of (entity .SortByCreatedAt )
1422+ pageInfo .SortBy = ptr .Of (dto .SortByCreatedAt )
14201423 }
14211424
14221425 res , err := p .DomainSVC .ListDraftPlugins (ctx , & dto.ListDraftPluginsRequest {
@@ -1530,7 +1533,7 @@ func (p *PluginApplicationService) BatchCreateAPI(ctx context.Context, req *plug
15301533 }
15311534
15321535 duplicated := slices .Transform (res .DuplicatedTools , func (e entity.UniqueToolAPI ) * common.PluginAPIInfo {
1533- method , _ := model .ToThriftAPIMethod (e .Method )
1536+ method , _ := convert .ToThriftAPIMethod (e .Method )
15341537 return & common.PluginAPIInfo {
15351538 Path : e .SubURL ,
15361539 Method : method ,
@@ -1554,7 +1557,7 @@ func (p *PluginApplicationService) RevokeAuthToken(ctx context.Context, req *plu
15541557 return nil , errorx .New (errno .ErrPluginPermissionCode , errorx .KV (errno .PluginMsgKey , "session is required" ))
15551558 }
15561559
1557- err = p .DomainSVC .RevokeAccessToken (ctx , & entity .AuthorizationCodeMeta {
1560+ err = p .DomainSVC .RevokeAccessToken (ctx , & dto .AuthorizationCodeMeta {
15581561 UserID : conv .Int64ToStr (* userID ),
15591562 PluginID : req .PluginID ,
15601563 IsDraft : req .GetBotID () == 0 ,
@@ -1674,7 +1677,7 @@ func (p *PluginApplicationService) OauthAuthorizationCode(ctx context.Context, r
16741677 return nil , errorx .WrapByCode (err , errno .ErrPluginOAuthFailed , errorx .KV (errno .PluginMsgKey , "invalid state" ))
16751678 }
16761679
1677- state := & entity .OAuthState {}
1680+ state := & dto .OAuthState {}
16781681 err = json .Unmarshal (stateBytes , state )
16791682 if err != nil {
16801683 return nil , errorx .WrapByCode (err , errno .ErrPluginOAuthFailed , errorx .KV (errno .PluginMsgKey , "invalid state" ))
0 commit comments