fix: ensure swarm final result is relayed to user and update swarm status
This commit is contained in:
parent
29fa56eb4f
commit
16f37b077f
2 changed files with 32 additions and 3 deletions
|
|
@ -56,6 +56,13 @@ func (o *Orchestrator) SpawnSwarm(ctx context.Context, goal, channel, chatID str
|
|||
go func() {
|
||||
defer o.StopSwarm(id)
|
||||
o.RunSubTask(sCtx, id, "", "Manager", goal)
|
||||
|
||||
// Update swarm status to completed
|
||||
sw, err := o.store.GetSwarm(context.Background(), id)
|
||||
if err == nil {
|
||||
sw.Status = core.SwarmStatusCompleted
|
||||
o.store.UpdateSwarm(context.Background(), sw)
|
||||
}
|
||||
}()
|
||||
return id, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,11 +42,33 @@ func NewService(dbPath string, provider providers.LLMProvider, registry *tools.T
|
|||
|
||||
func (s *Service) listen() {
|
||||
if _, err := s.Bus.Subscribe("node.events", func(e core.Event) {
|
||||
// --- Terminal Log (Lokal Only) ---
|
||||
color := "\033[36m" // Cyan
|
||||
if e.Type == "node.failed" { color = "\033[31m" } // Red
|
||||
if e.Type == "node.completed" { color = "\033[32m" } // Green
|
||||
|
||||
content := e.Payload["content"]
|
||||
if content == nil { content = e.Payload["output"] }
|
||||
if content == nil { content = e.Payload["error"] }
|
||||
|
||||
fmt.Printf("\n%s[SWARM LOG]\033[0m Node: %s | Type: %s | Content: %v\n", color, e.NodeID[:4], e.Type, content)
|
||||
// ---------------------------------
|
||||
|
||||
msg := ""
|
||||
switch e.Type {
|
||||
case core.EventNodeThinking: msg = fmt.Sprintf("🤖 [%s]: %s", e.NodeID[:4], e.Payload["content"])
|
||||
case core.EventNodeCompleted: msg = fmt.Sprintf("✅ [%s] Done.", e.NodeID[:4])
|
||||
case core.EventNodeFailed: msg = fmt.Sprintf("❌ [%s] Failed: %v", e.NodeID[:4], e.Payload["error"])
|
||||
case core.EventNodeThinking:
|
||||
msg = fmt.Sprintf("🤖 [%s]: %s", e.NodeID[:4], e.Payload["content"])
|
||||
case core.EventNodeCompleted:
|
||||
// Cek apakah ini Manager (Root Node)
|
||||
node, err := s.Store.GetNode(context.Background(), e.NodeID)
|
||||
if err == nil && node.ParentID == "" {
|
||||
// Ini Manager! Kirim hasil akhirnya.
|
||||
msg = fmt.Sprintf("🏁 **FINAL RESULT FROM SWARM** 🏁\n\n%s", e.Payload["output"])
|
||||
} else {
|
||||
msg = fmt.Sprintf("✅ [%s] Done.", e.NodeID[:4])
|
||||
}
|
||||
case core.EventNodeFailed:
|
||||
msg = fmt.Sprintf("❌ [%s] Failed: %v", e.NodeID[:4], e.Payload["error"])
|
||||
}
|
||||
if msg != "" {
|
||||
// Get swarm origin
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue