diff --git a/memory-bank/aiConfig.md b/memory-bank/aiConfig.md index 93ee324..d660232 100644 --- a/memory-bank/aiConfig.md +++ b/memory-bank/aiConfig.md @@ -649,7 +649,8 @@ known generation, the existing GPT-5.x and GPT-6 catch-alls still apply. Gemini (`gemini-helpers.ts`) keys its entries by a representative id per variant and version (`gemini-3.7-flash`, `gemini-3-pro`); the exported `findGeminiVariantDonor` (`gemini-variant.ts`) parses -`gemini-[.]-` and returns the +`gemini-[.]-` (`pro`, `flash`, `flash-lite`, and the +Gemini 4 names `argon`, `carbon`, `hydrogen`, `neon`) and returns the same-variant known id with the greatest version at or below the requested one, plus whether it is the variant's newest: `gemini-3.9-flash` → 3.7/3.8 Flash, `gemini-4-pro` → 3 Pro. The table ignores the newest flag; the diff --git a/memory-bank/geminiInteractions.md b/memory-bank/geminiInteractions.md index 9467a9f..5c4036b 100644 --- a/memory-bank/geminiInteractions.md +++ b/memory-bank/geminiInteractions.md @@ -124,9 +124,11 @@ Gemini 3.6/3.7 Flash were invisible until manually allowlisted): - **Future versions inherit.** `getGeminiInteractionsProfile` falls back, after an exact miss, to ai-config's `findGeminiVariantDonor`: a Gemini chat id (`isGeminiApiChatModel`) whose variant (`pro`, `flash`, - `flash-lite`) version is at or above that variant's newest profiled id - takes that profile (`gemini-3.9-flash` → `gemini-3.8-flash`, - `gemini-4-pro` and the alias `gemini-3.1-pro` → `gemini-3.1-pro-preview`). + `flash-lite`, or a Gemini 4 name: `argon`, `carbon`, `hydrogen`, `neon`) + version is at or above that variant's newest profiled id takes that + profile (`gemini-3.9-flash` → `gemini-3.8-flash`, `gemini-4-pro` and the + alias `gemini-3.1-pro` → `gemini-3.1-pro-preview`, + `gemini-4-argon-cyber-permissive` → `gemini-4-argon`). An id below the newest profile (`gemini-3-pro-preview`) gets nothing, since plain "nearest older" would hand it 2.5 Pro's `medium`. The chat gate matters because `GeminiClient` looks up whatever id it is given: diff --git a/memory-bank/opencodeRouting.md b/memory-bank/opencodeRouting.md index 3dc897a..11ec236 100644 --- a/memory-bank/opencodeRouting.md +++ b/memory-bank/opencodeRouting.md @@ -118,6 +118,9 @@ by the resolved credential base URL so a product switch refetches. `thinkingConfig`; the 3.x rules are exact per documented variant (level sets differ per variant — 3.7/3.8 Flash accept `low`/`medium`/`high`, no `minimal`; verified against https://ai.google.dev/gemini-api/docs/thinking, page updated 2026-09-09 UTC, reviewed 2026-09-11). +Gemini 4 Argon and Carbon accept `low`/`medium`/`high`; Hydrogen and Neon add `xhigh` (reviewed +2026-11-20). `@ai-sdk/google` before 4.0.119 rejects `xhigh` in provider options without sending a +request, so the SDK must not drop below that version. OpenCode discovery **excludes** a Gemini-stamped model with no verified profile (actionable `logger.warn` diagnostic) rather than advertising an unusable model; an explicit configured model with such an id surfaces the client's unsupported-variant error. No silent Chat Completions diff --git a/package-lock.json b/package-lock.json index 717ca6d..6cc2b88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,15 +17,15 @@ } }, "node_modules/@ai-sdk/amazon-bedrock": { - "version": "5.0.120", - "resolved": "https://registry.npmjs.org/@ai-sdk/amazon-bedrock/-/amazon-bedrock-5.0.120.tgz", - "integrity": "sha512-ssOeZDG3B3NWEs2z+wh0KcMOnIYAEh0mT1Bhe+vhbVZYouBk+HBJkTCsd9wJTLKSGLI9eebBd32wGLBwx290GQ==", + "version": "5.0.142", + "resolved": "https://registry.npmjs.org/@ai-sdk/amazon-bedrock/-/amazon-bedrock-5.0.142.tgz", + "integrity": "sha512-eOwZ14N8XmamP6hZPirRen+xS1F5563MIPBz8RiQiV/bbcxZvEepQKPe85QeKDm+NwiBVrCXEFS6dtB08vjjJQ==", "license": "Apache-2.0", "dependencies": { - "@ai-sdk/anthropic": "4.0.84", - "@ai-sdk/openai": "4.0.98", - "@ai-sdk/provider": "4.0.31", - "@ai-sdk/provider-utils": "5.0.64", + "@ai-sdk/anthropic": "4.0.105", + "@ai-sdk/openai": "4.0.118", + "@ai-sdk/provider": "4.0.38", + "@ai-sdk/provider-utils": "5.0.81", "@smithy/eventstream-codec": "^4.3.3", "@smithy/util-utf8": "^4.3.3", "aws4fetch": "^1.0.20" @@ -38,13 +38,13 @@ } }, "node_modules/@ai-sdk/anthropic": { - "version": "4.0.84", - "resolved": "https://registry.npmjs.org/@ai-sdk/anthropic/-/anthropic-4.0.84.tgz", - "integrity": "sha512-jcqib3OpVtcMmJDWYpQqkjAusaLyqfORyM4bDc3UwLgP/usfiTONfj98HeQCLwMJ2uxrmSWiXFga2Rw/k50usw==", + "version": "4.0.105", + "resolved": "https://registry.npmjs.org/@ai-sdk/anthropic/-/anthropic-4.0.105.tgz", + "integrity": "sha512-i6kmv6y+FGTBxOPtLRrb5I+92WcFFGubhd33CD0JeaSyFOnLJ8my4a9olkAgyR9fACHMzxFBmoEHd0uO4i72bA==", "license": "Apache-2.0", "dependencies": { - "@ai-sdk/provider": "4.0.31", - "@ai-sdk/provider-utils": "5.0.64" + "@ai-sdk/provider": "4.0.38", + "@ai-sdk/provider-utils": "5.0.81" }, "engines": { "node": ">=22" @@ -54,13 +54,13 @@ } }, "node_modules/@ai-sdk/deepseek": { - "version": "3.0.69", - "resolved": "https://registry.npmjs.org/@ai-sdk/deepseek/-/deepseek-3.0.69.tgz", - "integrity": "sha512-NltFqxQhB0jGb0kY+Nevf2WnOkNkeY0cK5uiDMjgoFQv10VvzWahJYyRiWGivG1TQ0Jmi/3dsK2V7/wTWocsQQ==", + "version": "3.0.87", + "resolved": "https://registry.npmjs.org/@ai-sdk/deepseek/-/deepseek-3.0.87.tgz", + "integrity": "sha512-byIeauKjVE/G6FbMd5LnWk/NKr7RnD3rTL81OSrXBv4Fykijyn63JNeB8y+exxjYHPlWJedkR4FLLel5AYpFgw==", "license": "Apache-2.0", "dependencies": { - "@ai-sdk/provider": "4.0.31", - "@ai-sdk/provider-utils": "5.0.64" + "@ai-sdk/provider": "4.0.38", + "@ai-sdk/provider-utils": "5.0.81" }, "engines": { "node": ">=22" @@ -70,14 +70,14 @@ } }, "node_modules/@ai-sdk/gateway": { - "version": "4.0.120", - "resolved": "https://registry.npmjs.org/@ai-sdk/gateway/-/gateway-4.0.120.tgz", - "integrity": "sha512-hHGDQrCBgiEiPuimtc1NHPRGwte7sBG3XQuxTdurrpuGXKqCSHVlrBIDsiXjFOBYOms1+9aDz2xpTq+kOhiJWA==", + "version": "4.0.146", + "resolved": "https://registry.npmjs.org/@ai-sdk/gateway/-/gateway-4.0.146.tgz", + "integrity": "sha512-rJ5NQSyjnpo6HSBEYc9Ff6k1EROUuB7KeAfHYVbVDsk68ynY0Eb8JeWflZKXlT6NhYgqyCiBDxE5blXWACXMKQ==", "dev": true, "license": "Apache-2.0", "dependencies": { - "@ai-sdk/provider": "4.0.31", - "@ai-sdk/provider-utils": "5.0.64", + "@ai-sdk/provider": "4.0.38", + "@ai-sdk/provider-utils": "5.0.81", "@vercel/oidc": "3.2.0" }, "engines": { @@ -88,13 +88,13 @@ } }, "node_modules/@ai-sdk/google": { - "version": "4.0.101", - "resolved": "https://registry.npmjs.org/@ai-sdk/google/-/google-4.0.101.tgz", - "integrity": "sha512-1uplIBDqdjfVOJXTcyjCMkpEqeERpdvBPXUNwVVApoBRlllANHiDC0mAyDc5YGiGwf+VDCbPVj6EH5rKbfvWqw==", + "version": "4.0.121", + "resolved": "https://registry.npmjs.org/@ai-sdk/google/-/google-4.0.121.tgz", + "integrity": "sha512-K4aC8ZTe/dXegkaE2TxD1Ln2BaNFV4iTI57BykEcoS2KjBihaC3mu+UcmNZyY5yaoBJlLVGcxPhItF32TU6fLg==", "license": "Apache-2.0", "dependencies": { - "@ai-sdk/provider": "4.0.31", - "@ai-sdk/provider-utils": "5.0.64" + "@ai-sdk/provider": "4.0.38", + "@ai-sdk/provider-utils": "5.0.81" }, "engines": { "node": ">=22" @@ -104,17 +104,17 @@ } }, "node_modules/@ai-sdk/google-vertex": { - "version": "5.0.118", - "resolved": "https://registry.npmjs.org/@ai-sdk/google-vertex/-/google-vertex-5.0.118.tgz", - "integrity": "sha512-AAa89RJxwBkfCMOB2Ft9QWKi08YwRspnhpcTibXfD6M5EAF5s8sYfC/bd3CIFuFTAjtZagbNzSRD2nWE1O7xhA==", + "version": "5.0.141", + "resolved": "https://registry.npmjs.org/@ai-sdk/google-vertex/-/google-vertex-5.0.141.tgz", + "integrity": "sha512-28JdNni1rlufonYlQGQ4smoSKwWfd92+RtEJ+REHV6wJwjzehwnrOzfv8br9E7OsWeLWp/hjJPcpX8lzf7uJWg==", "license": "Apache-2.0", "dependencies": { - "@ai-sdk/anthropic": "4.0.84", - "@ai-sdk/google": "4.0.101", - "@ai-sdk/openai-compatible": "3.0.74", - "@ai-sdk/provider": "4.0.31", - "@ai-sdk/provider-utils": "5.0.64", - "google-auth-library": "^10.6.2" + "@ai-sdk/anthropic": "4.0.105", + "@ai-sdk/google": "4.0.121", + "@ai-sdk/openai-compatible": "3.0.92", + "@ai-sdk/provider": "4.0.38", + "@ai-sdk/provider-utils": "5.0.81", + "google-auth-library": "^11.3.1" }, "engines": { "node": ">=22" @@ -124,13 +124,13 @@ } }, "node_modules/@ai-sdk/openai": { - "version": "4.0.98", - "resolved": "https://registry.npmjs.org/@ai-sdk/openai/-/openai-4.0.98.tgz", - "integrity": "sha512-RvrbLblENKj//cQWlzsbmVKvvV8ZUq8FFB8/68ODWnu5sS3T+lUmRoKOM7NjR2UIX0/7YDrtauJr9fxQ0cwkug==", + "version": "4.0.118", + "resolved": "https://registry.npmjs.org/@ai-sdk/openai/-/openai-4.0.118.tgz", + "integrity": "sha512-pBsFeB+IudrX96P0ic9AO/1NPnfB6IyoS2B2pnhBJ/Ovt4bsvAmBOPeUxwEfYbQyfetJdVFep9sfYX42uVX3SQ==", "license": "Apache-2.0", "dependencies": { - "@ai-sdk/provider": "4.0.31", - "@ai-sdk/provider-utils": "5.0.64" + "@ai-sdk/provider": "4.0.38", + "@ai-sdk/provider-utils": "5.0.81" }, "engines": { "node": ">=22" @@ -140,13 +140,13 @@ } }, "node_modules/@ai-sdk/openai-compatible": { - "version": "3.0.74", - "resolved": "https://registry.npmjs.org/@ai-sdk/openai-compatible/-/openai-compatible-3.0.74.tgz", - "integrity": "sha512-W8+IW5dYlgmHpg/CQM/fcflhOe3JUbaHGrHzbE8sdbfETLjVFU/BgUTRfySpNlAst8FERaGH7prmKooQzp0qKw==", + "version": "3.0.92", + "resolved": "https://registry.npmjs.org/@ai-sdk/openai-compatible/-/openai-compatible-3.0.92.tgz", + "integrity": "sha512-2gV7HHV4qpx+8GotOZMmGqY270ExkftwFG5+DM6nChLmRaP6WP9JKj4e9WjLhih/GsPL9dSGnZHzwCsofHwiAQ==", "license": "Apache-2.0", "dependencies": { - "@ai-sdk/provider": "4.0.31", - "@ai-sdk/provider-utils": "5.0.64" + "@ai-sdk/provider": "4.0.38", + "@ai-sdk/provider-utils": "5.0.81" }, "engines": { "node": ">=22" @@ -156,9 +156,9 @@ } }, "node_modules/@ai-sdk/provider": { - "version": "4.0.31", - "resolved": "https://registry.npmjs.org/@ai-sdk/provider/-/provider-4.0.31.tgz", - "integrity": "sha512-3wJnwVTFg8SwOyoZCv+ov7Re2GB+7IQnU5a5MYJACrtiWDDUHgqTBeeesq2MB2ddgojzL8hgWleltwpAgtUqfg==", + "version": "4.0.38", + "resolved": "https://registry.npmjs.org/@ai-sdk/provider/-/provider-4.0.38.tgz", + "integrity": "sha512-GElz70UUCuDFFyD6m6aQJFgRY0HEABQzB5otzgkrisYaF5mnss7o0upAmbBTSD6KWiM9h7lZm1ls2c7xzHR8CA==", "license": "Apache-2.0", "dependencies": { "json-schema": "^0.4.0" @@ -168,16 +168,15 @@ } }, "node_modules/@ai-sdk/provider-utils": { - "version": "5.0.64", - "resolved": "https://registry.npmjs.org/@ai-sdk/provider-utils/-/provider-utils-5.0.64.tgz", - "integrity": "sha512-BDU8rDR6mBR+na5U/Dj4B33LX980x200lqhBGRIOxxx1NFunoixuvvweqIB+sCsCoFC8cGCsa82Ce2fKoAPOqw==", + "version": "5.0.81", + "resolved": "https://registry.npmjs.org/@ai-sdk/provider-utils/-/provider-utils-5.0.81.tgz", + "integrity": "sha512-pfvvdQ3d1WxdBuug/mnGEP6E48cPokwD8dMBnsFeeAUp0/rb/H2aj0f3mwOiY62gu/Cu5GO44e+SE5nDHyBWMA==", "license": "Apache-2.0", "dependencies": { - "@ai-sdk/provider": "4.0.31", + "@ai-sdk/provider": "4.0.38", "@standard-schema/spec": "^1.1.0", "@workflow/serde": "4.1.0", - "eventsource-parser": "^3.0.8", - "undici": "^7.29.0" + "eventsource-parser": "^3.0.8" }, "engines": { "node": ">=22" @@ -2937,15 +2936,15 @@ } }, "node_modules/ai": { - "version": "7.0.147", - "resolved": "https://registry.npmjs.org/ai/-/ai-7.0.147.tgz", - "integrity": "sha512-9MsjkCddqIPYGDMDc6HF+i4cydkFpC2xteQGlR6Dz5cuWLIV5sCARbFCqaiTUn3/GaNxg3bIfRlfSzxPvi77fw==", + "version": "7.0.173", + "resolved": "https://registry.npmjs.org/ai/-/ai-7.0.173.tgz", + "integrity": "sha512-dLea37zT1h7cjkUsBprU4Rq35HJqhtHHaq1jTAXjHQoyfpeswpgCrhjZJWdWc10gjEAxmz114py7iLGQ3xIMxw==", "dev": true, "license": "Apache-2.0", "dependencies": { - "@ai-sdk/gateway": "4.0.120", - "@ai-sdk/provider": "4.0.31", - "@ai-sdk/provider-utils": "5.0.64" + "@ai-sdk/gateway": "4.0.146", + "@ai-sdk/provider": "4.0.38", + "@ai-sdk/provider-utils": "5.0.81" }, "engines": { "node": ">=22" @@ -3663,9 +3662,9 @@ } }, "node_modules/gaxios": { - "version": "7.1.5", - "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-7.1.5.tgz", - "integrity": "sha512-5FZy72Rh8LhtjmvDrKkI+lVhrsQrVKVsItxMoDm5mNQE+xR0WVIIs+jzPSJgBvKVsLi24fZhXJIsNI0bihDzFg==", + "version": "8.3.3", + "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-8.3.3.tgz", + "integrity": "sha512-zqPbbtW5bAOZ8BRjS7bxj5VG7PBY5PwKRxpku9NplLqAPmYMoXExL1KOdaK5fHvwRETu3bPplLEsFGDdUUlrpw==", "license": "Apache-2.0", "dependencies": { "extend": "^3.0.2", @@ -3673,21 +3672,21 @@ "node-fetch": "^3.3.2" }, "engines": { - "node": ">=18" + "node": ">=22" } }, "node_modules/gcp-metadata": { - "version": "8.1.2", - "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-8.1.2.tgz", - "integrity": "sha512-zV/5HKTfCeKWnxG0Dmrw51hEWFGfcF2xiXqcA3+J90WDuP0SvoiSO5ORvcBsifmx/FoIjgQN3oNOGaQ5PhLFkg==", + "version": "9.2.3", + "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-9.2.3.tgz", + "integrity": "sha512-d2OI/dJJ3IIaeOz3c9jvr5j5G5beI5fQzbgilNiWhDKGwvJN9o10Qub70NkbF6PNJSUoNKZ77JKYGz0Fs4+9Lg==", "license": "Apache-2.0", "dependencies": { - "gaxios": "^7.0.0", - "google-logging-utils": "^1.0.0", + "gaxios": "^8.3.1", + "google-logging-utils": "^2.1.0", "json-bigint": "^1.0.0" }, "engines": { - "node": ">=18" + "node": ">=22" } }, "node_modules/get-caller-file": { @@ -3714,29 +3713,29 @@ } }, "node_modules/google-auth-library": { - "version": "10.7.0", - "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-10.7.0.tgz", - "integrity": "sha512-QpTAbNJ36TliZLx3TTtahR8HG0hN9RllL1e3FymOvQSIKK8JmgV58H924ub2wa2DsS3ANjjP1Aw1N+Ramc8hqQ==", + "version": "11.3.4", + "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-11.3.4.tgz", + "integrity": "sha512-RaYCDoeYIIFTRgH8hesSxqLrmtC2l+DB3cSCS/SN1TPGjI2VpPdJmF3bfRLUn8VvP/4I2Af9fsktw2f9SvVSVg==", "license": "Apache-2.0", "dependencies": { "base64-js": "^1.3.0", "ecdsa-sig-formatter": "^1.0.11", - "gaxios": "^7.1.4", - "gcp-metadata": "8.1.2", - "google-logging-utils": "1.1.3", + "gaxios": "^8.3.1", + "gcp-metadata": "^9.2.1", + "google-logging-utils": "^2.1.0", "jws": "^4.0.0" }, "engines": { - "node": ">=18" + "node": ">=22" } }, "node_modules/google-logging-utils": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/google-logging-utils/-/google-logging-utils-1.1.3.tgz", - "integrity": "sha512-eAmLkjDjAFCVXg7A1unxHsLf961m6y17QFqXqAXGj/gVkKFrEICfStRfwUlGNfeCEjNRa32JEWOUTlYXPyyKvA==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/google-logging-utils/-/google-logging-utils-2.2.0.tgz", + "integrity": "sha512-Q6HuSEyoaxi0AgqUrOYb2gc77fDl4QugRoHpreI8VpW/VzPsoKyxjL8tGKLmZpWlvC1uVBXM85tykoQpCGBF5g==", "license": "Apache-2.0", "engines": { - "node": ">=14" + "node": ">=22" } }, "node_modules/graceful-fs": { @@ -5539,15 +5538,6 @@ "@esbuild/win32-x64": "0.28.1" } }, - "node_modules/undici": { - "version": "7.30.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-7.30.0.tgz", - "integrity": "sha512-dkrQXeHSaoamnItlYbmzG0wFYrM0ZwDxCIg0A7aKjTyyhh9svRzCNFEzV+Vm05/yehjCzjDZ31KXfGEjYSztDQ==", - "license": "MIT", - "engines": { - "node": ">=20.18.1" - } - }, "node_modules/undici-types": { "version": "6.21.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", @@ -6070,31 +6060,31 @@ "version": "0.1.0", "license": "MIT", "dependencies": { - "@ai-sdk/amazon-bedrock": "^5.0.120", - "@ai-sdk/anthropic": "^4.0.84", - "@ai-sdk/deepseek": "^3.0.69", - "@ai-sdk/google": "^4.0.101", - "@ai-sdk/google-vertex": "^5.0.118", - "@ai-sdk/openai": "^4.0.98", - "@ai-sdk/openai-compatible": "^3.0.74", + "@ai-sdk/amazon-bedrock": "^5.0.142", + "@ai-sdk/anthropic": "^4.0.105", + "@ai-sdk/deepseek": "^3.0.87", + "@ai-sdk/google": "^4.0.121", + "@ai-sdk/google-vertex": "^5.0.141", + "@ai-sdk/openai": "^4.0.118", + "@ai-sdk/openai-compatible": "^3.0.92", "@aws-sdk/client-bedrock": "^3.981.0", "@aws-sdk/credential-providers": "^3.981.0", "@azure/identity": "^4.13.1", "@openrouter/ai-sdk-provider": "^3.1.0", "@smithy/core": "^3.25.1", - "ai": "^7.0.147", + "ai": "^7.0.173", "ai-config": "*", "ai-credentials": "*", "ai-sdk-ollama": "^4.4.0", "aws4fetch": "^1.0.20", - "google-auth-library": "^10.5.0" + "google-auth-library": "^11.3.4" }, "devDependencies": { "@smithy/eventstream-codec": "^4.3.3", "@smithy/util-utf8": "^4.3.3", "@types/node": "22.x", "@types/positron-vscode": "npm:@types/vscode@^1.100.0", - "ai": "^7.0.147", + "ai": "^7.0.173", "concurrently": "^9.2.1", "esbuild": "^0.25.0", "husky": "^9.1.7", diff --git a/packages/ai-config/src/model-capabilities/__tests__/gemini-helpers.test.ts b/packages/ai-config/src/model-capabilities/__tests__/gemini-helpers.test.ts index 1d5c80f..07238ee 100644 --- a/packages/ai-config/src/model-capabilities/__tests__/gemini-helpers.test.ts +++ b/packages/ai-config/src/model-capabilities/__tests__/gemini-helpers.test.ts @@ -12,12 +12,20 @@ describe("getGeminiModelCapabilities", () => { { name: "a two-digit minor", id: "gemini-3.10-flash", donor: "gemini-3.8-flash" }, { name: "a major bump", id: "gemini-4-pro", donor: "gemini-3.1-pro" }, { name: "Flash-Lite", id: "gemini-3.5-flash-lite", donor: "gemini-3.1-flash-lite" }, + { name: "a Gemini 4 name", id: "gemini-4.1-neon", donor: "gemini-4-neon" }, + { + name: "a suffixed Gemini 4 name", + id: "gemini-4-argon-cyber-permissive", + donor: "gemini-4-argon", + }, { name: "a dated suffix", id: "gemini-2.5-flash-preview-09-2025", donor: "gemini-2.5-flash", }, ])("inherits the nearest older same-variant entry for $name", ({ id, donor }) => { + // Unrecognized ids share the defaults, so equality alone proves nothing. + expect(getGeminiModelCapabilities(donor)?.family).toBeDefined(); expect(getGeminiModelCapabilities(id)).toEqual(getGeminiModelCapabilities(donor)); }); diff --git a/packages/ai-config/src/model-capabilities/gemini-generate-content.ts b/packages/ai-config/src/model-capabilities/gemini-generate-content.ts index b789ecf..2a506ef 100644 --- a/packages/ai-config/src/model-capabilities/gemini-generate-content.ts +++ b/packages/ai-config/src/model-capabilities/gemini-generate-content.ts @@ -82,6 +82,7 @@ const FLASH_BUDGETS = { low: 2048, medium: 8192, high: 24_576 } as const; /** Level sets for the documented 3.x variants. */ const LEVELS_WITH_MINIMAL = ["minimal", "low", "medium", "high"] as const; const LEVELS_LOW_MEDIUM_HIGH = ["low", "medium", "high"] as const; +const LEVELS_LOW_TO_XHIGH = ["low", "medium", "high", "xhigh"] as const; /** `gemini-3-pro-preview` documents only these two levels. */ const LEVELS_LOW_HIGH = ["low", "high"] as const; /** `gemini-3.1-flash-lite-image` documents only these two levels. */ @@ -168,6 +169,23 @@ const VARIANT_RULES: readonly VariantRule[] = [ match: /^gemini-3\.8-flash(?:$|[-.])/, thinking: { control: "level", levels: LEVELS_LOW_MEDIUM_HIGH }, }, + + // --- Gemini 4 --- + { + // Argon and Carbon document low/medium/high; `minimal` and thinkingBudget + // return HTTP 400. Checked 2026-11-20 against + // https://ai.google.dev/gemini-api/docs/latest-model and Google Cloud's + // Gemini 4 model pages. Also covers `gemini-4-argon-cyber-permissive`, + // which takes the same levels. + match: /^gemini-4-(?:argon|carbon)(?:$|[-.])/, + thinking: { control: "level", levels: LEVELS_LOW_MEDIUM_HIGH }, + }, + { + // Hydrogen and Neon add `xhigh` (same sources and date). Sending it + // needs @ai-sdk/google 4.0.119 or later. + match: /^gemini-4-(?:hydrogen|neon)(?:$|[-.])/, + thinking: { control: "level", levels: LEVELS_LOW_TO_XHIGH }, + }, ]; // --------------------------------------------------------------------------- diff --git a/packages/ai-config/src/model-capabilities/gemini-helpers.ts b/packages/ai-config/src/model-capabilities/gemini-helpers.ts index 9ae4a06..6ee0301 100644 --- a/packages/ai-config/src/model-capabilities/gemini-helpers.ts +++ b/packages/ai-config/src/model-capabilities/gemini-helpers.ts @@ -22,6 +22,9 @@ const LEVELS_WITH_MINIMAL = ["minimal", "low", "medium", "high"]; */ const LEVELS_WITHOUT_MINIMAL = ["low", "medium", "high"]; +/** Effort levels for Gemini 4 models that add `xhigh` (and reject `minimal`). */ +const LEVELS_WITH_XHIGH = ["low", "medium", "high", "xhigh"]; + /** Limits and thinking levels a capability entry assigns to a Gemini model. */ interface GeminiCapabilities { family: string; @@ -31,7 +34,11 @@ interface GeminiCapabilities { thinkingEffortLevels?: string[]; } -/** Limits shared by every Gemini 2.5 and 3.x model. */ +/** + * Limits shared by every Gemini 2.5, 3.x, and 4 model. Gemini 4 documents a + * 1,048,576-token window shared by input and output, with 65,536 output + * tokens per synchronous response. + */ const LIMITS_1M = { maxInputTokens: 1_000_000, maxContextLength: 1_000_000, @@ -40,7 +47,8 @@ const LIMITS_1M = { /** * Gemini models keyed by a representative id of their variant (`pro`, - * `flash`, `flash-lite`) and version. A requested id takes the entry of its + * `flash`, `flash-lite`, and the Gemini 4 names) and version. A requested id + * takes the entry of its * variant with the greatest version at or below its own (see * {@link findGeminiVariantDonor}), so each entry covers the versions up to * the next one, and the newest entry of a variant is the fallback for later @@ -96,6 +104,25 @@ const VARIANT_ENTRIES: ReadonlyMap = new Map([ "gemini-3-flash-lite", { family: "gemini-3", ...LIMITS_1M, thinkingEffortLevels: LEVELS_WITH_MINIMAL }, ], + + // --- Gemini 4 --- + // All reject `minimal`. Argon and Carbon take low/medium/high; Hydrogen and + // Neon add xhigh. Checked 2026-11-20 against Google's model docs + // (https://ai.google.dev/gemini-api/docs/latest-model and the Gemini 4 + // model pages). Sending xhigh needs @ai-sdk/google 4.0.119 or later. + [ + "gemini-4-argon", + { family: "gemini-4", ...LIMITS_1M, thinkingEffortLevels: LEVELS_WITHOUT_MINIMAL }, + ], + [ + "gemini-4-carbon", + { family: "gemini-4", ...LIMITS_1M, thinkingEffortLevels: LEVELS_WITHOUT_MINIMAL }, + ], + [ + "gemini-4-hydrogen", + { family: "gemini-4", ...LIMITS_1M, thinkingEffortLevels: LEVELS_WITH_XHIGH }, + ], + ["gemini-4-neon", { family: "gemini-4", ...LIMITS_1M, thinkingEffortLevels: LEVELS_WITH_XHIGH }], ]); /** diff --git a/packages/ai-config/src/model-capabilities/gemini-variant.ts b/packages/ai-config/src/model-capabilities/gemini-variant.ts index 2ed2355..d8b17af 100644 --- a/packages/ai-config/src/model-capabilities/gemini-variant.ts +++ b/packages/ai-config/src/model-capabilities/gemini-variant.ts @@ -4,12 +4,13 @@ /** * Variant and version of a bare Gemini id: `gemini-3.8-flash`, - * `gemini-3.1-pro-preview`, `gemini-2.5-flash-preview-09-2025`. Suffixes after - * the variant are ignored. `flash-lite` precedes `flash` so Flash-Lite ids - * aren't read as Flash. Gemma, `-latest` aliases, and dash-joined versions - * (`gemini-2-5-pro`) don't match. + * `gemini-3.1-pro-preview`, `gemini-4-neon`, `gemini-2.5-flash-preview-09-2025`. + * Suffixes after the variant are ignored. `flash-lite` precedes `flash` so + * Flash-Lite ids aren't read as Flash. Gemma, `-latest` aliases, and + * dash-joined versions (`gemini-2-5-pro`) don't match. */ -const GEMINI_VARIANT_ID = /^gemini-(\d+)(?:\.(\d+))?-(flash-lite|flash|pro)(?=$|-)/; +const GEMINI_VARIANT_ID = + /^gemini-(\d+)(?:\.(\d+))?-(flash-lite|flash|pro|argon|carbon|hydrogen|neon)(?=$|-)/; interface ParsedGeminiId { variant: string; @@ -37,7 +38,7 @@ export interface GeminiVariantDonor { } /** - * Find the known id of the same variant (`pro`, `flash`, `flash-lite`) with + * Find the known id of the same variant (`pro`, `flash`, `neon`, …) with * the greatest version at or below `modelId`'s own, so later versions * inherit from the newest known model (`gemini-3.9-flash` → 3.8 Flash). * `newest` lets a caller restrict inheritance to versions at or above the diff --git a/packages/ai-provider-bridge/package.json b/packages/ai-provider-bridge/package.json index 13613ba..9a0eca8 100644 --- a/packages/ai-provider-bridge/package.json +++ b/packages/ai-provider-bridge/package.json @@ -70,22 +70,22 @@ "dependencies": { "ai-config": "*", "ai-credentials": "*", - "@ai-sdk/amazon-bedrock": "^5.0.120", - "@ai-sdk/anthropic": "^4.0.84", - "@ai-sdk/deepseek": "^3.0.69", - "@ai-sdk/google": "^4.0.101", - "@ai-sdk/google-vertex": "^5.0.118", - "@ai-sdk/openai": "^4.0.98", - "@ai-sdk/openai-compatible": "^3.0.74", + "@ai-sdk/amazon-bedrock": "^5.0.142", + "@ai-sdk/anthropic": "^4.0.105", + "@ai-sdk/deepseek": "^3.0.87", + "@ai-sdk/google": "^4.0.121", + "@ai-sdk/google-vertex": "^5.0.141", + "@ai-sdk/openai": "^4.0.118", + "@ai-sdk/openai-compatible": "^3.0.92", "@aws-sdk/client-bedrock": "^3.981.0", "@aws-sdk/credential-providers": "^3.981.0", "@smithy/core": "^3.25.1", "aws4fetch": "^1.0.20", "@openrouter/ai-sdk-provider": "^3.1.0", "@azure/identity": "^4.13.1", - "ai": "^7.0.147", + "ai": "^7.0.173", "ai-sdk-ollama": "^4.4.0", - "google-auth-library": "^10.5.0" + "google-auth-library": "^11.3.4" }, "peerDependencies": { "vscode": "^1.100.0" @@ -100,7 +100,7 @@ "@smithy/util-utf8": "^4.3.3", "@types/node": "22.x", "@types/positron-vscode": "npm:@types/vscode@^1.100.0", - "ai": "^7.0.147", + "ai": "^7.0.173", "concurrently": "^9.2.1", "esbuild": "^0.25.0", "husky": "^9.1.7", diff --git a/packages/ai-provider-bridge/src/__tests__/gemini-interactions.test.ts b/packages/ai-provider-bridge/src/__tests__/gemini-interactions.test.ts index f3f64bb..f59da52 100644 --- a/packages/ai-provider-bridge/src/__tests__/gemini-interactions.test.ts +++ b/packages/ai-provider-bridge/src/__tests__/gemini-interactions.test.ts @@ -46,6 +46,9 @@ describe("getGeminiInteractionsProfile inheritance", () => { { id: "gemini-4-pro", donor: "gemini-3.1-pro-preview" }, // Equal version: an alias of the newest profiled id { id: "gemini-3.1-pro", donor: "gemini-3.1-pro-preview" }, + // Gemini 4 names are variants too, so suffixed ids and later versions inherit + { id: "gemini-4-argon-cyber-permissive", donor: "gemini-4-argon" }, + { id: "gemini-4.1-hydrogen", donor: "gemini-4-hydrogen" }, ])("$id inherits the newest same-variant profile", ({ id, donor }) => { const profile = getGeminiInteractionsProfile(id); expect(profile).toBeDefined(); diff --git a/packages/ai-provider-bridge/src/model-capabilities/gemini-interactions.ts b/packages/ai-provider-bridge/src/model-capabilities/gemini-interactions.ts index ecc2f25..69a2643 100644 --- a/packages/ai-provider-bridge/src/model-capabilities/gemini-interactions.ts +++ b/packages/ai-provider-bridge/src/model-capabilities/gemini-interactions.ts @@ -56,7 +56,7 @@ function identityLevels(...levels: string[]): Readonly> { /** * Explicit enumerated thinking profiles for models reachable via * `POST /v1beta/interactions`. An unlisted Gemini chat ID at or above the - * newest listed version of its variant (`pro`, `flash`, `flash-lite`) + * newest listed version of its variant (`pro`, `flash`, `neon`, …) * inherits that entry's profile, so the newest entry of a variant also * serves its future versions. Other unlisted IDs are still discoverable (see * {@link isGeminiApiChatModel}) but get no advertised thinking levels and no @@ -98,6 +98,18 @@ const INTERACTIONS_PROFILES: ReadonlyMap = ne // (https://ai.google.dev/gemini-api/docs/models/gemini-3.8-flash). ["gemini-3.8-flash", { effortToWireLevel: identityLevels("low", "medium", "high") }], + // --- Gemini 4 --- + // All reject `minimal`. Argon (default medium) and Carbon (default medium) + // take low/medium/high; Hydrogen and Neon (default high) add xhigh. + // Checked 2026-11-20 against Google's model docs + // (https://ai.google.dev/gemini-api/docs/latest-model and the Gemini 4 + // model pages). @ai-sdk/google before 4.0.119 rejects xhigh in provider + // options without sending a request. + ["gemini-4-argon", { effortToWireLevel: identityLevels("low", "medium", "high") }], + ["gemini-4-carbon", { effortToWireLevel: identityLevels("low", "medium", "high") }], + ["gemini-4-hydrogen", { effortToWireLevel: identityLevels("low", "medium", "high", "xhigh") }], + ["gemini-4-neon", { effortToWireLevel: identityLevels("low", "medium", "high", "xhigh") }], + // --- Gemma 4 (hosted on the Gemini API) --- // Binary thinking, verified against the live API (2026-08-17): wire // thinkingLevel accepts only "minimal" (off) and "high" (on), and the diff --git a/packages/ai-provider-bridge/src/model-clients/__tests__/gemini-xhigh-wire.test.ts b/packages/ai-provider-bridge/src/model-clients/__tests__/gemini-xhigh-wire.test.ts new file mode 100644 index 0000000..962be75 --- /dev/null +++ b/packages/ai-provider-bridge/src/model-clients/__tests__/gemini-xhigh-wire.test.ts @@ -0,0 +1,79 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (C) 2026 Posit Software, PBC. All rights reserved. + *--------------------------------------------------------------------------------------------*/ + +/** + * Raw-wire evidence that the `xhigh` thinking level the Gemini 4 profiles + * advertise survives @ai-sdk/google's provider-option validation on both + * APIs. Before 4.0.119 the SDK rejected `xhigh` ("invalid google provider + * options") without sending a request, so advertising it was a guaranteed + * failure. + */ + +import { createGoogle } from "@ai-sdk/google"; +import { streamText, type LanguageModel } from "ai"; +import { getGeminiGenerateContentProfile } from "ai-config"; +import { afterEach, describe, expect, it, vi } from "vitest"; + +import { createRawFetchCapture } from "../../../tests/helpers/raw-fetch-capture"; +import { buildInteractionsOptions } from "../GeminiClient"; +import { buildGenerateContentOptions } from "../GeminiGenerateContentClient"; + +const MODEL_ID = "gemini-4-neon"; + +/** Drive one `streamText` request through a stubbed fetch and return the raw body. */ +async function captureBody( + model: LanguageModel, + providerOptions: Parameters[0]["providerOptions"], +): Promise { + const rawFetch = createRawFetchCapture( + async () => new Response("", { status: 200, headers: { "content-type": "text/event-stream" } }), + ); + vi.stubGlobal("fetch", rawFetch.mock); + try { + const result = streamText({ + model, + messages: [{ role: "user", content: "hi" }], + providerOptions, + }); + for await (const _part of result.stream) { + // Drain the (empty) mocked event stream. + } + } catch { + // The mocked stream is minimal; only the serialized request matters. + } + const [, init] = rawFetch.single(); + return JSON.parse(String(init?.body)); +} + +afterEach(() => { + vi.unstubAllGlobals(); +}); + +describe("Gemini 4 xhigh wire serialization", () => { + it("sends thinking_level xhigh on the Interactions API", async () => { + const provider = createGoogle({ apiKey: "test-key" }); + const body = await captureBody( + provider.interactions(MODEL_ID), + buildInteractionsOptions({ + thinkingEffort: "xhigh", + modelId: MODEL_ID, + previousInteractionId: null, + }), + ); + expect(body).toMatchObject({ generation_config: { thinking_level: "xhigh" } }); + }); + + it("sends thinkingLevel xhigh on generateContent", async () => { + const profile = getGeminiGenerateContentProfile(MODEL_ID); + if (!profile) throw new Error(`Expected a generateContent profile for ${MODEL_ID}`); + const provider = createGoogle({ apiKey: "test-key" }); + const body = await captureBody( + provider(MODEL_ID), + buildGenerateContentOptions({ thinkingEffort: "xhigh", profile }), + ); + expect(body).toMatchObject({ + generationConfig: { thinkingConfig: { thinkingLevel: "xhigh" } }, + }); + }); +});