()
| 172 | } |
| 173 | |
| 174 | private async ensureAuthenticated(): Promise<void> { |
| 175 | if (!this.credentials) { |
| 176 | this.credentials = await this.loadCachedQwenCredentials() |
| 177 | } |
| 178 | |
| 179 | if (!this.isTokenValid(this.credentials)) { |
| 180 | this.credentials = await this.refreshAccessToken(this.credentials) |
| 181 | } |
| 182 | |
| 183 | // After authentication, update the apiKey and baseURL on the existing client |
| 184 | const client = this.ensureClient() |
| 185 | client.apiKey = this.credentials.access_token |
| 186 | client.baseURL = this.getBaseUrl(this.credentials) |
| 187 | } |
| 188 | |
| 189 | private getBaseUrl(creds: QwenOAuthCredentials): string { |
| 190 | let baseUrl = creds.resource_url || "https://dashscope.aliyuncs.com/compatible-mode/v1" |
no test coverage detected