Skip to content

Commit 2d162d6

Browse files
committed
fix(provider): sync view-local state when activating provider profile
1 parent e0052db commit 2d162d6

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
@@ -1038,6 +1038,37 @@ describe("ClineProvider - Parallel Mode Support", () => {
10381038
})
10391039
})
10401040

1041+
describe("provider profile activation", () => {
1042+
it("should sync view-local apiConfiguration when activating an upserted profile", async () => {
1043+
const provider = new ClineProvider(mockContext, mockOutputChannel, "sidebar", new ContextProxy(mockContext))
1044+
await (provider as any).saveViewState("apiConfiguration", {
1045+
apiProvider: "openrouter",
1046+
openRouterModelId: "openai/gpt-4.1",
1047+
})
1048+
1049+
const providerSettings = {
1050+
apiProvider: "zai" as const,
1051+
zaiApiKey: "mock-key",
1052+
zaiApiLine: "international_api" as const,
1053+
apiModelId: "glm-5.1",
1054+
}
1055+
vi.spyOn(provider.providerSettingsManager, "saveConfig").mockResolvedValue("zai-profile-id")
1056+
vi.spyOn(provider.providerSettingsManager, "listConfig").mockResolvedValue([
1057+
{ name: "default", id: "zai-profile-id", apiProvider: "zai" },
1058+
])
1059+
1060+
await provider.upsertProviderProfile("default", providerSettings, true)
1061+
1062+
const state = await provider.getState()
1063+
expect(state.currentApiConfigName).toBe("default")
1064+
expect(state.apiConfiguration).toMatchObject(providerSettings)
1065+
expect(state.apiConfiguration.apiProvider).toBe("zai")
1066+
expect((provider as any).viewLocalState.apiConfiguration).toMatchObject(providerSettings)
1067+
1068+
await provider.dispose()
1069+
})
1070+
})
1071+
10411072
describe("handleModeSwitch integration", () => {
10421073
it("should update viewLocalState.mode when handleModeSwitch is called", async () => {
10431074
const postMessage = vi.fn()

0 commit comments

Comments
 (0)