Events stream
| Method | Path | Auth |
|---|---|---|
GET | /events | bearer |
Stream Server-Sent Events yang mirror event hub logger bot
line-by-line. Setiap logger.state(...), transport TCP/HTTP message,
dan hasil dispatcher keluar di sini sebagai JSON.
Connect
curl -N http://localhost:8090/events -H 'authorization: Bearer <token>'
Koneksi tetep buka indefinite. SSE auto-reconnect built-in di setiap
EventSource browser; buat caller curl mentah, exit + buka ulang
stream pas mati.
Format frame
Server-Sent Events standar. Setiap frame blok data: {…}\n\n. Body-nya
JSON.
event: log
data: {"timestamp_ms":1778201531241,"level":"info","scope":"auth_client","session_id":"bot-1","transport":"http","direction":"outgoing","message":"POST https://11ef5c.playfabapi.com/Client/LoginWithEmailAddress?sdk=UnitySDK-2.178.230929 body={...}"}
event: log
data: {"timestamp_ms":1778201531870,"level":"info","scope":"tcp","session_id":"bot-1","transport":"tcp","direction":"outgoing","message":"VChk {ID=\"VChk\" OS=\"Android\" OSt=2}"}
event: session
data: {"snapshot":{"id":"bot-1","status":"in_world",...}}
Dua flavor event: di-emit:
event: log— setiap line logger.levelituinfo/warn/error/state.scopeidentifikasi source-nya (auth_client,tcp,bot,tutorial,seraph, …).event: session— snapshot periodik state bot, shape sama denganGET /api/bots/{id}. Di-emit di setiap state transition.
Reference field
Payload log
| Field | Type | Arti |
|---|---|---|
timestamp_ms | i64 | Unix epoch ms pas event nyala. |
level | string | info / warn / error / state. |
scope | string | Module source (mis. auth_client, tcp, bot). |
session_id | string|null | Bot id kalau event-nya bot-scoped. |
transport | string|null | tcp / http buat event wire. |
direction | string|null | outgoing / incoming buat event wire. |
message | string | Line display yang udah ke-format. |
Payload session
{ "snapshot": { ...BotSnapshot } } — lihat
GET /api/bots/{id} buat setiap field.
Kenapa SSE
SSE itu satu arah (server → client) — cocok banget sama use case-nya.
Dashboard mau live tail apa yang lagi bot lakuin, gak ada pesan
client→server di socket ini. Auto-reconnect built-in di setiap
EventSource browser, gak butuh library.
Buat komunikasi dua arah ala WebSocket, pake raw dispatch
lewat POST /invoke.
Pakai dari browser
Browser gak ngijinin EventSource set custom header, jadi pake
form query-string buat token-nya:
const es = new EventSource(
`http://localhost:8090/events?token=${encodeURIComponent(token)}`,
);
es.addEventListener("log", (e) => {
const ev = JSON.parse(e.data);
console.log(`[${ev.scope}] ${ev.message}`);
});
es.addEventListener("session", (e) => {
const { snapshot } = JSON.parse(e.data);
ui.updateBotRow(snapshot);
});
// Default `message` event nyala buat frame yang gak ber-tipe; keep
// sebagai fallback supaya kalo ada event kind baru gak silently
// dropped.
es.onmessage = (e) => console.debug("untyped event:", e.data);