Skip to main content

muse_code_sdk/msp/method/
model_completed.rs

1// @generated from the MSP stable schema and protocol sources; do not edit by hand.
2
3use serde::Deserialize;
4use serde::Deserializer;
5use serde::Serialize;
6use serde::Serializer;
7
8/// How a `model/complete` call settled. **Open**: a server-produced result
9/// vocabulary, so a word a newer host adds decodes to `Unknown`.
10#[derive(Debug, Clone, PartialEq, Eq)]
11#[non_exhaustive]
12pub enum ModelCompleteOutcome {
13    /// The model answered; `text` carries the answer.
14    Completed,
15    /// The call failed; `message` says why.
16    Failed,
17    /// `model/cancel` or a connection close won the race.
18    Cancelled,
19    /// The host-enforced 45 s bound fired.
20    TimedOut,
21    /// A value from a newer host, kept verbatim. Excluded from the generated
22    /// schema; never construct it with a known word.
23    Unknown(String),
24}
25
26impl ModelCompleteOutcome {
27    /// The exact wire spelling, including a value from a newer host.
28    #[must_use]
29    pub fn as_str(&self) -> &str {
30        match self {
31            Self::Completed => "completed",
32            Self::Failed => "failed",
33            Self::Cancelled => "cancelled",
34            Self::TimedOut => "timedOut",
35            Self::Unknown(value) => value,
36        }
37    }
38}
39
40impl Serialize for ModelCompleteOutcome {
41    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
42    where
43        S: Serializer,
44    {
45        serializer.serialize_str(self.as_str())
46    }
47}
48
49impl<'de> Deserialize<'de> for ModelCompleteOutcome {
50    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
51    where
52        D: Deserializer<'de>,
53    {
54        let value = String::deserialize(deserializer)?;
55        Ok(match value.as_str() {
56            "completed" => Self::Completed,
57            "failed" => Self::Failed,
58            "cancelled" => Self::Cancelled,
59            "timedOut" => Self::TimedOut,
60            _ => Self::Unknown(value),
61        })
62    }
63}
64
65/// Why the model stopped on a `completed` call. **Open**: a server-produced
66/// word, so a word a newer host adds decodes to `Unknown`.
67#[derive(Debug, Clone, PartialEq, Eq)]
68#[non_exhaustive]
69pub enum ModelCompleteStopReason {
70    /// The answer ended, for any reason but the request's bound.
71    End,
72    /// The provider stopped at the request's `maxTokens`.
73    MaxTokens,
74    /// A value from a newer host, kept verbatim. Excluded from the generated
75    /// schema; never construct it with a known word.
76    Unknown(String),
77}
78
79impl ModelCompleteStopReason {
80    /// The exact wire spelling, including a value from a newer host.
81    #[must_use]
82    pub fn as_str(&self) -> &str {
83        match self {
84            Self::End => "end",
85            Self::MaxTokens => "maxTokens",
86            Self::Unknown(value) => value,
87        }
88    }
89}
90
91impl Serialize for ModelCompleteStopReason {
92    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
93    where
94        S: Serializer,
95    {
96        serializer.serialize_str(self.as_str())
97    }
98}
99
100impl<'de> Deserialize<'de> for ModelCompleteStopReason {
101    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
102    where
103        D: Deserializer<'de>,
104    {
105        let value = String::deserialize(deserializer)?;
106        Ok(match value.as_str() {
107            "end" => Self::End,
108            "maxTokens" => Self::MaxTokens,
109            _ => Self::Unknown(value),
110        })
111    }
112}
113
114/// The provider's token counts for one completed call: real counts only, never
115/// an estimate.
116#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
117#[serde(rename_all = "camelCase")]
118#[non_exhaustive]
119pub struct ModelCompleteUsage {
120    /// Input tokens, as the provider counted them.
121    pub input_tokens: u64,
122    /// Output tokens, as the provider counted them.
123    pub output_tokens: u64,
124}
125
126/// `model/completed` params. `text`, `stopReason`, `modelId` and `usage` ride
127/// `completed` (`usage` only when the provider reported counts); `message`
128/// rides `failed`; `cancelled` and `timedOut` carry neither. The struct marks
129/// the conditional members optional; the SS prose pins the per-outcome rule.
130/// `text` is untrusted model output.
131#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
132#[serde(rename_all = "camelCase")]
133#[non_exhaustive]
134pub struct ModelCompletedParams {
135    /// The request's id — the correlation key.
136    pub command_id: String,
137    /// How the call settled.
138    pub outcome: ModelCompleteOutcome,
139    /// The model's answer, verbatim (on `completed`).
140    #[serde(default, skip_serializing_if = "Option::is_none")]
141    pub text: Option<String>,
142    /// Why the model stopped (on `completed`).
143    #[serde(default, skip_serializing_if = "Option::is_none")]
144    pub stop_reason: Option<ModelCompleteStopReason>,
145    /// The `model/list` id of the model that ran (on `completed`).
146    #[serde(default, skip_serializing_if = "Option::is_none")]
147    pub model_id: Option<String>,
148    /// The provider's counts (on `completed`, when it reported them).
149    #[serde(default, skip_serializing_if = "Option::is_none")]
150    pub usage: Option<ModelCompleteUsage>,
151    /// Why the call failed, in words (on `failed`).
152    #[serde(default, skip_serializing_if = "Option::is_none")]
153    pub message: Option<String>,
154}