Skip to main content

Session

Struct Session 

Source
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

Source

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

Source

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.

Source

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 the host can still read replays its first decision instead of running twice; a host that cannot read it takes the resend as new and may run it again (see PendingTurn::turn_id). 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

Source

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, unless the session’s event source has failed, or it keeps no route for that turn and already follows as many turns as it can, when the Turn fails instead.

Source

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

Source

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

Source

pub fn session_id(&self) -> &str

The session id the server returned: the one the start or resume named, or one the server minted.

Source

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).

Source

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.

Source

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.

Source

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. A Turn that Session::send_user_turn or Session::resolve_reconnect returned already failed, because the session was already tracking as many active turns as it can, counts as settled until a later call returns a live turn for it. Approvals 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.

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.