@ai-sdk/google
Advanced tools
+13
-4
| # @ai-sdk/google | ||
| ## 4.0.0-beta.14 | ||
| ### Patch Changes | ||
| - 3887c70: feat(provider): add new top-level reasoning parameter to spec and support it in `generateText` and `streamText` | ||
| - Updated dependencies [3887c70] | ||
| - @ai-sdk/provider-utils@5.0.0-beta.6 | ||
| - @ai-sdk/provider@4.0.0-beta.4 | ||
| ## 4.0.0-beta.13 | ||
@@ -416,3 +425,3 @@ | ||
| ```ts | ||
| model.textEmbeddingModel('my-model-id'); | ||
| model.textEmbeddingModel("my-model-id"); | ||
| ``` | ||
@@ -423,3 +432,3 @@ | ||
| ```ts | ||
| model.embeddingModel('my-model-id'); | ||
| model.embeddingModel("my-model-id"); | ||
| ``` | ||
@@ -733,3 +742,3 @@ | ||
| ```ts | ||
| model.textEmbeddingModel('my-model-id'); | ||
| model.textEmbeddingModel("my-model-id"); | ||
| ``` | ||
@@ -740,3 +749,3 @@ | ||
| ```ts | ||
| model.embeddingModel('my-model-id'); | ||
| model.embeddingModel("my-model-id"); | ||
| ``` | ||
@@ -743,0 +752,0 @@ |
@@ -7,3 +7,6 @@ // src/google-generative-ai-language-model.ts | ||
| generateId, | ||
| isCustomReasoning, | ||
| lazySchema as lazySchema3, | ||
| mapReasoningToProviderBudget, | ||
| mapReasoningToProviderEffort, | ||
| parseProviderOptions, | ||
@@ -778,2 +781,3 @@ postJsonToApi, | ||
| toolChoice, | ||
| reasoning, | ||
| providerOptions | ||
@@ -818,2 +822,8 @@ }) { | ||
| }); | ||
| const resolvedThinking = resolveThinkingConfig({ | ||
| reasoning, | ||
| modelId: this.modelId, | ||
| warnings | ||
| }); | ||
| const thinkingConfig = (googleOptions == null ? void 0 : googleOptions.thinkingConfig) || resolvedThinking ? { ...resolvedThinking, ...googleOptions == null ? void 0 : googleOptions.thinkingConfig } : void 0; | ||
| return { | ||
@@ -842,3 +852,3 @@ args: { | ||
| responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities, | ||
| thinkingConfig: googleOptions == null ? void 0 : googleOptions.thinkingConfig, | ||
| thinkingConfig, | ||
| ...(googleOptions == null ? void 0 : googleOptions.mediaResolution) && { | ||
@@ -1274,2 +1284,71 @@ mediaResolution: googleOptions.mediaResolution | ||
| }; | ||
| function isGemini3Model(modelId) { | ||
| return /gemini-3[\.\-]/i.test(modelId) || /gemini-3$/i.test(modelId); | ||
| } | ||
| function getMaxOutputTokensForGemini25Model() { | ||
| return 65536; | ||
| } | ||
| function getMaxThinkingTokensForGemini25Model(modelId) { | ||
| const id = modelId.toLowerCase(); | ||
| if (id.includes("2.5-pro") || id.includes("gemini-3-pro-image")) { | ||
| return 32768; | ||
| } | ||
| return 24576; | ||
| } | ||
| function resolveThinkingConfig({ | ||
| reasoning, | ||
| modelId, | ||
| warnings | ||
| }) { | ||
| if (!isCustomReasoning(reasoning)) { | ||
| return void 0; | ||
| } | ||
| if (isGemini3Model(modelId) && !modelId.includes("gemini-3-pro-image")) { | ||
| return resolveGemini3ThinkingConfig({ reasoning, warnings }); | ||
| } | ||
| return resolveGemini25ThinkingConfig({ reasoning, modelId, warnings }); | ||
| } | ||
| function resolveGemini3ThinkingConfig({ | ||
| reasoning, | ||
| warnings | ||
| }) { | ||
| if (reasoning === "none") { | ||
| return { thinkingLevel: "minimal" }; | ||
| } | ||
| const thinkingLevel = mapReasoningToProviderEffort({ | ||
| reasoning, | ||
| effortMap: { | ||
| minimal: "minimal", | ||
| low: "low", | ||
| medium: "medium", | ||
| high: "high", | ||
| xhigh: "high" | ||
| }, | ||
| warnings | ||
| }); | ||
| if (thinkingLevel == null) { | ||
| return void 0; | ||
| } | ||
| return { thinkingLevel }; | ||
| } | ||
| function resolveGemini25ThinkingConfig({ | ||
| reasoning, | ||
| modelId, | ||
| warnings | ||
| }) { | ||
| if (reasoning === "none") { | ||
| return { thinkingBudget: 0 }; | ||
| } | ||
| const thinkingBudget = mapReasoningToProviderBudget({ | ||
| reasoning, | ||
| maxOutputTokens: getMaxOutputTokensForGemini25Model(), | ||
| maxReasoningBudget: getMaxThinkingTokensForGemini25Model(modelId), | ||
| minReasoningBudget: 0, | ||
| warnings | ||
| }); | ||
| if (thinkingBudget == null) { | ||
| return void 0; | ||
| } | ||
| return { thinkingBudget }; | ||
| } | ||
| function getToolCallsFromParts({ | ||
@@ -1276,0 +1355,0 @@ parts, |
+3
-5
| { | ||
| "name": "@ai-sdk/google", | ||
| "version": "4.0.0-beta.13", | ||
| "version": "4.0.0-beta.14", | ||
| "license": "Apache-2.0", | ||
@@ -39,4 +39,4 @@ "sideEffects": false, | ||
| "dependencies": { | ||
| "@ai-sdk/provider": "4.0.0-beta.3", | ||
| "@ai-sdk/provider-utils": "5.0.0-beta.5" | ||
| "@ai-sdk/provider": "4.0.0-beta.4", | ||
| "@ai-sdk/provider-utils": "5.0.0-beta.6" | ||
| }, | ||
@@ -75,5 +75,3 @@ "devDependencies": { | ||
| "clean": "del-cli dist docs *.tsbuildinfo", | ||
| "lint": "eslint \"./**/*.ts*\"", | ||
| "type-check": "tsc --build", | ||
| "prettier-check": "prettier --check \"./**/*.ts*\"", | ||
| "test": "pnpm test:node && pnpm test:edge", | ||
@@ -80,0 +78,0 @@ "test:update": "pnpm test:node -u", |
@@ -20,3 +20,6 @@ import { | ||
| InferSchema, | ||
| isCustomReasoning, | ||
| lazySchema, | ||
| mapReasoningToProviderBudget, | ||
| mapReasoningToProviderEffort, | ||
| parseProviderOptions, | ||
@@ -100,2 +103,3 @@ ParseResult, | ||
| toolChoice, | ||
| reasoning, | ||
| providerOptions, | ||
@@ -156,2 +160,12 @@ }: LanguageModelV4CallOptions) { | ||
| const resolvedThinking = resolveThinkingConfig({ | ||
| reasoning, | ||
| modelId: this.modelId, | ||
| warnings, | ||
| }); | ||
| const thinkingConfig = | ||
| googleOptions?.thinkingConfig || resolvedThinking | ||
| ? { ...resolvedThinking, ...googleOptions?.thinkingConfig } | ||
| : undefined; | ||
| return { | ||
@@ -188,3 +202,3 @@ args: { | ||
| responseModalities: googleOptions?.responseModalities, | ||
| thinkingConfig: googleOptions?.thinkingConfig, | ||
| thinkingConfig, | ||
| ...(googleOptions?.mediaResolution && { | ||
@@ -713,2 +727,105 @@ mediaResolution: googleOptions.mediaResolution, | ||
| function isGemini3Model(modelId: string): boolean { | ||
| return /gemini-3[\.\-]/i.test(modelId) || /gemini-3$/i.test(modelId); | ||
| } | ||
| function getMaxOutputTokensForGemini25Model(): number { | ||
| return 65536; | ||
| } | ||
| function getMaxThinkingTokensForGemini25Model(modelId: string): number { | ||
| const id = modelId.toLowerCase(); | ||
| if (id.includes('2.5-pro') || id.includes('gemini-3-pro-image')) { | ||
| return 32768; | ||
| } | ||
| return 24576; | ||
| } | ||
| type GoogleThinkingConfig = NonNullable< | ||
| InferSchema<typeof googleLanguageModelOptions>['thinkingConfig'] | ||
| >; | ||
| function resolveThinkingConfig({ | ||
| reasoning, | ||
| modelId, | ||
| warnings, | ||
| }: { | ||
| reasoning: LanguageModelV4CallOptions['reasoning']; | ||
| modelId: string; | ||
| warnings: SharedV4Warning[]; | ||
| }): Omit<GoogleThinkingConfig, 'includeThoughts'> | undefined { | ||
| if (!isCustomReasoning(reasoning)) { | ||
| return undefined; | ||
| } | ||
| if (isGemini3Model(modelId) && !modelId.includes('gemini-3-pro-image')) { | ||
| return resolveGemini3ThinkingConfig({ reasoning, warnings }); | ||
| } | ||
| return resolveGemini25ThinkingConfig({ reasoning, modelId, warnings }); | ||
| } | ||
| function resolveGemini3ThinkingConfig({ | ||
| reasoning, | ||
| warnings, | ||
| }: { | ||
| reasoning: Exclude< | ||
| LanguageModelV4CallOptions['reasoning'], | ||
| 'provider-default' | undefined | ||
| >; | ||
| warnings: SharedV4Warning[]; | ||
| }): Pick<GoogleThinkingConfig, 'thinkingLevel'> | undefined { | ||
| if (reasoning === 'none') { | ||
| // It's not possible to fully disable thinking with Gemini 3. | ||
| return { thinkingLevel: 'minimal' }; | ||
| } | ||
| const thinkingLevel = mapReasoningToProviderEffort({ | ||
| reasoning, | ||
| effortMap: { | ||
| minimal: 'minimal', | ||
| low: 'low', | ||
| medium: 'medium', | ||
| high: 'high', | ||
| xhigh: 'high', | ||
| }, | ||
| warnings, | ||
| }); | ||
| if (thinkingLevel == null) { | ||
| return undefined; | ||
| } | ||
| return { thinkingLevel }; | ||
| } | ||
| function resolveGemini25ThinkingConfig({ | ||
| reasoning, | ||
| modelId, | ||
| warnings, | ||
| }: { | ||
| reasoning: Exclude< | ||
| LanguageModelV4CallOptions['reasoning'], | ||
| 'provider-default' | undefined | ||
| >; | ||
| modelId: string; | ||
| warnings: SharedV4Warning[]; | ||
| }): Pick<GoogleThinkingConfig, 'thinkingBudget'> | undefined { | ||
| if (reasoning === 'none') { | ||
| return { thinkingBudget: 0 }; | ||
| } | ||
| const thinkingBudget = mapReasoningToProviderBudget({ | ||
| reasoning, | ||
| maxOutputTokens: getMaxOutputTokensForGemini25Model(), | ||
| maxReasoningBudget: getMaxThinkingTokensForGemini25Model(modelId), | ||
| minReasoningBudget: 0, | ||
| warnings, | ||
| }); | ||
| if (thinkingBudget == null) { | ||
| return undefined; | ||
| } | ||
| return { thinkingBudget }; | ||
| } | ||
| function getToolCallsFromParts({ | ||
@@ -715,0 +832,0 @@ parts, |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
1149578
2.54%12792
3.34%2
-33.33%+ Added
+ Added
- Removed
- Removed