ai 7.0.0-beta.100 → 7.0.0-beta.101

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # ai
2
2
 
3
+ ## 7.0.0-beta.101
4
+
5
+ ### Patch Changes
6
+
7
+ - 4873966: chore(ai): allow general usage of `logWarnings` and emit them via Node API when available
8
+
3
9
  ## 7.0.0-beta.100
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -6737,13 +6737,13 @@ type LogWarningsFunction = (options: {
6737
6737
  */
6738
6738
  warnings: Warning[];
6739
6739
  /**
6740
- * The provider id used for the call.
6740
+ * The provider id used for the call, if scoped to a specific provider.
6741
6741
  */
6742
- provider: string;
6742
+ provider?: string;
6743
6743
  /**
6744
- * The model id used for the call.
6744
+ * The model id used for the call, if scoped to a specific provider.
6745
6745
  */
6746
- model: string;
6746
+ model?: string;
6747
6747
  }) => void;
6748
6748
 
6749
6749
  /**
package/dist/index.js CHANGED
@@ -514,7 +514,8 @@ function formatWarning({
514
514
  provider,
515
515
  model
516
516
  }) {
517
- const prefix = `AI SDK Warning (${provider} / ${model}):`;
517
+ const scope = provider != null && model != null ? ` (${provider} / ${model})` : "";
518
+ const prefix = `AI SDK Warning${scope}:`;
518
519
  switch (warning.type) {
519
520
  case "unsupported": {
520
521
  let message = `${prefix} The feature "${warning.feature}" is not supported.`;
@@ -560,13 +561,18 @@ var logWarnings = (options) => {
560
561
  console.info(FIRST_WARNING_INFO_MESSAGE);
561
562
  }
562
563
  for (const warning of options.warnings) {
563
- console.warn(
564
- formatWarning({
565
- warning,
566
- provider: options.provider,
567
- model: options.model
568
- })
569
- );
564
+ const message = formatWarning({
565
+ warning,
566
+ provider: options.provider,
567
+ model: options.model
568
+ });
569
+ if (typeof process !== "undefined" && typeof process.emitWarning === "function") {
570
+ process.emitWarning(message, {
571
+ type: warning.type === "deprecated" ? "DeprecationWarning" : "Warning"
572
+ });
573
+ } else {
574
+ console.warn(message);
575
+ }
570
576
  }
571
577
  };
572
578
 
@@ -1255,7 +1261,7 @@ import {
1255
1261
  } from "@ai-sdk/provider-utils";
1256
1262
 
1257
1263
  // src/version.ts
1258
- var VERSION = true ? "7.0.0-beta.100" : "0.0.0-test";
1264
+ var VERSION = true ? "7.0.0-beta.101" : "0.0.0-test";
1259
1265
 
1260
1266
  // src/util/download/download.ts
1261
1267
  var download = async ({
@@ -1525,6 +1531,7 @@ function convertToLanguageModelMessage({
1525
1531
  // TODO: remove in v8 when "file-id" and "image-file-id" types are removed
1526
1532
  provider
1527
1533
  }) {
1534
+ const warnings = [];
1528
1535
  const role = message.role;
1529
1536
  switch (role) {
1530
1537
  case "system": {
@@ -1542,11 +1549,15 @@ function convertToLanguageModelMessage({
1542
1549
  providerOptions: message.providerOptions
1543
1550
  };
1544
1551
  }
1545
- return {
1552
+ const converted = {
1546
1553
  role: "user",
1547
1554
  content: message.content.map((part) => convertPartToLanguageModelPart(part, downloadedAssets)).filter((part) => part.type !== "text" || part.text !== ""),
1548
1555
  providerOptions: message.providerOptions
1549
1556
  };
1557
+ if (warnings.length > 0) {
1558
+ logWarnings({ warnings });
1559
+ }
1560
+ return converted;
1550
1561
  }
1551
1562
  case "assistant": {
1552
1563
  if (typeof message.content === "string") {
@@ -1556,7 +1567,7 @@ function convertToLanguageModelMessage({
1556
1567
  providerOptions: message.providerOptions
1557
1568
  };
1558
1569
  }
1559
- return {
1570
+ const converted = {
1560
1571
  role: "assistant",
1561
1572
  content: message.content.filter(
1562
1573
  // remove empty text parts (no text, and no provider options):
@@ -1636,7 +1647,8 @@ function convertToLanguageModelMessage({
1636
1647
  toolName: part.toolName,
1637
1648
  output: mapToolResultOutput({
1638
1649
  output: part.output,
1639
- provider
1650
+ provider,
1651
+ warnings
1640
1652
  }),
1641
1653
  providerOptions
1642
1654
  };
@@ -1645,9 +1657,13 @@ function convertToLanguageModelMessage({
1645
1657
  }),
1646
1658
  providerOptions: message.providerOptions
1647
1659
  };
1660
+ if (warnings.length > 0) {
1661
+ logWarnings({ warnings });
1662
+ }
1663
+ return converted;
1648
1664
  }
1649
1665
  case "tool": {
1650
- return {
1666
+ const converted = {
1651
1667
  role: "tool",
1652
1668
  content: message.content.filter(
1653
1669
  // Only include tool-approval-response for provider-executed tools
@@ -1661,7 +1677,8 @@ function convertToLanguageModelMessage({
1661
1677
  toolName: part.toolName,
1662
1678
  output: mapToolResultOutput({
1663
1679
  output: part.output,
1664
- provider
1680
+ provider,
1681
+ warnings
1665
1682
  }),
1666
1683
  providerOptions: part.providerOptions
1667
1684
  };
@@ -1678,6 +1695,10 @@ function convertToLanguageModelMessage({
1678
1695
  }),
1679
1696
  providerOptions: message.providerOptions
1680
1697
  };
1698
+ if (warnings.length > 0) {
1699
+ logWarnings({ warnings });
1700
+ }
1701
+ return converted;
1681
1702
  }
1682
1703
  default: {
1683
1704
  const _exhaustiveCheck = role;
@@ -1784,7 +1805,8 @@ function mapToolResultOutput({
1784
1805
  output,
1785
1806
  // `provider` is only needed here to convert legacy "file-id" and "image-file-id" types to provider references, in case they are using string ID values.
1786
1807
  // TODO: remove in v8 when "file-id" and "image-file-id" types are removed
1787
- provider
1808
+ provider,
1809
+ warnings = []
1788
1810
  }) {
1789
1811
  if (output.type !== "content") {
1790
1812
  return output;
@@ -1795,6 +1817,11 @@ function mapToolResultOutput({
1795
1817
  var _a21;
1796
1818
  switch (item.type) {
1797
1819
  case "image-data": {
1820
+ warnings.push({
1821
+ type: "deprecated",
1822
+ setting: '"tool-result" content of type "image-data"',
1823
+ message: `The "image-data" type for tool result content is deprecated. Use the "file-data" type instead.`
1824
+ });
1798
1825
  return {
1799
1826
  type: "file-data",
1800
1827
  data: item.data,
@@ -1803,6 +1830,11 @@ function mapToolResultOutput({
1803
1830
  };
1804
1831
  }
1805
1832
  case "image-url": {
1833
+ warnings.push({
1834
+ type: "deprecated",
1835
+ setting: '"tool-result" content of type "image-url"',
1836
+ message: `The "image-url" type for tool result content is deprecated. Use the "file-url" type instead.`
1837
+ });
1806
1838
  return {
1807
1839
  type: "file-url",
1808
1840
  url: item.url,
@@ -1811,6 +1843,11 @@ function mapToolResultOutput({
1811
1843
  };
1812
1844
  }
1813
1845
  case "image-file-id": {
1846
+ warnings.push({
1847
+ type: "deprecated",
1848
+ setting: '"tool-result" content of type "image-file-id"',
1849
+ message: `The "image-file-id" type for tool result content is deprecated. Use the "file-reference" type instead.`
1850
+ });
1814
1851
  return {
1815
1852
  type: "file-reference",
1816
1853
  providerReference: convertFileIdToProviderReference({
@@ -1821,6 +1858,11 @@ function mapToolResultOutput({
1821
1858
  };
1822
1859
  }
1823
1860
  case "image-file-reference": {
1861
+ warnings.push({
1862
+ type: "deprecated",
1863
+ setting: '"tool-result" content of type "image-file-reference"',
1864
+ message: `The "image-file-reference" type for tool result content is deprecated. Use the "file-reference" type instead.`
1865
+ });
1824
1866
  return {
1825
1867
  type: "file-reference",
1826
1868
  providerReference: item.providerReference,
@@ -1828,6 +1870,11 @@ function mapToolResultOutput({
1828
1870
  };
1829
1871
  }
1830
1872
  case "file-id": {
1873
+ warnings.push({
1874
+ type: "deprecated",
1875
+ setting: '"tool-result" content of type "file-id"',
1876
+ message: `The "file-id" type for tool result content is deprecated. Use the "file-reference" type instead.`
1877
+ });
1831
1878
  return {
1832
1879
  type: "file-reference",
1833
1880
  providerReference: convertFileIdToProviderReference({
@@ -1840,15 +1887,12 @@ function mapToolResultOutput({
1840
1887
  case "file-url": {
1841
1888
  const mediaType = (_a21 = item.mediaType) != null ? _a21 : getMediaTypeFromUrl(item.url);
1842
1889
  if (!item.mediaType) {
1843
- if (mediaType === "application/octet-stream") {
1844
- console.warn(
1845
- `AI SDK: 'file-url' tool result content part is missing 'mediaType'. Unable to infer media type from URL. Defaulting to 'application/octet-stream'. Provide 'mediaType' on the 'file-url' part for correct provider behavior.`
1846
- );
1847
- } else {
1848
- console.warn(
1849
- `AI SDK: 'file-url' tool result content part is missing 'mediaType'. Inferred '${mediaType}' from URL. Provide 'mediaType' on the 'file-url' part for correct provider behavior.`
1850
- );
1851
- }
1890
+ const messageSuffix = mediaType === "application/octet-stream" ? `Unable to infer media type from URL. Defaulting to 'application/octet-stream'.` : `Inferred media type '${mediaType}' from URL.`;
1891
+ warnings.push({
1892
+ type: "deprecated",
1893
+ setting: '"tool-result" content of type "file-url" without mediaType',
1894
+ message: `The "file-url" tool result content part with URL "${item.url}" is missing a "mediaType". ` + messageSuffix
1895
+ });
1852
1896
  }
1853
1897
  return {
1854
1898
  type: "file-url",