@anvia/core 1.1.2 → 1.2.0

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 (598) hide show
  1. package/README.md +226 -0
  2. package/dist/agent/agent-stream.js +7 -0
  3. package/dist/agent/agent-stream.js.map +1 -0
  4. package/dist/agent/agent-tool.js +24 -0
  5. package/dist/agent/agent-tool.js.map +1 -0
  6. package/dist/agent/agent.js +89 -0
  7. package/dist/agent/agent.js.map +1 -0
  8. package/dist/agent/errors.js +17 -0
  9. package/dist/agent/errors.js.map +1 -0
  10. package/dist/agent/ids.js +7 -0
  11. package/dist/agent/ids.js.map +1 -0
  12. package/dist/agent/index.d.ts +127 -9
  13. package/dist/agent/index.js +103 -21
  14. package/dist/agent/interactions/index.js +2 -2
  15. package/dist/agent/interactions.js +22 -0
  16. package/dist/agent/interactions.js.map +1 -0
  17. package/dist/agent/lifecycle.js +9 -0
  18. package/dist/agent/lifecycle.js.map +1 -0
  19. package/dist/agent/output-schema.js +10 -0
  20. package/dist/agent/output-schema.js.map +1 -0
  21. package/dist/agent/resolve-options.js +46 -0
  22. package/dist/agent/resolve-options.js.map +1 -0
  23. package/dist/agent/resolved-agent.js +92 -0
  24. package/dist/agent/resolved-agent.js.map +1 -0
  25. package/dist/agent/run-types.js +1 -0
  26. package/dist/agent/run-types.js.map +1 -0
  27. package/dist/agent/snapshot.js +17 -0
  28. package/dist/agent/snapshot.js.map +1 -0
  29. package/dist/agent/team/agent-team.js +98 -0
  30. package/dist/agent/team/agent-team.js.map +1 -0
  31. package/dist/agent/team/errors.js +9 -0
  32. package/dist/agent/team/errors.js.map +1 -0
  33. package/dist/agent/team/index.js +104 -0
  34. package/dist/agent/team/index.js.map +1 -0
  35. package/dist/agent/team/types.js +1 -0
  36. package/dist/agent/team/types.js.map +1 -0
  37. package/dist/agent/tool-catalog.js +37 -0
  38. package/dist/agent/tool-catalog.js.map +1 -0
  39. package/dist/agent/tool-state.js +11 -0
  40. package/dist/agent/tool-state.js.map +1 -0
  41. package/dist/agent/types.js +1 -0
  42. package/dist/agent/types.js.map +1 -0
  43. package/dist/agent/vector-context.js +10 -0
  44. package/dist/agent/vector-context.js.map +1 -0
  45. package/dist/{agent-DTmzs1Qr.d.ts → agent-C9VhENdj.d.ts} +2 -3
  46. package/dist/{chunk-2QZJTG2E.js → chunk-23GEYG2X.js} +11 -71
  47. package/dist/chunk-23GEYG2X.js.map +1 -0
  48. package/dist/{chunk-I3Q7XSBB.js → chunk-23LRXKQX.js} +6 -4
  49. package/dist/{chunk-I3Q7XSBB.js.map → chunk-23LRXKQX.js.map} +1 -1
  50. package/dist/{chunk-YK4WAAS4.js → chunk-2NLINXRF.js} +1 -1
  51. package/dist/{chunk-SPD4XVR7.js → chunk-2XSMGVBG.js} +1 -1
  52. package/dist/chunk-3J2CSVPR.js +1 -0
  53. package/dist/chunk-3J2CSVPR.js.map +1 -0
  54. package/dist/chunk-3P3YVJ7V.js +1 -0
  55. package/dist/chunk-3P3YVJ7V.js.map +1 -0
  56. package/dist/chunk-3TAQXJBC.js +107 -0
  57. package/dist/chunk-3TAQXJBC.js.map +1 -0
  58. package/dist/chunk-47NTHIVB.js +76 -0
  59. package/dist/chunk-47NTHIVB.js.map +1 -0
  60. package/dist/chunk-4AW2633B.js +9 -0
  61. package/dist/chunk-4AW2633B.js.map +1 -0
  62. package/dist/{chunk-3XQGVDU5.js → chunk-4C7AXYOM.js} +1 -1
  63. package/dist/{chunk-IZNOP6JG.js → chunk-4FIVU53H.js} +1 -1
  64. package/dist/chunk-4ITAV7YA.js +1 -0
  65. package/dist/chunk-4ITAV7YA.js.map +1 -0
  66. package/dist/{chunk-7JLAIN6E.js → chunk-4ONUNWGC.js} +2 -2
  67. package/dist/chunk-4UUIGAIX.js +1 -0
  68. package/dist/chunk-4UUIGAIX.js.map +1 -0
  69. package/dist/chunk-53TPAXYR.js +1 -0
  70. package/dist/chunk-53TPAXYR.js.map +1 -0
  71. package/dist/chunk-5AETKC4L.js +107 -0
  72. package/dist/chunk-5AETKC4L.js.map +1 -0
  73. package/dist/chunk-5I2NVRHC.js +146 -0
  74. package/dist/chunk-5I2NVRHC.js.map +1 -0
  75. package/dist/chunk-5IURMWFN.js +53 -0
  76. package/dist/chunk-5IURMWFN.js.map +1 -0
  77. package/dist/chunk-5M6GTA3T.js +1 -0
  78. package/dist/chunk-5M6GTA3T.js.map +1 -0
  79. package/dist/chunk-5N5W7CX7.js +18 -0
  80. package/dist/chunk-5N5W7CX7.js.map +1 -0
  81. package/dist/chunk-5P2YOQSA.js +355 -0
  82. package/dist/chunk-5P2YOQSA.js.map +1 -0
  83. package/dist/chunk-5S7T2URX.js +1 -0
  84. package/dist/chunk-5S7T2URX.js.map +1 -0
  85. package/dist/chunk-5V533R7F.js +19 -0
  86. package/dist/chunk-5V533R7F.js.map +1 -0
  87. package/dist/chunk-5WLIHNNJ.js +56 -0
  88. package/dist/chunk-5WLIHNNJ.js.map +1 -0
  89. package/dist/chunk-6BTJC3ES.js +37 -0
  90. package/dist/chunk-6BTJC3ES.js.map +1 -0
  91. package/dist/chunk-6N4ENZO4.js +24 -0
  92. package/dist/chunk-6N4ENZO4.js.map +1 -0
  93. package/dist/{chunk-4UQALF5Y.js → chunk-6RQYWZI3.js} +2 -36
  94. package/dist/chunk-6RQYWZI3.js.map +1 -0
  95. package/dist/chunk-6TAWRKFK.js +86 -0
  96. package/dist/chunk-6TAWRKFK.js.map +1 -0
  97. package/dist/chunk-7F53DOML.js +53 -0
  98. package/dist/chunk-7F53DOML.js.map +1 -0
  99. package/dist/chunk-7KAGWJ5M.js +112 -0
  100. package/dist/chunk-7KAGWJ5M.js.map +1 -0
  101. package/dist/chunk-7LBPRXZP.js +1 -0
  102. package/dist/chunk-7LBPRXZP.js.map +1 -0
  103. package/dist/chunk-A7BXVZXZ.js +25 -0
  104. package/dist/chunk-A7BXVZXZ.js.map +1 -0
  105. package/dist/chunk-B47EXUHL.js +67 -0
  106. package/dist/chunk-B47EXUHL.js.map +1 -0
  107. package/dist/chunk-B5JQDR33.js +14 -0
  108. package/dist/chunk-B5JQDR33.js.map +1 -0
  109. package/dist/chunk-B5YTCKUJ.js +158 -0
  110. package/dist/chunk-B5YTCKUJ.js.map +1 -0
  111. package/dist/chunk-BDDC72GF.js +189 -0
  112. package/dist/chunk-BDDC72GF.js.map +1 -0
  113. package/dist/chunk-BDKFFFVX.js +342 -0
  114. package/dist/chunk-BDKFFFVX.js.map +1 -0
  115. package/dist/{chunk-QGX73TSQ.js → chunk-BONQTXRQ.js} +3 -12
  116. package/dist/chunk-BONQTXRQ.js.map +1 -0
  117. package/dist/chunk-BUPC72Y2.js +1007 -0
  118. package/dist/chunk-BUPC72Y2.js.map +1 -0
  119. package/dist/chunk-CKKNO4XB.js +70 -0
  120. package/dist/chunk-CKKNO4XB.js.map +1 -0
  121. package/dist/chunk-CX7ZVTO5.js +22 -0
  122. package/dist/chunk-CX7ZVTO5.js.map +1 -0
  123. package/dist/chunk-DU4WA6LQ.js +1 -0
  124. package/dist/chunk-DU4WA6LQ.js.map +1 -0
  125. package/dist/chunk-EJR6VVB3.js +63 -0
  126. package/dist/chunk-EJR6VVB3.js.map +1 -0
  127. package/dist/chunk-EKZRAWBP.js +110 -0
  128. package/dist/chunk-EKZRAWBP.js.map +1 -0
  129. package/dist/chunk-ENZ2XX27.js +26 -0
  130. package/dist/chunk-ENZ2XX27.js.map +1 -0
  131. package/dist/chunk-EOAJBBII.js +1 -0
  132. package/dist/chunk-EOAJBBII.js.map +1 -0
  133. package/dist/chunk-ERN7P6Q4.js +1 -0
  134. package/dist/chunk-ERN7P6Q4.js.map +1 -0
  135. package/dist/chunk-ESOFEAYK.js +57 -0
  136. package/dist/chunk-ESOFEAYK.js.map +1 -0
  137. package/dist/chunk-ETYB5JO6.js +175 -0
  138. package/dist/chunk-ETYB5JO6.js.map +1 -0
  139. package/dist/chunk-EZR5AV3J.js +74 -0
  140. package/dist/chunk-EZR5AV3J.js.map +1 -0
  141. package/dist/chunk-F2OKLHGB.js +9 -0
  142. package/dist/chunk-F2OKLHGB.js.map +1 -0
  143. package/dist/chunk-F3E2RLC7.js +342 -0
  144. package/dist/chunk-F3E2RLC7.js.map +1 -0
  145. package/dist/chunk-FAPIZJS2.js +54 -0
  146. package/dist/chunk-FAPIZJS2.js.map +1 -0
  147. package/dist/chunk-GDJNOZ47.js +1 -0
  148. package/dist/chunk-GDJNOZ47.js.map +1 -0
  149. package/dist/chunk-GDY2Z2SZ.js +83 -0
  150. package/dist/chunk-GDY2Z2SZ.js.map +1 -0
  151. package/dist/chunk-GLMYZ6OA.js +20 -0
  152. package/dist/chunk-GLMYZ6OA.js.map +1 -0
  153. package/dist/{chunk-XEVOC433.js → chunk-GPVXCY5I.js} +2 -73
  154. package/dist/chunk-GPVXCY5I.js.map +1 -0
  155. package/dist/{chunk-KSKST3KP.js → chunk-H3H74RWJ.js} +1 -1
  156. package/dist/chunk-HAAGSIZH.js +89 -0
  157. package/dist/chunk-HAAGSIZH.js.map +1 -0
  158. package/dist/{chunk-K5L7R7XM.js → chunk-HHMLE3TZ.js} +6 -54
  159. package/dist/chunk-HHMLE3TZ.js.map +1 -0
  160. package/dist/{chunk-JLJMVRRE.js → chunk-HP34GRQX.js} +10 -83
  161. package/dist/chunk-HP34GRQX.js.map +1 -0
  162. package/dist/chunk-HTI343NP.js +1 -0
  163. package/dist/chunk-HTI343NP.js.map +1 -0
  164. package/dist/{chunk-T2C3CGDQ.js → chunk-HTI7DZJM.js} +6 -4
  165. package/dist/{chunk-T2C3CGDQ.js.map → chunk-HTI7DZJM.js.map} +1 -1
  166. package/dist/chunk-IDNL6IH4.js +294 -0
  167. package/dist/chunk-IDNL6IH4.js.map +1 -0
  168. package/dist/chunk-IV6YQTY2.js +47 -0
  169. package/dist/chunk-IV6YQTY2.js.map +1 -0
  170. package/dist/chunk-J4SINPUA.js +939 -0
  171. package/dist/chunk-J4SINPUA.js.map +1 -0
  172. package/dist/chunk-J6S6MT7O.js +32 -0
  173. package/dist/chunk-J6S6MT7O.js.map +1 -0
  174. package/dist/chunk-JB3RFK6K.js +168 -0
  175. package/dist/chunk-JB3RFK6K.js.map +1 -0
  176. package/dist/chunk-JBQNCUXA.js +34 -0
  177. package/dist/chunk-JBQNCUXA.js.map +1 -0
  178. package/dist/chunk-JMJFK3A4.js +1 -0
  179. package/dist/chunk-JMJFK3A4.js.map +1 -0
  180. package/dist/chunk-JMMZICU7.js +74 -0
  181. package/dist/chunk-JMMZICU7.js.map +1 -0
  182. package/dist/chunk-JOQ2T3QP.js +663 -0
  183. package/dist/chunk-JOQ2T3QP.js.map +1 -0
  184. package/dist/chunk-K4IBS7VB.js +55 -0
  185. package/dist/chunk-K4IBS7VB.js.map +1 -0
  186. package/dist/chunk-KBBQSP4M.js +16 -0
  187. package/dist/chunk-KBBQSP4M.js.map +1 -0
  188. package/dist/chunk-KFAVEL5F.js +68 -0
  189. package/dist/chunk-KFAVEL5F.js.map +1 -0
  190. package/dist/chunk-KITX3HDN.js +17 -0
  191. package/dist/chunk-KITX3HDN.js.map +1 -0
  192. package/dist/chunk-KO5NMTAM.js +1 -0
  193. package/dist/chunk-KO5NMTAM.js.map +1 -0
  194. package/dist/chunk-KY4VXIN2.js +118 -0
  195. package/dist/chunk-KY4VXIN2.js.map +1 -0
  196. package/dist/chunk-KZGSXJKU.js +29 -0
  197. package/dist/chunk-KZGSXJKU.js.map +1 -0
  198. package/dist/chunk-LAIATEUB.js +24 -0
  199. package/dist/chunk-LAIATEUB.js.map +1 -0
  200. package/dist/{chunk-OJBFDBLG.js → chunk-LBYJPMHC.js} +2 -2
  201. package/dist/chunk-LKIABZNR.js +49 -0
  202. package/dist/chunk-LKIABZNR.js.map +1 -0
  203. package/dist/chunk-LQJ4KHMY.js +23 -0
  204. package/dist/chunk-LQJ4KHMY.js.map +1 -0
  205. package/dist/chunk-MEN4AFDZ.js +1 -0
  206. package/dist/chunk-MEN4AFDZ.js.map +1 -0
  207. package/dist/chunk-MHOJJYDK.js +93 -0
  208. package/dist/chunk-MHOJJYDK.js.map +1 -0
  209. package/dist/chunk-MJCMKZFP.js +30 -0
  210. package/dist/chunk-MJCMKZFP.js.map +1 -0
  211. package/dist/chunk-MT3BLVYN.js +31 -0
  212. package/dist/chunk-MT3BLVYN.js.map +1 -0
  213. package/dist/chunk-NF6WBPFG.js +37 -0
  214. package/dist/chunk-NF6WBPFG.js.map +1 -0
  215. package/dist/chunk-NNEKBZSM.js +66 -0
  216. package/dist/chunk-NNEKBZSM.js.map +1 -0
  217. package/dist/chunk-NPJ2T3L5.js +19 -0
  218. package/dist/chunk-NPJ2T3L5.js.map +1 -0
  219. package/dist/chunk-NVALGVQG.js +150 -0
  220. package/dist/chunk-NVALGVQG.js.map +1 -0
  221. package/dist/chunk-OJF67RNM.js +1 -0
  222. package/dist/chunk-OJF67RNM.js.map +1 -0
  223. package/dist/chunk-PHLGGRHC.js +89 -0
  224. package/dist/chunk-PHLGGRHC.js.map +1 -0
  225. package/dist/chunk-PIMD4DYG.js +104 -0
  226. package/dist/chunk-PIMD4DYG.js.map +1 -0
  227. package/dist/chunk-PJNE75WC.js +1 -0
  228. package/dist/chunk-PJNE75WC.js.map +1 -0
  229. package/dist/{chunk-J6LVLV6P.js → chunk-PLDJCCVL.js} +1 -1
  230. package/dist/{chunk-3RWESPUG.js → chunk-POXHJF3H.js} +6 -51
  231. package/dist/chunk-POXHJF3H.js.map +1 -0
  232. package/dist/chunk-PPJ7SYQL.js +81 -0
  233. package/dist/chunk-PPJ7SYQL.js.map +1 -0
  234. package/dist/chunk-PT777EQ3.js +48 -0
  235. package/dist/chunk-PT777EQ3.js.map +1 -0
  236. package/dist/chunk-PYLPLFJZ.js +318 -0
  237. package/dist/chunk-PYLPLFJZ.js.map +1 -0
  238. package/dist/chunk-QEPBHHAP.js +41 -0
  239. package/dist/chunk-QEPBHHAP.js.map +1 -0
  240. package/dist/chunk-QHGYCYV6.js +91 -0
  241. package/dist/chunk-QHGYCYV6.js.map +1 -0
  242. package/dist/chunk-R6722CIU.js +28 -0
  243. package/dist/chunk-R6722CIU.js.map +1 -0
  244. package/dist/chunk-RA4YVN43.js +1 -0
  245. package/dist/chunk-RA4YVN43.js.map +1 -0
  246. package/dist/chunk-RT5LUEO3.js +2339 -0
  247. package/dist/chunk-RT5LUEO3.js.map +1 -0
  248. package/dist/chunk-RXKUIJ77.js +236 -0
  249. package/dist/chunk-RXKUIJ77.js.map +1 -0
  250. package/dist/chunk-SC4SUIEY.js +1 -0
  251. package/dist/chunk-SC4SUIEY.js.map +1 -0
  252. package/dist/chunk-SQAAVYJG.js +12 -0
  253. package/dist/chunk-SQAAVYJG.js.map +1 -0
  254. package/dist/chunk-SXE4J43E.js +59 -0
  255. package/dist/chunk-SXE4J43E.js.map +1 -0
  256. package/dist/{chunk-EFLT7XZD.js → chunk-SYULMZGL.js} +6 -4
  257. package/dist/{chunk-EFLT7XZD.js.map → chunk-SYULMZGL.js.map} +1 -1
  258. package/dist/chunk-T4KS577P.js +58 -0
  259. package/dist/chunk-T4KS577P.js.map +1 -0
  260. package/dist/chunk-TFIOU6UR.js +78 -0
  261. package/dist/chunk-TFIOU6UR.js.map +1 -0
  262. package/dist/chunk-TIZGADU4.js +375 -0
  263. package/dist/chunk-TIZGADU4.js.map +1 -0
  264. package/dist/chunk-TP3MCUXS.js +1 -0
  265. package/dist/chunk-TP3MCUXS.js.map +1 -0
  266. package/dist/chunk-TSPQD5HW.js +613 -0
  267. package/dist/chunk-TSPQD5HW.js.map +1 -0
  268. package/dist/{chunk-JTJU56ZV.js → chunk-UOGM62JL.js} +11 -7
  269. package/dist/{chunk-JTJU56ZV.js.map → chunk-UOGM62JL.js.map} +1 -1
  270. package/dist/chunk-USRKPEQN.js +55 -0
  271. package/dist/chunk-USRKPEQN.js.map +1 -0
  272. package/dist/chunk-UTAB3XQI.js +667 -0
  273. package/dist/chunk-UTAB3XQI.js.map +1 -0
  274. package/dist/chunk-V3FFZWF3.js +182 -0
  275. package/dist/chunk-V3FFZWF3.js.map +1 -0
  276. package/dist/chunk-V4OZ7ISA.js +9 -0
  277. package/dist/chunk-V4OZ7ISA.js.map +1 -0
  278. package/dist/chunk-VZ5ZZBNX.js +139 -0
  279. package/dist/chunk-VZ5ZZBNX.js.map +1 -0
  280. package/dist/{chunk-AHLKV6KP.js → chunk-WN6AVBO4.js} +1 -1
  281. package/dist/chunk-WXR5CWSC.js +1 -0
  282. package/dist/chunk-WXR5CWSC.js.map +1 -0
  283. package/dist/chunk-X6WS3XWL.js +36 -0
  284. package/dist/chunk-X6WS3XWL.js.map +1 -0
  285. package/dist/{chunk-Q5BCNYED.js → chunk-XJRNBTIV.js} +7 -4
  286. package/dist/chunk-XQV3XNVT.js +225 -0
  287. package/dist/chunk-XQV3XNVT.js.map +1 -0
  288. package/dist/chunk-XV3DH5GC.js +58 -0
  289. package/dist/chunk-XV3DH5GC.js.map +1 -0
  290. package/dist/chunk-YWRXOPHC.js +43 -0
  291. package/dist/chunk-YWRXOPHC.js.map +1 -0
  292. package/dist/chunk-YZVFIW5D.js +27 -0
  293. package/dist/chunk-YZVFIW5D.js.map +1 -0
  294. package/dist/chunk-ZHC5CD6J.js +33 -0
  295. package/dist/chunk-ZHC5CD6J.js.map +1 -0
  296. package/dist/chunk-ZPJFXRQZ.js +23 -0
  297. package/dist/chunk-ZPJFXRQZ.js.map +1 -0
  298. package/dist/chunk-ZPXOBQDS.js +57 -0
  299. package/dist/chunk-ZPXOBQDS.js.map +1 -0
  300. package/dist/chunk-ZUFS6R7L.js +155 -0
  301. package/dist/chunk-ZUFS6R7L.js.map +1 -0
  302. package/dist/chunk-ZXLCTQUX.js +62 -0
  303. package/dist/chunk-ZXLCTQUX.js.map +1 -0
  304. package/dist/chunk-ZYXMWEL4.js +59 -0
  305. package/dist/chunk-ZYXMWEL4.js.map +1 -0
  306. package/dist/completion/controls.js +11 -0
  307. package/dist/completion/controls.js.map +1 -0
  308. package/dist/completion/documents.js +9 -0
  309. package/dist/completion/documents.js.map +1 -0
  310. package/dist/completion/generate-completion.js +23 -0
  311. package/dist/completion/generate-completion.js.map +1 -0
  312. package/dist/completion/index.js +23 -12
  313. package/dist/completion/json.js +7 -0
  314. package/dist/completion/json.js.map +1 -0
  315. package/dist/completion/message-schema.js +18 -0
  316. package/dist/completion/message-schema.js.map +1 -0
  317. package/dist/completion/provider-output-error.js +12 -0
  318. package/dist/completion/provider-output-error.js.map +1 -0
  319. package/dist/completion/stream-accumulator.js +10 -0
  320. package/dist/completion/stream-accumulator.js.map +1 -0
  321. package/dist/completion/types.js +28 -0
  322. package/dist/completion/types.js.map +1 -0
  323. package/dist/documents/chunk-text.js +7 -0
  324. package/dist/documents/chunk-text.js.map +1 -0
  325. package/dist/documents/index.js +5 -2
  326. package/dist/documents/text-document.js +8 -0
  327. package/dist/documents/text-document.js.map +1 -0
  328. package/dist/embeddings/distance.js +17 -0
  329. package/dist/embeddings/distance.js.map +1 -0
  330. package/dist/embeddings/embed.js +18 -0
  331. package/dist/embeddings/embed.js.map +1 -0
  332. package/dist/embeddings/index.js +11 -6
  333. package/dist/embeddings/types.js +2 -0
  334. package/dist/embeddings/types.js.map +1 -0
  335. package/dist/evals/advanced-metrics.js +46 -0
  336. package/dist/evals/advanced-metrics.js.map +1 -0
  337. package/dist/evals/agent-target.js +10 -0
  338. package/dist/evals/agent-target.js.map +1 -0
  339. package/dist/evals/cli.js +40 -0
  340. package/dist/evals/cli.js.map +1 -0
  341. package/dist/evals/execution.js +15 -0
  342. package/dist/evals/execution.js.map +1 -0
  343. package/dist/evals/format.js +13 -0
  344. package/dist/evals/format.js.map +1 -0
  345. package/dist/evals/index.d.ts +4 -4
  346. package/dist/evals/index.js +87 -2660
  347. package/dist/evals/index.js.map +1 -1
  348. package/dist/evals/judge.js +27 -0
  349. package/dist/evals/judge.js.map +1 -0
  350. package/dist/evals/metric.js +7 -0
  351. package/dist/evals/metric.js.map +1 -0
  352. package/dist/evals/metrics.js +53 -0
  353. package/dist/evals/metrics.js.map +1 -0
  354. package/dist/evals/outcome.js +7 -0
  355. package/dist/evals/outcome.js.map +1 -0
  356. package/dist/evals/reporting.js +11 -0
  357. package/dist/evals/reporting.js.map +1 -0
  358. package/dist/evals/runner.js +29 -0
  359. package/dist/evals/runner.js.map +1 -0
  360. package/dist/evals/selectors.js +18 -0
  361. package/dist/evals/selectors.js.map +1 -0
  362. package/dist/evals/suite.js +11 -0
  363. package/dist/evals/suite.js.map +1 -0
  364. package/dist/evals/types.js +1 -0
  365. package/dist/evals/types.js.map +1 -0
  366. package/dist/extractor/extractor.js +23 -0
  367. package/dist/extractor/extractor.js.map +1 -0
  368. package/dist/extractor/index.js +16 -7
  369. package/dist/guardrails/actions.js +13 -0
  370. package/dist/guardrails/actions.js.map +1 -0
  371. package/dist/guardrails/index.d.ts +3 -4
  372. package/dist/guardrails/index.js +15 -7
  373. package/dist/guardrails/message.js +9 -0
  374. package/dist/guardrails/message.js.map +1 -0
  375. package/dist/guardrails/policy.js +17 -0
  376. package/dist/guardrails/policy.js.map +1 -0
  377. package/dist/guardrails/runtime.js +11 -0
  378. package/dist/guardrails/runtime.js.map +1 -0
  379. package/dist/guardrails/text.js +9 -0
  380. package/dist/guardrails/text.js.map +1 -0
  381. package/dist/guardrails/types.js +1 -0
  382. package/dist/guardrails/types.js.map +1 -0
  383. package/dist/hooks/control.js +17 -0
  384. package/dist/hooks/control.js.map +1 -0
  385. package/dist/hooks/index.js +19 -0
  386. package/dist/hooks/index.js.map +1 -0
  387. package/dist/hooks/types.js +2 -0
  388. package/dist/hooks/types.js.map +1 -0
  389. package/dist/image-generation/generate-image.js +11 -0
  390. package/dist/image-generation/generate-image.js.map +1 -0
  391. package/dist/image-generation/index.js +7 -4
  392. package/dist/image-generation/types.js +2 -0
  393. package/dist/image-generation/types.js.map +1 -0
  394. package/dist/index.d.ts +5 -7
  395. package/dist/index.js +163 -57
  396. package/dist/internal/abort.js +13 -0
  397. package/dist/internal/abort.js.map +1 -0
  398. package/dist/internal/agent-runtime/agent-run.js +81 -0
  399. package/dist/internal/agent-runtime/agent-run.js.map +1 -0
  400. package/dist/internal/agent-runtime/approval-request.js +1 -0
  401. package/dist/internal/agent-runtime/approval-request.js.map +1 -0
  402. package/dist/internal/agent-runtime/approval-requirement.js +9 -0
  403. package/dist/internal/agent-runtime/approval-requirement.js.map +1 -0
  404. package/dist/internal/agent-runtime/continuation-state.js +26 -0
  405. package/dist/internal/agent-runtime/continuation-state.js.map +1 -0
  406. package/dist/internal/agent-runtime/interaction-suspension.js +25 -0
  407. package/dist/internal/agent-runtime/interaction-suspension.js.map +1 -0
  408. package/dist/internal/agent-runtime/memory-scope.js +8 -0
  409. package/dist/internal/agent-runtime/memory-scope.js.map +1 -0
  410. package/dist/internal/agent-runtime/memory.js +24 -0
  411. package/dist/internal/agent-runtime/memory.js.map +1 -0
  412. package/dist/internal/agent-runtime/prepared-tool-call.js +19 -0
  413. package/dist/internal/agent-runtime/prepared-tool-call.js.map +1 -0
  414. package/dist/internal/agent-runtime/retrieval.js +35 -0
  415. package/dist/internal/agent-runtime/retrieval.js.map +1 -0
  416. package/dist/internal/agent-runtime/run-options.js +9 -0
  417. package/dist/internal/agent-runtime/run-options.js.map +1 -0
  418. package/dist/internal/agent-runtime/run-validation.js +9 -0
  419. package/dist/internal/agent-runtime/run-validation.js.map +1 -0
  420. package/dist/internal/agent-runtime/stream-events.js +11 -0
  421. package/dist/internal/agent-runtime/stream-events.js.map +1 -0
  422. package/dist/internal/agent-runtime/structured-output.js +13 -0
  423. package/dist/internal/agent-runtime/structured-output.js.map +1 -0
  424. package/dist/internal/agent-runtime/tool-execution.js +55 -0
  425. package/dist/internal/agent-runtime/tool-execution.js.map +1 -0
  426. package/dist/internal/agent.d.ts +5 -5
  427. package/dist/internal/agent.js +93 -57
  428. package/dist/internal/agent.js.map +1 -1
  429. package/dist/internal/async-queue.js +7 -0
  430. package/dist/internal/async-queue.js.map +1 -0
  431. package/dist/internal/completion-request.js +11 -0
  432. package/dist/internal/completion-request.js.map +1 -0
  433. package/dist/internal/concurrency.js +7 -0
  434. package/dist/internal/concurrency.js.map +1 -0
  435. package/dist/internal/json-object.js +8 -0
  436. package/dist/internal/json-object.js.map +1 -0
  437. package/dist/internal/rag-text.js +7 -0
  438. package/dist/internal/rag-text.js.map +1 -0
  439. package/dist/internal/record.js +7 -0
  440. package/dist/internal/record.js.map +1 -0
  441. package/dist/internal/team-runtime/coordination.js +12 -0
  442. package/dist/internal/team-runtime/coordination.js.map +1 -0
  443. package/dist/internal/team-runtime/member.js +26 -0
  444. package/dist/internal/team-runtime/member.js.map +1 -0
  445. package/dist/internal/team-runtime/policy.js +7 -0
  446. package/dist/internal/team-runtime/policy.js.map +1 -0
  447. package/dist/internal/team-runtime/run.js +95 -0
  448. package/dist/internal/team-runtime/run.js.map +1 -0
  449. package/dist/internal/team-runtime/stream.js +9 -0
  450. package/dist/internal/team-runtime/stream.js.map +1 -0
  451. package/dist/internal/team-runtime/tools.js +17 -0
  452. package/dist/internal/team-runtime/tools.js.map +1 -0
  453. package/dist/internal/type-utils.js +1 -0
  454. package/dist/internal/type-utils.js.map +1 -0
  455. package/dist/internal/vector-search-options.js +9 -0
  456. package/dist/internal/vector-search-options.js.map +1 -0
  457. package/dist/mcp/index.js +3 -1
  458. package/dist/mcp/tool.js +7 -0
  459. package/dist/mcp/tool.js.map +1 -0
  460. package/dist/mcp/types.js +2 -0
  461. package/dist/mcp/types.js.map +1 -0
  462. package/dist/memory/assert.js +11 -0
  463. package/dist/memory/assert.js.map +1 -0
  464. package/dist/memory/compaction.js +26 -0
  465. package/dist/memory/compaction.js.map +1 -0
  466. package/dist/memory/errors.js +9 -0
  467. package/dist/memory/errors.js.map +1 -0
  468. package/dist/memory/index.js +23 -10
  469. package/dist/memory/options.js +10 -0
  470. package/dist/memory/options.js.map +1 -0
  471. package/dist/memory/scope-key.js +7 -0
  472. package/dist/memory/scope-key.js.map +1 -0
  473. package/dist/memory/types.js +2 -0
  474. package/dist/memory/types.js.map +1 -0
  475. package/dist/{types-CRda8x7p.d.ts → middleware-CWjnMbiH.d.ts} +64 -5
  476. package/dist/model-call-options.js +1 -0
  477. package/dist/model-call-options.js.map +1 -0
  478. package/dist/model-listing/errors.js +7 -0
  479. package/dist/model-listing/errors.js.map +1 -0
  480. package/dist/model-listing/index.js +4 -13
  481. package/dist/model-listing/index.js.map +1 -1
  482. package/dist/model-listing/types.js +2 -0
  483. package/dist/model-listing/types.js.map +1 -0
  484. package/dist/observability/group.js +30 -0
  485. package/dist/observability/group.js.map +1 -0
  486. package/dist/observability/index.d.ts +4 -6
  487. package/dist/observability/index.js +16 -8
  488. package/dist/observability/snapshot.js +7 -0
  489. package/dist/observability/snapshot.js.map +1 -0
  490. package/dist/observability/types.js +1 -0
  491. package/dist/observability/types.js.map +1 -0
  492. package/dist/pipeline/errors.js +9 -0
  493. package/dist/pipeline/errors.js.map +1 -0
  494. package/dist/pipeline/graph.js +21 -0
  495. package/dist/pipeline/graph.js.map +1 -0
  496. package/dist/pipeline/index.d.ts +4 -6
  497. package/dist/pipeline/index.js +27 -805
  498. package/dist/pipeline/index.js.map +1 -1
  499. package/dist/pipeline/observability.js +15 -0
  500. package/dist/pipeline/observability.js.map +1 -0
  501. package/dist/pipeline/pipeline.js +30 -0
  502. package/dist/pipeline/pipeline.js.map +1 -0
  503. package/dist/pipeline/runtime.js +17 -0
  504. package/dist/pipeline/runtime.js.map +1 -0
  505. package/dist/pipeline/types.js +1 -0
  506. package/dist/pipeline/types.js.map +1 -0
  507. package/dist/retry.js +20 -0
  508. package/dist/retry.js.map +1 -0
  509. package/dist/schema/index.js +1 -0
  510. package/dist/schema/index.js.map +1 -0
  511. package/dist/schema/zod-schema.js +7 -0
  512. package/dist/schema/zod-schema.js.map +1 -0
  513. package/dist/skills/index.js +41 -12
  514. package/dist/skills/instructions.js +7 -0
  515. package/dist/skills/instructions.js.map +1 -0
  516. package/dist/skills/load.js +39 -0
  517. package/dist/skills/load.js.map +1 -0
  518. package/dist/skills/local.js +9 -0
  519. package/dist/skills/local.js.map +1 -0
  520. package/dist/skills/tools.js +37 -0
  521. package/dist/skills/tools.js.map +1 -0
  522. package/dist/skills/types.js +7 -0
  523. package/dist/skills/types.js.map +1 -0
  524. package/dist/speech-generation/generate-speech.js +11 -0
  525. package/dist/speech-generation/generate-speech.js.map +1 -0
  526. package/dist/speech-generation/index.js +7 -4
  527. package/dist/speech-generation/types.js +2 -0
  528. package/dist/speech-generation/types.js.map +1 -0
  529. package/dist/streaming/index.js +3 -37
  530. package/dist/streaming/index.js.map +1 -1
  531. package/dist/streaming/readable-stream.js +7 -0
  532. package/dist/streaming/readable-stream.js.map +1 -0
  533. package/dist/{text-CmjXxakS.d.ts → text-GbW4WYMg.d.ts} +1 -1
  534. package/dist/tool/create-tool.js +14 -0
  535. package/dist/tool/create-tool.js.map +1 -0
  536. package/dist/tool/dynamic-tools.js +35 -0
  537. package/dist/tool/dynamic-tools.js.map +1 -0
  538. package/dist/tool/errors.js +11 -0
  539. package/dist/tool/errors.js.map +1 -0
  540. package/dist/tool/index.d.ts +3 -2
  541. package/dist/tool/index.js +41 -15
  542. package/dist/tool/middleware.js +7 -0
  543. package/dist/tool/middleware.js.map +1 -0
  544. package/dist/tool/question-tool.js +17 -0
  545. package/dist/tool/question-tool.js.map +1 -0
  546. package/dist/tool/skill-tool-marker.js +9 -0
  547. package/dist/tool/skill-tool-marker.js.map +1 -0
  548. package/dist/tool/think-tool.js +15 -0
  549. package/dist/tool/think-tool.js.map +1 -0
  550. package/dist/tool/tool.js +17 -0
  551. package/dist/tool/tool.js.map +1 -0
  552. package/dist/transcription/index.js +7 -4
  553. package/dist/transcription/transcribe.js +11 -0
  554. package/dist/transcription/transcribe.js.map +1 -0
  555. package/dist/transcription/types.js +2 -0
  556. package/dist/transcription/types.js.map +1 -0
  557. package/dist/{types-h0EL6Xn0.d.ts → types-Bqw0AuFl.d.ts} +6 -2
  558. package/dist/vector-store/filter.js +9 -0
  559. package/dist/vector-store/filter.js.map +1 -0
  560. package/dist/vector-store/index.js +31 -11
  561. package/dist/vector-store/ingest.js +19 -0
  562. package/dist/vector-store/ingest.js.map +1 -0
  563. package/dist/vector-store/lsh.js +7 -0
  564. package/dist/vector-store/lsh.js.map +1 -0
  565. package/dist/vector-store/retrieve.js +15 -0
  566. package/dist/vector-store/retrieve.js.map +1 -0
  567. package/dist/vector-store/types.js +1 -0
  568. package/dist/vector-store/types.js.map +1 -0
  569. package/package.json +2 -2
  570. package/dist/chunk-2QZJTG2E.js.map +0 -1
  571. package/dist/chunk-3RWESPUG.js.map +0 -1
  572. package/dist/chunk-4UQALF5Y.js.map +0 -1
  573. package/dist/chunk-AZB6N7P4.js +0 -320
  574. package/dist/chunk-AZB6N7P4.js.map +0 -1
  575. package/dist/chunk-JLJMVRRE.js.map +0 -1
  576. package/dist/chunk-K5L7R7XM.js.map +0 -1
  577. package/dist/chunk-OI3LSMJG.js +0 -1545
  578. package/dist/chunk-OI3LSMJG.js.map +0 -1
  579. package/dist/chunk-QGX73TSQ.js.map +0 -1
  580. package/dist/chunk-XC3LVC4K.js +0 -753
  581. package/dist/chunk-XC3LVC4K.js.map +0 -1
  582. package/dist/chunk-XEVOC433.js.map +0 -1
  583. package/dist/chunk-XSV5C4R5.js +0 -400
  584. package/dist/chunk-XSV5C4R5.js.map +0 -1
  585. package/dist/chunk-XU54PLSD.js +0 -4786
  586. package/dist/chunk-XU54PLSD.js.map +0 -1
  587. package/dist/middleware-mY_lpjDp.d.ts +0 -59
  588. package/dist/type-utils-CtHVDRn_.d.ts +0 -6
  589. /package/dist/{chunk-YK4WAAS4.js.map → chunk-2NLINXRF.js.map} +0 -0
  590. /package/dist/{chunk-SPD4XVR7.js.map → chunk-2XSMGVBG.js.map} +0 -0
  591. /package/dist/{chunk-3XQGVDU5.js.map → chunk-4C7AXYOM.js.map} +0 -0
  592. /package/dist/{chunk-IZNOP6JG.js.map → chunk-4FIVU53H.js.map} +0 -0
  593. /package/dist/{chunk-7JLAIN6E.js.map → chunk-4ONUNWGC.js.map} +0 -0
  594. /package/dist/{chunk-KSKST3KP.js.map → chunk-H3H74RWJ.js.map} +0 -0
  595. /package/dist/{chunk-OJBFDBLG.js.map → chunk-LBYJPMHC.js.map} +0 -0
  596. /package/dist/{chunk-J6LVLV6P.js.map → chunk-PLDJCCVL.js.map} +0 -0
  597. /package/dist/{chunk-AHLKV6KP.js.map → chunk-WN6AVBO4.js.map} +0 -0
  598. /package/dist/{chunk-Q5BCNYED.js.map → chunk-XJRNBTIV.js.map} +0 -0
@@ -1,753 +0,0 @@
1
- import {
2
- chunkTextDocuments
3
- } from "./chunk-XEVOC433.js";
4
- import {
5
- cosineSimilarity,
6
- embedDocuments,
7
- embedSparseQuery,
8
- embedText
9
- } from "./chunk-K5L7R7XM.js";
10
- import {
11
- parseMessage,
12
- toProviderJsonSchema
13
- } from "./chunk-QGX73TSQ.js";
14
- import {
15
- isJsonValue
16
- } from "./chunk-3XQGVDU5.js";
17
- import {
18
- resolveRetryOptions,
19
- runWithRetries,
20
- throwIfAborted
21
- } from "./chunk-3RWESPUG.js";
22
-
23
- // src/vector-store/index.ts
24
- import { z } from "zod";
25
-
26
- // src/internal/vector-search-options.ts
27
- function assertPositiveSearchLimit(value, name = "topK") {
28
- if (!Number.isSafeInteger(value) || value <= 0) {
29
- throw new RangeError(`${name} must be a positive safe integer.`);
30
- }
31
- return value;
32
- }
33
- function assertFiniteMinScore(value, name = "minScore") {
34
- if (value !== void 0 && !Number.isFinite(value)) {
35
- throw new RangeError(`${name} must be a finite number.`);
36
- }
37
- return value;
38
- }
39
-
40
- // src/internal/agent-runtime/approval-requirement.ts
41
- function toolMayRequireApproval(requirement) {
42
- return requirement !== void 0 && requirement !== false;
43
- }
44
- function assertToolApprovalRequirement(requirement, options) {
45
- if (typeof requirement === "boolean") {
46
- return;
47
- }
48
- if (options.allowFunction && typeof requirement === "function") {
49
- return;
50
- }
51
- if (typeof requirement !== "object" || requirement === null || Array.isArray(requirement)) {
52
- throw new TypeError(
53
- 'Tool "requiresApproval" must be a boolean, a function, or an object with an optional string reason.'
54
- );
55
- }
56
- const reason = requirement.reason;
57
- if (reason !== void 0 && typeof reason !== "string") {
58
- throw new TypeError('Tool "requiresApproval.reason" must be a string.');
59
- }
60
- }
61
-
62
- // src/tool/errors.ts
63
- var ToolCallError = class extends Error {
64
- constructor(message, cause) {
65
- super(message);
66
- this.cause = cause;
67
- this.name = "ToolCallError";
68
- }
69
- cause;
70
- };
71
- var ToolNotFoundError = class extends Error {
72
- constructor(toolName) {
73
- super(`Tool not found: ${toolName}`);
74
- this.toolName = toolName;
75
- this.name = "ToolNotFoundError";
76
- }
77
- toolName;
78
- };
79
- var ToolJsonError = class extends Error {
80
- constructor(message, cause) {
81
- super(message);
82
- this.cause = cause;
83
- this.name = "ToolJsonError";
84
- }
85
- cause;
86
- };
87
-
88
- // src/tool/tool.ts
89
- var richToolOutput = /* @__PURE__ */ Symbol.for("anvia.tool-output.content");
90
- var ToolResultSerializationError = class extends TypeError {
91
- constructor(output) {
92
- super("Tool output must be a string, a strict JSON value, or ToolOutput.content(...).");
93
- this.output = output;
94
- this.name = "ToolResultSerializationError";
95
- }
96
- output;
97
- };
98
- var ToolOutput = {
99
- content(content) {
100
- return { [richToolOutput]: true, content };
101
- }
102
- };
103
- function normalizeToolResultOutput(output) {
104
- if (typeof output === "string") {
105
- return { type: "text", value: output };
106
- }
107
- if (isRichToolOutput(output)) {
108
- try {
109
- const message = parseMessage({
110
- role: "tool",
111
- content: [
112
- {
113
- type: "tool-result",
114
- toolCallId: "validation",
115
- toolName: "validation",
116
- output: { type: "content", value: output.content }
117
- }
118
- ]
119
- });
120
- if (message.role !== "tool") throw new TypeError("Unexpected message role");
121
- const result = message.content[0];
122
- if (result?.type !== "tool-result") throw new TypeError("Unexpected tool result part");
123
- if (result?.output.type !== "content") throw new TypeError("Unexpected tool output");
124
- return result.output;
125
- } catch {
126
- throw new ToolResultSerializationError(output);
127
- }
128
- }
129
- if (isJsonValue(output)) {
130
- return { type: "json", value: output };
131
- }
132
- throw new ToolResultSerializationError(output);
133
- }
134
- function toolResultContentToText(content) {
135
- return content.map((item) => item.type === "text" ? item.text : `[file:${item.mediaType}]`).join("\n");
136
- }
137
- function isRichToolOutput(value) {
138
- if (typeof value !== "object" || value === null) return false;
139
- return Object.getOwnPropertyDescriptor(value, richToolOutput)?.value === true;
140
- }
141
- function parseToolArgs(args) {
142
- const value = JSON.parse(args);
143
- if (!isJsonValue(value)) {
144
- throw new TypeError("Tool arguments must be a JSON value.");
145
- }
146
- return value;
147
- }
148
-
149
- // src/internal/agent-runtime/prepared-tool-call.ts
150
- var preparedToolInputSymbol = /* @__PURE__ */ Symbol("preparedToolInput");
151
- var preparedToolOwnerSymbol = /* @__PURE__ */ Symbol("preparedToolOwner");
152
- function attachPreparedToolOwner(tool, owner) {
153
- Object.defineProperty(tool, preparedToolOwnerSymbol, {
154
- configurable: false,
155
- enumerable: true,
156
- value: owner,
157
- writable: false
158
- });
159
- return tool;
160
- }
161
- function preparedToolInput(context, owner) {
162
- if (context === void 0 || !(preparedToolInputSymbol in context)) {
163
- return void 0;
164
- }
165
- const prepared = context[preparedToolInputSymbol];
166
- return prepared?.owner === owner ? { input: prepared.input } : void 0;
167
- }
168
- function withoutPreparedToolInput(context) {
169
- if (!(preparedToolInputSymbol in context)) {
170
- return context;
171
- }
172
- const { [preparedToolInputSymbol]: _prepared, ...publicContext } = context;
173
- return publicContext;
174
- }
175
- function prepareToolCall(tool, args) {
176
- let rawInput;
177
- try {
178
- rawInput = parseToolArgs(args);
179
- } catch (error) {
180
- throw new ToolJsonError(`Invalid JSON arguments for tool ${tool.name}`, error);
181
- }
182
- let input;
183
- try {
184
- input = tool.parseInput === void 0 ? rawInput : tool.parseInput(rawInput);
185
- } catch (error) {
186
- throw asToolCallError(tool.name, error);
187
- }
188
- return prepareToolCallFromInput(tool, input);
189
- }
190
- function prepareToolCallFromInput(tool, input) {
191
- return {
192
- input,
193
- async call(context) {
194
- try {
195
- const owner = tool[preparedToolOwnerSymbol];
196
- return normalizeToolResultOutput(
197
- await tool.call(
198
- input,
199
- owner === void 0 ? context : withPreparedToolInput(context, owner, input)
200
- )
201
- );
202
- } catch (error) {
203
- throw asToolCallError(tool.name, error);
204
- }
205
- }
206
- };
207
- }
208
- function withPreparedToolInput(context, owner, input) {
209
- const preparedContext = { ...context };
210
- Object.defineProperty(preparedContext, preparedToolInputSymbol, {
211
- configurable: false,
212
- enumerable: true,
213
- value: { owner, input },
214
- writable: false
215
- });
216
- return preparedContext;
217
- }
218
- function asToolCallError(toolName, error) {
219
- if (error instanceof ToolCallError) {
220
- return error;
221
- }
222
- return error instanceof Error ? new ToolCallError(error.message, error) : new ToolCallError(`Tool ${toolName} failed`, error);
223
- }
224
-
225
- // src/tool/create-tool.ts
226
- function createTool(options) {
227
- const { name, description, inputSchema, outputSchema, execute } = options;
228
- const requiresApproval = snapshotApprovalRequirement(options.requiresApproval);
229
- if (requiresApproval !== void 0) {
230
- assertToolApprovalRequirement(requiresApproval, { allowFunction: true });
231
- }
232
- const parameters = toProviderJsonSchema(inputSchema);
233
- const preparedInputOwner = {};
234
- const definition = () => ({
235
- name,
236
- description,
237
- parameters: globalThis.structuredClone(parameters)
238
- });
239
- const call = async (args, context = {}) => {
240
- const prepared = preparedToolInput(context, preparedInputOwner);
241
- const parsedArgs = prepared === void 0 ? inputSchema.parse(args) : prepared.input;
242
- const executionContext = prepared === void 0 ? context : withoutPreparedToolInput(context);
243
- const result = await execute(parsedArgs, executionContext);
244
- return outputSchema === void 0 ? result : outputSchema.parse(result);
245
- };
246
- const parseInput = (args) => inputSchema.parse(args);
247
- const tool = {
248
- name,
249
- definition,
250
- call,
251
- parseInput
252
- };
253
- if (requiresApproval !== void 0) {
254
- Object.defineProperty(tool, "requiresApproval", {
255
- configurable: false,
256
- enumerable: true,
257
- value: requiresApproval,
258
- writable: false
259
- });
260
- }
261
- return attachPreparedToolOwner(tool, preparedInputOwner);
262
- }
263
- function snapshotApprovalRequirement(requirement) {
264
- return typeof requirement === "object" && requirement !== null ? Object.freeze({ ...requirement }) : requirement;
265
- }
266
-
267
- // src/vector-store/filter.ts
268
- var vectorFilter = {
269
- eq(key, value) {
270
- return { type: "eq", key, value };
271
- },
272
- gt(key, value) {
273
- return { type: "gt", key, value };
274
- },
275
- lt(key, value) {
276
- return { type: "lt", key, value };
277
- },
278
- and(left, right) {
279
- return { type: "and", filters: [left, right] };
280
- },
281
- or(left, right) {
282
- return { type: "or", filters: [left, right] };
283
- }
284
- };
285
- function matchesVectorFilter(metadata, filter) {
286
- if (filter === void 0) {
287
- return true;
288
- }
289
- if (metadata === void 0) {
290
- return false;
291
- }
292
- switch (filter.type) {
293
- case "eq":
294
- return metadata[filter.key] === filter.value;
295
- case "gt":
296
- return compare(metadata[filter.key], filter.value) > 0;
297
- case "lt":
298
- return compare(metadata[filter.key], filter.value) < 0;
299
- case "and":
300
- return matchesVectorFilter(metadata, filter.filters[0]) && matchesVectorFilter(metadata, filter.filters[1]);
301
- case "or":
302
- return matchesVectorFilter(metadata, filter.filters[0]) || matchesVectorFilter(metadata, filter.filters[1]);
303
- }
304
- }
305
- function compare(left, right) {
306
- if (typeof left === "number" && typeof right === "number") {
307
- return left - right;
308
- }
309
- if (typeof left === "string" && typeof right === "string") {
310
- return left.localeCompare(right);
311
- }
312
- if (typeof left === "boolean" && typeof right === "boolean") {
313
- return Number(left) - Number(right);
314
- }
315
- return 0;
316
- }
317
-
318
- // src/vector-store/lsh.ts
319
- var LshIndex = class {
320
- constructor(dimensions, options) {
321
- this.options = options;
322
- const rng = seededRandom(options.seed ?? 42);
323
- this.hyperplanes = [];
324
- for (let index = 0; index < options.numTables * options.numHyperplanes; index += 1) {
325
- const plane = Array.from({ length: dimensions }, () => rng() * 2 - 1);
326
- const norm = Math.sqrt(plane.reduce((sum, value) => sum + value ** 2, 0));
327
- this.hyperplanes.push(norm === 0 ? plane : plane.map((value) => value / norm));
328
- }
329
- this.tables = Array.from({ length: options.numTables }, () => /* @__PURE__ */ new Map());
330
- }
331
- options;
332
- hyperplanes;
333
- tables;
334
- insert(id, vector) {
335
- for (let table = 0; table < this.options.numTables; table += 1) {
336
- const hash = this.hash(vector, table);
337
- const bucket = this.tables[table]?.get(hash) ?? /* @__PURE__ */ new Set();
338
- bucket.add(id);
339
- this.tables[table]?.set(hash, bucket);
340
- }
341
- }
342
- query(vector) {
343
- const candidates = /* @__PURE__ */ new Set();
344
- for (let table = 0; table < this.options.numTables; table += 1) {
345
- const hash = this.hash(vector, table);
346
- for (const id of this.tables[table]?.get(hash) ?? []) {
347
- candidates.add(id);
348
- }
349
- }
350
- return candidates;
351
- }
352
- hash(vector, table) {
353
- let hash = "";
354
- const start = table * this.options.numHyperplanes;
355
- for (let offset = 0; offset < this.options.numHyperplanes; offset += 1) {
356
- const plane = this.hyperplanes[start + offset];
357
- const dot = vector.reduce((sum, value, index) => sum + value * (plane[index] ?? 0), 0);
358
- hash += dot >= 0 ? "1" : "0";
359
- }
360
- return hash;
361
- }
362
- };
363
- function seededRandom(seed) {
364
- let state = seed >>> 0;
365
- return () => {
366
- state = state * 1664525 + 1013904223 >>> 0;
367
- return state / 4294967296;
368
- };
369
- }
370
-
371
- // src/vector-store/retrieve.ts
372
- async function retrieveDocuments(options) {
373
- assertPositiveSearchLimit(options.topK);
374
- assertFiniteMinScore(options.minScore);
375
- throwIfAborted(options.abortSignal);
376
- const retries = resolveRetries(options.retries);
377
- const search = (operation) => runWithRetries(operation, retries, {
378
- streaming: false,
379
- abortSignal: options.abortSignal
380
- });
381
- if ("model" in options && options.model !== void 0) {
382
- const { embedding } = await embedText({
383
- model: options.model,
384
- text: options.query,
385
- retries: options.retries,
386
- abortSignal: options.abortSignal
387
- });
388
- return deduplicateResults(
389
- await search(
390
- () => options.store.search({
391
- vector: embedding.vector,
392
- topK: options.topK,
393
- minScore: options.minScore,
394
- filter: options.filter,
395
- abortSignal: options.abortSignal
396
- })
397
- )
398
- );
399
- }
400
- const [{ embedding: dense }, { embedding: sparse }] = await Promise.all([
401
- embedText({
402
- model: options.models.dense,
403
- text: options.query,
404
- retries: options.retries,
405
- abortSignal: options.abortSignal
406
- }),
407
- embedSparseQuery({
408
- model: options.models.sparse,
409
- query: options.query,
410
- retries: options.retries,
411
- abortSignal: options.abortSignal
412
- })
413
- ]);
414
- return deduplicateResults(
415
- await search(
416
- () => options.store.searchHybrid({
417
- vector: dense.vector,
418
- sparseVector: sparse.vector,
419
- fusion: options.fusion,
420
- topK: options.topK,
421
- minScore: options.minScore,
422
- filter: options.filter,
423
- abortSignal: options.abortSignal
424
- })
425
- )
426
- );
427
- }
428
- function deduplicateResults(results) {
429
- const bestById = /* @__PURE__ */ new Map();
430
- for (const result of results) {
431
- const current = bestById.get(result.id);
432
- if (current === void 0 || result.score > current.score) bestById.set(result.id, result);
433
- }
434
- return [...bestById.values()].sort((left, right) => right.score - left.score);
435
- }
436
- function resolveRetries(setting) {
437
- return setting === void 0 || setting === false ? void 0 : resolveRetryOptions(setting);
438
- }
439
-
440
- // src/vector-store/ingest.ts
441
- async function ingestVectorText(options) {
442
- return ingestVectorDocuments({
443
- store: options.store,
444
- documents: [options.document],
445
- embeddingModel: options.embeddingModel,
446
- chunking: options.chunking,
447
- retries: options.retries,
448
- concurrency: options.concurrency,
449
- providerOptions: options.providerOptions,
450
- abortSignal: options.abortSignal
451
- });
452
- }
453
- async function ingestVectorDocuments(options) {
454
- for (const document of options.documents) {
455
- validateVectorMetadata(document.metadata, document.id);
456
- }
457
- const chunks = chunkTextDocuments({
458
- documents: options.documents,
459
- chunking: options.chunking
460
- });
461
- const chunksByDocument = groupChunksByDocument(chunks);
462
- const embedded = await embedDocuments({
463
- model: options.embeddingModel,
464
- documents: [...options.documents],
465
- id: (document) => document.id,
466
- content: (document) => {
467
- const documentChunks = chunksByDocument.get(document.id);
468
- if (documentChunks === void 0) {
469
- throw new TypeError(`Text document ${document.id} has no chunks`);
470
- }
471
- return documentChunks.map((chunk) => chunk.text);
472
- },
473
- metadata: (document) => document.metadata,
474
- retries: options.retries,
475
- concurrency: options.concurrency,
476
- abortSignal: options.abortSignal
477
- });
478
- await options.store.upsert({
479
- documents: embedded.documents,
480
- providerOptions: options.providerOptions
481
- });
482
- return { documents: embedded.documents };
483
- }
484
- function validateVectorMetadata(metadata, documentId) {
485
- if (metadata === void 0) {
486
- return;
487
- }
488
- if (typeof metadata !== "object" || metadata === null || Array.isArray(metadata)) {
489
- throw new TypeError(`Text document ${documentId} metadata must be an object`);
490
- }
491
- for (const [key, value] of Object.entries(metadata)) {
492
- validateVectorMetadataValue(value, `Text document ${documentId} metadata.${key}`);
493
- }
494
- }
495
- function validateVectorMetadataValue(value, label) {
496
- if (value === null || typeof value === "string" || typeof value === "boolean") {
497
- return;
498
- }
499
- if (typeof value !== "number" || !Number.isFinite(value)) {
500
- throw new TypeError(`${label} must be a finite vector metadata value`);
501
- }
502
- if (Number.isInteger(value) && !Number.isSafeInteger(value)) {
503
- throw new TypeError(`${label} must be a safe integer`);
504
- }
505
- }
506
- function groupChunksByDocument(chunks) {
507
- const grouped = /* @__PURE__ */ new Map();
508
- for (const chunk of chunks) {
509
- const documentChunks = grouped.get(chunk.documentId);
510
- if (documentChunks === void 0) {
511
- grouped.set(chunk.documentId, [chunk]);
512
- } else {
513
- documentChunks.push(chunk);
514
- }
515
- }
516
- return grouped;
517
- }
518
-
519
- // src/vector-store/index.ts
520
- var InMemoryVectorStore = class _InMemoryVectorStore {
521
- documents = /* @__PURE__ */ new Map();
522
- indexStrategy;
523
- lshIndex;
524
- embeddingDimension;
525
- constructor(options = {}) {
526
- this.indexStrategy = options.index ?? { type: "bruteForce" };
527
- if (options.dimensions !== void 0 && (!Number.isSafeInteger(options.dimensions) || options.dimensions < 1)) {
528
- throw new RangeError("Vector dimensions must be a positive safe integer.");
529
- }
530
- this.embeddingDimension = options.dimensions;
531
- }
532
- static fromDocuments(options) {
533
- const store = new _InMemoryVectorStore(options);
534
- store.replaceDocuments(options.documents);
535
- return store;
536
- }
537
- async ensure() {
538
- }
539
- async validate() {
540
- }
541
- async upsert(options) {
542
- this.replaceDocuments(options.documents);
543
- }
544
- get(options) {
545
- return this.documents.get(options.id);
546
- }
547
- values() {
548
- return [...this.documents.values()];
549
- }
550
- len() {
551
- return this.documents.size;
552
- }
553
- isEmpty() {
554
- return this.documents.size === 0;
555
- }
556
- async search(request) {
557
- throwIfAborted2(request.abortSignal);
558
- assertPositiveSearchLimit(request.topK);
559
- assertFiniteMinScore(request.minScore);
560
- const queryEmbedding = { document: "", vector: request.vector };
561
- const results = this.candidates(queryEmbedding).filter((document) => matchesVectorFilter(document.metadata, request.filter)).flatMap((document) => {
562
- const score = bestScore(queryEmbedding, document.embeddings);
563
- if (score === void 0 || request.minScore !== void 0 && score < request.minScore) {
564
- return [];
565
- }
566
- let result = {
567
- score,
568
- id: document.id,
569
- document: document.document
570
- };
571
- if (document.metadata !== void 0) {
572
- result = { ...result, metadata: document.metadata };
573
- }
574
- return [result];
575
- }).sort((left, right) => right.score - left.score).slice(0, request.topK);
576
- throwIfAborted2(request.abortSignal);
577
- return results;
578
- }
579
- async inspect(request) {
580
- throwIfAborted2(request.abortSignal);
581
- const limit = assertPositiveSearchLimit(request.limit);
582
- const start = Math.max(0, Math.trunc(Number(request.cursor ?? "0")));
583
- const documents = this.values().filter(
584
- (document) => matchesVectorFilter(document.metadata, request.filter)
585
- );
586
- const page = documents.slice(start, start + limit);
587
- const nextOffset = start + page.length;
588
- const result = {
589
- items: page.map((document) => {
590
- let item = {
591
- id: document.id,
592
- document: document.document
593
- };
594
- if (document.metadata !== void 0) {
595
- item = { ...item, metadata: document.metadata };
596
- }
597
- return item;
598
- }),
599
- totalCount: documents.length
600
- };
601
- if (nextOffset < documents.length) result.nextCursor = String(nextOffset);
602
- throwIfAborted2(request.abortSignal);
603
- return result;
604
- }
605
- replaceDocuments(documents) {
606
- const ids = /* @__PURE__ */ new Set();
607
- for (const document of documents) {
608
- if (ids.has(document.id)) throw new TypeError(`Duplicate vector document id: ${document.id}`);
609
- ids.add(document.id);
610
- if (document.embeddings.length === 0) {
611
- throw new TypeError(`Vector document ${document.id} must contain at least one embedding.`);
612
- }
613
- for (const embedding of document.embeddings)
614
- assertFiniteVector(embedding.vector, document.id);
615
- }
616
- this.validateDocumentDimensions(documents);
617
- for (const document of documents) this.documents.set(document.id, document);
618
- this.rebuildLshIndex();
619
- }
620
- candidates(queryEmbedding) {
621
- this.validateQueryDimension(queryEmbedding);
622
- if (this.indexStrategy.type !== "lsh" || this.lshIndex === void 0) return this.values();
623
- const candidateIds = this.lshIndex.query(queryEmbedding.vector);
624
- if (candidateIds.size === 0) return this.values();
625
- return [...candidateIds].flatMap((id) => {
626
- const document = this.documents.get(id);
627
- return document === void 0 ? [] : [document];
628
- });
629
- }
630
- rebuildLshIndex() {
631
- if (this.indexStrategy.type !== "lsh") {
632
- this.lshIndex = void 0;
633
- return;
634
- }
635
- const firstEmbedding = this.values().flatMap((document) => document.embeddings)[0];
636
- if (firstEmbedding === void 0) {
637
- this.lshIndex = void 0;
638
- return;
639
- }
640
- const index = new LshIndex(firstEmbedding.vector.length, this.indexStrategy);
641
- for (const document of this.documents.values()) {
642
- for (const embedding of document.embeddings) index.insert(document.id, embedding.vector);
643
- }
644
- this.lshIndex = index;
645
- }
646
- validateDocumentDimensions(documents) {
647
- let dimension = this.embeddingDimension;
648
- for (const document of documents) {
649
- for (const embedding of document.embeddings) {
650
- dimension = validateEmbeddingDimension(dimension, embedding, document.id);
651
- }
652
- }
653
- this.embeddingDimension = dimension;
654
- }
655
- validateQueryDimension(queryEmbedding) {
656
- if (this.embeddingDimension !== void 0) {
657
- validateEmbeddingDimension(this.embeddingDimension, queryEmbedding, "query");
658
- }
659
- }
660
- };
661
- function throwIfAborted2(signal) {
662
- if (signal?.aborted) {
663
- const error = new Error("The operation was aborted.");
664
- error.name = "AbortError";
665
- throw error;
666
- }
667
- }
668
- function createVectorSearchTool(options) {
669
- const configuredTopK = assertPositiveSearchLimit(options.topK ?? 5);
670
- assertFiniteMinScore(options.minScore);
671
- return createTool({
672
- name: options.name,
673
- description: options.description ?? "Search a vector store for documents relevant to the provided query.",
674
- inputSchema: z.object({
675
- query: z.string().min(1).describe("The query string to search for relevant documents."),
676
- topK: z.number().int().positive().optional().describe("The maximum number of results.")
677
- }),
678
- outputSchema: z.array(
679
- z.object({
680
- score: z.number(),
681
- id: z.string(),
682
- document: z.any(),
683
- metadata: z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.null()])).optional()
684
- })
685
- ),
686
- execute: ({ query, topK }, context) => {
687
- const request = {
688
- query,
689
- topK: topK ?? configuredTopK,
690
- minScore: options.minScore,
691
- filter: options.filter,
692
- retries: options.retries,
693
- abortSignal: context.abortSignal
694
- };
695
- return "models" in options && options.models !== void 0 ? retrieveDocuments({
696
- ...request,
697
- store: options.store,
698
- models: options.models,
699
- fusion: options.fusion
700
- }) : retrieveDocuments({ ...request, store: options.store, model: options.model });
701
- }
702
- });
703
- }
704
- function bestScore(queryEmbedding, embeddings) {
705
- let best;
706
- for (const embedding of embeddings) {
707
- const score = cosineSimilarity(queryEmbedding.vector, embedding.vector);
708
- best = best === void 0 ? score : Math.max(best, score);
709
- }
710
- return best;
711
- }
712
- function validateEmbeddingDimension(expectedDimension, embedding, id) {
713
- assertFiniteVector(embedding.vector, id);
714
- if (expectedDimension === void 0) return embedding.vector.length;
715
- if (embedding.vector.length !== expectedDimension) {
716
- throw new Error(
717
- `Vector dimension mismatch: expected ${expectedDimension} dimensions but received ${embedding.vector.length} for ${id}`
718
- );
719
- }
720
- return expectedDimension;
721
- }
722
- function assertFiniteVector(vector, id) {
723
- if (vector.length === 0) throw new TypeError(`Vector for ${id} must not be empty.`);
724
- if (!vector.every(Number.isFinite)) {
725
- throw new TypeError(`Vector for ${id} must contain only finite numbers.`);
726
- }
727
- }
728
-
729
- export {
730
- toolMayRequireApproval,
731
- assertToolApprovalRequirement,
732
- ToolCallError,
733
- ToolNotFoundError,
734
- ToolJsonError,
735
- ToolResultSerializationError,
736
- ToolOutput,
737
- normalizeToolResultOutput,
738
- toolResultContentToText,
739
- parseToolArgs,
740
- prepareToolCall,
741
- prepareToolCallFromInput,
742
- createTool,
743
- assertPositiveSearchLimit,
744
- assertFiniteMinScore,
745
- vectorFilter,
746
- matchesVectorFilter,
747
- retrieveDocuments,
748
- ingestVectorText,
749
- ingestVectorDocuments,
750
- InMemoryVectorStore,
751
- createVectorSearchTool
752
- };
753
- //# sourceMappingURL=chunk-XC3LVC4K.js.map