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
38 changes: 28 additions & 10 deletions src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
ORGANIZATION_ALLOW_ALL,
DEFAULT_MODES,
DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
getModelId,
} from "@roo-code/types"
import { TelemetryService } from "@roo-code/telemetry"
import { CloudService, BridgeOrchestrator, getRooCodeApiUrl } from "@roo-code/cloud"
Expand Down Expand Up @@ -1295,6 +1296,31 @@ export class ClineProvider

// Provider Profile Management

/**
* Updates the current task's API handler if the provider or model has changed.
* This prevents unnecessary context condensing when only non-model settings change.
* @param providerSettings The new provider settings to apply
*/
private updateTaskApiHandlerIfNeeded(providerSettings: ProviderSettings): void {
const task = this.getCurrentTask()

if (task && task.apiConfiguration) {
// Only rebuild API handler if provider or model actually changed
// to avoid triggering unnecessary context condensing
const currentProvider = task.apiConfiguration.apiProvider
const newProvider = providerSettings.apiProvider
const currentModelId = getModelId(task.apiConfiguration)
const newModelId = getModelId(providerSettings)

if (currentProvider !== newProvider || currentModelId !== newModelId) {
task.api = buildApiHandler(providerSettings)
}
} else if (task) {
// Fallback: rebuild if apiConfiguration is not available
task.api = buildApiHandler(providerSettings)
}
}

getProviderProfileEntries(): ProviderSettingsEntry[] {
return this.contextProxy.getValues().listApiConfigMeta || []
}
Expand Down Expand Up @@ -1342,11 +1368,7 @@ export class ClineProvider

// Change the provider for the current task.
// TODO: We should rename `buildApiHandler` for clarity (e.g. `getProviderClient`).
const task = this.getCurrentTask()

if (task) {
task.api = buildApiHandler(providerSettings)
}
this.updateTaskApiHandlerIfNeeded(providerSettings)
} else {
await this.updateGlobalState("listApiConfigMeta", await this.providerSettingsManager.listConfig())
}
Expand Down Expand Up @@ -1403,11 +1425,7 @@ export class ClineProvider
}

// Change the provider for the current task.
const task = this.getCurrentTask()

if (task) {
task.api = buildApiHandler(providerSettings)
}
this.updateTaskApiHandlerIfNeeded(providerSettings)

await this.postStateToWebview()

Expand Down
Loading