@ai-sdk/google 4.0.73 → 4.0.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 4.0.75
4
+
5
+ ### Patch Changes
6
+
7
+ - e369c4d: fix(google): advertise the supported Gemini image per-call limit
8
+ - 2b391f8: fix(google): ignore default prompt block reasons in non-streaming responses
9
+ - 1284569: fix(google): include tool-use prompt tokens in input usage
10
+ - Updated dependencies [0455398]
11
+ - @ai-sdk/provider-utils@5.0.44
12
+
13
+ ## 4.0.74
14
+
15
+ ### Patch Changes
16
+
17
+ - d4d96bf: Add `google.evaluationModel()` for experimental Choice, Score, and Boolean evaluations through Gemini structured output, preserving provider thinking options and validating exact labels and score bounds. Boolean answers contain prompted P(true) estimates validated to be in [0, 1]. Boolean estimates are not guaranteed to be calibrated; application code chooses thresholds.
18
+ - Updated dependencies [215b25e]
19
+ - Updated dependencies [d4d96bf]
20
+ - Updated dependencies [a7dd893]
21
+ - Updated dependencies [3456e2c]
22
+ - Updated dependencies [c4e76de]
23
+ - @ai-sdk/provider-utils@5.0.43
24
+ - @ai-sdk/provider@4.0.17
25
+
3
26
  ## 4.0.73
4
27
 
5
28
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
2
2
  import { InferSchema, FetchFunction, WebSocketConstructor, WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE, Resolvable } from '@ai-sdk/provider-utils';
3
3
  import { z } from 'zod/v4';
4
4
  import * as _ai_sdk_provider from '@ai-sdk/provider';
5
- import { ProviderV4, LanguageModelV4, Experimental_BatchV4, ImageModelV4, EmbeddingModelV4, Experimental_VideoModelV4, Experimental_SpeechTranslationModelV4, SpeechModelV4, TranscriptionModelV4, FilesV4, Experimental_RealtimeFactoryV4, Experimental_RealtimeModelV4, Experimental_RealtimeModelV4ClientSecretOptions, Experimental_RealtimeModelV4ClientSecretResult, Experimental_RealtimeModelV4ServerEvent, Experimental_RealtimeModelV4ClientEvent, Experimental_RealtimeModelV4SessionConfig, JSONObject, Experimental_TranscriptionModelV4StreamOptions, Experimental_SpeechTranslationModelV4StreamOptions } from '@ai-sdk/provider';
5
+ import { ProviderV4, LanguageModelV4, Experimental_EvaluationModelV4, Experimental_BatchV4, ImageModelV4, EmbeddingModelV4, Experimental_VideoModelV4, Experimental_SpeechTranslationModelV4, SpeechModelV4, TranscriptionModelV4, FilesV4, Experimental_RealtimeFactoryV4, Experimental_RealtimeModelV4, Experimental_RealtimeModelV4ClientSecretOptions, Experimental_RealtimeModelV4ClientSecretResult, Experimental_RealtimeModelV4ServerEvent, Experimental_RealtimeModelV4ClientEvent, Experimental_RealtimeModelV4SessionConfig, JSONObject, Experimental_TranscriptionModelV4StreamOptions, Experimental_SpeechTranslationModelV4StreamOptions } from '@ai-sdk/provider';
6
6
 
7
7
  declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{
8
8
  error: {
@@ -559,7 +559,7 @@ declare const googleTools: {
559
559
  type GoogleImageModelId = 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | 'gemini-3.1-flash-image-preview' | (string & {});
560
560
  interface GoogleImageSettings {
561
561
  /**
562
- * Override the maximum number of images per call (default 10)
562
+ * Override the maximum number of images per call (default 1)
563
563
  */
564
564
  maxImagesPerCall?: number;
565
565
  }
@@ -592,6 +592,8 @@ interface GoogleProvider extends ProviderV4 {
592
592
  (modelId: GoogleModelId): LanguageModelV4;
593
593
  languageModel(modelId: GoogleModelId): LanguageModelV4;
594
594
  chat(modelId: GoogleModelId): LanguageModelV4;
595
+ /** Creates an experimental Choice/Score/Boolean evaluation model using Gemini. */
596
+ evaluationModel(modelId: GoogleModelId): Experimental_EvaluationModelV4;
595
597
  experimental_batch(): Experimental_BatchV4<{
596
598
  text: GoogleModelId;
597
599
  image: GoogleImageModelId;
package/dist/index.js CHANGED
@@ -5,9 +5,10 @@ import {
5
5
  withoutTrailingSlash,
6
6
  withUserAgentSuffix as withUserAgentSuffix2
7
7
  } from "@ai-sdk/provider-utils";
8
+ import { Experimental_EvaluationLanguageModel as EvaluationLanguageModel } from "@ai-sdk/provider-utils/experimental-evaluation";
8
9
 
9
10
  // src/version.ts
10
- var VERSION = true ? "4.0.73" : "0.0.0-test";
11
+ var VERSION = true ? "4.0.75" : "0.0.0-test";
11
12
 
12
13
  // src/google-embedding-model.ts
13
14
  import {
@@ -305,18 +306,20 @@ import { z as z5 } from "zod/v4";
305
306
  // src/convert-google-usage.ts
306
307
  import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
307
308
  function convertGoogleUsage(usage) {
308
- var _a, _b, _c, _d;
309
+ var _a, _b, _c, _d, _e;
309
310
  if (usage == null) {
310
311
  return createNullLanguageModelUsage();
311
312
  }
312
313
  const promptTokens = (_a = usage.promptTokenCount) != null ? _a : 0;
313
314
  const candidatesTokens = (_b = usage.candidatesTokenCount) != null ? _b : 0;
314
- const cachedContentTokens = (_c = usage.cachedContentTokenCount) != null ? _c : 0;
315
- const thoughtsTokens = (_d = usage.thoughtsTokenCount) != null ? _d : 0;
315
+ const toolUsePromptTokens = (_c = usage.toolUsePromptTokenCount) != null ? _c : 0;
316
+ const cachedContentTokens = (_d = usage.cachedContentTokenCount) != null ? _d : 0;
317
+ const thoughtsTokens = (_e = usage.thoughtsTokenCount) != null ? _e : 0;
318
+ const inputTokens = promptTokens + toolUsePromptTokens;
316
319
  return {
317
320
  inputTokens: {
318
- total: promptTokens,
319
- noCache: promptTokens - cachedContentTokens,
321
+ total: inputTokens,
322
+ noCache: inputTokens - cachedContentTokens,
320
323
  cacheRead: cachedContentTokens,
321
324
  cacheWrite: void 0
322
325
  },
@@ -1899,27 +1902,30 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1899
1902
  providerOptionsNames,
1900
1903
  toolNameMapping
1901
1904
  }) {
1902
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
1905
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
1903
1906
  const wrapProviderMetadata = (payload) => Object.fromEntries(
1904
1907
  providerOptionsNames.map((name) => [name, payload])
1905
1908
  );
1906
1909
  const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
1907
1910
  const promptBlockReason = (_b = response.promptFeedback) == null ? void 0 : _b.blockReason;
1908
- const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && promptBlockReason != null;
1909
- const rawFinishReason = (_d = (_c = candidate == null ? void 0 : candidate.finishReason) != null ? _c : promptBlockReason) != null ? _d : void 0;
1911
+ const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
1912
+ promptBlockReason
1913
+ ) ? promptBlockReason : void 0;
1914
+ const isPromptBlocked = (candidate == null ? void 0 : candidate.finishReason) == null && confirmedPromptBlockReason != null;
1915
+ const rawFinishReason = (_c = candidate == null ? void 0 : candidate.finishReason) != null ? _c : confirmedPromptBlockReason;
1910
1916
  const content = [];
1911
- const parts = (_f = (_e = candidate == null ? void 0 : candidate.content) == null ? void 0 : _e.parts) != null ? _f : [];
1917
+ const parts = (_e = (_d = candidate == null ? void 0 : candidate.content) == null ? void 0 : _d.parts) != null ? _e : [];
1912
1918
  const usageMetadata = response.usageMetadata;
1913
1919
  let lastCodeExecutionToolCallId;
1914
1920
  let lastServerToolCallId;
1915
1921
  for (const part of parts) {
1916
- if ("executableCode" in part && ((_g = part.executableCode) == null ? void 0 : _g.code)) {
1922
+ if ("executableCode" in part && ((_f = part.executableCode) == null ? void 0 : _f.code)) {
1917
1923
  const toolCallId = config.generateId();
1918
1924
  lastCodeExecutionToolCallId = toolCallId;
1919
1925
  content.push({
1920
1926
  type: "tool-call",
1921
1927
  toolCallId,
1922
- toolName: (_h = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _h : "code_execution",
1928
+ toolName: (_g = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _g : "code_execution",
1923
1929
  input: JSON.stringify(part.executableCode),
1924
1930
  providerExecuted: true
1925
1931
  });
@@ -1928,10 +1934,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1928
1934
  type: "tool-result",
1929
1935
  // Results correspond to the most recent executable code part.
1930
1936
  toolCallId: lastCodeExecutionToolCallId,
1931
- toolName: (_i = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _i : "code_execution",
1937
+ toolName: (_h = toolNameMapping == null ? void 0 : toolNameMapping.toCustomToolName("code_execution")) != null ? _h : "code_execution",
1932
1938
  result: {
1933
1939
  outcome: part.codeExecutionResult.outcome,
1934
- output: (_j = part.codeExecutionResult.output) != null ? _j : ""
1940
+ output: (_i = part.codeExecutionResult.output) != null ? _i : ""
1935
1941
  }
1936
1942
  });
1937
1943
  } else if ("text" in part && part.text != null) {
@@ -1955,7 +1961,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1955
1961
  type: "tool-call",
1956
1962
  toolCallId: part.functionCall.id || config.generateId(),
1957
1963
  toolName: part.functionCall.name,
1958
- input: JSON.stringify((_k = part.functionCall.args) != null ? _k : {}),
1964
+ input: JSON.stringify((_j = part.functionCall.args) != null ? _j : {}),
1959
1965
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1960
1966
  thoughtSignature: part.thoughtSignature
1961
1967
  }) : void 0
@@ -1978,7 +1984,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1978
1984
  type: "tool-call",
1979
1985
  toolCallId,
1980
1986
  toolName: `server:${part.toolCall.toolType}`,
1981
- input: JSON.stringify((_l = part.toolCall.args) != null ? _l : {}),
1987
+ input: JSON.stringify((_k = part.toolCall.args) != null ? _k : {}),
1982
1988
  providerExecuted: true,
1983
1989
  dynamic: true,
1984
1990
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
@@ -1996,7 +2002,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1996
2002
  type: "tool-result",
1997
2003
  toolCallId: responseToolCallId,
1998
2004
  toolName: `server:${part.toolResponse.toolType}`,
1999
- result: (_m = part.toolResponse.response) != null ? _m : {},
2005
+ result: (_l = part.toolResponse.response) != null ? _l : {},
2000
2006
  providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
2001
2007
  thoughtSignature: part.thoughtSignature,
2002
2008
  serverToolCallId: responseToolCallId,
@@ -2009,10 +2015,10 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2009
2015
  lastServerToolCallId = void 0;
2010
2016
  }
2011
2017
  }
2012
- const sources = (_n = extractSources({
2018
+ const sources = (_m = extractSources({
2013
2019
  groundingMetadata: candidate == null ? void 0 : candidate.groundingMetadata,
2014
2020
  generateId: config.generateId
2015
- })) != null ? _n : [];
2021
+ })) != null ? _m : [];
2016
2022
  for (const source of sources) {
2017
2023
  content.push(source);
2018
2024
  }
@@ -2031,17 +2037,17 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2031
2037
  usage: convertGoogleUsage(usageMetadata),
2032
2038
  warnings,
2033
2039
  providerMetadata: wrapProviderMetadata({
2034
- promptFeedback: (_o = response.promptFeedback) != null ? _o : null,
2035
- groundingMetadata: (_p = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _p : null,
2036
- urlContextMetadata: (_q = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _q : null,
2037
- safetyRatings: (_r = candidate == null ? void 0 : candidate.safetyRatings) != null ? _r : null,
2040
+ promptFeedback: (_n = response.promptFeedback) != null ? _n : null,
2041
+ groundingMetadata: (_o = candidate == null ? void 0 : candidate.groundingMetadata) != null ? _o : null,
2042
+ urlContextMetadata: (_p = candidate == null ? void 0 : candidate.urlContextMetadata) != null ? _p : null,
2043
+ safetyRatings: (_q = candidate == null ? void 0 : candidate.safetyRatings) != null ? _q : null,
2038
2044
  usageMetadata: usageMetadata != null ? usageMetadata : null,
2039
- finishMessage: (_s = candidate == null ? void 0 : candidate.finishMessage) != null ? _s : null,
2040
- serviceTier: (_t = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _t : null
2045
+ finishMessage: (_r = candidate == null ? void 0 : candidate.finishMessage) != null ? _r : null,
2046
+ serviceTier: (_s = usageMetadata == null ? void 0 : usageMetadata.serviceTier) != null ? _s : null
2041
2047
  }),
2042
2048
  response: {
2043
2049
  // TODO timestamp, model id
2044
- id: (_u = response.responseId) != null ? _u : void 0
2050
+ id: (_t = response.responseId) != null ? _t : void 0
2045
2051
  }
2046
2052
  };
2047
2053
  }
@@ -3856,7 +3862,7 @@ var GoogleImageModel = class _GoogleImageModel {
3856
3862
  if (this.settings.maxImagesPerCall != null) {
3857
3863
  return this.settings.maxImagesPerCall;
3858
3864
  }
3859
- return 10;
3865
+ return 1;
3860
3866
  }
3861
3867
  get provider() {
3862
3868
  return this.config.provider;
@@ -3870,7 +3876,6 @@ var GoogleImageModel = class _GoogleImageModel {
3870
3876
  }
3871
3877
  const {
3872
3878
  prompt,
3873
- n,
3874
3879
  size,
3875
3880
  aspectRatio,
3876
3881
  seed,
@@ -3886,11 +3891,6 @@ var GoogleImageModel = class _GoogleImageModel {
3886
3891
  "Gemini image models do not support mask-based image editing."
3887
3892
  );
3888
3893
  }
3889
- if (n != null && n > 1) {
3890
- throw new Error(
3891
- "Gemini image models do not support generating a set number of images per call. Use n=1 or omit the n parameter."
3892
- );
3893
- }
3894
3894
  if (size != null) {
3895
3895
  warnings.push({
3896
3896
  type: "unsupported",
@@ -9489,6 +9489,10 @@ function createGoogle(options = {}) {
9489
9489
  provider.languageModel = createChatModel;
9490
9490
  provider.chat = createChatModel;
9491
9491
  provider.generativeAI = createChatModel;
9492
+ provider.evaluationModel = (modelId) => new EvaluationLanguageModel({
9493
+ model: createChatModel(modelId),
9494
+ provider: `${providerName.replace(/\.generative-ai$/, "")}.evaluation`
9495
+ });
9492
9496
  provider.experimental_batch = createBatch;
9493
9497
  provider.embedding = createEmbeddingModel;
9494
9498
  provider.embeddingModel = createEmbeddingModel;