Move rest of state to cache (#5404)
* move rest of state to cacheService * finish moving state to cache * remove console logs * fix types * don't type cast * add eslint rule banning use of direct storage apis * fix types * move vscode state eslint rule to separate rule since it's error and the others aren't * fix eslint rules parsing
This commit is contained in:
1 parent
2aa5156905
commit
669e018b85
52 files changed
+1472
-1096
No files matched your search
@@ -1,7 +1,6 @@
|
||||
import type { Controller } from "../index"
|
||||
import { EmptyRequest, Empty } from "@shared/proto/cline/common"
|
||||
|
||||
import { getAllExtensionState, getGlobalState, updateGlobalState } from "../../storage/state"
|
||||
import { sendOpenRouterModelsEvent } from "../models/subscribeToOpenRouterModels"
|
||||
import { sendMcpMarketplaceCatalogEvent } from "../mcp/subscribeToMcpMarketplaceCatalog"
|
||||
import { telemetryService } from "@/services/posthog/PostHogClientProvider"
|
||||
@@ -31,7 +30,7 @@ export async function initializeWebview(controller: Controller, request: EmptyRe
|
||||
if (response && response.models) {
|
||||
// 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)
|
||||
const apiConfiguration = controller.cacheService.getApiConfiguration()
|
||||
const { planActSeparateModelsSetting } = await getAllExtensionState(controller.context)
|
||||
const planActSeparateModelsSetting = controller.cacheService.getGlobalStateKey("planActSeparateModelsSetting")
|
||||
const currentMode = await controller.getCurrentMode()
|
||||
|
||||
if (planActSeparateModelsSetting) {
|
||||
@@ -77,7 +76,7 @@ export async function initializeWebview(controller: Controller, request: EmptyRe
|
||||
if (response && response.models) {
|
||||
// Update model info in state for Groq (this needs to be done here since we don't want to update state while settings is open, and we may refresh models there)
|
||||
const apiConfiguration = controller.cacheService.getApiConfiguration()
|
||||
const { planActSeparateModelsSetting } = await getAllExtensionState(controller.context)
|
||||
const planActSeparateModelsSetting = controller.cacheService.getGlobalStateKey("planActSeparateModelsSetting")
|
||||
const currentMode = await controller.getCurrentMode()
|
||||
|
||||
if (planActSeparateModelsSetting) {
|
||||
@@ -122,7 +121,9 @@ export async function initializeWebview(controller: Controller, request: EmptyRe
|
||||
refreshBasetenModels(controller, EmptyRequest.create()).then(async (response) => {
|
||||
if (response && response.models) {
|
||||
// Update model info in state for Baseten (this needs to be done here since we don't want to update state while settings is open, and we may refresh models there)
|
||||
const { apiConfiguration, planActSeparateModelsSetting } = await getAllExtensionState(controller.context)
|
||||
const apiConfiguration = controller.cacheService.getApiConfiguration()
|
||||
const planActSeparateModelsSetting = controller.cacheService.getGlobalStateKey("planActSeparateModelsSetting")
|
||||
|
||||
const currentMode = await controller.getCurrentMode()
|
||||
|
||||
if (planActSeparateModelsSetting) {
|
||||
@@ -132,7 +133,7 @@ export async function initializeWebview(controller: Controller, request: EmptyRe
|
||||
const modelId = apiConfiguration[modelIdField]
|
||||
|
||||
if (modelId && response.models[modelId]) {
|
||||
await updateGlobalState(controller.context, modelInfoField, response.models[modelId])
|
||||
controller.cacheService.setGlobalState(modelInfoField, response.models[modelId])
|
||||
await controller.postStateToWebview()
|
||||
}
|
||||
} else {
|
||||
@@ -142,12 +143,12 @@ export async function initializeWebview(controller: Controller, request: EmptyRe
|
||||
|
||||
// Update plan mode model info if we have a model ID
|
||||
if (planModelId && response.models[planModelId]) {
|
||||
await updateGlobalState(controller.context, "planModeBasetenModelInfo", response.models[planModelId])
|
||||
controller.cacheService.setGlobalState("planModeBasetenModelInfo", response.models[planModelId])
|
||||
}
|
||||
|
||||
// Update act mode model info if we have a model ID
|
||||
if (actModelId && response.models[actModelId]) {
|
||||
await updateGlobalState(controller.context, "actModeBasetenModelInfo", response.models[actModelId])
|
||||
controller.cacheService.setGlobalState("actModeBasetenModelInfo", response.models[actModelId])
|
||||
}
|
||||
|
||||
// Post state update if we updated any model info
|
||||
@@ -163,12 +164,12 @@ export async function initializeWebview(controller: Controller, request: EmptyRe
|
||||
// (see normalizeApiConfiguration > openrouter)
|
||||
// Prefetch marketplace and OpenRouter models
|
||||
|
||||
// Send cached MCP marketplace catalog if available
|
||||
getGlobalState(controller.context, "mcpMarketplaceCatalog").then((mcpMarketplaceCatalog) => {
|
||||
if (mcpMarketplaceCatalog) {
|
||||
sendMcpMarketplaceCatalogEvent(mcpMarketplaceCatalog as McpMarketplaceCatalog)
|
||||
}
|
||||
})
|
||||
// Send stored MCP marketplace catalog if available
|
||||
const mcpMarketplaceCatalog = controller.cacheService.getGlobalStateKey("mcpMarketplaceCatalog")
|
||||
|
||||
if (mcpMarketplaceCatalog) {
|
||||
sendMcpMarketplaceCatalogEvent(mcpMarketplaceCatalog as McpMarketplaceCatalog)
|
||||
}
|
||||
|
||||
// Silently refresh MCP marketplace catalog
|
||||
controller.silentlyRefreshMcpMarketplace()
|
||||
|
||||
Reference in new issue
Block a user