|
|
@@ -6,6 +6,7 @@ import {
|
|
|
GLOBAL_SETTINGS_KEYS,
|
|
|
SECRET_STATE_KEYS,
|
|
|
GLOBAL_STATE_KEYS,
|
|
|
+ GLOBAL_SECRET_KEYS,
|
|
|
type ProviderSettings,
|
|
|
type GlobalSettings,
|
|
|
type SecretState,
|
|
|
@@ -61,19 +62,77 @@ export class ContextProxy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const promises = SECRET_STATE_KEYS.map(async (key) => {
|
|
|
- try {
|
|
|
- this.secretCache[key] = await this.originalContext.secrets.get(key)
|
|
|
- } catch (error) {
|
|
|
- logger.error(`Error loading secret ${key}: ${error instanceof Error ? error.message : String(error)}`)
|
|
|
- }
|
|
|
- })
|
|
|
+ const promises = [
|
|
|
+ ...SECRET_STATE_KEYS.map(async (key) => {
|
|
|
+ try {
|
|
|
+ this.secretCache[key] = await this.originalContext.secrets.get(key)
|
|
|
+ } catch (error) {
|
|
|
+ logger.error(
|
|
|
+ `Error loading secret ${key}: ${error instanceof Error ? error.message : String(error)}`,
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ ...GLOBAL_SECRET_KEYS.map(async (key) => {
|
|
|
+ try {
|
|
|
+ this.secretCache[key] = await this.originalContext.secrets.get(key)
|
|
|
+ } catch (error) {
|
|
|
+ logger.error(
|
|
|
+ `Error loading global secret ${key}: ${error instanceof Error ? error.message : String(error)}`,
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ ]
|
|
|
|
|
|
await Promise.all(promises)
|
|
|
|
|
|
+ // Migration: Check for old nested image generation settings and migrate them
|
|
|
+ await this.migrateImageGenerationSettings()
|
|
|
+
|
|
|
this._isInitialized = true
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Migrates old nested openRouterImageGenerationSettings to the new flattened structure
|
|
|
+ */
|
|
|
+ private async migrateImageGenerationSettings() {
|
|
|
+ try {
|
|
|
+ // Check if there's an old nested structure
|
|
|
+ const oldNestedSettings = this.originalContext.globalState.get<any>("openRouterImageGenerationSettings")
|
|
|
+
|
|
|
+ if (oldNestedSettings && typeof oldNestedSettings === "object") {
|
|
|
+ logger.info("Migrating old nested image generation settings to flattened structure")
|
|
|
+
|
|
|
+ // Migrate the API key if it exists and we don't already have one
|
|
|
+ if (oldNestedSettings.openRouterApiKey && !this.secretCache.openRouterImageApiKey) {
|
|
|
+ await this.originalContext.secrets.store(
|
|
|
+ "openRouterImageApiKey",
|
|
|
+ oldNestedSettings.openRouterApiKey,
|
|
|
+ )
|
|
|
+ this.secretCache.openRouterImageApiKey = oldNestedSettings.openRouterApiKey
|
|
|
+ logger.info("Migrated openRouterImageApiKey to secrets")
|
|
|
+ }
|
|
|
+
|
|
|
+ // Migrate the selected model if it exists and we don't already have one
|
|
|
+ if (oldNestedSettings.selectedModel && !this.stateCache.openRouterImageGenerationSelectedModel) {
|
|
|
+ await this.originalContext.globalState.update(
|
|
|
+ "openRouterImageGenerationSelectedModel",
|
|
|
+ oldNestedSettings.selectedModel,
|
|
|
+ )
|
|
|
+ this.stateCache.openRouterImageGenerationSelectedModel = oldNestedSettings.selectedModel
|
|
|
+ logger.info("Migrated openRouterImageGenerationSelectedModel to global state")
|
|
|
+ }
|
|
|
+
|
|
|
+ // Clean up the old nested structure
|
|
|
+ await this.originalContext.globalState.update("openRouterImageGenerationSettings", undefined)
|
|
|
+ logger.info("Removed old nested openRouterImageGenerationSettings")
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ logger.error(
|
|
|
+ `Error during image generation settings migration: ${error instanceof Error ? error.message : String(error)}`,
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public get extensionUri() {
|
|
|
return this.originalContext.extensionUri
|
|
|
}
|
|
|
@@ -152,20 +211,34 @@ export class ContextProxy {
|
|
|
* This is useful when you need to ensure the cache has the latest values
|
|
|
*/
|
|
|
async refreshSecrets(): Promise<void> {
|
|
|
- const promises = SECRET_STATE_KEYS.map(async (key) => {
|
|
|
- try {
|
|
|
- this.secretCache[key] = await this.originalContext.secrets.get(key)
|
|
|
- } catch (error) {
|
|
|
- logger.error(
|
|
|
- `Error refreshing secret ${key}: ${error instanceof Error ? error.message : String(error)}`,
|
|
|
- )
|
|
|
- }
|
|
|
- })
|
|
|
+ const promises = [
|
|
|
+ ...SECRET_STATE_KEYS.map(async (key) => {
|
|
|
+ try {
|
|
|
+ this.secretCache[key] = await this.originalContext.secrets.get(key)
|
|
|
+ } catch (error) {
|
|
|
+ logger.error(
|
|
|
+ `Error refreshing secret ${key}: ${error instanceof Error ? error.message : String(error)}`,
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ ...GLOBAL_SECRET_KEYS.map(async (key) => {
|
|
|
+ try {
|
|
|
+ this.secretCache[key] = await this.originalContext.secrets.get(key)
|
|
|
+ } catch (error) {
|
|
|
+ logger.error(
|
|
|
+ `Error refreshing global secret ${key}: ${error instanceof Error ? error.message : String(error)}`,
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ ]
|
|
|
await Promise.all(promises)
|
|
|
}
|
|
|
|
|
|
private getAllSecretState(): SecretState {
|
|
|
- return Object.fromEntries(SECRET_STATE_KEYS.map((key) => [key, this.getSecret(key)]))
|
|
|
+ return Object.fromEntries([
|
|
|
+ ...SECRET_STATE_KEYS.map((key) => [key, this.getSecret(key as SecretStateKey)]),
|
|
|
+ ...GLOBAL_SECRET_KEYS.map((key) => [key, this.getSecret(key as SecretStateKey)]),
|
|
|
+ ])
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -232,18 +305,24 @@ export class ContextProxy {
|
|
|
* RooCodeSettings
|
|
|
*/
|
|
|
|
|
|
- public setValue<K extends RooCodeSettingsKey>(key: K, value: RooCodeSettings[K]) {
|
|
|
- return isSecretStateKey(key) ? this.storeSecret(key, value as string) : this.updateGlobalState(key, value)
|
|
|
+ public async setValue<K extends RooCodeSettingsKey>(key: K, value: RooCodeSettings[K]) {
|
|
|
+ return isSecretStateKey(key)
|
|
|
+ ? this.storeSecret(key as SecretStateKey, value as string)
|
|
|
+ : this.updateGlobalState(key as GlobalStateKey, value)
|
|
|
}
|
|
|
|
|
|
public getValue<K extends RooCodeSettingsKey>(key: K): RooCodeSettings[K] {
|
|
|
return isSecretStateKey(key)
|
|
|
- ? (this.getSecret(key) as RooCodeSettings[K])
|
|
|
- : (this.getGlobalState(key) as RooCodeSettings[K])
|
|
|
+ ? (this.getSecret(key as SecretStateKey) as RooCodeSettings[K])
|
|
|
+ : (this.getGlobalState(key as GlobalStateKey) as RooCodeSettings[K])
|
|
|
}
|
|
|
|
|
|
public getValues(): RooCodeSettings {
|
|
|
- return { ...this.getAllGlobalState(), ...this.getAllSecretState() }
|
|
|
+ const globalState = this.getAllGlobalState()
|
|
|
+ const secretState = this.getAllSecretState()
|
|
|
+
|
|
|
+ // Simply merge all states - no nested secrets to handle
|
|
|
+ return { ...globalState, ...secretState }
|
|
|
}
|
|
|
|
|
|
public async setValues(values: RooCodeSettings) {
|
|
|
@@ -285,6 +364,7 @@ export class ContextProxy {
|
|
|
await Promise.all([
|
|
|
...GLOBAL_STATE_KEYS.map((key) => this.originalContext.globalState.update(key, undefined)),
|
|
|
...SECRET_STATE_KEYS.map((key) => this.originalContext.secrets.delete(key)),
|
|
|
+ ...GLOBAL_SECRET_KEYS.map((key) => this.originalContext.secrets.delete(key)),
|
|
|
])
|
|
|
|
|
|
await this.initialize()
|