pig/session_store

Durable session storage types for atomic agent-state transitions.

Types

The durable transcript and its current commit head.

pub type Session {
  Session(
    head: option.Option(String),
    messages: List(message.Message),
  )
}

Constructors

An atomic delta to append to a session transcript.

pub type SessionCommit {
  SessionCommit(
    id: String,
    parent: option.Option(String),
    messages: List(message.Message),
  )
}

Constructors

Errors returned while loading or committing a durable session.

pub type SessionError {
  Unavailable(message: String)
  Corrupt(message: String)
  ParentConflict(
    expected: option.Option(String),
    actual: option.Option(String),
  )
  InvalidCommit(message: String)
}

Constructors

  • Unavailable(message: String)

    The store could not be reached or complete an operation.

  • Corrupt(message: String)

    Stored data is corrupt, including a commit ID reused with different contents.

  • ParentConflict(
      expected: option.Option(String),
      actual: option.Option(String),
    )

    A commit’s expected parent does not match the session’s current head.

  • InvalidCommit(message: String)

    The proposed commit is invalid and cannot be stored.

A synchronous durable store bound to one logical session.

commit atomically persists the complete message delta and returns the resulting session. Recommitting an identical commit ID is idempotent.

pub type SessionStore {
  SessionStore(
    load: fn() -> Result(Session, SessionError),
    commit: fn(SessionCommit) -> Result(Session, SessionError),
  )
}

Constructors

Values

pub fn new_commit(
  parent: option.Option(String),
  messages: List(message.Message),
) -> SessionCommit

Create a commit with a fresh opaque ID, its expected parent, and its delta.

The ID is generated independently of the messages, so commits with identical contents still have distinct identities.

Search Document