}
return daemonServe(ctx, listener, telegram, whatsapp, func(notify func(Event)) (*TurnLoop, error) {
- return newTurnLoop(agent, memory, subagents, client, time.Now, notify)
+ return newTurnLoop(agent, memory, subagents, whatsapp, client, time.Now, notify)
})
}
}
// daemonServe runs the loop that start makes and serves the clients of listener
-// until ctx ends or the loop fails. It closes listener. It keeps whatsapp
-// connected. When bot is not nil, it runs the bot too, and a failure of the bot
-// stops the agent.
+// until ctx ends or the loop fails. It closes listener. It runs whatsapp, which
+// logs its batches and notes in the loop and tells all clients its notices, and
+// a failure of whatsapp stops the agent. When bot is not nil, it runs the bot
+// too, and a failure of the bot stops the agent.
func daemonServe(ctx context.Context, listener net.Listener, bot *TelegramBot, whatsapp *WhatsApp, start func(notify func(Event)) (*TurnLoop, error)) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
hub.Accept(ctx, listener, l)
}()
+ var whatsappErr error
go func() {
defer workers.Done()
- whatsapp.Run(ctx)
+ whatsappErr = whatsapp.Run(ctx, l, notify)
+ cancel()
}()
var botErr error
hub.CloseAll()
workers.Wait()
- return errors.Join(err, botErr)
+ return errors.Join(err, whatsappErr, botErr)
}
// daemonRunRequest runs one request of a client. The answers of a WhatsApp