@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.js CHANGED
@@ -26,8 +26,7 @@ __export(src_exports, {
26
26
  module.exports = __toCommonJS(src_exports);
27
27
 
28
28
  // src/google-provider.ts
29
- var import_provider4 = require("@ai-sdk/provider");
30
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
29
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
31
30
 
32
31
  // src/google-generative-ai-embedding-model.ts
33
32
  var import_provider = require("@ai-sdk/provider");
@@ -150,8 +149,8 @@ var googleGenerativeAITextEmbeddingResponseSchema = import_v43.z.object({
150
149
  });
151
150
 
152
151
  // src/google-generative-ai-language-model.ts
153
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
154
- var import_v45 = require("zod/v4");
152
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
153
+ var import_v47 = require("zod/v4");
155
154
 
156
155
  // src/convert-json-schema-to-openapi-schema.ts
157
156
  function convertJSONSchemaToOpenAPISchema(jsonSchema) {
@@ -376,17 +375,6 @@ function getModelPath(modelId) {
376
375
 
377
376
  // src/google-generative-ai-options.ts
378
377
  var import_v44 = require("zod/v4");
379
- var dynamicRetrievalConfig = import_v44.z.object({
380
- /**
381
- * The mode of the predictor to be used in dynamic retrieval.
382
- */
383
- mode: import_v44.z.enum(["MODE_UNSPECIFIED", "MODE_DYNAMIC"]).optional(),
384
- /**
385
- * The threshold to be used in dynamic retrieval. If not set, a system default
386
- * value is used.
387
- */
388
- dynamicThreshold: import_v44.z.number().optional()
389
- });
390
378
  var googleGenerativeAIProviderOptions = import_v44.z.object({
391
379
  responseModalities: import_v44.z.array(import_v44.z.enum(["TEXT", "IMAGE"])).optional(),
392
380
  thinkingConfig: import_v44.z.object({
@@ -444,21 +432,7 @@ var googleGenerativeAIProviderOptions = import_v44.z.object({
444
432
  *
445
433
  * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
446
434
  */
447
- audioTimestamp: import_v44.z.boolean().optional(),
448
- /**
449
- Optional. When enabled, the model will use Google search to ground the response.
450
-
451
- @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview
452
- */
453
- useSearchGrounding: import_v44.z.boolean().optional(),
454
- /**
455
- Optional. Specifies the dynamic retrieval configuration.
456
-
457
- @note Dynamic retrieval is only compatible with Gemini 1.5 Flash.
458
-
459
- @see https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/ground-with-google-search#dynamic-retrieval
460
- */
461
- dynamicRetrievalConfig: dynamicRetrievalConfig.optional()
435
+ audioTimestamp: import_v44.z.boolean().optional()
462
436
  });
463
437
 
464
438
  // src/google-prepare-tools.ts
@@ -466,8 +440,6 @@ var import_provider3 = require("@ai-sdk/provider");
466
440
  function prepareTools({
467
441
  tools,
468
442
  toolChoice,
469
- useSearchGrounding,
470
- dynamicRetrievalConfig: dynamicRetrievalConfig2,
471
443
  modelId
472
444
  }) {
473
445
  var _a;
@@ -475,28 +447,76 @@ function prepareTools({
475
447
  const toolWarnings = [];
476
448
  const isGemini2 = modelId.includes("gemini-2");
477
449
  const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
478
- if (useSearchGrounding) {
450
+ if (tools == null) {
451
+ return { tools: void 0, toolConfig: void 0, toolWarnings };
452
+ }
453
+ const hasFunctionTools = tools.some((tool) => tool.type === "function");
454
+ const hasProviderDefinedTools = tools.some(
455
+ (tool) => tool.type === "provider-defined"
456
+ );
457
+ if (hasFunctionTools && hasProviderDefinedTools) {
458
+ toolWarnings.push({
459
+ type: "unsupported-tool",
460
+ tool: tools.find((tool) => tool.type === "function"),
461
+ 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."
462
+ });
463
+ }
464
+ if (hasProviderDefinedTools) {
465
+ const googleTools2 = {};
466
+ const providerDefinedTools = tools.filter(
467
+ (tool) => tool.type === "provider-defined"
468
+ );
469
+ providerDefinedTools.forEach((tool) => {
470
+ switch (tool.id) {
471
+ case "google.google_search":
472
+ if (isGemini2) {
473
+ googleTools2.googleSearch = {};
474
+ } else if (supportsDynamicRetrieval) {
475
+ googleTools2.googleSearchRetrieval = {
476
+ dynamicRetrievalConfig: {
477
+ mode: tool.args.mode,
478
+ dynamicThreshold: tool.args.dynamicThreshold
479
+ }
480
+ };
481
+ } else {
482
+ googleTools2.googleSearchRetrieval = {};
483
+ }
484
+ break;
485
+ case "google.url_context":
486
+ if (isGemini2) {
487
+ googleTools2.urlContext = {};
488
+ } else {
489
+ toolWarnings.push({
490
+ type: "unsupported-tool",
491
+ tool,
492
+ details: "The URL context tool is not supported with other Gemini models than Gemini 2."
493
+ });
494
+ }
495
+ break;
496
+ default:
497
+ toolWarnings.push({ type: "unsupported-tool", tool });
498
+ break;
499
+ }
500
+ });
479
501
  return {
480
- tools: isGemini2 ? { googleSearch: {} } : {
481
- googleSearchRetrieval: !supportsDynamicRetrieval || !dynamicRetrievalConfig2 ? {} : { dynamicRetrievalConfig: dynamicRetrievalConfig2 }
482
- },
502
+ tools: Object.keys(googleTools2).length > 0 ? googleTools2 : void 0,
483
503
  toolConfig: void 0,
484
504
  toolWarnings
485
505
  };
486
506
  }
487
- if (tools == null) {
488
- return { tools: void 0, toolConfig: void 0, toolWarnings };
489
- }
490
507
  const functionDeclarations = [];
491
508
  for (const tool of tools) {
492
- if (tool.type === "provider-defined") {
493
- toolWarnings.push({ type: "unsupported-tool", tool });
494
- } else {
495
- functionDeclarations.push({
496
- name: tool.name,
497
- description: (_a = tool.description) != null ? _a : "",
498
- parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
499
- });
509
+ switch (tool.type) {
510
+ case "function":
511
+ functionDeclarations.push({
512
+ name: tool.name,
513
+ description: (_a = tool.description) != null ? _a : "",
514
+ parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
515
+ });
516
+ break;
517
+ default:
518
+ toolWarnings.push({ type: "unsupported-tool", tool });
519
+ break;
500
520
  }
501
521
  }
502
522
  if (toolChoice == null) {
@@ -573,12 +593,72 @@ function mapGoogleGenerativeAIFinishReason({
573
593
  }
574
594
  }
575
595
 
596
+ // src/tool/google-search.ts
597
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
598
+ var import_v45 = require("zod/v4");
599
+ var groundingChunkSchema = import_v45.z.object({
600
+ web: import_v45.z.object({ uri: import_v45.z.string(), title: import_v45.z.string() }).nullish(),
601
+ retrievedContext: import_v45.z.object({ uri: import_v45.z.string(), title: import_v45.z.string() }).nullish()
602
+ });
603
+ var groundingMetadataSchema = import_v45.z.object({
604
+ webSearchQueries: import_v45.z.array(import_v45.z.string()).nullish(),
605
+ retrievalQueries: import_v45.z.array(import_v45.z.string()).nullish(),
606
+ searchEntryPoint: import_v45.z.object({ renderedContent: import_v45.z.string() }).nullish(),
607
+ groundingChunks: import_v45.z.array(groundingChunkSchema).nullish(),
608
+ groundingSupports: import_v45.z.array(
609
+ import_v45.z.object({
610
+ segment: import_v45.z.object({
611
+ startIndex: import_v45.z.number().nullish(),
612
+ endIndex: import_v45.z.number().nullish(),
613
+ text: import_v45.z.string().nullish()
614
+ }),
615
+ segment_text: import_v45.z.string().nullish(),
616
+ groundingChunkIndices: import_v45.z.array(import_v45.z.number()).nullish(),
617
+ supportChunkIndices: import_v45.z.array(import_v45.z.number()).nullish(),
618
+ confidenceScores: import_v45.z.array(import_v45.z.number()).nullish(),
619
+ confidenceScore: import_v45.z.array(import_v45.z.number()).nullish()
620
+ })
621
+ ).nullish(),
622
+ retrievalMetadata: import_v45.z.union([
623
+ import_v45.z.object({
624
+ webDynamicRetrievalScore: import_v45.z.number()
625
+ }),
626
+ import_v45.z.object({})
627
+ ]).nullish()
628
+ });
629
+ var googleSearch = (0, import_provider_utils4.createProviderDefinedToolFactory)({
630
+ id: "google.google_search",
631
+ name: "google_search",
632
+ inputSchema: import_v45.z.object({
633
+ mode: import_v45.z.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
634
+ dynamicThreshold: import_v45.z.number().default(1)
635
+ })
636
+ });
637
+
638
+ // src/tool/url-context.ts
639
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
640
+ var import_v46 = require("zod/v4");
641
+ var urlMetadataSchema = import_v46.z.object({
642
+ retrievedUrl: import_v46.z.string(),
643
+ urlRetrievalStatus: import_v46.z.string()
644
+ });
645
+ var urlContextMetadataSchema = import_v46.z.object({
646
+ urlMetadata: import_v46.z.array(urlMetadataSchema)
647
+ });
648
+ var urlContext = (0, import_provider_utils5.createProviderDefinedToolFactory)({
649
+ id: "google.url_context",
650
+ name: "url_context",
651
+ inputSchema: import_v46.z.object({})
652
+ });
653
+
576
654
  // src/google-generative-ai-language-model.ts
577
655
  var GoogleGenerativeAILanguageModel = class {
578
656
  constructor(modelId, config) {
579
657
  this.specificationVersion = "v2";
658
+ var _a;
580
659
  this.modelId = modelId;
581
660
  this.config = config;
661
+ this.generateId = (_a = config.generateId) != null ? _a : import_provider_utils6.generateId;
582
662
  }
583
663
  get provider() {
584
664
  return this.config.provider;
@@ -602,9 +682,9 @@ var GoogleGenerativeAILanguageModel = class {
602
682
  toolChoice,
603
683
  providerOptions
604
684
  }) {
605
- var _a, _b, _c;
685
+ var _a, _b;
606
686
  const warnings = [];
607
- const googleOptions = await (0, import_provider_utils4.parseProviderOptions)({
687
+ const googleOptions = await (0, import_provider_utils6.parseProviderOptions)({
608
688
  provider: "google",
609
689
  providerOptions,
610
690
  schema: googleGenerativeAIProviderOptions
@@ -621,14 +701,12 @@ var GoogleGenerativeAILanguageModel = class {
621
701
  { isGemmaModel }
622
702
  );
623
703
  const {
624
- tools: googleTools,
704
+ tools: googleTools2,
625
705
  toolConfig: googleToolConfig,
626
706
  toolWarnings
627
707
  } = prepareTools({
628
708
  tools,
629
709
  toolChoice,
630
- useSearchGrounding: (_b = googleOptions == null ? void 0 : googleOptions.useSearchGrounding) != null ? _b : false,
631
- dynamicRetrievalConfig: googleOptions == null ? void 0 : googleOptions.dynamicRetrievalConfig,
632
710
  modelId: this.modelId
633
711
  });
634
712
  return {
@@ -648,7 +726,7 @@ var GoogleGenerativeAILanguageModel = class {
648
726
  responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
649
727
  // so this is needed as an escape hatch:
650
728
  // TODO convert into provider option
651
- ((_c = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _c : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
729
+ ((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
652
730
  ...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
653
731
  audioTimestamp: googleOptions.audioTimestamp
654
732
  },
@@ -659,7 +737,7 @@ var GoogleGenerativeAILanguageModel = class {
659
737
  contents,
660
738
  systemInstruction: isGemmaModel ? void 0 : systemInstruction,
661
739
  safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
662
- tools: googleTools,
740
+ tools: googleTools2,
663
741
  toolConfig: googleToolConfig,
664
742
  cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent
665
743
  },
@@ -667,25 +745,25 @@ var GoogleGenerativeAILanguageModel = class {
667
745
  };
668
746
  }
669
747
  async doGenerate(options) {
670
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
748
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
671
749
  const { args, warnings } = await this.getArgs(options);
672
750
  const body = JSON.stringify(args);
673
- const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
674
- await (0, import_provider_utils4.resolve)(this.config.headers),
751
+ const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
752
+ await (0, import_provider_utils6.resolve)(this.config.headers),
675
753
  options.headers
676
754
  );
677
755
  const {
678
756
  responseHeaders,
679
757
  value: response,
680
758
  rawValue: rawResponse
681
- } = await (0, import_provider_utils4.postJsonToApi)({
759
+ } = await (0, import_provider_utils6.postJsonToApi)({
682
760
  url: `${this.config.baseURL}/${getModelPath(
683
761
  this.modelId
684
762
  )}:generateContent`,
685
763
  headers: mergedHeaders,
686
764
  body: args,
687
765
  failedResponseHandler: googleFailedResponseHandler,
688
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(responseSchema),
766
+ successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(responseSchema),
689
767
  abortSignal: options.abortSignal,
690
768
  fetch: this.config.fetch
691
769
  });
@@ -739,7 +817,8 @@ var GoogleGenerativeAILanguageModel = class {
739
817
  providerMetadata: {
740
818
  google: {
741
819
  groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
742
- safetyRatings: (_i = candidate.safetyRatings) != null ? _i : null,
820
+ urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
821
+ safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
743
822
  usageMetadata: usageMetadata != null ? usageMetadata : null
744
823
  }
745
824
  },
@@ -754,18 +833,18 @@ var GoogleGenerativeAILanguageModel = class {
754
833
  async doStream(options) {
755
834
  const { args, warnings } = await this.getArgs(options);
756
835
  const body = JSON.stringify(args);
757
- const headers = (0, import_provider_utils4.combineHeaders)(
758
- await (0, import_provider_utils4.resolve)(this.config.headers),
836
+ const headers = (0, import_provider_utils6.combineHeaders)(
837
+ await (0, import_provider_utils6.resolve)(this.config.headers),
759
838
  options.headers
760
839
  );
761
- const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
840
+ const { responseHeaders, value: response } = await (0, import_provider_utils6.postJsonToApi)({
762
841
  url: `${this.config.baseURL}/${getModelPath(
763
842
  this.modelId
764
843
  )}:streamGenerateContent?alt=sse`,
765
844
  headers,
766
845
  body: args,
767
846
  failedResponseHandler: googleFailedResponseHandler,
768
- successfulResponseHandler: (0, import_provider_utils4.createEventSourceResponseHandler)(chunkSchema),
847
+ successfulResponseHandler: (0, import_provider_utils6.createEventSourceResponseHandler)(chunkSchema),
769
848
  abortSignal: options.abortSignal,
770
849
  fetch: this.config.fetch
771
850
  });
@@ -776,7 +855,7 @@ var GoogleGenerativeAILanguageModel = class {
776
855
  totalTokens: void 0
777
856
  };
778
857
  let providerMetadata = void 0;
779
- const generateId2 = this.config.generateId;
858
+ const generateId3 = this.config.generateId;
780
859
  let hasToolCalls = false;
781
860
  let currentTextBlockId = null;
782
861
  let currentReasoningBlockId = null;
@@ -788,7 +867,7 @@ var GoogleGenerativeAILanguageModel = class {
788
867
  controller.enqueue({ type: "stream-start", warnings });
789
868
  },
790
869
  transform(chunk, controller) {
791
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
870
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
792
871
  if (options.includeRawChunks) {
793
872
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
794
873
  }
@@ -869,7 +948,7 @@ var GoogleGenerativeAILanguageModel = class {
869
948
  }
870
949
  const toolCallDeltas = getToolCallsFromParts({
871
950
  parts: content.parts,
872
- generateId: generateId2
951
+ generateId: generateId3
873
952
  });
874
953
  if (toolCallDeltas != null) {
875
954
  for (const toolCall of toolCallDeltas) {
@@ -904,7 +983,7 @@ var GoogleGenerativeAILanguageModel = class {
904
983
  });
905
984
  const sources = (_h = extractSources({
906
985
  groundingMetadata: candidate.groundingMetadata,
907
- generateId: generateId2
986
+ generateId: generateId3
908
987
  })) != null ? _h : [];
909
988
  for (const source of sources) {
910
989
  controller.enqueue(source);
@@ -912,7 +991,8 @@ var GoogleGenerativeAILanguageModel = class {
912
991
  providerMetadata = {
913
992
  google: {
914
993
  groundingMetadata: (_i = candidate.groundingMetadata) != null ? _i : null,
915
- safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null
994
+ urlContextMetadata: (_j = candidate.urlContextMetadata) != null ? _j : null,
995
+ safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null
916
996
  }
917
997
  };
918
998
  if (usageMetadata != null) {
@@ -949,14 +1029,14 @@ var GoogleGenerativeAILanguageModel = class {
949
1029
  };
950
1030
  function getToolCallsFromParts({
951
1031
  parts,
952
- generateId: generateId2
1032
+ generateId: generateId3
953
1033
  }) {
954
1034
  const functionCallParts = parts == null ? void 0 : parts.filter(
955
1035
  (part) => "functionCall" in part
956
1036
  );
957
1037
  return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
958
1038
  type: "tool-call",
959
- toolCallId: generateId2(),
1039
+ toolCallId: generateId3(),
960
1040
  toolName: part.functionCall.name,
961
1041
  args: JSON.stringify(part.functionCall.args)
962
1042
  }));
@@ -968,7 +1048,7 @@ function getInlineDataParts(parts) {
968
1048
  }
969
1049
  function extractSources({
970
1050
  groundingMetadata,
971
- generateId: generateId2
1051
+ generateId: generateId3
972
1052
  }) {
973
1053
  var _a;
974
1054
  return (_a = groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks) == null ? void 0 : _a.filter(
@@ -976,108 +1056,196 @@ function extractSources({
976
1056
  ).map((chunk) => ({
977
1057
  type: "source",
978
1058
  sourceType: "url",
979
- id: generateId2(),
1059
+ id: generateId3(),
980
1060
  url: chunk.web.uri,
981
1061
  title: chunk.web.title
982
1062
  }));
983
1063
  }
984
- var contentSchema = import_v45.z.object({
985
- parts: import_v45.z.array(
986
- import_v45.z.union([
1064
+ var contentSchema = import_v47.z.object({
1065
+ parts: import_v47.z.array(
1066
+ import_v47.z.union([
987
1067
  // note: order matters since text can be fully empty
988
- import_v45.z.object({
989
- functionCall: import_v45.z.object({
990
- name: import_v45.z.string(),
991
- args: import_v45.z.unknown()
1068
+ import_v47.z.object({
1069
+ functionCall: import_v47.z.object({
1070
+ name: import_v47.z.string(),
1071
+ args: import_v47.z.unknown()
992
1072
  })
993
1073
  }),
994
- import_v45.z.object({
995
- inlineData: import_v45.z.object({
996
- mimeType: import_v45.z.string(),
997
- data: import_v45.z.string()
1074
+ import_v47.z.object({
1075
+ inlineData: import_v47.z.object({
1076
+ mimeType: import_v47.z.string(),
1077
+ data: import_v47.z.string()
998
1078
  })
999
1079
  }),
1000
- import_v45.z.object({
1001
- text: import_v45.z.string().nullish(),
1002
- thought: import_v45.z.boolean().nullish()
1080
+ import_v47.z.object({
1081
+ text: import_v47.z.string().nullish(),
1082
+ thought: import_v47.z.boolean().nullish()
1003
1083
  })
1004
1084
  ])
1005
1085
  ).nullish()
1006
1086
  });
1007
- var groundingChunkSchema = import_v45.z.object({
1008
- web: import_v45.z.object({ uri: import_v45.z.string(), title: import_v45.z.string() }).nullish(),
1009
- retrievedContext: import_v45.z.object({ uri: import_v45.z.string(), title: import_v45.z.string() }).nullish()
1010
- });
1011
- var groundingMetadataSchema = import_v45.z.object({
1012
- webSearchQueries: import_v45.z.array(import_v45.z.string()).nullish(),
1013
- retrievalQueries: import_v45.z.array(import_v45.z.string()).nullish(),
1014
- searchEntryPoint: import_v45.z.object({ renderedContent: import_v45.z.string() }).nullish(),
1015
- groundingChunks: import_v45.z.array(groundingChunkSchema).nullish(),
1016
- groundingSupports: import_v45.z.array(
1017
- import_v45.z.object({
1018
- segment: import_v45.z.object({
1019
- startIndex: import_v45.z.number().nullish(),
1020
- endIndex: import_v45.z.number().nullish(),
1021
- text: import_v45.z.string().nullish()
1022
- }),
1023
- segment_text: import_v45.z.string().nullish(),
1024
- groundingChunkIndices: import_v45.z.array(import_v45.z.number()).nullish(),
1025
- supportChunkIndices: import_v45.z.array(import_v45.z.number()).nullish(),
1026
- confidenceScores: import_v45.z.array(import_v45.z.number()).nullish(),
1027
- confidenceScore: import_v45.z.array(import_v45.z.number()).nullish()
1028
- })
1029
- ).nullish(),
1030
- retrievalMetadata: import_v45.z.union([
1031
- import_v45.z.object({
1032
- webDynamicRetrievalScore: import_v45.z.number()
1033
- }),
1034
- import_v45.z.object({})
1035
- ]).nullish()
1036
- });
1037
- var safetyRatingSchema = import_v45.z.object({
1038
- category: import_v45.z.string().nullish(),
1039
- probability: import_v45.z.string().nullish(),
1040
- probabilityScore: import_v45.z.number().nullish(),
1041
- severity: import_v45.z.string().nullish(),
1042
- severityScore: import_v45.z.number().nullish(),
1043
- blocked: import_v45.z.boolean().nullish()
1087
+ var safetyRatingSchema = import_v47.z.object({
1088
+ category: import_v47.z.string().nullish(),
1089
+ probability: import_v47.z.string().nullish(),
1090
+ probabilityScore: import_v47.z.number().nullish(),
1091
+ severity: import_v47.z.string().nullish(),
1092
+ severityScore: import_v47.z.number().nullish(),
1093
+ blocked: import_v47.z.boolean().nullish()
1044
1094
  });
1045
- var usageSchema = import_v45.z.object({
1046
- cachedContentTokenCount: import_v45.z.number().nullish(),
1047
- thoughtsTokenCount: import_v45.z.number().nullish(),
1048
- promptTokenCount: import_v45.z.number().nullish(),
1049
- candidatesTokenCount: import_v45.z.number().nullish(),
1050
- totalTokenCount: import_v45.z.number().nullish()
1095
+ var usageSchema = import_v47.z.object({
1096
+ cachedContentTokenCount: import_v47.z.number().nullish(),
1097
+ thoughtsTokenCount: import_v47.z.number().nullish(),
1098
+ promptTokenCount: import_v47.z.number().nullish(),
1099
+ candidatesTokenCount: import_v47.z.number().nullish(),
1100
+ totalTokenCount: import_v47.z.number().nullish()
1051
1101
  });
1052
- var responseSchema = import_v45.z.object({
1053
- candidates: import_v45.z.array(
1054
- import_v45.z.object({
1055
- content: contentSchema.nullish().or(import_v45.z.object({}).strict()),
1056
- finishReason: import_v45.z.string().nullish(),
1057
- safetyRatings: import_v45.z.array(safetyRatingSchema).nullish(),
1058
- groundingMetadata: groundingMetadataSchema.nullish()
1102
+ var responseSchema = import_v47.z.object({
1103
+ candidates: import_v47.z.array(
1104
+ import_v47.z.object({
1105
+ content: contentSchema.nullish().or(import_v47.z.object({}).strict()),
1106
+ finishReason: import_v47.z.string().nullish(),
1107
+ safetyRatings: import_v47.z.array(safetyRatingSchema).nullish(),
1108
+ groundingMetadata: groundingMetadataSchema.nullish(),
1109
+ urlContextMetadata: urlContextMetadataSchema.nullish()
1059
1110
  })
1060
1111
  ),
1061
1112
  usageMetadata: usageSchema.nullish()
1062
1113
  });
1063
- var chunkSchema = import_v45.z.object({
1064
- candidates: import_v45.z.array(
1065
- import_v45.z.object({
1114
+ var chunkSchema = import_v47.z.object({
1115
+ candidates: import_v47.z.array(
1116
+ import_v47.z.object({
1066
1117
  content: contentSchema.nullish(),
1067
- finishReason: import_v45.z.string().nullish(),
1068
- safetyRatings: import_v45.z.array(safetyRatingSchema).nullish(),
1069
- groundingMetadata: groundingMetadataSchema.nullish()
1118
+ finishReason: import_v47.z.string().nullish(),
1119
+ safetyRatings: import_v47.z.array(safetyRatingSchema).nullish(),
1120
+ groundingMetadata: groundingMetadataSchema.nullish(),
1121
+ urlContextMetadata: urlContextMetadataSchema.nullish()
1070
1122
  })
1071
1123
  ).nullish(),
1072
1124
  usageMetadata: usageSchema.nullish()
1073
1125
  });
1074
1126
 
1127
+ // src/google-tools.ts
1128
+ var googleTools = {
1129
+ /**
1130
+ * Creates a Google search tool that gives Google direct access to real-time web content.
1131
+ * Must have name "google_search".
1132
+ */
1133
+ googleSearch,
1134
+ /**
1135
+ * Creates a URL context tool that gives Google direct access to real-time web content.
1136
+ * Must have name "url_context".
1137
+ */
1138
+ urlContext
1139
+ };
1140
+
1141
+ // src/google-generative-ai-image-model.ts
1142
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
1143
+ var import_v48 = require("zod/v4");
1144
+ var GoogleGenerativeAIImageModel = class {
1145
+ constructor(modelId, settings, config) {
1146
+ this.modelId = modelId;
1147
+ this.settings = settings;
1148
+ this.config = config;
1149
+ this.specificationVersion = "v2";
1150
+ }
1151
+ get maxImagesPerCall() {
1152
+ var _a;
1153
+ return (_a = this.settings.maxImagesPerCall) != null ? _a : 4;
1154
+ }
1155
+ get provider() {
1156
+ return this.config.provider;
1157
+ }
1158
+ async doGenerate(options) {
1159
+ var _a, _b, _c;
1160
+ const {
1161
+ prompt,
1162
+ n = 1,
1163
+ size = "1024x1024",
1164
+ aspectRatio = "1:1",
1165
+ seed,
1166
+ providerOptions,
1167
+ headers,
1168
+ abortSignal
1169
+ } = options;
1170
+ const warnings = [];
1171
+ if (size != null) {
1172
+ warnings.push({
1173
+ type: "unsupported-setting",
1174
+ setting: "size",
1175
+ details: "This model does not support the `size` option. Use `aspectRatio` instead."
1176
+ });
1177
+ }
1178
+ if (seed != null) {
1179
+ warnings.push({
1180
+ type: "unsupported-setting",
1181
+ setting: "seed",
1182
+ details: "This model does not support the `seed` option through this provider."
1183
+ });
1184
+ }
1185
+ const googleOptions = await (0, import_provider_utils7.parseProviderOptions)({
1186
+ provider: "google",
1187
+ providerOptions,
1188
+ schema: googleImageProviderOptionsSchema
1189
+ });
1190
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1191
+ const parameters = {
1192
+ sampleCount: n
1193
+ };
1194
+ if (aspectRatio != null) {
1195
+ parameters.aspectRatio = aspectRatio;
1196
+ }
1197
+ if (googleOptions) {
1198
+ Object.assign(parameters, googleOptions);
1199
+ }
1200
+ const body = {
1201
+ instances: [{ prompt }],
1202
+ parameters
1203
+ };
1204
+ const { responseHeaders, value: response } = await (0, import_provider_utils7.postJsonToApi)({
1205
+ url: `${this.config.baseURL}/models/${this.modelId}:predict`,
1206
+ headers: (0, import_provider_utils7.combineHeaders)(await (0, import_provider_utils7.resolve)(this.config.headers), headers),
1207
+ body,
1208
+ failedResponseHandler: googleFailedResponseHandler,
1209
+ successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
1210
+ googleImageResponseSchema
1211
+ ),
1212
+ abortSignal,
1213
+ fetch: this.config.fetch
1214
+ });
1215
+ return {
1216
+ images: response.predictions.map(
1217
+ (p) => p.bytesBase64Encoded
1218
+ ),
1219
+ warnings: warnings != null ? warnings : [],
1220
+ providerMetadata: {
1221
+ google: {
1222
+ images: response.predictions.map((prediction) => ({
1223
+ // Add any prediction-specific metadata here
1224
+ }))
1225
+ }
1226
+ },
1227
+ response: {
1228
+ timestamp: currentDate,
1229
+ modelId: this.modelId,
1230
+ headers: responseHeaders
1231
+ }
1232
+ };
1233
+ }
1234
+ };
1235
+ var googleImageResponseSchema = import_v48.z.object({
1236
+ predictions: import_v48.z.array(import_v48.z.object({ bytesBase64Encoded: import_v48.z.string() })).default([])
1237
+ });
1238
+ var googleImageProviderOptionsSchema = import_v48.z.object({
1239
+ personGeneration: import_v48.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
1240
+ aspectRatio: import_v48.z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
1241
+ });
1242
+
1075
1243
  // src/google-provider.ts
1076
1244
  function createGoogleGenerativeAI(options = {}) {
1077
1245
  var _a;
1078
- const baseURL = (_a = (0, import_provider_utils5.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
1246
+ const baseURL = (_a = (0, import_provider_utils8.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
1079
1247
  const getHeaders = () => ({
1080
- "x-goog-api-key": (0, import_provider_utils5.loadApiKey)({
1248
+ "x-goog-api-key": (0, import_provider_utils8.loadApiKey)({
1081
1249
  apiKey: options.apiKey,
1082
1250
  environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
1083
1251
  description: "Google Generative AI"
@@ -1090,7 +1258,7 @@ function createGoogleGenerativeAI(options = {}) {
1090
1258
  provider: "google.generative-ai",
1091
1259
  baseURL,
1092
1260
  headers: getHeaders,
1093
- generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils5.generateId,
1261
+ generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils8.generateId,
1094
1262
  supportedUrls: () => ({
1095
1263
  "*": [
1096
1264
  // Only allow requests to the Google Generative Language "files" endpoint
@@ -1107,6 +1275,12 @@ function createGoogleGenerativeAI(options = {}) {
1107
1275
  headers: getHeaders,
1108
1276
  fetch: options.fetch
1109
1277
  });
1278
+ const createImageModel = (modelId, settings = {}) => new GoogleGenerativeAIImageModel(modelId, settings, {
1279
+ provider: "google.generative-ai",
1280
+ baseURL,
1281
+ headers: getHeaders,
1282
+ fetch: options.fetch
1283
+ });
1110
1284
  const provider = function(modelId) {
1111
1285
  if (new.target) {
1112
1286
  throw new Error(
@@ -1121,9 +1295,9 @@ function createGoogleGenerativeAI(options = {}) {
1121
1295
  provider.embedding = createEmbeddingModel;
1122
1296
  provider.textEmbedding = createEmbeddingModel;
1123
1297
  provider.textEmbeddingModel = createEmbeddingModel;
1124
- provider.imageModel = (modelId) => {
1125
- throw new import_provider4.NoSuchModelError({ modelId, modelType: "imageModel" });
1126
- };
1298
+ provider.image = createImageModel;
1299
+ provider.imageModel = createImageModel;
1300
+ provider.tools = googleTools;
1127
1301
  return provider;
1128
1302
  }
1129
1303
  var google = createGoogleGenerativeAI();