diff --git a/internal/agent/remote_picks.go b/internal/agent/remote_picks.go index a8807f2ba..57aed6d39 100644 --- a/internal/agent/remote_picks.go +++ b/internal/agent/remote_picks.go @@ -171,6 +171,24 @@ func FollowRemotePicks(ctx context.Context) { followRemote(ctx) } +// KeepFollowingRemote runs FollowRemotePicks until ctx ends, for a magpie +// with no app: the app's Library loop runs it there (library.KeepLinked), +// and a headless `magpie serve` client of a Remote magpie followed its +// model list and efforts but never a pick changed on the remote (KoiLx0 +// on X). +func KeepFollowingRemote(ctx context.Context, interval time.Duration) { + t := time.NewTicker(interval) + defer t.Stop() + for { + FollowRemotePicks(ctx) + select { + case <-ctx.Done(): + return + case <-t.C: + } + } +} + func followRemote(ctx context.Context) { cctx, cancel := context.WithTimeout(ctx, 2*provider.RemoteAgentModelsWait) picks := remotePicks(cctx, 0) diff --git a/internal/cli/providers_cli.go b/internal/cli/providers_cli.go index 0c11e9a5b..91898c1e2 100644 --- a/internal/cli/providers_cli.go +++ b/internal/cli/providers_cli.go @@ -1728,6 +1728,8 @@ func serve() error { // one's own Remote magpies follow it gateway.SetUpdater(serveUpdateAsked(follow)) go provider.KeepRemotesUpdated(ctx, version) + // the models a Remote magpie's agents are on, as the app follows them + go agent.KeepFollowingRemote(ctx, 30*time.Second) err := s.ListenAndServe(ctx) if exe := follow.restartTo(); exe != "" { // the plugin hosts end, waited for, first, as magpie web's diff --git a/internal/cli/web_cli.go b/internal/cli/web_cli.go index 17659acd7..295565858 100644 --- a/internal/cli/web_cli.go +++ b/internal/cli/web_cli.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "github.com/yetone/magpie/internal/agent" "github.com/yetone/magpie/internal/daemon" "github.com/yetone/magpie/internal/gateway" "github.com/yetone/magpie/internal/gui" @@ -241,6 +242,8 @@ func serveCmd(args []string) error { return serve() } go stats.Run(version, "serve") + // the models a Remote magpie's agents are on, as the app follows them + go agent.KeepFollowingRemote(context.Background(), 30*time.Second) w, err := gui.StartWeb(web, version) if err != nil { return err