@@ -35,10 +35,6 @@ interface QwenOAuthCredentials {
3535 resource_url ?: string
3636}
3737
38- function getQwenCachedCredentialPath ( ) : string {
39- return path . join ( os . homedir ( ) , QWEN_DIR , QWEN_CREDENTIAL_FILENAME )
40- }
41-
4238function objectToUrlEncoded ( data : Record < string , string > ) : string {
4339 return Object . keys ( data )
4440 . map ( ( key ) => `${ encodeURIComponent ( key ) } =${ encodeURIComponent ( data [ key ] ) } ` )
@@ -62,13 +58,20 @@ export class QwenCodeHandler extends BaseProvider implements SingleCompletionHan
6258 } )
6359 }
6460
61+ private getQwenCachedCredentialPath ( ) : string {
62+ if ( this . options . qwenCodeOAuthPath ) {
63+ return this . options . qwenCodeOAuthPath
64+ }
65+ return path . join ( os . homedir ( ) , QWEN_DIR , QWEN_CREDENTIAL_FILENAME )
66+ }
67+
6568 private async loadCachedQwenCredentials ( ) : Promise < QwenOAuthCredentials > {
69+ const keyFile = this . getQwenCachedCredentialPath ( )
6670 try {
67- const keyFile = getQwenCachedCredentialPath ( )
6871 const credsStr = await fs . readFile ( keyFile , "utf-8" )
6972 return JSON . parse ( credsStr )
7073 } catch ( error ) {
71- console . error ( `Error reading or parsing credentials file at ${ getQwenCachedCredentialPath ( ) } ` )
74+ console . error ( `Error reading or parsing credentials file at ${ keyFile } ` )
7275 throw new Error ( t ( "common:errors.qwenCode.oauthLoadFailed" , { error } ) )
7376 }
7477 }
@@ -112,7 +115,7 @@ export class QwenCodeHandler extends BaseProvider implements SingleCompletionHan
112115 expiry_date : Date . now ( ) + tokenData . expires_in * 1000 ,
113116 }
114117
115- const filePath = getQwenCachedCredentialPath ( )
118+ const filePath = this . getQwenCachedCredentialPath ( )
116119 await fs . writeFile ( filePath , JSON . stringify ( newCredentials , null , 2 ) )
117120
118121 return newCredentials
0 commit comments