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