@event handlers for each one.
Declaring parameters
Store client-facing parameters as instance attributes. Initialize them in your@connected handler so each client starts with a clean slate:
run():
Explicit event handlers
Every parameter the client can change needs an explicit@event handler.
{"type": "set_prompt", "data": {"prompt": "a dark forest"}} and the runtime calls your method.
Validation with InputField
InputField defines constraints that the runtime enforces automatically. Invalid values from clients are silently rejected.
@event handler parameters, and the runtime enforces them before your handler is called.
Resetting between clients
If you need to reset your model’s state between clients, use the connection hooks:@connected, attributes may carry over from the previous session.
Scheduling
run() and @event handlers share the same event loop, so handlers can run at any await in your loop. If you need consistent values across a forward pass, snapshot them:
Derived state
For expensive derived values (embeddings, cached tensors), compute them in the event handler and store them alongside the raw value:self._embedding in run() instead of re-encoding every frame.
Next
Events & Messages
Custom events, lifecycle hooks, and outbound messages.
Video Input
Read webcam frames with manual buffer management.