Skip to content

Commit fbe27a9

Browse files
authored
Merge pull request #937 from dgageot/resolve2
Simplify BytesSource
2 parents dbddade + 58b01d5 commit fbe27a9

5 files changed

Lines changed: 11 additions & 14 deletions

File tree

cmd/root/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (f *runExecFlags) runOrExec(ctx context.Context, out *cli.Printer, args []s
103103

104104
var source teamloader.AgentSource
105105
if agentFileName == "default" {
106-
source = teamloader.NewBytesSource(f.runConfig.WorkingDir, defaultAgent)
106+
source = teamloader.NewBytesSource(defaultAgent)
107107
} else {
108108
source = teamloader.NewFileSource(agentFileName)
109109
}

pkg/creator/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Can you explain to me what the agent will be used for?`,
180180

181181
return teamloader.LoadFrom(
182182
ctx,
183-
teamloader.NewBytesSource(runConfig.WorkingDir, configAsJSON),
183+
teamloader.NewBytesSource(configAsJSON),
184184
runConfig,
185185
teamloader.WithModelOverrides([]string{modelNameOverride}),
186186
teamloader.WithToolsetRegistry(registry),

pkg/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ func (s *Server) loadTeamForSession(ctx context.Context, agentFilename string, s
13251325

13261326
reloaded, err := teamloader.LoadFrom(
13271327
ctx,
1328-
teamloader.NewBytesSource(sess.WorkingDir, []byte(yamlContent)),
1328+
teamloader.NewBytesSource([]byte(yamlContent)),
13291329
rc,
13301330
teamloader.WithID(agentFilename),
13311331
)

pkg/teamloader/sources.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,12 @@ func (a fileSource) Read() ([]byte, error) {
4949

5050
// bytesSource is used to load an agent configuration from a []byte.
5151
type bytesSource struct {
52-
workingDir string
53-
data []byte
52+
data []byte
5453
}
5554

56-
func NewBytesSource(workingDir string, data []byte) AgentSource {
57-
// TODO(dga): this is not perfect but ok for now
58-
if workingDir == "" {
59-
workingDir = "."
60-
}
55+
func NewBytesSource(data []byte) AgentSource {
6156
return bytesSource{
62-
workingDir: workingDir,
63-
data: data,
57+
data: data,
6458
}
6559
}
6660

@@ -69,7 +63,7 @@ func (a bytesSource) Name() string {
6963
}
7064

7165
func (a bytesSource) ParentDir() string {
72-
return a.workingDir
66+
return ""
7367
}
7468

7569
func (a bytesSource) Read() ([]byte, error) {

pkg/teamloader/teamloader.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ func LoadFrom(ctx context.Context, source AgentSource, runtimeConfig *config.Run
123123
}
124124

125125
fileName := source.Name()
126-
parentDir := source.ParentDir()
127126
env := runtimeConfig.EnvProvider()
127+
parentDir := source.ParentDir()
128+
if parentDir == "" {
129+
parentDir = runtimeConfig.WorkingDir
130+
}
128131

129132
// Load the agent's configuration
130133
data, err := source.Read()

0 commit comments

Comments
 (0)