Skip to content

Commit d31fc4f

Browse files
authored
feat: support web console opener, deprecate sandbox creation (#821)
* feat: support web console opener, deprecate sandbox creation * chore(lk): add opener flag for lk room join * chore(lk): set agent name on env in bootstrap
1 parent 8a8c5eb commit d31fc4f

9 files changed

Lines changed: 395 additions & 57 deletions

File tree

cmd/lk/agent.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,16 @@ var (
142142
}, {
143143
sandboxFlag,
144144
&cli.BoolFlag{
145-
Name: "no-sandbox",
146-
Usage: "If set, will not create a sandbox for the project. ",
147-
Value: false,
145+
Name: "no-sandbox",
146+
Usage: "If set, will not create a sandbox for the project. ",
147+
Value: true,
148+
Hidden: true,
148149
},
149150
}},
150151
}},
151152
Flags: []cli.Flag{
152153
regionFlag,
154+
installFlag,
153155
},
154156
ArgsUsage: "[AGENT-NAME]",
155157
DisableSliceFlagSeparator: true,
@@ -432,6 +434,11 @@ func initAgent(ctx context.Context, cmd *cli.Command) error {
432434

433435
logger.Debugw("Initializing agent project", "working-dir", workingDir)
434436

437+
appName = cmd.Args().First()
438+
if appName == "" {
439+
appName = project.Name
440+
}
441+
435442
// Create sandbox only when not disabled by flag and we don't already have one
436443
if !cmd.Bool("no-sandbox") && sandboxID == "" {
437444
if err := util.Await("Creating sandbox app...", ctx, func(ctx context.Context) error {
@@ -440,11 +447,6 @@ func initAgent(ctx context.Context, cmd *cli.Command) error {
440447
return err
441448
}
442449

443-
appName = cmd.Args().First()
444-
if appName == "" {
445-
appName = project.Name
446-
}
447-
448450
// TODO: (@rektdeckard) figure out why AccessKeyProvider does not immediately
449451
// have access to newly-created API keys, then remove this sleep
450452
time.Sleep(4 * time.Second)
@@ -457,8 +459,7 @@ func initAgent(ctx context.Context, cmd *cli.Command) error {
457459
serverURL,
458460
)
459461

460-
// We set agent name and sandbox ID in env for use in template tasks
461-
os.Setenv("LIVEKIT_AGENT_NAME", appName)
462+
// We set sandbox ID in env for use in template tasks
462463
os.Setenv("LIVEKIT_SANDBOX_ID", sandboxID)
463464

464465
return err

cmd/lk/app.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ var (
6161
templateFlag,
6262
templateURLFlag,
6363
sandboxFlag,
64+
installFlag,
6465
},
6566
},
6667
{
@@ -328,7 +329,6 @@ func setupTemplate(ctx context.Context, cmd *cli.Command) error {
328329
}).
329330
WithTheme(util.Theme))
330331
}
331-
332332
if len(preinstallPrompts) > 0 {
333333
group := huh.NewGroup(preinstallPrompts...)
334334
if err := huh.NewForm(group).
@@ -338,6 +338,10 @@ func setupTemplate(ctx context.Context, cmd *cli.Command) error {
338338
}
339339
}
340340

341+
// Set environment variables for template instantiation
342+
os.Setenv("LIVEKIT_AGENT_NAME", appName)
343+
os.Setenv("LIVEKIT_PROJECT_ID", project.ProjectId)
344+
341345
fmt.Println("Cloning template...")
342346
if err := cloneTemplate(ctx, cmd, templateURL, appName); err != nil {
343347
return err
@@ -374,10 +378,20 @@ func setupTemplate(ctx context.Context, cmd *cli.Command) error {
374378

375379
bootstrap.WriteDotEnv(appName, envOutputFile, env)
376380

381+
if !cmd.IsSet("install") && !SkipPrompts(cmd) {
382+
if err := huh.NewConfirm().
383+
Title("Install dependencies?").
384+
Value(&install).
385+
Inline(true).
386+
WithTheme(util.Theme).
387+
Run(); err != nil {
388+
return err
389+
}
390+
}
377391
if install {
378392
fmt.Println("Installing template...")
379393
if err := doInstall(ctx, bootstrap.TaskInstall, appName, verbose); err != nil {
380-
return err
394+
fmt.Fprintf(os.Stderr, "Warning: installation failed: %v\n", err)
381395
}
382396
}
383397
if err := doPostCreate(ctx, cmd, appName, verbose); err != nil {

cmd/lk/room.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,13 @@ func joinRoom(ctx context.Context, cmd *cli.Command) error {
10711071
})
10721072
token, _ := at.ToJWT()
10731073
_ = util.OpenInMeet(project.URL, token)
1074+
case string(util.OpenTargetConsole):
1075+
_ = util.OpenInConsole(dashboardURL, project.ProjectId, &util.ConsoleURLParams{
1076+
Identity: participantIdentity,
1077+
RoomName: roomName,
1078+
Hidden: true,
1079+
AutoStart: true,
1080+
})
10741081
}
10751082
}
10761083

cmd/lk/token.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ var (
7272
optional(roomFlag),
7373
optional(identityFlag),
7474
openFlag,
75-
7675
&cli.BoolFlag{
7776
Name: "create",
7877
Usage: usageCreate,
@@ -158,7 +157,6 @@ var (
158157
Action: createToken,
159158
Flags: []cli.Flag{
160159
optional(roomFlag),
161-
162160
&cli.BoolFlag{
163161
Name: "create",
164162
Usage: usageCreate,
@@ -416,9 +414,10 @@ func createToken(ctx context.Context, c *cli.Command) error {
416414
at.SetInferenceGrant(&auth.InferenceGrant{Perform: true})
417415
}
418416

417+
agent := c.String("agent")
418+
jobMetadata := c.String("job-metadata")
419419
if grant.RoomJoin {
420-
if agent := c.String("agent"); agent != "" {
421-
jobMetadata := c.String("job-metadata")
420+
if agent != "" {
422421
at.SetRoomConfig(&livekit.RoomConfiguration{
423422
Agents: []*livekit.RoomAgentDispatch{
424423
{
@@ -472,7 +471,22 @@ func createToken(ctx context.Context, c *cli.Command) error {
472471
if c.IsSet("open") {
473472
switch c.String("open") {
474473
case string(util.OpenTargetMeet):
475-
_ = util.OpenInMeet(project.URL, token)
474+
if err := util.OpenInMeet(project.URL, token); err != nil {
475+
return err
476+
}
477+
case string(util.OpenTargetConsole):
478+
if err := util.OpenInConsole(dashboardURL, project.ProjectId, &util.ConsoleURLParams{
479+
AgentName: agent,
480+
JobMetadata: jobMetadata,
481+
Identity: participant,
482+
RoomName: room,
483+
Metadata: metadata,
484+
Attributes: participantAttributes,
485+
Hidden: false,
486+
AutoStart: true,
487+
}); err != nil {
488+
return err
489+
}
476490
}
477491
}
478492

cmd/lk/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ var (
8585
Name: "sandbox",
8686
Usage: "`NAME` of the sandbox, see your cloud dashboard",
8787
Destination: &sandboxID,
88+
Hidden: true,
89+
}
90+
installFlag = &cli.BoolFlag{
91+
Name: "install",
92+
Usage: "Run installation after creating the application",
8893
}
8994

9095
openFlag = util.OpenFlag

0 commit comments

Comments
 (0)