Fix vercel gateway thinking and model list (#7196)

This commit is contained in:
Saoud Rizwan authored and GitHub committed 2025-11-05 12:43:44 -08:00
1 parent aaa3846b82
commit 515b4e5d6a
16 files changed
+97 -304

No files matched your search

-6
View File
@@ -180,8 +180,6 @@ func setSimpleField(settings *cline.Settings, key, value string) error {
settings.PlanModeHuaweiCloudMaasModelId = strPtr(value)
case "plan_mode_oca_model_id":
settings.PlanModeOcaModelId = strPtr(value)
case "plan_mode_vercel_ai_gateway_model_id":
settings.PlanModeVercelAiGatewayModelId = strPtr(value)
case "act_mode_api_model_id":
settings.ActModeApiModelId = strPtr(value)
case "act_mode_reasoning_effort":
@@ -218,8 +216,6 @@ func setSimpleField(settings *cline.Settings, key, value string) error {
settings.ActModeHuaweiCloudMaasModelId = strPtr(value)
case "act_mode_oca_model_id":
settings.ActModeOcaModelId = strPtr(value)
case "act_mode_vercel_ai_gateway_model_id":
settings.ActModeVercelAiGatewayModelId = strPtr(value)
// Boolean fields
case "aws_use_cross_region_inference":
@@ -736,8 +732,6 @@ func setSecretField(secrets *cline.Secrets, key, value string) error {
secrets.HuaweiCloudMaasApiKey = strPtr(value)
case "baseten_api_key":
secrets.BasetenApiKey = strPtr(value)
case "vercel_ai_gateway_api_key":
secrets.VercelAiGatewayApiKey = strPtr(value)
case "dify_api_key":
secrets.DifyApiKey = strPtr(value)
case "oca_api_key":
-2
View File
@@ -23,8 +23,6 @@ service ModelsService {
rpc refreshHuggingFaceModels(EmptyRequest) returns (OpenRouterCompatibleModelInfo);
// Refreshes and returns OpenAI models
rpc refreshOpenAiModels(OpenAiModelsRequest) returns (StringArray);
// Refreshes and returns Vercel AI Gateway models
rpc refreshVercelAiGatewayModelsRpc(EmptyRequest) returns (OpenRouterCompatibleModelInfo);
// Refreshes and returns Requesty models
rpc refreshRequestyModels(EmptyRequest) returns (OpenRouterCompatibleModelInfo);
// Refreshes and returns Hicap models
+4 -4
View File
@@ -367,10 +367,10 @@ function createHandlerForProvider(
return new VercelAIGatewayHandler({
onRetryAttempt: options.onRetryAttempt,
vercelAiGatewayApiKey: options.vercelAiGatewayApiKey,
vercelAiGatewayModelId:
mode === "plan" ? options.planModeVercelAiGatewayModelId : options.actModeVercelAiGatewayModelId,
vercelAiGatewayModelInfo:
mode === "plan" ? options.planModeVercelAiGatewayModelInfo : options.actModeVercelAiGatewayModelInfo,
openRouterModelId: mode === "plan" ? options.planModeOpenRouterModelId : options.actModeOpenRouterModelId,
openRouterModelInfo: mode === "plan" ? options.planModeOpenRouterModelInfo : options.actModeOpenRouterModelInfo,
thinkingBudgetTokens:
mode === "plan" ? options.planModeThinkingBudgetTokens : options.actModeThinkingBudgetTokens,
})
case "zai":
return new ZAiHandler({
+30 -6
View File
@@ -1,5 +1,5 @@
import { Anthropic } from "@anthropic-ai/sdk"
import { ModelInfo, vercelAiGatewayDefaultModelId, vercelAiGatewayDefaultModelInfo } from "@shared/api"
import { ModelInfo, openRouterDefaultModelId, openRouterDefaultModelInfo } from "@shared/api"
import OpenAI from "openai"
import type { ChatCompletionTool as OpenAITool } from "openai/resources/chat/completions"
import { fetch } from "@/shared/net"
@@ -11,8 +11,9 @@ import { createVercelAIGatewayStream } from "../transform/vercel-ai-gateway-stre
interface VercelAIGatewayHandlerOptions extends CommonApiHandlerOptions {
vercelAiGatewayApiKey?: string
vercelAiGatewayModelId?: string
vercelAiGatewayModelInfo?: ModelInfo
openRouterModelId?: string
openRouterModelInfo?: ModelInfo
thinkingBudgetTokens?: number
}
export class VercelAIGatewayHandler implements ApiHandler {
@@ -57,6 +58,7 @@ export class VercelAIGatewayHandler implements ApiHandler {
systemPrompt,
messages,
{ id: modelId, info: modelInfo },
this.options.thinkingBudgetTokens,
tools,
)
let didOutputUsage: boolean = false
@@ -76,6 +78,28 @@ export class VercelAIGatewayHandler implements ApiHandler {
yield* toolCallProcessor.processToolCallDeltas(delta.tool_calls)
}
// Reasoning tokens are returned separately from the content
if ("reasoning" in delta && delta.reasoning) {
yield {
type: "reasoning",
// @ts-ignore-next-line
reasoning: delta.reasoning,
}
}
// Reasoning details that can be passed back in API requests to preserve reasoning traces
if (
"reasoning_details" in delta &&
delta.reasoning_details &&
// @ts-ignore-next-line
delta.reasoning_details.length // exists and non-0
) {
yield {
type: "reasoning_details",
reasoning_details: delta.reasoning_details,
}
}
if (!didOutputUsage && chunk.usage) {
const inputTokens = chunk.usage.prompt_tokens || 0
const outputTokens =
@@ -109,11 +133,11 @@ export class VercelAIGatewayHandler implements ApiHandler {
}
getModel(): { id: string; info: ModelInfo } {
const modelId = this.options.vercelAiGatewayModelId
const modelInfo = this.options.vercelAiGatewayModelInfo
const modelId = this.options.openRouterModelId
const modelInfo = this.options.openRouterModelInfo
if (modelId && modelInfo) {
return { id: modelId, info: modelInfo }
}
return { id: vercelAiGatewayDefaultModelId, info: vercelAiGatewayDefaultModelInfo }
return { id: openRouterDefaultModelId, info: openRouterDefaultModelInfo }
}
}
@@ -1,5 +1,10 @@
import { Anthropic } from "@anthropic-ai/sdk"
import { ModelInfo } from "@shared/api"
import {
CLAUDE_SONNET_1M_SUFFIX,
ModelInfo,
openRouterClaudeSonnet41mModelId,
openRouterClaudeSonnet451mModelId,
} from "@shared/api"
import OpenAI from "openai"
import type { ChatCompletionTool as OpenAITool } from "openai/resources/chat/completions"
import { convertToOpenAiMessages } from "../transform/openai-format"
@@ -10,6 +15,7 @@ export async function createVercelAIGatewayStream(
systemPrompt: string,
messages: Anthropic.Messages.MessageParam[],
model: { id: string; info: ModelInfo },
thinkingBudgetTokens?: number,
tools?: OpenAITool[],
) {
// Convert Anthropic messages to OpenAI format
@@ -18,9 +24,15 @@ export async function createVercelAIGatewayStream(
...convertToOpenAiMessages(messages),
]
const isClaudeSonnet1m = model.id === openRouterClaudeSonnet41mModelId || model.id === openRouterClaudeSonnet451mModelId
if (isClaudeSonnet1m) {
// remove the custom :1m suffix, to create the model id openrouter API expects
model.id = model.id.slice(0, -CLAUDE_SONNET_1M_SUFFIX.length)
}
const isAnthropicModel = model.id.startsWith("anthropic/")
if (isAnthropicModel && model.info.supportsPromptCache) {
if (isAnthropicModel) {
openAiMessages[0] = {
role: "system",
content: systemPrompt,
@@ -46,12 +58,32 @@ export async function createVercelAIGatewayStream(
})
}
// Configure reasoning parameters similar to OpenRouter
let temperature: number | undefined = 0
let reasoning: { max_tokens: number } | undefined
if (isAnthropicModel) {
const budget_tokens = thinkingBudgetTokens || 0
const reasoningOn = budget_tokens !== 0
if (reasoningOn) {
temperature = undefined // extended thinking does not support non-1 temperature
reasoning = { max_tokens: budget_tokens }
}
} else if (thinkingBudgetTokens && model.info?.thinkingConfig && thinkingBudgetTokens > 0) {
temperature = undefined // extended thinking does not support non-1 temperature
reasoning = { max_tokens: thinkingBudgetTokens }
}
// @ts-ignore-next-line
const stream = await client.chat.completions.create({
model: model.id,
max_tokens: model.info.maxTokens,
temperature: 0.7,
temperature: temperature,
messages: openAiMessages,
stream: true,
stream_options: { include_usage: true },
include_reasoning: true,
...(reasoning ? { reasoning } : {}),
...getOpenAIToolParams(tools),
})
-11
View File
@@ -764,17 +764,6 @@ export class Controller {
return undefined
}
// Read Vercel AI Gateway models from disk cache
async readVercelAiGatewayModels(): Promise<Record<string, ModelInfo> | undefined> {
const vercelAiGatewayModelsFilePath = path.join(await ensureCacheDirectoryExists(), GlobalFileNames.vercelAiGatewayModels)
const fileExists = await fileExistsAtPath(vercelAiGatewayModelsFilePath)
if (fileExists) {
const fileContents = await fs.readFile(vercelAiGatewayModelsFilePath, "utf8")
return JSON.parse(fileContents)
}
return undefined
}
// Task history
async getTaskWithId(id: string): Promise<{
@@ -9,7 +9,6 @@ import { refreshBasetenModels } from "../models/refreshBasetenModels"
import { refreshGroqModels } from "../models/refreshGroqModels"
import { refreshHicapModels } from "../models/refreshHicapModels"
import { refreshOpenRouterModels } from "../models/refreshOpenRouterModels"
import { refreshVercelAiGatewayModels } from "../models/refreshVercelAiGatewayModels"
import { sendOpenRouterModelsEvent } from "../models/subscribeToOpenRouterModels"
/**
@@ -152,51 +151,6 @@ export async function initializeWebview(controller: Controller, _request: EmptyR
}
})
// Refresh Vercel AI Gateway models from API
refreshVercelAiGatewayModels(controller).then(async (models) => {
if (models && Object.keys(models).length > 0) {
// Update model info in state for Vercel AI Gateway (this needs to be done here since we don't want to update state while settings is open, and we may refresh models there)
const apiConfiguration = controller.stateManager.getApiConfiguration()
const planActSeparateModelsSetting = controller.stateManager.getGlobalSettingsKey("planActSeparateModelsSetting")
const currentMode = controller.stateManager.getGlobalSettingsKey("mode")
if (planActSeparateModelsSetting) {
// Separate models: update only current mode
const modelIdField =
currentMode === "plan" ? "planModeVercelAiGatewayModelId" : "actModeVercelAiGatewayModelId"
const modelInfoField =
currentMode === "plan" ? "planModeVercelAiGatewayModelInfo" : "actModeVercelAiGatewayModelInfo"
const modelId = apiConfiguration[modelIdField]
if (modelId && models[modelId]) {
controller.stateManager.setGlobalState(modelInfoField, models[modelId])
await controller.postStateToWebview()
}
} else {
// Shared models: update both plan and act modes
const planModelId = apiConfiguration.planModeVercelAiGatewayModelId
const actModelId = apiConfiguration.actModeVercelAiGatewayModelId
const updates: Partial<GlobalStateAndSettings> = {}
// Update plan mode model info if we have a model ID
if (planModelId && models[planModelId]) {
updates.planModeVercelAiGatewayModelInfo = models[planModelId]
}
// Update act mode model info if we have a model ID
if (actModelId && models[actModelId]) {
updates.actModeVercelAiGatewayModelInfo = models[actModelId]
}
// Post state update if we updated any model info
if (Object.keys(updates).length > 0) {
controller.stateManager.setGlobalStateBatch(updates)
await controller.postStateToWebview()
}
}
}
})
// Refresh Hicap models from API
refreshHicapModels(controller, EmptyRequest.create()).then(async (response) => {
if (response && response.models) {
-18
View File
@@ -530,8 +530,6 @@ export class StateManager {
planModeHuggingFaceModelInfo,
planModeHuaweiCloudMaasModelId,
planModeHuaweiCloudMaasModelInfo,
planModeVercelAiGatewayModelId,
planModeVercelAiGatewayModelInfo,
planModeOcaModelId,
planModeOcaModelInfo,
planModeHicapModelId,
@@ -568,8 +566,6 @@ export class StateManager {
actModeHuggingFaceModelInfo,
actModeHuaweiCloudMaasModelId,
actModeHuaweiCloudMaasModelInfo,
actModeVercelAiGatewayModelId,
actModeVercelAiGatewayModelInfo,
actModeOcaModelId,
actModeOcaModelInfo,
actModeHicapModelId,
@@ -610,8 +606,6 @@ export class StateManager {
planModeHuggingFaceModelInfo,
planModeHuaweiCloudMaasModelId,
planModeHuaweiCloudMaasModelInfo,
planModeVercelAiGatewayModelId,
planModeVercelAiGatewayModelInfo,
planModeOcaModelId,
planModeOcaModelInfo,
planModeHicapModelId,
@@ -647,8 +641,6 @@ export class StateManager {
actModeHuggingFaceModelInfo,
actModeHuaweiCloudMaasModelId,
actModeHuaweiCloudMaasModelInfo,
actModeVercelAiGatewayModelId,
actModeVercelAiGatewayModelInfo,
actModeOcaModelId,
actModeOcaModelInfo,
actModeHicapModelId,
@@ -1150,11 +1142,6 @@ export class StateManager {
planModeHuaweiCloudMaasModelInfo:
this.taskStateCache["planModeHuaweiCloudMaasModelInfo"] ||
this.globalStateCache["planModeHuaweiCloudMaasModelInfo"],
planModeVercelAiGatewayModelId:
this.taskStateCache["planModeVercelAiGatewayModelId"] || this.globalStateCache["planModeVercelAiGatewayModelId"],
planModeVercelAiGatewayModelInfo:
this.taskStateCache["planModeVercelAiGatewayModelInfo"] ||
this.globalStateCache["planModeVercelAiGatewayModelInfo"],
planModeOcaModelId: this.globalStateCache["planModeOcaModelId"],
planModeOcaModelInfo: this.globalStateCache["planModeOcaModelInfo"],
planModeHicapModelId: this.taskStateCache["planModeHicapModelId"] || this.globalStateCache["planModeHicapModelId"],
@@ -1222,11 +1209,6 @@ export class StateManager {
actModeHuaweiCloudMaasModelInfo:
this.taskStateCache["actModeHuaweiCloudMaasModelInfo"] ||
this.globalStateCache["actModeHuaweiCloudMaasModelInfo"],
actModeVercelAiGatewayModelId:
this.taskStateCache["actModeVercelAiGatewayModelId"] || this.globalStateCache["actModeVercelAiGatewayModelId"],
actModeVercelAiGatewayModelInfo:
this.taskStateCache["actModeVercelAiGatewayModelInfo"] ||
this.globalStateCache["actModeVercelAiGatewayModelInfo"],
actModeOcaModelId: this.globalStateCache["actModeOcaModelId"],
actModeOcaModelInfo: this.globalStateCache["actModeOcaModelInfo"],
actModeHicapModelId: this.globalStateCache["actModeHicapModelId"],
-14
View File
@@ -369,11 +369,6 @@ export async function readGlobalStateFromDisk(context: ExtensionContext): Promis
context.globalState.get<GlobalStateAndSettings["planModeBasetenModelId"]>("planModeBasetenModelId")
const planModeBasetenModelInfo =
context.globalState.get<GlobalStateAndSettings["planModeBasetenModelInfo"]>("planModeBasetenModelInfo")
const planModeVercelAiGatewayModelId =
context.globalState.get<GlobalStateAndSettings["planModeVercelAiGatewayModelId"]>("planModeVercelAiGatewayModelId")
const planModeVercelAiGatewayModelInfo = context.globalState.get<
GlobalStateAndSettings["planModeVercelAiGatewayModelInfo"]
>("planModeVercelAiGatewayModelInfo")
const planModeOcaModelId = context.globalState.get("planModeOcaModelId") as string | undefined
const planModeOcaModelInfo = context.globalState.get("planModeOcaModelInfo") as OcaModelInfo | undefined
const planModeHicapModelId =
@@ -443,11 +438,6 @@ export async function readGlobalStateFromDisk(context: ExtensionContext): Promis
context.globalState.get<GlobalStateAndSettings["actModeBasetenModelId"]>("actModeBasetenModelId")
const actModeBasetenModelInfo =
context.globalState.get<GlobalStateAndSettings["actModeBasetenModelInfo"]>("actModeBasetenModelInfo")
const actModeVercelAiGatewayModelId =
context.globalState.get<GlobalStateAndSettings["actModeVercelAiGatewayModelId"]>("actModeVercelAiGatewayModelId")
const actModeVercelAiGatewayModelInfo = context.globalState.get<
GlobalStateAndSettings["actModeVercelAiGatewayModelInfo"]
>("actModeVercelAiGatewayModelInfo")
const actModeOcaModelId = context.globalState.get("actModeOcaModelId") as string | undefined
const actModeOcaModelInfo = context.globalState.get("actModeOcaModelInfo") as OcaModelInfo | undefined
const sapAiCoreUseOrchestrationMode =
@@ -573,8 +563,6 @@ export async function readGlobalStateFromDisk(context: ExtensionContext): Promis
planModeHuaweiCloudMaasModelInfo,
planModeBasetenModelId,
planModeBasetenModelInfo,
planModeVercelAiGatewayModelId,
planModeVercelAiGatewayModelInfo,
planModeOcaModelId,
planModeOcaModelInfo,
planModeHicapModelId,
@@ -611,8 +599,6 @@ export async function readGlobalStateFromDisk(context: ExtensionContext): Promis
actModeHuaweiCloudMaasModelInfo,
actModeBasetenModelId,
actModeBasetenModelInfo,
actModeVercelAiGatewayModelId,
actModeVercelAiGatewayModelInfo,
actModeOcaModelId,
actModeOcaModelInfo,
actModeHicapModelId,
-21
View File
@@ -164,8 +164,6 @@ export interface ApiHandlerOptions {
planModeHuggingFaceModelInfo?: ModelInfo
planModeHuaweiCloudMaasModelId?: string
planModeHuaweiCloudMaasModelInfo?: ModelInfo
planModeVercelAiGatewayModelId?: string
planModeVercelAiGatewayModelInfo?: ModelInfo
planModeOcaModelId?: string
planModeOcaModelInfo?: OcaModelInfo
planModeAihubmixModelId?: string
@@ -203,8 +201,6 @@ export interface ApiHandlerOptions {
actModeHuggingFaceModelInfo?: ModelInfo
actModeHuaweiCloudMaasModelId?: string
actModeHuaweiCloudMaasModelInfo?: ModelInfo
actModeVercelAiGatewayModelId?: string
actModeVercelAiGatewayModelInfo?: ModelInfo
actModeOcaModelId?: string
actModeOcaModelInfo?: OcaModelInfo
actModeAihubmixModelId?: string
@@ -3101,23 +3097,6 @@ export const cerebrasModels = {
},
} as const satisfies Record<string, ModelInfo>
// VERCEL AI GATEWAY MODELS
export type VercelAIGatewayModelId = string
export const vercelAiGatewayDefaultModelId = "anthropic/claude-sonnet-4"
export const vercelAiGatewayDefaultModelInfo: ModelInfo = {
maxTokens: 64_000,
contextWindow: 200_000,
supportsImages: true,
supportsPromptCache: true,
inputPrice: 3.0,
outputPrice: 15.0,
cacheWritesPrice: 3.75,
cacheReadsPrice: 0.3,
description:
"Claude Sonnet 4 delivers superior intelligence across coding, agentic search, and AI agent capabilities. It's a powerful choice for agentic coding, and can complete tasks across the entire software development lifecycle—from initial planning to bug fixes, maintenance to large refactors. It offers strong performance in both planning and solving for complex coding tasks, making it an ideal choice to power end-to-end software development processes.\n\nRead more in the [blog post here](https://www.anthropic.com/claude/sonnet)",
}
// Groq
// https://console.groq.com/docs/models
// https://groq.com/pricing/
@@ -520,8 +520,6 @@ export function convertApiConfigurationToProto(config: ApiConfiguration): ProtoA
planModeHuaweiCloudMaasModelId: config.planModeHuaweiCloudMaasModelId,
planModeHuaweiCloudMaasModelInfo: convertModelInfoToProtoOpenRouter(config.planModeHuaweiCloudMaasModelInfo),
planModeSapAiCoreDeploymentId: config.planModeSapAiCoreDeploymentId,
planModeVercelAiGatewayModelId: config.planModeVercelAiGatewayModelId,
planModeVercelAiGatewayModelInfo: convertModelInfoToProtoOpenRouter(config.planModeVercelAiGatewayModelInfo),
planModeOcaModelId: config.planModeOcaModelId,
planModeOcaModelInfo: convertOcaModelInfoToProtoOcaModelInfo(config.planModeOcaModelInfo),
planModeAihubmixModelId: config.planModeAihubmixModelId,
@@ -559,8 +557,6 @@ export function convertApiConfigurationToProto(config: ApiConfiguration): ProtoA
actModeHuaweiCloudMaasModelId: config.actModeHuaweiCloudMaasModelId,
actModeHuaweiCloudMaasModelInfo: convertModelInfoToProtoOpenRouter(config.actModeHuaweiCloudMaasModelInfo),
actModeSapAiCoreDeploymentId: config.actModeSapAiCoreDeploymentId,
actModeVercelAiGatewayModelId: config.actModeVercelAiGatewayModelId,
actModeVercelAiGatewayModelInfo: convertModelInfoToProtoOpenRouter(config.actModeVercelAiGatewayModelInfo),
actModeOcaModelId: config.actModeOcaModelId,
actModeOcaModelInfo: convertOcaModelInfoToProtoOcaModelInfo(config.actModeOcaModelInfo),
actModeAihubmixModelId: config.actModeAihubmixModelId,
@@ -689,8 +685,6 @@ export function convertProtoToApiConfiguration(protoConfig: ProtoApiConfiguratio
planModeHuaweiCloudMaasModelId: protoConfig.planModeHuaweiCloudMaasModelId,
planModeHuaweiCloudMaasModelInfo: convertProtoToModelInfo(protoConfig.planModeHuaweiCloudMaasModelInfo),
planModeSapAiCoreDeploymentId: protoConfig.planModeSapAiCoreDeploymentId,
planModeVercelAiGatewayModelId: protoConfig.planModeVercelAiGatewayModelId,
planModeVercelAiGatewayModelInfo: convertProtoToModelInfo(protoConfig.planModeVercelAiGatewayModelInfo),
planModeOcaModelId: protoConfig.planModeOcaModelId,
planModeOcaModelInfo: convertProtoOcaModelInfoToOcaModelInfo(protoConfig.planModeOcaModelInfo),
planModeAihubmixModelId: protoConfig.planModeAihubmixModelId,
@@ -729,8 +723,6 @@ export function convertProtoToApiConfiguration(protoConfig: ProtoApiConfiguratio
actModeHuaweiCloudMaasModelId: protoConfig.actModeHuaweiCloudMaasModelId,
actModeHuaweiCloudMaasModelInfo: convertProtoToModelInfo(protoConfig.actModeHuaweiCloudMaasModelInfo),
actModeSapAiCoreDeploymentId: protoConfig.actModeSapAiCoreDeploymentId,
actModeVercelAiGatewayModelId: protoConfig.actModeVercelAiGatewayModelId,
actModeVercelAiGatewayModelInfo: convertProtoToModelInfo(protoConfig.actModeVercelAiGatewayModelInfo),
actModeOcaModelId: protoConfig.actModeOcaModelId,
actModeOcaModelInfo: convertProtoOcaModelInfoToOcaModelInfo(protoConfig.actModeOcaModelInfo),
actModeAihubmixModelId: protoConfig.actModeAihubmixModelId,
-4
View File
@@ -188,10 +188,6 @@ export interface Settings {
actModeHuggingFaceModelInfo: ModelInfo | undefined
actModeHuaweiCloudMaasModelId: string | undefined
actModeHuaweiCloudMaasModelInfo: ModelInfo | undefined
planModeVercelAiGatewayModelId: string | undefined
planModeVercelAiGatewayModelInfo: ModelInfo | undefined
actModeVercelAiGatewayModelId: string | undefined
actModeVercelAiGatewayModelInfo: ModelInfo | undefined
actModeOcaModelId: string | undefined
actModeOcaModelInfo: OcaModelInfo | undefined
actModeHicapModelId: string | undefined
@@ -147,7 +147,7 @@ const OpenRouterModelPicker: React.FC<OpenRouterModelPickerProps> = ({ isPopup,
return !id.includes(":free")
})
}
// For OpenRouter provider: exclude Cline-specific models
// For OpenRouter and Vercel AI Gateway providers: exclude Cline-specific models
return unfilteredModelIds.filter((id) => !id.startsWith("cline/"))
}, [openRouterModels, modeFields.apiProvider])
@@ -423,7 +423,7 @@ const OpenRouterModelPicker: React.FC<OpenRouterModelPickerProps> = ({ isPopup,
anthropic/claude-sonnet-4.5.
</VSCodeLink>
You can also try searching "free" for no-cost options currently available. OpenRouter presets can be used by
entering <strong>@preset/your-preset-name</strong>.
entering @preset/your-preset-name
</p>
)}
</div>
@@ -1,14 +1,8 @@
import { EmptyRequest } from "@shared/proto/cline/common"
import { fromProtobufModels } from "@shared/proto-conversions/models/typeConversion"
import { Mode } from "@shared/storage/types"
import { useCallback, useMemo, useState } from "react"
import { useMount } from "react-use"
import { VSCodeLink } from "@vscode/webview-ui-toolkit/react"
import { useExtensionState } from "@/context/ExtensionStateContext"
import { ModelsServiceClient } from "@/services/grpc-client"
import { DebouncedTextField } from "../common/DebouncedTextField"
import { ModelInfoView } from "../common/ModelInfoView"
import { ModelSelector } from "../common/ModelSelector"
import { normalizeApiConfiguration } from "../utils/providerUtils"
import OpenRouterModelPicker from "../OpenRouterModelPicker"
import { useApiConfigurationHandlers } from "../utils/useApiConfigurationHandlers"
/**
@@ -24,62 +18,8 @@ interface VercelAIGatewayProviderProps {
* The Vercel AI Gateway provider configuration component
*/
export const VercelAIGatewayProvider = ({ showModelOptions, isPopup, currentMode }: VercelAIGatewayProviderProps) => {
const { apiConfiguration, vercelAiGatewayModels, setVercelAiGatewayModels } = useExtensionState()
const { handleFieldChange, handleModeFieldsChange } = useApiConfigurationHandlers()
const [isLoadingModels, setIsLoadingModels] = useState(false)
// Get the normalized configuration (includes defaults)
const { selectedModelId, selectedModelInfo } = normalizeApiConfiguration(apiConfiguration, currentMode)
// Fetch models only once when component mounts
useMount(() => {
if (showModelOptions) {
setIsLoadingModels(true)
ModelsServiceClient.refreshVercelAiGatewayModelsRpc(EmptyRequest.create({}))
.then((response) => {
if (response && response.models) {
setVercelAiGatewayModels(fromProtobufModels(response.models))
}
setIsLoadingModels(false)
})
.catch((error) => {
console.error("Failed to fetch Vercel AI Gateway models:", error)
setVercelAiGatewayModels({})
setIsLoadingModels(false)
})
}
})
const handleModelChange = useCallback(
(modelId: string) => {
handleModeFieldsChange(
{
vercelAiGatewayModelId: { plan: "planModeVercelAiGatewayModelId", act: "actModeVercelAiGatewayModelId" },
vercelAiGatewayModelInfo: {
plan: "planModeVercelAiGatewayModelInfo",
act: "actModeVercelAiGatewayModelInfo",
},
},
{
vercelAiGatewayModelId: modelId,
vercelAiGatewayModelInfo: vercelAiGatewayModels[modelId],
},
currentMode,
)
},
[vercelAiGatewayModels, handleModeFieldsChange, currentMode],
)
const hasModels = useMemo(() => {
return Object.keys(vercelAiGatewayModels).length > 0
}, [vercelAiGatewayModels])
const displayModelInfo = useMemo(() => {
if (hasModels && selectedModelId && vercelAiGatewayModels[selectedModelId]) {
return vercelAiGatewayModels[selectedModelId]
}
return selectedModelInfo
}, [hasModels, selectedModelId, vercelAiGatewayModels, selectedModelInfo])
const { apiConfiguration } = useExtensionState()
const { handleFieldChange } = useApiConfigurationHandlers()
return (
<div>
@@ -95,81 +35,27 @@ export const VercelAIGatewayProvider = ({ showModelOptions, isPopup, currentMode
<p
style={{
fontSize: "12px",
marginTop: 3,
marginTop: "5px",
color: "var(--vscode-descriptionForeground)",
}}>
This key is stored locally and only used to make API requests from this extension.
{!apiConfiguration?.vercelAiGatewayApiKey && (
<span>
<>
{" "}
<a
You can get a Vercel AI Gateway API key by{" "}
<VSCodeLink
href="https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai"
style={{
color: "var(--vscode-textLink-foreground)",
textDecoration: "none",
}}>
You can get a Vercel AI Gateway API key by signing up here.
</a>
</span>
style={{ display: "inline", fontSize: "inherit" }}>
signing up here.
</VSCodeLink>
</>
)}
</p>
</div>
{showModelOptions && (
<>
{hasModels ? (
<ModelSelector
label="Model"
models={vercelAiGatewayModels}
onChange={(e) => handleModelChange(e.target.value)}
selectedModelId={selectedModelId || ""}
/>
) : (
<>
<DebouncedTextField
initialValue={selectedModelId || ""}
onChange={(value) =>
handleModeFieldsChange(
{
vercelAiGatewayModelId: {
plan: "planModeVercelAiGatewayModelId",
act: "actModeVercelAiGatewayModelId",
},
vercelAiGatewayModelInfo: {
plan: "planModeVercelAiGatewayModelInfo",
act: "actModeVercelAiGatewayModelInfo",
},
},
{
vercelAiGatewayModelId: value,
vercelAiGatewayModelInfo: undefined,
},
currentMode,
)
}
placeholder={"Enter Model ID (e.g., openai/gpt-4o)..."}
style={{ width: "100%", marginBottom: 10 }}>
<span style={{ fontWeight: 500 }}>Model ID</span>
</DebouncedTextField>
{!isLoadingModels && (
<p
style={{
fontSize: "12px",
marginTop: "-5px",
marginBottom: "10px",
color: "var(--vscode-descriptionForeground)",
fontStyle: "italic",
}}>
Unable to fetch models from Vercel AI Gateway.
</p>
)}
</>
)}
{displayModelInfo && (
<ModelInfoView isPopup={isPopup} modelInfo={displayModelInfo} selectedModelId={selectedModelId} />
)}
<OpenRouterModelPicker currentMode={currentMode} isPopup={isPopup} />
</>
)}
</div>
@@ -59,8 +59,6 @@ import {
sambanovaModels,
sapAiCoreDefaultModelId,
sapAiCoreModels,
vercelAiGatewayDefaultModelId,
vercelAiGatewayDefaultModelInfo,
vertexDefaultModelId,
vertexModels,
xaiDefaultModelId,
@@ -331,18 +329,17 @@ export function normalizeApiConfiguration(
},
}
case "vercel-ai-gateway":
const vercelAiGatewayModelId =
// Vercel AI Gateway uses OpenRouter model fields
const vercelModelId =
currentMode === "plan" ? apiConfiguration?.planModeOpenRouterModelId : apiConfiguration?.actModeOpenRouterModelId
const vercelModelInfo =
currentMode === "plan"
? apiConfiguration?.planModeVercelAiGatewayModelId
: apiConfiguration?.actModeVercelAiGatewayModelId
const vercelAiGatewayModelInfo =
currentMode === "plan"
? apiConfiguration?.planModeVercelAiGatewayModelInfo
: apiConfiguration?.actModeVercelAiGatewayModelInfo
? apiConfiguration?.planModeOpenRouterModelInfo
: apiConfiguration?.actModeOpenRouterModelInfo
return {
selectedProvider: provider,
selectedModelId: vercelAiGatewayModelId || vercelAiGatewayDefaultModelId,
selectedModelInfo: vercelAiGatewayModelInfo || vercelAiGatewayDefaultModelInfo,
selectedModelId: vercelModelId || openRouterDefaultModelId,
selectedModelInfo: vercelModelInfo || openRouterDefaultModelInfo,
}
case "zai":
const zaiModels = apiConfiguration?.zaiApiLine === "china" ? mainlandZAiModels : internationalZAiModels
@@ -412,7 +409,6 @@ export function getModeSpecificFields(apiConfiguration: ApiConfiguration | undef
basetenModelId: undefined,
huggingFaceModelId: undefined,
huaweiCloudMaasModelId: undefined,
vercelAiGatewayModelId: undefined,
hicapModelId: undefined,
aihubmixModelId: undefined,
@@ -424,7 +420,6 @@ export function getModeSpecificFields(apiConfiguration: ApiConfiguration | undef
groqModelInfo: undefined,
basetenModelInfo: undefined,
huggingFaceModelInfo: undefined,
vercelAiGatewayModelInfo: undefined,
vsCodeLmModelSelector: undefined,
aihubmixModelInfo: undefined,
@@ -462,8 +457,6 @@ export function getModeSpecificFields(apiConfiguration: ApiConfiguration | undef
mode === "plan" ? apiConfiguration.planModeHuggingFaceModelId : apiConfiguration.actModeHuggingFaceModelId,
huaweiCloudMaasModelId:
mode === "plan" ? apiConfiguration.planModeHuaweiCloudMaasModelId : apiConfiguration.actModeHuaweiCloudMaasModelId,
vercelAiGatewayModelId:
mode === "plan" ? apiConfiguration.planModeVercelAiGatewayModelId : apiConfiguration.actModeVercelAiGatewayModelId,
ocaModelId: mode === "plan" ? apiConfiguration.planModeOcaModelId : apiConfiguration.actModeOcaModelId,
hicapModelId: mode === "plan" ? apiConfiguration.planModeHicapModelId : apiConfiguration.actModeHicapModelId,
aihubmixModelId: mode === "plan" ? apiConfiguration.planModeAihubmixModelId : apiConfiguration.actModeAihubmixModelId,
@@ -479,10 +472,6 @@ export function getModeSpecificFields(apiConfiguration: ApiConfiguration | undef
basetenModelInfo: mode === "plan" ? apiConfiguration.planModeBasetenModelInfo : apiConfiguration.actModeBasetenModelInfo,
huggingFaceModelInfo:
mode === "plan" ? apiConfiguration.planModeHuggingFaceModelInfo : apiConfiguration.actModeHuggingFaceModelInfo,
vercelAiGatewayModelInfo:
mode === "plan"
? apiConfiguration.planModeVercelAiGatewayModelInfo
: apiConfiguration.actModeVercelAiGatewayModelInfo,
vsCodeLmModelSelector:
mode === "plan" ? apiConfiguration.planModeVsCodeLmModelSelector : apiConfiguration.actModeVsCodeLmModelSelector,
hicapModelInfo: mode === "plan" ? apiConfiguration.planModeHicapModelInfo : apiConfiguration.actModeHicapModelInfo,
@@ -650,10 +639,11 @@ export async function syncModeConfigurations(
break
case "vercel-ai-gateway":
updates.planModeVercelAiGatewayModelId = sourceFields.vercelAiGatewayModelId
updates.actModeVercelAiGatewayModelId = sourceFields.vercelAiGatewayModelId
updates.planModeVercelAiGatewayModelInfo = sourceFields.vercelAiGatewayModelInfo
updates.actModeVercelAiGatewayModelInfo = sourceFields.vercelAiGatewayModelInfo
// Vercel AI Gateway uses OpenRouter model fields
updates.planModeOpenRouterModelId = sourceFields.openRouterModelId
updates.actModeOpenRouterModelId = sourceFields.openRouterModelId
updates.planModeOpenRouterModelInfo = sourceFields.openRouterModelInfo
updates.actModeOpenRouterModelInfo = sourceFields.openRouterModelInfo
break
case "oca":
updates.planModeOcaModelId = sourceFields.ocaModelId
@@ -26,8 +26,6 @@ import {
openRouterDefaultModelInfo,
requestyDefaultModelId,
requestyDefaultModelInfo,
vercelAiGatewayDefaultModelId,
vercelAiGatewayDefaultModelInfo,
} from "../../../src/shared/api"
import type { McpMarketplaceCatalog, McpServer, McpViewTab } from "../../../src/shared/mcp"
import { McpServiceClient, ModelsServiceClient, StateServiceClient, UiServiceClient } from "../services/grpc-client"
@@ -42,7 +40,6 @@ export interface ExtensionStateContextType extends ExtensionState {
groqModels: Record<string, ModelInfo>
basetenModels: Record<string, ModelInfo>
huggingFaceModels: Record<string, ModelInfo>
vercelAiGatewayModels: Record<string, ModelInfo>
mcpServers: McpServer[]
mcpMarketplaceCatalog: McpMarketplaceCatalog
totalTasksSize: number | null
@@ -71,7 +68,6 @@ export interface ExtensionStateContextType extends ExtensionState {
setGroqModels: (value: Record<string, ModelInfo>) => void
setBasetenModels: (value: Record<string, ModelInfo>) => void
setHuggingFaceModels: (value: Record<string, ModelInfo>) => void
setVercelAiGatewayModels: (value: Record<string, ModelInfo>) => void
setGlobalClineRulesToggles: (toggles: Record<string, boolean>) => void
setLocalClineRulesToggles: (toggles: Record<string, boolean>) => void
setLocalCursorRulesToggles: (toggles: Record<string, boolean>) => void
@@ -257,9 +253,6 @@ export const ExtensionStateContextProvider: React.FC<{
[basetenDefaultModelId]: basetenModels[basetenDefaultModelId],
})
const [huggingFaceModels, setHuggingFaceModels] = useState<Record<string, ModelInfo>>({})
const [vercelAiGatewayModels, setVercelAiGatewayModels] = useState<Record<string, ModelInfo>>({
[vercelAiGatewayDefaultModelId]: vercelAiGatewayDefaultModelInfo,
})
const [mcpServers, setMcpServers] = useState<McpServer[]>([])
const [mcpMarketplaceCatalog, setMcpMarketplaceCatalog] = useState<McpMarketplaceCatalog>({ items: [] })
@@ -658,7 +651,6 @@ export const ExtensionStateContextProvider: React.FC<{
groqModels: groqModelsState,
basetenModels: basetenModelsState,
huggingFaceModels,
vercelAiGatewayModels,
mcpServers,
mcpMarketplaceCatalog,
totalTasksSize,
@@ -704,7 +696,6 @@ export const ExtensionStateContextProvider: React.FC<{
setGroqModels: (models: Record<string, ModelInfo>) => setGroqModels(models),
setBasetenModels: (models: Record<string, ModelInfo>) => setBasetenModels(models),
setHuggingFaceModels: (models: Record<string, ModelInfo>) => setHuggingFaceModels(models),
setVercelAiGatewayModels: (models: Record<string, ModelInfo>) => setVercelAiGatewayModels(models),
setMcpMarketplaceCatalog: (catalog: McpMarketplaceCatalog) => setMcpMarketplaceCatalog(catalog),
setShowMcp,
closeMcpView,