@@ -441,10 +441,10 @@ var agentsAuthCreateCmd = &cobra.Command{
441441}
442442
443443var agentsAuthInvokeCmd = & cobra.Command {
444- Use : "invoke < auth-agent-id> " ,
444+ Use : "invoke [ auth-agent-id] " ,
445445 Short : "Start an auth invocation" ,
446446 Long : "Start an authentication invocation using the hosted UI flow" ,
447- Args : cobra .ExactArgs (1 ),
447+ Args : cobra .MaximumNArgs (1 ),
448448 RunE : runAgentsAuthInvoke ,
449449}
450450
@@ -516,6 +516,7 @@ func init() {
516516 // invoke flags
517517 agentsAuthInvokeCmd .Flags ().String ("save-credential-as" , "" , "Save credentials under this name after successful login" )
518518 agentsAuthInvokeCmd .Flags ().Bool ("no-browser" , false , "Don't automatically open browser" )
519+ agentsAuthInvokeCmd .Flags ().BoolP ("interactive" , "i" , false , "Interactive mode - select auth agent from list" )
519520
520521 // list flags
521522 agentsAuthListCmd .Flags ().String ("domain" , "" , "Filter by domain" )
@@ -656,16 +657,59 @@ func runAgentsAuthCreate(cmd *cobra.Command, args []string) error {
656657
657658func runAgentsAuthInvoke (cmd * cobra.Command , args []string ) error {
658659 client := getKernelClient (cmd )
660+ ctx := cmd .Context ()
659661
660662 saveCredentialAs , _ := cmd .Flags ().GetString ("save-credential-as" )
661663 noBrowser , _ := cmd .Flags ().GetBool ("no-browser" )
664+ interactive , _ := cmd .Flags ().GetBool ("interactive" )
665+
666+ var authAgentID string
667+ if len (args ) > 0 {
668+ authAgentID = args [0 ]
669+ }
670+
671+ if interactive || authAgentID == "" {
672+ // Fetch auth agents and let user select
673+ page , err := client .Agents .Auth .List (ctx , kernel.AgentAuthListParams {})
674+ if err != nil {
675+ return util.CleanedUpSdkError {Err : err }
676+ }
677+
678+ if len (page .Items ) == 0 {
679+ pterm .Error .Println ("No auth agents found. Create one first with: kernel agents auth create" )
680+ return nil
681+ }
682+
683+ options := []string {}
684+ agentMap := make (map [string ]string ) // display -> id
685+ for _ , agent := range page .Items {
686+ display := fmt .Sprintf ("%s - %s (%s)" , agent .ID [:8 ], agent .Domain , agent .ProfileName )
687+ options = append (options , display )
688+ agentMap [display ] = agent .ID
689+ }
690+
691+ selected , err := pterm .DefaultInteractiveSelect .
692+ WithDefaultText ("Select an auth agent to invoke" ).
693+ WithOptions (options ).
694+ WithFilter (true ).
695+ Show ()
696+ if err != nil {
697+ return fmt .Errorf ("failed to select auth agent: %w" , err )
698+ }
699+
700+ authAgentID = agentMap [selected ]
701+ }
702+
703+ if authAgentID == "" {
704+ return fmt .Errorf ("auth-agent-id is required (or use -i for interactive mode)" )
705+ }
662706
663707 svc := client .Agents .Auth
664708 invocationsSvc := client .Agents .Auth .Invocations
665709 a := AgentAuthCmd {auth : & svc , invocations : & invocationsSvc }
666710
667- return a .Invoke (cmd . Context () , InvokeInput {
668- AuthAgentID : args [ 0 ] ,
711+ return a .Invoke (ctx , InvokeInput {
712+ AuthAgentID : authAgentID ,
669713 SaveCredentialAs : saveCredentialAs ,
670714 NoBrowser : noBrowser ,
671715 })
0 commit comments