fix(agent/agentcontainers): reduce need to recreate sub agents (#18402)

This commit is contained in:
Mathias Fredriksson
2025-06-17 18:53:41 +03:00
committed by GitHub
parent 7e9a9e098c
commit 7fa1ad8923
5 changed files with 199 additions and 106 deletions
+21
View File
@@ -2,6 +2,7 @@ package agentcontainers
import (
"context"
"slices"
"github.com/google/uuid"
"golang.org/x/xerrors"
@@ -23,6 +24,26 @@ type SubAgent struct {
DisplayApps []codersdk.DisplayApp
}
// CloneConfig makes a copy of SubAgent without ID and AuthToken. The
// name is inherited from the devcontainer.
func (s SubAgent) CloneConfig(dc codersdk.WorkspaceAgentDevcontainer) SubAgent {
return SubAgent{
Name: dc.Name,
Directory: s.Directory,
Architecture: s.Architecture,
OperatingSystem: s.OperatingSystem,
DisplayApps: slices.Clone(s.DisplayApps),
}
}
func (s SubAgent) EqualConfig(other SubAgent) bool {
return s.Name == other.Name &&
s.Directory == other.Directory &&
s.Architecture == other.Architecture &&
s.OperatingSystem == other.OperatingSystem &&
slices.Equal(s.DisplayApps, other.DisplayApps)
}
// SubAgentClient is an interface for managing sub agents and allows
// changing the implementation without having to deal with the
// agentproto package directly.