nolo-cli 0.264.0-alpha.2 → 0.266.0-alpha.1

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 (538) hide show
  1. package/{chunk-LXP53WGF.js → chunk-05wkntba.js} +44 -40
  2. package/{chunk-XFYFMTOM.js → chunk-08ts2q1n.js} +9 -11
  3. package/{chromeCommands-MVEEIY4R.js → chunk-0a3m1n6h.js} +182 -238
  4. package/chunk-0gfvc7g8.js +13 -0
  5. package/{chunk-CF7PE763.js → chunk-0h0sncy4.js} +3 -4
  6. package/{chunk-3UH7SS4W.js → chunk-0nsxwrge.js} +232 -241
  7. package/chunk-0ra8cne4.js +11 -0
  8. package/{chunk-MRACVEPZ.js → chunk-0sgwk7am.js} +1 -3
  9. package/{chunk-PEXGRTTQ.js → chunk-0tsfn0dk.js} +44 -45
  10. package/{chunk-WOAZVUSN.js → chunk-0y8cbwzy.js} +26 -30
  11. package/chunk-12gz55kk.js +6 -0
  12. package/{chunk-GLKOYSRU.js → chunk-186gshgw.js} +3 -6
  13. package/chunk-19w4ss38.js +44 -0
  14. package/{chunk-RF576RYE.js → chunk-1cakzp6r.js} +23 -23
  15. package/chunk-1fbfwbzp.js +27 -0
  16. package/{chunk-4IVMDQBA.js → chunk-1fv9k8zt.js} +103 -68
  17. package/{chunk-Q5FJJ6XI.js → chunk-1js4cdzp.js} +11 -19
  18. package/{chunk-YECCIUYU.js → chunk-1nhx0er5.js} +63 -63
  19. package/chunk-1p152b7g.js +12 -0
  20. package/{chunk-HXEO5DNV.js → chunk-1ynbq3yr.js} +322 -353
  21. package/{chunk-6UBGXX2W.js → chunk-1zrg4h5n.js} +3 -4
  22. package/{chunk-Y5GCAMGP.js → chunk-2g6zsfq8.js} +1 -3
  23. package/chunk-2hekb0eh.js +17 -0
  24. package/chunk-2pj6qzq5.js +12 -0
  25. package/chunk-2tvd4jyp.js +226 -0
  26. package/chunk-2ygg7azv.js +846 -0
  27. package/chunk-33405wtv.js +50 -0
  28. package/chunk-34axejtd.js +30 -0
  29. package/{tableCommands-FCPDULSU.js → chunk-3700dvt3.js} +224 -276
  30. package/{pdf-KE3QI2V7.js → chunk-3j08t1nm.js} +12505 -10133
  31. package/chunk-3j9gq18v.js +111 -0
  32. package/{chunk-LYPJYBE5.js → chunk-3qfpcdkm.js} +486 -505
  33. package/{settingThunks-PNC7ZISV.js → chunk-3r2x7h64.js} +189 -272
  34. package/{agentGrantCommands-2VLLXGIU.js → chunk-3tbj5fxt.js} +61 -56
  35. package/chunk-40whhjj5.js +168 -0
  36. package/chunk-4301919y.js +7 -0
  37. package/chunk-43adz39e.js +77 -0
  38. package/{chunk-5ZUL4CUO.js → chunk-49v3zc4g.js} +1 -3
  39. package/chunk-4dd7mxkb.js +72 -0
  40. package/{chunk-BKP325XS.js → chunk-4hapfzpq.js} +66 -62
  41. package/chunk-4mm7dz0m.js +95 -0
  42. package/chunk-4pqxempz.js +440 -0
  43. package/chunk-4x9zf5pv.js +10 -0
  44. package/{chunk-CA7LGAHV.js → chunk-511q8qzv.js} +66 -57
  45. package/{chunk-U7OULUMF.js → chunk-53v9g0np.js} +49 -64
  46. package/chunk-572mg6q5.js +19 -0
  47. package/{chunk-QAW6BEWQ.js → chunk-57eyhmwr.js} +17173 -16165
  48. package/chunk-5hsr0zjm.js +156 -0
  49. package/chunk-5k883yyd.js +20 -0
  50. package/chunk-5m0wsee4.js +639 -0
  51. package/{memberThunks-NEZRAW5K.js → chunk-5r1sq2gt.js} +299 -373
  52. package/chunk-648rq4np.js +255 -0
  53. package/{chunk-IYRZKHA6.js → chunk-666yjw5c.js} +63 -86
  54. package/{chunk-4O22PGNQ.js → chunk-6cdcbmtp.js} +19 -19
  55. package/chunk-6dbyqcf7.js +59 -0
  56. package/{agentProviderCommands-2W3VXDLV.js → chunk-6e8mgp1x.js} +82 -105
  57. package/chunk-6n0pw7sx.js +44 -0
  58. package/chunk-6q1b7381.js +361 -0
  59. package/chunk-6sj756ry.js +23 -0
  60. package/{chunk-4UNN45DS.js → chunk-6t7a7zck.js} +14785 -14454
  61. package/chunk-6yarwtxh.js +776 -0
  62. package/chunk-708h542p.js +18 -0
  63. package/chunk-76f076t8.js +266 -0
  64. package/chunk-782rrrwv.js +523 -0
  65. package/{workloadLifecycle-P2SJVV3S.js → chunk-7gk330wp.js} +77 -84
  66. package/{chunk-EZKIRVLJ.js → chunk-7ks60vxy.js} +146 -128
  67. package/{chunk-FI4DPLR7.js → chunk-7mrqbxe8.js} +342 -228
  68. package/chunk-7sztayrd.js +169 -0
  69. package/chunk-7vgt2mxz.js +15 -0
  70. package/{localFirstLog-OIETGK66.js → chunk-7z8y4k6y.js} +0 -2
  71. package/{chunk-KDDXC2IH.js → chunk-82htft2m.js} +49 -11
  72. package/{updateDialogTitleAction-XOSLNRT3.js → chunk-88vrtxxg.js} +65 -137
  73. package/{chunk-LS5KAVFQ.js → chunk-8dtjbp79.js} +293 -229
  74. package/chunk-8fajbkaz.js +50 -0
  75. package/chunk-8m1ebxpw.js +65 -0
  76. package/{accountResolver-JYG5L7YP.js → chunk-8mgfeg0w.js} +37 -30
  77. package/{chunk-LPXBBC32.js → chunk-8myksy35.js} +156 -160
  78. package/{chunk-BMQ2MJUK.js → chunk-8nrj7dc7.js} +75 -66
  79. package/{commandRegistry-ENNFT77C.js → chunk-8t8x64ec.js} +228 -286
  80. package/chunk-8yj4pq79.js +458 -0
  81. package/{chunk-5MKPNTJP.js → chunk-8z6pepcx.js} +43 -48
  82. package/{chunk-UYQILGDR.js → chunk-90egc9vb.js} +122 -102
  83. package/{chunk-EODBQPRM.js → chunk-91q5dc5r.js} +10 -14
  84. package/{chunk-U6VC4MU4.js → chunk-96jtrqk1.js} +2 -4
  85. package/{chunk-H57T64RA.js → chunk-996j61av.js} +28 -31
  86. package/{chunk-Q6FKWH66.js → chunk-9cxgb9jy.js} +137 -243
  87. package/{chunk-2ZBPWX7N.js → chunk-9q1gbmet.js} +62 -104
  88. package/chunk-9qtjh73q.js +344 -0
  89. package/{chunk-SR57FDTX.js → chunk-9raka469.js} +72 -155
  90. package/{chunk-V6K5U4YE.js → chunk-9vh4v046.js} +32 -41
  91. package/{chunk-AGIM7IMJ.js → chunk-9yr1fy7j.js} +14 -49
  92. package/{chunk-FGFJUFPS.js → chunk-a16x0wt6.js} +11 -18
  93. package/chunk-a5b2rvzs.js +131 -0
  94. package/{chunk-7DPNBQSV.js → chunk-a7bz6nc3.js} +3 -4
  95. package/chunk-ac85azv9.js +29 -0
  96. package/{chunk-VXL2FZTP.js → chunk-ahhbkad4.js} +16 -20
  97. package/{chunk-37DGW762.js → chunk-anhksj2j.js} +16 -29
  98. package/{cliAuthorityBrokerServer-27C5YBYP.js → chunk-atvmx76t.js} +180 -186
  99. package/{chunk-E6A5NHDH.js → chunk-av2mzeqz.js} +16 -17
  100. package/chunk-avbwrb0z.js +614 -0
  101. package/chunk-avr6rqe5.js +544 -0
  102. package/{workContextQueryProjection-CACY5VFE.js → chunk-axx60d5a.js} +7 -7
  103. package/{chunk-EWQ3HGNZ.js → chunk-b00vzjkb.js} +30 -23
  104. package/chunk-b0m6ezxr.js +132 -0
  105. package/chunk-bbd5mgdt.js +47 -0
  106. package/chunk-bcecft0r.js +28 -0
  107. package/chunk-beyr4pyp.js +33 -0
  108. package/{chunk-BR3GT6MR.js → chunk-bge0cagn.js} +7 -18
  109. package/{offlineMarxistsAgentCommand-MFURGWHL.js → chunk-bh53zg3t.js} +33 -43
  110. package/chunk-bmx1cw89.js +37 -0
  111. package/chunk-br2195h4.js +22 -0
  112. package/chunk-bsqkwveq.js +56 -0
  113. package/{chunk-QAU6KM2U.js → chunk-c09s2z1m.js} +139 -98
  114. package/chunk-c235kypv.js +24636 -0
  115. package/{chunk-2JMYAH5O.js → chunk-c30j6pyh.js} +213 -256
  116. package/chunk-c3v6r6sq.js +29 -0
  117. package/{chunk-PDSXYHNI.js → chunk-c5z7qspt.js} +1177 -1196
  118. package/{chunk-GWB6AGME.js → chunk-c6jvz0mp.js} +34 -50
  119. package/{chunk-PRJ473FK.js → chunk-cd6h9qqs.js} +14 -12
  120. package/chunk-cdt0amyy.js +37 -0
  121. package/{chunk-2AJLG6PY.js → chunk-cfh6tfc3.js} +73 -86
  122. package/{chunk-WIVVNJUS.js → chunk-ch4ck1yz.js} +38 -68
  123. package/chunk-chtvrtp5.js +55 -0
  124. package/{chunk-EYLGAEB4.js → chunk-ckvz7abv.js} +170 -165
  125. package/{chunk-YZMNK53S.js → chunk-csf18m5w.js} +32 -25
  126. package/{chunk-C36L6ZID.js → chunk-cwnvf8dt.js} +2 -10
  127. package/chunk-cy7thb6n.js +19877 -0
  128. package/{dialogPortabilityCommands-YQJNB2KL.js → chunk-d61q9nah.js} +439 -487
  129. package/chunk-d6xdy0gp.js +142 -0
  130. package/{chunk-EBH4RFJ6.js → chunk-dh69vqbd.js} +6390 -6496
  131. package/{chunk-KJ4J2XQB.js → chunk-dj4ggbc6.js} +17 -19
  132. package/{chunk-LISC7BD4.js → chunk-djrrhbk3.js} +29 -37
  133. package/chunk-drqzzzvr.js +822 -0
  134. package/chunk-e1n7edjk.js +33 -0
  135. package/chunk-e3atr4hk.js +59 -0
  136. package/chunk-e9bn2aav.js +13 -0
  137. package/chunk-ed396rfq.js +87 -0
  138. package/chunk-eha8ggh6.js +10 -0
  139. package/{chunk-MALPQFGT.js → chunk-ek122zzt.js} +893 -948
  140. package/chunk-epnmvek4.js +22 -0
  141. package/{chunk-S25VJYXV.js → chunk-eqzvk3xm.js} +69 -80
  142. package/chunk-ex34n71b.js +2874 -0
  143. package/{chunk-56OAS5RZ.js → chunk-f3ad6q4h.js} +7 -11
  144. package/{chunk-3PVYUPXK.js → chunk-f8jepva1.js} +6 -7
  145. package/{chunk-GH34JXNV.js → chunk-f9yvy9t9.js} +114 -92
  146. package/chunk-fbdz4f0j.js +90 -0
  147. package/{chunk-J44TXB4J.js → chunk-fcsc2day.js} +216 -164
  148. package/chunk-fevdhnbh.js +19 -0
  149. package/chunk-fkrgqq8w.js +3300 -0
  150. package/{chunk-TSBJVMNW.js → chunk-fs3bvh2p.js} +42 -57
  151. package/chunk-fvwzyhah.js +134 -0
  152. package/chunk-g0mpxdp9.js +101 -0
  153. package/{chunk-LTQ6ECCF.js → chunk-g35f20d1.js} +450 -414
  154. package/{chunk-3L2WKC3W.js → chunk-g5fhtjqg.js} +13 -16
  155. package/{chunk-DBEOW57U.js → chunk-gcq01td7.js} +270 -227
  156. package/{chunk-ADMRXWXJ.js → chunk-ge97b11r.js} +121 -42
  157. package/chunk-ghjtgbkw.js +180 -0
  158. package/chunk-gkra36c1.js +16 -0
  159. package/chunk-gmz86t60.js +1000 -0
  160. package/{localDialogRead-GWGWSL5K.js → chunk-gszpesze.js} +5 -12
  161. package/chunk-gvsfec9m.js +16536 -0
  162. package/{chunk-QSJ3HFEF.js → chunk-h1hzmqph.js} +1 -3
  163. package/chunk-h30dg154.js +17 -0
  164. package/chunk-h3hkb7cw.js +241 -0
  165. package/chunk-h40py996.js +28 -0
  166. package/{chunk-47T3QP4V.js → chunk-h60gnewh.js} +112 -116
  167. package/{agentPullCommand-XEGOUYQT.js → chunk-hkwsv9xf.js} +33 -45
  168. package/chunk-hnyg0gwj.js +28 -0
  169. package/{chunk-KSV6T4AH.js → chunk-hqqqph5w.js} +12 -4
  170. package/{chunk-YQJEXXDK.js → chunk-hrngs1wy.js} +157 -246
  171. package/{chunk-LRLLWD4P.js → chunk-htf69s94.js} +14 -12
  172. package/chunk-j0yxesh3.js +83 -0
  173. package/{chunk-VF4K2QE6.js → chunk-j22t9g05.js} +3 -6
  174. package/{chunk-3R4AYHJR.js → chunk-j4a8m2zn.js} +5 -34
  175. package/chunk-j9p4jnwg.js +27 -0
  176. package/{chunk-R72QWIFO.js → chunk-jdycmfsm.js} +9 -9
  177. package/chunk-jdyvrne0.js +52 -0
  178. package/{spacePruneCommand-YKIEUIDQ.js → chunk-je0b66qf.js} +44 -62
  179. package/{chunk-HNMXYYJR.js → chunk-jec44fkj.js} +3 -4
  180. package/{chunk-526GLZJE.js → chunk-jf1ex00r.js} +107 -73
  181. package/chunk-jgqdec9b.js +31 -0
  182. package/{chunk-56GBUMO5.js → chunk-jkw9n4h5.js} +16 -25
  183. package/{chunk-7422ZLGL.js → chunk-jmnzdwjt.js} +867 -965
  184. package/chunk-jqq57s0a.js +58 -0
  185. package/{chunk-OKUSDVRS.js → chunk-jtkn5aj6.js} +27 -38
  186. package/chunk-jwvzn9r0.js +316 -0
  187. package/chunk-k1re0fc7.js +107 -0
  188. package/chunk-k2ep3rb2.js +103 -0
  189. package/{chunk-JEXVIMYZ.js → chunk-k6ycb24w.js} +5 -8
  190. package/{chunk-RI7SXDJW.js → chunk-kawvydbk.js} +383 -195
  191. package/chunk-kf2ghpzh.js +10 -0
  192. package/{chunk-S6FAHQDH.js → chunk-kgah9e46.js} +28 -59
  193. package/{chunk-T3MWVUBE.js → chunk-kjjepkvc.js} +71 -82
  194. package/chunk-kn4dgg4j.js +4113 -0
  195. package/{chunk-2LFYMWM3.js → chunk-kn5p91n8.js} +43 -53
  196. package/{chunk-MVOZ22RZ.js → chunk-kntqrbwc.js} +8 -12
  197. package/{chunk-I6YIA2TY.js → chunk-kq3vr7mx.js} +25 -20
  198. package/chunk-kz1x1d8n.js +15 -0
  199. package/{mcpLocalAuthorizeCommand-IKOFKY5U.js → chunk-m22e7tt2.js} +53 -71
  200. package/{chunk-ZNFJWEN4.js → chunk-m32rwr4d.js} +11 -8
  201. package/chunk-m39e9m18.js +93 -0
  202. package/{chunk-4D4QD7FT.js → chunk-m5518371.js} +64 -56
  203. package/{chunk-LHTXSC2E.js → chunk-mb5hnfyp.js} +9 -11
  204. package/chunk-mexet11v.js +11 -0
  205. package/chunk-mg2hgfgh.js +185 -0
  206. package/chunk-mmdhm4kx.js +10317 -0
  207. package/chunk-mz002yz8.js +2821 -0
  208. package/chunk-mzadqnyq.js +56 -0
  209. package/{chunk-VIDPVFP3.js → chunk-n3r1ebdm.js} +5 -6
  210. package/chunk-n438qea7.js +33 -0
  211. package/chunk-n5ffnhnb.js +93 -0
  212. package/chunk-nbvd87fy.js +9 -0
  213. package/{chunk-E36V7MPY.js → chunk-ndej7jc9.js} +53 -43
  214. package/{chunk-B767MA64.js → chunk-nen6rwe4.js} +62 -22
  215. package/chunk-nf06tr3v.js +16 -0
  216. package/chunk-ng8z355q.js +16 -0
  217. package/{chunk-4MEKE5D3.js → chunk-nhtxfv8k.js} +78 -63
  218. package/{runAgentClientLoop-2SFASHDS.js → chunk-nj62jscj.js} +132 -214
  219. package/{chunk-GBWGPTA7.js → chunk-nkryrkyp.js} +16 -19
  220. package/chunk-nmesxem8.js +197 -0
  221. package/{chunk-YR4J7RFS.js → chunk-nmq0qwbn.js} +117 -164
  222. package/chunk-nph8brvw.js +7 -0
  223. package/chunk-nr8fees9.js +10 -0
  224. package/{chunk-DFI7MVCQ.js → chunk-nvewvf7h.js} +1441 -1427
  225. package/{chunk-G7Y4GXTY.js → chunk-nyamhphs.js} +70 -79
  226. package/chunk-nz1c8tcg.js +111 -0
  227. package/{chunk-GPLUFN2E.js → chunk-nzc5yffh.js} +176 -217
  228. package/{chunk-G3SUCT4W.js → chunk-p1vg4bx8.js} +2 -4
  229. package/chunk-p3k3abe8.js +202 -0
  230. package/chunk-p4zy30q5.js +8 -0
  231. package/{chunk-ZJACPM5O.js → chunk-p6se1rx0.js} +102 -102
  232. package/chunk-p9dpshev.js +6968 -0
  233. package/chunk-pa42wxr0.js +116 -0
  234. package/{chunk-TA5QI4MM.js → chunk-paxthgqp.js} +56 -107
  235. package/{readlineWorkspace-ZH5FGDMI.js → chunk-pb35s8d9.js} +5395 -5786
  236. package/{chunk-XT6C2QZW.js → chunk-pbebzbcq.js} +8 -8
  237. package/chunk-pbx7e1mb.js +11 -0
  238. package/chunk-pe5czfn9.js +8 -0
  239. package/chunk-pextk1j4.js +62 -0
  240. package/chunk-pf5rywc6.js +575 -0
  241. package/chunk-pjfhd3fz.js +136 -0
  242. package/{chunk-ZCMAKAZM.js → chunk-pkhqb0fs.js} +118 -59
  243. package/chunk-pm5xb9jh.js +26 -0
  244. package/{chunk-Y3KGWZKF.js → chunk-ppdmmdkx.js} +110 -97
  245. package/chunk-pqp6y2hs.js +9 -0
  246. package/{chunk-QHEN7NZ7.js → chunk-ptz8fm2n.js} +12 -17
  247. package/{chunk-EUHMI5KG.js → chunk-pwqnvbt7.js} +65 -46
  248. package/chunk-pzr31nz7.js +12 -0
  249. package/{chunk-WWC7I6TA.js → chunk-q3cx89sw.js} +2 -4
  250. package/chunk-q5pe7be3.js +78 -0
  251. package/{chunk-ZHWTBHT3.js → chunk-q6zqbxp2.js} +418 -409
  252. package/chunk-q7r0e1p3.js +15 -0
  253. package/chunk-q8t2fecd.js +6 -0
  254. package/{chunk-2QAZCYOM.js → chunk-q94zx4d0.js} +721 -753
  255. package/{runtimeDoctorCommands-52MBG5JN.js → chunk-qarz1az1.js} +65 -85
  256. package/{chunk-4INJGWE3.js → chunk-qdcvr25b.js} +72 -53
  257. package/{streamAgentChatTurn-KOUWITHH.js → chunk-qxs27wfg.js} +1079 -1475
  258. package/{chunk-GIXWVN2W.js → chunk-r06ycjjr.js} +50 -47
  259. package/{chunk-63W5N6P3.js → chunk-r20jw5hb.js} +57 -38
  260. package/{chunk-I5BYFTYK.js → chunk-r7sfwdka.js} +1201 -1142
  261. package/{chunk-UMADT6B2.js → chunk-r9sp1yyb.js} +6 -8
  262. package/{handleSendMessageAction-FHGUFT2X.js → chunk-rbd2vgb3.js} +627 -757
  263. package/chunk-rc37js46.js +12 -0
  264. package/{chunk-5YI447UL.js → chunk-rmngk6r3.js} +67 -76
  265. package/chunk-rnhbnbrq.js +15 -0
  266. package/{chunk-WRHVVIGI.js → chunk-rsfnmrt5.js} +111 -131
  267. package/{chunk-YFSM2366.js → chunk-rvvn2rhj.js} +28 -22
  268. package/{chunk-4Y6CZ2N4.js → chunk-s0fpz7ht.js} +37 -33
  269. package/{chunk-VI4SWTUO.js → chunk-s1cqzb2r.js} +77 -65
  270. package/{chunk-6QDYSCPW.js → chunk-s8q81tda.js} +73 -65
  271. package/chunk-s9hy639e.js +6 -0
  272. package/{chunk-R5GO3YZP.js → chunk-s9vbwme8.js} +115 -106
  273. package/chunk-sger1m1b.js +20 -0
  274. package/chunk-spe6crvk.js +60 -0
  275. package/chunk-spwsrvh9.js +70 -0
  276. package/chunk-sr05zpk7.js +573 -0
  277. package/{chunk-M2EJHDJP.js → chunk-srncrd3f.js} +1 -12
  278. package/{chunk-QXHFIX7W.js → chunk-sry80bpx.js} +71 -53
  279. package/{chunk-PSCNXBYA.js → chunk-t6q69p83.js} +3 -4
  280. package/{chunk-UAD2WT54.js → chunk-t714r4q0.js} +9 -28
  281. package/chunk-t7vbraqe.js +42 -0
  282. package/{chunk-CVMMWN6P.js → chunk-td7653rr.js} +10 -20
  283. package/{chunk-3BQDF4QB.js → chunk-tmytcetz.js} +17 -21
  284. package/{chunk-AMWMV56B.js → chunk-tta4prwg.js} +16 -15
  285. package/chunk-tvh8azgq.js +4829 -0
  286. package/{chunk-ID4G2MAR.js → chunk-v08kbfm8.js} +10 -11
  287. package/{chunk-OKPOQGQJ.js → chunk-v1x702q8.js} +801 -852
  288. package/{chunk-KHCLMKZZ.js → chunk-v39fea91.js} +576 -247
  289. package/{chunk-OW765XBU.js → chunk-vejtd8p2.js} +3 -4
  290. package/chunk-vep7zkha.js +368 -0
  291. package/chunk-vfwn1k7n.js +142 -0
  292. package/chunk-vg68vxhx.js +20 -0
  293. package/chunk-vgcqgnsm.js +31 -0
  294. package/{chunk-NF64D32W.js → chunk-vnzyjdea.js} +1 -3
  295. package/{chunk-ZCLSM5AK.js → chunk-vqgtw1px.js} +800 -717
  296. package/chunk-vv1gr5xz.js +76 -0
  297. package/{spaceCommands-Z2CTQD6G.js → chunk-w1qeadpq.js} +176 -242
  298. package/chunk-w468ez1p.js +13 -0
  299. package/chunk-w49s0t79.js +14 -0
  300. package/{mcpLocalManageCommands-KUDZQRM4.js → chunk-w58zhfbn.js} +91 -93
  301. package/chunk-w5b74aq6.js +11 -0
  302. package/chunk-w7y41qyw.js +117 -0
  303. package/chunk-w820gg1w.js +4165 -0
  304. package/{chunk-DBJAJ4UD.js → chunk-wdsmaqmt.js} +399 -453
  305. package/{chunk-3EUW3WEO.js → chunk-wfvvnmmj.js} +1 -3
  306. package/{chunk-QY4NZCDA.js → chunk-wkr04bhk.js} +432 -651
  307. package/{chunk-KUG52IAP.js → chunk-ws402twv.js} +1 -3
  308. package/chunk-wzwh311q.js +164 -0
  309. package/{runtimeModeArgs-X7DL7PUN.js → chunk-x5vtgvwn.js} +6 -5
  310. package/{agentMachineCommands-COJD2KPZ.js → chunk-x8h2csmq.js} +152 -195
  311. package/{chunk-BAZCS5XG.js → chunk-x9zfjnrc.js} +59 -47
  312. package/{chunk-WTIJKWCI.js → chunk-xcarc2rf.js} +50 -56
  313. package/chunk-xf33gz0a.js +8 -0
  314. package/{chunk-PVFYPUIM.js → chunk-y7b3gwx1.js} +78 -71
  315. package/{memoryCommands-SVLAVFCV.js → chunk-y7sphmnh.js} +119 -95
  316. package/{agentListCommands-436FHOIT.js → chunk-ycvaafhc.js} +260 -374
  317. package/chunk-yd7zprb0.js +9 -0
  318. package/chunk-yfz3d27k.js +40 -0
  319. package/{chunk-MKR6KDD3.js → chunk-ykv9g3m4.js} +141 -125
  320. package/chunk-ystjgb9e.js +544 -0
  321. package/chunk-yysxn7ep.js +12 -0
  322. package/{chunk-AL3TYDIF.js → chunk-z17eyawk.js} +18 -16
  323. package/{machineCommands-RVB5OG2X.js → chunk-z17q416p.js} +442 -563
  324. package/chunk-z1n98pcf.js +12 -0
  325. package/{dialogTraceCommand-HWXGIGZX.js → chunk-z566jx5r.js} +292 -397
  326. package/chunk-zjxd6942.js +6 -0
  327. package/{versionChangeNotice-RFABJGJE.js → chunk-zk11x9y5.js} +7 -9
  328. package/{chunk-TEFD5E2D.js → chunk-zt73yc33.js} +48 -51
  329. package/chunk-zvs2fra1.js +5 -0
  330. package/{chunk-SVFFKLMR.js → chunk-zwee84rh.js} +117 -141
  331. package/chunk-zxgfqv72.js +8 -0
  332. package/index.js +53 -69
  333. package/package.json +4 -4
  334. package/_executeModel-YQNZNR2Y.js +0 -341
  335. package/action-UK3HXGXF.js +0 -30
  336. package/addContentAction-CAKFVBDM.js +0 -38
  337. package/addDialogAgentAction-KLJ2YWWM.js +0 -77
  338. package/agentDeleteCommand-S5FVPYKT.js +0 -523
  339. package/agentEmailCommands-ZEFMGVKM.js +0 -742
  340. package/agentRecordCommands-JZ35AC5A.js +0 -211
  341. package/agentRun-UIO43TUG.js +0 -251
  342. package/agentRunCommand-ATLKKD6O.js +0 -249
  343. package/agentRunControl-U2MV74WR.js +0 -211
  344. package/agentRuntimeLocal-P4MMGIR6.js +0 -189
  345. package/agentSlice-HHNKNNYM.js +0 -52
  346. package/appConfigCommands-W4JQHMOJ.js +0 -417
  347. package/appDeleteCommands-IXR47IAV.js +0 -183
  348. package/appDeployCommands-LB6DHDF4.js +0 -232
  349. package/appDeployStatusCommands-UQ6MJL6D.js +0 -204
  350. package/appGetCommands-M5JCTDDQ.js +0 -185
  351. package/appListCommands-TE3ZHE3I.js +0 -186
  352. package/appMigrateCommands-FOXH6R4B.js +0 -230
  353. package/appSourceCommands-3ACYB6I7.js +0 -279
  354. package/authCommand-I5OBJP5S.js +0 -66
  355. package/authCommands-I6KCGOCN.js +0 -54
  356. package/builtinSkillRegistry-MIXYSZUU.js +0 -35
  357. package/chromeOpsCommands-IZRCYDSW.js +0 -579
  358. package/chunk-24BICQPB.js +0 -25
  359. package/chunk-2E4BYAUE.js +0 -69
  360. package/chunk-2O72G3U2.js +0 -17157
  361. package/chunk-2OROOEOQ.js +0 -229
  362. package/chunk-2R6M34JP.js +0 -27225
  363. package/chunk-2SXN7LAY.js +0 -15
  364. package/chunk-35JIFLIG.js +0 -30
  365. package/chunk-3VXVE2LF.js +0 -12
  366. package/chunk-4DBTBNTX.js +0 -477
  367. package/chunk-4JH2UMJR.js +0 -40
  368. package/chunk-4RUQ2PFX.js +0 -432
  369. package/chunk-4SN6J65J.js +0 -38
  370. package/chunk-5MMAK75Q.js +0 -15
  371. package/chunk-6NYQHXMV.js +0 -1737
  372. package/chunk-6R4IY46J.js +0 -14
  373. package/chunk-7E6YXSFZ.js +0 -441
  374. package/chunk-7K4J76JQ.js +0 -917
  375. package/chunk-7LR2IFUH.js +0 -100
  376. package/chunk-AETZ7AD6.js +0 -274
  377. package/chunk-ATNTHIZI.js +0 -13
  378. package/chunk-BPB3T5EU.js +0 -791
  379. package/chunk-BV3FLP2L.js +0 -133
  380. package/chunk-BVYHE6QD.js +0 -110
  381. package/chunk-BWJLEN6X.js +0 -1388
  382. package/chunk-CHOZJMJS.js +0 -78
  383. package/chunk-D2LTQAGN.js +0 -464
  384. package/chunk-DALXH7BG.js +0 -3392
  385. package/chunk-DBCWXGOC.js +0 -15210
  386. package/chunk-DLXL4NSL.js +0 -1179
  387. package/chunk-DSBRIUX5.js +0 -23
  388. package/chunk-DWLEOOGR.js +0 -8
  389. package/chunk-E2KZNP6C.js +0 -13
  390. package/chunk-E5JV4DCB.js +0 -272
  391. package/chunk-EUGTFFO6.js +0 -42
  392. package/chunk-FBNVJ2TO.js +0 -294
  393. package/chunk-FGXG6OLW.js +0 -34
  394. package/chunk-G22P2J7O.js +0 -1775
  395. package/chunk-HEVRQGGH.js +0 -106
  396. package/chunk-HHXF57CL.js +0 -180
  397. package/chunk-HI5RS2O4.js +0 -2109
  398. package/chunk-HJTI7RZV.js +0 -94
  399. package/chunk-HRWRIPTB.js +0 -531
  400. package/chunk-HYCVEESH.js +0 -2824
  401. package/chunk-I42VC5KR.js +0 -15
  402. package/chunk-IB5AR52X.js +0 -15
  403. package/chunk-IIRJ4P4I.js +0 -24
  404. package/chunk-IT3ZZRJE.js +0 -12
  405. package/chunk-IV6VUVLJ.js +0 -88
  406. package/chunk-J42X32PV.js +0 -472
  407. package/chunk-JDMWYVUF.js +0 -449
  408. package/chunk-JKVOKKMQ.js +0 -53
  409. package/chunk-JRTNUU5Z.js +0 -54
  410. package/chunk-K7HLFORE.js +0 -226
  411. package/chunk-KGBASAB5.js +0 -74
  412. package/chunk-KGKTN2NX.js +0 -25
  413. package/chunk-KX6YBIHG.js +0 -8
  414. package/chunk-KYHNSSL2.js +0 -62
  415. package/chunk-KZO2MTVM.js +0 -140
  416. package/chunk-LKZPX6YH.js +0 -0
  417. package/chunk-LLP2NDED.js +0 -201
  418. package/chunk-LOFRSJX2.js +0 -47
  419. package/chunk-M75RM77T.js +0 -3970
  420. package/chunk-MDAYRIP7.js +0 -1889
  421. package/chunk-MI6HRMCK.js +0 -25
  422. package/chunk-MTNQNLSE.js +0 -1029
  423. package/chunk-NH4PUEWK.js +0 -762
  424. package/chunk-NHLLXINQ.js +0 -8
  425. package/chunk-NTUNHTJV.js +0 -40
  426. package/chunk-OJKUU3LP.js +0 -67
  427. package/chunk-OQH3TAB7.js +0 -299
  428. package/chunk-P62DHV4F.js +0 -443
  429. package/chunk-PHIERFHT.js +0 -574
  430. package/chunk-PKDFU6MY.js +0 -102
  431. package/chunk-PL5RKESU.js +0 -40
  432. package/chunk-PSJJBBWV.js +0 -42
  433. package/chunk-QKM55LP2.js +0 -739
  434. package/chunk-QQ56R7KS.js +0 -88
  435. package/chunk-QYPE3TS3.js +0 -43
  436. package/chunk-REAE2SZK.js +0 -62
  437. package/chunk-RGQ4UUWZ.js +0 -208
  438. package/chunk-RIRFHJTW.js +0 -353
  439. package/chunk-RYMLMTPZ.js +0 -547
  440. package/chunk-SSGTV4FC.js +0 -303
  441. package/chunk-SVKWZ3EG.js +0 -607
  442. package/chunk-T7KODHYS.js +0 -317
  443. package/chunk-TGVVE5BA.js +0 -3085
  444. package/chunk-TKLBBR7P.js +0 -779
  445. package/chunk-TZXPT53C.js +0 -8
  446. package/chunk-U67V476Y.js +0 -35
  447. package/chunk-UEILX4EV.js +0 -15
  448. package/chunk-VIWDGTDA.js +0 -8
  449. package/chunk-VXUQWCEZ.js +0 -138
  450. package/chunk-W5GKF5ZW.js +0 -32
  451. package/chunk-WDWZPASX.js +0 -29
  452. package/chunk-WX266G2C.js +0 -9594
  453. package/chunk-YCITCYSJ.js +0 -356
  454. package/chunk-Z3KTXWWB.js +0 -76
  455. package/chunk-ZC3CMUKU.js +0 -322
  456. package/chunk-ZSZBHRLP.js +0 -1710
  457. package/chunk-ZV7ZY46L.js +0 -1343
  458. package/cliAgentConfigHelpers-WB2S7PDO.js +0 -47
  459. package/cliAuthorityBrokerClient-3SKOA7OZ.js +0 -23
  460. package/cliAuthorityBrokerProcess-BMBVXPKU.js +0 -24
  461. package/cliAuthorityStoreDriver-6FE3BJNB.js +0 -20
  462. package/cliEnvHelpers-7V5ZWUJA.js +0 -34
  463. package/cliExecutor-N3445G2Z.js +0 -45
  464. package/cliLocalAgentRecordReader-QKKRK53P.js +0 -113
  465. package/cloudAutomationCommands-S52NKCLL.js +0 -310
  466. package/contentThunks-ERA42OXW.js +0 -100
  467. package/cooldownCommands-ZFDAL4MR.js +0 -79
  468. package/createAgentAutomationAction-DMD2VDPI.js +0 -173
  469. package/createDialogAction-3SPOJQAK.js +0 -87
  470. package/createPageAction-AVXUMZVT.js +0 -91
  471. package/cursorProvider-2RACMEMF.js +0 -6123
  472. package/db-LTHLW7QA.js +0 -178
  473. package/dbSlice-WNUHTF4C.js +0 -76
  474. package/deleteDbKey-KV6MYBAI.js +0 -87
  475. package/desktopFolderProjects-4POAMVJN.js +0 -45
  476. package/dialogCommands-4MOLJW4G.js +0 -165
  477. package/dialogMessageRecord-2HJTEXQX.js +0 -7
  478. package/dialogNotifyCommand-YL2GFKLO.js +0 -45
  479. package/dialogSlice-Q7H2YVNO.js +0 -200
  480. package/dialogUsageCommand-IO2BQKL2.js +0 -31
  481. package/docCreateCommands-OYLRBK2M.js +0 -255
  482. package/docDeleteCommands-3NF6QPJU.js +0 -226
  483. package/docReadCommands-CBAERJAP.js +0 -184
  484. package/docStore-GWPFDV6Y.js +0 -89
  485. package/docUpdateCommands-BAMCGX6F.js +0 -326
  486. package/ebookDownloaderAgentCommand-NOIZ6U7Y.js +0 -675
  487. package/fetchMessages-P7FSCSXV.js +0 -19
  488. package/getPricing-KNXVEIUI.js +0 -40
  489. package/hostCredentialCreate-2VEYBXJV.js +0 -402
  490. package/i18n-SAK6DDY4.js +0 -51
  491. package/keys-FXEGMKSG.js +0 -183
  492. package/legacyMigration-TF4SYJCZ.js +0 -19
  493. package/levelAuthorityStore-L5SVDM5O.js +0 -10
  494. package/localAutomationCommands-XSK7SM7I.js +0 -199
  495. package/localAutomationRuntime-5WBO7HGQ.js +0 -61
  496. package/localRecall-BDYKXB46.js +0 -17
  497. package/localRuntimeAdapter-Y6H6XRIH.js +0 -310
  498. package/localRuntimeAuthority-Q5C2KWGF.js +0 -45
  499. package/localRuntimeDb-MM3DINZM.js +0 -12
  500. package/machineInfo-HNPJHQFU.js +0 -14
  501. package/machineWsRunDispatch-Y5SJGCEE.js +0 -228
  502. package/models-TOXYINNM.js +0 -10
  503. package/oauthTokenStore-RUYNYALS.js +0 -24
  504. package/overlay-JA3SPVUS.js +0 -15
  505. package/parityCommands-5OCBPVES.js +0 -613
  506. package/processSpawn-6GEO77KV.js +0 -11
  507. package/profileConfig-KOWK4HOG.js +0 -49
  508. package/projectArchive-WE3VVPZ2.js +0 -132
  509. package/providerPresetApply-YCVSP2WX.js +0 -235
  510. package/providerRegistry-26PAUYH2.js +0 -24
  511. package/read-D4WYJQJQ.js +0 -32
  512. package/readDocTool-3S3OQFOH.js +0 -22
  513. package/rememberExplicit-ZPI6KK5M.js +0 -16
  514. package/remove-AHRMUDMH.js +0 -32
  515. package/removeDialogAgentAction-AALRBFSA.js +0 -81
  516. package/secretCommands-2PSS3QNZ.js +0 -24
  517. package/setDialogExtraReferencesAction-SLHQ3GYL.js +0 -39
  518. package/setPrimaryDialogAgentAction-XKCSGJ7M.js +0 -96
  519. package/skillDiscovery-IUEZZG2B.js +0 -29
  520. package/skillSummaryMarker-62UW7HI7.js +0 -9
  521. package/slateToRenderMarkdown-R3X74MCX.js +0 -7
  522. package/slateUtils-ESQAJ6RN.js +0 -19
  523. package/store-WSAVTR32.js +0 -50
  524. package/switchDialogAgentAction-YJIWQGIR.js +0 -70
  525. package/tombstones-FQQMEDOW.js +0 -32
  526. package/toolApiClient-FVXTIIEN.js +0 -42
  527. package/tools-WN4AVSNS.js +0 -147
  528. package/tuiRestart-LU2BDLAW.js +0 -50
  529. package/tuiSummaryLlmCaller-Z2ZVBIGN.js +0 -53
  530. package/updateCommands-4QP7WJLA.js +0 -63
  531. package/usageCommand-AZX7D3LB.js +0 -31
  532. package/usageRebuildCommand-XV5QQCHK.js +0 -623
  533. package/userDataMerge-HT2ZVHBJ.js +0 -13
  534. package/windowsSelfUpdate-5OFKSW6Y.js +0 -14
  535. package/workContext-ZAW6VXT7.js +0 -18
  536. package/workContextAccess-VU5I4LKZ.js +0 -11
  537. package/workContextWriteNotice-YCSSMHN4.js +0 -7
  538. /package/{chunk-BYXBJQAS.js → chunk-0bcc25vg.js} +0 -0
package/chunk-TGVVE5BA.js DELETED
@@ -1,3085 +0,0 @@
1
- import {
2
- getAllMemberSpaces,
3
- getCurrentSpaceId,
4
- getCurrentSpaceIdRaw,
5
- isRemoteAccountSpace,
6
- mutateDbOps,
7
- spItemKey,
8
- syncLocalSpaceEntityCache,
9
- updateCurrentSpaceIfMatch
10
- } from "./chunk-JDMWYVUF.js";
11
- import {
12
- deleteDialog,
13
- runtime_default,
14
- toast
15
- } from "./chunk-DBCWXGOC.js";
16
- import {
17
- isSystemAdmin
18
- } from "./chunk-IB5AR52X.js";
19
- import {
20
- createPlainAsyncThunk
21
- } from "./chunk-KZO2MTVM.js";
22
- import {
23
- UNCATEGORIZED_ID,
24
- addContentAction,
25
- canManageSpaceContent,
26
- checkSpaceMembership,
27
- loadSpaceContentOrThrow,
28
- localSpaceAuthorityPatchStamp,
29
- notifyUserDataUpdated,
30
- patchIndividualContentRecord,
31
- readContentRecordForSpaceSync,
32
- syncContentRecordSpaceId
33
- } from "./chunk-E5JV4DCB.js";
34
- import {
35
- createSpaceKey,
36
- normalizeSpaceId
37
- } from "./chunk-UAD2WT54.js";
38
- import {
39
- formatLocalIso
40
- } from "./chunk-PL5RKESU.js";
41
- import {
42
- patch,
43
- protectedSyncStateKey,
44
- read,
45
- readAndWait,
46
- remove,
47
- unwrapDbResult,
48
- uploadFileAction,
49
- upsertSSREntity,
50
- write
51
- } from "./chunk-6NYQHXMV.js";
52
- import {
53
- resolveFileCategory
54
- } from "./chunk-3PVYUPXK.js";
55
- import {
56
- emitUserDataUpdated
57
- } from "./chunk-T7KODHYS.js";
58
- import {
59
- DEVICE_LOCAL_OWNER_ID,
60
- getRuntimeServerContext,
61
- isDeviceLocalSpaceBody,
62
- resolveReplicationServers,
63
- scheduleDeleteReplication,
64
- scheduleWriteReplication
65
- } from "./chunk-MTNQNLSE.js";
66
- import {
67
- require_react,
68
- selectIdentityUserId
69
- } from "./chunk-HI5RS2O4.js";
70
- import {
71
- getIsDesktopApp
72
- } from "./chunk-K7HLFORE.js";
73
- import {
74
- createClientLogger
75
- } from "./chunk-QQ56R7KS.js";
76
- import {
77
- asRecordOrEmpty
78
- } from "./chunk-KX6YBIHG.js";
79
- import {
80
- isAbortError
81
- } from "./chunk-7DPNBQSV.js";
82
- import {
83
- buildTombstoneRecord
84
- } from "./chunk-BV3FLP2L.js";
85
- import {
86
- extractUserId
87
- } from "./chunk-M2EJHDJP.js";
88
- import {
89
- isRecord
90
- } from "./chunk-KUG52IAP.js";
91
- import {
92
- SEPARATOR,
93
- createKey,
94
- fileKey,
95
- isAgentKey,
96
- isPageKey,
97
- metaKey,
98
- rowKey,
99
- splitKey
100
- } from "./chunk-DLXL4NSL.js";
101
- import {
102
- ulid
103
- } from "./chunk-OJKUU3LP.js";
104
- import {
105
- asTrimmedNonEmptyStringArray
106
- } from "./chunk-I42VC5KR.js";
107
- import {
108
- asTrimmedString
109
- } from "./chunk-3EUW3WEO.js";
110
- import {
111
- asOptionalFiniteNumber
112
- } from "./chunk-WWC7I6TA.js";
113
- import {
114
- asOptionalPositiveFiniteNumber
115
- } from "./chunk-U6VC4MU4.js";
116
- import {
117
- asOptionalTrimmedString
118
- } from "./chunk-G3SUCT4W.js";
119
- import {
120
- __toESM
121
- } from "./chunk-U67V476Y.js";
122
-
123
- // packages/render/table/tableStore.ts
124
- var import_react = __toESM(require_react(), 1);
125
- import { ulid as ulid3 } from "ulid";
126
-
127
- // packages/core/logger.ts
128
- import pino from "pino";
129
- var logger = pino({
130
- level: process.env.NODE_ENV === "production" ? "info" : "debug"
131
- });
132
-
133
- // packages/render/table/fetchAndCacheTableRows.ts
134
- var TABLE_ROWS_FETCH_TIMEOUT_MS = 5e3;
135
- var getRowTimestamp = (row) => {
136
- if (!row || typeof row !== "object") return 0;
137
- return asOptionalPositiveFiniteNumber(Date.parse(row.updatedAt ?? "")) ?? asOptionalPositiveFiniteNumber(Date.parse(row.createdAt ?? "")) ?? 0;
138
- };
139
- var shouldReplaceMergedRow = (nextRow, currentRow) => {
140
- const nextTs = getRowTimestamp(nextRow);
141
- const currentTs = getRowTimestamp(currentRow);
142
- if (nextTs !== currentTs) return nextTs > currentTs;
143
- return Boolean(nextRow?.deletedAt) && !currentRow?.deletedAt;
144
- };
145
- var mergeTableRows = (...rowLists) => {
146
- const merged = /* @__PURE__ */ new Map();
147
- for (const rowList of rowLists) {
148
- for (const row of rowList) {
149
- const dbKey = row?.dbKey;
150
- if (!dbKey) continue;
151
- const existing = merged.get(dbKey);
152
- if (!existing || shouldReplaceMergedRow(row, existing)) {
153
- merged.set(dbKey, row);
154
- }
155
- }
156
- }
157
- return Array.from(merged.values());
158
- };
159
- var TABLE_SYNC_ENVELOPE = "table-sync-v1";
160
- var MAX_TABLE_SYNC_PAGES = 100;
161
- var getLatestTableMeta = (snapshots) => {
162
- let latestMeta = null;
163
- for (const snapshot of snapshots) {
164
- const tableMeta = snapshot.tableMeta;
165
- if (!tableMeta || typeof tableMeta !== "object") continue;
166
- if (!latestMeta || shouldReplaceMergedRow(tableMeta, latestMeta)) {
167
- latestMeta = tableMeta;
168
- }
169
- }
170
- return latestMeta;
171
- };
172
- var loadLocalTableRows = async (db, tenantId, tableId) => {
173
- if (!db || typeof db.iterator !== "function") {
174
- return [];
175
- }
176
- const rows = [];
177
- const { gte, lte } = rowKey.range(tenantId, tableId);
178
- try {
179
- for await (const [, value] of db.iterator({ gte, lte })) {
180
- if (value?.type === "table_row" /* TABLE_ROW */) {
181
- rows.push(value);
182
- }
183
- }
184
- } catch {
185
- return [];
186
- }
187
- return rows;
188
- };
189
- var fetchTableRowsPage = async (server, tenantId, tableId, headers, fetchImpl, cursor, externalSignal) => {
190
- if (externalSignal?.aborted) {
191
- throw new Error(`\u52A0\u8F7D\u8868 ${tableId} \u884C\u5DF2\u53D6\u6D88`);
192
- }
193
- const controller = new AbortController();
194
- let timedOut = false;
195
- const onExternalAbort = () => controller.abort();
196
- externalSignal?.addEventListener("abort", onExternalAbort, { once: true });
197
- const timeoutId = setTimeout(() => {
198
- timedOut = true;
199
- controller.abort();
200
- }, TABLE_ROWS_FETCH_TIMEOUT_MS);
201
- try {
202
- const res = await fetchImpl(`${server}/rpc/listTableRows`, {
203
- method: "POST",
204
- headers,
205
- credentials: "include",
206
- body: JSON.stringify({
207
- tenantId,
208
- tableId,
209
- includeDeleted: true,
210
- envelope: TABLE_SYNC_ENVELOPE,
211
- ...cursor ? { cursor } : {}
212
- }),
213
- signal: controller.signal
214
- });
215
- if (!res.ok) {
216
- let msg = `\u52A0\u8F7D\u8868 ${tableId} \u884C\u5931\u8D25\uFF08${res.status}\uFF09`;
217
- try {
218
- const err2 = await res.json();
219
- if (err2 && typeof err2.message === "string") {
220
- msg = err2.message;
221
- }
222
- } catch {
223
- }
224
- throw new Error(msg);
225
- }
226
- const data = await res.json();
227
- if (Array.isArray(data)) {
228
- return {
229
- rows: data,
230
- deletedRows: [],
231
- tableMeta: null,
232
- complete: false
233
- };
234
- }
235
- if (!data || typeof data !== "object" || !Array.isArray(data.rows)) {
236
- throw new Error("\u670D\u52A1\u5668\u8FD4\u56DE\u683C\u5F0F\u9519\u8BEF\uFF1A\u9884\u671F\u4E3A\u6570\u7EC4");
237
- }
238
- const nextCursor = typeof data.nextCursor === "string" && data.nextCursor.length > 0 ? data.nextCursor : void 0;
239
- return {
240
- rows: data.rows,
241
- deletedRows: Array.isArray(data.deletedRows) ? data.deletedRows : [],
242
- tableMeta: data.tableMeta ?? null,
243
- complete: data.complete === true && !nextCursor,
244
- snapshotConsistent: data.snapshotConsistent === true && !nextCursor,
245
- ...nextCursor ? { nextCursor } : {}
246
- };
247
- } catch (err2) {
248
- if (isAbortError(err2)) {
249
- if (externalSignal?.aborted && !timedOut) {
250
- throw new Error(`\u52A0\u8F7D\u8868 ${tableId} \u884C\u5DF2\u53D6\u6D88`);
251
- }
252
- throw new Error(
253
- `\u52A0\u8F7D\u8868 ${tableId} \u884C\u8D85\u65F6\uFF1A${server} \u5728 ${TABLE_ROWS_FETCH_TIMEOUT_MS / 1e3}s \u5185\u65E0\u54CD\u5E94`
254
- );
255
- }
256
- throw err2;
257
- } finally {
258
- clearTimeout(timeoutId);
259
- externalSignal?.removeEventListener("abort", onExternalAbort);
260
- }
261
- };
262
- var fetchTableRowsFromServer = async (server, tenantId, tableId, headers, fetchImpl = fetch, externalSignal) => {
263
- const expectedPrefix = rowKey.single(tenantId, tableId, "");
264
- const allRows = [];
265
- const allDeletedRows = [];
266
- const seenCursors = /* @__PURE__ */ new Set();
267
- let latestTableMeta = null;
268
- let cursor;
269
- for (let page = 0; page < MAX_TABLE_SYNC_PAGES; page++) {
270
- const pageResult = await fetchTableRowsPage(
271
- server,
272
- tenantId,
273
- tableId,
274
- headers,
275
- fetchImpl,
276
- cursor,
277
- externalSignal
278
- );
279
- allRows.push(...pageResult.rows);
280
- allDeletedRows.push(...pageResult.deletedRows);
281
- if (pageResult.tableMeta) {
282
- latestTableMeta = pageResult.tableMeta;
283
- }
284
- if (pageResult.complete || !pageResult.nextCursor) {
285
- return {
286
- rows: allRows,
287
- deletedRows: allDeletedRows,
288
- tableMeta: latestTableMeta,
289
- complete: pageResult.complete && !pageResult.nextCursor,
290
- // Multi-page traversal without explicit server snapshot token is NEVER a consistent point-in-time snapshot (C1).
291
- snapshotConsistent: page === 0 && pageResult.snapshotConsistent === true && !pageResult.nextCursor
292
- };
293
- }
294
- const nextCursor = pageResult.nextCursor;
295
- if (!nextCursor.startsWith(expectedPrefix) || nextCursor.length <= expectedPrefix.length || seenCursors.has(nextCursor) || cursor !== void 0 && nextCursor <= cursor) {
296
- throw new Error(`\u52A0\u8F7D\u8868 ${tableId} \u884C\u5206\u9875\u6E38\u6807\u5F02\u5E38\uFF1A\u6E38\u6807\u8D8A\u754C\u6216\u672A\u524D\u8FDB`);
297
- }
298
- seenCursors.add(nextCursor);
299
- cursor = nextCursor;
300
- }
301
- return {
302
- rows: allRows,
303
- deletedRows: allDeletedRows,
304
- tableMeta: latestTableMeta,
305
- complete: false
306
- };
307
- };
308
- async function hasPendingRowSyncState(db, actorId, rowDbKey) {
309
- if (!db || typeof db.get !== "function" || !actorId) return false;
310
- try {
311
- const state3 = await db.get(protectedSyncStateKey(actorId, rowDbKey));
312
- if (!state3 || typeof state3 !== "object") return false;
313
- return Array.isArray(state3.outbox) && state3.outbox.length > 0 || state3.workingCopy !== null;
314
- } catch {
315
- return false;
316
- }
317
- }
318
- var cacheMergedTableRows = async (db, mergedRows, actorId) => {
319
- if (!db) return;
320
- await Promise.all(
321
- mergedRows.map(async (mergedRow) => {
322
- if (!mergedRow?.dbKey) return;
323
- try {
324
- if (await hasPendingRowSyncState(db, actorId, mergedRow.dbKey)) {
325
- return;
326
- }
327
- const localRow = await db.get(mergedRow.dbKey).catch(() => null);
328
- if (!localRow) {
329
- await db.put(mergedRow.dbKey, mergedRow);
330
- return;
331
- }
332
- const serverTs = new Date(
333
- mergedRow.updatedAt ?? mergedRow.createdAt ?? 0
334
- ).getTime();
335
- const localTs = new Date(
336
- localRow.updatedAt ?? localRow.createdAt ?? 0
337
- ).getTime();
338
- const shouldOverwrite = serverTs > localTs || serverTs === localTs && Boolean(mergedRow.deletedAt) && !Boolean(localRow.deletedAt);
339
- if (shouldOverwrite) {
340
- await db.put(mergedRow.dbKey, mergedRow);
341
- }
342
- } catch {
343
- }
344
- })
345
- );
346
- };
347
- var clearStaleLocalRows = async (db, localRows, authoritativeRows, actorId) => {
348
- if (!db || typeof db.del !== "function") return;
349
- const authoritativeKeys = new Set(
350
- authoritativeRows.map((row) => row?.dbKey).filter((dbKey) => typeof dbKey === "string" && dbKey.length > 0)
351
- );
352
- await Promise.all(
353
- localRows.map(async (row) => {
354
- const dbKey = row?.dbKey;
355
- if (typeof dbKey !== "string" || authoritativeKeys.has(dbKey)) return;
356
- if (await hasPendingRowSyncState(db, actorId, dbKey)) return;
357
- try {
358
- await db.del(dbKey);
359
- } catch {
360
- }
361
- })
362
- );
363
- };
364
- var keepRemoteRowForPartialMerge = (row, localRowsByKey) => {
365
- const dbKey = row?.dbKey;
366
- if (typeof dbKey !== "string" || !dbKey) return false;
367
- const localRow = localRowsByKey.get(dbKey);
368
- if (!localRow) return true;
369
- const remoteDeleted = Boolean(row?.deletedAt);
370
- const localDeleted = Boolean(localRow?.deletedAt);
371
- return remoteDeleted === localDeleted;
372
- };
373
- var fetchAndCacheTableRows = async ({
374
- db,
375
- tenantId,
376
- tableId,
377
- token,
378
- remoteServers = [],
379
- fetchImpl = fetch,
380
- signal
381
- }) => {
382
- const headers = {
383
- "Content-Type": "application/json"
384
- };
385
- if (typeof token === "string" && token.trim()) {
386
- headers.Authorization = `Bearer ${token.trim()}`;
387
- }
388
- const isWebBrowser = typeof window !== "undefined" && !getIsDesktopApp();
389
- const serversToQuery = isWebBrowser && remoteServers.length > 0 ? [remoteServers[0]] : remoteServers;
390
- const localRows = await loadLocalTableRows(db, tenantId, tableId);
391
- const remoteResults = await Promise.allSettled(
392
- serversToQuery.map(
393
- (server) => fetchTableRowsFromServer(server, tenantId, tableId, headers, fetchImpl, signal)
394
- )
395
- );
396
- const fulfilledRemoteSnapshots = remoteResults.filter(
397
- (result) => result.status === "fulfilled"
398
- ).map((result) => result.value);
399
- if (fulfilledRemoteSnapshots.length === 0 && localRows.length === 0) {
400
- const firstFailure = remoteResults.find(
401
- (result) => result.status === "rejected"
402
- );
403
- throw new Error(firstFailure?.reason?.message || "\u52A0\u8F7D\u8868\u884C\u5931\u8D25");
404
- }
405
- const allRemoteSnapshotsComplete = serversToQuery.length > 0 && remoteResults.length === serversToQuery.length && fulfilledRemoteSnapshots.length === serversToQuery.length && fulfilledRemoteSnapshots.every((snapshot) => snapshot.complete);
406
- const localRowsByKey = new Map(
407
- localRows.filter((row) => typeof row?.dbKey === "string" && row.dbKey.length > 0).map((row) => [row.dbKey, row])
408
- );
409
- const remoteRowLists = fulfilledRemoteSnapshots.map((snapshot) => {
410
- const snapshotRows = [...snapshot.rows, ...snapshot.deletedRows];
411
- return allRemoteSnapshotsComplete ? snapshotRows : snapshotRows.filter((row) => keepRemoteRowForPartialMerge(row, localRowsByKey));
412
- });
413
- const authoritativeRemoteRows = remoteRowLists.flat();
414
- const tableDeleted = allRemoteSnapshotsComplete && Boolean(getLatestTableMeta(fulfilledRemoteSnapshots)?.deletedAt);
415
- const allRemoteSnapshotsConsistent = allRemoteSnapshotsComplete && fulfilledRemoteSnapshots.every((snapshot) => snapshot.snapshotConsistent === true);
416
- if (allRemoteSnapshotsConsistent) {
417
- await clearStaleLocalRows(db, localRows, authoritativeRemoteRows, tenantId);
418
- }
419
- const authoritativeRemoteKeys = allRemoteSnapshotsConsistent ? new Set(
420
- authoritativeRemoteRows.map((remoteRow) => remoteRow?.dbKey).filter((dbKey) => typeof dbKey === "string" && dbKey.length > 0)
421
- ) : null;
422
- const pendingProtectedKeys = /* @__PURE__ */ new Set();
423
- for (const row of localRows) {
424
- if (typeof row?.dbKey === "string" && await hasPendingRowSyncState(db, tenantId, row.dbKey)) {
425
- pendingProtectedKeys.add(row.dbKey);
426
- }
427
- }
428
- const localRowsForMerge = authoritativeRemoteKeys ? localRows.filter(
429
- (row) => typeof row?.dbKey === "string" && (authoritativeRemoteKeys.has(row.dbKey) || pendingProtectedKeys.has(row.dbKey))
430
- ) : localRows;
431
- const filteredRemoteRowLists = remoteRowLists.map(
432
- (list) => list.filter((row) => typeof row?.dbKey !== "string" || !pendingProtectedKeys.has(row.dbKey))
433
- );
434
- const mergedRows = mergeTableRows(localRowsForMerge, ...filteredRemoteRowLists);
435
- await cacheMergedTableRows(db, mergedRows, tenantId);
436
- return tableDeleted ? [] : mergedRows.filter((row) => !row?.deletedAt);
437
- };
438
-
439
- // packages/render/table/tableColumnCore.ts
440
- var ok = (value) => ({ ok: true, value });
441
- var err = (error) => ({ ok: false, error });
442
- var hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
443
- var buildMeta = (meta, columns, updatedAt) => ({
444
- meta: { ...meta, columns, updatedAt },
445
- metaChanges: { columns, updatedAt },
446
- noop: false
447
- });
448
- var reorderList = (list, from, to) => {
449
- const next = [...list];
450
- const [moved] = next.splice(from, 1);
451
- next.splice(to, 0, moved);
452
- return next;
453
- };
454
- function addColumnToMeta(meta, input, deps) {
455
- const { columnName } = input;
456
- if (!columnName.trim()) {
457
- return err("\u5B57\u6BB5\u540D\u4E0D\u80FD\u4E3A\u7A7A");
458
- }
459
- if (meta.columns.some((c) => c.name === columnName)) {
460
- return err(`\u5B57\u6BB5 ${columnName} \u5DF2\u5B58\u5728`);
461
- }
462
- const newColumn = {
463
- id: deps.id,
464
- name: columnName,
465
- label: columnName
466
- };
467
- return ok(buildMeta(meta, [...meta.columns, newColumn], deps.nowIso));
468
- }
469
- function deleteColumnFromMeta(meta, rows, input, deps) {
470
- const { columnName } = input;
471
- const { nowIso } = deps;
472
- if (!meta.columns.some((c) => c.name === columnName)) {
473
- return err(`\u5B57\u6BB5 ${columnName} \u4E0D\u5B58\u5728`);
474
- }
475
- const newColumns = meta.columns.filter((c) => c.name !== columnName);
476
- const rowPatches = rows.filter((row) => hasOwn(row, columnName)).map((row) => ({
477
- dbKey: row.dbKey,
478
- changes: { [columnName]: null, updatedAt: nowIso }
479
- }));
480
- const newRows = rows.map((row) => {
481
- if (!hasOwn(row, columnName)) {
482
- return row;
483
- }
484
- const { [columnName]: _removed, ...rest } = row;
485
- return { ...rest, updatedAt: nowIso };
486
- });
487
- return ok({
488
- ...buildMeta(meta, newColumns, nowIso),
489
- rows: newRows,
490
- rowPatches
491
- });
492
- }
493
- function reorderColumnInMeta(meta, input, deps) {
494
- const { fromIndex, toIndex } = input;
495
- const columnCount = meta.columns.length;
496
- if (fromIndex < 0 || fromIndex >= columnCount || toIndex < 0 || toIndex >= columnCount) {
497
- return err("\u5217\u7D22\u5F15\u8D85\u51FA\u8303\u56F4");
498
- }
499
- if (fromIndex === toIndex) {
500
- return ok({
501
- meta,
502
- metaChanges: { columns: meta.columns, updatedAt: meta.updatedAt },
503
- noop: true
504
- });
505
- }
506
- return ok(
507
- buildMeta(meta, reorderList(meta.columns, fromIndex, toIndex), deps.nowIso)
508
- );
509
- }
510
- function renameColumnLabelInMeta(meta, input, deps) {
511
- const { columnId } = input;
512
- const label = input.label.trim();
513
- if (!label) {
514
- return err("\u5B57\u6BB5\u663E\u793A\u540D\u4E0D\u80FD\u4E3A\u7A7A");
515
- }
516
- if (!meta.columns.some((c) => c.id === columnId)) {
517
- return err("\u8981\u91CD\u547D\u540D\u7684\u5B57\u6BB5\u4E0D\u5B58\u5728");
518
- }
519
- const newColumns = meta.columns.map(
520
- (c) => c.id === columnId ? { ...c, label } : c
521
- );
522
- return ok(buildMeta(meta, newColumns, deps.nowIso));
523
- }
524
- function updateColumnWidthInMeta(meta, input, deps) {
525
- const { columnId, width } = input;
526
- if (!meta.columns.some((c) => c.id === columnId)) {
527
- return err("\u8981\u8C03\u6574\u5BBD\u5EA6\u7684\u5B57\u6BB5\u4E0D\u5B58\u5728");
528
- }
529
- const normalizedWidth = typeof width === "number" && width > 0 ? Math.round(width) : void 0;
530
- const newColumns = meta.columns.map(
531
- (c) => c.id === columnId ? { ...c, width: normalizedWidth } : c
532
- );
533
- return ok(buildMeta(meta, newColumns, deps.nowIso));
534
- }
535
- function addColumnOptionInMeta(meta, input, deps) {
536
- const { columnId } = input;
537
- const option = input.option.trim();
538
- if (!option) {
539
- return err("\u9009\u9879\u540D\u4E0D\u80FD\u4E3A\u7A7A");
540
- }
541
- const column = meta.columns.find((c) => c.id === columnId);
542
- if (!column) {
543
- return err("\u8981\u65B0\u589E\u9009\u9879\u7684\u5B57\u6BB5\u4E0D\u5B58\u5728");
544
- }
545
- if ((column.options ?? []).some((o) => o.trim() === option)) {
546
- return ok({
547
- meta,
548
- metaChanges: { columns: meta.columns, updatedAt: meta.updatedAt },
549
- noop: true
550
- });
551
- }
552
- const newColumns = meta.columns.map(
553
- (c) => c.id === columnId ? { ...c, options: [...c.options ?? [], option] } : c
554
- );
555
- return ok(buildMeta(meta, newColumns, deps.nowIso));
556
- }
557
-
558
- // packages/render/table/createTableAction.ts
559
- import { ulid as ulid2 } from "ulid";
560
-
561
- // packages/create/space/resolveCreationSpaceId.ts
562
- function resolveCreationSpaceId(customSpaceId, currentSpaceId) {
563
- return (customSpaceId ?? currentSpaceId) || null;
564
- }
565
-
566
- // packages/render/table/createTableAction.ts
567
- var DEFAULT_COLUMNS = [
568
- {
569
- name: "title",
570
- label: "\u6807\u9898",
571
- type: "text",
572
- description: "\u8FD9\u4E00\u884C\u8BB0\u5F55\u7684\u4E3B\u9898\u6216\u540D\u79F0\u3002",
573
- isPrimary: true,
574
- required: true
575
- },
576
- {
577
- name: "note",
578
- label: "\u5907\u6CE8",
579
- type: "text",
580
- description: "\u5BF9\u8BE5\u6761\u76EE\u7684\u8865\u5145\u8BF4\u660E\u3002",
581
- required: false
582
- }
583
- ];
584
- var normalizeColumns = (inputColumns) => {
585
- const base = Array.isArray(inputColumns) ? inputColumns : [];
586
- const normalized = base.map((c) => {
587
- if (!c || typeof c.name !== "string") return null;
588
- const name = c.name.trim();
589
- if (!name) return null;
590
- const col = {
591
- id: asOptionalTrimmedString(c.id) ?? ulid2(),
592
- name
593
- };
594
- const label = asOptionalTrimmedString(c.label);
595
- if (label) col.label = label;
596
- if (typeof c.type === "string") {
597
- col.type = c.type;
598
- }
599
- const description = asOptionalTrimmedString(c.description);
600
- if (description) col.description = description;
601
- if (typeof c.isPrimary === "boolean") {
602
- col.isPrimary = c.isPrimary;
603
- }
604
- if (typeof c.required === "boolean") {
605
- col.required = c.required;
606
- }
607
- if (Array.isArray(c.options)) {
608
- const opts = asTrimmedNonEmptyStringArray(c.options);
609
- if (opts.length) {
610
- col.options = opts;
611
- }
612
- }
613
- return col;
614
- }).filter(Boolean);
615
- if (normalized.length > 0) {
616
- if (!normalized.some((c) => c.isPrimary)) {
617
- normalized[0].isPrimary = true;
618
- }
619
- return normalized;
620
- }
621
- return DEFAULT_COLUMNS.map((c) => ({
622
- ...c,
623
- id: ulid2()
624
- }));
625
- };
626
- var normalizeStringArray = (value) => {
627
- if (!Array.isArray(value)) return void 0;
628
- const items = [...new Set(asTrimmedNonEmptyStringArray(value))];
629
- return items.length ? items : void 0;
630
- };
631
- var normalizePublicIntake = (input) => {
632
- if (!isRecord(input)) return void 0;
633
- const allowedFields = normalizeStringArray(input.allowedFields) ?? [];
634
- if (input.enabled !== true) {
635
- return { enabled: false, allowedFields };
636
- }
637
- if (allowedFields.length === 0) {
638
- throw new Error("publicIntake.allowedFields \u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u5B57\u6BB5\u3002");
639
- }
640
- const slug = asOptionalTrimmedString(input.slug);
641
- const honeypotField = asOptionalTrimmedString(input.honeypotField);
642
- return {
643
- enabled: true,
644
- ...slug ? { slug } : {},
645
- ...normalizeStringArray(input.appIds) ? { appIds: normalizeStringArray(input.appIds) } : {},
646
- allowedFields,
647
- ...normalizeStringArray(input.requiredFields) ? { requiredFields: normalizeStringArray(input.requiredFields) } : {},
648
- ...honeypotField ? { honeypotField } : {}
649
- };
650
- };
651
- var createTableAction = async ({
652
- spaceId: customSpaceId,
653
- title: customTitle,
654
- purpose: customPurpose,
655
- description: customDescription,
656
- tags: customTags,
657
- publicIntake,
658
- categoryId,
659
- columns,
660
- withDefaultRows = true
661
- } = {}, { dispatch, getState }) => {
662
- const state3 = getState();
663
- const userId = selectIdentityUserId(state3);
664
- if (!userId) throw new Error("User ID not found.");
665
- const spaceId = resolveCreationSpaceId(customSpaceId, getCurrentSpaceId());
666
- const tableId = ulid2();
667
- const now = /* @__PURE__ */ new Date();
668
- const nowIso = formatLocalIso(now);
669
- const dbKey = metaKey(userId, tableId);
670
- const defaultTitle = runtime_default.t("space:newTable", {
671
- defaultValue: "\u65B0\u5EFA\u8868\u683C"
672
- });
673
- const title = asOptionalTrimmedString(customTitle) ?? defaultTitle;
674
- const purpose = asOptionalTrimmedString(customPurpose);
675
- const description = asOptionalTrimmedString(customDescription);
676
- const tags = Array.isArray(customTags) && customTags.length ? asTrimmedNonEmptyStringArray(customTags) : void 0;
677
- const finalPublicIntake = normalizePublicIntake(publicIntake);
678
- const finalColumns = normalizeColumns(columns);
679
- const tableMeta = {
680
- dbKey,
681
- tenantId: userId,
682
- tableId,
683
- spaceId: spaceId ?? null,
684
- displayName: title,
685
- purpose,
686
- description,
687
- tags,
688
- schemaVersion: 1,
689
- columns: finalColumns,
690
- views: [],
691
- // 后续可以在 UI 中新增视图
692
- triggers: [],
693
- // 后续可以在 UI/配置中新增触发器
694
- aiConfig: void 0,
695
- ...finalPublicIntake ? { publicIntake: finalPublicIntake } : {},
696
- createdAt: nowIso,
697
- updatedAt: nowIso,
698
- type: "table" /* TABLE */
699
- };
700
- await dispatch(
701
- write({
702
- data: tableMeta,
703
- customKey: dbKey
704
- })
705
- ).unwrap();
706
- if (withDefaultRows) {
707
- const defaultRows = [
708
- {
709
- title: "\u793A\u4F8B\u4E00",
710
- note: "\u4F60\u53EF\u4EE5\u5728\u8FD9\u91CC\u8BB0\u5F55\u4EFB\u4F55\u5185\u5BB9\uFF0C\u4F8B\u5982\u4EFB\u52A1\u3001\u60F3\u6CD5\u6216\u914D\u7F6E\u9879\u3002"
711
- },
712
- {
713
- title: "\u793A\u4F8B\u4E8C",
714
- note: "\u53CC\u51FB\u5355\u5143\u683C\u5F00\u59CB\u7F16\u8F91\uFF0C\u53F3\u4E0A\u89D2\u53EF\u4EE5\u6DFB\u52A0\u5B57\u6BB5\u548C\u884C\u3002"
715
- }
716
- ];
717
- await Promise.all(
718
- defaultRows.map(async (values) => {
719
- const { dbKey: rowKeyStr, rowId } = rowKey.create(userId, tableId);
720
- const row = {
721
- dbKey: rowKeyStr,
722
- tenantId: userId,
723
- tableId,
724
- rowId,
725
- createdAt: nowIso,
726
- updatedAt: nowIso,
727
- type: "table_row" /* TABLE_ROW */,
728
- ...values
729
- };
730
- await dispatch(
731
- write({
732
- data: row,
733
- customKey: rowKeyStr
734
- })
735
- ).unwrap();
736
- })
737
- );
738
- }
739
- if (spaceId) {
740
- await dispatch(
741
- addContentToSpace({
742
- spaceId,
743
- contentKey: dbKey,
744
- type: "table" /* TABLE */,
745
- title,
746
- categoryId
747
- })
748
- ).unwrap();
749
- }
750
- if (typeof window !== "undefined") {
751
- emitUserDataUpdated();
752
- }
753
- return dbKey;
754
- };
755
-
756
- // packages/render/table/deleteTableAction.ts
757
- var parseMetaKey = (dbKey) => {
758
- const parts = dbKey.split(SEPARATOR);
759
- if (parts[0] !== "meta" || parts.length < 3) {
760
- throw new Error(`\u975E\u6CD5\u8868 key\uFF1A${dbKey}`);
761
- }
762
- const tenantId = parts[1];
763
- const tableId = parts.slice(2).join(SEPARATOR);
764
- return { tenantId, tableId };
765
- };
766
- var collectEntriesByPrefix = async (db, prefix) => {
767
- const entries = [];
768
- for await (const [key, value] of db.iterator({
769
- gte: prefix,
770
- lte: prefix + "\uFFFF"
771
- })) {
772
- entries.push([key, value]);
773
- }
774
- return entries;
775
- };
776
- var belongsToTable = (value, tenantId, tableId) => Boolean(
777
- value && typeof value === "object" && value.tenantId === tenantId && value.tableId === tableId
778
- );
779
- var indexValueReferencesRows = (value, rowDbKeys, rowIds) => {
780
- if (typeof value === "string") {
781
- return rowDbKeys.has(value) || rowIds.has(value);
782
- }
783
- if (!value || typeof value !== "object") return false;
784
- const candidate = value;
785
- return typeof candidate.dbKey === "string" && rowDbKeys.has(candidate.dbKey) || typeof candidate.rowDbKey === "string" && rowDbKeys.has(candidate.rowDbKey) || typeof candidate.rowId === "string" && rowIds.has(candidate.rowId);
786
- };
787
- var deleteTableAction = async ({ dbKey }, {
788
- dispatch,
789
- getState,
790
- extra
791
- }) => {
792
- const { db } = extra;
793
- const state3 = getState();
794
- const { currentServer, syncServers } = getRuntimeServerContext(state3);
795
- const { tenantId, tableId } = parseMetaKey(dbKey);
796
- const nowIso = (/* @__PURE__ */ new Date()).toISOString();
797
- const rowPrefix = createKey("row", tenantId, tableId, "");
798
- const rowEntries = (await collectEntriesByPrefix(db, rowPrefix)).filter(
799
- ([, value]) => belongsToTable(value, tenantId, tableId)
800
- );
801
- const rowDbKeys = new Set(rowEntries.map(([key]) => key));
802
- const rowIds = new Set(
803
- rowEntries.map(([, value]) => value.rowId).filter((rowId) => typeof rowId === "string")
804
- );
805
- const idxPrefix = createKey("idx", tenantId, tableId, "");
806
- const idxEntries = await collectEntriesByPrefix(db, idxPrefix);
807
- const idxKeys = idxEntries.filter(
808
- ([, value]) => belongsToTable(value, tenantId, tableId) || indexValueReferencesRows(value, rowDbKeys, rowIds)
809
- ).map(([key]) => key);
810
- const viewPrefix = createKey("view", tenantId, tableId, "");
811
- const viewEntries = await collectEntriesByPrefix(db, viewPrefix);
812
- const viewKeys = viewEntries.filter(([, value]) => belongsToTable(value, tenantId, tableId)).map(([key]) => key);
813
- const metaRecord = typeof db.get === "function" ? await db.get(dbKey).catch(() => null) : null;
814
- const keysToDelete = Array.from(
815
- /* @__PURE__ */ new Set([
816
- ...idxKeys,
817
- ...viewKeys
818
- ])
819
- );
820
- const putOps = [
821
- ...metaRecord && typeof metaRecord === "object" ? [
822
- {
823
- type: "put",
824
- key: dbKey,
825
- value: buildTombstoneRecord(metaRecord, nowIso)
826
- }
827
- ] : [],
828
- ...rowEntries.map(([key, value]) => ({
829
- type: "put",
830
- key,
831
- value: buildTombstoneRecord(value, nowIso)
832
- }))
833
- ];
834
- if (keysToDelete.length > 0 || putOps.length > 0) {
835
- const ops = [
836
- ...putOps,
837
- ...keysToDelete.map((key) => ({
838
- type: "del",
839
- key
840
- }))
841
- ];
842
- await db.batch(ops);
843
- }
844
- scheduleDeleteReplication({
845
- currentServer,
846
- syncServers,
847
- dbKey,
848
- deleteOptions: { type: "table" },
849
- state: state3
850
- });
851
- return dbKey;
852
- };
853
-
854
- // packages/render/table/inferTableColumns.ts
855
- var TABLE_SYSTEM_ROW_FIELDS = /* @__PURE__ */ new Set([
856
- "dbKey",
857
- "tenantId",
858
- "tableId",
859
- "rowId",
860
- "type",
861
- "userId",
862
- "authorName",
863
- "authorAvatar",
864
- "ownerId",
865
- "createdAt",
866
- "updatedAt",
867
- "deletedAt"
868
- ]);
869
- var ISO_DATETIME_RE = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,6})?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;
870
- function classifyScalarValue(value) {
871
- if (value === null || value === void 0) return null;
872
- if (typeof value === "boolean") return "boolean";
873
- if (typeof value === "number" && Number.isFinite(value)) return "number";
874
- if (typeof value === "string") {
875
- const trimmed = value.trim();
876
- if (!trimmed) return null;
877
- if (ISO_DATETIME_RE.test(trimmed) && !Number.isNaN(Date.parse(trimmed))) {
878
- return "datetime";
879
- }
880
- return "text";
881
- }
882
- return "text";
883
- }
884
- function mergeInferredKind(prev, next) {
885
- if (next === null) return prev;
886
- if (prev === null) return next;
887
- if (prev === next) return prev;
888
- return "text";
889
- }
890
- function inferColumnsFromRows(rows, options = {}) {
891
- const generateId = options.generateId ?? ulid;
892
- const maxRows = options.maxRows ?? 600;
893
- const fieldKinds = /* @__PURE__ */ new Map();
894
- const limit = Math.min(rows.length, maxRows);
895
- for (let i = 0; i < limit; i++) {
896
- const row = rows[i];
897
- if (!row || typeof row !== "object" || Array.isArray(row)) continue;
898
- for (const [field, value] of Object.entries(row)) {
899
- if (!field || field === "__proto__" || field === "prototype" || field === "constructor" || TABLE_SYSTEM_ROW_FIELDS.has(field)) {
900
- continue;
901
- }
902
- const prev = fieldKinds.get(field) ?? null;
903
- fieldKinds.set(field, mergeInferredKind(prev, classifyScalarValue(value)));
904
- }
905
- }
906
- const columns = [];
907
- for (const [name, kind] of fieldKinds.entries()) {
908
- columns.push({
909
- id: generateId(),
910
- name,
911
- label: name,
912
- type: kind ?? "text"
913
- });
914
- }
915
- return columns;
916
- }
917
-
918
- // packages/render/table/tableStore.ts
919
- async function safeDispatch(dispatch, action) {
920
- if (!dispatch) return void 0;
921
- const res = await dispatch(action);
922
- if (res && typeof res.unwrap === "function") {
923
- return await res.unwrap();
924
- }
925
- return res?.payload ?? res;
926
- }
927
- var createInitialState = () => ({
928
- currentTable: null,
929
- expectedTableKey: null,
930
- isLoading: false,
931
- isInitialized: false,
932
- error: null,
933
- rows: [],
934
- focusContext: null
935
- });
936
- var listeners = /* @__PURE__ */ new Set();
937
- var version = 0;
938
- var state = createInitialState();
939
- var notify = () => {
940
- for (const listener of listeners) {
941
- try {
942
- listener();
943
- } catch {
944
- }
945
- }
946
- };
947
- var bump = () => {
948
- version += 1;
949
- notify();
950
- };
951
- var setState = (updater) => {
952
- state = typeof updater === "function" ? updater(state) : updater;
953
- bump();
954
- };
955
- function getTableState() {
956
- return state;
957
- }
958
- function createTableCommand(name, fn) {
959
- const command = (args) => {
960
- return async (dispatch, getState, extra) => {
961
- try {
962
- const payload = await fn(args, { dispatch, getState, extra });
963
- return {
964
- type: `${name}/fulfilled`,
965
- payload,
966
- meta: { arg: args },
967
- unwrap: async () => payload
968
- };
969
- } catch (err2) {
970
- const message = err2?.message || String(err2);
971
- return {
972
- type: `${name}/rejected`,
973
- payload: message,
974
- error: { message },
975
- unwrap: async () => {
976
- throw err2 instanceof Error ? err2 : new Error(message);
977
- }
978
- };
979
- }
980
- };
981
- };
982
- command.fulfilled = {
983
- type: `${name}/fulfilled`,
984
- match: (action) => action?.type === `${name}/fulfilled`
985
- };
986
- command.rejected = {
987
- type: `${name}/rejected`,
988
- match: (action) => action?.type === `${name}/rejected`
989
- };
990
- command.pending = {
991
- type: `${name}/pending`,
992
- match: (action) => action?.type === `${name}/pending`
993
- };
994
- command.run = (args, context = {}) => fn(args, context);
995
- return command;
996
- }
997
- var initTable = createTableCommand(
998
- "table/initTable",
999
- async (args, { dispatch } = {}) => {
1000
- const { tenantId, tableId } = args;
1001
- const dbKey = metaKey(tenantId, tableId);
1002
- setState((s) => ({
1003
- ...s,
1004
- isLoading: true,
1005
- error: null,
1006
- isInitialized: false,
1007
- currentTable: null,
1008
- // 从第一行起就声明「预期表」:读取期间 currentTable 为 null,
1009
- // 但只有本表的 loadTableRows 结果有权写入(见 isCurrentTableTarget)。
1010
- expectedTableKey: { tenantId, tableId },
1011
- rows: []
1012
- }));
1013
- try {
1014
- if (!dispatch) {
1015
- throw new Error("dispatch is required to initialize table");
1016
- }
1017
- const readAction = await dispatch(readAndWait(dbKey));
1018
- let meta;
1019
- try {
1020
- meta = unwrapDbResult(readAction) || readAction;
1021
- } catch {
1022
- }
1023
- if (meta && typeof meta === "object" && ("columns" in meta || "displayName" in meta || "tableId" in meta)) {
1024
- setState((s) => {
1025
- if (!isCurrentTableTarget(s, tenantId, tableId)) return s;
1026
- return {
1027
- ...s,
1028
- isLoading: false,
1029
- isInitialized: true,
1030
- currentTable: meta,
1031
- error: null
1032
- };
1033
- });
1034
- return meta;
1035
- }
1036
- const msg = readAction.payload?.message || `\u65E0\u6CD5\u52A0\u8F7D\u8868 ${tableId}`;
1037
- setState((s) => {
1038
- if (!isCurrentTableTarget(s, tenantId, tableId)) return s;
1039
- return {
1040
- ...s,
1041
- isLoading: false,
1042
- isInitialized: true,
1043
- currentTable: null,
1044
- error: msg,
1045
- rows: []
1046
- };
1047
- });
1048
- throw new Error(msg);
1049
- } catch (e) {
1050
- const msg = e?.message || `\u521D\u59CB\u5316\u8868 ${tableId} \u65F6\u51FA\u9519`;
1051
- setState((s) => {
1052
- if (!isCurrentTableTarget(s, tenantId, tableId)) return s;
1053
- return {
1054
- ...s,
1055
- isLoading: false,
1056
- isInitialized: true,
1057
- currentTable: null,
1058
- error: msg,
1059
- rows: []
1060
- };
1061
- });
1062
- throw e;
1063
- }
1064
- }
1065
- );
1066
- var sameTableTarget = (target, tenantId, tableId) => !!target && target.tenantId === tenantId && target.tableId === tableId;
1067
- var isCurrentTableTarget = (s, tenantId, tableId) => {
1068
- if (s.expectedTableKey) {
1069
- return sameTableTarget(s.expectedTableKey, tenantId, tableId);
1070
- }
1071
- if (s.currentTable) {
1072
- return sameTableTarget(s.currentTable, tenantId, tableId);
1073
- }
1074
- return true;
1075
- };
1076
- var loadTableRows = createTableCommand(
1077
- "table/loadTableRows",
1078
- async (args, { getState, extra } = {}) => {
1079
- const { tenantId, tableId } = args;
1080
- const db = extra?.db;
1081
- setState((s) => {
1082
- if (isCurrentTableTarget(s, tenantId, tableId)) {
1083
- return { ...s, error: null };
1084
- }
1085
- return s;
1086
- });
1087
- try {
1088
- const stateObj = getState ? getState() : {};
1089
- const { currentToken: token, remoteServers } = getRuntimeServerContext(stateObj);
1090
- const rows = await fetchAndCacheTableRows({
1091
- db,
1092
- tenantId,
1093
- tableId,
1094
- token,
1095
- remoteServers
1096
- });
1097
- setState((s) => {
1098
- if (isCurrentTableTarget(s, tenantId, tableId)) {
1099
- return { ...s, rows };
1100
- }
1101
- return s;
1102
- });
1103
- return rows;
1104
- } catch (e) {
1105
- const msg = e?.message || "\u52A0\u8F7D\u8868\u884C\u5931\u8D25";
1106
- try {
1107
- const stateObj = getState ? getState() : {};
1108
- const { remoteServers } = getRuntimeServerContext(stateObj);
1109
- logger.warn(
1110
- {
1111
- tenantId,
1112
- tableId,
1113
- remoteServers: remoteServers?.length ?? 0,
1114
- err: msg
1115
- },
1116
- "loadTableRows failed"
1117
- );
1118
- } catch {
1119
- }
1120
- setState((s) => {
1121
- if (isCurrentTableTarget(s, tenantId, tableId)) {
1122
- return { ...s, error: msg, rows: [] };
1123
- }
1124
- return s;
1125
- });
1126
- throw e;
1127
- }
1128
- }
1129
- );
1130
- var addRow = createTableCommand(
1131
- "table/addRow",
1132
- async (args, { dispatch } = {}) => {
1133
- const { tenantId, tableId, values } = args;
1134
- setState((s) => {
1135
- if (s.currentTable && s.currentTable.tenantId === tenantId && s.currentTable.tableId === tableId) {
1136
- return { ...s, error: null };
1137
- }
1138
- return s;
1139
- });
1140
- try {
1141
- const { dbKey, rowId } = rowKey.create(tenantId, tableId);
1142
- const nowIso = formatLocalIso(/* @__PURE__ */ new Date());
1143
- const row = {
1144
- dbKey,
1145
- tenantId,
1146
- tableId,
1147
- rowId,
1148
- createdAt: nowIso,
1149
- updatedAt: nowIso,
1150
- type: "table_row" /* TABLE_ROW */,
1151
- ...values
1152
- };
1153
- if (dispatch) {
1154
- await safeDispatch(
1155
- dispatch,
1156
- write({
1157
- data: row,
1158
- customKey: dbKey
1159
- })
1160
- );
1161
- }
1162
- setState((s) => {
1163
- const meta = s.currentTable;
1164
- if (meta && row?.tenantId === meta.tenantId && row?.tableId === meta.tableId) {
1165
- return { ...s, rows: [...s.rows, row] };
1166
- }
1167
- return s;
1168
- });
1169
- return row;
1170
- } catch (e) {
1171
- const msg = e?.message || "\u65B0\u589E\u8868\u884C\u5931\u8D25";
1172
- setState((s) => {
1173
- if (s.currentTable && s.currentTable.tenantId === tenantId && s.currentTable.tableId === tableId) {
1174
- return { ...s, error: msg };
1175
- }
1176
- return s;
1177
- });
1178
- throw e;
1179
- }
1180
- }
1181
- );
1182
- var deleteRow = createTableCommand(
1183
- "table/deleteRow",
1184
- async (dbKey, { dispatch, getState, extra } = {}) => {
1185
- try {
1186
- let row = state.rows.find((item) => item?.dbKey === dbKey);
1187
- if (!row && extra?.db && typeof extra.db.get === "function") {
1188
- try {
1189
- row = await extra.db.get(dbKey);
1190
- } catch {
1191
- }
1192
- }
1193
- if (!row && dispatch) {
1194
- try {
1195
- const readAction = await safeDispatch(dispatch, readAndWait(dbKey));
1196
- row = readAction?.payload || readAction;
1197
- } catch {
1198
- }
1199
- }
1200
- if (!row) {
1201
- throw new Error(`\u5F53\u524D\u8868\u4E2D\u627E\u4E0D\u5230\u8981\u5220\u9664\u7684\u884C\uFF1A${dbKey}`);
1202
- }
1203
- const nowIso = formatLocalIso(/* @__PURE__ */ new Date());
1204
- const tombstoneRow = {
1205
- ...row,
1206
- deletedAt: nowIso,
1207
- updatedAt: nowIso,
1208
- type: "table_row" /* TABLE_ROW */
1209
- };
1210
- if (extra?.db && typeof extra.db.put === "function") {
1211
- await extra.db.put(dbKey, tombstoneRow);
1212
- }
1213
- if (dispatch) {
1214
- dispatch(upsertSSREntity(tombstoneRow));
1215
- }
1216
- const stateObj = getState ? getState() : {};
1217
- const { currentServer, syncServers } = getRuntimeServerContext(stateObj);
1218
- const servers = resolveReplicationServers(currentServer, syncServers);
1219
- scheduleWriteReplication(
1220
- servers,
1221
- {
1222
- data: tombstoneRow,
1223
- customKey: dbKey
1224
- },
1225
- stateObj
1226
- );
1227
- setState((s) => ({
1228
- ...s,
1229
- rows: s.rows.filter((r) => r.dbKey !== dbKey)
1230
- }));
1231
- return dbKey;
1232
- } catch (e) {
1233
- const msg = e?.message || "\u5220\u9664\u8868\u884C\u5931\u8D25";
1234
- setState((s) => ({ ...s, error: msg }));
1235
- throw e;
1236
- }
1237
- }
1238
- );
1239
- var createTable = createTableCommand(
1240
- "table/createTable",
1241
- async (args, context = {}) => {
1242
- return await createTableAction(args, context);
1243
- }
1244
- );
1245
- var deleteTable = createTableCommand(
1246
- "table/deleteTable",
1247
- async (args, context = {}) => {
1248
- setState((s) => ({ ...s, error: null }));
1249
- try {
1250
- const deletedKey = await deleteTableAction(args, context);
1251
- setState((s) => {
1252
- if (s.currentTable?.dbKey === deletedKey) {
1253
- return {
1254
- ...s,
1255
- currentTable: null,
1256
- rows: [],
1257
- isInitialized: false
1258
- };
1259
- }
1260
- return s;
1261
- });
1262
- return deletedKey;
1263
- } catch (e) {
1264
- const msg = e?.message || "\u5220\u9664\u8868\u65F6\u53D1\u751F\u672A\u77E5\u9519\u8BEF";
1265
- setState((s) => ({ ...s, error: msg }));
1266
- throw e;
1267
- }
1268
- }
1269
- );
1270
- var addColumn = createTableCommand(
1271
- "table/addColumn",
1272
- async (args, { dispatch } = {}) => {
1273
- const { tenantId, tableId, columnName } = args;
1274
- const meta = state.currentTable;
1275
- if (!meta || meta.tenantId !== tenantId || meta.tableId !== tableId) {
1276
- throw new Error("\u5F53\u524D\u6CA1\u6709\u52A0\u8F7D\u5BF9\u5E94\u7684\u8868\u5B9A\u4E49");
1277
- }
1278
- const result = addColumnToMeta(
1279
- meta,
1280
- { columnName },
1281
- { id: ulid3(), nowIso: formatLocalIso(/* @__PURE__ */ new Date()) }
1282
- );
1283
- if (!result.ok) {
1284
- throw new Error(result.error);
1285
- }
1286
- setState((s) => ({ ...s, error: null }));
1287
- try {
1288
- if (dispatch) {
1289
- await safeDispatch(
1290
- dispatch,
1291
- patch({
1292
- dbKey: meta.dbKey,
1293
- changes: result.value.metaChanges
1294
- })
1295
- );
1296
- }
1297
- setState((s) => ({
1298
- ...s,
1299
- currentTable: result.value.meta,
1300
- isInitialized: true
1301
- }));
1302
- return result.value.meta;
1303
- } catch (e) {
1304
- const msg = e?.message || "\u6DFB\u52A0\u5B57\u6BB5\u5931\u8D25";
1305
- setState((s) => ({ ...s, error: msg }));
1306
- throw e;
1307
- }
1308
- }
1309
- );
1310
- var deleteColumn = createTableCommand(
1311
- "table/deleteColumn",
1312
- async (args, { dispatch } = {}) => {
1313
- const { tenantId, tableId, columnName } = args;
1314
- const meta = state.currentTable;
1315
- if (!meta || meta.tenantId !== tenantId || meta.tableId !== tableId) {
1316
- throw new Error("\u5F53\u524D\u6CA1\u6709\u52A0\u8F7D\u5BF9\u5E94\u7684\u8868\u5B9A\u4E49");
1317
- }
1318
- const result = deleteColumnFromMeta(
1319
- meta,
1320
- state.rows,
1321
- { columnName },
1322
- { nowIso: formatLocalIso(/* @__PURE__ */ new Date()) }
1323
- );
1324
- if (!result.ok) {
1325
- throw new Error(result.error);
1326
- }
1327
- const { meta: nextMeta, metaChanges, rows: newRows, rowPatches } = result.value;
1328
- setState((s) => ({ ...s, error: null }));
1329
- try {
1330
- if (dispatch) {
1331
- await Promise.all(
1332
- rowPatches.map((p) => safeDispatch(dispatch, patch(p)))
1333
- );
1334
- await safeDispatch(
1335
- dispatch,
1336
- patch({ dbKey: meta.dbKey, changes: metaChanges })
1337
- );
1338
- }
1339
- setState((s) => ({
1340
- ...s,
1341
- currentTable: nextMeta,
1342
- rows: newRows,
1343
- isInitialized: true
1344
- }));
1345
- return { meta: nextMeta, rows: newRows };
1346
- } catch (e) {
1347
- const msg = e?.message || "\u5220\u9664\u5B57\u6BB5\u5931\u8D25";
1348
- setState((s) => ({ ...s, error: msg }));
1349
- throw e;
1350
- }
1351
- }
1352
- );
1353
- var reorderColumn = createTableCommand(
1354
- "table/reorderColumn",
1355
- async (args, { dispatch } = {}) => {
1356
- const { tenantId, tableId, fromIndex, toIndex } = args;
1357
- const meta = state.currentTable;
1358
- if (!meta || meta.tenantId !== tenantId || meta.tableId !== tableId) {
1359
- throw new Error("\u5F53\u524D\u6CA1\u6709\u52A0\u8F7D\u5BF9\u5E94\u7684\u8868\u5B9A\u4E49");
1360
- }
1361
- const result = reorderColumnInMeta(
1362
- meta,
1363
- { fromIndex, toIndex },
1364
- { nowIso: formatLocalIso(/* @__PURE__ */ new Date()) }
1365
- );
1366
- if (!result.ok) {
1367
- throw new Error(result.error);
1368
- }
1369
- if (result.value.noop) {
1370
- return meta;
1371
- }
1372
- const { meta: nextMeta, metaChanges } = result.value;
1373
- setState((s) => ({ ...s, error: null }));
1374
- try {
1375
- if (dispatch) {
1376
- await safeDispatch(
1377
- dispatch,
1378
- patch({ dbKey: meta.dbKey, changes: metaChanges })
1379
- );
1380
- }
1381
- setState((s) => ({
1382
- ...s,
1383
- currentTable: nextMeta,
1384
- isInitialized: true
1385
- }));
1386
- return nextMeta;
1387
- } catch (e) {
1388
- const msg = e?.message || "\u8C03\u6574\u5217\u987A\u5E8F\u5931\u8D25";
1389
- setState((s) => ({ ...s, error: msg }));
1390
- throw e;
1391
- }
1392
- }
1393
- );
1394
- var renameColumnLabel = createTableCommand(
1395
- "table/renameColumnLabel",
1396
- async (args, { dispatch } = {}) => {
1397
- const { tenantId, tableId, columnId, newLabel } = args;
1398
- const meta = state.currentTable;
1399
- if (!meta || meta.tenantId !== tenantId || meta.tableId !== tableId) {
1400
- throw new Error("\u5F53\u524D\u6CA1\u6709\u52A0\u8F7D\u5BF9\u5E94\u7684\u8868\u5B9A\u4E49");
1401
- }
1402
- const result = renameColumnLabelInMeta(
1403
- meta,
1404
- { columnId, label: newLabel },
1405
- { nowIso: formatLocalIso(/* @__PURE__ */ new Date()) }
1406
- );
1407
- if (!result.ok) {
1408
- throw new Error(result.error);
1409
- }
1410
- const { meta: nextMeta, metaChanges } = result.value;
1411
- setState((s) => ({ ...s, error: null }));
1412
- try {
1413
- if (dispatch) {
1414
- await safeDispatch(
1415
- dispatch,
1416
- patch({ dbKey: meta.dbKey, changes: metaChanges })
1417
- );
1418
- }
1419
- setState((s) => ({
1420
- ...s,
1421
- currentTable: nextMeta,
1422
- isInitialized: true
1423
- }));
1424
- return nextMeta;
1425
- } catch (e) {
1426
- const msg = e?.message || "\u91CD\u547D\u540D\u5B57\u6BB5\u663E\u793A\u540D\u5931\u8D25";
1427
- setState((s) => ({ ...s, error: msg }));
1428
- throw e;
1429
- }
1430
- }
1431
- );
1432
- var updateColumnWidth = createTableCommand(
1433
- "table/updateColumnWidth",
1434
- async (args, { dispatch } = {}) => {
1435
- const { tenantId, tableId, columnId, width } = args;
1436
- const meta = state.currentTable;
1437
- if (!meta || meta.tenantId !== tenantId || meta.tableId !== tableId) {
1438
- throw new Error("\u5F53\u524D\u6CA1\u6709\u52A0\u8F7D\u5BF9\u5E94\u7684\u8868\u5B9A\u4E49");
1439
- }
1440
- const result = updateColumnWidthInMeta(
1441
- meta,
1442
- { columnId, width },
1443
- { nowIso: formatLocalIso(/* @__PURE__ */ new Date()) }
1444
- );
1445
- if (!result.ok) {
1446
- throw new Error(result.error);
1447
- }
1448
- const { meta: nextMeta, metaChanges } = result.value;
1449
- setState((s) => ({ ...s, error: null }));
1450
- try {
1451
- if (dispatch) {
1452
- await safeDispatch(
1453
- dispatch,
1454
- patch({ dbKey: meta.dbKey, changes: metaChanges })
1455
- );
1456
- }
1457
- setState((s) => ({
1458
- ...s,
1459
- currentTable: nextMeta,
1460
- isInitialized: true
1461
- }));
1462
- return nextMeta;
1463
- } catch (e) {
1464
- const msg = e?.message || "\u66F4\u65B0\u5B57\u6BB5\u5BBD\u5EA6\u5931\u8D25";
1465
- setState((s) => ({ ...s, error: msg }));
1466
- throw e;
1467
- }
1468
- }
1469
- );
1470
- var addColumnOption = createTableCommand(
1471
- "table/addColumnOption",
1472
- async (args, { dispatch } = {}) => {
1473
- const { tenantId, tableId, columnId, option } = args;
1474
- const meta = state.currentTable;
1475
- if (!meta || meta.tenantId !== tenantId || meta.tableId !== tableId) {
1476
- throw new Error("\u5F53\u524D\u6CA1\u6709\u52A0\u8F7D\u5BF9\u5E94\u7684\u8868\u5B9A\u4E49");
1477
- }
1478
- const result = addColumnOptionInMeta(
1479
- meta,
1480
- { columnId, option },
1481
- { nowIso: formatLocalIso(/* @__PURE__ */ new Date()) }
1482
- );
1483
- if (!result.ok) {
1484
- throw new Error(result.error);
1485
- }
1486
- if (result.value.noop) {
1487
- return meta;
1488
- }
1489
- const { meta: nextMeta, metaChanges } = result.value;
1490
- setState((s) => ({ ...s, error: null }));
1491
- try {
1492
- if (dispatch) {
1493
- await safeDispatch(
1494
- dispatch,
1495
- patch({ dbKey: meta.dbKey, changes: metaChanges })
1496
- );
1497
- }
1498
- setState((s) => ({
1499
- ...s,
1500
- currentTable: nextMeta,
1501
- isInitialized: true
1502
- }));
1503
- return nextMeta;
1504
- } catch (e) {
1505
- const msg = e?.message || "\u65B0\u589E\u9009\u9879\u5931\u8D25";
1506
- setState((s) => ({ ...s, error: msg }));
1507
- throw e;
1508
- }
1509
- }
1510
- );
1511
- var renameTable = createTableCommand(
1512
- "table/renameTable",
1513
- async (args, { dispatch } = {}) => {
1514
- const { tenantId, tableId, newName } = args;
1515
- const trimmedName = newName.trim();
1516
- if (!trimmedName) {
1517
- throw new Error("\u8868\u540D\u4E0D\u80FD\u4E3A\u7A7A");
1518
- }
1519
- const meta = state.currentTable;
1520
- if (!meta || meta.tenantId !== tenantId || meta.tableId !== tableId) {
1521
- throw new Error("\u5F53\u524D\u6CA1\u6709\u52A0\u8F7D\u5BF9\u5E94\u7684\u8868\u5B9A\u4E49");
1522
- }
1523
- const nowIso = formatLocalIso(/* @__PURE__ */ new Date());
1524
- setState((s) => ({ ...s, error: null }));
1525
- try {
1526
- if (dispatch) {
1527
- await safeDispatch(
1528
- dispatch,
1529
- patch({
1530
- dbKey: meta.dbKey,
1531
- changes: {
1532
- displayName: trimmedName,
1533
- updatedAt: nowIso
1534
- }
1535
- })
1536
- );
1537
- }
1538
- const nextMeta = {
1539
- ...meta,
1540
- displayName: trimmedName,
1541
- updatedAt: nowIso
1542
- };
1543
- setState((s) => {
1544
- if (!isCurrentTableTarget(s, tenantId, tableId) || !sameTableTarget(s.currentTable, tenantId, tableId)) return s;
1545
- return {
1546
- ...s,
1547
- currentTable: { ...s.currentTable, displayName: trimmedName, updatedAt: nowIso },
1548
- isInitialized: true
1549
- };
1550
- });
1551
- return nextMeta;
1552
- } catch (e) {
1553
- const msg = e?.message || "\u91CD\u547D\u540D\u8868\u5931\u8D25";
1554
- setState((s) => sameTableTarget(s.expectedTableKey ?? s.currentTable, tenantId, tableId) ? { ...s, error: msg } : s);
1555
- throw e;
1556
- }
1557
- }
1558
- );
1559
- var updateTableIcon = createTableCommand(
1560
- "table/updateTableIcon",
1561
- async (args, { dispatch } = {}) => {
1562
- const { tenantId, tableId, icon } = args;
1563
- const meta = state.currentTable;
1564
- if (!meta || meta.tenantId !== tenantId || meta.tableId !== tableId) {
1565
- throw new Error("\u5F53\u524D\u6CA1\u6709\u52A0\u8F7D\u5BF9\u5E94\u7684\u8868\u5B9A\u4E49");
1566
- }
1567
- const nowIso = formatLocalIso(/* @__PURE__ */ new Date());
1568
- setState((s) => ({ ...s, error: null }));
1569
- try {
1570
- if (dispatch) {
1571
- await safeDispatch(
1572
- dispatch,
1573
- patch({
1574
- dbKey: meta.dbKey,
1575
- changes: {
1576
- icon: icon ?? null,
1577
- updatedAt: nowIso
1578
- }
1579
- })
1580
- );
1581
- }
1582
- const nextMeta = {
1583
- ...meta,
1584
- icon: icon ?? null,
1585
- updatedAt: nowIso
1586
- };
1587
- setState((s) => {
1588
- if (!isCurrentTableTarget(s, tenantId, tableId) || !sameTableTarget(s.currentTable, tenantId, tableId)) return s;
1589
- return {
1590
- ...s,
1591
- currentTable: { ...s.currentTable, icon: icon ?? null, updatedAt: nowIso }
1592
- };
1593
- });
1594
- return nextMeta;
1595
- } catch (e) {
1596
- const msg = e?.message || "\u66F4\u65B0\u8868\u683C\u56FE\u6807\u5931\u8D25";
1597
- setState((s) => sameTableTarget(s.expectedTableKey ?? s.currentTable, tenantId, tableId) ? { ...s, error: msg } : s);
1598
- throw e;
1599
- }
1600
- }
1601
- );
1602
- var updateCell = createTableCommand(
1603
- "table/updateCell",
1604
- async (args, { dispatch } = {}) => {
1605
- const { dbKey, columnName, value } = args;
1606
- setState((s) => ({ ...s, error: null }));
1607
- try {
1608
- const nowIso = formatLocalIso(/* @__PURE__ */ new Date());
1609
- if (dispatch) {
1610
- await safeDispatch(
1611
- dispatch,
1612
- patch({
1613
- dbKey,
1614
- changes: {
1615
- [columnName]: value,
1616
- updatedAt: nowIso
1617
- }
1618
- })
1619
- );
1620
- }
1621
- setState((s) => ({
1622
- ...s,
1623
- rows: s.rows.map((r) => {
1624
- if (r.dbKey === dbKey) {
1625
- return {
1626
- ...r,
1627
- [columnName]: value,
1628
- updatedAt: nowIso
1629
- };
1630
- }
1631
- return r;
1632
- })
1633
- }));
1634
- return { dbKey, columnName, value, updatedAt: nowIso };
1635
- } catch (e) {
1636
- const msg = e?.message || "\u66F4\u65B0\u5355\u5143\u683C\u5931\u8D25";
1637
- setState((s) => ({ ...s, error: msg }));
1638
- throw e;
1639
- }
1640
- }
1641
- );
1642
- var repairTableSchema = createTableCommand(
1643
- "table/repairTableSchema",
1644
- async (args, { dispatch } = {}) => {
1645
- const { tenantId, tableId } = args;
1646
- const targetDbKey = metaKey(tenantId, tableId);
1647
- const meta = state.currentTable;
1648
- const sourceRows = args.rows ?? state.rows;
1649
- const inferredColumns = inferColumnsFromRows(sourceRows);
1650
- if (inferredColumns.length === 0) {
1651
- throw new Error("\u5F53\u524D\u8868\u4E2D\u6CA1\u6709\u53EF\u7528\u4E8E\u63A8\u65AD\u5217\u5B9A\u4E49\u7684\u4E1A\u52A1\u5B57\u6BB5\u3002");
1652
- }
1653
- const nowIso = formatLocalIso(/* @__PURE__ */ new Date());
1654
- const metaChanges = {
1655
- dbKey: targetDbKey,
1656
- tenantId,
1657
- tableId,
1658
- type: "table" /* TABLE */,
1659
- schemaVersion: meta?.schemaVersion ?? 1,
1660
- columns: inferredColumns,
1661
- columnCount: inferredColumns.length,
1662
- updatedAt: nowIso
1663
- };
1664
- setState((s) => ({ ...s, error: null }));
1665
- try {
1666
- if (dispatch) {
1667
- await safeDispatch(
1668
- dispatch,
1669
- patch({
1670
- dbKey: targetDbKey,
1671
- changes: metaChanges
1672
- })
1673
- );
1674
- }
1675
- const nextMeta = {
1676
- ...meta ?? {},
1677
- ...metaChanges,
1678
- displayName: meta?.displayName ?? tableId,
1679
- views: meta?.views ?? [],
1680
- triggers: meta?.triggers ?? [],
1681
- createdAt: meta?.createdAt ?? nowIso
1682
- };
1683
- setState((s) => ({
1684
- ...s,
1685
- currentTable: nextMeta,
1686
- isInitialized: true
1687
- }));
1688
- return nextMeta;
1689
- } catch (e) {
1690
- const msg = e?.message || "\u4FEE\u590D\u8868\u7ED3\u6784\u5931\u8D25";
1691
- setState((s) => ({ ...s, error: msg }));
1692
- throw e;
1693
- }
1694
- }
1695
- );
1696
-
1697
- // packages/create/space/content/deleteContentFromSpaceAction.ts
1698
- var nextSpaceUpdatedAt = (value) => {
1699
- const previousTimestamp = typeof value === "number" ? value : typeof value === "string" ? Date.parse(value) || 0 : 0;
1700
- const nextTimestamp = Math.max(Date.now(), previousTimestamp + 1);
1701
- return typeof value === "string" ? new Date(nextTimestamp).toISOString() : nextTimestamp;
1702
- };
1703
- var findContentReference = (spaceData, requestedContentKey) => {
1704
- const contents = spaceData.contents ?? {};
1705
- const directMatch = contents[requestedContentKey];
1706
- if (directMatch) {
1707
- return { entryKey: requestedContentKey, contentInfo: directMatch };
1708
- }
1709
- for (const [entryKey, item] of Object.entries(contents)) {
1710
- if (!item) continue;
1711
- if (item.contentKey === requestedContentKey) {
1712
- return { entryKey, contentInfo: item };
1713
- }
1714
- }
1715
- return null;
1716
- };
1717
- var ENTITY_DELETE_STRATEGIES = {
1718
- dialog: async (key, { dispatch }) => {
1719
- await dispatch(deleteDialog(key)).unwrap();
1720
- },
1721
- page: async (key, { dispatch, userId, sourceServerOrigin }) => {
1722
- const isOwnerByKey = extractUserId(key) === userId;
1723
- if (isOwnerByKey || isSystemAdmin(userId)) {
1724
- await dispatch(remove({ dbKey: key, preferredServerOrigin: sourceServerOrigin }));
1725
- }
1726
- },
1727
- table: async (key, { dispatch }) => {
1728
- await dispatch(deleteTable({ dbKey: key })).unwrap();
1729
- },
1730
- file: async (key, { thunkAPI }) => {
1731
- const { removeAction } = await import("./remove-AHRMUDMH.js");
1732
- await removeAction(key, thunkAPI);
1733
- },
1734
- image: async (key, { thunkAPI }) => {
1735
- const { removeAction } = await import("./remove-AHRMUDMH.js");
1736
- await removeAction(key, thunkAPI);
1737
- },
1738
- agent: async (key, { dispatch, userId, sourceServerOrigin }) => {
1739
- const parts = splitKey(key);
1740
- const isPublic = parts[1] === "pub";
1741
- const isOwnerByKey = parts[1] === userId;
1742
- if (!isPublic) {
1743
- if (isOwnerByKey || isSystemAdmin(userId)) {
1744
- await dispatch(remove({ dbKey: key, preferredServerOrigin: sourceServerOrigin }));
1745
- }
1746
- } else {
1747
- const agentData = await dispatch(read({
1748
- dbKey: key,
1749
- preferredServerOrigin: sourceServerOrigin
1750
- })).unwrap();
1751
- if (agentData) {
1752
- const isCreator = agentData.userId === userId;
1753
- const isAdmin = isSystemAdmin(userId);
1754
- if (isCreator || isAdmin) {
1755
- await dispatch(remove({ dbKey: key, preferredServerOrigin: sourceServerOrigin }));
1756
- }
1757
- }
1758
- }
1759
- }
1760
- };
1761
- var deleteContentFromSpaceAction = async (input, thunkAPI) => {
1762
- const { contentKey, sourceServerOrigin, skipEntityDelete } = input;
1763
- const spaceId = normalizeSpaceId(input.spaceId);
1764
- const { dispatch, getState } = thunkAPI;
1765
- const accountUserId = selectIdentityUserId(getState());
1766
- const spaceKey = createSpaceKey.space(spaceId);
1767
- const spaceData = await dispatch(read({
1768
- dbKey: spaceKey,
1769
- preferredServerOrigin: sourceServerOrigin
1770
- })).unwrap();
1771
- if (!spaceData) throw new Error("\u7A7A\u95F4\u4E0D\u5B58\u5728");
1772
- checkSpaceMembership(spaceData, accountUserId);
1773
- const contentReference = findContentReference(spaceData, contentKey);
1774
- if (!contentReference) {
1775
- return { contentKey, spaceId, updatedSpaceData: spaceData };
1776
- }
1777
- const { entryKey, contentInfo } = contentReference;
1778
- const entityKey = String(contentInfo.contentKey || contentKey || entryKey);
1779
- const contentDeletes = {
1780
- [entryKey]: null
1781
- };
1782
- if (entityKey !== entryKey) {
1783
- contentDeletes[entityKey] = null;
1784
- }
1785
- const updatedSpaceData = await dispatch(
1786
- patch({
1787
- dbKey: spaceKey,
1788
- preferredServerOrigin: sourceServerOrigin,
1789
- changes: {
1790
- contents: contentDeletes,
1791
- updatedAt: nextSpaceUpdatedAt(spaceData.updatedAt),
1792
- ...localSpaceAuthorityPatchStamp(spaceData)
1793
- }
1794
- })
1795
- ).unwrap();
1796
- if (skipEntityDelete) {
1797
- return {
1798
- contentKey,
1799
- spaceId,
1800
- updatedSpaceData,
1801
- entityRemoveError: null
1802
- };
1803
- }
1804
- const userId = isDeviceLocalSpaceBody(spaceData) ? DEVICE_LOCAL_OWNER_ID : String(accountUserId ?? "");
1805
- let entityRemoveError = null;
1806
- const contentType = String(contentInfo.type || "").toLowerCase();
1807
- try {
1808
- const strategy = ENTITY_DELETE_STRATEGIES[contentType];
1809
- if (strategy) {
1810
- await strategy(entityKey, { dispatch, userId, thunkAPI, sourceServerOrigin });
1811
- } else if (isPageKey(entityKey)) {
1812
- await ENTITY_DELETE_STRATEGIES.page(entityKey, {
1813
- dispatch,
1814
- userId,
1815
- thunkAPI,
1816
- sourceServerOrigin
1817
- });
1818
- } else if (isAgentKey(entityKey)) {
1819
- await ENTITY_DELETE_STRATEGIES.agent(entityKey, {
1820
- dispatch,
1821
- userId,
1822
- thunkAPI,
1823
- sourceServerOrigin
1824
- });
1825
- }
1826
- } catch (err2) {
1827
- console.error(`[deleteContent] Failed to delete entity ${entityKey}:`, err2);
1828
- entityRemoveError = err2.message || "Unknown error";
1829
- }
1830
- return {
1831
- contentKey,
1832
- spaceId,
1833
- updatedSpaceData,
1834
- entityRemoveError
1835
- };
1836
- };
1837
-
1838
- // packages/create/space/content/unlinkSpaceContentAction.ts
1839
- var logger2 = createClientLogger("unlink-space-content");
1840
- var resolveMembershipRole = (spaceId) => {
1841
- const normalized = normalizeSpaceId(spaceId);
1842
- const membership = getAllMemberSpaces().find(
1843
- (space) => normalizeSpaceId(space.spaceId) === normalized
1844
- );
1845
- return membership ? { role: membership.role } : null;
1846
- };
1847
- var unlinkSpaceContentAction = async (input, thunkAPI) => {
1848
- const { spaceId, contentKey, sourceServerOrigin } = input;
1849
- const { dispatch, getState } = thunkAPI;
1850
- const userId = selectIdentityUserId(getState()) ?? null;
1851
- if (!contentKey || typeof contentKey !== "string" || !contentKey.trim()) {
1852
- throw new Error("\u65E0\u6548\u7684\u5185\u5BB9 Key\u3002");
1853
- }
1854
- if (!spaceId || typeof spaceId !== "string" || !spaceId.trim()) {
1855
- throw new Error("\u65E0\u6548\u7684\u7A7A\u95F4 ID\u3002");
1856
- }
1857
- const spaceKey = createSpaceKey.space(spaceId);
1858
- const spaceData = await dispatch(
1859
- read({ dbKey: spaceKey, preferredServerOrigin: sourceServerOrigin })
1860
- ).unwrap();
1861
- if (!spaceData) {
1862
- throw new Error(`\u65E0\u6CD5\u52A0\u8F7D\u7A7A\u95F4\u6570\u636E: ${spaceId}`);
1863
- }
1864
- checkSpaceMembership(spaceData, userId);
1865
- if (!canManageSpaceContent(spaceData, userId, resolveMembershipRole(spaceId))) {
1866
- throw new Error("\u5F53\u524D\u89D2\u8272\u4E0D\u80FD\u4ECE\u7A7A\u95F4\u79FB\u9664\u5185\u5BB9");
1867
- }
1868
- const result = {
1869
- spaceId,
1870
- contentKey,
1871
- updatedSpaceData: spaceData,
1872
- removed: false,
1873
- entitySpaceSync: "no-record"
1874
- };
1875
- if (spaceData.contents?.[contentKey]) {
1876
- const state3 = getState();
1877
- const trimmedOrigin = sourceServerOrigin?.trim();
1878
- const apiOpts = trimmedOrigin ? { serverOrigin: trimmedOrigin } : void 0;
1879
- let updatedSpaceData;
1880
- if (isRemoteAccountSpace(spaceData, state3, apiOpts)) {
1881
- let effectiveUpdatedAt = Date.now();
1882
- try {
1883
- const res = await mutateDbOps(
1884
- state3,
1885
- [{ op: "tombstone", key: spItemKey(spaceId, contentKey) }],
1886
- apiOpts
1887
- );
1888
- effectiveUpdatedAt = res?.applied?.[0]?.updatedAt ?? effectiveUpdatedAt;
1889
- } catch (apiError) {
1890
- throw new Error(
1891
- `\u4ECE\u7A7A\u95F4\u79FB\u9664\u5F15\u7528\u5931\u8D25: ${apiError?.message || "\u672A\u77E5\u9519\u8BEF"}`
1892
- );
1893
- }
1894
- const nextContents = { ...spaceData.contents ?? {} };
1895
- delete nextContents[contentKey];
1896
- updatedSpaceData = await syncLocalSpaceEntityCache(thunkAPI, spaceKey, {
1897
- ...spaceData,
1898
- contents: nextContents,
1899
- updatedAt: effectiveUpdatedAt
1900
- });
1901
- } else {
1902
- try {
1903
- updatedSpaceData = await dispatch(
1904
- patch({
1905
- dbKey: spaceKey,
1906
- changes: {
1907
- contents: { [contentKey]: null },
1908
- updatedAt: Date.now(),
1909
- ...localSpaceAuthorityPatchStamp(spaceData)
1910
- }
1911
- })
1912
- ).unwrap();
1913
- } catch (patchError) {
1914
- throw new Error(
1915
- `\u4ECE\u7A7A\u95F4\u79FB\u9664\u5F15\u7528\u5931\u8D25: ${patchError?.message || "\u672A\u77E5\u9519\u8BEF"}`
1916
- );
1917
- }
1918
- }
1919
- result.removed = true;
1920
- result.updatedSpaceData = updatedSpaceData;
1921
- }
1922
- const entityRead = await readContentRecordForSpaceSync(dispatch, contentKey);
1923
- if (entityRead.status === "unreadable") {
1924
- result.entitySpaceSync = "unreadable";
1925
- result.error = "\u5F15\u7528\u5DF2\u4ECE\u7A7A\u95F4\u79FB\u9664\uFF0C\u4F46\u65E0\u6CD5\u8BFB\u53D6\u5185\u5BB9\u8BB0\u5F55\uFF0C\u5F52\u5C5E\u7A7A\u95F4\u672A\u5BF9\u9F50\uFF08\u53EF\u91CD\u8BD5\uFF09";
1926
- notifyUserDataUpdated();
1927
- return result;
1928
- }
1929
- if (entityRead.status === "missing") {
1930
- result.entitySpaceSync = "no-record";
1931
- notifyUserDataUpdated();
1932
- return result;
1933
- }
1934
- const record = entityRead.record;
1935
- const ownerRaw = typeof record.userId === "string" ? record.userId : typeof record.ownerId === "string" ? record.ownerId : "";
1936
- const owner = ownerRaw.trim();
1937
- const ownsRecord = Boolean(owner) && (owner === userId || owner === "local");
1938
- if (!ownsRecord) {
1939
- result.entitySpaceSync = "skipped-not-owner";
1940
- notifyUserDataUpdated();
1941
- return result;
1942
- }
1943
- const currentSpaceId = typeof record.spaceId === "string" ? normalizeSpaceId(record.spaceId) : null;
1944
- if (currentSpaceId !== normalizeSpaceId(spaceId)) {
1945
- result.entitySpaceSync = "skipped-mismatch";
1946
- notifyUserDataUpdated();
1947
- return result;
1948
- }
1949
- try {
1950
- await dispatch(
1951
- patch({ dbKey: contentKey, changes: { spaceId: null } })
1952
- ).unwrap();
1953
- result.entitySpaceSync = "cleared";
1954
- } catch (entityPatchError) {
1955
- result.entitySpaceSync = "failed";
1956
- result.error = `\u5F15\u7528\u5DF2\u79FB\u9664\uFF0C\u4F46\u6E05\u7A7A\u5185\u5BB9\u5F52\u5C5E\u7A7A\u95F4\u5931\u8D25\uFF08\u53EF\u91CD\u8BD5\uFF09: ${entityPatchError?.message || "\u672A\u77E5\u9519\u8BEF"}`;
1957
- logger2.error(
1958
- { contentKey, spaceId, reason: entityPatchError?.message },
1959
- "Failed to clear content spaceId after unlink"
1960
- );
1961
- }
1962
- notifyUserDataUpdated();
1963
- return result;
1964
- };
1965
-
1966
- // packages/create/space/content/moveContentAction.ts
1967
- var logger3 = createClientLogger("move-content");
1968
- var moveContentAction = async (input, thunkAPI) => {
1969
- const {
1970
- contentKey,
1971
- sourceSpaceId,
1972
- targetSpaceId,
1973
- targetCategoryId: rawTargetCategoryId
1974
- } = input;
1975
- const { dispatch, getState } = thunkAPI;
1976
- const state3 = getState();
1977
- const userId = selectIdentityUserId(state3);
1978
- const now = Date.now();
1979
- logger3.info({ ...input, userId }, "Initiating moveContentAction");
1980
- if (sourceSpaceId === targetSpaceId) {
1981
- logger3.error("Source and target space IDs are the same.");
1982
- throw new Error(
1983
- "\u6E90\u7A7A\u95F4\u548C\u76EE\u6807\u7A7A\u95F4\u4E0D\u80FD\u76F8\u540C\u3002\u5982\u9700\u4FEE\u6539\u5206\u7C7B\uFF0C\u8BF7\u4F7F\u7528\u66F4\u65B0\u5206\u7C7B\u64CD\u4F5C\u3002"
1984
- );
1985
- }
1986
- if (!contentKey || typeof contentKey !== "string" || contentKey.trim() === "") {
1987
- logger3.error("Invalid contentKey provided.");
1988
- throw new Error("\u65E0\u6548\u7684\u5185\u5BB9 Key\u3002");
1989
- }
1990
- let sourceSpaceData = null;
1991
- let targetSpaceData = null;
1992
- let contentDataFromSource = null;
1993
- let finalSourceData = null;
1994
- let finalTargetData = null;
1995
- let contentSpaceSync = void 0;
1996
- let targetWritten = false;
1997
- let sourcePruned = false;
1998
- let resumedFromTarget = false;
1999
- let overallError = void 0;
2000
- try {
2001
- const sourceSpaceKey = createSpaceKey.space(sourceSpaceId);
2002
- const targetSpaceKey = createSpaceKey.space(targetSpaceId);
2003
- logger3.info(
2004
- { sourceSpaceKey, targetSpaceKey },
2005
- "Reading source and target space data."
2006
- );
2007
- const [sourceResult, targetResult] = await Promise.allSettled([
2008
- dispatch(read({
2009
- dbKey: sourceSpaceKey
2010
- })).unwrap(),
2011
- dispatch(read({
2012
- dbKey: targetSpaceKey
2013
- })).unwrap()
2014
- ]);
2015
- if (sourceResult.status === "rejected" || !sourceResult.value) {
2016
- const reason = sourceResult.status === "rejected" ? sourceResult.reason : "Data is null";
2017
- throw new Error(
2018
- `\u65E0\u6CD5\u52A0\u8F7D\u6E90\u7A7A\u95F4 (${sourceSpaceId}): ${reason?.message || reason}`
2019
- );
2020
- }
2021
- sourceSpaceData = sourceResult.value;
2022
- if (targetResult.status === "rejected" || !targetResult.value) {
2023
- const reason = targetResult.status === "rejected" ? targetResult.reason : "Data is null";
2024
- throw new Error(
2025
- `\u65E0\u6CD5\u52A0\u8F7D\u76EE\u6807\u7A7A\u95F4 (${targetSpaceId}): ${reason?.message || reason}`
2026
- );
2027
- }
2028
- targetSpaceData = targetResult.value;
2029
- logger3.info("Checking permissions for source and target spaces.");
2030
- checkSpaceMembership(sourceSpaceData, userId);
2031
- checkSpaceMembership(targetSpaceData, userId);
2032
- const sourceSpaceKeyForWrite = createSpaceKey.space(sourceSpaceId);
2033
- const targetSpaceKeyForWrite = createSpaceKey.space(targetSpaceId);
2034
- const sourceHasLink = Boolean(sourceSpaceData.contents?.[contentKey]);
2035
- const targetHasLink = Boolean(targetSpaceData.contents?.[contentKey]);
2036
- if (!sourceHasLink && !targetHasLink) {
2037
- throw new Error(
2038
- `\u5185\u5BB9 (${contentKey}) \u65E2\u4E0D\u5728\u6E90\u7A7A\u95F4 (${sourceSpaceId}) \u4E5F\u4E0D\u5728\u76EE\u6807\u7A7A\u95F4 (${targetSpaceId}) \u4E2D\u3002`
2039
- );
2040
- }
2041
- contentDataFromSource = sourceSpaceData.contents?.[contentKey] ?? null;
2042
- resumedFromTarget = !sourceHasLink && targetHasLink;
2043
- if (resumedFromTarget) {
2044
- logger3.info(
2045
- { contentKey, sourceSpaceId, targetSpaceId },
2046
- "Source link already pruned and target link exists; resuming convergence (no overwrite)."
2047
- );
2048
- }
2049
- let categoryIdForTargetStorage;
2050
- if (!targetHasLink) {
2051
- if (rawTargetCategoryId && rawTargetCategoryId !== "" && rawTargetCategoryId !== UNCATEGORIZED_ID) {
2052
- if (targetSpaceData.categories?.[rawTargetCategoryId]) {
2053
- categoryIdForTargetStorage = rawTargetCategoryId;
2054
- } else {
2055
- logger3.warn(
2056
- `Target category ${rawTargetCategoryId} not found in target space ${targetSpaceId}. Content will be uncategorized.`
2057
- );
2058
- categoryIdForTargetStorage = void 0;
2059
- }
2060
- }
2061
- }
2062
- if (!targetHasLink) {
2063
- if (!contentDataFromSource) {
2064
- throw new Error(`\u5185\u5BB9 (${contentKey}) \u5728\u6E90\u7A7A\u95F4\u4E2D\u6CA1\u6709\u53EF\u8FC1\u79FB\u7684\u5F15\u7528\u6570\u636E\u3002`);
2065
- }
2066
- const contentReferenceForTarget = {
2067
- ...contentDataFromSource,
2068
- updatedAt: now
2069
- };
2070
- delete contentReferenceForTarget.categoryId;
2071
- if (categoryIdForTargetStorage !== void 0) {
2072
- contentReferenceForTarget.categoryId = categoryIdForTargetStorage;
2073
- }
2074
- try {
2075
- await dispatch(
2076
- patch({
2077
- dbKey: targetSpaceKeyForWrite,
2078
- changes: {
2079
- contents: { [contentKey]: contentReferenceForTarget },
2080
- updatedAt: now,
2081
- ...localSpaceAuthorityPatchStamp(targetSpaceData)
2082
- }
2083
- })
2084
- ).unwrap();
2085
- } catch (targetPatchError) {
2086
- throw new Error(
2087
- `\u76EE\u6807\u7A7A\u95F4\u5199\u5165\u5931\u8D25\uFF0C\u6E90\u7A7A\u95F4\u5F15\u7528\u5DF2\u4FDD\u7559\uFF08\u53EF\u91CD\u8BD5\uFF09: ${targetPatchError?.message || "\u672A\u77E5\u9519\u8BEF"}`
2088
- );
2089
- }
2090
- targetWritten = true;
2091
- logger3.info("Target reference written (target-first).");
2092
- }
2093
- try {
2094
- contentSpaceSync = await syncContentRecordSpaceId(
2095
- dispatch,
2096
- contentKey,
2097
- targetSpaceId,
2098
- "\u5185\u5BB9\u5DF2\u8FC1\u79FB\u5230\u76EE\u6807\u7A7A\u95F4\uFF0C\u4F46\u540C\u6B65\u5185\u5BB9\u8BB0\u5F55\u7684\u5F52\u5C5E\u7A7A\u95F4\u5931\u8D25",
2099
- {
2100
- actorUserId: userId,
2101
- targetSpaceIsDeviceLocal: isDeviceLocalSpaceBody(sourceSpaceData) || isDeviceLocalSpaceBody(targetSpaceData)
2102
- }
2103
- );
2104
- } catch (entitySyncError) {
2105
- throw new Error(
2106
- `${entitySyncError?.message || "\u540C\u6B65\u5185\u5BB9\u8BB0\u5F55\u5931\u8D25"}\uFF08\u76EE\u6807\u7A7A\u95F4\u5DF2\u5199\u5165\uFF0C\u6E90\u7A7A\u95F4\u5F15\u7528\u5DF2\u4FDD\u7559\uFF0C\u53EF\u91CD\u8BD5\uFF09`
2107
- );
2108
- }
2109
- if (contentSpaceSync === "unreadable") {
2110
- throw new Error(
2111
- "\u65E0\u6CD5\u8BFB\u53D6\u5185\u5BB9\u8BB0\u5F55\u786E\u8BA4\u5F52\u5C5E\u7A7A\u95F4\u540C\u6B65\uFF08\u76EE\u6807\u7A7A\u95F4\u5DF2\u5199\u5165\uFF0C\u6E90\u7A7A\u95F4\u5F15\u7528\u5DF2\u4FDD\u7559\uFF0C\u53EF\u91CD\u8BD5\uFF09"
2112
- );
2113
- }
2114
- if (sourceHasLink) {
2115
- try {
2116
- await dispatch(
2117
- patch({
2118
- dbKey: sourceSpaceKeyForWrite,
2119
- changes: {
2120
- contents: { [contentKey]: null },
2121
- updatedAt: now,
2122
- ...localSpaceAuthorityPatchStamp(sourceSpaceData)
2123
- }
2124
- })
2125
- ).unwrap();
2126
- } catch (sourcePatchError) {
2127
- throw new Error(
2128
- `\u5185\u5BB9\u5DF2\u5199\u5165\u76EE\u6807\u7A7A\u95F4\uFF0C\u4F46\u4ECE\u6E90\u7A7A\u95F4\u79FB\u9664\u5F15\u7528\u5931\u8D25\uFF08\u53EF\u91CD\u8BD5\uFF09: ${sourcePatchError?.message || "\u672A\u77E5\u9519\u8BEF"}`
2129
- );
2130
- }
2131
- }
2132
- sourcePruned = true;
2133
- logger3.info("Source reference pruned; move converged.");
2134
- } catch (error) {
2135
- logger3.error(
2136
- { error: error.message, stack: error.stack },
2137
- "Error during move content action execution."
2138
- );
2139
- overallError = error.message || "\u79FB\u52A8\u5185\u5BB9\u65F6\u53D1\u751F\u672A\u77E5\u9519\u8BEF";
2140
- } finally {
2141
- logger3.info("Attempting to re-read final space data.");
2142
- const sourceSpaceKey = createSpaceKey.space(sourceSpaceId);
2143
- const targetSpaceKey = createSpaceKey.space(targetSpaceId);
2144
- const [finalSourceResult, finalTargetResult] = await Promise.allSettled([
2145
- dispatch(read({
2146
- dbKey: sourceSpaceKey
2147
- })).unwrap(),
2148
- dispatch(read({
2149
- dbKey: targetSpaceKey
2150
- })).unwrap()
2151
- ]);
2152
- if (finalSourceResult.status === "fulfilled") {
2153
- finalSourceData = finalSourceResult.value;
2154
- } else {
2155
- logger3.error(
2156
- { sourceSpaceId, reason: finalSourceResult.reason },
2157
- "Failed to re-read final source space data."
2158
- );
2159
- }
2160
- if (finalTargetResult.status === "fulfilled") {
2161
- finalTargetData = finalTargetResult.value;
2162
- } else {
2163
- logger3.error(
2164
- { targetSpaceId, reason: finalTargetResult.reason },
2165
- "Failed to re-read final target space data."
2166
- );
2167
- }
2168
- logger3.info(
2169
- {
2170
- hasError: !!overallError,
2171
- sourceReadSuccess: !!finalSourceData,
2172
- targetReadSuccess: !!finalTargetData,
2173
- targetWritten,
2174
- sourcePruned,
2175
- resumedFromTarget,
2176
- contentSpaceSync
2177
- },
2178
- "Move content action finished."
2179
- );
2180
- notifyUserDataUpdated();
2181
- const result = {
2182
- sourceSpaceId,
2183
- updatedSourceSpaceData: finalSourceData,
2184
- targetSpaceId,
2185
- updatedTargetSpaceData: finalTargetData,
2186
- contentSpaceSync,
2187
- targetWritten,
2188
- sourcePruned,
2189
- resumedFromTarget,
2190
- error: overallError
2191
- // 如果过程中有错误,则传递错误信息
2192
- };
2193
- return result;
2194
- }
2195
- };
2196
-
2197
- // packages/create/space/content/updateContentTitleAction.ts
2198
- var buildContentRecordTitleChanges = (content, title, updatedAt) => {
2199
- const changes = { title, updatedAt };
2200
- if (content.type === "app") {
2201
- changes.name = title;
2202
- }
2203
- return changes;
2204
- };
2205
- var updateContentTitleAction = async (input, thunkAPI) => {
2206
- const { spaceId, contentKey, title, skillSummary, sourceServerOrigin } = input;
2207
- const { dispatch } = thunkAPI;
2208
- if (title === void 0 || title === null || typeof title !== "string") {
2209
- throw new Error("Invalid title provided.");
2210
- }
2211
- if (title.trim() === "") {
2212
- throw new Error("Title cannot be empty.");
2213
- }
2214
- const { spaceKey, spaceData, content } = await loadSpaceContentOrThrow(
2215
- dispatch,
2216
- spaceId,
2217
- contentKey,
2218
- sourceServerOrigin
2219
- );
2220
- const trimmedTitle = title.trim();
2221
- const now = (/* @__PURE__ */ new Date()).toISOString();
2222
- const changes = {
2223
- contents: {
2224
- [contentKey]: {
2225
- ...spaceData.contents[contentKey],
2226
- title: trimmedTitle,
2227
- updatedAt: now,
2228
- ...skillSummary !== void 0 ? { skillSummary } : {}
2229
- }
2230
- },
2231
- updatedAt: now
2232
- };
2233
- const state3 = typeof thunkAPI?.getState === "function" ? thunkAPI.getState() : {};
2234
- const trimmedOrigin = sourceServerOrigin?.trim();
2235
- const apiOpts = trimmedOrigin ? { serverOrigin: trimmedOrigin } : void 0;
2236
- let updatedSpaceData;
2237
- if (isRemoteAccountSpace(spaceData, state3, apiOpts)) {
2238
- const nowMs = Date.now();
2239
- try {
2240
- const res = await mutateDbOps(
2241
- state3,
2242
- [
2243
- {
2244
- op: "patch",
2245
- key: spItemKey(spaceId, contentKey),
2246
- value: {
2247
- title: trimmedTitle,
2248
- ...skillSummary !== void 0 ? { skillSummary } : {}
2249
- }
2250
- }
2251
- ],
2252
- apiOpts
2253
- );
2254
- const effectiveUpdatedAt = res?.applied?.[0]?.updatedAt ?? nowMs;
2255
- updatedSpaceData = await syncLocalSpaceEntityCache(thunkAPI, spaceKey, {
2256
- ...spaceData,
2257
- contents: {
2258
- ...spaceData.contents ?? {},
2259
- [contentKey]: {
2260
- ...spaceData.contents[contentKey],
2261
- title: trimmedTitle,
2262
- updatedAt: effectiveUpdatedAt,
2263
- ...skillSummary !== void 0 ? { skillSummary } : {}
2264
- }
2265
- },
2266
- updatedAt: effectiveUpdatedAt
2267
- });
2268
- } catch (apiError) {
2269
- throw new Error(`\u66F4\u65B0\u5185\u5BB9\u6807\u9898\u5931\u8D25: ${apiError.message || "\u672A\u77E5\u9519\u8BEF"}`);
2270
- }
2271
- } else {
2272
- try {
2273
- updatedSpaceData = await dispatch(
2274
- patch({
2275
- dbKey: spaceKey,
2276
- changes,
2277
- preferredServerOrigin: sourceServerOrigin
2278
- })
2279
- ).unwrap();
2280
- } catch (patchError) {
2281
- throw new Error(`\u66F4\u65B0\u5185\u5BB9\u6807\u9898\u5931\u8D25: ${patchError.message || "\u672A\u77E5\u9519\u8BEF"}`);
2282
- }
2283
- }
2284
- await patchIndividualContentRecord(
2285
- dispatch,
2286
- contentKey,
2287
- buildContentRecordTitleChanges(content, trimmedTitle, now),
2288
- sourceServerOrigin,
2289
- "\u6807\u9898\u5DF2\u5199\u5165\u7A7A\u95F4\uFF0C\u4F46\u540C\u6B65\u72EC\u7ACB\u8BB0\u5F55\u5931\u8D25"
2290
- );
2291
- if (contentKey.startsWith("meta-")) {
2292
- const parts = contentKey.split(SEPARATOR);
2293
- if (parts.length >= 3) {
2294
- const tableId = parts.slice(2).join(SEPARATOR);
2295
- const tenantId = parts[1];
2296
- try {
2297
- await dispatch(
2298
- renameTable({
2299
- tenantId,
2300
- tableId,
2301
- newName: trimmedTitle
2302
- })
2303
- ).unwrap();
2304
- } catch (tableError) {
2305
- console.error("Failed to sync title to TableMeta:", tableError);
2306
- }
2307
- }
2308
- }
2309
- return { spaceId, updatedSpaceData };
2310
- };
2311
-
2312
- // packages/create/space/content/updateContentPinnedAction.ts
2313
- var updateContentPinnedAction = async (input, thunkAPI) => {
2314
- const { spaceId, contentKey, pinned, sourceServerOrigin } = input;
2315
- const { dispatch } = thunkAPI;
2316
- if (typeof pinned !== "boolean") {
2317
- throw new Error("Invalid pinned value provided.");
2318
- }
2319
- if (!spaceId) {
2320
- if (!contentKey || typeof contentKey !== "string" || contentKey.trim() === "") {
2321
- throw new Error("Invalid contentKey provided.");
2322
- }
2323
- await patchIndividualContentRecord(
2324
- dispatch,
2325
- contentKey,
2326
- { pinned },
2327
- sourceServerOrigin,
2328
- "\u66F4\u65B0\u7F6E\u9876\u72B6\u6001\u5931\u8D25"
2329
- );
2330
- return { spaceId: null, updatedSpaceData: null };
2331
- }
2332
- const { spaceKey, spaceData } = await loadSpaceContentOrThrow(
2333
- dispatch,
2334
- spaceId,
2335
- contentKey,
2336
- sourceServerOrigin
2337
- );
2338
- const changes = {
2339
- contents: {
2340
- [contentKey]: { ...spaceData.contents[contentKey], pinned }
2341
- },
2342
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
2343
- };
2344
- const state3 = typeof thunkAPI?.getState === "function" ? thunkAPI.getState() : {};
2345
- const trimmedOrigin = sourceServerOrigin?.trim();
2346
- const apiOpts = trimmedOrigin ? { serverOrigin: trimmedOrigin } : void 0;
2347
- let updatedSpaceData;
2348
- if (isRemoteAccountSpace(spaceData, state3, apiOpts)) {
2349
- const nowMs = Date.now();
2350
- try {
2351
- const res = await mutateDbOps(
2352
- state3,
2353
- [{ op: "patch", key: spItemKey(spaceId, contentKey), value: { pinned } }],
2354
- apiOpts
2355
- );
2356
- const effectiveUpdatedAt = res?.applied?.[0]?.updatedAt ?? nowMs;
2357
- updatedSpaceData = await syncLocalSpaceEntityCache(thunkAPI, spaceKey, {
2358
- ...spaceData,
2359
- contents: {
2360
- ...spaceData.contents ?? {},
2361
- [contentKey]: {
2362
- ...spaceData.contents[contentKey],
2363
- pinned,
2364
- updatedAt: effectiveUpdatedAt
2365
- }
2366
- },
2367
- updatedAt: effectiveUpdatedAt
2368
- });
2369
- } catch (apiError) {
2370
- throw new Error(`\u66F4\u65B0\u5185\u5BB9\u7F6E\u9876\u72B6\u6001\u5931\u8D25: ${apiError.message || "\u672A\u77E5\u9519\u8BEF"}`);
2371
- }
2372
- } else {
2373
- try {
2374
- updatedSpaceData = await dispatch(
2375
- patch({ dbKey: spaceKey, changes, preferredServerOrigin: sourceServerOrigin })
2376
- ).unwrap();
2377
- } catch (patchError) {
2378
- throw new Error(`\u66F4\u65B0\u5185\u5BB9\u7F6E\u9876\u72B6\u6001\u5931\u8D25: ${patchError.message || "\u672A\u77E5\u9519\u8BEF"}`);
2379
- }
2380
- }
2381
- await patchIndividualContentRecord(
2382
- dispatch,
2383
- contentKey,
2384
- { pinned },
2385
- sourceServerOrigin,
2386
- "\u7F6E\u9876\u72B6\u6001\u5DF2\u5199\u5165\u7A7A\u95F4\uFF0C\u4F46\u540C\u6B65\u72EC\u7ACB\u8BB0\u5F55\u5931\u8D25"
2387
- );
2388
- return { spaceId, updatedSpaceData };
2389
- };
2390
-
2391
- // packages/create/space/content/updateContentCategoryAction.ts
2392
- var updateContentCategoryAction = async (input, thunkAPI) => {
2393
- const { spaceId, contentKey, categoryId: targetContainerId } = input;
2394
- const { dispatch, getState } = thunkAPI;
2395
- const state3 = getState();
2396
- const userId = selectIdentityUserId(state3);
2397
- if (!userId) {
2398
- throw new Error("User is not logged in.");
2399
- }
2400
- if (!contentKey || typeof contentKey !== "string" || contentKey.trim() === "") {
2401
- throw new Error("Invalid contentKey provided.");
2402
- }
2403
- if (typeof targetContainerId !== "string") {
2404
- throw new Error("Invalid target container ID provided (must be a string).");
2405
- }
2406
- const spaceKey = createSpaceKey.space(spaceId);
2407
- let spaceData = null;
2408
- try {
2409
- spaceData = await dispatch(read({
2410
- dbKey: spaceKey
2411
- })).unwrap();
2412
- } catch (readError) {
2413
- console.error(
2414
- `[updateContentCategoryAction] Failed to read space data for key ${spaceKey}:`,
2415
- readError
2416
- );
2417
- throw new Error(
2418
- `\u65E0\u6CD5\u52A0\u8F7D\u7A7A\u95F4\u6570\u636E: ${spaceId}, \u539F\u56E0: ${readError.message || "\u672A\u77E5\u9519\u8BEF"}`
2419
- );
2420
- }
2421
- if (!spaceData) {
2422
- throw new Error(`\u7A7A\u95F4\u4E0D\u5B58\u5728: ${spaceId}`);
2423
- }
2424
- try {
2425
- checkSpaceMembership(spaceData, userId);
2426
- } catch (permissionError) {
2427
- throw new Error(`\u6743\u9650\u4E0D\u8DB3\uFF0C\u65E0\u6CD5\u4FEE\u6539\u5185\u5BB9\u5206\u7C7B: ${permissionError.message}`);
2428
- }
2429
- const currentContent = spaceData.contents?.[contentKey];
2430
- if (!currentContent) {
2431
- console.warn(
2432
- `[updateContentCategoryAction] Content ${contentKey} not found in space ${spaceId}.`
2433
- );
2434
- throw new Error("Content not found");
2435
- }
2436
- if (targetContainerId !== UNCATEGORIZED_ID) {
2437
- if (!spaceData.categories[targetContainerId]) {
2438
- console.warn(
2439
- `[updateContentCategoryAction] Target category ${targetContainerId} not found or invalid in space ${spaceId}. Cannot move content.`
2440
- );
2441
- throw new Error("Target category not found or is invalid");
2442
- }
2443
- }
2444
- const now = Date.now();
2445
- const categoryIdValueForPatch = targetContainerId === UNCATEGORIZED_ID ? null : targetContainerId;
2446
- const currentCategoryId = currentContent.categoryId;
2447
- let needsUpdate = true;
2448
- if (categoryIdValueForPatch === null && currentCategoryId === void 0) {
2449
- needsUpdate = false;
2450
- } else if (categoryIdValueForPatch === currentCategoryId) {
2451
- needsUpdate = false;
2452
- }
2453
- let changes = null;
2454
- if (needsUpdate) {
2455
- changes = {
2456
- contents: {
2457
- // 使用动态键更新指定的 contentKey
2458
- [contentKey]: {
2459
- // --- 修改: 使用计算出的 categoryIdValueForPatch ---
2460
- categoryId: categoryIdValueForPatch,
2461
- // null 或 目标分类 ID
2462
- updatedAt: now
2463
- // 更新内容的 updatedAt
2464
- }
2465
- },
2466
- updatedAt: now
2467
- // 更新顶层的 updatedAt
2468
- };
2469
- } else {
2470
- console.log(
2471
- `[updateContentCategoryAction] No category change needed for ${contentKey}. Skipping patch.`
2472
- );
2473
- return { spaceId, updatedSpaceData: spaceData };
2474
- }
2475
- let updatedSpaceData;
2476
- if (isRemoteAccountSpace(spaceData, state3)) {
2477
- try {
2478
- const res = await mutateDbOps(state3, [
2479
- {
2480
- op: "patch",
2481
- key: spItemKey(spaceId, contentKey),
2482
- value: { categoryId: categoryIdValueForPatch }
2483
- }
2484
- ]);
2485
- const effectiveUpdatedAt = res?.applied?.[0]?.updatedAt ?? now;
2486
- const nextEntry = {
2487
- ...currentContent,
2488
- updatedAt: effectiveUpdatedAt
2489
- };
2490
- if (categoryIdValueForPatch === null) {
2491
- delete nextEntry.categoryId;
2492
- } else {
2493
- nextEntry.categoryId = categoryIdValueForPatch;
2494
- }
2495
- updatedSpaceData = await syncLocalSpaceEntityCache(thunkAPI, spaceKey, {
2496
- ...spaceData,
2497
- contents: {
2498
- ...spaceData.contents ?? {},
2499
- [contentKey]: nextEntry
2500
- },
2501
- updatedAt: effectiveUpdatedAt
2502
- });
2503
- } catch (apiError) {
2504
- console.error(
2505
- `[updateContentCategoryAction] Failed to mutate item via db/mutate for ${spaceKey}:`,
2506
- apiError
2507
- );
2508
- throw new Error(`\u66F4\u65B0\u5185\u5BB9\u5206\u7C7B\u5931\u8D25: ${apiError.message || "\u672A\u77E5\u9519\u8BEF"}`);
2509
- }
2510
- } else {
2511
- try {
2512
- updatedSpaceData = await dispatch(
2513
- patch({ dbKey: spaceKey, changes })
2514
- ).unwrap();
2515
- } catch (patchError) {
2516
- console.error(
2517
- `[updateContentCategoryAction] Failed to patch space data for key ${spaceKey}:`,
2518
- patchError
2519
- );
2520
- throw new Error(`\u66F4\u65B0\u5185\u5BB9\u5206\u7C7B\u5931\u8D25: ${patchError.message || "\u672A\u77E5\u9519\u8BEF"}`);
2521
- }
2522
- }
2523
- return { spaceId, updatedSpaceData };
2524
- };
2525
-
2526
- // packages/create/space/content/spaceFileVersions.ts
2527
- var normalizeFileName = (name) => typeof name === "string" ? name.trim().normalize("NFC") : "";
2528
- var versionsOf = (entryKey, entry) => {
2529
- if (Array.isArray(entry.versions) && entry.versions.length > 0) {
2530
- return entry.versions.filter((v) => v && typeof v.fileKey === "string");
2531
- }
2532
- return [
2533
- {
2534
- fileKey: entry.contentKey || entryKey,
2535
- sha256: entry.sha256 || "",
2536
- size: typeof entry.fileSize === "number" ? entry.fileSize : 0,
2537
- uploadedAt: typeof entry.createdAt === "number" ? entry.createdAt : 0
2538
- }
2539
- ];
2540
- };
2541
- var findSameNameFileEntries = (contents, originalName) => {
2542
- const target = normalizeFileName(originalName);
2543
- if (!target || !contents) return [];
2544
- return Object.entries(contents).filter(([, value]) => Boolean(value)).map(([entryKey, value]) => ({ entryKey, entry: value })).filter(
2545
- ({ entry }) => entry.type === "file" && normalizeFileName(entry.originalName ?? entry.title) === target
2546
- );
2547
- };
2548
- var sortVersions = (versions) => [...versions].sort(
2549
- (a, b) => a.uploadedAt - b.uploadedAt || a.fileKey.localeCompare(b.fileKey)
2550
- );
2551
- var mergeVersions = (groups) => {
2552
- const byKey = /* @__PURE__ */ new Map();
2553
- for (const { entryKey, entry } of groups) {
2554
- for (const v of versionsOf(entryKey, entry)) {
2555
- const prev = byKey.get(v.fileKey);
2556
- if (!prev || !prev.sha256 && v.sha256) byKey.set(v.fileKey, v);
2557
- }
2558
- }
2559
- return sortVersions([...byKey.values()]);
2560
- };
2561
- var planSpaceFileUpload = (contents, originalName, sha256) => {
2562
- const same = findSameNameFileEntries(contents, originalName);
2563
- if (same.length === 0) return { kind: "new_file" };
2564
- const primary = pickPrimary(same);
2565
- const current = primary.entry.contentKey || primary.entryKey;
2566
- const versions = mergeVersions(same);
2567
- const currentVersion = versions.find((v) => v.fileKey === current);
2568
- if (currentVersion?.sha256 && currentVersion.sha256 === sha256) {
2569
- return { kind: "unchanged", entryKey: primary.entryKey, currentKey: current };
2570
- }
2571
- const older = versions.find((v) => v.sha256 && v.sha256 === sha256);
2572
- if (older) {
2573
- return { kind: "restore_existing", entryKey: primary.entryKey, versionKey: older.fileKey };
2574
- }
2575
- return { kind: "new_version", entryKey: primary.entryKey };
2576
- };
2577
- var pickPrimary = (same) => [...same].sort((a, b) => {
2578
- const at = Math.max(...versionsOf(a.entryKey, a.entry).map((v) => v.uploadedAt));
2579
- const bt = Math.max(...versionsOf(b.entryKey, b.entry).map((v) => v.uploadedAt));
2580
- return bt - at || b.entryKey.localeCompare(a.entryKey);
2581
- })[0];
2582
- var buildVersionedEntryPatch = (input) => {
2583
- const { same, extraVersion, now } = input;
2584
- const versions = mergeVersions(
2585
- extraVersion ? [...same, { entryKey: extraVersion.fileKey, entry: { versions: [extraVersion] } }] : same
2586
- );
2587
- const currentKey = input.currentKey ?? versions[versions.length - 1].fileKey;
2588
- const current = versions.find((v) => v.fileKey === currentKey);
2589
- if (!current) throw new Error(`Version ${currentKey} not found for this file.`);
2590
- const template = same.length > 0 ? pickPrimary(same).entry : {};
2591
- const patch2 = {};
2592
- for (const { entryKey } of same) {
2593
- if (entryKey !== currentKey) patch2[entryKey] = null;
2594
- }
2595
- patch2[currentKey] = {
2596
- ...template,
2597
- contentKey: currentKey,
2598
- currentVersionKey: currentKey,
2599
- fileSize: current.size,
2600
- versions,
2601
- updatedAt: now,
2602
- ...input.restoredFrom ? { restoredFromVersionKey: input.restoredFrom } : {}
2603
- };
2604
- return patch2;
2605
- };
2606
- var sha256Hex = async (file) => {
2607
- const digest = await crypto.subtle.digest("SHA-256", await file.arrayBuffer());
2608
- return Array.from(new Uint8Array(digest)).map((b) => b.toString(16).padStart(2, "0")).join("");
2609
- };
2610
-
2611
- // packages/create/space/content/uploadAndAddFileToSpaceAction.ts
2612
- var uploadQueues = /* @__PURE__ */ new Map();
2613
- var serialize = (key, task) => {
2614
- const prev = uploadQueues.get(key) ?? Promise.resolve();
2615
- const next = prev.catch(() => void 0).then(task);
2616
- uploadQueues.set(key, next);
2617
- void next.finally(() => {
2618
- if (uploadQueues.get(key) === next) uploadQueues.delete(key);
2619
- }).catch(() => void 0);
2620
- return next;
2621
- };
2622
- var readSpaceOrNull = async (dispatch, spaceId) => {
2623
- try {
2624
- return await dispatch(read({ dbKey: createSpaceKey.space(spaceId) })).unwrap() ?? null;
2625
- } catch {
2626
- return null;
2627
- }
2628
- };
2629
- var reconcileSameNameEntries = async (thunkAPI, spaceId, originalName, options = {}) => {
2630
- let updated = await reconcileOnce(thunkAPI, spaceId, originalName, options);
2631
- for (let attempt = 0; attempt < 2 && updated; attempt += 1) {
2632
- const same = findSameNameFileEntries(updated.contents, originalName);
2633
- const keys = new Set(mergeVersions(same).map((v) => v.fileKey));
2634
- const missingOwn = options.extraVersion && !keys.has(options.extraVersion.fileKey);
2635
- if (same.length <= 1 && !missingOwn) break;
2636
- const fresh = await readSpaceOrNull(thunkAPI.dispatch, spaceId);
2637
- const freshSame = findSameNameFileEntries(fresh?.contents, originalName);
2638
- const freshKeys = new Set(mergeVersions(freshSame).map((v) => v.fileKey));
2639
- const stillMissing = options.extraVersion && !freshKeys.has(options.extraVersion.fileKey);
2640
- if (freshSame.length <= 1 && !stillMissing) {
2641
- updated = fresh;
2642
- break;
2643
- }
2644
- updated = await reconcileOnce(thunkAPI, spaceId, originalName, {
2645
- ...stillMissing ? { extraVersion: options.extraVersion } : {}
2646
- });
2647
- }
2648
- return updated;
2649
- };
2650
- var reconcileOnce = async (thunkAPI, spaceId, originalName, options = {}) => {
2651
- const { dispatch, getState } = thunkAPI;
2652
- const spaceData = await readSpaceOrNull(dispatch, spaceId);
2653
- if (!spaceData) return null;
2654
- checkSpaceMembership(spaceData, selectIdentityUserId(getState()));
2655
- const same = findSameNameFileEntries(spaceData.contents, originalName);
2656
- if (same.length === 0 && !options.extraVersion) return spaceData;
2657
- const contentsPatch = buildVersionedEntryPatch({ same, now: Date.now(), ...options });
2658
- return await dispatch(
2659
- patch({
2660
- dbKey: createSpaceKey.space(spaceId),
2661
- changes: {
2662
- contents: contentsPatch,
2663
- updatedAt: Date.now(),
2664
- ...localSpaceAuthorityPatchStamp(spaceData)
2665
- }
2666
- })
2667
- ).unwrap();
2668
- };
2669
- var uploadAndAddFileToSpaceAction = async (payload, thunkAPI) => {
2670
- const { spaceId, file } = payload;
2671
- const userId = selectIdentityUserId(thunkAPI.getState());
2672
- if (!userId) {
2673
- throw new Error("Cannot upload a file to a space without an authenticated user.");
2674
- }
2675
- return serialize(
2676
- `${spaceId}\0${file.name}`,
2677
- () => uploadOnce(payload, thunkAPI, userId)
2678
- );
2679
- };
2680
- var uploadOnce = async (payload, thunkAPI, userId) => {
2681
- const { spaceId, file, categoryId } = payload;
2682
- const { dispatch } = thunkAPI;
2683
- try {
2684
- const sha256 = await sha256Hex(file);
2685
- const existingSpace = await readSpaceOrNull(dispatch, spaceId);
2686
- const plan = existingSpace ? planSpaceFileUpload(existingSpace.contents, file.name, sha256) : { kind: "new_file" };
2687
- if (plan.kind === "unchanged") {
2688
- return {
2689
- spaceId,
2690
- updatedSpaceData: existingSpace,
2691
- contentKey: plan.currentKey,
2692
- fileId: plan.currentKey.split("-").slice(2).join("-"),
2693
- outcome: "unchanged"
2694
- };
2695
- }
2696
- if (plan.kind === "restore_existing") {
2697
- const updated = await reconcileSameNameEntries(thunkAPI, spaceId, file.name, {
2698
- currentKey: plan.versionKey,
2699
- restoredFrom: plan.entryKey
2700
- });
2701
- return {
2702
- spaceId,
2703
- updatedSpaceData: updated ?? existingSpace,
2704
- contentKey: plan.versionKey,
2705
- fileId: plan.versionKey.split("-").slice(2).join("-"),
2706
- outcome: "restored_existing"
2707
- };
2708
- }
2709
- const id = ulid();
2710
- const dbKey = fileKey.single(userId, id);
2711
- const contentType = "file" /* FILE */;
2712
- const fileCategory = resolveFileCategory({
2713
- mimeType: file.type,
2714
- fileName: file.name
2715
- });
2716
- const fileMetadata = await uploadFileAction(
2717
- // 这是「上传为 Space 资产」,不是「把个人文件收录进 Space」:
2718
- // 明确声明 Space 归属,服务端校验成员身份后落库
2719
- // `ownerType:"space"` + `ownerId:<spaceId>`,其他成员据此可读原件。
2720
- // 声明只是请求,服务端(uploadOwnership.ts)才是归属权威。
2721
- { file, customKey: dbKey, userId, ownerType: "space", spaceId },
2722
- thunkAPI
2723
- );
2724
- if (!fileMetadata) {
2725
- throw new Error("Upload failed, no metadata returned");
2726
- }
2727
- const contentKey = fileMetadata.dbKey || dbKey;
2728
- const title = file.name;
2729
- const fileSize = asOptionalFiniteNumber(file.size);
2730
- const version3 = {
2731
- fileKey: contentKey,
2732
- sha256,
2733
- size: fileSize ?? 0,
2734
- uploadedAt: Date.now()
2735
- };
2736
- const addAsNewFile = async () => {
2737
- const result2 = await addContentAction({
2738
- spaceId,
2739
- contentKey,
2740
- title,
2741
- type: contentType,
2742
- fileCategory,
2743
- mimeType: file.type || void 0,
2744
- fileSize,
2745
- originalName: file.name,
2746
- categoryId
2747
- }, thunkAPI);
2748
- return result2;
2749
- };
2750
- const result = plan.kind === "new_file" ? await addAsNewFile() : { spaceId, updatedSpaceData: existingSpace };
2751
- await dispatch(
2752
- patch({
2753
- dbKey: contentKey,
2754
- changes: {
2755
- title,
2756
- spaceId,
2757
- fileCategory,
2758
- fileSize,
2759
- originalName: file.name
2760
- }
2761
- })
2762
- ).unwrap();
2763
- const reconciled = await reconcileSameNameEntries(thunkAPI, spaceId, file.name, {
2764
- extraVersion: version3,
2765
- currentKey: contentKey
2766
- }).catch((error) => {
2767
- if (plan.kind === "new_version") throw error;
2768
- console.warn("[uploadAndAddFileToSpace] version reconcile failed", error);
2769
- return null;
2770
- });
2771
- if (typeof window !== "undefined") {
2772
- emitUserDataUpdated();
2773
- }
2774
- return {
2775
- ...result,
2776
- ...reconciled ? { updatedSpaceData: reconciled } : {},
2777
- contentKey,
2778
- fileId: fileMetadata.id,
2779
- outcome: plan.kind === "new_file" ? "new_file" : "new_version"
2780
- };
2781
- } catch (error) {
2782
- console.error("Upload and add file error:", error);
2783
- throw error;
2784
- }
2785
- };
2786
- var restoreSpaceFileVersionAction = async (input, thunkAPI) => {
2787
- const { spaceId, contentKey, versionKey } = input;
2788
- const spaceData = await readSpaceOrNull(thunkAPI.dispatch, spaceId);
2789
- if (!spaceData) throw new Error(`\u65E0\u6CD5\u52A0\u8F7D\u7A7A\u95F4\u6570\u636E: ${spaceId}`);
2790
- const entry = spaceData.contents?.[contentKey];
2791
- if (!entry || entry.type !== "file" /* FILE */) throw new Error("File not found in space");
2792
- const versions = Array.isArray(entry.versions) ? entry.versions : [];
2793
- if (!versions.some((v) => v.fileKey === versionKey)) {
2794
- throw new Error("Version not found for this file");
2795
- }
2796
- const name = entry.originalName ?? entry.title;
2797
- const updated = await serialize(
2798
- `${spaceId}\0${name}`,
2799
- () => reconcileSameNameEntries(thunkAPI, spaceId, name, {
2800
- currentKey: versionKey,
2801
- restoredFrom: contentKey
2802
- })
2803
- );
2804
- return { spaceId, updatedSpaceData: updated ?? spaceData, contentKey: versionKey };
2805
- };
2806
-
2807
- // packages/create/space/spaceCollapsedState.ts
2808
- var SPACE_COLLAPSE_STORAGE_PREFIX = "space-collapsed-categories:";
2809
- var normalizeCollapsedCategories = (value) => {
2810
- const entries = Object.entries(asRecordOrEmpty(value)).filter(
2811
- ([key, collapsed]) => typeof key === "string" && typeof collapsed === "boolean"
2812
- );
2813
- return Object.fromEntries(entries);
2814
- };
2815
- var storageKeyForSpace = (spaceId) => `${SPACE_COLLAPSE_STORAGE_PREFIX}${spaceId}`;
2816
- var readStoredCollapsedCategories = (spaceId, storage) => {
2817
- if (!spaceId || !storage) return {};
2818
- try {
2819
- const raw = storage.getItem(storageKeyForSpace(spaceId));
2820
- if (!raw) return { [UNCATEGORIZED_ID]: false };
2821
- return normalizeCollapsedCategories(JSON.parse(raw));
2822
- } catch (error) {
2823
- console.warn("[Space] \u8BFB\u53D6\u5206\u7C7B\u6298\u53E0\u72B6\u6001\u5931\u8D25:", error);
2824
- return {};
2825
- }
2826
- };
2827
- var writeStoredCollapsedCategories = (spaceId, collapsedCategories, storage) => {
2828
- if (!spaceId || !storage) return;
2829
- try {
2830
- storage.setItem(
2831
- storageKeyForSpace(spaceId),
2832
- JSON.stringify(normalizeCollapsedCategories(collapsedCategories))
2833
- );
2834
- } catch (error) {
2835
- console.warn("[Space] \u4FDD\u5B58\u5206\u7C7B\u6298\u53E0\u72B6\u6001\u5931\u8D25:", error);
2836
- }
2837
- };
2838
-
2839
- // packages/create/space/spaceUiStore.ts
2840
- var import_react2 = __toESM(require_react(), 1);
2841
- var DEFAULT_COLLAPSED_CATEGORIES = {
2842
- [UNCATEGORIZED_ID]: false
2843
- };
2844
- var FAVORITES_COLLAPSED_STORAGE_KEY = "nolo-sidebar-favorites-collapsed";
2845
- var readStoredFavoritesCollapsed = () => {
2846
- try {
2847
- if (typeof window === "undefined") return false;
2848
- return window.localStorage.getItem(FAVORITES_COLLAPSED_STORAGE_KEY) === "1";
2849
- } catch {
2850
- return false;
2851
- }
2852
- };
2853
- var createInitialState2 = () => ({
2854
- favoritesCollapsed: readStoredFavoritesCollapsed(),
2855
- collapsedCategories: {},
2856
- collapsedCategoriesSpaceId: null
2857
- });
2858
- var state2 = createInitialState2();
2859
- var listeners2 = /* @__PURE__ */ new Set();
2860
- var version2 = 0;
2861
- var notify2 = () => {
2862
- version2 += 1;
2863
- for (const listener of listeners2) {
2864
- try {
2865
- listener();
2866
- } catch {
2867
- }
2868
- }
2869
- };
2870
- function getCollapsedCategories() {
2871
- return state2.collapsedCategories;
2872
- }
2873
- function setCollapsedCategories(categories, spaceId) {
2874
- state2 = {
2875
- ...state2,
2876
- collapsedCategories: categories,
2877
- collapsedCategoriesSpaceId: spaceId
2878
- };
2879
- notify2();
2880
- }
2881
- function toggleCategoryCollapse(categoryId) {
2882
- const current = state2.collapsedCategories[categoryId] ?? (DEFAULT_COLLAPSED_CATEGORIES[categoryId] ?? true);
2883
- state2 = {
2884
- ...state2,
2885
- collapsedCategories: {
2886
- ...state2.collapsedCategories,
2887
- [categoryId]: !current
2888
- }
2889
- };
2890
- notify2();
2891
- }
2892
- function expandCategoryInCollapsed(categoryId, spaceId) {
2893
- if (!categoryId || categoryId === UNCATEGORIZED_ID) return;
2894
- state2 = {
2895
- ...state2,
2896
- collapsedCategories: {
2897
- ...state2.collapsedCategories,
2898
- [categoryId]: false
2899
- }
2900
- };
2901
- if (typeof window !== "undefined") {
2902
- writeStoredCollapsedCategories(
2903
- spaceId,
2904
- state2.collapsedCategories,
2905
- window.localStorage
2906
- );
2907
- }
2908
- notify2();
2909
- }
2910
-
2911
- // packages/create/space/content/contentThunks.ts
2912
- var syncCurrentSpaceIfNormalizedMatch = (spaceId, updatedSpaceData) => {
2913
- const normalizedSpaceId = normalizeSpaceId(spaceId);
2914
- const rawSpaceId = getCurrentSpaceIdRaw();
2915
- const normalizedCurrentSpaceId = rawSpaceId ? normalizeSpaceId(rawSpaceId) : null;
2916
- if (normalizedCurrentSpaceId === normalizedSpaceId && updatedSpaceData) {
2917
- updateCurrentSpaceIfMatch(spaceId, updatedSpaceData);
2918
- }
2919
- };
2920
- var addContentToSpace = createPlainAsyncThunk(
2921
- "space/addContentToSpace",
2922
- async (input, thunkAPI) => {
2923
- const result = await addContentAction(input, thunkAPI);
2924
- const rawCategoryId = asTrimmedString(input.categoryId);
2925
- const expandCategoryId = rawCategoryId && rawCategoryId !== UNCATEGORIZED_ID ? rawCategoryId : null;
2926
- if (expandCategoryId) {
2927
- const collapsedCategories = {
2928
- ...getCollapsedCategories(),
2929
- [expandCategoryId]: false
2930
- };
2931
- if (typeof window !== "undefined") {
2932
- writeStoredCollapsedCategories(
2933
- result.spaceId,
2934
- collapsedCategories,
2935
- window.localStorage
2936
- );
2937
- }
2938
- expandCategoryInCollapsed(expandCategoryId, result.spaceId);
2939
- syncCurrentSpaceIfNormalizedMatch(
2940
- result.spaceId,
2941
- result.updatedSpaceData
2942
- );
2943
- return { ...result, expandCategoryId, collapsedCategories };
2944
- }
2945
- syncCurrentSpaceIfNormalizedMatch(result.spaceId, result.updatedSpaceData);
2946
- return { ...result, expandCategoryId: null };
2947
- }
2948
- );
2949
- var moveContentToSpace = createPlainAsyncThunk(
2950
- "space/moveContentToSpace",
2951
- async (arg, thunkAPI) => {
2952
- const payload = await moveContentAction(arg, thunkAPI);
2953
- const {
2954
- sourceSpaceId,
2955
- updatedSourceSpaceData,
2956
- targetSpaceId,
2957
- updatedTargetSpaceData
2958
- } = payload;
2959
- if (getCurrentSpaceIdRaw() === sourceSpaceId && updatedSourceSpaceData) {
2960
- updateCurrentSpaceIfMatch(sourceSpaceId, updatedSourceSpaceData);
2961
- }
2962
- if (getCurrentSpaceIdRaw() === targetSpaceId && updatedTargetSpaceData) {
2963
- updateCurrentSpaceIfMatch(targetSpaceId, updatedTargetSpaceData);
2964
- }
2965
- if (payload.error) {
2966
- throw new Error(payload.error);
2967
- }
2968
- return payload;
2969
- }
2970
- );
2971
- var unlinkSpaceContent = createPlainAsyncThunk(
2972
- "space/unlinkSpaceContent",
2973
- async (arg, thunkAPI) => {
2974
- const payload = await unlinkSpaceContentAction(arg, thunkAPI);
2975
- if (payload.updatedSpaceData && getCurrentSpaceIdRaw() === payload.spaceId) {
2976
- updateCurrentSpaceIfMatch(payload.spaceId, payload.updatedSpaceData);
2977
- }
2978
- if (payload.error) {
2979
- throw new Error(payload.error);
2980
- }
2981
- return payload;
2982
- }
2983
- );
2984
- var deleteContentFromSpace = createPlainAsyncThunk(
2985
- "space/deleteContentFromSpace",
2986
- async (arg, thunkAPI) => {
2987
- const payload = await deleteContentFromSpaceAction(arg, thunkAPI);
2988
- syncCurrentSpaceIfNormalizedMatch(
2989
- payload.spaceId,
2990
- payload.updatedSpaceData
2991
- );
2992
- return payload;
2993
- }
2994
- );
2995
- var uploadAndAddFileToSpace = createPlainAsyncThunk(
2996
- "space/uploadAndAddFileToSpace",
2997
- async (arg, thunkAPI) => {
2998
- const payload = await uploadAndAddFileToSpaceAction(arg, thunkAPI);
2999
- if (getCurrentSpaceIdRaw() === payload.spaceId) {
3000
- updateCurrentSpaceIfMatch(payload.spaceId, payload.updatedSpaceData);
3001
- }
3002
- return payload;
3003
- }
3004
- );
3005
- var restoreSpaceFileVersion = createPlainAsyncThunk(
3006
- "space/restoreSpaceFileVersion",
3007
- async (arg, thunkAPI) => {
3008
- const payload = await restoreSpaceFileVersionAction(arg, thunkAPI);
3009
- if (getCurrentSpaceIdRaw() === payload.spaceId) {
3010
- updateCurrentSpaceIfMatch(payload.spaceId, payload.updatedSpaceData);
3011
- }
3012
- return payload;
3013
- }
3014
- );
3015
- var updateContentTitle = createPlainAsyncThunk(
3016
- "space/updateContentTitle",
3017
- async (arg, thunkAPI) => {
3018
- try {
3019
- const payload = await updateContentTitleAction(arg, thunkAPI);
3020
- if (getCurrentSpaceIdRaw() === payload.spaceId) {
3021
- updateCurrentSpaceIfMatch(payload.spaceId, payload.updatedSpaceData);
3022
- }
3023
- return payload;
3024
- } catch (error) {
3025
- const message = error?.message || "\u6807\u9898\u4FDD\u5B58\u5931\u8D25";
3026
- if (!message.includes("\u65E0\u6CD5\u52A0\u8F7D\u7A7A\u95F4\u6570\u636E")) {
3027
- toast.error(message);
3028
- }
3029
- throw error;
3030
- }
3031
- }
3032
- );
3033
- var updateContentPinned = createPlainAsyncThunk(
3034
- "space/updateContentPinned",
3035
- async (arg, thunkAPI) => {
3036
- try {
3037
- const payload = await updateContentPinnedAction(arg, thunkAPI);
3038
- if (payload.updatedSpaceData && payload.spaceId && getCurrentSpaceIdRaw() === payload.spaceId) {
3039
- updateCurrentSpaceIfMatch(payload.spaceId, payload.updatedSpaceData);
3040
- }
3041
- return payload;
3042
- } catch (error) {
3043
- toast.error(
3044
- error?.message || "\u7F6E\u9876\u72B6\u6001\u66F4\u65B0\u5931\u8D25"
3045
- );
3046
- throw error;
3047
- }
3048
- }
3049
- );
3050
- var updateContentCategory = createPlainAsyncThunk(
3051
- "space/updateContentCategory",
3052
- async (arg, thunkAPI) => {
3053
- const payload = await updateContentCategoryAction(arg, thunkAPI);
3054
- if (getCurrentSpaceIdRaw() === payload.spaceId) {
3055
- updateCurrentSpaceIfMatch(payload.spaceId, payload.updatedSpaceData);
3056
- }
3057
- return payload;
3058
- }
3059
- );
3060
-
3061
- export {
3062
- fetchAndCacheTableRows,
3063
- resolveCreationSpaceId,
3064
- getTableState,
3065
- loadTableRows,
3066
- addRow,
3067
- createTable,
3068
- deleteTable,
3069
- readStoredCollapsedCategories,
3070
- writeStoredCollapsedCategories,
3071
- DEFAULT_COLLAPSED_CATEGORIES,
3072
- getCollapsedCategories,
3073
- setCollapsedCategories,
3074
- toggleCategoryCollapse,
3075
- expandCategoryInCollapsed,
3076
- addContentToSpace,
3077
- moveContentToSpace,
3078
- unlinkSpaceContent,
3079
- deleteContentFromSpace,
3080
- uploadAndAddFileToSpace,
3081
- restoreSpaceFileVersion,
3082
- updateContentTitle,
3083
- updateContentPinned,
3084
- updateContentCategory
3085
- };