@@ -284,19 +284,14 @@ function instrumentMethod<T extends unknown[], R>(
284
284
*/
285
285
function createDeepProxy < T extends object > ( target : T , currentPath = '' , options ?: GoogleGenAIOptions ) : T {
286
286
return new Proxy ( target , {
287
- get ( obj : object , prop : string ) : unknown {
288
- const value = ( obj as Record < string , unknown > ) [ prop ] ;
287
+ get : ( t , prop ) => {
288
+ const value = Reflect . get ( t , prop ) ;
289
289
const methodPath = buildMethodPath ( currentPath , String ( prop ) ) ;
290
290
291
291
if ( typeof value === 'function' && shouldInstrument ( methodPath ) ) {
292
292
// Special case: chats.create is synchronous but needs both instrumentation AND result proxying
293
293
if ( methodPath === CHATS_CREATE_METHOD ) {
294
- const instrumentedMethod = instrumentMethod (
295
- value as ( ...args : unknown [ ] ) => unknown ,
296
- methodPath ,
297
- obj ,
298
- options ,
299
- ) ;
294
+ const instrumentedMethod = instrumentMethod ( value as ( ...args : unknown [ ] ) => unknown , methodPath , t , options ) ;
300
295
return function instrumentedAndProxiedCreate ( ...args : unknown [ ] ) : unknown {
301
296
const result = instrumentedMethod ( ...args ) ;
302
297
// If the result is an object (like a chat instance), proxy it too
@@ -307,12 +302,12 @@ function createDeepProxy<T extends object>(target: T, currentPath = '', options?
307
302
} ;
308
303
}
309
304
310
- return instrumentMethod ( value as ( ...args : unknown [ ] ) => Promise < unknown > , methodPath , obj , options ) ;
305
+ return instrumentMethod ( value as ( ...args : unknown [ ] ) => Promise < unknown > , methodPath , t , options ) ;
311
306
}
312
307
313
308
if ( typeof value === 'function' ) {
314
309
// Bind non-instrumented functions to preserve the original `this` context
315
- return value . bind ( obj ) ;
310
+ return value . bind ( t ) ;
316
311
}
317
312
318
313
if ( value && typeof value === 'object' ) {
0 commit comments