@ai-sdk/google 2.0.17 → 2.0.19

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