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/dist/index.mjs
CHANGED
|
@@ -1144,7 +1144,7 @@ import {
|
|
|
1144
1144
|
} from "@ai-sdk/provider-utils";
|
|
1145
1145
|
|
|
1146
1146
|
// src/version.ts
|
|
1147
|
-
var VERSION = true ? "6.0.
|
|
1147
|
+
var VERSION = true ? "6.0.183" : "0.0.0-test";
|
|
1148
1148
|
|
|
1149
1149
|
// src/util/download/download.ts
|
|
1150
1150
|
var download = async ({
|
|
@@ -1485,7 +1485,10 @@ function convertToLanguageModelMessage({
|
|
|
1485
1485
|
type: "tool-result",
|
|
1486
1486
|
toolCallId: part.toolCallId,
|
|
1487
1487
|
toolName: part.toolName,
|
|
1488
|
-
output: mapToolResultOutput(
|
|
1488
|
+
output: mapToolResultOutput({
|
|
1489
|
+
output: part.output,
|
|
1490
|
+
downloadedAssets
|
|
1491
|
+
}),
|
|
1489
1492
|
providerOptions
|
|
1490
1493
|
};
|
|
1491
1494
|
}
|
|
@@ -1507,7 +1510,10 @@ function convertToLanguageModelMessage({
|
|
|
1507
1510
|
type: "tool-result",
|
|
1508
1511
|
toolCallId: part.toolCallId,
|
|
1509
1512
|
toolName: part.toolName,
|
|
1510
|
-
output: mapToolResultOutput(
|
|
1513
|
+
output: mapToolResultOutput({
|
|
1514
|
+
output: part.output,
|
|
1515
|
+
downloadedAssets
|
|
1516
|
+
}),
|
|
1511
1517
|
providerOptions: part.providerOptions
|
|
1512
1518
|
};
|
|
1513
1519
|
}
|
|
@@ -1531,20 +1537,44 @@ function convertToLanguageModelMessage({
|
|
|
1531
1537
|
}
|
|
1532
1538
|
}
|
|
1533
1539
|
async function downloadAssets(messages, download2, supportedUrls) {
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
(
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
} catch (ignored) {
|
|
1540
|
+
var _a21;
|
|
1541
|
+
const downloadableFiles = [];
|
|
1542
|
+
for (const message of messages) {
|
|
1543
|
+
if (message.role === "user" && Array.isArray(message.content)) {
|
|
1544
|
+
for (const part of message.content) {
|
|
1545
|
+
if (part.type === "image" || part.type === "file") {
|
|
1546
|
+
downloadableFiles.push({
|
|
1547
|
+
data: part.type === "image" ? part.image : part.data,
|
|
1548
|
+
mediaType: (_a21 = part.mediaType) != null ? _a21 : part.type === "image" ? "image/*" : void 0
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1546
1551
|
}
|
|
1547
1552
|
}
|
|
1553
|
+
if (message.role === "tool" || message.role === "assistant") {
|
|
1554
|
+
if (!Array.isArray(message.content)) {
|
|
1555
|
+
continue;
|
|
1556
|
+
}
|
|
1557
|
+
for (const part of message.content) {
|
|
1558
|
+
if (part.type !== "tool-result") {
|
|
1559
|
+
continue;
|
|
1560
|
+
}
|
|
1561
|
+
if (part.output.type !== "content") {
|
|
1562
|
+
continue;
|
|
1563
|
+
}
|
|
1564
|
+
for (const contentPart of part.output.value) {
|
|
1565
|
+
if (contentPart.type === "image-url" || contentPart.type === "file-url") {
|
|
1566
|
+
downloadableFiles.push({
|
|
1567
|
+
data: new URL(contentPart.url),
|
|
1568
|
+
mediaType: contentPart.type === "image-url" ? "image/*" : void 0
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
const plannedDownloads = downloadableFiles.map((part) => {
|
|
1576
|
+
const mediaType = part.mediaType;
|
|
1577
|
+
const { data } = convertToLanguageModelV3DataContent(part.data);
|
|
1548
1578
|
return { mediaType, data };
|
|
1549
1579
|
}).filter(
|
|
1550
1580
|
(part) => part.data instanceof URL
|
|
@@ -1625,13 +1655,41 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
|
1625
1655
|
}
|
|
1626
1656
|
}
|
|
1627
1657
|
}
|
|
1628
|
-
function mapToolResultOutput(
|
|
1658
|
+
function mapToolResultOutput({
|
|
1659
|
+
output,
|
|
1660
|
+
downloadedAssets
|
|
1661
|
+
}) {
|
|
1629
1662
|
if (output.type !== "content") {
|
|
1630
1663
|
return output;
|
|
1631
1664
|
}
|
|
1632
1665
|
return {
|
|
1633
1666
|
type: "content",
|
|
1634
1667
|
value: output.value.map((item) => {
|
|
1668
|
+
var _a21, _b;
|
|
1669
|
+
if (item.type === "image-url") {
|
|
1670
|
+
const downloadedFile = downloadedAssets[new URL(item.url).toString()];
|
|
1671
|
+
if (downloadedFile) {
|
|
1672
|
+
return {
|
|
1673
|
+
type: "image-data",
|
|
1674
|
+
data: convertDataContentToBase64String(downloadedFile.data),
|
|
1675
|
+
mediaType: (_a21 = downloadedFile.mediaType) != null ? _a21 : "image/*",
|
|
1676
|
+
providerOptions: item.providerOptions
|
|
1677
|
+
};
|
|
1678
|
+
}
|
|
1679
|
+
return item;
|
|
1680
|
+
}
|
|
1681
|
+
if (item.type === "file-url") {
|
|
1682
|
+
const downloadedFile = downloadedAssets[new URL(item.url).toString()];
|
|
1683
|
+
if (downloadedFile) {
|
|
1684
|
+
return {
|
|
1685
|
+
type: "file-data",
|
|
1686
|
+
data: convertDataContentToBase64String(downloadedFile.data),
|
|
1687
|
+
mediaType: (_b = downloadedFile.mediaType) != null ? _b : "application/octet-stream",
|
|
1688
|
+
providerOptions: item.providerOptions
|
|
1689
|
+
};
|
|
1690
|
+
}
|
|
1691
|
+
return item;
|
|
1692
|
+
}
|
|
1635
1693
|
if (item.type !== "media") {
|
|
1636
1694
|
return item;
|
|
1637
1695
|
}
|
|
@@ -8767,7 +8825,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
8767
8825
|
toolCallId: z8.string(),
|
|
8768
8826
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
8769
8827
|
state: z8.literal("output-error"),
|
|
8770
|
-
input: z8.unknown(),
|
|
8828
|
+
input: z8.unknown().optional(),
|
|
8771
8829
|
rawInput: z8.unknown().optional(),
|
|
8772
8830
|
providerExecuted: z8.boolean().optional(),
|
|
8773
8831
|
output: z8.never().optional(),
|
|
@@ -8877,7 +8935,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
8877
8935
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
8878
8936
|
state: z8.literal("output-error"),
|
|
8879
8937
|
providerExecuted: z8.boolean().optional(),
|
|
8880
|
-
input: z8.unknown(),
|
|
8938
|
+
input: z8.unknown().optional(),
|
|
8881
8939
|
rawInput: z8.unknown().optional(),
|
|
8882
8940
|
output: z8.never().optional(),
|
|
8883
8941
|
errorText: z8.string(),
|