@ai-sdk/google 4.0.0-beta.4 → 4.0.0-beta.41

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,35 +1,22 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/internal/index.ts
21
- var internal_exports = {};
22
- __export(internal_exports, {
23
- GoogleGenerativeAILanguageModel: () => GoogleGenerativeAILanguageModel,
24
- getGroundingMetadataSchema: () => getGroundingMetadataSchema,
25
- getUrlContextMetadataSchema: () => getUrlContextMetadataSchema,
26
- googleTools: () => googleTools
27
- });
28
- module.exports = __toCommonJS(internal_exports);
29
-
30
1
  // src/google-generative-ai-language-model.ts
31
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
32
- var import_v43 = require("zod/v4");
2
+ import {
3
+ combineHeaders,
4
+ createEventSourceResponseHandler,
5
+ createJsonResponseHandler,
6
+ generateId,
7
+ isCustomReasoning,
8
+ lazySchema as lazySchema3,
9
+ mapReasoningToProviderBudget,
10
+ mapReasoningToProviderEffort,
11
+ parseProviderOptions,
12
+ postJsonToApi,
13
+ resolve,
14
+ serializeModelOptions,
15
+ WORKFLOW_SERIALIZE,
16
+ WORKFLOW_DESERIALIZE,
17
+ zodSchema as zodSchema3
18
+ } from "@ai-sdk/provider-utils";
19
+ import { z as z3 } from "zod/v4";
33
20
 
34
21
  // src/convert-google-generative-ai-usage.ts
35
22
  function convertGoogleGenerativeAIUsage(usage) {
@@ -187,20 +174,133 @@ function isEmptyObjectSchema(jsonSchema) {
187
174
  }
188
175
 
189
176
  // src/convert-to-google-generative-ai-messages.ts
190
- var import_provider = require("@ai-sdk/provider");
191
- var import_provider_utils = require("@ai-sdk/provider-utils");
177
+ import {
178
+ UnsupportedFunctionalityError
179
+ } from "@ai-sdk/provider";
180
+ import {
181
+ convertToBase64,
182
+ isProviderReference,
183
+ resolveProviderReference
184
+ } from "@ai-sdk/provider-utils";
185
+ var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
186
+ function parseBase64DataUrl(value) {
187
+ const match = dataUrlRegex.exec(value);
188
+ if (match == null) {
189
+ return void 0;
190
+ }
191
+ return {
192
+ mediaType: match[1],
193
+ data: match[2]
194
+ };
195
+ }
196
+ function convertUrlToolResultPart(url) {
197
+ const parsedDataUrl = parseBase64DataUrl(url);
198
+ if (parsedDataUrl == null) {
199
+ return void 0;
200
+ }
201
+ return {
202
+ inlineData: {
203
+ mimeType: parsedDataUrl.mediaType,
204
+ data: parsedDataUrl.data
205
+ }
206
+ };
207
+ }
208
+ function appendToolResultParts(parts, toolName, outputValue) {
209
+ const functionResponseParts = [];
210
+ const responseTextParts = [];
211
+ for (const contentPart of outputValue) {
212
+ switch (contentPart.type) {
213
+ case "text": {
214
+ responseTextParts.push(contentPart.text);
215
+ break;
216
+ }
217
+ case "file-data": {
218
+ functionResponseParts.push({
219
+ inlineData: {
220
+ mimeType: contentPart.mediaType,
221
+ data: contentPart.data
222
+ }
223
+ });
224
+ break;
225
+ }
226
+ case "file-url": {
227
+ const functionResponsePart = convertUrlToolResultPart(
228
+ contentPart.url
229
+ );
230
+ if (functionResponsePart != null) {
231
+ functionResponseParts.push(functionResponsePart);
232
+ } else {
233
+ responseTextParts.push(JSON.stringify(contentPart));
234
+ }
235
+ break;
236
+ }
237
+ default: {
238
+ responseTextParts.push(JSON.stringify(contentPart));
239
+ break;
240
+ }
241
+ }
242
+ }
243
+ parts.push({
244
+ functionResponse: {
245
+ name: toolName,
246
+ response: {
247
+ name: toolName,
248
+ content: responseTextParts.length > 0 ? responseTextParts.join("\n") : "Tool executed successfully."
249
+ },
250
+ ...functionResponseParts.length > 0 ? { parts: functionResponseParts } : {}
251
+ }
252
+ });
253
+ }
254
+ function appendLegacyToolResultParts(parts, toolName, outputValue) {
255
+ for (const contentPart of outputValue) {
256
+ switch (contentPart.type) {
257
+ case "text":
258
+ parts.push({
259
+ functionResponse: {
260
+ name: toolName,
261
+ response: {
262
+ name: toolName,
263
+ content: contentPart.text
264
+ }
265
+ }
266
+ });
267
+ break;
268
+ case "file-data":
269
+ if (contentPart.mediaType.startsWith("image/")) {
270
+ parts.push(
271
+ {
272
+ inlineData: {
273
+ mimeType: contentPart.mediaType,
274
+ data: contentPart.data
275
+ }
276
+ },
277
+ {
278
+ text: "Tool executed successfully and returned this image as a response"
279
+ }
280
+ );
281
+ } else {
282
+ parts.push({ text: JSON.stringify(contentPart) });
283
+ }
284
+ break;
285
+ default:
286
+ parts.push({ text: JSON.stringify(contentPart) });
287
+ break;
288
+ }
289
+ }
290
+ }
192
291
  function convertToGoogleGenerativeAIMessages(prompt, options) {
193
- var _a, _b, _c;
292
+ var _a, _b, _c, _d, _e, _f, _g, _h;
194
293
  const systemInstructionParts = [];
195
294
  const contents = [];
196
295
  let systemMessagesAllowed = true;
197
296
  const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
198
297
  const providerOptionsName = (_b = options == null ? void 0 : options.providerOptionsName) != null ? _b : "google";
298
+ const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
199
299
  for (const { role, content } of prompt) {
200
300
  switch (role) {
201
301
  case "system": {
202
302
  if (!systemMessagesAllowed) {
203
- throw new import_provider.UnsupportedFunctionalityError({
303
+ throw new UnsupportedFunctionalityError({
204
304
  functionality: "system messages are only supported at the beginning of the conversation"
205
305
  });
206
306
  }
@@ -218,19 +318,36 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
218
318
  }
219
319
  case "file": {
220
320
  const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
221
- parts.push(
222
- part.data instanceof URL ? {
321
+ if (part.data instanceof URL) {
322
+ parts.push({
223
323
  fileData: {
224
324
  mimeType: mediaType,
225
325
  fileUri: part.data.toString()
226
326
  }
227
- } : {
327
+ });
328
+ } else if (isProviderReference(part.data)) {
329
+ if (providerOptionsName === "vertex") {
330
+ throw new UnsupportedFunctionalityError({
331
+ functionality: "file parts with provider references"
332
+ });
333
+ }
334
+ parts.push({
335
+ fileData: {
336
+ mimeType: mediaType,
337
+ fileUri: resolveProviderReference({
338
+ reference: part.data,
339
+ provider: "google"
340
+ })
341
+ }
342
+ });
343
+ } else {
344
+ parts.push({
228
345
  inlineData: {
229
346
  mimeType: mediaType,
230
- data: (0, import_provider_utils.convertToBase64)(part.data)
347
+ data: convertToBase64(part.data)
231
348
  }
232
- }
233
- );
349
+ });
350
+ }
234
351
  break;
235
352
  }
236
353
  }
@@ -243,8 +360,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
243
360
  contents.push({
244
361
  role: "model",
245
362
  parts: content.map((part) => {
246
- var _a2, _b2, _c2, _d;
247
- const providerOpts = (_d = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) != null ? _d : providerOptionsName !== "google" ? (_b2 = part.providerOptions) == null ? void 0 : _b2.google : (_c2 = part.providerOptions) == null ? void 0 : _c2.vertex;
363
+ var _a2, _b2, _c2, _d2;
364
+ const providerOpts = (_d2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) != null ? _d2 : providerOptionsName !== "google" ? (_b2 = part.providerOptions) == null ? void 0 : _b2.google : (_c2 = part.providerOptions) == null ? void 0 : _c2.vertex;
248
365
  const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
249
366
  switch (part.type) {
250
367
  case "text": {
@@ -260,22 +377,67 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
260
377
  thoughtSignature
261
378
  };
262
379
  }
380
+ case "reasoning-file": {
381
+ if (part.data instanceof URL) {
382
+ throw new UnsupportedFunctionalityError({
383
+ functionality: "File data URLs in assistant messages are not supported"
384
+ });
385
+ }
386
+ return {
387
+ inlineData: {
388
+ mimeType: part.mediaType,
389
+ data: convertToBase64(part.data)
390
+ },
391
+ thought: true,
392
+ thoughtSignature
393
+ };
394
+ }
263
395
  case "file": {
264
396
  if (part.data instanceof URL) {
265
- throw new import_provider.UnsupportedFunctionalityError({
397
+ throw new UnsupportedFunctionalityError({
266
398
  functionality: "File data URLs in assistant messages are not supported"
267
399
  });
268
400
  }
401
+ if (isProviderReference(part.data)) {
402
+ if (providerOptionsName === "vertex") {
403
+ throw new UnsupportedFunctionalityError({
404
+ functionality: "file parts with provider references"
405
+ });
406
+ }
407
+ return {
408
+ fileData: {
409
+ mimeType: part.mediaType,
410
+ fileUri: resolveProviderReference({
411
+ reference: part.data,
412
+ provider: "google"
413
+ })
414
+ },
415
+ ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
416
+ thoughtSignature
417
+ };
418
+ }
269
419
  return {
270
420
  inlineData: {
271
421
  mimeType: part.mediaType,
272
- data: (0, import_provider_utils.convertToBase64)(part.data)
422
+ data: convertToBase64(part.data)
273
423
  },
274
424
  ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
275
425
  thoughtSignature
276
426
  };
277
427
  }
278
428
  case "tool-call": {
429
+ const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
430
+ const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
431
+ if (serverToolCallId && serverToolType) {
432
+ return {
433
+ toolCall: {
434
+ toolType: serverToolType,
435
+ args: typeof part.input === "string" ? JSON.parse(part.input) : part.input,
436
+ id: serverToolCallId
437
+ },
438
+ thoughtSignature
439
+ };
440
+ }
279
441
  return {
280
442
  functionCall: {
281
443
  name: part.toolName,
@@ -284,6 +446,21 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
284
446
  thoughtSignature
285
447
  };
286
448
  }
449
+ case "tool-result": {
450
+ const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
451
+ const serverToolType = (providerOpts == null ? void 0 : providerOpts.serverToolType) != null ? String(providerOpts.serverToolType) : void 0;
452
+ if (serverToolCallId && serverToolType) {
453
+ return {
454
+ toolResponse: {
455
+ toolType: serverToolType,
456
+ response: part.output.type === "json" ? part.output.value : {},
457
+ id: serverToolCallId
458
+ },
459
+ thoughtSignature
460
+ };
461
+ }
462
+ return void 0;
463
+ }
287
464
  }
288
465
  }).filter((part) => part !== void 0)
289
466
  });
@@ -296,38 +473,32 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
296
473
  if (part.type === "tool-approval-response") {
297
474
  continue;
298
475
  }
476
+ const partProviderOpts = (_g = (_d = part.providerOptions) == null ? void 0 : _d[providerOptionsName]) != null ? _g : providerOptionsName !== "google" ? (_e = part.providerOptions) == null ? void 0 : _e.google : (_f = part.providerOptions) == null ? void 0 : _f.vertex;
477
+ const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
478
+ const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
479
+ if (serverToolCallId && serverToolType) {
480
+ const serverThoughtSignature = (partProviderOpts == null ? void 0 : partProviderOpts.thoughtSignature) != null ? String(partProviderOpts.thoughtSignature) : void 0;
481
+ if (contents.length > 0) {
482
+ const lastContent = contents[contents.length - 1];
483
+ if (lastContent.role === "model") {
484
+ lastContent.parts.push({
485
+ toolResponse: {
486
+ toolType: serverToolType,
487
+ response: part.output.type === "json" ? part.output.value : {},
488
+ id: serverToolCallId
489
+ },
490
+ thoughtSignature: serverThoughtSignature
491
+ });
492
+ continue;
493
+ }
494
+ }
495
+ }
299
496
  const output = part.output;
300
497
  if (output.type === "content") {
301
- for (const contentPart of output.value) {
302
- switch (contentPart.type) {
303
- case "text":
304
- parts.push({
305
- functionResponse: {
306
- name: part.toolName,
307
- response: {
308
- name: part.toolName,
309
- content: contentPart.text
310
- }
311
- }
312
- });
313
- break;
314
- case "image-data":
315
- parts.push(
316
- {
317
- inlineData: {
318
- mimeType: contentPart.mediaType,
319
- data: contentPart.data
320
- }
321
- },
322
- {
323
- text: "Tool executed successfully and returned this image as a response"
324
- }
325
- );
326
- break;
327
- default:
328
- parts.push({ text: JSON.stringify(contentPart) });
329
- break;
330
- }
498
+ if (supportsFunctionResponseParts) {
499
+ appendToolResultParts(parts, part.toolName, output.value);
500
+ } else {
501
+ appendLegacyToolResultParts(parts, part.toolName, output.value);
331
502
  }
332
503
  } else {
333
504
  parts.push({
@@ -335,7 +506,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
335
506
  name: part.toolName,
336
507
  response: {
337
508
  name: part.toolName,
338
- content: output.type === "execution-denied" ? (_c = output.reason) != null ? _c : "Tool execution denied." : output.value
509
+ content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool execution denied." : output.value
339
510
  }
340
511
  }
341
512
  });
@@ -365,43 +536,47 @@ function getModelPath(modelId) {
365
536
  }
366
537
 
367
538
  // src/google-error.ts
368
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
369
- var import_v4 = require("zod/v4");
370
- var googleErrorDataSchema = (0, import_provider_utils2.lazySchema)(
371
- () => (0, import_provider_utils2.zodSchema)(
372
- import_v4.z.object({
373
- error: import_v4.z.object({
374
- code: import_v4.z.number().nullable(),
375
- message: import_v4.z.string(),
376
- status: import_v4.z.string()
539
+ import {
540
+ createJsonErrorResponseHandler,
541
+ lazySchema,
542
+ zodSchema
543
+ } from "@ai-sdk/provider-utils";
544
+ import { z } from "zod/v4";
545
+ var googleErrorDataSchema = lazySchema(
546
+ () => zodSchema(
547
+ z.object({
548
+ error: z.object({
549
+ code: z.number().nullable(),
550
+ message: z.string(),
551
+ status: z.string()
377
552
  })
378
553
  })
379
554
  )
380
555
  );
381
- var googleFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
556
+ var googleFailedResponseHandler = createJsonErrorResponseHandler({
382
557
  errorSchema: googleErrorDataSchema,
383
558
  errorToMessage: (data) => data.error.message
384
559
  });
385
560
 
386
561
  // src/google-generative-ai-options.ts
387
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
388
- var import_v42 = require("zod/v4");
389
- var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
390
- () => (0, import_provider_utils3.zodSchema)(
391
- import_v42.z.object({
392
- responseModalities: import_v42.z.array(import_v42.z.enum(["TEXT", "IMAGE"])).optional(),
393
- thinkingConfig: import_v42.z.object({
394
- thinkingBudget: import_v42.z.number().optional(),
395
- includeThoughts: import_v42.z.boolean().optional(),
562
+ import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
563
+ import { z as z2 } from "zod/v4";
564
+ var googleLanguageModelOptions = lazySchema2(
565
+ () => zodSchema2(
566
+ z2.object({
567
+ responseModalities: z2.array(z2.enum(["TEXT", "IMAGE"])).optional(),
568
+ thinkingConfig: z2.object({
569
+ thinkingBudget: z2.number().optional(),
570
+ includeThoughts: z2.boolean().optional(),
396
571
  // https://ai.google.dev/gemini-api/docs/gemini-3?thinking=high#thinking_level
397
- thinkingLevel: import_v42.z.enum(["minimal", "low", "medium", "high"]).optional()
572
+ thinkingLevel: z2.enum(["minimal", "low", "medium", "high"]).optional()
398
573
  }).optional(),
399
574
  /**
400
575
  * Optional.
401
576
  * The name of the cached content used as context to serve the prediction.
402
577
  * Format: cachedContents/{cachedContent}
403
578
  */
404
- cachedContent: import_v42.z.string().optional(),
579
+ cachedContent: z2.string().optional(),
405
580
  /**
406
581
  * Optional. Enable structured output. Default is true.
407
582
  *
@@ -410,13 +585,13 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
410
585
  * Google Generative AI uses. You can use this to disable
411
586
  * structured outputs if you need to.
412
587
  */
413
- structuredOutputs: import_v42.z.boolean().optional(),
588
+ structuredOutputs: z2.boolean().optional(),
414
589
  /**
415
590
  * Optional. A list of unique safety settings for blocking unsafe content.
416
591
  */
417
- safetySettings: import_v42.z.array(
418
- import_v42.z.object({
419
- category: import_v42.z.enum([
592
+ safetySettings: z2.array(
593
+ z2.object({
594
+ category: z2.enum([
420
595
  "HARM_CATEGORY_UNSPECIFIED",
421
596
  "HARM_CATEGORY_HATE_SPEECH",
422
597
  "HARM_CATEGORY_DANGEROUS_CONTENT",
@@ -424,7 +599,7 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
424
599
  "HARM_CATEGORY_SEXUALLY_EXPLICIT",
425
600
  "HARM_CATEGORY_CIVIC_INTEGRITY"
426
601
  ]),
427
- threshold: import_v42.z.enum([
602
+ threshold: z2.enum([
428
603
  "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
429
604
  "BLOCK_LOW_AND_ABOVE",
430
605
  "BLOCK_MEDIUM_AND_ABOVE",
@@ -434,7 +609,7 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
434
609
  ])
435
610
  })
436
611
  ).optional(),
437
- threshold: import_v42.z.enum([
612
+ threshold: z2.enum([
438
613
  "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
439
614
  "BLOCK_LOW_AND_ABOVE",
440
615
  "BLOCK_MEDIUM_AND_ABOVE",
@@ -447,19 +622,19 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
447
622
  *
448
623
  * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
449
624
  */
450
- audioTimestamp: import_v42.z.boolean().optional(),
625
+ audioTimestamp: z2.boolean().optional(),
451
626
  /**
452
627
  * Optional. Defines labels used in billing reports. Available on Vertex AI only.
453
628
  *
454
629
  * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls
455
630
  */
456
- labels: import_v42.z.record(import_v42.z.string(), import_v42.z.string()).optional(),
631
+ labels: z2.record(z2.string(), z2.string()).optional(),
457
632
  /**
458
633
  * Optional. If specified, the media resolution specified will be used.
459
634
  *
460
635
  * https://ai.google.dev/api/generate-content#MediaResolution
461
636
  */
462
- mediaResolution: import_v42.z.enum([
637
+ mediaResolution: z2.enum([
463
638
  "MEDIA_RESOLUTION_UNSPECIFIED",
464
639
  "MEDIA_RESOLUTION_LOW",
465
640
  "MEDIA_RESOLUTION_MEDIUM",
@@ -470,8 +645,8 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
470
645
  *
471
646
  * https://ai.google.dev/gemini-api/docs/image-generation#aspect_ratios
472
647
  */
473
- imageConfig: import_v42.z.object({
474
- aspectRatio: import_v42.z.enum([
648
+ imageConfig: z2.object({
649
+ aspectRatio: z2.enum([
475
650
  "1:1",
476
651
  "2:3",
477
652
  "3:2",
@@ -487,7 +662,7 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
487
662
  "1:4",
488
663
  "4:1"
489
664
  ]).optional(),
490
- imageSize: import_v42.z.enum(["1K", "2K", "4K", "512"]).optional()
665
+ imageSize: z2.enum(["1K", "2K", "4K", "512"]).optional()
491
666
  }).optional(),
492
667
  /**
493
668
  * Optional. Configuration for grounding retrieval.
@@ -495,24 +670,46 @@ var googleLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
495
670
  *
496
671
  * https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-with-google-maps
497
672
  */
498
- retrievalConfig: import_v42.z.object({
499
- latLng: import_v42.z.object({
500
- latitude: import_v42.z.number(),
501
- longitude: import_v42.z.number()
673
+ retrievalConfig: z2.object({
674
+ latLng: z2.object({
675
+ latitude: z2.number(),
676
+ longitude: z2.number()
502
677
  }).optional()
503
- }).optional()
678
+ }).optional(),
679
+ /**
680
+ * Optional. When set to true, function call arguments will be streamed
681
+ * incrementally via partialArgs in streaming responses. Only supported
682
+ * on the Vertex AI API (not the Gemini API) and only for Gemini 3+
683
+ * models.
684
+ *
685
+ * @default false
686
+ *
687
+ * https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc
688
+ */
689
+ streamFunctionCallArguments: z2.boolean().optional(),
690
+ /**
691
+ * Optional. The service tier to use for the request.
692
+ */
693
+ serviceTier: z2.enum(["standard", "flex", "priority"]).optional()
504
694
  })
505
695
  )
506
696
  );
697
+ var VertexServiceTierMap = {
698
+ standard: "SERVICE_TIER_STANDARD",
699
+ flex: "SERVICE_TIER_FLEX",
700
+ priority: "SERVICE_TIER_PRIORITY"
701
+ };
507
702
 
508
703
  // src/google-prepare-tools.ts
509
- var import_provider2 = require("@ai-sdk/provider");
704
+ import {
705
+ UnsupportedFunctionalityError as UnsupportedFunctionalityError2
706
+ } from "@ai-sdk/provider";
510
707
  function prepareTools({
511
708
  tools,
512
709
  toolChoice,
513
710
  modelId
514
711
  }) {
515
- var _a;
712
+ var _a, _b;
516
713
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
517
714
  const toolWarnings = [];
518
715
  const isLatest = [
@@ -521,13 +718,14 @@ function prepareTools({
521
718
  "gemini-pro-latest"
522
719
  ].some((id) => id === modelId);
523
720
  const isGemini2orNewer = modelId.includes("gemini-2") || modelId.includes("gemini-3") || modelId.includes("nano-banana") || isLatest;
721
+ const isGemini3orNewer = modelId.includes("gemini-3");
524
722
  const supportsFileSearch = modelId.includes("gemini-2.5") || modelId.includes("gemini-3");
525
723
  if (tools == null) {
526
724
  return { tools: void 0, toolConfig: void 0, toolWarnings };
527
725
  }
528
726
  const hasFunctionTools = tools.some((tool) => tool.type === "function");
529
727
  const hasProviderTools = tools.some((tool) => tool.type === "provider");
530
- if (hasFunctionTools && hasProviderTools) {
728
+ if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) {
531
729
  toolWarnings.push({
532
730
  type: "unsupported",
533
731
  feature: `combination of function and provider-defined tools`
@@ -578,7 +776,7 @@ function prepareTools({
578
776
  toolWarnings.push({
579
777
  type: "unsupported",
580
778
  feature: `provider-defined tool ${tool.id}`,
581
- details: "The code execution tools is not supported with other Gemini models than Gemini 2."
779
+ details: "The code execution tool is not supported with other Gemini models than Gemini 2."
582
780
  });
583
781
  }
584
782
  break;
@@ -632,6 +830,45 @@ function prepareTools({
632
830
  break;
633
831
  }
634
832
  });
833
+ if (hasFunctionTools && isGemini3orNewer && googleTools2.length > 0) {
834
+ const functionDeclarations2 = [];
835
+ for (const tool of tools) {
836
+ if (tool.type === "function") {
837
+ functionDeclarations2.push({
838
+ name: tool.name,
839
+ description: (_a = tool.description) != null ? _a : "",
840
+ parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
841
+ });
842
+ }
843
+ }
844
+ const combinedToolConfig = {
845
+ functionCallingConfig: { mode: "VALIDATED" },
846
+ includeServerSideToolInvocations: true
847
+ };
848
+ if (toolChoice != null) {
849
+ switch (toolChoice.type) {
850
+ case "auto":
851
+ break;
852
+ case "none":
853
+ combinedToolConfig.functionCallingConfig = { mode: "NONE" };
854
+ break;
855
+ case "required":
856
+ combinedToolConfig.functionCallingConfig = { mode: "ANY" };
857
+ break;
858
+ case "tool":
859
+ combinedToolConfig.functionCallingConfig = {
860
+ mode: "ANY",
861
+ allowedFunctionNames: [toolChoice.toolName]
862
+ };
863
+ break;
864
+ }
865
+ }
866
+ return {
867
+ tools: [...googleTools2, { functionDeclarations: functionDeclarations2 }],
868
+ toolConfig: combinedToolConfig,
869
+ toolWarnings
870
+ };
871
+ }
635
872
  return {
636
873
  tools: googleTools2.length > 0 ? googleTools2 : void 0,
637
874
  toolConfig: void 0,
@@ -645,7 +882,7 @@ function prepareTools({
645
882
  case "function":
646
883
  functionDeclarations.push({
647
884
  name: tool.name,
648
- description: (_a = tool.description) != null ? _a : "",
885
+ description: (_b = tool.description) != null ? _b : "",
649
886
  parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
650
887
  });
651
888
  if (tool.strict === true) {
@@ -708,13 +945,236 @@ function prepareTools({
708
945
  };
709
946
  default: {
710
947
  const _exhaustiveCheck = type;
711
- throw new import_provider2.UnsupportedFunctionalityError({
948
+ throw new UnsupportedFunctionalityError2({
712
949
  functionality: `tool choice type: ${_exhaustiveCheck}`
713
950
  });
714
951
  }
715
952
  }
716
953
  }
717
954
 
955
+ // src/google-json-accumulator.ts
956
+ var GoogleJSONAccumulator = class {
957
+ constructor() {
958
+ this.accumulatedArgs = {};
959
+ this.jsonText = "";
960
+ /**
961
+ * Stack representing the currently "open" containers in the JSON output.
962
+ * Entry 0 is always the root `{` object once the first value is written.
963
+ */
964
+ this.pathStack = [];
965
+ /**
966
+ * Whether a string value is currently "open" (willContinue was true),
967
+ * meaning the closing quote has not yet been emitted.
968
+ */
969
+ this.stringOpen = false;
970
+ }
971
+ /**
972
+ * Input: [{jsonPath:"$.brightness",numberValue:50}]
973
+ * Output: { currentJSON:{brightness:50}, textDelta:'{"brightness":50' }
974
+ */
975
+ processPartialArgs(partialArgs) {
976
+ let delta = "";
977
+ for (const arg of partialArgs) {
978
+ const rawPath = arg.jsonPath.replace(/^\$\./, "");
979
+ if (!rawPath) continue;
980
+ const segments = parsePath(rawPath);
981
+ const existingValue = getNestedValue(this.accumulatedArgs, segments);
982
+ const isStringContinuation = arg.stringValue != null && existingValue !== void 0;
983
+ if (isStringContinuation) {
984
+ const escaped = JSON.stringify(arg.stringValue).slice(1, -1);
985
+ setNestedValue(
986
+ this.accumulatedArgs,
987
+ segments,
988
+ existingValue + arg.stringValue
989
+ );
990
+ delta += escaped;
991
+ continue;
992
+ }
993
+ const resolved = resolvePartialArgValue(arg);
994
+ if (resolved == null) continue;
995
+ setNestedValue(this.accumulatedArgs, segments, resolved.value);
996
+ delta += this.emitNavigationTo(segments, arg, resolved.json);
997
+ }
998
+ this.jsonText += delta;
999
+ return {
1000
+ currentJSON: this.accumulatedArgs,
1001
+ textDelta: delta
1002
+ };
1003
+ }
1004
+ /**
1005
+ * Input: jsonText='{"brightness":50', accumulatedArgs={brightness:50}
1006
+ * Output: { finalJSON:'{"brightness":50}', closingDelta:'}' }
1007
+ */
1008
+ finalize() {
1009
+ const finalArgs = JSON.stringify(this.accumulatedArgs);
1010
+ const closingDelta = finalArgs.slice(this.jsonText.length);
1011
+ return { finalJSON: finalArgs, closingDelta };
1012
+ }
1013
+ /**
1014
+ * Input: pathStack=[] (first call) or pathStack=[root,...] (subsequent calls)
1015
+ * Output: '{' (first call) or '' (subsequent calls)
1016
+ */
1017
+ ensureRoot() {
1018
+ if (this.pathStack.length === 0) {
1019
+ this.pathStack.push({ segment: "", isArray: false, childCount: 0 });
1020
+ return "{";
1021
+ }
1022
+ return "";
1023
+ }
1024
+ /**
1025
+ * Emits the JSON text fragment needed to navigate from the current open
1026
+ * path to the new leaf at `targetSegments`, then writes the value.
1027
+ *
1028
+ * Input: targetSegments=["recipe","name"], arg={jsonPath:"$.recipe.name",stringValue:"Lasagna"}, valueJson='"Lasagna"'
1029
+ * Output: '{"recipe":{"name":"Lasagna"'
1030
+ */
1031
+ emitNavigationTo(targetSegments, arg, valueJson) {
1032
+ let fragment = "";
1033
+ if (this.stringOpen) {
1034
+ fragment += '"';
1035
+ this.stringOpen = false;
1036
+ }
1037
+ fragment += this.ensureRoot();
1038
+ const targetContainerSegments = targetSegments.slice(0, -1);
1039
+ const leafSegment = targetSegments[targetSegments.length - 1];
1040
+ const commonDepth = this.findCommonStackDepth(targetContainerSegments);
1041
+ fragment += this.closeDownTo(commonDepth);
1042
+ fragment += this.openDownTo(targetContainerSegments, leafSegment);
1043
+ fragment += this.emitLeaf(leafSegment, arg, valueJson);
1044
+ return fragment;
1045
+ }
1046
+ /**
1047
+ * Returns the stack depth to preserve when navigating to a new target
1048
+ * container path. Always >= 1 (the root is never popped).
1049
+ *
1050
+ * Input: stack=[root,"recipe","ingredients",0], target=["recipe","ingredients",1]
1051
+ * Output: 3 (keep root+"recipe"+"ingredients")
1052
+ */
1053
+ findCommonStackDepth(targetContainer) {
1054
+ const maxDepth = Math.min(
1055
+ this.pathStack.length - 1,
1056
+ targetContainer.length
1057
+ );
1058
+ let common = 0;
1059
+ for (let i = 0; i < maxDepth; i++) {
1060
+ if (this.pathStack[i + 1].segment === targetContainer[i]) {
1061
+ common++;
1062
+ } else {
1063
+ break;
1064
+ }
1065
+ }
1066
+ return common + 1;
1067
+ }
1068
+ /**
1069
+ * Closes containers from the current stack depth back down to `targetDepth`.
1070
+ *
1071
+ * Input: this.pathStack=[root,"recipe","ingredients",0], targetDepth=3
1072
+ * Output: '}'
1073
+ */
1074
+ closeDownTo(targetDepth) {
1075
+ let fragment = "";
1076
+ while (this.pathStack.length > targetDepth) {
1077
+ const entry = this.pathStack.pop();
1078
+ fragment += entry.isArray ? "]" : "}";
1079
+ }
1080
+ return fragment;
1081
+ }
1082
+ /**
1083
+ * Opens containers from the current stack depth down to the full target
1084
+ * container path, emitting opening `{`, `[`, keys, and commas as needed.
1085
+ * `leafSegment` is used to determine if the innermost container is an array.
1086
+ *
1087
+ * Input: this.pathStack=[root], targetContainer=["recipe","ingredients"], leafSegment=0
1088
+ * Output: '"recipe":{"ingredients":['
1089
+ */
1090
+ openDownTo(targetContainer, leafSegment) {
1091
+ let fragment = "";
1092
+ const startIdx = this.pathStack.length - 1;
1093
+ for (let i = startIdx; i < targetContainer.length; i++) {
1094
+ const seg = targetContainer[i];
1095
+ const parentEntry = this.pathStack[this.pathStack.length - 1];
1096
+ if (parentEntry.childCount > 0) {
1097
+ fragment += ",";
1098
+ }
1099
+ parentEntry.childCount++;
1100
+ if (typeof seg === "string") {
1101
+ fragment += `${JSON.stringify(seg)}:`;
1102
+ }
1103
+ const childSeg = i + 1 < targetContainer.length ? targetContainer[i + 1] : leafSegment;
1104
+ const isArray = typeof childSeg === "number";
1105
+ fragment += isArray ? "[" : "{";
1106
+ this.pathStack.push({ segment: seg, isArray, childCount: 0 });
1107
+ }
1108
+ return fragment;
1109
+ }
1110
+ /**
1111
+ * Emits the comma, key, and value for a leaf entry in the current container.
1112
+ *
1113
+ * Input: leafSegment="name", arg={stringValue:"Lasagna"}, valueJson='"Lasagna"'
1114
+ * Output: '"name":"Lasagna"' (or ',"name":"Lasagna"' if container.childCount > 0)
1115
+ */
1116
+ emitLeaf(leafSegment, arg, valueJson) {
1117
+ let fragment = "";
1118
+ const container = this.pathStack[this.pathStack.length - 1];
1119
+ if (container.childCount > 0) {
1120
+ fragment += ",";
1121
+ }
1122
+ container.childCount++;
1123
+ if (typeof leafSegment === "string") {
1124
+ fragment += `${JSON.stringify(leafSegment)}:`;
1125
+ }
1126
+ if (arg.stringValue != null && arg.willContinue) {
1127
+ fragment += valueJson.slice(0, -1);
1128
+ this.stringOpen = true;
1129
+ } else {
1130
+ fragment += valueJson;
1131
+ }
1132
+ return fragment;
1133
+ }
1134
+ };
1135
+ function parsePath(rawPath) {
1136
+ const segments = [];
1137
+ for (const part of rawPath.split(".")) {
1138
+ const bracketIdx = part.indexOf("[");
1139
+ if (bracketIdx === -1) {
1140
+ segments.push(part);
1141
+ } else {
1142
+ if (bracketIdx > 0) segments.push(part.slice(0, bracketIdx));
1143
+ for (const m of part.matchAll(/\[(\d+)\]/g)) {
1144
+ segments.push(parseInt(m[1], 10));
1145
+ }
1146
+ }
1147
+ }
1148
+ return segments;
1149
+ }
1150
+ function getNestedValue(obj, segments) {
1151
+ let current = obj;
1152
+ for (const seg of segments) {
1153
+ if (current == null || typeof current !== "object") return void 0;
1154
+ current = current[seg];
1155
+ }
1156
+ return current;
1157
+ }
1158
+ function setNestedValue(obj, segments, value) {
1159
+ let current = obj;
1160
+ for (let i = 0; i < segments.length - 1; i++) {
1161
+ const seg = segments[i];
1162
+ const nextSeg = segments[i + 1];
1163
+ if (current[seg] == null) {
1164
+ current[seg] = typeof nextSeg === "number" ? [] : {};
1165
+ }
1166
+ current = current[seg];
1167
+ }
1168
+ current[segments[segments.length - 1]] = value;
1169
+ }
1170
+ function resolvePartialArgValue(arg) {
1171
+ var _a, _b;
1172
+ const value = (_b = (_a = arg.stringValue) != null ? _a : arg.numberValue) != null ? _b : arg.boolValue;
1173
+ if (value != null) return { value, json: JSON.stringify(value) };
1174
+ if ("nullValue" in arg) return { value: null, json: "null" };
1175
+ return void 0;
1176
+ }
1177
+
718
1178
  // src/map-google-generative-ai-finish-reason.ts
719
1179
  function mapGoogleGenerativeAIFinishReason({
720
1180
  finishReason,
@@ -742,13 +1202,22 @@ function mapGoogleGenerativeAIFinishReason({
742
1202
  }
743
1203
 
744
1204
  // src/google-generative-ai-language-model.ts
745
- var GoogleGenerativeAILanguageModel = class {
1205
+ var GoogleGenerativeAILanguageModel = class _GoogleGenerativeAILanguageModel {
746
1206
  constructor(modelId, config) {
747
- this.specificationVersion = "v3";
1207
+ this.specificationVersion = "v4";
748
1208
  var _a;
749
1209
  this.modelId = modelId;
750
1210
  this.config = config;
751
- this.generateId = (_a = config.generateId) != null ? _a : import_provider_utils4.generateId;
1211
+ this.generateId = (_a = config.generateId) != null ? _a : generateId;
1212
+ }
1213
+ static [WORKFLOW_SERIALIZE](model) {
1214
+ return serializeModelOptions({
1215
+ modelId: model.modelId,
1216
+ config: model.config
1217
+ });
1218
+ }
1219
+ static [WORKFLOW_DESERIALIZE](options) {
1220
+ return new _GoogleGenerativeAILanguageModel(options.modelId, options.config);
752
1221
  }
753
1222
  get provider() {
754
1223
  return this.config.provider;
@@ -770,35 +1239,52 @@ var GoogleGenerativeAILanguageModel = class {
770
1239
  seed,
771
1240
  tools,
772
1241
  toolChoice,
1242
+ reasoning,
773
1243
  providerOptions
774
- }) {
775
- var _a;
1244
+ }, { isStreaming = false } = {}) {
1245
+ var _a, _b;
776
1246
  const warnings = [];
777
1247
  const providerOptionsName = this.config.provider.includes("vertex") ? "vertex" : "google";
778
- let googleOptions = await (0, import_provider_utils4.parseProviderOptions)({
1248
+ let googleOptions = await parseProviderOptions({
779
1249
  provider: providerOptionsName,
780
1250
  providerOptions,
781
1251
  schema: googleLanguageModelOptions
782
1252
  });
783
1253
  if (googleOptions == null && providerOptionsName !== "google") {
784
- googleOptions = await (0, import_provider_utils4.parseProviderOptions)({
1254
+ googleOptions = await parseProviderOptions({
785
1255
  provider: "google",
786
1256
  providerOptions,
787
1257
  schema: googleLanguageModelOptions
788
1258
  });
789
1259
  }
1260
+ const isVertexProvider = this.config.provider.startsWith("google.vertex.");
790
1261
  if ((tools == null ? void 0 : tools.some(
791
1262
  (tool) => tool.type === "provider" && tool.id === "google.vertex_rag_store"
792
- )) && !this.config.provider.startsWith("google.vertex.")) {
1263
+ )) && !isVertexProvider) {
793
1264
  warnings.push({
794
1265
  type: "other",
795
1266
  message: `The 'vertex_rag_store' tool is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${this.config.provider}).`
796
1267
  });
797
1268
  }
1269
+ if ((googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) && !isVertexProvider) {
1270
+ warnings.push({
1271
+ type: "other",
1272
+ message: `'streamFunctionCallArguments' is only supported on the Vertex AI API and will be ignored with the current Google provider (${this.config.provider}). See https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc`
1273
+ });
1274
+ }
1275
+ let sanitizedServiceTier = googleOptions == null ? void 0 : googleOptions.serviceTier;
1276
+ if ((googleOptions == null ? void 0 : googleOptions.serviceTier) && isVertexProvider) {
1277
+ sanitizedServiceTier = VertexServiceTierMap[googleOptions.serviceTier];
1278
+ }
798
1279
  const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
1280
+ const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
799
1281
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
800
1282
  prompt,
801
- { isGemmaModel, providerOptionsName }
1283
+ {
1284
+ isGemmaModel,
1285
+ providerOptionsName,
1286
+ supportsFunctionResponseParts
1287
+ }
802
1288
  );
803
1289
  const {
804
1290
  tools: googleTools2,
@@ -809,6 +1295,25 @@ var GoogleGenerativeAILanguageModel = class {
809
1295
  toolChoice,
810
1296
  modelId: this.modelId
811
1297
  });
1298
+ const resolvedThinking = resolveThinkingConfig({
1299
+ reasoning,
1300
+ modelId: this.modelId,
1301
+ warnings
1302
+ });
1303
+ const thinkingConfig = (googleOptions == null ? void 0 : googleOptions.thinkingConfig) || resolvedThinking ? { ...resolvedThinking, ...googleOptions == null ? void 0 : googleOptions.thinkingConfig } : void 0;
1304
+ const streamFunctionCallArguments = isStreaming && isVertexProvider ? (_a = googleOptions == null ? void 0 : googleOptions.streamFunctionCallArguments) != null ? _a : false : void 0;
1305
+ const toolConfig = googleToolConfig || streamFunctionCallArguments || (googleOptions == null ? void 0 : googleOptions.retrievalConfig) ? {
1306
+ ...googleToolConfig,
1307
+ ...streamFunctionCallArguments && {
1308
+ functionCallingConfig: {
1309
+ ...googleToolConfig == null ? void 0 : googleToolConfig.functionCallingConfig,
1310
+ streamFunctionCallArguments: true
1311
+ }
1312
+ },
1313
+ ...(googleOptions == null ? void 0 : googleOptions.retrievalConfig) && {
1314
+ retrievalConfig: googleOptions.retrievalConfig
1315
+ }
1316
+ } : void 0;
812
1317
  return {
813
1318
  args: {
814
1319
  generationConfig: {
@@ -826,13 +1331,13 @@ var GoogleGenerativeAILanguageModel = class {
826
1331
  responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
827
1332
  // so this is needed as an escape hatch:
828
1333
  // TODO convert into provider option
829
- ((_a = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _a : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
1334
+ ((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
830
1335
  ...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
831
1336
  audioTimestamp: googleOptions.audioTimestamp
832
1337
  },
833
1338
  // provider options:
834
1339
  responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
835
- thinkingConfig: googleOptions == null ? void 0 : googleOptions.thinkingConfig,
1340
+ thinkingConfig,
836
1341
  ...(googleOptions == null ? void 0 : googleOptions.mediaResolution) && {
837
1342
  mediaResolution: googleOptions.mediaResolution
838
1343
  },
@@ -844,36 +1349,34 @@ var GoogleGenerativeAILanguageModel = class {
844
1349
  systemInstruction: isGemmaModel ? void 0 : systemInstruction,
845
1350
  safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
846
1351
  tools: googleTools2,
847
- toolConfig: (googleOptions == null ? void 0 : googleOptions.retrievalConfig) ? {
848
- ...googleToolConfig,
849
- retrievalConfig: googleOptions.retrievalConfig
850
- } : googleToolConfig,
1352
+ toolConfig,
851
1353
  cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent,
852
- labels: googleOptions == null ? void 0 : googleOptions.labels
1354
+ labels: googleOptions == null ? void 0 : googleOptions.labels,
1355
+ serviceTier: sanitizedServiceTier
853
1356
  },
854
1357
  warnings: [...warnings, ...toolWarnings],
855
1358
  providerOptionsName
856
1359
  };
857
1360
  }
858
1361
  async doGenerate(options) {
859
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1362
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
860
1363
  const { args, warnings, providerOptionsName } = await this.getArgs(options);
861
- const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
862
- await (0, import_provider_utils4.resolve)(this.config.headers),
1364
+ const mergedHeaders = combineHeaders(
1365
+ this.config.headers ? await resolve(this.config.headers) : void 0,
863
1366
  options.headers
864
1367
  );
865
1368
  const {
866
1369
  responseHeaders,
867
1370
  value: response,
868
1371
  rawValue: rawResponse
869
- } = await (0, import_provider_utils4.postJsonToApi)({
1372
+ } = await postJsonToApi({
870
1373
  url: `${this.config.baseURL}/${getModelPath(
871
1374
  this.modelId
872
1375
  )}:generateContent`,
873
1376
  headers: mergedHeaders,
874
1377
  body: args,
875
1378
  failedResponseHandler: googleFailedResponseHandler,
876
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(responseSchema),
1379
+ successfulResponseHandler: createJsonResponseHandler(responseSchema),
877
1380
  abortSignal: options.abortSignal,
878
1381
  fetch: this.config.fetch
879
1382
  });
@@ -882,6 +1385,7 @@ var GoogleGenerativeAILanguageModel = class {
882
1385
  const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
883
1386
  const usageMetadata = response.usageMetadata;
884
1387
  let lastCodeExecutionToolCallId;
1388
+ let lastServerToolCallId;
885
1389
  for (const part of parts) {
886
1390
  if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
887
1391
  const toolCallId = this.config.generateId();
@@ -923,7 +1427,7 @@ var GoogleGenerativeAILanguageModel = class {
923
1427
  providerMetadata: thoughtSignatureMetadata
924
1428
  });
925
1429
  }
926
- } else if ("functionCall" in part) {
1430
+ } else if ("functionCall" in part && part.functionCall.name != null && part.functionCall.args != null) {
927
1431
  content.push({
928
1432
  type: "tool-call",
929
1433
  toolCallId: this.config.generateId(),
@@ -939,22 +1443,65 @@ var GoogleGenerativeAILanguageModel = class {
939
1443
  const hasThought = part.thought === true;
940
1444
  const hasThoughtSignature = !!part.thoughtSignature;
941
1445
  content.push({
942
- type: "file",
1446
+ type: hasThought ? "reasoning-file" : "file",
943
1447
  data: part.inlineData.data,
944
1448
  mediaType: part.inlineData.mimeType,
945
- providerMetadata: hasThought || hasThoughtSignature ? {
1449
+ providerMetadata: hasThoughtSignature ? {
946
1450
  [providerOptionsName]: {
947
- ...hasThought ? { thought: true } : {},
948
- ...hasThoughtSignature ? { thoughtSignature: part.thoughtSignature } : {}
1451
+ thoughtSignature: part.thoughtSignature
949
1452
  }
950
1453
  } : void 0
951
1454
  });
1455
+ } else if ("toolCall" in part && part.toolCall) {
1456
+ const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
1457
+ lastServerToolCallId = toolCallId;
1458
+ content.push({
1459
+ type: "tool-call",
1460
+ toolCallId,
1461
+ toolName: `server:${part.toolCall.toolType}`,
1462
+ input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
1463
+ providerExecuted: true,
1464
+ dynamic: true,
1465
+ providerMetadata: part.thoughtSignature ? {
1466
+ [providerOptionsName]: {
1467
+ thoughtSignature: part.thoughtSignature,
1468
+ serverToolCallId: toolCallId,
1469
+ serverToolType: part.toolCall.toolType
1470
+ }
1471
+ } : {
1472
+ [providerOptionsName]: {
1473
+ serverToolCallId: toolCallId,
1474
+ serverToolType: part.toolCall.toolType
1475
+ }
1476
+ }
1477
+ });
1478
+ } else if ("toolResponse" in part && part.toolResponse) {
1479
+ const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
1480
+ content.push({
1481
+ type: "tool-result",
1482
+ toolCallId: responseToolCallId,
1483
+ toolName: `server:${part.toolResponse.toolType}`,
1484
+ result: (_h = part.toolResponse.response) != null ? _h : {},
1485
+ providerMetadata: part.thoughtSignature ? {
1486
+ [providerOptionsName]: {
1487
+ thoughtSignature: part.thoughtSignature,
1488
+ serverToolCallId: responseToolCallId,
1489
+ serverToolType: part.toolResponse.toolType
1490
+ }
1491
+ } : {
1492
+ [providerOptionsName]: {
1493
+ serverToolCallId: responseToolCallId,
1494
+ serverToolType: part.toolResponse.toolType
1495
+ }
1496
+ }
1497
+ });
1498
+ lastServerToolCallId = void 0;
952
1499
  }
953
1500
  }
954
- const sources = (_e = extractSources({
1501
+ const sources = (_i = extractSources({
955
1502
  groundingMetadata: candidate.groundingMetadata,
956
1503
  generateId: this.config.generateId
957
- })) != null ? _e : [];
1504
+ })) != null ? _i : [];
958
1505
  for (const source of sources) {
959
1506
  content.push(source);
960
1507
  }
@@ -968,17 +1515,19 @@ var GoogleGenerativeAILanguageModel = class {
968
1515
  (part) => part.type === "tool-call" && !part.providerExecuted
969
1516
  )
970
1517
  }),
971
- raw: (_f = candidate.finishReason) != null ? _f : void 0
1518
+ raw: (_j = candidate.finishReason) != null ? _j : void 0
972
1519
  },
973
1520
  usage: convertGoogleGenerativeAIUsage(usageMetadata),
974
1521
  warnings,
975
1522
  providerMetadata: {
976
1523
  [providerOptionsName]: {
977
- promptFeedback: (_g = response.promptFeedback) != null ? _g : null,
978
- groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
979
- urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
980
- safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
981
- usageMetadata: usageMetadata != null ? usageMetadata : null
1524
+ promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
1525
+ groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
1526
+ urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
1527
+ safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
1528
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1529
+ finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
1530
+ serviceTier: (_p = response.serviceTier) != null ? _p : null
982
1531
  }
983
1532
  },
984
1533
  request: { body: args },
@@ -990,19 +1539,22 @@ var GoogleGenerativeAILanguageModel = class {
990
1539
  };
991
1540
  }
992
1541
  async doStream(options) {
993
- const { args, warnings, providerOptionsName } = await this.getArgs(options);
994
- const headers = (0, import_provider_utils4.combineHeaders)(
995
- await (0, import_provider_utils4.resolve)(this.config.headers),
1542
+ const { args, warnings, providerOptionsName } = await this.getArgs(
1543
+ options,
1544
+ { isStreaming: true }
1545
+ );
1546
+ const headers = combineHeaders(
1547
+ this.config.headers ? await resolve(this.config.headers) : void 0,
996
1548
  options.headers
997
1549
  );
998
- const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
1550
+ const { responseHeaders, value: response } = await postJsonToApi({
999
1551
  url: `${this.config.baseURL}/${getModelPath(
1000
1552
  this.modelId
1001
1553
  )}:streamGenerateContent?alt=sse`,
1002
1554
  headers,
1003
1555
  body: args,
1004
1556
  failedResponseHandler: googleFailedResponseHandler,
1005
- successfulResponseHandler: (0, import_provider_utils4.createEventSourceResponseHandler)(chunkSchema),
1557
+ successfulResponseHandler: createEventSourceResponseHandler(chunkSchema),
1006
1558
  abortSignal: options.abortSignal,
1007
1559
  fetch: this.config.fetch
1008
1560
  });
@@ -1014,6 +1566,7 @@ var GoogleGenerativeAILanguageModel = class {
1014
1566
  let providerMetadata = void 0;
1015
1567
  let lastGroundingMetadata = null;
1016
1568
  let lastUrlContextMetadata = null;
1569
+ let serviceTier = null;
1017
1570
  const generateId2 = this.config.generateId;
1018
1571
  let hasToolCalls = false;
1019
1572
  let currentTextBlockId = null;
@@ -1021,6 +1574,8 @@ var GoogleGenerativeAILanguageModel = class {
1021
1574
  let blockCounter = 0;
1022
1575
  const emittedSourceUrls = /* @__PURE__ */ new Set();
1023
1576
  let lastCodeExecutionToolCallId;
1577
+ let lastServerToolCallId;
1578
+ const activeStreamingToolCalls = [];
1024
1579
  return {
1025
1580
  stream: response.pipeThrough(
1026
1581
  new TransformStream({
@@ -1028,7 +1583,7 @@ var GoogleGenerativeAILanguageModel = class {
1028
1583
  controller.enqueue({ type: "stream-start", warnings });
1029
1584
  },
1030
1585
  transform(chunk, controller) {
1031
- var _a, _b, _c, _d, _e, _f;
1586
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1032
1587
  if (options.includeRawChunks) {
1033
1588
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1034
1589
  }
@@ -1041,6 +1596,9 @@ var GoogleGenerativeAILanguageModel = class {
1041
1596
  if (usageMetadata != null) {
1042
1597
  usage = usageMetadata;
1043
1598
  }
1599
+ if (value.serviceTier != null) {
1600
+ serviceTier = value.serviceTier;
1601
+ }
1044
1602
  const candidate = (_a = value.candidates) == null ? void 0 : _a[0];
1045
1603
  if (candidate == null) {
1046
1604
  return;
@@ -1168,50 +1726,159 @@ var GoogleGenerativeAILanguageModel = class {
1168
1726
  }
1169
1727
  const hasThought = part.thought === true;
1170
1728
  const hasThoughtSignature = !!part.thoughtSignature;
1171
- const fileMeta = hasThought || hasThoughtSignature ? {
1729
+ const fileMeta = hasThoughtSignature ? {
1172
1730
  [providerOptionsName]: {
1173
- ...hasThought ? { thought: true } : {},
1174
- ...hasThoughtSignature ? { thoughtSignature: part.thoughtSignature } : {}
1731
+ thoughtSignature: part.thoughtSignature
1175
1732
  }
1176
1733
  } : void 0;
1177
1734
  controller.enqueue({
1178
- type: "file",
1735
+ type: hasThought ? "reasoning-file" : "file",
1179
1736
  mediaType: part.inlineData.mimeType,
1180
1737
  data: part.inlineData.data,
1181
1738
  providerMetadata: fileMeta
1182
1739
  });
1740
+ } else if ("toolCall" in part && part.toolCall) {
1741
+ const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId2();
1742
+ lastServerToolCallId = toolCallId;
1743
+ const serverMeta = {
1744
+ [providerOptionsName]: {
1745
+ ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
1746
+ serverToolCallId: toolCallId,
1747
+ serverToolType: part.toolCall.toolType
1748
+ }
1749
+ };
1750
+ controller.enqueue({
1751
+ type: "tool-call",
1752
+ toolCallId,
1753
+ toolName: `server:${part.toolCall.toolType}`,
1754
+ input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
1755
+ providerExecuted: true,
1756
+ dynamic: true,
1757
+ providerMetadata: serverMeta
1758
+ });
1759
+ } else if ("toolResponse" in part && part.toolResponse) {
1760
+ const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId2();
1761
+ const serverMeta = {
1762
+ [providerOptionsName]: {
1763
+ ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
1764
+ serverToolCallId: responseToolCallId,
1765
+ serverToolType: part.toolResponse.toolType
1766
+ }
1767
+ };
1768
+ controller.enqueue({
1769
+ type: "tool-result",
1770
+ toolCallId: responseToolCallId,
1771
+ toolName: `server:${part.toolResponse.toolType}`,
1772
+ result: (_h = part.toolResponse.response) != null ? _h : {},
1773
+ providerMetadata: serverMeta
1774
+ });
1775
+ lastServerToolCallId = void 0;
1183
1776
  }
1184
1777
  }
1185
- const toolCallDeltas = getToolCallsFromParts({
1186
- parts: content.parts,
1187
- generateId: generateId2,
1188
- providerOptionsName
1189
- });
1190
- if (toolCallDeltas != null) {
1191
- for (const toolCall of toolCallDeltas) {
1778
+ for (const part of parts) {
1779
+ if (!("functionCall" in part)) continue;
1780
+ const providerMeta = part.thoughtSignature ? {
1781
+ [providerOptionsName]: {
1782
+ thoughtSignature: part.thoughtSignature
1783
+ }
1784
+ } : void 0;
1785
+ const isStreamingChunk = part.functionCall.partialArgs != null || part.functionCall.name != null && part.functionCall.willContinue === true;
1786
+ const isTerminalChunk = part.functionCall.name == null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue == null;
1787
+ const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
1788
+ if (isStreamingChunk) {
1789
+ if (part.functionCall.name != null && part.functionCall.willContinue === true) {
1790
+ const toolCallId = generateId2();
1791
+ const accumulator = new GoogleJSONAccumulator();
1792
+ activeStreamingToolCalls.push({
1793
+ toolCallId,
1794
+ toolName: part.functionCall.name,
1795
+ accumulator,
1796
+ providerMetadata: providerMeta
1797
+ });
1798
+ controller.enqueue({
1799
+ type: "tool-input-start",
1800
+ id: toolCallId,
1801
+ toolName: part.functionCall.name,
1802
+ providerMetadata: providerMeta
1803
+ });
1804
+ if (part.functionCall.partialArgs != null) {
1805
+ const { textDelta } = accumulator.processPartialArgs(
1806
+ part.functionCall.partialArgs
1807
+ );
1808
+ if (textDelta.length > 0) {
1809
+ controller.enqueue({
1810
+ type: "tool-input-delta",
1811
+ id: toolCallId,
1812
+ delta: textDelta,
1813
+ providerMetadata: providerMeta
1814
+ });
1815
+ }
1816
+ }
1817
+ } else if (part.functionCall.partialArgs != null && activeStreamingToolCalls.length > 0) {
1818
+ const active = activeStreamingToolCalls[activeStreamingToolCalls.length - 1];
1819
+ const { textDelta } = active.accumulator.processPartialArgs(
1820
+ part.functionCall.partialArgs
1821
+ );
1822
+ if (textDelta.length > 0) {
1823
+ controller.enqueue({
1824
+ type: "tool-input-delta",
1825
+ id: active.toolCallId,
1826
+ delta: textDelta,
1827
+ providerMetadata: providerMeta
1828
+ });
1829
+ }
1830
+ }
1831
+ } else if (isTerminalChunk && activeStreamingToolCalls.length > 0) {
1832
+ const active = activeStreamingToolCalls.pop();
1833
+ const { finalJSON, closingDelta } = active.accumulator.finalize();
1834
+ if (closingDelta.length > 0) {
1835
+ controller.enqueue({
1836
+ type: "tool-input-delta",
1837
+ id: active.toolCallId,
1838
+ delta: closingDelta,
1839
+ providerMetadata: active.providerMetadata
1840
+ });
1841
+ }
1842
+ controller.enqueue({
1843
+ type: "tool-input-end",
1844
+ id: active.toolCallId,
1845
+ providerMetadata: active.providerMetadata
1846
+ });
1847
+ controller.enqueue({
1848
+ type: "tool-call",
1849
+ toolCallId: active.toolCallId,
1850
+ toolName: active.toolName,
1851
+ input: finalJSON,
1852
+ providerMetadata: active.providerMetadata
1853
+ });
1854
+ hasToolCalls = true;
1855
+ } else if (isCompleteCall) {
1856
+ const toolCallId = generateId2();
1857
+ const toolName = part.functionCall.name;
1858
+ const args2 = typeof part.functionCall.args === "string" ? part.functionCall.args : JSON.stringify((_i = part.functionCall.args) != null ? _i : {});
1192
1859
  controller.enqueue({
1193
1860
  type: "tool-input-start",
1194
- id: toolCall.toolCallId,
1195
- toolName: toolCall.toolName,
1196
- providerMetadata: toolCall.providerMetadata
1861
+ id: toolCallId,
1862
+ toolName,
1863
+ providerMetadata: providerMeta
1197
1864
  });
1198
1865
  controller.enqueue({
1199
1866
  type: "tool-input-delta",
1200
- id: toolCall.toolCallId,
1201
- delta: toolCall.args,
1202
- providerMetadata: toolCall.providerMetadata
1867
+ id: toolCallId,
1868
+ delta: args2,
1869
+ providerMetadata: providerMeta
1203
1870
  });
1204
1871
  controller.enqueue({
1205
1872
  type: "tool-input-end",
1206
- id: toolCall.toolCallId,
1207
- providerMetadata: toolCall.providerMetadata
1873
+ id: toolCallId,
1874
+ providerMetadata: providerMeta
1208
1875
  });
1209
1876
  controller.enqueue({
1210
1877
  type: "tool-call",
1211
- toolCallId: toolCall.toolCallId,
1212
- toolName: toolCall.toolName,
1213
- input: toolCall.args,
1214
- providerMetadata: toolCall.providerMetadata
1878
+ toolCallId,
1879
+ toolName,
1880
+ input: args2,
1881
+ providerMetadata: providerMeta
1215
1882
  });
1216
1883
  hasToolCalls = true;
1217
1884
  }
@@ -1227,15 +1894,15 @@ var GoogleGenerativeAILanguageModel = class {
1227
1894
  };
1228
1895
  providerMetadata = {
1229
1896
  [providerOptionsName]: {
1230
- promptFeedback: (_e = value.promptFeedback) != null ? _e : null,
1897
+ promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
1231
1898
  groundingMetadata: lastGroundingMetadata,
1232
1899
  urlContextMetadata: lastUrlContextMetadata,
1233
- safetyRatings: (_f = candidate.safetyRatings) != null ? _f : null
1900
+ safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
1901
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1902
+ finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
1903
+ serviceTier
1234
1904
  }
1235
1905
  };
1236
- if (usageMetadata != null) {
1237
- providerMetadata[providerOptionsName].usageMetadata = usageMetadata;
1238
- }
1239
1906
  }
1240
1907
  },
1241
1908
  flush(controller) {
@@ -1265,25 +1932,74 @@ var GoogleGenerativeAILanguageModel = class {
1265
1932
  };
1266
1933
  }
1267
1934
  };
1268
- function getToolCallsFromParts({
1269
- parts,
1270
- generateId: generateId2,
1271
- providerOptionsName
1935
+ function isGemini3Model(modelId) {
1936
+ return /gemini-3[\.\-]/i.test(modelId) || /gemini-3$/i.test(modelId);
1937
+ }
1938
+ function getMaxOutputTokensForGemini25Model() {
1939
+ return 65536;
1940
+ }
1941
+ function getMaxThinkingTokensForGemini25Model(modelId) {
1942
+ const id = modelId.toLowerCase();
1943
+ if (id.includes("2.5-pro") || id.includes("gemini-3-pro-image")) {
1944
+ return 32768;
1945
+ }
1946
+ return 24576;
1947
+ }
1948
+ function resolveThinkingConfig({
1949
+ reasoning,
1950
+ modelId,
1951
+ warnings
1272
1952
  }) {
1273
- const functionCallParts = parts == null ? void 0 : parts.filter(
1274
- (part) => "functionCall" in part
1275
- );
1276
- return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
1277
- type: "tool-call",
1278
- toolCallId: generateId2(),
1279
- toolName: part.functionCall.name,
1280
- args: JSON.stringify(part.functionCall.args),
1281
- providerMetadata: part.thoughtSignature ? {
1282
- [providerOptionsName]: {
1283
- thoughtSignature: part.thoughtSignature
1284
- }
1285
- } : void 0
1286
- }));
1953
+ if (!isCustomReasoning(reasoning)) {
1954
+ return void 0;
1955
+ }
1956
+ if (isGemini3Model(modelId) && !modelId.includes("gemini-3-pro-image")) {
1957
+ return resolveGemini3ThinkingConfig({ reasoning, warnings });
1958
+ }
1959
+ return resolveGemini25ThinkingConfig({ reasoning, modelId, warnings });
1960
+ }
1961
+ function resolveGemini3ThinkingConfig({
1962
+ reasoning,
1963
+ warnings
1964
+ }) {
1965
+ if (reasoning === "none") {
1966
+ return { thinkingLevel: "minimal" };
1967
+ }
1968
+ const thinkingLevel = mapReasoningToProviderEffort({
1969
+ reasoning,
1970
+ effortMap: {
1971
+ minimal: "minimal",
1972
+ low: "low",
1973
+ medium: "medium",
1974
+ high: "high",
1975
+ xhigh: "high"
1976
+ },
1977
+ warnings
1978
+ });
1979
+ if (thinkingLevel == null) {
1980
+ return void 0;
1981
+ }
1982
+ return { thinkingLevel };
1983
+ }
1984
+ function resolveGemini25ThinkingConfig({
1985
+ reasoning,
1986
+ modelId,
1987
+ warnings
1988
+ }) {
1989
+ if (reasoning === "none") {
1990
+ return { thinkingBudget: 0 };
1991
+ }
1992
+ const thinkingBudget = mapReasoningToProviderBudget({
1993
+ reasoning,
1994
+ maxOutputTokens: getMaxOutputTokensForGemini25Model(),
1995
+ maxReasoningBudget: getMaxThinkingTokensForGemini25Model(modelId),
1996
+ minReasoningBudget: 0,
1997
+ warnings
1998
+ });
1999
+ if (thinkingBudget == null) {
2000
+ return void 0;
2001
+ }
2002
+ return { thinkingBudget };
1287
2003
  }
1288
2004
  function extractSources({
1289
2005
  groundingMetadata,
@@ -1379,231 +2095,286 @@ function extractSources({
1379
2095
  }
1380
2096
  return sources.length > 0 ? sources : void 0;
1381
2097
  }
1382
- var getGroundingMetadataSchema = () => import_v43.z.object({
1383
- webSearchQueries: import_v43.z.array(import_v43.z.string()).nullish(),
1384
- imageSearchQueries: import_v43.z.array(import_v43.z.string()).nullish(),
1385
- retrievalQueries: import_v43.z.array(import_v43.z.string()).nullish(),
1386
- searchEntryPoint: import_v43.z.object({ renderedContent: import_v43.z.string() }).nullish(),
1387
- groundingChunks: import_v43.z.array(
1388
- import_v43.z.object({
1389
- web: import_v43.z.object({ uri: import_v43.z.string(), title: import_v43.z.string().nullish() }).nullish(),
1390
- image: import_v43.z.object({
1391
- sourceUri: import_v43.z.string(),
1392
- imageUri: import_v43.z.string(),
1393
- title: import_v43.z.string().nullish(),
1394
- domain: import_v43.z.string().nullish()
2098
+ var getGroundingMetadataSchema = () => z3.object({
2099
+ webSearchQueries: z3.array(z3.string()).nullish(),
2100
+ imageSearchQueries: z3.array(z3.string()).nullish(),
2101
+ retrievalQueries: z3.array(z3.string()).nullish(),
2102
+ searchEntryPoint: z3.object({ renderedContent: z3.string() }).nullish(),
2103
+ groundingChunks: z3.array(
2104
+ z3.object({
2105
+ web: z3.object({ uri: z3.string(), title: z3.string().nullish() }).nullish(),
2106
+ image: z3.object({
2107
+ sourceUri: z3.string(),
2108
+ imageUri: z3.string(),
2109
+ title: z3.string().nullish(),
2110
+ domain: z3.string().nullish()
1395
2111
  }).nullish(),
1396
- retrievedContext: import_v43.z.object({
1397
- uri: import_v43.z.string().nullish(),
1398
- title: import_v43.z.string().nullish(),
1399
- text: import_v43.z.string().nullish(),
1400
- fileSearchStore: import_v43.z.string().nullish()
2112
+ retrievedContext: z3.object({
2113
+ uri: z3.string().nullish(),
2114
+ title: z3.string().nullish(),
2115
+ text: z3.string().nullish(),
2116
+ fileSearchStore: z3.string().nullish()
1401
2117
  }).nullish(),
1402
- maps: import_v43.z.object({
1403
- uri: import_v43.z.string().nullish(),
1404
- title: import_v43.z.string().nullish(),
1405
- text: import_v43.z.string().nullish(),
1406
- placeId: import_v43.z.string().nullish()
2118
+ maps: z3.object({
2119
+ uri: z3.string().nullish(),
2120
+ title: z3.string().nullish(),
2121
+ text: z3.string().nullish(),
2122
+ placeId: z3.string().nullish()
1407
2123
  }).nullish()
1408
2124
  })
1409
2125
  ).nullish(),
1410
- groundingSupports: import_v43.z.array(
1411
- import_v43.z.object({
1412
- segment: import_v43.z.object({
1413
- startIndex: import_v43.z.number().nullish(),
1414
- endIndex: import_v43.z.number().nullish(),
1415
- text: import_v43.z.string().nullish()
2126
+ groundingSupports: z3.array(
2127
+ z3.object({
2128
+ segment: z3.object({
2129
+ startIndex: z3.number().nullish(),
2130
+ endIndex: z3.number().nullish(),
2131
+ text: z3.string().nullish()
1416
2132
  }).nullish(),
1417
- segment_text: import_v43.z.string().nullish(),
1418
- groundingChunkIndices: import_v43.z.array(import_v43.z.number()).nullish(),
1419
- supportChunkIndices: import_v43.z.array(import_v43.z.number()).nullish(),
1420
- confidenceScores: import_v43.z.array(import_v43.z.number()).nullish(),
1421
- confidenceScore: import_v43.z.array(import_v43.z.number()).nullish()
2133
+ segment_text: z3.string().nullish(),
2134
+ groundingChunkIndices: z3.array(z3.number()).nullish(),
2135
+ supportChunkIndices: z3.array(z3.number()).nullish(),
2136
+ confidenceScores: z3.array(z3.number()).nullish(),
2137
+ confidenceScore: z3.array(z3.number()).nullish()
1422
2138
  })
1423
2139
  ).nullish(),
1424
- retrievalMetadata: import_v43.z.union([
1425
- import_v43.z.object({
1426
- webDynamicRetrievalScore: import_v43.z.number()
2140
+ retrievalMetadata: z3.union([
2141
+ z3.object({
2142
+ webDynamicRetrievalScore: z3.number()
1427
2143
  }),
1428
- import_v43.z.object({})
2144
+ z3.object({})
1429
2145
  ]).nullish()
1430
2146
  });
1431
- var getContentSchema = () => import_v43.z.object({
1432
- parts: import_v43.z.array(
1433
- import_v43.z.union([
2147
+ var partialArgSchema = z3.object({
2148
+ jsonPath: z3.string(),
2149
+ stringValue: z3.string().nullish(),
2150
+ numberValue: z3.number().nullish(),
2151
+ boolValue: z3.boolean().nullish(),
2152
+ nullValue: z3.unknown().nullish(),
2153
+ willContinue: z3.boolean().nullish()
2154
+ });
2155
+ var getContentSchema = () => z3.object({
2156
+ parts: z3.array(
2157
+ z3.union([
1434
2158
  // note: order matters since text can be fully empty
1435
- import_v43.z.object({
1436
- functionCall: import_v43.z.object({
1437
- name: import_v43.z.string(),
1438
- args: import_v43.z.unknown()
2159
+ z3.object({
2160
+ functionCall: z3.object({
2161
+ name: z3.string().nullish(),
2162
+ args: z3.unknown().nullish(),
2163
+ partialArgs: z3.array(partialArgSchema).nullish(),
2164
+ willContinue: z3.boolean().nullish()
2165
+ }),
2166
+ thoughtSignature: z3.string().nullish()
2167
+ }),
2168
+ z3.object({
2169
+ inlineData: z3.object({
2170
+ mimeType: z3.string(),
2171
+ data: z3.string()
1439
2172
  }),
1440
- thoughtSignature: import_v43.z.string().nullish()
2173
+ thought: z3.boolean().nullish(),
2174
+ thoughtSignature: z3.string().nullish()
1441
2175
  }),
1442
- import_v43.z.object({
1443
- inlineData: import_v43.z.object({
1444
- mimeType: import_v43.z.string(),
1445
- data: import_v43.z.string()
2176
+ z3.object({
2177
+ toolCall: z3.object({
2178
+ toolType: z3.string(),
2179
+ args: z3.unknown().nullish(),
2180
+ id: z3.string()
1446
2181
  }),
1447
- thought: import_v43.z.boolean().nullish(),
1448
- thoughtSignature: import_v43.z.string().nullish()
2182
+ thoughtSignature: z3.string().nullish()
1449
2183
  }),
1450
- import_v43.z.object({
1451
- executableCode: import_v43.z.object({
1452
- language: import_v43.z.string(),
1453
- code: import_v43.z.string()
2184
+ z3.object({
2185
+ toolResponse: z3.object({
2186
+ toolType: z3.string(),
2187
+ response: z3.unknown().nullish(),
2188
+ id: z3.string()
2189
+ }),
2190
+ thoughtSignature: z3.string().nullish()
2191
+ }),
2192
+ z3.object({
2193
+ executableCode: z3.object({
2194
+ language: z3.string(),
2195
+ code: z3.string()
1454
2196
  }).nullish(),
1455
- codeExecutionResult: import_v43.z.object({
1456
- outcome: import_v43.z.string(),
1457
- output: import_v43.z.string().nullish()
2197
+ codeExecutionResult: z3.object({
2198
+ outcome: z3.string(),
2199
+ output: z3.string().nullish()
1458
2200
  }).nullish(),
1459
- text: import_v43.z.string().nullish(),
1460
- thought: import_v43.z.boolean().nullish(),
1461
- thoughtSignature: import_v43.z.string().nullish()
2201
+ text: z3.string().nullish(),
2202
+ thought: z3.boolean().nullish(),
2203
+ thoughtSignature: z3.string().nullish()
1462
2204
  })
1463
2205
  ])
1464
2206
  ).nullish()
1465
2207
  });
1466
- var getSafetyRatingSchema = () => import_v43.z.object({
1467
- category: import_v43.z.string().nullish(),
1468
- probability: import_v43.z.string().nullish(),
1469
- probabilityScore: import_v43.z.number().nullish(),
1470
- severity: import_v43.z.string().nullish(),
1471
- severityScore: import_v43.z.number().nullish(),
1472
- blocked: import_v43.z.boolean().nullish()
2208
+ var getSafetyRatingSchema = () => z3.object({
2209
+ category: z3.string().nullish(),
2210
+ probability: z3.string().nullish(),
2211
+ probabilityScore: z3.number().nullish(),
2212
+ severity: z3.string().nullish(),
2213
+ severityScore: z3.number().nullish(),
2214
+ blocked: z3.boolean().nullish()
1473
2215
  });
1474
- var usageSchema = import_v43.z.object({
1475
- cachedContentTokenCount: import_v43.z.number().nullish(),
1476
- thoughtsTokenCount: import_v43.z.number().nullish(),
1477
- promptTokenCount: import_v43.z.number().nullish(),
1478
- candidatesTokenCount: import_v43.z.number().nullish(),
1479
- totalTokenCount: import_v43.z.number().nullish(),
2216
+ var tokenDetailsSchema = z3.array(
2217
+ z3.object({
2218
+ modality: z3.string(),
2219
+ tokenCount: z3.number()
2220
+ })
2221
+ ).nullish();
2222
+ var usageSchema = z3.object({
2223
+ cachedContentTokenCount: z3.number().nullish(),
2224
+ thoughtsTokenCount: z3.number().nullish(),
2225
+ promptTokenCount: z3.number().nullish(),
2226
+ candidatesTokenCount: z3.number().nullish(),
2227
+ totalTokenCount: z3.number().nullish(),
1480
2228
  // https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
1481
- trafficType: import_v43.z.string().nullish()
2229
+ trafficType: z3.string().nullish(),
2230
+ // https://ai.google.dev/api/generate-content#Modality
2231
+ promptTokensDetails: tokenDetailsSchema,
2232
+ candidatesTokensDetails: tokenDetailsSchema
1482
2233
  });
1483
- var getUrlContextMetadataSchema = () => import_v43.z.object({
1484
- urlMetadata: import_v43.z.array(
1485
- import_v43.z.object({
1486
- retrievedUrl: import_v43.z.string(),
1487
- urlRetrievalStatus: import_v43.z.string()
2234
+ var getUrlContextMetadataSchema = () => z3.object({
2235
+ urlMetadata: z3.array(
2236
+ z3.object({
2237
+ retrievedUrl: z3.string(),
2238
+ urlRetrievalStatus: z3.string()
1488
2239
  })
1489
2240
  ).nullish()
1490
2241
  });
1491
- var responseSchema = (0, import_provider_utils4.lazySchema)(
1492
- () => (0, import_provider_utils4.zodSchema)(
1493
- import_v43.z.object({
1494
- candidates: import_v43.z.array(
1495
- import_v43.z.object({
1496
- content: getContentSchema().nullish().or(import_v43.z.object({}).strict()),
1497
- finishReason: import_v43.z.string().nullish(),
1498
- safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish(),
2242
+ var responseSchema = lazySchema3(
2243
+ () => zodSchema3(
2244
+ z3.object({
2245
+ candidates: z3.array(
2246
+ z3.object({
2247
+ content: getContentSchema().nullish().or(z3.object({}).strict()),
2248
+ finishReason: z3.string().nullish(),
2249
+ finishMessage: z3.string().nullish(),
2250
+ safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
1499
2251
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1500
2252
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
1501
2253
  })
1502
2254
  ),
1503
2255
  usageMetadata: usageSchema.nullish(),
1504
- promptFeedback: import_v43.z.object({
1505
- blockReason: import_v43.z.string().nullish(),
1506
- safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish()
1507
- }).nullish()
2256
+ promptFeedback: z3.object({
2257
+ blockReason: z3.string().nullish(),
2258
+ safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
2259
+ }).nullish(),
2260
+ serviceTier: z3.string().nullish()
1508
2261
  })
1509
2262
  )
1510
2263
  );
1511
- var chunkSchema = (0, import_provider_utils4.lazySchema)(
1512
- () => (0, import_provider_utils4.zodSchema)(
1513
- import_v43.z.object({
1514
- candidates: import_v43.z.array(
1515
- import_v43.z.object({
2264
+ var chunkSchema = lazySchema3(
2265
+ () => zodSchema3(
2266
+ z3.object({
2267
+ candidates: z3.array(
2268
+ z3.object({
1516
2269
  content: getContentSchema().nullish(),
1517
- finishReason: import_v43.z.string().nullish(),
1518
- safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish(),
2270
+ finishReason: z3.string().nullish(),
2271
+ finishMessage: z3.string().nullish(),
2272
+ safetyRatings: z3.array(getSafetyRatingSchema()).nullish(),
1519
2273
  groundingMetadata: getGroundingMetadataSchema().nullish(),
1520
2274
  urlContextMetadata: getUrlContextMetadataSchema().nullish()
1521
2275
  })
1522
2276
  ).nullish(),
1523
2277
  usageMetadata: usageSchema.nullish(),
1524
- promptFeedback: import_v43.z.object({
1525
- blockReason: import_v43.z.string().nullish(),
1526
- safetyRatings: import_v43.z.array(getSafetyRatingSchema()).nullish()
1527
- }).nullish()
2278
+ promptFeedback: z3.object({
2279
+ blockReason: z3.string().nullish(),
2280
+ safetyRatings: z3.array(getSafetyRatingSchema()).nullish()
2281
+ }).nullish(),
2282
+ serviceTier: z3.string().nullish()
1528
2283
  })
1529
2284
  )
1530
2285
  );
1531
2286
 
1532
2287
  // src/tool/code-execution.ts
1533
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
1534
- var import_v44 = require("zod/v4");
1535
- var codeExecution = (0, import_provider_utils5.createProviderToolFactoryWithOutputSchema)({
2288
+ import { createProviderToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils";
2289
+ import { z as z4 } from "zod/v4";
2290
+ var codeExecution = createProviderToolFactoryWithOutputSchema({
1536
2291
  id: "google.code_execution",
1537
- inputSchema: import_v44.z.object({
1538
- language: import_v44.z.string().describe("The programming language of the code."),
1539
- code: import_v44.z.string().describe("The code to be executed.")
2292
+ inputSchema: z4.object({
2293
+ language: z4.string().describe("The programming language of the code."),
2294
+ code: z4.string().describe("The code to be executed.")
1540
2295
  }),
1541
- outputSchema: import_v44.z.object({
1542
- outcome: import_v44.z.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
1543
- output: import_v44.z.string().describe("The output from the code execution.")
2296
+ outputSchema: z4.object({
2297
+ outcome: z4.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
2298
+ output: z4.string().describe("The output from the code execution.")
1544
2299
  })
1545
2300
  });
1546
2301
 
1547
2302
  // src/tool/enterprise-web-search.ts
1548
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
1549
- var import_v45 = require("zod/v4");
1550
- var enterpriseWebSearch = (0, import_provider_utils6.createProviderToolFactory)({
2303
+ import {
2304
+ createProviderToolFactory,
2305
+ lazySchema as lazySchema4,
2306
+ zodSchema as zodSchema4
2307
+ } from "@ai-sdk/provider-utils";
2308
+ import { z as z5 } from "zod/v4";
2309
+ var enterpriseWebSearch = createProviderToolFactory({
1551
2310
  id: "google.enterprise_web_search",
1552
- inputSchema: (0, import_provider_utils6.lazySchema)(() => (0, import_provider_utils6.zodSchema)(import_v45.z.object({})))
2311
+ inputSchema: lazySchema4(() => zodSchema4(z5.object({})))
1553
2312
  });
1554
2313
 
1555
2314
  // src/tool/file-search.ts
1556
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
1557
- var import_v46 = require("zod/v4");
1558
- var fileSearchArgsBaseSchema = import_v46.z.object({
2315
+ import {
2316
+ createProviderToolFactory as createProviderToolFactory2,
2317
+ lazySchema as lazySchema5,
2318
+ zodSchema as zodSchema5
2319
+ } from "@ai-sdk/provider-utils";
2320
+ import { z as z6 } from "zod/v4";
2321
+ var fileSearchArgsBaseSchema = z6.object({
1559
2322
  /** The names of the file_search_stores to retrieve from.
1560
2323
  * Example: `fileSearchStores/my-file-search-store-123`
1561
2324
  */
1562
- fileSearchStoreNames: import_v46.z.array(import_v46.z.string()).describe(
2325
+ fileSearchStoreNames: z6.array(z6.string()).describe(
1563
2326
  "The names of the file_search_stores to retrieve from. Example: `fileSearchStores/my-file-search-store-123`"
1564
2327
  ),
1565
2328
  /** The number of file search retrieval chunks to retrieve. */
1566
- topK: import_v46.z.number().int().positive().describe("The number of file search retrieval chunks to retrieve.").optional(),
2329
+ topK: z6.number().int().positive().describe("The number of file search retrieval chunks to retrieve.").optional(),
1567
2330
  /** Metadata filter to apply to the file search retrieval documents.
1568
2331
  * See https://google.aip.dev/160 for the syntax of the filter expression.
1569
2332
  */
1570
- metadataFilter: import_v46.z.string().describe(
2333
+ metadataFilter: z6.string().describe(
1571
2334
  "Metadata filter to apply to the file search retrieval documents. See https://google.aip.dev/160 for the syntax of the filter expression."
1572
2335
  ).optional()
1573
2336
  }).passthrough();
1574
- var fileSearchArgsSchema = (0, import_provider_utils7.lazySchema)(
1575
- () => (0, import_provider_utils7.zodSchema)(fileSearchArgsBaseSchema)
2337
+ var fileSearchArgsSchema = lazySchema5(
2338
+ () => zodSchema5(fileSearchArgsBaseSchema)
1576
2339
  );
1577
- var fileSearch = (0, import_provider_utils7.createProviderToolFactory)({
2340
+ var fileSearch = createProviderToolFactory2({
1578
2341
  id: "google.file_search",
1579
2342
  inputSchema: fileSearchArgsSchema
1580
2343
  });
1581
2344
 
1582
2345
  // src/tool/google-maps.ts
1583
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
1584
- var import_v47 = require("zod/v4");
1585
- var googleMaps = (0, import_provider_utils8.createProviderToolFactory)({
2346
+ import {
2347
+ createProviderToolFactory as createProviderToolFactory3,
2348
+ lazySchema as lazySchema6,
2349
+ zodSchema as zodSchema6
2350
+ } from "@ai-sdk/provider-utils";
2351
+ import { z as z7 } from "zod/v4";
2352
+ var googleMaps = createProviderToolFactory3({
1586
2353
  id: "google.google_maps",
1587
- inputSchema: (0, import_provider_utils8.lazySchema)(() => (0, import_provider_utils8.zodSchema)(import_v47.z.object({})))
2354
+ inputSchema: lazySchema6(() => zodSchema6(z7.object({})))
1588
2355
  });
1589
2356
 
1590
2357
  // src/tool/google-search.ts
1591
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
1592
- var import_v48 = require("zod/v4");
1593
- var googleSearchToolArgsBaseSchema = import_v48.z.object({
1594
- searchTypes: import_v48.z.object({
1595
- webSearch: import_v48.z.object({}).optional(),
1596
- imageSearch: import_v48.z.object({}).optional()
2358
+ import {
2359
+ createProviderToolFactory as createProviderToolFactory4,
2360
+ lazySchema as lazySchema7,
2361
+ zodSchema as zodSchema7
2362
+ } from "@ai-sdk/provider-utils";
2363
+ import { z as z8 } from "zod/v4";
2364
+ var googleSearchToolArgsBaseSchema = z8.object({
2365
+ searchTypes: z8.object({
2366
+ webSearch: z8.object({}).optional(),
2367
+ imageSearch: z8.object({}).optional()
1597
2368
  }).optional(),
1598
- timeRangeFilter: import_v48.z.object({
1599
- startTime: import_v48.z.string(),
1600
- endTime: import_v48.z.string()
2369
+ timeRangeFilter: z8.object({
2370
+ startTime: z8.string(),
2371
+ endTime: z8.string()
1601
2372
  }).optional()
1602
2373
  }).passthrough();
1603
- var googleSearchToolArgsSchema = (0, import_provider_utils9.lazySchema)(
1604
- () => (0, import_provider_utils9.zodSchema)(googleSearchToolArgsBaseSchema)
2374
+ var googleSearchToolArgsSchema = lazySchema7(
2375
+ () => zodSchema7(googleSearchToolArgsBaseSchema)
1605
2376
  );
1606
- var googleSearch = (0, import_provider_utils9.createProviderToolFactory)(
2377
+ var googleSearch = createProviderToolFactory4(
1607
2378
  {
1608
2379
  id: "google.google_search",
1609
2380
  inputSchema: googleSearchToolArgsSchema
@@ -1611,21 +2382,25 @@ var googleSearch = (0, import_provider_utils9.createProviderToolFactory)(
1611
2382
  );
1612
2383
 
1613
2384
  // src/tool/url-context.ts
1614
- var import_provider_utils10 = require("@ai-sdk/provider-utils");
1615
- var import_v49 = require("zod/v4");
1616
- var urlContext = (0, import_provider_utils10.createProviderToolFactory)({
2385
+ import {
2386
+ createProviderToolFactory as createProviderToolFactory5,
2387
+ lazySchema as lazySchema8,
2388
+ zodSchema as zodSchema8
2389
+ } from "@ai-sdk/provider-utils";
2390
+ import { z as z9 } from "zod/v4";
2391
+ var urlContext = createProviderToolFactory5({
1617
2392
  id: "google.url_context",
1618
- inputSchema: (0, import_provider_utils10.lazySchema)(() => (0, import_provider_utils10.zodSchema)(import_v49.z.object({})))
2393
+ inputSchema: lazySchema8(() => zodSchema8(z9.object({})))
1619
2394
  });
1620
2395
 
1621
2396
  // src/tool/vertex-rag-store.ts
1622
- var import_provider_utils11 = require("@ai-sdk/provider-utils");
1623
- var import_v410 = require("zod/v4");
1624
- var vertexRagStore = (0, import_provider_utils11.createProviderToolFactory)({
2397
+ import { createProviderToolFactory as createProviderToolFactory6 } from "@ai-sdk/provider-utils";
2398
+ import { z as z10 } from "zod/v4";
2399
+ var vertexRagStore = createProviderToolFactory6({
1625
2400
  id: "google.vertex_rag_store",
1626
- inputSchema: import_v410.z.object({
1627
- ragCorpus: import_v410.z.string(),
1628
- topK: import_v410.z.number().optional()
2401
+ inputSchema: z10.object({
2402
+ ragCorpus: z10.string(),
2403
+ topK: z10.number().optional()
1629
2404
  })
1630
2405
  });
1631
2406
 
@@ -1688,11 +2463,10 @@ var googleTools = {
1688
2463
  */
1689
2464
  vertexRagStore
1690
2465
  };
1691
- // Annotate the CommonJS export names for ESM import in node:
1692
- 0 && (module.exports = {
2466
+ export {
1693
2467
  GoogleGenerativeAILanguageModel,
1694
2468
  getGroundingMetadataSchema,
1695
2469
  getUrlContextMetadataSchema,
1696
2470
  googleTools
1697
- });
2471
+ };
1698
2472
  //# sourceMappingURL=index.js.map