@@ -419,9 +419,13 @@ func (r *Runner) start(callCtx engine.Context, state *State, monitor Monitor, en
419419 return nil , err
420420 }
421421
422- if len (callCtx .Tool .Credentials ) > 0 {
422+ credTools , err := callCtx .Tool .GetCredentialTools (* callCtx .Program , callCtx .AgentGroup )
423+ if err != nil {
424+ return nil , err
425+ }
426+ if len (credTools ) > 0 {
423427 var err error
424- env , err = r .handleCredentials (callCtx , monitor , env )
428+ env , err = r .handleCredentials (callCtx , monitor , env , credTools )
425429 if err != nil {
426430 return nil , err
427431 }
@@ -552,9 +556,13 @@ func (r *Runner) resume(callCtx engine.Context, monitor Monitor, env []string, s
552556 progress , progressClose := streamProgress (& callCtx , monitor )
553557 defer progressClose ()
554558
555- if len (callCtx .Tool .Credentials ) > 0 {
559+ credTools , err := callCtx .Tool .GetCredentialTools (* callCtx .Program , callCtx .AgentGroup )
560+ if err != nil {
561+ return nil , err
562+ }
563+ if len (credTools ) > 0 {
556564 var err error
557- env , err = r .handleCredentials (callCtx , monitor , env )
565+ env , err = r .handleCredentials (callCtx , monitor , env , credTools )
558566 if err != nil {
559567 return nil , err
560568 }
@@ -828,7 +836,7 @@ func getEventContent(content string, callCtx engine.Context) string {
828836 return content
829837}
830838
831- func (r * Runner ) handleCredentials (callCtx engine.Context , monitor Monitor , env []string ) ([]string , error ) {
839+ func (r * Runner ) handleCredentials (callCtx engine.Context , monitor Monitor , env []string , credToolRefs []types. ToolReference ) ([]string , error ) {
832840 // Since credential tools (usually) prompt the user, we want to only run one at a time.
833841 r .credMutex .Lock ()
834842 defer r .credMutex .Unlock ()
@@ -845,10 +853,10 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
845853 }
846854 }
847855
848- for _ , credToolName := range callCtx . Tool . Credentials {
849- toolName , credentialAlias , args , err := types .ParseCredentialArgs (credToolName , callCtx .Input )
856+ for _ , ref := range credToolRefs {
857+ toolName , credentialAlias , args , err := types .ParseCredentialArgs (ref . Reference , callCtx .Input )
850858 if err != nil {
851- return nil , fmt .Errorf ("failed to parse credential tool %q: %w" , credToolName , err )
859+ return nil , fmt .Errorf ("failed to parse credential tool %q: %w" , ref . Reference , err )
852860 }
853861
854862 credName := toolName
@@ -895,11 +903,6 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
895903 // If the credential doesn't already exist in the store, run the credential tool in order to get the value,
896904 // and save it in the store.
897905 if ! exists || c .IsExpired () {
898- credToolRefs , ok := callCtx .Tool .ToolMapping [credToolName ]
899- if ! ok || len (credToolRefs ) != 1 {
900- return nil , fmt .Errorf ("failed to find ID for tool %s" , credToolName )
901- }
902-
903906 // If the existing credential is expired, we need to provide it to the cred tool through the environment.
904907 if exists && c .IsExpired () {
905908 credJSON , err := json .Marshal (c )
@@ -914,22 +917,22 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
914917 if args != nil {
915918 inputBytes , err := json .Marshal (args )
916919 if err != nil {
917- return nil , fmt .Errorf ("failed to marshal args for tool %s: %w" , credToolName , err )
920+ return nil , fmt .Errorf ("failed to marshal args for tool %s: %w" , ref . Reference , err )
918921 }
919922 input = string (inputBytes )
920923 }
921924
922- res , err := r .subCall (callCtx .Ctx , callCtx , monitor , env , credToolRefs [ 0 ] .ToolID , input , "" , engine .CredentialToolCategory )
925+ res , err := r .subCall (callCtx .Ctx , callCtx , monitor , env , ref .ToolID , input , "" , engine .CredentialToolCategory )
923926 if err != nil {
924- return nil , fmt .Errorf ("failed to run credential tool %s: %w" , credToolName , err )
927+ return nil , fmt .Errorf ("failed to run credential tool %s: %w" , ref . Reference , err )
925928 }
926929
927930 if res .Result == nil {
928- return nil , fmt .Errorf ("invalid state: credential tool [%s] can not result in a continuation" , credToolName )
931+ return nil , fmt .Errorf ("invalid state: credential tool [%s] can not result in a continuation" , ref . Reference )
929932 }
930933
931934 if err := json .Unmarshal ([]byte (* res .Result ), & c ); err != nil {
932- return nil , fmt .Errorf ("failed to unmarshal credential tool %s response: %w" , credToolName , err )
935+ return nil , fmt .Errorf ("failed to unmarshal credential tool %s response: %w" , ref . Reference , err )
933936 }
934937 c .ToolName = credName
935938 c .Type = credentials .CredentialTypeTool
@@ -943,7 +946,7 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
943946 }
944947
945948 // Only store the credential if the tool is on GitHub or has an alias, and the credential is non-empty.
946- if (isGitHubTool (toolName ) && callCtx .Program .ToolSet [credToolRefs [ 0 ] .ToolID ].Source .Repo != nil ) || credentialAlias != "" {
949+ if (isGitHubTool (toolName ) && callCtx .Program .ToolSet [ref .ToolID ].Source .Repo != nil ) || credentialAlias != "" {
947950 if isEmpty {
948951 log .Warnf ("Not saving empty credential for tool %s" , toolName )
949952 } else if err := r .credStore .Add (callCtx .Ctx , * c ); err != nil {
0 commit comments