@ai-sdk/google 4.0.101 → 4.0.102

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.
@@ -878,7 +878,7 @@ import { generateText } from 'ai';
878
878
  const { text, sources, providerMetadata } = await generateText({
879
879
  model: google('gemini-4-argon'),
880
880
  prompt: `Based on the document: https://ai.google.dev/gemini-api/docs/url-context.
881
- Answer this question: How many links we can consume in one request?`,
881
+ Answer this question: How many links can we consume in one request?`,
882
882
  tools: {
883
883
  url_context: google.tools.urlContext({}),
884
884
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google",
3
- "version": "4.0.101",
3
+ "version": "4.0.102",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@ai-sdk/provider": "4.0.31",
39
- "@ai-sdk/provider-utils": "5.0.64"
39
+ "@ai-sdk/provider-utils": "5.0.65"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@ai-sdk/test-server": "2.0.4",
@@ -78,35 +78,38 @@ function assertSupportedBatchRequests(
78
78
  }
79
79
  }
80
80
 
81
- const googleRpcStatusSchema = z.object({
82
- code: z.union([z.number(), z.string()]).nullish(),
83
- message: z.string().nullish(),
84
- status: z.string().nullish(),
85
- });
86
-
87
- const googleBatchStatsSchema = z.object({
88
- requestCount: z.union([z.string(), z.number()]).nullish(),
89
- successfulRequestCount: z.union([z.string(), z.number()]).nullish(),
90
- failedRequestCount: z.union([z.string(), z.number()]).nullish(),
91
- pendingRequestCount: z.union([z.string(), z.number()]).nullish(),
92
- });
93
-
94
- const googleBatchOutputSchema = z.object({
95
- responsesFile: z.string().nullish(),
96
- inlinedResponses: z
97
- .object({
98
- inlinedResponses: z.array(
99
- z.object({
100
- metadata: z.object({
101
- key: z.string(),
81
+ const googleRpcStatusSchema = () =>
82
+ z.object({
83
+ code: z.union([z.number(), z.string()]).nullish(),
84
+ message: z.string().nullish(),
85
+ status: z.string().nullish(),
86
+ });
87
+
88
+ const googleBatchStatsSchema = () =>
89
+ z.object({
90
+ requestCount: z.union([z.string(), z.number()]).nullish(),
91
+ successfulRequestCount: z.union([z.string(), z.number()]).nullish(),
92
+ failedRequestCount: z.union([z.string(), z.number()]).nullish(),
93
+ pendingRequestCount: z.union([z.string(), z.number()]).nullish(),
94
+ });
95
+
96
+ const googleBatchOutputSchema = () =>
97
+ z.object({
98
+ responsesFile: z.string().nullish(),
99
+ inlinedResponses: z
100
+ .object({
101
+ inlinedResponses: z.array(
102
+ z.object({
103
+ metadata: z.object({
104
+ key: z.string(),
105
+ }),
106
+ response: z.unknown().nullish(),
107
+ error: googleRpcStatusSchema().nullish(),
102
108
  }),
103
- response: z.unknown().nullish(),
104
- error: googleRpcStatusSchema.nullish(),
105
- }),
106
- ),
107
- })
108
- .nullish(),
109
- });
109
+ ),
110
+ })
111
+ .nullish(),
112
+ });
110
113
 
111
114
  const googleBatchOperationZodSchema = () =>
112
115
  z.object({
@@ -115,13 +118,13 @@ const googleBatchOperationZodSchema = () =>
115
118
  .object({
116
119
  state: z.string().nullish(),
117
120
  createTime: z.string().nullish(),
118
- batchStats: googleBatchStatsSchema.nullish(),
119
- output: googleBatchOutputSchema.nullish(),
121
+ batchStats: googleBatchStatsSchema().nullish(),
122
+ output: googleBatchOutputSchema().nullish(),
120
123
  })
121
124
  .nullish(),
122
125
  done: z.boolean().nullish(),
123
- error: googleRpcStatusSchema.nullish(),
124
- response: googleBatchOutputSchema.nullish(),
126
+ error: googleRpcStatusSchema().nullish(),
127
+ response: googleBatchOutputSchema().nullish(),
125
128
  });
126
129
 
127
130
  const googleBatchOperationSchema = lazySchema(() =>
@@ -159,7 +162,7 @@ const googleBatchResultLineSchema = lazySchema(() =>
159
162
  z.object({
160
163
  key: z.string(),
161
164
  response: z.unknown().nullish(),
162
- error: googleRpcStatusSchema.nullish(),
165
+ error: googleRpcStatusSchema().nullish(),
163
166
  }),
164
167
  ),
165
168
  );
@@ -872,7 +875,7 @@ function parseCount(value: string | number | null | undefined) {
872
875
  }
873
876
 
874
877
  function convertGoogleRpcError(
875
- error: InferSchema<typeof googleRpcStatusSchema>,
878
+ error: InferSchema<ReturnType<typeof googleRpcStatusSchema>>,
876
879
  fallbackMessage: string,
877
880
  ): BatchV4Error {
878
881
  return {
@@ -11,21 +11,22 @@ export type GoogleEmbeddingModelId =
11
11
  | 'gemini-embedding-2-preview'
12
12
  | (string & {});
13
13
 
14
- const googleEmbeddingContentPartSchema = z.union([
15
- z.object({ text: z.string() }),
16
- z.object({
17
- inlineData: z.object({
18
- mimeType: z.string(),
19
- data: z.string(),
14
+ const googleEmbeddingContentPartSchema = () =>
15
+ z.union([
16
+ z.object({ text: z.string() }),
17
+ z.object({
18
+ inlineData: z.object({
19
+ mimeType: z.string(),
20
+ data: z.string(),
21
+ }),
20
22
  }),
21
- }),
22
- z.object({
23
- fileData: z.object({
24
- fileUri: z.string(),
25
- mimeType: z.string(),
23
+ z.object({
24
+ fileData: z.object({
25
+ fileUri: z.string(),
26
+ mimeType: z.string(),
27
+ }),
26
28
  }),
27
- }),
28
- ]);
29
+ ]);
29
30
 
30
31
  export const googleEmbeddingModelOptions = lazySchema(() =>
31
32
  zodSchema(
@@ -71,7 +72,7 @@ export const googleEmbeddingModelOptions = lazySchema(() =>
71
72
  * the case of a single embedding, the array length must be 1.
72
73
  */
73
74
  content: z
74
- .array(z.array(googleEmbeddingContentPartSchema).min(1).nullable())
75
+ .array(z.array(googleEmbeddingContentPartSchema()).min(1).nullable())
75
76
  .optional(),
76
77
  }),
77
78
  ),
@@ -13,6 +13,7 @@ import {
13
13
  lazySchema,
14
14
  parseProviderOptions,
15
15
  zodSchema,
16
+ encodePathSegment,
16
17
  getFromApi,
17
18
  type FetchFunction,
18
19
  } from '@ai-sdk/provider-utils';
@@ -34,17 +35,6 @@ interface GoogleFilesConfig {
34
35
  fetch?: FetchFunction;
35
36
  }
36
37
 
37
- function encodePathSegment(value: string): string {
38
- const encodedValue = encodeURIComponent(value);
39
-
40
- // URL parsing normalizes both literal and percent-encoded dot segments.
41
- return encodedValue === '.'
42
- ? '%252E'
43
- : encodedValue === '..'
44
- ? '%252E%252E'
45
- : encodedValue;
46
- }
47
-
48
38
  export class GoogleFiles implements FilesV4 {
49
39
  readonly specificationVersion = 'v4';
50
40
 
@@ -18,7 +18,7 @@ export const googleImageModelOptionsSchema = lazySchema(() =>
18
18
  * dedicated escape hatch for grounding image generation the same way
19
19
  * `generateText` does.
20
20
  */
21
- googleSearch: googleSearchToolArgsBaseSchema.optional(),
21
+ googleSearch: googleSearchToolArgsBaseSchema().optional(),
22
22
  }),
23
23
  ),
24
24
  );
@@ -1889,14 +1889,15 @@ export const getGroundingMetadataSchema = () =>
1889
1889
  .nullish(),
1890
1890
  });
1891
1891
 
1892
- const partialArgSchema = z.object({
1893
- jsonPath: z.string(),
1894
- stringValue: z.string().nullish(),
1895
- numberValue: z.number().nullish(),
1896
- boolValue: z.boolean().nullish(),
1897
- nullValue: z.unknown().nullish(),
1898
- willContinue: z.boolean().nullish(),
1899
- });
1892
+ const partialArgSchema = () =>
1893
+ z.object({
1894
+ jsonPath: z.string(),
1895
+ stringValue: z.string().nullish(),
1896
+ numberValue: z.number().nullish(),
1897
+ boolValue: z.boolean().nullish(),
1898
+ nullValue: z.unknown().nullish(),
1899
+ willContinue: z.boolean().nullish(),
1900
+ });
1900
1901
 
1901
1902
  const getContentSchema = () =>
1902
1903
  z.object({
@@ -1909,7 +1910,7 @@ const getContentSchema = () =>
1909
1910
  id: z.string().nullish(),
1910
1911
  name: z.string().nullish(),
1911
1912
  args: z.unknown().nullish(),
1912
- partialArgs: z.array(partialArgSchema).nullish(),
1913
+ partialArgs: z.array(partialArgSchema()).nullish(),
1913
1914
  willContinue: z.boolean().nullish(),
1914
1915
  }),
1915
1916
  thoughtSignature: z.string().nullish(),
@@ -1971,35 +1972,37 @@ const getSafetyRatingSchema = () =>
1971
1972
  blocked: z.boolean().nullish(),
1972
1973
  });
1973
1974
 
1974
- const tokenDetailsSchema = z
1975
- .array(
1976
- z
1977
- .object({
1978
- modality: z.string(),
1979
- tokenCount: z.number(),
1980
- })
1981
- .loose(),
1982
- )
1983
- .nullish();
1984
-
1985
- const usageSchema = z
1986
- .object({
1987
- cachedContentTokenCount: z.number().nullish(),
1988
- thoughtsTokenCount: z.number().nullish(),
1989
- promptTokenCount: z.number().nullish(),
1990
- candidatesTokenCount: z.number().nullish(),
1991
- toolUsePromptTokenCount: z.number().nullish(),
1992
- totalTokenCount: z.number().nullish(),
1993
- // https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
1994
- trafficType: z.string().nullish(),
1995
- serviceTier: z.string().nullish(),
1996
- // https://ai.google.dev/api/generate-content#Modality
1997
- promptTokensDetails: tokenDetailsSchema,
1998
- cacheTokensDetails: tokenDetailsSchema,
1999
- candidatesTokensDetails: tokenDetailsSchema,
2000
- toolUsePromptTokensDetails: tokenDetailsSchema,
2001
- })
2002
- .loose();
1975
+ const tokenDetailsSchema = () =>
1976
+ z
1977
+ .array(
1978
+ z
1979
+ .object({
1980
+ modality: z.string(),
1981
+ tokenCount: z.number(),
1982
+ })
1983
+ .loose(),
1984
+ )
1985
+ .nullish();
1986
+
1987
+ const usageSchema = () =>
1988
+ z
1989
+ .object({
1990
+ cachedContentTokenCount: z.number().nullish(),
1991
+ thoughtsTokenCount: z.number().nullish(),
1992
+ promptTokenCount: z.number().nullish(),
1993
+ candidatesTokenCount: z.number().nullish(),
1994
+ toolUsePromptTokenCount: z.number().nullish(),
1995
+ totalTokenCount: z.number().nullish(),
1996
+ // https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
1997
+ trafficType: z.string().nullish(),
1998
+ serviceTier: z.string().nullish(),
1999
+ // https://ai.google.dev/api/generate-content#Modality
2000
+ promptTokensDetails: tokenDetailsSchema(),
2001
+ cacheTokensDetails: tokenDetailsSchema(),
2002
+ candidatesTokensDetails: tokenDetailsSchema(),
2003
+ toolUsePromptTokensDetails: tokenDetailsSchema(),
2004
+ })
2005
+ .loose();
2003
2006
 
2004
2007
  // https://ai.google.dev/api/generate-content#UrlRetrievalMetadata
2005
2008
  export const getUrlContextMetadataSchema = () =>
@@ -2031,7 +2034,7 @@ export const responseSchema = lazySchema(() =>
2031
2034
  }),
2032
2035
  )
2033
2036
  .nullish(),
2034
- usageMetadata: usageSchema.nullish(),
2037
+ usageMetadata: usageSchema().nullish(),
2035
2038
  promptFeedback: z
2036
2039
  .object({
2037
2040
  blockReason: z.string().nullish(),
@@ -2086,7 +2089,7 @@ const chunkSchema = lazySchema(() =>
2086
2089
  }),
2087
2090
  )
2088
2091
  .nullish(),
2089
- usageMetadata: usageSchema.nullish(),
2092
+ usageMetadata: usageSchema().nullish(),
2090
2093
  promptFeedback: z
2091
2094
  .object({
2092
2095
  blockReason: z.string().nullish(),
@@ -13,25 +13,28 @@ export type GoogleSpeechModelId =
13
13
  | 'gemini-3.8-flash-lite-tts'
14
14
  | (string & {});
15
15
 
16
- const prebuiltVoiceConfigSchema = z.object({
17
- voiceName: z.string(),
18
- });
16
+ const prebuiltVoiceConfigSchema = () =>
17
+ z.object({
18
+ voiceName: z.string(),
19
+ });
19
20
 
20
- const voiceConfigSchema = z.object({
21
- prebuiltVoiceConfig: prebuiltVoiceConfigSchema,
22
- voice: z.never().optional(),
23
- });
21
+ const voiceConfigSchema = () =>
22
+ z.object({
23
+ prebuiltVoiceConfig: prebuiltVoiceConfigSchema(),
24
+ voice: z.never().optional(),
25
+ });
24
26
 
25
- const speechMetadataSchema = z.object({
26
- speaker: z.string().min(1).optional(),
27
- style: z.string().optional(),
28
- });
27
+ const speechMetadataSchema = () =>
28
+ z.object({
29
+ speaker: z.string().min(1).optional(),
30
+ style: z.string().optional(),
31
+ });
29
32
 
30
33
  export const googleSpeechProviderOptionsSchema = lazySchema(() =>
31
34
  zodSchema(
32
35
  z.object({
33
36
  /** Turn-level directions for the top-level text, for Gemini 3.8 TTS. */
34
- speechMetadata: speechMetadataSchema.optional(),
37
+ speechMetadata: speechMetadataSchema().optional(),
35
38
 
36
39
  /**
37
40
  * Structured transcript for Gemini 3.8 TTS. Replaces the top-level text;
@@ -42,7 +45,7 @@ export const googleSpeechProviderOptionsSchema = lazySchema(() =>
42
45
  .array(
43
46
  z.object({
44
47
  text: z.string(),
45
- speechMetadata: speechMetadataSchema.optional(),
48
+ speechMetadata: speechMetadataSchema().optional(),
46
49
  }),
47
50
  )
48
51
  .min(1)
@@ -61,7 +64,7 @@ export const googleSpeechProviderOptionsSchema = lazySchema(() =>
61
64
  speakerVoiceConfigs: z.array(
62
65
  z.object({
63
66
  speaker: z.string(),
64
- voiceConfig: voiceConfigSchema,
67
+ voiceConfig: voiceConfigSchema(),
65
68
  }),
66
69
  ),
67
70
  })
@@ -9,6 +9,9 @@ import {
9
9
  type SharedV4Warning,
10
10
  } from '@ai-sdk/provider';
11
11
  import {
12
+ lazySchema,
13
+ zodSchema,
14
+ type InferSchema,
12
15
  combineHeaders,
13
16
  convertUint8ArrayToBase64,
14
17
  createJsonResponseHandler,
@@ -265,7 +268,7 @@ export class GoogleVideoModel implements VideoModelV4 {
265
268
  }
266
269
 
267
270
  private async buildCompletedResult(
268
- finalOperation: z.infer<typeof googleOperationSchema>,
271
+ finalOperation: InferSchema<typeof googleOperationSchema>,
269
272
  responseHeaders: Record<string, string> | undefined,
270
273
  warnings: SharedV4Warning[],
271
274
  currentDate: Date,
@@ -441,33 +444,37 @@ export class GoogleVideoModel implements VideoModelV4 {
441
444
  }
442
445
  }
443
446
 
444
- const googleOperationSchema = z.object({
445
- name: z.string().nullish(),
446
- done: z.boolean().nullish(),
447
- error: z
448
- .object({
449
- code: z.number().nullish(),
450
- message: z.string(),
451
- status: z.string().nullish(),
452
- })
453
- .nullish(),
454
- response: z
455
- .object({
456
- generateVideoResponse: z
447
+ const googleOperationSchema = lazySchema(() =>
448
+ zodSchema(
449
+ z.object({
450
+ name: z.string().nullish(),
451
+ done: z.boolean().nullish(),
452
+ error: z
457
453
  .object({
458
- generatedSamples: z
459
- .array(
460
- z.object({
461
- video: z
462
- .object({
463
- uri: z.string().nullish(),
464
- })
465
- .nullish(),
466
- }),
467
- )
454
+ code: z.number().nullish(),
455
+ message: z.string(),
456
+ status: z.string().nullish(),
457
+ })
458
+ .nullish(),
459
+ response: z
460
+ .object({
461
+ generateVideoResponse: z
462
+ .object({
463
+ generatedSamples: z
464
+ .array(
465
+ z.object({
466
+ video: z
467
+ .object({
468
+ uri: z.string().nullish(),
469
+ })
470
+ .nullish(),
471
+ }),
472
+ )
473
+ .nullish(),
474
+ })
468
475
  .nullish(),
469
476
  })
470
477
  .nullish(),
471
- })
472
- .nullish(),
473
- });
478
+ }),
479
+ ),
480
+ );
@@ -1,4 +1,5 @@
1
1
  import {
2
+ type InferSchema,
2
3
  createProviderExecutedToolFactory,
3
4
  lazySchema,
4
5
  zodSchema,
@@ -6,35 +7,41 @@ import {
6
7
  import { z } from 'zod/v4';
7
8
 
8
9
  /** Tool to retrieve knowledge from the File Search Stores. */
9
- const fileSearchArgsBaseSchema = z.looseObject({
10
- /** The names of the file_search_stores to retrieve from.
11
- * Example: `fileSearchStores/my-file-search-store-123`
12
- */
13
- fileSearchStoreNames: z
14
- .array(z.string())
15
- .describe(
16
- 'The names of the file_search_stores to retrieve from. Example: `fileSearchStores/my-file-search-store-123`',
17
- ),
18
- /** The number of file search retrieval chunks to retrieve. */
19
- topK: z
20
- .number()
21
- .int()
22
- .positive()
23
- .describe('The number of file search retrieval chunks to retrieve.')
24
- .optional(),
10
+ const fileSearchArgsBaseSchema = lazySchema(() =>
11
+ zodSchema(
12
+ z.looseObject({
13
+ /** The names of the file_search_stores to retrieve from.
14
+ * Example: `fileSearchStores/my-file-search-store-123`
15
+ */
16
+ fileSearchStoreNames: z
17
+ .array(z.string())
18
+ .describe(
19
+ 'The names of the file_search_stores to retrieve from. Example: `fileSearchStores/my-file-search-store-123`',
20
+ ),
21
+ /** The number of file search retrieval chunks to retrieve. */
22
+ topK: z
23
+ .number()
24
+ .int()
25
+ .positive()
26
+ .describe('The number of file search retrieval chunks to retrieve.')
27
+ .optional(),
25
28
 
26
- /** Metadata filter to apply to the file search retrieval documents.
27
- * See https://google.aip.dev/160 for the syntax of the filter expression.
28
- */
29
- metadataFilter: z
30
- .string()
31
- .describe(
32
- 'Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression.',
33
- )
34
- .optional(),
35
- });
29
+ /** Metadata filter to apply to the file search retrieval documents.
30
+ * See https://google.aip.dev/160 for the syntax of the filter expression.
31
+ */
32
+ metadataFilter: z
33
+ .string()
34
+ .describe(
35
+ 'Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression.',
36
+ )
37
+ .optional(),
38
+ }),
39
+ ),
40
+ );
36
41
 
37
- export type GoogleFileSearchToolArgs = z.infer<typeof fileSearchArgsBaseSchema>;
42
+ export type GoogleFileSearchToolArgs = InferSchema<
43
+ typeof fileSearchArgsBaseSchema
44
+ >;
38
45
 
39
46
  export const fileSearch = createProviderExecutedToolFactory<
40
47
  {},
@@ -9,24 +9,25 @@ import { z } from 'zod/v4';
9
9
  // https://ai.google.dev/api/generate-content#GroundingSupport
10
10
  // https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-search
11
11
 
12
- export const googleSearchToolArgsBaseSchema = z.looseObject({
13
- searchTypes: z
14
- .object({
15
- webSearch: z.object({}).optional(),
16
- imageSearch: z.object({}).optional(),
17
- })
18
- .optional(),
12
+ export const googleSearchToolArgsBaseSchema = () =>
13
+ z.looseObject({
14
+ searchTypes: z
15
+ .object({
16
+ webSearch: z.object({}).optional(),
17
+ imageSearch: z.object({}).optional(),
18
+ })
19
+ .optional(),
19
20
 
20
- timeRangeFilter: z
21
- .object({
22
- startTime: z.string(),
23
- endTime: z.string(),
24
- })
25
- .optional(),
26
- });
21
+ timeRangeFilter: z
22
+ .object({
23
+ startTime: z.string(),
24
+ endTime: z.string(),
25
+ })
26
+ .optional(),
27
+ });
27
28
 
28
29
  export type GoogleSearchToolArgs = z.infer<
29
- typeof googleSearchToolArgsBaseSchema
30
+ ReturnType<typeof googleSearchToolArgsBaseSchema>
30
31
  >;
31
32
 
32
33
  export const googleSearch = createProviderExecutedToolFactory<