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::ToolCallContentChunk(_) => {
1034                return Err(ProtocolConversionError::new(
1035                    "v2 SessionUpdate variant `tool_call_content_chunk` cannot be represented in v1 because v1 tool-call content updates replace content instead of appending",
1036                ));
1037            }
1038            Self::ToolCallUpdate(value) => {
1039                vec![crate::v1::SessionUpdate::ToolCallUpdate(value.into_v1()?)]
1040            }
1041            #[cfg(feature = "unstable_plan_operations")]
1042            Self::PlanUpdate(value) => vec![crate::v1::SessionUpdate::PlanUpdate(value.into_v1()?)],
1043            #[cfg(not(feature = "unstable_plan_operations"))]
1044            Self::PlanUpdate(value) => vec![crate::v1::SessionUpdate::Plan(value.into_v1()?)],
1045            #[cfg(feature = "unstable_plan_operations")]
1046            Self::PlanRemoved(value) => {
1047                vec![crate::v1::SessionUpdate::PlanRemoved(value.into_v1()?)]
1048            }
1049            Self::AvailableCommandsUpdate(value) => {
1050                vec![crate::v1::SessionUpdate::AvailableCommandsUpdate(
1051                    value.into_v1()?,
1052                )]
1053            }
1054            Self::ConfigOptionUpdate(value) => {
1055                vec![crate::v1::SessionUpdate::ConfigOptionUpdate(
1056                    value.into_v1()?,
1057                )]
1058            }
1059            Self::SessionInfoUpdate(value) => {
1060                vec![crate::v1::SessionUpdate::SessionInfoUpdate(
1061                    value.into_v1()?,
1062                )]
1063            }
1064            Self::UsageUpdate(value) => {
1065                vec![crate::v1::SessionUpdate::UsageUpdate(value.into_v1()?)]
1066            }
1067            Self::Other(value) => {
1068                return Err(unknown_v2_enum_variant(
1069                    "SessionUpdate",
1070                    &value.session_update,
1071                ));
1072            }
1073        })
1074    }
1075}
1076
1077fn v2_message_update_into_v1_chunks(
1078    variant: &str,
1079    message_id: super::MessageId,
1080    content: crate::MaybeUndefined<Vec<super::ContentBlock>>,
1081    meta: crate::MaybeUndefined<super::Meta>,
1082    wrap: impl Fn(crate::v1::ContentChunk) -> crate::v1::SessionUpdate,
1083) -> Result<Vec<crate::v1::SessionUpdate>> {
1084    let content = match content {
1085        crate::MaybeUndefined::Value(content) if !content.is_empty() => content,
1086        crate::MaybeUndefined::Value(_) => {
1087            return Err(ProtocolConversionError::new(format!(
1088                "v2 SessionUpdate variant `{variant}` with empty content cannot be represented in v1 chunks"
1089            )));
1090        }
1091        crate::MaybeUndefined::Null => {
1092            return Err(ProtocolConversionError::new(format!(
1093                "v2 SessionUpdate variant `{variant}` with null content cannot be represented in v1 chunks"
1094            )));
1095        }
1096        crate::MaybeUndefined::Undefined => {
1097            return Err(ProtocolConversionError::new(format!(
1098                "v2 SessionUpdate variant `{variant}` without content cannot be represented in v1 chunks"
1099            )));
1100        }
1101    };
1102    let message_id = message_id.into_v1()?;
1103    let meta = match meta {
1104        crate::MaybeUndefined::Value(meta) => Some(meta.into_v1()?),
1105        crate::MaybeUndefined::Null => {
1106            return Err(ProtocolConversionError::new(format!(
1107                "v2 SessionUpdate variant `{variant}` with null _meta cannot be represented in v1 chunks"
1108            )));
1109        }
1110        crate::MaybeUndefined::Undefined => None,
1111    };
1112
1113    content
1114        .into_iter()
1115        .map(|content| {
1116            Ok(wrap(crate::v1::ContentChunk {
1117                content: content.into_v1()?,
1118                message_id: Some(message_id.clone()),
1119                meta: meta.clone(),
1120            }))
1121        })
1122        .collect()
1123}
1124
1125impl IntoV2 for crate::v1::SessionUpdate {
1126    type Output = super::SessionUpdate;
1127
1128    fn into_v2(self) -> Result<Self::Output> {
1129        Ok(match self {
1130            Self::UserMessageChunk(value) => {
1131                super::SessionUpdate::UserMessageChunk(value.into_v2()?)
1132            }
1133            Self::AgentMessageChunk(value) => {
1134                super::SessionUpdate::AgentMessageChunk(value.into_v2()?)
1135            }
1136            Self::AgentThoughtChunk(value) => {
1137                super::SessionUpdate::AgentThoughtChunk(value.into_v2()?)
1138            }
1139            Self::ToolCall(value) => super::SessionUpdate::ToolCallUpdate(value.into_v2()?),
1140            Self::ToolCallUpdate(value) => super::SessionUpdate::ToolCallUpdate(value.into_v2()?),
1141            Self::Plan(value) => {
1142                let crate::v1::Plan { entries, meta } = value;
1143                super::SessionUpdate::PlanUpdate(super::PlanUpdate {
1144                    plan: super::PlanUpdateContent::items(LEGACY_V1_PLAN_ID, entries.into_v2()?),
1145                    meta: meta.into_v2()?,
1146                })
1147            }
1148            #[cfg(feature = "unstable_plan_operations")]
1149            Self::PlanUpdate(value) => super::SessionUpdate::PlanUpdate(value.into_v2()?),
1150            #[cfg(feature = "unstable_plan_operations")]
1151            Self::PlanRemoved(value) => super::SessionUpdate::PlanRemoved(value.into_v2()?),
1152            Self::AvailableCommandsUpdate(value) => {
1153                super::SessionUpdate::AvailableCommandsUpdate(value.into_v2()?)
1154            }
1155            Self::CurrentModeUpdate(_) => {
1156                return Err(removed_v1_enum_variant(
1157                    "SessionUpdate",
1158                    "current_mode_update",
1159                ));
1160            }
1161            Self::ConfigOptionUpdate(value) => {
1162                super::SessionUpdate::ConfigOptionUpdate(value.into_v2()?)
1163            }
1164            Self::SessionInfoUpdate(value) => {
1165                super::SessionUpdate::SessionInfoUpdate(value.into_v2()?)
1166            }
1167            Self::UsageUpdate(value) => super::SessionUpdate::UsageUpdate(value.into_v2()?),
1168        })
1169    }
1170}
1171
1172impl IntoV1 for super::ConfigOptionUpdate {
1173    type Output = crate::v1::ConfigOptionUpdate;
1174
1175    fn into_v1(self) -> Result<Self::Output> {
1176        let Self {
1177            config_options,
1178            meta,
1179        } = self;
1180        Ok(crate::v1::ConfigOptionUpdate {
1181            config_options: into_v1_vec_skip_errors(config_options),
1182            meta: meta.into_v1()?,
1183        })
1184    }
1185}
1186
1187impl IntoV2 for crate::v1::ConfigOptionUpdate {
1188    type Output = super::ConfigOptionUpdate;
1189
1190    fn into_v2(self) -> Result<Self::Output> {
1191        let Self {
1192            config_options,
1193            meta,
1194        } = self;
1195        Ok(super::ConfigOptionUpdate {
1196            config_options: into_v2_vec_skip_errors(config_options),
1197            meta: meta.into_v2()?,
1198        })
1199    }
1200}
1201
1202impl IntoV1 for super::SessionInfoUpdate {
1203    type Output = crate::v1::SessionInfoUpdate;
1204
1205    fn into_v1(self) -> Result<Self::Output> {
1206        let Self {
1207            title,
1208            updated_at,
1209            meta,
1210        } = self;
1211        Ok(crate::v1::SessionInfoUpdate {
1212            title: title.into_v1()?,
1213            updated_at: updated_at.into_v1()?,
1214            meta: meta.into_v1()?,
1215        })
1216    }
1217}
1218
1219impl IntoV2 for crate::v1::SessionInfoUpdate {
1220    type Output = super::SessionInfoUpdate;
1221
1222    fn into_v2(self) -> Result<Self::Output> {
1223        let Self {
1224            title,
1225            updated_at,
1226            meta,
1227        } = self;
1228        Ok(super::SessionInfoUpdate {
1229            title: title.into_v2()?,
1230            updated_at: updated_at.into_v2()?,
1231            meta: meta.into_v2()?,
1232        })
1233    }
1234}
1235
1236impl IntoV1 for super::UsageUpdate {
1237    type Output = crate::v1::UsageUpdate;
1238
1239    fn into_v1(self) -> Result<Self::Output> {
1240        let Self {
1241            used,
1242            size,
1243            cost,
1244            meta,
1245        } = self;
1246        Ok(crate::v1::UsageUpdate {
1247            used: used.into_v1()?,
1248            size: size.into_v1()?,
1249            cost: into_v1_default_on_error(cost),
1250            meta: meta.into_v1()?,
1251        })
1252    }
1253}
1254
1255impl IntoV2 for crate::v1::UsageUpdate {
1256    type Output = super::UsageUpdate;
1257
1258    fn into_v2(self) -> Result<Self::Output> {
1259        let Self {
1260            used,
1261            size,
1262            cost,
1263            meta,
1264        } = self;
1265        Ok(super::UsageUpdate {
1266            used: used.into_v2()?,
1267            size: size.into_v2()?,
1268            cost: into_v2_default_on_error(cost),
1269            meta: meta.into_v2()?,
1270        })
1271    }
1272}
1273
1274impl IntoV1 for super::Cost {
1275    type Output = crate::v1::Cost;
1276
1277    fn into_v1(self) -> Result<Self::Output> {
1278        let Self {
1279            amount,
1280            currency,
1281            meta,
1282        } = self;
1283        Ok(crate::v1::Cost {
1284            amount: amount.into_v1()?,
1285            currency: currency.into_v1()?,
1286            meta: meta.into_v1()?,
1287        })
1288    }
1289}
1290
1291impl IntoV2 for crate::v1::Cost {
1292    type Output = super::Cost;
1293
1294    fn into_v2(self) -> Result<Self::Output> {
1295        let Self {
1296            amount,
1297            currency,
1298            meta,
1299        } = self;
1300        Ok(super::Cost {
1301            amount: amount.into_v2()?,
1302            currency: currency.into_v2()?,
1303            meta: meta.into_v2()?,
1304        })
1305    }
1306}
1307
1308impl IntoV1 for super::ContentChunk {
1309    type Output = crate::v1::ContentChunk;
1310
1311    fn into_v1(self) -> Result<Self::Output> {
1312        let Self {
1313            content,
1314            message_id,
1315            meta,
1316        } = self;
1317        Ok(crate::v1::ContentChunk {
1318            content: content.into_v1()?,
1319            message_id: Some(message_id.into_v1()?),
1320            meta: meta.into_v1()?,
1321        })
1322    }
1323}
1324
1325impl IntoV2 for crate::v1::ContentChunk {
1326    type Output = super::ContentChunk;
1327
1328    fn into_v2(self) -> Result<Self::Output> {
1329        let Self {
1330            content,
1331            message_id,
1332            meta,
1333        } = self;
1334        Ok(super::ContentChunk {
1335            content: content.into_v2()?,
1336            message_id: message_id
1337                .ok_or_else(|| {
1338                    ProtocolConversionError::new(
1339                        "v1 ContentChunk without messageId cannot be represented in v2",
1340                    )
1341                })?
1342                .into_v2()?,
1343            meta: meta.into_v2()?,
1344        })
1345    }
1346}
1347
1348impl IntoV1 for super::AvailableCommandsUpdate {
1349    type Output = crate::v1::AvailableCommandsUpdate;
1350
1351    fn into_v1(self) -> Result<Self::Output> {
1352        let Self {
1353            available_commands,
1354            meta,
1355        } = self;
1356        Ok(crate::v1::AvailableCommandsUpdate {
1357            available_commands: into_v1_vec_skip_errors(available_commands),
1358            meta: meta.into_v1()?,
1359        })
1360    }
1361}
1362
1363impl IntoV2 for crate::v1::AvailableCommandsUpdate {
1364    type Output = super::AvailableCommandsUpdate;
1365
1366    fn into_v2(self) -> Result<Self::Output> {
1367        let Self {
1368            available_commands,
1369            meta,
1370        } = self;
1371        Ok(super::AvailableCommandsUpdate {
1372            available_commands: into_v2_vec_skip_errors(available_commands),
1373            meta: meta.into_v2()?,
1374        })
1375    }
1376}
1377
1378impl IntoV1 for super::AvailableCommand {
1379    type Output = crate::v1::AvailableCommand;
1380
1381    fn into_v1(self) -> Result<Self::Output> {
1382        let Self {
1383            name,
1384            description,
1385            input,
1386            meta,
1387        } = self;
1388        Ok(crate::v1::AvailableCommand {
1389            name: name.into_v1()?,
1390            description: description.into_v1()?,
1391            input: into_v1_default_on_error(input),
1392            meta: meta.into_v1()?,
1393        })
1394    }
1395}
1396
1397impl IntoV2 for crate::v1::AvailableCommand {
1398    type Output = super::AvailableCommand;
1399
1400    fn into_v2(self) -> Result<Self::Output> {
1401        let Self {
1402            name,
1403            description,
1404            input,
1405            meta,
1406        } = self;
1407        Ok(super::AvailableCommand {
1408            name: name.into_v2()?,
1409            description: description.into_v2()?,
1410            input: into_v2_default_on_error(input),
1411            meta: meta.into_v2()?,
1412        })
1413    }
1414}
1415
1416impl IntoV1 for super::AvailableCommandInput {
1417    type Output = crate::v1::AvailableCommandInput;
1418
1419    fn into_v1(self) -> Result<Self::Output> {
1420        Ok(match self {
1421            Self::Unstructured(value) => {
1422                crate::v1::AvailableCommandInput::Unstructured(value.into_v1()?)
1423            }
1424            Self::Other(value) => {
1425                return Err(unknown_v2_enum_variant(
1426                    "AvailableCommandInput",
1427                    &value.type_,
1428                ));
1429            }
1430        })
1431    }
1432}
1433
1434impl IntoV2 for crate::v1::AvailableCommandInput {
1435    type Output = super::AvailableCommandInput;
1436
1437    fn into_v2(self) -> Result<Self::Output> {
1438        Ok(match self {
1439            Self::Unstructured(value) => {
1440                super::AvailableCommandInput::Unstructured(value.into_v2()?)
1441            }
1442        })
1443    }
1444}
1445
1446impl IntoV1 for super::UnstructuredCommandInput {
1447    type Output = crate::v1::UnstructuredCommandInput;
1448
1449    fn into_v1(self) -> Result<Self::Output> {
1450        let Self { hint, meta } = self;
1451        Ok(crate::v1::UnstructuredCommandInput {
1452            hint: hint.into_v1()?,
1453            meta: meta.into_v1()?,
1454        })
1455    }
1456}
1457
1458impl IntoV2 for crate::v1::UnstructuredCommandInput {
1459    type Output = super::UnstructuredCommandInput;
1460
1461    fn into_v2(self) -> Result<Self::Output> {
1462        let Self { hint, meta } = self;
1463        Ok(super::UnstructuredCommandInput {
1464            hint: hint.into_v2()?,
1465            meta: meta.into_v2()?,
1466        })
1467    }
1468}
1469
1470impl IntoV1 for super::RequestPermissionRequest {
1471    type Output = crate::v1::RequestPermissionRequest;
1472
1473    fn into_v1(self) -> Result<Self::Output> {
1474        let Self {
1475            session_id,
1476            tool_call,
1477            options,
1478            meta,
1479        } = self;
1480        Ok(crate::v1::RequestPermissionRequest {
1481            session_id: session_id.into_v1()?,
1482            tool_call: tool_call.into_v1()?,
1483            options: options.into_v1()?,
1484            meta: meta.into_v1()?,
1485        })
1486    }
1487}
1488
1489impl IntoV2 for crate::v1::RequestPermissionRequest {
1490    type Output = super::RequestPermissionRequest;
1491
1492    fn into_v2(self) -> Result<Self::Output> {
1493        let Self {
1494            session_id,
1495            tool_call,
1496            options,
1497            meta,
1498        } = self;
1499        Ok(super::RequestPermissionRequest {
1500            session_id: session_id.into_v2()?,
1501            tool_call: tool_call.into_v2()?,
1502            options: options.into_v2()?,
1503            meta: meta.into_v2()?,
1504        })
1505    }
1506}
1507
1508impl IntoV1 for super::PermissionOption {
1509    type Output = crate::v1::PermissionOption;
1510
1511    fn into_v1(self) -> Result<Self::Output> {
1512        let Self {
1513            option_id,
1514            name,
1515            kind,
1516            meta,
1517        } = self;
1518        Ok(crate::v1::PermissionOption {
1519            option_id: option_id.into_v1()?,
1520            name: name.into_v1()?,
1521            kind: kind.into_v1()?,
1522            meta: meta.into_v1()?,
1523        })
1524    }
1525}
1526
1527impl IntoV2 for crate::v1::PermissionOption {
1528    type Output = super::PermissionOption;
1529
1530    fn into_v2(self) -> Result<Self::Output> {
1531        let Self {
1532            option_id,
1533            name,
1534            kind,
1535            meta,
1536        } = self;
1537        Ok(super::PermissionOption {
1538            option_id: option_id.into_v2()?,
1539            name: name.into_v2()?,
1540            kind: kind.into_v2()?,
1541            meta: meta.into_v2()?,
1542        })
1543    }
1544}
1545
1546impl IntoV1 for super::PermissionOptionId {
1547    type Output = crate::v1::PermissionOptionId;
1548
1549    fn into_v1(self) -> Result<Self::Output> {
1550        Ok(crate::v1::PermissionOptionId(self.0.into_v1()?))
1551    }
1552}
1553
1554impl IntoV2 for crate::v1::PermissionOptionId {
1555    type Output = super::PermissionOptionId;
1556
1557    fn into_v2(self) -> Result<Self::Output> {
1558        Ok(super::PermissionOptionId(self.0.into_v2()?))
1559    }
1560}
1561
1562impl IntoV1 for super::PermissionOptionKind {
1563    type Output = crate::v1::PermissionOptionKind;
1564
1565    fn into_v1(self) -> Result<Self::Output> {
1566        Ok(match self {
1567            Self::AllowOnce => crate::v1::PermissionOptionKind::AllowOnce,
1568            Self::AllowAlways => crate::v1::PermissionOptionKind::AllowAlways,
1569            Self::RejectOnce => crate::v1::PermissionOptionKind::RejectOnce,
1570            Self::RejectAlways => crate::v1::PermissionOptionKind::RejectAlways,
1571            Self::Other(value) => {
1572                return Err(unknown_v2_enum_variant("PermissionOptionKind", &value));
1573            }
1574        })
1575    }
1576}
1577
1578impl IntoV2 for crate::v1::PermissionOptionKind {
1579    type Output = super::PermissionOptionKind;
1580
1581    fn into_v2(self) -> Result<Self::Output> {
1582        Ok(match self {
1583            Self::AllowOnce => super::PermissionOptionKind::AllowOnce,
1584            Self::AllowAlways => super::PermissionOptionKind::AllowAlways,
1585            Self::RejectOnce => super::PermissionOptionKind::RejectOnce,
1586            Self::RejectAlways => super::PermissionOptionKind::RejectAlways,
1587        })
1588    }
1589}
1590
1591impl IntoV1 for super::RequestPermissionResponse {
1592    type Output = crate::v1::RequestPermissionResponse;
1593
1594    fn into_v1(self) -> Result<Self::Output> {
1595        let Self { outcome, meta } = self;
1596        Ok(crate::v1::RequestPermissionResponse {
1597            outcome: outcome.into_v1()?,
1598            meta: meta.into_v1()?,
1599        })
1600    }
1601}
1602
1603impl IntoV2 for crate::v1::RequestPermissionResponse {
1604    type Output = super::RequestPermissionResponse;
1605
1606    fn into_v2(self) -> Result<Self::Output> {
1607        let Self { outcome, meta } = self;
1608        Ok(super::RequestPermissionResponse {
1609            outcome: outcome.into_v2()?,
1610            meta: meta.into_v2()?,
1611        })
1612    }
1613}
1614
1615impl IntoV1 for super::RequestPermissionOutcome {
1616    type Output = crate::v1::RequestPermissionOutcome;
1617
1618    fn into_v1(self) -> Result<Self::Output> {
1619        Ok(match self {
1620            Self::Cancelled => crate::v1::RequestPermissionOutcome::Cancelled,
1621            Self::Selected(value) => {
1622                crate::v1::RequestPermissionOutcome::Selected(value.into_v1()?)
1623            }
1624        })
1625    }
1626}
1627
1628impl IntoV2 for crate::v1::RequestPermissionOutcome {
1629    type Output = super::RequestPermissionOutcome;
1630
1631    fn into_v2(self) -> Result<Self::Output> {
1632        Ok(match self {
1633            Self::Cancelled => super::RequestPermissionOutcome::Cancelled,
1634            Self::Selected(value) => super::RequestPermissionOutcome::Selected(value.into_v2()?),
1635        })
1636    }
1637}
1638
1639impl IntoV1 for super::SelectedPermissionOutcome {
1640    type Output = crate::v1::SelectedPermissionOutcome;
1641
1642    fn into_v1(self) -> Result<Self::Output> {
1643        let Self { option_id, meta } = self;
1644        Ok(crate::v1::SelectedPermissionOutcome {
1645            option_id: option_id.into_v1()?,
1646            meta: meta.into_v1()?,
1647        })
1648    }
1649}
1650
1651impl IntoV2 for crate::v1::SelectedPermissionOutcome {
1652    type Output = super::SelectedPermissionOutcome;
1653
1654    fn into_v2(self) -> Result<Self::Output> {
1655        let Self { option_id, meta } = self;
1656        Ok(super::SelectedPermissionOutcome {
1657            option_id: option_id.into_v2()?,
1658            meta: meta.into_v2()?,
1659        })
1660    }
1661}
1662
1663#[cfg(feature = "unstable_mcp_over_acp")]
1664impl IntoV1 for super::ConnectMcpRequest {
1665    type Output = crate::v1::ConnectMcpRequest;
1666
1667    fn into_v1(self) -> Result<Self::Output> {
1668        let Self { acp_id, meta } = self;
1669        Ok(crate::v1::ConnectMcpRequest {
1670            acp_id: acp_id.into_v1()?,
1671            meta: meta.into_v1()?,
1672        })
1673    }
1674}
1675
1676#[cfg(feature = "unstable_mcp_over_acp")]
1677impl IntoV2 for crate::v1::ConnectMcpRequest {
1678    type Output = super::ConnectMcpRequest;
1679
1680    fn into_v2(self) -> Result<Self::Output> {
1681        let Self { acp_id, meta } = self;
1682        Ok(super::ConnectMcpRequest {
1683            acp_id: acp_id.into_v2()?,
1684            meta: meta.into_v2()?,
1685        })
1686    }
1687}
1688
1689#[cfg(feature = "unstable_mcp_over_acp")]
1690impl IntoV1 for super::ConnectMcpResponse {
1691    type Output = crate::v1::ConnectMcpResponse;
1692
1693    fn into_v1(self) -> Result<Self::Output> {
1694        let Self {
1695            connection_id,
1696            meta,
1697        } = self;
1698        Ok(crate::v1::ConnectMcpResponse {
1699            connection_id: connection_id.into_v1()?,
1700            meta: meta.into_v1()?,
1701        })
1702    }
1703}
1704
1705#[cfg(feature = "unstable_mcp_over_acp")]
1706impl IntoV2 for crate::v1::ConnectMcpResponse {
1707    type Output = super::ConnectMcpResponse;
1708
1709    fn into_v2(self) -> Result<Self::Output> {
1710        let Self {
1711            connection_id,
1712            meta,
1713        } = self;
1714        Ok(super::ConnectMcpResponse {
1715            connection_id: connection_id.into_v2()?,
1716            meta: meta.into_v2()?,
1717        })
1718    }
1719}
1720
1721#[cfg(feature = "unstable_mcp_over_acp")]
1722impl IntoV1 for super::MessageMcpRequest {
1723    type Output = crate::v1::MessageMcpRequest;
1724
1725    fn into_v1(self) -> Result<Self::Output> {
1726        let Self {
1727            connection_id,
1728            method,
1729            params,
1730            meta,
1731        } = self;
1732        Ok(crate::v1::MessageMcpRequest {
1733            connection_id: connection_id.into_v1()?,
1734            method: method.into_v1()?,
1735            params: params.into_v1()?,
1736            meta: meta.into_v1()?,
1737        })
1738    }
1739}
1740
1741#[cfg(feature = "unstable_mcp_over_acp")]
1742impl IntoV2 for crate::v1::MessageMcpRequest {
1743    type Output = super::MessageMcpRequest;
1744
1745    fn into_v2(self) -> Result<Self::Output> {
1746        let Self {
1747            connection_id,
1748            method,
1749            params,
1750            meta,
1751        } = self;
1752        Ok(super::MessageMcpRequest {
1753            connection_id: connection_id.into_v2()?,
1754            method: method.into_v2()?,
1755            params: params.into_v2()?,
1756            meta: meta.into_v2()?,
1757        })
1758    }
1759}
1760
1761#[cfg(feature = "unstable_mcp_over_acp")]
1762impl IntoV1 for super::MessageMcpNotification {
1763    type Output = crate::v1::MessageMcpNotification;
1764
1765    fn into_v1(self) -> Result<Self::Output> {
1766        let Self {
1767            connection_id,
1768            method,
1769            params,
1770            meta,
1771        } = self;
1772        Ok(crate::v1::MessageMcpNotification {
1773            connection_id: connection_id.into_v1()?,
1774            method: method.into_v1()?,
1775            params: params.into_v1()?,
1776            meta: meta.into_v1()?,
1777        })
1778    }
1779}
1780
1781#[cfg(feature = "unstable_mcp_over_acp")]
1782impl IntoV2 for crate::v1::MessageMcpNotification {
1783    type Output = super::MessageMcpNotification;
1784
1785    fn into_v2(self) -> Result<Self::Output> {
1786        let Self {
1787            connection_id,
1788            method,
1789            params,
1790            meta,
1791        } = self;
1792        Ok(super::MessageMcpNotification {
1793            connection_id: connection_id.into_v2()?,
1794            method: method.into_v2()?,
1795            params: params.into_v2()?,
1796            meta: meta.into_v2()?,
1797        })
1798    }
1799}
1800
1801#[cfg(feature = "unstable_mcp_over_acp")]
1802impl IntoV1 for super::MessageMcpResponse {
1803    type Output = crate::v1::MessageMcpResponse;
1804
1805    fn into_v1(self) -> Result<Self::Output> {
1806        let Self(result) = self;
1807        Ok(crate::v1::MessageMcpResponse::new(result.into_v1()?))
1808    }
1809}
1810
1811#[cfg(feature = "unstable_mcp_over_acp")]
1812impl IntoV2 for crate::v1::MessageMcpResponse {
1813    type Output = super::MessageMcpResponse;
1814
1815    fn into_v2(self) -> Result<Self::Output> {
1816        let Self(result) = self;
1817        Ok(super::MessageMcpResponse::new(result.into_v2()?))
1818    }
1819}
1820
1821#[cfg(feature = "unstable_mcp_over_acp")]
1822impl IntoV1 for super::DisconnectMcpRequest {
1823    type Output = crate::v1::DisconnectMcpRequest;
1824
1825    fn into_v1(self) -> Result<Self::Output> {
1826        let Self {
1827            connection_id,
1828            meta,
1829        } = self;
1830        Ok(crate::v1::DisconnectMcpRequest {
1831            connection_id: connection_id.into_v1()?,
1832            meta: meta.into_v1()?,
1833        })
1834    }
1835}
1836
1837#[cfg(feature = "unstable_mcp_over_acp")]
1838impl IntoV2 for crate::v1::DisconnectMcpRequest {
1839    type Output = super::DisconnectMcpRequest;
1840
1841    fn into_v2(self) -> Result<Self::Output> {
1842        let Self {
1843            connection_id,
1844            meta,
1845        } = self;
1846        Ok(super::DisconnectMcpRequest {
1847            connection_id: connection_id.into_v2()?,
1848            meta: meta.into_v2()?,
1849        })
1850    }
1851}
1852
1853#[cfg(feature = "unstable_mcp_over_acp")]
1854impl IntoV1 for super::DisconnectMcpResponse {
1855    type Output = crate::v1::DisconnectMcpResponse;
1856
1857    fn into_v1(self) -> Result<Self::Output> {
1858        let Self { meta } = self;
1859        Ok(crate::v1::DisconnectMcpResponse {
1860            meta: meta.into_v1()?,
1861        })
1862    }
1863}
1864
1865#[cfg(feature = "unstable_mcp_over_acp")]
1866impl IntoV2 for crate::v1::DisconnectMcpResponse {
1867    type Output = super::DisconnectMcpResponse;
1868
1869    fn into_v2(self) -> Result<Self::Output> {
1870        let Self { meta } = self;
1871        Ok(super::DisconnectMcpResponse {
1872            meta: meta.into_v2()?,
1873        })
1874    }
1875}
1876
1877impl IntoV1 for super::ClientCapabilities {
1878    type Output = crate::v1::ClientCapabilities;
1879
1880    fn into_v1(self) -> Result<Self::Output> {
1881        let Self {
1882            #[cfg(feature = "unstable_auth_methods")]
1883            auth,
1884            #[cfg(feature = "unstable_elicitation")]
1885            elicitation,
1886            #[cfg(feature = "unstable_nes")]
1887            nes,
1888            #[cfg(feature = "unstable_nes")]
1889            position_encodings,
1890            meta,
1891        } = self;
1892        Ok(crate::v1::ClientCapabilities {
1893            fs: crate::v1::FileSystemCapabilities::default(),
1894            terminal: false,
1895            #[cfg(feature = "unstable_plan_operations")]
1896            plan: None,
1897            #[cfg(feature = "unstable_auth_methods")]
1898            auth: auth.into_v1()?,
1899            #[cfg(feature = "unstable_elicitation")]
1900            elicitation: into_v1_default_on_error(elicitation),
1901            #[cfg(feature = "unstable_nes")]
1902            nes: into_v1_default_on_error(nes),
1903            #[cfg(feature = "unstable_nes")]
1904            position_encodings: into_v1_vec_skip_errors(position_encodings),
1905            meta: meta.into_v1()?,
1906        })
1907    }
1908}
1909
1910impl IntoV2 for crate::v1::ClientCapabilities {
1911    type Output = super::ClientCapabilities;
1912
1913    fn into_v2(self) -> Result<Self::Output> {
1914        let Self {
1915            fs: _,
1916            terminal: _,
1917            #[cfg(feature = "unstable_plan_operations")]
1918                plan: _,
1919            #[cfg(feature = "unstable_auth_methods")]
1920            auth,
1921            #[cfg(feature = "unstable_elicitation")]
1922            elicitation,
1923            #[cfg(feature = "unstable_nes")]
1924            nes,
1925            #[cfg(feature = "unstable_nes")]
1926            position_encodings,
1927            meta,
1928        } = self;
1929        Ok(super::ClientCapabilities {
1930            #[cfg(feature = "unstable_auth_methods")]
1931            auth: auth.into_v2()?,
1932            #[cfg(feature = "unstable_elicitation")]
1933            elicitation: into_v2_default_on_error(elicitation),
1934            #[cfg(feature = "unstable_nes")]
1935            nes: into_v2_default_on_error(nes),
1936            #[cfg(feature = "unstable_nes")]
1937            position_encodings: into_v2_vec_skip_errors(position_encodings),
1938            meta: meta.into_v2()?,
1939        })
1940    }
1941}
1942
1943#[cfg(feature = "unstable_auth_methods")]
1944impl IntoV1 for super::AuthCapabilities {
1945    type Output = crate::v1::AuthCapabilities;
1946
1947    fn into_v1(self) -> Result<Self::Output> {
1948        let Self { terminal, meta } = self;
1949        Ok(crate::v1::AuthCapabilities {
1950            terminal: terminal.is_some(),
1951            meta: meta.into_v1()?,
1952        })
1953    }
1954}
1955
1956#[cfg(feature = "unstable_auth_methods")]
1957impl IntoV2 for crate::v1::AuthCapabilities {
1958    type Output = super::AuthCapabilities;
1959
1960    fn into_v2(self) -> Result<Self::Output> {
1961        let Self { terminal, meta } = self;
1962        Ok(super::AuthCapabilities {
1963            terminal: terminal.then(super::TerminalAuthCapabilities::new),
1964            meta: meta.into_v2()?,
1965        })
1966    }
1967}
1968
1969impl IntoV1 for super::AgentRequest {
1970    type Output = crate::v1::AgentRequest;
1971
1972    fn into_v1(self) -> Result<Self::Output> {
1973        Ok(match self {
1974            Self::RequestPermissionRequest(value) => {
1975                crate::v1::AgentRequest::RequestPermissionRequest(value.into_v1()?)
1976            }
1977            #[cfg(feature = "unstable_elicitation")]
1978            Self::CreateElicitationRequest(value) => {
1979                crate::v1::AgentRequest::CreateElicitationRequest(value.into_v1()?)
1980            }
1981            #[cfg(feature = "unstable_mcp_over_acp")]
1982            Self::ConnectMcpRequest(value) => {
1983                crate::v1::AgentRequest::ConnectMcpRequest(value.into_v1()?)
1984            }
1985            #[cfg(feature = "unstable_mcp_over_acp")]
1986            Self::MessageMcpRequest(value) => {
1987                crate::v1::AgentRequest::MessageMcpRequest(value.into_v1()?)
1988            }
1989            #[cfg(feature = "unstable_mcp_over_acp")]
1990            Self::DisconnectMcpRequest(value) => {
1991                crate::v1::AgentRequest::DisconnectMcpRequest(value.into_v1()?)
1992            }
1993            Self::ExtMethodRequest(value) => {
1994                crate::v1::AgentRequest::ExtMethodRequest(value.into_v1()?)
1995            }
1996        })
1997    }
1998}
1999
2000impl IntoV2 for crate::v1::AgentRequest {
2001    type Output = super::AgentRequest;
2002
2003    fn into_v2(self) -> Result<Self::Output> {
2004        Ok(match self {
2005            Self::WriteTextFileRequest(_) => {
2006                return Err(removed_v1_enum_variant(
2007                    "AgentRequest",
2008                    "fs/write_text_file",
2009                ));
2010            }
2011            Self::ReadTextFileRequest(_) => {
2012                return Err(removed_v1_enum_variant("AgentRequest", "fs/read_text_file"));
2013            }
2014            Self::RequestPermissionRequest(value) => {
2015                super::AgentRequest::RequestPermissionRequest(Box::new(value.into_v2()?))
2016            }
2017            Self::CreateTerminalRequest(_) => {
2018                return Err(removed_v1_enum_variant("AgentRequest", "terminal/create"));
2019            }
2020            Self::TerminalOutputRequest(_) => {
2021                return Err(removed_v1_enum_variant("AgentRequest", "terminal/output"));
2022            }
2023            Self::ReleaseTerminalRequest(_) => {
2024                return Err(removed_v1_enum_variant("AgentRequest", "terminal/release"));
2025            }
2026            Self::WaitForTerminalExitRequest(_) => {
2027                return Err(removed_v1_enum_variant(
2028                    "AgentRequest",
2029                    "terminal/wait_for_exit",
2030                ));
2031            }
2032            Self::KillTerminalRequest(_) => {
2033                return Err(removed_v1_enum_variant("AgentRequest", "terminal/kill"));
2034            }
2035            #[cfg(feature = "unstable_elicitation")]
2036            Self::CreateElicitationRequest(value) => {
2037                super::AgentRequest::CreateElicitationRequest(value.into_v2()?)
2038            }
2039            #[cfg(feature = "unstable_mcp_over_acp")]
2040            Self::ConnectMcpRequest(value) => {
2041                super::AgentRequest::ConnectMcpRequest(value.into_v2()?)
2042            }
2043            #[cfg(feature = "unstable_mcp_over_acp")]
2044            Self::MessageMcpRequest(value) => {
2045                super::AgentRequest::MessageMcpRequest(value.into_v2()?)
2046            }
2047            #[cfg(feature = "unstable_mcp_over_acp")]
2048            Self::DisconnectMcpRequest(value) => {
2049                super::AgentRequest::DisconnectMcpRequest(value.into_v2()?)
2050            }
2051            Self::ExtMethodRequest(value) => {
2052                super::AgentRequest::ExtMethodRequest(value.into_v2()?)
2053            }
2054        })
2055    }
2056}
2057
2058impl IntoV1 for super::ClientResponse {
2059    type Output = crate::v1::ClientResponse;
2060
2061    fn into_v1(self) -> Result<Self::Output> {
2062        Ok(match self {
2063            Self::RequestPermissionResponse(value) => {
2064                crate::v1::ClientResponse::RequestPermissionResponse(value.into_v1()?)
2065            }
2066            #[cfg(feature = "unstable_elicitation")]
2067            Self::CreateElicitationResponse(value) => {
2068                crate::v1::ClientResponse::CreateElicitationResponse(value.into_v1()?)
2069            }
2070            #[cfg(feature = "unstable_mcp_over_acp")]
2071            Self::ConnectMcpResponse(value) => {
2072                crate::v1::ClientResponse::ConnectMcpResponse(value.into_v1()?)
2073            }
2074            #[cfg(feature = "unstable_mcp_over_acp")]
2075            Self::MessageMcpResponse(value) => {
2076                crate::v1::ClientResponse::MessageMcpResponse(value.into_v1()?)
2077            }
2078            #[cfg(feature = "unstable_mcp_over_acp")]
2079            Self::DisconnectMcpResponse(value) => {
2080                crate::v1::ClientResponse::DisconnectMcpResponse(value.into_v1()?)
2081            }
2082            Self::ExtMethodResponse(value) => {
2083                crate::v1::ClientResponse::ExtMethodResponse(value.into_v1()?)
2084            }
2085        })
2086    }
2087}
2088
2089impl IntoV2 for crate::v1::ClientResponse {
2090    type Output = super::ClientResponse;
2091
2092    fn into_v2(self) -> Result<Self::Output> {
2093        Ok(match self {
2094            Self::WriteTextFileResponse(_) => {
2095                return Err(removed_v1_enum_variant(
2096                    "ClientResponse",
2097                    "fs/write_text_file",
2098                ));
2099            }
2100            Self::ReadTextFileResponse(_) => {
2101                return Err(removed_v1_enum_variant(
2102                    "ClientResponse",
2103                    "fs/read_text_file",
2104                ));
2105            }
2106            Self::RequestPermissionResponse(value) => {
2107                super::ClientResponse::RequestPermissionResponse(value.into_v2()?)
2108            }
2109            Self::CreateTerminalResponse(_) => {
2110                return Err(removed_v1_enum_variant("ClientResponse", "terminal/create"));
2111            }
2112            Self::TerminalOutputResponse(_) => {
2113                return Err(removed_v1_enum_variant("ClientResponse", "terminal/output"));
2114            }
2115            Self::ReleaseTerminalResponse(_) => {
2116                return Err(removed_v1_enum_variant(
2117                    "ClientResponse",
2118                    "terminal/release",
2119                ));
2120            }
2121            Self::WaitForTerminalExitResponse(_) => {
2122                return Err(removed_v1_enum_variant(
2123                    "ClientResponse",
2124                    "terminal/wait_for_exit",
2125                ));
2126            }
2127            Self::KillTerminalResponse(_) => {
2128                return Err(removed_v1_enum_variant("ClientResponse", "terminal/kill"));
2129            }
2130            #[cfg(feature = "unstable_elicitation")]
2131            Self::CreateElicitationResponse(value) => {
2132                super::ClientResponse::CreateElicitationResponse(value.into_v2()?)
2133            }
2134            #[cfg(feature = "unstable_mcp_over_acp")]
2135            Self::ConnectMcpResponse(value) => {
2136                super::ClientResponse::ConnectMcpResponse(value.into_v2()?)
2137            }
2138            #[cfg(feature = "unstable_mcp_over_acp")]
2139            Self::MessageMcpResponse(value) => {
2140                super::ClientResponse::MessageMcpResponse(value.into_v2()?)
2141            }
2142            #[cfg(feature = "unstable_mcp_over_acp")]
2143            Self::DisconnectMcpResponse(value) => {
2144                super::ClientResponse::DisconnectMcpResponse(value.into_v2()?)
2145            }
2146            Self::ExtMethodResponse(value) => {
2147                super::ClientResponse::ExtMethodResponse(value.into_v2()?)
2148            }
2149        })
2150    }
2151}
2152
2153impl IntoV1Many for super::AgentNotification {
2154    type Output = crate::v1::AgentNotification;
2155
2156    fn into_v1_many(self) -> Result<Vec<Self::Output>> {
2157        Ok(match self {
2158            Self::SessionNotification(value) => {
2159                return value
2160                    .into_v1_many()?
2161                    .into_iter()
2162                    .map(|value| Ok(crate::v1::AgentNotification::SessionNotification(value)))
2163                    .collect();
2164            }
2165            #[cfg(feature = "unstable_elicitation")]
2166            Self::CompleteElicitationNotification(value) => {
2167                vec![
2168                    crate::v1::AgentNotification::CompleteElicitationNotification(value.into_v1()?),
2169                ]
2170            }
2171            #[cfg(feature = "unstable_mcp_over_acp")]
2172            Self::MessageMcpNotification(value) => {
2173                vec![crate::v1::AgentNotification::MessageMcpNotification(
2174                    value.into_v1()?,
2175                )]
2176            }
2177            Self::ExtNotification(value) => {
2178                vec![crate::v1::AgentNotification::ExtNotification(
2179                    value.into_v1()?,
2180                )]
2181            }
2182        })
2183    }
2184}
2185
2186impl IntoV2 for crate::v1::AgentNotification {
2187    type Output = super::AgentNotification;
2188
2189    fn into_v2(self) -> Result<Self::Output> {
2190        Ok(match self {
2191            Self::SessionNotification(value) => {
2192                super::AgentNotification::SessionNotification(Box::new(value.into_v2()?))
2193            }
2194            #[cfg(feature = "unstable_elicitation")]
2195            Self::CompleteElicitationNotification(value) => {
2196                super::AgentNotification::CompleteElicitationNotification(value.into_v2()?)
2197            }
2198            #[cfg(feature = "unstable_mcp_over_acp")]
2199            Self::MessageMcpNotification(value) => {
2200                super::AgentNotification::MessageMcpNotification(value.into_v2()?)
2201            }
2202            Self::ExtNotification(value) => {
2203                super::AgentNotification::ExtNotification(value.into_v2()?)
2204            }
2205        })
2206    }
2207}
2208
2209impl IntoV1 for super::Error {
2210    type Output = crate::v1::Error;
2211
2212    fn into_v1(self) -> Result<Self::Output> {
2213        let Self {
2214            code,
2215            message,
2216            data,
2217        } = self;
2218        Ok(crate::v1::Error {
2219            code: code.into_v1()?,
2220            message: message.into_v1()?,
2221            data: data.into_v1()?,
2222        })
2223    }
2224}
2225
2226impl IntoV2 for crate::v1::Error {
2227    type Output = super::Error;
2228
2229    fn into_v2(self) -> Result<Self::Output> {
2230        let Self {
2231            code,
2232            message,
2233            data,
2234        } = self;
2235        Ok(super::Error {
2236            code: code.into_v2()?,
2237            message: message.into_v2()?,
2238            data: data.into_v2()?,
2239        })
2240    }
2241}
2242
2243impl IntoV1 for super::ErrorCode {
2244    type Output = crate::v1::ErrorCode;
2245
2246    fn into_v1(self) -> Result<Self::Output> {
2247        Ok(i32::from(self).into())
2248    }
2249}
2250
2251impl IntoV2 for crate::v1::ErrorCode {
2252    type Output = super::ErrorCode;
2253
2254    fn into_v2(self) -> Result<Self::Output> {
2255        Ok(i32::from(self).into())
2256    }
2257}
2258
2259impl IntoV1 for super::ExtRequest {
2260    type Output = crate::v1::ExtRequest;
2261
2262    fn into_v1(self) -> Result<Self::Output> {
2263        let Self { method, params } = self;
2264        Ok(crate::v1::ExtRequest {
2265            method: method.into_v1()?,
2266            params: params.into_v1()?,
2267        })
2268    }
2269}
2270
2271impl IntoV2 for crate::v1::ExtRequest {
2272    type Output = super::ExtRequest;
2273
2274    fn into_v2(self) -> Result<Self::Output> {
2275        let Self { method, params } = self;
2276        Ok(super::ExtRequest {
2277            method: method.into_v2()?,
2278            params: params.into_v2()?,
2279        })
2280    }
2281}
2282
2283impl IntoV1 for super::ExtResponse {
2284    type Output = crate::v1::ExtResponse;
2285
2286    fn into_v1(self) -> Result<Self::Output> {
2287        Ok(crate::v1::ExtResponse(self.0.into_v1()?))
2288    }
2289}
2290
2291impl IntoV2 for crate::v1::ExtResponse {
2292    type Output = super::ExtResponse;
2293
2294    fn into_v2(self) -> Result<Self::Output> {
2295        Ok(super::ExtResponse(self.0.into_v2()?))
2296    }
2297}
2298
2299impl IntoV1 for super::ExtNotification {
2300    type Output = crate::v1::ExtNotification;
2301
2302    fn into_v1(self) -> Result<Self::Output> {
2303        let Self { method, params } = self;
2304        Ok(crate::v1::ExtNotification {
2305            method: method.into_v1()?,
2306            params: params.into_v1()?,
2307        })
2308    }
2309}
2310
2311impl IntoV2 for crate::v1::ExtNotification {
2312    type Output = super::ExtNotification;
2313
2314    fn into_v2(self) -> Result<Self::Output> {
2315        let Self { method, params } = self;
2316        Ok(super::ExtNotification {
2317            method: method.into_v2()?,
2318            params: params.into_v2()?,
2319        })
2320    }
2321}
2322
2323fn maybe_undefined_value_into_v1_option<T>(value: crate::MaybeUndefined<T>) -> Option<T::Output>
2324where
2325    T: IntoV1,
2326{
2327    match value {
2328        crate::MaybeUndefined::Value(value) => value.into_v1().ok(),
2329        crate::MaybeUndefined::Null | crate::MaybeUndefined::Undefined => None,
2330    }
2331}
2332
2333fn maybe_undefined_vec_into_v1_option<T>(
2334    value: crate::MaybeUndefined<Vec<T>>,
2335) -> Option<Vec<T::Output>>
2336where
2337    T: IntoV1,
2338{
2339    match value {
2340        crate::MaybeUndefined::Value(value) => Some(into_v1_vec_skip_errors(value)),
2341        crate::MaybeUndefined::Null => Some(Vec::new()),
2342        crate::MaybeUndefined::Undefined => None,
2343    }
2344}
2345
2346fn option_into_v2_maybe_undefined<T>(value: Option<T>) -> Result<crate::MaybeUndefined<T::Output>>
2347where
2348    T: IntoV2,
2349{
2350    match value {
2351        Some(value) => Ok(crate::MaybeUndefined::Value(value.into_v2()?)),
2352        None => Ok(crate::MaybeUndefined::Undefined),
2353    }
2354}
2355
2356fn option_vec_into_v2_maybe_undefined_skip_errors<T>(
2357    value: Option<Vec<T>>,
2358) -> crate::MaybeUndefined<Vec<T::Output>>
2359where
2360    T: IntoV2,
2361{
2362    match value {
2363        Some(value) => crate::MaybeUndefined::Value(into_v2_vec_skip_errors(value)),
2364        None => crate::MaybeUndefined::Undefined,
2365    }
2366}
2367
2368fn vec_into_v2_maybe_undefined_skip_errors<T>(
2369    value: Vec<T>,
2370) -> crate::MaybeUndefined<Vec<T::Output>>
2371where
2372    T: IntoV2,
2373{
2374    if value.is_empty() {
2375        crate::MaybeUndefined::Undefined
2376    } else {
2377        crate::MaybeUndefined::Value(into_v2_vec_skip_errors(value))
2378    }
2379}
2380
2381impl IntoV1 for super::ToolCallUpdate {
2382    type Output = crate::v1::ToolCallUpdate;
2383
2384    fn into_v1(self) -> Result<Self::Output> {
2385        let Self {
2386            tool_call_id,
2387            title,
2388            kind,
2389            status,
2390            content,
2391            locations,
2392            raw_input,
2393            raw_output,
2394            meta,
2395        } = self;
2396        Ok(crate::v1::ToolCallUpdate {
2397            tool_call_id: tool_call_id.into_v1()?,
2398            fields: crate::v1::ToolCallUpdateFields {
2399                kind: maybe_undefined_value_into_v1_option(kind),
2400                status: maybe_undefined_value_into_v1_option(status),
2401                title: maybe_undefined_value_into_v1_option(title),
2402                content: maybe_undefined_vec_into_v1_option(content),
2403                locations: maybe_undefined_vec_into_v1_option(locations),
2404                raw_input: maybe_undefined_value_into_v1_option(raw_input),
2405                raw_output: maybe_undefined_value_into_v1_option(raw_output),
2406            },
2407            meta: meta.into_v1()?,
2408        })
2409    }
2410}
2411
2412impl IntoV2 for crate::v1::ToolCall {
2413    type Output = super::ToolCallUpdate;
2414
2415    fn into_v2(self) -> Result<Self::Output> {
2416        let Self {
2417            tool_call_id,
2418            title,
2419            kind,
2420            status,
2421            content,
2422            locations,
2423            raw_input,
2424            raw_output,
2425            meta,
2426        } = self;
2427        Ok(super::ToolCallUpdate {
2428            tool_call_id: tool_call_id.into_v2()?,
2429            title: crate::MaybeUndefined::Value(title.into_v2()?),
2430            kind: if matches!(kind, crate::v1::ToolKind::Other) {
2431                crate::MaybeUndefined::Undefined
2432            } else {
2433                crate::MaybeUndefined::Value(kind.into_v2()?)
2434            },
2435            status: if matches!(status, crate::v1::ToolCallStatus::Pending) {
2436                crate::MaybeUndefined::Undefined
2437            } else {
2438                crate::MaybeUndefined::Value(status.into_v2()?)
2439            },
2440            content: vec_into_v2_maybe_undefined_skip_errors(content),
2441            locations: vec_into_v2_maybe_undefined_skip_errors(locations),
2442            raw_input: option_into_v2_maybe_undefined(raw_input)?,
2443            raw_output: option_into_v2_maybe_undefined(raw_output)?,
2444            meta: meta.into_v2()?,
2445        })
2446    }
2447}
2448
2449impl IntoV2 for crate::v1::ToolCallUpdate {
2450    type Output = super::ToolCallUpdate;
2451
2452    fn into_v2(self) -> Result<Self::Output> {
2453        let Self {
2454            tool_call_id,
2455            fields,
2456            meta,
2457        } = self;
2458        let crate::v1::ToolCallUpdateFields {
2459            kind,
2460            status,
2461            title,
2462            content,
2463            locations,
2464            raw_input,
2465            raw_output,
2466        } = fields;
2467        Ok(super::ToolCallUpdate {
2468            tool_call_id: tool_call_id.into_v2()?,
2469            kind: option_into_v2_maybe_undefined(kind)?,
2470            status: option_into_v2_maybe_undefined(status)?,
2471            title: option_into_v2_maybe_undefined(title)?,
2472            content: option_vec_into_v2_maybe_undefined_skip_errors(content),
2473            locations: option_vec_into_v2_maybe_undefined_skip_errors(locations),
2474            raw_input: option_into_v2_maybe_undefined(raw_input)?,
2475            raw_output: option_into_v2_maybe_undefined(raw_output)?,
2476            meta: meta.into_v2()?,
2477        })
2478    }
2479}
2480
2481impl IntoV1 for super::ToolCallId {
2482    type Output = crate::v1::ToolCallId;
2483
2484    fn into_v1(self) -> Result<Self::Output> {
2485        Ok(crate::v1::ToolCallId(self.0.into_v1()?))
2486    }
2487}
2488
2489impl IntoV2 for crate::v1::ToolCallId {
2490    type Output = super::ToolCallId;
2491
2492    fn into_v2(self) -> Result<Self::Output> {
2493        Ok(super::ToolCallId(self.0.into_v2()?))
2494    }
2495}
2496
2497impl IntoV1 for super::ToolKind {
2498    type Output = crate::v1::ToolKind;
2499
2500    fn into_v1(self) -> Result<Self::Output> {
2501        Ok(match self {
2502            Self::Read => crate::v1::ToolKind::Read,
2503            Self::Edit => crate::v1::ToolKind::Edit,
2504            Self::Delete => crate::v1::ToolKind::Delete,
2505            Self::Move => crate::v1::ToolKind::Move,
2506            Self::Search => crate::v1::ToolKind::Search,
2507            Self::Execute => crate::v1::ToolKind::Execute,
2508            Self::Think => crate::v1::ToolKind::Think,
2509            Self::Fetch => crate::v1::ToolKind::Fetch,
2510            Self::SwitchMode => crate::v1::ToolKind::SwitchMode,
2511            Self::Other => crate::v1::ToolKind::Other,
2512            Self::Unknown(value) => return Err(unknown_v2_enum_variant("ToolKind", &value)),
2513        })
2514    }
2515}
2516
2517impl IntoV2 for crate::v1::ToolKind {
2518    type Output = super::ToolKind;
2519
2520    fn into_v2(self) -> Result<Self::Output> {
2521        Ok(match self {
2522            Self::Read => super::ToolKind::Read,
2523            Self::Edit => super::ToolKind::Edit,
2524            Self::Delete => super::ToolKind::Delete,
2525            Self::Move => super::ToolKind::Move,
2526            Self::Search => super::ToolKind::Search,
2527            Self::Execute => super::ToolKind::Execute,
2528            Self::Think => super::ToolKind::Think,
2529            Self::Fetch => super::ToolKind::Fetch,
2530            Self::SwitchMode => super::ToolKind::SwitchMode,
2531            Self::Other => super::ToolKind::Other,
2532        })
2533    }
2534}
2535
2536impl IntoV1 for super::ToolCallStatus {
2537    type Output = crate::v1::ToolCallStatus;
2538
2539    fn into_v1(self) -> Result<Self::Output> {
2540        Ok(match self {
2541            Self::Pending => crate::v1::ToolCallStatus::Pending,
2542            Self::InProgress => crate::v1::ToolCallStatus::InProgress,
2543            Self::Completed => crate::v1::ToolCallStatus::Completed,
2544            Self::Failed => crate::v1::ToolCallStatus::Failed,
2545            Self::Other(value) => return Err(unknown_v2_enum_variant("ToolCallStatus", &value)),
2546        })
2547    }
2548}
2549
2550impl IntoV2 for crate::v1::ToolCallStatus {
2551    type Output = super::ToolCallStatus;
2552
2553    fn into_v2(self) -> Result<Self::Output> {
2554        Ok(match self {
2555            Self::Pending => super::ToolCallStatus::Pending,
2556            Self::InProgress => super::ToolCallStatus::InProgress,
2557            Self::Completed => super::ToolCallStatus::Completed,
2558            Self::Failed => super::ToolCallStatus::Failed,
2559        })
2560    }
2561}
2562
2563impl IntoV1 for super::ToolCallContent {
2564    type Output = crate::v1::ToolCallContent;
2565
2566    fn into_v1(self) -> Result<Self::Output> {
2567        Ok(match self {
2568            Self::Content(value) => crate::v1::ToolCallContent::Content(value.into_v1()?),
2569            Self::Diff(value) => crate::v1::ToolCallContent::Diff(value.into_v1()?),
2570            Self::Other(value) => {
2571                return Err(unknown_v2_enum_variant("ToolCallContent", &value.type_));
2572            }
2573        })
2574    }
2575}
2576
2577impl IntoV2 for crate::v1::ToolCallContent {
2578    type Output = super::ToolCallContent;
2579
2580    fn into_v2(self) -> Result<Self::Output> {
2581        Ok(match self {
2582            Self::Content(value) => super::ToolCallContent::Content(Box::new(value.into_v2()?)),
2583            Self::Diff(value) => super::ToolCallContent::Diff(value.into_v2()?),
2584            Self::Terminal(_) => {
2585                return Err(removed_v1_enum_variant("ToolCallContent", "terminal"));
2586            }
2587        })
2588    }
2589}
2590
2591impl IntoV1 for super::Content {
2592    type Output = crate::v1::Content;
2593
2594    fn into_v1(self) -> Result<Self::Output> {
2595        let Self { content, meta } = self;
2596        Ok(crate::v1::Content {
2597            content: content.into_v1()?,
2598            meta: meta.into_v1()?,
2599        })
2600    }
2601}
2602
2603impl IntoV2 for crate::v1::Content {
2604    type Output = super::Content;
2605
2606    fn into_v2(self) -> Result<Self::Output> {
2607        let Self { content, meta } = self;
2608        Ok(super::Content {
2609            content: content.into_v2()?,
2610            meta: meta.into_v2()?,
2611        })
2612    }
2613}
2614
2615impl IntoV1 for super::Diff {
2616    type Output = crate::v1::Diff;
2617
2618    fn into_v1(self) -> Result<Self::Output> {
2619        let Self {
2620            path,
2621            old_text,
2622            new_text,
2623            meta,
2624        } = self;
2625        Ok(crate::v1::Diff {
2626            path: path.into_v1()?,
2627            old_text: old_text.into_v1()?,
2628            new_text: new_text.into_v1()?,
2629            meta: meta.into_v1()?,
2630        })
2631    }
2632}
2633
2634impl IntoV2 for crate::v1::Diff {
2635    type Output = super::Diff;
2636
2637    fn into_v2(self) -> Result<Self::Output> {
2638        let Self {
2639            path,
2640            old_text,
2641            new_text,
2642            meta,
2643        } = self;
2644        Ok(super::Diff {
2645            path: path.into_v2()?,
2646            old_text: old_text.into_v2()?,
2647            new_text: new_text.into_v2()?,
2648            meta: meta.into_v2()?,
2649        })
2650    }
2651}
2652
2653impl IntoV1 for super::ToolCallLocation {
2654    type Output = crate::v1::ToolCallLocation;
2655
2656    fn into_v1(self) -> Result<Self::Output> {
2657        let Self { path, line, meta } = self;
2658        Ok(crate::v1::ToolCallLocation {
2659            path: path.into_v1()?,
2660            line: line.into_v1()?,
2661            meta: meta.into_v1()?,
2662        })
2663    }
2664}
2665
2666impl IntoV2 for crate::v1::ToolCallLocation {
2667    type Output = super::ToolCallLocation;
2668
2669    fn into_v2(self) -> Result<Self::Output> {
2670        let Self { path, line, meta } = self;
2671        Ok(super::ToolCallLocation {
2672            path: path.into_v2()?,
2673            line: line.into_v2()?,
2674            meta: meta.into_v2()?,
2675        })
2676    }
2677}
2678
2679impl IntoV1 for super::InitializeRequest {
2680    type Output = crate::v1::InitializeRequest;
2681
2682    fn into_v1(self) -> Result<Self::Output> {
2683        let Self {
2684            protocol_version,
2685            capabilities,
2686            client_info,
2687            meta,
2688        } = self;
2689        Ok(crate::v1::InitializeRequest {
2690            protocol_version: protocol_version.into_v1()?,
2691            client_capabilities: capabilities.into_v1()?,
2692            client_info: into_v1_default_on_error(client_info),
2693            meta: meta.into_v1()?,
2694        })
2695    }
2696}
2697
2698impl IntoV2 for crate::v1::InitializeRequest {
2699    type Output = super::InitializeRequest;
2700
2701    fn into_v2(self) -> Result<Self::Output> {
2702        let Self {
2703            protocol_version,
2704            client_capabilities,
2705            client_info,
2706            meta,
2707        } = self;
2708        Ok(super::InitializeRequest {
2709            protocol_version: protocol_version.into_v2()?,
2710            capabilities: client_capabilities.into_v2()?,
2711            client_info: into_v2_default_on_error(client_info),
2712            meta: meta.into_v2()?,
2713        })
2714    }
2715}
2716
2717impl IntoV1 for super::InitializeResponse {
2718    type Output = crate::v1::InitializeResponse;
2719
2720    fn into_v1(self) -> Result<Self::Output> {
2721        let Self {
2722            protocol_version,
2723            capabilities: agent_capabilities,
2724            auth_methods,
2725            agent_info,
2726            meta,
2727        } = self;
2728        Ok(crate::v1::InitializeResponse {
2729            protocol_version: protocol_version.into_v1()?,
2730            agent_capabilities: agent_capabilities.into_v1()?,
2731            auth_methods: into_v1_vec_skip_errors(auth_methods),
2732            agent_info: into_v1_default_on_error(agent_info),
2733            meta: meta.into_v1()?,
2734        })
2735    }
2736}
2737
2738impl IntoV2 for crate::v1::InitializeResponse {
2739    type Output = super::InitializeResponse;
2740
2741    fn into_v2(self) -> Result<Self::Output> {
2742        let Self {
2743            protocol_version,
2744            agent_capabilities,
2745            auth_methods,
2746            agent_info,
2747            meta,
2748        } = self;
2749        Ok(super::InitializeResponse {
2750            protocol_version: protocol_version.into_v2()?,
2751            capabilities: agent_capabilities.into_v2()?,
2752            auth_methods: into_v2_vec_skip_errors(auth_methods),
2753            agent_info: into_v2_default_on_error(agent_info),
2754            meta: meta.into_v2()?,
2755        })
2756    }
2757}
2758
2759impl IntoV1 for super::Implementation {
2760    type Output = crate::v1::Implementation;
2761
2762    fn into_v1(self) -> Result<Self::Output> {
2763        let Self {
2764            name,
2765            title,
2766            version,
2767            meta,
2768        } = self;
2769        Ok(crate::v1::Implementation {
2770            name: name.into_v1()?,
2771            title: title.into_v1()?,
2772            version: version.into_v1()?,
2773            meta: meta.into_v1()?,
2774        })
2775    }
2776}
2777
2778impl IntoV2 for crate::v1::Implementation {
2779    type Output = super::Implementation;
2780
2781    fn into_v2(self) -> Result<Self::Output> {
2782        let Self {
2783            name,
2784            title,
2785            version,
2786            meta,
2787        } = self;
2788        Ok(super::Implementation {
2789            name: name.into_v2()?,
2790            title: title.into_v2()?,
2791            version: version.into_v2()?,
2792            meta: meta.into_v2()?,
2793        })
2794    }
2795}
2796
2797impl IntoV1 for super::AuthenticateRequest {
2798    type Output = crate::v1::AuthenticateRequest;
2799
2800    fn into_v1(self) -> Result<Self::Output> {
2801        let Self { method_id, meta } = self;
2802        Ok(crate::v1::AuthenticateRequest {
2803            method_id: method_id.into_v1()?,
2804            meta: meta.into_v1()?,
2805        })
2806    }
2807}
2808
2809impl IntoV2 for crate::v1::AuthenticateRequest {
2810    type Output = super::AuthenticateRequest;
2811
2812    fn into_v2(self) -> Result<Self::Output> {
2813        let Self { method_id, meta } = self;
2814        Ok(super::AuthenticateRequest {
2815            method_id: method_id.into_v2()?,
2816            meta: meta.into_v2()?,
2817        })
2818    }
2819}
2820
2821impl IntoV1 for super::AuthenticateResponse {
2822    type Output = crate::v1::AuthenticateResponse;
2823
2824    fn into_v1(self) -> Result<Self::Output> {
2825        let Self { meta } = self;
2826        Ok(crate::v1::AuthenticateResponse {
2827            meta: meta.into_v1()?,
2828        })
2829    }
2830}
2831
2832impl IntoV2 for crate::v1::AuthenticateResponse {
2833    type Output = super::AuthenticateResponse;
2834
2835    fn into_v2(self) -> Result<Self::Output> {
2836        let Self { meta } = self;
2837        Ok(super::AuthenticateResponse {
2838            meta: meta.into_v2()?,
2839        })
2840    }
2841}
2842
2843impl IntoV1 for super::LogoutRequest {
2844    type Output = crate::v1::LogoutRequest;
2845
2846    fn into_v1(self) -> Result<Self::Output> {
2847        let Self { meta } = self;
2848        Ok(crate::v1::LogoutRequest {
2849            meta: meta.into_v1()?,
2850        })
2851    }
2852}
2853
2854impl IntoV2 for crate::v1::LogoutRequest {
2855    type Output = super::LogoutRequest;
2856
2857    fn into_v2(self) -> Result<Self::Output> {
2858        let Self { meta } = self;
2859        Ok(super::LogoutRequest {
2860            meta: meta.into_v2()?,
2861        })
2862    }
2863}
2864
2865impl IntoV1 for super::LogoutResponse {
2866    type Output = crate::v1::LogoutResponse;
2867
2868    fn into_v1(self) -> Result<Self::Output> {
2869        let Self { meta } = self;
2870        Ok(crate::v1::LogoutResponse {
2871            meta: meta.into_v1()?,
2872        })
2873    }
2874}
2875
2876impl IntoV2 for crate::v1::LogoutResponse {
2877    type Output = super::LogoutResponse;
2878
2879    fn into_v2(self) -> Result<Self::Output> {
2880        let Self { meta } = self;
2881        Ok(super::LogoutResponse {
2882            meta: meta.into_v2()?,
2883        })
2884    }
2885}
2886
2887impl IntoV1 for super::AgentAuthCapabilities {
2888    type Output = crate::v1::AgentAuthCapabilities;
2889
2890    fn into_v1(self) -> Result<Self::Output> {
2891        let Self { logout, meta } = self;
2892        Ok(crate::v1::AgentAuthCapabilities {
2893            logout: into_v1_default_on_error(logout),
2894            meta: meta.into_v1()?,
2895        })
2896    }
2897}
2898
2899impl IntoV2 for crate::v1::AgentAuthCapabilities {
2900    type Output = super::AgentAuthCapabilities;
2901
2902    fn into_v2(self) -> Result<Self::Output> {
2903        let Self { logout, meta } = self;
2904        Ok(super::AgentAuthCapabilities {
2905            logout: into_v2_default_on_error(logout),
2906            meta: meta.into_v2()?,
2907        })
2908    }
2909}
2910
2911impl IntoV1 for super::LogoutCapabilities {
2912    type Output = crate::v1::LogoutCapabilities;
2913
2914    fn into_v1(self) -> Result<Self::Output> {
2915        let Self { meta } = self;
2916        Ok(crate::v1::LogoutCapabilities {
2917            meta: meta.into_v1()?,
2918        })
2919    }
2920}
2921
2922impl IntoV2 for crate::v1::LogoutCapabilities {
2923    type Output = super::LogoutCapabilities;
2924
2925    fn into_v2(self) -> Result<Self::Output> {
2926        let Self { meta } = self;
2927        Ok(super::LogoutCapabilities {
2928            meta: meta.into_v2()?,
2929        })
2930    }
2931}
2932
2933impl IntoV1 for super::AuthMethodId {
2934    type Output = crate::v1::AuthMethodId;
2935
2936    fn into_v1(self) -> Result<Self::Output> {
2937        Ok(crate::v1::AuthMethodId(self.0.into_v1()?))
2938    }
2939}
2940
2941impl IntoV2 for crate::v1::AuthMethodId {
2942    type Output = super::AuthMethodId;
2943
2944    fn into_v2(self) -> Result<Self::Output> {
2945        Ok(super::AuthMethodId(self.0.into_v2()?))
2946    }
2947}
2948
2949impl IntoV1 for super::AuthMethod {
2950    type Output = crate::v1::AuthMethod;
2951
2952    fn into_v1(self) -> Result<Self::Output> {
2953        Ok(match self {
2954            #[cfg(feature = "unstable_auth_methods")]
2955            Self::EnvVar(value) => crate::v1::AuthMethod::EnvVar(value.into_v1()?),
2956            #[cfg(feature = "unstable_auth_methods")]
2957            Self::Terminal(value) => crate::v1::AuthMethod::Terminal(value.into_v1()?),
2958            Self::Other(value) => {
2959                return Err(unknown_v2_enum_variant("AuthMethod", &value.type_));
2960            }
2961            Self::Agent(value) => crate::v1::AuthMethod::Agent(value.into_v1()?),
2962        })
2963    }
2964}
2965
2966impl IntoV2 for crate::v1::AuthMethod {
2967    type Output = super::AuthMethod;
2968
2969    fn into_v2(self) -> Result<Self::Output> {
2970        Ok(match self {
2971            #[cfg(feature = "unstable_auth_methods")]
2972            Self::EnvVar(value) => super::AuthMethod::EnvVar(value.into_v2()?),
2973            #[cfg(feature = "unstable_auth_methods")]
2974            Self::Terminal(value) => super::AuthMethod::Terminal(value.into_v2()?),
2975            Self::Agent(value) => super::AuthMethod::Agent(value.into_v2()?),
2976        })
2977    }
2978}
2979
2980impl IntoV1 for super::AuthMethodAgent {
2981    type Output = crate::v1::AuthMethodAgent;
2982
2983    fn into_v1(self) -> Result<Self::Output> {
2984        let Self {
2985            id,
2986            name,
2987            description,
2988            meta,
2989        } = self;
2990        Ok(crate::v1::AuthMethodAgent {
2991            id: id.into_v1()?,
2992            name: name.into_v1()?,
2993            description: description.into_v1()?,
2994            meta: meta.into_v1()?,
2995        })
2996    }
2997}
2998
2999impl IntoV2 for crate::v1::AuthMethodAgent {
3000    type Output = super::AuthMethodAgent;
3001
3002    fn into_v2(self) -> Result<Self::Output> {
3003        let Self {
3004            id,
3005            name,
3006            description,
3007            meta,
3008        } = self;
3009        Ok(super::AuthMethodAgent {
3010            id: id.into_v2()?,
3011            name: name.into_v2()?,
3012            description: description.into_v2()?,
3013            meta: meta.into_v2()?,
3014        })
3015    }
3016}
3017
3018#[cfg(feature = "unstable_auth_methods")]
3019impl IntoV1 for super::AuthMethodEnvVar {
3020    type Output = crate::v1::AuthMethodEnvVar;
3021
3022    fn into_v1(self) -> Result<Self::Output> {
3023        let Self {
3024            id,
3025            name,
3026            description,
3027            vars,
3028            link,
3029            meta,
3030        } = self;
3031        Ok(crate::v1::AuthMethodEnvVar {
3032            id: id.into_v1()?,
3033            name: name.into_v1()?,
3034            description: description.into_v1()?,
3035            vars: vars.into_v1()?,
3036            link: link.into_v1()?,
3037            meta: meta.into_v1()?,
3038        })
3039    }
3040}
3041
3042#[cfg(feature = "unstable_auth_methods")]
3043impl IntoV2 for crate::v1::AuthMethodEnvVar {
3044    type Output = super::AuthMethodEnvVar;
3045
3046    fn into_v2(self) -> Result<Self::Output> {
3047        let Self {
3048            id,
3049            name,
3050            description,
3051            vars,
3052            link,
3053            meta,
3054        } = self;
3055        Ok(super::AuthMethodEnvVar {
3056            id: id.into_v2()?,
3057            name: name.into_v2()?,
3058            description: description.into_v2()?,
3059            vars: vars.into_v2()?,
3060            link: link.into_v2()?,
3061            meta: meta.into_v2()?,
3062        })
3063    }
3064}
3065
3066#[cfg(feature = "unstable_auth_methods")]
3067impl IntoV1 for super::AuthEnvVar {
3068    type Output = crate::v1::AuthEnvVar;
3069
3070    fn into_v1(self) -> Result<Self::Output> {
3071        let Self {
3072            name,
3073            label,
3074            secret,
3075            optional,
3076            meta,
3077        } = self;
3078        Ok(crate::v1::AuthEnvVar {
3079            name: name.into_v1()?,
3080            label: label.into_v1()?,
3081            secret: secret.into_v1()?,
3082            optional: optional.into_v1()?,
3083            meta: meta.into_v1()?,
3084        })
3085    }
3086}
3087
3088#[cfg(feature = "unstable_auth_methods")]
3089impl IntoV2 for crate::v1::AuthEnvVar {
3090    type Output = super::AuthEnvVar;
3091
3092    fn into_v2(self) -> Result<Self::Output> {
3093        let Self {
3094            name,
3095            label,
3096            secret,
3097            optional,
3098            meta,
3099        } = self;
3100        Ok(super::AuthEnvVar {
3101            name: name.into_v2()?,
3102            label: label.into_v2()?,
3103            secret: secret.into_v2()?,
3104            optional: optional.into_v2()?,
3105            meta: meta.into_v2()?,
3106        })
3107    }
3108}
3109
3110#[cfg(feature = "unstable_auth_methods")]
3111impl IntoV1 for super::AuthMethodTerminal {
3112    type Output = crate::v1::AuthMethodTerminal;
3113
3114    fn into_v1(self) -> Result<Self::Output> {
3115        let Self {
3116            id,
3117            name,
3118            description,
3119            args,
3120            env,
3121            meta,
3122        } = self;
3123        Ok(crate::v1::AuthMethodTerminal {
3124            id: id.into_v1()?,
3125            name: name.into_v1()?,
3126            description: description.into_v1()?,
3127            args: args.into_v1()?,
3128            env: env.into_v1()?,
3129            meta: meta.into_v1()?,
3130        })
3131    }
3132}
3133
3134#[cfg(feature = "unstable_auth_methods")]
3135impl IntoV2 for crate::v1::AuthMethodTerminal {
3136    type Output = super::AuthMethodTerminal;
3137
3138    fn into_v2(self) -> Result<Self::Output> {
3139        let Self {
3140            id,
3141            name,
3142            description,
3143            args,
3144            env,
3145            meta,
3146        } = self;
3147        Ok(super::AuthMethodTerminal {
3148            id: id.into_v2()?,
3149            name: name.into_v2()?,
3150            description: description.into_v2()?,
3151            args: args.into_v2()?,
3152            env: env.into_v2()?,
3153            meta: meta.into_v2()?,
3154        })
3155    }
3156}
3157
3158impl IntoV1 for super::NewSessionRequest {
3159    type Output = crate::v1::NewSessionRequest;
3160
3161    fn into_v1(self) -> Result<Self::Output> {
3162        let Self {
3163            cwd,
3164            additional_directories,
3165            mcp_servers,
3166            meta,
3167        } = self;
3168        Ok(crate::v1::NewSessionRequest {
3169            cwd: cwd.into_v1()?,
3170            additional_directories: additional_directories.into_v1()?,
3171            mcp_servers: mcp_servers.into_v1()?,
3172            meta: meta.into_v1()?,
3173        })
3174    }
3175}
3176
3177impl IntoV2 for crate::v1::NewSessionRequest {
3178    type Output = super::NewSessionRequest;
3179
3180    fn into_v2(self) -> Result<Self::Output> {
3181        let Self {
3182            cwd,
3183            additional_directories,
3184            mcp_servers,
3185            meta,
3186        } = self;
3187        Ok(super::NewSessionRequest {
3188            cwd: cwd.into_v2()?,
3189            additional_directories: additional_directories.into_v2()?,
3190            mcp_servers: mcp_servers.into_v2()?,
3191            meta: meta.into_v2()?,
3192        })
3193    }
3194}
3195
3196impl IntoV1 for super::NewSessionResponse {
3197    type Output = crate::v1::NewSessionResponse;
3198
3199    fn into_v1(self) -> Result<Self::Output> {
3200        let Self {
3201            session_id,
3202            config_options,
3203            meta,
3204        } = self;
3205        Ok(crate::v1::NewSessionResponse {
3206            session_id: session_id.into_v1()?,
3207            modes: None,
3208            config_options: option_vec_into_v1_skip_errors(config_options),
3209            meta: meta.into_v1()?,
3210        })
3211    }
3212}
3213
3214impl IntoV2 for crate::v1::NewSessionResponse {
3215    type Output = super::NewSessionResponse;
3216
3217    fn into_v2(self) -> Result<Self::Output> {
3218        let Self {
3219            session_id,
3220            modes: _,
3221            config_options,
3222            meta,
3223        } = self;
3224        Ok(super::NewSessionResponse {
3225            session_id: session_id.into_v2()?,
3226            config_options: option_vec_into_v2_skip_errors(config_options),
3227            meta: meta.into_v2()?,
3228        })
3229    }
3230}
3231
3232impl IntoV1 for super::LoadSessionRequest {
3233    type Output = crate::v1::LoadSessionRequest;
3234
3235    fn into_v1(self) -> Result<Self::Output> {
3236        let Self {
3237            mcp_servers,
3238            cwd,
3239            additional_directories,
3240            session_id,
3241            meta,
3242        } = self;
3243        Ok(crate::v1::LoadSessionRequest {
3244            mcp_servers: mcp_servers.into_v1()?,
3245            cwd: cwd.into_v1()?,
3246            additional_directories: additional_directories.into_v1()?,
3247            session_id: session_id.into_v1()?,
3248            meta: meta.into_v1()?,
3249        })
3250    }
3251}
3252
3253impl IntoV2 for crate::v1::LoadSessionRequest {
3254    type Output = super::LoadSessionRequest;
3255
3256    fn into_v2(self) -> Result<Self::Output> {
3257        let Self {
3258            mcp_servers,
3259            cwd,
3260            additional_directories,
3261            session_id,
3262            meta,
3263        } = self;
3264        Ok(super::LoadSessionRequest {
3265            mcp_servers: mcp_servers.into_v2()?,
3266            cwd: cwd.into_v2()?,
3267            additional_directories: additional_directories.into_v2()?,
3268            session_id: session_id.into_v2()?,
3269            meta: meta.into_v2()?,
3270        })
3271    }
3272}
3273
3274impl IntoV1 for super::LoadSessionResponse {
3275    type Output = crate::v1::LoadSessionResponse;
3276
3277    fn into_v1(self) -> Result<Self::Output> {
3278        let Self {
3279            config_options,
3280            meta,
3281        } = self;
3282        Ok(crate::v1::LoadSessionResponse {
3283            modes: None,
3284            config_options: option_vec_into_v1_skip_errors(config_options),
3285            meta: meta.into_v1()?,
3286        })
3287    }
3288}
3289
3290impl IntoV2 for crate::v1::LoadSessionResponse {
3291    type Output = super::LoadSessionResponse;
3292
3293    fn into_v2(self) -> Result<Self::Output> {
3294        let Self {
3295            modes: _,
3296            config_options,
3297            meta,
3298        } = self;
3299        Ok(super::LoadSessionResponse {
3300            config_options: option_vec_into_v2_skip_errors(config_options),
3301            meta: meta.into_v2()?,
3302        })
3303    }
3304}
3305
3306#[cfg(feature = "unstable_session_fork")]
3307impl IntoV1 for super::ForkSessionRequest {
3308    type Output = crate::v1::ForkSessionRequest;
3309
3310    fn into_v1(self) -> Result<Self::Output> {
3311        let Self {
3312            session_id,
3313            cwd,
3314            additional_directories,
3315            mcp_servers,
3316            meta,
3317        } = self;
3318        Ok(crate::v1::ForkSessionRequest {
3319            session_id: session_id.into_v1()?,
3320            cwd: cwd.into_v1()?,
3321            additional_directories: additional_directories.into_v1()?,
3322            mcp_servers: mcp_servers.into_v1()?,
3323            meta: meta.into_v1()?,
3324        })
3325    }
3326}
3327
3328#[cfg(feature = "unstable_session_fork")]
3329impl IntoV2 for crate::v1::ForkSessionRequest {
3330    type Output = super::ForkSessionRequest;
3331
3332    fn into_v2(self) -> Result<Self::Output> {
3333        let Self {
3334            session_id,
3335            cwd,
3336            additional_directories,
3337            mcp_servers,
3338            meta,
3339        } = self;
3340        Ok(super::ForkSessionRequest {
3341            session_id: session_id.into_v2()?,
3342            cwd: cwd.into_v2()?,
3343            additional_directories: additional_directories.into_v2()?,
3344            mcp_servers: mcp_servers.into_v2()?,
3345            meta: meta.into_v2()?,
3346        })
3347    }
3348}
3349
3350#[cfg(feature = "unstable_session_fork")]
3351impl IntoV1 for super::ForkSessionResponse {
3352    type Output = crate::v1::ForkSessionResponse;
3353
3354    fn into_v1(self) -> Result<Self::Output> {
3355        let Self {
3356            session_id,
3357            config_options,
3358            meta,
3359        } = self;
3360        Ok(crate::v1::ForkSessionResponse {
3361            session_id: session_id.into_v1()?,
3362            modes: None,
3363            config_options: option_vec_into_v1_skip_errors(config_options),
3364            meta: meta.into_v1()?,
3365        })
3366    }
3367}
3368
3369#[cfg(feature = "unstable_session_fork")]
3370impl IntoV2 for crate::v1::ForkSessionResponse {
3371    type Output = super::ForkSessionResponse;
3372
3373    fn into_v2(self) -> Result<Self::Output> {
3374        let Self {
3375            session_id,
3376            modes: _,
3377            config_options,
3378            meta,
3379        } = self;
3380        Ok(super::ForkSessionResponse {
3381            session_id: session_id.into_v2()?,
3382            config_options: option_vec_into_v2_skip_errors(config_options),
3383            meta: meta.into_v2()?,
3384        })
3385    }
3386}
3387
3388impl IntoV1 for super::ResumeSessionRequest {
3389    type Output = crate::v1::ResumeSessionRequest;
3390
3391    fn into_v1(self) -> Result<Self::Output> {
3392        let Self {
3393            session_id,
3394            cwd,
3395            additional_directories,
3396            mcp_servers,
3397            meta,
3398        } = self;
3399        Ok(crate::v1::ResumeSessionRequest {
3400            session_id: session_id.into_v1()?,
3401            cwd: cwd.into_v1()?,
3402            additional_directories: additional_directories.into_v1()?,
3403            mcp_servers: mcp_servers.into_v1()?,
3404            meta: meta.into_v1()?,
3405        })
3406    }
3407}
3408
3409impl IntoV2 for crate::v1::ResumeSessionRequest {
3410    type Output = super::ResumeSessionRequest;
3411
3412    fn into_v2(self) -> Result<Self::Output> {
3413        let Self {
3414            session_id,
3415            cwd,
3416            additional_directories,
3417            mcp_servers,
3418            meta,
3419        } = self;
3420        Ok(super::ResumeSessionRequest {
3421            session_id: session_id.into_v2()?,
3422            cwd: cwd.into_v2()?,
3423            additional_directories: additional_directories.into_v2()?,
3424            mcp_servers: mcp_servers.into_v2()?,
3425            meta: meta.into_v2()?,
3426        })
3427    }
3428}
3429
3430impl IntoV1 for super::ResumeSessionResponse {
3431    type Output = crate::v1::ResumeSessionResponse;
3432
3433    fn into_v1(self) -> Result<Self::Output> {
3434        let Self {
3435            config_options,
3436            meta,
3437        } = self;
3438        Ok(crate::v1::ResumeSessionResponse {
3439            modes: None,
3440            config_options: option_vec_into_v1_skip_errors(config_options),
3441            meta: meta.into_v1()?,
3442        })
3443    }
3444}
3445
3446impl IntoV2 for crate::v1::ResumeSessionResponse {
3447    type Output = super::ResumeSessionResponse;
3448
3449    fn into_v2(self) -> Result<Self::Output> {
3450        let Self {
3451            modes: _,
3452            config_options,
3453            meta,
3454        } = self;
3455        Ok(super::ResumeSessionResponse {
3456            config_options: option_vec_into_v2_skip_errors(config_options),
3457            meta: meta.into_v2()?,
3458        })
3459    }
3460}
3461
3462impl IntoV1 for super::CloseSessionRequest {
3463    type Output = crate::v1::CloseSessionRequest;
3464
3465    fn into_v1(self) -> Result<Self::Output> {
3466        let Self { session_id, meta } = self;
3467        Ok(crate::v1::CloseSessionRequest {
3468            session_id: session_id.into_v1()?,
3469            meta: meta.into_v1()?,
3470        })
3471    }
3472}
3473
3474impl IntoV2 for crate::v1::CloseSessionRequest {
3475    type Output = super::CloseSessionRequest;
3476
3477    fn into_v2(self) -> Result<Self::Output> {
3478        let Self { session_id, meta } = self;
3479        Ok(super::CloseSessionRequest {
3480            session_id: session_id.into_v2()?,
3481            meta: meta.into_v2()?,
3482        })
3483    }
3484}
3485
3486impl IntoV1 for super::CloseSessionResponse {
3487    type Output = crate::v1::CloseSessionResponse;
3488
3489    fn into_v1(self) -> Result<Self::Output> {
3490        let Self { meta } = self;
3491        Ok(crate::v1::CloseSessionResponse {
3492            meta: meta.into_v1()?,
3493        })
3494    }
3495}
3496
3497impl IntoV2 for crate::v1::CloseSessionResponse {
3498    type Output = super::CloseSessionResponse;
3499
3500    fn into_v2(self) -> Result<Self::Output> {
3501        let Self { meta } = self;
3502        Ok(super::CloseSessionResponse {
3503            meta: meta.into_v2()?,
3504        })
3505    }
3506}
3507
3508impl IntoV1 for super::DeleteSessionRequest {
3509    type Output = crate::v1::DeleteSessionRequest;
3510
3511    fn into_v1(self) -> Result<Self::Output> {
3512        let Self { session_id, meta } = self;
3513        Ok(crate::v1::DeleteSessionRequest {
3514            session_id: session_id.into_v1()?,
3515            meta: meta.into_v1()?,
3516        })
3517    }
3518}
3519
3520impl IntoV2 for crate::v1::DeleteSessionRequest {
3521    type Output = super::DeleteSessionRequest;
3522
3523    fn into_v2(self) -> Result<Self::Output> {
3524        let Self { session_id, meta } = self;
3525        Ok(super::DeleteSessionRequest {
3526            session_id: session_id.into_v2()?,
3527            meta: meta.into_v2()?,
3528        })
3529    }
3530}
3531
3532impl IntoV1 for super::DeleteSessionResponse {
3533    type Output = crate::v1::DeleteSessionResponse;
3534
3535    fn into_v1(self) -> Result<Self::Output> {
3536        let Self { meta } = self;
3537        Ok(crate::v1::DeleteSessionResponse {
3538            meta: meta.into_v1()?,
3539        })
3540    }
3541}
3542
3543impl IntoV2 for crate::v1::DeleteSessionResponse {
3544    type Output = super::DeleteSessionResponse;
3545
3546    fn into_v2(self) -> Result<Self::Output> {
3547        let Self { meta } = self;
3548        Ok(super::DeleteSessionResponse {
3549            meta: meta.into_v2()?,
3550        })
3551    }
3552}
3553
3554impl IntoV1 for super::ListSessionsRequest {
3555    type Output = crate::v1::ListSessionsRequest;
3556
3557    fn into_v1(self) -> Result<Self::Output> {
3558        let Self { cwd, cursor, meta } = self;
3559        Ok(crate::v1::ListSessionsRequest {
3560            cwd: cwd.into_v1()?,
3561            cursor: cursor.into_v1()?,
3562            meta: meta.into_v1()?,
3563        })
3564    }
3565}
3566
3567impl IntoV2 for crate::v1::ListSessionsRequest {
3568    type Output = super::ListSessionsRequest;
3569
3570    fn into_v2(self) -> Result<Self::Output> {
3571        let Self { cwd, cursor, meta } = self;
3572        Ok(super::ListSessionsRequest {
3573            cwd: cwd.into_v2()?,
3574            cursor: cursor.into_v2()?,
3575            meta: meta.into_v2()?,
3576        })
3577    }
3578}
3579
3580impl IntoV1 for super::ListSessionsResponse {
3581    type Output = crate::v1::ListSessionsResponse;
3582
3583    fn into_v1(self) -> Result<Self::Output> {
3584        let Self {
3585            sessions,
3586            next_cursor,
3587            meta,
3588        } = self;
3589        Ok(crate::v1::ListSessionsResponse {
3590            sessions: into_v1_vec_skip_errors(sessions),
3591            next_cursor: next_cursor.into_v1()?,
3592            meta: meta.into_v1()?,
3593        })
3594    }
3595}
3596
3597impl IntoV2 for crate::v1::ListSessionsResponse {
3598    type Output = super::ListSessionsResponse;
3599
3600    fn into_v2(self) -> Result<Self::Output> {
3601        let Self {
3602            sessions,
3603            next_cursor,
3604            meta,
3605        } = self;
3606        Ok(super::ListSessionsResponse {
3607            sessions: into_v2_vec_skip_errors(sessions),
3608            next_cursor: next_cursor.into_v2()?,
3609            meta: meta.into_v2()?,
3610        })
3611    }
3612}
3613
3614impl IntoV1 for super::SessionInfo {
3615    type Output = crate::v1::SessionInfo;
3616
3617    fn into_v1(self) -> Result<Self::Output> {
3618        let Self {
3619            session_id,
3620            cwd,
3621            additional_directories,
3622            title,
3623            updated_at,
3624            meta,
3625        } = self;
3626        Ok(crate::v1::SessionInfo {
3627            session_id: session_id.into_v1()?,
3628            cwd: cwd.into_v1()?,
3629            additional_directories: additional_directories.into_v1()?,
3630            title: into_v1_default_on_error(title),
3631            updated_at: into_v1_default_on_error(updated_at),
3632            meta: meta.into_v1()?,
3633        })
3634    }
3635}
3636
3637impl IntoV2 for crate::v1::SessionInfo {
3638    type Output = super::SessionInfo;
3639
3640    fn into_v2(self) -> Result<Self::Output> {
3641        let Self {
3642            session_id,
3643            cwd,
3644            additional_directories,
3645            title,
3646            updated_at,
3647            meta,
3648        } = self;
3649        Ok(super::SessionInfo {
3650            session_id: session_id.into_v2()?,
3651            cwd: cwd.into_v2()?,
3652            additional_directories: additional_directories.into_v2()?,
3653            title: into_v2_default_on_error(title),
3654            updated_at: into_v2_default_on_error(updated_at),
3655            meta: meta.into_v2()?,
3656        })
3657    }
3658}
3659
3660impl IntoV1 for super::SessionConfigId {
3661    type Output = crate::v1::SessionConfigId;
3662
3663    fn into_v1(self) -> Result<Self::Output> {
3664        Ok(crate::v1::SessionConfigId(self.0.into_v1()?))
3665    }
3666}
3667
3668impl IntoV2 for crate::v1::SessionConfigId {
3669    type Output = super::SessionConfigId;
3670
3671    fn into_v2(self) -> Result<Self::Output> {
3672        Ok(super::SessionConfigId(self.0.into_v2()?))
3673    }
3674}
3675
3676impl IntoV1 for super::SessionConfigValueId {
3677    type Output = crate::v1::SessionConfigValueId;
3678
3679    fn into_v1(self) -> Result<Self::Output> {
3680        Ok(crate::v1::SessionConfigValueId(self.0.into_v1()?))
3681    }
3682}
3683
3684impl IntoV2 for crate::v1::SessionConfigValueId {
3685    type Output = super::SessionConfigValueId;
3686
3687    fn into_v2(self) -> Result<Self::Output> {
3688        Ok(super::SessionConfigValueId(self.0.into_v2()?))
3689    }
3690}
3691
3692impl IntoV1 for super::SessionConfigGroupId {
3693    type Output = crate::v1::SessionConfigGroupId;
3694
3695    fn into_v1(self) -> Result<Self::Output> {
3696        Ok(crate::v1::SessionConfigGroupId(self.0.into_v1()?))
3697    }
3698}
3699
3700impl IntoV2 for crate::v1::SessionConfigGroupId {
3701    type Output = super::SessionConfigGroupId;
3702
3703    fn into_v2(self) -> Result<Self::Output> {
3704        Ok(super::SessionConfigGroupId(self.0.into_v2()?))
3705    }
3706}
3707
3708impl IntoV1 for super::SessionConfigSelectOption {
3709    type Output = crate::v1::SessionConfigSelectOption;
3710
3711    fn into_v1(self) -> Result<Self::Output> {
3712        let Self {
3713            value,
3714            name,
3715            description,
3716            meta,
3717        } = self;
3718        Ok(crate::v1::SessionConfigSelectOption {
3719            value: value.into_v1()?,
3720            name: name.into_v1()?,
3721            description: description.into_v1()?,
3722            meta: meta.into_v1()?,
3723        })
3724    }
3725}
3726
3727impl IntoV2 for crate::v1::SessionConfigSelectOption {
3728    type Output = super::SessionConfigSelectOption;
3729
3730    fn into_v2(self) -> Result<Self::Output> {
3731        let Self {
3732            value,
3733            name,
3734            description,
3735            meta,
3736        } = self;
3737        Ok(super::SessionConfigSelectOption {
3738            value: value.into_v2()?,
3739            name: name.into_v2()?,
3740            description: description.into_v2()?,
3741            meta: meta.into_v2()?,
3742        })
3743    }
3744}
3745
3746impl IntoV1 for super::SessionConfigSelectGroup {
3747    type Output = crate::v1::SessionConfigSelectGroup;
3748
3749    fn into_v1(self) -> Result<Self::Output> {
3750        let Self {
3751            group,
3752            name,
3753            options,
3754            meta,
3755        } = self;
3756        Ok(crate::v1::SessionConfigSelectGroup {
3757            group: group.into_v1()?,
3758            name: name.into_v1()?,
3759            options: options.into_v1()?,
3760            meta: meta.into_v1()?,
3761        })
3762    }
3763}
3764
3765impl IntoV2 for crate::v1::SessionConfigSelectGroup {
3766    type Output = super::SessionConfigSelectGroup;
3767
3768    fn into_v2(self) -> Result<Self::Output> {
3769        let Self {
3770            group,
3771            name,
3772            options,
3773            meta,
3774        } = self;
3775        Ok(super::SessionConfigSelectGroup {
3776            group: group.into_v2()?,
3777            name: name.into_v2()?,
3778            options: options.into_v2()?,
3779            meta: meta.into_v2()?,
3780        })
3781    }
3782}
3783
3784impl IntoV1 for super::SessionConfigSelectOptions {
3785    type Output = crate::v1::SessionConfigSelectOptions;
3786
3787    fn into_v1(self) -> Result<Self::Output> {
3788        Ok(match self {
3789            Self::Ungrouped(value) => {
3790                crate::v1::SessionConfigSelectOptions::Ungrouped(value.into_v1()?)
3791            }
3792            Self::Grouped(value) => {
3793                crate::v1::SessionConfigSelectOptions::Grouped(value.into_v1()?)
3794            }
3795        })
3796    }
3797}
3798
3799impl IntoV2 for crate::v1::SessionConfigSelectOptions {
3800    type Output = super::SessionConfigSelectOptions;
3801
3802    fn into_v2(self) -> Result<Self::Output> {
3803        Ok(match self {
3804            Self::Ungrouped(value) => {
3805                super::SessionConfigSelectOptions::Ungrouped(value.into_v2()?)
3806            }
3807            Self::Grouped(value) => super::SessionConfigSelectOptions::Grouped(value.into_v2()?),
3808        })
3809    }
3810}
3811
3812impl IntoV1 for super::SessionConfigSelect {
3813    type Output = crate::v1::SessionConfigSelect;
3814
3815    fn into_v1(self) -> Result<Self::Output> {
3816        let Self {
3817            current_value,
3818            options,
3819        } = self;
3820        Ok(crate::v1::SessionConfigSelect {
3821            current_value: current_value.into_v1()?,
3822            options: options.into_v1()?,
3823        })
3824    }
3825}
3826
3827impl IntoV2 for crate::v1::SessionConfigSelect {
3828    type Output = super::SessionConfigSelect;
3829
3830    fn into_v2(self) -> Result<Self::Output> {
3831        let Self {
3832            current_value,
3833            options,
3834        } = self;
3835        Ok(super::SessionConfigSelect {
3836            current_value: current_value.into_v2()?,
3837            options: options.into_v2()?,
3838        })
3839    }
3840}
3841
3842#[cfg(feature = "unstable_boolean_config")]
3843impl IntoV1 for super::SessionConfigBoolean {
3844    type Output = crate::v1::SessionConfigBoolean;
3845
3846    fn into_v1(self) -> Result<Self::Output> {
3847        let Self { current_value } = self;
3848        Ok(crate::v1::SessionConfigBoolean {
3849            current_value: current_value.into_v1()?,
3850        })
3851    }
3852}
3853
3854#[cfg(feature = "unstable_boolean_config")]
3855impl IntoV2 for crate::v1::SessionConfigBoolean {
3856    type Output = super::SessionConfigBoolean;
3857
3858    fn into_v2(self) -> Result<Self::Output> {
3859        let Self { current_value } = self;
3860        Ok(super::SessionConfigBoolean {
3861            current_value: current_value.into_v2()?,
3862        })
3863    }
3864}
3865
3866impl IntoV1 for super::SessionConfigOptionCategory {
3867    type Output = crate::v1::SessionConfigOptionCategory;
3868
3869    fn into_v1(self) -> Result<Self::Output> {
3870        Ok(match self {
3871            Self::Mode => crate::v1::SessionConfigOptionCategory::Mode,
3872            Self::Model => crate::v1::SessionConfigOptionCategory::Model,
3873            Self::ThoughtLevel => crate::v1::SessionConfigOptionCategory::ThoughtLevel,
3874            Self::Other(value) => crate::v1::SessionConfigOptionCategory::Other(value.into_v1()?),
3875        })
3876    }
3877}
3878
3879impl IntoV2 for crate::v1::SessionConfigOptionCategory {
3880    type Output = super::SessionConfigOptionCategory;
3881
3882    fn into_v2(self) -> Result<Self::Output> {
3883        Ok(match self {
3884            Self::Mode => super::SessionConfigOptionCategory::Mode,
3885            Self::Model => super::SessionConfigOptionCategory::Model,
3886            Self::ThoughtLevel => super::SessionConfigOptionCategory::ThoughtLevel,
3887            Self::Other(value) => super::SessionConfigOptionCategory::Other(value.into_v2()?),
3888        })
3889    }
3890}
3891
3892impl IntoV1 for super::SessionConfigKind {
3893    type Output = crate::v1::SessionConfigKind;
3894
3895    fn into_v1(self) -> Result<Self::Output> {
3896        Ok(match self {
3897            Self::Select(value) => crate::v1::SessionConfigKind::Select(value.into_v1()?),
3898            #[cfg(feature = "unstable_boolean_config")]
3899            Self::Boolean(value) => crate::v1::SessionConfigKind::Boolean(value.into_v1()?),
3900            Self::Other(value) => {
3901                return Err(unknown_v2_enum_variant("SessionConfigKind", &value.type_));
3902            }
3903        })
3904    }
3905}
3906
3907impl IntoV2 for crate::v1::SessionConfigKind {
3908    type Output = super::SessionConfigKind;
3909
3910    fn into_v2(self) -> Result<Self::Output> {
3911        Ok(match self {
3912            Self::Select(value) => super::SessionConfigKind::Select(value.into_v2()?),
3913            #[cfg(feature = "unstable_boolean_config")]
3914            Self::Boolean(value) => super::SessionConfigKind::Boolean(value.into_v2()?),
3915        })
3916    }
3917}
3918
3919impl IntoV1 for super::SessionConfigOption {
3920    type Output = crate::v1::SessionConfigOption;
3921
3922    fn into_v1(self) -> Result<Self::Output> {
3923        let Self {
3924            id,
3925            name,
3926            description,
3927            category,
3928            kind,
3929            meta,
3930        } = self;
3931        Ok(crate::v1::SessionConfigOption {
3932            id: id.into_v1()?,
3933            name: name.into_v1()?,
3934            description: description.into_v1()?,
3935            category: into_v1_default_on_error(category),
3936            kind: kind.into_v1()?,
3937            meta: meta.into_v1()?,
3938        })
3939    }
3940}
3941
3942impl IntoV2 for crate::v1::SessionConfigOption {
3943    type Output = super::SessionConfigOption;
3944
3945    fn into_v2(self) -> Result<Self::Output> {
3946        let Self {
3947            id,
3948            name,
3949            description,
3950            category,
3951            kind,
3952            meta,
3953        } = self;
3954        Ok(super::SessionConfigOption {
3955            id: id.into_v2()?,
3956            name: name.into_v2()?,
3957            description: description.into_v2()?,
3958            category: into_v2_default_on_error(category),
3959            kind: kind.into_v2()?,
3960            meta: meta.into_v2()?,
3961        })
3962    }
3963}
3964
3965#[cfg(feature = "unstable_boolean_config")]
3966impl IntoV1 for super::SessionConfigOptionValue {
3967    type Output = crate::v1::SessionConfigOptionValue;
3968
3969    fn into_v1(self) -> Result<Self::Output> {
3970        Ok(match self {
3971            Self::Boolean { value } => crate::v1::SessionConfigOptionValue::Boolean {
3972                value: value.into_v1()?,
3973            },
3974            Self::ValueId { value } => crate::v1::SessionConfigOptionValue::ValueId {
3975                value: value.into_v1()?,
3976            },
3977        })
3978    }
3979}
3980
3981#[cfg(feature = "unstable_boolean_config")]
3982impl IntoV2 for crate::v1::SessionConfigOptionValue {
3983    type Output = super::SessionConfigOptionValue;
3984
3985    fn into_v2(self) -> Result<Self::Output> {
3986        Ok(match self {
3987            Self::Boolean { value } => super::SessionConfigOptionValue::Boolean {
3988                value: value.into_v2()?,
3989            },
3990            Self::ValueId { value } => super::SessionConfigOptionValue::ValueId {
3991                value: value.into_v2()?,
3992            },
3993        })
3994    }
3995}
3996
3997impl IntoV1 for super::SetSessionConfigOptionRequest {
3998    type Output = crate::v1::SetSessionConfigOptionRequest;
3999
4000    fn into_v1(self) -> Result<Self::Output> {
4001        let Self {
4002            session_id,
4003            config_id,
4004            value,
4005            meta,
4006        } = self;
4007        Ok(crate::v1::SetSessionConfigOptionRequest {
4008            session_id: session_id.into_v1()?,
4009            config_id: config_id.into_v1()?,
4010            value: value.into_v1()?,
4011            meta: meta.into_v1()?,
4012        })
4013    }
4014}
4015
4016impl IntoV2 for crate::v1::SetSessionConfigOptionRequest {
4017    type Output = super::SetSessionConfigOptionRequest;
4018
4019    fn into_v2(self) -> Result<Self::Output> {
4020        let Self {
4021            session_id,
4022            config_id,
4023            value,
4024            meta,
4025        } = self;
4026        Ok(super::SetSessionConfigOptionRequest {
4027            session_id: session_id.into_v2()?,
4028            config_id: config_id.into_v2()?,
4029            value: value.into_v2()?,
4030            meta: meta.into_v2()?,
4031        })
4032    }
4033}
4034
4035impl IntoV1 for super::SetSessionConfigOptionResponse {
4036    type Output = crate::v1::SetSessionConfigOptionResponse;
4037
4038    fn into_v1(self) -> Result<Self::Output> {
4039        let Self {
4040            config_options,
4041            meta,
4042        } = self;
4043        Ok(crate::v1::SetSessionConfigOptionResponse {
4044            config_options: into_v1_vec_skip_errors(config_options),
4045            meta: meta.into_v1()?,
4046        })
4047    }
4048}
4049
4050impl IntoV2 for crate::v1::SetSessionConfigOptionResponse {
4051    type Output = super::SetSessionConfigOptionResponse;
4052
4053    fn into_v2(self) -> Result<Self::Output> {
4054        let Self {
4055            config_options,
4056            meta,
4057        } = self;
4058        Ok(super::SetSessionConfigOptionResponse {
4059            config_options: into_v2_vec_skip_errors(config_options),
4060            meta: meta.into_v2()?,
4061        })
4062    }
4063}
4064
4065impl IntoV1 for super::McpServer {
4066    type Output = crate::v1::McpServer;
4067
4068    fn into_v1(self) -> Result<Self::Output> {
4069        Ok(match self {
4070            Self::Http(value) => crate::v1::McpServer::Http(value.into_v1()?),
4071            #[cfg(feature = "unstable_mcp_over_acp")]
4072            Self::Acp(value) => crate::v1::McpServer::Acp(value.into_v1()?),
4073            Self::Stdio(value) => crate::v1::McpServer::Stdio(value.into_v1()?),
4074            Self::Other(value) => return Err(unknown_v2_enum_variant("McpServer", &value.type_)),
4075        })
4076    }
4077}
4078
4079impl IntoV2 for crate::v1::McpServer {
4080    type Output = super::McpServer;
4081
4082    fn into_v2(self) -> Result<Self::Output> {
4083        Ok(match self {
4084            Self::Http(value) => super::McpServer::Http(value.into_v2()?),
4085            Self::Sse(_) => return Err(removed_v1_enum_variant("McpServer", "sse")),
4086            #[cfg(feature = "unstable_mcp_over_acp")]
4087            Self::Acp(value) => super::McpServer::Acp(value.into_v2()?),
4088            Self::Stdio(value) => super::McpServer::Stdio(value.into_v2()?),
4089        })
4090    }
4091}
4092
4093impl IntoV1 for super::McpServerHttp {
4094    type Output = crate::v1::McpServerHttp;
4095
4096    fn into_v1(self) -> Result<Self::Output> {
4097        let Self {
4098            name,
4099            url,
4100            headers,
4101            meta,
4102        } = self;
4103        Ok(crate::v1::McpServerHttp {
4104            name: name.into_v1()?,
4105            url: url.into_v1()?,
4106            headers: headers.into_v1()?,
4107            meta: meta.into_v1()?,
4108        })
4109    }
4110}
4111
4112impl IntoV2 for crate::v1::McpServerHttp {
4113    type Output = super::McpServerHttp;
4114
4115    fn into_v2(self) -> Result<Self::Output> {
4116        let Self {
4117            name,
4118            url,
4119            headers,
4120            meta,
4121        } = self;
4122        Ok(super::McpServerHttp {
4123            name: name.into_v2()?,
4124            url: url.into_v2()?,
4125            headers: headers.into_v2()?,
4126            meta: meta.into_v2()?,
4127        })
4128    }
4129}
4130
4131#[cfg(feature = "unstable_mcp_over_acp")]
4132impl IntoV1 for super::McpServerAcpId {
4133    type Output = crate::v1::McpServerAcpId;
4134
4135    fn into_v1(self) -> Result<Self::Output> {
4136        Ok(crate::v1::McpServerAcpId(self.0.into_v1()?))
4137    }
4138}
4139
4140#[cfg(feature = "unstable_mcp_over_acp")]
4141impl IntoV2 for crate::v1::McpServerAcpId {
4142    type Output = super::McpServerAcpId;
4143
4144    fn into_v2(self) -> Result<Self::Output> {
4145        Ok(super::McpServerAcpId(self.0.into_v2()?))
4146    }
4147}
4148
4149#[cfg(feature = "unstable_mcp_over_acp")]
4150impl IntoV1 for super::McpConnectionId {
4151    type Output = crate::v1::McpConnectionId;
4152
4153    fn into_v1(self) -> Result<Self::Output> {
4154        Ok(crate::v1::McpConnectionId(self.0.into_v1()?))
4155    }
4156}
4157
4158#[cfg(feature = "unstable_mcp_over_acp")]
4159impl IntoV2 for crate::v1::McpConnectionId {
4160    type Output = super::McpConnectionId;
4161
4162    fn into_v2(self) -> Result<Self::Output> {
4163        Ok(super::McpConnectionId(self.0.into_v2()?))
4164    }
4165}
4166
4167#[cfg(feature = "unstable_mcp_over_acp")]
4168impl IntoV1 for super::McpServerAcp {
4169    type Output = crate::v1::McpServerAcp;
4170
4171    fn into_v1(self) -> Result<Self::Output> {
4172        let Self { name, id, meta } = self;
4173        Ok(crate::v1::McpServerAcp {
4174            name: name.into_v1()?,
4175            id: id.into_v1()?,
4176            meta: meta.into_v1()?,
4177        })
4178    }
4179}
4180
4181#[cfg(feature = "unstable_mcp_over_acp")]
4182impl IntoV2 for crate::v1::McpServerAcp {
4183    type Output = super::McpServerAcp;
4184
4185    fn into_v2(self) -> Result<Self::Output> {
4186        let Self { name, id, meta } = self;
4187        Ok(super::McpServerAcp {
4188            name: name.into_v2()?,
4189            id: id.into_v2()?,
4190            meta: meta.into_v2()?,
4191        })
4192    }
4193}
4194
4195impl IntoV1 for super::McpServerStdio {
4196    type Output = crate::v1::McpServerStdio;
4197
4198    fn into_v1(self) -> Result<Self::Output> {
4199        let Self {
4200            name,
4201            command,
4202            args,
4203            env,
4204            meta,
4205        } = self;
4206        Ok(crate::v1::McpServerStdio {
4207            name: name.into_v1()?,
4208            command: command.into_v1()?,
4209            args: args.into_v1()?,
4210            env: env.into_v1()?,
4211            meta: meta.into_v1()?,
4212        })
4213    }
4214}
4215
4216impl IntoV2 for crate::v1::McpServerStdio {
4217    type Output = super::McpServerStdio;
4218
4219    fn into_v2(self) -> Result<Self::Output> {
4220        let Self {
4221            name,
4222            command,
4223            args,
4224            env,
4225            meta,
4226        } = self;
4227        Ok(super::McpServerStdio {
4228            name: name.into_v2()?,
4229            command: command.into_v2()?,
4230            args: args.into_v2()?,
4231            env: env.into_v2()?,
4232            meta: meta.into_v2()?,
4233        })
4234    }
4235}
4236
4237impl IntoV1 for super::EnvVariable {
4238    type Output = crate::v1::EnvVariable;
4239
4240    fn into_v1(self) -> Result<Self::Output> {
4241        let Self { name, value, meta } = self;
4242        Ok(crate::v1::EnvVariable {
4243            name: name.into_v1()?,
4244            value: value.into_v1()?,
4245            meta: meta.into_v1()?,
4246        })
4247    }
4248}
4249
4250impl IntoV2 for crate::v1::EnvVariable {
4251    type Output = super::EnvVariable;
4252
4253    fn into_v2(self) -> Result<Self::Output> {
4254        let Self { name, value, meta } = self;
4255        Ok(super::EnvVariable {
4256            name: name.into_v2()?,
4257            value: value.into_v2()?,
4258            meta: meta.into_v2()?,
4259        })
4260    }
4261}
4262
4263impl IntoV1 for super::HttpHeader {
4264    type Output = crate::v1::HttpHeader;
4265
4266    fn into_v1(self) -> Result<Self::Output> {
4267        let Self { name, value, meta } = self;
4268        Ok(crate::v1::HttpHeader {
4269            name: name.into_v1()?,
4270            value: value.into_v1()?,
4271            meta: meta.into_v1()?,
4272        })
4273    }
4274}
4275
4276impl IntoV2 for crate::v1::HttpHeader {
4277    type Output = super::HttpHeader;
4278
4279    fn into_v2(self) -> Result<Self::Output> {
4280        let Self { name, value, meta } = self;
4281        Ok(super::HttpHeader {
4282            name: name.into_v2()?,
4283            value: value.into_v2()?,
4284            meta: meta.into_v2()?,
4285        })
4286    }
4287}
4288
4289impl IntoV1 for super::PromptRequest {
4290    type Output = crate::v1::PromptRequest;
4291
4292    fn into_v1(self) -> Result<Self::Output> {
4293        let Self {
4294            session_id,
4295            prompt,
4296            meta,
4297        } = self;
4298        Ok(crate::v1::PromptRequest {
4299            session_id: session_id.into_v1()?,
4300            prompt: prompt.into_v1()?,
4301            meta: meta.into_v1()?,
4302        })
4303    }
4304}
4305
4306impl IntoV2 for crate::v1::PromptRequest {
4307    type Output = super::PromptRequest;
4308
4309    fn into_v2(self) -> Result<Self::Output> {
4310        let Self {
4311            session_id,
4312            prompt,
4313            meta,
4314        } = self;
4315        Ok(super::PromptRequest {
4316            session_id: session_id.into_v2()?,
4317            prompt: prompt.into_v2()?,
4318            meta: meta.into_v2()?,
4319        })
4320    }
4321}
4322
4323impl IntoV1 for super::PromptResponse {
4324    type Output = crate::v1::PromptResponse;
4325
4326    fn into_v1(self) -> Result<Self::Output> {
4327        let Self {
4328            stop_reason,
4329            #[cfg(feature = "unstable_end_turn_token_usage")]
4330            usage,
4331            meta,
4332        } = self;
4333        Ok(crate::v1::PromptResponse {
4334            stop_reason: stop_reason.into_v1()?,
4335            #[cfg(feature = "unstable_end_turn_token_usage")]
4336            usage: usage.into_v1()?,
4337            meta: meta.into_v1()?,
4338        })
4339    }
4340}
4341
4342impl IntoV2 for crate::v1::PromptResponse {
4343    type Output = super::PromptResponse;
4344
4345    fn into_v2(self) -> Result<Self::Output> {
4346        let Self {
4347            stop_reason,
4348            #[cfg(feature = "unstable_end_turn_token_usage")]
4349            usage,
4350            meta,
4351        } = self;
4352        Ok(super::PromptResponse {
4353            stop_reason: stop_reason.into_v2()?,
4354            #[cfg(feature = "unstable_end_turn_token_usage")]
4355            usage: usage.into_v2()?,
4356            meta: meta.into_v2()?,
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 converts_v2_initialize_request_to_v1_without_serde() {
9027        let request = v2::InitializeRequest::new(ProtocolVersion::V2);
9028
9029        let converted: v1::InitializeRequest = v2_to_v1(request).unwrap();
9030
9031        assert_eq!(converted.protocol_version, ProtocolVersion::V2);
9032    }
9033
9034    #[test]
9035    fn converts_v1_initialize_request_to_v2_without_serde() {
9036        let request = v1::InitializeRequest::new(ProtocolVersion::V1);
9037
9038        let converted: v2::InitializeRequest = v1_to_v2(request).unwrap();
9039
9040        assert_eq!(converted.protocol_version, ProtocolVersion::V1);
9041    }
9042
9043    #[test]
9044    fn round_trips_initialize_request() {
9045        let client_capabilities = v1::ClientCapabilities::new();
9046
9047        let request = v1::InitializeRequest::new(ProtocolVersion::V1)
9048            .client_capabilities(client_capabilities)
9049            .client_info(v1::Implementation::new("test-client", "1.0.0").title("Test Client"));
9050
9051        assert_v1_round_trip::<v1::InitializeRequest, v2::InitializeRequest>(request.clone());
9052        let converted: v2::InitializeRequest =
9053            v1_to_v2(request).expect("v1 -> v2 conversion failed");
9054        let converted_capabilities =
9055            serde_json::to_value(converted.capabilities).expect("v2 serialize");
9056        assert_eq!(converted_capabilities.get("fs"), None);
9057        assert_eq!(converted_capabilities.get("terminal"), None);
9058    }
9059
9060    #[test]
9061    fn round_trips_initialize_response() {
9062        let response = v1::InitializeResponse::new(ProtocolVersion::V1)
9063            .agent_info(v1::Implementation::new("test-agent", "2.0.0").title("Test Agent"));
9064        assert_v1_round_trip::<v1::InitializeResponse, v2::InitializeResponse>(response.clone());
9065        let converted: v2::InitializeResponse =
9066            v1_to_v2(response).expect("v1 -> v2 conversion failed");
9067        let converted_json = serde_json::to_value(&converted).expect("v2 serialize");
9068        assert_eq!(converted_json.get("agentCapabilities"), None);
9069        assert!(converted_json.get("capabilities").is_some());
9070        assert_eq!(converted_json.pointer("/capabilities/loadSession"), None);
9071    }
9072
9073    #[test]
9074    fn agent_load_session_capability_moves_between_v1_and_v2() {
9075        let v1_capabilities = v1::AgentCapabilities::new().load_session(true);
9076
9077        let v2_capabilities: v2::AgentCapabilities =
9078            v1_to_v2(v1_capabilities).expect("v1 -> v2 conversion");
9079        let session = v2_capabilities
9080            .session
9081            .as_ref()
9082            .expect("v1 capabilities imply v2 session support");
9083        assert!(session.load.is_some());
9084        let v2_json = serde_json::to_value(&v2_capabilities).expect("v2 serialize");
9085        assert_eq!(v2_json.get("loadSession"), None);
9086        assert_eq!(
9087            v2_json.pointer("/session/load"),
9088            Some(&serde_json::json!({}))
9089        );
9090
9091        let v1_after: v1::AgentCapabilities =
9092            v2_to_v1(v2_capabilities).expect("v2 -> v1 conversion");
9093        assert!(v1_after.load_session);
9094    }
9095
9096    #[test]
9097    fn v2_agent_capabilities_without_session_do_not_convert_to_v1() {
9098        let error = v2::AgentCapabilities::new().into_v1().unwrap_err();
9099        assert_eq!(
9100            error.message(),
9101            "v2 AgentCapabilities without `session` cannot be represented in v1"
9102        );
9103    }
9104
9105    #[test]
9106    fn v2_session_capabilities_convert_to_v1_agent_capability_parts() {
9107        let parts = v2::SessionCapabilities::new()
9108            .load(v2::SessionLoadCapabilities::new())
9109            .prompt(v2::PromptCapabilities::new().image(v2::PromptImageCapabilities::new()))
9110            .mcp(v2::McpCapabilities::new().http(v2::McpHttpCapabilities::new()))
9111            .list(v2::SessionListCapabilities::new())
9112            .into_v1()
9113            .expect("v2 session capabilities -> v1 parts");
9114
9115        assert!(parts.session_capabilities.list.is_some());
9116        assert!(parts.prompt_capabilities.image);
9117        assert!(parts.load_session);
9118        assert!(parts.mcp_capabilities.http);
9119    }
9120
9121    #[test]
9122    fn v1_prompt_capability_bools_convert_to_v2_objects() {
9123        let v1_capabilities = v1::PromptCapabilities::new()
9124            .image(true)
9125            .audio(true)
9126            .embedded_context(true);
9127
9128        let v2_capabilities: v2::PromptCapabilities =
9129            v1_to_v2(v1_capabilities).expect("v1 -> v2 conversion");
9130        let v2_json = serde_json::to_value(&v2_capabilities).expect("v2 serialize");
9131        assert_eq!(v2_json.pointer("/image"), Some(&serde_json::json!({})));
9132        assert_eq!(v2_json.pointer("/audio"), Some(&serde_json::json!({})));
9133        assert_eq!(
9134            v2_json.pointer("/embeddedContext"),
9135            Some(&serde_json::json!({}))
9136        );
9137
9138        let v1_after: v1::PromptCapabilities =
9139            v2_to_v1(v2_capabilities).expect("v2 -> v1 conversion");
9140        assert!(v1_after.image);
9141        assert!(v1_after.audio);
9142        assert!(v1_after.embedded_context);
9143    }
9144
9145    #[test]
9146    fn v1_mcp_capabilities_convert_to_v2_transport_objects() {
9147        let v1_capabilities = v1::McpCapabilities::new().http(true).sse(true);
9148
9149        let v2_capabilities: v2::McpCapabilities =
9150            v1_to_v2(v1_capabilities).expect("v1 -> v2 conversion");
9151        let v2_json = serde_json::to_value(&v2_capabilities).expect("v2 serialize");
9152        assert_eq!(v2_json.pointer("/stdio"), Some(&serde_json::json!({})));
9153        assert_eq!(v2_json.pointer("/http"), Some(&serde_json::json!({})));
9154        assert_eq!(v2_json.pointer("/sse"), None);
9155
9156        let v1_after: v1::McpCapabilities = v2_to_v1(v2_capabilities).expect("v2 -> v1 conversion");
9157        assert!(v1_after.http);
9158        assert!(!v1_after.sse);
9159    }
9160
9161    #[cfg(feature = "unstable_mcp_over_acp")]
9162    #[test]
9163    fn v1_mcp_acp_capability_bool_converts_to_v2_object() {
9164        let v1_capabilities = v1::McpCapabilities::new().acp(true);
9165
9166        let v2_capabilities: v2::McpCapabilities =
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("/acp"), Some(&serde_json::json!({})));
9170
9171        let v1_after: v1::McpCapabilities = v2_to_v1(v2_capabilities).expect("v2 -> v1 conversion");
9172        assert!(v1_after.acp);
9173    }
9174
9175    #[cfg(feature = "unstable_auth_methods")]
9176    #[test]
9177    fn v1_auth_terminal_capability_bool_converts_to_v2_object() {
9178        let v1_capabilities = v1::AuthCapabilities::new().terminal(true);
9179
9180        let v2_capabilities: v2::AuthCapabilities =
9181            v1_to_v2(v1_capabilities).expect("v1 -> v2 conversion");
9182        let v2_json = serde_json::to_value(&v2_capabilities).expect("v2 serialize");
9183        assert_eq!(v2_json.pointer("/terminal"), Some(&serde_json::json!({})));
9184
9185        let v1_after: v1::AuthCapabilities =
9186            v2_to_v1(v2_capabilities).expect("v2 -> v1 conversion");
9187        assert!(v1_after.terminal);
9188    }
9189
9190    #[test]
9191    fn v1_client_fs_and_terminal_capabilities_are_removed_in_v2() {
9192        let v1_capabilities =
9193            v1::ClientCapabilities::new()
9194                .terminal(true)
9195                .fs(v1::FileSystemCapabilities::new()
9196                    .read_text_file(true)
9197                    .write_text_file(true));
9198
9199        let v2_capabilities: v2::ClientCapabilities =
9200            v1_to_v2(v1_capabilities).expect("v1 -> v2 conversion");
9201        let v2_json = serde_json::to_value(&v2_capabilities).expect("v2 serialize");
9202        assert_eq!(
9203            v2_json.get("fs"),
9204            None,
9205            "v2 ClientCapabilities must not include filesystem capabilities"
9206        );
9207        assert_eq!(
9208            v2_json.get("terminal"),
9209            None,
9210            "v2 ClientCapabilities must not include terminal capabilities"
9211        );
9212
9213        let v1_after: v1::ClientCapabilities =
9214            v2_to_v1(v2_capabilities).expect("v2 -> v1 conversion");
9215        assert!(!v1_after.fs.read_text_file);
9216        assert!(!v1_after.fs.write_text_file);
9217        assert!(!v1_after.terminal);
9218    }
9219
9220    #[test]
9221    fn v1_client_fs_and_terminal_methods_do_not_convert_to_v2() {
9222        assert_v1_to_v2_error(
9223            v1::AgentRequest::WriteTextFileRequest(v1::WriteTextFileRequest::new(
9224                "sess",
9225                "/workspace/file.txt",
9226                "contents",
9227            )),
9228            "v1 AgentRequest variant `fs/write_text_file` cannot be represented in v2",
9229        );
9230        assert_v1_to_v2_error(
9231            v1::AgentRequest::ReadTextFileRequest(v1::ReadTextFileRequest::new(
9232                "sess",
9233                "/workspace/file.txt",
9234            )),
9235            "v1 AgentRequest variant `fs/read_text_file` cannot be represented in v2",
9236        );
9237        assert_v1_to_v2_error(
9238            v1::AgentRequest::CreateTerminalRequest(v1::CreateTerminalRequest::new("sess", "echo")),
9239            "v1 AgentRequest variant `terminal/create` cannot be represented in v2",
9240        );
9241        assert_v1_to_v2_error(
9242            v1::AgentRequest::TerminalOutputRequest(v1::TerminalOutputRequest::new("sess", "term")),
9243            "v1 AgentRequest variant `terminal/output` cannot be represented in v2",
9244        );
9245        assert_v1_to_v2_error(
9246            v1::AgentRequest::ReleaseTerminalRequest(v1::ReleaseTerminalRequest::new(
9247                "sess", "term",
9248            )),
9249            "v1 AgentRequest variant `terminal/release` cannot be represented in v2",
9250        );
9251        assert_v1_to_v2_error(
9252            v1::AgentRequest::WaitForTerminalExitRequest(v1::WaitForTerminalExitRequest::new(
9253                "sess", "term",
9254            )),
9255            "v1 AgentRequest variant `terminal/wait_for_exit` cannot be represented in v2",
9256        );
9257        assert_v1_to_v2_error(
9258            v1::AgentRequest::KillTerminalRequest(v1::KillTerminalRequest::new("sess", "term")),
9259            "v1 AgentRequest variant `terminal/kill` cannot be represented in v2",
9260        );
9261
9262        assert_v1_to_v2_error(
9263            v1::ClientResponse::WriteTextFileResponse(v1::WriteTextFileResponse::new()),
9264            "v1 ClientResponse variant `fs/write_text_file` cannot be represented in v2",
9265        );
9266        assert_v1_to_v2_error(
9267            v1::ClientResponse::ReadTextFileResponse(v1::ReadTextFileResponse::new("contents")),
9268            "v1 ClientResponse variant `fs/read_text_file` cannot be represented in v2",
9269        );
9270        assert_v1_to_v2_error(
9271            v1::ClientResponse::CreateTerminalResponse(v1::CreateTerminalResponse::new("term")),
9272            "v1 ClientResponse variant `terminal/create` cannot be represented in v2",
9273        );
9274        assert_v1_to_v2_error(
9275            v1::ClientResponse::TerminalOutputResponse(v1::TerminalOutputResponse::new("", false)),
9276            "v1 ClientResponse variant `terminal/output` cannot be represented in v2",
9277        );
9278        assert_v1_to_v2_error(
9279            v1::ClientResponse::ReleaseTerminalResponse(v1::ReleaseTerminalResponse::new()),
9280            "v1 ClientResponse variant `terminal/release` cannot be represented in v2",
9281        );
9282        assert_v1_to_v2_error(
9283            v1::ClientResponse::WaitForTerminalExitResponse(v1::WaitForTerminalExitResponse::new(
9284                v1::TerminalExitStatus::new(),
9285            )),
9286            "v1 ClientResponse variant `terminal/wait_for_exit` cannot be represented in v2",
9287        );
9288        assert_v1_to_v2_error(
9289            v1::ClientResponse::KillTerminalResponse(v1::KillTerminalResponse::new()),
9290            "v1 ClientResponse variant `terminal/kill` cannot be represented in v2",
9291        );
9292    }
9293
9294    #[test]
9295    fn v1_terminal_tool_call_content_does_not_convert_to_v2() {
9296        assert_v1_to_v2_error(
9297            v1::ToolCallContent::Terminal(v1::Terminal::new("term")),
9298            "v1 ToolCallContent variant `terminal` cannot be represented in v2",
9299        );
9300    }
9301
9302    #[test]
9303    fn v1_mcp_sse_transport_does_not_convert_to_v2() {
9304        assert_v1_to_v2_error(
9305            v1::McpServer::Sse(v1::McpServerSse::new("events", "https://example.com/sse")),
9306            "v1 McpServer variant `sse` cannot be represented in v2",
9307        );
9308    }
9309
9310    #[test]
9311    fn v2_unknown_mcp_transport_does_not_convert_to_v1() {
9312        assert_v2_to_v1_error(
9313            v2::McpServer::Other(v2::OtherMcpServer::new("websocket", BTreeMap::default())),
9314            "v2 McpServer variant `websocket` cannot be represented in v1",
9315        );
9316    }
9317
9318    #[test]
9319    fn round_trips_new_session_request_with_mcp_variants() {
9320        let request = v1::NewSessionRequest::new("/workspace").mcp_servers(vec![
9321            v1::McpServer::Stdio(v1::McpServerStdio::new("local", "/usr/bin/mcp")),
9322            v1::McpServer::Http(v1::McpServerHttp::new("remote", "https://example.com")),
9323        ]);
9324
9325        assert_v1_round_trip::<v1::NewSessionRequest, v2::NewSessionRequest>(request.clone());
9326
9327        let v2_request: v2::NewSessionRequest = v1_to_v2(request).expect("v1 -> v2 conversion");
9328        assert_eq!(
9329            serde_json::to_value(&v2_request).expect("v2 serialize"),
9330            serde_json::json!({
9331                "cwd": "/workspace",
9332                "mcpServers": [
9333                    {
9334                        "type": "stdio",
9335                        "name": "local",
9336                        "command": "/usr/bin/mcp",
9337                        "args": [],
9338                        "env": []
9339                    },
9340                    {
9341                        "type": "http",
9342                        "name": "remote",
9343                        "url": "https://example.com",
9344                        "headers": []
9345                    }
9346                ]
9347            })
9348        );
9349    }
9350
9351    #[test]
9352    fn round_trips_prompt_request_with_content_variants() {
9353        let prompt = vec![
9354            v1::ContentBlock::Text(v1::TextContent::new("hello")),
9355            v1::ContentBlock::Image(v1::ImageContent::new("data", "image/png")),
9356            v1::ContentBlock::ResourceLink(v1::ResourceLink::new("file.txt", "file:///file.txt")),
9357        ];
9358        let request = v1::PromptRequest::new("sess_1", prompt);
9359        assert_v1_round_trip::<v1::PromptRequest, v2::PromptRequest>(request.clone());
9360        assert_json_eq_after_v1_to_v2::<v1::PromptRequest, v2::PromptRequest>(request);
9361    }
9362
9363    #[test]
9364    fn v1_tool_call_converts_to_v2_upsert_with_diff_and_locations() {
9365        let tool_call = v1::ToolCall::new("tc_1", "editing files")
9366            .kind(v1::ToolKind::Edit)
9367            .status(v1::ToolCallStatus::InProgress)
9368            .content(vec![v1::ToolCallContent::Diff(
9369                v1::Diff::new("/path", "new contents").old_text("old contents"),
9370            )])
9371            .locations(vec![v1::ToolCallLocation::new("/path").line(42)])
9372            .raw_input(serde_json::json!({"foo": "bar"}))
9373            .raw_output(serde_json::json!({"ok": true}));
9374
9375        let converted: v2::ToolCallUpdate = v1_to_v2(tool_call).expect("v1 -> v2 conversion");
9376        assert_eq!(
9377            serde_json::to_value(&converted).expect("v2 serialize"),
9378            serde_json::json!({
9379                "toolCallId": "tc_1",
9380                "title": "editing files",
9381                "kind": "edit",
9382                "status": "in_progress",
9383                "content": [
9384                    {
9385                        "type": "diff",
9386                        "path": "/path",
9387                        "oldText": "old contents",
9388                        "newText": "new contents"
9389                    }
9390                ],
9391                "locations": [
9392                    {
9393                        "path": "/path",
9394                        "line": 42
9395                    }
9396                ],
9397                "rawInput": {
9398                    "foo": "bar"
9399                },
9400                "rawOutput": {
9401                    "ok": true
9402                }
9403            })
9404        );
9405
9406        let back: v1::ToolCallUpdate = v2_to_v1(converted).expect("v2 -> v1 conversion");
9407        assert_eq!(back.tool_call_id.0.as_ref(), "tc_1");
9408        assert_eq!(back.fields.title.as_deref(), Some("editing files"));
9409        assert_eq!(back.fields.kind, Some(v1::ToolKind::Edit));
9410        assert_eq!(back.fields.status, Some(v1::ToolCallStatus::InProgress));
9411        assert_eq!(back.fields.content.as_ref().map(Vec::len), Some(1));
9412        assert_eq!(back.fields.locations.as_ref().map(Vec::len), Some(1));
9413        assert_eq!(
9414            back.fields.raw_input,
9415            Some(serde_json::json!({"foo": "bar"}))
9416        );
9417        assert_eq!(
9418            back.fields.raw_output,
9419            Some(serde_json::json!({"ok": true}))
9420        );
9421    }
9422
9423    #[test]
9424    fn v1_tool_call_update_round_trips_through_v2_tool_call_update_upsert() {
9425        let update = v1::ToolCallUpdate::new(
9426            "tc",
9427            v1::ToolCallUpdateFields::new()
9428                .status(v1::ToolCallStatus::Completed)
9429                .content(Vec::new()),
9430        );
9431
9432        assert_v1_round_trip::<v1::ToolCallUpdate, v2::ToolCallUpdate>(update.clone());
9433        assert_json_eq_after_v1_to_v2::<v1::ToolCallUpdate, v2::ToolCallUpdate>(update);
9434    }
9435
9436    #[test]
9437    fn round_trips_session_notification_for_unchanged_update_kinds() {
9438        fn content_chunk(text: &str, message_id: &str) -> v1::ContentChunk {
9439            let chunk = v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new(text)));
9440            chunk.message_id(message_id)
9441        }
9442
9443        let cases: Vec<v1::SessionUpdate> = vec![
9444            v1::SessionUpdate::UserMessageChunk(content_chunk("u", "msg_user")),
9445            v1::SessionUpdate::AgentMessageChunk(content_chunk("a", "msg_agent")),
9446            v1::SessionUpdate::AgentThoughtChunk(content_chunk("t", "msg_thought")),
9447            #[cfg(feature = "unstable_plan_operations")]
9448            v1::SessionUpdate::PlanUpdate(v1::PlanUpdate::new(v1::PlanUpdateContent::markdown(
9449                "plan-1",
9450                "## Steps\n- [ ] Test conversion",
9451            ))),
9452            #[cfg(feature = "unstable_plan_operations")]
9453            v1::SessionUpdate::PlanRemoved(v1::PlanRemoved::new("plan-1")),
9454            v1::SessionUpdate::SessionInfoUpdate(v1::SessionInfoUpdate::new().title("hi")),
9455            v1::SessionUpdate::UsageUpdate(
9456                v1::UsageUpdate::new(53_000, 200_000).cost(v1::Cost::new(0.045, "USD")),
9457            ),
9458        ];
9459        for update in cases {
9460            let notification = v1::SessionNotification::new("sess", update);
9461            let original_json = serde_json::to_value(&notification).expect("v1 serialize");
9462            let as_v2: v2::SessionNotification =
9463                v1_to_v2(notification.clone()).expect("v1 -> v2 conversion");
9464            let v2_json = serde_json::to_value(&as_v2).expect("v2 serialize");
9465            assert_eq!(
9466                original_json, v2_json,
9467                "JSON shape diverged after v1 -> v2 conversion"
9468            );
9469
9470            let back = v2_to_v1_many(as_v2).expect("v2 -> v1 conversion");
9471            assert_eq!(back, vec![notification]);
9472            let back_json = serde_json::to_value(&back[0]).expect("v1 serialize after round trip");
9473            assert_eq!(
9474                original_json, back_json,
9475                "JSON shape diverged after v2 -> v1 conversion"
9476            );
9477        }
9478    }
9479
9480    #[test]
9481    fn v1_tool_call_session_updates_convert_to_unified_v2_tool_call_update() {
9482        let create = v1::SessionNotification::new(
9483            "sess",
9484            v1::SessionUpdate::ToolCall(v1::ToolCall::new("tc", "title")),
9485        );
9486        let create_v2: v2::SessionNotification = v1_to_v2(create).expect("v1 -> v2 conversion");
9487        assert!(matches!(
9488            create_v2.update,
9489            v2::SessionUpdate::ToolCallUpdate(_)
9490        ));
9491        assert_eq!(
9492            serde_json::to_value(&create_v2).expect("v2 serialize"),
9493            serde_json::json!({
9494                "sessionId": "sess",
9495                "update": {
9496                    "sessionUpdate": "tool_call_update",
9497                    "toolCallId": "tc",
9498                    "title": "title"
9499                }
9500            })
9501        );
9502
9503        let update = v1::SessionNotification::new(
9504            "sess",
9505            v1::SessionUpdate::ToolCallUpdate(v1::ToolCallUpdate::new(
9506                "tc",
9507                v1::ToolCallUpdateFields::new().status(v1::ToolCallStatus::Completed),
9508            )),
9509        );
9510        let update_v2: v2::SessionNotification = v1_to_v2(update).expect("v1 -> v2 conversion");
9511        assert!(matches!(
9512            update_v2.update,
9513            v2::SessionUpdate::ToolCallUpdate(_)
9514        ));
9515        assert_eq!(
9516            serde_json::to_value(&update_v2).expect("v2 serialize"),
9517            serde_json::json!({
9518                "sessionId": "sess",
9519                "update": {
9520                    "sessionUpdate": "tool_call_update",
9521                    "toolCallId": "tc",
9522                    "status": "completed"
9523                }
9524            })
9525        );
9526    }
9527
9528    #[test]
9529    fn v2_full_messages_convert_to_v1_message_chunks() {
9530        let mut meta = v2::Meta::new();
9531        meta.insert("source".to_string(), serde_json::json!("full"));
9532
9533        let chunks = v2_to_v1_many(v2::SessionUpdate::UserMessage(
9534            v2::UserMessage::new("msg_user")
9535                .content(vec![
9536                    v2::ContentBlock::Text(v2::TextContent::new("hello")),
9537                    v2::ContentBlock::Text(v2::TextContent::new("world")),
9538                ])
9539                .meta(meta.clone()),
9540        ))
9541        .expect("v2 -> v1 conversion");
9542        assert_eq!(
9543            chunks,
9544            vec![
9545                v1::SessionUpdate::UserMessageChunk(
9546                    v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new("hello")))
9547                        .message_id("msg_user")
9548                        .meta(meta.clone())
9549                ),
9550                v1::SessionUpdate::UserMessageChunk(
9551                    v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new("world")))
9552                        .message_id("msg_user")
9553                        .meta(meta)
9554                ),
9555            ]
9556        );
9557
9558        assert_eq!(
9559            v2_to_v1_many(v2::SessionUpdate::AgentMessage(
9560                v2::AgentMessage::new("msg_agent")
9561                    .content(vec![v2::ContentBlock::Text(v2::TextContent::new("hello"))])
9562            ))
9563            .expect("v2 -> v1 conversion"),
9564            vec![v1::SessionUpdate::AgentMessageChunk(
9565                v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new("hello")))
9566                    .message_id("msg_agent")
9567            )]
9568        );
9569
9570        assert_eq!(
9571            v2_to_v1_many(v2::SessionUpdate::AgentThought(
9572                v2::AgentThought::new("msg_thought").content(vec![v2::ContentBlock::Text(
9573                    v2::TextContent::new("thinking")
9574                )])
9575            ))
9576            .expect("v2 -> v1 conversion"),
9577            vec![v1::SessionUpdate::AgentThoughtChunk(
9578                v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new("thinking")))
9579                    .message_id("msg_thought")
9580            )]
9581        );
9582    }
9583
9584    #[test]
9585    fn v2_full_message_session_notification_fans_out_to_v1_chunk_notifications() {
9586        let notification = v2::SessionNotification::new(
9587            "sess",
9588            v2::SessionUpdate::AgentMessage(v2::AgentMessage::new("msg_agent").content(vec![
9589                v2::ContentBlock::Text(v2::TextContent::new("hello")),
9590                v2::ContentBlock::Text(v2::TextContent::new("world")),
9591            ])),
9592        );
9593
9594        let notifications = v2_to_v1_many(notification).expect("v2 -> v1 conversion");
9595        assert_eq!(
9596            notifications,
9597            vec![
9598                v1::SessionNotification::new(
9599                    "sess",
9600                    v1::SessionUpdate::AgentMessageChunk(
9601                        v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new(
9602                            "hello"
9603                        )))
9604                        .message_id("msg_agent")
9605                    )
9606                ),
9607                v1::SessionNotification::new(
9608                    "sess",
9609                    v1::SessionUpdate::AgentMessageChunk(
9610                        v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new(
9611                            "world"
9612                        )))
9613                        .message_id("msg_agent")
9614                    )
9615                ),
9616            ]
9617        );
9618    }
9619
9620    #[test]
9621    fn v2_json_rpc_agent_notification_fans_out_to_v1_chunk_notifications() {
9622        let message = v2::JsonRpcMessage::wrap(v2::Notification {
9623            method: "session/update".into(),
9624            params: Some(v2::AgentNotification::SessionNotification(Box::new(
9625                v2::SessionNotification::new(
9626                    "sess",
9627                    v2::SessionUpdate::AgentMessage(v2::AgentMessage::new("msg_agent").content(
9628                        vec![
9629                            v2::ContentBlock::Text(v2::TextContent::new("hello")),
9630                            v2::ContentBlock::Text(v2::TextContent::new("world")),
9631                        ],
9632                    )),
9633                ),
9634            ))),
9635        });
9636
9637        let messages = v2_to_v1_many(message).expect("v2 -> v1 conversion");
9638        let json = messages
9639            .into_iter()
9640            .map(|message| serde_json::to_value(message).expect("serialize v1 message"))
9641            .collect::<Vec<_>>();
9642        assert_eq!(
9643            json,
9644            vec![
9645                serde_json::json!({
9646                    "jsonrpc": "2.0",
9647                    "method": "session/update",
9648                    "params": {
9649                        "sessionId": "sess",
9650                        "update": {
9651                            "sessionUpdate": "agent_message_chunk",
9652                            "content": {
9653                                "type": "text",
9654                                "text": "hello"
9655                            },
9656                            "messageId": "msg_agent"
9657                        }
9658                    }
9659                }),
9660                serde_json::json!({
9661                    "jsonrpc": "2.0",
9662                    "method": "session/update",
9663                    "params": {
9664                        "sessionId": "sess",
9665                        "update": {
9666                            "sessionUpdate": "agent_message_chunk",
9667                            "content": {
9668                                "type": "text",
9669                                "text": "world"
9670                            },
9671                            "messageId": "msg_agent"
9672                        }
9673                    }
9674                }),
9675            ]
9676        );
9677    }
9678
9679    #[test]
9680    fn v2_message_patches_and_clears_do_not_convert_to_v1_chunks() {
9681        assert_v2_to_v1_many_error(
9682            v2::SessionUpdate::AgentMessage(v2::AgentMessage::new("msg_agent")),
9683            "v2 SessionUpdate variant `agent_message` without content cannot be represented in v1 chunks",
9684        );
9685
9686        assert_v2_to_v1_many_error(
9687            v2::SessionUpdate::AgentMessage(
9688                v2::AgentMessage::new("msg_agent").content(None::<Vec<v2::ContentBlock>>),
9689            ),
9690            "v2 SessionUpdate variant `agent_message` with null content cannot be represented in v1 chunks",
9691        );
9692
9693        assert_v2_to_v1_many_error(
9694            v2::SessionUpdate::AgentMessage(
9695                v2::AgentMessage::new("msg_agent").content(Vec::<v2::ContentBlock>::new()),
9696            ),
9697            "v2 SessionUpdate variant `agent_message` with empty content cannot be represented in v1 chunks",
9698        );
9699
9700        assert_v2_to_v1_many_error(
9701            v2::SessionUpdate::AgentMessage(
9702                v2::AgentMessage::new("msg_agent")
9703                    .content(vec![v2::ContentBlock::Text(v2::TextContent::new("hello"))])
9704                    .meta(None::<v2::Meta>),
9705            ),
9706            "v2 SessionUpdate variant `agent_message` with null _meta cannot be represented in v1 chunks",
9707        );
9708    }
9709
9710    #[test]
9711    fn v2_tool_call_content_chunk_does_not_convert_to_v1_replacement_update() {
9712        assert_v2_to_v1_many_error(
9713            v2::SessionUpdate::ToolCallContentChunk(v2::ToolCallContentChunk::new(
9714                "tc_1",
9715                v2::ContentBlock::Text(v2::TextContent::new("partial output")),
9716            )),
9717            "v2 SessionUpdate variant `tool_call_content_chunk` cannot be represented in v1 because v1 tool-call content updates replace content instead of appending",
9718        );
9719    }
9720
9721    #[test]
9722    fn v1_content_chunk_without_message_id_does_not_convert_to_v2() {
9723        assert_v1_to_v2_error(
9724            v1::ContentChunk::new(v1::ContentBlock::Text(v1::TextContent::new("missing"))),
9725            "v1 ContentChunk without messageId cannot be represented in v2",
9726        );
9727    }
9728
9729    #[test]
9730    fn v1_plan_session_update_converts_to_v2_item_plan_update() {
9731        let update = v1::SessionUpdate::Plan(v1::Plan::new(vec![v1::PlanEntry::new(
9732            "step",
9733            v1::PlanEntryPriority::High,
9734            v1::PlanEntryStatus::InProgress,
9735        )]));
9736
9737        let as_v2: v2::SessionUpdate = v1_to_v2(update.clone()).unwrap();
9738        assert_eq!(
9739            serde_json::to_value(&as_v2).unwrap(),
9740            serde_json::json!({
9741                "sessionUpdate": "plan_update",
9742                "plan": {
9743                    "type": "items",
9744                    "id": LEGACY_V1_PLAN_ID,
9745                    "entries": [
9746                        {
9747                            "content": "step",
9748                            "priority": "high",
9749                            "status": "in_progress"
9750                        }
9751                    ]
9752                }
9753            })
9754        );
9755
9756        let back = v2_to_v1_many(as_v2).unwrap();
9757        #[cfg(not(feature = "unstable_plan_operations"))]
9758        assert_eq!(back, vec![update]);
9759        #[cfg(feature = "unstable_plan_operations")]
9760        assert!(matches!(
9761            back.as_slice(),
9762            [v1::SessionUpdate::PlanUpdate(_)]
9763        ));
9764    }
9765
9766    #[test]
9767    fn unknown_v2_session_update_does_not_convert_to_v1() {
9768        let update = v2::SessionUpdate::Other(v2::OtherSessionUpdate::new(
9769            "_status_badge",
9770            std::collections::BTreeMap::new(),
9771        ));
9772
9773        assert_v2_to_v1_many_error(
9774            update,
9775            "v2 SessionUpdate variant `_status_badge` cannot be represented in v1",
9776        );
9777    }
9778
9779    #[test]
9780    fn v1_current_mode_update_does_not_convert_to_v2() {
9781        assert_v1_to_v2_error(
9782            v1::SessionUpdate::CurrentModeUpdate(v1::CurrentModeUpdate::new("ask")),
9783            "v1 SessionUpdate variant `current_mode_update` cannot be represented in v2",
9784        );
9785    }
9786
9787    #[test]
9788    fn v1_session_mode_methods_do_not_convert_to_v2() {
9789        assert_v1_to_v2_error(
9790            v1::ClientRequest::SetSessionModeRequest(v1::SetSessionModeRequest::new("sess", "ask")),
9791            "v1 ClientRequest variant `session/set_mode` cannot be represented in v2",
9792        );
9793        assert_v1_to_v2_error(
9794            v1::AgentResponse::SetSessionModeResponse(v1::SetSessionModeResponse::new()),
9795            "v1 AgentResponse variant `session/set_mode` cannot be represented in v2",
9796        );
9797    }
9798
9799    #[test]
9800    fn v1_session_response_modes_fall_back_to_none_in_v2() {
9801        let response = v1::NewSessionResponse::new("sess").modes(v1::SessionModeState::new(
9802            "ask",
9803            vec![v1::SessionMode::new("ask", "Ask")],
9804        ));
9805
9806        let as_v2: v2::NewSessionResponse = v1_to_v2(response).unwrap();
9807        let back_to_v1: v1::NewSessionResponse = v2_to_v1(as_v2).unwrap();
9808
9809        assert!(back_to_v1.modes.is_none());
9810    }
9811
9812    #[test]
9813    fn v2_session_response_converts_to_v1_without_mode_state() {
9814        let response: v1::NewSessionResponse =
9815            v2_to_v1(v2::NewSessionResponse::new("sess")).unwrap();
9816
9817        assert!(response.modes.is_none());
9818    }
9819
9820    #[test]
9821    fn v2_tool_call_update_conversion_matches_v1_default_on_error_fields() {
9822        let update = v2::ToolCallUpdate::new("tc")
9823            .kind(v2::ToolKind::Unknown("_future_kind".to_string()))
9824            .status(v2::ToolCallStatus::Other("_paused".to_string()))
9825            .content(vec![
9826                v2::ToolCallContent::Other(v2::OtherToolCallContent::new(
9827                    "_chart",
9828                    BTreeMap::default(),
9829                )),
9830                v2::ToolCallContent::Diff(v2::Diff::new("/tmp/file.txt", "new")),
9831            ]);
9832
9833        let converted: v1::ToolCallUpdate = v2_to_v1(update).unwrap();
9834
9835        assert_eq!(converted.fields.kind, None);
9836        assert_eq!(converted.fields.status, None);
9837        assert_eq!(
9838            converted.fields.content,
9839            Some(vec![v1::ToolCallContent::Diff(v1::Diff::new(
9840                "/tmp/file.txt",
9841                "new"
9842            ))])
9843        );
9844    }
9845
9846    #[test]
9847    fn v2_collection_conversion_skips_items_like_v1_vec_skip_error() {
9848        let response = v2::InitializeResponse::new(ProtocolVersion::V2)
9849            .capabilities(v2::AgentCapabilities::new().session(v2::SessionCapabilities::new()))
9850            .auth_methods(vec![
9851                v2::AuthMethod::Other(v2::OtherAuthMethod::new(
9852                    "_oauth",
9853                    "oauth",
9854                    "OAuth",
9855                    BTreeMap::default(),
9856                )),
9857                v2::AuthMethod::Agent(v2::AuthMethodAgent::new("agent", "Agent")),
9858            ]);
9859        let converted: v1::InitializeResponse = v2_to_v1(response).unwrap();
9860        assert_eq!(converted.auth_methods.len(), 1);
9861        assert!(matches!(
9862            converted.auth_methods[0],
9863            v1::AuthMethod::Agent(_)
9864        ));
9865
9866        let config_update = v2::ConfigOptionUpdate::new(vec![
9867            v2::SessionConfigOption::select(
9868                "mode",
9869                "Mode",
9870                "ask",
9871                vec![v2::SessionConfigSelectOption::new("ask", "Ask")],
9872            ),
9873            v2::SessionConfigOption::new(
9874                "future",
9875                "Future",
9876                v2::SessionConfigKind::Other(v2::OtherSessionConfigKind::new(
9877                    "_slider",
9878                    BTreeMap::default(),
9879                )),
9880            ),
9881        ]);
9882        let converted: v1::ConfigOptionUpdate = v2_to_v1(config_update).unwrap();
9883        assert_eq!(converted.config_options.len(), 1);
9884        assert_eq!(converted.config_options[0].id.0.as_ref(), "mode");
9885    }
9886
9887    #[test]
9888    fn v2_default_on_error_fields_drop_unrepresentable_nested_values() {
9889        let command = v2::AvailableCommand::new("review", "Review changes").input(
9890            v2::AvailableCommandInput::Other(v2::OtherAvailableCommandInput::new(
9891                "_choices",
9892                BTreeMap::default(),
9893            )),
9894        );
9895        let converted: v1::AvailableCommandsUpdate =
9896            v2_to_v1(v2::AvailableCommandsUpdate::new(vec![command])).unwrap();
9897
9898        assert_eq!(converted.available_commands.len(), 1);
9899        assert_eq!(converted.available_commands[0].input, None);
9900
9901        let content = v2::TextContent::new("hello").annotations(
9902            v2::Annotations::new()
9903                .audience(vec![v2::Role::Other("_critic".to_string()), v2::Role::User]),
9904        );
9905        let converted: v1::TextContent = v2_to_v1(content).unwrap();
9906
9907        assert_eq!(
9908            converted
9909                .annotations
9910                .and_then(|annotations| annotations.audience),
9911            Some(vec![v1::Role::User])
9912        );
9913    }
9914
9915    #[test]
9916    fn v2_plan_entries_skip_unrepresentable_items_inside_tolerant_vectors() {
9917        let update = v2::PlanUpdate::new(v2::PlanUpdateContent::items(
9918            "main",
9919            vec![
9920                v2::PlanEntry::new(
9921                    "keep",
9922                    v2::PlanEntryPriority::High,
9923                    v2::PlanEntryStatus::Pending,
9924                ),
9925                v2::PlanEntry::new(
9926                    "drop",
9927                    v2::PlanEntryPriority::Other("_critical".to_string()),
9928                    v2::PlanEntryStatus::Pending,
9929                ),
9930            ],
9931        ));
9932
9933        #[cfg(not(feature = "unstable_plan_operations"))]
9934        {
9935            let converted: v1::Plan = v2_to_v1(update).unwrap();
9936            assert_eq!(converted.entries.len(), 1);
9937            assert_eq!(converted.entries[0].content, "keep");
9938        }
9939
9940        #[cfg(feature = "unstable_plan_operations")]
9941        {
9942            let converted: v1::PlanUpdate = v2_to_v1(update).unwrap();
9943            let v1::PlanUpdateContent::Items(items) = converted.plan else {
9944                panic!("expected item plan update");
9945            };
9946            assert_eq!(items.entries.len(), 1);
9947            assert_eq!(items.entries[0].content, "keep");
9948        }
9949    }
9950
9951    #[test]
9952    fn v1_tool_call_update_conversion_skips_items_for_v2_vec_skip_error_fields() {
9953        let update = v1::ToolCallUpdate::new(
9954            "tc",
9955            v1::ToolCallUpdateFields::new().content(vec![
9956                v1::ToolCallContent::Terminal(v1::Terminal::new("term")),
9957                v1::ToolCallContent::Diff(v1::Diff::new("/tmp/file.txt", "new")),
9958            ]),
9959        );
9960
9961        let converted: v2::ToolCallUpdate = v1_to_v2(update).unwrap();
9962        assert_eq!(
9963            converted.content,
9964            crate::MaybeUndefined::Value(vec![v2::ToolCallContent::Diff(v2::Diff::new(
9965                "/tmp/file.txt",
9966                "new"
9967            ))])
9968        );
9969    }
9970
9971    #[test]
9972    fn unknown_v2_raw_fallbacks_do_not_convert_to_v1() {
9973        assert_v2_to_v1_error(
9974            v2::ContentBlock::Other(v2::OtherContentBlock::new(
9975                "_widget",
9976                std::collections::BTreeMap::new(),
9977            )),
9978            "v2 ContentBlock variant `_widget` cannot be represented in v1",
9979        );
9980        assert_v2_to_v1_error(
9981            v2::ToolCallContent::Other(v2::OtherToolCallContent::new(
9982                "_chart",
9983                std::collections::BTreeMap::new(),
9984            )),
9985            "v2 ToolCallContent variant `_chart` cannot be represented in v1",
9986        );
9987        assert_v2_to_v1_error(
9988            v2::AvailableCommandInput::Other(v2::OtherAvailableCommandInput::new(
9989                "_choices",
9990                std::collections::BTreeMap::new(),
9991            )),
9992            "v2 AvailableCommandInput variant `_choices` cannot be represented in v1",
9993        );
9994        assert_v2_to_v1_error(
9995            v2::SessionConfigKind::Other(v2::OtherSessionConfigKind::new(
9996                "_slider",
9997                std::collections::BTreeMap::new(),
9998            )),
9999            "v2 SessionConfigKind variant `_slider` cannot be represented in v1",
10000        );
10001        assert_v2_to_v1_error(
10002            v2::AuthMethod::Other(v2::OtherAuthMethod::new(
10003                "_oauth",
10004                "oauth",
10005                "OAuth",
10006                std::collections::BTreeMap::new(),
10007            )),
10008            "v2 AuthMethod variant `_oauth` cannot be represented in v1",
10009        );
10010        assert_v2_to_v1_error(
10011            v2::PlanUpdate::new(v2::PlanUpdateContent::Other(
10012                v2::OtherPlanUpdateContent::new(
10013                    "_timeline",
10014                    "plan-1",
10015                    std::collections::BTreeMap::new(),
10016                ),
10017            )),
10018            "v2 PlanUpdateContent variant `_timeline` cannot be represented in v1",
10019        );
10020        #[cfg(feature = "unstable_nes")]
10021        assert_v2_to_v1_error(
10022            v2::NesSuggestion::Other(v2::OtherNesSuggestion::new(
10023                "_preview",
10024                std::collections::BTreeMap::new(),
10025            )),
10026            "v2 NesSuggestion variant `_preview` cannot be represented in v1",
10027        );
10028    }
10029
10030    #[test]
10031    fn round_trips_request_permission_outcomes() {
10032        let cancelled = v1::RequestPermissionResponse::new(v1::RequestPermissionOutcome::Cancelled);
10033        assert_v1_round_trip::<v1::RequestPermissionResponse, v2::RequestPermissionResponse>(
10034            cancelled,
10035        );
10036
10037        let selected = v1::RequestPermissionResponse::new(v1::RequestPermissionOutcome::Selected(
10038            v1::SelectedPermissionOutcome::new("opt_1"),
10039        ));
10040        assert_v1_round_trip::<v1::RequestPermissionResponse, v2::RequestPermissionResponse>(
10041            selected,
10042        );
10043    }
10044
10045    #[test]
10046    fn round_trips_error_with_data_payload() {
10047        let err = v1::Error::invalid_params().data(serde_json::json!({
10048            "reason": "missing field",
10049            "field": "sessionId",
10050        }));
10051        assert_v1_round_trip::<v1::Error, v2::Error>(err);
10052    }
10053
10054    #[test]
10055    fn round_trips_v2_value_back_through_v1() {
10056        // Same coverage but starting from v2, to exercise IntoV1 explicitly.
10057        let request = v2::PromptRequest::new(
10058            "sess_2",
10059            vec![v2::ContentBlock::Text(v2::TextContent::new("hi"))],
10060        );
10061        assert_v2_round_trip::<v2::PromptRequest, v1::PromptRequest>(request.clone());
10062        assert_json_eq_after_v2_to_v1::<v2::PromptRequest, v1::PromptRequest>(request);
10063    }
10064
10065    #[test]
10066    fn protocol_version_v1_constant_is_unchanged_by_feature_flag() {
10067        // Guards against `LATEST` accidentally being re-pointed to V2 in the
10068        // future; the contract is that `LATEST` is always the latest **stable**
10069        // version, even when the v2 draft feature is enabled.
10070        assert_eq!(ProtocolVersion::LATEST, ProtocolVersion::V1);
10071    }
10072
10073    /// `?` bubbles a [`ProtocolConversionError`] into a [`v1::Error`] without
10074    /// loss of message, mapped onto the internal-error code.
10075    #[test]
10076    fn protocol_conversion_error_maps_into_v1_error() {
10077        fn run() -> std::result::Result<(), v1::Error> {
10078            // Synthesize a conversion error so we don't have to wait for v2
10079            // to actually diverge before exercising the `?` path.
10080            Err(ProtocolConversionError::new("missing required field"))?;
10081            unreachable!();
10082        }
10083
10084        let err = run().unwrap_err();
10085        assert_eq!(err.code, v1::ErrorCode::InternalError);
10086        assert_eq!(
10087            err.data,
10088            Some(serde_json::Value::String(
10089                "missing required field".to_string()
10090            ))
10091        );
10092    }
10093
10094    /// Mirror of the v1 test for the v2 [`Error`] type.
10095    #[test]
10096    fn protocol_conversion_error_maps_into_v2_error() {
10097        fn run() -> std::result::Result<(), v2::Error> {
10098            Err(ProtocolConversionError::new("missing required field"))?;
10099            unreachable!();
10100        }
10101
10102        let err = run().unwrap_err();
10103        assert_eq!(err.code, v2::ErrorCode::InternalError);
10104        assert_eq!(
10105            err.data,
10106            Some(serde_json::Value::String(
10107                "missing required field".to_string()
10108            ))
10109        );
10110    }
10111}