Skip to content

Commit 78be287

Browse files
migrate plan/act state to workspace storage (RooCodeInc#4130)
1 parent 02f016c commit 78be287

File tree

7 files changed

+250
-166
lines changed

7 files changed

+250
-166
lines changed

src/core/controller/index.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class Controller {
114114
try {
115115
await storeSecret(this.context, "clineApiKey", undefined)
116116
await updateGlobalState(this.context, "userInfo", undefined)
117-
await updateGlobalState(this.context, "apiProvider", "openrouter")
117+
await updateWorkspaceState(this.context, "apiProvider", "openrouter")
118118
await this.postStateToWebview()
119119
vscode.window.showInformationMessage("Successfully logged out of Cline")
120120
} catch (error) {
@@ -297,9 +297,9 @@ export class Controller {
297297

298298
if (shouldSwitchModel) {
299299
// Save the last model used in this mode
300-
await updateGlobalState(this.context, "previousModeApiProvider", apiConfiguration.apiProvider)
301-
await updateGlobalState(this.context, "previousModeThinkingBudgetTokens", apiConfiguration.thinkingBudgetTokens)
302-
await updateGlobalState(this.context, "previousModeReasoningEffort", apiConfiguration.reasoningEffort)
300+
await updateWorkspaceState(this.context, "previousModeApiProvider", apiConfiguration.apiProvider)
301+
await updateWorkspaceState(this.context, "previousModeThinkingBudgetTokens", apiConfiguration.thinkingBudgetTokens)
302+
await updateWorkspaceState(this.context, "previousModeReasoningEffort", apiConfiguration.reasoningEffort)
303303
switch (apiConfiguration.apiProvider) {
304304
case "anthropic":
305305
case "vertex":
@@ -309,51 +309,51 @@ export class Controller {
309309
case "qwen":
310310
case "deepseek":
311311
case "xai":
312-
await updateGlobalState(this.context, "previousModeModelId", apiConfiguration.apiModelId)
312+
await updateWorkspaceState(this.context, "previousModeModelId", apiConfiguration.apiModelId)
313313
break
314314
case "bedrock":
315-
await updateGlobalState(this.context, "previousModeModelId", apiConfiguration.apiModelId)
316-
await updateGlobalState(
315+
await updateWorkspaceState(this.context, "previousModeModelId", apiConfiguration.apiModelId)
316+
await updateWorkspaceState(
317317
this.context,
318318
"previousModeAwsBedrockCustomSelected",
319319
apiConfiguration.awsBedrockCustomSelected,
320320
)
321-
await updateGlobalState(
321+
await updateWorkspaceState(
322322
this.context,
323323
"previousModeAwsBedrockCustomModelBaseId",
324324
apiConfiguration.awsBedrockCustomModelBaseId,
325325
)
326326
break
327327
case "openrouter":
328328
case "cline":
329-
await updateGlobalState(this.context, "previousModeModelId", apiConfiguration.openRouterModelId)
330-
await updateGlobalState(this.context, "previousModeModelInfo", apiConfiguration.openRouterModelInfo)
329+
await updateWorkspaceState(this.context, "previousModeModelId", apiConfiguration.openRouterModelId)
330+
await updateWorkspaceState(this.context, "previousModeModelInfo", apiConfiguration.openRouterModelInfo)
331331
break
332332
case "vscode-lm":
333333
// Important we don't set modelId to this, as it's an object not string (webview expects model id to be a string)
334-
await updateGlobalState(
334+
await updateWorkspaceState(
335335
this.context,
336336
"previousModeVsCodeLmModelSelector",
337337
apiConfiguration.vsCodeLmModelSelector,
338338
)
339339
break
340340
case "openai":
341-
await updateGlobalState(this.context, "previousModeModelId", apiConfiguration.openAiModelId)
342-
await updateGlobalState(this.context, "previousModeModelInfo", apiConfiguration.openAiModelInfo)
341+
await updateWorkspaceState(this.context, "previousModeModelId", apiConfiguration.openAiModelId)
342+
await updateWorkspaceState(this.context, "previousModeModelInfo", apiConfiguration.openAiModelInfo)
343343
break
344344
case "ollama":
345-
await updateGlobalState(this.context, "previousModeModelId", apiConfiguration.ollamaModelId)
345+
await updateWorkspaceState(this.context, "previousModeModelId", apiConfiguration.ollamaModelId)
346346
break
347347
case "lmstudio":
348-
await updateGlobalState(this.context, "previousModeModelId", apiConfiguration.lmStudioModelId)
348+
await updateWorkspaceState(this.context, "previousModeModelId", apiConfiguration.lmStudioModelId)
349349
break
350350
case "litellm":
351-
await updateGlobalState(this.context, "previousModeModelId", apiConfiguration.liteLlmModelId)
352-
await updateGlobalState(this.context, "previousModeModelInfo", apiConfiguration.liteLlmModelInfo)
351+
await updateWorkspaceState(this.context, "previousModeModelId", apiConfiguration.liteLlmModelId)
352+
await updateWorkspaceState(this.context, "previousModeModelInfo", apiConfiguration.liteLlmModelInfo)
353353
break
354354
case "requesty":
355-
await updateGlobalState(this.context, "previousModeModelId", apiConfiguration.requestyModelId)
356-
await updateGlobalState(this.context, "previousModeModelInfo", apiConfiguration.requestyModelInfo)
355+
await updateWorkspaceState(this.context, "previousModeModelId", apiConfiguration.requestyModelId)
356+
await updateWorkspaceState(this.context, "previousModeModelInfo", apiConfiguration.requestyModelInfo)
357357
break
358358
}
359359

@@ -365,9 +365,9 @@ export class Controller {
365365
newReasoningEffort ||
366366
newVsCodeLmModelSelector
367367
) {
368-
await updateGlobalState(this.context, "apiProvider", newApiProvider)
369-
await updateGlobalState(this.context, "thinkingBudgetTokens", newThinkingBudgetTokens)
370-
await updateGlobalState(this.context, "reasoningEffort", newReasoningEffort)
368+
await updateWorkspaceState(this.context, "apiProvider", newApiProvider)
369+
await updateWorkspaceState(this.context, "thinkingBudgetTokens", newThinkingBudgetTokens)
370+
await updateWorkspaceState(this.context, "reasoningEffort", newReasoningEffort)
371371
switch (newApiProvider) {
372372
case "anthropic":
373373
case "vertex":
@@ -377,38 +377,38 @@ export class Controller {
377377
case "qwen":
378378
case "deepseek":
379379
case "xai":
380-
await updateGlobalState(this.context, "apiModelId", newModelId)
380+
await updateWorkspaceState(this.context, "apiModelId", newModelId)
381381
break
382382
case "bedrock":
383-
await updateGlobalState(this.context, "apiModelId", newModelId)
384-
await updateGlobalState(this.context, "awsBedrockCustomSelected", newAwsBedrockCustomSelected)
385-
await updateGlobalState(this.context, "awsBedrockCustomModelBaseId", newAwsBedrockCustomModelBaseId)
383+
await updateWorkspaceState(this.context, "apiModelId", newModelId)
384+
await updateWorkspaceState(this.context, "awsBedrockCustomSelected", newAwsBedrockCustomSelected)
385+
await updateWorkspaceState(this.context, "awsBedrockCustomModelBaseId", newAwsBedrockCustomModelBaseId)
386386
break
387387
case "openrouter":
388388
case "cline":
389-
await updateGlobalState(this.context, "openRouterModelId", newModelId)
390-
await updateGlobalState(this.context, "openRouterModelInfo", newModelInfo)
389+
await updateWorkspaceState(this.context, "openRouterModelId", newModelId)
390+
await updateWorkspaceState(this.context, "openRouterModelInfo", newModelInfo)
391391
break
392392
case "vscode-lm":
393-
await updateGlobalState(this.context, "vsCodeLmModelSelector", newVsCodeLmModelSelector)
393+
await updateWorkspaceState(this.context, "vsCodeLmModelSelector", newVsCodeLmModelSelector)
394394
break
395395
case "openai":
396-
await updateGlobalState(this.context, "openAiModelId", newModelId)
397-
await updateGlobalState(this.context, "openAiModelInfo", newModelInfo)
396+
await updateWorkspaceState(this.context, "openAiModelId", newModelId)
397+
await updateWorkspaceState(this.context, "openAiModelInfo", newModelInfo)
398398
break
399399
case "ollama":
400-
await updateGlobalState(this.context, "ollamaModelId", newModelId)
400+
await updateWorkspaceState(this.context, "ollamaModelId", newModelId)
401401
break
402402
case "lmstudio":
403-
await updateGlobalState(this.context, "lmStudioModelId", newModelId)
403+
await updateWorkspaceState(this.context, "lmStudioModelId", newModelId)
404404
break
405405
case "litellm":
406-
await updateGlobalState(this.context, "previousModeModelId", apiConfiguration.liteLlmModelId)
407-
await updateGlobalState(this.context, "previousModeModelInfo", apiConfiguration.liteLlmModelInfo)
406+
await updateWorkspaceState(this.context, "previousModeModelId", apiConfiguration.liteLlmModelId)
407+
await updateWorkspaceState(this.context, "previousModeModelInfo", apiConfiguration.liteLlmModelInfo)
408408
break
409409
case "requesty":
410-
await updateGlobalState(this.context, "requestyModelId", newModelId)
411-
await updateGlobalState(this.context, "requestyModelInfo", newModelInfo)
410+
await updateWorkspaceState(this.context, "requestyModelId", newModelId)
411+
await updateWorkspaceState(this.context, "requestyModelInfo", newModelInfo)
412412
break
413413
}
414414

@@ -419,7 +419,7 @@ export class Controller {
419419
}
420420
}
421421

422-
await updateGlobalState(this.context, "chatSettings", chatSettings)
422+
await updateWorkspaceState(this.context, "chatSettings", chatSettings)
423423
await this.postStateToWebview()
424424

425425
if (this.task) {
@@ -510,7 +510,7 @@ export class Controller {
510510
await sendAuthCallbackEvent(customToken)
511511

512512
const clineProvider: ApiProvider = "cline"
513-
await updateGlobalState(this.context, "apiProvider", clineProvider)
513+
await updateWorkspaceState(this.context, "apiProvider", clineProvider)
514514

515515
// Update API configuration with the new provider and API key
516516
const { apiConfiguration } = await getAllExtensionState(this.context)
@@ -669,7 +669,7 @@ export class Controller {
669669
}
670670

671671
const openrouter: ApiProvider = "openrouter"
672-
await updateGlobalState(this.context, "apiProvider", openrouter)
672+
await updateWorkspaceState(this.context, "apiProvider", openrouter)
673673
await storeSecret(this.context, "openRouterApiKey", apiKey)
674674
await this.postStateToWebview()
675675
if (this.task) {

src/core/controller/ui/initializeWebview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Controller } from "../index"
22
import { EmptyRequest, Empty } from "@shared/proto/common"
33
import { handleModelsServiceRequest } from "../models"
4-
import { getAllExtensionState, getGlobalState, updateGlobalState } from "../../storage/state"
4+
import { getAllExtensionState, getGlobalState, updateWorkspaceState } from "../../storage/state"
55
import { sendOpenRouterModelsEvent } from "../models/subscribeToOpenRouterModels"
66
import { sendMcpMarketplaceCatalogEvent } from "../mcp/subscribeToMcpMarketplaceCatalog"
77
import { telemetryService } from "@/services/posthog/telemetry/TelemetryService"
@@ -32,7 +32,7 @@ export async function initializeWebview(controller: Controller, request: EmptyRe
3232
// Update model info in state (this needs to be done here since we don't want to update state while settings is open, and we may refresh models there)
3333
const { apiConfiguration } = await getAllExtensionState(controller.context)
3434
if (apiConfiguration.openRouterModelId && response.models[apiConfiguration.openRouterModelId]) {
35-
await updateGlobalState(
35+
await updateWorkspaceState(
3636
controller.context,
3737
"openRouterModelInfo",
3838
response.models[apiConfiguration.openRouterModelId],

src/core/storage/state-keys.ts

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@ export type SecretKey =
2424
| "cerebrasApiKey"
2525

2626
export type GlobalStateKey =
27-
| "apiProvider"
28-
| "apiModelId"
2927
| "awsRegion"
3028
| "awsUseCrossRegionInference"
3129
| "awsBedrockUsePromptCache"
3230
| "awsBedrockEndpoint"
3331
| "awsProfile"
3432
| "awsUseProfile"
35-
| "awsBedrockCustomSelected"
36-
| "awsBedrockCustomModelBaseId"
3733
| "vertexProjectId"
3834
| "vertexRegion"
3935
| "lastShownAnnouncementId"
@@ -43,48 +39,27 @@ export type GlobalStateKey =
4339
| "openAiModelId"
4440
| "openAiModelInfo"
4541
| "openAiHeaders"
46-
| "ollamaModelId"
4742
| "ollamaBaseUrl"
4843
| "ollamaApiOptionsCtxNum"
4944
| "lmStudioModelId"
5045
| "lmStudioBaseUrl"
5146
| "anthropicBaseUrl"
5247
| "geminiBaseUrl"
5348
| "azureApiVersion"
54-
| "openRouterModelId"
55-
| "openRouterModelInfo"
5649
| "openRouterProviderSorting"
5750
| "autoApprovalSettings"
5851
| "globalClineRulesToggles"
5952
| "globalWorkflowToggles"
6053
| "browserSettings"
61-
| "chatSettings"
62-
| "vsCodeLmModelSelector"
6354
| "userInfo"
64-
| "previousModeApiProvider"
65-
| "previousModeModelId"
66-
| "previousModeThinkingBudgetTokens"
67-
| "previousModeReasoningEffort"
68-
| "previousModeVsCodeLmModelSelector"
69-
| "previousModeAwsBedrockCustomSelected"
70-
| "previousModeAwsBedrockCustomModelBaseId"
71-
| "previousModeModelInfo"
7255
| "liteLlmBaseUrl"
73-
| "liteLlmModelId"
74-
| "liteLlmModelInfo"
7556
| "liteLlmUsePromptCache"
76-
| "fireworksModelId"
7757
| "fireworksModelMaxCompletionTokens"
7858
| "fireworksModelMaxTokens"
7959
| "qwenApiLine"
80-
| "requestyModelId"
81-
| "requestyModelInfo"
82-
| "togetherModelId"
8360
| "mcpMarketplaceCatalog"
8461
| "telemetrySetting"
8562
| "asksageApiUrl"
86-
| "thinkingBudgetTokens"
87-
| "reasoningEffort"
8863
| "planActSeparateModelsSetting"
8964
| "enableCheckpointsSetting"
9065
| "mcpMarketplaceEnabled"
@@ -95,4 +70,35 @@ export type GlobalStateKey =
9570
| "terminalReuseEnabled"
9671
| "isNewUser"
9772

98-
export type LocalStateKey = "localClineRulesToggles"
73+
export type LocalStateKey =
74+
| "localClineRulesToggles"
75+
| "chatSettings"
76+
// Current active model configuration (per workspace)
77+
| "apiProvider"
78+
| "apiModelId"
79+
| "thinkingBudgetTokens"
80+
| "reasoningEffort"
81+
| "vsCodeLmModelSelector"
82+
| "awsBedrockCustomSelected"
83+
| "awsBedrockCustomModelBaseId"
84+
| "openRouterModelId"
85+
| "openRouterModelInfo"
86+
| "openAiModelId"
87+
| "openAiModelInfo"
88+
| "ollamaModelId"
89+
| "lmStudioModelId"
90+
| "liteLlmModelId"
91+
| "liteLlmModelInfo"
92+
| "requestyModelId"
93+
| "requestyModelInfo"
94+
| "togetherModelId"
95+
| "fireworksModelId"
96+
// Previous mode saved configurations (per workspace)
97+
| "previousModeApiProvider"
98+
| "previousModeModelId"
99+
| "previousModeModelInfo"
100+
| "previousModeVsCodeLmModelSelector"
101+
| "previousModeThinkingBudgetTokens"
102+
| "previousModeReasoningEffort"
103+
| "previousModeAwsBedrockCustomSelected"
104+
| "previousModeAwsBedrockCustomModelBaseId"

0 commit comments

Comments
 (0)