Streaming & Realtime
SSE, webhooks, Socket.io, and polling for AI output.
How UXDL surfaces AI output to clients: live tokens, durable completion, and job status updates.
Mechanisms
| Mechanism | Use case | Typical pattern |
|---|---|---|
| SSE | Token-by-token display for in-process agents | Agents & pipelines + POST /chat/stream |
| LangGraph webhook | Durable completion for hosted runs | Webhooks & reconciliation |
| Socket.io | Push job status when the DB row updates | Backend → Socket.io |
| Polling | Fallback while status === processing | GET job endpoint on an interval |
In-process chat (SSE)
Expose streaming from agent.stream() or equivalent via Server-Sent Events.
Event types (convention):
| Event | Payload | Meaning |
|---|---|---|
token | { token: string, node: string } | Streamed AI chunk |
done | "" | Generation complete |
error | { message: string } | Runtime error |
Persist the full assistant message to the database after the stream completes so history survives restarts.
Hosted runs (webhook + optional stream)
Hosted graphs may stream interim events via LangGraph streamMode, but durable user-visible text for async jobs should still land via the webhook handler writing to the product DB.
Async jobs (poll + socket)
Frontend pattern for long-running generation:
- Optimistic UI after
POSTcreates the job. - Poll
GET /jobs/:idwhilestatus === processing. - Optionally subscribe to a Socket.io event when the row updates.
- Stop when
statusiscompletedorerror.
Reconciliation on read can unblock stuck jobs. See Local development.