Skip to main content

agent_client_protocol_schema/v2/
conversion.rs

1//! Explicit conversion helpers for experimenting with ACP v2 while SDKs still speak v1.
2//!
3//! The conversions below intentionally move values field-by-field and
4//! variant-by-variant instead of serializing through JSON so v2 shape changes
5//! have obvious edit points.
6
7use std::{
8    collections::{BTreeMap, HashMap},
9    fmt,
10    hash::{BuildHasher, Hash},
11    path::PathBuf,
12    sync::Arc,
13};
14
15use serde_json::value::RawValue;
16
17use crate::version::ProtocolVersion;
18
19/// Result type returned by protocol conversion helpers.
20pub type Result<T> = std::result::Result<T, ProtocolConversionError>;
21
22/// Error returned when converting between v1 and v2 protocol type namespaces fails.
23#[derive(Debug, Clone, PartialEq, Eq)]
24#[non_exhaustive]
25pub struct ProtocolConversionError {
26    message: String,
27}
28
29impl ProtocolConversionError {
30    /// Creates a conversion error with a human-readable message.
31    #[must_use]
32    pub fn new(message: impl Into<String>) -> Self {
33        Self {
34            message: message.into(),
35        }
36    }
37
38    /// Returns the human-readable conversion error message.
39    #[must_use]
40    pub fn message(&self) -> &str {
41        &self.message
42    }
43}
44
45impl fmt::Display for ProtocolConversionError {
46    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
47        formatter.write_str(&self.message)
48    }
49}
50
51impl std::error::Error for ProtocolConversionError {}
52
53fn unknown_v2_enum_variant(type_name: &str, value: &str) -> ProtocolConversionError {
54    ProtocolConversionError::new(format!(
55        "v2 {type_name} variant `{value}` cannot be represented in v1"
56    ))
57}
58
59fn removed_v1_enum_variant(type_name: &str, value: &str) -> ProtocolConversionError {
60    ProtocolConversionError::new(format!(
61        "v1 {type_name} variant `{value}` cannot be represented in v2"
62    ))
63}
64
65const LEGACY_V1_PLAN_ID: &str = "main";
66
67/// Converts a [`ProtocolConversionError`] into a v1 [`Error`](crate::v1::Error)
68/// so callers can use `?` to bubble conversion failures through APIs that
69/// already speak the v1 error type.
70///
71/// The conversion is mapped onto [`Error::internal_error`](crate::v1::Error::internal_error)
72/// because a failed cross-version conversion always indicates a protocol
73/// mismatch on this side of the wire rather than a client mistake.
74impl From<ProtocolConversionError> for crate::v1::Error {
75    fn from(error: ProtocolConversionError) -> Self {
76        crate::v1::Error::internal_error().data(error.message)
77    }
78}
79
80/// Mirror of the [v1 `From`](#impl-From%3CProtocolConversionError%3E-for-Error)
81/// impl for the v2 [`Error`](crate::v2::Error) type.
82impl From<ProtocolConversionError> for crate::v2::Error {
83    fn from(error: ProtocolConversionError) -> Self {
84        crate::v2::Error::internal_error().data(error.message)
85    }
86}
87
88/// Converts a value from the v2 draft type namespace into the matching v1 type.
89pub trait IntoV1 {
90    /// The corresponding v1 type.
91    type Output;
92
93    /// Converts this value into the corresponding v1 type.
94    ///
95    /// # Errors
96    ///
97    /// Returns [`ProtocolConversionError`] when a value cannot be represented in v1.
98    fn into_v1(self) -> Result<Self::Output>;
99}
100
101/// Converts a value from the v2 draft type namespace into one or more v1 values.
102///
103/// Use this trait for protocol values where a single v2 value may need to fan
104/// out into multiple v1 values. For example, a whole v2 message update contains
105/// an array of content blocks, while v1 represents those blocks as separate
106/// chunk updates.
107///
108/// This is intentionally not blanket-implemented for every [`IntoV1`] type.
109/// Keeping one-to-one and one-to-many conversions separate makes future v2
110/// fan-out cases explicit and avoids trait coherence conflicts when an
111/// existing one-to-one shape grows a v2-only variant that needs fan-out.
112pub trait IntoV1Many {
113    /// The corresponding v1 item type.
114    type Output;
115
116    /// Converts this value into one or more corresponding v1 items.
117    ///
118    /// # Errors
119    ///
120    /// Returns [`ProtocolConversionError`] when a value cannot be represented in v1.
121    fn into_v1_many(self) -> Result<Vec<Self::Output>>;
122}
123
124/// Converts a value from the v1 type namespace into the matching v2 draft type.
125pub trait IntoV2 {
126    /// The corresponding v2 draft type.
127    type Output;
128
129    /// Converts this value into the corresponding v2 draft type.
130    ///
131    /// # Errors
132    ///
133    /// Returns [`ProtocolConversionError`] when a value cannot be represented in v2.
134    fn into_v2(self) -> Result<Self::Output>;
135}
136
137/// Converts a v2 draft value into the corresponding v1 value type.
138///
139/// # Errors
140///
141/// Returns [`ProtocolConversionError`] when a value cannot be represented in v1.
142pub fn v2_to_v1<T>(value: T) -> Result<T::Output>
143where
144    T: IntoV1,
145{
146    value.into_v1()
147}
148
149/// Converts a v2 draft value into one or more corresponding v1 values.
150///
151/// One-to-many conversions are stateless. When a v2 update's semantics depend
152/// on previously delivered updates, this helper can only reject cases that are
153/// visible in the value being converted. For example, a content-bearing whole
154/// message update can be emitted as v1 chunks, but v1 cannot represent the
155/// replacement semantics if the v1 side has already received content for that
156/// `messageId`.
157///
158/// # Errors
159///
160/// Returns [`ProtocolConversionError`] when a value cannot be represented in v1.
161pub fn v2_to_v1_many<T>(value: T) -> Result<Vec<T::Output>>
162where
163    T: IntoV1Many,
164{
165    value.into_v1_many()
166}
167
168/// Converts a v1 value into the corresponding v2 draft value type.
169///
170/// # Errors
171///
172/// Returns [`ProtocolConversionError`] when a value cannot be represented in v2.
173pub fn v1_to_v2<T>(value: T) -> Result<T::Output>
174where
175    T: IntoV2,
176{
177    value.into_v2()
178}
179
180macro_rules! identity_conversion {
181    ($($ty:ty),* $(,)?) => {
182        $(
183            impl IntoV1 for $ty {
184                type Output = Self;
185
186                fn into_v1(self) -> Result<Self::Output> {
187                    Ok(self)
188                }
189            }
190
191            impl IntoV2 for $ty {
192                type Output = Self;
193
194                fn into_v2(self) -> Result<Self::Output> {
195                    Ok(self)
196                }
197            }
198        )*
199    };
200}
201
202identity_conversion!(
203    bool,
204    f32,
205    f64,
206    i16,
207    i32,
208    i64,
209    i8,
210    isize,
211    String,
212    u16,
213    u32,
214    u64,
215    u8,
216    usize,
217    &'static str,
218    Arc<RawValue>,
219    Arc<str>,
220    PathBuf,
221    ProtocolVersion,
222    super::RequestId,
223    serde_json::Map<String, serde_json::Value>,
224    serde_json::Value,
225);
226
227impl<T> IntoV1 for Option<T>
228where
229    T: IntoV1,
230{
231    type Output = Option<T::Output>;
232    fn into_v1(self) -> Result<Self::Output> {
233        self.map(IntoV1::into_v1).transpose()
234    }
235}
236
237impl<T> IntoV2 for Option<T>
238where
239    T: IntoV2,
240{
241    type Output = Option<T::Output>;
242    fn into_v2(self) -> Result<Self::Output> {
243        self.map(IntoV2::into_v2).transpose()
244    }
245}
246
247impl<T> IntoV1 for Vec<T>
248where
249    T: IntoV1,
250{
251    type Output = Vec<T::Output>;
252    fn into_v1(self) -> Result<Self::Output> {
253        self.into_iter().map(IntoV1::into_v1).collect()
254    }
255}
256
257fn into_v1_default_on_error<T>(value: T) -> T::Output
258where
259    T: IntoV1,
260    T::Output: Default,
261{
262    value.into_v1().unwrap_or_default()
263}
264
265fn into_v2_default_on_error<T>(value: T) -> T::Output
266where
267    T: IntoV2,
268    T::Output: Default,
269{
270    value.into_v2().unwrap_or_default()
271}
272
273fn into_v1_vec_skip_errors<T>(values: Vec<T>) -> Vec<T::Output>
274where
275    T: IntoV1,
276{
277    values
278        .into_iter()
279        .filter_map(|value| value.into_v1().ok())
280        .collect()
281}
282
283fn into_v2_vec_skip_errors<T>(values: Vec<T>) -> Vec<T::Output>
284where
285    T: IntoV2,
286{
287    values
288        .into_iter()
289        .filter_map(|value| value.into_v2().ok())
290        .collect()
291}
292
293fn option_vec_into_v1_skip_errors<T>(value: Option<Vec<T>>) -> Option<Vec<T::Output>>
294where
295    T: IntoV1,
296{
297    value.map(into_v1_vec_skip_errors)
298}
299
300fn option_vec_into_v2_skip_errors<T>(value: Option<Vec<T>>) -> Option<Vec<T::Output>>
301where
302    T: IntoV2,
303{
304    value.map(into_v2_vec_skip_errors)
305}
306
307impl<T> IntoV2 for Vec<T>
308where
309    T: IntoV2,
310{
311    type Output = Vec<T::Output>;
312    fn into_v2(self) -> Result<Self::Output> {
313        self.into_iter().map(IntoV2::into_v2).collect()
314    }
315}
316
317impl<K, V> IntoV1 for BTreeMap<K, V>
318where
319    K: IntoV1,
320    K::Output: Ord,
321    V: IntoV1,
322{
323    type Output = BTreeMap<K::Output, V::Output>;
324    fn into_v1(self) -> Result<Self::Output> {
325        self.into_iter()
326            .map(|(key, value)| Ok((key.into_v1()?, value.into_v1()?)))
327            .collect()
328    }
329}
330
331impl<K, V> IntoV2 for BTreeMap<K, V>
332where
333    K: IntoV2,
334    K::Output: Ord,
335    V: IntoV2,
336{
337    type Output = BTreeMap<K::Output, V::Output>;
338    fn into_v2(self) -> Result<Self::Output> {
339        self.into_iter()
340            .map(|(key, value)| Ok((key.into_v2()?, value.into_v2()?)))
341            .collect()
342    }
343}
344
345impl<K, V, S> IntoV1 for HashMap<K, V, S>
346where
347    K: IntoV1,
348    K::Output: Eq + Hash,
349    V: IntoV1,
350    S: BuildHasher,
351{
352    type Output = HashMap<K::Output, V::Output>;
353    fn into_v1(self) -> Result<Self::Output> {
354        self.into_iter()
355            .map(|(key, value)| Ok((key.into_v1()?, value.into_v1()?)))
356            .collect()
357    }
358}
359
360impl<K, V, S> IntoV2 for HashMap<K, V, S>
361where
362    K: IntoV2,
363    K::Output: Eq + Hash,
364    V: IntoV2,
365    S: BuildHasher,
366{
367    type Output = HashMap<K::Output, V::Output>;
368    fn into_v2(self) -> Result<Self::Output> {
369        self.into_iter()
370            .map(|(key, value)| Ok((key.into_v2()?, value.into_v2()?)))
371            .collect()
372    }
373}
374
375impl<T> IntoV1 for crate::MaybeUndefined<T>
376where
377    T: IntoV1,
378{
379    type Output = crate::MaybeUndefined<T::Output>;
380    fn into_v1(self) -> Result<Self::Output> {
381        Ok(match self {
382            Self::Undefined => crate::MaybeUndefined::Undefined,
383            Self::Null => crate::MaybeUndefined::Null,
384            Self::Value(value) => crate::MaybeUndefined::Value(value.into_v1()?),
385        })
386    }
387}
388
389impl<T> IntoV2 for crate::MaybeUndefined<T>
390where
391    T: IntoV2,
392{
393    type Output = crate::MaybeUndefined<T::Output>;
394    fn into_v2(self) -> Result<Self::Output> {
395        Ok(match self {
396            Self::Undefined => crate::MaybeUndefined::Undefined,
397            Self::Null => crate::MaybeUndefined::Null,
398            Self::Value(value) => crate::MaybeUndefined::Value(value.into_v2()?),
399        })
400    }
401}
402
403impl<Params> IntoV1 for super::Request<Params>
404where
405    Params: IntoV1,
406{
407    type Output = crate::v1::Request<Params::Output>;
408    fn into_v1(self) -> Result<Self::Output> {
409        Ok(crate::v1::Request {
410            id: self.id.into_v1()?,
411            method: self.method,
412            params: self.params.into_v1()?,
413        })
414    }
415}
416
417impl<Params> IntoV2 for crate::v1::Request<Params>
418where
419    Params: IntoV2,
420{
421    type Output = super::Request<Params::Output>;
422    fn into_v2(self) -> Result<Self::Output> {
423        Ok(super::Request {
424            id: self.id.into_v2()?,
425            method: self.method,
426            params: self.params.into_v2()?,
427        })
428    }
429}
430
431impl<Params> IntoV1 for super::Notification<Params>
432where
433    Params: IntoV1,
434{
435    type Output = crate::v1::Notification<Params::Output>;
436    fn into_v1(self) -> Result<Self::Output> {
437        Ok(crate::v1::Notification {
438            method: self.method,
439            params: self.params.into_v1()?,
440        })
441    }
442}
443
444impl<Params> IntoV2 for crate::v1::Notification<Params>
445where
446    Params: IntoV2,
447{
448    type Output = super::Notification<Params::Output>;
449    fn into_v2(self) -> Result<Self::Output> {
450        Ok(super::Notification {
451            method: self.method,
452            params: self.params.into_v2()?,
453        })
454    }
455}
456
457impl<Response> IntoV1 for super::Response<Response>
458where
459    Response: IntoV1,
460{
461    type Output = crate::v1::Response<Response::Output>;
462    fn into_v1(self) -> Result<Self::Output> {
463        Ok(match self {
464            Self::Result { id, result } => crate::v1::Response::Result {
465                id: id.into_v1()?,
466                result: result.into_v1()?,
467            },
468            Self::Error { id, error } => crate::v1::Response::Error {
469                id: id.into_v1()?,
470                error: error.into_v1()?,
471            },
472        })
473    }
474}
475
476impl<Response> IntoV2 for crate::v1::Response<Response>
477where
478    Response: IntoV2,
479{
480    type Output = super::Response<Response::Output>;
481    fn into_v2(self) -> Result<Self::Output> {
482        Ok(match self {
483            Self::Result { id, result } => super::Response::Result {
484                id: id.into_v2()?,
485                result: result.into_v2()?,
486            },
487            Self::Error { id, error } => super::Response::Error {
488                id: id.into_v2()?,
489                error: error.into_v2()?,
490            },
491        })
492    }
493}
494
495impl<Message> IntoV1 for super::JsonRpcMessage<Message>
496where
497    Message: IntoV1,
498{
499    type Output = crate::v1::JsonRpcMessage<Message::Output>;
500    fn into_v1(self) -> Result<Self::Output> {
501        Ok(crate::v1::JsonRpcMessage::wrap(
502            self.into_inner().into_v1()?,
503        ))
504    }
505}
506
507impl<Message> IntoV2 for crate::v1::JsonRpcMessage<Message>
508where
509    Message: IntoV2,
510{
511    type Output = super::JsonRpcMessage<Message::Output>;
512    fn into_v2(self) -> Result<Self::Output> {
513        Ok(super::JsonRpcMessage::wrap(self.into_inner().into_v2()?))
514    }
515}
516
517impl IntoV1Many for super::Notification<super::AgentNotification> {
518    type Output = crate::v1::Notification<crate::v1::AgentNotification>;
519
520    fn into_v1_many(self) -> Result<Vec<Self::Output>> {
521        let Self { method, params } = self;
522        let Some(params) = params else {
523            return Ok(vec![crate::v1::Notification {
524                method,
525                params: None,
526            }]);
527        };
528
529        params
530            .into_v1_many()?
531            .into_iter()
532            .map(|params| {
533                Ok(crate::v1::Notification {
534                    method: method.clone(),
535                    params: Some(params),
536                })
537            })
538            .collect()
539    }
540}
541
542impl IntoV1Many for super::JsonRpcMessage<super::Notification<super::AgentNotification>> {
543    type Output = crate::v1::JsonRpcMessage<crate::v1::Notification<crate::v1::AgentNotification>>;
544
545    fn into_v1_many(self) -> Result<Vec<Self::Output>> {
546        self.into_inner()
547            .into_v1_many()?
548            .into_iter()
549            .map(|message| Ok(crate::v1::JsonRpcMessage::wrap(message)))
550            .collect()
551    }
552}
553
554impl IntoV1Many for super::JsonRpcBatch<super::Notification<super::AgentNotification>> {
555    type Output = crate::v1::JsonRpcMessage<crate::v1::Notification<crate::v1::AgentNotification>>;
556
557    fn into_v1_many(self) -> Result<Vec<Self::Output>> {
558        let messages = self
559            .into_vec()
560            .into_iter()
561            .map(IntoV1Many::into_v1_many)
562            .collect::<Result<Vec<_>>>()?
563            .into_iter()
564            .flatten()
565            .collect();
566        Ok(messages)
567    }
568}
569
570impl IntoV1 for super::SessionId {
571    type Output = crate::v1::SessionId;
572
573    fn into_v1(self) -> Result<Self::Output> {
574        Ok(crate::v1::SessionId(self.0.into_v1()?))
575    }
576}
577
578impl IntoV2 for crate::v1::SessionId {
579    type Output = super::SessionId;
580
581    fn into_v2(self) -> Result<Self::Output> {
582        Ok(super::SessionId(self.0.into_v2()?))
583    }
584}
585
586impl IntoV1 for super::MessageId {
587    type Output = crate::v1::MessageId;
588
589    fn into_v1(self) -> Result<Self::Output> {
590        Ok(crate::v1::MessageId(self.0.into_v1()?))
591    }
592}
593
594impl IntoV2 for crate::v1::MessageId {
595    type Output = super::MessageId;
596
597    fn into_v2(self) -> Result<Self::Output> {
598        Ok(super::MessageId(self.0.into_v2()?))
599    }
600}
601
602#[cfg(not(feature = "unstable_plan_operations"))]
603impl IntoV1 for super::PlanUpdate {
604    type Output = crate::v1::Plan;
605
606    fn into_v1(self) -> Result<Self::Output> {
607        let Self { plan, meta } = self;
608        Ok(match plan {
609            super::PlanUpdateContent::Items(items) => {
610                let super::PlanItems {
611                    id: _,
612                    entries,
613                    meta: items_meta,
614                } = items;
615                crate::v1::Plan {
616                    entries: into_v1_vec_skip_errors(entries),
617                    meta: meta.or(items_meta).into_v1()?,
618                }
619            }
620            super::PlanUpdateContent::Other(value) => {
621                return Err(unknown_v2_enum_variant("PlanUpdateContent", &value.type_));
622            }
623        })
624    }
625}
626
627#[cfg(feature = "unstable_plan_operations")]
628impl IntoV1 for super::PlanId {
629    type Output = crate::v1::PlanId;
630
631    fn into_v1(self) -> Result<Self::Output> {
632        Ok(crate::v1::PlanId(self.0.into_v1()?))
633    }
634}
635
636#[cfg(feature = "unstable_plan_operations")]
637impl IntoV2 for crate::v1::PlanId {
638    type Output = super::PlanId;
639
640    fn into_v2(self) -> Result<Self::Output> {
641        Ok(super::PlanId(self.0.into_v2()?))
642    }
643}
644
645#[cfg(feature = "unstable_plan_operations")]
646impl IntoV1 for super::PlanUpdate {
647    type Output = crate::v1::PlanUpdate;
648
649    fn into_v1(self) -> Result<Self::Output> {
650        let Self { plan, meta } = self;
651        Ok(crate::v1::PlanUpdate {
652            plan: plan.into_v1()?,
653            meta: meta.into_v1()?,
654        })
655    }
656}
657
658#[cfg(feature = "unstable_plan_operations")]
659impl IntoV2 for crate::v1::PlanUpdate {
660    type Output = super::PlanUpdate;
661
662    fn into_v2(self) -> Result<Self::Output> {
663        let Self { plan, meta } = self;
664        Ok(super::PlanUpdate {
665            plan: plan.into_v2()?,
666            meta: meta.into_v2()?,
667        })
668    }
669}
670
671#[cfg(feature = "unstable_plan_operations")]
672impl IntoV1 for super::PlanUpdateContent {
673    type Output = crate::v1::PlanUpdateContent;
674
675    fn into_v1(self) -> Result<Self::Output> {
676        Ok(match self {
677            Self::Items(value) => crate::v1::PlanUpdateContent::Items(value.into_v1()?),
678            Self::File(value) => crate::v1::PlanUpdateContent::File(value.into_v1()?),
679            Self::Markdown(value) => crate::v1::PlanUpdateContent::Markdown(value.into_v1()?),
680            Self::Other(value) => {
681                return Err(unknown_v2_enum_variant("PlanUpdateContent", &value.type_));
682            }
683        })
684    }
685}
686
687#[cfg(feature = "unstable_plan_operations")]
688impl IntoV2 for crate::v1::PlanUpdateContent {
689    type Output = super::PlanUpdateContent;
690
691    fn into_v2(self) -> Result<Self::Output> {
692        Ok(match self {
693            Self::Items(value) => super::PlanUpdateContent::Items(value.into_v2()?),
694            Self::File(value) => super::PlanUpdateContent::File(value.into_v2()?),
695            Self::Markdown(value) => super::PlanUpdateContent::Markdown(value.into_v2()?),
696        })
697    }
698}
699
700#[cfg(feature = "unstable_plan_operations")]
701impl IntoV1 for super::PlanItems {
702    type Output = crate::v1::PlanItems;
703
704    fn into_v1(self) -> Result<Self::Output> {
705        let Self { id, entries, meta } = self;
706        Ok(crate::v1::PlanItems {
707            id: id.into_v1()?,
708            entries: into_v1_vec_skip_errors(entries),
709            meta: meta.into_v1()?,
710        })
711    }
712}
713
714#[cfg(feature = "unstable_plan_operations")]
715impl IntoV2 for crate::v1::PlanItems {
716    type Output = super::PlanItems;
717
718    fn into_v2(self) -> Result<Self::Output> {
719        let Self { id, entries, meta } = self;
720        Ok(super::PlanItems {
721            id: id.into_v2()?,
722            entries: into_v2_vec_skip_errors(entries),
723            meta: meta.into_v2()?,
724        })
725    }
726}
727
728#[cfg(feature = "unstable_plan_operations")]
729impl IntoV1 for super::PlanFile {
730    type Output = crate::v1::PlanFile;
731
732    fn into_v1(self) -> Result<Self::Output> {
733        let Self { id, uri, meta } = self;
734        Ok(crate::v1::PlanFile {
735            id: id.into_v1()?,
736            uri: uri.into_v1()?,
737            meta: meta.into_v1()?,
738        })
739    }
740}
741
742#[cfg(feature = "unstable_plan_operations")]
743impl IntoV2 for crate::v1::PlanFile {
744    type Output = super::PlanFile;
745
746    fn into_v2(self) -> Result<Self::Output> {
747        let Self { id, uri, meta } = self;
748        Ok(super::PlanFile {
749            id: id.into_v2()?,
750            uri: uri.into_v2()?,
751            meta: meta.into_v2()?,
752        })
753    }
754}
755
756#[cfg(feature = "unstable_plan_operations")]
757impl IntoV1 for super::PlanMarkdown {
758    type Output = crate::v1::PlanMarkdown;
759
760    fn into_v1(self) -> Result<Self::Output> {
761        let Self { id, content, meta } = self;
762        Ok(crate::v1::PlanMarkdown {
763            id: id.into_v1()?,
764            content: content.into_v1()?,
765            meta: meta.into_v1()?,
766        })
767    }
768}
769
770#[cfg(feature = "unstable_plan_operations")]
771impl IntoV2 for crate::v1::PlanMarkdown {
772    type Output = super::PlanMarkdown;
773
774    fn into_v2(self) -> Result<Self::Output> {
775        let Self { id, content, meta } = self;
776        Ok(super::PlanMarkdown {
777            id: id.into_v2()?,
778            content: content.into_v2()?,
779            meta: meta.into_v2()?,
780        })
781    }
782}
783
784#[cfg(feature = "unstable_plan_operations")]
785impl IntoV1 for super::PlanRemoved {
786    type Output = crate::v1::PlanRemoved;
787
788    fn into_v1(self) -> Result<Self::Output> {
789        let Self { id, meta } = self;
790        Ok(crate::v1::PlanRemoved {
791            id: id.into_v1()?,
792            meta: meta.into_v1()?,
793        })
794    }
795}
796
797#[cfg(feature = "unstable_plan_operations")]
798impl IntoV2 for crate::v1::PlanRemoved {
799    type Output = super::PlanRemoved;
800
801    fn into_v2(self) -> Result<Self::Output> {
802        let Self { id, meta } = self;
803        Ok(super::PlanRemoved {
804            id: id.into_v2()?,
805            meta: meta.into_v2()?,
806        })
807    }
808}
809
810impl IntoV1 for super::PlanEntry {
811    type Output = crate::v1::PlanEntry;
812
813    fn into_v1(self) -> Result<Self::Output> {
814        let Self {
815            content,
816            priority,
817            status,
818            meta,
819        } = self;
820        Ok(crate::v1::PlanEntry {
821            content: content.into_v1()?,
822            priority: priority.into_v1()?,
823            status: status.into_v1()?,
824            meta: meta.into_v1()?,
825        })
826    }
827}
828
829impl IntoV2 for crate::v1::PlanEntry {
830    type Output = super::PlanEntry;
831
832    fn into_v2(self) -> Result<Self::Output> {
833        let Self {
834            content,
835            priority,
836            status,
837            meta,
838        } = self;
839        Ok(super::PlanEntry {
840            content: content.into_v2()?,
841            priority: priority.into_v2()?,
842            status: status.into_v2()?,
843            meta: meta.into_v2()?,
844        })
845    }
846}
847
848impl IntoV1 for super::PlanEntryPriority {
849    type Output = crate::v1::PlanEntryPriority;
850
851    fn into_v1(self) -> Result<Self::Output> {
852        Ok(match self {
853            Self::High => crate::v1::PlanEntryPriority::High,
854            Self::Medium => crate::v1::PlanEntryPriority::Medium,
855            Self::Low => crate::v1::PlanEntryPriority::Low,
856            Self::Other(value) => {
857                return Err(unknown_v2_enum_variant("PlanEntryPriority", &value));
858            }
859        })
860    }
861}
862
863impl IntoV2 for crate::v1::PlanEntryPriority {
864    type Output = super::PlanEntryPriority;
865
866    fn into_v2(self) -> Result<Self::Output> {
867        Ok(match self {
868            Self::High => super::PlanEntryPriority::High,
869            Self::Medium => super::PlanEntryPriority::Medium,
870            Self::Low => super::PlanEntryPriority::Low,
871        })
872    }
873}
874
875impl IntoV1 for super::PlanEntryStatus {
876    type Output = crate::v1::PlanEntryStatus;
877
878    fn into_v1(self) -> Result<Self::Output> {
879        Ok(match self {
880            Self::Pending => crate::v1::PlanEntryStatus::Pending,
881            Self::InProgress => crate::v1::PlanEntryStatus::InProgress,
882            Self::Completed => crate::v1::PlanEntryStatus::Completed,
883            Self::Other(value) => return Err(unknown_v2_enum_variant("PlanEntryStatus", &value)),
884        })
885    }
886}
887
888impl IntoV2 for crate::v1::PlanEntryStatus {
889    type Output = super::PlanEntryStatus;
890
891    fn into_v2(self) -> Result<Self::Output> {
892        Ok(match self {
893            Self::Pending => super::PlanEntryStatus::Pending,
894            Self::InProgress => super::PlanEntryStatus::InProgress,
895            Self::Completed => super::PlanEntryStatus::Completed,
896        })
897    }
898}
899
900#[cfg(feature = "unstable_cancel_request")]
901impl IntoV1 for super::CancelRequestNotification {
902    type Output = crate::v1::CancelRequestNotification;
903
904    fn into_v1(self) -> Result<Self::Output> {
905        let Self { request_id, meta } = self;
906        Ok(crate::v1::CancelRequestNotification {
907            request_id: request_id.into_v1()?,
908            meta: meta.into_v1()?,
909        })
910    }
911}
912
913#[cfg(feature = "unstable_cancel_request")]
914impl IntoV2 for crate::v1::CancelRequestNotification {
915    type Output = super::CancelRequestNotification;
916
917    fn into_v2(self) -> Result<Self::Output> {
918        let Self { request_id, meta } = self;
919        Ok(super::CancelRequestNotification {
920            request_id: request_id.into_v2()?,
921            meta: meta.into_v2()?,
922        })
923    }
924}
925
926#[cfg(feature = "unstable_cancel_request")]
927impl IntoV1 for super::ProtocolLevelNotification {
928    type Output = crate::v1::ProtocolLevelNotification;
929
930    fn into_v1(self) -> Result<Self::Output> {
931        Ok(match self {
932            Self::CancelRequestNotification(value) => {
933                crate::v1::ProtocolLevelNotification::CancelRequestNotification(value.into_v1()?)
934            }
935        })
936    }
937}
938
939#[cfg(feature = "unstable_cancel_request")]
940impl IntoV2 for crate::v1::ProtocolLevelNotification {
941    type Output = super::ProtocolLevelNotification;
942
943    fn into_v2(self) -> Result<Self::Output> {
944        Ok(match self {
945            Self::CancelRequestNotification(value) => {
946                super::ProtocolLevelNotification::CancelRequestNotification(value.into_v2()?)
947            }
948        })
949    }
950}
951
952impl IntoV1Many for super::SessionNotification {
953    type Output = crate::v1::SessionNotification;
954
955    fn into_v1_many(self) -> Result<Vec<Self::Output>> {
956        let Self {
957            session_id,
958            update,
959            meta,
960        } = self;
961        let session_id = session_id.into_v1()?;
962        let meta = meta.into_v1()?;
963        update
964            .into_v1_many()?
965            .into_iter()
966            .map(|update| {
967                Ok(crate::v1::SessionNotification {
968                    session_id: session_id.clone(),
969                    update,
970                    meta: meta.clone(),
971                })
972            })
973            .collect()
974    }
975}
976
977impl IntoV2 for crate::v1::SessionNotification {
978    type Output = super::SessionNotification;
979
980    fn into_v2(self) -> Result<Self::Output> {
981        let Self {
982            session_id,
983            update,
984            meta,
985        } = self;
986        Ok(super::SessionNotification {
987            session_id: session_id.into_v2()?,
988            update: update.into_v2()?,
989            meta: meta.into_v2()?,
990        })
991    }
992}
993
994impl IntoV1Many for super::SessionUpdate {
995    type Output = crate::v1::SessionUpdate;
996
997    fn into_v1_many(self) -> Result<Vec<Self::Output>> {
998        Ok(match self {
999            Self::UserMessageChunk(value) => {
1000                vec![crate::v1::SessionUpdate::UserMessageChunk(value.into_v1()?)]
1001            }
1002            Self::UserMessage(value) => v2_message_update_into_v1_chunks(
1003                "user_message",
1004                value.message_id,
1005                value.content,
1006                value.meta,
1007                crate::v1::SessionUpdate::UserMessageChunk,
1008            )?,
1009            Self::AgentMessageChunk(value) => {
1010                vec![crate::v1::SessionUpdate::AgentMessageChunk(
1011                    value.into_v1()?,
1012                )]
1013            }
1014            Self::AgentMessage(value) => v2_message_update_into_v1_chunks(
1015                "agent_message",
1016                value.message_id,
1017                value.content,
1018                value.meta,
1019                crate::v1::SessionUpdate::AgentMessageChunk,
1020            )?,
1021            Self::AgentThoughtChunk(value) => {
1022                vec![crate::v1::SessionUpdate::AgentThoughtChunk(
1023                    value.into_v1()?,
1024                )]
1025            }
1026            Self::AgentThought(value) => v2_message_update_into_v1_chunks(
1027                "agent_thought",
1028                value.message_id,
1029                value.content,
1030                value.meta,
1031                crate::v1::SessionUpdate::AgentThoughtChunk,
1032            )?,
1033            Self::StateUpdate(_) => {
1034                return Err(ProtocolConversionError::new(
1035                    "v2 SessionUpdate variant `state_update` cannot be represented in v1 because v1 reports completion in the session/prompt response",
1036                ));
1037            }
1038            Self::ToolCallContentChunk(_) => {
1039                return Err(ProtocolConversionError::new(
1040                    "v2 SessionUpdate variant `tool_call_content_chunk` cannot be represented in v1 because v1 tool-call content updates replace content instead of appending",
1041                ));
1042            }
1043            Self::ToolCallUpdate(value) => {
1044                vec![crate::v1::SessionUpdate::ToolCallUpdate(value.into_v1()?)]
1045            }
1046            #[cfg(feature = "unstable_plan_operations")]
1047            Self::PlanUpdate(value) => vec![crate::v1::SessionUpdate::PlanUpdate(value.into_v1()?)],
1048            #[cfg(not(feature = "unstable_plan_operations"))]
1049            Self::PlanUpdate(value) => vec![crate::v1::SessionUpdate::Plan(value.into_v1()?)],
1050            #[cfg(feature = "unstable_plan_operations")]
1051            Self::PlanRemoved(value) => {
1052                vec![crate::v1::SessionUpdate::PlanRemoved(value.into_v1()?)]
1053            }
1054            Self::AvailableCommandsUpdate(value) => {
1055                vec![crate::v1::SessionUpdate::AvailableCommandsUpdate(
1056                    value.into_v1()?,
1057                )]
1058            }
1059            Self::ConfigOptionUpdate(value) => {
1060                vec![crate::v1::SessionUpdate::ConfigOptionUpdate(
1061                    value.into_v1()?,
1062                )]
1063            }
1064            Self::SessionInfoUpdate(value) => {
1065                vec![crate::v1::SessionUpdate::SessionInfoUpdate(
1066                    value.into_v1()?,
1067                )]
1068            }
1069            Self::UsageUpdate(value) => {
1070                vec![crate::v1::SessionUpdate::UsageUpdate(value.into_v1()?)]
1071            }
1072            Self::Other(value) => {
1073                return Err(unknown_v2_enum_variant(
1074                    "SessionUpdate",
1075                    &value.session_update,
1076                ));
1077            }
1078        })
1079    }
1080}
1081
1082fn v2_message_update_into_v1_chunks(
1083    variant: &str,
1084    message_id: super::MessageId,
1085    content: crate::MaybeUndefined<Vec<super::ContentBlock>>,
1086    meta: crate::MaybeUndefined<super::Meta>,
1087    wrap: impl Fn(crate::v1::ContentChunk) -> crate::v1::SessionUpdate,
1088) -> Result<Vec<crate::v1::SessionUpdate>> {
1089    let content = match content {
1090        crate::MaybeUndefined::Value(content) if !content.is_empty() => content,
1091        crate::MaybeUndefined::Value(_) => {
1092            return Err(ProtocolConversionError::new(format!(
1093                "v2 SessionUpdate variant `{variant}` with empty content cannot be represented in v1 chunks"
1094            )));
1095        }
1096        crate::MaybeUndefined::Null => {
1097            return Err(ProtocolConversionError::new(format!(
1098                "v2 SessionUpdate variant `{variant}` with null content cannot be represented in v1 chunks"
1099            )));
1100        }
1101        crate::MaybeUndefined::Undefined => {
1102            return Err(ProtocolConversionError::new(format!(
1103                "v2 SessionUpdate variant `{variant}` without content cannot be represented in v1 chunks"
1104            )));
1105        }
1106    };
1107    let message_id = message_id.into_v1()?;
1108    let meta = match meta {
1109        crate::MaybeUndefined::Value(meta) => Some(meta.into_v1()?),
1110        crate::MaybeUndefined::Null => {
1111            return Err(ProtocolConversionError::new(format!(
1112                "v2 SessionUpdate variant `{variant}` with null _meta cannot be represented in v1 chunks"
1113            )));
1114        }
1115        crate::MaybeUndefined::Undefined => None,
1116    };
1117
1118    content
1119        .into_iter()
1120        .map(|content| {
1121            Ok(wrap(crate::v1::ContentChunk {
1122                content: content.into_v1()?,
1123                message_id: Some(message_id.clone()),
1124                meta: meta.clone(),
1125            }))
1126        })
1127        .collect()
1128}
1129
1130impl IntoV2 for crate::v1::SessionUpdate {
1131    type Output = super::SessionUpdate;
1132
1133    fn into_v2(self) -> Result<Self::Output> {
1134        Ok(match self {
1135            Self::UserMessageChunk(value) => {
1136                super::SessionUpdate::UserMessageChunk(value.into_v2()?)
1137            }
1138            Self::AgentMessageChunk(value) => {
1139                super::SessionUpdate::AgentMessageChunk(value.into_v2()?)
1140            }
1141            Self::AgentThoughtChunk(value) => {
1142                super::SessionUpdate::AgentThoughtChunk(value.into_v2()?)
1143            }
1144            Self::ToolCall(value) => super::SessionUpdate::ToolCallUpdate(value.into_v2()?),
1145            Self::ToolCallUpdate(value) => super::SessionUpdate::ToolCallUpdate(value.into_v2()?),
1146            Self::Plan(value) => {
1147                let crate::v1::Plan { entries, meta } = value;
1148                super::SessionUpdate::PlanUpdate(super::PlanUpdate {
1149                    plan: super::PlanUpdateContent::items(LEGACY_V1_PLAN_ID, entries.into_v2()?),
1150                    meta: meta.into_v2()?,
1151                })
1152            }
1153            #[cfg(feature = "unstable_plan_operations")]
1154            Self::PlanUpdate(value) => super::SessionUpdate::PlanUpdate(value.into_v2()?),
1155            #[cfg(feature = "unstable_plan_operations")]
1156            Self::PlanRemoved(value) => super::SessionUpdate::PlanRemoved(value.into_v2()?),
1157            Self::AvailableCommandsUpdate(value) => {
1158                super::SessionUpdate::AvailableCommandsUpdate(value.into_v2()?)
1159            }
1160            Self::CurrentModeUpdate(_) => {
1161                return Err(removed_v1_enum_variant(
1162                    "SessionUpdate",
1163                    "current_mode_update",
1164                ));
1165            }
1166            Self::ConfigOptionUpdate(value) => {
1167                super::SessionUpdate::ConfigOptionUpdate(value.into_v2()?)
1168            }
1169            Self::SessionInfoUpdate(value) => {
1170                super::SessionUpdate::SessionInfoUpdate(value.into_v2()?)
1171            }
1172            Self::UsageUpdate(value) => super::SessionUpdate::UsageUpdate(value.into_v2()?),
1173        })
1174    }
1175}
1176
1177impl IntoV1 for super::ConfigOptionUpdate {
1178    type Output = crate::v1::ConfigOptionUpdate;
1179
1180    fn into_v1(self) -> Result<Self::Output> {
1181        let Self {
1182            config_options,
1183            meta,
1184        } = self;
1185        Ok(crate::v1::ConfigOptionUpdate {
1186            config_options: into_v1_vec_skip_errors(config_options),
1187            meta: meta.into_v1()?,
1188        })
1189    }
1190}
1191
1192impl IntoV2 for crate::v1::ConfigOptionUpdate {
1193    type Output = super::ConfigOptionUpdate;
1194
1195    fn into_v2(self) -> Result<Self::Output> {
1196        let Self {
1197            config_options,
1198            meta,
1199        } = self;
1200        Ok(super::ConfigOptionUpdate {
1201            config_options: into_v2_vec_skip_errors(config_options),
1202            meta: meta.into_v2()?,
1203        })
1204    }
1205}
1206
1207impl IntoV1 for super::SessionInfoUpdate {
1208    type Output = crate::v1::SessionInfoUpdate;
1209
1210    fn into_v1(self) -> Result<Self::Output> {
1211        let Self {
1212            title,
1213            updated_at,
1214            meta,
1215        } = self;
1216        Ok(crate::v1::SessionInfoUpdate {
1217            title: title.into_v1()?,
1218            updated_at: updated_at.into_v1()?,
1219            meta: meta.into_v1()?,
1220        })
1221    }
1222}
1223
1224impl IntoV2 for crate::v1::SessionInfoUpdate {
1225    type Output = super::SessionInfoUpdate;
1226
1227    fn into_v2(self) -> Result<Self::Output> {
1228        let Self {
1229            title,
1230            updated_at,
1231            meta,
1232        } = self;
1233        Ok(super::SessionInfoUpdate {
1234            title: title.into_v2()?,
1235            updated_at: updated_at.into_v2()?,
1236            meta: meta.into_v2()?,
1237        })
1238    }
1239}
1240
1241impl IntoV1 for super::UsageUpdate {
1242    type Output = crate::v1::UsageUpdate;
1243
1244    fn into_v1(self) -> Result<Self::Output> {
1245        let Self {
1246            used,
1247            size,
1248            cost,
1249            meta,
1250        } = self;
1251        Ok(crate::v1::UsageUpdate {
1252            used: used.into_v1()?,
1253            size: size.into_v1()?,
1254            cost: into_v1_default_on_error(cost),
1255            meta: meta.into_v1()?,
1256        })
1257    }
1258}
1259
1260impl IntoV2 for crate::v1::UsageUpdate {
1261    type Output = super::UsageUpdate;
1262
1263    fn into_v2(self) -> Result<Self::Output> {
1264        let Self {
1265            used,
1266            size,
1267            cost,
1268            meta,
1269        } = self;
1270        Ok(super::UsageUpdate {
1271            used: used.into_v2()?,
1272            size: size.into_v2()?,
1273            cost: into_v2_default_on_error(cost),
1274            meta: meta.into_v2()?,
1275        })
1276    }
1277}
1278
1279impl IntoV1 for super::Cost {
1280    type Output = crate::v1::Cost;
1281
1282    fn into_v1(self) -> Result<Self::Output> {
1283        let Self {
1284            amount,
1285            currency,
1286            meta,
1287        } = self;
1288        Ok(crate::v1::Cost {
1289            amount: amount.into_v1()?,
1290            currency: currency.into_v1()?,
1291            meta: meta.into_v1()?,
1292        })
1293    }
1294}
1295
1296impl IntoV2 for crate::v1::Cost {
1297    type Output = super::Cost;
1298
1299    fn into_v2(self) -> Result<Self::Output> {
1300        let Self {
1301            amount,
1302            currency,
1303            meta,
1304        } = self;
1305        Ok(super::Cost {
1306            amount: amount.into_v2()?,
1307            currency: currency.into_v2()?,
1308            meta: meta.into_v2()?,
1309        })
1310    }
1311}
1312
1313impl IntoV1 for super::ContentChunk {
1314    type Output = crate::v1::ContentChunk;
1315
1316    fn into_v1(self) -> Result<Self::Output> {
1317        let Self {
1318            content,
1319            message_id,
1320            meta,
1321        } = self;
1322        Ok(crate::v1::ContentChunk {
1323            content: content.into_v1()?,
1324            message_id: Some(message_id.into_v1()?),
1325            meta: meta.into_v1()?,
1326        })
1327    }
1328}
1329
1330impl IntoV2 for crate::v1::ContentChunk {
1331    type Output = super::ContentChunk;
1332
1333    fn into_v2(self) -> Result<Self::Output> {
1334        let Self {
1335            content,
1336            message_id,
1337            meta,
1338        } = self;
1339        Ok(super::ContentChunk {
1340            content: content.into_v2()?,
1341            message_id: message_id
1342                .ok_or_else(|| {
1343                    ProtocolConversionError::new(
1344                        "v1 ContentChunk without messageId cannot be represented in v2",
1345                    )
1346                })?
1347                .into_v2()?,
1348            meta: meta.into_v2()?,
1349        })
1350    }
1351}
1352
1353impl IntoV1 for super::AvailableCommandsUpdate {
1354    type Output = crate::v1::AvailableCommandsUpdate;
1355
1356    fn into_v1(self) -> Result<Self::Output> {
1357        let Self {
1358            available_commands,
1359            meta,
1360        } = self;
1361        Ok(crate::v1::AvailableCommandsUpdate {
1362            available_commands: into_v1_vec_skip_errors(available_commands),
1363            meta: meta.into_v1()?,
1364        })
1365    }
1366}
1367
1368impl IntoV2 for crate::v1::AvailableCommandsUpdate {
1369    type Output = super::AvailableCommandsUpdate;
1370
1371    fn into_v2(self) -> Result<Self::Output> {
1372        let Self {
1373            available_commands,
1374            meta,
1375        } = self;
1376        Ok(super::AvailableCommandsUpdate {
1377            available_commands: into_v2_vec_skip_errors(available_commands),
1378            meta: meta.into_v2()?,
1379        })
1380    }
1381}
1382
1383impl IntoV1 for super::AvailableCommand {
1384    type Output = crate::v1::AvailableCommand;
1385
1386    fn into_v1(self) -> Result<Self::Output> {
1387        let Self {
1388            name,
1389            description,
1390            input,
1391            meta,
1392        } = self;
1393        Ok(crate::v1::AvailableCommand {
1394            name: name.into_v1()?,
1395            description: description.into_v1()?,
1396            input: into_v1_default_on_error(input),
1397            meta: meta.into_v1()?,
1398        })
1399    }
1400}
1401
1402impl IntoV2 for crate::v1::AvailableCommand {
1403    type Output = super::AvailableCommand;
1404
1405    fn into_v2(self) -> Result<Self::Output> {
1406        let Self {
1407            name,
1408            description,
1409            input,
1410            meta,
1411        } = self;
1412        Ok(super::AvailableCommand {
1413            name: name.into_v2()?,
1414            description: description.into_v2()?,
1415            input: into_v2_default_on_error(input),
1416            meta: meta.into_v2()?,
1417        })
1418    }
1419}
1420
1421impl IntoV1 for super::AvailableCommandInput {
1422    type Output = crate::v1::AvailableCommandInput;
1423
1424    fn into_v1(self) -> Result<Self::Output> {
1425        Ok(match self {
1426            Self::Unstructured(value) => {
1427                crate::v1::AvailableCommandInput::Unstructured(value.into_v1()?)
1428            }
1429            Self::Other(value) => {
1430                return Err(unknown_v2_enum_variant(
1431                    "AvailableCommandInput",
1432                    &value.type_,
1433                ));
1434            }
1435        })
1436    }
1437}
1438
1439impl IntoV2 for crate::v1::AvailableCommandInput {
1440    type Output = super::AvailableCommandInput;
1441
1442    fn into_v2(self) -> Result<Self::Output> {
1443        Ok(match self {
1444            Self::Unstructured(value) => {
1445                super::AvailableCommandInput::Unstructured(value.into_v2()?)
1446            }
1447        })
1448    }
1449}
1450
1451impl IntoV1 for super::UnstructuredCommandInput {
1452    type Output = crate::v1::UnstructuredCommandInput;
1453
1454    fn into_v1(self) -> Result<Self::Output> {
1455        let Self { hint, meta } = self;
1456        Ok(crate::v1::UnstructuredCommandInput {
1457            hint: hint.into_v1()?,
1458            meta: meta.into_v1()?,
1459        })
1460    }
1461}
1462
1463impl IntoV2 for crate::v1::UnstructuredCommandInput {
1464    type Output = super::UnstructuredCommandInput;
1465
1466    fn into_v2(self) -> Result<Self::Output> {
1467        let Self { hint, meta } = self;
1468        Ok(super::UnstructuredCommandInput {
1469            hint: hint.into_v2()?,
1470            meta: meta.into_v2()?,
1471        })
1472    }
1473}
1474
1475impl IntoV1 for super::RequestPermissionRequest {
1476    type Output = crate::v1::RequestPermissionRequest;
1477
1478    fn into_v1(self) -> Result<Self::Output> {
1479        let Self {
1480            session_id,
1481            tool_call,
1482            options,
1483            meta,
1484        } = self;
1485        Ok(crate::v1::RequestPermissionRequest {
1486            session_id: session_id.into_v1()?,
1487            tool_call: tool_call.into_v1()?,
1488            options: options.into_v1()?,
1489            meta: meta.into_v1()?,
1490        })
1491    }
1492}
1493
1494impl IntoV2 for crate::v1::RequestPermissionRequest {
1495    type Output = super::RequestPermissionRequest;
1496
1497    fn into_v2(self) -> Result<Self::Output> {
1498        let Self {
1499            session_id,
1500            tool_call,
1501            options,
1502            meta,
1503        } = self;
1504        Ok(super::RequestPermissionRequest {
1505            session_id: session_id.into_v2()?,
1506            tool_call: tool_call.into_v2()?,
1507            options: options.into_v2()?,
1508            meta: meta.into_v2()?,
1509        })
1510    }
1511}
1512
1513impl IntoV1 for super::PermissionOption {
1514    type Output = crate::v1::PermissionOption;
1515
1516    fn into_v1(self) -> Result<Self::Output> {
1517        let Self {
1518            option_id,
1519            name,
1520            kind,
1521            meta,
1522        } = self;
1523        Ok(crate::v1::PermissionOption {
1524            option_id: option_id.into_v1()?,
1525            name: name.into_v1()?,
1526            kind: kind.into_v1()?,
1527            meta: meta.into_v1()?,
1528        })
1529    }
1530}
1531
1532impl IntoV2 for crate::v1::PermissionOption {
1533    type Output = super::PermissionOption;
1534
1535    fn into_v2(self) -> Result<Self::Output> {
1536        let Self {
1537            option_id,
1538            name,
1539            kind,
1540            meta,
1541        } = self;
1542        Ok(super::PermissionOption {
1543            option_id: option_id.into_v2()?,
1544            name: name.into_v2()?,
1545            kind: kind.into_v2()?,
1546            meta: meta.into_v2()?,
1547        })
1548    }
1549}
1550
1551impl IntoV1 for super::PermissionOptionId {
1552    type Output = crate::v1::PermissionOptionId;
1553
1554    fn into_v1(self) -> Result<Self::Output> {
1555        Ok(crate::v1::PermissionOptionId(self.0.into_v1()?))
1556    }
1557}
1558
1559impl IntoV2 for crate::v1::PermissionOptionId {
1560    type Output = super::PermissionOptionId;
1561
1562    fn into_v2(self) -> Result<Self::Output> {
1563        Ok(super::PermissionOptionId(self.0.into_v2()?))
1564    }
1565}
1566
1567impl IntoV1 for super::PermissionOptionKind {
1568    type Output = crate::v1::PermissionOptionKind;
1569
1570    fn into_v1(self) -> Result<Self::Output> {
1571        Ok(match self {
1572            Self::AllowOnce => crate::v1::PermissionOptionKind::AllowOnce,
1573            Self::AllowAlways => crate::v1::PermissionOptionKind::AllowAlways,
1574            Self::RejectOnce => crate::v1::PermissionOptionKind::RejectOnce,
1575            Self::RejectAlways => crate::v1::PermissionOptionKind::RejectAlways,
1576            Self::Other(value) => {
1577                return Err(unknown_v2_enum_variant("PermissionOptionKind", &value));
1578            }
1579        })
1580    }
1581}
1582
1583impl IntoV2 for crate::v1::PermissionOptionKind {
1584    type Output = super::PermissionOptionKind;
1585
1586    fn into_v2(self) -> Result<Self::Output> {
1587        Ok(match self {
1588            Self::AllowOnce => super::PermissionOptionKind::AllowOnce,
1589            Self::AllowAlways => super::PermissionOptionKind::AllowAlways,
1590            Self::RejectOnce => super::PermissionOptionKind::RejectOnce,
1591            Self::RejectAlways => super::PermissionOptionKind::RejectAlways,
1592        })
1593    }
1594}
1595
1596impl IntoV1 for super::RequestPermissionResponse {
1597    type Output = crate::v1::RequestPermissionResponse;
1598
1599    fn into_v1(self) -> Result<Self::Output> {
1600        let Self { outcome, meta } = self;
1601        Ok(crate::v1::RequestPermissionResponse {
1602            outcome: outcome.into_v1()?,
1603            meta: meta.into_v1()?,
1604        })
1605    }
1606}
1607
1608impl IntoV2 for crate::v1::RequestPermissionResponse {
1609    type Output = super::RequestPermissionResponse;
1610
1611    fn into_v2(self) -> Result<Self::Output> {
1612        let Self { outcome, meta } = self;
1613        Ok(super::RequestPermissionResponse {
1614            outcome: outcome.into_v2()?,
1615            meta: meta.into_v2()?,
1616        })
1617    }
1618}
1619
1620impl IntoV1 for super::RequestPermissionOutcome {
1621    type Output = crate::v1::RequestPermissionOutcome;
1622
1623    fn into_v1(self) -> Result<Self::Output> {
1624        Ok(match self {
1625            Self::Cancelled => crate::v1::RequestPermissionOutcome::Cancelled,
1626            Self::Selected(value) => {
1627                crate::v1::RequestPermissionOutcome::Selected(value.into_v1()?)
1628            }
1629        })
1630    }
1631}
1632
1633impl IntoV2 for crate::v1::RequestPermissionOutcome {
1634    type Output = super::RequestPermissionOutcome;
1635
1636    fn into_v2(self) -> Result<Self::Output> {
1637        Ok(match self {
1638            Self::Cancelled => super::RequestPermissionOutcome::Cancelled,
1639            Self::Selected(value) => super::RequestPermissionOutcome::Selected(value.into_v2()?),
1640        })
1641    }
1642}
1643
1644impl IntoV1 for super::SelectedPermissionOutcome {
1645    type Output = crate::v1::SelectedPermissionOutcome;
1646
1647    fn into_v1(self) -> Result<Self::Output> {
1648        let Self { option_id, meta } = self;
1649        Ok(crate::v1::SelectedPermissionOutcome {
1650            option_id: option_id.into_v1()?,
1651            meta: meta.into_v1()?,
1652        })
1653    }
1654}
1655
1656impl IntoV2 for crate::v1::SelectedPermissionOutcome {
1657    type Output = super::SelectedPermissionOutcome;
1658
1659    fn into_v2(self) -> Result<Self::Output> {
1660        let Self { option_id, meta } = self;
1661        Ok(super::SelectedPermissionOutcome {
1662            option_id: option_id.into_v2()?,
1663            meta: meta.into_v2()?,
1664        })
1665    }
1666}
1667
1668#[cfg(feature = "unstable_mcp_over_acp")]
1669impl IntoV1 for super::ConnectMcpRequest {
1670    type Output = crate::v1::ConnectMcpRequest;
1671
1672    fn into_v1(self) -> Result<Self::Output> {
1673        let Self { acp_id, meta } = self;
1674        Ok(crate::v1::ConnectMcpRequest {
1675            acp_id: acp_id.into_v1()?,
1676            meta: meta.into_v1()?,
1677        })
1678    }
1679}
1680
1681#[cfg(feature = "unstable_mcp_over_acp")]
1682impl IntoV2 for crate::v1::ConnectMcpRequest {
1683    type Output = super::ConnectMcpRequest;
1684
1685    fn into_v2(self) -> Result<Self::Output> {
1686        let Self { acp_id, meta } = self;
1687        Ok(super::ConnectMcpRequest {
1688            acp_id: acp_id.into_v2()?,
1689            meta: meta.into_v2()?,
1690        })
1691    }
1692}
1693
1694#[cfg(feature = "unstable_mcp_over_acp")]
1695impl IntoV1 for super::ConnectMcpResponse {
1696    type Output = crate::v1::ConnectMcpResponse;
1697
1698    fn into_v1(self) -> Result<Self::Output> {
1699        let Self {
1700            connection_id,
1701            meta,
1702        } = self;
1703        Ok(crate::v1::ConnectMcpResponse {
1704            connection_id: connection_id.into_v1()?,
1705            meta: meta.into_v1()?,
1706        })
1707    }
1708}
1709
1710#[cfg(feature = "unstable_mcp_over_acp")]
1711impl IntoV2 for crate::v1::ConnectMcpResponse {
1712    type Output = super::ConnectMcpResponse;
1713
1714    fn into_v2(self) -> Result<Self::Output> {
1715        let Self {
1716            connection_id,
1717            meta,
1718        } = self;
1719        Ok(super::ConnectMcpResponse {
1720            connection_id: connection_id.into_v2()?,
1721            meta: meta.into_v2()?,
1722        })
1723    }
1724}
1725
1726#[cfg(feature = "unstable_mcp_over_acp")]
1727impl IntoV1 for super::MessageMcpRequest {
1728    type Output = crate::v1::MessageMcpRequest;
1729
1730    fn into_v1(self) -> Result<Self::Output> {
1731        let Self {
1732            connection_id,
1733            method,
1734            params,
1735            meta,
1736        } = self;
1737        Ok(crate::v1::MessageMcpRequest {
1738            connection_id: connection_id.into_v1()?,
1739            method: method.into_v1()?,
1740            params: params.into_v1()?,
1741            meta: meta.into_v1()?,
1742        })
1743    }
1744}
1745
1746#[cfg(feature = "unstable_mcp_over_acp")]
1747impl IntoV2 for crate::v1::MessageMcpRequest {
1748    type Output = super::MessageMcpRequest;
1749
1750    fn into_v2(self) -> Result<Self::Output> {
1751        let Self {
1752            connection_id,
1753            method,
1754            params,
1755            meta,
1756        } = self;
1757        Ok(super::MessageMcpRequest {
1758            connection_id: connection_id.into_v2()?,
1759            method: method.into_v2()?,
1760            params: params.into_v2()?,
1761            meta: meta.into_v2()?,
1762        })
1763    }
1764}
1765
1766#[cfg(feature = "unstable_mcp_over_acp")]
1767impl IntoV1 for super::MessageMcpNotification {
1768    type Output = crate::v1::MessageMcpNotification;
1769
1770    fn into_v1(self) -> Result<Self::Output> {
1771        let Self {
1772            connection_id,
1773            method,
1774            params,
1775            meta,
1776        } = self;
1777        Ok(crate::v1::MessageMcpNotification {
1778            connection_id: connection_id.into_v1()?,
1779            method: method.into_v1()?,
1780            params: params.into_v1()?,
1781            meta: meta.into_v1()?,
1782        })
1783    }
1784}
1785
1786#[cfg(feature = "unstable_mcp_over_acp")]
1787impl IntoV2 for crate::v1::MessageMcpNotification {
1788    type Output = super::MessageMcpNotification;
1789
1790    fn into_v2(self) -> Result<Self::Output> {
1791        let Self {
1792            connection_id,
1793            method,
1794            params,
1795            meta,
1796        } = self;
1797        Ok(super::MessageMcpNotification {
1798            connection_id: connection_id.into_v2()?,
1799            method: method.into_v2()?,
1800            params: params.into_v2()?,
1801            meta: meta.into_v2()?,
1802        })
1803    }
1804}
1805
1806#[cfg(feature = "unstable_mcp_over_acp")]
1807impl IntoV1 for super::MessageMcpResponse {
1808    type Output = crate::v1::MessageMcpResponse;
1809
1810    fn into_v1(self) -> Result<Self::Output> {
1811        let Self(result) = self;
1812        Ok(crate::v1::MessageMcpResponse::new(result.into_v1()?))
1813    }
1814}
1815
1816#[cfg(feature = "unstable_mcp_over_acp")]
1817impl IntoV2 for crate::v1::MessageMcpResponse {
1818    type Output = super::MessageMcpResponse;
1819
1820    fn into_v2(self) -> Result<Self::Output> {
1821        let Self(result) = self;
1822        Ok(super::MessageMcpResponse::new(result.into_v2()?))
1823    }
1824}
1825
1826#[cfg(feature = "unstable_mcp_over_acp")]
1827impl IntoV1 for super::DisconnectMcpRequest {
1828    type Output = crate::v1::DisconnectMcpRequest;
1829
1830    fn into_v1(self) -> Result<Self::Output> {
1831        let Self {
1832            connection_id,
1833            meta,
1834        } = self;
1835        Ok(crate::v1::DisconnectMcpRequest {
1836            connection_id: connection_id.into_v1()?,
1837            meta: meta.into_v1()?,
1838        })
1839    }
1840}
1841
1842#[cfg(feature = "unstable_mcp_over_acp")]
1843impl IntoV2 for crate::v1::DisconnectMcpRequest {
1844    type Output = super::DisconnectMcpRequest;
1845
1846    fn into_v2(self) -> Result<Self::Output> {
1847        let Self {
1848            connection_id,
1849            meta,
1850        } = self;
1851        Ok(super::DisconnectMcpRequest {
1852            connection_id: connection_id.into_v2()?,
1853            meta: meta.into_v2()?,
1854        })
1855    }
1856}
1857
1858#[cfg(feature = "unstable_mcp_over_acp")]
1859impl IntoV1 for super::DisconnectMcpResponse {
1860    type Output = crate::v1::DisconnectMcpResponse;
1861
1862    fn into_v1(self) -> Result<Self::Output> {
1863        let Self { meta } = self;
1864        Ok(crate::v1::DisconnectMcpResponse {
1865            meta: meta.into_v1()?,
1866        })
1867    }
1868}
1869
1870#[cfg(feature = "unstable_mcp_over_acp")]
1871impl IntoV2 for crate::v1::DisconnectMcpResponse {
1872    type Output = super::DisconnectMcpResponse;
1873
1874    fn into_v2(self) -> Result<Self::Output> {
1875        let Self { meta } = self;
1876        Ok(super::DisconnectMcpResponse {
1877            meta: meta.into_v2()?,
1878        })
1879    }
1880}
1881
1882impl IntoV1 for super::ClientCapabilities {
1883    type Output = crate::v1::ClientCapabilities;
1884
1885    fn into_v1(self) -> Result<Self::Output> {
1886        let Self {
1887            #[cfg(feature = "unstable_auth_methods")]
1888            auth,
1889            #[cfg(feature = "unstable_elicitation")]
1890            elicitation,
1891            #[cfg(feature = "unstable_nes")]
1892            nes,
1893            #[cfg(feature = "unstable_nes")]
1894            position_encodings,
1895            meta,
1896        } = self;
1897        Ok(crate::v1::ClientCapabilities {
1898            fs: crate::v1::FileSystemCapabilities::default(),
1899            terminal: false,
1900            #[cfg(feature = "unstable_boolean_config")]
1901            session: Some(
1902                crate::v1::ClientSessionCapabilities::new().config_options(
1903                    crate::v1::SessionConfigOptionsCapabilities::new()
1904                        .boolean(crate::v1::BooleanConfigOptionCapabilities::new()),
1905                ),
1906            ),
1907            #[cfg(feature = "unstable_plan_operations")]
1908            plan: None,
1909            #[cfg(feature = "unstable_auth_methods")]
1910            auth: auth.into_v1()?,
1911            #[cfg(feature = "unstable_elicitation")]
1912            elicitation: into_v1_default_on_error(elicitation),
1913            #[cfg(feature = "unstable_nes")]
1914            nes: into_v1_default_on_error(nes),
1915            #[cfg(feature = "unstable_nes")]
1916            position_encodings: into_v1_vec_skip_errors(position_encodings),
1917            meta: meta.into_v1()?,
1918        })
1919    }
1920}
1921
1922impl IntoV2 for crate::v1::ClientCapabilities {
1923    type Output = super::ClientCapabilities;
1924
1925    fn into_v2(self) -> Result<Self::Output> {
1926        let Self {
1927            fs: _,
1928            terminal: _,
1929            #[cfg(feature = "unstable_boolean_config")]
1930                session: _,
1931            #[cfg(feature = "unstable_plan_operations")]
1932                plan: _,
1933            #[cfg(feature = "unstable_auth_methods")]
1934            auth,
1935            #[cfg(feature = "unstable_elicitation")]
1936            elicitation,
1937            #[cfg(feature = "unstable_nes")]
1938            nes,
1939            #[cfg(feature = "unstable_nes")]
1940            position_encodings,
1941            meta,
1942        } = self;
1943        Ok(super::ClientCapabilities {
1944            #[cfg(feature = "unstable_auth_methods")]
1945            auth: auth.into_v2()?,
1946            #[cfg(feature = "unstable_elicitation")]
1947            elicitation: into_v2_default_on_error(elicitation),
1948            #[cfg(feature = "unstable_nes")]
1949            nes: into_v2_default_on_error(nes),
1950            #[cfg(feature = "unstable_nes")]
1951            position_encodings: into_v2_vec_skip_errors(position_encodings),
1952            meta: meta.into_v2()?,
1953        })
1954    }
1955}
1956
1957#[cfg(feature = "unstable_auth_methods")]
1958impl IntoV1 for super::AuthCapabilities {
1959    type Output = crate::v1::AuthCapabilities;
1960
1961    fn into_v1(self) -> Result<Self::Output> {
1962        let Self { terminal, meta } = self;
1963        Ok(crate::v1::AuthCapabilities {
1964            terminal: terminal.is_some(),
1965            meta: meta.into_v1()?,
1966        })
1967    }
1968}
1969
1970#[cfg(feature = "unstable_auth_methods")]
1971impl IntoV2 for crate::v1::AuthCapabilities {
1972    type Output = super::AuthCapabilities;
1973
1974    fn into_v2(self) -> Result<Self::Output> {
1975        let Self { terminal, meta } = self;
1976        Ok(super::AuthCapabilities {
1977            terminal: terminal.then(super::TerminalAuthCapabilities::new),
1978            meta: meta.into_v2()?,
1979        })
1980    }
1981}
1982
1983impl IntoV1 for super::AgentRequest {
1984    type Output = crate::v1::AgentRequest;
1985
1986    fn into_v1(self) -> Result<Self::Output> {
1987        Ok(match self {
1988            Self::RequestPermissionRequest(value) => {
1989                crate::v1::AgentRequest::RequestPermissionRequest(value.into_v1()?)
1990            }
1991            #[cfg(feature = "unstable_elicitation")]
1992            Self::CreateElicitationRequest(value) => {
1993                crate::v1::AgentRequest::CreateElicitationRequest(value.into_v1()?)
1994            }
1995            #[cfg(feature = "unstable_mcp_over_acp")]
1996            Self::ConnectMcpRequest(value) => {
1997                crate::v1::AgentRequest::ConnectMcpRequest(value.into_v1()?)
1998            }
1999            #[cfg(feature = "unstable_mcp_over_acp")]
2000            Self::MessageMcpRequest(value) => {
2001                crate::v1::AgentRequest::MessageMcpRequest(value.into_v1()?)
2002            }
2003            #[cfg(feature = "unstable_mcp_over_acp")]
2004            Self::DisconnectMcpRequest(value) => {
2005                crate::v1::AgentRequest::DisconnectMcpRequest(value.into_v1()?)
2006            }
2007            Self::ExtMethodRequest(value) => {
2008                crate::v1::AgentRequest::ExtMethodRequest(value.into_v1()?)
2009            }
2010        })
2011    }
2012}
2013
2014impl IntoV2 for crate::v1::AgentRequest {
2015    type Output = super::AgentRequest;
2016
2017    fn into_v2(self) -> Result<Self::Output> {
2018        Ok(match self {
2019            Self::WriteTextFileRequest(_) => {
2020                return Err(removed_v1_enum_variant(
2021                    "AgentRequest",
2022                    "fs/write_text_file",
2023                ));
2024            }
2025            Self::ReadTextFileRequest(_) => {
2026                return Err(removed_v1_enum_variant("AgentRequest", "fs/read_text_file"));
2027            }
2028            Self::RequestPermissionRequest(value) => {
2029                super::AgentRequest::RequestPermissionRequest(Box::new(value.into_v2()?))
2030            }
2031            Self::CreateTerminalRequest(_) => {
2032                return Err(removed_v1_enum_variant("AgentRequest", "terminal/create"));
2033            }
2034            Self::TerminalOutputRequest(_) => {
2035                return Err(removed_v1_enum_variant("AgentRequest", "terminal/output"));
2036            }
2037            Self::ReleaseTerminalRequest(_) => {
2038                return Err(removed_v1_enum_variant("AgentRequest", "terminal/release"));
2039            }
2040            Self::WaitForTerminalExitRequest(_) => {
2041                return Err(removed_v1_enum_variant(
2042                    "AgentRequest",
2043                    "terminal/wait_for_exit",
2044                ));
2045            }
2046            Self::KillTerminalRequest(_) => {
2047                return Err(removed_v1_enum_variant("AgentRequest", "terminal/kill"));
2048            }
2049            #[cfg(feature = "unstable_elicitation")]
2050            Self::CreateElicitationRequest(value) => {
2051                super::AgentRequest::CreateElicitationRequest(value.into_v2()?)
2052            }
2053            #[cfg(feature = "unstable_mcp_over_acp")]
2054            Self::ConnectMcpRequest(value) => {
2055                super::AgentRequest::ConnectMcpRequest(value.into_v2()?)
2056            }
2057            #[cfg(feature = "unstable_mcp_over_acp")]
2058            Self::MessageMcpRequest(value) => {
2059                super::AgentRequest::MessageMcpRequest(value.into_v2()?)
2060            }
2061            #[cfg(feature = "unstable_mcp_over_acp")]
2062            Self::DisconnectMcpRequest(value) => {
2063                super::AgentRequest::DisconnectMcpRequest(value.into_v2()?)
2064            }
2065            Self::ExtMethodRequest(value) => {
2066                super::AgentRequest::ExtMethodRequest(value.into_v2()?)
2067            }
2068        })
2069    }
2070}
2071
2072impl IntoV1 for super::ClientResponse {
2073    type Output = crate::v1::ClientResponse;
2074
2075    fn into_v1(self) -> Result<Self::Output> {
2076        Ok(match self {
2077            Self::RequestPermissionResponse(value) => {
2078                crate::v1::ClientResponse::RequestPermissionResponse(value.into_v1()?)
2079            }
2080            #[cfg(feature = "unstable_elicitation")]
2081            Self::CreateElicitationResponse(value) => {
2082                crate::v1::ClientResponse::CreateElicitationResponse(value.into_v1()?)
2083            }
2084            #[cfg(feature = "unstable_mcp_over_acp")]
2085            Self::ConnectMcpResponse(value) => {
2086                crate::v1::ClientResponse::ConnectMcpResponse(value.into_v1()?)
2087            }
2088            #[cfg(feature = "unstable_mcp_over_acp")]
2089            Self::MessageMcpResponse(value) => {
2090                crate::v1::ClientResponse::MessageMcpResponse(value.into_v1()?)
2091            }
2092            #[cfg(feature = "unstable_mcp_over_acp")]
2093            Self::DisconnectMcpResponse(value) => {
2094                crate::v1::ClientResponse::DisconnectMcpResponse(value.into_v1()?)
2095            }
2096            Self::ExtMethodResponse(value) => {
2097                crate::v1::ClientResponse::ExtMethodResponse(value.into_v1()?)
2098            }
2099        })
2100    }
2101}
2102
2103impl IntoV2 for crate::v1::ClientResponse {
2104    type Output = super::ClientResponse;
2105
2106    fn into_v2(self) -> Result<Self::Output> {
2107        Ok(match self {
2108            Self::WriteTextFileResponse(_) => {
2109                return Err(removed_v1_enum_variant(
2110                    "ClientResponse",
2111                    "fs/write_text_file",
2112                ));
2113            }
2114            Self::ReadTextFileResponse(_) => {
2115                return Err(removed_v1_enum_variant(
2116                    "ClientResponse",
2117                    "fs/read_text_file",
2118                ));
2119            }
2120            Self::RequestPermissionResponse(value) => {
2121                super::ClientResponse::RequestPermissionResponse(value.into_v2()?)
2122            }
2123            Self::CreateTerminalResponse(_) => {
2124                return Err(removed_v1_enum_variant("ClientResponse", "terminal/create"));
2125            }
2126            Self::TerminalOutputResponse(_) => {
2127                return Err(removed_v1_enum_variant("ClientResponse", "terminal/output"));
2128            }
2129            Self::ReleaseTerminalResponse(_) => {
2130                return Err(removed_v1_enum_variant(
2131                    "ClientResponse",
2132                    "terminal/release",
2133                ));
2134            }
2135            Self::WaitForTerminalExitResponse(_) => {
2136                return Err(removed_v1_enum_variant(
2137                    "ClientResponse",
2138                    "terminal/wait_for_exit",
2139                ));
2140            }
2141            Self::KillTerminalResponse(_) => {
2142                return Err(removed_v1_enum_variant("ClientResponse", "terminal/kill"));
2143            }
2144            #[cfg(feature = "unstable_elicitation")]
2145            Self::CreateElicitationResponse(value) => {
2146                super::ClientResponse::CreateElicitationResponse(value.into_v2()?)
2147            }
2148            #[cfg(feature = "unstable_mcp_over_acp")]
2149            Self::ConnectMcpResponse(value) => {
2150                super::ClientResponse::ConnectMcpResponse(value.into_v2()?)
2151            }
2152            #[cfg(feature = "unstable_mcp_over_acp")]
2153            Self::MessageMcpResponse(value) => {
2154                super::ClientResponse::MessageMcpResponse(value.into_v2()?)
2155            }
2156            #[cfg(feature = "unstable_mcp_over_acp")]
2157            Self::DisconnectMcpResponse(value) => {
2158                super::ClientResponse::DisconnectMcpResponse(value.into_v2()?)
2159            }
2160            Self::ExtMethodResponse(value) => {
2161                super::ClientResponse::ExtMethodResponse(value.into_v2()?)
2162            }
2163        })
2164    }
2165}
2166
2167impl IntoV1Many for super::AgentNotification {
2168    type Output = crate::v1::AgentNotification;
2169
2170    fn into_v1_many(self) -> Result<Vec<Self::Output>> {
2171        Ok(match self {
2172            Self::SessionNotification(value) => {
2173                return value
2174                    .into_v1_many()?
2175                    .into_iter()
2176                    .map(|value| Ok(crate::v1::AgentNotification::SessionNotification(value)))
2177                    .collect();
2178            }
2179            #[cfg(feature = "unstable_elicitation")]
2180            Self::CompleteElicitationNotification(value) => {
2181                vec![
2182                    crate::v1::AgentNotification::CompleteElicitationNotification(value.into_v1()?),
2183                ]
2184            }
2185            #[cfg(feature = "unstable_mcp_over_acp")]
2186            Self::MessageMcpNotification(value) => {
2187                vec![crate::v1::AgentNotification::MessageMcpNotification(
2188                    value.into_v1()?,
2189                )]
2190            }
2191            Self::ExtNotification(value) => {
2192                vec![crate::v1::AgentNotification::ExtNotification(
2193                    value.into_v1()?,
2194                )]
2195            }
2196        })
2197    }
2198}
2199
2200impl IntoV2 for crate::v1::AgentNotification {
2201    type Output = super::AgentNotification;
2202
2203    fn into_v2(self) -> Result<Self::Output> {
2204        Ok(match self {
2205            Self::SessionNotification(value) => {
2206                super::AgentNotification::SessionNotification(Box::new(value.into_v2()?))
2207            }
2208            #[cfg(feature = "unstable_elicitation")]
2209            Self::CompleteElicitationNotification(value) => {
2210                super::AgentNotification::CompleteElicitationNotification(value.into_v2()?)
2211            }
2212            #[cfg(feature = "unstable_mcp_over_acp")]
2213            Self::MessageMcpNotification(value) => {
2214                super::AgentNotification::MessageMcpNotification(value.into_v2()?)
2215            }
2216            Self::ExtNotification(value) => {
2217                super::AgentNotification::ExtNotification(value.into_v2()?)
2218            }
2219        })
2220    }
2221}
2222
2223impl IntoV1 for super::Error {
2224    type Output = crate::v1::Error;
2225
2226    fn into_v1(self) -> Result<Self::Output> {
2227        let Self {
2228            code,
2229            message,
2230            data,
2231        } = self;
2232        Ok(crate::v1::Error {
2233            code: code.into_v1()?,
2234            message: message.into_v1()?,
2235            data: data.into_v1()?,
2236        })
2237    }
2238}
2239
2240impl IntoV2 for crate::v1::Error {
2241    type Output = super::Error;
2242
2243    fn into_v2(self) -> Result<Self::Output> {
2244        let Self {
2245            code,
2246            message,
2247            data,
2248        } = self;
2249        Ok(super::Error {
2250            code: code.into_v2()?,
2251            message: message.into_v2()?,
2252            data: data.into_v2()?,
2253        })
2254    }
2255}
2256
2257impl IntoV1 for super::ErrorCode {
2258    type Output = crate::v1::ErrorCode;
2259
2260    fn into_v1(self) -> Result<Self::Output> {
2261        Ok(i32::from(self).into())
2262    }
2263}
2264
2265impl IntoV2 for crate::v1::ErrorCode {
2266    type Output = super::ErrorCode;
2267
2268    fn into_v2(self) -> Result<Self::Output> {
2269        Ok(i32::from(self).into())
2270    }
2271}
2272
2273impl IntoV1 for super::ExtRequest {
2274    type Output = crate::v1::ExtRequest;
2275
2276    fn into_v1(self) -> Result<Self::Output> {
2277        let Self { method, params } = self;
2278        Ok(crate::v1::ExtRequest {
2279            method: method.into_v1()?,
2280            params: params.into_v1()?,
2281        })
2282    }
2283}
2284
2285impl IntoV2 for crate::v1::ExtRequest {
2286    type Output = super::ExtRequest;
2287
2288    fn into_v2(self) -> Result<Self::Output> {
2289        let Self { method, params } = self;
2290        Ok(super::ExtRequest {
2291            method: method.into_v2()?,
2292            params: params.into_v2()?,
2293        })
2294    }
2295}
2296
2297impl IntoV1 for super::ExtResponse {
2298    type Output = crate::v1::ExtResponse;
2299
2300    fn into_v1(self) -> Result<Self::Output> {
2301        Ok(crate::v1::ExtResponse(self.0.into_v1()?))
2302    }
2303}
2304
2305impl IntoV2 for crate::v1::ExtResponse {
2306    type Output = super::ExtResponse;
2307
2308    fn into_v2(self) -> Result<Self::Output> {
2309        Ok(super::ExtResponse(self.0.into_v2()?))
2310    }
2311}
2312
2313impl IntoV1 for super::ExtNotification {
2314    type Output = crate::v1::ExtNotification;
2315
2316    fn into_v1(self) -> Result<Self::Output> {
2317        let Self { method, params } = self;
2318        Ok(crate::v1::ExtNotification {
2319            method: method.into_v1()?,
2320            params: params.into_v1()?,
2321        })
2322    }
2323}
2324
2325impl IntoV2 for crate::v1::ExtNotification {
2326    type Output = super::ExtNotification;
2327
2328    fn into_v2(self) -> Result<Self::Output> {
2329        let Self { method, params } = self;
2330        Ok(super::ExtNotification {
2331            method: method.into_v2()?,
2332            params: params.into_v2()?,
2333        })
2334    }
2335}
2336
2337fn maybe_undefined_value_into_v1_option<T>(value: crate::MaybeUndefined<T>) -> Option<T::Output>
2338where
2339    T: IntoV1,
2340{
2341    match value {
2342        crate::MaybeUndefined::Value(value) => value.into_v1().ok(),
2343        crate::MaybeUndefined::Null | crate::MaybeUndefined::Undefined => None,
2344    }
2345}
2346
2347fn maybe_undefined_vec_into_v1_option<T>(
2348    value: crate::MaybeUndefined<Vec<T>>,
2349) -> Option<Vec<T::Output>>
2350where
2351    T: IntoV1,
2352{
2353    match value {
2354        crate::MaybeUndefined::Value(value) => Some(into_v1_vec_skip_errors(value)),
2355        crate::MaybeUndefined::Null => Some(Vec::new()),
2356        crate::MaybeUndefined::Undefined => None,
2357    }
2358}
2359
2360fn option_into_v2_maybe_undefined<T>(value: Option<T>) -> Result<crate::MaybeUndefined<T::Output>>
2361where
2362    T: IntoV2,
2363{
2364    match value {
2365        Some(value) => Ok(crate::MaybeUndefined::Value(value.into_v2()?)),
2366        None => Ok(crate::MaybeUndefined::Undefined),
2367    }
2368}
2369
2370fn option_vec_into_v2_maybe_undefined_skip_errors<T>(
2371    value: Option<Vec<T>>,
2372) -> crate::MaybeUndefined<Vec<T::Output>>
2373where
2374    T: IntoV2,
2375{
2376    match value {
2377        Some(value) => crate::MaybeUndefined::Value(into_v2_vec_skip_errors(value)),
2378        None => crate::MaybeUndefined::Undefined,
2379    }
2380}
2381
2382fn vec_into_v2_maybe_undefined_skip_errors<T>(
2383    value: Vec<T>,
2384) -> crate::MaybeUndefined<Vec<T::Output>>
2385where
2386    T: IntoV2,
2387{
2388    if value.is_empty() {
2389        crate::MaybeUndefined::Undefined
2390    } else {
2391        crate::MaybeUndefined::Value(into_v2_vec_skip_errors(value))
2392    }
2393}
2394
2395impl IntoV1 for super::ToolCallUpdate {
2396    type Output = crate::v1::ToolCallUpdate;
2397
2398    fn into_v1(self) -> Result<Self::Output> {
2399        let Self {
2400            tool_call_id,
2401            title,
2402            kind,
2403            status,
2404            content,
2405            locations,
2406            raw_input,
2407            raw_output,
2408            meta,
2409        } = self;
2410        Ok(crate::v1::ToolCallUpdate {
2411            tool_call_id: tool_call_id.into_v1()?,
2412            fields: crate::v1::ToolCallUpdateFields {
2413                kind: maybe_undefined_value_into_v1_option(kind),
2414                status: maybe_undefined_value_into_v1_option(status),
2415                title: maybe_undefined_value_into_v1_option(title),
2416                content: maybe_undefined_vec_into_v1_option(content),
2417                locations: maybe_undefined_vec_into_v1_option(locations),
2418                raw_input: maybe_undefined_value_into_v1_option(raw_input),
2419                raw_output: maybe_undefined_value_into_v1_option(raw_output),
2420            },
2421            meta: meta.into_v1()?,
2422        })
2423    }
2424}
2425
2426impl IntoV2 for crate::v1::ToolCall {
2427    type Output = super::ToolCallUpdate;
2428
2429    fn into_v2(self) -> Result<Self::Output> {
2430        let Self {
2431            tool_call_id,
2432            title,
2433            kind,
2434            status,
2435            content,
2436            locations,
2437            raw_input,
2438            raw_output,
2439            meta,
2440        } = self;
2441        Ok(super::ToolCallUpdate {
2442            tool_call_id: tool_call_id.into_v2()?,
2443            title: crate::MaybeUndefined::Value(title.into_v2()?),
2444            kind: if matches!(kind, crate::v1::ToolKind::Other) {
2445                crate::MaybeUndefined::Undefined
2446            } else {
2447                crate::MaybeUndefined::Value(kind.into_v2()?)
2448            },
2449            status: if matches!(status, crate::v1::ToolCallStatus::Pending) {
2450                crate::MaybeUndefined::Undefined
2451            } else {
2452                crate::MaybeUndefined::Value(status.into_v2()?)
2453            },
2454            content: vec_into_v2_maybe_undefined_skip_errors(content),
2455            locations: vec_into_v2_maybe_undefined_skip_errors(locations),
2456            raw_input: option_into_v2_maybe_undefined(raw_input)?,
2457            raw_output: option_into_v2_maybe_undefined(raw_output)?,
2458            meta: meta.into_v2()?,
2459        })
2460    }
2461}
2462
2463impl IntoV2 for crate::v1::ToolCallUpdate {
2464    type Output = super::ToolCallUpdate;
2465
2466    fn into_v2(self) -> Result<Self::Output> {
2467        let Self {
2468            tool_call_id,
2469            fields,
2470            meta,
2471        } = self;
2472        let crate::v1::ToolCallUpdateFields {
2473            kind,
2474            status,
2475            title,
2476            content,
2477            locations,
2478            raw_input,
2479            raw_output,
2480        } = fields;
2481        Ok(super::ToolCallUpdate {
2482            tool_call_id: tool_call_id.into_v2()?,
2483            kind: option_into_v2_maybe_undefined(kind)?,
2484            status: option_into_v2_maybe_undefined(status)?,
2485            title: option_into_v2_maybe_undefined(title)?,
2486            content: option_vec_into_v2_maybe_undefined_skip_errors(content),
2487            locations: option_vec_into_v2_maybe_undefined_skip_errors(locations),
2488            raw_input: option_into_v2_maybe_undefined(raw_input)?,
2489            raw_output: option_into_v2_maybe_undefined(raw_output)?,
2490            meta: meta.into_v2()?,
2491        })
2492    }
2493}
2494
2495impl IntoV1 for super::ToolCallId {
2496    type Output = crate::v1::ToolCallId;
2497
2498    fn into_v1(self) -> Result<Self::Output> {
2499        Ok(crate::v1::ToolCallId(self.0.into_v1()?))
2500    }
2501}
2502
2503impl IntoV2 for crate::v1::ToolCallId {
2504    type Output = super::ToolCallId;
2505
2506    fn into_v2(self) -> Result<Self::Output> {
2507        Ok(super::ToolCallId(self.0.into_v2()?))
2508    }
2509}
2510
2511impl IntoV1 for super::ToolKind {
2512    type Output = crate::v1::ToolKind;
2513
2514    fn into_v1(self) -> Result<Self::Output> {
2515        Ok(match self {
2516            Self::Read => crate::v1::ToolKind::Read,
2517            Self::Edit => crate::v1::ToolKind::Edit,
2518            Self::Delete => crate::v1::ToolKind::Delete,
2519            Self::Move => crate::v1::ToolKind::Move,
2520            Self::Search => crate::v1::ToolKind::Search,
2521            Self::Execute => crate::v1::ToolKind::Execute,
2522            Self::Think => crate::v1::ToolKind::Think,
2523            Self::Fetch => crate::v1::ToolKind::Fetch,
2524            Self::SwitchMode => crate::v1::ToolKind::SwitchMode,
2525            Self::Other => crate::v1::ToolKind::Other,
2526            Self::Unknown(value) => return Err(unknown_v2_enum_variant("ToolKind", &value)),
2527        })
2528    }
2529}
2530
2531impl IntoV2 for crate::v1::ToolKind {
2532    type Output = super::ToolKind;
2533
2534    fn into_v2(self) -> Result<Self::Output> {
2535        Ok(match self {
2536            Self::Read => super::ToolKind::Read,
2537            Self::Edit => super::ToolKind::Edit,
2538            Self::Delete => super::ToolKind::Delete,
2539            Self::Move => super::ToolKind::Move,
2540            Self::Search => super::ToolKind::Search,
2541            Self::Execute => super::ToolKind::Execute,
2542            Self::Think => super::ToolKind::Think,
2543            Self::Fetch => super::ToolKind::Fetch,
2544            Self::SwitchMode => super::ToolKind::SwitchMode,
2545            Self::Other => super::ToolKind::Other,
2546        })
2547    }
2548}
2549
2550impl IntoV1 for super::ToolCallStatus {
2551    type Output = crate::v1::ToolCallStatus;
2552
2553    fn into_v1(self) -> Result<Self::Output> {
2554        Ok(match self {
2555            Self::Pending => crate::v1::ToolCallStatus::Pending,
2556            Self::InProgress => crate::v1::ToolCallStatus::InProgress,
2557            Self::Completed => crate::v1::ToolCallStatus::Completed,
2558            Self::Failed => crate::v1::ToolCallStatus::Failed,
2559            Self::Other(value) => return Err(unknown_v2_enum_variant("ToolCallStatus", &value)),
2560        })
2561    }
2562}
2563
2564impl IntoV2 for crate::v1::ToolCallStatus {
2565    type Output = super::ToolCallStatus;
2566
2567    fn into_v2(self) -> Result<Self::Output> {
2568        Ok(match self {
2569            Self::Pending => super::ToolCallStatus::Pending,
2570            Self::InProgress => super::ToolCallStatus::InProgress,
2571            Self::Completed => super::ToolCallStatus::Completed,
2572            Self::Failed => super::ToolCallStatus::Failed,
2573        })
2574    }
2575}
2576
2577impl IntoV1 for super::ToolCallContent {
2578    type Output = crate::v1::ToolCallContent;
2579
2580    fn into_v1(self) -> Result<Self::Output> {
2581        Ok(match self {
2582            Self::Content(value) => crate::v1::ToolCallContent::Content(value.into_v1()?),
2583            Self::Diff(value) => crate::v1::ToolCallContent::Diff(value.into_v1()?),
2584            Self::Other(value) => {
2585                return Err(unknown_v2_enum_variant("ToolCallContent", &value.type_));
2586            }
2587        })
2588    }
2589}
2590
2591impl IntoV2 for crate::v1::ToolCallContent {
2592    type Output = super::ToolCallContent;
2593
2594    fn into_v2(self) -> Result<Self::Output> {
2595        Ok(match self {
2596            Self::Content(value) => super::ToolCallContent::Content(Box::new(value.into_v2()?)),
2597            Self::Diff(value) => super::ToolCallContent::Diff(value.into_v2()?),
2598            Self::Terminal(_) => {
2599                return Err(removed_v1_enum_variant("ToolCallContent", "terminal"));
2600            }
2601        })
2602    }
2603}
2604
2605impl IntoV1 for super::Content {
2606    type Output = crate::v1::Content;
2607
2608    fn into_v1(self) -> Result<Self::Output> {
2609        let Self { content, meta } = self;
2610        Ok(crate::v1::Content {
2611            content: content.into_v1()?,
2612            meta: meta.into_v1()?,
2613        })
2614    }
2615}
2616
2617impl IntoV2 for crate::v1::Content {
2618    type Output = super::Content;
2619
2620    fn into_v2(self) -> Result<Self::Output> {
2621        let Self { content, meta } = self;
2622        Ok(super::Content {
2623            content: content.into_v2()?,
2624            meta: meta.into_v2()?,
2625        })
2626    }
2627}
2628
2629impl IntoV1 for super::Diff {
2630    type Output = crate::v1::Diff;
2631
2632    fn into_v1(self) -> Result<Self::Output> {
2633        let Self {
2634            path,
2635            old_text,
2636            new_text,
2637            meta,
2638        } = self;
2639        Ok(crate::v1::Diff {
2640            path: path.into_v1()?,
2641            old_text: old_text.into_v1()?,
2642            new_text: new_text.into_v1()?,
2643            meta: meta.into_v1()?,
2644        })
2645    }
2646}
2647
2648impl IntoV2 for crate::v1::Diff {
2649    type Output = super::Diff;
2650
2651    fn into_v2(self) -> Result<Self::Output> {
2652        let Self {
2653            path,
2654            old_text,
2655            new_text,
2656            meta,
2657        } = self;
2658        Ok(super::Diff {
2659            path: path.into_v2()?,
2660            old_text: old_text.into_v2()?,
2661            new_text: new_text.into_v2()?,
2662            meta: meta.into_v2()?,
2663        })
2664    }
2665}
2666
2667impl IntoV1 for super::ToolCallLocation {
2668    type Output = crate::v1::ToolCallLocation;
2669
2670    fn into_v1(self) -> Result<Self::Output> {
2671        let Self { path, line, meta } = self;
2672        Ok(crate::v1::ToolCallLocation {
2673            path: path.into_v1()?,
2674            line: line.into_v1()?,
2675            meta: meta.into_v1()?,
2676        })
2677    }
2678}
2679
2680impl IntoV2 for crate::v1::ToolCallLocation {
2681    type Output = super::ToolCallLocation;
2682
2683    fn into_v2(self) -> Result<Self::Output> {
2684        let Self { path, line, meta } = self;
2685        Ok(super::ToolCallLocation {
2686            path: path.into_v2()?,
2687            line: line.into_v2()?,
2688            meta: meta.into_v2()?,
2689        })
2690    }
2691}
2692
2693impl IntoV1 for super::InitializeRequest {
2694    type Output = crate::v1::InitializeRequest;
2695
2696    fn into_v1(self) -> Result<Self::Output> {
2697        let Self {
2698            protocol_version,
2699            capabilities,
2700            client_info,
2701            meta,
2702        } = self;
2703        Ok(crate::v1::InitializeRequest {
2704            protocol_version: protocol_version.into_v1()?,
2705            client_capabilities: capabilities.into_v1()?,
2706            client_info: into_v1_default_on_error(client_info),
2707            meta: meta.into_v1()?,
2708        })
2709    }
2710}
2711
2712impl IntoV2 for crate::v1::InitializeRequest {
2713    type Output = super::InitializeRequest;
2714
2715    fn into_v2(self) -> Result<Self::Output> {
2716        let Self {
2717            protocol_version,
2718            client_capabilities,
2719            client_info,
2720            meta,
2721        } = self;
2722        Ok(super::InitializeRequest {
2723            protocol_version: protocol_version.into_v2()?,
2724            capabilities: client_capabilities.into_v2()?,
2725            client_info: into_v2_default_on_error(client_info),
2726            meta: meta.into_v2()?,
2727        })
2728    }
2729}
2730
2731impl IntoV1 for super::InitializeResponse {
2732    type Output = crate::v1::InitializeResponse;
2733
2734    fn into_v1(self) -> Result<Self::Output> {
2735        let Self {
2736            protocol_version,
2737            capabilities: agent_capabilities,
2738            auth_methods,
2739            agent_info,
2740            meta,
2741        } = self;
2742        Ok(crate::v1::InitializeResponse {
2743            protocol_version: protocol_version.into_v1()?,
2744            agent_capabilities: agent_capabilities.into_v1()?,
2745            auth_methods: into_v1_vec_skip_errors(auth_methods),
2746            agent_info: into_v1_default_on_error(agent_info),
2747            meta: meta.into_v1()?,
2748        })
2749    }
2750}
2751
2752impl IntoV2 for crate::v1::InitializeResponse {
2753    type Output = super::InitializeResponse;
2754
2755    fn into_v2(self) -> Result<Self::Output> {
2756        let Self {
2757            protocol_version,
2758            agent_capabilities,
2759            auth_methods,
2760            agent_info,
2761            meta,
2762        } = self;
2763        Ok(super::InitializeResponse {
2764            protocol_version: protocol_version.into_v2()?,
2765            capabilities: agent_capabilities.into_v2()?,
2766            auth_methods: into_v2_vec_skip_errors(auth_methods),
2767            agent_info: into_v2_default_on_error(agent_info),
2768            meta: meta.into_v2()?,
2769        })
2770    }
2771}
2772
2773impl IntoV1 for super::Implementation {
2774    type Output = crate::v1::Implementation;
2775
2776    fn into_v1(self) -> Result<Self::Output> {
2777        let Self {
2778            name,
2779            title,
2780            version,
2781            meta,
2782        } = self;
2783        Ok(crate::v1::Implementation {
2784            name: name.into_v1()?,
2785            title: title.into_v1()?,
2786            version: version.into_v1()?,
2787            meta: meta.into_v1()?,
2788        })
2789    }
2790}
2791
2792impl IntoV2 for crate::v1::Implementation {
2793    type Output = super::Implementation;
2794
2795    fn into_v2(self) -> Result<Self::Output> {
2796        let Self {
2797            name,
2798            title,
2799            version,
2800            meta,
2801        } = self;
2802        Ok(super::Implementation {
2803            name: name.into_v2()?,
2804            title: title.into_v2()?,
2805            version: version.into_v2()?,
2806            meta: meta.into_v2()?,
2807        })
2808    }
2809}
2810
2811impl IntoV1 for super::AuthenticateRequest {
2812    type Output = crate::v1::AuthenticateRequest;
2813
2814    fn into_v1(self) -> Result<Self::Output> {
2815        let Self { method_id, meta } = self;
2816        Ok(crate::v1::AuthenticateRequest {
2817            method_id: method_id.into_v1()?,
2818            meta: meta.into_v1()?,
2819        })
2820    }
2821}
2822
2823impl IntoV2 for crate::v1::AuthenticateRequest {
2824    type Output = super::AuthenticateRequest;
2825
2826    fn into_v2(self) -> Result<Self::Output> {
2827        let Self { method_id, meta } = self;
2828        Ok(super::AuthenticateRequest {
2829            method_id: method_id.into_v2()?,
2830            meta: meta.into_v2()?,
2831        })
2832    }
2833}
2834
2835impl IntoV1 for super::AuthenticateResponse {
2836    type Output = crate::v1::AuthenticateResponse;
2837
2838    fn into_v1(self) -> Result<Self::Output> {
2839        let Self { meta } = self;
2840        Ok(crate::v1::AuthenticateResponse {
2841            meta: meta.into_v1()?,
2842        })
2843    }
2844}
2845
2846impl IntoV2 for crate::v1::AuthenticateResponse {
2847    type Output = super::AuthenticateResponse;
2848
2849    fn into_v2(self) -> Result<Self::Output> {
2850        let Self { meta } = self;
2851        Ok(super::AuthenticateResponse {
2852            meta: meta.into_v2()?,
2853        })
2854    }
2855}
2856
2857impl IntoV1 for super::LogoutRequest {
2858    type Output = crate::v1::LogoutRequest;
2859
2860    fn into_v1(self) -> Result<Self::Output> {
2861        let Self { meta } = self;
2862        Ok(crate::v1::LogoutRequest {
2863            meta: meta.into_v1()?,
2864        })
2865    }
2866}
2867
2868impl IntoV2 for crate::v1::LogoutRequest {
2869    type Output = super::LogoutRequest;
2870
2871    fn into_v2(self) -> Result<Self::Output> {
2872        let Self { meta } = self;
2873        Ok(super::LogoutRequest {
2874            meta: meta.into_v2()?,
2875        })
2876    }
2877}
2878
2879impl IntoV1 for super::LogoutResponse {
2880    type Output = crate::v1::LogoutResponse;
2881
2882    fn into_v1(self) -> Result<Self::Output> {
2883        let Self { meta } = self;
2884        Ok(crate::v1::LogoutResponse {
2885            meta: meta.into_v1()?,
2886        })
2887    }
2888}
2889
2890impl IntoV2 for crate::v1::LogoutResponse {
2891    type Output = super::LogoutResponse;
2892
2893    fn into_v2(self) -> Result<Self::Output> {
2894        let Self { meta } = self;
2895        Ok(super::LogoutResponse {
2896            meta: meta.into_v2()?,
2897        })
2898    }
2899}
2900
2901impl IntoV1 for super::AgentAuthCapabilities {
2902    type Output = crate::v1::AgentAuthCapabilities;
2903
2904    fn into_v1(self) -> Result<Self::Output> {
2905        let Self { logout, meta } = self;
2906        Ok(crate::v1::AgentAuthCapabilities {
2907            logout: into_v1_default_on_error(logout),
2908            meta: meta.into_v1()?,
2909        })
2910    }
2911}
2912
2913impl IntoV2 for crate::v1::AgentAuthCapabilities {
2914    type Output = super::AgentAuthCapabilities;
2915
2916    fn into_v2(self) -> Result<Self::Output> {
2917        let Self { logout, meta } = self;
2918        Ok(super::AgentAuthCapabilities {
2919            logout: into_v2_default_on_error(logout),
2920            meta: meta.into_v2()?,
2921        })
2922    }
2923}
2924
2925impl IntoV1 for super::LogoutCapabilities {
2926    type Output = crate::v1::LogoutCapabilities;
2927
2928    fn into_v1(self) -> Result<Self::Output> {
2929        let Self { meta } = self;
2930        Ok(crate::v1::LogoutCapabilities {
2931            meta: meta.into_v1()?,
2932        })
2933    }
2934}
2935
2936impl IntoV2 for crate::v1::LogoutCapabilities {
2937    type Output = super::LogoutCapabilities;
2938
2939    fn into_v2(self) -> Result<Self::Output> {
2940        let Self { meta } = self;
2941        Ok(super::LogoutCapabilities {
2942            meta: meta.into_v2()?,
2943        })
2944    }
2945}
2946
2947impl IntoV1 for super::AuthMethodId {
2948    type Output = crate::v1::AuthMethodId;
2949
2950    fn into_v1(self) -> Result<Self::Output> {
2951        Ok(crate::v1::AuthMethodId(self.0.into_v1()?))
2952    }
2953}
2954
2955impl IntoV2 for crate::v1::AuthMethodId {
2956    type Output = super::AuthMethodId;
2957
2958    fn into_v2(self) -> Result<Self::Output> {
2959        Ok(super::AuthMethodId(self.0.into_v2()?))
2960    }
2961}
2962
2963impl IntoV1 for super::AuthMethod {
2964    type Output = crate::v1::AuthMethod;
2965
2966    fn into_v1(self) -> Result<Self::Output> {
2967        Ok(match self {
2968            #[cfg(feature = "unstable_auth_methods")]
2969            Self::EnvVar(value) => crate::v1::AuthMethod::EnvVar(value.into_v1()?),
2970            #[cfg(feature = "unstable_auth_methods")]
2971            Self::Terminal(value) => crate::v1::AuthMethod::Terminal(value.into_v1()?),
2972            Self::Other(value) => {
2973                return Err(unknown_v2_enum_variant("AuthMethod", &value.type_));
2974            }
2975            Self::Agent(value) => crate::v1::AuthMethod::Agent(value.into_v1()?),
2976        })
2977    }
2978}
2979
2980impl IntoV2 for crate::v1::AuthMethod {
2981    type Output = super::AuthMethod;
2982
2983    fn into_v2(self) -> Result<Self::Output> {
2984        Ok(match self {
2985            #[cfg(feature = "unstable_auth_methods")]
2986            Self::EnvVar(value) => super::AuthMethod::EnvVar(value.into_v2()?),
2987            #[cfg(feature = "unstable_auth_methods")]
2988            Self::Terminal(value) => super::AuthMethod::Terminal(value.into_v2()?),
2989            Self::Agent(value) => super::AuthMethod::Agent(value.into_v2()?),
2990        })
2991    }
2992}
2993
2994impl IntoV1 for super::AuthMethodAgent {
2995    type Output = crate::v1::AuthMethodAgent;
2996
2997    fn into_v1(self) -> Result<Self::Output> {
2998        let Self {
2999            id,
3000            name,
3001            description,
3002            meta,
3003        } = self;
3004        Ok(crate::v1::AuthMethodAgent {
3005            id: id.into_v1()?,
3006            name: name.into_v1()?,
3007            description: description.into_v1()?,
3008            meta: meta.into_v1()?,
3009        })
3010    }
3011}
3012
3013impl IntoV2 for crate::v1::AuthMethodAgent {
3014    type Output = super::AuthMethodAgent;
3015
3016    fn into_v2(self) -> Result<Self::Output> {
3017        let Self {
3018            id,
3019            name,
3020            description,
3021            meta,
3022        } = self;
3023        Ok(super::AuthMethodAgent {
3024            id: id.into_v2()?,
3025            name: name.into_v2()?,
3026            description: description.into_v2()?,
3027            meta: meta.into_v2()?,
3028        })
3029    }
3030}
3031
3032#[cfg(feature = "unstable_auth_methods")]
3033impl IntoV1 for super::AuthMethodEnvVar {
3034    type Output = crate::v1::AuthMethodEnvVar;
3035
3036    fn into_v1(self) -> Result<Self::Output> {
3037        let Self {
3038            id,
3039            name,
3040            description,
3041            vars,
3042            link,
3043            meta,
3044        } = self;
3045        Ok(crate::v1::AuthMethodEnvVar {
3046            id: id.into_v1()?,
3047            name: name.into_v1()?,
3048            description: description.into_v1()?,
3049            vars: vars.into_v1()?,
3050            link: link.into_v1()?,
3051            meta: meta.into_v1()?,
3052        })
3053    }
3054}
3055
3056#[cfg(feature = "unstable_auth_methods")]
3057impl IntoV2 for crate::v1::AuthMethodEnvVar {
3058    type Output = super::AuthMethodEnvVar;
3059
3060    fn into_v2(self) -> Result<Self::Output> {
3061        let Self {
3062            id,
3063            name,
3064            description,
3065            vars,
3066            link,
3067            meta,
3068        } = self;
3069        Ok(super::AuthMethodEnvVar {
3070            id: id.into_v2()?,
3071            name: name.into_v2()?,
3072            description: description.into_v2()?,
3073            vars: vars.into_v2()?,
3074            link: link.into_v2()?,
3075            meta: meta.into_v2()?,
3076        })
3077    }
3078}
3079
3080#[cfg(feature = "unstable_auth_methods")]
3081impl IntoV1 for super::AuthEnvVar {
3082    type Output = crate::v1::AuthEnvVar;
3083
3084    fn into_v1(self) -> Result<Self::Output> {
3085        let Self {
3086            name,
3087            label,
3088            secret,
3089            optional,
3090            meta,
3091        } = self;
3092        Ok(crate::v1::AuthEnvVar {
3093            name: name.into_v1()?,
3094            label: label.into_v1()?,
3095            secret: secret.into_v1()?,
3096            optional: optional.into_v1()?,
3097            meta: meta.into_v1()?,
3098        })
3099    }
3100}
3101
3102#[cfg(feature = "unstable_auth_methods")]
3103impl IntoV2 for crate::v1::AuthEnvVar {
3104    type Output = super::AuthEnvVar;
3105
3106    fn into_v2(self) -> Result<Self::Output> {
3107        let Self {
3108            name,
3109            label,
3110            secret,
3111            optional,
3112            meta,
3113        } = self;
3114        Ok(super::AuthEnvVar {
3115            name: name.into_v2()?,
3116            label: label.into_v2()?,
3117            secret: secret.into_v2()?,
3118            optional: optional.into_v2()?,
3119            meta: meta.into_v2()?,
3120        })
3121    }
3122}
3123
3124#[cfg(feature = "unstable_auth_methods")]
3125impl IntoV1 for super::AuthMethodTerminal {
3126    type Output = crate::v1::AuthMethodTerminal;
3127
3128    fn into_v1(self) -> Result<Self::Output> {
3129        let Self {
3130            id,
3131            name,
3132            description,
3133            args,
3134            env,
3135            meta,
3136        } = self;
3137        Ok(crate::v1::AuthMethodTerminal {
3138            id: id.into_v1()?,
3139            name: name.into_v1()?,
3140            description: description.into_v1()?,
3141            args: args.into_v1()?,
3142            env: env.into_v1()?,
3143            meta: meta.into_v1()?,
3144        })
3145    }
3146}
3147
3148#[cfg(feature = "unstable_auth_methods")]
3149impl IntoV2 for crate::v1::AuthMethodTerminal {
3150    type Output = super::AuthMethodTerminal;
3151
3152    fn into_v2(self) -> Result<Self::Output> {
3153        let Self {
3154            id,
3155            name,
3156            description,
3157            args,
3158            env,
3159            meta,
3160        } = self;
3161        Ok(super::AuthMethodTerminal {
3162            id: id.into_v2()?,
3163            name: name.into_v2()?,
3164            description: description.into_v2()?,
3165            args: args.into_v2()?,
3166            env: env.into_v2()?,
3167            meta: meta.into_v2()?,
3168        })
3169    }
3170}
3171
3172impl IntoV1 for super::NewSessionRequest {
3173    type Output = crate::v1::NewSessionRequest;
3174
3175    fn into_v1(self) -> Result<Self::Output> {
3176        let Self {
3177            cwd,
3178            additional_directories,
3179            mcp_servers,
3180            meta,
3181        } = self;
3182        Ok(crate::v1::NewSessionRequest {
3183            cwd: cwd.into_v1()?,
3184            additional_directories: additional_directories.into_v1()?,
3185            mcp_servers: mcp_servers.into_v1()?,
3186            meta: meta.into_v1()?,
3187        })
3188    }
3189}
3190
3191impl IntoV2 for crate::v1::NewSessionRequest {
3192    type Output = super::NewSessionRequest;
3193
3194    fn into_v2(self) -> Result<Self::Output> {
3195        let Self {
3196            cwd,
3197            additional_directories,
3198            mcp_servers,
3199            meta,
3200        } = self;
3201        Ok(super::NewSessionRequest {
3202            cwd: cwd.into_v2()?,
3203            additional_directories: additional_directories.into_v2()?,
3204            mcp_servers: mcp_servers.into_v2()?,
3205            meta: meta.into_v2()?,
3206        })
3207    }
3208}
3209
3210impl IntoV1 for super::NewSessionResponse {
3211    type Output = crate::v1::NewSessionResponse;
3212
3213    fn into_v1(self) -> Result<Self::Output> {
3214        let Self {
3215            session_id,
3216            config_options,
3217            meta,
3218        } = self;
3219        Ok(crate::v1::NewSessionResponse {
3220            session_id: session_id.into_v1()?,
3221            modes: None,
3222            config_options: option_vec_into_v1_skip_errors(config_options),
3223            meta: meta.into_v1()?,
3224        })
3225    }
3226}
3227
3228impl IntoV2 for crate::v1::NewSessionResponse {
3229    type Output = super::NewSessionResponse;
3230
3231    fn into_v2(self) -> Result<Self::Output> {
3232        let Self {
3233            session_id,
3234            modes: _,
3235            config_options,
3236            meta,
3237        } = self;
3238        Ok(super::NewSessionResponse {
3239            session_id: session_id.into_v2()?,
3240            config_options: option_vec_into_v2_skip_errors(config_options),
3241            meta: meta.into_v2()?,
3242        })
3243    }
3244}
3245
3246impl IntoV1 for super::LoadSessionRequest {
3247    type Output = crate::v1::LoadSessionRequest;
3248
3249    fn into_v1(self) -> Result<Self::Output> {
3250        let Self {
3251            mcp_servers,
3252            cwd,
3253            additional_directories,
3254            session_id,
3255            meta,
3256        } = self;
3257        Ok(crate::v1::LoadSessionRequest {
3258            mcp_servers: mcp_servers.into_v1()?,
3259            cwd: cwd.into_v1()?,
3260            additional_directories: additional_directories.into_v1()?,
3261            session_id: session_id.into_v1()?,
3262            meta: meta.into_v1()?,
3263        })
3264    }
3265}
3266
3267impl IntoV2 for crate::v1::LoadSessionRequest {
3268    type Output = super::LoadSessionRequest;
3269
3270    fn into_v2(self) -> Result<Self::Output> {
3271        let Self {
3272            mcp_servers,
3273            cwd,
3274            additional_directories,
3275            session_id,
3276            meta,
3277        } = self;
3278        Ok(super::LoadSessionRequest {
3279            mcp_servers: mcp_servers.into_v2()?,
3280            cwd: cwd.into_v2()?,
3281            additional_directories: additional_directories.into_v2()?,
3282            session_id: session_id.into_v2()?,
3283            meta: meta.into_v2()?,
3284        })
3285    }
3286}
3287
3288impl IntoV1 for super::LoadSessionResponse {
3289    type Output = crate::v1::LoadSessionResponse;
3290
3291    fn into_v1(self) -> Result<Self::Output> {
3292        let Self {
3293            config_options,
3294            meta,
3295        } = self;
3296        Ok(crate::v1::LoadSessionResponse {
3297            modes: None,
3298            config_options: option_vec_into_v1_skip_errors(config_options),
3299            meta: meta.into_v1()?,
3300        })
3301    }
3302}
3303
3304impl IntoV2 for crate::v1::LoadSessionResponse {
3305    type Output = super::LoadSessionResponse;
3306
3307    fn into_v2(self) -> Result<Self::Output> {
3308        let Self {
3309            modes: _,
3310            config_options,
3311            meta,
3312        } = self;
3313        Ok(super::LoadSessionResponse {
3314            config_options: option_vec_into_v2_skip_errors(config_options),
3315            meta: meta.into_v2()?,
3316        })
3317    }
3318}
3319
3320#[cfg(feature = "unstable_session_fork")]
3321impl IntoV1 for super::ForkSessionRequest {
3322    type Output = crate::v1::ForkSessionRequest;
3323
3324    fn into_v1(self) -> Result<Self::Output> {
3325        let Self {
3326            session_id,
3327            cwd,
3328            additional_directories,
3329            mcp_servers,
3330            meta,
3331        } = self;
3332        Ok(crate::v1::ForkSessionRequest {
3333            session_id: session_id.into_v1()?,
3334            cwd: cwd.into_v1()?,
3335            additional_directories: additional_directories.into_v1()?,
3336            mcp_servers: mcp_servers.into_v1()?,
3337            meta: meta.into_v1()?,
3338        })
3339    }
3340}
3341
3342#[cfg(feature = "unstable_session_fork")]
3343impl IntoV2 for crate::v1::ForkSessionRequest {
3344    type Output = super::ForkSessionRequest;
3345
3346    fn into_v2(self) -> Result<Self::Output> {
3347        let Self {
3348            session_id,
3349            cwd,
3350            additional_directories,
3351            mcp_servers,
3352            meta,
3353        } = self;
3354        Ok(super::ForkSessionRequest {
3355            session_id: session_id.into_v2()?,
3356            cwd: cwd.into_v2()?,
3357            additional_directories: additional_directories.into_v2()?,
3358            mcp_servers: mcp_servers.into_v2()?,
3359            meta: meta.into_v2()?,
3360        })
3361    }
3362}
3363
3364#[cfg(feature = "unstable_session_fork")]
3365impl IntoV1 for super::ForkSessionResponse {
3366    type Output = crate::v1::ForkSessionResponse;
3367
3368    fn into_v1(self) -> Result<Self::Output> {
3369        let Self {
3370            session_id,
3371            config_options,
3372            meta,
3373        } = self;
3374        Ok(crate::v1::ForkSessionResponse {
3375            session_id: session_id.into_v1()?,
3376            modes: None,
3377            config_options: option_vec_into_v1_skip_errors(config_options),
3378            meta: meta.into_v1()?,
3379        })
3380    }
3381}
3382
3383#[cfg(feature = "unstable_session_fork")]
3384impl IntoV2 for crate::v1::ForkSessionResponse {
3385    type Output = super::ForkSessionResponse;
3386
3387    fn into_v2(self) -> Result<Self::Output> {
3388        let Self {
3389            session_id,
3390            modes: _,
3391            config_options,
3392            meta,
3393        } = self;
3394        Ok(super::ForkSessionResponse {
3395            session_id: session_id.into_v2()?,
3396            config_options: option_vec_into_v2_skip_errors(config_options),
3397            meta: meta.into_v2()?,
3398        })
3399    }
3400}
3401
3402impl IntoV1 for super::ResumeSessionRequest {
3403    type Output = crate::v1::ResumeSessionRequest;
3404
3405    fn into_v1(self) -> Result<Self::Output> {
3406        let Self {
3407            session_id,
3408            cwd,
3409            additional_directories,
3410            mcp_servers,
3411            meta,
3412        } = self;
3413        Ok(crate::v1::ResumeSessionRequest {
3414            session_id: session_id.into_v1()?,
3415            cwd: cwd.into_v1()?,
3416            additional_directories: additional_directories.into_v1()?,
3417            mcp_servers: mcp_servers.into_v1()?,
3418            meta: meta.into_v1()?,
3419        })
3420    }
3421}
3422
3423impl IntoV2 for crate::v1::ResumeSessionRequest {
3424    type Output = super::ResumeSessionRequest;
3425
3426    fn into_v2(self) -> Result<Self::Output> {
3427        let Self {
3428            session_id,
3429            cwd,
3430            additional_directories,
3431            mcp_servers,
3432            meta,
3433        } = self;
3434        Ok(super::ResumeSessionRequest {
3435            session_id: session_id.into_v2()?,
3436            cwd: cwd.into_v2()?,
3437            additional_directories: additional_directories.into_v2()?,
3438            mcp_servers: mcp_servers.into_v2()?,
3439            meta: meta.into_v2()?,
3440        })
3441    }
3442}
3443
3444impl IntoV1 for super::ResumeSessionResponse {
3445    type Output = crate::v1::ResumeSessionResponse;
3446
3447    fn into_v1(self) -> Result<Self::Output> {
3448        let Self {
3449            config_options,
3450            meta,
3451        } = self;
3452        Ok(crate::v1::ResumeSessionResponse {
3453            modes: None,
3454            config_options: option_vec_into_v1_skip_errors(config_options),
3455            meta: meta.into_v1()?,
3456        })
3457    }
3458}
3459
3460impl IntoV2 for crate::v1::ResumeSessionResponse {
3461    type Output = super::ResumeSessionResponse;
3462
3463    fn into_v2(self) -> Result<Self::Output> {
3464        let Self {
3465            modes: _,
3466            config_options,
3467            meta,
3468        } = self;
3469        Ok(super::ResumeSessionResponse {
3470            config_options: option_vec_into_v2_skip_errors(config_options),
3471            meta: meta.into_v2()?,
3472        })
3473    }
3474}
3475
3476impl IntoV1 for super::CloseSessionRequest {
3477    type Output = crate::v1::CloseSessionRequest;
3478
3479    fn into_v1(self) -> Result<Self::Output> {
3480        let Self { session_id, meta } = self;
3481        Ok(crate::v1::CloseSessionRequest {
3482            session_id: session_id.into_v1()?,
3483            meta: meta.into_v1()?,
3484        })
3485    }
3486}
3487
3488impl IntoV2 for crate::v1::CloseSessionRequest {
3489    type Output = super::CloseSessionRequest;
3490
3491    fn into_v2(self) -> Result<Self::Output> {
3492        let Self { session_id, meta } = self;
3493        Ok(super::CloseSessionRequest {
3494            session_id: session_id.into_v2()?,
3495            meta: meta.into_v2()?,
3496        })
3497    }
3498}
3499
3500impl IntoV1 for super::CloseSessionResponse {
3501    type Output = crate::v1::CloseSessionResponse;
3502
3503    fn into_v1(self) -> Result<Self::Output> {
3504        let Self { meta } = self;
3505        Ok(crate::v1::CloseSessionResponse {
3506            meta: meta.into_v1()?,
3507        })
3508    }
3509}
3510
3511impl IntoV2 for crate::v1::CloseSessionResponse {
3512    type Output = super::CloseSessionResponse;
3513
3514    fn into_v2(self) -> Result<Self::Output> {
3515        let Self { meta } = self;
3516        Ok(super::CloseSessionResponse {
3517            meta: meta.into_v2()?,
3518        })
3519    }
3520}
3521
3522impl IntoV1 for super::DeleteSessionRequest {
3523    type Output = crate::v1::DeleteSessionRequest;
3524
3525    fn into_v1(self) -> Result<Self::Output> {
3526        let Self { session_id, meta } = self;
3527        Ok(crate::v1::DeleteSessionRequest {
3528            session_id: session_id.into_v1()?,
3529            meta: meta.into_v1()?,
3530        })
3531    }
3532}
3533
3534impl IntoV2 for crate::v1::DeleteSessionRequest {
3535    type Output = super::DeleteSessionRequest;
3536
3537    fn into_v2(self) -> Result<Self::Output> {
3538        let Self { session_id, meta } = self;
3539        Ok(super::DeleteSessionRequest {
3540            session_id: session_id.into_v2()?,
3541            meta: meta.into_v2()?,
3542        })
3543    }
3544}
3545
3546impl IntoV1 for super::DeleteSessionResponse {
3547    type Output = crate::v1::DeleteSessionResponse;
3548
3549    fn into_v1(self) -> Result<Self::Output> {
3550        let Self { meta } = self;
3551        Ok(crate::v1::DeleteSessionResponse {
3552            meta: meta.into_v1()?,
3553        })
3554    }
3555}
3556
3557impl IntoV2 for crate::v1::DeleteSessionResponse {
3558    type Output = super::DeleteSessionResponse;
3559
3560    fn into_v2(self) -> Result<Self::Output> {
3561        let Self { meta } = self;
3562        Ok(super::DeleteSessionResponse {
3563            meta: meta.into_v2()?,
3564        })
3565    }
3566}
3567
3568impl IntoV1 for super::ListSessionsRequest {
3569    type Output = crate::v1::ListSessionsRequest;
3570
3571    fn into_v1(self) -> Result<Self::Output> {
3572        let Self { cwd, cursor, meta } = self;
3573        Ok(crate::v1::ListSessionsRequest {
3574            cwd: cwd.into_v1()?,
3575            cursor: cursor.into_v1()?,
3576            meta: meta.into_v1()?,
3577        })
3578    }
3579}
3580
3581impl IntoV2 for crate::v1::ListSessionsRequest {
3582    type Output = super::ListSessionsRequest;
3583
3584    fn into_v2(self) -> Result<Self::Output> {
3585        let Self { cwd, cursor, meta } = self;
3586        Ok(super::ListSessionsRequest {
3587            cwd: cwd.into_v2()?,
3588            cursor: cursor.into_v2()?,
3589            meta: meta.into_v2()?,
3590        })
3591    }
3592}
3593
3594impl IntoV1 for super::ListSessionsResponse {
3595    type Output = crate::v1::ListSessionsResponse;
3596
3597    fn into_v1(self) -> Result<Self::Output> {
3598        let Self {
3599            sessions,
3600            next_cursor,
3601            meta,
3602        } = self;
3603        Ok(crate::v1::ListSessionsResponse {
3604            sessions: into_v1_vec_skip_errors(sessions),
3605            next_cursor: next_cursor.into_v1()?,
3606            meta: meta.into_v1()?,
3607        })
3608    }
3609}
3610
3611impl IntoV2 for crate::v1::ListSessionsResponse {
3612    type Output = super::ListSessionsResponse;
3613
3614    fn into_v2(self) -> Result<Self::Output> {
3615        let Self {
3616            sessions,
3617            next_cursor,
3618            meta,
3619        } = self;
3620        Ok(super::ListSessionsResponse {
3621            sessions: into_v2_vec_skip_errors(sessions),
3622            next_cursor: next_cursor.into_v2()?,
3623            meta: meta.into_v2()?,
3624        })
3625    }
3626}
3627
3628impl IntoV1 for super::SessionInfo {
3629    type Output = crate::v1::SessionInfo;
3630
3631    fn into_v1(self) -> Result<Self::Output> {
3632        let Self {
3633            session_id,
3634            cwd,
3635            additional_directories,
3636            title,
3637            updated_at,
3638            meta,
3639        } = self;
3640        Ok(crate::v1::SessionInfo {
3641            session_id: session_id.into_v1()?,
3642            cwd: cwd.into_v1()?,
3643            additional_directories: additional_directories.into_v1()?,
3644            title: into_v1_default_on_error(title),
3645            updated_at: into_v1_default_on_error(updated_at),
3646            meta: meta.into_v1()?,
3647        })
3648    }
3649}
3650
3651impl IntoV2 for crate::v1::SessionInfo {
3652    type Output = super::SessionInfo;
3653
3654    fn into_v2(self) -> Result<Self::Output> {
3655        let Self {
3656            session_id,
3657            cwd,
3658            additional_directories,
3659            title,
3660            updated_at,
3661            meta,
3662        } = self;
3663        Ok(super::SessionInfo {
3664            session_id: session_id.into_v2()?,
3665            cwd: cwd.into_v2()?,
3666            additional_directories: additional_directories.into_v2()?,
3667            title: into_v2_default_on_error(title),
3668            updated_at: into_v2_default_on_error(updated_at),
3669            meta: meta.into_v2()?,
3670        })
3671    }
3672}
3673
3674impl IntoV1 for super::SessionConfigId {
3675    type Output = crate::v1::SessionConfigId;
3676
3677    fn into_v1(self) -> Result<Self::Output> {
3678        Ok(crate::v1::SessionConfigId(self.0.into_v1()?))
3679    }
3680}
3681
3682impl IntoV2 for crate::v1::SessionConfigId {
3683    type Output = super::SessionConfigId;
3684
3685    fn into_v2(self) -> Result<Self::Output> {
3686        Ok(super::SessionConfigId(self.0.into_v2()?))
3687    }
3688}
3689
3690impl IntoV1 for super::SessionConfigValueId {
3691    type Output = crate::v1::SessionConfigValueId;
3692
3693    fn into_v1(self) -> Result<Self::Output> {
3694        Ok(crate::v1::SessionConfigValueId(self.0.into_v1()?))
3695    }
3696}
3697
3698impl IntoV2 for crate::v1::SessionConfigValueId {
3699    type Output = super::SessionConfigValueId;
3700
3701    fn into_v2(self) -> Result<Self::Output> {
3702        Ok(super::SessionConfigValueId(self.0.into_v2()?))
3703    }
3704}
3705
3706impl IntoV1 for super::SessionConfigGroupId {
3707    type Output = crate::v1::SessionConfigGroupId;
3708
3709    fn into_v1(self) -> Result<Self::Output> {
3710        Ok(crate::v1::SessionConfigGroupId(self.0.into_v1()?))
3711    }
3712}
3713
3714impl IntoV2 for crate::v1::SessionConfigGroupId {
3715    type Output = super::SessionConfigGroupId;
3716
3717    fn into_v2(self) -> Result<Self::Output> {
3718        Ok(super::SessionConfigGroupId(self.0.into_v2()?))
3719    }
3720}
3721
3722impl IntoV1 for super::SessionConfigSelectOption {
3723    type Output = crate::v1::SessionConfigSelectOption;
3724
3725    fn into_v1(self) -> Result<Self::Output> {
3726        let Self {
3727            value,
3728            name,
3729            description,
3730            meta,
3731        } = self;
3732        Ok(crate::v1::SessionConfigSelectOption {
3733            value: value.into_v1()?,
3734            name: name.into_v1()?,
3735            description: description.into_v1()?,
3736            meta: meta.into_v1()?,
3737        })
3738    }
3739}
3740
3741impl IntoV2 for crate::v1::SessionConfigSelectOption {
3742    type Output = super::SessionConfigSelectOption;
3743
3744    fn into_v2(self) -> Result<Self::Output> {
3745        let Self {
3746            value,
3747            name,
3748            description,
3749            meta,
3750        } = self;
3751        Ok(super::SessionConfigSelectOption {
3752            value: value.into_v2()?,
3753            name: name.into_v2()?,
3754            description: description.into_v2()?,
3755            meta: meta.into_v2()?,
3756        })
3757    }
3758}
3759
3760impl IntoV1 for super::SessionConfigSelectGroup {
3761    type Output = crate::v1::SessionConfigSelectGroup;
3762
3763    fn into_v1(self) -> Result<Self::Output> {
3764        let Self {
3765            group,
3766            name,
3767            options,
3768            meta,
3769        } = self;
3770        Ok(crate::v1::SessionConfigSelectGroup {
3771            group: group.into_v1()?,
3772            name: name.into_v1()?,
3773            options: options.into_v1()?,
3774            meta: meta.into_v1()?,
3775        })
3776    }
3777}
3778
3779impl IntoV2 for crate::v1::SessionConfigSelectGroup {
3780    type Output = super::SessionConfigSelectGroup;
3781
3782    fn into_v2(self) -> Result<Self::Output> {
3783        let Self {
3784            group,
3785            name,
3786            options,
3787            meta,
3788        } = self;
3789        Ok(super::SessionConfigSelectGroup {
3790            group: group.into_v2()?,
3791            name: name.into_v2()?,
3792            options: options.into_v2()?,
3793            meta: meta.into_v2()?,
3794        })
3795    }
3796}
3797
3798impl IntoV1 for super::SessionConfigSelectOptions {
3799    type Output = crate::v1::SessionConfigSelectOptions;
3800
3801    fn into_v1(self) -> Result<Self::Output> {
3802        Ok(match self {
3803            Self::Ungrouped(value) => {
3804                crate::v1::SessionConfigSelectOptions::Ungrouped(value.into_v1()?)
3805            }
3806            Self::Grouped(value) => {
3807                crate::v1::SessionConfigSelectOptions::Grouped(value.into_v1()?)
3808            }
3809        })
3810    }
3811}
3812
3813impl IntoV2 for crate::v1::SessionConfigSelectOptions {
3814    type Output = super::SessionConfigSelectOptions;
3815
3816    fn into_v2(self) -> Result<Self::Output> {
3817        Ok(match self {
3818            Self::Ungrouped(value) => {
3819                super::SessionConfigSelectOptions::Ungrouped(value.into_v2()?)
3820            }
3821            Self::Grouped(value) => super::SessionConfigSelectOptions::Grouped(value.into_v2()?),
3822        })
3823    }
3824}
3825
3826impl IntoV1 for super::SessionConfigSelect {
3827    type Output = crate::v1::SessionConfigSelect;
3828
3829    fn into_v1(self) -> Result<Self::Output> {
3830        let Self {
3831            current_value,
3832            options,
3833        } = self;
3834        Ok(crate::v1::SessionConfigSelect {
3835            current_value: current_value.into_v1()?,
3836            options: options.into_v1()?,
3837        })
3838    }
3839}
3840
3841impl IntoV2 for crate::v1::SessionConfigSelect {
3842    type Output = super::SessionConfigSelect;
3843
3844    fn into_v2(self) -> Result<Self::Output> {
3845        let Self {
3846            current_value,
3847            options,
3848        } = self;
3849        Ok(super::SessionConfigSelect {
3850            current_value: current_value.into_v2()?,
3851            options: options.into_v2()?,
3852        })
3853    }
3854}
3855
3856#[cfg(feature = "unstable_boolean_config")]
3857impl IntoV1 for super::SessionConfigBoolean {
3858    type Output = crate::v1::SessionConfigBoolean;
3859
3860    fn into_v1(self) -> Result<Self::Output> {
3861        let Self { current_value } = self;
3862        Ok(crate::v1::SessionConfigBoolean {
3863            current_value: current_value.into_v1()?,
3864        })
3865    }
3866}
3867
3868#[cfg(feature = "unstable_boolean_config")]
3869impl IntoV2 for crate::v1::SessionConfigBoolean {
3870    type Output = super::SessionConfigBoolean;
3871
3872    fn into_v2(self) -> Result<Self::Output> {
3873        let Self { current_value } = self;
3874        Ok(super::SessionConfigBoolean {
3875            current_value: current_value.into_v2()?,
3876        })
3877    }
3878}
3879
3880impl IntoV1 for super::SessionConfigOptionCategory {
3881    type Output = crate::v1::SessionConfigOptionCategory;
3882
3883    fn into_v1(self) -> Result<Self::Output> {
3884        Ok(match self {
3885            Self::Mode => crate::v1::SessionConfigOptionCategory::Mode,
3886            Self::Model => crate::v1::SessionConfigOptionCategory::Model,
3887            #[cfg(feature = "unstable_model_config_category")]
3888            Self::ModelConfig => crate::v1::SessionConfigOptionCategory::ModelConfig,
3889            Self::ThoughtLevel => crate::v1::SessionConfigOptionCategory::ThoughtLevel,
3890            Self::Other(value) => crate::v1::SessionConfigOptionCategory::Other(value.into_v1()?),
3891        })
3892    }
3893}
3894
3895impl IntoV2 for crate::v1::SessionConfigOptionCategory {
3896    type Output = super::SessionConfigOptionCategory;
3897
3898    fn into_v2(self) -> Result<Self::Output> {
3899        Ok(match self {
3900            Self::Mode => super::SessionConfigOptionCategory::Mode,
3901            Self::Model => super::SessionConfigOptionCategory::Model,
3902            #[cfg(feature = "unstable_model_config_category")]
3903            Self::ModelConfig => super::SessionConfigOptionCategory::ModelConfig,
3904            Self::ThoughtLevel => super::SessionConfigOptionCategory::ThoughtLevel,
3905            Self::Other(value) => super::SessionConfigOptionCategory::Other(value.into_v2()?),
3906        })
3907    }
3908}
3909
3910impl IntoV1 for super::SessionConfigKind {
3911    type Output = crate::v1::SessionConfigKind;
3912
3913    fn into_v1(self) -> Result<Self::Output> {
3914        Ok(match self {
3915            Self::Select(value) => crate::v1::SessionConfigKind::Select(value.into_v1()?),
3916            #[cfg(feature = "unstable_boolean_config")]
3917            Self::Boolean(value) => crate::v1::SessionConfigKind::Boolean(value.into_v1()?),
3918            Self::Other(value) => {
3919                return Err(unknown_v2_enum_variant("SessionConfigKind", &value.type_));
3920            }
3921        })
3922    }
3923}
3924
3925impl IntoV2 for crate::v1::SessionConfigKind {
3926    type Output = super::SessionConfigKind;
3927
3928    fn into_v2(self) -> Result<Self::Output> {
3929        Ok(match self {
3930            Self::Select(value) => super::SessionConfigKind::Select(value.into_v2()?),
3931            #[cfg(feature = "unstable_boolean_config")]
3932            Self::Boolean(value) => super::SessionConfigKind::Boolean(value.into_v2()?),
3933        })
3934    }
3935}
3936
3937impl IntoV1 for super::SessionConfigOption {
3938    type Output = crate::v1::SessionConfigOption;
3939
3940    fn into_v1(self) -> Result<Self::Output> {
3941        let Self {
3942            id,
3943            name,
3944            description,
3945            category,
3946            kind,
3947            meta,
3948        } = self;
3949        Ok(crate::v1::SessionConfigOption {
3950            id: id.into_v1()?,
3951            name: name.into_v1()?,
3952            description: description.into_v1()?,
3953            category: into_v1_default_on_error(category),
3954            kind: kind.into_v1()?,
3955            meta: meta.into_v1()?,
3956        })
3957    }
3958}
3959
3960impl IntoV2 for crate::v1::SessionConfigOption {
3961    type Output = super::SessionConfigOption;
3962
3963    fn into_v2(self) -> Result<Self::Output> {
3964        let Self {
3965            id,
3966            name,
3967            description,
3968            category,
3969            kind,
3970            meta,
3971        } = self;
3972        Ok(super::SessionConfigOption {
3973            id: id.into_v2()?,
3974            name: name.into_v2()?,
3975            description: description.into_v2()?,
3976            category: into_v2_default_on_error(category),
3977            kind: kind.into_v2()?,
3978            meta: meta.into_v2()?,
3979        })
3980    }
3981}
3982
3983#[cfg(feature = "unstable_boolean_config")]
3984impl IntoV1 for super::SessionConfigOptionValue {
3985    type Output = crate::v1::SessionConfigOptionValue;
3986
3987    fn into_v1(self) -> Result<Self::Output> {
3988        Ok(match self {
3989            Self::Boolean { value } => crate::v1::SessionConfigOptionValue::Boolean {
3990                value: value.into_v1()?,
3991            },
3992            Self::ValueId { value } => crate::v1::SessionConfigOptionValue::ValueId {
3993                value: value.into_v1()?,
3994            },
3995        })
3996    }
3997}
3998
3999#[cfg(feature = "unstable_boolean_config")]
4000impl IntoV2 for crate::v1::SessionConfigOptionValue {
4001    type Output = super::SessionConfigOptionValue;
4002
4003    fn into_v2(self) -> Result<Self::Output> {
4004        Ok(match self {
4005            Self::Boolean { value } => super::SessionConfigOptionValue::Boolean {
4006                value: value.into_v2()?,
4007            },
4008            Self::ValueId { value } => super::SessionConfigOptionValue::ValueId {
4009                value: value.into_v2()?,
4010            },
4011        })
4012    }
4013}
4014
4015impl IntoV1 for super::SetSessionConfigOptionRequest {
4016    type Output = crate::v1::SetSessionConfigOptionRequest;
4017
4018    fn into_v1(self) -> Result<Self::Output> {
4019        let Self {
4020            session_id,
4021            config_id,
4022            value,
4023            meta,
4024        } = self;
4025        Ok(crate::v1::SetSessionConfigOptionRequest {
4026            session_id: session_id.into_v1()?,
4027            config_id: config_id.into_v1()?,
4028            value: value.into_v1()?,
4029            meta: meta.into_v1()?,
4030        })
4031    }
4032}
4033
4034impl IntoV2 for crate::v1::SetSessionConfigOptionRequest {
4035    type Output = super::SetSessionConfigOptionRequest;
4036
4037    fn into_v2(self) -> Result<Self::Output> {
4038        let Self {
4039            session_id,
4040            config_id,
4041            value,
4042            meta,
4043        } = self;
4044        Ok(super::SetSessionConfigOptionRequest {
4045            session_id: session_id.into_v2()?,
4046            config_id: config_id.into_v2()?,
4047            value: value.into_v2()?,
4048            meta: meta.into_v2()?,
4049        })
4050    }
4051}
4052
4053impl IntoV1 for super::SetSessionConfigOptionResponse {
4054    type Output = crate::v1::SetSessionConfigOptionResponse;
4055
4056    fn into_v1(self) -> Result<Self::Output> {
4057        let Self {
4058            config_options,
4059            meta,
4060        } = self;
4061        Ok(crate::v1::SetSessionConfigOptionResponse {
4062            config_options: into_v1_vec_skip_errors(config_options),
4063            meta: meta.into_v1()?,
4064        })
4065    }
4066}
4067
4068impl IntoV2 for crate::v1::SetSessionConfigOptionResponse {
4069    type Output = super::SetSessionConfigOptionResponse;
4070
4071    fn into_v2(self) -> Result<Self::Output> {
4072        let Self {
4073            config_options,
4074            meta,
4075        } = self;
4076        Ok(super::SetSessionConfigOptionResponse {
4077            config_options: into_v2_vec_skip_errors(config_options),
4078            meta: meta.into_v2()?,
4079        })
4080    }
4081}
4082
4083impl IntoV1 for super::McpServer {
4084    type Output = crate::v1::McpServer;
4085
4086    fn into_v1(self) -> Result<Self::Output> {
4087        Ok(match self {
4088            Self::Http(value) => crate::v1::McpServer::Http(value.into_v1()?),
4089            #[cfg(feature = "unstable_mcp_over_acp")]
4090            Self::Acp(value) => crate::v1::McpServer::Acp(value.into_v1()?),
4091            Self::Stdio(value) => crate::v1::McpServer::Stdio(value.into_v1()?),
4092            Self::Other(value) => return Err(unknown_v2_enum_variant("McpServer", &value.type_)),
4093        })
4094    }
4095}
4096
4097impl IntoV2 for crate::v1::McpServer {
4098    type Output = super::McpServer;
4099
4100    fn into_v2(self) -> Result<Self::Output> {
4101        Ok(match self {
4102            Self::Http(value) => super::McpServer::Http(value.into_v2()?),
4103            Self::Sse(_) => return Err(removed_v1_enum_variant("McpServer", "sse")),
4104            #[cfg(feature = "unstable_mcp_over_acp")]
4105            Self::Acp(value) => super::McpServer::Acp(value.into_v2()?),
4106            Self::Stdio(value) => super::McpServer::Stdio(value.into_v2()?),
4107        })
4108    }
4109}
4110
4111impl IntoV1 for super::McpServerHttp {
4112    type Output = crate::v1::McpServerHttp;
4113
4114    fn into_v1(self) -> Result<Self::Output> {
4115        let Self {
4116            name,
4117            url,
4118            headers,
4119            meta,
4120        } = self;
4121        Ok(crate::v1::McpServerHttp {
4122            name: name.into_v1()?,
4123            url: url.into_v1()?,
4124            headers: headers.into_v1()?,
4125            meta: meta.into_v1()?,
4126        })
4127    }
4128}
4129
4130impl IntoV2 for crate::v1::McpServerHttp {
4131    type Output = super::McpServerHttp;
4132
4133    fn into_v2(self) -> Result<Self::Output> {
4134        let Self {
4135            name,
4136            url,
4137            headers,
4138            meta,
4139        } = self;
4140        Ok(super::McpServerHttp {
4141            name: name.into_v2()?,
4142            url: url.into_v2()?,
4143            headers: headers.into_v2()?,
4144            meta: meta.into_v2()?,
4145        })
4146    }
4147}
4148
4149#[cfg(feature = "unstable_mcp_over_acp")]
4150impl IntoV1 for super::McpServerAcpId {
4151    type Output = crate::v1::McpServerAcpId;
4152
4153    fn into_v1(self) -> Result<Self::Output> {
4154        Ok(crate::v1::McpServerAcpId(self.0.into_v1()?))
4155    }
4156}
4157
4158#[cfg(feature = "unstable_mcp_over_acp")]
4159impl IntoV2 for crate::v1::McpServerAcpId {
4160    type Output = super::McpServerAcpId;
4161
4162    fn into_v2(self) -> Result<Self::Output> {
4163        Ok(super::McpServerAcpId(self.0.into_v2()?))
4164    }
4165}
4166
4167#[cfg(feature = "unstable_mcp_over_acp")]
4168impl IntoV1 for super::McpConnectionId {
4169    type Output = crate::v1::McpConnectionId;
4170
4171    fn into_v1(self) -> Result<Self::Output> {
4172        Ok(crate::v1::McpConnectionId(self.0.into_v1()?))
4173    }
4174}
4175
4176#[cfg(feature = "unstable_mcp_over_acp")]
4177impl IntoV2 for crate::v1::McpConnectionId {
4178    type Output = super::McpConnectionId;
4179
4180    fn into_v2(self) -> Result<Self::Output> {
4181        Ok(super::McpConnectionId(self.0.into_v2()?))
4182    }
4183}
4184
4185#[cfg(feature = "unstable_mcp_over_acp")]
4186impl IntoV1 for super::McpServerAcp {
4187    type Output = crate::v1::McpServerAcp;
4188
4189    fn into_v1(self) -> Result<Self::Output> {
4190        let Self { name, id, meta } = self;
4191        Ok(crate::v1::McpServerAcp {
4192            name: name.into_v1()?,
4193            id: id.into_v1()?,
4194            meta: meta.into_v1()?,
4195        })
4196    }
4197}
4198
4199#[cfg(feature = "unstable_mcp_over_acp")]
4200impl IntoV2 for crate::v1::McpServerAcp {
4201    type Output = super::McpServerAcp;
4202
4203    fn into_v2(self) -> Result<Self::Output> {
4204        let Self { name, id, meta } = self;
4205        Ok(super::McpServerAcp {
4206            name: name.into_v2()?,
4207            id: id.into_v2()?,
4208            meta: meta.into_v2()?,
4209        })
4210    }
4211}
4212
4213impl IntoV1 for super::McpServerStdio {
4214    type Output = crate::v1::McpServerStdio;
4215
4216    fn into_v1(self) -> Result<Self::Output> {
4217        let Self {
4218            name,
4219            command,
4220            args,
4221            env,
4222            meta,
4223        } = self;
4224        Ok(crate::v1::McpServerStdio {
4225            name: name.into_v1()?,
4226            command: command.into_v1()?,
4227            args: args.into_v1()?,
4228            env: env.into_v1()?,
4229            meta: meta.into_v1()?,
4230        })
4231    }
4232}
4233
4234impl IntoV2 for crate::v1::McpServerStdio {
4235    type Output = super::McpServerStdio;
4236
4237    fn into_v2(self) -> Result<Self::Output> {
4238        let Self {
4239            name,
4240            command,
4241            args,
4242            env,
4243            meta,
4244        } = self;
4245        Ok(super::McpServerStdio {
4246            name: name.into_v2()?,
4247            command: command.into_v2()?,
4248            args: args.into_v2()?,
4249            env: env.into_v2()?,
4250            meta: meta.into_v2()?,
4251        })
4252    }
4253}
4254
4255impl IntoV1 for super::EnvVariable {
4256    type Output = crate::v1::EnvVariable;
4257
4258    fn into_v1(self) -> Result<Self::Output> {
4259        let Self { name, value, meta } = self;
4260        Ok(crate::v1::EnvVariable {
4261            name: name.into_v1()?,
4262            value: value.into_v1()?,
4263            meta: meta.into_v1()?,
4264        })
4265    }
4266}
4267
4268impl IntoV2 for crate::v1::EnvVariable {
4269    type Output = super::EnvVariable;
4270
4271    fn into_v2(self) -> Result<Self::Output> {
4272        let Self { name, value, meta } = self;
4273        Ok(super::EnvVariable {
4274            name: name.into_v2()?,
4275            value: value.into_v2()?,
4276            meta: meta.into_v2()?,
4277        })
4278    }
4279}
4280
4281impl IntoV1 for super::HttpHeader {
4282    type Output = crate::v1::HttpHeader;
4283
4284    fn into_v1(self) -> Result<Self::Output> {
4285        let Self { name, value, meta } = self;
4286        Ok(crate::v1::HttpHeader {
4287            name: name.into_v1()?,
4288            value: value.into_v1()?,
4289            meta: meta.into_v1()?,
4290        })
4291    }
4292}
4293
4294impl IntoV2 for crate::v1::HttpHeader {
4295    type Output = super::HttpHeader;
4296
4297    fn into_v2(self) -> Result<Self::Output> {
4298        let Self { name, value, meta } = self;
4299        Ok(super::HttpHeader {
4300            name: name.into_v2()?,
4301            value: value.into_v2()?,
4302            meta: meta.into_v2()?,
4303        })
4304    }
4305}
4306
4307impl IntoV1 for super::PromptRequest {
4308    type Output = crate::v1::PromptRequest;
4309
4310    fn into_v1(self) -> Result<Self::Output> {
4311        let Self {
4312            session_id,
4313            prompt,
4314            meta,
4315        } = self;
4316        Ok(crate::v1::PromptRequest {
4317            session_id: session_id.into_v1()?,
4318            prompt: prompt.into_v1()?,
4319            meta: meta.into_v1()?,
4320        })
4321    }
4322}
4323
4324impl IntoV2 for crate::v1::PromptRequest {
4325    type Output = super::PromptRequest;
4326
4327    fn into_v2(self) -> Result<Self::Output> {
4328        let Self {
4329            session_id,
4330            prompt,
4331            meta,
4332        } = self;
4333        Ok(super::PromptRequest {
4334            session_id: session_id.into_v2()?,
4335            prompt: prompt.into_v2()?,
4336            meta: meta.into_v2()?,
4337        })
4338    }
4339}
4340
4341impl IntoV1 for super::PromptResponse {
4342    type Output = crate::v1::PromptResponse;
4343
4344    fn into_v1(self) -> Result<Self::Output> {
4345        Err(ProtocolConversionError::new(
4346            "v2 PromptResponse cannot be represented in v1 because v2 reports completion with state_update session updates",
4347        ))
4348    }
4349}
4350
4351impl IntoV2 for crate::v1::PromptResponse {
4352    type Output = super::PromptResponse;
4353
4354    fn into_v2(self) -> Result<Self::Output> {
4355        Err(ProtocolConversionError::new(
4356            "v1 PromptResponse cannot be represented in v2 by itself because v2 reports completion with state_update session updates",
4357        ))
4358    }
4359}
4360
4361impl IntoV1 for super::StopReason {
4362    type Output = crate::v1::StopReason;
4363
4364    fn into_v1(self) -> Result<Self::Output> {
4365        Ok(match self {
4366            Self::EndTurn => crate::v1::StopReason::EndTurn,
4367            Self::MaxTokens => crate::v1::StopReason::MaxTokens,
4368            Self::MaxTurnRequests => crate::v1::StopReason::MaxTurnRequests,
4369            Self::Refusal => crate::v1::StopReason::Refusal,
4370            Self::Cancelled => crate::v1::StopReason::Cancelled,
4371            Self::Other(value) => return Err(unknown_v2_enum_variant("StopReason", &value)),
4372        })
4373    }
4374}
4375
4376impl IntoV2 for crate::v1::StopReason {
4377    type Output = super::StopReason;
4378
4379    fn into_v2(self) -> Result<Self::Output> {
4380        Ok(match self {
4381            Self::EndTurn => super::StopReason::EndTurn,
4382            Self::MaxTokens => super::StopReason::MaxTokens,
4383            Self::MaxTurnRequests => super::StopReason::MaxTurnRequests,
4384            Self::Refusal => super::StopReason::Refusal,
4385            Self::Cancelled => super::StopReason::Cancelled,
4386        })
4387    }
4388}
4389
4390#[cfg(feature = "unstable_end_turn_token_usage")]
4391impl IntoV1 for super::Usage {
4392    type Output = crate::v1::Usage;
4393
4394    fn into_v1(self) -> Result<Self::Output> {
4395        let Self {
4396            total_tokens,
4397            input_tokens,
4398            output_tokens,
4399            thought_tokens,
4400            cached_read_tokens,
4401            cached_write_tokens,
4402            meta,
4403        } = self;
4404        Ok(crate::v1::Usage {
4405            total_tokens: total_tokens.into_v1()?,
4406            input_tokens: input_tokens.into_v1()?,
4407            output_tokens: output_tokens.into_v1()?,
4408            thought_tokens: thought_tokens.into_v1()?,
4409            cached_read_tokens: cached_read_tokens.into_v1()?,
4410            cached_write_tokens: cached_write_tokens.into_v1()?,
4411            meta: meta.into_v1()?,
4412        })
4413    }
4414}
4415
4416#[cfg(feature = "unstable_end_turn_token_usage")]
4417impl IntoV2 for crate::v1::Usage {
4418    type Output = super::Usage;
4419
4420    fn into_v2(self) -> Result<Self::Output> {
4421        let Self {
4422            total_tokens,
4423            input_tokens,
4424            output_tokens,
4425            thought_tokens,
4426            cached_read_tokens,
4427            cached_write_tokens,
4428            meta,
4429        } = self;
4430        Ok(super::Usage {
4431            total_tokens: total_tokens.into_v2()?,
4432            input_tokens: input_tokens.into_v2()?,
4433            output_tokens: output_tokens.into_v2()?,
4434            thought_tokens: thought_tokens.into_v2()?,
4435            cached_read_tokens: cached_read_tokens.into_v2()?,
4436            cached_write_tokens: cached_write_tokens.into_v2()?,
4437            meta: meta.into_v2()?,
4438        })
4439    }
4440}
4441
4442#[cfg(feature = "unstable_llm_providers")]
4443impl IntoV1 for super::LlmProtocol {
4444    type Output = crate::v1::LlmProtocol;
4445
4446    fn into_v1(self) -> Result<Self::Output> {
4447        Ok(match self {
4448            Self::Anthropic => crate::v1::LlmProtocol::Anthropic,
4449            Self::OpenAi => crate::v1::LlmProtocol::OpenAi,
4450            Self::Azure => crate::v1::LlmProtocol::Azure,
4451            Self::Vertex => crate::v1::LlmProtocol::Vertex,
4452            Self::Bedrock => crate::v1::LlmProtocol::Bedrock,
4453            Self::Other(value) => crate::v1::LlmProtocol::Other(value.into_v1()?),
4454        })
4455    }
4456}
4457
4458#[cfg(feature = "unstable_llm_providers")]
4459impl IntoV2 for crate::v1::LlmProtocol {
4460    type Output = super::LlmProtocol;
4461
4462    fn into_v2(self) -> Result<Self::Output> {
4463        Ok(match self {
4464            Self::Anthropic => super::LlmProtocol::Anthropic,
4465            Self::OpenAi => super::LlmProtocol::OpenAi,
4466            Self::Azure => super::LlmProtocol::Azure,
4467            Self::Vertex => super::LlmProtocol::Vertex,
4468            Self::Bedrock => super::LlmProtocol::Bedrock,
4469            Self::Other(value) => super::LlmProtocol::Other(value.into_v2()?),
4470        })
4471    }
4472}
4473
4474#[cfg(feature = "unstable_llm_providers")]
4475impl IntoV1 for super::ProviderCurrentConfig {
4476    type Output = crate::v1::ProviderCurrentConfig;
4477
4478    fn into_v1(self) -> Result<Self::Output> {
4479        let Self {
4480            api_type,
4481            base_url,
4482            meta,
4483        } = self;
4484        Ok(crate::v1::ProviderCurrentConfig {
4485            api_type: api_type.into_v1()?,
4486            base_url: base_url.into_v1()?,
4487            meta: meta.into_v1()?,
4488        })
4489    }
4490}
4491
4492#[cfg(feature = "unstable_llm_providers")]
4493impl IntoV2 for crate::v1::ProviderCurrentConfig {
4494    type Output = super::ProviderCurrentConfig;
4495
4496    fn into_v2(self) -> Result<Self::Output> {
4497        let Self {
4498            api_type,
4499            base_url,
4500            meta,
4501        } = self;
4502        Ok(super::ProviderCurrentConfig {
4503            api_type: api_type.into_v2()?,
4504            base_url: base_url.into_v2()?,
4505            meta: meta.into_v2()?,
4506        })
4507    }
4508}
4509
4510#[cfg(feature = "unstable_llm_providers")]
4511impl IntoV1 for super::ProviderInfo {
4512    type Output = crate::v1::ProviderInfo;
4513
4514    fn into_v1(self) -> Result<Self::Output> {
4515        let Self {
4516            id,
4517            supported,
4518            required,
4519            current,
4520            meta,
4521        } = self;
4522        Ok(crate::v1::ProviderInfo {
4523            id: id.into_v1()?,
4524            supported: into_v1_vec_skip_errors(supported),
4525            required: required.into_v1()?,
4526            current: current.into_v1()?,
4527            meta: meta.into_v1()?,
4528        })
4529    }
4530}
4531
4532#[cfg(feature = "unstable_llm_providers")]
4533impl IntoV2 for crate::v1::ProviderInfo {
4534    type Output = super::ProviderInfo;
4535
4536    fn into_v2(self) -> Result<Self::Output> {
4537        let Self {
4538            id,
4539            supported,
4540            required,
4541            current,
4542            meta,
4543        } = self;
4544        Ok(super::ProviderInfo {
4545            id: id.into_v2()?,
4546            supported: into_v2_vec_skip_errors(supported),
4547            required: required.into_v2()?,
4548            current: current.into_v2()?,
4549            meta: meta.into_v2()?,
4550        })
4551    }
4552}
4553
4554#[cfg(feature = "unstable_llm_providers")]
4555impl IntoV1 for super::ListProvidersRequest {
4556    type Output = crate::v1::ListProvidersRequest;
4557
4558    fn into_v1(self) -> Result<Self::Output> {
4559        let Self { meta } = self;
4560        Ok(crate::v1::ListProvidersRequest {
4561            meta: meta.into_v1()?,
4562        })
4563    }
4564}
4565
4566#[cfg(feature = "unstable_llm_providers")]
4567impl IntoV2 for crate::v1::ListProvidersRequest {
4568    type Output = super::ListProvidersRequest;
4569
4570    fn into_v2(self) -> Result<Self::Output> {
4571        let Self { meta } = self;
4572        Ok(super::ListProvidersRequest {
4573            meta: meta.into_v2()?,
4574        })
4575    }
4576}
4577
4578#[cfg(feature = "unstable_llm_providers")]
4579impl IntoV1 for super::ListProvidersResponse {
4580    type Output = crate::v1::ListProvidersResponse;
4581
4582    fn into_v1(self) -> Result<Self::Output> {
4583        let Self { providers, meta } = self;
4584        Ok(crate::v1::ListProvidersResponse {
4585            providers: into_v1_vec_skip_errors(providers),
4586            meta: meta.into_v1()?,
4587        })
4588    }
4589}
4590
4591#[cfg(feature = "unstable_llm_providers")]
4592impl IntoV2 for crate::v1::ListProvidersResponse {
4593    type Output = super::ListProvidersResponse;
4594
4595    fn into_v2(self) -> Result<Self::Output> {
4596        let Self { providers, meta } = self;
4597        Ok(super::ListProvidersResponse {
4598            providers: into_v2_vec_skip_errors(providers),
4599            meta: meta.into_v2()?,
4600        })
4601    }
4602}
4603
4604#[cfg(feature = "unstable_llm_providers")]
4605impl IntoV1 for super::SetProviderRequest {
4606    type Output = crate::v1::SetProviderRequest;
4607
4608    fn into_v1(self) -> Result<Self::Output> {
4609        let Self {
4610            id,
4611            api_type,
4612            base_url,
4613            headers,
4614            meta,
4615        } = self;
4616        Ok(crate::v1::SetProviderRequest {
4617            id: id.into_v1()?,
4618            api_type: api_type.into_v1()?,
4619            base_url: base_url.into_v1()?,
4620            headers: headers.into_v1()?,
4621            meta: meta.into_v1()?,
4622        })
4623    }
4624}
4625
4626#[cfg(feature = "unstable_llm_providers")]
4627impl IntoV2 for crate::v1::SetProviderRequest {
4628    type Output = super::SetProviderRequest;
4629
4630    fn into_v2(self) -> Result<Self::Output> {
4631        let Self {
4632            id,
4633            api_type,
4634            base_url,
4635            headers,
4636            meta,
4637        } = self;
4638        Ok(super::SetProviderRequest {
4639            id: id.into_v2()?,
4640            api_type: api_type.into_v2()?,
4641            base_url: base_url.into_v2()?,
4642            headers: headers.into_v2()?,
4643            meta: meta.into_v2()?,
4644        })
4645    }
4646}
4647
4648#[cfg(feature = "unstable_llm_providers")]
4649impl IntoV1 for super::SetProviderResponse {
4650    type Output = crate::v1::SetProviderResponse;
4651
4652    fn into_v1(self) -> Result<Self::Output> {
4653        let Self { meta } = self;
4654        Ok(crate::v1::SetProviderResponse {
4655            meta: meta.into_v1()?,
4656        })
4657    }
4658}
4659
4660#[cfg(feature = "unstable_llm_providers")]
4661impl IntoV2 for crate::v1::SetProviderResponse {
4662    type Output = super::SetProviderResponse;
4663
4664    fn into_v2(self) -> Result<Self::Output> {
4665        let Self { meta } = self;
4666        Ok(super::SetProviderResponse {
4667            meta: meta.into_v2()?,
4668        })
4669    }
4670}
4671
4672#[cfg(feature = "unstable_llm_providers")]
4673impl IntoV1 for super::DisableProviderRequest {
4674    type Output = crate::v1::DisableProviderRequest;
4675
4676    fn into_v1(self) -> Result<Self::Output> {
4677        let Self { id, meta } = self;
4678        Ok(crate::v1::DisableProviderRequest {
4679            id: id.into_v1()?,
4680            meta: meta.into_v1()?,
4681        })
4682    }
4683}
4684
4685#[cfg(feature = "unstable_llm_providers")]
4686impl IntoV2 for crate::v1::DisableProviderRequest {
4687    type Output = super::DisableProviderRequest;
4688
4689    fn into_v2(self) -> Result<Self::Output> {
4690        let Self { id, meta } = self;
4691        Ok(super::DisableProviderRequest {
4692            id: id.into_v2()?,
4693            meta: meta.into_v2()?,
4694        })
4695    }
4696}
4697
4698#[cfg(feature = "unstable_llm_providers")]
4699impl IntoV1 for super::DisableProviderResponse {
4700    type Output = crate::v1::DisableProviderResponse;
4701
4702    fn into_v1(self) -> Result<Self::Output> {
4703        let Self { meta } = self;
4704        Ok(crate::v1::DisableProviderResponse {
4705            meta: meta.into_v1()?,
4706        })
4707    }
4708}
4709
4710#[cfg(feature = "unstable_llm_providers")]
4711impl IntoV2 for crate::v1::DisableProviderResponse {
4712    type Output = super::DisableProviderResponse;
4713
4714    fn into_v2(self) -> Result<Self::Output> {
4715        let Self { meta } = self;
4716        Ok(super::DisableProviderResponse {
4717            meta: meta.into_v2()?,
4718        })
4719    }
4720}
4721
4722impl IntoV1 for super::AgentCapabilities {
4723    type Output = crate::v1::AgentCapabilities;
4724
4725    fn into_v1(self) -> Result<Self::Output> {
4726        let Self {
4727            session,
4728            auth,
4729            #[cfg(feature = "unstable_llm_providers")]
4730            providers,
4731            #[cfg(feature = "unstable_nes")]
4732            nes,
4733            #[cfg(feature = "unstable_nes")]
4734            position_encoding,
4735            meta,
4736        } = self;
4737        let Some(session) = session else {
4738            return Err(ProtocolConversionError::new(
4739                "v2 AgentCapabilities without `session` cannot be represented in v1",
4740            ));
4741        };
4742        let V1SessionCapabilityParts {
4743            session_capabilities,
4744            prompt_capabilities,
4745            load_session,
4746            mcp_capabilities,
4747        } = session.into_v1()?;
4748
4749        Ok(crate::v1::AgentCapabilities {
4750            load_session: load_session.into_v1()?,
4751            prompt_capabilities,
4752            mcp_capabilities,
4753            session_capabilities,
4754            auth: auth.into_v1()?,
4755            #[cfg(feature = "unstable_llm_providers")]
4756            providers: into_v1_default_on_error(providers),
4757            #[cfg(feature = "unstable_nes")]
4758            nes: into_v1_default_on_error(nes),
4759            #[cfg(feature = "unstable_nes")]
4760            position_encoding: into_v1_default_on_error(position_encoding),
4761            meta: meta.into_v1()?,
4762        })
4763    }
4764}
4765
4766impl IntoV2 for crate::v1::AgentCapabilities {
4767    type Output = super::AgentCapabilities;
4768
4769    fn into_v2(self) -> Result<Self::Output> {
4770        let Self {
4771            load_session,
4772            prompt_capabilities,
4773            mcp_capabilities,
4774            session_capabilities,
4775            auth,
4776            #[cfg(feature = "unstable_llm_providers")]
4777            providers,
4778            #[cfg(feature = "unstable_nes")]
4779            nes,
4780            #[cfg(feature = "unstable_nes")]
4781            position_encoding,
4782            meta,
4783        } = self;
4784        let session = super::SessionCapabilities::from_v1(
4785            session_capabilities,
4786            prompt_capabilities,
4787            load_session,
4788            mcp_capabilities,
4789        )?;
4790
4791        Ok(super::AgentCapabilities {
4792            session: Some(session),
4793            auth: auth.into_v2()?,
4794            #[cfg(feature = "unstable_llm_providers")]
4795            providers: into_v2_default_on_error(providers),
4796            #[cfg(feature = "unstable_nes")]
4797            nes: into_v2_default_on_error(nes),
4798            #[cfg(feature = "unstable_nes")]
4799            position_encoding: into_v2_default_on_error(position_encoding),
4800            meta: meta.into_v2()?,
4801        })
4802    }
4803}
4804
4805#[cfg(feature = "unstable_llm_providers")]
4806impl IntoV1 for super::ProvidersCapabilities {
4807    type Output = crate::v1::ProvidersCapabilities;
4808
4809    fn into_v1(self) -> Result<Self::Output> {
4810        let Self { meta } = self;
4811        Ok(crate::v1::ProvidersCapabilities {
4812            meta: meta.into_v1()?,
4813        })
4814    }
4815}
4816
4817#[cfg(feature = "unstable_llm_providers")]
4818impl IntoV2 for crate::v1::ProvidersCapabilities {
4819    type Output = super::ProvidersCapabilities;
4820
4821    fn into_v2(self) -> Result<Self::Output> {
4822        let Self { meta } = self;
4823        Ok(super::ProvidersCapabilities {
4824            meta: meta.into_v2()?,
4825        })
4826    }
4827}
4828
4829/// The v1 capability fields represented by v2 `SessionCapabilities`.
4830#[derive(Debug, Clone, PartialEq, Eq)]
4831#[non_exhaustive]
4832pub struct V1SessionCapabilityParts {
4833    /// Session-specific v1 capabilities.
4834    pub session_capabilities: crate::v1::SessionCapabilities,
4835    /// Prompt capabilities for v1 `session/prompt` requests.
4836    pub prompt_capabilities: crate::v1::PromptCapabilities,
4837    /// Whether v1 `session/load` is supported.
4838    pub load_session: bool,
4839    /// MCP capabilities for v1 session lifecycle requests.
4840    pub mcp_capabilities: crate::v1::McpCapabilities,
4841}
4842
4843impl super::SessionCapabilities {
4844    /// Converts these v2 draft session capabilities into the v1 capability
4845    /// fields they represent.
4846    ///
4847    /// # Errors
4848    ///
4849    /// Returns [`ProtocolConversionError`] when any contained capability field
4850    /// cannot be represented in v1.
4851    pub fn into_v1(self) -> Result<V1SessionCapabilityParts> {
4852        let Self {
4853            prompt,
4854            mcp,
4855            load,
4856            list,
4857            delete,
4858            additional_directories,
4859            #[cfg(feature = "unstable_session_fork")]
4860            fork,
4861            resume,
4862            close,
4863            meta,
4864        } = self;
4865
4866        Ok(V1SessionCapabilityParts {
4867            session_capabilities: crate::v1::SessionCapabilities {
4868                list: into_v1_default_on_error(list),
4869                delete: into_v1_default_on_error(delete),
4870                additional_directories: into_v1_default_on_error(additional_directories),
4871                #[cfg(feature = "unstable_session_fork")]
4872                fork: into_v1_default_on_error(fork),
4873                resume: into_v1_default_on_error(resume),
4874                close: into_v1_default_on_error(close),
4875                meta: meta.into_v1()?,
4876            },
4877            prompt_capabilities: prompt.unwrap_or_default().into_v1()?,
4878            load_session: load.is_some(),
4879            mcp_capabilities: mcp.unwrap_or_default().into_v1()?,
4880        })
4881    }
4882
4883    /// Builds v2 draft session capabilities from the v1 agent capability fields
4884    /// that now live under `session` in v2.
4885    ///
4886    /// # Errors
4887    ///
4888    /// Returns [`ProtocolConversionError`] when any of the supplied v1
4889    /// capability fields cannot be represented in v2.
4890    pub fn from_v1(
4891        session_capabilities: crate::v1::SessionCapabilities,
4892        prompt_capabilities: crate::v1::PromptCapabilities,
4893        load_session: bool,
4894        mcp_capabilities: crate::v1::McpCapabilities,
4895    ) -> Result<Self> {
4896        let crate::v1::SessionCapabilities {
4897            list,
4898            delete,
4899            additional_directories,
4900            #[cfg(feature = "unstable_session_fork")]
4901            fork,
4902            resume,
4903            close,
4904            meta,
4905        } = session_capabilities;
4906
4907        Ok(super::SessionCapabilities {
4908            prompt: Some(prompt_capabilities.into_v2()?),
4909            mcp: Some(mcp_capabilities.into_v2()?),
4910            load: load_session.then(super::SessionLoadCapabilities::new),
4911            list: into_v2_default_on_error(list),
4912            delete: into_v2_default_on_error(delete),
4913            additional_directories: into_v2_default_on_error(additional_directories),
4914            #[cfg(feature = "unstable_session_fork")]
4915            fork: into_v2_default_on_error(fork),
4916            resume: into_v2_default_on_error(resume),
4917            close: into_v2_default_on_error(close),
4918            meta: meta.into_v2()?,
4919        })
4920    }
4921}
4922
4923impl IntoV1 for super::SessionListCapabilities {
4924    type Output = crate::v1::SessionListCapabilities;
4925
4926    fn into_v1(self) -> Result<Self::Output> {
4927        let Self { meta } = self;
4928        Ok(crate::v1::SessionListCapabilities {
4929            meta: meta.into_v1()?,
4930        })
4931    }
4932}
4933
4934impl IntoV2 for crate::v1::SessionListCapabilities {
4935    type Output = super::SessionListCapabilities;
4936
4937    fn into_v2(self) -> Result<Self::Output> {
4938        let Self { meta } = self;
4939        Ok(super::SessionListCapabilities {
4940            meta: meta.into_v2()?,
4941        })
4942    }
4943}
4944
4945impl IntoV1 for super::SessionDeleteCapabilities {
4946    type Output = crate::v1::SessionDeleteCapabilities;
4947
4948    fn into_v1(self) -> Result<Self::Output> {
4949        let Self { meta } = self;
4950        Ok(crate::v1::SessionDeleteCapabilities {
4951            meta: meta.into_v1()?,
4952        })
4953    }
4954}
4955
4956impl IntoV2 for crate::v1::SessionDeleteCapabilities {
4957    type Output = super::SessionDeleteCapabilities;
4958
4959    fn into_v2(self) -> Result<Self::Output> {
4960        let Self { meta } = self;
4961        Ok(super::SessionDeleteCapabilities {
4962            meta: meta.into_v2()?,
4963        })
4964    }
4965}
4966impl IntoV1 for super::SessionAdditionalDirectoriesCapabilities {
4967    type Output = crate::v1::SessionAdditionalDirectoriesCapabilities;
4968
4969    fn into_v1(self) -> Result<Self::Output> {
4970        let Self { meta } = self;
4971        Ok(crate::v1::SessionAdditionalDirectoriesCapabilities {
4972            meta: meta.into_v1()?,
4973        })
4974    }
4975}
4976
4977impl IntoV2 for crate::v1::SessionAdditionalDirectoriesCapabilities {
4978    type Output = super::SessionAdditionalDirectoriesCapabilities;
4979
4980    fn into_v2(self) -> Result<Self::Output> {
4981        let Self { meta } = self;
4982        Ok(super::SessionAdditionalDirectoriesCapabilities {
4983            meta: meta.into_v2()?,
4984        })
4985    }
4986}
4987
4988#[cfg(feature = "unstable_session_fork")]
4989impl IntoV1 for super::SessionForkCapabilities {
4990    type Output = crate::v1::SessionForkCapabilities;
4991
4992    fn into_v1(self) -> Result<Self::Output> {
4993        let Self { meta } = self;
4994        Ok(crate::v1::SessionForkCapabilities {
4995            meta: meta.into_v1()?,
4996        })
4997    }
4998}
4999
5000#[cfg(feature = "unstable_session_fork")]
5001impl IntoV2 for crate::v1::SessionForkCapabilities {
5002    type Output = super::SessionForkCapabilities;
5003
5004    fn into_v2(self) -> Result<Self::Output> {
5005        let Self { meta } = self;
5006        Ok(super::SessionForkCapabilities {
5007            meta: meta.into_v2()?,
5008        })
5009    }
5010}
5011
5012impl IntoV1 for super::SessionResumeCapabilities {
5013    type Output = crate::v1::SessionResumeCapabilities;
5014
5015    fn into_v1(self) -> Result<Self::Output> {
5016        let Self { meta } = self;
5017        Ok(crate::v1::SessionResumeCapabilities {
5018            meta: meta.into_v1()?,
5019        })
5020    }
5021}
5022
5023impl IntoV2 for crate::v1::SessionResumeCapabilities {
5024    type Output = super::SessionResumeCapabilities;
5025
5026    fn into_v2(self) -> Result<Self::Output> {
5027        let Self { meta } = self;
5028        Ok(super::SessionResumeCapabilities {
5029            meta: meta.into_v2()?,
5030        })
5031    }
5032}
5033
5034impl IntoV1 for super::SessionCloseCapabilities {
5035    type Output = crate::v1::SessionCloseCapabilities;
5036
5037    fn into_v1(self) -> Result<Self::Output> {
5038        let Self { meta } = self;
5039        Ok(crate::v1::SessionCloseCapabilities {
5040            meta: meta.into_v1()?,
5041        })
5042    }
5043}
5044
5045impl IntoV2 for crate::v1::SessionCloseCapabilities {
5046    type Output = super::SessionCloseCapabilities;
5047
5048    fn into_v2(self) -> Result<Self::Output> {
5049        let Self { meta } = self;
5050        Ok(super::SessionCloseCapabilities {
5051            meta: meta.into_v2()?,
5052        })
5053    }
5054}
5055
5056impl IntoV1 for super::PromptCapabilities {
5057    type Output = crate::v1::PromptCapabilities;
5058
5059    fn into_v1(self) -> Result<Self::Output> {
5060        let Self {
5061            image,
5062            audio,
5063            embedded_context,
5064            meta,
5065        } = self;
5066        Ok(crate::v1::PromptCapabilities {
5067            image: image.is_some(),
5068            audio: audio.is_some(),
5069            embedded_context: embedded_context.is_some(),
5070            meta: meta.into_v1()?,
5071        })
5072    }
5073}
5074
5075impl IntoV2 for crate::v1::PromptCapabilities {
5076    type Output = super::PromptCapabilities;
5077
5078    fn into_v2(self) -> Result<Self::Output> {
5079        let Self {
5080            image,
5081            audio,
5082            embedded_context,
5083            meta,
5084        } = self;
5085        Ok(super::PromptCapabilities {
5086            image: image.then(super::PromptImageCapabilities::new),
5087            audio: audio.then(super::PromptAudioCapabilities::new),
5088            embedded_context: embedded_context.then(super::PromptEmbeddedContextCapabilities::new),
5089            meta: meta.into_v2()?,
5090        })
5091    }
5092}
5093
5094impl IntoV1 for super::McpCapabilities {
5095    type Output = crate::v1::McpCapabilities;
5096
5097    fn into_v1(self) -> Result<Self::Output> {
5098        let Self {
5099            stdio: _,
5100            http,
5101            #[cfg(feature = "unstable_mcp_over_acp")]
5102            acp,
5103            meta,
5104        } = self;
5105        Ok(crate::v1::McpCapabilities {
5106            http: http.is_some(),
5107            sse: false,
5108            #[cfg(feature = "unstable_mcp_over_acp")]
5109            acp: acp.is_some(),
5110            meta: meta.into_v1()?,
5111        })
5112    }
5113}
5114
5115impl IntoV2 for crate::v1::McpCapabilities {
5116    type Output = super::McpCapabilities;
5117
5118    fn into_v2(self) -> Result<Self::Output> {
5119        let Self {
5120            http,
5121            sse: _,
5122            #[cfg(feature = "unstable_mcp_over_acp")]
5123            acp,
5124            meta,
5125        } = self;
5126        Ok(super::McpCapabilities {
5127            stdio: Some(super::McpStdioCapabilities::new()),
5128            http: http.then(super::McpHttpCapabilities::new),
5129            #[cfg(feature = "unstable_mcp_over_acp")]
5130            acp: acp.then(super::McpAcpCapabilities::new),
5131            meta: meta.into_v2()?,
5132        })
5133    }
5134}
5135
5136impl IntoV1 for super::ClientRequest {
5137    type Output = crate::v1::ClientRequest;
5138
5139    fn into_v1(self) -> Result<Self::Output> {
5140        Ok(match self {
5141            Self::InitializeRequest(value) => {
5142                crate::v1::ClientRequest::InitializeRequest(value.into_v1()?)
5143            }
5144            Self::AuthenticateRequest(value) => {
5145                crate::v1::ClientRequest::AuthenticateRequest(value.into_v1()?)
5146            }
5147            #[cfg(feature = "unstable_llm_providers")]
5148            Self::ListProvidersRequest(value) => {
5149                crate::v1::ClientRequest::ListProvidersRequest(value.into_v1()?)
5150            }
5151            #[cfg(feature = "unstable_llm_providers")]
5152            Self::SetProviderRequest(value) => {
5153                crate::v1::ClientRequest::SetProviderRequest(value.into_v1()?)
5154            }
5155            #[cfg(feature = "unstable_llm_providers")]
5156            Self::DisableProviderRequest(value) => {
5157                crate::v1::ClientRequest::DisableProviderRequest(value.into_v1()?)
5158            }
5159            Self::LogoutRequest(value) => crate::v1::ClientRequest::LogoutRequest(value.into_v1()?),
5160            Self::NewSessionRequest(value) => {
5161                crate::v1::ClientRequest::NewSessionRequest(value.into_v1()?)
5162            }
5163            Self::LoadSessionRequest(value) => {
5164                crate::v1::ClientRequest::LoadSessionRequest(value.into_v1()?)
5165            }
5166            Self::ListSessionsRequest(value) => {
5167                crate::v1::ClientRequest::ListSessionsRequest(value.into_v1()?)
5168            }
5169            Self::DeleteSessionRequest(value) => {
5170                crate::v1::ClientRequest::DeleteSessionRequest(value.into_v1()?)
5171            }
5172            #[cfg(feature = "unstable_session_fork")]
5173            Self::ForkSessionRequest(value) => {
5174                crate::v1::ClientRequest::ForkSessionRequest(value.into_v1()?)
5175            }
5176            Self::ResumeSessionRequest(value) => {
5177                crate::v1::ClientRequest::ResumeSessionRequest(value.into_v1()?)
5178            }
5179            Self::CloseSessionRequest(value) => {
5180                crate::v1::ClientRequest::CloseSessionRequest(value.into_v1()?)
5181            }
5182            Self::SetSessionConfigOptionRequest(value) => {
5183                crate::v1::ClientRequest::SetSessionConfigOptionRequest(value.into_v1()?)
5184            }
5185            Self::PromptRequest(value) => crate::v1::ClientRequest::PromptRequest(value.into_v1()?),
5186            #[cfg(feature = "unstable_nes")]
5187            Self::StartNesRequest(value) => {
5188                crate::v1::ClientRequest::StartNesRequest(value.into_v1()?)
5189            }
5190            #[cfg(feature = "unstable_nes")]
5191            Self::SuggestNesRequest(value) => {
5192                crate::v1::ClientRequest::SuggestNesRequest(value.into_v1()?)
5193            }
5194            #[cfg(feature = "unstable_nes")]
5195            Self::CloseNesRequest(value) => {
5196                crate::v1::ClientRequest::CloseNesRequest(value.into_v1()?)
5197            }
5198            #[cfg(feature = "unstable_mcp_over_acp")]
5199            Self::MessageMcpRequest(value) => {
5200                crate::v1::ClientRequest::MessageMcpRequest(value.into_v1()?)
5201            }
5202            Self::ExtMethodRequest(value) => {
5203                crate::v1::ClientRequest::ExtMethodRequest(value.into_v1()?)
5204            }
5205        })
5206    }
5207}
5208
5209impl IntoV2 for crate::v1::ClientRequest {
5210    type Output = super::ClientRequest;
5211
5212    fn into_v2(self) -> Result<Self::Output> {
5213        Ok(match self {
5214            Self::InitializeRequest(value) => {
5215                super::ClientRequest::InitializeRequest(Box::new(value.into_v2()?))
5216            }
5217            Self::AuthenticateRequest(value) => {
5218                super::ClientRequest::AuthenticateRequest(value.into_v2()?)
5219            }
5220            #[cfg(feature = "unstable_llm_providers")]
5221            Self::ListProvidersRequest(value) => {
5222                super::ClientRequest::ListProvidersRequest(value.into_v2()?)
5223            }
5224            #[cfg(feature = "unstable_llm_providers")]
5225            Self::SetProviderRequest(value) => {
5226                super::ClientRequest::SetProviderRequest(Box::new(value.into_v2()?))
5227            }
5228            #[cfg(feature = "unstable_llm_providers")]
5229            Self::DisableProviderRequest(value) => {
5230                super::ClientRequest::DisableProviderRequest(value.into_v2()?)
5231            }
5232            Self::LogoutRequest(value) => super::ClientRequest::LogoutRequest(value.into_v2()?),
5233            Self::NewSessionRequest(value) => {
5234                super::ClientRequest::NewSessionRequest(value.into_v2()?)
5235            }
5236            Self::LoadSessionRequest(value) => {
5237                super::ClientRequest::LoadSessionRequest(value.into_v2()?)
5238            }
5239            Self::ListSessionsRequest(value) => {
5240                super::ClientRequest::ListSessionsRequest(value.into_v2()?)
5241            }
5242            Self::DeleteSessionRequest(value) => {
5243                super::ClientRequest::DeleteSessionRequest(value.into_v2()?)
5244            }
5245            #[cfg(feature = "unstable_session_fork")]
5246            Self::ForkSessionRequest(value) => {
5247                super::ClientRequest::ForkSessionRequest(value.into_v2()?)
5248            }
5249            Self::ResumeSessionRequest(value) => {
5250                super::ClientRequest::ResumeSessionRequest(value.into_v2()?)
5251            }
5252            Self::CloseSessionRequest(value) => {
5253                super::ClientRequest::CloseSessionRequest(value.into_v2()?)
5254            }
5255            Self::SetSessionModeRequest(_) => {
5256                return Err(removed_v1_enum_variant("ClientRequest", "session/set_mode"));
5257            }
5258            Self::SetSessionConfigOptionRequest(value) => {
5259                super::ClientRequest::SetSessionConfigOptionRequest(value.into_v2()?)
5260            }
5261            Self::PromptRequest(value) => super::ClientRequest::PromptRequest(value.into_v2()?),
5262            #[cfg(feature = "unstable_nes")]
5263            Self::StartNesRequest(value) => {
5264                super::ClientRequest::StartNesRequest(Box::new(value.into_v2()?))
5265            }
5266            #[cfg(feature = "unstable_nes")]
5267            Self::SuggestNesRequest(value) => {
5268                super::ClientRequest::SuggestNesRequest(Box::new(value.into_v2()?))
5269            }
5270            #[cfg(feature = "unstable_nes")]
5271            Self::CloseNesRequest(value) => super::ClientRequest::CloseNesRequest(value.into_v2()?),
5272            #[cfg(feature = "unstable_mcp_over_acp")]
5273            Self::MessageMcpRequest(value) => {
5274                super::ClientRequest::MessageMcpRequest(value.into_v2()?)
5275            }
5276            Self::ExtMethodRequest(value) => {
5277                super::ClientRequest::ExtMethodRequest(value.into_v2()?)
5278            }
5279        })
5280    }
5281}
5282
5283impl IntoV1 for super::AgentResponse {
5284    type Output = crate::v1::AgentResponse;
5285
5286    fn into_v1(self) -> Result<Self::Output> {
5287        Ok(match self {
5288            Self::InitializeResponse(value) => {
5289                crate::v1::AgentResponse::InitializeResponse(value.into_v1()?)
5290            }
5291            Self::AuthenticateResponse(value) => {
5292                crate::v1::AgentResponse::AuthenticateResponse(value.into_v1()?)
5293            }
5294            #[cfg(feature = "unstable_llm_providers")]
5295            Self::ListProvidersResponse(value) => {
5296                crate::v1::AgentResponse::ListProvidersResponse(value.into_v1()?)
5297            }
5298            #[cfg(feature = "unstable_llm_providers")]
5299            Self::SetProviderResponse(value) => {
5300                crate::v1::AgentResponse::SetProviderResponse(value.into_v1()?)
5301            }
5302            #[cfg(feature = "unstable_llm_providers")]
5303            Self::DisableProviderResponse(value) => {
5304                crate::v1::AgentResponse::DisableProviderResponse(value.into_v1()?)
5305            }
5306            Self::LogoutResponse(value) => {
5307                crate::v1::AgentResponse::LogoutResponse(value.into_v1()?)
5308            }
5309            Self::NewSessionResponse(value) => {
5310                crate::v1::AgentResponse::NewSessionResponse(value.into_v1()?)
5311            }
5312            Self::LoadSessionResponse(value) => {
5313                crate::v1::AgentResponse::LoadSessionResponse(value.into_v1()?)
5314            }
5315            Self::ListSessionsResponse(value) => {
5316                crate::v1::AgentResponse::ListSessionsResponse(value.into_v1()?)
5317            }
5318            Self::DeleteSessionResponse(value) => {
5319                crate::v1::AgentResponse::DeleteSessionResponse(value.into_v1()?)
5320            }
5321            #[cfg(feature = "unstable_session_fork")]
5322            Self::ForkSessionResponse(value) => {
5323                crate::v1::AgentResponse::ForkSessionResponse(value.into_v1()?)
5324            }
5325            Self::ResumeSessionResponse(value) => {
5326                crate::v1::AgentResponse::ResumeSessionResponse(value.into_v1()?)
5327            }
5328            Self::CloseSessionResponse(value) => {
5329                crate::v1::AgentResponse::CloseSessionResponse(value.into_v1()?)
5330            }
5331            Self::SetSessionConfigOptionResponse(value) => {
5332                crate::v1::AgentResponse::SetSessionConfigOptionResponse(value.into_v1()?)
5333            }
5334            Self::PromptResponse(value) => {
5335                crate::v1::AgentResponse::PromptResponse(value.into_v1()?)
5336            }
5337            #[cfg(feature = "unstable_nes")]
5338            Self::StartNesResponse(value) => {
5339                crate::v1::AgentResponse::StartNesResponse(value.into_v1()?)
5340            }
5341            #[cfg(feature = "unstable_nes")]
5342            Self::SuggestNesResponse(value) => {
5343                crate::v1::AgentResponse::SuggestNesResponse(value.into_v1()?)
5344            }
5345            #[cfg(feature = "unstable_nes")]
5346            Self::CloseNesResponse(value) => {
5347                crate::v1::AgentResponse::CloseNesResponse(value.into_v1()?)
5348            }
5349            Self::ExtMethodResponse(value) => {
5350                crate::v1::AgentResponse::ExtMethodResponse(value.into_v1()?)
5351            }
5352            #[cfg(feature = "unstable_mcp_over_acp")]
5353            Self::MessageMcpResponse(value) => {
5354                crate::v1::AgentResponse::MessageMcpResponse(value.into_v1()?)
5355            }
5356        })
5357    }
5358}
5359
5360impl IntoV2 for crate::v1::AgentResponse {
5361    type Output = super::AgentResponse;
5362
5363    fn into_v2(self) -> Result<Self::Output> {
5364        Ok(match self {
5365            Self::InitializeResponse(value) => {
5366                super::AgentResponse::InitializeResponse(Box::new(value.into_v2()?))
5367            }
5368            Self::AuthenticateResponse(value) => {
5369                super::AgentResponse::AuthenticateResponse(value.into_v2()?)
5370            }
5371            #[cfg(feature = "unstable_llm_providers")]
5372            Self::ListProvidersResponse(value) => {
5373                super::AgentResponse::ListProvidersResponse(value.into_v2()?)
5374            }
5375            #[cfg(feature = "unstable_llm_providers")]
5376            Self::SetProviderResponse(value) => {
5377                super::AgentResponse::SetProviderResponse(value.into_v2()?)
5378            }
5379            #[cfg(feature = "unstable_llm_providers")]
5380            Self::DisableProviderResponse(value) => {
5381                super::AgentResponse::DisableProviderResponse(value.into_v2()?)
5382            }
5383            Self::LogoutResponse(value) => super::AgentResponse::LogoutResponse(value.into_v2()?),
5384            Self::NewSessionResponse(value) => {
5385                super::AgentResponse::NewSessionResponse(value.into_v2()?)
5386            }
5387            Self::LoadSessionResponse(value) => {
5388                super::AgentResponse::LoadSessionResponse(value.into_v2()?)
5389            }
5390            Self::ListSessionsResponse(value) => {
5391                super::AgentResponse::ListSessionsResponse(value.into_v2()?)
5392            }
5393            Self::DeleteSessionResponse(value) => {
5394                super::AgentResponse::DeleteSessionResponse(value.into_v2()?)
5395            }
5396            #[cfg(feature = "unstable_session_fork")]
5397            Self::ForkSessionResponse(value) => {
5398                super::AgentResponse::ForkSessionResponse(value.into_v2()?)
5399            }
5400            Self::ResumeSessionResponse(value) => {
5401                super::AgentResponse::ResumeSessionResponse(value.into_v2()?)
5402            }
5403            Self::CloseSessionResponse(value) => {
5404                super::AgentResponse::CloseSessionResponse(value.into_v2()?)
5405            }
5406            Self::SetSessionModeResponse(_) => {
5407                return Err(removed_v1_enum_variant("AgentResponse", "session/set_mode"));
5408            }
5409            Self::SetSessionConfigOptionResponse(value) => {
5410                super::AgentResponse::SetSessionConfigOptionResponse(value.into_v2()?)
5411            }
5412            Self::PromptResponse(value) => super::AgentResponse::PromptResponse(value.into_v2()?),
5413            #[cfg(feature = "unstable_nes")]
5414            Self::StartNesResponse(value) => {
5415                super::AgentResponse::StartNesResponse(value.into_v2()?)
5416            }
5417            #[cfg(feature = "unstable_nes")]
5418            Self::SuggestNesResponse(value) => {
5419                super::AgentResponse::SuggestNesResponse(value.into_v2()?)
5420            }
5421            #[cfg(feature = "unstable_nes")]
5422            Self::CloseNesResponse(value) => {
5423                super::AgentResponse::CloseNesResponse(value.into_v2()?)
5424            }
5425            Self::ExtMethodResponse(value) => {
5426                super::AgentResponse::ExtMethodResponse(value.into_v2()?)
5427            }
5428            #[cfg(feature = "unstable_mcp_over_acp")]
5429            Self::MessageMcpResponse(value) => {
5430                super::AgentResponse::MessageMcpResponse(value.into_v2()?)
5431            }
5432        })
5433    }
5434}
5435
5436impl IntoV1 for super::ClientNotification {
5437    type Output = crate::v1::ClientNotification;
5438
5439    fn into_v1(self) -> Result<Self::Output> {
5440        Ok(match self {
5441            Self::CancelNotification(value) => {
5442                crate::v1::ClientNotification::CancelNotification(value.into_v1()?)
5443            }
5444            #[cfg(feature = "unstable_nes")]
5445            Self::DidOpenDocumentNotification(value) => {
5446                crate::v1::ClientNotification::DidOpenDocumentNotification(value.into_v1()?)
5447            }
5448            #[cfg(feature = "unstable_nes")]
5449            Self::DidChangeDocumentNotification(value) => {
5450                crate::v1::ClientNotification::DidChangeDocumentNotification(value.into_v1()?)
5451            }
5452            #[cfg(feature = "unstable_nes")]
5453            Self::DidCloseDocumentNotification(value) => {
5454                crate::v1::ClientNotification::DidCloseDocumentNotification(value.into_v1()?)
5455            }
5456            #[cfg(feature = "unstable_nes")]
5457            Self::DidSaveDocumentNotification(value) => {
5458                crate::v1::ClientNotification::DidSaveDocumentNotification(value.into_v1()?)
5459            }
5460            #[cfg(feature = "unstable_nes")]
5461            Self::DidFocusDocumentNotification(value) => {
5462                crate::v1::ClientNotification::DidFocusDocumentNotification(value.into_v1()?)
5463            }
5464            #[cfg(feature = "unstable_nes")]
5465            Self::AcceptNesNotification(value) => {
5466                crate::v1::ClientNotification::AcceptNesNotification(value.into_v1()?)
5467            }
5468            #[cfg(feature = "unstable_nes")]
5469            Self::RejectNesNotification(value) => {
5470                crate::v1::ClientNotification::RejectNesNotification(value.into_v1()?)
5471            }
5472            #[cfg(feature = "unstable_mcp_over_acp")]
5473            Self::MessageMcpNotification(value) => {
5474                crate::v1::ClientNotification::MessageMcpNotification(value.into_v1()?)
5475            }
5476            Self::ExtNotification(value) => {
5477                crate::v1::ClientNotification::ExtNotification(value.into_v1()?)
5478            }
5479        })
5480    }
5481}
5482
5483impl IntoV2 for crate::v1::ClientNotification {
5484    type Output = super::ClientNotification;
5485
5486    fn into_v2(self) -> Result<Self::Output> {
5487        Ok(match self {
5488            Self::CancelNotification(value) => {
5489                super::ClientNotification::CancelNotification(value.into_v2()?)
5490            }
5491            #[cfg(feature = "unstable_nes")]
5492            Self::DidOpenDocumentNotification(value) => {
5493                super::ClientNotification::DidOpenDocumentNotification(value.into_v2()?)
5494            }
5495            #[cfg(feature = "unstable_nes")]
5496            Self::DidChangeDocumentNotification(value) => {
5497                super::ClientNotification::DidChangeDocumentNotification(value.into_v2()?)
5498            }
5499            #[cfg(feature = "unstable_nes")]
5500            Self::DidCloseDocumentNotification(value) => {
5501                super::ClientNotification::DidCloseDocumentNotification(value.into_v2()?)
5502            }
5503            #[cfg(feature = "unstable_nes")]
5504            Self::DidSaveDocumentNotification(value) => {
5505                super::ClientNotification::DidSaveDocumentNotification(value.into_v2()?)
5506            }
5507            #[cfg(feature = "unstable_nes")]
5508            Self::DidFocusDocumentNotification(value) => {
5509                super::ClientNotification::DidFocusDocumentNotification(Box::new(value.into_v2()?))
5510            }
5511            #[cfg(feature = "unstable_nes")]
5512            Self::AcceptNesNotification(value) => {
5513                super::ClientNotification::AcceptNesNotification(value.into_v2()?)
5514            }
5515            #[cfg(feature = "unstable_nes")]
5516            Self::RejectNesNotification(value) => {
5517                super::ClientNotification::RejectNesNotification(value.into_v2()?)
5518            }
5519            #[cfg(feature = "unstable_mcp_over_acp")]
5520            Self::MessageMcpNotification(value) => {
5521                super::ClientNotification::MessageMcpNotification(value.into_v2()?)
5522            }
5523            Self::ExtNotification(value) => {
5524                super::ClientNotification::ExtNotification(value.into_v2()?)
5525            }
5526        })
5527    }
5528}
5529
5530impl IntoV1 for super::CancelNotification {
5531    type Output = crate::v1::CancelNotification;
5532
5533    fn into_v1(self) -> Result<Self::Output> {
5534        let Self { session_id, meta } = self;
5535        Ok(crate::v1::CancelNotification {
5536            session_id: session_id.into_v1()?,
5537            meta: meta.into_v1()?,
5538        })
5539    }
5540}
5541
5542impl IntoV2 for crate::v1::CancelNotification {
5543    type Output = super::CancelNotification;
5544
5545    fn into_v2(self) -> Result<Self::Output> {
5546        let Self { session_id, meta } = self;
5547        Ok(super::CancelNotification {
5548            session_id: session_id.into_v2()?,
5549            meta: meta.into_v2()?,
5550        })
5551    }
5552}
5553
5554#[cfg(feature = "unstable_nes")]
5555impl IntoV1 for super::PositionEncodingKind {
5556    type Output = crate::v1::PositionEncodingKind;
5557
5558    fn into_v1(self) -> Result<Self::Output> {
5559        Ok(match self {
5560            Self::Utf16 => crate::v1::PositionEncodingKind::Utf16,
5561            Self::Utf32 => crate::v1::PositionEncodingKind::Utf32,
5562            Self::Utf8 => crate::v1::PositionEncodingKind::Utf8,
5563        })
5564    }
5565}
5566
5567#[cfg(feature = "unstable_nes")]
5568impl IntoV2 for crate::v1::PositionEncodingKind {
5569    type Output = super::PositionEncodingKind;
5570
5571    fn into_v2(self) -> Result<Self::Output> {
5572        Ok(match self {
5573            Self::Utf16 => super::PositionEncodingKind::Utf16,
5574            Self::Utf32 => super::PositionEncodingKind::Utf32,
5575            Self::Utf8 => super::PositionEncodingKind::Utf8,
5576        })
5577    }
5578}
5579
5580#[cfg(feature = "unstable_nes")]
5581impl IntoV1 for super::Position {
5582    type Output = crate::v1::Position;
5583
5584    fn into_v1(self) -> Result<Self::Output> {
5585        let Self {
5586            line,
5587            character,
5588            meta,
5589        } = self;
5590        Ok(crate::v1::Position {
5591            line: line.into_v1()?,
5592            character: character.into_v1()?,
5593            meta: meta.into_v1()?,
5594        })
5595    }
5596}
5597
5598#[cfg(feature = "unstable_nes")]
5599impl IntoV2 for crate::v1::Position {
5600    type Output = super::Position;
5601
5602    fn into_v2(self) -> Result<Self::Output> {
5603        let Self {
5604            line,
5605            character,
5606            meta,
5607        } = self;
5608        Ok(super::Position {
5609            line: line.into_v2()?,
5610            character: character.into_v2()?,
5611            meta: meta.into_v2()?,
5612        })
5613    }
5614}
5615
5616#[cfg(feature = "unstable_nes")]
5617impl IntoV1 for super::Range {
5618    type Output = crate::v1::Range;
5619
5620    fn into_v1(self) -> Result<Self::Output> {
5621        let Self { start, end, meta } = self;
5622        Ok(crate::v1::Range {
5623            start: start.into_v1()?,
5624            end: end.into_v1()?,
5625            meta: meta.into_v1()?,
5626        })
5627    }
5628}
5629
5630#[cfg(feature = "unstable_nes")]
5631impl IntoV2 for crate::v1::Range {
5632    type Output = super::Range;
5633
5634    fn into_v2(self) -> Result<Self::Output> {
5635        let Self { start, end, meta } = self;
5636        Ok(super::Range {
5637            start: start.into_v2()?,
5638            end: end.into_v2()?,
5639            meta: meta.into_v2()?,
5640        })
5641    }
5642}
5643
5644#[cfg(feature = "unstable_nes")]
5645impl IntoV1 for super::NesCapabilities {
5646    type Output = crate::v1::NesCapabilities;
5647
5648    fn into_v1(self) -> Result<Self::Output> {
5649        let Self {
5650            events,
5651            context,
5652            meta,
5653        } = self;
5654        Ok(crate::v1::NesCapabilities {
5655            events: into_v1_default_on_error(events),
5656            context: into_v1_default_on_error(context),
5657            meta: meta.into_v1()?,
5658        })
5659    }
5660}
5661
5662#[cfg(feature = "unstable_nes")]
5663impl IntoV2 for crate::v1::NesCapabilities {
5664    type Output = super::NesCapabilities;
5665
5666    fn into_v2(self) -> Result<Self::Output> {
5667        let Self {
5668            events,
5669            context,
5670            meta,
5671        } = self;
5672        Ok(super::NesCapabilities {
5673            events: into_v2_default_on_error(events),
5674            context: into_v2_default_on_error(context),
5675            meta: meta.into_v2()?,
5676        })
5677    }
5678}
5679
5680#[cfg(feature = "unstable_nes")]
5681impl IntoV1 for super::NesEventCapabilities {
5682    type Output = crate::v1::NesEventCapabilities;
5683
5684    fn into_v1(self) -> Result<Self::Output> {
5685        let Self { document, meta } = self;
5686        Ok(crate::v1::NesEventCapabilities {
5687            document: into_v1_default_on_error(document),
5688            meta: meta.into_v1()?,
5689        })
5690    }
5691}
5692
5693#[cfg(feature = "unstable_nes")]
5694impl IntoV2 for crate::v1::NesEventCapabilities {
5695    type Output = super::NesEventCapabilities;
5696
5697    fn into_v2(self) -> Result<Self::Output> {
5698        let Self { document, meta } = self;
5699        Ok(super::NesEventCapabilities {
5700            document: into_v2_default_on_error(document),
5701            meta: meta.into_v2()?,
5702        })
5703    }
5704}
5705
5706#[cfg(feature = "unstable_nes")]
5707impl IntoV1 for super::NesDocumentEventCapabilities {
5708    type Output = crate::v1::NesDocumentEventCapabilities;
5709
5710    fn into_v1(self) -> Result<Self::Output> {
5711        let Self {
5712            did_open,
5713            did_change,
5714            did_close,
5715            did_save,
5716            did_focus,
5717            meta,
5718        } = self;
5719        Ok(crate::v1::NesDocumentEventCapabilities {
5720            did_open: into_v1_default_on_error(did_open),
5721            did_change: into_v1_default_on_error(did_change),
5722            did_close: into_v1_default_on_error(did_close),
5723            did_save: into_v1_default_on_error(did_save),
5724            did_focus: into_v1_default_on_error(did_focus),
5725            meta: meta.into_v1()?,
5726        })
5727    }
5728}
5729
5730#[cfg(feature = "unstable_nes")]
5731impl IntoV2 for crate::v1::NesDocumentEventCapabilities {
5732    type Output = super::NesDocumentEventCapabilities;
5733
5734    fn into_v2(self) -> Result<Self::Output> {
5735        let Self {
5736            did_open,
5737            did_change,
5738            did_close,
5739            did_save,
5740            did_focus,
5741            meta,
5742        } = self;
5743        Ok(super::NesDocumentEventCapabilities {
5744            did_open: into_v2_default_on_error(did_open),
5745            did_change: into_v2_default_on_error(did_change),
5746            did_close: into_v2_default_on_error(did_close),
5747            did_save: into_v2_default_on_error(did_save),
5748            did_focus: into_v2_default_on_error(did_focus),
5749            meta: meta.into_v2()?,
5750        })
5751    }
5752}
5753
5754#[cfg(feature = "unstable_nes")]
5755impl IntoV1 for super::NesDocumentDidOpenCapabilities {
5756    type Output = crate::v1::NesDocumentDidOpenCapabilities;
5757
5758    fn into_v1(self) -> Result<Self::Output> {
5759        let Self { meta } = self;
5760        Ok(crate::v1::NesDocumentDidOpenCapabilities {
5761            meta: meta.into_v1()?,
5762        })
5763    }
5764}
5765
5766#[cfg(feature = "unstable_nes")]
5767impl IntoV2 for crate::v1::NesDocumentDidOpenCapabilities {
5768    type Output = super::NesDocumentDidOpenCapabilities;
5769
5770    fn into_v2(self) -> Result<Self::Output> {
5771        let Self { meta } = self;
5772        Ok(super::NesDocumentDidOpenCapabilities {
5773            meta: meta.into_v2()?,
5774        })
5775    }
5776}
5777
5778#[cfg(feature = "unstable_nes")]
5779impl IntoV1 for super::NesDocumentDidChangeCapabilities {
5780    type Output = crate::v1::NesDocumentDidChangeCapabilities;
5781
5782    fn into_v1(self) -> Result<Self::Output> {
5783        let Self { sync_kind, meta } = self;
5784        Ok(crate::v1::NesDocumentDidChangeCapabilities {
5785            sync_kind: sync_kind.into_v1()?,
5786            meta: meta.into_v1()?,
5787        })
5788    }
5789}
5790
5791#[cfg(feature = "unstable_nes")]
5792impl IntoV2 for crate::v1::NesDocumentDidChangeCapabilities {
5793    type Output = super::NesDocumentDidChangeCapabilities;
5794
5795    fn into_v2(self) -> Result<Self::Output> {
5796        let Self { sync_kind, meta } = self;
5797        Ok(super::NesDocumentDidChangeCapabilities {
5798            sync_kind: sync_kind.into_v2()?,
5799            meta: meta.into_v2()?,
5800        })
5801    }
5802}
5803
5804#[cfg(feature = "unstable_nes")]
5805impl IntoV1 for super::TextDocumentSyncKind {
5806    type Output = crate::v1::TextDocumentSyncKind;
5807
5808    fn into_v1(self) -> Result<Self::Output> {
5809        Ok(match self {
5810            Self::Full => crate::v1::TextDocumentSyncKind::Full,
5811            Self::Incremental => crate::v1::TextDocumentSyncKind::Incremental,
5812        })
5813    }
5814}
5815
5816#[cfg(feature = "unstable_nes")]
5817impl IntoV2 for crate::v1::TextDocumentSyncKind {
5818    type Output = super::TextDocumentSyncKind;
5819
5820    fn into_v2(self) -> Result<Self::Output> {
5821        Ok(match self {
5822            Self::Full => super::TextDocumentSyncKind::Full,
5823            Self::Incremental => super::TextDocumentSyncKind::Incremental,
5824        })
5825    }
5826}
5827
5828#[cfg(feature = "unstable_nes")]
5829impl IntoV1 for super::NesDocumentDidCloseCapabilities {
5830    type Output = crate::v1::NesDocumentDidCloseCapabilities;
5831
5832    fn into_v1(self) -> Result<Self::Output> {
5833        let Self { meta } = self;
5834        Ok(crate::v1::NesDocumentDidCloseCapabilities {
5835            meta: meta.into_v1()?,
5836        })
5837    }
5838}
5839
5840#[cfg(feature = "unstable_nes")]
5841impl IntoV2 for crate::v1::NesDocumentDidCloseCapabilities {
5842    type Output = super::NesDocumentDidCloseCapabilities;
5843
5844    fn into_v2(self) -> Result<Self::Output> {
5845        let Self { meta } = self;
5846        Ok(super::NesDocumentDidCloseCapabilities {
5847            meta: meta.into_v2()?,
5848        })
5849    }
5850}
5851
5852#[cfg(feature = "unstable_nes")]
5853impl IntoV1 for super::NesDocumentDidSaveCapabilities {
5854    type Output = crate::v1::NesDocumentDidSaveCapabilities;
5855
5856    fn into_v1(self) -> Result<Self::Output> {
5857        let Self { meta } = self;
5858        Ok(crate::v1::NesDocumentDidSaveCapabilities {
5859            meta: meta.into_v1()?,
5860        })
5861    }
5862}
5863
5864#[cfg(feature = "unstable_nes")]
5865impl IntoV2 for crate::v1::NesDocumentDidSaveCapabilities {
5866    type Output = super::NesDocumentDidSaveCapabilities;
5867
5868    fn into_v2(self) -> Result<Self::Output> {
5869        let Self { meta } = self;
5870        Ok(super::NesDocumentDidSaveCapabilities {
5871            meta: meta.into_v2()?,
5872        })
5873    }
5874}
5875
5876#[cfg(feature = "unstable_nes")]
5877impl IntoV1 for super::NesDocumentDidFocusCapabilities {
5878    type Output = crate::v1::NesDocumentDidFocusCapabilities;
5879
5880    fn into_v1(self) -> Result<Self::Output> {
5881        let Self { meta } = self;
5882        Ok(crate::v1::NesDocumentDidFocusCapabilities {
5883            meta: meta.into_v1()?,
5884        })
5885    }
5886}
5887
5888#[cfg(feature = "unstable_nes")]
5889impl IntoV2 for crate::v1::NesDocumentDidFocusCapabilities {
5890    type Output = super::NesDocumentDidFocusCapabilities;
5891
5892    fn into_v2(self) -> Result<Self::Output> {
5893        let Self { meta } = self;
5894        Ok(super::NesDocumentDidFocusCapabilities {
5895            meta: meta.into_v2()?,
5896        })
5897    }
5898}
5899
5900#[cfg(feature = "unstable_nes")]
5901impl IntoV1 for super::NesContextCapabilities {
5902    type Output = crate::v1::NesContextCapabilities;
5903
5904    fn into_v1(self) -> Result<Self::Output> {
5905        let Self {
5906            recent_files,
5907            related_snippets,
5908            edit_history,
5909            user_actions,
5910            open_files,
5911            diagnostics,
5912            meta,
5913        } = self;
5914        Ok(crate::v1::NesContextCapabilities {
5915            recent_files: into_v1_default_on_error(recent_files),
5916            related_snippets: into_v1_default_on_error(related_snippets),
5917            edit_history: into_v1_default_on_error(edit_history),
5918            user_actions: into_v1_default_on_error(user_actions),
5919            open_files: into_v1_default_on_error(open_files),
5920            diagnostics: into_v1_default_on_error(diagnostics),
5921            meta: meta.into_v1()?,
5922        })
5923    }
5924}
5925
5926#[cfg(feature = "unstable_nes")]
5927impl IntoV2 for crate::v1::NesContextCapabilities {
5928    type Output = super::NesContextCapabilities;
5929
5930    fn into_v2(self) -> Result<Self::Output> {
5931        let Self {
5932            recent_files,
5933            related_snippets,
5934            edit_history,
5935            user_actions,
5936            open_files,
5937            diagnostics,
5938            meta,
5939        } = self;
5940        Ok(super::NesContextCapabilities {
5941            recent_files: into_v2_default_on_error(recent_files),
5942            related_snippets: into_v2_default_on_error(related_snippets),
5943            edit_history: into_v2_default_on_error(edit_history),
5944            user_actions: into_v2_default_on_error(user_actions),
5945            open_files: into_v2_default_on_error(open_files),
5946            diagnostics: into_v2_default_on_error(diagnostics),
5947            meta: meta.into_v2()?,
5948        })
5949    }
5950}
5951
5952#[cfg(feature = "unstable_nes")]
5953impl IntoV1 for super::NesRecentFilesCapabilities {
5954    type Output = crate::v1::NesRecentFilesCapabilities;
5955
5956    fn into_v1(self) -> Result<Self::Output> {
5957        let Self { max_count, meta } = self;
5958        Ok(crate::v1::NesRecentFilesCapabilities {
5959            max_count: max_count.into_v1()?,
5960            meta: meta.into_v1()?,
5961        })
5962    }
5963}
5964
5965#[cfg(feature = "unstable_nes")]
5966impl IntoV2 for crate::v1::NesRecentFilesCapabilities {
5967    type Output = super::NesRecentFilesCapabilities;
5968
5969    fn into_v2(self) -> Result<Self::Output> {
5970        let Self { max_count, meta } = self;
5971        Ok(super::NesRecentFilesCapabilities {
5972            max_count: max_count.into_v2()?,
5973            meta: meta.into_v2()?,
5974        })
5975    }
5976}
5977
5978#[cfg(feature = "unstable_nes")]
5979impl IntoV1 for super::NesRelatedSnippetsCapabilities {
5980    type Output = crate::v1::NesRelatedSnippetsCapabilities;
5981
5982    fn into_v1(self) -> Result<Self::Output> {
5983        let Self { meta } = self;
5984        Ok(crate::v1::NesRelatedSnippetsCapabilities {
5985            meta: meta.into_v1()?,
5986        })
5987    }
5988}
5989
5990#[cfg(feature = "unstable_nes")]
5991impl IntoV2 for crate::v1::NesRelatedSnippetsCapabilities {
5992    type Output = super::NesRelatedSnippetsCapabilities;
5993
5994    fn into_v2(self) -> Result<Self::Output> {
5995        let Self { meta } = self;
5996        Ok(super::NesRelatedSnippetsCapabilities {
5997            meta: meta.into_v2()?,
5998        })
5999    }
6000}
6001
6002#[cfg(feature = "unstable_nes")]
6003impl IntoV1 for super::NesEditHistoryCapabilities {
6004    type Output = crate::v1::NesEditHistoryCapabilities;
6005
6006    fn into_v1(self) -> Result<Self::Output> {
6007        let Self { max_count, meta } = self;
6008        Ok(crate::v1::NesEditHistoryCapabilities {
6009            max_count: max_count.into_v1()?,
6010            meta: meta.into_v1()?,
6011        })
6012    }
6013}
6014
6015#[cfg(feature = "unstable_nes")]
6016impl IntoV2 for crate::v1::NesEditHistoryCapabilities {
6017    type Output = super::NesEditHistoryCapabilities;
6018
6019    fn into_v2(self) -> Result<Self::Output> {
6020        let Self { max_count, meta } = self;
6021        Ok(super::NesEditHistoryCapabilities {
6022            max_count: max_count.into_v2()?,
6023            meta: meta.into_v2()?,
6024        })
6025    }
6026}
6027
6028#[cfg(feature = "unstable_nes")]
6029impl IntoV1 for super::NesUserActionsCapabilities {
6030    type Output = crate::v1::NesUserActionsCapabilities;
6031
6032    fn into_v1(self) -> Result<Self::Output> {
6033        let Self { max_count, meta } = self;
6034        Ok(crate::v1::NesUserActionsCapabilities {
6035            max_count: max_count.into_v1()?,
6036            meta: meta.into_v1()?,
6037        })
6038    }
6039}
6040
6041#[cfg(feature = "unstable_nes")]
6042impl IntoV2 for crate::v1::NesUserActionsCapabilities {
6043    type Output = super::NesUserActionsCapabilities;
6044
6045    fn into_v2(self) -> Result<Self::Output> {
6046        let Self { max_count, meta } = self;
6047        Ok(super::NesUserActionsCapabilities {
6048            max_count: max_count.into_v2()?,
6049            meta: meta.into_v2()?,
6050        })
6051    }
6052}
6053
6054#[cfg(feature = "unstable_nes")]
6055impl IntoV1 for super::NesOpenFilesCapabilities {
6056    type Output = crate::v1::NesOpenFilesCapabilities;
6057
6058    fn into_v1(self) -> Result<Self::Output> {
6059        let Self { meta } = self;
6060        Ok(crate::v1::NesOpenFilesCapabilities {
6061            meta: meta.into_v1()?,
6062        })
6063    }
6064}
6065
6066#[cfg(feature = "unstable_nes")]
6067impl IntoV2 for crate::v1::NesOpenFilesCapabilities {
6068    type Output = super::NesOpenFilesCapabilities;
6069
6070    fn into_v2(self) -> Result<Self::Output> {
6071        let Self { meta } = self;
6072        Ok(super::NesOpenFilesCapabilities {
6073            meta: meta.into_v2()?,
6074        })
6075    }
6076}
6077
6078#[cfg(feature = "unstable_nes")]
6079impl IntoV1 for super::NesDiagnosticsCapabilities {
6080    type Output = crate::v1::NesDiagnosticsCapabilities;
6081
6082    fn into_v1(self) -> Result<Self::Output> {
6083        let Self { meta } = self;
6084        Ok(crate::v1::NesDiagnosticsCapabilities {
6085            meta: meta.into_v1()?,
6086        })
6087    }
6088}
6089
6090#[cfg(feature = "unstable_nes")]
6091impl IntoV2 for crate::v1::NesDiagnosticsCapabilities {
6092    type Output = super::NesDiagnosticsCapabilities;
6093
6094    fn into_v2(self) -> Result<Self::Output> {
6095        let Self { meta } = self;
6096        Ok(super::NesDiagnosticsCapabilities {
6097            meta: meta.into_v2()?,
6098        })
6099    }
6100}
6101
6102#[cfg(feature = "unstable_nes")]
6103impl IntoV1 for super::ClientNesCapabilities {
6104    type Output = crate::v1::ClientNesCapabilities;
6105
6106    fn into_v1(self) -> Result<Self::Output> {
6107        let Self {
6108            jump,
6109            rename,
6110            search_and_replace,
6111            meta,
6112        } = self;
6113        Ok(crate::v1::ClientNesCapabilities {
6114            jump: into_v1_default_on_error(jump),
6115            rename: into_v1_default_on_error(rename),
6116            search_and_replace: into_v1_default_on_error(search_and_replace),
6117            meta: meta.into_v1()?,
6118        })
6119    }
6120}
6121
6122#[cfg(feature = "unstable_nes")]
6123impl IntoV2 for crate::v1::ClientNesCapabilities {
6124    type Output = super::ClientNesCapabilities;
6125
6126    fn into_v2(self) -> Result<Self::Output> {
6127        let Self {
6128            jump,
6129            rename,
6130            search_and_replace,
6131            meta,
6132        } = self;
6133        Ok(super::ClientNesCapabilities {
6134            jump: into_v2_default_on_error(jump),
6135            rename: into_v2_default_on_error(rename),
6136            search_and_replace: into_v2_default_on_error(search_and_replace),
6137            meta: meta.into_v2()?,
6138        })
6139    }
6140}
6141
6142#[cfg(feature = "unstable_nes")]
6143impl IntoV1 for super::NesJumpCapabilities {
6144    type Output = crate::v1::NesJumpCapabilities;
6145
6146    fn into_v1(self) -> Result<Self::Output> {
6147        let Self { meta } = self;
6148        Ok(crate::v1::NesJumpCapabilities {
6149            meta: meta.into_v1()?,
6150        })
6151    }
6152}
6153
6154#[cfg(feature = "unstable_nes")]
6155impl IntoV2 for crate::v1::NesJumpCapabilities {
6156    type Output = super::NesJumpCapabilities;
6157
6158    fn into_v2(self) -> Result<Self::Output> {
6159        let Self { meta } = self;
6160        Ok(super::NesJumpCapabilities {
6161            meta: meta.into_v2()?,
6162        })
6163    }
6164}
6165
6166#[cfg(feature = "unstable_nes")]
6167impl IntoV1 for super::NesRenameCapabilities {
6168    type Output = crate::v1::NesRenameCapabilities;
6169
6170    fn into_v1(self) -> Result<Self::Output> {
6171        let Self { meta } = self;
6172        Ok(crate::v1::NesRenameCapabilities {
6173            meta: meta.into_v1()?,
6174        })
6175    }
6176}
6177
6178#[cfg(feature = "unstable_nes")]
6179impl IntoV2 for crate::v1::NesRenameCapabilities {
6180    type Output = super::NesRenameCapabilities;
6181
6182    fn into_v2(self) -> Result<Self::Output> {
6183        let Self { meta } = self;
6184        Ok(super::NesRenameCapabilities {
6185            meta: meta.into_v2()?,
6186        })
6187    }
6188}
6189
6190#[cfg(feature = "unstable_nes")]
6191impl IntoV1 for super::NesSearchAndReplaceCapabilities {
6192    type Output = crate::v1::NesSearchAndReplaceCapabilities;
6193
6194    fn into_v1(self) -> Result<Self::Output> {
6195        let Self { meta } = self;
6196        Ok(crate::v1::NesSearchAndReplaceCapabilities {
6197            meta: meta.into_v1()?,
6198        })
6199    }
6200}
6201
6202#[cfg(feature = "unstable_nes")]
6203impl IntoV2 for crate::v1::NesSearchAndReplaceCapabilities {
6204    type Output = super::NesSearchAndReplaceCapabilities;
6205
6206    fn into_v2(self) -> Result<Self::Output> {
6207        let Self { meta } = self;
6208        Ok(super::NesSearchAndReplaceCapabilities {
6209            meta: meta.into_v2()?,
6210        })
6211    }
6212}
6213
6214#[cfg(feature = "unstable_nes")]
6215impl IntoV1 for super::DidOpenDocumentNotification {
6216    type Output = crate::v1::DidOpenDocumentNotification;
6217
6218    fn into_v1(self) -> Result<Self::Output> {
6219        let Self {
6220            session_id,
6221            uri,
6222            language_id,
6223            version,
6224            text,
6225            meta,
6226        } = self;
6227        Ok(crate::v1::DidOpenDocumentNotification {
6228            session_id: session_id.into_v1()?,
6229            uri: uri.into_v1()?,
6230            language_id: language_id.into_v1()?,
6231            version: version.into_v1()?,
6232            text: text.into_v1()?,
6233            meta: meta.into_v1()?,
6234        })
6235    }
6236}
6237
6238#[cfg(feature = "unstable_nes")]
6239impl IntoV2 for crate::v1::DidOpenDocumentNotification {
6240    type Output = super::DidOpenDocumentNotification;
6241
6242    fn into_v2(self) -> Result<Self::Output> {
6243        let Self {
6244            session_id,
6245            uri,
6246            language_id,
6247            version,
6248            text,
6249            meta,
6250        } = self;
6251        Ok(super::DidOpenDocumentNotification {
6252            session_id: session_id.into_v2()?,
6253            uri: uri.into_v2()?,
6254            language_id: language_id.into_v2()?,
6255            version: version.into_v2()?,
6256            text: text.into_v2()?,
6257            meta: meta.into_v2()?,
6258        })
6259    }
6260}
6261
6262#[cfg(feature = "unstable_nes")]
6263impl IntoV1 for super::DidChangeDocumentNotification {
6264    type Output = crate::v1::DidChangeDocumentNotification;
6265
6266    fn into_v1(self) -> Result<Self::Output> {
6267        let Self {
6268            session_id,
6269            uri,
6270            version,
6271            content_changes,
6272            meta,
6273        } = self;
6274        Ok(crate::v1::DidChangeDocumentNotification {
6275            session_id: session_id.into_v1()?,
6276            uri: uri.into_v1()?,
6277            version: version.into_v1()?,
6278            content_changes: content_changes.into_v1()?,
6279            meta: meta.into_v1()?,
6280        })
6281    }
6282}
6283
6284#[cfg(feature = "unstable_nes")]
6285impl IntoV2 for crate::v1::DidChangeDocumentNotification {
6286    type Output = super::DidChangeDocumentNotification;
6287
6288    fn into_v2(self) -> Result<Self::Output> {
6289        let Self {
6290            session_id,
6291            uri,
6292            version,
6293            content_changes,
6294            meta,
6295        } = self;
6296        Ok(super::DidChangeDocumentNotification {
6297            session_id: session_id.into_v2()?,
6298            uri: uri.into_v2()?,
6299            version: version.into_v2()?,
6300            content_changes: content_changes.into_v2()?,
6301            meta: meta.into_v2()?,
6302        })
6303    }
6304}
6305
6306#[cfg(feature = "unstable_nes")]
6307impl IntoV1 for super::TextDocumentContentChangeEvent {
6308    type Output = crate::v1::TextDocumentContentChangeEvent;
6309
6310    fn into_v1(self) -> Result<Self::Output> {
6311        let Self { range, text, meta } = self;
6312        Ok(crate::v1::TextDocumentContentChangeEvent {
6313            range: range.into_v1()?,
6314            text: text.into_v1()?,
6315            meta: meta.into_v1()?,
6316        })
6317    }
6318}
6319
6320#[cfg(feature = "unstable_nes")]
6321impl IntoV2 for crate::v1::TextDocumentContentChangeEvent {
6322    type Output = super::TextDocumentContentChangeEvent;
6323
6324    fn into_v2(self) -> Result<Self::Output> {
6325        let Self { range, text, meta } = self;
6326        Ok(super::TextDocumentContentChangeEvent {
6327            range: range.into_v2()?,
6328            text: text.into_v2()?,
6329            meta: meta.into_v2()?,
6330        })
6331    }
6332}
6333
6334#[cfg(feature = "unstable_nes")]
6335impl IntoV1 for super::DidCloseDocumentNotification {
6336    type Output = crate::v1::DidCloseDocumentNotification;
6337
6338    fn into_v1(self) -> Result<Self::Output> {
6339        let Self {
6340            session_id,
6341            uri,
6342            meta,
6343        } = self;
6344        Ok(crate::v1::DidCloseDocumentNotification {
6345            session_id: session_id.into_v1()?,
6346            uri: uri.into_v1()?,
6347            meta: meta.into_v1()?,
6348        })
6349    }
6350}
6351
6352#[cfg(feature = "unstable_nes")]
6353impl IntoV2 for crate::v1::DidCloseDocumentNotification {
6354    type Output = super::DidCloseDocumentNotification;
6355
6356    fn into_v2(self) -> Result<Self::Output> {
6357        let Self {
6358            session_id,
6359            uri,
6360            meta,
6361        } = self;
6362        Ok(super::DidCloseDocumentNotification {
6363            session_id: session_id.into_v2()?,
6364            uri: uri.into_v2()?,
6365            meta: meta.into_v2()?,
6366        })
6367    }
6368}
6369
6370#[cfg(feature = "unstable_nes")]
6371impl IntoV1 for super::DidSaveDocumentNotification {
6372    type Output = crate::v1::DidSaveDocumentNotification;
6373
6374    fn into_v1(self) -> Result<Self::Output> {
6375        let Self {
6376            session_id,
6377            uri,
6378            meta,
6379        } = self;
6380        Ok(crate::v1::DidSaveDocumentNotification {
6381            session_id: session_id.into_v1()?,
6382            uri: uri.into_v1()?,
6383            meta: meta.into_v1()?,
6384        })
6385    }
6386}
6387
6388#[cfg(feature = "unstable_nes")]
6389impl IntoV2 for crate::v1::DidSaveDocumentNotification {
6390    type Output = super::DidSaveDocumentNotification;
6391
6392    fn into_v2(self) -> Result<Self::Output> {
6393        let Self {
6394            session_id,
6395            uri,
6396            meta,
6397        } = self;
6398        Ok(super::DidSaveDocumentNotification {
6399            session_id: session_id.into_v2()?,
6400            uri: uri.into_v2()?,
6401            meta: meta.into_v2()?,
6402        })
6403    }
6404}
6405
6406#[cfg(feature = "unstable_nes")]
6407impl IntoV1 for super::DidFocusDocumentNotification {
6408    type Output = crate::v1::DidFocusDocumentNotification;
6409
6410    fn into_v1(self) -> Result<Self::Output> {
6411        let Self {
6412            session_id,
6413            uri,
6414            version,
6415            position,
6416            visible_range,
6417            meta,
6418        } = self;
6419        Ok(crate::v1::DidFocusDocumentNotification {
6420            session_id: session_id.into_v1()?,
6421            uri: uri.into_v1()?,
6422            version: version.into_v1()?,
6423            position: position.into_v1()?,
6424            visible_range: visible_range.into_v1()?,
6425            meta: meta.into_v1()?,
6426        })
6427    }
6428}
6429
6430#[cfg(feature = "unstable_nes")]
6431impl IntoV2 for crate::v1::DidFocusDocumentNotification {
6432    type Output = super::DidFocusDocumentNotification;
6433
6434    fn into_v2(self) -> Result<Self::Output> {
6435        let Self {
6436            session_id,
6437            uri,
6438            version,
6439            position,
6440            visible_range,
6441            meta,
6442        } = self;
6443        Ok(super::DidFocusDocumentNotification {
6444            session_id: session_id.into_v2()?,
6445            uri: uri.into_v2()?,
6446            version: version.into_v2()?,
6447            position: position.into_v2()?,
6448            visible_range: visible_range.into_v2()?,
6449            meta: meta.into_v2()?,
6450        })
6451    }
6452}
6453
6454#[cfg(feature = "unstable_nes")]
6455impl IntoV1 for super::StartNesRequest {
6456    type Output = crate::v1::StartNesRequest;
6457
6458    fn into_v1(self) -> Result<Self::Output> {
6459        let Self {
6460            workspace_uri,
6461            workspace_folders,
6462            repository,
6463            meta,
6464        } = self;
6465        Ok(crate::v1::StartNesRequest {
6466            workspace_uri: workspace_uri.into_v1()?,
6467            workspace_folders: option_vec_into_v1_skip_errors(workspace_folders),
6468            repository: into_v1_default_on_error(repository),
6469            meta: meta.into_v1()?,
6470        })
6471    }
6472}
6473
6474#[cfg(feature = "unstable_nes")]
6475impl IntoV2 for crate::v1::StartNesRequest {
6476    type Output = super::StartNesRequest;
6477
6478    fn into_v2(self) -> Result<Self::Output> {
6479        let Self {
6480            workspace_uri,
6481            workspace_folders,
6482            repository,
6483            meta,
6484        } = self;
6485        Ok(super::StartNesRequest {
6486            workspace_uri: workspace_uri.into_v2()?,
6487            workspace_folders: option_vec_into_v2_skip_errors(workspace_folders),
6488            repository: into_v2_default_on_error(repository),
6489            meta: meta.into_v2()?,
6490        })
6491    }
6492}
6493
6494#[cfg(feature = "unstable_nes")]
6495impl IntoV1 for super::WorkspaceFolder {
6496    type Output = crate::v1::WorkspaceFolder;
6497
6498    fn into_v1(self) -> Result<Self::Output> {
6499        let Self { uri, name, meta } = self;
6500        Ok(crate::v1::WorkspaceFolder {
6501            uri: uri.into_v1()?,
6502            name: name.into_v1()?,
6503            meta: meta.into_v1()?,
6504        })
6505    }
6506}
6507
6508#[cfg(feature = "unstable_nes")]
6509impl IntoV2 for crate::v1::WorkspaceFolder {
6510    type Output = super::WorkspaceFolder;
6511
6512    fn into_v2(self) -> Result<Self::Output> {
6513        let Self { uri, name, meta } = self;
6514        Ok(super::WorkspaceFolder {
6515            uri: uri.into_v2()?,
6516            name: name.into_v2()?,
6517            meta: meta.into_v2()?,
6518        })
6519    }
6520}
6521
6522#[cfg(feature = "unstable_nes")]
6523impl IntoV1 for super::NesRepository {
6524    type Output = crate::v1::NesRepository;
6525
6526    fn into_v1(self) -> Result<Self::Output> {
6527        let Self {
6528            name,
6529            owner,
6530            remote_url,
6531            meta,
6532        } = self;
6533        Ok(crate::v1::NesRepository {
6534            name: name.into_v1()?,
6535            owner: owner.into_v1()?,
6536            remote_url: remote_url.into_v1()?,
6537            meta: meta.into_v1()?,
6538        })
6539    }
6540}
6541
6542#[cfg(feature = "unstable_nes")]
6543impl IntoV2 for crate::v1::NesRepository {
6544    type Output = super::NesRepository;
6545
6546    fn into_v2(self) -> Result<Self::Output> {
6547        let Self {
6548            name,
6549            owner,
6550            remote_url,
6551            meta,
6552        } = self;
6553        Ok(super::NesRepository {
6554            name: name.into_v2()?,
6555            owner: owner.into_v2()?,
6556            remote_url: remote_url.into_v2()?,
6557            meta: meta.into_v2()?,
6558        })
6559    }
6560}
6561
6562#[cfg(feature = "unstable_nes")]
6563impl IntoV1 for super::StartNesResponse {
6564    type Output = crate::v1::StartNesResponse;
6565
6566    fn into_v1(self) -> Result<Self::Output> {
6567        let Self { session_id, meta } = self;
6568        Ok(crate::v1::StartNesResponse {
6569            session_id: session_id.into_v1()?,
6570            meta: meta.into_v1()?,
6571        })
6572    }
6573}
6574
6575#[cfg(feature = "unstable_nes")]
6576impl IntoV2 for crate::v1::StartNesResponse {
6577    type Output = super::StartNesResponse;
6578
6579    fn into_v2(self) -> Result<Self::Output> {
6580        let Self { session_id, meta } = self;
6581        Ok(super::StartNesResponse {
6582            session_id: session_id.into_v2()?,
6583            meta: meta.into_v2()?,
6584        })
6585    }
6586}
6587
6588#[cfg(feature = "unstable_nes")]
6589impl IntoV1 for super::CloseNesRequest {
6590    type Output = crate::v1::CloseNesRequest;
6591
6592    fn into_v1(self) -> Result<Self::Output> {
6593        let Self { session_id, meta } = self;
6594        Ok(crate::v1::CloseNesRequest {
6595            session_id: session_id.into_v1()?,
6596            meta: meta.into_v1()?,
6597        })
6598    }
6599}
6600
6601#[cfg(feature = "unstable_nes")]
6602impl IntoV2 for crate::v1::CloseNesRequest {
6603    type Output = super::CloseNesRequest;
6604
6605    fn into_v2(self) -> Result<Self::Output> {
6606        let Self { session_id, meta } = self;
6607        Ok(super::CloseNesRequest {
6608            session_id: session_id.into_v2()?,
6609            meta: meta.into_v2()?,
6610        })
6611    }
6612}
6613
6614#[cfg(feature = "unstable_nes")]
6615impl IntoV1 for super::CloseNesResponse {
6616    type Output = crate::v1::CloseNesResponse;
6617
6618    fn into_v1(self) -> Result<Self::Output> {
6619        let Self { meta } = self;
6620        Ok(crate::v1::CloseNesResponse {
6621            meta: meta.into_v1()?,
6622        })
6623    }
6624}
6625
6626#[cfg(feature = "unstable_nes")]
6627impl IntoV2 for crate::v1::CloseNesResponse {
6628    type Output = super::CloseNesResponse;
6629
6630    fn into_v2(self) -> Result<Self::Output> {
6631        let Self { meta } = self;
6632        Ok(super::CloseNesResponse {
6633            meta: meta.into_v2()?,
6634        })
6635    }
6636}
6637
6638#[cfg(feature = "unstable_nes")]
6639impl IntoV1 for super::NesTriggerKind {
6640    type Output = crate::v1::NesTriggerKind;
6641
6642    fn into_v1(self) -> Result<Self::Output> {
6643        Ok(match self {
6644            Self::Automatic => crate::v1::NesTriggerKind::Automatic,
6645            Self::Diagnostic => crate::v1::NesTriggerKind::Diagnostic,
6646            Self::Manual => crate::v1::NesTriggerKind::Manual,
6647            Self::Other(value) => return Err(unknown_v2_enum_variant("NesTriggerKind", &value)),
6648        })
6649    }
6650}
6651
6652#[cfg(feature = "unstable_nes")]
6653impl IntoV2 for crate::v1::NesTriggerKind {
6654    type Output = super::NesTriggerKind;
6655
6656    fn into_v2(self) -> Result<Self::Output> {
6657        Ok(match self {
6658            Self::Automatic => super::NesTriggerKind::Automatic,
6659            Self::Diagnostic => super::NesTriggerKind::Diagnostic,
6660            Self::Manual => super::NesTriggerKind::Manual,
6661        })
6662    }
6663}
6664
6665#[cfg(feature = "unstable_nes")]
6666impl IntoV1 for super::SuggestNesRequest {
6667    type Output = crate::v1::SuggestNesRequest;
6668
6669    fn into_v1(self) -> Result<Self::Output> {
6670        let Self {
6671            session_id,
6672            uri,
6673            version,
6674            position,
6675            selection,
6676            trigger_kind,
6677            context,
6678            meta,
6679        } = self;
6680        Ok(crate::v1::SuggestNesRequest {
6681            session_id: session_id.into_v1()?,
6682            uri: uri.into_v1()?,
6683            version: version.into_v1()?,
6684            position: position.into_v1()?,
6685            selection: into_v1_default_on_error(selection),
6686            trigger_kind: trigger_kind.into_v1()?,
6687            context: into_v1_default_on_error(context),
6688            meta: meta.into_v1()?,
6689        })
6690    }
6691}
6692
6693#[cfg(feature = "unstable_nes")]
6694impl IntoV2 for crate::v1::SuggestNesRequest {
6695    type Output = super::SuggestNesRequest;
6696
6697    fn into_v2(self) -> Result<Self::Output> {
6698        let Self {
6699            session_id,
6700            uri,
6701            version,
6702            position,
6703            selection,
6704            trigger_kind,
6705            context,
6706            meta,
6707        } = self;
6708        Ok(super::SuggestNesRequest {
6709            session_id: session_id.into_v2()?,
6710            uri: uri.into_v2()?,
6711            version: version.into_v2()?,
6712            position: position.into_v2()?,
6713            selection: into_v2_default_on_error(selection),
6714            trigger_kind: trigger_kind.into_v2()?,
6715            context: into_v2_default_on_error(context),
6716            meta: meta.into_v2()?,
6717        })
6718    }
6719}
6720
6721#[cfg(feature = "unstable_nes")]
6722impl IntoV1 for super::NesSuggestContext {
6723    type Output = crate::v1::NesSuggestContext;
6724
6725    fn into_v1(self) -> Result<Self::Output> {
6726        let Self {
6727            recent_files,
6728            related_snippets,
6729            edit_history,
6730            user_actions,
6731            open_files,
6732            diagnostics,
6733            meta,
6734        } = self;
6735        Ok(crate::v1::NesSuggestContext {
6736            recent_files: option_vec_into_v1_skip_errors(recent_files),
6737            related_snippets: option_vec_into_v1_skip_errors(related_snippets),
6738            edit_history: option_vec_into_v1_skip_errors(edit_history),
6739            user_actions: option_vec_into_v1_skip_errors(user_actions),
6740            open_files: option_vec_into_v1_skip_errors(open_files),
6741            diagnostics: option_vec_into_v1_skip_errors(diagnostics),
6742            meta: meta.into_v1()?,
6743        })
6744    }
6745}
6746
6747#[cfg(feature = "unstable_nes")]
6748impl IntoV2 for crate::v1::NesSuggestContext {
6749    type Output = super::NesSuggestContext;
6750
6751    fn into_v2(self) -> Result<Self::Output> {
6752        let Self {
6753            recent_files,
6754            related_snippets,
6755            edit_history,
6756            user_actions,
6757            open_files,
6758            diagnostics,
6759            meta,
6760        } = self;
6761        Ok(super::NesSuggestContext {
6762            recent_files: option_vec_into_v2_skip_errors(recent_files),
6763            related_snippets: option_vec_into_v2_skip_errors(related_snippets),
6764            edit_history: option_vec_into_v2_skip_errors(edit_history),
6765            user_actions: option_vec_into_v2_skip_errors(user_actions),
6766            open_files: option_vec_into_v2_skip_errors(open_files),
6767            diagnostics: option_vec_into_v2_skip_errors(diagnostics),
6768            meta: meta.into_v2()?,
6769        })
6770    }
6771}
6772
6773#[cfg(feature = "unstable_nes")]
6774impl IntoV1 for super::NesRecentFile {
6775    type Output = crate::v1::NesRecentFile;
6776
6777    fn into_v1(self) -> Result<Self::Output> {
6778        let Self {
6779            uri,
6780            language_id,
6781            text,
6782            meta,
6783        } = self;
6784        Ok(crate::v1::NesRecentFile {
6785            uri: uri.into_v1()?,
6786            language_id: language_id.into_v1()?,
6787            text: text.into_v1()?,
6788            meta: meta.into_v1()?,
6789        })
6790    }
6791}
6792
6793#[cfg(feature = "unstable_nes")]
6794impl IntoV2 for crate::v1::NesRecentFile {
6795    type Output = super::NesRecentFile;
6796
6797    fn into_v2(self) -> Result<Self::Output> {
6798        let Self {
6799            uri,
6800            language_id,
6801            text,
6802            meta,
6803        } = self;
6804        Ok(super::NesRecentFile {
6805            uri: uri.into_v2()?,
6806            language_id: language_id.into_v2()?,
6807            text: text.into_v2()?,
6808            meta: meta.into_v2()?,
6809        })
6810    }
6811}
6812
6813#[cfg(feature = "unstable_nes")]
6814impl IntoV1 for super::NesRelatedSnippet {
6815    type Output = crate::v1::NesRelatedSnippet;
6816
6817    fn into_v1(self) -> Result<Self::Output> {
6818        let Self {
6819            uri,
6820            excerpts,
6821            meta,
6822        } = self;
6823        Ok(crate::v1::NesRelatedSnippet {
6824            uri: uri.into_v1()?,
6825            excerpts: excerpts.into_v1()?,
6826            meta: meta.into_v1()?,
6827        })
6828    }
6829}
6830
6831#[cfg(feature = "unstable_nes")]
6832impl IntoV2 for crate::v1::NesRelatedSnippet {
6833    type Output = super::NesRelatedSnippet;
6834
6835    fn into_v2(self) -> Result<Self::Output> {
6836        let Self {
6837            uri,
6838            excerpts,
6839            meta,
6840        } = self;
6841        Ok(super::NesRelatedSnippet {
6842            uri: uri.into_v2()?,
6843            excerpts: excerpts.into_v2()?,
6844            meta: meta.into_v2()?,
6845        })
6846    }
6847}
6848
6849#[cfg(feature = "unstable_nes")]
6850impl IntoV1 for super::NesExcerpt {
6851    type Output = crate::v1::NesExcerpt;
6852
6853    fn into_v1(self) -> Result<Self::Output> {
6854        let Self {
6855            start_line,
6856            end_line,
6857            text,
6858            meta,
6859        } = self;
6860        Ok(crate::v1::NesExcerpt {
6861            start_line: start_line.into_v1()?,
6862            end_line: end_line.into_v1()?,
6863            text: text.into_v1()?,
6864            meta: meta.into_v1()?,
6865        })
6866    }
6867}
6868
6869#[cfg(feature = "unstable_nes")]
6870impl IntoV2 for crate::v1::NesExcerpt {
6871    type Output = super::NesExcerpt;
6872
6873    fn into_v2(self) -> Result<Self::Output> {
6874        let Self {
6875            start_line,
6876            end_line,
6877            text,
6878            meta,
6879        } = self;
6880        Ok(super::NesExcerpt {
6881            start_line: start_line.into_v2()?,
6882            end_line: end_line.into_v2()?,
6883            text: text.into_v2()?,
6884            meta: meta.into_v2()?,
6885        })
6886    }
6887}
6888
6889#[cfg(feature = "unstable_nes")]
6890impl IntoV1 for super::NesEditHistoryEntry {
6891    type Output = crate::v1::NesEditHistoryEntry;
6892
6893    fn into_v1(self) -> Result<Self::Output> {
6894        let Self { uri, diff, meta } = self;
6895        Ok(crate::v1::NesEditHistoryEntry {
6896            uri: uri.into_v1()?,
6897            diff: diff.into_v1()?,
6898            meta: meta.into_v1()?,
6899        })
6900    }
6901}
6902
6903#[cfg(feature = "unstable_nes")]
6904impl IntoV2 for crate::v1::NesEditHistoryEntry {
6905    type Output = super::NesEditHistoryEntry;
6906
6907    fn into_v2(self) -> Result<Self::Output> {
6908        let Self { uri, diff, meta } = self;
6909        Ok(super::NesEditHistoryEntry {
6910            uri: uri.into_v2()?,
6911            diff: diff.into_v2()?,
6912            meta: meta.into_v2()?,
6913        })
6914    }
6915}
6916
6917#[cfg(feature = "unstable_nes")]
6918impl IntoV1 for super::NesUserAction {
6919    type Output = crate::v1::NesUserAction;
6920
6921    fn into_v1(self) -> Result<Self::Output> {
6922        let Self {
6923            action,
6924            uri,
6925            position,
6926            timestamp_ms,
6927            meta,
6928        } = self;
6929        Ok(crate::v1::NesUserAction {
6930            action: action.into_v1()?,
6931            uri: uri.into_v1()?,
6932            position: position.into_v1()?,
6933            timestamp_ms: timestamp_ms.into_v1()?,
6934            meta: meta.into_v1()?,
6935        })
6936    }
6937}
6938
6939#[cfg(feature = "unstable_nes")]
6940impl IntoV2 for crate::v1::NesUserAction {
6941    type Output = super::NesUserAction;
6942
6943    fn into_v2(self) -> Result<Self::Output> {
6944        let Self {
6945            action,
6946            uri,
6947            position,
6948            timestamp_ms,
6949            meta,
6950        } = self;
6951        Ok(super::NesUserAction {
6952            action: action.into_v2()?,
6953            uri: uri.into_v2()?,
6954            position: position.into_v2()?,
6955            timestamp_ms: timestamp_ms.into_v2()?,
6956            meta: meta.into_v2()?,
6957        })
6958    }
6959}
6960
6961#[cfg(feature = "unstable_nes")]
6962impl IntoV1 for super::NesOpenFile {
6963    type Output = crate::v1::NesOpenFile;
6964
6965    fn into_v1(self) -> Result<Self::Output> {
6966        let Self {
6967            uri,
6968            language_id,
6969            visible_range,
6970            last_focused_ms,
6971            meta,
6972        } = self;
6973        Ok(crate::v1::NesOpenFile {
6974            uri: uri.into_v1()?,
6975            language_id: language_id.into_v1()?,
6976            visible_range: into_v1_default_on_error(visible_range),
6977            last_focused_ms: into_v1_default_on_error(last_focused_ms),
6978            meta: meta.into_v1()?,
6979        })
6980    }
6981}
6982
6983#[cfg(feature = "unstable_nes")]
6984impl IntoV2 for crate::v1::NesOpenFile {
6985    type Output = super::NesOpenFile;
6986
6987    fn into_v2(self) -> Result<Self::Output> {
6988        let Self {
6989            uri,
6990            language_id,
6991            visible_range,
6992            last_focused_ms,
6993            meta,
6994        } = self;
6995        Ok(super::NesOpenFile {
6996            uri: uri.into_v2()?,
6997            language_id: language_id.into_v2()?,
6998            visible_range: into_v2_default_on_error(visible_range),
6999            last_focused_ms: into_v2_default_on_error(last_focused_ms),
7000            meta: meta.into_v2()?,
7001        })
7002    }
7003}
7004
7005#[cfg(feature = "unstable_nes")]
7006impl IntoV1 for super::NesDiagnostic {
7007    type Output = crate::v1::NesDiagnostic;
7008
7009    fn into_v1(self) -> Result<Self::Output> {
7010        let Self {
7011            uri,
7012            range,
7013            severity,
7014            message,
7015            meta,
7016        } = self;
7017        Ok(crate::v1::NesDiagnostic {
7018            uri: uri.into_v1()?,
7019            range: range.into_v1()?,
7020            severity: severity.into_v1()?,
7021            message: message.into_v1()?,
7022            meta: meta.into_v1()?,
7023        })
7024    }
7025}
7026
7027#[cfg(feature = "unstable_nes")]
7028impl IntoV2 for crate::v1::NesDiagnostic {
7029    type Output = super::NesDiagnostic;
7030
7031    fn into_v2(self) -> Result<Self::Output> {
7032        let Self {
7033            uri,
7034            range,
7035            severity,
7036            message,
7037            meta,
7038        } = self;
7039        Ok(super::NesDiagnostic {
7040            uri: uri.into_v2()?,
7041            range: range.into_v2()?,
7042            severity: severity.into_v2()?,
7043            message: message.into_v2()?,
7044            meta: meta.into_v2()?,
7045        })
7046    }
7047}
7048
7049#[cfg(feature = "unstable_nes")]
7050impl IntoV1 for super::NesDiagnosticSeverity {
7051    type Output = crate::v1::NesDiagnosticSeverity;
7052
7053    fn into_v1(self) -> Result<Self::Output> {
7054        Ok(match self {
7055            Self::Error => crate::v1::NesDiagnosticSeverity::Error,
7056            Self::Warning => crate::v1::NesDiagnosticSeverity::Warning,
7057            Self::Information => crate::v1::NesDiagnosticSeverity::Information,
7058            Self::Hint => crate::v1::NesDiagnosticSeverity::Hint,
7059            Self::Other(value) => {
7060                return Err(unknown_v2_enum_variant("NesDiagnosticSeverity", &value));
7061            }
7062        })
7063    }
7064}
7065
7066#[cfg(feature = "unstable_nes")]
7067impl IntoV2 for crate::v1::NesDiagnosticSeverity {
7068    type Output = super::NesDiagnosticSeverity;
7069
7070    fn into_v2(self) -> Result<Self::Output> {
7071        Ok(match self {
7072            Self::Error => super::NesDiagnosticSeverity::Error,
7073            Self::Warning => super::NesDiagnosticSeverity::Warning,
7074            Self::Information => super::NesDiagnosticSeverity::Information,
7075            Self::Hint => super::NesDiagnosticSeverity::Hint,
7076        })
7077    }
7078}
7079
7080#[cfg(feature = "unstable_nes")]
7081impl IntoV1 for super::SuggestNesResponse {
7082    type Output = crate::v1::SuggestNesResponse;
7083
7084    fn into_v1(self) -> Result<Self::Output> {
7085        let Self { suggestions, meta } = self;
7086        Ok(crate::v1::SuggestNesResponse {
7087            suggestions: into_v1_vec_skip_errors(suggestions),
7088            meta: meta.into_v1()?,
7089        })
7090    }
7091}
7092
7093#[cfg(feature = "unstable_nes")]
7094impl IntoV2 for crate::v1::SuggestNesResponse {
7095    type Output = super::SuggestNesResponse;
7096
7097    fn into_v2(self) -> Result<Self::Output> {
7098        let Self { suggestions, meta } = self;
7099        Ok(super::SuggestNesResponse {
7100            suggestions: into_v2_vec_skip_errors(suggestions),
7101            meta: meta.into_v2()?,
7102        })
7103    }
7104}
7105
7106#[cfg(feature = "unstable_nes")]
7107impl IntoV1 for super::NesSuggestion {
7108    type Output = crate::v1::NesSuggestion;
7109
7110    fn into_v1(self) -> Result<Self::Output> {
7111        Ok(match self {
7112            Self::Edit(value) => crate::v1::NesSuggestion::Edit(value.into_v1()?),
7113            Self::Jump(value) => crate::v1::NesSuggestion::Jump(value.into_v1()?),
7114            Self::Rename(value) => crate::v1::NesSuggestion::Rename(value.into_v1()?),
7115            Self::SearchAndReplace(value) => {
7116                crate::v1::NesSuggestion::SearchAndReplace(value.into_v1()?)
7117            }
7118            Self::Other(value) => {
7119                return Err(unknown_v2_enum_variant("NesSuggestion", &value.kind));
7120            }
7121        })
7122    }
7123}
7124
7125#[cfg(feature = "unstable_nes")]
7126impl IntoV2 for crate::v1::NesSuggestion {
7127    type Output = super::NesSuggestion;
7128
7129    fn into_v2(self) -> Result<Self::Output> {
7130        Ok(match self {
7131            Self::Edit(value) => super::NesSuggestion::Edit(value.into_v2()?),
7132            Self::Jump(value) => super::NesSuggestion::Jump(value.into_v2()?),
7133            Self::Rename(value) => super::NesSuggestion::Rename(value.into_v2()?),
7134            Self::SearchAndReplace(value) => {
7135                super::NesSuggestion::SearchAndReplace(value.into_v2()?)
7136            }
7137        })
7138    }
7139}
7140
7141#[cfg(feature = "unstable_nes")]
7142impl IntoV1 for super::NesEditSuggestion {
7143    type Output = crate::v1::NesEditSuggestion;
7144
7145    fn into_v1(self) -> Result<Self::Output> {
7146        let Self {
7147            id,
7148            uri,
7149            edits,
7150            cursor_position,
7151            meta,
7152        } = self;
7153        Ok(crate::v1::NesEditSuggestion {
7154            id: id.into_v1()?,
7155            uri: uri.into_v1()?,
7156            edits: edits.into_v1()?,
7157            cursor_position: into_v1_default_on_error(cursor_position),
7158            meta: meta.into_v1()?,
7159        })
7160    }
7161}
7162
7163#[cfg(feature = "unstable_nes")]
7164impl IntoV2 for crate::v1::NesEditSuggestion {
7165    type Output = super::NesEditSuggestion;
7166
7167    fn into_v2(self) -> Result<Self::Output> {
7168        let Self {
7169            id,
7170            uri,
7171            edits,
7172            cursor_position,
7173            meta,
7174        } = self;
7175        Ok(super::NesEditSuggestion {
7176            id: id.into_v2()?,
7177            uri: uri.into_v2()?,
7178            edits: edits.into_v2()?,
7179            cursor_position: into_v2_default_on_error(cursor_position),
7180            meta: meta.into_v2()?,
7181        })
7182    }
7183}
7184
7185#[cfg(feature = "unstable_nes")]
7186impl IntoV1 for super::NesTextEdit {
7187    type Output = crate::v1::NesTextEdit;
7188
7189    fn into_v1(self) -> Result<Self::Output> {
7190        let Self {
7191            range,
7192            new_text,
7193            meta,
7194        } = self;
7195        Ok(crate::v1::NesTextEdit {
7196            range: range.into_v1()?,
7197            new_text: new_text.into_v1()?,
7198            meta: meta.into_v1()?,
7199        })
7200    }
7201}
7202
7203#[cfg(feature = "unstable_nes")]
7204impl IntoV2 for crate::v1::NesTextEdit {
7205    type Output = super::NesTextEdit;
7206
7207    fn into_v2(self) -> Result<Self::Output> {
7208        let Self {
7209            range,
7210            new_text,
7211            meta,
7212        } = self;
7213        Ok(super::NesTextEdit {
7214            range: range.into_v2()?,
7215            new_text: new_text.into_v2()?,
7216            meta: meta.into_v2()?,
7217        })
7218    }
7219}
7220
7221#[cfg(feature = "unstable_nes")]
7222impl IntoV1 for super::NesJumpSuggestion {
7223    type Output = crate::v1::NesJumpSuggestion;
7224
7225    fn into_v1(self) -> Result<Self::Output> {
7226        let Self {
7227            id,
7228            uri,
7229            position,
7230            meta,
7231        } = self;
7232        Ok(crate::v1::NesJumpSuggestion {
7233            id: id.into_v1()?,
7234            uri: uri.into_v1()?,
7235            position: position.into_v1()?,
7236            meta: meta.into_v1()?,
7237        })
7238    }
7239}
7240
7241#[cfg(feature = "unstable_nes")]
7242impl IntoV2 for crate::v1::NesJumpSuggestion {
7243    type Output = super::NesJumpSuggestion;
7244
7245    fn into_v2(self) -> Result<Self::Output> {
7246        let Self {
7247            id,
7248            uri,
7249            position,
7250            meta,
7251        } = self;
7252        Ok(super::NesJumpSuggestion {
7253            id: id.into_v2()?,
7254            uri: uri.into_v2()?,
7255            position: position.into_v2()?,
7256            meta: meta.into_v2()?,
7257        })
7258    }
7259}
7260
7261#[cfg(feature = "unstable_nes")]
7262impl IntoV1 for super::NesRenameSuggestion {
7263    type Output = crate::v1::NesRenameSuggestion;
7264
7265    fn into_v1(self) -> Result<Self::Output> {
7266        let Self {
7267            id,
7268            uri,
7269            position,
7270            new_name,
7271            meta,
7272        } = self;
7273        Ok(crate::v1::NesRenameSuggestion {
7274            id: id.into_v1()?,
7275            uri: uri.into_v1()?,
7276            position: position.into_v1()?,
7277            new_name: new_name.into_v1()?,
7278            meta: meta.into_v1()?,
7279        })
7280    }
7281}
7282
7283#[cfg(feature = "unstable_nes")]
7284impl IntoV2 for crate::v1::NesRenameSuggestion {
7285    type Output = super::NesRenameSuggestion;
7286
7287    fn into_v2(self) -> Result<Self::Output> {
7288        let Self {
7289            id,
7290            uri,
7291            position,
7292            new_name,
7293            meta,
7294        } = self;
7295        Ok(super::NesRenameSuggestion {
7296            id: id.into_v2()?,
7297            uri: uri.into_v2()?,
7298            position: position.into_v2()?,
7299            new_name: new_name.into_v2()?,
7300            meta: meta.into_v2()?,
7301        })
7302    }
7303}
7304
7305#[cfg(feature = "unstable_nes")]
7306impl IntoV1 for super::NesSearchAndReplaceSuggestion {
7307    type Output = crate::v1::NesSearchAndReplaceSuggestion;
7308
7309    fn into_v1(self) -> Result<Self::Output> {
7310        let Self {
7311            id,
7312            uri,
7313            search,
7314            replace,
7315            is_regex,
7316            meta,
7317        } = self;
7318        Ok(crate::v1::NesSearchAndReplaceSuggestion {
7319            id: id.into_v1()?,
7320            uri: uri.into_v1()?,
7321            search: search.into_v1()?,
7322            replace: replace.into_v1()?,
7323            is_regex: is_regex.into_v1()?,
7324            meta: meta.into_v1()?,
7325        })
7326    }
7327}
7328
7329#[cfg(feature = "unstable_nes")]
7330impl IntoV2 for crate::v1::NesSearchAndReplaceSuggestion {
7331    type Output = super::NesSearchAndReplaceSuggestion;
7332
7333    fn into_v2(self) -> Result<Self::Output> {
7334        let Self {
7335            id,
7336            uri,
7337            search,
7338            replace,
7339            is_regex,
7340            meta,
7341        } = self;
7342        Ok(super::NesSearchAndReplaceSuggestion {
7343            id: id.into_v2()?,
7344            uri: uri.into_v2()?,
7345            search: search.into_v2()?,
7346            replace: replace.into_v2()?,
7347            is_regex: is_regex.into_v2()?,
7348            meta: meta.into_v2()?,
7349        })
7350    }
7351}
7352
7353#[cfg(feature = "unstable_nes")]
7354impl IntoV1 for super::AcceptNesNotification {
7355    type Output = crate::v1::AcceptNesNotification;
7356
7357    fn into_v1(self) -> Result<Self::Output> {
7358        let Self {
7359            session_id,
7360            id,
7361            meta,
7362        } = self;
7363        Ok(crate::v1::AcceptNesNotification {
7364            session_id: session_id.into_v1()?,
7365            id: id.into_v1()?,
7366            meta: meta.into_v1()?,
7367        })
7368    }
7369}
7370
7371#[cfg(feature = "unstable_nes")]
7372impl IntoV2 for crate::v1::AcceptNesNotification {
7373    type Output = super::AcceptNesNotification;
7374
7375    fn into_v2(self) -> Result<Self::Output> {
7376        let Self {
7377            session_id,
7378            id,
7379            meta,
7380        } = self;
7381        Ok(super::AcceptNesNotification {
7382            session_id: session_id.into_v2()?,
7383            id: id.into_v2()?,
7384            meta: meta.into_v2()?,
7385        })
7386    }
7387}
7388
7389#[cfg(feature = "unstable_nes")]
7390impl IntoV1 for super::RejectNesNotification {
7391    type Output = crate::v1::RejectNesNotification;
7392
7393    fn into_v1(self) -> Result<Self::Output> {
7394        let Self {
7395            session_id,
7396            id,
7397            reason,
7398            meta,
7399        } = self;
7400        Ok(crate::v1::RejectNesNotification {
7401            session_id: session_id.into_v1()?,
7402            id: id.into_v1()?,
7403            reason: into_v1_default_on_error(reason),
7404            meta: meta.into_v1()?,
7405        })
7406    }
7407}
7408
7409#[cfg(feature = "unstable_nes")]
7410impl IntoV2 for crate::v1::RejectNesNotification {
7411    type Output = super::RejectNesNotification;
7412
7413    fn into_v2(self) -> Result<Self::Output> {
7414        let Self {
7415            session_id,
7416            id,
7417            reason,
7418            meta,
7419        } = self;
7420        Ok(super::RejectNesNotification {
7421            session_id: session_id.into_v2()?,
7422            id: id.into_v2()?,
7423            reason: into_v2_default_on_error(reason),
7424            meta: meta.into_v2()?,
7425        })
7426    }
7427}
7428
7429#[cfg(feature = "unstable_nes")]
7430impl IntoV1 for super::NesRejectReason {
7431    type Output = crate::v1::NesRejectReason;
7432
7433    fn into_v1(self) -> Result<Self::Output> {
7434        Ok(match self {
7435            Self::Rejected => crate::v1::NesRejectReason::Rejected,
7436            Self::Ignored => crate::v1::NesRejectReason::Ignored,
7437            Self::Replaced => crate::v1::NesRejectReason::Replaced,
7438            Self::Cancelled => crate::v1::NesRejectReason::Cancelled,
7439            Self::Other(value) => return Err(unknown_v2_enum_variant("NesRejectReason", &value)),
7440        })
7441    }
7442}
7443
7444#[cfg(feature = "unstable_nes")]
7445impl IntoV2 for crate::v1::NesRejectReason {
7446    type Output = super::NesRejectReason;
7447
7448    fn into_v2(self) -> Result<Self::Output> {
7449        Ok(match self {
7450            Self::Rejected => super::NesRejectReason::Rejected,
7451            Self::Ignored => super::NesRejectReason::Ignored,
7452            Self::Replaced => super::NesRejectReason::Replaced,
7453            Self::Cancelled => super::NesRejectReason::Cancelled,
7454        })
7455    }
7456}
7457
7458#[cfg(feature = "unstable_elicitation")]
7459impl IntoV1 for super::ElicitationId {
7460    type Output = crate::v1::ElicitationId;
7461
7462    fn into_v1(self) -> Result<Self::Output> {
7463        Ok(crate::v1::ElicitationId(self.0.into_v1()?))
7464    }
7465}
7466
7467#[cfg(feature = "unstable_elicitation")]
7468impl IntoV2 for crate::v1::ElicitationId {
7469    type Output = super::ElicitationId;
7470
7471    fn into_v2(self) -> Result<Self::Output> {
7472        Ok(super::ElicitationId(self.0.into_v2()?))
7473    }
7474}
7475
7476#[cfg(feature = "unstable_elicitation")]
7477impl IntoV1 for super::StringFormat {
7478    type Output = crate::v1::StringFormat;
7479
7480    fn into_v1(self) -> Result<Self::Output> {
7481        Ok(match self {
7482            Self::Email => crate::v1::StringFormat::Email,
7483            Self::Uri => crate::v1::StringFormat::Uri,
7484            Self::Date => crate::v1::StringFormat::Date,
7485            Self::DateTime => crate::v1::StringFormat::DateTime,
7486            Self::Other(value) => return Err(unknown_v2_enum_variant("StringFormat", &value)),
7487        })
7488    }
7489}
7490
7491#[cfg(feature = "unstable_elicitation")]
7492impl IntoV2 for crate::v1::StringFormat {
7493    type Output = super::StringFormat;
7494
7495    fn into_v2(self) -> Result<Self::Output> {
7496        Ok(match self {
7497            Self::Email => super::StringFormat::Email,
7498            Self::Uri => super::StringFormat::Uri,
7499            Self::Date => super::StringFormat::Date,
7500            Self::DateTime => super::StringFormat::DateTime,
7501        })
7502    }
7503}
7504
7505#[cfg(feature = "unstable_elicitation")]
7506impl IntoV1 for super::ElicitationSchemaType {
7507    type Output = crate::v1::ElicitationSchemaType;
7508
7509    fn into_v1(self) -> Result<Self::Output> {
7510        Ok(match self {
7511            Self::Object => crate::v1::ElicitationSchemaType::Object,
7512        })
7513    }
7514}
7515
7516#[cfg(feature = "unstable_elicitation")]
7517impl IntoV2 for crate::v1::ElicitationSchemaType {
7518    type Output = super::ElicitationSchemaType;
7519
7520    fn into_v2(self) -> Result<Self::Output> {
7521        Ok(match self {
7522            Self::Object => super::ElicitationSchemaType::Object,
7523        })
7524    }
7525}
7526
7527#[cfg(feature = "unstable_elicitation")]
7528impl IntoV1 for super::EnumOption {
7529    type Output = crate::v1::EnumOption;
7530
7531    fn into_v1(self) -> Result<Self::Output> {
7532        let Self { value, title, meta } = self;
7533        Ok(crate::v1::EnumOption {
7534            value: value.into_v1()?,
7535            title: title.into_v1()?,
7536            meta: meta.into_v1()?,
7537        })
7538    }
7539}
7540
7541#[cfg(feature = "unstable_elicitation")]
7542impl IntoV2 for crate::v1::EnumOption {
7543    type Output = super::EnumOption;
7544
7545    fn into_v2(self) -> Result<Self::Output> {
7546        let Self { value, title, meta } = self;
7547        Ok(super::EnumOption {
7548            value: value.into_v2()?,
7549            title: title.into_v2()?,
7550            meta: meta.into_v2()?,
7551        })
7552    }
7553}
7554
7555#[cfg(feature = "unstable_elicitation")]
7556impl IntoV1 for super::StringPropertySchema {
7557    type Output = crate::v1::StringPropertySchema;
7558
7559    fn into_v1(self) -> Result<Self::Output> {
7560        let Self {
7561            title,
7562            description,
7563            min_length,
7564            max_length,
7565            pattern,
7566            format,
7567            default,
7568            enum_values,
7569            one_of,
7570            meta,
7571        } = self;
7572        Ok(crate::v1::StringPropertySchema {
7573            title: title.into_v1()?,
7574            description: description.into_v1()?,
7575            min_length: min_length.into_v1()?,
7576            max_length: max_length.into_v1()?,
7577            pattern: pattern.into_v1()?,
7578            format: format.into_v1()?,
7579            default: default.into_v1()?,
7580            enum_values: enum_values.into_v1()?,
7581            one_of: one_of.into_v1()?,
7582            meta: meta.into_v1()?,
7583        })
7584    }
7585}
7586
7587#[cfg(feature = "unstable_elicitation")]
7588impl IntoV2 for crate::v1::StringPropertySchema {
7589    type Output = super::StringPropertySchema;
7590
7591    fn into_v2(self) -> Result<Self::Output> {
7592        let Self {
7593            title,
7594            description,
7595            min_length,
7596            max_length,
7597            pattern,
7598            format,
7599            default,
7600            enum_values,
7601            one_of,
7602            meta,
7603        } = self;
7604        Ok(super::StringPropertySchema {
7605            title: title.into_v2()?,
7606            description: description.into_v2()?,
7607            min_length: min_length.into_v2()?,
7608            max_length: max_length.into_v2()?,
7609            pattern: pattern.into_v2()?,
7610            format: format.into_v2()?,
7611            default: default.into_v2()?,
7612            enum_values: enum_values.into_v2()?,
7613            one_of: one_of.into_v2()?,
7614            meta: meta.into_v2()?,
7615        })
7616    }
7617}
7618
7619#[cfg(feature = "unstable_elicitation")]
7620impl IntoV1 for super::NumberPropertySchema {
7621    type Output = crate::v1::NumberPropertySchema;
7622
7623    fn into_v1(self) -> Result<Self::Output> {
7624        let Self {
7625            title,
7626            description,
7627            minimum,
7628            maximum,
7629            default,
7630            meta,
7631        } = self;
7632        Ok(crate::v1::NumberPropertySchema {
7633            title: title.into_v1()?,
7634            description: description.into_v1()?,
7635            minimum: minimum.into_v1()?,
7636            maximum: maximum.into_v1()?,
7637            default: default.into_v1()?,
7638            meta: meta.into_v1()?,
7639        })
7640    }
7641}
7642
7643#[cfg(feature = "unstable_elicitation")]
7644impl IntoV2 for crate::v1::NumberPropertySchema {
7645    type Output = super::NumberPropertySchema;
7646
7647    fn into_v2(self) -> Result<Self::Output> {
7648        let Self {
7649            title,
7650            description,
7651            minimum,
7652            maximum,
7653            default,
7654            meta,
7655        } = self;
7656        Ok(super::NumberPropertySchema {
7657            title: title.into_v2()?,
7658            description: description.into_v2()?,
7659            minimum: minimum.into_v2()?,
7660            maximum: maximum.into_v2()?,
7661            default: default.into_v2()?,
7662            meta: meta.into_v2()?,
7663        })
7664    }
7665}
7666
7667#[cfg(feature = "unstable_elicitation")]
7668impl IntoV1 for super::IntegerPropertySchema {
7669    type Output = crate::v1::IntegerPropertySchema;
7670
7671    fn into_v1(self) -> Result<Self::Output> {
7672        let Self {
7673            title,
7674            description,
7675            minimum,
7676            maximum,
7677            default,
7678            meta,
7679        } = self;
7680        Ok(crate::v1::IntegerPropertySchema {
7681            title: title.into_v1()?,
7682            description: description.into_v1()?,
7683            minimum: minimum.into_v1()?,
7684            maximum: maximum.into_v1()?,
7685            default: default.into_v1()?,
7686            meta: meta.into_v1()?,
7687        })
7688    }
7689}
7690
7691#[cfg(feature = "unstable_elicitation")]
7692impl IntoV2 for crate::v1::IntegerPropertySchema {
7693    type Output = super::IntegerPropertySchema;
7694
7695    fn into_v2(self) -> Result<Self::Output> {
7696        let Self {
7697            title,
7698            description,
7699            minimum,
7700            maximum,
7701            default,
7702            meta,
7703        } = self;
7704        Ok(super::IntegerPropertySchema {
7705            title: title.into_v2()?,
7706            description: description.into_v2()?,
7707            minimum: minimum.into_v2()?,
7708            maximum: maximum.into_v2()?,
7709            default: default.into_v2()?,
7710            meta: meta.into_v2()?,
7711        })
7712    }
7713}
7714
7715#[cfg(feature = "unstable_elicitation")]
7716impl IntoV1 for super::BooleanPropertySchema {
7717    type Output = crate::v1::BooleanPropertySchema;
7718
7719    fn into_v1(self) -> Result<Self::Output> {
7720        let Self {
7721            title,
7722            description,
7723            default,
7724            meta,
7725        } = self;
7726        Ok(crate::v1::BooleanPropertySchema {
7727            title: title.into_v1()?,
7728            description: description.into_v1()?,
7729            default: default.into_v1()?,
7730            meta: meta.into_v1()?,
7731        })
7732    }
7733}
7734
7735#[cfg(feature = "unstable_elicitation")]
7736impl IntoV2 for crate::v1::BooleanPropertySchema {
7737    type Output = super::BooleanPropertySchema;
7738
7739    fn into_v2(self) -> Result<Self::Output> {
7740        let Self {
7741            title,
7742            description,
7743            default,
7744            meta,
7745        } = self;
7746        Ok(super::BooleanPropertySchema {
7747            title: title.into_v2()?,
7748            description: description.into_v2()?,
7749            default: default.into_v2()?,
7750            meta: meta.into_v2()?,
7751        })
7752    }
7753}
7754
7755#[cfg(feature = "unstable_elicitation")]
7756impl IntoV1 for super::ElicitationStringType {
7757    type Output = crate::v1::ElicitationStringType;
7758
7759    fn into_v1(self) -> Result<Self::Output> {
7760        Ok(match self {
7761            Self::String => crate::v1::ElicitationStringType::String,
7762        })
7763    }
7764}
7765
7766#[cfg(feature = "unstable_elicitation")]
7767impl IntoV2 for crate::v1::ElicitationStringType {
7768    type Output = super::ElicitationStringType;
7769
7770    fn into_v2(self) -> Result<Self::Output> {
7771        Ok(match self {
7772            Self::String => super::ElicitationStringType::String,
7773        })
7774    }
7775}
7776
7777#[cfg(feature = "unstable_elicitation")]
7778impl IntoV1 for super::UntitledMultiSelectItems {
7779    type Output = crate::v1::UntitledMultiSelectItems;
7780
7781    fn into_v1(self) -> Result<Self::Output> {
7782        let Self {
7783            type_,
7784            values,
7785            meta,
7786        } = self;
7787        Ok(crate::v1::UntitledMultiSelectItems {
7788            type_: type_.into_v1()?,
7789            values: values.into_v1()?,
7790            meta: meta.into_v1()?,
7791        })
7792    }
7793}
7794
7795#[cfg(feature = "unstable_elicitation")]
7796impl IntoV2 for crate::v1::UntitledMultiSelectItems {
7797    type Output = super::UntitledMultiSelectItems;
7798
7799    fn into_v2(self) -> Result<Self::Output> {
7800        let Self {
7801            type_,
7802            values,
7803            meta,
7804        } = self;
7805        Ok(super::UntitledMultiSelectItems {
7806            type_: type_.into_v2()?,
7807            values: values.into_v2()?,
7808            meta: meta.into_v2()?,
7809        })
7810    }
7811}
7812
7813#[cfg(feature = "unstable_elicitation")]
7814impl IntoV1 for super::TitledMultiSelectItems {
7815    type Output = crate::v1::TitledMultiSelectItems;
7816
7817    fn into_v1(self) -> Result<Self::Output> {
7818        let Self { options, meta } = self;
7819        Ok(crate::v1::TitledMultiSelectItems {
7820            options: options.into_v1()?,
7821            meta: meta.into_v1()?,
7822        })
7823    }
7824}
7825
7826#[cfg(feature = "unstable_elicitation")]
7827impl IntoV2 for crate::v1::TitledMultiSelectItems {
7828    type Output = super::TitledMultiSelectItems;
7829
7830    fn into_v2(self) -> Result<Self::Output> {
7831        let Self { options, meta } = self;
7832        Ok(super::TitledMultiSelectItems {
7833            options: options.into_v2()?,
7834            meta: meta.into_v2()?,
7835        })
7836    }
7837}
7838
7839#[cfg(feature = "unstable_elicitation")]
7840impl IntoV1 for super::MultiSelectItems {
7841    type Output = crate::v1::MultiSelectItems;
7842
7843    fn into_v1(self) -> Result<Self::Output> {
7844        Ok(match self {
7845            Self::Untitled(value) => crate::v1::MultiSelectItems::Untitled(value.into_v1()?),
7846            Self::Titled(value) => crate::v1::MultiSelectItems::Titled(value.into_v1()?),
7847        })
7848    }
7849}
7850
7851#[cfg(feature = "unstable_elicitation")]
7852impl IntoV2 for crate::v1::MultiSelectItems {
7853    type Output = super::MultiSelectItems;
7854
7855    fn into_v2(self) -> Result<Self::Output> {
7856        Ok(match self {
7857            Self::Untitled(value) => super::MultiSelectItems::Untitled(value.into_v2()?),
7858            Self::Titled(value) => super::MultiSelectItems::Titled(value.into_v2()?),
7859        })
7860    }
7861}
7862
7863#[cfg(feature = "unstable_elicitation")]
7864impl IntoV1 for super::MultiSelectPropertySchema {
7865    type Output = crate::v1::MultiSelectPropertySchema;
7866
7867    fn into_v1(self) -> Result<Self::Output> {
7868        let Self {
7869            title,
7870            description,
7871            min_items,
7872            max_items,
7873            items,
7874            default,
7875            meta,
7876        } = self;
7877        Ok(crate::v1::MultiSelectPropertySchema {
7878            title: title.into_v1()?,
7879            description: description.into_v1()?,
7880            min_items: min_items.into_v1()?,
7881            max_items: max_items.into_v1()?,
7882            items: items.into_v1()?,
7883            default: default.into_v1()?,
7884            meta: meta.into_v1()?,
7885        })
7886    }
7887}
7888
7889#[cfg(feature = "unstable_elicitation")]
7890impl IntoV2 for crate::v1::MultiSelectPropertySchema {
7891    type Output = super::MultiSelectPropertySchema;
7892
7893    fn into_v2(self) -> Result<Self::Output> {
7894        let Self {
7895            title,
7896            description,
7897            min_items,
7898            max_items,
7899            items,
7900            default,
7901            meta,
7902        } = self;
7903        Ok(super::MultiSelectPropertySchema {
7904            title: title.into_v2()?,
7905            description: description.into_v2()?,
7906            min_items: min_items.into_v2()?,
7907            max_items: max_items.into_v2()?,
7908            items: items.into_v2()?,
7909            default: default.into_v2()?,
7910            meta: meta.into_v2()?,
7911        })
7912    }
7913}
7914
7915#[cfg(feature = "unstable_elicitation")]
7916impl IntoV1 for super::ElicitationPropertySchema {
7917    type Output = crate::v1::ElicitationPropertySchema;
7918
7919    fn into_v1(self) -> Result<Self::Output> {
7920        Ok(match self {
7921            Self::String(value) => crate::v1::ElicitationPropertySchema::String(value.into_v1()?),
7922            Self::Number(value) => crate::v1::ElicitationPropertySchema::Number(value.into_v1()?),
7923            Self::Integer(value) => crate::v1::ElicitationPropertySchema::Integer(value.into_v1()?),
7924            Self::Boolean(value) => crate::v1::ElicitationPropertySchema::Boolean(value.into_v1()?),
7925            Self::Array(value) => crate::v1::ElicitationPropertySchema::Array(value.into_v1()?),
7926        })
7927    }
7928}
7929
7930#[cfg(feature = "unstable_elicitation")]
7931impl IntoV2 for crate::v1::ElicitationPropertySchema {
7932    type Output = super::ElicitationPropertySchema;
7933
7934    fn into_v2(self) -> Result<Self::Output> {
7935        Ok(match self {
7936            Self::String(value) => super::ElicitationPropertySchema::String(value.into_v2()?),
7937            Self::Number(value) => super::ElicitationPropertySchema::Number(value.into_v2()?),
7938            Self::Integer(value) => super::ElicitationPropertySchema::Integer(value.into_v2()?),
7939            Self::Boolean(value) => super::ElicitationPropertySchema::Boolean(value.into_v2()?),
7940            Self::Array(value) => super::ElicitationPropertySchema::Array(value.into_v2()?),
7941        })
7942    }
7943}
7944
7945#[cfg(feature = "unstable_elicitation")]
7946impl IntoV1 for super::ElicitationSchema {
7947    type Output = crate::v1::ElicitationSchema;
7948
7949    fn into_v1(self) -> Result<Self::Output> {
7950        let Self {
7951            type_,
7952            title,
7953            properties,
7954            required,
7955            description,
7956            meta,
7957        } = self;
7958        Ok(crate::v1::ElicitationSchema {
7959            type_: type_.into_v1()?,
7960            title: title.into_v1()?,
7961            properties: properties.into_v1()?,
7962            required: required.into_v1()?,
7963            description: description.into_v1()?,
7964            meta: meta.into_v1()?,
7965        })
7966    }
7967}
7968
7969#[cfg(feature = "unstable_elicitation")]
7970impl IntoV2 for crate::v1::ElicitationSchema {
7971    type Output = super::ElicitationSchema;
7972
7973    fn into_v2(self) -> Result<Self::Output> {
7974        let Self {
7975            type_,
7976            title,
7977            properties,
7978            required,
7979            description,
7980            meta,
7981        } = self;
7982        Ok(super::ElicitationSchema {
7983            type_: type_.into_v2()?,
7984            title: title.into_v2()?,
7985            properties: properties.into_v2()?,
7986            required: required.into_v2()?,
7987            description: description.into_v2()?,
7988            meta: meta.into_v2()?,
7989        })
7990    }
7991}
7992
7993#[cfg(feature = "unstable_elicitation")]
7994impl IntoV1 for super::ElicitationCapabilities {
7995    type Output = crate::v1::ElicitationCapabilities;
7996
7997    fn into_v1(self) -> Result<Self::Output> {
7998        let Self { form, url, meta } = self;
7999        Ok(crate::v1::ElicitationCapabilities {
8000            form: into_v1_default_on_error(form),
8001            url: into_v1_default_on_error(url),
8002            meta: meta.into_v1()?,
8003        })
8004    }
8005}
8006
8007#[cfg(feature = "unstable_elicitation")]
8008impl IntoV2 for crate::v1::ElicitationCapabilities {
8009    type Output = super::ElicitationCapabilities;
8010
8011    fn into_v2(self) -> Result<Self::Output> {
8012        let Self { form, url, meta } = self;
8013        Ok(super::ElicitationCapabilities {
8014            form: into_v2_default_on_error(form),
8015            url: into_v2_default_on_error(url),
8016            meta: meta.into_v2()?,
8017        })
8018    }
8019}
8020
8021#[cfg(feature = "unstable_elicitation")]
8022impl IntoV1 for super::ElicitationFormCapabilities {
8023    type Output = crate::v1::ElicitationFormCapabilities;
8024
8025    fn into_v1(self) -> Result<Self::Output> {
8026        let Self { meta } = self;
8027        Ok(crate::v1::ElicitationFormCapabilities {
8028            meta: meta.into_v1()?,
8029        })
8030    }
8031}
8032
8033#[cfg(feature = "unstable_elicitation")]
8034impl IntoV2 for crate::v1::ElicitationFormCapabilities {
8035    type Output = super::ElicitationFormCapabilities;
8036
8037    fn into_v2(self) -> Result<Self::Output> {
8038        let Self { meta } = self;
8039        Ok(super::ElicitationFormCapabilities {
8040            meta: meta.into_v2()?,
8041        })
8042    }
8043}
8044
8045#[cfg(feature = "unstable_elicitation")]
8046impl IntoV1 for super::ElicitationUrlCapabilities {
8047    type Output = crate::v1::ElicitationUrlCapabilities;
8048
8049    fn into_v1(self) -> Result<Self::Output> {
8050        let Self { meta } = self;
8051        Ok(crate::v1::ElicitationUrlCapabilities {
8052            meta: meta.into_v1()?,
8053        })
8054    }
8055}
8056
8057#[cfg(feature = "unstable_elicitation")]
8058impl IntoV2 for crate::v1::ElicitationUrlCapabilities {
8059    type Output = super::ElicitationUrlCapabilities;
8060
8061    fn into_v2(self) -> Result<Self::Output> {
8062        let Self { meta } = self;
8063        Ok(super::ElicitationUrlCapabilities {
8064            meta: meta.into_v2()?,
8065        })
8066    }
8067}
8068
8069#[cfg(feature = "unstable_elicitation")]
8070impl IntoV1 for super::ElicitationScope {
8071    type Output = crate::v1::ElicitationScope;
8072
8073    fn into_v1(self) -> Result<Self::Output> {
8074        Ok(match self {
8075            Self::Session(value) => crate::v1::ElicitationScope::Session(value.into_v1()?),
8076            Self::Request(value) => crate::v1::ElicitationScope::Request(value.into_v1()?),
8077        })
8078    }
8079}
8080
8081#[cfg(feature = "unstable_elicitation")]
8082impl IntoV2 for crate::v1::ElicitationScope {
8083    type Output = super::ElicitationScope;
8084
8085    fn into_v2(self) -> Result<Self::Output> {
8086        Ok(match self {
8087            Self::Session(value) => super::ElicitationScope::Session(value.into_v2()?),
8088            Self::Request(value) => super::ElicitationScope::Request(value.into_v2()?),
8089        })
8090    }
8091}
8092
8093#[cfg(feature = "unstable_elicitation")]
8094impl IntoV1 for super::ElicitationSessionScope {
8095    type Output = crate::v1::ElicitationSessionScope;
8096
8097    fn into_v1(self) -> Result<Self::Output> {
8098        let Self {
8099            session_id,
8100            tool_call_id,
8101        } = self;
8102        Ok(crate::v1::ElicitationSessionScope {
8103            session_id: session_id.into_v1()?,
8104            tool_call_id: tool_call_id.into_v1()?,
8105        })
8106    }
8107}
8108
8109#[cfg(feature = "unstable_elicitation")]
8110impl IntoV2 for crate::v1::ElicitationSessionScope {
8111    type Output = super::ElicitationSessionScope;
8112
8113    fn into_v2(self) -> Result<Self::Output> {
8114        let Self {
8115            session_id,
8116            tool_call_id,
8117        } = self;
8118        Ok(super::ElicitationSessionScope {
8119            session_id: session_id.into_v2()?,
8120            tool_call_id: tool_call_id.into_v2()?,
8121        })
8122    }
8123}
8124
8125#[cfg(feature = "unstable_elicitation")]
8126impl IntoV1 for super::ElicitationRequestScope {
8127    type Output = crate::v1::ElicitationRequestScope;
8128
8129    fn into_v1(self) -> Result<Self::Output> {
8130        let Self { request_id } = self;
8131        Ok(crate::v1::ElicitationRequestScope {
8132            request_id: request_id.into_v1()?,
8133        })
8134    }
8135}
8136
8137#[cfg(feature = "unstable_elicitation")]
8138impl IntoV2 for crate::v1::ElicitationRequestScope {
8139    type Output = super::ElicitationRequestScope;
8140
8141    fn into_v2(self) -> Result<Self::Output> {
8142        let Self { request_id } = self;
8143        Ok(super::ElicitationRequestScope {
8144            request_id: request_id.into_v2()?,
8145        })
8146    }
8147}
8148
8149#[cfg(feature = "unstable_elicitation")]
8150impl IntoV1 for super::CreateElicitationRequest {
8151    type Output = crate::v1::CreateElicitationRequest;
8152
8153    fn into_v1(self) -> Result<Self::Output> {
8154        let Self {
8155            mode,
8156            message,
8157            meta,
8158        } = self;
8159        Ok(crate::v1::CreateElicitationRequest {
8160            mode: mode.into_v1()?,
8161            message: message.into_v1()?,
8162            meta: meta.into_v1()?,
8163        })
8164    }
8165}
8166
8167#[cfg(feature = "unstable_elicitation")]
8168impl IntoV2 for crate::v1::CreateElicitationRequest {
8169    type Output = super::CreateElicitationRequest;
8170
8171    fn into_v2(self) -> Result<Self::Output> {
8172        let Self {
8173            mode,
8174            message,
8175            meta,
8176        } = self;
8177        Ok(super::CreateElicitationRequest {
8178            mode: mode.into_v2()?,
8179            message: message.into_v2()?,
8180            meta: meta.into_v2()?,
8181        })
8182    }
8183}
8184
8185#[cfg(feature = "unstable_elicitation")]
8186impl IntoV1 for super::ElicitationMode {
8187    type Output = crate::v1::ElicitationMode;
8188
8189    fn into_v1(self) -> Result<Self::Output> {
8190        Ok(match self {
8191            Self::Form(value) => crate::v1::ElicitationMode::Form(value.into_v1()?),
8192            Self::Url(value) => crate::v1::ElicitationMode::Url(value.into_v1()?),
8193        })
8194    }
8195}
8196
8197#[cfg(feature = "unstable_elicitation")]
8198impl IntoV2 for crate::v1::ElicitationMode {
8199    type Output = super::ElicitationMode;
8200
8201    fn into_v2(self) -> Result<Self::Output> {
8202        Ok(match self {
8203            Self::Form(value) => super::ElicitationMode::Form(value.into_v2()?),
8204            Self::Url(value) => super::ElicitationMode::Url(value.into_v2()?),
8205        })
8206    }
8207}
8208
8209#[cfg(feature = "unstable_elicitation")]
8210impl IntoV1 for super::ElicitationFormMode {
8211    type Output = crate::v1::ElicitationFormMode;
8212
8213    fn into_v1(self) -> Result<Self::Output> {
8214        let Self {
8215            scope,
8216            requested_schema,
8217        } = self;
8218        Ok(crate::v1::ElicitationFormMode {
8219            scope: scope.into_v1()?,
8220            requested_schema: requested_schema.into_v1()?,
8221        })
8222    }
8223}
8224
8225#[cfg(feature = "unstable_elicitation")]
8226impl IntoV2 for crate::v1::ElicitationFormMode {
8227    type Output = super::ElicitationFormMode;
8228
8229    fn into_v2(self) -> Result<Self::Output> {
8230        let Self {
8231            scope,
8232            requested_schema,
8233        } = self;
8234        Ok(super::ElicitationFormMode {
8235            scope: scope.into_v2()?,
8236            requested_schema: requested_schema.into_v2()?,
8237        })
8238    }
8239}
8240
8241#[cfg(feature = "unstable_elicitation")]
8242impl IntoV1 for super::ElicitationUrlMode {
8243    type Output = crate::v1::ElicitationUrlMode;
8244
8245    fn into_v1(self) -> Result<Self::Output> {
8246        let Self {
8247            scope,
8248            elicitation_id,
8249            url,
8250        } = self;
8251        Ok(crate::v1::ElicitationUrlMode {
8252            scope: scope.into_v1()?,
8253            elicitation_id: elicitation_id.into_v1()?,
8254            url: url.into_v1()?,
8255        })
8256    }
8257}
8258
8259#[cfg(feature = "unstable_elicitation")]
8260impl IntoV2 for crate::v1::ElicitationUrlMode {
8261    type Output = super::ElicitationUrlMode;
8262
8263    fn into_v2(self) -> Result<Self::Output> {
8264        let Self {
8265            scope,
8266            elicitation_id,
8267            url,
8268        } = self;
8269        Ok(super::ElicitationUrlMode {
8270            scope: scope.into_v2()?,
8271            elicitation_id: elicitation_id.into_v2()?,
8272            url: url.into_v2()?,
8273        })
8274    }
8275}
8276
8277#[cfg(feature = "unstable_elicitation")]
8278impl IntoV1 for super::CreateElicitationResponse {
8279    type Output = crate::v1::CreateElicitationResponse;
8280
8281    fn into_v1(self) -> Result<Self::Output> {
8282        let Self { action, meta } = self;
8283        Ok(crate::v1::CreateElicitationResponse {
8284            action: action.into_v1()?,
8285            meta: meta.into_v1()?,
8286        })
8287    }
8288}
8289
8290#[cfg(feature = "unstable_elicitation")]
8291impl IntoV2 for crate::v1::CreateElicitationResponse {
8292    type Output = super::CreateElicitationResponse;
8293
8294    fn into_v2(self) -> Result<Self::Output> {
8295        let Self { action, meta } = self;
8296        Ok(super::CreateElicitationResponse {
8297            action: action.into_v2()?,
8298            meta: meta.into_v2()?,
8299        })
8300    }
8301}
8302
8303#[cfg(feature = "unstable_elicitation")]
8304impl IntoV1 for super::ElicitationAction {
8305    type Output = crate::v1::ElicitationAction;
8306
8307    fn into_v1(self) -> Result<Self::Output> {
8308        Ok(match self {
8309            Self::Accept(value) => crate::v1::ElicitationAction::Accept(value.into_v1()?),
8310            Self::Decline => crate::v1::ElicitationAction::Decline,
8311            Self::Cancel => crate::v1::ElicitationAction::Cancel,
8312        })
8313    }
8314}
8315
8316#[cfg(feature = "unstable_elicitation")]
8317impl IntoV2 for crate::v1::ElicitationAction {
8318    type Output = super::ElicitationAction;
8319
8320    fn into_v2(self) -> Result<Self::Output> {
8321        Ok(match self {
8322            Self::Accept(value) => super::ElicitationAction::Accept(value.into_v2()?),
8323            Self::Decline => super::ElicitationAction::Decline,
8324            Self::Cancel => super::ElicitationAction::Cancel,
8325        })
8326    }
8327}
8328
8329#[cfg(feature = "unstable_elicitation")]
8330impl IntoV1 for super::ElicitationAcceptAction {
8331    type Output = crate::v1::ElicitationAcceptAction;
8332
8333    fn into_v1(self) -> Result<Self::Output> {
8334        let Self { content } = self;
8335        Ok(crate::v1::ElicitationAcceptAction {
8336            content: content.into_v1()?,
8337        })
8338    }
8339}
8340
8341#[cfg(feature = "unstable_elicitation")]
8342impl IntoV2 for crate::v1::ElicitationAcceptAction {
8343    type Output = super::ElicitationAcceptAction;
8344
8345    fn into_v2(self) -> Result<Self::Output> {
8346        let Self { content } = self;
8347        Ok(super::ElicitationAcceptAction {
8348            content: content.into_v2()?,
8349        })
8350    }
8351}
8352
8353#[cfg(feature = "unstable_elicitation")]
8354impl IntoV1 for super::ElicitationContentValue {
8355    type Output = crate::v1::ElicitationContentValue;
8356
8357    fn into_v1(self) -> Result<Self::Output> {
8358        Ok(match self {
8359            Self::String(value) => crate::v1::ElicitationContentValue::String(value.into_v1()?),
8360            Self::Integer(value) => crate::v1::ElicitationContentValue::Integer(value.into_v1()?),
8361            Self::Number(value) => crate::v1::ElicitationContentValue::Number(value.into_v1()?),
8362            Self::Boolean(value) => crate::v1::ElicitationContentValue::Boolean(value.into_v1()?),
8363            Self::StringArray(value) => {
8364                crate::v1::ElicitationContentValue::StringArray(value.into_v1()?)
8365            }
8366        })
8367    }
8368}
8369
8370#[cfg(feature = "unstable_elicitation")]
8371impl IntoV2 for crate::v1::ElicitationContentValue {
8372    type Output = super::ElicitationContentValue;
8373
8374    fn into_v2(self) -> Result<Self::Output> {
8375        Ok(match self {
8376            Self::String(value) => super::ElicitationContentValue::String(value.into_v2()?),
8377            Self::Integer(value) => super::ElicitationContentValue::Integer(value.into_v2()?),
8378            Self::Number(value) => super::ElicitationContentValue::Number(value.into_v2()?),
8379            Self::Boolean(value) => super::ElicitationContentValue::Boolean(value.into_v2()?),
8380            Self::StringArray(value) => {
8381                super::ElicitationContentValue::StringArray(value.into_v2()?)
8382            }
8383        })
8384    }
8385}
8386
8387#[cfg(feature = "unstable_elicitation")]
8388impl IntoV1 for super::CompleteElicitationNotification {
8389    type Output = crate::v1::CompleteElicitationNotification;
8390
8391    fn into_v1(self) -> Result<Self::Output> {
8392        let Self {
8393            elicitation_id,
8394            meta,
8395        } = self;
8396        Ok(crate::v1::CompleteElicitationNotification {
8397            elicitation_id: elicitation_id.into_v1()?,
8398            meta: meta.into_v1()?,
8399        })
8400    }
8401}
8402
8403#[cfg(feature = "unstable_elicitation")]
8404impl IntoV2 for crate::v1::CompleteElicitationNotification {
8405    type Output = super::CompleteElicitationNotification;
8406
8407    fn into_v2(self) -> Result<Self::Output> {
8408        let Self {
8409            elicitation_id,
8410            meta,
8411        } = self;
8412        Ok(super::CompleteElicitationNotification {
8413            elicitation_id: elicitation_id.into_v2()?,
8414            meta: meta.into_v2()?,
8415        })
8416    }
8417}
8418
8419#[cfg(feature = "unstable_elicitation")]
8420impl IntoV1 for super::UrlElicitationRequiredData {
8421    type Output = crate::v1::UrlElicitationRequiredData;
8422
8423    fn into_v1(self) -> Result<Self::Output> {
8424        let Self { elicitations } = self;
8425        Ok(crate::v1::UrlElicitationRequiredData {
8426            elicitations: elicitations.into_v1()?,
8427        })
8428    }
8429}
8430
8431#[cfg(feature = "unstable_elicitation")]
8432impl IntoV2 for crate::v1::UrlElicitationRequiredData {
8433    type Output = super::UrlElicitationRequiredData;
8434
8435    fn into_v2(self) -> Result<Self::Output> {
8436        let Self { elicitations } = self;
8437        Ok(super::UrlElicitationRequiredData {
8438            elicitations: elicitations.into_v2()?,
8439        })
8440    }
8441}
8442
8443#[cfg(feature = "unstable_elicitation")]
8444impl IntoV1 for super::UrlElicitationRequiredItem {
8445    type Output = crate::v1::UrlElicitationRequiredItem;
8446
8447    fn into_v1(self) -> Result<Self::Output> {
8448        let Self {
8449            mode,
8450            elicitation_id,
8451            url,
8452            message,
8453        } = self;
8454        Ok(crate::v1::UrlElicitationRequiredItem {
8455            mode: mode.into_v1()?,
8456            elicitation_id: elicitation_id.into_v1()?,
8457            url: url.into_v1()?,
8458            message: message.into_v1()?,
8459        })
8460    }
8461}
8462
8463#[cfg(feature = "unstable_elicitation")]
8464impl IntoV2 for crate::v1::UrlElicitationRequiredItem {
8465    type Output = super::UrlElicitationRequiredItem;
8466
8467    fn into_v2(self) -> Result<Self::Output> {
8468        let Self {
8469            mode,
8470            elicitation_id,
8471            url,
8472            message,
8473        } = self;
8474        Ok(super::UrlElicitationRequiredItem {
8475            mode: mode.into_v2()?,
8476            elicitation_id: elicitation_id.into_v2()?,
8477            url: url.into_v2()?,
8478            message: message.into_v2()?,
8479        })
8480    }
8481}
8482
8483#[cfg(feature = "unstable_elicitation")]
8484impl IntoV1 for super::ElicitationUrlOnlyMode {
8485    type Output = crate::v1::ElicitationUrlOnlyMode;
8486
8487    fn into_v1(self) -> Result<Self::Output> {
8488        Ok(match self {
8489            Self::Url => crate::v1::ElicitationUrlOnlyMode::Url,
8490        })
8491    }
8492}
8493
8494#[cfg(feature = "unstable_elicitation")]
8495impl IntoV2 for crate::v1::ElicitationUrlOnlyMode {
8496    type Output = super::ElicitationUrlOnlyMode;
8497
8498    fn into_v2(self) -> Result<Self::Output> {
8499        Ok(match self {
8500            Self::Url => super::ElicitationUrlOnlyMode::Url,
8501        })
8502    }
8503}
8504
8505impl IntoV1 for super::ContentBlock {
8506    type Output = crate::v1::ContentBlock;
8507
8508    fn into_v1(self) -> Result<Self::Output> {
8509        Ok(match self {
8510            Self::Text(value) => crate::v1::ContentBlock::Text(value.into_v1()?),
8511            Self::Image(value) => crate::v1::ContentBlock::Image(value.into_v1()?),
8512            Self::Audio(value) => crate::v1::ContentBlock::Audio(value.into_v1()?),
8513            Self::ResourceLink(value) => crate::v1::ContentBlock::ResourceLink(value.into_v1()?),
8514            Self::Resource(value) => crate::v1::ContentBlock::Resource(value.into_v1()?),
8515            Self::Other(value) => {
8516                return Err(unknown_v2_enum_variant("ContentBlock", &value.type_));
8517            }
8518        })
8519    }
8520}
8521
8522impl IntoV2 for crate::v1::ContentBlock {
8523    type Output = super::ContentBlock;
8524
8525    fn into_v2(self) -> Result<Self::Output> {
8526        Ok(match self {
8527            Self::Text(value) => super::ContentBlock::Text(value.into_v2()?),
8528            Self::Image(value) => super::ContentBlock::Image(value.into_v2()?),
8529            Self::Audio(value) => super::ContentBlock::Audio(value.into_v2()?),
8530            Self::ResourceLink(value) => super::ContentBlock::ResourceLink(value.into_v2()?),
8531            Self::Resource(value) => super::ContentBlock::Resource(value.into_v2()?),
8532        })
8533    }
8534}
8535
8536impl IntoV1 for super::TextContent {
8537    type Output = crate::v1::TextContent;
8538
8539    fn into_v1(self) -> Result<Self::Output> {
8540        let Self {
8541            annotations,
8542            text,
8543            meta,
8544        } = self;
8545        Ok(crate::v1::TextContent {
8546            annotations: into_v1_default_on_error(annotations),
8547            text: text.into_v1()?,
8548            meta: meta.into_v1()?,
8549        })
8550    }
8551}
8552
8553impl IntoV2 for crate::v1::TextContent {
8554    type Output = super::TextContent;
8555
8556    fn into_v2(self) -> Result<Self::Output> {
8557        let Self {
8558            annotations,
8559            text,
8560            meta,
8561        } = self;
8562        Ok(super::TextContent {
8563            annotations: into_v2_default_on_error(annotations),
8564            text: text.into_v2()?,
8565            meta: meta.into_v2()?,
8566        })
8567    }
8568}
8569
8570impl IntoV1 for super::ImageContent {
8571    type Output = crate::v1::ImageContent;
8572
8573    fn into_v1(self) -> Result<Self::Output> {
8574        let Self {
8575            annotations,
8576            data,
8577            mime_type,
8578            uri,
8579            meta,
8580        } = self;
8581        Ok(crate::v1::ImageContent {
8582            annotations: into_v1_default_on_error(annotations),
8583            data: data.into_v1()?,
8584            mime_type: mime_type.into_v1()?,
8585            uri: uri.into_v1()?,
8586            meta: meta.into_v1()?,
8587        })
8588    }
8589}
8590
8591impl IntoV2 for crate::v1::ImageContent {
8592    type Output = super::ImageContent;
8593
8594    fn into_v2(self) -> Result<Self::Output> {
8595        let Self {
8596            annotations,
8597            data,
8598            mime_type,
8599            uri,
8600            meta,
8601        } = self;
8602        Ok(super::ImageContent {
8603            annotations: into_v2_default_on_error(annotations),
8604            data: data.into_v2()?,
8605            mime_type: mime_type.into_v2()?,
8606            uri: uri.into_v2()?,
8607            meta: meta.into_v2()?,
8608        })
8609    }
8610}
8611
8612impl IntoV1 for super::AudioContent {
8613    type Output = crate::v1::AudioContent;
8614
8615    fn into_v1(self) -> Result<Self::Output> {
8616        let Self {
8617            annotations,
8618            data,
8619            mime_type,
8620            meta,
8621        } = self;
8622        Ok(crate::v1::AudioContent {
8623            annotations: into_v1_default_on_error(annotations),
8624            data: data.into_v1()?,
8625            mime_type: mime_type.into_v1()?,
8626            meta: meta.into_v1()?,
8627        })
8628    }
8629}
8630
8631impl IntoV2 for crate::v1::AudioContent {
8632    type Output = super::AudioContent;
8633
8634    fn into_v2(self) -> Result<Self::Output> {
8635        let Self {
8636            annotations,
8637            data,
8638            mime_type,
8639            meta,
8640        } = self;
8641        Ok(super::AudioContent {
8642            annotations: into_v2_default_on_error(annotations),
8643            data: data.into_v2()?,
8644            mime_type: mime_type.into_v2()?,
8645            meta: meta.into_v2()?,
8646        })
8647    }
8648}
8649
8650impl IntoV1 for super::EmbeddedResource {
8651    type Output = crate::v1::EmbeddedResource;
8652
8653    fn into_v1(self) -> Result<Self::Output> {
8654        let Self {
8655            annotations,
8656            resource,
8657            meta,
8658        } = self;
8659        Ok(crate::v1::EmbeddedResource {
8660            annotations: into_v1_default_on_error(annotations),
8661            resource: resource.into_v1()?,
8662            meta: meta.into_v1()?,
8663        })
8664    }
8665}
8666
8667impl IntoV2 for crate::v1::EmbeddedResource {
8668    type Output = super::EmbeddedResource;
8669
8670    fn into_v2(self) -> Result<Self::Output> {
8671        let Self {
8672            annotations,
8673            resource,
8674            meta,
8675        } = self;
8676        Ok(super::EmbeddedResource {
8677            annotations: into_v2_default_on_error(annotations),
8678            resource: resource.into_v2()?,
8679            meta: meta.into_v2()?,
8680        })
8681    }
8682}
8683
8684impl IntoV1 for super::EmbeddedResourceResource {
8685    type Output = crate::v1::EmbeddedResourceResource;
8686
8687    fn into_v1(self) -> Result<Self::Output> {
8688        Ok(match self {
8689            Self::TextResourceContents(value) => {
8690                crate::v1::EmbeddedResourceResource::TextResourceContents(value.into_v1()?)
8691            }
8692            Self::BlobResourceContents(value) => {
8693                crate::v1::EmbeddedResourceResource::BlobResourceContents(value.into_v1()?)
8694            }
8695        })
8696    }
8697}
8698
8699impl IntoV2 for crate::v1::EmbeddedResourceResource {
8700    type Output = super::EmbeddedResourceResource;
8701
8702    fn into_v2(self) -> Result<Self::Output> {
8703        Ok(match self {
8704            Self::TextResourceContents(value) => {
8705                super::EmbeddedResourceResource::TextResourceContents(value.into_v2()?)
8706            }
8707            Self::BlobResourceContents(value) => {
8708                super::EmbeddedResourceResource::BlobResourceContents(value.into_v2()?)
8709            }
8710        })
8711    }
8712}
8713
8714impl IntoV1 for super::TextResourceContents {
8715    type Output = crate::v1::TextResourceContents;
8716
8717    fn into_v1(self) -> Result<Self::Output> {
8718        let Self {
8719            mime_type,
8720            text,
8721            uri,
8722            meta,
8723        } = self;
8724        Ok(crate::v1::TextResourceContents {
8725            mime_type: mime_type.into_v1()?,
8726            text: text.into_v1()?,
8727            uri: uri.into_v1()?,
8728            meta: meta.into_v1()?,
8729        })
8730    }
8731}
8732
8733impl IntoV2 for crate::v1::TextResourceContents {
8734    type Output = super::TextResourceContents;
8735
8736    fn into_v2(self) -> Result<Self::Output> {
8737        let Self {
8738            mime_type,
8739            text,
8740            uri,
8741            meta,
8742        } = self;
8743        Ok(super::TextResourceContents {
8744            mime_type: mime_type.into_v2()?,
8745            text: text.into_v2()?,
8746            uri: uri.into_v2()?,
8747            meta: meta.into_v2()?,
8748        })
8749    }
8750}
8751
8752impl IntoV1 for super::BlobResourceContents {
8753    type Output = crate::v1::BlobResourceContents;
8754
8755    fn into_v1(self) -> Result<Self::Output> {
8756        let Self {
8757            blob,
8758            mime_type,
8759            uri,
8760            meta,
8761        } = self;
8762        Ok(crate::v1::BlobResourceContents {
8763            blob: blob.into_v1()?,
8764            mime_type: mime_type.into_v1()?,
8765            uri: uri.into_v1()?,
8766            meta: meta.into_v1()?,
8767        })
8768    }
8769}
8770
8771impl IntoV2 for crate::v1::BlobResourceContents {
8772    type Output = super::BlobResourceContents;
8773
8774    fn into_v2(self) -> Result<Self::Output> {
8775        let Self {
8776            blob,
8777            mime_type,
8778            uri,
8779            meta,
8780        } = self;
8781        Ok(super::BlobResourceContents {
8782            blob: blob.into_v2()?,
8783            mime_type: mime_type.into_v2()?,
8784            uri: uri.into_v2()?,
8785            meta: meta.into_v2()?,
8786        })
8787    }
8788}
8789
8790impl IntoV1 for super::ResourceLink {
8791    type Output = crate::v1::ResourceLink;
8792
8793    fn into_v1(self) -> Result<Self::Output> {
8794        let Self {
8795            annotations,
8796            description,
8797            mime_type,
8798            name,
8799            size,
8800            title,
8801            uri,
8802            meta,
8803        } = self;
8804        Ok(crate::v1::ResourceLink {
8805            annotations: into_v1_default_on_error(annotations),
8806            description: description.into_v1()?,
8807            mime_type: mime_type.into_v1()?,
8808            name: name.into_v1()?,
8809            size: size.into_v1()?,
8810            title: title.into_v1()?,
8811            uri: uri.into_v1()?,
8812            meta: meta.into_v1()?,
8813        })
8814    }
8815}
8816
8817impl IntoV2 for crate::v1::ResourceLink {
8818    type Output = super::ResourceLink;
8819
8820    fn into_v2(self) -> Result<Self::Output> {
8821        let Self {
8822            annotations,
8823            description,
8824            mime_type,
8825            name,
8826            size,
8827            title,
8828            uri,
8829            meta,
8830        } = self;
8831        Ok(super::ResourceLink {
8832            annotations: into_v2_default_on_error(annotations),
8833            description: description.into_v2()?,
8834            mime_type: mime_type.into_v2()?,
8835            name: name.into_v2()?,
8836            size: size.into_v2()?,
8837            title: title.into_v2()?,
8838            uri: uri.into_v2()?,
8839            meta: meta.into_v2()?,
8840        })
8841    }
8842}
8843
8844impl IntoV1 for super::Annotations {
8845    type Output = crate::v1::Annotations;
8846
8847    fn into_v1(self) -> Result<Self::Output> {
8848        let Self {
8849            audience,
8850            last_modified,
8851            priority,
8852            meta,
8853        } = self;
8854        Ok(crate::v1::Annotations {
8855            audience: option_vec_into_v1_skip_errors(audience),
8856            last_modified: last_modified.into_v1()?,
8857            priority: priority.into_v1()?,
8858            meta: meta.into_v1()?,
8859        })
8860    }
8861}
8862
8863impl IntoV2 for crate::v1::Annotations {
8864    type Output = super::Annotations;
8865
8866    fn into_v2(self) -> Result<Self::Output> {
8867        let Self {
8868            audience,
8869            last_modified,
8870            priority,
8871            meta,
8872        } = self;
8873        Ok(super::Annotations {
8874            audience: option_vec_into_v2_skip_errors(audience),
8875            last_modified: last_modified.into_v2()?,
8876            priority: priority.into_v2()?,
8877            meta: meta.into_v2()?,
8878        })
8879    }
8880}
8881
8882impl IntoV1 for super::Role {
8883    type Output = crate::v1::Role;
8884
8885    fn into_v1(self) -> Result<Self::Output> {
8886        Ok(match self {
8887            Self::Assistant => crate::v1::Role::Assistant,
8888            Self::User => crate::v1::Role::User,
8889            Self::Other(value) => return Err(unknown_v2_enum_variant("Role", &value)),
8890        })
8891    }
8892}
8893
8894impl IntoV2 for crate::v1::Role {
8895    type Output = super::Role;
8896
8897    fn into_v2(self) -> Result<Self::Output> {
8898        Ok(match self {
8899            Self::Assistant => super::Role::Assistant,
8900            Self::User => super::Role::User,
8901        })
8902    }
8903}
8904
8905#[cfg(test)]
8906mod tests {
8907    use super::*;
8908    use crate::{v1, v2};
8909
8910    /// Round-trip a v1 value through v2 and back, asserting equality.
8911    ///
8912    /// This catches dropped fields, renamed fields, and missing enum
8913    /// variants in either direction of the conversion as soon as v1 and v2
8914    /// diverge.
8915    fn assert_v1_round_trip<T1, T2>(value: T1)
8916    where
8917        T1: IntoV2<Output = T2> + Clone + std::fmt::Debug + PartialEq,
8918        T2: IntoV1<Output = T1>,
8919    {
8920        let original = value.clone();
8921        let as_v2 = v1_to_v2(value).expect("v1 -> v2 conversion failed");
8922        let back = v2_to_v1(as_v2).expect("v2 -> v1 conversion failed");
8923        assert_eq!(
8924            original, back,
8925            "value did not survive v1 -> v2 -> v1 round trip"
8926        );
8927    }
8928
8929    /// Round-trip a v2 value through v1 and back, asserting equality.
8930    fn assert_v2_round_trip<T2, T1>(value: T2)
8931    where
8932        T2: IntoV1<Output = T1> + Clone + std::fmt::Debug + PartialEq,
8933        T1: IntoV2<Output = T2>,
8934    {
8935        let original = value.clone();
8936        let as_v1 = v2_to_v1(value).expect("v2 -> v1 conversion failed");
8937        let back = v1_to_v2(as_v1).expect("v1 -> v2 conversion failed");
8938        assert_eq!(
8939            original, back,
8940            "value did not survive v2 -> v1 -> v2 round trip"
8941        );
8942    }
8943
8944    /// While v1 and v2 are structurally identical, JSON produced by either
8945    /// module must be byte-equal after a conversion. This is a cheap insurance
8946    /// against accidental field renames or shape drift in conversions.
8947    ///
8948    /// Starts from a v1 value, converts forward to v2 and asserts JSON
8949    /// equality, then converts back to v1 and asserts JSON equality again.
8950    /// Catches shape drift in both directions of the conversion.
8951    fn assert_json_eq_after_v1_to_v2<T1, T2>(value: T1)
8952    where
8953        T1: IntoV2<Output = T2> + serde::Serialize + Clone,
8954        T2: IntoV1<Output = T1> + serde::Serialize,
8955    {
8956        let v1_json = serde_json::to_value(&value).expect("v1 serialize");
8957        let as_v2 = v1_to_v2(value).expect("v1 -> v2 conversion");
8958        let v2_json = serde_json::to_value(&as_v2).expect("v2 serialize");
8959        assert_eq!(
8960            v1_json, v2_json,
8961            "JSON shape diverged after v1 -> v2 conversion"
8962        );
8963
8964        let back_to_v1 = v2_to_v1(as_v2).expect("v2 -> v1 conversion");
8965        let v1_json_after =
8966            serde_json::to_value(&back_to_v1).expect("v1 serialize after round trip");
8967        assert_eq!(
8968            v2_json, v1_json_after,
8969            "JSON shape diverged after v2 -> v1 conversion"
8970        );
8971    }
8972
8973    /// Mirror of [`assert_json_eq_after_v1_to_v2`] that starts from a v2 value.
8974    /// Useful when the natural starting point is a v2 type (for example when
8975    /// the type only exists today in v2's draft API surface).
8976    fn assert_json_eq_after_v2_to_v1<T2, T1>(value: T2)
8977    where
8978        T2: IntoV1<Output = T1> + serde::Serialize + Clone,
8979        T1: IntoV2<Output = T2> + serde::Serialize,
8980    {
8981        let v2_json = serde_json::to_value(&value).expect("v2 serialize");
8982        let as_v1 = v2_to_v1(value).expect("v2 -> v1 conversion");
8983        let v1_json = serde_json::to_value(&as_v1).expect("v1 serialize");
8984        assert_eq!(
8985            v2_json, v1_json,
8986            "JSON shape diverged after v2 -> v1 conversion"
8987        );
8988
8989        let back_to_v2 = v1_to_v2(as_v1).expect("v1 -> v2 conversion");
8990        let v2_json_after =
8991            serde_json::to_value(&back_to_v2).expect("v2 serialize after round trip");
8992        assert_eq!(
8993            v1_json, v2_json_after,
8994            "JSON shape diverged after v1 -> v2 conversion"
8995        );
8996    }
8997
8998    fn assert_v2_to_v1_error<T>(value: T, expected: &str)
8999    where
9000        T: IntoV1,
9001        T::Output: std::fmt::Debug,
9002    {
9003        let error = v2_to_v1(value).unwrap_err();
9004        assert_eq!(error.message(), expected);
9005    }
9006
9007    fn assert_v2_to_v1_many_error<T>(value: T, expected: &str)
9008    where
9009        T: IntoV1Many,
9010        T::Output: std::fmt::Debug,
9011    {
9012        let error = v2_to_v1_many(value).unwrap_err();
9013        assert_eq!(error.message(), expected);
9014    }
9015
9016    fn assert_v1_to_v2_error<T>(value: T, expected: &str)
9017    where
9018        T: IntoV2,
9019        T::Output: std::fmt::Debug,
9020    {
9021        let error = v1_to_v2(value).unwrap_err();
9022        assert_eq!(error.message(), expected);
9023    }
9024
9025    #[test]
9026    fn round_trips_session_config_option_categories() {
9027        for category in [
9028            v1::SessionConfigOptionCategory::Mode,
9029            v1::SessionConfigOptionCategory::Model,
9030            #[cfg(feature = "unstable_model_config_category")]
9031            v1::SessionConfigOptionCategory::ModelConfig,
9032            v1::SessionConfigOptionCategory::ThoughtLevel,
9033            v1::SessionConfigOptionCategory::Other("_custom_category".to_string()),
9034        ] {
9035            assert_v1_round_trip::<v1::SessionConfigOptionCategory, v2::SessionConfigOptionCategory>(
9036                category,
9037            );
9038        }
9039
9040        for category in [
9041            v2::SessionConfigOptionCategory::Mode,
9042            v2::SessionConfigOptionCategory::Model,
9043            #[cfg(feature = "unstable_model_config_category")]
9044            v2::SessionConfigOptionCategory::ModelConfig,
9045            v2::SessionConfigOptionCategory::ThoughtLevel,
9046            v2::SessionConfigOptionCategory::Other("_custom_category".to_string()),
9047        ] {
9048            assert_v2_round_trip::<v2::SessionConfigOptionCategory, v1::SessionConfigOptionCategory>(
9049                category,
9050            );
9051        }
9052    }
9053
9054    #[test]
9055    fn converts_v2_initialize_request_to_v1_without_serde() {
9056        let request = v2::InitializeRequest::new(ProtocolVersion::V2);
9057
9058        let converted: v1::InitializeRequest = v2_to_v1(request).unwrap();
9059
9060        assert_eq!(converted.protocol_version, ProtocolVersion::V2);
9061    }
9062
9063    #[test]
9064    fn converts_v1_initialize_request_to_v2_without_serde() {
9065        let request = v1::InitializeRequest::new(ProtocolVersion::V1);
9066
9067        let converted: v2::InitializeRequest = v1_to_v2(request).unwrap();
9068
9069        assert_eq!(converted.protocol_version, ProtocolVersion::V1);
9070    }
9071
9072    #[test]
9073    fn round_trips_initialize_request() {
9074        let mut client_capabilities = v1::ClientCapabilities::new();
9075        #[cfg(feature = "unstable_boolean_config")]
9076        {
9077            client_capabilities = client_capabilities.session(
9078                v1::ClientSessionCapabilities::new().config_options(
9079                    v1::SessionConfigOptionsCapabilities::new()
9080                        .boolean(v1::BooleanConfigOptionCapabilities::new()),
9081                ),
9082            );
9083        }
9084
9085        let request = v1::InitializeRequest::new(ProtocolVersion::V1)
9086            .client_capabilities(client_capabilities)
9087            .client_info(v1::Implementation::new("test-client", "1.0.0").title("Test Client"));
9088
9089        assert_v1_round_trip::<v1::InitializeRequest, v2::InitializeRequest>(request.clone());
9090        let converted: v2::InitializeRequest =
9091            v1_to_v2(request).expect("v1 -> v2 conversion failed");
9092        let converted_capabilities =
9093            serde_json::to_value(converted.capabilities).expect("v2 serialize");
9094        assert_eq!(converted_capabilities.get("fs"), None);
9095        assert_eq!(converted_capabilities.get("terminal"), None);
9096    }
9097
9098    #[test]
9099    fn round_trips_initialize_response() {
9100        let response = v1::InitializeResponse::new(ProtocolVersion::V1)
9101            .agent_info(v1::Implementation::new("test-agent", "2.0.0").title("Test Agent"));
9102        assert_v1_round_trip::<v1::InitializeResponse, v2::InitializeResponse>(response.clone());
9103        let converted: v2::InitializeResponse =
9104            v1_to_v2(response).expect("v1 -> v2 conversion failed");
9105        let converted_json = serde_json::to_value(&converted).expect("v2 serialize");
9106        assert_eq!(converted_json.get("agentCapabilities"), None);
9107        assert!(converted_json.get("capabilities").is_some());
9108        assert_eq!(converted_json.pointer("/capabilities/loadSession"), None);
9109    }
9110
9111    #[test]
9112    fn agent_load_session_capability_moves_between_v1_and_v2() {
9113        let v1_capabilities = v1::AgentCapabilities::new().load_session(true);
9114
9115        let v2_capabilities: v2::AgentCapabilities =
9116            v1_to_v2(v1_capabilities).expect("v1 -> v2 conversion");
9117        let session = v2_capabilities
9118            .session
9119            .as_ref()
9120            .expect("v1 capabilities imply v2 session support");
9121        assert!(session.load.is_some());
9122        let v2_json = serde_json::to_value(&v2_capabilities).expect("v2 serialize");
9123        assert_eq!(v2_json.get("loadSession"), None);
9124        assert_eq!(
9125            v2_json.pointer("/session/load"),
9126            Some(&serde_json::json!({}))
9127        );
9128
9129        let v1_after: v1::AgentCapabilities =
9130            v2_to_v1(v2_capabilities).expect("v2 -> v1 conversion");
9131        assert!(v1_after.load_session);
9132    }
9133
9134    #[test]
9135    fn v2_agent_capabilities_without_session_do_not_convert_to_v1() {
9136        let error = v2::AgentCapabilities::new().into_v1().unwrap_err();
9137        assert_eq!(
9138            error.message(),
9139            "v2 AgentCapabilities without `session` cannot be represented in v1"
9140        );
9141    }
9142
9143    #[test]
9144    fn v2_session_capabilities_convert_to_v1_agent_capability_parts() {
9145        let parts = v2::SessionCapabilities::new()
9146            .load(v2::SessionLoadCapabilities::new())
9147            .prompt(v2::PromptCapabilities::new().image(v2::PromptImageCapabilities::new()))
9148            .mcp(v2::McpCapabilities::new().http(v2::McpHttpCapabilities::new()))
9149            .list(v2::SessionListCapabilities::new())
9150            .into_v1()
9151            .expect("v2 session capabilities -> v1 parts");
9152
9153        assert!(parts.session_capabilities.list.is_some());
9154        assert!(parts.prompt_capabilities.image);
9155        assert!(parts.load_session);
9156        assert!(parts.mcp_capabilities.http);
9157    }
9158
9159    #[test]
9160    fn v1_prompt_capability_bools_convert_to_v2_objects() {
9161        let v1_capabilities = v1::PromptCapabilities::new()
9162            .image(true)
9163            .audio(true)
9164            .embedded_context(true);
9165
9166        let v2_capabilities: v2::PromptCapabilities =
9167            v1_to_v2(v1_capabilities).expect("v1 -> v2 conversion");
9168        let v2_json = serde_json::to_value(&v2_capabilities).expect("v2 serialize");
9169        assert_eq!(v2_json.pointer("/image"), Some(&serde_json::json!({})));
9170        assert_eq!(v2_json.pointer("/audio"), Some(&serde_json::json!({})));
9171        assert_eq!(
9172            v2_json.pointer("/embeddedContext"),
9173            Some(&serde_json::json!({}))
9174        );
9175
9176        let v1_after: v1::PromptCapabilities =
9177            v2_to_v1(v2_capabilities).expect("v2 -> v1 conversion");
9178        assert!(v1_after.image);
9179        assert!(v1_after.audio);
9180        assert!(v1_after.embedded_context);
9181    }
9182
9183    #[test]
9184    fn v1_mcp_capabilities_convert_to_v2_transport_objects() {
9185        let v1_capabilities = v1::McpCapabilities::new().http(true).sse(true);
9186
9187        let v2_capabilities: v2::McpCapabilities =
9188            v1_to_v2(v1_capabilities).expect("v1 -> v2 conversion");
9189        let v2_json = serde_json::to_value(&v2_capabilities).expect("v2 serialize");
9190        assert_eq!(v2_json.pointer("/stdio"), Some(&serde_json::json!({})));
9191        assert_eq!(v2_json.pointer("/http"), Some(&serde_json::json!({})));
9192        assert_eq!(v2_json.pointer("/sse"), None);
9193
9194        let v1_after: v1::McpCapabilities = v2_to_v1(v2_capabilities).expect("v2 -> v1 conversion");
9195        assert!(v1_after.http);
9196        assert!(!v1_after.sse);
9197    }
9198
9199    #[cfg(feature = "unstable_mcp_over_acp")]
9200    #[test]
9201    fn v1_mcp_acp_capability_bool_converts_to_v2_object() {
9202        let v1_capabilities = v1::McpCapabilities::new().acp(true);
9203
9204        let v2_capabilities: v2::McpCapabilities =
9205            v1_to_v2(v1_capabilities).expect("v1 -> v2 conversion");
9206        let v2_json = serde_json::to_value(&v2_capabilities).expect("v2 serialize");
9207        assert_eq!(v2_json.pointer("/acp"), Some(&serde_json::json!({})));
9208
9209        let v1_after: v1::McpCapabilities = v2_to_v1(v2_capabilities).expect("v2 -> v1 conversion");
9210        assert!(v1_after.acp);
9211    }
9212
9213    #[cfg(feature = "unstable_auth_methods")]
9214    #[test]
9215    fn v1_auth_terminal_capability_bool_converts_to_v2_object() {
9216        let v1_capabilities = v1::AuthCapabilities::new().terminal(true);
9217
9218        let v2_capabilities: v2::AuthCapabilities =
9219            v1_to_v2(v1_capabilities).expect("v1 -> v2 conversion");
9220        let v2_json = serde_json::to_value(&v2_capabilities).expect("v2 serialize");
9221        assert_eq!(v2_json.pointer("/terminal"), Some(&serde_json::json!({})));
9222
9223        let v1_after: v1::AuthCapabilities =
9224            v2_to_v1(v2_capabilities).expect("v2 -> v1 conversion");
9225        assert!(v1_after.terminal);
9226    }
9227
9228    #[test]
9229    fn v1_client_fs_and_terminal_capabilities_are_removed_in_v2() {
9230        let v1_capabilities =
9231            v1::ClientCapabilities::new()
9232                .terminal(true)
9233                .fs(v1::FileSystemCapabilities::new()
9234                    .read_text_file(true)
9235                    .write_text_file(true));
9236
9237        let v2_capabilities: v2::ClientCapabilities =
9238            v1_to_v2(v1_capabilities).expect("v1 -> v2 conversion");
9239        let v2_json = serde_json::to_value(&v2_capabilities).expect("v2 serialize");
9240        assert_eq!(
9241            v2_json.get("fs"),
9242            None,
9243            "v2 ClientCapabilities must not include filesystem capabilities"
9244        );
9245        assert_eq!(
9246            v2_json.get("terminal"),
9247            None,
9248            "v2 ClientCapabilities must not include terminal capabilities"
9249        );
9250
9251        let v1_after: v1::ClientCapabilities =
9252            v2_to_v1(v2_capabilities).expect("v2 -> v1 conversion");
9253        assert!(!v1_after.fs.read_text_file);
9254        assert!(!v1_after.fs.write_text_file);
9255        assert!(!v1_after.terminal);
9256    }
9257
9258    #[cfg(feature = "unstable_boolean_config")]
9259    #[test]
9260    fn v2_client_capabilities_default_to_v1_boolean_config_option_support() {
9261        let v2_capabilities = v2::ClientCapabilities::new();
9262
9263        let v1_capabilities: v1::ClientCapabilities =
9264            v2_to_v1(v2_capabilities).expect("v2 -> v1 conversion");
9265
9266        assert!(
9267            v1_capabilities
9268                .session
9269                .and_then(|session| session.config_options)
9270                .and_then(|config_options| config_options.boolean)
9271                .is_some()
9272        );
9273    }
9274
9275    #[test]
9276    fn v1_client_fs_and_terminal_methods_do_not_convert_to_v2() {
9277        assert_v1_to_v2_error(
9278            v1::AgentRequest::WriteTextFileRequest(v1::WriteTextFileRequest::new(
9279                "sess",
9280                "/workspace/file.txt",
9281                "contents",
9282            )),
9283            "v1 AgentRequest variant `fs/write_text_file` cannot be represented in v2",
9284        );
9285        assert_v1_to_v2_error(
9286            v1::AgentRequest::ReadTextFileRequest(v1::ReadTextFileRequest::new(
9287                "sess",
9288                "/workspace/file.txt",
9289            )),
9290            "v1 AgentRequest variant `fs/read_text_file` cannot be represented in v2",
9291        );
9292        assert_v1_to_v2_error(
9293            v1::AgentRequest::CreateTerminalRequest(v1::CreateTerminalRequest::new("sess", "echo")),
9294            "v1 AgentRequest variant `terminal/create` cannot be represented in v2",
9295        );
9296        assert_v1_to_v2_error(
9297            v1::AgentRequest::TerminalOutputRequest(v1::TerminalOutputRequest::new("sess", "term")),
9298            "v1 AgentRequest variant `terminal/output` cannot be represented in v2",
9299        );
9300        assert_v1_to_v2_error(
9301            v1::AgentRequest::ReleaseTerminalRequest(v1::ReleaseTerminalRequest::new(
9302                "sess", "term",
9303            )),
9304            "v1 AgentRequest variant `terminal/release` cannot be represented in v2",
9305        );
9306        assert_v1_to_v2_error(
9307            v1::AgentRequest::WaitForTerminalExitRequest(v1::WaitForTerminalExitRequest::new(
9308                "sess", "term",
9309            )),
9310            "v1 AgentRequest variant `terminal/wait_for_exit` cannot be represented in v2",
9311        );
9312        assert_v1_to_v2_error(
9313            v1::AgentRequest::KillTerminalRequest(v1::KillTerminalRequest::new("sess", "term")),
9314            "v1 AgentRequest variant `terminal/kill` cannot be represented in v2",
9315        );
9316
9317        assert_v1_to_v2_error(
9318            v1::ClientResponse::WriteTextFileResponse(v1::WriteTextFileResponse::new()),
9319            "v1 ClientResponse variant `fs/write_text_file` cannot be represented in v2",
9320        );
9321        assert_v1_to_v2_error(
9322            v1::ClientResponse::ReadTextFileResponse(v1::ReadTextFileResponse::new("contents")),
9323            "v1 ClientResponse variant `fs/read_text_file` cannot be represented in v2",
9324        );
9325        assert_v1_to_v2_error(
9326            v1::ClientResponse::CreateTerminalResponse(v1::CreateTerminalResponse::new("term")),
9327            "v1 ClientResponse variant `terminal/create` cannot be represented in v2",
9328        );
9329        assert_v1_to_v2_error(
9330            v1::ClientResponse::TerminalOutputResponse(v1::TerminalOutputResponse::new("", false)),
9331            "v1 ClientResponse variant `terminal/output` cannot be represented in v2",
9332        );
9333        assert_v1_to_v2_error(
9334            v1::ClientResponse::ReleaseTerminalResponse(v1::ReleaseTerminalResponse::new()),
9335            "v1 ClientResponse variant `terminal/release` cannot be represented in v2",
9336        );
9337        assert_v1_to_v2_error(
9338            v1::ClientResponse::WaitForTerminalExitResponse(v1::WaitForTerminalExitResponse::new(
9339                v1::TerminalExitStatus::new(),
9340            )),
9341            "v1 ClientResponse variant `terminal/wait_for_exit` cannot be represented in v2",
9342        );
9343        assert_v1_to_v2_error(
9344            v1::ClientResponse::KillTerminalResponse(v1::KillTerminalResponse::new()),
9345            "v1 ClientResponse variant `terminal/kill` cannot be represented in v2",
9346        );
9347    }
9348
9349    #[test]
9350    fn v1_terminal_tool_call_content_does_not_convert_to_v2() {
9351        assert_v1_to_v2_error(
9352            v1::ToolCallContent::Terminal(v1::Terminal::new("term")),
9353            "v1 ToolCallContent variant `terminal` cannot be represented in v2",
9354        );
9355    }
9356
9357    #[test]
9358    fn v1_mcp_sse_transport_does_not_convert_to_v2() {
9359        assert_v1_to_v2_error(
9360            v1::McpServer::Sse(v1::McpServerSse::new("events", "https://example.com/sse")),
9361            "v1 McpServer variant `sse` cannot be represented in v2",
9362        );
9363    }
9364
9365    #[test]
9366    fn v2_unknown_mcp_transport_does_not_convert_to_v1() {
9367        assert_v2_to_v1_error(
9368            v2::McpServer::Other(v2::OtherMcpServer::new("websocket", BTreeMap::default())),
9369            "v2 McpServer variant `websocket` cannot be represented in v1",
9370        );
9371    }
9372
9373    #[test]
9374    fn round_trips_new_session_request_with_mcp_variants() {
9375        let request = v1::NewSessionRequest::new("/workspace").mcp_servers(vec![
9376            v1::McpServer::Stdio(v1::McpServerStdio::new("local", "/usr/bin/mcp")),
9377            v1::McpServer::Http(v1::McpServerHttp::new("remote", "https://example.com")),
9378        ]);
9379
9380        assert_v1_round_trip::<v1::NewSessionRequest, v2::NewSessionRequest>(request.clone());
9381
9382        let v2_request: v2::NewSessionRequest = v1_to_v2(request).expect("v1 -> v2 conversion");
9383        assert_eq!(
9384            serde_json::to_value(&v2_request).expect("v2 serialize"),
9385            serde_json::json!({
9386                "cwd": "/workspace",
9387                "mcpServers": [
9388                    {
9389                        "type": "stdio",
9390                        "name": "local",
9391                        "command": "/usr/bin/mcp",
9392                        "args": [],
9393                        "env": []
9394                    },
9395                    {
9396                        "type": "http",
9397                        "name": "remote",
9398                        "url": "https://example.com",
9399                        "headers": []
9400                    }
9401                ]
9402            })
9403        );
9404    }
9405
9406    #[test]
9407    fn round_trips_prompt_request_with_content_variants() {
9408        let prompt = vec![
9409            v1::ContentBlock::Text(v1::TextContent::new("hello")),
9410            v1::ContentBlock::Image(v1::ImageContent::new("data", "image/png")),
9411            v1::ContentBlock::ResourceLink(v1::ResourceLink::new("file.txt", "file:///file.txt")),
9412        ];
9413        let request = v1::PromptRequest::new("sess_1", prompt);
9414        assert_v1_round_trip::<v1::PromptRequest, v2::PromptRequest>(request.clone());
9415        assert_json_eq_after_v1_to_v2::<v1::PromptRequest, v2::PromptRequest>(request);
9416    }
9417
9418    #[test]
9419    fn prompt_responses_do_not_convert_across_v1_v2_lifecycle_boundary() {
9420        assert_v2_to_v1_error(
9421            v2::PromptResponse::new(),
9422            "v2 PromptResponse cannot be represented in v1 because v2 reports completion with state_update session updates",
9423        );
9424        assert_v1_to_v2_error(
9425            v1::PromptResponse::new(v1::StopReason::EndTurn),
9426            "v1 PromptResponse cannot be represented in v2 by itself because v2 reports completion with state_update session updates",
9427        );
9428    }
9429
9430    #[test]
9431    fn v1_tool_call_converts_to_v2_upsert_with_diff_and_locations() {
9432        let tool_call = v1::ToolCall::new("tc_1", "editing files")
9433            .kind(v1::ToolKind::Edit)
9434            .status(v1::ToolCallStatus::InProgress)
9435            .content(vec![v1::ToolCallContent::Diff(
9436                v1::Diff::new("/path", "new contents").old_text("old contents"),
9437            )])
9438            .locations(vec![v1::ToolCallLocation::new("/path").line(42)])
9439            .raw_input(serde_json::json!({"foo": "bar"}))
9440            .raw_output(serde_json::json!({"ok": true}));
9441
9442        let converted: v2::ToolCallUpdate = v1_to_v2(tool_call).expect("v1 -> v2 conversion");
9443        assert_eq!(
9444            serde_json::to_value(&converted).expect("v2 serialize"),
9445            serde_json::json!({
9446                "toolCallId": "tc_1",
9447                "title": "editing files",
9448                "kind": "edit",
9449                "status": "in_progress",
9450                "content": [
9451                    {
9452                        "type": "diff",
9453                        "path": "/path",
9454                        "oldText": "old contents",
9455                        "newText": "new contents"
9456                    }
9457                ],
9458                "locations": [
9459                    {
9460                        "path": "/path",
9461                        "line": 42
9462                    }
9463                ],
9464                "rawInput": {
9465                    "foo": "bar"
9466                },
9467                "rawOutput": {
9468                    "ok": true
9469                }
9470            })
9471        );
9472
9473        let back: v1::ToolCallUpdate = v2_to_v1(converted).expect("v2 -> v1 conversion");
9474        assert_eq!(back.tool_call_id.0.as_ref(), "tc_1");
9475        assert_eq!(back.fields.title.as_deref(), Some("editing files"));
9476        assert_eq!(back.fields.kind, Some(v1::ToolKind::Edit));
9477        assert_eq!(back.fields.status, Some(v1::ToolCallStatus::InProgress));
9478        assert_eq!(back.fields.content.as_ref().map(Vec::len), Some(1));
9479        assert_eq!(back.fields.locations.as_ref().map(Vec::len), Some(1));
9480        assert_eq!(
9481            back.fields.raw_input,
9482            Some(serde_json::json!({"foo": "bar"}))
9483        );
9484        assert_eq!(
9485            back.fields.raw_output,
9486            Some(serde_json::json!({"ok": true}))
9487        );
9488    }
9489
9490    #[test]
9491    fn v1_tool_call_update_round_trips_through_v2_tool_call_update_upsert() {
9492        let update = v1::ToolCallUpdate::new(
9493            "tc",
9494            v1::ToolCallUpdateFields::new()
9495                .status(v1::ToolCallStatus::Completed)
9496                .content(Vec::new()),
9497        );
9498
9499        assert_v1_round_trip::<v1::ToolCallUpdate, v2::ToolCallUpdate>(update.clone());
9500        assert_json_eq_after_v1_to_v2::<v1::ToolCallUpdate, v2::ToolCallUpdate>(update);
9501    }
9502
9503    #[test]
9504    fn round_trips_session_notification_for_unchanged_update_kinds() {
9505        fn content_chunk(text: &str, message_id: &str) -> v1::ContentChunk {
9506            let chunk = v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new(text)));
9507            chunk.message_id(message_id)
9508        }
9509
9510        let cases: Vec<v1::SessionUpdate> = vec![
9511            v1::SessionUpdate::UserMessageChunk(content_chunk("u", "msg_user")),
9512            v1::SessionUpdate::AgentMessageChunk(content_chunk("a", "msg_agent")),
9513            v1::SessionUpdate::AgentThoughtChunk(content_chunk("t", "msg_thought")),
9514            #[cfg(feature = "unstable_plan_operations")]
9515            v1::SessionUpdate::PlanUpdate(v1::PlanUpdate::new(v1::PlanUpdateContent::markdown(
9516                "plan-1",
9517                "## Steps\n- [ ] Test conversion",
9518            ))),
9519            #[cfg(feature = "unstable_plan_operations")]
9520            v1::SessionUpdate::PlanRemoved(v1::PlanRemoved::new("plan-1")),
9521            v1::SessionUpdate::SessionInfoUpdate(v1::SessionInfoUpdate::new().title("hi")),
9522            v1::SessionUpdate::UsageUpdate(
9523                v1::UsageUpdate::new(53_000, 200_000).cost(v1::Cost::new(0.045, "USD")),
9524            ),
9525        ];
9526        for update in cases {
9527            let notification = v1::SessionNotification::new("sess", update);
9528            let original_json = serde_json::to_value(&notification).expect("v1 serialize");
9529            let as_v2: v2::SessionNotification =
9530                v1_to_v2(notification.clone()).expect("v1 -> v2 conversion");
9531            let v2_json = serde_json::to_value(&as_v2).expect("v2 serialize");
9532            assert_eq!(
9533                original_json, v2_json,
9534                "JSON shape diverged after v1 -> v2 conversion"
9535            );
9536
9537            let back = v2_to_v1_many(as_v2).expect("v2 -> v1 conversion");
9538            assert_eq!(back, vec![notification]);
9539            let back_json = serde_json::to_value(&back[0]).expect("v1 serialize after round trip");
9540            assert_eq!(
9541                original_json, back_json,
9542                "JSON shape diverged after v2 -> v1 conversion"
9543            );
9544        }
9545    }
9546
9547    #[test]
9548    fn v1_tool_call_session_updates_convert_to_unified_v2_tool_call_update() {
9549        let create = v1::SessionNotification::new(
9550            "sess",
9551            v1::SessionUpdate::ToolCall(v1::ToolCall::new("tc", "title")),
9552        );
9553        let create_v2: v2::SessionNotification = v1_to_v2(create).expect("v1 -> v2 conversion");
9554        assert!(matches!(
9555            create_v2.update,
9556            v2::SessionUpdate::ToolCallUpdate(_)
9557        ));
9558        assert_eq!(
9559            serde_json::to_value(&create_v2).expect("v2 serialize"),
9560            serde_json::json!({
9561                "sessionId": "sess",
9562                "update": {
9563                    "sessionUpdate": "tool_call_update",
9564                    "toolCallId": "tc",
9565                    "title": "title"
9566                }
9567            })
9568        );
9569
9570        let update = v1::SessionNotification::new(
9571            "sess",
9572            v1::SessionUpdate::ToolCallUpdate(v1::ToolCallUpdate::new(
9573                "tc",
9574                v1::ToolCallUpdateFields::new().status(v1::ToolCallStatus::Completed),
9575            )),
9576        );
9577        let update_v2: v2::SessionNotification = v1_to_v2(update).expect("v1 -> v2 conversion");
9578        assert!(matches!(
9579            update_v2.update,
9580            v2::SessionUpdate::ToolCallUpdate(_)
9581        ));
9582        assert_eq!(
9583            serde_json::to_value(&update_v2).expect("v2 serialize"),
9584            serde_json::json!({
9585                "sessionId": "sess",
9586                "update": {
9587                    "sessionUpdate": "tool_call_update",
9588                    "toolCallId": "tc",
9589                    "status": "completed"
9590                }
9591            })
9592        );
9593    }
9594
9595    #[test]
9596    fn v2_full_messages_convert_to_v1_message_chunks() {
9597        let mut meta = v2::Meta::new();
9598        meta.insert("source".to_string(), serde_json::json!("full"));
9599
9600        let chunks = v2_to_v1_many(v2::SessionUpdate::UserMessage(
9601            v2::UserMessage::new("msg_user")
9602                .content(vec![
9603                    v2::ContentBlock::Text(v2::TextContent::new("hello")),
9604                    v2::ContentBlock::Text(v2::TextContent::new("world")),
9605                ])
9606                .meta(meta.clone()),
9607        ))
9608        .expect("v2 -> v1 conversion");
9609        assert_eq!(
9610            chunks,
9611            vec![
9612                v1::SessionUpdate::UserMessageChunk(
9613                    v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new("hello")))
9614                        .message_id("msg_user")
9615                        .meta(meta.clone())
9616                ),
9617                v1::SessionUpdate::UserMessageChunk(
9618                    v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new("world")))
9619                        .message_id("msg_user")
9620                        .meta(meta)
9621                ),
9622            ]
9623        );
9624
9625        assert_eq!(
9626            v2_to_v1_many(v2::SessionUpdate::AgentMessage(
9627                v2::AgentMessage::new("msg_agent")
9628                    .content(vec![v2::ContentBlock::Text(v2::TextContent::new("hello"))])
9629            ))
9630            .expect("v2 -> v1 conversion"),
9631            vec![v1::SessionUpdate::AgentMessageChunk(
9632                v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new("hello")))
9633                    .message_id("msg_agent")
9634            )]
9635        );
9636
9637        assert_eq!(
9638            v2_to_v1_many(v2::SessionUpdate::AgentThought(
9639                v2::AgentThought::new("msg_thought").content(vec![v2::ContentBlock::Text(
9640                    v2::TextContent::new("thinking")
9641                )])
9642            ))
9643            .expect("v2 -> v1 conversion"),
9644            vec![v1::SessionUpdate::AgentThoughtChunk(
9645                v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new("thinking")))
9646                    .message_id("msg_thought")
9647            )]
9648        );
9649    }
9650
9651    #[test]
9652    fn v2_full_message_session_notification_fans_out_to_v1_chunk_notifications() {
9653        let notification = v2::SessionNotification::new(
9654            "sess",
9655            v2::SessionUpdate::AgentMessage(v2::AgentMessage::new("msg_agent").content(vec![
9656                v2::ContentBlock::Text(v2::TextContent::new("hello")),
9657                v2::ContentBlock::Text(v2::TextContent::new("world")),
9658            ])),
9659        );
9660
9661        let notifications = v2_to_v1_many(notification).expect("v2 -> v1 conversion");
9662        assert_eq!(
9663            notifications,
9664            vec![
9665                v1::SessionNotification::new(
9666                    "sess",
9667                    v1::SessionUpdate::AgentMessageChunk(
9668                        v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new(
9669                            "hello"
9670                        )))
9671                        .message_id("msg_agent")
9672                    )
9673                ),
9674                v1::SessionNotification::new(
9675                    "sess",
9676                    v1::SessionUpdate::AgentMessageChunk(
9677                        v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new(
9678                            "world"
9679                        )))
9680                        .message_id("msg_agent")
9681                    )
9682                ),
9683            ]
9684        );
9685    }
9686
9687    #[test]
9688    fn v2_json_rpc_agent_notification_fans_out_to_v1_chunk_notifications() {
9689        let message = v2::JsonRpcMessage::wrap(v2::Notification {
9690            method: "session/update".into(),
9691            params: Some(v2::AgentNotification::SessionNotification(Box::new(
9692                v2::SessionNotification::new(
9693                    "sess",
9694                    v2::SessionUpdate::AgentMessage(v2::AgentMessage::new("msg_agent").content(
9695                        vec![
9696                            v2::ContentBlock::Text(v2::TextContent::new("hello")),
9697                            v2::ContentBlock::Text(v2::TextContent::new("world")),
9698                        ],
9699                    )),
9700                ),
9701            ))),
9702        });
9703
9704        let messages = v2_to_v1_many(message).expect("v2 -> v1 conversion");
9705        let json = messages
9706            .into_iter()
9707            .map(|message| serde_json::to_value(message).expect("serialize v1 message"))
9708            .collect::<Vec<_>>();
9709        assert_eq!(
9710            json,
9711            vec![
9712                serde_json::json!({
9713                    "jsonrpc": "2.0",
9714                    "method": "session/update",
9715                    "params": {
9716                        "sessionId": "sess",
9717                        "update": {
9718                            "sessionUpdate": "agent_message_chunk",
9719                            "content": {
9720                                "type": "text",
9721                                "text": "hello"
9722                            },
9723                            "messageId": "msg_agent"
9724                        }
9725                    }
9726                }),
9727                serde_json::json!({
9728                    "jsonrpc": "2.0",
9729                    "method": "session/update",
9730                    "params": {
9731                        "sessionId": "sess",
9732                        "update": {
9733                            "sessionUpdate": "agent_message_chunk",
9734                            "content": {
9735                                "type": "text",
9736                                "text": "world"
9737                            },
9738                            "messageId": "msg_agent"
9739                        }
9740                    }
9741                }),
9742            ]
9743        );
9744    }
9745
9746    #[test]
9747    fn v2_message_patches_and_clears_do_not_convert_to_v1_chunks() {
9748        assert_v2_to_v1_many_error(
9749            v2::SessionUpdate::AgentMessage(v2::AgentMessage::new("msg_agent")),
9750            "v2 SessionUpdate variant `agent_message` without content cannot be represented in v1 chunks",
9751        );
9752
9753        assert_v2_to_v1_many_error(
9754            v2::SessionUpdate::AgentMessage(
9755                v2::AgentMessage::new("msg_agent").content(None::<Vec<v2::ContentBlock>>),
9756            ),
9757            "v2 SessionUpdate variant `agent_message` with null content cannot be represented in v1 chunks",
9758        );
9759
9760        assert_v2_to_v1_many_error(
9761            v2::SessionUpdate::AgentMessage(
9762                v2::AgentMessage::new("msg_agent").content(Vec::<v2::ContentBlock>::new()),
9763            ),
9764            "v2 SessionUpdate variant `agent_message` with empty content cannot be represented in v1 chunks",
9765        );
9766
9767        assert_v2_to_v1_many_error(
9768            v2::SessionUpdate::AgentMessage(
9769                v2::AgentMessage::new("msg_agent")
9770                    .content(vec![v2::ContentBlock::Text(v2::TextContent::new("hello"))])
9771                    .meta(None::<v2::Meta>),
9772            ),
9773            "v2 SessionUpdate variant `agent_message` with null _meta cannot be represented in v1 chunks",
9774        );
9775    }
9776
9777    #[test]
9778    fn v2_tool_call_content_chunk_does_not_convert_to_v1_replacement_update() {
9779        assert_v2_to_v1_many_error(
9780            v2::SessionUpdate::ToolCallContentChunk(v2::ToolCallContentChunk::new(
9781                "tc_1",
9782                v2::ContentBlock::Text(v2::TextContent::new("partial output")),
9783            )),
9784            "v2 SessionUpdate variant `tool_call_content_chunk` cannot be represented in v1 because v1 tool-call content updates replace content instead of appending",
9785        );
9786    }
9787
9788    #[test]
9789    fn v1_content_chunk_without_message_id_does_not_convert_to_v2() {
9790        assert_v1_to_v2_error(
9791            v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new("missing"))),
9792            "v1 ContentChunk without messageId cannot be represented in v2",
9793        );
9794    }
9795
9796    #[test]
9797    fn v1_plan_session_update_converts_to_v2_item_plan_update() {
9798        let update = v1::SessionUpdate::Plan(v1::Plan::new(vec![v1::PlanEntry::new(
9799            "step",
9800            v1::PlanEntryPriority::High,
9801            v1::PlanEntryStatus::InProgress,
9802        )]));
9803
9804        let as_v2: v2::SessionUpdate = v1_to_v2(update.clone()).unwrap();
9805        assert_eq!(
9806            serde_json::to_value(&as_v2).unwrap(),
9807            serde_json::json!({
9808                "sessionUpdate": "plan_update",
9809                "plan": {
9810                    "type": "items",
9811                    "id": LEGACY_V1_PLAN_ID,
9812                    "entries": [
9813                        {
9814                            "content": "step",
9815                            "priority": "high",
9816                            "status": "in_progress"
9817                        }
9818                    ]
9819                }
9820            })
9821        );
9822
9823        let back = v2_to_v1_many(as_v2).unwrap();
9824        #[cfg(not(feature = "unstable_plan_operations"))]
9825        assert_eq!(back, vec![update]);
9826        #[cfg(feature = "unstable_plan_operations")]
9827        assert!(matches!(
9828            back.as_slice(),
9829            [v1::SessionUpdate::PlanUpdate(_)]
9830        ));
9831    }
9832
9833    #[test]
9834    fn unknown_v2_session_update_does_not_convert_to_v1() {
9835        let update = v2::SessionUpdate::Other(v2::OtherSessionUpdate::new(
9836            "_status_badge",
9837            std::collections::BTreeMap::new(),
9838        ));
9839
9840        assert_v2_to_v1_many_error(
9841            update,
9842            "v2 SessionUpdate variant `_status_badge` cannot be represented in v1",
9843        );
9844    }
9845
9846    #[test]
9847    fn v2_state_update_does_not_convert_to_v1() {
9848        assert_v2_to_v1_many_error(
9849            v2::SessionUpdate::StateUpdate(v2::StateUpdate::Idle(
9850                v2::IdleStateUpdate::new().stop_reason(v2::StopReason::EndTurn),
9851            )),
9852            "v2 SessionUpdate variant `state_update` cannot be represented in v1 because v1 reports completion in the session/prompt response",
9853        );
9854    }
9855
9856    #[test]
9857    fn v1_current_mode_update_does_not_convert_to_v2() {
9858        assert_v1_to_v2_error(
9859            v1::SessionUpdate::CurrentModeUpdate(v1::CurrentModeUpdate::new("ask")),
9860            "v1 SessionUpdate variant `current_mode_update` cannot be represented in v2",
9861        );
9862    }
9863
9864    #[test]
9865    fn v1_session_mode_methods_do_not_convert_to_v2() {
9866        assert_v1_to_v2_error(
9867            v1::ClientRequest::SetSessionModeRequest(v1::SetSessionModeRequest::new("sess", "ask")),
9868            "v1 ClientRequest variant `session/set_mode` cannot be represented in v2",
9869        );
9870        assert_v1_to_v2_error(
9871            v1::AgentResponse::SetSessionModeResponse(v1::SetSessionModeResponse::new()),
9872            "v1 AgentResponse variant `session/set_mode` cannot be represented in v2",
9873        );
9874    }
9875
9876    #[test]
9877    fn v1_session_response_modes_fall_back_to_none_in_v2() {
9878        let response = v1::NewSessionResponse::new("sess").modes(v1::SessionModeState::new(
9879            "ask",
9880            vec![v1::SessionMode::new("ask", "Ask")],
9881        ));
9882
9883        let as_v2: v2::NewSessionResponse = v1_to_v2(response).unwrap();
9884        let back_to_v1: v1::NewSessionResponse = v2_to_v1(as_v2).unwrap();
9885
9886        assert!(back_to_v1.modes.is_none());
9887    }
9888
9889    #[test]
9890    fn v2_session_response_converts_to_v1_without_mode_state() {
9891        let response: v1::NewSessionResponse =
9892            v2_to_v1(v2::NewSessionResponse::new("sess")).unwrap();
9893
9894        assert!(response.modes.is_none());
9895    }
9896
9897    #[test]
9898    fn v2_tool_call_update_conversion_matches_v1_default_on_error_fields() {
9899        let update = v2::ToolCallUpdate::new("tc")
9900            .kind(v2::ToolKind::Unknown("_future_kind".to_string()))
9901            .status(v2::ToolCallStatus::Other("_paused".to_string()))
9902            .content(vec![
9903                v2::ToolCallContent::Other(v2::OtherToolCallContent::new(
9904                    "_chart",
9905                    BTreeMap::default(),
9906                )),
9907                v2::ToolCallContent::Diff(v2::Diff::new("/tmp/file.txt", "new")),
9908            ]);
9909
9910        let converted: v1::ToolCallUpdate = v2_to_v1(update).unwrap();
9911
9912        assert_eq!(converted.fields.kind, None);
9913        assert_eq!(converted.fields.status, None);
9914        assert_eq!(
9915            converted.fields.content,
9916            Some(vec![v1::ToolCallContent::Diff(v1::Diff::new(
9917                "/tmp/file.txt",
9918                "new"
9919            ))])
9920        );
9921    }
9922
9923    #[test]
9924    fn v2_collection_conversion_skips_items_like_v1_vec_skip_error() {
9925        let response = v2::InitializeResponse::new(ProtocolVersion::V2)
9926            .capabilities(v2::AgentCapabilities::new().session(v2::SessionCapabilities::new()))
9927            .auth_methods(vec![
9928                v2::AuthMethod::Other(v2::OtherAuthMethod::new(
9929                    "_oauth",
9930                    "oauth",
9931                    "OAuth",
9932                    BTreeMap::default(),
9933                )),
9934                v2::AuthMethod::Agent(v2::AuthMethodAgent::new("agent", "Agent")),
9935            ]);
9936        let converted: v1::InitializeResponse = v2_to_v1(response).unwrap();
9937        assert_eq!(converted.auth_methods.len(), 1);
9938        assert!(matches!(
9939            converted.auth_methods[0],
9940            v1::AuthMethod::Agent(_)
9941        ));
9942
9943        let config_update = v2::ConfigOptionUpdate::new(vec![
9944            v2::SessionConfigOption::select(
9945                "mode",
9946                "Mode",
9947                "ask",
9948                vec![v2::SessionConfigSelectOption::new("ask", "Ask")],
9949            ),
9950            v2::SessionConfigOption::new(
9951                "future",
9952                "Future",
9953                v2::SessionConfigKind::Other(v2::OtherSessionConfigKind::new(
9954                    "_slider",
9955                    BTreeMap::default(),
9956                )),
9957            ),
9958        ]);
9959        let converted: v1::ConfigOptionUpdate = v2_to_v1(config_update).unwrap();
9960        assert_eq!(converted.config_options.len(), 1);
9961        assert_eq!(converted.config_options[0].id.0.as_ref(), "mode");
9962    }
9963
9964    #[test]
9965    fn v2_default_on_error_fields_drop_unrepresentable_nested_values() {
9966        let command = v2::AvailableCommand::new("review", "Review changes").input(
9967            v2::AvailableCommandInput::Other(v2::OtherAvailableCommandInput::new(
9968                "_choices",
9969                BTreeMap::default(),
9970            )),
9971        );
9972        let converted: v1::AvailableCommandsUpdate =
9973            v2_to_v1(v2::AvailableCommandsUpdate::new(vec![command])).unwrap();
9974
9975        assert_eq!(converted.available_commands.len(), 1);
9976        assert_eq!(converted.available_commands[0].input, None);
9977
9978        let content = v2::TextContent::new("hello").annotations(
9979            v2::Annotations::new()
9980                .audience(vec![v2::Role::Other("_critic".to_string()), v2::Role::User]),
9981        );
9982        let converted: v1::TextContent = v2_to_v1(content).unwrap();
9983
9984        assert_eq!(
9985            converted
9986                .annotations
9987                .and_then(|annotations| annotations.audience),
9988            Some(vec![v1::Role::User])
9989        );
9990    }
9991
9992    #[test]
9993    fn v2_plan_entries_skip_unrepresentable_items_inside_tolerant_vectors() {
9994        let update = v2::PlanUpdate::new(v2::PlanUpdateContent::items(
9995            "main",
9996            vec![
9997                v2::PlanEntry::new(
9998                    "keep",
9999                    v2::PlanEntryPriority::High,
10000                    v2::PlanEntryStatus::Pending,
10001                ),
10002                v2::PlanEntry::new(
10003                    "drop",
10004                    v2::PlanEntryPriority::Other("_critical".to_string()),
10005                    v2::PlanEntryStatus::Pending,
10006                ),
10007            ],
10008        ));
10009
10010        #[cfg(not(feature = "unstable_plan_operations"))]
10011        {
10012            let converted: v1::Plan = v2_to_v1(update).unwrap();
10013            assert_eq!(converted.entries.len(), 1);
10014            assert_eq!(converted.entries[0].content, "keep");
10015        }
10016
10017        #[cfg(feature = "unstable_plan_operations")]
10018        {
10019            let converted: v1::PlanUpdate = v2_to_v1(update).unwrap();
10020            let v1::PlanUpdateContent::Items(items) = converted.plan else {
10021                panic!("expected item plan update");
10022            };
10023            assert_eq!(items.entries.len(), 1);
10024            assert_eq!(items.entries[0].content, "keep");
10025        }
10026    }
10027
10028    #[test]
10029    fn v1_tool_call_update_conversion_skips_items_for_v2_vec_skip_error_fields() {
10030        let update = v1::ToolCallUpdate::new(
10031            "tc",
10032            v1::ToolCallUpdateFields::new().content(vec![
10033                v1::ToolCallContent::Terminal(v1::Terminal::new("term")),
10034                v1::ToolCallContent::Diff(v1::Diff::new("/tmp/file.txt", "new")),
10035            ]),
10036        );
10037
10038        let converted: v2::ToolCallUpdate = v1_to_v2(update).unwrap();
10039        assert_eq!(
10040            converted.content,
10041            crate::MaybeUndefined::Value(vec![v2::ToolCallContent::Diff(v2::Diff::new(
10042                "/tmp/file.txt",
10043                "new"
10044            ))])
10045        );
10046    }
10047
10048    #[test]
10049    fn unknown_v2_raw_fallbacks_do_not_convert_to_v1() {
10050        assert_v2_to_v1_error(
10051            v2::ContentBlock::Other(v2::OtherContentBlock::new(
10052                "_widget",
10053                std::collections::BTreeMap::new(),
10054            )),
10055            "v2 ContentBlock variant `_widget` cannot be represented in v1",
10056        );
10057        assert_v2_to_v1_error(
10058            v2::ToolCallContent::Other(v2::OtherToolCallContent::new(
10059                "_chart",
10060                std::collections::BTreeMap::new(),
10061            )),
10062            "v2 ToolCallContent variant `_chart` cannot be represented in v1",
10063        );
10064        assert_v2_to_v1_error(
10065            v2::AvailableCommandInput::Other(v2::OtherAvailableCommandInput::new(
10066                "_choices",
10067                std::collections::BTreeMap::new(),
10068            )),
10069            "v2 AvailableCommandInput variant `_choices` cannot be represented in v1",
10070        );
10071        assert_v2_to_v1_error(
10072            v2::SessionConfigKind::Other(v2::OtherSessionConfigKind::new(
10073                "_slider",
10074                std::collections::BTreeMap::new(),
10075            )),
10076            "v2 SessionConfigKind variant `_slider` cannot be represented in v1",
10077        );
10078        assert_v2_to_v1_error(
10079            v2::AuthMethod::Other(v2::OtherAuthMethod::new(
10080                "_oauth",
10081                "oauth",
10082                "OAuth",
10083                std::collections::BTreeMap::new(),
10084            )),
10085            "v2 AuthMethod variant `_oauth` cannot be represented in v1",
10086        );
10087        assert_v2_to_v1_error(
10088            v2::PlanUpdate::new(v2::PlanUpdateContent::Other(
10089                v2::OtherPlanUpdateContent::new(
10090                    "_timeline",
10091                    "plan-1",
10092                    std::collections::BTreeMap::new(),
10093                ),
10094            )),
10095            "v2 PlanUpdateContent variant `_timeline` cannot be represented in v1",
10096        );
10097        #[cfg(feature = "unstable_nes")]
10098        assert_v2_to_v1_error(
10099            v2::NesSuggestion::Other(v2::OtherNesSuggestion::new(
10100                "_preview",
10101                std::collections::BTreeMap::new(),
10102            )),
10103            "v2 NesSuggestion variant `_preview` cannot be represented in v1",
10104        );
10105    }
10106
10107    #[test]
10108    fn round_trips_request_permission_outcomes() {
10109        let cancelled = v1::RequestPermissionResponse::new(v1::RequestPermissionOutcome::Cancelled);
10110        assert_v1_round_trip::<v1::RequestPermissionResponse, v2::RequestPermissionResponse>(
10111            cancelled,
10112        );
10113
10114        let selected = v1::RequestPermissionResponse::new(v1::RequestPermissionOutcome::Selected(
10115            v1::SelectedPermissionOutcome::new("opt_1"),
10116        ));
10117        assert_v1_round_trip::<v1::RequestPermissionResponse, v2::RequestPermissionResponse>(
10118            selected,
10119        );
10120    }
10121
10122    #[test]
10123    fn round_trips_error_with_data_payload() {
10124        let err = v1::Error::invalid_params().data(serde_json::json!({
10125            "reason": "missing field",
10126            "field": "sessionId",
10127        }));
10128        assert_v1_round_trip::<v1::Error, v2::Error>(err);
10129    }
10130
10131    #[test]
10132    fn round_trips_v2_value_back_through_v1() {
10133        // Same coverage but starting from v2, to exercise IntoV1 explicitly.
10134        let request = v2::PromptRequest::new(
10135            "sess_2",
10136            vec![v2::ContentBlock::Text(v2::TextContent::new("hi"))],
10137        );
10138        assert_v2_round_trip::<v2::PromptRequest, v1::PromptRequest>(request.clone());
10139        assert_json_eq_after_v2_to_v1::<v2::PromptRequest, v1::PromptRequest>(request);
10140    }
10141
10142    #[test]
10143    fn protocol_version_v1_constant_is_unchanged_by_feature_flag() {
10144        // Guards against `LATEST` accidentally being re-pointed to V2 in the
10145        // future; the contract is that `LATEST` is always the latest **stable**
10146        // version, even when the v2 draft feature is enabled.
10147        assert_eq!(ProtocolVersion::LATEST, ProtocolVersion::V1);
10148    }
10149
10150    /// `?` bubbles a [`ProtocolConversionError`] into a [`v1::Error`] without
10151    /// loss of message, mapped onto the internal-error code.
10152    #[test]
10153    fn protocol_conversion_error_maps_into_v1_error() {
10154        fn run() -> std::result::Result<(), v1::Error> {
10155            // Synthesize a conversion error so we don't have to wait for v2
10156            // to actually diverge before exercising the `?` path.
10157            Err(ProtocolConversionError::new("missing required field"))?;
10158            unreachable!();
10159        }
10160
10161        let err = run().unwrap_err();
10162        assert_eq!(err.code, v1::ErrorCode::InternalError);
10163        assert_eq!(
10164            err.data,
10165            Some(serde_json::Value::String(
10166                "missing required field".to_string()
10167            ))
10168        );
10169    }
10170
10171    /// Mirror of the v1 test for the v2 [`Error`] type.
10172    #[test]
10173    fn protocol_conversion_error_maps_into_v2_error() {
10174        fn run() -> std::result::Result<(), v2::Error> {
10175            Err(ProtocolConversionError::new("missing required field"))?;
10176            unreachable!();
10177        }
10178
10179        let err = run().unwrap_err();
10180        assert_eq!(err.code, v2::ErrorCode::InternalError);
10181        assert_eq!(
10182            err.data,
10183            Some(serde_json::Value::String(
10184                "missing required field".to_string()
10185            ))
10186        );
10187    }
10188}