1use std::{borrow::Cow, collections::BTreeMap, sync::Arc};
7
8#[cfg(feature = "unstable_llm_providers")]
9use std::collections::HashMap;
10
11use derive_more::{Display, From};
12#[cfg(feature = "schemars")]
13use schemars::Schema;
14use serde::{Deserialize, Serialize};
15use serde_with::{DefaultOnError, DefaultOnNull, VecSkipError, serde_as, skip_serializing_none};
16
17use super::{
18 AbsolutePath, AvailableCommand, ClientCapabilities, ContentBlock, Error, ExtNotification,
19 ExtRequest, ExtResponse, MessageId, Meta, SessionId, TerminalId, ToolCallId,
20};
21use crate::{IntoOption, ProtocolVersion};
22
23#[cfg(feature = "unstable_session_status")]
24use super::StateUpdate;
25
26#[cfg(all(feature = "unstable_auth_status", feature = "schemars"))]
27use super::AUTH_STATUS_UPDATE_NOTIFICATION;
28#[cfg(feature = "unstable_mcp_over_acp")]
29use super::mcp::{MCP_MESSAGE_METHOD_NAME, MessageMcpNotification};
30
31#[serde_as]
39#[skip_serializing_none]
40#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
41#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
42#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = INITIALIZE_METHOD_NAME)))]
43#[serde(rename_all = "camelCase")]
44#[non_exhaustive]
45pub struct InitializeRequest {
46 pub protocol_version: ProtocolVersion,
48 pub info: Implementation,
50 #[serde_as(deserialize_as = "DefaultOnError")]
52 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
53 #[serde(default)]
54 pub capabilities: ClientCapabilities,
55 #[serde_as(deserialize_as = "DefaultOnError")]
61 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
62 #[serde(default)]
63 #[serde(rename = "_meta")]
64 pub meta: Option<Meta>,
65}
66
67impl InitializeRequest {
68 #[must_use]
70 pub fn new(protocol_version: ProtocolVersion, info: Implementation) -> Self {
71 Self {
72 protocol_version,
73 capabilities: ClientCapabilities::default(),
74 info,
75 meta: None,
76 }
77 }
78
79 #[must_use]
81 pub fn capabilities(mut self, capabilities: ClientCapabilities) -> Self {
82 self.capabilities = capabilities;
83 self
84 }
85
86 #[must_use]
92 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
93 self.meta = meta.into_option();
94 self
95 }
96}
97
98#[serde_as]
104#[skip_serializing_none]
105#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
106#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
107#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = INITIALIZE_METHOD_NAME)))]
108#[serde(rename_all = "camelCase")]
109#[non_exhaustive]
110pub struct InitializeResponse {
111 pub protocol_version: ProtocolVersion,
118 pub info: Implementation,
120 #[serde_as(deserialize_as = "DefaultOnError")]
122 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
123 #[serde(default)]
124 pub capabilities: AgentCapabilities,
125 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
131 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
132 #[serde(default, skip_serializing_if = "Vec::is_empty")]
133 pub auth_methods: Vec<AuthMethod>,
134 #[serde_as(deserialize_as = "DefaultOnError")]
140 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
141 #[serde(default)]
142 #[serde(rename = "_meta")]
143 pub meta: Option<Meta>,
144}
145
146impl InitializeResponse {
147 #[must_use]
149 pub fn new(protocol_version: ProtocolVersion, info: Implementation) -> Self {
150 Self {
151 protocol_version,
152 capabilities: AgentCapabilities::default(),
153 auth_methods: vec![],
154 info,
155 meta: None,
156 }
157 }
158
159 #[must_use]
161 pub fn capabilities(mut self, capabilities: AgentCapabilities) -> Self {
162 self.capabilities = capabilities;
163 self
164 }
165
166 #[must_use]
171 pub fn auth_methods(mut self, auth_methods: Vec<AuthMethod>) -> Self {
172 self.auth_methods = auth_methods;
173 self
174 }
175
176 #[must_use]
182 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
183 self.meta = meta.into_option();
184 self
185 }
186}
187
188#[serde_as]
192#[skip_serializing_none]
193#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
194#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
195#[serde(rename_all = "camelCase")]
196#[non_exhaustive]
197pub struct Implementation {
198 pub name: String,
201 #[serde_as(deserialize_as = "DefaultOnError")]
208 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
209 #[serde(default)]
210 pub title: Option<String>,
211 pub version: String,
214 #[serde_as(deserialize_as = "DefaultOnError")]
220 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
221 #[serde(default)]
222 #[serde(rename = "_meta")]
223 pub meta: Option<Meta>,
224}
225
226impl Implementation {
227 #[must_use]
229 pub fn new(name: impl Into<String>, version: impl Into<String>) -> Self {
230 Self {
231 name: name.into(),
232 title: None,
233 version: version.into(),
234 meta: None,
235 }
236 }
237
238 #[must_use]
243 pub fn title(mut self, title: impl IntoOption<String>) -> Self {
244 self.title = title.into_option();
245 self
246 }
247
248 #[must_use]
254 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
255 self.meta = meta.into_option();
256 self
257 }
258}
259
260#[serde_as]
270#[skip_serializing_none]
271#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
272#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
273#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = AUTH_LOGIN_METHOD_NAME)))]
274#[serde(rename_all = "camelCase")]
275#[non_exhaustive]
276pub struct LoginAuthRequest {
277 pub method_id: AuthMethodId,
280 #[serde_as(deserialize_as = "DefaultOnError")]
286 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
287 #[serde(default)]
288 #[serde(rename = "_meta")]
289 pub meta: Option<Meta>,
290}
291
292impl LoginAuthRequest {
293 #[must_use]
295 pub fn new(method_id: impl Into<AuthMethodId>) -> Self {
296 Self {
297 method_id: method_id.into(),
298 meta: None,
299 }
300 }
301
302 #[must_use]
308 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
309 self.meta = meta.into_option();
310 self
311 }
312}
313
314crate::serde_util::default_on_null! {
315 #[serde_as]
317 #[skip_serializing_none]
318 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
319 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
320 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = AUTH_LOGIN_METHOD_NAME)))]
321 #[serde(rename_all = "camelCase")]
322 #[non_exhaustive]
323 pub struct LoginAuthResponse {
324 #[serde_as(deserialize_as = "DefaultOnError")]
330 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
331 #[serde(default)]
332 #[serde(rename = "_meta")]
333 pub meta: Option<Meta>,
334 }
335}
336
337impl LoginAuthResponse {
338 #[must_use]
340 pub fn new() -> Self {
341 Self::default()
342 }
343
344 #[must_use]
350 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
351 self.meta = meta.into_option();
352 self
353 }
354}
355
356crate::serde_util::default_on_null! {
359 #[serde_as]
367 #[skip_serializing_none]
368 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
369 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
370 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = AUTH_LOGOUT_METHOD_NAME)))]
371 #[serde(rename_all = "camelCase")]
372 #[non_exhaustive]
373 pub struct LogoutAuthRequest {
374 #[serde_as(deserialize_as = "DefaultOnError")]
380 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
381 #[serde(default)]
382 #[serde(rename = "_meta")]
383 pub meta: Option<Meta>,
384 }
385}
386
387impl LogoutAuthRequest {
388 #[must_use]
390 pub fn new() -> Self {
391 Self::default()
392 }
393
394 #[must_use]
400 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
401 self.meta = meta.into_option();
402 self
403 }
404}
405
406crate::serde_util::default_on_null! {
407 #[serde_as]
409 #[skip_serializing_none]
410 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
411 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
412 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = AUTH_LOGOUT_METHOD_NAME)))]
413 #[serde(rename_all = "camelCase")]
414 #[non_exhaustive]
415 pub struct LogoutAuthResponse {
416 #[serde_as(deserialize_as = "DefaultOnError")]
422 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
423 #[serde(default)]
424 #[serde(rename = "_meta")]
425 pub meta: Option<Meta>,
426 }
427}
428
429impl LogoutAuthResponse {
430 #[must_use]
432 pub fn new() -> Self {
433 Self::default()
434 }
435
436 #[must_use]
442 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
443 self.meta = meta.into_option();
444 self
445 }
446}
447
448#[cfg(feature = "unstable_auth_status")]
451crate::serde_util::default_on_null! {
452 #[serde_as]
463 #[skip_serializing_none]
464 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
465 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
466 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = AUTH_STATUS_METHOD_NAME)))]
467 #[serde(rename_all = "camelCase")]
468 #[non_exhaustive]
469 pub struct AuthStatusRequest {
470 #[serde_as(deserialize_as = "DefaultOnError")]
476 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
477 #[serde(default)]
478 #[serde(rename = "_meta")]
479 pub meta: Option<Meta>,
480 }
481}
482
483#[cfg(feature = "unstable_auth_status")]
484impl AuthStatusRequest {
485 #[must_use]
487 pub fn new() -> Self {
488 Self::default()
489 }
490
491 #[must_use]
497 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
498 self.meta = meta.into_option();
499 self
500 }
501}
502
503#[cfg(feature = "unstable_auth_status")]
509#[serde_as]
510#[skip_serializing_none]
511#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
512#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
513#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = AUTH_STATUS_METHOD_NAME)))]
514#[serde(rename_all = "camelCase")]
515#[non_exhaustive]
516pub struct AuthStatusResponse {
517 pub state: AuthState,
522 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
528 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
529 #[serde(default, skip_serializing_if = "Vec::is_empty")]
530 pub accounts: Vec<AuthAccount>,
531 #[serde_as(deserialize_as = "DefaultOnError")]
537 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
538 #[serde(default)]
539 #[serde(rename = "_meta")]
540 pub meta: Option<Meta>,
541}
542
543#[cfg(feature = "unstable_auth_status")]
544impl AuthStatusResponse {
545 #[must_use]
547 pub fn new(state: AuthState) -> Self {
548 Self {
549 state,
550 accounts: vec![],
551 meta: None,
552 }
553 }
554
555 #[must_use]
557 pub fn accounts(mut self, accounts: Vec<AuthAccount>) -> Self {
558 self.accounts = accounts;
559 self
560 }
561
562 #[must_use]
568 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
569 self.meta = meta.into_option();
570 self
571 }
572}
573
574#[cfg(feature = "unstable_auth_status")]
584#[serde_as]
585#[skip_serializing_none]
586#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
587#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
588#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "client", "x-method" = AUTH_STATUS_UPDATE_NOTIFICATION)))]
589#[serde(rename_all = "camelCase")]
590#[non_exhaustive]
591pub struct AuthStatusUpdateNotification {
592 pub state: AuthState,
597 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
603 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
604 #[serde(default, skip_serializing_if = "Vec::is_empty")]
605 pub accounts: Vec<AuthAccount>,
606 #[serde_as(deserialize_as = "DefaultOnError")]
612 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
613 #[serde(default)]
614 #[serde(rename = "_meta")]
615 pub meta: Option<Meta>,
616}
617
618#[cfg(feature = "unstable_auth_status")]
619impl AuthStatusUpdateNotification {
620 #[must_use]
622 pub fn new(state: AuthState) -> Self {
623 Self {
624 state,
625 accounts: vec![],
626 meta: None,
627 }
628 }
629
630 #[must_use]
632 pub fn accounts(mut self, accounts: Vec<AuthAccount>) -> Self {
633 self.accounts = accounts;
634 self
635 }
636
637 #[must_use]
643 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
644 self.meta = meta.into_option();
645 self
646 }
647}
648
649#[cfg(feature = "unstable_auth_status")]
655#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
656#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
657#[serde(rename_all = "snake_case")]
658#[non_exhaustive]
659pub enum AuthState {
660 Authenticated,
662 Unauthenticated,
665 NotRequired,
667 Unknown,
669 #[serde(untagged)]
675 Other(String),
676}
677
678#[cfg(feature = "unstable_auth_status")]
689#[serde_as]
690#[skip_serializing_none]
691#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
692#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
693#[serde(rename_all = "camelCase")]
694#[non_exhaustive]
695pub struct AuthAccount {
696 pub label: String,
699 #[serde_as(deserialize_as = "DefaultOnError")]
704 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
705 #[serde(default)]
706 pub description: Option<String>,
707 #[serde_as(deserialize_as = "DefaultOnError")]
713 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
714 #[serde(default)]
715 pub active: Option<bool>,
716 #[serde_as(deserialize_as = "DefaultOnError")]
720 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
721 #[serde(default)]
722 pub name: Option<String>,
723 #[serde_as(deserialize_as = "DefaultOnError")]
727 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
728 #[serde(default)]
729 pub email: 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 organization: Option<String>,
737 #[serde_as(deserialize_as = "DefaultOnError")]
743 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
744 #[serde(default)]
745 #[serde(rename = "_meta")]
746 pub meta: Option<Meta>,
747}
748
749#[cfg(feature = "unstable_auth_status")]
750impl AuthAccount {
751 #[must_use]
753 pub fn new(label: impl Into<String>) -> Self {
754 Self {
755 label: label.into(),
756 description: None,
757 active: None,
758 name: None,
759 email: None,
760 organization: None,
761 meta: None,
762 }
763 }
764
765 #[must_use]
767 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
768 self.description = description.into_option();
769 self
770 }
771
772 #[must_use]
774 pub fn active(mut self, active: impl IntoOption<bool>) -> Self {
775 self.active = active.into_option();
776 self
777 }
778
779 #[must_use]
781 pub fn name(mut self, name: impl IntoOption<String>) -> Self {
782 self.name = name.into_option();
783 self
784 }
785
786 #[must_use]
788 pub fn email(mut self, email: impl IntoOption<String>) -> Self {
789 self.email = email.into_option();
790 self
791 }
792
793 #[must_use]
795 pub fn organization(mut self, organization: impl IntoOption<String>) -> Self {
796 self.organization = organization.into_option();
797 self
798 }
799
800 #[must_use]
806 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
807 self.meta = meta.into_option();
808 self
809 }
810}
811
812#[cfg(feature = "unstable_auth_status")]
820#[serde_as]
821#[skip_serializing_none]
822#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
823#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
824#[non_exhaustive]
825pub struct AuthStatusCapabilities {
826 #[serde_as(deserialize_as = "DefaultOnError")]
832 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
833 #[serde(default)]
834 #[serde(rename = "_meta")]
835 pub meta: Option<Meta>,
836}
837
838#[cfg(feature = "unstable_auth_status")]
839impl AuthStatusCapabilities {
840 #[must_use]
842 pub fn new() -> Self {
843 Self::default()
844 }
845
846 #[must_use]
852 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
853 self.meta = meta.into_option();
854 self
855 }
856}
857
858#[serde_as]
864#[skip_serializing_none]
865#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
866#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
867#[serde(rename_all = "camelCase")]
868#[non_exhaustive]
869pub struct AgentAuthCapabilities {
870 #[cfg(feature = "unstable_auth_status")]
879 #[serde_as(deserialize_as = "DefaultOnError")]
880 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
881 #[serde(default)]
882 pub status: Option<AuthStatusCapabilities>,
883 #[serde_as(deserialize_as = "DefaultOnError")]
889 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
890 #[serde(default)]
891 #[serde(rename = "_meta")]
892 pub meta: Option<Meta>,
893}
894
895impl AgentAuthCapabilities {
896 #[must_use]
898 pub fn new() -> Self {
899 Self::default()
900 }
901
902 #[cfg(feature = "unstable_auth_status")]
908 #[must_use]
909 pub fn status(mut self, status: impl IntoOption<AuthStatusCapabilities>) -> Self {
910 self.status = status.into_option();
911 self
912 }
913
914 #[must_use]
920 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
921 self.meta = meta.into_option();
922 self
923 }
924}
925
926#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
928#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Display, From)]
929#[serde(transparent)]
930#[from(forward)]
931#[non_exhaustive]
932pub struct AuthMethodId(pub Arc<str>);
933
934impl AuthMethodId {
935 #[must_use]
937 pub fn new(id: impl Into<Self>) -> Self {
938 id.into()
939 }
940}
941
942#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
946#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
947#[serde(tag = "type", rename_all = "snake_case")]
948#[non_exhaustive]
949pub enum AuthMethod {
950 Terminal(AuthMethodTerminal),
953 Agent(AuthMethodAgent),
957 #[serde(untagged)]
967 Other(OtherAuthMethod),
968}
969
970impl AuthMethod {
971 #[must_use]
973 pub fn method_id(&self) -> &AuthMethodId {
974 match self {
975 Self::Agent(a) => &a.method_id,
976 Self::Other(a) => &a.method_id,
977 Self::Terminal(t) => &t.method_id,
978 }
979 }
980
981 #[must_use]
983 pub fn name(&self) -> &str {
984 match self {
985 Self::Agent(a) => &a.name,
986 Self::Other(a) => &a.name,
987 Self::Terminal(t) => &t.name,
988 }
989 }
990
991 #[must_use]
993 pub fn description(&self) -> Option<&str> {
994 match self {
995 Self::Agent(a) => a.description.as_deref(),
996 Self::Other(a) => a
997 .fields
998 .get("description")
999 .and_then(serde_json::Value::as_str),
1000 Self::Terminal(t) => t.description.as_deref(),
1001 }
1002 }
1003
1004 #[must_use]
1010 pub fn meta(&self) -> Option<&Meta> {
1011 match self {
1012 Self::Agent(a) => a.meta.as_ref(),
1013 Self::Other(a) => a.fields.get("_meta").and_then(serde_json::Value::as_object),
1014 Self::Terminal(t) => t.meta.as_ref(),
1015 }
1016 }
1017}
1018
1019#[serde_as]
1021#[skip_serializing_none]
1022#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1023#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
1024#[cfg_attr(feature = "schemars", schemars(inline))]
1025#[cfg_attr(feature = "schemars", schemars(transform = other_auth_method_schema))]
1026#[serde(rename_all = "camelCase")]
1027#[non_exhaustive]
1028pub struct OtherAuthMethod {
1029 #[serde(rename = "type")]
1035 pub type_: String,
1036 pub method_id: AuthMethodId,
1038 pub name: String,
1040 #[serde(flatten)]
1043 pub fields: BTreeMap<String, serde_json::Value>,
1044}
1045
1046impl OtherAuthMethod {
1047 #[must_use]
1049 pub fn new(
1050 type_: impl Into<String>,
1051 method_id: impl Into<AuthMethodId>,
1052 name: impl Into<String>,
1053 mut fields: BTreeMap<String, serde_json::Value>,
1054 ) -> Self {
1055 fields.remove("type");
1056 fields.remove("methodId");
1057 fields.remove("name");
1058 Self {
1059 type_: type_.into(),
1060 method_id: method_id.into(),
1061 name: name.into(),
1062 fields,
1063 }
1064 }
1065}
1066
1067impl<'de> Deserialize<'de> for OtherAuthMethod {
1068 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1069 where
1070 D: serde::Deserializer<'de>,
1071 {
1072 #[derive(Deserialize)]
1073 #[serde(rename_all = "camelCase")]
1074 struct RawOtherAuthMethod {
1075 #[serde(rename = "type")]
1076 type_: String,
1077 method_id: AuthMethodId,
1078 name: String,
1079 #[serde(flatten)]
1080 fields: BTreeMap<String, serde_json::Value>,
1081 }
1082
1083 let raw = RawOtherAuthMethod::deserialize(deserializer)?;
1084 if is_known_auth_method_type(&raw.type_) {
1085 return Err(serde::de::Error::custom(format!(
1086 "known authentication method `{}` did not match its schema",
1087 raw.type_
1088 )));
1089 }
1090
1091 Ok(Self {
1092 type_: raw.type_,
1093 method_id: raw.method_id,
1094 name: raw.name,
1095 fields: raw.fields,
1096 })
1097 }
1098}
1099
1100fn is_known_auth_method_type(type_: &str) -> bool {
1101 matches!(type_, "agent" | "terminal")
1102}
1103
1104#[cfg(feature = "schemars")]
1105fn other_auth_method_schema(schema: &mut Schema) {
1106 super::schema_util::reject_known_string_discriminators(schema, "type", &["agent", "terminal"]);
1107}
1108
1109#[serde_as]
1113#[skip_serializing_none]
1114#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1115#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1116#[serde(rename_all = "camelCase")]
1117#[non_exhaustive]
1118pub struct AuthMethodAgent {
1119 pub method_id: AuthMethodId,
1121 pub name: String,
1123 #[serde_as(deserialize_as = "DefaultOnError")]
1127 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1128 #[serde(default)]
1129 pub description: Option<String>,
1130 #[serde_as(deserialize_as = "DefaultOnError")]
1136 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1137 #[serde(default)]
1138 #[serde(rename = "_meta")]
1139 pub meta: Option<Meta>,
1140}
1141
1142impl AuthMethodAgent {
1143 #[must_use]
1145 pub fn new(method_id: impl Into<AuthMethodId>, name: impl Into<String>) -> Self {
1146 Self {
1147 method_id: method_id.into(),
1148 name: name.into(),
1149 description: None,
1150 meta: None,
1151 }
1152 }
1153
1154 #[must_use]
1156 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
1157 self.description = description.into_option();
1158 self
1159 }
1160
1161 #[must_use]
1167 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1168 self.meta = meta.into_option();
1169 self
1170 }
1171}
1172
1173#[serde_as]
1181#[skip_serializing_none]
1182#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1183#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1184#[serde(rename_all = "camelCase")]
1185#[non_exhaustive]
1186pub struct AuthMethodTerminal {
1187 pub method_id: AuthMethodId,
1189 pub name: String,
1191 #[serde_as(deserialize_as = "DefaultOnError")]
1195 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1196 #[serde(default)]
1197 pub description: Option<String>,
1198 #[serde_as(deserialize_as = "DefaultOnNull")]
1200 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1201 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1202 pub args: Vec<String>,
1203 #[serde_as(deserialize_as = "DefaultOnNull")]
1207 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1208 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1209 pub env: Vec<EnvVariable>,
1210 #[serde_as(deserialize_as = "DefaultOnError")]
1216 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1217 #[serde(default)]
1218 #[serde(rename = "_meta")]
1219 pub meta: Option<Meta>,
1220}
1221
1222impl AuthMethodTerminal {
1223 #[must_use]
1225 pub fn new(method_id: impl Into<AuthMethodId>, name: impl Into<String>) -> Self {
1226 Self {
1227 method_id: method_id.into(),
1228 name: name.into(),
1229 description: None,
1230 args: Vec::new(),
1231 env: Vec::new(),
1232 meta: None,
1233 }
1234 }
1235
1236 #[must_use]
1238 pub fn args(mut self, args: Vec<String>) -> Self {
1239 self.args = args;
1240 self
1241 }
1242
1243 #[must_use]
1247 pub fn env(mut self, env: Vec<EnvVariable>) -> Self {
1248 self.env = env;
1249 self
1250 }
1251
1252 #[must_use]
1254 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
1255 self.description = description.into_option();
1256 self
1257 }
1258
1259 #[must_use]
1265 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1266 self.meta = meta.into_option();
1267 self
1268 }
1269}
1270
1271#[serde_as]
1277#[skip_serializing_none]
1278#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1279#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1280#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_NEW_METHOD_NAME)))]
1281#[serde(rename_all = "camelCase")]
1282#[non_exhaustive]
1283pub struct NewSessionRequest {
1284 pub cwd: AbsolutePath,
1286 #[serde_as(deserialize_as = "DefaultOnNull")]
1292 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1293 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1294 pub additional_directories: Vec<AbsolutePath>,
1295 #[serde_as(deserialize_as = "DefaultOnNull")]
1297 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1298 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1299 pub mcp_servers: Vec<McpServer>,
1300 #[serde(default)]
1306 pub system_prompt: Option<SystemPrompt>,
1307 #[cfg(feature = "unstable_session_options")]
1325 #[serde_as(deserialize_as = "DefaultOnNull")]
1326 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1327 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1328 pub config_options: Vec<InitialSessionConfigOption>,
1329 #[serde_as(deserialize_as = "DefaultOnError")]
1335 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1336 #[serde(default)]
1337 #[serde(rename = "_meta")]
1338 pub meta: Option<Meta>,
1339}
1340
1341impl NewSessionRequest {
1342 #[must_use]
1344 pub fn new(cwd: impl Into<AbsolutePath>) -> Self {
1345 Self {
1346 cwd: cwd.into(),
1347 additional_directories: vec![],
1348 mcp_servers: vec![],
1349 system_prompt: None,
1350 #[cfg(feature = "unstable_session_options")]
1351 config_options: vec![],
1352 meta: None,
1353 }
1354 }
1355
1356 #[must_use]
1358 pub fn additional_directories<I, P>(mut self, additional_directories: I) -> Self
1359 where
1360 I: IntoIterator<Item = P>,
1361 P: Into<AbsolutePath>,
1362 {
1363 self.additional_directories = additional_directories.into_iter().map(Into::into).collect();
1364 self
1365 }
1366
1367 #[must_use]
1369 pub fn mcp_servers(mut self, mcp_servers: Vec<McpServer>) -> Self {
1370 self.mcp_servers = mcp_servers;
1371 self
1372 }
1373
1374 #[must_use]
1376 pub fn system_prompt(mut self, system_prompt: impl IntoOption<SystemPrompt>) -> Self {
1377 self.system_prompt = system_prompt.into_option();
1378 self
1379 }
1380
1381 #[cfg(feature = "unstable_session_options")]
1399 #[must_use]
1400 pub fn config_options(mut self, config_options: Vec<InitialSessionConfigOption>) -> Self {
1401 self.config_options = config_options;
1402 self
1403 }
1404
1405 #[must_use]
1411 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1412 self.meta = meta.into_option();
1413 self
1414 }
1415}
1416
1417#[serde_as]
1425#[skip_serializing_none]
1426#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1427#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1428#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_NEW_METHOD_NAME)))]
1429#[serde(rename_all = "camelCase")]
1430#[non_exhaustive]
1431pub struct NewSessionResponse {
1432 pub session_id: SessionId,
1436 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
1442 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
1443 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1444 pub config_options: Vec<SessionConfigOption>,
1445 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
1451 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
1452 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1453 pub available_commands: Vec<AvailableCommand>,
1454 #[serde_as(deserialize_as = "DefaultOnError")]
1460 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1461 #[serde(default)]
1462 #[serde(rename = "_meta")]
1463 pub meta: Option<Meta>,
1464}
1465
1466impl NewSessionResponse {
1467 #[must_use]
1469 pub fn new(session_id: impl Into<SessionId>) -> Self {
1470 Self {
1471 session_id: session_id.into(),
1472 config_options: Vec::new(),
1473 available_commands: Vec::new(),
1474 meta: None,
1475 }
1476 }
1477
1478 #[must_use]
1484 pub fn config_options(mut self, config_options: Vec<SessionConfigOption>) -> Self {
1485 self.config_options = config_options;
1486 self
1487 }
1488
1489 #[must_use]
1491 pub fn available_commands(mut self, available_commands: Vec<AvailableCommand>) -> Self {
1492 self.available_commands = available_commands;
1493 self
1494 }
1495
1496 #[must_use]
1502 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1503 self.meta = meta.into_option();
1504 self
1505 }
1506}
1507
1508#[cfg(feature = "unstable_session_fork")]
1521#[serde_as]
1522#[skip_serializing_none]
1523#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1524#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1525#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_FORK_METHOD_NAME)))]
1526#[serde(rename_all = "camelCase")]
1527#[non_exhaustive]
1528pub struct ForkSessionRequest {
1529 pub session_id: SessionId,
1531 pub cwd: AbsolutePath,
1533 #[serde_as(deserialize_as = "DefaultOnNull")]
1539 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1540 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1541 pub additional_directories: Vec<AbsolutePath>,
1542 #[serde_as(deserialize_as = "DefaultOnNull")]
1544 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1545 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1546 pub mcp_servers: Vec<McpServer>,
1547 #[serde(default)]
1555 pub system_prompt: Option<SystemPrompt>,
1556 #[cfg(feature = "unstable_session_options")]
1575 #[serde_as(deserialize_as = "DefaultOnNull")]
1576 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1577 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1578 pub config_options: Vec<InitialSessionConfigOption>,
1579 #[serde_as(deserialize_as = "DefaultOnError")]
1585 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1586 #[serde(default)]
1587 #[serde(rename = "_meta")]
1588 pub meta: Option<Meta>,
1589}
1590
1591#[cfg(feature = "unstable_session_fork")]
1592impl ForkSessionRequest {
1593 #[must_use]
1595 pub fn new(session_id: impl Into<SessionId>, cwd: impl Into<AbsolutePath>) -> Self {
1596 Self {
1597 session_id: session_id.into(),
1598 cwd: cwd.into(),
1599 additional_directories: vec![],
1600 mcp_servers: vec![],
1601 system_prompt: None,
1602 #[cfg(feature = "unstable_session_options")]
1603 config_options: vec![],
1604 meta: None,
1605 }
1606 }
1607
1608 #[must_use]
1610 pub fn additional_directories<I, P>(mut self, additional_directories: I) -> Self
1611 where
1612 I: IntoIterator<Item = P>,
1613 P: Into<AbsolutePath>,
1614 {
1615 self.additional_directories = additional_directories.into_iter().map(Into::into).collect();
1616 self
1617 }
1618
1619 #[must_use]
1621 pub fn mcp_servers(mut self, mcp_servers: Vec<McpServer>) -> Self {
1622 self.mcp_servers = mcp_servers;
1623 self
1624 }
1625
1626 #[must_use]
1628 pub fn system_prompt(mut self, system_prompt: impl IntoOption<SystemPrompt>) -> Self {
1629 self.system_prompt = system_prompt.into_option();
1630 self
1631 }
1632
1633 #[cfg(feature = "unstable_session_options")]
1652 #[must_use]
1653 pub fn config_options(mut self, config_options: Vec<InitialSessionConfigOption>) -> Self {
1654 self.config_options = config_options;
1655 self
1656 }
1657
1658 #[must_use]
1664 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1665 self.meta = meta.into_option();
1666 self
1667 }
1668}
1669
1670#[cfg(feature = "unstable_session_fork")]
1676#[serde_as]
1677#[skip_serializing_none]
1678#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1679#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1680#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_FORK_METHOD_NAME)))]
1681#[serde(rename_all = "camelCase")]
1682#[non_exhaustive]
1683pub struct ForkSessionResponse {
1684 pub session_id: SessionId,
1686 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
1692 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
1693 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1694 pub config_options: Vec<SessionConfigOption>,
1695 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
1701 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
1702 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1703 pub available_commands: Vec<AvailableCommand>,
1704 #[serde_as(deserialize_as = "DefaultOnError")]
1710 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1711 #[serde(default)]
1712 #[serde(rename = "_meta")]
1713 pub meta: Option<Meta>,
1714}
1715
1716#[cfg(feature = "unstable_session_fork")]
1717impl ForkSessionResponse {
1718 #[must_use]
1720 pub fn new(session_id: impl Into<SessionId>) -> Self {
1721 Self {
1722 session_id: session_id.into(),
1723 config_options: Vec::new(),
1724 available_commands: Vec::new(),
1725 meta: None,
1726 }
1727 }
1728
1729 #[must_use]
1735 pub fn config_options(mut self, config_options: Vec<SessionConfigOption>) -> Self {
1736 self.config_options = config_options;
1737 self
1738 }
1739
1740 #[must_use]
1742 pub fn available_commands(mut self, available_commands: Vec<AvailableCommand>) -> Self {
1743 self.available_commands = available_commands;
1744 self
1745 }
1746
1747 #[must_use]
1753 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1754 self.meta = meta.into_option();
1755 self
1756 }
1757}
1758
1759#[serde_as]
1766#[skip_serializing_none]
1767#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1768#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1769#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_RESUME_METHOD_NAME)))]
1770#[serde(rename_all = "camelCase")]
1771#[non_exhaustive]
1772pub struct ResumeSessionRequest {
1773 pub session_id: SessionId,
1775 pub cwd: AbsolutePath,
1780 #[serde_as(deserialize_as = "DefaultOnNull")]
1787 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1788 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1789 pub additional_directories: Vec<AbsolutePath>,
1790 #[serde_as(deserialize_as = "DefaultOnNull")]
1795 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1796 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1797 pub mcp_servers: Vec<McpServer>,
1798 #[serde(default)]
1810 pub replay_from: Option<ReplayFrom>,
1811 #[serde(default)]
1819 pub system_prompt: Option<SystemPrompt>,
1820 #[cfg(feature = "unstable_session_options")]
1841 #[serde_as(deserialize_as = "DefaultOnNull")]
1842 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
1843 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1844 pub config_options: Vec<InitialSessionConfigOption>,
1845 #[serde_as(deserialize_as = "DefaultOnError")]
1851 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1852 #[serde(default)]
1853 #[serde(rename = "_meta")]
1854 pub meta: Option<Meta>,
1855}
1856
1857impl ResumeSessionRequest {
1858 #[must_use]
1860 pub fn new(session_id: impl Into<SessionId>, cwd: impl Into<AbsolutePath>) -> Self {
1861 Self {
1862 session_id: session_id.into(),
1863 cwd: cwd.into(),
1864 additional_directories: vec![],
1865 mcp_servers: vec![],
1866 replay_from: None,
1867 system_prompt: None,
1868 #[cfg(feature = "unstable_session_options")]
1869 config_options: vec![],
1870 meta: None,
1871 }
1872 }
1873
1874 #[must_use]
1876 pub fn additional_directories<I, P>(mut self, additional_directories: I) -> Self
1877 where
1878 I: IntoIterator<Item = P>,
1879 P: Into<AbsolutePath>,
1880 {
1881 self.additional_directories = additional_directories.into_iter().map(Into::into).collect();
1882 self
1883 }
1884
1885 #[must_use]
1887 pub fn mcp_servers(mut self, mcp_servers: Vec<McpServer>) -> Self {
1888 self.mcp_servers = mcp_servers;
1889 self
1890 }
1891
1892 #[must_use]
1900 pub fn replay_from(mut self, replay_from: impl IntoOption<ReplayFrom>) -> Self {
1901 self.replay_from = replay_from.into_option();
1902 self
1903 }
1904
1905 #[must_use]
1907 pub fn system_prompt(mut self, system_prompt: impl IntoOption<SystemPrompt>) -> Self {
1908 self.system_prompt = system_prompt.into_option();
1909 self
1910 }
1911
1912 #[cfg(feature = "unstable_session_options")]
1930 #[must_use]
1931 pub fn config_options(mut self, config_options: Vec<InitialSessionConfigOption>) -> Self {
1932 self.config_options = config_options;
1933 self
1934 }
1935
1936 #[must_use]
1942 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
1943 self.meta = meta.into_option();
1944 self
1945 }
1946}
1947
1948#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1952#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1953#[serde(tag = "type", rename_all = "snake_case")]
1954#[non_exhaustive]
1955pub enum ReplayFrom {
1956 Start(ReplayFromStart),
1958 #[serde(untagged)]
1969 Other(OtherReplayFrom),
1970}
1971
1972impl From<ReplayFromStart> for ReplayFrom {
1973 fn from(replay_from: ReplayFromStart) -> Self {
1974 Self::Start(replay_from)
1975 }
1976}
1977
1978#[serde_as]
1980#[skip_serializing_none]
1981#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
1982#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1983#[serde(rename_all = "camelCase")]
1984#[non_exhaustive]
1985pub struct ReplayFromStart {
1986 #[serde_as(deserialize_as = "DefaultOnError")]
1992 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
1993 #[serde(default)]
1994 #[serde(rename = "_meta")]
1995 pub meta: Option<Meta>,
1996}
1997
1998impl ReplayFromStart {
1999 #[must_use]
2001 pub fn new() -> Self {
2002 Self::default()
2003 }
2004
2005 #[must_use]
2011 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2012 self.meta = meta.into_option();
2013 self
2014 }
2015}
2016
2017#[serde_as]
2019#[skip_serializing_none]
2020#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2021#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
2022#[cfg_attr(feature = "schemars", schemars(inline))]
2023#[cfg_attr(feature = "schemars", schemars(transform = other_replay_from_schema))]
2024#[serde(rename_all = "camelCase")]
2025#[non_exhaustive]
2026pub struct OtherReplayFrom {
2027 #[serde(rename = "type")]
2033 pub type_: String,
2034 #[serde(flatten)]
2037 pub fields: BTreeMap<String, serde_json::Value>,
2038}
2039
2040impl OtherReplayFrom {
2041 #[must_use]
2043 pub fn new(type_: impl Into<String>, mut fields: BTreeMap<String, serde_json::Value>) -> Self {
2044 fields.remove("type");
2045 Self {
2046 type_: type_.into(),
2047 fields,
2048 }
2049 }
2050}
2051
2052impl<'de> Deserialize<'de> for OtherReplayFrom {
2053 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
2054 where
2055 D: serde::Deserializer<'de>,
2056 {
2057 let mut fields = BTreeMap::<String, serde_json::Value>::deserialize(deserializer)?;
2058 let type_ = fields
2059 .remove("type")
2060 .ok_or_else(|| serde::de::Error::missing_field("type"))?;
2061 let serde_json::Value::String(type_) = type_ else {
2062 return Err(serde::de::Error::custom("`type` must be a string"));
2063 };
2064
2065 if is_known_replay_from_type(&type_) {
2066 return Err(serde::de::Error::custom(format!(
2067 "known replay cursor `{type_}` did not match its schema"
2068 )));
2069 }
2070
2071 Ok(Self { type_, fields })
2072 }
2073}
2074
2075fn is_known_replay_from_type(type_: &str) -> bool {
2076 matches!(type_, "start")
2077}
2078
2079#[cfg(feature = "schemars")]
2080fn other_replay_from_schema(schema: &mut Schema) {
2081 super::schema_util::reject_known_string_discriminators(schema, "type", &["start"]);
2082}
2083
2084crate::serde_util::default_on_null! {
2085 #[serde_as]
2093 #[skip_serializing_none]
2094 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2095 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2096 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_RESUME_METHOD_NAME)))]
2097 #[serde(rename_all = "camelCase")]
2098 #[non_exhaustive]
2099 pub struct ResumeSessionResponse {
2100 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
2106 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
2107 #[serde(default, skip_serializing_if = "Vec::is_empty")]
2108 pub config_options: Vec<SessionConfigOption>,
2109 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
2115 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
2116 #[serde(default, skip_serializing_if = "Vec::is_empty")]
2117 pub available_commands: Vec<AvailableCommand>,
2118 #[serde_as(deserialize_as = "DefaultOnError")]
2124 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2125 #[serde(default)]
2126 #[serde(rename = "_meta")]
2127 pub meta: Option<Meta>,
2128 }
2129}
2130
2131impl ResumeSessionResponse {
2132 #[must_use]
2134 pub fn new() -> Self {
2135 Self::default()
2136 }
2137
2138 #[must_use]
2144 pub fn config_options(mut self, config_options: Vec<SessionConfigOption>) -> Self {
2145 self.config_options = config_options;
2146 self
2147 }
2148
2149 #[must_use]
2151 pub fn available_commands(mut self, available_commands: Vec<AvailableCommand>) -> Self {
2152 self.available_commands = available_commands;
2153 self
2154 }
2155
2156 #[must_use]
2162 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2163 self.meta = meta.into_option();
2164 self
2165 }
2166}
2167
2168#[serde_as]
2191#[skip_serializing_none]
2192#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2193#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2194#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_CLOSE_METHOD_NAME)))]
2195#[serde(rename_all = "camelCase")]
2196#[non_exhaustive]
2197pub struct CloseSessionRequest {
2198 pub session_id: SessionId,
2200 #[serde_as(deserialize_as = "DefaultOnError")]
2206 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2207 #[serde(default)]
2208 #[serde(rename = "_meta")]
2209 pub meta: Option<Meta>,
2210}
2211
2212impl CloseSessionRequest {
2213 #[must_use]
2215 pub fn new(session_id: impl Into<SessionId>) -> Self {
2216 Self {
2217 session_id: session_id.into(),
2218 meta: None,
2219 }
2220 }
2221
2222 #[must_use]
2228 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2229 self.meta = meta.into_option();
2230 self
2231 }
2232}
2233
2234crate::serde_util::default_on_null! {
2235 #[serde_as]
2237 #[skip_serializing_none]
2238 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2239 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2240 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_CLOSE_METHOD_NAME)))]
2241 #[serde(rename_all = "camelCase")]
2242 #[non_exhaustive]
2243 pub struct CloseSessionResponse {
2244 #[serde_as(deserialize_as = "DefaultOnError")]
2250 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2251 #[serde(default)]
2252 #[serde(rename = "_meta")]
2253 pub meta: Option<Meta>,
2254 }
2255}
2256
2257impl CloseSessionResponse {
2258 #[must_use]
2260 pub fn new() -> Self {
2261 Self::default()
2262 }
2263
2264 #[must_use]
2270 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2271 self.meta = meta.into_option();
2272 self
2273 }
2274}
2275
2276#[cfg(feature = "unstable_session_status")]
2290#[serde_as]
2291#[skip_serializing_none]
2292#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2293#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2294#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_STATUS_METHOD_NAME)))]
2295#[serde(rename_all = "camelCase")]
2296#[non_exhaustive]
2297pub struct SessionStatusRequest {
2298 pub session_id: SessionId,
2300 #[serde_as(deserialize_as = "DefaultOnError")]
2306 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2307 #[serde(default)]
2308 #[serde(rename = "_meta")]
2309 pub meta: Option<Meta>,
2310}
2311
2312#[cfg(feature = "unstable_session_status")]
2313impl SessionStatusRequest {
2314 #[must_use]
2316 pub fn new(session_id: impl Into<SessionId>) -> Self {
2317 Self {
2318 session_id: session_id.into(),
2319 meta: None,
2320 }
2321 }
2322
2323 #[must_use]
2329 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2330 self.meta = meta.into_option();
2331 self
2332 }
2333}
2334
2335#[cfg(feature = "unstable_session_status")]
2344#[serde_as]
2345#[skip_serializing_none]
2346#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2347#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2348#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_STATUS_METHOD_NAME)))]
2349#[serde(rename_all = "camelCase")]
2350#[non_exhaustive]
2351pub struct SessionStatusResponse {
2352 pub status: SessionStatus,
2356 #[serde_as(deserialize_as = "DefaultOnError")]
2364 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2365 #[serde(default)]
2366 pub state: Option<StateUpdate>,
2367 #[serde_as(deserialize_as = "DefaultOnError")]
2373 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2374 #[serde(default)]
2375 #[serde(rename = "_meta")]
2376 pub meta: Option<Meta>,
2377}
2378
2379#[cfg(feature = "unstable_session_status")]
2380impl SessionStatusResponse {
2381 #[must_use]
2383 pub fn new(status: SessionStatus) -> Self {
2384 Self {
2385 status,
2386 state: None,
2387 meta: None,
2388 }
2389 }
2390
2391 #[must_use]
2394 pub fn state(mut self, state: impl IntoOption<StateUpdate>) -> Self {
2395 self.state = state.into_option();
2396 self
2397 }
2398
2399 #[must_use]
2405 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2406 self.meta = meta.into_option();
2407 self
2408 }
2409}
2410
2411#[cfg(feature = "unstable_session_status")]
2417#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2418#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2419#[serde(rename_all = "snake_case")]
2420#[non_exhaustive]
2421pub enum SessionStatus {
2422 Open,
2429 Saved,
2433 #[serde(untagged)]
2440 Other(String),
2441}
2442
2443#[cfg(feature = "unstable_session_options")]
2457#[serde_as]
2458#[skip_serializing_none]
2459#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2460#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2461#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_OPTIONS_METHOD_NAME)))]
2462#[serde(rename_all = "camelCase")]
2463#[non_exhaustive]
2464pub struct SessionOptionsRequest {
2465 pub cwd: AbsolutePath,
2467 #[serde_as(deserialize_as = "DefaultOnNull")]
2471 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
2472 #[serde(default, skip_serializing_if = "Vec::is_empty")]
2473 pub additional_directories: Vec<AbsolutePath>,
2474 #[serde(default)]
2481 pub session_id: Option<SessionId>,
2482 #[serde_as(deserialize_as = "DefaultOnError")]
2488 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2489 #[serde(default)]
2490 #[serde(rename = "_meta")]
2491 pub meta: Option<Meta>,
2492}
2493
2494#[cfg(feature = "unstable_session_options")]
2495impl SessionOptionsRequest {
2496 #[must_use]
2498 pub fn new(cwd: impl Into<AbsolutePath>) -> Self {
2499 Self {
2500 cwd: cwd.into(),
2501 additional_directories: vec![],
2502 session_id: None,
2503 meta: None,
2504 }
2505 }
2506
2507 #[must_use]
2509 pub fn additional_directories<I, P>(mut self, additional_directories: I) -> Self
2510 where
2511 I: IntoIterator<Item = P>,
2512 P: Into<AbsolutePath>,
2513 {
2514 self.additional_directories = additional_directories.into_iter().map(Into::into).collect();
2515 self
2516 }
2517
2518 #[must_use]
2520 pub fn session_id(mut self, session_id: impl IntoOption<SessionId>) -> Self {
2521 self.session_id = session_id.into_option();
2522 self
2523 }
2524
2525 #[must_use]
2531 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2532 self.meta = meta.into_option();
2533 self
2534 }
2535}
2536
2537#[cfg(feature = "unstable_session_options")]
2538crate::serde_util::default_on_null! {
2539 #[serde_as]
2548 #[skip_serializing_none]
2549 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2550 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2551 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_OPTIONS_METHOD_NAME)))]
2552 #[serde(rename_all = "camelCase")]
2553 #[non_exhaustive]
2554 pub struct SessionOptionsResponse {
2555 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
2561 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
2562 #[serde(default, skip_serializing_if = "Vec::is_empty")]
2563 pub config_options: Vec<SessionConfigOption>,
2564 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
2573 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
2574 #[serde(default, skip_serializing_if = "Vec::is_empty")]
2575 pub available_commands: Vec<AvailableCommand>,
2576 #[serde_as(deserialize_as = "DefaultOnError")]
2582 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2583 #[serde(default)]
2584 #[serde(rename = "_meta")]
2585 pub meta: Option<Meta>,
2586 }
2587}
2588
2589#[cfg(feature = "unstable_session_options")]
2590impl SessionOptionsResponse {
2591 #[must_use]
2593 pub fn new() -> Self {
2594 Self::default()
2595 }
2596
2597 #[must_use]
2599 pub fn config_options(mut self, config_options: Vec<SessionConfigOption>) -> Self {
2600 self.config_options = config_options;
2601 self
2602 }
2603
2604 #[must_use]
2606 pub fn available_commands(mut self, available_commands: Vec<AvailableCommand>) -> Self {
2607 self.available_commands = available_commands;
2608 self
2609 }
2610
2611 #[must_use]
2617 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2618 self.meta = meta.into_option();
2619 self
2620 }
2621}
2622
2623#[cfg(feature = "unstable_session_options")]
2633#[serde_as]
2634#[skip_serializing_none]
2635#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2636#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2637#[serde(rename_all = "camelCase")]
2638#[non_exhaustive]
2639pub struct InitialSessionConfigOption {
2640 pub config_id: SessionConfigId,
2642 #[serde(flatten)]
2647 pub value: SessionConfigOptionValue,
2648 #[serde_as(deserialize_as = "DefaultOnError")]
2654 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2655 #[serde(default)]
2656 #[serde(rename = "_meta")]
2657 pub meta: Option<Meta>,
2658}
2659
2660#[cfg(feature = "unstable_session_options")]
2661impl InitialSessionConfigOption {
2662 #[must_use]
2664 pub fn new(
2665 config_id: impl Into<SessionConfigId>,
2666 value: impl Into<SessionConfigOptionValue>,
2667 ) -> Self {
2668 Self {
2669 config_id: config_id.into(),
2670 value: value.into(),
2671 meta: None,
2672 }
2673 }
2674
2675 #[must_use]
2681 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2682 self.meta = meta.into_option();
2683 self
2684 }
2685}
2686
2687#[serde_as]
2702#[skip_serializing_none]
2703#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2704#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2705#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = TOOL_CALL_CANCEL_METHOD_NAME)))]
2706#[serde(rename_all = "camelCase")]
2707#[non_exhaustive]
2708pub struct CancelToolCallRequest {
2709 pub session_id: SessionId,
2711 pub tool_call_id: ToolCallId,
2713 #[serde_as(deserialize_as = "DefaultOnError")]
2719 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2720 #[serde(default)]
2721 #[serde(rename = "_meta")]
2722 pub meta: Option<Meta>,
2723}
2724
2725impl CancelToolCallRequest {
2726 #[must_use]
2728 pub fn new(session_id: impl Into<SessionId>, tool_call_id: impl Into<ToolCallId>) -> Self {
2729 Self {
2730 session_id: session_id.into(),
2731 tool_call_id: tool_call_id.into(),
2732 meta: None,
2733 }
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
2748crate::serde_util::default_on_null! {
2749 #[serde_as]
2751 #[skip_serializing_none]
2752 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2753 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2754 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = TOOL_CALL_CANCEL_METHOD_NAME)))]
2755 #[serde(rename_all = "camelCase")]
2756 #[non_exhaustive]
2757 pub struct CancelToolCallResponse {
2758 #[serde_as(deserialize_as = "DefaultOnError")]
2764 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2765 #[serde(default)]
2766 #[serde(rename = "_meta")]
2767 pub meta: Option<Meta>,
2768 }
2769}
2770
2771impl CancelToolCallResponse {
2772 #[must_use]
2774 pub fn new() -> Self {
2775 Self::default()
2776 }
2777
2778 #[must_use]
2784 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2785 self.meta = meta.into_option();
2786 self
2787 }
2788}
2789
2790#[serde_as]
2806#[skip_serializing_none]
2807#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2808#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
2809#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = TERMINAL_CANCEL_METHOD_NAME)))]
2810#[serde(rename_all = "camelCase")]
2811#[non_exhaustive]
2812pub struct CancelTerminalRequest {
2813 pub session_id: SessionId,
2815 pub terminal_id: TerminalId,
2817 #[serde_as(deserialize_as = "DefaultOnError")]
2823 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2824 #[serde(default)]
2825 #[serde(rename = "_meta")]
2826 pub meta: Option<Meta>,
2827}
2828
2829impl CancelTerminalRequest {
2830 #[must_use]
2832 pub fn new(session_id: impl Into<SessionId>, terminal_id: impl Into<TerminalId>) -> Self {
2833 Self {
2834 session_id: session_id.into(),
2835 terminal_id: terminal_id.into(),
2836 meta: None,
2837 }
2838 }
2839
2840 #[must_use]
2846 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2847 self.meta = meta.into_option();
2848 self
2849 }
2850}
2851
2852crate::serde_util::default_on_null! {
2853 #[serde_as]
2855 #[skip_serializing_none]
2856 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2857 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2858 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = TERMINAL_CANCEL_METHOD_NAME)))]
2859 #[serde(rename_all = "camelCase")]
2860 #[non_exhaustive]
2861 pub struct CancelTerminalResponse {
2862 #[serde_as(deserialize_as = "DefaultOnError")]
2868 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2869 #[serde(default)]
2870 #[serde(rename = "_meta")]
2871 pub meta: Option<Meta>,
2872 }
2873}
2874
2875impl CancelTerminalResponse {
2876 #[must_use]
2878 pub fn new() -> Self {
2879 Self::default()
2880 }
2881
2882 #[must_use]
2888 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
2889 self.meta = meta.into_option();
2890 self
2891 }
2892}
2893
2894#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2898#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Display, From)]
2899#[serde(transparent)]
2900#[from(Arc<str>, String, &str, &mut str, Box<str>, Cow<'_, str>)]
2901#[non_exhaustive]
2902pub struct SessionListCursor(pub Arc<str>);
2903
2904impl SessionListCursor {
2905 #[must_use]
2907 pub fn new(cursor: impl Into<Self>) -> Self {
2908 cursor.into()
2909 }
2910}
2911
2912impl AsRef<str> for SessionListCursor {
2913 fn as_ref(&self) -> &str {
2914 &self.0
2915 }
2916}
2917
2918impl From<&String> for SessionListCursor {
2919 fn from(cursor: &String) -> Self {
2920 Self(cursor.as_str().into())
2921 }
2922}
2923
2924macro_rules! impl_session_list_cursor_option_conversion {
2925 ($source:ty) => {
2926 impl IntoOption<SessionListCursor> for $source {
2927 fn into_option(self) -> Option<SessionListCursor> {
2928 Some(self.into())
2929 }
2930 }
2931 };
2932}
2933
2934impl_session_list_cursor_option_conversion!(Arc<str>);
2935impl_session_list_cursor_option_conversion!(String);
2936impl_session_list_cursor_option_conversion!(&str);
2937impl_session_list_cursor_option_conversion!(&mut str);
2938impl_session_list_cursor_option_conversion!(&String);
2939impl_session_list_cursor_option_conversion!(Box<str>);
2940impl_session_list_cursor_option_conversion!(Cow<'_, str>);
2941
2942crate::serde_util::default_on_null! {
2943 #[serde_as]
2945 #[skip_serializing_none]
2946 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2947 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
2948 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_LIST_METHOD_NAME)))]
2949 #[serde(rename_all = "camelCase")]
2950 #[non_exhaustive]
2951 pub struct ListSessionsRequest {
2952 #[serde(default)]
2959 pub cwd: Option<AbsolutePath>,
2960 #[serde(default)]
2964 pub cursor: Option<SessionListCursor>,
2965 #[cfg(feature = "unstable_session_archive")]
2975 #[serde(default)]
2976 pub archived: Option<SessionArchiveFilter>,
2977 #[serde_as(deserialize_as = "DefaultOnError")]
2983 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
2984 #[serde(default)]
2985 #[serde(rename = "_meta")]
2986 pub meta: Option<Meta>,
2987 }
2988}
2989
2990impl ListSessionsRequest {
2991 #[must_use]
2993 pub fn new() -> Self {
2994 Self::default()
2995 }
2996
2997 #[must_use]
2999 pub fn cwd(mut self, cwd: impl IntoOption<AbsolutePath>) -> Self {
3000 self.cwd = cwd.into_option();
3001 self
3002 }
3003
3004 #[must_use]
3006 pub fn cursor(mut self, cursor: impl IntoOption<SessionListCursor>) -> Self {
3007 self.cursor = cursor.into_option();
3008 self
3009 }
3010
3011 #[cfg(feature = "unstable_session_archive")]
3017 #[must_use]
3018 pub fn archived(mut self, archived: impl IntoOption<SessionArchiveFilter>) -> Self {
3019 self.archived = archived.into_option();
3020 self
3021 }
3022
3023 #[must_use]
3029 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3030 self.meta = meta.into_option();
3031 self
3032 }
3033}
3034
3035#[serde_as]
3037#[skip_serializing_none]
3038#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3039#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3040#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_LIST_METHOD_NAME)))]
3041#[serde(rename_all = "camelCase")]
3042#[non_exhaustive]
3043pub struct ListSessionsResponse {
3044 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
3046 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
3047 pub sessions: Vec<SessionInfo>,
3048 #[serde(default)]
3052 pub next_cursor: Option<SessionListCursor>,
3053 #[serde_as(deserialize_as = "DefaultOnError")]
3059 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3060 #[serde(default)]
3061 #[serde(rename = "_meta")]
3062 pub meta: Option<Meta>,
3063}
3064
3065impl ListSessionsResponse {
3066 #[must_use]
3068 pub fn new(sessions: Vec<SessionInfo>) -> Self {
3069 Self {
3070 sessions,
3071 next_cursor: None,
3072 meta: None,
3073 }
3074 }
3075
3076 #[must_use]
3078 pub fn next_cursor(mut self, next_cursor: impl IntoOption<SessionListCursor>) -> Self {
3079 self.next_cursor = next_cursor.into_option();
3080 self
3081 }
3082
3083 #[must_use]
3089 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3090 self.meta = meta.into_option();
3091 self
3092 }
3093}
3094
3095#[serde_as]
3101#[skip_serializing_none]
3102#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3103#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3104#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_DELETE_METHOD_NAME)))]
3105#[serde(rename_all = "camelCase")]
3106#[non_exhaustive]
3107pub struct DeleteSessionRequest {
3108 pub session_id: SessionId,
3110 #[serde_as(deserialize_as = "DefaultOnError")]
3116 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3117 #[serde(default)]
3118 #[serde(rename = "_meta")]
3119 pub meta: Option<Meta>,
3120}
3121
3122impl DeleteSessionRequest {
3123 #[must_use]
3125 pub fn new(session_id: impl Into<SessionId>) -> Self {
3126 Self {
3127 session_id: session_id.into(),
3128 meta: None,
3129 }
3130 }
3131
3132 #[must_use]
3138 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3139 self.meta = meta.into_option();
3140 self
3141 }
3142}
3143
3144crate::serde_util::default_on_null! {
3145 #[serde_as]
3147 #[skip_serializing_none]
3148 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3149 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
3150 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_DELETE_METHOD_NAME)))]
3151 #[serde(rename_all = "camelCase")]
3152 #[non_exhaustive]
3153 pub struct DeleteSessionResponse {
3154 #[serde_as(deserialize_as = "DefaultOnError")]
3160 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3161 #[serde(default)]
3162 #[serde(rename = "_meta")]
3163 pub meta: Option<Meta>,
3164 }
3165}
3166
3167impl DeleteSessionResponse {
3168 #[must_use]
3170 pub fn new() -> Self {
3171 Self::default()
3172 }
3173
3174 #[must_use]
3180 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3181 self.meta = meta.into_option();
3182 self
3183 }
3184}
3185
3186#[cfg(feature = "unstable_session_archive")]
3202#[serde_as]
3203#[skip_serializing_none]
3204#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3205#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3206#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_ARCHIVE_METHOD_NAME)))]
3207#[serde(rename_all = "camelCase")]
3208#[non_exhaustive]
3209pub struct ArchiveSessionRequest {
3210 pub session_id: SessionId,
3212 #[serde_as(deserialize_as = "DefaultOnError")]
3218 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3219 #[serde(default)]
3220 #[serde(rename = "_meta")]
3221 pub meta: Option<Meta>,
3222}
3223
3224#[cfg(feature = "unstable_session_archive")]
3225impl ArchiveSessionRequest {
3226 #[must_use]
3228 pub fn new(session_id: impl Into<SessionId>) -> Self {
3229 Self {
3230 session_id: session_id.into(),
3231 meta: None,
3232 }
3233 }
3234
3235 #[must_use]
3241 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3242 self.meta = meta.into_option();
3243 self
3244 }
3245}
3246
3247#[cfg(feature = "unstable_session_archive")]
3248crate::serde_util::default_on_null! {
3249 #[serde_as]
3255 #[skip_serializing_none]
3256 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3257 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
3258 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_ARCHIVE_METHOD_NAME)))]
3259 #[serde(rename_all = "camelCase")]
3260 #[non_exhaustive]
3261 pub struct ArchiveSessionResponse {
3262 #[serde_as(deserialize_as = "DefaultOnError")]
3268 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3269 #[serde(default)]
3270 #[serde(rename = "_meta")]
3271 pub meta: Option<Meta>,
3272 }
3273}
3274
3275#[cfg(feature = "unstable_session_archive")]
3276impl ArchiveSessionResponse {
3277 #[must_use]
3279 pub fn new() -> Self {
3280 Self::default()
3281 }
3282
3283 #[must_use]
3289 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3290 self.meta = meta.into_option();
3291 self
3292 }
3293}
3294
3295#[cfg(feature = "unstable_session_archive")]
3310#[serde_as]
3311#[skip_serializing_none]
3312#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3313#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3314#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_UNARCHIVE_METHOD_NAME)))]
3315#[serde(rename_all = "camelCase")]
3316#[non_exhaustive]
3317pub struct UnarchiveSessionRequest {
3318 pub session_id: SessionId,
3320 #[serde_as(deserialize_as = "DefaultOnError")]
3326 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3327 #[serde(default)]
3328 #[serde(rename = "_meta")]
3329 pub meta: Option<Meta>,
3330}
3331
3332#[cfg(feature = "unstable_session_archive")]
3333impl UnarchiveSessionRequest {
3334 #[must_use]
3336 pub fn new(session_id: impl Into<SessionId>) -> Self {
3337 Self {
3338 session_id: session_id.into(),
3339 meta: None,
3340 }
3341 }
3342
3343 #[must_use]
3349 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3350 self.meta = meta.into_option();
3351 self
3352 }
3353}
3354
3355#[cfg(feature = "unstable_session_archive")]
3356crate::serde_util::default_on_null! {
3357 #[serde_as]
3363 #[skip_serializing_none]
3364 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3365 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
3366 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_UNARCHIVE_METHOD_NAME)))]
3367 #[serde(rename_all = "camelCase")]
3368 #[non_exhaustive]
3369 pub struct UnarchiveSessionResponse {
3370 #[serde_as(deserialize_as = "DefaultOnError")]
3376 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3377 #[serde(default)]
3378 #[serde(rename = "_meta")]
3379 pub meta: Option<Meta>,
3380 }
3381}
3382
3383#[cfg(feature = "unstable_session_archive")]
3384impl UnarchiveSessionResponse {
3385 #[must_use]
3387 pub fn new() -> Self {
3388 Self::default()
3389 }
3390
3391 #[must_use]
3397 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3398 self.meta = meta.into_option();
3399 self
3400 }
3401}
3402
3403#[cfg(feature = "unstable_session_archive")]
3412#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3413#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
3414#[serde(rename_all = "snake_case")]
3415#[non_exhaustive]
3416pub enum SessionArchiveFilter {
3417 #[default]
3419 Exclude,
3420 Include,
3422 Only,
3424 #[serde(untagged)]
3430 Other(String),
3431}
3432
3433#[serde_as]
3435#[skip_serializing_none]
3436#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3437#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3438#[serde(rename_all = "camelCase")]
3439#[non_exhaustive]
3440pub struct SessionInfo {
3441 pub session_id: SessionId,
3443 pub cwd: AbsolutePath,
3445 #[serde_as(deserialize_as = "DefaultOnNull")]
3451 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
3452 #[serde(default, skip_serializing_if = "Vec::is_empty")]
3453 pub additional_directories: Vec<AbsolutePath>,
3454
3455 #[serde_as(deserialize_as = "DefaultOnError")]
3459 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3460 #[serde(default)]
3461 pub title: Option<String>,
3462 #[serde_as(deserialize_as = "DefaultOnError")]
3466 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "format" = "date-time")))]
3467 #[serde(default)]
3468 pub updated_at: Option<String>,
3469 #[cfg(feature = "unstable_session_archive")]
3478 #[serde_as(deserialize_as = "DefaultOnError")]
3479 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3480 #[serde(default)]
3481 pub archived: Option<bool>,
3482 #[serde_as(deserialize_as = "DefaultOnError")]
3488 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3489 #[serde(default)]
3490 #[serde(rename = "_meta")]
3491 pub meta: Option<Meta>,
3492}
3493
3494impl SessionInfo {
3495 #[must_use]
3497 pub fn new(session_id: impl Into<SessionId>, cwd: impl Into<AbsolutePath>) -> Self {
3498 Self {
3499 session_id: session_id.into(),
3500 cwd: cwd.into(),
3501 additional_directories: vec![],
3502 title: None,
3503 updated_at: None,
3504 #[cfg(feature = "unstable_session_archive")]
3505 archived: None,
3506 meta: None,
3507 }
3508 }
3509
3510 #[must_use]
3512 pub fn additional_directories<I, P>(mut self, additional_directories: I) -> Self
3513 where
3514 I: IntoIterator<Item = P>,
3515 P: Into<AbsolutePath>,
3516 {
3517 self.additional_directories = additional_directories.into_iter().map(Into::into).collect();
3518 self
3519 }
3520
3521 #[must_use]
3523 pub fn title(mut self, title: impl IntoOption<String>) -> Self {
3524 self.title = title.into_option();
3525 self
3526 }
3527
3528 #[must_use]
3530 pub fn updated_at(mut self, updated_at: impl IntoOption<String>) -> Self {
3531 self.updated_at = updated_at.into_option();
3532 self
3533 }
3534
3535 #[cfg(feature = "unstable_session_archive")]
3541 #[must_use]
3542 pub fn archived(mut self, archived: impl IntoOption<bool>) -> Self {
3543 self.archived = archived.into_option();
3544 self
3545 }
3546
3547 #[must_use]
3553 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3554 self.meta = meta.into_option();
3555 self
3556 }
3557}
3558
3559#[cfg(feature = "unstable_session_set_title")]
3575#[serde_as]
3576#[skip_serializing_none]
3577#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3578#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3579#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_TITLE_METHOD_NAME)))]
3580#[serde(rename_all = "camelCase")]
3581#[non_exhaustive]
3582pub struct SetSessionTitleRequest {
3583 pub session_id: SessionId,
3585 pub title: String,
3592 #[serde_as(deserialize_as = "DefaultOnError")]
3598 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3599 #[serde(default)]
3600 #[serde(rename = "_meta")]
3601 pub meta: Option<Meta>,
3602}
3603
3604#[cfg(feature = "unstable_session_set_title")]
3605impl SetSessionTitleRequest {
3606 #[must_use]
3608 pub fn new(session_id: impl Into<SessionId>, title: impl Into<String>) -> Self {
3609 Self {
3610 session_id: session_id.into(),
3611 title: title.into(),
3612 meta: None,
3613 }
3614 }
3615
3616 #[must_use]
3622 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3623 self.meta = meta.into_option();
3624 self
3625 }
3626}
3627
3628#[cfg(feature = "unstable_session_set_title")]
3634#[serde_as]
3635#[skip_serializing_none]
3636#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3637#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3638#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_TITLE_METHOD_NAME)))]
3639#[serde(rename_all = "camelCase")]
3640#[non_exhaustive]
3641pub struct SetSessionTitleResponse {
3642 pub title: String,
3647 #[serde_as(deserialize_as = "DefaultOnError")]
3653 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3654 #[serde(default)]
3655 #[serde(rename = "_meta")]
3656 pub meta: Option<Meta>,
3657}
3658
3659#[cfg(feature = "unstable_session_set_title")]
3660impl SetSessionTitleResponse {
3661 #[must_use]
3663 pub fn new(title: impl Into<String>) -> Self {
3664 Self {
3665 title: title.into(),
3666 meta: None,
3667 }
3668 }
3669
3670 #[must_use]
3676 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3677 self.meta = meta.into_option();
3678 self
3679 }
3680}
3681
3682#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3686#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, From, Display)]
3687#[serde(transparent)]
3688#[from(forward)]
3689#[non_exhaustive]
3690pub struct SessionConfigId(pub Arc<str>);
3691
3692impl SessionConfigId {
3693 #[must_use]
3695 pub fn new(id: impl Into<Self>) -> Self {
3696 id.into()
3697 }
3698}
3699
3700#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3702#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, From, Display)]
3703#[serde(transparent)]
3704#[from(forward)]
3705#[non_exhaustive]
3706pub struct SessionConfigValueId(pub Arc<str>);
3707
3708impl SessionConfigValueId {
3709 #[must_use]
3711 pub fn new(id: impl Into<Self>) -> Self {
3712 id.into()
3713 }
3714}
3715
3716#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3718#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, From, Display)]
3719#[serde(transparent)]
3720#[from(forward)]
3721#[non_exhaustive]
3722pub struct SessionConfigGroupId(pub Arc<str>);
3723
3724impl SessionConfigGroupId {
3725 #[must_use]
3727 pub fn new(id: impl Into<Self>) -> Self {
3728 id.into()
3729 }
3730}
3731
3732#[serde_as]
3734#[skip_serializing_none]
3735#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3736#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3737#[serde(rename_all = "camelCase")]
3738#[non_exhaustive]
3739pub struct SessionConfigSelectOption {
3740 pub value: SessionConfigValueId,
3742 pub name: String,
3744 #[serde_as(deserialize_as = "DefaultOnError")]
3748 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3749 #[serde(default)]
3750 pub description: Option<String>,
3751 #[serde_as(deserialize_as = "DefaultOnError")]
3757 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3758 #[serde(default)]
3759 #[serde(rename = "_meta")]
3760 pub meta: Option<Meta>,
3761}
3762
3763impl SessionConfigSelectOption {
3764 #[must_use]
3766 pub fn new(value: impl Into<SessionConfigValueId>, name: impl Into<String>) -> Self {
3767 Self {
3768 value: value.into(),
3769 name: name.into(),
3770 description: None,
3771 meta: None,
3772 }
3773 }
3774
3775 #[must_use]
3777 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
3778 self.description = description.into_option();
3779 self
3780 }
3781
3782 #[must_use]
3788 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3789 self.meta = meta.into_option();
3790 self
3791 }
3792}
3793
3794#[serde_as]
3796#[skip_serializing_none]
3797#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3798#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3799#[serde(rename_all = "camelCase")]
3800#[non_exhaustive]
3801pub struct SessionConfigSelectGroup {
3802 pub group_id: SessionConfigGroupId,
3804 pub name: String,
3806 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
3808 #[cfg_attr(feature = "schemars", schemars(length(min = 1), extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
3809 pub options: Vec<SessionConfigSelectOption>,
3810 #[serde_as(deserialize_as = "DefaultOnError")]
3816 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
3817 #[serde(default)]
3818 #[serde(rename = "_meta")]
3819 pub meta: Option<Meta>,
3820}
3821
3822impl SessionConfigSelectGroup {
3823 #[must_use]
3825 pub fn new(
3826 group_id: impl Into<SessionConfigGroupId>,
3827 name: impl Into<String>,
3828 options: Vec<SessionConfigSelectOption>,
3829 ) -> Self {
3830 Self {
3831 group_id: group_id.into(),
3832 name: name.into(),
3833 options,
3834 meta: None,
3835 }
3836 }
3837
3838 #[must_use]
3844 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
3845 self.meta = meta.into_option();
3846 self
3847 }
3848}
3849
3850#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3852#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3853#[serde(untagged)]
3854#[non_exhaustive]
3855pub enum SessionConfigSelectOptions {
3856 Ungrouped(
3858 #[cfg_attr(feature = "schemars", schemars(length(min = 1)))] Vec<SessionConfigSelectOption>,
3859 ),
3860 Grouped(
3862 #[cfg_attr(feature = "schemars", schemars(length(min = 1)))] Vec<SessionConfigSelectGroup>,
3863 ),
3864}
3865
3866impl From<Vec<SessionConfigSelectOption>> for SessionConfigSelectOptions {
3867 fn from(options: Vec<SessionConfigSelectOption>) -> Self {
3868 SessionConfigSelectOptions::Ungrouped(options)
3869 }
3870}
3871
3872impl From<Vec<SessionConfigSelectGroup>> for SessionConfigSelectOptions {
3873 fn from(groups: Vec<SessionConfigSelectGroup>) -> Self {
3874 SessionConfigSelectOptions::Grouped(groups)
3875 }
3876}
3877
3878#[skip_serializing_none]
3880#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3881#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3882#[serde(rename_all = "camelCase")]
3883#[non_exhaustive]
3884pub struct SessionConfigSelect {
3885 pub current_value: SessionConfigValueId,
3887 pub options: SessionConfigSelectOptions,
3890}
3891
3892impl SessionConfigSelect {
3893 #[must_use]
3895 pub fn new(
3896 current_value: impl Into<SessionConfigValueId>,
3897 options: impl Into<SessionConfigSelectOptions>,
3898 ) -> Self {
3899 Self {
3900 current_value: current_value.into(),
3901 options: options.into(),
3902 }
3903 }
3904}
3905
3906#[skip_serializing_none]
3908#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3909#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3910#[serde(rename_all = "camelCase")]
3911#[non_exhaustive]
3912pub struct SessionConfigBoolean {
3913 pub current_value: bool,
3915}
3916
3917impl SessionConfigBoolean {
3918 #[must_use]
3920 pub fn new(current_value: bool) -> Self {
3921 Self { current_value }
3922 }
3923}
3924
3925#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3935#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3936#[serde(rename_all = "snake_case")]
3937#[non_exhaustive]
3938pub enum SessionConfigOptionCategory {
3939 Mode,
3941 Model,
3943 ModelConfig,
3945 #[cfg(feature = "unstable_speed_config_category")]
3951 Speed,
3952 ThoughtLevel,
3954 #[serde(untagged)]
3960 Other(String),
3961}
3962
3963#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3965#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3966#[serde(tag = "type", rename_all = "snake_case")]
3967#[non_exhaustive]
3968pub enum SessionConfigKind {
3969 Select(SessionConfigSelect),
3971 Boolean(SessionConfigBoolean),
3973 #[serde(untagged)]
3983 Other(OtherSessionConfigKind),
3984}
3985
3986#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3988#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
3989#[cfg_attr(feature = "schemars", schemars(inline))]
3990#[cfg_attr(feature = "schemars", schemars(transform = other_session_config_kind_schema))]
3991#[serde(rename_all = "camelCase")]
3992#[non_exhaustive]
3993pub struct OtherSessionConfigKind {
3994 #[serde(rename = "type")]
4000 pub type_: String,
4001 #[serde(flatten)]
4003 pub fields: BTreeMap<String, serde_json::Value>,
4004}
4005
4006impl OtherSessionConfigKind {
4007 #[must_use]
4009 pub fn new(type_: impl Into<String>, mut fields: BTreeMap<String, serde_json::Value>) -> Self {
4010 fields.remove("type");
4011 fields.remove("_meta");
4012 Self {
4013 type_: type_.into(),
4014 fields,
4015 }
4016 }
4017}
4018
4019impl<'de> Deserialize<'de> for OtherSessionConfigKind {
4020 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
4021 where
4022 D: serde::Deserializer<'de>,
4023 {
4024 let mut fields = BTreeMap::<String, serde_json::Value>::deserialize(deserializer)?;
4025 let type_ = fields
4026 .remove("type")
4027 .ok_or_else(|| serde::de::Error::missing_field("type"))?;
4028 let serde_json::Value::String(type_) = type_ else {
4029 return Err(serde::de::Error::custom("`type` must be a string"));
4030 };
4031
4032 if is_known_session_config_kind_type(&type_) {
4033 return Err(serde::de::Error::custom(format!(
4034 "known session configuration option `{type_}` did not match its schema"
4035 )));
4036 }
4037
4038 Ok(Self { type_, fields })
4039 }
4040}
4041
4042fn is_known_session_config_kind_type(type_: &str) -> bool {
4043 matches!(type_, "select" | "boolean")
4044}
4045
4046#[cfg(feature = "schemars")]
4047fn other_session_config_kind_schema(schema: &mut Schema) {
4048 super::schema_util::reject_known_string_discriminators(schema, "type", &["select", "boolean"]);
4049}
4050
4051#[serde_as]
4053#[skip_serializing_none]
4054#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4055#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4056#[serde(rename_all = "camelCase")]
4057#[non_exhaustive]
4058pub struct SessionConfigOption {
4059 pub config_id: SessionConfigId,
4061 pub name: String,
4063 #[serde_as(deserialize_as = "DefaultOnError")]
4067 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4068 #[serde(default)]
4069 pub description: Option<String>,
4070 #[serde_as(deserialize_as = "DefaultOnError")]
4074 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4075 #[serde(default)]
4076 pub category: Option<SessionConfigOptionCategory>,
4077 #[serde(flatten)]
4079 pub kind: SessionConfigKind,
4080 #[serde_as(deserialize_as = "DefaultOnError")]
4086 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4087 #[serde(default)]
4088 #[serde(rename = "_meta")]
4089 pub meta: Option<Meta>,
4090}
4091
4092impl SessionConfigOption {
4093 #[must_use]
4095 pub fn new(
4096 config_id: impl Into<SessionConfigId>,
4097 name: impl Into<String>,
4098 kind: SessionConfigKind,
4099 ) -> Self {
4100 Self {
4101 config_id: config_id.into(),
4102 name: name.into(),
4103 description: None,
4104 category: None,
4105 kind,
4106 meta: None,
4107 }
4108 }
4109
4110 #[must_use]
4112 pub fn select(
4113 config_id: impl Into<SessionConfigId>,
4114 name: impl Into<String>,
4115 current_value: impl Into<SessionConfigValueId>,
4116 options: impl Into<SessionConfigSelectOptions>,
4117 ) -> Self {
4118 Self::new(
4119 config_id,
4120 name,
4121 SessionConfigKind::Select(SessionConfigSelect::new(current_value, options)),
4122 )
4123 }
4124
4125 #[must_use]
4127 pub fn boolean(
4128 config_id: impl Into<SessionConfigId>,
4129 name: impl Into<String>,
4130 current_value: bool,
4131 ) -> Self {
4132 Self::new(
4133 config_id,
4134 name,
4135 SessionConfigKind::Boolean(SessionConfigBoolean::new(current_value)),
4136 )
4137 }
4138
4139 #[must_use]
4141 pub fn description(mut self, description: impl IntoOption<String>) -> Self {
4142 self.description = description.into_option();
4143 self
4144 }
4145
4146 #[must_use]
4148 pub fn category(mut self, category: impl IntoOption<SessionConfigOptionCategory>) -> Self {
4149 self.category = category.into_option();
4150 self
4151 }
4152
4153 #[must_use]
4159 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4160 self.meta = meta.into_option();
4161 self
4162 }
4163}
4164
4165#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4174#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
4175#[serde(tag = "type", rename_all = "snake_case")]
4176#[non_exhaustive]
4177pub enum SessionConfigOptionValue {
4178 Id {
4180 value: SessionConfigValueId,
4182 },
4183 Boolean {
4185 value: bool,
4187 },
4188 #[serde(untagged)]
4197 Other(OtherSessionConfigOptionValue),
4198}
4199
4200#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4202#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
4203#[cfg_attr(feature = "schemars", schemars(inline))]
4204#[cfg_attr(feature = "schemars", schemars(transform = other_session_config_option_value_schema))]
4205#[serde(rename_all = "camelCase")]
4206#[non_exhaustive]
4207pub struct OtherSessionConfigOptionValue {
4208 #[serde(rename = "type")]
4214 pub type_: String,
4215 pub value: serde_json::Value,
4217 #[serde(flatten)]
4219 pub fields: BTreeMap<String, serde_json::Value>,
4220}
4221
4222impl OtherSessionConfigOptionValue {
4223 #[must_use]
4225 pub fn new(
4226 type_: impl Into<String>,
4227 value: serde_json::Value,
4228 mut fields: BTreeMap<String, serde_json::Value>,
4229 ) -> Self {
4230 fields.remove("type");
4231 fields.remove("value");
4232 fields.remove("_meta");
4233 Self {
4234 type_: type_.into(),
4235 value,
4236 fields,
4237 }
4238 }
4239}
4240
4241impl<'de> Deserialize<'de> for OtherSessionConfigOptionValue {
4242 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
4243 where
4244 D: serde::Deserializer<'de>,
4245 {
4246 let mut fields = BTreeMap::<String, serde_json::Value>::deserialize(deserializer)?;
4247 let type_ = fields
4248 .remove("type")
4249 .ok_or_else(|| serde::de::Error::missing_field("type"))?;
4250 let serde_json::Value::String(type_) = type_ else {
4251 return Err(serde::de::Error::custom("`type` must be a string"));
4252 };
4253
4254 if is_known_session_config_option_value_type(&type_) {
4255 return Err(serde::de::Error::custom(format!(
4256 "known session configuration option value `{type_}` did not match its schema"
4257 )));
4258 }
4259
4260 let value = fields
4261 .remove("value")
4262 .ok_or_else(|| serde::de::Error::missing_field("value"))?;
4263
4264 Ok(Self {
4265 type_,
4266 value,
4267 fields,
4268 })
4269 }
4270}
4271
4272impl<'de> Deserialize<'de> for SessionConfigOptionValue {
4273 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
4274 where
4275 D: serde::Deserializer<'de>,
4276 {
4277 let mut fields = BTreeMap::<String, serde_json::Value>::deserialize(deserializer)?;
4278 let type_ = fields.remove("type");
4279 let value = fields
4280 .remove("value")
4281 .ok_or_else(|| serde::de::Error::missing_field("value"))?;
4282
4283 let type_ = type_.ok_or_else(|| serde::de::Error::missing_field("type"))?;
4284
4285 let serde_json::Value::String(type_) = type_ else {
4286 return Err(serde::de::Error::custom("`type` must be a string"));
4287 };
4288
4289 match type_.as_str() {
4290 "id" => {
4291 let value = serde_json::from_value(value).map_err(|error| {
4292 serde::de::Error::custom(format!(
4293 "`value` must be a string for `type: id`: {error}"
4294 ))
4295 })?;
4296 Ok(Self::Id { value })
4297 }
4298 "boolean" => {
4299 let value = serde_json::from_value(value).map_err(|error| {
4300 serde::de::Error::custom(format!(
4301 "`value` must be a boolean for `type: boolean`: {error}"
4302 ))
4303 })?;
4304 Ok(Self::Boolean { value })
4305 }
4306 _ => Ok(Self::Other(OtherSessionConfigOptionValue {
4307 type_,
4308 value,
4309 fields,
4310 })),
4311 }
4312 }
4313}
4314
4315fn is_known_session_config_option_value_type(type_: &str) -> bool {
4316 matches!(type_, "id" | "boolean")
4317}
4318
4319#[cfg(feature = "schemars")]
4320fn other_session_config_option_value_schema(schema: &mut Schema) {
4321 super::schema_util::reject_known_string_discriminators(schema, "type", &["id", "boolean"]);
4322}
4323
4324impl SessionConfigOptionValue {
4325 #[must_use]
4327 pub fn id(id: impl Into<SessionConfigValueId>) -> Self {
4328 Self::Id { value: id.into() }
4329 }
4330
4331 #[must_use]
4333 pub fn boolean(val: bool) -> Self {
4334 Self::Boolean { value: val }
4335 }
4336
4337 #[must_use]
4340 pub fn as_id(&self) -> Option<&SessionConfigValueId> {
4341 match self {
4342 Self::Id { value } => Some(value),
4343 _ => None,
4344 }
4345 }
4346
4347 #[must_use]
4349 pub fn as_bool(&self) -> Option<bool> {
4350 match self {
4351 Self::Boolean { value } => Some(*value),
4352 _ => None,
4353 }
4354 }
4355}
4356
4357impl From<SessionConfigValueId> for SessionConfigOptionValue {
4358 fn from(value: SessionConfigValueId) -> Self {
4359 Self::Id { value }
4360 }
4361}
4362
4363impl From<bool> for SessionConfigOptionValue {
4364 fn from(value: bool) -> Self {
4365 Self::Boolean { value }
4366 }
4367}
4368
4369impl From<&str> for SessionConfigOptionValue {
4370 fn from(value: &str) -> Self {
4371 Self::Id {
4372 value: SessionConfigValueId::new(value),
4373 }
4374 }
4375}
4376
4377#[serde_as]
4385#[skip_serializing_none]
4386#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4387#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4388#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_CONFIG_OPTION_METHOD_NAME)))]
4389#[serde(rename_all = "camelCase")]
4390#[non_exhaustive]
4391pub struct SetSessionConfigOptionRequest {
4392 pub session_id: SessionId,
4394 pub config_id: SessionConfigId,
4396 #[serde(flatten)]
4400 pub value: SessionConfigOptionValue,
4401 #[serde_as(deserialize_as = "DefaultOnError")]
4407 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4408 #[serde(default)]
4409 #[serde(rename = "_meta")]
4410 pub meta: Option<Meta>,
4411}
4412
4413impl SetSessionConfigOptionRequest {
4414 #[must_use]
4416 pub fn new(
4417 session_id: impl Into<SessionId>,
4418 config_id: impl Into<SessionConfigId>,
4419 value: impl Into<SessionConfigOptionValue>,
4420 ) -> Self {
4421 Self {
4422 session_id: session_id.into(),
4423 config_id: config_id.into(),
4424 value: value.into(),
4425 meta: None,
4426 }
4427 }
4428
4429 #[must_use]
4435 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4436 self.meta = meta.into_option();
4437 self
4438 }
4439}
4440
4441#[serde_as]
4443#[skip_serializing_none]
4444#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4445#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4446#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_CONFIG_OPTION_METHOD_NAME)))]
4447#[serde(rename_all = "camelCase")]
4448#[non_exhaustive]
4449pub struct SetSessionConfigOptionResponse {
4450 #[serde_as(deserialize_as = "VecSkipError<_>")]
4452 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-skip-invalid-items" = true)))]
4453 pub config_options: Vec<SessionConfigOption>,
4454 #[serde_as(deserialize_as = "DefaultOnError")]
4460 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4461 #[serde(default)]
4462 #[serde(rename = "_meta")]
4463 pub meta: Option<Meta>,
4464}
4465
4466impl SetSessionConfigOptionResponse {
4467 #[must_use]
4469 pub fn new(config_options: Vec<SessionConfigOption>) -> Self {
4470 Self {
4471 config_options,
4472 meta: None,
4473 }
4474 }
4475
4476 #[must_use]
4482 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4483 self.meta = meta.into_option();
4484 self
4485 }
4486}
4487
4488#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4497#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4498#[serde(tag = "type", rename_all = "snake_case")]
4499#[non_exhaustive]
4500pub enum McpServer {
4501 Http(McpServerHttp),
4505 #[cfg(feature = "unstable_mcp_over_acp")]
4514 Acp(McpServerAcp),
4515 Stdio(McpServerStdio),
4519 #[serde(untagged)]
4530 Other(OtherMcpServer),
4531}
4532
4533#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4535#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
4536#[cfg_attr(feature = "schemars", schemars(inline))]
4537#[cfg_attr(feature = "schemars", schemars(transform = other_mcp_server_schema))]
4538#[serde(rename_all = "camelCase")]
4539#[non_exhaustive]
4540pub struct OtherMcpServer {
4541 #[serde(rename = "type")]
4547 pub type_: String,
4548 #[serde(flatten)]
4550 pub fields: BTreeMap<String, serde_json::Value>,
4551}
4552
4553impl OtherMcpServer {
4554 #[must_use]
4556 pub fn new(type_: impl Into<String>, mut fields: BTreeMap<String, serde_json::Value>) -> Self {
4557 fields.remove("type");
4558 Self {
4559 type_: type_.into(),
4560 fields,
4561 }
4562 }
4563}
4564
4565impl<'de> Deserialize<'de> for OtherMcpServer {
4566 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
4567 where
4568 D: serde::Deserializer<'de>,
4569 {
4570 let mut fields = BTreeMap::<String, serde_json::Value>::deserialize(deserializer)?;
4571 let type_ = fields
4572 .remove("type")
4573 .ok_or_else(|| serde::de::Error::missing_field("type"))?;
4574 let serde_json::Value::String(type_) = type_ else {
4575 return Err(serde::de::Error::custom("`type` must be a string"));
4576 };
4577
4578 if is_known_mcp_server_type(&type_) {
4579 return Err(serde::de::Error::custom(format!(
4580 "known MCP server transport `{type_}` did not match its schema"
4581 )));
4582 }
4583
4584 Ok(Self { type_, fields })
4585 }
4586}
4587
4588fn is_known_mcp_server_type(type_: &str) -> bool {
4589 match type_ {
4590 "http" | "stdio" => true,
4591 #[cfg(feature = "unstable_mcp_over_acp")]
4592 "acp" => true,
4593 _ => false,
4594 }
4595}
4596
4597#[cfg(feature = "schemars")]
4598fn other_mcp_server_schema(schema: &mut Schema) {
4599 super::schema_util::reject_known_string_discriminators(
4600 schema,
4601 "type",
4602 &[
4603 "http",
4604 "stdio",
4605 #[cfg(feature = "unstable_mcp_over_acp")]
4606 "acp",
4607 ],
4608 );
4609}
4610
4611#[serde_as]
4613#[skip_serializing_none]
4614#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4615#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4616#[serde(rename_all = "camelCase")]
4617#[non_exhaustive]
4618pub struct McpServerHttp {
4619 pub name: String,
4621 #[cfg_attr(feature = "schemars", schemars(url))]
4623 pub url: String,
4624 #[serde_as(deserialize_as = "DefaultOnNull")]
4627 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
4628 #[serde(default, skip_serializing_if = "Vec::is_empty")]
4629 pub headers: Vec<HttpHeader>,
4630 #[serde_as(deserialize_as = "DefaultOnError")]
4636 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4637 #[serde(default)]
4638 #[serde(rename = "_meta")]
4639 pub meta: Option<Meta>,
4640}
4641
4642impl McpServerHttp {
4643 #[must_use]
4645 pub fn new(name: impl Into<String>, url: impl Into<String>) -> Self {
4646 Self {
4647 name: name.into(),
4648 url: url.into(),
4649 headers: Vec::new(),
4650 meta: None,
4651 }
4652 }
4653
4654 #[must_use]
4657 pub fn headers(mut self, headers: Vec<HttpHeader>) -> Self {
4658 self.headers = headers;
4659 self
4660 }
4661
4662 #[must_use]
4668 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4669 self.meta = meta.into_option();
4670 self
4671 }
4672}
4673
4674#[cfg(feature = "unstable_mcp_over_acp")]
4683#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4684#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Display, From)]
4685#[serde(transparent)]
4686#[from(forward)]
4687#[non_exhaustive]
4688pub struct McpServerAcpId(pub Arc<str>);
4689
4690#[cfg(feature = "unstable_mcp_over_acp")]
4691impl McpServerAcpId {
4692 #[must_use]
4694 pub fn new(id: impl Into<Self>) -> Self {
4695 id.into()
4696 }
4697}
4698
4699#[serde_as]
4708#[skip_serializing_none]
4709#[cfg(feature = "unstable_mcp_over_acp")]
4710#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4711#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4712#[serde(rename_all = "camelCase")]
4713#[non_exhaustive]
4714pub struct McpServerAcp {
4715 pub name: String,
4717 pub server_id: McpServerAcpId,
4722 #[serde_as(deserialize_as = "DefaultOnError")]
4728 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4729 #[serde(default)]
4730 #[serde(rename = "_meta")]
4731 pub meta: Option<Meta>,
4732}
4733
4734#[cfg(feature = "unstable_mcp_over_acp")]
4735impl McpServerAcp {
4736 #[must_use]
4738 pub fn new(name: impl Into<String>, server_id: impl Into<McpServerAcpId>) -> Self {
4739 Self {
4740 name: name.into(),
4741 server_id: server_id.into(),
4742 meta: None,
4743 }
4744 }
4745
4746 #[must_use]
4752 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4753 self.meta = meta.into_option();
4754 self
4755 }
4756}
4757
4758#[serde_as]
4760#[skip_serializing_none]
4761#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4762#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4763#[serde(rename_all = "camelCase")]
4764#[non_exhaustive]
4765pub struct McpServerStdio {
4766 pub name: String,
4768 pub command: AbsolutePath,
4770 #[serde_as(deserialize_as = "DefaultOnNull")]
4772 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
4773 #[serde(default, skip_serializing_if = "Vec::is_empty")]
4774 pub args: Vec<String>,
4775 #[serde_as(deserialize_as = "DefaultOnNull")]
4778 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
4779 #[serde(default, skip_serializing_if = "Vec::is_empty")]
4780 pub env: Vec<EnvVariable>,
4781 #[serde_as(deserialize_as = "DefaultOnError")]
4787 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4788 #[serde(default)]
4789 #[serde(rename = "_meta")]
4790 pub meta: Option<Meta>,
4791}
4792
4793impl McpServerStdio {
4794 #[must_use]
4796 pub fn new(name: impl Into<String>, command: impl Into<AbsolutePath>) -> Self {
4797 Self {
4798 name: name.into(),
4799 command: command.into(),
4800 args: Vec::new(),
4801 env: Vec::new(),
4802 meta: None,
4803 }
4804 }
4805
4806 #[must_use]
4808 pub fn args(mut self, args: Vec<String>) -> Self {
4809 self.args = args;
4810 self
4811 }
4812
4813 #[must_use]
4816 pub fn env(mut self, env: Vec<EnvVariable>) -> Self {
4817 self.env = env;
4818 self
4819 }
4820
4821 #[must_use]
4827 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4828 self.meta = meta.into_option();
4829 self
4830 }
4831}
4832
4833#[serde_as]
4835#[skip_serializing_none]
4836#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4837#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4838#[serde(rename_all = "camelCase")]
4839#[non_exhaustive]
4840pub struct EnvVariable {
4841 pub name: String,
4843 pub value: String,
4845 #[serde_as(deserialize_as = "DefaultOnError")]
4851 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4852 #[serde(default)]
4853 #[serde(rename = "_meta")]
4854 pub meta: Option<Meta>,
4855}
4856
4857impl EnvVariable {
4858 #[must_use]
4860 pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self {
4861 Self {
4862 name: name.into(),
4863 value: value.into(),
4864 meta: None,
4865 }
4866 }
4867
4868 #[must_use]
4874 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4875 self.meta = meta.into_option();
4876 self
4877 }
4878}
4879
4880#[serde_as]
4882#[skip_serializing_none]
4883#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4884#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4885#[serde(rename_all = "camelCase")]
4886#[non_exhaustive]
4887pub struct HttpHeader {
4888 pub name: String,
4890 pub value: String,
4892 #[serde_as(deserialize_as = "DefaultOnError")]
4898 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4899 #[serde(default)]
4900 #[serde(rename = "_meta")]
4901 pub meta: Option<Meta>,
4902}
4903
4904impl HttpHeader {
4905 #[must_use]
4907 pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self {
4908 Self {
4909 name: name.into(),
4910 value: value.into(),
4911 meta: None,
4912 }
4913 }
4914
4915 #[must_use]
4921 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4922 self.meta = meta.into_option();
4923 self
4924 }
4925}
4926
4927#[serde_as]
4936#[skip_serializing_none]
4937#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
4938#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
4939#[serde(rename_all = "camelCase")]
4940#[non_exhaustive]
4941pub struct SystemPrompt {
4942 pub mode: SystemPromptMode,
4947 pub content: Vec<ContentBlock>,
4957 #[serde_as(deserialize_as = "DefaultOnError")]
4963 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
4964 #[serde(default)]
4965 #[serde(rename = "_meta")]
4966 pub meta: Option<Meta>,
4967}
4968
4969impl SystemPrompt {
4970 #[must_use]
4975 pub fn new(content: Vec<ContentBlock>) -> Self {
4976 Self {
4977 mode: SystemPromptMode::default(),
4978 content,
4979 meta: None,
4980 }
4981 }
4982
4983 #[must_use]
4985 pub fn mode(mut self, mode: SystemPromptMode) -> Self {
4986 self.mode = mode;
4987 self
4988 }
4989
4990 #[must_use]
4996 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
4997 self.meta = meta.into_option();
4998 self
4999 }
5000}
5001
5002#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5008#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
5009#[serde(rename_all = "snake_case")]
5010#[non_exhaustive]
5011pub enum SystemPromptMode {
5012 #[default]
5019 Append,
5020 Override,
5029 #[serde(untagged)]
5035 Other(String),
5036}
5037
5038#[serde_as]
5046#[skip_serializing_none]
5047#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5048#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5049#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_PROMPT_METHOD_NAME)))]
5050#[serde(rename_all = "camelCase")]
5051#[non_exhaustive]
5052pub struct PromptRequest {
5053 pub session_id: SessionId,
5055 #[cfg_attr(feature = "schemars", schemars(length(min = 1)))]
5072 pub prompt: Vec<ContentBlock>,
5073 #[serde_as(deserialize_as = "DefaultOnError")]
5079 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5080 #[serde(default)]
5081 #[serde(rename = "_meta")]
5082 pub meta: Option<Meta>,
5083}
5084
5085impl PromptRequest {
5086 #[must_use]
5088 pub fn new(session_id: impl Into<SessionId>, prompt: Vec<ContentBlock>) -> Self {
5089 Self {
5090 session_id: session_id.into(),
5091 prompt,
5092 meta: None,
5093 }
5094 }
5095
5096 #[must_use]
5102 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5103 self.meta = meta.into_option();
5104 self
5105 }
5106}
5107
5108#[serde_as]
5119#[skip_serializing_none]
5120#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5121#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5122#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_PROMPT_METHOD_NAME)))]
5123#[serde(rename_all = "camelCase")]
5124#[non_exhaustive]
5125pub struct PromptResponse {
5126 pub message_id: MessageId,
5134 #[serde_as(deserialize_as = "DefaultOnError")]
5140 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5141 #[serde(default)]
5142 #[serde(rename = "_meta")]
5143 pub meta: Option<Meta>,
5144}
5145
5146impl PromptResponse {
5147 #[must_use]
5149 pub fn new(message_id: impl Into<MessageId>) -> Self {
5150 Self {
5151 message_id: message_id.into(),
5152 meta: None,
5153 }
5154 }
5155
5156 #[must_use]
5162 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5163 self.meta = meta.into_option();
5164 self
5165 }
5166}
5167
5168#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5172#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
5173#[serde(tag = "stopReason", rename_all = "snake_case")]
5174#[non_exhaustive]
5175pub enum StopReason {
5176 EndTurn,
5179 MaxTokens,
5181 MaxTurnRequests,
5184 Refusal,
5186 Cancelled,
5197 Error(ErrorStopReason),
5203 #[serde(untagged)]
5209 Other(OtherStopReason),
5210}
5211
5212impl From<ErrorStopReason> for StopReason {
5213 fn from(value: ErrorStopReason) -> Self {
5214 Self::Error(value)
5215 }
5216}
5217
5218#[serde_as]
5220#[skip_serializing_none]
5221#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5222#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5223#[serde(rename_all = "camelCase")]
5224#[non_exhaustive]
5225pub struct ErrorStopReason {
5226 #[serde_as(deserialize_as = "DefaultOnError")]
5231 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5232 #[serde(default)]
5233 pub error: Option<Box<Error>>,
5234}
5235
5236impl ErrorStopReason {
5237 #[must_use]
5239 pub fn new() -> Self {
5240 Self::default()
5241 }
5242
5243 #[must_use]
5245 pub fn error(mut self, error: impl IntoOption<Error>) -> Self {
5246 self.error = error.into_option().map(Box::new);
5247 self
5248 }
5249}
5250
5251#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5253#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
5254#[cfg_attr(feature = "schemars", schemars(inline))]
5255#[cfg_attr(feature = "schemars", schemars(transform = other_stop_reason_schema))]
5256#[serde(rename_all = "camelCase")]
5257#[non_exhaustive]
5258pub struct OtherStopReason {
5259 pub stop_reason: String,
5265 #[serde(flatten)]
5267 pub fields: BTreeMap<String, serde_json::Value>,
5268}
5269
5270impl OtherStopReason {
5271 #[must_use]
5273 pub fn new(
5274 stop_reason: impl Into<String>,
5275 mut fields: BTreeMap<String, serde_json::Value>,
5276 ) -> Self {
5277 remove_idle_state_update_fields(&mut fields);
5278 Self {
5279 stop_reason: stop_reason.into(),
5280 fields,
5281 }
5282 }
5283}
5284
5285impl<'de> Deserialize<'de> for OtherStopReason {
5286 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
5287 where
5288 D: serde::Deserializer<'de>,
5289 {
5290 let mut fields = BTreeMap::<String, serde_json::Value>::deserialize(deserializer)?;
5291 let stop_reason = fields
5292 .remove("stopReason")
5293 .ok_or_else(|| serde::de::Error::missing_field("stopReason"))?;
5294 let serde_json::Value::String(stop_reason) = stop_reason else {
5295 return Err(serde::de::Error::custom("`stopReason` must be a string"));
5296 };
5297
5298 if KNOWN_STOP_REASONS.contains(&stop_reason.as_str()) {
5299 return Err(serde::de::Error::custom(format!(
5300 "known stop reason `{stop_reason}` did not match its schema"
5301 )));
5302 }
5303 remove_idle_state_update_fields(&mut fields);
5304
5305 Ok(Self {
5306 stop_reason,
5307 fields,
5308 })
5309 }
5310}
5311
5312const KNOWN_STOP_REASONS: &[&str] = &[
5313 "end_turn",
5314 "max_tokens",
5315 "max_turn_requests",
5316 "refusal",
5317 "cancelled",
5318 "error",
5319];
5320
5321fn remove_idle_state_update_fields(fields: &mut BTreeMap<String, serde_json::Value>) {
5323 fields.remove("stopReason");
5324 fields.remove("usage");
5325 fields.remove("_meta");
5326}
5327
5328#[cfg(feature = "schemars")]
5329fn other_stop_reason_schema(schema: &mut Schema) {
5330 super::schema_util::reject_known_string_discriminators(
5331 schema,
5332 "stopReason",
5333 KNOWN_STOP_REASONS,
5334 );
5335}
5336
5337#[cfg(feature = "unstable_end_turn_token_usage")]
5343#[serde_as]
5344#[skip_serializing_none]
5345#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5346#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5347#[serde(rename_all = "camelCase")]
5348#[non_exhaustive]
5349pub struct Usage {
5350 pub total_tokens: u64,
5352 pub input_tokens: u64,
5354 pub output_tokens: u64,
5356 #[serde_as(deserialize_as = "DefaultOnError")]
5360 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5361 #[serde(default)]
5362 pub thought_tokens: Option<u64>,
5363 #[serde_as(deserialize_as = "DefaultOnError")]
5367 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5368 #[serde(default)]
5369 pub cached_read_tokens: Option<u64>,
5370 #[serde_as(deserialize_as = "DefaultOnError")]
5374 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5375 #[serde(default)]
5376 pub cached_write_tokens: Option<u64>,
5377 #[serde_as(deserialize_as = "DefaultOnError")]
5383 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5384 #[serde(default)]
5385 #[serde(rename = "_meta")]
5386 pub meta: Option<Meta>,
5387}
5388
5389#[cfg(feature = "unstable_end_turn_token_usage")]
5390impl Usage {
5391 #[must_use]
5393 pub fn new(total_tokens: u64, input_tokens: u64, output_tokens: u64) -> Self {
5394 Self {
5395 total_tokens,
5396 input_tokens,
5397 output_tokens,
5398 thought_tokens: None,
5399 cached_read_tokens: None,
5400 cached_write_tokens: None,
5401 meta: None,
5402 }
5403 }
5404
5405 #[must_use]
5407 pub fn thought_tokens(mut self, thought_tokens: impl IntoOption<u64>) -> Self {
5408 self.thought_tokens = thought_tokens.into_option();
5409 self
5410 }
5411
5412 #[must_use]
5414 pub fn cached_read_tokens(mut self, cached_read_tokens: impl IntoOption<u64>) -> Self {
5415 self.cached_read_tokens = cached_read_tokens.into_option();
5416 self
5417 }
5418
5419 #[must_use]
5421 pub fn cached_write_tokens(mut self, cached_write_tokens: impl IntoOption<u64>) -> Self {
5422 self.cached_write_tokens = cached_write_tokens.into_option();
5423 self
5424 }
5425
5426 #[must_use]
5432 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5433 self.meta = meta.into_option();
5434 self
5435 }
5436}
5437
5438#[cfg(feature = "unstable_llm_providers")]
5451#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5452#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5453#[serde(rename_all = "snake_case")]
5454#[non_exhaustive]
5455#[expect(clippy::doc_markdown)]
5456pub enum LlmProtocol {
5457 Anthropic,
5459 #[serde(rename = "openai")]
5461 OpenAi,
5462 Azure,
5464 Vertex,
5466 Bedrock,
5468 #[serde(untagged)]
5474 Other(String),
5475}
5476
5477#[cfg(feature = "unstable_llm_providers")]
5483#[serde_as]
5484#[skip_serializing_none]
5485#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5486#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5487#[serde(rename_all = "camelCase")]
5488#[non_exhaustive]
5489pub struct ProviderCurrentConfig {
5490 pub api_type: LlmProtocol,
5492 #[cfg_attr(feature = "schemars", schemars(url))]
5494 pub base_url: String,
5495 #[serde_as(deserialize_as = "DefaultOnError")]
5501 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5502 #[serde(default)]
5503 #[serde(rename = "_meta")]
5504 pub meta: Option<Meta>,
5505}
5506
5507#[cfg(feature = "unstable_llm_providers")]
5508impl ProviderCurrentConfig {
5509 #[must_use]
5511 pub fn new(api_type: LlmProtocol, base_url: impl Into<String>) -> Self {
5512 Self {
5513 api_type,
5514 base_url: base_url.into(),
5515 meta: None,
5516 }
5517 }
5518
5519 #[must_use]
5525 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5526 self.meta = meta.into_option();
5527 self
5528 }
5529}
5530
5531#[cfg(feature = "unstable_llm_providers")]
5537#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5538#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Display, From)]
5539#[serde(transparent)]
5540#[from(forward)]
5541#[non_exhaustive]
5542pub struct ProviderId(pub Arc<str>);
5543
5544#[cfg(feature = "unstable_llm_providers")]
5545impl ProviderId {
5546 #[must_use]
5548 pub fn new(id: impl Into<Self>) -> Self {
5549 id.into()
5550 }
5551}
5552
5553#[cfg(feature = "unstable_llm_providers")]
5559#[serde_as]
5560#[skip_serializing_none]
5561#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5562#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5563#[serde(rename_all = "camelCase")]
5564#[non_exhaustive]
5565pub struct ProviderInfo {
5566 pub provider_id: ProviderId,
5568 #[serde_as(deserialize_as = "DefaultOnError<VecSkipError<_>>")]
5570 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true, "x-deserialize-skip-invalid-items" = true)))]
5571 pub supported: Vec<LlmProtocol>,
5572 pub required: bool,
5575 #[serde(default)]
5578 pub current: Option<ProviderCurrentConfig>,
5579 #[serde_as(deserialize_as = "DefaultOnError")]
5585 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5586 #[serde(default)]
5587 #[serde(rename = "_meta")]
5588 pub meta: Option<Meta>,
5589}
5590
5591#[cfg(feature = "unstable_llm_providers")]
5592impl ProviderInfo {
5593 #[must_use]
5595 pub fn new(
5596 provider_id: impl Into<ProviderId>,
5597 supported: Vec<LlmProtocol>,
5598 required: bool,
5599 current: impl IntoOption<ProviderCurrentConfig>,
5600 ) -> Self {
5601 Self {
5602 provider_id: provider_id.into(),
5603 supported,
5604 required,
5605 current: current.into_option(),
5606 meta: None,
5607 }
5608 }
5609
5610 #[must_use]
5616 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5617 self.meta = meta.into_option();
5618 self
5619 }
5620}
5621
5622#[cfg(feature = "unstable_llm_providers")]
5623crate::serde_util::default_on_null! {
5624 #[serde_as]
5630 #[skip_serializing_none]
5631 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5632 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
5633 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_LIST_METHOD_NAME)))]
5634 #[serde(rename_all = "camelCase")]
5635 #[non_exhaustive]
5636 pub struct ListProvidersRequest {
5637 #[serde_as(deserialize_as = "DefaultOnError")]
5643 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5644 #[serde(default)]
5645 #[serde(rename = "_meta")]
5646 pub meta: Option<Meta>,
5647 }
5648}
5649
5650#[cfg(feature = "unstable_llm_providers")]
5651impl ListProvidersRequest {
5652 #[must_use]
5654 pub fn new() -> Self {
5655 Self::default()
5656 }
5657
5658 #[must_use]
5664 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5665 self.meta = meta.into_option();
5666 self
5667 }
5668}
5669
5670#[cfg(feature = "unstable_llm_providers")]
5676#[serde_as]
5677#[skip_serializing_none]
5678#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5679#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5680#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_LIST_METHOD_NAME)))]
5681#[serde(rename_all = "camelCase")]
5682#[non_exhaustive]
5683pub struct ListProvidersResponse {
5684 pub providers: Vec<ProviderInfo>,
5686 #[serde_as(deserialize_as = "DefaultOnError")]
5692 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5693 #[serde(default)]
5694 #[serde(rename = "_meta")]
5695 pub meta: Option<Meta>,
5696}
5697
5698#[cfg(feature = "unstable_llm_providers")]
5699impl ListProvidersResponse {
5700 #[must_use]
5702 pub fn new(providers: Vec<ProviderInfo>) -> Self {
5703 Self {
5704 providers,
5705 meta: None,
5706 }
5707 }
5708
5709 #[must_use]
5715 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5716 self.meta = meta.into_option();
5717 self
5718 }
5719}
5720
5721#[cfg(feature = "unstable_llm_providers")]
5729#[serde_as]
5730#[skip_serializing_none]
5731#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5732#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
5733#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_SET_METHOD_NAME)))]
5734#[serde(rename_all = "camelCase")]
5735#[non_exhaustive]
5736pub struct SetProviderRequest {
5737 pub provider_id: ProviderId,
5739 pub api_type: LlmProtocol,
5741 #[cfg_attr(feature = "schemars", schemars(url))]
5743 pub base_url: String,
5744 #[serde(default, skip_serializing_if = "HashMap::is_empty")]
5747 pub headers: HashMap<String, String>,
5748 #[serde_as(deserialize_as = "DefaultOnError")]
5754 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5755 #[serde(default)]
5756 #[serde(rename = "_meta")]
5757 pub meta: Option<Meta>,
5758}
5759
5760#[cfg(feature = "unstable_llm_providers")]
5761impl SetProviderRequest {
5762 #[must_use]
5764 pub fn new(
5765 provider_id: impl Into<ProviderId>,
5766 api_type: LlmProtocol,
5767 base_url: impl Into<String>,
5768 ) -> Self {
5769 Self {
5770 provider_id: provider_id.into(),
5771 api_type,
5772 base_url: base_url.into(),
5773 headers: HashMap::new(),
5774 meta: None,
5775 }
5776 }
5777
5778 #[must_use]
5781 pub fn headers(mut self, headers: HashMap<String, String>) -> Self {
5782 self.headers = headers;
5783 self
5784 }
5785
5786 #[must_use]
5792 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5793 self.meta = meta.into_option();
5794 self
5795 }
5796}
5797
5798#[cfg(feature = "unstable_llm_providers")]
5799crate::serde_util::default_on_null! {
5800 #[serde_as]
5806 #[skip_serializing_none]
5807 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5808 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
5809 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_SET_METHOD_NAME)))]
5810 #[serde(rename_all = "camelCase")]
5811 #[non_exhaustive]
5812 pub struct SetProviderResponse {
5813 #[serde_as(deserialize_as = "DefaultOnError")]
5819 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5820 #[serde(default)]
5821 #[serde(rename = "_meta")]
5822 pub meta: Option<Meta>,
5823 }
5824}
5825
5826#[cfg(feature = "unstable_llm_providers")]
5827impl SetProviderResponse {
5828 #[must_use]
5830 pub fn new() -> Self {
5831 Self::default()
5832 }
5833
5834 #[must_use]
5840 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5841 self.meta = meta.into_option();
5842 self
5843 }
5844}
5845
5846#[cfg(feature = "unstable_llm_providers")]
5852#[serde_as]
5853#[skip_serializing_none]
5854#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5855#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5856#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_DISABLE_METHOD_NAME)))]
5857#[serde(rename_all = "camelCase")]
5858#[non_exhaustive]
5859pub struct DisableProviderRequest {
5860 pub provider_id: ProviderId,
5862 #[serde_as(deserialize_as = "DefaultOnError")]
5868 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5869 #[serde(default)]
5870 #[serde(rename = "_meta")]
5871 pub meta: Option<Meta>,
5872}
5873
5874#[cfg(feature = "unstable_llm_providers")]
5875impl DisableProviderRequest {
5876 #[must_use]
5878 pub fn new(provider_id: impl Into<ProviderId>) -> Self {
5879 Self {
5880 provider_id: provider_id.into(),
5881 meta: None,
5882 }
5883 }
5884
5885 #[must_use]
5891 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5892 self.meta = meta.into_option();
5893 self
5894 }
5895}
5896
5897#[cfg(feature = "unstable_llm_providers")]
5898crate::serde_util::default_on_null! {
5899 #[serde_as]
5905 #[skip_serializing_none]
5906 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5907 #[derive(Default, Debug, Clone, Serialize, PartialEq, Eq)]
5908 #[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = PROVIDERS_DISABLE_METHOD_NAME)))]
5909 #[serde(rename_all = "camelCase")]
5910 #[non_exhaustive]
5911 pub struct DisableProviderResponse {
5912 #[serde_as(deserialize_as = "DefaultOnError")]
5918 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5919 #[serde(default)]
5920 #[serde(rename = "_meta")]
5921 pub meta: Option<Meta>,
5922 }
5923}
5924
5925#[cfg(feature = "unstable_llm_providers")]
5926impl DisableProviderResponse {
5927 #[must_use]
5929 pub fn new() -> Self {
5930 Self::default()
5931 }
5932
5933 #[must_use]
5939 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
5940 self.meta = meta.into_option();
5941 self
5942 }
5943}
5944
5945#[serde_as]
5954#[skip_serializing_none]
5955#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5956#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5957#[serde(rename_all = "camelCase")]
5958#[non_exhaustive]
5959pub struct AgentCapabilities {
5960 #[serde_as(deserialize_as = "DefaultOnError")]
5968 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5969 #[serde(default)]
5970 pub session: Option<SessionCapabilities>,
5971 #[serde_as(deserialize_as = "DefaultOnError")]
5978 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5979 #[serde(default)]
5980 pub auth: Option<AgentAuthCapabilities>,
5981 #[cfg(feature = "unstable_llm_providers")]
5990 #[serde_as(deserialize_as = "DefaultOnError")]
5991 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
5992 #[serde(default)]
5993 pub providers: Option<ProvidersCapabilities>,
5994 #[serde_as(deserialize_as = "DefaultOnError")]
6000 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6001 #[serde(default)]
6002 #[serde(rename = "_meta")]
6003 pub meta: Option<Meta>,
6004}
6005
6006impl AgentCapabilities {
6007 #[must_use]
6009 pub fn new() -> Self {
6010 Self::default()
6011 }
6012
6013 #[must_use]
6021 pub fn session(mut self, session: impl IntoOption<SessionCapabilities>) -> Self {
6022 self.session = session.into_option();
6023 self
6024 }
6025
6026 #[must_use]
6030 pub fn auth(mut self, auth: impl IntoOption<AgentAuthCapabilities>) -> Self {
6031 self.auth = auth.into_option();
6032 self
6033 }
6034
6035 #[cfg(feature = "unstable_llm_providers")]
6041 #[must_use]
6042 pub fn providers(mut self, providers: impl IntoOption<ProvidersCapabilities>) -> Self {
6043 self.providers = providers.into_option();
6044 self
6045 }
6046
6047 #[must_use]
6053 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6054 self.meta = meta.into_option();
6055 self
6056 }
6057}
6058
6059#[cfg(feature = "unstable_llm_providers")]
6067#[serde_as]
6068#[skip_serializing_none]
6069#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6070#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6071#[non_exhaustive]
6072pub struct ProvidersCapabilities {
6073 #[serde_as(deserialize_as = "DefaultOnError")]
6079 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6080 #[serde(default)]
6081 #[serde(rename = "_meta")]
6082 pub meta: Option<Meta>,
6083}
6084
6085#[cfg(feature = "unstable_llm_providers")]
6086impl ProvidersCapabilities {
6087 #[must_use]
6089 pub fn new() -> Self {
6090 Self::default()
6091 }
6092
6093 #[must_use]
6099 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6100 self.meta = meta.into_option();
6101 self
6102 }
6103}
6104
6105#[serde_as]
6117#[skip_serializing_none]
6118#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6119#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6120#[serde(rename_all = "camelCase")]
6121#[non_exhaustive]
6122pub struct SessionCapabilities {
6123 #[serde_as(deserialize_as = "DefaultOnError")]
6129 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6130 #[serde(default)]
6131 pub prompt: Option<PromptCapabilities>,
6132 #[serde_as(deserialize_as = "DefaultOnError")]
6137 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6138 #[serde(default)]
6139 pub mcp: Option<McpCapabilities>,
6140 #[serde_as(deserialize_as = "DefaultOnError")]
6145 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6146 #[serde(default)]
6147 pub delete: Option<SessionDeleteCapabilities>,
6148 #[serde_as(deserialize_as = "DefaultOnError")]
6157 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6158 #[serde(default)]
6159 pub additional_directories: Option<SessionAdditionalDirectoriesCapabilities>,
6160 #[serde_as(deserialize_as = "DefaultOnError")]
6165 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6166 #[serde(default)]
6167 pub system_prompt: Option<SessionSystemPromptCapabilities>,
6168 #[cfg(feature = "unstable_session_fork")]
6177 #[serde_as(deserialize_as = "DefaultOnError")]
6178 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6179 #[serde(default)]
6180 pub fork: Option<SessionForkCapabilities>,
6181 #[cfg(feature = "unstable_session_archive")]
6191 #[serde_as(deserialize_as = "DefaultOnError")]
6192 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6193 #[serde(default)]
6194 pub archive: Option<SessionArchiveCapabilities>,
6195 #[cfg(feature = "unstable_session_status")]
6204 #[serde_as(deserialize_as = "DefaultOnError")]
6205 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6206 #[serde(default)]
6207 pub status: Option<SessionStatusCapabilities>,
6208 #[cfg(feature = "unstable_session_options")]
6218 #[serde_as(deserialize_as = "DefaultOnError")]
6219 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6220 #[serde(default)]
6221 pub options: Option<SessionOptionsCapabilities>,
6222 #[cfg(feature = "unstable_session_set_title")]
6234 #[serde_as(deserialize_as = "DefaultOnError")]
6235 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6236 #[serde(default)]
6237 pub title: Option<SessionTitleCapabilities>,
6238 #[serde_as(deserialize_as = "DefaultOnError")]
6244 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6245 #[serde(default)]
6246 #[serde(rename = "_meta")]
6247 pub meta: Option<Meta>,
6248}
6249
6250impl SessionCapabilities {
6251 #[must_use]
6253 pub fn new() -> Self {
6254 Self::default()
6255 }
6256
6257 #[must_use]
6263 pub fn prompt(mut self, prompt: impl IntoOption<PromptCapabilities>) -> Self {
6264 self.prompt = prompt.into_option();
6265 self
6266 }
6267
6268 #[must_use]
6273 pub fn mcp(mut self, mcp: impl IntoOption<McpCapabilities>) -> Self {
6274 self.mcp = mcp.into_option();
6275 self
6276 }
6277
6278 #[must_use]
6283 pub fn delete(mut self, delete: impl IntoOption<SessionDeleteCapabilities>) -> Self {
6284 self.delete = delete.into_option();
6285 self
6286 }
6287
6288 #[must_use]
6297 pub fn additional_directories(
6298 mut self,
6299 additional_directories: impl IntoOption<SessionAdditionalDirectoriesCapabilities>,
6300 ) -> Self {
6301 self.additional_directories = additional_directories.into_option();
6302 self
6303 }
6304
6305 #[must_use]
6310 pub fn system_prompt(
6311 mut self,
6312 system_prompt: impl IntoOption<SessionSystemPromptCapabilities>,
6313 ) -> Self {
6314 self.system_prompt = system_prompt.into_option();
6315 self
6316 }
6317
6318 #[cfg(feature = "unstable_session_fork")]
6319 #[must_use]
6324 pub fn fork(mut self, fork: impl IntoOption<SessionForkCapabilities>) -> Self {
6325 self.fork = fork.into_option();
6326 self
6327 }
6328
6329 #[cfg(feature = "unstable_session_archive")]
6339 #[must_use]
6340 pub fn archive(mut self, archive: impl IntoOption<SessionArchiveCapabilities>) -> Self {
6341 self.archive = archive.into_option();
6342 self
6343 }
6344
6345 #[cfg(feature = "unstable_session_status")]
6354 #[must_use]
6355 pub fn status(mut self, status: impl IntoOption<SessionStatusCapabilities>) -> Self {
6356 self.status = status.into_option();
6357 self
6358 }
6359
6360 #[cfg(feature = "unstable_session_options")]
6370 #[must_use]
6371 pub fn options(mut self, options: impl IntoOption<SessionOptionsCapabilities>) -> Self {
6372 self.options = options.into_option();
6373 self
6374 }
6375
6376 #[cfg(feature = "unstable_session_set_title")]
6388 #[must_use]
6389 pub fn title(mut self, title: impl IntoOption<SessionTitleCapabilities>) -> Self {
6390 self.title = title.into_option();
6391 self
6392 }
6393
6394 #[must_use]
6400 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6401 self.meta = meta.into_option();
6402 self
6403 }
6404}
6405
6406#[serde_as]
6410#[skip_serializing_none]
6411#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6412#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6413#[non_exhaustive]
6414pub struct SessionDeleteCapabilities {
6415 #[serde_as(deserialize_as = "DefaultOnError")]
6421 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6422 #[serde(default)]
6423 #[serde(rename = "_meta")]
6424 pub meta: Option<Meta>,
6425}
6426
6427impl SessionDeleteCapabilities {
6428 #[must_use]
6430 pub fn new() -> Self {
6431 Self::default()
6432 }
6433
6434 #[must_use]
6440 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6441 self.meta = meta.into_option();
6442 self
6443 }
6444}
6445
6446#[serde_as]
6453#[skip_serializing_none]
6454#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6455#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6456#[non_exhaustive]
6457pub struct SessionAdditionalDirectoriesCapabilities {
6458 #[serde_as(deserialize_as = "DefaultOnError")]
6464 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6465 #[serde(default)]
6466 #[serde(rename = "_meta")]
6467 pub meta: Option<Meta>,
6468}
6469
6470impl SessionAdditionalDirectoriesCapabilities {
6471 #[must_use]
6473 pub fn new() -> Self {
6474 Self::default()
6475 }
6476
6477 #[must_use]
6483 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6484 self.meta = meta.into_option();
6485 self
6486 }
6487}
6488
6489#[serde_as]
6494#[skip_serializing_none]
6495#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6496#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6497#[serde(rename_all = "camelCase")]
6498#[non_exhaustive]
6499pub struct SessionSystemPromptCapabilities {
6500 #[serde_as(deserialize_as = "DefaultOnError")]
6504 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6505 #[serde(default)]
6506 pub mode: Option<SessionSystemPromptModeCapabilities>,
6507 #[serde_as(deserialize_as = "DefaultOnError")]
6513 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6514 #[serde(default)]
6515 #[serde(rename = "_meta")]
6516 pub meta: Option<Meta>,
6517}
6518
6519impl SessionSystemPromptCapabilities {
6520 #[must_use]
6522 pub fn new() -> Self {
6523 Self::default()
6524 }
6525
6526 #[must_use]
6530 pub fn mode(mut self, mode: impl IntoOption<SessionSystemPromptModeCapabilities>) -> Self {
6531 self.mode = mode.into_option();
6532 self
6533 }
6534
6535 #[must_use]
6541 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6542 self.meta = meta.into_option();
6543 self
6544 }
6545}
6546
6547#[serde_as]
6552#[skip_serializing_none]
6553#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6554#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6555#[serde(rename_all = "camelCase")]
6556#[non_exhaustive]
6557pub struct SessionSystemPromptModeCapabilities {
6558 #[serde_as(deserialize_as = "DefaultOnError")]
6564 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6565 #[serde(default, rename = "override")]
6566 pub override_: Option<SessionSystemPromptOverrideCapabilities>,
6567 #[serde_as(deserialize_as = "DefaultOnError")]
6573 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6574 #[serde(default)]
6575 #[serde(rename = "_meta")]
6576 pub meta: Option<Meta>,
6577}
6578
6579impl SessionSystemPromptModeCapabilities {
6580 #[must_use]
6582 pub fn new() -> Self {
6583 Self::default()
6584 }
6585
6586 #[must_use]
6592 pub fn override_(
6593 mut self,
6594 override_: impl IntoOption<SessionSystemPromptOverrideCapabilities>,
6595 ) -> Self {
6596 self.override_ = override_.into_option();
6597 self
6598 }
6599
6600 #[must_use]
6606 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6607 self.meta = meta.into_option();
6608 self
6609 }
6610}
6611
6612#[serde_as]
6617#[skip_serializing_none]
6618#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6619#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6620#[non_exhaustive]
6621pub struct SessionSystemPromptOverrideCapabilities {
6622 #[serde_as(deserialize_as = "DefaultOnError")]
6628 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6629 #[serde(default)]
6630 #[serde(rename = "_meta")]
6631 pub meta: Option<Meta>,
6632}
6633
6634impl SessionSystemPromptOverrideCapabilities {
6635 #[must_use]
6637 pub fn new() -> Self {
6638 Self::default()
6639 }
6640
6641 #[must_use]
6647 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6648 self.meta = meta.into_option();
6649 self
6650 }
6651}
6652
6653#[cfg(feature = "unstable_session_fork")]
6661#[serde_as]
6662#[skip_serializing_none]
6663#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6664#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6665#[non_exhaustive]
6666pub struct SessionForkCapabilities {
6667 #[serde_as(deserialize_as = "DefaultOnError")]
6673 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6674 #[serde(default)]
6675 #[serde(rename = "_meta")]
6676 pub meta: Option<Meta>,
6677}
6678
6679#[cfg(feature = "unstable_session_fork")]
6680impl SessionForkCapabilities {
6681 #[must_use]
6683 pub fn new() -> Self {
6684 Self::default()
6685 }
6686
6687 #[must_use]
6693 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6694 self.meta = meta.into_option();
6695 self
6696 }
6697}
6698
6699#[cfg(feature = "unstable_session_archive")]
6708#[serde_as]
6709#[skip_serializing_none]
6710#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6711#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6712#[non_exhaustive]
6713pub struct SessionArchiveCapabilities {
6714 #[serde_as(deserialize_as = "DefaultOnError")]
6720 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6721 #[serde(default)]
6722 #[serde(rename = "_meta")]
6723 pub meta: Option<Meta>,
6724}
6725
6726#[cfg(feature = "unstable_session_archive")]
6727impl SessionArchiveCapabilities {
6728 #[must_use]
6730 pub fn new() -> Self {
6731 Self::default()
6732 }
6733
6734 #[must_use]
6740 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6741 self.meta = meta.into_option();
6742 self
6743 }
6744}
6745
6746#[cfg(feature = "unstable_session_status")]
6754#[serde_as]
6755#[skip_serializing_none]
6756#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6757#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6758#[non_exhaustive]
6759pub struct SessionStatusCapabilities {
6760 #[serde_as(deserialize_as = "DefaultOnError")]
6766 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6767 #[serde(default)]
6768 #[serde(rename = "_meta")]
6769 pub meta: Option<Meta>,
6770}
6771
6772#[cfg(feature = "unstable_session_status")]
6773impl SessionStatusCapabilities {
6774 #[must_use]
6776 pub fn new() -> Self {
6777 Self::default()
6778 }
6779
6780 #[must_use]
6786 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6787 self.meta = meta.into_option();
6788 self
6789 }
6790}
6791
6792#[cfg(feature = "unstable_session_options")]
6801#[serde_as]
6802#[skip_serializing_none]
6803#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6804#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6805#[non_exhaustive]
6806pub struct SessionOptionsCapabilities {
6807 #[serde_as(deserialize_as = "DefaultOnError")]
6813 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6814 #[serde(default)]
6815 #[serde(rename = "_meta")]
6816 pub meta: Option<Meta>,
6817}
6818
6819#[cfg(feature = "unstable_session_options")]
6820impl SessionOptionsCapabilities {
6821 #[must_use]
6823 pub fn new() -> Self {
6824 Self::default()
6825 }
6826
6827 #[must_use]
6833 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6834 self.meta = meta.into_option();
6835 self
6836 }
6837}
6838
6839#[cfg(feature = "unstable_session_set_title")]
6848#[serde_as]
6849#[skip_serializing_none]
6850#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6851#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6852#[non_exhaustive]
6853pub struct SessionTitleCapabilities {
6854 #[serde_as(deserialize_as = "DefaultOnError")]
6860 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6861 #[serde(default)]
6862 #[serde(rename = "_meta")]
6863 pub meta: Option<Meta>,
6864}
6865
6866#[cfg(feature = "unstable_session_set_title")]
6867impl SessionTitleCapabilities {
6868 #[must_use]
6870 pub fn new() -> Self {
6871 Self::default()
6872 }
6873
6874 #[must_use]
6880 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
6881 self.meta = meta.into_option();
6882 self
6883 }
6884}
6885
6886#[serde_as]
6899#[skip_serializing_none]
6900#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6901#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6902#[serde(rename_all = "camelCase")]
6903#[non_exhaustive]
6904pub struct PromptCapabilities {
6905 #[serde_as(deserialize_as = "DefaultOnError")]
6910 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6911 #[serde(default)]
6912 pub image: Option<PromptImageCapabilities>,
6913 #[serde_as(deserialize_as = "DefaultOnError")]
6918 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6919 #[serde(default)]
6920 pub audio: Option<PromptAudioCapabilities>,
6921 #[serde_as(deserialize_as = "DefaultOnError")]
6929 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6930 #[serde(default)]
6931 pub embedded_context: Option<PromptEmbeddedContextCapabilities>,
6932 #[cfg(feature = "unstable_agent_skills")]
6942 #[serde_as(deserialize_as = "DefaultOnError")]
6943 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6944 #[serde(default)]
6945 pub skill: Option<PromptSkillCapabilities>,
6946 #[serde_as(deserialize_as = "DefaultOnError")]
6952 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
6953 #[serde(default)]
6954 #[serde(rename = "_meta")]
6955 pub meta: Option<Meta>,
6956}
6957
6958impl PromptCapabilities {
6959 #[must_use]
6961 pub fn new() -> Self {
6962 Self::default()
6963 }
6964
6965 #[must_use]
6970 pub fn image(mut self, image: impl IntoOption<PromptImageCapabilities>) -> Self {
6971 self.image = image.into_option();
6972 self
6973 }
6974
6975 #[must_use]
6980 pub fn audio(mut self, audio: impl IntoOption<PromptAudioCapabilities>) -> Self {
6981 self.audio = audio.into_option();
6982 self
6983 }
6984
6985 #[must_use]
6993 pub fn embedded_context(
6994 mut self,
6995 embedded_context: impl IntoOption<PromptEmbeddedContextCapabilities>,
6996 ) -> Self {
6997 self.embedded_context = embedded_context.into_option();
6998 self
6999 }
7000
7001 #[cfg(feature = "unstable_agent_skills")]
7010 #[must_use]
7011 pub fn skill(mut self, skill: impl IntoOption<PromptSkillCapabilities>) -> Self {
7012 self.skill = skill.into_option();
7013 self
7014 }
7015
7016 #[must_use]
7022 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
7023 self.meta = meta.into_option();
7024 self
7025 }
7026}
7027
7028#[serde_as]
7032#[skip_serializing_none]
7033#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7034#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7035#[non_exhaustive]
7036pub struct PromptImageCapabilities {
7037 #[serde_as(deserialize_as = "DefaultOnError")]
7043 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7044 #[serde(default)]
7045 #[serde(rename = "_meta")]
7046 pub meta: Option<Meta>,
7047}
7048
7049impl PromptImageCapabilities {
7050 #[must_use]
7052 pub fn new() -> Self {
7053 Self::default()
7054 }
7055
7056 #[must_use]
7062 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
7063 self.meta = meta.into_option();
7064 self
7065 }
7066}
7067
7068#[serde_as]
7072#[skip_serializing_none]
7073#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7074#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7075#[non_exhaustive]
7076pub struct PromptAudioCapabilities {
7077 #[serde_as(deserialize_as = "DefaultOnError")]
7083 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7084 #[serde(default)]
7085 #[serde(rename = "_meta")]
7086 pub meta: Option<Meta>,
7087}
7088
7089impl PromptAudioCapabilities {
7090 #[must_use]
7092 pub fn new() -> Self {
7093 Self::default()
7094 }
7095
7096 #[must_use]
7102 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
7103 self.meta = meta.into_option();
7104 self
7105 }
7106}
7107
7108#[serde_as]
7112#[skip_serializing_none]
7113#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7114#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7115#[non_exhaustive]
7116pub struct PromptEmbeddedContextCapabilities {
7117 #[serde_as(deserialize_as = "DefaultOnError")]
7123 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7124 #[serde(default)]
7125 #[serde(rename = "_meta")]
7126 pub meta: Option<Meta>,
7127}
7128
7129impl PromptEmbeddedContextCapabilities {
7130 #[must_use]
7132 pub fn new() -> Self {
7133 Self::default()
7134 }
7135
7136 #[must_use]
7142 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
7143 self.meta = meta.into_option();
7144 self
7145 }
7146}
7147
7148#[cfg(feature = "unstable_agent_skills")]
7157#[serde_as]
7158#[skip_serializing_none]
7159#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7160#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7161#[serde(rename_all = "camelCase")]
7162#[non_exhaustive]
7163pub struct PromptSkillCapabilities {
7164 #[serde_as(deserialize_as = "DefaultOnError")]
7170 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7171 #[serde(default)]
7172 pub inline: Option<PromptSkillInlineCapabilities>,
7173 #[serde_as(deserialize_as = "DefaultOnError")]
7179 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7180 #[serde(default)]
7181 #[serde(rename = "_meta")]
7182 pub meta: Option<Meta>,
7183}
7184
7185#[cfg(feature = "unstable_agent_skills")]
7186impl PromptSkillCapabilities {
7187 #[must_use]
7189 pub fn new() -> Self {
7190 Self::default()
7191 }
7192
7193 #[must_use]
7199 pub fn inline(mut self, inline: impl IntoOption<PromptSkillInlineCapabilities>) -> Self {
7200 self.inline = inline.into_option();
7201 self
7202 }
7203
7204 #[must_use]
7210 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
7211 self.meta = meta.into_option();
7212 self
7213 }
7214}
7215
7216#[cfg(feature = "unstable_agent_skills")]
7225#[serde_as]
7226#[skip_serializing_none]
7227#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7228#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7229#[non_exhaustive]
7230pub struct PromptSkillInlineCapabilities {
7231 #[serde_as(deserialize_as = "DefaultOnError")]
7237 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7238 #[serde(default)]
7239 #[serde(rename = "_meta")]
7240 pub meta: Option<Meta>,
7241}
7242
7243#[cfg(feature = "unstable_agent_skills")]
7244impl PromptSkillInlineCapabilities {
7245 #[must_use]
7247 pub fn new() -> Self {
7248 Self::default()
7249 }
7250
7251 #[must_use]
7257 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
7258 self.meta = meta.into_option();
7259 self
7260 }
7261}
7262
7263#[serde_as]
7265#[skip_serializing_none]
7266#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7267#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7268#[serde(rename_all = "camelCase")]
7269#[non_exhaustive]
7270pub struct McpCapabilities {
7271 #[serde_as(deserialize_as = "DefaultOnError")]
7276 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7277 #[serde(default)]
7278 pub stdio: Option<McpStdioCapabilities>,
7279 #[serde_as(deserialize_as = "DefaultOnError")]
7284 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7285 #[serde(default)]
7286 pub http: Option<McpHttpCapabilities>,
7287 #[cfg(feature = "unstable_mcp_over_acp")]
7296 #[serde_as(deserialize_as = "DefaultOnError")]
7297 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7298 #[serde(default)]
7299 pub acp: Option<McpAcpCapabilities>,
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 McpCapabilities {
7313 #[must_use]
7315 pub fn new() -> Self {
7316 Self::default()
7317 }
7318
7319 #[must_use]
7324 pub fn stdio(mut self, stdio: impl IntoOption<McpStdioCapabilities>) -> Self {
7325 self.stdio = stdio.into_option();
7326 self
7327 }
7328
7329 #[must_use]
7334 pub fn http(mut self, http: impl IntoOption<McpHttpCapabilities>) -> Self {
7335 self.http = http.into_option();
7336 self
7337 }
7338
7339 #[cfg(feature = "unstable_mcp_over_acp")]
7345 #[must_use]
7349 pub fn acp(mut self, acp: impl IntoOption<McpAcpCapabilities>) -> Self {
7350 self.acp = acp.into_option();
7351 self
7352 }
7353
7354 #[must_use]
7360 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
7361 self.meta = meta.into_option();
7362 self
7363 }
7364}
7365
7366#[serde_as]
7370#[skip_serializing_none]
7371#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7372#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7373#[non_exhaustive]
7374pub struct McpStdioCapabilities {
7375 #[serde_as(deserialize_as = "DefaultOnError")]
7381 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7382 #[serde(default)]
7383 #[serde(rename = "_meta")]
7384 pub meta: Option<Meta>,
7385}
7386
7387impl McpStdioCapabilities {
7388 #[must_use]
7390 pub fn new() -> Self {
7391 Self::default()
7392 }
7393
7394 #[must_use]
7400 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
7401 self.meta = meta.into_option();
7402 self
7403 }
7404}
7405
7406#[serde_as]
7410#[skip_serializing_none]
7411#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7412#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7413#[non_exhaustive]
7414pub struct McpHttpCapabilities {
7415 #[serde_as(deserialize_as = "DefaultOnError")]
7421 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7422 #[serde(default)]
7423 #[serde(rename = "_meta")]
7424 pub meta: Option<Meta>,
7425}
7426
7427impl McpHttpCapabilities {
7428 #[must_use]
7430 pub fn new() -> Self {
7431 Self::default()
7432 }
7433
7434 #[must_use]
7440 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
7441 self.meta = meta.into_option();
7442 self
7443 }
7444}
7445
7446#[cfg(feature = "unstable_mcp_over_acp")]
7454#[serde_as]
7455#[skip_serializing_none]
7456#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7457#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7458#[non_exhaustive]
7459pub struct McpAcpCapabilities {
7460 #[serde_as(deserialize_as = "DefaultOnError")]
7466 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7467 #[serde(default)]
7468 #[serde(rename = "_meta")]
7469 pub meta: Option<Meta>,
7470}
7471
7472#[cfg(feature = "unstable_mcp_over_acp")]
7473impl McpAcpCapabilities {
7474 #[must_use]
7476 pub fn new() -> Self {
7477 Self::default()
7478 }
7479
7480 #[must_use]
7486 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
7487 self.meta = meta.into_option();
7488 self
7489 }
7490}
7491
7492#[serde_as]
7496#[skip_serializing_none]
7497#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7498#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7499#[cfg_attr(feature = "schemars", schemars(extend("x-side" = "agent", "x-method" = SESSION_CANCEL_METHOD_NAME)))]
7500#[serde(rename_all = "camelCase")]
7501#[non_exhaustive]
7502pub struct CancelSessionNotification {
7503 pub session_id: SessionId,
7505 #[serde_as(deserialize_as = "DefaultOnError")]
7511 #[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-error" = true)))]
7512 #[serde(default)]
7513 #[serde(rename = "_meta")]
7514 pub meta: Option<Meta>,
7515}
7516
7517impl CancelSessionNotification {
7518 #[must_use]
7520 pub fn new(session_id: impl Into<SessionId>) -> Self {
7521 Self {
7522 session_id: session_id.into(),
7523 meta: None,
7524 }
7525 }
7526
7527 #[must_use]
7533 pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
7534 self.meta = meta.into_option();
7535 self
7536 }
7537}
7538
7539#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7545#[non_exhaustive]
7546pub struct AgentMethodNames {
7547 pub initialize: &'static str,
7549 pub auth_login: &'static str,
7551 #[cfg(feature = "unstable_llm_providers")]
7553 pub providers_list: &'static str,
7554 #[cfg(feature = "unstable_llm_providers")]
7556 pub providers_set: &'static str,
7557 #[cfg(feature = "unstable_llm_providers")]
7559 pub providers_disable: &'static str,
7560 pub session_new: &'static str,
7562 pub session_set_config_option: &'static str,
7564 pub session_prompt: &'static str,
7566 pub session_cancel: &'static str,
7568 #[cfg(feature = "unstable_mcp_over_acp")]
7570 pub mcp_message: &'static str,
7571 pub session_list: &'static str,
7573 pub session_delete: &'static str,
7575 #[cfg(feature = "unstable_session_fork")]
7577 pub session_fork: &'static str,
7578 #[cfg(feature = "unstable_session_archive")]
7580 pub session_archive: &'static str,
7581 #[cfg(feature = "unstable_session_archive")]
7583 pub session_unarchive: &'static str,
7584 #[cfg(feature = "unstable_session_status")]
7586 pub session_status: &'static str,
7587 #[cfg(feature = "unstable_session_options")]
7589 pub session_options: &'static str,
7590 #[cfg(feature = "unstable_session_set_title")]
7592 pub session_set_title: &'static str,
7593 pub session_resume: &'static str,
7595 pub session_close: &'static str,
7597 pub tool_call_cancel: &'static str,
7599 pub terminal_cancel: &'static str,
7601 pub auth_logout: &'static str,
7603 #[cfg(feature = "unstable_auth_status")]
7605 pub auth_status: &'static str,
7606}
7607
7608pub const AGENT_METHOD_NAMES: AgentMethodNames = AgentMethodNames {
7610 initialize: INITIALIZE_METHOD_NAME,
7611 auth_login: AUTH_LOGIN_METHOD_NAME,
7612 #[cfg(feature = "unstable_llm_providers")]
7613 providers_list: PROVIDERS_LIST_METHOD_NAME,
7614 #[cfg(feature = "unstable_llm_providers")]
7615 providers_set: PROVIDERS_SET_METHOD_NAME,
7616 #[cfg(feature = "unstable_llm_providers")]
7617 providers_disable: PROVIDERS_DISABLE_METHOD_NAME,
7618 session_new: SESSION_NEW_METHOD_NAME,
7619 session_set_config_option: SESSION_SET_CONFIG_OPTION_METHOD_NAME,
7620 session_prompt: SESSION_PROMPT_METHOD_NAME,
7621 session_cancel: SESSION_CANCEL_METHOD_NAME,
7622 #[cfg(feature = "unstable_mcp_over_acp")]
7623 mcp_message: MCP_MESSAGE_METHOD_NAME,
7624 session_list: SESSION_LIST_METHOD_NAME,
7625 session_delete: SESSION_DELETE_METHOD_NAME,
7626 #[cfg(feature = "unstable_session_fork")]
7627 session_fork: SESSION_FORK_METHOD_NAME,
7628 #[cfg(feature = "unstable_session_archive")]
7629 session_archive: SESSION_ARCHIVE_METHOD_NAME,
7630 #[cfg(feature = "unstable_session_archive")]
7631 session_unarchive: SESSION_UNARCHIVE_METHOD_NAME,
7632 #[cfg(feature = "unstable_session_status")]
7633 session_status: SESSION_STATUS_METHOD_NAME,
7634 #[cfg(feature = "unstable_session_options")]
7635 session_options: SESSION_OPTIONS_METHOD_NAME,
7636 #[cfg(feature = "unstable_session_set_title")]
7637 session_set_title: SESSION_SET_TITLE_METHOD_NAME,
7638 session_resume: SESSION_RESUME_METHOD_NAME,
7639 session_close: SESSION_CLOSE_METHOD_NAME,
7640 tool_call_cancel: TOOL_CALL_CANCEL_METHOD_NAME,
7641 terminal_cancel: TERMINAL_CANCEL_METHOD_NAME,
7642 auth_logout: AUTH_LOGOUT_METHOD_NAME,
7643 #[cfg(feature = "unstable_auth_status")]
7644 auth_status: AUTH_STATUS_METHOD_NAME,
7645};
7646
7647pub(crate) const INITIALIZE_METHOD_NAME: &str = "initialize";
7649pub(crate) const AUTH_LOGIN_METHOD_NAME: &str = "auth/login";
7651#[cfg(feature = "unstable_llm_providers")]
7653pub(crate) const PROVIDERS_LIST_METHOD_NAME: &str = "providers/list";
7654#[cfg(feature = "unstable_llm_providers")]
7656pub(crate) const PROVIDERS_SET_METHOD_NAME: &str = "providers/set";
7657#[cfg(feature = "unstable_llm_providers")]
7659pub(crate) const PROVIDERS_DISABLE_METHOD_NAME: &str = "providers/disable";
7660pub(crate) const SESSION_NEW_METHOD_NAME: &str = "session/new";
7662pub(crate) const SESSION_SET_CONFIG_OPTION_METHOD_NAME: &str = "session/set_config_option";
7664pub(crate) const SESSION_PROMPT_METHOD_NAME: &str = "session/prompt";
7666pub(crate) const SESSION_CANCEL_METHOD_NAME: &str = "session/cancel";
7668pub(crate) const SESSION_LIST_METHOD_NAME: &str = "session/list";
7670pub(crate) const SESSION_DELETE_METHOD_NAME: &str = "session/delete";
7672#[cfg(feature = "unstable_session_fork")]
7674pub(crate) const SESSION_FORK_METHOD_NAME: &str = "session/fork";
7675#[cfg(feature = "unstable_session_archive")]
7677pub(crate) const SESSION_ARCHIVE_METHOD_NAME: &str = "session/archive";
7678#[cfg(feature = "unstable_session_archive")]
7680pub(crate) const SESSION_UNARCHIVE_METHOD_NAME: &str = "session/unarchive";
7681#[cfg(feature = "unstable_session_status")]
7683pub(crate) const SESSION_STATUS_METHOD_NAME: &str = "session/status";
7684#[cfg(feature = "unstable_session_options")]
7686pub(crate) const SESSION_OPTIONS_METHOD_NAME: &str = "session/options";
7687#[cfg(feature = "unstable_session_set_title")]
7689pub(crate) const SESSION_SET_TITLE_METHOD_NAME: &str = "session/set_title";
7690pub(crate) const SESSION_RESUME_METHOD_NAME: &str = "session/resume";
7692pub(crate) const SESSION_CLOSE_METHOD_NAME: &str = "session/close";
7694pub(crate) const TOOL_CALL_CANCEL_METHOD_NAME: &str = "tool_call/cancel";
7696pub(crate) const TERMINAL_CANCEL_METHOD_NAME: &str = "terminal/cancel";
7698pub(crate) const AUTH_LOGOUT_METHOD_NAME: &str = "auth/logout";
7700#[cfg(feature = "unstable_auth_status")]
7702pub(crate) const AUTH_STATUS_METHOD_NAME: &str = "auth/status";
7703
7704#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7711#[derive(Clone, Debug, Serialize, Deserialize)]
7712#[serde(untagged)]
7713#[cfg_attr(feature = "schemars", schemars(inline))]
7714#[non_exhaustive]
7715pub enum ClientRequest {
7716 InitializeRequest(Box<InitializeRequest>),
7730 LoginAuthRequest(Box<LoginAuthRequest>),
7745 #[cfg(feature = "unstable_llm_providers")]
7751 ListProvidersRequest(Box<ListProvidersRequest>),
7752 #[cfg(feature = "unstable_llm_providers")]
7758 SetProviderRequest(Box<SetProviderRequest>),
7759 #[cfg(feature = "unstable_llm_providers")]
7765 DisableProviderRequest(Box<DisableProviderRequest>),
7766 LogoutAuthRequest(Box<LogoutAuthRequest>),
7776 #[cfg(feature = "unstable_auth_status")]
7785 AuthStatusRequest(Box<AuthStatusRequest>),
7786 NewSessionRequest(Box<NewSessionRequest>),
7799 ListSessionsRequest(Box<ListSessionsRequest>),
7803 DeleteSessionRequest(Box<DeleteSessionRequest>),
7807 #[cfg(feature = "unstable_session_fork")]
7808 ForkSessionRequest(Box<ForkSessionRequest>),
7824 #[cfg(feature = "unstable_session_archive")]
7825 ArchiveSessionRequest(Box<ArchiveSessionRequest>),
7833 #[cfg(feature = "unstable_session_archive")]
7834 UnarchiveSessionRequest(Box<UnarchiveSessionRequest>),
7842 #[cfg(feature = "unstable_session_status")]
7843 SessionStatusRequest(Box<SessionStatusRequest>),
7851 #[cfg(feature = "unstable_session_options")]
7852 SessionOptionsRequest(Box<SessionOptionsRequest>),
7860 #[cfg(feature = "unstable_session_set_title")]
7861 SetSessionTitleRequest(Box<SetSessionTitleRequest>),
7872 ResumeSessionRequest(Box<ResumeSessionRequest>),
7878 CloseSessionRequest(Box<CloseSessionRequest>),
7883 CancelToolCallRequest(Box<CancelToolCallRequest>),
7889 CancelTerminalRequest(Box<CancelTerminalRequest>),
7895 SetSessionConfigOptionRequest(Box<SetSessionConfigOptionRequest>),
7897 PromptRequest(Box<PromptRequest>),
7919 ExtMethodRequest(Box<ExtRequest>),
7926}
7927
7928impl ClientRequest {
7929 #[must_use]
7931 pub fn method(&self) -> &str {
7932 match self {
7933 Self::InitializeRequest(_) => AGENT_METHOD_NAMES.initialize,
7934 Self::LoginAuthRequest(_) => AGENT_METHOD_NAMES.auth_login,
7935 #[cfg(feature = "unstable_llm_providers")]
7936 Self::ListProvidersRequest(_) => AGENT_METHOD_NAMES.providers_list,
7937 #[cfg(feature = "unstable_llm_providers")]
7938 Self::SetProviderRequest(_) => AGENT_METHOD_NAMES.providers_set,
7939 #[cfg(feature = "unstable_llm_providers")]
7940 Self::DisableProviderRequest(_) => AGENT_METHOD_NAMES.providers_disable,
7941 Self::LogoutAuthRequest(_) => AGENT_METHOD_NAMES.auth_logout,
7942 #[cfg(feature = "unstable_auth_status")]
7943 Self::AuthStatusRequest(_) => AGENT_METHOD_NAMES.auth_status,
7944 Self::NewSessionRequest(_) => AGENT_METHOD_NAMES.session_new,
7945 Self::ListSessionsRequest(_) => AGENT_METHOD_NAMES.session_list,
7946 Self::DeleteSessionRequest(_) => AGENT_METHOD_NAMES.session_delete,
7947 #[cfg(feature = "unstable_session_fork")]
7948 Self::ForkSessionRequest(_) => AGENT_METHOD_NAMES.session_fork,
7949 #[cfg(feature = "unstable_session_archive")]
7950 Self::ArchiveSessionRequest(_) => AGENT_METHOD_NAMES.session_archive,
7951 #[cfg(feature = "unstable_session_archive")]
7952 Self::UnarchiveSessionRequest(_) => AGENT_METHOD_NAMES.session_unarchive,
7953 #[cfg(feature = "unstable_session_status")]
7954 Self::SessionStatusRequest(_) => AGENT_METHOD_NAMES.session_status,
7955 #[cfg(feature = "unstable_session_options")]
7956 Self::SessionOptionsRequest(_) => AGENT_METHOD_NAMES.session_options,
7957 #[cfg(feature = "unstable_session_set_title")]
7958 Self::SetSessionTitleRequest(_) => AGENT_METHOD_NAMES.session_set_title,
7959 Self::ResumeSessionRequest(_) => AGENT_METHOD_NAMES.session_resume,
7960 Self::CloseSessionRequest(_) => AGENT_METHOD_NAMES.session_close,
7961 Self::CancelToolCallRequest(_) => AGENT_METHOD_NAMES.tool_call_cancel,
7962 Self::CancelTerminalRequest(_) => AGENT_METHOD_NAMES.terminal_cancel,
7963 Self::SetSessionConfigOptionRequest(_) => AGENT_METHOD_NAMES.session_set_config_option,
7964 Self::PromptRequest(_) => AGENT_METHOD_NAMES.session_prompt,
7965 Self::ExtMethodRequest(ext_request) => &ext_request.method,
7966 }
7967 }
7968}
7969
7970#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7977#[derive(Clone, Debug, Serialize, Deserialize)]
7978#[serde(untagged)]
7979#[cfg_attr(feature = "schemars", schemars(inline))]
7980#[non_exhaustive]
7981pub enum AgentResponse {
7982 InitializeResponse(Box<InitializeResponse>),
7984 LoginAuthResponse(#[serde(default)] Box<LoginAuthResponse>),
7986 #[cfg(feature = "unstable_llm_providers")]
7988 ListProvidersResponse(Box<ListProvidersResponse>),
7989 #[cfg(feature = "unstable_llm_providers")]
7991 SetProviderResponse(#[serde(default)] Box<SetProviderResponse>),
7992 #[cfg(feature = "unstable_llm_providers")]
7994 DisableProviderResponse(#[serde(default)] Box<DisableProviderResponse>),
7995 LogoutAuthResponse(#[serde(default)] Box<LogoutAuthResponse>),
7997 #[cfg(feature = "unstable_auth_status")]
7999 AuthStatusResponse(Box<AuthStatusResponse>),
8000 NewSessionResponse(Box<NewSessionResponse>),
8002 ListSessionsResponse(Box<ListSessionsResponse>),
8004 DeleteSessionResponse(#[serde(default)] Box<DeleteSessionResponse>),
8006 #[cfg(feature = "unstable_session_fork")]
8008 ForkSessionResponse(Box<ForkSessionResponse>),
8009 #[cfg(feature = "unstable_session_archive")]
8011 ArchiveSessionResponse(#[serde(default)] Box<ArchiveSessionResponse>),
8012 #[cfg(feature = "unstable_session_archive")]
8014 UnarchiveSessionResponse(#[serde(default)] Box<UnarchiveSessionResponse>),
8015 #[cfg(feature = "unstable_session_status")]
8017 SessionStatusResponse(Box<SessionStatusResponse>),
8018 #[cfg(feature = "unstable_session_options")]
8020 SessionOptionsResponse(#[serde(default)] Box<SessionOptionsResponse>),
8021 #[cfg(feature = "unstable_session_set_title")]
8023 SetSessionTitleResponse(Box<SetSessionTitleResponse>),
8024 ResumeSessionResponse(#[serde(default)] Box<ResumeSessionResponse>),
8026 CloseSessionResponse(#[serde(default)] Box<CloseSessionResponse>),
8028 CancelToolCallResponse(#[serde(default)] Box<CancelToolCallResponse>),
8030 CancelTerminalResponse(#[serde(default)] Box<CancelTerminalResponse>),
8032 SetSessionConfigOptionResponse(Box<SetSessionConfigOptionResponse>),
8034 PromptResponse(Box<PromptResponse>),
8036 ExtMethodResponse(Box<ExtResponse>),
8038}
8039
8040#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
8047#[derive(Clone, Debug, Serialize, Deserialize)]
8048#[serde(untagged)]
8049#[cfg_attr(feature = "schemars", schemars(inline))]
8050#[non_exhaustive]
8051pub enum ClientNotification {
8052 CancelSessionNotification(Box<CancelSessionNotification>),
8083 #[cfg(feature = "unstable_mcp_over_acp")]
8089 MessageMcpNotification(Box<MessageMcpNotification>),
8090 ExtNotification(Box<ExtNotification>),
8097}
8098
8099impl ClientNotification {
8100 #[must_use]
8102 pub fn method(&self) -> &str {
8103 match self {
8104 Self::CancelSessionNotification(_) => AGENT_METHOD_NAMES.session_cancel,
8105 #[cfg(feature = "unstable_mcp_over_acp")]
8106 Self::MessageMcpNotification(_) => AGENT_METHOD_NAMES.mcp_message,
8107 Self::ExtNotification(ext_notification) => &ext_notification.method,
8108 }
8109 }
8110}
8111
8112#[cfg(test)]
8113mod test_serialization {
8114 use std::path::PathBuf;
8115
8116 use super::*;
8117 use serde_json::json;
8118
8119 fn test_meta() -> Meta {
8120 json!({ "source": "test" }).as_object().unwrap().clone()
8121 }
8122
8123 #[test]
8124 fn list_sessions_cursor_and_session_directories_are_strict() {
8125 for cursor in [json!(null), json!("next")] {
8126 let response = json!({ "sessions": [], "nextCursor": cursor });
8127 serde_json::from_value::<ListSessionsResponse>(response).unwrap();
8128 }
8129 let malformed = json!({ "sessions": [], "nextCursor": 42 });
8130 assert!(serde_json::from_value::<ListSessionsResponse>(malformed).is_err());
8131
8132 let session = |dirs: serde_json::Value| json!({ "sessionId": "s", "cwd": "/w", "additionalDirectories": dirs });
8133 let info: SessionInfo = serde_json::from_value(session(json!(null))).unwrap();
8134 assert_eq!(info.additional_directories, Vec::<AbsolutePath>::new());
8135 for bad in [json!(["/a", 42]), json!("/a")] {
8136 assert!(serde_json::from_value::<SessionInfo>(session(bad)).is_err());
8137 }
8138 let response = json!({ "sessions": [session(json!(["/a", 42]))] });
8140 let response: ListSessionsResponse = serde_json::from_value(response).unwrap();
8141 assert_eq!(response.sessions, Vec::<SessionInfo>::new());
8142 }
8143
8144 #[test]
8145 fn other_fallbacks_preserve_optional_fields_verbatim() {
8146 let valid = json!({ "type": "_custom", "methodId": "m", "name": "M",
8147 "description": "d", "_meta": { "k": 1 } });
8148 let method: AuthMethod = serde_json::from_value(valid.clone()).unwrap();
8149 assert_eq!(method.description(), Some("d"));
8150 assert_eq!(
8151 method.meta(),
8152 Some(&json!({ "k": 1 }).as_object().unwrap().clone())
8153 );
8154 assert_eq!(serde_json::to_value(&method).unwrap(), valid);
8155
8156 let malformed = json!({ "type": "_custom", "methodId": "m", "name": "M",
8158 "description": 42, "_meta": "bad", "extra": true });
8159 let method: AuthMethod = serde_json::from_value(malformed.clone()).unwrap();
8160 assert_eq!(method.description(), None);
8161 assert_eq!(method.meta(), None);
8162 assert_eq!(serde_json::to_value(&method).unwrap(), malformed);
8163
8164 let replay = json!({ "type": "_custom", "_meta": "bad", "cursor": 3 });
8165 let decoded: ReplayFrom = serde_json::from_value(replay.clone()).unwrap();
8166 assert_eq!(serde_json::to_value(&decoded).unwrap(), replay);
8167 }
8168
8169 fn serialized_meta_key_count(value: &impl serde::Serialize) -> usize {
8170 serde_json::to_string(value)
8171 .unwrap()
8172 .matches("\"_meta\"")
8173 .count()
8174 }
8175
8176 #[test]
8177 fn prompt_response_without_metadata_round_trips() {
8178 let response = PromptResponse::new(MessageId::new("message-1"));
8179 let serialized = serde_json::to_value(&response).unwrap();
8180 assert_eq!(serialized, json!({ "messageId": "message-1" }));
8181 assert_eq!(
8182 serde_json::from_value::<PromptResponse>(serialized).unwrap(),
8183 response
8184 );
8185 assert_eq!(
8186 serde_json::from_value::<PromptResponse>(json!({
8187 "messageId": "message-1",
8188 "_meta": null
8189 }))
8190 .unwrap(),
8191 response
8192 );
8193 }
8194
8195 #[test]
8196 fn prompt_response_requires_message_id_and_preserves_metadata_tolerance() {
8197 let response = PromptResponse::new("message-1").meta(test_meta());
8198 let serialized = serde_json::to_value(&response).unwrap();
8199 assert_eq!(
8200 serialized,
8201 json!({
8202 "messageId": "message-1",
8203 "_meta": { "source": "test" }
8204 })
8205 );
8206
8207 let deserialized: PromptResponse = serde_json::from_value(serialized).unwrap();
8208 assert_eq!(deserialized.message_id, MessageId::new("message-1"));
8209 assert_eq!(deserialized.meta, Some(test_meta()));
8210
8211 let malformed_meta: PromptResponse = serde_json::from_value(json!({
8212 "messageId": "message-2",
8213 "_meta": false
8214 }))
8215 .unwrap();
8216 assert_eq!(malformed_meta.message_id, MessageId::new("message-2"));
8217 assert_eq!(malformed_meta.meta, None);
8218
8219 for invalid in [
8220 json!({}),
8221 json!({ "messageId": null }),
8222 json!({ "messageId": 1 }),
8223 json!({ "messageId": false }),
8224 json!({ "messageId": {} }),
8225 json!({ "messageId": [] }),
8226 ] {
8227 assert!(
8228 serde_json::from_value::<PromptResponse>(invalid).is_err(),
8229 "missing, null, and non-string message IDs must be rejected"
8230 );
8231 }
8232 }
8233
8234 #[cfg(feature = "schemars")]
8235 #[test]
8236 fn prompt_response_schema_requires_non_null_string_message_id_reference() {
8237 let schema = serde_json::to_value(schemars::schema_for!(PromptResponse)).unwrap();
8238
8239 assert_eq!(schema["required"], json!(["messageId"]));
8240 assert_eq!(
8241 schema["properties"]["messageId"]["$ref"],
8242 "#/$defs/MessageId"
8243 );
8244 assert_eq!(schema["$defs"]["MessageId"]["type"], "string");
8245 }
8246
8247 #[test]
8248 fn test_initialize_capabilities_default_on_malformed_values() {
8249 let request: InitializeRequest = serde_json::from_value(json!({
8250 "protocolVersion": 2,
8251 "capabilities": false,
8252 "info": {
8253 "name": "client",
8254 "version": "1.0.0"
8255 }
8256 }))
8257 .unwrap();
8258 assert_eq!(request.capabilities, ClientCapabilities::default());
8259
8260 let response: InitializeResponse = serde_json::from_value(json!({
8261 "protocolVersion": 2,
8262 "capabilities": false,
8263 "info": {
8264 "name": "agent",
8265 "version": "1.0.0"
8266 }
8267 }))
8268 .unwrap();
8269 assert_eq!(response.capabilities, AgentCapabilities::default());
8270 }
8271
8272 #[test]
8273 fn test_agent_capabilities_default_on_malformed_values() {
8274 let capabilities: AgentCapabilities = serde_json::from_value(json!({
8275 "session": false,
8276 "auth": false
8277 }))
8278 .unwrap();
8279
8280 assert!(capabilities.session.is_none());
8281 assert_eq!(capabilities.auth, None);
8282 }
8283
8284 #[test]
8285 fn test_mcp_server_stdio_serialization() {
8286 let server = McpServer::Stdio(
8287 McpServerStdio::new("test-server", "/usr/bin/server")
8288 .args(vec!["--port".to_string(), "3000".to_string()])
8289 .env(vec![EnvVariable::new("API_KEY", "secret123")]),
8290 );
8291
8292 let json = serde_json::to_value(&server).unwrap();
8293 assert_eq!(
8294 json,
8295 json!({
8296 "type": "stdio",
8297 "name": "test-server",
8298 "command": "/usr/bin/server",
8299 "args": ["--port", "3000"],
8300 "env": [
8301 {
8302 "name": "API_KEY",
8303 "value": "secret123"
8304 }
8305 ]
8306 })
8307 );
8308
8309 let deserialized: McpServer = serde_json::from_value(json).unwrap();
8310 match deserialized {
8311 McpServer::Stdio(McpServerStdio {
8312 name,
8313 command,
8314 args,
8315 env,
8316 meta: _,
8317 }) => {
8318 assert_eq!(name, "test-server");
8319 assert_eq!(command, AbsolutePath::new("/usr/bin/server"));
8320 assert_eq!(args, vec!["--port", "3000"]);
8321 assert_eq!(env.len(), 1);
8322 assert_eq!(env[0].name, "API_KEY");
8323 assert_eq!(env[0].value, "secret123");
8324 }
8325 _ => panic!("Expected Stdio variant"),
8326 }
8327 }
8328
8329 #[test]
8330 fn test_mcp_server_empty_arrays_are_optional() {
8331 let stdio = McpServer::Stdio(McpServerStdio::new("test-server", "/usr/bin/server"));
8332 assert_eq!(
8333 serde_json::to_value(&stdio).unwrap(),
8334 json!({
8335 "type": "stdio",
8336 "name": "test-server",
8337 "command": "/usr/bin/server"
8338 })
8339 );
8340
8341 let McpServer::Stdio(McpServerStdio { args, env, .. }) =
8342 serde_json::from_value::<McpServer>(json!({
8343 "type": "stdio",
8344 "name": "test-server",
8345 "command": "/usr/bin/server"
8346 }))
8347 .unwrap()
8348 else {
8349 panic!("Expected Stdio variant");
8350 };
8351 assert_eq!(args, Vec::<String>::new());
8352 assert_eq!(env, []);
8353
8354 let http = McpServer::Http(McpServerHttp::new("http-server", "https://api.example.com"));
8355 assert_eq!(
8356 serde_json::to_value(&http).unwrap(),
8357 json!({
8358 "type": "http",
8359 "name": "http-server",
8360 "url": "https://api.example.com"
8361 })
8362 );
8363
8364 let McpServer::Http(McpServerHttp { headers, .. }) =
8365 serde_json::from_value::<McpServer>(json!({
8366 "type": "http",
8367 "name": "http-server",
8368 "url": "https://api.example.com"
8369 }))
8370 .unwrap()
8371 else {
8372 panic!("Expected Http variant");
8373 };
8374 assert_eq!(headers, []);
8375 }
8376
8377 #[test]
8378 fn test_mcp_server_unknown_transport_serialization() {
8379 let json = json!({
8380 "type": "websocket",
8381 "name": "future-server",
8382 "url": "wss://example.com/mcp",
8383 "protocolVersion": "2026-01-01"
8384 });
8385
8386 let deserialized: McpServer = serde_json::from_value(json.clone()).unwrap();
8387 let McpServer::Other(OtherMcpServer { type_, fields }) = &deserialized else {
8388 panic!("Expected Other variant");
8389 };
8390
8391 assert_eq!(type_, "websocket");
8392 assert_eq!(fields["name"], "future-server");
8393 assert_eq!(fields["url"], "wss://example.com/mcp");
8394 assert_eq!(fields["protocolVersion"], "2026-01-01");
8395 assert_eq!(serde_json::to_value(&deserialized).unwrap(), json);
8396 }
8397
8398 #[test]
8399 fn test_mcp_server_stdio_requires_type() {
8400 let result = serde_json::from_value::<McpServer>(json!({
8401 "name": "test-server",
8402 "command": "/usr/bin/server",
8403 "args": [],
8404 "env": []
8405 }));
8406
8407 assert!(result.is_err());
8408 }
8409
8410 #[test]
8411 fn test_mcp_server_unknown_does_not_hide_malformed_known_transport() {
8412 let result = serde_json::from_value::<McpServer>(json!({
8413 "type": "stdio",
8414 "name": "test-server",
8415 "args": [],
8416 "env": []
8417 }));
8418
8419 assert!(result.is_err());
8420 }
8421
8422 #[test]
8423 fn test_mcp_server_http_serialization() {
8424 let server = McpServer::Http(
8425 McpServerHttp::new("http-server", "https://api.example.com").headers(vec![
8426 HttpHeader::new("Authorization", "Bearer token123"),
8427 HttpHeader::new("Content-Type", "application/json"),
8428 ]),
8429 );
8430
8431 let json = serde_json::to_value(&server).unwrap();
8432 assert_eq!(
8433 json,
8434 json!({
8435 "type": "http",
8436 "name": "http-server",
8437 "url": "https://api.example.com",
8438 "headers": [
8439 {
8440 "name": "Authorization",
8441 "value": "Bearer token123"
8442 },
8443 {
8444 "name": "Content-Type",
8445 "value": "application/json"
8446 }
8447 ]
8448 })
8449 );
8450
8451 let deserialized: McpServer = serde_json::from_value(json).unwrap();
8452 match deserialized {
8453 McpServer::Http(McpServerHttp {
8454 name,
8455 url,
8456 headers,
8457 meta: _,
8458 }) => {
8459 assert_eq!(name, "http-server");
8460 assert_eq!(url, "https://api.example.com");
8461 assert_eq!(headers.len(), 2);
8462 assert_eq!(headers[0].name, "Authorization");
8463 assert_eq!(headers[0].value, "Bearer token123");
8464 assert_eq!(headers[1].name, "Content-Type");
8465 assert_eq!(headers[1].value, "application/json");
8466 }
8467 _ => panic!("Expected Http variant"),
8468 }
8469 }
8470
8471 #[cfg(feature = "schemars")]
8472 #[test]
8473 fn mcp_server_http_schema_marks_url_as_uri() {
8474 let schema = serde_json::to_value(schemars::schema_for!(McpServerHttp)).unwrap();
8475
8476 assert_eq!(schema["properties"]["url"]["format"], "uri");
8477 }
8478
8479 #[cfg(feature = "unstable_mcp_over_acp")]
8480 #[test]
8481 fn test_client_mcp_message_method_names() {
8482 use serde_json::json;
8483
8484 assert_eq!(AGENT_METHOD_NAMES.mcp_message, "mcp/message");
8485
8486 let notification =
8487 MessageMcpNotification::new("server-1", "req-1", "notifications/progress");
8488 assert_eq!(
8489 ClientNotification::MessageMcpNotification(Box::new(notification.clone())).method(),
8490 "mcp/message"
8491 );
8492 assert_eq!(
8493 serde_json::to_value(notification).unwrap(),
8494 json!({
8495 "serverId": "server-1",
8496 "requestId": "req-1",
8497 "method": "notifications/progress"
8498 })
8499 );
8500 let notification: MessageMcpNotification = serde_json::from_value(json!({
8501 "serverId": "server-1", "requestId": "req-1", "method": "notifications/progress",
8502 "params": null, "_meta": null
8503 }))
8504 .unwrap();
8505 assert_eq!(notification.params, None);
8506 assert_eq!(notification.meta, None);
8507 for key in ["serverId", "requestId", "method"] {
8508 let mut value = json!({"serverId":"server-1", "requestId":"req-1", "method":"notifications/progress"});
8509 value.as_object_mut().unwrap().remove(key);
8510 assert!(serde_json::from_value::<MessageMcpNotification>(value).is_err());
8511 }
8512 }
8513
8514 #[test]
8515 fn test_auth_method_names() {
8516 assert_eq!(AGENT_METHOD_NAMES.auth_login, "auth/login");
8517 assert_eq!(AGENT_METHOD_NAMES.auth_logout, "auth/logout");
8518
8519 assert_eq!(
8520 ClientRequest::LoginAuthRequest(Box::new(LoginAuthRequest::new("agent-login")))
8521 .method(),
8522 "auth/login"
8523 );
8524 assert_eq!(
8525 ClientRequest::LogoutAuthRequest(Box::new(LogoutAuthRequest::new())).method(),
8526 "auth/logout"
8527 );
8528 }
8529
8530 #[test]
8531 fn test_session_config_option_category_known_variants() {
8532 assert_eq!(
8534 serde_json::to_value(&SessionConfigOptionCategory::Mode).unwrap(),
8535 json!("mode")
8536 );
8537 assert_eq!(
8538 serde_json::to_value(&SessionConfigOptionCategory::Model).unwrap(),
8539 json!("model")
8540 );
8541 assert_eq!(
8542 serde_json::to_value(&SessionConfigOptionCategory::ModelConfig).unwrap(),
8543 json!("model_config")
8544 );
8545 #[cfg(feature = "unstable_speed_config_category")]
8546 assert_eq!(
8547 serde_json::to_value(&SessionConfigOptionCategory::Speed).unwrap(),
8548 json!("speed")
8549 );
8550 assert_eq!(
8551 serde_json::to_value(&SessionConfigOptionCategory::ThoughtLevel).unwrap(),
8552 json!("thought_level")
8553 );
8554
8555 assert_eq!(
8557 serde_json::from_str::<SessionConfigOptionCategory>("\"mode\"").unwrap(),
8558 SessionConfigOptionCategory::Mode
8559 );
8560 assert_eq!(
8561 serde_json::from_str::<SessionConfigOptionCategory>("\"model\"").unwrap(),
8562 SessionConfigOptionCategory::Model
8563 );
8564 assert_eq!(
8565 serde_json::from_str::<SessionConfigOptionCategory>("\"model_config\"").unwrap(),
8566 SessionConfigOptionCategory::ModelConfig
8567 );
8568 #[cfg(feature = "unstable_speed_config_category")]
8569 assert_eq!(
8570 serde_json::from_str::<SessionConfigOptionCategory>("\"speed\"").unwrap(),
8571 SessionConfigOptionCategory::Speed
8572 );
8573 assert_eq!(
8574 serde_json::from_str::<SessionConfigOptionCategory>("\"thought_level\"").unwrap(),
8575 SessionConfigOptionCategory::ThoughtLevel
8576 );
8577 }
8578
8579 #[test]
8580 fn test_session_config_option_category_unknown_variants() {
8581 let unknown: SessionConfigOptionCategory =
8583 serde_json::from_str("\"some_future_category\"").unwrap();
8584 assert_eq!(
8585 unknown,
8586 SessionConfigOptionCategory::Other("some_future_category".to_string())
8587 );
8588
8589 let json = serde_json::to_value(&unknown).unwrap();
8591 assert_eq!(json, json!("some_future_category"));
8592 }
8593
8594 #[cfg(not(feature = "unstable_speed_config_category"))]
8595 #[test]
8596 fn test_session_config_option_speed_is_unknown_without_feature() {
8597 let unknown: SessionConfigOptionCategory = serde_json::from_str("\"speed\"").unwrap();
8598 assert_eq!(
8599 unknown,
8600 SessionConfigOptionCategory::Other("speed".to_string())
8601 );
8602 }
8603
8604 #[test]
8605 fn test_session_config_option_category_custom_categories() {
8606 let custom: SessionConfigOptionCategory =
8608 serde_json::from_str("\"_my_custom_category\"").unwrap();
8609 assert_eq!(
8610 custom,
8611 SessionConfigOptionCategory::Other("_my_custom_category".to_string())
8612 );
8613
8614 let json = serde_json::to_value(&custom).unwrap();
8616 assert_eq!(json, json!("_my_custom_category"));
8617
8618 let deserialized: SessionConfigOptionCategory = serde_json::from_value(json).unwrap();
8620 assert_eq!(
8621 deserialized,
8622 SessionConfigOptionCategory::Other("_my_custom_category".to_string()),
8623 );
8624 }
8625
8626 fn test_config_option() -> SessionConfigOption {
8627 SessionConfigOption::select(
8628 "mode",
8629 "Mode",
8630 "ask",
8631 vec![SessionConfigSelectOption::new("ask", "Ask")],
8632 )
8633 }
8634
8635 #[test]
8636 fn test_session_response_initial_state_default_empty_and_skip_serializing() {
8637 assert_eq!(
8638 serde_json::to_value(NewSessionResponse::new("sess")).unwrap(),
8639 json!({ "sessionId": "sess" })
8640 );
8641 assert_eq!(
8642 serde_json::to_value(ResumeSessionResponse::new()).unwrap(),
8643 json!({})
8644 );
8645 #[cfg(feature = "unstable_session_fork")]
8646 assert_eq!(
8647 serde_json::to_value(ForkSessionResponse::new("fork")).unwrap(),
8648 json!({ "sessionId": "fork" })
8649 );
8650
8651 let json = serde_json::to_value(
8652 NewSessionResponse::new("sess").config_options(vec![test_config_option()]),
8653 )
8654 .unwrap();
8655 assert_eq!(json["configOptions"].as_array().unwrap().len(), 1);
8656 }
8657
8658 #[test]
8659 fn test_session_response_config_options_deserialize_missing_null_and_invalid() {
8660 let missing: NewSessionResponse =
8661 serde_json::from_value(json!({ "sessionId": "sess" })).unwrap();
8662 assert_eq!(missing.config_options, []);
8663
8664 let null: NewSessionResponse = serde_json::from_value(json!({
8665 "sessionId": "sess",
8666 "configOptions": null
8667 }))
8668 .unwrap();
8669 assert_eq!(null.config_options, []);
8670
8671 let wrong_shape: NewSessionResponse = serde_json::from_value(json!({
8672 "sessionId": "sess",
8673 "configOptions": "oops"
8674 }))
8675 .unwrap();
8676 assert_eq!(wrong_shape.config_options, []);
8677
8678 let valid_option = serde_json::to_value(test_config_option()).unwrap();
8679 let mixed: NewSessionResponse = serde_json::from_value(json!({
8680 "sessionId": "sess",
8681 "configOptions": ["oops", valid_option]
8682 }))
8683 .unwrap();
8684 assert_eq!(mixed.config_options.len(), 1);
8685
8686 let resume: ResumeSessionResponse = serde_json::from_value(json!({})).unwrap();
8687 assert_eq!(resume.config_options, []);
8688 #[cfg(feature = "unstable_session_fork")]
8689 {
8690 let fork: ForkSessionResponse =
8691 serde_json::from_value(json!({ "sessionId": "fork" })).unwrap();
8692 assert_eq!(fork.config_options, []);
8693 }
8694 }
8695
8696 #[test]
8697 fn test_session_response_available_commands_roundtrip_with_config_options() {
8698 use super::super::{AvailableCommandInput, Command, TextCommandInput};
8699
8700 let commands = vec![
8701 AvailableCommand::Command(
8702 Command::new("web", "Search the web")
8703 .input(AvailableCommandInput::Text(TextCommandInput::new("Query"))),
8704 ),
8705 AvailableCommand::Command(Command::new("test", "Run project tests")),
8706 ];
8707 let mut expected = json!({
8708 "sessionId": "sess",
8709 "configOptions": [test_config_option()],
8710 "availableCommands": [
8711 {
8712 "type": "command",
8713 "name": "web",
8714 "description": "Search the web",
8715 "input": { "type": "text", "hint": "Query" }
8716 },
8717 { "type": "command", "name": "test", "description": "Run project tests" }
8718 ]
8719 });
8720
8721 let new = NewSessionResponse::new("sess")
8722 .config_options(vec![test_config_option()])
8723 .available_commands(commands.clone());
8724 assert_eq!(serde_json::to_value(&new).unwrap(), expected);
8725 assert_eq!(
8726 serde_json::from_value::<NewSessionResponse>(expected.clone()).unwrap(),
8727 new
8728 );
8729
8730 expected.as_object_mut().unwrap().remove("sessionId");
8731 let resume = ResumeSessionResponse::new()
8732 .config_options(vec![test_config_option()])
8733 .available_commands(commands.clone());
8734 assert_eq!(serde_json::to_value(&resume).unwrap(), expected);
8735 assert_eq!(
8736 serde_json::from_value::<ResumeSessionResponse>(expected.clone()).unwrap(),
8737 resume
8738 );
8739
8740 #[cfg(feature = "unstable_session_fork")]
8741 {
8742 expected["sessionId"] = json!("fork");
8743 let fork = ForkSessionResponse::new("fork")
8744 .config_options(vec![test_config_option()])
8745 .available_commands(commands);
8746 assert_eq!(serde_json::to_value(&fork).unwrap(), expected);
8747 assert_eq!(
8748 serde_json::from_value::<ForkSessionResponse>(expected).unwrap(),
8749 fork
8750 );
8751 }
8752 }
8753
8754 #[test]
8755 fn test_session_response_available_commands_deserialize_missing_null_and_invalid() {
8756 let command =
8757 AvailableCommand::Command(super::super::Command::new("test", "Run project tests"));
8758 let config_options = vec![test_config_option()];
8759
8760 for (commands, expected) in [
8761 (None, vec![]),
8762 (Some(json!(null)), vec![]),
8763 (Some(json!([])), vec![]),
8764 (Some(json!("oops")), vec![]),
8765 (Some(json!({})), vec![]),
8766 (Some(json!([null, {}, { "name": "invalid" }])), vec![]),
8767 (
8768 Some(json!([{ "name": "test", "description": "Run project tests" }])),
8769 vec![],
8770 ),
8771 (
8772 Some(json!([null, command, { "name": "invalid" }])),
8773 vec![command.clone()],
8774 ),
8775 ] {
8776 let mut value = json!({
8777 "sessionId": "sess",
8778 "configOptions": config_options
8779 });
8780 if let Some(commands) = commands {
8781 value["availableCommands"] = commands;
8782 }
8783
8784 let new: NewSessionResponse = serde_json::from_value(value.clone()).unwrap();
8785 assert_eq!(new.available_commands, expected);
8786 assert_eq!(new.config_options, config_options);
8787
8788 #[cfg(feature = "unstable_session_fork")]
8789 {
8790 let fork: ForkSessionResponse = serde_json::from_value(value.clone()).unwrap();
8791 assert_eq!(fork.available_commands, expected);
8792 assert_eq!(fork.config_options, config_options);
8793 }
8794
8795 value.as_object_mut().unwrap().remove("sessionId");
8796 let resume: ResumeSessionResponse = serde_json::from_value(value).unwrap();
8797 assert_eq!(resume.available_commands, expected);
8798 assert_eq!(resume.config_options, config_options);
8799 }
8800
8801 let resume: ResumeSessionResponse = serde_json::from_value(json!(null)).unwrap();
8802 assert_eq!(resume.available_commands, []);
8803 }
8804
8805 #[test]
8806 fn test_resume_session_replay_from_serialization() {
8807 assert_eq!(
8808 serde_json::to_value(ResumeSessionRequest::new(
8809 "sess_abc123",
8810 "/home/user/project"
8811 ))
8812 .unwrap(),
8813 json!({
8814 "sessionId": "sess_abc123",
8815 "cwd": "/home/user/project"
8816 })
8817 );
8818 assert_eq!(
8819 serde_json::to_value(
8820 ResumeSessionRequest::new("sess_abc123", "/home/user/project")
8821 .replay_from(ReplayFrom::from(ReplayFromStart::new()))
8822 )
8823 .unwrap(),
8824 json!({
8825 "sessionId": "sess_abc123",
8826 "cwd": "/home/user/project",
8827 "replayFrom": {
8828 "type": "start"
8829 }
8830 })
8831 );
8832
8833 let replay: ResumeSessionRequest = serde_json::from_value(json!({
8834 "sessionId": "sess_abc123",
8835 "cwd": "/home/user/project",
8836 "replayFrom": {
8837 "type": "start"
8838 }
8839 }))
8840 .unwrap();
8841 assert!(matches!(replay.replay_from, Some(ReplayFrom::Start(_))));
8842
8843 let none: ResumeSessionRequest = serde_json::from_value(json!({
8844 "sessionId": "sess_abc123",
8845 "cwd": "/home/user/project",
8846 "replayFrom": null
8847 }))
8848 .unwrap();
8849 assert!(none.replay_from.is_none());
8850 }
8851
8852 #[test]
8853 fn test_auth_method_agent_serialization() {
8854 let method = AuthMethod::Agent(AuthMethodAgent::new("default-auth", "Default Auth"));
8855
8856 let json = serde_json::to_value(&method).unwrap();
8857 assert_eq!(
8858 json,
8859 json!({
8860 "methodId": "default-auth",
8861 "name": "Default Auth",
8862 "type": "agent"
8863 })
8864 );
8865 assert!(!json.as_object().unwrap().contains_key("description"));
8867
8868 let deserialized: AuthMethod = serde_json::from_value(json).unwrap();
8869 match deserialized {
8870 AuthMethod::Agent(AuthMethodAgent {
8871 method_id, name, ..
8872 }) => {
8873 assert_eq!(method_id.0.as_ref(), "default-auth");
8874 assert_eq!(name, "Default Auth");
8875 }
8876 _ => panic!("Expected Agent variant"),
8877 }
8878 }
8879
8880 #[test]
8881 fn test_auth_method_agent_deserialization() {
8882 let json = json!({
8883 "methodId": "agent-auth",
8884 "name": "Agent Auth",
8885 "type": "agent"
8886 });
8887
8888 let deserialized: AuthMethod = serde_json::from_value(json).unwrap();
8889 assert!(matches!(deserialized, AuthMethod::Agent(_)));
8890 }
8891
8892 #[test]
8893 fn test_auth_method_agent_requires_type() {
8894 assert!(
8895 serde_json::from_value::<AuthMethod>(json!({
8896 "methodId": "agent-auth",
8897 "name": "Agent Auth"
8898 }))
8899 .is_err()
8900 );
8901 }
8902
8903 #[test]
8904 fn test_auth_method_agent_rejects_null_type() {
8905 assert!(
8906 serde_json::from_value::<AuthMethod>(json!({
8907 "methodId": "agent-auth",
8908 "name": "Agent Auth",
8909 "type": null
8910 }))
8911 .is_err()
8912 );
8913 }
8914
8915 #[test]
8916 fn test_auth_method_unknown_does_not_hide_malformed_agent() {
8917 assert!(
8918 serde_json::from_value::<AuthMethod>(json!({
8919 "methodId": "agent-auth",
8920 "type": "agent"
8921 }))
8922 .is_err()
8923 );
8924 assert!(
8925 serde_json::from_value::<AuthMethod>(json!({
8926 "methodId": "api-key",
8927 "type": "env_var",
8928 "vars": [{"name": "API_KEY"}]
8929 }))
8930 .is_err()
8931 );
8932 }
8933
8934 #[test]
8935 fn test_auth_method_unknown_variant_roundtrip() {
8936 let method: AuthMethod = serde_json::from_value(json!({
8937 "methodId": "oauth",
8938 "name": "OAuth",
8939 "type": "_oauth",
8940 "authorizationUrl": "https://example.com/auth"
8941 }))
8942 .unwrap();
8943
8944 assert_eq!(method.method_id().0.as_ref(), "oauth");
8945 assert_eq!(method.name(), "OAuth");
8946 let AuthMethod::Other(unknown) = method else {
8947 panic!("expected unknown auth method");
8948 };
8949 assert_eq!(unknown.type_, "_oauth");
8950 assert_eq!(
8951 unknown.fields.get("authorizationUrl"),
8952 Some(&json!("https://example.com/auth"))
8953 );
8954
8955 assert_eq!(
8956 serde_json::to_value(AuthMethod::Other(unknown)).unwrap(),
8957 json!({
8958 "methodId": "oauth",
8959 "name": "OAuth",
8960 "type": "_oauth",
8961 "authorizationUrl": "https://example.com/auth"
8962 })
8963 );
8964 }
8965
8966 #[test]
8967 fn test_auth_method_unknown_does_not_hide_malformed_known_variant() {
8968 assert!(
8969 serde_json::from_value::<AuthMethod>(json!({
8970 "methodId": "terminal-auth",
8971 "type": "terminal"
8972 }))
8973 .is_err()
8974 );
8975 }
8976
8977 #[test]
8978 fn test_tool_call_and_terminal_cancel_serialization() {
8979 assert_eq!(AGENT_METHOD_NAMES.tool_call_cancel, "tool_call/cancel");
8980 assert_eq!(AGENT_METHOD_NAMES.terminal_cancel, "terminal/cancel");
8981 assert_eq!(
8982 ClientRequest::CancelToolCallRequest(Box::new(CancelToolCallRequest::new(
8983 "sess_abc123",
8984 "call_012"
8985 )))
8986 .method(),
8987 "tool_call/cancel"
8988 );
8989 assert_eq!(
8990 ClientRequest::CancelTerminalRequest(Box::new(CancelTerminalRequest::new(
8991 "sess_abc123",
8992 "term_003"
8993 )))
8994 .method(),
8995 "terminal/cancel"
8996 );
8997 assert_eq!(
8998 serde_json::to_value(CancelToolCallRequest::new("sess_abc123", "call_012")).unwrap(),
8999 json!({"sessionId": "sess_abc123", "toolCallId": "call_012"})
9000 );
9001 assert_eq!(
9002 serde_json::to_value(CancelTerminalRequest::new("sess_abc123", "term_003")).unwrap(),
9003 json!({"sessionId": "sess_abc123", "terminalId": "term_003"})
9004 );
9005 assert!(
9006 serde_json::from_value::<CancelToolCallRequest>(json!({"sessionId": "sess_abc123"}))
9007 .is_err()
9008 );
9009 assert_eq!(
9010 serde_json::to_value(CancelTerminalResponse::new()).unwrap(),
9011 json!({})
9012 );
9013 }
9014
9015 #[test]
9016 fn test_session_delete_serialization() {
9017 assert_eq!(AGENT_METHOD_NAMES.session_delete, "session/delete");
9018 assert_eq!(
9019 ClientRequest::DeleteSessionRequest(Box::new(DeleteSessionRequest::new("sess_abc123")))
9020 .method(),
9021 "session/delete"
9022 );
9023 assert_eq!(
9024 serde_json::to_value(DeleteSessionRequest::new("sess_abc123")).unwrap(),
9025 json!({
9026 "sessionId": "sess_abc123"
9027 })
9028 );
9029 assert_eq!(
9030 serde_json::to_value(DeleteSessionResponse::new()).unwrap(),
9031 json!({})
9032 );
9033 assert_eq!(
9034 serde_json::to_value(
9035 SessionCapabilities::new().delete(SessionDeleteCapabilities::new())
9036 )
9037 .unwrap(),
9038 json!({
9039 "delete": {}
9040 })
9041 );
9042 }
9043 #[cfg(feature = "unstable_session_set_title")]
9044 #[test]
9045 fn test_session_set_title_serialization() {
9046 assert_eq!(AGENT_METHOD_NAMES.session_set_title, "session/set_title");
9047 assert_eq!(
9048 ClientRequest::SetSessionTitleRequest(Box::new(SetSessionTitleRequest::new(
9049 "sess_abc123",
9050 "Investigate OAuth timeout"
9051 )))
9052 .method(),
9053 "session/set_title"
9054 );
9055 assert_eq!(
9056 serde_json::to_value(SetSessionTitleRequest::new(
9057 "sess_abc123",
9058 "Investigate OAuth timeout"
9059 ))
9060 .unwrap(),
9061 json!({
9062 "sessionId": "sess_abc123",
9063 "title": "Investigate OAuth timeout"
9064 })
9065 );
9066 assert_eq!(
9067 serde_json::to_value(SetSessionTitleResponse::new("Investigate OAuth timeout"))
9068 .unwrap(),
9069 json!({
9070 "title": "Investigate OAuth timeout"
9071 })
9072 );
9073 assert_eq!(
9074 serde_json::to_value(SessionCapabilities::new().title(SessionTitleCapabilities::new()))
9075 .unwrap(),
9076 json!({
9077 "title": {}
9078 })
9079 );
9080 }
9081
9082 #[cfg(feature = "unstable_session_set_title")]
9083 #[test]
9084 fn test_session_set_title_requires_title() {
9085 for params in [
9086 json!({"sessionId": "sess_abc123"}),
9087 json!({"sessionId": "sess_abc123", "title": null}),
9088 json!({"sessionId": "sess_abc123", "title": 42}),
9089 ] {
9090 assert!(serde_json::from_value::<SetSessionTitleRequest>(params).is_err());
9091 }
9092 for result in [json!({}), json!({"title": null})] {
9093 assert!(serde_json::from_value::<SetSessionTitleResponse>(result).is_err());
9094 }
9095 }
9096
9097 #[cfg(feature = "unstable_session_options")]
9098 #[test]
9099 fn test_session_options_serialization() {
9100 assert_eq!(AGENT_METHOD_NAMES.session_options, "session/options");
9101 assert_eq!(
9102 ClientRequest::SessionOptionsRequest(Box::new(SessionOptionsRequest::new(
9103 "/home/user/project"
9104 )))
9105 .method(),
9106 "session/options"
9107 );
9108 assert_eq!(
9109 serde_json::to_value(
9110 SessionOptionsRequest::new("/home/user/project")
9111 .session_id(SessionId::new("sess_abc123"))
9112 )
9113 .unwrap(),
9114 json!({"cwd": "/home/user/project", "sessionId": "sess_abc123"})
9115 );
9116 assert_eq!(
9117 serde_json::from_value::<SessionOptionsRequest>(
9118 json!({"cwd": "/home/user/project", "additionalDirectories": null, "sessionId": null})
9119 )
9120 .unwrap(),
9121 SessionOptionsRequest::new("/home/user/project")
9122 );
9123 let request = NewSessionRequest::new("/home/user/project").config_options(vec![
9124 InitialSessionConfigOption::new("model", SessionConfigOptionValue::id("model-2")),
9125 InitialSessionConfigOption::new("fast", SessionConfigOptionValue::boolean(true)),
9126 ]);
9127 let value = serde_json::to_value(&request).unwrap();
9128 assert_eq!(
9129 value["configOptions"],
9130 json!([
9131 {"configId": "model", "type": "id", "value": "model-2"},
9132 {"configId": "fast", "type": "boolean", "value": true}
9133 ])
9134 );
9135 assert_eq!(
9136 serde_json::from_value::<NewSessionRequest>(value).unwrap(),
9137 request
9138 );
9139 assert!(
9140 serde_json::from_value::<NewSessionRequest>(json!({
9141 "cwd": "/home/user/project",
9142 "mcpServers": [],
9143 "configOptions": [{"type": "boolean", "value": true}]
9144 }))
9145 .is_err()
9146 );
9147 assert_eq!(
9148 serde_json::to_value(SessionOptionsResponse::new()).unwrap(),
9149 json!({})
9150 );
9151 #[cfg(feature = "unstable_session_fork")]
9152 {
9153 let fork =
9154 ForkSessionRequest::new("sess_abc123", "/home/user/project").config_options(vec![
9155 InitialSessionConfigOption::new(
9156 "model",
9157 SessionConfigOptionValue::id("model-2"),
9158 ),
9159 ]);
9160 let value = serde_json::to_value(&fork).unwrap();
9161 assert_eq!(
9162 value["configOptions"],
9163 json!([{"configId": "model", "type": "id", "value": "model-2"}])
9164 );
9165 assert_eq!(
9166 serde_json::from_value::<ForkSessionRequest>(value).unwrap(),
9167 fork
9168 );
9169 assert_eq!(
9171 serde_json::from_value::<ForkSessionRequest>(json!({
9172 "sessionId": "sess_abc123",
9173 "cwd": "/home/user/project",
9174 "configOptions": null
9175 }))
9176 .unwrap(),
9177 ForkSessionRequest::new("sess_abc123", "/home/user/project")
9178 );
9179 assert!(
9180 serde_json::from_value::<ForkSessionRequest>(json!({
9181 "sessionId": "sess_abc123",
9182 "cwd": "/home/user/project",
9183 "configOptions": [{"type": "boolean", "value": true}]
9184 }))
9185 .is_err()
9186 );
9187 }
9188 assert_eq!(
9189 serde_json::to_value(
9190 SessionCapabilities::new().options(SessionOptionsCapabilities::new())
9191 )
9192 .unwrap(),
9193 json!({"options": {}})
9194 );
9195 }
9196
9197 #[cfg(feature = "unstable_session_status")]
9198 #[test]
9199 fn test_session_status_serialization() {
9200 assert_eq!(AGENT_METHOD_NAMES.session_status, "session/status");
9201 assert_eq!(
9202 ClientRequest::SessionStatusRequest(Box::new(SessionStatusRequest::new("sess_abc123")))
9203 .method(),
9204 "session/status"
9205 );
9206 assert_eq!(
9207 serde_json::to_value(SessionStatusRequest::new("sess_abc123")).unwrap(),
9208 json!({"sessionId": "sess_abc123"})
9209 );
9210 assert_eq!(
9211 serde_json::to_value(SessionStatusResponse::new(SessionStatus::Saved)).unwrap(),
9212 json!({"status": "saved"})
9213 );
9214 assert_eq!(
9215 serde_json::to_value(
9216 SessionCapabilities::new().status(SessionStatusCapabilities::new())
9217 )
9218 .unwrap(),
9219 json!({"status": {}})
9220 );
9221 assert_eq!(
9222 serde_json::to_value(SessionStatusResponse::new(SessionStatus::Open).state(
9223 StateUpdate::RequiresAction(crate::v2::RequiresActionStateUpdate::new())
9224 ))
9225 .unwrap(),
9226 json!({
9227 "status": "open",
9228 "state": {"state": "requires_action"}
9229 })
9230 );
9231 for state in [json!(null), json!("running"), json!({"state": 7})] {
9232 let response = serde_json::from_value::<SessionStatusResponse>(
9233 json!({"status": "open", "state": state}),
9234 )
9235 .unwrap();
9236 assert_eq!(response.state, None);
9237 }
9238 }
9239
9240 #[cfg(feature = "unstable_session_status")]
9241 #[test]
9242 fn test_session_status_is_strict_and_open() {
9243 let custom =
9244 serde_json::from_value::<SessionStatusResponse>(json!({"status": "_suspended"}))
9245 .unwrap();
9246 assert_eq!(
9247 custom.status,
9248 SessionStatus::Other("_suspended".to_string())
9249 );
9250 assert_eq!(
9251 serde_json::to_value(&custom).unwrap(),
9252 json!({"status": "_suspended"})
9253 );
9254 for result in [json!({}), json!({"status": null}), json!({"status": 1})] {
9255 assert!(serde_json::from_value::<SessionStatusResponse>(result).is_err());
9256 }
9257 for params in [json!({}), json!({"sessionId": null})] {
9258 assert!(serde_json::from_value::<SessionStatusRequest>(params).is_err());
9259 }
9260 }
9261
9262 #[cfg(feature = "unstable_session_archive")]
9263 #[test]
9264 fn test_session_archive_serialization() {
9265 assert_eq!(AGENT_METHOD_NAMES.session_archive, "session/archive");
9266 assert_eq!(AGENT_METHOD_NAMES.session_unarchive, "session/unarchive");
9267 assert_eq!(
9268 ClientRequest::ArchiveSessionRequest(Box::new(ArchiveSessionRequest::new(
9269 "sess_abc123"
9270 )))
9271 .method(),
9272 "session/archive"
9273 );
9274 assert_eq!(
9275 ClientRequest::UnarchiveSessionRequest(Box::new(UnarchiveSessionRequest::new(
9276 "sess_abc123"
9277 )))
9278 .method(),
9279 "session/unarchive"
9280 );
9281 assert_eq!(
9282 serde_json::to_value(ArchiveSessionRequest::new("sess_abc123")).unwrap(),
9283 json!({"sessionId": "sess_abc123"})
9284 );
9285 assert_eq!(
9286 serde_json::to_value(UnarchiveSessionResponse::new()).unwrap(),
9287 json!({})
9288 );
9289 assert_eq!(
9290 serde_json::to_value(
9291 SessionCapabilities::new().archive(SessionArchiveCapabilities::new())
9292 )
9293 .unwrap(),
9294 json!({"archive": {}})
9295 );
9296 assert_eq!(
9297 serde_json::to_value(
9298 ListSessionsRequest::new()
9299 .cwd("/home/user/project")
9300 .archived(SessionArchiveFilter::Only)
9301 )
9302 .unwrap(),
9303 json!({"cwd": "/home/user/project", "archived": "only"})
9304 );
9305 assert_eq!(
9306 serde_json::to_value(
9307 SessionInfo::new("sess_abc123", "/home/user/project").archived(true)
9308 )
9309 .unwrap(),
9310 json!({"sessionId": "sess_abc123", "cwd": "/home/user/project", "archived": true})
9311 );
9312 }
9313
9314 #[cfg(feature = "unstable_session_archive")]
9315 #[test]
9316 fn test_session_archive_filter_is_strict_and_open() {
9317 for (value, expected) in [
9318 (json!(null), None),
9319 (json!("include"), Some(SessionArchiveFilter::Include)),
9320 (
9321 json!("_recent"),
9322 Some(SessionArchiveFilter::Other("_recent".to_string())),
9323 ),
9324 ] {
9325 let request =
9326 serde_json::from_value::<ListSessionsRequest>(json!({"archived": value})).unwrap();
9327 assert_eq!(request.archived, expected);
9328 }
9329 for value in [json!(true), json!(1), json!({})] {
9330 assert!(
9331 serde_json::from_value::<ListSessionsRequest>(json!({"archived": value})).is_err()
9332 );
9333 }
9334 let info = serde_json::from_value::<SessionInfo>(
9335 json!({"sessionId": "sess_abc123", "cwd": "/home/user/project", "archived": "yes"}),
9336 )
9337 .unwrap();
9338 assert_eq!(info.archived, None);
9339 }
9340
9341 #[test]
9342 fn test_session_additional_directories_serialization() {
9343 assert_eq!(
9344 serde_json::to_value(NewSessionRequest::new("/home/user/project")).unwrap(),
9345 json!({
9346 "cwd": "/home/user/project",
9347 })
9348 );
9349 assert_eq!(
9350 serde_json::to_value(
9351 NewSessionRequest::new("/home/user/project").additional_directories(vec![
9352 PathBuf::from("/home/user/shared-lib"),
9353 PathBuf::from("/home/user/product-docs"),
9354 ])
9355 )
9356 .unwrap(),
9357 json!({
9358 "cwd": "/home/user/project",
9359 "additionalDirectories": [
9360 "/home/user/shared-lib",
9361 "/home/user/product-docs"
9362 ],
9363 })
9364 );
9365 assert_eq!(
9366 serde_json::to_value(ResumeSessionRequest::new(
9367 "sess_abc123",
9368 "/home/user/project"
9369 ))
9370 .unwrap(),
9371 json!({
9372 "sessionId": "sess_abc123",
9373 "cwd": "/home/user/project",
9374 })
9375 );
9376 assert_eq!(
9377 serde_json::from_value::<ResumeSessionRequest>(json!({
9378 "sessionId": "sess_abc123",
9379 "cwd": "/home/user/project"
9380 }))
9381 .unwrap()
9382 .mcp_servers,
9383 Vec::<McpServer>::new()
9384 );
9385 assert_eq!(
9386 serde_json::from_value::<ResumeSessionRequest>(json!({
9387 "sessionId": "sess_abc123",
9388 "cwd": "/home/user/project",
9389 "mcpServers": null
9390 }))
9391 .unwrap()
9392 .mcp_servers,
9393 Vec::<McpServer>::new()
9394 );
9395 assert_eq!(
9396 serde_json::to_value(SessionInfo::new("sess_abc123", "/home/user/project")).unwrap(),
9397 json!({
9398 "sessionId": "sess_abc123",
9399 "cwd": "/home/user/project"
9400 })
9401 );
9402 assert_eq!(
9403 serde_json::to_value(
9404 SessionInfo::new("sess_abc123", "/home/user/project").additional_directories(vec![
9405 PathBuf::from("/home/user/shared-lib"),
9406 PathBuf::from("/home/user/product-docs"),
9407 ])
9408 )
9409 .unwrap(),
9410 json!({
9411 "sessionId": "sess_abc123",
9412 "cwd": "/home/user/project",
9413 "additionalDirectories": [
9414 "/home/user/shared-lib",
9415 "/home/user/product-docs"
9416 ]
9417 })
9418 );
9419 assert_eq!(
9420 serde_json::from_value::<SessionInfo>(json!({
9421 "sessionId": "sess_abc123",
9422 "cwd": "/home/user/project"
9423 }))
9424 .unwrap()
9425 .additional_directories,
9426 Vec::<AbsolutePath>::new()
9427 );
9428 }
9429 #[test]
9430 fn test_session_additional_directories_capabilities_serialization() {
9431 assert_eq!(
9432 serde_json::to_value(
9433 SessionCapabilities::new()
9434 .additional_directories(SessionAdditionalDirectoriesCapabilities::new())
9435 )
9436 .unwrap(),
9437 json!({
9438 "additionalDirectories": {}
9439 })
9440 );
9441 }
9442
9443 #[test]
9444 fn test_session_system_prompt_capabilities_serialization() {
9445 assert_eq!(
9446 serde_json::to_value(
9447 SessionCapabilities::new().system_prompt(SessionSystemPromptCapabilities::new())
9448 )
9449 .unwrap(),
9450 json!({ "systemPrompt": {} })
9451 );
9452 assert_eq!(
9453 serde_json::to_value(
9454 SessionCapabilities::new().system_prompt(
9455 SessionSystemPromptCapabilities::new().mode(
9456 SessionSystemPromptModeCapabilities::new()
9457 .override_(SessionSystemPromptOverrideCapabilities::new())
9458 )
9459 )
9460 )
9461 .unwrap(),
9462 json!({ "systemPrompt": { "mode": { "override": {} } } })
9463 );
9464 assert_eq!(
9465 serde_json::from_value::<SessionCapabilities>(
9466 json!({ "systemPrompt": { "mode": { "override": {} } } })
9467 )
9468 .unwrap()
9469 .system_prompt
9470 .and_then(|capabilities| capabilities.mode)
9471 .and_then(|mode| mode.override_),
9472 Some(SessionSystemPromptOverrideCapabilities::new())
9473 );
9474
9475 assert_eq!(
9477 serde_json::from_value::<SessionCapabilities>(json!({ "systemPrompt": "yes" }))
9478 .unwrap()
9479 .system_prompt,
9480 None
9481 );
9482 assert_eq!(
9483 serde_json::from_value::<SessionCapabilities>(
9484 json!({ "systemPrompt": { "mode": { "override": true } } })
9485 )
9486 .unwrap()
9487 .system_prompt,
9488 Some(
9489 SessionSystemPromptCapabilities::new()
9490 .mode(SessionSystemPromptModeCapabilities::new())
9491 )
9492 );
9493 assert_eq!(
9494 serde_json::from_value::<SessionCapabilities>(
9495 json!({ "systemPrompt": { "mode": "override" } })
9496 )
9497 .unwrap()
9498 .system_prompt,
9499 Some(SessionSystemPromptCapabilities::new())
9500 );
9501 }
9502
9503 #[test]
9504 fn test_system_prompt_lifecycle_request_serialization() {
9505 let system_prompt = SystemPrompt::new(vec![ContentBlock::from(
9506 "You are a code review specialist.",
9507 )]);
9508 let system_prompt_json = json!({
9509 "mode": "append",
9510 "content": [{ "type": "text", "text": "You are a code review specialist." }]
9511 });
9512
9513 let request =
9514 NewSessionRequest::new("/home/user/project").system_prompt(system_prompt.clone());
9515 let request_json = json!({
9516 "cwd": "/home/user/project",
9517 "systemPrompt": system_prompt_json
9518 });
9519 assert_eq!(serde_json::to_value(&request).unwrap(), request_json);
9520 assert_eq!(
9521 serde_json::from_value::<NewSessionRequest>(request_json).unwrap(),
9522 request
9523 );
9524
9525 assert_eq!(
9526 serde_json::to_value(
9527 ResumeSessionRequest::new("sess_abc123", "/home/user/project")
9528 .system_prompt(system_prompt.clone())
9529 )
9530 .unwrap()["systemPrompt"],
9531 system_prompt_json
9532 );
9533 #[cfg(feature = "unstable_session_fork")]
9534 assert_eq!(
9535 serde_json::to_value(
9536 ForkSessionRequest::new("sess_abc123", "/home/user/project")
9537 .system_prompt(system_prompt.clone())
9538 )
9539 .unwrap()["systemPrompt"],
9540 system_prompt_json
9541 );
9542
9543 let override_prompt =
9544 SystemPrompt::new(vec![ContentBlock::from("...")]).mode(SystemPromptMode::Override);
9545 let override_json = json!({
9546 "mode": "override",
9547 "content": [{ "type": "text", "text": "..." }]
9548 });
9549 assert_eq!(
9550 serde_json::to_value(&override_prompt).unwrap(),
9551 override_json
9552 );
9553 assert_eq!(
9554 serde_json::from_value::<SystemPrompt>(override_json).unwrap(),
9555 override_prompt
9556 );
9557 }
9558
9559 #[test]
9562 fn test_system_prompt_new_defaults_to_append() {
9563 let system_prompt = SystemPrompt::new(vec![ContentBlock::from("...")]);
9564 assert_eq!(system_prompt.mode, SystemPromptMode::Append);
9565 assert_eq!(
9566 serde_json::to_value(&system_prompt).unwrap(),
9567 json!({ "mode": "append", "content": [{ "type": "text", "text": "..." }] })
9568 );
9569 }
9570
9571 #[test]
9575 fn test_system_prompt_preserves_unknown_modes() {
9576 for mode in ["_vendor_mode", "prepend"] {
9577 let system_prompt_json =
9578 json!({ "mode": mode, "content": [{ "type": "text", "text": "..." }] });
9579 let system_prompt: SystemPrompt =
9580 serde_json::from_value(system_prompt_json.clone()).unwrap();
9581 assert_eq!(
9582 system_prompt.mode,
9583 SystemPromptMode::Other(mode.to_string())
9584 );
9585 assert_eq!(
9586 serde_json::to_value(&system_prompt).unwrap(),
9587 system_prompt_json
9588 );
9589 }
9590 }
9591
9592 fn assert_system_prompt_is_strict<T>(base: &serde_json::Value)
9596 where
9597 T: serde::de::DeserializeOwned + PartialEq + std::fmt::Debug,
9598 {
9599 let name = std::any::type_name::<T>();
9600 let with = |system_prompt: serde_json::Value| {
9601 let mut request = base.clone();
9602 request["systemPrompt"] = system_prompt;
9603 serde_json::from_value::<T>(request)
9604 };
9605
9606 for system_prompt in [
9607 json!("You are a code review specialist."),
9608 json!({ "content": [{ "type": "text", "text": "..." }] }),
9609 json!({ "mode": null, "content": [{ "type": "text", "text": "..." }] }),
9610 json!({ "mode": 1, "content": [{ "type": "text", "text": "..." }] }),
9611 json!({ "mode": "append" }),
9612 json!({ "mode": "append", "content": "..." }),
9613 json!({ "mode": "append", "content": [{ "type": "text" }] }),
9614 ] {
9615 assert!(
9616 with(system_prompt.clone()).is_err(),
9617 "{name}.systemPrompt: {system_prompt}"
9618 );
9619 }
9620
9621 assert_eq!(
9622 with(serde_json::Value::Null).unwrap(),
9623 serde_json::from_value::<T>(base.clone()).unwrap(),
9624 "{name}.systemPrompt"
9625 );
9626 }
9627
9628 #[test]
9629 fn test_session_setup_requests_reject_malformed_system_prompts() {
9630 assert!(
9631 serde_json::to_value(NewSessionRequest::new("/repo"))
9632 .unwrap()
9633 .get("systemPrompt")
9634 .is_none()
9635 );
9636 assert_system_prompt_is_strict::<NewSessionRequest>(&json!({ "cwd": "/repo" }));
9637 assert_system_prompt_is_strict::<ResumeSessionRequest>(&json!({
9638 "sessionId": "sess-1",
9639 "cwd": "/repo"
9640 }));
9641 #[cfg(feature = "unstable_session_fork")]
9642 assert_system_prompt_is_strict::<ForkSessionRequest>(&json!({
9643 "sessionId": "sess-1",
9644 "cwd": "/repo"
9645 }));
9646 }
9647
9648 #[test]
9651 fn test_system_prompt_preserves_unknown_content_blocks() {
9652 let request: NewSessionRequest = serde_json::from_value(json!({
9653 "cwd": "/home/user/project",
9654 "systemPrompt": {
9655 "mode": "append",
9656 "content": [{ "type": "_vendor_video", "uri": "https://example.com/intro.mp4" }]
9657 }
9658 }))
9659 .unwrap();
9660 let content = request.system_prompt.unwrap().content;
9661 assert_eq!(content.len(), 1);
9662 assert!(matches!(content[0], ContentBlock::Other(_)));
9663 }
9664
9665 #[test]
9666 fn test_auth_method_terminal_serialization() {
9667 let method = AuthMethod::Terminal(AuthMethodTerminal::new("tui-auth", "Terminal Auth"));
9668
9669 let json = serde_json::to_value(&method).unwrap();
9670 assert_eq!(
9671 json,
9672 json!({
9673 "methodId": "tui-auth",
9674 "name": "Terminal Auth",
9675 "type": "terminal"
9676 })
9677 );
9678 assert!(!json.as_object().unwrap().contains_key("args"));
9680 assert!(!json.as_object().unwrap().contains_key("env"));
9681
9682 let deserialized: AuthMethod = serde_json::from_value(json).unwrap();
9683 match deserialized {
9684 AuthMethod::Terminal(AuthMethodTerminal { args, env, .. }) => {
9685 assert_eq!(args, Vec::<String>::new());
9686 assert_eq!(env, []);
9687 }
9688 _ => panic!("Expected Terminal variant"),
9689 }
9690 }
9691
9692 #[test]
9693 fn test_auth_method_terminal_with_args_and_env_serialization() {
9694 let method = AuthMethod::Terminal(
9695 AuthMethodTerminal::new("tui-auth", "Terminal Auth")
9696 .args(vec!["--interactive".to_string(), "--color".to_string()])
9697 .env(vec![EnvVariable::new("TERM", "xterm-256color")]),
9698 );
9699
9700 let json = serde_json::to_value(&method).unwrap();
9701 assert_eq!(
9702 json,
9703 json!({
9704 "methodId": "tui-auth",
9705 "name": "Terminal Auth",
9706 "type": "terminal",
9707 "args": ["--interactive", "--color"],
9708 "env": [
9709 {
9710 "name": "TERM",
9711 "value": "xterm-256color"
9712 }
9713 ]
9714 })
9715 );
9716
9717 let deserialized: AuthMethod = serde_json::from_value(json).unwrap();
9718 match deserialized {
9719 AuthMethod::Terminal(AuthMethodTerminal { args, env, .. }) => {
9720 assert_eq!(args, vec!["--interactive", "--color"]);
9721 assert_eq!(env.len(), 1);
9722 assert_eq!(env[0].name, "TERM");
9723 assert_eq!(env[0].value, "xterm-256color");
9724 }
9725 _ => panic!("Expected Terminal variant"),
9726 }
9727 }
9728
9729 #[test]
9730 fn test_session_config_option_id_serialize() {
9731 let val = SessionConfigOptionValue::id("model-1");
9732 let json = serde_json::to_value(&val).unwrap();
9733 assert_eq!(json, json!({ "type": "id", "value": "model-1" }));
9734 }
9735
9736 #[test]
9737 fn test_session_config_option_value_boolean_serialize() {
9738 let val = SessionConfigOptionValue::boolean(true);
9739 let json = serde_json::to_value(&val).unwrap();
9740 assert_eq!(json, json!({ "type": "boolean", "value": true }));
9741 }
9742
9743 #[test]
9744 fn test_session_config_option_value_deserialize_id() {
9745 let json = json!({ "type": "id", "value": "model-1" });
9746 let val: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
9747 assert_eq!(val, SessionConfigOptionValue::id("model-1"));
9748 assert_eq!(val.as_id().unwrap().to_string(), "model-1");
9749 }
9750
9751 #[test]
9752 fn test_session_config_option_value_deserialize_requires_type() {
9753 let json = json!({ "value": "model-1" });
9754 let result = serde_json::from_value::<SessionConfigOptionValue>(json);
9755 assert!(result.is_err());
9756 }
9757
9758 #[test]
9759 fn test_session_config_option_value_deserialize_boolean() {
9760 let json = json!({ "type": "boolean", "value": true });
9761 let val: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
9762 assert_eq!(val, SessionConfigOptionValue::boolean(true));
9763 assert_eq!(val.as_bool(), Some(true));
9764 }
9765
9766 #[test]
9767 fn test_session_config_option_value_deserialize_boolean_false() {
9768 let json = json!({ "type": "boolean", "value": false });
9769 let val: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
9770 assert_eq!(val, SessionConfigOptionValue::boolean(false));
9771 assert_eq!(val.as_bool(), Some(false));
9772 }
9773
9774 #[test]
9775 fn test_session_config_option_value_deserialize_unknown_type_with_string_value() {
9776 let json = json!({
9777 "type": "text",
9778 "value": "freeform input",
9779 "maxLength": 200
9780 });
9781 let val: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
9782 let SessionConfigOptionValue::Other(unknown) = val else {
9783 panic!("Expected Other variant");
9784 };
9785 assert_eq!(unknown.type_, "text");
9786 assert_eq!(unknown.value, json!("freeform input"));
9787 assert_eq!(unknown.fields["maxLength"], json!(200));
9788 }
9789
9790 #[test]
9791 fn test_session_config_option_value_deserialize_unknown_type_with_object_value() {
9792 let json = json!({
9793 "type": "range",
9794 "value": { "min": 1, "max": 5 }
9795 });
9796 let val: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
9797 let SessionConfigOptionValue::Other(unknown) = val else {
9798 panic!("Expected Other variant");
9799 };
9800 assert_eq!(unknown.type_, "range");
9801 assert_eq!(unknown.value, json!({ "min": 1, "max": 5 }));
9802 }
9803
9804 #[test]
9805 fn test_session_config_option_value_roundtrip_id() {
9806 let original = SessionConfigOptionValue::id("option-a");
9807 let json = serde_json::to_value(&original).unwrap();
9808 let roundtripped: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
9809 assert_eq!(original, roundtripped);
9810 }
9811
9812 #[test]
9813 fn test_session_config_option_value_roundtrip_boolean() {
9814 let original = SessionConfigOptionValue::boolean(false);
9815 let json = serde_json::to_value(&original).unwrap();
9816 let roundtripped: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
9817 assert_eq!(original, roundtripped);
9818 }
9819
9820 #[test]
9821 fn test_session_config_option_value_roundtrip_other() {
9822 let mut fields = BTreeMap::new();
9823 fields.insert("maxLength".to_string(), json!(200));
9824 let original = SessionConfigOptionValue::Other(OtherSessionConfigOptionValue::new(
9825 "text",
9826 json!("freeform input"),
9827 fields,
9828 ));
9829 let json = serde_json::to_value(&original).unwrap();
9830 let roundtripped: SessionConfigOptionValue = serde_json::from_value(json).unwrap();
9831 assert_eq!(original, roundtripped);
9832 }
9833
9834 #[test]
9835 fn test_session_config_option_value_type_mismatch_boolean_with_string() {
9836 let json = json!({ "type": "boolean", "value": "not a bool" });
9837 let result = serde_json::from_value::<SessionConfigOptionValue>(json);
9838 assert!(result.is_err());
9839 }
9840
9841 #[test]
9842 fn test_session_config_option_value_from_impls() {
9843 let from_str: SessionConfigOptionValue = "model-1".into();
9844 assert_eq!(from_str.as_id().unwrap().to_string(), "model-1");
9845
9846 let from_id: SessionConfigOptionValue = SessionConfigValueId::new("model-2").into();
9847 assert_eq!(from_id.as_id().unwrap().to_string(), "model-2");
9848
9849 let from_bool: SessionConfigOptionValue = true.into();
9850 assert_eq!(from_bool.as_bool(), Some(true));
9851 }
9852
9853 #[test]
9854 fn test_set_session_config_option_request_id() {
9855 let req = SetSessionConfigOptionRequest::new("sess_1", "model", "model-1");
9856 let json = serde_json::to_value(&req).unwrap();
9857 assert_eq!(
9858 json,
9859 json!({
9860 "sessionId": "sess_1",
9861 "configId": "model",
9862 "type": "id",
9863 "value": "model-1"
9864 })
9865 );
9866 }
9867
9868 #[test]
9869 fn test_set_session_config_option_request_boolean() {
9870 let req = SetSessionConfigOptionRequest::new("sess_1", "brave_mode", true);
9871 let json = serde_json::to_value(&req).unwrap();
9872 assert_eq!(
9873 json,
9874 json!({
9875 "sessionId": "sess_1",
9876 "configId": "brave_mode",
9877 "type": "boolean",
9878 "value": true
9879 })
9880 );
9881 }
9882
9883 #[test]
9884 fn test_set_session_config_option_request_deserialize_requires_type() {
9885 let json = json!({
9886 "sessionId": "sess_1",
9887 "configId": "model",
9888 "value": "model-1"
9889 });
9890 let result = serde_json::from_value::<SetSessionConfigOptionRequest>(json);
9891 assert!(result.is_err());
9892 }
9893
9894 #[test]
9895 fn test_set_session_config_option_request_deserialize_boolean() {
9896 let json = json!({
9897 "sessionId": "sess_1",
9898 "configId": "brave_mode",
9899 "type": "boolean",
9900 "value": true
9901 });
9902 let req: SetSessionConfigOptionRequest = serde_json::from_value(json).unwrap();
9903 assert_eq!(req.value.as_bool(), Some(true));
9904 }
9905
9906 #[test]
9907 fn test_set_session_config_option_request_roundtrip_id() {
9908 let original = SetSessionConfigOptionRequest::new("s", "c", "v");
9909 let json = serde_json::to_value(&original).unwrap();
9910 let roundtripped: SetSessionConfigOptionRequest = serde_json::from_value(json).unwrap();
9911 assert_eq!(original, roundtripped);
9912 }
9913
9914 #[test]
9915 fn test_set_session_config_option_request_roundtrip_boolean() {
9916 let original = SetSessionConfigOptionRequest::new("s", "c", false);
9917 let json = serde_json::to_value(&original).unwrap();
9918 let roundtripped: SetSessionConfigOptionRequest = serde_json::from_value(json).unwrap();
9919 assert_eq!(original, roundtripped);
9920 }
9921
9922 #[test]
9923 fn test_session_config_boolean_serialization() {
9924 let cfg = SessionConfigBoolean::new(true);
9925 let json = serde_json::to_value(&cfg).unwrap();
9926 assert_eq!(json, json!({ "currentValue": true }));
9927
9928 let deserialized: SessionConfigBoolean = serde_json::from_value(json).unwrap();
9929 assert!(deserialized.current_value);
9930 }
9931
9932 #[test]
9933 fn test_session_config_option_boolean_variant() {
9934 let opt = SessionConfigOption::boolean("brave_mode", "Brave Mode", false)
9935 .description("Skip confirmation prompts")
9936 .meta(test_meta());
9937 assert_eq!(serialized_meta_key_count(&opt), 1);
9938
9939 let json = serde_json::to_value(&opt).unwrap();
9940 assert_eq!(
9941 json,
9942 json!({
9943 "configId": "brave_mode",
9944 "name": "Brave Mode",
9945 "description": "Skip confirmation prompts",
9946 "type": "boolean",
9947 "currentValue": false,
9948 "_meta": {
9949 "source": "test"
9950 }
9951 })
9952 );
9953
9954 let deserialized: SessionConfigOption = serde_json::from_value(json).unwrap();
9955 assert_eq!(deserialized.config_id.to_string(), "brave_mode");
9956 assert_eq!(deserialized.name, "Brave Mode");
9957 match deserialized.kind {
9958 SessionConfigKind::Boolean(ref b) => assert!(!b.current_value),
9959 _ => panic!("Expected Boolean kind"),
9960 }
9961 }
9962
9963 #[test]
9964 fn test_session_config_option_select_still_works() {
9965 let opt = SessionConfigOption::select(
9967 "model",
9968 "Model",
9969 "model-1",
9970 vec![
9971 SessionConfigSelectOption::new("model-1", "Model 1"),
9972 SessionConfigSelectOption::new("model-2", "Model 2"),
9973 ],
9974 )
9975 .meta(test_meta());
9976 assert_eq!(serialized_meta_key_count(&opt), 1);
9977
9978 let json = serde_json::to_value(&opt).unwrap();
9979 assert_eq!(json["type"], "select");
9980 assert_eq!(json["currentValue"], "model-1");
9981 assert_eq!(json["options"].as_array().unwrap().len(), 2);
9982 assert_eq!(json["_meta"]["source"], "test");
9983
9984 let deserialized: SessionConfigOption = serde_json::from_value(json).unwrap();
9985 match deserialized.kind {
9986 SessionConfigKind::Select(ref s) => {
9987 assert_eq!(s.current_value.to_string(), "model-1");
9988 }
9989 _ => panic!("Expected Select kind"),
9990 }
9991 }
9992
9993 #[test]
9994 fn test_session_config_option_unknown_kind_roundtrip() {
9995 let option: SessionConfigOption = serde_json::from_value(json!({
9996 "configId": "verbosity",
9997 "name": "Verbosity",
9998 "type": "_slider",
9999 "currentValue": 3,
10000 "min": 0,
10001 "max": 5,
10002 "_meta": {
10003 "source": "test"
10004 }
10005 }))
10006 .unwrap();
10007
10008 assert_eq!(option.config_id.to_string(), "verbosity");
10009 assert_eq!(option.meta.as_ref().unwrap()["source"], "test");
10010 let SessionConfigKind::Other(unknown) = &option.kind else {
10011 panic!("expected unknown config kind");
10012 };
10013 assert_eq!(unknown.type_, "_slider");
10014 assert_eq!(unknown.fields.get("currentValue"), Some(&json!(3)));
10015 assert!(!unknown.fields.contains_key("_meta"));
10016 assert_eq!(serialized_meta_key_count(&option), 1);
10017
10018 let json = serde_json::to_value(&option).unwrap();
10019 assert_eq!(json["type"], "_slider");
10020 assert_eq!(json["currentValue"], 3);
10021 assert_eq!(json["min"], 0);
10022 assert_eq!(json["max"], 5);
10023 assert_eq!(json["_meta"]["source"], "test");
10024 }
10025
10026 #[test]
10027 fn test_session_config_option_unknown_kind_does_not_duplicate_flattened_meta() {
10028 let mut fields = std::collections::BTreeMap::new();
10029 fields.insert("currentValue".to_string(), json!(3));
10030 fields.insert("_meta".to_string(), json!({ "inner": "ignored" }));
10031
10032 let option = SessionConfigOption::new(
10033 "verbosity",
10034 "Verbosity",
10035 SessionConfigKind::Other(OtherSessionConfigKind::new("_slider", fields)),
10036 )
10037 .meta(test_meta());
10038
10039 let SessionConfigKind::Other(unknown) = &option.kind else {
10040 panic!("expected unknown config kind");
10041 };
10042 assert!(!unknown.fields.contains_key("_meta"));
10043 assert_eq!(serialized_meta_key_count(&option), 1);
10044
10045 let json = serde_json::to_value(&option).unwrap();
10046 assert_eq!(json["type"], "_slider");
10047 assert_eq!(json["currentValue"], 3);
10048 assert_eq!(json["_meta"]["source"], "test");
10049 }
10050
10051 #[test]
10052 fn test_session_config_option_unknown_does_not_hide_malformed_known_kind() {
10053 assert!(
10054 serde_json::from_value::<SessionConfigOption>(json!({
10055 "configId": "model",
10056 "name": "Model",
10057 "type": "select"
10058 }))
10059 .is_err()
10060 );
10061 }
10062
10063 #[cfg(feature = "unstable_llm_providers")]
10064 #[test]
10065 fn test_llm_protocol_known_variants() {
10066 assert_eq!(
10067 serde_json::to_value(&LlmProtocol::Anthropic).unwrap(),
10068 json!("anthropic")
10069 );
10070 assert_eq!(
10071 serde_json::to_value(&LlmProtocol::OpenAi).unwrap(),
10072 json!("openai")
10073 );
10074 assert_eq!(
10075 serde_json::to_value(&LlmProtocol::Azure).unwrap(),
10076 json!("azure")
10077 );
10078 assert_eq!(
10079 serde_json::to_value(&LlmProtocol::Vertex).unwrap(),
10080 json!("vertex")
10081 );
10082 assert_eq!(
10083 serde_json::to_value(&LlmProtocol::Bedrock).unwrap(),
10084 json!("bedrock")
10085 );
10086
10087 assert_eq!(
10088 serde_json::from_str::<LlmProtocol>("\"anthropic\"").unwrap(),
10089 LlmProtocol::Anthropic
10090 );
10091 assert_eq!(
10092 serde_json::from_str::<LlmProtocol>("\"openai\"").unwrap(),
10093 LlmProtocol::OpenAi
10094 );
10095 assert_eq!(
10096 serde_json::from_str::<LlmProtocol>("\"azure\"").unwrap(),
10097 LlmProtocol::Azure
10098 );
10099 assert_eq!(
10100 serde_json::from_str::<LlmProtocol>("\"vertex\"").unwrap(),
10101 LlmProtocol::Vertex
10102 );
10103 assert_eq!(
10104 serde_json::from_str::<LlmProtocol>("\"bedrock\"").unwrap(),
10105 LlmProtocol::Bedrock
10106 );
10107 }
10108
10109 #[cfg(feature = "unstable_llm_providers")]
10110 #[test]
10111 fn test_llm_protocol_unknown_variant() {
10112 let unknown: LlmProtocol = serde_json::from_str("\"cohere\"").unwrap();
10113 assert_eq!(unknown, LlmProtocol::Other("cohere".to_string()));
10114
10115 let json = serde_json::to_value(&unknown).unwrap();
10116 assert_eq!(json, json!("cohere"));
10117 }
10118
10119 #[cfg(feature = "unstable_llm_providers")]
10120 #[test]
10121 fn test_provider_current_config_serialization() {
10122 let config =
10123 ProviderCurrentConfig::new(LlmProtocol::Anthropic, "https://api.anthropic.com");
10124
10125 let json = serde_json::to_value(&config).unwrap();
10126 assert_eq!(
10127 json,
10128 json!({
10129 "apiType": "anthropic",
10130 "baseUrl": "https://api.anthropic.com"
10131 })
10132 );
10133
10134 let deserialized: ProviderCurrentConfig = serde_json::from_value(json).unwrap();
10135 assert_eq!(deserialized.api_type, LlmProtocol::Anthropic);
10136 assert_eq!(deserialized.base_url, "https://api.anthropic.com");
10137 }
10138
10139 #[cfg(feature = "unstable_llm_providers")]
10140 #[test]
10141 fn test_provider_info_with_current_config() {
10142 let info = ProviderInfo::new(
10143 "main",
10144 vec![LlmProtocol::Anthropic, LlmProtocol::OpenAi],
10145 true,
10146 Some(ProviderCurrentConfig::new(
10147 LlmProtocol::Anthropic,
10148 "https://api.anthropic.com",
10149 )),
10150 );
10151
10152 let json = serde_json::to_value(&info).unwrap();
10153 assert_eq!(
10154 json,
10155 json!({
10156 "providerId": "main",
10157 "supported": ["anthropic", "openai"],
10158 "required": true,
10159 "current": {
10160 "apiType": "anthropic",
10161 "baseUrl": "https://api.anthropic.com"
10162 }
10163 })
10164 );
10165
10166 let deserialized: ProviderInfo = serde_json::from_value(json).unwrap();
10167 assert_eq!(deserialized.provider_id.to_string(), "main");
10168 assert_eq!(deserialized.supported.len(), 2);
10169 assert!(deserialized.required);
10170 assert!(deserialized.current.is_some());
10171 assert_eq!(
10172 deserialized.current.as_ref().unwrap().api_type,
10173 LlmProtocol::Anthropic
10174 );
10175 }
10176
10177 #[cfg(feature = "unstable_llm_providers")]
10178 #[test]
10179 fn test_provider_info_disabled() {
10180 let info = ProviderInfo::new(
10181 "secondary",
10182 vec![LlmProtocol::OpenAi],
10183 false,
10184 None::<ProviderCurrentConfig>,
10185 );
10186
10187 let json = serde_json::to_value(&info).unwrap();
10188 assert_eq!(
10189 json,
10190 json!({
10191 "providerId": "secondary",
10192 "supported": ["openai"],
10193 "required": false
10194 })
10195 );
10196
10197 let deserialized: ProviderInfo = serde_json::from_value(json).unwrap();
10198 assert_eq!(deserialized.provider_id.to_string(), "secondary");
10199 assert!(!deserialized.required);
10200 assert!(deserialized.current.is_none());
10201 }
10202
10203 #[cfg(feature = "unstable_llm_providers")]
10204 #[test]
10205 fn test_provider_info_missing_current_defaults_to_none() {
10206 let json = json!({
10208 "providerId": "main",
10209 "supported": ["anthropic"],
10210 "required": true
10211 });
10212 let deserialized: ProviderInfo = serde_json::from_value(json).unwrap();
10213 assert!(deserialized.current.is_none());
10214 }
10215
10216 #[cfg(feature = "unstable_llm_providers")]
10217 #[test]
10218 fn test_provider_info_explicit_null_current_decodes_to_none() {
10219 let json = json!({
10223 "providerId": "main",
10224 "supported": ["anthropic"],
10225 "required": true,
10226 "current": null
10227 });
10228 let deserialized: ProviderInfo = serde_json::from_value(json).unwrap();
10229 assert!(deserialized.current.is_none());
10230 }
10231
10232 #[cfg(feature = "unstable_llm_providers")]
10233 #[test]
10234 fn test_list_providers_response_serialization() {
10235 let response = ListProvidersResponse::new(vec![ProviderInfo::new(
10236 "main",
10237 vec![LlmProtocol::Anthropic],
10238 true,
10239 Some(ProviderCurrentConfig::new(
10240 LlmProtocol::Anthropic,
10241 "https://api.anthropic.com",
10242 )),
10243 )]);
10244
10245 let json = serde_json::to_value(&response).unwrap();
10246 assert_eq!(json["providers"].as_array().unwrap().len(), 1);
10247 assert_eq!(json["providers"][0]["providerId"], "main");
10248
10249 let deserialized: ListProvidersResponse = serde_json::from_value(json).unwrap();
10250 assert_eq!(deserialized.providers.len(), 1);
10251 }
10252
10253 #[cfg(feature = "unstable_llm_providers")]
10254 #[test]
10255 fn test_set_provider_request_serialization() {
10256 use std::collections::HashMap;
10257
10258 let mut headers = HashMap::new();
10259 headers.insert("Authorization".to_string(), "Bearer sk-test".to_string());
10260
10261 let request =
10262 SetProviderRequest::new("main", LlmProtocol::OpenAi, "https://api.openai.com/v1")
10263 .headers(headers);
10264
10265 let json = serde_json::to_value(&request).unwrap();
10266 assert_eq!(
10267 json,
10268 json!({
10269 "providerId": "main",
10270 "apiType": "openai",
10271 "baseUrl": "https://api.openai.com/v1",
10272 "headers": {
10273 "Authorization": "Bearer sk-test"
10274 }
10275 })
10276 );
10277
10278 let deserialized: SetProviderRequest = serde_json::from_value(json).unwrap();
10279 assert_eq!(deserialized.provider_id.to_string(), "main");
10280 assert_eq!(deserialized.api_type, LlmProtocol::OpenAi);
10281 assert_eq!(deserialized.base_url, "https://api.openai.com/v1");
10282 assert_eq!(deserialized.headers.len(), 1);
10283 assert_eq!(
10284 deserialized.headers.get("Authorization").unwrap(),
10285 "Bearer sk-test"
10286 );
10287 }
10288
10289 #[cfg(feature = "unstable_llm_providers")]
10290 #[test]
10291 fn test_set_provider_request_omits_empty_headers() {
10292 let request =
10293 SetProviderRequest::new("main", LlmProtocol::Anthropic, "https://api.anthropic.com");
10294
10295 let json = serde_json::to_value(&request).unwrap();
10296 assert!(!json.as_object().unwrap().contains_key("headers"));
10298 }
10299
10300 #[cfg(feature = "unstable_llm_providers")]
10301 #[test]
10302 fn test_disable_provider_request_serialization() {
10303 let request = DisableProviderRequest::new("secondary");
10304
10305 let json = serde_json::to_value(&request).unwrap();
10306 assert_eq!(json, json!({ "providerId": "secondary" }));
10307
10308 let deserialized: DisableProviderRequest = serde_json::from_value(json).unwrap();
10309 assert_eq!(deserialized.provider_id.to_string(), "secondary");
10310 }
10311
10312 #[cfg(feature = "unstable_llm_providers")]
10313 #[test]
10314 fn test_providers_capabilities_serialization() {
10315 let caps = ProvidersCapabilities::new();
10316
10317 let json = serde_json::to_value(&caps).unwrap();
10318 assert_eq!(json, json!({}));
10319
10320 let deserialized: ProvidersCapabilities = serde_json::from_value(json).unwrap();
10321 assert!(deserialized.meta.is_none());
10322 }
10323
10324 #[cfg(feature = "unstable_llm_providers")]
10325 #[test]
10326 fn test_agent_capabilities_with_providers() {
10327 let caps = AgentCapabilities::new().providers(ProvidersCapabilities::new());
10328
10329 let json = serde_json::to_value(&caps).unwrap();
10330 assert_eq!(json["providers"], json!({}));
10331
10332 let deserialized: AgentCapabilities = serde_json::from_value(json).unwrap();
10333 assert!(deserialized.providers.is_some());
10334 }
10335
10336 #[test]
10337 fn test_agent_capabilities_session_is_explicit() {
10338 let json = serde_json::to_value(AgentCapabilities::new()).unwrap();
10339 assert!(json.get("session").is_none());
10340
10341 let caps = AgentCapabilities::new().session(
10342 SessionCapabilities::new()
10343 .prompt(PromptCapabilities::new().image(PromptImageCapabilities::new()))
10344 .mcp(McpCapabilities::new().stdio(McpStdioCapabilities::new())),
10345 );
10346
10347 assert_eq!(
10348 serde_json::to_value(&caps).unwrap(),
10349 json!({
10350 "session": {
10351 "prompt": {
10352 "image": {}
10353 },
10354 "mcp": {
10355 "stdio": {}
10356 }
10357 }
10358 })
10359 );
10360
10361 let deserialized: AgentCapabilities = serde_json::from_value(json!({
10362 "session": false
10363 }))
10364 .unwrap();
10365 assert!(deserialized.session.is_none());
10366 }
10367
10368 #[test]
10369 fn test_prompt_capabilities_serialize_supported_content_as_objects() {
10370 let caps = PromptCapabilities::new()
10371 .image(PromptImageCapabilities::new())
10372 .audio(PromptAudioCapabilities::new())
10373 .embedded_context(PromptEmbeddedContextCapabilities::new());
10374
10375 assert_eq!(
10376 serde_json::to_value(&caps).unwrap(),
10377 json!({
10378 "image": {},
10379 "audio": {},
10380 "embeddedContext": {}
10381 })
10382 );
10383
10384 let deserialized: PromptCapabilities = serde_json::from_value(json!({
10385 "image": null,
10386 "audio": false,
10387 "embeddedContext": {}
10388 }))
10389 .unwrap();
10390 assert!(deserialized.image.is_none());
10391 assert!(deserialized.audio.is_none());
10392 assert!(deserialized.embedded_context.is_some());
10393 }
10394
10395 #[cfg(feature = "unstable_agent_skills")]
10396 #[test]
10397 fn prompt_skill_capability_has_two_levels() {
10398 let leading = PromptCapabilities::new().skill(PromptSkillCapabilities::new());
10400 assert_eq!(
10401 serde_json::to_value(&leading).unwrap(),
10402 json!({ "skill": {} })
10403 );
10404
10405 let inline = PromptCapabilities::new()
10406 .skill(PromptSkillCapabilities::new().inline(PromptSkillInlineCapabilities::new()));
10407 let wire = json!({ "skill": { "inline": {} } });
10408 assert_eq!(serde_json::to_value(&inline).unwrap(), wire);
10409 assert_eq!(
10410 serde_json::from_value::<PromptCapabilities>(wire).unwrap(),
10411 inline
10412 );
10413
10414 for unsupported in [
10415 json!({}),
10416 json!({ "skill": null }),
10417 json!({ "skill": false }),
10418 json!({ "skill": true }),
10419 ] {
10420 let caps: PromptCapabilities = serde_json::from_value(unsupported).unwrap();
10421 assert!(caps.skill.is_none());
10422 }
10423
10424 for leading_only in [
10426 json!({ "skill": { "inline": null } }),
10427 json!({ "skill": { "inline": true } }),
10428 ] {
10429 assert_eq!(
10430 serde_json::from_value::<PromptCapabilities>(leading_only).unwrap(),
10431 leading
10432 );
10433 }
10434 }
10435
10436 #[test]
10437 fn test_mcp_capabilities_serialize_supported_transports_as_objects() {
10438 let caps = McpCapabilities::new()
10439 .stdio(McpStdioCapabilities::new())
10440 .http(McpHttpCapabilities::new());
10441
10442 assert_eq!(
10443 serde_json::to_value(&caps).unwrap(),
10444 json!({
10445 "stdio": {},
10446 "http": {}
10447 })
10448 );
10449
10450 let deserialized: McpCapabilities = serde_json::from_value(json!({
10451 "stdio": null,
10452 "http": false
10453 }))
10454 .unwrap();
10455 assert!(deserialized.stdio.is_none());
10456 assert!(deserialized.http.is_none());
10457 }
10458
10459 #[cfg(feature = "unstable_mcp_over_acp")]
10460 #[test]
10461 fn test_mcp_capabilities_serialize_acp_support_as_object() {
10462 let caps = McpCapabilities::new().acp(McpAcpCapabilities::new());
10463
10464 assert_eq!(
10465 serde_json::to_value(&caps).unwrap(),
10466 json!({
10467 "acp": {}
10468 })
10469 );
10470 }
10471
10472 #[test]
10473 fn prompt_request_rejects_malformed_content_block() {
10474 use serde_json::json;
10475
10476 assert!(
10477 serde_json::from_value::<PromptRequest>(json!({
10478 "sessionId": "sess-1",
10479 "prompt": [{"type": "text"}]
10480 }))
10481 .is_err()
10482 );
10483 }
10484
10485 #[test]
10486 fn prompt_request_rejects_non_array_prompt() {
10487 use serde_json::json;
10488
10489 assert!(
10490 serde_json::from_value::<PromptRequest>(json!({
10491 "sessionId": "sess-1",
10492 "prompt": "hello"
10493 }))
10494 .is_err()
10495 );
10496 }
10497
10498 fn assert_session_setup_lists_are_strict<T>(base: &serde_json::Value)
10499 where
10500 T: serde::de::DeserializeOwned + PartialEq + std::fmt::Debug,
10501 {
10502 let name = std::any::type_name::<T>();
10503 let with = |field: &str, value: serde_json::Value| {
10504 let mut request = base.clone();
10505 request[field] = value;
10506 serde_json::from_value::<T>(request)
10507 };
10508
10509 for (field, value) in [
10510 (
10512 "mcpServers",
10513 json!([
10514 {"type": "stdio", "name": "github", "command": "/usr/bin/gh-mcp", "env": [{"name": "GITHUB_TOKEN", "value": null}]},
10515 {"type": "stdio", "name": "fs", "command": "/usr/bin/fs-mcp"}
10516 ]),
10517 ),
10518 ("mcpServers", json!({"type": "stdio", "name": "fs"})),
10519 ("additionalDirectories", json!(["/repo/lib", 42])),
10520 ("additionalDirectories", json!("/repo/lib")),
10521 ] {
10522 assert!(
10523 with(field, value.clone()).is_err(),
10524 "{name}.{field}: {value}"
10525 );
10526 }
10527
10528 let empty = serde_json::from_value::<T>(base.clone()).unwrap();
10529 for field in ["mcpServers", "additionalDirectories"] {
10530 assert_eq!(
10531 with(field, serde_json::Value::Null).unwrap(),
10532 empty,
10533 "{name}.{field}"
10534 );
10535 }
10536 }
10537
10538 #[test]
10539 fn session_setup_requests_reject_malformed_mcp_servers_and_directories() {
10540 assert_session_setup_lists_are_strict::<NewSessionRequest>(&json!({"cwd": "/repo"}));
10541 assert_session_setup_lists_are_strict::<ResumeSessionRequest>(&json!({
10542 "sessionId": "sess-1",
10543 "cwd": "/repo"
10544 }));
10545 #[cfg(feature = "unstable_session_fork")]
10546 assert_session_setup_lists_are_strict::<ForkSessionRequest>(&json!({
10547 "sessionId": "sess-1",
10548 "cwd": "/repo"
10549 }));
10550 }
10551
10552 #[test]
10553 fn resume_session_request_rejects_malformed_replay_from() {
10554 let request = |replay_from: serde_json::Value| {
10555 serde_json::from_value::<ResumeSessionRequest>(json!({
10556 "sessionId": "sess-1",
10557 "cwd": "/repo",
10558 "replayFrom": replay_from
10559 }))
10560 };
10561
10562 assert!(request(json!("start")).is_err());
10564 assert_eq!(request(serde_json::Value::Null).unwrap().replay_from, None);
10565 assert!(matches!(
10566 request(json!({"type": "start"})).unwrap().replay_from,
10567 Some(ReplayFrom::Start(_))
10568 ));
10569 }
10570
10571 #[test]
10572 fn mcp_server_lists_treat_null_as_empty() {
10573 let servers: Vec<McpServer> = serde_json::from_value(json!([
10574 {"type": "stdio", "name": "fs", "command": "/usr/bin/fs-mcp", "args": null, "env": null},
10575 {"type": "http", "name": "api", "url": "https://example.com/mcp", "headers": null}
10576 ]))
10577 .unwrap();
10578
10579 assert_eq!(
10580 servers,
10581 vec![
10582 McpServer::Stdio(McpServerStdio::new("fs", "/usr/bin/fs-mcp")),
10583 McpServer::Http(McpServerHttp::new("api", "https://example.com/mcp")),
10584 ]
10585 );
10586 }
10587
10588 #[test]
10589 fn terminal_auth_methods_reject_malformed_launch_config() {
10590 let response: InitializeResponse = serde_json::from_value(json!({
10594 "protocolVersion": 2,
10595 "info": {"name": "agent", "version": "1.0.0"},
10596 "authMethods": [
10597 {"type": "terminal", "methodId": "bad-args", "name": "Log in", "args": ["auth", "--port", 8123]},
10598 {"type": "terminal", "methodId": "bad-env", "name": "Log in", "env": [{"name": "DEBUG", "value": 1}]},
10599 {"type": "terminal", "methodId": "null-config", "name": "Log in", "args": null, "env": null},
10600 {"type": "agent", "methodId": "agent", "name": "Agent login"}
10601 ]
10602 }))
10603 .unwrap();
10604
10605 assert_eq!(
10606 response.auth_methods,
10607 vec![
10608 AuthMethod::Terminal(AuthMethodTerminal::new("null-config", "Log in")),
10609 AuthMethod::Agent(AuthMethodAgent::new("agent", "Agent login")),
10610 ]
10611 );
10612 }
10613
10614 #[cfg(feature = "unstable_auth_status")]
10615 #[test]
10616 fn auth_status_response_round_trips() {
10617 let response = AuthStatusResponse::new(AuthState::Authenticated).accounts(vec![
10618 AuthAccount::new("Anthropic API key")
10619 .description("API key helper".to_string())
10620 .active(true),
10621 AuthAccount::new("Claude Max").email("user@example.com".to_string()),
10622 ]);
10623 let json = serde_json::to_value(&response).unwrap();
10624 assert_eq!(
10625 json,
10626 json!({
10627 "state": "authenticated",
10628 "accounts": [
10629 {
10630 "label": "Anthropic API key",
10631 "description": "API key helper",
10632 "active": true
10633 },
10634 {
10635 "label": "Claude Max",
10636 "email": "user@example.com"
10637 }
10638 ]
10639 })
10640 );
10641 assert_eq!(
10642 serde_json::from_value::<AuthStatusResponse>(json).unwrap(),
10643 response
10644 );
10645 assert_eq!(
10646 serde_json::to_value(AuthStatusResponse::new(AuthState::NotRequired)).unwrap(),
10647 json!({"state": "not_required"})
10648 );
10649 }
10650
10651 #[cfg(feature = "unstable_auth_status")]
10652 #[test]
10653 fn auth_status_state_is_strict_and_accounts_are_lenient() {
10654 assert!(serde_json::from_value::<AuthStatusResponse>(json!({})).is_err());
10655 assert!(serde_json::from_value::<AuthStatusResponse>(json!({"state": null})).is_err());
10656 assert!(serde_json::from_value::<AuthStatusResponse>(json!({"state": 1})).is_err());
10657
10658 let response: AuthStatusResponse = serde_json::from_value(json!({
10659 "state": "_vendor_state",
10660 "accounts": [
10661 {"active": true},
10662 {
10663 "label": "Vertex AI",
10664 "description": 42,
10665 "active": "yes",
10666 "email": ["not", "a", "string"]
10667 }
10668 ]
10669 }))
10670 .unwrap();
10671 assert_eq!(
10672 response,
10673 AuthStatusResponse::new(AuthState::Other("_vendor_state".to_string()))
10674 .accounts(vec![AuthAccount::new("Vertex AI")])
10675 );
10676 assert_eq!(
10677 serde_json::from_value::<AuthStatusResponse>(
10678 json!({"state": "unknown", "accounts": null})
10679 )
10680 .unwrap(),
10681 AuthStatusResponse::new(AuthState::Unknown)
10682 );
10683 }
10684
10685 #[cfg(feature = "unstable_auth_status")]
10686 #[test]
10687 fn auth_status_update_notification_routes() {
10688 use crate::v2::{AgentNotification, CLIENT_METHOD_NAMES};
10689
10690 assert_eq!(AGENT_METHOD_NAMES.auth_status, "auth/status");
10691 assert_eq!(CLIENT_METHOD_NAMES.auth_status_update, "auth/status_update");
10692 let notification = AgentNotification::AuthStatusUpdateNotification(Box::new(
10693 AuthStatusUpdateNotification::new(AuthState::Unauthenticated),
10694 ));
10695 assert_eq!(notification.method(), "auth/status_update");
10696 assert_eq!(
10697 serde_json::to_value(¬ification).unwrap(),
10698 json!({"state": "unauthenticated"})
10699 );
10700 }
10701}