Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions cmd/lk/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
return err
} else if viewLogs {
fmt.Println("Tailing runtime logs...safe to exit at any time")
return agentsClient.StreamLogs(ctx, "deploy", lkConfig.Agent.ID, os.Stdout)
return agentsClient.StreamLogs(ctx, "deploy", lkConfig.Agent.ID, os.Stdout, resp.ServerRegions[0])
}
}
return nil
Expand Down Expand Up @@ -849,7 +849,19 @@ func getLogs(ctx context.Context, cmd *cli.Command) error {
if err != nil {
return err
}
return agentsClient.StreamLogs(ctx, cmd.String("log-type"), agentID, os.Stdout)

response, err := agentsClient.ListAgents(ctx, &lkproto.ListAgentsRequest{
AgentId: agentID,
})
if err != nil {
return err
}

if len(response.Agents) == 0 {
return fmt.Errorf("no agent deployments found")
}

return agentsClient.StreamLogs(ctx, cmd.String("log-type"), agentID, os.Stdout, response.Agents[0].AgentDeployments[0].ServerRegion)
}

func deleteAgent(ctx context.Context, cmd *cli.Command) error {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/go-logr/logr v1.4.3
github.com/go-task/task/v3 v3.44.1
github.com/joho/godotenv v1.5.1
github.com/livekit/protocol v1.42.1-0.20250929175250-2ddfb3ee7f7e
github.com/livekit/protocol v1.42.1-0.20251001181643-1c8cbd7cbbb5
github.com/livekit/server-sdk-go/v2 v2.11.3
github.com/moby/buildkit v0.23.2
github.com/moby/patternmatcher v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731 h1:9x+U2HGLrSw5AT
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
github.com/livekit/mediatransportutil v0.0.0-20250825135402-7bc31f107ade h1:lpxPcglwzUWNB4J0S2qZuyMehzmR7vW9whzSwV4IGoI=
github.com/livekit/mediatransportutil v0.0.0-20250825135402-7bc31f107ade/go.mod h1:mSNtYzSf6iY9xM3UX42VEI+STHvMgHmrYzEHPcdhB8A=
github.com/livekit/protocol v1.42.1-0.20250929175250-2ddfb3ee7f7e h1:yytr+uwFXtJ8UxBV2q3j55jVKg7zslECuGeE4F56NoU=
github.com/livekit/protocol v1.42.1-0.20250929175250-2ddfb3ee7f7e/go.mod h1:vhMS30QoEyH2p34vi6X1eWkC4EMV72ZGZwQb74ajY7A=
github.com/livekit/protocol v1.42.1-0.20251001181643-1c8cbd7cbbb5 h1:TAvDDQDVO0t63gv3d6xGntWRflVJLRdqPTMgMi8hzdY=
github.com/livekit/protocol v1.42.1-0.20251001181643-1c8cbd7cbbb5/go.mod h1:vhMS30QoEyH2p34vi6X1eWkC4EMV72ZGZwQb74ajY7A=
github.com/livekit/psrpc v0.7.0 h1:rtfqfjYN06WJYloE/S0nmkJ/Y04x4pxLQLe8kQ4FVHU=
github.com/livekit/psrpc v0.7.0/go.mod h1:AuDC5uOoEjQJEc69v4Li3t77Ocz0e0NdjQEuFfO+vfk=
github.com/livekit/server-sdk-go/v2 v2.11.3 h1:k+YDxo8wPCixRrS9fJHcbtlurlXhVLfyPva5Ne4tVH0=
Expand Down
12 changes: 8 additions & 4 deletions pkg/agentfs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import (
"regexp"
"strings"

"github.com/twitchtv/twirp"

livekitcli "github.com/livekit/livekit-cli/v2"
"github.com/livekit/protocol/auth"
lkproto "github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
lksdk "github.com/livekit/server-sdk-go/v2"
"github.com/twitchtv/twirp"
)

// Client is a wrapper around the lksdk.AgentClient that provides a simpler interface for creating and deploying agents.
Expand Down Expand Up @@ -63,7 +64,7 @@ func New(opts ...ClientOption) (*Client, error) {
return nil, err
}
client.AgentClient = agentClient
client.agentsURL = client.getAgentsURL()
client.agentsURL = client.getAgentsURL("")
if client.httpClient == nil {
client.httpClient = &http.Client{}
}
Expand Down Expand Up @@ -164,7 +165,7 @@ func (c *Client) uploadAndBuild(
return nil
}

func (c *Client) getAgentsURL() string {
func (c *Client) getAgentsURL(serverRegion string) string {
agentsURL := c.projectURL
if strings.HasPrefix(agentsURL, "ws") {
agentsURL = strings.Replace(agentsURL, "ws", "http", 1)
Expand All @@ -174,7 +175,10 @@ func (c *Client) getAgentsURL() string {
} else if !strings.Contains(agentsURL, "localhost") && !strings.Contains(agentsURL, "127.0.0.1") {
pattern := `^https://[a-zA-Z0-9\-]+\.`
re := regexp.MustCompile(pattern)
agentsURL = re.ReplaceAllString(agentsURL, "https://agents.")
if serverRegion != "" {
serverRegion = fmt.Sprintf("%s.", serverRegion)
}
agentsURL = re.ReplaceAllString(agentsURL, fmt.Sprintf("https://%sagents.", serverRegion))
}
return agentsURL
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/agentfs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ type APIError struct {
}

// StreamLogs streams the logs for the given agent.
func (c *Client) StreamLogs(ctx context.Context, logType, agentID string, writer io.Writer) error {
func (c *Client) StreamLogs(ctx context.Context, logType, agentID string, writer io.Writer, serverRegion string) error {
logger := c.logger.WithName("StreamLogs")
if logType == "" {
logType = "deploy"
}
params := url.Values{}
params.Add("agent_id", agentID)
params.Add("log_type", logType)
fullUrl := fmt.Sprintf("%s/logs?%s", c.agentsURL, params.Encode())
fullUrl := fmt.Sprintf("%s/logs?%s", c.getAgentsURL(serverRegion), params.Encode())
req, err := c.newRequest("GET", fullUrl, nil)
if err != nil {
return err
Expand Down
Loading