@ai-sdk/anthropic 3.0.8 → 3.0.10

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.
@@ -665,6 +665,7 @@ var anthropicMessagesChunkSchema = lazySchema2(
665
665
  }).nullish()
666
666
  }),
667
667
  usage: z2.looseObject({
668
+ input_tokens: z2.number().nullish(),
668
669
  output_tokens: z2.number(),
669
670
  cache_creation_input_tokens: z2.number().nullish()
670
671
  })
@@ -1557,6 +1558,15 @@ function convertToString(data) {
1557
1558
  functionality: `unsupported data type for text documents: ${typeof data}`
1558
1559
  });
1559
1560
  }
1561
+ function isUrlData(data) {
1562
+ return data instanceof URL || isUrlString(data);
1563
+ }
1564
+ function isUrlString(data) {
1565
+ return typeof data === "string" && /^https?:\/\//i.test(data);
1566
+ }
1567
+ function getUrlString(data) {
1568
+ return data instanceof URL ? data.toString() : data;
1569
+ }
1560
1570
  async function convertToAnthropicMessagesPrompt({
1561
1571
  prompt,
1562
1572
  sendReasoning,
@@ -1640,9 +1650,9 @@ async function convertToAnthropicMessagesPrompt({
1640
1650
  if (part.mediaType.startsWith("image/")) {
1641
1651
  anthropicContent.push({
1642
1652
  type: "image",
1643
- source: part.data instanceof URL ? {
1653
+ source: isUrlData(part.data) ? {
1644
1654
  type: "url",
1645
- url: part.data.toString()
1655
+ url: getUrlString(part.data)
1646
1656
  } : {
1647
1657
  type: "base64",
1648
1658
  media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
@@ -1660,9 +1670,9 @@ async function convertToAnthropicMessagesPrompt({
1660
1670
  );
1661
1671
  anthropicContent.push({
1662
1672
  type: "document",
1663
- source: part.data instanceof URL ? {
1673
+ source: isUrlData(part.data) ? {
1664
1674
  type: "url",
1665
- url: part.data.toString()
1675
+ url: getUrlString(part.data)
1666
1676
  } : {
1667
1677
  type: "base64",
1668
1678
  media_type: "application/pdf",
@@ -1684,9 +1694,9 @@ async function convertToAnthropicMessagesPrompt({
1684
1694
  );
1685
1695
  anthropicContent.push({
1686
1696
  type: "document",
1687
- source: part.data instanceof URL ? {
1697
+ source: isUrlData(part.data) ? {
1688
1698
  type: "url",
1689
- url: part.data.toString()
1699
+ url: getUrlString(part.data)
1690
1700
  } : {
1691
1701
  type: "text",
1692
1702
  media_type: "text/plain",
@@ -3673,6 +3683,9 @@ var AnthropicMessagesLanguageModel = class {
3673
3683
  return;
3674
3684
  }
3675
3685
  case "message_delta": {
3686
+ if (value.usage.input_tokens != null && usage.input_tokens !== value.usage.input_tokens) {
3687
+ usage.input_tokens = value.usage.input_tokens;
3688
+ }
3676
3689
  usage.output_tokens = value.usage.output_tokens;
3677
3690
  finishReason = {
3678
3691
  unified: mapAnthropicStopReason({