@ai-sdk/google 4.0.0-beta.46 → 4.0.0-beta.48

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google",
3
- "version": "4.0.0-beta.46",
3
+ "version": "4.0.0-beta.48",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -35,15 +35,15 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@ai-sdk/provider-utils": "5.0.0-beta.27",
39
- "@ai-sdk/provider": "4.0.0-beta.12"
38
+ "@ai-sdk/provider": "4.0.0-beta.14",
39
+ "@ai-sdk/provider-utils": "5.0.0-beta.29"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "20.17.24",
43
43
  "tsup": "^8",
44
44
  "typescript": "5.8.3",
45
45
  "zod": "3.25.76",
46
- "@ai-sdk/test-server": "2.0.0-beta.1",
46
+ "@ai-sdk/test-server": "2.0.0-beta.3",
47
47
  "@vercel/ai-tsconfig": "0.0.0"
48
48
  },
49
49
  "peerDependencies": {
@@ -59,7 +59,8 @@
59
59
  "homepage": "https://ai-sdk.dev/docs",
60
60
  "repository": {
61
61
  "type": "git",
62
- "url": "git+https://github.com/vercel/ai.git"
62
+ "url": "https://github.com/vercel/ai",
63
+ "directory": "packages/google"
63
64
  },
64
65
  "bugs": {
65
66
  "url": "https://github.com/vercel/ai/issues"
@@ -1,4 +1,4 @@
1
- import { LanguageModelV4Usage } from '@ai-sdk/provider';
1
+ import type { LanguageModelV4Usage } from '@ai-sdk/provider';
2
2
 
3
3
  export type GoogleTokenDetail = {
4
4
  modality: string;
@@ -1,4 +1,4 @@
1
- import { JSONSchema7Definition } from '@ai-sdk/provider';
1
+ import type { JSONSchema7Definition } from '@ai-sdk/provider';
2
2
 
3
3
  /**
4
4
  * Converts JSON Schema 7 to OpenAPI Schema 3.0
@@ -1,13 +1,14 @@
1
1
  import {
2
- LanguageModelV4Prompt,
3
2
  UnsupportedFunctionalityError,
3
+ type LanguageModelV4Prompt,
4
4
  } from '@ai-sdk/provider';
5
5
  import {
6
6
  convertToBase64,
7
- isProviderReference,
7
+ isFullMediaType,
8
+ resolveFullMediaType,
8
9
  resolveProviderReference,
9
10
  } from '@ai-sdk/provider-utils';
10
- import {
11
+ import type {
11
12
  GoogleContent,
12
13
  GoogleContentPart,
13
14
  GoogleFunctionResponsePart,
@@ -209,39 +210,56 @@ export function convertToGoogleMessages(
209
210
  }
210
211
 
211
212
  case 'file': {
212
- const mediaType =
213
- part.mediaType === 'image/*' ? 'image/jpeg' : part.mediaType;
214
-
215
- if (part.data instanceof URL) {
216
- parts.push({
217
- fileData: {
218
- mimeType: mediaType,
219
- fileUri: part.data.toString(),
220
- },
221
- });
222
- } else if (isProviderReference(part.data)) {
223
- if (providerOptionsName === 'vertex') {
224
- throw new UnsupportedFunctionalityError({
225
- functionality: 'file parts with provider references',
213
+ switch (part.data.type) {
214
+ case 'url': {
215
+ parts.push({
216
+ fileData: {
217
+ mimeType: resolveFullMediaType({ part }),
218
+ fileUri: part.data.url.toString(),
219
+ },
226
220
  });
221
+ break;
227
222
  }
223
+ case 'reference': {
224
+ if (providerOptionsName === 'vertex') {
225
+ throw new UnsupportedFunctionalityError({
226
+ functionality: 'file parts with provider references',
227
+ });
228
+ }
228
229
 
229
- parts.push({
230
- fileData: {
231
- mimeType: mediaType,
232
- fileUri: resolveProviderReference({
233
- reference: part.data,
234
- provider: 'google',
235
- }),
236
- },
237
- });
238
- } else {
239
- parts.push({
240
- inlineData: {
241
- mimeType: mediaType,
242
- data: convertToBase64(part.data),
243
- },
244
- });
230
+ parts.push({
231
+ fileData: {
232
+ mimeType: resolveFullMediaType({ part }),
233
+ fileUri: resolveProviderReference({
234
+ reference: part.data.reference,
235
+ provider: 'google',
236
+ }),
237
+ },
238
+ });
239
+ break;
240
+ }
241
+ case 'text': {
242
+ parts.push({
243
+ inlineData: {
244
+ mimeType: isFullMediaType(part.mediaType)
245
+ ? part.mediaType
246
+ : 'text/plain',
247
+ data: convertToBase64(
248
+ new TextEncoder().encode(part.data.text),
249
+ ),
250
+ },
251
+ });
252
+ break;
253
+ }
254
+ case 'data': {
255
+ parts.push({
256
+ inlineData: {
257
+ mimeType: resolveFullMediaType({ part }),
258
+ data: convertToBase64(part.data.data),
259
+ },
260
+ });
261
+ break;
262
+ }
245
263
  }
246
264
 
247
265
  break;
@@ -291,63 +309,86 @@ export function convertToGoogleMessages(
291
309
  }
292
310
 
293
311
  case 'reasoning-file': {
294
- if (part.data instanceof URL) {
295
- throw new UnsupportedFunctionalityError({
296
- functionality:
297
- 'File data URLs in assistant messages are not supported',
298
- });
312
+ switch (part.data.type) {
313
+ case 'url': {
314
+ throw new UnsupportedFunctionalityError({
315
+ functionality:
316
+ 'File data URLs in assistant messages are not supported',
317
+ });
318
+ }
319
+ case 'data': {
320
+ return {
321
+ inlineData: {
322
+ mimeType: part.mediaType,
323
+ data: convertToBase64(part.data.data),
324
+ },
325
+ thought: true,
326
+ thoughtSignature,
327
+ };
328
+ }
299
329
  }
300
-
301
- return {
302
- inlineData: {
303
- mimeType: part.mediaType,
304
- data: convertToBase64(part.data),
305
- },
306
- thought: true,
307
- thoughtSignature,
308
- };
330
+ break;
309
331
  }
310
332
 
311
333
  case 'file': {
312
- if (part.data instanceof URL) {
313
- throw new UnsupportedFunctionalityError({
314
- functionality:
315
- 'File data URLs in assistant messages are not supported',
316
- });
317
- }
318
-
319
- if (isProviderReference(part.data)) {
320
- if (providerOptionsName === 'vertex') {
334
+ switch (part.data.type) {
335
+ case 'url': {
321
336
  throw new UnsupportedFunctionalityError({
322
- functionality: 'file parts with provider references',
337
+ functionality:
338
+ 'File data URLs in assistant messages are not supported',
323
339
  });
324
340
  }
325
-
326
- return {
327
- fileData: {
328
- mimeType: part.mediaType,
329
- fileUri: resolveProviderReference({
330
- reference: part.data,
331
- provider: 'google',
332
- }),
333
- },
334
- ...(providerOpts?.thought === true
335
- ? { thought: true }
336
- : {}),
337
- thoughtSignature,
338
- };
341
+ case 'reference': {
342
+ if (providerOptionsName === 'vertex') {
343
+ throw new UnsupportedFunctionalityError({
344
+ functionality: 'file parts with provider references',
345
+ });
346
+ }
347
+
348
+ return {
349
+ fileData: {
350
+ mimeType: part.mediaType,
351
+ fileUri: resolveProviderReference({
352
+ reference: part.data.reference,
353
+ provider: 'google',
354
+ }),
355
+ },
356
+ ...(providerOpts?.thought === true
357
+ ? { thought: true }
358
+ : {}),
359
+ thoughtSignature,
360
+ };
361
+ }
362
+ case 'text': {
363
+ return {
364
+ inlineData: {
365
+ mimeType: isFullMediaType(part.mediaType)
366
+ ? part.mediaType
367
+ : 'text/plain',
368
+ data: convertToBase64(
369
+ new TextEncoder().encode(part.data.text),
370
+ ),
371
+ },
372
+ ...(providerOpts?.thought === true
373
+ ? { thought: true }
374
+ : {}),
375
+ thoughtSignature,
376
+ };
377
+ }
378
+ case 'data': {
379
+ return {
380
+ inlineData: {
381
+ mimeType: part.mediaType,
382
+ data: convertToBase64(part.data.data),
383
+ },
384
+ ...(providerOpts?.thought === true
385
+ ? { thought: true }
386
+ : {}),
387
+ thoughtSignature,
388
+ };
389
+ }
339
390
  }
340
-
341
- return {
342
- inlineData: {
343
- mimeType: part.mediaType,
344
- data: convertToBase64(part.data),
345
- },
346
- ...(providerOpts?.thought === true
347
- ? { thought: true }
348
- : {}),
349
- thoughtSignature,
350
- };
391
+ break;
351
392
  }
352
393
 
353
394
  case 'tool-call': {
@@ -1,11 +1,10 @@
1
1
  import {
2
- EmbeddingModelV4,
3
2
  TooManyEmbeddingValuesForCallError,
3
+ type EmbeddingModelV4,
4
4
  } from '@ai-sdk/provider';
5
5
  import {
6
6
  combineHeaders,
7
7
  createJsonResponseHandler,
8
- FetchFunction,
9
8
  lazySchema,
10
9
  parseProviderOptions,
11
10
  postJsonToApi,
@@ -14,14 +13,14 @@ import {
14
13
  WORKFLOW_SERIALIZE,
15
14
  WORKFLOW_DESERIALIZE,
16
15
  zodSchema,
16
+ type FetchFunction,
17
17
  } from '@ai-sdk/provider-utils';
18
18
  import { z } from 'zod/v4';
19
19
  import { googleFailedResponseHandler } from './google-error';
20
20
  import {
21
- GoogleEmbeddingModelId,
22
21
  googleEmbeddingModelOptions,
22
+ type GoogleEmbeddingModelId,
23
23
  } from './google-embedding-options';
24
-
25
24
  type GoogleEmbeddingConfig = {
26
25
  provider: string;
27
26
  baseURL: string;
@@ -1,7 +1,7 @@
1
1
  import {
2
- type InferSchema,
3
2
  lazySchema,
4
3
  zodSchema,
4
+ type InferSchema,
5
5
  } from '@ai-sdk/provider-utils';
6
6
  import { z } from 'zod/v4';
7
7
 
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createJsonErrorResponseHandler,
3
- type InferSchema,
4
3
  lazySchema,
5
4
  zodSchema,
5
+ type InferSchema,
6
6
  } from '@ai-sdk/provider-utils';
7
7
  import { z } from 'zod/v4';
8
8
 
@@ -7,13 +7,14 @@ import {
7
7
  } from '@ai-sdk/provider';
8
8
  import {
9
9
  combineHeaders,
10
+ convertInlineFileDataToUint8Array,
10
11
  createJsonResponseHandler,
11
12
  delay,
12
- type FetchFunction,
13
13
  lazySchema,
14
14
  parseProviderOptions,
15
15
  zodSchema,
16
16
  getFromApi,
17
+ type FetchFunction,
17
18
  } from '@ai-sdk/provider-utils';
18
19
  import { z } from 'zod/v4';
19
20
  import { googleFailedResponseHandler } from './google-error';
@@ -59,11 +60,7 @@ export class GoogleFiles implements FilesV4 {
59
60
  warnings.push({ type: 'unsupported', feature: 'filename' });
60
61
  }
61
62
 
62
- const data = options.data;
63
- const fileBytes =
64
- data instanceof Uint8Array
65
- ? data
66
- : Uint8Array.from(atob(data), c => c.charCodeAt(0));
63
+ const fileBytes = convertInlineFileDataToUint8Array(options.data);
67
64
 
68
65
  const mediaType = options.mediaType;
69
66
  const displayName = googleOptions?.displayName;
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  ImageModelV4,
3
3
  LanguageModelV4Prompt,
4
4
  SharedV4Warning,
@@ -7,22 +7,22 @@ import {
7
7
  combineHeaders,
8
8
  convertToBase64,
9
9
  createJsonResponseHandler,
10
- FetchFunction,
11
10
  generateId as defaultGenerateId,
12
- type InferSchema,
13
11
  lazySchema,
14
12
  parseProviderOptions,
15
13
  postJsonToApi,
16
- Resolvable,
17
14
  resolve,
18
15
  serializeModelOptions,
19
16
  WORKFLOW_SERIALIZE,
20
17
  WORKFLOW_DESERIALIZE,
21
18
  zodSchema,
19
+ type InferSchema,
20
+ type FetchFunction,
21
+ type Resolvable,
22
22
  } from '@ai-sdk/provider-utils';
23
23
  import { z } from 'zod/v4';
24
24
  import { googleFailedResponseHandler } from './google-error';
25
- import {
25
+ import type {
26
26
  GoogleImageModelId,
27
27
  GoogleImageSettings,
28
28
  } from './google-image-settings';
@@ -240,33 +240,39 @@ export class GoogleImageModel implements ImageModelV4 {
240
240
  });
241
241
  }
242
242
 
243
- // Build user message content for language model
244
243
  const userContent: Array<
245
244
  | { type: 'text'; text: string }
246
- | { type: 'file'; data: string | Uint8Array | URL; mediaType: string }
245
+ | {
246
+ type: 'file';
247
+ data:
248
+ | { type: 'data'; data: string | Uint8Array }
249
+ | { type: 'url'; url: URL };
250
+ mediaType: string;
251
+ }
247
252
  > = [];
248
253
 
249
- // Add text prompt
250
254
  if (prompt != null) {
251
255
  userContent.push({ type: 'text', text: prompt });
252
256
  }
253
257
 
254
- // Add input images for editing
255
258
  if (files != null && files.length > 0) {
256
259
  for (const file of files) {
257
260
  if (file.type === 'url') {
258
261
  userContent.push({
259
262
  type: 'file',
260
- data: new URL(file.url),
263
+ data: { type: 'url', url: new URL(file.url) },
261
264
  mediaType: 'image/*',
262
265
  });
263
266
  } else {
264
267
  userContent.push({
265
268
  type: 'file',
266
- data:
267
- typeof file.data === 'string'
268
- ? file.data
269
- : new Uint8Array(file.data),
269
+ data: {
270
+ type: 'data',
271
+ data:
272
+ typeof file.data === 'string'
273
+ ? file.data
274
+ : new Uint8Array(file.data),
275
+ },
270
276
  mediaType: file.mediaType,
271
277
  });
272
278
  }
@@ -312,11 +318,14 @@ export class GoogleImageModel implements ImageModelV4 {
312
318
 
313
319
  const currentDate = this.config._internal?.currentDate?.() ?? new Date();
314
320
 
315
- // Extract images from language model response
316
321
  const images: string[] = [];
317
322
  for (const part of result.content) {
318
- if (part.type === 'file' && part.mediaType.startsWith('image/')) {
319
- images.push(convertToBase64(part.data));
323
+ if (
324
+ part.type === 'file' &&
325
+ part.mediaType.startsWith('image/') &&
326
+ part.data.type === 'data'
327
+ ) {
328
+ images.push(convertToBase64(part.data.data));
320
329
  }
321
330
  }
322
331
 
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  LanguageModelV4,
3
3
  LanguageModelV4CallOptions,
4
4
  LanguageModelV4Content,
@@ -15,40 +15,43 @@ import {
15
15
  combineHeaders,
16
16
  createEventSourceResponseHandler,
17
17
  createJsonResponseHandler,
18
- FetchFunction,
19
18
  generateId,
20
- InferSchema,
21
19
  isCustomReasoning,
22
20
  lazySchema,
23
21
  mapReasoningToProviderBudget,
24
22
  mapReasoningToProviderEffort,
25
23
  parseProviderOptions,
26
- ParseResult,
27
24
  postJsonToApi,
28
- Resolvable,
29
25
  resolve,
30
26
  serializeModelOptions,
31
27
  WORKFLOW_SERIALIZE,
32
28
  WORKFLOW_DESERIALIZE,
33
29
  zodSchema,
30
+ type FetchFunction,
31
+ type InferSchema,
32
+ type ParseResult,
33
+ type Resolvable,
34
34
  } from '@ai-sdk/provider-utils';
35
35
  import { z } from 'zod/v4';
36
36
  import {
37
37
  convertGoogleUsage,
38
- GoogleUsageMetadata,
38
+ type GoogleUsageMetadata,
39
39
  } from './convert-google-usage';
40
40
  import { convertJSONSchemaToOpenAPISchema } from './convert-json-schema-to-openapi-schema';
41
41
  import { convertToGoogleMessages } from './convert-to-google-messages';
42
42
  import { getModelPath } from './get-model-path';
43
43
  import { googleFailedResponseHandler } from './google-error';
44
44
  import {
45
- GoogleModelId,
46
45
  googleLanguageModelOptions,
47
46
  VertexServiceTierMap,
47
+ type GoogleModelId,
48
48
  } from './google-options';
49
- import { GoogleProviderMetadata } from './google-prompt';
49
+ import type { GoogleProviderMetadata } from './google-prompt';
50
50
  import { prepareTools } from './google-prepare-tools';
51
- import { GoogleJSONAccumulator, PartialArg } from './google-json-accumulator';
51
+ import {
52
+ GoogleJSONAccumulator,
53
+ type PartialArg,
54
+ } from './google-json-accumulator';
52
55
  import { mapGoogleFinishReason } from './map-google-finish-reason';
53
56
 
54
57
  type GoogleConfig = {
@@ -388,7 +391,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
388
391
  const hasThoughtSignature = !!part.thoughtSignature;
389
392
  content.push({
390
393
  type: hasThought ? 'reasoning-file' : 'file',
391
- data: part.inlineData.data,
394
+ data: { type: 'data', data: part.inlineData.data },
392
395
  mediaType: part.inlineData.mimeType,
393
396
  providerMetadata: hasThoughtSignature
394
397
  ? {
@@ -754,7 +757,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
754
757
  controller.enqueue({
755
758
  type: hasThought ? 'reasoning-file' : 'file',
756
759
  mediaType: part.inlineData.mimeType,
757
- data: part.inlineData.data,
760
+ data: { type: 'data', data: part.inlineData.data },
758
761
  providerMetadata: fileMeta,
759
762
  });
760
763
  } else if ('toolCall' in part && part.toolCall) {
@@ -1,4 +1,8 @@
1
- import { InferSchema, lazySchema, zodSchema } from '@ai-sdk/provider-utils';
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ } from '@ai-sdk/provider-utils';
2
6
  import { z } from 'zod/v4';
3
7
 
4
8
  export type GoogleModelId =
@@ -1,10 +1,10 @@
1
1
  import {
2
- LanguageModelV4CallOptions,
3
- SharedV4Warning,
4
2
  UnsupportedFunctionalityError,
3
+ type LanguageModelV4CallOptions,
4
+ type SharedV4Warning,
5
5
  } from '@ai-sdk/provider';
6
6
  import { convertJSONSchemaToOpenAPISchema } from './convert-json-schema-to-openapi-schema';
7
- import { GoogleModelId } from './google-options';
7
+ import type { GoogleModelId } from './google-options';
8
8
 
9
9
  export function prepareTools({
10
10
  tools,
@@ -1,8 +1,8 @@
1
- import {
1
+ import type {
2
2
  GroundingMetadataSchema,
3
3
  PromptFeedbackSchema,
4
+ SafetyRatingSchema,
4
5
  UrlContextMetadataSchema,
5
- type SafetyRatingSchema,
6
6
  UsageMetadataSchema,
7
7
  } from './google-language-model';
8
8
 
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  EmbeddingModelV4,
3
3
  Experimental_VideoModelV4,
4
4
  FilesV4,
@@ -7,27 +7,27 @@ import {
7
7
  ProviderV4,
8
8
  } from '@ai-sdk/provider';
9
9
  import {
10
- FetchFunction,
11
10
  generateId,
12
11
  loadApiKey,
13
12
  withoutTrailingSlash,
14
13
  withUserAgentSuffix,
14
+ type FetchFunction,
15
15
  } from '@ai-sdk/provider-utils';
16
16
  import { VERSION } from './version';
17
17
  import { GoogleEmbeddingModel } from './google-embedding-model';
18
- import { GoogleEmbeddingModelId } from './google-embedding-options';
18
+ import type { GoogleEmbeddingModelId } from './google-embedding-options';
19
19
  import { GoogleLanguageModel } from './google-language-model';
20
- import { GoogleModelId } from './google-options';
20
+ import type { GoogleModelId } from './google-options';
21
21
  import { googleTools } from './google-tools';
22
22
 
23
- import {
23
+ import type {
24
24
  GoogleImageSettings,
25
25
  GoogleImageModelId,
26
26
  } from './google-image-settings';
27
27
  import { GoogleImageModel } from './google-image-model';
28
28
  import { GoogleFiles } from './google-files';
29
29
  import { GoogleVideoModel } from './google-video-model';
30
- import { GoogleVideoModelId } from './google-video-settings';
30
+ import type { GoogleVideoModelId } from './google-video-settings';
31
31
 
32
32
  export interface GoogleProvider extends ProviderV4 {
33
33
  (modelId: GoogleModelId): LanguageModelV4;
@@ -8,14 +8,14 @@ import {
8
8
  convertUint8ArrayToBase64,
9
9
  createJsonResponseHandler,
10
10
  delay,
11
- type FetchFunction,
12
11
  getFromApi,
13
12
  lazySchema,
14
13
  parseProviderOptions,
15
14
  postJsonToApi,
16
- type Resolvable,
17
15
  resolve,
18
16
  zodSchema,
17
+ type FetchFunction,
18
+ type Resolvable,
19
19
  } from '@ai-sdk/provider-utils';
20
20
  import { z } from 'zod/v4';
21
21
  import { googleFailedResponseHandler } from './google-error';
@@ -1,4 +1,4 @@
1
- import { LanguageModelV4FinishReason } from '@ai-sdk/provider';
1
+ import type { LanguageModelV4FinishReason } from '@ai-sdk/provider';
2
2
 
3
3
  export function mapGoogleFinishReason({
4
4
  finishReason,