Skip to main content

muse_code_sdk/msp/
envelope.rs

1// @generated from the MSP stable schema and protocol sources; do not edit by hand.
2
3use crate::msp::error::ErrorObject;
4use serde::Deserialize;
5use serde::Serialize;
6
7/// A JSON object payload whose member set is method-specific rather than part
8/// of the envelope grammar (`params`, `result`). Kept order-preserving-free:
9/// `serde_json::Map` is a `BTreeMap` under the workspace's default features, so
10/// serialization order is deterministic.
11pub type JsonObject = serde_json::Map<String, serde_json::Value>;
12
13/// The literal `"2.0"` every frame carries.
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
15pub enum JsonRpcVersion {
16    /// The only value; a different string is not an MSP frame.
17    #[serde(rename = "2.0")]
18    V2,
19}
20
21/// A request id: client-chosen string or integer. `1` and `"1"` do not compare
22/// equal; each direction owns its own id space.
23#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
24#[serde(untagged)]
25pub enum RequestId {
26    /// Integer form; server-initiated requests always use this form, from a
27    /// monotonically increasing per-process counter.
28    Integer(i64),
29    /// String form (client-initiated only).
30    String(String),
31}
32
33/// Optional W3C trace context, on requests in both directions only — never on
34/// responses or notifications.
35#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
36#[serde(rename_all = "camelCase")]
37#[non_exhaustive]
38pub struct TraceContext {
39    /// W3C `traceparent` string; receivers that do not trace ignore it.
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub traceparent: Option<String>,
42    /// W3C `tracestate` string.
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub tracestate: Option<String>,
45}
46
47/// A request frame, either direction.
48#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
49#[serde(rename_all = "camelCase")]
50#[non_exhaustive]
51pub struct Request {
52    /// The literal `"2.0"`.
53    pub jsonrpc: JsonRpcVersion,
54    /// Client-chosen id, unique among that client's in-flight requests.
55    pub id: RequestId,
56    /// Slash-namespaced camelCase method name.
57    pub method: String,
58    /// Method-specific parameters; omitted entirely when empty, never `null`.
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub params: Option<JsonObject>,
61    /// W3C trace passthrough; requests only.
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub trace: Option<TraceContext>,
64}
65
66/// A success response frame.
67#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
68#[serde(rename_all = "camelCase")]
69#[non_exhaustive]
70pub struct SuccessResponse {
71    /// The literal `"2.0"`.
72    pub jsonrpc: JsonRpcVersion,
73    /// Echo of the request id.
74    pub id: RequestId,
75    /// Always a JSON object, possibly `{}`, never a bare scalar — so every
76    /// result can grow additive-optional members.
77    pub result: JsonObject,
78}
79
80/// An error response frame. Exactly one of `result` or `error` appears on a
81/// response; this type is the `error` half.
82#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
83#[serde(rename_all = "camelCase")]
84#[non_exhaustive]
85pub struct ErrorResponse {
86    /// The literal `"2.0"`.
87    pub jsonrpc: JsonRpcVersion,
88    /// Echo of the request id; `null` **only** for an unrecoverable parse error
89    /// whose offending id could not be recovered. Always serialized, so `None`
90    /// renders as `null` rather than being omitted — required-but-nullable (see
91    /// [`require_nullable_id`]).
92    pub id: Option<RequestId>,
93    /// The error payload.
94    pub error: ErrorObject,
95}
96
97/// A notification frame, either direction. No `id`; a notification is never
98/// answered.
99#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
100#[serde(rename_all = "camelCase")]
101#[non_exhaustive]
102pub struct Notification {
103    /// The literal `"2.0"`.
104    pub jsonrpc: JsonRpcVersion,
105    /// Notification method name.
106    pub method: String,
107    /// Method-specific parameters; omitted entirely when empty.
108    #[serde(skip_serializing_if = "Option::is_none")]
109    pub params: Option<JsonObject>,
110    /// Emission time in Unix milliseconds, recorded once at emission;
111    /// server→client notifications only. Optional on the wire so decoders
112    /// tolerate older servers.
113    #[serde(skip_serializing_if = "Option::is_none")]
114    pub emitted_at_ms: Option<i64>,
115}