nolo-cli 0.149.0-alpha.1 → 0.151.0-alpha.3

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 (258) hide show
  1. package/{_executeModel-OW3H7ICR.js → _executeModel-T7ANHTUW.js} +134 -91
  2. package/accountResolver-7RYB4D2P.js +300 -0
  3. package/action-SXJD5N5R.js +23 -0
  4. package/{addContentAction-B2DRF7P6.js → addContentAction-ZV774PHH.js} +20 -14
  5. package/{addDialogAgentAction-2P2FLTLD.js → addDialogAgentAction-A6SMKAGH.js} +26 -22
  6. package/{agentDeleteCommand-7IDWF6E3.js → agentDeleteCommand-4L5KCKFY.js} +181 -93
  7. package/{agentEmailCommands-A6XBQZBN.js → agentEmailCommands-2IMMIRO2.js} +132 -112
  8. package/{agentGrantCommands-M3XFO6EN.js → agentGrantCommands-HOJ3JBBQ.js} +3 -3
  9. package/agentListCommands-TWFLUYIZ.js +802 -0
  10. package/{agentMachineCommands-DQPUIMAC.js → agentMachineCommands-KIWXWT6L.js} +58 -62
  11. package/{agentProviderCommands-YK2BIIXZ.js → agentProviderCommands-HL6MBLCL.js} +149 -2
  12. package/{agentPullCommand-HF4A42D4.js → agentPullCommand-FA43RBRU.js} +7 -7
  13. package/agentRecordCommands-727NPCRW.js +154 -0
  14. package/agentRunCommand-JASIG3FZ.js +183 -0
  15. package/{agentRunControl-2SKCR4SB.js → agentRunControl-IFM7IGMG.js} +10 -2
  16. package/{agentRuntimeLocal-AK2QVJHY.js → agentRuntimeLocal-KKSQJMTE.js} +47 -50
  17. package/{agentSlice-O4RUQUMT.js → agentSlice-SLV57QGU.js} +23 -16
  18. package/{appDeleteCommands-N3XEVVYC.js → appDeleteCommands-4PL4KYRN.js} +58 -59
  19. package/{appDeployCommands-AWFIXYVW.js → appDeployCommands-EEEXCEB6.js} +67 -63
  20. package/{appDeployStatusCommands-CZRON2FO.js → appDeployStatusCommands-35ZX7T66.js} +56 -56
  21. package/{appGetCommands-XQIUY4TD.js → appGetCommands-WFCHXJWF.js} +56 -56
  22. package/{appListCommands-NNG4H36Y.js → appListCommands-XY2U6DPF.js} +57 -59
  23. package/{authCommand-UBJ4EWYZ.js → authCommand-QYN47CQD.js} +371 -68
  24. package/{authCommands-H6WKKCRW.js → authCommands-77CHYBGF.js} +12 -9
  25. package/{builtinSkillRegistry-ZMF6YGNO.js → builtinSkillRegistry-TDQ6JB2E.js} +13 -11
  26. package/{chromeCommands-2N6MEWRU.js → chromeCommands-OBBNJCLS.js} +314 -13
  27. package/chromeOpsCommands-3Z34RKSE.js +472 -0
  28. package/{chunk-ALXHV7NK.js → chunk-2GGXHQIW.js} +43 -4
  29. package/{localRuntimeAuthority-5W6IJRAD.js → chunk-2IXDJNZI.js} +154 -75
  30. package/{chunk-IVZJWTDI.js → chunk-36OMEXXR.js} +89 -21
  31. package/{chunk-H6A6X4EK.js → chunk-3MZAGMYY.js} +16 -0
  32. package/chunk-3PVYUPXK.js +40 -0
  33. package/chunk-3SZA4U64.js +1192 -0
  34. package/{chunk-ID7LNBWR.js → chunk-3T4ZG6AC.js} +1920 -644
  35. package/{chunk-GNMAFAIS.js → chunk-44WXLHFI.js} +1 -1
  36. package/{chunk-AGGIDPCZ.js → chunk-4JH2UMJR.js} +6 -0
  37. package/chunk-4LCOCOR5.js +50 -0
  38. package/chunk-4YRTZIVN.js +871 -0
  39. package/{chunk-N7J63Q6C.js → chunk-56GBUMO5.js} +10 -1
  40. package/{chunk-W7XHHYWM.js → chunk-5BHQICF2.js} +5 -1
  41. package/{chunk-XUWRURDF.js → chunk-5EBLANFT.js} +1 -1
  42. package/{chunk-3AH7LNUB.js → chunk-5EMSBTQ6.js} +33 -14
  43. package/{chunk-YRRASA5Q.js → chunk-5MM7NNO6.js} +113 -52
  44. package/chunk-5MMAK75Q.js +15 -0
  45. package/{chunk-TXH4IWJL.js → chunk-626KHJNX.js} +20 -11
  46. package/{chunk-M5PVFLD4.js → chunk-64K7WX26.js} +90 -21
  47. package/{chunk-AKG5W4LG.js → chunk-6CCFTVBP.js} +76 -221
  48. package/chunk-6MJNEXUU.js +614 -0
  49. package/{chunk-62IL3KQV.js → chunk-6MXDOUMH.js} +15 -3
  50. package/{chunk-QOKAKDPE.js → chunk-6Q7UTJKR.js} +6 -94
  51. package/chunk-6QDYSCPW.js +223 -0
  52. package/{chunk-HYZIYH2H.js → chunk-74RAWNQN.js} +56 -63
  53. package/chunk-7DPNBQSV.js +9 -0
  54. package/{chunk-IAESIMK7.js → chunk-A4MW3YZL.js} +10 -14
  55. package/{chunk-OMRJYNCI.js → chunk-AG7MCDLR.js} +26 -31
  56. package/chunk-AGIM7IMJ.js +147 -0
  57. package/{chunk-7CHC4W22.js → chunk-AIZE5TDM.js} +3 -3
  58. package/chunk-AJ3G7X2K.js +7012 -0
  59. package/{chunk-5GVBDNTO.js → chunk-AU7AXHUL.js} +1 -1
  60. package/{chunk-4H22P2JV.js → chunk-AUIJZACN.js} +2073 -1275
  61. package/{chunk-CIF4X6ZM.js → chunk-AWVFQMOV.js} +25 -3
  62. package/{chunk-YAQJJDC2.js → chunk-BJEZC5RA.js} +214 -51
  63. package/{chunk-RYZINGPM.js → chunk-BPMPOFWP.js} +347 -235
  64. package/{chunk-YUNJN43V.js → chunk-BU2YQBV4.js} +215 -28
  65. package/{chunk-XPRWFQQK.js → chunk-CBHGZRCE.js} +38 -12
  66. package/{chunk-Y3PMXGLH.js → chunk-CHCS6XPJ.js} +365 -144
  67. package/chunk-CHOZJMJS.js +78 -0
  68. package/chunk-CYJWI3NH.js +119 -0
  69. package/{chunk-GBRG75BQ.js → chunk-D2MDMY2M.js} +1 -0
  70. package/{chunk-3SV7RM24.js → chunk-D2QN6CTI.js} +117 -72
  71. package/{chunk-TZZ2WRBL.js → chunk-DFDXM2Y4.js} +20 -16
  72. package/{chunk-5TEEECZM.js → chunk-E2AKSW7L.js} +10 -7
  73. package/{chunk-RSEEDUMS.js → chunk-EDX5XSJM.js} +2 -2
  74. package/{chunk-QDSINZM3.js → chunk-EUGTFFO6.js} +2 -23
  75. package/{chunk-UNYJU5L6.js → chunk-EYLGAEB4.js} +5 -1
  76. package/{chunk-CU3QB4HW.js → chunk-EYWJT7A2.js} +12 -12
  77. package/{chunk-BNGW5ASC.js → chunk-EZVK3N5L.js} +66 -18
  78. package/{chunk-6FGTMQCL.js → chunk-F32Z66T4.js} +6 -10
  79. package/{chunk-ZOVKKMF6.js → chunk-FY4SDK2E.js} +1 -1
  80. package/chunk-G6OOUQWJ.js +417 -0
  81. package/{chunk-PQWU42UQ.js → chunk-GCKHQECX.js} +6 -6
  82. package/chunk-GKXCHNTE.js +15 -0
  83. package/{chunk-P6GMCCAT.js → chunk-GQV5KHJU.js} +78 -12
  84. package/{chunk-B2XUQXQX.js → chunk-HIQ4GF53.js} +191 -68
  85. package/{chunk-GMZLP5DV.js → chunk-HNUWUO75.js} +30 -19
  86. package/{chunk-UASIEDKM.js → chunk-I2XLRXVX.js} +36 -31
  87. package/{chunk-5UTFL4QJ.js → chunk-I2ZMGXXF.js} +10 -5
  88. package/chunk-I42VC5KR.js +15 -0
  89. package/{chunk-3BXNTXYI.js → chunk-I4SN4NUQ.js} +1199 -56
  90. package/chunk-IA7TRNNR.js +11 -0
  91. package/{chunk-WIWM4FE3.js → chunk-IJERIUXS.js} +55 -748
  92. package/{chunk-BIDGLJQ3.js → chunk-IK2TSJQA.js} +45 -8
  93. package/{chunk-CPUFH46E.js → chunk-ILU2NPWY.js} +10 -10
  94. package/{chunk-SLLGJZDT.js → chunk-ISQL4V7C.js} +4 -4
  95. package/chunk-IT3ZZRJE.js +12 -0
  96. package/{chunk-DY7ANLKG.js → chunk-JKMLSTZK.js} +43 -12
  97. package/{chunk-6TPOEJMQ.js → chunk-JZX2XLKC.js} +64 -23
  98. package/{chunk-27ONFIEY.js → chunk-K2AER7RX.js} +19 -12
  99. package/{chunk-O2OWEFII.js → chunk-KFHQQ3NO.js} +1 -1
  100. package/{chunk-QXGPFY6J.js → chunk-LGN377P3.js} +27 -17
  101. package/{chunk-L36OWPP3.js → chunk-LIQJTQRN.js} +118 -139
  102. package/{chunk-BFU6C242.js → chunk-NMFV26UG.js} +1 -1
  103. package/{chunk-5J3PYNUP.js → chunk-NYYFIKHI.js} +17 -3
  104. package/{chunk-6O4IK4V2.js → chunk-OFFL4DCR.js} +1 -1
  105. package/{chunk-B6SAMB33.js → chunk-OWYYDMGJ.js} +209 -9
  106. package/{chunk-KQHGZWSV.js → chunk-OXME3PEE.js} +1 -1
  107. package/{chunk-CTUQJVQM.js → chunk-P5QACQDK.js} +1 -1
  108. package/{chunk-TB3MIBRC.js → chunk-PIDUNDFS.js} +572 -430
  109. package/{chunk-4JMDLJAD.js → chunk-PJNFNEJE.js} +114 -37
  110. package/chunk-PKZKOVA5.js +11507 -0
  111. package/{chunk-Z4CSIXYP.js → chunk-PLSVXHSA.js} +3 -3
  112. package/chunk-PWTNI4N7.js +47 -0
  113. package/chunk-QFEW2ULV.js +42 -0
  114. package/{chunk-RGNEEJ3Y.js → chunk-QLQ573SU.js} +35 -9
  115. package/chunk-QQ56R7KS.js +88 -0
  116. package/chunk-QYPE3TS3.js +43 -0
  117. package/{chunk-HTVYCXBP.js → chunk-RN2GPWN6.js} +354 -120
  118. package/{chunk-ATLTFRYJ.js → chunk-ROCUB2H2.js} +280 -98
  119. package/{chunk-4DPP773Q.js → chunk-RSHPU4PD.js} +59 -11
  120. package/chunk-RVWMAFIT.js +134 -0
  121. package/{chunk-ESHYE7WU.js → chunk-S73EPYNC.js} +10 -7
  122. package/{chunk-UQNS32WZ.js → chunk-SCMHQUMK.js} +1 -1
  123. package/chunk-SW4S4XYB.js +1794 -0
  124. package/{chunk-ZUEK6A6C.js → chunk-TTH4HOJD.js} +1973 -754
  125. package/chunk-TY3TIUJK.js +89 -0
  126. package/{chunk-X2QRZXZH.js → chunk-TYJ5XFEA.js} +4 -4
  127. package/{chunk-ALFH24P3.js → chunk-TYYRSFBG.js} +197 -155
  128. package/{chunk-MST6R3E4.js → chunk-U5GPBQDG.js} +34 -22
  129. package/chunk-U5ICMAFV.js +14110 -0
  130. package/{chunk-7KVZ5LDQ.js → chunk-UBUH2TCC.js} +18 -4
  131. package/chunk-UEILX4EV.js +15 -0
  132. package/chunk-UHTDNB5Y.js +140 -0
  133. package/{chunk-YYLHWIW6.js → chunk-UKZX3NHN.js} +1 -1
  134. package/{chunk-OHOVNO7I.js → chunk-UOKFKFPO.js} +6 -3
  135. package/{chunk-XISEYOGH.js → chunk-USHQX6VT.js} +5 -5
  136. package/chunk-UUPR3TD7.js +53 -0
  137. package/{chunk-3DAVPNFT.js → chunk-V4EE3D54.js} +122 -107
  138. package/{chunk-HDLLCBRF.js → chunk-VEA7H5FG.js} +2 -2
  139. package/chunk-VHGD6FHV.js +116 -0
  140. package/chunk-VIWDGTDA.js +8 -0
  141. package/{chunk-GOH6RW6F.js → chunk-VJXHL6MH.js} +34 -11
  142. package/{chunk-4XEYAFLY.js → chunk-VL5KOY2C.js} +623 -94
  143. package/{chunk-EADNWBAZ.js → chunk-VP3BINY7.js} +13 -0
  144. package/{chunk-DXHL7G2L.js → chunk-VWW6O2TL.js} +274 -93
  145. package/{chunk-EOARMOVD.js → chunk-W4S6OTSC.js} +6 -3
  146. package/chunk-WD4XYDYC.js +567 -0
  147. package/chunk-WJZOQR2J.js +151 -0
  148. package/{chunk-AUDNYVRC.js → chunk-XETG4RIX.js} +5 -5
  149. package/{chunk-MX574M24.js → chunk-XI7DGLUK.js} +4 -4
  150. package/{chunk-3L2WKC3W.js → chunk-XPWGOTBQ.js} +8 -1
  151. package/chunk-XRUSXPCQ.js +514 -0
  152. package/{chunk-I4OPU5TK.js → chunk-XS47QOFV.js} +273 -11
  153. package/{chunk-S5XGT6GB.js → chunk-XZNCX52W.js} +30 -9
  154. package/{chunk-5OA5HMTL.js → chunk-YLMMECCH.js} +1 -1
  155. package/{chunk-CFT5HBGW.js → chunk-YVLQXTUB.js} +448 -12
  156. package/chunk-YVPQATSC.js +709 -0
  157. package/chunk-ZEZC7IIM.js +126 -0
  158. package/{chunk-ALGORS6Y.js → chunk-ZF6526IQ.js} +43 -8
  159. package/chunk-ZIWPQEFU.js +165 -0
  160. package/chunk-ZRAU6T47.js +56 -0
  161. package/{cliExecutor-AWYR3T33.js → cliExecutor-BWBF2MTI.js} +4 -3
  162. package/{clipboardy-BX4NMYHE.js → clipboardy-GCO3GT3I.js} +3 -8
  163. package/{commandRegistry-2KBOXZQC.js → commandRegistry-NBLZEMCW.js} +183 -107
  164. package/contentThunks-6AIWNSGO.js +84 -0
  165. package/{cooldownCommands-ZLEPIB4A.js → cooldownCommands-JFKTYS2D.js} +2 -2
  166. package/{createAgentAutomationAction-5UGTB26P.js → createAgentAutomationAction-4BUS65DZ.js} +53 -44
  167. package/createDialogAction-QAIKSCG4.js +76 -0
  168. package/{createPageAction-CDLDKPRM.js → createPageAction-DXCZ334C.js} +65 -54
  169. package/cursorProvider-YGGNMVWX.js +6123 -0
  170. package/{db-VQSAOWAO.js → db-2QOTXYGH.js} +11 -5
  171. package/{dbSlice-DQ32LYTJ.js → dbSlice-J37OGIXH.js} +19 -13
  172. package/{deleteFile-NX6QHCWZ.js → deleteFile-6JWDDRVP.js} +10 -6
  173. package/dialogCommands-YZLSJB6X.js +113 -0
  174. package/{dialogSlice-N3YB65G5.js → dialogSlice-PVUSMKFW.js} +53 -39
  175. package/{docCreateCommands-ZSLGVBZT.js → docCreateCommands-JB2RRMRJ.js} +54 -57
  176. package/{docDeleteCommands-5N4GVZBG.js → docDeleteCommands-AQENULNM.js} +56 -58
  177. package/{docReadCommands-YJSAA7AV.js → docReadCommands-DYD25YLQ.js} +53 -56
  178. package/{docStore-E3CEOV5Q.js → docStore-CSEBEMKP.js} +25 -16
  179. package/{docUpdateCommands-WEMLSW6W.js → docUpdateCommands-3GVS23QL.js} +54 -57
  180. package/{fetchMessages-67MEFPZR.js → fetchMessages-IIJWQ3HR.js} +5 -4
  181. package/{getPricing-NMMFT3YI.js → getPricing-FKK3F5EJ.js} +11 -9
  182. package/{handleSendMessageAction-DQAD5ERJ.js → handleSendMessageAction-G2TLYGC4.js} +422 -118
  183. package/index.js +11 -7
  184. package/{lib-FRRS27KN.js → lib-4YTWAGY7.js} +581 -248
  185. package/{localDialogRead-EBRS242U.js → localDialogRead-FSOMOPDZ.js} +2 -2
  186. package/localRuntimeAdapter-B4TAYYA7.js +244 -0
  187. package/localRuntimeAuthority-JDAD7CB6.js +16 -0
  188. package/{localRuntimeDb-3LRMNLCM.js → localRuntimeDb-CVC62PM5.js} +1 -1
  189. package/{machineCommands-HAP75VSG.js → machineCommands-6OBFD3XF.js} +503 -161
  190. package/{machineInfo-66ZFUMLE.js → machineInfo-UKPTZO5Y.js} +2 -2
  191. package/machineWsRunDispatch-OO7N3O3Y.js +169 -0
  192. package/{memberThunks-5ZXPR63F.js → memberThunks-66DH6ABQ.js} +25 -18
  193. package/{models-ZPU5EDF4.js → models-LAS4B2B5.js} +2 -2
  194. package/package.json +1 -1
  195. package/{providerPresetApply-DD6NGWW6.js → providerPresetApply-MY66I6NT.js} +10 -10
  196. package/{providerRegistry-XDRLMYGJ.js → providerRegistry-QOE2FT57.js} +13 -9
  197. package/{read-EPTJRAEF.js → read-DC4NUGN6.js} +12 -8
  198. package/{readDocTool-W4NDXNEX.js → readDocTool-NCJ5NT25.js} +1 -1
  199. package/{readlineWorkspace-7BC66QSX.js → readlineWorkspace-UIQN7JUR.js} +5017 -915
  200. package/{removeDialogAgentAction-OSYNZRX7.js → removeDialogAgentAction-E2H3OZU6.js} +29 -28
  201. package/{runAgentClientLoop-6E6UC3CE.js → runAgentClientLoop-GS3SGG37.js} +154 -97
  202. package/{runtimeDoctorCommands-ID23PNNZ.js → runtimeDoctorCommands-GIOGC5SC.js} +17 -17
  203. package/secretCommands-ZXZRLR3R.js +700 -0
  204. package/setDialogExtraReferencesAction-SITRPMYU.js +37 -0
  205. package/{setPrimaryDialogAgentAction-WZ7KI3YA.js → setPrimaryDialogAgentAction-U7N45TGC.js} +30 -29
  206. package/{chunk-SONWNI3L.js → settingThunks-Y7SVJOMZ.js} +223 -928
  207. package/{skillDiscovery-ZBU76COE.js → skillDiscovery-QC35EQY4.js} +2 -2
  208. package/{slateUtils-RIZES3PV.js → slateUtils-NGV2NMKM.js} +1 -1
  209. package/{spaceCommands-UJOVU4XI.js → spaceCommands-ZR5BR3GX.js} +59 -59
  210. package/{streamAgentChatTurn-3UXPYFNX.js → streamAgentChatTurn-4XYC33KE.js} +309 -165
  211. package/{switchDialogAgentAction-GMR7WN3P.js → switchDialogAgentAction-OMGBD3N2.js} +26 -22
  212. package/{tableCommands-G7RV3RU3.js → tableCommands-U3QDY4L6.js} +19 -17
  213. package/{toolApiClient-CVGWM4PN.js → toolApiClient-7WSJJJBV.js} +6 -5
  214. package/tools-P77EE7Q4.js +124 -0
  215. package/tuiSummaryLlmCaller-BM3VSTBU.js +130 -0
  216. package/{updateCommands-4EHDLF5J.js → updateCommands-NQXAGFM7.js} +3 -3
  217. package/{updateDialogTitleAction-UPFV7TDT.js → updateDialogTitleAction-CIANVPZC.js} +102 -57
  218. package/workloadLifecycle-36DXRZKU.js +320 -0
  219. package/action-GI44T4DR.js +0 -31
  220. package/agentListCommands-IW3GQVUP.js +0 -427
  221. package/agentRecordCommands-VCA76W6B.js +0 -134
  222. package/agentRunCommand-YNLDKVR7.js +0 -161
  223. package/browser-image-compression-MFDTD7K6.js +0 -1763
  224. package/chatQueueReduxAdapter-TJRMXMYA.js +0 -186
  225. package/chromeOpsCommands-IXRLN57H.js +0 -289
  226. package/chunk-36KZDDO5.js +0 -2415
  227. package/chunk-ACQD6YI2.js +0 -25363
  228. package/chunk-CQ3WA2NE.js +0 -299
  229. package/chunk-CYSYR67N.js +0 -93
  230. package/chunk-JBTJAPUF.js +0 -35
  231. package/chunk-K2CSUCHJ.js +0 -620
  232. package/chunk-LTRXGFMS.js +0 -83
  233. package/chunk-M76ECQRD.js +0 -13658
  234. package/chunk-MEYIRKDN.js +0 -8967
  235. package/chunk-OCZKATRC.js +0 -129
  236. package/chunk-OTGFTBLI.js +0 -13
  237. package/chunk-PUOC4YRO.js +0 -394
  238. package/chunk-PZZTFEKK.js +0 -34
  239. package/chunk-URMS4XY2.js +0 -10
  240. package/chunk-UV6VISQJ.js +0 -20
  241. package/chunk-VJVNU77E.js +0 -83
  242. package/chunk-XYJSY4KG.js +0 -13807
  243. package/chunk-Y5GCAMGP.js +0 -9
  244. package/chunk-YPREESF4.js +0 -225
  245. package/contentThunks-BDIQRZR6.js +0 -73
  246. package/createDialogAction-B7VGVEVU.js +0 -66
  247. package/dialogCommands-G7YBVAMC.js +0 -102
  248. package/levelLazyShim-GZBKODGI.js +0 -7
  249. package/machineWsRunDispatch-L32G7C4P.js +0 -149
  250. package/serverStoreFactory-YMXDF4NI.js +0 -20
  251. package/setDialogExtraReferencesAction-M32UYNCG.js +0 -30
  252. package/settingSlice-Q6EKL7EQ.js +0 -204
  253. package/syncMapping-N6RGXGBW.js +0 -437
  254. package/tools-MKYDMWA4.js +0 -111
  255. package/tuiSummaryLlmCaller-3YFNHCTW.js +0 -128
  256. package/{chunk-SV5IJK6K.js → chunk-NBTY7YJF.js} +3 -3
  257. package/{chunk-2SYTUTLI.js → chunk-YBNHPX4S.js} +3 -3
  258. package/{offlineMarxistsAgentCommand-HGXZV4XJ.js → offlineMarxistsAgentCommand-2QTHJCHV.js} +4 -4
@@ -0,0 +1,871 @@
1
+ import {
2
+ fnv1a32
3
+ } from "./chunk-UEILX4EV.js";
4
+ import {
5
+ createSelector,
6
+ noloDeleteRequest,
7
+ noloPatchRequest,
8
+ noloUploadRequest,
9
+ noloWriteRequest,
10
+ syncWithServers
11
+ } from "./chunk-IJERIUXS.js";
12
+ import {
13
+ getAllServers,
14
+ getIsDesktopApp
15
+ } from "./chunk-6Q7UTJKR.js";
16
+ import {
17
+ selectIdentityToken,
18
+ selectIdentityUser,
19
+ selectIdentityUserId
20
+ } from "./chunk-SEJ5OS6F.js";
21
+ import {
22
+ asOptionalPositiveFiniteNumber
23
+ } from "./chunk-U6VC4MU4.js";
24
+ import {
25
+ isRecord
26
+ } from "./chunk-KUG52IAP.js";
27
+ import {
28
+ asTrimmedString
29
+ } from "./chunk-3EUW3WEO.js";
30
+ import {
31
+ SERVERS,
32
+ normalizeKnownServerOrigin
33
+ } from "./chunk-LCBAMY2M.js";
34
+ import {
35
+ isLocalServerUrl
36
+ } from "./chunk-4SN6J65J.js";
37
+ import {
38
+ normalizeServerOrigin
39
+ } from "./chunk-CF7PE763.js";
40
+ import {
41
+ asOptionalTrimmedString
42
+ } from "./chunk-G3SUCT4W.js";
43
+
44
+ // packages/app/stateViews/runtime.ts
45
+ var selectCurrentToken = (state) => {
46
+ const token = selectIdentityToken(state);
47
+ return typeof token === "string" ? token : void 0;
48
+ };
49
+ var selectCurrentUserId = (state) => {
50
+ const userId = selectIdentityUserId(state);
51
+ return typeof userId === "string" ? userId : void 0;
52
+ };
53
+ var EMPTY_SYNC_SERVERS = [];
54
+ var selectRuntimeRemoteServer = (state) => {
55
+ const configuredServer = normalizeKnownServerOrigin(state.settings?.currentServer) ?? void 0;
56
+ if (!getIsDesktopApp()) return configuredServer || SERVERS.MAIN;
57
+ return isLocalServerUrl(configuredServer) ? SERVERS.MAIN : configuredServer || SERVERS.MAIN;
58
+ };
59
+ var selectConfiguredSyncServers = (state) => state.settings?.syncServers;
60
+ var selectRuntimeRemoteSyncServers = createSelector(
61
+ [selectConfiguredSyncServers],
62
+ (syncServers) => {
63
+ if (!Array.isArray(syncServers) || syncServers.length === 0) {
64
+ return EMPTY_SYNC_SERVERS;
65
+ }
66
+ const normalized = syncServers.map(normalizeKnownServerOrigin).filter((server) => !!server);
67
+ if (!getIsDesktopApp()) return normalized;
68
+ return normalized.filter((server) => !isLocalServerUrl(server));
69
+ }
70
+ );
71
+ var selectLocalRuntimeOrigin = () => {
72
+ if (typeof window !== "undefined" && typeof window.location?.origin === "string" && /^https?:\/\//.test(window.location.origin)) {
73
+ return window.location.origin.replace(/\/+$/, "");
74
+ }
75
+ return void 0;
76
+ };
77
+ var selectRuntimeSnapshot = createSelector(
78
+ [
79
+ selectCurrentToken,
80
+ selectCurrentUserId,
81
+ selectRuntimeRemoteServer,
82
+ selectRuntimeRemoteSyncServers,
83
+ selectLocalRuntimeOrigin
84
+ ],
85
+ (currentToken, currentUserId, currentServer, syncServers, localRuntimeOrigin) => ({
86
+ currentToken,
87
+ currentUserId,
88
+ currentServer,
89
+ syncServers,
90
+ localRuntimeOrigin
91
+ })
92
+ );
93
+ var selectRuntimeCurrentServer = createSelector(
94
+ [selectRuntimeSnapshot],
95
+ (runtime) => runtime.currentServer
96
+ );
97
+ var selectRuntimeRemoteServers = createSelector(
98
+ [selectRuntimeSnapshot],
99
+ (runtime) => getAllServers(runtime.currentServer, runtime.syncServers)
100
+ );
101
+
102
+ // packages/database/runtimeServerContext.ts
103
+ var getRuntimeServerContext = (state, preferredServerOrigin) => {
104
+ const {
105
+ currentToken,
106
+ currentUserId,
107
+ currentServer,
108
+ syncServers = []
109
+ } = selectRuntimeSnapshot(state);
110
+ return {
111
+ currentToken,
112
+ currentUserId,
113
+ currentServer,
114
+ syncServers,
115
+ userAuthorityRegistry: resolveRuntimeUserAuthorityRegistry(state),
116
+ remoteServers: getAllServers(
117
+ currentServer,
118
+ syncServers,
119
+ preferredServerOrigin
120
+ )
121
+ };
122
+ };
123
+ var resolveRuntimeUserAuthorityRegistry = (state) => {
124
+ const settingsRegistry = state.settings?.userAuthorityRegistry;
125
+ if (settingsRegistry && typeof settingsRegistry === "object") {
126
+ return settingsRegistry;
127
+ }
128
+ const userRegistry = selectIdentityUser(state)?.authorityRegistry;
129
+ if (userRegistry && typeof userRegistry === "object") {
130
+ return userRegistry;
131
+ }
132
+ return void 0;
133
+ };
134
+
135
+ // packages/database/authority/ownerKey.ts
136
+ var USER_OWNED_SECOND_SEGMENT_PREFIXES = /* @__PURE__ */ new Set([
137
+ "agent",
138
+ "dialog",
139
+ "page",
140
+ "doc",
141
+ "notification",
142
+ "email",
143
+ "meta",
144
+ "row",
145
+ "view",
146
+ "file",
147
+ "job"
148
+ ]);
149
+ var PUBLIC_OWNER_SENTINELS = /* @__PURE__ */ new Set(["pub", "id", "stats", "index"]);
150
+ var cleanSegment = (value) => {
151
+ const trimmed = asTrimmedString(value);
152
+ return trimmed.length > 0 ? trimmed : null;
153
+ };
154
+ var normalizeCandidateOwners = (candidateOwnerUserIds) => {
155
+ const out = [];
156
+ for (const candidate of candidateOwnerUserIds ?? []) {
157
+ const normalized = cleanSegment(candidate ?? void 0);
158
+ if (!normalized || PUBLIC_OWNER_SENTINELS.has(normalized)) continue;
159
+ if (!out.includes(normalized)) out.push(normalized);
160
+ }
161
+ return out.sort((left, right) => right.length - left.length);
162
+ };
163
+ var resolveCandidateOwnerFromKeyRemainder = (remainder, candidateOwnerUserIds) => {
164
+ const normalizedRemainder = cleanSegment(remainder);
165
+ if (!normalizedRemainder) return null;
166
+ for (const candidate of normalizeCandidateOwners(candidateOwnerUserIds)) {
167
+ if (normalizedRemainder === candidate || normalizedRemainder.startsWith(`${candidate}-`)) {
168
+ return candidate;
169
+ }
170
+ }
171
+ return null;
172
+ };
173
+ var parseOwnerUserIdFromDbKey = (dbKey, options = {}) => {
174
+ const normalized = cleanSegment(dbKey);
175
+ if (!normalized) return null;
176
+ const parts = normalized.split("-");
177
+ const [prefix] = parts;
178
+ if (!prefix) return null;
179
+ if (!USER_OWNED_SECOND_SEGMENT_PREFIXES.has(prefix)) {
180
+ if (prefix === "grant" && parts[1] === "agent" && parts.length >= 5) {
181
+ const ownerAndRest2 = normalized.slice(prefix.length + 1 + parts[1].length + 1);
182
+ const [owner2] = ownerAndRest2.split("-");
183
+ return cleanSegment(owner2);
184
+ }
185
+ return null;
186
+ }
187
+ if (parts[0] === "dialog" && parts[2] === "msg") {
188
+ return null;
189
+ }
190
+ const ownerAndRest = normalized.slice(prefix.length + 1);
191
+ const candidateOwner = resolveCandidateOwnerFromKeyRemainder(
192
+ ownerAndRest,
193
+ options.candidateOwnerUserIds
194
+ );
195
+ if (candidateOwner) return candidateOwner;
196
+ const [owner] = ownerAndRest.split("-");
197
+ const ownerUserId = cleanSegment(owner);
198
+ if (!ownerUserId) return null;
199
+ if (PUBLIC_OWNER_SENTINELS.has(ownerUserId)) return null;
200
+ return ownerUserId;
201
+ };
202
+
203
+ // packages/database/authority/userAuthorityRegistry.ts
204
+ var normalizeAuthorityServerOrigin = (value) => {
205
+ const normalized = normalizeServerOrigin(value);
206
+ return /^https?:\/\//i.test(normalized) ? normalized : null;
207
+ };
208
+ var normalizeUserId = (value) => asOptionalTrimmedString(value) ?? null;
209
+ var readEntryAuthorityServer = (entry) => {
210
+ if (typeof entry === "string") {
211
+ return normalizeAuthorityServerOrigin(entry);
212
+ }
213
+ if (!isRecord(entry)) {
214
+ return null;
215
+ }
216
+ return normalizeAuthorityServerOrigin(entry.authorityServer) ?? normalizeAuthorityServerOrigin(entry.homeServer) ?? normalizeAuthorityServerOrigin(entry.primaryServer);
217
+ };
218
+ var resolveUserAuthorityServer = ({
219
+ ownerUserId,
220
+ registry
221
+ }) => {
222
+ const normalizedOwner = normalizeUserId(ownerUserId);
223
+ if (!normalizedOwner || !registry || typeof registry !== "object") {
224
+ return null;
225
+ }
226
+ return readEntryAuthorityServer(registry[normalizedOwner]);
227
+ };
228
+
229
+ // packages/database/authority/recordAuthority.ts
230
+ var normalizeUserId2 = (value) => asOptionalTrimmedString(value) ?? null;
231
+ var getRegistryOwnerCandidates = (registry) => isRecord(registry) ? Object.keys(registry) : [];
232
+ var resolveRecordAuthority = ({
233
+ dbKey,
234
+ record,
235
+ currentUserId,
236
+ currentServer,
237
+ userAuthorityRegistry
238
+ }) => {
239
+ const ownerUserId = parseOwnerUserIdFromDbKey(dbKey, {
240
+ candidateOwnerUserIds: [
241
+ normalizeUserId2(record?.userId),
242
+ normalizeUserId2(currentUserId),
243
+ ...getRegistryOwnerCandidates(userAuthorityRegistry)
244
+ ]
245
+ }) ?? normalizeUserId2(record?.userId);
246
+ const serverOrigin = normalizeAuthorityServerOrigin(record?.serverOrigin);
247
+ const explicitAuthority = normalizeAuthorityServerOrigin(record?.authorityServer);
248
+ const registryAuthority = resolveUserAuthorityServer({
249
+ ownerUserId,
250
+ registry: userAuthorityRegistry
251
+ });
252
+ const currentUserAuthority = ownerUserId && ownerUserId === normalizeUserId2(currentUserId) ? normalizeAuthorityServerOrigin(currentServer) : null;
253
+ return {
254
+ ownerUserId,
255
+ authorityServer: explicitAuthority ?? registryAuthority ?? currentUserAuthority ?? serverOrigin,
256
+ serverOrigin
257
+ };
258
+ };
259
+
260
+ // packages/database/actions/readResolution.ts
261
+ var toComparableTimestamp = (data) => {
262
+ if (!data || typeof data !== "object") return 0;
263
+ const updatedAtMs = asOptionalPositiveFiniteNumber(
264
+ new Date(data.updatedAt).getTime()
265
+ );
266
+ if (updatedAtMs !== void 0) return updatedAtMs;
267
+ const createdAtMs = asOptionalPositiveFiniteNumber(
268
+ new Date(data.createdAt).getTime()
269
+ );
270
+ if (createdAtMs !== void 0) return createdAtMs;
271
+ return asOptionalPositiveFiniteNumber(Number(data?.meta?.createdAt)) ?? 0;
272
+ };
273
+ var partitionReadServers = ({
274
+ allServers,
275
+ preferredServerOrigin
276
+ }) => {
277
+ const preferredServer = typeof preferredServerOrigin === "string" && preferredServerOrigin.trim().length > 0 ? normalizeServerOrigin(preferredServerOrigin) : null;
278
+ const fallbackServers = preferredServer ? allServers.filter(
279
+ (server) => normalizeServerOrigin(server) !== preferredServer
280
+ ) : allServers;
281
+ return {
282
+ preferredServer,
283
+ fallbackServers,
284
+ orderedServersForLocalHit: preferredServer ? [preferredServer, ...fallbackServers] : fallbackServers
285
+ };
286
+ };
287
+ var compareRemoteRecordsByComparableTime = (left, right) => toComparableTimestamp(left) - toComparableTimestamp(right);
288
+ var pickBestSettledRemoteRecord = ({
289
+ settledResults,
290
+ isBetterCandidate
291
+ }) => {
292
+ const validResults = settledResults.map((result, index) => ({
293
+ data: result.status === "fulfilled" ? result.value : null,
294
+ index
295
+ })).filter((item) => item.data !== null && typeof item.data === "object");
296
+ if (validResults.length === 0) return null;
297
+ const latest = validResults.reduce(
298
+ (best, current) => isBetterCandidate(current.data, best.data) ? current : best
299
+ );
300
+ return { index: latest.index, data: latest.data };
301
+ };
302
+ var shouldReplaceLocalWithRemoteRecord = ({
303
+ localData,
304
+ remoteData,
305
+ isRemoteNewer
306
+ }) => {
307
+ if (!remoteData || typeof remoteData !== "object") return false;
308
+ if (!localData || typeof localData !== "object") return true;
309
+ return isRemoteNewer(remoteData, localData);
310
+ };
311
+ var shouldReplicateLocalRecord = ({
312
+ localData,
313
+ remoteData,
314
+ remoteTargetCount
315
+ }) => !!localData && !remoteData && remoteTargetCount > 0;
316
+ var compactUniqueServers = (servers) => {
317
+ const out = [];
318
+ for (const server of servers) {
319
+ if (typeof server !== "string" || server.trim().length === 0) continue;
320
+ const normalized = normalizeServerOrigin(server);
321
+ if (!out.includes(normalized)) out.push(normalized);
322
+ }
323
+ return out;
324
+ };
325
+ var planAuthorityReadServers = ({
326
+ allServers,
327
+ authorityServer,
328
+ serverOrigin
329
+ }) => compactUniqueServers([authorityServer, serverOrigin, ...allServers]);
330
+
331
+ // packages/database/fileRing.ts
332
+ var chooseServersByKey = (allServers, key, replicaCount) => {
333
+ if (!allServers.length || replicaCount <= 0) return [];
334
+ const uniqueServers = Array.from(new Set(allServers)).filter((s) => !!s);
335
+ if (uniqueServers.length === 0) return [];
336
+ const scored = uniqueServers.map((server) => ({
337
+ server,
338
+ score: fnv1a32(`${server}::${key}`)
339
+ }));
340
+ scored.sort((a, b) => a.score - b.score);
341
+ const limit = Math.min(replicaCount, scored.length);
342
+ return scored.slice(0, limit).map((item) => item.server);
343
+ };
344
+
345
+ // packages/database/tenantPlacement.ts
346
+ var TENANT_REPLICA_COUNT = 2;
347
+ var planServersForTenant = (allServers, currentServer, tenantId) => {
348
+ const uniqueServers = Array.from(new Set(allServers)).filter(Boolean);
349
+ if (!uniqueServers.length) return [];
350
+ const key = asOptionalTrimmedString(tenantId) ?? "default-tenant";
351
+ const fromRing = chooseServersByKey(
352
+ uniqueServers,
353
+ key,
354
+ TENANT_REPLICA_COUNT
355
+ );
356
+ const set = new Set(fromRing);
357
+ if (currentServer && uniqueServers.includes(currentServer)) {
358
+ set.add(currentServer);
359
+ }
360
+ return Array.from(set);
361
+ };
362
+
363
+ // packages/database/authority/deviceLocal.ts
364
+ var DEVICE_LOCAL_OWNER_ID = "local";
365
+ var DEVICE_LOCAL_DB_KEY_PREFIXES = [
366
+ "dialog-local-",
367
+ "agent-local-"
368
+ ];
369
+ var clean = (value) => asOptionalTrimmedString(value) ?? null;
370
+ var isDeviceLocalOwnerId = (userId) => clean(userId) === DEVICE_LOCAL_OWNER_ID;
371
+ var resolveEffectiveSpaceActorId = (accountUserId) => {
372
+ const cleaned = clean(accountUserId);
373
+ if (!cleaned || isDeviceLocalOwnerId(cleaned)) {
374
+ return DEVICE_LOCAL_OWNER_ID;
375
+ }
376
+ return cleaned;
377
+ };
378
+ var isDeviceLocalSpaceMembership = (membership) => isDeviceLocalOwnerId(membership?.userId);
379
+ var isDeviceLocalSpaceBody = (space) => isDeviceLocalOwnerId(space?.userId) || isDeviceLocalOwnerId(space?.ownerId);
380
+ var isDeviceLocalDbKey = (dbKey) => {
381
+ const key = clean(dbKey);
382
+ if (!key) return false;
383
+ for (const prefix of DEVICE_LOCAL_DB_KEY_PREFIXES) {
384
+ if (key.startsWith(prefix)) return true;
385
+ }
386
+ return parseOwnerUserIdFromDbKey(key, {
387
+ candidateOwnerUserIds: [DEVICE_LOCAL_OWNER_ID]
388
+ }) === DEVICE_LOCAL_OWNER_ID;
389
+ };
390
+ var resolveRecordOwnerUserId = (record) => {
391
+ if (!record) return null;
392
+ const explicit = clean(record.userId);
393
+ if (explicit) return explicit;
394
+ if (isDeviceLocalDbKey(record.dbKey) || isDeviceLocalDbKey(record.id)) {
395
+ return DEVICE_LOCAL_OWNER_ID;
396
+ }
397
+ const fromKey = parseOwnerUserIdFromDbKey(clean(record.dbKey) ?? "", {
398
+ candidateOwnerUserIds: [DEVICE_LOCAL_OWNER_ID]
399
+ }) ?? parseOwnerUserIdFromDbKey(clean(record.id) ?? "", {
400
+ candidateOwnerUserIds: [DEVICE_LOCAL_OWNER_ID]
401
+ });
402
+ return fromKey;
403
+ };
404
+
405
+ // packages/database/actions/writeAck.ts
406
+ var ACK_ENTRY_RETENTION_MS = 1e4;
407
+ var ACK_ENTRY_MAX = 256;
408
+ var replicationTargetKey = (server) => normalizeKnownServerOrigin(server) ?? normalizeServerOrigin(server);
409
+ var ackEntries = /* @__PURE__ */ new Map();
410
+ var sweepAckEntries = () => {
411
+ const wallClock = Date.now();
412
+ for (const [key, entry] of ackEntries) {
413
+ if (entry.settledAt !== null && wallClock - entry.settledAt > ACK_ENTRY_RETENTION_MS) {
414
+ ackEntries.delete(key);
415
+ }
416
+ }
417
+ while (ackEntries.size > ACK_ENTRY_MAX) {
418
+ const oldest = ackEntries.keys().next().value;
419
+ if (oldest === void 0) break;
420
+ ackEntries.delete(oldest);
421
+ }
422
+ };
423
+ var isReplicationAckHandle = (value) => {
424
+ if (!value || typeof value !== "object") return false;
425
+ const handle = value;
426
+ return typeof handle.primary?.then === "function" && handle.targets instanceof Map;
427
+ };
428
+ var asAckStatus = (ack) => ack.then(
429
+ (ok) => ok ? "acked" : "failed",
430
+ () => "failed"
431
+ );
432
+ var beginWriteAck = (dbKey) => {
433
+ let resolveOutcome = () => {
434
+ };
435
+ const promise = new Promise((resolve) => {
436
+ resolveOutcome = resolve;
437
+ });
438
+ const entry = {
439
+ promise,
440
+ settledAt: null,
441
+ servers: [],
442
+ primaryTargetKey: null,
443
+ planRegistered: false,
444
+ targetAcks: /* @__PURE__ */ new Map(),
445
+ settle: (status) => {
446
+ entry.settledAt = Date.now();
447
+ resolveOutcome(status);
448
+ }
449
+ };
450
+ ackEntries.set(dbKey, entry);
451
+ sweepAckEntries();
452
+ return {
453
+ settleWithReplication: (replication) => {
454
+ if (isReplicationAckHandle(replication)) {
455
+ entry.planRegistered = true;
456
+ entry.servers = [...replication.servers];
457
+ entry.primaryTargetKey = replicationTargetKey(replication.servers[0]);
458
+ for (const [key, ack] of replication.targets) {
459
+ entry.targetAcks.set(key, asAckStatus(ack));
460
+ }
461
+ void asAckStatus(replication.primary).then(
462
+ (status) => entry.settle(status)
463
+ );
464
+ return;
465
+ }
466
+ if (replication && typeof replication.then === "function") {
467
+ void asAckStatus(replication).then(
468
+ (status) => entry.settle(status)
469
+ );
470
+ return;
471
+ }
472
+ entry.settle("not-replicated");
473
+ },
474
+ markNotReplicated: () => entry.settle("not-replicated"),
475
+ markAborted: () => entry.settle("aborted")
476
+ };
477
+ };
478
+
479
+ // packages/database/actions/replication.ts
480
+ var isReadonlyPublicRecordKey = (dbKey) => dbKey.startsWith("agent-pub-");
481
+ var normalizeCurrentUserId = (state) => {
482
+ const userId = selectIdentityUserId(state);
483
+ return asOptionalTrimmedString(userId) ?? null;
484
+ };
485
+ var resolveReplicationServers = (currentServer, syncServers, preferredServerOrigin) => getAllServers(currentServer, syncServers, preferredServerOrigin);
486
+ var resolveAuthorityReplicationServers = ({
487
+ currentServer,
488
+ syncServers,
489
+ preferredServerOrigin,
490
+ dbKey,
491
+ record,
492
+ state
493
+ }) => {
494
+ const allServers = resolveReplicationServers(
495
+ currentServer,
496
+ syncServers,
497
+ preferredServerOrigin
498
+ );
499
+ const authority = resolveRecordAuthority({
500
+ dbKey,
501
+ record,
502
+ currentUserId: selectIdentityUserId(state),
503
+ currentServer,
504
+ userAuthorityRegistry: state?.settings?.userAuthorityRegistry ?? selectIdentityUser(state)?.authorityRegistry
505
+ });
506
+ if (isDeviceLocalOwnerId(authority.ownerUserId) || isDeviceLocalOwnerId(record?.userId) || isDeviceLocalDbKey(dbKey)) {
507
+ return [];
508
+ }
509
+ return planAuthorityReadServers({
510
+ allServers,
511
+ authorityServer: preferredServerOrigin ?? authority.authorityServer,
512
+ serverOrigin: authority.serverOrigin
513
+ });
514
+ };
515
+ var scheduleWriteReplication = (servers, request, state) => {
516
+ if (servers.length === 0) return null;
517
+ const [primaryServer, ...backupServers] = servers;
518
+ const targets = /* @__PURE__ */ new Map();
519
+ const settleTarget = /* @__PURE__ */ new Map();
520
+ for (const server of servers) {
521
+ const key = replicationTargetKey(server);
522
+ if (!key || targets.has(key)) continue;
523
+ targets.set(
524
+ key,
525
+ new Promise((resolve) => {
526
+ settleTarget.set(key, resolve);
527
+ })
528
+ );
529
+ }
530
+ const settleTargetFor = (server, ok) => {
531
+ const key = replicationTargetKey(server);
532
+ const resolve = settleTarget.get(key);
533
+ if (!resolve) return;
534
+ settleTarget.delete(key);
535
+ resolve(ok);
536
+ };
537
+ const primaryAck = Promise.resolve().then(async () => {
538
+ let primarySucceeded = false;
539
+ try {
540
+ primarySucceeded = await noloWriteRequest(primaryServer, request, state);
541
+ } finally {
542
+ settleTargetFor(primaryServer, primarySucceeded);
543
+ }
544
+ if (!primarySucceeded) {
545
+ console.warn(`Primary write sync failed for ${request.customKey} on ${primaryServer}`);
546
+ }
547
+ if (backupServers.length === 0) {
548
+ return primarySucceeded;
549
+ }
550
+ try {
551
+ syncWithServers(
552
+ backupServers,
553
+ (server, requestConfig, requestState, signal) => noloWriteRequest(server, requestConfig, requestState, signal, {
554
+ failureLogLevel: "info"
555
+ }).then(
556
+ (ok) => {
557
+ settleTargetFor(server, ok);
558
+ return ok;
559
+ },
560
+ (error) => {
561
+ settleTargetFor(server, false);
562
+ throw error;
563
+ }
564
+ ),
565
+ `Backup write sync failed for ${request.customKey} on`,
566
+ request,
567
+ state
568
+ );
569
+ } catch (error) {
570
+ for (const server of backupServers) settleTargetFor(server, false);
571
+ throw error;
572
+ }
573
+ return primarySucceeded;
574
+ });
575
+ return { servers: [...servers], primary: primaryAck, targets };
576
+ };
577
+ var resolveTenantReplicationServers = ({
578
+ currentServer,
579
+ syncServers,
580
+ tenantId
581
+ }) => {
582
+ const allServers = resolveReplicationServers(currentServer, syncServers);
583
+ if (allServers.length === 0) {
584
+ return [];
585
+ }
586
+ return planServersForTenant(allServers, currentServer, tenantId);
587
+ };
588
+ var resolveUploadReplicationServers = ({
589
+ currentServer,
590
+ syncServers,
591
+ tenantId,
592
+ uploadConfig,
593
+ state
594
+ }) => {
595
+ const allServers = resolveReplicationServers(currentServer, syncServers);
596
+ const authority = resolveRecordAuthority({
597
+ dbKey: uploadConfig.customKey,
598
+ record: uploadConfig.metadata,
599
+ currentUserId: selectIdentityUserId(state),
600
+ currentServer,
601
+ userAuthorityRegistry: state?.settings?.userAuthorityRegistry ?? selectIdentityUser(state)?.authorityRegistry
602
+ });
603
+ if (authority.ownerUserId || authority.authorityServer) {
604
+ return planAuthorityReadServers({
605
+ allServers,
606
+ authorityServer: authority.authorityServer,
607
+ serverOrigin: authority.serverOrigin
608
+ });
609
+ }
610
+ return resolveTenantReplicationServers({
611
+ currentServer,
612
+ syncServers,
613
+ tenantId
614
+ });
615
+ };
616
+ var scheduleExistingRecordReplication = ({
617
+ currentServer,
618
+ syncServers,
619
+ preferredServerOrigin,
620
+ dbKey,
621
+ localData,
622
+ state
623
+ }) => {
624
+ if (isReadonlyPublicRecordKey(dbKey)) {
625
+ return [];
626
+ }
627
+ const currentUserId = normalizeCurrentUserId(state);
628
+ const authority = resolveRecordAuthority({
629
+ dbKey,
630
+ record: localData,
631
+ currentUserId,
632
+ currentServer,
633
+ userAuthorityRegistry: state?.settings?.userAuthorityRegistry ?? selectIdentityUser(state)?.authorityRegistry
634
+ });
635
+ if (authority.ownerUserId && currentUserId && authority.ownerUserId !== currentUserId) {
636
+ return [];
637
+ }
638
+ const servers = resolveAuthorityReplicationServers({
639
+ currentServer,
640
+ syncServers,
641
+ preferredServerOrigin,
642
+ dbKey,
643
+ record: localData,
644
+ state
645
+ });
646
+ if (servers.length === 0) {
647
+ return [];
648
+ }
649
+ scheduleWriteReplication(
650
+ servers,
651
+ {
652
+ data: localData,
653
+ customKey: dbKey,
654
+ userId: typeof localData?.userId === "string" ? localData.userId : selectIdentityUserId(state)
655
+ },
656
+ state
657
+ );
658
+ return servers;
659
+ };
660
+ var schedulePatchReplication = ({
661
+ servers,
662
+ dbKey,
663
+ changes,
664
+ state,
665
+ preferredServerOrigin
666
+ }) => {
667
+ if (servers.length === 0) return;
668
+ Promise.resolve().then(async () => {
669
+ const primaryServer = typeof preferredServerOrigin === "string" && preferredServerOrigin.trim().length > 0 ? normalizeServerOrigin(preferredServerOrigin) : servers[0];
670
+ const backupServers = servers.filter(
671
+ (server) => normalizeServerOrigin(server) !== primaryServer
672
+ );
673
+ const primarySucceeded = await noloPatchRequest(primaryServer, dbKey, changes, state, void 0, {
674
+ failureLogLevel: "warn"
675
+ });
676
+ if (!primarySucceeded) {
677
+ console.warn(`Primary patch sync failed for ${dbKey} on ${primaryServer}`);
678
+ }
679
+ if (backupServers.length > 0) {
680
+ syncWithServers(
681
+ backupServers,
682
+ (server, targetDbKey, nextChanges, requestState, signal) => noloPatchRequest(server, targetDbKey, nextChanges, requestState, signal, {
683
+ failureLogLevel: "info"
684
+ }),
685
+ `Backup patch sync failed for ${dbKey} on`,
686
+ dbKey,
687
+ changes,
688
+ state
689
+ );
690
+ }
691
+ });
692
+ };
693
+ var scheduleConfiguredPatchReplication = ({
694
+ currentServer,
695
+ syncServers,
696
+ preferredServerOrigin,
697
+ dbKey,
698
+ changes,
699
+ state
700
+ }) => {
701
+ const servers = resolveAuthorityReplicationServers({
702
+ currentServer,
703
+ syncServers,
704
+ preferredServerOrigin,
705
+ dbKey,
706
+ record: changes,
707
+ state
708
+ });
709
+ if (servers.length === 0) {
710
+ return [];
711
+ }
712
+ schedulePatchReplication({
713
+ servers,
714
+ dbKey,
715
+ changes,
716
+ state,
717
+ preferredServerOrigin
718
+ });
719
+ return servers;
720
+ };
721
+ var scheduleUploadReplication = ({
722
+ currentServer,
723
+ syncServers,
724
+ tenantId,
725
+ uploadConfig,
726
+ state,
727
+ excludeServers = []
728
+ }) => {
729
+ const servers = resolveUploadReplicationServers({
730
+ currentServer,
731
+ syncServers,
732
+ tenantId,
733
+ uploadConfig,
734
+ state
735
+ });
736
+ const excluded = new Set(
737
+ excludeServers.filter((server) => typeof server === "string").map((server) => normalizeServerOrigin(server))
738
+ );
739
+ const remainingServers = servers.filter(
740
+ (server) => !excluded.has(normalizeServerOrigin(server))
741
+ );
742
+ if (remainingServers.length === 0) {
743
+ return [];
744
+ }
745
+ Promise.resolve().then(() => {
746
+ syncWithServers(
747
+ remainingServers,
748
+ noloUploadRequest,
749
+ `Upload sync failed for ${uploadConfig.customKey} on`,
750
+ uploadConfig,
751
+ state
752
+ );
753
+ });
754
+ return remainingServers;
755
+ };
756
+ var uploadToCurrentServer = async ({
757
+ currentServer,
758
+ uploadConfig,
759
+ state,
760
+ signal,
761
+ onProgress
762
+ }) => {
763
+ if (!currentServer) {
764
+ return false;
765
+ }
766
+ if (signal || onProgress) {
767
+ return noloUploadRequest(currentServer, uploadConfig, state, signal, onProgress);
768
+ }
769
+ return noloUploadRequest(currentServer, uploadConfig, state);
770
+ };
771
+ var deleteFromReplicationServers = async ({
772
+ servers,
773
+ dbKey,
774
+ deleteOptions = { type: "single" },
775
+ state,
776
+ preferredServerOrigin
777
+ }) => {
778
+ if (!servers.length) {
779
+ return { succeeded: [], failed: [] };
780
+ }
781
+ const preferredServer = typeof preferredServerOrigin === "string" && preferredServerOrigin.trim().length > 0 ? normalizeServerOrigin(preferredServerOrigin) : null;
782
+ const remainingServers = preferredServer ? servers.filter((server) => normalizeServerOrigin(server) !== preferredServer) : servers;
783
+ const succeeded = [];
784
+ const failed = [];
785
+ if (preferredServer) {
786
+ const ok = await noloDeleteRequest(preferredServer, dbKey, deleteOptions, state);
787
+ if (ok) {
788
+ succeeded.push(preferredServer);
789
+ } else {
790
+ failed.push(preferredServer);
791
+ }
792
+ }
793
+ if (remainingServers.length > 0) {
794
+ const results = await Promise.all(
795
+ remainingServers.map(async (server) => ({
796
+ server,
797
+ ok: await noloDeleteRequest(server, dbKey, deleteOptions, state)
798
+ }))
799
+ );
800
+ results.forEach(({ server, ok }) => {
801
+ if (ok) succeeded.push(server);
802
+ else failed.push(server);
803
+ });
804
+ }
805
+ return { succeeded, failed };
806
+ };
807
+ var scheduleDeleteReplication = ({
808
+ currentServer,
809
+ syncServers,
810
+ preferredServerOrigin,
811
+ dbKey,
812
+ deleteOptions,
813
+ state,
814
+ onResult,
815
+ onError
816
+ }) => {
817
+ const servers = resolveAuthorityReplicationServers({
818
+ currentServer,
819
+ syncServers,
820
+ preferredServerOrigin,
821
+ dbKey,
822
+ state
823
+ });
824
+ if (servers.length === 0) {
825
+ return [];
826
+ }
827
+ void Promise.resolve().then(
828
+ () => deleteFromReplicationServers({
829
+ servers,
830
+ dbKey,
831
+ deleteOptions,
832
+ state,
833
+ preferredServerOrigin
834
+ })
835
+ ).then((result) => {
836
+ onResult?.(result);
837
+ }).catch((error) => {
838
+ onError?.(error);
839
+ });
840
+ return servers;
841
+ };
842
+
843
+ export {
844
+ selectRuntimeSnapshot,
845
+ selectRuntimeCurrentServer,
846
+ getRuntimeServerContext,
847
+ parseOwnerUserIdFromDbKey,
848
+ DEVICE_LOCAL_OWNER_ID,
849
+ isDeviceLocalOwnerId,
850
+ resolveEffectiveSpaceActorId,
851
+ isDeviceLocalSpaceMembership,
852
+ isDeviceLocalSpaceBody,
853
+ resolveRecordOwnerUserId,
854
+ resolveRecordAuthority,
855
+ beginWriteAck,
856
+ partitionReadServers,
857
+ compareRemoteRecordsByComparableTime,
858
+ pickBestSettledRemoteRecord,
859
+ shouldReplaceLocalWithRemoteRecord,
860
+ shouldReplicateLocalRecord,
861
+ planAuthorityReadServers,
862
+ resolveReplicationServers,
863
+ resolveAuthorityReplicationServers,
864
+ scheduleWriteReplication,
865
+ resolveUploadReplicationServers,
866
+ scheduleExistingRecordReplication,
867
+ scheduleConfiguredPatchReplication,
868
+ scheduleUploadReplication,
869
+ uploadToCurrentServer,
870
+ scheduleDeleteReplication
871
+ };