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 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
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,
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.
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 async fn list_tasks(&self) -> FacadeResult<TaskListResult>
pub async fn list_tasks(&self) -> FacadeResult<TaskListResult>
Lists this session’s running tasks, background and foreground
(task/list).
Sourcepub async fn list_skills(&self) -> FacadeResult<SkillListResult>
pub async fn list_skills(&self) -> FacadeResult<SkillListResult>
Lists the skills a user can invoke in this session (skill/list).
Sourcepub async fn list_hooks(&self) -> FacadeResult<HookListResult>
pub async fn list_hooks(&self) -> FacadeResult<HookListResult>
Lists this session’s installed hooks, one row per handler and event
(hook/list).
Sourcepub async fn pause_workflow(
&self,
workflow_run_id: impl Into<String>,
) -> FacadeResult<WorkflowControlResult>
pub async fn pause_workflow( &self, workflow_run_id: impl Into<String>, ) -> FacadeResult<WorkflowControlResult>
Pauses a running workflow (workflow/pause). The result is admission
only: the pause shows on the workflow item’s later events. Pass
workflow_run_id exactly as the workflow item names it.
Sourcepub async fn resume_workflow(
&self,
workflow_run_id: impl Into<String>,
) -> FacadeResult<WorkflowResumeResult>
pub async fn resume_workflow( &self, workflow_run_id: impl Into<String>, ) -> FacadeResult<WorkflowResumeResult>
Resumes a paused workflow (workflow/resume). The host drives a turn
for it, a fresh one on an idle session or the running one otherwise,
and the result names that turn. Pass workflow_run_id exactly as the
workflow item names it.
Sourcepub async fn request_recap(&self) -> FacadeResult<RecapRequestResult>
pub async fn request_recap(&self) -> FacadeResult<RecapRequestResult>
Asks the host for a recap of this session (recap/request). The
result is admission only, never the recap itself.
Sourcepub async fn submit_feedback(
&self,
options: SubmitFeedbackOptions,
) -> FacadeResult<FeedbackSubmitResult>
pub async fn submit_feedback( &self, options: SubmitFeedbackOptions, ) -> FacadeResult<FeedbackSubmitResult>
Submits feedback about this session (feedback/submit). The host
serves it only on a connection granted the feedback capability.
MuseClient requests no capabilities yet,
so a real host refuses this call with capabilityRequired
(MuseError::Msp).
Sourcepub async fn open_side_chat(&self) -> FacadeResult<SessionSideChatResult>
pub async fn open_side_chat(&self) -> FacadeResult<SessionSideChatResult>
Opens a side chat from this session (session/sideChat) and returns
the opening the host served for the new side session: its session,
view cursor and history. It returns no Session for the side chat.
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. 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.