@ai-sdk/google 4.0.0-beta.47 → 4.0.0-beta.49

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
@@ -7,7 +7,7 @@ import {
7
7
  } from "@ai-sdk/provider-utils";
8
8
 
9
9
  // src/version.ts
10
- var VERSION = true ? "4.0.0-beta.47" : "0.0.0-test";
10
+ var VERSION = true ? "4.0.0-beta.49" : "0.0.0-test";
11
11
 
12
12
  // src/google-embedding-model.ts
13
13
  import {
@@ -50,7 +50,7 @@ var googleFailedResponseHandler = createJsonErrorResponseHandler({
50
50
  errorToMessage: (data) => data.error.message
51
51
  });
52
52
 
53
- // src/google-embedding-options.ts
53
+ // src/google-embedding-model-options.ts
54
54
  import {
55
55
  lazySchema as lazySchema2,
56
56
  zodSchema as zodSchema2
@@ -425,7 +425,8 @@ import {
425
425
  } from "@ai-sdk/provider";
426
426
  import {
427
427
  convertToBase64,
428
- isProviderReference,
428
+ isFullMediaType,
429
+ resolveFullMediaType,
429
430
  resolveProviderReference
430
431
  } from "@ai-sdk/provider-utils";
431
432
  var dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
@@ -535,13 +536,25 @@ function appendLegacyToolResultParts(parts, toolName, outputValue) {
535
536
  }
536
537
  }
537
538
  function convertToGoogleMessages(prompt, options) {
538
- var _a, _b, _c, _d, _e, _f, _g, _h;
539
+ var _a, _b, _c, _d;
539
540
  const systemInstructionParts = [];
540
541
  const contents = [];
541
542
  let systemMessagesAllowed = true;
542
543
  const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
543
- const providerOptionsName = (_b = options == null ? void 0 : options.providerOptionsName) != null ? _b : "google";
544
+ const providerOptionsNames = (_b = options == null ? void 0 : options.providerOptionsNames) != null ? _b : ["google"];
545
+ const isVertexLike = !providerOptionsNames.includes("google");
544
546
  const supportsFunctionResponseParts = (_c = options == null ? void 0 : options.supportsFunctionResponseParts) != null ? _c : true;
547
+ const readProviderOpts = (part) => {
548
+ var _a2, _b2, _c2, _d2, _e;
549
+ for (const name of providerOptionsNames) {
550
+ const v = (_a2 = part.providerOptions) == null ? void 0 : _a2[name];
551
+ if (v != null) return v;
552
+ }
553
+ if (isVertexLike) {
554
+ return (_b2 = part.providerOptions) == null ? void 0 : _b2.google;
555
+ }
556
+ return (_e = (_c2 = part.providerOptions) == null ? void 0 : _c2.googleVertex) != null ? _e : (_d2 = part.providerOptions) == null ? void 0 : _d2.vertex;
557
+ };
545
558
  for (const { role, content } of prompt) {
546
559
  switch (role) {
547
560
  case "system": {
@@ -563,36 +576,53 @@ function convertToGoogleMessages(prompt, options) {
563
576
  break;
564
577
  }
565
578
  case "file": {
566
- const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
567
- if (part.data instanceof URL) {
568
- parts.push({
569
- fileData: {
570
- mimeType: mediaType,
571
- fileUri: part.data.toString()
572
- }
573
- });
574
- } else if (isProviderReference(part.data)) {
575
- if (providerOptionsName === "vertex") {
576
- throw new UnsupportedFunctionalityError({
577
- functionality: "file parts with provider references"
579
+ switch (part.data.type) {
580
+ case "url": {
581
+ parts.push({
582
+ fileData: {
583
+ mimeType: resolveFullMediaType({ part }),
584
+ fileUri: part.data.url.toString()
585
+ }
578
586
  });
587
+ break;
579
588
  }
580
- parts.push({
581
- fileData: {
582
- mimeType: mediaType,
583
- fileUri: resolveProviderReference({
584
- reference: part.data,
585
- provider: "google"
586
- })
587
- }
588
- });
589
- } else {
590
- parts.push({
591
- inlineData: {
592
- mimeType: mediaType,
593
- data: convertToBase64(part.data)
589
+ case "reference": {
590
+ if (isVertexLike) {
591
+ throw new UnsupportedFunctionalityError({
592
+ functionality: "file parts with provider references"
593
+ });
594
594
  }
595
- });
595
+ parts.push({
596
+ fileData: {
597
+ mimeType: resolveFullMediaType({ part }),
598
+ fileUri: resolveProviderReference({
599
+ reference: part.data.reference,
600
+ provider: "google"
601
+ })
602
+ }
603
+ });
604
+ break;
605
+ }
606
+ case "text": {
607
+ parts.push({
608
+ inlineData: {
609
+ mimeType: isFullMediaType(part.mediaType) ? part.mediaType : "text/plain",
610
+ data: convertToBase64(
611
+ new TextEncoder().encode(part.data.text)
612
+ )
613
+ }
614
+ });
615
+ break;
616
+ }
617
+ case "data": {
618
+ parts.push({
619
+ inlineData: {
620
+ mimeType: resolveFullMediaType({ part }),
621
+ data: convertToBase64(part.data.data)
622
+ }
623
+ });
624
+ break;
625
+ }
596
626
  }
597
627
  break;
598
628
  }
@@ -606,8 +636,7 @@ function convertToGoogleMessages(prompt, options) {
606
636
  contents.push({
607
637
  role: "model",
608
638
  parts: content.map((part) => {
609
- var _a2, _b2, _c2, _d2;
610
- const providerOpts = (_d2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) != null ? _d2 : providerOptionsName !== "google" ? (_b2 = part.providerOptions) == null ? void 0 : _b2.google : (_c2 = part.providerOptions) == null ? void 0 : _c2.vertex;
639
+ const providerOpts = readProviderOpts(part);
611
640
  const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
612
641
  switch (part.type) {
613
642
  case "text": {
@@ -624,52 +653,74 @@ function convertToGoogleMessages(prompt, options) {
624
653
  };
625
654
  }
626
655
  case "reasoning-file": {
627
- if (part.data instanceof URL) {
628
- throw new UnsupportedFunctionalityError({
629
- functionality: "File data URLs in assistant messages are not supported"
630
- });
656
+ switch (part.data.type) {
657
+ case "url": {
658
+ throw new UnsupportedFunctionalityError({
659
+ functionality: "File data URLs in assistant messages are not supported"
660
+ });
661
+ }
662
+ case "data": {
663
+ return {
664
+ inlineData: {
665
+ mimeType: part.mediaType,
666
+ data: convertToBase64(part.data.data)
667
+ },
668
+ thought: true,
669
+ thoughtSignature
670
+ };
671
+ }
631
672
  }
632
- return {
633
- inlineData: {
634
- mimeType: part.mediaType,
635
- data: convertToBase64(part.data)
636
- },
637
- thought: true,
638
- thoughtSignature
639
- };
673
+ break;
640
674
  }
641
675
  case "file": {
642
- if (part.data instanceof URL) {
643
- throw new UnsupportedFunctionalityError({
644
- functionality: "File data URLs in assistant messages are not supported"
645
- });
646
- }
647
- if (isProviderReference(part.data)) {
648
- if (providerOptionsName === "vertex") {
676
+ switch (part.data.type) {
677
+ case "url": {
649
678
  throw new UnsupportedFunctionalityError({
650
- functionality: "file parts with provider references"
679
+ functionality: "File data URLs in assistant messages are not supported"
651
680
  });
652
681
  }
653
- return {
654
- fileData: {
655
- mimeType: part.mediaType,
656
- fileUri: resolveProviderReference({
657
- reference: part.data,
658
- provider: "google"
659
- })
660
- },
661
- ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
662
- thoughtSignature
663
- };
682
+ case "reference": {
683
+ if (isVertexLike) {
684
+ throw new UnsupportedFunctionalityError({
685
+ functionality: "file parts with provider references"
686
+ });
687
+ }
688
+ return {
689
+ fileData: {
690
+ mimeType: part.mediaType,
691
+ fileUri: resolveProviderReference({
692
+ reference: part.data.reference,
693
+ provider: "google"
694
+ })
695
+ },
696
+ ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
697
+ thoughtSignature
698
+ };
699
+ }
700
+ case "text": {
701
+ return {
702
+ inlineData: {
703
+ mimeType: isFullMediaType(part.mediaType) ? part.mediaType : "text/plain",
704
+ data: convertToBase64(
705
+ new TextEncoder().encode(part.data.text)
706
+ )
707
+ },
708
+ ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
709
+ thoughtSignature
710
+ };
711
+ }
712
+ case "data": {
713
+ return {
714
+ inlineData: {
715
+ mimeType: part.mediaType,
716
+ data: convertToBase64(part.data.data)
717
+ },
718
+ ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
719
+ thoughtSignature
720
+ };
721
+ }
664
722
  }
665
- return {
666
- inlineData: {
667
- mimeType: part.mediaType,
668
- data: convertToBase64(part.data)
669
- },
670
- ...(providerOpts == null ? void 0 : providerOpts.thought) === true ? { thought: true } : {},
671
- thoughtSignature
672
- };
723
+ break;
673
724
  }
674
725
  case "tool-call": {
675
726
  const serverToolCallId = (providerOpts == null ? void 0 : providerOpts.serverToolCallId) != null ? String(providerOpts.serverToolCallId) : void 0;
@@ -719,7 +770,7 @@ function convertToGoogleMessages(prompt, options) {
719
770
  if (part.type === "tool-approval-response") {
720
771
  continue;
721
772
  }
722
- const partProviderOpts = (_g = (_d = part.providerOptions) == null ? void 0 : _d[providerOptionsName]) != null ? _g : providerOptionsName !== "google" ? (_e = part.providerOptions) == null ? void 0 : _e.google : (_f = part.providerOptions) == null ? void 0 : _f.vertex;
773
+ const partProviderOpts = readProviderOpts(part);
723
774
  const serverToolCallId = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolCallId) != null ? String(partProviderOpts.serverToolCallId) : void 0;
724
775
  const serverToolType = (partProviderOpts == null ? void 0 : partProviderOpts.serverToolType) != null ? String(partProviderOpts.serverToolType) : void 0;
725
776
  if (serverToolCallId && serverToolType) {
@@ -752,7 +803,7 @@ function convertToGoogleMessages(prompt, options) {
752
803
  name: part.toolName,
753
804
  response: {
754
805
  name: part.toolName,
755
- content: output.type === "execution-denied" ? (_h = output.reason) != null ? _h : "Tool call execution denied." : output.value
806
+ content: output.type === "execution-denied" ? (_d = output.reason) != null ? _d : "Tool call execution denied." : output.value
756
807
  }
757
808
  }
758
809
  });
@@ -781,8 +832,11 @@ function getModelPath(modelId) {
781
832
  return modelId.includes("/") ? modelId : `models/${modelId}`;
782
833
  }
783
834
 
784
- // src/google-options.ts
785
- import { lazySchema as lazySchema4, zodSchema as zodSchema4 } from "@ai-sdk/provider-utils";
835
+ // src/google-language-model-options.ts
836
+ import {
837
+ lazySchema as lazySchema4,
838
+ zodSchema as zodSchema4
839
+ } from "@ai-sdk/provider-utils";
786
840
  import { z as z4 } from "zod/v4";
787
841
  var googleLanguageModelOptions = lazySchema4(
788
842
  () => zodSchema4(
@@ -1470,13 +1524,17 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1470
1524
  }, { isStreaming = false } = {}) {
1471
1525
  var _a, _b;
1472
1526
  const warnings = [];
1473
- const providerOptionsName = this.config.provider.includes("vertex") ? "vertex" : "google";
1474
- let googleOptions = await parseProviderOptions2({
1475
- provider: providerOptionsName,
1476
- providerOptions,
1477
- schema: googleLanguageModelOptions
1478
- });
1479
- if (googleOptions == null && providerOptionsName !== "google") {
1527
+ const providerOptionsNames = this.config.provider.includes("vertex") ? ["googleVertex", "vertex"] : ["google"];
1528
+ let googleOptions;
1529
+ for (const name of providerOptionsNames) {
1530
+ googleOptions = await parseProviderOptions2({
1531
+ provider: name,
1532
+ providerOptions,
1533
+ schema: googleLanguageModelOptions
1534
+ });
1535
+ if (googleOptions != null) break;
1536
+ }
1537
+ if (googleOptions == null && !providerOptionsNames.includes("google")) {
1480
1538
  googleOptions = await parseProviderOptions2({
1481
1539
  provider: "google",
1482
1540
  providerOptions,
@@ -1506,7 +1564,7 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1506
1564
  const supportsFunctionResponseParts = this.modelId.startsWith("gemini-3");
1507
1565
  const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
1508
1566
  isGemmaModel,
1509
- providerOptionsName,
1567
+ providerOptionsNames,
1510
1568
  supportsFunctionResponseParts
1511
1569
  });
1512
1570
  const {
@@ -1579,12 +1637,15 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1579
1637
  serviceTier: sanitizedServiceTier
1580
1638
  },
1581
1639
  warnings: [...warnings, ...toolWarnings],
1582
- providerOptionsName
1640
+ providerOptionsNames
1583
1641
  };
1584
1642
  }
1585
1643
  async doGenerate(options) {
1586
1644
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1587
- const { args, warnings, providerOptionsName } = await this.getArgs(options);
1645
+ const { args, warnings, providerOptionsNames } = await this.getArgs(options);
1646
+ const wrapProviderMetadata = (payload) => Object.fromEntries(
1647
+ providerOptionsNames.map((name) => [name, payload])
1648
+ );
1588
1649
  const mergedHeaders = combineHeaders2(
1589
1650
  this.config.headers ? await resolve2(this.config.headers) : void 0,
1590
1651
  options.headers
@@ -1634,11 +1695,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1634
1695
  });
1635
1696
  lastCodeExecutionToolCallId = void 0;
1636
1697
  } else if ("text" in part && part.text != null) {
1637
- const thoughtSignatureMetadata = part.thoughtSignature ? {
1638
- [providerOptionsName]: {
1639
- thoughtSignature: part.thoughtSignature
1640
- }
1641
- } : void 0;
1698
+ const thoughtSignatureMetadata = part.thoughtSignature ? wrapProviderMetadata({
1699
+ thoughtSignature: part.thoughtSignature
1700
+ }) : void 0;
1642
1701
  if (part.text.length === 0) {
1643
1702
  if (thoughtSignatureMetadata != null && content.length > 0) {
1644
1703
  const lastContent = content[content.length - 1];
@@ -1657,24 +1716,20 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1657
1716
  toolCallId: this.config.generateId(),
1658
1717
  toolName: part.functionCall.name,
1659
1718
  input: JSON.stringify(part.functionCall.args),
1660
- providerMetadata: part.thoughtSignature ? {
1661
- [providerOptionsName]: {
1662
- thoughtSignature: part.thoughtSignature
1663
- }
1664
- } : void 0
1719
+ providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1720
+ thoughtSignature: part.thoughtSignature
1721
+ }) : void 0
1665
1722
  });
1666
1723
  } else if ("inlineData" in part) {
1667
1724
  const hasThought = part.thought === true;
1668
1725
  const hasThoughtSignature = !!part.thoughtSignature;
1669
1726
  content.push({
1670
1727
  type: hasThought ? "reasoning-file" : "file",
1671
- data: part.inlineData.data,
1728
+ data: { type: "data", data: part.inlineData.data },
1672
1729
  mediaType: part.inlineData.mimeType,
1673
- providerMetadata: hasThoughtSignature ? {
1674
- [providerOptionsName]: {
1675
- thoughtSignature: part.thoughtSignature
1676
- }
1677
- } : void 0
1730
+ providerMetadata: hasThoughtSignature ? wrapProviderMetadata({
1731
+ thoughtSignature: part.thoughtSignature
1732
+ }) : void 0
1678
1733
  });
1679
1734
  } else if ("toolCall" in part && part.toolCall) {
1680
1735
  const toolCallId = (_e = part.toolCall.id) != null ? _e : this.config.generateId();
@@ -1686,18 +1741,14 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1686
1741
  input: JSON.stringify((_f = part.toolCall.args) != null ? _f : {}),
1687
1742
  providerExecuted: true,
1688
1743
  dynamic: true,
1689
- providerMetadata: part.thoughtSignature ? {
1690
- [providerOptionsName]: {
1691
- thoughtSignature: part.thoughtSignature,
1692
- serverToolCallId: toolCallId,
1693
- serverToolType: part.toolCall.toolType
1694
- }
1695
- } : {
1696
- [providerOptionsName]: {
1697
- serverToolCallId: toolCallId,
1698
- serverToolType: part.toolCall.toolType
1699
- }
1700
- }
1744
+ providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1745
+ thoughtSignature: part.thoughtSignature,
1746
+ serverToolCallId: toolCallId,
1747
+ serverToolType: part.toolCall.toolType
1748
+ }) : wrapProviderMetadata({
1749
+ serverToolCallId: toolCallId,
1750
+ serverToolType: part.toolCall.toolType
1751
+ })
1701
1752
  });
1702
1753
  } else if ("toolResponse" in part && part.toolResponse) {
1703
1754
  const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : this.config.generateId();
@@ -1706,18 +1757,14 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1706
1757
  toolCallId: responseToolCallId,
1707
1758
  toolName: `server:${part.toolResponse.toolType}`,
1708
1759
  result: (_h = part.toolResponse.response) != null ? _h : {},
1709
- providerMetadata: part.thoughtSignature ? {
1710
- [providerOptionsName]: {
1711
- thoughtSignature: part.thoughtSignature,
1712
- serverToolCallId: responseToolCallId,
1713
- serverToolType: part.toolResponse.toolType
1714
- }
1715
- } : {
1716
- [providerOptionsName]: {
1717
- serverToolCallId: responseToolCallId,
1718
- serverToolType: part.toolResponse.toolType
1719
- }
1720
- }
1760
+ providerMetadata: part.thoughtSignature ? wrapProviderMetadata({
1761
+ thoughtSignature: part.thoughtSignature,
1762
+ serverToolCallId: responseToolCallId,
1763
+ serverToolType: part.toolResponse.toolType
1764
+ }) : wrapProviderMetadata({
1765
+ serverToolCallId: responseToolCallId,
1766
+ serverToolType: part.toolResponse.toolType
1767
+ })
1721
1768
  });
1722
1769
  lastServerToolCallId = void 0;
1723
1770
  }
@@ -1743,17 +1790,15 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1743
1790
  },
1744
1791
  usage: convertGoogleUsage(usageMetadata),
1745
1792
  warnings,
1746
- providerMetadata: {
1747
- [providerOptionsName]: {
1748
- promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
1749
- groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
1750
- urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
1751
- safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
1752
- usageMetadata: usageMetadata != null ? usageMetadata : null,
1753
- finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
1754
- serviceTier: (_p = response.serviceTier) != null ? _p : null
1755
- }
1756
- },
1793
+ providerMetadata: wrapProviderMetadata({
1794
+ promptFeedback: (_k = response.promptFeedback) != null ? _k : null,
1795
+ groundingMetadata: (_l = candidate.groundingMetadata) != null ? _l : null,
1796
+ urlContextMetadata: (_m = candidate.urlContextMetadata) != null ? _m : null,
1797
+ safetyRatings: (_n = candidate.safetyRatings) != null ? _n : null,
1798
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
1799
+ finishMessage: (_o = candidate.finishMessage) != null ? _o : null,
1800
+ serviceTier: (_p = response.serviceTier) != null ? _p : null
1801
+ }),
1757
1802
  request: { body: args },
1758
1803
  response: {
1759
1804
  // TODO timestamp, model id, id
@@ -1763,10 +1808,13 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1763
1808
  };
1764
1809
  }
1765
1810
  async doStream(options) {
1766
- const { args, warnings, providerOptionsName } = await this.getArgs(
1811
+ const { args, warnings, providerOptionsNames } = await this.getArgs(
1767
1812
  options,
1768
1813
  { isStreaming: true }
1769
1814
  );
1815
+ const wrapProviderMetadata = (payload) => Object.fromEntries(
1816
+ providerOptionsNames.map((name) => [name, payload])
1817
+ );
1770
1818
  const headers = combineHeaders2(
1771
1819
  this.config.headers ? await resolve2(this.config.headers) : void 0,
1772
1820
  options.headers
@@ -1874,11 +1922,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1874
1922
  lastCodeExecutionToolCallId = void 0;
1875
1923
  }
1876
1924
  } else if ("text" in part && part.text != null) {
1877
- const thoughtSignatureMetadata = part.thoughtSignature ? {
1878
- [providerOptionsName]: {
1879
- thoughtSignature: part.thoughtSignature
1880
- }
1881
- } : void 0;
1925
+ const thoughtSignatureMetadata = part.thoughtSignature ? wrapProviderMetadata({
1926
+ thoughtSignature: part.thoughtSignature
1927
+ }) : void 0;
1882
1928
  if (part.text.length === 0) {
1883
1929
  if (thoughtSignatureMetadata != null && currentTextBlockId !== null) {
1884
1930
  controller.enqueue({
@@ -1950,27 +1996,23 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1950
1996
  }
1951
1997
  const hasThought = part.thought === true;
1952
1998
  const hasThoughtSignature = !!part.thoughtSignature;
1953
- const fileMeta = hasThoughtSignature ? {
1954
- [providerOptionsName]: {
1955
- thoughtSignature: part.thoughtSignature
1956
- }
1957
- } : void 0;
1999
+ const fileMeta = hasThoughtSignature ? wrapProviderMetadata({
2000
+ thoughtSignature: part.thoughtSignature
2001
+ }) : void 0;
1958
2002
  controller.enqueue({
1959
2003
  type: hasThought ? "reasoning-file" : "file",
1960
2004
  mediaType: part.inlineData.mimeType,
1961
- data: part.inlineData.data,
2005
+ data: { type: "data", data: part.inlineData.data },
1962
2006
  providerMetadata: fileMeta
1963
2007
  });
1964
2008
  } else if ("toolCall" in part && part.toolCall) {
1965
2009
  const toolCallId = (_e = part.toolCall.id) != null ? _e : generateId3();
1966
2010
  lastServerToolCallId = toolCallId;
1967
- const serverMeta = {
1968
- [providerOptionsName]: {
1969
- ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
1970
- serverToolCallId: toolCallId,
1971
- serverToolType: part.toolCall.toolType
1972
- }
1973
- };
2011
+ const serverMeta = wrapProviderMetadata({
2012
+ ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
2013
+ serverToolCallId: toolCallId,
2014
+ serverToolType: part.toolCall.toolType
2015
+ });
1974
2016
  controller.enqueue({
1975
2017
  type: "tool-call",
1976
2018
  toolCallId,
@@ -1982,13 +2024,11 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
1982
2024
  });
1983
2025
  } else if ("toolResponse" in part && part.toolResponse) {
1984
2026
  const responseToolCallId = (_g = lastServerToolCallId != null ? lastServerToolCallId : part.toolResponse.id) != null ? _g : generateId3();
1985
- const serverMeta = {
1986
- [providerOptionsName]: {
1987
- ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
1988
- serverToolCallId: responseToolCallId,
1989
- serverToolType: part.toolResponse.toolType
1990
- }
1991
- };
2027
+ const serverMeta = wrapProviderMetadata({
2028
+ ...part.thoughtSignature ? { thoughtSignature: part.thoughtSignature } : {},
2029
+ serverToolCallId: responseToolCallId,
2030
+ serverToolType: part.toolResponse.toolType
2031
+ });
1992
2032
  controller.enqueue({
1993
2033
  type: "tool-result",
1994
2034
  toolCallId: responseToolCallId,
@@ -2001,11 +2041,9 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2001
2041
  }
2002
2042
  for (const part of parts) {
2003
2043
  if (!("functionCall" in part)) continue;
2004
- const providerMeta = part.thoughtSignature ? {
2005
- [providerOptionsName]: {
2006
- thoughtSignature: part.thoughtSignature
2007
- }
2008
- } : void 0;
2044
+ const providerMeta = part.thoughtSignature ? wrapProviderMetadata({
2045
+ thoughtSignature: part.thoughtSignature
2046
+ }) : void 0;
2009
2047
  const isStreamingChunk = part.functionCall.partialArgs != null || part.functionCall.name != null && part.functionCall.willContinue === true;
2010
2048
  const isTerminalChunk = part.functionCall.name == null && part.functionCall.args == null && part.functionCall.partialArgs == null && part.functionCall.willContinue == null;
2011
2049
  const isCompleteCall = part.functionCall.name != null && part.functionCall.args != null && part.functionCall.partialArgs == null;
@@ -2116,17 +2154,15 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
2116
2154
  }),
2117
2155
  raw: candidate.finishReason
2118
2156
  };
2119
- providerMetadata = {
2120
- [providerOptionsName]: {
2121
- promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
2122
- groundingMetadata: lastGroundingMetadata,
2123
- urlContextMetadata: lastUrlContextMetadata,
2124
- safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
2125
- usageMetadata: usageMetadata != null ? usageMetadata : null,
2126
- finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
2127
- serviceTier
2128
- }
2129
- };
2157
+ providerMetadata = wrapProviderMetadata({
2158
+ promptFeedback: (_j = value.promptFeedback) != null ? _j : null,
2159
+ groundingMetadata: lastGroundingMetadata,
2160
+ urlContextMetadata: lastUrlContextMetadata,
2161
+ safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null,
2162
+ usageMetadata: usageMetadata != null ? usageMetadata : null,
2163
+ finishMessage: (_l = candidate.finishMessage) != null ? _l : null,
2164
+ serviceTier
2165
+ });
2130
2166
  }
2131
2167
  },
2132
2168
  flush(controller) {
@@ -2693,16 +2729,33 @@ import {
2693
2729
  convertToBase64 as convertToBase642,
2694
2730
  createJsonResponseHandler as createJsonResponseHandler3,
2695
2731
  generateId as defaultGenerateId,
2696
- lazySchema as lazySchema12,
2732
+ lazySchema as lazySchema13,
2697
2733
  parseProviderOptions as parseProviderOptions3,
2698
2734
  postJsonToApi as postJsonToApi3,
2699
2735
  resolve as resolve3,
2700
2736
  serializeModelOptions as serializeModelOptions3,
2701
2737
  WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3,
2702
2738
  WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
2739
+ zodSchema as zodSchema13
2740
+ } from "@ai-sdk/provider-utils";
2741
+ import { z as z14 } from "zod/v4";
2742
+
2743
+ // src/google-image-model-options.ts
2744
+ import {
2745
+ lazySchema as lazySchema12,
2703
2746
  zodSchema as zodSchema12
2704
2747
  } from "@ai-sdk/provider-utils";
2705
2748
  import { z as z13 } from "zod/v4";
2749
+ var googleImageModelOptionsSchema = lazySchema12(
2750
+ () => zodSchema12(
2751
+ z13.object({
2752
+ personGeneration: z13.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
2753
+ aspectRatio: z13.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
2754
+ })
2755
+ )
2756
+ );
2757
+
2758
+ // src/google-image-model.ts
2706
2759
  var GoogleImageModel = class _GoogleImageModel {
2707
2760
  constructor(modelId, settings, config) {
2708
2761
  this.modelId = modelId;
@@ -2869,13 +2922,16 @@ var GoogleImageModel = class _GoogleImageModel {
2869
2922
  if (file.type === "url") {
2870
2923
  userContent.push({
2871
2924
  type: "file",
2872
- data: new URL(file.url),
2925
+ data: { type: "url", url: new URL(file.url) },
2873
2926
  mediaType: "image/*"
2874
2927
  });
2875
2928
  } else {
2876
2929
  userContent.push({
2877
2930
  type: "file",
2878
- data: typeof file.data === "string" ? file.data : new Uint8Array(file.data),
2931
+ data: {
2932
+ type: "data",
2933
+ data: typeof file.data === "string" ? file.data : new Uint8Array(file.data)
2934
+ },
2879
2935
  mediaType: file.mediaType
2880
2936
  });
2881
2937
  }
@@ -2909,8 +2965,8 @@ var GoogleImageModel = class _GoogleImageModel {
2909
2965
  const currentDate = (_f = (_e = (_d = this.config._internal) == null ? void 0 : _d.currentDate) == null ? void 0 : _e.call(_d)) != null ? _f : /* @__PURE__ */ new Date();
2910
2966
  const images = [];
2911
2967
  for (const part of result.content) {
2912
- if (part.type === "file" && part.mediaType.startsWith("image/")) {
2913
- images.push(convertToBase642(part.data));
2968
+ if (part.type === "file" && part.mediaType.startsWith("image/") && part.data.type === "data") {
2969
+ images.push(convertToBase642(part.data.data));
2914
2970
  }
2915
2971
  }
2916
2972
  return {
@@ -2937,18 +2993,10 @@ var GoogleImageModel = class _GoogleImageModel {
2937
2993
  function isGeminiModel(modelId) {
2938
2994
  return modelId.startsWith("gemini-");
2939
2995
  }
2940
- var googleImageResponseSchema = lazySchema12(
2941
- () => zodSchema12(
2942
- z13.object({
2943
- predictions: z13.array(z13.object({ bytesBase64Encoded: z13.string() })).default([])
2944
- })
2945
- )
2946
- );
2947
- var googleImageModelOptionsSchema = lazySchema12(
2948
- () => zodSchema12(
2949
- z13.object({
2950
- personGeneration: z13.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
2951
- aspectRatio: z13.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
2996
+ var googleImageResponseSchema = lazySchema13(
2997
+ () => zodSchema13(
2998
+ z14.object({
2999
+ predictions: z14.array(z14.object({ bytesBase64Encoded: z14.string() })).default([])
2952
3000
  })
2953
3001
  )
2954
3002
  );
@@ -2959,14 +3007,15 @@ import {
2959
3007
  } from "@ai-sdk/provider";
2960
3008
  import {
2961
3009
  combineHeaders as combineHeaders4,
3010
+ convertInlineFileDataToUint8Array,
2962
3011
  createJsonResponseHandler as createJsonResponseHandler4,
2963
3012
  delay,
2964
- lazySchema as lazySchema13,
3013
+ lazySchema as lazySchema14,
2965
3014
  parseProviderOptions as parseProviderOptions4,
2966
- zodSchema as zodSchema13,
3015
+ zodSchema as zodSchema14,
2967
3016
  getFromApi
2968
3017
  } from "@ai-sdk/provider-utils";
2969
- import { z as z14 } from "zod/v4";
3018
+ import { z as z15 } from "zod/v4";
2970
3019
  var GoogleFiles = class {
2971
3020
  constructor(config) {
2972
3021
  this.config = config;
@@ -2988,8 +3037,7 @@ var GoogleFiles = class {
2988
3037
  if (options.filename != null) {
2989
3038
  warnings.push({ type: "unsupported", feature: "filename" });
2990
3039
  }
2991
- const data = options.data;
2992
- const fileBytes = data instanceof Uint8Array ? data : Uint8Array.from(atob(data), (c) => c.charCodeAt(0));
3040
+ const fileBytes = convertInlineFileDataToUint8Array(options.data);
2993
3041
  const mediaType = options.mediaType;
2994
3042
  const displayName = googleOptions == null ? void 0 : googleOptions.displayName;
2995
3043
  const baseOrigin = this.config.baseURL.replace(/\/v1beta$/, "");
@@ -3090,28 +3138,28 @@ var GoogleFiles = class {
3090
3138
  };
3091
3139
  }
3092
3140
  };
3093
- var googleFileResponseSchema = lazySchema13(
3094
- () => zodSchema13(
3095
- z14.object({
3096
- name: z14.string(),
3097
- displayName: z14.string().nullish(),
3098
- mimeType: z14.string(),
3099
- sizeBytes: z14.string().nullish(),
3100
- createTime: z14.string().nullish(),
3101
- updateTime: z14.string().nullish(),
3102
- expirationTime: z14.string().nullish(),
3103
- sha256Hash: z14.string().nullish(),
3104
- uri: z14.string(),
3105
- state: z14.string()
3141
+ var googleFileResponseSchema = lazySchema14(
3142
+ () => zodSchema14(
3143
+ z15.object({
3144
+ name: z15.string(),
3145
+ displayName: z15.string().nullish(),
3146
+ mimeType: z15.string(),
3147
+ sizeBytes: z15.string().nullish(),
3148
+ createTime: z15.string().nullish(),
3149
+ updateTime: z15.string().nullish(),
3150
+ expirationTime: z15.string().nullish(),
3151
+ sha256Hash: z15.string().nullish(),
3152
+ uri: z15.string(),
3153
+ state: z15.string()
3106
3154
  })
3107
3155
  )
3108
3156
  );
3109
- var googleFilesUploadOptionsSchema = lazySchema13(
3110
- () => zodSchema13(
3111
- z14.object({
3112
- displayName: z14.string().nullish(),
3113
- pollIntervalMs: z14.number().positive().nullish(),
3114
- pollTimeoutMs: z14.number().positive().nullish()
3157
+ var googleFilesUploadOptionsSchema = lazySchema14(
3158
+ () => zodSchema14(
3159
+ z15.object({
3160
+ displayName: z15.string().nullish(),
3161
+ pollIntervalMs: z15.number().positive().nullish(),
3162
+ pollTimeoutMs: z15.number().positive().nullish()
3115
3163
  }).passthrough()
3116
3164
  )
3117
3165
  );
@@ -3126,13 +3174,33 @@ import {
3126
3174
  createJsonResponseHandler as createJsonResponseHandler5,
3127
3175
  delay as delay2,
3128
3176
  getFromApi as getFromApi2,
3129
- lazySchema as lazySchema14,
3130
3177
  parseProviderOptions as parseProviderOptions5,
3131
3178
  postJsonToApi as postJsonToApi4,
3132
- resolve as resolve4,
3133
- zodSchema as zodSchema14
3179
+ resolve as resolve4
3134
3180
  } from "@ai-sdk/provider-utils";
3135
- import { z as z15 } from "zod/v4";
3181
+ import { z as z17 } from "zod/v4";
3182
+
3183
+ // src/google-video-model-options.ts
3184
+ import { lazySchema as lazySchema15, zodSchema as zodSchema15 } from "@ai-sdk/provider-utils";
3185
+ import { z as z16 } from "zod/v4";
3186
+ var googleVideoModelOptionsSchema = lazySchema15(
3187
+ () => zodSchema15(
3188
+ z16.object({
3189
+ pollIntervalMs: z16.number().positive().nullish(),
3190
+ pollTimeoutMs: z16.number().positive().nullish(),
3191
+ personGeneration: z16.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
3192
+ negativePrompt: z16.string().nullish(),
3193
+ referenceImages: z16.array(
3194
+ z16.object({
3195
+ bytesBase64Encoded: z16.string().nullish(),
3196
+ gcsUri: z16.string().nullish()
3197
+ })
3198
+ ).nullish()
3199
+ }).passthrough()
3200
+ )
3201
+ );
3202
+
3203
+ // src/google-video-model.ts
3136
3204
  var GoogleVideoModel = class {
3137
3205
  constructor(modelId, config) {
3138
3206
  this.modelId = modelId;
@@ -3344,42 +3412,26 @@ var GoogleVideoModel = class {
3344
3412
  };
3345
3413
  }
3346
3414
  };
3347
- var googleOperationSchema = z15.object({
3348
- name: z15.string().nullish(),
3349
- done: z15.boolean().nullish(),
3350
- error: z15.object({
3351
- code: z15.number().nullish(),
3352
- message: z15.string(),
3353
- status: z15.string().nullish()
3415
+ var googleOperationSchema = z17.object({
3416
+ name: z17.string().nullish(),
3417
+ done: z17.boolean().nullish(),
3418
+ error: z17.object({
3419
+ code: z17.number().nullish(),
3420
+ message: z17.string(),
3421
+ status: z17.string().nullish()
3354
3422
  }).nullish(),
3355
- response: z15.object({
3356
- generateVideoResponse: z15.object({
3357
- generatedSamples: z15.array(
3358
- z15.object({
3359
- video: z15.object({
3360
- uri: z15.string().nullish()
3423
+ response: z17.object({
3424
+ generateVideoResponse: z17.object({
3425
+ generatedSamples: z17.array(
3426
+ z17.object({
3427
+ video: z17.object({
3428
+ uri: z17.string().nullish()
3361
3429
  }).nullish()
3362
3430
  })
3363
3431
  ).nullish()
3364
3432
  }).nullish()
3365
3433
  }).nullish()
3366
3434
  });
3367
- var googleVideoModelOptionsSchema = lazySchema14(
3368
- () => zodSchema14(
3369
- z15.object({
3370
- pollIntervalMs: z15.number().positive().nullish(),
3371
- pollTimeoutMs: z15.number().positive().nullish(),
3372
- personGeneration: z15.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
3373
- negativePrompt: z15.string().nullish(),
3374
- referenceImages: z15.array(
3375
- z15.object({
3376
- bytesBase64Encoded: z15.string().nullish(),
3377
- gcsUri: z15.string().nullish()
3378
- })
3379
- ).nullish()
3380
- }).passthrough()
3381
- )
3382
- );
3383
3435
 
3384
3436
  // src/google-provider.ts
3385
3437
  function createGoogle(options = {}) {