@ai-sdk/google
Advanced tools
| type GoogleModelCapabilities = { | ||
| supportsGemini2Tools: boolean; | ||
| supportsFileSearch: boolean; | ||
| usesGemini3Features: boolean; | ||
| }; | ||
| const gemini1ModelPattern = /(^|\/)gemini-1(?:[.-]|$)/i; | ||
| const gemini2ModelPattern = /(^|\/)gemini-2(?:[.-]|$)/i; | ||
| const gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i; | ||
| const geminiModelPattern = /(^|\/)gemini-/i; | ||
| function isKnownPreGemini2Model(modelId: string): boolean { | ||
| return ( | ||
| gemini1ModelPattern.test(modelId) || | ||
| /(^|\/)gemini-pro(?:-vision)?$/i.test(modelId) || | ||
| /(^|\/)gemini-robotics-er-1\.5(?:[.-]|$)/i.test(modelId) | ||
| ); | ||
| } | ||
| /** | ||
| * Classifies Gemini capabilities by excluding known older generations. | ||
| * | ||
| * Google model IDs are open-ended, so unrecognized Gemini IDs and aliases | ||
| * intentionally inherit the newest supported behavior. Add exceptions here | ||
| * only when a model is known to require a legacy request shape. | ||
| */ | ||
| export function getGoogleModelCapabilities( | ||
| modelId: string, | ||
| ): GoogleModelCapabilities { | ||
| const isGeminiModel = geminiModelPattern.test(modelId); | ||
| const isGemini2Model = gemini2ModelPattern.test(modelId); | ||
| const isKnownPreGemini2 = isKnownPreGemini2Model(modelId); | ||
| const isKnownOlderModel = isKnownPreGemini2 || isGemini2Model; | ||
| const usesGemini3Features = isGeminiModel && !isKnownOlderModel; | ||
| return { | ||
| supportsGemini2Tools: | ||
| (isGeminiModel && !isKnownPreGemini2) || | ||
| modelId.toLowerCase().includes('nano-banana'), | ||
| supportsFileSearch: | ||
| gemini25ModelPattern.test(modelId) || usesGemini3Features, | ||
| usesGemini3Features, | ||
| }; | ||
| } |
+1
-1
| { | ||
| "name": "@ai-sdk/google", | ||
| "version": "3.0.99", | ||
| "version": "3.0.100", | ||
| "license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -42,2 +42,3 @@ import type { | ||
| } from './google-generative-ai-options'; | ||
| import { getGoogleModelCapabilities } from './google-model-capabilities'; | ||
| import type { | ||
@@ -233,4 +234,3 @@ GoogleGenerativeAIContentPart, | ||
| const isGemmaModel = this.modelId.toLowerCase().startsWith('gemma-'); | ||
| const isGemini3Model = /^gemini-3[.-]/.test(this.modelId); | ||
| const supportsFunctionResponseParts = isGemini3Model; | ||
| const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId); | ||
@@ -241,5 +241,5 @@ const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages( | ||
| isGemmaModel, | ||
| isGemini3Model, | ||
| isGemini3Model: usesGemini3Features, | ||
| providerOptionsName, | ||
| supportsFunctionResponseParts, | ||
| supportsFunctionResponseParts: usesGemini3Features, | ||
| onWarning: warning => warnings.push(warning), | ||
@@ -246,0 +246,0 @@ }, |
@@ -8,2 +8,3 @@ import { | ||
| import type { GoogleGenerativeAIModelId } from './google-generative-ai-options'; | ||
| import { getGoogleModelCapabilities } from './google-model-capabilities'; | ||
@@ -50,17 +51,4 @@ export function prepareTools({ | ||
| const isLatest = ( | ||
| [ | ||
| 'gemini-flash-latest', | ||
| 'gemini-flash-lite-latest', | ||
| 'gemini-pro-latest', | ||
| ] as const satisfies GoogleGenerativeAIModelId[] | ||
| ).some(id => id === modelId); | ||
| const isGemini2orNewer = | ||
| modelId.includes('gemini-2') || | ||
| modelId.includes('gemini-3') || | ||
| modelId.includes('nano-banana') || | ||
| isLatest; | ||
| const isGemini3orNewer = modelId.includes('gemini-3'); | ||
| const supportsFileSearch = | ||
| modelId.includes('gemini-2.5') || modelId.includes('gemini-3'); | ||
| const { supportsGemini2Tools, supportsFileSearch, usesGemini3Features } = | ||
| getGoogleModelCapabilities(modelId); | ||
@@ -75,3 +63,3 @@ if (tools == null) { | ||
| if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) { | ||
| if (hasFunctionTools && hasProviderTools && !usesGemini3Features) { | ||
| toolWarnings.push({ | ||
@@ -90,3 +78,3 @@ type: 'unsupported', | ||
| case 'google.google_search': | ||
| if (isGemini2orNewer) { | ||
| if (supportsGemini2Tools) { | ||
| googleTools.push({ googleSearch: { ...tool.args } }); | ||
@@ -102,3 +90,3 @@ } else { | ||
| case 'google.enterprise_web_search': | ||
| if (isGemini2orNewer) { | ||
| if (supportsGemini2Tools) { | ||
| googleTools.push({ enterpriseWebSearch: {} }); | ||
@@ -114,3 +102,3 @@ } else { | ||
| case 'google.url_context': | ||
| if (isGemini2orNewer) { | ||
| if (supportsGemini2Tools) { | ||
| googleTools.push({ urlContext: {} }); | ||
@@ -127,3 +115,3 @@ } else { | ||
| case 'google.code_execution': | ||
| if (isGemini2orNewer) { | ||
| if (supportsGemini2Tools) { | ||
| googleTools.push({ codeExecution: {} }); | ||
@@ -152,3 +140,3 @@ } else { | ||
| case 'google.vertex_rag_store': | ||
| if (isGemini2orNewer) { | ||
| if (supportsGemini2Tools) { | ||
| googleTools.push({ | ||
@@ -174,3 +162,3 @@ retrieval: { | ||
| case 'google.google_maps': | ||
| if (isGemini2orNewer) { | ||
| if (supportsGemini2Tools) { | ||
| googleTools.push({ googleMaps: {} }); | ||
@@ -195,3 +183,3 @@ } else { | ||
| if (hasFunctionTools && isGemini3orNewer && googleTools.length > 0) { | ||
| if (hasFunctionTools && usesGemini3Features && googleTools.length > 0) { | ||
| const functionDeclarations: Array<{ | ||
@@ -198,0 +186,0 @@ name: string; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
3127657
0.39%66
1.54%34154
0.22%