feat: update orchestrator for enhanced multi-bot management and room discovery
This commit is contained in:
+25
-11
@@ -14,6 +14,9 @@ import (
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@@ -70,13 +73,14 @@ func main() {
|
||||
// Non-fatal: orchestration is optional
|
||||
logger.Warn("orchestrator not started", "err", err)
|
||||
} else {
|
||||
logger.Info("orchestrator ready",
|
||||
"managed_rooms", len(orch.cfg.Orchestration.Rooms),
|
||||
)
|
||||
logger.Info("orchestrator initialized")
|
||||
}
|
||||
|
||||
// ── Start normal agents ──
|
||||
var wg sync.WaitGroup
|
||||
var scannerOnce sync.Once
|
||||
var scanner *mautrix.Client
|
||||
|
||||
for _, path := range configPaths {
|
||||
path := path
|
||||
cfg, err := config.Load(path)
|
||||
@@ -101,20 +105,22 @@ func main() {
|
||||
// Connect agent to bus for orchestration
|
||||
a.SetBus(agentBus)
|
||||
|
||||
// If orchestrator is active, set interceptor so bots don't
|
||||
// handle events directly in orchestrated rooms.
|
||||
// The first bot's listener to receive the event will trigger orchestration.
|
||||
// If orchestrator is active, wire interceptor and membership notify
|
||||
if orch != nil {
|
||||
a.SetInterceptor(orch.orchestrator.Intercept)
|
||||
}
|
||||
a.SetMembershipNotify(orch.orchestrator.NotifyMembership)
|
||||
|
||||
// Register this agent as a participant in the orchestrator
|
||||
if orch != nil {
|
||||
orch.orchestrator.RegisterParticipant(orchestration.ParticipantInfo{
|
||||
ID: cfg.Agent.ID,
|
||||
Description: cfg.Agent.Description,
|
||||
ID: cfg.Agent.ID,
|
||||
MatrixUserID: cfg.Matrix.UserID,
|
||||
Description: cfg.Agent.Description,
|
||||
Capabilities: cfg.Agent.Tags,
|
||||
})
|
||||
|
||||
// Grab the first available Matrix client for room scanning
|
||||
scannerOnce.Do(func() {
|
||||
scanner = a.RawMatrixClient()
|
||||
})
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
@@ -127,6 +133,14 @@ func main() {
|
||||
}()
|
||||
}
|
||||
|
||||
// ── Startup room scan (after all participants are registered) ──
|
||||
if orch != nil && scanner != nil {
|
||||
orch.orchestrator.SetScanner(scanner)
|
||||
scanCtx, scanCancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
orch.orchestrator.ScanExistingRooms(scanCtx)
|
||||
scanCancel()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
logger.Info("all agents stopped")
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user