Skip to content

Commit b4094a6

Browse files
committed
refactor by pr comment
1 parent 167229f commit b4094a6

File tree

2 files changed

+52
-37
lines changed

2 files changed

+52
-37
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as path from "path"
88
import * as vscode from "vscode"
99
import simpleGit from "simple-git"
1010

11-
import { ApiConfiguration, ApiProvider, ModelInfo } from "../../shared/api"
11+
import { ApiConfiguration, ApiProvider, ModelInfo, API_CONFIG_KEYS } from "../../shared/api"
1212
import { findLast } from "../../shared/array"
1313
import { CustomSupportPrompts, supportPrompt } from "../../shared/support-prompt"
1414
import { GlobalFileNames } from "../../shared/globalFileNames"
@@ -2114,47 +2114,19 @@ export class ClineProvider implements vscode.WebviewViewProvider {
21142114
}
21152115

21162116
// Build the apiConfiguration object combining state values and secrets
2117+
// Using the dynamic approach with API_CONFIG_KEYS
21172118
const apiConfiguration: ApiConfiguration = {
2118-
apiProvider,
2119-
apiModelId: stateValues.apiModelId,
2120-
glamaModelId: stateValues.glamaModelId,
2121-
glamaModelInfo: stateValues.glamaModelInfo,
2122-
awsRegion: stateValues.awsRegion,
2123-
awsUseCrossRegionInference: stateValues.awsUseCrossRegionInference,
2124-
awsProfile: stateValues.awsProfile,
2125-
awsUseProfile: stateValues.awsUseProfile,
2126-
vertexProjectId: stateValues.vertexProjectId,
2127-
vertexRegion: stateValues.vertexRegion,
2128-
openAiBaseUrl: stateValues.openAiBaseUrl,
2129-
openAiModelId: stateValues.openAiModelId,
2130-
openAiCustomModelInfo: stateValues.openAiCustomModelInfo,
2131-
openAiUseAzure: stateValues.openAiUseAzure,
2132-
ollamaModelId: stateValues.ollamaModelId,
2133-
ollamaBaseUrl: stateValues.ollamaBaseUrl,
2134-
lmStudioModelId: stateValues.lmStudioModelId,
2135-
lmStudioBaseUrl: stateValues.lmStudioBaseUrl,
2136-
anthropicBaseUrl: stateValues.anthropicBaseUrl,
2137-
modelMaxThinkingTokens: stateValues.modelMaxThinkingTokens,
2138-
mistralCodestralUrl: stateValues.mistralCodestralUrl,
2139-
azureApiVersion: stateValues.azureApiVersion,
2140-
openAiStreamingEnabled: stateValues.openAiStreamingEnabled,
2141-
openRouterModelId: stateValues.openRouterModelId,
2142-
openRouterModelInfo: stateValues.openRouterModelInfo,
2143-
openRouterBaseUrl: stateValues.openRouterBaseUrl,
2144-
openRouterUseMiddleOutTransform: stateValues.openRouterUseMiddleOutTransform,
2145-
vsCodeLmModelSelector: stateValues.vsCodeLmModelSelector,
2146-
unboundModelId: stateValues.unboundModelId,
2147-
unboundModelInfo: stateValues.unboundModelInfo,
2148-
requestyModelId: stateValues.requestyModelId,
2149-
requestyModelInfo: stateValues.requestyModelInfo,
2150-
modelTemperature: stateValues.modelTemperature,
2151-
modelMaxTokens: stateValues.modelMaxTokens,
2152-
lmStudioSpeculativeDecodingEnabled: stateValues.lmStudioSpeculativeDecodingEnabled,
2153-
lmStudioDraftModelId: stateValues.lmStudioDraftModelId,
2119+
// Dynamically add all API-related keys from stateValues
2120+
...Object.fromEntries(API_CONFIG_KEYS.map((key) => [key, stateValues[key]])),
21542121
// Add all secrets
21552122
...secretValues,
21562123
}
21572124

2125+
// Ensure apiProvider is set properly if not already in state
2126+
if (!apiConfiguration.apiProvider) {
2127+
apiConfiguration.apiProvider = apiProvider
2128+
}
2129+
21582130
// Return the same structure as before
21592131
return {
21602132
apiConfiguration,

src/shared/api.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,49 @@ export type ApiConfiguration = ApiHandlerOptions & {
7878
id?: string // stable unique identifier
7979
}
8080

81+
// Import GlobalStateKey type from globalState.ts
82+
import { GlobalStateKey } from "./globalState"
83+
84+
// Define API configuration keys for dynamic object building
85+
export const API_CONFIG_KEYS: GlobalStateKey[] = [
86+
"apiProvider",
87+
"apiModelId",
88+
"glamaModelId",
89+
"glamaModelInfo",
90+
"awsRegion",
91+
"awsUseCrossRegionInference",
92+
"awsProfile",
93+
"awsUseProfile",
94+
"vertexProjectId",
95+
"vertexRegion",
96+
"openAiBaseUrl",
97+
"openAiModelId",
98+
"openAiCustomModelInfo",
99+
"openAiUseAzure",
100+
"ollamaModelId",
101+
"ollamaBaseUrl",
102+
"lmStudioModelId",
103+
"lmStudioBaseUrl",
104+
"anthropicBaseUrl",
105+
"modelMaxThinkingTokens",
106+
"mistralCodestralUrl",
107+
"azureApiVersion",
108+
"openAiStreamingEnabled",
109+
"openRouterModelId",
110+
"openRouterModelInfo",
111+
"openRouterBaseUrl",
112+
"openRouterUseMiddleOutTransform",
113+
"vsCodeLmModelSelector",
114+
"unboundModelId",
115+
"unboundModelInfo",
116+
"requestyModelId",
117+
"requestyModelInfo",
118+
"modelTemperature",
119+
"modelMaxTokens",
120+
"lmStudioSpeculativeDecodingEnabled",
121+
"lmStudioDraftModelId"
122+
]
123+
81124
// Models
82125

83126
export interface ModelInfo {

0 commit comments

Comments
 (0)