@@ -23,6 +23,7 @@ import (
2323 "github.com/docker/cagent/pkg/chat"
2424 "github.com/docker/cagent/pkg/content"
2525 "github.com/docker/cagent/pkg/evaluation"
26+ "github.com/docker/cagent/pkg/oauth"
2627 "github.com/docker/cagent/pkg/remote"
2728 "github.com/docker/cagent/pkg/runtime"
2829 "github.com/docker/cagent/pkg/session"
@@ -180,6 +181,31 @@ func doRunCommand(ctx context.Context, args []string, exec bool) error {
180181 agentFilename = tmpFile .Name ()
181182 }
182183
184+ // Set up OAuth redirect URI for CLI/TUI mode
185+ if runConfig .RedirectURI == "" {
186+ runConfig .RedirectURI = "http://localhost:8083/oauth-callback"
187+ slog .Debug ("Set default OAuth redirect URI for CLI/TUI mode" , "redirectURI" , runConfig .RedirectURI )
188+
189+ // Start OAuth callback server for CLI/TUI mode
190+ callbackServer := oauth .NewCallbackServer (8083 )
191+ err := callbackServer .Start (ctx )
192+ if err != nil {
193+ slog .Warn ("Failed to start OAuth callback server" , "error" , err )
194+ } else {
195+ defer func () {
196+ shutdownCtx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
197+ defer cancel ()
198+ if err := callbackServer .Stop (shutdownCtx ); err != nil {
199+ slog .Error ("Failed to stop OAuth callback server" , "error" , err )
200+ }
201+ }()
202+ slog .Debug ("Started OAuth callback server" , "port" , 8083 )
203+
204+ // Set up global callback server for OAuth manager
205+ oauth .SetGlobalCallbackServer (callbackServer )
206+ }
207+ }
208+
183209 agents , err = teamloader .Load (ctx , agentFilename , runConfig )
184210 if err != nil {
185211 return err
@@ -455,6 +481,22 @@ func runWithoutTUI(ctx context.Context, agentFilename string, rt runtime.Runtime
455481 rt .Resume (ctx , string (runtime .ResumeTypeReject ))
456482 return nil
457483 }
484+ case * runtime.AuthorizationRequiredEvent :
485+ if llmIsTyping {
486+ fmt .Println ()
487+ llmIsTyping = false
488+ }
489+
490+ if e .Confirmation == "pending" {
491+ result := promptOAuthAuthorization (e .ServerURL , e .ServerType )
492+ switch result {
493+ case ConfirmationApprove :
494+ rt .ResumeStartAuthorizationFlow (ctx , true )
495+ case ConfirmationReject :
496+ rt .ResumeStartAuthorizationFlow (ctx , false )
497+ return fmt .Errorf ("OAuth authorization rejected by user" )
498+ }
499+ }
458500 }
459501 }
460502
0 commit comments