@ai-sdk/google 3.0.0-beta.15 → 3.0.0-beta.17

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 * 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";
287
+ import {
288
+ createJsonErrorResponseHandler,
289
+ lazySchema,
290
+ zodSchema
291
+ } from "@ai-sdk/provider-utils";
286
292
  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
- });
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
310
+ import {
311
+ lazySchema as lazySchema2,
312
+ zodSchema as zodSchema2
313
+ } from "@ai-sdk/provider-utils";
300
314
  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(
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,41 +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
- /**
366
- * Optional. If specified, the media resolution specified will be used.
367
- *
368
- * https://ai.google.dev/api/generate-content#MediaResolution
369
- */
370
- mediaResolution: z2.enum([
371
- "MEDIA_RESOLUTION_UNSPECIFIED",
372
- "MEDIA_RESOLUTION_LOW",
373
- "MEDIA_RESOLUTION_MEDIUM",
374
- "MEDIA_RESOLUTION_HIGH"
375
- ]).optional()
376
- });
393
+ )
394
+ );
377
395
 
378
396
  // src/google-prepare-tools.ts
379
397
  import {
@@ -551,64 +569,6 @@ function mapGoogleGenerativeAIFinishReason({
551
569
  }
552
570
  }
553
571
 
554
- // src/tool/google-search.ts
555
- import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils";
556
- import * as z3 from "zod/v4";
557
- var groundingChunkSchema = z3.object({
558
- web: z3.object({ uri: z3.string(), title: z3.string() }).nullish(),
559
- retrievedContext: z3.object({ uri: z3.string(), title: z3.string() }).nullish()
560
- });
561
- var groundingMetadataSchema = z3.object({
562
- webSearchQueries: z3.array(z3.string()).nullish(),
563
- retrievalQueries: z3.array(z3.string()).nullish(),
564
- searchEntryPoint: z3.object({ renderedContent: z3.string() }).nullish(),
565
- groundingChunks: z3.array(groundingChunkSchema).nullish(),
566
- groundingSupports: z3.array(
567
- z3.object({
568
- segment: z3.object({
569
- startIndex: z3.number().nullish(),
570
- endIndex: z3.number().nullish(),
571
- text: z3.string().nullish()
572
- }),
573
- segment_text: z3.string().nullish(),
574
- groundingChunkIndices: z3.array(z3.number()).nullish(),
575
- supportChunkIndices: z3.array(z3.number()).nullish(),
576
- confidenceScores: z3.array(z3.number()).nullish(),
577
- confidenceScore: z3.array(z3.number()).nullish()
578
- })
579
- ).nullish(),
580
- retrievalMetadata: z3.union([
581
- z3.object({
582
- webDynamicRetrievalScore: z3.number()
583
- }),
584
- z3.object({})
585
- ]).nullish()
586
- });
587
- var googleSearch = createProviderDefinedToolFactory({
588
- id: "google.google_search",
589
- name: "google_search",
590
- inputSchema: z3.object({
591
- mode: z3.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
592
- dynamicThreshold: z3.number().default(1)
593
- })
594
- });
595
-
596
- // src/tool/url-context.ts
597
- import { createProviderDefinedToolFactory as createProviderDefinedToolFactory2 } from "@ai-sdk/provider-utils";
598
- import * as z4 from "zod/v4";
599
- var urlMetadataSchema = z4.object({
600
- retrievedUrl: z4.string(),
601
- urlRetrievalStatus: z4.string()
602
- });
603
- var urlContextMetadataSchema = z4.object({
604
- urlMetadata: z4.array(urlMetadataSchema)
605
- });
606
- var urlContext = createProviderDefinedToolFactory2({
607
- id: "google.url_context",
608
- name: "url_context",
609
- inputSchema: z4.object({})
610
- });
611
-
612
572
  // src/google-generative-ai-language-model.ts
613
573
  var GoogleGenerativeAILanguageModel = class {
614
574
  constructor(modelId, config) {
@@ -1104,103 +1064,183 @@ function extractSources({
1104
1064
  title: chunk.web.title
1105
1065
  }));
1106
1066
  }
1107
- var contentSchema = z5.object({
1108
- parts: z5.array(
1109
- z5.union([
1067
+ var getGroundingMetadataSchema = () => z3.object({
1068
+ webSearchQueries: z3.array(z3.string()).nullish(),
1069
+ retrievalQueries: z3.array(z3.string()).nullish(),
1070
+ searchEntryPoint: z3.object({ renderedContent: z3.string() }).nullish(),
1071
+ groundingChunks: z3.array(
1072
+ z3.object({
1073
+ web: z3.object({ uri: z3.string(), title: z3.string() }).nullish(),
1074
+ retrievedContext: z3.object({ uri: z3.string(), title: z3.string() }).nullish()
1075
+ })
1076
+ ).nullish(),
1077
+ groundingSupports: z3.array(
1078
+ z3.object({
1079
+ segment: z3.object({
1080
+ startIndex: z3.number().nullish(),
1081
+ endIndex: z3.number().nullish(),
1082
+ text: z3.string().nullish()
1083
+ }),
1084
+ segment_text: z3.string().nullish(),
1085
+ groundingChunkIndices: z3.array(z3.number()).nullish(),
1086
+ supportChunkIndices: z3.array(z3.number()).nullish(),
1087
+ confidenceScores: z3.array(z3.number()).nullish(),
1088
+ confidenceScore: z3.array(z3.number()).nullish()
1089
+ })
1090
+ ).nullish(),
1091
+ retrievalMetadata: z3.union([
1092
+ z3.object({
1093
+ webDynamicRetrievalScore: z3.number()
1094
+ }),
1095
+ z3.object({})
1096
+ ]).nullish()
1097
+ });
1098
+ var getContentSchema = () => z3.object({
1099
+ parts: z3.array(
1100
+ z3.union([
1110
1101
  // note: order matters since text can be fully empty
1111
- z5.object({
1112
- functionCall: z5.object({
1113
- name: z5.string(),
1114
- args: z5.unknown()
1102
+ z3.object({
1103
+ functionCall: z3.object({
1104
+ name: z3.string(),
1105
+ args: z3.unknown()
1115
1106
  }),
1116
- thoughtSignature: z5.string().nullish()
1107
+ thoughtSignature: z3.string().nullish()
1117
1108
  }),
1118
- z5.object({
1119
- inlineData: z5.object({
1120
- mimeType: z5.string(),
1121
- data: z5.string()
1109
+ z3.object({
1110
+ inlineData: z3.object({
1111
+ mimeType: z3.string(),
1112
+ data: z3.string()
1122
1113
  })
1123
1114
  }),
1124
- z5.object({
1125
- executableCode: z5.object({
1126
- language: z5.string(),
1127
- code: z5.string()
1115
+ z3.object({
1116
+ executableCode: z3.object({
1117
+ language: z3.string(),
1118
+ code: z3.string()
1128
1119
  }).nullish(),
1129
- codeExecutionResult: z5.object({
1130
- outcome: z5.string(),
1131
- output: z5.string()
1120
+ codeExecutionResult: z3.object({
1121
+ outcome: z3.string(),
1122
+ output: z3.string()
1132
1123
  }).nullish(),
1133
- text: z5.string().nullish(),
1134
- thought: z5.boolean().nullish(),
1135
- thoughtSignature: z5.string().nullish()
1124
+ text: z3.string().nullish(),
1125
+ thought: z3.boolean().nullish(),
1126
+ thoughtSignature: z3.string().nullish()
1136
1127
  })
1137
1128
  ])
1138
1129
  ).nullish()
1139
1130
  });
1140
- var safetyRatingSchema = z5.object({
1141
- category: z5.string().nullish(),
1142
- probability: z5.string().nullish(),
1143
- probabilityScore: z5.number().nullish(),
1144
- severity: z5.string().nullish(),
1145
- severityScore: z5.number().nullish(),
1146
- blocked: z5.boolean().nullish()
1131
+ var getSafetyRatingSchema = () => z3.object({
1132
+ category: z3.string().nullish(),
1133
+ probability: z3.string().nullish(),
1134
+ probabilityScore: z3.number().nullish(),
1135
+ severity: z3.string().nullish(),
1136
+ severityScore: z3.number().nullish(),
1137
+ blocked: z3.boolean().nullish()
1147
1138
  });
1148
- var usageSchema = z5.object({
1149
- cachedContentTokenCount: z5.number().nullish(),
1150
- thoughtsTokenCount: z5.number().nullish(),
1151
- promptTokenCount: z5.number().nullish(),
1152
- candidatesTokenCount: z5.number().nullish(),
1153
- totalTokenCount: z5.number().nullish()
1139
+ var usageSchema = z3.object({
1140
+ cachedContentTokenCount: z3.number().nullish(),
1141
+ thoughtsTokenCount: z3.number().nullish(),
1142
+ promptTokenCount: z3.number().nullish(),
1143
+ candidatesTokenCount: z3.number().nullish(),
1144
+ totalTokenCount: z3.number().nullish()
1154
1145
  });
1155
- var responseSchema = z5.object({
1156
- candidates: z5.array(
1157
- z5.object({
1158
- content: contentSchema.nullish().or(z5.object({}).strict()),
1159
- finishReason: z5.string().nullish(),
1160
- safetyRatings: z5.array(safetyRatingSchema).nullish(),
1161
- groundingMetadata: groundingMetadataSchema.nullish(),
1162
- urlContextMetadata: urlContextMetadataSchema.nullish()
1146
+ var getUrlContextMetadataSchema = () => z3.object({
1147
+ urlMetadata: z3.array(
1148
+ z3.object({
1149
+ retrievedUrl: z3.string(),
1150
+ urlRetrievalStatus: z3.string()
1163
1151
  })
1164
- ),
1165
- usageMetadata: usageSchema.nullish(),
1166
- promptFeedback: z5.object({
1167
- blockReason: z5.string().nullish(),
1168
- safetyRatings: z5.array(safetyRatingSchema).nullish()
1169
- }).nullish()
1152
+ )
1170
1153
  });
1171
- var chunkSchema = z5.object({
1172
- candidates: z5.array(
1173
- z5.object({
1174
- content: contentSchema.nullish(),
1175
- finishReason: z5.string().nullish(),
1176
- safetyRatings: z5.array(safetyRatingSchema).nullish(),
1177
- groundingMetadata: groundingMetadataSchema.nullish(),
1178
- urlContextMetadata: urlContextMetadataSchema.nullish()
1154
+ var responseSchema = lazySchema3(
1155
+ () => zodSchema3(
1156
+ z3.object({
1157
+ candidates: z3.array(
1158
+ z3.object({
1159
+ content: getContentSchema().nullish().or(z3.object({}).strict()),
1160
+ finishReason: z3.string().nullish(),
1161
+ safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
1162
+ groundingMetadata: getGroundingMetadataSchema().nullish(),
1163
+ urlContextMetadata: getUrlContextMetadataSchema().nullish()
1164
+ })
1165
+ ),
1166
+ usageMetadata: usageSchema.nullish(),
1167
+ promptFeedback: z3.object({
1168
+ blockReason: z3.string().nullish(),
1169
+ safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
1170
+ }).nullish()
1179
1171
  })
1180
- ).nullish(),
1181
- usageMetadata: usageSchema.nullish(),
1182
- promptFeedback: z5.object({
1183
- blockReason: z5.string().nullish(),
1184
- safetyRatings: z5.array(safetyRatingSchema).nullish()
1185
- }).nullish()
1186
- });
1172
+ )
1173
+ );
1174
+ var chunkSchema = lazySchema3(
1175
+ () => zodSchema3(
1176
+ z3.object({
1177
+ candidates: z3.array(
1178
+ z3.object({
1179
+ content: getContentSchema().nullish(),
1180
+ finishReason: z3.string().nullish(),
1181
+ safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
1182
+ groundingMetadata: getGroundingMetadataSchema().nullish(),
1183
+ urlContextMetadata: getUrlContextMetadataSchema().nullish()
1184
+ })
1185
+ ).nullish(),
1186
+ usageMetadata: usageSchema.nullish(),
1187
+ promptFeedback: z3.object({
1188
+ blockReason: z3.string().nullish(),
1189
+ safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
1190
+ }).nullish()
1191
+ })
1192
+ )
1193
+ );
1187
1194
 
1188
1195
  // src/tool/code-execution.ts
1189
1196
  import { createProviderDefinedToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils";
1190
- import * as z6 from "zod/v4";
1197
+ import * as z4 from "zod/v4";
1191
1198
  var codeExecution = createProviderDefinedToolFactoryWithOutputSchema({
1192
1199
  id: "google.code_execution",
1193
1200
  name: "code_execution",
1194
- inputSchema: z6.object({
1195
- language: z6.string().describe("The programming language of the code."),
1196
- code: z6.string().describe("The code to be executed.")
1201
+ inputSchema: z4.object({
1202
+ language: z4.string().describe("The programming language of the code."),
1203
+ code: z4.string().describe("The code to be executed.")
1197
1204
  }),
1198
- outputSchema: z6.object({
1199
- outcome: z6.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
1200
- output: z6.string().describe("The output from the code execution.")
1205
+ outputSchema: z4.object({
1206
+ outcome: z4.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
1207
+ output: z4.string().describe("The output from the code execution.")
1201
1208
  })
1202
1209
  });
1203
1210
 
1211
+ // src/tool/google-search.ts
1212
+ import {
1213
+ createProviderDefinedToolFactory,
1214
+ lazySchema as lazySchema4,
1215
+ zodSchema as zodSchema4
1216
+ } from "@ai-sdk/provider-utils";
1217
+ import * as z5 from "zod/v4";
1218
+ var googleSearch = createProviderDefinedToolFactory({
1219
+ id: "google.google_search",
1220
+ name: "google_search",
1221
+ inputSchema: lazySchema4(
1222
+ () => zodSchema4(
1223
+ z5.object({
1224
+ mode: z5.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
1225
+ dynamicThreshold: z5.number().default(1)
1226
+ })
1227
+ )
1228
+ )
1229
+ });
1230
+
1231
+ // src/tool/url-context.ts
1232
+ import {
1233
+ createProviderDefinedToolFactory as createProviderDefinedToolFactory2,
1234
+ lazySchema as lazySchema5,
1235
+ zodSchema as zodSchema5
1236
+ } from "@ai-sdk/provider-utils";
1237
+ import * as z6 from "zod/v4";
1238
+ var urlContext = createProviderDefinedToolFactory2({
1239
+ id: "google.url_context",
1240
+ name: "url_context",
1241
+ inputSchema: lazySchema5(() => zodSchema5(z6.object({})))
1242
+ });
1243
+
1204
1244
  // src/google-tools.ts
1205
1245
  var googleTools = {
1206
1246
  /**
@@ -1227,7 +1267,8 @@ var googleTools = {
1227
1267
  };
1228
1268
  export {
1229
1269
  GoogleGenerativeAILanguageModel,
1230
- googleTools,
1231
- safetyRatingSchema
1270
+ getGroundingMetadataSchema,
1271
+ getUrlContextMetadataSchema,
1272
+ googleTools
1232
1273
  };
1233
1274
  //# sourceMappingURL=index.mjs.map