Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: agentmode #1500

Open
wants to merge 1 commit into
base: target-workspace-refactor
Choose a base branch
from
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
7 changes: 2 additions & 5 deletions docs/agent_mode/daytona.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ daytona [flags]
* [daytona docs](daytona_docs.md) - Opens the Daytona documentation in your default browser.
* [daytona expose](daytona_expose.md) - Expose a local port over stdout - Used by the Daytona CLI to make direct connections to the workspace
* [daytona forward](daytona_forward.md) - Forward a port publicly via an URL
* [daytona info](daytona_info.md) - Show workspace info
* [daytona info](daytona_info.md) - Show resource info
* [daytona list](daytona_list.md) - List workspaces
* [daytona logs](daytona_logs.md) - View logs for the workspace
* [daytona restart](daytona_restart.md) - Restart the workspace
* [daytona start](daytona_start.md) - Start the workspace
* [daytona stop](daytona_stop.md) - Stop the workspace
* [daytona logs](daytona_logs.md) - View resource logs
* [daytona version](daytona_version.md) - Print the version number

2 changes: 1 addition & 1 deletion docs/agent_mode/daytona_info.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## daytona info

Show workspace info
Show resource info

```
daytona info [flags]
Expand Down
2 changes: 1 addition & 1 deletion docs/agent_mode/daytona_logs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## daytona logs

View logs for the workspace
View resource logs

```
daytona logs [flags]
Expand Down
18 changes: 0 additions & 18 deletions docs/agent_mode/daytona_restart.md

This file was deleted.

18 changes: 0 additions & 18 deletions docs/agent_mode/daytona_start.md

This file was deleted.

18 changes: 0 additions & 18 deletions docs/agent_mode/daytona_stop.md

This file was deleted.

7 changes: 2 additions & 5 deletions hack/docs/agent_mode/daytona.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ see_also:
- daytona docs - Opens the Daytona documentation in your default browser.
- daytona expose - Expose a local port over stdout - Used by the Daytona CLI to make direct connections to the workspace
- daytona forward - Forward a port publicly via an URL
- daytona info - Show workspace info
- daytona info - Show resource info
- daytona list - List workspaces
- daytona logs - View logs for the workspace
- daytona restart - Restart the workspace
- daytona start - Start the workspace
- daytona stop - Stop the workspace
- daytona logs - View resource logs
- daytona version - Print the version number
2 changes: 1 addition & 1 deletion hack/docs/agent_mode/daytona_info.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: daytona info
synopsis: Show workspace info
synopsis: Show resource info
usage: daytona info [flags]
options:
- name: format
Expand Down
2 changes: 1 addition & 1 deletion hack/docs/agent_mode/daytona_logs.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: daytona logs
synopsis: View logs for the workspace
synopsis: View resource logs
usage: daytona logs [flags]
inherited_options:
- name: help
Expand Down
9 changes: 0 additions & 9 deletions hack/docs/agent_mode/daytona_restart.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions hack/docs/agent_mode/daytona_start.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions hack/docs/agent_mode/daytona_stop.yaml

This file was deleted.

7 changes: 4 additions & 3 deletions pkg/cmd/agentmode/agent_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ func Execute() error {
agentModeRootCmd.AddCommand(gitCredCmd)
agentModeRootCmd.AddCommand(dockerCredCmd)
agentModeRootCmd.AddCommand(AgentCmd)
agentModeRootCmd.AddCommand(startCmd)
agentModeRootCmd.AddCommand(stopCmd)
agentModeRootCmd.AddCommand(restartCmd)
agentModeRootCmd.AddCommand(infoCmd)
agentModeRootCmd.AddCommand(portForwardCmd)
agentModeRootCmd.AddCommand(exposeCmd)
Expand Down Expand Up @@ -71,3 +68,7 @@ func init() {
workspaceId = workspaceIdEnv
}
}

func isWorkspaceAgentMode() bool {
return workspaceId != ""
}
68 changes: 48 additions & 20 deletions pkg/cmd/agentmode/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,69 @@ package agentmode
import (
"github.com/daytonaio/daytona/internal/util"
apiclient_util "github.com/daytonaio/daytona/internal/util/apiclient"
"github.com/daytonaio/daytona/pkg/apiclient"
"github.com/daytonaio/daytona/pkg/cmd/format"
"github.com/daytonaio/daytona/pkg/views/target/info"
target_views "github.com/daytonaio/daytona/pkg/views/target/info"
workspaces_views "github.com/daytonaio/daytona/pkg/views/workspace/info"
"github.com/spf13/cobra"
)

var infoCmd = &cobra.Command{
Use: "info",
Short: "Show workspace info",
Short: "Show resource info",
Aliases: []string{"view", "inspect"},
Args: cobra.ExactArgs(0),
GroupID: util.TARGET_GROUP,
RunE: func(cmd *cobra.Command, args []string) error {
var target *apiclient.TargetDTO

target, _, err := apiclient_util.GetTarget(targetId)
if err != nil {
return err
}

if target == nil {
return nil
if isWorkspaceAgentMode() {
return runWorkspaceInfo()
}

if format.FormatFlag != "" {
formattedData := format.NewFormatter(target)
formattedData.Print()
return nil
}

info.Render(target, false)
return nil
return runTargetInfo()
},
}

func init() {
format.RegisterFormatFlag(infoCmd)
}

func runWorkspaceInfo() error {
workspace, _, err := apiclient_util.GetWorkspace(workspaceId)
if err != nil {
return err
}

if workspace == nil {
return nil
}

if format.FormatFlag != "" {
formattedData := format.NewFormatter(workspace)
formattedData.Print()
return nil
}

workspaces_views.Render(workspace, "", false)

return nil
}

func runTargetInfo() error {
target, _, err := apiclient_util.GetTarget(targetId)
if err != nil {
return err
}

if target == nil {
return nil
}

if format.FormatFlag != "" {
formattedData := format.NewFormatter(target)
formattedData.Print()
return nil
}

target_views.Render(target, false)

return nil
}
61 changes: 58 additions & 3 deletions pkg/cmd/agentmode/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,74 @@
package agentmode

import (
"errors"
"context"

"github.com/daytonaio/daytona/internal/util"
apiclient_util "github.com/daytonaio/daytona/internal/util/apiclient"
"github.com/daytonaio/daytona/pkg/agent/config"
cmd_common "github.com/daytonaio/daytona/pkg/cmd/common"
"github.com/spf13/cobra"
)

var logsCmd = &cobra.Command{
Use: "logs",
Short: "View logs for the workspace",
Short: "View resource logs",
Args: cobra.NoArgs,
GroupID: util.TARGET_GROUP,
Aliases: []string{"lg", "log"},
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("not implemented")
ctx := context.Background()

mode := config.ModeTarget
if isWorkspaceAgentMode() {
mode = config.ModeWorkspace
}

cfg, err := config.GetConfig(mode)
if err != nil {
return err
}

if isWorkspaceAgentMode() {
return runWorkspaceLogs(ctx, cfg.Server.ApiUrl, cfg.Server.ApiKey)
}

return runTargetLogs(ctx, cfg.Server.ApiUrl, cfg.Server.ApiKey)
},
}

func runWorkspaceLogs(ctx context.Context, serverUrl, serverApiKey string) error {
workspace, _, err := apiclient_util.GetWorkspace(workspaceId)
if err != nil {
return err
}

cmd_common.ReadWorkspaceLogs(ctx, cmd_common.ReadLogParams{
Id: workspace.Id,
Label: &workspace.Name,
ServerUrl: serverUrl,
ApiKey: serverApiKey,
Index: util.Pointer(0),
Follow: util.Pointer(false),
})

return nil
}

func runTargetLogs(ctx context.Context, serverUrl, serverApiKey string) error {
target, _, err := apiclient_util.GetTarget(targetId)
if err != nil {
return err
}

cmd_common.ReadTargetLogs(ctx, cmd_common.ReadLogParams{
Id: target.Id,
Label: &target.Name,
ServerUrl: serverUrl,
ApiKey: serverApiKey,
Index: util.Pointer(0),
Follow: util.Pointer(false),
})

return nil
}
39 changes: 0 additions & 39 deletions pkg/cmd/agentmode/restart.go

This file was deleted.

Loading