1- use aws_smithy_types:: Document ;
1+ use aws_smithy_types:: {
2+ Blob ,
3+ Document ,
4+ } ;
25use serde:: {
36 Deserialize ,
47 Serialize ,
@@ -565,17 +568,113 @@ impl From<GitState> for amzn_qdeveloper_streaming_client::types::GitState {
565568 }
566569}
567570
571+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
572+ pub struct ImageBlock {
573+ pub format : ImageFormat ,
574+ pub source : ImageSource ,
575+ }
576+
577+ #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq ) ]
578+ pub enum ImageFormat {
579+ Gif ,
580+ Jpeg ,
581+ Png ,
582+ Webp ,
583+ }
584+
585+ impl std:: str:: FromStr for ImageFormat {
586+ type Err = String ;
587+
588+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
589+ match s. trim ( ) . to_lowercase ( ) . as_str ( ) {
590+ "gif" => Ok ( ImageFormat :: Gif ) ,
591+ "jpeg" => Ok ( ImageFormat :: Jpeg ) ,
592+ "jpg" => Ok ( ImageFormat :: Jpeg ) ,
593+ "png" => Ok ( ImageFormat :: Png ) ,
594+ "webp" => Ok ( ImageFormat :: Webp ) ,
595+ _ => Err ( format ! ( "Failed to parse '{}' as ImageFormat" , s) ) ,
596+ }
597+ }
598+ }
599+
600+ impl From < ImageFormat > for amzn_codewhisperer_streaming_client:: types:: ImageFormat {
601+ fn from ( value : ImageFormat ) -> Self {
602+ match value {
603+ ImageFormat :: Gif => Self :: Gif ,
604+ ImageFormat :: Jpeg => Self :: Jpeg ,
605+ ImageFormat :: Png => Self :: Png ,
606+ ImageFormat :: Webp => Self :: Webp ,
607+ }
608+ }
609+ }
610+ impl From < ImageFormat > for amzn_qdeveloper_streaming_client:: types:: ImageFormat {
611+ fn from ( value : ImageFormat ) -> Self {
612+ match value {
613+ ImageFormat :: Gif => Self :: Gif ,
614+ ImageFormat :: Jpeg => Self :: Jpeg ,
615+ ImageFormat :: Png => Self :: Png ,
616+ ImageFormat :: Webp => Self :: Webp ,
617+ }
618+ }
619+ }
620+
621+ #[ non_exhaustive]
622+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
623+ pub enum ImageSource {
624+ Bytes ( Vec < u8 > ) ,
625+ #[ non_exhaustive]
626+ Unknown ,
627+ }
628+
629+ impl From < ImageSource > for amzn_codewhisperer_streaming_client:: types:: ImageSource {
630+ fn from ( value : ImageSource ) -> Self {
631+ match value {
632+ ImageSource :: Bytes ( bytes) => Self :: Bytes ( Blob :: new ( bytes) ) ,
633+ ImageSource :: Unknown => Self :: Unknown ,
634+ }
635+ }
636+ }
637+ impl From < ImageSource > for amzn_qdeveloper_streaming_client:: types:: ImageSource {
638+ fn from ( value : ImageSource ) -> Self {
639+ match value {
640+ ImageSource :: Bytes ( bytes) => Self :: Bytes ( Blob :: new ( bytes) ) ,
641+ ImageSource :: Unknown => Self :: Unknown ,
642+ }
643+ }
644+ }
645+
646+ impl From < ImageBlock > for amzn_codewhisperer_streaming_client:: types:: ImageBlock {
647+ fn from ( value : ImageBlock ) -> Self {
648+ Self :: builder ( )
649+ . format ( value. format . into ( ) )
650+ . source ( value. source . into ( ) )
651+ . build ( )
652+ . expect ( "Failed to build ImageBlock" )
653+ }
654+ }
655+ impl From < ImageBlock > for amzn_qdeveloper_streaming_client:: types:: ImageBlock {
656+ fn from ( value : ImageBlock ) -> Self {
657+ Self :: builder ( )
658+ . format ( value. format . into ( ) )
659+ . source ( value. source . into ( ) )
660+ . build ( )
661+ . expect ( "Failed to build ImageBlock" )
662+ }
663+ }
664+
568665#[ derive( Debug , Clone ) ]
569666pub struct UserInputMessage {
570667 pub content : String ,
571668 pub user_input_message_context : Option < UserInputMessageContext > ,
572669 pub user_intent : Option < UserIntent > ,
670+ pub images : Option < Vec < ImageBlock > > ,
573671}
574672
575673impl From < UserInputMessage > for amzn_codewhisperer_streaming_client:: types:: UserInputMessage {
576674 fn from ( value : UserInputMessage ) -> Self {
577675 Self :: builder ( )
578676 . content ( value. content )
677+ . set_images ( value. images . map ( |images| images. into_iter ( ) . map ( Into :: into) . collect ( ) ) )
579678 . set_user_input_message_context ( value. user_input_message_context . map ( Into :: into) )
580679 . set_user_intent ( value. user_intent . map ( Into :: into) )
581680 . origin ( amzn_codewhisperer_streaming_client:: types:: Origin :: Cli )
@@ -588,6 +687,7 @@ impl From<UserInputMessage> for amzn_qdeveloper_streaming_client::types::UserInp
588687 fn from ( value : UserInputMessage ) -> Self {
589688 Self :: builder ( )
590689 . content ( value. content )
690+ . set_images ( value. images . map ( |images| images. into_iter ( ) . map ( Into :: into) . collect ( ) ) )
591691 . set_user_input_message_context ( value. user_input_message_context . map ( Into :: into) )
592692 . set_user_intent ( value. user_intent . map ( Into :: into) )
593693 . origin ( amzn_qdeveloper_streaming_client:: types:: Origin :: Cli )
@@ -654,6 +754,10 @@ mod tests {
654754 #[ test]
655755 fn build_user_input_message ( ) {
656756 let user_input_message = UserInputMessage {
757+ images : Some ( vec ! [ ImageBlock {
758+ format: ImageFormat :: Png ,
759+ source: ImageSource :: Bytes ( vec![ 1 , 2 , 3 ] ) ,
760+ } ] ) ,
657761 content : "test content" . to_string ( ) ,
658762 user_input_message_context : Some ( UserInputMessageContext {
659763 env_state : Some ( EnvState {
@@ -690,6 +794,7 @@ mod tests {
690794 assert_eq ! ( format!( "{codewhisper_input:?}" ) , format!( "{qdeveloper_input:?}" ) ) ;
691795
692796 let minimal_message = UserInputMessage {
797+ images : None ,
693798 content : "test content" . to_string ( ) ,
694799 user_input_message_context : None ,
695800 user_intent : None ,
0 commit comments