langgraph-ui-components 0.0.3 → 0.0.4
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/README.md +32 -0
- package/dist/index.es100.js +3157 -5
- package/dist/index.es100.js.map +1 -1
- package/dist/index.es101.js +35 -71
- package/dist/index.es101.js.map +1 -1
- package/dist/index.es102.js +5 -37
- package/dist/index.es102.js.map +1 -1
- package/dist/index.es103.js +73 -5
- package/dist/index.es103.js.map +1 -1
- package/dist/index.es104.js +39 -2
- package/dist/index.es104.js.map +1 -1
- package/dist/index.es105.js +5 -11
- package/dist/index.es105.js.map +1 -1
- package/dist/index.es106.js +2 -503
- package/dist/index.es106.js.map +1 -1
- package/dist/index.es107.js +11 -5
- package/dist/index.es107.js.map +1 -1
- package/dist/index.es108.js +503 -2
- package/dist/index.es108.js.map +1 -1
- package/dist/index.es109.js +5 -146
- package/dist/index.es109.js.map +1 -1
- package/dist/index.es110.js +2 -908
- package/dist/index.es110.js.map +1 -1
- package/dist/index.es111.js +128 -262
- package/dist/index.es111.js.map +1 -1
- package/dist/index.es112.js +907 -3
- package/dist/index.es112.js.map +1 -1
- package/dist/index.es113.js +262 -426
- package/dist/index.es113.js.map +1 -1
- package/dist/index.es114.js +3 -47
- package/dist/index.es114.js.map +1 -1
- package/dist/index.es115.js +443 -21
- package/dist/index.es115.js.map +1 -1
- package/dist/index.es116.js +42 -75
- package/dist/index.es116.js.map +1 -1
- package/dist/index.es117.js +22 -129
- package/dist/index.es117.js.map +1 -1
- package/dist/index.es118.js +74 -44
- package/dist/index.es118.js.map +1 -1
- package/dist/index.es119.js +129 -10
- package/dist/index.es119.js.map +1 -1
- package/dist/index.es12.js +7 -7
- package/dist/index.es12.js.map +1 -1
- package/dist/index.es120.js +47 -43
- package/dist/index.es120.js.map +1 -1
- package/dist/index.es121.js +9 -98
- package/dist/index.es121.js.map +1 -1
- package/dist/index.es122.js +43 -51
- package/dist/index.es122.js.map +1 -1
- package/dist/index.es123.js +96 -13
- package/dist/index.es123.js.map +1 -1
- package/dist/index.es124.js +52 -14
- package/dist/index.es124.js.map +1 -1
- package/dist/index.es125.js +13 -86
- package/dist/index.es125.js.map +1 -1
- package/dist/index.es126.js +15 -2
- package/dist/index.es126.js.map +1 -1
- package/dist/index.es127.js +87 -54
- package/dist/index.es127.js.map +1 -1
- package/dist/index.es128.js +2 -100
- package/dist/index.es128.js.map +1 -1
- package/dist/index.es129.js +51 -186
- package/dist/index.es129.js.map +1 -1
- package/dist/index.es13.js +5 -6
- package/dist/index.es13.js.map +1 -1
- package/dist/index.es130.js +87 -97
- package/dist/index.es130.js.map +1 -1
- package/dist/index.es131.js +187 -31
- package/dist/index.es131.js.map +1 -1
- package/dist/index.es132.js +110 -10
- package/dist/index.es132.js.map +1 -1
- package/dist/index.es133.js +35 -11
- package/dist/index.es133.js.map +1 -1
- package/dist/index.es134.js +10 -12
- package/dist/index.es134.js.map +1 -1
- package/dist/index.es135.js +10 -90
- package/dist/index.es135.js.map +1 -1
- package/dist/index.es136.js +11 -274
- package/dist/index.es136.js.map +1 -1
- package/dist/index.es137.js +91 -2
- package/dist/index.es137.js.map +1 -1
- package/dist/index.es138.js +261 -150
- package/dist/index.es138.js.map +1 -1
- package/dist/index.es139.js +2 -51
- package/dist/index.es139.js.map +1 -1
- package/dist/index.es140.js +158 -34
- package/dist/index.es140.js.map +1 -1
- package/dist/index.es141.js +50 -34
- package/dist/index.es141.js.map +1 -1
- package/dist/index.es142.js +32 -32
- package/dist/index.es142.js.map +1 -1
- package/dist/index.es143.js +34 -23
- package/dist/index.es143.js.map +1 -1
- package/dist/index.es144.js +32 -583
- package/dist/index.es144.js.map +1 -1
- package/dist/index.es145.js +20 -121
- package/dist/index.es145.js.map +1 -1
- package/dist/index.es146.js +585 -158
- package/dist/index.es146.js.map +1 -1
- package/dist/index.es147.js +125 -2
- package/dist/index.es147.js.map +1 -1
- package/dist/index.es148.js +164 -2
- package/dist/index.es148.js.map +1 -1
- package/dist/index.es149.js +2 -2
- package/dist/index.es15.js +15 -15
- package/dist/index.es150.js +2 -22
- package/dist/index.es150.js.map +1 -1
- package/dist/index.es151.js +2 -2
- package/dist/index.es152.js +21 -24
- package/dist/index.es152.js.map +1 -1
- package/dist/index.es153.js +2 -4
- package/dist/index.es153.js.map +1 -1
- package/dist/index.es154.js +25 -5
- package/dist/index.es154.js.map +1 -1
- package/dist/index.es155.js +7 -12
- package/dist/index.es155.js.map +1 -1
- package/dist/index.es156.js +5 -6
- package/dist/index.es156.js.map +1 -1
- package/dist/index.es157.js +12 -7
- package/dist/index.es157.js.map +1 -1
- package/dist/index.es158.js +6 -64
- package/dist/index.es158.js.map +1 -1
- package/dist/index.es159.js +63 -21
- package/dist/index.es159.js.map +1 -1
- package/dist/index.es16.js +2 -2
- package/dist/index.es160.js +21 -5
- package/dist/index.es160.js.map +1 -1
- package/dist/index.es161.js +5 -348
- package/dist/index.es161.js.map +1 -1
- package/dist/index.es162.js +346 -22
- package/dist/index.es162.js.map +1 -1
- package/dist/index.es163.js +25 -12
- package/dist/index.es163.js.map +1 -1
- package/dist/index.es164.js +11 -53
- package/dist/index.es164.js.map +1 -1
- package/dist/index.es165.js +53 -6
- package/dist/index.es165.js.map +1 -1
- package/dist/index.es166.js +7 -103
- package/dist/index.es166.js.map +1 -1
- package/dist/index.es167.js +101 -117
- package/dist/index.es167.js.map +1 -1
- package/dist/index.es168.js +110 -127
- package/dist/index.es168.js.map +1 -1
- package/dist/index.es169.js +128 -107
- package/dist/index.es169.js.map +1 -1
- package/dist/index.es17.js +2 -2
- package/dist/index.es170.js +115 -6
- package/dist/index.es170.js.map +1 -1
- package/dist/index.es171.js +6 -2
- package/dist/index.es171.js.map +1 -1
- package/dist/index.es172.js +3 -141
- package/dist/index.es172.js.map +1 -1
- package/dist/index.es173.js +2 -2
- package/dist/index.es174.js +2 -2
- package/dist/index.es175.js +1 -1
- package/dist/index.es177.js +2 -2
- package/dist/index.es179.js +1 -1
- package/dist/index.es182.js +1 -1
- package/dist/index.es19.js +15 -119
- package/dist/index.es19.js.map +1 -1
- package/dist/index.es190.js +142 -32
- package/dist/index.es190.js.map +1 -1
- package/dist/index.es191.js +2 -6
- package/dist/index.es191.js.map +1 -1
- package/dist/index.es192.js +31 -105
- package/dist/index.es192.js.map +1 -1
- package/dist/index.es193.js +6 -13
- package/dist/index.es193.js.map +1 -1
- package/dist/index.es194.js +105 -17
- package/dist/index.es194.js.map +1 -1
- package/dist/index.es195.js +11 -29
- package/dist/index.es195.js.map +1 -1
- package/dist/index.es196.js +17 -3
- package/dist/index.es196.js.map +1 -1
- package/dist/index.es197.js +30 -4
- package/dist/index.es197.js.map +1 -1
- package/dist/index.es198.js +4 -5
- package/dist/index.es198.js.map +1 -1
- package/dist/index.es199.js +4 -36
- package/dist/index.es199.js.map +1 -1
- package/dist/index.es2.js +2 -2
- package/dist/index.es2.js.map +1 -1
- package/dist/index.es20.js +68 -17
- package/dist/index.es20.js.map +1 -1
- package/dist/index.es200.js +5 -8
- package/dist/index.es200.js.map +1 -1
- package/dist/index.es201.js +36 -5
- package/dist/index.es201.js.map +1 -1
- package/dist/index.es202.js +5 -4
- package/dist/index.es202.js.map +1 -1
- package/dist/index.es203.js +5 -41
- package/dist/index.es203.js.map +1 -1
- package/dist/index.es204.js +4 -10
- package/dist/index.es204.js.map +1 -1
- package/dist/index.es205.js +39 -239
- package/dist/index.es205.js.map +1 -1
- package/dist/index.es206.js +10 -48
- package/dist/index.es206.js.map +1 -1
- package/dist/index.es207.js +239 -32
- package/dist/index.es207.js.map +1 -1
- package/dist/index.es208.js +49 -11
- package/dist/index.es208.js.map +1 -1
- package/dist/index.es209.js +33 -6
- package/dist/index.es209.js.map +1 -1
- package/dist/index.es21.js +36 -67
- package/dist/index.es21.js.map +1 -1
- package/dist/index.es210.js +12 -6
- package/dist/index.es210.js.map +1 -1
- package/dist/index.es211.js +7 -64
- package/dist/index.es211.js.map +1 -1
- package/dist/index.es212.js +6 -40
- package/dist/index.es212.js.map +1 -1
- package/dist/index.es213.js +63 -30
- package/dist/index.es213.js.map +1 -1
- package/dist/index.es214.js +35 -56
- package/dist/index.es214.js.map +1 -1
- package/dist/index.es215.js +32 -15
- package/dist/index.es215.js.map +1 -1
- package/dist/index.es216.js +60 -21
- package/dist/index.es216.js.map +1 -1
- package/dist/index.es217.js +15 -5
- package/dist/index.es217.js.map +1 -1
- package/dist/index.es218.js +21 -15
- package/dist/index.es218.js.map +1 -1
- package/dist/index.es219.js +4 -32
- package/dist/index.es219.js.map +1 -1
- package/dist/index.es22.js +25 -34
- package/dist/index.es22.js.map +1 -1
- package/dist/index.es220.js +16 -4
- package/dist/index.es220.js.map +1 -1
- package/dist/index.es221.js +32 -4
- package/dist/index.es221.js.map +1 -1
- package/dist/index.es222.js +5 -5
- package/dist/index.es222.js.map +1 -1
- package/dist/index.es223.js +4 -7
- package/dist/index.es223.js.map +1 -1
- package/dist/index.es224.js +4 -91
- package/dist/index.es224.js.map +1 -1
- package/dist/index.es225.js +7 -17
- package/dist/index.es225.js.map +1 -1
- package/dist/index.es226.js +90 -760
- package/dist/index.es226.js.map +1 -1
- package/dist/index.es227.js +18 -66
- package/dist/index.es227.js.map +1 -1
- package/dist/index.es228.js +749 -161
- package/dist/index.es228.js.map +1 -1
- package/dist/index.es229.js +66 -38
- package/dist/index.es229.js.map +1 -1
- package/dist/index.es23.js +144 -29
- package/dist/index.es23.js.map +1 -1
- package/dist/index.es230.js +172 -135
- package/dist/index.es230.js.map +1 -1
- package/dist/index.es231.js +37 -92
- package/dist/index.es231.js.map +1 -1
- package/dist/index.es232.js +135 -31
- package/dist/index.es232.js.map +1 -1
- package/dist/index.es233.js +92 -284
- package/dist/index.es233.js.map +1 -1
- package/dist/index.es234.js +31 -24
- package/dist/index.es234.js.map +1 -1
- package/dist/index.es235.js +284 -23
- package/dist/index.es235.js.map +1 -1
- package/dist/index.es236.js +24 -13
- package/dist/index.es236.js.map +1 -1
- package/dist/index.es237.js +22 -13
- package/dist/index.es237.js.map +1 -1
- package/dist/index.es238.js +13 -24
- package/dist/index.es238.js.map +1 -1
- package/dist/index.es239.js +12 -43
- package/dist/index.es239.js.map +1 -1
- package/dist/index.es24.js +291 -133
- package/dist/index.es24.js.map +1 -1
- package/dist/index.es240.js +24 -10
- package/dist/index.es240.js.map +1 -1
- package/dist/index.es241.js +45 -11
- package/dist/index.es241.js.map +1 -1
- package/dist/index.es242.js +10 -10
- package/dist/index.es242.js.map +1 -1
- package/dist/index.es243.js +11 -14
- package/dist/index.es243.js.map +1 -1
- package/dist/index.es244.js +10 -10
- package/dist/index.es244.js.map +1 -1
- package/dist/index.es245.js +14 -11
- package/dist/index.es245.js.map +1 -1
- package/dist/index.es246.js +11 -11
- package/dist/index.es246.js.map +1 -1
- package/dist/index.es247.js +11 -15
- package/dist/index.es247.js.map +1 -1
- package/dist/index.es248.js +11 -11
- package/dist/index.es248.js.map +1 -1
- package/dist/index.es249.js +15 -11
- package/dist/index.es249.js.map +1 -1
- package/dist/index.es25.js +116 -96
- package/dist/index.es25.js.map +1 -1
- package/dist/index.es250.js +11 -11
- package/dist/index.es250.js.map +1 -1
- package/dist/index.es251.js +11 -11
- package/dist/index.es251.js.map +1 -1
- package/dist/index.es252.js +10 -10
- package/dist/index.es252.js.map +1 -1
- package/dist/index.es253.js +10 -10
- package/dist/index.es253.js.map +1 -1
- package/dist/index.es254.js +10 -10
- package/dist/index.es254.js.map +1 -1
- package/dist/index.es255.js +10 -10
- package/dist/index.es255.js.map +1 -1
- package/dist/index.es256.js +11 -56
- package/dist/index.es256.js.map +1 -1
- package/dist/index.es257.js +11 -49
- package/dist/index.es257.js.map +1 -1
- package/dist/index.es258.js +51 -114
- package/dist/index.es258.js.map +1 -1
- package/dist/index.es259.js +43 -378
- package/dist/index.es259.js.map +1 -1
- package/dist/index.es26.js +5 -70
- package/dist/index.es26.js.map +1 -1
- package/dist/index.es260.js +117 -16
- package/dist/index.es260.js.map +1 -1
- package/dist/index.es261.js +384 -11
- package/dist/index.es261.js.map +1 -1
- package/dist/index.es262.js +13 -26
- package/dist/index.es262.js.map +1 -1
- package/dist/index.es263.js +10 -30
- package/dist/index.es263.js.map +1 -1
- package/dist/index.es264.js +25 -56
- package/dist/index.es264.js.map +1 -1
- package/dist/index.es265.js +25 -11
- package/dist/index.es265.js.map +1 -1
- package/dist/index.es266.js +49 -64
- package/dist/index.es266.js.map +1 -1
- package/dist/index.es267.js +17 -11
- package/dist/index.es267.js.map +1 -1
- package/dist/index.es268.js +77 -11
- package/dist/index.es268.js.map +1 -1
- package/dist/index.es269.js +11 -15
- package/dist/index.es269.js.map +1 -1
- package/dist/index.es27.js +91 -168
- package/dist/index.es27.js.map +1 -1
- package/dist/index.es270.js +11 -52
- package/dist/index.es270.js.map +1 -1
- package/dist/index.es271.js +13 -164
- package/dist/index.es271.js.map +1 -1
- package/dist/index.es272.js +53 -2
- package/dist/index.es272.js.map +1 -1
- package/dist/index.es273.js +166 -10
- package/dist/index.es273.js.map +1 -1
- package/dist/index.es274.js +2 -20
- package/dist/index.es274.js.map +1 -1
- package/dist/index.es275.js +10 -38
- package/dist/index.es275.js.map +1 -1
- package/dist/index.es276.js +23 -0
- package/dist/index.es276.js.map +1 -0
- package/dist/index.es277.js +42 -0
- package/dist/index.es277.js.map +1 -0
- package/dist/index.es28.js +68 -24
- package/dist/index.es28.js.map +1 -1
- package/dist/index.es29.js +178 -12
- package/dist/index.es29.js.map +1 -1
- package/dist/index.es30.js +23 -437
- package/dist/index.es30.js.map +1 -1
- package/dist/index.es31.js +13 -15
- package/dist/index.es31.js.map +1 -1
- package/dist/index.es32.js +429 -107
- package/dist/index.es32.js.map +1 -1
- package/dist/index.es33.js +13 -70
- package/dist/index.es33.js.map +1 -1
- package/dist/index.es34.js +119 -19
- package/dist/index.es34.js.map +1 -1
- package/dist/index.es35.js +66 -256
- package/dist/index.es35.js.map +1 -1
- package/dist/index.es36.js +17 -42
- package/dist/index.es36.js.map +1 -1
- package/dist/index.es37.js +239 -193
- package/dist/index.es37.js.map +1 -1
- package/dist/index.es38.js +17 -41
- package/dist/index.es38.js.map +1 -1
- package/dist/index.es39.js +193 -120
- package/dist/index.es39.js.map +1 -1
- package/dist/index.es40.js +60 -17
- package/dist/index.es40.js.map +1 -1
- package/dist/index.es41.js +123 -211
- package/dist/index.es41.js.map +1 -1
- package/dist/index.es42.js +22 -7
- package/dist/index.es42.js.map +1 -1
- package/dist/index.es43.js +214 -1176
- package/dist/index.es43.js.map +1 -1
- package/dist/index.es44.js +10 -8
- package/dist/index.es44.js.map +1 -1
- package/dist/index.es45.js +1182 -137
- package/dist/index.es45.js.map +1 -1
- package/dist/index.es46.js +8 -8
- package/dist/index.es46.js.map +1 -1
- package/dist/index.es47.js +138 -84
- package/dist/index.es47.js.map +1 -1
- package/dist/index.es48.js +8 -4
- package/dist/index.es48.js.map +1 -1
- package/dist/index.es49.js +91 -33
- package/dist/index.es49.js.map +1 -1
- package/dist/index.es50.js +3 -71
- package/dist/index.es50.js.map +1 -1
- package/dist/index.es51.js +34 -36
- package/dist/index.es51.js.map +1 -1
- package/dist/index.es52.js +61 -295
- package/dist/index.es52.js.map +1 -1
- package/dist/index.es53.js +38 -9
- package/dist/index.es53.js.map +1 -1
- package/dist/index.es54.js +296 -81
- package/dist/index.es54.js.map +1 -1
- package/dist/index.es55.js +9 -8
- package/dist/index.es55.js.map +1 -1
- package/dist/index.es56.js +89 -13
- package/dist/index.es56.js.map +1 -1
- package/dist/index.es57.js +6 -141
- package/dist/index.es57.js.map +1 -1
- package/dist/index.es58.js +12 -297
- package/dist/index.es58.js.map +1 -1
- package/dist/index.es59.js +137 -60
- package/dist/index.es59.js.map +1 -1
- package/dist/index.es6.js +21 -5
- package/dist/index.es6.js.map +1 -1
- package/dist/index.es60.js +247 -160
- package/dist/index.es60.js.map +1 -1
- package/dist/index.es61.js +63 -31
- package/dist/index.es61.js.map +1 -1
- package/dist/index.es62.js +212 -8
- package/dist/index.es62.js.map +1 -1
- package/dist/index.es63.js +32 -10
- package/dist/index.es63.js.map +1 -1
- package/dist/index.es64.js +8 -186
- package/dist/index.es64.js.map +1 -1
- package/dist/index.es65.js +11 -23
- package/dist/index.es65.js.map +1 -1
- package/dist/index.es66.js +183 -1396
- package/dist/index.es66.js.map +1 -1
- package/dist/index.es67.js +24 -9
- package/dist/index.es67.js.map +1 -1
- package/dist/index.es68.js +1400 -8
- package/dist/index.es68.js.map +1 -1
- package/dist/index.es69.js +9 -6
- package/dist/index.es69.js.map +1 -1
- package/dist/index.es70.js +8 -163
- package/dist/index.es70.js.map +1 -1
- package/dist/index.es71.js +6 -672
- package/dist/index.es71.js.map +1 -1
- package/dist/index.es72.js +161 -10
- package/dist/index.es72.js.map +1 -1
- package/dist/index.es73.js +671 -39
- package/dist/index.es73.js.map +1 -1
- package/dist/index.es74.js +10 -32
- package/dist/index.es74.js.map +1 -1
- package/dist/index.es75.js +31 -223
- package/dist/index.es75.js.map +1 -1
- package/dist/index.es76.js +33 -29
- package/dist/index.es76.js.map +1 -1
- package/dist/index.es77.js +193 -36
- package/dist/index.es77.js.map +1 -1
- package/dist/index.es78.js +26 -72
- package/dist/index.es78.js.map +1 -1
- package/dist/index.es79.js +70 -47
- package/dist/index.es79.js.map +1 -1
- package/dist/index.es80.js +72 -26
- package/dist/index.es80.js.map +1 -1
- package/dist/index.es81.js +37 -28
- package/dist/index.es81.js.map +1 -1
- package/dist/index.es82.js +28 -55
- package/dist/index.es82.js.map +1 -1
- package/dist/index.es83.js +43 -13
- package/dist/index.es83.js.map +1 -1
- package/dist/index.es84.js +52 -132
- package/dist/index.es84.js.map +1 -1
- package/dist/index.es85.js +13 -21
- package/dist/index.es85.js.map +1 -1
- package/dist/index.es86.js +124 -169
- package/dist/index.es86.js.map +1 -1
- package/dist/index.es87.js +19 -239
- package/dist/index.es87.js.map +1 -1
- package/dist/index.es88.js +165 -338
- package/dist/index.es88.js.map +1 -1
- package/dist/index.es89.js +231 -127
- package/dist/index.es89.js.map +1 -1
- package/dist/index.es90.js +348 -63
- package/dist/index.es90.js.map +1 -1
- package/dist/index.es91.js +133 -33
- package/dist/index.es91.js.map +1 -1
- package/dist/index.es92.js +67 -34
- package/dist/index.es92.js.map +1 -1
- package/dist/index.es93.js +33 -162
- package/dist/index.es93.js.map +1 -1
- package/dist/index.es94.js +34 -200
- package/dist/index.es94.js.map +1 -1
- package/dist/index.es95.js +165 -13
- package/dist/index.es95.js.map +1 -1
- package/dist/index.es96.js +198 -25
- package/dist/index.es96.js.map +1 -1
- package/dist/index.es97.js +13 -33
- package/dist/index.es97.js.map +1 -1
- package/dist/index.es98.js +24 -3151
- package/dist/index.es98.js.map +1 -1
- package/dist/index.es99.js +30 -33
- package/dist/index.es99.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +5 -1
package/dist/index.es43.js
CHANGED
|
@@ -1,1196 +1,234 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (typeof name !== "string") throw new TypeError(`Expected header name to be a string, got ${typeof name}`);
|
|
23
|
-
const values = Array.isArray(item[1]) ? item[1] : [item[1]];
|
|
24
|
-
let didClear = false;
|
|
25
|
-
for (const value of values) {
|
|
26
|
-
if (value === void 0) continue;
|
|
27
|
-
if (shouldClear && !didClear) {
|
|
28
|
-
didClear = true;
|
|
29
|
-
yield [name, null];
|
|
30
|
-
}
|
|
31
|
-
yield [name, value];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
import { isBaseMessage, _isMessageFieldWithRole } from "./index.es37.js";
|
|
2
|
+
import { ToolMessage } from "./index.es41.js";
|
|
3
|
+
import { addLangChainErrorFields } from "./index.es64.js";
|
|
4
|
+
import { _isToolCall } from "./index.es65.js";
|
|
5
|
+
import { parsePartialJson } from "./index.es66.js";
|
|
6
|
+
import { ChatMessage, ChatMessageChunk } from "./index.es52.js";
|
|
7
|
+
import { FunctionMessage, FunctionMessageChunk } from "./index.es53.js";
|
|
8
|
+
import { HumanMessage, HumanMessageChunk } from "./index.es38.js";
|
|
9
|
+
import { RemoveMessage } from "./index.es42.js";
|
|
10
|
+
import { SystemMessage, SystemMessageChunk } from "./index.es40.js";
|
|
11
|
+
import { AIMessage, AIMessageChunk } from "./index.es39.js";
|
|
12
|
+
const iife = (fn) => fn();
|
|
13
|
+
function _coerceToolCall(toolCall) {
|
|
14
|
+
if (_isToolCall(toolCall)) return toolCall;
|
|
15
|
+
else if (typeof toolCall.id === "string" && toolCall.type === "function" && typeof toolCall.function === "object" && toolCall.function !== null && "arguments" in toolCall.function && typeof toolCall.function.arguments === "string" && "name" in toolCall.function && typeof toolCall.function.name === "string") return {
|
|
16
|
+
id: toolCall.id,
|
|
17
|
+
args: JSON.parse(toolCall.function.arguments),
|
|
18
|
+
name: toolCall.function.name,
|
|
19
|
+
type: "tool_call"
|
|
20
|
+
};
|
|
21
|
+
else return toolCall;
|
|
34
22
|
}
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
for (const headers of headerObjects) {
|
|
38
|
-
if (!headers) continue;
|
|
39
|
-
for (const [name, value] of iterateHeaders(headers)) if (value === null) outputHeaders.delete(name);
|
|
40
|
-
else outputHeaders.append(name, value);
|
|
41
|
-
}
|
|
42
|
-
const headerEntries = [];
|
|
43
|
-
outputHeaders.forEach((value, name) => {
|
|
44
|
-
headerEntries.push([name, value]);
|
|
45
|
-
});
|
|
46
|
-
return Object.fromEntries(headerEntries);
|
|
23
|
+
function isSerializedConstructor(x) {
|
|
24
|
+
return typeof x === "object" && x != null && x.lc === 1 && Array.isArray(x.id) && x.kwargs != null && typeof x.kwargs === "object";
|
|
47
25
|
}
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (
|
|
26
|
+
function _constructMessageFromParams(params) {
|
|
27
|
+
let type;
|
|
28
|
+
let rest;
|
|
29
|
+
if (isSerializedConstructor(params)) {
|
|
30
|
+
const className = params.id.at(-1);
|
|
31
|
+
if (className === "HumanMessage" || className === "HumanMessageChunk") type = "user";
|
|
32
|
+
else if (className === "AIMessage" || className === "AIMessageChunk") type = "assistant";
|
|
33
|
+
else if (className === "SystemMessage" || className === "SystemMessageChunk") type = "system";
|
|
34
|
+
else if (className === "FunctionMessage" || className === "FunctionMessageChunk") type = "function";
|
|
35
|
+
else if (className === "ToolMessage" || className === "ToolMessageChunk") type = "tool";
|
|
36
|
+
else type = "unknown";
|
|
37
|
+
rest = params.kwargs;
|
|
38
|
+
} else {
|
|
39
|
+
const { type: extractedType, ...otherParams } = params;
|
|
40
|
+
type = extractedType;
|
|
41
|
+
rest = otherParams;
|
|
42
|
+
}
|
|
43
|
+
if (type === "human" || type === "user") return new HumanMessage(rest);
|
|
44
|
+
else if (type === "ai" || type === "assistant") {
|
|
45
|
+
const { tool_calls: rawToolCalls, ...other } = rest;
|
|
46
|
+
if (!Array.isArray(rawToolCalls)) return new AIMessage(rest);
|
|
47
|
+
const tool_calls = rawToolCalls.map(_coerceToolCall);
|
|
48
|
+
return new AIMessage({
|
|
49
|
+
...other,
|
|
50
|
+
tool_calls
|
|
51
|
+
});
|
|
52
|
+
} else if (type === "system") return new SystemMessage(rest);
|
|
53
|
+
else if (type === "developer") return new SystemMessage({
|
|
54
|
+
...rest,
|
|
55
|
+
additional_kwargs: {
|
|
56
|
+
...rest.additional_kwargs,
|
|
57
|
+
__openai_role__: "developer"
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
else if (type === "tool" && "tool_call_id" in rest) return new ToolMessage({
|
|
61
|
+
...rest,
|
|
62
|
+
content: rest.content,
|
|
63
|
+
tool_call_id: rest.tool_call_id,
|
|
64
|
+
name: rest.name
|
|
65
|
+
});
|
|
66
|
+
else if (type === "remove" && "id" in rest && typeof rest.id === "string") return new RemoveMessage({
|
|
67
|
+
...rest,
|
|
68
|
+
id: rest.id
|
|
69
|
+
});
|
|
70
|
+
else {
|
|
71
|
+
const error = addLangChainErrorFields(/* @__PURE__ */ new Error(`Unable to coerce message from array: only human, AI, system, developer, or tool message coercion is currently supported.
|
|
72
|
+
|
|
73
|
+
Received: ${JSON.stringify(params, null, 2)}`), "MESSAGE_COERCION_FAILURE");
|
|
74
|
+
throw error;
|
|
58
75
|
}
|
|
59
76
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
77
|
+
function coerceMessageLikeToMessage(messageLike) {
|
|
78
|
+
if (typeof messageLike === "string") return new HumanMessage(messageLike);
|
|
79
|
+
else if (isBaseMessage(messageLike)) return messageLike;
|
|
80
|
+
if (Array.isArray(messageLike)) {
|
|
81
|
+
const [type, content] = messageLike;
|
|
82
|
+
return _constructMessageFromParams({
|
|
83
|
+
type,
|
|
84
|
+
content
|
|
85
|
+
});
|
|
86
|
+
} else if (_isMessageFieldWithRole(messageLike)) {
|
|
87
|
+
const { role: type, ...rest } = messageLike;
|
|
88
|
+
return _constructMessageFromParams({
|
|
89
|
+
...rest,
|
|
90
|
+
type
|
|
91
|
+
});
|
|
92
|
+
} else return _constructMessageFromParams(messageLike);
|
|
70
93
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
let
|
|
84
|
-
if (
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (global[fetchSmb]) callerOptions.fetch ??= global[fetchSmb];
|
|
89
|
-
if (global[urlSmb]) defaultApiUrl = global[urlSmb];
|
|
94
|
+
function getBufferString(messages, humanPrefix = "Human", aiPrefix = "AI") {
|
|
95
|
+
const string_messages = [];
|
|
96
|
+
for (const m of messages) {
|
|
97
|
+
let role;
|
|
98
|
+
if (m.type === "human") role = humanPrefix;
|
|
99
|
+
else if (m.type === "ai") role = aiPrefix;
|
|
100
|
+
else if (m.type === "system") role = "System";
|
|
101
|
+
else if (m.type === "tool") role = "Tool";
|
|
102
|
+
else if (m.type === "generic") role = m.role;
|
|
103
|
+
else throw new Error(`Got unsupported message type: ${m.type}`);
|
|
104
|
+
const nameStr = m.name ? `${m.name}, ` : "";
|
|
105
|
+
const readableContent = m.text;
|
|
106
|
+
let message = `${role}: ${nameStr}${readableContent}`;
|
|
107
|
+
if (m.type === "ai") {
|
|
108
|
+
const aiMessage = m;
|
|
109
|
+
if (aiMessage.tool_calls && aiMessage.tool_calls.length > 0) message += JSON.stringify(aiMessage.tool_calls);
|
|
110
|
+
else if (aiMessage.additional_kwargs && "function_call" in aiMessage.additional_kwargs) message += JSON.stringify(aiMessage.additional_kwargs.function_call);
|
|
90
111
|
}
|
|
91
|
-
|
|
92
|
-
this.timeoutMs = config?.timeoutMs;
|
|
93
|
-
this.apiUrl = config?.apiUrl?.replace(/\/$/, "") || defaultApiUrl;
|
|
94
|
-
this.defaultHeaders = config?.defaultHeaders || {};
|
|
95
|
-
this.onRequest = config?.onRequest;
|
|
96
|
-
const apiKey = getApiKey(config?.apiKey);
|
|
97
|
-
if (apiKey) this.defaultHeaders["x-api-key"] = apiKey;
|
|
112
|
+
string_messages.push(message);
|
|
98
113
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (options.timeoutMs != null) timeoutSignal = AbortSignal.timeout(options.timeoutMs);
|
|
113
|
-
} else if (this.timeoutMs != null) timeoutSignal = AbortSignal.timeout(this.timeoutMs);
|
|
114
|
-
mutatedOptions.signal = mergeSignals(timeoutSignal, mutatedOptions.signal);
|
|
115
|
-
const targetUrl = new URL(`${this.apiUrl}${path}`);
|
|
116
|
-
if (mutatedOptions.params) {
|
|
117
|
-
for (const [key, value] of Object.entries(mutatedOptions.params)) {
|
|
118
|
-
if (value == null) continue;
|
|
119
|
-
const strValue = typeof value === "string" || typeof value === "number" ? value.toString() : JSON.stringify(value);
|
|
120
|
-
targetUrl.searchParams.append(key, strValue);
|
|
114
|
+
return string_messages.join("\n");
|
|
115
|
+
}
|
|
116
|
+
function mapV1MessageToStoredMessage(message) {
|
|
117
|
+
if (message.data !== void 0) return message;
|
|
118
|
+
else {
|
|
119
|
+
const v1Message = message;
|
|
120
|
+
return {
|
|
121
|
+
type: v1Message.type,
|
|
122
|
+
data: {
|
|
123
|
+
content: v1Message.text,
|
|
124
|
+
role: v1Message.role,
|
|
125
|
+
name: void 0,
|
|
126
|
+
tool_call_id: void 0
|
|
121
127
|
}
|
|
122
|
-
delete mutatedOptions.params;
|
|
123
|
-
}
|
|
124
|
-
return [targetUrl, mutatedOptions];
|
|
125
|
-
}
|
|
126
|
-
async fetch(path, options) {
|
|
127
|
-
const [url, init] = this.prepareFetchOptions(path, options);
|
|
128
|
-
let finalInit = init;
|
|
129
|
-
if (this.onRequest) finalInit = await this.onRequest(url, init);
|
|
130
|
-
const response = await this.asyncCaller.fetch(url, finalInit);
|
|
131
|
-
const body = (() => {
|
|
132
|
-
if (response.status === 202 || response.status === 204) return;
|
|
133
|
-
return response.json();
|
|
134
|
-
})();
|
|
135
|
-
if (options?.withResponse) return [await body, response];
|
|
136
|
-
return body;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Protected helper for streaming with automatic retry logic.
|
|
140
|
-
* Handles both initial requests and reconnections with SSE.
|
|
141
|
-
*/
|
|
142
|
-
async *streamWithRetry(config) {
|
|
143
|
-
const makeRequest = async (reconnectParams) => {
|
|
144
|
-
const requestEndpoint = reconnectParams?.reconnectPath || config.endpoint;
|
|
145
|
-
const isReconnect = !!reconnectParams?.reconnectPath;
|
|
146
|
-
const method = isReconnect ? "GET" : config.method || "GET";
|
|
147
|
-
const requestHeaders = isReconnect && reconnectParams?.lastEventId ? {
|
|
148
|
-
...config.headers,
|
|
149
|
-
"Last-Event-ID": reconnectParams.lastEventId
|
|
150
|
-
} : config.headers;
|
|
151
|
-
let [url, init] = this.prepareFetchOptions(requestEndpoint, {
|
|
152
|
-
method,
|
|
153
|
-
timeoutMs: null,
|
|
154
|
-
signal: config.signal,
|
|
155
|
-
headers: requestHeaders,
|
|
156
|
-
params: config.params,
|
|
157
|
-
json: isReconnect ? void 0 : config.json
|
|
158
|
-
});
|
|
159
|
-
if (this.onRequest != null) init = await this.onRequest(url, init);
|
|
160
|
-
const response = await this.asyncCaller.fetch(url, init);
|
|
161
|
-
if (!isReconnect && config.onInitialResponse) await config.onInitialResponse(response);
|
|
162
|
-
return {
|
|
163
|
-
response,
|
|
164
|
-
stream: (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(BytesLineDecoder()).pipeThrough(SSEDecoder())
|
|
165
|
-
};
|
|
166
|
-
};
|
|
167
|
-
yield* streamWithRetry(makeRequest, {
|
|
168
|
-
maxRetries: config.maxRetries ?? 5,
|
|
169
|
-
signal: config.signal,
|
|
170
|
-
onReconnect: config.onReconnect
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
var CronsClient = class extends BaseClient {
|
|
175
|
-
/**
|
|
176
|
-
*
|
|
177
|
-
* @param threadId The ID of the thread.
|
|
178
|
-
* @param assistantId Assistant ID to use for this cron job.
|
|
179
|
-
* @param payload Payload for creating a cron job.
|
|
180
|
-
* @returns The created background run.
|
|
181
|
-
*/
|
|
182
|
-
async createForThread(threadId, assistantId, payload) {
|
|
183
|
-
const json = {
|
|
184
|
-
schedule: payload?.schedule,
|
|
185
|
-
input: payload?.input,
|
|
186
|
-
config: payload?.config,
|
|
187
|
-
context: payload?.context,
|
|
188
|
-
metadata: payload?.metadata,
|
|
189
|
-
assistant_id: assistantId,
|
|
190
|
-
interrupt_before: payload?.interruptBefore,
|
|
191
|
-
interrupt_after: payload?.interruptAfter,
|
|
192
|
-
webhook: payload?.webhook,
|
|
193
|
-
multitask_strategy: payload?.multitaskStrategy,
|
|
194
|
-
if_not_exists: payload?.ifNotExists,
|
|
195
|
-
checkpoint_during: payload?.checkpointDuring,
|
|
196
|
-
durability: payload?.durability
|
|
197
|
-
};
|
|
198
|
-
return this.fetch(`/threads/${threadId}/runs/crons`, {
|
|
199
|
-
method: "POST",
|
|
200
|
-
json,
|
|
201
|
-
signal: payload?.signal
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
*
|
|
206
|
-
* @param assistantId Assistant ID to use for this cron job.
|
|
207
|
-
* @param payload Payload for creating a cron job.
|
|
208
|
-
* @returns
|
|
209
|
-
*/
|
|
210
|
-
async create(assistantId, payload) {
|
|
211
|
-
const json = {
|
|
212
|
-
schedule: payload?.schedule,
|
|
213
|
-
input: payload?.input,
|
|
214
|
-
config: payload?.config,
|
|
215
|
-
context: payload?.context,
|
|
216
|
-
metadata: payload?.metadata,
|
|
217
|
-
assistant_id: assistantId,
|
|
218
|
-
interrupt_before: payload?.interruptBefore,
|
|
219
|
-
interrupt_after: payload?.interruptAfter,
|
|
220
|
-
webhook: payload?.webhook,
|
|
221
|
-
on_run_completed: payload?.onRunCompleted,
|
|
222
|
-
multitask_strategy: payload?.multitaskStrategy,
|
|
223
|
-
if_not_exists: payload?.ifNotExists,
|
|
224
|
-
checkpoint_during: payload?.checkpointDuring,
|
|
225
|
-
durability: payload?.durability
|
|
226
128
|
};
|
|
227
|
-
return this.fetch(`/runs/crons`, {
|
|
228
|
-
method: "POST",
|
|
229
|
-
json,
|
|
230
|
-
signal: payload?.signal
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
*
|
|
235
|
-
* @param cronId Cron ID of Cron job to delete.
|
|
236
|
-
*/
|
|
237
|
-
async delete(cronId, options) {
|
|
238
|
-
await this.fetch(`/runs/crons/${cronId}`, {
|
|
239
|
-
method: "DELETE",
|
|
240
|
-
signal: options?.signal
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
*
|
|
245
|
-
* @param query Query options.
|
|
246
|
-
* @returns List of crons.
|
|
247
|
-
*/
|
|
248
|
-
async search(query) {
|
|
249
|
-
return this.fetch("/runs/crons/search", {
|
|
250
|
-
method: "POST",
|
|
251
|
-
json: {
|
|
252
|
-
assistant_id: query?.assistantId ?? void 0,
|
|
253
|
-
thread_id: query?.threadId ?? void 0,
|
|
254
|
-
limit: query?.limit ?? 10,
|
|
255
|
-
offset: query?.offset ?? 0,
|
|
256
|
-
sort_by: query?.sortBy ?? void 0,
|
|
257
|
-
sort_order: query?.sortOrder ?? void 0,
|
|
258
|
-
select: query?.select ?? void 0
|
|
259
|
-
},
|
|
260
|
-
signal: query?.signal
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Count cron jobs matching filters.
|
|
265
|
-
*
|
|
266
|
-
* @param query.assistantId Assistant ID to filter by.
|
|
267
|
-
* @param query.threadId Thread ID to filter by.
|
|
268
|
-
* @returns Number of cron jobs matching the criteria.
|
|
269
|
-
*/
|
|
270
|
-
async count(query) {
|
|
271
|
-
return this.fetch(`/runs/crons/count`, {
|
|
272
|
-
method: "POST",
|
|
273
|
-
json: {
|
|
274
|
-
assistant_id: query?.assistantId ?? void 0,
|
|
275
|
-
thread_id: query?.threadId ?? void 0
|
|
276
|
-
},
|
|
277
|
-
signal: query?.signal
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
var AssistantsClient = class extends BaseClient {
|
|
282
|
-
/**
|
|
283
|
-
* Get an assistant by ID.
|
|
284
|
-
*
|
|
285
|
-
* @param assistantId The ID of the assistant.
|
|
286
|
-
* @returns Assistant
|
|
287
|
-
*/
|
|
288
|
-
async get(assistantId, options) {
|
|
289
|
-
return this.fetch(`/assistants/${assistantId}`, { signal: options?.signal });
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Get the JSON representation of the graph assigned to a runnable
|
|
293
|
-
* @param assistantId The ID of the assistant.
|
|
294
|
-
* @param options.xray Whether to include subgraphs in the serialized graph representation. If an integer value is provided, only subgraphs with a depth less than or equal to the value will be included.
|
|
295
|
-
* @returns Serialized graph
|
|
296
|
-
*/
|
|
297
|
-
async getGraph(assistantId, options) {
|
|
298
|
-
return this.fetch(`/assistants/${assistantId}/graph`, {
|
|
299
|
-
params: { xray: options?.xray },
|
|
300
|
-
signal: options?.signal
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Get the state and config schema of the graph assigned to a runnable
|
|
305
|
-
* @param assistantId The ID of the assistant.
|
|
306
|
-
* @returns Graph schema
|
|
307
|
-
*/
|
|
308
|
-
async getSchemas(assistantId, options) {
|
|
309
|
-
return this.fetch(`/assistants/${assistantId}/schemas`, { signal: options?.signal });
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Get the schemas of an assistant by ID.
|
|
313
|
-
*
|
|
314
|
-
* @param assistantId The ID of the assistant to get the schema of.
|
|
315
|
-
* @param options Additional options for getting subgraphs, such as namespace or recursion extraction.
|
|
316
|
-
* @returns The subgraphs of the assistant.
|
|
317
|
-
*/
|
|
318
|
-
async getSubgraphs(assistantId, options) {
|
|
319
|
-
if (options?.namespace) return this.fetch(`/assistants/${assistantId}/subgraphs/${options.namespace}`, {
|
|
320
|
-
params: { recurse: options?.recurse },
|
|
321
|
-
signal: options?.signal
|
|
322
|
-
});
|
|
323
|
-
return this.fetch(`/assistants/${assistantId}/subgraphs`, {
|
|
324
|
-
params: { recurse: options?.recurse },
|
|
325
|
-
signal: options?.signal
|
|
326
|
-
});
|
|
327
129
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Update an assistant.
|
|
351
|
-
* @param assistantId ID of the assistant.
|
|
352
|
-
* @param payload Payload for updating the assistant.
|
|
353
|
-
* @returns The updated assistant.
|
|
354
|
-
*/
|
|
355
|
-
async update(assistantId, payload) {
|
|
356
|
-
return this.fetch(`/assistants/${assistantId}`, {
|
|
357
|
-
method: "PATCH",
|
|
358
|
-
json: {
|
|
359
|
-
graph_id: payload.graphId,
|
|
360
|
-
config: payload.config,
|
|
361
|
-
context: payload.context,
|
|
362
|
-
metadata: payload.metadata,
|
|
363
|
-
name: payload.name,
|
|
364
|
-
description: payload.description
|
|
365
|
-
},
|
|
366
|
-
signal: payload.signal
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Delete an assistant.
|
|
371
|
-
*
|
|
372
|
-
* @param assistantId ID of the assistant.
|
|
373
|
-
* @param deleteThreads If true, delete all threads with `metadata.assistant_id` equal to `assistantId`. Defaults to false.
|
|
374
|
-
*/
|
|
375
|
-
async delete(assistantId, options) {
|
|
376
|
-
return this.fetch(`/assistants/${assistantId}?delete_threads=${options?.deleteThreads ?? false}`, {
|
|
377
|
-
method: "DELETE",
|
|
378
|
-
signal: options?.signal
|
|
379
|
-
});
|
|
130
|
+
}
|
|
131
|
+
function mapStoredMessageToChatMessage(message) {
|
|
132
|
+
const storedMessage = mapV1MessageToStoredMessage(message);
|
|
133
|
+
switch (storedMessage.type) {
|
|
134
|
+
case "human":
|
|
135
|
+
return new HumanMessage(storedMessage.data);
|
|
136
|
+
case "ai":
|
|
137
|
+
return new AIMessage(storedMessage.data);
|
|
138
|
+
case "system":
|
|
139
|
+
return new SystemMessage(storedMessage.data);
|
|
140
|
+
case "function":
|
|
141
|
+
if (storedMessage.data.name === void 0) throw new Error("Name must be defined for function messages");
|
|
142
|
+
return new FunctionMessage(storedMessage.data);
|
|
143
|
+
case "tool":
|
|
144
|
+
if (storedMessage.data.tool_call_id === void 0) throw new Error("Tool call ID must be defined for tool messages");
|
|
145
|
+
return new ToolMessage(storedMessage.data);
|
|
146
|
+
case "generic":
|
|
147
|
+
if (storedMessage.data.role === void 0) throw new Error("Role must be defined for chat messages");
|
|
148
|
+
return new ChatMessage(storedMessage.data);
|
|
149
|
+
default:
|
|
150
|
+
throw new Error(`Got unexpected type: ${storedMessage.type}`);
|
|
380
151
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
152
|
+
}
|
|
153
|
+
function mapStoredMessagesToChatMessages(messages) {
|
|
154
|
+
return messages.map(mapStoredMessageToChatMessage);
|
|
155
|
+
}
|
|
156
|
+
function mapChatMessagesToStoredMessages(messages) {
|
|
157
|
+
return messages.map((message) => message.toDict());
|
|
158
|
+
}
|
|
159
|
+
function convertToChunk(message) {
|
|
160
|
+
const type = message._getType();
|
|
161
|
+
if (type === "human") return new HumanMessageChunk({ ...message });
|
|
162
|
+
else if (type === "ai") {
|
|
163
|
+
let aiChunkFields = { ...message };
|
|
164
|
+
if ("tool_calls" in aiChunkFields) aiChunkFields = {
|
|
165
|
+
...aiChunkFields,
|
|
166
|
+
tool_call_chunks: aiChunkFields.tool_calls?.map((tc) => ({
|
|
167
|
+
...tc,
|
|
168
|
+
type: "tool_call_chunk",
|
|
169
|
+
index: void 0,
|
|
170
|
+
args: JSON.stringify(tc.args)
|
|
171
|
+
}))
|
|
401
172
|
};
|
|
402
|
-
return
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
},
|
|
437
|
-
signal: payload?.signal
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Change the version of an assistant.
|
|
442
|
-
*
|
|
443
|
-
* @param assistantId ID of the assistant.
|
|
444
|
-
* @param version The version to change to.
|
|
445
|
-
* @returns The updated assistant.
|
|
446
|
-
*/
|
|
447
|
-
async setLatest(assistantId, version, options) {
|
|
448
|
-
return this.fetch(`/assistants/${assistantId}/latest`, {
|
|
449
|
-
method: "POST",
|
|
450
|
-
json: { version },
|
|
451
|
-
signal: options?.signal
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
var ThreadsClient = class extends BaseClient {
|
|
456
|
-
/**
|
|
457
|
-
* Get a thread by ID.
|
|
458
|
-
*
|
|
459
|
-
* @param threadId ID of the thread.
|
|
460
|
-
* @returns The thread.
|
|
461
|
-
*/
|
|
462
|
-
async get(threadId, options) {
|
|
463
|
-
return this.fetch(`/threads/${threadId}`, { signal: options?.signal });
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Create a new thread.
|
|
467
|
-
*
|
|
468
|
-
* @param payload Payload for creating a thread.
|
|
469
|
-
* @returns The created thread.
|
|
470
|
-
*/
|
|
471
|
-
async create(payload) {
|
|
472
|
-
const ttlPayload = typeof payload?.ttl === "number" ? {
|
|
473
|
-
ttl: payload.ttl,
|
|
474
|
-
strategy: "delete"
|
|
475
|
-
} : payload?.ttl;
|
|
476
|
-
return this.fetch(`/threads`, {
|
|
477
|
-
method: "POST",
|
|
478
|
-
json: {
|
|
479
|
-
metadata: {
|
|
480
|
-
...payload?.metadata,
|
|
481
|
-
graph_id: payload?.graphId
|
|
482
|
-
},
|
|
483
|
-
thread_id: payload?.threadId,
|
|
484
|
-
if_exists: payload?.ifExists,
|
|
485
|
-
supersteps: payload?.supersteps?.map((s) => ({ updates: s.updates.map((u) => ({
|
|
486
|
-
values: u.values,
|
|
487
|
-
command: u.command,
|
|
488
|
-
as_node: u.asNode
|
|
489
|
-
})) })),
|
|
490
|
-
ttl: ttlPayload
|
|
491
|
-
},
|
|
492
|
-
signal: payload?.signal
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
/**
|
|
496
|
-
* Copy an existing thread
|
|
497
|
-
* @param threadId ID of the thread to be copied
|
|
498
|
-
* @returns Newly copied thread
|
|
499
|
-
*/
|
|
500
|
-
async copy(threadId, options) {
|
|
501
|
-
return this.fetch(`/threads/${threadId}/copy`, {
|
|
502
|
-
method: "POST",
|
|
503
|
-
signal: options?.signal
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
/**
|
|
507
|
-
* Update a thread.
|
|
508
|
-
*
|
|
509
|
-
* @param threadId ID of the thread.
|
|
510
|
-
* @param payload Payload for updating the thread.
|
|
511
|
-
* @returns The updated thread.
|
|
512
|
-
*/
|
|
513
|
-
async update(threadId, payload) {
|
|
514
|
-
const ttlPayload = typeof payload?.ttl === "number" ? {
|
|
515
|
-
ttl: payload.ttl,
|
|
516
|
-
strategy: "delete"
|
|
517
|
-
} : payload?.ttl;
|
|
518
|
-
return this.fetch(`/threads/${threadId}`, {
|
|
519
|
-
method: "PATCH",
|
|
520
|
-
json: {
|
|
521
|
-
metadata: payload?.metadata,
|
|
522
|
-
ttl: ttlPayload
|
|
523
|
-
},
|
|
524
|
-
signal: payload?.signal
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
* Delete a thread.
|
|
529
|
-
*
|
|
530
|
-
* @param threadId ID of the thread.
|
|
531
|
-
*/
|
|
532
|
-
async delete(threadId, options) {
|
|
533
|
-
return this.fetch(`/threads/${threadId}`, {
|
|
534
|
-
method: "DELETE",
|
|
535
|
-
signal: options?.signal
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* List threads
|
|
540
|
-
*
|
|
541
|
-
* @param query Query options
|
|
542
|
-
* @returns List of threads
|
|
543
|
-
*/
|
|
544
|
-
async search(query) {
|
|
545
|
-
return this.fetch("/threads/search", {
|
|
546
|
-
method: "POST",
|
|
547
|
-
json: {
|
|
548
|
-
metadata: query?.metadata ?? void 0,
|
|
549
|
-
ids: query?.ids ?? void 0,
|
|
550
|
-
limit: query?.limit ?? 10,
|
|
551
|
-
offset: query?.offset ?? 0,
|
|
552
|
-
status: query?.status,
|
|
553
|
-
sort_by: query?.sortBy,
|
|
554
|
-
sort_order: query?.sortOrder,
|
|
555
|
-
select: query?.select ?? void 0,
|
|
556
|
-
values: query?.values ?? void 0
|
|
557
|
-
},
|
|
558
|
-
signal: query?.signal
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* Count threads matching filters.
|
|
563
|
-
*
|
|
564
|
-
* @param query.metadata Thread metadata to filter on.
|
|
565
|
-
* @param query.values State values to filter on.
|
|
566
|
-
* @param query.status Thread status to filter on.
|
|
567
|
-
* @returns Number of threads matching the criteria.
|
|
568
|
-
*/
|
|
569
|
-
async count(query) {
|
|
570
|
-
return this.fetch(`/threads/count`, {
|
|
571
|
-
method: "POST",
|
|
572
|
-
json: {
|
|
573
|
-
metadata: query?.metadata ?? void 0,
|
|
574
|
-
values: query?.values ?? void 0,
|
|
575
|
-
status: query?.status ?? void 0
|
|
576
|
-
},
|
|
577
|
-
signal: query?.signal
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
/**
|
|
581
|
-
* Get state for a thread.
|
|
582
|
-
*
|
|
583
|
-
* @param threadId ID of the thread.
|
|
584
|
-
* @returns Thread state.
|
|
585
|
-
*/
|
|
586
|
-
async getState(threadId, checkpoint, options) {
|
|
587
|
-
if (checkpoint != null) {
|
|
588
|
-
if (typeof checkpoint !== "string") return this.fetch(`/threads/${threadId}/state/checkpoint`, {
|
|
589
|
-
method: "POST",
|
|
590
|
-
json: {
|
|
591
|
-
checkpoint,
|
|
592
|
-
subgraphs: options?.subgraphs
|
|
593
|
-
},
|
|
594
|
-
signal: options?.signal
|
|
173
|
+
return new AIMessageChunk({ ...aiChunkFields });
|
|
174
|
+
} else if (type === "system") return new SystemMessageChunk({ ...message });
|
|
175
|
+
else if (type === "function") return new FunctionMessageChunk({ ...message });
|
|
176
|
+
else if (ChatMessage.isInstance(message)) return new ChatMessageChunk({ ...message });
|
|
177
|
+
else throw new Error("Unknown message type.");
|
|
178
|
+
}
|
|
179
|
+
function collapseToolCallChunks(chunks) {
|
|
180
|
+
const groupedToolCallChunks = chunks.reduce((acc, chunk) => {
|
|
181
|
+
const matchedChunkIndex = acc.findIndex(([match]) => {
|
|
182
|
+
if ("id" in chunk && chunk.id && "index" in chunk && chunk.index !== void 0) return chunk.id === match.id && chunk.index === match.index;
|
|
183
|
+
if ("id" in chunk && chunk.id) return chunk.id === match.id;
|
|
184
|
+
if ("index" in chunk && chunk.index !== void 0) return chunk.index === match.index;
|
|
185
|
+
return false;
|
|
186
|
+
});
|
|
187
|
+
if (matchedChunkIndex !== -1) acc[matchedChunkIndex].push(chunk);
|
|
188
|
+
else acc.push([chunk]);
|
|
189
|
+
return acc;
|
|
190
|
+
}, []);
|
|
191
|
+
const toolCalls = [];
|
|
192
|
+
const invalidToolCalls = [];
|
|
193
|
+
for (const chunks$1 of groupedToolCallChunks) {
|
|
194
|
+
let parsedArgs = null;
|
|
195
|
+
const name = chunks$1[0]?.name ?? "";
|
|
196
|
+
const joinedArgs = chunks$1.map((c) => c.args || "").join("").trim();
|
|
197
|
+
const argsStr = joinedArgs.length ? joinedArgs : "{}";
|
|
198
|
+
const id = chunks$1[0]?.id;
|
|
199
|
+
try {
|
|
200
|
+
parsedArgs = parsePartialJson(argsStr);
|
|
201
|
+
if (!id || parsedArgs === null || typeof parsedArgs !== "object" || Array.isArray(parsedArgs)) throw new Error("Malformed tool call chunk args.");
|
|
202
|
+
toolCalls.push({
|
|
203
|
+
name,
|
|
204
|
+
args: parsedArgs,
|
|
205
|
+
id,
|
|
206
|
+
type: "tool_call"
|
|
595
207
|
});
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
208
|
+
} catch {
|
|
209
|
+
invalidToolCalls.push({
|
|
210
|
+
name,
|
|
211
|
+
args: argsStr,
|
|
212
|
+
id,
|
|
213
|
+
error: "Malformed args.",
|
|
214
|
+
type: "invalid_tool_call"
|
|
599
215
|
});
|
|
600
216
|
}
|
|
601
|
-
return this.fetch(`/threads/${threadId}/state`, {
|
|
602
|
-
params: { subgraphs: options?.subgraphs },
|
|
603
|
-
signal: options?.signal
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* Add state to a thread.
|
|
608
|
-
*
|
|
609
|
-
* @param threadId The ID of the thread.
|
|
610
|
-
* @returns
|
|
611
|
-
*/
|
|
612
|
-
async updateState(threadId, options) {
|
|
613
|
-
return this.fetch(`/threads/${threadId}/state`, {
|
|
614
|
-
method: "POST",
|
|
615
|
-
json: {
|
|
616
|
-
values: options.values,
|
|
617
|
-
checkpoint_id: options.checkpointId,
|
|
618
|
-
checkpoint: options.checkpoint,
|
|
619
|
-
as_node: options?.asNode
|
|
620
|
-
},
|
|
621
|
-
signal: options?.signal
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
* Patch the metadata of a thread.
|
|
626
|
-
*
|
|
627
|
-
* @param threadIdOrConfig Thread ID or config to patch the state of.
|
|
628
|
-
* @param metadata Metadata to patch the state with.
|
|
629
|
-
*/
|
|
630
|
-
async patchState(threadIdOrConfig, metadata, options) {
|
|
631
|
-
let threadId;
|
|
632
|
-
if (typeof threadIdOrConfig !== "string") {
|
|
633
|
-
if (typeof threadIdOrConfig.configurable?.thread_id !== "string") throw new Error("Thread ID is required when updating state with a config.");
|
|
634
|
-
threadId = threadIdOrConfig.configurable.thread_id;
|
|
635
|
-
} else threadId = threadIdOrConfig;
|
|
636
|
-
return this.fetch(`/threads/${threadId}/state`, {
|
|
637
|
-
method: "PATCH",
|
|
638
|
-
json: { metadata },
|
|
639
|
-
signal: options?.signal
|
|
640
|
-
});
|
|
641
|
-
}
|
|
642
|
-
/**
|
|
643
|
-
* Get all past states for a thread.
|
|
644
|
-
*
|
|
645
|
-
* @param threadId ID of the thread.
|
|
646
|
-
* @param options Additional options.
|
|
647
|
-
* @returns List of thread states.
|
|
648
|
-
*/
|
|
649
|
-
async getHistory(threadId, options) {
|
|
650
|
-
return this.fetch(`/threads/${threadId}/history`, {
|
|
651
|
-
method: "POST",
|
|
652
|
-
json: {
|
|
653
|
-
limit: options?.limit ?? 10,
|
|
654
|
-
before: options?.before,
|
|
655
|
-
metadata: options?.metadata,
|
|
656
|
-
checkpoint: options?.checkpoint
|
|
657
|
-
},
|
|
658
|
-
signal: options?.signal
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
|
-
async *joinStream(threadId, options) {
|
|
662
|
-
yield* this.streamWithRetry({
|
|
663
|
-
endpoint: `/threads/${threadId}/stream`,
|
|
664
|
-
method: "GET",
|
|
665
|
-
signal: options?.signal,
|
|
666
|
-
headers: options?.lastEventId ? { "Last-Event-ID": options.lastEventId } : void 0,
|
|
667
|
-
params: options?.streamMode ? { stream_mode: options.streamMode } : void 0
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
};
|
|
671
|
-
var RunsClient = class extends BaseClient {
|
|
672
|
-
/**
|
|
673
|
-
* Create a run and stream the results.
|
|
674
|
-
*
|
|
675
|
-
* @param threadId The ID of the thread.
|
|
676
|
-
* @param assistantId Assistant ID to use for this run.
|
|
677
|
-
* @param payload Payload for creating a run.
|
|
678
|
-
*/
|
|
679
|
-
async *stream(threadId, assistantId, payload) {
|
|
680
|
-
const json = {
|
|
681
|
-
input: payload?.input,
|
|
682
|
-
command: payload?.command,
|
|
683
|
-
config: payload?.config,
|
|
684
|
-
context: payload?.context,
|
|
685
|
-
metadata: payload?.metadata,
|
|
686
|
-
stream_mode: payload?.streamMode,
|
|
687
|
-
stream_subgraphs: payload?.streamSubgraphs,
|
|
688
|
-
stream_resumable: payload?.streamResumable,
|
|
689
|
-
feedback_keys: payload?.feedbackKeys,
|
|
690
|
-
assistant_id: assistantId,
|
|
691
|
-
interrupt_before: payload?.interruptBefore,
|
|
692
|
-
interrupt_after: payload?.interruptAfter,
|
|
693
|
-
checkpoint: payload?.checkpoint,
|
|
694
|
-
checkpoint_id: payload?.checkpointId,
|
|
695
|
-
webhook: payload?.webhook,
|
|
696
|
-
multitask_strategy: payload?.multitaskStrategy,
|
|
697
|
-
on_completion: payload?.onCompletion,
|
|
698
|
-
on_disconnect: payload?.onDisconnect,
|
|
699
|
-
after_seconds: payload?.afterSeconds,
|
|
700
|
-
if_not_exists: payload?.ifNotExists,
|
|
701
|
-
checkpoint_during: payload?.checkpointDuring,
|
|
702
|
-
durability: payload?.durability
|
|
703
|
-
};
|
|
704
|
-
yield* this.streamWithRetry({
|
|
705
|
-
endpoint: threadId == null ? `/runs/stream` : `/threads/${threadId}/runs/stream`,
|
|
706
|
-
method: "POST",
|
|
707
|
-
json,
|
|
708
|
-
signal: payload?.signal,
|
|
709
|
-
onInitialResponse: (response) => {
|
|
710
|
-
const runMetadata = getRunMetadataFromResponse(response);
|
|
711
|
-
if (runMetadata) payload?.onRunCreated?.(runMetadata);
|
|
712
|
-
}
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
/**
|
|
716
|
-
* Create a run.
|
|
717
|
-
*
|
|
718
|
-
* @param threadId The ID of the thread.
|
|
719
|
-
* @param assistantId Assistant ID to use for this run.
|
|
720
|
-
* @param payload Payload for creating a run.
|
|
721
|
-
* @returns The created run.
|
|
722
|
-
*/
|
|
723
|
-
async create(threadId, assistantId, payload) {
|
|
724
|
-
const json = {
|
|
725
|
-
input: payload?.input,
|
|
726
|
-
command: payload?.command,
|
|
727
|
-
config: payload?.config,
|
|
728
|
-
context: payload?.context,
|
|
729
|
-
metadata: payload?.metadata,
|
|
730
|
-
stream_mode: payload?.streamMode,
|
|
731
|
-
stream_subgraphs: payload?.streamSubgraphs,
|
|
732
|
-
stream_resumable: payload?.streamResumable,
|
|
733
|
-
assistant_id: assistantId,
|
|
734
|
-
interrupt_before: payload?.interruptBefore,
|
|
735
|
-
interrupt_after: payload?.interruptAfter,
|
|
736
|
-
webhook: payload?.webhook,
|
|
737
|
-
checkpoint: payload?.checkpoint,
|
|
738
|
-
checkpoint_id: payload?.checkpointId,
|
|
739
|
-
multitask_strategy: payload?.multitaskStrategy,
|
|
740
|
-
after_seconds: payload?.afterSeconds,
|
|
741
|
-
if_not_exists: payload?.ifNotExists,
|
|
742
|
-
checkpoint_during: payload?.checkpointDuring,
|
|
743
|
-
durability: payload?.durability,
|
|
744
|
-
langsmith_tracer: payload?._langsmithTracer ? {
|
|
745
|
-
project_name: payload?._langsmithTracer?.projectName,
|
|
746
|
-
example_id: payload?._langsmithTracer?.exampleId
|
|
747
|
-
} : void 0
|
|
748
|
-
};
|
|
749
|
-
const endpoint = threadId === null ? "/runs" : `/threads/${threadId}/runs`;
|
|
750
|
-
const [run, response] = await this.fetch(endpoint, {
|
|
751
|
-
method: "POST",
|
|
752
|
-
json,
|
|
753
|
-
signal: payload?.signal,
|
|
754
|
-
withResponse: true
|
|
755
|
-
});
|
|
756
|
-
const runMetadata = getRunMetadataFromResponse(response);
|
|
757
|
-
if (runMetadata) payload?.onRunCreated?.(runMetadata);
|
|
758
|
-
return run;
|
|
759
|
-
}
|
|
760
|
-
/**
|
|
761
|
-
* Create a batch of stateless background runs.
|
|
762
|
-
*
|
|
763
|
-
* @param payloads An array of payloads for creating runs.
|
|
764
|
-
* @returns An array of created runs.
|
|
765
|
-
*/
|
|
766
|
-
async createBatch(payloads, options) {
|
|
767
|
-
const filteredPayloads = payloads.map((payload) => ({
|
|
768
|
-
...payload,
|
|
769
|
-
assistant_id: payload.assistantId
|
|
770
|
-
})).map((payload) => {
|
|
771
|
-
return Object.fromEntries(Object.entries(payload).filter(([_, v]) => v !== void 0));
|
|
772
|
-
});
|
|
773
|
-
return this.fetch("/runs/batch", {
|
|
774
|
-
method: "POST",
|
|
775
|
-
json: filteredPayloads,
|
|
776
|
-
signal: options?.signal
|
|
777
|
-
});
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* Create a run and wait for it to complete.
|
|
781
|
-
*
|
|
782
|
-
* @param threadId The ID of the thread.
|
|
783
|
-
* @param assistantId Assistant ID to use for this run.
|
|
784
|
-
* @param payload Payload for creating a run.
|
|
785
|
-
* @returns The last values chunk of the thread.
|
|
786
|
-
*/
|
|
787
|
-
async wait(threadId, assistantId, payload) {
|
|
788
|
-
const json = {
|
|
789
|
-
input: payload?.input,
|
|
790
|
-
command: payload?.command,
|
|
791
|
-
config: payload?.config,
|
|
792
|
-
context: payload?.context,
|
|
793
|
-
metadata: payload?.metadata,
|
|
794
|
-
assistant_id: assistantId,
|
|
795
|
-
interrupt_before: payload?.interruptBefore,
|
|
796
|
-
interrupt_after: payload?.interruptAfter,
|
|
797
|
-
checkpoint: payload?.checkpoint,
|
|
798
|
-
checkpoint_id: payload?.checkpointId,
|
|
799
|
-
webhook: payload?.webhook,
|
|
800
|
-
multitask_strategy: payload?.multitaskStrategy,
|
|
801
|
-
on_completion: payload?.onCompletion,
|
|
802
|
-
on_disconnect: payload?.onDisconnect,
|
|
803
|
-
after_seconds: payload?.afterSeconds,
|
|
804
|
-
if_not_exists: payload?.ifNotExists,
|
|
805
|
-
checkpoint_during: payload?.checkpointDuring,
|
|
806
|
-
durability: payload?.durability,
|
|
807
|
-
langsmith_tracer: payload?._langsmithTracer ? {
|
|
808
|
-
project_name: payload?._langsmithTracer?.projectName,
|
|
809
|
-
example_id: payload?._langsmithTracer?.exampleId
|
|
810
|
-
} : void 0
|
|
811
|
-
};
|
|
812
|
-
const endpoint = threadId == null ? `/runs/wait` : `/threads/${threadId}/runs/wait`;
|
|
813
|
-
const [run, response] = await this.fetch(endpoint, {
|
|
814
|
-
method: "POST",
|
|
815
|
-
json,
|
|
816
|
-
timeoutMs: null,
|
|
817
|
-
signal: payload?.signal,
|
|
818
|
-
withResponse: true
|
|
819
|
-
});
|
|
820
|
-
const runMetadata = getRunMetadataFromResponse(response);
|
|
821
|
-
if (runMetadata) payload?.onRunCreated?.(runMetadata);
|
|
822
|
-
if ((payload?.raiseError !== void 0 ? payload.raiseError : true) && "__error__" in run && typeof run.__error__ === "object" && run.__error__ && "error" in run.__error__ && "message" in run.__error__) throw new Error(`${run.__error__?.error}: ${run.__error__?.message}`);
|
|
823
|
-
return run;
|
|
824
|
-
}
|
|
825
|
-
/**
|
|
826
|
-
* List all runs for a thread.
|
|
827
|
-
*
|
|
828
|
-
* @param threadId The ID of the thread.
|
|
829
|
-
* @param options Filtering and pagination options.
|
|
830
|
-
* @returns List of runs.
|
|
831
|
-
*/
|
|
832
|
-
async list(threadId, options) {
|
|
833
|
-
return this.fetch(`/threads/${threadId}/runs`, {
|
|
834
|
-
params: {
|
|
835
|
-
limit: options?.limit ?? 10,
|
|
836
|
-
offset: options?.offset ?? 0,
|
|
837
|
-
status: options?.status ?? void 0,
|
|
838
|
-
select: options?.select ?? void 0
|
|
839
|
-
},
|
|
840
|
-
signal: options?.signal
|
|
841
|
-
});
|
|
842
|
-
}
|
|
843
|
-
/**
|
|
844
|
-
* Get a run by ID.
|
|
845
|
-
*
|
|
846
|
-
* @param threadId The ID of the thread.
|
|
847
|
-
* @param runId The ID of the run.
|
|
848
|
-
* @returns The run.
|
|
849
|
-
*/
|
|
850
|
-
async get(threadId, runId, options) {
|
|
851
|
-
return this.fetch(`/threads/${threadId}/runs/${runId}`, { signal: options?.signal });
|
|
852
|
-
}
|
|
853
|
-
/**
|
|
854
|
-
* Cancel a run.
|
|
855
|
-
*
|
|
856
|
-
* @param threadId The ID of the thread.
|
|
857
|
-
* @param runId The ID of the run.
|
|
858
|
-
* @param wait Whether to block when canceling
|
|
859
|
-
* @param action Action to take when cancelling the run. Possible values are `interrupt` or `rollback`. Default is `interrupt`.
|
|
860
|
-
* @returns
|
|
861
|
-
*/
|
|
862
|
-
async cancel(threadId, runId, wait = false, action = "interrupt", options = {}) {
|
|
863
|
-
return this.fetch(`/threads/${threadId}/runs/${runId}/cancel`, {
|
|
864
|
-
method: "POST",
|
|
865
|
-
params: {
|
|
866
|
-
wait: wait ? "1" : "0",
|
|
867
|
-
action
|
|
868
|
-
},
|
|
869
|
-
signal: options?.signal
|
|
870
|
-
});
|
|
871
217
|
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
* @returns
|
|
878
|
-
*/
|
|
879
|
-
async join(threadId, runId, options) {
|
|
880
|
-
return this.fetch(`/threads/${threadId}/runs/${runId}/join`, {
|
|
881
|
-
timeoutMs: null,
|
|
882
|
-
signal: options?.signal
|
|
883
|
-
});
|
|
884
|
-
}
|
|
885
|
-
/**
|
|
886
|
-
* Stream output from a run in real-time, until the run is done.
|
|
887
|
-
*
|
|
888
|
-
* @param threadId The ID of the thread. Can be set to `null` | `undefined` for stateless runs.
|
|
889
|
-
* @param runId The ID of the run.
|
|
890
|
-
* @param options Additional options for controlling the stream behavior:
|
|
891
|
-
* - signal: An AbortSignal that can be used to cancel the stream request
|
|
892
|
-
* - lastEventId: The ID of the last event received. Can be used to reconnect to a stream without losing events.
|
|
893
|
-
* - cancelOnDisconnect: When true, automatically cancels the run if the client disconnects from the stream
|
|
894
|
-
* - streamMode: Controls what types of events to receive from the stream (can be a single mode or array of modes)
|
|
895
|
-
* Must be a subset of the stream modes passed when creating the run. Background runs default to having the union of all
|
|
896
|
-
* stream modes enabled.
|
|
897
|
-
* @returns An async generator yielding stream parts.
|
|
898
|
-
*/
|
|
899
|
-
async *joinStream(threadId, runId, options) {
|
|
900
|
-
const opts = typeof options === "object" && options != null && options instanceof AbortSignal ? { signal: options } : options;
|
|
901
|
-
yield* this.streamWithRetry({
|
|
902
|
-
endpoint: threadId != null ? `/threads/${threadId}/runs/${runId}/stream` : `/runs/${runId}/stream`,
|
|
903
|
-
method: "GET",
|
|
904
|
-
signal: opts?.signal,
|
|
905
|
-
headers: opts?.lastEventId ? { "Last-Event-ID": opts.lastEventId } : void 0,
|
|
906
|
-
params: {
|
|
907
|
-
cancel_on_disconnect: opts?.cancelOnDisconnect ? "1" : "0",
|
|
908
|
-
stream_mode: opts?.streamMode
|
|
909
|
-
}
|
|
910
|
-
});
|
|
911
|
-
}
|
|
912
|
-
/**
|
|
913
|
-
* Delete a run.
|
|
914
|
-
*
|
|
915
|
-
* @param threadId The ID of the thread.
|
|
916
|
-
* @param runId The ID of the run.
|
|
917
|
-
* @returns
|
|
918
|
-
*/
|
|
919
|
-
async delete(threadId, runId, options) {
|
|
920
|
-
return this.fetch(`/threads/${threadId}/runs/${runId}`, {
|
|
921
|
-
method: "DELETE",
|
|
922
|
-
signal: options?.signal
|
|
923
|
-
});
|
|
924
|
-
}
|
|
925
|
-
};
|
|
926
|
-
var StoreClient = class extends BaseClient {
|
|
927
|
-
/**
|
|
928
|
-
* Store or update an item.
|
|
929
|
-
*
|
|
930
|
-
* @param namespace A list of strings representing the namespace path.
|
|
931
|
-
* @param key The unique identifier for the item within the namespace.
|
|
932
|
-
* @param value A dictionary containing the item's data.
|
|
933
|
-
* @param options.index Controls search indexing - null (use defaults), false (disable), or list of field paths to index.
|
|
934
|
-
* @param options.ttl Optional time-to-live in minutes for the item, or null for no expiration.
|
|
935
|
-
* @returns Promise<void>
|
|
936
|
-
*
|
|
937
|
-
* @example
|
|
938
|
-
* ```typescript
|
|
939
|
-
* await client.store.putItem(
|
|
940
|
-
* ["documents", "user123"],
|
|
941
|
-
* "item456",
|
|
942
|
-
* { title: "My Document", content: "Hello World" },
|
|
943
|
-
* { ttl: 60 } // expires in 60 minutes
|
|
944
|
-
* );
|
|
945
|
-
* ```
|
|
946
|
-
*/
|
|
947
|
-
async putItem(namespace, key, value, options) {
|
|
948
|
-
namespace.forEach((label) => {
|
|
949
|
-
if (label.includes(".")) throw new Error(`Invalid namespace label '${label}'. Namespace labels cannot contain periods ('.')`);
|
|
950
|
-
});
|
|
951
|
-
const payload = {
|
|
952
|
-
namespace,
|
|
953
|
-
key,
|
|
954
|
-
value,
|
|
955
|
-
index: options?.index,
|
|
956
|
-
ttl: options?.ttl
|
|
957
|
-
};
|
|
958
|
-
return this.fetch("/store/items", {
|
|
959
|
-
method: "PUT",
|
|
960
|
-
json: payload,
|
|
961
|
-
signal: options?.signal
|
|
962
|
-
});
|
|
963
|
-
}
|
|
964
|
-
/**
|
|
965
|
-
* Retrieve a single item.
|
|
966
|
-
*
|
|
967
|
-
* @param namespace A list of strings representing the namespace path.
|
|
968
|
-
* @param key The unique identifier for the item.
|
|
969
|
-
* @param options.refreshTtl Whether to refresh the TTL on this read operation. If null, uses the store's default behavior.
|
|
970
|
-
* @returns Promise<Item>
|
|
971
|
-
*
|
|
972
|
-
* @example
|
|
973
|
-
* ```typescript
|
|
974
|
-
* const item = await client.store.getItem(
|
|
975
|
-
* ["documents", "user123"],
|
|
976
|
-
* "item456",
|
|
977
|
-
* { refreshTtl: true }
|
|
978
|
-
* );
|
|
979
|
-
* console.log(item);
|
|
980
|
-
* // {
|
|
981
|
-
* // namespace: ["documents", "user123"],
|
|
982
|
-
* // key: "item456",
|
|
983
|
-
* // value: { title: "My Document", content: "Hello World" },
|
|
984
|
-
* // createdAt: "2024-07-30T12:00:00Z",
|
|
985
|
-
* // updatedAt: "2024-07-30T12:00:00Z"
|
|
986
|
-
* // }
|
|
987
|
-
* ```
|
|
988
|
-
*/
|
|
989
|
-
async getItem(namespace, key, options) {
|
|
990
|
-
namespace.forEach((label) => {
|
|
991
|
-
if (label.includes(".")) throw new Error(`Invalid namespace label '${label}'. Namespace labels cannot contain periods ('.')`);
|
|
992
|
-
});
|
|
993
|
-
const params = {
|
|
994
|
-
namespace: namespace.join("."),
|
|
995
|
-
key
|
|
996
|
-
};
|
|
997
|
-
if (options?.refreshTtl !== void 0) params.refresh_ttl = options.refreshTtl;
|
|
998
|
-
const response = await this.fetch("/store/items", {
|
|
999
|
-
params,
|
|
1000
|
-
signal: options?.signal
|
|
1001
|
-
});
|
|
1002
|
-
return response ? {
|
|
1003
|
-
...response,
|
|
1004
|
-
createdAt: response.created_at,
|
|
1005
|
-
updatedAt: response.updated_at
|
|
1006
|
-
} : null;
|
|
1007
|
-
}
|
|
1008
|
-
/**
|
|
1009
|
-
* Delete an item.
|
|
1010
|
-
*
|
|
1011
|
-
* @param namespace A list of strings representing the namespace path.
|
|
1012
|
-
* @param key The unique identifier for the item.
|
|
1013
|
-
* @returns Promise<void>
|
|
1014
|
-
*/
|
|
1015
|
-
async deleteItem(namespace, key, options) {
|
|
1016
|
-
namespace.forEach((label) => {
|
|
1017
|
-
if (label.includes(".")) throw new Error(`Invalid namespace label '${label}'. Namespace labels cannot contain periods ('.')`);
|
|
1018
|
-
});
|
|
1019
|
-
return this.fetch("/store/items", {
|
|
1020
|
-
method: "DELETE",
|
|
1021
|
-
json: {
|
|
1022
|
-
namespace,
|
|
1023
|
-
key
|
|
1024
|
-
},
|
|
1025
|
-
signal: options?.signal
|
|
1026
|
-
});
|
|
1027
|
-
}
|
|
1028
|
-
/**
|
|
1029
|
-
* Search for items within a namespace prefix.
|
|
1030
|
-
*
|
|
1031
|
-
* @param namespacePrefix List of strings representing the namespace prefix.
|
|
1032
|
-
* @param options.filter Optional dictionary of key-value pairs to filter results.
|
|
1033
|
-
* @param options.limit Maximum number of items to return (default is 10).
|
|
1034
|
-
* @param options.offset Number of items to skip before returning results (default is 0).
|
|
1035
|
-
* @param options.query Optional search query.
|
|
1036
|
-
* @param options.refreshTtl Whether to refresh the TTL on items returned by this search. If null, uses the store's default behavior.
|
|
1037
|
-
* @returns Promise<SearchItemsResponse>
|
|
1038
|
-
*
|
|
1039
|
-
* @example
|
|
1040
|
-
* ```typescript
|
|
1041
|
-
* const results = await client.store.searchItems(
|
|
1042
|
-
* ["documents"],
|
|
1043
|
-
* {
|
|
1044
|
-
* filter: { author: "John Doe" },
|
|
1045
|
-
* limit: 5,
|
|
1046
|
-
* refreshTtl: true
|
|
1047
|
-
* }
|
|
1048
|
-
* );
|
|
1049
|
-
* console.log(results);
|
|
1050
|
-
* // {
|
|
1051
|
-
* // items: [
|
|
1052
|
-
* // {
|
|
1053
|
-
* // namespace: ["documents", "user123"],
|
|
1054
|
-
* // key: "item789",
|
|
1055
|
-
* // value: { title: "Another Document", author: "John Doe" },
|
|
1056
|
-
* // createdAt: "2024-07-30T12:00:00Z",
|
|
1057
|
-
* // updatedAt: "2024-07-30T12:00:00Z"
|
|
1058
|
-
* // },
|
|
1059
|
-
* // // ... additional items ...
|
|
1060
|
-
* // ]
|
|
1061
|
-
* // }
|
|
1062
|
-
* ```
|
|
1063
|
-
*/
|
|
1064
|
-
async searchItems(namespacePrefix, options) {
|
|
1065
|
-
const payload = {
|
|
1066
|
-
namespace_prefix: namespacePrefix,
|
|
1067
|
-
filter: options?.filter,
|
|
1068
|
-
limit: options?.limit ?? 10,
|
|
1069
|
-
offset: options?.offset ?? 0,
|
|
1070
|
-
query: options?.query,
|
|
1071
|
-
refresh_ttl: options?.refreshTtl
|
|
1072
|
-
};
|
|
1073
|
-
return { items: (await this.fetch("/store/items/search", {
|
|
1074
|
-
method: "POST",
|
|
1075
|
-
json: payload,
|
|
1076
|
-
signal: options?.signal
|
|
1077
|
-
})).items.map((item) => ({
|
|
1078
|
-
...item,
|
|
1079
|
-
createdAt: item.created_at,
|
|
1080
|
-
updatedAt: item.updated_at
|
|
1081
|
-
})) };
|
|
1082
|
-
}
|
|
1083
|
-
/**
|
|
1084
|
-
* List namespaces with optional match conditions.
|
|
1085
|
-
*
|
|
1086
|
-
* @param options.prefix Optional list of strings representing the prefix to filter namespaces.
|
|
1087
|
-
* @param options.suffix Optional list of strings representing the suffix to filter namespaces.
|
|
1088
|
-
* @param options.maxDepth Optional integer specifying the maximum depth of namespaces to return.
|
|
1089
|
-
* @param options.limit Maximum number of namespaces to return (default is 100).
|
|
1090
|
-
* @param options.offset Number of namespaces to skip before returning results (default is 0).
|
|
1091
|
-
* @returns Promise<ListNamespaceResponse>
|
|
1092
|
-
*/
|
|
1093
|
-
async listNamespaces(options) {
|
|
1094
|
-
const payload = {
|
|
1095
|
-
prefix: options?.prefix,
|
|
1096
|
-
suffix: options?.suffix,
|
|
1097
|
-
max_depth: options?.maxDepth,
|
|
1098
|
-
limit: options?.limit ?? 100,
|
|
1099
|
-
offset: options?.offset ?? 0
|
|
1100
|
-
};
|
|
1101
|
-
return this.fetch("/store/namespaces", {
|
|
1102
|
-
method: "POST",
|
|
1103
|
-
json: payload,
|
|
1104
|
-
signal: options?.signal
|
|
1105
|
-
});
|
|
1106
|
-
}
|
|
1107
|
-
};
|
|
1108
|
-
var UiClient = class UiClient2 extends BaseClient {
|
|
1109
|
-
static promiseCache = {};
|
|
1110
|
-
static getOrCached(key, fn) {
|
|
1111
|
-
if (UiClient2.promiseCache[key] != null) return UiClient2.promiseCache[key];
|
|
1112
|
-
const promise = fn();
|
|
1113
|
-
UiClient2.promiseCache[key] = promise;
|
|
1114
|
-
return promise;
|
|
1115
|
-
}
|
|
1116
|
-
async getComponent(assistantId, agentName) {
|
|
1117
|
-
return UiClient2.getOrCached(`${this.apiUrl}-${assistantId}-${agentName}`, async () => {
|
|
1118
|
-
let [url, init] = this.prepareFetchOptions(`/ui/${assistantId}`, {
|
|
1119
|
-
headers: {
|
|
1120
|
-
Accept: "text/html",
|
|
1121
|
-
"Content-Type": "application/json"
|
|
1122
|
-
},
|
|
1123
|
-
method: "POST",
|
|
1124
|
-
json: { name: agentName }
|
|
1125
|
-
});
|
|
1126
|
-
if (this.onRequest != null) init = await this.onRequest(url, init);
|
|
1127
|
-
return (await this.asyncCaller.fetch(url, init)).text();
|
|
1128
|
-
});
|
|
1129
|
-
}
|
|
1130
|
-
};
|
|
1131
|
-
var Client = class {
|
|
1132
|
-
/**
|
|
1133
|
-
* The client for interacting with assistants.
|
|
1134
|
-
*/
|
|
1135
|
-
assistants;
|
|
1136
|
-
/**
|
|
1137
|
-
* The client for interacting with threads.
|
|
1138
|
-
*/
|
|
1139
|
-
threads;
|
|
1140
|
-
/**
|
|
1141
|
-
* The client for interacting with runs.
|
|
1142
|
-
*/
|
|
1143
|
-
runs;
|
|
1144
|
-
/**
|
|
1145
|
-
* The client for interacting with cron runs.
|
|
1146
|
-
*/
|
|
1147
|
-
crons;
|
|
1148
|
-
/**
|
|
1149
|
-
* The client for interacting with the KV store.
|
|
1150
|
-
*/
|
|
1151
|
-
store;
|
|
1152
|
-
/**
|
|
1153
|
-
* The client for interacting with the UI.
|
|
1154
|
-
* @internal Used by LoadExternalComponent and the API might change in the future.
|
|
1155
|
-
*/
|
|
1156
|
-
"~ui";
|
|
1157
|
-
/**
|
|
1158
|
-
* @internal Used to obtain a stable key representing the client.
|
|
1159
|
-
*/
|
|
1160
|
-
"~configHash";
|
|
1161
|
-
constructor(config) {
|
|
1162
|
-
this["~configHash"] = JSON.stringify({
|
|
1163
|
-
apiUrl: config?.apiUrl,
|
|
1164
|
-
apiKey: config?.apiKey,
|
|
1165
|
-
timeoutMs: config?.timeoutMs,
|
|
1166
|
-
defaultHeaders: config?.defaultHeaders,
|
|
1167
|
-
maxConcurrency: config?.callerOptions?.maxConcurrency,
|
|
1168
|
-
maxRetries: config?.callerOptions?.maxRetries,
|
|
1169
|
-
callbacks: {
|
|
1170
|
-
onFailedResponseHook: config?.callerOptions?.onFailedResponseHook != null,
|
|
1171
|
-
onRequest: config?.onRequest != null,
|
|
1172
|
-
fetch: config?.callerOptions?.fetch != null
|
|
1173
|
-
}
|
|
1174
|
-
});
|
|
1175
|
-
this.assistants = new AssistantsClient(config);
|
|
1176
|
-
this.threads = new ThreadsClient(config);
|
|
1177
|
-
this.runs = new RunsClient(config);
|
|
1178
|
-
this.crons = new CronsClient(config);
|
|
1179
|
-
this.store = new StoreClient(config);
|
|
1180
|
-
this["~ui"] = new UiClient(config);
|
|
1181
|
-
}
|
|
1182
|
-
};
|
|
1183
|
-
function getClientConfigHash(client) {
|
|
1184
|
-
return client["~configHash"];
|
|
218
|
+
return {
|
|
219
|
+
tool_call_chunks: chunks,
|
|
220
|
+
tool_calls: toolCalls,
|
|
221
|
+
invalid_tool_calls: invalidToolCalls
|
|
222
|
+
};
|
|
1185
223
|
}
|
|
1186
224
|
export {
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
225
|
+
coerceMessageLikeToMessage,
|
|
226
|
+
collapseToolCallChunks,
|
|
227
|
+
convertToChunk,
|
|
228
|
+
getBufferString,
|
|
229
|
+
iife,
|
|
230
|
+
mapChatMessagesToStoredMessages,
|
|
231
|
+
mapStoredMessageToChatMessage,
|
|
232
|
+
mapStoredMessagesToChatMessages
|
|
1195
233
|
};
|
|
1196
234
|
//# sourceMappingURL=index.es43.js.map
|