yera.ui.sessions_store.sqlite_store
Persist browser sessions and event histories in a local SQLite database.
The store uses WAL mode and one connection per calling thread. Each operation commits on success and rolls back on failure, while server shutdown closes every connection opened during the store context.
Symbols
SQLiteSessionStore
BaseSessionStorePersist session metadata and ordered events in SQLite.
The database lives in Yera's home directory unless another root is supplied. Entering the store creates or migrates its schema and enables WAL mode. Runtime and HTTP threads receive separate connections, while a shared registry lets context exit close them all.
Event insertion and its optional metadata update occur in one transaction. This keeps transcript history, titles, timestamps, and lifecycle status consistent.
Methods
SQLiteSessionStore.__init__
__init__(
root_path: Path | None = None,
timeout: float = 5.0,
) → NoneConfigure a closed SQLite session store.
No directory, database, or connection is created until the store enters its context.
Parameters
Directory containing sessions.db, or None to use
Yera's home directory.
Seconds a connection waits for a database lock before failing.
SQLiteSessionStore.create
create(
app_id: str,
) → SessionRecordCreate a new session record for app_id.
Parameters
Identifier of the application that owns the session.
Returns
The newly created :class:SessionRecord.
SQLiteSessionStore.has
has(
session_id: str,
) → boolReturn True if a session with session_id exists in the store.
Parameters
The UUID of the session to look up.
Returns
True if the session is present, otherwise False.
SQLiteSessionStore.has_events
has_events(
session_id: str,
) → boolCheck whether any events are stored for session_id.
Parameters
The UUID of the session whose event log is queried.
Returns
True if at least one event exists, otherwise False.
SQLiteSessionStore.get
get(
session_id: str,
) → SessionRecordRetrieve the :class:SessionRecord for session_id.
Parameters
The UUID of the desired session.
Returns
The corresponding :class:SessionRecord.
Raises
If no such session exists.
SQLiteSessionStore.list
list() → list[SessionRecord]Return all stored sessions ordered by most recent update time.
Returns
A list of :class:SessionRecord objects sorted descending by updated_at.
SQLiteSessionStore.update
update(
session_id: str,
title: str | None = None,
status: SessionStatus | None = None,
) → NoneUpdate metadata for session_id.
Parameters
The UUID of the session to modify.
Optional new title. If omitted, only the updated_at timestamp is refreshed.
An optional new lifecycle status for the session.
Raises
If the specified session does not exist.
SQLiteSessionStore.append_event
append_event(
session_id: str,
event: OutputEvent | InputEvent,
update: SessionRecordUpdate | None = None,
) → NoneAppend an event and optional metadata update in one transaction.
The event is serialized with its concrete model name so it can be reconstructed as typed input or output during replay. The session's update timestamp is always refreshed; supplied title and status values are committed alongside the event.
Parameters
Session receiving the event.
Typed runtime input or output event to serialize.
Optional title or lifecycle change committed with the event.
Raises
If the session does not exist.
SQLiteSessionStore.read_records
read_records(
session_id: str,
) → Iterator[StoredEventRecord]Read timestamped events in their original append order.
Rows are fetched while the store connection is open, then deserialized lazily by the returned iterator. The database creation timestamp is retained as the authoritative persistence time for each event.
Parameters
Session whose event history is read.
Returns
An iterator of timestamped input and output event records.
Raises
If the session does not exist. This is raised before the iterator is returned.
If iteration encounters an unknown stored event type or an invalid persistence timestamp.
SQLiteSessionStore.__enter__
__enter__() → SelfCreate or migrate the database and open the store for operations.
Returns
The initialized, open store.
SQLiteSessionStore.__exit__
__exit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) → NoneClose every thread-local connection and mark the store closed.
Parameters
Type of exception leaving the context, if any.
Exception instance leaving the context, if any.
Traceback associated with the exception, if any.