Skip to content

Commit 554de34

Browse files
committed
fix(provider): sync view-local state when activating provider profile
1 parent dfe4dea commit 554de34

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/core/webview/ClineProvider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,8 @@ export class ClineProvider
17721772
this.updateGlobalState("currentApiConfigName", name),
17731773
this.providerSettingsManager.setModeConfig(mode, id),
17741774
this.contextProxy.setProviderSettings(providerSettings),
1775+
this.saveViewState("currentApiConfigName", name),
1776+
this.saveViewState("apiConfiguration", providerSettings),
17751777
])
17761778

17771779
// Change the provider for the current task.
@@ -1861,6 +1863,8 @@ export class ClineProvider
18611863
this.contextProxy.setValue("listApiConfigMeta", await this.providerSettingsManager.listConfig()),
18621864
this.contextProxy.setValue("currentApiConfigName", name),
18631865
this.contextProxy.setProviderSettings(providerSettings),
1866+
this.saveViewState("currentApiConfigName", name),
1867+
this.saveViewState("apiConfiguration", providerSettings),
18641868
])
18651869

18661870
const { mode } = await this.getState()

src/core/webview/__tests__/ClineProvider.parallelMode.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,37 @@ describe("ClineProvider - Parallel Mode Support", () => {
10221022
})
10231023
})
10241024

1025+
describe("provider profile activation", () => {
1026+
it("should sync view-local apiConfiguration when activating an upserted profile", async () => {
1027+
const provider = new ClineProvider(mockContext, mockOutputChannel, "sidebar", new ContextProxy(mockContext))
1028+
await (provider as any).saveViewState("apiConfiguration", {
1029+
apiProvider: "openrouter",
1030+
openRouterModelId: "openai/gpt-4.1",
1031+
})
1032+
1033+
const providerSettings = {
1034+
apiProvider: "zai" as const,
1035+
zaiApiKey: "mock-key",
1036+
zaiApiLine: "international_api" as const,
1037+
apiModelId: "glm-5.1",
1038+
}
1039+
vi.spyOn(provider.providerSettingsManager, "saveConfig").mockResolvedValue("zai-profile-id")
1040+
vi.spyOn(provider.providerSettingsManager, "listConfig").mockResolvedValue([
1041+
{ name: "default", id: "zai-profile-id", apiProvider: "zai" },
1042+
])
1043+
1044+
await provider.upsertProviderProfile("default", providerSettings, true)
1045+
1046+
const state = await provider.getState()
1047+
expect(state.currentApiConfigName).toBe("default")
1048+
expect(state.apiConfiguration).toMatchObject(providerSettings)
1049+
expect(state.apiConfiguration.apiProvider).toBe("zai")
1050+
expect((provider as any).viewLocalState.apiConfiguration).toMatchObject(providerSettings)
1051+
1052+
await provider.dispose()
1053+
})
1054+
})
1055+
10251056
describe("_clearViewLocalState", () => {
10261057
it("should clear all view-local state values", async () => {
10271058
const provider = new ClineProvider(mockContext, mockOutputChannel, "sidebar", new ContextProxy(mockContext))

0 commit comments

Comments
 (0)