fix: preserve custom model name in Anthropic provider instead of falling back to default

This commit is contained in:
Roo Code 2026-04-05 08:19:59 +00:00
parent 137d3f4fd8
commit ec40a48750
2 changed files with 38 additions and 2 deletions

View file

@ -343,6 +343,39 @@ describe("AnthropicHandler", () => {
expect(model.info.inputPrice).toBe(6.0)
expect(model.info.outputPrice).toBe(22.5)
})
it("should pass through custom/unknown model IDs instead of falling back to default", () => {
const handler = new AnthropicHandler({
apiKey: "test-api-key",
apiModelId: "qwen/qwen3.6-plus",
})
const model = handler.getModel()
expect(model.id).toBe("qwen/qwen3.6-plus")
// Should use default model info as fallback for unknown models
expect(model.info).toBeDefined()
expect(model.info.contextWindow).toBeDefined()
})
it("should use default model ID when no model ID is provided at all", () => {
const handler = new AnthropicHandler({
apiKey: "test-api-key",
apiModelId: undefined,
})
const model = handler.getModel()
expect(model.id).toBeDefined()
// Should fall back to anthropicDefaultModelId, not an empty string
expect(model.id).not.toBe("")
})
it("should preserve custom model ID when using custom base URL", () => {
const handler = new AnthropicHandler({
apiKey: "test-api-key",
anthropicBaseUrl: "http://localhost:3000/api",
apiModelId: "my-custom-model",
})
const model = handler.getModel()
expect(model.id).toBe("my-custom-model")
})
})
describe("reasoning block filtering", () => {

View file

@ -334,8 +334,11 @@ 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]
const isKnownModel = modelId !== undefined && modelId in anthropicModels
let id: string = isKnownModel ? (modelId as AnthropicModelId) : modelId || anthropicDefaultModelId
let info: ModelInfo = isKnownModel
? anthropicModels[modelId as AnthropicModelId]
: anthropicModels[anthropicDefaultModelId]
// If 1M context beta is enabled for supported models, update the model info
if (