Session<State> class
final
State manager for a session turn, tracking messages, custom state, and artifacts.
Custom state is stored internally as plain JSON (mirroring the JS plain
object), and the typed State layer is a thin veneer over it: getCustom
parses the JSON into a State, and updateCustom serializes the returned
State back to JSON before storing. When a stateSchema is supplied,
State is a real parsed type (e.g. a schemantic-generated class); without
one State defaults to dynamic and the value is a bare view over the JSON.
Keeping the internal representation as plain JSON is deliberate: the
customChanged -> customPatch streaming logic diffs raw JSON, so the typed
API never changes what is stored on the wire.
- Annotations
-
- @experimental
Constructors
-
Session(SessionState initialState, {SchemanticType<
State> ? stateSchema}) -
Builds a session from
initialState, assigning a sessionId if absent.
Properties
Methods
-
addArtifacts(
List< Artifact> artifacts) → void - Adds artifacts to the session, deduplicating items by name.
-
addMessages(
List< Message> messages) → void - Appends a list of messages to the session.
-
getArtifacts(
) → List< Artifact> - Retrieves the list of artifacts generated during the session.
-
getCustom(
) → State? -
Retrieves the custom state of the session as a typed
State. -
getMessages(
) → List< Message> - Retrieves all messages associated with the session.
-
getState(
) → SessionState - Returns a deep copy of the current session state.
-
getVersion(
) → int - Gets the current mutation version of the session state.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
on(
String event, void callback(Object? arg)) → void Function() -
Subscribes to a session
event('customChanged','artifactAdded','artifactUpdated'). Returns an unsubscribe function. -
run<
O> (O fn()) → O - Runs the provided function inside the session's context.
-
setMessages(
List< Message> messages) → void - Overwrites the session messages.
-
toString(
) → String -
A string representation of this object.
inherited
-
updateCustom(
State? fn(State? custom)) → void - Updates the custom state of the session using a mutator function.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited