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.
Files changed (393) hide show
  1. package/dist/index.es.js +3 -2
  2. package/dist/index.es10.js +25 -6
  3. package/dist/index.es10.js.map +1 -1
  4. package/dist/index.es100.js +131 -64
  5. package/dist/index.es100.js.map +1 -1
  6. package/dist/index.es101.js +65 -32
  7. package/dist/index.es101.js.map +1 -1
  8. package/dist/index.es102.js +34 -34
  9. package/dist/index.es102.js.map +1 -1
  10. package/dist/index.es103.js +35 -164
  11. package/dist/index.es103.js.map +1 -1
  12. package/dist/index.es104.js +156 -193
  13. package/dist/index.es104.js.map +1 -1
  14. package/dist/index.es105.js +202 -13
  15. package/dist/index.es105.js.map +1 -1
  16. package/dist/index.es106.js +13 -29
  17. package/dist/index.es106.js.map +1 -1
  18. package/dist/index.es107.js +25 -29
  19. package/dist/index.es107.js.map +1 -1
  20. package/dist/index.es108.js +24 -3147
  21. package/dist/index.es108.js.map +1 -1
  22. package/dist/index.es109.js +3151 -31
  23. package/dist/index.es109.js.map +1 -1
  24. package/dist/index.es110.js +21 -5
  25. package/dist/index.es110.js.map +1 -1
  26. package/dist/index.es111.js +64 -69
  27. package/dist/index.es111.js.map +1 -1
  28. package/dist/index.es112.js +3 -37
  29. package/dist/index.es112.js.map +1 -1
  30. package/dist/index.es113.js +16 -5
  31. package/dist/index.es113.js.map +1 -1
  32. package/dist/index.es114.js +7 -2
  33. package/dist/index.es114.js.map +1 -1
  34. package/dist/index.es115.js +2 -13
  35. package/dist/index.es115.js.map +1 -1
  36. package/dist/index.es116.js +9 -499
  37. package/dist/index.es116.js.map +1 -1
  38. package/dist/index.es117.js +501 -5
  39. package/dist/index.es117.js.map +1 -1
  40. package/dist/index.es118.js +7 -2
  41. package/dist/index.es118.js.map +1 -1
  42. package/dist/index.es119.js +2 -148
  43. package/dist/index.es119.js.map +1 -1
  44. package/dist/index.es120.js +118 -878
  45. package/dist/index.es120.js.map +1 -1
  46. package/dist/index.es121.js +877 -251
  47. package/dist/index.es121.js.map +1 -1
  48. package/dist/index.es122.js +281 -3
  49. package/dist/index.es122.js.map +1 -1
  50. package/dist/index.es123.js +3 -445
  51. package/dist/index.es123.js.map +1 -1
  52. package/dist/index.es124.js +437 -39
  53. package/dist/index.es124.js.map +1 -1
  54. package/dist/index.es125.js +46 -22
  55. package/dist/index.es125.js.map +1 -1
  56. package/dist/index.es126.js +21 -78
  57. package/dist/index.es126.js.map +1 -1
  58. package/dist/index.es127.js +76 -126
  59. package/dist/index.es127.js.map +1 -1
  60. package/dist/index.es128.js +125 -45
  61. package/dist/index.es128.js.map +1 -1
  62. package/dist/index.es129.js +48 -9
  63. package/dist/index.es129.js.map +1 -1
  64. package/dist/index.es130.js +10 -45
  65. package/dist/index.es130.js.map +1 -1
  66. package/dist/index.es131.js +43 -97
  67. package/dist/index.es131.js.map +1 -1
  68. package/dist/index.es132.js +94 -48
  69. package/dist/index.es132.js.map +1 -1
  70. package/dist/index.es133.js +51 -14
  71. package/dist/index.es133.js.map +1 -1
  72. package/dist/index.es134.js +1 -1
  73. package/dist/index.es135.js +1 -1
  74. package/dist/index.es138.js +1 -1
  75. package/dist/index.es139.js +1 -1
  76. package/dist/index.es140.js +1 -1
  77. package/dist/index.es141.js +1 -1
  78. package/dist/index.es142.js +1 -1
  79. package/dist/index.es143.js +1 -1
  80. package/dist/index.es144.js +1 -1
  81. package/dist/index.es145.js +1 -1
  82. package/dist/index.es146.js +1 -1
  83. package/dist/index.es147.js +1 -1
  84. package/dist/index.es148.js +1 -1
  85. package/dist/index.es149.js +1 -1
  86. package/dist/index.es150.js +1 -1
  87. package/dist/index.es151.js +1 -1
  88. package/dist/index.es152.js +1 -1
  89. package/dist/index.es153.js +1 -1
  90. package/dist/index.es154.js +1 -1
  91. package/dist/index.es155.js +1 -1
  92. package/dist/index.es156.js +1 -1
  93. package/dist/index.es157.js +1 -1
  94. package/dist/index.es158.js +1 -1
  95. package/dist/index.es159.js +1 -1
  96. package/dist/index.es16.js +3 -3
  97. package/dist/index.es16.js.map +1 -1
  98. package/dist/index.es160.js +1 -1
  99. package/dist/index.es161.js +1 -1
  100. package/dist/index.es162.js +1 -1
  101. package/dist/index.es163.js +1 -1
  102. package/dist/index.es164.js +1 -1
  103. package/dist/index.es165.js +1 -1
  104. package/dist/index.es166.js +1 -1
  105. package/dist/index.es167.js +1 -1
  106. package/dist/index.es168.js +1 -1
  107. package/dist/index.es169.js +1 -1
  108. package/dist/index.es170.js +1 -1
  109. package/dist/index.es171.js +1 -1
  110. package/dist/index.es172.js +1 -1
  111. package/dist/index.es173.js +1 -1
  112. package/dist/index.es174.js +1 -1
  113. package/dist/index.es175.js +1 -1
  114. package/dist/index.es176.js +1 -1
  115. package/dist/index.es177.js +1 -1
  116. package/dist/index.es178.js +1 -1
  117. package/dist/index.es179.js +1 -1
  118. package/dist/index.es18.js +15 -15
  119. package/dist/index.es180.js +1 -1
  120. package/dist/index.es181.js +1 -1
  121. package/dist/index.es182.js +1 -1
  122. package/dist/index.es183.js +162 -13
  123. package/dist/index.es183.js.map +1 -1
  124. package/dist/index.es184.js +2 -89
  125. package/dist/index.es184.js.map +1 -1
  126. package/dist/index.es185.js +15 -2
  127. package/dist/index.es185.js.map +1 -1
  128. package/dist/index.es186.js +89 -2
  129. package/dist/index.es186.js.map +1 -1
  130. package/dist/index.es187.js +2 -2
  131. package/dist/index.es188.js +56 -2
  132. package/dist/index.es188.js.map +1 -1
  133. package/dist/index.es189.js +100 -2
  134. package/dist/index.es189.js.map +1 -1
  135. package/dist/index.es190.js +191 -2
  136. package/dist/index.es190.js.map +1 -1
  137. package/dist/index.es191.js +110 -2
  138. package/dist/index.es191.js.map +1 -1
  139. package/dist/index.es192.js +35 -2
  140. package/dist/index.es192.js.map +1 -1
  141. package/dist/index.es193.js +10 -2
  142. package/dist/index.es193.js.map +1 -1
  143. package/dist/index.es194.js +11 -2
  144. package/dist/index.es194.js.map +1 -1
  145. package/dist/index.es195.js +12 -2
  146. package/dist/index.es195.js.map +1 -1
  147. package/dist/index.es196.js +91 -2
  148. package/dist/index.es196.js.map +1 -1
  149. package/dist/index.es197.js +275 -2
  150. package/dist/index.es197.js.map +1 -1
  151. package/dist/index.es198.js +2 -2
  152. package/dist/index.es199.js +164 -2
  153. package/dist/index.es199.js.map +1 -1
  154. package/dist/index.es200.js +51 -2
  155. package/dist/index.es200.js.map +1 -1
  156. package/dist/index.es201.js +40 -2
  157. package/dist/index.es201.js.map +1 -1
  158. package/dist/index.es202.js +35 -2
  159. package/dist/index.es202.js.map +1 -1
  160. package/dist/index.es203.js +40 -2
  161. package/dist/index.es203.js.map +1 -1
  162. package/dist/index.es204.js +24 -2
  163. package/dist/index.es204.js.map +1 -1
  164. package/dist/index.es205.js +591 -2
  165. package/dist/index.es205.js.map +1 -1
  166. package/dist/index.es206.js +125 -2
  167. package/dist/index.es206.js.map +1 -1
  168. package/dist/index.es207.js +2 -2
  169. package/dist/index.es208.js +2 -2
  170. package/dist/index.es209.js +2 -2
  171. package/dist/index.es210.js +2 -2
  172. package/dist/index.es211.js +2 -2
  173. package/dist/index.es212.js +2 -2
  174. package/dist/index.es213.js +2 -2
  175. package/dist/index.es214.js +2 -2
  176. package/dist/index.es215.js +2 -2
  177. package/dist/index.es216.js +2 -2
  178. package/dist/index.es217.js +2 -2
  179. package/dist/index.es218.js +2 -2
  180. package/dist/index.es219.js +2 -2
  181. package/dist/index.es220.js +2 -2
  182. package/dist/index.es221.js +2 -2
  183. package/dist/index.es222.js +2 -2
  184. package/dist/index.es223.js +2 -2
  185. package/dist/index.es224.js +2 -2
  186. package/dist/index.es225.js +2 -2
  187. package/dist/index.es226.js +2 -2
  188. package/dist/index.es227.js +2 -2
  189. package/dist/index.es228.js +2 -2
  190. package/dist/index.es229.js +2 -2
  191. package/dist/index.es230.js +2 -2
  192. package/dist/index.es231.js +2 -56
  193. package/dist/index.es231.js.map +1 -1
  194. package/dist/index.es232.js +2 -100
  195. package/dist/index.es232.js.map +1 -1
  196. package/dist/index.es233.js +2 -191
  197. package/dist/index.es233.js.map +1 -1
  198. package/dist/index.es234.js +2 -110
  199. package/dist/index.es234.js.map +1 -1
  200. package/dist/index.es235.js +2 -35
  201. package/dist/index.es235.js.map +1 -1
  202. package/dist/index.es236.js +2 -10
  203. package/dist/index.es236.js.map +1 -1
  204. package/dist/index.es237.js +2 -11
  205. package/dist/index.es237.js.map +1 -1
  206. package/dist/index.es238.js +2 -12
  207. package/dist/index.es238.js.map +1 -1
  208. package/dist/index.es239.js +2 -91
  209. package/dist/index.es239.js.map +1 -1
  210. package/dist/index.es24.js +1 -1
  211. package/dist/index.es240.js +2 -275
  212. package/dist/index.es240.js.map +1 -1
  213. package/dist/index.es241.js +2 -2
  214. package/dist/index.es242.js +2 -164
  215. package/dist/index.es242.js.map +1 -1
  216. package/dist/index.es243.js +2 -51
  217. package/dist/index.es243.js.map +1 -1
  218. package/dist/index.es244.js +2 -40
  219. package/dist/index.es244.js.map +1 -1
  220. package/dist/index.es245.js +2 -35
  221. package/dist/index.es245.js.map +1 -1
  222. package/dist/index.es246.js +2 -40
  223. package/dist/index.es246.js.map +1 -1
  224. package/dist/index.es247.js +2 -24
  225. package/dist/index.es247.js.map +1 -1
  226. package/dist/index.es248.js +2 -591
  227. package/dist/index.es248.js.map +1 -1
  228. package/dist/index.es249.js +2 -125
  229. package/dist/index.es249.js.map +1 -1
  230. package/dist/index.es25.js +3 -1
  231. package/dist/index.es25.js.map +1 -1
  232. package/dist/index.es250.js +2 -164
  233. package/dist/index.es250.js.map +1 -1
  234. package/dist/index.es251.js +2 -2
  235. package/dist/index.es252.js +2 -2
  236. package/dist/index.es253.js +1 -1
  237. package/dist/index.es258.js +1 -1
  238. package/dist/index.es260.js +2 -2
  239. package/dist/index.es262.js +2 -2
  240. package/dist/index.es265.js +1 -1
  241. package/dist/index.es267.js +1 -1
  242. package/dist/index.es277.js +2 -147
  243. package/dist/index.es277.js.map +1 -1
  244. package/dist/index.es278.js +126 -167
  245. package/dist/index.es278.js.map +1 -1
  246. package/dist/index.es279.js +188 -2
  247. package/dist/index.es279.js.map +1 -1
  248. package/dist/index.es280.js +1 -1
  249. package/dist/index.es283.js +1 -1
  250. package/dist/index.es288.js +1 -1
  251. package/dist/index.es29.js +1 -1
  252. package/dist/index.es3.js +24 -9
  253. package/dist/index.es3.js.map +1 -1
  254. package/dist/index.es300.js +1 -1
  255. package/dist/index.es302.js +1 -1
  256. package/dist/index.es31.js +7 -7
  257. package/dist/index.es314.js +1 -1
  258. package/dist/index.es32.js +1 -1
  259. package/dist/index.es334.js +2 -2
  260. package/dist/index.es35.js +4 -4
  261. package/dist/index.es36.js +1185 -111
  262. package/dist/index.es36.js.map +1 -1
  263. package/dist/index.es37.js +7 -71
  264. package/dist/index.es37.js.map +1 -1
  265. package/dist/index.es38.js +9 -18
  266. package/dist/index.es38.js.map +1 -1
  267. package/dist/index.es39.js +136 -250
  268. package/dist/index.es39.js.map +1 -1
  269. package/dist/index.es4.js +2 -1
  270. package/dist/index.es4.js.map +1 -1
  271. package/dist/index.es40.js +116 -41
  272. package/dist/index.es40.js.map +1 -1
  273. package/dist/index.es41.js +64 -208
  274. package/dist/index.es41.js.map +1 -1
  275. package/dist/index.es42.js +17 -66
  276. package/dist/index.es42.js.map +1 -1
  277. package/dist/index.es43.js +236 -117
  278. package/dist/index.es43.js.map +1 -1
  279. package/dist/index.es44.js +38 -19
  280. package/dist/index.es44.js.map +1 -1
  281. package/dist/index.es45.js +202 -217
  282. package/dist/index.es45.js.map +1 -1
  283. package/dist/index.es46.js +65 -7
  284. package/dist/index.es46.js.map +1 -1
  285. package/dist/index.es47.js +131 -1181
  286. package/dist/index.es47.js.map +1 -1
  287. package/dist/index.es48.js +25 -8
  288. package/dist/index.es48.js.map +1 -1
  289. package/dist/index.es49.js +218 -135
  290. package/dist/index.es49.js.map +1 -1
  291. package/dist/index.es5.js.map +1 -1
  292. package/dist/index.es50.js +5 -208
  293. package/dist/index.es50.js.map +1 -1
  294. package/dist/index.es51.js +208 -5
  295. package/dist/index.es51.js.map +1 -1
  296. package/dist/index.es52.js +90 -7
  297. package/dist/index.es52.js.map +1 -1
  298. package/dist/index.es53.js +6 -92
  299. package/dist/index.es53.js.map +1 -1
  300. package/dist/index.es54.js +14 -3
  301. package/dist/index.es54.js.map +1 -1
  302. package/dist/index.es55.js +8 -36
  303. package/dist/index.es55.js.map +1 -1
  304. package/dist/index.es56.js +83 -61
  305. package/dist/index.es56.js.map +1 -1
  306. package/dist/index.es57.js +3 -37
  307. package/dist/index.es57.js.map +1 -1
  308. package/dist/index.es58.js +34 -304
  309. package/dist/index.es58.js.map +1 -1
  310. package/dist/index.es59.js +72 -9
  311. package/dist/index.es59.js.map +1 -1
  312. package/dist/index.es60.js +32 -85
  313. package/dist/index.es60.js.map +1 -1
  314. package/dist/index.es61.js +304 -6
  315. package/dist/index.es61.js.map +1 -1
  316. package/dist/index.es62.js +9 -15
  317. package/dist/index.es62.js.map +1 -1
  318. package/dist/index.es63.js +3 -3
  319. package/dist/index.es64.js +5 -142
  320. package/dist/index.es64.js.map +1 -1
  321. package/dist/index.es65.js +148 -285
  322. package/dist/index.es65.js.map +1 -1
  323. package/dist/index.es66.js +668 -62
  324. package/dist/index.es66.js.map +1 -1
  325. package/dist/index.es67.js +131 -201
  326. package/dist/index.es67.js.map +1 -1
  327. package/dist/index.es68.js +295 -29
  328. package/dist/index.es68.js.map +1 -1
  329. package/dist/index.es69.js +65 -8
  330. package/dist/index.es69.js.map +1 -1
  331. package/dist/index.es7.js +2 -1
  332. package/dist/index.es7.js.map +1 -1
  333. package/dist/index.es70.js +210 -9
  334. package/dist/index.es70.js.map +1 -1
  335. package/dist/index.es71.js +28 -181
  336. package/dist/index.es71.js.map +1 -1
  337. package/dist/index.es72.js +8 -23
  338. package/dist/index.es72.js.map +1 -1
  339. package/dist/index.es73.js +9 -1397
  340. package/dist/index.es73.js.map +1 -1
  341. package/dist/index.es74.js +187 -9
  342. package/dist/index.es74.js.map +1 -1
  343. package/dist/index.es75.js +24 -8
  344. package/dist/index.es75.js.map +1 -1
  345. package/dist/index.es76.js +1399 -5
  346. package/dist/index.es76.js.map +1 -1
  347. package/dist/index.es77.js +9 -163
  348. package/dist/index.es77.js.map +1 -1
  349. package/dist/index.es78.js +8 -672
  350. package/dist/index.es78.js.map +1 -1
  351. package/dist/index.es79.js +36 -20
  352. package/dist/index.es79.js.map +1 -1
  353. package/dist/index.es80.js +5 -68
  354. package/dist/index.es80.js.map +1 -1
  355. package/dist/index.es81.js +73 -3
  356. package/dist/index.es81.js.map +1 -1
  357. package/dist/index.es82.js +36 -11
  358. package/dist/index.es82.js.map +1 -1
  359. package/dist/index.es83.js +10 -38
  360. package/dist/index.es83.js.map +1 -1
  361. package/dist/index.es84.js +34 -28
  362. package/dist/index.es84.js.map +1 -1
  363. package/dist/index.es85.js +28 -226
  364. package/dist/index.es85.js.map +1 -1
  365. package/dist/index.es86.js +228 -26
  366. package/dist/index.es86.js.map +1 -1
  367. package/dist/index.es87.js +26 -71
  368. package/dist/index.es87.js.map +1 -1
  369. package/dist/index.es88.js +41 -42
  370. package/dist/index.es88.js.map +1 -1
  371. package/dist/index.es89.js +71 -47
  372. package/dist/index.es89.js.map +1 -1
  373. package/dist/index.es90.js +37 -15
  374. package/dist/index.es90.js.map +1 -1
  375. package/dist/index.es91.js +6 -19
  376. package/dist/index.es91.js.map +1 -1
  377. package/dist/index.es92.js +40 -54
  378. package/dist/index.es92.js.map +1 -1
  379. package/dist/index.es93.js +56 -12
  380. package/dist/index.es93.js.map +1 -1
  381. package/dist/index.es94.js +13 -137
  382. package/dist/index.es94.js.map +1 -1
  383. package/dist/index.es95.js +135 -19
  384. package/dist/index.es95.js.map +1 -1
  385. package/dist/index.es96.js +18 -179
  386. package/dist/index.es96.js.map +1 -1
  387. package/dist/index.es97.js +163 -222
  388. package/dist/index.es97.js.map +1 -1
  389. package/dist/index.es98.js +187 -301
  390. package/dist/index.es98.js.map +1 -1
  391. package/dist/index.es99.js +348 -130
  392. package/dist/index.es99.js.map +1 -1
  393. package/package.json +1 -1
@@ -1,283 +1,909 @@
1
- import { __export } from "./index.es52.js";
2
- import { _deepClone, PatchError, unescapePathComponent, isInteger, hasUndefined } from "./index.es239.js";
3
- var core_exports = {};
4
- __export(core_exports, {
5
- JsonPatchError: () => JsonPatchError,
6
- _areEquals: () => _areEquals,
7
- applyOperation: () => applyOperation,
8
- applyPatch: () => applyPatch,
9
- applyReducer: () => applyReducer,
10
- deepClone: () => deepClone,
11
- getValueByPointer: () => getValueByPointer,
12
- validate: () => validate,
13
- validator: () => validator
14
- });
15
- const JsonPatchError = PatchError;
16
- const deepClone = _deepClone;
17
- function isDangerousKey(key) {
18
- return Object.getOwnPropertyNames(Object.prototype).includes(key);
1
+ import { Client } from "./index.es280.js";
2
+ import { isTracingEnabled } from "./index.es292.js";
3
+ import { isConflictingEndpointsError, ConflictingEndpointsError } from "./index.es289.js";
4
+ import { _LC_CONTEXT_VARIABLES_KEY, _REPLICA_TRACE_ROOTS_KEY } from "./index.es293.js";
5
+ import { getContextVar, setContextVar } from "./index.es294.js";
6
+ import { getEnvironmentVariable, getRuntimeEnvironment, getLangSmithEnvironmentVariable } from "./index.es285.js";
7
+ import { getDefaultProjectName } from "./index.es263.js";
8
+ import { warnOnce } from "./index.es287.js";
9
+ import { uuid7FromTime } from "./index.es286.js";
10
+ import { v5 } from "uuid";
11
+ const UUID_NAMESPACE_DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
12
+ function getReplicaKey(replica) {
13
+ const sortedKeys = Object.keys(replica).sort();
14
+ const keyData = sortedKeys.map((key) => `${key}:${replica[key] ?? ""}`).join("|");
15
+ return v5(keyData, UUID_NAMESPACE_DNS);
19
16
  }
20
- const objOps = {
21
- add: function(obj, key, document) {
22
- if (isDangerousKey(key)) throw new TypeError("JSON-Patch: modifying `__proto__`, `constructor`, or `prototype` prop is banned for security reasons");
23
- obj[key] = this.value;
24
- return { newDocument: document };
25
- },
26
- remove: function(obj, key, document) {
27
- if (isDangerousKey(key)) throw new TypeError("JSON-Patch: modifying `__proto__`, `constructor`, or `prototype` prop is banned for security reasons");
28
- var removed = obj[key];
29
- delete obj[key];
30
- return {
31
- newDocument: document,
32
- removed
33
- };
34
- },
35
- replace: function(obj, key, document) {
36
- if (isDangerousKey(key)) throw new TypeError("JSON-Patch: modifying `__proto__`, `constructor`, or `prototype` prop is banned for security reasons");
37
- var removed = obj[key];
38
- obj[key] = this.value;
39
- return {
40
- newDocument: document,
41
- removed
42
- };
43
- },
44
- move: function(obj, key, document) {
45
- let removed = getValueByPointer(document, this.path);
46
- if (removed) removed = _deepClone(removed);
47
- const originalValue = applyOperation(document, {
48
- op: "remove",
49
- path: this.from
50
- }).removed;
51
- applyOperation(document, {
52
- op: "add",
53
- path: this.path,
54
- value: originalValue
17
+ function stripNonAlphanumeric(input) {
18
+ return input.replace(/[-:.]/g, "");
19
+ }
20
+ function getMicrosecondPrecisionDatestring(epoch, executionOrder = 1) {
21
+ const paddedOrder = executionOrder.toFixed(0).slice(0, 3).padStart(3, "0");
22
+ return `${new Date(epoch).toISOString().slice(0, -1)}${paddedOrder}Z`;
23
+ }
24
+ function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
25
+ const microsecondPrecisionDatestring = getMicrosecondPrecisionDatestring(epoch, executionOrder);
26
+ return {
27
+ dottedOrder: stripNonAlphanumeric(microsecondPrecisionDatestring) + runId,
28
+ microsecondPrecisionDatestring
29
+ };
30
+ }
31
+ const HEADER_SAFE_REPLICA_FIELDS = /* @__PURE__ */ new Set([
32
+ "projectName",
33
+ "updates",
34
+ "reroot"
35
+ ]);
36
+ function filterReplicaForHeaders(replica) {
37
+ const filtered = {};
38
+ for (const key of Object.keys(replica)) {
39
+ if (HEADER_SAFE_REPLICA_FIELDS.has(key)) {
40
+ filtered[key] = replica[key];
41
+ }
42
+ }
43
+ return filtered;
44
+ }
45
+ class Baggage {
46
+ constructor(metadata, tags, project_name, replicas) {
47
+ Object.defineProperty(this, "metadata", {
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true,
51
+ value: void 0
55
52
  });
56
- return {
57
- newDocument: document,
58
- removed
53
+ Object.defineProperty(this, "tags", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: void 0
58
+ });
59
+ Object.defineProperty(this, "project_name", {
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true,
63
+ value: void 0
64
+ });
65
+ Object.defineProperty(this, "replicas", {
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true,
69
+ value: void 0
70
+ });
71
+ this.metadata = metadata;
72
+ this.tags = tags;
73
+ this.project_name = project_name;
74
+ this.replicas = replicas;
75
+ }
76
+ static fromHeader(value) {
77
+ const items = value.split(",");
78
+ let metadata = {};
79
+ let tags = [];
80
+ let project_name;
81
+ let replicas;
82
+ for (const item of items) {
83
+ const [key, uriValue] = item.split("=");
84
+ const value2 = decodeURIComponent(uriValue);
85
+ if (key === "langsmith-metadata") {
86
+ metadata = JSON.parse(value2);
87
+ } else if (key === "langsmith-tags") {
88
+ tags = value2.split(",");
89
+ } else if (key === "langsmith-project") {
90
+ project_name = value2;
91
+ } else if (key === "langsmith-replicas") {
92
+ const parsed = JSON.parse(value2);
93
+ replicas = parsed.map((replica) => {
94
+ if (Array.isArray(replica)) {
95
+ return replica;
96
+ }
97
+ return filterReplicaForHeaders(replica);
98
+ });
99
+ }
100
+ }
101
+ return new Baggage(metadata, tags, project_name, replicas);
102
+ }
103
+ toHeader() {
104
+ const items = [];
105
+ if (this.metadata && Object.keys(this.metadata).length > 0) {
106
+ items.push(`langsmith-metadata=${encodeURIComponent(JSON.stringify(this.metadata))}`);
107
+ }
108
+ if (this.tags && this.tags.length > 0) {
109
+ items.push(`langsmith-tags=${encodeURIComponent(this.tags.join(","))}`);
110
+ }
111
+ if (this.project_name) {
112
+ items.push(`langsmith-project=${encodeURIComponent(this.project_name)}`);
113
+ }
114
+ return items.join(",");
115
+ }
116
+ }
117
+ class RunTree {
118
+ constructor(originalConfig) {
119
+ Object.defineProperty(this, "id", {
120
+ enumerable: true,
121
+ configurable: true,
122
+ writable: true,
123
+ value: void 0
124
+ });
125
+ Object.defineProperty(this, "name", {
126
+ enumerable: true,
127
+ configurable: true,
128
+ writable: true,
129
+ value: void 0
130
+ });
131
+ Object.defineProperty(this, "run_type", {
132
+ enumerable: true,
133
+ configurable: true,
134
+ writable: true,
135
+ value: void 0
136
+ });
137
+ Object.defineProperty(this, "project_name", {
138
+ enumerable: true,
139
+ configurable: true,
140
+ writable: true,
141
+ value: void 0
142
+ });
143
+ Object.defineProperty(this, "parent_run", {
144
+ enumerable: true,
145
+ configurable: true,
146
+ writable: true,
147
+ value: void 0
148
+ });
149
+ Object.defineProperty(this, "parent_run_id", {
150
+ enumerable: true,
151
+ configurable: true,
152
+ writable: true,
153
+ value: void 0
154
+ });
155
+ Object.defineProperty(this, "child_runs", {
156
+ enumerable: true,
157
+ configurable: true,
158
+ writable: true,
159
+ value: void 0
160
+ });
161
+ Object.defineProperty(this, "start_time", {
162
+ enumerable: true,
163
+ configurable: true,
164
+ writable: true,
165
+ value: void 0
166
+ });
167
+ Object.defineProperty(this, "end_time", {
168
+ enumerable: true,
169
+ configurable: true,
170
+ writable: true,
171
+ value: void 0
172
+ });
173
+ Object.defineProperty(this, "extra", {
174
+ enumerable: true,
175
+ configurable: true,
176
+ writable: true,
177
+ value: void 0
178
+ });
179
+ Object.defineProperty(this, "tags", {
180
+ enumerable: true,
181
+ configurable: true,
182
+ writable: true,
183
+ value: void 0
184
+ });
185
+ Object.defineProperty(this, "error", {
186
+ enumerable: true,
187
+ configurable: true,
188
+ writable: true,
189
+ value: void 0
190
+ });
191
+ Object.defineProperty(this, "serialized", {
192
+ enumerable: true,
193
+ configurable: true,
194
+ writable: true,
195
+ value: void 0
196
+ });
197
+ Object.defineProperty(this, "inputs", {
198
+ enumerable: true,
199
+ configurable: true,
200
+ writable: true,
201
+ value: void 0
202
+ });
203
+ Object.defineProperty(this, "outputs", {
204
+ enumerable: true,
205
+ configurable: true,
206
+ writable: true,
207
+ value: void 0
208
+ });
209
+ Object.defineProperty(this, "reference_example_id", {
210
+ enumerable: true,
211
+ configurable: true,
212
+ writable: true,
213
+ value: void 0
214
+ });
215
+ Object.defineProperty(this, "client", {
216
+ enumerable: true,
217
+ configurable: true,
218
+ writable: true,
219
+ value: void 0
220
+ });
221
+ Object.defineProperty(this, "events", {
222
+ enumerable: true,
223
+ configurable: true,
224
+ writable: true,
225
+ value: void 0
226
+ });
227
+ Object.defineProperty(this, "trace_id", {
228
+ enumerable: true,
229
+ configurable: true,
230
+ writable: true,
231
+ value: void 0
232
+ });
233
+ Object.defineProperty(this, "dotted_order", {
234
+ enumerable: true,
235
+ configurable: true,
236
+ writable: true,
237
+ value: void 0
238
+ });
239
+ Object.defineProperty(this, "tracingEnabled", {
240
+ enumerable: true,
241
+ configurable: true,
242
+ writable: true,
243
+ value: void 0
244
+ });
245
+ Object.defineProperty(this, "execution_order", {
246
+ enumerable: true,
247
+ configurable: true,
248
+ writable: true,
249
+ value: void 0
250
+ });
251
+ Object.defineProperty(this, "child_execution_order", {
252
+ enumerable: true,
253
+ configurable: true,
254
+ writable: true,
255
+ value: void 0
256
+ });
257
+ Object.defineProperty(this, "attachments", {
258
+ enumerable: true,
259
+ configurable: true,
260
+ writable: true,
261
+ value: void 0
262
+ });
263
+ Object.defineProperty(this, "replicas", {
264
+ enumerable: true,
265
+ configurable: true,
266
+ writable: true,
267
+ value: void 0
268
+ });
269
+ Object.defineProperty(this, "distributedParentId", {
270
+ enumerable: true,
271
+ configurable: true,
272
+ writable: true,
273
+ value: void 0
274
+ });
275
+ Object.defineProperty(this, "_serialized_start_time", {
276
+ enumerable: true,
277
+ configurable: true,
278
+ writable: true,
279
+ value: void 0
280
+ });
281
+ Object.defineProperty(this, "_awaitInputsOnPost", {
282
+ enumerable: true,
283
+ configurable: true,
284
+ writable: true,
285
+ value: void 0
286
+ });
287
+ if (isRunTree(originalConfig)) {
288
+ Object.assign(this, { ...originalConfig });
289
+ return;
290
+ }
291
+ const defaultConfig = RunTree.getDefaultConfig();
292
+ const { metadata, ...config } = originalConfig;
293
+ const client = config.client ?? RunTree.getSharedClient();
294
+ const dedupedMetadata = {
295
+ ...metadata,
296
+ ...config?.extra?.metadata
59
297
  };
60
- },
61
- copy: function(obj, key, document) {
62
- const valueToCopy = getValueByPointer(document, this.from);
63
- applyOperation(document, {
64
- op: "add",
65
- path: this.path,
66
- value: _deepClone(valueToCopy)
67
- });
68
- return { newDocument: document };
69
- },
70
- test: function(obj, key, document) {
71
- return {
72
- newDocument: document,
73
- test: _areEquals(obj[key], this.value)
298
+ config.extra = { ...config.extra, metadata: dedupedMetadata };
299
+ if ("id" in config && config.id == null) {
300
+ delete config.id;
301
+ }
302
+ Object.assign(this, { ...defaultConfig, ...config, client });
303
+ this.execution_order ??= 1;
304
+ this.child_execution_order ??= 1;
305
+ if (!this.dotted_order) {
306
+ this._serialized_start_time = getMicrosecondPrecisionDatestring(this.start_time, this.execution_order);
307
+ }
308
+ if (!this.id) {
309
+ this.id = uuid7FromTime(this._serialized_start_time ?? this.start_time);
310
+ }
311
+ if (!this.trace_id) {
312
+ if (this.parent_run) {
313
+ this.trace_id = this.parent_run.trace_id ?? this.id;
314
+ } else {
315
+ this.trace_id = this.id;
316
+ }
317
+ }
318
+ this.replicas = _ensureWriteReplicas(this.replicas);
319
+ if (!this.dotted_order) {
320
+ const { dottedOrder } = convertToDottedOrderFormat(this.start_time, this.id, this.execution_order);
321
+ if (this.parent_run) {
322
+ this.dotted_order = this.parent_run.dotted_order + "." + dottedOrder;
323
+ } else {
324
+ this.dotted_order = dottedOrder;
325
+ }
326
+ }
327
+ }
328
+ set metadata(metadata) {
329
+ this.extra = {
330
+ ...this.extra,
331
+ metadata: {
332
+ ...this.extra?.metadata,
333
+ ...metadata
334
+ }
74
335
  };
75
- },
76
- _get: function(obj, key, document) {
77
- this.value = obj[key];
78
- return { newDocument: document };
79
336
  }
80
- };
81
- var arrOps = {
82
- add: function(arr, i, document) {
83
- if (isInteger(i)) arr.splice(i, 0, this.value);
84
- else arr[i] = this.value;
337
+ get metadata() {
338
+ return this.extra?.metadata;
339
+ }
340
+ static getDefaultConfig() {
341
+ const start_time = Date.now();
85
342
  return {
86
- newDocument: document,
87
- index: i
343
+ run_type: "chain",
344
+ project_name: getDefaultProjectName(),
345
+ child_runs: [],
346
+ api_url: getEnvironmentVariable("LANGCHAIN_ENDPOINT") ?? "http://localhost:1984",
347
+ api_key: getEnvironmentVariable("LANGCHAIN_API_KEY"),
348
+ caller_options: {},
349
+ start_time,
350
+ serialized: {},
351
+ inputs: {},
352
+ extra: {}
88
353
  };
89
- },
90
- remove: function(arr, i, document) {
91
- var removedList = arr.splice(i, 1);
354
+ }
355
+ static getSharedClient() {
356
+ if (!RunTree.sharedClient) {
357
+ RunTree.sharedClient = new Client();
358
+ }
359
+ return RunTree.sharedClient;
360
+ }
361
+ createChild(config) {
362
+ const child_execution_order = this.child_execution_order + 1;
363
+ const inheritedReplicas = this.replicas?.map((replica) => {
364
+ const { reroot, ...rest } = replica;
365
+ return rest;
366
+ });
367
+ const childReplicas = config.replicas ?? inheritedReplicas;
368
+ const child = new RunTree({
369
+ ...config,
370
+ parent_run: this,
371
+ project_name: this.project_name,
372
+ replicas: childReplicas,
373
+ client: this.client,
374
+ tracingEnabled: this.tracingEnabled,
375
+ execution_order: child_execution_order,
376
+ child_execution_order
377
+ });
378
+ if (_LC_CONTEXT_VARIABLES_KEY in this) {
379
+ child[_LC_CONTEXT_VARIABLES_KEY] = this[_LC_CONTEXT_VARIABLES_KEY];
380
+ }
381
+ const LC_CHILD = /* @__PURE__ */ Symbol.for("lc:child_config");
382
+ const presentConfig = config.extra?.[LC_CHILD] ?? this.extra[LC_CHILD];
383
+ if (isRunnableConfigLike(presentConfig)) {
384
+ const newConfig = { ...presentConfig };
385
+ const callbacks = isCallbackManagerLike(newConfig.callbacks) ? newConfig.callbacks.copy?.() : void 0;
386
+ if (callbacks) {
387
+ Object.assign(callbacks, { _parentRunId: child.id });
388
+ callbacks.handlers?.find(isLangChainTracerLike)?.updateFromRunTree?.(child);
389
+ newConfig.callbacks = callbacks;
390
+ }
391
+ child.extra[LC_CHILD] = newConfig;
392
+ }
393
+ const visited = /* @__PURE__ */ new Set();
394
+ let current = this;
395
+ while (current != null && !visited.has(current.id)) {
396
+ visited.add(current.id);
397
+ current.child_execution_order = Math.max(current.child_execution_order, child_execution_order);
398
+ current = current.parent_run;
399
+ }
400
+ this.child_runs.push(child);
401
+ return child;
402
+ }
403
+ async end(outputs, error, endTime = Date.now(), metadata) {
404
+ this.outputs = this.outputs ?? outputs;
405
+ this.error = this.error ?? error;
406
+ this.end_time = this.end_time ?? endTime;
407
+ if (metadata && Object.keys(metadata).length > 0) {
408
+ this.extra = this.extra ? { ...this.extra, metadata: { ...this.extra.metadata, ...metadata } } : { metadata };
409
+ }
410
+ }
411
+ _convertToCreate(run, runtimeEnv, excludeChildRuns = true) {
412
+ const runExtra = run.extra ?? {};
413
+ if (runExtra?.runtime?.library === void 0) {
414
+ if (!runExtra.runtime) {
415
+ runExtra.runtime = {};
416
+ }
417
+ if (runtimeEnv) {
418
+ for (const [k, v] of Object.entries(runtimeEnv)) {
419
+ if (!runExtra.runtime[k]) {
420
+ runExtra.runtime[k] = v;
421
+ }
422
+ }
423
+ }
424
+ }
425
+ let child_runs;
426
+ let parent_run_id;
427
+ if (!excludeChildRuns) {
428
+ child_runs = run.child_runs.map((child_run) => this._convertToCreate(child_run, runtimeEnv, excludeChildRuns));
429
+ parent_run_id = void 0;
430
+ } else {
431
+ parent_run_id = run.parent_run?.id ?? run.parent_run_id;
432
+ child_runs = [];
433
+ }
92
434
  return {
93
- newDocument: document,
94
- removed: removedList[0]
435
+ id: run.id,
436
+ name: run.name,
437
+ start_time: run._serialized_start_time ?? run.start_time,
438
+ end_time: run.end_time,
439
+ run_type: run.run_type,
440
+ reference_example_id: run.reference_example_id,
441
+ extra: runExtra,
442
+ serialized: run.serialized,
443
+ error: run.error,
444
+ inputs: run.inputs,
445
+ outputs: run.outputs,
446
+ session_name: run.project_name,
447
+ child_runs,
448
+ parent_run_id,
449
+ trace_id: run.trace_id,
450
+ dotted_order: run.dotted_order,
451
+ tags: run.tags,
452
+ attachments: run.attachments,
453
+ events: run.events
95
454
  };
96
- },
97
- replace: function(arr, i, document) {
98
- var removed = arr[i];
99
- arr[i] = this.value;
455
+ }
456
+ _sliceParentId(parentId, run) {
457
+ if (run.dotted_order) {
458
+ const segs = run.dotted_order.split(".");
459
+ let startIdx = null;
460
+ for (let idx = 0; idx < segs.length; idx++) {
461
+ const segId = segs[idx].slice(-36);
462
+ if (segId === parentId) {
463
+ startIdx = idx;
464
+ break;
465
+ }
466
+ }
467
+ if (startIdx !== null) {
468
+ const trimmedSegs = segs.slice(startIdx + 1);
469
+ run.dotted_order = trimmedSegs.join(".");
470
+ if (trimmedSegs.length > 0) {
471
+ run.trace_id = trimmedSegs[0].slice(-36);
472
+ } else {
473
+ run.trace_id = run.id;
474
+ }
475
+ }
476
+ }
477
+ if (run.parent_run_id === parentId) {
478
+ run.parent_run_id = void 0;
479
+ }
480
+ }
481
+ _setReplicaTraceRoot(replicaKey, traceRootId) {
482
+ const replicaTraceRoots = getContextVar(this, _REPLICA_TRACE_ROOTS_KEY) ?? {};
483
+ replicaTraceRoots[replicaKey] = traceRootId;
484
+ setContextVar(this, _REPLICA_TRACE_ROOTS_KEY, replicaTraceRoots);
485
+ for (const child of this.child_runs) {
486
+ child._setReplicaTraceRoot(replicaKey, traceRootId);
487
+ }
488
+ }
489
+ _remapForProject(params) {
490
+ const { projectName, runtimeEnv, excludeChildRuns = true, reroot = false, distributedParentId, apiUrl, apiKey, workspaceId } = params;
491
+ const baseRun = this._convertToCreate(this, runtimeEnv, excludeChildRuns);
492
+ if (projectName === this.project_name) {
493
+ return {
494
+ ...baseRun,
495
+ session_name: projectName
496
+ };
497
+ }
498
+ if (reroot) {
499
+ if (distributedParentId) {
500
+ this._sliceParentId(distributedParentId, baseRun);
501
+ } else {
502
+ baseRun.parent_run_id = void 0;
503
+ if (baseRun.dotted_order) {
504
+ const segs = baseRun.dotted_order.split(".");
505
+ if (segs.length > 0) {
506
+ baseRun.dotted_order = segs[segs.length - 1];
507
+ baseRun.trace_id = baseRun.id;
508
+ }
509
+ }
510
+ }
511
+ const replicaKey = getReplicaKey({
512
+ projectName,
513
+ apiUrl,
514
+ apiKey,
515
+ workspaceId
516
+ });
517
+ this._setReplicaTraceRoot(replicaKey, baseRun.id);
518
+ }
519
+ let ancestorRerootedTraceId;
520
+ if (!reroot) {
521
+ const replicaTraceRoots = getContextVar(this, _REPLICA_TRACE_ROOTS_KEY) ?? {};
522
+ const replicaKey = getReplicaKey({
523
+ projectName,
524
+ apiUrl,
525
+ apiKey,
526
+ workspaceId
527
+ });
528
+ ancestorRerootedTraceId = replicaTraceRoots[replicaKey];
529
+ if (ancestorRerootedTraceId) {
530
+ baseRun.trace_id = ancestorRerootedTraceId;
531
+ if (baseRun.dotted_order) {
532
+ const segs = baseRun.dotted_order.split(".");
533
+ let rootIdx = null;
534
+ for (let idx = 0; idx < segs.length; idx++) {
535
+ const segId = segs[idx].slice(-36);
536
+ if (segId === ancestorRerootedTraceId) {
537
+ rootIdx = idx;
538
+ break;
539
+ }
540
+ }
541
+ if (rootIdx !== null) {
542
+ const trimmedSegs = segs.slice(rootIdx);
543
+ baseRun.dotted_order = trimmedSegs.join(".");
544
+ }
545
+ }
546
+ }
547
+ }
548
+ const oldId = baseRun.id;
549
+ const newId = v5(`${oldId}:${projectName}`, UUID_NAMESPACE_DNS);
550
+ let newTraceId;
551
+ if (baseRun.trace_id) {
552
+ newTraceId = v5(`${baseRun.trace_id}:${projectName}`, UUID_NAMESPACE_DNS);
553
+ } else {
554
+ newTraceId = newId;
555
+ }
556
+ let newParentId;
557
+ if (baseRun.parent_run_id) {
558
+ newParentId = v5(`${baseRun.parent_run_id}:${projectName}`, UUID_NAMESPACE_DNS);
559
+ }
560
+ let newDottedOrder;
561
+ if (baseRun.dotted_order) {
562
+ const segs = baseRun.dotted_order.split(".");
563
+ const remappedSegs = segs.map((seg) => {
564
+ const segId = seg.slice(-36);
565
+ const remappedId = v5(`${segId}:${projectName}`, UUID_NAMESPACE_DNS);
566
+ return seg.slice(0, -36) + remappedId;
567
+ });
568
+ newDottedOrder = remappedSegs.join(".");
569
+ }
100
570
  return {
101
- newDocument: document,
102
- removed
571
+ ...baseRun,
572
+ id: newId,
573
+ trace_id: newTraceId,
574
+ parent_run_id: newParentId,
575
+ dotted_order: newDottedOrder,
576
+ session_name: projectName
103
577
  };
104
- },
105
- move: objOps.move,
106
- copy: objOps.copy,
107
- test: objOps.test,
108
- _get: objOps._get
109
- };
110
- function getValueByPointer(document, pointer) {
111
- if (pointer == "") return document;
112
- var getOriginalDestination = {
113
- op: "_get",
114
- path: pointer
115
- };
116
- applyOperation(document, getOriginalDestination);
117
- return getOriginalDestination.value;
118
- }
119
- function applyOperation(document, operation, validateOperation = false, mutateDocument = true, banPrototypeModifications = true, index = 0) {
120
- if (validateOperation) if (typeof validateOperation == "function") validateOperation(operation, 0, document, operation.path);
121
- else validator(operation, 0);
122
- if (operation.path === "") {
123
- let returnValue = { newDocument: document };
124
- if (operation.op === "add") {
125
- returnValue.newDocument = operation.value;
126
- return returnValue;
127
- } else if (operation.op === "replace") {
128
- returnValue.newDocument = operation.value;
129
- returnValue.removed = document;
130
- return returnValue;
131
- } else if (operation.op === "move" || operation.op === "copy") {
132
- returnValue.newDocument = getValueByPointer(document, operation.from);
133
- if (operation.op === "move") returnValue.removed = document;
134
- return returnValue;
135
- } else if (operation.op === "test") {
136
- returnValue.test = _areEquals(document, operation.value);
137
- if (returnValue.test === false) throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
138
- returnValue.newDocument = document;
139
- return returnValue;
140
- } else if (operation.op === "remove") {
141
- returnValue.removed = document;
142
- returnValue.newDocument = null;
143
- return returnValue;
144
- } else if (operation.op === "_get") {
145
- operation.value = document;
146
- return returnValue;
147
- } else if (validateOperation) throw new JsonPatchError("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", index, operation, document);
148
- else return returnValue;
149
- } else {
150
- if (!mutateDocument) document = _deepClone(document);
151
- const path = operation.path || "";
152
- const keys = path.split("/");
153
- let obj = document;
154
- let t = 1;
155
- let len = keys.length;
156
- let existingPathFragment = void 0;
157
- let key;
158
- let validateFunction;
159
- if (typeof validateOperation == "function") validateFunction = validateOperation;
160
- else validateFunction = validator;
161
- while (true) {
162
- key = keys[t];
163
- if (key && key.indexOf("~") != -1) key = unescapePathComponent(key);
164
- if (banPrototypeModifications && (key == "__proto__" || key == "prototype" && t > 0 && keys[t - 1] == "constructor")) throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");
165
- if (validateOperation) {
166
- if (existingPathFragment === void 0) {
167
- if (obj[key] === void 0) existingPathFragment = keys.slice(0, t).join("/");
168
- else if (t == len - 1) existingPathFragment = operation.path;
169
- if (existingPathFragment !== void 0) validateFunction(operation, 0, document, existingPathFragment);
578
+ }
579
+ async postRun(excludeChildRuns = true) {
580
+ if (this._awaitInputsOnPost) {
581
+ this.inputs = await this.inputs;
582
+ }
583
+ try {
584
+ const runtimeEnv = getRuntimeEnvironment();
585
+ if (this.replicas && this.replicas.length > 0) {
586
+ for (const { projectName, apiKey, apiUrl, workspaceId, reroot } of this.replicas) {
587
+ const runCreate = this._remapForProject({
588
+ projectName: projectName ?? this.project_name,
589
+ runtimeEnv,
590
+ excludeChildRuns: true,
591
+ reroot,
592
+ distributedParentId: this.distributedParentId,
593
+ apiUrl,
594
+ apiKey,
595
+ workspaceId
596
+ });
597
+ await this.client.createRun(runCreate, {
598
+ apiKey,
599
+ apiUrl,
600
+ workspaceId
601
+ });
170
602
  }
603
+ } else {
604
+ const runCreate = this._convertToCreate(this, runtimeEnv, excludeChildRuns);
605
+ await this.client.createRun(runCreate);
171
606
  }
172
- t++;
173
- if (Array.isArray(obj)) {
174
- if (key === "-") key = obj.length;
175
- else if (validateOperation && !isInteger(key)) throw new JsonPatchError("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", index, operation, document);
176
- else if (isInteger(key)) key = ~~key;
177
- if (t >= len) {
178
- if (validateOperation && operation.op === "add" && key > obj.length) throw new JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", index, operation, document);
179
- const returnValue = arrOps[operation.op].call(operation, obj, key, document);
180
- if (returnValue.test === false) throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
181
- return returnValue;
607
+ if (!excludeChildRuns) {
608
+ warnOnce("Posting with excludeChildRuns=false is deprecated and will be removed in a future version.");
609
+ for (const childRun of this.child_runs) {
610
+ await childRun.postRun(false);
182
611
  }
183
- } else if (t >= len) {
184
- const returnValue = objOps[operation.op].call(operation, obj, key, document);
185
- if (returnValue.test === false) throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
186
- return returnValue;
187
612
  }
188
- obj = obj[key];
189
- if (validateOperation && t < len && (!obj || typeof obj !== "object")) throw new JsonPatchError("Cannot perform operation at the desired path", "OPERATION_PATH_UNRESOLVABLE", index, operation, document);
613
+ this.child_runs = [];
614
+ } catch (error) {
615
+ console.error(`Error in postRun for run ${this.id}:`, error);
190
616
  }
191
617
  }
192
- }
193
- function applyPatch(document, patch, validateOperation, mutateDocument = true, banPrototypeModifications = true) {
194
- if (validateOperation) {
195
- if (!Array.isArray(patch)) throw new JsonPatchError("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
618
+ async patchRun(options) {
619
+ if (this.replicas && this.replicas.length > 0) {
620
+ for (const { projectName, apiKey, apiUrl, workspaceId, updates, reroot } of this.replicas) {
621
+ const runData = this._remapForProject({
622
+ projectName: projectName ?? this.project_name,
623
+ runtimeEnv: void 0,
624
+ excludeChildRuns: true,
625
+ reroot,
626
+ distributedParentId: this.distributedParentId,
627
+ apiUrl,
628
+ apiKey,
629
+ workspaceId
630
+ });
631
+ const updatePayload = {
632
+ id: runData.id,
633
+ name: runData.name,
634
+ run_type: runData.run_type,
635
+ start_time: runData.start_time,
636
+ outputs: runData.outputs,
637
+ error: runData.error,
638
+ parent_run_id: runData.parent_run_id,
639
+ session_name: runData.session_name,
640
+ reference_example_id: runData.reference_example_id,
641
+ end_time: runData.end_time,
642
+ dotted_order: runData.dotted_order,
643
+ trace_id: runData.trace_id,
644
+ events: runData.events,
645
+ tags: runData.tags,
646
+ extra: runData.extra,
647
+ attachments: this.attachments,
648
+ ...updates
649
+ };
650
+ if (!options?.excludeInputs) {
651
+ updatePayload.inputs = runData.inputs;
652
+ }
653
+ await this.client.updateRun(runData.id, updatePayload, {
654
+ apiKey,
655
+ apiUrl,
656
+ workspaceId
657
+ });
658
+ }
659
+ } else {
660
+ try {
661
+ const runUpdate = {
662
+ name: this.name,
663
+ run_type: this.run_type,
664
+ start_time: this._serialized_start_time ?? this.start_time,
665
+ end_time: this.end_time,
666
+ error: this.error,
667
+ outputs: this.outputs,
668
+ parent_run_id: this.parent_run?.id ?? this.parent_run_id,
669
+ reference_example_id: this.reference_example_id,
670
+ extra: this.extra,
671
+ events: this.events,
672
+ dotted_order: this.dotted_order,
673
+ trace_id: this.trace_id,
674
+ tags: this.tags,
675
+ attachments: this.attachments,
676
+ session_name: this.project_name
677
+ };
678
+ if (!options?.excludeInputs) {
679
+ runUpdate.inputs = this.inputs;
680
+ }
681
+ await this.client.updateRun(this.id, runUpdate);
682
+ } catch (error) {
683
+ console.error(`Error in patchRun for run ${this.id}`, error);
684
+ }
685
+ }
686
+ this.child_runs = [];
196
687
  }
197
- if (!mutateDocument) document = _deepClone(document);
198
- const results = new Array(patch.length);
199
- for (let i = 0, length = patch.length; i < length; i++) {
200
- results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
201
- document = results[i].newDocument;
688
+ toJSON() {
689
+ return this._convertToCreate(this, void 0, false);
202
690
  }
203
- results.newDocument = document;
204
- return results;
205
- }
206
- function applyReducer(document, operation, index) {
207
- const operationResult = applyOperation(document, operation);
208
- if (operationResult.test === false) throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
209
- return operationResult.newDocument;
210
- }
211
- function validator(operation, index, document, existingPathFragment) {
212
- if (typeof operation !== "object" || operation === null || Array.isArray(operation)) throw new JsonPatchError("Operation is not an object", "OPERATION_NOT_AN_OBJECT", index, operation, document);
213
- else if (!objOps[operation.op]) throw new JsonPatchError("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", index, operation, document);
214
- else if (typeof operation.path !== "string") throw new JsonPatchError("Operation `path` property is not a string", "OPERATION_PATH_INVALID", index, operation, document);
215
- else if (operation.path.indexOf("/") !== 0 && operation.path.length > 0) throw new JsonPatchError('Operation `path` property must start with "/"', "OPERATION_PATH_INVALID", index, operation, document);
216
- else if ((operation.op === "move" || operation.op === "copy") && typeof operation.from !== "string") throw new JsonPatchError("Operation `from` property is not present (applicable in `move` and `copy` operations)", "OPERATION_FROM_REQUIRED", index, operation, document);
217
- else if ((operation.op === "add" || operation.op === "replace" || operation.op === "test") && operation.value === void 0) throw new JsonPatchError("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_REQUIRED", index, operation, document);
218
- else if ((operation.op === "add" || operation.op === "replace" || operation.op === "test") && hasUndefined(operation.value)) throw new JsonPatchError("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED", index, operation, document);
219
- else if (document) {
220
- if (operation.op == "add") {
221
- var pathLen = operation.path.split("/").length;
222
- var existingPathLen = existingPathFragment.split("/").length;
223
- if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) throw new JsonPatchError("Cannot perform an `add` operation at the desired path", "OPERATION_PATH_CANNOT_ADD", index, operation, document);
224
- } else if (operation.op === "replace" || operation.op === "remove" || operation.op === "_get") {
225
- if (operation.path !== existingPathFragment) throw new JsonPatchError("Cannot perform the operation at a path that does not exist", "OPERATION_PATH_UNRESOLVABLE", index, operation, document);
226
- } else if (operation.op === "move" || operation.op === "copy") {
227
- var existingValue = {
228
- op: "_get",
229
- path: operation.from,
230
- value: void 0
231
- };
232
- var error = validate([existingValue], document);
233
- if (error && error.name === "OPERATION_PATH_UNRESOLVABLE") throw new JsonPatchError("Cannot perform the operation from a path that does not exist", "OPERATION_FROM_UNRESOLVABLE", index, operation, document);
691
+ /**
692
+ * Add an event to the run tree.
693
+ * @param event - A single event or string to add
694
+ */
695
+ addEvent(event) {
696
+ if (!this.events) {
697
+ this.events = [];
698
+ }
699
+ if (typeof event === "string") {
700
+ this.events.push({
701
+ name: "event",
702
+ time: (/* @__PURE__ */ new Date()).toISOString(),
703
+ message: event
704
+ });
705
+ } else {
706
+ this.events.push({
707
+ ...event,
708
+ time: event.time ?? (/* @__PURE__ */ new Date()).toISOString()
709
+ });
234
710
  }
235
711
  }
712
+ static fromRunnableConfig(parentConfig, props) {
713
+ const callbackManager = parentConfig?.callbacks;
714
+ let parentRun;
715
+ let projectName;
716
+ let client;
717
+ let tracingEnabled = isTracingEnabled();
718
+ if (callbackManager) {
719
+ const parentRunId = callbackManager?.getParentRunId?.() ?? "";
720
+ const langChainTracer = callbackManager?.handlers?.find((handler) => handler?.name == "langchain_tracer");
721
+ parentRun = langChainTracer?.getRun?.(parentRunId);
722
+ projectName = langChainTracer?.projectName;
723
+ client = langChainTracer?.client;
724
+ tracingEnabled = tracingEnabled || !!langChainTracer;
725
+ }
726
+ if (!parentRun) {
727
+ return new RunTree({
728
+ ...props,
729
+ client,
730
+ tracingEnabled,
731
+ project_name: projectName
732
+ });
733
+ }
734
+ const parentRunTree = new RunTree({
735
+ name: parentRun.name,
736
+ id: parentRun.id,
737
+ trace_id: parentRun.trace_id,
738
+ dotted_order: parentRun.dotted_order,
739
+ client,
740
+ tracingEnabled,
741
+ project_name: projectName,
742
+ tags: [
743
+ ...new Set((parentRun?.tags ?? []).concat(parentConfig?.tags ?? []))
744
+ ],
745
+ extra: {
746
+ metadata: {
747
+ ...parentRun?.extra?.metadata,
748
+ ...parentConfig?.metadata
749
+ }
750
+ }
751
+ });
752
+ return parentRunTree.createChild(props);
753
+ }
754
+ static fromDottedOrder(dottedOrder) {
755
+ return this.fromHeaders({ "langsmith-trace": dottedOrder });
756
+ }
757
+ static fromHeaders(headers, inheritArgs) {
758
+ const rawHeaders = "get" in headers && typeof headers.get === "function" ? {
759
+ "langsmith-trace": headers.get("langsmith-trace"),
760
+ baggage: headers.get("baggage")
761
+ } : headers;
762
+ const headerTrace = rawHeaders["langsmith-trace"];
763
+ if (!headerTrace || typeof headerTrace !== "string")
764
+ return void 0;
765
+ const parentDottedOrder = headerTrace.trim();
766
+ const parsedDottedOrder = parentDottedOrder.split(".").map((part) => {
767
+ const [strTime, uuid] = part.split("Z");
768
+ return { strTime, time: Date.parse(strTime + "Z"), uuid };
769
+ });
770
+ const traceId = parsedDottedOrder[0].uuid;
771
+ const config = {
772
+ ...inheritArgs,
773
+ name: inheritArgs?.["name"] ?? "parent",
774
+ run_type: inheritArgs?.["run_type"] ?? "chain",
775
+ start_time: inheritArgs?.["start_time"] ?? Date.now(),
776
+ id: parsedDottedOrder.at(-1)?.uuid,
777
+ trace_id: traceId,
778
+ dotted_order: parentDottedOrder
779
+ };
780
+ if (rawHeaders["baggage"] && typeof rawHeaders["baggage"] === "string") {
781
+ const baggage = Baggage.fromHeader(rawHeaders["baggage"]);
782
+ config.metadata = baggage.metadata;
783
+ config.tags = baggage.tags;
784
+ config.project_name = baggage.project_name;
785
+ config.replicas = baggage.replicas;
786
+ }
787
+ const runTree = new RunTree(config);
788
+ runTree.distributedParentId = runTree.id;
789
+ return runTree;
790
+ }
791
+ toHeaders(headers) {
792
+ const result = {
793
+ "langsmith-trace": this.dotted_order,
794
+ baggage: new Baggage(this.extra?.metadata, this.tags, this.project_name, this.replicas).toHeader()
795
+ };
796
+ if (headers) {
797
+ for (const [key, value] of Object.entries(result)) {
798
+ headers.set(key, value);
799
+ }
800
+ }
801
+ return result;
802
+ }
803
+ }
804
+ Object.defineProperty(RunTree, "sharedClient", {
805
+ enumerable: true,
806
+ configurable: true,
807
+ writable: true,
808
+ value: null
809
+ });
810
+ function isRunTree(x) {
811
+ return x != null && typeof x.createChild === "function" && typeof x.postRun === "function";
812
+ }
813
+ function isLangChainTracerLike(x) {
814
+ return typeof x === "object" && x != null && typeof x.name === "string" && x.name === "langchain_tracer";
815
+ }
816
+ function containsLangChainTracerLike(x) {
817
+ return Array.isArray(x) && x.some((callback) => isLangChainTracerLike(callback));
236
818
  }
237
- function validate(sequence, document, externalValidator) {
819
+ function isCallbackManagerLike(x) {
820
+ return typeof x === "object" && x != null && Array.isArray(x.handlers);
821
+ }
822
+ function isRunnableConfigLike(x) {
823
+ const callbacks = x?.callbacks;
824
+ return x != null && typeof callbacks === "object" && // Callback manager with a langchain tracer
825
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
826
+ (containsLangChainTracerLike(callbacks?.handlers) || // Or it's an array with a LangChainTracerLike object within it
827
+ containsLangChainTracerLike(callbacks));
828
+ }
829
+ function _getWriteReplicasFromEnv() {
830
+ const envVar = getEnvironmentVariable("LANGSMITH_RUNS_ENDPOINTS");
831
+ if (!envVar)
832
+ return [];
238
833
  try {
239
- if (!Array.isArray(sequence)) throw new JsonPatchError("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
240
- if (document) applyPatch(_deepClone(document), _deepClone(sequence), externalValidator || true);
241
- else {
242
- externalValidator = externalValidator || validator;
243
- for (var i = 0; i < sequence.length; i++) externalValidator(sequence[i], i, document, void 0);
834
+ const parsed = JSON.parse(envVar);
835
+ if (Array.isArray(parsed)) {
836
+ const replicas = [];
837
+ for (const item of parsed) {
838
+ if (typeof item !== "object" || item === null) {
839
+ console.warn(`Invalid item type in LANGSMITH_RUNS_ENDPOINTS: expected object, got ${typeof item}`);
840
+ continue;
841
+ }
842
+ if (typeof item.api_url !== "string") {
843
+ console.warn(`Invalid api_url type in LANGSMITH_RUNS_ENDPOINTS: expected string, got ${typeof item.api_url}`);
844
+ continue;
845
+ }
846
+ if (typeof item.api_key !== "string") {
847
+ console.warn(`Invalid api_key type in LANGSMITH_RUNS_ENDPOINTS: expected string, got ${typeof item.api_key}`);
848
+ continue;
849
+ }
850
+ replicas.push({
851
+ apiUrl: item.api_url.replace(/\/$/, ""),
852
+ apiKey: item.api_key
853
+ });
854
+ }
855
+ return replicas;
856
+ } else if (typeof parsed === "object" && parsed !== null) {
857
+ _checkEndpointEnvUnset(parsed);
858
+ const replicas = [];
859
+ for (const [url, key] of Object.entries(parsed)) {
860
+ const cleanUrl = url.replace(/\/$/, "");
861
+ if (typeof key === "string") {
862
+ replicas.push({
863
+ apiUrl: cleanUrl,
864
+ apiKey: key
865
+ });
866
+ } else {
867
+ console.warn(`Invalid value type in LANGSMITH_RUNS_ENDPOINTS for URL ${url}: expected string, got ${typeof key}`);
868
+ continue;
869
+ }
870
+ }
871
+ return replicas;
872
+ } else {
873
+ console.warn(`Invalid LANGSMITH_RUNS_ENDPOINTS – must be valid JSON array of objects with api_url and api_key properties, or object mapping url->apiKey, got ${typeof parsed}`);
874
+ return [];
244
875
  }
245
876
  } catch (e) {
246
- if (e instanceof JsonPatchError) return e;
247
- else throw e;
877
+ if (isConflictingEndpointsError(e)) {
878
+ throw e;
879
+ }
880
+ console.warn("Invalid LANGSMITH_RUNS_ENDPOINTS – must be valid JSON array of objects with api_url and api_key properties, or object mapping url->apiKey");
881
+ return [];
882
+ }
883
+ }
884
+ function _ensureWriteReplicas(replicas) {
885
+ if (replicas) {
886
+ return replicas.map((replica) => {
887
+ if (Array.isArray(replica)) {
888
+ return {
889
+ projectName: replica[0],
890
+ updates: replica[1]
891
+ };
892
+ }
893
+ return replica;
894
+ });
248
895
  }
896
+ return _getWriteReplicasFromEnv();
249
897
  }
250
- function _areEquals(a, b) {
251
- if (a === b) return true;
252
- if (a && b && typeof a == "object" && typeof b == "object") {
253
- var arrA = Array.isArray(a), arrB = Array.isArray(b), i, length, key;
254
- if (arrA && arrB) {
255
- length = a.length;
256
- if (length != b.length) return false;
257
- for (i = length; i-- !== 0; ) if (!_areEquals(a[i], b[i])) return false;
258
- return true;
259
- }
260
- if (arrA != arrB) return false;
261
- var keys = Object.keys(a);
262
- length = keys.length;
263
- if (length !== Object.keys(b).length) return false;
264
- for (i = length; i-- !== 0; ) if (!b.hasOwnProperty(keys[i])) return false;
265
- for (i = length; i-- !== 0; ) {
266
- key = keys[i];
267
- if (!_areEquals(a[key], b[key])) return false;
268
- }
269
- return true;
898
+ function _checkEndpointEnvUnset(parsed) {
899
+ if (Object.keys(parsed).length > 0 && getLangSmithEnvironmentVariable("ENDPOINT")) {
900
+ throw new ConflictingEndpointsError();
270
901
  }
271
- return a !== a && b !== b;
272
902
  }
273
903
  export {
274
- _areEquals,
275
- applyOperation,
276
- applyPatch,
277
- applyReducer,
278
- core_exports,
279
- getValueByPointer,
280
- validate,
281
- validator
904
+ RunTree,
905
+ convertToDottedOrderFormat,
906
+ isRunTree,
907
+ isRunnableConfigLike
282
908
  };
283
909
  //# sourceMappingURL=index.es121.js.map