@@ -10,7 +10,7 @@ import { countTokens } from "../../utils/countTokens"
1010 * Base class for API providers that implements common functionality.
1111 */
1212export abstract class BaseProvider implements ApiHandler {
13- protected client : any // Added protected client field
13+ // constructor remains empty, no new properties added here
1414
1515 abstract createMessage (
1616 systemPrompt : string ,
@@ -40,17 +40,19 @@ export abstract class BaseProvider implements ApiHandler {
4040 * Attempts common disposal methods on the client if it exists.
4141 */
4242 public dispose ( ) : void {
43- if ( this . client ) {
43+ // Use reflection to find any property named 'client' on the instance
44+ const clientProperty = ( this as any ) . client
45+ if ( clientProperty ) {
4446 // Try common disposal methods that SDKs might have
45- if ( typeof ( this . client as any ) . close === "function" ) {
46- ; ( this . client as any ) . close ( )
47- } else if ( typeof ( this . client as any ) . destroy === "function" ) {
48- ; ( this . client as any ) . destroy ( )
49- } else if ( typeof ( this . client as any ) . dispose === "function" ) {
50- ; ( this . client as any ) . dispose ( )
47+ if ( typeof clientProperty . close === "function" ) {
48+ clientProperty . close ( )
49+ } else if ( typeof clientProperty . destroy === "function" ) {
50+ clientProperty . destroy ( )
51+ } else if ( typeof clientProperty . dispose === "function" ) {
52+ clientProperty . dispose ( )
5153 }
52- // Clear the reference
53- this . client = undefined
54+ // Clear the reference on the instance
55+ ; ( this as any ) . client = undefined
5456 }
5557 }
5658}
0 commit comments