yera.dev.services.event_converter

Event conversion utilities for converting between backend and frontend formats.

Symbols

def json_to_output_event — Reconstruct an OutputEvent from a parsed SSE JSON dict.
def output_event_to_json — Convert an OutputEvent to frontend JSON format.
def user_interaction_to_input_event — Convert a UserInteraction dict to InputEvent format.

json_to_output_event

json_to_output_event(
    d: dict,
) → OutputEvent

Reconstruct an OutputEvent from a parsed SSE JSON dict.

Reverse of output_event_to_json: converts the wire JSON format back into a domain OutputEvent with the correct BlockData subtype.

Parameters

d
type: dict

Parsed JSON dict with keys event_class, block_type, block_id, data, timestamp, chunk_id, app, and parent_block_id.

Returns

type: OutputEvent

Fully populated OutputEvent ready for console rendering.

output_event_to_json

output_event_to_json(
    event: OutputEvent,
) → dict

Convert an OutputEvent to frontend JSON format.

Parameters

event
type: OutputEvent

OutputEvent from the app execution

Returns

type: dict

Dictionary matching the frontend AppMessage interface: { "event_class": "content" | "prompt" | "progress" | "structure" | "control" | "context" | "lifecycle", "block_type": str, "block_id": str, "data": dict, "timestamp": str (ISO format), "chunk_id": int, "app": { "name": str, "instance_id": int }, "parent_block_id": str | None }

user_interaction_to_input_event

user_interaction_to_input_event(
    interaction: dict,
) → InputEvent

Convert a UserInteraction dict to InputEvent format.

Parameters

interaction
type: dict

UserInteraction dictionary with: - blockId: str - value: Any - blockType: str

Returns

type: InputEvent

InputEvent for pushing to EventStream