updateApiConfiguration v2 (#7160)

* add new version of updateApiConfiguration that splits options and secrets

* remove console log

* remove unnecessary modelInfo conversion
This commit is contained in:
celestial-vault authored and GitHub committed 2025-10-29 22:39:51 -06:00
1 parent f6eb3aa386
commit d95d86f329
3 files changed
+316 -31

No files matched your search

+169 -2
View File
@@ -29,8 +29,10 @@ service ModelsService {
rpc refreshRequestyModels(EmptyRequest) returns (OpenRouterCompatibleModelInfo);
// Subscribe to OpenRouter models updates
rpc subscribeToOpenRouterModels(EmptyRequest) returns (stream OpenRouterCompatibleModelInfo);
// Updates API configuration
// Updates API configuration (legacy - uses combined configuration)
rpc updateApiConfigurationProto(UpdateApiConfigurationRequest) returns (Empty);
// Updates API configuration (new - uses separate options and secrets)
rpc updateApiConfiguration(UpdateApiConfigurationRequestNew) returns (Empty);
// Updates API configuration with partial values (only updates fields that are explicitly set)
rpc updateApiConfigurationPartial(UpdateApiConfigurationPartialRequest) returns (Empty);
// Refreshes and returns Groq models
@@ -128,12 +130,177 @@ message SapAiCoreModelsResponse {
bool orchestration_available = 2;
}
// Request for updating API configuration
// API secrets (credentials, API keys)
message ModelsApiSecrets {
optional string api_key = 1;
optional string cline_api_key = 2;
optional string lite_llm_api_key = 3;
optional string open_router_api_key = 4;
optional string aws_access_key = 5;
optional string aws_secret_key = 6;
optional string aws_session_token = 7;
optional string aws_bedrock_api_key = 8;
optional string open_ai_api_key = 9;
optional string ollama_api_key = 10;
optional string gemini_api_key = 11;
optional string open_ai_native_api_key = 12;
optional string deep_seek_api_key = 13;
optional string requesty_api_key = 14;
optional string together_api_key = 15;
optional string fireworks_api_key = 16;
optional string qwen_api_key = 17;
optional string doubao_api_key = 18;
optional string mistral_api_key = 19;
optional string nebius_api_key = 20;
optional string asksage_api_key = 21;
optional string xai_api_key = 22;
optional string sambanova_api_key = 23;
optional string cerebras_api_key = 24;
optional string sap_ai_core_client_id = 25;
optional string sap_ai_core_client_secret = 26;
optional string moonshot_api_key = 27;
optional string cline_account_id = 28;
optional string groq_api_key = 29;
optional string hugging_face_api_key = 30;
optional string huawei_cloud_maas_api_key = 31;
optional string baseten_api_key = 32;
optional string zai_api_key = 33;
optional string vercel_ai_gateway_api_key = 34;
optional string dify_api_key = 35;
optional string oca_api_key = 36;
optional string oca_refresh_token = 37;
optional string minimax_api_key = 38;
}
// API configuration options (non-secret settings)
message ModelsApiOptions {
// Global configuration fields (not mode-specific)
optional string ulid = 1;
optional string lite_llm_base_url = 2;
optional bool lite_llm_use_prompt_cache = 3;
map<string, string> open_ai_headers = 4;
optional string anthropic_base_url = 5;
optional string open_router_provider_sorting = 6;
optional string aws_region = 7;
optional bool aws_use_cross_region_inference = 8;
optional bool aws_bedrock_use_prompt_cache = 9;
optional bool aws_use_profile = 10;
optional string aws_profile = 11;
optional string aws_bedrock_endpoint = 12;
optional string claude_code_path = 13;
optional string vertex_project_id = 14;
optional string vertex_region = 15;
optional string open_ai_base_url = 16;
optional string ollama_base_url = 17;
optional string ollama_api_options_ctx_num = 18;
optional string lm_studio_base_url = 19;
optional string gemini_base_url = 20;
optional string requesty_base_url = 21;
optional int64 fireworks_model_max_completion_tokens = 22;
optional int64 fireworks_model_max_tokens = 23;
optional string azure_api_version = 24;
optional string qwen_api_line = 25;
optional string asksage_api_url = 26;
optional int64 request_timeout_ms = 27;
optional string sap_ai_resource_group = 28;
optional string sap_ai_core_token_url = 29;
optional string sap_ai_core_base_url = 30;
optional bool sap_ai_core_use_orchestration_mode = 31;
optional string moonshot_api_line = 32;
optional string aws_authentication = 33;
optional string zai_api_line = 34;
optional string lm_studio_max_tokens = 35;
optional string qwen_code_oauth_path = 36;
optional string dify_base_url = 37;
optional string oca_base_url = 38;
optional string oca_mode = 39;
optional bool aws_use_global_inference = 40;
optional string minimax_api_line = 41;
// Plan mode configurations
optional ApiProvider plan_mode_api_provider = 100;
optional string plan_mode_api_model_id = 101;
optional int64 plan_mode_thinking_budget_tokens = 102;
optional string plan_mode_reasoning_effort = 103;
optional LanguageModelChatSelector plan_mode_vs_code_lm_model_selector = 104;
optional bool plan_mode_aws_bedrock_custom_selected = 105;
optional string plan_mode_aws_bedrock_custom_model_base_id = 106;
optional string plan_mode_open_router_model_id = 107;
optional OpenRouterModelInfo plan_mode_open_router_model_info = 108;
optional string plan_mode_open_ai_model_id = 109;
optional OpenAiCompatibleModelInfo plan_mode_open_ai_model_info = 110;
optional string plan_mode_ollama_model_id = 111;
optional string plan_mode_lm_studio_model_id = 112;
optional string plan_mode_lite_llm_model_id = 113;
optional LiteLLMModelInfo plan_mode_lite_llm_model_info = 114;
optional string plan_mode_requesty_model_id = 115;
optional OpenRouterModelInfo plan_mode_requesty_model_info = 116;
optional string plan_mode_together_model_id = 117;
optional string plan_mode_fireworks_model_id = 118;
optional string plan_mode_sap_ai_core_model_id = 119;
optional string plan_mode_sap_ai_core_deployment_id = 120;
optional string plan_mode_groq_model_id = 121;
optional OpenRouterModelInfo plan_mode_groq_model_info = 122;
optional string plan_mode_hugging_face_model_id = 123;
optional OpenRouterModelInfo plan_mode_hugging_face_model_info = 124;
optional string plan_mode_huawei_cloud_maas_model_id = 125;
optional OpenRouterModelInfo plan_mode_huawei_cloud_maas_model_info = 126;
optional string plan_mode_baseten_model_id = 127;
optional OpenRouterModelInfo plan_mode_baseten_model_info = 128;
optional string plan_mode_vercel_ai_gateway_model_id = 129;
optional OpenRouterModelInfo plan_mode_vercel_ai_gateway_model_info = 130;
optional string plan_mode_oca_model_id = 131;
optional OcaModelInfo plan_mode_oca_model_info = 132;
// Act mode configurations
optional ApiProvider act_mode_api_provider = 200;
optional string act_mode_api_model_id = 201;
optional int64 act_mode_thinking_budget_tokens = 202;
optional string act_mode_reasoning_effort = 203;
optional LanguageModelChatSelector act_mode_vs_code_lm_model_selector = 204;
optional bool act_mode_aws_bedrock_custom_selected = 205;
optional string act_mode_aws_bedrock_custom_model_base_id = 206;
optional string act_mode_open_router_model_id = 207;
optional OpenRouterModelInfo act_mode_open_router_model_info = 208;
optional string act_mode_open_ai_model_id = 209;
optional OpenAiCompatibleModelInfo act_mode_open_ai_model_info = 210;
optional string act_mode_ollama_model_id = 211;
optional string act_mode_lm_studio_model_id = 212;
optional string act_mode_lite_llm_model_id = 213;
optional LiteLLMModelInfo act_mode_lite_llm_model_info = 214;
optional string act_mode_requesty_model_id = 215;
optional OpenRouterModelInfo act_mode_requesty_model_info = 216;
optional string act_mode_together_model_id = 217;
optional string act_mode_fireworks_model_id = 218;
optional string act_mode_sap_ai_core_model_id = 219;
optional string act_mode_sap_ai_core_deployment_id = 220;
optional string act_mode_groq_model_id = 221;
optional OpenRouterModelInfo act_mode_groq_model_info = 222;
optional string act_mode_hugging_face_model_id = 223;
optional OpenRouterModelInfo act_mode_hugging_face_model_info = 224;
optional string act_mode_huawei_cloud_maas_model_id = 225;
optional OpenRouterModelInfo act_mode_huawei_cloud_maas_model_info = 226;
optional string act_mode_baseten_model_id = 227;
optional OpenRouterModelInfo act_mode_baseten_model_info = 228;
optional string act_mode_vercel_ai_gateway_model_id = 229;
optional OpenRouterModelInfo act_mode_vercel_ai_gateway_model_info = 230;
optional string act_mode_oca_model_id = 231;
optional OcaModelInfo act_mode_oca_model_info = 232;
}
// Request for updating API configuration (legacy - uses combined configuration)
message UpdateApiConfigurationRequest {
Metadata metadata = 1;
ModelsApiConfiguration api_configuration = 2;
}
// Request for updating API configuration (new - uses separate options and secrets)
message UpdateApiConfigurationRequestNew {
Metadata metadata = 1;
ModelsApiOptions options = 2;
ModelsApiSecrets secrets = 3;
}
// Request for partially updating API configuration using FieldMask
// Only fields specified in update_mask will be updated from api_configuration
message UpdateApiConfigurationPartialRequest {
@@ -0,0 +1,79 @@
import { Empty } from "@shared/proto/cline/common"
import { convertProtoToApiProvider } from "@shared/proto-conversions/models/api-configuration-conversion"
import { buildApiHandler } from "@/core/api"
import { ApiHandlerOptions, ApiHandlerSecrets, ApiProvider } from "@/shared/api"
import { UpdateApiConfigurationRequestNew } from "@/shared/proto/index.cline"
import type { Controller } from "../index"
/**
* Updates API configuration
* @param controller The controller instance
* @param request The update API configuration request
* @returns Empty response
*/
export async function updateApiConfiguration(controller: Controller, request: UpdateApiConfigurationRequestNew): Promise<Empty> {
try {
const { options: protoOptions, secrets: protoSecrets } = request
const secrets: Partial<ApiHandlerSecrets> = {}
if (protoSecrets) {
const filteredSecrets = Object.fromEntries(Object.entries(protoSecrets).filter(([_, value]) => value !== undefined))
Object.assign(secrets, filteredSecrets)
}
const options: Partial<ApiHandlerOptions> & { planModeApiProvider?: ApiProvider; actModeApiProvider?: ApiProvider } = {}
if (protoOptions) {
// Extract fields requiring conversion or special handling
const {
// Fields requiring enum conversion
planModeApiProvider,
actModeApiProvider,
// Fields requiring special handling
openAiHeaders,
...simpleOptions
} = protoOptions
// Batch update for simple pass-through fields
const filteredOptions = Object.fromEntries(Object.entries(simpleOptions).filter(([_, value]) => value !== undefined))
Object.assign(options, filteredOptions)
// Handle openAiHeaders (skip empty objects)
if (openAiHeaders && Object.keys(openAiHeaders).length > 0) {
options.openAiHeaders = openAiHeaders
}
// Convert proto ApiProvider enums to native string types
if (planModeApiProvider !== undefined) {
options.planModeApiProvider = convertProtoToApiProvider(planModeApiProvider)
}
if (actModeApiProvider !== undefined) {
options.actModeApiProvider = convertProtoToApiProvider(actModeApiProvider)
}
}
// Update storage using batch methods
if (Object.keys(secrets).length > 0) {
controller.stateManager.setSecretsBatch(secrets)
}
if (Object.keys(options).length > 0) {
controller.stateManager.setGlobalStateBatch(options)
}
// Update the task's API handler if there's an active task
if (controller.task) {
const currentMode = controller.stateManager.getGlobalSettingsKey("mode")
// Combine secrets and options for the API handler
const apiConfigForHandler = { ...secrets, ...options, ulid: controller.task.ulid }
controller.task.api = buildApiHandler(apiConfigForHandler, currentMode)
}
// Post updated state to webview
await controller.postStateToWebview()
return Empty.create()
} catch (error) {
console.error(`Failed to update API configuration: ${error}`)
throw error
}
}
@@ -1,14 +1,15 @@
import { liteLlmModelInfoSaneDefaults } from "@shared/api"
import { UpdateApiConfigurationRequestNew } from "@shared/proto/index.cline"
import { Mode } from "@shared/storage/types"
import { VSCodeCheckbox, VSCodeLink } from "@vscode/webview-ui-toolkit/react"
import { useState } from "react"
import { useExtensionState } from "@/context/ExtensionStateContext"
import { ModelsServiceClient } from "@/services/grpc-client"
import { getAsVar, VSC_DESCRIPTION_FOREGROUND } from "@/utils/vscStyles"
import { DebouncedTextField } from "../common/DebouncedTextField"
import { ModelInfoView } from "../common/ModelInfoView"
import ThinkingBudgetSlider from "../ThinkingBudgetSlider"
import { getModeSpecificFields, normalizeApiConfiguration } from "../utils/providerUtils"
import { useApiConfigurationHandlers } from "../utils/useApiConfigurationHandlers"
/**
* Props for the LiteLlmProvider component
@@ -24,7 +25,6 @@ interface LiteLlmProviderProps {
*/
export const LiteLlmProvider = ({ showModelOptions, isPopup, currentMode }: LiteLlmProviderProps) => {
const { apiConfiguration } = useExtensionState()
const { handleFieldChange, handleModeFieldChange } = useApiConfigurationHandlers()
// Get the normalized configuration
const { selectedModelId, selectedModelInfo } = normalizeApiConfiguration(apiConfiguration, currentMode)
@@ -39,7 +39,15 @@ export const LiteLlmProvider = ({ showModelOptions, isPopup, currentMode }: Lite
<div>
<DebouncedTextField
initialValue={apiConfiguration?.liteLlmBaseUrl || ""}
onChange={(value) => handleFieldChange("liteLlmBaseUrl", value)}
onChange={async (value) => {
await ModelsServiceClient.updateApiConfiguration(
UpdateApiConfigurationRequestNew.create({
options: {
liteLlmBaseUrl: value,
},
}),
)
}}
placeholder={"Default: http://localhost:4000"}
style={{ width: "100%" }}
type="text">
@@ -47,7 +55,15 @@ export const LiteLlmProvider = ({ showModelOptions, isPopup, currentMode }: Lite
</DebouncedTextField>
<DebouncedTextField
initialValue={apiConfiguration?.liteLlmApiKey || ""}
onChange={(value) => handleFieldChange("liteLlmApiKey", value)}
onChange={async (value) => {
await ModelsServiceClient.updateApiConfiguration(
UpdateApiConfigurationRequestNew.create({
secrets: {
liteLlmApiKey: value,
},
}),
)
}}
placeholder="Default: noop"
style={{ width: "100%" }}
type="password">
@@ -55,9 +71,14 @@ export const LiteLlmProvider = ({ showModelOptions, isPopup, currentMode }: Lite
</DebouncedTextField>
<DebouncedTextField
initialValue={liteLlmModelId || ""}
onChange={(value) =>
handleModeFieldChange({ plan: "planModeLiteLlmModelId", act: "actModeLiteLlmModelId" }, value, currentMode)
}
onChange={async (value) => {
await ModelsServiceClient.updateApiConfiguration(
UpdateApiConfigurationRequestNew.create({
options:
currentMode === "plan" ? { planModeLiteLlmModelId: value } : { actModeLiteLlmModelId: value },
}),
)
}}
placeholder={"e.g. anthropic/claude-sonnet-4-20250514"}
style={{ width: "100%" }}>
<span style={{ fontWeight: 500 }}>Model ID</span>
@@ -68,10 +89,16 @@ export const LiteLlmProvider = ({ showModelOptions, isPopup, currentMode }: Lite
<>
<VSCodeCheckbox
checked={apiConfiguration?.liteLlmUsePromptCache || false}
onChange={(e: any) => {
onChange={async (e: any) => {
const isChecked = e.target.checked === true
handleFieldChange("liteLlmUsePromptCache", isChecked)
await ModelsServiceClient.updateApiConfiguration(
UpdateApiConfigurationRequestNew.create({
options: {
liteLlmUsePromptCache: isChecked,
},
}),
)
}}
style={{ fontWeight: 500, color: "var(--vscode-charts-green)" }}>
Use prompt caching (GA)
@@ -124,15 +151,18 @@ export const LiteLlmProvider = ({ showModelOptions, isPopup, currentMode }: Lite
<>
<VSCodeCheckbox
checked={!!liteLlmModelInfo?.supportsImages}
onChange={(e: any) => {
onChange={async (e: any) => {
const isChecked = e.target.checked === true
const modelInfo = liteLlmModelInfo ? liteLlmModelInfo : { ...liteLlmModelInfoSaneDefaults }
modelInfo.supportsImages = isChecked
handleModeFieldChange(
{ plan: "planModeLiteLlmModelInfo", act: "actModeLiteLlmModelInfo" },
modelInfo,
currentMode,
await ModelsServiceClient.updateApiConfiguration(
UpdateApiConfigurationRequestNew.create({
options:
currentMode === "plan"
? { planModeLiteLlmModelInfo: modelInfo }
: { actModeLiteLlmModelInfo: modelInfo },
}),
)
}}>
Supports Images
@@ -144,14 +174,17 @@ export const LiteLlmProvider = ({ showModelOptions, isPopup, currentMode }: Lite
? liteLlmModelInfo.contextWindow.toString()
: (liteLlmModelInfoSaneDefaults.contextWindow?.toString() ?? "")
}
onChange={(value) => {
onChange={async (value) => {
const modelInfo = liteLlmModelInfo ? liteLlmModelInfo : { ...liteLlmModelInfoSaneDefaults }
modelInfo.contextWindow = Number(value)
handleModeFieldChange(
{ plan: "planModeLiteLlmModelInfo", act: "actModeLiteLlmModelInfo" },
modelInfo,
currentMode,
await ModelsServiceClient.updateApiConfiguration(
UpdateApiConfigurationRequestNew.create({
options:
currentMode === "plan"
? { planModeLiteLlmModelInfo: modelInfo }
: { actModeLiteLlmModelInfo: modelInfo },
}),
)
}}
style={{ flex: 1 }}>
@@ -163,14 +196,17 @@ export const LiteLlmProvider = ({ showModelOptions, isPopup, currentMode }: Lite
? liteLlmModelInfo.maxTokens.toString()
: (liteLlmModelInfoSaneDefaults.maxTokens?.toString() ?? "")
}
onChange={(value) => {
onChange={async (value) => {
const modelInfo = liteLlmModelInfo ? liteLlmModelInfo : { ...liteLlmModelInfoSaneDefaults }
modelInfo.maxTokens = Number(value)
handleModeFieldChange(
{ plan: "planModeLiteLlmModelInfo", act: "actModeLiteLlmModelInfo" },
modelInfo,
currentMode,
await ModelsServiceClient.updateApiConfiguration(
UpdateApiConfigurationRequestNew.create({
options:
currentMode === "plan"
? { planModeLiteLlmModelInfo: modelInfo }
: { actModeLiteLlmModelInfo: modelInfo },
}),
)
}}
style={{ flex: 1 }}>
@@ -184,7 +220,7 @@ export const LiteLlmProvider = ({ showModelOptions, isPopup, currentMode }: Lite
? liteLlmModelInfo.temperature.toString()
: (liteLlmModelInfoSaneDefaults.temperature?.toString() ?? "")
}
onChange={(value) => {
onChange={async (value) => {
const modelInfo = liteLlmModelInfo ? liteLlmModelInfo : { ...liteLlmModelInfoSaneDefaults }
// Check if the input ends with a decimal point or has trailing zeros after decimal
@@ -193,10 +229,13 @@ export const LiteLlmProvider = ({ showModelOptions, isPopup, currentMode }: Lite
modelInfo.temperature =
value === "" ? liteLlmModelInfoSaneDefaults.temperature : parseFloat(value)
handleModeFieldChange(
{ plan: "planModeLiteLlmModelInfo", act: "actModeLiteLlmModelInfo" },
modelInfo,
currentMode,
await ModelsServiceClient.updateApiConfiguration(
UpdateApiConfigurationRequestNew.create({
options:
currentMode === "plan"
? { planModeLiteLlmModelInfo: modelInfo }
: { actModeLiteLlmModelInfo: modelInfo },
}),
)
}}>
<span style={{ fontWeight: 500 }}>Temperature</span>