Live events (SSE)
MeroKit streams a node’s real-time context events over Server-Sent Events. The task-oriented walkthrough is the live events guide; this page is the API surface.
mero.events(contextIds:)
Section titled “mero.events(contextIds:)”nonisolated func events(contextIds: [String]) -> AsyncThrowingStream<ContextEvent, Error>Opens GET /sse and subscribes to the given context ids via
POST /sse/subscription, then yields a ContextEvent per emission. It is
nonisolated — callable without await — and reconnects automatically ~3s
after a drop (the node persists session subscriptions). Consume it with
for try await; cancel the enclosing Task to close the connection.
let task = Task { for try await event in mero.events(contextIds: [contextId]) { print(event.contextId, event.kind) await reload() }}// later:task.cancel() // closes the SSE streamContextEvent
Section titled “ContextEvent”public struct ContextEvent: Sendable { public let contextId: String public let kind: String // event discriminator, e.g. "ExecutionEvent" public let payload: JSONValue // raw event JSON}For a contract emission (kind == "ExecutionEvent") the encoded contract events
live under payload’s data.events[].data.
SseClient
Section titled “SseClient”mero.events(...) builds an SseClient for you; use it directly only if you
need to manage the connection yourself.
public final class SseClient: @unchecked Sendable { public init( baseURL: URL, token: @escaping @Sendable () async -> String?, session: URLSession = .shared ) public func events(contextIds: [String]) -> AsyncThrowingStream<ContextEvent, Error>}