@ai-sdk/google 2.1.0-beta.9 → 3.0.0-beta.15

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.
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/internal/index.ts
@@ -28,7 +38,7 @@ module.exports = __toCommonJS(internal_exports);
28
38
 
29
39
  // src/google-generative-ai-language-model.ts
30
40
  var import_provider_utils5 = require("@ai-sdk/provider-utils");
31
- var import_v45 = require("zod/v4");
41
+ var z5 = __toESM(require("zod/v4"));
32
42
 
33
43
  // src/convert-json-schema-to-openapi-schema.ts
34
44
  function convertJSONSchemaToOpenAPISchema(jsonSchema) {
@@ -128,7 +138,7 @@ function isEmptyObjectSchema(jsonSchema) {
128
138
  var import_provider = require("@ai-sdk/provider");
129
139
  var import_provider_utils = require("@ai-sdk/provider-utils");
130
140
  function convertToGoogleGenerativeAIMessages(prompt, options) {
131
- var _a;
141
+ var _a, _b;
132
142
  const systemInstructionParts = [];
133
143
  const contents = [];
134
144
  let systemMessagesAllowed = true;
@@ -180,12 +190,12 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
180
190
  contents.push({
181
191
  role: "model",
182
192
  parts: content.map((part) => {
183
- var _a2, _b, _c, _d, _e, _f;
193
+ var _a2, _b2, _c, _d, _e, _f;
184
194
  switch (part.type) {
185
195
  case "text": {
186
196
  return part.text.length === 0 ? void 0 : {
187
197
  text: part.text,
188
- thoughtSignature: (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b.thoughtSignature
198
+ thoughtSignature: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.google) == null ? void 0 : _b2.thoughtSignature
189
199
  };
190
200
  }
191
201
  case "reasoning": {
@@ -270,7 +280,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
270
280
  name: part.toolName,
271
281
  response: {
272
282
  name: part.toolName,
273
- content: output.value
283
+ content: output.type === "execution-denied" ? (_b = output.reason) != null ? _b : "Tool execution denied." : output.value
274
284
  }
275
285
  }
276
286
  });
@@ -301,12 +311,12 @@ function getModelPath(modelId) {
301
311
 
302
312
  // src/google-error.ts
303
313
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
304
- var import_v4 = require("zod/v4");
305
- var googleErrorDataSchema = import_v4.z.object({
306
- error: import_v4.z.object({
307
- code: import_v4.z.number().nullable(),
308
- message: import_v4.z.string(),
309
- status: import_v4.z.string()
314
+ var z = __toESM(require("zod/v4"));
315
+ var googleErrorDataSchema = z.object({
316
+ error: z.object({
317
+ code: z.number().nullable(),
318
+ message: z.string(),
319
+ status: z.string()
310
320
  })
311
321
  });
312
322
  var googleFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
@@ -315,19 +325,19 @@ var googleFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResp
315
325
  });
316
326
 
317
327
  // src/google-generative-ai-options.ts
318
- var import_v42 = require("zod/v4");
319
- var googleGenerativeAIProviderOptions = import_v42.z.object({
320
- responseModalities: import_v42.z.array(import_v42.z.enum(["TEXT", "IMAGE"])).optional(),
321
- thinkingConfig: import_v42.z.object({
322
- thinkingBudget: import_v42.z.number().optional(),
323
- includeThoughts: import_v42.z.boolean().optional()
328
+ var z2 = __toESM(require("zod/v4"));
329
+ var googleGenerativeAIProviderOptions = z2.object({
330
+ responseModalities: z2.array(z2.enum(["TEXT", "IMAGE"])).optional(),
331
+ thinkingConfig: z2.object({
332
+ thinkingBudget: z2.number().optional(),
333
+ includeThoughts: z2.boolean().optional()
324
334
  }).optional(),
325
335
  /**
326
336
  Optional.
327
337
  The name of the cached content used as context to serve the prediction.
328
338
  Format: cachedContents/{cachedContent}
329
339
  */
330
- cachedContent: import_v42.z.string().optional(),
340
+ cachedContent: z2.string().optional(),
331
341
  /**
332
342
  * Optional. Enable structured output. Default is true.
333
343
  *
@@ -336,13 +346,13 @@ var googleGenerativeAIProviderOptions = import_v42.z.object({
336
346
  * Google Generative AI uses. You can use this to disable
337
347
  * structured outputs if you need to.
338
348
  */
339
- structuredOutputs: import_v42.z.boolean().optional(),
349
+ structuredOutputs: z2.boolean().optional(),
340
350
  /**
341
351
  Optional. A list of unique safety settings for blocking unsafe content.
342
352
  */
343
- safetySettings: import_v42.z.array(
344
- import_v42.z.object({
345
- category: import_v42.z.enum([
353
+ safetySettings: z2.array(
354
+ z2.object({
355
+ category: z2.enum([
346
356
  "HARM_CATEGORY_UNSPECIFIED",
347
357
  "HARM_CATEGORY_HATE_SPEECH",
348
358
  "HARM_CATEGORY_DANGEROUS_CONTENT",
@@ -350,7 +360,7 @@ var googleGenerativeAIProviderOptions = import_v42.z.object({
350
360
  "HARM_CATEGORY_SEXUALLY_EXPLICIT",
351
361
  "HARM_CATEGORY_CIVIC_INTEGRITY"
352
362
  ]),
353
- threshold: import_v42.z.enum([
363
+ threshold: z2.enum([
354
364
  "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
355
365
  "BLOCK_LOW_AND_ABOVE",
356
366
  "BLOCK_MEDIUM_AND_ABOVE",
@@ -360,7 +370,7 @@ var googleGenerativeAIProviderOptions = import_v42.z.object({
360
370
  ])
361
371
  })
362
372
  ).optional(),
363
- threshold: import_v42.z.enum([
373
+ threshold: z2.enum([
364
374
  "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
365
375
  "BLOCK_LOW_AND_ABOVE",
366
376
  "BLOCK_MEDIUM_AND_ABOVE",
@@ -373,19 +383,19 @@ var googleGenerativeAIProviderOptions = import_v42.z.object({
373
383
  *
374
384
  * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
375
385
  */
376
- audioTimestamp: import_v42.z.boolean().optional(),
386
+ audioTimestamp: z2.boolean().optional(),
377
387
  /**
378
388
  * Optional. Defines labels used in billing reports. Available on Vertex AI only.
379
389
  *
380
390
  * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
381
391
  */
382
- labels: import_v42.z.record(import_v42.z.string(), import_v42.z.string()).optional(),
392
+ labels: z2.record(z2.string(), z2.string()).optional(),
383
393
  /**
384
394
  * Optional. If specified, the media resolution specified will be used.
385
395
  *
386
396
  * https://ai.google.dev/api/generate-content#MediaResolution
387
397
  */
388
- mediaResolution: import_v42.z.enum([
398
+ mediaResolution: z2.enum([
389
399
  "MEDIA_RESOLUTION_UNSPECIFIED",
390
400
  "MEDIA_RESOLUTION_LOW",
391
401
  "MEDIA_RESOLUTION_MEDIUM",
@@ -403,7 +413,12 @@ function prepareTools({
403
413
  var _a;
404
414
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
405
415
  const toolWarnings = [];
406
- const isGemini2 = modelId.includes("gemini-2");
416
+ const isLatest = [
417
+ "gemini-flash-latest",
418
+ "gemini-flash-lite-latest",
419
+ "gemini-pro-latest"
420
+ ].some((id) => id === modelId);
421
+ const isGemini2 = modelId.includes("gemini-2") || isLatest;
407
422
  const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
408
423
  if (tools == null) {
409
424
  return { tools: void 0, toolConfig: void 0, toolWarnings };
@@ -564,60 +579,60 @@ function mapGoogleGenerativeAIFinishReason({
564
579
 
565
580
  // src/tool/google-search.ts
566
581
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
567
- var import_v43 = require("zod/v4");
568
- var groundingChunkSchema = import_v43.z.object({
569
- web: import_v43.z.object({ uri: import_v43.z.string(), title: import_v43.z.string() }).nullish(),
570
- retrievedContext: import_v43.z.object({ uri: import_v43.z.string(), title: import_v43.z.string() }).nullish()
582
+ var z3 = __toESM(require("zod/v4"));
583
+ var groundingChunkSchema = z3.object({
584
+ web: z3.object({ uri: z3.string(), title: z3.string() }).nullish(),
585
+ retrievedContext: z3.object({ uri: z3.string(), title: z3.string() }).nullish()
571
586
  });
572
- var groundingMetadataSchema = import_v43.z.object({
573
- webSearchQueries: import_v43.z.array(import_v43.z.string()).nullish(),
574
- retrievalQueries: import_v43.z.array(import_v43.z.string()).nullish(),
575
- searchEntryPoint: import_v43.z.object({ renderedContent: import_v43.z.string() }).nullish(),
576
- groundingChunks: import_v43.z.array(groundingChunkSchema).nullish(),
577
- groundingSupports: import_v43.z.array(
578
- import_v43.z.object({
579
- segment: import_v43.z.object({
580
- startIndex: import_v43.z.number().nullish(),
581
- endIndex: import_v43.z.number().nullish(),
582
- text: import_v43.z.string().nullish()
587
+ var groundingMetadataSchema = z3.object({
588
+ webSearchQueries: z3.array(z3.string()).nullish(),
589
+ retrievalQueries: z3.array(z3.string()).nullish(),
590
+ searchEntryPoint: z3.object({ renderedContent: z3.string() }).nullish(),
591
+ groundingChunks: z3.array(groundingChunkSchema).nullish(),
592
+ groundingSupports: z3.array(
593
+ z3.object({
594
+ segment: z3.object({
595
+ startIndex: z3.number().nullish(),
596
+ endIndex: z3.number().nullish(),
597
+ text: z3.string().nullish()
583
598
  }),
584
- segment_text: import_v43.z.string().nullish(),
585
- groundingChunkIndices: import_v43.z.array(import_v43.z.number()).nullish(),
586
- supportChunkIndices: import_v43.z.array(import_v43.z.number()).nullish(),
587
- confidenceScores: import_v43.z.array(import_v43.z.number()).nullish(),
588
- confidenceScore: import_v43.z.array(import_v43.z.number()).nullish()
599
+ segment_text: z3.string().nullish(),
600
+ groundingChunkIndices: z3.array(z3.number()).nullish(),
601
+ supportChunkIndices: z3.array(z3.number()).nullish(),
602
+ confidenceScores: z3.array(z3.number()).nullish(),
603
+ confidenceScore: z3.array(z3.number()).nullish()
589
604
  })
590
605
  ).nullish(),
591
- retrievalMetadata: import_v43.z.union([
592
- import_v43.z.object({
593
- webDynamicRetrievalScore: import_v43.z.number()
606
+ retrievalMetadata: z3.union([
607
+ z3.object({
608
+ webDynamicRetrievalScore: z3.number()
594
609
  }),
595
- import_v43.z.object({})
610
+ z3.object({})
596
611
  ]).nullish()
597
612
  });
598
613
  var googleSearch = (0, import_provider_utils3.createProviderDefinedToolFactory)({
599
614
  id: "google.google_search",
600
615
  name: "google_search",
601
- inputSchema: import_v43.z.object({
602
- mode: import_v43.z.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
603
- dynamicThreshold: import_v43.z.number().default(1)
616
+ inputSchema: z3.object({
617
+ mode: z3.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
618
+ dynamicThreshold: z3.number().default(1)
604
619
  })
605
620
  });
606
621
 
607
622
  // src/tool/url-context.ts
608
623
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
609
- var import_v44 = require("zod/v4");
610
- var urlMetadataSchema = import_v44.z.object({
611
- retrievedUrl: import_v44.z.string(),
612
- urlRetrievalStatus: import_v44.z.string()
624
+ var z4 = __toESM(require("zod/v4"));
625
+ var urlMetadataSchema = z4.object({
626
+ retrievedUrl: z4.string(),
627
+ urlRetrievalStatus: z4.string()
613
628
  });
614
- var urlContextMetadataSchema = import_v44.z.object({
615
- urlMetadata: import_v44.z.array(urlMetadataSchema)
629
+ var urlContextMetadataSchema = z4.object({
630
+ urlMetadata: z4.array(urlMetadataSchema)
616
631
  });
617
632
  var urlContext = (0, import_provider_utils4.createProviderDefinedToolFactory)({
618
633
  id: "google.url_context",
619
634
  name: "url_context",
620
- inputSchema: import_v44.z.object({})
635
+ inputSchema: z4.object({})
621
636
  });
622
637
 
623
638
  // src/google-generative-ai-language-model.ts
@@ -1115,100 +1130,100 @@ function extractSources({
1115
1130
  title: chunk.web.title
1116
1131
  }));
1117
1132
  }
1118
- var contentSchema = import_v45.z.object({
1119
- parts: import_v45.z.array(
1120
- import_v45.z.union([
1133
+ var contentSchema = z5.object({
1134
+ parts: z5.array(
1135
+ z5.union([
1121
1136
  // note: order matters since text can be fully empty
1122
- import_v45.z.object({
1123
- functionCall: import_v45.z.object({
1124
- name: import_v45.z.string(),
1125
- args: import_v45.z.unknown()
1137
+ z5.object({
1138
+ functionCall: z5.object({
1139
+ name: z5.string(),
1140
+ args: z5.unknown()
1126
1141
  }),
1127
- thoughtSignature: import_v45.z.string().nullish()
1142
+ thoughtSignature: z5.string().nullish()
1128
1143
  }),
1129
- import_v45.z.object({
1130
- inlineData: import_v45.z.object({
1131
- mimeType: import_v45.z.string(),
1132
- data: import_v45.z.string()
1144
+ z5.object({
1145
+ inlineData: z5.object({
1146
+ mimeType: z5.string(),
1147
+ data: z5.string()
1133
1148
  })
1134
1149
  }),
1135
- import_v45.z.object({
1136
- executableCode: import_v45.z.object({
1137
- language: import_v45.z.string(),
1138
- code: import_v45.z.string()
1150
+ z5.object({
1151
+ executableCode: z5.object({
1152
+ language: z5.string(),
1153
+ code: z5.string()
1139
1154
  }).nullish(),
1140
- codeExecutionResult: import_v45.z.object({
1141
- outcome: import_v45.z.string(),
1142
- output: import_v45.z.string()
1155
+ codeExecutionResult: z5.object({
1156
+ outcome: z5.string(),
1157
+ output: z5.string()
1143
1158
  }).nullish(),
1144
- text: import_v45.z.string().nullish(),
1145
- thought: import_v45.z.boolean().nullish(),
1146
- thoughtSignature: import_v45.z.string().nullish()
1159
+ text: z5.string().nullish(),
1160
+ thought: z5.boolean().nullish(),
1161
+ thoughtSignature: z5.string().nullish()
1147
1162
  })
1148
1163
  ])
1149
1164
  ).nullish()
1150
1165
  });
1151
- var safetyRatingSchema = import_v45.z.object({
1152
- category: import_v45.z.string().nullish(),
1153
- probability: import_v45.z.string().nullish(),
1154
- probabilityScore: import_v45.z.number().nullish(),
1155
- severity: import_v45.z.string().nullish(),
1156
- severityScore: import_v45.z.number().nullish(),
1157
- blocked: import_v45.z.boolean().nullish()
1166
+ var safetyRatingSchema = z5.object({
1167
+ category: z5.string().nullish(),
1168
+ probability: z5.string().nullish(),
1169
+ probabilityScore: z5.number().nullish(),
1170
+ severity: z5.string().nullish(),
1171
+ severityScore: z5.number().nullish(),
1172
+ blocked: z5.boolean().nullish()
1158
1173
  });
1159
- var usageSchema = import_v45.z.object({
1160
- cachedContentTokenCount: import_v45.z.number().nullish(),
1161
- thoughtsTokenCount: import_v45.z.number().nullish(),
1162
- promptTokenCount: import_v45.z.number().nullish(),
1163
- candidatesTokenCount: import_v45.z.number().nullish(),
1164
- totalTokenCount: import_v45.z.number().nullish()
1174
+ var usageSchema = z5.object({
1175
+ cachedContentTokenCount: z5.number().nullish(),
1176
+ thoughtsTokenCount: z5.number().nullish(),
1177
+ promptTokenCount: z5.number().nullish(),
1178
+ candidatesTokenCount: z5.number().nullish(),
1179
+ totalTokenCount: z5.number().nullish()
1165
1180
  });
1166
- var responseSchema = import_v45.z.object({
1167
- candidates: import_v45.z.array(
1168
- import_v45.z.object({
1169
- content: contentSchema.nullish().or(import_v45.z.object({}).strict()),
1170
- finishReason: import_v45.z.string().nullish(),
1171
- safetyRatings: import_v45.z.array(safetyRatingSchema).nullish(),
1181
+ var responseSchema = z5.object({
1182
+ candidates: z5.array(
1183
+ z5.object({
1184
+ content: contentSchema.nullish().or(z5.object({}).strict()),
1185
+ finishReason: z5.string().nullish(),
1186
+ safetyRatings: z5.array(safetyRatingSchema).nullish(),
1172
1187
  groundingMetadata: groundingMetadataSchema.nullish(),
1173
1188
  urlContextMetadata: urlContextMetadataSchema.nullish()
1174
1189
  })
1175
1190
  ),
1176
1191
  usageMetadata: usageSchema.nullish(),
1177
- promptFeedback: import_v45.z.object({
1178
- blockReason: import_v45.z.string().nullish(),
1179
- safetyRatings: import_v45.z.array(safetyRatingSchema).nullish()
1192
+ promptFeedback: z5.object({
1193
+ blockReason: z5.string().nullish(),
1194
+ safetyRatings: z5.array(safetyRatingSchema).nullish()
1180
1195
  }).nullish()
1181
1196
  });
1182
- var chunkSchema = import_v45.z.object({
1183
- candidates: import_v45.z.array(
1184
- import_v45.z.object({
1197
+ var chunkSchema = z5.object({
1198
+ candidates: z5.array(
1199
+ z5.object({
1185
1200
  content: contentSchema.nullish(),
1186
- finishReason: import_v45.z.string().nullish(),
1187
- safetyRatings: import_v45.z.array(safetyRatingSchema).nullish(),
1201
+ finishReason: z5.string().nullish(),
1202
+ safetyRatings: z5.array(safetyRatingSchema).nullish(),
1188
1203
  groundingMetadata: groundingMetadataSchema.nullish(),
1189
1204
  urlContextMetadata: urlContextMetadataSchema.nullish()
1190
1205
  })
1191
1206
  ).nullish(),
1192
1207
  usageMetadata: usageSchema.nullish(),
1193
- promptFeedback: import_v45.z.object({
1194
- blockReason: import_v45.z.string().nullish(),
1195
- safetyRatings: import_v45.z.array(safetyRatingSchema).nullish()
1208
+ promptFeedback: z5.object({
1209
+ blockReason: z5.string().nullish(),
1210
+ safetyRatings: z5.array(safetyRatingSchema).nullish()
1196
1211
  }).nullish()
1197
1212
  });
1198
1213
 
1199
1214
  // src/tool/code-execution.ts
1200
1215
  var import_provider_utils6 = require("@ai-sdk/provider-utils");
1201
- var import_v46 = require("zod/v4");
1216
+ var z6 = __toESM(require("zod/v4"));
1202
1217
  var codeExecution = (0, import_provider_utils6.createProviderDefinedToolFactoryWithOutputSchema)({
1203
1218
  id: "google.code_execution",
1204
1219
  name: "code_execution",
1205
- inputSchema: import_v46.z.object({
1206
- language: import_v46.z.string().describe("The programming language of the code."),
1207
- code: import_v46.z.string().describe("The code to be executed.")
1220
+ inputSchema: z6.object({
1221
+ language: z6.string().describe("The programming language of the code."),
1222
+ code: z6.string().describe("The code to be executed.")
1208
1223
  }),
1209
- outputSchema: import_v46.z.object({
1210
- outcome: import_v46.z.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
1211
- output: import_v46.z.string().describe("The output from the code execution.")
1224
+ outputSchema: z6.object({
1225
+ outcome: z6.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
1226
+ output: z6.string().describe("The output from the code execution.")
1212
1227
  })
1213
1228
  });
1214
1229