muse_code_sdk/msp/method/lifecycle/session_resume.rs
1// @generated from the MSP stable schema and protocol sources; do not edit by hand.
2
3use super::session_mcp::SessionConfig;
4use crate::msp::method::session::Session;
5use crate::msp::method::snapshot::ViewSnapshot;
6use crate::msp::view::event::TurnError;
7use crate::msp::view::event::TurnTerminal;
8use crate::msp::view::item::Item;
9use serde::Deserialize;
10use serde::Serialize;
11
12mod catch_all;
13
14/// `session/resume` params.
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct SessionResumeParams {
18 /// The idempotency handle (UUIDv7). A resume that loads a session writes a
19 /// durable `SessionResumed` record.
20 pub command_id: String,
21 /// Cold-resume replacement choice; omission preserves the retained choice.
22 /// A warm attach rejects a different or unestablished choice as invalidParams.
23 /// Explicit null is invalid.
24 #[serde(
25 default,
26 deserialize_with = "super::deserialize_non_null_optional",
27 skip_serializing_if = "Option::is_none"
28 )]
29 pub recovery_mode: Option<super::RecoveryMode>,
30 /// The session to load.
31 pub session_id: String,
32 /// A view cursor previously observed by this client — or an observed
33 /// `summarizedThrough` compaction anchor. When it names an event the server
34 /// still holds, the server returns only the suffix and `history.mode` is
35 /// `none`. A cursor the server minted that names no event yet, such as the
36 /// empty start cursor of a session that had no events, is treated as no
37 /// cursor: the server serves what a resume without a cursor would. A cursor
38 /// older than the earliest event the server still holds gets a snapshot, or
39 /// `-32040` `viewTruncated` when none fits. A cursor this session's view
40 /// never minted is refused with `-32011` `notFound`, reason
41 /// `missingAnchor`, and a compaction anchor naming a boundary the server
42 /// has pruned is refused with `-32042` `boundaryPruned`. Omitted and
43 /// explicit `null` both mean "no cursor".
44 #[serde(skip_serializing_if = "Option::is_none")]
45 pub cursor: Option<String>,
46 /// Return only session metadata and live resume state; page history
47 /// separately with `view/page`. Default `false`.
48 #[serde(skip_serializing_if = "Option::is_none")]
49 pub exclude_items: Option<bool>,
50 /// History mode preference, default `auto`. A PREFERENCE, not a budget
51 /// override: when the requested mode does not fit the history budget the
52 /// server downgrades it and `history.mode` reports what was actually
53 /// served. Ignored when `cursor` or `excludeItems` makes it moot.
54 #[serde(skip_serializing_if = "Option::is_none")]
55 pub history: Option<HistoryPreference>,
56 /// The launch permission-profile pick: a profile id the host catalog
57 /// already admits. Select, never create. Omitted restores retained
58 /// authority only, with no override. The host restores first, then applies
59 /// the pick in the same pre-marker step; over a declared lost record the
60 /// restore is the never-wider reset, committed before the pick, and where
61 /// the reset cannot commit the pick is committed alone as that reset. A
62 /// pick that fails admission refuses the resume `commandRejected` (-32030;
63 /// `permission_profile_unknown` / `permission_profile_unavailable`) before
64 /// any durable byte. Explicit `null` is invalid params (the same closed
65 /// null-tolerant set as at start).
66 #[serde(
67 default,
68 deserialize_with = "super::deserialize_non_null_optional",
69 skip_serializing_if = "Option::is_none"
70 )]
71 pub permission_profile: Option<String>,
72 /// The same open construction-time extension object as `session/start`.
73 #[serde(
74 default,
75 deserialize_with = "super::deserialize_non_null_optional",
76 skip_serializing_if = "Option::is_none"
77 )]
78 pub config: Option<SessionConfig>,
79}
80
81/// The `history` request preference of `session/resume`. The forced values
82/// downgrade `anchored` → `inline` → `snapshot` → `none`; under `auto` the full
83/// rung order is anchoredSnapshot → inline → snapshot → elided snapshot → none.
84#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
85#[serde(rename_all = "camelCase")]
86pub enum HistoryPreference {
87 /// Serve the best rung that fits, anchored first.
88 Auto,
89 /// Prefer the full folded item array.
90 Inline,
91 /// Prefer a folded view state plus suffix.
92 Snapshot,
93 /// Prefer a snapshot anchored at the latest installed compaction boundary.
94 Anchored,
95}
96
97/// The `history` envelope shared by `session/resume`, `session/fork`, and
98/// `session/read`.
99#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
100#[serde(rename_all = "camelCase")]
101#[non_exhaustive]
102pub struct SessionHistory {
103 /// What was actually served — never what was asked for.
104 pub mode: HistoryMode,
105 /// The full folded item array when `mode` is `inline`; `null` otherwise.
106 pub items: Option<Vec<Item>>,
107 /// The folded view state when `mode` is `snapshot` or `anchoredSnapshot`;
108 /// `null` otherwise.
109 pub snapshot: Option<ViewSnapshot>,
110 /// Why no history was served — sent exactly when `mode` is `"none"`.
111 #[serde(skip_serializing_if = "Option::is_none")]
112 pub none_reason: Option<HistoryNoneReason>,
113 /// The checkpoint-prune boundary: rows for served items at-or-before
114 /// `through_item_id` in served order predate the selected checkpoint.
115 /// Additive-optional; absence is a non-assertion.
116 #[serde(default, skip_serializing_if = "Option::is_none")]
117 pub checkpoint_boundary: Option<CheckpointBoundary>,
118}
119
120/// A served checkpoint-prune boundary: `through_item_id` names the last
121/// first-opened item that opened strictly before the boundary checkpoint event.
122#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
123#[serde(rename_all = "camelCase")]
124#[non_exhaustive]
125pub struct CheckpointBoundary {
126 /// The last pre-boundary item's id, in served (first-opened) order.
127 pub through_item_id: String,
128}
129
130/// Why a result served `history.mode: "none"`: the server's typed reason for
131/// serving no history. Open on the client side: an absent (older server) or
132/// unknown (newer server) value decodes conservatively as an unknown reason,
133/// and `viewCursor` text never substitutes for it.
134#[derive(Debug, Clone, PartialEq, Eq)]
135#[non_exhaustive]
136pub enum HistoryNoneReason {
137 /// The request's effective `excludeItems` was `true` (the
138 /// `session/read` default; explicit on resume/fork).
139 Excluded,
140 /// A retained cursor was supplied; the streamed suffix carries the
141 /// history.
142 CursorSuffix,
143 /// Every rung through the elided snapshot exceeded the history budget;
144 /// page via `view/page` from the result's `viewCursor`.
145 HistoryBudget,
146 /// No trustworthy materialized projection exists; paging cannot recover it.
147 ProjectionUnavailable,
148 /// The projection exists but the aggregate materialized read exceeded
149 /// its bounded read cap; page in bounded chunks.
150 ProjectionReadLimit,
151 /// A value from a newer host, kept verbatim so an older client decodes the
152 /// rest of the message. Excluded from the generated schema while the enum
153 /// stays declared open; never construct it with a known word.
154 Unknown(String),
155}
156
157/// What history a lifecycle result actually served. Open on the client side:
158/// report-what-was-served means a client treats an unknown mode as "page it
159/// yourself".
160#[derive(Debug, Clone, PartialEq, Eq)]
161#[non_exhaustive]
162pub enum HistoryMode {
163 /// `snapshot` holds a folded view state anchored at the latest installed
164 /// compaction boundary; `snapshot.anchor` names it.
165 AnchoredSnapshot,
166 /// `items` is the full folded item array.
167 Inline,
168 /// `snapshot` holds a folded view state at `snapshot.viewCursor`.
169 Snapshot,
170 /// No history was served — page it via `view/page` from the result's
171 /// `viewCursor`.
172 None,
173 /// A value from a newer host, kept verbatim so an older client decodes the
174 /// rest of the message. Excluded from the generated schema while the enum
175 /// stays declared open; never construct it with a known word.
176 Unknown(String),
177}
178
179/// A late-joiner pointer at an unsettled server-initiated request. The full
180/// payloads arrive as re-issued server-to-client requests right after a
181/// `session/resume` response; `session/read` never re-issues them.
182///
183/// The protocol defines two kind-discriminated entry shapes (`{kind:
184/// "approval", approvalId, viewCursor}` / `{kind: "userInput", userInputId,
185/// viewCursor}`). This type is one flat object with both ids optional, as for
186/// `ApprovalSubject` and `TurnInputPart`, because the v1 model names no
187/// object-variant union; the serialized JSON is the same, but the published
188/// schema also accepts `{"kind":"approval","userInputId":…}` and an entry
189/// carrying no id at all. Unlike `TurnInputPart.type`, `kind` here is an OPEN
190/// enum.
191#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
192#[serde(rename_all = "camelCase")]
193#[non_exhaustive]
194pub struct PendingRequestPointer {
195 /// The discriminator; v1 values `approval` and `userInput`.
196 pub kind: PendingRequestKind,
197 /// Present on an `approval` entry.
198 #[serde(skip_serializing_if = "Option::is_none")]
199 pub approval_id: Option<String>,
200 /// Present on a `userInput` entry.
201 #[serde(skip_serializing_if = "Option::is_none")]
202 pub user_input_id: Option<String>,
203 /// The cursor the request opened at.
204 pub view_cursor: String,
205}
206
207/// The `pendingRequests` discriminator. Open enum, v1 values `approval` and
208/// `userInput`.
209#[derive(Debug, Clone, PartialEq, Eq)]
210#[non_exhaustive]
211pub enum PendingRequestKind {
212 /// An unsettled approval.
213 Approval,
214 /// An unsettled user-input prompt.
215 UserInput,
216 /// A value from a newer host, kept verbatim so an older client decodes the
217 /// rest of the message. Never construct it with a known word.
218 Unknown(String),
219}
220
221/// `session/resume` result.
222#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
223#[serde(rename_all = "camelCase")]
224#[non_exhaustive]
225pub struct SessionResumeResult {
226 /// The loaded session.
227 pub session: Session,
228 /// The session view head; the connection is subscribed after it. A
229 /// still-loaded session a prior `view/unsubscribe` detached is RE-ATTACHED
230 /// by this resume: live delivery resumes from this head. Explicit-cursor
231 /// re-attach with `(after, head]` engine replay stays `view/subscribe`.
232 pub view_cursor: String,
233 /// The served history.
234 pub history: SessionHistory,
235 /// The late-joiner pointer set; empty when nothing is pending.
236 pub pending_requests: Vec<PendingRequestPointer>,
237 /// How the last folded turn ended. **Additive-optional**; absence is a
238 /// non-assertion.
239 #[serde(default, skip_serializing_if = "Option::is_none")]
240 pub last_turn: Option<LastTurn>,
241 /// The axes this resume tightened: when the stored choice exceeds the
242 /// restarted host's narrower ceiling, the resume clamps to fit, carries the
243 /// tightened `currentLimits` on the session, and names each tightened axis
244 /// here. **Experimental, same-user socket only**
245 /// (`session/resume.tightenedAxes`; stripped per-connection for unopted
246 /// callers). Absent when nothing tightened — never an empty array.
247 #[serde(default, skip_serializing_if = "Option::is_none")]
248 pub tightened_axes: Option<Vec<String>>,
249 /// The recallable blocked prompt's refill text. **Additive-optional**;
250 /// absence means no blocked prompt to recall (an unblocked session, or a
251 /// pre-feature host). Data only, never a rendered row: clients seed cold
252 /// recall from it (C-p refills `text`) and MUST NOT display it as history.
253 #[serde(default, skip_serializing_if = "Option::is_none")]
254 pub blocked_prompt: Option<BlockedPrompt>,
255}
256
257/// The cold recall seed on `session/resume` and `session/read` results: at most
258/// one, the latest blocked Main prompt — exactly the host's mirror of
259/// `prompt_recovery::replay::ReplayInput`'s choice.
260#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
261#[serde(rename_all = "camelCase")]
262#[non_exhaustive]
263pub struct BlockedPrompt {
264 /// The exact submitted prompt, verbatim — no truncation, no
265 /// normalization; recall fidelity requires exactness.
266 pub text: String,
267}
268
269/// The last `turn/completed` the session-view fold applied, restated on
270/// `session/resume` and `session/read` so a reopened session can report a
271/// failed last turn.
272#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
273#[serde(rename_all = "camelCase")]
274#[non_exhaustive]
275pub struct LastTurn {
276 /// The turn's id, as on its `turn/completed`; clients deduplicate a live
277 /// `turn/completed` against this member by it.
278 pub turn_id: String,
279 /// The turn's terminal.
280 pub terminal: TurnTerminal,
281 /// Copied when the `turn/completed` carried it; a synthesized host-death
282 /// `failed` terminal carries only this (`crash`, `crash_inferred`, or
283 /// `incomplete`). Free display text: clients never branch on it.
284 #[serde(default, skip_serializing_if = "Option::is_none")]
285 pub reason: Option<String>,
286 /// Copied when the `turn/completed` carried it: runtime `failed` terminals
287 /// do, host-death `failed` terminals do not.
288 #[serde(default, skip_serializing_if = "Option::is_none")]
289 pub error: Option<TurnError>,
290}