vuer.rtc.types
Core types for the vuer.rtc CRDT-based data store.
This module provides Python equivalents to the TypeScript @vuer-ai/vuer-rtc types, enabling a consistent API across Python and JavaScript clients.
Key structures:
- VectorClock: Causal ordering via vector clocks
- Operation: Individual CRDT operations (node.insert, vector3.set, etc.)
- CRDTMessage: Message envelope containing batched operations
- SceneNode: Individual node in the scene graph
- SceneGraph: The computed state (map of nodes)
- JournalEntry: Committed message with ack/deleted status
- EditBuffer: Uncommitted operations awaiting commit
- Snapshot: Checkpoint for fast replay
- ClientState: Full client state container
create_vector_clock
Create an empty vector clock.
increment_clock
Return a new clock with the session's counter incremented.
merge_clocks
Merge two vector clocks, taking the max of each session's counter.
compare_clocks
Compare two vector clocks for causal ordering. Returns:
- "before" if clock1 happened before clock2
- "after" if clock1 happened after clock2
- "concurrent" if neither happened before the other
- "equal" if they are identical
OType
All supported operation types (dtype.operation format).
Operation
Base operation structure for all CRDT operations.
Attributes: key: Node key (e.g., 'cube-1', 'scene') otype: Operation type in dtype.operation format (e.g., 'vector3.add') path: Property path using dot notation (e.g., 'transform.position') value: Operation-specific value (type depends on otype)
Operation.to_dict
Serialize operation to dictionary.
Operation.from_dict
Deserialize operation from dictionary.
CRDTMessage
Message envelope for batched CRDT operations.
Attributes: id: Unique message identifier (format: sessionId:sequence) session_id: Session that created this message clock: Vector clock for causal ordering lamport_time: Lamport timestamp for total ordering timestamp: Wall-clock time in milliseconds since epoch ops: Array of operations in this batch
CRDTMessage.to_dict
Serialize message to dictionary.
CRDTMessage.from_dict
Deserialize message from dictionary.
generate_message_id
Generate a message ID in the format sessionId:sequence.
generate_uuid
Generate a UUID string.
SceneNode
Individual node in the scene graph.
Attributes: key: Unique key (human-friendly identifier) tag: Node type (Scene, Mesh, Group, etc.) name: Display name children: List of child node keys clock: Vector clock when created lamport_time: Lamport timestamp created_at: Creation timestamp (ms since epoch) updated_at: Last update timestamp (ms since epoch) deleted_at: Soft delete marker (tombstone), None if not deleted properties: Dynamic properties stored by path
SceneNode.get_property
Get a property value by dot-notation path.
SceneNode.set_property
Set a property value by dot-notation path.
SceneNode.is_deleted
Check if this node has been soft-deleted.
SceneNode.to_dict
Serialize node to dictionary.
SceneNode.from_dict
Deserialize node from dictionary.
SceneNode.copy
Create a deep copy of this node.
SceneGraph
The computed state of the scene as a flattened map of nodes.
Attributes: nodes: Dictionary mapping node keys to SceneNode instances root_key: Key of the root node (typically "scene")
SceneGraph.get_node
Get a node by key.
SceneGraph.set_node
Add or update a node in the graph.
SceneGraph.remove_node
Remove a node from the graph. Returns the removed node or None.
SceneGraph.has_node
Check if a node exists.
SceneGraph.get_children
Get all child nodes of a given node.
SceneGraph.to_dict
Serialize graph to dictionary.
SceneGraph.from_dict
Deserialize graph from dictionary.
SceneGraph.copy
Create a deep copy of this graph.
create_empty_graph
Create an empty scene graph with a root node.
Args: root_key: Key for the root node (default: "scene")
Returns: A new SceneGraph with an empty root Scene node
JournalEntry
A committed message with acknowledgment and deletion status.
Attributes: msg: The CRDT message ack: Whether the server has acknowledged this message deleted_at: Timestamp when this entry was undone (None if not undone)
JournalEntry.is_deleted
Check if this entry has been undone.
JournalEntry.to_dict
Serialize entry to dictionary.
JournalEntry.from_dict
Deserialize entry from dictionary.
EditBuffer
Buffer for uncommitted operations awaiting commit.
Attributes: ops: List of pending operations start_graph: Graph state when edits started (for cancel/revert)
EditBuffer.is_empty
Check if there are no pending edits.
EditBuffer.add
Add an operation to the buffer.
EditBuffer.clear
Clear the buffer and return the operations.
EditBuffer.to_dict
Serialize buffer to dictionary.
EditBuffer.from_dict
Deserialize buffer from dictionary.
Snapshot
Checkpoint for fast replay.
Attributes: graph: Scene graph state at this checkpoint vector_clock: Vector clock value at checkpoint lamport_time: Max lamport time baked into snapshot journal_index: Number of journal entries baked into snapshot
Snapshot.to_dict
Serialize snapshot to dictionary.
Snapshot.from_dict
Deserialize snapshot from dictionary.
create_initial_snapshot
Create an initial snapshot with an empty or provided graph.
ClientState
Full client state container for the CRDT data store.
Attributes: session_id: Unique identifier for this client session graph: Current computed state journal: List of committed messages with ack status edits: Uncommitted operations awaiting commit snapshot: Checkpoint for fast replay lamport_time: Current Lamport timestamp vector_clock: Current vector clock
ClientState.to_dict
Serialize state to dictionary.
ClientState.from_dict
Deserialize state from dictionary.
create_initial_state
Create an initial client state.
Args: session_id: Unique identifier for this session snapshot: Optional snapshot to restore from
Returns: A new ClientState initialized with the given session ID