11import { BitbucketIcon } from '@/components/icons'
22import type { BlockConfig , BlockMeta } from '@/blocks/types'
33import { AuthMode , IntegrationType } from '@/blocks/types'
4+ import { mapperOperation , toolCallArg } from '@/blocks/utils'
45import { getTrigger } from '@/triggers'
56
67const WORKSPACE_FIELD = [ 'workspacePicker' , 'workspaceSlugInput' ] as const
@@ -925,10 +926,20 @@ export const BitbucketBlock: BlockConfig = {
925926 }
926927 return params . operation
927928 } ,
928- params : ( params ) => {
929- if ( ! isBitbucketOperation ( params . operation ) ) {
930- throw new Error ( `Invalid Bitbucket operation: ${ String ( params . operation ) } ` )
929+ params : ( params , context ) => {
930+ const operation = mapperOperation ( params , context )
931+ if ( ! isBitbucketOperation ( operation ) ) {
932+ throw new Error ( `Invalid Bitbucket operation: ${ operation } ` )
931933 }
934+ /** A tool call's model args arrive under the tool's param names, not the block field ids. */
935+ const modelArg = ( key : string ) => toolCallArg ( context , params [ key ] )
936+ const q = ( ) => optionalString ( params . query , 'query' ) ?? optionalString ( modelArg ( 'q' ) , 'q' )
937+ const commit = ( ) =>
938+ optionalString ( params . revision , 'revision' ) ??
939+ optionalString ( modelArg ( 'commit' ) , 'commit' )
940+ const branchName = ( ) =>
941+ optionalString ( params . branchName , 'branchName' ) ??
942+ optionalString ( modelArg ( 'name' ) , 'name' )
932943
933944 const common = {
934945 oauthCredential : params . oauthCredential ,
@@ -940,7 +951,7 @@ export const BitbucketBlock: BlockConfig = {
940951 nextUrl : optionalString ( params . nextUrl , 'nextUrl' ) ,
941952 }
942953
943- switch ( params . operation ) {
954+ switch ( operation ) {
944955 case 'bitbucket_list_workspaces' :
945956 return {
946957 oauthCredential : params . oauthCredential ,
@@ -953,30 +964,41 @@ export const BitbucketBlock: BlockConfig = {
953964 oauthCredential : params . oauthCredential ,
954965 workspaceSlug : optionalString ( params . workspaceSlug , 'workspaceSlug' ) ,
955966 role : optionalString ( params . role , 'role' ) ,
956- q : optionalString ( params . query , 'query' ) ,
967+ q : q ( ) ,
957968 sort : optionalString ( params . sort , 'sort' ) ,
958969 ...pagination ,
959970 }
960971 case 'bitbucket_list_branches' :
961972 return {
962973 ...common ,
963- q : optionalString ( params . query , 'query' ) ,
974+ q : q ( ) ,
964975 sort : optionalString ( params . sort , 'sort' ) ,
965976 ...pagination ,
966977 }
967978 case 'bitbucket_list_pipelines' :
968979 return {
969980 ...common ,
970- refType : optionalString ( params . pipelineRefType , 'pipelineRefType' ) ,
971- refName : optionalString ( params . pipelineRefName , 'pipelineRefName' ) ,
972- commitHash : optionalString ( params . pipelineCommitHash , 'pipelineCommitHash' ) ,
973- selectorType : optionalString ( params . pipelineSelectorType , 'pipelineSelectorType' ) ,
974- selectorPattern : optionalString (
975- params . pipelineSelectorPattern ,
976- 'pipelineSelectorPattern'
977- ) ,
978- triggerType : optionalString ( params . pipelineTriggerType , 'pipelineTriggerType' ) ,
979- status : optionalString ( params . pipelineStatus , 'pipelineStatus' ) ,
981+ refType :
982+ optionalString ( params . pipelineRefType , 'pipelineRefType' ) ??
983+ optionalString ( modelArg ( 'refType' ) , 'refType' ) ,
984+ refName :
985+ optionalString ( params . pipelineRefName , 'pipelineRefName' ) ??
986+ optionalString ( modelArg ( 'refName' ) , 'refName' ) ,
987+ commitHash :
988+ optionalString ( params . pipelineCommitHash , 'pipelineCommitHash' ) ??
989+ optionalString ( modelArg ( 'commitHash' ) , 'commitHash' ) ,
990+ selectorType :
991+ optionalString ( params . pipelineSelectorType , 'pipelineSelectorType' ) ??
992+ optionalString ( modelArg ( 'selectorType' ) , 'selectorType' ) ,
993+ selectorPattern :
994+ optionalString ( params . pipelineSelectorPattern , 'pipelineSelectorPattern' ) ??
995+ optionalString ( modelArg ( 'selectorPattern' ) , 'selectorPattern' ) ,
996+ triggerType :
997+ optionalString ( params . pipelineTriggerType , 'pipelineTriggerType' ) ??
998+ optionalString ( modelArg ( 'triggerType' ) , 'triggerType' ) ,
999+ status :
1000+ optionalString ( params . pipelineStatus , 'pipelineStatus' ) ??
1001+ optionalString ( modelArg ( 'status' ) , 'status' ) ,
9801002 sort : optionalString ( params . sort , 'sort' ) ,
9811003 ...pagination ,
9821004 }
@@ -985,48 +1007,54 @@ export const BitbucketBlock: BlockConfig = {
9851007 case 'bitbucket_create_branch' :
9861008 return {
9871009 ...common ,
988- name : optionalString ( params . branchName , 'branchName' ) ,
1010+ name : branchName ( ) ,
9891011 target : optionalString ( params . target , 'target' ) ,
9901012 }
9911013 case 'bitbucket_delete_branch' :
992- return { ...common , name : optionalString ( params . branchName , 'branchName' ) }
1014+ return { ...common , name : branchName ( ) }
9931015 case 'bitbucket_list_commits' :
9941016 return {
9951017 ...common ,
996- include : stringList ( params . commitInclude , 'commitInclude' ) ,
997- exclude : stringList ( params . commitExclude , 'commitExclude' ) ,
998- path : optionalString ( params . commitPath , 'commitPath' ) ,
1018+ include :
1019+ stringList ( params . commitInclude , 'commitInclude' ) ??
1020+ stringList ( modelArg ( 'include' ) , 'include' ) ,
1021+ exclude :
1022+ stringList ( params . commitExclude , 'commitExclude' ) ??
1023+ stringList ( modelArg ( 'exclude' ) , 'exclude' ) ,
1024+ path :
1025+ optionalString ( params . commitPath , 'commitPath' ) ??
1026+ optionalString ( modelArg ( 'path' ) , 'path' ) ,
9991027 ...pagination ,
10001028 }
10011029 case 'bitbucket_get_commit' :
1002- return { ...common , commit : optionalString ( params . revision , 'revision' ) }
1030+ return { ...common , commit : commit ( ) }
10031031 case 'bitbucket_list_directory' :
10041032 return {
10051033 ...common ,
1006- commit : optionalString ( params . revision , 'revision' ) ,
1034+ commit : commit ( ) ,
10071035 path : optionalText ( params . path , 'path' ) ,
1008- q : optionalString ( params . query , 'query' ) ,
1036+ q : q ( ) ,
10091037 sort : optionalString ( params . sort , 'sort' ) ,
10101038 ...pagination ,
10111039 }
10121040 case 'bitbucket_get_file_metadata' :
10131041 return {
10141042 ...common ,
1015- commit : optionalString ( params . revision , 'revision' ) ,
1043+ commit : commit ( ) ,
10161044 path : optionalText ( params . path , 'path' ) ,
10171045 }
10181046 case 'bitbucket_get_file' :
10191047 return {
10201048 ...common ,
1021- commit : optionalString ( params . revision , 'revision' ) ,
1049+ commit : commit ( ) ,
10221050 path : optionalText ( params . path , 'path' ) ,
10231051 maxCharacters : optionalInteger ( params . maxCharacters , 'maxCharacters' ) ,
10241052 }
10251053 case 'bitbucket_list_pull_requests' :
10261054 return {
10271055 ...common ,
10281056 state : optionalString ( params . state , 'state' ) ,
1029- q : optionalString ( params . query , 'query' ) ,
1057+ q : q ( ) ,
10301058 sort : optionalString ( params . sort , 'sort' ) ,
10311059 ...pagination ,
10321060 }
@@ -1042,11 +1070,12 @@ export const BitbucketBlock: BlockConfig = {
10421070 sourceBranch : optionalString ( params . sourceBranch , 'sourceBranch' ) ,
10431071 destinationBranch : optionalString ( params . destinationBranch , 'destinationBranch' ) ,
10441072 description : optionalText ( params . description , 'description' ) ,
1045- reviewerUuids : stringList ( params . reviewerAccountIds , 'reviewerAccountIds' ) ,
1046- closeSourceBranch : optionalBoolean (
1047- params . createCloseSourceBranch ,
1048- 'createCloseSourceBranch'
1049- ) ,
1073+ reviewerUuids :
1074+ stringList ( params . reviewerAccountIds , 'reviewerAccountIds' ) ??
1075+ stringList ( modelArg ( 'reviewerUuids' ) , 'reviewerUuids' ) ,
1076+ closeSourceBranch :
1077+ optionalBoolean ( params . createCloseSourceBranch , 'createCloseSourceBranch' ) ??
1078+ optionalBoolean ( modelArg ( 'closeSourceBranch' ) , 'closeSourceBranch' ) ,
10501079 draft : optionalBoolean ( params . draft , 'draft' ) ,
10511080 }
10521081 case 'bitbucket_merge_pull_request' :
@@ -1055,10 +1084,9 @@ export const BitbucketBlock: BlockConfig = {
10551084 prId : optionalInteger ( params . prId , 'prId' ) ,
10561085 mergeStrategy : optionalString ( params . mergeStrategy , 'mergeStrategy' ) ,
10571086 message : optionalText ( params . message , 'message' ) ,
1058- closeSourceBranch : optionalBoolean (
1059- params . mergeCloseSourceBranch ,
1060- 'mergeCloseSourceBranch'
1061- ) ,
1087+ closeSourceBranch :
1088+ optionalBoolean ( params . mergeCloseSourceBranch , 'mergeCloseSourceBranch' ) ??
1089+ optionalBoolean ( modelArg ( 'closeSourceBranch' ) , 'closeSourceBranch' ) ,
10621090 }
10631091 case 'bitbucket_get_pull_request_merge_task_status' :
10641092 return {
@@ -1080,7 +1108,7 @@ export const BitbucketBlock: BlockConfig = {
10801108 return {
10811109 ...common ,
10821110 prId : optionalInteger ( params . prId , 'prId' ) ,
1083- q : optionalString ( params . query , 'query' ) ,
1111+ q : q ( ) ,
10841112 sort : optionalString ( params . sort , 'sort' ) ,
10851113 ...pagination ,
10861114 }
@@ -1097,9 +1125,16 @@ export const BitbucketBlock: BlockConfig = {
10971125 case 'bitbucket_trigger_pipeline' :
10981126 return {
10991127 ...common ,
1100- refType : optionalString ( params . targetRefType , 'targetRefType' ) ?? 'branch' ,
1101- refName : optionalString ( params . targetRef , 'targetRef' ) ,
1102- commitHash : optionalString ( params . targetCommitHash , 'targetCommitHash' ) ,
1128+ refType :
1129+ optionalString ( params . targetRefType , 'targetRefType' ) ??
1130+ optionalString ( modelArg ( 'refType' ) , 'refType' ) ??
1131+ 'branch' ,
1132+ refName :
1133+ optionalString ( params . targetRef , 'targetRef' ) ??
1134+ optionalString ( modelArg ( 'refName' ) , 'refName' ) ,
1135+ commitHash :
1136+ optionalString ( params . targetCommitHash , 'targetCommitHash' ) ??
1137+ optionalString ( modelArg ( 'commitHash' ) , 'commitHash' ) ,
11031138 }
11041139 case 'bitbucket_list_pipeline_steps' :
11051140 return {
0 commit comments