(obj: object, prop: string)
| 240 | function createDeepProxy<T extends object>(target: T, currentPath = '', options: OpenAiOptions): T { |
| 241 | return new Proxy(target, { |
| 242 | get(obj: object, prop: string): unknown { |
| 243 | const value = (obj as Record<string, unknown>)[prop]; |
| 244 | const methodPath = buildMethodPath(currentPath, String(prop)); |
| 245 | |
| 246 | const instrumentedMethod = OPENAI_METHOD_REGISTRY[methodPath as keyof typeof OPENAI_METHOD_REGISTRY]; |
| 247 | if (typeof value === 'function' && instrumentedMethod) { |
| 248 | return instrumentMethod( |
| 249 | value as (...args: unknown[]) => Promise<unknown>, |
| 250 | methodPath, |
| 251 | instrumentedMethod, |
| 252 | obj, |
| 253 | options, |
| 254 | ); |
| 255 | } |
| 256 | |
| 257 | if (typeof value === 'function') { |
| 258 | // Bind non-instrumented functions to preserve the original `this` context, |
| 259 | // which is required for accessing private class fields (e.g. #baseURL) in OpenAI SDK v5. |
| 260 | return value.bind(obj); |
| 261 | } |
| 262 | |
| 263 | if (value && typeof value === 'object') { |
| 264 | return createDeepProxy(value, methodPath, options); |
| 265 | } |
| 266 | |
| 267 | return value; |
| 268 | }, |
| 269 | }) as T; |
| 270 | } |
| 271 |
nothing calls this directly
no test coverage detected