@ai-sdk/google 2.0.0-beta.7 → 2.0.0-beta.9

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";
@@ -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/v4";
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) {
@@ -372,17 +370,6 @@ function getModelPath(modelId) {
372
370
 
373
371
  // src/google-generative-ai-options.ts
374
372
  import { z as z4 } from "zod/v4";
375
- var dynamicRetrievalConfig = z4.object({
376
- /**
377
- * The mode of the predictor to be used in dynamic retrieval.
378
- */
379
- mode: z4.enum(["MODE_UNSPECIFIED", "MODE_DYNAMIC"]).optional(),
380
- /**
381
- * The threshold to be used in dynamic retrieval. If not set, a system default
382
- * value is used.
383
- */
384
- dynamicThreshold: z4.number().optional()
385
- });
386
373
  var googleGenerativeAIProviderOptions = z4.object({
387
374
  responseModalities: z4.array(z4.enum(["TEXT", "IMAGE"])).optional(),
388
375
  thinkingConfig: z4.object({
@@ -440,21 +427,7 @@ var googleGenerativeAIProviderOptions = z4.object({
440
427
  *
441
428
  * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
442
429
  */
443
- audioTimestamp: z4.boolean().optional(),
444
- /**
445
- Optional. When enabled, the model will use Google search to ground the response.
446
-
447
- @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview
448
- */
449
- useSearchGrounding: z4.boolean().optional(),
450
- /**
451
- Optional. Specifies the dynamic retrieval configuration.
452
-
453
- @note Dynamic retrieval is only compatible with Gemini 1.5 Flash.
454
-
455
- @see https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/ground-with-google-search#dynamic-retrieval
456
- */
457
- dynamicRetrievalConfig: dynamicRetrievalConfig.optional()
430
+ audioTimestamp: z4.boolean().optional()
458
431
  });
459
432
 
460
433
  // src/google-prepare-tools.ts
@@ -464,8 +437,6 @@ import {
464
437
  function prepareTools({
465
438
  tools,
466
439
  toolChoice,
467
- useSearchGrounding,
468
- dynamicRetrievalConfig: dynamicRetrievalConfig2,
469
440
  modelId
470
441
  }) {
471
442
  var _a;
@@ -473,28 +444,76 @@ function prepareTools({
473
444
  const toolWarnings = [];
474
445
  const isGemini2 = modelId.includes("gemini-2");
475
446
  const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
476
- 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
+ });
477
498
  return {
478
- tools: isGemini2 ? { googleSearch: {} } : {
479
- googleSearchRetrieval: !supportsDynamicRetrieval || !dynamicRetrievalConfig2 ? {} : { dynamicRetrievalConfig: dynamicRetrievalConfig2 }
480
- },
499
+ tools: Object.keys(googleTools2).length > 0 ? googleTools2 : void 0,
481
500
  toolConfig: void 0,
482
501
  toolWarnings
483
502
  };
484
503
  }
485
- if (tools == null) {
486
- return { tools: void 0, toolConfig: void 0, toolWarnings };
487
- }
488
504
  const functionDeclarations = [];
489
505
  for (const tool of tools) {
490
- if (tool.type === "provider-defined") {
491
- toolWarnings.push({ type: "unsupported-tool", tool });
492
- } else {
493
- functionDeclarations.push({
494
- name: tool.name,
495
- description: (_a = tool.description) != null ? _a : "",
496
- parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
497
- });
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;
498
517
  }
499
518
  }
500
519
  if (toolChoice == null) {
@@ -571,12 +590,72 @@ function mapGoogleGenerativeAIFinishReason({
571
590
  }
572
591
  }
573
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
+
574
651
  // src/google-generative-ai-language-model.ts
575
652
  var GoogleGenerativeAILanguageModel = class {
576
653
  constructor(modelId, config) {
577
654
  this.specificationVersion = "v2";
655
+ var _a;
578
656
  this.modelId = modelId;
579
657
  this.config = config;
658
+ this.generateId = (_a = config.generateId) != null ? _a : generateId;
580
659
  }
581
660
  get provider() {
582
661
  return this.config.provider;
@@ -600,7 +679,7 @@ var GoogleGenerativeAILanguageModel = class {
600
679
  toolChoice,
601
680
  providerOptions
602
681
  }) {
603
- var _a, _b, _c;
682
+ var _a, _b;
604
683
  const warnings = [];
605
684
  const googleOptions = await parseProviderOptions2({
606
685
  provider: "google",
@@ -619,14 +698,12 @@ var GoogleGenerativeAILanguageModel = class {
619
698
  { isGemmaModel }
620
699
  );
621
700
  const {
622
- tools: googleTools,
701
+ tools: googleTools2,
623
702
  toolConfig: googleToolConfig,
624
703
  toolWarnings
625
704
  } = prepareTools({
626
705
  tools,
627
706
  toolChoice,
628
- useSearchGrounding: (_b = googleOptions == null ? void 0 : googleOptions.useSearchGrounding) != null ? _b : false,
629
- dynamicRetrievalConfig: googleOptions == null ? void 0 : googleOptions.dynamicRetrievalConfig,
630
707
  modelId: this.modelId
631
708
  });
632
709
  return {
@@ -646,7 +723,7 @@ var GoogleGenerativeAILanguageModel = class {
646
723
  responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
647
724
  // so this is needed as an escape hatch:
648
725
  // TODO convert into provider option
649
- ((_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,
650
727
  ...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
651
728
  audioTimestamp: googleOptions.audioTimestamp
652
729
  },
@@ -657,7 +734,7 @@ var GoogleGenerativeAILanguageModel = class {
657
734
  contents,
658
735
  systemInstruction: isGemmaModel ? void 0 : systemInstruction,
659
736
  safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
660
- tools: googleTools,
737
+ tools: googleTools2,
661
738
  toolConfig: googleToolConfig,
662
739
  cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent
663
740
  },
@@ -665,7 +742,7 @@ var GoogleGenerativeAILanguageModel = class {
665
742
  };
666
743
  }
667
744
  async doGenerate(options) {
668
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
745
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
669
746
  const { args, warnings } = await this.getArgs(options);
670
747
  const body = JSON.stringify(args);
671
748
  const mergedHeaders = combineHeaders2(
@@ -737,7 +814,8 @@ var GoogleGenerativeAILanguageModel = class {
737
814
  providerMetadata: {
738
815
  google: {
739
816
  groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
740
- safetyRatings: (_i = candidate.safetyRatings) != null ? _i : null,
817
+ urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
818
+ safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
741
819
  usageMetadata: usageMetadata != null ? usageMetadata : null
742
820
  }
743
821
  },
@@ -774,7 +852,7 @@ var GoogleGenerativeAILanguageModel = class {
774
852
  totalTokens: void 0
775
853
  };
776
854
  let providerMetadata = void 0;
777
- const generateId2 = this.config.generateId;
855
+ const generateId3 = this.config.generateId;
778
856
  let hasToolCalls = false;
779
857
  let currentTextBlockId = null;
780
858
  let currentReasoningBlockId = null;
@@ -786,7 +864,7 @@ var GoogleGenerativeAILanguageModel = class {
786
864
  controller.enqueue({ type: "stream-start", warnings });
787
865
  },
788
866
  transform(chunk, controller) {
789
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
867
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
790
868
  if (options.includeRawChunks) {
791
869
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
792
870
  }
@@ -867,7 +945,7 @@ var GoogleGenerativeAILanguageModel = class {
867
945
  }
868
946
  const toolCallDeltas = getToolCallsFromParts({
869
947
  parts: content.parts,
870
- generateId: generateId2
948
+ generateId: generateId3
871
949
  });
872
950
  if (toolCallDeltas != null) {
873
951
  for (const toolCall of toolCallDeltas) {
@@ -902,7 +980,7 @@ var GoogleGenerativeAILanguageModel = class {
902
980
  });
903
981
  const sources = (_h = extractSources({
904
982
  groundingMetadata: candidate.groundingMetadata,
905
- generateId: generateId2
983
+ generateId: generateId3
906
984
  })) != null ? _h : [];
907
985
  for (const source of sources) {
908
986
  controller.enqueue(source);
@@ -910,7 +988,8 @@ var GoogleGenerativeAILanguageModel = class {
910
988
  providerMetadata = {
911
989
  google: {
912
990
  groundingMetadata: (_i = candidate.groundingMetadata) != null ? _i : null,
913
- safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null
991
+ urlContextMetadata: (_j = candidate.urlContextMetadata) != null ? _j : null,
992
+ safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null
914
993
  }
915
994
  };
916
995
  if (usageMetadata != null) {
@@ -947,14 +1026,14 @@ var GoogleGenerativeAILanguageModel = class {
947
1026
  };
948
1027
  function getToolCallsFromParts({
949
1028
  parts,
950
- generateId: generateId2
1029
+ generateId: generateId3
951
1030
  }) {
952
1031
  const functionCallParts = parts == null ? void 0 : parts.filter(
953
1032
  (part) => "functionCall" in part
954
1033
  );
955
1034
  return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
956
1035
  type: "tool-call",
957
- toolCallId: generateId2(),
1036
+ toolCallId: generateId3(),
958
1037
  toolName: part.functionCall.name,
959
1038
  args: JSON.stringify(part.functionCall.args)
960
1039
  }));
@@ -966,7 +1045,7 @@ function getInlineDataParts(parts) {
966
1045
  }
967
1046
  function extractSources({
968
1047
  groundingMetadata,
969
- generateId: generateId2
1048
+ generateId: generateId3
970
1049
  }) {
971
1050
  var _a;
972
1051
  return (_a = groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks) == null ? void 0 : _a.filter(
@@ -974,102 +1053,196 @@ function extractSources({
974
1053
  ).map((chunk) => ({
975
1054
  type: "source",
976
1055
  sourceType: "url",
977
- id: generateId2(),
1056
+ id: generateId3(),
978
1057
  url: chunk.web.uri,
979
1058
  title: chunk.web.title
980
1059
  }));
981
1060
  }
982
- var contentSchema = z5.object({
983
- parts: z5.array(
984
- z5.union([
1061
+ var contentSchema = z7.object({
1062
+ parts: z7.array(
1063
+ z7.union([
985
1064
  // note: order matters since text can be fully empty
986
- z5.object({
987
- functionCall: z5.object({
988
- name: z5.string(),
989
- args: z5.unknown()
1065
+ z7.object({
1066
+ functionCall: z7.object({
1067
+ name: z7.string(),
1068
+ args: z7.unknown()
990
1069
  })
991
1070
  }),
992
- z5.object({
993
- inlineData: z5.object({
994
- mimeType: z5.string(),
995
- data: z5.string()
1071
+ z7.object({
1072
+ inlineData: z7.object({
1073
+ mimeType: z7.string(),
1074
+ data: z7.string()
996
1075
  })
997
1076
  }),
998
- z5.object({
999
- text: z5.string().nullish(),
1000
- thought: z5.boolean().nullish()
1077
+ z7.object({
1078
+ text: z7.string().nullish(),
1079
+ thought: z7.boolean().nullish()
1001
1080
  })
1002
1081
  ])
1003
1082
  ).nullish()
1004
1083
  });
1005
- var groundingChunkSchema = z5.object({
1006
- web: z5.object({ uri: z5.string(), title: z5.string() }).nullish(),
1007
- retrievedContext: z5.object({ uri: z5.string(), title: z5.string() }).nullish()
1008
- });
1009
- var groundingMetadataSchema = z5.object({
1010
- webSearchQueries: z5.array(z5.string()).nullish(),
1011
- retrievalQueries: z5.array(z5.string()).nullish(),
1012
- searchEntryPoint: z5.object({ renderedContent: z5.string() }).nullish(),
1013
- groundingChunks: z5.array(groundingChunkSchema).nullish(),
1014
- groundingSupports: z5.array(
1015
- z5.object({
1016
- segment: z5.object({
1017
- startIndex: z5.number().nullish(),
1018
- endIndex: z5.number().nullish(),
1019
- text: z5.string().nullish()
1020
- }),
1021
- segment_text: z5.string().nullish(),
1022
- groundingChunkIndices: z5.array(z5.number()).nullish(),
1023
- supportChunkIndices: z5.array(z5.number()).nullish(),
1024
- confidenceScores: z5.array(z5.number()).nullish(),
1025
- confidenceScore: z5.array(z5.number()).nullish()
1026
- })
1027
- ).nullish(),
1028
- retrievalMetadata: z5.union([
1029
- z5.object({
1030
- webDynamicRetrievalScore: z5.number()
1031
- }),
1032
- z5.object({})
1033
- ]).nullish()
1034
- });
1035
- var safetyRatingSchema = z5.object({
1036
- category: z5.string().nullish(),
1037
- probability: z5.string().nullish(),
1038
- probabilityScore: z5.number().nullish(),
1039
- severity: z5.string().nullish(),
1040
- severityScore: z5.number().nullish(),
1041
- blocked: z5.boolean().nullish()
1084
+ var safetyRatingSchema = z7.object({
1085
+ category: z7.string().nullish(),
1086
+ probability: z7.string().nullish(),
1087
+ probabilityScore: z7.number().nullish(),
1088
+ severity: z7.string().nullish(),
1089
+ severityScore: z7.number().nullish(),
1090
+ blocked: z7.boolean().nullish()
1042
1091
  });
1043
- var usageSchema = z5.object({
1044
- cachedContentTokenCount: z5.number().nullish(),
1045
- thoughtsTokenCount: z5.number().nullish(),
1046
- promptTokenCount: z5.number().nullish(),
1047
- candidatesTokenCount: z5.number().nullish(),
1048
- totalTokenCount: z5.number().nullish()
1092
+ var usageSchema = z7.object({
1093
+ cachedContentTokenCount: z7.number().nullish(),
1094
+ thoughtsTokenCount: z7.number().nullish(),
1095
+ promptTokenCount: z7.number().nullish(),
1096
+ candidatesTokenCount: z7.number().nullish(),
1097
+ totalTokenCount: z7.number().nullish()
1049
1098
  });
1050
- var responseSchema = z5.object({
1051
- candidates: z5.array(
1052
- z5.object({
1053
- content: contentSchema.nullish().or(z5.object({}).strict()),
1054
- finishReason: z5.string().nullish(),
1055
- safetyRatings: z5.array(safetyRatingSchema).nullish(),
1056
- groundingMetadata: groundingMetadataSchema.nullish()
1099
+ var responseSchema = z7.object({
1100
+ candidates: z7.array(
1101
+ z7.object({
1102
+ content: contentSchema.nullish().or(z7.object({}).strict()),
1103
+ finishReason: z7.string().nullish(),
1104
+ safetyRatings: z7.array(safetyRatingSchema).nullish(),
1105
+ groundingMetadata: groundingMetadataSchema.nullish(),
1106
+ urlContextMetadata: urlContextMetadataSchema.nullish()
1057
1107
  })
1058
1108
  ),
1059
1109
  usageMetadata: usageSchema.nullish()
1060
1110
  });
1061
- var chunkSchema = z5.object({
1062
- candidates: z5.array(
1063
- z5.object({
1111
+ var chunkSchema = z7.object({
1112
+ candidates: z7.array(
1113
+ z7.object({
1064
1114
  content: contentSchema.nullish(),
1065
- finishReason: z5.string().nullish(),
1066
- safetyRatings: z5.array(safetyRatingSchema).nullish(),
1067
- groundingMetadata: groundingMetadataSchema.nullish()
1115
+ finishReason: z7.string().nullish(),
1116
+ safetyRatings: z7.array(safetyRatingSchema).nullish(),
1117
+ groundingMetadata: groundingMetadataSchema.nullish(),
1118
+ urlContextMetadata: urlContextMetadataSchema.nullish()
1068
1119
  })
1069
1120
  ).nullish(),
1070
1121
  usageMetadata: usageSchema.nullish()
1071
1122
  });
1072
1123
 
1124
+ // src/google-tools.ts
1125
+ var googleTools = {
1126
+ /**
1127
+ * Creates a Google search tool that gives Google direct access to real-time web content.
1128
+ * Must have name "google_search".
1129
+ */
1130
+ googleSearch,
1131
+ /**
1132
+ * Creates a URL context tool that gives Google direct access to real-time web content.
1133
+ * Must have name "url_context".
1134
+ */
1135
+ urlContext
1136
+ };
1137
+
1138
+ // src/google-generative-ai-image-model.ts
1139
+ import {
1140
+ combineHeaders as combineHeaders3,
1141
+ createJsonResponseHandler as createJsonResponseHandler3,
1142
+ parseProviderOptions as parseProviderOptions3,
1143
+ postJsonToApi as postJsonToApi3,
1144
+ resolve as resolve3
1145
+ } from "@ai-sdk/provider-utils";
1146
+ import { z as z8 } from "zod/v4";
1147
+ var GoogleGenerativeAIImageModel = class {
1148
+ constructor(modelId, settings, config) {
1149
+ this.modelId = modelId;
1150
+ this.settings = settings;
1151
+ this.config = config;
1152
+ this.specificationVersion = "v2";
1153
+ }
1154
+ get maxImagesPerCall() {
1155
+ var _a;
1156
+ return (_a = this.settings.maxImagesPerCall) != null ? _a : 4;
1157
+ }
1158
+ get provider() {
1159
+ return this.config.provider;
1160
+ }
1161
+ async doGenerate(options) {
1162
+ var _a, _b, _c;
1163
+ const {
1164
+ prompt,
1165
+ n = 1,
1166
+ size = "1024x1024",
1167
+ aspectRatio = "1:1",
1168
+ seed,
1169
+ providerOptions,
1170
+ headers,
1171
+ abortSignal
1172
+ } = options;
1173
+ const warnings = [];
1174
+ if (size != null) {
1175
+ warnings.push({
1176
+ type: "unsupported-setting",
1177
+ setting: "size",
1178
+ details: "This model does not support the `size` option. Use `aspectRatio` instead."
1179
+ });
1180
+ }
1181
+ if (seed != null) {
1182
+ warnings.push({
1183
+ type: "unsupported-setting",
1184
+ setting: "seed",
1185
+ details: "This model does not support the `seed` option through this provider."
1186
+ });
1187
+ }
1188
+ const googleOptions = await parseProviderOptions3({
1189
+ provider: "google",
1190
+ providerOptions,
1191
+ schema: googleImageProviderOptionsSchema
1192
+ });
1193
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1194
+ const parameters = {
1195
+ sampleCount: n
1196
+ };
1197
+ if (aspectRatio != null) {
1198
+ parameters.aspectRatio = aspectRatio;
1199
+ }
1200
+ if (googleOptions) {
1201
+ Object.assign(parameters, googleOptions);
1202
+ }
1203
+ const body = {
1204
+ instances: [{ prompt }],
1205
+ parameters
1206
+ };
1207
+ const { responseHeaders, value: response } = await postJsonToApi3({
1208
+ url: `${this.config.baseURL}/models/${this.modelId}:predict`,
1209
+ headers: combineHeaders3(await resolve3(this.config.headers), headers),
1210
+ body,
1211
+ failedResponseHandler: googleFailedResponseHandler,
1212
+ successfulResponseHandler: createJsonResponseHandler3(
1213
+ googleImageResponseSchema
1214
+ ),
1215
+ abortSignal,
1216
+ fetch: this.config.fetch
1217
+ });
1218
+ return {
1219
+ images: response.predictions.map(
1220
+ (p) => p.bytesBase64Encoded
1221
+ ),
1222
+ warnings: warnings != null ? warnings : [],
1223
+ providerMetadata: {
1224
+ google: {
1225
+ images: response.predictions.map((prediction) => ({
1226
+ // Add any prediction-specific metadata here
1227
+ }))
1228
+ }
1229
+ },
1230
+ response: {
1231
+ timestamp: currentDate,
1232
+ modelId: this.modelId,
1233
+ headers: responseHeaders
1234
+ }
1235
+ };
1236
+ }
1237
+ };
1238
+ var googleImageResponseSchema = z8.object({
1239
+ predictions: z8.array(z8.object({ bytesBase64Encoded: z8.string() })).default([])
1240
+ });
1241
+ var googleImageProviderOptionsSchema = z8.object({
1242
+ personGeneration: z8.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
1243
+ aspectRatio: z8.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
1244
+ });
1245
+
1073
1246
  // src/google-provider.ts
1074
1247
  function createGoogleGenerativeAI(options = {}) {
1075
1248
  var _a;
@@ -1088,7 +1261,7 @@ function createGoogleGenerativeAI(options = {}) {
1088
1261
  provider: "google.generative-ai",
1089
1262
  baseURL,
1090
1263
  headers: getHeaders,
1091
- generateId: (_a2 = options.generateId) != null ? _a2 : generateId,
1264
+ generateId: (_a2 = options.generateId) != null ? _a2 : generateId2,
1092
1265
  supportedUrls: () => ({
1093
1266
  "*": [
1094
1267
  // Only allow requests to the Google Generative Language "files" endpoint
@@ -1105,6 +1278,12 @@ function createGoogleGenerativeAI(options = {}) {
1105
1278
  headers: getHeaders,
1106
1279
  fetch: options.fetch
1107
1280
  });
1281
+ const createImageModel = (modelId, settings = {}) => new GoogleGenerativeAIImageModel(modelId, settings, {
1282
+ provider: "google.generative-ai",
1283
+ baseURL,
1284
+ headers: getHeaders,
1285
+ fetch: options.fetch
1286
+ });
1108
1287
  const provider = function(modelId) {
1109
1288
  if (new.target) {
1110
1289
  throw new Error(
@@ -1119,9 +1298,9 @@ function createGoogleGenerativeAI(options = {}) {
1119
1298
  provider.embedding = createEmbeddingModel;
1120
1299
  provider.textEmbedding = createEmbeddingModel;
1121
1300
  provider.textEmbeddingModel = createEmbeddingModel;
1122
- provider.imageModel = (modelId) => {
1123
- throw new NoSuchModelError({ modelId, modelType: "imageModel" });
1124
- };
1301
+ provider.image = createImageModel;
1302
+ provider.imageModel = createImageModel;
1303
+ provider.tools = googleTools;
1125
1304
  return provider;
1126
1305
  }
1127
1306
  var google = createGoogleGenerativeAI();