langgraph-ui-components 0.0.10 → 0.0.11-testing
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/dist/index.es.js +3 -2
- package/dist/index.es10.js +25 -6
- package/dist/index.es10.js.map +1 -1
- package/dist/index.es100.js +131 -64
- package/dist/index.es100.js.map +1 -1
- package/dist/index.es101.js +65 -32
- package/dist/index.es101.js.map +1 -1
- package/dist/index.es102.js +34 -34
- package/dist/index.es102.js.map +1 -1
- package/dist/index.es103.js +35 -164
- package/dist/index.es103.js.map +1 -1
- package/dist/index.es104.js +156 -193
- package/dist/index.es104.js.map +1 -1
- package/dist/index.es105.js +202 -13
- package/dist/index.es105.js.map +1 -1
- package/dist/index.es106.js +13 -29
- package/dist/index.es106.js.map +1 -1
- package/dist/index.es107.js +25 -29
- package/dist/index.es107.js.map +1 -1
- package/dist/index.es108.js +24 -3147
- package/dist/index.es108.js.map +1 -1
- package/dist/index.es109.js +3151 -31
- package/dist/index.es109.js.map +1 -1
- package/dist/index.es110.js +21 -5
- package/dist/index.es110.js.map +1 -1
- package/dist/index.es111.js +64 -69
- package/dist/index.es111.js.map +1 -1
- package/dist/index.es112.js +3 -37
- package/dist/index.es112.js.map +1 -1
- package/dist/index.es113.js +16 -5
- package/dist/index.es113.js.map +1 -1
- package/dist/index.es114.js +7 -2
- package/dist/index.es114.js.map +1 -1
- package/dist/index.es115.js +2 -13
- package/dist/index.es115.js.map +1 -1
- package/dist/index.es116.js +9 -499
- package/dist/index.es116.js.map +1 -1
- package/dist/index.es117.js +501 -5
- package/dist/index.es117.js.map +1 -1
- package/dist/index.es118.js +7 -2
- package/dist/index.es118.js.map +1 -1
- package/dist/index.es119.js +2 -148
- package/dist/index.es119.js.map +1 -1
- package/dist/index.es120.js +118 -878
- package/dist/index.es120.js.map +1 -1
- package/dist/index.es121.js +877 -251
- package/dist/index.es121.js.map +1 -1
- package/dist/index.es122.js +281 -3
- package/dist/index.es122.js.map +1 -1
- package/dist/index.es123.js +3 -445
- package/dist/index.es123.js.map +1 -1
- package/dist/index.es124.js +437 -39
- package/dist/index.es124.js.map +1 -1
- package/dist/index.es125.js +46 -22
- package/dist/index.es125.js.map +1 -1
- package/dist/index.es126.js +21 -78
- package/dist/index.es126.js.map +1 -1
- package/dist/index.es127.js +76 -126
- package/dist/index.es127.js.map +1 -1
- package/dist/index.es128.js +125 -45
- package/dist/index.es128.js.map +1 -1
- package/dist/index.es129.js +48 -9
- package/dist/index.es129.js.map +1 -1
- package/dist/index.es130.js +10 -45
- package/dist/index.es130.js.map +1 -1
- package/dist/index.es131.js +43 -97
- package/dist/index.es131.js.map +1 -1
- package/dist/index.es132.js +94 -48
- package/dist/index.es132.js.map +1 -1
- package/dist/index.es133.js +51 -14
- package/dist/index.es133.js.map +1 -1
- package/dist/index.es134.js +1 -1
- package/dist/index.es135.js +1 -1
- package/dist/index.es138.js +1 -1
- package/dist/index.es139.js +1 -1
- package/dist/index.es140.js +1 -1
- package/dist/index.es141.js +1 -1
- package/dist/index.es142.js +1 -1
- package/dist/index.es143.js +1 -1
- package/dist/index.es144.js +1 -1
- package/dist/index.es145.js +1 -1
- package/dist/index.es146.js +1 -1
- package/dist/index.es147.js +1 -1
- package/dist/index.es148.js +1 -1
- package/dist/index.es149.js +1 -1
- package/dist/index.es150.js +1 -1
- package/dist/index.es151.js +1 -1
- package/dist/index.es152.js +1 -1
- package/dist/index.es153.js +1 -1
- package/dist/index.es154.js +1 -1
- package/dist/index.es155.js +1 -1
- package/dist/index.es156.js +1 -1
- package/dist/index.es157.js +1 -1
- package/dist/index.es158.js +1 -1
- package/dist/index.es159.js +1 -1
- package/dist/index.es16.js +3 -3
- package/dist/index.es16.js.map +1 -1
- package/dist/index.es160.js +1 -1
- package/dist/index.es161.js +1 -1
- package/dist/index.es162.js +1 -1
- package/dist/index.es163.js +1 -1
- package/dist/index.es164.js +1 -1
- package/dist/index.es165.js +1 -1
- package/dist/index.es166.js +1 -1
- package/dist/index.es167.js +1 -1
- package/dist/index.es168.js +1 -1
- package/dist/index.es169.js +1 -1
- package/dist/index.es170.js +1 -1
- package/dist/index.es171.js +1 -1
- package/dist/index.es172.js +1 -1
- package/dist/index.es173.js +1 -1
- package/dist/index.es174.js +1 -1
- package/dist/index.es175.js +1 -1
- package/dist/index.es176.js +1 -1
- package/dist/index.es177.js +1 -1
- package/dist/index.es178.js +1 -1
- package/dist/index.es179.js +1 -1
- package/dist/index.es18.js +15 -15
- package/dist/index.es180.js +1 -1
- package/dist/index.es181.js +1 -1
- package/dist/index.es182.js +1 -1
- package/dist/index.es183.js +162 -13
- package/dist/index.es183.js.map +1 -1
- package/dist/index.es184.js +2 -89
- package/dist/index.es184.js.map +1 -1
- package/dist/index.es185.js +15 -2
- package/dist/index.es185.js.map +1 -1
- package/dist/index.es186.js +89 -2
- package/dist/index.es186.js.map +1 -1
- package/dist/index.es187.js +2 -2
- package/dist/index.es188.js +56 -2
- package/dist/index.es188.js.map +1 -1
- package/dist/index.es189.js +100 -2
- package/dist/index.es189.js.map +1 -1
- package/dist/index.es190.js +191 -2
- package/dist/index.es190.js.map +1 -1
- package/dist/index.es191.js +110 -2
- package/dist/index.es191.js.map +1 -1
- package/dist/index.es192.js +35 -2
- package/dist/index.es192.js.map +1 -1
- package/dist/index.es193.js +10 -2
- package/dist/index.es193.js.map +1 -1
- package/dist/index.es194.js +11 -2
- package/dist/index.es194.js.map +1 -1
- package/dist/index.es195.js +12 -2
- package/dist/index.es195.js.map +1 -1
- package/dist/index.es196.js +91 -2
- package/dist/index.es196.js.map +1 -1
- package/dist/index.es197.js +275 -2
- package/dist/index.es197.js.map +1 -1
- package/dist/index.es198.js +2 -2
- package/dist/index.es199.js +164 -2
- package/dist/index.es199.js.map +1 -1
- package/dist/index.es200.js +51 -2
- package/dist/index.es200.js.map +1 -1
- package/dist/index.es201.js +40 -2
- package/dist/index.es201.js.map +1 -1
- package/dist/index.es202.js +35 -2
- package/dist/index.es202.js.map +1 -1
- package/dist/index.es203.js +40 -2
- package/dist/index.es203.js.map +1 -1
- package/dist/index.es204.js +24 -2
- package/dist/index.es204.js.map +1 -1
- package/dist/index.es205.js +591 -2
- package/dist/index.es205.js.map +1 -1
- package/dist/index.es206.js +125 -2
- package/dist/index.es206.js.map +1 -1
- package/dist/index.es207.js +2 -2
- package/dist/index.es208.js +2 -2
- package/dist/index.es209.js +2 -2
- package/dist/index.es210.js +2 -2
- package/dist/index.es211.js +2 -2
- package/dist/index.es212.js +2 -2
- package/dist/index.es213.js +2 -2
- package/dist/index.es214.js +2 -2
- package/dist/index.es215.js +2 -2
- package/dist/index.es216.js +2 -2
- package/dist/index.es217.js +2 -2
- package/dist/index.es218.js +2 -2
- package/dist/index.es219.js +2 -2
- package/dist/index.es220.js +2 -2
- package/dist/index.es221.js +2 -2
- package/dist/index.es222.js +2 -2
- package/dist/index.es223.js +2 -2
- package/dist/index.es224.js +2 -2
- package/dist/index.es225.js +2 -2
- package/dist/index.es226.js +2 -2
- package/dist/index.es227.js +2 -2
- package/dist/index.es228.js +2 -2
- package/dist/index.es229.js +2 -2
- package/dist/index.es230.js +2 -2
- package/dist/index.es231.js +2 -56
- package/dist/index.es231.js.map +1 -1
- package/dist/index.es232.js +2 -100
- package/dist/index.es232.js.map +1 -1
- package/dist/index.es233.js +2 -191
- package/dist/index.es233.js.map +1 -1
- package/dist/index.es234.js +2 -110
- package/dist/index.es234.js.map +1 -1
- package/dist/index.es235.js +2 -35
- package/dist/index.es235.js.map +1 -1
- package/dist/index.es236.js +2 -10
- package/dist/index.es236.js.map +1 -1
- package/dist/index.es237.js +2 -11
- package/dist/index.es237.js.map +1 -1
- package/dist/index.es238.js +2 -12
- package/dist/index.es238.js.map +1 -1
- package/dist/index.es239.js +2 -91
- package/dist/index.es239.js.map +1 -1
- package/dist/index.es24.js +1 -1
- package/dist/index.es240.js +2 -275
- package/dist/index.es240.js.map +1 -1
- package/dist/index.es241.js +2 -2
- package/dist/index.es242.js +2 -164
- package/dist/index.es242.js.map +1 -1
- package/dist/index.es243.js +2 -51
- package/dist/index.es243.js.map +1 -1
- package/dist/index.es244.js +2 -40
- package/dist/index.es244.js.map +1 -1
- package/dist/index.es245.js +2 -35
- package/dist/index.es245.js.map +1 -1
- package/dist/index.es246.js +2 -40
- package/dist/index.es246.js.map +1 -1
- package/dist/index.es247.js +2 -24
- package/dist/index.es247.js.map +1 -1
- package/dist/index.es248.js +2 -591
- package/dist/index.es248.js.map +1 -1
- package/dist/index.es249.js +2 -125
- package/dist/index.es249.js.map +1 -1
- package/dist/index.es25.js +3 -1
- package/dist/index.es25.js.map +1 -1
- package/dist/index.es250.js +2 -164
- package/dist/index.es250.js.map +1 -1
- package/dist/index.es251.js +2 -2
- package/dist/index.es252.js +2 -2
- package/dist/index.es253.js +1 -1
- package/dist/index.es258.js +1 -1
- package/dist/index.es260.js +2 -2
- package/dist/index.es262.js +2 -2
- package/dist/index.es265.js +1 -1
- package/dist/index.es267.js +1 -1
- package/dist/index.es277.js +2 -147
- package/dist/index.es277.js.map +1 -1
- package/dist/index.es278.js +126 -167
- package/dist/index.es278.js.map +1 -1
- package/dist/index.es279.js +188 -2
- package/dist/index.es279.js.map +1 -1
- package/dist/index.es280.js +1 -1
- package/dist/index.es283.js +1 -1
- package/dist/index.es288.js +1 -1
- package/dist/index.es29.js +1 -1
- package/dist/index.es3.js +24 -9
- package/dist/index.es3.js.map +1 -1
- package/dist/index.es300.js +1 -1
- package/dist/index.es302.js +1 -1
- package/dist/index.es31.js +7 -7
- package/dist/index.es314.js +1 -1
- package/dist/index.es32.js +1 -1
- package/dist/index.es334.js +2 -2
- package/dist/index.es35.js +4 -4
- package/dist/index.es36.js +1185 -111
- package/dist/index.es36.js.map +1 -1
- package/dist/index.es37.js +7 -71
- package/dist/index.es37.js.map +1 -1
- package/dist/index.es38.js +9 -18
- package/dist/index.es38.js.map +1 -1
- package/dist/index.es39.js +136 -250
- package/dist/index.es39.js.map +1 -1
- package/dist/index.es4.js +2 -1
- package/dist/index.es4.js.map +1 -1
- package/dist/index.es40.js +116 -41
- package/dist/index.es40.js.map +1 -1
- package/dist/index.es41.js +64 -208
- package/dist/index.es41.js.map +1 -1
- package/dist/index.es42.js +17 -66
- package/dist/index.es42.js.map +1 -1
- package/dist/index.es43.js +236 -117
- package/dist/index.es43.js.map +1 -1
- package/dist/index.es44.js +38 -19
- package/dist/index.es44.js.map +1 -1
- package/dist/index.es45.js +202 -217
- package/dist/index.es45.js.map +1 -1
- package/dist/index.es46.js +65 -7
- package/dist/index.es46.js.map +1 -1
- package/dist/index.es47.js +131 -1181
- package/dist/index.es47.js.map +1 -1
- package/dist/index.es48.js +25 -8
- package/dist/index.es48.js.map +1 -1
- package/dist/index.es49.js +218 -135
- package/dist/index.es49.js.map +1 -1
- package/dist/index.es5.js.map +1 -1
- package/dist/index.es50.js +5 -208
- package/dist/index.es50.js.map +1 -1
- package/dist/index.es51.js +208 -5
- package/dist/index.es51.js.map +1 -1
- package/dist/index.es52.js +90 -7
- package/dist/index.es52.js.map +1 -1
- package/dist/index.es53.js +6 -92
- package/dist/index.es53.js.map +1 -1
- package/dist/index.es54.js +14 -3
- package/dist/index.es54.js.map +1 -1
- package/dist/index.es55.js +8 -36
- package/dist/index.es55.js.map +1 -1
- package/dist/index.es56.js +83 -61
- package/dist/index.es56.js.map +1 -1
- package/dist/index.es57.js +3 -37
- package/dist/index.es57.js.map +1 -1
- package/dist/index.es58.js +34 -304
- package/dist/index.es58.js.map +1 -1
- package/dist/index.es59.js +72 -9
- package/dist/index.es59.js.map +1 -1
- package/dist/index.es60.js +32 -85
- package/dist/index.es60.js.map +1 -1
- package/dist/index.es61.js +304 -6
- package/dist/index.es61.js.map +1 -1
- package/dist/index.es62.js +9 -15
- package/dist/index.es62.js.map +1 -1
- package/dist/index.es63.js +3 -3
- package/dist/index.es64.js +5 -142
- package/dist/index.es64.js.map +1 -1
- package/dist/index.es65.js +148 -285
- package/dist/index.es65.js.map +1 -1
- package/dist/index.es66.js +668 -62
- package/dist/index.es66.js.map +1 -1
- package/dist/index.es67.js +131 -201
- package/dist/index.es67.js.map +1 -1
- package/dist/index.es68.js +295 -29
- package/dist/index.es68.js.map +1 -1
- package/dist/index.es69.js +65 -8
- package/dist/index.es69.js.map +1 -1
- package/dist/index.es7.js +2 -1
- package/dist/index.es7.js.map +1 -1
- package/dist/index.es70.js +210 -9
- package/dist/index.es70.js.map +1 -1
- package/dist/index.es71.js +28 -181
- package/dist/index.es71.js.map +1 -1
- package/dist/index.es72.js +8 -23
- package/dist/index.es72.js.map +1 -1
- package/dist/index.es73.js +9 -1397
- package/dist/index.es73.js.map +1 -1
- package/dist/index.es74.js +187 -9
- package/dist/index.es74.js.map +1 -1
- package/dist/index.es75.js +24 -8
- package/dist/index.es75.js.map +1 -1
- package/dist/index.es76.js +1399 -5
- package/dist/index.es76.js.map +1 -1
- package/dist/index.es77.js +9 -163
- package/dist/index.es77.js.map +1 -1
- package/dist/index.es78.js +8 -672
- package/dist/index.es78.js.map +1 -1
- package/dist/index.es79.js +36 -20
- package/dist/index.es79.js.map +1 -1
- package/dist/index.es80.js +5 -68
- package/dist/index.es80.js.map +1 -1
- package/dist/index.es81.js +73 -3
- package/dist/index.es81.js.map +1 -1
- package/dist/index.es82.js +36 -11
- package/dist/index.es82.js.map +1 -1
- package/dist/index.es83.js +10 -38
- package/dist/index.es83.js.map +1 -1
- package/dist/index.es84.js +34 -28
- package/dist/index.es84.js.map +1 -1
- package/dist/index.es85.js +28 -226
- package/dist/index.es85.js.map +1 -1
- package/dist/index.es86.js +228 -26
- package/dist/index.es86.js.map +1 -1
- package/dist/index.es87.js +26 -71
- package/dist/index.es87.js.map +1 -1
- package/dist/index.es88.js +41 -42
- package/dist/index.es88.js.map +1 -1
- package/dist/index.es89.js +71 -47
- package/dist/index.es89.js.map +1 -1
- package/dist/index.es90.js +37 -15
- package/dist/index.es90.js.map +1 -1
- package/dist/index.es91.js +6 -19
- package/dist/index.es91.js.map +1 -1
- package/dist/index.es92.js +40 -54
- package/dist/index.es92.js.map +1 -1
- package/dist/index.es93.js +56 -12
- package/dist/index.es93.js.map +1 -1
- package/dist/index.es94.js +13 -137
- package/dist/index.es94.js.map +1 -1
- package/dist/index.es95.js +135 -19
- package/dist/index.es95.js.map +1 -1
- package/dist/index.es96.js +18 -179
- package/dist/index.es96.js.map +1 -1
- package/dist/index.es97.js +163 -222
- package/dist/index.es97.js.map +1 -1
- package/dist/index.es98.js +187 -301
- package/dist/index.es98.js.map +1 -1
- package/dist/index.es99.js +348 -130
- package/dist/index.es99.js.map +1 -1
- package/package.json +1 -1
package/dist/index.es65.js
CHANGED
|
@@ -1,303 +1,166 @@
|
|
|
1
|
-
import
|
|
2
|
-
function
|
|
3
|
-
if (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
citedText: cited_text
|
|
13
|
-
};
|
|
1
|
+
import isNetworkError from "./index.es79.js";
|
|
2
|
+
function validateRetries(retries) {
|
|
3
|
+
if (typeof retries === "number") {
|
|
4
|
+
if (retries < 0) {
|
|
5
|
+
throw new TypeError("Expected `retries` to be a non-negative number.");
|
|
6
|
+
}
|
|
7
|
+
if (Number.isNaN(retries)) {
|
|
8
|
+
throw new TypeError("Expected `retries` to be a valid number or Infinity, got NaN.");
|
|
9
|
+
}
|
|
10
|
+
} else if (retries !== void 0) {
|
|
11
|
+
throw new TypeError("Expected `retries` to be a number or Infinity.");
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
type: "citation",
|
|
20
|
-
source: "page",
|
|
21
|
-
title: document_title ?? void 0,
|
|
22
|
-
startIndex: start_page_number,
|
|
23
|
-
endIndex: end_page_number,
|
|
24
|
-
citedText: cited_text
|
|
25
|
-
};
|
|
13
|
+
}
|
|
14
|
+
function validateNumberOption(name, value, { min = 0, allowInfinity = false } = {}) {
|
|
15
|
+
if (value === void 0) {
|
|
16
|
+
return;
|
|
26
17
|
}
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
...rest,
|
|
31
|
-
type: "citation",
|
|
32
|
-
source: "block",
|
|
33
|
-
title: document_title ?? void 0,
|
|
34
|
-
startIndex: start_block_index,
|
|
35
|
-
endIndex: end_block_index,
|
|
36
|
-
citedText: cited_text
|
|
37
|
-
};
|
|
18
|
+
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
19
|
+
throw new TypeError(`Expected \`${name}\` to be a number${allowInfinity ? " or Infinity" : ""}.`);
|
|
38
20
|
}
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
...rest,
|
|
43
|
-
type: "citation",
|
|
44
|
-
source: "url",
|
|
45
|
-
url,
|
|
46
|
-
title,
|
|
47
|
-
startIndex: Number(encrypted_index),
|
|
48
|
-
endIndex: Number(encrypted_index),
|
|
49
|
-
citedText: cited_text
|
|
50
|
-
};
|
|
21
|
+
if (!allowInfinity && !Number.isFinite(value)) {
|
|
22
|
+
throw new TypeError(`Expected \`${name}\` to be a finite number.`);
|
|
51
23
|
}
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
24
|
+
if (value < min) {
|
|
25
|
+
throw new TypeError(`Expected \`${name}\` to be ≥ ${min}.`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
class AbortError extends Error {
|
|
29
|
+
constructor(message) {
|
|
30
|
+
super();
|
|
31
|
+
if (message instanceof Error) {
|
|
32
|
+
this.originalError = message;
|
|
33
|
+
({ message } = message);
|
|
34
|
+
} else {
|
|
35
|
+
this.originalError = new Error(message);
|
|
36
|
+
this.originalError.stack = this.stack;
|
|
37
|
+
}
|
|
38
|
+
this.name = "AbortError";
|
|
39
|
+
this.message = message;
|
|
64
40
|
}
|
|
65
|
-
return void 0;
|
|
66
41
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
};
|
|
78
|
-
else if (block.source.type === "file" && _isString(block.source.file_id)) return {
|
|
79
|
-
type: "file",
|
|
80
|
-
fileId: block.source.file_id
|
|
81
|
-
};
|
|
82
|
-
else if (block.source.type === "text" && _isString(block.source.data)) return {
|
|
83
|
-
type: "file",
|
|
84
|
-
mimeType: String(block.source.media_type ?? "text/plain"),
|
|
85
|
-
data: block.source.data
|
|
86
|
-
};
|
|
87
|
-
} else if (_isContentBlock(block, "image") && _isObject(block.source) && "type" in block.source) {
|
|
88
|
-
if (block.source.type === "base64" && _isString(block.source.media_type) && _isString(block.source.data)) return {
|
|
89
|
-
type: "image",
|
|
90
|
-
mimeType: block.source.media_type,
|
|
91
|
-
data: block.source.data
|
|
92
|
-
};
|
|
93
|
-
else if (block.source.type === "url" && _isString(block.source.url)) return {
|
|
94
|
-
type: "image",
|
|
95
|
-
url: block.source.url
|
|
96
|
-
};
|
|
97
|
-
else if (block.source.type === "file" && _isString(block.source.file_id)) return {
|
|
98
|
-
type: "image",
|
|
99
|
-
fileId: block.source.file_id
|
|
100
|
-
};
|
|
42
|
+
function calculateDelay(retriesConsumed, options) {
|
|
43
|
+
const attempt = Math.max(1, retriesConsumed + 1);
|
|
44
|
+
const random = options.randomize ? Math.random() + 1 : 1;
|
|
45
|
+
let timeout = Math.round(random * options.minTimeout * options.factor ** (attempt - 1));
|
|
46
|
+
timeout = Math.min(timeout, options.maxTimeout);
|
|
47
|
+
return timeout;
|
|
48
|
+
}
|
|
49
|
+
function calculateRemainingTime(start, max) {
|
|
50
|
+
if (!Number.isFinite(max)) {
|
|
51
|
+
return max;
|
|
101
52
|
}
|
|
102
|
-
return
|
|
53
|
+
return max - (performance.now() - start);
|
|
103
54
|
}
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
55
|
+
async function onAttemptFailure({ error, attemptNumber, retriesConsumed, startTime, options }) {
|
|
56
|
+
const normalizedError = error instanceof Error ? error : new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`);
|
|
57
|
+
if (normalizedError instanceof AbortError) {
|
|
58
|
+
throw normalizedError.originalError;
|
|
59
|
+
}
|
|
60
|
+
const retriesLeft = Number.isFinite(options.retries) ? Math.max(0, options.retries - retriesConsumed) : options.retries;
|
|
61
|
+
const maxRetryTime = options.maxRetryTime ?? Number.POSITIVE_INFINITY;
|
|
62
|
+
const context = Object.freeze({
|
|
63
|
+
error: normalizedError,
|
|
64
|
+
attemptNumber,
|
|
65
|
+
retriesLeft,
|
|
66
|
+
retriesConsumed
|
|
67
|
+
});
|
|
68
|
+
await options.onFailedAttempt(context);
|
|
69
|
+
if (calculateRemainingTime(startTime, maxRetryTime) <= 0) {
|
|
70
|
+
throw normalizedError;
|
|
71
|
+
}
|
|
72
|
+
const consumeRetry = await options.shouldConsumeRetry(context);
|
|
73
|
+
const remainingTime = calculateRemainingTime(startTime, maxRetryTime);
|
|
74
|
+
if (remainingTime <= 0 || retriesLeft <= 0) {
|
|
75
|
+
throw normalizedError;
|
|
76
|
+
}
|
|
77
|
+
if (normalizedError instanceof TypeError && !isNetworkError(normalizedError)) {
|
|
78
|
+
if (consumeRetry) {
|
|
79
|
+
throw normalizedError;
|
|
110
80
|
}
|
|
81
|
+
options.signal?.throwIfAborted();
|
|
82
|
+
return false;
|
|
111
83
|
}
|
|
112
|
-
|
|
84
|
+
if (!await options.shouldRetry(context)) {
|
|
85
|
+
throw normalizedError;
|
|
86
|
+
}
|
|
87
|
+
if (!consumeRetry) {
|
|
88
|
+
options.signal?.throwIfAborted();
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
const delayTime = calculateDelay(retriesConsumed, options);
|
|
92
|
+
const finalDelay = Math.min(delayTime, remainingTime);
|
|
93
|
+
options.signal?.throwIfAborted();
|
|
94
|
+
if (finalDelay > 0) {
|
|
95
|
+
await new Promise((resolve, reject) => {
|
|
96
|
+
const onAbort = () => {
|
|
97
|
+
clearTimeout(timeoutToken);
|
|
98
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
99
|
+
reject(options.signal.reason);
|
|
100
|
+
};
|
|
101
|
+
const timeoutToken = setTimeout(() => {
|
|
102
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
103
|
+
resolve();
|
|
104
|
+
}, finalDelay);
|
|
105
|
+
if (options.unref) {
|
|
106
|
+
timeoutToken.unref?.();
|
|
107
|
+
}
|
|
108
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
options.signal?.throwIfAborted();
|
|
112
|
+
return true;
|
|
113
113
|
}
|
|
114
|
-
function
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
};
|
|
158
|
-
continue;
|
|
159
|
-
} else if (_isContentBlock(block, "tool_use") && _isString(block.name) && _isString(block.id)) {
|
|
160
|
-
yield {
|
|
161
|
-
type: "tool_call",
|
|
162
|
-
id: block.id,
|
|
163
|
-
name: block.name,
|
|
164
|
-
args: block.input
|
|
165
|
-
};
|
|
166
|
-
continue;
|
|
167
|
-
} else if (_isContentBlock(block, "input_json_delta")) {
|
|
168
|
-
if (_isAIMessageChunk(message) && message.tool_call_chunks?.length) {
|
|
169
|
-
const tool_call_chunk = message.tool_call_chunks[0];
|
|
170
|
-
yield {
|
|
171
|
-
type: "tool_call_chunk",
|
|
172
|
-
id: tool_call_chunk.id,
|
|
173
|
-
name: tool_call_chunk.name,
|
|
174
|
-
args: tool_call_chunk.args,
|
|
175
|
-
index: tool_call_chunk.index
|
|
176
|
-
};
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
} else if (_isContentBlock(block, "server_tool_use") && _isString(block.name) && _isString(block.id)) {
|
|
180
|
-
const { name, id } = block;
|
|
181
|
-
if (name === "web_search") {
|
|
182
|
-
const query = iife(() => {
|
|
183
|
-
if (typeof block.input === "string") return block.input;
|
|
184
|
-
else if (_isObject(block.input) && _isString(block.input.query)) return block.input.query;
|
|
185
|
-
else if (_isString(block.partial_json)) {
|
|
186
|
-
const json = safeParseJson(block.partial_json);
|
|
187
|
-
if (json?.query) return json.query;
|
|
188
|
-
}
|
|
189
|
-
return "";
|
|
190
|
-
});
|
|
191
|
-
yield {
|
|
192
|
-
id,
|
|
193
|
-
type: "server_tool_call",
|
|
194
|
-
name: "web_search",
|
|
195
|
-
args: { query }
|
|
196
|
-
};
|
|
197
|
-
continue;
|
|
198
|
-
} else if (block.name === "code_execution") {
|
|
199
|
-
const code = iife(() => {
|
|
200
|
-
if (typeof block.input === "string") return block.input;
|
|
201
|
-
else if (_isObject(block.input) && _isString(block.input.code)) return block.input.code;
|
|
202
|
-
else if (_isString(block.partial_json)) {
|
|
203
|
-
const json = safeParseJson(block.partial_json);
|
|
204
|
-
if (json?.code) return json.code;
|
|
205
|
-
}
|
|
206
|
-
return "";
|
|
207
|
-
});
|
|
208
|
-
yield {
|
|
209
|
-
id,
|
|
210
|
-
type: "server_tool_call",
|
|
211
|
-
name: "code_execution",
|
|
212
|
-
args: { code }
|
|
213
|
-
};
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
} else if (_isContentBlock(block, "web_search_tool_result") && _isString(block.tool_use_id) && _isArray(block.content)) {
|
|
217
|
-
const { content: content$1, tool_use_id } = block;
|
|
218
|
-
const urls = content$1.reduce((acc, content$2) => {
|
|
219
|
-
if (_isContentBlock(content$2, "web_search_result")) return [...acc, content$2.url];
|
|
220
|
-
return acc;
|
|
221
|
-
}, []);
|
|
222
|
-
yield {
|
|
223
|
-
type: "server_tool_call_result",
|
|
224
|
-
name: "web_search",
|
|
225
|
-
toolCallId: tool_use_id,
|
|
226
|
-
status: "success",
|
|
227
|
-
output: { urls }
|
|
228
|
-
};
|
|
229
|
-
continue;
|
|
230
|
-
} else if (_isContentBlock(block, "code_execution_tool_result") && _isString(block.tool_use_id) && _isObject(block.content)) {
|
|
231
|
-
yield {
|
|
232
|
-
type: "server_tool_call_result",
|
|
233
|
-
name: "code_execution",
|
|
234
|
-
toolCallId: block.tool_use_id,
|
|
235
|
-
status: "success",
|
|
236
|
-
output: block.content
|
|
237
|
-
};
|
|
238
|
-
continue;
|
|
239
|
-
} else if (_isContentBlock(block, "mcp_tool_use")) {
|
|
240
|
-
yield {
|
|
241
|
-
id: block.id,
|
|
242
|
-
type: "server_tool_call",
|
|
243
|
-
name: "mcp_tool_use",
|
|
244
|
-
args: block.input
|
|
245
|
-
};
|
|
246
|
-
continue;
|
|
247
|
-
} else if (_isContentBlock(block, "mcp_tool_result") && _isString(block.tool_use_id) && _isObject(block.content)) {
|
|
248
|
-
yield {
|
|
249
|
-
type: "server_tool_call_result",
|
|
250
|
-
name: "mcp_tool_use",
|
|
251
|
-
toolCallId: block.tool_use_id,
|
|
252
|
-
status: "success",
|
|
253
|
-
output: block.content
|
|
254
|
-
};
|
|
255
|
-
continue;
|
|
256
|
-
} else if (_isContentBlock(block, "container_upload")) {
|
|
257
|
-
yield {
|
|
258
|
-
type: "server_tool_call",
|
|
259
|
-
name: "container_upload",
|
|
260
|
-
args: block.input
|
|
261
|
-
};
|
|
262
|
-
continue;
|
|
263
|
-
} else if (_isContentBlock(block, "search_result")) {
|
|
264
|
-
yield {
|
|
265
|
-
id: block.id,
|
|
266
|
-
type: "non_standard",
|
|
267
|
-
value: block
|
|
268
|
-
};
|
|
269
|
-
continue;
|
|
270
|
-
} else if (_isContentBlock(block, "tool_result")) {
|
|
271
|
-
yield {
|
|
272
|
-
id: block.id,
|
|
273
|
-
type: "non_standard",
|
|
274
|
-
value: block
|
|
275
|
-
};
|
|
276
|
-
continue;
|
|
277
|
-
} else {
|
|
278
|
-
const stdBlock = convertToV1FromAnthropicContentBlock(block);
|
|
279
|
-
if (stdBlock) {
|
|
280
|
-
yield stdBlock;
|
|
281
|
-
continue;
|
|
282
|
-
}
|
|
114
|
+
async function pRetry(input, options = {}) {
|
|
115
|
+
options = { ...options };
|
|
116
|
+
validateRetries(options.retries);
|
|
117
|
+
if (Object.hasOwn(options, "forever")) {
|
|
118
|
+
throw new Error("The `forever` option is no longer supported. For many use-cases, you can set `retries: Infinity` instead.");
|
|
119
|
+
}
|
|
120
|
+
options.retries ??= 10;
|
|
121
|
+
options.factor ??= 2;
|
|
122
|
+
options.minTimeout ??= 1e3;
|
|
123
|
+
options.maxTimeout ??= Number.POSITIVE_INFINITY;
|
|
124
|
+
options.maxRetryTime ??= Number.POSITIVE_INFINITY;
|
|
125
|
+
options.randomize ??= false;
|
|
126
|
+
options.onFailedAttempt ??= () => {
|
|
127
|
+
};
|
|
128
|
+
options.shouldRetry ??= () => true;
|
|
129
|
+
options.shouldConsumeRetry ??= () => true;
|
|
130
|
+
validateNumberOption("factor", options.factor, { min: 0, allowInfinity: false });
|
|
131
|
+
validateNumberOption("minTimeout", options.minTimeout, { min: 0, allowInfinity: false });
|
|
132
|
+
validateNumberOption("maxTimeout", options.maxTimeout, { min: 0, allowInfinity: true });
|
|
133
|
+
validateNumberOption("maxRetryTime", options.maxRetryTime, { min: 0, allowInfinity: true });
|
|
134
|
+
if (!(options.factor > 0)) {
|
|
135
|
+
options.factor = 1;
|
|
136
|
+
}
|
|
137
|
+
options.signal?.throwIfAborted();
|
|
138
|
+
let attemptNumber = 0;
|
|
139
|
+
let retriesConsumed = 0;
|
|
140
|
+
const startTime = performance.now();
|
|
141
|
+
while (Number.isFinite(options.retries) ? retriesConsumed <= options.retries : true) {
|
|
142
|
+
attemptNumber++;
|
|
143
|
+
try {
|
|
144
|
+
options.signal?.throwIfAborted();
|
|
145
|
+
const result = await input(attemptNumber);
|
|
146
|
+
options.signal?.throwIfAborted();
|
|
147
|
+
return result;
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (await onAttemptFailure({
|
|
150
|
+
error,
|
|
151
|
+
attemptNumber,
|
|
152
|
+
retriesConsumed,
|
|
153
|
+
startTime,
|
|
154
|
+
options
|
|
155
|
+
})) {
|
|
156
|
+
retriesConsumed++;
|
|
283
157
|
}
|
|
284
|
-
yield {
|
|
285
|
-
type: "non_standard",
|
|
286
|
-
value: block
|
|
287
|
-
};
|
|
288
158
|
}
|
|
289
159
|
}
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
const ChatAnthropicTranslator = {
|
|
293
|
-
translateContent: convertToV1FromAnthropicMessage,
|
|
294
|
-
translateContentChunk: convertToV1FromAnthropicMessage
|
|
295
|
-
};
|
|
296
|
-
function _isAIMessageChunk(message) {
|
|
297
|
-
return typeof message?._getType === "function" && typeof message.concat === "function" && message._getType() === "ai";
|
|
160
|
+
throw new Error("Retry attempts exhausted without throwing an error.");
|
|
298
161
|
}
|
|
299
162
|
export {
|
|
300
|
-
|
|
301
|
-
|
|
163
|
+
AbortError,
|
|
164
|
+
pRetry as default
|
|
302
165
|
};
|
|
303
166
|
//# sourceMappingURL=index.es65.js.map
|
package/dist/index.es65.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es65.js","sources":["../node_modules/.pnpm/@langchain+core@1.1.13_openai@6.16.0_zod@4.3.5_/node_modules/@langchain/core/dist/messages/block_translators/anthropic.js"],"sourcesContent":["import { _isArray, _isContentBlock, _isNumber, _isObject, _isString, iife, safeParseJson } from \"./utils.js\";\n\n//#region src/messages/block_translators/anthropic.ts\nfunction convertAnthropicAnnotation(citation) {\n\tif (citation.type === \"char_location\" && _isString(citation.document_title) && _isNumber(citation.start_char_index) && _isNumber(citation.end_char_index) && _isString(citation.cited_text)) {\n\t\tconst { document_title, start_char_index, end_char_index, cited_text,...rest } = citation;\n\t\treturn {\n\t\t\t...rest,\n\t\t\ttype: \"citation\",\n\t\t\tsource: \"char\",\n\t\t\ttitle: document_title ?? void 0,\n\t\t\tstartIndex: start_char_index,\n\t\t\tendIndex: end_char_index,\n\t\t\tcitedText: cited_text\n\t\t};\n\t}\n\tif (citation.type === \"page_location\" && _isString(citation.document_title) && _isNumber(citation.start_page_number) && _isNumber(citation.end_page_number) && _isString(citation.cited_text)) {\n\t\tconst { document_title, start_page_number, end_page_number, cited_text,...rest } = citation;\n\t\treturn {\n\t\t\t...rest,\n\t\t\ttype: \"citation\",\n\t\t\tsource: \"page\",\n\t\t\ttitle: document_title ?? void 0,\n\t\t\tstartIndex: start_page_number,\n\t\t\tendIndex: end_page_number,\n\t\t\tcitedText: cited_text\n\t\t};\n\t}\n\tif (citation.type === \"content_block_location\" && _isString(citation.document_title) && _isNumber(citation.start_block_index) && _isNumber(citation.end_block_index) && _isString(citation.cited_text)) {\n\t\tconst { document_title, start_block_index, end_block_index, cited_text,...rest } = citation;\n\t\treturn {\n\t\t\t...rest,\n\t\t\ttype: \"citation\",\n\t\t\tsource: \"block\",\n\t\t\ttitle: document_title ?? void 0,\n\t\t\tstartIndex: start_block_index,\n\t\t\tendIndex: end_block_index,\n\t\t\tcitedText: cited_text\n\t\t};\n\t}\n\tif (citation.type === \"web_search_result_location\" && _isString(citation.url) && _isString(citation.title) && _isString(citation.encrypted_index) && _isString(citation.cited_text)) {\n\t\tconst { url, title, encrypted_index, cited_text,...rest } = citation;\n\t\treturn {\n\t\t\t...rest,\n\t\t\ttype: \"citation\",\n\t\t\tsource: \"url\",\n\t\t\turl,\n\t\t\ttitle,\n\t\t\tstartIndex: Number(encrypted_index),\n\t\t\tendIndex: Number(encrypted_index),\n\t\t\tcitedText: cited_text\n\t\t};\n\t}\n\tif (citation.type === \"search_result_location\" && _isString(citation.source) && _isString(citation.title) && _isNumber(citation.start_block_index) && _isNumber(citation.end_block_index) && _isString(citation.cited_text)) {\n\t\tconst { source, title, start_block_index, end_block_index, cited_text,...rest } = citation;\n\t\treturn {\n\t\t\t...rest,\n\t\t\ttype: \"citation\",\n\t\t\tsource: \"search\",\n\t\t\turl: source,\n\t\t\ttitle: title ?? void 0,\n\t\t\tstartIndex: start_block_index,\n\t\t\tendIndex: end_block_index,\n\t\t\tcitedText: cited_text\n\t\t};\n\t}\n\treturn void 0;\n}\n/**\n* Converts an Anthropic content block to a standard V1 content block.\n*\n* This function handles the conversion of Anthropic-specific content blocks\n* (document and image blocks) to the standardized V1 format. It supports\n* various source types including base64 data, URLs, file IDs, and text data.\n*\n* @param block - The Anthropic content block to convert\n* @returns A standard V1 content block if conversion is successful, undefined otherwise\n*\n* @example\n* ```typescript\n* const anthropicBlock = {\n* type: \"image\",\n* source: {\n* type: \"base64\",\n* media_type: \"image/png\",\n* data: \"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==\"\n* }\n* };\n*\n* const standardBlock = convertToV1FromAnthropicContentBlock(anthropicBlock);\n* // Returns: { type: \"image\", mimeType: \"image/png\", data: \"...\" }\n* ```\n*/\nfunction convertToV1FromAnthropicContentBlock(block) {\n\tif (_isContentBlock(block, \"document\") && _isObject(block.source) && \"type\" in block.source) {\n\t\tif (block.source.type === \"base64\" && _isString(block.source.media_type) && _isString(block.source.data)) return {\n\t\t\ttype: \"file\",\n\t\t\tmimeType: block.source.media_type,\n\t\t\tdata: block.source.data\n\t\t};\n\t\telse if (block.source.type === \"url\" && _isString(block.source.url)) return {\n\t\t\ttype: \"file\",\n\t\t\turl: block.source.url\n\t\t};\n\t\telse if (block.source.type === \"file\" && _isString(block.source.file_id)) return {\n\t\t\ttype: \"file\",\n\t\t\tfileId: block.source.file_id\n\t\t};\n\t\telse if (block.source.type === \"text\" && _isString(block.source.data)) return {\n\t\t\ttype: \"file\",\n\t\t\tmimeType: String(block.source.media_type ?? \"text/plain\"),\n\t\t\tdata: block.source.data\n\t\t};\n\t} else if (_isContentBlock(block, \"image\") && _isObject(block.source) && \"type\" in block.source) {\n\t\tif (block.source.type === \"base64\" && _isString(block.source.media_type) && _isString(block.source.data)) return {\n\t\t\ttype: \"image\",\n\t\t\tmimeType: block.source.media_type,\n\t\t\tdata: block.source.data\n\t\t};\n\t\telse if (block.source.type === \"url\" && _isString(block.source.url)) return {\n\t\t\ttype: \"image\",\n\t\t\turl: block.source.url\n\t\t};\n\t\telse if (block.source.type === \"file\" && _isString(block.source.file_id)) return {\n\t\t\ttype: \"image\",\n\t\t\tfileId: block.source.file_id\n\t\t};\n\t}\n\treturn void 0;\n}\n/**\n* Converts an array of content blocks from Anthropic format to v1 standard format.\n*\n* This function processes each content block in the input array, attempting to convert\n* Anthropic-specific block formats (like image blocks with source objects, document blocks, etc.)\n* to the standardized v1 content block format. If a block cannot be converted, it is\n* passed through as-is with a type assertion to ContentBlock.Standard.\n*\n* @param content - Array of content blocks in Anthropic format to be converted\n* @returns Array of content blocks in v1 standard format\n*/\nfunction convertToV1FromAnthropicInput(content) {\n\tfunction* iterateContent() {\n\t\tfor (const block of content) {\n\t\t\tconst stdBlock = convertToV1FromAnthropicContentBlock(block);\n\t\t\tif (stdBlock) yield stdBlock;\n\t\t\telse yield block;\n\t\t}\n\t}\n\treturn Array.from(iterateContent());\n}\n/**\n* Converts an Anthropic AI message to an array of v1 standard content blocks.\n*\n* This function processes an AI message containing Anthropic-specific content blocks\n* and converts them to the standardized v1 content block format.\n*\n* @param message - The AI message containing Anthropic-formatted content blocks\n* @returns Array of content blocks in v1 standard format\n*\n* @example\n* ```typescript\n* const message = new AIMessage([\n* { type: \"text\", text: \"Hello world\" },\n* { type: \"thinking\", text: \"Let me think about this...\" },\n* { type: \"tool_use\", id: \"123\", name: \"calculator\", input: { a: 1, b: 2 } }\n* ]);\n*\n* const standardBlocks = convertToV1FromAnthropicMessage(message);\n* // Returns:\n* // [\n* // { type: \"text\", text: \"Hello world\" },\n* // { type: \"reasoning\", reasoning: \"Let me think about this...\" },\n* // { type: \"tool_call\", id: \"123\", name: \"calculator\", args: { a: 1, b: 2 } }\n* // ]\n* ```\n*/\nfunction convertToV1FromAnthropicMessage(message) {\n\tfunction* iterateContent() {\n\t\tconst content = typeof message.content === \"string\" ? [{\n\t\t\ttype: \"text\",\n\t\t\ttext: message.content\n\t\t}] : message.content;\n\t\tfor (const block of content) {\n\t\t\tif (_isContentBlock(block, \"text\") && _isString(block.text)) {\n\t\t\t\tconst { text, citations,...rest } = block;\n\t\t\t\tif (_isArray(citations) && citations.length) {\n\t\t\t\t\tconst _citations = citations.reduce((acc, item) => {\n\t\t\t\t\t\tconst citation = convertAnthropicAnnotation(item);\n\t\t\t\t\t\tif (citation) return [...acc, citation];\n\t\t\t\t\t\treturn acc;\n\t\t\t\t\t}, []);\n\t\t\t\t\tyield {\n\t\t\t\t\t\t...rest,\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext,\n\t\t\t\t\t\tannotations: _citations\n\t\t\t\t\t};\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\tyield {\n\t\t\t\t\t\t...rest,\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext\n\t\t\t\t\t};\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t} else if (_isContentBlock(block, \"thinking\") && _isString(block.thinking)) {\n\t\t\t\tconst { thinking, signature,...rest } = block;\n\t\t\t\tyield {\n\t\t\t\t\t...rest,\n\t\t\t\t\ttype: \"reasoning\",\n\t\t\t\t\treasoning: thinking,\n\t\t\t\t\tsignature\n\t\t\t\t};\n\t\t\t\tcontinue;\n\t\t\t} else if (_isContentBlock(block, \"redacted_thinking\")) {\n\t\t\t\tyield {\n\t\t\t\t\ttype: \"non_standard\",\n\t\t\t\t\tvalue: block\n\t\t\t\t};\n\t\t\t\tcontinue;\n\t\t\t} else if (_isContentBlock(block, \"tool_use\") && _isString(block.name) && _isString(block.id)) {\n\t\t\t\tyield {\n\t\t\t\t\ttype: \"tool_call\",\n\t\t\t\t\tid: block.id,\n\t\t\t\t\tname: block.name,\n\t\t\t\t\targs: block.input\n\t\t\t\t};\n\t\t\t\tcontinue;\n\t\t\t} else if (_isContentBlock(block, \"input_json_delta\")) {\n\t\t\t\tif (_isAIMessageChunk(message) && message.tool_call_chunks?.length) {\n\t\t\t\t\tconst tool_call_chunk = message.tool_call_chunks[0];\n\t\t\t\t\tyield {\n\t\t\t\t\t\ttype: \"tool_call_chunk\",\n\t\t\t\t\t\tid: tool_call_chunk.id,\n\t\t\t\t\t\tname: tool_call_chunk.name,\n\t\t\t\t\t\targs: tool_call_chunk.args,\n\t\t\t\t\t\tindex: tool_call_chunk.index\n\t\t\t\t\t};\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t} else if (_isContentBlock(block, \"server_tool_use\") && _isString(block.name) && _isString(block.id)) {\n\t\t\t\tconst { name, id } = block;\n\t\t\t\tif (name === \"web_search\") {\n\t\t\t\t\tconst query = iife(() => {\n\t\t\t\t\t\tif (typeof block.input === \"string\") return block.input;\n\t\t\t\t\t\telse if (_isObject(block.input) && _isString(block.input.query)) return block.input.query;\n\t\t\t\t\t\telse if (_isString(block.partial_json)) {\n\t\t\t\t\t\t\tconst json = safeParseJson(block.partial_json);\n\t\t\t\t\t\t\tif (json?.query) return json.query;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn \"\";\n\t\t\t\t\t});\n\t\t\t\t\tyield {\n\t\t\t\t\t\tid,\n\t\t\t\t\t\ttype: \"server_tool_call\",\n\t\t\t\t\t\tname: \"web_search\",\n\t\t\t\t\t\targs: { query }\n\t\t\t\t\t};\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if (block.name === \"code_execution\") {\n\t\t\t\t\tconst code = iife(() => {\n\t\t\t\t\t\tif (typeof block.input === \"string\") return block.input;\n\t\t\t\t\t\telse if (_isObject(block.input) && _isString(block.input.code)) return block.input.code;\n\t\t\t\t\t\telse if (_isString(block.partial_json)) {\n\t\t\t\t\t\t\tconst json = safeParseJson(block.partial_json);\n\t\t\t\t\t\t\tif (json?.code) return json.code;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn \"\";\n\t\t\t\t\t});\n\t\t\t\t\tyield {\n\t\t\t\t\t\tid,\n\t\t\t\t\t\ttype: \"server_tool_call\",\n\t\t\t\t\t\tname: \"code_execution\",\n\t\t\t\t\t\targs: { code }\n\t\t\t\t\t};\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t} else if (_isContentBlock(block, \"web_search_tool_result\") && _isString(block.tool_use_id) && _isArray(block.content)) {\n\t\t\t\tconst { content: content$1, tool_use_id } = block;\n\t\t\t\tconst urls = content$1.reduce((acc, content$2) => {\n\t\t\t\t\tif (_isContentBlock(content$2, \"web_search_result\")) return [...acc, content$2.url];\n\t\t\t\t\treturn acc;\n\t\t\t\t}, []);\n\t\t\t\tyield {\n\t\t\t\t\ttype: \"server_tool_call_result\",\n\t\t\t\t\tname: \"web_search\",\n\t\t\t\t\ttoolCallId: tool_use_id,\n\t\t\t\t\tstatus: \"success\",\n\t\t\t\t\toutput: { urls }\n\t\t\t\t};\n\t\t\t\tcontinue;\n\t\t\t} else if (_isContentBlock(block, \"code_execution_tool_result\") && _isString(block.tool_use_id) && _isObject(block.content)) {\n\t\t\t\tyield {\n\t\t\t\t\ttype: \"server_tool_call_result\",\n\t\t\t\t\tname: \"code_execution\",\n\t\t\t\t\ttoolCallId: block.tool_use_id,\n\t\t\t\t\tstatus: \"success\",\n\t\t\t\t\toutput: block.content\n\t\t\t\t};\n\t\t\t\tcontinue;\n\t\t\t} else if (_isContentBlock(block, \"mcp_tool_use\")) {\n\t\t\t\tyield {\n\t\t\t\t\tid: block.id,\n\t\t\t\t\ttype: \"server_tool_call\",\n\t\t\t\t\tname: \"mcp_tool_use\",\n\t\t\t\t\targs: block.input\n\t\t\t\t};\n\t\t\t\tcontinue;\n\t\t\t} else if (_isContentBlock(block, \"mcp_tool_result\") && _isString(block.tool_use_id) && _isObject(block.content)) {\n\t\t\t\tyield {\n\t\t\t\t\ttype: \"server_tool_call_result\",\n\t\t\t\t\tname: \"mcp_tool_use\",\n\t\t\t\t\ttoolCallId: block.tool_use_id,\n\t\t\t\t\tstatus: \"success\",\n\t\t\t\t\toutput: block.content\n\t\t\t\t};\n\t\t\t\tcontinue;\n\t\t\t} else if (_isContentBlock(block, \"container_upload\")) {\n\t\t\t\tyield {\n\t\t\t\t\ttype: \"server_tool_call\",\n\t\t\t\t\tname: \"container_upload\",\n\t\t\t\t\targs: block.input\n\t\t\t\t};\n\t\t\t\tcontinue;\n\t\t\t} else if (_isContentBlock(block, \"search_result\")) {\n\t\t\t\tyield {\n\t\t\t\t\tid: block.id,\n\t\t\t\t\ttype: \"non_standard\",\n\t\t\t\t\tvalue: block\n\t\t\t\t};\n\t\t\t\tcontinue;\n\t\t\t} else if (_isContentBlock(block, \"tool_result\")) {\n\t\t\t\tyield {\n\t\t\t\t\tid: block.id,\n\t\t\t\t\ttype: \"non_standard\",\n\t\t\t\t\tvalue: block\n\t\t\t\t};\n\t\t\t\tcontinue;\n\t\t\t} else {\n\t\t\t\tconst stdBlock = convertToV1FromAnthropicContentBlock(block);\n\t\t\t\tif (stdBlock) {\n\t\t\t\t\tyield stdBlock;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tyield {\n\t\t\t\ttype: \"non_standard\",\n\t\t\t\tvalue: block\n\t\t\t};\n\t\t}\n\t}\n\treturn Array.from(iterateContent());\n}\nconst ChatAnthropicTranslator = {\n\ttranslateContent: convertToV1FromAnthropicMessage,\n\ttranslateContentChunk: convertToV1FromAnthropicMessage\n};\nfunction _isAIMessageChunk(message) {\n\treturn typeof message?._getType === \"function\" && typeof message.concat === \"function\" && message._getType() === \"ai\";\n}\n\n//#endregion\nexport { ChatAnthropicTranslator, convertToV1FromAnthropicInput };\n//# sourceMappingURL=anthropic.js.map"],"names":[],"mappings":";AAGA,SAAS,2BAA2B,UAAU;AAC7C,MAAI,SAAS,SAAS,mBAAmB,UAAU,SAAS,cAAc,KAAK,UAAU,SAAS,gBAAgB,KAAK,UAAU,SAAS,cAAc,KAAK,UAAU,SAAS,UAAU,GAAG;AAC5L,UAAM,EAAE,gBAAgB,kBAAkB,gBAAgB,YAAW,GAAG,KAAI,IAAK;AACjF,WAAO;AAAA,MACN,GAAG;AAAA,MACH,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,OAAO,kBAAkB;AAAA,MACzB,YAAY;AAAA,MACZ,UAAU;AAAA,MACV,WAAW;AAAA,IACd;AAAA,EACC;AACA,MAAI,SAAS,SAAS,mBAAmB,UAAU,SAAS,cAAc,KAAK,UAAU,SAAS,iBAAiB,KAAK,UAAU,SAAS,eAAe,KAAK,UAAU,SAAS,UAAU,GAAG;AAC9L,UAAM,EAAE,gBAAgB,mBAAmB,iBAAiB,YAAW,GAAG,KAAI,IAAK;AACnF,WAAO;AAAA,MACN,GAAG;AAAA,MACH,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,OAAO,kBAAkB;AAAA,MACzB,YAAY;AAAA,MACZ,UAAU;AAAA,MACV,WAAW;AAAA,IACd;AAAA,EACC;AACA,MAAI,SAAS,SAAS,4BAA4B,UAAU,SAAS,cAAc,KAAK,UAAU,SAAS,iBAAiB,KAAK,UAAU,SAAS,eAAe,KAAK,UAAU,SAAS,UAAU,GAAG;AACvM,UAAM,EAAE,gBAAg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AA,MACD,WAAW,gBAAgB,OAAO,kBAAkB,GAAG;AACtD,cAAM;AAAA,UACL,MAAM;AAAA,UACN,MAAM;AAAA,UACN,MAAM,MAAM;AAAA,QACjB;AACI;AAAA,MACD,WAAW,gBAAgB,OAAO,eAAe,GAAG;AACnD,cAAM;AAAA,UACL,IAAI,MAAM;AAAA,UACV,MAAM;AAAA,UACN,OAAO;AAAA,QACZ;AACI;AAAA,MACD,WAAW,gBAAgB,OAAO,aAAa,GAAG;AACjD,cAAM;AAAA,UACL,IAAI,MAAM;AAAA,UACV,MAAM;AAAA,UACN,OAAO;AAAA,QACZ;AACI;AAAA,MACD,OAAO;AACN,cAAM,WAAW,qCAAqC,KAAK;AAC3D,YAAI,UAAU;AACb,gBAAM;AACN;AAAA,QACD;AAAA,MACD;AACA,YAAM;AAAA,QACL,MAAM;AAAA,QACN,OAAO;AAAA,MACX;AAAA,IACE;AAAA,EACD;AACA,SAAO,MAAM,KAAK,gBAAgB;AACnC;AACK,MAAC,0BAA0B;AAAA,EAC/B,kBAAkB;AAAA,EAClB,uBAAuB;AACxB;AACA,SAAS,kBAAkB,SAAS;AACnC,SAAO,OAAO,SAAS,aAAa,cAAc,OAAO,QAAQ,WAAW,cAAc,QAAQ,SAAQ,MAAO;AAClH;","x_google_ignoreList":[0]}
|
|
1
|
+
{"version":3,"file":"index.es65.js","sources":["../node_modules/.pnpm/p-retry@7.1.1/node_modules/p-retry/index.js"],"sourcesContent":["import isNetworkError from 'is-network-error';\n\nfunction validateRetries(retries) {\n\tif (typeof retries === 'number') {\n\t\tif (retries < 0) {\n\t\t\tthrow new TypeError('Expected `retries` to be a non-negative number.');\n\t\t}\n\n\t\tif (Number.isNaN(retries)) {\n\t\t\tthrow new TypeError('Expected `retries` to be a valid number or Infinity, got NaN.');\n\t\t}\n\t} else if (retries !== undefined) {\n\t\tthrow new TypeError('Expected `retries` to be a number or Infinity.');\n\t}\n}\n\nfunction validateNumberOption(name, value, {min = 0, allowInfinity = false} = {}) {\n\tif (value === undefined) {\n\t\treturn;\n\t}\n\n\tif (typeof value !== 'number' || Number.isNaN(value)) {\n\t\tthrow new TypeError(`Expected \\`${name}\\` to be a number${allowInfinity ? ' or Infinity' : ''}.`);\n\t}\n\n\tif (!allowInfinity && !Number.isFinite(value)) {\n\t\tthrow new TypeError(`Expected \\`${name}\\` to be a finite number.`);\n\t}\n\n\tif (value < min) {\n\t\tthrow new TypeError(`Expected \\`${name}\\` to be \\u2265 ${min}.`);\n\t}\n}\n\nexport class AbortError extends Error {\n\tconstructor(message) {\n\t\tsuper();\n\n\t\tif (message instanceof Error) {\n\t\t\tthis.originalError = message;\n\t\t\t({message} = message);\n\t\t} else {\n\t\t\tthis.originalError = new Error(message);\n\t\t\tthis.originalError.stack = this.stack;\n\t\t}\n\n\t\tthis.name = 'AbortError';\n\t\tthis.message = message;\n\t}\n}\n\nfunction calculateDelay(retriesConsumed, options) {\n\tconst attempt = Math.max(1, retriesConsumed + 1);\n\tconst random = options.randomize ? (Math.random() + 1) : 1;\n\n\tlet timeout = Math.round(random * options.minTimeout * (options.factor ** (attempt - 1)));\n\ttimeout = Math.min(timeout, options.maxTimeout);\n\n\treturn timeout;\n}\n\nfunction calculateRemainingTime(start, max) {\n\tif (!Number.isFinite(max)) {\n\t\treturn max;\n\t}\n\n\treturn max - (performance.now() - start);\n}\n\nasync function onAttemptFailure({error, attemptNumber, retriesConsumed, startTime, options}) {\n\tconst normalizedError = error instanceof Error\n\t\t? error\n\t\t: new TypeError(`Non-error was thrown: \"${error}\". You should only throw errors.`);\n\n\tif (normalizedError instanceof AbortError) {\n\t\tthrow normalizedError.originalError;\n\t}\n\n\tconst retriesLeft = Number.isFinite(options.retries)\n\t\t? Math.max(0, options.retries - retriesConsumed)\n\t\t: options.retries;\n\n\tconst maxRetryTime = options.maxRetryTime ?? Number.POSITIVE_INFINITY;\n\n\tconst context = Object.freeze({\n\t\terror: normalizedError,\n\t\tattemptNumber,\n\t\tretriesLeft,\n\t\tretriesConsumed,\n\t});\n\n\tawait options.onFailedAttempt(context);\n\n\tif (calculateRemainingTime(startTime, maxRetryTime) <= 0) {\n\t\tthrow normalizedError;\n\t}\n\n\tconst consumeRetry = await options.shouldConsumeRetry(context);\n\n\tconst remainingTime = calculateRemainingTime(startTime, maxRetryTime);\n\n\tif (remainingTime <= 0 || retriesLeft <= 0) {\n\t\tthrow normalizedError;\n\t}\n\n\tif (normalizedError instanceof TypeError && !isNetworkError(normalizedError)) {\n\t\tif (consumeRetry) {\n\t\t\tthrow normalizedError;\n\t\t}\n\n\t\toptions.signal?.throwIfAborted();\n\t\treturn false;\n\t}\n\n\tif (!await options.shouldRetry(context)) {\n\t\tthrow normalizedError;\n\t}\n\n\tif (!consumeRetry) {\n\t\toptions.signal?.throwIfAborted();\n\t\treturn false;\n\t}\n\n\tconst delayTime = calculateDelay(retriesConsumed, options);\n\tconst finalDelay = Math.min(delayTime, remainingTime);\n\n\toptions.signal?.throwIfAborted();\n\n\tif (finalDelay > 0) {\n\t\tawait new Promise((resolve, reject) => {\n\t\t\tconst onAbort = () => {\n\t\t\t\tclearTimeout(timeoutToken);\n\t\t\t\toptions.signal?.removeEventListener('abort', onAbort);\n\t\t\t\treject(options.signal.reason);\n\t\t\t};\n\n\t\t\tconst timeoutToken = setTimeout(() => {\n\t\t\t\toptions.signal?.removeEventListener('abort', onAbort);\n\t\t\t\tresolve();\n\t\t\t}, finalDelay);\n\n\t\t\tif (options.unref) {\n\t\t\t\ttimeoutToken.unref?.();\n\t\t\t}\n\n\t\t\toptions.signal?.addEventListener('abort', onAbort, {once: true});\n\t\t});\n\t}\n\n\toptions.signal?.throwIfAborted();\n\n\treturn true;\n}\n\nexport default async function pRetry(input, options = {}) {\n\toptions = {...options};\n\n\tvalidateRetries(options.retries);\n\n\tif (Object.hasOwn(options, 'forever')) {\n\t\tthrow new Error('The `forever` option is no longer supported. For many use-cases, you can set `retries: Infinity` instead.');\n\t}\n\n\toptions.retries ??= 10;\n\toptions.factor ??= 2;\n\toptions.minTimeout ??= 1000;\n\toptions.maxTimeout ??= Number.POSITIVE_INFINITY;\n\toptions.maxRetryTime ??= Number.POSITIVE_INFINITY;\n\toptions.randomize ??= false;\n\toptions.onFailedAttempt ??= () => {};\n\toptions.shouldRetry ??= () => true;\n\toptions.shouldConsumeRetry ??= () => true;\n\n\t// Validate numeric options and normalize edge cases\n\tvalidateNumberOption('factor', options.factor, {min: 0, allowInfinity: false});\n\tvalidateNumberOption('minTimeout', options.minTimeout, {min: 0, allowInfinity: false});\n\tvalidateNumberOption('maxTimeout', options.maxTimeout, {min: 0, allowInfinity: true});\n\tvalidateNumberOption('maxRetryTime', options.maxRetryTime, {min: 0, allowInfinity: true});\n\n\t// Treat non-positive factor as 1 to avoid zero backoff or negative behavior\n\tif (!(options.factor > 0)) {\n\t\toptions.factor = 1;\n\t}\n\n\toptions.signal?.throwIfAborted();\n\n\tlet attemptNumber = 0;\n\tlet retriesConsumed = 0;\n\tconst startTime = performance.now();\n\n\twhile (Number.isFinite(options.retries) ? retriesConsumed <= options.retries : true) {\n\t\tattemptNumber++;\n\n\t\ttry {\n\t\t\toptions.signal?.throwIfAborted();\n\n\t\t\tconst result = await input(attemptNumber);\n\n\t\t\toptions.signal?.throwIfAborted();\n\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tif (await onAttemptFailure({\n\t\t\t\terror,\n\t\t\t\tattemptNumber,\n\t\t\t\tretriesConsumed,\n\t\t\t\tstartTime,\n\t\t\t\toptions,\n\t\t\t})) {\n\t\t\t\tretriesConsumed++;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Should not reach here, but in case it does, throw an error\n\tthrow new Error('Retry attempts exhausted without throwing an error.');\n}\n\nexport function makeRetriable(function_, options) {\n\treturn function (...arguments_) {\n\t\treturn pRetry(() => function_.apply(this, arguments_), options);\n\t};\n}\n"],"names":[],"mappings":";AAEA,SAAS,gBAAgB,SAAS;AACjC,MAAI,OAAO,YAAY,UAAU;AAChC,QAAI,UAAU,GAAG;AACh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