@@ -1506,6 +1506,10 @@ function emitSessionMethod(key: string, method: RpcMethod, lines: string[], clas
15061506 const effectiveParams = resolveMethodParamsSchema ( method ) ;
15071507 const paramEntries = ( effectiveParams ?. properties ? Object . entries ( effectiveParams . properties ) : [ ] ) . filter ( ( [ k ] ) => k !== "sessionId" ) ;
15081508 const requiredSet = new Set ( effectiveParams ?. required || [ ] ) ;
1509+ const useRequestParameter =
1510+ paramEntries . length > 0 &&
1511+ ! ! getNullableInner ( method . params ) &&
1512+ paramEntries . every ( ( [ name ] ) => ! requiredSet . has ( name ) ) ;
15091513
15101514 // Sort so required params come before optional (C# requires defaults at end)
15111515 paramEntries . sort ( ( a , b ) => {
@@ -1515,12 +1519,28 @@ function emitSessionMethod(key: string, method: RpcMethod, lines: string[], clas
15151519 } ) ;
15161520
15171521 const requestClassName = paramsTypeName ( method ) ;
1522+ const wireRequestClassName = useRequestParameter ? `${ requestClassName } WithSession` : requestClassName ;
15181523 if ( method . stability === "experimental" ) {
15191524 experimentalRpcTypes . add ( requestClassName ) ;
1525+ if ( useRequestParameter ) {
1526+ experimentalRpcTypes . add ( wireRequestClassName ) ;
1527+ }
15201528 }
15211529 if ( effectiveParams ?. properties && Object . keys ( effectiveParams . properties ) . length > 0 ) {
1522- const reqClass = emitRpcClass ( requestClassName , effectiveParams , "internal" , classes ) ;
1523- if ( reqClass ) classes . push ( reqClass ) ;
1530+ if ( useRequestParameter ) {
1531+ const publicParams : JSONSchema7 = {
1532+ ...effectiveParams ,
1533+ properties : Object . fromEntries ( paramEntries ) ,
1534+ required : effectiveParams . required ?. filter ( ( name ) => name !== "sessionId" ) ,
1535+ } ;
1536+ const publicReqClass = emitRpcClass ( requestClassName , publicParams , methodVisibility , classes ) ;
1537+ if ( publicReqClass ) classes . push ( publicReqClass ) ;
1538+ const wireReqClass = emitRpcClass ( wireRequestClassName , effectiveParams , "internal" , classes ) ;
1539+ if ( wireReqClass ) classes . push ( wireReqClass ) ;
1540+ } else {
1541+ const reqClass = emitRpcClass ( requestClassName , effectiveParams , "internal" , classes ) ;
1542+ if ( reqClass ) classes . push ( reqClass ) ;
1543+ }
15241544 }
15251545
15261546 lines . push ( "" , `${ indent } /// <summary>Calls "${ method . rpcMethod } ".</summary>` ) ;
@@ -1533,22 +1553,30 @@ function emitSessionMethod(key: string, method: RpcMethod, lines: string[], clas
15331553 const sigParams : string [ ] = [ ] ;
15341554 const bodyAssignments = [ `SessionId = _sessionId` ] ;
15351555
1536- for ( const [ pName , pSchema ] of paramEntries ) {
1537- if ( typeof pSchema !== "object" ) continue ;
1538- const isReq = requiredSet . has ( pName ) ;
1539- const csType = resolveRpcType ( pSchema as JSONSchema7 , isReq , requestClassName , toPascalCase ( pName ) , classes ) ;
1540- sigParams . push ( `${ csType } ${ pName } ${ isReq ? "" : " = null" } ` ) ;
1541- bodyAssignments . push ( `${ toPascalCase ( pName ) } = ${ pName } ` ) ;
1556+ if ( useRequestParameter ) {
1557+ sigParams . push ( `${ requestClassName } ? request = null` ) ;
1558+ for ( const [ pName ] of paramEntries ) {
1559+ bodyAssignments . push ( `${ toPascalCase ( pName ) } = request?.${ toPascalCase ( pName ) } ` ) ;
1560+ }
1561+ } else {
1562+ for ( const [ pName , pSchema ] of paramEntries ) {
1563+ if ( typeof pSchema !== "object" ) continue ;
1564+ const isReq = requiredSet . has ( pName ) ;
1565+ const csType = resolveRpcType ( pSchema as JSONSchema7 , isReq , requestClassName , toPascalCase ( pName ) , classes ) ;
1566+ sigParams . push ( `${ csType } ${ pName } ${ isReq ? "" : " = null" } ` ) ;
1567+ bodyAssignments . push ( `${ toPascalCase ( pName ) } = ${ pName } ` ) ;
1568+ }
15421569 }
15431570 sigParams . push ( "CancellationToken cancellationToken = default" ) ;
15441571
15451572 const taskType = ! isVoidSchema ( resultSchema ) ? `Task<${ resultClassName } >` : "Task" ;
1573+ const localRequestName = useRequestParameter ? "rpcRequest" : "request" ;
15461574 lines . push ( `${ indent } ${ methodVisibility } async ${ taskType } ${ methodName } Async(${ sigParams . join ( ", " ) } )` ) ;
1547- lines . push ( `${ indent } {` , `${ indent } var request = new ${ requestClassName } { ${ bodyAssignments . join ( ", " ) } };` ) ;
1575+ lines . push ( `${ indent } {` , `${ indent } var ${ localRequestName } = new ${ wireRequestClassName } { ${ bodyAssignments . join ( ", " ) } };` ) ;
15481576 if ( ! isVoidSchema ( resultSchema ) ) {
1549- lines . push ( `${ indent } return await CopilotClient.InvokeRpcAsync<${ resultClassName } >(_rpc, "${ method . rpcMethod } ", [request ], cancellationToken);` , `${ indent } }` ) ;
1577+ lines . push ( `${ indent } return await CopilotClient.InvokeRpcAsync<${ resultClassName } >(_rpc, "${ method . rpcMethod } ", [${ localRequestName } ], cancellationToken);` , `${ indent } }` ) ;
15501578 } else {
1551- lines . push ( `${ indent } await CopilotClient.InvokeRpcAsync(_rpc, "${ method . rpcMethod } ", [request ], cancellationToken);` , `${ indent } }` ) ;
1579+ lines . push ( `${ indent } await CopilotClient.InvokeRpcAsync(_rpc, "${ method . rpcMethod } ", [${ localRequestName } ], cancellationToken);` , `${ indent } }` ) ;
15521580 }
15531581}
15541582
0 commit comments