pub struct SessionState { /* private fields */ }Expand description
Key-value store with change tracking for session-attached structured data.
Tools receive an Arc<RwLock<SessionState>> during execution and can
read/write arbitrary typed values. Changes are tracked in a StateDelta
that is flushed at the end of each turn.
Implementations§
Source§impl SessionState
impl SessionState
Sourcepub fn with_data(data: HashMap<String, Value>) -> Self
pub fn with_data(data: HashMap<String, Value>) -> Self
Create session state pre-populated with the given data.
Pre-seeded data does NOT appear in the delta (baseline semantics).
Sourcepub fn get<T: DeserializeOwned>(&self, key: &str) -> Option<T>
pub fn get<T: DeserializeOwned>(&self, key: &str) -> Option<T>
Get a typed value by key. Returns None if key is missing or
deserialization fails.
Sourcepub fn get_raw(&self, key: &str) -> Option<&Value>
pub fn get_raw(&self, key: &str) -> Option<&Value>
Get the raw JSON value by key without deserialization.
Sourcepub fn set<T: Serialize>(&mut self, key: &str, value: T) -> Result<(), Error>
pub fn set<T: Serialize>(&mut self, key: &str, value: T) -> Result<(), Error>
Set a typed value. Serializes to Value and records in delta.
Returns an error if the value cannot be serialized to JSON.
Sourcepub fn remove(&mut self, key: &str)
pub fn remove(&mut self, key: &str)
Remove a key. Records removal in delta. No-op if key absent.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Remove all key-value pairs. Records all existing keys as removed in delta.
Sourcepub const fn delta(&self) -> &StateDelta
pub const fn delta(&self) -> &StateDelta
Read-only reference to pending delta.
Sourcepub fn flush_delta(&mut self) -> StateDelta
pub fn flush_delta(&mut self) -> StateDelta
Take the pending delta and reset tracking. Returns the delta.
Sourcepub fn snapshot(&self) -> Value
pub fn snapshot(&self) -> Value
Snapshot the materialized data as a JSON Value (for persistence).
Sourcepub fn restore_from_snapshot(snapshot: Value) -> Result<Self, Error>
pub fn restore_from_snapshot(snapshot: Value) -> Result<Self, Error>
Restore from a JSON Value snapshot. Returns a new SessionState with
empty delta.
Trait Implementations§
Source§impl Clone for SessionState
impl Clone for SessionState
Source§fn clone(&self) -> SessionState
fn clone(&self) -> SessionState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more