Events
The Server-Sent Events stream behind the shelf's live status, streaming replies and new messages.
The shelf stays live through one Server-Sent Events (SSE) connection per page:
GET https://app.teamshelf.ai/w/<team key>/events?session=<token>The stream belongs to one visitor. Start a session first and pass its token as session — EventSource can’t send headers. You only receive that visitor’s events: their statuses, their messages and their bots’ live replies. Nothing from other visitors is sent.
Every event is sent with the SSE event name message, and its data is a JSON object with a type. A plain EventSource receives them in onmessage:
const source = new EventSource(`https://app.teamshelf.ai/w/ts_yxT2lwZi7337/events?session=${encodeURIComponent(session.token)}`);
source.onmessage = (e) => {
const event = JSON.parse(e.data);
switch (event.type) {
case "team": /* replace the whole team */ break;
case "status": /* update one bot's status */ break;
case "message": /* add or update a message */ break;
case "live": /* show streaming text / activity */ break;
case "live.end": /* the run finished */ break;
case "thread.cleared": /* empty a conversation */ break;
}
};Connecting
When a connection opens, the stream starts with a team event carrying the full team, then a live event for every bot that’s mid-reply, so a page that loads during a run catches up straight away.
Every 20 seconds the server sends a ping event with empty data to keep the connection open through proxies. onmessage doesn’t see it; ignore it if you listen for named events.
If the connection drops, EventSource reconnects on its own. Once the session expires, the server refuses the stream with 401; start a new session and open a new EventSource with the new token. Events sent while you were disconnected aren’t replayed — the team event on reconnect resets status, and the widget reloads the open conversation. Do the same if you build on the stream.
The server may also close the stream when the team’s settings change in the portal; the reconnect picks up the new configuration.
Event types
team
{ "type": "team", "team": { "teamName": "…", "primaryBotId": "…", "bots": [ … ], "sections": [ … ], "ungroupedBotIds": [ … ], "manageUrl": "…" } }The whole team, in the same shape as GET /team, with this visitor’s statuses. Sent on connect and whenever bots, sections, the primary bot or a bot’s look change. Replace your copy entirely.
status
{ "type": "status", "status": { "botId": "b_wh", "state": "working", "runStatus": "running", "line": "Checking pick logs…", "lineIsActivity": true, "quiet": false } }One bot’s live status for this visitor changed. See Status below.
message
{ "type": "message", "botId": "b_ops", "message": { "id": "m_57", "seq": 57, "role": "bot", "blocks": [{ "kind": "text", "text": "Warehouse says the order was picked late." }], "runId": "r_…", "createdAt": "…" } }A message was added to, or updated in, this visitor’s conversation with a bot. Merge by message.id: an update replaces the earlier copy. When a message arrives with the same runId as a streaming reply, it replaces the streamed text.
live
{ "type": "live", "botId": "b_ops", "runId": "r_…", "text": "Warehouse says the order", "activity": "Messaging Warehouse" }A reply in progress. text is the full streamed text so far — replace, don’t append. activity is the latest step the bot is taking, or null.
live.end
{ "type": "live.end", "botId": "b_ops", "runId": "r_…", "error": null }The run finished. Clear any streaming text for the bot. error is a message when the run failed, otherwise null or absent.
thread.cleared
{ "type": "thread.cleared", "botId": "b_ops" }This visitor’s conversation with the bot was emptied. Drop its messages. Other visitors’ conversations aren’t affected.
Status
| Field | Meaning |
|---|---|
state | working, attention, done or idle — see below. |
runStatus | The raw run status behind state, such as running, waiting_input or idle. For display or debugging. |
line | A one-line status, up to 80 characters: live activity while working, otherwise the bot’s last reply or its role. |
lineIsActivity | true when line is live activity. |
quiet | true when the bot has never replied. |
state | When |
|---|---|
working | A run is queued or in progress. |
attention | The bot is waiting for an answer (line reads “Waiting for your answer”), or its last run failed. |
done | Finished, with a reply this visitor hasn’t read. Cleared by POST /read. |
idle | Nothing new. |
Status and read state are per visitor. When one visitor reads a reply, done goes back to idle for them only.