Skip to content

Commit 8fa1d5a

Browse files
committed
refactor(experiments): simplify experiment config structure
- Remove redundant id field from ExperimentConfig interface - Update UI components to use experiment keys directly - Improve type safety by using key-based mapping instead of object values
1 parent 7dd1618 commit 8fa1d5a

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

src/shared/experiments.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export type ExperimentKey = keyof typeof EXPERIMENT_IDS
88
export type ExperimentId = valueof<typeof EXPERIMENT_IDS>
99

1010
export interface ExperimentConfig {
11-
id: ExperimentId
1211
name: string
1312
description: string
1413
enabled: boolean
@@ -18,21 +17,18 @@ type valueof<X> = X[keyof X]
1817

1918
export const experimentConfigsMap: Record<ExperimentKey, ExperimentConfig> = {
2019
DIFF_STRATEGY: {
21-
id: EXPERIMENT_IDS.DIFF_STRATEGY,
2220
name: "Use experimental unified diff strategy",
2321
description:
2422
"Enable the experimental unified diff strategy. This strategy might reduce the number of retries caused by model errors but may cause unexpected behavior or incorrect edits. Only enable if you understand the risks and are willing to carefully review all changes.",
2523
enabled: false,
2624
},
2725
SEARCH_AND_REPLACE: {
28-
id: EXPERIMENT_IDS.SEARCH_AND_REPLACE,
2926
name: "Use experimental search and replace tool",
3027
description:
3128
"Enable the experimental search and replace tool, allowing Roo to replace multiple instances of a search term in one request.",
3229
enabled: false,
3330
},
3431
INSERT_BLOCK: {
35-
id: EXPERIMENT_IDS.INSERT_BLOCK,
3632
name: "Use experimental insert block tool",
3733

3834
description:
@@ -42,7 +38,10 @@ export const experimentConfigsMap: Record<ExperimentKey, ExperimentConfig> = {
4238
}
4339

4440
export const experimentDefault = Object.fromEntries(
45-
Object.entries(experimentConfigsMap).map(([_, config]) => [config.id, config.enabled]),
41+
Object.entries(experimentConfigsMap).map(([_, config]) => [
42+
EXPERIMENT_IDS[_ as keyof typeof EXPERIMENT_IDS] as ExperimentId,
43+
config.enabled,
44+
]),
4645
) as Record<ExperimentId, boolean>
4746

4847
export const experiments = {
@@ -56,9 +55,15 @@ export const experiments = {
5655

5756
// Expose experiment details for UI - pre-compute from map for better performance
5857
export const experimentLabels = Object.fromEntries(
59-
Object.values(experimentConfigsMap).map((config) => [config.id, config.name]),
58+
Object.entries(experimentConfigsMap).map(([_, config]) => [
59+
EXPERIMENT_IDS[_ as keyof typeof EXPERIMENT_IDS] as ExperimentId,
60+
config.name,
61+
]),
6062
) as Record<string, string>
6163

6264
export const experimentDescriptions = Object.fromEntries(
63-
Object.values(experimentConfigsMap).map((config) => [config.id, config.description]),
65+
Object.entries(experimentConfigsMap).map(([_, config]) => [
66+
EXPERIMENT_IDS[_ as keyof typeof EXPERIMENT_IDS] as ExperimentId,
67+
config.description,
68+
]),
6469
) as Record<string, string>

webview-ui/src/components/settings/ExperimentalFeature.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
22

33
interface ExperimentalFeatureProps {
4-
id: string
54
name: string
65
description: string
76
enabled: boolean
87
onChange: (value: boolean) => void
98
}
109

11-
const ExperimentalFeature = ({ id, name, description, enabled, onChange }: ExperimentalFeatureProps) => {
10+
const ExperimentalFeature = ({ name, description, enabled, onChange }: ExperimentalFeatureProps) => {
1211
return (
1312
<div
1413
style={{

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { validateApiConfiguration, validateModelId } from "../../utils/validate"
55
import { vscode } from "../../utils/vscode"
66
import ApiOptions from "./ApiOptions"
77
import ExperimentalFeature from "./ExperimentalFeature"
8-
import { EXPERIMENT_IDS, experimentConfigsMap } from "../../../../src/shared/experiments"
8+
import { EXPERIMENT_IDS, experimentConfigsMap, ExperimentId, ExperimentKey } from "../../../../src/shared/experiments"
99
import ApiConfigManager from "./ApiConfigManager"
1010

1111
type SettingsViewProps = {
@@ -97,6 +97,8 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
9797
apiConfiguration,
9898
})
9999

100+
console.log("Experiments", experiments)
101+
100102
vscode.postMessage({
101103
type: "updateExperimental",
102104
values: experiments,
@@ -646,14 +648,21 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
646648
</p>
647649
</div>
648650
)}
649-
{Object.values(experimentConfigsMap)
650-
.filter((config) => config.id !== EXPERIMENT_IDS.DIFF_STRATEGY)
651+
{Object.entries(experimentConfigsMap)
652+
.filter((config) => config[0] !== "DIFF_STRATEGY")
651653
.map((config) => (
652654
<ExperimentalFeature
653-
key={config.id}
654-
{...config}
655-
enabled={experiments[config.id] ?? false}
656-
onChange={(enabled) => setExperimentEnabled(config.id, enabled)}
655+
key={config[0]}
656+
{...config[1]}
657+
enabled={
658+
experiments[EXPERIMENT_IDS[config[0] as keyof typeof EXPERIMENT_IDS]] ?? false
659+
}
660+
onChange={(enabled) =>
661+
setExperimentEnabled(
662+
EXPERIMENT_IDS[config[0] as keyof typeof EXPERIMENT_IDS],
663+
enabled,
664+
)
665+
}
657666
/>
658667
))}
659668
</div>

0 commit comments

Comments
 (0)