Просмотр исходного кода

Add config getters to RooCodeAPI (#2048)

Chris Estreich 9 месяцев назад
Родитель
Сommit
3d0fc3ccc5

+ 5 - 0
.changeset/two-months-drop.md

@@ -0,0 +1,5 @@
+---
+"roo-cline": patch
+---
+
+Add config getters to RooCodeAPI

+ 10 - 9
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<ClineProviderEvents> implements
 		return history
 	}
 
-	// global
+	// ContextProxy
 
-	public async updateGlobalState<K extends keyof GlobalState>(key: K, value: GlobalState[K]) {
+	// @deprecated - Use `ContextProxy#setValue` instead.
+	private async updateGlobalState<K extends keyof GlobalState>(key: K, value: GlobalState[K]) {
 		await this.contextProxy.setValue(key, value)
 	}
 
-	public getGlobalState<K extends keyof GlobalState>(key: K) {
+	// @deprecated - Use `ContextProxy#getValue` instead.
+	private getGlobalState<K extends keyof GlobalState>(key: K) {
 		return this.contextProxy.getValue(key)
 	}
 
-	// secrets
-
-	public async storeSecret(key: keyof SecretState, value?: string) {
+	public async setValue<K extends keyof RooCodeSettings>(key: K, value: RooCodeSettings[K]) {
 		await this.contextProxy.setValue(key, value)
 	}
 
-	private getSecret(key: keyof SecretState) {
+	public getValue<K extends keyof RooCodeSettings>(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)

+ 5 - 5
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")
 	})
 

+ 12 - 0
src/exports/api.ts

@@ -78,10 +78,22 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
 		await this.provider.postMessageToWebview({ type: "invoke", invoke: "secondaryButtonClick" })
 	}
 
+	public getConfiguration() {
+		return this.provider.getValues()
+	}
+
+	public getConfigurationValue<K extends keyof RooCodeSettings>(key: K) {
+		return this.provider.getValue(key)
+	}
+
 	public async setConfiguration(values: RooCodeSettings) {
 		await this.provider.setValues(values)
 	}
 
+	public async setConfigurationValue<K extends keyof RooCodeSettings>(key: K, value: RooCodeSettings[K]) {
+		await this.provider.setValue(key, value)
+	}
+
 	public isReady() {
 		return this.provider.viewLaunched
 	}

+ 20 - 0
src/exports/interface.ts

@@ -61,12 +61,32 @@ export interface RooCodeAPI extends EventEmitter<RooCodeEvents> {
 	 */
 	pressSecondaryButton(): Promise<void>
 
+	/**
+	 * 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<K extends keyof RooCodeSettings>(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<void>
 
+	/**
+	 * Sets the value of a configuration key.
+	 * @param key The key of the configuration value to set.
+	 * @param value The value to set.
+	 */
+	setConfigurationValue<K extends keyof RooCodeSettings>(key: K, value: RooCodeSettings[K]): Promise<void>
+
 	/**
 	 * Returns true if the API is ready to use.
 	 */

+ 17 - 0
src/exports/roo-code.d.ts

@@ -452,11 +452,28 @@ interface RooCodeAPI extends EventEmitter<RooCodeEvents> {
 	 * Simulates pressing the secondary button in the chat interface.
 	 */
 	pressSecondaryButton(): Promise<void>
+	/**
+	 * 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<K extends keyof RooCodeSettings>(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<void>
+	/**
+	 * Sets the value of a configuration key.
+	 * @param key The key of the configuration value to set.
+	 * @param value The value to set.
+	 */
+	setConfigurationValue<K extends keyof RooCodeSettings>(key: K, value: RooCodeSettings[K]): Promise<void>
 	/**
 	 * Returns true if the API is ready to use.
 	 */