1use std::{path::PathBuf, sync::Arc};
7
8use std::collections::HashMap;
9
10use derive_more::{Display, From};
11use serde::{Deserialize, Serialize};
12use serde_with::{DefaultOnError, DefaultOnNull, VecSkipError, serde_as, skip_serializing_none};
13
14use crate::{IntoOption, ProtocolVersion};
15
16#[cfg(all(
17 feature = "unstable_session_fork",
18 feature = "unstable_session_cursors"
19))]
20use super::CursorId;
21
22use super::{
23 ClientCapabilities, ContentBlock, ExtNotification, ExtRequest, ExtResponse, Meta, SessionId,
24};
25
26#[cfg(all(feature = "unstable_auth_status", feature = "schemars"))]
27use super::AUTH_STATUS_UPDATE_NOTIFICATION;
28#[cfg(feature = "unstable_mcp_over_acp")]
29use super::mcp::{MCP_MESSAGE_METHOD_NAME, MessageMcpNotification};
30
31#[serde_as]
39#[skip_serializing_none]
40#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
41#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
42#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = INITIALIZE_METHOD_NAME)))]
43#[serde(rename_all = "camelCase")]
44#[non_exhaustive]
45pub struct InitializeRequest {
46 pub protocol_version: ProtocolVersion,
48 #[serde_as(deserialize_as = "DefaultOnError")]
50 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
51 #[serde(default)]
52 pub client_capabilities: ClientCapabilities,
53 #[serde_as(deserialize_as = "DefaultOnError")]
57 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
58 #[serde(default)]
59 pub client_info: Option<Implementation>,
60 #[serde_as(deserialize_as = "DefaultOnError")]
66 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
67 #[serde(default)]
68 #[serde(rename = "_meta")]
69 pub meta: Option<Meta>,
70}
71
72impl InitializeRequest {
73 #[must_use]
75 pub fn new(protocol_version: ProtocolVersion) -> Self {
76 Self {
77 protocol_version,
78 client_capabilities: ClientCapabilities::default(),
79 client_info: None,
80 meta: None,
81 }
82 }
83
84 #[must_use]
86 pub fn client_capabilities(mut self, client_capabilities: ClientCapabilities) -> Self {
87 self.client_capabilities = client_capabilities;
88 self
89 }
90
91 #[must_use]
93 pub fn client_info(mut self, client_info: impl IntoOption<Implementation>) -> Self {
94 self.client_info = client_info.into_option();
95 self
96 }
97
98 #[must_use]
104 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
105 self.meta = meta.into_option();
106 self
107 }
108}
109
110#[serde_as]
116#[skip_serializing_none]
117#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
118#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
119#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = INITIALIZE_METHOD_NAME)))]
120#[serde(rename_all = "camelCase")]
121#[non_exhaustive]
122pub struct InitializeResponse {
123 pub protocol_version: ProtocolVersion,
128 #[serde_as(deserialize_as = "DefaultOnError")]
130 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
131 #[serde(default)]
132 pub agent_capabilities: AgentCapabilities,
133 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
135 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
136 #[serde(default)]
137 pub auth_methods: Vec<AuthMethod>,
138 #[serde_as(deserialize_as = "DefaultOnError")]
142 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
143 #[serde(default)]
144 pub agent_info: Option<Implementation>,
145 #[serde_as(deserialize_as = "DefaultOnError")]
151 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
152 #[serde(default)]
153 #[serde(rename = "_meta")]
154 pub meta: Option<Meta>,
155}
156
157impl InitializeResponse {
158 #[must_use]
160 pub fn new(protocol_version: ProtocolVersion) -> Self {
161 Self {
162 protocol_version,
163 agent_capabilities: AgentCapabilities::default(),
164 auth_methods: vec![],
165 agent_info: None,
166 meta: None,
167 }
168 }
169
170 #[must_use]
172 pub fn agent_capabilities(mut self, agent_capabilities: AgentCapabilities) -> Self {
173 self.agent_capabilities = agent_capabilities;
174 self
175 }
176
177 #[must_use]
179 pub fn auth_methods(mut self, auth_methods: Vec<AuthMethod>) -> Self {
180 self.auth_methods = auth_methods;
181 self
182 }
183
184 #[must_use]
186 pub fn agent_info(mut self, agent_info: impl IntoOption<Implementation>) -> Self {
187 self.agent_info = agent_info.into_option();
188 self
189 }
190
191 #[must_use]
197 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
198 self.meta = meta.into_option();
199 self
200 }
201}
202
203#[serde_as]
207#[skip_serializing_none]
208#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
209#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
210#[serde(rename_all = "camelCase")]
211#[non_exhaustive]
212pub struct Implementation {
213 pub name: String,
216 #[serde_as(deserialize_as = "DefaultOnError")]
221 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
222 #[serde(default)]
223 pub title: Option<String>,
224 pub version: String,
227 #[serde_as(deserialize_as = "DefaultOnError")]
233 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
234 #[serde(default)]
235 #[serde(rename = "_meta")]
236 pub meta: Option<Meta>,
237}
238
239impl Implementation {
240 #[must_use]
242 pub fn new(name: impl Into<String>, version: impl Into<String>) -> Self {
243 Self {
244 name: name.into(),
245 title: None,
246 version: version.into(),
247 meta: None,
248 }
249 }
250
251 #[must_use]
256 pub fn title(mut self, title: impl IntoOption<String>) -> Self {
257 self.title = title.into_option();
258 self
259 }
260
261 #[must_use]
267 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
268 self.meta = meta.into_option();
269 self
270 }
271}
272
273#[serde_as]
279#[skip_serializing_none]
280#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
281#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
282#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = AUTHENTICATE_METHOD_NAME)))]
283#[serde(rename_all = "camelCase")]
284#[non_exhaustive]
285pub struct AuthenticateRequest {
286 pub method_id: AuthMethodId,
289 #[serde_as(deserialize_as = "DefaultOnError")]
295 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
296 #[serde(default)]
297 #[serde(rename = "_meta")]
298 pub meta: Option<Meta>,
299}
300
301impl AuthenticateRequest {
302 #[must_use]
304 pub fn new(method_id: impl Into<AuthMethodId>) -> Self {
305 Self {
306 method_id: method_id.into(),
307 meta: None,
308 }
309 }
310
311 #[must_use]
317 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
318 self.meta = meta.into_option();
319 self
320 }
321}
322
323crate::serde_util::default_on_null! {
324 #[serde_as]
326 #[skip_serializing_none]
327 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
328 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
329 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = AUTHENTICATE_METHOD_NAME)))]
330 #[serde(rename_all = "camelCase")]
331 #[non_exhaustive]
332 pub struct AuthenticateResponse {
333 #[serde_as(deserialize_as = "DefaultOnError")]
339 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
340 #[serde(default)]
341 #[serde(rename = "_meta")]
342 pub meta: Option<Meta>,
343 }
344}
345
346impl AuthenticateResponse {
347 #[must_use]
349 pub fn new() -> Self {
350 Self::default()
351 }
352
353 #[must_use]
359 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
360 self.meta = meta.into_option();
361 self
362 }
363}
364
365crate::serde_util::default_on_null! {
368 #[serde_as]
372 #[skip_serializing_none]
373 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
374 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
375 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = LOGOUT_METHOD_NAME)))]
376 #[serde(rename_all = "camelCase")]
377 #[non_exhaustive]
378 pub struct LogoutRequest {
379 #[serde_as(deserialize_as = "DefaultOnError")]
385 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
386 #[serde(default)]
387 #[serde(rename = "_meta")]
388 pub meta: Option<Meta>,
389 }
390}
391
392impl LogoutRequest {
393 #[must_use]
395 pub fn new() -> Self {
396 Self::default()
397 }
398
399 #[must_use]
405 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
406 self.meta = meta.into_option();
407 self
408 }
409}
410
411crate::serde_util::default_on_null! {
412 #[serde_as]
414 #[skip_serializing_none]
415 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
416 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
417 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = LOGOUT_METHOD_NAME)))]
418 #[serde(rename_all = "camelCase")]
419 #[non_exhaustive]
420 pub struct LogoutResponse {
421 #[serde_as(deserialize_as = "DefaultOnError")]
427 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
428 #[serde(default)]
429 #[serde(rename = "_meta")]
430 pub meta: Option<Meta>,
431 }
432}
433
434impl LogoutResponse {
435 #[must_use]
437 pub fn new() -> Self {
438 Self::default()
439 }
440
441 #[must_use]
447 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
448 self.meta = meta.into_option();
449 self
450 }
451}
452
453#[cfg(feature = "unstable_auth_status")]
456crate::serde_util::default_on_null! {
457 #[serde_as]
468 #[skip_serializing_none]
469 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
470 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
471 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = AUTH_STATUS_METHOD_NAME)))]
472 #[serde(rename_all = "camelCase")]
473 #[non_exhaustive]
474 pub struct AuthStatusRequest {
475 #[serde_as(deserialize_as = "DefaultOnError")]
481 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
482 #[serde(default)]
483 #[serde(rename = "_meta")]
484 pub meta: Option<Meta>,
485 }
486}
487
488#[cfg(feature = "unstable_auth_status")]
489impl AuthStatusRequest {
490 #[must_use]
492 pub fn new() -> Self {
493 Self::default()
494 }
495
496 #[must_use]
502 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
503 self.meta = meta.into_option();
504 self
505 }
506}
507
508#[cfg(feature = "unstable_auth_status")]
514#[serde_as]
515#[skip_serializing_none]
516#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
517#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
518#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = AUTH_STATUS_METHOD_NAME)))]
519#[serde(rename_all = "camelCase")]
520#[non_exhaustive]
521pub struct AuthStatusResponse {
522 pub state: AuthState,
527 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
533 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
534 #[serde(default, skip_serializing_if = "Vec::is_empty")]
535 pub accounts: Vec<AuthAccount>,
536 #[serde_as(deserialize_as = "DefaultOnError")]
542 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
543 #[serde(default)]
544 #[serde(rename = "_meta")]
545 pub meta: Option<Meta>,
546}
547
548#[cfg(feature = "unstable_auth_status")]
549impl AuthStatusResponse {
550 #[must_use]
552 pub fn new(state: AuthState) -> Self {
553 Self {
554 state,
555 accounts: vec![],
556 meta: None,
557 }
558 }
559
560 #[must_use]
562 pub fn accounts(mut self, accounts: Vec<AuthAccount>) -> Self {
563 self.accounts = accounts;
564 self
565 }
566
567 #[must_use]
573 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
574 self.meta = meta.into_option();
575 self
576 }
577}
578
579#[cfg(feature = "unstable_auth_status")]
589#[serde_as]
590#[skip_serializing_none]
591#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
592#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
593#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "client", "x-method" = AUTH_STATUS_UPDATE_NOTIFICATION)))]
594#[serde(rename_all = "camelCase")]
595#[non_exhaustive]
596pub struct AuthStatusUpdateNotification {
597 pub state: AuthState,
602 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
608 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
609 #[serde(default, skip_serializing_if = "Vec::is_empty")]
610 pub accounts: Vec<AuthAccount>,
611 #[serde_as(deserialize_as = "DefaultOnError")]
617 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
618 #[serde(default)]
619 #[serde(rename = "_meta")]
620 pub meta: Option<Meta>,
621}
622
623#[cfg(feature = "unstable_auth_status")]
624impl AuthStatusUpdateNotification {
625 #[must_use]
627 pub fn new(state: AuthState) -> Self {
628 Self {
629 state,
630 accounts: vec![],
631 meta: None,
632 }
633 }
634
635 #[must_use]
637 pub fn accounts(mut self, accounts: Vec<AuthAccount>) -> Self {
638 self.accounts = accounts;
639 self
640 }
641
642 #[must_use]
648 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
649 self.meta = meta.into_option();
650 self
651 }
652}
653
654#[cfg(feature = "unstable_auth_status")]
660#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
661#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
662#[serde(rename_all = "snake_case")]
663#[non_exhaustive]
664pub enum AuthState {
665 Authenticated,
667 Unauthenticated,
670 NotRequired,
672 Unknown,
674 #[serde(untagged)]
680 Other(String),
681}
682
683#[cfg(feature = "unstable_auth_status")]
694#[serde_as]
695#[skip_serializing_none]
696#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
697#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
698#[serde(rename_all = "camelCase")]
699#[non_exhaustive]
700pub struct AuthAccount {
701 pub label: String,
704 #[serde_as(deserialize_as = "DefaultOnError")]
709 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
710 #[serde(default)]
711 pub description: Option<String>,
712 #[serde_as(deserialize_as = "DefaultOnError")]
718 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
719 #[serde(default)]
720 pub active: Option<bool>,
721 #[serde_as(deserialize_as = "DefaultOnError")]
725 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
726 #[serde(default)]
727 pub name: Option<String>,
728 #[serde_as(deserialize_as = "DefaultOnError")]
732 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
733 #[serde(default)]
734 pub email: Option<String>,
735 #[serde_as(deserialize_as = "DefaultOnError")]
739 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
740 #[serde(default)]
741 pub organization: Option<String>,
742 #[serde_as(deserialize_as = "DefaultOnError")]
748 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
749 #[serde(default)]
750 #[serde(rename = "_meta")]
751 pub meta: Option<Meta>,
752}
753
754#[cfg(feature = "unstable_auth_status")]
755impl AuthAccount {
756 #[must_use]
758 pub fn new(label: impl Into<String>) -> Self {
759 Self {
760 label: label.into(),
761 description: None,
762 active: None,
763 name: None,
764 email: None,
765 organization: None,
766 meta: None,
767 }
768 }
769
770 #[must_use]
772 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
773 self.description = description.into_option();
774 self
775 }
776
777 #[must_use]
779 pub fn active(mut self, active: impl IntoOption<bool>) -> Self {
780 self.active = active.into_option();
781 self
782 }
783
784 #[must_use]
786 pub fn name(mut self, name: impl IntoOption<String>) -> Self {
787 self.name = name.into_option();
788 self
789 }
790
791 #[must_use]
793 pub fn email(mut self, email: impl IntoOption<String>) -> Self {
794 self.email = email.into_option();
795 self
796 }
797
798 #[must_use]
800 pub fn organization(mut self, organization: impl IntoOption<String>) -> Self {
801 self.organization = organization.into_option();
802 self
803 }
804
805 #[must_use]
811 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
812 self.meta = meta.into_option();
813 self
814 }
815}
816
817#[cfg(feature = "unstable_auth_status")]
825#[serde_as]
826#[skip_serializing_none]
827#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
828#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
829#[non_exhaustive]
830pub struct AuthStatusCapabilities {
831 #[serde_as(deserialize_as = "DefaultOnError")]
837 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
838 #[serde(default)]
839 #[serde(rename = "_meta")]
840 pub meta: Option<Meta>,
841}
842
843#[cfg(feature = "unstable_auth_status")]
844impl AuthStatusCapabilities {
845 #[must_use]
847 pub fn new() -> Self {
848 Self::default()
849 }
850
851 #[must_use]
857 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
858 self.meta = meta.into_option();
859 self
860 }
861}
862
863#[serde_as]
865#[skip_serializing_none]
866#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
867#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
868#[serde(rename_all = "camelCase")]
869#[non_exhaustive]
870pub struct AgentAuthCapabilities {
871 #[cfg(feature = "unstable_auth_status")]
880 #[serde_as(deserialize_as = "DefaultOnError")]
881 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
882 #[serde(default)]
883 pub status: Option<AuthStatusCapabilities>,
884 #[serde_as(deserialize_as = "DefaultOnError")]
889 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
890 #[serde(default)]
891 pub logout: Option<LogoutCapabilities>,
892 #[serde_as(deserialize_as = "DefaultOnError")]
898 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
899 #[serde(default)]
900 #[serde(rename = "_meta")]
901 pub meta: Option<Meta>,
902}
903
904impl AgentAuthCapabilities {
905 #[must_use]
907 pub fn new() -> Self {
908 Self::default()
909 }
910
911 #[cfg(feature = "unstable_auth_status")]
917 #[must_use]
918 pub fn status(mut self, status: impl IntoOption<AuthStatusCapabilities>) -> Self {
919 self.status = status.into_option();
920 self
921 }
922
923 #[must_use]
925 pub fn logout(mut self, logout: impl IntoOption<LogoutCapabilities>) -> Self {
926 self.logout = logout.into_option();
927 self
928 }
929
930 #[must_use]
936 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
937 self.meta = meta.into_option();
938 self
939 }
940}
941
942#[serde_as]
946#[skip_serializing_none]
947#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
948#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
949#[non_exhaustive]
950pub struct LogoutCapabilities {
951 #[serde_as(deserialize_as = "DefaultOnError")]
957 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
958 #[serde(default)]
959 #[serde(rename = "_meta")]
960 pub meta: Option<Meta>,
961}
962
963impl LogoutCapabilities {
964 #[must_use]
966 pub fn new() -> Self {
967 Self::default()
968 }
969
970 #[must_use]
976 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
977 self.meta = meta.into_option();
978 self
979 }
980}
981
982#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
984#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Display, From)]
985#[serde(transparent)]
986#[from(Arc<str>, String, &'static str)]
987#[non_exhaustive]
988pub struct AuthMethodId(pub Arc<str>);
989
990impl AuthMethodId {
991 #[must_use]
993 pub fn new(id: impl Into<Arc<str>>) -> Self {
994 Self(id.into())
995 }
996}
997
998#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1003#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1004#[serde(tag = "type", rename_all = "snake_case")]
1005#[non_exhaustive]
1006pub enum AuthMethod {
1007 Terminal(AuthMethodTerminal),
1010 #[serde(untagged, deserialize_with = "deserialize_agent_auth_method_fallback")]
1014 Agent(AuthMethodAgent),
1015}
1016
1017fn deserialize_agent_auth_method_fallback<'de, D>(
1022 deserializer: D,
1023) -> Result<AuthMethodAgent, D::Error>
1024where
1025 D: serde::Deserializer<'de>,
1026{
1027 let value = serde_json::Value::deserialize(deserializer)?;
1028 if value.get("type").and_then(serde_json::Value::as_str) == Some("terminal") {
1029 return Err(serde::de::Error::custom(
1030 "known authentication method `terminal` did not match its schema",
1031 ));
1032 }
1033 AuthMethodAgent::deserialize(value).map_err(serde::de::Error::custom)
1034}
1035
1036impl AuthMethod {
1037 #[must_use]
1039 pub fn id(&self) -> &AuthMethodId {
1040 match self {
1041 Self::Agent(a) => &a.id,
1042 Self::Terminal(t) => &t.id,
1043 }
1044 }
1045
1046 #[must_use]
1048 pub fn name(&self) -> &str {
1049 match self {
1050 Self::Agent(a) => &a.name,
1051 Self::Terminal(t) => &t.name,
1052 }
1053 }
1054
1055 #[must_use]
1057 pub fn description(&self) -> Option<&str> {
1058 match self {
1059 Self::Agent(a) => a.description.as_deref(),
1060 Self::Terminal(t) => t.description.as_deref(),
1061 }
1062 }
1063
1064 #[must_use]
1070 pub fn meta(&self) -> Option<&Meta> {
1071 match self {
1072 Self::Agent(a) => a.meta.as_ref(),
1073 Self::Terminal(t) => t.meta.as_ref(),
1074 }
1075 }
1076}
1077
1078#[serde_as]
1082#[skip_serializing_none]
1083#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1084#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1085#[serde(rename_all = "camelCase")]
1086#[non_exhaustive]
1087pub struct AuthMethodAgent {
1088 pub id: AuthMethodId,
1090 pub name: String,
1092 #[serde_as(deserialize_as = "DefaultOnError")]
1094 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1095 #[serde(default)]
1096 pub description: Option<String>,
1097 #[serde_as(deserialize_as = "DefaultOnError")]
1103 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1104 #[serde(default)]
1105 #[serde(rename = "_meta")]
1106 pub meta: Option<Meta>,
1107}
1108
1109impl AuthMethodAgent {
1110 #[must_use]
1112 pub fn new(id: impl Into<AuthMethodId>, name: impl Into<String>) -> Self {
1113 Self {
1114 id: id.into(),
1115 name: name.into(),
1116 description: None,
1117 meta: None,
1118 }
1119 }
1120
1121 #[must_use]
1123 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
1124 self.description = description.into_option();
1125 self
1126 }
1127
1128 #[must_use]
1134 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1135 self.meta = meta.into_option();
1136 self
1137 }
1138}
1139
1140#[serde_as]
1148#[skip_serializing_none]
1149#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1150#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1151#[serde(rename_all = "camelCase")]
1152#[non_exhaustive]
1153pub struct AuthMethodTerminal {
1154 pub id: AuthMethodId,
1156 pub name: String,
1158 #[serde_as(deserialize_as = "DefaultOnError")]
1160 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1161 #[serde(default)]
1162 pub description: Option<String>,
1163 #[serde_as(deserialize_as = "DefaultOnNull")]
1165 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1166 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1167 pub args: Vec<String>,
1168 #[serde_as(deserialize_as = "DefaultOnNull")]
1171 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1172 #[serde(default, skip_serializing_if = "HashMap::is_empty")]
1173 pub env: HashMap<String, String>,
1174 #[serde_as(deserialize_as = "DefaultOnError")]
1180 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1181 #[serde(default)]
1182 #[serde(rename = "_meta")]
1183 pub meta: Option<Meta>,
1184}
1185
1186impl AuthMethodTerminal {
1187 #[must_use]
1189 pub fn new(id: impl Into<AuthMethodId>, name: impl Into<String>) -> Self {
1190 Self {
1191 id: id.into(),
1192 name: name.into(),
1193 description: None,
1194 args: Vec::new(),
1195 env: HashMap::new(),
1196 meta: None,
1197 }
1198 }
1199
1200 #[must_use]
1202 pub fn args(mut self, args: Vec<String>) -> Self {
1203 self.args = args;
1204 self
1205 }
1206
1207 #[must_use]
1210 pub fn env(mut self, env: HashMap<String, String>) -> Self {
1211 self.env = env;
1212 self
1213 }
1214
1215 #[must_use]
1217 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
1218 self.description = description.into_option();
1219 self
1220 }
1221
1222 #[must_use]
1228 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1229 self.meta = meta.into_option();
1230 self
1231 }
1232}
1233
1234#[serde_as]
1240#[skip_serializing_none]
1241#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1242#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1243#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_NEW_METHOD_NAME)))]
1244#[serde(rename_all = "camelCase")]
1245#[non_exhaustive]
1246pub struct NewSessionRequest {
1247 pub cwd: PathBuf,
1249 #[serde_as(deserialize_as = "DefaultOnNull")]
1255 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1256 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1257 pub additional_directories: Vec<PathBuf>,
1258 #[serde_as(deserialize_as = "DefaultOnNull")]
1260 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1261 pub mcp_servers: Vec<McpServer>,
1262 #[serde(default)]
1268 pub system_prompt: Option<SystemPrompt>,
1269 #[cfg(feature = "unstable_session_options")]
1287 #[serde_as(deserialize_as = "DefaultOnNull")]
1288 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1289 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1290 pub config_options: Vec<InitialSessionConfigOption>,
1291 #[serde_as(deserialize_as = "DefaultOnError")]
1297 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1298 #[serde(default)]
1299 #[serde(rename = "_meta")]
1300 pub meta: Option<Meta>,
1301}
1302
1303impl NewSessionRequest {
1304 #[must_use]
1306 pub fn new(cwd: impl Into<PathBuf>) -> Self {
1307 Self {
1308 cwd: cwd.into(),
1309 additional_directories: vec![],
1310 mcp_servers: vec![],
1311 system_prompt: None,
1312 #[cfg(feature = "unstable_session_options")]
1313 config_options: vec![],
1314 meta: None,
1315 }
1316 }
1317
1318 #[must_use]
1320 pub fn additional_directories(mut self, additional_directories: Vec<PathBuf>) -> Self {
1321 self.additional_directories = additional_directories;
1322 self
1323 }
1324
1325 #[must_use]
1327 pub fn mcp_servers(mut self, mcp_servers: Vec<McpServer>) -> Self {
1328 self.mcp_servers = mcp_servers;
1329 self
1330 }
1331
1332 #[must_use]
1334 pub fn system_prompt(mut self, system_prompt: impl IntoOption<SystemPrompt>) -> Self {
1335 self.system_prompt = system_prompt.into_option();
1336 self
1337 }
1338
1339 #[cfg(feature = "unstable_session_options")]
1357 #[must_use]
1358 pub fn config_options(mut self, config_options: Vec<InitialSessionConfigOption>) -> Self {
1359 self.config_options = config_options;
1360 self
1361 }
1362
1363 #[must_use]
1369 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1370 self.meta = meta.into_option();
1371 self
1372 }
1373}
1374
1375#[serde_as]
1379#[skip_serializing_none]
1380#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1381#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1382#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_NEW_METHOD_NAME)))]
1383#[serde(rename_all = "camelCase")]
1384#[non_exhaustive]
1385pub struct NewSessionResponse {
1386 pub session_id: SessionId,
1390 #[serde_as(deserialize_as = "DefaultOnError")]
1394 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1395 #[serde(default)]
1396 pub modes: Option<SessionModeState>,
1397 #[serde_as(deserialize_as = "DefaultOnError<Option<VecSkipError<_>>>")]
1399 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
1400 #[serde(default)]
1401 pub config_options: Option<Vec<SessionConfigOption>>,
1402 #[serde_as(deserialize_as = "DefaultOnError")]
1408 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1409 #[serde(default)]
1410 #[serde(rename = "_meta")]
1411 pub meta: Option<Meta>,
1412}
1413
1414impl NewSessionResponse {
1415 #[must_use]
1417 pub fn new(session_id: impl Into<SessionId>) -> Self {
1418 Self {
1419 session_id: session_id.into(),
1420 modes: None,
1421 config_options: None,
1422 meta: None,
1423 }
1424 }
1425
1426 #[must_use]
1430 pub fn modes(mut self, modes: impl IntoOption<SessionModeState>) -> Self {
1431 self.modes = modes.into_option();
1432 self
1433 }
1434
1435 #[must_use]
1437 pub fn config_options(
1438 mut self,
1439 config_options: impl IntoOption<Vec<SessionConfigOption>>,
1440 ) -> Self {
1441 self.config_options = config_options.into_option();
1442 self
1443 }
1444
1445 #[must_use]
1451 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1452 self.meta = meta.into_option();
1453 self
1454 }
1455}
1456
1457#[serde_as]
1465#[skip_serializing_none]
1466#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1467#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1468#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_LOAD_METHOD_NAME)))]
1469#[serde(rename_all = "camelCase")]
1470#[non_exhaustive]
1471pub struct LoadSessionRequest {
1472 #[serde_as(deserialize_as = "DefaultOnNull")]
1474 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1475 pub mcp_servers: Vec<McpServer>,
1476 pub cwd: PathBuf,
1478 #[serde_as(deserialize_as = "DefaultOnNull")]
1485 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1486 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1487 pub additional_directories: Vec<PathBuf>,
1488 pub session_id: SessionId,
1490 #[serde(default)]
1498 pub system_prompt: Option<SystemPrompt>,
1499 #[cfg(feature = "unstable_session_options")]
1515 #[serde_as(deserialize_as = "DefaultOnNull")]
1516 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1517 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1518 pub config_options: Vec<InitialSessionConfigOption>,
1519 #[serde_as(deserialize_as = "DefaultOnError")]
1525 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1526 #[serde(default)]
1527 #[serde(rename = "_meta")]
1528 pub meta: Option<Meta>,
1529}
1530
1531impl LoadSessionRequest {
1532 #[must_use]
1534 pub fn new(session_id: impl Into<SessionId>, cwd: impl Into<PathBuf>) -> Self {
1535 Self {
1536 mcp_servers: vec![],
1537 cwd: cwd.into(),
1538 additional_directories: vec![],
1539 session_id: session_id.into(),
1540 system_prompt: None,
1541 #[cfg(feature = "unstable_session_options")]
1542 config_options: vec![],
1543 meta: None,
1544 }
1545 }
1546
1547 #[must_use]
1549 pub fn additional_directories(mut self, additional_directories: Vec<PathBuf>) -> Self {
1550 self.additional_directories = additional_directories;
1551 self
1552 }
1553
1554 #[must_use]
1556 pub fn mcp_servers(mut self, mcp_servers: Vec<McpServer>) -> Self {
1557 self.mcp_servers = mcp_servers;
1558 self
1559 }
1560
1561 #[must_use]
1563 pub fn system_prompt(mut self, system_prompt: impl IntoOption<SystemPrompt>) -> Self {
1564 self.system_prompt = system_prompt.into_option();
1565 self
1566 }
1567
1568 #[cfg(feature = "unstable_session_options")]
1584 #[must_use]
1585 pub fn config_options(mut self, config_options: Vec<InitialSessionConfigOption>) -> Self {
1586 self.config_options = config_options;
1587 self
1588 }
1589
1590 #[must_use]
1596 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1597 self.meta = meta.into_option();
1598 self
1599 }
1600}
1601
1602crate::serde_util::default_on_null! {
1603 #[serde_as]
1605 #[skip_serializing_none]
1606 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1607 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
1608 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_LOAD_METHOD_NAME)))]
1609 #[serde(rename_all = "camelCase")]
1610 #[non_exhaustive]
1611 pub struct LoadSessionResponse {
1612 #[serde_as(deserialize_as = "DefaultOnError")]
1616 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1617 #[serde(default)]
1618 pub modes: Option<SessionModeState>,
1619 #[serde_as(deserialize_as = "DefaultOnError<Option<VecSkipError<_>>>")]
1621 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
1622 #[serde(default)]
1623 pub config_options: Option<Vec<SessionConfigOption>>,
1624 #[serde_as(deserialize_as = "DefaultOnError")]
1630 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1631 #[serde(default)]
1632 #[serde(rename = "_meta")]
1633 pub meta: Option<Meta>,
1634 }
1635}
1636
1637impl LoadSessionResponse {
1638 #[must_use]
1640 pub fn new() -> Self {
1641 Self::default()
1642 }
1643
1644 #[must_use]
1648 pub fn modes(mut self, modes: impl IntoOption<SessionModeState>) -> Self {
1649 self.modes = modes.into_option();
1650 self
1651 }
1652
1653 #[must_use]
1655 pub fn config_options(
1656 mut self,
1657 config_options: impl IntoOption<Vec<SessionConfigOption>>,
1658 ) -> Self {
1659 self.config_options = config_options.into_option();
1660 self
1661 }
1662
1663 #[must_use]
1669 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1670 self.meta = meta.into_option();
1671 self
1672 }
1673}
1674
1675#[cfg(feature = "unstable_session_fork")]
1688#[serde_as]
1689#[skip_serializing_none]
1690#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1691#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1692#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_FORK_METHOD_NAME)))]
1693#[serde(rename_all = "camelCase")]
1694#[non_exhaustive]
1695pub struct ForkSessionRequest {
1696 pub session_id: SessionId,
1698 #[cfg(feature = "unstable_session_cursors")]
1711 #[serde(default)]
1712 pub cursor_id: Option<CursorId>,
1713 pub cwd: PathBuf,
1715 #[serde_as(deserialize_as = "DefaultOnNull")]
1721 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1722 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1723 pub additional_directories: Vec<PathBuf>,
1724 #[serde_as(deserialize_as = "DefaultOnNull")]
1726 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1727 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1728 pub mcp_servers: Vec<McpServer>,
1729 #[serde(default)]
1737 pub system_prompt: Option<SystemPrompt>,
1738 #[cfg(feature = "unstable_session_options")]
1757 #[serde_as(deserialize_as = "DefaultOnNull")]
1758 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1759 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1760 pub config_options: Vec<InitialSessionConfigOption>,
1761 #[serde_as(deserialize_as = "DefaultOnError")]
1767 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1768 #[serde(default)]
1769 #[serde(rename = "_meta")]
1770 pub meta: Option<Meta>,
1771}
1772
1773#[cfg(feature = "unstable_session_fork")]
1774impl ForkSessionRequest {
1775 #[must_use]
1777 pub fn new(session_id: impl Into<SessionId>, cwd: impl Into<PathBuf>) -> Self {
1778 Self {
1779 session_id: session_id.into(),
1780 #[cfg(feature = "unstable_session_cursors")]
1781 cursor_id: None,
1782 cwd: cwd.into(),
1783 additional_directories: vec![],
1784 mcp_servers: vec![],
1785 system_prompt: None,
1786 #[cfg(feature = "unstable_session_options")]
1787 config_options: vec![],
1788 meta: None,
1789 }
1790 }
1791
1792 #[cfg(feature = "unstable_session_cursors")]
1801 #[must_use]
1802 pub fn cursor_id(mut self, cursor_id: impl IntoOption<CursorId>) -> Self {
1803 self.cursor_id = cursor_id.into_option();
1804 self
1805 }
1806
1807 #[must_use]
1809 pub fn additional_directories(mut self, additional_directories: Vec<PathBuf>) -> Self {
1810 self.additional_directories = additional_directories;
1811 self
1812 }
1813
1814 #[must_use]
1816 pub fn mcp_servers(mut self, mcp_servers: Vec<McpServer>) -> Self {
1817 self.mcp_servers = mcp_servers;
1818 self
1819 }
1820
1821 #[must_use]
1823 pub fn system_prompt(mut self, system_prompt: impl IntoOption<SystemPrompt>) -> Self {
1824 self.system_prompt = system_prompt.into_option();
1825 self
1826 }
1827
1828 #[cfg(feature = "unstable_session_options")]
1847 #[must_use]
1848 pub fn config_options(mut self, config_options: Vec<InitialSessionConfigOption>) -> Self {
1849 self.config_options = config_options;
1850 self
1851 }
1852
1853 #[must_use]
1859 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1860 self.meta = meta.into_option();
1861 self
1862 }
1863}
1864
1865#[cfg(feature = "unstable_session_fork")]
1871#[serde_as]
1872#[skip_serializing_none]
1873#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1874#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1875#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_FORK_METHOD_NAME)))]
1876#[serde(rename_all = "camelCase")]
1877#[non_exhaustive]
1878pub struct ForkSessionResponse {
1879 pub session_id: SessionId,
1881 #[serde_as(deserialize_as = "DefaultOnError")]
1885 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1886 #[serde(default)]
1887 pub modes: Option<SessionModeState>,
1888 #[serde_as(deserialize_as = "DefaultOnError<Option<VecSkipError<_>>>")]
1890 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
1891 #[serde(default)]
1892 pub config_options: Option<Vec<SessionConfigOption>>,
1893 #[serde_as(deserialize_as = "DefaultOnError")]
1899 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1900 #[serde(default)]
1901 #[serde(rename = "_meta")]
1902 pub meta: Option<Meta>,
1903}
1904
1905#[cfg(feature = "unstable_session_fork")]
1906impl ForkSessionResponse {
1907 #[must_use]
1909 pub fn new(session_id: impl Into<SessionId>) -> Self {
1910 Self {
1911 session_id: session_id.into(),
1912 modes: None,
1913 config_options: None,
1914 meta: None,
1915 }
1916 }
1917
1918 #[must_use]
1922 pub fn modes(mut self, modes: impl IntoOption<SessionModeState>) -> Self {
1923 self.modes = modes.into_option();
1924 self
1925 }
1926
1927 #[must_use]
1929 pub fn config_options(
1930 mut self,
1931 config_options: impl IntoOption<Vec<SessionConfigOption>>,
1932 ) -> Self {
1933 self.config_options = config_options.into_option();
1934 self
1935 }
1936
1937 #[must_use]
1943 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1944 self.meta = meta.into_option();
1945 self
1946 }
1947}
1948
1949#[serde_as]
1958#[skip_serializing_none]
1959#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1960#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1961#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_RESUME_METHOD_NAME)))]
1962#[serde(rename_all = "camelCase")]
1963#[non_exhaustive]
1964pub struct ResumeSessionRequest {
1965 pub session_id: SessionId,
1967 pub cwd: PathBuf,
1969 #[serde_as(deserialize_as = "DefaultOnNull")]
1976 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1977 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1978 pub additional_directories: Vec<PathBuf>,
1979 #[serde_as(deserialize_as = "DefaultOnNull")]
1981 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1982 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1983 pub mcp_servers: Vec<McpServer>,
1984 #[serde(default)]
1992 pub system_prompt: Option<SystemPrompt>,
1993 #[cfg(feature = "unstable_session_options")]
2009 #[serde_as(deserialize_as = "DefaultOnNull")]
2010 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
2011 #[serde(default, skip_serializing_if = "Vec::is_empty")]
2012 pub config_options: Vec<InitialSessionConfigOption>,
2013 #[serde_as(deserialize_as = "DefaultOnError")]
2019 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2020 #[serde(default)]
2021 #[serde(rename = "_meta")]
2022 pub meta: Option<Meta>,
2023}
2024
2025impl ResumeSessionRequest {
2026 #[must_use]
2028 pub fn new(session_id: impl Into<SessionId>, cwd: impl Into<PathBuf>) -> Self {
2029 Self {
2030 session_id: session_id.into(),
2031 cwd: cwd.into(),
2032 additional_directories: vec![],
2033 mcp_servers: vec![],
2034 system_prompt: None,
2035 #[cfg(feature = "unstable_session_options")]
2036 config_options: vec![],
2037 meta: None,
2038 }
2039 }
2040
2041 #[must_use]
2043 pub fn additional_directories(mut self, additional_directories: Vec<PathBuf>) -> Self {
2044 self.additional_directories = additional_directories;
2045 self
2046 }
2047
2048 #[must_use]
2050 pub fn mcp_servers(mut self, mcp_servers: Vec<McpServer>) -> Self {
2051 self.mcp_servers = mcp_servers;
2052 self
2053 }
2054
2055 #[must_use]
2057 pub fn system_prompt(mut self, system_prompt: impl IntoOption<SystemPrompt>) -> Self {
2058 self.system_prompt = system_prompt.into_option();
2059 self
2060 }
2061
2062 #[cfg(feature = "unstable_session_options")]
2078 #[must_use]
2079 pub fn config_options(mut self, config_options: Vec<InitialSessionConfigOption>) -> Self {
2080 self.config_options = config_options;
2081 self
2082 }
2083
2084 #[must_use]
2090 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2091 self.meta = meta.into_option();
2092 self
2093 }
2094}
2095
2096crate::serde_util::default_on_null! {
2097 #[serde_as]
2099 #[skip_serializing_none]
2100 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2101 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2102 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_RESUME_METHOD_NAME)))]
2103 #[serde(rename_all = "camelCase")]
2104 #[non_exhaustive]
2105 pub struct ResumeSessionResponse {
2106 #[serde_as(deserialize_as = "DefaultOnError")]
2110 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2111 #[serde(default)]
2112 pub modes: Option<SessionModeState>,
2113 #[serde_as(deserialize_as = "DefaultOnError<Option<VecSkipError<_>>>")]
2115 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
2116 #[serde(default)]
2117 pub config_options: Option<Vec<SessionConfigOption>>,
2118 #[serde_as(deserialize_as = "DefaultOnError")]
2124 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2125 #[serde(default)]
2126 #[serde(rename = "_meta")]
2127 pub meta: Option<Meta>,
2128 }
2129}
2130
2131impl ResumeSessionResponse {
2132 #[must_use]
2134 pub fn new() -> Self {
2135 Self::default()
2136 }
2137
2138 #[must_use]
2142 pub fn modes(mut self, modes: impl IntoOption<SessionModeState>) -> Self {
2143 self.modes = modes.into_option();
2144 self
2145 }
2146
2147 #[must_use]
2149 pub fn config_options(
2150 mut self,
2151 config_options: impl IntoOption<Vec<SessionConfigOption>>,
2152 ) -> Self {
2153 self.config_options = config_options.into_option();
2154 self
2155 }
2156
2157 #[must_use]
2163 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2164 self.meta = meta.into_option();
2165 self
2166 }
2167}
2168
2169#[serde_as]
2179#[skip_serializing_none]
2180#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2181#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2182#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_CLOSE_METHOD_NAME)))]
2183#[serde(rename_all = "camelCase")]
2184#[non_exhaustive]
2185pub struct CloseSessionRequest {
2186 pub session_id: SessionId,
2188 #[serde_as(deserialize_as = "DefaultOnError")]
2194 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2195 #[serde(default)]
2196 #[serde(rename = "_meta")]
2197 pub meta: Option<Meta>,
2198}
2199
2200impl CloseSessionRequest {
2201 #[must_use]
2203 pub fn new(session_id: impl Into<SessionId>) -> Self {
2204 Self {
2205 session_id: session_id.into(),
2206 meta: None,
2207 }
2208 }
2209
2210 #[must_use]
2216 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2217 self.meta = meta.into_option();
2218 self
2219 }
2220}
2221
2222crate::serde_util::default_on_null! {
2223 #[serde_as]
2225 #[skip_serializing_none]
2226 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2227 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2228 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_CLOSE_METHOD_NAME)))]
2229 #[serde(rename_all = "camelCase")]
2230 #[non_exhaustive]
2231 pub struct CloseSessionResponse {
2232 #[serde_as(deserialize_as = "DefaultOnError")]
2238 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2239 #[serde(default)]
2240 #[serde(rename = "_meta")]
2241 pub meta: Option<Meta>,
2242 }
2243}
2244
2245impl CloseSessionResponse {
2246 #[must_use]
2248 pub fn new() -> Self {
2249 Self::default()
2250 }
2251
2252 #[must_use]
2258 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2259 self.meta = meta.into_option();
2260 self
2261 }
2262}
2263
2264#[cfg(feature = "unstable_session_status")]
2278#[serde_as]
2279#[skip_serializing_none]
2280#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2281#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2282#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_STATUS_METHOD_NAME)))]
2283#[serde(rename_all = "camelCase")]
2284#[non_exhaustive]
2285pub struct SessionStatusRequest {
2286 pub session_id: SessionId,
2288 #[serde_as(deserialize_as = "DefaultOnError")]
2294 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2295 #[serde(default)]
2296 #[serde(rename = "_meta")]
2297 pub meta: Option<Meta>,
2298}
2299
2300#[cfg(feature = "unstable_session_status")]
2301impl SessionStatusRequest {
2302 #[must_use]
2304 pub fn new(session_id: impl Into<SessionId>) -> Self {
2305 Self {
2306 session_id: session_id.into(),
2307 meta: None,
2308 }
2309 }
2310
2311 #[must_use]
2317 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2318 self.meta = meta.into_option();
2319 self
2320 }
2321}
2322
2323#[cfg(feature = "unstable_session_status")]
2332#[serde_as]
2333#[skip_serializing_none]
2334#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2335#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2336#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_STATUS_METHOD_NAME)))]
2337#[serde(rename_all = "camelCase")]
2338#[non_exhaustive]
2339pub struct SessionStatusResponse {
2340 pub status: SessionStatus,
2344 #[serde_as(deserialize_as = "DefaultOnError")]
2350 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2351 #[serde(default)]
2352 #[serde(rename = "_meta")]
2353 pub meta: Option<Meta>,
2354}
2355
2356#[cfg(feature = "unstable_session_status")]
2357impl SessionStatusResponse {
2358 #[must_use]
2360 pub fn new(status: SessionStatus) -> Self {
2361 Self { status, meta: None }
2362 }
2363
2364 #[must_use]
2370 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2371 self.meta = meta.into_option();
2372 self
2373 }
2374}
2375
2376#[cfg(feature = "unstable_session_status")]
2382#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2383#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2384#[serde(rename_all = "snake_case")]
2385#[non_exhaustive]
2386pub enum SessionStatus {
2387 Open,
2394 Saved,
2398 #[serde(untagged)]
2405 Other(String),
2406}
2407
2408#[cfg(feature = "unstable_session_options")]
2422#[serde_as]
2423#[skip_serializing_none]
2424#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2425#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2426#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_OPTIONS_METHOD_NAME)))]
2427#[serde(rename_all = "camelCase")]
2428#[non_exhaustive]
2429pub struct SessionOptionsRequest {
2430 pub cwd: PathBuf,
2432 #[serde_as(deserialize_as = "DefaultOnNull")]
2436 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
2437 #[serde(default, skip_serializing_if = "Vec::is_empty")]
2438 pub additional_directories: Vec<PathBuf>,
2439 #[serde(default)]
2448 pub session_id: Option<SessionId>,
2449 #[serde_as(deserialize_as = "DefaultOnError")]
2455 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2456 #[serde(default)]
2457 #[serde(rename = "_meta")]
2458 pub meta: Option<Meta>,
2459}
2460
2461#[cfg(feature = "unstable_session_options")]
2462impl SessionOptionsRequest {
2463 #[must_use]
2465 pub fn new(cwd: impl Into<PathBuf>) -> Self {
2466 Self {
2467 cwd: cwd.into(),
2468 additional_directories: vec![],
2469 session_id: None,
2470 meta: None,
2471 }
2472 }
2473
2474 #[must_use]
2476 pub fn additional_directories(mut self, additional_directories: Vec<PathBuf>) -> Self {
2477 self.additional_directories = additional_directories;
2478 self
2479 }
2480
2481 #[must_use]
2483 pub fn session_id(mut self, session_id: impl IntoOption<SessionId>) -> Self {
2484 self.session_id = session_id.into_option();
2485 self
2486 }
2487
2488 #[must_use]
2494 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2495 self.meta = meta.into_option();
2496 self
2497 }
2498}
2499
2500#[cfg(feature = "unstable_session_options")]
2501crate::serde_util::default_on_null! {
2502 #[serde_as]
2514 #[skip_serializing_none]
2515 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2516 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2517 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_OPTIONS_METHOD_NAME)))]
2518 #[serde(rename_all = "camelCase")]
2519 #[non_exhaustive]
2520 pub struct SessionOptionsResponse {
2521 #[serde_as(deserialize_as = "DefaultOnError")]
2525 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2526 #[serde(default)]
2527 pub modes: Option<SessionModeState>,
2528 #[serde_as(deserialize_as = "DefaultOnError<Option<VecSkipError<_>>>")]
2533 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
2534 #[serde(default)]
2535 pub config_options: Option<Vec<SessionConfigOption>>,
2536 #[serde_as(deserialize_as = "DefaultOnError")]
2542 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2543 #[serde(default)]
2544 #[serde(rename = "_meta")]
2545 pub meta: Option<Meta>,
2546 }
2547}
2548
2549#[cfg(feature = "unstable_session_options")]
2550impl SessionOptionsResponse {
2551 #[must_use]
2553 pub fn new() -> Self {
2554 Self::default()
2555 }
2556
2557 #[must_use]
2561 pub fn modes(mut self, modes: impl IntoOption<SessionModeState>) -> Self {
2562 self.modes = modes.into_option();
2563 self
2564 }
2565
2566 #[must_use]
2568 pub fn config_options(
2569 mut self,
2570 config_options: impl IntoOption<Vec<SessionConfigOption>>,
2571 ) -> Self {
2572 self.config_options = config_options.into_option();
2573 self
2574 }
2575
2576 #[must_use]
2582 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2583 self.meta = meta.into_option();
2584 self
2585 }
2586}
2587
2588#[cfg(feature = "unstable_session_options")]
2601#[serde_as]
2602#[skip_serializing_none]
2603#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2604#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2605#[serde(rename_all = "camelCase")]
2606#[non_exhaustive]
2607pub struct InitialSessionConfigOption {
2608 pub config_id: SessionConfigId,
2610 #[serde(flatten)]
2615 pub value: SessionConfigOptionValue,
2616 #[serde_as(deserialize_as = "DefaultOnError")]
2622 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2623 #[serde(default)]
2624 #[serde(rename = "_meta")]
2625 pub meta: Option<Meta>,
2626}
2627
2628#[cfg(feature = "unstable_session_options")]
2629impl InitialSessionConfigOption {
2630 #[must_use]
2632 pub fn new(
2633 config_id: impl Into<SessionConfigId>,
2634 value: impl Into<SessionConfigOptionValue>,
2635 ) -> Self {
2636 Self {
2637 config_id: config_id.into(),
2638 value: value.into(),
2639 meta: None,
2640 }
2641 }
2642
2643 #[must_use]
2649 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2650 self.meta = meta.into_option();
2651 self
2652 }
2653}
2654
2655crate::serde_util::default_on_null! {
2658 #[serde_as]
2662 #[skip_serializing_none]
2663 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2664 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2665 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_LIST_METHOD_NAME)))]
2666 #[serde(rename_all = "camelCase")]
2667 #[non_exhaustive]
2668 pub struct ListSessionsRequest {
2669 #[serde(default)]
2671 pub cwd: Option<PathBuf>,
2672 #[serde(default)]
2674 pub cursor: Option<String>,
2675 #[cfg(feature = "unstable_session_archive")]
2685 #[serde(default)]
2686 pub archived: Option<SessionArchiveFilter>,
2687 #[serde_as(deserialize_as = "DefaultOnError")]
2693 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2694 #[serde(default)]
2695 #[serde(rename = "_meta")]
2696 pub meta: Option<Meta>,
2697 }
2698}
2699
2700impl ListSessionsRequest {
2701 #[must_use]
2703 pub fn new() -> Self {
2704 Self::default()
2705 }
2706
2707 #[must_use]
2709 pub fn cwd(mut self, cwd: impl IntoOption<PathBuf>) -> Self {
2710 self.cwd = cwd.into_option();
2711 self
2712 }
2713
2714 #[must_use]
2716 pub fn cursor(mut self, cursor: impl IntoOption<String>) -> Self {
2717 self.cursor = cursor.into_option();
2718 self
2719 }
2720
2721 #[cfg(feature = "unstable_session_archive")]
2727 #[must_use]
2728 pub fn archived(mut self, archived: impl IntoOption<SessionArchiveFilter>) -> Self {
2729 self.archived = archived.into_option();
2730 self
2731 }
2732
2733 #[must_use]
2739 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2740 self.meta = meta.into_option();
2741 self
2742 }
2743}
2744
2745#[serde_as]
2747#[skip_serializing_none]
2748#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2749#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2750#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_LIST_METHOD_NAME)))]
2751#[serde(rename_all = "camelCase")]
2752#[non_exhaustive]
2753pub struct ListSessionsResponse {
2754 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
2756 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
2757 pub sessions: Vec<SessionInfo>,
2758 #[serde_as(deserialize_as = "DefaultOnError")]
2761 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2762 #[serde(default)]
2763 pub next_cursor: Option<String>,
2764 #[serde_as(deserialize_as = "DefaultOnError")]
2770 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2771 #[serde(default)]
2772 #[serde(rename = "_meta")]
2773 pub meta: Option<Meta>,
2774}
2775
2776impl ListSessionsResponse {
2777 #[must_use]
2779 pub fn new(sessions: Vec<SessionInfo>) -> Self {
2780 Self {
2781 sessions,
2782 next_cursor: None,
2783 meta: None,
2784 }
2785 }
2786
2787 #[must_use]
2789 pub fn next_cursor(mut self, next_cursor: impl IntoOption<String>) -> Self {
2790 self.next_cursor = next_cursor.into_option();
2791 self
2792 }
2793
2794 #[must_use]
2800 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2801 self.meta = meta.into_option();
2802 self
2803 }
2804}
2805
2806#[serde_as]
2812#[skip_serializing_none]
2813#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2814#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2815#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_DELETE_METHOD_NAME)))]
2816#[serde(rename_all = "camelCase")]
2817#[non_exhaustive]
2818pub struct DeleteSessionRequest {
2819 pub session_id: SessionId,
2821 #[serde_as(deserialize_as = "DefaultOnError")]
2827 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2828 #[serde(default)]
2829 #[serde(rename = "_meta")]
2830 pub meta: Option<Meta>,
2831}
2832
2833impl DeleteSessionRequest {
2834 #[must_use]
2836 pub fn new(session_id: impl Into<SessionId>) -> Self {
2837 Self {
2838 session_id: session_id.into(),
2839 meta: None,
2840 }
2841 }
2842
2843 #[must_use]
2849 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2850 self.meta = meta.into_option();
2851 self
2852 }
2853}
2854
2855crate::serde_util::default_on_null! {
2856 #[serde_as]
2858 #[skip_serializing_none]
2859 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2860 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2861 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_DELETE_METHOD_NAME)))]
2862 #[serde(rename_all = "camelCase")]
2863 #[non_exhaustive]
2864 pub struct DeleteSessionResponse {
2865 #[serde_as(deserialize_as = "DefaultOnError")]
2871 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2872 #[serde(default)]
2873 #[serde(rename = "_meta")]
2874 pub meta: Option<Meta>,
2875 }
2876}
2877
2878impl DeleteSessionResponse {
2879 #[must_use]
2881 pub fn new() -> Self {
2882 Self::default()
2883 }
2884
2885 #[must_use]
2891 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2892 self.meta = meta.into_option();
2893 self
2894 }
2895}
2896
2897#[cfg(feature = "unstable_session_archive")]
2913#[serde_as]
2914#[skip_serializing_none]
2915#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2916#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2917#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_ARCHIVE_METHOD_NAME)))]
2918#[serde(rename_all = "camelCase")]
2919#[non_exhaustive]
2920pub struct ArchiveSessionRequest {
2921 pub session_id: SessionId,
2923 #[serde_as(deserialize_as = "DefaultOnError")]
2929 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2930 #[serde(default)]
2931 #[serde(rename = "_meta")]
2932 pub meta: Option<Meta>,
2933}
2934
2935#[cfg(feature = "unstable_session_archive")]
2936impl ArchiveSessionRequest {
2937 #[must_use]
2939 pub fn new(session_id: impl Into<SessionId>) -> Self {
2940 Self {
2941 session_id: session_id.into(),
2942 meta: None,
2943 }
2944 }
2945
2946 #[must_use]
2952 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2953 self.meta = meta.into_option();
2954 self
2955 }
2956}
2957
2958#[cfg(feature = "unstable_session_archive")]
2959crate::serde_util::default_on_null! {
2960 #[serde_as]
2966 #[skip_serializing_none]
2967 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2968 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2969 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_ARCHIVE_METHOD_NAME)))]
2970 #[serde(rename_all = "camelCase")]
2971 #[non_exhaustive]
2972 pub struct ArchiveSessionResponse {
2973 #[serde_as(deserialize_as = "DefaultOnError")]
2979 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2980 #[serde(default)]
2981 #[serde(rename = "_meta")]
2982 pub meta: Option<Meta>,
2983 }
2984}
2985
2986#[cfg(feature = "unstable_session_archive")]
2987impl ArchiveSessionResponse {
2988 #[must_use]
2990 pub fn new() -> Self {
2991 Self::default()
2992 }
2993
2994 #[must_use]
3000 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3001 self.meta = meta.into_option();
3002 self
3003 }
3004}
3005
3006#[cfg(feature = "unstable_session_archive")]
3021#[serde_as]
3022#[skip_serializing_none]
3023#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3024#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3025#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_UNARCHIVE_METHOD_NAME)))]
3026#[serde(rename_all = "camelCase")]
3027#[non_exhaustive]
3028pub struct UnarchiveSessionRequest {
3029 pub session_id: SessionId,
3031 #[serde_as(deserialize_as = "DefaultOnError")]
3037 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3038 #[serde(default)]
3039 #[serde(rename = "_meta")]
3040 pub meta: Option<Meta>,
3041}
3042
3043#[cfg(feature = "unstable_session_archive")]
3044impl UnarchiveSessionRequest {
3045 #[must_use]
3047 pub fn new(session_id: impl Into<SessionId>) -> Self {
3048 Self {
3049 session_id: session_id.into(),
3050 meta: None,
3051 }
3052 }
3053
3054 #[must_use]
3060 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3061 self.meta = meta.into_option();
3062 self
3063 }
3064}
3065
3066#[cfg(feature = "unstable_session_archive")]
3067crate::serde_util::default_on_null! {
3068 #[serde_as]
3074 #[skip_serializing_none]
3075 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3076 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
3077 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_UNARCHIVE_METHOD_NAME)))]
3078 #[serde(rename_all = "camelCase")]
3079 #[non_exhaustive]
3080 pub struct UnarchiveSessionResponse {
3081 #[serde_as(deserialize_as = "DefaultOnError")]
3087 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3088 #[serde(default)]
3089 #[serde(rename = "_meta")]
3090 pub meta: Option<Meta>,
3091 }
3092}
3093
3094#[cfg(feature = "unstable_session_archive")]
3095impl UnarchiveSessionResponse {
3096 #[must_use]
3098 pub fn new() -> Self {
3099 Self::default()
3100 }
3101
3102 #[must_use]
3108 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3109 self.meta = meta.into_option();
3110 self
3111 }
3112}
3113
3114#[cfg(feature = "unstable_session_archive")]
3123#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3124#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
3125#[serde(rename_all = "snake_case")]
3126#[non_exhaustive]
3127pub enum SessionArchiveFilter {
3128 #[default]
3130 Exclude,
3131 Include,
3133 Only,
3135 #[serde(untagged)]
3141 Other(String),
3142}
3143
3144#[serde_as]
3146#[skip_serializing_none]
3147#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3148#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3149#[serde(rename_all = "camelCase")]
3150#[non_exhaustive]
3151pub struct SessionInfo {
3152 pub session_id: SessionId,
3154 pub cwd: PathBuf,
3156 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
3162 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
3163 #[serde(default, skip_serializing_if = "Vec::is_empty")]
3164 pub additional_directories: Vec<PathBuf>,
3165
3166 #[serde_as(deserialize_as = "DefaultOnError")]
3168 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3169 #[serde(default)]
3170 pub title: Option<String>,
3171 #[serde_as(deserialize_as = "DefaultOnError")]
3173 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3174 #[serde(default)]
3175 pub updated_at: Option<String>,
3176 #[cfg(feature = "unstable_session_archive")]
3185 #[serde_as(deserialize_as = "DefaultOnError")]
3186 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3187 #[serde(default)]
3188 pub archived: Option<bool>,
3189 #[serde_as(deserialize_as = "DefaultOnError")]
3195 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3196 #[serde(default)]
3197 #[serde(rename = "_meta")]
3198 pub meta: Option<Meta>,
3199}
3200
3201impl SessionInfo {
3202 #[must_use]
3204 pub fn new(session_id: impl Into<SessionId>, cwd: impl Into<PathBuf>) -> Self {
3205 Self {
3206 session_id: session_id.into(),
3207 cwd: cwd.into(),
3208 additional_directories: vec![],
3209 title: None,
3210 updated_at: None,
3211 #[cfg(feature = "unstable_session_archive")]
3212 archived: None,
3213 meta: None,
3214 }
3215 }
3216
3217 #[must_use]
3219 pub fn additional_directories(mut self, additional_directories: Vec<PathBuf>) -> Self {
3220 self.additional_directories = additional_directories;
3221 self
3222 }
3223
3224 #[must_use]
3226 pub fn title(mut self, title: impl IntoOption<String>) -> Self {
3227 self.title = title.into_option();
3228 self
3229 }
3230
3231 #[must_use]
3233 pub fn updated_at(mut self, updated_at: impl IntoOption<String>) -> Self {
3234 self.updated_at = updated_at.into_option();
3235 self
3236 }
3237
3238 #[cfg(feature = "unstable_session_archive")]
3244 #[must_use]
3245 pub fn archived(mut self, archived: impl IntoOption<bool>) -> Self {
3246 self.archived = archived.into_option();
3247 self
3248 }
3249
3250 #[must_use]
3256 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3257 self.meta = meta.into_option();
3258 self
3259 }
3260}
3261
3262#[cfg(feature = "unstable_session_set_title")]
3278#[serde_as]
3279#[skip_serializing_none]
3280#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3281#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3282#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_TITLE_METHOD_NAME)))]
3283#[serde(rename_all = "camelCase")]
3284#[non_exhaustive]
3285pub struct SetSessionTitleRequest {
3286 pub session_id: SessionId,
3288 pub title: String,
3295 #[serde_as(deserialize_as = "DefaultOnError")]
3301 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3302 #[serde(default)]
3303 #[serde(rename = "_meta")]
3304 pub meta: Option<Meta>,
3305}
3306
3307#[cfg(feature = "unstable_session_set_title")]
3308impl SetSessionTitleRequest {
3309 #[must_use]
3311 pub fn new(session_id: impl Into<SessionId>, title: impl Into<String>) -> Self {
3312 Self {
3313 session_id: session_id.into(),
3314 title: title.into(),
3315 meta: None,
3316 }
3317 }
3318
3319 #[must_use]
3325 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3326 self.meta = meta.into_option();
3327 self
3328 }
3329}
3330
3331#[cfg(feature = "unstable_session_set_title")]
3337#[serde_as]
3338#[skip_serializing_none]
3339#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3340#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3341#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_TITLE_METHOD_NAME)))]
3342#[serde(rename_all = "camelCase")]
3343#[non_exhaustive]
3344pub struct SetSessionTitleResponse {
3345 pub title: String,
3350 #[serde_as(deserialize_as = "DefaultOnError")]
3356 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3357 #[serde(default)]
3358 #[serde(rename = "_meta")]
3359 pub meta: Option<Meta>,
3360}
3361
3362#[cfg(feature = "unstable_session_set_title")]
3363impl SetSessionTitleResponse {
3364 #[must_use]
3366 pub fn new(title: impl Into<String>) -> Self {
3367 Self {
3368 title: title.into(),
3369 meta: None,
3370 }
3371 }
3372
3373 #[must_use]
3379 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3380 self.meta = meta.into_option();
3381 self
3382 }
3383}
3384
3385#[serde_as]
3389#[skip_serializing_none]
3390#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3391#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3392#[serde(rename_all = "camelCase")]
3393#[non_exhaustive]
3394pub struct SessionModeState {
3395 pub current_mode_id: SessionModeId,
3397 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
3399 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
3400 pub available_modes: Vec<SessionMode>,
3401 #[serde_as(deserialize_as = "DefaultOnError")]
3407 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3408 #[serde(default)]
3409 #[serde(rename = "_meta")]
3410 pub meta: Option<Meta>,
3411}
3412
3413impl SessionModeState {
3414 #[must_use]
3416 pub fn new(
3417 current_mode_id: impl Into<SessionModeId>,
3418 available_modes: Vec<SessionMode>,
3419 ) -> Self {
3420 Self {
3421 current_mode_id: current_mode_id.into(),
3422 available_modes,
3423 meta: None,
3424 }
3425 }
3426
3427 #[must_use]
3433 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3434 self.meta = meta.into_option();
3435 self
3436 }
3437}
3438
3439#[serde_as]
3443#[skip_serializing_none]
3444#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3445#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3446#[serde(rename_all = "camelCase")]
3447#[non_exhaustive]
3448pub struct SessionMode {
3449 pub id: SessionModeId,
3451 pub name: String,
3453 #[serde_as(deserialize_as = "DefaultOnError")]
3455 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3456 #[serde(default)]
3457 pub description: Option<String>,
3458 #[serde_as(deserialize_as = "DefaultOnError")]
3464 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3465 #[serde(default)]
3466 #[serde(rename = "_meta")]
3467 pub meta: Option<Meta>,
3468}
3469
3470impl SessionMode {
3471 #[must_use]
3473 pub fn new(id: impl Into<SessionModeId>, name: impl Into<String>) -> Self {
3474 Self {
3475 id: id.into(),
3476 name: name.into(),
3477 description: None,
3478 meta: None,
3479 }
3480 }
3481
3482 #[must_use]
3484 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
3485 self.description = description.into_option();
3486 self
3487 }
3488
3489 #[must_use]
3495 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3496 self.meta = meta.into_option();
3497 self
3498 }
3499}
3500
3501#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3503#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, From, Display)]
3504#[serde(transparent)]
3505#[from(Arc<str>, String, &'static str)]
3506#[non_exhaustive]
3507pub struct SessionModeId(pub Arc<str>);
3508
3509impl SessionModeId {
3510 #[must_use]
3512 pub fn new(id: impl Into<Arc<str>>) -> Self {
3513 Self(id.into())
3514 }
3515}
3516
3517#[serde_as]
3519#[skip_serializing_none]
3520#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3521#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3522#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_MODE_METHOD_NAME)))]
3523#[serde(rename_all = "camelCase")]
3524#[non_exhaustive]
3525pub struct SetSessionModeRequest {
3526 pub session_id: SessionId,
3528 pub mode_id: SessionModeId,
3530 #[serde_as(deserialize_as = "DefaultOnError")]
3536 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3537 #[serde(default)]
3538 #[serde(rename = "_meta")]
3539 pub meta: Option<Meta>,
3540}
3541
3542impl SetSessionModeRequest {
3543 #[must_use]
3545 pub fn new(session_id: impl Into<SessionId>, mode_id: impl Into<SessionModeId>) -> Self {
3546 Self {
3547 session_id: session_id.into(),
3548 mode_id: mode_id.into(),
3549 meta: None,
3550 }
3551 }
3552
3553 #[must_use]
3555 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3556 self.meta = meta.into_option();
3557 self
3558 }
3559}
3560
3561crate::serde_util::default_on_null! {
3562 #[serde_as]
3564 #[skip_serializing_none]
3565 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3566 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
3567 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_MODE_METHOD_NAME)))]
3568 #[serde(rename_all = "camelCase")]
3569 #[non_exhaustive]
3570 pub struct SetSessionModeResponse {
3571 #[serde_as(deserialize_as = "DefaultOnError")]
3577 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3578 #[serde(default)]
3579 #[serde(rename = "_meta")]
3580 pub meta: Option<Meta>,
3581 }
3582}
3583
3584impl SetSessionModeResponse {
3585 #[must_use]
3587 pub fn new() -> Self {
3588 Self::default()
3589 }
3590
3591 #[must_use]
3597 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3598 self.meta = meta.into_option();
3599 self
3600 }
3601}
3602
3603#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3607#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, From, Display)]
3608#[serde(transparent)]
3609#[from(Arc<str>, String, &'static str)]
3610#[non_exhaustive]
3611pub struct SessionConfigId(pub Arc<str>);
3612
3613impl SessionConfigId {
3614 #[must_use]
3616 pub fn new(id: impl Into<Arc<str>>) -> Self {
3617 Self(id.into())
3618 }
3619}
3620
3621#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3623#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, From, Display)]
3624#[serde(transparent)]
3625#[from(Arc<str>, String, &'static str)]
3626#[non_exhaustive]
3627pub struct SessionConfigValueId(pub Arc<str>);
3628
3629impl SessionConfigValueId {
3630 #[must_use]
3632 pub fn new(id: impl Into<Arc<str>>) -> Self {
3633 Self(id.into())
3634 }
3635}
3636
3637#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3639#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, From, Display)]
3640#[serde(transparent)]
3641#[from(Arc<str>, String, &'static str)]
3642#[non_exhaustive]
3643pub struct SessionConfigGroupId(pub Arc<str>);
3644
3645impl SessionConfigGroupId {
3646 #[must_use]
3648 pub fn new(id: impl Into<Arc<str>>) -> Self {
3649 Self(id.into())
3650 }
3651}
3652
3653#[serde_as]
3655#[skip_serializing_none]
3656#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3657#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3658#[serde(rename_all = "camelCase")]
3659#[non_exhaustive]
3660pub struct SessionConfigSelectOption {
3661 pub value: SessionConfigValueId,
3663 pub name: String,
3665 #[serde_as(deserialize_as = "DefaultOnError")]
3667 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3668 #[serde(default)]
3669 pub description: Option<String>,
3670 #[serde_as(deserialize_as = "DefaultOnError")]
3676 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3677 #[serde(default)]
3678 #[serde(rename = "_meta")]
3679 pub meta: Option<Meta>,
3680}
3681
3682impl SessionConfigSelectOption {
3683 #[must_use]
3685 pub fn new(value: impl Into<SessionConfigValueId>, name: impl Into<String>) -> Self {
3686 Self {
3687 value: value.into(),
3688 name: name.into(),
3689 description: None,
3690 meta: None,
3691 }
3692 }
3693
3694 #[must_use]
3696 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
3697 self.description = description.into_option();
3698 self
3699 }
3700
3701 #[must_use]
3707 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3708 self.meta = meta.into_option();
3709 self
3710 }
3711}
3712
3713#[serde_as]
3715#[skip_serializing_none]
3716#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3717#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3718#[serde(rename_all = "camelCase")]
3719#[non_exhaustive]
3720pub struct SessionConfigSelectGroup {
3721 pub group: SessionConfigGroupId,
3723 pub name: String,
3725 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
3727 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
3728 pub options: Vec<SessionConfigSelectOption>,
3729 #[serde_as(deserialize_as = "DefaultOnError")]
3735 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3736 #[serde(default)]
3737 #[serde(rename = "_meta")]
3738 pub meta: Option<Meta>,
3739}
3740
3741impl SessionConfigSelectGroup {
3742 #[must_use]
3744 pub fn new(
3745 group: impl Into<SessionConfigGroupId>,
3746 name: impl Into<String>,
3747 options: Vec<SessionConfigSelectOption>,
3748 ) -> Self {
3749 Self {
3750 group: group.into(),
3751 name: name.into(),
3752 options,
3753 meta: None,
3754 }
3755 }
3756
3757 #[must_use]
3763 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3764 self.meta = meta.into_option();
3765 self
3766 }
3767}
3768
3769#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3771#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3772#[serde(untagged)]
3773#[non_exhaustive]
3774pub enum SessionConfigSelectOptions {
3775 Ungrouped(Vec<SessionConfigSelectOption>),
3777 Grouped(Vec<SessionConfigSelectGroup>),
3779}
3780
3781impl From<Vec<SessionConfigSelectOption>> for SessionConfigSelectOptions {
3782 fn from(options: Vec<SessionConfigSelectOption>) -> Self {
3783 SessionConfigSelectOptions::Ungrouped(options)
3784 }
3785}
3786
3787impl From<Vec<SessionConfigSelectGroup>> for SessionConfigSelectOptions {
3788 fn from(groups: Vec<SessionConfigSelectGroup>) -> Self {
3789 SessionConfigSelectOptions::Grouped(groups)
3790 }
3791}
3792
3793#[skip_serializing_none]
3795#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3796#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3797#[serde(rename_all = "camelCase")]
3798#[non_exhaustive]
3799pub struct SessionConfigSelect {
3800 pub current_value: SessionConfigValueId,
3802 pub options: SessionConfigSelectOptions,
3804}
3805
3806impl SessionConfigSelect {
3807 #[must_use]
3809 pub fn new(
3810 current_value: impl Into<SessionConfigValueId>,
3811 options: impl Into<SessionConfigSelectOptions>,
3812 ) -> Self {
3813 Self {
3814 current_value: current_value.into(),
3815 options: options.into(),
3816 }
3817 }
3818}
3819
3820#[skip_serializing_none]
3822#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3823#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3824#[serde(rename_all = "camelCase")]
3825#[non_exhaustive]
3826pub struct SessionConfigBoolean {
3827 pub current_value: bool,
3829}
3830
3831impl SessionConfigBoolean {
3832 #[must_use]
3834 pub fn new(current_value: bool) -> Self {
3835 Self { current_value }
3836 }
3837}
3838
3839#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3849#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3850#[serde(rename_all = "snake_case")]
3851#[non_exhaustive]
3852pub enum SessionConfigOptionCategory {
3853 Mode,
3855 Model,
3857 ModelConfig,
3859 #[cfg(feature = "unstable_speed_config_category")]
3865 Speed,
3866 ThoughtLevel,
3868 #[serde(untagged)]
3870 Other(String),
3871}
3872
3873#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3875#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3876#[serde(tag = "type", rename_all = "snake_case")]
3877#[cfg_attr(feature = "schemars", schemars(extend("discriminator" = {"propertyName": "type"})))]
3878#[non_exhaustive]
3879pub enum SessionConfigKind {
3880 Select(SessionConfigSelect),
3882 Boolean(SessionConfigBoolean),
3884}
3885
3886#[serde_as]
3888#[skip_serializing_none]
3889#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3890#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3891#[serde(rename_all = "camelCase")]
3892#[non_exhaustive]
3893pub struct SessionConfigOption {
3894 pub id: SessionConfigId,
3896 pub name: String,
3898 #[serde_as(deserialize_as = "DefaultOnError")]
3900 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3901 #[serde(default)]
3902 pub description: Option<String>,
3903 #[serde_as(deserialize_as = "DefaultOnError")]
3905 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3906 #[serde(default)]
3907 pub category: Option<SessionConfigOptionCategory>,
3908 #[serde(flatten)]
3910 pub kind: SessionConfigKind,
3911 #[serde_as(deserialize_as = "DefaultOnError")]
3917 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3918 #[serde(default)]
3919 #[serde(rename = "_meta")]
3920 pub meta: Option<Meta>,
3921}
3922
3923impl SessionConfigOption {
3924 #[must_use]
3926 pub fn new(
3927 id: impl Into<SessionConfigId>,
3928 name: impl Into<String>,
3929 kind: SessionConfigKind,
3930 ) -> Self {
3931 Self {
3932 id: id.into(),
3933 name: name.into(),
3934 description: None,
3935 category: None,
3936 kind,
3937 meta: None,
3938 }
3939 }
3940
3941 #[must_use]
3943 pub fn select(
3944 id: impl Into<SessionConfigId>,
3945 name: impl Into<String>,
3946 current_value: impl Into<SessionConfigValueId>,
3947 options: impl Into<SessionConfigSelectOptions>,
3948 ) -> Self {
3949 Self::new(
3950 id,
3951 name,
3952 SessionConfigKind::Select(SessionConfigSelect::new(current_value, options)),
3953 )
3954 }
3955
3956 #[must_use]
3958 pub fn boolean(
3959 id: impl Into<SessionConfigId>,
3960 name: impl Into<String>,
3961 current_value: bool,
3962 ) -> Self {
3963 Self::new(
3964 id,
3965 name,
3966 SessionConfigKind::Boolean(SessionConfigBoolean::new(current_value)),
3967 )
3968 }
3969
3970 #[must_use]
3972 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
3973 self.description = description.into_option();
3974 self
3975 }
3976
3977 #[must_use]
3979 pub fn category(mut self, category: impl IntoOption<SessionConfigOptionCategory>) -> Self {
3980 self.category = category.into_option();
3981 self
3982 }
3983
3984 #[must_use]
3990 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3991 self.meta = meta.into_option();
3992 self
3993 }
3994}
3995
3996#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4007#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4008#[serde(tag = "type", rename_all = "snake_case")]
4009#[non_exhaustive]
4010pub enum SessionConfigOptionValue {
4011 Boolean {
4013 value: bool,
4015 },
4016 #[serde(untagged)]
4022 ValueId {
4023 value: SessionConfigValueId,
4025 },
4026}
4027
4028impl SessionConfigOptionValue {
4029 #[must_use]
4031 pub fn value_id(id: impl Into<SessionConfigValueId>) -> Self {
4032 Self::ValueId { value: id.into() }
4033 }
4034
4035 #[must_use]
4037 pub fn boolean(val: bool) -> Self {
4038 Self::Boolean { value: val }
4039 }
4040
4041 #[must_use]
4044 pub fn as_value_id(&self) -> Option<&SessionConfigValueId> {
4045 match self {
4046 Self::ValueId { value } => Some(value),
4047 _ => None,
4048 }
4049 }
4050
4051 #[must_use]
4053 pub fn as_bool(&self) -> Option<bool> {
4054 match self {
4055 Self::Boolean { value } => Some(*value),
4056 _ => None,
4057 }
4058 }
4059}
4060
4061impl From<SessionConfigValueId> for SessionConfigOptionValue {
4062 fn from(value: SessionConfigValueId) -> Self {
4063 Self::ValueId { value }
4064 }
4065}
4066
4067impl From<bool> for SessionConfigOptionValue {
4068 fn from(value: bool) -> Self {
4069 Self::Boolean { value }
4070 }
4071}
4072
4073impl From<&str> for SessionConfigOptionValue {
4074 fn from(value: &str) -> Self {
4075 Self::ValueId {
4076 value: SessionConfigValueId::new(value),
4077 }
4078 }
4079}
4080
4081#[serde_as]
4083#[skip_serializing_none]
4084#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4085#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4086#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_CONFIG_OPTION_METHOD_NAME)))]
4087#[serde(rename_all = "camelCase")]
4088#[non_exhaustive]
4089pub struct SetSessionConfigOptionRequest {
4090 pub session_id: SessionId,
4092 pub config_id: SessionConfigId,
4094 #[serde(flatten)]
4099 pub value: SessionConfigOptionValue,
4100 #[serde_as(deserialize_as = "DefaultOnError")]
4106 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4107 #[serde(default)]
4108 #[serde(rename = "_meta")]
4109 pub meta: Option<Meta>,
4110}
4111
4112impl SetSessionConfigOptionRequest {
4113 #[must_use]
4115 pub fn new(
4116 session_id: impl Into<SessionId>,
4117 config_id: impl Into<SessionConfigId>,
4118 value: impl Into<SessionConfigOptionValue>,
4119 ) -> Self {
4120 Self {
4121 session_id: session_id.into(),
4122 config_id: config_id.into(),
4123 value: value.into(),
4124 meta: None,
4125 }
4126 }
4127
4128 #[must_use]
4134 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4135 self.meta = meta.into_option();
4136 self
4137 }
4138}
4139
4140#[serde_as]
4142#[skip_serializing_none]
4143#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4144#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4145#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_CONFIG_OPTION_METHOD_NAME)))]
4146#[serde(rename_all = "camelCase")]
4147#[non_exhaustive]
4148pub struct SetSessionConfigOptionResponse {
4149 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
4151 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
4152 pub config_options: Vec<SessionConfigOption>,
4153 #[serde_as(deserialize_as = "DefaultOnError")]
4159 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4160 #[serde(default)]
4161 #[serde(rename = "_meta")]
4162 pub meta: Option<Meta>,
4163}
4164
4165impl SetSessionConfigOptionResponse {
4166 #[must_use]
4168 pub fn new(config_options: Vec<SessionConfigOption>) -> Self {
4169 Self {
4170 config_options,
4171 meta: None,
4172 }
4173 }
4174
4175 #[must_use]
4181 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4182 self.meta = meta.into_option();
4183 self
4184 }
4185}
4186
4187#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4196#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4197#[serde(tag = "type", rename_all = "snake_case")]
4198#[non_exhaustive]
4199pub enum McpServer {
4200 Http(McpServerHttp),
4204 Sse(McpServerSse),
4208 #[cfg(feature = "unstable_mcp_over_acp")]
4217 Acp(McpServerAcp),
4218 #[serde(untagged)]
4222 Stdio(McpServerStdio),
4223}
4224
4225#[serde_as]
4227#[skip_serializing_none]
4228#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4229#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4230#[serde(rename_all = "camelCase")]
4231#[non_exhaustive]
4232pub struct McpServerHttp {
4233 pub name: String,
4235 pub url: String,
4237 #[serde_as(deserialize_as = "DefaultOnNull")]
4239 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
4240 pub headers: Vec<HttpHeader>,
4241 #[serde_as(deserialize_as = "DefaultOnError")]
4247 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4248 #[serde(default)]
4249 #[serde(rename = "_meta")]
4250 pub meta: Option<Meta>,
4251}
4252
4253impl McpServerHttp {
4254 #[must_use]
4256 pub fn new(name: impl Into<String>, url: impl Into<String>) -> Self {
4257 Self {
4258 name: name.into(),
4259 url: url.into(),
4260 headers: Vec::new(),
4261 meta: None,
4262 }
4263 }
4264
4265 #[must_use]
4267 pub fn headers(mut self, headers: Vec<HttpHeader>) -> Self {
4268 self.headers = headers;
4269 self
4270 }
4271
4272 #[must_use]
4278 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4279 self.meta = meta.into_option();
4280 self
4281 }
4282}
4283
4284#[serde_as]
4286#[skip_serializing_none]
4287#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4288#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4289#[serde(rename_all = "camelCase")]
4290#[non_exhaustive]
4291pub struct McpServerSse {
4292 pub name: String,
4294 pub url: String,
4296 #[serde_as(deserialize_as = "DefaultOnNull")]
4298 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
4299 pub headers: Vec<HttpHeader>,
4300 #[serde_as(deserialize_as = "DefaultOnError")]
4306 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4307 #[serde(default)]
4308 #[serde(rename = "_meta")]
4309 pub meta: Option<Meta>,
4310}
4311
4312impl McpServerSse {
4313 #[must_use]
4315 pub fn new(name: impl Into<String>, url: impl Into<String>) -> Self {
4316 Self {
4317 name: name.into(),
4318 url: url.into(),
4319 headers: Vec::new(),
4320 meta: None,
4321 }
4322 }
4323
4324 #[must_use]
4326 pub fn headers(mut self, headers: Vec<HttpHeader>) -> Self {
4327 self.headers = headers;
4328 self
4329 }
4330
4331 #[must_use]
4337 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4338 self.meta = meta.into_option();
4339 self
4340 }
4341}
4342
4343#[cfg(feature = "unstable_mcp_over_acp")]
4352#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4353#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Display, From)]
4354#[serde(transparent)]
4355#[from(Arc<str>, String, &'static str)]
4356#[non_exhaustive]
4357pub struct McpServerAcpId(pub Arc<str>);
4358
4359#[cfg(feature = "unstable_mcp_over_acp")]
4360impl McpServerAcpId {
4361 #[must_use]
4363 pub fn new(id: impl Into<Arc<str>>) -> Self {
4364 Self(id.into())
4365 }
4366}
4367
4368#[serde_as]
4377#[skip_serializing_none]
4378#[cfg(feature = "unstable_mcp_over_acp")]
4379#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4380#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4381#[serde(rename_all = "camelCase")]
4382#[non_exhaustive]
4383pub struct McpServerAcp {
4384 pub name: String,
4386 pub server_id: McpServerAcpId,
4391 #[serde_as(deserialize_as = "DefaultOnError")]
4397 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4398 #[serde(default)]
4399 #[serde(rename = "_meta")]
4400 pub meta: Option<Meta>,
4401}
4402
4403#[cfg(feature = "unstable_mcp_over_acp")]
4404impl McpServerAcp {
4405 #[must_use]
4407 pub fn new(name: impl Into<String>, id: impl Into<McpServerAcpId>) -> Self {
4408 Self {
4409 name: name.into(),
4410 server_id: id.into(),
4411 meta: None,
4412 }
4413 }
4414
4415 #[must_use]
4421 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4422 self.meta = meta.into_option();
4423 self
4424 }
4425}
4426
4427#[serde_as]
4429#[skip_serializing_none]
4430#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4431#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4432#[serde(rename_all = "camelCase")]
4433#[non_exhaustive]
4434pub struct McpServerStdio {
4435 pub name: String,
4437 pub command: PathBuf,
4439 #[serde_as(deserialize_as = "DefaultOnNull")]
4441 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
4442 pub args: Vec<String>,
4443 #[serde_as(deserialize_as = "DefaultOnNull")]
4445 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
4446 pub env: Vec<EnvVariable>,
4447 #[serde_as(deserialize_as = "DefaultOnError")]
4453 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4454 #[serde(default)]
4455 #[serde(rename = "_meta")]
4456 pub meta: Option<Meta>,
4457}
4458
4459impl McpServerStdio {
4460 #[must_use]
4462 pub fn new(name: impl Into<String>, command: impl Into<PathBuf>) -> Self {
4463 Self {
4464 name: name.into(),
4465 command: command.into(),
4466 args: Vec::new(),
4467 env: Vec::new(),
4468 meta: None,
4469 }
4470 }
4471
4472 #[must_use]
4474 pub fn args(mut self, args: Vec<String>) -> Self {
4475 self.args = args;
4476 self
4477 }
4478
4479 #[must_use]
4481 pub fn env(mut self, env: Vec<EnvVariable>) -> Self {
4482 self.env = env;
4483 self
4484 }
4485
4486 #[must_use]
4492 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4493 self.meta = meta.into_option();
4494 self
4495 }
4496}
4497
4498#[serde_as]
4500#[skip_serializing_none]
4501#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4502#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4503#[serde(rename_all = "camelCase")]
4504#[non_exhaustive]
4505pub struct EnvVariable {
4506 pub name: String,
4508 pub value: String,
4510 #[serde_as(deserialize_as = "DefaultOnError")]
4516 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4517 #[serde(default)]
4518 #[serde(rename = "_meta")]
4519 pub meta: Option<Meta>,
4520}
4521
4522impl EnvVariable {
4523 #[must_use]
4525 pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self {
4526 Self {
4527 name: name.into(),
4528 value: value.into(),
4529 meta: None,
4530 }
4531 }
4532
4533 #[must_use]
4539 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4540 self.meta = meta.into_option();
4541 self
4542 }
4543}
4544
4545#[serde_as]
4547#[skip_serializing_none]
4548#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4549#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4550#[serde(rename_all = "camelCase")]
4551#[non_exhaustive]
4552pub struct HttpHeader {
4553 pub name: String,
4555 pub value: String,
4557 #[serde_as(deserialize_as = "DefaultOnError")]
4563 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4564 #[serde(default)]
4565 #[serde(rename = "_meta")]
4566 pub meta: Option<Meta>,
4567}
4568
4569impl HttpHeader {
4570 #[must_use]
4572 pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self {
4573 Self {
4574 name: name.into(),
4575 value: value.into(),
4576 meta: None,
4577 }
4578 }
4579
4580 #[must_use]
4586 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4587 self.meta = meta.into_option();
4588 self
4589 }
4590}
4591
4592#[serde_as]
4601#[skip_serializing_none]
4602#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4603#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4604#[serde(rename_all = "camelCase")]
4605#[non_exhaustive]
4606pub struct SystemPrompt {
4607 pub mode: SystemPromptMode,
4612 pub content: Vec<ContentBlock>,
4622 #[serde_as(deserialize_as = "DefaultOnError")]
4628 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4629 #[serde(default)]
4630 #[serde(rename = "_meta")]
4631 pub meta: Option<Meta>,
4632}
4633
4634impl SystemPrompt {
4635 #[must_use]
4640 pub fn new(content: Vec<ContentBlock>) -> Self {
4641 Self {
4642 mode: SystemPromptMode::default(),
4643 content,
4644 meta: None,
4645 }
4646 }
4647
4648 #[must_use]
4650 pub fn mode(mut self, mode: SystemPromptMode) -> Self {
4651 self.mode = mode;
4652 self
4653 }
4654
4655 #[must_use]
4661 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4662 self.meta = meta.into_option();
4663 self
4664 }
4665}
4666
4667#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4673#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
4674#[serde(rename_all = "snake_case")]
4675#[non_exhaustive]
4676pub enum SystemPromptMode {
4677 #[default]
4684 Append,
4685 Override,
4694 #[serde(untagged)]
4700 Other(String),
4701}
4702
4703#[serde_as]
4711#[skip_serializing_none]
4712#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4713#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4714#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_PROMPT_METHOD_NAME)))]
4715#[serde(rename_all = "camelCase")]
4716#[non_exhaustive]
4717pub struct PromptRequest {
4718 pub session_id: SessionId,
4720 pub prompt: Vec<ContentBlock>,
4734 #[serde_as(deserialize_as = "DefaultOnError")]
4740 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4741 #[serde(default)]
4742 #[serde(rename = "_meta")]
4743 pub meta: Option<Meta>,
4744}
4745
4746impl PromptRequest {
4747 #[must_use]
4749 pub fn new(session_id: impl Into<SessionId>, prompt: Vec<ContentBlock>) -> Self {
4750 Self {
4751 session_id: session_id.into(),
4752 prompt,
4753 meta: None,
4754 }
4755 }
4756
4757 #[must_use]
4763 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4764 self.meta = meta.into_option();
4765 self
4766 }
4767}
4768
4769#[serde_as]
4773#[skip_serializing_none]
4774#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4775#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4776#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_PROMPT_METHOD_NAME)))]
4777#[serde(rename_all = "camelCase")]
4778#[non_exhaustive]
4779pub struct PromptResponse {
4780 pub stop_reason: StopReason,
4782 #[cfg(feature = "unstable_end_turn_token_usage")]
4788 #[serde_as(deserialize_as = "DefaultOnError")]
4789 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4790 #[serde(default)]
4791 pub usage: Option<Usage>,
4792 #[serde_as(deserialize_as = "DefaultOnError")]
4798 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4799 #[serde(default)]
4800 #[serde(rename = "_meta")]
4801 pub meta: Option<Meta>,
4802}
4803
4804impl PromptResponse {
4805 #[must_use]
4807 pub fn new(stop_reason: StopReason) -> Self {
4808 Self {
4809 stop_reason,
4810 #[cfg(feature = "unstable_end_turn_token_usage")]
4811 usage: None,
4812 meta: None,
4813 }
4814 }
4815
4816 #[cfg(feature = "unstable_end_turn_token_usage")]
4822 #[must_use]
4823 pub fn usage(mut self, usage: impl IntoOption<Usage>) -> Self {
4824 self.usage = usage.into_option();
4825 self
4826 }
4827
4828 #[must_use]
4834 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4835 self.meta = meta.into_option();
4836 self
4837 }
4838}
4839
4840#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4844#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
4845#[serde(rename_all = "snake_case")]
4846#[non_exhaustive]
4847pub enum StopReason {
4848 EndTurn,
4850 MaxTokens,
4852 MaxTurnRequests,
4855 Refusal,
4859 Cancelled,
4866}
4867
4868#[cfg(feature = "unstable_end_turn_token_usage")]
4874#[serde_as]
4875#[skip_serializing_none]
4876#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4877#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4878#[serde(rename_all = "camelCase")]
4879#[non_exhaustive]
4880pub struct Usage {
4881 pub total_tokens: u64,
4883 pub input_tokens: u64,
4885 pub output_tokens: u64,
4887 #[serde_as(deserialize_as = "DefaultOnError")]
4889 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4890 #[serde(default)]
4891 pub thought_tokens: Option<u64>,
4892 #[serde_as(deserialize_as = "DefaultOnError")]
4894 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4895 #[serde(default)]
4896 pub cached_read_tokens: Option<u64>,
4897 #[serde_as(deserialize_as = "DefaultOnError")]
4899 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4900 #[serde(default)]
4901 pub cached_write_tokens: Option<u64>,
4902 #[serde_as(deserialize_as = "DefaultOnError")]
4908 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4909 #[serde(default)]
4910 #[serde(rename = "_meta")]
4911 pub meta: Option<Meta>,
4912}
4913
4914#[cfg(feature = "unstable_end_turn_token_usage")]
4915impl Usage {
4916 #[must_use]
4918 pub fn new(total_tokens: u64, input_tokens: u64, output_tokens: u64) -> Self {
4919 Self {
4920 total_tokens,
4921 input_tokens,
4922 output_tokens,
4923 thought_tokens: None,
4924 cached_read_tokens: None,
4925 cached_write_tokens: None,
4926 meta: None,
4927 }
4928 }
4929
4930 #[must_use]
4932 pub fn thought_tokens(mut self, thought_tokens: impl IntoOption<u64>) -> Self {
4933 self.thought_tokens = thought_tokens.into_option();
4934 self
4935 }
4936
4937 #[must_use]
4939 pub fn cached_read_tokens(mut self, cached_read_tokens: impl IntoOption<u64>) -> Self {
4940 self.cached_read_tokens = cached_read_tokens.into_option();
4941 self
4942 }
4943
4944 #[must_use]
4946 pub fn cached_write_tokens(mut self, cached_write_tokens: impl IntoOption<u64>) -> Self {
4947 self.cached_write_tokens = cached_write_tokens.into_option();
4948 self
4949 }
4950
4951 #[must_use]
4957 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4958 self.meta = meta.into_option();
4959 self
4960 }
4961}
4962
4963#[cfg(feature = "unstable_llm_providers")]
4976#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4977#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4978#[serde(rename_all = "snake_case")]
4979#[non_exhaustive]
4980#[expect(clippy::doc_markdown)]
4981pub enum LlmProtocol {
4982 Anthropic,
4984 #[serde(rename = "openai")]
4986 OpenAi,
4987 Azure,
4989 Vertex,
4991 Bedrock,
4993 #[serde(untagged)]
4995 Other(String),
4996}
4997
4998#[cfg(feature = "unstable_llm_providers")]
5004#[serde_as]
5005#[skip_serializing_none]
5006#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5007#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5008#[serde(rename_all = "camelCase")]
5009#[non_exhaustive]
5010pub struct ProviderCurrentConfig {
5011 pub api_type: LlmProtocol,
5013 pub base_url: String,
5015 #[serde_as(deserialize_as = "DefaultOnError")]
5021 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5022 #[serde(default)]
5023 #[serde(rename = "_meta")]
5024 pub meta: Option<Meta>,
5025}
5026
5027#[cfg(feature = "unstable_llm_providers")]
5028impl ProviderCurrentConfig {
5029 #[must_use]
5031 pub fn new(api_type: LlmProtocol, base_url: impl Into<String>) -> Self {
5032 Self {
5033 api_type,
5034 base_url: base_url.into(),
5035 meta: None,
5036 }
5037 }
5038
5039 #[must_use]
5045 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5046 self.meta = meta.into_option();
5047 self
5048 }
5049}
5050
5051#[cfg(feature = "unstable_llm_providers")]
5057#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5058#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Display, From)]
5059#[serde(transparent)]
5060#[from(Arc<str>, String, &'static str)]
5061#[non_exhaustive]
5062pub struct ProviderId(pub Arc<str>);
5063
5064#[cfg(feature = "unstable_llm_providers")]
5065impl ProviderId {
5066 #[must_use]
5068 pub fn new(id: impl Into<Arc<str>>) -> Self {
5069 Self(id.into())
5070 }
5071}
5072
5073#[cfg(feature = "unstable_llm_providers")]
5079#[serde_as]
5080#[skip_serializing_none]
5081#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5082#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5083#[serde(rename_all = "camelCase")]
5084#[non_exhaustive]
5085pub struct ProviderInfo {
5086 pub provider_id: ProviderId,
5088 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
5090 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
5091 pub supported: Vec<LlmProtocol>,
5092 pub required: bool,
5095 #[serde(default)]
5098 pub current: Option<ProviderCurrentConfig>,
5099 #[serde_as(deserialize_as = "DefaultOnError")]
5105 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5106 #[serde(default)]
5107 #[serde(rename = "_meta")]
5108 pub meta: Option<Meta>,
5109}
5110
5111#[cfg(feature = "unstable_llm_providers")]
5112impl ProviderInfo {
5113 #[must_use]
5115 pub fn new(
5116 provider_id: impl Into<ProviderId>,
5117 supported: Vec<LlmProtocol>,
5118 required: bool,
5119 current: impl IntoOption<ProviderCurrentConfig>,
5120 ) -> Self {
5121 Self {
5122 provider_id: provider_id.into(),
5123 supported,
5124 required,
5125 current: current.into_option(),
5126 meta: None,
5127 }
5128 }
5129
5130 #[must_use]
5136 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5137 self.meta = meta.into_option();
5138 self
5139 }
5140}
5141
5142#[cfg(feature = "unstable_llm_providers")]
5143crate::serde_util::default_on_null! {
5144 #[serde_as]
5150 #[skip_serializing_none]
5151 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5152 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
5153 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_LIST_METHOD_NAME)))]
5154 #[serde(rename_all = "camelCase")]
5155 #[non_exhaustive]
5156 pub struct ListProvidersRequest {
5157 #[serde_as(deserialize_as = "DefaultOnError")]
5163 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5164 #[serde(default)]
5165 #[serde(rename = "_meta")]
5166 pub meta: Option<Meta>,
5167 }
5168}
5169
5170#[cfg(feature = "unstable_llm_providers")]
5171impl ListProvidersRequest {
5172 #[must_use]
5174 pub fn new() -> Self {
5175 Self::default()
5176 }
5177
5178 #[must_use]
5184 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5185 self.meta = meta.into_option();
5186 self
5187 }
5188}
5189
5190#[cfg(feature = "unstable_llm_providers")]
5196#[serde_as]
5197#[skip_serializing_none]
5198#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5199#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5200#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_LIST_METHOD_NAME)))]
5201#[serde(rename_all = "camelCase")]
5202#[non_exhaustive]
5203pub struct ListProvidersResponse {
5204 pub providers: Vec<ProviderInfo>,
5206 #[serde_as(deserialize_as = "DefaultOnError")]
5212 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5213 #[serde(default)]
5214 #[serde(rename = "_meta")]
5215 pub meta: Option<Meta>,
5216}
5217
5218#[cfg(feature = "unstable_llm_providers")]
5219impl ListProvidersResponse {
5220 #[must_use]
5222 pub fn new(providers: Vec<ProviderInfo>) -> Self {
5223 Self {
5224 providers,
5225 meta: None,
5226 }
5227 }
5228
5229 #[must_use]
5235 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5236 self.meta = meta.into_option();
5237 self
5238 }
5239}
5240
5241#[cfg(feature = "unstable_llm_providers")]
5249#[serde_as]
5250#[skip_serializing_none]
5251#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5252#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
5253#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_SET_METHOD_NAME)))]
5254#[serde(rename_all = "camelCase")]
5255#[non_exhaustive]
5256pub struct SetProviderRequest {
5257 pub provider_id: ProviderId,
5259 pub api_type: LlmProtocol,
5261 pub base_url: String,
5263 #[serde(default, skip_serializing_if = "HashMap::is_empty")]
5266 pub headers: HashMap<String, String>,
5267 #[serde_as(deserialize_as = "DefaultOnError")]
5273 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5274 #[serde(default)]
5275 #[serde(rename = "_meta")]
5276 pub meta: Option<Meta>,
5277}
5278
5279#[cfg(feature = "unstable_llm_providers")]
5280impl SetProviderRequest {
5281 #[must_use]
5283 pub fn new(
5284 provider_id: impl Into<ProviderId>,
5285 api_type: LlmProtocol,
5286 base_url: impl Into<String>,
5287 ) -> Self {
5288 Self {
5289 provider_id: provider_id.into(),
5290 api_type,
5291 base_url: base_url.into(),
5292 headers: HashMap::new(),
5293 meta: None,
5294 }
5295 }
5296
5297 #[must_use]
5300 pub fn headers(mut self, headers: HashMap<String, String>) -> Self {
5301 self.headers = headers;
5302 self
5303 }
5304
5305 #[must_use]
5311 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5312 self.meta = meta.into_option();
5313 self
5314 }
5315}
5316
5317#[cfg(feature = "unstable_llm_providers")]
5318crate::serde_util::default_on_null! {
5319 #[serde_as]
5325 #[skip_serializing_none]
5326 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5327 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
5328 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_SET_METHOD_NAME)))]
5329 #[serde(rename_all = "camelCase")]
5330 #[non_exhaustive]
5331 pub struct SetProviderResponse {
5332 #[serde_as(deserialize_as = "DefaultOnError")]
5338 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5339 #[serde(default)]
5340 #[serde(rename = "_meta")]
5341 pub meta: Option<Meta>,
5342 }
5343}
5344
5345#[cfg(feature = "unstable_llm_providers")]
5346impl SetProviderResponse {
5347 #[must_use]
5349 pub fn new() -> Self {
5350 Self::default()
5351 }
5352
5353 #[must_use]
5359 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5360 self.meta = meta.into_option();
5361 self
5362 }
5363}
5364
5365#[cfg(feature = "unstable_llm_providers")]
5371#[serde_as]
5372#[skip_serializing_none]
5373#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5374#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5375#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_DISABLE_METHOD_NAME)))]
5376#[serde(rename_all = "camelCase")]
5377#[non_exhaustive]
5378pub struct DisableProviderRequest {
5379 pub provider_id: ProviderId,
5381 #[serde_as(deserialize_as = "DefaultOnError")]
5387 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5388 #[serde(default)]
5389 #[serde(rename = "_meta")]
5390 pub meta: Option<Meta>,
5391}
5392
5393#[cfg(feature = "unstable_llm_providers")]
5394impl DisableProviderRequest {
5395 #[must_use]
5397 pub fn new(provider_id: impl Into<ProviderId>) -> Self {
5398 Self {
5399 provider_id: provider_id.into(),
5400 meta: None,
5401 }
5402 }
5403
5404 #[must_use]
5410 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5411 self.meta = meta.into_option();
5412 self
5413 }
5414}
5415
5416#[cfg(feature = "unstable_llm_providers")]
5417crate::serde_util::default_on_null! {
5418 #[serde_as]
5424 #[skip_serializing_none]
5425 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5426 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
5427 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_DISABLE_METHOD_NAME)))]
5428 #[serde(rename_all = "camelCase")]
5429 #[non_exhaustive]
5430 pub struct DisableProviderResponse {
5431 #[serde_as(deserialize_as = "DefaultOnError")]
5437 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5438 #[serde(default)]
5439 #[serde(rename = "_meta")]
5440 pub meta: Option<Meta>,
5441 }
5442}
5443
5444#[cfg(feature = "unstable_llm_providers")]
5445impl DisableProviderResponse {
5446 #[must_use]
5448 pub fn new() -> Self {
5449 Self::default()
5450 }
5451
5452 #[must_use]
5458 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5459 self.meta = meta.into_option();
5460 self
5461 }
5462}
5463
5464#[serde_as]
5473#[skip_serializing_none]
5474#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5475#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5476#[serde(rename_all = "camelCase")]
5477#[non_exhaustive]
5478pub struct AgentCapabilities {
5479 #[serde_as(deserialize_as = "DefaultOnError")]
5481 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5482 #[serde(default)]
5483 pub load_session: bool,
5484 #[serde_as(deserialize_as = "DefaultOnError")]
5486 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5487 #[serde(default)]
5488 pub prompt_capabilities: PromptCapabilities,
5489 #[serde_as(deserialize_as = "DefaultOnError")]
5491 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5492 #[serde(default)]
5493 pub mcp_capabilities: McpCapabilities,
5494 #[serde_as(deserialize_as = "DefaultOnError")]
5496 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5497 #[serde(default)]
5498 pub session_capabilities: SessionCapabilities,
5499 #[serde_as(deserialize_as = "DefaultOnError")]
5501 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5502 #[serde(default)]
5503 pub auth: AgentAuthCapabilities,
5504 #[cfg(feature = "unstable_llm_providers")]
5513 #[serde_as(deserialize_as = "DefaultOnError")]
5514 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5515 #[serde(default)]
5516 pub providers: Option<ProvidersCapabilities>,
5517 #[serde_as(deserialize_as = "DefaultOnError")]
5523 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5524 #[serde(default)]
5525 #[serde(rename = "_meta")]
5526 pub meta: Option<Meta>,
5527}
5528
5529impl AgentCapabilities {
5530 #[must_use]
5532 pub fn new() -> Self {
5533 Self::default()
5534 }
5535
5536 #[must_use]
5538 pub fn load_session(mut self, load_session: bool) -> Self {
5539 self.load_session = load_session;
5540 self
5541 }
5542
5543 #[must_use]
5545 pub fn prompt_capabilities(mut self, prompt_capabilities: PromptCapabilities) -> Self {
5546 self.prompt_capabilities = prompt_capabilities;
5547 self
5548 }
5549
5550 #[must_use]
5552 pub fn mcp_capabilities(mut self, mcp_capabilities: McpCapabilities) -> Self {
5553 self.mcp_capabilities = mcp_capabilities;
5554 self
5555 }
5556
5557 #[must_use]
5559 pub fn session_capabilities(mut self, session_capabilities: SessionCapabilities) -> Self {
5560 self.session_capabilities = session_capabilities;
5561 self
5562 }
5563
5564 #[must_use]
5566 pub fn auth(mut self, auth: AgentAuthCapabilities) -> Self {
5567 self.auth = auth;
5568 self
5569 }
5570
5571 #[cfg(feature = "unstable_llm_providers")]
5577 #[must_use]
5578 pub fn providers(mut self, providers: impl IntoOption<ProvidersCapabilities>) -> Self {
5579 self.providers = providers.into_option();
5580 self
5581 }
5582
5583 #[must_use]
5589 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5590 self.meta = meta.into_option();
5591 self
5592 }
5593}
5594
5595#[cfg(feature = "unstable_llm_providers")]
5603#[serde_as]
5604#[skip_serializing_none]
5605#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5606#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5607#[non_exhaustive]
5608pub struct ProvidersCapabilities {
5609 #[serde_as(deserialize_as = "DefaultOnError")]
5615 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5616 #[serde(default)]
5617 #[serde(rename = "_meta")]
5618 pub meta: Option<Meta>,
5619}
5620
5621#[cfg(feature = "unstable_llm_providers")]
5622impl ProvidersCapabilities {
5623 #[must_use]
5625 pub fn new() -> Self {
5626 Self::default()
5627 }
5628
5629 #[must_use]
5635 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5636 self.meta = meta.into_option();
5637 self
5638 }
5639}
5640
5641#[serde_as]
5651#[skip_serializing_none]
5652#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5653#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5654#[serde(rename_all = "camelCase")]
5655#[non_exhaustive]
5656pub struct SessionCapabilities {
5657 #[serde_as(deserialize_as = "DefaultOnError")]
5662 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5663 #[serde(default)]
5664 pub list: Option<SessionListCapabilities>,
5665 #[serde_as(deserialize_as = "DefaultOnError")]
5670 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5671 #[serde(default)]
5672 pub delete: Option<SessionDeleteCapabilities>,
5673 #[serde_as(deserialize_as = "DefaultOnError")]
5683 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5684 #[serde(default)]
5685 pub additional_directories: Option<SessionAdditionalDirectoriesCapabilities>,
5686 #[serde_as(deserialize_as = "DefaultOnError")]
5691 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5692 #[serde(default)]
5693 pub system_prompt: Option<SessionSystemPromptCapabilities>,
5694 #[cfg(feature = "unstable_session_fork")]
5703 #[serde_as(deserialize_as = "DefaultOnError")]
5704 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5705 #[serde(default)]
5706 pub fork: Option<SessionForkCapabilities>,
5707 #[cfg(feature = "unstable_session_archive")]
5717 #[serde_as(deserialize_as = "DefaultOnError")]
5718 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5719 #[serde(default)]
5720 pub archive: Option<SessionArchiveCapabilities>,
5721 #[cfg(feature = "unstable_session_status")]
5730 #[serde_as(deserialize_as = "DefaultOnError")]
5731 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5732 #[serde(default)]
5733 pub status: Option<SessionStatusCapabilities>,
5734 #[cfg(feature = "unstable_session_options")]
5744 #[serde_as(deserialize_as = "DefaultOnError")]
5745 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5746 #[serde(default)]
5747 pub options: Option<SessionOptionsCapabilities>,
5748 #[cfg(feature = "unstable_session_set_title")]
5760 #[serde_as(deserialize_as = "DefaultOnError")]
5761 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5762 #[serde(default)]
5763 pub title: Option<SessionTitleCapabilities>,
5764 #[serde_as(deserialize_as = "DefaultOnError")]
5769 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5770 #[serde(default)]
5771 pub resume: Option<SessionResumeCapabilities>,
5772 #[serde_as(deserialize_as = "DefaultOnError")]
5777 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5778 #[serde(default)]
5779 pub close: Option<SessionCloseCapabilities>,
5780 #[serde_as(deserialize_as = "DefaultOnError")]
5786 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5787 #[serde(default)]
5788 #[serde(rename = "_meta")]
5789 pub meta: Option<Meta>,
5790}
5791
5792impl SessionCapabilities {
5793 #[must_use]
5795 pub fn new() -> Self {
5796 Self::default()
5797 }
5798
5799 #[must_use]
5804 pub fn list(mut self, list: impl IntoOption<SessionListCapabilities>) -> Self {
5805 self.list = list.into_option();
5806 self
5807 }
5808
5809 #[must_use]
5814 pub fn delete(mut self, delete: impl IntoOption<SessionDeleteCapabilities>) -> Self {
5815 self.delete = delete.into_option();
5816 self
5817 }
5818
5819 #[must_use]
5829 pub fn additional_directories(
5830 mut self,
5831 additional_directories: impl IntoOption<SessionAdditionalDirectoriesCapabilities>,
5832 ) -> Self {
5833 self.additional_directories = additional_directories.into_option();
5834 self
5835 }
5836
5837 #[must_use]
5842 pub fn system_prompt(
5843 mut self,
5844 system_prompt: impl IntoOption<SessionSystemPromptCapabilities>,
5845 ) -> Self {
5846 self.system_prompt = system_prompt.into_option();
5847 self
5848 }
5849
5850 #[cfg(feature = "unstable_session_fork")]
5851 #[must_use]
5856 pub fn fork(mut self, fork: impl IntoOption<SessionForkCapabilities>) -> Self {
5857 self.fork = fork.into_option();
5858 self
5859 }
5860
5861 #[cfg(feature = "unstable_session_archive")]
5871 #[must_use]
5872 pub fn archive(mut self, archive: impl IntoOption<SessionArchiveCapabilities>) -> Self {
5873 self.archive = archive.into_option();
5874 self
5875 }
5876
5877 #[cfg(feature = "unstable_session_status")]
5886 #[must_use]
5887 pub fn status(mut self, status: impl IntoOption<SessionStatusCapabilities>) -> Self {
5888 self.status = status.into_option();
5889 self
5890 }
5891
5892 #[cfg(feature = "unstable_session_options")]
5902 #[must_use]
5903 pub fn options(mut self, options: impl IntoOption<SessionOptionsCapabilities>) -> Self {
5904 self.options = options.into_option();
5905 self
5906 }
5907
5908 #[cfg(feature = "unstable_session_set_title")]
5920 #[must_use]
5921 pub fn title(mut self, title: impl IntoOption<SessionTitleCapabilities>) -> Self {
5922 self.title = title.into_option();
5923 self
5924 }
5925
5926 #[must_use]
5931 pub fn resume(mut self, resume: impl IntoOption<SessionResumeCapabilities>) -> Self {
5932 self.resume = resume.into_option();
5933 self
5934 }
5935
5936 #[must_use]
5941 pub fn close(mut self, close: impl IntoOption<SessionCloseCapabilities>) -> Self {
5942 self.close = close.into_option();
5943 self
5944 }
5945
5946 #[must_use]
5952 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5953 self.meta = meta.into_option();
5954 self
5955 }
5956}
5957
5958#[serde_as]
5962#[skip_serializing_none]
5963#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5964#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5965#[non_exhaustive]
5966pub struct SessionListCapabilities {
5967 #[serde_as(deserialize_as = "DefaultOnError")]
5973 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5974 #[serde(default)]
5975 #[serde(rename = "_meta")]
5976 pub meta: Option<Meta>,
5977}
5978
5979impl SessionListCapabilities {
5980 #[must_use]
5982 pub fn new() -> Self {
5983 Self::default()
5984 }
5985
5986 #[must_use]
5992 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5993 self.meta = meta.into_option();
5994 self
5995 }
5996}
5997
5998#[serde_as]
6002#[skip_serializing_none]
6003#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6004#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6005#[non_exhaustive]
6006pub struct SessionDeleteCapabilities {
6007 #[serde_as(deserialize_as = "DefaultOnError")]
6013 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6014 #[serde(default)]
6015 #[serde(rename = "_meta")]
6016 pub meta: Option<Meta>,
6017}
6018
6019impl SessionDeleteCapabilities {
6020 #[must_use]
6022 pub fn new() -> Self {
6023 Self::default()
6024 }
6025
6026 #[must_use]
6032 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6033 self.meta = meta.into_option();
6034 self
6035 }
6036}
6037
6038#[serde_as]
6045#[skip_serializing_none]
6046#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6047#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6048#[non_exhaustive]
6049pub struct SessionAdditionalDirectoriesCapabilities {
6050 #[serde_as(deserialize_as = "DefaultOnError")]
6056 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6057 #[serde(default)]
6058 #[serde(rename = "_meta")]
6059 pub meta: Option<Meta>,
6060}
6061
6062impl SessionAdditionalDirectoriesCapabilities {
6063 #[must_use]
6065 pub fn new() -> Self {
6066 Self::default()
6067 }
6068
6069 #[must_use]
6075 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6076 self.meta = meta.into_option();
6077 self
6078 }
6079}
6080
6081#[serde_as]
6086#[skip_serializing_none]
6087#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6088#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6089#[serde(rename_all = "camelCase")]
6090#[non_exhaustive]
6091pub struct SessionSystemPromptCapabilities {
6092 #[serde_as(deserialize_as = "DefaultOnError")]
6096 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6097 #[serde(default)]
6098 pub mode: Option<SessionSystemPromptModeCapabilities>,
6099 #[serde_as(deserialize_as = "DefaultOnError")]
6105 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6106 #[serde(default)]
6107 #[serde(rename = "_meta")]
6108 pub meta: Option<Meta>,
6109}
6110
6111impl SessionSystemPromptCapabilities {
6112 #[must_use]
6114 pub fn new() -> Self {
6115 Self::default()
6116 }
6117
6118 #[must_use]
6122 pub fn mode(mut self, mode: impl IntoOption<SessionSystemPromptModeCapabilities>) -> Self {
6123 self.mode = mode.into_option();
6124 self
6125 }
6126
6127 #[must_use]
6133 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6134 self.meta = meta.into_option();
6135 self
6136 }
6137}
6138
6139#[serde_as]
6144#[skip_serializing_none]
6145#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6146#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6147#[serde(rename_all = "camelCase")]
6148#[non_exhaustive]
6149pub struct SessionSystemPromptModeCapabilities {
6150 #[serde_as(deserialize_as = "DefaultOnError")]
6156 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6157 #[serde(default, rename = "override")]
6158 pub override_: Option<SessionSystemPromptOverrideCapabilities>,
6159 #[serde_as(deserialize_as = "DefaultOnError")]
6165 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6166 #[serde(default)]
6167 #[serde(rename = "_meta")]
6168 pub meta: Option<Meta>,
6169}
6170
6171impl SessionSystemPromptModeCapabilities {
6172 #[must_use]
6174 pub fn new() -> Self {
6175 Self::default()
6176 }
6177
6178 #[must_use]
6184 pub fn override_(
6185 mut self,
6186 override_: impl IntoOption<SessionSystemPromptOverrideCapabilities>,
6187 ) -> Self {
6188 self.override_ = override_.into_option();
6189 self
6190 }
6191
6192 #[must_use]
6198 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6199 self.meta = meta.into_option();
6200 self
6201 }
6202}
6203
6204#[serde_as]
6209#[skip_serializing_none]
6210#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6211#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6212#[non_exhaustive]
6213pub struct SessionSystemPromptOverrideCapabilities {
6214 #[serde_as(deserialize_as = "DefaultOnError")]
6220 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6221 #[serde(default)]
6222 #[serde(rename = "_meta")]
6223 pub meta: Option<Meta>,
6224}
6225
6226impl SessionSystemPromptOverrideCapabilities {
6227 #[must_use]
6229 pub fn new() -> Self {
6230 Self::default()
6231 }
6232
6233 #[must_use]
6239 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6240 self.meta = meta.into_option();
6241 self
6242 }
6243}
6244
6245#[cfg(feature = "unstable_session_fork")]
6253#[serde_as]
6254#[skip_serializing_none]
6255#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6256#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6257#[non_exhaustive]
6258pub struct SessionForkCapabilities {
6259 #[serde_as(deserialize_as = "DefaultOnError")]
6265 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6266 #[serde(default)]
6267 #[serde(rename = "_meta")]
6268 pub meta: Option<Meta>,
6269}
6270
6271#[cfg(feature = "unstable_session_fork")]
6272impl SessionForkCapabilities {
6273 #[must_use]
6275 pub fn new() -> Self {
6276 Self::default()
6277 }
6278
6279 #[must_use]
6285 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6286 self.meta = meta.into_option();
6287 self
6288 }
6289}
6290
6291#[cfg(feature = "unstable_session_archive")]
6300#[serde_as]
6301#[skip_serializing_none]
6302#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6303#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6304#[non_exhaustive]
6305pub struct SessionArchiveCapabilities {
6306 #[serde_as(deserialize_as = "DefaultOnError")]
6312 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6313 #[serde(default)]
6314 #[serde(rename = "_meta")]
6315 pub meta: Option<Meta>,
6316}
6317
6318#[cfg(feature = "unstable_session_archive")]
6319impl SessionArchiveCapabilities {
6320 #[must_use]
6322 pub fn new() -> Self {
6323 Self::default()
6324 }
6325
6326 #[must_use]
6332 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6333 self.meta = meta.into_option();
6334 self
6335 }
6336}
6337
6338#[cfg(feature = "unstable_session_status")]
6346#[serde_as]
6347#[skip_serializing_none]
6348#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6349#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6350#[non_exhaustive]
6351pub struct SessionStatusCapabilities {
6352 #[serde_as(deserialize_as = "DefaultOnError")]
6358 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6359 #[serde(default)]
6360 #[serde(rename = "_meta")]
6361 pub meta: Option<Meta>,
6362}
6363
6364#[cfg(feature = "unstable_session_status")]
6365impl SessionStatusCapabilities {
6366 #[must_use]
6368 pub fn new() -> Self {
6369 Self::default()
6370 }
6371
6372 #[must_use]
6378 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6379 self.meta = meta.into_option();
6380 self
6381 }
6382}
6383
6384#[cfg(feature = "unstable_session_options")]
6393#[serde_as]
6394#[skip_serializing_none]
6395#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6396#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6397#[non_exhaustive]
6398pub struct SessionOptionsCapabilities {
6399 #[serde_as(deserialize_as = "DefaultOnError")]
6405 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6406 #[serde(default)]
6407 #[serde(rename = "_meta")]
6408 pub meta: Option<Meta>,
6409}
6410
6411#[cfg(feature = "unstable_session_options")]
6412impl SessionOptionsCapabilities {
6413 #[must_use]
6415 pub fn new() -> Self {
6416 Self::default()
6417 }
6418
6419 #[must_use]
6425 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6426 self.meta = meta.into_option();
6427 self
6428 }
6429}
6430
6431#[cfg(feature = "unstable_session_set_title")]
6440#[serde_as]
6441#[skip_serializing_none]
6442#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6443#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6444#[non_exhaustive]
6445pub struct SessionTitleCapabilities {
6446 #[serde_as(deserialize_as = "DefaultOnError")]
6452 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6453 #[serde(default)]
6454 #[serde(rename = "_meta")]
6455 pub meta: Option<Meta>,
6456}
6457
6458#[cfg(feature = "unstable_session_set_title")]
6459impl SessionTitleCapabilities {
6460 #[must_use]
6462 pub fn new() -> Self {
6463 Self::default()
6464 }
6465
6466 #[must_use]
6472 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6473 self.meta = meta.into_option();
6474 self
6475 }
6476}
6477
6478#[serde_as]
6482#[skip_serializing_none]
6483#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6484#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6485#[non_exhaustive]
6486pub struct SessionResumeCapabilities {
6487 #[serde_as(deserialize_as = "DefaultOnError")]
6493 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6494 #[serde(default)]
6495 #[serde(rename = "_meta")]
6496 pub meta: Option<Meta>,
6497}
6498
6499impl SessionResumeCapabilities {
6500 #[must_use]
6502 pub fn new() -> Self {
6503 Self::default()
6504 }
6505
6506 #[must_use]
6512 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6513 self.meta = meta.into_option();
6514 self
6515 }
6516}
6517
6518#[serde_as]
6522#[skip_serializing_none]
6523#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6524#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6525#[non_exhaustive]
6526pub struct SessionCloseCapabilities {
6527 #[serde_as(deserialize_as = "DefaultOnError")]
6533 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6534 #[serde(default)]
6535 #[serde(rename = "_meta")]
6536 pub meta: Option<Meta>,
6537}
6538
6539impl SessionCloseCapabilities {
6540 #[must_use]
6542 pub fn new() -> Self {
6543 Self::default()
6544 }
6545
6546 #[must_use]
6552 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6553 self.meta = meta.into_option();
6554 self
6555 }
6556}
6557
6558#[serde_as]
6571#[skip_serializing_none]
6572#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6573#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6574#[serde(rename_all = "camelCase")]
6575#[non_exhaustive]
6576pub struct PromptCapabilities {
6577 #[serde_as(deserialize_as = "DefaultOnError")]
6579 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6580 #[serde(default)]
6581 pub image: bool,
6582 #[serde_as(deserialize_as = "DefaultOnError")]
6584 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6585 #[serde(default)]
6586 pub audio: bool,
6587 #[serde_as(deserialize_as = "DefaultOnError")]
6592 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6593 #[serde(default)]
6594 pub embedded_context: bool,
6595 #[serde_as(deserialize_as = "DefaultOnError")]
6601 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6602 #[serde(default)]
6603 #[serde(rename = "_meta")]
6604 pub meta: Option<Meta>,
6605}
6606
6607impl PromptCapabilities {
6608 #[must_use]
6610 pub fn new() -> Self {
6611 Self::default()
6612 }
6613
6614 #[must_use]
6616 pub fn image(mut self, image: bool) -> Self {
6617 self.image = image;
6618 self
6619 }
6620
6621 #[must_use]
6623 pub fn audio(mut self, audio: bool) -> Self {
6624 self.audio = audio;
6625 self
6626 }
6627
6628 #[must_use]
6633 pub fn embedded_context(mut self, embedded_context: bool) -> Self {
6634 self.embedded_context = embedded_context;
6635 self
6636 }
6637
6638 #[must_use]
6644 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6645 self.meta = meta.into_option();
6646 self
6647 }
6648}
6649
6650#[serde_as]
6652#[skip_serializing_none]
6653#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6654#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6655#[serde(rename_all = "camelCase")]
6656#[non_exhaustive]
6657pub struct McpCapabilities {
6658 #[serde_as(deserialize_as = "DefaultOnError")]
6660 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6661 #[serde(default)]
6662 pub http: bool,
6663 #[serde_as(deserialize_as = "DefaultOnError")]
6665 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6666 #[serde(default)]
6667 pub sse: bool,
6668 #[cfg(feature = "unstable_mcp_over_acp")]
6674 #[serde_as(deserialize_as = "DefaultOnError")]
6675 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6676 #[serde(default)]
6677 pub acp: bool,
6678 #[serde_as(deserialize_as = "DefaultOnError")]
6684 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6685 #[serde(default)]
6686 #[serde(rename = "_meta")]
6687 pub meta: Option<Meta>,
6688}
6689
6690impl McpCapabilities {
6691 #[must_use]
6693 pub fn new() -> Self {
6694 Self::default()
6695 }
6696
6697 #[must_use]
6699 pub fn http(mut self, http: bool) -> Self {
6700 self.http = http;
6701 self
6702 }
6703
6704 #[must_use]
6706 pub fn sse(mut self, sse: bool) -> Self {
6707 self.sse = sse;
6708 self
6709 }
6710
6711 #[cfg(feature = "unstable_mcp_over_acp")]
6717 #[must_use]
6718 pub fn acp(mut self, acp: bool) -> Self {
6719 self.acp = acp;
6720 self
6721 }
6722
6723 #[must_use]
6729 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6730 self.meta = meta.into_option();
6731 self
6732 }
6733}
6734
6735#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6741#[non_exhaustive]
6742pub struct AgentMethodNames {
6743 pub initialize: &'static str,
6745 pub authenticate: &'static str,
6747 #[cfg(feature = "unstable_llm_providers")]
6749 pub providers_list: &'static str,
6750 #[cfg(feature = "unstable_llm_providers")]
6752 pub providers_set: &'static str,
6753 #[cfg(feature = "unstable_llm_providers")]
6755 pub providers_disable: &'static str,
6756 pub session_new: &'static str,
6758 pub session_load: &'static str,
6760 pub session_set_mode: &'static str,
6762 pub session_set_config_option: &'static str,
6764 pub session_prompt: &'static str,
6766 pub session_cancel: &'static str,
6768 #[cfg(feature = "unstable_mcp_over_acp")]
6770 pub mcp_message: &'static str,
6771 pub session_list: &'static str,
6773 pub session_delete: &'static str,
6775 #[cfg(feature = "unstable_session_fork")]
6777 pub session_fork: &'static str,
6778 #[cfg(feature = "unstable_session_archive")]
6780 pub session_archive: &'static str,
6781 #[cfg(feature = "unstable_session_archive")]
6783 pub session_unarchive: &'static str,
6784 #[cfg(feature = "unstable_session_status")]
6786 pub session_status: &'static str,
6787 #[cfg(feature = "unstable_session_options")]
6789 pub session_options: &'static str,
6790 #[cfg(feature = "unstable_session_set_title")]
6792 pub session_set_title: &'static str,
6793 pub session_resume: &'static str,
6795 pub session_close: &'static str,
6797 pub logout: &'static str,
6799 #[cfg(feature = "unstable_auth_status")]
6801 pub auth_status: &'static str,
6802}
6803
6804pub const AGENT_METHOD_NAMES: AgentMethodNames = AgentMethodNames {
6806 initialize: INITIALIZE_METHOD_NAME,
6807 authenticate: AUTHENTICATE_METHOD_NAME,
6808 #[cfg(feature = "unstable_llm_providers")]
6809 providers_list: PROVIDERS_LIST_METHOD_NAME,
6810 #[cfg(feature = "unstable_llm_providers")]
6811 providers_set: PROVIDERS_SET_METHOD_NAME,
6812 #[cfg(feature = "unstable_llm_providers")]
6813 providers_disable: PROVIDERS_DISABLE_METHOD_NAME,
6814 session_new: SESSION_NEW_METHOD_NAME,
6815 session_load: SESSION_LOAD_METHOD_NAME,
6816 session_set_mode: SESSION_SET_MODE_METHOD_NAME,
6817 session_set_config_option: SESSION_SET_CONFIG_OPTION_METHOD_NAME,
6818 session_prompt: SESSION_PROMPT_METHOD_NAME,
6819 session_cancel: SESSION_CANCEL_METHOD_NAME,
6820 #[cfg(feature = "unstable_mcp_over_acp")]
6821 mcp_message: MCP_MESSAGE_METHOD_NAME,
6822 session_list: SESSION_LIST_METHOD_NAME,
6823 session_delete: SESSION_DELETE_METHOD_NAME,
6824 #[cfg(feature = "unstable_session_fork")]
6825 session_fork: SESSION_FORK_METHOD_NAME,
6826 #[cfg(feature = "unstable_session_archive")]
6827 session_archive: SESSION_ARCHIVE_METHOD_NAME,
6828 #[cfg(feature = "unstable_session_archive")]
6829 session_unarchive: SESSION_UNARCHIVE_METHOD_NAME,
6830 #[cfg(feature = "unstable_session_status")]
6831 session_status: SESSION_STATUS_METHOD_NAME,
6832 #[cfg(feature = "unstable_session_options")]
6833 session_options: SESSION_OPTIONS_METHOD_NAME,
6834 #[cfg(feature = "unstable_session_set_title")]
6835 session_set_title: SESSION_SET_TITLE_METHOD_NAME,
6836 session_resume: SESSION_RESUME_METHOD_NAME,
6837 session_close: SESSION_CLOSE_METHOD_NAME,
6838 logout: LOGOUT_METHOD_NAME,
6839 #[cfg(feature = "unstable_auth_status")]
6840 auth_status: AUTH_STATUS_METHOD_NAME,
6841};
6842
6843pub(crate) const INITIALIZE_METHOD_NAME: &str = "initialize";
6845pub(crate) const AUTHENTICATE_METHOD_NAME: &str = "authenticate";
6847#[cfg(feature = "unstable_llm_providers")]
6849pub(crate) const PROVIDERS_LIST_METHOD_NAME: &str = "providers/list";
6850#[cfg(feature = "unstable_llm_providers")]
6852pub(crate) const PROVIDERS_SET_METHOD_NAME: &str = "providers/set";
6853#[cfg(feature = "unstable_llm_providers")]
6855pub(crate) const PROVIDERS_DISABLE_METHOD_NAME: &str = "providers/disable";
6856pub(crate) const SESSION_NEW_METHOD_NAME: &str = "session/new";
6858pub(crate) const SESSION_LOAD_METHOD_NAME: &str = "session/load";
6860pub(crate) const SESSION_SET_MODE_METHOD_NAME: &str = "session/set_mode";
6862pub(crate) const SESSION_SET_CONFIG_OPTION_METHOD_NAME: &str = "session/set_config_option";
6864pub(crate) const SESSION_PROMPT_METHOD_NAME: &str = "session/prompt";
6866pub(crate) const SESSION_CANCEL_METHOD_NAME: &str = "session/cancel";
6868pub(crate) const SESSION_LIST_METHOD_NAME: &str = "session/list";
6870pub(crate) const SESSION_DELETE_METHOD_NAME: &str = "session/delete";
6872#[cfg(feature = "unstable_session_fork")]
6874pub(crate) const SESSION_FORK_METHOD_NAME: &str = "session/fork";
6875#[cfg(feature = "unstable_session_archive")]
6877pub(crate) const SESSION_ARCHIVE_METHOD_NAME: &str = "session/archive";
6878#[cfg(feature = "unstable_session_archive")]
6880pub(crate) const SESSION_UNARCHIVE_METHOD_NAME: &str = "session/unarchive";
6881#[cfg(feature = "unstable_session_status")]
6883pub(crate) const SESSION_STATUS_METHOD_NAME: &str = "session/status";
6884#[cfg(feature = "unstable_session_options")]
6886pub(crate) const SESSION_OPTIONS_METHOD_NAME: &str = "session/options";
6887#[cfg(feature = "unstable_session_set_title")]
6889pub(crate) const SESSION_SET_TITLE_METHOD_NAME: &str = "session/set_title";
6890pub(crate) const SESSION_RESUME_METHOD_NAME: &str = "session/resume";
6892pub(crate) const SESSION_CLOSE_METHOD_NAME: &str = "session/close";
6894pub(crate) const LOGOUT_METHOD_NAME: &str = "logout";
6896#[cfg(feature = "unstable_auth_status")]
6898pub(crate) const AUTH_STATUS_METHOD_NAME: &str = "auth/status";
6899
6900#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6907#[derive(Clone, Debug, Serialize, Deserialize)]
6908#[serde(untagged)]
6909#[cfg_attr(feature = "schemars", schemars(inline))]
6910#[non_exhaustive]
6911#[allow(clippy::large_enum_variant)]
6912pub enum ClientRequest {
6913 InitializeRequest(InitializeRequest),
6924 AuthenticateRequest(AuthenticateRequest),
6935 #[cfg(feature = "unstable_llm_providers")]
6941 ListProvidersRequest(ListProvidersRequest),
6942 #[cfg(feature = "unstable_llm_providers")]
6948 SetProviderRequest(SetProviderRequest),
6949 #[cfg(feature = "unstable_llm_providers")]
6955 DisableProviderRequest(DisableProviderRequest),
6956 LogoutRequest(LogoutRequest),
6961 #[cfg(feature = "unstable_auth_status")]
6970 AuthStatusRequest(AuthStatusRequest),
6971 NewSessionRequest(NewSessionRequest),
6984 LoadSessionRequest(LoadSessionRequest),
6995 ListSessionsRequest(ListSessionsRequest),
7001 DeleteSessionRequest(DeleteSessionRequest),
7005 #[cfg(feature = "unstable_session_fork")]
7006 ForkSessionRequest(ForkSessionRequest),
7022 #[cfg(feature = "unstable_session_archive")]
7023 ArchiveSessionRequest(ArchiveSessionRequest),
7031 #[cfg(feature = "unstable_session_archive")]
7032 UnarchiveSessionRequest(UnarchiveSessionRequest),
7040 #[cfg(feature = "unstable_session_status")]
7041 SessionStatusRequest(SessionStatusRequest),
7049 #[cfg(feature = "unstable_session_options")]
7050 SessionOptionsRequest(SessionOptionsRequest),
7058 #[cfg(feature = "unstable_session_set_title")]
7059 SetSessionTitleRequest(SetSessionTitleRequest),
7070 ResumeSessionRequest(ResumeSessionRequest),
7077 CloseSessionRequest(CloseSessionRequest),
7084 SetSessionModeRequest(SetSessionModeRequest),
7098 SetSessionConfigOptionRequest(SetSessionConfigOptionRequest),
7100 PromptRequest(PromptRequest),
7112 ExtMethodRequest(ExtRequest),
7119}
7120
7121impl_request_dispatch! {
7122 ClientRequest => AgentResponse {
7123 InitializeRequest => InitializeResponse: AGENT_METHOD_NAMES.initialize,
7124 AuthenticateRequest => AuthenticateResponse: AGENT_METHOD_NAMES.authenticate,
7125 #[cfg(feature = "unstable_llm_providers")]
7126 ListProvidersRequest => ListProvidersResponse: AGENT_METHOD_NAMES.providers_list,
7127 #[cfg(feature = "unstable_llm_providers")]
7128 SetProviderRequest => SetProviderResponse: AGENT_METHOD_NAMES.providers_set,
7129 #[cfg(feature = "unstable_llm_providers")]
7130 DisableProviderRequest => DisableProviderResponse: AGENT_METHOD_NAMES.providers_disable,
7131 LogoutRequest => LogoutResponse: AGENT_METHOD_NAMES.logout,
7132 #[cfg(feature = "unstable_auth_status")]
7133 AuthStatusRequest => AuthStatusResponse: AGENT_METHOD_NAMES.auth_status,
7134 NewSessionRequest => NewSessionResponse: AGENT_METHOD_NAMES.session_new,
7135 LoadSessionRequest => LoadSessionResponse: AGENT_METHOD_NAMES.session_load,
7136 ListSessionsRequest => ListSessionsResponse: AGENT_METHOD_NAMES.session_list,
7137 DeleteSessionRequest => DeleteSessionResponse: AGENT_METHOD_NAMES.session_delete,
7138 #[cfg(feature = "unstable_session_fork")]
7139 ForkSessionRequest => ForkSessionResponse: AGENT_METHOD_NAMES.session_fork,
7140 #[cfg(feature = "unstable_session_archive")]
7141 ArchiveSessionRequest => ArchiveSessionResponse: AGENT_METHOD_NAMES.session_archive,
7142 #[cfg(feature = "unstable_session_archive")]
7143 UnarchiveSessionRequest => UnarchiveSessionResponse: AGENT_METHOD_NAMES.session_unarchive,
7144 #[cfg(feature = "unstable_session_status")]
7145 SessionStatusRequest => SessionStatusResponse: AGENT_METHOD_NAMES.session_status,
7146 #[cfg(feature = "unstable_session_options")]
7147 SessionOptionsRequest => SessionOptionsResponse: AGENT_METHOD_NAMES.session_options,
7148 #[cfg(feature = "unstable_session_set_title")]
7149 SetSessionTitleRequest => SetSessionTitleResponse: AGENT_METHOD_NAMES.session_set_title,
7150 ResumeSessionRequest => ResumeSessionResponse: AGENT_METHOD_NAMES.session_resume,
7151 CloseSessionRequest => CloseSessionResponse: AGENT_METHOD_NAMES.session_close,
7152 SetSessionModeRequest => SetSessionModeResponse: AGENT_METHOD_NAMES.session_set_mode,
7153 SetSessionConfigOptionRequest => SetSessionConfigOptionResponse: AGENT_METHOD_NAMES.session_set_config_option,
7154 PromptRequest => PromptResponse: AGENT_METHOD_NAMES.session_prompt,
7155 }
7156 extension ExtMethodRequest(ExtRequest) => ExtMethodResponse;
7157}
7158
7159#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7166#[derive(Clone, Debug, Serialize, Deserialize)]
7167#[serde(untagged)]
7168#[cfg_attr(feature = "schemars", schemars(inline))]
7169#[non_exhaustive]
7170#[allow(clippy::large_enum_variant)]
7171pub enum AgentResponse {
7172 InitializeResponse(InitializeResponse),
7174 AuthenticateResponse(#[serde(default)] AuthenticateResponse),
7176 #[cfg(feature = "unstable_llm_providers")]
7178 ListProvidersResponse(ListProvidersResponse),
7179 #[cfg(feature = "unstable_llm_providers")]
7181 SetProviderResponse(#[serde(default)] SetProviderResponse),
7182 #[cfg(feature = "unstable_llm_providers")]
7184 DisableProviderResponse(#[serde(default)] DisableProviderResponse),
7185 LogoutResponse(#[serde(default)] LogoutResponse),
7187 #[cfg(feature = "unstable_auth_status")]
7189 AuthStatusResponse(AuthStatusResponse),
7190 NewSessionResponse(NewSessionResponse),
7192 LoadSessionResponse(#[serde(default)] LoadSessionResponse),
7194 ListSessionsResponse(ListSessionsResponse),
7196 DeleteSessionResponse(#[serde(default)] DeleteSessionResponse),
7198 #[cfg(feature = "unstable_session_fork")]
7200 ForkSessionResponse(ForkSessionResponse),
7201 #[cfg(feature = "unstable_session_archive")]
7203 ArchiveSessionResponse(#[serde(default)] ArchiveSessionResponse),
7204 #[cfg(feature = "unstable_session_archive")]
7206 UnarchiveSessionResponse(#[serde(default)] UnarchiveSessionResponse),
7207 #[cfg(feature = "unstable_session_status")]
7209 SessionStatusResponse(SessionStatusResponse),
7210 #[cfg(feature = "unstable_session_options")]
7212 SessionOptionsResponse(#[serde(default)] SessionOptionsResponse),
7213 #[cfg(feature = "unstable_session_set_title")]
7215 SetSessionTitleResponse(SetSessionTitleResponse),
7216 ResumeSessionResponse(#[serde(default)] ResumeSessionResponse),
7218 CloseSessionResponse(#[serde(default)] CloseSessionResponse),
7220 SetSessionModeResponse(#[serde(default)] SetSessionModeResponse),
7222 SetSessionConfigOptionResponse(SetSessionConfigOptionResponse),
7224 PromptResponse(PromptResponse),
7226 ExtMethodResponse(ExtResponse),
7228}
7229
7230#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7237#[derive(Clone, Debug, Serialize, Deserialize)]
7238#[serde(untagged)]
7239#[cfg_attr(feature = "schemars", schemars(inline))]
7240#[non_exhaustive]
7241#[allow(clippy::large_enum_variant)]
7242pub enum ClientNotification {
7243 CancelNotification(CancelNotification),
7255 #[cfg(feature = "unstable_mcp_over_acp")]
7261 MessageMcpNotification(MessageMcpNotification),
7262 ExtNotification(ExtNotification),
7269}
7270
7271impl_message_dispatch! {
7272 ClientNotification {
7273 CancelNotification => AGENT_METHOD_NAMES.session_cancel,
7274 #[cfg(feature = "unstable_mcp_over_acp")]
7275 MessageMcpNotification => AGENT_METHOD_NAMES.mcp_message,
7276 }
7277 extension ExtNotification(ExtNotification);
7278}
7279
7280#[serde_as]
7284#[skip_serializing_none]
7285#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7286#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7287#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_CANCEL_METHOD_NAME)))]
7288#[serde(rename_all = "camelCase")]
7289#[non_exhaustive]
7290pub struct CancelNotification {
7291 pub session_id: SessionId,
7293 #[serde_as(deserialize_as = "DefaultOnError")]
7299 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7300 #[serde(default)]
7301 #[serde(rename = "_meta")]
7302 pub meta: Option<Meta>,
7303}
7304
7305impl CancelNotification {
7306 #[must_use]
7308 pub fn new(session_id: impl Into<SessionId>) -> Self {
7309 Self {
7310 session_id: session_id.into(),
7311 meta: None,
7312 }
7313 }
7314
7315 #[must_use]
7321 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
7322 self.meta = meta.into_option();
7323 self
7324 }
7325}
7326
7327#[cfg(test)]
7328mod test_serialization {
7329 use super::*;
7330 use serde_json::json;
7331
7332 fn test_meta() -> Meta {
7333 json!({ "source": "test" }).as_object().unwrap().clone()
7334 }
7335
7336 fn serialized_meta_key_count(value: &impl serde::Serialize) -> usize {
7337 serde_json::to_string(value)
7338 .unwrap()
7339 .matches("\"_meta\"")
7340 .count()
7341 }
7342
7343 #[test]
7346 fn prompt_response_has_no_error_stop_reason() {
7347 assert_eq!(
7348 serde_json::from_value::<PromptResponse>(json!({ "stopReason": "end_turn" }))
7349 .unwrap()
7350 .stop_reason,
7351 StopReason::EndTurn
7352 );
7353 assert!(
7354 serde_json::from_value::<PromptResponse>(json!({ "stopReason": "error" })).is_err()
7355 );
7356 }
7357
7358 #[test]
7359 fn test_initialize_capabilities_default_on_malformed_values() {
7360 let request: InitializeRequest = serde_json::from_value(json!({
7361 "protocolVersion": 1,
7362 "clientCapabilities": false
7363 }))
7364 .unwrap();
7365 assert_eq!(request.client_capabilities, ClientCapabilities::default());
7366
7367 let response: InitializeResponse = serde_json::from_value(json!({
7368 "protocolVersion": 1,
7369 "agentCapabilities": false
7370 }))
7371 .unwrap();
7372 assert_eq!(response.agent_capabilities, AgentCapabilities::default());
7373 }
7374
7375 #[test]
7376 fn test_agent_capabilities_default_on_malformed_values() {
7377 let capabilities: AgentCapabilities = serde_json::from_value(json!({
7378 "loadSession": "yes",
7379 "promptCapabilities": {
7380 "image": "yes",
7381 "audio": true,
7382 "embeddedContext": {}
7383 },
7384 "mcpCapabilities": {
7385 "http": "yes",
7386 "sse": true
7387 },
7388 "sessionCapabilities": false,
7389 "auth": false
7390 }))
7391 .unwrap();
7392
7393 assert!(!capabilities.load_session);
7394 assert!(!capabilities.prompt_capabilities.image);
7395 assert!(capabilities.prompt_capabilities.audio);
7396 assert!(!capabilities.prompt_capabilities.embedded_context);
7397 assert!(!capabilities.mcp_capabilities.http);
7398 assert!(capabilities.mcp_capabilities.sse);
7399 assert_eq!(
7400 capabilities.session_capabilities,
7401 SessionCapabilities::default()
7402 );
7403 assert_eq!(capabilities.auth, AgentAuthCapabilities::default());
7404 }
7405
7406 #[test]
7407 fn test_mcp_server_stdio_serialization() {
7408 let server = McpServer::Stdio(
7409 McpServerStdio::new("test-server", "/usr/bin/server")
7410 .args(vec!["--port".to_string(), "3000".to_string()])
7411 .env(vec![EnvVariable::new("API_KEY", "secret123")]),
7412 );
7413
7414 let json = serde_json::to_value(&server).unwrap();
7415 assert_eq!(
7416 json,
7417 json!({
7418 "name": "test-server",
7419 "command": "/usr/bin/server",
7420 "args": ["--port", "3000"],
7421 "env": [
7422 {
7423 "name": "API_KEY",
7424 "value": "secret123"
7425 }
7426 ]
7427 })
7428 );
7429
7430 let deserialized: McpServer = serde_json::from_value(json).unwrap();
7431 match deserialized {
7432 McpServer::Stdio(McpServerStdio {
7433 name,
7434 command,
7435 args,
7436 env,
7437 meta: _,
7438 }) => {
7439 assert_eq!(name, "test-server");
7440 assert_eq!(command, PathBuf::from("/usr/bin/server"));
7441 assert_eq!(args, vec!["--port", "3000"]);
7442 assert_eq!(env.len(), 1);
7443 assert_eq!(env[0].name, "API_KEY");
7444 assert_eq!(env[0].value, "secret123");
7445 }
7446 _ => panic!("Expected Stdio variant"),
7447 }
7448 }
7449
7450 #[test]
7451 fn test_mcp_server_http_serialization() {
7452 let server = McpServer::Http(
7453 McpServerHttp::new("http-server", "https://api.example.com").headers(vec![
7454 HttpHeader::new("Authorization", "Bearer token123"),
7455 HttpHeader::new("Content-Type", "application/json"),
7456 ]),
7457 );
7458
7459 let json = serde_json::to_value(&server).unwrap();
7460 assert_eq!(
7461 json,
7462 json!({
7463 "type": "http",
7464 "name": "http-server",
7465 "url": "https://api.example.com",
7466 "headers": [
7467 {
7468 "name": "Authorization",
7469 "value": "Bearer token123"
7470 },
7471 {
7472 "name": "Content-Type",
7473 "value": "application/json"
7474 }
7475 ]
7476 })
7477 );
7478
7479 let deserialized: McpServer = serde_json::from_value(json).unwrap();
7480 match deserialized {
7481 McpServer::Http(McpServerHttp {
7482 name,
7483 url,
7484 headers,
7485 meta: _,
7486 }) => {
7487 assert_eq!(name, "http-server");
7488 assert_eq!(url, "https://api.example.com");
7489 assert_eq!(headers.len(), 2);
7490 assert_eq!(headers[0].name, "Authorization");
7491 assert_eq!(headers[0].value, "Bearer token123");
7492 assert_eq!(headers[1].name, "Content-Type");
7493 assert_eq!(headers[1].value, "application/json");
7494 }
7495 _ => panic!("Expected Http variant"),
7496 }
7497 }
7498
7499 #[cfg(feature = "unstable_mcp_over_acp")]
7500 #[test]
7501 fn test_mcp_server_acp_serialization() {
7502 let server = McpServer::Acp(McpServerAcp::new("project-tools", "project-tools-id"));
7503
7504 let json = serde_json::to_value(&server).unwrap();
7505 assert_eq!(
7506 json,
7507 json!({
7508 "type": "acp",
7509 "name": "project-tools",
7510 "serverId": "project-tools-id"
7511 })
7512 );
7513
7514 let deserialized: McpServer = serde_json::from_value(json).unwrap();
7515 match deserialized {
7516 McpServer::Acp(McpServerAcp {
7517 name,
7518 server_id: id,
7519 meta: _,
7520 }) => {
7521 assert_eq!(name, "project-tools");
7522 assert_eq!(id, McpServerAcpId::new("project-tools-id"));
7523 }
7524 _ => panic!("Expected Acp variant"),
7525 }
7526 }
7527
7528 #[cfg(feature = "unstable_mcp_over_acp")]
7529 #[test]
7530 fn test_client_mcp_message_method_names() {
7531 use serde_json::json;
7532
7533 assert_eq!(AGENT_METHOD_NAMES.mcp_message, "mcp/message");
7534
7535 let notification =
7536 MessageMcpNotification::new("server-1", "req-1", "notifications/progress");
7537 assert_eq!(
7538 ClientNotification::MessageMcpNotification(notification.clone()).method(),
7539 "mcp/message"
7540 );
7541 assert_eq!(
7542 serde_json::to_value(notification).unwrap(),
7543 json!({
7544 "serverId": "server-1",
7545 "requestId": "req-1",
7546 "method": "notifications/progress"
7547 })
7548 );
7549 let notification: MessageMcpNotification = serde_json::from_value(json!({
7550 "serverId": "server-1", "requestId": "req-1", "method": "notifications/progress",
7551 "params": null, "_meta": null
7552 }))
7553 .unwrap();
7554 assert_eq!(notification.params, None);
7555 assert_eq!(notification.meta, None);
7556 for key in ["serverId", "requestId", "method"] {
7557 let mut value = json!({"serverId":"server-1", "requestId":"req-1", "method":"notifications/progress"});
7558 value.as_object_mut().unwrap().remove(key);
7559 assert!(serde_json::from_value::<MessageMcpNotification>(value).is_err());
7560 }
7561 }
7562
7563 #[cfg(all(feature = "unstable_mcp_over_acp", feature = "schemars"))]
7564 #[test]
7565 fn test_mcp_server_acp_schema() {
7566 let mcp_server_schema = serde_json::to_value(schemars::schema_for!(McpServer)).unwrap();
7567 assert!(json_contains_entry(
7568 &mcp_server_schema,
7569 "const",
7570 &json!("acp")
7571 ));
7572 assert!(json_contains_entry(
7573 &mcp_server_schema,
7574 "$ref",
7575 &json!("#/$defs/McpServerAcp")
7576 ));
7577
7578 let capabilities_schema =
7579 serde_json::to_value(schemars::schema_for!(McpCapabilities)).unwrap();
7580 assert!(json_contains_key(&capabilities_schema, "acp"));
7581 }
7582
7583 #[cfg(all(feature = "unstable_mcp_over_acp", feature = "schemars"))]
7584 fn json_contains_entry(
7585 value: &serde_json::Value,
7586 key: &str,
7587 expected: &serde_json::Value,
7588 ) -> bool {
7589 match value {
7590 serde_json::Value::Object(map) => {
7591 map.get(key) == Some(expected)
7592 || map
7593 .values()
7594 .any(|value| json_contains_entry(value, key, expected))
7595 }
7596 serde_json::Value::Array(values) => values
7597 .iter()
7598 .any(|value| json_contains_entry(value, key, expected)),
7599 _ => false,
7600 }
7601 }
7602
7603 #[cfg(all(feature = "unstable_mcp_over_acp", feature = "schemars"))]
7604 fn json_contains_key(value: &serde_json::Value, key: &str) -> bool {
7605 match value {
7606 serde_json::Value::Object(map) => {
7607 map.contains_key(key) || map.values().any(|value| json_contains_key(value, key))
7608 }
7609 serde_json::Value::Array(values) => {
7610 values.iter().any(|value| json_contains_key(value, key))
7611 }
7612 _ => false,
7613 }
7614 }
7615
7616 #[test]
7617 fn test_mcp_server_sse_serialization() {
7618 let server = McpServer::Sse(
7619 McpServerSse::new("sse-server", "https://sse.example.com/events")
7620 .headers(vec![HttpHeader::new("X-API-Key", "apikey456")]),
7621 );
7622
7623 let json = serde_json::to_value(&server).unwrap();
7624 assert_eq!(
7625 json,
7626 json!({
7627 "type": "sse",
7628 "name": "sse-server",
7629 "url": "https://sse.example.com/events",
7630 "headers": [
7631 {
7632 "name": "X-API-Key",
7633 "value": "apikey456"
7634 }
7635 ]
7636 })
7637 );
7638
7639 let deserialized: McpServer = serde_json::from_value(json).unwrap();
7640 match deserialized {
7641 McpServer::Sse(McpServerSse {
7642 name,
7643 url,
7644 headers,
7645 meta: _,
7646 }) => {
7647 assert_eq!(name, "sse-server");
7648 assert_eq!(url, "https://sse.example.com/events");
7649 assert_eq!(headers.len(), 1);
7650 assert_eq!(headers[0].name, "X-API-Key");
7651 assert_eq!(headers[0].value, "apikey456");
7652 }
7653 _ => panic!("Expected Sse variant"),
7654 }
7655 }
7656
7657 #[test]
7658 fn test_session_config_option_category_known_variants() {
7659 assert_eq!(
7661 serde_json::to_value(&SessionConfigOptionCategory::Mode).unwrap(),
7662 json!("mode")
7663 );
7664 assert_eq!(
7665 serde_json::to_value(&SessionConfigOptionCategory::Model).unwrap(),
7666 json!("model")
7667 );
7668 assert_eq!(
7669 serde_json::to_value(&SessionConfigOptionCategory::ModelConfig).unwrap(),
7670 json!("model_config")
7671 );
7672 #[cfg(feature = "unstable_speed_config_category")]
7673 assert_eq!(
7674 serde_json::to_value(&SessionConfigOptionCategory::Speed).unwrap(),
7675 json!("speed")
7676 );
7677 assert_eq!(
7678 serde_json::to_value(&SessionConfigOptionCategory::ThoughtLevel).unwrap(),
7679 json!("thought_level")
7680 );
7681
7682 assert_eq!(
7684 serde_json::from_str::<SessionConfigOptionCategory>("\"mode\"").unwrap(),
7685 SessionConfigOptionCategory::Mode
7686 );
7687 assert_eq!(
7688 serde_json::from_str::<SessionConfigOptionCategory>("\"model\"").unwrap(),
7689 SessionConfigOptionCategory::Model
7690 );
7691 assert_eq!(
7692 serde_json::from_str::<SessionConfigOptionCategory>("\"model_config\"").unwrap(),
7693 SessionConfigOptionCategory::ModelConfig
7694 );
7695 #[cfg(feature = "unstable_speed_config_category")]
7696 assert_eq!(
7697 serde_json::from_str::<SessionConfigOptionCategory>("\"speed\"").unwrap(),
7698 SessionConfigOptionCategory::Speed
7699 );
7700 assert_eq!(
7701 serde_json::from_str::<SessionConfigOptionCategory>("\"thought_level\"").unwrap(),
7702 SessionConfigOptionCategory::ThoughtLevel
7703 );
7704 }
7705
7706 #[test]
7707 fn test_session_config_option_category_unknown_variants() {
7708 let unknown: SessionConfigOptionCategory =
7710 serde_json::from_str("\"some_future_category\"").unwrap();
7711 assert_eq!(
7712 unknown,
7713 SessionConfigOptionCategory::Other("some_future_category".to_string())
7714 );
7715
7716 let json = serde_json::to_value(&unknown).unwrap();
7718 assert_eq!(json, json!("some_future_category"));
7719 }
7720
7721 #[cfg(not(feature = "unstable_speed_config_category"))]
7722 #[test]
7723 fn test_session_config_option_speed_is_unknown_without_feature() {
7724 let unknown: SessionConfigOptionCategory = serde_json::from_str("\"speed\"").unwrap();
7725 assert_eq!(
7726 unknown,
7727 SessionConfigOptionCategory::Other("speed".to_string())
7728 );
7729 }
7730
7731 #[test]
7732 fn test_session_config_option_category_custom_categories() {
7733 let custom: SessionConfigOptionCategory =
7735 serde_json::from_str("\"_my_custom_category\"").unwrap();
7736 assert_eq!(
7737 custom,
7738 SessionConfigOptionCategory::Other("_my_custom_category".to_string())
7739 );
7740
7741 let json = serde_json::to_value(&custom).unwrap();
7743 assert_eq!(json, json!("_my_custom_category"));
7744
7745 let deserialized: SessionConfigOptionCategory = serde_json::from_value(json).unwrap();
7747 assert_eq!(
7748 deserialized,
7749 SessionConfigOptionCategory::Other("_my_custom_category".to_string()),
7750 );
7751 }
7752
7753 #[test]
7754 fn test_auth_method_agent_serialization() {
7755 let method = AuthMethod::Agent(AuthMethodAgent::new("default-auth", "Default Auth"));
7756
7757 let json = serde_json::to_value(&method).unwrap();
7758 assert_eq!(
7759 json,
7760 json!({
7761 "id": "default-auth",
7762 "name": "Default Auth"
7763 })
7764 );
7765 assert!(!json.as_object().unwrap().contains_key("description"));
7767 assert!(!json.as_object().unwrap().contains_key("type"));
7769
7770 let deserialized: AuthMethod = serde_json::from_value(json).unwrap();
7771 match deserialized {
7772 AuthMethod::Agent(AuthMethodAgent { id, name, .. }) => {
7773 assert_eq!(id.0.as_ref(), "default-auth");
7774 assert_eq!(name, "Default Auth");
7775 }
7776 _ => panic!("Expected Agent variant"),
7777 }
7778 }
7779
7780 #[test]
7781 fn test_auth_method_explicit_agent_deserialization() {
7782 let json = json!({
7784 "id": "agent-auth",
7785 "name": "Agent Auth",
7786 "type": "agent"
7787 });
7788
7789 let deserialized: AuthMethod = serde_json::from_value(json).unwrap();
7790 assert!(matches!(deserialized, AuthMethod::Agent(_)));
7791 }
7792
7793 #[test]
7794 fn test_session_delete_serialization() {
7795 assert_eq!(AGENT_METHOD_NAMES.session_delete, "session/delete");
7796 assert_eq!(
7797 ClientRequest::DeleteSessionRequest(DeleteSessionRequest::new("sess_abc123")).method(),
7798 "session/delete"
7799 );
7800 assert_eq!(
7801 serde_json::to_value(DeleteSessionRequest::new("sess_abc123")).unwrap(),
7802 json!({
7803 "sessionId": "sess_abc123"
7804 })
7805 );
7806 assert_eq!(
7807 serde_json::to_value(DeleteSessionResponse::new()).unwrap(),
7808 json!({})
7809 );
7810 assert_eq!(
7811 serde_json::to_value(
7812 SessionCapabilities::new().delete(SessionDeleteCapabilities::new())
7813 )
7814 .unwrap(),
7815 json!({
7816 "delete": {}
7817 })
7818 );
7819 }
7820 #[cfg(feature = "unstable_session_set_title")]
7821 #[test]
7822 fn test_session_set_title_serialization() {
7823 assert_eq!(AGENT_METHOD_NAMES.session_set_title, "session/set_title");
7824 assert_eq!(
7825 ClientRequest::SetSessionTitleRequest(SetSessionTitleRequest::new(
7826 "sess_abc123",
7827 "Investigate OAuth timeout"
7828 ))
7829 .method(),
7830 "session/set_title"
7831 );
7832 assert_eq!(
7833 serde_json::to_value(SetSessionTitleRequest::new(
7834 "sess_abc123",
7835 "Investigate OAuth timeout"
7836 ))
7837 .unwrap(),
7838 json!({
7839 "sessionId": "sess_abc123",
7840 "title": "Investigate OAuth timeout"
7841 })
7842 );
7843 assert_eq!(
7844 serde_json::to_value(SetSessionTitleResponse::new("Investigate OAuth timeout"))
7845 .unwrap(),
7846 json!({
7847 "title": "Investigate OAuth timeout"
7848 })
7849 );
7850 assert_eq!(
7851 serde_json::to_value(SessionCapabilities::new().title(SessionTitleCapabilities::new()))
7852 .unwrap(),
7853 json!({
7854 "title": {}
7855 })
7856 );
7857 }
7858
7859 #[cfg(feature = "unstable_session_set_title")]
7860 #[test]
7861 fn test_session_set_title_requires_title() {
7862 for params in [
7863 json!({"sessionId": "sess_abc123"}),
7864 json!({"sessionId": "sess_abc123", "title": null}),
7865 json!({"sessionId": "sess_abc123", "title": 42}),
7866 ] {
7867 assert!(serde_json::from_value::<SetSessionTitleRequest>(params).is_err());
7868 }
7869 for result in [json!({}), json!({"title": null})] {
7870 assert!(serde_json::from_value::<SetSessionTitleResponse>(result).is_err());
7871 }
7872 }
7873
7874 #[cfg(feature = "unstable_session_options")]
7875 #[test]
7876 fn test_session_options_serialization() {
7877 assert_eq!(AGENT_METHOD_NAMES.session_options, "session/options");
7878 assert_eq!(
7879 ClientRequest::SessionOptionsRequest(SessionOptionsRequest::new("/home/user/project"))
7880 .method(),
7881 "session/options"
7882 );
7883 assert_eq!(
7884 serde_json::to_value(
7885 SessionOptionsRequest::new("/home/user/project")
7886 .session_id(SessionId::new("sess_abc123"))
7887 )
7888 .unwrap(),
7889 json!({"cwd": "/home/user/project", "sessionId": "sess_abc123"})
7890 );
7891 assert_eq!(
7892 serde_json::from_value::<SessionOptionsRequest>(
7893 json!({"cwd": "/home/user/project", "additionalDirectories": null, "sessionId": null})
7894 )
7895 .unwrap(),
7896 SessionOptionsRequest::new("/home/user/project")
7897 );
7898 let request = NewSessionRequest::new("/home/user/project").config_options(vec![
7899 InitialSessionConfigOption::new("model", SessionConfigOptionValue::value_id("model-2")),
7900 InitialSessionConfigOption::new("fast", SessionConfigOptionValue::boolean(true)),
7901 ]);
7902 let value = serde_json::to_value(&request).unwrap();
7903 assert_eq!(
7904 value["configOptions"],
7905 json!([
7906 {"configId": "model", "value": "model-2"},
7907 {"configId": "fast", "type": "boolean", "value": true}
7908 ])
7909 );
7910 assert_eq!(
7911 serde_json::from_value::<NewSessionRequest>(value).unwrap(),
7912 request
7913 );
7914 assert!(
7915 serde_json::from_value::<NewSessionRequest>(json!({
7916 "cwd": "/home/user/project",
7917 "mcpServers": [],
7918 "configOptions": [{"type": "boolean", "value": true}]
7919 }))
7920 .is_err()
7921 );
7922 assert_eq!(
7923 serde_json::to_value(SessionOptionsResponse::new()).unwrap(),
7924 json!({})
7925 );
7926 #[cfg(feature = "unstable_session_fork")]
7927 {
7928 let fork =
7929 ForkSessionRequest::new("sess_abc123", "/home/user/project").config_options(vec![
7930 InitialSessionConfigOption::new(
7931 "model",
7932 SessionConfigOptionValue::value_id("model-2"),
7933 ),
7934 ]);
7935 let value = serde_json::to_value(&fork).unwrap();
7936 assert_eq!(
7937 value["configOptions"],
7938 json!([{"configId": "model", "value": "model-2"}])
7939 );
7940 assert_eq!(
7941 serde_json::from_value::<ForkSessionRequest>(value).unwrap(),
7942 fork
7943 );
7944 assert_eq!(
7946 serde_json::from_value::<ForkSessionRequest>(json!({
7947 "sessionId": "sess_abc123",
7948 "cwd": "/home/user/project",
7949 "configOptions": null
7950 }))
7951 .unwrap(),
7952 ForkSessionRequest::new("sess_abc123", "/home/user/project")
7953 );
7954 assert!(
7955 serde_json::from_value::<ForkSessionRequest>(json!({
7956 "sessionId": "sess_abc123",
7957 "cwd": "/home/user/project",
7958 "configOptions": [{"type": "boolean", "value": true}]
7959 }))
7960 .is_err()
7961 );
7962 }
7963 assert_eq!(
7964 serde_json::to_value(
7965 SessionCapabilities::new().options(SessionOptionsCapabilities::new())
7966 )
7967 .unwrap(),
7968 json!({"options": {}})
7969 );
7970 }
7971
7972 #[cfg(feature = "unstable_session_status")]
7973 #[test]
7974 fn test_session_status_serialization() {
7975 assert_eq!(AGENT_METHOD_NAMES.session_status, "session/status");
7976 assert_eq!(
7977 ClientRequest::SessionStatusRequest(SessionStatusRequest::new("sess_abc123")).method(),
7978 "session/status"
7979 );
7980 assert_eq!(
7981 serde_json::to_value(SessionStatusRequest::new("sess_abc123")).unwrap(),
7982 json!({"sessionId": "sess_abc123"})
7983 );
7984 assert_eq!(
7985 serde_json::to_value(SessionStatusResponse::new(SessionStatus::Saved)).unwrap(),
7986 json!({"status": "saved"})
7987 );
7988 assert_eq!(
7989 serde_json::to_value(
7990 SessionCapabilities::new().status(SessionStatusCapabilities::new())
7991 )
7992 .unwrap(),
7993 json!({"status": {}})
7994 );
7995 }
7996
7997 #[cfg(feature = "unstable_session_status")]
7998 #[test]
7999 fn test_session_status_is_strict_and_open() {
8000 let custom =
8001 serde_json::from_value::<SessionStatusResponse>(json!({"status": "_suspended"}))
8002 .unwrap();
8003 assert_eq!(
8004 custom.status,
8005 SessionStatus::Other("_suspended".to_string())
8006 );
8007 assert_eq!(
8008 serde_json::to_value(&custom).unwrap(),
8009 json!({"status": "_suspended"})
8010 );
8011 for result in [json!({}), json!({"status": null}), json!({"status": 1})] {
8012 assert!(serde_json::from_value::<SessionStatusResponse>(result).is_err());
8013 }
8014 for params in [json!({}), json!({"sessionId": null})] {
8015 assert!(serde_json::from_value::<SessionStatusRequest>(params).is_err());
8016 }
8017 }
8018
8019 #[cfg(feature = "unstable_session_archive")]
8020 #[test]
8021 fn test_session_archive_serialization() {
8022 assert_eq!(AGENT_METHOD_NAMES.session_archive, "session/archive");
8023 assert_eq!(AGENT_METHOD_NAMES.session_unarchive, "session/unarchive");
8024 assert_eq!(
8025 ClientRequest::ArchiveSessionRequest(ArchiveSessionRequest::new("sess_abc123"))
8026 .method(),
8027 "session/archive"
8028 );
8029 assert_eq!(
8030 ClientRequest::UnarchiveSessionRequest(UnarchiveSessionRequest::new("sess_abc123"))
8031 .method(),
8032 "session/unarchive"
8033 );
8034 assert_eq!(
8035 serde_json::to_value(ArchiveSessionRequest::new("sess_abc123")).unwrap(),
8036 json!({"sessionId": "sess_abc123"})
8037 );
8038 assert_eq!(
8039 serde_json::to_value(UnarchiveSessionResponse::new()).unwrap(),
8040 json!({})
8041 );
8042 assert_eq!(
8043 serde_json::to_value(
8044 SessionCapabilities::new().archive(SessionArchiveCapabilities::new())
8045 )
8046 .unwrap(),
8047 json!({"archive": {}})
8048 );
8049 assert_eq!(
8050 serde_json::to_value(
8051 ListSessionsRequest::new()
8052 .cwd("/home/user/project")
8053 .archived(SessionArchiveFilter::Only)
8054 )
8055 .unwrap(),
8056 json!({"cwd": "/home/user/project", "archived": "only"})
8057 );
8058 assert_eq!(
8059 serde_json::to_value(
8060 SessionInfo::new("sess_abc123", "/home/user/project").archived(true)
8061 )
8062 .unwrap(),
8063 json!({"sessionId": "sess_abc123", "cwd": "/home/user/project", "archived": true})
8064 );
8065 }
8066
8067 #[cfg(feature = "unstable_session_archive")]
8068 #[test]
8069 fn test_session_archive_filter_is_strict_and_open() {
8070 for (value, expected) in [
8071 (json!(null), None),
8072 (json!("include"), Some(SessionArchiveFilter::Include)),
8073 (
8074 json!("_recent"),
8075 Some(SessionArchiveFilter::Other("_recent".to_string())),
8076 ),
8077 ] {
8078 let request =
8079 serde_json::from_value::<ListSessionsRequest>(json!({"archived": value})).unwrap();
8080 assert_eq!(request.archived, expected);
8081 }
8082 for value in [json!(true), json!(1), json!({})] {
8083 assert!(
8084 serde_json::from_value::<ListSessionsRequest>(json!({"archived": value})).is_err()
8085 );
8086 }
8087 let info = serde_json::from_value::<SessionInfo>(
8088 json!({"sessionId": "sess_abc123", "cwd": "/home/user/project", "archived": "yes"}),
8089 )
8090 .unwrap();
8091 assert_eq!(info.archived, None);
8092 }
8093
8094 #[test]
8095 fn test_session_additional_directories_serialization() {
8096 assert_eq!(
8097 serde_json::to_value(NewSessionRequest::new("/home/user/project")).unwrap(),
8098 json!({
8099 "cwd": "/home/user/project",
8100 "mcpServers": []
8101 })
8102 );
8103 assert_eq!(
8104 serde_json::to_value(
8105 NewSessionRequest::new("/home/user/project").additional_directories(vec![
8106 PathBuf::from("/home/user/shared-lib"),
8107 PathBuf::from("/home/user/product-docs"),
8108 ])
8109 )
8110 .unwrap(),
8111 json!({
8112 "cwd": "/home/user/project",
8113 "additionalDirectories": [
8114 "/home/user/shared-lib",
8115 "/home/user/product-docs"
8116 ],
8117 "mcpServers": []
8118 })
8119 );
8120 assert_eq!(
8121 serde_json::to_value(SessionInfo::new("sess_abc123", "/home/user/project")).unwrap(),
8122 json!({
8123 "sessionId": "sess_abc123",
8124 "cwd": "/home/user/project"
8125 })
8126 );
8127 assert_eq!(
8128 serde_json::to_value(
8129 SessionInfo::new("sess_abc123", "/home/user/project").additional_directories(vec![
8130 PathBuf::from("/home/user/shared-lib"),
8131 PathBuf::from("/home/user/product-docs"),
8132 ])
8133 )
8134 .unwrap(),
8135 json!({
8136 "sessionId": "sess_abc123",
8137 "cwd": "/home/user/project",
8138 "additionalDirectories": [
8139 "/home/user/shared-lib",
8140 "/home/user/product-docs"
8141 ]
8142 })
8143 );
8144 assert_eq!(
8145 serde_json::from_value::<SessionInfo>(json!({
8146 "sessionId": "sess_abc123",
8147 "cwd": "/home/user/project"
8148 }))
8149 .unwrap()
8150 .additional_directories,
8151 Vec::<PathBuf>::new()
8152 );
8153 }
8154 #[test]
8155 fn test_session_additional_directories_capabilities_serialization() {
8156 assert_eq!(
8157 serde_json::to_value(
8158 SessionCapabilities::new()
8159 .additional_directories(SessionAdditionalDirectoriesCapabilities::new())
8160 )
8161 .unwrap(),
8162 json!({
8163 "additionalDirectories": {}
8164 })
8165 );
8166 }
8167
8168 #[test]
8169 fn test_session_system_prompt_capabilities_serialization() {
8170 assert_eq!(
8171 serde_json::to_value(
8172 SessionCapabilities::new().system_prompt(SessionSystemPromptCapabilities::new())
8173 )
8174 .unwrap(),
8175 json!({ "systemPrompt": {} })
8176 );
8177 assert_eq!(
8178 serde_json::to_value(
8179 SessionCapabilities::new().system_prompt(
8180 SessionSystemPromptCapabilities::new().mode(
8181 SessionSystemPromptModeCapabilities::new()
8182 .override_(SessionSystemPromptOverrideCapabilities::new())
8183 )
8184 )
8185 )
8186 .unwrap(),
8187 json!({ "systemPrompt": { "mode": { "override": {} } } })
8188 );
8189 assert_eq!(
8190 serde_json::from_value::<SessionCapabilities>(
8191 json!({ "systemPrompt": { "mode": { "override": {} } } })
8192 )
8193 .unwrap()
8194 .system_prompt
8195 .and_then(|capabilities| capabilities.mode)
8196 .and_then(|mode| mode.override_),
8197 Some(SessionSystemPromptOverrideCapabilities::new())
8198 );
8199
8200 assert_eq!(
8202 serde_json::from_value::<SessionCapabilities>(json!({ "systemPrompt": "yes" }))
8203 .unwrap()
8204 .system_prompt,
8205 None
8206 );
8207 assert_eq!(
8208 serde_json::from_value::<SessionCapabilities>(
8209 json!({ "systemPrompt": { "mode": { "override": true } } })
8210 )
8211 .unwrap()
8212 .system_prompt,
8213 Some(
8214 SessionSystemPromptCapabilities::new()
8215 .mode(SessionSystemPromptModeCapabilities::new())
8216 )
8217 );
8218 assert_eq!(
8219 serde_json::from_value::<SessionCapabilities>(
8220 json!({ "systemPrompt": { "mode": "override" } })
8221 )
8222 .unwrap()
8223 .system_prompt,
8224 Some(SessionSystemPromptCapabilities::new())
8225 );
8226 }
8227
8228 #[test]
8229 fn test_system_prompt_lifecycle_request_serialization() {
8230 let system_prompt = SystemPrompt::new(vec![ContentBlock::from(
8231 "You are a code review specialist.",
8232 )]);
8233 let system_prompt_json = json!({
8234 "mode": "append",
8235 "content": [{ "type": "text", "text": "You are a code review specialist." }]
8236 });
8237
8238 let request =
8239 NewSessionRequest::new("/home/user/project").system_prompt(system_prompt.clone());
8240 let request_json = json!({
8241 "cwd": "/home/user/project",
8242 "mcpServers": [],
8243 "systemPrompt": system_prompt_json
8244 });
8245 assert_eq!(serde_json::to_value(&request).unwrap(), request_json);
8246 assert_eq!(
8247 serde_json::from_value::<NewSessionRequest>(request_json).unwrap(),
8248 request
8249 );
8250
8251 assert_eq!(
8252 serde_json::to_value(
8253 LoadSessionRequest::new("sess_abc123", "/home/user/project")
8254 .system_prompt(system_prompt.clone())
8255 )
8256 .unwrap()["systemPrompt"],
8257 system_prompt_json
8258 );
8259 assert_eq!(
8260 serde_json::to_value(
8261 ResumeSessionRequest::new("sess_abc123", "/home/user/project")
8262 .system_prompt(system_prompt.clone())
8263 )
8264 .unwrap()["systemPrompt"],
8265 system_prompt_json
8266 );
8267 #[cfg(feature = "unstable_session_fork")]
8268 assert_eq!(
8269 serde_json::to_value(
8270 ForkSessionRequest::new("sess_abc123", "/home/user/project")
8271 .system_prompt(system_prompt.clone())
8272 )
8273 .unwrap()["systemPrompt"],
8274 system_prompt_json
8275 );
8276
8277 let override_prompt =
8278 SystemPrompt::new(vec![ContentBlock::from("...")]).mode(SystemPromptMode::Override);
8279 let override_json = json!({
8280 "mode": "override",
8281 "content": [{ "type": "text", "text": "..." }]
8282 });
8283 assert_eq!(
8284 serde_json::to_value(&override_prompt).unwrap(),
8285 override_json
8286 );
8287 assert_eq!(
8288 serde_json::from_value::<SystemPrompt>(override_json).unwrap(),
8289 override_prompt
8290 );
8291 }
8292
8293 #[test]
8296 fn test_system_prompt_new_defaults_to_append() {
8297 let system_prompt = SystemPrompt::new(vec![ContentBlock::from("...")]);
8298 assert_eq!(system_prompt.mode, SystemPromptMode::Append);
8299 assert_eq!(
8300 serde_json::to_value(&system_prompt).unwrap(),
8301 json!({ "mode": "append", "content": [{ "type": "text", "text": "..." }] })
8302 );
8303 }
8304
8305 #[test]
8309 fn test_system_prompt_preserves_unknown_modes() {
8310 for mode in ["_vendor_mode", "prepend"] {
8311 let system_prompt_json =
8312 json!({ "mode": mode, "content": [{ "type": "text", "text": "..." }] });
8313 let system_prompt: SystemPrompt =
8314 serde_json::from_value(system_prompt_json.clone()).unwrap();
8315 assert_eq!(
8316 system_prompt.mode,
8317 SystemPromptMode::Other(mode.to_string())
8318 );
8319 assert_eq!(
8320 serde_json::to_value(&system_prompt).unwrap(),
8321 system_prompt_json
8322 );
8323 }
8324 }
8325
8326 fn assert_system_prompt_is_strict<T>(base: &serde_json::Value)
8330 where
8331 T: serde::de::DeserializeOwned + PartialEq + std::fmt::Debug,
8332 {
8333 let name = std::any::type_name::<T>();
8334 let with = |system_prompt: serde_json::Value| {
8335 let mut request = base.clone();
8336 request["systemPrompt"] = system_prompt;
8337 serde_json::from_value::<T>(request)
8338 };
8339
8340 for system_prompt in [
8341 json!("You are a code review specialist."),
8342 json!({ "content": [{ "type": "text", "text": "..." }] }),
8343 json!({ "mode": null, "content": [{ "type": "text", "text": "..." }] }),
8344 json!({ "mode": 1, "content": [{ "type": "text", "text": "..." }] }),
8345 json!({ "mode": "append" }),
8346 json!({ "mode": "append", "content": "..." }),
8347 json!({ "mode": "append", "content": [{ "type": "text" }] }),
8348 json!({ "mode": "append", "content": [{ "type": "video", "uri": "..." }] }),
8349 ] {
8350 assert!(
8351 with(system_prompt.clone()).is_err(),
8352 "{name}.systemPrompt: {system_prompt}"
8353 );
8354 }
8355
8356 assert_eq!(
8357 with(serde_json::Value::Null).unwrap(),
8358 serde_json::from_value::<T>(base.clone()).unwrap(),
8359 "{name}.systemPrompt"
8360 );
8361 }
8362
8363 #[test]
8364 fn test_session_setup_requests_reject_malformed_system_prompts() {
8365 assert!(
8366 serde_json::to_value(NewSessionRequest::new("/repo"))
8367 .unwrap()
8368 .get("systemPrompt")
8369 .is_none()
8370 );
8371 assert_system_prompt_is_strict::<NewSessionRequest>(&json!({
8372 "cwd": "/repo",
8373 "mcpServers": []
8374 }));
8375 assert_system_prompt_is_strict::<LoadSessionRequest>(&json!({
8376 "sessionId": "sess-1",
8377 "cwd": "/repo",
8378 "mcpServers": []
8379 }));
8380 assert_system_prompt_is_strict::<ResumeSessionRequest>(&json!({
8381 "sessionId": "sess-1",
8382 "cwd": "/repo"
8383 }));
8384 #[cfg(feature = "unstable_session_fork")]
8385 assert_system_prompt_is_strict::<ForkSessionRequest>(&json!({
8386 "sessionId": "sess-1",
8387 "cwd": "/repo"
8388 }));
8389 }
8390
8391 #[test]
8392 fn test_auth_method_terminal_serialization() {
8393 let method = AuthMethod::Terminal(AuthMethodTerminal::new("tui-auth", "Terminal Auth"));
8394
8395 let json = serde_json::to_value(&method).unwrap();
8396 assert_eq!(
8397 json,
8398 json!({
8399 "id": "tui-auth",
8400 "name": "Terminal Auth",
8401 "type": "terminal"
8402 })
8403 );
8404 assert!(!json.as_object().unwrap().contains_key("args"));
8406 assert!(!json.as_object().unwrap().contains_key("env"));
8407
8408 let deserialized: AuthMethod = serde_json::from_value(json).unwrap();
8409 match deserialized {
8410 AuthMethod::Terminal(AuthMethodTerminal { args, env, .. }) => {
8411 assert_eq!(args, Vec::<String>::new());
8412 assert!(env.is_empty());
8413 }
8414 _ => panic!("Expected Terminal variant"),
8415 }
8416 }
8417
8418 #[test]
8419 fn test_auth_method_terminal_with_args_and_env_serialization() {
8420 use std::collections::HashMap;
8421
8422 let mut env = HashMap::new();
8423 env.insert("TERM".to_string(), "xterm-256color".to_string());
8424
8425 let method = AuthMethod::Terminal(
8426 AuthMethodTerminal::new("tui-auth", "Terminal Auth")
8427 .args(vec!["--interactive".to_string(), "--color".to_string()])
8428 .env(env),
8429 );
8430
8431 let json = serde_json::to_value(&method).unwrap();
8432 assert_eq!(
8433 json,
8434 json!({
8435 "id": "tui-auth",
8436 "name": "Terminal Auth",
8437 "type": "terminal",
8438 "args": ["--interactive", "--color"],
8439 "env": {
8440 "TERM": "xterm-256color"
8441 }
8442 })
8443 );
8444
8445 let deserialized: AuthMethod = serde_json::from_value(json).unwrap();
8446 match deserialized {
8447 AuthMethod::Terminal(AuthMethodTerminal { args, env, .. }) => {
8448 assert_eq!(args, vec!["--interactive", "--color"]);
8449 assert_eq!(env.len(), 1);
8450 assert_eq!(env.get("TERM").unwrap(), "xterm-256color");
8451 }
8452 _ => panic!("Expected Terminal variant"),
8453 }
8454 }
8455
8456 #[test]
8457 fn test_session_config_option_value_id_serialize() {
8458 let val = SessionConfigOptionValue::value_id("model-1");
8459 let json = serde_json::to_value(&val).unwrap();
8460 assert_eq!(json, json!({ "value": "model-1" }));
8462 assert!(!json.as_object().unwrap().contains_key("type"));
8463 }
8464
8465 #[test]
8466 fn test_session_config_option_value_boolean_serialize() {
8467 let val = SessionConfigOptionValue::boolean(true);
8468 let json = serde_json::to_value(&val).unwrap();
8469 assert_eq!(json, json!({ "type": "boolean", "value": true }));
8470 }
8471
8472 #[test]
8473 fn test_session_config_option_value_deserialize_no_type() {
8474 let json = json!({ "value": "model-1" });
8476 let val: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
8477 assert_eq!(val, SessionConfigOptionValue::value_id("model-1"));
8478 assert_eq!(val.as_value_id().unwrap().to_string(), "model-1");
8479 }
8480
8481 #[test]
8482 fn test_session_config_option_value_deserialize_boolean() {
8483 let json = json!({ "type": "boolean", "value": true });
8484 let val: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
8485 assert_eq!(val, SessionConfigOptionValue::boolean(true));
8486 assert_eq!(val.as_bool(), Some(true));
8487 }
8488
8489 #[test]
8490 fn test_session_config_option_value_deserialize_boolean_false() {
8491 let json = json!({ "type": "boolean", "value": false });
8492 let val: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
8493 assert_eq!(val, SessionConfigOptionValue::boolean(false));
8494 assert_eq!(val.as_bool(), Some(false));
8495 }
8496
8497 #[test]
8498 fn test_session_config_option_value_deserialize_unknown_type_with_string_value() {
8499 let json = json!({ "type": "text", "value": "freeform input" });
8501 let val: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
8502 assert_eq!(val.as_value_id().unwrap().to_string(), "freeform input");
8503 }
8504
8505 #[test]
8506 fn test_session_config_option_value_roundtrip_value_id() {
8507 let original = SessionConfigOptionValue::value_id("option-a");
8508 let json = serde_json::to_value(&original).unwrap();
8509 let roundtripped: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
8510 assert_eq!(original, roundtripped);
8511 }
8512
8513 #[test]
8514 fn test_session_config_option_value_roundtrip_boolean() {
8515 let original = SessionConfigOptionValue::boolean(false);
8516 let json = serde_json::to_value(&original).unwrap();
8517 let roundtripped: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
8518 assert_eq!(original, roundtripped);
8519 }
8520
8521 #[test]
8522 fn test_session_config_option_value_type_mismatch_boolean_with_string() {
8523 let json = json!({ "type": "boolean", "value": "not a bool" });
8525 let result = serde_json::from_value::<SessionConfigOptionValue>(json);
8526 assert!(result.is_ok());
8528 assert_eq!(
8529 result.unwrap().as_value_id().unwrap().to_string(),
8530 "not a bool"
8531 );
8532 }
8533
8534 #[test]
8535 fn test_session_config_option_value_from_impls() {
8536 let from_str: SessionConfigOptionValue = "model-1".into();
8537 assert_eq!(from_str.as_value_id().unwrap().to_string(), "model-1");
8538
8539 let from_id: SessionConfigOptionValue = SessionConfigValueId::new("model-2").into();
8540 assert_eq!(from_id.as_value_id().unwrap().to_string(), "model-2");
8541
8542 let from_bool: SessionConfigOptionValue = true.into();
8543 assert_eq!(from_bool.as_bool(), Some(true));
8544 }
8545
8546 #[test]
8547 fn test_set_session_config_option_request_value_id() {
8548 let req = SetSessionConfigOptionRequest::new("sess_1", "model", "model-1");
8549 let json = serde_json::to_value(&req).unwrap();
8550 assert_eq!(
8551 json,
8552 json!({
8553 "sessionId": "sess_1",
8554 "configId": "model",
8555 "value": "model-1"
8556 })
8557 );
8558 assert!(!json.as_object().unwrap().contains_key("type"));
8560 }
8561
8562 #[test]
8563 fn test_set_session_config_option_request_boolean() {
8564 let req = SetSessionConfigOptionRequest::new("sess_1", "brave_mode", true);
8565 let json = serde_json::to_value(&req).unwrap();
8566 assert_eq!(
8567 json,
8568 json!({
8569 "sessionId": "sess_1",
8570 "configId": "brave_mode",
8571 "type": "boolean",
8572 "value": true
8573 })
8574 );
8575 }
8576
8577 #[test]
8578 fn test_set_session_config_option_request_deserialize_no_type() {
8579 let json = json!({
8581 "sessionId": "sess_1",
8582 "configId": "model",
8583 "value": "model-1"
8584 });
8585 let req: SetSessionConfigOptionRequest = serde_json::from_value(json).unwrap();
8586 assert_eq!(req.session_id.to_string(), "sess_1");
8587 assert_eq!(req.config_id.to_string(), "model");
8588 assert_eq!(req.value.as_value_id().unwrap().to_string(), "model-1");
8589 }
8590
8591 #[test]
8592 fn test_set_session_config_option_request_deserialize_boolean() {
8593 let json = json!({
8594 "sessionId": "sess_1",
8595 "configId": "brave_mode",
8596 "type": "boolean",
8597 "value": true
8598 });
8599 let req: SetSessionConfigOptionRequest = serde_json::from_value(json).unwrap();
8600 assert_eq!(req.value.as_bool(), Some(true));
8601 }
8602
8603 #[test]
8604 fn test_set_session_config_option_request_roundtrip_value_id() {
8605 let original = SetSessionConfigOptionRequest::new("s", "c", "v");
8606 let json = serde_json::to_value(&original).unwrap();
8607 let roundtripped: SetSessionConfigOptionRequest = serde_json::from_value(json).unwrap();
8608 assert_eq!(original, roundtripped);
8609 }
8610
8611 #[test]
8612 fn test_set_session_config_option_request_roundtrip_boolean() {
8613 let original = SetSessionConfigOptionRequest::new("s", "c", false);
8614 let json = serde_json::to_value(&original).unwrap();
8615 let roundtripped: SetSessionConfigOptionRequest = serde_json::from_value(json).unwrap();
8616 assert_eq!(original, roundtripped);
8617 }
8618
8619 #[test]
8620 fn test_session_config_boolean_serialization() {
8621 let cfg = SessionConfigBoolean::new(true);
8622 let json = serde_json::to_value(&cfg).unwrap();
8623 assert_eq!(json, json!({ "currentValue": true }));
8624
8625 let deserialized: SessionConfigBoolean = serde_json::from_value(json).unwrap();
8626 assert!(deserialized.current_value);
8627 }
8628
8629 #[test]
8630 fn test_session_config_option_boolean_variant() {
8631 let opt = SessionConfigOption::boolean("brave_mode", "Brave Mode", false)
8632 .description("Skip confirmation prompts")
8633 .meta(test_meta());
8634 assert_eq!(serialized_meta_key_count(&opt), 1);
8635
8636 let json = serde_json::to_value(&opt).unwrap();
8637 assert_eq!(
8638 json,
8639 json!({
8640 "id": "brave_mode",
8641 "name": "Brave Mode",
8642 "description": "Skip confirmation prompts",
8643 "type": "boolean",
8644 "currentValue": false,
8645 "_meta": {
8646 "source": "test"
8647 }
8648 })
8649 );
8650
8651 let deserialized: SessionConfigOption = serde_json::from_value(json).unwrap();
8652 assert_eq!(deserialized.id.to_string(), "brave_mode");
8653 assert_eq!(deserialized.name, "Brave Mode");
8654 match deserialized.kind {
8655 SessionConfigKind::Boolean(ref b) => assert!(!b.current_value),
8656 _ => panic!("Expected Boolean kind"),
8657 }
8658 }
8659
8660 #[test]
8661 fn test_session_config_option_select_still_works() {
8662 let opt = SessionConfigOption::select(
8664 "model",
8665 "Model",
8666 "model-1",
8667 vec![
8668 SessionConfigSelectOption::new("model-1", "Model 1"),
8669 SessionConfigSelectOption::new("model-2", "Model 2"),
8670 ],
8671 )
8672 .meta(test_meta());
8673 assert_eq!(serialized_meta_key_count(&opt), 1);
8674
8675 let json = serde_json::to_value(&opt).unwrap();
8676 assert_eq!(json["type"], "select");
8677 assert_eq!(json["currentValue"], "model-1");
8678 assert_eq!(json["options"].as_array().unwrap().len(), 2);
8679 assert_eq!(json["_meta"]["source"], "test");
8680
8681 let deserialized: SessionConfigOption = serde_json::from_value(json).unwrap();
8682 match deserialized.kind {
8683 SessionConfigKind::Select(ref s) => {
8684 assert_eq!(s.current_value.to_string(), "model-1");
8685 }
8686 _ => panic!("Expected Select kind"),
8687 }
8688 }
8689
8690 #[cfg(feature = "unstable_llm_providers")]
8691 #[test]
8692 fn test_llm_protocol_known_variants() {
8693 assert_eq!(
8694 serde_json::to_value(&LlmProtocol::Anthropic).unwrap(),
8695 json!("anthropic")
8696 );
8697 assert_eq!(
8698 serde_json::to_value(&LlmProtocol::OpenAi).unwrap(),
8699 json!("openai")
8700 );
8701 assert_eq!(
8702 serde_json::to_value(&LlmProtocol::Azure).unwrap(),
8703 json!("azure")
8704 );
8705 assert_eq!(
8706 serde_json::to_value(&LlmProtocol::Vertex).unwrap(),
8707 json!("vertex")
8708 );
8709 assert_eq!(
8710 serde_json::to_value(&LlmProtocol::Bedrock).unwrap(),
8711 json!("bedrock")
8712 );
8713
8714 assert_eq!(
8715 serde_json::from_str::<LlmProtocol>("\"anthropic\"").unwrap(),
8716 LlmProtocol::Anthropic
8717 );
8718 assert_eq!(
8719 serde_json::from_str::<LlmProtocol>("\"openai\"").unwrap(),
8720 LlmProtocol::OpenAi
8721 );
8722 assert_eq!(
8723 serde_json::from_str::<LlmProtocol>("\"azure\"").unwrap(),
8724 LlmProtocol::Azure
8725 );
8726 assert_eq!(
8727 serde_json::from_str::<LlmProtocol>("\"vertex\"").unwrap(),
8728 LlmProtocol::Vertex
8729 );
8730 assert_eq!(
8731 serde_json::from_str::<LlmProtocol>("\"bedrock\"").unwrap(),
8732 LlmProtocol::Bedrock
8733 );
8734 }
8735
8736 #[cfg(feature = "unstable_llm_providers")]
8737 #[test]
8738 fn test_llm_protocol_unknown_variant() {
8739 let unknown: LlmProtocol = serde_json::from_str("\"cohere\"").unwrap();
8740 assert_eq!(unknown, LlmProtocol::Other("cohere".to_string()));
8741
8742 let json = serde_json::to_value(&unknown).unwrap();
8743 assert_eq!(json, json!("cohere"));
8744 }
8745
8746 #[cfg(feature = "unstable_llm_providers")]
8747 #[test]
8748 fn test_provider_current_config_serialization() {
8749 let config =
8750 ProviderCurrentConfig::new(LlmProtocol::Anthropic, "https://api.anthropic.com");
8751
8752 let json = serde_json::to_value(&config).unwrap();
8753 assert_eq!(
8754 json,
8755 json!({
8756 "apiType": "anthropic",
8757 "baseUrl": "https://api.anthropic.com"
8758 })
8759 );
8760
8761 let deserialized: ProviderCurrentConfig = serde_json::from_value(json).unwrap();
8762 assert_eq!(deserialized.api_type, LlmProtocol::Anthropic);
8763 assert_eq!(deserialized.base_url, "https://api.anthropic.com");
8764 }
8765
8766 #[cfg(feature = "unstable_llm_providers")]
8767 #[test]
8768 fn test_provider_info_with_current_config() {
8769 let info = ProviderInfo::new(
8770 "main",
8771 vec![LlmProtocol::Anthropic, LlmProtocol::OpenAi],
8772 true,
8773 Some(ProviderCurrentConfig::new(
8774 LlmProtocol::Anthropic,
8775 "https://api.anthropic.com",
8776 )),
8777 );
8778
8779 let json = serde_json::to_value(&info).unwrap();
8780 assert_eq!(
8781 json,
8782 json!({
8783 "providerId": "main",
8784 "supported": ["anthropic", "openai"],
8785 "required": true,
8786 "current": {
8787 "apiType": "anthropic",
8788 "baseUrl": "https://api.anthropic.com"
8789 }
8790 })
8791 );
8792
8793 let deserialized: ProviderInfo = serde_json::from_value(json).unwrap();
8794 assert_eq!(deserialized.provider_id.to_string(), "main");
8795 assert_eq!(deserialized.supported.len(), 2);
8796 assert!(deserialized.required);
8797 assert!(deserialized.current.is_some());
8798 assert_eq!(
8799 deserialized.current.as_ref().unwrap().api_type,
8800 LlmProtocol::Anthropic
8801 );
8802 }
8803
8804 #[cfg(feature = "unstable_llm_providers")]
8805 #[test]
8806 fn test_provider_info_disabled() {
8807 let info = ProviderInfo::new(
8808 "secondary",
8809 vec![LlmProtocol::OpenAi],
8810 false,
8811 None::<ProviderCurrentConfig>,
8812 );
8813
8814 let json = serde_json::to_value(&info).unwrap();
8815 assert_eq!(
8816 json,
8817 json!({
8818 "providerId": "secondary",
8819 "supported": ["openai"],
8820 "required": false
8821 })
8822 );
8823
8824 let deserialized: ProviderInfo = serde_json::from_value(json).unwrap();
8825 assert_eq!(deserialized.provider_id.to_string(), "secondary");
8826 assert!(!deserialized.required);
8827 assert!(deserialized.current.is_none());
8828 }
8829
8830 #[cfg(feature = "unstable_llm_providers")]
8831 #[test]
8832 fn test_provider_info_missing_current_defaults_to_none() {
8833 let json = json!({
8835 "providerId": "main",
8836 "supported": ["anthropic"],
8837 "required": true
8838 });
8839 let deserialized: ProviderInfo = serde_json::from_value(json).unwrap();
8840 assert!(deserialized.current.is_none());
8841 }
8842
8843 #[cfg(feature = "unstable_llm_providers")]
8844 #[test]
8845 fn test_provider_info_explicit_null_current_decodes_to_none() {
8846 let json = json!({
8850 "providerId": "main",
8851 "supported": ["anthropic"],
8852 "required": true,
8853 "current": null
8854 });
8855 let deserialized: ProviderInfo = serde_json::from_value(json).unwrap();
8856 assert!(deserialized.current.is_none());
8857 }
8858
8859 #[cfg(feature = "unstable_llm_providers")]
8860 #[test]
8861 fn test_list_providers_response_serialization() {
8862 let response = ListProvidersResponse::new(vec![ProviderInfo::new(
8863 "main",
8864 vec![LlmProtocol::Anthropic],
8865 true,
8866 Some(ProviderCurrentConfig::new(
8867 LlmProtocol::Anthropic,
8868 "https://api.anthropic.com",
8869 )),
8870 )]);
8871
8872 let json = serde_json::to_value(&response).unwrap();
8873 assert_eq!(json["providers"].as_array().unwrap().len(), 1);
8874 assert_eq!(json["providers"][0]["providerId"], "main");
8875
8876 let deserialized: ListProvidersResponse = serde_json::from_value(json).unwrap();
8877 assert_eq!(deserialized.providers.len(), 1);
8878 }
8879
8880 #[cfg(feature = "unstable_llm_providers")]
8881 #[test]
8882 fn test_set_provider_request_serialization() {
8883 use std::collections::HashMap;
8884
8885 let mut headers = HashMap::new();
8886 headers.insert("Authorization".to_string(), "Bearer sk-test".to_string());
8887
8888 let request =
8889 SetProviderRequest::new("main", LlmProtocol::OpenAi, "https://api.openai.com/v1")
8890 .headers(headers);
8891
8892 let json = serde_json::to_value(&request).unwrap();
8893 assert_eq!(
8894 json,
8895 json!({
8896 "providerId": "main",
8897 "apiType": "openai",
8898 "baseUrl": "https://api.openai.com/v1",
8899 "headers": {
8900 "Authorization": "Bearer sk-test"
8901 }
8902 })
8903 );
8904
8905 let deserialized: SetProviderRequest = serde_json::from_value(json).unwrap();
8906 assert_eq!(deserialized.provider_id.to_string(), "main");
8907 assert_eq!(deserialized.api_type, LlmProtocol::OpenAi);
8908 assert_eq!(deserialized.base_url, "https://api.openai.com/v1");
8909 assert_eq!(deserialized.headers.len(), 1);
8910 assert_eq!(
8911 deserialized.headers.get("Authorization").unwrap(),
8912 "Bearer sk-test"
8913 );
8914 }
8915
8916 #[cfg(feature = "unstable_llm_providers")]
8917 #[test]
8918 fn test_set_provider_request_omits_empty_headers() {
8919 let request =
8920 SetProviderRequest::new("main", LlmProtocol::Anthropic, "https://api.anthropic.com");
8921
8922 let json = serde_json::to_value(&request).unwrap();
8923 assert!(!json.as_object().unwrap().contains_key("headers"));
8925 }
8926
8927 #[cfg(feature = "unstable_llm_providers")]
8928 #[test]
8929 fn test_disable_provider_request_serialization() {
8930 let request = DisableProviderRequest::new("secondary");
8931
8932 let json = serde_json::to_value(&request).unwrap();
8933 assert_eq!(json, json!({ "providerId": "secondary" }));
8934
8935 let deserialized: DisableProviderRequest = serde_json::from_value(json).unwrap();
8936 assert_eq!(deserialized.provider_id.to_string(), "secondary");
8937 }
8938
8939 #[cfg(feature = "unstable_llm_providers")]
8940 #[test]
8941 fn test_providers_capabilities_serialization() {
8942 let caps = ProvidersCapabilities::new();
8943
8944 let json = serde_json::to_value(&caps).unwrap();
8945 assert_eq!(json, json!({}));
8946
8947 let deserialized: ProvidersCapabilities = serde_json::from_value(json).unwrap();
8948 assert!(deserialized.meta.is_none());
8949 }
8950
8951 #[cfg(feature = "unstable_llm_providers")]
8952 #[test]
8953 fn test_agent_capabilities_with_providers() {
8954 let caps = AgentCapabilities::new().providers(ProvidersCapabilities::new());
8955
8956 let json = serde_json::to_value(&caps).unwrap();
8957 assert_eq!(json["providers"], json!({}));
8958
8959 let deserialized: AgentCapabilities = serde_json::from_value(json).unwrap();
8960 assert!(deserialized.providers.is_some());
8961 }
8962
8963 #[test]
8964 fn prompt_request_rejects_malformed_content_block() {
8965 use serde_json::json;
8966
8967 assert!(
8968 serde_json::from_value::<PromptRequest>(json!({
8969 "sessionId": "sess-1",
8970 "prompt": [{"type": "text"}]
8971 }))
8972 .is_err()
8973 );
8974 }
8975
8976 #[test]
8977 fn prompt_request_rejects_non_array_prompt() {
8978 use serde_json::json;
8979
8980 assert!(
8981 serde_json::from_value::<PromptRequest>(json!({
8982 "sessionId": "sess-1",
8983 "prompt": "hello"
8984 }))
8985 .is_err()
8986 );
8987 }
8988
8989 fn assert_session_setup_lists_are_strict<T>(base: &serde_json::Value)
8990 where
8991 T: serde::de::DeserializeOwned + PartialEq + std::fmt::Debug,
8992 {
8993 let name = std::any::type_name::<T>();
8994 let with = |field: &str, value: serde_json::Value| {
8995 let mut request = base.clone();
8996 request[field] = value;
8997 serde_json::from_value::<T>(request)
8998 };
8999
9000 for (field, value) in [
9001 (
9003 "mcpServers",
9004 json!([
9005 {"name": "github", "command": "/usr/bin/gh-mcp", "args": [], "env": [{"name": "GITHUB_TOKEN", "value": null}]},
9006 {"name": "fs", "command": "/usr/bin/fs-mcp", "args": [], "env": []}
9007 ]),
9008 ),
9009 ("mcpServers", json!({"name": "fs"})),
9010 ("additionalDirectories", json!(["/repo/lib", 42])),
9011 ("additionalDirectories", json!("/repo/lib")),
9012 ] {
9013 assert!(
9014 with(field, value.clone()).is_err(),
9015 "{name}.{field}: {value}"
9016 );
9017 }
9018
9019 let empty = serde_json::from_value::<T>(base.clone()).unwrap();
9020 for field in ["mcpServers", "additionalDirectories"] {
9021 assert_eq!(
9022 with(field, serde_json::Value::Null).unwrap(),
9023 empty,
9024 "{name}.{field}"
9025 );
9026 }
9027 }
9028
9029 #[test]
9030 fn session_setup_requests_reject_malformed_mcp_servers_and_directories() {
9031 assert_session_setup_lists_are_strict::<NewSessionRequest>(&json!({
9032 "cwd": "/repo",
9033 "mcpServers": []
9034 }));
9035 assert_session_setup_lists_are_strict::<LoadSessionRequest>(&json!({
9036 "sessionId": "sess-1",
9037 "cwd": "/repo",
9038 "mcpServers": []
9039 }));
9040 assert_session_setup_lists_are_strict::<ResumeSessionRequest>(&json!({
9041 "sessionId": "sess-1",
9042 "cwd": "/repo"
9043 }));
9044 #[cfg(feature = "unstable_session_fork")]
9045 assert_session_setup_lists_are_strict::<ForkSessionRequest>(&json!({
9046 "sessionId": "sess-1",
9047 "cwd": "/repo"
9048 }));
9049 }
9050
9051 #[test]
9052 fn mcp_server_lists_treat_null_as_empty() {
9053 let servers: Vec<McpServer> = serde_json::from_value(json!([
9054 {"name": "fs", "command": "/usr/bin/fs-mcp", "args": null, "env": null},
9055 {"type": "http", "name": "api", "url": "https://example.com/mcp", "headers": null},
9056 {"type": "sse", "name": "events", "url": "https://example.com/sse", "headers": null}
9057 ]))
9058 .unwrap();
9059
9060 assert_eq!(
9061 servers,
9062 vec![
9063 McpServer::Stdio(McpServerStdio::new("fs", "/usr/bin/fs-mcp")),
9064 McpServer::Http(McpServerHttp::new("api", "https://example.com/mcp")),
9065 McpServer::Sse(McpServerSse::new("events", "https://example.com/sse")),
9066 ]
9067 );
9068 }
9069
9070 #[test]
9071 fn terminal_auth_methods_reject_malformed_launch_config() {
9072 let response: InitializeResponse = serde_json::from_value(json!({
9076 "protocolVersion": 1,
9077 "authMethods": [
9078 {"type": "terminal", "id": "bad-args", "name": "Log in", "args": ["auth", "--port", 8123]},
9079 {"type": "terminal", "id": "bad-env", "name": "Log in", "env": {"AUTH_MODE": "device", "DEBUG": 1}},
9080 {"type": "terminal", "id": "null-config", "name": "Log in", "args": null, "env": null},
9081 {"id": "agent", "name": "Agent login"}
9082 ]
9083 }))
9084 .unwrap();
9085
9086 assert_eq!(
9087 response.auth_methods,
9088 vec![
9089 AuthMethod::Terminal(AuthMethodTerminal::new("null-config", "Log in")),
9090 AuthMethod::Agent(AuthMethodAgent::new("agent", "Agent login")),
9091 ]
9092 );
9093 assert!(
9094 serde_json::from_value::<AuthMethod>(json!({
9095 "type": "terminal",
9096 "id": "bad-args",
9097 "name": "Log in",
9098 "args": ["auth", 8123]
9099 }))
9100 .is_err()
9101 );
9102 }
9103
9104 #[cfg(feature = "unstable_auth_status")]
9105 #[test]
9106 fn auth_status_response_round_trips() {
9107 let response = AuthStatusResponse::new(AuthState::Authenticated).accounts(vec![
9108 AuthAccount::new("Anthropic API key")
9109 .description("API key helper".to_string())
9110 .active(true),
9111 AuthAccount::new("Claude Max").email("user@example.com".to_string()),
9112 ]);
9113 let json = serde_json::to_value(&response).unwrap();
9114 assert_eq!(
9115 json,
9116 json!({
9117 "state": "authenticated",
9118 "accounts": [
9119 {
9120 "label": "Anthropic API key",
9121 "description": "API key helper",
9122 "active": true
9123 },
9124 {
9125 "label": "Claude Max",
9126 "email": "user@example.com"
9127 }
9128 ]
9129 })
9130 );
9131 assert_eq!(
9132 serde_json::from_value::<AuthStatusResponse>(json).unwrap(),
9133 response
9134 );
9135 assert_eq!(
9136 serde_json::to_value(AuthStatusResponse::new(AuthState::NotRequired)).unwrap(),
9137 json!({"state": "not_required"})
9138 );
9139 }
9140
9141 #[cfg(feature = "unstable_auth_status")]
9142 #[test]
9143 fn auth_status_state_is_strict_and_accounts_are_lenient() {
9144 assert!(serde_json::from_value::<AuthStatusResponse>(json!({})).is_err());
9145 assert!(serde_json::from_value::<AuthStatusResponse>(json!({"state": null})).is_err());
9146 assert!(serde_json::from_value::<AuthStatusResponse>(json!({"state": 1})).is_err());
9147
9148 let response: AuthStatusResponse = serde_json::from_value(json!({
9149 "state": "_vendor_state",
9150 "accounts": [
9151 {"active": true},
9152 {
9153 "label": "Vertex AI",
9154 "description": 42,
9155 "active": "yes",
9156 "email": ["not", "a", "string"]
9157 }
9158 ]
9159 }))
9160 .unwrap();
9161 assert_eq!(
9162 response,
9163 AuthStatusResponse::new(AuthState::Other("_vendor_state".to_string()))
9164 .accounts(vec![AuthAccount::new("Vertex AI")])
9165 );
9166 assert_eq!(
9167 serde_json::from_value::<AuthStatusResponse>(
9168 json!({"state": "unknown", "accounts": null})
9169 )
9170 .unwrap(),
9171 AuthStatusResponse::new(AuthState::Unknown)
9172 );
9173 }
9174
9175 #[cfg(feature = "unstable_auth_status")]
9176 #[test]
9177 fn auth_status_update_notification_routes() {
9178 use crate::v1::{AgentNotification, CLIENT_METHOD_NAMES};
9179
9180 assert_eq!(AGENT_METHOD_NAMES.auth_status, "auth/status");
9181 assert_eq!(CLIENT_METHOD_NAMES.auth_status_update, "auth/status_update");
9182 let notification = AgentNotification::AuthStatusUpdateNotification(
9183 AuthStatusUpdateNotification::new(AuthState::Unauthenticated),
9184 );
9185 assert_eq!(notification.method(), "auth/status_update");
9186 assert_eq!(
9187 serde_json::to_value(¬ification).unwrap(),
9188 json!({"state": "unauthenticated"})
9189 );
9190 }
9191
9192 #[cfg(all(
9193 feature = "unstable_session_fork",
9194 feature = "unstable_session_cursors"
9195 ))]
9196 #[test]
9197 fn fork_session_request_cursor_id_is_optional_and_strict() {
9198 let request = ForkSessionRequest::new("sess_abc123", "/home/user/project")
9199 .cursor_id(CursorId::new("cur_1"));
9200 let wire = json!({
9201 "sessionId": "sess_abc123",
9202 "cursorId": "cur_1",
9203 "cwd": "/home/user/project"
9204 });
9205 assert_eq!(serde_json::to_value(&request).unwrap(), wire);
9206 assert_eq!(
9207 serde_json::from_value::<ForkSessionRequest>(wire).unwrap(),
9208 request
9209 );
9210
9211 for wire in [
9213 json!({ "sessionId": "sess_abc123", "cwd": "/home/user/project" }),
9214 json!({ "sessionId": "sess_abc123", "cwd": "/home/user/project", "cursorId": null }),
9215 ] {
9216 assert_eq!(
9217 serde_json::from_value::<ForkSessionRequest>(wire)
9218 .unwrap()
9219 .cursor_id,
9220 None
9221 );
9222 }
9223
9224 assert!(
9226 serde_json::from_value::<ForkSessionRequest>(json!({
9227 "sessionId": "sess_abc123",
9228 "cwd": "/home/user/project",
9229 "cursorId": 7
9230 }))
9231 .is_err()
9232 );
9233 }
9234}