@ai-sdk/anthropic 3.0.8 → 3.0.9
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 +6 -0
- package/dist/index.js +16 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -7
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +15 -6
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +15 -6
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/internal/index.js
CHANGED
|
@@ -1541,6 +1541,15 @@ function convertToString(data) {
|
|
|
1541
1541
|
functionality: `unsupported data type for text documents: ${typeof data}`
|
|
1542
1542
|
});
|
|
1543
1543
|
}
|
|
1544
|
+
function isUrlData(data) {
|
|
1545
|
+
return data instanceof URL || isUrlString(data);
|
|
1546
|
+
}
|
|
1547
|
+
function isUrlString(data) {
|
|
1548
|
+
return typeof data === "string" && /^https?:\/\//i.test(data);
|
|
1549
|
+
}
|
|
1550
|
+
function getUrlString(data) {
|
|
1551
|
+
return data instanceof URL ? data.toString() : data;
|
|
1552
|
+
}
|
|
1544
1553
|
async function convertToAnthropicMessagesPrompt({
|
|
1545
1554
|
prompt,
|
|
1546
1555
|
sendReasoning,
|
|
@@ -1624,9 +1633,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1624
1633
|
if (part.mediaType.startsWith("image/")) {
|
|
1625
1634
|
anthropicContent.push({
|
|
1626
1635
|
type: "image",
|
|
1627
|
-
source: part.data
|
|
1636
|
+
source: isUrlData(part.data) ? {
|
|
1628
1637
|
type: "url",
|
|
1629
|
-
url: part.data
|
|
1638
|
+
url: getUrlString(part.data)
|
|
1630
1639
|
} : {
|
|
1631
1640
|
type: "base64",
|
|
1632
1641
|
media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
|
|
@@ -1644,9 +1653,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1644
1653
|
);
|
|
1645
1654
|
anthropicContent.push({
|
|
1646
1655
|
type: "document",
|
|
1647
|
-
source: part.data
|
|
1656
|
+
source: isUrlData(part.data) ? {
|
|
1648
1657
|
type: "url",
|
|
1649
|
-
url: part.data
|
|
1658
|
+
url: getUrlString(part.data)
|
|
1650
1659
|
} : {
|
|
1651
1660
|
type: "base64",
|
|
1652
1661
|
media_type: "application/pdf",
|
|
@@ -1668,9 +1677,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1668
1677
|
);
|
|
1669
1678
|
anthropicContent.push({
|
|
1670
1679
|
type: "document",
|
|
1671
|
-
source: part.data
|
|
1680
|
+
source: isUrlData(part.data) ? {
|
|
1672
1681
|
type: "url",
|
|
1673
|
-
url: part.data
|
|
1682
|
+
url: getUrlString(part.data)
|
|
1674
1683
|
} : {
|
|
1675
1684
|
type: "text",
|
|
1676
1685
|
media_type: "text/plain",
|