@ai-sdk/google 2.0.0-beta.1 → 2.0.0-beta.10

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.
package/dist/index.mjs CHANGED
@@ -1,9 +1,6 @@
1
1
  // src/google-provider.ts
2
2
  import {
3
- NoSuchModelError
4
- } from "@ai-sdk/provider";
5
- import {
6
- generateId,
3
+ generateId as generateId2,
7
4
  loadApiKey,
8
5
  withoutTrailingSlash
9
6
  } from "@ai-sdk/provider-utils";
@@ -19,11 +16,11 @@ import {
19
16
  postJsonToApi,
20
17
  resolve
21
18
  } from "@ai-sdk/provider-utils";
22
- import { z as z3 } from "zod";
19
+ import { z as z3 } from "zod/v4";
23
20
 
24
21
  // src/google-error.ts
25
22
  import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
26
- import { z } from "zod";
23
+ import { z } from "zod/v4";
27
24
  var googleErrorDataSchema = z.object({
28
25
  error: z.object({
29
26
  code: z.number().nullable(),
@@ -37,7 +34,7 @@ var googleFailedResponseHandler = createJsonErrorResponseHandler({
37
34
  });
38
35
 
39
36
  // src/google-generative-ai-embedding-options.ts
40
- import { z as z2 } from "zod";
37
+ import { z as z2 } from "zod/v4";
41
38
  var googleGenerativeAIEmbeddingProviderOptions = z2.object({
42
39
  /**
43
40
  * Optional. Optional reduced dimension for the output embedding.
@@ -141,11 +138,12 @@ import {
141
138
  combineHeaders as combineHeaders2,
142
139
  createEventSourceResponseHandler,
143
140
  createJsonResponseHandler as createJsonResponseHandler2,
141
+ generateId,
144
142
  parseProviderOptions as parseProviderOptions2,
145
143
  postJsonToApi as postJsonToApi2,
146
144
  resolve as resolve2
147
145
  } from "@ai-sdk/provider-utils";
148
- import { z as z5 } from "zod";
146
+ import { z as z7 } from "zod/v4";
149
147
 
150
148
  // src/convert-json-schema-to-openapi-schema.ts
151
149
  function convertJSONSchemaToOpenAPISchema(jsonSchema) {
@@ -241,7 +239,7 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema) {
241
239
  return result;
242
240
  }
243
241
  function isEmptyObjectSchema(jsonSchema) {
244
- return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0);
242
+ return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
245
243
  }
246
244
 
247
245
  // src/convert-to-google-generative-ai-messages.ts
@@ -249,10 +247,12 @@ import {
249
247
  UnsupportedFunctionalityError
250
248
  } from "@ai-sdk/provider";
251
249
  import { convertToBase64 } from "@ai-sdk/provider-utils";
252
- function convertToGoogleGenerativeAIMessages(prompt) {
250
+ function convertToGoogleGenerativeAIMessages(prompt, options) {
251
+ var _a;
253
252
  const systemInstructionParts = [];
254
253
  const contents = [];
255
254
  let systemMessagesAllowed = true;
255
+ const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
256
256
  for (const { role, content } of prompt) {
257
257
  switch (role) {
258
258
  case "system": {
@@ -353,8 +353,12 @@ function convertToGoogleGenerativeAIMessages(prompt) {
353
353
  }
354
354
  }
355
355
  }
356
+ if (isGemmaModel && systemInstructionParts.length > 0 && contents.length > 0 && contents[0].role === "user") {
357
+ const systemText = systemInstructionParts.map((part) => part.text).join("\n\n");
358
+ contents[0].parts.unshift({ text: systemText + "\n\n" });
359
+ }
356
360
  return {
357
- systemInstruction: systemInstructionParts.length > 0 ? { parts: systemInstructionParts } : void 0,
361
+ systemInstruction: systemInstructionParts.length > 0 && !isGemmaModel ? { parts: systemInstructionParts } : void 0,
358
362
  contents
359
363
  };
360
364
  }
@@ -365,18 +369,7 @@ function getModelPath(modelId) {
365
369
  }
366
370
 
367
371
  // src/google-generative-ai-options.ts
368
- import { z as z4 } from "zod";
369
- var dynamicRetrievalConfig = z4.object({
370
- /**
371
- * The mode of the predictor to be used in dynamic retrieval.
372
- */
373
- mode: z4.enum(["MODE_UNSPECIFIED", "MODE_DYNAMIC"]).optional(),
374
- /**
375
- * The threshold to be used in dynamic retrieval. If not set, a system default
376
- * value is used.
377
- */
378
- dynamicThreshold: z4.number().optional()
379
- });
372
+ import { z as z4 } from "zod/v4";
380
373
  var googleGenerativeAIProviderOptions = z4.object({
381
374
  responseModalities: z4.array(z4.enum(["TEXT", "IMAGE"])).optional(),
382
375
  thinkingConfig: z4.object({
@@ -434,21 +427,7 @@ var googleGenerativeAIProviderOptions = z4.object({
434
427
  *
435
428
  * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
436
429
  */
437
- audioTimestamp: z4.boolean().optional(),
438
- /**
439
- Optional. When enabled, the model will use Google search to ground the response.
440
-
441
- @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview
442
- */
443
- useSearchGrounding: z4.boolean().optional(),
444
- /**
445
- Optional. Specifies the dynamic retrieval configuration.
446
-
447
- @note Dynamic retrieval is only compatible with Gemini 1.5 Flash.
448
-
449
- @see https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/ground-with-google-search#dynamic-retrieval
450
- */
451
- dynamicRetrievalConfig: dynamicRetrievalConfig.optional()
430
+ audioTimestamp: z4.boolean().optional()
452
431
  });
453
432
 
454
433
  // src/google-prepare-tools.ts
@@ -458,8 +437,6 @@ import {
458
437
  function prepareTools({
459
438
  tools,
460
439
  toolChoice,
461
- useSearchGrounding,
462
- dynamicRetrievalConfig: dynamicRetrievalConfig2,
463
440
  modelId
464
441
  }) {
465
442
  var _a;
@@ -467,28 +444,76 @@ function prepareTools({
467
444
  const toolWarnings = [];
468
445
  const isGemini2 = modelId.includes("gemini-2");
469
446
  const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
470
- if (useSearchGrounding) {
447
+ if (tools == null) {
448
+ return { tools: void 0, toolConfig: void 0, toolWarnings };
449
+ }
450
+ const hasFunctionTools = tools.some((tool) => tool.type === "function");
451
+ const hasProviderDefinedTools = tools.some(
452
+ (tool) => tool.type === "provider-defined"
453
+ );
454
+ if (hasFunctionTools && hasProviderDefinedTools) {
455
+ toolWarnings.push({
456
+ type: "unsupported-tool",
457
+ tool: tools.find((tool) => tool.type === "function"),
458
+ details: "Cannot mix function tools with provider-defined tools in the same request. Please use either function tools or provider-defined tools, but not both."
459
+ });
460
+ }
461
+ if (hasProviderDefinedTools) {
462
+ const googleTools2 = {};
463
+ const providerDefinedTools = tools.filter(
464
+ (tool) => tool.type === "provider-defined"
465
+ );
466
+ providerDefinedTools.forEach((tool) => {
467
+ switch (tool.id) {
468
+ case "google.google_search":
469
+ if (isGemini2) {
470
+ googleTools2.googleSearch = {};
471
+ } else if (supportsDynamicRetrieval) {
472
+ googleTools2.googleSearchRetrieval = {
473
+ dynamicRetrievalConfig: {
474
+ mode: tool.args.mode,
475
+ dynamicThreshold: tool.args.dynamicThreshold
476
+ }
477
+ };
478
+ } else {
479
+ googleTools2.googleSearchRetrieval = {};
480
+ }
481
+ break;
482
+ case "google.url_context":
483
+ if (isGemini2) {
484
+ googleTools2.urlContext = {};
485
+ } else {
486
+ toolWarnings.push({
487
+ type: "unsupported-tool",
488
+ tool,
489
+ details: "The URL context tool is not supported with other Gemini models than Gemini 2."
490
+ });
491
+ }
492
+ break;
493
+ default:
494
+ toolWarnings.push({ type: "unsupported-tool", tool });
495
+ break;
496
+ }
497
+ });
471
498
  return {
472
- tools: isGemini2 ? { googleSearch: {} } : {
473
- googleSearchRetrieval: !supportsDynamicRetrieval || !dynamicRetrievalConfig2 ? {} : { dynamicRetrievalConfig: dynamicRetrievalConfig2 }
474
- },
499
+ tools: Object.keys(googleTools2).length > 0 ? googleTools2 : void 0,
475
500
  toolConfig: void 0,
476
501
  toolWarnings
477
502
  };
478
503
  }
479
- if (tools == null) {
480
- return { tools: void 0, toolConfig: void 0, toolWarnings };
481
- }
482
504
  const functionDeclarations = [];
483
505
  for (const tool of tools) {
484
- if (tool.type === "provider-defined") {
485
- toolWarnings.push({ type: "unsupported-tool", tool });
486
- } else {
487
- functionDeclarations.push({
488
- name: tool.name,
489
- description: (_a = tool.description) != null ? _a : "",
490
- parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
491
- });
506
+ switch (tool.type) {
507
+ case "function":
508
+ functionDeclarations.push({
509
+ name: tool.name,
510
+ description: (_a = tool.description) != null ? _a : "",
511
+ parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
512
+ });
513
+ break;
514
+ default:
515
+ toolWarnings.push({ type: "unsupported-tool", tool });
516
+ break;
492
517
  }
493
518
  }
494
519
  if (toolChoice == null) {
@@ -565,12 +590,72 @@ function mapGoogleGenerativeAIFinishReason({
565
590
  }
566
591
  }
567
592
 
593
+ // src/tool/google-search.ts
594
+ import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils";
595
+ import { z as z5 } from "zod/v4";
596
+ var groundingChunkSchema = z5.object({
597
+ web: z5.object({ uri: z5.string(), title: z5.string() }).nullish(),
598
+ retrievedContext: z5.object({ uri: z5.string(), title: z5.string() }).nullish()
599
+ });
600
+ var groundingMetadataSchema = z5.object({
601
+ webSearchQueries: z5.array(z5.string()).nullish(),
602
+ retrievalQueries: z5.array(z5.string()).nullish(),
603
+ searchEntryPoint: z5.object({ renderedContent: z5.string() }).nullish(),
604
+ groundingChunks: z5.array(groundingChunkSchema).nullish(),
605
+ groundingSupports: z5.array(
606
+ z5.object({
607
+ segment: z5.object({
608
+ startIndex: z5.number().nullish(),
609
+ endIndex: z5.number().nullish(),
610
+ text: z5.string().nullish()
611
+ }),
612
+ segment_text: z5.string().nullish(),
613
+ groundingChunkIndices: z5.array(z5.number()).nullish(),
614
+ supportChunkIndices: z5.array(z5.number()).nullish(),
615
+ confidenceScores: z5.array(z5.number()).nullish(),
616
+ confidenceScore: z5.array(z5.number()).nullish()
617
+ })
618
+ ).nullish(),
619
+ retrievalMetadata: z5.union([
620
+ z5.object({
621
+ webDynamicRetrievalScore: z5.number()
622
+ }),
623
+ z5.object({})
624
+ ]).nullish()
625
+ });
626
+ var googleSearch = createProviderDefinedToolFactory({
627
+ id: "google.google_search",
628
+ name: "google_search",
629
+ inputSchema: z5.object({
630
+ mode: z5.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
631
+ dynamicThreshold: z5.number().default(1)
632
+ })
633
+ });
634
+
635
+ // src/tool/url-context.ts
636
+ import { createProviderDefinedToolFactory as createProviderDefinedToolFactory2 } from "@ai-sdk/provider-utils";
637
+ import { z as z6 } from "zod/v4";
638
+ var urlMetadataSchema = z6.object({
639
+ retrievedUrl: z6.string(),
640
+ urlRetrievalStatus: z6.string()
641
+ });
642
+ var urlContextMetadataSchema = z6.object({
643
+ urlMetadata: z6.array(urlMetadataSchema)
644
+ });
645
+ var urlContext = createProviderDefinedToolFactory2({
646
+ id: "google.url_context",
647
+ name: "url_context",
648
+ inputSchema: z6.object({})
649
+ });
650
+
568
651
  // src/google-generative-ai-language-model.ts
569
652
  var GoogleGenerativeAILanguageModel = class {
570
653
  constructor(modelId, config) {
571
654
  this.specificationVersion = "v2";
655
+ var _a;
572
656
  this.modelId = modelId;
573
657
  this.config = config;
658
+ this.generateId = (_a = config.generateId) != null ? _a : generateId;
574
659
  }
575
660
  get provider() {
576
661
  return this.config.provider;
@@ -594,7 +679,7 @@ var GoogleGenerativeAILanguageModel = class {
594
679
  toolChoice,
595
680
  providerOptions
596
681
  }) {
597
- var _a, _b, _c;
682
+ var _a, _b;
598
683
  const warnings = [];
599
684
  const googleOptions = await parseProviderOptions2({
600
685
  provider: "google",
@@ -607,16 +692,18 @@ var GoogleGenerativeAILanguageModel = class {
607
692
  message: `The 'includeThoughts' option 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}).`
608
693
  });
609
694
  }
610
- const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(prompt);
695
+ const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
696
+ const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
697
+ prompt,
698
+ { isGemmaModel }
699
+ );
611
700
  const {
612
- tools: googleTools,
701
+ tools: googleTools2,
613
702
  toolConfig: googleToolConfig,
614
703
  toolWarnings
615
704
  } = prepareTools({
616
705
  tools,
617
706
  toolChoice,
618
- useSearchGrounding: (_b = googleOptions == null ? void 0 : googleOptions.useSearchGrounding) != null ? _b : false,
619
- dynamicRetrievalConfig: googleOptions == null ? void 0 : googleOptions.dynamicRetrievalConfig,
620
707
  modelId: this.modelId
621
708
  });
622
709
  return {
@@ -636,7 +723,7 @@ var GoogleGenerativeAILanguageModel = class {
636
723
  responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
637
724
  // so this is needed as an escape hatch:
638
725
  // TODO convert into provider option
639
- ((_c = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _c : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
726
+ ((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
640
727
  ...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
641
728
  audioTimestamp: googleOptions.audioTimestamp
642
729
  },
@@ -645,9 +732,9 @@ var GoogleGenerativeAILanguageModel = class {
645
732
  thinkingConfig: googleOptions == null ? void 0 : googleOptions.thinkingConfig
646
733
  },
647
734
  contents,
648
- systemInstruction,
735
+ systemInstruction: isGemmaModel ? void 0 : systemInstruction,
649
736
  safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
650
- tools: googleTools,
737
+ tools: googleTools2,
651
738
  toolConfig: googleToolConfig,
652
739
  cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent
653
740
  },
@@ -655,7 +742,7 @@ var GoogleGenerativeAILanguageModel = class {
655
742
  };
656
743
  }
657
744
  async doGenerate(options) {
658
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
745
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
659
746
  const { args, warnings } = await this.getArgs(options);
660
747
  const body = JSON.stringify(args);
661
748
  const mergedHeaders = combineHeaders2(
@@ -727,7 +814,9 @@ var GoogleGenerativeAILanguageModel = class {
727
814
  providerMetadata: {
728
815
  google: {
729
816
  groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
730
- safetyRatings: (_i = candidate.safetyRatings) != null ? _i : null
817
+ urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
818
+ safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
819
+ usageMetadata: usageMetadata != null ? usageMetadata : null
731
820
  }
732
821
  },
733
822
  request: { body },
@@ -763,11 +852,12 @@ var GoogleGenerativeAILanguageModel = class {
763
852
  totalTokens: void 0
764
853
  };
765
854
  let providerMetadata = void 0;
766
- const generateId2 = this.config.generateId;
855
+ const generateId3 = this.config.generateId;
767
856
  let hasToolCalls = false;
768
857
  let currentTextBlockId = null;
769
858
  let currentReasoningBlockId = null;
770
859
  let blockCounter = 0;
860
+ const emittedSourceUrls = /* @__PURE__ */ new Set();
771
861
  return {
772
862
  stream: response.pipeThrough(
773
863
  new TransformStream({
@@ -797,6 +887,18 @@ var GoogleGenerativeAILanguageModel = class {
797
887
  return;
798
888
  }
799
889
  const content = candidate.content;
890
+ const sources = extractSources({
891
+ groundingMetadata: candidate.groundingMetadata,
892
+ generateId: generateId3
893
+ });
894
+ if (sources != null) {
895
+ for (const source of sources) {
896
+ if (source.sourceType === "url" && !emittedSourceUrls.has(source.url)) {
897
+ emittedSourceUrls.add(source.url);
898
+ controller.enqueue(source);
899
+ }
900
+ }
901
+ }
800
902
  if (content != null) {
801
903
  const parts = (_g = content.parts) != null ? _g : [];
802
904
  for (const part of parts) {
@@ -856,7 +958,7 @@ var GoogleGenerativeAILanguageModel = class {
856
958
  }
857
959
  const toolCallDeltas = getToolCallsFromParts({
858
960
  parts: content.parts,
859
- generateId: generateId2
961
+ generateId: generateId3
860
962
  });
861
963
  if (toolCallDeltas != null) {
862
964
  for (const toolCall of toolCallDeltas) {
@@ -889,19 +991,16 @@ var GoogleGenerativeAILanguageModel = class {
889
991
  finishReason: candidate.finishReason,
890
992
  hasToolCalls
891
993
  });
892
- const sources = (_h = extractSources({
893
- groundingMetadata: candidate.groundingMetadata,
894
- generateId: generateId2
895
- })) != null ? _h : [];
896
- for (const source of sources) {
897
- controller.enqueue(source);
898
- }
899
994
  providerMetadata = {
900
995
  google: {
901
- groundingMetadata: (_i = candidate.groundingMetadata) != null ? _i : null,
996
+ groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
997
+ urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
902
998
  safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null
903
999
  }
904
1000
  };
1001
+ if (usageMetadata != null) {
1002
+ providerMetadata.google.usageMetadata = usageMetadata;
1003
+ }
905
1004
  }
906
1005
  },
907
1006
  flush(controller) {
@@ -933,14 +1032,14 @@ var GoogleGenerativeAILanguageModel = class {
933
1032
  };
934
1033
  function getToolCallsFromParts({
935
1034
  parts,
936
- generateId: generateId2
1035
+ generateId: generateId3
937
1036
  }) {
938
1037
  const functionCallParts = parts == null ? void 0 : parts.filter(
939
1038
  (part) => "functionCall" in part
940
1039
  );
941
1040
  return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
942
1041
  type: "tool-call",
943
- toolCallId: generateId2(),
1042
+ toolCallId: generateId3(),
944
1043
  toolName: part.functionCall.name,
945
1044
  args: JSON.stringify(part.functionCall.args)
946
1045
  }));
@@ -952,7 +1051,7 @@ function getInlineDataParts(parts) {
952
1051
  }
953
1052
  function extractSources({
954
1053
  groundingMetadata,
955
- generateId: generateId2
1054
+ generateId: generateId3
956
1055
  }) {
957
1056
  var _a;
958
1057
  return (_a = groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks) == null ? void 0 : _a.filter(
@@ -960,102 +1059,196 @@ function extractSources({
960
1059
  ).map((chunk) => ({
961
1060
  type: "source",
962
1061
  sourceType: "url",
963
- id: generateId2(),
1062
+ id: generateId3(),
964
1063
  url: chunk.web.uri,
965
1064
  title: chunk.web.title
966
1065
  }));
967
1066
  }
968
- var contentSchema = z5.object({
969
- parts: z5.array(
970
- z5.union([
1067
+ var contentSchema = z7.object({
1068
+ parts: z7.array(
1069
+ z7.union([
971
1070
  // note: order matters since text can be fully empty
972
- z5.object({
973
- functionCall: z5.object({
974
- name: z5.string(),
975
- args: z5.unknown()
1071
+ z7.object({
1072
+ functionCall: z7.object({
1073
+ name: z7.string(),
1074
+ args: z7.unknown()
976
1075
  })
977
1076
  }),
978
- z5.object({
979
- inlineData: z5.object({
980
- mimeType: z5.string(),
981
- data: z5.string()
1077
+ z7.object({
1078
+ inlineData: z7.object({
1079
+ mimeType: z7.string(),
1080
+ data: z7.string()
982
1081
  })
983
1082
  }),
984
- z5.object({
985
- text: z5.string().nullish(),
986
- thought: z5.boolean().nullish()
1083
+ z7.object({
1084
+ text: z7.string().nullish(),
1085
+ thought: z7.boolean().nullish()
987
1086
  })
988
1087
  ])
989
1088
  ).nullish()
990
1089
  });
991
- var groundingChunkSchema = z5.object({
992
- web: z5.object({ uri: z5.string(), title: z5.string() }).nullish(),
993
- retrievedContext: z5.object({ uri: z5.string(), title: z5.string() }).nullish()
994
- });
995
- var groundingMetadataSchema = z5.object({
996
- webSearchQueries: z5.array(z5.string()).nullish(),
997
- retrievalQueries: z5.array(z5.string()).nullish(),
998
- searchEntryPoint: z5.object({ renderedContent: z5.string() }).nullish(),
999
- groundingChunks: z5.array(groundingChunkSchema).nullish(),
1000
- groundingSupports: z5.array(
1001
- z5.object({
1002
- segment: z5.object({
1003
- startIndex: z5.number().nullish(),
1004
- endIndex: z5.number().nullish(),
1005
- text: z5.string().nullish()
1006
- }),
1007
- segment_text: z5.string().nullish(),
1008
- groundingChunkIndices: z5.array(z5.number()).nullish(),
1009
- supportChunkIndices: z5.array(z5.number()).nullish(),
1010
- confidenceScores: z5.array(z5.number()).nullish(),
1011
- confidenceScore: z5.array(z5.number()).nullish()
1012
- })
1013
- ).nullish(),
1014
- retrievalMetadata: z5.union([
1015
- z5.object({
1016
- webDynamicRetrievalScore: z5.number()
1017
- }),
1018
- z5.object({})
1019
- ]).nullish()
1020
- });
1021
- var safetyRatingSchema = z5.object({
1022
- category: z5.string().nullish(),
1023
- probability: z5.string().nullish(),
1024
- probabilityScore: z5.number().nullish(),
1025
- severity: z5.string().nullish(),
1026
- severityScore: z5.number().nullish(),
1027
- blocked: z5.boolean().nullish()
1090
+ var safetyRatingSchema = z7.object({
1091
+ category: z7.string().nullish(),
1092
+ probability: z7.string().nullish(),
1093
+ probabilityScore: z7.number().nullish(),
1094
+ severity: z7.string().nullish(),
1095
+ severityScore: z7.number().nullish(),
1096
+ blocked: z7.boolean().nullish()
1028
1097
  });
1029
- var usageSchema = z5.object({
1030
- cachedContentTokenCount: z5.number().nullish(),
1031
- thoughtsTokenCount: z5.number().nullish(),
1032
- promptTokenCount: z5.number().nullish(),
1033
- candidatesTokenCount: z5.number().nullish(),
1034
- totalTokenCount: z5.number().nullish()
1098
+ var usageSchema = z7.object({
1099
+ cachedContentTokenCount: z7.number().nullish(),
1100
+ thoughtsTokenCount: z7.number().nullish(),
1101
+ promptTokenCount: z7.number().nullish(),
1102
+ candidatesTokenCount: z7.number().nullish(),
1103
+ totalTokenCount: z7.number().nullish()
1035
1104
  });
1036
- var responseSchema = z5.object({
1037
- candidates: z5.array(
1038
- z5.object({
1039
- content: contentSchema.nullish().or(z5.object({}).strict()),
1040
- finishReason: z5.string().nullish(),
1041
- safetyRatings: z5.array(safetyRatingSchema).nullish(),
1042
- groundingMetadata: groundingMetadataSchema.nullish()
1105
+ var responseSchema = z7.object({
1106
+ candidates: z7.array(
1107
+ z7.object({
1108
+ content: contentSchema.nullish().or(z7.object({}).strict()),
1109
+ finishReason: z7.string().nullish(),
1110
+ safetyRatings: z7.array(safetyRatingSchema).nullish(),
1111
+ groundingMetadata: groundingMetadataSchema.nullish(),
1112
+ urlContextMetadata: urlContextMetadataSchema.nullish()
1043
1113
  })
1044
1114
  ),
1045
1115
  usageMetadata: usageSchema.nullish()
1046
1116
  });
1047
- var chunkSchema = z5.object({
1048
- candidates: z5.array(
1049
- z5.object({
1117
+ var chunkSchema = z7.object({
1118
+ candidates: z7.array(
1119
+ z7.object({
1050
1120
  content: contentSchema.nullish(),
1051
- finishReason: z5.string().nullish(),
1052
- safetyRatings: z5.array(safetyRatingSchema).nullish(),
1053
- groundingMetadata: groundingMetadataSchema.nullish()
1121
+ finishReason: z7.string().nullish(),
1122
+ safetyRatings: z7.array(safetyRatingSchema).nullish(),
1123
+ groundingMetadata: groundingMetadataSchema.nullish(),
1124
+ urlContextMetadata: urlContextMetadataSchema.nullish()
1054
1125
  })
1055
1126
  ).nullish(),
1056
1127
  usageMetadata: usageSchema.nullish()
1057
1128
  });
1058
1129
 
1130
+ // src/google-tools.ts
1131
+ var googleTools = {
1132
+ /**
1133
+ * Creates a Google search tool that gives Google direct access to real-time web content.
1134
+ * Must have name "google_search".
1135
+ */
1136
+ googleSearch,
1137
+ /**
1138
+ * Creates a URL context tool that gives Google direct access to real-time web content.
1139
+ * Must have name "url_context".
1140
+ */
1141
+ urlContext
1142
+ };
1143
+
1144
+ // src/google-generative-ai-image-model.ts
1145
+ import {
1146
+ combineHeaders as combineHeaders3,
1147
+ createJsonResponseHandler as createJsonResponseHandler3,
1148
+ parseProviderOptions as parseProviderOptions3,
1149
+ postJsonToApi as postJsonToApi3,
1150
+ resolve as resolve3
1151
+ } from "@ai-sdk/provider-utils";
1152
+ import { z as z8 } from "zod/v4";
1153
+ var GoogleGenerativeAIImageModel = class {
1154
+ constructor(modelId, settings, config) {
1155
+ this.modelId = modelId;
1156
+ this.settings = settings;
1157
+ this.config = config;
1158
+ this.specificationVersion = "v2";
1159
+ }
1160
+ get maxImagesPerCall() {
1161
+ var _a;
1162
+ return (_a = this.settings.maxImagesPerCall) != null ? _a : 4;
1163
+ }
1164
+ get provider() {
1165
+ return this.config.provider;
1166
+ }
1167
+ async doGenerate(options) {
1168
+ var _a, _b, _c;
1169
+ const {
1170
+ prompt,
1171
+ n = 1,
1172
+ size = "1024x1024",
1173
+ aspectRatio = "1:1",
1174
+ seed,
1175
+ providerOptions,
1176
+ headers,
1177
+ abortSignal
1178
+ } = options;
1179
+ const warnings = [];
1180
+ if (size != null) {
1181
+ warnings.push({
1182
+ type: "unsupported-setting",
1183
+ setting: "size",
1184
+ details: "This model does not support the `size` option. Use `aspectRatio` instead."
1185
+ });
1186
+ }
1187
+ if (seed != null) {
1188
+ warnings.push({
1189
+ type: "unsupported-setting",
1190
+ setting: "seed",
1191
+ details: "This model does not support the `seed` option through this provider."
1192
+ });
1193
+ }
1194
+ const googleOptions = await parseProviderOptions3({
1195
+ provider: "google",
1196
+ providerOptions,
1197
+ schema: googleImageProviderOptionsSchema
1198
+ });
1199
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1200
+ const parameters = {
1201
+ sampleCount: n
1202
+ };
1203
+ if (aspectRatio != null) {
1204
+ parameters.aspectRatio = aspectRatio;
1205
+ }
1206
+ if (googleOptions) {
1207
+ Object.assign(parameters, googleOptions);
1208
+ }
1209
+ const body = {
1210
+ instances: [{ prompt }],
1211
+ parameters
1212
+ };
1213
+ const { responseHeaders, value: response } = await postJsonToApi3({
1214
+ url: `${this.config.baseURL}/models/${this.modelId}:predict`,
1215
+ headers: combineHeaders3(await resolve3(this.config.headers), headers),
1216
+ body,
1217
+ failedResponseHandler: googleFailedResponseHandler,
1218
+ successfulResponseHandler: createJsonResponseHandler3(
1219
+ googleImageResponseSchema
1220
+ ),
1221
+ abortSignal,
1222
+ fetch: this.config.fetch
1223
+ });
1224
+ return {
1225
+ images: response.predictions.map(
1226
+ (p) => p.bytesBase64Encoded
1227
+ ),
1228
+ warnings: warnings != null ? warnings : [],
1229
+ providerMetadata: {
1230
+ google: {
1231
+ images: response.predictions.map((prediction) => ({
1232
+ // Add any prediction-specific metadata here
1233
+ }))
1234
+ }
1235
+ },
1236
+ response: {
1237
+ timestamp: currentDate,
1238
+ modelId: this.modelId,
1239
+ headers: responseHeaders
1240
+ }
1241
+ };
1242
+ }
1243
+ };
1244
+ var googleImageResponseSchema = z8.object({
1245
+ predictions: z8.array(z8.object({ bytesBase64Encoded: z8.string() })).default([])
1246
+ });
1247
+ var googleImageProviderOptionsSchema = z8.object({
1248
+ personGeneration: z8.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
1249
+ aspectRatio: z8.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
1250
+ });
1251
+
1059
1252
  // src/google-provider.ts
1060
1253
  function createGoogleGenerativeAI(options = {}) {
1061
1254
  var _a;
@@ -1074,7 +1267,7 @@ function createGoogleGenerativeAI(options = {}) {
1074
1267
  provider: "google.generative-ai",
1075
1268
  baseURL,
1076
1269
  headers: getHeaders,
1077
- generateId: (_a2 = options.generateId) != null ? _a2 : generateId,
1270
+ generateId: (_a2 = options.generateId) != null ? _a2 : generateId2,
1078
1271
  supportedUrls: () => ({
1079
1272
  "*": [
1080
1273
  // Only allow requests to the Google Generative Language "files" endpoint
@@ -1091,6 +1284,12 @@ function createGoogleGenerativeAI(options = {}) {
1091
1284
  headers: getHeaders,
1092
1285
  fetch: options.fetch
1093
1286
  });
1287
+ const createImageModel = (modelId, settings = {}) => new GoogleGenerativeAIImageModel(modelId, settings, {
1288
+ provider: "google.generative-ai",
1289
+ baseURL,
1290
+ headers: getHeaders,
1291
+ fetch: options.fetch
1292
+ });
1094
1293
  const provider = function(modelId) {
1095
1294
  if (new.target) {
1096
1295
  throw new Error(
@@ -1105,9 +1304,9 @@ function createGoogleGenerativeAI(options = {}) {
1105
1304
  provider.embedding = createEmbeddingModel;
1106
1305
  provider.textEmbedding = createEmbeddingModel;
1107
1306
  provider.textEmbeddingModel = createEmbeddingModel;
1108
- provider.imageModel = (modelId) => {
1109
- throw new NoSuchModelError({ modelId, modelType: "imageModel" });
1110
- };
1307
+ provider.image = createImageModel;
1308
+ provider.imageModel = createImageModel;
1309
+ provider.tools = googleTools;
1111
1310
  return provider;
1112
1311
  }
1113
1312
  var google = createGoogleGenerativeAI();