Genkit JS API reference
    Preparing search index...

    Class InMemorySessionStore<S>

    In-memory implementation of persistent Session Store.

    Type Parameters

    • S = unknown

    Implements

    Index

    Constructors

    • Type Parameters

      • S = unknown

      Parameters

      • Optionaloptions: { rejectBranchingSessions?: boolean }
        • OptionalrejectBranchingSessions?: boolean

          When true, a sessionId lookup that resolves to a branched history (more than one leaf) throws FAILED_PRECONDITION instead of returning the latest leaf. Defaults to false; opt in (e.g. in dev) to surface accidental branching early.

      Returns InMemorySessionStore<S>

    Methods

    • Loads a snapshot either by its snapshotId or by sessionId.

      See GetSnapshotOptions for the lookup semantics (exactly one of snapshotId / sessionId; sessionId resolves to the session's latest leaf snapshot, optionally rejecting branching histories).

      Parameters

      • opts: GetSnapshotOptions

      Returns Promise<SessionSnapshot<S> | undefined>

    • Atomically reads the current snapshot (if snapshotId is provided), passes it to mutator, and persists the result.

      • When snapshotId is provided the store reads the existing snapshot and passes it to the mutator. The mutator can inspect the current state (e.g. to check for concurrent status changes) and return the updated snapshot to save, or null to skip the write.
      • When snapshotId is undefined the store passes undefined to the mutator (signaling a new snapshot). The store assigns a new identifier.

      Implementations should ensure the read→mutate→write cycle is atomic to prevent race conditions (e.g. a "done" write overwriting a concurrent "aborted" status).

      The mutator can:

      • Return a snapshot to save it.
      • Return null to silently skip the write.
      • Throw to abort with an error.

      Parameters

      Returns Promise<string | null>

      The snapshotId that was used, or null when the mutator returned null.