Skip to main content

agent_client_protocol_schema/v2/
conversion.rs

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