Add SSE endpoint and dream notify — /api/events and /api/events/notify

This commit is contained in:
2026-04-27 02:20:50 +00:00
parent 9088b5643d
commit 9b312d936f
2 changed files with 60 additions and 0 deletions
+12
View File
@@ -289,6 +289,18 @@ def deliver(dream_text, mode, task=None):
print(f"Dream written to Nextcloud: Journal/Dreams/{filename}")
# Notify any open browser connections via SSE
try:
import requests as _req
_req.post("http://localhost:8000/api/events/notify", json={
"type": "dream",
"mode": mode,
"filename": filename,
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M"),
}, timeout=3)
except Exception as _e:
print(f"SSE notify failed (non-critical): {_e}")
state = load_dreamer_state()
state["last_dream_timestamp"] = datetime.now().timestamp()
state["last_dream_mode"] = mode