@ai-sdk/google 3.0.126 → 3.0.128

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.
@@ -327,7 +327,11 @@ function isEmptyObjectSchema(jsonSchema) {
327
327
  import {
328
328
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
329
329
  } from "@ai-sdk/provider";
330
- import { convertToBase64, secureJsonParse } from "@ai-sdk/provider-utils";
330
+ import {
331
+ convertToBase64,
332
+ isUrlSupported,
333
+ secureJsonParse
334
+ } from "@ai-sdk/provider-utils";
331
335
  var SKIP_THOUGHT_SIGNATURE_VALIDATOR = "skip_thought_signature_validator";
332
336
  function getGoogleProviderOptions(providerOptions, providerOptionsName) {
333
337
  const namespaces = [
@@ -356,19 +360,28 @@ function parseBase64DataUrl(value) {
356
360
  data: match[2]
357
361
  };
358
362
  }
359
- function convertUrlToolResultPart(url) {
363
+ function convertUrlToolResultPart(url, mediaType, supportedFunctionResponseUrls) {
360
364
  const parsedDataUrl = parseBase64DataUrl(url);
361
- if (parsedDataUrl == null) {
362
- return void 0;
365
+ if (parsedDataUrl != null) {
366
+ return {
367
+ inlineData: {
368
+ mimeType: parsedDataUrl.mediaType,
369
+ data: parsedDataUrl.data
370
+ }
371
+ };
363
372
  }
364
- return {
365
- inlineData: {
366
- mimeType: parsedDataUrl.mediaType,
367
- data: parsedDataUrl.data
373
+ return mediaType != null && isUrlSupported({
374
+ url,
375
+ mediaType,
376
+ supportedUrls: supportedFunctionResponseUrls
377
+ }) ? {
378
+ fileData: {
379
+ mimeType: mediaType,
380
+ fileUri: url
368
381
  }
369
- };
382
+ } : void 0;
370
383
  }
371
- function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true) {
384
+ function appendToolResultParts(parts, toolName, outputValue, toolCallId, includeFunctionCallIds = true, supportedFunctionResponseUrls = {}) {
372
385
  const functionResponseParts = [];
373
386
  const responseTextParts = [];
374
387
  for (const contentPart of outputValue) {
@@ -390,7 +403,9 @@ function appendToolResultParts(parts, toolName, outputValue, toolCallId, include
390
403
  case "image-url":
391
404
  case "file-url": {
392
405
  const functionResponsePart = convertUrlToolResultPart(
393
- contentPart.url
406
+ contentPart.url,
407
+ contentPart.mediaType,
408
+ supportedFunctionResponseUrls
394
409
  );
395
410
  if (functionResponsePart != null) {
396
411
  functionResponseParts.push(functionResponsePart);
@@ -455,7 +470,7 @@ function appendLegacyToolResultParts(parts, toolName, outputValue, toolCallId, i
455
470
  }
456
471
  }
457
472
  function convertToGoogleGenerativeAIMessages(prompt, options) {
458
- var _a, _b, _c, _d, _e, _f;
473
+ var _a, _b, _c, _d, _e, _f, _g;
459
474
  const systemInstructionParts = [];
460
475
  const contents = [];
461
476
  let systemMessagesAllowed = true;
@@ -465,6 +480,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
465
480
  const supportsFunctionResponseParts = (_d = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _d : true;
466
481
  const onWarning = options == null ? void 0 : options.onWarning;
467
482
  const includeFunctionCallIds = (_e = options == null ? void 0 : options.includeFunctionCallIds) != null ? _e : true;
483
+ const supportedFunctionResponseUrls = (_f = options == null ? void 0 : options.supportedFunctionResponseUrls) != null ? _f : {};
468
484
  let sentinelInjected = false;
469
485
  const missingSignatureToolNames = [];
470
486
  const injectSkipSignature = (toolName) => {
@@ -646,7 +662,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
646
662
  part.toolName,
647
663
  output.value,
648
664
  part.toolCallId,
649
- includeFunctionCallIds
665
+ includeFunctionCallIds,
666
+ supportedFunctionResponseUrls
650
667
  );
651
668
  } else {
652
669
  appendLegacyToolResultParts(
@@ -664,7 +681,7 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
664
681
  name: part.toolName,
665
682
  response: {
666
683
  name: part.toolName,
667
- content: output.type === "execution-denied" ? (_f = output.reason) != null ? _f : "Tool call execution denied." : output.value
684
+ content: output.type === "execution-denied" ? (_g = output.reason) != null ? _g : "Tool call execution denied." : output.value
668
685
  }
669
686
  }
670
687
  });
@@ -695,6 +712,76 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
695
712
  };
696
713
  }
697
714
 
715
+ // src/download-tool-result-files.ts
716
+ import {
717
+ convertUint8ArrayToBase64,
718
+ downloadBlob,
719
+ isUrlSupported as isUrlSupported2
720
+ } from "@ai-sdk/provider-utils";
721
+ async function downloadToolResultFiles(prompt, {
722
+ abortSignal,
723
+ supportedUrls = {}
724
+ }) {
725
+ async function downloadOutput(output) {
726
+ if (output.type !== "content") {
727
+ return output;
728
+ }
729
+ return {
730
+ ...output,
731
+ value: await Promise.all(
732
+ output.value.map(async (part) => {
733
+ var _a;
734
+ if (part.type !== "file-url" && part.type !== "image-url") {
735
+ return part;
736
+ }
737
+ if (part.type === "file-url" && part.mediaType != null && isUrlSupported2({
738
+ url: part.url,
739
+ mediaType: part.mediaType,
740
+ supportedUrls
741
+ })) {
742
+ return part;
743
+ }
744
+ const blob = await downloadBlob(part.url, { abortSignal });
745
+ return {
746
+ type: part.type === "file-url" ? "file-data" : "image-data",
747
+ data: convertUint8ArrayToBase64(
748
+ new Uint8Array(await blob.arrayBuffer())
749
+ ),
750
+ mediaType: blob.type || (part.type === "file-url" ? (_a = part.mediaType) != null ? _a : "application/octet-stream" : "image/*"),
751
+ providerOptions: part.providerOptions
752
+ };
753
+ })
754
+ )
755
+ };
756
+ }
757
+ return Promise.all(
758
+ prompt.map(async (message) => {
759
+ switch (message.role) {
760
+ case "assistant":
761
+ return {
762
+ ...message,
763
+ content: await Promise.all(
764
+ message.content.map(
765
+ async (part) => part.type === "tool-result" ? { ...part, output: await downloadOutput(part.output) } : part
766
+ )
767
+ )
768
+ };
769
+ case "tool":
770
+ return {
771
+ ...message,
772
+ content: await Promise.all(
773
+ message.content.map(
774
+ async (part) => part.type === "tool-result" ? { ...part, output: await downloadOutput(part.output) } : part
775
+ )
776
+ )
777
+ };
778
+ default:
779
+ return message;
780
+ }
781
+ })
782
+ );
783
+ }
784
+
698
785
  // src/get-model-path.ts
699
786
  function getModelPath(modelId) {
700
787
  return modelId.includes("/") ? modelId : `models/${modelId}`;
@@ -1467,6 +1554,13 @@ var configurableSafetySettingCategories = [
1467
1554
  "HARM_CATEGORY_SEXUALLY_EXPLICIT"
1468
1555
  ];
1469
1556
  var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
1557
+ var googleCloudStorageFunctionResponseUrls = {
1558
+ "image/png": [/^gs:\/\/.*$/],
1559
+ "image/jpeg": [/^gs:\/\/.*$/],
1560
+ "image/webp": [/^gs:\/\/.*$/],
1561
+ "application/pdf": [/^gs:\/\/.*$/],
1562
+ "text/plain": [/^gs:\/\/.*$/]
1563
+ };
1470
1564
  var GoogleGenerativeAILanguageModel = class {
1471
1565
  constructor(modelId, config) {
1472
1566
  this.specificationVersion = "v3";
@@ -1495,7 +1589,8 @@ var GoogleGenerativeAILanguageModel = class {
1495
1589
  seed,
1496
1590
  tools,
1497
1591
  toolChoice,
1498
- providerOptions
1592
+ providerOptions,
1593
+ abortSignal
1499
1594
  }, { isStreaming = false } = {}) {
1500
1595
  var _a, _b, _c;
1501
1596
  const warnings = [];
@@ -1584,15 +1679,21 @@ var GoogleGenerativeAILanguageModel = class {
1584
1679
  });
1585
1680
  }
1586
1681
  const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
1682
+ const supportedFunctionResponseUrls = usesGemini3Features && isVertexProvider ? googleCloudStorageFunctionResponseUrls : void 0;
1683
+ const promptWithDownloadedToolResultFiles = isVertexProvider ? await downloadToolResultFiles(prompt, {
1684
+ abortSignal,
1685
+ supportedUrls: supportedFunctionResponseUrls
1686
+ }) : prompt;
1587
1687
  const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
1588
- prompt,
1688
+ promptWithDownloadedToolResultFiles,
1589
1689
  {
1590
1690
  isGemmaModel,
1591
1691
  isGemini3Model: usesGemini3Features,
1592
1692
  providerOptionsName,
1593
1693
  supportsFunctionResponseParts: usesGemini3Features,
1594
1694
  onWarning: (warning) => warnings.push(warning),
1595
- includeFunctionCallIds: !isVertexProvider
1695
+ includeFunctionCallIds: !isVertexProvider,
1696
+ supportedFunctionResponseUrls
1596
1697
  }
1597
1698
  );
1598
1699
  const {