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