ai 6.0.180 → 6.0.183
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 +21 -0
- package/dist/index.js +76 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +76 -18
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +83 -16
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +83 -16
- package/dist/internal/index.mjs.map +1 -1
- package/docs/07-reference/02-ai-sdk-ui/02-use-completion.mdx +1 -1
- package/package.json +2 -2
- package/src/prompt/convert-to-language-model-prompt.ts +101 -27
- package/src/ui/validate-ui-messages.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.183
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [363cefe]
|
|
8
|
+
- @ai-sdk/gateway@3.0.115
|
|
9
|
+
|
|
10
|
+
## 6.0.182
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- e76a29a: fix(ai): download tool-result file URLs
|
|
15
|
+
|
|
16
|
+
## 6.0.181
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 538974a: fix(ui): make `input` optional on `output-error` tool and dynamic-tool UI message parts
|
|
21
|
+
|
|
22
|
+
`validateUIMessages` rejected persisted assistant messages whose `output-error` tool parts had no `input` key. This happened for any errored tool call where the SDK set `input: undefined` (e.g. `NoSuchToolError` / `InvalidToolInputError`): JSON serialization stripped the `undefined` value, and Zod 4.4+ treats a missing `z.unknown()` key as a validation failure (previously it was implicitly optional). The schema now matches the runtime shape produced by `process-ui-message-stream`, so reloading a thread that contains an errored tool call no longer throws `AI_TypeValidationError`.
|
|
23
|
+
|
|
3
24
|
## 6.0.180
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1254,7 +1254,7 @@ function detectMediaType({
|
|
|
1254
1254
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
1255
1255
|
|
|
1256
1256
|
// src/version.ts
|
|
1257
|
-
var VERSION = true ? "6.0.
|
|
1257
|
+
var VERSION = true ? "6.0.183" : "0.0.0-test";
|
|
1258
1258
|
|
|
1259
1259
|
// src/util/download/download.ts
|
|
1260
1260
|
var download = async ({
|
|
@@ -1592,7 +1592,10 @@ function convertToLanguageModelMessage({
|
|
|
1592
1592
|
type: "tool-result",
|
|
1593
1593
|
toolCallId: part.toolCallId,
|
|
1594
1594
|
toolName: part.toolName,
|
|
1595
|
-
output: mapToolResultOutput(
|
|
1595
|
+
output: mapToolResultOutput({
|
|
1596
|
+
output: part.output,
|
|
1597
|
+
downloadedAssets
|
|
1598
|
+
}),
|
|
1596
1599
|
providerOptions
|
|
1597
1600
|
};
|
|
1598
1601
|
}
|
|
@@ -1614,7 +1617,10 @@ function convertToLanguageModelMessage({
|
|
|
1614
1617
|
type: "tool-result",
|
|
1615
1618
|
toolCallId: part.toolCallId,
|
|
1616
1619
|
toolName: part.toolName,
|
|
1617
|
-
output: mapToolResultOutput(
|
|
1620
|
+
output: mapToolResultOutput({
|
|
1621
|
+
output: part.output,
|
|
1622
|
+
downloadedAssets
|
|
1623
|
+
}),
|
|
1618
1624
|
providerOptions: part.providerOptions
|
|
1619
1625
|
};
|
|
1620
1626
|
}
|
|
@@ -1638,20 +1644,44 @@ function convertToLanguageModelMessage({
|
|
|
1638
1644
|
}
|
|
1639
1645
|
}
|
|
1640
1646
|
async function downloadAssets(messages, download2, supportedUrls) {
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
(
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
} catch (ignored) {
|
|
1647
|
+
var _a21;
|
|
1648
|
+
const downloadableFiles = [];
|
|
1649
|
+
for (const message of messages) {
|
|
1650
|
+
if (message.role === "user" && Array.isArray(message.content)) {
|
|
1651
|
+
for (const part of message.content) {
|
|
1652
|
+
if (part.type === "image" || part.type === "file") {
|
|
1653
|
+
downloadableFiles.push({
|
|
1654
|
+
data: part.type === "image" ? part.image : part.data,
|
|
1655
|
+
mediaType: (_a21 = part.mediaType) != null ? _a21 : part.type === "image" ? "image/*" : void 0
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1653
1658
|
}
|
|
1654
1659
|
}
|
|
1660
|
+
if (message.role === "tool" || message.role === "assistant") {
|
|
1661
|
+
if (!Array.isArray(message.content)) {
|
|
1662
|
+
continue;
|
|
1663
|
+
}
|
|
1664
|
+
for (const part of message.content) {
|
|
1665
|
+
if (part.type !== "tool-result") {
|
|
1666
|
+
continue;
|
|
1667
|
+
}
|
|
1668
|
+
if (part.output.type !== "content") {
|
|
1669
|
+
continue;
|
|
1670
|
+
}
|
|
1671
|
+
for (const contentPart of part.output.value) {
|
|
1672
|
+
if (contentPart.type === "image-url" || contentPart.type === "file-url") {
|
|
1673
|
+
downloadableFiles.push({
|
|
1674
|
+
data: new URL(contentPart.url),
|
|
1675
|
+
mediaType: contentPart.type === "image-url" ? "image/*" : void 0
|
|
1676
|
+
});
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
const plannedDownloads = downloadableFiles.map((part) => {
|
|
1683
|
+
const mediaType = part.mediaType;
|
|
1684
|
+
const { data } = convertToLanguageModelV3DataContent(part.data);
|
|
1655
1685
|
return { mediaType, data };
|
|
1656
1686
|
}).filter(
|
|
1657
1687
|
(part) => part.data instanceof URL
|
|
@@ -1732,13 +1762,41 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
1732
1762
|
}
|
|
1733
1763
|
}
|
|
1734
1764
|
}
|
|
1735
|
-
function mapToolResultOutput(
|
|
1765
|
+
function mapToolResultOutput({
|
|
1766
|
+
output,
|
|
1767
|
+
downloadedAssets
|
|
1768
|
+
}) {
|
|
1736
1769
|
if (output.type !== "content") {
|
|
1737
1770
|
return output;
|
|
1738
1771
|
}
|
|
1739
1772
|
return {
|
|
1740
1773
|
type: "content",
|
|
1741
1774
|
value: output.value.map((item) => {
|
|
1775
|
+
var _a21, _b;
|
|
1776
|
+
if (item.type === "image-url") {
|
|
1777
|
+
const downloadedFile = downloadedAssets[new URL(item.url).toString()];
|
|
1778
|
+
if (downloadedFile) {
|
|
1779
|
+
return {
|
|
1780
|
+
type: "image-data",
|
|
1781
|
+
data: convertDataContentToBase64String(downloadedFile.data),
|
|
1782
|
+
mediaType: (_a21 = downloadedFile.mediaType) != null ? _a21 : "image/*",
|
|
1783
|
+
providerOptions: item.providerOptions
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1786
|
+
return item;
|
|
1787
|
+
}
|
|
1788
|
+
if (item.type === "file-url") {
|
|
1789
|
+
const downloadedFile = downloadedAssets[new URL(item.url).toString()];
|
|
1790
|
+
if (downloadedFile) {
|
|
1791
|
+
return {
|
|
1792
|
+
type: "file-data",
|
|
1793
|
+
data: convertDataContentToBase64String(downloadedFile.data),
|
|
1794
|
+
mediaType: (_b = downloadedFile.mediaType) != null ? _b : "application/octet-stream",
|
|
1795
|
+
providerOptions: item.providerOptions
|
|
1796
|
+
};
|
|
1797
|
+
}
|
|
1798
|
+
return item;
|
|
1799
|
+
}
|
|
1742
1800
|
if (item.type !== "media") {
|
|
1743
1801
|
return item;
|
|
1744
1802
|
}
|
|
@@ -8835,7 +8893,7 @@ var uiMessagesSchema = (0, import_provider_utils22.lazySchema)(
|
|
|
8835
8893
|
toolCallId: import_v48.z.string(),
|
|
8836
8894
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
8837
8895
|
state: import_v48.z.literal("output-error"),
|
|
8838
|
-
input: import_v48.z.unknown(),
|
|
8896
|
+
input: import_v48.z.unknown().optional(),
|
|
8839
8897
|
rawInput: import_v48.z.unknown().optional(),
|
|
8840
8898
|
providerExecuted: import_v48.z.boolean().optional(),
|
|
8841
8899
|
output: import_v48.z.never().optional(),
|
|
@@ -8945,7 +9003,7 @@ var uiMessagesSchema = (0, import_provider_utils22.lazySchema)(
|
|
|
8945
9003
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
8946
9004
|
state: import_v48.z.literal("output-error"),
|
|
8947
9005
|
providerExecuted: import_v48.z.boolean().optional(),
|
|
8948
|
-
input: import_v48.z.unknown(),
|
|
9006
|
+
input: import_v48.z.unknown().optional(),
|
|
8949
9007
|
rawInput: import_v48.z.unknown().optional(),
|
|
8950
9008
|
output: import_v48.z.never().optional(),
|
|
8951
9009
|
errorText: import_v48.z.string(),
|