Skip to content

Commit 57233d0

Browse files
authored
Merge pull request #2125 from nitinprajwal/qwen-code
feat(qwen-code): Use custom OAuth path for credential storage
2 parents 24644a4 + 617cf4a commit 57233d0

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

.changeset/metal-feet-dream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"kilo-code": patch
3+
---
4+
5+
Added support to Qwen Code for a custom OAuth credential storage path

src/api/providers/qwen-code.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
4238
function 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

Comments
 (0)