@ai-sdk/google 4.0.0-canary.80 → 4.0.0

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,164 @@
1
1
  # @ai-sdk/google
2
2
 
3
+ ## 4.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - a3757d7: chore(provider/google): remove useless GenerativeAI affix from types and classes for consistency
8
+ - f7d4f01: feat(provider): add support for `reasoning-file` type for files that are part of reasoning
9
+ - ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
10
+ - c29a26f: feat(provider): add support for provider references and uploading files as supported per provider
11
+ - 3887c70: feat(provider): add new top-level reasoning parameter to spec and support it in `generateText` and `streamText`
12
+ - 8359612: Start v7 pre-release
13
+ - 04e9009: chore: make provider implementations code patterns more consistent, including renaming certain exported symbols
14
+
15
+ For all externally exported symbols that were renamed, the old names continue to work via deprecated aliases.
16
+
17
+ ### Patch Changes
18
+
19
+ - 7f04802: feat(provider/google): add support for managed agents in the Interactions API
20
+ - 38fc777: Add AI Gateway hint to provider READMEs
21
+ - b71c0d7: feat(provider/google): support Google search grounding when using `generateImage` with Gemini
22
+ - 6190649: chore(provider/google): remove obsolete Google image model
23
+ - 55db546: fix(provider/google): fix Gemini service tier enum after upstream update
24
+ - 9a0a618: fix(google): fix `serviceTier` to be correctly formatted for Vertex API
25
+ - 00a0f36: feat(google, google-vertex): added `gemini-embedding-2`, `deep-research-max-preview-04-2026` and `deep-research-preview-04-2026`
26
+ - 9715ec7: feat(provider/google): add support for service tier parameter
27
+ - 41da50c: fix(provider/google): support `functionCall.id` when returned by Gemini API and provide matching `functionResponse.id`
28
+ - add4326: fix(provider/google): correct JSDoc for multimodal embedding content option
29
+ - a8d70b6: fix(google): auto-inject `skip_thought_signature_validator` for Gemini 3 tool-call replays without a signature
30
+ - 947cdab: Add Google realtime Live Translation provider options for `gemini-3.5-live-translate-preview`.
31
+ - 4e825f3: feat(google): update Interactions API implementation to cater for upstream breaking changes coming May 26
32
+ - b563707: feat(provider/google): add Gemini text-to-speech (speech) model support
33
+ - a05109d: feat(provider/google): preserve per-modality token details in usage data
34
+ - cfca634: fix(google): emit Vertex no-args streaming tool calls and preserve thoughtSignature
35
+
36
+ Vertex emits a no-args function call as a single chunk shaped `{ functionCall: { name: 'X' } }` with no `args`, no `partialArgs`, and no `willContinue`. The streaming parser had no branch for this shape, so the call was dropped along with any `thoughtSignature` it carried. For Gemini 3 thinking models this caused the next multi-turn step to 400 with `missing thought_signature`. The unary (`doGenerate`) path had the same drop.
37
+
38
+ Both paths now emit the call as a complete tool call with `'{}'` input and propagate `thoughtSignature` provider metadata.
39
+
40
+ Fixes #14847.
41
+
42
+ - c9c4661: fix(provider/google): preserve groundingMetadata and urlContextMetadata when they arrive in a stream chunk before the finishReason chunk
43
+ - 045d2e8: fix(google): read `serviceTier` from `usageMetadata.serviceTier` in both generate and stream paths
44
+
45
+ The previous implementation read `serviceTier` from the `x-gemini-service-tier`
46
+ response header, which is only populated on non-streaming responses. Gemini
47
+ streaming includes the value in `usageMetadata.serviceTier` on every chunk, so
48
+ `providerMetadata.google.serviceTier` was always `null` for streams. Read from
49
+ `usageMetadata` for both paths instead.
50
+
51
+ - 19b95f9: fix(google): use VALIDATED function calling mode when any tool has strict:true
52
+ - 2ce3c65: feat(provider/google-vertex): add Gemini text-to-speech (speech) model support
53
+ - 5878b40: fix(google): prevent prototype pollution when streaming tool args
54
+ - 46d1149: chore(provider-utils,google): fix grammar errors in error and warning messages
55
+ - 6a26901: feat(google): add `fileData` support to embedding model
56
+ - 01fa606: feat(provider/google): support combining built-in tools with function calling on Gemini 3
57
+ - 5036db8: feat(google-vertex): add support for streaming tool arguments input
58
+ - 9f0e36c: trigger release for all packages after provenance setup
59
+ - a2609df: fix(google): fix streaming tool call args
60
+ - ab43029: feat(provider/google): support multimodal content parts in embedding provider options
61
+ - 82288b0: feat(provider/google): add `gemini-embedding-2-preview` and fix multimodal embedding support with `embedMany`
62
+ - b04e23e: feat(provider/google): add support for the Gemini Interactions API
63
+ - 58a2ad7: fix: more precise default message for tool execution denial
64
+ - e59176c: chore(google): update v3 specs to v4
65
+ - ebbb0f2: fix(provider/google): fix lack of image consistency when using Interactions API in stateless mode
66
+ - aeda373: fix: only send provider credentials to same-origin response-supplied URLs
67
+
68
+ Several provider clients followed a URL taken from the provider's API response (a polling/status URL or a final media URL such as `polling_url`, `urls.get`, `result_url`, `result.sample`, or `video.uri`) and reused the authenticated headers — or appended `?key=<API_KEY>` — on that request. Because the host of the response-supplied URL was never validated, the long-lived API key was sent to whatever host the response named (a CDN in the benign case, or an attacker-chosen host if the provider response was tampered with), allowing credential exfiltration.
69
+
70
+ A new `isSameOrigin` helper is added to `@ai-sdk/provider-utils`, and the affected fetches in `@ai-sdk/black-forest-labs`, `@ai-sdk/fireworks`, `@ai-sdk/replicate`, `@ai-sdk/gladia`, `@ai-sdk/fal`, and `@ai-sdk/google` now attach credentials only when the followed URL is same-origin with the provider's configured API origin. Requests to a foreign origin are made without the credential.
71
+
72
+ - 7fc6bd6: Raise minimum supported Node.js version to 22. Supported versions: 22, 24, and 26.
73
+ - 0c4c275: trigger initial canary release
74
+ - bdb9ea1: chore(google): remove now obsolete Interactions API `Api-Revision` header
75
+ - db394ab: feat(provider/google): support cancelling long-running Interactions API agents via AbortSignal, and process their intermittent stream
76
+ - ce769dd: feat(provider): add experimental Realtime API support for voice conversations
77
+
78
+ Adds first-class support for realtime (speech-to-speech) APIs:
79
+
80
+ - `Experimental_RealtimeModelV4` spec in `@ai-sdk/provider` with normalized event types and factory
81
+ - OpenAI, Google, and xAI realtime provider implementations
82
+ - `openai.experimental_realtime()` / `google.experimental_realtime()` / `xai.experimental_realtime()` work in both server and browser
83
+ - `.getToken()` static method on each provider for server-side ephemeral token creation
84
+ - `experimental_getRealtimeToolDefinitions` helper for provider session tool definitions
85
+ - `experimental_useRealtime` hook in `@ai-sdk/react` returning `UIMessage[]` (aligned with `useChat`), with `onToolCall` and `addToolOutput` for client-driven tool execution
86
+ - `inputAudioTranscription` session config for showing transcribed user audio messages when supported by the provider
87
+
88
+ - 5b7e7c2: fix(google-vertex): don't send streamFunctionCallArguments for unary API calls and change default to false
89
+ - 2edd14e: fix(provider/google): correctly mark reasoning files as such and fix related multi-turn errors
90
+ - 9bd6512: feat(provider): change file part data property to be tagged with a type and remove the image part type
91
+ - 258c093: chore: ensure consistent import handling and avoid import duplicates or cycles
92
+ - 546cefe: feat(provider/google): add `gemini-3.5-flash`
93
+ - 5463d0d: feat(provider): align tool result output content file part types with top-level message file part types
94
+ - 55f0938: chore(provider/google): update available models
95
+ - b8396f0: trigger initial beta release
96
+ - 84f36e0: fix(google): omit passing includeServerSideToolInvocations for Vertex tool_config
97
+ - 90e2d8a: chore: fix unused vars not being flagged by our lint tooling
98
+ - 4dac142: feat(google): add new finishMessage field in providerMetadata
99
+ - aeea161: feat(google): read `serviceTier` from `x-gemini-service-tier` response header in Gemini API and use PayGo for Vertex
100
+ - 18c1970: feat(provider/google): Add multimodal tool-result support for Google function responses.
101
+
102
+ Tool results with `output.type = 'content'` now map media parts into
103
+ `functionResponse.parts` for Google models, including `image-data`,
104
+ `file-data`, and base64 `data:` URLs in URL-style content parts.
105
+ Remote HTTP(S) URLs in URL-style tool-result parts are not supported.
106
+
107
+ - b3976a2: Add workflow serialization support to all provider models.
108
+
109
+ **`@ai-sdk/provider-utils`:** New `serializeModel()` helper that extracts only serializable properties from a model instance, filtering out functions and objects containing functions. Third-party provider authors can use this to add workflow support to their own models.
110
+
111
+ **All providers:** `headers` is now optional in provider config types. This is non-breaking — existing code that passes `headers` continues to work. Custom provider implementations that construct model configs manually can now omit `headers`, which is useful when models are deserialized from a workflow step boundary where auth is provided separately.
112
+
113
+ All provider model classes now include `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` static methods, enabling them to cross workflow step boundaries without serialization errors.
114
+
115
+ - ff5eba1: feat: roll `image-*` tool output types into their equivalent `file-*` types
116
+
117
+ ## 4.0.0-beta.85
118
+
119
+ ### Patch Changes
120
+
121
+ - Updated dependencies [0416e3e]
122
+ - @ai-sdk/provider@4.0.0-beta.20
123
+ - @ai-sdk/provider-utils@5.0.0-beta.50
124
+
125
+ ## 4.0.0-beta.84
126
+
127
+ ### Patch Changes
128
+
129
+ - 947cdab: Add Google realtime Live Translation provider options for `gemini-3.5-live-translate-preview`.
130
+
131
+ ## 4.0.0-beta.83
132
+
133
+ ### Patch Changes
134
+
135
+ - bdb9ea1: chore(google): remove now obsolete Interactions API `Api-Revision` header
136
+
137
+ ## 4.0.0-beta.82
138
+
139
+ ### Patch Changes
140
+
141
+ - b8396f0: trigger initial beta release
142
+ - Updated dependencies [b8396f0]
143
+ - @ai-sdk/provider-utils@5.0.0-beta.49
144
+ - @ai-sdk/provider@4.0.0-beta.19
145
+
146
+ ## 4.0.0-canary.81
147
+
148
+ ### Patch Changes
149
+
150
+ - 5878b40: fix(google): prevent prototype pollution when streaming tool args
151
+ - aeda373: fix: only send provider credentials to same-origin response-supplied URLs
152
+
153
+ Several provider clients followed a URL taken from the provider's API response (a polling/status URL or a final media URL such as `polling_url`, `urls.get`, `result_url`, `result.sample`, or `video.uri`) and reused the authenticated headers — or appended `?key=<API_KEY>` — on that request. Because the host of the response-supplied URL was never validated, the long-lived API key was sent to whatever host the response named (a CDN in the benign case, or an attacker-chosen host if the provider response was tampered with), allowing credential exfiltration.
154
+
155
+ A new `isSameOrigin` helper is added to `@ai-sdk/provider-utils`, and the affected fetches in `@ai-sdk/black-forest-labs`, `@ai-sdk/fireworks`, `@ai-sdk/replicate`, `@ai-sdk/gladia`, `@ai-sdk/fal`, and `@ai-sdk/google` now attach credentials only when the followed URL is same-origin with the provider's configured API origin. Requests to a foreign origin are made without the credential.
156
+
157
+ - Updated dependencies [aeda373]
158
+ - Updated dependencies [375fdd7]
159
+ - Updated dependencies [b4507d5]
160
+ - @ai-sdk/provider-utils@5.0.0-canary.48
161
+
3
162
  ## 4.0.0-canary.80
4
163
 
5
164
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -622,6 +622,28 @@ declare class GoogleRealtimeModel implements Experimental_RealtimeModelV4 {
622
622
  buildSessionConfig(config: Experimental_RealtimeModelV4SessionConfig): Record<string, unknown>;
623
623
  }
624
624
 
625
+ type GoogleRealtimeModelId = string;
626
+ type GoogleRealtimeModelOptions = {
627
+ /**
628
+ * Gemini Live Translation configuration.
629
+ *
630
+ * Required for `gemini-3.5-live-translate-preview` when translating speech
631
+ * to a target language.
632
+ */
633
+ translationConfig?: {
634
+ /**
635
+ * BCP-47 language code of the language to translate into.
636
+ * Defaults to `en` in the Gemini API.
637
+ */
638
+ targetLanguageCode?: string;
639
+ /**
640
+ * Whether input audio already in the target language should be echoed
641
+ * instead of producing silence.
642
+ */
643
+ echoTargetLanguage?: boolean;
644
+ };
645
+ };
646
+
625
647
  declare const VERSION: string;
626
648
 
627
- export { GoogleRealtimeModel as Experimental_GoogleRealtimeModel, type GoogleRealtimeModelConfig as Experimental_GoogleRealtimeModelConfig, type GoogleEmbeddingModelOptions, type GoogleErrorData, type GoogleFilesUploadOptions, type GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions, type GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions, type GoogleProvider as GoogleGenerativeAIProvider, type GoogleProviderMetadata as GoogleGenerativeAIProviderMetadata, type GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions, type GoogleProviderSettings as GoogleGenerativeAIProviderSettings, type GoogleVideoModelId as GoogleGenerativeAIVideoModelId, type GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions, type GoogleImageModelOptions, type GoogleInteractionsAgentName, type GoogleInteractionsModelId, type GoogleInteractionsProviderMetadata, type GoogleLanguageModelInteractionsOptions, type GoogleLanguageModelOptions, type GoogleProvider, type GoogleProviderMetadata, type GoogleProviderSettings, type GoogleSpeechModelId, type GoogleSpeechModelOptions, type GoogleVideoModelId, type GoogleVideoModelOptions, VERSION, createGoogle, createGoogle as createGoogleGenerativeAI, google };
649
+ export { GoogleRealtimeModel as Experimental_GoogleRealtimeModel, type GoogleRealtimeModelConfig as Experimental_GoogleRealtimeModelConfig, type GoogleRealtimeModelId as Experimental_GoogleRealtimeModelId, type GoogleRealtimeModelOptions as Experimental_GoogleRealtimeModelOptions, type GoogleEmbeddingModelOptions, type GoogleErrorData, type GoogleFilesUploadOptions, type GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions, type GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions, type GoogleProvider as GoogleGenerativeAIProvider, type GoogleProviderMetadata as GoogleGenerativeAIProviderMetadata, type GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions, type GoogleProviderSettings as GoogleGenerativeAIProviderSettings, type GoogleVideoModelId as GoogleGenerativeAIVideoModelId, type GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions, type GoogleImageModelOptions, type GoogleInteractionsAgentName, type GoogleInteractionsModelId, type GoogleInteractionsProviderMetadata, type GoogleLanguageModelInteractionsOptions, type GoogleLanguageModelOptions, type GoogleProvider, type GoogleProviderMetadata, type GoogleProviderSettings, type GoogleSpeechModelId, type GoogleSpeechModelOptions, type GoogleVideoModelId, type GoogleVideoModelOptions, VERSION, createGoogle, createGoogle as createGoogleGenerativeAI, google };
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "4.0.0-canary.80" : "0.0.0-test";
10
+ var VERSION = true ? "4.0.0" : "0.0.0-test";
11
11
 
12
12
  // src/google-embedding-model.ts
13
13
  import {
@@ -1484,11 +1484,25 @@ function parsePath(rawPath) {
1484
1484
  }
1485
1485
  return segments;
1486
1486
  }
1487
+ var hasOwn = Object.prototype.hasOwnProperty;
1488
+ function hasOwnProperty(obj, key) {
1489
+ return hasOwn.call(obj, key);
1490
+ }
1491
+ function defineOwnProperty(obj, key, value) {
1492
+ Object.defineProperty(obj, key, {
1493
+ value,
1494
+ enumerable: true,
1495
+ configurable: true,
1496
+ writable: true
1497
+ });
1498
+ }
1487
1499
  function getNestedValue(obj, segments) {
1488
1500
  let current = obj;
1489
1501
  for (const pathSegment of segments) {
1490
1502
  if (current == null || typeof current !== "object") return void 0;
1491
- current = current[pathSegment];
1503
+ const currentRecord = current;
1504
+ if (!hasOwnProperty(currentRecord, pathSegment)) return void 0;
1505
+ current = currentRecord[pathSegment];
1492
1506
  }
1493
1507
  return current;
1494
1508
  }
@@ -1497,12 +1511,16 @@ function setNestedValue(obj, segments, value) {
1497
1511
  for (let i = 0; i < segments.length - 1; i++) {
1498
1512
  const pathSegment = segments[i];
1499
1513
  const nextSeg = segments[i + 1];
1500
- if (current[pathSegment] == null) {
1501
- current[pathSegment] = typeof nextSeg === "number" ? [] : {};
1514
+ if (!hasOwnProperty(current, pathSegment) || current[pathSegment] == null) {
1515
+ defineOwnProperty(
1516
+ current,
1517
+ pathSegment,
1518
+ typeof nextSeg === "number" ? [] : {}
1519
+ );
1502
1520
  }
1503
1521
  current = current[pathSegment];
1504
1522
  }
1505
- current[segments[segments.length - 1]] = value;
1523
+ defineOwnProperty(current, segments[segments.length - 1], value);
1506
1524
  }
1507
1525
  function resolvePartialArgValue(arg) {
1508
1526
  var _a, _b;
@@ -3314,6 +3332,7 @@ import {
3314
3332
  createJsonResponseHandler as createJsonResponseHandler5,
3315
3333
  delay as delay2,
3316
3334
  getFromApi as getFromApi2,
3335
+ isSameOrigin,
3317
3336
  parseProviderOptions as parseProviderOptions5,
3318
3337
  postJsonToApi as postJsonToApi4,
3319
3338
  resolve as resolve4
@@ -3519,7 +3538,7 @@ var GoogleVideoModel = class {
3519
3538
  const apiKey = resolvedHeaders == null ? void 0 : resolvedHeaders["x-goog-api-key"];
3520
3539
  for (const generatedSample of response.generateVideoResponse.generatedSamples) {
3521
3540
  if ((_h = generatedSample.video) == null ? void 0 : _h.uri) {
3522
- const urlWithAuth = apiKey ? `${generatedSample.video.uri}${generatedSample.video.uri.includes("?") ? "&" : "?"}key=${apiKey}` : generatedSample.video.uri;
3541
+ const urlWithAuth = apiKey && isSameOrigin(generatedSample.video.uri, this.config.baseURL) ? `${generatedSample.video.uri}${generatedSample.video.uri.includes("?") ? "&" : "?"}key=${apiKey}` : generatedSample.video.uri;
3523
3542
  videos.push({
3524
3543
  type: "url",
3525
3544
  url: urlWithAuth,
@@ -6477,7 +6496,6 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6477
6496
  const { args, warnings, isAgent, pollingTimeoutMs } = await this.getArgs(options);
6478
6497
  const url = `${this.config.baseURL}/interactions`;
6479
6498
  const mergedHeaders = combineHeaders8(
6480
- INTERACTIONS_API_REVISION_HEADER,
6481
6499
  this.config.headers ? await resolve6(this.config.headers) : void 0,
6482
6500
  options.headers
6483
6501
  );
@@ -6558,7 +6576,6 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6558
6576
  const { args, warnings, isBackground, pollingTimeoutMs } = await this.getArgs(options);
6559
6577
  const url = `${this.config.baseURL}/interactions`;
6560
6578
  const mergedHeaders = combineHeaders8(
6561
- INTERACTIONS_API_REVISION_HEADER,
6562
6579
  this.config.headers ? await resolve6(this.config.headers) : void 0,
6563
6580
  options.headers
6564
6581
  );
@@ -6678,9 +6695,6 @@ var GoogleInteractionsLanguageModel = class _GoogleInteractionsLanguageModel {
6678
6695
  };
6679
6696
  }
6680
6697
  };
6681
- var INTERACTIONS_API_REVISION_HEADER = {
6682
- "Api-Revision": "2026-05-20"
6683
- };
6684
6698
  function pruneUndefined(obj) {
6685
6699
  const result = {};
6686
6700
  for (const [key, value] of Object.entries(obj)) {
@@ -6692,6 +6706,9 @@ function pruneUndefined(obj) {
6692
6706
 
6693
6707
  // src/realtime/google-realtime-event-mapper.ts
6694
6708
  import { safeParseJSON } from "@ai-sdk/provider-utils";
6709
+ function isRecord(value) {
6710
+ return value != null && typeof value === "object" && !Array.isArray(value);
6711
+ }
6695
6712
  var GoogleRealtimeEventMapper = class {
6696
6713
  constructor() {
6697
6714
  this.turnCounter = 0;
@@ -6886,6 +6903,11 @@ var GoogleRealtimeEventMapper = class {
6886
6903
  }
6887
6904
  };
6888
6905
  case "input-audio-commit":
6906
+ return {
6907
+ realtimeInput: {
6908
+ audioStreamEnd: true
6909
+ }
6910
+ };
6889
6911
  case "input-audio-clear":
6890
6912
  case "response-create":
6891
6913
  case "response-cancel":
@@ -6970,8 +6992,18 @@ function buildGoogleSessionConfig(config, modelId) {
6970
6992
  if ((config == null ? void 0 : config.outputAudioTranscription) != null) {
6971
6993
  setup.outputAudioTranscription = {};
6972
6994
  }
6973
- if ((config == null ? void 0 : config.providerOptions) != null) {
6974
- Object.assign(setup, config.providerOptions);
6995
+ if ((config == null ? void 0 : config.providerOptions) == null) {
6996
+ return setup;
6997
+ }
6998
+ const { google: google2, ...providerOptions } = config.providerOptions;
6999
+ Object.assign(setup, providerOptions);
7000
+ const googleOptions = isRecord(google2) ? google2 : void 0;
7001
+ if ((googleOptions == null ? void 0 : googleOptions.translationConfig) != null) {
7002
+ const target = isRecord(setup.generationConfig) ? setup.generationConfig : generationConfig;
7003
+ setup.generationConfig = {
7004
+ ...target,
7005
+ translationConfig: googleOptions.translationConfig
7006
+ };
6975
7007
  }
6976
7008
  return setup;
6977
7009
  }