@@ -536,7 +536,11 @@ mod imp {
536536 }
537537
538538 fn public_to_v2_message ( message : UntypedMessage ) -> Result < UntypedMessage , crate :: Error > {
539- let UntypedMessage { method, params } = message;
539+ let UntypedMessage { method, mut params } = message;
540+
541+ if method == "initialize" {
542+ ensure_legacy_initialize_info ( & mut params, "clientInfo" ) ;
543+ }
540544
541545 if let Some ( message) = try_convert_message_to_v2 :: < ClientRequest > ( & method, & params) ? {
542546 return Ok ( message) ;
@@ -573,8 +577,12 @@ mod imp {
573577
574578 fn public_to_v2_response (
575579 method : & str ,
576- value : serde_json:: Value ,
580+ mut value : serde_json:: Value ,
577581 ) -> Result < serde_json:: Value , crate :: Error > {
582+ if method == "initialize" {
583+ ensure_legacy_initialize_info ( & mut value, "agentInfo" ) ;
584+ }
585+
578586 if let Some ( value) = try_convert_response_to_v2 :: < AgentResponse > ( method, & value) ? {
579587 return Ok ( value) ;
580588 }
@@ -585,6 +593,27 @@ mod imp {
585593 Ok ( value)
586594 }
587595
596+ fn ensure_legacy_initialize_info ( value : & mut serde_json:: Value , field : & str ) {
597+ let serde_json:: Value :: Object ( object) = value else {
598+ return ;
599+ } ;
600+
601+ let needs_default = match object. get ( field) {
602+ Some ( value) => value. is_null ( ) ,
603+ None => true ,
604+ } ;
605+
606+ if needs_default {
607+ object. insert (
608+ field. into ( ) ,
609+ serde_json:: json!( {
610+ "name" : "legacy-acp-peer" ,
611+ "version" : "unknown" ,
612+ } ) ,
613+ ) ;
614+ }
615+ }
616+
588617 fn v2_to_public_response (
589618 method : & str ,
590619 value : serde_json:: Value ,
@@ -728,6 +757,10 @@ mod imp {
728757 . negotiated
729758 }
730759
760+ fn v2_implementation ( ) -> v2:: Implementation {
761+ v2:: Implementation :: new ( "rust-sdk-test" , "0.0.0" )
762+ }
763+
731764 #[ test]
732765 fn initialize_request_sets_active_wire_version_before_response ( ) -> Result < ( ) , crate :: Error >
733766 {
@@ -736,7 +769,7 @@ mod imp {
736769
737770 compat. incoming_message ( UntypedMessage :: new (
738771 "initialize" ,
739- v2:: InitializeRequest :: new ( ProtocolVersion :: V2 ) ,
772+ v2:: InitializeRequest :: new ( ProtocolVersion :: V2 , v2_implementation ( ) ) ,
740773 ) ?) ?;
741774
742775 assert_eq ! ( negotiated( & compat) , ProtocolVersionKind :: V1 ) ;
@@ -746,6 +779,7 @@ mod imp {
746779 "initialize" ,
747780 Ok ( serde_json:: to_value ( v2:: InitializeResponse :: new (
748781 ProtocolVersion :: V2 ,
782+ v2_implementation ( ) ,
749783 ) ) ?) ,
750784 ) ?;
751785
@@ -762,7 +796,7 @@ mod imp {
762796
763797 compat. outgoing_message ( UntypedMessage :: new (
764798 "initialize" ,
765- v2:: InitializeRequest :: new ( ProtocolVersion :: V1 ) ,
799+ v2:: InitializeRequest :: new ( ProtocolVersion :: V1 , v2_implementation ( ) ) ,
766800 ) ?) ?;
767801
768802 assert_eq ! ( negotiated( & compat) , ProtocolVersionKind :: V1 ) ;
@@ -772,6 +806,7 @@ mod imp {
772806 "initialize" ,
773807 Ok ( serde_json:: to_value ( v2:: InitializeResponse :: new (
774808 ProtocolVersion :: V2 ,
809+ v2_implementation ( ) ,
775810 ) ) ?) ,
776811 ) ?;
777812
@@ -788,7 +823,7 @@ mod imp {
788823
789824 compat. outgoing_message ( UntypedMessage :: new (
790825 "initialize" ,
791- v2:: InitializeRequest :: new ( ProtocolVersion :: V1 ) ,
826+ v2:: InitializeRequest :: new ( ProtocolVersion :: V1 , v2_implementation ( ) ) ,
792827 ) ?) ?;
793828
794829 assert_eq ! ( negotiated( & compat) , ProtocolVersionKind :: V1 ) ;
@@ -814,7 +849,7 @@ mod imp {
814849 let compat = ProtocolCompat :: new ( ProtocolMode :: v2_client ( ) ) ;
815850 compat. outgoing_message ( UntypedMessage :: new (
816851 "initialize" ,
817- v2:: InitializeRequest :: new ( ProtocolVersion :: V1 ) ,
852+ v2:: InitializeRequest :: new ( ProtocolVersion :: V1 , v2_implementation ( ) ) ,
818853 ) ?) ?;
819854
820855 let error = compat
@@ -838,7 +873,7 @@ mod imp {
838873 let compat = ProtocolCompat :: new ( ProtocolMode :: v2_agent ( ) ) ;
839874 let messages = compat. outgoing_notification ( UntypedMessage :: new (
840875 "session/update" ,
841- v2:: SessionNotification :: new (
876+ v2:: UpdateSessionNotification :: new (
842877 "sess" ,
843878 v2:: SessionUpdate :: AgentMessage ( v2:: AgentMessage :: new ( "msg_agent" ) . content (
844879 vec ! [
0 commit comments