@@ -938,6 +938,18 @@ impl ElicitationRequestScope {
938938 }
939939}
940940
941+ impl From < ElicitationSessionScope > for ElicitationScope {
942+ fn from ( scope : ElicitationSessionScope ) -> Self {
943+ Self :: Session ( scope)
944+ }
945+ }
946+
947+ impl From < ElicitationRequestScope > for ElicitationScope {
948+ fn from ( scope : ElicitationRequestScope ) -> Self {
949+ Self :: Request ( scope)
950+ }
951+ }
952+
941953/// **UNSTABLE**
942954///
943955/// This capability is not part of the spec yet, and may be removed or changed at any point.
@@ -968,9 +980,9 @@ pub struct CreateElicitationRequest {
968980
969981impl CreateElicitationRequest {
970982 #[ must_use]
971- pub fn new ( mode : ElicitationMode , message : impl Into < String > ) -> Self {
983+ pub fn new ( mode : impl Into < ElicitationMode > , message : impl Into < String > ) -> Self {
972984 Self {
973- mode,
985+ mode : mode . into ( ) ,
974986 message : message. into ( ) ,
975987 meta : None ,
976988 }
@@ -1010,6 +1022,18 @@ pub enum ElicitationMode {
10101022 Url ( ElicitationUrlMode ) ,
10111023}
10121024
1025+ impl From < ElicitationFormMode > for ElicitationMode {
1026+ fn from ( mode : ElicitationFormMode ) -> Self {
1027+ Self :: Form ( mode)
1028+ }
1029+ }
1030+
1031+ impl From < ElicitationUrlMode > for ElicitationMode {
1032+ fn from ( mode : ElicitationUrlMode ) -> Self {
1033+ Self :: Url ( mode)
1034+ }
1035+ }
1036+
10131037impl ElicitationMode {
10141038 /// Returns the scope this elicitation mode is tied to.
10151039 #[ must_use]
@@ -1039,9 +1063,9 @@ pub struct ElicitationFormMode {
10391063
10401064impl ElicitationFormMode {
10411065 #[ must_use]
1042- pub fn new ( scope : ElicitationScope , requested_schema : ElicitationSchema ) -> Self {
1066+ pub fn new ( scope : impl Into < ElicitationScope > , requested_schema : ElicitationSchema ) -> Self {
10431067 Self {
1044- scope,
1068+ scope : scope . into ( ) ,
10451069 requested_schema,
10461070 }
10471071 }
@@ -1069,12 +1093,12 @@ pub struct ElicitationUrlMode {
10691093impl ElicitationUrlMode {
10701094 #[ must_use]
10711095 pub fn new (
1072- scope : ElicitationScope ,
1096+ scope : impl Into < ElicitationScope > ,
10731097 elicitation_id : impl Into < ElicitationId > ,
10741098 url : impl Into < String > ,
10751099 ) -> Self {
10761100 Self {
1077- scope,
1101+ scope : scope . into ( ) ,
10781102 elicitation_id : elicitation_id. into ( ) ,
10791103 url : url. into ( ) ,
10801104 }
@@ -1353,10 +1377,7 @@ mod tests {
13531377 fn form_mode_request_serialization ( ) {
13541378 let schema = ElicitationSchema :: new ( ) . string ( "name" , true ) ;
13551379 let req = CreateElicitationRequest :: new (
1356- ElicitationMode :: Form ( ElicitationFormMode :: new (
1357- ElicitationScope :: Session ( ElicitationSessionScope :: new ( "sess_1" ) ) ,
1358- schema,
1359- ) ) ,
1380+ ElicitationFormMode :: new ( ElicitationSessionScope :: new ( "sess_1" ) , schema) ,
13601381 "Please enter your name" ,
13611382 ) ;
13621383
@@ -1375,7 +1396,7 @@ mod tests {
13751396 let roundtripped: CreateElicitationRequest = serde_json:: from_value ( json) . unwrap ( ) ;
13761397 assert_eq ! (
13771398 * roundtripped. scope( ) ,
1378- ElicitationScope :: Session ( ElicitationSessionScope :: new( "sess_1" ) )
1399+ ElicitationSessionScope :: new( "sess_1" ) . into ( )
13791400 ) ;
13801401 assert_eq ! ( roundtripped. message, "Please enter your name" ) ;
13811402 assert ! ( matches!( roundtripped. mode, ElicitationMode :: Form ( _) ) ) ;
@@ -1384,13 +1405,11 @@ mod tests {
13841405 #[ test]
13851406 fn url_mode_request_serialization ( ) {
13861407 let req = CreateElicitationRequest :: new (
1387- ElicitationMode :: Url ( ElicitationUrlMode :: new (
1388- ElicitationScope :: Session (
1389- ElicitationSessionScope :: new ( "sess_2" ) . tool_call_id ( "tc_1" ) ,
1390- ) ,
1408+ ElicitationUrlMode :: new (
1409+ ElicitationSessionScope :: new ( "sess_2" ) . tool_call_id ( "tc_1" ) ,
13911410 "elic_1" ,
13921411 "https://example.com/auth" ,
1393- ) ) ,
1412+ ) ,
13941413 "Please authenticate" ,
13951414 ) ;
13961415
@@ -1405,7 +1424,9 @@ mod tests {
14051424 let roundtripped: CreateElicitationRequest = serde_json:: from_value ( json) . unwrap ( ) ;
14061425 assert_eq ! (
14071426 * roundtripped. scope( ) ,
1408- ElicitationScope :: Session ( ElicitationSessionScope :: new( "sess_2" ) . tool_call_id( "tc_1" ) , )
1427+ ElicitationSessionScope :: new( "sess_2" )
1428+ . tool_call_id( "tc_1" )
1429+ . into( )
14091430 ) ;
14101431 assert ! ( matches!( roundtripped. mode, ElicitationMode :: Url ( _) ) ) ;
14111432 }
@@ -1455,35 +1476,14 @@ mod tests {
14551476 assert ! ( matches!( roundtripped. action, ElicitationAction :: Cancel ) ) ;
14561477 }
14571478
1458- #[ test]
1459- fn session_only_request_serialization ( ) {
1460- let req = CreateElicitationRequest :: new (
1461- ElicitationMode :: Form ( ElicitationFormMode :: new (
1462- ElicitationScope :: Session ( ElicitationSessionScope :: new ( "sess_1" ) ) ,
1463- ElicitationSchema :: new ( ) . string ( "name" , true ) ,
1464- ) ) ,
1465- "Enter your name" ,
1466- ) ;
1467-
1468- let json = serde_json:: to_value ( & req) . unwrap ( ) ;
1469- assert_eq ! ( json[ "sessionId" ] , "sess_1" ) ;
1470- assert ! ( json. get( "toolCallId" ) . is_none( ) ) ;
1471-
1472- let roundtripped: CreateElicitationRequest = serde_json:: from_value ( json) . unwrap ( ) ;
1473- assert_eq ! (
1474- * roundtripped. scope( ) ,
1475- ElicitationScope :: Session ( ElicitationSessionScope :: new( "sess_1" ) )
1476- ) ;
1477- }
1478-
14791479 #[ test]
14801480 fn url_mode_request_scope_serialization ( ) {
14811481 let req = CreateElicitationRequest :: new (
1482- ElicitationMode :: Url ( ElicitationUrlMode :: new (
1483- ElicitationScope :: Request ( ElicitationRequestScope :: new ( RequestId :: Number ( 42 ) ) ) ,
1482+ ElicitationUrlMode :: new (
1483+ ElicitationRequestScope :: new ( RequestId :: Number ( 42 ) ) ,
14841484 "elic_2" ,
14851485 "https://example.com/setup" ,
1486- ) ) ,
1486+ ) ,
14871487 "Please complete setup" ,
14881488 ) ;
14891489
@@ -1498,18 +1498,18 @@ mod tests {
14981498 let roundtripped: CreateElicitationRequest = serde_json:: from_value ( json) . unwrap ( ) ;
14991499 assert_eq ! (
15001500 * roundtripped. scope( ) ,
1501- ElicitationScope :: Request ( ElicitationRequestScope :: new( RequestId :: Number ( 42 ) ) )
1501+ ElicitationRequestScope :: new( RequestId :: Number ( 42 ) ) . into ( )
15021502 ) ;
15031503 assert ! ( matches!( roundtripped. mode, ElicitationMode :: Url ( _) ) ) ;
15041504 }
15051505
15061506 #[ test]
15071507 fn request_scope_request_serialization ( ) {
15081508 let req = CreateElicitationRequest :: new (
1509- ElicitationMode :: Form ( ElicitationFormMode :: new (
1510- ElicitationScope :: Request ( ElicitationRequestScope :: new ( RequestId :: Number ( 99 ) ) ) ,
1509+ ElicitationFormMode :: new (
1510+ ElicitationRequestScope :: new ( RequestId :: Number ( 99 ) ) ,
15111511 ElicitationSchema :: new ( ) . string ( "workspace" , true ) ,
1512- ) ) ,
1512+ ) ,
15131513 "Enter workspace name" ,
15141514 ) ;
15151515
@@ -1520,7 +1520,7 @@ mod tests {
15201520 let roundtripped: CreateElicitationRequest = serde_json:: from_value ( json) . unwrap ( ) ;
15211521 assert_eq ! (
15221522 * roundtripped. scope( ) ,
1523- ElicitationScope :: Request ( ElicitationRequestScope :: new( RequestId :: Number ( 99 ) ) )
1523+ ElicitationRequestScope :: new( RequestId :: Number ( 99 ) ) . into ( )
15241524 ) ;
15251525 }
15261526
@@ -1597,10 +1597,7 @@ mod tests {
15971597 } ) ;
15981598
15991599 let req: CreateElicitationRequest = serde_json:: from_value ( json) . unwrap ( ) ;
1600- assert_eq ! (
1601- * req. scope( ) ,
1602- ElicitationScope :: Session ( ElicitationSessionScope :: new( "sess_1" ) )
1603- ) ;
1600+ assert_eq ! ( * req. scope( ) , ElicitationSessionScope :: new( "sess_1" ) . into( ) ) ;
16041601 assert_eq ! ( req. message, "Enter your name" ) ;
16051602 assert ! ( matches!( req. mode, ElicitationMode :: Form ( _) ) ) ;
16061603 }
0 commit comments