@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 02d9b68: fix `input_tokens` compatibility
|
|
8
|
+
|
|
9
|
+
## 3.0.9
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- de2399b: fix(anthropic): assign type urls in file parts correctly
|
|
14
|
+
|
|
3
15
|
## 3.0.8
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
32
32
|
var import_provider_utils22 = require("@ai-sdk/provider-utils");
|
|
33
33
|
|
|
34
34
|
// src/version.ts
|
|
35
|
-
var VERSION = true ? "3.0.
|
|
35
|
+
var VERSION = true ? "3.0.10" : "0.0.0-test";
|
|
36
36
|
|
|
37
37
|
// src/anthropic-messages-language-model.ts
|
|
38
38
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -686,6 +686,7 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
686
686
|
}).nullish()
|
|
687
687
|
}),
|
|
688
688
|
usage: import_v42.z.looseObject({
|
|
689
|
+
input_tokens: import_v42.z.number().nullish(),
|
|
689
690
|
output_tokens: import_v42.z.number(),
|
|
690
691
|
cache_creation_input_tokens: import_v42.z.number().nullish()
|
|
691
692
|
})
|
|
@@ -1549,6 +1550,15 @@ function convertToString(data) {
|
|
|
1549
1550
|
functionality: `unsupported data type for text documents: ${typeof data}`
|
|
1550
1551
|
});
|
|
1551
1552
|
}
|
|
1553
|
+
function isUrlData(data) {
|
|
1554
|
+
return data instanceof URL || isUrlString(data);
|
|
1555
|
+
}
|
|
1556
|
+
function isUrlString(data) {
|
|
1557
|
+
return typeof data === "string" && /^https?:\/\//i.test(data);
|
|
1558
|
+
}
|
|
1559
|
+
function getUrlString(data) {
|
|
1560
|
+
return data instanceof URL ? data.toString() : data;
|
|
1561
|
+
}
|
|
1552
1562
|
async function convertToAnthropicMessagesPrompt({
|
|
1553
1563
|
prompt,
|
|
1554
1564
|
sendReasoning,
|
|
@@ -1632,9 +1642,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1632
1642
|
if (part.mediaType.startsWith("image/")) {
|
|
1633
1643
|
anthropicContent.push({
|
|
1634
1644
|
type: "image",
|
|
1635
|
-
source: part.data
|
|
1645
|
+
source: isUrlData(part.data) ? {
|
|
1636
1646
|
type: "url",
|
|
1637
|
-
url: part.data
|
|
1647
|
+
url: getUrlString(part.data)
|
|
1638
1648
|
} : {
|
|
1639
1649
|
type: "base64",
|
|
1640
1650
|
media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
|
|
@@ -1652,9 +1662,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1652
1662
|
);
|
|
1653
1663
|
anthropicContent.push({
|
|
1654
1664
|
type: "document",
|
|
1655
|
-
source: part.data
|
|
1665
|
+
source: isUrlData(part.data) ? {
|
|
1656
1666
|
type: "url",
|
|
1657
|
-
url: part.data
|
|
1667
|
+
url: getUrlString(part.data)
|
|
1658
1668
|
} : {
|
|
1659
1669
|
type: "base64",
|
|
1660
1670
|
media_type: "application/pdf",
|
|
@@ -1676,9 +1686,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1676
1686
|
);
|
|
1677
1687
|
anthropicContent.push({
|
|
1678
1688
|
type: "document",
|
|
1679
|
-
source: part.data
|
|
1689
|
+
source: isUrlData(part.data) ? {
|
|
1680
1690
|
type: "url",
|
|
1681
|
-
url: part.data
|
|
1691
|
+
url: getUrlString(part.data)
|
|
1682
1692
|
} : {
|
|
1683
1693
|
type: "text",
|
|
1684
1694
|
media_type: "text/plain",
|
|
@@ -3665,6 +3675,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3665
3675
|
return;
|
|
3666
3676
|
}
|
|
3667
3677
|
case "message_delta": {
|
|
3678
|
+
if (value.usage.input_tokens != null && usage.input_tokens !== value.usage.input_tokens) {
|
|
3679
|
+
usage.input_tokens = value.usage.input_tokens;
|
|
3680
|
+
}
|
|
3668
3681
|
usage.output_tokens = value.usage.output_tokens;
|
|
3669
3682
|
finishReason = {
|
|
3670
3683
|
unified: mapAnthropicStopReason({
|