Class SnapshotStore

java.lang.Object
io.agentscope.spring.boot.admin.snapshot.SnapshotStore

public final class SnapshotStore extends Object
In-memory undo/redo stacks per session.

Stacks store the serialized JSON form of AgentState — deserialization happens at restore time. A bounded per-session capacity (default 20) caps memory use; the oldest snapshot is dropped when the limit is hit.

This is a deliberately simple, single-node store. Cluster-aware deployments should swap in a Redis-backed implementation by exposing a custom SnapshotStore bean.

  • Field Details

    • DEFAULT_CAPACITY

      public static final int DEFAULT_CAPACITY
      Default per-session undo depth.
      See Also:
  • Constructor Details

    • SnapshotStore

      public SnapshotStore()
    • SnapshotStore

      public SnapshotStore(int capacityPerSession)
  • Method Details

    • push

      public void push(String sessionId, String json)
      Push a new snapshot for sessionId. Clears the redo stack — this is a fresh edit.
    • undo

      public Optional<String> undo(String sessionId, String currentJson)
      Pop the most recent undo snapshot, and atomically push currentJson onto the redo stack so a subsequent redo(String, String) can restore it.
      Returns:
      the JSON of the snapshot to restore, or empty if none available
    • redo

      public Optional<String> redo(String sessionId, String currentJson)
      Pop the most recent redo snapshot, and push currentJson onto the undo stack so a subsequent undo(String, String) can revert it.
    • undoDepth

      public int undoDepth(String sessionId)
    • redoDepth

      public int redoDepth(String sessionId)
    • clear

      public void clear(String sessionId)