Store¶
ConversationStore ¶
Bases: ABC
Persistent storage for rooms, events, bindings, and participants.
Implement this ABC to plug in any storage backend (SQL, Redis, etc.).
The library ships with InMemoryStore for development and testing.
delete_room
abstractmethod
async
¶
Delete a room. Returns True if the room existed.
find_rooms
abstractmethod
async
¶
Find rooms matching the given filters.
find_latest_room
abstractmethod
async
¶
Find the most recent room for a participant.
find_room_id_by_channel
abstractmethod
async
¶
Find a room ID that has a binding for the given channel_id.
update_event
abstractmethod
async
¶
Update an existing event (e.g., mark as edited or deleted).
list_events
abstractmethod
async
¶
List events in a room with pagination and optional visibility filter.
check_idempotency
abstractmethod
async
¶
Check if an idempotency key has been seen. Returns True if duplicate.
get_event_count
abstractmethod
async
¶
Return the total number of events in a room.
add_event_auto_index
async
¶
Atomically assign the next index and store the event.
The default implementation reads the count and writes in two steps. Backends should override this with an atomic implementation (e.g. a single SQL transaction) to prevent race conditions on the index.
get_binding
abstractmethod
async
¶
Get a channel binding, or None if not attached.
remove_binding
abstractmethod
async
¶
Detach a channel from a room. Returns True if it was attached.
get_participant
abstractmethod
async
¶
Get a participant by ID within a room.
list_participants
abstractmethod
async
¶
List all participants in a room.
resolve_identity
abstractmethod
async
¶
Look up an identity by channel type and address.
link_address
abstractmethod
async
¶
Link a channel address to an identity.
list_tasks
abstractmethod
async
¶
List tasks for a room, optionally filtered by status.
list_observations
abstractmethod
async
¶
List all observations for a room.
mark_read
abstractmethod
async
¶
Mark an event as read for a channel.
mark_all_read
abstractmethod
async
¶
Mark all events as read for a channel.
get_unread_count
abstractmethod
async
¶
Return the number of unread events for a channel in a room.
InMemoryStore ¶
Bases: ConversationStore
Dict-based in-memory store for development and testing.
add_event_auto_index
async
¶
Atomically assign index = len(room_events) and append.
PostgresStore ¶
Bases: ConversationStore
PostgreSQL-backed conversation store using asyncpg.
init
async
¶
Create the connection pool (if needed) and ensure schema exists.
add_event_auto_index
async
¶
Atomically assign the next index and store the event in one transaction.
Uses SELECT ... FOR UPDATE on the rooms table to serialise
concurrent index assignments for the same room, preventing
duplicate indices under READ COMMITTED isolation.