sam hoang 10 месяцев назад
Родитель
Сommit
b4094a6281
2 измененных файлов с 52 добавлено и 37 удалено
  1. 9 37
      src/core/webview/ClineProvider.ts
  2. 43 0
      src/shared/api.ts

+ 9 - 37
src/core/webview/ClineProvider.ts

@@ -8,7 +8,7 @@ import * as path from "path"
 import * as vscode from "vscode"
 import simpleGit from "simple-git"
 
-import { ApiConfiguration, ApiProvider, ModelInfo } from "../../shared/api"
+import { ApiConfiguration, ApiProvider, ModelInfo, API_CONFIG_KEYS } from "../../shared/api"
 import { findLast } from "../../shared/array"
 import { CustomSupportPrompts, supportPrompt } from "../../shared/support-prompt"
 import { GlobalFileNames } from "../../shared/globalFileNames"
@@ -2114,47 +2114,19 @@ export class ClineProvider implements vscode.WebviewViewProvider {
 		}
 
 		// Build the apiConfiguration object combining state values and secrets
+		// Using the dynamic approach with API_CONFIG_KEYS
 		const apiConfiguration: ApiConfiguration = {
-			apiProvider,
-			apiModelId: stateValues.apiModelId,
-			glamaModelId: stateValues.glamaModelId,
-			glamaModelInfo: stateValues.glamaModelInfo,
-			awsRegion: stateValues.awsRegion,
-			awsUseCrossRegionInference: stateValues.awsUseCrossRegionInference,
-			awsProfile: stateValues.awsProfile,
-			awsUseProfile: stateValues.awsUseProfile,
-			vertexProjectId: stateValues.vertexProjectId,
-			vertexRegion: stateValues.vertexRegion,
-			openAiBaseUrl: stateValues.openAiBaseUrl,
-			openAiModelId: stateValues.openAiModelId,
-			openAiCustomModelInfo: stateValues.openAiCustomModelInfo,
-			openAiUseAzure: stateValues.openAiUseAzure,
-			ollamaModelId: stateValues.ollamaModelId,
-			ollamaBaseUrl: stateValues.ollamaBaseUrl,
-			lmStudioModelId: stateValues.lmStudioModelId,
-			lmStudioBaseUrl: stateValues.lmStudioBaseUrl,
-			anthropicBaseUrl: stateValues.anthropicBaseUrl,
-			modelMaxThinkingTokens: stateValues.modelMaxThinkingTokens,
-			mistralCodestralUrl: stateValues.mistralCodestralUrl,
-			azureApiVersion: stateValues.azureApiVersion,
-			openAiStreamingEnabled: stateValues.openAiStreamingEnabled,
-			openRouterModelId: stateValues.openRouterModelId,
-			openRouterModelInfo: stateValues.openRouterModelInfo,
-			openRouterBaseUrl: stateValues.openRouterBaseUrl,
-			openRouterUseMiddleOutTransform: stateValues.openRouterUseMiddleOutTransform,
-			vsCodeLmModelSelector: stateValues.vsCodeLmModelSelector,
-			unboundModelId: stateValues.unboundModelId,
-			unboundModelInfo: stateValues.unboundModelInfo,
-			requestyModelId: stateValues.requestyModelId,
-			requestyModelInfo: stateValues.requestyModelInfo,
-			modelTemperature: stateValues.modelTemperature,
-			modelMaxTokens: stateValues.modelMaxTokens,
-			lmStudioSpeculativeDecodingEnabled: stateValues.lmStudioSpeculativeDecodingEnabled,
-			lmStudioDraftModelId: stateValues.lmStudioDraftModelId,
+			// Dynamically add all API-related keys from stateValues
+			...Object.fromEntries(API_CONFIG_KEYS.map((key) => [key, stateValues[key]])),
 			// Add all secrets
 			...secretValues,
 		}
 
+		// Ensure apiProvider is set properly if not already in state
+		if (!apiConfiguration.apiProvider) {
+			apiConfiguration.apiProvider = apiProvider
+		}
+
 		// Return the same structure as before
 		return {
 			apiConfiguration,

+ 43 - 0
src/shared/api.ts

@@ -78,6 +78,49 @@ export type ApiConfiguration = ApiHandlerOptions & {
 	id?: string // stable unique identifier
 }
 
+// Import GlobalStateKey type from globalState.ts
+import { GlobalStateKey } from "./globalState"
+
+// Define API configuration keys for dynamic object building
+export const API_CONFIG_KEYS: GlobalStateKey[] = [
+	"apiProvider",
+	"apiModelId",
+	"glamaModelId",
+	"glamaModelInfo",
+	"awsRegion",
+	"awsUseCrossRegionInference",
+	"awsProfile",
+	"awsUseProfile",
+	"vertexProjectId",
+	"vertexRegion",
+	"openAiBaseUrl",
+	"openAiModelId",
+	"openAiCustomModelInfo",
+	"openAiUseAzure",
+	"ollamaModelId",
+	"ollamaBaseUrl",
+	"lmStudioModelId",
+	"lmStudioBaseUrl",
+	"anthropicBaseUrl",
+	"modelMaxThinkingTokens",
+	"mistralCodestralUrl",
+	"azureApiVersion",
+	"openAiStreamingEnabled",
+	"openRouterModelId",
+	"openRouterModelInfo",
+	"openRouterBaseUrl",
+	"openRouterUseMiddleOutTransform",
+	"vsCodeLmModelSelector",
+	"unboundModelId",
+	"unboundModelInfo",
+	"requestyModelId",
+	"requestyModelInfo",
+	"modelTemperature",
+	"modelMaxTokens",
+	"lmStudioSpeculativeDecodingEnabled",
+	"lmStudioDraftModelId"
+]
+
 // Models
 
 export interface ModelInfo {