refactor(experiments): improve type safety for experiment configuration

Change ExperimentId type to be value-based rather than key-based
Make experiment record types more strict with proper typing
Pass full experiment config object instead of single boolean flag
Update type definitions and usages across codebase
This commit is contained in:
sam hoang
2025-01-27 14:59:52 +07:00
parent bb84d79af1
commit 3ed8540eba
6 changed files with 28 additions and 24 deletions

View File

@@ -45,6 +45,7 @@ import {
experimentConfigs,
experiments as Experiments,
experimentDefault,
ExperimentId,
} from "../../shared/experiments"
import { CustomSupportPrompts, supportPrompt } from "../../shared/support-prompt"
@@ -360,7 +361,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
task,
images,
undefined,
Experiments.isEnabled(experiments, EXPERIMENT_IDS.DIFF_STRATEGY),
experiments,
)
}
@@ -388,7 +389,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
undefined,
undefined,
historyItem,
Experiments.isEnabled(experiments, EXPERIMENT_IDS.DIFF_STRATEGY),
experiments,
)
}
@@ -1222,7 +1223,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
const updatedExperiments = {
...((await this.getGlobalState("experiments")) ?? experimentDefault),
...message.values,
}
} as Record<ExperimentId, boolean>
await this.updateGlobalState("experiments", updatedExperiments)
@@ -2132,7 +2133,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
this.getGlobalState("enhancementApiConfigId") as Promise<string | undefined>,
this.getGlobalState("autoApprovalEnabled") as Promise<boolean | undefined>,
this.customModesManager.getCustomModes(),
this.getGlobalState("experiments") as Promise<Record<string, boolean> | undefined>,
this.getGlobalState("experiments") as Promise<Record<ExperimentId, boolean> | undefined>,
])
let apiProvider: ApiProvider