Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/api/providers/__tests__/gemini.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,14 @@ describe("GeminiHandler", () => {
expect(modelInfo.info).toBeDefined()
})

it("should return default model if invalid model specified", () => {
it("should preserve custom model id when not in known models", () => {
const invalidHandler = new GeminiHandler({
apiModelId: "invalid-model",
apiModelId: "custom-model",
geminiApiKey: "test-key",
})
const modelInfo = invalidHandler.getModel()
expect(modelInfo.id).toBe(geminiDefaultModelId) // Default model
expect(modelInfo.id).toBe("custom-model") // Custom model ID is preserved
expect(modelInfo.info).toBeDefined() // Falls back to default model info
})

it("should exclude apply_diff and include edit in tool preferences", () => {
Expand Down
6 changes: 3 additions & 3 deletions src/api/providers/__tests__/openai-codex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ describe("OpenAiCodexHandler.getModel", () => {
},
)

it("should fall back to default model when an invalid model id is provided", () => {
it("should preserve custom model id when not in known models", () => {
const handler = new OpenAiCodexHandler({ apiModelId: "not-a-real-model" })
const model = handler.getModel()

expect(model.id).toBe("gpt-5.3-codex")
expect(model.info).toBeDefined()
expect(model.id).toBe("not-a-real-model") // Custom model ID is preserved
expect(model.info).toBeDefined() // Falls back to default model info
})

it("should use Spark-specific limits and capabilities", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/api/providers/anthropic-vertex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ export class AnthropicVertexHandler extends BaseProvider implements SingleComple

getModel() {
const modelId = this.options.apiModelId
let id = modelId && modelId in vertexModels ? (modelId as VertexModelId) : vertexDefaultModelId
let info: ModelInfo = vertexModels[id]
let id = modelId ?? vertexDefaultModelId
let info: ModelInfo = vertexModels[id as VertexModelId] ?? vertexModels[vertexDefaultModelId]

// Check if 1M context beta should be enabled for supported models
const supports1MContext = VERTEX_1M_CONTEXT_MODEL_IDS.includes(
Expand Down
4 changes: 2 additions & 2 deletions src/api/providers/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa

getModel() {
const modelId = this.options.apiModelId
let id = modelId && modelId in anthropicModels ? (modelId as AnthropicModelId) : anthropicDefaultModelId
let info: ModelInfo = anthropicModels[id]
let id = modelId ?? anthropicDefaultModelId
let info: ModelInfo = anthropicModels[id as AnthropicModelId] ?? anthropicModels[anthropicDefaultModelId]

// If 1M context beta is enabled for supported models, update the model info
if (
Expand Down
8 changes: 3 additions & 5 deletions src/api/providers/base-openai-compatible-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,9 @@ export abstract class BaseOpenAiCompatibleProvider<ModelName extends string>
}

override getModel() {
const id =
this.options.apiModelId && this.options.apiModelId in this.providerModels
? (this.options.apiModelId as ModelName)
: this.defaultProviderModelId
const id = this.options.apiModelId ?? this.defaultProviderModelId
const info = this.providerModels[id as ModelName] ?? this.providerModels[this.defaultProviderModelId]

return { id, info: this.providerModels[id] }
return { id, info }
}
}
4 changes: 2 additions & 2 deletions src/api/providers/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl

override getModel() {
const modelId = this.options.apiModelId
let id = modelId && modelId in geminiModels ? (modelId as GeminiModelId) : geminiDefaultModelId
let info: ModelInfo = geminiModels[id]
let id = modelId ?? geminiDefaultModelId
let info: ModelInfo = geminiModels[id as GeminiModelId] ?? geminiModels[geminiDefaultModelId]

const params = getModelParams({
format: "gemini",
Expand Down
4 changes: 2 additions & 2 deletions src/api/providers/minimax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ export class MiniMaxHandler extends BaseProvider implements SingleCompletionHand

getModel() {
const modelId = this.options.apiModelId
const id = modelId && modelId in minimaxModels ? (modelId as MinimaxModelId) : minimaxDefaultModelId
const info = minimaxModels[id]
const id = modelId ?? minimaxDefaultModelId
const info = minimaxModels[id as MinimaxModelId] ?? minimaxModels[minimaxDefaultModelId]

const params = getModelParams({
format: "anthropic",
Expand Down
5 changes: 3 additions & 2 deletions src/api/providers/openai-codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1117,9 +1117,10 @@ export class OpenAiCodexHandler extends BaseProvider implements SingleCompletion
override getModel() {
const modelId = this.options.apiModelId

let id = modelId && modelId in openAiCodexModels ? (modelId as OpenAiCodexModelId) : openAiCodexDefaultModelId
let id = modelId ?? openAiCodexDefaultModelId

const info: ModelInfo = openAiCodexModels[id]
const info: ModelInfo =
openAiCodexModels[id as OpenAiCodexModelId] ?? openAiCodexModels[openAiCodexDefaultModelId]

const params = getModelParams({
format: "openai",
Expand Down
6 changes: 3 additions & 3 deletions src/api/providers/openai-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1435,10 +1435,10 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
override getModel() {
const modelId = this.options.apiModelId

let id =
modelId && modelId in openAiNativeModels ? (modelId as OpenAiNativeModelId) : openAiNativeDefaultModelId
let id = modelId ?? openAiNativeDefaultModelId

const info: ModelInfo = openAiNativeModels[id]
const info: ModelInfo =
openAiNativeModels[id as OpenAiNativeModelId] ?? openAiNativeModels[openAiNativeDefaultModelId]

const params = getModelParams({
format: "openai",
Expand Down
4 changes: 2 additions & 2 deletions src/api/providers/vertex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class VertexHandler extends GeminiHandler implements SingleCompletionHand

override getModel() {
const modelId = this.options.apiModelId
let id = modelId && modelId in vertexModels ? (modelId as VertexModelId) : vertexDefaultModelId
let info: ModelInfo = vertexModels[id]
let id = modelId ?? vertexDefaultModelId
let info: ModelInfo = vertexModels[id as VertexModelId] ?? vertexModels[vertexDefaultModelId]
const params = getModelParams({
format: "gemini",
modelId: id,
Expand Down
7 changes: 2 additions & 5 deletions src/api/providers/xai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ export class XAIHandler extends BaseProvider implements SingleCompletionHandler
}

override getModel() {
const id =
this.options.apiModelId && this.options.apiModelId in xaiModels
? (this.options.apiModelId as XAIModelId)
: xaiDefaultModelId
const id = this.options.apiModelId ?? xaiDefaultModelId

const info = xaiModels[id]
const info = xaiModels[id as XAIModelId] ?? xaiModels[xaiDefaultModelId]
const params = getModelParams({
format: "openai",
modelId: id,
Expand Down
Loading