Roo-Code/src/api/providers/vertex.ts
Roo Code edbd11269a feat: allow custom model ID passthrough for Vertex AI providers
- Add gemini-3.1-flash-lite-preview to vertex models list
- Update VertexHandler.getModel() to pass through unknown model IDs
  with sensible default ModelInfo instead of falling back to default model
- Update AnthropicVertexHandler.getModel() with same custom model ID
  passthrough behavior
- Add tests for custom model ID passthrough in both handlers

Closes #12232
2026-05-08 05:28:36 +00:00

59 lines
1.8 KiB
TypeScript

import { type ModelInfo, type VertexModelId, vertexDefaultModelId, vertexModels } from "@roo-code/types"
import type { ApiHandlerOptions } from "../../shared/api"
import { getModelParams } from "../transform/model-params"
import { GeminiHandler } from "./gemini"
import { SingleCompletionHandler } from "../index"
export class VertexHandler extends GeminiHandler implements SingleCompletionHandler {
constructor(options: ApiHandlerOptions) {
super({ ...options, isVertex: true })
}
override getModel() {
const modelId = this.options.apiModelId
let id: string
let info: ModelInfo
if (modelId && modelId in vertexModels) {
id = modelId as VertexModelId
info = vertexModels[id as VertexModelId]
} else if (modelId) {
// Pass through custom/unknown model IDs with sensible defaults
id = modelId
info = {
maxTokens: 8192,
contextWindow: 1_048_576,
supportsImages: true,
supportsPromptCache: false,
inputPrice: 0,
outputPrice: 0,
}
} else {
id = vertexDefaultModelId
info = vertexModels[vertexDefaultModelId]
}
const params = getModelParams({
format: "gemini",
modelId: id,
model: info,
settings: this.options,
defaultTemperature: info.defaultTemperature ?? 1,
})
// Vertex Gemini models perform better with the edit tool instead of apply_diff.
info = {
...info,
excludedTools: [...new Set([...(info.excludedTools || []), "apply_diff"])],
includedTools: [...new Set([...(info.includedTools || []), "edit"])],
}
// The `:thinking` suffix indicates that the model is a "Hybrid"
// reasoning model and that reasoning is required to be enabled.
// The actual model ID honored by Gemini's API does not have this
// suffix.
return { id: id.endsWith(":thinking") ? id.replace(":thinking", "") : id, info, ...params }
}
}