Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ describe("VirtualQuotaFallbackProvider", () => {
id: "",
info: {
maxTokens: 1,
contextWindow: 1,
contextWindow: 1000000,
supportsPromptCache: false,
},
})
Expand Down
24 changes: 16 additions & 8 deletions src/api/providers/virtual-quota-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,21 @@ export class VirtualQuotaFallbackHandler extends EventEmitter implements ApiHand
yield chunk
}
} catch (error) {
// Check if this is a retryable
// Check if this is a retryable error (rate limit or overload)
if (this.isRateLimitError(error) || this.isOverloadError(error)) {
// Set cooldown for the current provider
await this.usage.setCooldown(this.activeProfileId, 10 * 60 * 1000)
// Set a short cooldown (10 seconds) to prevent rapid cycling
await this.usage.setCooldown(this.activeProfileId, 10 * 1000)

// Switch to a different provider
// Switch to a different provider and retry
await this.adjustActiveHandler("Retryable Error")

// Retry the request with the new provider
yield* this.createMessage(systemPrompt, messages, metadata)
return
}

// For non-rate limit errors, set cooldown and rethrow
await this.usage.setCooldown(this.activeProfileId, 10 * 60 * 1000)
// For non-retryable errors, set cooldown and rethrow
await this.usage.setCooldown(this.activeProfileId, 10 * 1000)
throw error
}
} catch (error) {
Expand All @@ -130,17 +130,25 @@ export class VirtualQuotaFallbackHandler extends EventEmitter implements ApiHand
id: "",
info: {
maxTokens: 1,
contextWindow: 1,
contextWindow: 1000000,
supportsPromptCache: false,
},
}
}
return this.activeHandler.getModel()
}

getActiveProfileNumber(): number | undefined {
if (!this.activeProfileId) {
return undefined
}
const index = this.handlerConfigs.findIndex((c) => c.profileId === this.activeProfileId)
return index >= 0 ? index + 1 : undefined
}

get contextWindow(): number {
if (!this.activeHandler) {
return 1 // Default fallback
return 1000000 // Default fallback
}
const model = this.activeHandler.getModel()
return model.info.contextWindow
Expand Down
9 changes: 8 additions & 1 deletion src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import { t } from "../../i18n"

import { buildApiHandler } from "../../api"
import { forceFullModelDetailsLoad, hasLoadedFullDetails } from "../../api/providers/fetchers/lmstudio"
import { VirtualQuotaFallbackHandler } from "../../api/providers/virtual-quota-fallback"

import { ContextProxy } from "../config/ContextProxy"
import { getEnabledRules } from "./kilorules"
Expand Down Expand Up @@ -2190,7 +2191,13 @@ export class ClineProvider
// kilocode_change start: Get active model for virtual quota fallback UI display
const virtualQuotaActiveModel =
apiConfiguration?.apiProvider === "virtual-quota-fallback" && this.getCurrentTask()
? this.getCurrentTask()!.api.getModel()
? {
...this.getCurrentTask()!.api.getModel(),
activeProfileNumber:
this.getCurrentTask()!.api instanceof VirtualQuotaFallbackHandler
? (this.getCurrentTask()!.api as VirtualQuotaFallbackHandler).getActiveProfileNumber()
: undefined,
}
: undefined
// kilocode_change end

Expand Down
2 changes: 1 addition & 1 deletion src/shared/ExtensionMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ export type ExtensionState = Pick<
remoteControlEnabled: boolean
taskSyncEnabled: boolean
featureRoomoteControlEnabled: boolean
virtualQuotaActiveModel?: { id: string; info: ModelInfo } // kilocode_change: Add virtual quota active model for UI display
virtualQuotaActiveModel?: { id: string; info: ModelInfo; activeProfileNumber?: number } // kilocode_change: Add virtual quota active model for UI display with profile number
showTimestamps?: boolean // kilocode_change: Show timestamps in chat messages
claudeCodeIsAuthenticated?: boolean
debug?: boolean
Expand Down
6 changes: 5 additions & 1 deletion webview-ui/src/components/kilocode/BottomApiConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export const BottomApiConfig = () => {
//kilocode_change: Pass virtual quota active model to ModelSelector
virtualQuotaActiveModel={
virtualQuotaActiveModel
? { id: virtualQuotaActiveModel.id, name: virtualQuotaActiveModel.id }
? {
id: virtualQuotaActiveModel.id,
name: virtualQuotaActiveModel.id,
activeProfileNumber: virtualQuotaActiveModel.activeProfileNumber,
}
: undefined
}
/>
Expand Down
5 changes: 4 additions & 1 deletion webview-ui/src/components/kilocode/chat/ModelSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface ModelSelectorProps {
currentApiConfigName?: string
apiConfiguration: ProviderSettings
fallbackText: string
virtualQuotaActiveModel?: { id: string; name: string } // kilocode_change: Add virtual quota active model for UI display
virtualQuotaActiveModel?: { id: string; name: string; activeProfileNumber?: number } // kilocode_change: Add virtual quota active model for UI display
}

export const ModelSelector = ({
Expand Down Expand Up @@ -123,6 +123,9 @@ export const ModelSelector = ({
return (
<span className="text-xs text-vscode-descriptionForeground opacity-70 truncate">
{prettyModelName(virtualQuotaActiveModel.id)}
{virtualQuotaActiveModel.activeProfileNumber !== undefined && (
<> ({virtualQuotaActiveModel.activeProfileNumber})</>
)}
</span>
)
}
Expand Down