Skip to content
Developer Preview

Session

One conversation with the agent.

A session folds every server event into readable state — items, turns, session facts, pending approvals — and submits your side of the exchange. Get one from MuseClient.startSession or resumeSession, then sendUserTurn to talk, turn to follow a turn’s items to its outcome, and onApproval to answer permission requests.

Property Type Stability Presence Description
opening SessionOpening | undefined required See SessionOpening. Absent when the caller built this directly.
sessionId string required
durability SessionDurabilityProfile required
fold SessionFoldView required Read-only; events enter through apply so turn routing cannot be skipped.
pending PendingCommandView<I> required The set, minus the three mutators Session drives itself.
Method Signature Stability Description
constructor new Session(options: SessionOptions)
apply apply(event: ViewEvent): SessionApplyOutcome<I> Fold one view event, then fan it out to the turn handles that want it.
apply apply(event: object): SessionApplyOutcome<I> Fold one view event, then fan it out to the turn handles that want it.
hostExited hostExited(exit: HostDeathNotification): HostDeathDischarge<I> A host process exited. Classify it, and discharge if the profile demands it.
onApproval onApproval(handler: ApprovalHandler): void Answer approvals with handler. See ApprovalRouter.
onApprovalError onApprovalError(handler: ApprovalFailureHandler): void Observe round trips that did not complete. See ApprovalFailure.
onGapError onGapError(handler: GapFillFailureHandler): void Observe fills that did not complete. See MuseGapFillError.
replayAnswered replayAnswered(commandId: string, answer: ReplayAnswer): "held" | PendingRetirement<I> Feed a consumer-driven replay’s answer through the live settlement rules. Wrapped for the same replay-memory bookkeeping as stopRetrying; "held" means the answer settled nothing and the entry stays.
resolveReconnect resolveReconnect(): Promise<readonly PendingRetirement<I>[]> Resolve a reconnect with NO snapshot (history.mode: "none", the default cursor-resume path). Reconnect itself is the trigger: replay each acked entry once, resubmit each unacked entry’s SAME commandId once.
resolveSnapshotJoin resolveSnapshotJoin(facts: SnapshotJoinFacts): Promise<readonly PendingRetirement<I>[]> Resolve a snapshot join by performing the I/O its plan demands: same-commandId resubmits FIRST, then the replays, then the reclaimed-signature verdict.
sendUserTurn sendUserTurn(options: SendUserTurnOptions<I>): Promise<Turn> Submit a user turn and hand back THIS session’s handle for the turn the ack named.
stopRetrying stopRetrying(commandId: string): PendingRetirement<I> | undefined Stop the retry loop for one entry and take its input back (“Abandoned”).
turn turn(turnId: string): Turn The handle for a turn, created on first mention from either side. A turn the fold has already settled returns its settled handle, so a wait registered late resolves instead of hanging on an event that has passed.
Source

clients/sdk-ts/src/facade/session.ts:277

{
"kind": "Class",
"canonicalPath": "Session"
}