@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.
- package/CHANGELOG.md +12 -0
- package/dist/index.js +20 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -7
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +19 -6
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +19 -6
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "@ai-sdk/provider-utils";
|
|
12
12
|
|
|
13
13
|
// src/version.ts
|
|
14
|
-
var VERSION = true ? "3.0.
|
|
14
|
+
var VERSION = true ? "3.0.10" : "0.0.0-test";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-messages-language-model.ts
|
|
17
17
|
import {
|
|
@@ -680,6 +680,7 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
680
680
|
}).nullish()
|
|
681
681
|
}),
|
|
682
682
|
usage: z2.looseObject({
|
|
683
|
+
input_tokens: z2.number().nullish(),
|
|
683
684
|
output_tokens: z2.number(),
|
|
684
685
|
cache_creation_input_tokens: z2.number().nullish()
|
|
685
686
|
})
|
|
@@ -1572,6 +1573,15 @@ function convertToString(data) {
|
|
|
1572
1573
|
functionality: `unsupported data type for text documents: ${typeof data}`
|
|
1573
1574
|
});
|
|
1574
1575
|
}
|
|
1576
|
+
function isUrlData(data) {
|
|
1577
|
+
return data instanceof URL || isUrlString(data);
|
|
1578
|
+
}
|
|
1579
|
+
function isUrlString(data) {
|
|
1580
|
+
return typeof data === "string" && /^https?:\/\//i.test(data);
|
|
1581
|
+
}
|
|
1582
|
+
function getUrlString(data) {
|
|
1583
|
+
return data instanceof URL ? data.toString() : data;
|
|
1584
|
+
}
|
|
1575
1585
|
async function convertToAnthropicMessagesPrompt({
|
|
1576
1586
|
prompt,
|
|
1577
1587
|
sendReasoning,
|
|
@@ -1655,9 +1665,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1655
1665
|
if (part.mediaType.startsWith("image/")) {
|
|
1656
1666
|
anthropicContent.push({
|
|
1657
1667
|
type: "image",
|
|
1658
|
-
source: part.data
|
|
1668
|
+
source: isUrlData(part.data) ? {
|
|
1659
1669
|
type: "url",
|
|
1660
|
-
url: part.data
|
|
1670
|
+
url: getUrlString(part.data)
|
|
1661
1671
|
} : {
|
|
1662
1672
|
type: "base64",
|
|
1663
1673
|
media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
|
|
@@ -1675,9 +1685,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1675
1685
|
);
|
|
1676
1686
|
anthropicContent.push({
|
|
1677
1687
|
type: "document",
|
|
1678
|
-
source: part.data
|
|
1688
|
+
source: isUrlData(part.data) ? {
|
|
1679
1689
|
type: "url",
|
|
1680
|
-
url: part.data
|
|
1690
|
+
url: getUrlString(part.data)
|
|
1681
1691
|
} : {
|
|
1682
1692
|
type: "base64",
|
|
1683
1693
|
media_type: "application/pdf",
|
|
@@ -1699,9 +1709,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1699
1709
|
);
|
|
1700
1710
|
anthropicContent.push({
|
|
1701
1711
|
type: "document",
|
|
1702
|
-
source: part.data
|
|
1712
|
+
source: isUrlData(part.data) ? {
|
|
1703
1713
|
type: "url",
|
|
1704
|
-
url: part.data
|
|
1714
|
+
url: getUrlString(part.data)
|
|
1705
1715
|
} : {
|
|
1706
1716
|
type: "text",
|
|
1707
1717
|
media_type: "text/plain",
|
|
@@ -3688,6 +3698,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3688
3698
|
return;
|
|
3689
3699
|
}
|
|
3690
3700
|
case "message_delta": {
|
|
3701
|
+
if (value.usage.input_tokens != null && usage.input_tokens !== value.usage.input_tokens) {
|
|
3702
|
+
usage.input_tokens = value.usage.input_tokens;
|
|
3703
|
+
}
|
|
3691
3704
|
usage.output_tokens = value.usage.output_tokens;
|
|
3692
3705
|
finishReason = {
|
|
3693
3706
|
unified: mapAnthropicStopReason({
|