Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4604c3d
feat(public): builder agent methods on the Public API client
Topherhindman Nov 19, 2026
b97f3c7
feat(lk): lk agent builder manages builder agents under --user-auth
Topherhindman Nov 19, 2026
33db19e
refactor(public): name the recording download client for every signed…
Topherhindman Nov 19, 2026
2ce1ae7
feat(lk): lk agent builder download fetches a version's agent code
Topherhindman Nov 19, 2026
2645eda
fix(lk): a refused builder command doesn't point at an API-key path
Topherhindman Nov 20, 2026
dee252f
fix(lk): webhook, user and workspace refusals don't point at an API-k…
Topherhindman Nov 20, 2026
7f33c29
fix(lk): builder --config-file reports where its JSON is broken
Topherhindman Nov 20, 2026
50e17f6
fix(lk): deploy --wait ends on SLEEPING and checks freshness by serve…
Topherhindman Nov 20, 2026
d5c8ed8
fix(lk): deploy --wait says the deployment continues however it stops
Topherhindman Nov 20, 2026
9f29f48
fix(lk): download --output makes an existing file private too
Topherhindman Nov 20, 2026
4fbb244
fix(lk): a failed --unzip leaves its directory as it found it
Topherhindman Nov 20, 2026
490dc71
test(lk): show that a config property lk doesn't know reaches the API
Topherhindman Nov 20, 2026
2ce6335
feat(lk): lk agent builder names Agent Builder agents as the API does
Topherhindman Nov 20, 2026
4da357d
fix(lk): a failed --unzip removes only what it made
Topherhindman Nov 20, 2026
e481dea
fix(lk): deploy --wait reports a failure whose build it never saw
Topherhindman Nov 20, 2026
6e617bb
fix(lk): --config-file names a missing file in lk's own words
Topherhindman Nov 20, 2026
0fa9e82
fix(lk): deploy --wait treats an unknown status before the deploy as …
Topherhindman Nov 20, 2026
67fb6a0
fix(lk): agent builder list and versions refuse a --limit that wraps
Topherhindman Dec 2, 2026
a81489a
fix(lk): agent builder usage lines leave out --project and --user-auth
Topherhindman Dec 2, 2026
914e8f8
chore(public): regenerate the Public API client
Topherhindman Dec 2, 2026
8a64cec
feat(lk): lk agent builder update-secrets sets and removes an agent's…
Topherhindman Dec 2, 2026
8992e86
fix(lk): a KEY=VALUE flag that lk can't parse doesn't print its value
Topherhindman Dec 2, 2026
2ceaa2c
fix(lk): a $ in a --secrets or --attribute value reaches the API as w…
Topherhindman Dec 2, 2026
add2712
fix(lk): agent builder deploy --json prints one shape with or without…
Topherhindman Dec 2, 2026
2376abe
fix(lk): agent builder download --unzip stops at 256 MiB unpacked
Topherhindman Dec 2, 2026
2ec58c5
fix(lk): agent builder deploy --wait stops when the agent is deleted
Topherhindman Dec 3, 2026
87671f1
fix(lk): a KEY=VALUE flag keeps bytes that aren't UTF-8
Topherhindman Dec 3, 2026
d1b25f3
fix(lk): key, member and invite refusals don't point at an API-key path
Topherhindman Dec 3, 2026
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
861 changes: 861 additions & 0 deletions cmd/lk/agent_builder.go

Large diffs are not rendered by default.

402 changes: 402 additions & 0 deletions cmd/lk/agent_builder_test.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions cmd/lk/project_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func listProjectKeys(ctx context.Context, cmd *cli.Command) error {
// may not record.
me, err := client.GetCurrentUser(ctx)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
// An empty owner would list everyone's keys.
if filter.OwnerID = util.Deref(me.Id); filter.OwnerID == "" {
Expand All @@ -100,7 +100,7 @@ func listProjectKeys(ctx context.Context, cmd *cli.Command) error {
}
keys, err := client.ListKeys(ctx, projectID, filter)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
return render.AccessKeys(out, cmd.Bool("json"), keys)
}
Expand All @@ -116,7 +116,7 @@ func createProjectKey(ctx context.Context, cmd *cli.Command) error {
}
key, err := client.GenerateKey(ctx, projectID, cmd.String("description"), cmd.Bool("service-account"))
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
if cmd.Bool("json") {
util.PrintJSON(key)
Expand Down Expand Up @@ -145,7 +145,7 @@ func deleteProjectKey(ctx context.Context, cmd *cli.Command) error {
return errors.New("aborted")
}
if err := client.DeleteKey(ctx, projectID, apiKey); err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
return util.RenderAction(out, cmd.Bool("json"), "apiKey", apiKey, "deleted", fmt.Sprintf("Revoked API key %s", util.Accented(apiKey)))
}
22 changes: 11 additions & 11 deletions cmd/lk/project_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func listProjectMembers(ctx context.Context, cmd *cli.Command) error {
}
members, err := client.ListProjectMembers(ctx, projectID)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
return render.ProjectMembers(out, cmd.Bool("json"), members)
}
Expand All @@ -182,7 +182,7 @@ func getProjectMember(ctx context.Context, cmd *cli.Command) error {
}
member, err := client.GetProjectMember(ctx, projectID, userID)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
return render.ProjectMember(out, cmd.Bool("json"), *member)
}
Expand All @@ -206,7 +206,7 @@ func updateProjectMember(ctx context.Context, cmd *cli.Command) error {
}
member, err := client.UpdateProjectMember(ctx, projectID, userID, role)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
out.Statusf("Updated member %s", util.Accented(userID))
return render.ProjectMember(out, cmd.Bool("json"), *member)
Expand All @@ -229,7 +229,7 @@ func removeProjectMember(ctx context.Context, cmd *cli.Command) error {
return client.RemoveProjectMember(ctx, projectID, userID, confirmedNumKeys)
})
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
return renderMemberRemoved(cmd, userID, numKeys)
}
Expand All @@ -254,7 +254,7 @@ func addProjectMembers(ctx context.Context, cmd *cli.Command) error {
}
members, err := client.AddWorkspaceMembersToProject(ctx, projectID, userIDs, role)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
out.Statusf("Added %d member(s) to project", len(members))
return render.ProjectMembers(out, cmd.Bool("json"), members)
Expand All @@ -271,7 +271,7 @@ func listProjectInvites(ctx context.Context, cmd *cli.Command) error {
}
invites, err := client.ListProjectInvites(ctx, projectID)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
return render.ProjectInvites(out, cmd.Bool("json"), invites)
}
Expand All @@ -287,7 +287,7 @@ func getProjectInvite(ctx context.Context, cmd *cli.Command) error {
}
invite, err := client.GetProjectInvite(ctx, token)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
return render.ProjectInvite(out, cmd.Bool("json"), *invite)
}
Expand All @@ -311,7 +311,7 @@ func createProjectInvite(ctx context.Context, cmd *cli.Command) error {
}
resp, err := client.InviteProjectMember(ctx, projectID, email, role)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}

if cmd.Bool("json") {
Expand Down Expand Up @@ -347,7 +347,7 @@ func updateProjectInvite(ctx context.Context, cmd *cli.Command) error {
}
invite, err := client.UpdateProjectInvite(ctx, projectID, email, role)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
out.Statusf("Updated invite for %s", util.Accented(email))
return render.ProjectInvite(out, cmd.Bool("json"), *invite)
Expand All @@ -367,7 +367,7 @@ func deleteProjectInvite(ctx context.Context, cmd *cli.Command) error {
return err
}
if err := client.DeleteProjectInvite(ctx, projectID, email); err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
return util.RenderAction(out, cmd.Bool("json"), "email", email, "deleted", fmt.Sprintf("Revoked invite for %s", util.Accented(email)))
}
Expand All @@ -384,7 +384,7 @@ func answerProjectInvite(ctx context.Context, cmd *cli.Command) error {
accept := !cmd.Bool("decline")
member, err := client.AnswerProjectInvitation(ctx, token, accept)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
if !accept {
out.Status("Declined invite.")
Expand Down
12 changes: 6 additions & 6 deletions cmd/lk/project_webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func listProjectWebhooks(ctx context.Context, cmd *cli.Command) error {
}
webhooks, err := client.ListWebhooks(ctx, projectID)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
return render.Webhooks(out, cmd.Bool("json"), webhooks)
}
Expand All @@ -180,7 +180,7 @@ func createProjectWebhook(ctx context.Context, cmd *cli.Command) error {
FilterParams: webhookFilter(cmd),
})
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
if !cmd.Bool("json") {
out.Statusf("Created webhook %s", util.Accented(util.Deref(webhook.Id)))
Expand Down Expand Up @@ -220,7 +220,7 @@ func updateProjectWebhook(ctx context.Context, cmd *cli.Command) error {
}
webhook, err := client.UpdateWebhook(ctx, projectID, webhookID, body)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
if !cmd.Bool("json") {
out.Statusf("Updated webhook %s", util.Accented(webhookID))
Expand All @@ -245,7 +245,7 @@ func deleteProjectWebhook(ctx context.Context, cmd *cli.Command) error {
return errors.New("aborted")
}
if err := client.DeleteWebhook(ctx, projectID, webhookID); err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
return util.RenderAction(out, cmd.Bool("json"), "webhookId", webhookID, "deleted", fmt.Sprintf("Deleted webhook %s", util.Accented(webhookID)))
}
Expand All @@ -266,7 +266,7 @@ func testProjectWebhook(ctx context.Context, cmd *cli.Command) error {
event := cmd.String("event")
result, err := client.SendTestWebhook(ctx, projectID, webhookID, event)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
if cmd.Bool("json") {
util.PrintJSON(result)
Expand Down Expand Up @@ -301,7 +301,7 @@ func listProjectWebhookEvents(ctx context.Context, cmd *cli.Command) error {
}
events, err := client.ListWebhookEvents(ctx, projectID)
if err != nil {
return cloudAPIError(err)
return cloudOnlyAPIError(err)
}
if cmd.Bool("json") {
if events == nil {
Expand Down
43 changes: 41 additions & 2 deletions cmd/lk/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ package main
// credential it carried (a session token as bearer=, or as apikey= the
// API key that issued an access token, read from its claims without
// checking the signature) and the project it named.
// body METHOD URL
// Print the body of the last METHOD request to URL, a URL without a
// query, as lk sent it.
//
// To regenerate expected output after an intended change, run
//
Expand All @@ -53,6 +56,7 @@ package main
// rewritten with what the run produced; regexp checks (stdout, stderr) are not.

import (
"bytes"
"context"
"encoding/json"
"errors"
Expand Down Expand Up @@ -103,6 +107,7 @@ func TestScripts(t *testing.T) {
Cmds: map[string]func(*testscript.TestScript, bool, []string){
"respond": cmdRespond,
"requests": cmdRequests,
"body": cmdBody,
"mint": cmdMint,
"capture-next-agent-upload": cmdCaptureNextAgentUpload,
},
Expand Down Expand Up @@ -148,6 +153,7 @@ type fakeCloud struct {
mu sync.Mutex
responses map[string]cannedResponse // by "METHOD URL", with the query only if respond had one
log []string
bodies map[string]string // the last request body, by "METHOD URL" without the query

// mint makes the fake answer a Public API token request it has no canned
// response for as the Public API does: with an access token carrying the
Expand All @@ -167,7 +173,7 @@ type cannedResponse struct {
}

func newFakeCloud() *fakeCloud {
f := &fakeCloud{responses: map[string]cannedResponse{}, secrets: map[string]string{}, sessions: map[string]bool{}}
f := &fakeCloud{responses: map[string]cannedResponse{}, bodies: map[string]string{}, secrets: map[string]string{}, sessions: map[string]bool{}}
f.Server = httptest.NewServer(http.HandlerFunc(f.serve))
return f
}
Expand Down Expand Up @@ -197,6 +203,10 @@ func (f *fakeCloud) serve(w http.ResponseWriter, r *http.Request) {
}

target := r.Method + " " + r.URL.Scheme + "://" + r.URL.Host + r.URL.Path
if body, err := io.ReadAll(r.Body); err == nil {
f.bodies[target] = string(body)
r.Body = io.NopCloser(bytes.NewReader(body))
}
line := target
if token, ok := strings.CutPrefix(r.Header.Get("Authorization"), "Bearer "); ok {
if v, err := auth.ParseAPIToken(token); err == nil {
Expand Down Expand Up @@ -336,6 +346,21 @@ func cmdMint(ts *testscript.TestScript, neg bool, args []string) {
}
}

// cmdBody implements `body METHOD URL`.
func cmdBody(ts *testscript.TestScript, neg bool, args []string) {
if neg || len(args) != 2 {
ts.Fatalf("usage: body METHOD URL")
}
f := ts.Value(fakeCloudKey{}).(*fakeCloud)
f.mu.Lock()
body, ok := f.bodies[args[0]+" "+args[1]]
f.mu.Unlock()
if !ok {
ts.Fatalf("no %s request to %s", args[0], args[1])
}
fmt.Fprintln(ts.Stdout(), body)
}

// cmdRequests implements `requests`.
func cmdRequests(ts *testscript.TestScript, neg bool, args []string) {
if neg || len(args) != 0 {
Expand Down Expand Up @@ -371,7 +396,7 @@ func (f *fakeCloud) respond(target string, status int, body string) error {
}

// publicAPIRoutes are the Public API routes the fake answers, each with the
// generated type of its 200 body.
// generated type of its 200 body, or nil for a route whose body isn't JSON.
var publicAPIRoutes = []struct {
method string
path *regexp.Regexp
Expand Down Expand Up @@ -437,6 +462,17 @@ var publicAPIRoutes = []struct {
{http.MethodGet, regexp.MustCompile(`^/v0/projects/[^/]+/phone-numbers/[^/]+$`), func() any { return new(oapi.LivekitPublicapiTelephonyV1PhoneNumbersGetResponse) }},
{http.MethodPatch, regexp.MustCompile(`^/v0/projects/[^/]+/phone-numbers/[^/]+$`), func() any { return new(oapi.LivekitPublicapiTelephonyV1PhoneNumbersUpdateResponse) }},
{http.MethodDelete, regexp.MustCompile(`^/v0/projects/[^/]+/phone-numbers/[^/]+$`), func() any { return new(oapi.LivekitPublicapiTelephonyV1PhoneNumbersReleaseResponse) }},
{http.MethodGet, regexp.MustCompile(`^/v0/projects/[^/]+/agent-builder/agents$`), func() any { return new(oapi.LivekitPublicapiAgentbuilderV1AgentsListResponse) }},
{http.MethodPost, regexp.MustCompile(`^/v0/projects/[^/]+/agent-builder/agents$`), func() any { return new(oapi.LivekitPublicapiAgentbuilderV1AgentsCreateResponse) }},
{http.MethodGet, regexp.MustCompile(`^/v0/projects/[^/]+/agent-builder/agents/[^/:]+$`), func() any { return new(oapi.LivekitPublicapiAgentbuilderV1AgentsGetResponse) }},
{http.MethodPatch, regexp.MustCompile(`^/v0/projects/[^/]+/agent-builder/agents/[^/:]+$`), func() any { return new(oapi.LivekitPublicapiAgentbuilderV1AgentsUpdateResponse) }},
{http.MethodDelete, regexp.MustCompile(`^/v0/projects/[^/]+/agent-builder/agents/[^/:]+$`), func() any { return new(oapi.LivekitPublicapiAgentbuilderV1AgentsDeleteResponse) }},
{http.MethodPost, regexp.MustCompile(`^/v0/projects/[^/]+/agent-builder/agents/[^/:]+:deploy$`), func() any { return new(oapi.LivekitPublicapiAgentbuilderV1AgentsDeployResponse) }},
{http.MethodPatch, regexp.MustCompile(`^/v0/projects/[^/]+/agent-builder/agents/[^/]+/secrets$`), func() any { return new(oapi.LivekitPublicapiAgentbuilderV1AgentSecretsUpdateResponse) }},
{http.MethodGet, regexp.MustCompile(`^/v0/projects/[^/]+/agent-builder/agents/[^/]+/versions$`), func() any { return new(oapi.LivekitPublicapiAgentbuilderV1AgentVersionsListResponse) }},
{http.MethodGet, regexp.MustCompile(`^/v0/projects/[^/]+/agent-builder/agents/[^/]+/code-url$`), func() any { return new(oapi.LivekitPublicapiAgentbuilderV1AgentsGetCodeURLResponse) }},
// The signed URL of an Agent Builder agent's code answers a zip, not JSON.
{http.MethodGet, regexp.MustCompile(`^/v0/projects/[^/]+/agent-builder/agents/[^/]+/versions/[^/]+/code$`), nil},
{http.MethodGet, regexp.MustCompile(`^/v0/users/me$`), func() any { return new(oapi.LivekitPublicapiUsersV1GetCurrentUserResponse) }},
{http.MethodDelete, regexp.MustCompile(`^/v0/users/me/session-token$`), func() any { return new(oapi.LivekitPublicapiUsersV1SessionTokenRevokeResponse) }},
}
Expand Down Expand Up @@ -473,6 +509,9 @@ func checkPublicAPIBody(method, path string, status int, body string) error {
default:
for _, r := range publicAPIRoutes {
if r.method == method && r.path.MatchString(path) {
if r.body == nil {
return nil
}
v = r.body()
break
}
Expand Down
50 changes: 50 additions & 0 deletions cmd/lk/testdata/script/agent-builder-deploy-wait.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# deploy --wait reads the agent once before the deploy, so that it can tell
# a failure of this deployment from an earlier one, then reads it until the
# new deployment is up. A RUNNING whose deployedAt is after the deploy
# response's Date header is the new deployment. (The order of statuses
# across reads, failures and SLEEPING are TestWaitForBuilderDeployment's
# job.)
respond POST http://publicapi.test/v0/projects/p_1/agent-builder/agents/ab_1:deploy 200 '{"versionId":"abv_2","status":"DEPLOYMENT_STATUS_BUILDING"}'
respond GET http://publicapi.test/v0/projects/p_1/agent-builder/agents/ab_1 200 '{"agent":{"id":"ab_1","name":"greeter","versionId":"abv_2","deployment":{"status":"DEPLOYMENT_STATUS_RUNNING","versionId":"abv_2","deployedAt":"2099-01-01T00:00:00Z"}}}'
exec lk --user-auth agent builder deploy ab_1 --wait
stdout 'ab_1.*greeter.*RUNNING.*abv_2.*abv_2'
cmp stderr want-stderr

# --json prints the deploy's answer, the shape it has without --wait, with
# the status the wait ended on.
exec lk --user-auth agent builder deploy ab_1 --wait --json
cmp stdout want-json

requests
cmp stdout want-requests

-- home/.livekit/cli-config.yaml --
default_user: u_1
users:
- id: u_1
email: dev@example.com
session_token: st_1
api_url: http://publicapi.test
default_project: p_1
projects:
- project_id: p_1
name: one
alias: one
url: ws://one.test
-- want-stderr --
Using user [dev@example.com] on [http://publicapi.test]
Deploying version abv_2 of Agent Builder agent ab_1
Status: RUNNING
Agent Builder agent ab_1 runs version abv_2
-- want-json --
{
"status": "DEPLOYMENT_STATUS_RUNNING",
"versionId": "abv_2"
}
-- want-requests --
GET http://publicapi.test/v0/projects/p_1/agent-builder/agents/ab_1 bearer=st_1 project=p_1
POST http://publicapi.test/v0/projects/p_1/agent-builder/agents/ab_1:deploy bearer=st_1 project=p_1
GET http://publicapi.test/v0/projects/p_1/agent-builder/agents/ab_1 bearer=st_1 project=p_1
GET http://publicapi.test/v0/projects/p_1/agent-builder/agents/ab_1 bearer=st_1 project=p_1
POST http://publicapi.test/v0/projects/p_1/agent-builder/agents/ab_1:deploy bearer=st_1 project=p_1
GET http://publicapi.test/v0/projects/p_1/agent-builder/agents/ab_1 bearer=st_1 project=p_1
Loading
Loading