LocalStorageCheckpointer
A persistent Checkpointer for apps that run in a browser. It stores the checkpoints of each thread in the page's localStorage, so a paused run is still there after the page is reloaded or the browser is closed.
val config = GraphConfig(
threadId = "ticket-42",
checkpointer = LocalStorageCheckpointer(KotlinxStateSerializer<Ticket>()),
interruptBefore = setOf("pay"),
)What to know about localStorage:
It belongs to the origin of the page (scheme, host and port). Every page of that origin reads and writes the same entries, so give keyPrefix a name of your own.
A browser keeps about 5 MB for an origin. When it is full, save throws a LocalStorageException and the checkpoints that were stored before stay as they were. For that reason a thread keeps only its latest checkpoint unless you raise maxHistory.
The person using the browser can read and change it. Do not keep secrets in the state.
It is not available in a web worker, on Node.js, or when the browser blocks storage for the page. Every call then throws a LocalStorageException.
The entries have the format of CheckpointCodec, the same as the files of FileCheckpointer.
Parameters
converts the graph state to and from a string.
what the key of an entry starts with. The thread id follows it.
how many checkpoints a thread keeps, counted from the latest, for CompiledGraph.history and fork. The default keeps only the latest.
Throws
if maxHistory is not positive.