From 39afb1528ca6cfa0b74417099de0b8b84377c115 Mon Sep 17 00:00:00 2001 From: Jon Scalet Date: Fri, 27 Mar 2026 15:19:25 -0700 Subject: [PATCH] fix: bypass subdomain validation when agents_url is configured Self-hosted deployments with custom domains (e.g. livekit.example.com) cannot use lk agent commands because the subdomain extracted from the project URL never matches the livekit.toml subdomain field. Add agents_url to LiveKitTOMLAgentConfig and skip subdomain validation when it is explicitly set, applying it as LK_AGENTS_URL instead. --- cmd/lk/agent.go | 20 ++++++++++++++------ pkg/config/livekit.go | 3 ++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/lk/agent.go b/cmd/lk/agent.go index e6745d0a..056d7636 100644 --- a/cmd/lk/agent.go +++ b/cmd/lk/agent.go @@ -382,12 +382,20 @@ func createAgentClientWithOpts(ctx context.Context, cmd *cli.Command, opts ...lo return ctx, err } if configExists { - projectSubdomainMatch := subdomainPattern.FindStringSubmatch(project.URL) - if len(projectSubdomainMatch) < 2 { - return ctx, fmt.Errorf("invalid project URL [%s]", project.URL) - } - if projectSubdomainMatch[1] != lkConfig.Project.Subdomain { - return ctx, fmt.Errorf("project does not match agent subdomain [%s]", lkConfig.Project.Subdomain) + // When agents_url is explicitly configured, skip subdomain validation. + // This supports self-hosted deployments where the project URL does not + // follow the .livekit.cloud pattern. + agentsURLOverride := lkConfig.Agent != nil && lkConfig.Agent.AgentsURL != "" + if !agentsURLOverride { + projectSubdomainMatch := subdomainPattern.FindStringSubmatch(project.URL) + if len(projectSubdomainMatch) < 2 { + return ctx, fmt.Errorf("invalid project URL [%s]", project.URL) + } + if projectSubdomainMatch[1] != lkConfig.Project.Subdomain { + return ctx, fmt.Errorf("project does not match agent subdomain [%s]", lkConfig.Project.Subdomain) + } + } else { + os.Setenv("LK_AGENTS_URL", lkConfig.Agent.AgentsURL) } } diff --git a/pkg/config/livekit.go b/pkg/config/livekit.go index b4da9ec9..0807c525 100644 --- a/pkg/config/livekit.go +++ b/pkg/config/livekit.go @@ -51,7 +51,8 @@ type LiveKitTOMLProjectConfig struct { } type LiveKitTOMLAgentConfig struct { - ID string `toml:"id"` + ID string `toml:"id"` + AgentsURL string `toml:"agents_url,omitempty"` } func NewLiveKitTOML(forSubdomain string) *LiveKitTOML {