yera.runtime.router
Route output-event blocks to target-specific handler instances.
The router owns handler lifetime. It creates one handler for each open block, passes every chunk with that block identity to the same instance, and closes the handler when the block's terminal event arrives. Parent identities bind nested handlers to their still-open container handler.
Symbols
EventRouter
Route ordered output events through block-scoped handlers.
The first ordinary event for a block creates and enters a handler. Later chunks with the same block identity reuse it, allowing streaming handlers to retain state. A terminal block event exits and removes that handler.
Prompt and lifecycle events are handled as one-shot boundaries and returned to the caller. Lifecycle events first close every open handler. If routing raises, all open handlers are unwound before the exception propagates.
Methods
EventRouter.__init__
__init__(
handlers: EventHandlerRegistry,
) → NoneInitialize a router with no open block handlers.
Parameters
Registry used to construct a handler for each event block.
EventRouter.process_stream
process_stream(
events: Iterator[OutputEvent],
) → OutputEventRoute events until the host must handle a prompt or lifecycle event.
Ordinary block chunks are forwarded to their block-scoped handlers. Terminal block events close their handlers without being rendered. A prompt event is rendered once and returned so the caller can collect input. A lifecycle event closes all open handlers, is rendered once, and is returned to the caller.
Parameters
Ordered output events from the app runtime.
Returns
The prompt or lifecycle event that paused routing.
Raises
If the iterator ends without a prompt or lifecycle boundary.