1use std::{path::PathBuf, sync::Arc};
7
8use std::collections::HashMap;
9
10use derive_more::{Display, From};
11#[cfg(feature = "unstable_llm_providers")]
12use indexmap::IndexMap;
13use serde::{Deserialize, Serialize};
14use serde_with::{DefaultOnError, DefaultOnNull, VecSkipError, serde_as, skip_serializing_none};
15
16use crate::{IntoOption, ProtocolVersion};
17
18#[cfg(all(
19 feature = "unstable_session_fork",
20 feature = "unstable_session_cursors"
21))]
22use super::CursorId;
23
24use super::{
25 ClientCapabilities, ContentBlock, ExtNotification, ExtRequest, ExtResponse, Meta, SessionId,
26};
27
28#[cfg(all(feature = "unstable_auth_status", feature = "schemars"))]
29use super::AUTH_STATUS_UPDATE_NOTIFICATION;
30#[cfg(feature = "unstable_mcp_over_acp")]
31use super::mcp::{MCP_MESSAGE_METHOD_NAME, MessageMcpNotification};
32
33#[serde_as]
41#[skip_serializing_none]
42#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
43#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
44#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = INITIALIZE_METHOD_NAME)))]
45#[serde(rename_all = "camelCase")]
46#[non_exhaustive]
47pub struct InitializeRequest {
48 pub protocol_version: ProtocolVersion,
50 #[serde_as(deserialize_as = "DefaultOnError")]
52 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
53 #[serde(default)]
54 pub client_capabilities: ClientCapabilities,
55 #[serde_as(deserialize_as = "DefaultOnError")]
59 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
60 #[serde(default)]
61 pub client_info: Option<Implementation>,
62 #[serde_as(deserialize_as = "DefaultOnError")]
68 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
69 #[serde(default)]
70 #[serde(rename = "_meta")]
71 pub meta: Option<Meta>,
72}
73
74impl InitializeRequest {
75 #[must_use]
77 pub fn new(protocol_version: ProtocolVersion) -> Self {
78 Self {
79 protocol_version,
80 client_capabilities: ClientCapabilities::default(),
81 client_info: None,
82 meta: None,
83 }
84 }
85
86 #[must_use]
88 pub fn client_capabilities(mut self, client_capabilities: ClientCapabilities) -> Self {
89 self.client_capabilities = client_capabilities;
90 self
91 }
92
93 #[must_use]
95 pub fn client_info(mut self, client_info: impl IntoOption<Implementation>) -> Self {
96 self.client_info = client_info.into_option();
97 self
98 }
99
100 #[must_use]
106 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
107 self.meta = meta.into_option();
108 self
109 }
110}
111
112#[serde_as]
118#[skip_serializing_none]
119#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
120#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
121#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = INITIALIZE_METHOD_NAME)))]
122#[serde(rename_all = "camelCase")]
123#[non_exhaustive]
124pub struct InitializeResponse {
125 pub protocol_version: ProtocolVersion,
130 #[serde_as(deserialize_as = "DefaultOnError")]
132 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
133 #[serde(default)]
134 pub agent_capabilities: AgentCapabilities,
135 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
137 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
138 #[serde(default)]
139 pub auth_methods: Vec<AuthMethod>,
140 #[serde_as(deserialize_as = "DefaultOnError")]
144 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
145 #[serde(default)]
146 pub agent_info: Option<Implementation>,
147 #[serde_as(deserialize_as = "DefaultOnError")]
153 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
154 #[serde(default)]
155 #[serde(rename = "_meta")]
156 pub meta: Option<Meta>,
157}
158
159impl InitializeResponse {
160 #[must_use]
162 pub fn new(protocol_version: ProtocolVersion) -> Self {
163 Self {
164 protocol_version,
165 agent_capabilities: AgentCapabilities::default(),
166 auth_methods: vec![],
167 agent_info: None,
168 meta: None,
169 }
170 }
171
172 #[must_use]
174 pub fn agent_capabilities(mut self, agent_capabilities: AgentCapabilities) -> Self {
175 self.agent_capabilities = agent_capabilities;
176 self
177 }
178
179 #[must_use]
181 pub fn auth_methods(mut self, auth_methods: Vec<AuthMethod>) -> Self {
182 self.auth_methods = auth_methods;
183 self
184 }
185
186 #[must_use]
188 pub fn agent_info(mut self, agent_info: impl IntoOption<Implementation>) -> Self {
189 self.agent_info = agent_info.into_option();
190 self
191 }
192
193 #[must_use]
199 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
200 self.meta = meta.into_option();
201 self
202 }
203}
204
205#[serde_as]
209#[skip_serializing_none]
210#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
211#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
212#[serde(rename_all = "camelCase")]
213#[non_exhaustive]
214pub struct Implementation {
215 pub name: String,
218 #[serde_as(deserialize_as = "DefaultOnError")]
223 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
224 #[serde(default)]
225 pub title: Option<String>,
226 pub version: String,
229 #[serde_as(deserialize_as = "DefaultOnError")]
235 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
236 #[serde(default)]
237 #[serde(rename = "_meta")]
238 pub meta: Option<Meta>,
239}
240
241impl Implementation {
242 #[must_use]
244 pub fn new(name: impl Into<String>, version: impl Into<String>) -> Self {
245 Self {
246 name: name.into(),
247 title: None,
248 version: version.into(),
249 meta: None,
250 }
251 }
252
253 #[must_use]
258 pub fn title(mut self, title: impl IntoOption<String>) -> Self {
259 self.title = title.into_option();
260 self
261 }
262
263 #[must_use]
269 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
270 self.meta = meta.into_option();
271 self
272 }
273}
274
275#[serde_as]
281#[skip_serializing_none]
282#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
283#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
284#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = AUTHENTICATE_METHOD_NAME)))]
285#[serde(rename_all = "camelCase")]
286#[non_exhaustive]
287pub struct AuthenticateRequest {
288 pub method_id: AuthMethodId,
291 #[serde_as(deserialize_as = "DefaultOnError")]
297 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
298 #[serde(default)]
299 #[serde(rename = "_meta")]
300 pub meta: Option<Meta>,
301}
302
303impl AuthenticateRequest {
304 #[must_use]
306 pub fn new(method_id: impl Into<AuthMethodId>) -> Self {
307 Self {
308 method_id: method_id.into(),
309 meta: None,
310 }
311 }
312
313 #[must_use]
319 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
320 self.meta = meta.into_option();
321 self
322 }
323}
324
325crate::serde_util::default_on_null! {
326 #[serde_as]
328 #[skip_serializing_none]
329 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
330 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
331 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = AUTHENTICATE_METHOD_NAME)))]
332 #[serde(rename_all = "camelCase")]
333 #[non_exhaustive]
334 pub struct AuthenticateResponse {
335 #[serde_as(deserialize_as = "DefaultOnError")]
341 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
342 #[serde(default)]
343 #[serde(rename = "_meta")]
344 pub meta: Option<Meta>,
345 }
346}
347
348impl AuthenticateResponse {
349 #[must_use]
351 pub fn new() -> Self {
352 Self::default()
353 }
354
355 #[must_use]
361 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
362 self.meta = meta.into_option();
363 self
364 }
365}
366
367crate::serde_util::default_on_null! {
370 #[serde_as]
374 #[skip_serializing_none]
375 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
376 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
377 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = LOGOUT_METHOD_NAME)))]
378 #[serde(rename_all = "camelCase")]
379 #[non_exhaustive]
380 pub struct LogoutRequest {
381 #[serde_as(deserialize_as = "DefaultOnError")]
387 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
388 #[serde(default)]
389 #[serde(rename = "_meta")]
390 pub meta: Option<Meta>,
391 }
392}
393
394impl LogoutRequest {
395 #[must_use]
397 pub fn new() -> Self {
398 Self::default()
399 }
400
401 #[must_use]
407 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
408 self.meta = meta.into_option();
409 self
410 }
411}
412
413crate::serde_util::default_on_null! {
414 #[serde_as]
416 #[skip_serializing_none]
417 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
418 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
419 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = LOGOUT_METHOD_NAME)))]
420 #[serde(rename_all = "camelCase")]
421 #[non_exhaustive]
422 pub struct LogoutResponse {
423 #[serde_as(deserialize_as = "DefaultOnError")]
429 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
430 #[serde(default)]
431 #[serde(rename = "_meta")]
432 pub meta: Option<Meta>,
433 }
434}
435
436impl LogoutResponse {
437 #[must_use]
439 pub fn new() -> Self {
440 Self::default()
441 }
442
443 #[must_use]
449 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
450 self.meta = meta.into_option();
451 self
452 }
453}
454
455#[cfg(feature = "unstable_auth_status")]
458crate::serde_util::default_on_null! {
459 #[serde_as]
470 #[skip_serializing_none]
471 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
472 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
473 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = AUTH_STATUS_METHOD_NAME)))]
474 #[serde(rename_all = "camelCase")]
475 #[non_exhaustive]
476 pub struct AuthStatusRequest {
477 #[serde_as(deserialize_as = "DefaultOnError")]
483 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
484 #[serde(default)]
485 #[serde(rename = "_meta")]
486 pub meta: Option<Meta>,
487 }
488}
489
490#[cfg(feature = "unstable_auth_status")]
491impl AuthStatusRequest {
492 #[must_use]
494 pub fn new() -> Self {
495 Self::default()
496 }
497
498 #[must_use]
504 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
505 self.meta = meta.into_option();
506 self
507 }
508}
509
510#[cfg(feature = "unstable_auth_status")]
516#[serde_as]
517#[skip_serializing_none]
518#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
519#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
520#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = AUTH_STATUS_METHOD_NAME)))]
521#[serde(rename_all = "camelCase")]
522#[non_exhaustive]
523pub struct AuthStatusResponse {
524 pub state: AuthState,
529 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
535 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
536 #[serde(default, skip_serializing_if = "Vec::is_empty")]
537 pub accounts: Vec<AuthAccount>,
538 #[serde_as(deserialize_as = "DefaultOnError")]
544 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
545 #[serde(default)]
546 #[serde(rename = "_meta")]
547 pub meta: Option<Meta>,
548}
549
550#[cfg(feature = "unstable_auth_status")]
551impl AuthStatusResponse {
552 #[must_use]
554 pub fn new(state: AuthState) -> Self {
555 Self {
556 state,
557 accounts: vec![],
558 meta: None,
559 }
560 }
561
562 #[must_use]
564 pub fn accounts(mut self, accounts: Vec<AuthAccount>) -> Self {
565 self.accounts = accounts;
566 self
567 }
568
569 #[must_use]
575 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
576 self.meta = meta.into_option();
577 self
578 }
579}
580
581#[cfg(feature = "unstable_auth_status")]
591#[serde_as]
592#[skip_serializing_none]
593#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
594#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
595#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "client", "x-method" = AUTH_STATUS_UPDATE_NOTIFICATION)))]
596#[serde(rename_all = "camelCase")]
597#[non_exhaustive]
598pub struct AuthStatusUpdateNotification {
599 pub state: AuthState,
604 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
610 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
611 #[serde(default, skip_serializing_if = "Vec::is_empty")]
612 pub accounts: Vec<AuthAccount>,
613 #[serde_as(deserialize_as = "DefaultOnError")]
619 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
620 #[serde(default)]
621 #[serde(rename = "_meta")]
622 pub meta: Option<Meta>,
623}
624
625#[cfg(feature = "unstable_auth_status")]
626impl AuthStatusUpdateNotification {
627 #[must_use]
629 pub fn new(state: AuthState) -> Self {
630 Self {
631 state,
632 accounts: vec![],
633 meta: None,
634 }
635 }
636
637 #[must_use]
639 pub fn accounts(mut self, accounts: Vec<AuthAccount>) -> Self {
640 self.accounts = accounts;
641 self
642 }
643
644 #[must_use]
650 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
651 self.meta = meta.into_option();
652 self
653 }
654}
655
656#[cfg(feature = "unstable_auth_status")]
662#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
663#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
664#[serde(rename_all = "snake_case")]
665#[non_exhaustive]
666pub enum AuthState {
667 Authenticated,
669 Unauthenticated,
672 NotRequired,
674 Unknown,
676 #[serde(untagged)]
682 Other(String),
683}
684
685#[cfg(feature = "unstable_auth_status")]
696#[serde_as]
697#[skip_serializing_none]
698#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
699#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
700#[serde(rename_all = "camelCase")]
701#[non_exhaustive]
702pub struct AuthAccount {
703 pub label: String,
706 #[serde_as(deserialize_as = "DefaultOnError")]
711 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
712 #[serde(default)]
713 pub description: Option<String>,
714 #[serde_as(deserialize_as = "DefaultOnError")]
720 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
721 #[serde(default)]
722 pub active: Option<bool>,
723 #[serde_as(deserialize_as = "DefaultOnError")]
727 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
728 #[serde(default)]
729 pub name: Option<String>,
730 #[serde_as(deserialize_as = "DefaultOnError")]
734 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
735 #[serde(default)]
736 pub email: Option<String>,
737 #[serde_as(deserialize_as = "DefaultOnError")]
741 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
742 #[serde(default)]
743 pub organization: Option<String>,
744 #[serde_as(deserialize_as = "DefaultOnError")]
750 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
751 #[serde(default)]
752 #[serde(rename = "_meta")]
753 pub meta: Option<Meta>,
754}
755
756#[cfg(feature = "unstable_auth_status")]
757impl AuthAccount {
758 #[must_use]
760 pub fn new(label: impl Into<String>) -> Self {
761 Self {
762 label: label.into(),
763 description: None,
764 active: None,
765 name: None,
766 email: None,
767 organization: None,
768 meta: None,
769 }
770 }
771
772 #[must_use]
774 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
775 self.description = description.into_option();
776 self
777 }
778
779 #[must_use]
781 pub fn active(mut self, active: impl IntoOption<bool>) -> Self {
782 self.active = active.into_option();
783 self
784 }
785
786 #[must_use]
788 pub fn name(mut self, name: impl IntoOption<String>) -> Self {
789 self.name = name.into_option();
790 self
791 }
792
793 #[must_use]
795 pub fn email(mut self, email: impl IntoOption<String>) -> Self {
796 self.email = email.into_option();
797 self
798 }
799
800 #[must_use]
802 pub fn organization(mut self, organization: impl IntoOption<String>) -> Self {
803 self.organization = organization.into_option();
804 self
805 }
806
807 #[must_use]
813 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
814 self.meta = meta.into_option();
815 self
816 }
817}
818
819#[cfg(feature = "unstable_auth_status")]
827#[serde_as]
828#[skip_serializing_none]
829#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
830#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
831#[non_exhaustive]
832pub struct AuthStatusCapabilities {
833 #[serde_as(deserialize_as = "DefaultOnError")]
839 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
840 #[serde(default)]
841 #[serde(rename = "_meta")]
842 pub meta: Option<Meta>,
843}
844
845#[cfg(feature = "unstable_auth_status")]
846impl AuthStatusCapabilities {
847 #[must_use]
849 pub fn new() -> Self {
850 Self::default()
851 }
852
853 #[must_use]
859 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
860 self.meta = meta.into_option();
861 self
862 }
863}
864
865#[serde_as]
867#[skip_serializing_none]
868#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
869#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
870#[serde(rename_all = "camelCase")]
871#[non_exhaustive]
872pub struct AgentAuthCapabilities {
873 #[cfg(feature = "unstable_auth_status")]
882 #[serde_as(deserialize_as = "DefaultOnError")]
883 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
884 #[serde(default)]
885 pub status: Option<AuthStatusCapabilities>,
886 #[serde_as(deserialize_as = "DefaultOnError")]
891 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
892 #[serde(default)]
893 pub logout: Option<LogoutCapabilities>,
894 #[serde_as(deserialize_as = "DefaultOnError")]
900 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
901 #[serde(default)]
902 #[serde(rename = "_meta")]
903 pub meta: Option<Meta>,
904}
905
906impl AgentAuthCapabilities {
907 #[must_use]
909 pub fn new() -> Self {
910 Self::default()
911 }
912
913 #[cfg(feature = "unstable_auth_status")]
919 #[must_use]
920 pub fn status(mut self, status: impl IntoOption<AuthStatusCapabilities>) -> Self {
921 self.status = status.into_option();
922 self
923 }
924
925 #[must_use]
927 pub fn logout(mut self, logout: impl IntoOption<LogoutCapabilities>) -> Self {
928 self.logout = logout.into_option();
929 self
930 }
931
932 #[must_use]
938 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
939 self.meta = meta.into_option();
940 self
941 }
942}
943
944#[serde_as]
948#[skip_serializing_none]
949#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
950#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
951#[non_exhaustive]
952pub struct LogoutCapabilities {
953 #[serde_as(deserialize_as = "DefaultOnError")]
959 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
960 #[serde(default)]
961 #[serde(rename = "_meta")]
962 pub meta: Option<Meta>,
963}
964
965impl LogoutCapabilities {
966 #[must_use]
968 pub fn new() -> Self {
969 Self::default()
970 }
971
972 #[must_use]
978 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
979 self.meta = meta.into_option();
980 self
981 }
982}
983
984#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
986#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Display, From)]
987#[serde(transparent)]
988#[from(Arc<str>, String, &'static str)]
989#[non_exhaustive]
990pub struct AuthMethodId(pub Arc<str>);
991
992impl AuthMethodId {
993 #[must_use]
995 pub fn new(id: impl Into<Arc<str>>) -> Self {
996 Self(id.into())
997 }
998}
999
1000#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1005#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1006#[serde(tag = "type", rename_all = "snake_case")]
1007#[non_exhaustive]
1008pub enum AuthMethod {
1009 Terminal(AuthMethodTerminal),
1012 #[serde(untagged, deserialize_with = "deserialize_agent_auth_method_fallback")]
1016 Agent(AuthMethodAgent),
1017}
1018
1019fn deserialize_agent_auth_method_fallback<'de, D>(
1024 deserializer: D,
1025) -> Result<AuthMethodAgent, D::Error>
1026where
1027 D: serde::Deserializer<'de>,
1028{
1029 let value = serde_json::Value::deserialize(deserializer)?;
1030 if value.get("type").and_then(serde_json::Value::as_str) == Some("terminal") {
1031 return Err(serde::de::Error::custom(
1032 "known authentication method `terminal` did not match its schema",
1033 ));
1034 }
1035 AuthMethodAgent::deserialize(value).map_err(serde::de::Error::custom)
1036}
1037
1038impl AuthMethod {
1039 #[must_use]
1041 pub fn id(&self) -> &AuthMethodId {
1042 match self {
1043 Self::Agent(a) => &a.id,
1044 Self::Terminal(t) => &t.id,
1045 }
1046 }
1047
1048 #[must_use]
1050 pub fn name(&self) -> &str {
1051 match self {
1052 Self::Agent(a) => &a.name,
1053 Self::Terminal(t) => &t.name,
1054 }
1055 }
1056
1057 #[must_use]
1059 pub fn description(&self) -> Option<&str> {
1060 match self {
1061 Self::Agent(a) => a.description.as_deref(),
1062 Self::Terminal(t) => t.description.as_deref(),
1063 }
1064 }
1065
1066 #[must_use]
1072 pub fn meta(&self) -> Option<&Meta> {
1073 match self {
1074 Self::Agent(a) => a.meta.as_ref(),
1075 Self::Terminal(t) => t.meta.as_ref(),
1076 }
1077 }
1078}
1079
1080#[serde_as]
1084#[skip_serializing_none]
1085#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1086#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1087#[serde(rename_all = "camelCase")]
1088#[non_exhaustive]
1089pub struct AuthMethodAgent {
1090 pub id: AuthMethodId,
1092 pub name: String,
1094 #[serde_as(deserialize_as = "DefaultOnError")]
1096 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1097 #[serde(default)]
1098 pub description: Option<String>,
1099 #[serde_as(deserialize_as = "DefaultOnError")]
1105 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1106 #[serde(default)]
1107 #[serde(rename = "_meta")]
1108 pub meta: Option<Meta>,
1109}
1110
1111impl AuthMethodAgent {
1112 #[must_use]
1114 pub fn new(id: impl Into<AuthMethodId>, name: impl Into<String>) -> Self {
1115 Self {
1116 id: id.into(),
1117 name: name.into(),
1118 description: None,
1119 meta: None,
1120 }
1121 }
1122
1123 #[must_use]
1125 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
1126 self.description = description.into_option();
1127 self
1128 }
1129
1130 #[must_use]
1136 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1137 self.meta = meta.into_option();
1138 self
1139 }
1140}
1141
1142#[serde_as]
1150#[skip_serializing_none]
1151#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1152#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1153#[serde(rename_all = "camelCase")]
1154#[non_exhaustive]
1155pub struct AuthMethodTerminal {
1156 pub id: AuthMethodId,
1158 pub name: String,
1160 #[serde_as(deserialize_as = "DefaultOnError")]
1162 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1163 #[serde(default)]
1164 pub description: Option<String>,
1165 #[serde_as(deserialize_as = "DefaultOnNull")]
1167 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1168 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1169 pub args: Vec<String>,
1170 #[serde_as(deserialize_as = "DefaultOnNull")]
1173 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1174 #[serde(default, skip_serializing_if = "HashMap::is_empty")]
1175 pub env: HashMap<String, String>,
1177 #[serde_as(deserialize_as = "DefaultOnError")]
1183 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1184 #[serde(default)]
1185 #[serde(rename = "_meta")]
1186 pub meta: Option<Meta>,
1187}
1188
1189impl AuthMethodTerminal {
1190 #[must_use]
1192 pub fn new(id: impl Into<AuthMethodId>, name: impl Into<String>) -> Self {
1193 Self {
1194 id: id.into(),
1195 name: name.into(),
1196 description: None,
1197 args: Vec::new(),
1198 env: HashMap::new(),
1199 meta: None,
1200 }
1201 }
1202
1203 #[must_use]
1205 pub fn args(mut self, args: Vec<String>) -> Self {
1206 self.args = args;
1207 self
1208 }
1209
1210 #[must_use]
1213 pub fn env(mut self, env: HashMap<String, String>) -> Self {
1214 self.env = env;
1215 self
1216 }
1217
1218 #[must_use]
1220 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
1221 self.description = description.into_option();
1222 self
1223 }
1224
1225 #[must_use]
1231 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1232 self.meta = meta.into_option();
1233 self
1234 }
1235}
1236
1237#[serde_as]
1243#[skip_serializing_none]
1244#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1245#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1246#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_NEW_METHOD_NAME)))]
1247#[serde(rename_all = "camelCase")]
1248#[non_exhaustive]
1249pub struct NewSessionRequest {
1250 pub cwd: PathBuf,
1252 #[serde_as(deserialize_as = "DefaultOnNull")]
1258 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1259 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1260 pub additional_directories: Vec<PathBuf>,
1261 #[serde_as(deserialize_as = "DefaultOnNull")]
1263 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1264 pub mcp_servers: Vec<McpServer>,
1265 #[serde(default)]
1271 pub system_prompt: Option<SystemPrompt>,
1272 #[cfg(feature = "unstable_session_options")]
1290 #[serde_as(deserialize_as = "DefaultOnNull")]
1291 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1292 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1293 pub config_options: Vec<InitialSessionConfigOption>,
1294 #[serde_as(deserialize_as = "DefaultOnError")]
1300 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1301 #[serde(default)]
1302 #[serde(rename = "_meta")]
1303 pub meta: Option<Meta>,
1304}
1305
1306impl NewSessionRequest {
1307 #[must_use]
1309 pub fn new(cwd: impl Into<PathBuf>) -> Self {
1310 Self {
1311 cwd: cwd.into(),
1312 additional_directories: vec![],
1313 mcp_servers: vec![],
1314 system_prompt: None,
1315 #[cfg(feature = "unstable_session_options")]
1316 config_options: vec![],
1317 meta: None,
1318 }
1319 }
1320
1321 #[must_use]
1323 pub fn additional_directories(mut self, additional_directories: Vec<PathBuf>) -> Self {
1324 self.additional_directories = additional_directories;
1325 self
1326 }
1327
1328 #[must_use]
1330 pub fn mcp_servers(mut self, mcp_servers: Vec<McpServer>) -> Self {
1331 self.mcp_servers = mcp_servers;
1332 self
1333 }
1334
1335 #[must_use]
1337 pub fn system_prompt(mut self, system_prompt: impl IntoOption<SystemPrompt>) -> Self {
1338 self.system_prompt = system_prompt.into_option();
1339 self
1340 }
1341
1342 #[cfg(feature = "unstable_session_options")]
1360 #[must_use]
1361 pub fn config_options(mut self, config_options: Vec<InitialSessionConfigOption>) -> Self {
1362 self.config_options = config_options;
1363 self
1364 }
1365
1366 #[must_use]
1372 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1373 self.meta = meta.into_option();
1374 self
1375 }
1376}
1377
1378#[serde_as]
1382#[skip_serializing_none]
1383#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1384#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1385#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_NEW_METHOD_NAME)))]
1386#[serde(rename_all = "camelCase")]
1387#[non_exhaustive]
1388pub struct NewSessionResponse {
1389 pub session_id: SessionId,
1393 #[serde_as(deserialize_as = "DefaultOnError")]
1397 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1398 #[serde(default)]
1399 pub modes: Option<SessionModeState>,
1400 #[serde_as(deserialize_as = "DefaultOnError<Option<VecSkipError<_>>>")]
1402 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
1403 #[serde(default)]
1404 pub config_options: Option<Vec<SessionConfigOption>>,
1405 #[serde_as(deserialize_as = "DefaultOnError")]
1411 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1412 #[serde(default)]
1413 #[serde(rename = "_meta")]
1414 pub meta: Option<Meta>,
1415}
1416
1417impl NewSessionResponse {
1418 #[must_use]
1420 pub fn new(session_id: impl Into<SessionId>) -> Self {
1421 Self {
1422 session_id: session_id.into(),
1423 modes: None,
1424 config_options: None,
1425 meta: None,
1426 }
1427 }
1428
1429 #[must_use]
1433 pub fn modes(mut self, modes: impl IntoOption<SessionModeState>) -> Self {
1434 self.modes = modes.into_option();
1435 self
1436 }
1437
1438 #[must_use]
1440 pub fn config_options(
1441 mut self,
1442 config_options: impl IntoOption<Vec<SessionConfigOption>>,
1443 ) -> Self {
1444 self.config_options = config_options.into_option();
1445 self
1446 }
1447
1448 #[must_use]
1454 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1455 self.meta = meta.into_option();
1456 self
1457 }
1458}
1459
1460#[serde_as]
1468#[skip_serializing_none]
1469#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1470#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1471#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_LOAD_METHOD_NAME)))]
1472#[serde(rename_all = "camelCase")]
1473#[non_exhaustive]
1474pub struct LoadSessionRequest {
1475 #[serde_as(deserialize_as = "DefaultOnNull")]
1477 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1478 pub mcp_servers: Vec<McpServer>,
1479 pub cwd: PathBuf,
1481 #[serde_as(deserialize_as = "DefaultOnNull")]
1488 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1489 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1490 pub additional_directories: Vec<PathBuf>,
1491 pub session_id: SessionId,
1493 #[serde(default)]
1501 pub system_prompt: Option<SystemPrompt>,
1502 #[cfg(feature = "unstable_session_options")]
1518 #[serde_as(deserialize_as = "DefaultOnNull")]
1519 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1520 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1521 pub config_options: Vec<InitialSessionConfigOption>,
1522 #[serde_as(deserialize_as = "DefaultOnError")]
1528 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1529 #[serde(default)]
1530 #[serde(rename = "_meta")]
1531 pub meta: Option<Meta>,
1532}
1533
1534impl LoadSessionRequest {
1535 #[must_use]
1537 pub fn new(session_id: impl Into<SessionId>, cwd: impl Into<PathBuf>) -> Self {
1538 Self {
1539 mcp_servers: vec![],
1540 cwd: cwd.into(),
1541 additional_directories: vec![],
1542 session_id: session_id.into(),
1543 system_prompt: None,
1544 #[cfg(feature = "unstable_session_options")]
1545 config_options: vec![],
1546 meta: None,
1547 }
1548 }
1549
1550 #[must_use]
1552 pub fn additional_directories(mut self, additional_directories: Vec<PathBuf>) -> Self {
1553 self.additional_directories = additional_directories;
1554 self
1555 }
1556
1557 #[must_use]
1559 pub fn mcp_servers(mut self, mcp_servers: Vec<McpServer>) -> Self {
1560 self.mcp_servers = mcp_servers;
1561 self
1562 }
1563
1564 #[must_use]
1566 pub fn system_prompt(mut self, system_prompt: impl IntoOption<SystemPrompt>) -> Self {
1567 self.system_prompt = system_prompt.into_option();
1568 self
1569 }
1570
1571 #[cfg(feature = "unstable_session_options")]
1587 #[must_use]
1588 pub fn config_options(mut self, config_options: Vec<InitialSessionConfigOption>) -> Self {
1589 self.config_options = config_options;
1590 self
1591 }
1592
1593 #[must_use]
1599 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1600 self.meta = meta.into_option();
1601 self
1602 }
1603}
1604
1605crate::serde_util::default_on_null! {
1606 #[serde_as]
1608 #[skip_serializing_none]
1609 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1610 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
1611 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_LOAD_METHOD_NAME)))]
1612 #[serde(rename_all = "camelCase")]
1613 #[non_exhaustive]
1614 pub struct LoadSessionResponse {
1615 #[serde_as(deserialize_as = "DefaultOnError")]
1619 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1620 #[serde(default)]
1621 pub modes: Option<SessionModeState>,
1622 #[serde_as(deserialize_as = "DefaultOnError<Option<VecSkipError<_>>>")]
1624 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
1625 #[serde(default)]
1626 pub config_options: Option<Vec<SessionConfigOption>>,
1627 #[serde_as(deserialize_as = "DefaultOnError")]
1633 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1634 #[serde(default)]
1635 #[serde(rename = "_meta")]
1636 pub meta: Option<Meta>,
1637 }
1638}
1639
1640impl LoadSessionResponse {
1641 #[must_use]
1643 pub fn new() -> Self {
1644 Self::default()
1645 }
1646
1647 #[must_use]
1651 pub fn modes(mut self, modes: impl IntoOption<SessionModeState>) -> Self {
1652 self.modes = modes.into_option();
1653 self
1654 }
1655
1656 #[must_use]
1658 pub fn config_options(
1659 mut self,
1660 config_options: impl IntoOption<Vec<SessionConfigOption>>,
1661 ) -> Self {
1662 self.config_options = config_options.into_option();
1663 self
1664 }
1665
1666 #[must_use]
1672 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1673 self.meta = meta.into_option();
1674 self
1675 }
1676}
1677
1678#[cfg(feature = "unstable_session_fork")]
1691#[serde_as]
1692#[skip_serializing_none]
1693#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1694#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1695#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_FORK_METHOD_NAME)))]
1696#[serde(rename_all = "camelCase")]
1697#[non_exhaustive]
1698pub struct ForkSessionRequest {
1699 pub session_id: SessionId,
1701 #[cfg(feature = "unstable_session_cursors")]
1714 #[serde(default)]
1715 pub cursor_id: Option<CursorId>,
1716 pub cwd: PathBuf,
1718 #[serde_as(deserialize_as = "DefaultOnNull")]
1724 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1725 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1726 pub additional_directories: Vec<PathBuf>,
1727 #[serde_as(deserialize_as = "DefaultOnNull")]
1729 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1730 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1731 pub mcp_servers: Vec<McpServer>,
1732 #[serde(default)]
1740 pub system_prompt: Option<SystemPrompt>,
1741 #[cfg(feature = "unstable_session_options")]
1760 #[serde_as(deserialize_as = "DefaultOnNull")]
1761 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1762 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1763 pub config_options: Vec<InitialSessionConfigOption>,
1764 #[serde_as(deserialize_as = "DefaultOnError")]
1770 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1771 #[serde(default)]
1772 #[serde(rename = "_meta")]
1773 pub meta: Option<Meta>,
1774}
1775
1776#[cfg(feature = "unstable_session_fork")]
1777impl ForkSessionRequest {
1778 #[must_use]
1780 pub fn new(session_id: impl Into<SessionId>, cwd: impl Into<PathBuf>) -> Self {
1781 Self {
1782 session_id: session_id.into(),
1783 #[cfg(feature = "unstable_session_cursors")]
1784 cursor_id: None,
1785 cwd: cwd.into(),
1786 additional_directories: vec![],
1787 mcp_servers: vec![],
1788 system_prompt: None,
1789 #[cfg(feature = "unstable_session_options")]
1790 config_options: vec![],
1791 meta: None,
1792 }
1793 }
1794
1795 #[cfg(feature = "unstable_session_cursors")]
1804 #[must_use]
1805 pub fn cursor_id(mut self, cursor_id: impl IntoOption<CursorId>) -> Self {
1806 self.cursor_id = cursor_id.into_option();
1807 self
1808 }
1809
1810 #[must_use]
1812 pub fn additional_directories(mut self, additional_directories: Vec<PathBuf>) -> Self {
1813 self.additional_directories = additional_directories;
1814 self
1815 }
1816
1817 #[must_use]
1819 pub fn mcp_servers(mut self, mcp_servers: Vec<McpServer>) -> Self {
1820 self.mcp_servers = mcp_servers;
1821 self
1822 }
1823
1824 #[must_use]
1826 pub fn system_prompt(mut self, system_prompt: impl IntoOption<SystemPrompt>) -> Self {
1827 self.system_prompt = system_prompt.into_option();
1828 self
1829 }
1830
1831 #[cfg(feature = "unstable_session_options")]
1850 #[must_use]
1851 pub fn config_options(mut self, config_options: Vec<InitialSessionConfigOption>) -> Self {
1852 self.config_options = config_options;
1853 self
1854 }
1855
1856 #[must_use]
1862 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1863 self.meta = meta.into_option();
1864 self
1865 }
1866}
1867
1868#[cfg(feature = "unstable_session_fork")]
1874#[serde_as]
1875#[skip_serializing_none]
1876#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1877#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1878#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_FORK_METHOD_NAME)))]
1879#[serde(rename_all = "camelCase")]
1880#[non_exhaustive]
1881pub struct ForkSessionResponse {
1882 pub session_id: SessionId,
1884 #[serde_as(deserialize_as = "DefaultOnError")]
1888 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1889 #[serde(default)]
1890 pub modes: Option<SessionModeState>,
1891 #[serde_as(deserialize_as = "DefaultOnError<Option<VecSkipError<_>>>")]
1893 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
1894 #[serde(default)]
1895 pub config_options: Option<Vec<SessionConfigOption>>,
1896 #[serde_as(deserialize_as = "DefaultOnError")]
1902 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1903 #[serde(default)]
1904 #[serde(rename = "_meta")]
1905 pub meta: Option<Meta>,
1906}
1907
1908#[cfg(feature = "unstable_session_fork")]
1909impl ForkSessionResponse {
1910 #[must_use]
1912 pub fn new(session_id: impl Into<SessionId>) -> Self {
1913 Self {
1914 session_id: session_id.into(),
1915 modes: None,
1916 config_options: None,
1917 meta: None,
1918 }
1919 }
1920
1921 #[must_use]
1925 pub fn modes(mut self, modes: impl IntoOption<SessionModeState>) -> Self {
1926 self.modes = modes.into_option();
1927 self
1928 }
1929
1930 #[must_use]
1932 pub fn config_options(
1933 mut self,
1934 config_options: impl IntoOption<Vec<SessionConfigOption>>,
1935 ) -> Self {
1936 self.config_options = config_options.into_option();
1937 self
1938 }
1939
1940 #[must_use]
1946 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1947 self.meta = meta.into_option();
1948 self
1949 }
1950}
1951
1952#[serde_as]
1961#[skip_serializing_none]
1962#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1963#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1964#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_RESUME_METHOD_NAME)))]
1965#[serde(rename_all = "camelCase")]
1966#[non_exhaustive]
1967pub struct ResumeSessionRequest {
1968 pub session_id: SessionId,
1970 pub cwd: PathBuf,
1972 #[serde_as(deserialize_as = "DefaultOnNull")]
1979 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1980 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1981 pub additional_directories: Vec<PathBuf>,
1982 #[serde_as(deserialize_as = "DefaultOnNull")]
1984 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1985 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1986 pub mcp_servers: Vec<McpServer>,
1987 #[serde(default)]
1995 pub system_prompt: Option<SystemPrompt>,
1996 #[cfg(feature = "unstable_session_options")]
2012 #[serde_as(deserialize_as = "DefaultOnNull")]
2013 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
2014 #[serde(default, skip_serializing_if = "Vec::is_empty")]
2015 pub config_options: Vec<InitialSessionConfigOption>,
2016 #[serde_as(deserialize_as = "DefaultOnError")]
2022 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2023 #[serde(default)]
2024 #[serde(rename = "_meta")]
2025 pub meta: Option<Meta>,
2026}
2027
2028impl ResumeSessionRequest {
2029 #[must_use]
2031 pub fn new(session_id: impl Into<SessionId>, cwd: impl Into<PathBuf>) -> Self {
2032 Self {
2033 session_id: session_id.into(),
2034 cwd: cwd.into(),
2035 additional_directories: vec![],
2036 mcp_servers: vec![],
2037 system_prompt: None,
2038 #[cfg(feature = "unstable_session_options")]
2039 config_options: vec![],
2040 meta: None,
2041 }
2042 }
2043
2044 #[must_use]
2046 pub fn additional_directories(mut self, additional_directories: Vec<PathBuf>) -> Self {
2047 self.additional_directories = additional_directories;
2048 self
2049 }
2050
2051 #[must_use]
2053 pub fn mcp_servers(mut self, mcp_servers: Vec<McpServer>) -> Self {
2054 self.mcp_servers = mcp_servers;
2055 self
2056 }
2057
2058 #[must_use]
2060 pub fn system_prompt(mut self, system_prompt: impl IntoOption<SystemPrompt>) -> Self {
2061 self.system_prompt = system_prompt.into_option();
2062 self
2063 }
2064
2065 #[cfg(feature = "unstable_session_options")]
2081 #[must_use]
2082 pub fn config_options(mut self, config_options: Vec<InitialSessionConfigOption>) -> Self {
2083 self.config_options = config_options;
2084 self
2085 }
2086
2087 #[must_use]
2093 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2094 self.meta = meta.into_option();
2095 self
2096 }
2097}
2098
2099crate::serde_util::default_on_null! {
2100 #[serde_as]
2102 #[skip_serializing_none]
2103 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2104 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2105 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_RESUME_METHOD_NAME)))]
2106 #[serde(rename_all = "camelCase")]
2107 #[non_exhaustive]
2108 pub struct ResumeSessionResponse {
2109 #[serde_as(deserialize_as = "DefaultOnError")]
2113 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2114 #[serde(default)]
2115 pub modes: Option<SessionModeState>,
2116 #[serde_as(deserialize_as = "DefaultOnError<Option<VecSkipError<_>>>")]
2118 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
2119 #[serde(default)]
2120 pub config_options: Option<Vec<SessionConfigOption>>,
2121 #[serde_as(deserialize_as = "DefaultOnError")]
2127 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2128 #[serde(default)]
2129 #[serde(rename = "_meta")]
2130 pub meta: Option<Meta>,
2131 }
2132}
2133
2134impl ResumeSessionResponse {
2135 #[must_use]
2137 pub fn new() -> Self {
2138 Self::default()
2139 }
2140
2141 #[must_use]
2145 pub fn modes(mut self, modes: impl IntoOption<SessionModeState>) -> Self {
2146 self.modes = modes.into_option();
2147 self
2148 }
2149
2150 #[must_use]
2152 pub fn config_options(
2153 mut self,
2154 config_options: impl IntoOption<Vec<SessionConfigOption>>,
2155 ) -> Self {
2156 self.config_options = config_options.into_option();
2157 self
2158 }
2159
2160 #[must_use]
2166 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2167 self.meta = meta.into_option();
2168 self
2169 }
2170}
2171
2172#[serde_as]
2182#[skip_serializing_none]
2183#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2184#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2185#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_CLOSE_METHOD_NAME)))]
2186#[serde(rename_all = "camelCase")]
2187#[non_exhaustive]
2188pub struct CloseSessionRequest {
2189 pub session_id: SessionId,
2191 #[serde_as(deserialize_as = "DefaultOnError")]
2197 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2198 #[serde(default)]
2199 #[serde(rename = "_meta")]
2200 pub meta: Option<Meta>,
2201}
2202
2203impl CloseSessionRequest {
2204 #[must_use]
2206 pub fn new(session_id: impl Into<SessionId>) -> Self {
2207 Self {
2208 session_id: session_id.into(),
2209 meta: None,
2210 }
2211 }
2212
2213 #[must_use]
2219 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2220 self.meta = meta.into_option();
2221 self
2222 }
2223}
2224
2225crate::serde_util::default_on_null! {
2226 #[serde_as]
2228 #[skip_serializing_none]
2229 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2230 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2231 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_CLOSE_METHOD_NAME)))]
2232 #[serde(rename_all = "camelCase")]
2233 #[non_exhaustive]
2234 pub struct CloseSessionResponse {
2235 #[serde_as(deserialize_as = "DefaultOnError")]
2241 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2242 #[serde(default)]
2243 #[serde(rename = "_meta")]
2244 pub meta: Option<Meta>,
2245 }
2246}
2247
2248impl CloseSessionResponse {
2249 #[must_use]
2251 pub fn new() -> Self {
2252 Self::default()
2253 }
2254
2255 #[must_use]
2261 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2262 self.meta = meta.into_option();
2263 self
2264 }
2265}
2266
2267#[cfg(feature = "unstable_session_status")]
2281#[serde_as]
2282#[skip_serializing_none]
2283#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2284#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2285#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_STATUS_METHOD_NAME)))]
2286#[serde(rename_all = "camelCase")]
2287#[non_exhaustive]
2288pub struct SessionStatusRequest {
2289 pub session_id: SessionId,
2291 #[serde_as(deserialize_as = "DefaultOnError")]
2297 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2298 #[serde(default)]
2299 #[serde(rename = "_meta")]
2300 pub meta: Option<Meta>,
2301}
2302
2303#[cfg(feature = "unstable_session_status")]
2304impl SessionStatusRequest {
2305 #[must_use]
2307 pub fn new(session_id: impl Into<SessionId>) -> Self {
2308 Self {
2309 session_id: session_id.into(),
2310 meta: None,
2311 }
2312 }
2313
2314 #[must_use]
2320 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2321 self.meta = meta.into_option();
2322 self
2323 }
2324}
2325
2326#[cfg(feature = "unstable_session_status")]
2335#[serde_as]
2336#[skip_serializing_none]
2337#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2338#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2339#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_STATUS_METHOD_NAME)))]
2340#[serde(rename_all = "camelCase")]
2341#[non_exhaustive]
2342pub struct SessionStatusResponse {
2343 pub status: SessionStatus,
2347 #[serde_as(deserialize_as = "DefaultOnError")]
2353 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2354 #[serde(default)]
2355 #[serde(rename = "_meta")]
2356 pub meta: Option<Meta>,
2357}
2358
2359#[cfg(feature = "unstable_session_status")]
2360impl SessionStatusResponse {
2361 #[must_use]
2363 pub fn new(status: SessionStatus) -> Self {
2364 Self { status, meta: None }
2365 }
2366
2367 #[must_use]
2373 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2374 self.meta = meta.into_option();
2375 self
2376 }
2377}
2378
2379#[cfg(feature = "unstable_session_status")]
2385#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2386#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2387#[serde(rename_all = "snake_case")]
2388#[non_exhaustive]
2389pub enum SessionStatus {
2390 Open,
2397 Saved,
2401 #[serde(untagged)]
2408 Other(String),
2409}
2410
2411#[cfg(feature = "unstable_session_options")]
2425#[serde_as]
2426#[skip_serializing_none]
2427#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2428#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2429#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_OPTIONS_METHOD_NAME)))]
2430#[serde(rename_all = "camelCase")]
2431#[non_exhaustive]
2432pub struct SessionOptionsRequest {
2433 pub cwd: PathBuf,
2435 #[serde_as(deserialize_as = "DefaultOnNull")]
2439 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
2440 #[serde(default, skip_serializing_if = "Vec::is_empty")]
2441 pub additional_directories: Vec<PathBuf>,
2442 #[serde(default)]
2451 pub session_id: Option<SessionId>,
2452 #[serde_as(deserialize_as = "DefaultOnError")]
2458 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2459 #[serde(default)]
2460 #[serde(rename = "_meta")]
2461 pub meta: Option<Meta>,
2462}
2463
2464#[cfg(feature = "unstable_session_options")]
2465impl SessionOptionsRequest {
2466 #[must_use]
2468 pub fn new(cwd: impl Into<PathBuf>) -> Self {
2469 Self {
2470 cwd: cwd.into(),
2471 additional_directories: vec![],
2472 session_id: None,
2473 meta: None,
2474 }
2475 }
2476
2477 #[must_use]
2479 pub fn additional_directories(mut self, additional_directories: Vec<PathBuf>) -> Self {
2480 self.additional_directories = additional_directories;
2481 self
2482 }
2483
2484 #[must_use]
2486 pub fn session_id(mut self, session_id: impl IntoOption<SessionId>) -> Self {
2487 self.session_id = session_id.into_option();
2488 self
2489 }
2490
2491 #[must_use]
2497 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2498 self.meta = meta.into_option();
2499 self
2500 }
2501}
2502
2503#[cfg(feature = "unstable_session_options")]
2504crate::serde_util::default_on_null! {
2505 #[serde_as]
2517 #[skip_serializing_none]
2518 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2519 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2520 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_OPTIONS_METHOD_NAME)))]
2521 #[serde(rename_all = "camelCase")]
2522 #[non_exhaustive]
2523 pub struct SessionOptionsResponse {
2524 #[serde_as(deserialize_as = "DefaultOnError")]
2528 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2529 #[serde(default)]
2530 pub modes: Option<SessionModeState>,
2531 #[serde_as(deserialize_as = "DefaultOnError<Option<VecSkipError<_>>>")]
2536 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
2537 #[serde(default)]
2538 pub config_options: Option<Vec<SessionConfigOption>>,
2539 #[serde_as(deserialize_as = "DefaultOnError")]
2545 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2546 #[serde(default)]
2547 #[serde(rename = "_meta")]
2548 pub meta: Option<Meta>,
2549 }
2550}
2551
2552#[cfg(feature = "unstable_session_options")]
2553impl SessionOptionsResponse {
2554 #[must_use]
2556 pub fn new() -> Self {
2557 Self::default()
2558 }
2559
2560 #[must_use]
2564 pub fn modes(mut self, modes: impl IntoOption<SessionModeState>) -> Self {
2565 self.modes = modes.into_option();
2566 self
2567 }
2568
2569 #[must_use]
2571 pub fn config_options(
2572 mut self,
2573 config_options: impl IntoOption<Vec<SessionConfigOption>>,
2574 ) -> Self {
2575 self.config_options = config_options.into_option();
2576 self
2577 }
2578
2579 #[must_use]
2585 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2586 self.meta = meta.into_option();
2587 self
2588 }
2589}
2590
2591#[cfg(feature = "unstable_session_options")]
2604#[serde_as]
2605#[skip_serializing_none]
2606#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2607#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2608#[serde(rename_all = "camelCase")]
2609#[non_exhaustive]
2610pub struct InitialSessionConfigOption {
2611 pub config_id: SessionConfigId,
2613 #[serde(flatten)]
2618 pub value: SessionConfigOptionValue,
2619 #[serde_as(deserialize_as = "DefaultOnError")]
2625 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2626 #[serde(default)]
2627 #[serde(rename = "_meta")]
2628 pub meta: Option<Meta>,
2629}
2630
2631#[cfg(feature = "unstable_session_options")]
2632impl InitialSessionConfigOption {
2633 #[must_use]
2635 pub fn new(
2636 config_id: impl Into<SessionConfigId>,
2637 value: impl Into<SessionConfigOptionValue>,
2638 ) -> Self {
2639 Self {
2640 config_id: config_id.into(),
2641 value: value.into(),
2642 meta: None,
2643 }
2644 }
2645
2646 #[must_use]
2652 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2653 self.meta = meta.into_option();
2654 self
2655 }
2656}
2657
2658crate::serde_util::default_on_null! {
2661 #[serde_as]
2665 #[skip_serializing_none]
2666 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2667 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2668 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_LIST_METHOD_NAME)))]
2669 #[serde(rename_all = "camelCase")]
2670 #[non_exhaustive]
2671 pub struct ListSessionsRequest {
2672 #[serde(default)]
2674 pub cwd: Option<PathBuf>,
2675 #[serde(default)]
2677 pub cursor: Option<String>,
2678 #[cfg(feature = "unstable_session_archive")]
2688 #[serde(default)]
2689 pub archived: Option<SessionArchiveFilter>,
2690 #[serde_as(deserialize_as = "DefaultOnError")]
2696 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2697 #[serde(default)]
2698 #[serde(rename = "_meta")]
2699 pub meta: Option<Meta>,
2700 }
2701}
2702
2703impl ListSessionsRequest {
2704 #[must_use]
2706 pub fn new() -> Self {
2707 Self::default()
2708 }
2709
2710 #[must_use]
2712 pub fn cwd(mut self, cwd: impl IntoOption<PathBuf>) -> Self {
2713 self.cwd = cwd.into_option();
2714 self
2715 }
2716
2717 #[must_use]
2719 pub fn cursor(mut self, cursor: impl IntoOption<String>) -> Self {
2720 self.cursor = cursor.into_option();
2721 self
2722 }
2723
2724 #[cfg(feature = "unstable_session_archive")]
2730 #[must_use]
2731 pub fn archived(mut self, archived: impl IntoOption<SessionArchiveFilter>) -> Self {
2732 self.archived = archived.into_option();
2733 self
2734 }
2735
2736 #[must_use]
2742 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2743 self.meta = meta.into_option();
2744 self
2745 }
2746}
2747
2748#[serde_as]
2750#[skip_serializing_none]
2751#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2752#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2753#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_LIST_METHOD_NAME)))]
2754#[serde(rename_all = "camelCase")]
2755#[non_exhaustive]
2756pub struct ListSessionsResponse {
2757 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
2759 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
2760 pub sessions: Vec<SessionInfo>,
2761 #[serde_as(deserialize_as = "DefaultOnError")]
2764 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2765 #[serde(default)]
2766 pub next_cursor: Option<String>,
2767 #[serde_as(deserialize_as = "DefaultOnError")]
2773 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2774 #[serde(default)]
2775 #[serde(rename = "_meta")]
2776 pub meta: Option<Meta>,
2777}
2778
2779impl ListSessionsResponse {
2780 #[must_use]
2782 pub fn new(sessions: Vec<SessionInfo>) -> Self {
2783 Self {
2784 sessions,
2785 next_cursor: None,
2786 meta: None,
2787 }
2788 }
2789
2790 #[must_use]
2792 pub fn next_cursor(mut self, next_cursor: impl IntoOption<String>) -> Self {
2793 self.next_cursor = next_cursor.into_option();
2794 self
2795 }
2796
2797 #[must_use]
2803 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2804 self.meta = meta.into_option();
2805 self
2806 }
2807}
2808
2809#[serde_as]
2815#[skip_serializing_none]
2816#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2817#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2818#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_DELETE_METHOD_NAME)))]
2819#[serde(rename_all = "camelCase")]
2820#[non_exhaustive]
2821pub struct DeleteSessionRequest {
2822 pub session_id: SessionId,
2824 #[serde_as(deserialize_as = "DefaultOnError")]
2830 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2831 #[serde(default)]
2832 #[serde(rename = "_meta")]
2833 pub meta: Option<Meta>,
2834}
2835
2836impl DeleteSessionRequest {
2837 #[must_use]
2839 pub fn new(session_id: impl Into<SessionId>) -> Self {
2840 Self {
2841 session_id: session_id.into(),
2842 meta: None,
2843 }
2844 }
2845
2846 #[must_use]
2852 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2853 self.meta = meta.into_option();
2854 self
2855 }
2856}
2857
2858crate::serde_util::default_on_null! {
2859 #[serde_as]
2861 #[skip_serializing_none]
2862 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2863 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2864 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_DELETE_METHOD_NAME)))]
2865 #[serde(rename_all = "camelCase")]
2866 #[non_exhaustive]
2867 pub struct DeleteSessionResponse {
2868 #[serde_as(deserialize_as = "DefaultOnError")]
2874 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2875 #[serde(default)]
2876 #[serde(rename = "_meta")]
2877 pub meta: Option<Meta>,
2878 }
2879}
2880
2881impl DeleteSessionResponse {
2882 #[must_use]
2884 pub fn new() -> Self {
2885 Self::default()
2886 }
2887
2888 #[must_use]
2894 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2895 self.meta = meta.into_option();
2896 self
2897 }
2898}
2899
2900#[cfg(feature = "unstable_session_archive")]
2916#[serde_as]
2917#[skip_serializing_none]
2918#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2919#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2920#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_ARCHIVE_METHOD_NAME)))]
2921#[serde(rename_all = "camelCase")]
2922#[non_exhaustive]
2923pub struct ArchiveSessionRequest {
2924 pub session_id: SessionId,
2926 #[serde_as(deserialize_as = "DefaultOnError")]
2932 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2933 #[serde(default)]
2934 #[serde(rename = "_meta")]
2935 pub meta: Option<Meta>,
2936}
2937
2938#[cfg(feature = "unstable_session_archive")]
2939impl ArchiveSessionRequest {
2940 #[must_use]
2942 pub fn new(session_id: impl Into<SessionId>) -> Self {
2943 Self {
2944 session_id: session_id.into(),
2945 meta: None,
2946 }
2947 }
2948
2949 #[must_use]
2955 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2956 self.meta = meta.into_option();
2957 self
2958 }
2959}
2960
2961#[cfg(feature = "unstable_session_archive")]
2962crate::serde_util::default_on_null! {
2963 #[serde_as]
2969 #[skip_serializing_none]
2970 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2971 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2972 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_ARCHIVE_METHOD_NAME)))]
2973 #[serde(rename_all = "camelCase")]
2974 #[non_exhaustive]
2975 pub struct ArchiveSessionResponse {
2976 #[serde_as(deserialize_as = "DefaultOnError")]
2982 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2983 #[serde(default)]
2984 #[serde(rename = "_meta")]
2985 pub meta: Option<Meta>,
2986 }
2987}
2988
2989#[cfg(feature = "unstable_session_archive")]
2990impl ArchiveSessionResponse {
2991 #[must_use]
2993 pub fn new() -> Self {
2994 Self::default()
2995 }
2996
2997 #[must_use]
3003 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3004 self.meta = meta.into_option();
3005 self
3006 }
3007}
3008
3009#[cfg(feature = "unstable_session_archive")]
3024#[serde_as]
3025#[skip_serializing_none]
3026#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3027#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3028#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_UNARCHIVE_METHOD_NAME)))]
3029#[serde(rename_all = "camelCase")]
3030#[non_exhaustive]
3031pub struct UnarchiveSessionRequest {
3032 pub session_id: SessionId,
3034 #[serde_as(deserialize_as = "DefaultOnError")]
3040 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3041 #[serde(default)]
3042 #[serde(rename = "_meta")]
3043 pub meta: Option<Meta>,
3044}
3045
3046#[cfg(feature = "unstable_session_archive")]
3047impl UnarchiveSessionRequest {
3048 #[must_use]
3050 pub fn new(session_id: impl Into<SessionId>) -> Self {
3051 Self {
3052 session_id: session_id.into(),
3053 meta: None,
3054 }
3055 }
3056
3057 #[must_use]
3063 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3064 self.meta = meta.into_option();
3065 self
3066 }
3067}
3068
3069#[cfg(feature = "unstable_session_archive")]
3070crate::serde_util::default_on_null! {
3071 #[serde_as]
3077 #[skip_serializing_none]
3078 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3079 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
3080 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_UNARCHIVE_METHOD_NAME)))]
3081 #[serde(rename_all = "camelCase")]
3082 #[non_exhaustive]
3083 pub struct UnarchiveSessionResponse {
3084 #[serde_as(deserialize_as = "DefaultOnError")]
3090 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3091 #[serde(default)]
3092 #[serde(rename = "_meta")]
3093 pub meta: Option<Meta>,
3094 }
3095}
3096
3097#[cfg(feature = "unstable_session_archive")]
3098impl UnarchiveSessionResponse {
3099 #[must_use]
3101 pub fn new() -> Self {
3102 Self::default()
3103 }
3104
3105 #[must_use]
3111 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3112 self.meta = meta.into_option();
3113 self
3114 }
3115}
3116
3117#[cfg(feature = "unstable_session_archive")]
3126#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3127#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
3128#[serde(rename_all = "snake_case")]
3129#[non_exhaustive]
3130pub enum SessionArchiveFilter {
3131 #[default]
3133 Exclude,
3134 Include,
3136 Only,
3138 #[serde(untagged)]
3144 Other(String),
3145}
3146
3147#[serde_as]
3149#[skip_serializing_none]
3150#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3151#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3152#[serde(rename_all = "camelCase")]
3153#[non_exhaustive]
3154pub struct SessionInfo {
3155 pub session_id: SessionId,
3157 pub cwd: PathBuf,
3159 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
3165 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
3166 #[serde(default, skip_serializing_if = "Vec::is_empty")]
3167 pub additional_directories: Vec<PathBuf>,
3168
3169 #[serde_as(deserialize_as = "DefaultOnError")]
3171 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3172 #[serde(default)]
3173 pub title: Option<String>,
3174 #[serde_as(deserialize_as = "DefaultOnError")]
3176 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3177 #[serde(default)]
3178 pub updated_at: Option<String>,
3179 #[cfg(feature = "unstable_session_archive")]
3188 #[serde_as(deserialize_as = "DefaultOnError")]
3189 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3190 #[serde(default)]
3191 pub archived: Option<bool>,
3192 #[serde_as(deserialize_as = "DefaultOnError")]
3198 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3199 #[serde(default)]
3200 #[serde(rename = "_meta")]
3201 pub meta: Option<Meta>,
3202}
3203
3204impl SessionInfo {
3205 #[must_use]
3207 pub fn new(session_id: impl Into<SessionId>, cwd: impl Into<PathBuf>) -> Self {
3208 Self {
3209 session_id: session_id.into(),
3210 cwd: cwd.into(),
3211 additional_directories: vec![],
3212 title: None,
3213 updated_at: None,
3214 #[cfg(feature = "unstable_session_archive")]
3215 archived: None,
3216 meta: None,
3217 }
3218 }
3219
3220 #[must_use]
3222 pub fn additional_directories(mut self, additional_directories: Vec<PathBuf>) -> Self {
3223 self.additional_directories = additional_directories;
3224 self
3225 }
3226
3227 #[must_use]
3229 pub fn title(mut self, title: impl IntoOption<String>) -> Self {
3230 self.title = title.into_option();
3231 self
3232 }
3233
3234 #[must_use]
3236 pub fn updated_at(mut self, updated_at: impl IntoOption<String>) -> Self {
3237 self.updated_at = updated_at.into_option();
3238 self
3239 }
3240
3241 #[cfg(feature = "unstable_session_archive")]
3247 #[must_use]
3248 pub fn archived(mut self, archived: impl IntoOption<bool>) -> Self {
3249 self.archived = archived.into_option();
3250 self
3251 }
3252
3253 #[must_use]
3259 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3260 self.meta = meta.into_option();
3261 self
3262 }
3263}
3264
3265#[cfg(feature = "unstable_session_set_title")]
3281#[serde_as]
3282#[skip_serializing_none]
3283#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3284#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3285#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_TITLE_METHOD_NAME)))]
3286#[serde(rename_all = "camelCase")]
3287#[non_exhaustive]
3288pub struct SetSessionTitleRequest {
3289 pub session_id: SessionId,
3291 pub title: String,
3298 #[serde_as(deserialize_as = "DefaultOnError")]
3304 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3305 #[serde(default)]
3306 #[serde(rename = "_meta")]
3307 pub meta: Option<Meta>,
3308}
3309
3310#[cfg(feature = "unstable_session_set_title")]
3311impl SetSessionTitleRequest {
3312 #[must_use]
3314 pub fn new(session_id: impl Into<SessionId>, title: impl Into<String>) -> Self {
3315 Self {
3316 session_id: session_id.into(),
3317 title: title.into(),
3318 meta: None,
3319 }
3320 }
3321
3322 #[must_use]
3328 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3329 self.meta = meta.into_option();
3330 self
3331 }
3332}
3333
3334#[cfg(feature = "unstable_session_set_title")]
3340#[serde_as]
3341#[skip_serializing_none]
3342#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3343#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3344#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_TITLE_METHOD_NAME)))]
3345#[serde(rename_all = "camelCase")]
3346#[non_exhaustive]
3347pub struct SetSessionTitleResponse {
3348 pub title: String,
3353 #[serde_as(deserialize_as = "DefaultOnError")]
3359 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3360 #[serde(default)]
3361 #[serde(rename = "_meta")]
3362 pub meta: Option<Meta>,
3363}
3364
3365#[cfg(feature = "unstable_session_set_title")]
3366impl SetSessionTitleResponse {
3367 #[must_use]
3369 pub fn new(title: impl Into<String>) -> Self {
3370 Self {
3371 title: title.into(),
3372 meta: None,
3373 }
3374 }
3375
3376 #[must_use]
3382 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3383 self.meta = meta.into_option();
3384 self
3385 }
3386}
3387
3388#[serde_as]
3392#[skip_serializing_none]
3393#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3394#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3395#[serde(rename_all = "camelCase")]
3396#[non_exhaustive]
3397pub struct SessionModeState {
3398 pub current_mode_id: SessionModeId,
3400 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
3402 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
3403 pub available_modes: Vec<SessionMode>,
3404 #[serde_as(deserialize_as = "DefaultOnError")]
3410 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3411 #[serde(default)]
3412 #[serde(rename = "_meta")]
3413 pub meta: Option<Meta>,
3414}
3415
3416impl SessionModeState {
3417 #[must_use]
3419 pub fn new(
3420 current_mode_id: impl Into<SessionModeId>,
3421 available_modes: Vec<SessionMode>,
3422 ) -> Self {
3423 Self {
3424 current_mode_id: current_mode_id.into(),
3425 available_modes,
3426 meta: None,
3427 }
3428 }
3429
3430 #[must_use]
3436 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3437 self.meta = meta.into_option();
3438 self
3439 }
3440}
3441
3442#[serde_as]
3446#[skip_serializing_none]
3447#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3448#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3449#[serde(rename_all = "camelCase")]
3450#[non_exhaustive]
3451pub struct SessionMode {
3452 pub id: SessionModeId,
3454 pub name: String,
3456 #[serde_as(deserialize_as = "DefaultOnError")]
3458 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3459 #[serde(default)]
3460 pub description: Option<String>,
3461 #[serde_as(deserialize_as = "DefaultOnError")]
3467 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3468 #[serde(default)]
3469 #[serde(rename = "_meta")]
3470 pub meta: Option<Meta>,
3471}
3472
3473impl SessionMode {
3474 #[must_use]
3476 pub fn new(id: impl Into<SessionModeId>, name: impl Into<String>) -> Self {
3477 Self {
3478 id: id.into(),
3479 name: name.into(),
3480 description: None,
3481 meta: None,
3482 }
3483 }
3484
3485 #[must_use]
3487 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
3488 self.description = description.into_option();
3489 self
3490 }
3491
3492 #[must_use]
3498 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3499 self.meta = meta.into_option();
3500 self
3501 }
3502}
3503
3504#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3506#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, From, Display)]
3507#[serde(transparent)]
3508#[from(Arc<str>, String, &'static str)]
3509#[non_exhaustive]
3510pub struct SessionModeId(pub Arc<str>);
3511
3512impl SessionModeId {
3513 #[must_use]
3515 pub fn new(id: impl Into<Arc<str>>) -> Self {
3516 Self(id.into())
3517 }
3518}
3519
3520#[serde_as]
3522#[skip_serializing_none]
3523#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3524#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3525#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_MODE_METHOD_NAME)))]
3526#[serde(rename_all = "camelCase")]
3527#[non_exhaustive]
3528pub struct SetSessionModeRequest {
3529 pub session_id: SessionId,
3531 pub mode_id: SessionModeId,
3533 #[serde_as(deserialize_as = "DefaultOnError")]
3539 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3540 #[serde(default)]
3541 #[serde(rename = "_meta")]
3542 pub meta: Option<Meta>,
3543}
3544
3545impl SetSessionModeRequest {
3546 #[must_use]
3548 pub fn new(session_id: impl Into<SessionId>, mode_id: impl Into<SessionModeId>) -> Self {
3549 Self {
3550 session_id: session_id.into(),
3551 mode_id: mode_id.into(),
3552 meta: None,
3553 }
3554 }
3555
3556 #[must_use]
3558 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3559 self.meta = meta.into_option();
3560 self
3561 }
3562}
3563
3564crate::serde_util::default_on_null! {
3565 #[serde_as]
3567 #[skip_serializing_none]
3568 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3569 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
3570 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_MODE_METHOD_NAME)))]
3571 #[serde(rename_all = "camelCase")]
3572 #[non_exhaustive]
3573 pub struct SetSessionModeResponse {
3574 #[serde_as(deserialize_as = "DefaultOnError")]
3580 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3581 #[serde(default)]
3582 #[serde(rename = "_meta")]
3583 pub meta: Option<Meta>,
3584 }
3585}
3586
3587impl SetSessionModeResponse {
3588 #[must_use]
3590 pub fn new() -> Self {
3591 Self::default()
3592 }
3593
3594 #[must_use]
3600 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3601 self.meta = meta.into_option();
3602 self
3603 }
3604}
3605
3606#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3610#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, From, Display)]
3611#[serde(transparent)]
3612#[from(Arc<str>, String, &'static str)]
3613#[non_exhaustive]
3614pub struct SessionConfigId(pub Arc<str>);
3615
3616impl SessionConfigId {
3617 #[must_use]
3619 pub fn new(id: impl Into<Arc<str>>) -> Self {
3620 Self(id.into())
3621 }
3622}
3623
3624#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3626#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, From, Display)]
3627#[serde(transparent)]
3628#[from(Arc<str>, String, &'static str)]
3629#[non_exhaustive]
3630pub struct SessionConfigValueId(pub Arc<str>);
3631
3632impl SessionConfigValueId {
3633 #[must_use]
3635 pub fn new(id: impl Into<Arc<str>>) -> Self {
3636 Self(id.into())
3637 }
3638}
3639
3640#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3642#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, From, Display)]
3643#[serde(transparent)]
3644#[from(Arc<str>, String, &'static str)]
3645#[non_exhaustive]
3646pub struct SessionConfigGroupId(pub Arc<str>);
3647
3648impl SessionConfigGroupId {
3649 #[must_use]
3651 pub fn new(id: impl Into<Arc<str>>) -> Self {
3652 Self(id.into())
3653 }
3654}
3655
3656#[serde_as]
3658#[skip_serializing_none]
3659#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3660#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3661#[serde(rename_all = "camelCase")]
3662#[non_exhaustive]
3663pub struct SessionConfigSelectOption {
3664 pub value: SessionConfigValueId,
3666 pub name: String,
3668 #[serde_as(deserialize_as = "DefaultOnError")]
3670 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3671 #[serde(default)]
3672 pub description: Option<String>,
3673 #[serde_as(deserialize_as = "DefaultOnError")]
3679 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3680 #[serde(default)]
3681 #[serde(rename = "_meta")]
3682 pub meta: Option<Meta>,
3683}
3684
3685impl SessionConfigSelectOption {
3686 #[must_use]
3688 pub fn new(value: impl Into<SessionConfigValueId>, name: impl Into<String>) -> Self {
3689 Self {
3690 value: value.into(),
3691 name: name.into(),
3692 description: None,
3693 meta: None,
3694 }
3695 }
3696
3697 #[must_use]
3699 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
3700 self.description = description.into_option();
3701 self
3702 }
3703
3704 #[must_use]
3710 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3711 self.meta = meta.into_option();
3712 self
3713 }
3714}
3715
3716#[serde_as]
3718#[skip_serializing_none]
3719#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3720#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3721#[serde(rename_all = "camelCase")]
3722#[non_exhaustive]
3723pub struct SessionConfigSelectGroup {
3724 pub group: SessionConfigGroupId,
3726 pub name: String,
3728 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
3730 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
3731 pub options: Vec<SessionConfigSelectOption>,
3732 #[serde_as(deserialize_as = "DefaultOnError")]
3738 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3739 #[serde(default)]
3740 #[serde(rename = "_meta")]
3741 pub meta: Option<Meta>,
3742}
3743
3744impl SessionConfigSelectGroup {
3745 #[must_use]
3747 pub fn new(
3748 group: impl Into<SessionConfigGroupId>,
3749 name: impl Into<String>,
3750 options: Vec<SessionConfigSelectOption>,
3751 ) -> Self {
3752 Self {
3753 group: group.into(),
3754 name: name.into(),
3755 options,
3756 meta: None,
3757 }
3758 }
3759
3760 #[must_use]
3766 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3767 self.meta = meta.into_option();
3768 self
3769 }
3770}
3771
3772#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3774#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3775#[serde(untagged)]
3776#[non_exhaustive]
3777pub enum SessionConfigSelectOptions {
3778 Ungrouped(Vec<SessionConfigSelectOption>),
3780 Grouped(Vec<SessionConfigSelectGroup>),
3782}
3783
3784impl From<Vec<SessionConfigSelectOption>> for SessionConfigSelectOptions {
3785 fn from(options: Vec<SessionConfigSelectOption>) -> Self {
3786 SessionConfigSelectOptions::Ungrouped(options)
3787 }
3788}
3789
3790impl From<Vec<SessionConfigSelectGroup>> for SessionConfigSelectOptions {
3791 fn from(groups: Vec<SessionConfigSelectGroup>) -> Self {
3792 SessionConfigSelectOptions::Grouped(groups)
3793 }
3794}
3795
3796#[skip_serializing_none]
3798#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3799#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3800#[serde(rename_all = "camelCase")]
3801#[non_exhaustive]
3802pub struct SessionConfigSelect {
3803 pub current_value: SessionConfigValueId,
3805 pub options: SessionConfigSelectOptions,
3807}
3808
3809impl SessionConfigSelect {
3810 #[must_use]
3812 pub fn new(
3813 current_value: impl Into<SessionConfigValueId>,
3814 options: impl Into<SessionConfigSelectOptions>,
3815 ) -> Self {
3816 Self {
3817 current_value: current_value.into(),
3818 options: options.into(),
3819 }
3820 }
3821}
3822
3823#[skip_serializing_none]
3825#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3826#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3827#[serde(rename_all = "camelCase")]
3828#[non_exhaustive]
3829pub struct SessionConfigBoolean {
3830 pub current_value: bool,
3832}
3833
3834impl SessionConfigBoolean {
3835 #[must_use]
3837 pub fn new(current_value: bool) -> Self {
3838 Self { current_value }
3839 }
3840}
3841
3842#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3852#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3853#[serde(rename_all = "snake_case")]
3854#[non_exhaustive]
3855pub enum SessionConfigOptionCategory {
3856 Mode,
3858 Model,
3860 ModelConfig,
3862 #[cfg(feature = "unstable_speed_config_category")]
3868 Speed,
3869 ThoughtLevel,
3871 #[serde(untagged)]
3873 Other(String),
3874}
3875
3876#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3878#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3879#[serde(tag = "type", rename_all = "snake_case")]
3880#[cfg_attr(feature = "schemars", schemars(extend("discriminator" = {"propertyName": "type"})))]
3881#[non_exhaustive]
3882pub enum SessionConfigKind {
3883 Select(SessionConfigSelect),
3885 Boolean(SessionConfigBoolean),
3887}
3888
3889#[serde_as]
3891#[skip_serializing_none]
3892#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3893#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3894#[serde(rename_all = "camelCase")]
3895#[non_exhaustive]
3896pub struct SessionConfigOption {
3897 pub id: SessionConfigId,
3899 pub name: String,
3901 #[serde_as(deserialize_as = "DefaultOnError")]
3903 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3904 #[serde(default)]
3905 pub description: Option<String>,
3906 #[serde_as(deserialize_as = "DefaultOnError")]
3908 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3909 #[serde(default)]
3910 pub category: Option<SessionConfigOptionCategory>,
3911 #[serde(flatten)]
3913 pub kind: SessionConfigKind,
3914 #[serde_as(deserialize_as = "DefaultOnError")]
3920 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3921 #[serde(default)]
3922 #[serde(rename = "_meta")]
3923 pub meta: Option<Meta>,
3924}
3925
3926impl SessionConfigOption {
3927 #[must_use]
3929 pub fn new(
3930 id: impl Into<SessionConfigId>,
3931 name: impl Into<String>,
3932 kind: SessionConfigKind,
3933 ) -> Self {
3934 Self {
3935 id: id.into(),
3936 name: name.into(),
3937 description: None,
3938 category: None,
3939 kind,
3940 meta: None,
3941 }
3942 }
3943
3944 #[must_use]
3946 pub fn select(
3947 id: impl Into<SessionConfigId>,
3948 name: impl Into<String>,
3949 current_value: impl Into<SessionConfigValueId>,
3950 options: impl Into<SessionConfigSelectOptions>,
3951 ) -> Self {
3952 Self::new(
3953 id,
3954 name,
3955 SessionConfigKind::Select(SessionConfigSelect::new(current_value, options)),
3956 )
3957 }
3958
3959 #[must_use]
3961 pub fn boolean(
3962 id: impl Into<SessionConfigId>,
3963 name: impl Into<String>,
3964 current_value: bool,
3965 ) -> Self {
3966 Self::new(
3967 id,
3968 name,
3969 SessionConfigKind::Boolean(SessionConfigBoolean::new(current_value)),
3970 )
3971 }
3972
3973 #[must_use]
3975 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
3976 self.description = description.into_option();
3977 self
3978 }
3979
3980 #[must_use]
3982 pub fn category(mut self, category: impl IntoOption<SessionConfigOptionCategory>) -> Self {
3983 self.category = category.into_option();
3984 self
3985 }
3986
3987 #[must_use]
3993 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3994 self.meta = meta.into_option();
3995 self
3996 }
3997}
3998
3999#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4010#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4011#[serde(tag = "type", rename_all = "snake_case")]
4012#[non_exhaustive]
4013pub enum SessionConfigOptionValue {
4014 Boolean {
4016 value: bool,
4018 },
4019 #[serde(untagged)]
4025 ValueId {
4026 value: SessionConfigValueId,
4028 },
4029}
4030
4031impl SessionConfigOptionValue {
4032 #[must_use]
4034 pub fn value_id(id: impl Into<SessionConfigValueId>) -> Self {
4035 Self::ValueId { value: id.into() }
4036 }
4037
4038 #[must_use]
4040 pub fn boolean(val: bool) -> Self {
4041 Self::Boolean { value: val }
4042 }
4043
4044 #[must_use]
4047 pub fn as_value_id(&self) -> Option<&SessionConfigValueId> {
4048 match self {
4049 Self::ValueId { value } => Some(value),
4050 _ => None,
4051 }
4052 }
4053
4054 #[must_use]
4056 pub fn as_bool(&self) -> Option<bool> {
4057 match self {
4058 Self::Boolean { value } => Some(*value),
4059 _ => None,
4060 }
4061 }
4062}
4063
4064impl From<SessionConfigValueId> for SessionConfigOptionValue {
4065 fn from(value: SessionConfigValueId) -> Self {
4066 Self::ValueId { value }
4067 }
4068}
4069
4070impl From<bool> for SessionConfigOptionValue {
4071 fn from(value: bool) -> Self {
4072 Self::Boolean { value }
4073 }
4074}
4075
4076impl From<&str> for SessionConfigOptionValue {
4077 fn from(value: &str) -> Self {
4078 Self::ValueId {
4079 value: SessionConfigValueId::new(value),
4080 }
4081 }
4082}
4083
4084#[serde_as]
4086#[skip_serializing_none]
4087#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4088#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4089#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_CONFIG_OPTION_METHOD_NAME)))]
4090#[serde(rename_all = "camelCase")]
4091#[non_exhaustive]
4092pub struct SetSessionConfigOptionRequest {
4093 pub session_id: SessionId,
4095 pub config_id: SessionConfigId,
4097 #[serde(flatten)]
4102 pub value: SessionConfigOptionValue,
4103 #[serde_as(deserialize_as = "DefaultOnError")]
4109 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4110 #[serde(default)]
4111 #[serde(rename = "_meta")]
4112 pub meta: Option<Meta>,
4113}
4114
4115impl SetSessionConfigOptionRequest {
4116 #[must_use]
4118 pub fn new(
4119 session_id: impl Into<SessionId>,
4120 config_id: impl Into<SessionConfigId>,
4121 value: impl Into<SessionConfigOptionValue>,
4122 ) -> Self {
4123 Self {
4124 session_id: session_id.into(),
4125 config_id: config_id.into(),
4126 value: value.into(),
4127 meta: None,
4128 }
4129 }
4130
4131 #[must_use]
4137 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4138 self.meta = meta.into_option();
4139 self
4140 }
4141}
4142
4143#[serde_as]
4145#[skip_serializing_none]
4146#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4147#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4148#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_CONFIG_OPTION_METHOD_NAME)))]
4149#[serde(rename_all = "camelCase")]
4150#[non_exhaustive]
4151pub struct SetSessionConfigOptionResponse {
4152 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
4154 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
4155 pub config_options: Vec<SessionConfigOption>,
4156 #[serde_as(deserialize_as = "DefaultOnError")]
4162 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4163 #[serde(default)]
4164 #[serde(rename = "_meta")]
4165 pub meta: Option<Meta>,
4166}
4167
4168impl SetSessionConfigOptionResponse {
4169 #[must_use]
4171 pub fn new(config_options: Vec<SessionConfigOption>) -> Self {
4172 Self {
4173 config_options,
4174 meta: None,
4175 }
4176 }
4177
4178 #[must_use]
4184 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4185 self.meta = meta.into_option();
4186 self
4187 }
4188}
4189
4190#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4199#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4200#[serde(tag = "type", rename_all = "snake_case")]
4201#[non_exhaustive]
4202pub enum McpServer {
4203 Http(McpServerHttp),
4207 Sse(McpServerSse),
4211 #[cfg(feature = "unstable_mcp_over_acp")]
4220 Acp(McpServerAcp),
4221 #[serde(untagged)]
4225 Stdio(McpServerStdio),
4226}
4227
4228#[serde_as]
4230#[skip_serializing_none]
4231#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4232#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4233#[serde(rename_all = "camelCase")]
4234#[non_exhaustive]
4235pub struct McpServerHttp {
4236 pub name: String,
4238 pub url: String,
4240 #[serde_as(deserialize_as = "DefaultOnNull")]
4242 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
4243 pub headers: Vec<HttpHeader>,
4244 #[serde_as(deserialize_as = "DefaultOnError")]
4250 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4251 #[serde(default)]
4252 #[serde(rename = "_meta")]
4253 pub meta: Option<Meta>,
4254}
4255
4256impl McpServerHttp {
4257 #[must_use]
4259 pub fn new(name: impl Into<String>, url: impl Into<String>) -> Self {
4260 Self {
4261 name: name.into(),
4262 url: url.into(),
4263 headers: Vec::new(),
4264 meta: None,
4265 }
4266 }
4267
4268 #[must_use]
4270 pub fn headers(mut self, headers: Vec<HttpHeader>) -> Self {
4271 self.headers = headers;
4272 self
4273 }
4274
4275 #[must_use]
4281 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4282 self.meta = meta.into_option();
4283 self
4284 }
4285}
4286
4287#[serde_as]
4289#[skip_serializing_none]
4290#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4291#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4292#[serde(rename_all = "camelCase")]
4293#[non_exhaustive]
4294pub struct McpServerSse {
4295 pub name: String,
4297 pub url: String,
4299 #[serde_as(deserialize_as = "DefaultOnNull")]
4301 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
4302 pub headers: Vec<HttpHeader>,
4303 #[serde_as(deserialize_as = "DefaultOnError")]
4309 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4310 #[serde(default)]
4311 #[serde(rename = "_meta")]
4312 pub meta: Option<Meta>,
4313}
4314
4315impl McpServerSse {
4316 #[must_use]
4318 pub fn new(name: impl Into<String>, url: impl Into<String>) -> Self {
4319 Self {
4320 name: name.into(),
4321 url: url.into(),
4322 headers: Vec::new(),
4323 meta: None,
4324 }
4325 }
4326
4327 #[must_use]
4329 pub fn headers(mut self, headers: Vec<HttpHeader>) -> Self {
4330 self.headers = headers;
4331 self
4332 }
4333
4334 #[must_use]
4340 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4341 self.meta = meta.into_option();
4342 self
4343 }
4344}
4345
4346#[cfg(feature = "unstable_mcp_over_acp")]
4355#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4356#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Display, From)]
4357#[serde(transparent)]
4358#[from(Arc<str>, String, &'static str)]
4359#[non_exhaustive]
4360pub struct McpServerAcpId(pub Arc<str>);
4361
4362#[cfg(feature = "unstable_mcp_over_acp")]
4363impl McpServerAcpId {
4364 #[must_use]
4366 pub fn new(id: impl Into<Arc<str>>) -> Self {
4367 Self(id.into())
4368 }
4369}
4370
4371#[serde_as]
4380#[skip_serializing_none]
4381#[cfg(feature = "unstable_mcp_over_acp")]
4382#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4383#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4384#[serde(rename_all = "camelCase")]
4385#[non_exhaustive]
4386pub struct McpServerAcp {
4387 pub name: String,
4389 pub server_id: McpServerAcpId,
4394 #[serde_as(deserialize_as = "DefaultOnError")]
4400 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4401 #[serde(default)]
4402 #[serde(rename = "_meta")]
4403 pub meta: Option<Meta>,
4404}
4405
4406#[cfg(feature = "unstable_mcp_over_acp")]
4407impl McpServerAcp {
4408 #[must_use]
4410 pub fn new(name: impl Into<String>, id: impl Into<McpServerAcpId>) -> Self {
4411 Self {
4412 name: name.into(),
4413 server_id: id.into(),
4414 meta: None,
4415 }
4416 }
4417
4418 #[must_use]
4424 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4425 self.meta = meta.into_option();
4426 self
4427 }
4428}
4429
4430#[serde_as]
4432#[skip_serializing_none]
4433#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4434#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4435#[serde(rename_all = "camelCase")]
4436#[non_exhaustive]
4437pub struct McpServerStdio {
4438 pub name: String,
4440 pub command: PathBuf,
4442 #[serde_as(deserialize_as = "DefaultOnNull")]
4444 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
4445 pub args: Vec<String>,
4446 #[serde_as(deserialize_as = "DefaultOnNull")]
4448 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
4449 pub env: Vec<EnvVariable>,
4450 #[serde_as(deserialize_as = "DefaultOnError")]
4456 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4457 #[serde(default)]
4458 #[serde(rename = "_meta")]
4459 pub meta: Option<Meta>,
4460}
4461
4462impl McpServerStdio {
4463 #[must_use]
4465 pub fn new(name: impl Into<String>, command: impl Into<PathBuf>) -> Self {
4466 Self {
4467 name: name.into(),
4468 command: command.into(),
4469 args: Vec::new(),
4470 env: Vec::new(),
4471 meta: None,
4472 }
4473 }
4474
4475 #[must_use]
4477 pub fn args(mut self, args: Vec<String>) -> Self {
4478 self.args = args;
4479 self
4480 }
4481
4482 #[must_use]
4484 pub fn env(mut self, env: Vec<EnvVariable>) -> Self {
4485 self.env = env;
4486 self
4487 }
4488
4489 #[must_use]
4495 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4496 self.meta = meta.into_option();
4497 self
4498 }
4499}
4500
4501#[serde_as]
4503#[skip_serializing_none]
4504#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4505#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4506#[serde(rename_all = "camelCase")]
4507#[non_exhaustive]
4508pub struct EnvVariable {
4509 pub name: String,
4511 pub value: String,
4513 #[serde_as(deserialize_as = "DefaultOnError")]
4519 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4520 #[serde(default)]
4521 #[serde(rename = "_meta")]
4522 pub meta: Option<Meta>,
4523}
4524
4525impl EnvVariable {
4526 #[must_use]
4528 pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self {
4529 Self {
4530 name: name.into(),
4531 value: value.into(),
4532 meta: None,
4533 }
4534 }
4535
4536 #[must_use]
4542 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4543 self.meta = meta.into_option();
4544 self
4545 }
4546}
4547
4548#[serde_as]
4550#[skip_serializing_none]
4551#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4552#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4553#[serde(rename_all = "camelCase")]
4554#[non_exhaustive]
4555pub struct HttpHeader {
4556 pub name: String,
4558 pub value: String,
4560 #[serde_as(deserialize_as = "DefaultOnError")]
4566 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4567 #[serde(default)]
4568 #[serde(rename = "_meta")]
4569 pub meta: Option<Meta>,
4570}
4571
4572impl HttpHeader {
4573 #[must_use]
4575 pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self {
4576 Self {
4577 name: name.into(),
4578 value: value.into(),
4579 meta: None,
4580 }
4581 }
4582
4583 #[must_use]
4589 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4590 self.meta = meta.into_option();
4591 self
4592 }
4593}
4594
4595#[serde_as]
4604#[skip_serializing_none]
4605#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4606#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4607#[serde(rename_all = "camelCase")]
4608#[non_exhaustive]
4609pub struct SystemPrompt {
4610 pub mode: SystemPromptMode,
4615 pub content: Vec<ContentBlock>,
4625 #[serde_as(deserialize_as = "DefaultOnError")]
4631 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4632 #[serde(default)]
4633 #[serde(rename = "_meta")]
4634 pub meta: Option<Meta>,
4635}
4636
4637impl SystemPrompt {
4638 #[must_use]
4643 pub fn new(content: Vec<ContentBlock>) -> Self {
4644 Self {
4645 mode: SystemPromptMode::default(),
4646 content,
4647 meta: None,
4648 }
4649 }
4650
4651 #[must_use]
4653 pub fn mode(mut self, mode: SystemPromptMode) -> Self {
4654 self.mode = mode;
4655 self
4656 }
4657
4658 #[must_use]
4664 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4665 self.meta = meta.into_option();
4666 self
4667 }
4668}
4669
4670#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4676#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
4677#[serde(rename_all = "snake_case")]
4678#[non_exhaustive]
4679pub enum SystemPromptMode {
4680 #[default]
4687 Append,
4688 Override,
4697 #[serde(untagged)]
4703 Other(String),
4704}
4705
4706#[serde_as]
4714#[skip_serializing_none]
4715#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4716#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4717#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_PROMPT_METHOD_NAME)))]
4718#[serde(rename_all = "camelCase")]
4719#[non_exhaustive]
4720pub struct PromptRequest {
4721 pub session_id: SessionId,
4723 pub prompt: Vec<ContentBlock>,
4737 #[serde_as(deserialize_as = "DefaultOnError")]
4743 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4744 #[serde(default)]
4745 #[serde(rename = "_meta")]
4746 pub meta: Option<Meta>,
4747}
4748
4749impl PromptRequest {
4750 #[must_use]
4752 pub fn new(session_id: impl Into<SessionId>, prompt: Vec<ContentBlock>) -> Self {
4753 Self {
4754 session_id: session_id.into(),
4755 prompt,
4756 meta: None,
4757 }
4758 }
4759
4760 #[must_use]
4766 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4767 self.meta = meta.into_option();
4768 self
4769 }
4770}
4771
4772#[serde_as]
4776#[skip_serializing_none]
4777#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4778#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4779#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_PROMPT_METHOD_NAME)))]
4780#[serde(rename_all = "camelCase")]
4781#[non_exhaustive]
4782pub struct PromptResponse {
4783 pub stop_reason: StopReason,
4785 #[cfg(feature = "unstable_end_turn_token_usage")]
4791 #[serde_as(deserialize_as = "DefaultOnError")]
4792 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4793 #[serde(default)]
4794 pub usage: Option<Usage>,
4795 #[serde_as(deserialize_as = "DefaultOnError")]
4801 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4802 #[serde(default)]
4803 #[serde(rename = "_meta")]
4804 pub meta: Option<Meta>,
4805}
4806
4807impl PromptResponse {
4808 #[must_use]
4810 pub fn new(stop_reason: StopReason) -> Self {
4811 Self {
4812 stop_reason,
4813 #[cfg(feature = "unstable_end_turn_token_usage")]
4814 usage: None,
4815 meta: None,
4816 }
4817 }
4818
4819 #[cfg(feature = "unstable_end_turn_token_usage")]
4825 #[must_use]
4826 pub fn usage(mut self, usage: impl IntoOption<Usage>) -> Self {
4827 self.usage = usage.into_option();
4828 self
4829 }
4830
4831 #[must_use]
4837 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4838 self.meta = meta.into_option();
4839 self
4840 }
4841}
4842
4843#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4847#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
4848#[serde(rename_all = "snake_case")]
4849#[non_exhaustive]
4850pub enum StopReason {
4851 EndTurn,
4853 MaxTokens,
4855 MaxTurnRequests,
4858 Refusal,
4862 Cancelled,
4869}
4870
4871#[cfg(feature = "unstable_end_turn_token_usage")]
4877#[serde_as]
4878#[skip_serializing_none]
4879#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4880#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4881#[serde(rename_all = "camelCase")]
4882#[non_exhaustive]
4883pub struct Usage {
4884 pub total_tokens: u64,
4886 pub input_tokens: u64,
4888 pub output_tokens: u64,
4890 #[serde_as(deserialize_as = "DefaultOnError")]
4892 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4893 #[serde(default)]
4894 pub thought_tokens: Option<u64>,
4895 #[serde_as(deserialize_as = "DefaultOnError")]
4897 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4898 #[serde(default)]
4899 pub cached_read_tokens: Option<u64>,
4900 #[serde_as(deserialize_as = "DefaultOnError")]
4902 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4903 #[serde(default)]
4904 pub cached_write_tokens: Option<u64>,
4905 #[serde_as(deserialize_as = "DefaultOnError")]
4911 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4912 #[serde(default)]
4913 #[serde(rename = "_meta")]
4914 pub meta: Option<Meta>,
4915}
4916
4917#[cfg(feature = "unstable_end_turn_token_usage")]
4918impl Usage {
4919 #[must_use]
4921 pub fn new(total_tokens: u64, input_tokens: u64, output_tokens: u64) -> Self {
4922 Self {
4923 total_tokens,
4924 input_tokens,
4925 output_tokens,
4926 thought_tokens: None,
4927 cached_read_tokens: None,
4928 cached_write_tokens: None,
4929 meta: None,
4930 }
4931 }
4932
4933 #[must_use]
4935 pub fn thought_tokens(mut self, thought_tokens: impl IntoOption<u64>) -> Self {
4936 self.thought_tokens = thought_tokens.into_option();
4937 self
4938 }
4939
4940 #[must_use]
4942 pub fn cached_read_tokens(mut self, cached_read_tokens: impl IntoOption<u64>) -> Self {
4943 self.cached_read_tokens = cached_read_tokens.into_option();
4944 self
4945 }
4946
4947 #[must_use]
4949 pub fn cached_write_tokens(mut self, cached_write_tokens: impl IntoOption<u64>) -> Self {
4950 self.cached_write_tokens = cached_write_tokens.into_option();
4951 self
4952 }
4953
4954 #[must_use]
4960 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4961 self.meta = meta.into_option();
4962 self
4963 }
4964}
4965
4966#[cfg(feature = "unstable_llm_providers")]
4979#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4980#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4981#[serde(rename_all = "snake_case")]
4982#[non_exhaustive]
4983pub enum LlmProtocol {
4984 Anthropic,
4986 #[serde(rename = "openai")]
4988 OpenAi,
4989 Azure,
4991 Vertex,
4993 Bedrock,
4995 #[serde(untagged)]
4997 Other(String),
4998}
4999
5000#[cfg(feature = "unstable_llm_providers")]
5006#[serde_as]
5007#[skip_serializing_none]
5008#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5009#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5010#[serde(rename_all = "camelCase")]
5011#[non_exhaustive]
5012pub struct ProviderCurrentConfig {
5013 pub api_type: LlmProtocol,
5015 pub base_url: String,
5017 #[serde_as(deserialize_as = "DefaultOnError")]
5023 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5024 #[serde(default)]
5025 #[serde(rename = "_meta")]
5026 pub meta: Option<Meta>,
5027}
5028
5029#[cfg(feature = "unstable_llm_providers")]
5030impl ProviderCurrentConfig {
5031 #[must_use]
5033 pub fn new(api_type: LlmProtocol, base_url: impl Into<String>) -> Self {
5034 Self {
5035 api_type,
5036 base_url: base_url.into(),
5037 meta: None,
5038 }
5039 }
5040
5041 #[must_use]
5047 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5048 self.meta = meta.into_option();
5049 self
5050 }
5051}
5052
5053#[cfg(feature = "unstable_llm_providers")]
5059#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5060#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Display, From)]
5061#[serde(transparent)]
5062#[from(Arc<str>, String, &'static str)]
5063#[non_exhaustive]
5064pub struct ProviderId(pub Arc<str>);
5065
5066#[cfg(feature = "unstable_llm_providers")]
5067impl ProviderId {
5068 #[must_use]
5070 pub fn new(id: impl Into<Arc<str>>) -> Self {
5071 Self(id.into())
5072 }
5073}
5074
5075#[cfg(feature = "unstable_llm_providers")]
5081#[serde_as]
5082#[skip_serializing_none]
5083#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5084#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5085#[serde(rename_all = "camelCase")]
5086#[non_exhaustive]
5087pub struct ProviderInfo {
5088 pub provider_id: ProviderId,
5090 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
5092 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
5093 pub supported: Vec<LlmProtocol>,
5094 pub required: bool,
5097 #[serde(default)]
5100 pub current: Option<ProviderCurrentConfig>,
5101 #[serde_as(deserialize_as = "DefaultOnError")]
5107 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5108 #[serde(default)]
5109 #[serde(rename = "_meta")]
5110 pub meta: Option<Meta>,
5111}
5112
5113#[cfg(feature = "unstable_llm_providers")]
5114impl ProviderInfo {
5115 #[must_use]
5117 pub fn new(
5118 provider_id: impl Into<ProviderId>,
5119 supported: Vec<LlmProtocol>,
5120 required: bool,
5121 current: impl IntoOption<ProviderCurrentConfig>,
5122 ) -> Self {
5123 Self {
5124 provider_id: provider_id.into(),
5125 supported,
5126 required,
5127 current: current.into_option(),
5128 meta: None,
5129 }
5130 }
5131
5132 #[must_use]
5138 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5139 self.meta = meta.into_option();
5140 self
5141 }
5142}
5143
5144#[cfg(feature = "unstable_llm_providers")]
5145crate::serde_util::default_on_null! {
5146 #[serde_as]
5152 #[skip_serializing_none]
5153 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5154 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
5155 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_LIST_METHOD_NAME)))]
5156 #[serde(rename_all = "camelCase")]
5157 #[non_exhaustive]
5158 pub struct ListProvidersRequest {
5159 #[serde_as(deserialize_as = "DefaultOnError")]
5165 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5166 #[serde(default)]
5167 #[serde(rename = "_meta")]
5168 pub meta: Option<Meta>,
5169 }
5170}
5171
5172#[cfg(feature = "unstable_llm_providers")]
5173impl ListProvidersRequest {
5174 #[must_use]
5176 pub fn new() -> Self {
5177 Self::default()
5178 }
5179
5180 #[must_use]
5186 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5187 self.meta = meta.into_option();
5188 self
5189 }
5190}
5191
5192#[cfg(feature = "unstable_llm_providers")]
5198#[serde_as]
5199#[skip_serializing_none]
5200#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5201#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5202#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_LIST_METHOD_NAME)))]
5203#[serde(rename_all = "camelCase")]
5204#[non_exhaustive]
5205pub struct ListProvidersResponse {
5206 pub providers: Vec<ProviderInfo>,
5208 #[serde_as(deserialize_as = "DefaultOnError")]
5214 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5215 #[serde(default)]
5216 #[serde(rename = "_meta")]
5217 pub meta: Option<Meta>,
5218}
5219
5220#[cfg(feature = "unstable_llm_providers")]
5221impl ListProvidersResponse {
5222 #[must_use]
5224 pub fn new(providers: Vec<ProviderInfo>) -> Self {
5225 Self {
5226 providers,
5227 meta: None,
5228 }
5229 }
5230
5231 #[must_use]
5237 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5238 self.meta = meta.into_option();
5239 self
5240 }
5241}
5242
5243#[cfg(feature = "unstable_llm_providers")]
5251#[serde_as]
5252#[skip_serializing_none]
5253#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5254#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
5255#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_SET_METHOD_NAME)))]
5256#[serde(rename_all = "camelCase")]
5257#[non_exhaustive]
5258pub struct SetProviderRequest {
5259 pub provider_id: ProviderId,
5261 pub api_type: LlmProtocol,
5263 pub base_url: String,
5265 #[serde(default, skip_serializing_if = "IndexMap::is_empty")]
5268 pub headers: IndexMap<String, String>,
5269 #[serde_as(deserialize_as = "DefaultOnError")]
5275 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5276 #[serde(default)]
5277 #[serde(rename = "_meta")]
5278 pub meta: Option<Meta>,
5279}
5280
5281#[cfg(feature = "unstable_llm_providers")]
5282impl SetProviderRequest {
5283 #[must_use]
5285 pub fn new(
5286 provider_id: impl Into<ProviderId>,
5287 api_type: LlmProtocol,
5288 base_url: impl Into<String>,
5289 ) -> Self {
5290 Self {
5291 provider_id: provider_id.into(),
5292 api_type,
5293 base_url: base_url.into(),
5294 headers: IndexMap::new(),
5295 meta: None,
5296 }
5297 }
5298
5299 #[must_use]
5302 pub fn headers(mut self, headers: IndexMap<String, String>) -> Self {
5303 self.headers = headers;
5304 self
5305 }
5306
5307 #[must_use]
5313 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5314 self.meta = meta.into_option();
5315 self
5316 }
5317}
5318
5319#[cfg(feature = "unstable_llm_providers")]
5320crate::serde_util::default_on_null! {
5321 #[serde_as]
5327 #[skip_serializing_none]
5328 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5329 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
5330 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_SET_METHOD_NAME)))]
5331 #[serde(rename_all = "camelCase")]
5332 #[non_exhaustive]
5333 pub struct SetProviderResponse {
5334 #[serde_as(deserialize_as = "DefaultOnError")]
5340 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5341 #[serde(default)]
5342 #[serde(rename = "_meta")]
5343 pub meta: Option<Meta>,
5344 }
5345}
5346
5347#[cfg(feature = "unstable_llm_providers")]
5348impl SetProviderResponse {
5349 #[must_use]
5351 pub fn new() -> Self {
5352 Self::default()
5353 }
5354
5355 #[must_use]
5361 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5362 self.meta = meta.into_option();
5363 self
5364 }
5365}
5366
5367#[cfg(feature = "unstable_llm_providers")]
5373#[serde_as]
5374#[skip_serializing_none]
5375#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5376#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5377#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_DISABLE_METHOD_NAME)))]
5378#[serde(rename_all = "camelCase")]
5379#[non_exhaustive]
5380pub struct DisableProviderRequest {
5381 pub provider_id: ProviderId,
5383 #[serde_as(deserialize_as = "DefaultOnError")]
5389 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5390 #[serde(default)]
5391 #[serde(rename = "_meta")]
5392 pub meta: Option<Meta>,
5393}
5394
5395#[cfg(feature = "unstable_llm_providers")]
5396impl DisableProviderRequest {
5397 #[must_use]
5399 pub fn new(provider_id: impl Into<ProviderId>) -> Self {
5400 Self {
5401 provider_id: provider_id.into(),
5402 meta: None,
5403 }
5404 }
5405
5406 #[must_use]
5412 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5413 self.meta = meta.into_option();
5414 self
5415 }
5416}
5417
5418#[cfg(feature = "unstable_llm_providers")]
5419crate::serde_util::default_on_null! {
5420 #[serde_as]
5426 #[skip_serializing_none]
5427 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5428 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
5429 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_DISABLE_METHOD_NAME)))]
5430 #[serde(rename_all = "camelCase")]
5431 #[non_exhaustive]
5432 pub struct DisableProviderResponse {
5433 #[serde_as(deserialize_as = "DefaultOnError")]
5439 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5440 #[serde(default)]
5441 #[serde(rename = "_meta")]
5442 pub meta: Option<Meta>,
5443 }
5444}
5445
5446#[cfg(feature = "unstable_llm_providers")]
5447impl DisableProviderResponse {
5448 #[must_use]
5450 pub fn new() -> Self {
5451 Self::default()
5452 }
5453
5454 #[must_use]
5460 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5461 self.meta = meta.into_option();
5462 self
5463 }
5464}
5465
5466#[serde_as]
5475#[skip_serializing_none]
5476#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5477#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5478#[serde(rename_all = "camelCase")]
5479#[non_exhaustive]
5480pub struct AgentCapabilities {
5481 #[serde_as(deserialize_as = "DefaultOnError")]
5483 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5484 #[serde(default)]
5485 pub load_session: bool,
5486 #[serde_as(deserialize_as = "DefaultOnError")]
5488 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5489 #[serde(default)]
5490 pub prompt_capabilities: PromptCapabilities,
5491 #[serde_as(deserialize_as = "DefaultOnError")]
5493 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5494 #[serde(default)]
5495 pub mcp_capabilities: McpCapabilities,
5496 #[serde_as(deserialize_as = "DefaultOnError")]
5498 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5499 #[serde(default)]
5500 pub session_capabilities: SessionCapabilities,
5501 #[serde_as(deserialize_as = "DefaultOnError")]
5503 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5504 #[serde(default)]
5505 pub auth: AgentAuthCapabilities,
5506 #[cfg(feature = "unstable_llm_providers")]
5515 #[serde_as(deserialize_as = "DefaultOnError")]
5516 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5517 #[serde(default)]
5518 pub providers: Option<ProvidersCapabilities>,
5519 #[serde_as(deserialize_as = "DefaultOnError")]
5525 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5526 #[serde(default)]
5527 #[serde(rename = "_meta")]
5528 pub meta: Option<Meta>,
5529}
5530
5531impl AgentCapabilities {
5532 #[must_use]
5534 pub fn new() -> Self {
5535 Self::default()
5536 }
5537
5538 #[must_use]
5540 pub fn load_session(mut self, load_session: bool) -> Self {
5541 self.load_session = load_session;
5542 self
5543 }
5544
5545 #[must_use]
5547 pub fn prompt_capabilities(mut self, prompt_capabilities: PromptCapabilities) -> Self {
5548 self.prompt_capabilities = prompt_capabilities;
5549 self
5550 }
5551
5552 #[must_use]
5554 pub fn mcp_capabilities(mut self, mcp_capabilities: McpCapabilities) -> Self {
5555 self.mcp_capabilities = mcp_capabilities;
5556 self
5557 }
5558
5559 #[must_use]
5561 pub fn session_capabilities(mut self, session_capabilities: SessionCapabilities) -> Self {
5562 self.session_capabilities = session_capabilities;
5563 self
5564 }
5565
5566 #[must_use]
5568 pub fn auth(mut self, auth: AgentAuthCapabilities) -> Self {
5569 self.auth = auth;
5570 self
5571 }
5572
5573 #[cfg(feature = "unstable_llm_providers")]
5579 #[must_use]
5580 pub fn providers(mut self, providers: impl IntoOption<ProvidersCapabilities>) -> Self {
5581 self.providers = providers.into_option();
5582 self
5583 }
5584
5585 #[must_use]
5591 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5592 self.meta = meta.into_option();
5593 self
5594 }
5595}
5596
5597#[cfg(feature = "unstable_llm_providers")]
5605#[serde_as]
5606#[skip_serializing_none]
5607#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5608#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5609#[non_exhaustive]
5610pub struct ProvidersCapabilities {
5611 #[serde_as(deserialize_as = "DefaultOnError")]
5617 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5618 #[serde(default)]
5619 #[serde(rename = "_meta")]
5620 pub meta: Option<Meta>,
5621}
5622
5623#[cfg(feature = "unstable_llm_providers")]
5624impl ProvidersCapabilities {
5625 #[must_use]
5627 pub fn new() -> Self {
5628 Self::default()
5629 }
5630
5631 #[must_use]
5637 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5638 self.meta = meta.into_option();
5639 self
5640 }
5641}
5642
5643#[serde_as]
5653#[skip_serializing_none]
5654#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5655#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5656#[serde(rename_all = "camelCase")]
5657#[non_exhaustive]
5658pub struct SessionCapabilities {
5659 #[serde_as(deserialize_as = "DefaultOnError")]
5664 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5665 #[serde(default)]
5666 pub list: Option<SessionListCapabilities>,
5667 #[serde_as(deserialize_as = "DefaultOnError")]
5672 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5673 #[serde(default)]
5674 pub delete: Option<SessionDeleteCapabilities>,
5675 #[serde_as(deserialize_as = "DefaultOnError")]
5685 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5686 #[serde(default)]
5687 pub additional_directories: Option<SessionAdditionalDirectoriesCapabilities>,
5688 #[serde_as(deserialize_as = "DefaultOnError")]
5693 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5694 #[serde(default)]
5695 pub system_prompt: Option<SessionSystemPromptCapabilities>,
5696 #[cfg(feature = "unstable_session_fork")]
5705 #[serde_as(deserialize_as = "DefaultOnError")]
5706 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5707 #[serde(default)]
5708 pub fork: Option<SessionForkCapabilities>,
5709 #[cfg(feature = "unstable_session_archive")]
5719 #[serde_as(deserialize_as = "DefaultOnError")]
5720 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5721 #[serde(default)]
5722 pub archive: Option<SessionArchiveCapabilities>,
5723 #[cfg(feature = "unstable_session_status")]
5732 #[serde_as(deserialize_as = "DefaultOnError")]
5733 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5734 #[serde(default)]
5735 pub status: Option<SessionStatusCapabilities>,
5736 #[cfg(feature = "unstable_session_options")]
5746 #[serde_as(deserialize_as = "DefaultOnError")]
5747 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5748 #[serde(default)]
5749 pub options: Option<SessionOptionsCapabilities>,
5750 #[cfg(feature = "unstable_session_set_title")]
5762 #[serde_as(deserialize_as = "DefaultOnError")]
5763 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5764 #[serde(default)]
5765 pub title: Option<SessionTitleCapabilities>,
5766 #[serde_as(deserialize_as = "DefaultOnError")]
5771 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5772 #[serde(default)]
5773 pub resume: Option<SessionResumeCapabilities>,
5774 #[serde_as(deserialize_as = "DefaultOnError")]
5779 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5780 #[serde(default)]
5781 pub close: Option<SessionCloseCapabilities>,
5782 #[serde_as(deserialize_as = "DefaultOnError")]
5788 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5789 #[serde(default)]
5790 #[serde(rename = "_meta")]
5791 pub meta: Option<Meta>,
5792}
5793
5794impl SessionCapabilities {
5795 #[must_use]
5797 pub fn new() -> Self {
5798 Self::default()
5799 }
5800
5801 #[must_use]
5806 pub fn list(mut self, list: impl IntoOption<SessionListCapabilities>) -> Self {
5807 self.list = list.into_option();
5808 self
5809 }
5810
5811 #[must_use]
5816 pub fn delete(mut self, delete: impl IntoOption<SessionDeleteCapabilities>) -> Self {
5817 self.delete = delete.into_option();
5818 self
5819 }
5820
5821 #[must_use]
5831 pub fn additional_directories(
5832 mut self,
5833 additional_directories: impl IntoOption<SessionAdditionalDirectoriesCapabilities>,
5834 ) -> Self {
5835 self.additional_directories = additional_directories.into_option();
5836 self
5837 }
5838
5839 #[must_use]
5844 pub fn system_prompt(
5845 mut self,
5846 system_prompt: impl IntoOption<SessionSystemPromptCapabilities>,
5847 ) -> Self {
5848 self.system_prompt = system_prompt.into_option();
5849 self
5850 }
5851
5852 #[cfg(feature = "unstable_session_fork")]
5853 #[must_use]
5858 pub fn fork(mut self, fork: impl IntoOption<SessionForkCapabilities>) -> Self {
5859 self.fork = fork.into_option();
5860 self
5861 }
5862
5863 #[cfg(feature = "unstable_session_archive")]
5873 #[must_use]
5874 pub fn archive(mut self, archive: impl IntoOption<SessionArchiveCapabilities>) -> Self {
5875 self.archive = archive.into_option();
5876 self
5877 }
5878
5879 #[cfg(feature = "unstable_session_status")]
5888 #[must_use]
5889 pub fn status(mut self, status: impl IntoOption<SessionStatusCapabilities>) -> Self {
5890 self.status = status.into_option();
5891 self
5892 }
5893
5894 #[cfg(feature = "unstable_session_options")]
5904 #[must_use]
5905 pub fn options(mut self, options: impl IntoOption<SessionOptionsCapabilities>) -> Self {
5906 self.options = options.into_option();
5907 self
5908 }
5909
5910 #[cfg(feature = "unstable_session_set_title")]
5922 #[must_use]
5923 pub fn title(mut self, title: impl IntoOption<SessionTitleCapabilities>) -> Self {
5924 self.title = title.into_option();
5925 self
5926 }
5927
5928 #[must_use]
5933 pub fn resume(mut self, resume: impl IntoOption<SessionResumeCapabilities>) -> Self {
5934 self.resume = resume.into_option();
5935 self
5936 }
5937
5938 #[must_use]
5943 pub fn close(mut self, close: impl IntoOption<SessionCloseCapabilities>) -> Self {
5944 self.close = close.into_option();
5945 self
5946 }
5947
5948 #[must_use]
5954 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5955 self.meta = meta.into_option();
5956 self
5957 }
5958}
5959
5960#[serde_as]
5964#[skip_serializing_none]
5965#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5966#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5967#[non_exhaustive]
5968pub struct SessionListCapabilities {
5969 #[serde_as(deserialize_as = "DefaultOnError")]
5975 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5976 #[serde(default)]
5977 #[serde(rename = "_meta")]
5978 pub meta: Option<Meta>,
5979}
5980
5981impl SessionListCapabilities {
5982 #[must_use]
5984 pub fn new() -> Self {
5985 Self::default()
5986 }
5987
5988 #[must_use]
5994 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5995 self.meta = meta.into_option();
5996 self
5997 }
5998}
5999
6000#[serde_as]
6004#[skip_serializing_none]
6005#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6006#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6007#[non_exhaustive]
6008pub struct SessionDeleteCapabilities {
6009 #[serde_as(deserialize_as = "DefaultOnError")]
6015 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6016 #[serde(default)]
6017 #[serde(rename = "_meta")]
6018 pub meta: Option<Meta>,
6019}
6020
6021impl SessionDeleteCapabilities {
6022 #[must_use]
6024 pub fn new() -> Self {
6025 Self::default()
6026 }
6027
6028 #[must_use]
6034 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6035 self.meta = meta.into_option();
6036 self
6037 }
6038}
6039
6040#[serde_as]
6047#[skip_serializing_none]
6048#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6049#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6050#[non_exhaustive]
6051pub struct SessionAdditionalDirectoriesCapabilities {
6052 #[serde_as(deserialize_as = "DefaultOnError")]
6058 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6059 #[serde(default)]
6060 #[serde(rename = "_meta")]
6061 pub meta: Option<Meta>,
6062}
6063
6064impl SessionAdditionalDirectoriesCapabilities {
6065 #[must_use]
6067 pub fn new() -> Self {
6068 Self::default()
6069 }
6070
6071 #[must_use]
6077 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6078 self.meta = meta.into_option();
6079 self
6080 }
6081}
6082
6083#[serde_as]
6088#[skip_serializing_none]
6089#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6090#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6091#[serde(rename_all = "camelCase")]
6092#[non_exhaustive]
6093pub struct SessionSystemPromptCapabilities {
6094 #[serde_as(deserialize_as = "DefaultOnError")]
6098 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6099 #[serde(default)]
6100 pub mode: Option<SessionSystemPromptModeCapabilities>,
6101 #[serde_as(deserialize_as = "DefaultOnError")]
6107 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6108 #[serde(default)]
6109 #[serde(rename = "_meta")]
6110 pub meta: Option<Meta>,
6111}
6112
6113impl SessionSystemPromptCapabilities {
6114 #[must_use]
6116 pub fn new() -> Self {
6117 Self::default()
6118 }
6119
6120 #[must_use]
6124 pub fn mode(mut self, mode: impl IntoOption<SessionSystemPromptModeCapabilities>) -> Self {
6125 self.mode = mode.into_option();
6126 self
6127 }
6128
6129 #[must_use]
6135 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6136 self.meta = meta.into_option();
6137 self
6138 }
6139}
6140
6141#[serde_as]
6146#[skip_serializing_none]
6147#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6148#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6149#[serde(rename_all = "camelCase")]
6150#[non_exhaustive]
6151pub struct SessionSystemPromptModeCapabilities {
6152 #[serde_as(deserialize_as = "DefaultOnError")]
6158 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6159 #[serde(default, rename = "override")]
6160 pub override_: Option<SessionSystemPromptOverrideCapabilities>,
6161 #[serde_as(deserialize_as = "DefaultOnError")]
6167 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6168 #[serde(default)]
6169 #[serde(rename = "_meta")]
6170 pub meta: Option<Meta>,
6171}
6172
6173impl SessionSystemPromptModeCapabilities {
6174 #[must_use]
6176 pub fn new() -> Self {
6177 Self::default()
6178 }
6179
6180 #[must_use]
6186 pub fn override_(
6187 mut self,
6188 override_: impl IntoOption<SessionSystemPromptOverrideCapabilities>,
6189 ) -> Self {
6190 self.override_ = override_.into_option();
6191 self
6192 }
6193
6194 #[must_use]
6200 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6201 self.meta = meta.into_option();
6202 self
6203 }
6204}
6205
6206#[serde_as]
6211#[skip_serializing_none]
6212#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6213#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6214#[non_exhaustive]
6215pub struct SessionSystemPromptOverrideCapabilities {
6216 #[serde_as(deserialize_as = "DefaultOnError")]
6222 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6223 #[serde(default)]
6224 #[serde(rename = "_meta")]
6225 pub meta: Option<Meta>,
6226}
6227
6228impl SessionSystemPromptOverrideCapabilities {
6229 #[must_use]
6231 pub fn new() -> Self {
6232 Self::default()
6233 }
6234
6235 #[must_use]
6241 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6242 self.meta = meta.into_option();
6243 self
6244 }
6245}
6246
6247#[cfg(feature = "unstable_session_fork")]
6255#[serde_as]
6256#[skip_serializing_none]
6257#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6258#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6259#[non_exhaustive]
6260pub struct SessionForkCapabilities {
6261 #[serde_as(deserialize_as = "DefaultOnError")]
6267 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6268 #[serde(default)]
6269 #[serde(rename = "_meta")]
6270 pub meta: Option<Meta>,
6271}
6272
6273#[cfg(feature = "unstable_session_fork")]
6274impl SessionForkCapabilities {
6275 #[must_use]
6277 pub fn new() -> Self {
6278 Self::default()
6279 }
6280
6281 #[must_use]
6287 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6288 self.meta = meta.into_option();
6289 self
6290 }
6291}
6292
6293#[cfg(feature = "unstable_session_archive")]
6302#[serde_as]
6303#[skip_serializing_none]
6304#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6305#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6306#[non_exhaustive]
6307pub struct SessionArchiveCapabilities {
6308 #[serde_as(deserialize_as = "DefaultOnError")]
6314 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6315 #[serde(default)]
6316 #[serde(rename = "_meta")]
6317 pub meta: Option<Meta>,
6318}
6319
6320#[cfg(feature = "unstable_session_archive")]
6321impl SessionArchiveCapabilities {
6322 #[must_use]
6324 pub fn new() -> Self {
6325 Self::default()
6326 }
6327
6328 #[must_use]
6334 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6335 self.meta = meta.into_option();
6336 self
6337 }
6338}
6339
6340#[cfg(feature = "unstable_session_status")]
6348#[serde_as]
6349#[skip_serializing_none]
6350#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6351#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6352#[non_exhaustive]
6353pub struct SessionStatusCapabilities {
6354 #[serde_as(deserialize_as = "DefaultOnError")]
6360 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6361 #[serde(default)]
6362 #[serde(rename = "_meta")]
6363 pub meta: Option<Meta>,
6364}
6365
6366#[cfg(feature = "unstable_session_status")]
6367impl SessionStatusCapabilities {
6368 #[must_use]
6370 pub fn new() -> Self {
6371 Self::default()
6372 }
6373
6374 #[must_use]
6380 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6381 self.meta = meta.into_option();
6382 self
6383 }
6384}
6385
6386#[cfg(feature = "unstable_session_options")]
6395#[serde_as]
6396#[skip_serializing_none]
6397#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6398#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6399#[non_exhaustive]
6400pub struct SessionOptionsCapabilities {
6401 #[serde_as(deserialize_as = "DefaultOnError")]
6407 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6408 #[serde(default)]
6409 #[serde(rename = "_meta")]
6410 pub meta: Option<Meta>,
6411}
6412
6413#[cfg(feature = "unstable_session_options")]
6414impl SessionOptionsCapabilities {
6415 #[must_use]
6417 pub fn new() -> Self {
6418 Self::default()
6419 }
6420
6421 #[must_use]
6427 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6428 self.meta = meta.into_option();
6429 self
6430 }
6431}
6432
6433#[cfg(feature = "unstable_session_set_title")]
6442#[serde_as]
6443#[skip_serializing_none]
6444#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6445#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6446#[non_exhaustive]
6447pub struct SessionTitleCapabilities {
6448 #[serde_as(deserialize_as = "DefaultOnError")]
6454 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6455 #[serde(default)]
6456 #[serde(rename = "_meta")]
6457 pub meta: Option<Meta>,
6458}
6459
6460#[cfg(feature = "unstable_session_set_title")]
6461impl SessionTitleCapabilities {
6462 #[must_use]
6464 pub fn new() -> Self {
6465 Self::default()
6466 }
6467
6468 #[must_use]
6474 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6475 self.meta = meta.into_option();
6476 self
6477 }
6478}
6479
6480#[serde_as]
6484#[skip_serializing_none]
6485#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6486#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6487#[non_exhaustive]
6488pub struct SessionResumeCapabilities {
6489 #[serde_as(deserialize_as = "DefaultOnError")]
6495 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6496 #[serde(default)]
6497 #[serde(rename = "_meta")]
6498 pub meta: Option<Meta>,
6499}
6500
6501impl SessionResumeCapabilities {
6502 #[must_use]
6504 pub fn new() -> Self {
6505 Self::default()
6506 }
6507
6508 #[must_use]
6514 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6515 self.meta = meta.into_option();
6516 self
6517 }
6518}
6519
6520#[serde_as]
6524#[skip_serializing_none]
6525#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6526#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6527#[non_exhaustive]
6528pub struct SessionCloseCapabilities {
6529 #[serde_as(deserialize_as = "DefaultOnError")]
6535 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6536 #[serde(default)]
6537 #[serde(rename = "_meta")]
6538 pub meta: Option<Meta>,
6539}
6540
6541impl SessionCloseCapabilities {
6542 #[must_use]
6544 pub fn new() -> Self {
6545 Self::default()
6546 }
6547
6548 #[must_use]
6554 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6555 self.meta = meta.into_option();
6556 self
6557 }
6558}
6559
6560#[serde_as]
6573#[skip_serializing_none]
6574#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6575#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6576#[serde(rename_all = "camelCase")]
6577#[non_exhaustive]
6578pub struct PromptCapabilities {
6579 #[serde_as(deserialize_as = "DefaultOnError")]
6581 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6582 #[serde(default)]
6583 pub image: bool,
6584 #[serde_as(deserialize_as = "DefaultOnError")]
6586 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6587 #[serde(default)]
6588 pub audio: bool,
6589 #[serde_as(deserialize_as = "DefaultOnError")]
6594 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6595 #[serde(default)]
6596 pub embedded_context: bool,
6597 #[serde_as(deserialize_as = "DefaultOnError")]
6603 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6604 #[serde(default)]
6605 #[serde(rename = "_meta")]
6606 pub meta: Option<Meta>,
6607}
6608
6609impl PromptCapabilities {
6610 #[must_use]
6612 pub fn new() -> Self {
6613 Self::default()
6614 }
6615
6616 #[must_use]
6618 pub fn image(mut self, image: bool) -> Self {
6619 self.image = image;
6620 self
6621 }
6622
6623 #[must_use]
6625 pub fn audio(mut self, audio: bool) -> Self {
6626 self.audio = audio;
6627 self
6628 }
6629
6630 #[must_use]
6635 pub fn embedded_context(mut self, embedded_context: bool) -> Self {
6636 self.embedded_context = embedded_context;
6637 self
6638 }
6639
6640 #[must_use]
6646 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6647 self.meta = meta.into_option();
6648 self
6649 }
6650}
6651
6652#[serde_as]
6654#[skip_serializing_none]
6655#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6656#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6657#[serde(rename_all = "camelCase")]
6658#[non_exhaustive]
6659pub struct McpCapabilities {
6660 #[serde_as(deserialize_as = "DefaultOnError")]
6662 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6663 #[serde(default)]
6664 pub http: bool,
6665 #[serde_as(deserialize_as = "DefaultOnError")]
6667 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6668 #[serde(default)]
6669 pub sse: bool,
6670 #[cfg(feature = "unstable_mcp_over_acp")]
6676 #[serde_as(deserialize_as = "DefaultOnError")]
6677 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6678 #[serde(default)]
6679 pub acp: bool,
6680 #[serde_as(deserialize_as = "DefaultOnError")]
6686 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6687 #[serde(default)]
6688 #[serde(rename = "_meta")]
6689 pub meta: Option<Meta>,
6690}
6691
6692impl McpCapabilities {
6693 #[must_use]
6695 pub fn new() -> Self {
6696 Self::default()
6697 }
6698
6699 #[must_use]
6701 pub fn http(mut self, http: bool) -> Self {
6702 self.http = http;
6703 self
6704 }
6705
6706 #[must_use]
6708 pub fn sse(mut self, sse: bool) -> Self {
6709 self.sse = sse;
6710 self
6711 }
6712
6713 #[cfg(feature = "unstable_mcp_over_acp")]
6719 #[must_use]
6720 pub fn acp(mut self, acp: bool) -> Self {
6721 self.acp = acp;
6722 self
6723 }
6724
6725 #[must_use]
6731 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6732 self.meta = meta.into_option();
6733 self
6734 }
6735}
6736
6737#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6743#[non_exhaustive]
6744pub struct AgentMethodNames {
6745 pub initialize: &'static str,
6747 pub authenticate: &'static str,
6749 #[cfg(feature = "unstable_llm_providers")]
6751 pub providers_list: &'static str,
6752 #[cfg(feature = "unstable_llm_providers")]
6754 pub providers_set: &'static str,
6755 #[cfg(feature = "unstable_llm_providers")]
6757 pub providers_disable: &'static str,
6758 pub session_new: &'static str,
6760 pub session_load: &'static str,
6762 pub session_set_mode: &'static str,
6764 pub session_set_config_option: &'static str,
6766 pub session_prompt: &'static str,
6768 pub session_cancel: &'static str,
6770 #[cfg(feature = "unstable_mcp_over_acp")]
6772 pub mcp_message: &'static str,
6773 pub session_list: &'static str,
6775 pub session_delete: &'static str,
6777 #[cfg(feature = "unstable_session_fork")]
6779 pub session_fork: &'static str,
6780 #[cfg(feature = "unstable_session_archive")]
6782 pub session_archive: &'static str,
6783 #[cfg(feature = "unstable_session_archive")]
6785 pub session_unarchive: &'static str,
6786 #[cfg(feature = "unstable_session_status")]
6788 pub session_status: &'static str,
6789 #[cfg(feature = "unstable_session_options")]
6791 pub session_options: &'static str,
6792 #[cfg(feature = "unstable_session_set_title")]
6794 pub session_set_title: &'static str,
6795 pub session_resume: &'static str,
6797 pub session_close: &'static str,
6799 pub logout: &'static str,
6801 #[cfg(feature = "unstable_auth_status")]
6803 pub auth_status: &'static str,
6804}
6805
6806pub const AGENT_METHOD_NAMES: AgentMethodNames = AgentMethodNames {
6808 initialize: INITIALIZE_METHOD_NAME,
6809 authenticate: AUTHENTICATE_METHOD_NAME,
6810 #[cfg(feature = "unstable_llm_providers")]
6811 providers_list: PROVIDERS_LIST_METHOD_NAME,
6812 #[cfg(feature = "unstable_llm_providers")]
6813 providers_set: PROVIDERS_SET_METHOD_NAME,
6814 #[cfg(feature = "unstable_llm_providers")]
6815 providers_disable: PROVIDERS_DISABLE_METHOD_NAME,
6816 session_new: SESSION_NEW_METHOD_NAME,
6817 session_load: SESSION_LOAD_METHOD_NAME,
6818 session_set_mode: SESSION_SET_MODE_METHOD_NAME,
6819 session_set_config_option: SESSION_SET_CONFIG_OPTION_METHOD_NAME,
6820 session_prompt: SESSION_PROMPT_METHOD_NAME,
6821 session_cancel: SESSION_CANCEL_METHOD_NAME,
6822 #[cfg(feature = "unstable_mcp_over_acp")]
6823 mcp_message: MCP_MESSAGE_METHOD_NAME,
6824 session_list: SESSION_LIST_METHOD_NAME,
6825 session_delete: SESSION_DELETE_METHOD_NAME,
6826 #[cfg(feature = "unstable_session_fork")]
6827 session_fork: SESSION_FORK_METHOD_NAME,
6828 #[cfg(feature = "unstable_session_archive")]
6829 session_archive: SESSION_ARCHIVE_METHOD_NAME,
6830 #[cfg(feature = "unstable_session_archive")]
6831 session_unarchive: SESSION_UNARCHIVE_METHOD_NAME,
6832 #[cfg(feature = "unstable_session_status")]
6833 session_status: SESSION_STATUS_METHOD_NAME,
6834 #[cfg(feature = "unstable_session_options")]
6835 session_options: SESSION_OPTIONS_METHOD_NAME,
6836 #[cfg(feature = "unstable_session_set_title")]
6837 session_set_title: SESSION_SET_TITLE_METHOD_NAME,
6838 session_resume: SESSION_RESUME_METHOD_NAME,
6839 session_close: SESSION_CLOSE_METHOD_NAME,
6840 logout: LOGOUT_METHOD_NAME,
6841 #[cfg(feature = "unstable_auth_status")]
6842 auth_status: AUTH_STATUS_METHOD_NAME,
6843};
6844
6845pub(crate) const INITIALIZE_METHOD_NAME: &str = "initialize";
6847pub(crate) const AUTHENTICATE_METHOD_NAME: &str = "authenticate";
6849#[cfg(feature = "unstable_llm_providers")]
6851pub(crate) const PROVIDERS_LIST_METHOD_NAME: &str = "providers/list";
6852#[cfg(feature = "unstable_llm_providers")]
6854pub(crate) const PROVIDERS_SET_METHOD_NAME: &str = "providers/set";
6855#[cfg(feature = "unstable_llm_providers")]
6857pub(crate) const PROVIDERS_DISABLE_METHOD_NAME: &str = "providers/disable";
6858pub(crate) const SESSION_NEW_METHOD_NAME: &str = "session/new";
6860pub(crate) const SESSION_LOAD_METHOD_NAME: &str = "session/load";
6862pub(crate) const SESSION_SET_MODE_METHOD_NAME: &str = "session/set_mode";
6864pub(crate) const SESSION_SET_CONFIG_OPTION_METHOD_NAME: &str = "session/set_config_option";
6866pub(crate) const SESSION_PROMPT_METHOD_NAME: &str = "session/prompt";
6868pub(crate) const SESSION_CANCEL_METHOD_NAME: &str = "session/cancel";
6870pub(crate) const SESSION_LIST_METHOD_NAME: &str = "session/list";
6872pub(crate) const SESSION_DELETE_METHOD_NAME: &str = "session/delete";
6874#[cfg(feature = "unstable_session_fork")]
6876pub(crate) const SESSION_FORK_METHOD_NAME: &str = "session/fork";
6877#[cfg(feature = "unstable_session_archive")]
6879pub(crate) const SESSION_ARCHIVE_METHOD_NAME: &str = "session/archive";
6880#[cfg(feature = "unstable_session_archive")]
6882pub(crate) const SESSION_UNARCHIVE_METHOD_NAME: &str = "session/unarchive";
6883#[cfg(feature = "unstable_session_status")]
6885pub(crate) const SESSION_STATUS_METHOD_NAME: &str = "session/status";
6886#[cfg(feature = "unstable_session_options")]
6888pub(crate) const SESSION_OPTIONS_METHOD_NAME: &str = "session/options";
6889#[cfg(feature = "unstable_session_set_title")]
6891pub(crate) const SESSION_SET_TITLE_METHOD_NAME: &str = "session/set_title";
6892pub(crate) const SESSION_RESUME_METHOD_NAME: &str = "session/resume";
6894pub(crate) const SESSION_CLOSE_METHOD_NAME: &str = "session/close";
6896pub(crate) const LOGOUT_METHOD_NAME: &str = "logout";
6898#[cfg(feature = "unstable_auth_status")]
6900pub(crate) const AUTH_STATUS_METHOD_NAME: &str = "auth/status";
6901
6902#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6909#[derive(Clone, Debug, Serialize, Deserialize)]
6910#[serde(untagged)]
6911#[cfg_attr(feature = "schemars", schemars(inline))]
6912#[non_exhaustive]
6913#[expect(
6914 clippy::large_enum_variant,
6915 reason = "TODO(next major): box InitializeRequest in the v1 enum"
6916)]
6917pub enum ClientRequest {
6918 InitializeRequest(InitializeRequest),
6929 AuthenticateRequest(AuthenticateRequest),
6940 #[cfg(feature = "unstable_llm_providers")]
6946 ListProvidersRequest(ListProvidersRequest),
6947 #[cfg(feature = "unstable_llm_providers")]
6953 SetProviderRequest(SetProviderRequest),
6954 #[cfg(feature = "unstable_llm_providers")]
6960 DisableProviderRequest(DisableProviderRequest),
6961 LogoutRequest(LogoutRequest),
6966 #[cfg(feature = "unstable_auth_status")]
6975 AuthStatusRequest(AuthStatusRequest),
6976 NewSessionRequest(NewSessionRequest),
6989 LoadSessionRequest(LoadSessionRequest),
7000 ListSessionsRequest(ListSessionsRequest),
7006 DeleteSessionRequest(DeleteSessionRequest),
7010 #[cfg(feature = "unstable_session_fork")]
7011 ForkSessionRequest(ForkSessionRequest),
7027 #[cfg(feature = "unstable_session_archive")]
7028 ArchiveSessionRequest(ArchiveSessionRequest),
7036 #[cfg(feature = "unstable_session_archive")]
7037 UnarchiveSessionRequest(UnarchiveSessionRequest),
7045 #[cfg(feature = "unstable_session_status")]
7046 SessionStatusRequest(SessionStatusRequest),
7054 #[cfg(feature = "unstable_session_options")]
7055 SessionOptionsRequest(SessionOptionsRequest),
7063 #[cfg(feature = "unstable_session_set_title")]
7064 SetSessionTitleRequest(SetSessionTitleRequest),
7075 ResumeSessionRequest(ResumeSessionRequest),
7082 CloseSessionRequest(CloseSessionRequest),
7089 SetSessionModeRequest(SetSessionModeRequest),
7103 SetSessionConfigOptionRequest(SetSessionConfigOptionRequest),
7105 PromptRequest(PromptRequest),
7117 ExtMethodRequest(ExtRequest),
7124}
7125
7126impl_request_dispatch! {
7127 ClientRequest => AgentResponse {
7128 InitializeRequest => InitializeResponse: AGENT_METHOD_NAMES.initialize,
7129 AuthenticateRequest => AuthenticateResponse: AGENT_METHOD_NAMES.authenticate,
7130 #[cfg(feature = "unstable_llm_providers")]
7131 ListProvidersRequest => ListProvidersResponse: AGENT_METHOD_NAMES.providers_list,
7132 #[cfg(feature = "unstable_llm_providers")]
7133 SetProviderRequest => SetProviderResponse: AGENT_METHOD_NAMES.providers_set,
7134 #[cfg(feature = "unstable_llm_providers")]
7135 DisableProviderRequest => DisableProviderResponse: AGENT_METHOD_NAMES.providers_disable,
7136 LogoutRequest => LogoutResponse: AGENT_METHOD_NAMES.logout,
7137 #[cfg(feature = "unstable_auth_status")]
7138 AuthStatusRequest => AuthStatusResponse: AGENT_METHOD_NAMES.auth_status,
7139 NewSessionRequest => NewSessionResponse: AGENT_METHOD_NAMES.session_new,
7140 LoadSessionRequest => LoadSessionResponse: AGENT_METHOD_NAMES.session_load,
7141 ListSessionsRequest => ListSessionsResponse: AGENT_METHOD_NAMES.session_list,
7142 DeleteSessionRequest => DeleteSessionResponse: AGENT_METHOD_NAMES.session_delete,
7143 #[cfg(feature = "unstable_session_fork")]
7144 ForkSessionRequest => ForkSessionResponse: AGENT_METHOD_NAMES.session_fork,
7145 #[cfg(feature = "unstable_session_archive")]
7146 ArchiveSessionRequest => ArchiveSessionResponse: AGENT_METHOD_NAMES.session_archive,
7147 #[cfg(feature = "unstable_session_archive")]
7148 UnarchiveSessionRequest => UnarchiveSessionResponse: AGENT_METHOD_NAMES.session_unarchive,
7149 #[cfg(feature = "unstable_session_status")]
7150 SessionStatusRequest => SessionStatusResponse: AGENT_METHOD_NAMES.session_status,
7151 #[cfg(feature = "unstable_session_options")]
7152 SessionOptionsRequest => SessionOptionsResponse: AGENT_METHOD_NAMES.session_options,
7153 #[cfg(feature = "unstable_session_set_title")]
7154 SetSessionTitleRequest => SetSessionTitleResponse: AGENT_METHOD_NAMES.session_set_title,
7155 ResumeSessionRequest => ResumeSessionResponse: AGENT_METHOD_NAMES.session_resume,
7156 CloseSessionRequest => CloseSessionResponse: AGENT_METHOD_NAMES.session_close,
7157 SetSessionModeRequest => SetSessionModeResponse: AGENT_METHOD_NAMES.session_set_mode,
7158 SetSessionConfigOptionRequest => SetSessionConfigOptionResponse: AGENT_METHOD_NAMES.session_set_config_option,
7159 PromptRequest => PromptResponse: AGENT_METHOD_NAMES.session_prompt,
7160 }
7161 extension ExtMethodRequest(ExtRequest) => ExtMethodResponse;
7162}
7163
7164#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7171#[derive(Clone, Debug, Serialize, Deserialize)]
7172#[serde(untagged)]
7173#[cfg_attr(feature = "schemars", schemars(inline))]
7174#[non_exhaustive]
7175#[expect(
7176 clippy::large_enum_variant,
7177 reason = "TODO(next major): box InitializeResponse in the v1 enum"
7178)]
7179pub enum AgentResponse {
7180 InitializeResponse(InitializeResponse),
7182 AuthenticateResponse(#[serde(default)] AuthenticateResponse),
7184 #[cfg(feature = "unstable_llm_providers")]
7186 ListProvidersResponse(ListProvidersResponse),
7187 #[cfg(feature = "unstable_llm_providers")]
7189 SetProviderResponse(#[serde(default)] SetProviderResponse),
7190 #[cfg(feature = "unstable_llm_providers")]
7192 DisableProviderResponse(#[serde(default)] DisableProviderResponse),
7193 LogoutResponse(#[serde(default)] LogoutResponse),
7195 #[cfg(feature = "unstable_auth_status")]
7197 AuthStatusResponse(AuthStatusResponse),
7198 NewSessionResponse(NewSessionResponse),
7200 LoadSessionResponse(#[serde(default)] LoadSessionResponse),
7202 ListSessionsResponse(ListSessionsResponse),
7204 DeleteSessionResponse(#[serde(default)] DeleteSessionResponse),
7206 #[cfg(feature = "unstable_session_fork")]
7208 ForkSessionResponse(ForkSessionResponse),
7209 #[cfg(feature = "unstable_session_archive")]
7211 ArchiveSessionResponse(#[serde(default)] ArchiveSessionResponse),
7212 #[cfg(feature = "unstable_session_archive")]
7214 UnarchiveSessionResponse(#[serde(default)] UnarchiveSessionResponse),
7215 #[cfg(feature = "unstable_session_status")]
7217 SessionStatusResponse(SessionStatusResponse),
7218 #[cfg(feature = "unstable_session_options")]
7220 SessionOptionsResponse(#[serde(default)] SessionOptionsResponse),
7221 #[cfg(feature = "unstable_session_set_title")]
7223 SetSessionTitleResponse(SetSessionTitleResponse),
7224 ResumeSessionResponse(#[serde(default)] ResumeSessionResponse),
7226 CloseSessionResponse(#[serde(default)] CloseSessionResponse),
7228 SetSessionModeResponse(#[serde(default)] SetSessionModeResponse),
7230 SetSessionConfigOptionResponse(SetSessionConfigOptionResponse),
7232 PromptResponse(PromptResponse),
7234 ExtMethodResponse(ExtResponse),
7236}
7237
7238#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7245#[derive(Clone, Debug, Serialize, Deserialize)]
7246#[serde(untagged)]
7247#[cfg_attr(feature = "schemars", schemars(inline))]
7248#[non_exhaustive]
7249pub enum ClientNotification {
7250 CancelNotification(CancelNotification),
7262 #[cfg(feature = "unstable_mcp_over_acp")]
7268 MessageMcpNotification(MessageMcpNotification),
7269 ExtNotification(ExtNotification),
7276}
7277
7278impl_message_dispatch! {
7279 ClientNotification {
7280 CancelNotification => AGENT_METHOD_NAMES.session_cancel,
7281 #[cfg(feature = "unstable_mcp_over_acp")]
7282 MessageMcpNotification => AGENT_METHOD_NAMES.mcp_message,
7283 }
7284 extension ExtNotification(ExtNotification);
7285}
7286
7287#[serde_as]
7291#[skip_serializing_none]
7292#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7293#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7294#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_CANCEL_METHOD_NAME)))]
7295#[serde(rename_all = "camelCase")]
7296#[non_exhaustive]
7297pub struct CancelNotification {
7298 pub session_id: SessionId,
7300 #[serde_as(deserialize_as = "DefaultOnError")]
7306 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7307 #[serde(default)]
7308 #[serde(rename = "_meta")]
7309 pub meta: Option<Meta>,
7310}
7311
7312impl CancelNotification {
7313 #[must_use]
7315 pub fn new(session_id: impl Into<SessionId>) -> Self {
7316 Self {
7317 session_id: session_id.into(),
7318 meta: None,
7319 }
7320 }
7321
7322 #[must_use]
7328 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
7329 self.meta = meta.into_option();
7330 self
7331 }
7332}
7333
7334#[cfg(test)]
7335mod test_serialization {
7336 use super::*;
7337 use serde_json::json;
7338
7339 fn test_meta() -> Meta {
7340 json!({ "source": "test" }).as_object().unwrap().clone()
7341 }
7342
7343 fn serialized_meta_key_count(value: &impl serde::Serialize) -> usize {
7344 serde_json::to_string(value)
7345 .unwrap()
7346 .matches("\"_meta\"")
7347 .count()
7348 }
7349
7350 #[test]
7353 fn prompt_response_has_no_error_stop_reason() {
7354 assert_eq!(
7355 serde_json::from_value::<PromptResponse>(json!({ "stopReason": "end_turn" }))
7356 .unwrap()
7357 .stop_reason,
7358 StopReason::EndTurn
7359 );
7360 assert!(
7361 serde_json::from_value::<PromptResponse>(json!({ "stopReason": "error" })).is_err()
7362 );
7363 }
7364
7365 #[test]
7366 fn test_initialize_capabilities_default_on_malformed_values() {
7367 let request: InitializeRequest = serde_json::from_value(json!({
7368 "protocolVersion": 1,
7369 "clientCapabilities": false
7370 }))
7371 .unwrap();
7372 assert_eq!(request.client_capabilities, ClientCapabilities::default());
7373
7374 let response: InitializeResponse = serde_json::from_value(json!({
7375 "protocolVersion": 1,
7376 "agentCapabilities": false
7377 }))
7378 .unwrap();
7379 assert_eq!(response.agent_capabilities, AgentCapabilities::default());
7380 }
7381
7382 #[test]
7383 fn test_agent_capabilities_default_on_malformed_values() {
7384 let capabilities: AgentCapabilities = serde_json::from_value(json!({
7385 "loadSession": "yes",
7386 "promptCapabilities": {
7387 "image": "yes",
7388 "audio": true,
7389 "embeddedContext": {}
7390 },
7391 "mcpCapabilities": {
7392 "http": "yes",
7393 "sse": true
7394 },
7395 "sessionCapabilities": false,
7396 "auth": false
7397 }))
7398 .unwrap();
7399
7400 assert!(!capabilities.load_session);
7401 assert!(!capabilities.prompt_capabilities.image);
7402 assert!(capabilities.prompt_capabilities.audio);
7403 assert!(!capabilities.prompt_capabilities.embedded_context);
7404 assert!(!capabilities.mcp_capabilities.http);
7405 assert!(capabilities.mcp_capabilities.sse);
7406 assert_eq!(
7407 capabilities.session_capabilities,
7408 SessionCapabilities::default()
7409 );
7410 assert_eq!(capabilities.auth, AgentAuthCapabilities::default());
7411 }
7412
7413 #[test]
7414 fn test_mcp_server_stdio_serialization() {
7415 let server = McpServer::Stdio(
7416 McpServerStdio::new("test-server", "/usr/bin/server")
7417 .args(vec!["--port".to_string(), "3000".to_string()])
7418 .env(vec![EnvVariable::new("API_KEY", "secret123")]),
7419 );
7420
7421 let json = serde_json::to_value(&server).unwrap();
7422 assert_eq!(
7423 json,
7424 json!({
7425 "name": "test-server",
7426 "command": "/usr/bin/server",
7427 "args": ["--port", "3000"],
7428 "env": [
7429 {
7430 "name": "API_KEY",
7431 "value": "secret123"
7432 }
7433 ]
7434 })
7435 );
7436
7437 let deserialized: McpServer = serde_json::from_value(json).unwrap();
7438 match deserialized {
7439 McpServer::Stdio(McpServerStdio {
7440 name,
7441 command,
7442 args,
7443 env,
7444 meta: _,
7445 }) => {
7446 assert_eq!(name, "test-server");
7447 assert_eq!(command, PathBuf::from("/usr/bin/server"));
7448 assert_eq!(args, vec!["--port", "3000"]);
7449 assert_eq!(env.len(), 1);
7450 assert_eq!(env[0].name, "API_KEY");
7451 assert_eq!(env[0].value, "secret123");
7452 }
7453 _ => panic!("Expected Stdio variant"),
7454 }
7455 }
7456
7457 #[test]
7458 fn test_mcp_server_http_serialization() {
7459 let server = McpServer::Http(
7460 McpServerHttp::new("http-server", "https://api.example.com").headers(vec![
7461 HttpHeader::new("Authorization", "Bearer token123"),
7462 HttpHeader::new("Content-Type", "application/json"),
7463 ]),
7464 );
7465
7466 let json = serde_json::to_value(&server).unwrap();
7467 assert_eq!(
7468 json,
7469 json!({
7470 "type": "http",
7471 "name": "http-server",
7472 "url": "https://api.example.com",
7473 "headers": [
7474 {
7475 "name": "Authorization",
7476 "value": "Bearer token123"
7477 },
7478 {
7479 "name": "Content-Type",
7480 "value": "application/json"
7481 }
7482 ]
7483 })
7484 );
7485
7486 let deserialized: McpServer = serde_json::from_value(json).unwrap();
7487 match deserialized {
7488 McpServer::Http(McpServerHttp {
7489 name,
7490 url,
7491 headers,
7492 meta: _,
7493 }) => {
7494 assert_eq!(name, "http-server");
7495 assert_eq!(url, "https://api.example.com");
7496 assert_eq!(headers.len(), 2);
7497 assert_eq!(headers[0].name, "Authorization");
7498 assert_eq!(headers[0].value, "Bearer token123");
7499 assert_eq!(headers[1].name, "Content-Type");
7500 assert_eq!(headers[1].value, "application/json");
7501 }
7502 _ => panic!("Expected Http variant"),
7503 }
7504 }
7505
7506 #[cfg(feature = "unstable_mcp_over_acp")]
7507 #[test]
7508 fn test_mcp_server_acp_serialization() {
7509 let server = McpServer::Acp(McpServerAcp::new("project-tools", "project-tools-id"));
7510
7511 let json = serde_json::to_value(&server).unwrap();
7512 assert_eq!(
7513 json,
7514 json!({
7515 "type": "acp",
7516 "name": "project-tools",
7517 "serverId": "project-tools-id"
7518 })
7519 );
7520
7521 let deserialized: McpServer = serde_json::from_value(json).unwrap();
7522 match deserialized {
7523 McpServer::Acp(McpServerAcp {
7524 name,
7525 server_id: id,
7526 meta: _,
7527 }) => {
7528 assert_eq!(name, "project-tools");
7529 assert_eq!(id, McpServerAcpId::new("project-tools-id"));
7530 }
7531 _ => panic!("Expected Acp variant"),
7532 }
7533 }
7534
7535 #[cfg(feature = "unstable_mcp_over_acp")]
7536 #[test]
7537 fn test_client_mcp_message_method_names() {
7538 use serde_json::json;
7539
7540 assert_eq!(AGENT_METHOD_NAMES.mcp_message, "mcp/message");
7541
7542 let notification =
7543 MessageMcpNotification::new("server-1", "req-1", "notifications/progress");
7544 assert_eq!(
7545 ClientNotification::MessageMcpNotification(notification.clone()).method(),
7546 "mcp/message"
7547 );
7548 assert_eq!(
7549 serde_json::to_value(notification).unwrap(),
7550 json!({
7551 "serverId": "server-1",
7552 "requestId": "req-1",
7553 "method": "notifications/progress"
7554 })
7555 );
7556 let notification: MessageMcpNotification = serde_json::from_value(json!({
7557 "serverId": "server-1", "requestId": "req-1", "method": "notifications/progress",
7558 "params": null, "_meta": null
7559 }))
7560 .unwrap();
7561 assert_eq!(notification.params, None);
7562 assert_eq!(notification.meta, None);
7563 for key in ["serverId", "requestId", "method"] {
7564 let mut value = json!({"serverId":"server-1", "requestId":"req-1", "method":"notifications/progress"});
7565 value.as_object_mut().unwrap().remove(key);
7566 assert!(serde_json::from_value::<MessageMcpNotification>(value).is_err());
7567 }
7568 }
7569
7570 #[cfg(all(feature = "unstable_mcp_over_acp", feature = "schemars"))]
7571 #[test]
7572 fn test_mcp_server_acp_schema() {
7573 let mcp_server_schema = serde_json::to_value(schemars::schema_for!(McpServer)).unwrap();
7574 assert!(json_contains_entry(
7575 &mcp_server_schema,
7576 "const",
7577 &json!("acp")
7578 ));
7579 assert!(json_contains_entry(
7580 &mcp_server_schema,
7581 "$ref",
7582 &json!("#/$defs/McpServerAcp")
7583 ));
7584
7585 let capabilities_schema =
7586 serde_json::to_value(schemars::schema_for!(McpCapabilities)).unwrap();
7587 assert!(json_contains_key(&capabilities_schema, "acp"));
7588 }
7589
7590 #[cfg(all(feature = "unstable_mcp_over_acp", feature = "schemars"))]
7591 fn json_contains_entry(
7592 value: &serde_json::Value,
7593 key: &str,
7594 expected: &serde_json::Value,
7595 ) -> bool {
7596 match value {
7597 serde_json::Value::Object(map) => {
7598 map.get(key) == Some(expected)
7599 || map
7600 .values()
7601 .any(|value| json_contains_entry(value, key, expected))
7602 }
7603 serde_json::Value::Array(values) => values
7604 .iter()
7605 .any(|value| json_contains_entry(value, key, expected)),
7606 _ => false,
7607 }
7608 }
7609
7610 #[cfg(all(feature = "unstable_mcp_over_acp", feature = "schemars"))]
7611 fn json_contains_key(value: &serde_json::Value, key: &str) -> bool {
7612 match value {
7613 serde_json::Value::Object(map) => {
7614 map.contains_key(key) || map.values().any(|value| json_contains_key(value, key))
7615 }
7616 serde_json::Value::Array(values) => {
7617 values.iter().any(|value| json_contains_key(value, key))
7618 }
7619 _ => false,
7620 }
7621 }
7622
7623 #[test]
7624 fn test_mcp_server_sse_serialization() {
7625 let server = McpServer::Sse(
7626 McpServerSse::new("sse-server", "https://sse.example.com/events")
7627 .headers(vec![HttpHeader::new("X-API-Key", "apikey456")]),
7628 );
7629
7630 let json = serde_json::to_value(&server).unwrap();
7631 assert_eq!(
7632 json,
7633 json!({
7634 "type": "sse",
7635 "name": "sse-server",
7636 "url": "https://sse.example.com/events",
7637 "headers": [
7638 {
7639 "name": "X-API-Key",
7640 "value": "apikey456"
7641 }
7642 ]
7643 })
7644 );
7645
7646 let deserialized: McpServer = serde_json::from_value(json).unwrap();
7647 match deserialized {
7648 McpServer::Sse(McpServerSse {
7649 name,
7650 url,
7651 headers,
7652 meta: _,
7653 }) => {
7654 assert_eq!(name, "sse-server");
7655 assert_eq!(url, "https://sse.example.com/events");
7656 assert_eq!(headers.len(), 1);
7657 assert_eq!(headers[0].name, "X-API-Key");
7658 assert_eq!(headers[0].value, "apikey456");
7659 }
7660 _ => panic!("Expected Sse variant"),
7661 }
7662 }
7663
7664 #[test]
7665 fn test_session_config_option_category_known_variants() {
7666 assert_eq!(
7668 serde_json::to_value(&SessionConfigOptionCategory::Mode).unwrap(),
7669 json!("mode")
7670 );
7671 assert_eq!(
7672 serde_json::to_value(&SessionConfigOptionCategory::Model).unwrap(),
7673 json!("model")
7674 );
7675 assert_eq!(
7676 serde_json::to_value(&SessionConfigOptionCategory::ModelConfig).unwrap(),
7677 json!("model_config")
7678 );
7679 #[cfg(feature = "unstable_speed_config_category")]
7680 assert_eq!(
7681 serde_json::to_value(&SessionConfigOptionCategory::Speed).unwrap(),
7682 json!("speed")
7683 );
7684 assert_eq!(
7685 serde_json::to_value(&SessionConfigOptionCategory::ThoughtLevel).unwrap(),
7686 json!("thought_level")
7687 );
7688
7689 assert_eq!(
7691 serde_json::from_str::<SessionConfigOptionCategory>("\"mode\"").unwrap(),
7692 SessionConfigOptionCategory::Mode
7693 );
7694 assert_eq!(
7695 serde_json::from_str::<SessionConfigOptionCategory>("\"model\"").unwrap(),
7696 SessionConfigOptionCategory::Model
7697 );
7698 assert_eq!(
7699 serde_json::from_str::<SessionConfigOptionCategory>("\"model_config\"").unwrap(),
7700 SessionConfigOptionCategory::ModelConfig
7701 );
7702 #[cfg(feature = "unstable_speed_config_category")]
7703 assert_eq!(
7704 serde_json::from_str::<SessionConfigOptionCategory>("\"speed\"").unwrap(),
7705 SessionConfigOptionCategory::Speed
7706 );
7707 assert_eq!(
7708 serde_json::from_str::<SessionConfigOptionCategory>("\"thought_level\"").unwrap(),
7709 SessionConfigOptionCategory::ThoughtLevel
7710 );
7711 }
7712
7713 #[test]
7714 fn test_session_config_option_category_unknown_variants() {
7715 let unknown: SessionConfigOptionCategory =
7717 serde_json::from_str("\"some_future_category\"").unwrap();
7718 assert_eq!(
7719 unknown,
7720 SessionConfigOptionCategory::Other("some_future_category".to_string())
7721 );
7722
7723 let json = serde_json::to_value(&unknown).unwrap();
7725 assert_eq!(json, json!("some_future_category"));
7726 }
7727
7728 #[cfg(not(feature = "unstable_speed_config_category"))]
7729 #[test]
7730 fn test_session_config_option_speed_is_unknown_without_feature() {
7731 let unknown: SessionConfigOptionCategory = serde_json::from_str("\"speed\"").unwrap();
7732 assert_eq!(
7733 unknown,
7734 SessionConfigOptionCategory::Other("speed".to_string())
7735 );
7736 }
7737
7738 #[test]
7739 fn test_session_config_option_category_custom_categories() {
7740 let custom: SessionConfigOptionCategory =
7742 serde_json::from_str("\"_my_custom_category\"").unwrap();
7743 assert_eq!(
7744 custom,
7745 SessionConfigOptionCategory::Other("_my_custom_category".to_string())
7746 );
7747
7748 let json = serde_json::to_value(&custom).unwrap();
7750 assert_eq!(json, json!("_my_custom_category"));
7751
7752 let deserialized: SessionConfigOptionCategory = serde_json::from_value(json).unwrap();
7754 assert_eq!(
7755 deserialized,
7756 SessionConfigOptionCategory::Other("_my_custom_category".to_string()),
7757 );
7758 }
7759
7760 #[test]
7761 fn test_auth_method_agent_serialization() {
7762 let method = AuthMethod::Agent(AuthMethodAgent::new("default-auth", "Default Auth"));
7763
7764 let json = serde_json::to_value(&method).unwrap();
7765 assert_eq!(
7766 json,
7767 json!({
7768 "id": "default-auth",
7769 "name": "Default Auth"
7770 })
7771 );
7772 assert!(!json.as_object().unwrap().contains_key("description"));
7774 assert!(!json.as_object().unwrap().contains_key("type"));
7776
7777 let deserialized: AuthMethod = serde_json::from_value(json).unwrap();
7778 match deserialized {
7779 AuthMethod::Agent(AuthMethodAgent { id, name, .. }) => {
7780 assert_eq!(id.0.as_ref(), "default-auth");
7781 assert_eq!(name, "Default Auth");
7782 }
7783 _ => panic!("Expected Agent variant"),
7784 }
7785 }
7786
7787 #[test]
7788 fn test_auth_method_explicit_agent_deserialization() {
7789 let json = json!({
7791 "id": "agent-auth",
7792 "name": "Agent Auth",
7793 "type": "agent"
7794 });
7795
7796 let deserialized: AuthMethod = serde_json::from_value(json).unwrap();
7797 assert!(matches!(deserialized, AuthMethod::Agent(_)));
7798 }
7799
7800 #[test]
7801 fn test_session_delete_serialization() {
7802 assert_eq!(AGENT_METHOD_NAMES.session_delete, "session/delete");
7803 assert_eq!(
7804 ClientRequest::DeleteSessionRequest(DeleteSessionRequest::new("sess_abc123")).method(),
7805 "session/delete"
7806 );
7807 assert_eq!(
7808 serde_json::to_value(DeleteSessionRequest::new("sess_abc123")).unwrap(),
7809 json!({
7810 "sessionId": "sess_abc123"
7811 })
7812 );
7813 assert_eq!(
7814 serde_json::to_value(DeleteSessionResponse::new()).unwrap(),
7815 json!({})
7816 );
7817 assert_eq!(
7818 serde_json::to_value(
7819 SessionCapabilities::new().delete(SessionDeleteCapabilities::new())
7820 )
7821 .unwrap(),
7822 json!({
7823 "delete": {}
7824 })
7825 );
7826 }
7827 #[cfg(feature = "unstable_session_set_title")]
7828 #[test]
7829 fn test_session_set_title_serialization() {
7830 assert_eq!(AGENT_METHOD_NAMES.session_set_title, "session/set_title");
7831 assert_eq!(
7832 ClientRequest::SetSessionTitleRequest(SetSessionTitleRequest::new(
7833 "sess_abc123",
7834 "Investigate OAuth timeout"
7835 ))
7836 .method(),
7837 "session/set_title"
7838 );
7839 assert_eq!(
7840 serde_json::to_value(SetSessionTitleRequest::new(
7841 "sess_abc123",
7842 "Investigate OAuth timeout"
7843 ))
7844 .unwrap(),
7845 json!({
7846 "sessionId": "sess_abc123",
7847 "title": "Investigate OAuth timeout"
7848 })
7849 );
7850 assert_eq!(
7851 serde_json::to_value(SetSessionTitleResponse::new("Investigate OAuth timeout"))
7852 .unwrap(),
7853 json!({
7854 "title": "Investigate OAuth timeout"
7855 })
7856 );
7857 assert_eq!(
7858 serde_json::to_value(SessionCapabilities::new().title(SessionTitleCapabilities::new()))
7859 .unwrap(),
7860 json!({
7861 "title": {}
7862 })
7863 );
7864 }
7865
7866 #[cfg(feature = "unstable_session_set_title")]
7867 #[test]
7868 fn test_session_set_title_requires_title() {
7869 for params in [
7870 json!({"sessionId": "sess_abc123"}),
7871 json!({"sessionId": "sess_abc123", "title": null}),
7872 json!({"sessionId": "sess_abc123", "title": 42}),
7873 ] {
7874 assert!(serde_json::from_value::<SetSessionTitleRequest>(params).is_err());
7875 }
7876 for result in [json!({}), json!({"title": null})] {
7877 assert!(serde_json::from_value::<SetSessionTitleResponse>(result).is_err());
7878 }
7879 }
7880
7881 #[cfg(feature = "unstable_session_options")]
7882 #[test]
7883 fn test_session_options_serialization() {
7884 assert_eq!(AGENT_METHOD_NAMES.session_options, "session/options");
7885 assert_eq!(
7886 ClientRequest::SessionOptionsRequest(SessionOptionsRequest::new("/home/user/project"))
7887 .method(),
7888 "session/options"
7889 );
7890 assert_eq!(
7891 serde_json::to_value(
7892 SessionOptionsRequest::new("/home/user/project")
7893 .session_id(SessionId::new("sess_abc123"))
7894 )
7895 .unwrap(),
7896 json!({"cwd": "/home/user/project", "sessionId": "sess_abc123"})
7897 );
7898 assert_eq!(
7899 serde_json::from_value::<SessionOptionsRequest>(
7900 json!({"cwd": "/home/user/project", "additionalDirectories": null, "sessionId": null})
7901 )
7902 .unwrap(),
7903 SessionOptionsRequest::new("/home/user/project")
7904 );
7905 let request = NewSessionRequest::new("/home/user/project").config_options(vec![
7906 InitialSessionConfigOption::new("model", SessionConfigOptionValue::value_id("model-2")),
7907 InitialSessionConfigOption::new("fast", SessionConfigOptionValue::boolean(true)),
7908 ]);
7909 let value = serde_json::to_value(&request).unwrap();
7910 assert_eq!(
7911 value["configOptions"],
7912 json!([
7913 {"configId": "model", "value": "model-2"},
7914 {"configId": "fast", "type": "boolean", "value": true}
7915 ])
7916 );
7917 assert_eq!(
7918 serde_json::from_value::<NewSessionRequest>(value).unwrap(),
7919 request
7920 );
7921 assert!(
7922 serde_json::from_value::<NewSessionRequest>(json!({
7923 "cwd": "/home/user/project",
7924 "mcpServers": [],
7925 "configOptions": [{"type": "boolean", "value": true}]
7926 }))
7927 .is_err()
7928 );
7929 assert_eq!(
7930 serde_json::to_value(SessionOptionsResponse::new()).unwrap(),
7931 json!({})
7932 );
7933 #[cfg(feature = "unstable_session_fork")]
7934 {
7935 let fork =
7936 ForkSessionRequest::new("sess_abc123", "/home/user/project").config_options(vec![
7937 InitialSessionConfigOption::new(
7938 "model",
7939 SessionConfigOptionValue::value_id("model-2"),
7940 ),
7941 ]);
7942 let value = serde_json::to_value(&fork).unwrap();
7943 assert_eq!(
7944 value["configOptions"],
7945 json!([{"configId": "model", "value": "model-2"}])
7946 );
7947 assert_eq!(
7948 serde_json::from_value::<ForkSessionRequest>(value).unwrap(),
7949 fork
7950 );
7951 assert_eq!(
7953 serde_json::from_value::<ForkSessionRequest>(json!({
7954 "sessionId": "sess_abc123",
7955 "cwd": "/home/user/project",
7956 "configOptions": null
7957 }))
7958 .unwrap(),
7959 ForkSessionRequest::new("sess_abc123", "/home/user/project")
7960 );
7961 assert!(
7962 serde_json::from_value::<ForkSessionRequest>(json!({
7963 "sessionId": "sess_abc123",
7964 "cwd": "/home/user/project",
7965 "configOptions": [{"type": "boolean", "value": true}]
7966 }))
7967 .is_err()
7968 );
7969 }
7970 assert_eq!(
7971 serde_json::to_value(
7972 SessionCapabilities::new().options(SessionOptionsCapabilities::new())
7973 )
7974 .unwrap(),
7975 json!({"options": {}})
7976 );
7977 }
7978
7979 #[cfg(feature = "unstable_session_status")]
7980 #[test]
7981 fn test_session_status_serialization() {
7982 assert_eq!(AGENT_METHOD_NAMES.session_status, "session/status");
7983 assert_eq!(
7984 ClientRequest::SessionStatusRequest(SessionStatusRequest::new("sess_abc123")).method(),
7985 "session/status"
7986 );
7987 assert_eq!(
7988 serde_json::to_value(SessionStatusRequest::new("sess_abc123")).unwrap(),
7989 json!({"sessionId": "sess_abc123"})
7990 );
7991 assert_eq!(
7992 serde_json::to_value(SessionStatusResponse::new(SessionStatus::Saved)).unwrap(),
7993 json!({"status": "saved"})
7994 );
7995 assert_eq!(
7996 serde_json::to_value(
7997 SessionCapabilities::new().status(SessionStatusCapabilities::new())
7998 )
7999 .unwrap(),
8000 json!({"status": {}})
8001 );
8002 }
8003
8004 #[cfg(feature = "unstable_session_status")]
8005 #[test]
8006 fn test_session_status_is_strict_and_open() {
8007 let custom =
8008 serde_json::from_value::<SessionStatusResponse>(json!({"status": "_suspended"}))
8009 .unwrap();
8010 assert_eq!(
8011 custom.status,
8012 SessionStatus::Other("_suspended".to_string())
8013 );
8014 assert_eq!(
8015 serde_json::to_value(&custom).unwrap(),
8016 json!({"status": "_suspended"})
8017 );
8018 for result in [json!({}), json!({"status": null}), json!({"status": 1})] {
8019 assert!(serde_json::from_value::<SessionStatusResponse>(result).is_err());
8020 }
8021 for params in [json!({}), json!({"sessionId": null})] {
8022 assert!(serde_json::from_value::<SessionStatusRequest>(params).is_err());
8023 }
8024 }
8025
8026 #[cfg(feature = "unstable_session_archive")]
8027 #[test]
8028 fn test_session_archive_serialization() {
8029 assert_eq!(AGENT_METHOD_NAMES.session_archive, "session/archive");
8030 assert_eq!(AGENT_METHOD_NAMES.session_unarchive, "session/unarchive");
8031 assert_eq!(
8032 ClientRequest::ArchiveSessionRequest(ArchiveSessionRequest::new("sess_abc123"))
8033 .method(),
8034 "session/archive"
8035 );
8036 assert_eq!(
8037 ClientRequest::UnarchiveSessionRequest(UnarchiveSessionRequest::new("sess_abc123"))
8038 .method(),
8039 "session/unarchive"
8040 );
8041 assert_eq!(
8042 serde_json::to_value(ArchiveSessionRequest::new("sess_abc123")).unwrap(),
8043 json!({"sessionId": "sess_abc123"})
8044 );
8045 assert_eq!(
8046 serde_json::to_value(UnarchiveSessionResponse::new()).unwrap(),
8047 json!({})
8048 );
8049 assert_eq!(
8050 serde_json::to_value(
8051 SessionCapabilities::new().archive(SessionArchiveCapabilities::new())
8052 )
8053 .unwrap(),
8054 json!({"archive": {}})
8055 );
8056 assert_eq!(
8057 serde_json::to_value(
8058 ListSessionsRequest::new()
8059 .cwd("/home/user/project")
8060 .archived(SessionArchiveFilter::Only)
8061 )
8062 .unwrap(),
8063 json!({"cwd": "/home/user/project", "archived": "only"})
8064 );
8065 assert_eq!(
8066 serde_json::to_value(
8067 SessionInfo::new("sess_abc123", "/home/user/project").archived(true)
8068 )
8069 .unwrap(),
8070 json!({"sessionId": "sess_abc123", "cwd": "/home/user/project", "archived": true})
8071 );
8072 }
8073
8074 #[cfg(feature = "unstable_session_archive")]
8075 #[test]
8076 fn test_session_archive_filter_is_strict_and_open() {
8077 for (value, expected) in [
8078 (json!(null), None),
8079 (json!("include"), Some(SessionArchiveFilter::Include)),
8080 (
8081 json!("_recent"),
8082 Some(SessionArchiveFilter::Other("_recent".to_string())),
8083 ),
8084 ] {
8085 let request =
8086 serde_json::from_value::<ListSessionsRequest>(json!({"archived": value})).unwrap();
8087 assert_eq!(request.archived, expected);
8088 }
8089 for value in [json!(true), json!(1), json!({})] {
8090 assert!(
8091 serde_json::from_value::<ListSessionsRequest>(json!({"archived": value})).is_err()
8092 );
8093 }
8094 let info = serde_json::from_value::<SessionInfo>(
8095 json!({"sessionId": "sess_abc123", "cwd": "/home/user/project", "archived": "yes"}),
8096 )
8097 .unwrap();
8098 assert_eq!(info.archived, None);
8099 }
8100
8101 #[test]
8102 fn test_session_additional_directories_serialization() {
8103 assert_eq!(
8104 serde_json::to_value(NewSessionRequest::new("/home/user/project")).unwrap(),
8105 json!({
8106 "cwd": "/home/user/project",
8107 "mcpServers": []
8108 })
8109 );
8110 assert_eq!(
8111 serde_json::to_value(
8112 NewSessionRequest::new("/home/user/project").additional_directories(vec![
8113 PathBuf::from("/home/user/shared-lib"),
8114 PathBuf::from("/home/user/product-docs"),
8115 ])
8116 )
8117 .unwrap(),
8118 json!({
8119 "cwd": "/home/user/project",
8120 "additionalDirectories": [
8121 "/home/user/shared-lib",
8122 "/home/user/product-docs"
8123 ],
8124 "mcpServers": []
8125 })
8126 );
8127 assert_eq!(
8128 serde_json::to_value(SessionInfo::new("sess_abc123", "/home/user/project")).unwrap(),
8129 json!({
8130 "sessionId": "sess_abc123",
8131 "cwd": "/home/user/project"
8132 })
8133 );
8134 assert_eq!(
8135 serde_json::to_value(
8136 SessionInfo::new("sess_abc123", "/home/user/project").additional_directories(vec![
8137 PathBuf::from("/home/user/shared-lib"),
8138 PathBuf::from("/home/user/product-docs"),
8139 ])
8140 )
8141 .unwrap(),
8142 json!({
8143 "sessionId": "sess_abc123",
8144 "cwd": "/home/user/project",
8145 "additionalDirectories": [
8146 "/home/user/shared-lib",
8147 "/home/user/product-docs"
8148 ]
8149 })
8150 );
8151 assert_eq!(
8152 serde_json::from_value::<SessionInfo>(json!({
8153 "sessionId": "sess_abc123",
8154 "cwd": "/home/user/project"
8155 }))
8156 .unwrap()
8157 .additional_directories,
8158 Vec::<PathBuf>::new()
8159 );
8160 }
8161 #[test]
8162 fn test_session_additional_directories_capabilities_serialization() {
8163 assert_eq!(
8164 serde_json::to_value(
8165 SessionCapabilities::new()
8166 .additional_directories(SessionAdditionalDirectoriesCapabilities::new())
8167 )
8168 .unwrap(),
8169 json!({
8170 "additionalDirectories": {}
8171 })
8172 );
8173 }
8174
8175 #[test]
8176 fn test_session_system_prompt_capabilities_serialization() {
8177 assert_eq!(
8178 serde_json::to_value(
8179 SessionCapabilities::new().system_prompt(SessionSystemPromptCapabilities::new())
8180 )
8181 .unwrap(),
8182 json!({ "systemPrompt": {} })
8183 );
8184 assert_eq!(
8185 serde_json::to_value(
8186 SessionCapabilities::new().system_prompt(
8187 SessionSystemPromptCapabilities::new().mode(
8188 SessionSystemPromptModeCapabilities::new()
8189 .override_(SessionSystemPromptOverrideCapabilities::new())
8190 )
8191 )
8192 )
8193 .unwrap(),
8194 json!({ "systemPrompt": { "mode": { "override": {} } } })
8195 );
8196 assert_eq!(
8197 serde_json::from_value::<SessionCapabilities>(
8198 json!({ "systemPrompt": { "mode": { "override": {} } } })
8199 )
8200 .unwrap()
8201 .system_prompt
8202 .and_then(|capabilities| capabilities.mode)
8203 .and_then(|mode| mode.override_),
8204 Some(SessionSystemPromptOverrideCapabilities::new())
8205 );
8206
8207 assert_eq!(
8209 serde_json::from_value::<SessionCapabilities>(json!({ "systemPrompt": "yes" }))
8210 .unwrap()
8211 .system_prompt,
8212 None
8213 );
8214 assert_eq!(
8215 serde_json::from_value::<SessionCapabilities>(
8216 json!({ "systemPrompt": { "mode": { "override": true } } })
8217 )
8218 .unwrap()
8219 .system_prompt,
8220 Some(
8221 SessionSystemPromptCapabilities::new()
8222 .mode(SessionSystemPromptModeCapabilities::new())
8223 )
8224 );
8225 assert_eq!(
8226 serde_json::from_value::<SessionCapabilities>(
8227 json!({ "systemPrompt": { "mode": "override" } })
8228 )
8229 .unwrap()
8230 .system_prompt,
8231 Some(SessionSystemPromptCapabilities::new())
8232 );
8233 }
8234
8235 #[test]
8236 fn test_system_prompt_lifecycle_request_serialization() {
8237 let system_prompt = SystemPrompt::new(vec![ContentBlock::from(
8238 "You are a code review specialist.",
8239 )]);
8240 let system_prompt_json = json!({
8241 "mode": "append",
8242 "content": [{ "type": "text", "text": "You are a code review specialist." }]
8243 });
8244
8245 let request =
8246 NewSessionRequest::new("/home/user/project").system_prompt(system_prompt.clone());
8247 let request_json = json!({
8248 "cwd": "/home/user/project",
8249 "mcpServers": [],
8250 "systemPrompt": system_prompt_json
8251 });
8252 assert_eq!(serde_json::to_value(&request).unwrap(), request_json);
8253 assert_eq!(
8254 serde_json::from_value::<NewSessionRequest>(request_json).unwrap(),
8255 request
8256 );
8257
8258 assert_eq!(
8259 serde_json::to_value(
8260 LoadSessionRequest::new("sess_abc123", "/home/user/project")
8261 .system_prompt(system_prompt.clone())
8262 )
8263 .unwrap()["systemPrompt"],
8264 system_prompt_json
8265 );
8266 assert_eq!(
8267 serde_json::to_value(
8268 ResumeSessionRequest::new("sess_abc123", "/home/user/project")
8269 .system_prompt(system_prompt.clone())
8270 )
8271 .unwrap()["systemPrompt"],
8272 system_prompt_json
8273 );
8274 #[cfg(feature = "unstable_session_fork")]
8275 assert_eq!(
8276 serde_json::to_value(
8277 ForkSessionRequest::new("sess_abc123", "/home/user/project")
8278 .system_prompt(system_prompt.clone())
8279 )
8280 .unwrap()["systemPrompt"],
8281 system_prompt_json
8282 );
8283
8284 let override_prompt =
8285 SystemPrompt::new(vec![ContentBlock::from("...")]).mode(SystemPromptMode::Override);
8286 let override_json = json!({
8287 "mode": "override",
8288 "content": [{ "type": "text", "text": "..." }]
8289 });
8290 assert_eq!(
8291 serde_json::to_value(&override_prompt).unwrap(),
8292 override_json
8293 );
8294 assert_eq!(
8295 serde_json::from_value::<SystemPrompt>(override_json).unwrap(),
8296 override_prompt
8297 );
8298 }
8299
8300 #[test]
8303 fn test_system_prompt_new_defaults_to_append() {
8304 let system_prompt = SystemPrompt::new(vec![ContentBlock::from("...")]);
8305 assert_eq!(system_prompt.mode, SystemPromptMode::Append);
8306 assert_eq!(
8307 serde_json::to_value(&system_prompt).unwrap(),
8308 json!({ "mode": "append", "content": [{ "type": "text", "text": "..." }] })
8309 );
8310 }
8311
8312 #[test]
8316 fn test_system_prompt_preserves_unknown_modes() {
8317 for mode in ["_vendor_mode", "prepend"] {
8318 let system_prompt_json =
8319 json!({ "mode": mode, "content": [{ "type": "text", "text": "..." }] });
8320 let system_prompt: SystemPrompt =
8321 serde_json::from_value(system_prompt_json.clone()).unwrap();
8322 assert_eq!(
8323 system_prompt.mode,
8324 SystemPromptMode::Other(mode.to_string())
8325 );
8326 assert_eq!(
8327 serde_json::to_value(&system_prompt).unwrap(),
8328 system_prompt_json
8329 );
8330 }
8331 }
8332
8333 fn assert_system_prompt_is_strict<T>(base: &serde_json::Value)
8337 where
8338 T: serde::de::DeserializeOwned + PartialEq + std::fmt::Debug,
8339 {
8340 let name = std::any::type_name::<T>();
8341 let with = |system_prompt: serde_json::Value| {
8342 let mut request = base.clone();
8343 request["systemPrompt"] = system_prompt;
8344 serde_json::from_value::<T>(request)
8345 };
8346
8347 for system_prompt in [
8348 json!("You are a code review specialist."),
8349 json!({ "content": [{ "type": "text", "text": "..." }] }),
8350 json!({ "mode": null, "content": [{ "type": "text", "text": "..." }] }),
8351 json!({ "mode": 1, "content": [{ "type": "text", "text": "..." }] }),
8352 json!({ "mode": "append" }),
8353 json!({ "mode": "append", "content": "..." }),
8354 json!({ "mode": "append", "content": [{ "type": "text" }] }),
8355 json!({ "mode": "append", "content": [{ "type": "video", "uri": "..." }] }),
8356 ] {
8357 assert!(
8358 with(system_prompt.clone()).is_err(),
8359 "{name}.systemPrompt: {system_prompt}"
8360 );
8361 }
8362
8363 assert_eq!(
8364 with(serde_json::Value::Null).unwrap(),
8365 serde_json::from_value::<T>(base.clone()).unwrap(),
8366 "{name}.systemPrompt"
8367 );
8368 }
8369
8370 #[test]
8371 fn test_session_setup_requests_reject_malformed_system_prompts() {
8372 assert!(
8373 serde_json::to_value(NewSessionRequest::new("/repo"))
8374 .unwrap()
8375 .get("systemPrompt")
8376 .is_none()
8377 );
8378 assert_system_prompt_is_strict::<NewSessionRequest>(&json!({
8379 "cwd": "/repo",
8380 "mcpServers": []
8381 }));
8382 assert_system_prompt_is_strict::<LoadSessionRequest>(&json!({
8383 "sessionId": "sess-1",
8384 "cwd": "/repo",
8385 "mcpServers": []
8386 }));
8387 assert_system_prompt_is_strict::<ResumeSessionRequest>(&json!({
8388 "sessionId": "sess-1",
8389 "cwd": "/repo"
8390 }));
8391 #[cfg(feature = "unstable_session_fork")]
8392 assert_system_prompt_is_strict::<ForkSessionRequest>(&json!({
8393 "sessionId": "sess-1",
8394 "cwd": "/repo"
8395 }));
8396 }
8397
8398 #[test]
8399 fn test_auth_method_terminal_serialization() {
8400 let method = AuthMethod::Terminal(AuthMethodTerminal::new("tui-auth", "Terminal Auth"));
8401
8402 let json = serde_json::to_value(&method).unwrap();
8403 assert_eq!(
8404 json,
8405 json!({
8406 "id": "tui-auth",
8407 "name": "Terminal Auth",
8408 "type": "terminal"
8409 })
8410 );
8411 assert!(!json.as_object().unwrap().contains_key("args"));
8413 assert!(!json.as_object().unwrap().contains_key("env"));
8414
8415 let deserialized: AuthMethod = serde_json::from_value(json).unwrap();
8416 match deserialized {
8417 AuthMethod::Terminal(AuthMethodTerminal { args, env, .. }) => {
8418 assert_eq!(args, Vec::<String>::new());
8419 assert!(env.is_empty());
8420 }
8421 _ => panic!("Expected Terminal variant"),
8422 }
8423 }
8424
8425 #[test]
8426 fn test_auth_method_terminal_with_args_and_env_serialization() {
8427 use std::collections::HashMap;
8428
8429 let mut env = HashMap::new();
8430 env.insert("TERM".to_string(), "xterm-256color".to_string());
8431
8432 let method = AuthMethod::Terminal(
8433 AuthMethodTerminal::new("tui-auth", "Terminal Auth")
8434 .args(vec!["--interactive".to_string(), "--color".to_string()])
8435 .env(env),
8436 );
8437
8438 let json = serde_json::to_value(&method).unwrap();
8439 assert_eq!(
8440 json,
8441 json!({
8442 "id": "tui-auth",
8443 "name": "Terminal Auth",
8444 "type": "terminal",
8445 "args": ["--interactive", "--color"],
8446 "env": {
8447 "TERM": "xterm-256color"
8448 }
8449 })
8450 );
8451
8452 let deserialized: AuthMethod = serde_json::from_value(json).unwrap();
8453 match deserialized {
8454 AuthMethod::Terminal(AuthMethodTerminal { args, env, .. }) => {
8455 assert_eq!(args, vec!["--interactive", "--color"]);
8456 assert_eq!(env.len(), 1);
8457 assert_eq!(env.get("TERM").unwrap(), "xterm-256color");
8458 }
8459 _ => panic!("Expected Terminal variant"),
8460 }
8461 }
8462
8463 #[test]
8464 fn test_session_config_option_value_id_serialize() {
8465 let val = SessionConfigOptionValue::value_id("model-1");
8466 let json = serde_json::to_value(&val).unwrap();
8467 assert_eq!(json, json!({ "value": "model-1" }));
8469 assert!(!json.as_object().unwrap().contains_key("type"));
8470 }
8471
8472 #[test]
8473 fn test_session_config_option_value_boolean_serialize() {
8474 let val = SessionConfigOptionValue::boolean(true);
8475 let json = serde_json::to_value(&val).unwrap();
8476 assert_eq!(json, json!({ "type": "boolean", "value": true }));
8477 }
8478
8479 #[test]
8480 fn test_session_config_option_value_deserialize_no_type() {
8481 let json = json!({ "value": "model-1" });
8483 let val: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
8484 assert_eq!(val, SessionConfigOptionValue::value_id("model-1"));
8485 assert_eq!(val.as_value_id().unwrap().to_string(), "model-1");
8486 }
8487
8488 #[test]
8489 fn test_session_config_option_value_deserialize_boolean() {
8490 let json = json!({ "type": "boolean", "value": true });
8491 let val: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
8492 assert_eq!(val, SessionConfigOptionValue::boolean(true));
8493 assert_eq!(val.as_bool(), Some(true));
8494 }
8495
8496 #[test]
8497 fn test_session_config_option_value_deserialize_boolean_false() {
8498 let json = json!({ "type": "boolean", "value": false });
8499 let val: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
8500 assert_eq!(val, SessionConfigOptionValue::boolean(false));
8501 assert_eq!(val.as_bool(), Some(false));
8502 }
8503
8504 #[test]
8505 fn test_session_config_option_value_deserialize_unknown_type_with_string_value() {
8506 let json = json!({ "type": "text", "value": "freeform input" });
8508 let val: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
8509 assert_eq!(val.as_value_id().unwrap().to_string(), "freeform input");
8510 }
8511
8512 #[test]
8513 fn test_session_config_option_value_roundtrip_value_id() {
8514 let original = SessionConfigOptionValue::value_id("option-a");
8515 let json = serde_json::to_value(&original).unwrap();
8516 let roundtripped: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
8517 assert_eq!(original, roundtripped);
8518 }
8519
8520 #[test]
8521 fn test_session_config_option_value_roundtrip_boolean() {
8522 let original = SessionConfigOptionValue::boolean(false);
8523 let json = serde_json::to_value(&original).unwrap();
8524 let roundtripped: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
8525 assert_eq!(original, roundtripped);
8526 }
8527
8528 #[test]
8529 fn test_session_config_option_value_type_mismatch_boolean_with_string() {
8530 let json = json!({ "type": "boolean", "value": "not a bool" });
8532 let result = serde_json::from_value::<SessionConfigOptionValue>(json);
8533 assert!(result.is_ok());
8535 assert_eq!(
8536 result.unwrap().as_value_id().unwrap().to_string(),
8537 "not a bool"
8538 );
8539 }
8540
8541 #[test]
8542 fn test_session_config_option_value_from_impls() {
8543 let from_str: SessionConfigOptionValue = "model-1".into();
8544 assert_eq!(from_str.as_value_id().unwrap().to_string(), "model-1");
8545
8546 let from_id: SessionConfigOptionValue = SessionConfigValueId::new("model-2").into();
8547 assert_eq!(from_id.as_value_id().unwrap().to_string(), "model-2");
8548
8549 let from_bool: SessionConfigOptionValue = true.into();
8550 assert_eq!(from_bool.as_bool(), Some(true));
8551 }
8552
8553 #[test]
8554 fn test_set_session_config_option_request_value_id() {
8555 let req = SetSessionConfigOptionRequest::new("sess_1", "model", "model-1");
8556 let json = serde_json::to_value(&req).unwrap();
8557 assert_eq!(
8558 json,
8559 json!({
8560 "sessionId": "sess_1",
8561 "configId": "model",
8562 "value": "model-1"
8563 })
8564 );
8565 assert!(!json.as_object().unwrap().contains_key("type"));
8567 }
8568
8569 #[test]
8570 fn test_set_session_config_option_request_boolean() {
8571 let req = SetSessionConfigOptionRequest::new("sess_1", "brave_mode", true);
8572 let json = serde_json::to_value(&req).unwrap();
8573 assert_eq!(
8574 json,
8575 json!({
8576 "sessionId": "sess_1",
8577 "configId": "brave_mode",
8578 "type": "boolean",
8579 "value": true
8580 })
8581 );
8582 }
8583
8584 #[test]
8585 fn test_set_session_config_option_request_deserialize_no_type() {
8586 let json = json!({
8588 "sessionId": "sess_1",
8589 "configId": "model",
8590 "value": "model-1"
8591 });
8592 let req: SetSessionConfigOptionRequest = serde_json::from_value(json).unwrap();
8593 assert_eq!(req.session_id.to_string(), "sess_1");
8594 assert_eq!(req.config_id.to_string(), "model");
8595 assert_eq!(req.value.as_value_id().unwrap().to_string(), "model-1");
8596 }
8597
8598 #[test]
8599 fn test_set_session_config_option_request_deserialize_boolean() {
8600 let json = json!({
8601 "sessionId": "sess_1",
8602 "configId": "brave_mode",
8603 "type": "boolean",
8604 "value": true
8605 });
8606 let req: SetSessionConfigOptionRequest = serde_json::from_value(json).unwrap();
8607 assert_eq!(req.value.as_bool(), Some(true));
8608 }
8609
8610 #[test]
8611 fn test_set_session_config_option_request_roundtrip_value_id() {
8612 let original = SetSessionConfigOptionRequest::new("s", "c", "v");
8613 let json = serde_json::to_value(&original).unwrap();
8614 let roundtripped: SetSessionConfigOptionRequest = serde_json::from_value(json).unwrap();
8615 assert_eq!(original, roundtripped);
8616 }
8617
8618 #[test]
8619 fn test_set_session_config_option_request_roundtrip_boolean() {
8620 let original = SetSessionConfigOptionRequest::new("s", "c", false);
8621 let json = serde_json::to_value(&original).unwrap();
8622 let roundtripped: SetSessionConfigOptionRequest = serde_json::from_value(json).unwrap();
8623 assert_eq!(original, roundtripped);
8624 }
8625
8626 #[test]
8627 fn test_session_config_boolean_serialization() {
8628 let cfg = SessionConfigBoolean::new(true);
8629 let json = serde_json::to_value(&cfg).unwrap();
8630 assert_eq!(json, json!({ "currentValue": true }));
8631
8632 let deserialized: SessionConfigBoolean = serde_json::from_value(json).unwrap();
8633 assert!(deserialized.current_value);
8634 }
8635
8636 #[test]
8637 fn test_session_config_option_boolean_variant() {
8638 let opt = SessionConfigOption::boolean("brave_mode", "Brave Mode", false)
8639 .description("Skip confirmation prompts")
8640 .meta(test_meta());
8641 assert_eq!(serialized_meta_key_count(&opt), 1);
8642
8643 let json = serde_json::to_value(&opt).unwrap();
8644 assert_eq!(
8645 json,
8646 json!({
8647 "id": "brave_mode",
8648 "name": "Brave Mode",
8649 "description": "Skip confirmation prompts",
8650 "type": "boolean",
8651 "currentValue": false,
8652 "_meta": {
8653 "source": "test"
8654 }
8655 })
8656 );
8657
8658 let deserialized: SessionConfigOption = serde_json::from_value(json).unwrap();
8659 assert_eq!(deserialized.id.to_string(), "brave_mode");
8660 assert_eq!(deserialized.name, "Brave Mode");
8661 match deserialized.kind {
8662 SessionConfigKind::Boolean(ref b) => assert!(!b.current_value),
8663 _ => panic!("Expected Boolean kind"),
8664 }
8665 }
8666
8667 #[test]
8668 fn test_session_config_option_select_still_works() {
8669 let opt = SessionConfigOption::select(
8671 "model",
8672 "Model",
8673 "model-1",
8674 vec![
8675 SessionConfigSelectOption::new("model-1", "Model 1"),
8676 SessionConfigSelectOption::new("model-2", "Model 2"),
8677 ],
8678 )
8679 .meta(test_meta());
8680 assert_eq!(serialized_meta_key_count(&opt), 1);
8681
8682 let json = serde_json::to_value(&opt).unwrap();
8683 assert_eq!(json["type"], "select");
8684 assert_eq!(json["currentValue"], "model-1");
8685 assert_eq!(json["options"].as_array().unwrap().len(), 2);
8686 assert_eq!(json["_meta"]["source"], "test");
8687
8688 let deserialized: SessionConfigOption = serde_json::from_value(json).unwrap();
8689 match deserialized.kind {
8690 SessionConfigKind::Select(ref s) => {
8691 assert_eq!(s.current_value.to_string(), "model-1");
8692 }
8693 _ => panic!("Expected Select kind"),
8694 }
8695 }
8696
8697 #[cfg(feature = "unstable_llm_providers")]
8698 #[test]
8699 fn test_llm_protocol_known_variants() {
8700 assert_eq!(
8701 serde_json::to_value(&LlmProtocol::Anthropic).unwrap(),
8702 json!("anthropic")
8703 );
8704 assert_eq!(
8705 serde_json::to_value(&LlmProtocol::OpenAi).unwrap(),
8706 json!("openai")
8707 );
8708 assert_eq!(
8709 serde_json::to_value(&LlmProtocol::Azure).unwrap(),
8710 json!("azure")
8711 );
8712 assert_eq!(
8713 serde_json::to_value(&LlmProtocol::Vertex).unwrap(),
8714 json!("vertex")
8715 );
8716 assert_eq!(
8717 serde_json::to_value(&LlmProtocol::Bedrock).unwrap(),
8718 json!("bedrock")
8719 );
8720
8721 assert_eq!(
8722 serde_json::from_str::<LlmProtocol>("\"anthropic\"").unwrap(),
8723 LlmProtocol::Anthropic
8724 );
8725 assert_eq!(
8726 serde_json::from_str::<LlmProtocol>("\"openai\"").unwrap(),
8727 LlmProtocol::OpenAi
8728 );
8729 assert_eq!(
8730 serde_json::from_str::<LlmProtocol>("\"azure\"").unwrap(),
8731 LlmProtocol::Azure
8732 );
8733 assert_eq!(
8734 serde_json::from_str::<LlmProtocol>("\"vertex\"").unwrap(),
8735 LlmProtocol::Vertex
8736 );
8737 assert_eq!(
8738 serde_json::from_str::<LlmProtocol>("\"bedrock\"").unwrap(),
8739 LlmProtocol::Bedrock
8740 );
8741 }
8742
8743 #[cfg(feature = "unstable_llm_providers")]
8744 #[test]
8745 fn test_llm_protocol_unknown_variant() {
8746 let unknown: LlmProtocol = serde_json::from_str("\"cohere\"").unwrap();
8747 assert_eq!(unknown, LlmProtocol::Other("cohere".to_string()));
8748
8749 let json = serde_json::to_value(&unknown).unwrap();
8750 assert_eq!(json, json!("cohere"));
8751 }
8752
8753 #[cfg(feature = "unstable_llm_providers")]
8754 #[test]
8755 fn test_provider_current_config_serialization() {
8756 let config =
8757 ProviderCurrentConfig::new(LlmProtocol::Anthropic, "https://api.anthropic.com");
8758
8759 let json = serde_json::to_value(&config).unwrap();
8760 assert_eq!(
8761 json,
8762 json!({
8763 "apiType": "anthropic",
8764 "baseUrl": "https://api.anthropic.com"
8765 })
8766 );
8767
8768 let deserialized: ProviderCurrentConfig = serde_json::from_value(json).unwrap();
8769 assert_eq!(deserialized.api_type, LlmProtocol::Anthropic);
8770 assert_eq!(deserialized.base_url, "https://api.anthropic.com");
8771 }
8772
8773 #[cfg(feature = "unstable_llm_providers")]
8774 #[test]
8775 fn test_provider_info_with_current_config() {
8776 let info = ProviderInfo::new(
8777 "main",
8778 vec![LlmProtocol::Anthropic, LlmProtocol::OpenAi],
8779 true,
8780 Some(ProviderCurrentConfig::new(
8781 LlmProtocol::Anthropic,
8782 "https://api.anthropic.com",
8783 )),
8784 );
8785
8786 let json = serde_json::to_value(&info).unwrap();
8787 assert_eq!(
8788 json,
8789 json!({
8790 "providerId": "main",
8791 "supported": ["anthropic", "openai"],
8792 "required": true,
8793 "current": {
8794 "apiType": "anthropic",
8795 "baseUrl": "https://api.anthropic.com"
8796 }
8797 })
8798 );
8799
8800 let deserialized: ProviderInfo = serde_json::from_value(json).unwrap();
8801 assert_eq!(deserialized.provider_id.to_string(), "main");
8802 assert_eq!(deserialized.supported.len(), 2);
8803 assert!(deserialized.required);
8804 assert!(deserialized.current.is_some());
8805 assert_eq!(
8806 deserialized.current.as_ref().unwrap().api_type,
8807 LlmProtocol::Anthropic
8808 );
8809 }
8810
8811 #[cfg(feature = "unstable_llm_providers")]
8812 #[test]
8813 fn test_provider_info_disabled() {
8814 let info = ProviderInfo::new(
8815 "secondary",
8816 vec![LlmProtocol::OpenAi],
8817 false,
8818 None::<ProviderCurrentConfig>,
8819 );
8820
8821 let json = serde_json::to_value(&info).unwrap();
8822 assert_eq!(
8823 json,
8824 json!({
8825 "providerId": "secondary",
8826 "supported": ["openai"],
8827 "required": false
8828 })
8829 );
8830
8831 let deserialized: ProviderInfo = serde_json::from_value(json).unwrap();
8832 assert_eq!(deserialized.provider_id.to_string(), "secondary");
8833 assert!(!deserialized.required);
8834 assert!(deserialized.current.is_none());
8835 }
8836
8837 #[cfg(feature = "unstable_llm_providers")]
8838 #[test]
8839 fn test_provider_info_missing_current_defaults_to_none() {
8840 let json = json!({
8842 "providerId": "main",
8843 "supported": ["anthropic"],
8844 "required": true
8845 });
8846 let deserialized: ProviderInfo = serde_json::from_value(json).unwrap();
8847 assert!(deserialized.current.is_none());
8848 }
8849
8850 #[cfg(feature = "unstable_llm_providers")]
8851 #[test]
8852 fn test_provider_info_explicit_null_current_decodes_to_none() {
8853 let json = json!({
8857 "providerId": "main",
8858 "supported": ["anthropic"],
8859 "required": true,
8860 "current": null
8861 });
8862 let deserialized: ProviderInfo = serde_json::from_value(json).unwrap();
8863 assert!(deserialized.current.is_none());
8864 }
8865
8866 #[cfg(feature = "unstable_llm_providers")]
8867 #[test]
8868 fn test_list_providers_response_serialization() {
8869 let response = ListProvidersResponse::new(vec![ProviderInfo::new(
8870 "main",
8871 vec![LlmProtocol::Anthropic],
8872 true,
8873 Some(ProviderCurrentConfig::new(
8874 LlmProtocol::Anthropic,
8875 "https://api.anthropic.com",
8876 )),
8877 )]);
8878
8879 let json = serde_json::to_value(&response).unwrap();
8880 assert_eq!(json["providers"].as_array().unwrap().len(), 1);
8881 assert_eq!(json["providers"][0]["providerId"], "main");
8882
8883 let deserialized: ListProvidersResponse = serde_json::from_value(json).unwrap();
8884 assert_eq!(deserialized.providers.len(), 1);
8885 }
8886
8887 #[cfg(feature = "unstable_llm_providers")]
8888 #[test]
8889 fn test_set_provider_request_serialization() {
8890 let mut headers = IndexMap::new();
8891 headers.insert("Authorization".to_string(), "Bearer sk-test".to_string());
8892
8893 let request =
8894 SetProviderRequest::new("main", LlmProtocol::OpenAi, "https://api.openai.com/v1")
8895 .headers(headers);
8896
8897 let json = serde_json::to_value(&request).unwrap();
8898 assert_eq!(
8899 json,
8900 json!({
8901 "providerId": "main",
8902 "apiType": "openai",
8903 "baseUrl": "https://api.openai.com/v1",
8904 "headers": {
8905 "Authorization": "Bearer sk-test"
8906 }
8907 })
8908 );
8909
8910 let deserialized: SetProviderRequest = serde_json::from_value(json).unwrap();
8911 assert_eq!(deserialized.provider_id.to_string(), "main");
8912 assert_eq!(deserialized.api_type, LlmProtocol::OpenAi);
8913 assert_eq!(deserialized.base_url, "https://api.openai.com/v1");
8914 assert_eq!(deserialized.headers.len(), 1);
8915 assert_eq!(
8916 deserialized.headers.get("Authorization").unwrap(),
8917 "Bearer sk-test"
8918 );
8919 }
8920
8921 #[cfg(feature = "unstable_llm_providers")]
8922 #[test]
8923 fn test_set_provider_request_omits_empty_headers() {
8924 let request =
8925 SetProviderRequest::new("main", LlmProtocol::Anthropic, "https://api.anthropic.com");
8926
8927 let json = serde_json::to_value(&request).unwrap();
8928 assert!(!json.as_object().unwrap().contains_key("headers"));
8930 }
8931
8932 #[cfg(feature = "unstable_llm_providers")]
8933 #[test]
8934 fn test_disable_provider_request_serialization() {
8935 let request = DisableProviderRequest::new("secondary");
8936
8937 let json = serde_json::to_value(&request).unwrap();
8938 assert_eq!(json, json!({ "providerId": "secondary" }));
8939
8940 let deserialized: DisableProviderRequest = serde_json::from_value(json).unwrap();
8941 assert_eq!(deserialized.provider_id.to_string(), "secondary");
8942 }
8943
8944 #[cfg(feature = "unstable_llm_providers")]
8945 #[test]
8946 fn test_providers_capabilities_serialization() {
8947 let caps = ProvidersCapabilities::new();
8948
8949 let json = serde_json::to_value(&caps).unwrap();
8950 assert_eq!(json, json!({}));
8951
8952 let deserialized: ProvidersCapabilities = serde_json::from_value(json).unwrap();
8953 assert!(deserialized.meta.is_none());
8954 }
8955
8956 #[cfg(feature = "unstable_llm_providers")]
8957 #[test]
8958 fn test_agent_capabilities_with_providers() {
8959 let caps = AgentCapabilities::new().providers(ProvidersCapabilities::new());
8960
8961 let json = serde_json::to_value(&caps).unwrap();
8962 assert_eq!(json["providers"], json!({}));
8963
8964 let deserialized: AgentCapabilities = serde_json::from_value(json).unwrap();
8965 assert!(deserialized.providers.is_some());
8966 }
8967
8968 #[test]
8969 fn prompt_request_rejects_malformed_content_block() {
8970 use serde_json::json;
8971
8972 assert!(
8973 serde_json::from_value::<PromptRequest>(json!({
8974 "sessionId": "sess-1",
8975 "prompt": [{"type": "text"}]
8976 }))
8977 .is_err()
8978 );
8979 }
8980
8981 #[test]
8982 fn prompt_request_rejects_non_array_prompt() {
8983 use serde_json::json;
8984
8985 assert!(
8986 serde_json::from_value::<PromptRequest>(json!({
8987 "sessionId": "sess-1",
8988 "prompt": "hello"
8989 }))
8990 .is_err()
8991 );
8992 }
8993
8994 fn assert_session_setup_lists_are_strict<T>(base: &serde_json::Value)
8995 where
8996 T: serde::de::DeserializeOwned + PartialEq + std::fmt::Debug,
8997 {
8998 let name = std::any::type_name::<T>();
8999 let with = |field: &str, value: serde_json::Value| {
9000 let mut request = base.clone();
9001 request[field] = value;
9002 serde_json::from_value::<T>(request)
9003 };
9004
9005 for (field, value) in [
9006 (
9008 "mcpServers",
9009 json!([
9010 {"name": "github", "command": "/usr/bin/gh-mcp", "args": [], "env": [{"name": "GITHUB_TOKEN", "value": null}]},
9011 {"name": "fs", "command": "/usr/bin/fs-mcp", "args": [], "env": []}
9012 ]),
9013 ),
9014 ("mcpServers", json!({"name": "fs"})),
9015 ("additionalDirectories", json!(["/repo/lib", 42])),
9016 ("additionalDirectories", json!("/repo/lib")),
9017 ] {
9018 assert!(
9019 with(field, value.clone()).is_err(),
9020 "{name}.{field}: {value}"
9021 );
9022 }
9023
9024 let empty = serde_json::from_value::<T>(base.clone()).unwrap();
9025 for field in ["mcpServers", "additionalDirectories"] {
9026 assert_eq!(
9027 with(field, serde_json::Value::Null).unwrap(),
9028 empty,
9029 "{name}.{field}"
9030 );
9031 }
9032 }
9033
9034 #[test]
9035 fn session_setup_requests_reject_malformed_mcp_servers_and_directories() {
9036 assert_session_setup_lists_are_strict::<NewSessionRequest>(&json!({
9037 "cwd": "/repo",
9038 "mcpServers": []
9039 }));
9040 assert_session_setup_lists_are_strict::<LoadSessionRequest>(&json!({
9041 "sessionId": "sess-1",
9042 "cwd": "/repo",
9043 "mcpServers": []
9044 }));
9045 assert_session_setup_lists_are_strict::<ResumeSessionRequest>(&json!({
9046 "sessionId": "sess-1",
9047 "cwd": "/repo"
9048 }));
9049 #[cfg(feature = "unstable_session_fork")]
9050 assert_session_setup_lists_are_strict::<ForkSessionRequest>(&json!({
9051 "sessionId": "sess-1",
9052 "cwd": "/repo"
9053 }));
9054 }
9055
9056 #[test]
9057 fn mcp_server_lists_treat_null_as_empty() {
9058 let servers: Vec<McpServer> = serde_json::from_value(json!([
9059 {"name": "fs", "command": "/usr/bin/fs-mcp", "args": null, "env": null},
9060 {"type": "http", "name": "api", "url": "https://example.com/mcp", "headers": null},
9061 {"type": "sse", "name": "events", "url": "https://example.com/sse", "headers": null}
9062 ]))
9063 .unwrap();
9064
9065 assert_eq!(
9066 servers,
9067 vec![
9068 McpServer::Stdio(McpServerStdio::new("fs", "/usr/bin/fs-mcp")),
9069 McpServer::Http(McpServerHttp::new("api", "https://example.com/mcp")),
9070 McpServer::Sse(McpServerSse::new("events", "https://example.com/sse")),
9071 ]
9072 );
9073 }
9074
9075 #[test]
9076 fn terminal_auth_methods_reject_malformed_launch_config() {
9077 let response: InitializeResponse = serde_json::from_value(json!({
9081 "protocolVersion": 1,
9082 "authMethods": [
9083 {"type": "terminal", "id": "bad-args", "name": "Log in", "args": ["auth", "--port", 8123]},
9084 {"type": "terminal", "id": "bad-env", "name": "Log in", "env": {"AUTH_MODE": "device", "DEBUG": 1}},
9085 {"type": "terminal", "id": "null-config", "name": "Log in", "args": null, "env": null},
9086 {"id": "agent", "name": "Agent login"}
9087 ]
9088 }))
9089 .unwrap();
9090
9091 assert_eq!(
9092 response.auth_methods,
9093 vec![
9094 AuthMethod::Terminal(AuthMethodTerminal::new("null-config", "Log in")),
9095 AuthMethod::Agent(AuthMethodAgent::new("agent", "Agent login")),
9096 ]
9097 );
9098 assert!(
9099 serde_json::from_value::<AuthMethod>(json!({
9100 "type": "terminal",
9101 "id": "bad-args",
9102 "name": "Log in",
9103 "args": ["auth", 8123]
9104 }))
9105 .is_err()
9106 );
9107 }
9108
9109 #[cfg(feature = "unstable_auth_status")]
9110 #[test]
9111 fn auth_status_response_round_trips() {
9112 let response = AuthStatusResponse::new(AuthState::Authenticated).accounts(vec![
9113 AuthAccount::new("Anthropic API key")
9114 .description("API key helper".to_string())
9115 .active(true),
9116 AuthAccount::new("Claude Max").email("user@example.com".to_string()),
9117 ]);
9118 let json = serde_json::to_value(&response).unwrap();
9119 assert_eq!(
9120 json,
9121 json!({
9122 "state": "authenticated",
9123 "accounts": [
9124 {
9125 "label": "Anthropic API key",
9126 "description": "API key helper",
9127 "active": true
9128 },
9129 {
9130 "label": "Claude Max",
9131 "email": "user@example.com"
9132 }
9133 ]
9134 })
9135 );
9136 assert_eq!(
9137 serde_json::from_value::<AuthStatusResponse>(json).unwrap(),
9138 response
9139 );
9140 assert_eq!(
9141 serde_json::to_value(AuthStatusResponse::new(AuthState::NotRequired)).unwrap(),
9142 json!({"state": "not_required"})
9143 );
9144 }
9145
9146 #[cfg(feature = "unstable_auth_status")]
9147 #[test]
9148 fn auth_status_state_is_strict_and_accounts_are_lenient() {
9149 assert!(serde_json::from_value::<AuthStatusResponse>(json!({})).is_err());
9150 assert!(serde_json::from_value::<AuthStatusResponse>(json!({"state": null})).is_err());
9151 assert!(serde_json::from_value::<AuthStatusResponse>(json!({"state": 1})).is_err());
9152
9153 let response: AuthStatusResponse = serde_json::from_value(json!({
9154 "state": "_vendor_state",
9155 "accounts": [
9156 {"active": true},
9157 {
9158 "label": "Vertex AI",
9159 "description": 42,
9160 "active": "yes",
9161 "email": ["not", "a", "string"]
9162 }
9163 ]
9164 }))
9165 .unwrap();
9166 assert_eq!(
9167 response,
9168 AuthStatusResponse::new(AuthState::Other("_vendor_state".to_string()))
9169 .accounts(vec![AuthAccount::new("Vertex AI")])
9170 );
9171 assert_eq!(
9172 serde_json::from_value::<AuthStatusResponse>(
9173 json!({"state": "unknown", "accounts": null})
9174 )
9175 .unwrap(),
9176 AuthStatusResponse::new(AuthState::Unknown)
9177 );
9178 }
9179
9180 #[cfg(feature = "unstable_auth_status")]
9181 #[test]
9182 fn auth_status_update_notification_routes() {
9183 use crate::v1::{AgentNotification, CLIENT_METHOD_NAMES};
9184
9185 assert_eq!(AGENT_METHOD_NAMES.auth_status, "auth/status");
9186 assert_eq!(CLIENT_METHOD_NAMES.auth_status_update, "auth/status_update");
9187 let notification = AgentNotification::AuthStatusUpdateNotification(
9188 AuthStatusUpdateNotification::new(AuthState::Unauthenticated),
9189 );
9190 assert_eq!(notification.method(), "auth/status_update");
9191 assert_eq!(
9192 serde_json::to_value(¬ification).unwrap(),
9193 json!({"state": "unauthenticated"})
9194 );
9195 }
9196
9197 #[cfg(all(
9198 feature = "unstable_session_fork",
9199 feature = "unstable_session_cursors"
9200 ))]
9201 #[test]
9202 fn fork_session_request_cursor_id_is_optional_and_strict() {
9203 let request = ForkSessionRequest::new("sess_abc123", "/home/user/project")
9204 .cursor_id(CursorId::new("cur_1"));
9205 let wire = json!({
9206 "sessionId": "sess_abc123",
9207 "cursorId": "cur_1",
9208 "cwd": "/home/user/project"
9209 });
9210 assert_eq!(serde_json::to_value(&request).unwrap(), wire);
9211 assert_eq!(
9212 serde_json::from_value::<ForkSessionRequest>(wire).unwrap(),
9213 request
9214 );
9215
9216 for wire in [
9218 json!({ "sessionId": "sess_abc123", "cwd": "/home/user/project" }),
9219 json!({ "sessionId": "sess_abc123", "cwd": "/home/user/project", "cursorId": null }),
9220 ] {
9221 assert_eq!(
9222 serde_json::from_value::<ForkSessionRequest>(wire)
9223 .unwrap()
9224 .cursor_id,
9225 None
9226 );
9227 }
9228
9229 assert!(
9231 serde_json::from_value::<ForkSessionRequest>(json!({
9232 "sessionId": "sess_abc123",
9233 "cwd": "/home/user/project",
9234 "cursorId": 7
9235 }))
9236 .is_err()
9237 );
9238 }
9239}