@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/internal/index.js
CHANGED
|
@@ -678,6 +678,7 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
678
678
|
}).nullish()
|
|
679
679
|
}),
|
|
680
680
|
usage: import_v42.z.looseObject({
|
|
681
|
+
input_tokens: import_v42.z.number().nullish(),
|
|
681
682
|
output_tokens: import_v42.z.number(),
|
|
682
683
|
cache_creation_input_tokens: import_v42.z.number().nullish()
|
|
683
684
|
})
|
|
@@ -1541,6 +1542,15 @@ function convertToString(data) {
|
|
|
1541
1542
|
functionality: `unsupported data type for text documents: ${typeof data}`
|
|
1542
1543
|
});
|
|
1543
1544
|
}
|
|
1545
|
+
function isUrlData(data) {
|
|
1546
|
+
return data instanceof URL || isUrlString(data);
|
|
1547
|
+
}
|
|
1548
|
+
function isUrlString(data) {
|
|
1549
|
+
return typeof data === "string" && /^https?:\/\//i.test(data);
|
|
1550
|
+
}
|
|
1551
|
+
function getUrlString(data) {
|
|
1552
|
+
return data instanceof URL ? data.toString() : data;
|
|
1553
|
+
}
|
|
1544
1554
|
async function convertToAnthropicMessagesPrompt({
|
|
1545
1555
|
prompt,
|
|
1546
1556
|
sendReasoning,
|
|
@@ -1624,9 +1634,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1624
1634
|
if (part.mediaType.startsWith("image/")) {
|
|
1625
1635
|
anthropicContent.push({
|
|
1626
1636
|
type: "image",
|
|
1627
|
-
source: part.data
|
|
1637
|
+
source: isUrlData(part.data) ? {
|
|
1628
1638
|
type: "url",
|
|
1629
|
-
url: part.data
|
|
1639
|
+
url: getUrlString(part.data)
|
|
1630
1640
|
} : {
|
|
1631
1641
|
type: "base64",
|
|
1632
1642
|
media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
|
|
@@ -1644,9 +1654,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1644
1654
|
);
|
|
1645
1655
|
anthropicContent.push({
|
|
1646
1656
|
type: "document",
|
|
1647
|
-
source: part.data
|
|
1657
|
+
source: isUrlData(part.data) ? {
|
|
1648
1658
|
type: "url",
|
|
1649
|
-
url: part.data
|
|
1659
|
+
url: getUrlString(part.data)
|
|
1650
1660
|
} : {
|
|
1651
1661
|
type: "base64",
|
|
1652
1662
|
media_type: "application/pdf",
|
|
@@ -1668,9 +1678,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1668
1678
|
);
|
|
1669
1679
|
anthropicContent.push({
|
|
1670
1680
|
type: "document",
|
|
1671
|
-
source: part.data
|
|
1681
|
+
source: isUrlData(part.data) ? {
|
|
1672
1682
|
type: "url",
|
|
1673
|
-
url: part.data
|
|
1683
|
+
url: getUrlString(part.data)
|
|
1674
1684
|
} : {
|
|
1675
1685
|
type: "text",
|
|
1676
1686
|
media_type: "text/plain",
|
|
@@ -3657,6 +3667,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3657
3667
|
return;
|
|
3658
3668
|
}
|
|
3659
3669
|
case "message_delta": {
|
|
3670
|
+
if (value.usage.input_tokens != null && usage.input_tokens !== value.usage.input_tokens) {
|
|
3671
|
+
usage.input_tokens = value.usage.input_tokens;
|
|
3672
|
+
}
|
|
3660
3673
|
usage.output_tokens = value.usage.output_tokens;
|
|
3661
3674
|
finishReason = {
|
|
3662
3675
|
unified: mapAnthropicStopReason({
|