Skip to content

Commit 5286c5d

Browse files
committed
Add config getters to RooCodeAPI
1 parent 7eb469f commit 5286c5d

File tree

6 files changed

+69
-14
lines changed

6 files changed

+69
-14
lines changed

.changeset/two-months-drop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Add config getters to RooCodeAPI

src/core/webview/ClineProvider.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import * as vscode from "vscode"
1212
import {
1313
CheckpointStorage,
1414
GlobalState,
15-
SecretState,
1615
Language,
1716
ProviderSettings,
1817
RooCodeSettings,
@@ -2802,27 +2801,29 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
28022801
return history
28032802
}
28042803

2805-
// global
2804+
// ContextProxy
28062805

2807-
public async updateGlobalState<K extends keyof GlobalState>(key: K, value: GlobalState[K]) {
2806+
// @deprecated - Use `ContextProxy#setValue` instead.
2807+
private async updateGlobalState<K extends keyof GlobalState>(key: K, value: GlobalState[K]) {
28082808
await this.contextProxy.setValue(key, value)
28092809
}
28102810

2811-
public getGlobalState<K extends keyof GlobalState>(key: K) {
2811+
// @deprecated - Use `ContextProxy#getValue` instead.
2812+
private getGlobalState<K extends keyof GlobalState>(key: K) {
28122813
return this.contextProxy.getValue(key)
28132814
}
28142815

2815-
// secrets
2816-
2817-
public async storeSecret(key: keyof SecretState, value?: string) {
2816+
public async setValue<K extends keyof RooCodeSettings>(key: K, value: RooCodeSettings[K]) {
28182817
await this.contextProxy.setValue(key, value)
28192818
}
28202819

2821-
private getSecret(key: keyof SecretState) {
2820+
public getValue<K extends keyof RooCodeSettings>(key: K) {
28222821
return this.contextProxy.getValue(key)
28232822
}
28242823

2825-
// global + secret
2824+
public getValues() {
2825+
return this.contextProxy.getValues()
2826+
}
28262827

28272828
public async setValues(values: RooCodeSettings) {
28282829
await this.contextProxy.setValues(values)

src/core/webview/__tests__/ClineProvider.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ describe("ClineProvider", () => {
630630
setModeConfig: jest.fn(),
631631
} as any
632632

633-
provider.updateGlobalState("currentApiConfigName", "current-config")
633+
provider.setValue("currentApiConfigName", "current-config")
634634

635635
// Switch to architect mode
636636
await messageHandler({ type: "mode", text: "architect" })
@@ -759,7 +759,7 @@ describe("ClineProvider", () => {
759759
},
760760
}
761761

762-
provider.updateGlobalState("customModePrompts", existingPrompts)
762+
provider.setValue("customModePrompts", existingPrompts)
763763

764764
// Test updating a prompt
765765
await messageHandler({
@@ -2159,19 +2159,19 @@ describe.skip("ContextProxy integration", () => {
21592159
})
21602160

21612161
test("updateGlobalState uses contextProxy", async () => {
2162-
await provider.updateGlobalState("currentApiConfigName", "testValue")
2162+
await provider.setValue("currentApiConfigName", "testValue")
21632163
expect(mockContextProxy.updateGlobalState).toHaveBeenCalledWith("currentApiConfigName", "testValue")
21642164
})
21652165

21662166
test("getGlobalState uses contextProxy", async () => {
21672167
mockContextProxy.getGlobalState.mockResolvedValueOnce("testValue")
2168-
const result = await provider.getGlobalState("currentApiConfigName")
2168+
const result = await provider.getValue("currentApiConfigName")
21692169
expect(mockContextProxy.getGlobalState).toHaveBeenCalledWith("currentApiConfigName")
21702170
expect(result).toBe("testValue")
21712171
})
21722172

21732173
test("storeSecret uses contextProxy", async () => {
2174-
await provider.storeSecret("apiKey", "test-secret")
2174+
await provider.setValue("apiKey", "test-secret")
21752175
expect(mockContextProxy.storeSecret).toHaveBeenCalledWith("apiKey", "test-secret")
21762176
})
21772177

src/exports/api.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,22 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
7878
await this.provider.postMessageToWebview({ type: "invoke", invoke: "secondaryButtonClick" })
7979
}
8080

81+
public getConfiguration() {
82+
return this.provider.getValues()
83+
}
84+
85+
public getConfigurationValue<K extends keyof RooCodeSettings>(key: K) {
86+
return this.provider.getValue(key)
87+
}
88+
8189
public async setConfiguration(values: RooCodeSettings) {
8290
await this.provider.setValues(values)
8391
}
8492

93+
public async setConfigurationValue<K extends keyof RooCodeSettings>(key: K, value: RooCodeSettings[K]) {
94+
await this.provider.setValue(key, value)
95+
}
96+
8597
public isReady() {
8698
return this.provider.viewLaunched
8799
}

src/exports/interface.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,32 @@ export interface RooCodeAPI extends EventEmitter<RooCodeEvents> {
6161
*/
6262
pressSecondaryButton(): Promise<void>
6363

64+
/**
65+
* Returns the current configuration.
66+
* @returns The current configuration.
67+
*/
68+
getConfiguration(): RooCodeSettings
69+
70+
/**
71+
* Returns the value of a configuration key.
72+
* @param key The key of the configuration value to return.
73+
* @returns The value of the configuration key.
74+
*/
75+
getConfigurationValue<K extends keyof RooCodeSettings>(key: K): RooCodeSettings[K]
76+
6477
/**
6578
* Sets the configuration for the current task.
6679
* @param values An object containing key-value pairs to set.
6780
*/
6881
setConfiguration(values: RooCodeSettings): Promise<void>
6982

83+
/**
84+
* Sets the value of a configuration key.
85+
* @param key The key of the configuration value to set.
86+
* @param value The value to set.
87+
*/
88+
setConfigurationValue<K extends keyof RooCodeSettings>(key: K, value: RooCodeSettings[K]): Promise<void>
89+
7090
/**
7191
* Returns true if the API is ready to use.
7292
*/

src/exports/roo-code.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,28 @@ interface RooCodeAPI extends EventEmitter<RooCodeEvents> {
452452
* Simulates pressing the secondary button in the chat interface.
453453
*/
454454
pressSecondaryButton(): Promise<void>
455+
/**
456+
* Returns the current configuration.
457+
* @returns The current configuration.
458+
*/
459+
getConfiguration(): RooCodeSettings
460+
/**
461+
* Returns the value of a configuration key.
462+
* @param key The key of the configuration value to return.
463+
* @returns The value of the configuration key.
464+
*/
465+
getConfigurationValue<K extends keyof RooCodeSettings>(key: K): RooCodeSettings[K]
455466
/**
456467
* Sets the configuration for the current task.
457468
* @param values An object containing key-value pairs to set.
458469
*/
459470
setConfiguration(values: RooCodeSettings): Promise<void>
471+
/**
472+
* Sets the value of a configuration key.
473+
* @param key The key of the configuration value to set.
474+
* @param value The value to set.
475+
*/
476+
setConfigurationValue<K extends keyof RooCodeSettings>(key: K, value: RooCodeSettings[K]): Promise<void>
460477
/**
461478
* Returns true if the API is ready to use.
462479
*/

0 commit comments

Comments
 (0)