@@ -234,7 +234,14 @@ func (f *runExecFlags) runOrExec(ctx context.Context, out *cli.Printer, args []s
234234 return err
235235 }
236236
237- loadResult , err := f .loadAgentFrom (ctx , agentSource )
237+ opts := []teamloader.Opt {
238+ teamloader .WithModelOverrides (f .modelOverrides ),
239+ }
240+ if len (f .promptFiles ) > 0 {
241+ opts = append (opts , teamloader .WithPromptFiles (f .promptFiles ))
242+ }
243+
244+ loadResult , err := teamloader .LoadWithConfig (ctx , agentSource , & f .runConfig , opts ... )
238245 if err != nil {
239246 return err
240247 }
@@ -275,58 +282,16 @@ func (f *runExecFlags) runOrExec(ctx context.Context, out *cli.Printer, args []s
275282 return f .handleRunMode (ctx , rt , sess , args )
276283}
277284
278- func (f * runExecFlags ) loadAgentFrom (ctx context.Context , agentSource config.Source ) (* teamloader.LoadResult , error ) {
279- opts := []teamloader.Opt {
280- teamloader .WithModelOverrides (f .modelOverrides ),
281- }
282- if len (f .promptFiles ) > 0 {
283- opts = append (opts , teamloader .WithPromptFiles (f .promptFiles ))
284- }
285-
286- result , err := teamloader .LoadWithConfig (ctx , agentSource , & f .runConfig , opts ... )
287- if err != nil {
288- return nil , err
289- }
290-
291- return result , nil
292- }
293-
294285func (f * runExecFlags ) createRemoteRuntimeAndSession (ctx context.Context , originalFilename string ) (runtime.Runtime , * session.Session , error ) {
295- if f .connectRPC {
296- return f .createConnectRPCRuntimeAndSession (ctx , originalFilename )
297- }
298- return f .createHTTPRuntimeAndSession (ctx , originalFilename )
299- }
300-
301- func (f * runExecFlags ) createConnectRPCRuntimeAndSession (ctx context.Context , originalFilename string ) (runtime.Runtime , * session.Session , error ) {
302- connectClient , err := runtime .NewConnectRPCClient (f .remoteAddress )
303- if err != nil {
304- return nil , nil , fmt .Errorf ("failed to create connect-rpc client: %w" , err )
305- }
306-
307- sessTemplate := session .New (
308- session .WithToolsApproved (f .autoApprove ),
309- )
310-
311- sess , err := connectClient .CreateSession (ctx , sessTemplate )
312- if err != nil {
313- return nil , nil , err
314- }
315-
316- remoteRt , err := runtime .NewRemoteRuntime (connectClient ,
317- runtime .WithRemoteCurrentAgent (f .agentName ),
318- runtime .WithRemoteAgentFilename (originalFilename ),
286+ var (
287+ client runtime.RemoteClient
288+ err error
319289 )
320- if err != nil {
321- return nil , nil , fmt .Errorf ("failed to create connect-rpc remote runtime: %w" , err )
290+ if f .connectRPC {
291+ client , err = runtime .NewConnectRPCClient (f .remoteAddress )
292+ } else {
293+ client , err = runtime .NewClient (f .remoteAddress )
322294 }
323-
324- slog .Debug ("Using connect-rpc remote runtime" , "address" , f .remoteAddress , "agent" , f .agentName )
325- return remoteRt , sess , nil
326- }
327-
328- func (f * runExecFlags ) createHTTPRuntimeAndSession (ctx context.Context , originalFilename string ) (runtime.Runtime , * session.Session , error ) {
329- remoteClient , err := runtime .NewClient (f .remoteAddress )
330295 if err != nil {
331296 return nil , nil , fmt .Errorf ("failed to create remote client: %w" , err )
332297 }
@@ -335,20 +300,20 @@ func (f *runExecFlags) createHTTPRuntimeAndSession(ctx context.Context, original
335300 session .WithToolsApproved (f .autoApprove ),
336301 )
337302
338- sess , err := remoteClient .CreateSession (ctx , sessTemplate )
303+ sess , err := client .CreateSession (ctx , sessTemplate )
339304 if err != nil {
340305 return nil , nil , err
341306 }
342307
343- remoteRt , err := runtime .NewRemoteRuntime (remoteClient ,
308+ remoteRt , err := runtime .NewRemoteRuntime (client ,
344309 runtime .WithRemoteCurrentAgent (f .agentName ),
345310 runtime .WithRemoteAgentFilename (originalFilename ),
346311 )
347312 if err != nil {
348313 return nil , nil , fmt .Errorf ("failed to create remote runtime: %w" , err )
349314 }
350315
351- slog .Debug ("Using remote runtime" , "address" , f .remoteAddress , "agent" , f .agentName )
316+ slog .Debug ("Using remote runtime" , "address" , f .remoteAddress , "agent" , f .agentName , "connect_rpc" , f . connectRPC )
352317 return remoteRt , sess , nil
353318}
354319
0 commit comments