Skip to content

Commit eaf7417

Browse files
fix(gemini): use own-property check for known model ids (#227)
modelId in geminiModels also matches inherited Object.prototype keys (e.g. "toString"), resolving info to a function. Use Object.hasOwn so only real model keys match; prototype-key ids fall through to the default.
1 parent bdece7e commit eaf7417

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/api/providers/__tests__/gemini.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ describe("GeminiHandler", () => {
194194
expect(modelInfo.info.tiers).toBeUndefined()
195195
})
196196

197+
it("should not treat Object prototype keys as known models", () => {
198+
// `"toString" in geminiModels` is true via the prototype chain, which would
199+
// otherwise resolve `info` to a function. An own-property check avoids this.
200+
const protoHandler = new GeminiHandler({
201+
apiModelId: "toString",
202+
geminiApiKey: "test-key",
203+
})
204+
const modelInfo = protoHandler.getModel()
205+
expect(modelInfo.id).toBe(geminiDefaultModelId)
206+
expect(modelInfo.info).toBeDefined()
207+
})
208+
197209
it("should exclude apply_diff and include edit in tool preferences", () => {
198210
const modelInfo = handler.getModel()
199211
expect(modelInfo.info.excludedTools).toContain("apply_diff")

src/api/providers/gemini.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
493493
let id: string
494494
let info: ModelInfo
495495

496-
if (modelId && modelId in geminiModels) {
496+
if (modelId && Object.hasOwn(geminiModels, modelId)) {
497497
id = modelId
498498
info = geminiModels[modelId as GeminiModelId]
499499
} else if (modelId && modelId.toLowerCase().startsWith("gemini-")) {

0 commit comments

Comments
 (0)