@ai-sdk/google 4.0.68 → 4.0.69

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.
@@ -79,6 +79,12 @@ type GoogleLanguageModelConfig = {
79
79
  * The supported URLs for the model.
80
80
  */
81
81
  supportedUrls?: () => LanguageModelV4['supportedUrls'];
82
+ /**
83
+ * Settings for downloading remote files in tool results before conversion.
84
+ */
85
+ downloadToolResultFiles?: {
86
+ maxBytes: number;
87
+ };
82
88
  };
83
89
  declare class GoogleLanguageModel implements LanguageModelV4 {
84
90
  readonly specificationVersion = "v4";
@@ -96,7 +102,7 @@ declare class GoogleLanguageModel implements LanguageModelV4 {
96
102
  constructor(modelId: GoogleModelId, config: GoogleLanguageModelConfig);
97
103
  get provider(): string;
98
104
  get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
99
- static prepareRequest({ modelId, config, options: { prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, tools, toolChoice, reasoning, providerOptions, }, isStreaming, }: {
105
+ static prepareRequest({ modelId, config, options: { prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, stopSequences, responseFormat, seed, tools, toolChoice, reasoning, providerOptions, abortSignal, }, isStreaming, }: {
100
106
  modelId: GoogleModelId;
101
107
  config: GoogleLanguageModelConfig;
102
108
  options: LanguageModelV4CallOptions;
@@ -787,6 +787,90 @@ function convertToGoogleMessages(prompt, options) {
787
787
  };
788
788
  }
789
789
 
790
+ // src/download-tool-result-files.ts
791
+ import {
792
+ detectMediaType,
793
+ downloadBlob,
794
+ isFullMediaType as isFullMediaType2
795
+ } from "@ai-sdk/provider-utils";
796
+ async function downloadToolResultFiles(prompt, {
797
+ abortSignal,
798
+ maxBytes
799
+ }) {
800
+ const result = [];
801
+ for (const message of prompt) {
802
+ if (message.role === "assistant") {
803
+ const content = [];
804
+ for (const part of message.content) {
805
+ content.push(
806
+ part.type === "tool-result" ? {
807
+ ...part,
808
+ output: await downloadToolResultOutput(part.output, {
809
+ abortSignal,
810
+ maxBytes
811
+ })
812
+ } : part
813
+ );
814
+ }
815
+ result.push({ ...message, content });
816
+ continue;
817
+ }
818
+ if (message.role === "tool") {
819
+ const content = [];
820
+ for (const part of message.content) {
821
+ if (part.type !== "tool-result") {
822
+ content.push(part);
823
+ continue;
824
+ }
825
+ content.push({
826
+ ...part,
827
+ output: await downloadToolResultOutput(part.output, {
828
+ abortSignal,
829
+ maxBytes
830
+ })
831
+ });
832
+ }
833
+ result.push({ ...message, content });
834
+ continue;
835
+ }
836
+ result.push(message);
837
+ }
838
+ return result;
839
+ }
840
+ async function downloadToolResultOutput(output, {
841
+ abortSignal,
842
+ maxBytes
843
+ }) {
844
+ if (output.type !== "content") {
845
+ return output;
846
+ }
847
+ const value = [];
848
+ for (const part of output.value) {
849
+ if (part.type !== "file" || part.data.type !== "url") {
850
+ value.push(part);
851
+ continue;
852
+ }
853
+ const blob = await downloadBlob(part.data.url.toString(), {
854
+ abortSignal,
855
+ maxBytes
856
+ });
857
+ const data = new Uint8Array(await blob.arrayBuffer());
858
+ const detectedMediaType = detectMediaType({
859
+ data,
860
+ topLevelType: "image"
861
+ });
862
+ value.push({
863
+ ...part,
864
+ data: { type: "data", data },
865
+ mediaType: detectedMediaType != null ? detectedMediaType : blob.type && !isFullMediaType2(part.mediaType) ? blob.type : part.mediaType
866
+ });
867
+ }
868
+ return {
869
+ ...output,
870
+ value
871
+ };
872
+ }
873
+
790
874
  // src/get-model-path.ts
791
875
  function getModelPath(modelId) {
792
876
  return modelId.includes("/") ? modelId : `models/${modelId}`;
@@ -1604,7 +1688,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1604
1688
  tools,
1605
1689
  toolChoice,
1606
1690
  reasoning,
1607
- providerOptions
1691
+ providerOptions,
1692
+ abortSignal
1608
1693
  },
1609
1694
  isStreaming = false
1610
1695
  }) {
@@ -1701,14 +1786,21 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1701
1786
  });
1702
1787
  }
1703
1788
  const { usesGemini3Features } = getGoogleModelCapabilities(modelId);
1704
- const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
1705
- isGemmaModel,
1706
- isGemini3Model: usesGemini3Features,
1707
- onWarning: (warning) => warnings.push(warning),
1708
- providerOptionsNames,
1709
- supportsFunctionResponseParts: usesGemini3Features,
1710
- includeFunctionCallIds: !isVertexProvider
1711
- });
1789
+ const promptWithDownloadedToolResultFiles = config.downloadToolResultFiles ? await downloadToolResultFiles(prompt, {
1790
+ abortSignal,
1791
+ maxBytes: config.downloadToolResultFiles.maxBytes
1792
+ }) : prompt;
1793
+ const { contents, systemInstruction } = convertToGoogleMessages(
1794
+ promptWithDownloadedToolResultFiles,
1795
+ {
1796
+ isGemmaModel,
1797
+ isGemini3Model: usesGemini3Features,
1798
+ onWarning: (warning) => warnings.push(warning),
1799
+ providerOptionsNames,
1800
+ supportsFunctionResponseParts: usesGemini3Features,
1801
+ includeFunctionCallIds: !isVertexProvider
1802
+ }
1803
+ );
1712
1804
  const {
1713
1805
  tools: googleTools2,
1714
1806
  toolConfig: googleToolConfig,
@@ -4066,7 +4158,7 @@ function buildGoogleInteractionsStreamTransform({
4066
4158
  import {
4067
4159
  convertToBase64 as convertToBase642,
4068
4160
  getTopLevelMediaType as getTopLevelMediaType2,
4069
- isFullMediaType as isFullMediaType2,
4161
+ isFullMediaType as isFullMediaType3,
4070
4162
  resolveFullMediaType as resolveFullMediaType2,
4071
4163
  resolveProviderReference as resolveProviderReference2,
4072
4164
  secureJsonParse as secureJsonParse2
@@ -4275,7 +4367,7 @@ function convertFilePartToContent({
4275
4367
  return {
4276
4368
  type: kind,
4277
4369
  uri: part.data.url.toString(),
4278
- ...isFullMediaType2(part.mediaType) ? { mime_type: part.mediaType } : {},
4370
+ ...isFullMediaType3(part.mediaType) ? { mime_type: part.mediaType } : {},
4279
4371
  ...resolutionField,
4280
4372
  ...processingField
4281
4373
  };
@@ -4288,7 +4380,7 @@ function convertFilePartToContent({
4288
4380
  return {
4289
4381
  type: kind,
4290
4382
  uri,
4291
- ...isFullMediaType2(part.mediaType) ? { mime_type: part.mediaType } : {},
4383
+ ...isFullMediaType3(part.mediaType) ? { mime_type: part.mediaType } : {},
4292
4384
  ...resolutionField,
4293
4385
  ...processingField
4294
4386
  };
@@ -4443,7 +4535,7 @@ function filePartToImageBlock({
4443
4535
  }) {
4444
4536
  switch (part.data.type) {
4445
4537
  case "data": {
4446
- const mimeType = isFullMediaType2(part.mediaType) ? part.mediaType : resolveFullMediaType2({
4538
+ const mimeType = isFullMediaType3(part.mediaType) ? part.mediaType : resolveFullMediaType2({
4447
4539
  part: {
4448
4540
  type: "file",
4449
4541
  mediaType: part.mediaType,
@@ -4460,7 +4552,7 @@ function filePartToImageBlock({
4460
4552
  return {
4461
4553
  type: "image",
4462
4554
  uri: part.data.url.toString(),
4463
- ...isFullMediaType2(part.mediaType) ? { mime_type: part.mediaType } : {}
4555
+ ...isFullMediaType3(part.mediaType) ? { mime_type: part.mediaType } : {}
4464
4556
  };
4465
4557
  case "reference": {
4466
4558
  const uri = resolveProviderReference2({
@@ -4470,7 +4562,7 @@ function filePartToImageBlock({
4470
4562
  return {
4471
4563
  type: "image",
4472
4564
  uri,
4473
- ...isFullMediaType2(part.mediaType) ? { mime_type: part.mediaType } : {}
4565
+ ...isFullMediaType3(part.mediaType) ? { mime_type: part.mediaType } : {}
4474
4566
  };
4475
4567
  }
4476
4568
  case "text": {