mirror of
https://github.com/coder/coder.git
synced 2026-10-29 17:44:33 +08:00
feat(agent/agentcontainers): support displayApps from devcontainer config (#18342)
Updates the agent injection routine to read the dev container's configuration so we can add display apps to the sub agent.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"cdr.dev/slog"
|
||||
|
||||
agentproto "github.com/coder/coder/v2/agent/proto"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
)
|
||||
|
||||
// SubAgent represents an agent running in a dev container.
|
||||
@@ -19,6 +20,7 @@ type SubAgent struct {
|
||||
Directory string
|
||||
Architecture string
|
||||
OperatingSystem string
|
||||
DisplayApps []codersdk.DisplayApp
|
||||
}
|
||||
|
||||
// SubAgentClient is an interface for managing sub agents and allows
|
||||
@@ -80,11 +82,34 @@ func (a *subAgentAPIClient) List(ctx context.Context) ([]SubAgent, error) {
|
||||
|
||||
func (a *subAgentAPIClient) Create(ctx context.Context, agent SubAgent) (SubAgent, error) {
|
||||
a.logger.Debug(ctx, "creating sub agent", slog.F("name", agent.Name), slog.F("directory", agent.Directory))
|
||||
|
||||
displayApps := make([]agentproto.CreateSubAgentRequest_DisplayApp, 0, len(agent.DisplayApps))
|
||||
for _, displayApp := range agent.DisplayApps {
|
||||
var app agentproto.CreateSubAgentRequest_DisplayApp
|
||||
switch displayApp {
|
||||
case codersdk.DisplayAppPortForward:
|
||||
app = agentproto.CreateSubAgentRequest_PORT_FORWARDING_HELPER
|
||||
case codersdk.DisplayAppSSH:
|
||||
app = agentproto.CreateSubAgentRequest_SSH_HELPER
|
||||
case codersdk.DisplayAppVSCodeDesktop:
|
||||
app = agentproto.CreateSubAgentRequest_VSCODE
|
||||
case codersdk.DisplayAppVSCodeInsiders:
|
||||
app = agentproto.CreateSubAgentRequest_VSCODE_INSIDERS
|
||||
case codersdk.DisplayAppWebTerminal:
|
||||
app = agentproto.CreateSubAgentRequest_WEB_TERMINAL
|
||||
default:
|
||||
return SubAgent{}, xerrors.Errorf("unexpected codersdk.DisplayApp: %#v", displayApp)
|
||||
}
|
||||
|
||||
displayApps = append(displayApps, app)
|
||||
}
|
||||
|
||||
resp, err := a.api.CreateSubAgent(ctx, &agentproto.CreateSubAgentRequest{
|
||||
Name: agent.Name,
|
||||
Directory: agent.Directory,
|
||||
Architecture: agent.Architecture,
|
||||
OperatingSystem: agent.OperatingSystem,
|
||||
DisplayApps: displayApps,
|
||||
})
|
||||
if err != nil {
|
||||
return SubAgent{}, err
|
||||
|
||||
Reference in New Issue
Block a user