@ai-sdk/google 2.0.0-canary.12 → 2.0.0-canary.14

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
@@ -85,18 +85,14 @@ var googleGenerativeAIEmbeddingProviderOptions = import_zod2.z.object({
85
85
  var GoogleGenerativeAIEmbeddingModel = class {
86
86
  constructor(modelId, config) {
87
87
  this.specificationVersion = "v2";
88
+ this.maxEmbeddingsPerCall = 2048;
89
+ this.supportsParallelCalls = true;
88
90
  this.modelId = modelId;
89
91
  this.config = config;
90
92
  }
91
93
  get provider() {
92
94
  return this.config.provider;
93
95
  }
94
- get maxEmbeddingsPerCall() {
95
- return 2048;
96
- }
97
- get supportsParallelCalls() {
98
- return true;
99
- }
100
96
  async doEmbed({
101
97
  values,
102
98
  headers,
@@ -155,7 +151,7 @@ var googleGenerativeAITextEmbeddingResponseSchema = import_zod3.z.object({
155
151
 
156
152
  // src/google-generative-ai-language-model.ts
157
153
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
158
- var import_zod4 = require("zod");
154
+ var import_zod5 = require("zod");
159
155
 
160
156
  // src/convert-json-schema-to-openapi-schema.ts
161
157
  function convertJSONSchemaToOpenAPISchema(jsonSchema) {
@@ -372,13 +368,99 @@ function getModelPath(modelId) {
372
368
  return modelId.includes("/") ? modelId : `models/${modelId}`;
373
369
  }
374
370
 
371
+ // src/google-generative-ai-options.ts
372
+ var import_zod4 = require("zod");
373
+ var dynamicRetrievalConfig = import_zod4.z.object({
374
+ /**
375
+ * The mode of the predictor to be used in dynamic retrieval.
376
+ */
377
+ mode: import_zod4.z.enum(["MODE_UNSPECIFIED", "MODE_DYNAMIC"]).optional(),
378
+ /**
379
+ * The threshold to be used in dynamic retrieval. If not set, a system default
380
+ * value is used.
381
+ */
382
+ dynamicThreshold: import_zod4.z.number().optional()
383
+ });
384
+ var googleGenerativeAIProviderOptions = import_zod4.z.object({
385
+ responseModalities: import_zod4.z.array(import_zod4.z.enum(["TEXT", "IMAGE"])).optional(),
386
+ thinkingConfig: import_zod4.z.object({
387
+ thinkingBudget: import_zod4.z.number().optional()
388
+ }).optional(),
389
+ /**
390
+ Optional.
391
+ The name of the cached content used as context to serve the prediction.
392
+ Format: cachedContents/{cachedContent}
393
+ */
394
+ cachedContent: import_zod4.z.string().optional(),
395
+ /**
396
+ * Optional. Enable structured output. Default is true.
397
+ *
398
+ * This is useful when the JSON Schema contains elements that are
399
+ * not supported by the OpenAPI schema version that
400
+ * Google Generative AI uses. You can use this to disable
401
+ * structured outputs if you need to.
402
+ */
403
+ structuredOutputs: import_zod4.z.boolean().optional(),
404
+ /**
405
+ Optional. A list of unique safety settings for blocking unsafe content.
406
+ */
407
+ safetySettings: import_zod4.z.array(
408
+ import_zod4.z.object({
409
+ category: import_zod4.z.enum([
410
+ "HARM_CATEGORY_UNSPECIFIED",
411
+ "HARM_CATEGORY_HATE_SPEECH",
412
+ "HARM_CATEGORY_DANGEROUS_CONTENT",
413
+ "HARM_CATEGORY_HARASSMENT",
414
+ "HARM_CATEGORY_SEXUALLY_EXPLICIT",
415
+ "HARM_CATEGORY_CIVIC_INTEGRITY"
416
+ ]),
417
+ threshold: import_zod4.z.enum([
418
+ "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
419
+ "BLOCK_LOW_AND_ABOVE",
420
+ "BLOCK_MEDIUM_AND_ABOVE",
421
+ "BLOCK_ONLY_HIGH",
422
+ "BLOCK_NONE",
423
+ "OFF"
424
+ ])
425
+ })
426
+ ).optional(),
427
+ threshold: import_zod4.z.enum([
428
+ "HARM_BLOCK_THRESHOLD_UNSPECIFIED",
429
+ "BLOCK_LOW_AND_ABOVE",
430
+ "BLOCK_MEDIUM_AND_ABOVE",
431
+ "BLOCK_ONLY_HIGH",
432
+ "BLOCK_NONE",
433
+ "OFF"
434
+ ]).optional(),
435
+ /**
436
+ * Optional. Enables timestamp understanding for audio-only files.
437
+ *
438
+ * https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
439
+ */
440
+ audioTimestamp: import_zod4.z.boolean().optional(),
441
+ /**
442
+ Optional. When enabled, the model will use Google search to ground the response.
443
+
444
+ @see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview
445
+ */
446
+ useSearchGrounding: import_zod4.z.boolean().optional(),
447
+ /**
448
+ Optional. Specifies the dynamic retrieval configuration.
449
+
450
+ @note Dynamic retrieval is only compatible with Gemini 1.5 Flash.
451
+
452
+ @see https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/ground-with-google-search#dynamic-retrieval
453
+ */
454
+ dynamicRetrievalConfig: dynamicRetrievalConfig.optional()
455
+ });
456
+
375
457
  // src/google-prepare-tools.ts
376
458
  var import_provider3 = require("@ai-sdk/provider");
377
459
  function prepareTools({
378
460
  tools,
379
461
  toolChoice,
380
462
  useSearchGrounding,
381
- dynamicRetrievalConfig,
463
+ dynamicRetrievalConfig: dynamicRetrievalConfig2,
382
464
  modelId
383
465
  }) {
384
466
  var _a;
@@ -389,7 +471,7 @@ function prepareTools({
389
471
  if (useSearchGrounding) {
390
472
  return {
391
473
  tools: isGemini2 ? { googleSearch: {} } : {
392
- googleSearchRetrieval: !supportsDynamicRetrieval || !dynamicRetrievalConfig ? {} : { dynamicRetrievalConfig }
474
+ googleSearchRetrieval: !supportsDynamicRetrieval || !dynamicRetrievalConfig2 ? {} : { dynamicRetrievalConfig: dynamicRetrievalConfig2 }
393
475
  },
394
476
  toolConfig: void 0,
395
477
  toolWarnings
@@ -486,18 +568,17 @@ function mapGoogleGenerativeAIFinishReason({
486
568
 
487
569
  // src/google-generative-ai-language-model.ts
488
570
  var GoogleGenerativeAILanguageModel = class {
489
- constructor(modelId, settings, config) {
571
+ constructor(modelId, config) {
490
572
  this.specificationVersion = "v2";
491
573
  this.modelId = modelId;
492
- this.settings = settings;
493
574
  this.config = config;
494
575
  }
495
576
  get provider() {
496
577
  return this.config.provider;
497
578
  }
498
- async getSupportedUrls() {
579
+ get supportedUrls() {
499
580
  var _a, _b, _c;
500
- return (_c = (_b = (_a = this.config).getSupportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
581
+ return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
501
582
  }
502
583
  async getArgs({
503
584
  prompt,
@@ -519,7 +600,7 @@ var GoogleGenerativeAILanguageModel = class {
519
600
  const googleOptions = await (0, import_provider_utils4.parseProviderOptions)({
520
601
  provider: "google",
521
602
  providerOptions,
522
- schema: googleGenerativeAIProviderOptionsSchema
603
+ schema: googleGenerativeAIProviderOptions
523
604
  });
524
605
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(prompt);
525
606
  const {
@@ -529,8 +610,8 @@ var GoogleGenerativeAILanguageModel = class {
529
610
  } = prepareTools({
530
611
  tools,
531
612
  toolChoice,
532
- useSearchGrounding: (_a = this.settings.useSearchGrounding) != null ? _a : false,
533
- dynamicRetrievalConfig: this.settings.dynamicRetrievalConfig,
613
+ useSearchGrounding: (_a = googleOptions == null ? void 0 : googleOptions.useSearchGrounding) != null ? _a : false,
614
+ dynamicRetrievalConfig: googleOptions == null ? void 0 : googleOptions.dynamicRetrievalConfig,
534
615
  modelId: this.modelId
535
616
  });
536
617
  return {
@@ -550,9 +631,9 @@ var GoogleGenerativeAILanguageModel = class {
550
631
  responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
551
632
  // so this is needed as an escape hatch:
552
633
  // TODO convert into provider option
553
- ((_b = this.settings.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
554
- ...this.settings.audioTimestamp && {
555
- audioTimestamp: this.settings.audioTimestamp
634
+ ((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
635
+ ...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
636
+ audioTimestamp: googleOptions.audioTimestamp
556
637
  },
557
638
  // provider options:
558
639
  responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
@@ -560,10 +641,10 @@ var GoogleGenerativeAILanguageModel = class {
560
641
  },
561
642
  contents,
562
643
  systemInstruction,
563
- safetySettings: this.settings.safetySettings,
644
+ safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
564
645
  tools: googleTools,
565
646
  toolConfig: googleToolConfig,
566
- cachedContent: this.settings.cachedContent
647
+ cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent
567
648
  },
568
649
  warnings: [...warnings, ...toolWarnings]
569
650
  };
@@ -811,100 +892,94 @@ function extractSources({
811
892
  title: chunk.web.title
812
893
  }));
813
894
  }
814
- var contentSchema = import_zod4.z.object({
815
- role: import_zod4.z.string(),
816
- parts: import_zod4.z.array(
817
- import_zod4.z.union([
818
- import_zod4.z.object({
819
- text: import_zod4.z.string()
895
+ var contentSchema = import_zod5.z.object({
896
+ role: import_zod5.z.string(),
897
+ parts: import_zod5.z.array(
898
+ import_zod5.z.union([
899
+ import_zod5.z.object({
900
+ text: import_zod5.z.string()
820
901
  }),
821
- import_zod4.z.object({
822
- functionCall: import_zod4.z.object({
823
- name: import_zod4.z.string(),
824
- args: import_zod4.z.unknown()
902
+ import_zod5.z.object({
903
+ functionCall: import_zod5.z.object({
904
+ name: import_zod5.z.string(),
905
+ args: import_zod5.z.unknown()
825
906
  })
826
907
  }),
827
- import_zod4.z.object({
828
- inlineData: import_zod4.z.object({
829
- mimeType: import_zod4.z.string(),
830
- data: import_zod4.z.string()
908
+ import_zod5.z.object({
909
+ inlineData: import_zod5.z.object({
910
+ mimeType: import_zod5.z.string(),
911
+ data: import_zod5.z.string()
831
912
  })
832
913
  })
833
914
  ])
834
915
  ).nullish()
835
916
  });
836
- var groundingChunkSchema = import_zod4.z.object({
837
- web: import_zod4.z.object({ uri: import_zod4.z.string(), title: import_zod4.z.string() }).nullish(),
838
- retrievedContext: import_zod4.z.object({ uri: import_zod4.z.string(), title: import_zod4.z.string() }).nullish()
917
+ var groundingChunkSchema = import_zod5.z.object({
918
+ web: import_zod5.z.object({ uri: import_zod5.z.string(), title: import_zod5.z.string() }).nullish(),
919
+ retrievedContext: import_zod5.z.object({ uri: import_zod5.z.string(), title: import_zod5.z.string() }).nullish()
839
920
  });
840
- var groundingMetadataSchema = import_zod4.z.object({
841
- webSearchQueries: import_zod4.z.array(import_zod4.z.string()).nullish(),
842
- retrievalQueries: import_zod4.z.array(import_zod4.z.string()).nullish(),
843
- searchEntryPoint: import_zod4.z.object({ renderedContent: import_zod4.z.string() }).nullish(),
844
- groundingChunks: import_zod4.z.array(groundingChunkSchema).nullish(),
845
- groundingSupports: import_zod4.z.array(
846
- import_zod4.z.object({
847
- segment: import_zod4.z.object({
848
- startIndex: import_zod4.z.number().nullish(),
849
- endIndex: import_zod4.z.number().nullish(),
850
- text: import_zod4.z.string().nullish()
921
+ var groundingMetadataSchema = import_zod5.z.object({
922
+ webSearchQueries: import_zod5.z.array(import_zod5.z.string()).nullish(),
923
+ retrievalQueries: import_zod5.z.array(import_zod5.z.string()).nullish(),
924
+ searchEntryPoint: import_zod5.z.object({ renderedContent: import_zod5.z.string() }).nullish(),
925
+ groundingChunks: import_zod5.z.array(groundingChunkSchema).nullish(),
926
+ groundingSupports: import_zod5.z.array(
927
+ import_zod5.z.object({
928
+ segment: import_zod5.z.object({
929
+ startIndex: import_zod5.z.number().nullish(),
930
+ endIndex: import_zod5.z.number().nullish(),
931
+ text: import_zod5.z.string().nullish()
851
932
  }),
852
- segment_text: import_zod4.z.string().nullish(),
853
- groundingChunkIndices: import_zod4.z.array(import_zod4.z.number()).nullish(),
854
- supportChunkIndices: import_zod4.z.array(import_zod4.z.number()).nullish(),
855
- confidenceScores: import_zod4.z.array(import_zod4.z.number()).nullish(),
856
- confidenceScore: import_zod4.z.array(import_zod4.z.number()).nullish()
933
+ segment_text: import_zod5.z.string().nullish(),
934
+ groundingChunkIndices: import_zod5.z.array(import_zod5.z.number()).nullish(),
935
+ supportChunkIndices: import_zod5.z.array(import_zod5.z.number()).nullish(),
936
+ confidenceScores: import_zod5.z.array(import_zod5.z.number()).nullish(),
937
+ confidenceScore: import_zod5.z.array(import_zod5.z.number()).nullish()
857
938
  })
858
939
  ).nullish(),
859
- retrievalMetadata: import_zod4.z.union([
860
- import_zod4.z.object({
861
- webDynamicRetrievalScore: import_zod4.z.number()
940
+ retrievalMetadata: import_zod5.z.union([
941
+ import_zod5.z.object({
942
+ webDynamicRetrievalScore: import_zod5.z.number()
862
943
  }),
863
- import_zod4.z.object({})
944
+ import_zod5.z.object({})
864
945
  ]).nullish()
865
946
  });
866
- var safetyRatingSchema = import_zod4.z.object({
867
- category: import_zod4.z.string(),
868
- probability: import_zod4.z.string(),
869
- probabilityScore: import_zod4.z.number().nullish(),
870
- severity: import_zod4.z.string().nullish(),
871
- severityScore: import_zod4.z.number().nullish(),
872
- blocked: import_zod4.z.boolean().nullish()
947
+ var safetyRatingSchema = import_zod5.z.object({
948
+ category: import_zod5.z.string(),
949
+ probability: import_zod5.z.string(),
950
+ probabilityScore: import_zod5.z.number().nullish(),
951
+ severity: import_zod5.z.string().nullish(),
952
+ severityScore: import_zod5.z.number().nullish(),
953
+ blocked: import_zod5.z.boolean().nullish()
873
954
  });
874
- var responseSchema = import_zod4.z.object({
875
- candidates: import_zod4.z.array(
876
- import_zod4.z.object({
877
- content: contentSchema.nullish().or(import_zod4.z.object({}).strict()),
878
- finishReason: import_zod4.z.string().nullish(),
879
- safetyRatings: import_zod4.z.array(safetyRatingSchema).nullish(),
955
+ var responseSchema = import_zod5.z.object({
956
+ candidates: import_zod5.z.array(
957
+ import_zod5.z.object({
958
+ content: contentSchema.nullish().or(import_zod5.z.object({}).strict()),
959
+ finishReason: import_zod5.z.string().nullish(),
960
+ safetyRatings: import_zod5.z.array(safetyRatingSchema).nullish(),
880
961
  groundingMetadata: groundingMetadataSchema.nullish()
881
962
  })
882
963
  ),
883
- usageMetadata: import_zod4.z.object({
884
- promptTokenCount: import_zod4.z.number().nullish(),
885
- candidatesTokenCount: import_zod4.z.number().nullish(),
886
- totalTokenCount: import_zod4.z.number().nullish()
964
+ usageMetadata: import_zod5.z.object({
965
+ promptTokenCount: import_zod5.z.number().nullish(),
966
+ candidatesTokenCount: import_zod5.z.number().nullish(),
967
+ totalTokenCount: import_zod5.z.number().nullish()
887
968
  }).nullish()
888
969
  });
889
- var chunkSchema = import_zod4.z.object({
890
- candidates: import_zod4.z.array(
891
- import_zod4.z.object({
970
+ var chunkSchema = import_zod5.z.object({
971
+ candidates: import_zod5.z.array(
972
+ import_zod5.z.object({
892
973
  content: contentSchema.nullish(),
893
- finishReason: import_zod4.z.string().nullish(),
894
- safetyRatings: import_zod4.z.array(safetyRatingSchema).nullish(),
974
+ finishReason: import_zod5.z.string().nullish(),
975
+ safetyRatings: import_zod5.z.array(safetyRatingSchema).nullish(),
895
976
  groundingMetadata: groundingMetadataSchema.nullish()
896
977
  })
897
978
  ).nullish(),
898
- usageMetadata: import_zod4.z.object({
899
- promptTokenCount: import_zod4.z.number().nullish(),
900
- candidatesTokenCount: import_zod4.z.number().nullish(),
901
- totalTokenCount: import_zod4.z.number().nullish()
902
- }).nullish()
903
- });
904
- var googleGenerativeAIProviderOptionsSchema = import_zod4.z.object({
905
- responseModalities: import_zod4.z.array(import_zod4.z.enum(["TEXT", "IMAGE"])).nullish(),
906
- thinkingConfig: import_zod4.z.object({
907
- thinkingBudget: import_zod4.z.number().nullish()
979
+ usageMetadata: import_zod5.z.object({
980
+ promptTokenCount: import_zod5.z.number().nullish(),
981
+ candidatesTokenCount: import_zod5.z.number().nullish(),
982
+ totalTokenCount: import_zod5.z.number().nullish()
908
983
  }).nullish()
909
984
  });
910
985
 
@@ -920,14 +995,14 @@ function createGoogleGenerativeAI(options = {}) {
920
995
  }),
921
996
  ...options.headers
922
997
  });
923
- const createChatModel = (modelId, settings = {}) => {
998
+ const createChatModel = (modelId) => {
924
999
  var _a2;
925
- return new GoogleGenerativeAILanguageModel(modelId, settings, {
1000
+ return new GoogleGenerativeAILanguageModel(modelId, {
926
1001
  provider: "google.generative-ai",
927
1002
  baseURL,
928
1003
  headers: getHeaders,
929
1004
  generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils5.generateId,
930
- getSupportedUrls: async () => ({
1005
+ supportedUrls: () => ({
931
1006
  "*": [
932
1007
  // HTTP URLs:
933
1008
  /^https?:\/\/.*$/
@@ -942,13 +1017,13 @@ function createGoogleGenerativeAI(options = {}) {
942
1017
  headers: getHeaders,
943
1018
  fetch: options.fetch
944
1019
  });
945
- const provider = function(modelId, settings) {
1020
+ const provider = function(modelId) {
946
1021
  if (new.target) {
947
1022
  throw new Error(
948
1023
  "The Google Generative AI model function cannot be called with the new keyword."
949
1024
  );
950
1025
  }
951
- return createChatModel(modelId, settings);
1026
+ return createChatModel(modelId);
952
1027
  };
953
1028
  provider.languageModel = createChatModel;
954
1029
  provider.chat = createChatModel;