Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix(api): flush SSE headers immediately on patrol stream connect

rcourtmanc457358c636c
diff --git a/internal/api/ai_handlers.go b/internal/api/ai_handlers.go
index 775c981e6b..8046ec48f6 100644
--- a/internal/api/ai_handlers.go
+++ b/internal/api/ai_handlers.go
@@ -3239,6 +3239,11 @@ func (h *AISettingsHandler) HandlePatrolStream(w http.ResponseWriter, r *http.Re
return
}
+ // Send an SSE comment to flush headers immediately so clients get the
+ // HTTP 200 response right away instead of blocking until the first event.
+ fmt.Fprintf(w, ": connected\n\n")
+ flusher.Flush()
+
// Subscribe to patrol stream
// Note: SubscribeToStream already sends the current buffered output to the channel
ch := patrol.SubscribeToStream()
diff --git a/internal/api/chat_service_adapter.go b/internal/api/chat_service_adapter.go
index da15211e15..bc485642a5 100644
--- a/internal/api/chat_service_adapter.go
+++ b/internal/api/chat_service_adapter.go
@@ -6,6 +6,7 @@ import (
"github.com/rcourtman/pulse-go-rewrite/internal/ai"
"github.com/rcourtman/pulse-go-rewrite/internal/ai/chat"
+ "github.com/rcourtman/pulse-go-rewrite/internal/ai/tools"
)
// chatServiceAdapter wraps chat.Service to implement ai.ChatServiceProvider.
@@ -68,6 +69,13 @@ func (a *chatServiceAdapter) DeleteSession(ctx context.Context, sessionID string
return a.svc.DeleteSession(ctx, sessionID)
}
+// GetExecutor exposes the underlying chat service's tool executor so that
+// patrol can set the finding creator. This satisfies the
+// chatServiceExecutorAccessor interface in the ai package.
+func (a *chatServiceAdapter) GetExecutor() *tools.PulseToolExecutor {
+ return a.svc.GetExecutor()
+}
+
// adaptCallback converts an ai.ChatStreamCallback to a chat.StreamCallback.
// The ai package uses []byte for event data, while the chat package uses json.RawMessage.
func adaptCallback(callback ai.ChatStreamCallback) chat.StreamCallback {