@@ -28,9 +28,9 @@ export interface JsonRpcTransportOptions {
2828}
2929
3030export class JsonRpcTransport implements A2ATransport {
31+ private readonly customFetchImpl ?: typeof fetch ;
32+ private readonly endpoint : string
3133 private requestIdCounter : number = 1 ;
32- private customFetchImpl ?: typeof fetch ;
33- private endpoint : string
3434
3535 constructor ( options : JsonRpcTransportOptions ) {
3636 this . endpoint = options . endpoint ;
@@ -96,7 +96,7 @@ export class JsonRpcTransport implements A2ATransport {
9696 ) ;
9797 }
9898
99- private async _sendRpcRequest < TParams , TResponse extends JSONRPCResponse > (
99+ private async _sendRpcRequest < TParams extends { [ key : string ] : any ; } , TResponse extends JSONRPCResponse > (
100100 method : string ,
101101 params : TParams ,
102102 idOverride : number | undefined ,
@@ -106,7 +106,7 @@ export class JsonRpcTransport implements A2ATransport {
106106 const rpcRequest : JSONRPCRequest = {
107107 jsonrpc : "2.0" ,
108108 method,
109- params : params as { [ key : string ] : any ; } ,
109+ params : params ,
110110 id : requestId ,
111111 } ;
112112
@@ -123,19 +123,20 @@ export class JsonRpcTransport implements A2ATransport {
123123 }
124124 if ( errorJson . jsonrpc && errorJson . error ) {
125125 throw JsonRpcTransport . mapToError ( errorJson ) ;
126- } else if ( ! errorJson . jsonrpc && errorJson . error ) {
127- throw new Error ( `RPC error for ${ method } : ${ errorJson . error . message } (Code: ${ errorJson . error . code } , HTTP Status: ${ httpResponse . status } ) Data: ${ JSON . stringify ( errorJson . error . data || { } ) } ` ) ;
128126 } else {
129127 throw new Error ( `HTTP error for ${ method } ! Status: ${ httpResponse . status } ${ httpResponse . statusText } . Response: ${ errorBodyText } ` ) ;
130128 }
131129 }
132130
133- const rpcResponse : JSONRPCSuccessResponse = await httpResponse . json ( ) ;
134-
131+ const rpcResponse : JSONRPCResponse = await httpResponse . json ( ) ;
135132 if ( rpcResponse . id !== requestId ) {
136133 console . error ( `CRITICAL: RPC response ID mismatch for method ${ method } . Expected ${ requestId } , got ${ rpcResponse . id } .` ) ;
137134 }
138135
136+ if ( 'error' in rpcResponse ) {
137+ throw JsonRpcTransport . mapToError ( rpcResponse ) ;
138+ }
139+
139140 return rpcResponse as TResponse ;
140141 }
141142
0 commit comments