@@ -4,18 +4,14 @@ import (
44 "fmt"
55 "log/slog"
66 "os"
7- "path/filepath"
8- "time"
97
108 "github.com/spf13/cobra"
119
1210 "github.com/docker/cagent/pkg/agentfile"
1311 "github.com/docker/cagent/pkg/cli"
1412 "github.com/docker/cagent/pkg/config"
15- "github.com/docker/cagent/pkg/remote"
1613 "github.com/docker/cagent/pkg/server"
1714 "github.com/docker/cagent/pkg/session"
18- "github.com/docker/cagent/pkg/teamloader"
1915 "github.com/docker/cagent/pkg/telemetry"
2016)
2117
@@ -73,96 +69,21 @@ func (f *apiFlags) runAPICommand(cmd *cobra.Command, args []string) error {
7369
7470 slog .Debug ("Starting server" , "agents" , agentsPath , "addr" , ln .Addr ().String ())
7571
76- resolvedPath , err := agentfile .Resolve (ctx , out , agentsPath )
77- if err != nil {
78- return err
79- }
80-
8172 sessionStore , err := session .NewSQLiteSessionStore (f .sessionDB )
8273 if err != nil {
8374 return fmt .Errorf ("failed to create session store: %w" , err )
8475 }
8576
86- var opts []server.Opt
87-
88- if ! agentfile .IsOCIReference (agentsPath ) {
89- stat , err := os .Stat (resolvedPath )
90- if err != nil {
91- return fmt .Errorf ("failed to stat agents path: %w" , err )
92- }
93- if stat .IsDir () {
94- // For directories: only set agentsDir, not agentsPath
95- opts = append (opts , server .WithAgentsDir (resolvedPath ))
96- } else {
97- opts = append (opts , server .WithAgentsPath (resolvedPath ), server .WithAgentsDir (filepath .Dir (resolvedPath )))
98- }
99- }
100-
101- teams , err := teamloader .LoadTeams (ctx , resolvedPath , & f .runConfig )
77+ sources , err := agentfile .ResolveSources (ctx , nil , agentsPath )
10278 if err != nil {
103- return fmt .Errorf ("failed to load teams: %w" , err )
104- }
105-
106- // For OCI refs: store the reference for later per-session reloading, then clean up temp file
107- if agentfile .IsOCIReference (agentsPath ) {
108- teamKey := filepath .Base (resolvedPath )
109- opts = append (opts , server .WithOCIRef (teamKey , agentsPath ))
110-
111- if err := os .Remove (resolvedPath ); err != nil {
112- slog .Warn ("Failed to remove temporary OCI file" , "path" , resolvedPath , "error" , err )
113- } else {
114- slog .Debug ("Cleaned up temporary OCI file" , "path" , resolvedPath )
115- }
79+ return fmt .Errorf ("failed to resolve agent sources: %w" , err )
11680 }
117-
118- defer func () {
119- for _ , team := range teams {
120- if err := team .StopToolSets (ctx ); err != nil {
121- slog .Error ("Failed to stop tool sets" , "error" , err )
122- }
123- }
124- }()
125-
126- s , err := server .New (sessionStore , & f .runConfig , teams , opts ... )
81+ s , err := server .New (sessionStore , & f .runConfig , sources )
12782 if err != nil {
12883 return fmt .Errorf ("failed to create server: %w" , err )
12984 }
13085
131- // Start background auto-pull for OCI references if enabled
132- if f .pullIntervalMins > 0 {
133- go func () {
134- ticker := time .NewTicker (time .Duration (f .pullIntervalMins ) * time .Minute )
135- defer ticker .Stop ()
136-
137- slog .Info ("Auto-pull enabled for OCI reference" , "reference" , agentsPath , "interval_minutes" , f .pullIntervalMins )
138-
139- for {
140- select {
141- case <- ctx .Done ():
142- return
143- case <- ticker .C :
144- slog .Info ("Auto-pulling OCI reference" , "reference" , agentsPath )
145- if _ , err := remote .Pull (ctx , agentsPath , false ); err != nil {
146- slog .Error ("Failed to auto-pull OCI reference" , "reference" , agentsPath , "error" , err )
147- continue
148- }
149-
150- // Resolve the OCI reference to get the updated file path
151- newResolvedPath , err := agentfile .Resolve (ctx , out , agentsPath )
152- if err != nil {
153- slog .Error ("Failed to resolve OCI reference after pull" , "reference" , agentsPath , "error" , err )
154- continue
155- }
156-
157- if err := s .ReloadTeams (ctx , newResolvedPath ); err != nil {
158- slog .Error ("Failed to reload teams" , "reference" , agentsPath , "error" , err )
159- } else {
160- slog .Info ("Successfully reloaded teams from updated OCI reference" , "reference" , agentsPath )
161- }
162- }
163- }
164- }()
165- }
86+ // TODO(rumpl): implement pull interval
16687
16788 return s .Serve (ctx , ln )
16889}
0 commit comments