Genkit JS API reference
    Preparing search index...

    Interface SessionStore<S>

    Interface for persistent session snapshot storage.

    interface SessionStore<S = unknown> {
        getSnapshot(
            opts: GetSnapshotOptions,
        ): Promise<SessionSnapshot<S> | undefined>;
        onSnapshotStateChange?(
            snapshotId: string,
            callback: (snapshot: SessionSnapshot<S>) => void,
            options?: SessionStoreOptions,
        ): void | (() => void);
        saveSnapshot(
            snapshotId: string | undefined,
            mutator: SnapshotMutator<S>,
            options?: SessionStoreOptions,
        ): Promise<string | null>;
    }

    Type Parameters

    • S = unknown

    Implemented by

    Index

    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.