Request validation and remove credit balance for cline team (#4817)
* Fix: Ensure Cline client is initialized with the latest auth token
The Cline client was not being re-initialized with the latest authentication token after the user signs in. This resulted in the client using an outdated or non-existent token, leading to authentication errors when making API requests.
This commit ensures that the Cline client is initialized with the most recent authentication token by setting the `apiKey` property of the `OpenAI` client instance to the current auth token retrieved from `AuthService` before every request. This guarantees that the client always uses the valid and up-to-date token for authentication.
* changeset
* move this._authService.getAuthToken() to ensureClient
* Request validation and remove credit balance for cline team
Add request validation for Cline API requests and fix the user interface for displaying credit-related information in UI.
The changes include:
- **Credit Balance Validation:** Implemented `validateRequest` method in `ClineAccountService` to check user's credit balance before making API requests. Requests from active organizations are skipped. An error is thrown if the balance is insufficient.
- **Error Handling:** Improved error handling in `ClineHandler` to provide more informative error messages to the user.
- **UI Enhancements:**
- Updated `CreditLimitError` component to display the current balance that matches the account view balance format (4 decimal places).
- Modified `ChatRow` to parse error messages and display the `CreditLimitError` component when applicable.
- Updated `AccountView` to only display credit balance for user accounts, not organization accounts.
- Removed unused props from `CreditLimitError` component. Context: https://cline-space.slack.com/archives/C08KYBFL9DJ/p1752182278852399?thread_ts=1752164726.247429&cid=C08KYBFL9DJ
- **Dependencies:** Updated dependencies in `webview-ui` to include `tailwindcss` and configured `tailwind.config.js` to support VSCode theme variables.
* changeset
* Update src/api/providers/cline.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---------
Co-authored-by: abeatrix <beatrix@cline.bot>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
6 files changed
+121
-117
No files matched your search
+13
-12
@@ -64,19 +64,19 @@ export class ClineHandler implements ApiHandler {
|
||||
|
||||
@withRetry()
|
||||
async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {
|
||||
const client = await this.ensureClient()
|
||||
|
||||
this.lastGenerationId = undefined
|
||||
|
||||
const me = await this.clineAccountService.fetchMe()
|
||||
console.log(
|
||||
"SwitchAuthToken: Active Organization",
|
||||
me?.organizations.filter((org) => org.active)[0]?.name || "No active organization",
|
||||
)
|
||||
|
||||
let didOutputUsage: boolean = false
|
||||
|
||||
try {
|
||||
// Only continue the request if the user:
|
||||
// 1. Has signed in to Cline with a token
|
||||
// 2. Has more than 0 credits
|
||||
// Or an error is thrown.
|
||||
await this.clineAccountService.validateRequest()
|
||||
|
||||
const client = await this.ensureClient()
|
||||
|
||||
this.lastGenerationId = undefined
|
||||
|
||||
let didOutputUsage: boolean = false
|
||||
|
||||
const stream = await createOpenRouterStream(
|
||||
client,
|
||||
systemPrompt,
|
||||
@@ -183,6 +183,7 @@ export class ClineHandler implements ApiHandler {
|
||||
throw new Error("Unauthorized: Please sign in to Cline before trying again.")
|
||||
}
|
||||
console.error("Cline API Error:", error)
|
||||
throw error instanceof Error ? error : new Error(String(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user