From 3d0fc3ccc5aa5829b9e189d5b844727cc337bf27 Mon Sep 17 00:00:00 2001 From: Chris Estreich Date: Thu, 27 Mar 2025 21:12:55 -0700 Subject: [PATCH] Add config getters to RooCodeAPI (#2048) --- .changeset/two-months-drop.md | 5 +++++ src/core/webview/ClineProvider.ts | 19 +++++++++--------- .../webview/__tests__/ClineProvider.test.ts | 10 +++++----- src/exports/api.ts | 12 +++++++++++ src/exports/interface.ts | 20 +++++++++++++++++++ src/exports/roo-code.d.ts | 17 ++++++++++++++++ 6 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 .changeset/two-months-drop.md diff --git a/.changeset/two-months-drop.md b/.changeset/two-months-drop.md new file mode 100644 index 0000000000..59c5cdfce6 --- /dev/null +++ b/.changeset/two-months-drop.md @@ -0,0 +1,5 @@ +--- +"roo-cline": patch +--- + +Add config getters to RooCodeAPI diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index baa10b24a5..021f95adf5 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -12,7 +12,6 @@ import * as vscode from "vscode" import { CheckpointStorage, GlobalState, - SecretState, Language, ProviderSettings, RooCodeSettings, @@ -2802,27 +2801,29 @@ export class ClineProvider extends EventEmitter implements return history } - // global + // ContextProxy - public async updateGlobalState(key: K, value: GlobalState[K]) { + // @deprecated - Use `ContextProxy#setValue` instead. + private async updateGlobalState(key: K, value: GlobalState[K]) { await this.contextProxy.setValue(key, value) } - public getGlobalState(key: K) { + // @deprecated - Use `ContextProxy#getValue` instead. + private getGlobalState(key: K) { return this.contextProxy.getValue(key) } - // secrets - - public async storeSecret(key: keyof SecretState, value?: string) { + public async setValue(key: K, value: RooCodeSettings[K]) { await this.contextProxy.setValue(key, value) } - private getSecret(key: keyof SecretState) { + public getValue(key: K) { return this.contextProxy.getValue(key) } - // global + secret + public getValues() { + return this.contextProxy.getValues() + } public async setValues(values: RooCodeSettings) { await this.contextProxy.setValues(values) diff --git a/src/core/webview/__tests__/ClineProvider.test.ts b/src/core/webview/__tests__/ClineProvider.test.ts index 728daaa3d0..5c859568eb 100644 --- a/src/core/webview/__tests__/ClineProvider.test.ts +++ b/src/core/webview/__tests__/ClineProvider.test.ts @@ -630,7 +630,7 @@ describe("ClineProvider", () => { setModeConfig: jest.fn(), } as any - provider.updateGlobalState("currentApiConfigName", "current-config") + provider.setValue("currentApiConfigName", "current-config") // Switch to architect mode await messageHandler({ type: "mode", text: "architect" }) @@ -759,7 +759,7 @@ describe("ClineProvider", () => { }, } - provider.updateGlobalState("customModePrompts", existingPrompts) + provider.setValue("customModePrompts", existingPrompts) // Test updating a prompt await messageHandler({ @@ -2159,19 +2159,19 @@ describe.skip("ContextProxy integration", () => { }) test("updateGlobalState uses contextProxy", async () => { - await provider.updateGlobalState("currentApiConfigName", "testValue") + await provider.setValue("currentApiConfigName", "testValue") expect(mockContextProxy.updateGlobalState).toHaveBeenCalledWith("currentApiConfigName", "testValue") }) test("getGlobalState uses contextProxy", async () => { mockContextProxy.getGlobalState.mockResolvedValueOnce("testValue") - const result = await provider.getGlobalState("currentApiConfigName") + const result = await provider.getValue("currentApiConfigName") expect(mockContextProxy.getGlobalState).toHaveBeenCalledWith("currentApiConfigName") expect(result).toBe("testValue") }) test("storeSecret uses contextProxy", async () => { - await provider.storeSecret("apiKey", "test-secret") + await provider.setValue("apiKey", "test-secret") expect(mockContextProxy.storeSecret).toHaveBeenCalledWith("apiKey", "test-secret") }) diff --git a/src/exports/api.ts b/src/exports/api.ts index 488f6884a2..9794d89028 100644 --- a/src/exports/api.ts +++ b/src/exports/api.ts @@ -78,10 +78,22 @@ export class API extends EventEmitter implements RooCodeAPI { await this.provider.postMessageToWebview({ type: "invoke", invoke: "secondaryButtonClick" }) } + public getConfiguration() { + return this.provider.getValues() + } + + public getConfigurationValue(key: K) { + return this.provider.getValue(key) + } + public async setConfiguration(values: RooCodeSettings) { await this.provider.setValues(values) } + public async setConfigurationValue(key: K, value: RooCodeSettings[K]) { + await this.provider.setValue(key, value) + } + public isReady() { return this.provider.viewLaunched } diff --git a/src/exports/interface.ts b/src/exports/interface.ts index e8abe8e379..de1f7ea15c 100644 --- a/src/exports/interface.ts +++ b/src/exports/interface.ts @@ -61,12 +61,32 @@ export interface RooCodeAPI extends EventEmitter { */ pressSecondaryButton(): Promise + /** + * Returns the current configuration. + * @returns The current configuration. + */ + getConfiguration(): RooCodeSettings + + /** + * Returns the value of a configuration key. + * @param key The key of the configuration value to return. + * @returns The value of the configuration key. + */ + getConfigurationValue(key: K): RooCodeSettings[K] + /** * Sets the configuration for the current task. * @param values An object containing key-value pairs to set. */ setConfiguration(values: RooCodeSettings): Promise + /** + * Sets the value of a configuration key. + * @param key The key of the configuration value to set. + * @param value The value to set. + */ + setConfigurationValue(key: K, value: RooCodeSettings[K]): Promise + /** * Returns true if the API is ready to use. */ diff --git a/src/exports/roo-code.d.ts b/src/exports/roo-code.d.ts index 5508d30160..12e86be8fd 100644 --- a/src/exports/roo-code.d.ts +++ b/src/exports/roo-code.d.ts @@ -452,11 +452,28 @@ interface RooCodeAPI extends EventEmitter { * Simulates pressing the secondary button in the chat interface. */ pressSecondaryButton(): Promise + /** + * Returns the current configuration. + * @returns The current configuration. + */ + getConfiguration(): RooCodeSettings + /** + * Returns the value of a configuration key. + * @param key The key of the configuration value to return. + * @returns The value of the configuration key. + */ + getConfigurationValue(key: K): RooCodeSettings[K] /** * Sets the configuration for the current task. * @param values An object containing key-value pairs to set. */ setConfiguration(values: RooCodeSettings): Promise + /** + * Sets the value of a configuration key. + * @param key The key of the configuration value to set. + * @param value The value to set. + */ + setConfigurationValue(key: K, value: RooCodeSettings[K]): Promise /** * Returns true if the API is ready to use. */