@delali/narsil 0.3.1-next.152 → 0.3.1-next.154

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 (268) hide show
  1. package/README.md +2 -1
  2. package/dist/adapters/filesystem.mjs +2 -2
  3. package/dist/adapters/gcs.mjs +2 -2
  4. package/dist/adapters/indexeddb.mjs +1 -1
  5. package/dist/adapters/s3.mjs +2 -2
  6. package/dist/{analysis-change-2OYM7ARW.mjs → analysis-change-4GCRVRBW.mjs} +27 -18
  7. package/dist/{react-native/chunks/analysis-change-entry-CXNRW324.mjs → analysis-change-entry-KYGSXW4K.mjs} +1 -1
  8. package/dist/browser/{analysis-change-2V2HZ2NY.mjs → analysis-change-IXWPXXJJ.mjs} +17 -7
  9. package/dist/{analysis-change-entry-QD7YNDEE.mjs → browser/analysis-change-entry-FCSHFQSS.mjs} +1 -1
  10. package/dist/browser/{chunk-TQ5UMFG5.mjs → chunk-2FX6ROWR.mjs} +15 -6
  11. package/dist/browser/{chunk-KWYQ6KX4.mjs → chunk-2SHAKW2Z.mjs} +119 -1922
  12. package/dist/browser/{chunk-55WYRLDZ.mjs → chunk-3U3QR5YP.mjs} +2 -2
  13. package/dist/browser/chunk-4PD752F6.mjs +85 -0
  14. package/dist/browser/chunk-5W3MMTLG.mjs +19 -0
  15. package/dist/browser/{chunk-IAXZAVYL.mjs → chunk-7MEYN7V6.mjs} +1 -151
  16. package/dist/browser/chunk-7TTWXUH6.mjs +1828 -0
  17. package/dist/browser/{chunk-CSCKZBVJ.mjs → chunk-AJ4HHOVT.mjs} +4 -4
  18. package/dist/{react-native/chunks/chunk-DFQJ4IJB.mjs → browser/chunk-AYY6PIKL.mjs} +2 -2
  19. package/dist/browser/{chunk-VD7JEUIR.mjs → chunk-C4KS2QNF.mjs} +9 -8
  20. package/dist/browser/chunk-DSXIBE6N.mjs +78 -0
  21. package/dist/browser/chunk-ELV4OZOI.mjs +29 -0
  22. package/dist/browser/{chunk-PM4MUM5N.mjs → chunk-EUNBNLKM.mjs} +6 -5
  23. package/dist/browser/{chunk-GJKXW3SF.mjs → chunk-G7LUMBSG.mjs} +137 -253
  24. package/dist/browser/{chunk-B3JM6Z74.mjs → chunk-H6QFBMVE.mjs} +3 -2
  25. package/dist/browser/chunk-J433A7P3.mjs +241 -0
  26. package/dist/browser/chunk-ML6HY7T7.mjs +96 -0
  27. package/dist/browser/chunk-ML7THVLJ.mjs +38 -0
  28. package/dist/{chunk-MDF6PDIA.mjs → browser/chunk-MYITLCHT.mjs} +7 -1
  29. package/dist/browser/{chunk-QJCO3TJU.mjs → chunk-QXTPSX2H.mjs} +9 -150
  30. package/dist/browser/{chunk-MPK76GVS.mjs → chunk-RA6LSBCM.mjs} +1 -21
  31. package/dist/browser/{chunk-7ZJTRUVW.mjs → chunk-SIR3LMTV.mjs} +2 -2
  32. package/dist/browser/{chunk-LURXVCHG.mjs → chunk-SJB6VIZG.mjs} +1 -1
  33. package/dist/browser/chunk-TTD27VXX.mjs +298 -0
  34. package/dist/browser/chunk-U2E3HMYW.mjs +151 -0
  35. package/dist/browser/{chunk-2A2IPRC3.mjs → chunk-VCOYGVP7.mjs} +5 -31
  36. package/dist/browser/chunk-VI7BQR4U.mjs +21 -0
  37. package/dist/browser/chunk-W5X2UFWQ.mjs +102 -0
  38. package/dist/browser/{chunk-HT7J73QL.mjs → chunk-XRV72TJD.mjs} +2 -2
  39. package/dist/browser/chunk-YJHGOJAC.mjs +15 -0
  40. package/dist/browser/chunk-ZI2V4VD7.mjs +21 -0
  41. package/dist/{react-native/chunks/chunk-QC4ZRBSX.mjs → browser/chunk-ZPTA75ZC.mjs} +2 -79
  42. package/dist/browser/{cold-module-YECAK4MN.mjs → cold-module-VTUGDYNY.mjs} +20 -14
  43. package/dist/browser/{durability-wiring-LM7WFL6X.mjs → durability-wiring-GL4A7KDV.mjs} +1886 -1364
  44. package/dist/browser/import-YI5GNB4H.mjs +17 -0
  45. package/dist/browser/methods-LMUTS7OI.mjs +30 -0
  46. package/dist/browser/{module-XQLEOYNM.mjs → module-EC3FYW7N.mjs} +9 -8
  47. package/dist/browser/{module-KAMRAJLE.mjs → module-M4JNBV6V.mjs} +16 -10
  48. package/dist/browser/operations-WVYLF72Q.mjs +5 -0
  49. package/dist/browser/{phrase-module-CNKMUY4U.mjs → phrase-module-NPYUVX75.mjs} +1 -1
  50. package/dist/browser/{pool-DTYSPBMQ.mjs → pool-WCGDZHJP.mjs} +3 -2
  51. package/dist/{restore-queue-AOF5OTQV.mjs → browser/restore-queue-TYIGDL5L.mjs} +2 -2
  52. package/dist/browser/retention-6QMRS5VK.mjs +207 -0
  53. package/dist/browser/{runtime-D2ULZGCN.mjs → runtime-3EW2AGB6.mjs} +1 -1
  54. package/dist/browser/{snapshot-UGZVMP4H.mjs → snapshot-DN3CRVUQ.mjs} +38 -307
  55. package/dist/browser/sync-state-P5XG6LTQ.mjs +15 -0
  56. package/dist/browser/{write-I5P5MW4O.mjs → write-WAWAFGKQ.mjs} +16 -11
  57. package/dist/{capabilities-BT-HLDC8.d.ts → capabilities-B3Brs1Rc.d.ts} +62 -7
  58. package/dist/{chunk-DGRM4EZZ.mjs → chunk-37IVJLP6.mjs} +1 -1
  59. package/dist/{chunk-KYVRZAYP.mjs → chunk-3A5KI24C.mjs} +2 -69
  60. package/dist/{chunk-POUYICOU.mjs → chunk-3OFU3NJT.mjs} +1 -1
  61. package/dist/{chunk-3TVDTACC.mjs → chunk-3Y3J4V2R.mjs} +1 -1
  62. package/dist/{chunk-FNBNZCGP.mjs → chunk-466PYR4P.mjs} +2 -2
  63. package/dist/{chunk-SEAJS664.mjs → chunk-4HWZV5MK.mjs} +5 -5
  64. package/dist/{chunk-UGVUW27S.mjs → chunk-5FUOVJKG.mjs} +13 -9
  65. package/dist/{chunk-ZHAXP7SD.mjs → chunk-5KGYQT6W.mjs} +6 -235
  66. package/dist/{chunk-NPXVQS33.mjs → chunk-62G63NMH.mjs} +4 -3
  67. package/dist/chunk-6MSZ543Y.mjs +32 -0
  68. package/dist/chunk-7GXJUJ24.mjs +49 -0
  69. package/dist/{chunk-3E4RRF5J.mjs → chunk-7HCZWC7B.mjs} +58 -8
  70. package/dist/{chunk-6RKSY3BX.mjs → chunk-7NTMUDC5.mjs} +5 -5
  71. package/dist/chunk-7QUGDVFC.mjs +101 -0
  72. package/dist/{chunk-G5KHSM6E.mjs → chunk-AO2FAYIZ.mjs} +1 -1
  73. package/dist/chunk-B7S6YEBP.mjs +102 -0
  74. package/dist/{chunk-AWNHDBKV.mjs → chunk-BPSKLCS7.mjs} +15 -7
  75. package/dist/chunk-BUMREPLU.mjs +15 -0
  76. package/dist/{chunk-T4CJDBBE.mjs → chunk-C6ASEFZI.mjs} +1 -1
  77. package/dist/{chunk-NITCPDFL.mjs → chunk-C73JLU4E.mjs} +2 -2
  78. package/dist/{chunk-NYSONUB7.mjs → chunk-CP5RRPJR.mjs} +1 -1
  79. package/dist/{chunk-TTCKT2RT.mjs → chunk-DMQPFLGI.mjs} +134 -11
  80. package/dist/{chunk-3SBJVQLL.mjs → chunk-DVWYODEB.mjs} +2 -2
  81. package/dist/chunk-ECX4SGX6.mjs +167 -0
  82. package/dist/chunk-GES7U2PM.mjs +68 -0
  83. package/dist/{chunk-NVTFQFUL.mjs → chunk-HVKXNBFL.mjs} +1 -1
  84. package/dist/chunk-HVYICDY3.mjs +214 -0
  85. package/dist/{chunk-3HV7M5OJ.mjs → chunk-HWEDFLB7.mjs} +9 -133
  86. package/dist/{chunk-52QQWEBS.mjs → chunk-IBNLW3AV.mjs} +21 -6
  87. package/dist/chunk-IJU7LL7D.mjs +242 -0
  88. package/dist/chunk-IPN7S4KX.mjs +130 -0
  89. package/dist/{chunk-5QMHMELB.mjs → chunk-IQ4R2I6N.mjs} +4 -1
  90. package/dist/chunk-JCLTESFN.mjs +96 -0
  91. package/dist/{chunk-J4BDAH2W.mjs → chunk-JFNKIBDT.mjs} +2 -2
  92. package/dist/{chunk-LDGGR7YT.mjs → chunk-K4B7OH65.mjs} +2 -2
  93. package/dist/{chunk-7TE2AJIH.mjs → chunk-K7KLL263.mjs} +13 -10
  94. package/dist/{chunk-CSHHU7PA.mjs → chunk-KCUIFVVW.mjs} +11 -30
  95. package/dist/{react-native/chunks/chunk-YH7W556M.mjs → chunk-KUZKUONM.mjs} +11 -2
  96. package/dist/chunk-KYYABCSW.mjs +72 -0
  97. package/dist/{chunk-B2FTZNNF.mjs → chunk-LKUE5GXS.mjs} +34 -14
  98. package/dist/{chunk-2PNYKG2D.mjs → chunk-LSM2YTKM.mjs} +100 -335
  99. package/dist/{chunk-DMNPYF54.mjs → chunk-LTUGDMV4.mjs} +2 -2
  100. package/dist/{chunk-FDG4KXX5.mjs → chunk-MLHNSAPK.mjs} +5 -3
  101. package/dist/{chunk-VP6XRMWR.mjs → chunk-MMBEANB2.mjs} +6 -32
  102. package/dist/{chunk-LJ4ENXOD.mjs → chunk-MMEMEUOO.mjs} +2 -2
  103. package/dist/{chunk-2HJWQPR6.mjs → chunk-NTZOXVUZ.mjs} +6 -122
  104. package/dist/{chunk-5WB2A3XU.mjs → chunk-NZMAXR2S.mjs} +397 -24
  105. package/dist/{chunk-IZT3G24Q.mjs → chunk-O43Z4MS6.mjs} +2 -2
  106. package/dist/{chunk-U46IZNCW.mjs → chunk-OKX2BBNW.mjs} +3 -2
  107. package/dist/{chunk-RBEHLIKX.mjs → chunk-PFKM7VNZ.mjs} +14 -8
  108. package/dist/chunk-PGVPE7GJ.mjs +96 -0
  109. package/dist/chunk-Q3TCTQCC.mjs +85 -0
  110. package/dist/chunk-Q7MS6P2J.mjs +74 -0
  111. package/dist/chunk-QDZJM7NI.mjs +23 -0
  112. package/dist/{chunk-ZS6CMXAE.mjs → chunk-QKZHLADX.mjs} +89 -250
  113. package/dist/{chunk-IJSFWGVW.mjs → chunk-REL7LFLR.mjs} +3 -3
  114. package/dist/chunk-RVKFI3A2.mjs +237 -0
  115. package/dist/chunk-S2N75OTN.mjs +83 -0
  116. package/dist/chunk-TRISKD4Q.mjs +50 -0
  117. package/dist/{chunk-6F6USYII.mjs → chunk-TV2L3BN7.mjs} +13 -11
  118. package/dist/{chunk-6BWLDLS3.mjs → chunk-URPCYQVJ.mjs} +1 -1
  119. package/dist/chunk-USR7FQRZ.mjs +34 -0
  120. package/dist/chunk-V6EUBAIT.mjs +19 -0
  121. package/dist/{chunk-SOUZMPME.mjs → chunk-VMXSVVXG.mjs} +7 -194
  122. package/dist/{chunk-4QCSHLNM.mjs → chunk-VREK3MYG.mjs} +3 -3
  123. package/dist/{chunk-YGQOPB2Z.mjs → chunk-WCBA2LVZ.mjs} +1 -1
  124. package/dist/{chunk-KQJVNPRM.mjs → chunk-X6NSJYQ3.mjs} +19 -16
  125. package/dist/chunk-Y4WPNHMC.mjs +50 -0
  126. package/dist/{chunk-IRWP524D.mjs → chunk-YBJDOA2T.mjs} +1 -1
  127. package/dist/{chunk-IJPK5PGM.mjs → chunk-YPUEV6ZC.mjs} +1 -1
  128. package/dist/{chunk-J7M73VY7.mjs → chunk-YROWNOMH.mjs} +1 -1
  129. package/dist/chunk-Z3TNWCI5.mjs +196 -0
  130. package/dist/{chunk-65WCV5JO.mjs → chunk-ZIFJXCKA.mjs} +1 -1
  131. package/dist/chunk-ZYAY26KG.mjs +29 -0
  132. package/dist/{client-Cn3gNxUU.d.ts → client-Df76GNKm.d.ts} +76 -6
  133. package/dist/client.d.ts +8 -7
  134. package/dist/client.mjs +56 -5
  135. package/dist/{cold-module-PYSSBIL7.mjs → cold-module-YLWMTTZG.mjs} +38 -28
  136. package/dist/{config-CfhH1IWQ.d.ts → config-05G_hy-1.d.ts} +3 -3
  137. package/dist/config-B8DP2VwR.d.ts +463 -0
  138. package/dist/{direct-executor-WYALQSMD.mjs → direct-executor-FI5GJHWX.mjs} +14 -9
  139. package/dist/distribution/coordinator/etcd.d.ts +11 -2
  140. package/dist/distribution/coordinator/etcd.mjs +268 -107
  141. package/dist/distribution/coordinator/in-memory.d.ts +2 -2
  142. package/dist/distribution/transport/grpc.mjs +4 -4
  143. package/dist/distribution/transport/in-memory.mjs +2 -2
  144. package/dist/distribution/transport/tcp.mjs +3 -3
  145. package/dist/distribution.d.ts +41 -9
  146. package/dist/distribution.mjs +1296 -117
  147. package/dist/{durability-wiring-7VBZEJLG.mjs → durability-wiring-RHLXDIVF.mjs} +1751 -1226
  148. package/dist/embeddings/openai.mjs +2 -2
  149. package/dist/{engine-CJRUHXgf.d.ts → engine-DYu-e0oR.d.ts} +50 -40
  150. package/dist/{import-GJOMB2HC.mjs → import-SRBNC6TE.mjs} +27 -19
  151. package/dist/{index-MsF7e5hL.d.ts → index-nRqDM6uS.d.ts} +1 -1
  152. package/dist/index.browser.mjs +8 -4
  153. package/dist/index.d.ts +7 -6
  154. package/dist/index.mjs +24 -16
  155. package/dist/index.react-native.mjs +17 -11
  156. package/dist/{long-query-thread-SCUE62TO.mjs → long-query-thread-EMYTGSJP.mjs} +28 -15
  157. package/dist/methods-ABM5ELBR.mjs +30 -0
  158. package/dist/{module-AVQEIB7O.mjs → module-3OMJZUFT.mjs} +12 -12
  159. package/dist/{module-6RLIKSZQ.mjs → module-MG7JMV2U.mjs} +33 -23
  160. package/dist/operations-PGOAY2KS.mjs +5 -0
  161. package/dist/{paged-partition-archive-KGRW366Y.mjs → paged-partition-archive-UOLHOEZJ.mjs} +37 -26
  162. package/dist/partial-words.mjs +6 -4
  163. package/dist/pattern.mjs +4 -3
  164. package/dist/persistence/durability/checkpoint-worker.d.ts +9 -1
  165. package/dist/persistence/durability/checkpoint-worker.mjs +34 -23
  166. package/dist/{phrase-module-OUQIRUQU.mjs → phrase-module-O3MDRQXP.mjs} +1 -1
  167. package/dist/{pool-UPV5PVPY.mjs → pool-CQXYPFLG.mjs} +2 -2
  168. package/dist/react-native/chunks/{analysis-change-DXPZRGWF.mjs → analysis-change-EAYO3Y6Q.mjs} +27 -15
  169. package/dist/{browser/analysis-change-entry-JL5U2N3Q.mjs → react-native/chunks/analysis-change-entry-TNLUC6IZ.mjs} +1 -1
  170. package/dist/react-native/chunks/{chunk-D7LFYPYI.mjs → chunk-2CGSQM4O.mjs} +12 -10
  171. package/dist/react-native/chunks/chunk-3NQOVO3K.mjs +1 -0
  172. package/dist/react-native/chunks/{chunk-R4OPUZQ5.mjs → chunk-3O57C2ZO.mjs} +2 -2
  173. package/dist/react-native/chunks/chunk-3XKMRNRE.mjs +298 -0
  174. package/dist/react-native/chunks/{chunk-IDFMNRIC.mjs → chunk-63YSZOXB.mjs} +97 -333
  175. package/dist/react-native/chunks/{chunk-UFNCLEQM.mjs → chunk-75VWIY35.mjs} +1 -1
  176. package/dist/react-native/chunks/{chunk-2J2727V4.mjs → chunk-7GWPJDOA.mjs} +1 -1
  177. package/dist/react-native/chunks/{chunk-PU55IOG4.mjs → chunk-AUT7PMA4.mjs} +6 -190
  178. package/dist/react-native/chunks/chunk-C2H2QQFW.mjs +288 -0
  179. package/dist/react-native/chunks/chunk-CHPTFFJM.mjs +43 -0
  180. package/dist/{browser/chunk-PIS7ZAP7.mjs → react-native/chunks/chunk-CUNGPR5R.mjs} +11 -2
  181. package/dist/{browser/chunk-NVEJJP4R.mjs → react-native/chunks/chunk-DCKMICOB.mjs} +2 -79
  182. package/dist/react-native/chunks/chunk-DH3TVWWK.mjs +102 -0
  183. package/dist/react-native/chunks/{chunk-ZCKNBPQ4.mjs → chunk-EH5CFV6Z.mjs} +2 -2
  184. package/dist/react-native/chunks/chunk-F753DA54.mjs +23 -0
  185. package/dist/{browser/chunk-VBX2TI5V.mjs → react-native/chunks/chunk-GFYFQLJD.mjs} +2 -2
  186. package/dist/react-native/chunks/{chunk-7IQR3SZO.mjs → chunk-I5PGWQJF.mjs} +142 -257
  187. package/dist/react-native/chunks/{chunk-NFGBOI46.mjs → chunk-IOY2SM2P.mjs} +1 -1
  188. package/dist/react-native/chunks/chunk-JDOEEMEF.mjs +38 -0
  189. package/dist/react-native/chunks/{chunk-TLYD7IJ2.mjs → chunk-JPAJWO6D.mjs} +1 -1
  190. package/dist/react-native/chunks/chunk-JWUCMVRK.mjs +15 -0
  191. package/dist/react-native/chunks/{chunk-KLZGAOLT.mjs → chunk-JX2RIAXH.mjs} +4 -4
  192. package/dist/react-native/chunks/chunk-LU3Y3P63.mjs +68 -0
  193. package/dist/react-native/chunks/{chunk-LQAKO5QV.mjs → chunk-NCJS3WIY.mjs} +2 -2
  194. package/dist/react-native/chunks/{chunk-BRNAVOKP.mjs → chunk-NKIZX26F.mjs} +2 -2
  195. package/dist/react-native/chunks/{chunk-CLE3LZ77.mjs → chunk-NP7DD4G5.mjs} +5 -4
  196. package/dist/react-native/chunks/chunk-NVVRSRX5.mjs +78 -0
  197. package/dist/react-native/chunks/chunk-O32RB3BL.mjs +191 -0
  198. package/dist/react-native/chunks/{chunk-DKJTZ625.mjs → chunk-OQQVRWZ2.mjs} +2 -69
  199. package/dist/react-native/chunks/chunk-PB2YXVQW.mjs +29 -0
  200. package/dist/react-native/chunks/chunk-Q32DDFKX.mjs +19 -0
  201. package/dist/react-native/chunks/{chunk-LRGWK367.mjs → chunk-RVAEBN74.mjs} +1 -1
  202. package/dist/react-native/chunks/{chunk-KOCTCUXW.mjs → chunk-RYMDHGL4.mjs} +16 -8
  203. package/dist/react-native/chunks/chunk-SJWDBRNP.mjs +85 -0
  204. package/dist/react-native/chunks/chunk-UNUFZ2QY.mjs +68 -0
  205. package/dist/react-native/chunks/chunk-UWDNZDWK.mjs +242 -0
  206. package/dist/react-native/chunks/{chunk-FS7BYE23.mjs → chunk-VQSKZ3EZ.mjs} +9 -152
  207. package/dist/react-native/chunks/{chunk-UCJU6WNH.mjs → chunk-VVFYOADG.mjs} +7 -6
  208. package/dist/react-native/chunks/{chunk-VGUWIZFQ.mjs → chunk-YBEW6YTR.mjs} +1 -1
  209. package/dist/react-native/chunks/{chunk-JYL35A4A.mjs → chunk-YHKZSLOC.mjs} +7 -33
  210. package/dist/react-native/chunks/{chunk-3CTWSQRW.mjs → chunk-ZBSWRSBG.mjs} +4 -30
  211. package/dist/react-native/chunks/chunk-ZYDKJXQJ.mjs +96 -0
  212. package/dist/react-native/chunks/{cold-module-KFGEWYEL.mjs → cold-module-TJL6AFAD.mjs} +29 -21
  213. package/dist/react-native/chunks/{durability-wiring-QKJB2QBT.mjs → durability-wiring-RRDYJLLM.mjs} +1882 -1358
  214. package/dist/react-native/chunks/gzip.react-native-DNB5YNFA.mjs +3 -0
  215. package/dist/react-native/chunks/import-JYBMEJPQ.mjs +29 -0
  216. package/dist/react-native/chunks/methods-X6F36SJE.mjs +30 -0
  217. package/dist/react-native/chunks/module-QT5HZAY4.mjs +33 -0
  218. package/dist/react-native/chunks/{module-UJ5VUARS.mjs → module-S4DKSWMF.mjs} +10 -9
  219. package/dist/react-native/chunks/operations-RYKTSZQA.mjs +5 -0
  220. package/dist/react-native/chunks/{phrase-module-76UAPPSG.mjs → phrase-module-JZ37TB7N.mjs} +1 -1
  221. package/dist/react-native/chunks/{pool-CD4ANYUI.mjs → pool-RTGXJXPU.mjs} +3 -2
  222. package/dist/{browser/restore-queue-UQ6AAUVX.mjs → react-native/chunks/restore-queue-ZBVIKJWI.mjs} +2 -2
  223. package/dist/react-native/chunks/retention-PPCTP2VY.mjs +219 -0
  224. package/dist/react-native/chunks/{runtime-3MCDLJAF.mjs → runtime-KUATOLYB.mjs} +1 -1
  225. package/dist/react-native/chunks/{snapshot-KVBD4LRC.mjs → snapshot-ZBIEOZTZ.mjs} +47 -314
  226. package/dist/react-native/chunks/sync-state-PASCIHHT.mjs +15 -0
  227. package/dist/react-native/chunks/{write-ES5A3WUA.mjs → write-2W4FTX7J.mjs} +25 -18
  228. package/dist/react-native/partial-words.mjs +6 -4
  229. package/dist/react-native/pattern.mjs +4 -3
  230. package/dist/react-native/sync.mjs +2236 -0
  231. package/dist/react-native/synonyms.mjs +7 -4
  232. package/dist/react.d.ts +10 -9
  233. package/dist/react.mjs +7 -1
  234. package/dist/{rerank-3W54N6P2.mjs → rerank-IZOB6NII.mjs} +4 -4
  235. package/dist/rerankers/http.mjs +2 -2
  236. package/dist/{react-native/chunks/restore-queue-H5VCN453.mjs → restore-queue-COI2GSSK.mjs} +2 -2
  237. package/dist/retention-55WA7GPU.mjs +58 -0
  238. package/dist/{runtime-L2DZYY6N.mjs → runtime-UZOC3NPY.mjs} +5 -5
  239. package/dist/{schema-D33CyXCy.d.ts → schema-DDauvDOv.d.ts} +1 -1
  240. package/dist/server.d.ts +22 -19
  241. package/dist/server.mjs +868 -50
  242. package/dist/{snapshot-WMX6JCLP.mjs → snapshot-NFX2EYN2.mjs} +62 -36
  243. package/dist/sync/filesystem.d.ts +30 -0
  244. package/dist/sync/filesystem.mjs +271 -0
  245. package/dist/sync/indexeddb.d.ts +30 -0
  246. package/dist/sync/indexeddb.mjs +237 -0
  247. package/dist/sync-state-ZWHLAFLE.mjs +15 -0
  248. package/dist/{config-aIsy7mcL.d.ts → sync-uXR7MmM7.d.ts} +53 -444
  249. package/dist/sync.browser.mjs +2231 -0
  250. package/dist/sync.d.ts +23 -0
  251. package/dist/sync.mjs +2206 -0
  252. package/dist/synonyms.mjs +5 -3
  253. package/dist/{tasks-C4ElXr4P.d.ts → tasks-BShx8pdK.d.ts} +4 -4
  254. package/dist/thread-P2G2FWM2.mjs +44 -0
  255. package/dist/types-SnO7_tAI.d.ts +228 -0
  256. package/dist/vector/search-worker.d.ts +1 -1
  257. package/dist/vector/search-worker.mjs +6 -6
  258. package/dist/workers/entry.mjs +7 -7
  259. package/dist/{write-SKJ6HW7O.mjs → write-FGB62BHQ.mjs} +31 -23
  260. package/openapi.json +119 -3
  261. package/package.json +28 -8
  262. package/dist/browser/import-QOY6ZH6X.mjs +0 -12
  263. package/dist/chunk-7LDMWKP6.mjs +0 -209
  264. package/dist/react-native/chunks/chunk-L4M7QJNP.mjs +0 -110
  265. package/dist/react-native/chunks/gzip.react-native-7JWCLVOB.mjs +0 -3
  266. package/dist/react-native/chunks/import-XFBCCENV.mjs +0 -22
  267. package/dist/react-native/chunks/module-FHJ2GOBI.mjs +0 -25
  268. package/dist/thread-I7DVHHW7.mjs +0 -31
package/dist/server.mjs CHANGED
@@ -1,56 +1,562 @@
1
- import { answerRequest } from './chunk-B2FTZNNF.mjs';
2
- import { DEFAULT_MAX_RETAINED_TASKS, loadUWebSockets, resolveCors, authorizerFor, createSharedGateBuffer, gateSlotOfWorker, createBodyBudgetBuffer, createRouteRunner, corsHeaderReader, createSharedBodyBudget, MAIN_THREAD_GATE_SLOT, createSharedRequestGate, registerServerRoutes, DEFAULT_MAX_CONCURRENT_TASKS, DEFAULT_MAX_TASK_PAGE_SIZE, DEFAULT_MAX_IMPORT_ERRORS, DEFAULT_MAX_FETCH_DOCUMENTS, DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_CONCURRENT_REQUESTS, DEFAULT_IMPORT_BATCH_SIZE, DEFAULT_MAX_LINE_BYTES, DEFAULT_MAX_RESTORE_BYTES, DEFAULT_MAX_IMPORT_BYTES, DEFAULT_MAX_BODY_BYTES, DEFAULT_MAX_RERANK_WINDOW, DEFAULT_MAX_BODY_BYTES_IN_FLIGHT_FRACTION, RUNNING_TASK_TTL_MS, DEFAULT_TASK_PAGE_SIZE, TERMINAL_TASK_TTL_MS, TASK_PROGRESS_WRITE_INTERVAL_MS, serializeNarsilError, createVersionHandler, acceptorOf, MAX_BODY_BYTES_IN_FLIGHT_FRACTION, createDocumentReadHandlers, sendError, respondError, respondJson, sendText, PROMETHEUS_TEXT_CONTENT_TYPE, MAX_INDEX_TOUCH_INTERVAL_MS, INDEX_TOUCH_INTERVALS_PER_IDLE_TIMEOUT, closeEveryThreadAtExit, REQUEST_THREAD_CLOSE_AT_EXIT_MS, clearGateSlot, clearBodyBudgetSlot, createCloseAtExitWords, createDepartureWord, departureConfirmed, parseJson, validateCreateIndex, rejectInvalid, isRemoveOnlyBatch, validateBatch, serializeBatchResult, parseWriteJson, validateDocumentBody, validateSuggest, validateQuery, refuseRegex, withServerRerankWindow, respondAnswer, parseTaskListQuery, parseJsonOptional, validateChangeAnalysis, validateRebalance, badRequest, sendStream, SNAPSHOT_ARCHIVE_CONTENT_TYPE, DOCUMENT_EXPORT_CONTENT_TYPE, parseRefusalOf, IMPORT_FLUSHES_IN_FLIGHT, confirmDeparture, SERVER_CAPABILITIES, toHttpError, MIN_UNBOUNDED_SERVER_LIMIT, MIN_COUNTED_SERVER_LIMIT } from './chunk-5WB2A3XU.mjs';
3
- export { ASYNC_IMPORT_CAPABILITY, BM25_TUNING_CAPABILITY, CHANGE_ANALYSIS_CAPABILITY, DOCUMENT_EXPORT_CAPABILITY, INDEX_LIFECYCLE_CAPABILITY, REBUILD_ANALYSIS_CAPABILITY, SERVER_CAPABILITIES, SYNONYMS_CAPABILITY, TASK_CANCEL_CAPABILITY, TASK_FILTER_CAPABILITY, httpStatusForNarsilError } from './chunk-5WB2A3XU.mjs';
4
- import { rerankOnHost } from './chunk-YGQOPB2Z.mjs';
5
- import { writeBlockLookupOf, indexReadsOf, validateBackupName, readRestorePlacement } from './chunk-52QQWEBS.mjs';
6
- import './chunk-LDGGR7YT.mjs';
7
- import { isRecord, validateIndexName } from './chunk-3E4RRF5J.mjs';
8
- import './chunk-IRWP524D.mjs';
1
+ import { answerRequest } from './chunk-LKUE5GXS.mjs';
2
+ import { DEFAULT_MAX_RETAINED_TASKS, loadUWebSockets, registerFeedRoute, resolveCors, authorizerFor, createSharedGateBuffer, gateSlotOfWorker, createBodyBudgetBuffer, createRouteRunner, corsHeaderReader, createSharedBodyBudget, MAIN_THREAD_GATE_SLOT, createSharedRequestGate, registerServerRoutes, DEFAULT_MAX_FEED_BUFFERED_BYTES, DEFAULT_MAX_FEED_CATCH_UPS, DEFAULT_MAX_FEED_CONNECTIONS, DEFAULT_FEED_WINDOW_BYTES, DEFAULT_MAX_CONCURRENT_TASKS, DEFAULT_MAX_TASK_PAGE_SIZE, DEFAULT_MAX_IMPORT_ERRORS, DEFAULT_MAX_FETCH_DOCUMENTS, DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_CONCURRENT_REQUESTS, DEFAULT_IMPORT_BATCH_SIZE, DEFAULT_MAX_LINE_BYTES, DEFAULT_MAX_RESTORE_BYTES, DEFAULT_MAX_IMPORT_BYTES, DEFAULT_MAX_BODY_BYTES, DEFAULT_MAX_RERANK_WINDOW, DEFAULT_MAX_BODY_BYTES_IN_FLIGHT_FRACTION, RUNNING_TASK_TTL_MS, DEFAULT_TASK_PAGE_SIZE, TERMINAL_TASK_TTL_MS, TASK_PROGRESS_WRITE_INTERVAL_MS, serializeNarsilError, createVersionHandler, createSyncSnapshotHandler, acceptorOf, MAX_BODY_BYTES_IN_FLIGHT_FRACTION, toHttpError, createDocumentReadHandlers, sendError, respondError, respondJson, sendText, PROMETHEUS_TEXT_CONTENT_TYPE, MAX_INDEX_TOUCH_INTERVAL_MS, INDEX_TOUCH_INTERVALS_PER_IDLE_TIMEOUT, closeEveryThreadAtExit, REQUEST_THREAD_CLOSE_AT_EXIT_MS, clearGateSlot, clearBodyBudgetSlot, createCloseAtExitWords, createDepartureWord, departureConfirmed, TIMER_DELAY_LIMIT_MS, FEED_HEAD_RETRY_MS, parseJson, validateCreateIndex, rejectInvalid, isRemoveOnlyBatch, validateBatch, serializeBatchResult, parseWriteJson, validateDocumentBody, validateSuggest, validateQuery, refuseRegex, withServerRerankWindow, respondAnswer, parseTaskListQuery, parseJsonOptional, validateChangeAnalysis, validateRebalance, badRequest, sendStream, SNAPSHOT_ARCHIVE_CONTENT_TYPE, DOCUMENT_EXPORT_CONTENT_TYPE, parseRefusalOf, IMPORT_FLUSHES_IN_FLIGHT, confirmDeparture, isThreadFeedNote, ENTRIES_MESSAGE_LIMIT_BYTES, SERVER_CAPABILITIES, MIN_UNBOUNDED_SERVER_LIMIT, MIN_COUNTED_SERVER_LIMIT } from './chunk-NZMAXR2S.mjs';
3
+ export { ASYNC_IMPORT_CAPABILITY, BM25_TUNING_CAPABILITY, CHANGE_ANALYSIS_CAPABILITY, DOCUMENT_EXPORT_CAPABILITY, INDEX_LIFECYCLE_CAPABILITY, REBUILD_ANALYSIS_CAPABILITY, SERVER_CAPABILITIES, SYNONYMS_CAPABILITY, TASK_CANCEL_CAPABILITY, TASK_FILTER_CAPABILITY, httpStatusForNarsilError } from './chunk-NZMAXR2S.mjs';
4
+ import { rerankOnHost } from './chunk-WCBA2LVZ.mjs';
5
+ import { startSyncRetentionSweep, publishedSyncSnapshot, publishedArchiveLayout } from './chunk-ECX4SGX6.mjs';
6
+ import './chunk-PGVPE7GJ.mjs';
7
+ import { SYNC_CLOSE_RESYNC, SYNC_CLOSE_CREDENTIAL_EXPIRED, SYNC_CLOSE_POLICY, MAX_DEVICE_MESSAGE_BYTES, SYNC_CLOSE_TOO_LARGE, deviceMessageOf, SYNC_CLOSE_SERVER_ERROR, positionList, positionsByPartition, SYNC_CLOSE_GOING_AWAY } from './chunk-KYYABCSW.mjs';
8
+ import { syncServingSourceOf, writeBlockLookupOf, indexReadsOf, validateBackupName, readRestorePlacement } from './chunk-IBNLW3AV.mjs';
9
+ import './chunk-K4B7OH65.mjs';
10
+ import { isRecord, validateIndexName } from './chunk-7HCZWC7B.mjs';
11
+ import { estimatedArchiveBytes } from './chunk-Q7MS6P2J.mjs';
12
+ import './chunk-YBJDOA2T.mjs';
13
+ import './chunk-B7S6YEBP.mjs';
14
+ import './chunk-V6EUBAIT.mjs';
15
+ import './chunk-ZYAY26KG.mjs';
16
+ import './chunk-5KGYQT6W.mjs';
17
+ import './chunk-IJU7LL7D.mjs';
18
+ import './chunk-BUMREPLU.mjs';
19
+ import './chunk-AO2FAYIZ.mjs';
9
20
  import './chunk-DJHHF2L5.mjs';
21
+ import './chunk-37CD3OKS.mjs';
10
22
  import './chunk-JDDXV6UF.mjs';
11
- import { rerankWindowCapOf, engineCoreOf, providedDocId, resolveVectorText } from './chunk-2PNYKG2D.mjs';
12
- import { readMemoryFigures } from './chunk-6F6USYII.mjs';
13
- import './chunk-UGVUW27S.mjs';
14
- import './chunk-3HV7M5OJ.mjs';
15
- import './chunk-KAKQ74LS.mjs';
23
+ import { manifestFileRefs } from './chunk-Q3TCTQCC.mjs';
24
+ import './chunk-QDZJM7NI.mjs';
25
+ import { rerankWindowCapOf, engineCoreOf, rulesOfStoredSynonyms, providedDocId, resolveVectorText } from './chunk-LSM2YTKM.mjs';
26
+ import { readMemoryFigures } from './chunk-TV2L3BN7.mjs';
16
27
  import { MAX_RERANK_WINDOW } from './chunk-HJSN7UYG.mjs';
17
- import { detectRuntime } from './chunk-6BWLDLS3.mjs';
28
+ import { detectRuntime } from './chunk-URPCYQVJ.mjs';
18
29
  import './chunk-XIHUI4KB.mjs';
19
- import './chunk-Q2UL2TPC.mjs';
20
30
  import './chunk-3MXV3VHR.mjs';
21
31
  import './chunk-EEBCDP36.mjs';
22
- import './chunk-2HJWQPR6.mjs';
32
+ import './chunk-5FUOVJKG.mjs';
33
+ import './chunk-HWEDFLB7.mjs';
34
+ import './chunk-USR7FQRZ.mjs';
35
+ import './chunk-HVYICDY3.mjs';
36
+ import './chunk-IPN7S4KX.mjs';
37
+ import './chunk-KAKQ74LS.mjs';
38
+ import './chunk-7GXJUJ24.mjs';
39
+ import './chunk-Q2UL2TPC.mjs';
40
+ import './chunk-NTZOXVUZ.mjs';
23
41
  import './chunk-X5CV2E2B.mjs';
42
+ import { listenForSyncChanges } from './chunk-Y4WPNHMC.mjs';
43
+ import './chunk-JCLTESFN.mjs';
24
44
  import './chunk-TGP5M5R7.mjs';
25
45
  import './chunk-U2BKYEC7.mjs';
26
- import './chunk-DGRM4EZZ.mjs';
27
46
  import './chunk-QHPYS427.mjs';
28
47
  import { startIdleHeapCleanup } from './chunk-QYRNLLLI.mjs';
48
+ import './chunk-37IVJLP6.mjs';
29
49
  import './chunk-ZXNQEW43.mjs';
30
50
  import './chunk-KOKM4PQN.mjs';
31
- import './chunk-NVTFQFUL.mjs';
32
- import './chunk-LQG5G2LY.mjs';
51
+ import './chunk-HVKXNBFL.mjs';
33
52
  import './chunk-BTPGQC6Z.mjs';
53
+ import './chunk-LQG5G2LY.mjs';
34
54
  import './chunk-RFBLQLLZ.mjs';
35
- import './chunk-U46IZNCW.mjs';
55
+ import './chunk-OKX2BBNW.mjs';
36
56
  import './chunk-JUKYYXSP.mjs';
37
- import './chunk-SOUZMPME.mjs';
57
+ import './chunk-VMXSVVXG.mjs';
58
+ import './chunk-Z3TNWCI5.mjs';
38
59
  import './chunk-FQBFZAWG.mjs';
39
- import './chunk-65WCV5JO.mjs';
60
+ import './chunk-ZIFJXCKA.mjs';
40
61
  import './chunk-4UMZ7KQL.mjs';
41
62
  import './chunk-ZXX5GZEX.mjs';
42
- import './chunk-KYVRZAYP.mjs';
63
+ import './chunk-GES7U2PM.mjs';
64
+ import './chunk-3A5KI24C.mjs';
43
65
  import './chunk-L5ORED7V.mjs';
44
- import './chunk-3TVDTACC.mjs';
66
+ import './chunk-3Y3J4V2R.mjs';
45
67
  import './chunk-U476IXKQ.mjs';
46
- import { NarsilError, ErrorCodes, ServerErrorCodes, isNarsilError } from './chunk-MDF6PDIA.mjs';
47
- export { ClientErrorCodes, ErrorCodes, NarsilError, ServerErrorCodes, isNarsilError } from './chunk-MDF6PDIA.mjs';
68
+ import { NarsilError, ErrorCodes, ServerErrorCodes, isNarsilError } from './chunk-KUZKUONM.mjs';
69
+ export { ClientErrorCodes, ErrorCodes, NarsilError, ServerErrorCodes, isNarsilError } from './chunk-KUZKUONM.mjs';
48
70
  import './chunk-R6A773WK.mjs';
49
- import './chunk-YTJCGKM4.mjs';
71
+ import { compareCodePoints } from './chunk-YTJCGKM4.mjs';
50
72
  import { randomUUID } from 'crypto';
73
+ import { encode, decode } from '@msgpack/msgpack';
51
74
  import { createReadStream } from 'fs';
52
75
  import { MessageChannel } from 'worker_threads';
53
76
 
77
+ // src/sync/feed/limits.ts
78
+ function createSemaphore(limit) {
79
+ let active = 0;
80
+ const waiting = [];
81
+ const release = () => {
82
+ active -= 1;
83
+ waiting.shift()?.();
84
+ };
85
+ return {
86
+ async run(task) {
87
+ if (active >= limit) await new Promise((resolve) => waiting.push(resolve));
88
+ active += 1;
89
+ try {
90
+ return await task();
91
+ } finally {
92
+ release();
93
+ }
94
+ }
95
+ };
96
+ }
97
+ function createByteBudget(limit) {
98
+ let used = 0;
99
+ const listeners = /* @__PURE__ */ new Set();
100
+ return {
101
+ take(bytes) {
102
+ if (used > 0 && used + bytes > limit) return false;
103
+ used += bytes;
104
+ return true;
105
+ },
106
+ give(bytes) {
107
+ used = Math.max(0, used - bytes);
108
+ for (const listener of [...listeners]) listener();
109
+ },
110
+ onFreed(listener) {
111
+ listeners.add(listener);
112
+ return () => {
113
+ listeners.delete(listener);
114
+ };
115
+ }
116
+ };
117
+ }
118
+ var FIXARRAY_LIMIT = 16;
119
+ var ARRAY16_LIMIT = 65536;
120
+ var FIXARRAY_TAG = 144;
121
+ var ARRAY16_TAG = 220;
122
+ var ARRAY32_TAG = 221;
123
+ var FIXMAP_OF_THREE = 131;
124
+ var entriesKeyPrefix = (() => {
125
+ const parts = [Uint8Array.of(FIXMAP_OF_THREE), encode("type"), encode("entries"), encode("partitionId")];
126
+ return concat(parts);
127
+ })();
128
+ var entriesKey = encode("entries");
129
+ function concat(parts) {
130
+ let length = 0;
131
+ for (const part of parts) length += part.byteLength;
132
+ const out = new Uint8Array(length);
133
+ let at = 0;
134
+ for (const part of parts) {
135
+ out.set(part, at);
136
+ at += part.byteLength;
137
+ }
138
+ return out;
139
+ }
140
+ function arrayHeader(count) {
141
+ if (count < FIXARRAY_LIMIT) return Uint8Array.of(FIXARRAY_TAG | count);
142
+ if (count < ARRAY16_LIMIT) return Uint8Array.of(ARRAY16_TAG, count >>> 8, count & 255);
143
+ return Uint8Array.of(ARRAY32_TAG, count >>> 24, count >>> 16 & 255, count >>> 8 & 255, count & 255);
144
+ }
145
+ function encodeEntriesMessage(partitionId, payloads) {
146
+ return concat([entriesKeyPrefix, encode(partitionId), entriesKey, arrayHeader(payloads.length), ...payloads]);
147
+ }
148
+ function encodeServerMessage(message) {
149
+ return encode(message, { ignoreUndefined: true });
150
+ }
151
+
152
+ // src/sync/feed/session.ts
153
+ var FeedSession = class {
154
+ constructor(deps) {
155
+ this.deps = deps;
156
+ this.stopBudgetWatch = deps.buffered.onFreed(() => {
157
+ if (this.state === "subscribed" && this.charged === 0) this.advance();
158
+ });
159
+ this.armExpiry();
160
+ }
161
+ state = "awaiting";
162
+ epoch = "";
163
+ sent = [];
164
+ heads = [];
165
+ unacked = [];
166
+ unackedBytes = 0;
167
+ charged = 0;
168
+ pumping = false;
169
+ pumpAgain = false;
170
+ retry = null;
171
+ expiry = null;
172
+ incoming = Promise.resolve();
173
+ stopBudgetWatch;
174
+ armExpiry() {
175
+ const { expiresAt } = this.deps;
176
+ if (expiresAt === null || this.state === "closed") return;
177
+ const remaining = expiresAt - Date.now();
178
+ if (remaining <= 0) {
179
+ queueMicrotask(() => this.close(SYNC_CLOSE_CREDENTIAL_EXPIRED, "credential expired"));
180
+ return;
181
+ }
182
+ this.expiry = setTimeout(
183
+ () => {
184
+ this.expiry = null;
185
+ this.armExpiry();
186
+ },
187
+ Math.min(remaining, TIMER_DELAY_LIMIT_MS)
188
+ );
189
+ }
190
+ get indexName() {
191
+ return this.deps.indexName;
192
+ }
193
+ receive(bytes, binary = true) {
194
+ if (this.state === "closed") return;
195
+ if (!binary) {
196
+ this.close(SYNC_CLOSE_POLICY, "feed messages travel in binary frames");
197
+ return;
198
+ }
199
+ if (bytes.byteLength > MAX_DEVICE_MESSAGE_BYTES) {
200
+ this.close(SYNC_CLOSE_TOO_LARGE, "message too large");
201
+ return;
202
+ }
203
+ let message;
204
+ try {
205
+ message = deviceMessageOf(decode(bytes));
206
+ } catch {
207
+ message = null;
208
+ }
209
+ if (message === null) {
210
+ this.close(SYNC_CLOSE_POLICY, "invalid message");
211
+ return;
212
+ }
213
+ const received = message;
214
+ this.incoming = this.incoming.then(() => this.handle(received)).catch((error) => this.fail(error));
215
+ }
216
+ advance() {
217
+ if (this.state !== "subscribed") return;
218
+ void this.pump();
219
+ }
220
+ sendSettings() {
221
+ if (this.state !== "subscribed") return;
222
+ const state = this.deps.source.indexState(this.deps.indexName);
223
+ if (state === null) return;
224
+ this.send(encodeServerMessage({ type: "settings", settings: state.settings }));
225
+ }
226
+ drained() {
227
+ this.settleBuffered();
228
+ this.advance();
229
+ }
230
+ resync(reason) {
231
+ if (this.state === "closed") return;
232
+ this.send(encodeServerMessage({ type: "resync", reason }));
233
+ this.close(SYNC_CLOSE_RESYNC, `resync ${reason}`);
234
+ }
235
+ close(code, reason) {
236
+ if (this.state === "closed") return;
237
+ this.state = "closed";
238
+ this.cleanUp();
239
+ this.deps.socket.close(code, reason);
240
+ this.deps.onClosed(this);
241
+ }
242
+ closedByPeer() {
243
+ if (this.state === "closed") return;
244
+ this.state = "closed";
245
+ this.cleanUp();
246
+ this.deps.onClosed(this);
247
+ }
248
+ cleanUp() {
249
+ if (this.retry !== null) clearTimeout(this.retry);
250
+ this.retry = null;
251
+ if (this.expiry !== null) clearTimeout(this.expiry);
252
+ this.expiry = null;
253
+ this.stopBudgetWatch();
254
+ this.deps.buffered.give(this.charged);
255
+ this.charged = 0;
256
+ }
257
+ fail(error) {
258
+ this.deps.onError(error);
259
+ this.close(SYNC_CLOSE_SERVER_ERROR, "feed read failed");
260
+ }
261
+ send(bytes) {
262
+ if (this.state === "closed") return;
263
+ this.deps.socket.send(bytes);
264
+ this.settleBuffered();
265
+ }
266
+ settleBuffered() {
267
+ const now = this.state === "closed" ? 0 : this.deps.socket.bufferedAmount();
268
+ if (now < this.charged) this.deps.buffered.give(this.charged - now);
269
+ this.charged = Math.min(this.charged, now);
270
+ }
271
+ async handle(message) {
272
+ if (this.state === "closed") return;
273
+ if (message.type === "subscribe") {
274
+ if (this.state !== "awaiting") return this.close(SYNC_CLOSE_POLICY, "subscribe after the first message");
275
+ return this.subscribe(message.epoch, message.positions);
276
+ }
277
+ if (this.state !== "subscribed") return this.close(SYNC_CLOSE_POLICY, "subscribe must come first");
278
+ if (message.type === "ack") return this.acknowledge(message.positions);
279
+ this.answerCheckpoint(message.id).catch((error) => this.fail(error));
280
+ }
281
+ async currentBounds() {
282
+ const all = [];
283
+ for (let partitionId = 0; partitionId < this.sent.length; partitionId++) {
284
+ all.push(await this.deps.source.bounds(this.deps.indexName, partitionId, "current"));
285
+ }
286
+ return all;
287
+ }
288
+ async answerCheckpoint(id) {
289
+ const covering = (await this.currentBounds()).map((bounds) => bounds.highestSeqNo);
290
+ while (this.state === "subscribed") {
291
+ const all = await this.currentBounds();
292
+ let covered = true;
293
+ for (let partitionId = 0; partitionId < all.length; partitionId++) {
294
+ covering[partitionId] = Math.min(covering[partitionId], all[partitionId].highestSeqNo);
295
+ const reachable = Math.max(all[partitionId].head, this.sent[partitionId]);
296
+ if (reachable < covering[partitionId]) covered = false;
297
+ }
298
+ if (covered) {
299
+ const heads = all.map((bounds) => bounds.head);
300
+ this.send(encodeServerMessage({ type: "checkpoint", id, heads: positionList(heads) }));
301
+ this.advance();
302
+ return;
303
+ }
304
+ await new Promise((resolve) => setTimeout(resolve, FEED_HEAD_RETRY_MS));
305
+ }
306
+ }
307
+ async subscribe(epoch, positions) {
308
+ const { source, indexName } = this.deps;
309
+ const state = source.indexState(indexName);
310
+ if (state === null) return this.close(SYNC_CLOSE_RESYNC, "sync is off");
311
+ if (epoch !== state.epoch) return this.resync("epoch");
312
+ const seqNos = positionsByPartition(positions, state.partitionCount);
313
+ if (seqNos === null) return this.close(SYNC_CLOSE_POLICY, "positions must name each partition once");
314
+ const heads = [];
315
+ for (let partitionId = 0; partitionId < state.partitionCount; partitionId++) {
316
+ const bounds = await this.deps.reads.run(() => source.bounds(indexName, partitionId, "current"));
317
+ if (seqNos[partitionId] < bounds.oldestSeqNo - 1) return this.resync("history");
318
+ if (seqNos[partitionId] > bounds.highestSeqNo) return this.resync("ahead");
319
+ heads.push(bounds.head);
320
+ }
321
+ const bytesBehind = await this.deps.reads.run(() => source.bytesBehind(indexName, seqNos));
322
+ const snapshotBytes = await this.deps.reads.run(() => source.snapshotBytes(indexName));
323
+ if (this.state === "closed") return;
324
+ if (source.indexState(indexName)?.epoch !== epoch) return this.resync("epoch");
325
+ this.epoch = epoch;
326
+ this.sent = seqNos;
327
+ this.heads = heads;
328
+ for (let i = 0; i < state.partitionCount; i++) this.unacked.push({ items: [], head: 0 });
329
+ this.state = "subscribed";
330
+ this.send(
331
+ encodeServerMessage({
332
+ type: "subscribed",
333
+ epoch,
334
+ partitionCount: state.partitionCount,
335
+ heads: positionList(heads),
336
+ bytesBehind,
337
+ snapshotBytes,
338
+ windowBytes: this.deps.windowBytes,
339
+ settings: state.settings
340
+ })
341
+ );
342
+ void this.pump();
343
+ }
344
+ acknowledge(positions) {
345
+ const seqNos = positionsByPartition(positions, this.sent.length);
346
+ if (seqNos === null) {
347
+ this.close(SYNC_CLOSE_POLICY, "positions must name each partition once");
348
+ return;
349
+ }
350
+ for (let partitionId = 0; partitionId < seqNos.length; partitionId++) {
351
+ if (seqNos[partitionId] > this.sent[partitionId]) {
352
+ this.close(SYNC_CLOSE_POLICY, "acknowledgement above a sent entry");
353
+ return;
354
+ }
355
+ }
356
+ for (let partitionId = 0; partitionId < seqNos.length; partitionId++) {
357
+ const queue = this.unacked[partitionId];
358
+ while (queue.head < queue.items.length && queue.items[queue.head].seqNo <= seqNos[partitionId]) {
359
+ this.unackedBytes -= queue.items[queue.head].bytes;
360
+ queue.head += 1;
361
+ }
362
+ if (queue.head > 0 && queue.head * 2 >= queue.items.length) {
363
+ queue.items = queue.items.slice(queue.head);
364
+ queue.head = 0;
365
+ }
366
+ }
367
+ void this.pump();
368
+ }
369
+ windowAllows(nextBytes) {
370
+ return this.unackedBytes === 0 || this.unackedBytes + nextBytes <= this.deps.windowBytes;
371
+ }
372
+ async pump() {
373
+ if (this.pumping) {
374
+ this.pumpAgain = true;
375
+ return;
376
+ }
377
+ this.pumping = true;
378
+ try {
379
+ do {
380
+ this.pumpAgain = false;
381
+ await this.refreshHeads();
382
+ await this.sendBehind();
383
+ } while (this.pumpAgain && this.state === "subscribed");
384
+ this.scheduleRetryWhileUndurable();
385
+ } catch (error) {
386
+ this.fail(error);
387
+ } finally {
388
+ this.pumping = false;
389
+ }
390
+ }
391
+ async refreshHeads() {
392
+ const { source, indexName } = this.deps;
393
+ if (source.indexState(indexName)?.epoch !== this.epoch) return this.resync("epoch");
394
+ for (let partitionId = 0; partitionId < this.heads.length; partitionId++) {
395
+ this.heads[partitionId] = Math.max(this.heads[partitionId], (await source.bounds(indexName, partitionId)).head);
396
+ }
397
+ }
398
+ async sendBehind() {
399
+ const { source, indexName } = this.deps;
400
+ let progressed = true;
401
+ while (progressed && this.state === "subscribed") {
402
+ progressed = false;
403
+ for (let partitionId = 0; partitionId < this.heads.length; partitionId++) {
404
+ if (this.state !== "subscribed" || this.sent[partitionId] >= this.heads[partitionId]) continue;
405
+ if (!this.windowAllows(1) || this.charged > 0) return;
406
+ const room = this.unackedBytes === 0 ? this.deps.windowBytes : this.deps.windowBytes - this.unackedBytes;
407
+ const maxBytes = Math.max(1, Math.min(room, ENTRIES_MESSAGE_LIMIT_BYTES));
408
+ const after = this.sent[partitionId];
409
+ const read = await this.deps.reads.run(
410
+ () => source.read(indexName, partitionId, after, this.heads[partitionId], maxBytes)
411
+ );
412
+ if (this.state !== "subscribed") return;
413
+ if (read.gone) return this.resync("history");
414
+ const frames = read.frames.filter((frame) => frame.seqNo > this.sent[partitionId]);
415
+ if (frames.length === 0) continue;
416
+ let bytes = 0;
417
+ for (const frame of frames) bytes += frame.payload.byteLength;
418
+ if (!this.windowAllows(bytes)) return;
419
+ const message = encodeEntriesMessage(
420
+ partitionId,
421
+ frames.map((frame) => frame.payload)
422
+ );
423
+ if (!this.deps.buffered.take(message.byteLength)) return;
424
+ this.charged += message.byteLength;
425
+ const queue = this.unacked[partitionId].items;
426
+ for (const frame of frames) queue.push({ seqNo: frame.seqNo, bytes: frame.payload.byteLength });
427
+ this.unackedBytes += bytes;
428
+ this.sent[partitionId] = frames[frames.length - 1].seqNo;
429
+ this.send(message);
430
+ progressed = true;
431
+ }
432
+ }
433
+ }
434
+ scheduleRetryWhileUndurable() {
435
+ if (this.state !== "subscribed" || this.retry !== null) return;
436
+ const { source, indexName } = this.deps;
437
+ const waiting = this.heads.some((head, partitionId) => source.pendingBeyondHead(indexName, partitionId, head));
438
+ if (!waiting) return;
439
+ this.retry = setTimeout(() => {
440
+ this.retry = null;
441
+ this.advance();
442
+ }, FEED_HEAD_RETRY_MS);
443
+ }
444
+ };
445
+
446
+ // src/sync/feed/hub.ts
447
+ function createFeedHub(source, options = {}) {
448
+ const windowBytes = options.windowBytes ?? DEFAULT_FEED_WINDOW_BYTES;
449
+ const maxConnections = options.maxConnections ?? DEFAULT_MAX_FEED_CONNECTIONS;
450
+ const reads = createSemaphore(options.maxCatchUps ?? DEFAULT_MAX_FEED_CATCH_UPS);
451
+ const buffered = createByteBudget(options.maxBufferedBytes ?? DEFAULT_MAX_FEED_BUFFERED_BYTES);
452
+ const sessionsByIndex = /* @__PURE__ */ new Map();
453
+ const unwatchByIndex = /* @__PURE__ */ new Map();
454
+ let connections = 0;
455
+ let stopListening = null;
456
+ let closed = false;
457
+ function each(indexName, action) {
458
+ const sessions = sessionsByIndex.get(indexName);
459
+ if (sessions === void 0) return;
460
+ for (const session of [...sessions]) action(session);
461
+ }
462
+ function onChange(change) {
463
+ switch (change.kind) {
464
+ case "advanced":
465
+ each(change.indexName, (session) => session.advance());
466
+ return;
467
+ case "settings":
468
+ each(change.indexName, (session) => session.sendSettings());
469
+ return;
470
+ case "epoch":
471
+ each(change.indexName, (session) => session.resync("epoch"));
472
+ return;
473
+ case "off":
474
+ case "dropped":
475
+ each(change.indexName, (session) => session.close(SYNC_CLOSE_RESYNC, "sync is off"));
476
+ return;
477
+ }
478
+ }
479
+ function forget(session) {
480
+ const sessions = sessionsByIndex.get(session.indexName);
481
+ if (sessions === void 0 || !sessions.delete(session)) return;
482
+ if (sessions.size === 0) {
483
+ sessionsByIndex.delete(session.indexName);
484
+ unwatchByIndex.get(session.indexName)?.();
485
+ unwatchByIndex.delete(session.indexName);
486
+ }
487
+ release();
488
+ }
489
+ function release() {
490
+ connections -= 1;
491
+ if (connections === 0 && stopListening !== null) {
492
+ stopListening();
493
+ stopListening = null;
494
+ }
495
+ }
496
+ function open(indexName, expiresAt, socket) {
497
+ if (stopListening === null) stopListening = source.listen(onChange);
498
+ const session = new FeedSession({
499
+ source,
500
+ indexName,
501
+ socket,
502
+ windowBytes,
503
+ expiresAt,
504
+ reads,
505
+ buffered,
506
+ onClosed: forget,
507
+ onError: (error) => options.onError?.(error)
508
+ });
509
+ let sessions = sessionsByIndex.get(indexName);
510
+ if (sessions === void 0) {
511
+ sessions = /* @__PURE__ */ new Set();
512
+ sessionsByIndex.set(indexName, sessions);
513
+ const unwatch = source.watchIndex?.(indexName);
514
+ if (unwatch !== void 0) unwatchByIndex.set(indexName, unwatch);
515
+ }
516
+ sessions.add(session);
517
+ return session;
518
+ }
519
+ return {
520
+ admit(indexName, expiresAt) {
521
+ if (closed) {
522
+ throw new NarsilError(ServerErrorCodes.TOO_MANY_REQUESTS, "The server is closing its feed connections");
523
+ }
524
+ if (source.indexState(indexName) === null) {
525
+ throw new NarsilError(ErrorCodes.SYNC_NOT_ENABLED, `Index "${indexName}" has device sync off`, { indexName });
526
+ }
527
+ if (connections >= maxConnections) {
528
+ throw new NarsilError(
529
+ ServerErrorCodes.TOO_MANY_REQUESTS,
530
+ `The server holds ${connections} feed connections, the most that it accepts`,
531
+ { maximum: maxConnections }
532
+ );
533
+ }
534
+ connections += 1;
535
+ let settled = false;
536
+ return {
537
+ open(socket) {
538
+ if (settled) throw new Error("A feed admission opens one connection");
539
+ settled = true;
540
+ return open(indexName, expiresAt, socket);
541
+ },
542
+ cancel() {
543
+ if (settled) return;
544
+ settled = true;
545
+ release();
546
+ }
547
+ };
548
+ },
549
+ connectionCount: () => connections,
550
+ close() {
551
+ closed = true;
552
+ for (const indexName of [...sessionsByIndex.keys()]) {
553
+ each(indexName, (session) => session.close(SYNC_CLOSE_GOING_AWAY, "server closing"));
554
+ }
555
+ stopListening?.();
556
+ stopListening = null;
557
+ }
558
+ };
559
+ }
54
560
  function createAdminHandlers(deps) {
55
561
  const { engine, tasks, limits } = deps;
56
562
  async function checkpoint(ctx) {
@@ -1264,34 +1770,28 @@ function assertAllowRegex(allowRegex) {
1264
1770
  { field: "allowRegex", value: String(allowRegex) }
1265
1771
  );
1266
1772
  }
1267
- var RELAYED_TYPES = /* @__PURE__ */ new Set([
1268
- "request",
1269
- "authorize",
1270
- "embed",
1271
- "rerank",
1272
- "await-writes",
1273
- "stream-credit",
1274
- "stream-cancel"
1275
- ]);
1276
- function isRelayRequest(message) {
1277
- if (typeof message !== "object" || message === null) return false;
1278
- const { type, requestId } = message;
1279
- if (type === "touch" || type === "leaving") return true;
1280
- return typeof requestId === "number" && typeof type === "string" && RELAYED_TYPES.has(type);
1281
- }
1773
+
1774
+ // src/server/request-threads/relay-answers.ts
1282
1775
  async function answerAuthorize(authorize, request) {
1283
1776
  if (authorize === void 0) {
1284
- return { type: "authorized", requestId: request.requestId, denial: null, hookError: false };
1777
+ return { type: "authorized", requestId: request.requestId, denial: null, hookError: false, expiresAt: null };
1285
1778
  }
1286
1779
  const authorization = await authorize(request.context);
1287
1780
  if (authorization.allowed) {
1288
- return { type: "authorized", requestId: request.requestId, denial: null, hookError: false };
1781
+ return {
1782
+ type: "authorized",
1783
+ requestId: request.requestId,
1784
+ denial: null,
1785
+ hookError: false,
1786
+ expiresAt: authorization.expiresAt
1787
+ };
1289
1788
  }
1290
1789
  return {
1291
1790
  type: "authorized",
1292
1791
  requestId: request.requestId,
1293
1792
  denial: authorization.denial,
1294
- hookError: authorization.denial === null
1793
+ hookError: authorization.denial === null,
1794
+ expiresAt: null
1295
1795
  };
1296
1796
  }
1297
1797
  async function answerEmbed(core, request) {
@@ -1328,6 +1828,33 @@ async function answerAwaitWrites(core, request) {
1328
1828
  await core.orchestrator.awaitWrites(request.indexName).catch(() => void 0);
1329
1829
  return { type: "writes-applied", requestId: request.requestId };
1330
1830
  }
1831
+ async function answerFeedAdmit(feeds, request) {
1832
+ if (feeds !== null) return feeds.admit(request);
1833
+ return {
1834
+ type: "feed-admitted",
1835
+ requestId: request.requestId,
1836
+ feedId: null,
1837
+ error: { code: ServerErrorCodes.NOT_FOUND, message: "Route not found" }
1838
+ };
1839
+ }
1840
+
1841
+ // src/server/request-threads/host.ts
1842
+ var RELAYED_TYPES = /* @__PURE__ */ new Set([
1843
+ "request",
1844
+ "authorize",
1845
+ "embed",
1846
+ "rerank",
1847
+ "await-writes",
1848
+ "stream-credit",
1849
+ "stream-cancel",
1850
+ "feed-admit"
1851
+ ]);
1852
+ function isRelayRequest(message) {
1853
+ if (typeof message !== "object" || message === null) return false;
1854
+ const { type, requestId } = message;
1855
+ if (type === "touch" || type === "leaving") return true;
1856
+ return typeof requestId === "number" && typeof type === "string" && RELAYED_TYPES.has(type);
1857
+ }
1331
1858
  function touchIntervalFor(copyIdleTimeoutMs) {
1332
1859
  return Math.min(MAX_INDEX_TOUCH_INTERVAL_MS, Math.floor(copyIdleTimeoutMs / INDEX_TOUCH_INTERVALS_PER_IDLE_TIMEOUT));
1333
1860
  }
@@ -1347,6 +1874,7 @@ async function startRequestThreads(options) {
1347
1874
  closeEveryThreadAtExit(closeAtExit, REQUEST_THREAD_CLOSE_AT_EXIT_MS);
1348
1875
  }
1349
1876
  function releaseDescriptor(thread) {
1877
+ thread.feeds?.closeAll();
1350
1878
  closeAtExit.delete(thread.closeAtExit);
1351
1879
  if (thread.descriptor !== null) {
1352
1880
  try {
@@ -1359,7 +1887,12 @@ async function startRequestThreads(options) {
1359
1887
  function relayFrom(thread) {
1360
1888
  const { port } = thread;
1361
1889
  const streams = /* @__PURE__ */ new Map();
1890
+ port.on("close", () => thread.feeds?.closeAll());
1362
1891
  port.on("message", (message) => {
1892
+ if (isThreadFeedNote(message)) {
1893
+ thread.feeds?.handle(message);
1894
+ return;
1895
+ }
1363
1896
  if (!isRelayRequest(message)) return;
1364
1897
  if (message.type === "leaving") {
1365
1898
  releaseDescriptor(thread);
@@ -1377,7 +1910,7 @@ async function startRequestThreads(options) {
1377
1910
  streams.get(message.requestId)?.cancel();
1378
1911
  return;
1379
1912
  }
1380
- const reply = message.type === "request" ? answerRequest(handlers[message.route], message, port, streams) : message.type === "authorize" ? answerAuthorize(authorize, message) : message.type === "embed" ? answerEmbed(core, message) : message.type === "await-writes" ? answerAwaitWrites(core, message) : answerRerank(core, message);
1913
+ const reply = message.type === "request" ? answerRequest(handlers[message.route], message, port, streams) : message.type === "authorize" ? answerAuthorize(authorize, message) : message.type === "feed-admit" ? answerFeedAdmit(thread.feeds, message) : message.type === "embed" ? answerEmbed(core, message) : message.type === "await-writes" ? answerAwaitWrites(core, message) : answerRerank(core, message);
1381
1914
  void reply.then((answer) => {
1382
1915
  if (answer !== null) port.postMessage(answer);
1383
1916
  });
@@ -1407,6 +1940,7 @@ async function startRequestThreads(options) {
1407
1940
  dropLongQueryThread();
1408
1941
  const channel = new MessageChannel();
1409
1942
  const relaying = {
1943
+ feeds: null,
1410
1944
  descriptor: null,
1411
1945
  port: channel.port2,
1412
1946
  executor,
@@ -1446,6 +1980,7 @@ async function startRequestThreads(options) {
1446
1980
  if (stopped) return;
1447
1981
  const channel = new MessageChannel();
1448
1982
  const thread = {
1983
+ feeds: options.feeds?.forThread(channel.port2) ?? null,
1449
1984
  descriptor: null,
1450
1985
  port: channel.port2,
1451
1986
  executor,
@@ -1480,6 +2015,7 @@ async function startRequestThreads(options) {
1480
2015
  patternWorkCap: options.core.patternWorkCap,
1481
2016
  maxRerankWindow: options.core.rerankSettings.maxWindow,
1482
2017
  allowRegex: options.allowRegex,
2018
+ sync: options.feeds !== null,
1483
2019
  longQueriesInFlight,
1484
2020
  longQueryPort: longQueryChannel?.port1 ?? null
1485
2021
  }
@@ -1553,6 +2089,260 @@ async function startRequestThreads(options) {
1553
2089
  };
1554
2090
  }
1555
2091
 
2092
+ // src/sync/feed/engine-source.ts
2093
+ function syncSettingsOf(entry) {
2094
+ const { config } = entry;
2095
+ const synonyms = entry.synonyms === null ? [] : rulesOfStoredSynonyms(entry.synonyms);
2096
+ return {
2097
+ language: entry.language.name,
2098
+ ...typeof config.tokenizer === "string" ? { tokenizer: config.tokenizer } : {},
2099
+ ...typeof config.stopWords === "string" ? { stopWords: config.stopWords } : {},
2100
+ ...config.stopWords instanceof Set ? { stopWordList: [...config.stopWords].sort(compareCodePoints) } : {},
2101
+ ...entry.analysisRevision !== null ? { analysisRevision: entry.analysisRevision } : {},
2102
+ ...config.bm25 !== void 0 ? { bm25: config.bm25 } : {},
2103
+ ...synonyms.length > 0 ? { synonyms } : {}
2104
+ };
2105
+ }
2106
+ function storageOf(core) {
2107
+ return core.durability?.manager.syncStorage?.() ?? null;
2108
+ }
2109
+ function engineFeedSource(engine, core) {
2110
+ const requireStorage = () => {
2111
+ const storage = storageOf(core);
2112
+ if (storage === null) {
2113
+ throw new NarsilError(ErrorCodes.SYNC_DURABILITY_REQUIRED, "Device sync needs write-ahead log durability");
2114
+ }
2115
+ return storage;
2116
+ };
2117
+ return {
2118
+ indexState(indexName) {
2119
+ const entry = core.indexRegistry.get(indexName);
2120
+ if (entry === void 0 || entry.sync === null || storageOf(core) === null) return null;
2121
+ return { epoch: entry.sync.epoch, partitionCount: entry.partitionCount, settings: syncSettingsOf(entry) };
2122
+ },
2123
+ async bounds(indexName, partitionId) {
2124
+ const log = await requireStorage().openPartitionLog(indexName, partitionId);
2125
+ const applied = core.durability?.manager.highestPersistedSeqNo(indexName, partitionId) ?? 0;
2126
+ return { oldestSeqNo: log.oldestSeqNo, head: log.head, highestSeqNo: Math.max(log.head, applied) };
2127
+ },
2128
+ async read(indexName, partitionId, afterSeqNo, upToSeqNo, maxBytes) {
2129
+ const read = await requireStorage().readPartitionLog(indexName, partitionId, afterSeqNo, upToSeqNo, maxBytes);
2130
+ return { frames: read.frames, gone: read.gone };
2131
+ },
2132
+ async bytesBehind(indexName, seqNos) {
2133
+ const storage = requireStorage();
2134
+ let bytes = 0;
2135
+ for (let partitionId = 0; partitionId < seqNos.length; partitionId++) {
2136
+ const log = await storage.openPartitionLog(indexName, partitionId);
2137
+ bytes += await storage.logBytesAfter(log, seqNos[partitionId]);
2138
+ }
2139
+ return bytes;
2140
+ },
2141
+ async snapshotBytes(indexName) {
2142
+ const storage = requireStorage();
2143
+ const published = await storage.published(indexName);
2144
+ if (published !== null) return publishedArchiveLayout(indexName, published, storage).byteLength;
2145
+ const manifest = await storage.currentManifest(indexName);
2146
+ if (manifest === null) return 0;
2147
+ return estimatedArchiveBytes(manifestFileRefs(manifest));
2148
+ },
2149
+ pendingBeyondHead(indexName, partitionId, head) {
2150
+ return (core.durability?.manager.highestPersistedSeqNo(indexName, partitionId) ?? 0) > head;
2151
+ },
2152
+ listen(onChange) {
2153
+ const onWrite = (payload) => onChange({ kind: "advanced", indexName: payload.indexName });
2154
+ engine.on("write", onWrite);
2155
+ const stopSyncChanges = listenForSyncChanges(core.indexRegistry, onChange);
2156
+ return () => {
2157
+ engine.off("write", onWrite);
2158
+ stopSyncChanges();
2159
+ };
2160
+ }
2161
+ };
2162
+ }
2163
+
2164
+ // src/server/sync/engine-serving.ts
2165
+ function engineSyncServing(engine, core) {
2166
+ startSyncRetentionSweep(core);
2167
+ return {
2168
+ async snapshot(indexName) {
2169
+ const published = await publishedSyncSnapshot(core, indexName);
2170
+ try {
2171
+ return {
2172
+ entityTag: published.snapshot.entityTag,
2173
+ layout: publishedArchiveLayout(indexName, published.snapshot, published.storage),
2174
+ release: published.unpin
2175
+ };
2176
+ } catch (error) {
2177
+ published.unpin();
2178
+ throw error;
2179
+ }
2180
+ },
2181
+ feed: engineFeedSource(engine, core),
2182
+ admitFeed: async () => void 0
2183
+ };
2184
+ }
2185
+
2186
+ // src/server/sync/feed-host.ts
2187
+ var RelayedFeedSocket = class {
2188
+ constructor(port, feedId) {
2189
+ this.port = port;
2190
+ this.feedId = feedId;
2191
+ }
2192
+ inTransit = 0;
2193
+ threadBuffered = 0;
2194
+ closed = false;
2195
+ send(bytes) {
2196
+ if (this.closed) return;
2197
+ const copy = bytes.slice();
2198
+ this.inTransit += copy.byteLength;
2199
+ this.post({ type: "feed-send", feedId: this.feedId, bytes: copy }, [copy.buffer]);
2200
+ }
2201
+ bufferedAmount() {
2202
+ return this.inTransit + this.threadBuffered;
2203
+ }
2204
+ close(code, reason) {
2205
+ if (this.closed) return;
2206
+ this.closed = true;
2207
+ this.post({ type: "feed-close", feedId: this.feedId, code, reason }, []);
2208
+ }
2209
+ sent(bytes, buffered) {
2210
+ this.inTransit = Math.max(0, this.inTransit - bytes);
2211
+ this.threadBuffered = buffered;
2212
+ }
2213
+ markClosed() {
2214
+ this.closed = true;
2215
+ }
2216
+ post(note, transfer) {
2217
+ try {
2218
+ this.port.postMessage(note, transfer);
2219
+ } catch {
2220
+ this.closed = true;
2221
+ }
2222
+ }
2223
+ };
2224
+ function createFeedHost(hub, serving, authorize) {
2225
+ async function admit(indexName, expiresAt) {
2226
+ await serving.admitFeed(indexName);
2227
+ return hub.admit(indexName, expiresAt);
2228
+ }
2229
+ const gateway = {
2230
+ authorize: (context) => authorize === void 0 ? Promise.resolve({ allowed: true, expiresAt: null }) : authorize(context),
2231
+ async admit(indexName, expiresAt) {
2232
+ const admission = await admit(indexName, expiresAt);
2233
+ return { open: (socket) => admission.open(socket), cancel: () => admission.cancel() };
2234
+ }
2235
+ };
2236
+ function forThread(port) {
2237
+ const feeds = /* @__PURE__ */ new Map();
2238
+ let nextFeedId = 0;
2239
+ let closed = false;
2240
+ function closeFeed(feedId) {
2241
+ const feed = feeds.get(feedId);
2242
+ if (feed === void 0) return;
2243
+ feeds.delete(feedId);
2244
+ feed.socket.markClosed();
2245
+ if (feed.session === null) feed.admission.cancel();
2246
+ else feed.session.closedByPeer();
2247
+ }
2248
+ return {
2249
+ async admit(request) {
2250
+ try {
2251
+ const admission = await admit(request.indexName, request.expiresAt);
2252
+ if (closed) {
2253
+ admission.cancel();
2254
+ return { type: "feed-admitted", requestId: request.requestId, feedId: null, error: null };
2255
+ }
2256
+ nextFeedId += 1;
2257
+ const feedId = nextFeedId;
2258
+ feeds.set(feedId, { admission, socket: new RelayedFeedSocket(port, feedId), session: null });
2259
+ return { type: "feed-admitted", requestId: request.requestId, feedId, error: null };
2260
+ } catch (err) {
2261
+ return { type: "feed-admitted", requestId: request.requestId, feedId: null, error: toHttpError(err).body };
2262
+ }
2263
+ },
2264
+ handle(note) {
2265
+ const feed = feeds.get(note.feedId);
2266
+ if (feed === void 0) return;
2267
+ switch (note.type) {
2268
+ case "feed-open":
2269
+ if (feed.session === null) feed.session = feed.admission.open(feed.socket);
2270
+ return;
2271
+ case "feed-message":
2272
+ feed.session?.receive(note.bytes, note.binary);
2273
+ return;
2274
+ case "feed-sent":
2275
+ feed.socket.sent(note.bytes, note.buffered);
2276
+ feed.session?.drained();
2277
+ return;
2278
+ case "feed-cancel":
2279
+ case "feed-closed":
2280
+ closeFeed(note.feedId);
2281
+ return;
2282
+ }
2283
+ },
2284
+ closeAll() {
2285
+ closed = true;
2286
+ for (const feedId of [...feeds.keys()]) closeFeed(feedId);
2287
+ }
2288
+ };
2289
+ }
2290
+ return { gateway, forThread, close: () => hub.close() };
2291
+ }
2292
+
2293
+ // src/server/sync/options.ts
2294
+ var SYNC_OPTION_FIELDS = ["windowBytes", "maxConnections", "maxCatchUps", "maxBufferedBytes"];
2295
+ function assertCount(field, value) {
2296
+ if (value === void 0) return;
2297
+ if (typeof value === "number" && Number.isSafeInteger(value) && value >= 1) return;
2298
+ throw new NarsilError(
2299
+ ErrorCodes.CONFIG_INVALID,
2300
+ `sync.${field} must be a whole number of at least 1; however, this configuration sets it to ${String(value)}`,
2301
+ { field, value: String(value) }
2302
+ );
2303
+ }
2304
+ function resolveSyncOptions(sync) {
2305
+ if (sync === void 0 || sync === false) return null;
2306
+ if (sync !== true && (typeof sync !== "object" || sync === null)) {
2307
+ throw new NarsilError(
2308
+ ErrorCodes.CONFIG_INVALID,
2309
+ `sync must be true, false, or an object of settings; however, this configuration sets it to ${String(sync)}`,
2310
+ { field: "sync", value: String(sync) }
2311
+ );
2312
+ }
2313
+ const settings = sync === true ? {} : sync;
2314
+ for (const field of SYNC_OPTION_FIELDS) assertCount(field, settings[field]);
2315
+ return {
2316
+ windowBytes: settings.windowBytes ?? DEFAULT_FEED_WINDOW_BYTES,
2317
+ maxConnections: settings.maxConnections ?? DEFAULT_MAX_FEED_CONNECTIONS,
2318
+ maxCatchUps: settings.maxCatchUps ?? DEFAULT_MAX_FEED_CATCH_UPS,
2319
+ maxBufferedBytes: settings.maxBufferedBytes ?? DEFAULT_MAX_FEED_BUFFERED_BYTES
2320
+ };
2321
+ }
2322
+ function assertSyncHasAuthentication(sync, options) {
2323
+ if (sync === null || options.onRequest !== void 0) return;
2324
+ throw new NarsilError(
2325
+ ErrorCodes.CONFIG_INVALID,
2326
+ "Refusing to start: the device sync routes are on with no onRequest hook. A device receives the whole index, so set options.onRequest to admit only the user whose documents the index holds. allowInsecure does not lift this refusal.",
2327
+ { field: "sync" }
2328
+ );
2329
+ }
2330
+
2331
+ // src/server/sync/setting-handlers.ts
2332
+ function createSyncSettingHandlers(engine) {
2333
+ async function updateSync(ctx) {
2334
+ const body = parseJson(ctx);
2335
+ if (body === void 0) return;
2336
+ try {
2337
+ await engine.updateSync(ctx.params[0], body);
2338
+ respondJson(ctx, { ok: true });
2339
+ } catch (err) {
2340
+ respondError(ctx, err);
2341
+ }
2342
+ }
2343
+ return { updateSync };
2344
+ }
2345
+
1556
2346
  // src/server/task-status.ts
1557
2347
  var TERMINAL_TASK_STATUSES = /* @__PURE__ */ new Set(["succeeded", "failed", "cancelled"]);
1558
2348
  function isTerminalTaskStatus(status) {
@@ -1817,7 +2607,7 @@ function assertSecureBinding(host, options) {
1817
2607
  { host }
1818
2608
  );
1819
2609
  }
1820
- function mainThreadHandlers(deps) {
2610
+ function mainThreadHandlers(deps, syncServing) {
1821
2611
  const idx = createIndexHandlers(deps);
1822
2612
  const doc = createDocumentHandlers(deps);
1823
2613
  const search = createSearchHandlers(deps);
@@ -1828,6 +2618,7 @@ function mainThreadHandlers(deps) {
1828
2618
  const backups = createBackupHandlers(deps);
1829
2619
  const version = createVersionHandler(deps);
1830
2620
  const capabilities = createCapabilitiesHandler();
2621
+ const syncSetting = createSyncSettingHandlers(deps.engine);
1831
2622
  return {
1832
2623
  livez: health.livez,
1833
2624
  readyz: health.readyz,
@@ -1883,7 +2674,9 @@ function mainThreadHandlers(deps) {
1883
2674
  updateBm25: admin.updateBm25,
1884
2675
  restore: admin.restore,
1885
2676
  exportDocuments: documentExport.exportDocuments,
1886
- importExport: documentExport.importExport
2677
+ importExport: documentExport.importExport,
2678
+ updateSync: syncSetting.updateSync,
2679
+ syncSnapshot: createSyncSnapshotHandler(syncServing)
1887
2680
  };
1888
2681
  }
1889
2682
  var NarsilHttpServer = class {
@@ -1896,12 +2689,16 @@ var NarsilHttpServer = class {
1896
2689
  listenSocket = null;
1897
2690
  ready = false;
1898
2691
  threads = null;
2692
+ sync;
2693
+ syncServing = null;
2694
+ feeds = null;
1899
2695
  stopIdleHeapCleanup = () => void 0;
1900
2696
  constructor(engine, options = {}) {
1901
2697
  assertServerEngine(engine);
1902
2698
  const engineRerankWindow = rerankWindowCapOf(engine);
1903
2699
  assertServerLimits(options.limits, engineRerankWindow);
1904
2700
  assertAllowRegex(options.allowRegex);
2701
+ this.sync = resolveSyncOptions(options.sync);
1905
2702
  this.host = options.host ?? "127.0.0.1";
1906
2703
  this.port = options.port ?? 9876;
1907
2704
  this.options = options;
@@ -1928,6 +2725,7 @@ var NarsilHttpServer = class {
1928
2725
  };
1929
2726
  }
1930
2727
  async listen() {
2728
+ assertSyncHasAuthentication(this.sync, this.options);
1931
2729
  assertSecureBinding(this.host, this.options);
1932
2730
  const uws = await loadUWebSockets();
1933
2731
  this.uws = uws;
@@ -1955,6 +2753,9 @@ var NarsilHttpServer = class {
1955
2753
  this.uws.us_listen_socket_close(this.listenSocket);
1956
2754
  this.listenSocket = null;
1957
2755
  }
2756
+ this.feeds?.close();
2757
+ this.feeds = null;
2758
+ this.syncServing = null;
1958
2759
  if (this.threads !== null) {
1959
2760
  const threads = this.threads;
1960
2761
  this.threads = null;
@@ -1972,6 +2773,21 @@ var NarsilHttpServer = class {
1972
2773
  get requestThreadCount() {
1973
2774
  return this.threads?.threadCount ?? 0;
1974
2775
  }
2776
+ startSync(app, authorize, core) {
2777
+ if (this.sync === null) return;
2778
+ const servingOfNode = syncServingSourceOf(this.engine);
2779
+ let serving;
2780
+ if (servingOfNode !== void 0) serving = servingOfNode();
2781
+ else if (core !== void 0) serving = engineSyncServing(this.engine, core);
2782
+ else return;
2783
+ const hub = createFeedHub(serving.feed, {
2784
+ ...this.sync,
2785
+ onError: (error) => console.warn("A device sync feed failed to read its index:", error)
2786
+ });
2787
+ this.syncServing = serving;
2788
+ this.feeds = createFeedHost(hub, serving, authorize);
2789
+ registerFeedRoute(app, this.feeds.gateway);
2790
+ }
1975
2791
  async registerRoutes(app) {
1976
2792
  const cors = resolveCors(this.options.cors);
1977
2793
  const authorize = this.options.onRequest ? authorizerFor(this.options.onRequest) : void 0;
@@ -1980,7 +2796,8 @@ var NarsilHttpServer = class {
1980
2796
  const gate = createSharedGateBuffer(gateSlotOfWorker(threadCount));
1981
2797
  const bodyBudget = createBodyBudgetBuffer(gateSlotOfWorker(threadCount));
1982
2798
  const { limits, build, allowRegex } = this.deps;
1983
- const handlers = mainThreadHandlers(this.deps);
2799
+ const handlers = mainThreadHandlers(this.deps, () => this.syncServing);
2800
+ this.startSync(app, authorize, core);
1984
2801
  const run = createRouteRunner({
1985
2802
  authorize,
1986
2803
  gate: createSharedRequestGate(gate, limits.maxConcurrentRequests, MAIN_THREAD_GATE_SLOT),
@@ -2000,7 +2817,8 @@ var NarsilHttpServer = class {
2000
2817
  limits,
2001
2818
  allowRegex,
2002
2819
  build,
2003
- cors
2820
+ cors,
2821
+ feeds: this.feeds
2004
2822
  });
2005
2823
  } catch (err) {
2006
2824
  console.warn("The server could not start request threads, so the main thread answers every request:", err);