ai 6.0.178 → 6.0.182
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 +30 -0
- package/README.md +1 -1
- package/dist/index.js +82 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -20
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +86 -18
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +86 -18
- package/dist/internal/index.mjs.map +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/src/util/retry-with-exponential-backoff.ts +10 -5
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.182" : "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
|
}
|
|
@@ -2560,12 +2618,13 @@ function mergeObjects(base, overrides) {
|
|
|
2560
2618
|
|
|
2561
2619
|
// src/util/retry-with-exponential-backoff.ts
|
|
2562
2620
|
import { APICallError as APICallError2 } from "@ai-sdk/provider";
|
|
2621
|
+
import { GatewayError } from "@ai-sdk/gateway";
|
|
2563
2622
|
import { delay, getErrorMessage as getErrorMessage4, isAbortError } from "@ai-sdk/provider-utils";
|
|
2564
2623
|
function getRetryDelayInMs({
|
|
2565
2624
|
error,
|
|
2566
2625
|
exponentialBackoffDelay
|
|
2567
2626
|
}) {
|
|
2568
|
-
const headers = error.responseHeaders;
|
|
2627
|
+
const headers = APICallError2.isInstance(error) ? error.responseHeaders : APICallError2.isInstance(error.cause) ? error.cause.responseHeaders : void 0;
|
|
2569
2628
|
if (!headers)
|
|
2570
2629
|
return exponentialBackoffDelay;
|
|
2571
2630
|
let ms;
|
|
@@ -2626,7 +2685,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
|
2626
2685
|
errors: newErrors
|
|
2627
2686
|
});
|
|
2628
2687
|
}
|
|
2629
|
-
if (error instanceof Error && APICallError2.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
|
2688
|
+
if (error instanceof Error && (APICallError2.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true) && tryNumber <= maxRetries) {
|
|
2630
2689
|
await delay(
|
|
2631
2690
|
getRetryDelayInMs({
|
|
2632
2691
|
error,
|
|
@@ -8766,7 +8825,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
8766
8825
|
toolCallId: z8.string(),
|
|
8767
8826
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
8768
8827
|
state: z8.literal("output-error"),
|
|
8769
|
-
input: z8.unknown(),
|
|
8828
|
+
input: z8.unknown().optional(),
|
|
8770
8829
|
rawInput: z8.unknown().optional(),
|
|
8771
8830
|
providerExecuted: z8.boolean().optional(),
|
|
8772
8831
|
output: z8.never().optional(),
|
|
@@ -8876,7 +8935,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
8876
8935
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
8877
8936
|
state: z8.literal("output-error"),
|
|
8878
8937
|
providerExecuted: z8.boolean().optional(),
|
|
8879
|
-
input: z8.unknown(),
|
|
8938
|
+
input: z8.unknown().optional(),
|
|
8880
8939
|
rawInput: z8.unknown().optional(),
|
|
8881
8940
|
output: z8.never().optional(),
|
|
8882
8941
|
errorText: z8.string(),
|