@ai-sdk/google 2.0.18 → 2.0.20

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.
@@ -4,11 +4,13 @@ import {
4
4
  createEventSourceResponseHandler,
5
5
  createJsonResponseHandler,
6
6
  generateId,
7
+ lazySchema as lazySchema3,
7
8
  parseProviderOptions,
8
9
  postJsonToApi,
9
- resolve
10
+ resolve,
11
+ zodSchema as zodSchema3
10
12
  } from "@ai-sdk/provider-utils";
11
- import * as z5 from "zod/v4";
13
+ import { z as z3 } from "zod/v4";
12
14
 
13
15
  // src/convert-json-schema-to-openapi-schema.ts
14
16
  function convertJSONSchemaToOpenAPISchema(jsonSchema) {
@@ -282,56 +284,80 @@ function getModelPath(modelId) {
282
284
  }
283
285
 
284
286
  // src/google-error.ts
285
- import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
286
- import * as z from "zod/v4";
287
- var googleErrorDataSchema = z.object({
288
- error: z.object({
289
- code: z.number().nullable(),
290
- message: z.string(),
291
- status: z.string()
292
- })
293
- });
287
+ import {
288
+ createJsonErrorResponseHandler,
289
+ lazySchema,
290
+ zodSchema
291
+ } from "@ai-sdk/provider-utils";
292
+ import { z } from "zod/v4";
293
+ var googleErrorDataSchema = lazySchema(
294
+ () => zodSchema(
295
+ z.object({
296
+ error: z.object({
297
+ code: z.number().nullable(),
298
+ message: z.string(),
299
+ status: z.string()
300
+ })
301
+ })
302
+ )
303
+ );
294
304
  var googleFailedResponseHandler = createJsonErrorResponseHandler({
295
305
  errorSchema: googleErrorDataSchema,
296
306
  errorToMessage: (data) => data.error.message
297
307
  });
298
308
 
299
309
  // src/google-generative-ai-options.ts
300
- import * as z2 from "zod/v4";
301
- var googleGenerativeAIProviderOptions = z2.object({
302
- responseModalities: z2.array(z2.enum(["TEXT", "IMAGE"])).optional(),
303
- thinkingConfig: z2.object({
304
- thinkingBudget: z2.number().optional(),
305
- includeThoughts: z2.boolean().optional()
306
- }).optional(),
307
- /**
308
- Optional.
309
- The name of the cached content used as context to serve the prediction.
310
- Format: cachedContents/{cachedContent}
311
- */
312
- cachedContent: z2.string().optional(),
313
- /**
314
- * Optional. Enable structured output. Default is true.
315
- *
316
- * This is useful when the JSON Schema contains elements that are
317
- * not supported by the OpenAPI schema version that
318
- * Google Generative AI uses. You can use this to disable
319
- * structured outputs if you need to.
320
- */
321
- structuredOutputs: z2.boolean().optional(),
322
- /**
323
- Optional. A list of unique safety settings for blocking unsafe content.
324
- */
325
- safetySettings: z2.array(
310
+ import {
311
+ lazySchema as lazySchema2,
312
+ zodSchema as zodSchema2
313
+ } from "@ai-sdk/provider-utils";
314
+ import { z as z2 } from "zod/v4";
315
+ var googleGenerativeAIProviderOptions = lazySchema2(
316
+ () => zodSchema2(
326
317
  z2.object({
327
- category: z2.enum([
328
- "HARM_CATEGORY_UNSPECIFIED",
329
- "HARM_CATEGORY_HATE_SPEECH",
330
- "HARM_CATEGORY_DANGEROUS_CONTENT",
331
- "HARM_CATEGORY_HARASSMENT",
332
- "HARM_CATEGORY_SEXUALLY_EXPLICIT",
333
- "HARM_CATEGORY_CIVIC_INTEGRITY"
334
- ]),
318
+ responseModalities: z2.array(z2.enum(["TEXT", "IMAGE"])).optional(),
319
+ thinkingConfig: z2.object({
320
+ thinkingBudget: z2.number().optional(),
321
+ includeThoughts: z2.boolean().optional()
322
+ }).optional(),
323
+ /**
324
+ * Optional.
325
+ * The name of the cached content used as context to serve the prediction.
326
+ * Format: cachedContents/{cachedContent}
327
+ */
328
+ cachedContent: z2.string().optional(),
329
+ /**
330
+ * Optional. Enable structured output. Default is true.
331
+ *
332
+ * This is useful when the JSON Schema contains elements that are
333
+ * not supported by the OpenAPI schema version that
334
+ * Google Generative AI uses. You can use this to disable
335
+ * structured outputs if you need to.
336
+ */
337
+ structuredOutputs: z2.boolean().optional(),
338
+ /**
339
+ * Optional. A list of unique safety settings for blocking unsafe content.
340
+ */
341
+ safetySettings: z2.array(
342
+ z2.object({
343
+ category: z2.enum([
344
+ "HARM_CATEGORY_UNSPECIFIED",
345
+ "HARM_CATEGORY_HATE_SPEECH",
346
+ "HARM_CATEGORY_DANGEROUS_CONTENT",
347
+ "HARM_CATEGORY_HARASSMENT",
348
+ "HARM_CATEGORY_SEXUALLY_EXPLICIT",
349
+ "HARM_CATEGORY_CIVIC_INTEGRITY"
350
+ ]),
351
+ threshold: z2.enum([
352
+ "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
353
+ "BLOCK_LOW_AND_ABOVE",
354
+ "BLOCK_MEDIUM_AND_ABOVE",
355
+ "BLOCK_ONLY_HIGH",
356
+ "BLOCK_NONE",
357
+ "OFF"
358
+ ])
359
+ })
360
+ ).optional(),
335
361
  threshold: z2.enum([
336
362
  "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
337
363
  "BLOCK_LOW_AND_ABOVE",
@@ -339,30 +365,33 @@ var googleGenerativeAIProviderOptions = z2.object({
339
365
  "BLOCK_ONLY_HIGH",
340
366
  "BLOCK_NONE",
341
367
  "OFF"
342
- ])
368
+ ]).optional(),
369
+ /**
370
+ * Optional. Enables timestamp understanding for audio-only files.
371
+ *
372
+ * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
373
+ */
374
+ audioTimestamp: z2.boolean().optional(),
375
+ /**
376
+ * Optional. Defines labels used in billing reports. Available on Vertex AI only.
377
+ *
378
+ * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
379
+ */
380
+ labels: z2.record(z2.string(), z2.string()).optional(),
381
+ /**
382
+ * Optional. If specified, the media resolution specified will be used.
383
+ *
384
+ * https://ai.google.dev/api/generate-content#MediaResolution
385
+ */
386
+ mediaResolution: z2.enum([
387
+ "MEDIA_RESOLUTION_UNSPECIFIED",
388
+ "MEDIA_RESOLUTION_LOW",
389
+ "MEDIA_RESOLUTION_MEDIUM",
390
+ "MEDIA_RESOLUTION_HIGH"
391
+ ]).optional()
343
392
  })
344
- ).optional(),
345
- threshold: z2.enum([
346
- "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
347
- "BLOCK_LOW_AND_ABOVE",
348
- "BLOCK_MEDIUM_AND_ABOVE",
349
- "BLOCK_ONLY_HIGH",
350
- "BLOCK_NONE",
351
- "OFF"
352
- ]).optional(),
353
- /**
354
- * Optional. Enables timestamp understanding for audio-only files.
355
- *
356
- * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
357
- */
358
- audioTimestamp: z2.boolean().optional(),
359
- /**
360
- * Optional. Defines labels used in billing reports. Available on Vertex AI only.
361
- *
362
- * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
363
- */
364
- labels: z2.record(z2.string(), z2.string()).optional()
365
- });
393
+ )
394
+ );
366
395
 
367
396
  // src/google-prepare-tools.ts
368
397
  import {
@@ -535,64 +564,6 @@ function mapGoogleGenerativeAIFinishReason({
535
564
  }
536
565
  }
537
566
 
538
- // src/tool/google-search.ts
539
- import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils";
540
- import * as z3 from "zod/v4";
541
- var groundingChunkSchema = z3.object({
542
- web: z3.object({ uri: z3.string(), title: z3.string() }).nullish(),
543
- retrievedContext: z3.object({ uri: z3.string(), title: z3.string() }).nullish()
544
- });
545
- var groundingMetadataSchema = z3.object({
546
- webSearchQueries: z3.array(z3.string()).nullish(),
547
- retrievalQueries: z3.array(z3.string()).nullish(),
548
- searchEntryPoint: z3.object({ renderedContent: z3.string() }).nullish(),
549
- groundingChunks: z3.array(groundingChunkSchema).nullish(),
550
- groundingSupports: z3.array(
551
- z3.object({
552
- segment: z3.object({
553
- startIndex: z3.number().nullish(),
554
- endIndex: z3.number().nullish(),
555
- text: z3.string().nullish()
556
- }),
557
- segment_text: z3.string().nullish(),
558
- groundingChunkIndices: z3.array(z3.number()).nullish(),
559
- supportChunkIndices: z3.array(z3.number()).nullish(),
560
- confidenceScores: z3.array(z3.number()).nullish(),
561
- confidenceScore: z3.array(z3.number()).nullish()
562
- })
563
- ).nullish(),
564
- retrievalMetadata: z3.union([
565
- z3.object({
566
- webDynamicRetrievalScore: z3.number()
567
- }),
568
- z3.object({})
569
- ]).nullish()
570
- });
571
- var googleSearch = createProviderDefinedToolFactory({
572
- id: "google.google_search",
573
- name: "google_search",
574
- inputSchema: z3.object({
575
- mode: z3.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
576
- dynamicThreshold: z3.number().default(1)
577
- })
578
- });
579
-
580
- // src/tool/url-context.ts
581
- import { createProviderDefinedToolFactory as createProviderDefinedToolFactory2 } from "@ai-sdk/provider-utils";
582
- import * as z4 from "zod/v4";
583
- var urlMetadataSchema = z4.object({
584
- retrievedUrl: z4.string(),
585
- urlRetrievalStatus: z4.string()
586
- });
587
- var urlContextMetadataSchema = z4.object({
588
- urlMetadata: z4.array(urlMetadataSchema)
589
- });
590
- var urlContext = createProviderDefinedToolFactory2({
591
- id: "google.url_context",
592
- name: "url_context",
593
- inputSchema: z4.object({})
594
- });
595
-
596
567
  // src/google-generative-ai-language-model.ts
597
568
  var GoogleGenerativeAILanguageModel = class {
598
569
  constructor(modelId, config) {
@@ -1085,103 +1056,183 @@ function extractSources({
1085
1056
  title: chunk.web.title
1086
1057
  }));
1087
1058
  }
1088
- var contentSchema = z5.object({
1089
- parts: z5.array(
1090
- z5.union([
1059
+ var getGroundingMetadataSchema = () => z3.object({
1060
+ webSearchQueries: z3.array(z3.string()).nullish(),
1061
+ retrievalQueries: z3.array(z3.string()).nullish(),
1062
+ searchEntryPoint: z3.object({ renderedContent: z3.string() }).nullish(),
1063
+ groundingChunks: z3.array(
1064
+ z3.object({
1065
+ web: z3.object({ uri: z3.string(), title: z3.string() }).nullish(),
1066
+ retrievedContext: z3.object({ uri: z3.string(), title: z3.string() }).nullish()
1067
+ })
1068
+ ).nullish(),
1069
+ groundingSupports: z3.array(
1070
+ z3.object({
1071
+ segment: z3.object({
1072
+ startIndex: z3.number().nullish(),
1073
+ endIndex: z3.number().nullish(),
1074
+ text: z3.string().nullish()
1075
+ }),
1076
+ segment_text: z3.string().nullish(),
1077
+ groundingChunkIndices: z3.array(z3.number()).nullish(),
1078
+ supportChunkIndices: z3.array(z3.number()).nullish(),
1079
+ confidenceScores: z3.array(z3.number()).nullish(),
1080
+ confidenceScore: z3.array(z3.number()).nullish()
1081
+ })
1082
+ ).nullish(),
1083
+ retrievalMetadata: z3.union([
1084
+ z3.object({
1085
+ webDynamicRetrievalScore: z3.number()
1086
+ }),
1087
+ z3.object({})
1088
+ ]).nullish()
1089
+ });
1090
+ var getContentSchema = () => z3.object({
1091
+ parts: z3.array(
1092
+ z3.union([
1091
1093
  // note: order matters since text can be fully empty
1092
- z5.object({
1093
- functionCall: z5.object({
1094
- name: z5.string(),
1095
- args: z5.unknown()
1094
+ z3.object({
1095
+ functionCall: z3.object({
1096
+ name: z3.string(),
1097
+ args: z3.unknown()
1096
1098
  }),
1097
- thoughtSignature: z5.string().nullish()
1099
+ thoughtSignature: z3.string().nullish()
1098
1100
  }),
1099
- z5.object({
1100
- inlineData: z5.object({
1101
- mimeType: z5.string(),
1102
- data: z5.string()
1101
+ z3.object({
1102
+ inlineData: z3.object({
1103
+ mimeType: z3.string(),
1104
+ data: z3.string()
1103
1105
  })
1104
1106
  }),
1105
- z5.object({
1106
- executableCode: z5.object({
1107
- language: z5.string(),
1108
- code: z5.string()
1107
+ z3.object({
1108
+ executableCode: z3.object({
1109
+ language: z3.string(),
1110
+ code: z3.string()
1109
1111
  }).nullish(),
1110
- codeExecutionResult: z5.object({
1111
- outcome: z5.string(),
1112
- output: z5.string()
1112
+ codeExecutionResult: z3.object({
1113
+ outcome: z3.string(),
1114
+ output: z3.string()
1113
1115
  }).nullish(),
1114
- text: z5.string().nullish(),
1115
- thought: z5.boolean().nullish(),
1116
- thoughtSignature: z5.string().nullish()
1116
+ text: z3.string().nullish(),
1117
+ thought: z3.boolean().nullish(),
1118
+ thoughtSignature: z3.string().nullish()
1117
1119
  })
1118
1120
  ])
1119
1121
  ).nullish()
1120
1122
  });
1121
- var safetyRatingSchema = z5.object({
1122
- category: z5.string().nullish(),
1123
- probability: z5.string().nullish(),
1124
- probabilityScore: z5.number().nullish(),
1125
- severity: z5.string().nullish(),
1126
- severityScore: z5.number().nullish(),
1127
- blocked: z5.boolean().nullish()
1123
+ var getSafetyRatingSchema = () => z3.object({
1124
+ category: z3.string().nullish(),
1125
+ probability: z3.string().nullish(),
1126
+ probabilityScore: z3.number().nullish(),
1127
+ severity: z3.string().nullish(),
1128
+ severityScore: z3.number().nullish(),
1129
+ blocked: z3.boolean().nullish()
1128
1130
  });
1129
- var usageSchema = z5.object({
1130
- cachedContentTokenCount: z5.number().nullish(),
1131
- thoughtsTokenCount: z5.number().nullish(),
1132
- promptTokenCount: z5.number().nullish(),
1133
- candidatesTokenCount: z5.number().nullish(),
1134
- totalTokenCount: z5.number().nullish()
1131
+ var usageSchema = z3.object({
1132
+ cachedContentTokenCount: z3.number().nullish(),
1133
+ thoughtsTokenCount: z3.number().nullish(),
1134
+ promptTokenCount: z3.number().nullish(),
1135
+ candidatesTokenCount: z3.number().nullish(),
1136
+ totalTokenCount: z3.number().nullish()
1135
1137
  });
1136
- var responseSchema = z5.object({
1137
- candidates: z5.array(
1138
- z5.object({
1139
- content: contentSchema.nullish().or(z5.object({}).strict()),
1140
- finishReason: z5.string().nullish(),
1141
- safetyRatings: z5.array(safetyRatingSchema).nullish(),
1142
- groundingMetadata: groundingMetadataSchema.nullish(),
1143
- urlContextMetadata: urlContextMetadataSchema.nullish()
1138
+ var getUrlContextMetadataSchema = () => z3.object({
1139
+ urlMetadata: z3.array(
1140
+ z3.object({
1141
+ retrievedUrl: z3.string(),
1142
+ urlRetrievalStatus: z3.string()
1144
1143
  })
1145
- ),
1146
- usageMetadata: usageSchema.nullish(),
1147
- promptFeedback: z5.object({
1148
- blockReason: z5.string().nullish(),
1149
- safetyRatings: z5.array(safetyRatingSchema).nullish()
1150
- }).nullish()
1144
+ )
1151
1145
  });
1152
- var chunkSchema = z5.object({
1153
- candidates: z5.array(
1154
- z5.object({
1155
- content: contentSchema.nullish(),
1156
- finishReason: z5.string().nullish(),
1157
- safetyRatings: z5.array(safetyRatingSchema).nullish(),
1158
- groundingMetadata: groundingMetadataSchema.nullish(),
1159
- urlContextMetadata: urlContextMetadataSchema.nullish()
1146
+ var responseSchema = lazySchema3(
1147
+ () => zodSchema3(
1148
+ z3.object({
1149
+ candidates: z3.array(
1150
+ z3.object({
1151
+ content: getContentSchema().nullish().or(z3.object({}).strict()),
1152
+ finishReason: z3.string().nullish(),
1153
+ safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
1154
+ groundingMetadata: getGroundingMetadataSchema().nullish(),
1155
+ urlContextMetadata: getUrlContextMetadataSchema().nullish()
1156
+ })
1157
+ ),
1158
+ usageMetadata: usageSchema.nullish(),
1159
+ promptFeedback: z3.object({
1160
+ blockReason: z3.string().nullish(),
1161
+ safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
1162
+ }).nullish()
1160
1163
  })
1161
- ).nullish(),
1162
- usageMetadata: usageSchema.nullish(),
1163
- promptFeedback: z5.object({
1164
- blockReason: z5.string().nullish(),
1165
- safetyRatings: z5.array(safetyRatingSchema).nullish()
1166
- }).nullish()
1167
- });
1164
+ )
1165
+ );
1166
+ var chunkSchema = lazySchema3(
1167
+ () => zodSchema3(
1168
+ z3.object({
1169
+ candidates: z3.array(
1170
+ z3.object({
1171
+ content: getContentSchema().nullish(),
1172
+ finishReason: z3.string().nullish(),
1173
+ safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
1174
+ groundingMetadata: getGroundingMetadataSchema().nullish(),
1175
+ urlContextMetadata: getUrlContextMetadataSchema().nullish()
1176
+ })
1177
+ ).nullish(),
1178
+ usageMetadata: usageSchema.nullish(),
1179
+ promptFeedback: z3.object({
1180
+ blockReason: z3.string().nullish(),
1181
+ safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
1182
+ }).nullish()
1183
+ })
1184
+ )
1185
+ );
1168
1186
 
1169
1187
  // src/tool/code-execution.ts
1170
1188
  import { createProviderDefinedToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils";
1171
- import * as z6 from "zod/v4";
1189
+ import { z as z4 } from "zod/v4";
1172
1190
  var codeExecution = createProviderDefinedToolFactoryWithOutputSchema({
1173
1191
  id: "google.code_execution",
1174
1192
  name: "code_execution",
1175
- inputSchema: z6.object({
1176
- language: z6.string().describe("The programming language of the code."),
1177
- code: z6.string().describe("The code to be executed.")
1193
+ inputSchema: z4.object({
1194
+ language: z4.string().describe("The programming language of the code."),
1195
+ code: z4.string().describe("The code to be executed.")
1178
1196
  }),
1179
- outputSchema: z6.object({
1180
- outcome: z6.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
1181
- output: z6.string().describe("The output from the code execution.")
1197
+ outputSchema: z4.object({
1198
+ outcome: z4.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
1199
+ output: z4.string().describe("The output from the code execution.")
1182
1200
  })
1183
1201
  });
1184
1202
 
1203
+ // src/tool/google-search.ts
1204
+ import {
1205
+ createProviderDefinedToolFactory,
1206
+ lazySchema as lazySchema4,
1207
+ zodSchema as zodSchema4
1208
+ } from "@ai-sdk/provider-utils";
1209
+ import { z as z5 } from "zod/v4";
1210
+ var googleSearch = createProviderDefinedToolFactory({
1211
+ id: "google.google_search",
1212
+ name: "google_search",
1213
+ inputSchema: lazySchema4(
1214
+ () => zodSchema4(
1215
+ z5.object({
1216
+ mode: z5.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
1217
+ dynamicThreshold: z5.number().default(1)
1218
+ })
1219
+ )
1220
+ )
1221
+ });
1222
+
1223
+ // src/tool/url-context.ts
1224
+ import {
1225
+ createProviderDefinedToolFactory as createProviderDefinedToolFactory2,
1226
+ lazySchema as lazySchema5,
1227
+ zodSchema as zodSchema5
1228
+ } from "@ai-sdk/provider-utils";
1229
+ import { z as z6 } from "zod/v4";
1230
+ var urlContext = createProviderDefinedToolFactory2({
1231
+ id: "google.url_context",
1232
+ name: "url_context",
1233
+ inputSchema: lazySchema5(() => zodSchema5(z6.object({})))
1234
+ });
1235
+
1185
1236
  // src/google-tools.ts
1186
1237
  var googleTools = {
1187
1238
  /**
@@ -1208,7 +1259,8 @@ var googleTools = {
1208
1259
  };
1209
1260
  export {
1210
1261
  GoogleGenerativeAILanguageModel,
1211
- googleTools,
1212
- safetyRatingSchema
1262
+ getGroundingMetadataSchema,
1263
+ getUrlContextMetadataSchema,
1264
+ googleTools
1213
1265
  };
1214
1266
  //# sourceMappingURL=index.mjs.map