@@ -18,7 +18,6 @@ import (
1818 "context"
1919 "errors"
2020 "fmt"
21- "net/http"
2221 "os"
2322 "path/filepath"
2423 "regexp"
@@ -30,14 +29,12 @@ import (
3029 "github.com/twitchtv/twirp"
3130 "github.com/urfave/cli/v3"
3231
33- livekitcli "github.com/livekit/livekit-cli/v2"
3432 "github.com/livekit/livekit-cli/v2/pkg/agentfs"
3533 "github.com/livekit/livekit-cli/v2/pkg/bootstrap"
3634 "github.com/livekit/livekit-cli/v2/pkg/config"
3735 "github.com/livekit/livekit-cli/v2/pkg/util"
3836 lkproto "github.com/livekit/protocol/livekit"
3937 "github.com/livekit/protocol/logger"
40- lksdk "github.com/livekit/server-sdk-go/v2"
4138)
4239
4340var (
@@ -320,7 +317,7 @@ var (
320317 },
321318 }
322319 subdomainPattern = regexp .MustCompile (`^(?:https?|wss?)://([^.]+)\.` )
323- agentsClient * lksdk. AgentClient
320+ agentsClient * agentfs. Client
324321 ignoredSecrets = []string {
325322 "LIVEKIT_API_KEY" ,
326323 "LIVEKIT_API_SECRET" ,
@@ -356,12 +353,7 @@ func createAgentClient(ctx context.Context, cmd *cli.Command) (context.Context,
356353 }
357354 }
358355
359- agentsClient , err = lksdk .NewAgentClient (project .URL , project .APIKey , project .APISecret , twirp .WithClientHooks (& twirp.ClientHooks {
360- RequestPrepared : func (ctx context.Context , req * http.Request ) (context.Context , error ) {
361- req .Header .Set ("X-LIVEKIT-CLI-VERSION" , livekitcli .Version )
362- return ctx , nil
363- },
364- }))
356+ agentsClient , err = agentfs .New (agentfs .WithProject (project .URL , project .APIKey , project .APISecret ))
365357 if err != nil {
366358 return ctx , err
367359 }
@@ -477,7 +469,7 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
477469 }
478470 var err error
479471 // Recreate the client with the new project
480- agentsClient , err = lksdk . NewAgentClient ( project .URL , project .APIKey , project .APISecret )
472+ agentsClient , err = agentfs . New ( agentfs . WithProject ( project .URL , project .APIKey , project .APISecret ) )
481473 if err != nil {
482474 return err
483475 }
@@ -538,13 +530,8 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
538530 }
539531
540532 regions := cmd .StringSlice ("regions" )
541-
542- req := & lkproto.CreateAgentRequest {
543- Secrets : secrets ,
544- Regions : regions ,
545- }
546-
547- resp , err := agentsClient .CreateAgent (ctx , req )
533+ excludeFiles := []string {fmt .Sprintf ("**/%s" , config .LiveKitTOMLFile )}
534+ resp , err := agentsClient .CreateAgent (ctx , workingDir , secrets , regions , excludeFiles )
548535 if err != nil {
549536 if twerr , ok := err .(twirp.Error ); ok {
550537 return fmt .Errorf ("unable to create agent: %s" , twerr .Msg ())
@@ -557,16 +544,7 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
557544 return err
558545 }
559546
560- err = agentfs .UploadTarball (workingDir , resp .PresignedUrl , []string {fmt .Sprintf ("**/%s" , config .LiveKitTOMLFile )}, projectType )
561- if err != nil {
562- return err
563- }
564-
565547 fmt .Printf ("Created agent with ID [%s]\n " , util .Accented (resp .AgentId ))
566- err = agentfs .Build (ctx , resp .AgentId , project )
567- if err != nil {
568- return err
569- }
570548
571549 fmt .Println ("Build completed - You can view build logs later with `lk agent logs --log-type=build`" )
572550
@@ -584,7 +562,7 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
584562 return err
585563 } else if viewLogs {
586564 fmt .Println ("Tailing runtime logs...safe to exit at any time" )
587- return agentfs . LogHelper (ctx , lkConfig .Agent .ID , "deploy" , project )
565+ return agentsClient . StreamLogs (ctx , "deploy" , lkConfig .Agent .ID , os . Stdout )
588566 }
589567 }
590568 return nil
@@ -697,30 +675,14 @@ func deployAgent(ctx context.Context, cmd *cli.Command) error {
697675 }
698676 }
699677
700- resp , err := agentsClient . DeployAgent ( ctx , req )
701- if err != nil {
678+ excludeFiles := [] string { fmt . Sprintf ( "**/%s" , config . LiveKitTOMLFile )}
679+ if err := agentsClient . DeployAgent ( ctx , agentId , workingDir , secrets , excludeFiles ); err != nil {
702680 if twerr , ok := err .(twirp.Error ); ok {
703681 return fmt .Errorf ("unable to deploy agent: %s" , twerr .Msg ())
704682 }
705683 return fmt .Errorf ("unable to deploy agent: %w" , err )
706684 }
707685
708- if ! resp .Success {
709- return fmt .Errorf ("failed to deploy agent: %s" , resp .Message )
710- }
711-
712- presignedUrl := resp .PresignedUrl
713- err = agentfs .UploadTarball (workingDir , presignedUrl , []string {fmt .Sprintf ("**/%s" , config .LiveKitTOMLFile )}, projectType )
714- if err != nil {
715- return err
716- }
717-
718- fmt .Printf ("Updated agent [%s]\n " , util .Accented (resp .AgentId ))
719- err = agentfs .Build (ctx , resp .AgentId , project )
720- if err != nil {
721- return err
722- }
723-
724686 fmt .Println ("Deployed agent" )
725687 return nil
726688}
@@ -887,8 +849,7 @@ func getLogs(ctx context.Context, cmd *cli.Command) error {
887849 if err != nil {
888850 return err
889851 }
890- err = agentfs .LogHelper (ctx , agentID , cmd .String ("log-type" ), project )
891- return err
852+ return agentsClient .StreamLogs (ctx , cmd .String ("log-type" ), agentID , os .Stdout )
892853}
893854
894855func deleteAgent (ctx context.Context , cmd * cli.Command ) error {
0 commit comments