Skip to content

Commit ca36ab4

Browse files
committed
More fixes
1 parent f0286cc commit ca36ab4

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

src/core/config/ProviderSettingsManager.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,7 @@ export class ProviderSettingsManager {
258258
}
259259
}
260260

261-
/**
262-
* Activate a profile by name or ID.
263-
*/
264-
public async activateProfile(
265-
params: { name: string } | { id: string },
266-
): Promise<ProviderSettingsWithId & { name: string }> {
261+
public async getProfile(params: { name: string } | { id: string }) {
267262
try {
268263
return await this.lock(async () => {
269264
const providerProfiles = await this.load()
@@ -293,13 +288,30 @@ export class ProviderSettingsManager {
293288
providerSettings = entry[1]
294289
}
295290

291+
return { name, ...providerSettings }
292+
})
293+
} catch (error) {
294+
throw new Error(`Failed to get profile profile: ${error}`)
295+
}
296+
}
297+
298+
/**
299+
* Activate a profile by name or ID.
300+
*/
301+
public async activateProfile(
302+
params: { name: string } | { id: string },
303+
): Promise<ProviderSettingsWithId & { name: string }> {
304+
const { name, ...providerSettings } = await this.getProfile(params)
305+
306+
try {
307+
return await this.lock(async () => {
308+
const providerProfiles = await this.load()
296309
providerProfiles.currentApiConfigName = name
297310
await this.store(providerProfiles)
298-
299311
return { name, ...providerSettings }
300312
})
301313
} catch (error) {
302-
throw new Error(`Failed to load config: ${error}`)
314+
throw new Error(`Failed to activate profile profile: ${error}`)
303315
}
304316
}
305317

src/core/webview/ClineProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,9 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
808808
await Promise.all([
809809
this.contextProxy.setValue("listApiConfigMeta", await this.providerSettingsManager.listConfig()),
810810
this.contextProxy.setValue("currentApiConfigName", name),
811-
this.updateApiConfiguration(providerSettings),
812811
])
813812

813+
await this.updateApiConfiguration(providerSettings)
814814
await this.postStateToWebview()
815815
}
816816

src/core/webview/webviewMessageHandler.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import pWaitFor from "p-wait-for"
44
import * as vscode from "vscode"
55

66
import { ClineProvider } from "./ClineProvider"
7-
import { Language, ApiConfigMeta } from "../../schemas"
7+
import { Language, ApiConfigMeta, ProviderSettings } from "../../schemas"
88
import { changeLanguage, t } from "../../i18n"
9-
import { ApiConfiguration, RouterName, toRouterName } from "../../shared/api"
9+
import { RouterName, toRouterName } from "../../shared/api"
1010
import { supportPrompt } from "../../shared/support-prompt"
1111

1212
import { checkoutDiffPayloadSchema, checkoutRestorePayloadSchema, WebviewMessage } from "../../shared/WebviewMessage"
@@ -933,19 +933,18 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
933933
await provider.getState()
934934

935935
// Try to get enhancement config first, fall back to current config.
936-
let configToUse: ApiConfiguration = apiConfiguration
937-
938-
if (enhancementApiConfigId) {
939-
const config = listApiConfigMeta?.find((c: ApiConfigMeta) => c.id === enhancementApiConfigId)
940-
941-
if (config?.name) {
942-
const { name: _, ...loadedConfig } = await provider.providerSettingsManager.activateProfile(
943-
{ name: config.name },
944-
)
936+
let configToUse: ProviderSettings = apiConfiguration
937+
938+
if (
939+
enhancementApiConfigId &&
940+
!!listApiConfigMeta.find((c: ApiConfigMeta) => c.id === enhancementApiConfigId)
941+
) {
942+
const { name: _, ...providerSettings } = await provider.providerSettingsManager.getProfile({
943+
id: enhancementApiConfigId,
944+
})
945945

946-
if (loadedConfig.apiProvider) {
947-
configToUse = loadedConfig
948-
}
946+
if (providerSettings.apiProvider) {
947+
configToUse = providerSettings
949948
}
950949
}
951950

@@ -954,7 +953,7 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
954953
supportPrompt.create("ENHANCE", { userInput: message.text }, customSupportPrompts),
955954
)
956955

957-
// Capture telemetry for prompt enhancement
956+
// Capture telemetry for prompt enhancement.
958957
const currentCline = provider.getCurrentCline()
959958
telemetryService.capturePromptEnhanced(currentCline?.taskId)
960959

0 commit comments

Comments
 (0)