pub struct Session { /* private fields */ }Expand description
One server session on a client: it submits turns, answers approvals and questions, and keeps a fold of the events it applied. Clones share it.
Implementations§
Source§impl Session
impl Session
Sourcepub fn fold(&self) -> SessionFoldView<'_>
pub fn fold(&self) -> SessionFoldView<'_>
A read view of this session’s fold.
The fold holds every event this session applied, in order, plus the
items its resume history served. A resume seeds
items only: turns, approvals, user inputs and session state show the
events that arrive after it, and the turn still running at resume is
named by Session::opening. The fold is complete only while
SessionFoldView::is_current holds: after a lost event, or once this
session id is opened again on the same client, it stops applying and
stays not current, which SessionFoldView::is_stopped reports. A
re-opened fold still lists its questions until its event source fails.
Source§impl Session
impl Session
Sourcepub fn pending(&self) -> Vec<PendingTurn>
pub fn pending(&self) -> Vec<PendingTurn>
Lists, in submission order, every send_user_turn submission whose
outcome this session has not observed: no answer arrived, or the
answered turn’s terminal never did. Carry it to
Session::resolve_reconnect on the resumed session.
Unlike PendingCommandSet, which
settles an entry on its acknowledgement, this keeps an answered
submission until its turn’s terminal: an answer alone is not the outcome.
Sourcepub async fn resolve_reconnect(
&self,
carried: Vec<PendingTurn>,
) -> FacadeResult<Vec<ReconnectResolution>>
pub async fn resolve_reconnect( &self, carried: Vec<PendingTurn>, ) -> FacadeResult<Vec<ReconnectResolution>>
Resends carried submissions in order under their original command ids.
A written intake replays its first decision instead of running twice.
On a durable client, a server refusal fails only its own entry; after a
transport end, that entry and every later one stay in this session’s
Session::pending.
An entry from another session refuses the whole call before any write.
Once past those refusals, the call releases a resumed session’s hold on settled turns when it ends, whether it succeeds or is cancelled. A call refused for a foreign entry keeps the hold for the corrected call; a discarded session refuses every call and has already dropped its settled turns. After a resume with nothing to carry, call it with an empty list to release that hold.
Source§impl Session
impl Session
Sourcepub async fn send_user_turn(
&self,
options: SendUserTurnOptions,
) -> FacadeResult<Turn>
pub async fn send_user_turn( &self, options: SendUserTurnOptions, ) -> FacadeResult<Turn>
Sends one turn/start under a fresh command id and returns the turn
it started or queued, or the running turn it steered into. A call
refused at entry (session discarded, client closed, transport
already ended) records nothing, so Session::pending does not
list it. Once recorded, on a durable client only a server refusal
(MuseError::Msp) drops the
submission; any other failure, a TransportEnded included, keeps it
listed, since the server may have taken the turn. A call the caller
cancels keeps nothing.
A same-command retry (a command id minted again after a reconnect)
that the server answers with the turn the resume restates as
lastTurn returns once every notification received before that
answer has been handed to the session. Its Turn settles on that
turn’s terminal if this session applied it before the claim, as it
does one received before the answer unless a pending view-gap fill
holds that one back; otherwise it replays the turn’s held history and
settles as TurnOutcome::Ended.
Sourcepub async fn unqueue_turn(
&self,
turn_id: &str,
) -> FacadeResult<TurnUnqueueResult>
pub async fn unqueue_turn( &self, turn_id: &str, ) -> FacadeResult<TurnUnqueueResult>
Reclaims a queued turn before it launches (turn/unqueue).
The result is admission only: the queued Turn settles as
TurnOutcome::Unqueued when the
server’s turn/unqueued arrives. A turn that already launched is
refused with MuseError::Msp and keeps
running to its terminal. Pass turn_id exactly as the server minted it
(Turn::turn_id or snapshot queuedTurns): the echoed id is compared
byte for byte.
Source§impl Session
impl Session
Sourcepub async fn answer_user_input(
&self,
user_input_id: impl Into<String>,
answers: Vec<UserInputAnswer>,
) -> FacadeResult<UserInputAnswerResult>
pub async fn answer_user_input( &self, user_input_id: impl Into<String>, answers: Vec<UserInputAnswer>, ) -> FacadeResult<UserInputAnswerResult>
Answers a pending user-input question with userInput/answer.
The result is the server’s admission only; the question settles when
the server’s userInput/settled event arrives. Pass user_input_id
exactly as the server sent it (the userInputId of a
pending_user_inputs() entry of Session::fold): the echoed id is
compared byte for byte.
Source§impl Session
impl Session
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
The session id the server returned: the one the start or resume named, or one the server minted.
Sourcepub fn opening(&self) -> &SessionOpening
pub fn opening(&self) -> &SessionOpening
The result that opened this session. For a resume, history.mode can
name a snapshot mode while history.snapshot is None: the SDK
dropped a snapshot newer than it understands (see
Session::dropped_snapshot_schema_version).
Sourcepub fn dropped_snapshot_schema_version(&self) -> Option<u64>
pub fn dropped_snapshot_schema_version(&self) -> Option<u64>
The schemaVersion of a resume snapshot this SDK dropped because it is
newer than the session view this SDK understands, if it dropped one.
The resume then used none of the snapshot’s state, for the fold or the
turns, and the opening’s history.snapshot is None. Events after the
snapshot’s cursor still stream and apply, so the fold holds only what
came after it. To get the earlier history, upgrade
muse-code-sdk, or close this client and resume the session on a new one
asking for inline history (ResumeSessionOptions::history), which the
host serves when it fits its budget. Resuming the same session again on
this client is no remedy: the newer session’s fold stops.
Sourcepub fn is_discarded(&self) -> bool
pub fn is_discarded(&self) -> bool
True once the transport ended on a client that is not durable (an
ephemeral host, or a durability value this SDK does not know): the SDK
assumes nothing survives to resume, so its fallible verbs refuse with
MuseError::SessionDiscarded.
Sourcepub fn on_approval<Handler, HandlerFuture>(&self, handler: Handler)where
Handler: Fn(ApprovalRequestParams) -> HandlerFuture + Send + Sync + 'static,
HandlerFuture: Future<Output = ApprovalDecisionInput> + Send + 'static,
pub fn on_approval<Handler, HandlerFuture>(&self, handler: Handler)where
Handler: Fn(ApprovalRequestParams) -> HandlerFuture + Send + Sync + 'static,
HandlerFuture: Future<Output = ApprovalDecisionInput> + Send + 'static,
Replaces the approval handler for this session.
A request for a turn this session has already settled gets the offered
rejecting choice without reaching the handler, and an answer whose turn
settles while the handler decides is replaced the same way; with no
rejecting choice offered, nothing is sent, and a later stage that offers
one gets it. Approvals for a turn refused at the active-turn cap,
or for a turn this Session no longer remembers as settled (it
keeps only its most recent settled turns, and a resumed Session starts
with none), still reach the handler as usual.