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