yera.ui.sessions_store.base

Module for managing and persisting Yera app session data.

Symbols

class BaseSessionStore — Abstract base class for storing and retrieving chat sessions.
class SessionRecord — Represents a record of a user session, including its metadata.
class SessionRecordUpdate — Metadata changes to apply while recording a session event.

BaseSessionStore

Inherits: ABC
Subclasses: SQLiteSessionStore

Abstract base class for storing and retrieving chat sessions.

Methods

create — Creates a new session in the store.
has — Checks if a session exists in the store.
has_events — Checks whether a session already has any recorded events.
get — Retrieves a session record by its ID.
list — Lists all stored session records.
update — Updates the metadata of an existing session.
append_event — Appends an event to a session's history.
read_events — Reads all events associated with a session.
__enter__ — Enter the session store context.
__exit__ — Exit the session store context.

BaseSessionStore.create

create(
    app_id: str,
) → SessionRecord

Creates a new session in the store.

Parameters

app_id
type: str

The ID of the application associated with the session.

Returns

type: SessionRecord

The created SessionRecord.

BaseSessionStore.has

has(
    session_id: str,
) → bool

Checks if a session exists in the store.

Parameters

session_id
type: str

The unique identifier of the session.

Returns

type: bool

True if the session exists, False otherwise.

BaseSessionStore.has_events

has_events(
    session_id: str,
) → bool

Checks whether a session already has any recorded events.

Used to distinguish a brand-new session (safe to launch live) from a historical one (should only ever be replayed).

Parameters

session_id
type: str

The unique identifier of the session.

Returns

type: bool

True if the session has one or more recorded events.

BaseSessionStore.get

get(
    session_id: str,
) → SessionRecord

Retrieves a session record by its ID.

Parameters

session_id
type: str

The unique identifier of the session.

Returns

type: SessionRecord

The requested SessionRecord.

BaseSessionStore.list

list() → list[SessionRecord]

Lists all stored session records.

Returns

type: list[SessionRecord]

A list of all SessionRecords.

BaseSessionStore.update

update(
    session_id: str,
    title: str | None = None,
    status: SessionStatus | None = None,
) → None

Updates the metadata of an existing session.

Parameters

session_id
type: str

The unique identifier of the session.

title
type: str | None = None

An optional new title for the session.

status
type: SessionStatus | None = None

An optional new lifecycle status for the session.

BaseSessionStore.append_event

append_event(
    session_id: str,
    event: OutputEvent | InputEvent,
    update: SessionRecordUpdate | None = None,
) → None

Appends an event to a session's history.

Parameters

session_id
type: str

The unique identifier of the session.

event
type: OutputEvent | InputEvent

The input or output event to store.

update
type: SessionRecordUpdate | None = None

Optional session metadata changes to apply atomically.

BaseSessionStore.read_events

read_events(
    session_id: str,
) → Iterator[OutputEvent | InputEvent]

Reads all events associated with a session.

Parameters

session_id
type: str

The unique identifier of the session.

Returns

type: Iterator[OutputEvent | InputEvent]

An iterator over the session's events.

BaseSessionStore.__enter__

__enter__() → Self

Enter the session store context.

BaseSessionStore.__exit__

__exit__(
    exc_type: type[BaseException] | None,
    exc_val: BaseException | None,
    exc_tb: TracebackType | None,
) → None

Exit the session store context.

SessionRecord

Inherits: BaseModel

Represents a record of a user session, including its metadata.

Methods

new — Creates a new session record.

SessionRecord.new

new(
    app_id: str,
    title: str | None = None,
) → SessionRecord

Creates a new session record.

Parameters

app_id
type: str

The ID of the application associated with the session.

title
type: str | None = None

optional title to assign to the session. Defaults to new chat.

Returns

type: SessionRecord

A new SessionRecord instance.

SessionRecordUpdate

Inherits: BaseModel

Metadata changes to apply while recording a session event.