This commit is contained in:
Deleted user 2026-05-27 11:35:28 +08:00 committed by GitHub
commit 468f08712b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 28 additions and 31 deletions

View file

@ -154,13 +154,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", () => {

View file

@ -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", () => {

View file

@ -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(

View file

@ -308,8 +308,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 (

View file

@ -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 }
}
}

View file

@ -339,8 +339,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",

View file

@ -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",

View file

@ -1111,9 +1111,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",

View file

@ -1429,10 +1429,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",

View file

@ -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,

View file

@ -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,