tempestweb.transports¶
The only seam separating Mode A from Mode B. PatchTransport is the Protocol both implement; above it the app's view() is identical, below it the JS client is the same. You rarely import from here — unless you are writing a transport of your own.
Guide with examples: Architecture · Wire contract.
tempestweb.transports ¶
tempestweb.transports — the single seam separating Mode A and Mode B.
Re-exports the transport contract and both modes' implementations. The wire
format every transport carries is documented in docs/contract.md and pinned
by the golden fixtures under tests/fixtures/.
- :class:
~tempestweb.transports.base.PatchTransport— the Protocol both modes satisfy. - :class:
~tempestweb.transports.wasm.WasmTransport— Mode A (pyodide.ffi). - :class:
~tempestweb.transports.websocket.WebSocketTransport— Mode B over WS. - :class:
~tempestweb.transports.sse.SSETransport— Mode B over SSE + HTTP POST. - Envelope encoders and the
Envelope/Patch/Eventtype aliases.
PatchTransport ¶
Bases: Protocol
Carries patches Python→client and events client→Python.
Implementations must be safe to drive from an asyncio event loop. The
reconciler hands fully-serialized patches to :meth:send_patches; user input
arrives through :meth:recv_event. Native capability proxying (Mode B) reuses
the same channel via :meth:send_native_call and the native_result events
delivered through :meth:recv_event.
Source code in tempestweb/transports/base.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
send_patches
async
¶
Deliver a coalesced batch of patches to the client for this tick.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
patches
|
list[Patch]
|
JSON-able patch dicts, in apply order. May be empty (no-op). |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the underlying channel is gone. |
Source code in tempestweb/transports/base.py
send_navigate
async
¶
Tell the client the app navigated to path (view → URL).
Sent when the app's top route changes so the client can pushState the
new URL. The reverse of the inbound navigate event. A transport whose
client never syncs the URL may treat this as a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The new top-route path. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the underlying channel is gone. |
Source code in tempestweb/transports/base.py
send_theme
async
¶
Tell the client which theme mode is resolved ("light"/"dark").
Sent on mount and on every change, so the base stylesheet can paint what no inline style covers. A transport whose client owns the theme itself (Mode A) may treat this as a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
The resolved mode — never |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the underlying channel is gone. |
Source code in tempestweb/transports/base.py
send_native_call
async
¶
Ask the client to run a native Web API capability (Mode B proxy).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
call_id
|
str
|
Correlation id matching the awaited |
required |
capability
|
str
|
Stable capability name (e.g. |
required |
args
|
dict[str, Any]
|
JSON-able arguments for the capability. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the underlying channel is gone. |
Source code in tempestweb/transports/base.py
send_native_subscribe
async
¶
Open a streaming subscription on the client (Mode B event channel).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_id
|
str
|
Correlation id every |
required |
capability
|
str
|
Stable streaming capability name (e.g. |
required |
args
|
dict[str, Any]
|
JSON-able subscription arguments. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the underlying channel is gone. |
Source code in tempestweb/transports/base.py
send_native_unsubscribe
async
¶
Cancel a streaming subscription on the client (Mode B event channel).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_id
|
str
|
The id of the subscription to close. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the underlying channel is gone. |
Source code in tempestweb/transports/base.py
recv_event
async
¶
Await the next user event from the client.
Inbound native_result and native_event envelopes are not returned
here; the transport routes them to the handlers registered with
:meth:on_native_result / :meth:on_native_event. This method yields only
user events ({"type", "key", "payload"}), so the session loop stays a
clean event pump.
Returns:
| Type | Description |
|---|---|
Event
|
A JSON-able user event dict. Blocks until one is available. |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the underlying channel is gone. |
Source code in tempestweb/transports/base.py
on_native_event ¶
Register the sink for inbound native_event envelopes (T-EV).
The transport invokes handler synchronously for each native_event
it receives, letting the session route it to the subscription keyed by
sub_id. A transport that never streams may ignore this.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
Callable[[NativeEvent], None]
|
Callback receiving the JSON-able |
required |
Source code in tempestweb/transports/base.py
on_native_result ¶
Register the sink for inbound native_result envelopes.
The transport invokes handler synchronously for each
native_result it receives, letting the session resolve the awaitable
keyed by call_id. A transport that never proxies native calls may
ignore this.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
Callable[[NativeResult], None]
|
Callback receiving the JSON-able |
required |
Source code in tempestweb/transports/base.py
TransportClosedError ¶
WasmTransport ¶
In-process :class:PatchTransport bridging Python and the JS client.
Patches flow out through the deliver callable; events flow in through
:meth:push_event, buffered on an :class:asyncio.Queue that
:meth:recv_event drains. Closing the transport unblocks any pending
:meth:recv_event with :class:TransportClosedError so the runtime's event
loop exits cleanly when the page tears down.
Attributes:
| Name | Type | Description |
|---|---|---|
closed |
bool
|
Whether the transport has been closed. |
Source code in tempestweb/transports/wasm.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
send_patches
async
¶
Deliver a coalesced batch of patches to the client for this tick.
An empty batch is a no-op (the reconciler emits [] when nothing
changed). The patch list is passed verbatim to the deliver sink; in
the browser, crossing pyodide.ffi converts the Python list of dicts
into a JS array of objects automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
patches
|
list[Patch]
|
JSON-able patch dicts, in apply order. May be empty. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the transport has been closed. |
Source code in tempestweb/transports/wasm.py
recv_event
async
¶
Await the next client event.
Blocks until :meth:push_event enqueues an event, or the transport is
closed.
Returns:
| Type | Description |
|---|---|
Event
|
The next JSON-able wire event |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the transport is (or becomes) closed. |
Source code in tempestweb/transports/wasm.py
push_event ¶
Enqueue a client event for the runtime to dispatch.
Called by the JS client across pyodide.ffi whenever a DOM event
fires (e.g. a button click). Safe to call from synchronous JS-driven
code: it only touches the queue, never awaits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
Event
|
The wire event |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the transport has been closed. |
Source code in tempestweb/transports/wasm.py
send_navigate
async
¶
Sync the client URL on app navigation — a no-op in Mode A.
In Mode A the Python runtime runs in the same browser tab, so view → URL
is wired directly by :class:~tempestweb.runtime.wasm.WasmRuntime's
on_navigate callback (it calls history.pushState over
pyodide.ffi), never through the transport. This method exists only to
satisfy the :class:~tempestweb.transports.base.PatchTransport Protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The new top-route path (ignored here). |
required |
Source code in tempestweb/transports/wasm.py
send_theme
async
¶
Mark the resolved theme mode — a no-op in Mode A.
In Mode A the Python runtime shares the tab, so
:class:~tempestweb.runtime.wasm.WasmRuntime writes the mode onto the
document itself over pyodide.ffi (its on_theme callback), never
through the transport. This exists to satisfy the
:class:~tempestweb.transports.base.PatchTransport Protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
The resolved theme mode (ignored here). |
required |
Source code in tempestweb/transports/wasm.py
send_native_call
async
¶
Proxy a native capability call — not used in Mode A.
In Mode A the Python runtime resolves native capabilities in-process
over pyodide.ffi (same browser tab), so they never travel through the
transport (see docs/contract.md). This method exists to satisfy the
:class:~tempestweb.transports.base.PatchTransport Protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
call_id
|
str
|
Correlation id matching the awaited |
required |
capability
|
str
|
Stable capability name. |
required |
args
|
dict[str, Any]
|
JSON-able arguments for the capability. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always — Mode A does not proxy native calls. |
Source code in tempestweb/transports/wasm.py
send_native_subscribe
async
¶
Open a streaming subscription — not used in Mode A.
In Mode A the event channel (T-EV) is served in-process by the
:class:~tempestweb.native.bridges.FFIBridge calling
client/native/index.js directly, so subscriptions never travel through
the transport. Exists to satisfy the PatchTransport Protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_id
|
str
|
Correlation id for the stream. |
required |
capability
|
str
|
Stable streaming capability name. |
required |
args
|
dict[str, Any]
|
JSON-able subscription arguments. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always — Mode A streams in-process via the FFI bridge. |
Source code in tempestweb/transports/wasm.py
send_native_unsubscribe
async
¶
Cancel a streaming subscription — not used in Mode A.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_id
|
str
|
The id of the subscription to close. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always — Mode A streams in-process via the FFI bridge. |
Source code in tempestweb/transports/wasm.py
on_native_result ¶
Register the sink for inbound native_result envelopes.
Stored for Protocol conformance; in Mode A no native_result is ever
routed through the transport (native calls resolve in-process), so the
handler is not invoked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
Callable[[NativeResult], None]
|
Callback receiving each JSON-able |
required |
Source code in tempestweb/transports/wasm.py
on_native_event ¶
Register the sink for inbound native_event envelopes.
Stored for Protocol conformance; in Mode A no native_event is ever
routed through the transport (the event channel resolves in-process), so
the handler is not invoked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
Callable[[NativeEvent], None]
|
Callback receiving each JSON-able |
required |
Source code in tempestweb/transports/wasm.py
close
async
¶
Tear down the transport, unblocking any pending :meth:recv_event.
Idempotent: closing an already-closed transport is a no-op.
Source code in tempestweb/transports/wasm.py
SSETransport ¶
:class:~tempestweb.transports.base.PatchTransport over SSE + HTTP POST.
Outbound envelopes are buffered (and assigned monotonic ids) so the SSE
stream can replay them after a reconnect. Inbound envelopes are pushed in by
the POST endpoint via :meth:feed_inbound.
Attributes:
| Name | Type | Description |
|---|---|---|
ping_interval |
float
|
Seconds between heartbeat |
Source code in tempestweb/transports/sse.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
send_patches
async
¶
Queue a patch batch as a patches envelope for the SSE stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
patches
|
list[Patch]
|
JSON-able patch dicts for one tick. Empty batches are skipped. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the transport has been closed. |
Source code in tempestweb/transports/sse.py
send_navigate
async
¶
Queue a navigate envelope for the SSE stream (view → URL).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The new top-route path the app navigated to. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the transport has been closed. |
Source code in tempestweb/transports/sse.py
send_theme
async
¶
Queue a theme envelope for the SSE stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
The resolved theme mode ( |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the transport has been closed. |
Source code in tempestweb/transports/sse.py
send_native_call
async
¶
Queue a native_call envelope for the SSE stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
call_id
|
str
|
Correlation id matching the awaited |
required |
capability
|
str
|
Stable capability name. |
required |
args
|
dict[str, Any]
|
JSON-able arguments for the capability. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the transport has been closed. |
Source code in tempestweb/transports/sse.py
send_native_subscribe
async
¶
Queue a native_subscribe envelope for the SSE stream (T-EV).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_id
|
str
|
Correlation id every |
required |
capability
|
str
|
Stable streaming capability name. |
required |
args
|
dict[str, Any]
|
JSON-able subscription arguments. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the transport has been closed. |
Source code in tempestweb/transports/sse.py
send_native_unsubscribe
async
¶
Queue a native_unsubscribe envelope for the SSE stream (T-EV).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_id
|
str
|
The id of the subscription to close. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the transport has been closed. |
Source code in tempestweb/transports/sse.py
missed_since ¶
Whether the replay buffer no longer covers everything after an id.
A reconnecting client asks to resume after the last tick it applied. When
the buffer has since dropped one of the ticks in between, resuming would
silently skip it — and patches are index-relative, so the client would
keep applying to a tree that no longer matches. The caller answers a
True here by pushing a full resync.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
last_event_id
|
int
|
The client's |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
evicted from the buffer. |
Source code in tempestweb/transports/sse.py
feed_inbound ¶
Route one inbound envelope POSTed by the client.
event envelopes are queued for :meth:recv_event; native_result
envelopes go to the registered handler. Bare event dicts (no kind)
are also accepted as events for forward compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
envelope
|
Envelope
|
The JSON-able envelope from the client's POST body. |
required |
Source code in tempestweb/transports/sse.py
recv_event
async
¶
Await the next user event POSTed by the client.
Returns:
| Type | Description |
|---|---|
Event
|
The next user event dict. |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the transport closed before an event. |
Source code in tempestweb/transports/sse.py
on_native_result ¶
Register the sink for inbound native_result envelopes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
Callable[[NativeResult], None]
|
Callback receiving each JSON-able |
required |
Source code in tempestweb/transports/sse.py
on_native_event ¶
Register the sink for inbound native_event envelopes (T-EV).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
Callable[[NativeEvent], None]
|
Callback receiving each JSON-able |
required |
Source code in tempestweb/transports/sse.py
stream
async
¶
Yield SSE-framed text for the text/event-stream response.
Walks the replay buffer with a cursor: every buffered envelope past
last_event_id is emitted in id order, then the stream waits for new
ones, emitting a named ping heartbeat whenever it idles for
ping_interval. A fresh connection (None) starts at the beginning
of the buffer, so envelopes queued before the stream opened — the initial
mount, most importantly — are not lost.
Opening a stream retires any earlier one on this transport: the previous cursor stops at its next wake-up. Two live streams would otherwise both be told about every envelope while the client that owns the session sees only its own, and (before the cursor rewrite) would have split one queue between them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
last_event_id
|
int | None
|
The client's |
None
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[str]
|
SSE wire chunks ( |
AsyncIterator[str]
|
blank line), ready to write to the response body. |
Source code in tempestweb/transports/sse.py
close
async
¶
Tear down the transport, unblocking the stream and event pump.
Source code in tempestweb/transports/sse.py
WebSocketTransport ¶
:class:~tempestweb.transports.base.PatchTransport over a WebSocket.
The caller is expected to have already accept-ed the socket. The
transport then runs until the peer disconnects or :meth:close is called.
Attributes:
| Name | Type | Description |
|---|---|---|
websocket |
WebSocket
|
The underlying Starlette WebSocket. |
Source code in tempestweb/transports/websocket.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
send_patches
async
¶
Send a patch batch as a patches envelope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
patches
|
list[Patch]
|
JSON-able patch dicts for one tick. Empty batches are skipped. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the socket is no longer connected. |
Source code in tempestweb/transports/websocket.py
send_navigate
async
¶
Send a navigate envelope so the client syncs its URL (view → URL).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The new top-route path the app navigated to. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the socket is no longer connected. |
Source code in tempestweb/transports/websocket.py
send_theme
async
¶
Send a theme envelope so the base sheet follows the app's theme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
The resolved theme mode ( |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the socket is no longer connected. |
Source code in tempestweb/transports/websocket.py
send_native_call
async
¶
Send a native_call envelope asking the client to run a capability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
call_id
|
str
|
Correlation id matching the awaited |
required |
capability
|
str
|
Stable capability name. |
required |
args
|
dict[str, Any]
|
JSON-able arguments for the capability. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the socket is no longer connected. |
Source code in tempestweb/transports/websocket.py
send_native_subscribe
async
¶
Send a native_subscribe envelope to open a stream on the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_id
|
str
|
Correlation id every |
required |
capability
|
str
|
Stable streaming capability name. |
required |
args
|
dict[str, Any]
|
JSON-able subscription arguments. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the socket is no longer connected. |
Source code in tempestweb/transports/websocket.py
send_native_unsubscribe
async
¶
Send a native_unsubscribe envelope to cancel a stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_id
|
str
|
The id of the subscription to close. |
required |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the socket is no longer connected. |
Source code in tempestweb/transports/websocket.py
recv_event
async
¶
Await the next user event from the client.
Starts the inbound demux on first call. native_result envelopes are
consumed by the demux, never returned here.
Returns:
| Type | Description |
|---|---|
Event
|
The next user event dict. |
Raises:
| Type | Description |
|---|---|
TransportClosedError
|
If the connection closed before an event. |
Source code in tempestweb/transports/websocket.py
on_native_result ¶
Register the sink for inbound native_result envelopes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
Callable[[NativeResult], None]
|
Callback receiving each JSON-able |
required |
Source code in tempestweb/transports/websocket.py
on_native_event ¶
Register the sink for inbound native_event envelopes (T-EV).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
Callable[[NativeEvent], None]
|
Callback receiving each JSON-able |
required |
Source code in tempestweb/transports/websocket.py
close
async
¶
Tear down the transport and close the WebSocket. Idempotent.
Source code in tempestweb/transports/websocket.py
encode_event ¶
Wrap a user event in an event envelope (client → server).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
Event
|
The JSON-able event dict. |
required |
Returns:
| Type | Description |
|---|---|
Envelope
|
The envelope |
Source code in tempestweb/transports/base.py
encode_native_call ¶
Wrap a native capability request in a native_call envelope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
call_id
|
str
|
Correlation id matching the eventual |
required |
capability
|
str
|
Stable capability name (e.g. |
required |
args
|
dict[str, Any]
|
JSON-able arguments for the capability. |
required |
Returns:
| Type | Description |
|---|---|
Envelope
|
The |
Source code in tempestweb/transports/base.py
encode_native_event ¶
Wrap one streaming event in a native_event envelope (client → server).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_id
|
str
|
The subscription id this event belongs to. |
required |
payload
|
dict[str, Any]
|
One of |
required |
Returns:
| Type | Description |
|---|---|
Envelope
|
The |
Source code in tempestweb/transports/base.py
encode_native_result ¶
encode_native_result(call_id: str, *, ok: bool, value: Any = None, error: str | None = None) -> Envelope
Wrap a native capability result in a native_result envelope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
call_id
|
str
|
Correlation id of the originating |
required |
ok
|
bool
|
Whether the capability succeeded. |
required |
value
|
Any
|
The JSON-able result value when |
None
|
error
|
str | None
|
The error string when |
None
|
Returns:
| Type | Description |
|---|---|
Envelope
|
The |
Source code in tempestweb/transports/base.py
encode_native_subscribe ¶
Wrap a streaming subscription request in a native_subscribe envelope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_id
|
str
|
Correlation id every event of this stream is tagged with. |
required |
capability
|
str
|
Stable streaming capability name (e.g. |
required |
args
|
dict[str, Any]
|
JSON-able arguments for the subscription. |
required |
Returns:
| Type | Description |
|---|---|
Envelope
|
The |
Source code in tempestweb/transports/base.py
encode_native_unsubscribe ¶
Wrap a subscription cancellation in a native_unsubscribe envelope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_id
|
str
|
The id of the subscription to close. |
required |
Returns:
| Type | Description |
|---|---|
Envelope
|
The |
Source code in tempestweb/transports/base.py
encode_navigate ¶
Wrap an imperative app navigation in a navigate envelope (server → client).
The reverse of the inbound navigate event: when the app's view
navigates (the top route changed), the server tells the client the new path
so it can sync the URL via history.pushState (back/forward + bookmarks
stay correct without a round-trip echoing the path back).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The new top-route path (e.g. |
required |
Returns:
| Type | Description |
|---|---|
Envelope
|
The envelope |
Source code in tempestweb/transports/base.py
encode_patches ¶
Wrap a patch batch in a patches envelope (server → client).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
patches
|
list[Patch]
|
JSON-able patch dicts for one coalesced tick. |
required |
Returns:
| Type | Description |
|---|---|
Envelope
|
The envelope |