mcard-js 2.1.41 → 2.1.43

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 (388) hide show
  1. package/dist/{CardCollection-MXTUJV4J.js → CardCollection-7DKJWKAG.js} +3 -2
  2. package/dist/CardCollection-S4RE3RXP.js +10 -0
  3. package/dist/CardCollection-VPN7AAAX.js +10 -0
  4. package/dist/{IndexedDBEngine-2G5KCISA.js → IndexedDBEngine-7JOGM2MM.js} +3 -2
  5. package/dist/IndexedDBEngine-BGZHJK5L.js +12 -0
  6. package/dist/IndexedDBEngine-ZJ442GI7.js +12 -0
  7. package/dist/{LLMRuntime-GIGDMDEZ.js → LLMRuntime-OZNVAPXJ.js} +4 -3
  8. package/dist/{LLMRuntime-LBWUJ7ON.js → LLMRuntime-UPSEDSIK.js} +2 -2
  9. package/dist/{LambdaRuntime-B6D6IQKZ.js → LambdaRuntime-JZ4Q56TI.js} +6 -5
  10. package/dist/LambdaRuntime-PM3OUFHU.js +19 -0
  11. package/dist/LambdaRuntime-WBEK37AF.js +19 -0
  12. package/dist/LambdaRuntime-YKSBAT65.js +19 -0
  13. package/dist/{Loader-3LSJXJQG.js → Loader-7HQVYDPA.js} +2 -2
  14. package/dist/{Loader-BM56B2TX.js → Loader-NYWTV7CQ.js} +4 -3
  15. package/dist/{Loader-CYLAA4XU.js → Loader-OLKPY6HT.js} +3 -3
  16. package/dist/{MCard-H56VOJLR.js → MCard-OYI73CUI.js} +1 -1
  17. package/dist/{MCard-5LIREV2B.js → MCard-XHG3BZC7.js} +2 -2
  18. package/dist/{NetworkRuntime-IAFHPQSX.js → NetworkRuntime-VYCC5HSY.js} +16 -11
  19. package/dist/{NetworkRuntime-JNGKW3DY.js → NetworkRuntime-XQX3LDDI.js} +61 -33
  20. package/dist/{NetworkRuntime-CXPKIAOQ.js → NetworkRuntime-XZR733M5.js} +17 -12
  21. package/dist/{OllamaProvider-QPX2JXL2.js → OllamaProvider-FBZ5WW72.js} +1 -1
  22. package/dist/OllamaProvider-W6TPZNHD.js +9 -0
  23. package/dist/chunk-2NFGZ6PA.js +170 -0
  24. package/dist/{chunk-VXV35I5J.js → chunk-4TYRTQ4V.js} +48 -17
  25. package/dist/chunk-4VWWTGRW.js +497 -0
  26. package/dist/{chunk-4PDYHPR6.js → chunk-5GHZP7E5.js} +4 -2
  27. package/dist/{chunk-42VF42KH.js → chunk-5HZNWJFT.js} +4 -2
  28. package/dist/{chunk-DEYMHG5A.js → chunk-6MG5ZHAP.js} +58 -22
  29. package/dist/{chunk-7V37AAPK.js → chunk-7B4PABOL.js} +16 -7
  30. package/dist/chunk-A5S2PI37.js +47 -0
  31. package/dist/chunk-BFD4WSWU.js +497 -0
  32. package/dist/chunk-BSEFN25Q.js +32 -0
  33. package/dist/{chunk-3LPY36OG.js → chunk-CBEVE7RG.js} +20 -15
  34. package/dist/{chunk-A5AB4WQN.js → chunk-DPA3ZK4Q.js} +30 -21
  35. package/dist/{chunk-5FA54AMM.js → chunk-EJHX3VZL.js} +54 -21
  36. package/dist/{chunk-QXPHMSPA.js → chunk-GNF4WAPV.js} +22 -9
  37. package/dist/{chunk-XPG6B5IW.js → chunk-JHIA2BQK.js} +26 -13
  38. package/dist/{chunk-4I5IZILN.js → chunk-KGPICAQW.js} +10 -7
  39. package/dist/{chunk-4WBJPHZP.js → chunk-MST5AZXJ.js} +17 -8
  40. package/dist/{chunk-K35KFTEA.js → chunk-N6KDHCBC.js} +58 -33
  41. package/dist/{chunk-2R4ESMZB.js → chunk-NFO5NU6B.js} +5 -3
  42. package/dist/chunk-OKWBHCKC.js +170 -0
  43. package/dist/{chunk-FIE4LAJG.js → chunk-OX3K6UZJ.js} +5 -3
  44. package/dist/{chunk-6SEX42H2.js → chunk-R3K7DG7O.js} +21 -16
  45. package/dist/chunk-RB35Z35T.js +44 -0
  46. package/dist/{chunk-AWGFLRLI.js → chunk-SP4YPKPR.js} +51 -318
  47. package/dist/chunk-U7TSFDKX.js +217 -0
  48. package/dist/chunk-UP3SQX56.js +112 -0
  49. package/dist/{chunk-4EUEU4SM.js → chunk-VGIRC3HX.js} +13 -110
  50. package/dist/chunk-WGG7526Z.js +112 -0
  51. package/dist/{chunk-3JBSRALP.js → chunk-WNKP66IR.js} +10 -7
  52. package/dist/{chunk-DOC55MPG.js → chunk-WR6ISHCS.js} +11 -3
  53. package/dist/{chunk-52UNWVOD.js → chunk-ZVOPQ5BM.js} +54 -21
  54. package/dist/chunk-ZZMOPQER.js +217 -0
  55. package/dist/index.browser.cjs +79 -1454
  56. package/dist/index.browser.d.cts +2 -17
  57. package/dist/index.browser.d.ts +2 -17
  58. package/dist/index.browser.js +7 -6
  59. package/dist/index.cjs +306 -1631
  60. package/dist/index.d.cts +3 -1
  61. package/dist/index.d.ts +3 -1
  62. package/dist/index.js +49 -35
  63. package/dist/storage/SqliteNodeEngine.cjs +59 -1335
  64. package/dist/storage/SqliteNodeEngine.js +4 -3
  65. package/dist/storage/SqliteWasmEngine.cjs +57 -1335
  66. package/dist/storage/SqliteWasmEngine.js +4 -3
  67. package/package.json +12 -8
  68. package/dist/CardCollection-4OFJ6XQJ.js +0 -9
  69. package/dist/CardCollection-7PDWM24F.js +0 -9
  70. package/dist/CardCollection-CEFQ5PA6.js +0 -9
  71. package/dist/CardCollection-GUEYGN2Y.js +0 -9
  72. package/dist/CardCollection-KDO4CQ4B.js +0 -9
  73. package/dist/CardCollection-PB7ZY73E.js +0 -9
  74. package/dist/CardCollection-RK4DVH63.js +0 -9
  75. package/dist/CardCollection-T376E3TS.js +0 -9
  76. package/dist/CardCollection-WGCKKUOD.js +0 -9
  77. package/dist/CardCollection-XON2IWDU.js +0 -9
  78. package/dist/CardCollection-ZEI6FMP3.js +0 -9
  79. package/dist/EventProducer-MW6QF4IO.js +0 -47
  80. package/dist/EventProducer-V7RY2KKR.js +0 -47
  81. package/dist/FileIO.d.ts +0 -44
  82. package/dist/FileIO.d.ts.map +0 -1
  83. package/dist/FileIO.js +0 -203
  84. package/dist/FileIO.js.map +0 -1
  85. package/dist/IndexedDBEngine-7JI2CL32.js +0 -10
  86. package/dist/IndexedDBEngine-7OHQIRTI.js +0 -10
  87. package/dist/IndexedDBEngine-E5YJQG4U.js +0 -10
  88. package/dist/IndexedDBEngine-NV625E7L.js +0 -10
  89. package/dist/IndexedDBEngine-RPQS7ILF.js +0 -10
  90. package/dist/IndexedDBEngine-S3ZWCSI7.js +0 -10
  91. package/dist/IndexedDBEngine-T7OC5GRR.js +0 -10
  92. package/dist/LLMRuntime-BKB3CLXM.js +0 -16
  93. package/dist/LLMRuntime-BQUUFLAB.js +0 -16
  94. package/dist/LLMRuntime-TNBC4JCB.js +0 -16
  95. package/dist/LambdaRuntime-4YILF3G7.js +0 -15
  96. package/dist/LambdaRuntime-53TPVENI.js +0 -16
  97. package/dist/LambdaRuntime-73BSWP2G.js +0 -16
  98. package/dist/LambdaRuntime-AL5SBDCA.js +0 -17
  99. package/dist/LambdaRuntime-BYBUI7H5.js +0 -17
  100. package/dist/LambdaRuntime-JDZP3HIQ.js +0 -17
  101. package/dist/LambdaRuntime-JEI7RVWG.js +0 -16
  102. package/dist/LambdaRuntime-LCTHBYMV.js +0 -17
  103. package/dist/LambdaRuntime-LDA3G7IR.js +0 -16
  104. package/dist/LambdaRuntime-LF4FR6YA.js +0 -16
  105. package/dist/LambdaRuntime-O7JBVHO2.js +0 -16
  106. package/dist/LambdaRuntime-OFOTT464.js +0 -17
  107. package/dist/LambdaRuntime-Q6ISCHAD.js +0 -16
  108. package/dist/LambdaRuntime-TCZ42XCB.js +0 -16
  109. package/dist/LambdaRuntime-UKUOKJIW.js +0 -17
  110. package/dist/LambdaRuntime-VKLON4IB.js +0 -17
  111. package/dist/LambdaRuntime-WNYDBTS6.js +0 -16
  112. package/dist/LambdaRuntime-WPTX76CX.js +0 -17
  113. package/dist/Loader-4P7PEBCL.js +0 -11
  114. package/dist/Loader-HQ3QKMYM.js +0 -11
  115. package/dist/Loader-NCATGB67.js +0 -11
  116. package/dist/Loader-NRHGDQBD.js +0 -11
  117. package/dist/Loader-RT4NI6AT.js +0 -11
  118. package/dist/Loader-SSRY57SS.js +0 -11
  119. package/dist/Loader-W72QZ3T7.js +0 -11
  120. package/dist/Loader-WECRIXQW.js +0 -11
  121. package/dist/Loader-XFBIHCQF.js +0 -11
  122. package/dist/Loader.d.ts +0 -34
  123. package/dist/Loader.d.ts.map +0 -1
  124. package/dist/Loader.js +0 -190
  125. package/dist/Loader.js.map +0 -1
  126. package/dist/MCard-4J6WSBRF.js +0 -8
  127. package/dist/MCard-E3MRPTJF.js +0 -8
  128. package/dist/MCard-FCOIB6BP.js +0 -8
  129. package/dist/MCard-G4HUWHY5.js +0 -8
  130. package/dist/MCard-HFL7AFIH.js +0 -8
  131. package/dist/MCard-JOW6RBSO.js +0 -8
  132. package/dist/MCard-M4LKN4U2.js +0 -8
  133. package/dist/MCard-VB7UDUTN.js +0 -8
  134. package/dist/MCard-WOHE6SX6.js +0 -8
  135. package/dist/NetworkRuntime-2H7AQITA.js +0 -1571
  136. package/dist/NetworkRuntime-3MIUBNOF.js +0 -1571
  137. package/dist/NetworkRuntime-AOE2EJIM.js +0 -1571
  138. package/dist/NetworkRuntime-BQMDBUDO.js +0 -1570
  139. package/dist/NetworkRuntime-GMANLCAB.js +0 -1542
  140. package/dist/NetworkRuntime-L7P4VCGK.js +0 -1542
  141. package/dist/NetworkRuntime-LC7SUAOF.js +0 -1542
  142. package/dist/NetworkRuntime-OJWCWPBI.js +0 -1570
  143. package/dist/NetworkRuntime-ZJ3B4T3A.js +0 -1542
  144. package/dist/OllamaProvider-32RC36HD.js +0 -8
  145. package/dist/OllamaProvider-MQXSXLCA.js +0 -8
  146. package/dist/OllamaProvider-Q45BMOVN.js +0 -8
  147. package/dist/SqliteNodeEngine-WKVFWBNH.js +0 -9
  148. package/dist/StorageAdapter-DdDUiIvH.d.cts +0 -391
  149. package/dist/StorageAdapter-DdDUiIvH.d.ts +0 -391
  150. package/dist/StorageAdapter-Dw1BeOam.d.cts +0 -380
  151. package/dist/StorageAdapter-Dw1BeOam.d.ts +0 -380
  152. package/dist/chunk-23GCCCXB.js +0 -402
  153. package/dist/chunk-2ECISK2I.js +0 -354
  154. package/dist/chunk-2MRBTM72.js +0 -354
  155. package/dist/chunk-2THXO6FH.js +0 -2313
  156. package/dist/chunk-2VNRWIBZ.js +0 -389
  157. package/dist/chunk-2VOQRXWH.js +0 -296
  158. package/dist/chunk-34AYBZRO.js +0 -920
  159. package/dist/chunk-37EEYISR.js +0 -372
  160. package/dist/chunk-3E2TKOCZ.js +0 -354
  161. package/dist/chunk-3MMMJ7NH.js +0 -1068
  162. package/dist/chunk-437JTYVP.js +0 -292
  163. package/dist/chunk-4MQINOOG.js +0 -1218
  164. package/dist/chunk-4UIWXZHY.js +0 -1049
  165. package/dist/chunk-53S2EZCY.js +0 -290
  166. package/dist/chunk-5BIDGXA6.js +0 -987
  167. package/dist/chunk-5HXLTWYN.js +0 -296
  168. package/dist/chunk-5W2FDGUF.js +0 -371
  169. package/dist/chunk-6R4ERZMG.js +0 -1136
  170. package/dist/chunk-74YSNHEM.js +0 -2309
  171. package/dist/chunk-7H2BQZDK.js +0 -270
  172. package/dist/chunk-7KEWCCES.js +0 -1136
  173. package/dist/chunk-7PN2BUYF.js +0 -371
  174. package/dist/chunk-A2ZJA2EV.js +0 -389
  175. package/dist/chunk-ARPIBGRP.js +0 -1236
  176. package/dist/chunk-ATHNEEAG.js +0 -2309
  177. package/dist/chunk-AVXJOPUE.js +0 -354
  178. package/dist/chunk-B7VEU4S2.js +0 -204
  179. package/dist/chunk-C2TKISBR.js +0 -1213
  180. package/dist/chunk-CBH4YKB4.js +0 -2309
  181. package/dist/chunk-DP7HBRDL.js +0 -2309
  182. package/dist/chunk-DV7ZSH4W.js +0 -2309
  183. package/dist/chunk-DWXNZ5AJ.js +0 -642
  184. package/dist/chunk-EFKMZTT2.js +0 -270
  185. package/dist/chunk-FXJYXHG6.js +0 -266
  186. package/dist/chunk-G466I6RT.js +0 -229
  187. package/dist/chunk-GATPBTHL.js +0 -1142
  188. package/dist/chunk-GMQAHPBC.js +0 -292
  189. package/dist/chunk-GMWA2IJJ.js +0 -1105
  190. package/dist/chunk-GVX5LDLH.js +0 -371
  191. package/dist/chunk-HGENNKOJ.js +0 -355
  192. package/dist/chunk-HM2NBYHU.js +0 -292
  193. package/dist/chunk-IZWB5GCG.js +0 -389
  194. package/dist/chunk-J4HOFUKM.js +0 -2309
  195. package/dist/chunk-JIK2G3EH.js +0 -2313
  196. package/dist/chunk-JRXNWGSW.js +0 -1136
  197. package/dist/chunk-KRKK3KP6.js +0 -1081
  198. package/dist/chunk-KYXZHRUG.js +0 -389
  199. package/dist/chunk-L36L2VDL.js +0 -371
  200. package/dist/chunk-L5PZCES6.js +0 -204
  201. package/dist/chunk-L5U77ZEM.js +0 -1142
  202. package/dist/chunk-LQEKGX2T.js +0 -204
  203. package/dist/chunk-LWMUDMMQ.js +0 -1144
  204. package/dist/chunk-MLKGABMK.js +0 -9
  205. package/dist/chunk-NZ6OQ7UT.js +0 -92
  206. package/dist/chunk-O2UMNZGF.js +0 -903
  207. package/dist/chunk-OFHDMLNM.js +0 -355
  208. package/dist/chunk-PDBMNUMB.js +0 -316
  209. package/dist/chunk-PW4XS7M3.js +0 -850
  210. package/dist/chunk-QA2XQMMJ.js +0 -2313
  211. package/dist/chunk-QL2JFNA7.js +0 -389
  212. package/dist/chunk-QPZ2HNSU.js +0 -912
  213. package/dist/chunk-QVGVU6OS.js +0 -296
  214. package/dist/chunk-RCEU7PFH.js +0 -270
  215. package/dist/chunk-RSTKX7WM.js +0 -907
  216. package/dist/chunk-RXL2CW64.js +0 -266
  217. package/dist/chunk-RXUF6Y43.js +0 -2309
  218. package/dist/chunk-SIAA4J6H.js +0 -21
  219. package/dist/chunk-SOJ2UMO2.js +0 -986
  220. package/dist/chunk-T3AG6DXY.js +0 -296
  221. package/dist/chunk-TPCNKMGZ.js +0 -355
  222. package/dist/chunk-TPT3S5AX.js +0 -204
  223. package/dist/chunk-TXWGIEVH.js +0 -2313
  224. package/dist/chunk-TZFI54AU.js +0 -2313
  225. package/dist/chunk-U3FWUPD3.js +0 -717
  226. package/dist/chunk-UFW2VW2D.js +0 -266
  227. package/dist/chunk-UTAOS5Y7.js +0 -2313
  228. package/dist/chunk-V7VX5OJ6.js +0 -389
  229. package/dist/chunk-W2XGNMYB.js +0 -355
  230. package/dist/chunk-W3M4HJ4U.js +0 -2309
  231. package/dist/chunk-WMJGGREP.js +0 -296
  232. package/dist/chunk-WTNVQ5WS.js +0 -732
  233. package/dist/chunk-WVFWNVT2.js +0 -1050
  234. package/dist/chunk-WY7EYSYC.js +0 -1236
  235. package/dist/chunk-X42F7DE3.js +0 -373
  236. package/dist/chunk-XC7Y4I7L.js +0 -290
  237. package/dist/chunk-YFULZTKP.js +0 -270
  238. package/dist/chunk-YSVHXKSZ.js +0 -373
  239. package/dist/chunk-YWGVK5OS.js +0 -292
  240. package/dist/chunk-Z4BRNTO5.js +0 -2313
  241. package/dist/chunk-ZDUXDKPD.js +0 -292
  242. package/dist/chunk-ZXQ2W7LO.js +0 -355
  243. package/dist/chunk-ZXQELXXO.js +0 -378
  244. package/dist/index.browser.d.ts.map +0 -1
  245. package/dist/index.browser.js.map +0 -1
  246. package/dist/index.d.ts.map +0 -1
  247. package/dist/index.js.map +0 -1
  248. package/dist/lib-4XS34IPZ.js +0 -778
  249. package/dist/model/CardCollection.d.ts +0 -147
  250. package/dist/model/CardCollection.d.ts.map +0 -1
  251. package/dist/model/CardCollection.js +0 -272
  252. package/dist/model/CardCollection.js.map +0 -1
  253. package/dist/model/ContentTypeInterpreter.d.ts +0 -28
  254. package/dist/model/ContentTypeInterpreter.d.ts.map +0 -1
  255. package/dist/model/ContentTypeInterpreter.js +0 -147
  256. package/dist/model/ContentTypeInterpreter.js.map +0 -1
  257. package/dist/model/EventProducer.d.ts +0 -10
  258. package/dist/model/EventProducer.d.ts.map +0 -1
  259. package/dist/model/EventProducer.js +0 -46
  260. package/dist/model/EventProducer.js.map +0 -1
  261. package/dist/model/GTime.d.ts +0 -44
  262. package/dist/model/GTime.d.ts.map +0 -1
  263. package/dist/model/GTime.js +0 -91
  264. package/dist/model/GTime.js.map +0 -1
  265. package/dist/model/Handle.d.ts +0 -37
  266. package/dist/model/Handle.d.ts.map +0 -1
  267. package/dist/model/Handle.js +0 -90
  268. package/dist/model/Handle.js.map +0 -1
  269. package/dist/model/MCard.d.ts +0 -145
  270. package/dist/model/MCard.d.ts.map +0 -1
  271. package/dist/model/MCard.js +0 -180
  272. package/dist/model/MCard.js.map +0 -1
  273. package/dist/model/PCard.d.ts +0 -271
  274. package/dist/model/PCard.d.ts.map +0 -1
  275. package/dist/model/PCard.js +0 -558
  276. package/dist/model/PCard.js.map +0 -1
  277. package/dist/model/VCard.d.ts +0 -277
  278. package/dist/model/VCard.d.ts.map +0 -1
  279. package/dist/model/VCard.js +0 -573
  280. package/dist/model/VCard.js.map +0 -1
  281. package/dist/model/constants.d.ts +0 -45
  282. package/dist/model/constants.d.ts.map +0 -1
  283. package/dist/model/constants.js +0 -27
  284. package/dist/model/constants.js.map +0 -1
  285. package/dist/model/vcard_vocabulary.d.ts +0 -174
  286. package/dist/model/vcard_vocabulary.d.ts.map +0 -1
  287. package/dist/model/vcard_vocabulary.js +0 -187
  288. package/dist/model/vcard_vocabulary.js.map +0 -1
  289. package/dist/monads/Either.d.ts +0 -51
  290. package/dist/monads/Either.d.ts.map +0 -1
  291. package/dist/monads/Either.js +0 -82
  292. package/dist/monads/Either.js.map +0 -1
  293. package/dist/monads/IO.d.ts +0 -38
  294. package/dist/monads/IO.d.ts.map +0 -1
  295. package/dist/monads/IO.js +0 -66
  296. package/dist/monads/IO.js.map +0 -1
  297. package/dist/monads/Maybe.d.ts +0 -45
  298. package/dist/monads/Maybe.d.ts.map +0 -1
  299. package/dist/monads/Maybe.js +0 -73
  300. package/dist/monads/Maybe.js.map +0 -1
  301. package/dist/monads/Reader.d.ts +0 -29
  302. package/dist/monads/Reader.d.ts.map +0 -1
  303. package/dist/monads/Reader.js +0 -44
  304. package/dist/monads/Reader.js.map +0 -1
  305. package/dist/monads/State.d.ts +0 -33
  306. package/dist/monads/State.d.ts.map +0 -1
  307. package/dist/monads/State.js +0 -50
  308. package/dist/monads/State.js.map +0 -1
  309. package/dist/monads/Writer.d.ts +0 -29
  310. package/dist/monads/Writer.d.ts.map +0 -1
  311. package/dist/monads/Writer.js +0 -46
  312. package/dist/monads/Writer.js.map +0 -1
  313. package/dist/ptr/Bridgelet.d.ts +0 -180
  314. package/dist/ptr/Bridgelet.d.ts.map +0 -1
  315. package/dist/ptr/Bridgelet.js +0 -296
  316. package/dist/ptr/Bridgelet.js.map +0 -1
  317. package/dist/ptr/CLMIntrospection.d.ts +0 -169
  318. package/dist/ptr/CLMIntrospection.d.ts.map +0 -1
  319. package/dist/ptr/CLMIntrospection.js +0 -329
  320. package/dist/ptr/CLMIntrospection.js.map +0 -1
  321. package/dist/ptr/FaroSidecar.d.ts +0 -56
  322. package/dist/ptr/FaroSidecar.d.ts.map +0 -1
  323. package/dist/ptr/FaroSidecar.js +0 -102
  324. package/dist/ptr/FaroSidecar.js.map +0 -1
  325. package/dist/ptr/LensProtocol.d.ts +0 -84
  326. package/dist/ptr/LensProtocol.d.ts.map +0 -1
  327. package/dist/ptr/LensProtocol.js +0 -98
  328. package/dist/ptr/LensProtocol.js.map +0 -1
  329. package/dist/ptr/OpenTelemetrySidecar.d.ts +0 -144
  330. package/dist/ptr/OpenTelemetrySidecar.d.ts.map +0 -1
  331. package/dist/ptr/OpenTelemetrySidecar.js +0 -232
  332. package/dist/ptr/OpenTelemetrySidecar.js.map +0 -1
  333. package/dist/ptr/SandboxWorker.d.ts +0 -79
  334. package/dist/ptr/SandboxWorker.d.ts.map +0 -1
  335. package/dist/ptr/SandboxWorker.js +0 -298
  336. package/dist/ptr/SandboxWorker.js.map +0 -1
  337. package/dist/ptr/common_types.d.ts +0 -39
  338. package/dist/ptr/common_types.d.ts.map +0 -1
  339. package/dist/ptr/common_types.js +0 -12
  340. package/dist/ptr/common_types.js.map +0 -1
  341. package/dist/rag/GraphRAGEngine.d.ts +0 -26
  342. package/dist/rag/GraphRAGEngine.d.ts.map +0 -1
  343. package/dist/rag/GraphRAGEngine.js +0 -166
  344. package/dist/rag/GraphRAGEngine.js.map +0 -1
  345. package/dist/rag/HandleVectorStore.d.ts +0 -201
  346. package/dist/rag/HandleVectorStore.d.ts.map +0 -1
  347. package/dist/rag/HandleVectorStore.js +0 -527
  348. package/dist/rag/HandleVectorStore.js.map +0 -1
  349. package/dist/rag/PersistentIndexer.d.ts +0 -148
  350. package/dist/rag/PersistentIndexer.d.ts.map +0 -1
  351. package/dist/rag/PersistentIndexer.js +0 -302
  352. package/dist/rag/PersistentIndexer.js.map +0 -1
  353. package/dist/rag/index.d.ts +0 -20
  354. package/dist/rag/index.d.ts.map +0 -1
  355. package/dist/rag/index.js +0 -26
  356. package/dist/rag/index.js.map +0 -1
  357. package/dist/rag/semanticVersioning.d.ts +0 -187
  358. package/dist/rag/semanticVersioning.d.ts.map +0 -1
  359. package/dist/rag/semanticVersioning.js +0 -253
  360. package/dist/rag/semanticVersioning.js.map +0 -1
  361. package/dist/storage/IndexedDBEngine.d.ts +0 -33
  362. package/dist/storage/IndexedDBEngine.d.ts.map +0 -1
  363. package/dist/storage/IndexedDBEngine.js +0 -198
  364. package/dist/storage/IndexedDBEngine.js.map +0 -1
  365. package/dist/storage/SqliteNodeEngine.d.ts.map +0 -1
  366. package/dist/storage/SqliteNodeEngine.js.map +0 -1
  367. package/dist/storage/SqliteWasmEngine.d.ts.map +0 -1
  368. package/dist/storage/SqliteWasmEngine.js.map +0 -1
  369. package/dist/storage/StorageAdapter.d.ts +0 -42
  370. package/dist/storage/StorageAdapter.d.ts.map +0 -1
  371. package/dist/storage/StorageAdapter.js +0 -2
  372. package/dist/storage/StorageAdapter.js.map +0 -1
  373. package/dist/storage/VectorStore.d.ts +0 -202
  374. package/dist/storage/VectorStore.d.ts.map +0 -1
  375. package/dist/storage/VectorStore.js +0 -557
  376. package/dist/storage/VectorStore.js.map +0 -1
  377. package/dist/storage/schema.d.ts +0 -162
  378. package/dist/storage/schema.d.ts.map +0 -1
  379. package/dist/storage/schema.js +0 -335
  380. package/dist/storage/schema.js.map +0 -1
  381. package/dist/storage/schema_constants.d.ts +0 -7
  382. package/dist/storage/schema_constants.d.ts.map +0 -1
  383. package/dist/storage/schema_constants.js +0 -415
  384. package/dist/storage/schema_constants.js.map +0 -1
  385. package/dist/types/dots.d.ts +0 -206
  386. package/dist/types/dots.d.ts.map +0 -1
  387. package/dist/types/dots.js +0 -201
  388. package/dist/types/dots.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -176,1013 +176,51 @@ var init_GTime = __esm({
176
176
  }
177
177
  });
178
178
 
179
- // src/model/detectors/BinaryDetector.ts
180
- var BinarySignatureDetector;
181
- var init_BinaryDetector = __esm({
182
- "src/model/detectors/BinaryDetector.ts"() {
183
- "use strict";
184
- BinarySignatureDetector = class _BinarySignatureDetector {
185
- contentTypeName = "binary";
186
- // Signatures map: [Signature Bytes, Mime Type]
187
- static SIGNATURES = [
188
- [new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), "image/png"],
189
- [new Uint8Array([255, 216, 255]), "image/jpeg"],
190
- [new Uint8Array([71, 73, 70, 56, 55, 97]), "image/gif"],
191
- // GIF87a
192
- [new Uint8Array([71, 73, 70, 56, 57, 97]), "image/gif"],
193
- // GIF89a
194
- [new Uint8Array([66, 77]), "image/bmp"],
195
- // BM
196
- [new Uint8Array([0, 0, 1, 0]), "image/x-icon"],
197
- [new Uint8Array([0, 0, 2, 0]), "image/x-icon"],
198
- [new Uint8Array([37, 80, 68, 70]), "application/pdf"],
199
- // %PDF
200
- [new Uint8Array([80, 75, 3, 4]), "application/zip"],
201
- // PK..
202
- [new Uint8Array([31, 139, 8]), "application/gzip"],
203
- [new Uint8Array([82, 97, 114, 33, 26, 7, 0]), "application/x-rar-compressed"],
204
- [new Uint8Array([55, 122, 188, 175, 39, 28]), "application/x-7z-compressed"],
205
- [new Uint8Array([83, 81, 76, 105, 116, 101, 32, 102, 111, 114, 109, 97, 116, 32, 51, 0]), "application/x-sqlite3"]
206
- ];
207
- // Extension-to-MIME mapping for binary types (used when byte detection fails)
208
- static EXT_TO_MIME = {
209
- // Video
210
- ".mp4": "video/mp4",
211
- ".webm": "video/webm",
212
- ".avi": "video/x-msvideo",
213
- ".mov": "video/quicktime",
214
- ".mkv": "video/x-matroska",
215
- ".wmv": "video/x-ms-wmv",
216
- ".flv": "video/x-flv",
217
- ".m4v": "video/x-m4v",
218
- // Audio
219
- ".mp3": "audio/mpeg",
220
- ".ogg": "audio/ogg",
221
- ".flac": "audio/flac",
222
- ".aac": "audio/aac",
223
- ".m4a": "audio/mp4",
224
- ".wma": "audio/x-ms-wma",
225
- // Images (backup for when signature detection fails)
226
- ".png": "image/png",
227
- ".jpg": "image/jpeg",
228
- ".jpeg": "image/jpeg",
229
- ".gif": "image/gif",
230
- ".bmp": "image/bmp",
231
- ".ico": "image/x-icon",
232
- ".webp": "image/webp",
233
- ".svg": "image/svg+xml",
234
- // Documents
235
- ".pdf": "application/pdf",
236
- // Archives
237
- ".zip": "application/zip",
238
- ".gz": "application/gzip",
239
- ".rar": "application/x-rar-compressed",
240
- ".7z": "application/x-7z-compressed",
241
- ".tar": "application/x-tar",
242
- // Database
243
- ".db": "application/x-sqlite3",
244
- ".sqlite": "application/x-sqlite3",
245
- ".sqlite3": "application/x-sqlite3",
246
- // Fonts
247
- ".woff": "font/woff",
248
- ".woff2": "font/woff2",
249
- ".ttf": "font/ttf",
250
- ".otf": "font/otf",
251
- ".eot": "application/vnd.ms-fontobject"
252
- };
253
- detect(contentSample, lines, firstLine, fileExtension) {
254
- const mime = this.getMimeType(contentSample, lines, firstLine, fileExtension);
255
- return mime && mime !== "application/octet-stream" ? 0.95 : 0;
256
- }
257
- getMimeType(contentSample, lines, firstLine, fileExtension) {
258
- const bytes = this.toBytes(contentSample);
259
- const detected = this.detectFromBytes(bytes);
260
- if (detected !== "application/octet-stream") {
261
- return detected;
262
- }
263
- if (fileExtension) {
264
- let ext = fileExtension.toLowerCase();
265
- const lastDotIndex = ext.lastIndexOf(".");
266
- if (lastDotIndex > -1) {
267
- ext = ext.substring(lastDotIndex);
268
- } else if (!ext.startsWith(".")) {
269
- if (ext.includes("/") || ext.includes("\\")) {
270
- return "application/octet-stream";
271
- }
272
- ext = "." + ext;
273
- }
274
- const extMime = _BinarySignatureDetector.EXT_TO_MIME[ext];
275
- if (extMime) {
276
- return extMime;
277
- }
278
- }
279
- return "application/octet-stream";
280
- }
281
- /**
282
- * Detect MIME type directly from bytes.
283
- */
284
- detectFromBytes(bytes) {
285
- if (this.startsWith(bytes, new Uint8Array([82, 73, 70, 70]))) {
286
- return this.detectRiffFormat(bytes);
287
- }
288
- for (const [sig, mime] of _BinarySignatureDetector.SIGNATURES) {
289
- if (this.startsWith(bytes, sig)) {
290
- if (mime === "application/zip") {
291
- return this.detectZipType(bytes);
292
- }
293
- return mime;
294
- }
295
- }
296
- return "application/octet-stream";
297
- }
298
- toBytes(content) {
299
- if (content instanceof Uint8Array) return content;
300
- return new TextEncoder().encode(content);
301
- }
302
- startsWith(data, prefix) {
303
- if (data.length < prefix.length) return false;
304
- for (let i = 0; i < prefix.length; i++) {
305
- if (data[i] !== prefix[i]) return false;
306
- }
307
- return true;
308
- }
309
- detectRiffFormat(bytes) {
310
- if (bytes.length < 12) return "application/octet-stream";
311
- const format = new TextDecoder().decode(bytes.slice(8, 12));
312
- if (format === "WAVE") return "audio/wav";
313
- if (format === "WEBP") return "image/webp";
314
- return "application/octet-stream";
315
- }
316
- detectZipType(bytes) {
317
- const header = new TextDecoder().decode(bytes.slice(0, 2048));
318
- if (header.includes("[Content_Types].xml") && header.includes("_rels/.rels")) {
319
- if (header.includes("word/")) return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
320
- if (header.includes("xl/")) return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
321
- if (header.includes("ppt/")) return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
322
- }
323
- return "application/zip";
324
- }
325
- };
326
- }
327
- });
328
-
329
- // src/model/detectors/LanguageDetector.ts
330
- var ProgrammingLanguageDetector;
331
- var init_LanguageDetector = __esm({
332
- "src/model/detectors/LanguageDetector.ts"() {
333
- "use strict";
334
- ProgrammingLanguageDetector = class {
335
- contentTypeName = "code";
336
- detect(contentSample, lines, firstLine, fileExtension) {
337
- const mime = this.getMimeType(contentSample, lines, firstLine, fileExtension);
338
- return mime && mime !== "text/plain" ? 0.95 : 0;
339
- }
340
- getMimeType(contentSample, lines, firstLine, fileExtension) {
341
- const text = typeof contentSample === "string" ? contentSample : new TextDecoder().decode(contentSample);
342
- if (this.isPython(firstLine, text, lines)) {
343
- return "text/x-python";
344
- }
345
- const cType = this.detectCFamily(text);
346
- if (cType) return cType;
347
- const jsType = this.detectJsType(text);
348
- if (jsType) return jsType;
349
- if (this.isTypescript(text)) {
350
- return "text/typescript";
351
- }
352
- return "text/plain";
353
- }
354
- isPython(firstLine, text, lines) {
355
- if (/^\s*import\s+(\w+|\w+\.\w+)/m.test(text) || /^\s*from\s+(\w+|\w+\.\w+)\s+import\s+/m.test(text)) {
356
- const stdLibs = ["os", "sys", "re", "json", "math", "random", "datetime"];
357
- if (stdLibs.some((lib) => text.includes(`import ${lib}`) || text.includes(`from ${lib}`))) {
358
- return true;
359
- }
360
- }
361
- if (firstLine.startsWith("#!") && firstLine.toLowerCase().includes("python")) return true;
362
- if (text.includes("if __name__ ==") && text.includes("__main__")) return true;
363
- if (/^\s*def\s+\w+\s*\(/.test(text) && !text.includes("function")) return true;
364
- if (/^\s*class\s+\w+\s*[\(:]/m.test(text)) return true;
365
- if (/^\s*@\w+/m.test(text)) return true;
366
- let count = 0;
367
- const patterns = [
368
- /\bif\b.*?:/,
369
- /\belif\b.*?:/,
370
- /\belse\s*:/,
371
- /\bfor\b.*?\bin\b.*?:/,
372
- /\bwhile\b.*?:/,
373
- /\btry\s*:/,
374
- /\bexcept\b.*?:/,
375
- /\bfinally\s*:/,
376
- /\bNone\b/,
377
- /\bTrue\b/,
378
- /\bFalse\b/,
379
- /f["'].*?\{.*?\}["']/,
380
- // f-string
381
- /\bdef\b/,
382
- /\bclass\b/,
383
- /\bimport\b/,
384
- /\bfrom\b/,
385
- /\blambda\b.*?:/
386
- ];
387
- for (const p of patterns) {
388
- if (p.test(text)) count++;
389
- }
390
- const nonEmptyLines = lines.filter((l) => l.trim().length > 0).length;
391
- if (nonEmptyLines <= 5 && count >= 1) {
392
- return true;
393
- }
394
- return count >= 3;
395
- }
396
- detectCFamily(text) {
397
- const cPatterns = [
398
- /#include\s*<.*?>/,
399
- /#include\s*".*?"/,
400
- /\b(int|void|char|float|double)\s+main\s*\(.*\)\s*\{/,
401
- /\bstruct\s+\w+\s*\{/,
402
- /#define\s+\w+/,
403
- /printf\(.*?\);/,
404
- /scanf\(.*?\);/
405
- ];
406
- const cppPatterns = [
407
- /\bclass\s+\w+\s*\{/,
408
- /\bnamespace\s+\w+\s*\{/,
409
- /\btemplate\s*<.*?>/,
410
- /::/,
411
- /\bstd::/,
412
- /\bcout\s*<</,
413
- /\bcin\s*>>/,
414
- /\bnew\s+\w+/,
415
- /\bdelete\s+\w+/,
416
- /#include\s*<iostream>/
417
- ];
418
- let cCount = 0;
419
- let cppCount = 0;
420
- cPatterns.forEach((p) => {
421
- if (p.test(text)) cCount++;
422
- });
423
- cppPatterns.forEach((p) => {
424
- if (p.test(text)) cppCount++;
425
- });
426
- if (cppCount >= 2 || cppCount >= 1 && text.includes("std::")) return "text/x-c++";
427
- if (cCount >= 2) return "text/x-c";
428
- return null;
429
- }
430
- detectJsType(text) {
431
- const jsPatterns = [
432
- /function\s+\w+\s*\(/.test(text),
433
- // function foo(
434
- /\bconst\s+\w+\s*=/.test(text),
435
- /\blet\s+\w+\s*=/.test(text),
436
- /\bvar\s+\w+\s*=/.test(text),
437
- /\bimport\s+.*\s+from/.test(text),
438
- /\bexport\s+/.test(text),
439
- /\=\>\s*\{/.test(text),
440
- // Arrow func
441
- /console\.log\(/.test(text)
442
- ];
443
- const jsxPatterns = [
444
- /<\w+(>|\s+.*?>)[\s\S]*?<\/\w+>/m.test(text),
445
- /<\w+\s+\/>/m.test(text),
446
- /className=/.test(text),
447
- /React\.createElement/.test(text)
448
- ];
449
- const jsCount = jsPatterns.filter(Boolean).length;
450
- const jsxCount = jsxPatterns.filter(Boolean).length;
451
- if (jsxCount > 0 && (text.includes("import React") || text.includes('from "react"'))) return "text/jsx";
452
- if (jsxCount >= 2) return "text/jsx";
453
- if (jsCount >= 2) {
454
- const stripped = text.trim();
455
- if (stripped.startsWith("{") && stripped.endsWith("}") || stripped.startsWith("[") && stripped.endsWith("]")) {
456
- try {
457
- JSON.parse(text);
458
- if (jsCount < 2) return null;
459
- } catch {
460
- }
461
- }
462
- return "text/javascript";
463
- }
464
- return null;
465
- }
466
- isTypescript(text) {
467
- const tsPatterns = [
468
- /:\s*(string|number|boolean|any|void|null|undefined)\b/,
469
- /\binterface\s+\w+\s*\{/,
470
- /\bclass\s+\w+\s+implements\s+\w+/,
471
- /\btype\s+\w+\s*=/,
472
- /\b(public|private|protected)\s+/,
473
- /\bnamespace\s+\w+\s*\{/,
474
- /<\w+>/
475
- // Generics (simple check)
476
- ];
477
- let count = 0;
478
- tsPatterns.forEach((p) => {
479
- if (p.test(text)) count++;
480
- });
481
- return count >= 2;
482
- }
483
- };
484
- }
485
- });
486
-
487
- // src/model/detectors/MarkupDetectors.ts
488
- var XMLDetector, MarkdownDetector, PlainTextDetector;
489
- var init_MarkupDetectors = __esm({
490
- "src/model/detectors/MarkupDetectors.ts"() {
491
- "use strict";
492
- XMLDetector = class _XMLDetector {
493
- contentTypeName = "xml";
494
- static XML_DECLARATION = /^\s*<\?xml/i;
495
- static BASIC_TAG_PAIR = /<(\w+)[^>]*>.*?<\/\1>/s;
496
- detect(contentSample, lines, firstLine, fileExtension) {
497
- const text = typeof contentSample === "string" ? contentSample : new TextDecoder().decode(contentSample);
498
- let confidence = 0;
499
- if (fileExtension && fileExtension.toLowerCase() === ".xml") {
500
- confidence = Math.max(confidence, 0.95);
501
- }
502
- if (_XMLDetector.XML_DECLARATION.test(firstLine) || text.trim().startsWith("<?xml")) {
503
- confidence = Math.max(confidence, 0.95);
504
- }
505
- if (text.includes("<") && text.includes(">") && text.includes("</")) {
506
- confidence = Math.max(confidence, 0.5);
507
- if (_XMLDetector.BASIC_TAG_PAIR.test(text)) {
508
- confidence = Math.max(confidence, 0.7);
509
- }
510
- }
511
- if (text.toLowerCase().includes("<!doctype html")) {
512
- if (confidence > 0.3) confidence -= 0.4;
513
- }
514
- return Math.min(Math.max(confidence, 0), 1);
515
- }
516
- getMimeType(contentSample, lines, firstLine, fileExtension) {
517
- const text = typeof contentSample === "string" ? contentSample : new TextDecoder().decode(contentSample);
518
- if (fileExtension === ".xml") return "application/xml";
519
- if (text.toLowerCase().includes("<svg")) return "image/svg+xml";
520
- if (text.toLowerCase().includes("<html") || text.toLowerCase().includes("<!doctype html")) return "text/html";
521
- if (this.detect(contentSample, lines, firstLine, fileExtension) > 0.5) return "application/xml";
522
- return "text/plain";
523
- }
524
- };
525
- MarkdownDetector = class _MarkdownDetector {
526
- contentTypeName = "markdown";
527
- static MD_PATTERNS = [
528
- /^#{1,6}\s+\S+/,
529
- // ATX Headers
530
- /^\s*[\*\+\-]\s+\S+/,
531
- // List items
532
- /^\s*\d+\.\s+\S+/,
533
- // Ordered list items
534
- /`{1,3}[^`]+`{1,3}/,
535
- // Inline code
536
- /\[[^\]]+\]\([^\)]+\)/,
537
- // Links
538
- /!\[[^\]]+\]\([^\)]+\)/,
539
- // Images
540
- /^\s*>.*/
541
- // Blockquotes
542
- ];
543
- static SETEXT_HEADER = /^.*\n(?:={3,}|-{3,})\s*$/m;
544
- detect(contentSample, lines, firstLine, fileExtension) {
545
- const text = typeof contentSample === "string" ? contentSample : new TextDecoder().decode(contentSample);
546
- let confidence = 0;
547
- if (fileExtension && [".md", ".markdown"].includes(fileExtension.toLowerCase())) {
548
- confidence = Math.max(confidence, 0.95);
549
- }
550
- let mdFeatures = 0;
551
- if (_MarkdownDetector.SETEXT_HEADER.test(text)) mdFeatures += 2;
552
- for (const line of lines.slice(0, 20)) {
553
- if (_MarkdownDetector.MD_PATTERNS.some((p) => p.test(line))) {
554
- mdFeatures++;
555
- }
556
- }
557
- const hasCodeFence = text.includes("```");
558
- if (hasCodeFence) mdFeatures++;
559
- if (mdFeatures > 1 && hasCodeFence) confidence = Math.max(confidence, 0.85);
560
- if (mdFeatures > 3 && hasCodeFence) confidence = Math.max(confidence, 0.95);
561
- else if (mdFeatures > 1) confidence = Math.max(confidence, 0.6);
562
- else if (mdFeatures > 3) confidence = Math.max(confidence, 0.8);
563
- else if (mdFeatures > 5) confidence = Math.max(confidence, 0.9);
564
- const stripped = text.trim();
565
- if (stripped.startsWith("{") && stripped.endsWith("}") || stripped.startsWith("[") && stripped.endsWith("]")) {
566
- try {
567
- JSON.parse(text);
568
- if (confidence > 0.3) confidence -= 0.4;
569
- } catch {
570
- }
571
- }
572
- if (stripped.startsWith("<") && text.includes("<?xml")) {
573
- if (confidence > 0.3) confidence -= 0.4;
574
- }
575
- return Math.min(Math.max(confidence, 0), 1);
576
- }
577
- getMimeType(contentSample, lines, firstLine, fileExtension) {
578
- return this.detect(contentSample, lines, firstLine, fileExtension) > 0.5 ? "text/markdown" : "text/plain";
579
- }
580
- };
581
- PlainTextDetector = class _PlainTextDetector {
582
- contentTypeName = "text";
583
- static IMAGE_EXTS = [".png", ".jpg", ".jpeg", ".gif", ".bmp", ".svg", ".webp"];
584
- detect(contentSample, lines, firstLine, fileExtension) {
585
- if (!contentSample && lines.length === 0) return 0.1;
586
- if (fileExtension) {
587
- const ext = fileExtension.toLowerCase();
588
- if (_PlainTextDetector.IMAGE_EXTS.includes(ext) || ext === ".pdf") return 0;
589
- }
590
- const text = typeof contentSample === "string" ? contentSample : new TextDecoder().decode(contentSample);
591
- if (text.includes(",") && lines.length < 5) {
592
- const commaLines = lines.filter((l) => l.includes(",")).length;
593
- if (commaLines > 0 && commaLines === lines.length) {
594
- return 0.8;
595
- }
596
- }
597
- return 0.15;
598
- }
599
- getMimeType(contentSample, lines, firstLine, fileExtension) {
600
- return "text/plain";
601
- }
602
- };
603
- }
604
- });
605
-
606
- // src/model/detectors/DataFormatDetectors.ts
607
- var SQLDetector, JSONDetector, YAMLDetector, CSVDetector;
608
- var init_DataFormatDetectors = __esm({
609
- "src/model/detectors/DataFormatDetectors.ts"() {
610
- "use strict";
611
- SQLDetector = class _SQLDetector {
612
- contentTypeName = "sql";
613
- // Keywords (case insensitive checking handled in method)
614
- static KEYWORDS = [
615
- "SELECT ",
616
- "INSERT ",
617
- "UPDATE ",
618
- "DELETE ",
619
- "CREATE ",
620
- "DROP ",
621
- "ALTER ",
622
- "FROM ",
623
- "WHERE ",
624
- "JOIN ",
625
- "TABLE ",
626
- "INTO ",
627
- "VALUES ",
628
- "SET ",
629
- "PRIMARY KEY"
630
- ];
631
- detect(contentSample, lines, firstLine, fileExtension) {
632
- const text = typeof contentSample === "string" ? contentSample : new TextDecoder().decode(contentSample);
633
- let confidence = 0;
634
- if (fileExtension && fileExtension.toLowerCase() === ".sql") {
635
- confidence = Math.max(confidence, 0.95);
636
- }
637
- let hits = 0;
638
- const upperText = text.toUpperCase();
639
- for (const line of lines.slice(0, 10)) {
640
- const upperLine = line.toUpperCase();
641
- for (const kw of _SQLDetector.KEYWORDS) {
642
- if (upperLine.includes(kw)) {
643
- hits++;
644
- }
645
- }
646
- }
647
- if (hits >= 2) confidence = Math.max(confidence, 0.85);
648
- else if (hits === 1) confidence = Math.max(confidence, 0.6);
649
- return Math.min(confidence, 1);
650
- }
651
- getMimeType(contentSample, lines, firstLine, fileExtension) {
652
- return this.detect(contentSample, lines, firstLine, fileExtension) > 0.5 ? "text/x-sql" : "text/plain";
653
- }
654
- };
655
- JSONDetector = class {
656
- contentTypeName = "json";
657
- detect(contentSample, lines, firstLine, fileExtension) {
658
- const text = typeof contentSample === "string" ? contentSample : new TextDecoder().decode(contentSample);
659
- if (fileExtension && fileExtension.toLowerCase() === ".json") {
660
- return this.verifyJsonStructure(text) ? 0.95 : 0.6;
661
- }
662
- const stripped = text.trim();
663
- if (!(stripped.startsWith("{") && stripped.endsWith("}") || stripped.startsWith("[") && stripped.endsWith("]"))) {
664
- return 0;
665
- }
666
- for (const line of lines.slice(0, 5)) {
667
- const l = line.trim();
668
- if (l.startsWith("//") || l.startsWith("/*")) return 0;
669
- }
670
- try {
671
- JSON.parse(text);
672
- return 0.9;
673
- } catch (e) {
674
- return 0;
675
- }
676
- }
677
- getMimeType(contentSample, lines, firstLine, fileExtension) {
678
- return this.detect(contentSample, lines, firstLine, fileExtension) > 0.5 ? "application/json" : "text/plain";
679
- }
680
- verifyJsonStructure(text) {
681
- try {
682
- JSON.parse(text);
683
- return true;
684
- } catch {
685
- return false;
686
- }
687
- }
688
- };
689
- YAMLDetector = class _YAMLDetector {
690
- contentTypeName = "yaml";
691
- static YAML_START_PATTERNS = [/^---\s*$/, /^%YAML/];
692
- static KEY_VALUE_PATTERN = /^\s*[\w.-]+:\s+(?![=\{\[])/;
693
- static LIST_ITEM_PATTERN = /^\s*-\s+[\w\'\"]/;
694
- detect(contentSample, lines, firstLine, fileExtension) {
695
- const text = typeof contentSample === "string" ? contentSample : new TextDecoder().decode(contentSample);
696
- let confidence = 0;
697
- if (fileExtension && [".yaml", ".yml"].includes(fileExtension.toLowerCase())) {
698
- confidence = Math.max(confidence, 0.95);
699
- }
700
- if (_YAMLDetector.YAML_START_PATTERNS.some((p) => p.test(firstLine))) {
701
- confidence = Math.max(confidence, 0.9);
702
- }
703
- let yamlFeatures = 0;
704
- if (_YAMLDetector.YAML_START_PATTERNS.some((p) => new RegExp(p.source, "m").test(text))) {
705
- yamlFeatures += 2;
706
- }
707
- for (const line of lines.slice(0, 20)) {
708
- const stripped = line.trim();
709
- if (_YAMLDetector.KEY_VALUE_PATTERN.test(stripped)) yamlFeatures++;
710
- else if (_YAMLDetector.LIST_ITEM_PATTERN.test(stripped)) yamlFeatures++;
711
- }
712
- const firstNonEmpty = lines.find((l) => l.trim().length > 0) || "";
713
- if (firstNonEmpty.trim() === "---") {
714
- if (yamlFeatures > 1) confidence = Math.max(confidence, 0.5);
715
- if (yamlFeatures > 3) confidence = Math.max(confidence, 0.75);
716
- if (yamlFeatures > 5) confidence = Math.max(confidence, 0.9);
717
- } else {
718
- if (fileExtension && [".yaml", ".yml"].includes(fileExtension.toLowerCase())) {
719
- }
720
- }
721
- return Math.min(Math.max(confidence, 0), 1);
722
- }
723
- getMimeType(contentSample, lines, firstLine, fileExtension) {
724
- const conf = this.detect(contentSample, lines, firstLine, fileExtension);
725
- return conf > 0.5 ? "application/x-yaml" : "text/plain";
726
- }
727
- };
728
- CSVDetector = class {
729
- contentTypeName = "csv";
730
- detect(contentSample, lines, firstLine, fileExtension) {
731
- const text = typeof contentSample === "string" ? contentSample : new TextDecoder().decode(contentSample);
732
- if (fileExtension && fileExtension.toLowerCase() === ".csv") {
733
- return this.verifyCsvStructure(lines) ? 0.95 : 0.6;
734
- }
735
- const hasComma = lines.some((l) => l.includes(","));
736
- if (hasComma) {
737
- if (lines.length < 3) {
738
- const commaLines = lines.filter((l) => l.includes(",")).length;
739
- if (commaLines > 0 && commaLines === lines.length) {
740
- const delimCounts = lines.filter((l) => l.trim()).map((l) => (l.match(/,/g) || []).length);
741
- if (delimCounts.length > 0 && delimCounts.every((c) => c <= 2)) {
742
- return 0;
743
- }
744
- }
745
- }
746
- }
747
- return this.analyzeCsvContent(lines);
748
- }
749
- getMimeType(contentSample, lines, firstLine, fileExtension) {
750
- return this.detect(contentSample, lines, firstLine, fileExtension) > 0.5 ? "text/csv" : "text/plain";
751
- }
752
- verifyCsvStructure(lines) {
753
- const sampleLines = lines.slice(0, 10).filter((l) => l.trim().length > 0);
754
- if (sampleLines.length === 0) return false;
755
- if (!sampleLines.every((l) => l.includes(","))) return false;
756
- const counts = sampleLines.map((l) => (l.match(/,/g) || []).length);
757
- const uniqueCounts = [...new Set(counts)];
758
- if (uniqueCounts.length === 1 && uniqueCounts[0] > 0) return true;
759
- if (sampleLines.length > 1) {
760
- const dataCounts = counts.slice(1);
761
- const uniqueData = [...new Set(dataCounts)];
762
- if (uniqueData.length === 1 && uniqueData[0] > 0) return true;
763
- }
764
- return false;
765
- }
766
- analyzeCsvContent(lines) {
767
- if (!lines || lines.length === 0) return 0;
768
- const sampleLines = lines.slice(0, 10).filter((l) => l.trim().length > 0);
769
- if (sampleLines.length === 0 || !sampleLines.every((l) => l.includes(","))) return 0;
770
- const counts = sampleLines.map((l) => (l.match(/,/g) || []).length);
771
- const uniqueCounts = [...new Set(counts)];
772
- if (uniqueCounts.length === 1 && uniqueCounts[0] > 0) return 0.9;
773
- if (sampleLines.length > 1) {
774
- const dataCounts = counts.slice(1);
775
- const uniqueData = [...new Set(dataCounts)];
776
- if (uniqueData.length === 1 && uniqueData[0] > 0) return 0.8;
777
- }
778
- if (counts.every((c) => c > 0)) return 0.5;
779
- return 0;
780
- }
781
- };
782
- }
783
- });
784
-
785
- // src/model/detectors/OBJDetector.ts
786
- var OBJDetector;
787
- var init_OBJDetector = __esm({
788
- "src/model/detectors/OBJDetector.ts"() {
789
- "use strict";
790
- OBJDetector = class _OBJDetector {
791
- contentTypeName = "obj";
792
- // Check for 'v ' (vertex), 'f ' (face), 'vn ', 'vt '
793
- static COMMANDS = ["v ", "vt ", "vn ", "f ", "g ", "o ", "s ", "mtllib ", "usemtl "];
794
- detect(contentSample, lines, firstLine, fileExtension) {
795
- const text = typeof contentSample === "string" ? contentSample : new TextDecoder().decode(contentSample);
796
- let confidence = 0;
797
- if (fileExtension && fileExtension.toLowerCase() === ".obj") {
798
- confidence = Math.max(confidence, 0.95);
799
- }
800
- const validLines = lines.filter((l) => l.trim().length > 0 && !l.trim().startsWith("#"));
801
- let commandCount = 0;
802
- for (const line of validLines.slice(0, 20)) {
803
- const trimmed = line.trim();
804
- for (const cmd of _OBJDetector.COMMANDS) {
805
- if (trimmed.startsWith(cmd)) {
806
- commandCount++;
807
- break;
808
- }
809
- }
810
- }
811
- if (commandCount >= 2) {
812
- if (commandCount > 10) confidence = Math.max(confidence, 0.9);
813
- else if (commandCount > 5) confidence = Math.max(confidence, 0.8);
814
- else confidence = Math.max(confidence, 0.7);
815
- }
816
- const codeKeywords = ["def ", "class ", "import ", "function ", "var ", "let ", "const "];
817
- if (codeKeywords.some((k) => text.includes(k))) {
818
- return 0;
819
- }
820
- return Math.min(confidence, 1);
821
- }
822
- getMimeType(contentSample, lines, firstLine, fileExtension) {
823
- return this.detect(contentSample, lines, firstLine, fileExtension) > 0.5 ? "application/3d-obj" : "text/plain";
824
- }
825
- };
826
- }
827
- });
828
-
829
- // src/model/detectors/registry.ts
830
- var DetectorRegistry, registry;
831
- var init_registry = __esm({
832
- "src/model/detectors/registry.ts"() {
833
- "use strict";
834
- init_BinaryDetector();
835
- init_LanguageDetector();
836
- init_MarkupDetectors();
837
- init_DataFormatDetectors();
838
- init_OBJDetector();
839
- DetectorRegistry = class {
840
- detectors;
841
- constructor() {
842
- this.detectors = [
843
- new BinarySignatureDetector(),
844
- // Programming languages
845
- new ProgrammingLanguageDetector(),
846
- // Structured data
847
- new XMLDetector(),
848
- new JSONDetector(),
849
- new OBJDetector(),
850
- // Markup
851
- new MarkdownDetector(),
852
- // Data formats (lower priority)
853
- new SQLDetector(),
854
- new CSVDetector(),
855
- new YAMLDetector(),
856
- // Fallback
857
- new PlainTextDetector()
858
- ];
859
- }
860
- /**
861
- * Get the active detectors.
862
- */
863
- getDetectors() {
864
- return this.detectors;
865
- }
866
- };
867
- registry = new DetectorRegistry();
868
- }
869
- });
870
-
871
- // ../mime_extensions.json
872
- var mime_extensions_default;
873
- var init_mime_extensions = __esm({
874
- "../mime_extensions.json"() {
875
- mime_extensions_default = {
876
- textMimeTypes: [
877
- "text/plain",
878
- "text/html",
879
- "text/xml",
880
- "text/csv",
881
- "text/css",
882
- "text/javascript",
883
- "text/markdown",
884
- "text/x-python",
885
- "text/x-java",
886
- "text/x-c",
887
- "text/x-c++",
888
- "text/x-sql",
889
- "text/jsx",
890
- "text/typescript",
891
- "application/json",
892
- "application/xml",
893
- "application/x-yaml",
894
- "application/javascript",
895
- "application/x-httpd-php",
896
- "application/x-sh",
897
- "application/x-tex",
898
- "application/3d-obj",
899
- "text/vnd.graphviz",
900
- "text/x-mermaid",
901
- "text/x-plantuml",
902
- "application/x-properties",
903
- "application/toml"
904
- ],
905
- mimeToExtension: {
906
- "image/png": "png",
907
- "image/jpeg": "jpg",
908
- "image/gif": "gif",
909
- "image/bmp": "bmp",
910
- "image/x-icon": "ico",
911
- "image/svg+xml": "svg",
912
- "image/djvu": "djvu",
913
- "image/vnd.djvu": "djv",
914
- "image/webp": "webp",
915
- "audio/wav": "wav",
916
- "audio/x-wav": "wav",
917
- "video/mp4": "mp4",
918
- "video/quicktime": "mov",
919
- "application/pdf": "pdf",
920
- "application/msword": "doc",
921
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
922
- "application/vnd.ms-excel": "xls",
923
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
924
- "application/vnd.ms-powerpoint": "ppt",
925
- "application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
926
- "application/zip": "zip",
927
- "application/gzip": "gz",
928
- "application/x-rar-compressed": "rar",
929
- "application/x-7z-compressed": "7z",
930
- "application/x-sqlite3": "db",
931
- "application/x-parquet": "parquet",
932
- "text/plain": "txt",
933
- "text/html": "html",
934
- "text/xml": "xml",
935
- "text/csv": "csv",
936
- "text/css": "css",
937
- "text/javascript": "js",
938
- "text/markdown": "md",
939
- "text/x-python": "py",
940
- "text/x-java": "java",
941
- "text/x-c": "c",
942
- "text/x-sql": "sql",
943
- "text/jsx": "js",
944
- "application/json": "json",
945
- "application/xml": "xml",
946
- "application/x-yaml": "yaml",
947
- "application/javascript": "js",
948
- "application/x-httpd-php": "php",
949
- "application/x-sh": "sh",
950
- "application/x-tex": "tex",
951
- "text/vnd.graphviz": "dot",
952
- "text/x-mermaid": "mmd",
953
- "text/x-plantuml": "puml",
954
- "application/3d-obj": "obj",
955
- "application/x-properties": "properties",
956
- "application/toml": "toml"
957
- }
958
- };
959
- }
960
- });
961
-
962
- // src/config/constants.ts
963
- var DEFAULT_PAGE_SIZE, DETECTION_SAMPLE_CAP, MAX_FILE_SIZE, KNOWN_TYPE_SIZE_LIMIT, BINARY_CHECK_SAMPLE_SIZE, CONTENT_DETECTION_SAMPLE_SIZE, DEFAULT_MAX_PROBLEM_BYTES, INDEXEDDB_DEFAULT_DB_NAME, INDEXEDDB_DEFAULT_DB_VERSION, SQLITE_BUSY_TIMEOUT_MS, DEFAULT_SQLJS_WASM_URL;
964
- var init_constants = __esm({
965
- "src/config/constants.ts"() {
966
- "use strict";
967
- DEFAULT_PAGE_SIZE = 10;
968
- DETECTION_SAMPLE_CAP = 8192;
969
- MAX_FILE_SIZE = 50 * 1024 * 1024;
970
- KNOWN_TYPE_SIZE_LIMIT = 1024 * 1024;
971
- BINARY_CHECK_SAMPLE_SIZE = 32 * 1024;
972
- CONTENT_DETECTION_SAMPLE_SIZE = 1024 * 1024;
973
- DEFAULT_MAX_PROBLEM_BYTES = 2 * 1024 * 1024;
974
- INDEXEDDB_DEFAULT_DB_NAME = "mcard-db";
975
- INDEXEDDB_DEFAULT_DB_VERSION = 1;
976
- SQLITE_BUSY_TIMEOUT_MS = 5e3;
977
- DEFAULT_SQLJS_WASM_URL = "https://sql.js.org/dist/";
978
- }
979
- });
980
-
981
- // src/model/strategies/DetectionStrategy.ts
982
- function loadSharedMimeData() {
983
- return {
984
- textMimeTypes: new Set(mime_extensions_default.textMimeTypes || []),
985
- mimeToExtension: mime_extensions_default.mimeToExtension || {}
986
- };
987
- }
988
- function withDot(ext) {
989
- return ext.startsWith(".") ? ext : `.${ext}`;
990
- }
991
- var _sharedData, DefaultDetectionStrategy;
992
- var init_DetectionStrategy = __esm({
993
- "src/model/strategies/DetectionStrategy.ts"() {
994
- "use strict";
995
- init_registry();
996
- init_mime_extensions();
997
- init_constants();
998
- _sharedData = loadSharedMimeData();
999
- DefaultDetectionStrategy = class _DefaultDetectionStrategy {
1000
- constructor(customRegistry) {
1001
- this.customRegistry = customRegistry;
1002
- }
1003
- // Loaded from the shared JSON
1004
- static extensionsRegistry = Object.fromEntries(
1005
- Object.entries(_sharedData.mimeToExtension).map(([k, v]) => [k, withDot(v)])
1006
- );
1007
- static textMimeTypes = _sharedData.textMimeTypes;
1008
- static registerExtension(mimeType, extension) {
1009
- this.extensionsRegistry[mimeType] = extension;
1010
- }
1011
- static loadExtensions(mapping) {
1012
- for (const [mime, ext] of Object.entries(mapping)) {
1013
- this.extensionsRegistry[mime] = ext;
1014
- }
1015
- }
1016
- static getExtension(mimeType) {
1017
- return this.extensionsRegistry[mimeType] || "";
1018
- }
1019
- detect(content, fileExtension) {
1020
- const contentSample = typeof content === "string" ? content.slice(0, DETECTION_SAMPLE_CAP) : content.slice(0, DETECTION_SAMPLE_CAP);
1021
- const textSample = this.getTextSample(contentSample);
1022
- const lines = textSample.split("\n").slice(0, 20);
1023
- const firstLine = lines[0] || "";
1024
- const detectors = this.customRegistry ? this.customRegistry.getDetectors() : registry.getDetectors();
1025
- let bestConfidence = 0;
1026
- let mimeType = "text/plain";
1027
- for (const detector of detectors) {
1028
- const confidence = detector.detect(contentSample, lines, firstLine, fileExtension);
1029
- if (confidence > bestConfidence) {
1030
- const detectedMime = detector.getMimeType(contentSample, lines, firstLine, fileExtension);
1031
- if (detectedMime) {
1032
- bestConfidence = confidence;
1033
- mimeType = detectedMime;
1034
- if (confidence >= 0.99) break;
1035
- }
1036
- }
1037
- }
1038
- let extension = this.getExtension(mimeType);
1039
- if (fileExtension && extension) {
1040
- if (fileExtension.toLowerCase() === extension || fileExtension.toLowerCase() === `.${extension}`) {
1041
- extension = fileExtension;
1042
- }
1043
- }
1044
- if (!extension && fileExtension) {
1045
- extension = fileExtension;
1046
- }
1047
- if (!extension) {
1048
- extension = ".txt";
1049
- }
1050
- return { mimeType, extension };
1051
- }
1052
- getTextSample(content) {
1053
- if (typeof content === "string") {
1054
- return content.slice(0, DETECTION_SAMPLE_CAP);
1055
- }
1056
- return new TextDecoder("utf-8", { fatal: false }).decode(content.slice(0, DETECTION_SAMPLE_CAP));
1057
- }
1058
- getExtension(mimeType) {
1059
- return _DefaultDetectionStrategy.getExtension(mimeType);
1060
- }
1061
- };
1062
- }
1063
- });
1064
-
1065
- // src/model/utils/ContentAnalyzer.ts
1066
- var ContentAnalyzer;
1067
- var init_ContentAnalyzer = __esm({
1068
- "src/model/utils/ContentAnalyzer.ts"() {
1069
- "use strict";
1070
- ContentAnalyzer = class {
1071
- /**
1072
- * Check if content should be treated as binary.
1073
- */
1074
- static isBinaryContent(content, mimeType) {
1075
- if (mimeType) {
1076
- if (mimeType.startsWith("text/") || mimeType.includes("json") || mimeType.includes("xml") || mimeType.includes("javascript") || mimeType.includes("ecmascript")) {
1077
- return false;
1078
- }
1079
- return true;
1080
- }
1081
- if (typeof content === "string") return false;
1082
- if (content.indexOf(0) !== -1) {
1083
- return true;
1084
- }
1085
- try {
1086
- const decoder = new TextDecoder("utf-8", { fatal: true });
1087
- const decoded = decoder.decode(content);
1088
- const sample = content.slice(0, 4096);
1089
- if (sample.length === 0) return false;
1090
- let nonTextChars = 0;
1091
- for (let i = 0; i < sample.length; i++) {
1092
- const b = sample[i];
1093
- if (b < 9 || b > 13 && b < 32 || b > 126) {
1094
- nonTextChars++;
1095
- }
1096
- }
1097
- const textRatio = 1 - nonTextChars / sample.length;
1098
- return textRatio < 0.7;
1099
- } catch (e) {
1100
- return true;
1101
- }
1102
- }
1103
- static isKnownLongLineExtension(extension) {
1104
- if (!extension) return false;
1105
- const ext = extension.toLowerCase();
1106
- return [".min.js", ".min.css", ".map", ".svg", ".json", ".geojson"].some((e) => ext.endsWith(e));
1107
- }
1108
- static isUnstructuredBinary(sample) {
1109
- if (sample.length < 512) return false;
1110
- let nullCount = 0;
1111
- let controlCount = 0;
1112
- const len = Math.min(sample.length, 32 * 1024);
1113
- for (let i = 0; i < len; i++) {
1114
- const byte = sample[i];
1115
- if (byte === 0) {
1116
- nullCount++;
1117
- }
1118
- if (byte < 32 && byte !== 9 && byte !== 10 && byte !== 13) {
1119
- controlCount++;
1120
- }
1121
- }
1122
- const nullRatio = nullCount / len;
1123
- const controlRatio = controlCount / len;
1124
- return nullRatio > 0.1 || controlRatio > 0.2;
1125
- }
1126
- static hasPathologicalLines(sample, isKnownType) {
1127
- if (isKnownType || sample.length < 32768) return false;
1128
- for (let i = 0; i < sample.length; i++) {
1129
- if (sample[i] === 10 || sample[i] === 13) return false;
1130
- }
1131
- return true;
1132
- }
1133
- };
1134
- }
1135
- });
1136
-
1137
179
  // src/model/ContentTypeInterpreter.ts
1138
- var ContentTypeInterpreter;
180
+ var import_mcard_wasm, ContentTypeInterpreter;
1139
181
  var init_ContentTypeInterpreter = __esm({
1140
182
  "src/model/ContentTypeInterpreter.ts"() {
1141
183
  "use strict";
1142
- init_DetectionStrategy();
1143
- init_ContentAnalyzer();
184
+ import_mcard_wasm = require("mcard-wasm");
1144
185
  ContentTypeInterpreter = class {
1145
- static strategy = new DefaultDetectionStrategy();
1146
- /**
1147
- * Convenience method to detect MIME type only.
1148
- * Matches the API expected by MCard/PCard/VCard.
1149
- */
1150
186
  static detect(content) {
1151
187
  return this.detectContentType(content).mimeType;
1152
188
  }
1153
- /**
1154
- * Detect content type and suggest extension.
1155
- *
1156
- * @param content Content string or binary buffer
1157
- * @param fileExtension Optional file extension hint
1158
- * @returns Object containing detected mimeType and suggested extension
1159
- */
1160
189
  static detectContentType(content, fileExtension) {
1161
- return this.strategy.detect(content, fileExtension);
1162
- }
1163
- static registerExtension(mimeType, extension) {
1164
- DefaultDetectionStrategy.registerExtension(mimeType, extension);
1165
- }
1166
- static registerExtensions(mapping) {
1167
- DefaultDetectionStrategy.loadExtensions(mapping);
190
+ const buffer = typeof content === "string" ? new TextEncoder().encode(content) : content;
191
+ const result = (0, import_mcard_wasm.detect_content_type)(buffer, fileExtension);
192
+ return { mimeType: result[0], extension: result[1] };
1168
193
  }
1169
194
  static getExtension(mimeType) {
1170
- return DefaultDetectionStrategy.getExtension(mimeType);
195
+ return (0, import_mcard_wasm.get_extension)(mimeType) || "bin";
1171
196
  }
1172
- /**
1173
- * Check if content should be treated as binary.
1174
- */
1175
197
  static isBinaryContent(content, mimeType) {
1176
- return ContentAnalyzer.isBinaryContent(content, mimeType);
198
+ const buffer = typeof content === "string" ? new TextEncoder().encode(content) : content;
199
+ return (0, import_mcard_wasm.is_binary_content)(buffer);
200
+ }
201
+ // Stub or bypass irrelevant manual TS rules now managed by mcard-core
202
+ static registerExtension(mimeType, extension) {
203
+ }
204
+ static registerExtensions(mapping) {
1177
205
  }
1178
206
  static isKnownLongLineExtension(extension) {
1179
- return ContentAnalyzer.isKnownLongLineExtension(extension);
207
+ return false;
1180
208
  }
1181
209
  static isUnstructuredBinary(sample) {
1182
- return ContentAnalyzer.isUnstructuredBinary(sample);
210
+ if (sample.length < 512) return false;
211
+ let nullCount = 0;
212
+ let controlChars = 0;
213
+ for (let i = 0; i < sample.length; i++) {
214
+ const b = sample[i];
215
+ if (b === 0) nullCount++;
216
+ if (b < 32 && b !== 9 && b !== 10 && b !== 13) controlChars++;
217
+ }
218
+ const nullRatio = nullCount / sample.length;
219
+ const controlRatio = controlChars / sample.length;
220
+ return nullRatio > 0.1 || controlRatio > 0.2;
1183
221
  }
1184
222
  static hasPathologicalLines(sample, isKnownType) {
1185
- return ContentAnalyzer.hasPathologicalLines(sample, isKnownType);
223
+ return false;
1186
224
  }
1187
225
  };
1188
226
  }
@@ -1297,16 +335,16 @@ var init_MCard = __esm({
1297
335
  }
1298
336
  /**
1299
337
  * Get DOTS vocabulary metadata for this MCard
1300
- *
338
+ *
1301
339
  * Returns the DOTS role information that positions this MCard
1302
340
  * in the Double Operadic Theory of Systems framework.
1303
- *
341
+ *
1304
342
  * MCard is always a CARRIER object in the Data Plane.
1305
- *
343
+ *
1306
344
  * @param tightRefs - Optional array of prerequisite MCard hashes (vertical composition)
1307
345
  * @param looseRefs - Optional array of alternative MCard hashes (horizontal composition)
1308
346
  * @returns DOTSMetadata describing this card's role in the compositional system
1309
- *
347
+ *
1310
348
  * @example
1311
349
  * ```typescript
1312
350
  * const card = await MCard.create('Hello World');
@@ -1406,6 +444,44 @@ var init_Handle = __esm({
1406
444
  }
1407
445
  });
1408
446
 
447
+ // src/config/constants.ts
448
+ var DEFAULT_PAGE_SIZE, MAX_FILE_SIZE, READ_TIMEOUT_MS, KNOWN_TYPE_SIZE_LIMIT, BINARY_CHECK_SAMPLE_SIZE, CONTENT_DETECTION_SAMPLE_SIZE, DEFAULT_MAX_PROBLEM_BYTES, INDEXEDDB_DEFAULT_DB_NAME, INDEXEDDB_DEFAULT_DB_VERSION, SQLITE_BUSY_TIMEOUT_MS, getEnvUrl, DEFAULT_OLLAMA_BASE_URL, DEFAULT_OTLP_ENDPOINT, DEFAULT_VLLM_BASE_URL, DEFAULT_LMSTUDIO_BASE_URL, DEFAULT_SQLJS_WASM_URL, DEFAULT_SANDBOX_TIMEOUT_MS, DEFAULT_CLM_TIMEOUT_MS, DEFAULT_VM_EXECUTION_TIMEOUT_MS, LLM_DEFAULT_TIMEOUT_SECS, LLM_DEFAULT_RETRY_COUNT, LLM_DEFAULT_RETRY_DELAY_SECS;
449
+ var init_constants = __esm({
450
+ "src/config/constants.ts"() {
451
+ "use strict";
452
+ DEFAULT_PAGE_SIZE = 10;
453
+ MAX_FILE_SIZE = 50 * 1024 * 1024;
454
+ READ_TIMEOUT_MS = 5e3;
455
+ KNOWN_TYPE_SIZE_LIMIT = 1024 * 1024;
456
+ BINARY_CHECK_SAMPLE_SIZE = 32 * 1024;
457
+ CONTENT_DETECTION_SAMPLE_SIZE = 1024 * 1024;
458
+ DEFAULT_MAX_PROBLEM_BYTES = 2 * 1024 * 1024;
459
+ INDEXEDDB_DEFAULT_DB_NAME = "mcard-db";
460
+ INDEXEDDB_DEFAULT_DB_VERSION = 1;
461
+ SQLITE_BUSY_TIMEOUT_MS = 5e3;
462
+ getEnvUrl = (key, fallback) => {
463
+ try {
464
+ if (typeof process !== "undefined" && process.env && process.env[key]) {
465
+ return process.env[key];
466
+ }
467
+ } catch (e) {
468
+ }
469
+ return fallback;
470
+ };
471
+ DEFAULT_OLLAMA_BASE_URL = getEnvUrl("OLLAMA_BASE_URL", "http://localhost:11434");
472
+ DEFAULT_OTLP_ENDPOINT = getEnvUrl("OTLP_ENDPOINT", "http://localhost:4317");
473
+ DEFAULT_VLLM_BASE_URL = getEnvUrl("VLLM_BASE_URL", "http://localhost:8000");
474
+ DEFAULT_LMSTUDIO_BASE_URL = getEnvUrl("LMSTUDIO_BASE_URL", "http://localhost:1234");
475
+ DEFAULT_SQLJS_WASM_URL = "https://sql.js.org/dist/";
476
+ DEFAULT_SANDBOX_TIMEOUT_MS = 5e3;
477
+ DEFAULT_CLM_TIMEOUT_MS = 5e3;
478
+ DEFAULT_VM_EXECUTION_TIMEOUT_MS = 5e3;
479
+ LLM_DEFAULT_TIMEOUT_SECS = 120;
480
+ LLM_DEFAULT_RETRY_COUNT = 3;
481
+ LLM_DEFAULT_RETRY_DELAY_SECS = 1;
482
+ }
483
+ });
484
+
1409
485
  // src/monads/Maybe.ts
1410
486
  var Maybe;
1411
487
  var init_Maybe = __esm({
@@ -2084,424 +1160,6 @@ var init_IndexedDBEngine2 = __esm({
2084
1160
  }
2085
1161
  });
2086
1162
 
2087
- // src/storage/schema_constants.ts
2088
- var MCARD_SCHEMA_SQL, MCARD_VECTOR_SCHEMA_SQL;
2089
- var init_schema_constants = __esm({
2090
- "src/storage/schema_constants.ts"() {
2091
- "use strict";
2092
- MCARD_SCHEMA_SQL = `-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2093
- -- MCard Unified Database Schema (Monadic Core)
2094
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2095
- --
2096
- -- STABILITY WARNING: This schema is the invariant "seeding meta-language" for all
2097
- -- Domain Specific Languages (DSLs). It must remain as stable as possible.
2098
- --
2099
- -- THE UNIFICATION THESIS:
2100
- -- This design unites three distinct namespaces into a single relational network
2101
- -- by leveraging the power of cryptographic hash functions:
2102
- -- 1. CONTENT SPACE (Intrinsic Identity): Content-Addressable Storage (CAS).
2103
- -- 2. HANDLE SPACE (Reserved Words): Mapping human logic to content hashes.
2104
- -- 3. VERSION SPACE (Temporal Evolution): Tracking state transitions via hash history.
2105
- --
2106
- -- TURING MACHINE ANALOGY (The Infinitely Long Tape):
2107
- -- The \`card\` table stores content blobs with unique identities, emulating the
2108
- -- "Infinitely Long Tape" of the Turing Machine formalism. By using relational
2109
- -- queries, this tape can be dynamically constructed and traversed for different
2110
- -- DSLs, providing a flexible substrate for practically all computable languages.
2111
- --
2112
- -- By using hash values as the universal primitives across content, handles, and
2113
- -- time, we create a "Wordless Book" \u2014 a minimal substrate capable of seeding any
2114
- -- domain-specific knowledge system without requiring schema changes.
2115
- --
2116
- -- Monadic Mapping (See: Monadic Justification for Schema Design.md):
2117
- -- 1. Card = Monad (Perception/State/Exponent) - Intrinsic Identity
2118
- -- 2. Handle = Registry (Appetition/Reader/Sum) - Mutable Reference
2119
- -- 3. Version = History (Harmony/Writer/Product) - Coordinated Evolution
2120
- --
2121
- -- Version: 3.0.2 (Turing Tape Refinement)
2122
- -- Last Updated: 2025-12-20
2123
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2124
-
2125
-
2126
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2127
- -- LAYER 1: CORE CONTENT-ADDRESSABLE STORAGE (The Monad / Exponent)
2128
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2129
- -- The fundamental MCard storage: content-addressed by cryptographic hash.
2130
- -- "Each Monad ... mirrors the universe"
2131
-
2132
- -- @table card
2133
- -- @description Core content-addressable storage table (Monad/State)
2134
- -- @column hash - SHA-256 hash of content (primary key)
2135
- -- @column content - The actual content (BLOB for binary safety)
2136
- -- @column g_time - Generation timestamp (ISO 8601)
2137
- CREATE TABLE IF NOT EXISTS card (
2138
- hash TEXT PRIMARY KEY,
2139
- content BLOB NOT NULL,
2140
- g_time TEXT NOT NULL
2141
- );
2142
-
2143
-
2144
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2145
- -- LAYER 2: HANDLE SYSTEM (Appetition / Sum)
2146
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2147
- -- The mutable pointer that "desires" to reference new content.
2148
- -- "Appetition: the tendency to move to new states"
2149
-
2150
- -- @table handle_registry (Monadic Role: Handle)
2151
- -- @description Maps human-readable handles to current content hashes
2152
- -- @column handle - UTF-8 handle name (primary key)
2153
- -- @column current_hash - FK to card.hash of current version
2154
- -- @column created_at - When handle was first created
2155
- -- @column updated_at - When handle was last updated
2156
- CREATE TABLE IF NOT EXISTS handle_registry (
2157
- handle TEXT PRIMARY KEY,
2158
- current_hash TEXT NOT NULL,
2159
- created_at TEXT NOT NULL,
2160
- updated_at TEXT NOT NULL,
2161
- FOREIGN KEY (current_hash) REFERENCES card(hash)
2162
- );
2163
-
2164
- -- @index idx_handle_current_hash
2165
- -- @description Efficient reverse lookup from hash to handles
2166
- CREATE INDEX IF NOT EXISTS idx_handle_current_hash
2167
- ON handle_registry(current_hash);
2168
-
2169
- -- @table handle_history (Monadic Role: Version / Product)
2170
- -- @description Audit trail for handle pointer changes (Pre-Established Harmony)
2171
- -- @column id - Auto-increment primary key
2172
- -- @column handle - The handle that was updated
2173
- -- @column previous_hash - Hash it pointed to before update
2174
- -- @column changed_at - When the change occurred
2175
- CREATE TABLE IF NOT EXISTS handle_history (
2176
- id INTEGER PRIMARY KEY AUTOINCREMENT,
2177
- handle TEXT NOT NULL,
2178
- previous_hash TEXT NOT NULL,
2179
- changed_at TEXT NOT NULL,
2180
- FOREIGN KEY (handle) REFERENCES handle_registry(handle),
2181
- FOREIGN KEY (previous_hash) REFERENCES card(hash)
2182
- );
2183
-
2184
- -- @index idx_handle_history_handle
2185
- -- @description Efficient lookup of history by handle
2186
- CREATE INDEX IF NOT EXISTS idx_handle_history_handle
2187
- ON handle_history(handle);
2188
-
2189
-
2190
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2191
- -- LEGACY SUPPORT: FTS5 Documents Table
2192
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2193
- -- KEPT FOR BACKWARD COMPATIBILITY with existing codebase.
2194
- -- New implementations should use mcard_vector_schema.sql -> mcard_fts
2195
-
2196
- -- @virtual_table documents
2197
- -- @description Legacy FTS table for backward compatibility
2198
- -- @note Synced with card table via triggers
2199
- CREATE VIRTUAL TABLE IF NOT EXISTS documents USING fts5(content);
2200
-
2201
-
2202
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2203
- -- SCHEMA METADATA
2204
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2205
-
2206
- -- @table schema_version
2207
- -- @description Tracks schema version for migrations
2208
- CREATE TABLE IF NOT EXISTS schema_version (
2209
- version TEXT PRIMARY KEY,
2210
- applied_at TEXT NOT NULL,
2211
- description TEXT
2212
- );
2213
-
2214
- -- Insert current schema version
2215
- INSERT OR IGNORE INTO schema_version (version, applied_at, description)
2216
- VALUES ('3.0.0', datetime('now'), 'Monadic Core Schema (split vectors to mcard_vector_schema.sql)');
2217
- `;
2218
- MCARD_VECTOR_SCHEMA_SQL = `-- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2219
- -- MCard Vector Database Schema (mcard_vectors.db)
2220
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2221
- --
2222
- -- This schema defines the structure for "Secondary Qualities" (Extrinsic Embeddings).
2223
- -- It is separated from the core mcard.db (Monadic Intrinsic Properties) to ensure:
2224
- -- 1. Separation of Concerns (Intrinsic vs Extrinsic)
2225
- -- 2. Linearity (Vectors are observer-dependent and large)
2226
- -- 3. Upgradability (Embedding models change frequently)
2227
- --
2228
- -- See: Monadic Justification for Schema Design.md
2229
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2230
-
2231
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2232
- -- LAYER 3: VECTOR STORAGE (Semantic Embeddings)
2233
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2234
- -- Storage for vector embeddings enabling semantic search.
2235
- -- Links to content via hash for content-addressing.
2236
-
2237
- -- @table mcard_vector_metadata
2238
- -- @description Metadata for stored embeddings
2239
- -- @column id - Auto-increment primary key
2240
- -- @column hash - FK to card.hash
2241
- -- @column model_name - Embedding model used (e.g., "nomic-embed-text")
2242
- -- @column dimensions - Vector dimensions
2243
- -- @column chunk_index - Index for chunked documents (0 = first/whole)
2244
- -- @column chunk_total - Total chunks for this document
2245
- -- @column chunk_text - Preview text for this chunk
2246
- -- @column created_at - When embedding was created
2247
- CREATE TABLE IF NOT EXISTS mcard_vector_metadata (
2248
- id INTEGER PRIMARY KEY AUTOINCREMENT,
2249
- hash TEXT NOT NULL,
2250
- model_name TEXT NOT NULL,
2251
- dimensions INTEGER NOT NULL,
2252
- chunk_index INTEGER DEFAULT 0,
2253
- chunk_total INTEGER DEFAULT 1,
2254
- chunk_text TEXT,
2255
- created_at TEXT NOT NULL,
2256
- UNIQUE(hash, chunk_index)
2257
- );
2258
-
2259
- -- @index idx_vector_metadata_hash
2260
- -- @description Efficient lookup of embeddings by content hash
2261
- CREATE INDEX IF NOT EXISTS idx_vector_metadata_hash
2262
- ON mcard_vector_metadata(hash);
2263
-
2264
- -- @table mcard_embeddings
2265
- -- @description Fallback embedding storage when sqlite-vec is unavailable
2266
- -- @column id - Auto-increment primary key
2267
- -- @column metadata_id - FK to mcard_vector_metadata.id
2268
- -- @column embedding - Serialized float32 vector as BLOB
2269
- CREATE TABLE IF NOT EXISTS mcard_embeddings (
2270
- id INTEGER PRIMARY KEY AUTOINCREMENT,
2271
- metadata_id INTEGER NOT NULL,
2272
- embedding BLOB NOT NULL,
2273
- UNIQUE(metadata_id),
2274
- FOREIGN KEY (metadata_id) REFERENCES mcard_vector_metadata(id)
2275
- );
2276
-
2277
- -- @virtual_table mcard_fts
2278
- -- @description Full-text search for hybrid retrieval
2279
- -- @note Uses Porter stemming with Unicode support
2280
- CREATE VIRTUAL TABLE IF NOT EXISTS mcard_fts USING fts5(
2281
- hash,
2282
- content,
2283
- tokenize='porter unicode61'
2284
- );
2285
-
2286
- -- Note: sqlite-vec virtual table is created dynamically with dimensions:
2287
- -- CREATE VIRTUAL TABLE IF NOT EXISTS mcard_vec USING vec0(
2288
- -- metadata_id INTEGER PRIMARY KEY,
2289
- -- embedding float[\${dimensions}]
2290
- -- );
2291
-
2292
-
2293
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2294
- -- LAYER 4: SEMANTIC VERSIONING (Handle-Vector Bridge)
2295
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2296
- -- Bridges handles to vector embeddings for semantic version comparison.
2297
- -- Enables measuring semantic drift between document versions.
2298
-
2299
- -- @table handle_version_vectors
2300
- -- @description Links handle versions to their semantic embeddings
2301
- -- @column id - Auto-increment primary key
2302
- -- @column handle - FK to handle_registry.handle
2303
- -- @column hash - FK to card.hash (this version)
2304
- -- @column parent_hash - FK to card.hash (previous version)
2305
- -- @column version_order - 0 = current, 1 = previous, etc.
2306
- -- @column is_current - TRUE if this is the current version
2307
- -- @column embedding_id - FK to mcard_vector_metadata.id
2308
- -- @column semantic_delta_from_parent - Cosine similarity to parent [-1, 1]
2309
- -- @column upgrade_type - Classification: 'trivial' | 'minor' | 'major' | 'breaking'
2310
- -- @column created_at - When this version was linked
2311
- CREATE TABLE IF NOT EXISTS handle_version_vectors (
2312
- id INTEGER PRIMARY KEY AUTOINCREMENT,
2313
- handle TEXT NOT NULL,
2314
- hash TEXT NOT NULL,
2315
- parent_hash TEXT,
2316
- version_order INTEGER NOT NULL,
2317
- is_current BOOLEAN DEFAULT FALSE,
2318
- embedding_id INTEGER,
2319
- semantic_delta_from_parent REAL,
2320
- upgrade_type TEXT,
2321
- created_at TEXT NOT NULL,
2322
- UNIQUE(handle, hash),
2323
- FOREIGN KEY (embedding_id) REFERENCES mcard_vector_metadata(id)
2324
- );
2325
-
2326
- -- @index idx_hvv_handle
2327
- -- @description Efficient lookup of versions by handle
2328
- CREATE INDEX IF NOT EXISTS idx_hvv_handle
2329
- ON handle_version_vectors(handle);
2330
-
2331
- -- @index idx_hvv_hash
2332
- -- @description Efficient lookup of versions by hash
2333
- CREATE INDEX IF NOT EXISTS idx_hvv_hash
2334
- ON handle_version_vectors(hash);
2335
-
2336
- -- @index idx_hvv_current
2337
- -- @description Efficient lookup of current versions
2338
- CREATE INDEX IF NOT EXISTS idx_hvv_current
2339
- ON handle_version_vectors(is_current);
2340
-
2341
- -- @index idx_hvv_parent
2342
- -- @description Efficient lookup by parent hash
2343
- CREATE INDEX IF NOT EXISTS idx_hvv_parent
2344
- ON handle_version_vectors(parent_hash);
2345
-
2346
- -- @table version_similarity_cache
2347
- -- @description Precomputed pairwise similarities for performance
2348
- -- @column id - Auto-increment primary key
2349
- -- @column handle - Handle these versions belong to
2350
- -- @column hash_a - First version hash
2351
- -- @column hash_b - Second version hash
2352
- -- @column similarity_score - Cosine similarity [-1, 1]
2353
- -- @column distance_euclidean - L2 distance [0, \u221E)
2354
- -- @column computed_at - When similarity was computed
2355
- CREATE TABLE IF NOT EXISTS version_similarity_cache (
2356
- id INTEGER PRIMARY KEY AUTOINCREMENT,
2357
- handle TEXT NOT NULL,
2358
- hash_a TEXT NOT NULL,
2359
- hash_b TEXT NOT NULL,
2360
- similarity_score REAL NOT NULL,
2361
- distance_euclidean REAL,
2362
- computed_at TEXT NOT NULL,
2363
- UNIQUE(handle, hash_a, hash_b)
2364
- );
2365
-
2366
- -- @index idx_vsc_handle
2367
- -- @description Efficient lookup of cached similarities by handle
2368
- CREATE INDEX IF NOT EXISTS idx_vsc_handle
2369
- ON version_similarity_cache(handle);
2370
-
2371
-
2372
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2373
- -- LAYER 5: KNOWLEDGE GRAPH (GraphRAG)
2374
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2375
- -- Storage for extracted knowledge graph entities and relationships.
2376
-
2377
- -- @table graph_entities
2378
- -- @description Nodes in the knowledge graph
2379
- -- @column id - Auto-increment primary key
2380
- -- @column name - Entity name
2381
- -- @column type - Entity type (e.g., "Person", "Organization")
2382
- -- @column description - Optional description
2383
- -- @column source_hash - FK to card.hash where entity was extracted
2384
- -- @column embedding - Optional entity embedding
2385
- -- @column created_at - When entity was created
2386
- CREATE TABLE IF NOT EXISTS graph_entities (
2387
- id INTEGER PRIMARY KEY AUTOINCREMENT,
2388
- name TEXT NOT NULL,
2389
- type TEXT NOT NULL,
2390
- description TEXT,
2391
- source_hash TEXT NOT NULL,
2392
- embedding BLOB,
2393
- created_at TEXT NOT NULL,
2394
- UNIQUE(name, type, source_hash)
2395
- );
2396
-
2397
- -- @index idx_entity_name
2398
- -- @description Efficient entity lookup by name
2399
- CREATE INDEX IF NOT EXISTS idx_entity_name
2400
- ON graph_entities(name);
2401
-
2402
- -- @index idx_entity_type
2403
- -- @description Efficient entity lookup by type
2404
- CREATE INDEX IF NOT EXISTS idx_entity_type
2405
- ON graph_entities(type);
2406
-
2407
- -- @index idx_entity_source
2408
- -- @description Efficient entity lookup by source document
2409
- CREATE INDEX IF NOT EXISTS idx_entity_source
2410
- ON graph_entities(source_hash);
2411
-
2412
- -- @table graph_relationships
2413
- -- @description Edges in the knowledge graph
2414
- -- @column id - Auto-increment primary key
2415
- -- @column source_entity_id - FK to graph_entities.id (from)
2416
- -- @column target_entity_id - FK to graph_entities.id (to)
2417
- -- @column relationship - Relationship type/label
2418
- -- @column description - Optional description
2419
- -- @column weight - Relationship strength
2420
- -- @column source_hash - FK to card.hash where relationship was extracted
2421
- -- @column created_at - When relationship was created
2422
- CREATE TABLE IF NOT EXISTS graph_relationships (
2423
- id INTEGER PRIMARY KEY AUTOINCREMENT,
2424
- source_entity_id INTEGER NOT NULL,
2425
- target_entity_id INTEGER NOT NULL,
2426
- relationship TEXT NOT NULL,
2427
- description TEXT,
2428
- weight REAL DEFAULT 1.0,
2429
- source_hash TEXT NOT NULL,
2430
- created_at TEXT NOT NULL,
2431
- UNIQUE(source_entity_id, target_entity_id, relationship, source_hash),
2432
- FOREIGN KEY (source_entity_id) REFERENCES graph_entities(id),
2433
- FOREIGN KEY (target_entity_id) REFERENCES graph_entities(id)
2434
- );
2435
-
2436
- -- @index idx_rel_source
2437
- -- @description Efficient lookup of relationships by source entity
2438
- CREATE INDEX IF NOT EXISTS idx_rel_source
2439
- ON graph_relationships(source_entity_id);
2440
-
2441
- -- @index idx_rel_target
2442
- -- @description Efficient lookup of relationships by target entity
2443
- CREATE INDEX IF NOT EXISTS idx_rel_target
2444
- ON graph_relationships(target_entity_id);
2445
-
2446
- -- @table graph_communities
2447
- -- @description Hierarchical community summaries (GraphRAG)
2448
- -- @column id - Auto-increment primary key
2449
- -- @column level - Hierarchy level (0 = leaf)
2450
- -- @column title - Community title
2451
- -- @column summary - AI-generated summary
2452
- -- @column embedding - Community embedding
2453
- -- @column member_entity_ids - JSON array of entity IDs
2454
- -- @column parent_community_id - FK to parent community
2455
- -- @column created_at - When community was created
2456
- CREATE TABLE IF NOT EXISTS graph_communities (
2457
- id INTEGER PRIMARY KEY AUTOINCREMENT,
2458
- level INTEGER NOT NULL DEFAULT 0,
2459
- title TEXT,
2460
- summary TEXT NOT NULL,
2461
- embedding BLOB,
2462
- member_entity_ids TEXT,
2463
- parent_community_id INTEGER,
2464
- created_at TEXT NOT NULL,
2465
- FOREIGN KEY (parent_community_id) REFERENCES graph_communities(id)
2466
- );
2467
-
2468
- -- @index idx_community_level
2469
- -- @description Efficient lookup of communities by level
2470
- CREATE INDEX IF NOT EXISTS idx_community_level
2471
- ON graph_communities(level);
2472
-
2473
- -- @table graph_extractions
2474
- -- @description Tracks which documents have been processed for entity extraction
2475
- -- @column hash - FK to card.hash (primary key)
2476
- -- @column entity_count - Number of entities extracted
2477
- -- @column relationship_count - Number of relationships extracted
2478
- -- @column extracted_at - When extraction was performed
2479
- CREATE TABLE IF NOT EXISTS graph_extractions (
2480
- hash TEXT PRIMARY KEY,
2481
- entity_count INTEGER DEFAULT 0,
2482
- relationship_count INTEGER DEFAULT 0,
2483
- extracted_at TEXT NOT NULL
2484
- );
2485
-
2486
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2487
- -- SCHEMA METADATA (Vector DB)
2488
- -- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
2489
-
2490
- -- @table schema_version
2491
- -- @description Tracks schema version for migrations
2492
- CREATE TABLE IF NOT EXISTS vector_schema_version (
2493
- version TEXT PRIMARY KEY,
2494
- applied_at TEXT NOT NULL,
2495
- description TEXT
2496
- );
2497
-
2498
- -- Insert current schema version
2499
- INSERT OR IGNORE INTO vector_schema_version (version, applied_at, description)
2500
- VALUES ('1.0.0', datetime('now'), 'Initial MCard Vector Schema');
2501
- `;
2502
- }
2503
- });
2504
-
2505
1163
  // src/storage/schema.ts
2506
1164
  function getSchemaInstance() {
2507
1165
  return MCardSchema.getInstance();
@@ -2511,11 +1169,11 @@ function initCoreSchemas(db) {
2511
1169
  schema.initCoreTables(db);
2512
1170
  schema.initHandleTables(db);
2513
1171
  }
2514
- var TABLE_LAYERS, MCardSchema, CARD_TABLE_SCHEMA, HANDLE_REGISTRY_SCHEMA, HANDLE_HISTORY_SCHEMA, HANDLE_INDEX_SCHEMA, VECTOR_METADATA_SCHEMA, VECTOR_METADATA_INDEX, VECTOR_EMBEDDINGS_SCHEMA, VECTOR_FTS_SCHEMA, HANDLE_VERSION_VECTORS_SCHEMA, HANDLE_VERSION_VECTORS_INDEXES, VERSION_SIMILARITY_CACHE_SCHEMA, VERSION_SIMILARITY_CACHE_INDEX, GRAPH_ENTITY_SCHEMA, GRAPH_ENTITY_INDEX_NAME, GRAPH_ENTITY_INDEX_TYPE, GRAPH_ENTITY_INDEX_SOURCE, GRAPH_RELATIONSHIP_SCHEMA, GRAPH_RELATIONSHIP_INDEX_SOURCE, GRAPH_RELATIONSHIP_INDEX_TARGET, GRAPH_COMMUNITY_SCHEMA, GRAPH_COMMUNITY_INDEX_LEVEL, GRAPH_EXTRACTION_SCHEMA, CORE_SCHEMAS;
1172
+ var import_mcard_wasm2, TABLE_LAYERS, MCardSchema, CARD_TABLE_SCHEMA, HANDLE_REGISTRY_SCHEMA, HANDLE_HISTORY_SCHEMA, HANDLE_INDEX_SCHEMA, VECTOR_METADATA_SCHEMA, VECTOR_METADATA_INDEX, VECTOR_EMBEDDINGS_SCHEMA, VECTOR_FTS_SCHEMA, HANDLE_VERSION_VECTORS_SCHEMA, HANDLE_VERSION_VECTORS_INDEXES, VERSION_SIMILARITY_CACHE_SCHEMA, VERSION_SIMILARITY_CACHE_INDEX, GRAPH_ENTITY_SCHEMA, GRAPH_ENTITY_INDEX_NAME, GRAPH_ENTITY_INDEX_TYPE, GRAPH_ENTITY_INDEX_SOURCE, GRAPH_RELATIONSHIP_SCHEMA, GRAPH_RELATIONSHIP_INDEX_SOURCE, GRAPH_RELATIONSHIP_INDEX_TARGET, GRAPH_COMMUNITY_SCHEMA, GRAPH_COMMUNITY_INDEX_LEVEL, GRAPH_EXTRACTION_SCHEMA, CORE_SCHEMAS;
2515
1173
  var init_schema = __esm({
2516
1174
  "src/storage/schema.ts"() {
2517
1175
  "use strict";
2518
- init_schema_constants();
1176
+ import_mcard_wasm2 = require("mcard-wasm");
2519
1177
  TABLE_LAYERS = {
2520
1178
  // Layer 1: Core
2521
1179
  "card": "core",
@@ -2565,10 +1223,11 @@ var init_schema = __esm({
2565
1223
  }
2566
1224
  load() {
2567
1225
  if (this.loaded) return;
2568
- this.schemaPath = "IN_MEMORY_CONSTANTS";
2569
- this.rawSql = MCARD_SCHEMA_SQL;
2570
- if (MCARD_VECTOR_SCHEMA_SQL) {
2571
- this.rawSql += "\n\n" + MCARD_VECTOR_SCHEMA_SQL;
1226
+ this.schemaPath = "WASM_MEMORY_SPACE";
1227
+ this.rawSql = (0, import_mcard_wasm2.get_core_schema)();
1228
+ const vectorSql = (0, import_mcard_wasm2.get_vector_schema)();
1229
+ if (vectorSql) {
1230
+ this.rawSql += "\n\n" + vectorSql;
2572
1231
  }
2573
1232
  this.statements = this.parseStatements(this.rawSql);
2574
1233
  for (const stmt of this.statements) {
@@ -3571,7 +2230,7 @@ async function readFileSafely(filePath, options = {}) {
3571
2230
  const stats = await fs.stat(filePath);
3572
2231
  if (stats.size > MAX_FILE_SIZE2) throw new Error(`File too large: ${stats.size}`);
3573
2232
  const controller = new AbortController();
3574
- const timeout = setTimeout(() => controller.abort(), READ_TIMEOUT_MS);
2233
+ const timeout = setTimeout(() => controller.abort(), READ_TIMEOUT_MS2);
3575
2234
  try {
3576
2235
  const handle = await fs.open(filePath, "r");
3577
2236
  try {
@@ -3634,16 +2293,17 @@ async function processFileContent(filePath, options = {}) {
3634
2293
  size: rawContent.length
3635
2294
  };
3636
2295
  }
3637
- var crypto2, fs, path, MAX_FILE_SIZE2, READ_TIMEOUT_MS;
2296
+ var crypto2, fs, path, MAX_FILE_SIZE2, READ_TIMEOUT_MS2;
3638
2297
  var init_FileIO = __esm({
3639
2298
  "src/FileIO.ts"() {
3640
2299
  "use strict";
3641
2300
  crypto2 = __toESM(require("crypto"), 1);
3642
2301
  fs = __toESM(require("fs/promises"), 1);
3643
2302
  path = __toESM(require("path"), 1);
2303
+ init_constants();
3644
2304
  init_ContentTypeInterpreter();
3645
- MAX_FILE_SIZE2 = 50 * 1024 * 1024;
3646
- READ_TIMEOUT_MS = 5e3;
2305
+ MAX_FILE_SIZE2 = MAX_FILE_SIZE;
2306
+ READ_TIMEOUT_MS2 = READ_TIMEOUT_MS;
3647
2307
  }
3648
2308
  });
3649
2309
 
@@ -3664,13 +2324,13 @@ async function processAndStoreFile(filePath, collection, options = {}) {
3664
2324
  let fileInfo;
3665
2325
  if (await isProblematicFile(filePath)) {
3666
2326
  if (!allowProblematic) {
3667
- console.warn(`Skipping problematic file: ${filePath}`);
2327
+ Logger.warn(`Skipping problematic file: ${filePath}`);
3668
2328
  return null;
3669
2329
  }
3670
2330
  const extension = path2.extname(filePath).toLowerCase();
3671
2331
  const isKnownType = ContentTypeInterpreter.isKnownLongLineExtension(extension);
3672
2332
  const wrapWidth = isKnownType ? WRAP_WIDTH_KNOWN : WRAP_WIDTH_DEFAULT;
3673
- console.warn(`Problematic file detected, processing as safe text: ${filePath}`);
2333
+ Logger.warn(`Problematic file detected, processing as safe text: ${filePath}`);
3674
2334
  try {
3675
2335
  const streamed = await streamReadNormalizedText(filePath, {
3676
2336
  byteCap: maxBytesOnProblem,
@@ -3689,7 +2349,7 @@ async function processAndStoreFile(filePath, collection, options = {}) {
3689
2349
  wrapWidth
3690
2350
  };
3691
2351
  } catch (e) {
3692
- console.warn(`Safe text processing failed, falling back to capped binary: ${filePath}`);
2352
+ Logger.warn(`Safe text processing failed, falling back to capped binary: ${filePath}`, e);
3693
2353
  fileInfo = await processFileContent(filePath, {
3694
2354
  forceBinary: true,
3695
2355
  allowPathological: true,
@@ -3697,15 +2357,13 @@ async function processAndStoreFile(filePath, collection, options = {}) {
3697
2357
  });
3698
2358
  }
3699
2359
  } else {
3700
- console.log(`Processing file: ${filePath}`);
2360
+ Logger.info(`Processing file: ${filePath}`);
3701
2361
  fileInfo = await processFileContent(filePath);
3702
2362
  }
3703
2363
  if (!fileInfo) return null;
3704
2364
  const content = fileInfo.content;
3705
2365
  if (!content || typeof content === "string" && content.length === 0 || content instanceof Uint8Array && content.length === 0) {
3706
- if (process.env.DEBUG) {
3707
- console.log(`Skipping empty file: ${filePath} (empty files cannot be stored as MCards)`);
3708
- }
2366
+ Logger.debug(`Skipping empty file: ${filePath} (empty files cannot be stored as MCards)`);
3709
2367
  return {
3710
2368
  hash: "",
3711
2369
  contentType: fileInfo.mimeType,
@@ -3733,11 +2391,9 @@ async function processAndStoreFile(filePath, collection, options = {}) {
3733
2391
  await collection.addWithHandle(mcard, relPath);
3734
2392
  registered = true;
3735
2393
  } catch (e2) {
3736
- if (process.env.DEBUG) {
3737
- console.log(
3738
- `Handle name '${handle}' already in use (common for files like README.md, LICENSE). MCard stored successfully with hash ${mcard.hash.slice(0, 8)}... (accessible by hash, not by handle)`
3739
- );
3740
- }
2394
+ Logger.debug(
2395
+ `Handle name '${handle}' already in use (common for files like README.md, LICENSE). MCard stored successfully with hash ${mcard.hash.slice(0, 8)}... (accessible by hash, not by handle)`
2396
+ );
3741
2397
  }
3742
2398
  }
3743
2399
  }
@@ -3745,6 +2401,7 @@ async function processAndStoreFile(filePath, collection, options = {}) {
3745
2401
  try {
3746
2402
  await collection.add(mcard);
3747
2403
  } catch (e3) {
2404
+ Logger.warn(`Hash fallback also failed for ${handle}:`, e3);
3748
2405
  }
3749
2406
  }
3750
2407
  }
@@ -3762,7 +2419,7 @@ async function processAndStoreFile(filePath, collection, options = {}) {
3762
2419
  if (metadataOnly && isProblematic) result.metadataOnly = true;
3763
2420
  return result;
3764
2421
  } catch (e) {
3765
- console.error(`Error processing ${filePath}:`, e);
2422
+ Logger.error(`Error processing ${filePath}:`, e);
3766
2423
  return null;
3767
2424
  }
3768
2425
  }
@@ -3804,7 +2461,7 @@ async function loadFileToCollection(targetPath, collection, options = {}) {
3804
2461
  directoriesCount: uniqueDirs.size,
3805
2462
  directoryLevels: maxDepth
3806
2463
  };
3807
- console.log(`About to process ${files.length} files`);
2464
+ Logger.info(`About to process ${files.length} files`);
3808
2465
  for (const file of files) {
3809
2466
  const result = await processAndStoreFile(file, collection, {
3810
2467
  allowProblematic: includeProblematic,
@@ -3816,7 +2473,7 @@ async function loadFileToCollection(targetPath, collection, options = {}) {
3816
2473
  }
3817
2474
  return { metrics, results };
3818
2475
  }
3819
- var fs2, path2, DEFAULT_MAX_PROBLEM_BYTES2, WRAP_WIDTH_KNOWN, WRAP_WIDTH_DEFAULT;
2476
+ var fs2, path2, DEFAULT_MAX_PROBLEM_BYTES2, WRAP_WIDTH_KNOWN, WRAP_WIDTH_DEFAULT, Logger;
3820
2477
  var init_Loader = __esm({
3821
2478
  "src/Loader.ts"() {
3822
2479
  "use strict";
@@ -3828,6 +2485,14 @@ var init_Loader = __esm({
3828
2485
  DEFAULT_MAX_PROBLEM_BYTES2 = 2 * 1024 * 1024;
3829
2486
  WRAP_WIDTH_KNOWN = 1e3;
3830
2487
  WRAP_WIDTH_DEFAULT = 80;
2488
+ Logger = {
2489
+ info: (...args) => console.log("[Loader]", ...args),
2490
+ warn: (...args) => console.warn("[Loader]", ...args),
2491
+ error: (...args) => console.error("[Loader]", ...args),
2492
+ debug: (...args) => {
2493
+ if (process.env.DEBUG) console.log("[Loader]", ...args);
2494
+ }
2495
+ };
3831
2496
  }
3832
2497
  });
3833
2498
 
@@ -3836,6 +2501,7 @@ var DEFAULT_PROVIDER, LLM_PROVIDERS, DEFAULT_LLM_CONFIG, RESPONSE_FORMATS, LLMCo
3836
2501
  var init_Config = __esm({
3837
2502
  "src/ptr/llm/Config.ts"() {
3838
2503
  "use strict";
2504
+ init_constants();
3839
2505
  DEFAULT_PROVIDER = "ollama";
3840
2506
  LLM_PROVIDERS = {
3841
2507
  "ollama": {
@@ -3893,11 +2559,11 @@ var init_Config = __esm({
3893
2559
  max_tokens: 2048,
3894
2560
  top_p: 1,
3895
2561
  top_k: 40,
3896
- timeout: 120,
2562
+ timeout: LLM_DEFAULT_TIMEOUT_SECS,
3897
2563
  stream: false,
3898
2564
  response_format: "text",
3899
- retry_count: 3,
3900
- retry_delay: 1
2565
+ retry_count: LLM_DEFAULT_RETRY_COUNT,
2566
+ retry_delay: LLM_DEFAULT_RETRY_DELAY_SECS
3901
2567
  };
3902
2568
  RESPONSE_FORMATS = ["text", "json", "structured", "markdown"];
3903
2569
  LLMConfig = class _LLMConfig {
@@ -4056,6 +2722,7 @@ var http, https, OllamaProvider;
4056
2722
  var init_OllamaProvider = __esm({
4057
2723
  "src/ptr/llm/providers/OllamaProvider.ts"() {
4058
2724
  "use strict";
2725
+ init_constants();
4059
2726
  init_LLMProvider();
4060
2727
  init_Either();
4061
2728
  init_Config();
@@ -4066,7 +2733,7 @@ var init_OllamaProvider = __esm({
4066
2733
  base_url;
4067
2734
  timeout;
4068
2735
  config;
4069
- constructor(base_url = null, timeout = 180) {
2736
+ constructor(base_url = null, timeout = LLM_DEFAULT_TIMEOUT_SECS) {
4070
2737
  super();
4071
2738
  this.config = LLM_PROVIDERS["ollama"];
4072
2739
  this.base_url = (base_url || this.config.base_url).replace(/\/$/, "");
@@ -4085,6 +2752,11 @@ var init_OllamaProvider = __esm({
4085
2752
  timeout: this.timeout
4086
2753
  };
4087
2754
  return new Promise((resolve10) => {
2755
+ let payload;
2756
+ if (data) {
2757
+ payload = JSON.stringify(data);
2758
+ options.headers["Content-Length"] = Buffer.byteLength(payload);
2759
+ }
4088
2760
  const req = client.request(url, options, (res) => {
4089
2761
  let body = "";
4090
2762
  res.on("data", (chunk) => {
@@ -4122,18 +2794,21 @@ var init_OllamaProvider = __esm({
4122
2794
  req.destroy();
4123
2795
  resolve10(Either.left(`Ollama request timed out after ${this.timeout}ms`));
4124
2796
  });
4125
- if (data) {
4126
- req.write(JSON.stringify(data));
2797
+ if (payload) {
2798
+ req.write(payload);
4127
2799
  }
4128
2800
  req.end();
4129
2801
  });
4130
2802
  }
4131
- async complete(prompt, params) {
2803
+ async complete(prompt, params, images) {
4132
2804
  const data = {
4133
2805
  model: typeof params.model === "string" ? params.model : this.config.default_model,
4134
2806
  prompt,
4135
2807
  stream: false
4136
2808
  };
2809
+ if (images && images.length > 0) {
2810
+ data.images = images;
2811
+ }
4137
2812
  if (params.options) {
4138
2813
  data.options = params.options;
4139
2814
  }
@@ -4273,7 +2948,7 @@ var init_WebLLMProvider = __esm({
4273
2948
  return Either.left(`WebLLM init failed: ${error.message || String(e)}`);
4274
2949
  }
4275
2950
  }
4276
- async complete(prompt, params) {
2951
+ async complete(prompt, params, images) {
4277
2952
  const model = typeof params.model === "string" ? params.model : this.config.default_model;
4278
2953
  const engineResult = await this._get_engine(model);
4279
2954
  if (engineResult.isLeft) return Either.left(engineResult.left);
@@ -4340,6 +3015,7 @@ var http2, https2, MLCLLMProvider;
4340
3015
  var init_MLCLLMProvider = __esm({
4341
3016
  "src/ptr/llm/providers/MLCLLMProvider.ts"() {
4342
3017
  "use strict";
3018
+ init_constants();
4343
3019
  init_LLMProvider();
4344
3020
  init_Either();
4345
3021
  init_Config();
@@ -4350,7 +3026,7 @@ var init_MLCLLMProvider = __esm({
4350
3026
  base_url;
4351
3027
  timeout;
4352
3028
  config;
4353
- constructor(base_url = null, timeout = 120) {
3029
+ constructor(base_url = null, timeout = LLM_DEFAULT_TIMEOUT_SECS) {
4354
3030
  super();
4355
3031
  this.config = LLM_PROVIDERS["mlc-llm"];
4356
3032
  this.base_url = (base_url || this.config.base_url).replace(/\/$/, "");
@@ -4415,10 +3091,10 @@ var init_MLCLLMProvider = __esm({
4415
3091
  req.end();
4416
3092
  });
4417
3093
  }
4418
- async complete(prompt, params) {
3094
+ async complete(prompt, params, images) {
4419
3095
  const data = {
4420
- model: params.model || this.config.default_model,
4421
- prompt,
3096
+ model: typeof params.model === "string" ? params.model : this.config.default_model,
3097
+ messages: [{ role: "user", content: prompt }],
4422
3098
  max_tokens: params.max_tokens,
4423
3099
  temperature: params.temperature,
4424
3100
  top_p: params.top_p,
@@ -4488,7 +3164,7 @@ __export(LLMRuntime_exports, {
4488
3164
  get_provider: () => get_provider,
4489
3165
  promptMonad: () => promptMonad
4490
3166
  });
4491
- function get_provider(provider_name = DEFAULT_PROVIDER, base_url = null, timeout = 120) {
3167
+ function get_provider(provider_name = DEFAULT_PROVIDER, base_url = null, timeout = LLM_DEFAULT_TIMEOUT_SECS) {
4492
3168
  if (provider_name === "ollama") {
4493
3169
  return new OllamaProvider(base_url, timeout);
4494
3170
  }
@@ -4542,6 +3218,7 @@ var LLMRuntime;
4542
3218
  var init_LLMRuntime = __esm({
4543
3219
  "src/ptr/llm/LLMRuntime.ts"() {
4544
3220
  "use strict";
3221
+ init_constants();
4545
3222
  init_Config();
4546
3223
  init_OllamaProvider();
4547
3224
  init_WebLLMProvider();
@@ -4571,32 +3248,45 @@ var init_LLMRuntime = __esm({
4571
3248
  this._provider = get_provider(llmConfig.provider, llmConfig.endpoint_url, llmConfig.timeout);
4572
3249
  }
4573
3250
  let prompt = "";
3251
+ let images;
4574
3252
  if (typeof context === "string") {
4575
3253
  prompt = context;
4576
- } else {
4577
- prompt = JSON.stringify(context);
3254
+ } else if (context && typeof context === "object") {
3255
+ const ctx = context;
3256
+ if (typeof ctx.prompt === "string") {
3257
+ prompt = ctx.prompt;
3258
+ if (Array.isArray(ctx.images)) {
3259
+ images = ctx.images;
3260
+ }
3261
+ } else {
3262
+ prompt = JSON.stringify(context);
3263
+ }
4578
3264
  }
4579
3265
  let result;
4580
3266
  if (llmConfig.system_prompt) {
4581
- result = await this._execute_chat(prompt, llmConfig);
3267
+ result = await this._execute_chat(prompt, llmConfig, images);
4582
3268
  } else {
4583
- result = await this._execute_completion(prompt, llmConfig);
3269
+ result = await this._execute_completion(prompt, llmConfig, images);
4584
3270
  }
4585
3271
  if (result.isLeft) {
4586
3272
  return `Error: ${result.left}`;
4587
3273
  }
4588
3274
  return this._format_response(result.right, llmConfig);
4589
3275
  }
4590
- async _execute_completion(prompt, config) {
3276
+ async _execute_completion(prompt, config, images) {
4591
3277
  const params = config.to_provider_params();
4592
- return this.provider.complete(prompt, params);
3278
+ return this.provider.complete(prompt, params, images);
4593
3279
  }
4594
- async _execute_chat(prompt, config) {
3280
+ async _execute_chat(prompt, config, images) {
4595
3281
  const messages = [];
4596
3282
  if (config.system_prompt) {
4597
3283
  messages.push({ role: "system", content: config.system_prompt });
4598
3284
  }
4599
- messages.push({ role: "user", content: prompt });
3285
+ const userMsg = { role: "user", content: prompt };
3286
+ if (images && images.length > 0) {
3287
+ userMsg.images = images;
3288
+ }
3289
+ messages.push(userMsg);
4600
3290
  if (config.assistant_instruction) {
4601
3291
  messages.push({ role: "assistant", content: config.assistant_instruction });
4602
3292
  }
@@ -5614,6 +4304,7 @@ var init_javascript = __esm({
5614
4304
  vm = __toESM(require("vm"), 1);
5615
4305
  child_process2 = __toESM(require("child_process"), 1);
5616
4306
  util2 = __toESM(require("util"), 1);
4307
+ init_constants();
5617
4308
  init_base();
5618
4309
  init_FileSystemUtils();
5619
4310
  writeFile2 = util2.promisify(fs4.writeFile);
@@ -5665,7 +4356,7 @@ var init_javascript = __esm({
5665
4356
  const codeRunnable = code + "\nresult;";
5666
4357
  const script = new vm.Script(codeRunnable);
5667
4358
  const vmContext = vm.createContext(sandbox);
5668
- const executionResult = script.runInContext(vmContext, { timeout: 5e3 });
4359
+ const executionResult = script.runInContext(vmContext, { timeout: DEFAULT_VM_EXECUTION_TIMEOUT_MS });
5669
4360
  return sandbox.result !== void 0 ? sandbox.result : executionResult;
5670
4361
  }
5671
4362
  /**
@@ -5675,7 +4366,9 @@ var init_javascript = __esm({
5675
4366
  const contextStr = JSON.stringify(context);
5676
4367
  const projectRoot = findProjectRoot();
5677
4368
  const wrapper = `
5678
- const process = require('process');
4369
+ import process from 'process';
4370
+ import { createRequire } from 'module';
4371
+ const require = createRequire(import.meta.url);
5679
4372
  const context = JSON.parse(process.argv[2]);
5680
4373
  global.context = context;
5681
4374
  let result;
@@ -5768,6 +4461,35 @@ Stdout: ${execError.stdout.toString()}` : "";
5768
4461
  * Create Python wrapper script with entry point invocation.
5769
4462
  */
5770
4463
  createWrapper(code, entryPoint) {
4464
+ let userLogic = code;
4465
+ let actualEntryPoint = entryPoint;
4466
+ if (code.startsWith("module://")) {
4467
+ const withoutPrefix = code.substring(9);
4468
+ const colonIndex = withoutPrefix.indexOf(":");
4469
+ let modulePath = withoutPrefix;
4470
+ let moduleFunc = "";
4471
+ if (colonIndex !== -1) {
4472
+ modulePath = withoutPrefix.substring(0, colonIndex);
4473
+ moduleFunc = withoutPrefix.substring(colonIndex + 1);
4474
+ }
4475
+ if (modulePath) {
4476
+ if (moduleFunc) {
4477
+ actualEntryPoint = moduleFunc;
4478
+ }
4479
+ userLogic = `
4480
+ import importlib
4481
+ try:
4482
+ _mod = importlib.import_module('${modulePath}')
4483
+ for _k in dir(_mod):
4484
+ if not _k.startswith('_'):
4485
+ globals()[_k] = getattr(_mod, _k)
4486
+ except Exception as e:
4487
+ import sys, json
4488
+ print(json.dumps({"error": f"Failed to import module ${modulePath}: {e}"}))
4489
+ sys.exit(1)
4490
+ `;
4491
+ }
4492
+ }
5771
4493
  return `
5772
4494
  import sys
5773
4495
  import json
@@ -5784,7 +4506,7 @@ except:
5784
4506
  pass
5785
4507
 
5786
4508
  # User logic
5787
- ${code}
4509
+ ${userLogic}
5788
4510
 
5789
4511
  # Entry point invocation
5790
4512
  def _is_arg_error(e):
@@ -5793,10 +4515,10 @@ def _is_arg_error(e):
5793
4515
 
5794
4516
  try:
5795
4517
  fn = None
5796
- if '${entryPoint}' in dir():
5797
- fn = ${entryPoint}
5798
- elif '${entryPoint}' in globals():
5799
- fn = globals()['${entryPoint}']
4518
+ if '${actualEntryPoint}' in dir():
4519
+ fn = locals()['${actualEntryPoint}']
4520
+ elif '${actualEntryPoint}' in globals():
4521
+ fn = globals()['${actualEntryPoint}']
5800
4522
 
5801
4523
  if fn is not None:
5802
4524
  try:
@@ -6093,6 +4815,34 @@ var init_loader = __esm({
6093
4815
  }
6094
4816
  });
6095
4817
 
4818
+ // src/ptr/node/NetworkConfig.ts
4819
+ var HTTP_DEFAULT_MAX_ATTEMPTS, HTTP_DEFAULT_BACKOFF, HTTP_DEFAULT_BASE_DELAY_MS, HTTP_DEFAULT_MAX_DELAY_MS, HTTP_DEFAULT_TIMEOUT_MS, HTTP_DEFAULT_CACHE_TTL_SECONDS, RATE_LIMIT_DEFAULT_TOKENS_PER_SECOND, RATE_LIMIT_DEFAULT_MAX_BURST, RATE_LIMIT_WAIT_INTERVAL_MS, NETWORK_DEFAULT_LISTEN_PORT, NETWORK_DEFAULT_SIGNALING_MAX_PORT_TRIES, NETWORK_SIGNALING_PORT_RELEASE_WAIT_MS, NETWORK_DEFAULT_HOST, NETWORK_DEFAULT_ORCHESTRATOR_SLEEP_MS, WEBSOCKET_SERVER_START_WAIT_MS, STATIC_SERVER_START_WAIT_MS, PROCESS_TERMINATE_WAIT_MS, SESSION_RECORD_DEFAULT_MAX_BUFFER_SIZE, WEBRTC_DEFAULT_TIMEOUT_MS, WEBRTC_DEFAULT_MOCK_DELAY_MS;
4820
+ var init_NetworkConfig = __esm({
4821
+ "src/ptr/node/NetworkConfig.ts"() {
4822
+ "use strict";
4823
+ HTTP_DEFAULT_MAX_ATTEMPTS = 1;
4824
+ HTTP_DEFAULT_BACKOFF = "exponential";
4825
+ HTTP_DEFAULT_BASE_DELAY_MS = 1e3;
4826
+ HTTP_DEFAULT_MAX_DELAY_MS = 3e4;
4827
+ HTTP_DEFAULT_TIMEOUT_MS = 3e4;
4828
+ HTTP_DEFAULT_CACHE_TTL_SECONDS = 300;
4829
+ RATE_LIMIT_DEFAULT_TOKENS_PER_SECOND = 10;
4830
+ RATE_LIMIT_DEFAULT_MAX_BURST = 20;
4831
+ RATE_LIMIT_WAIT_INTERVAL_MS = 100;
4832
+ NETWORK_DEFAULT_LISTEN_PORT = 3e3;
4833
+ NETWORK_DEFAULT_SIGNALING_MAX_PORT_TRIES = 10;
4834
+ NETWORK_SIGNALING_PORT_RELEASE_WAIT_MS = 500;
4835
+ NETWORK_DEFAULT_HOST = "localhost";
4836
+ NETWORK_DEFAULT_ORCHESTRATOR_SLEEP_MS = 1e3;
4837
+ WEBSOCKET_SERVER_START_WAIT_MS = 3e3;
4838
+ STATIC_SERVER_START_WAIT_MS = 1500;
4839
+ PROCESS_TERMINATE_WAIT_MS = 500;
4840
+ SESSION_RECORD_DEFAULT_MAX_BUFFER_SIZE = 5;
4841
+ WEBRTC_DEFAULT_TIMEOUT_MS = 3e4;
4842
+ WEBRTC_DEFAULT_MOCK_DELAY_MS = 100;
4843
+ }
4844
+ });
4845
+
6096
4846
  // src/ptr/node/P2PChatSession.ts
6097
4847
  var P2PChatSession;
6098
4848
  var init_P2PChatSession = __esm({
@@ -6231,17 +4981,17 @@ function killProcessOnPort(port) {
6231
4981
  return new Promise((resolve10) => {
6232
4982
  (0, import_child_process.exec)(`lsof -ti:${port} | xargs kill -9 2>/dev/null`, (error) => {
6233
4983
  if (error) {
6234
- console.log(`[Signal] No existing process on port ${port} to kill`);
4984
+ Logger2.info(`No existing process on port ${port} to kill`);
6235
4985
  } else {
6236
- console.log(`[Signal] Killed existing process on port ${port}`);
4986
+ Logger2.info(`Killed existing process on port ${port}`);
6237
4987
  }
6238
- setTimeout(resolve10, 500);
4988
+ setTimeout(resolve10, NETWORK_SIGNALING_PORT_RELEASE_WAIT_MS);
6239
4989
  });
6240
4990
  });
6241
4991
  }
6242
4992
  async function createSignalingServer(config = {}) {
6243
- const startPort = config.port || 3e3;
6244
- const maxTries = config.maxPortTries || 10;
4993
+ const startPort = config.port || NETWORK_DEFAULT_LISTEN_PORT;
4994
+ const maxTries = config.maxPortTries || NETWORK_DEFAULT_SIGNALING_MAX_PORT_TRIES;
6245
4995
  const autoFindPort = config.autoFindPort !== false;
6246
4996
  const clients = /* @__PURE__ */ new Map();
6247
4997
  const messageBuffer = /* @__PURE__ */ new Map();
@@ -6272,7 +5022,7 @@ async function createSignalingServer(config = {}) {
6272
5022
  res.end("Missing peer_id");
6273
5023
  return;
6274
5024
  }
6275
- console.log(`[Signal] Client connected: ${peerId}`);
5025
+ Logger2.info(`Client connected: ${peerId}`);
6276
5026
  res.writeHead(200, {
6277
5027
  "Content-Type": "text/event-stream",
6278
5028
  "Cache-Control": "no-cache",
@@ -6292,7 +5042,7 @@ async function createSignalingServer(config = {}) {
6292
5042
  messageBuffer.delete(peerId);
6293
5043
  }
6294
5044
  req.on("close", () => {
6295
- console.log(`[Signal] Client disconnected: ${peerId}`);
5045
+ Logger2.info(`Client disconnected: ${peerId}`);
6296
5046
  clearInterval(keepAlive);
6297
5047
  clients.delete(peerId);
6298
5048
  });
@@ -6310,7 +5060,7 @@ async function createSignalingServer(config = {}) {
6310
5060
  res.end("Missing target");
6311
5061
  return;
6312
5062
  }
6313
- console.log(`[Signal] Relaying ${msg.type} to ${target}`);
5063
+ Logger2.info(`Relaying ${msg.type} to ${target}`);
6314
5064
  if (clients.has(target)) {
6315
5065
  clients.get(target).write(`data: ${JSON.stringify(msg)}
6316
5066
 
@@ -6325,7 +5075,7 @@ async function createSignalingServer(config = {}) {
6325
5075
  res.writeHead(200);
6326
5076
  res.end("Sent");
6327
5077
  } catch (e) {
6328
- console.error(e);
5078
+ Logger2.error(`Failed to handle generic post-signal error`, e);
6329
5079
  res.writeHead(500);
6330
5080
  res.end(String(e));
6331
5081
  }
@@ -6351,7 +5101,7 @@ async function createSignalingServer(config = {}) {
6351
5101
  resolve10();
6352
5102
  });
6353
5103
  });
6354
- console.log(`[Signal] Server running on port ${port}`);
5104
+ Logger2.info(`Server running on port ${port}`);
6355
5105
  return {
6356
5106
  success: true,
6357
5107
  port,
@@ -6361,7 +5111,7 @@ async function createSignalingServer(config = {}) {
6361
5111
  } catch (err) {
6362
5112
  server.removeAllListeners("error");
6363
5113
  if (attempt === 0 && autoFindPort) {
6364
- console.log(`[Signal] Port ${port} in use, trying to kill existing process...`);
5114
+ Logger2.info(`Port ${port} in use, trying to kill existing process...`);
6365
5115
  await killProcessOnPort(port);
6366
5116
  try {
6367
5117
  await new Promise((resolve10, reject) => {
@@ -6371,7 +5121,7 @@ async function createSignalingServer(config = {}) {
6371
5121
  resolve10();
6372
5122
  });
6373
5123
  });
6374
- console.log(`[Signal] Server running on port ${port} (after kill)`);
5124
+ Logger2.info(`Server running on port ${port} (after kill)`);
6375
5125
  return {
6376
5126
  success: true,
6377
5127
  port,
@@ -6388,7 +5138,7 @@ async function createSignalingServer(config = {}) {
6388
5138
  error: `Port ${port} is already in use`
6389
5139
  };
6390
5140
  }
6391
- console.log(`[Signal] Port ${port} still in use, trying next...`);
5141
+ Logger2.info(`Port ${port} still in use, trying next...`);
6392
5142
  }
6393
5143
  }
6394
5144
  return {
@@ -6396,12 +5146,18 @@ async function createSignalingServer(config = {}) {
6396
5146
  error: `Could not find available port after ${maxTries} attempts starting from ${startPort}`
6397
5147
  };
6398
5148
  }
6399
- var import_http, import_child_process;
5149
+ var import_http, import_child_process, Logger2;
6400
5150
  var init_SignalingServer = __esm({
6401
5151
  "src/ptr/node/SignalingServer.ts"() {
6402
5152
  "use strict";
6403
5153
  import_http = require("http");
6404
5154
  import_child_process = require("child_process");
5155
+ init_NetworkConfig();
5156
+ Logger2 = {
5157
+ info: (...args) => console.log("[Signal]", ...args),
5158
+ warn: (...args) => console.warn("[Signal]", ...args),
5159
+ error: (...args) => console.error("[Signal]", ...args)
5160
+ };
6405
5161
  }
6406
5162
  });
6407
5163
 
@@ -6589,10 +5345,11 @@ var init_NetworkInfrastructure = __esm({
6589
5345
  "src/ptr/node/network/NetworkInfrastructure.ts"() {
6590
5346
  "use strict";
6591
5347
  init_MCard();
5348
+ init_NetworkConfig();
6592
5349
  RateLimiter = class {
6593
5350
  limits;
6594
5351
  defaultLimit;
6595
- constructor(tokensPerSecond = 10, maxBurst = 20) {
5352
+ constructor(tokensPerSecond = RATE_LIMIT_DEFAULT_TOKENS_PER_SECOND, maxBurst = RATE_LIMIT_DEFAULT_MAX_BURST) {
6596
5353
  this.limits = /* @__PURE__ */ new Map();
6597
5354
  this.defaultLimit = { tokensPerSecond, maxBurst };
6598
5355
  }
@@ -6622,7 +5379,7 @@ var init_NetworkInfrastructure = __esm({
6622
5379
  */
6623
5380
  async waitFor(domain) {
6624
5381
  while (!this.check(domain)) {
6625
- await new Promise((resolve10) => setTimeout(resolve10, 100));
5382
+ await new Promise((resolve10) => setTimeout(resolve10, RATE_LIMIT_WAIT_INTERVAL_MS));
6626
5383
  }
6627
5384
  }
6628
5385
  };
@@ -6711,6 +5468,7 @@ var HttpClient;
6711
5468
  var init_HttpClient = __esm({
6712
5469
  "src/ptr/node/network/HttpClient.ts"() {
6713
5470
  "use strict";
5471
+ init_NetworkConfig();
6714
5472
  init_MCard();
6715
5473
  init_NetworkInfrastructure();
6716
5474
  HttpClient = class {
@@ -6735,16 +5493,16 @@ var init_HttpClient = __esm({
6735
5493
  const domain = fetchUrl.hostname;
6736
5494
  await this.rateLimiter.waitFor(domain);
6737
5495
  const retryConfig = config.retry || {
6738
- max_attempts: 1,
6739
- backoff: "exponential",
6740
- base_delay: 1e3,
6741
- max_delay: 3e4
5496
+ max_attempts: HTTP_DEFAULT_MAX_ATTEMPTS,
5497
+ backoff: HTTP_DEFAULT_BACKOFF,
5498
+ base_delay: HTTP_DEFAULT_BASE_DELAY_MS,
5499
+ max_delay: HTTP_DEFAULT_MAX_DELAY_MS
6742
5500
  };
6743
5501
  let lastError = null;
6744
5502
  let lastStatus = null;
6745
5503
  let retriesAttempted = 0;
6746
5504
  for (let attempt = 1; attempt <= retryConfig.max_attempts; attempt++) {
6747
- const timeout = config.timeout || 3e4;
5505
+ const timeout = config.timeout || HTTP_DEFAULT_TIMEOUT_MS;
6748
5506
  const controller = new AbortController();
6749
5507
  const timeoutId = setTimeout(() => controller.abort(), timeout);
6750
5508
  try {
@@ -6811,7 +5569,12 @@ var init_HttpClient = __esm({
6811
5569
  mcard_hash
6812
5570
  };
6813
5571
  if (cacheConfig?.enabled && method === "GET" && response.ok) {
6814
- await this.cache.set(cacheKey, result, cacheConfig.ttl, cacheConfig.storage === "mcard");
5572
+ await this.cache.set(
5573
+ cacheKey,
5574
+ result,
5575
+ cacheConfig.ttl ?? HTTP_DEFAULT_CACHE_TTL_SECONDS,
5576
+ cacheConfig.storage === "mcard"
5577
+ );
6815
5578
  }
6816
5579
  return result;
6817
5580
  } catch (error) {
@@ -6856,6 +5619,7 @@ var init_NetworkRuntime = __esm({
6856
5619
  "src/ptr/node/NetworkRuntime.ts"() {
6857
5620
  "use strict";
6858
5621
  http3 = __toESM(require("http"), 1);
5622
+ init_NetworkConfig();
6859
5623
  init_P2PChatSession();
6860
5624
  init_SignalingServer();
6861
5625
  init_NetworkSecurity();
@@ -6994,7 +5758,7 @@ var init_NetworkRuntime = __esm({
6994
5758
  }, context);
6995
5759
  }
6996
5760
  async handleListenHttp(config, context) {
6997
- const port = Number(this.interpolate(String(config.port || 3e3), context));
5761
+ const port = Number(this.interpolate(String(config.port || NETWORK_DEFAULT_LISTEN_PORT), context));
6998
5762
  const path15 = this.interpolate(config.path || "/mcard", context);
6999
5763
  return new Promise((resolve10, reject) => {
7000
5764
  const server = http3.createServer(async (req, res) => {
@@ -7163,7 +5927,7 @@ var init_NetworkRuntime = __esm({
7163
5927
  status: "connected",
7164
5928
  mock: true
7165
5929
  });
7166
- }, 100);
5930
+ }, WEBRTC_DEFAULT_MOCK_DELAY_MS);
7167
5931
  });
7168
5932
  }
7169
5933
  console.log(`[WebRTC] Connecting to ${targetPeerId} via ${signalingUrl} as ${myPeerId}`);
@@ -7172,7 +5936,7 @@ var init_NetworkRuntime = __esm({
7172
5936
  });
7173
5937
  const dc = pc.createDataChannel(channelLabel);
7174
5938
  const connectionPromise = new Promise((resolve10, reject) => {
7175
- const timeoutMs = config.timeout || 3e4;
5939
+ const timeoutMs = config.timeout || WEBRTC_DEFAULT_TIMEOUT_MS;
7176
5940
  const timeoutId = setTimeout(() => {
7177
5941
  pc.close();
7178
5942
  reject(new Error("WebRTC connection timed out"));
@@ -7277,7 +6041,7 @@ var init_NetworkRuntime = __esm({
7277
6041
  status: "listening",
7278
6042
  mock: true
7279
6043
  });
7280
- }, 100);
6044
+ }, WEBRTC_DEFAULT_MOCK_DELAY_MS);
7281
6045
  });
7282
6046
  }
7283
6047
  console.log(`[WebRTC] Listening on ${signalingUrl} as ${myPeerId}`);
@@ -7292,7 +6056,7 @@ var init_NetworkRuntime = __esm({
7292
6056
  if (!this.collection) {
7293
6057
  throw new Error("Listen Sync requires a CardCollection.");
7294
6058
  }
7295
- const port = Number(this.interpolate(String(config.port || 3e3), context));
6059
+ const port = Number(this.interpolate(String(config.port || NETWORK_DEFAULT_LISTEN_PORT), context));
7296
6060
  const basePath = this.interpolate(config.base_path || "/sync", context);
7297
6061
  return new Promise((resolve10, reject) => {
7298
6062
  const server = http3.createServer(async (req, res) => {
@@ -7406,7 +6170,7 @@ var init_NetworkRuntime = __esm({
7406
6170
  if (this.sessions.has(sessionId)) {
7407
6171
  return { success: true, message: "Session already exists", sessionId };
7408
6172
  }
7409
- let bufferSize = config.maxBufferSize || 5;
6173
+ let bufferSize = config.maxBufferSize || SESSION_RECORD_DEFAULT_MAX_BUFFER_SIZE;
7410
6174
  if (typeof config.maxBufferSize === "string") {
7411
6175
  bufferSize = parseInt(this.interpolate(config.maxBufferSize, context), 10);
7412
6176
  }
@@ -7589,10 +6353,10 @@ var init_NetworkRuntime = __esm({
7589
6353
  console.warn(`[Orchestrator] No PID found for key '${key}'`);
7590
6354
  }
7591
6355
  } else if (step.action === "sleep") {
7592
- const ms = step.ms || 1e3;
6356
+ const ms = step.ms || NETWORK_DEFAULT_ORCHESTRATOR_SLEEP_MS;
7593
6357
  await new Promise((r) => setTimeout(r, ms));
7594
6358
  } else if (step.action === "start_signaling_server") {
7595
- const port = step.port || 3e3;
6359
+ const port = step.port || NETWORK_DEFAULT_LISTEN_PORT;
7596
6360
  console.log(`[Orchestrator] Starting builtin signaling server on port ${port}...`);
7597
6361
  const result = await this.handleSignalingServer({ port, background: true }, context);
7598
6362
  if (result.success) {
@@ -7694,12 +6458,12 @@ ${stdout}`);
7694
6458
  });
7695
6459
  }
7696
6460
  async handleSignalingServer(config, _context) {
7697
- const port = config.port || 3e3;
6461
+ const port = config.port || NETWORK_DEFAULT_LISTEN_PORT;
7698
6462
  console.log(`[NetworkRuntime] Starting signaling server on port ${port}...`);
7699
6463
  const result = await createSignalingServer({
7700
6464
  port,
7701
6465
  autoFindPort: true,
7702
- maxPortTries: 10
6466
+ maxPortTries: NETWORK_DEFAULT_SIGNALING_MAX_PORT_TRIES
7703
6467
  });
7704
6468
  if (result.success && result.server) {
7705
6469
  this._signalingServer = result.server;
@@ -8995,6 +7759,7 @@ var ErrorCodes = {
8995
7759
  };
8996
7760
 
8997
7761
  // src/ptr/SandboxWorker.ts
7762
+ init_constants();
8998
7763
  var WORKER_CODE = `
8999
7764
  // Multi-runtime sandboxed execution environment
9000
7765
  let pyodide = null;
@@ -9007,7 +7772,7 @@ const PYODIDE_CDN = 'https://cdn.jsdelivr.net/pyodide/v0.24.1/full/';
9007
7772
  async function loadPyodide() {
9008
7773
  if (pyodide) return pyodide;
9009
7774
  if (pyodideLoading) return pyodideLoading;
9010
-
7775
+
9011
7776
  pyodideLoading = (async () => {
9012
7777
  // Import Pyodide from CDN
9013
7778
  importScripts(PYODIDE_CDN + 'pyodide.js');
@@ -9017,25 +7782,25 @@ async function loadPyodide() {
9017
7782
  console.log('[SandboxWorker] Pyodide loaded successfully');
9018
7783
  return pyodide;
9019
7784
  })();
9020
-
7785
+
9021
7786
  return pyodideLoading;
9022
7787
  }
9023
7788
 
9024
7789
  self.onmessage = async function(e) {
9025
7790
  const request = e.data;
9026
-
7791
+
9027
7792
  try {
9028
7793
  if (request.method === 'pcard.execute') {
9029
7794
  const { pcard, context } = request.params;
9030
7795
  const runtime = pcard.runtime || 'javascript';
9031
-
7796
+
9032
7797
  let result;
9033
7798
  if (runtime === 'python' || runtime === 'py') {
9034
7799
  result = await executePython(pcard.code, pcard.input, context);
9035
7800
  } else {
9036
7801
  result = await executeJavaScript(pcard.code, pcard.input, context);
9037
7802
  }
9038
-
7803
+
9039
7804
  self.postMessage({
9040
7805
  jsonrpc: '2.0',
9041
7806
  id: request.id,
@@ -9090,11 +7855,11 @@ async function executeJavaScript(code, input, context) {
9090
7855
  // Execute Python code via Pyodide
9091
7856
  async function executePython(code, input, context) {
9092
7857
  const py = await loadPyodide();
9093
-
7858
+
9094
7859
  // Convert input to Python dict
9095
7860
  py.globals.set('input', py.toPy(input || {}));
9096
7861
  py.globals.set('context', py.toPy(context || {}));
9097
-
7862
+
9098
7863
  // Wrap code to capture result
9099
7864
  const wrappedCode = \`
9100
7865
  import json
@@ -9115,7 +7880,7 @@ result = None
9115
7880
  # Return result
9116
7881
  result
9117
7882
  \`;
9118
-
7883
+
9119
7884
  try {
9120
7885
  const pyResult = await py.runPythonAsync(wrappedCode);
9121
7886
  // Convert Python result to JavaScript
@@ -9131,8 +7896,7 @@ var SandboxWorker = class {
9131
7896
  worker = null;
9132
7897
  pythonLoaded = false;
9133
7898
  pendingRequests = /* @__PURE__ */ new Map();
9134
- defaultTimeout = 5e3;
9135
- // 5 seconds
7899
+ defaultTimeout = DEFAULT_SANDBOX_TIMEOUT_MS;
9136
7900
  /**
9137
7901
  * Initialize the sandbox worker
9138
7902
  */
@@ -9364,24 +8128,24 @@ var MCardStore = class {
9364
8128
  async setHandle(handle, newHash) {
9365
8129
  const db = await this.dbPromise;
9366
8130
  const tx = db.transaction(["handle_registry", "handle_history"], "readwrite");
9367
- const registry2 = tx.objectStore("handle_registry");
8131
+ const registry = tx.objectStore("handle_registry");
9368
8132
  const history = tx.objectStore("handle_history");
9369
8133
  const now = (/* @__PURE__ */ new Date()).toISOString();
9370
- const existing = await registry2.get(handle);
8134
+ const existing = await registry.get(handle);
9371
8135
  if (existing) {
9372
8136
  await history.add({
9373
8137
  handle,
9374
8138
  previous_hash: existing.current_hash,
9375
8139
  changed_at: now
9376
8140
  });
9377
- await registry2.put({
8141
+ await registry.put({
9378
8142
  handle,
9379
8143
  current_hash: newHash,
9380
8144
  created_at: existing.created_at,
9381
8145
  updated_at: now
9382
8146
  });
9383
8147
  } else {
9384
- await registry2.put({
8148
+ await registry.put({
9385
8149
  handle,
9386
8150
  current_hash: newHash,
9387
8151
  created_at: now,
@@ -9393,8 +8157,8 @@ var MCardStore = class {
9393
8157
  async resolveHandle(handle) {
9394
8158
  const db = await this.dbPromise;
9395
8159
  const tx = db.transaction(["handle_registry", "card"], "readonly");
9396
- const registry2 = tx.objectStore("handle_registry");
9397
- const entry = await registry2.get(handle);
8160
+ const registry = tx.objectStore("handle_registry");
8161
+ const entry = await registry.get(handle);
9398
8162
  if (!entry) return void 0;
9399
8163
  const cardStore = tx.objectStore("card");
9400
8164
  return cardStore.get(entry.current_hash);
@@ -9792,6 +8556,8 @@ function buildBaseContext(clm, input) {
9792
8556
  const inputObj = asObject(input);
9793
8557
  return {
9794
8558
  balanced: clm.clm.balanced,
8559
+ input_arguments: clm.clm.concrete?.input_arguments,
8560
+ output_arguments: clm.clm.concrete?.output_arguments,
9795
8561
  params: inputObj,
9796
8562
  ...inputObj
9797
8563
  };
@@ -9821,6 +8587,7 @@ function isMultiRuntime(clm) {
9821
8587
  // src/ptr/node/clm/runner.ts
9822
8588
  var path14 = __toESM(require("path"), 1);
9823
8589
  var yaml2 = __toESM(require("yaml"), 1);
8590
+ init_constants();
9824
8591
 
9825
8592
  // src/ptr/node/runtimes/index.ts
9826
8593
  init_base();
@@ -10922,6 +9689,7 @@ async function executePruneSingle(handle, versions, pruneType, olderThanSeconds)
10922
9689
  var import_child_process2 = require("child_process");
10923
9690
  var fs8 = __toESM(require("fs"), 1);
10924
9691
  var path10 = __toESM(require("path"), 1);
9692
+ init_NetworkConfig();
10925
9693
  function resolveConfigValue(val) {
10926
9694
  if (typeof val === "string" && val.startsWith("${") && val.endsWith("}")) {
10927
9695
  const envVar = val.slice(2, -1);
@@ -10951,7 +9719,7 @@ async function executeStaticServer(config, context, chapterDir) {
10951
9719
  const defaultPort = parseInt(process.env.HTTP_PORT || "8080", 10);
10952
9720
  const rawPort = context.port || config.port || defaultPort;
10953
9721
  const port = parseInt(String(resolveConfigValue(rawPort)), 10);
10954
- const host = context.host || config.host || "localhost";
9722
+ const host = context.host || config.host || NETWORK_DEFAULT_HOST;
10955
9723
  let rootDir = context.root_dir || config.root_dir || ".";
10956
9724
  let projectRoot = chapterDir;
10957
9725
  while (projectRoot !== path10.dirname(projectRoot)) {
@@ -11052,7 +9820,7 @@ setInterval(() => {}, 1000);
11052
9820
  });
11053
9821
  child.unref();
11054
9822
  fs8.writeFileSync(pidFile, String(child.pid));
11055
- await new Promise((resolve10) => setTimeout(resolve10, 1500));
9823
+ await new Promise((resolve10) => setTimeout(resolve10, STATIC_SERVER_START_WAIT_MS));
11056
9824
  if (isPortInUse(port)) {
11057
9825
  return {
11058
9826
  success: true,
@@ -11105,10 +9873,10 @@ setInterval(() => {}, 1000);
11105
9873
  }
11106
9874
  try {
11107
9875
  process.kill(pid, "SIGTERM");
11108
- await new Promise((resolve10) => setTimeout(resolve10, 500));
9876
+ await new Promise((resolve10) => setTimeout(resolve10, PROCESS_TERMINATE_WAIT_MS));
11109
9877
  if (isPortInUse(port)) {
11110
9878
  process.kill(pid, "SIGKILL");
11111
- await new Promise((resolve10) => setTimeout(resolve10, 500));
9879
+ await new Promise((resolve10) => setTimeout(resolve10, PROCESS_TERMINATE_WAIT_MS));
11112
9880
  }
11113
9881
  if (fs8.existsSync(pidFile)) {
11114
9882
  fs8.unlinkSync(pidFile);
@@ -11143,6 +9911,7 @@ setInterval(() => {}, 1000);
11143
9911
  var import_child_process3 = require("child_process");
11144
9912
  var fs9 = __toESM(require("fs"), 1);
11145
9913
  var path11 = __toESM(require("path"), 1);
9914
+ init_NetworkConfig();
11146
9915
  function resolveConfigValue2(val) {
11147
9916
  if (typeof val === "string" && val.startsWith("${") && val.endsWith("}")) {
11148
9917
  const envVar = val.slice(2, -1);
@@ -11172,7 +9941,7 @@ async function executeWebSocketServer(config, context, chapterDir) {
11172
9941
  const defaultPort = parseInt(process.env.VITE_WS_PORT || process.env.WS_PORT || "5321", 10);
11173
9942
  const rawPort = context.port || config.port || defaultPort;
11174
9943
  const port = parseInt(String(resolveConfigValue2(rawPort)), 10);
11175
- const host = context.host || config.host || "localhost";
9944
+ const host = context.host || config.host || NETWORK_DEFAULT_HOST;
11176
9945
  let projectRoot = chapterDir;
11177
9946
  while (projectRoot !== path11.dirname(projectRoot)) {
11178
9947
  if (fs9.existsSync(path11.join(projectRoot, "package.json")) || fs9.existsSync(path11.join(projectRoot, ".git"))) {
@@ -11250,7 +10019,7 @@ Process exited with code ${code}
11250
10019
  } catch {
11251
10020
  }
11252
10021
  fs9.writeFileSync(pidFile, String(child.pid));
11253
- await new Promise((resolve10) => setTimeout(resolve10, 3e3));
10022
+ await new Promise((resolve10) => setTimeout(resolve10, WEBSOCKET_SERVER_START_WAIT_MS));
11254
10023
  if (isPortInUse2(port)) {
11255
10024
  console.log(`[WebSocket Server] Successfully started on port ${port}`);
11256
10025
  return {
@@ -11314,10 +10083,10 @@ Process exited with code ${code}
11314
10083
  }
11315
10084
  try {
11316
10085
  process.kill(pid, "SIGTERM");
11317
- await new Promise((resolve10) => setTimeout(resolve10, 500));
10086
+ await new Promise((resolve10) => setTimeout(resolve10, PROCESS_TERMINATE_WAIT_MS));
11318
10087
  if (isPortInUse2(port)) {
11319
10088
  process.kill(pid, "SIGKILL");
11320
- await new Promise((resolve10) => setTimeout(resolve10, 500));
10089
+ await new Promise((resolve10) => setTimeout(resolve10, PROCESS_TERMINATE_WAIT_MS));
11321
10090
  }
11322
10091
  if (fs9.existsSync(pidFile)) {
11323
10092
  fs9.unlinkSync(pidFile);
@@ -11465,6 +10234,9 @@ var CLMLoader = class {
11465
10234
  }
11466
10235
  }
11467
10236
  if (config.code_file) {
10237
+ if (config.code_file.startsWith("module://")) {
10238
+ return config.code_file;
10239
+ }
11468
10240
  const logicPath = path12.resolve(this.basePath, chapterDir, config.code_file);
11469
10241
  if (fs10.existsSync(logicPath)) {
11470
10242
  return fs10.readFileSync(logicPath, "utf-8");
@@ -11643,7 +10415,7 @@ var CLMRunner = class _CLMRunner {
11643
10415
  loader;
11644
10416
  timeout;
11645
10417
  collection;
11646
- constructor(basePath = process.cwd(), timeout = 5e3, collection) {
10418
+ constructor(basePath = process.cwd(), timeout = DEFAULT_CLM_TIMEOUT_MS, collection) {
11647
10419
  this.loader = new CLMLoader(basePath);
11648
10420
  this.timeout = timeout;
11649
10421
  this.collection = collection;
@@ -12119,92 +10891,6 @@ var TextValidator = class _TextValidator extends BaseValidator {
12119
10891
  }
12120
10892
  };
12121
10893
 
12122
- // src/model/detectors/BinarySignatureDetector.ts
12123
- var BinarySignatureDetector2 = class _BinarySignatureDetector {
12124
- // Dictionary of binary signatures mapped to MIME types
12125
- // Note: In TS, we use numbers or number arrays for bytes
12126
- static SIGNATURES = {
12127
- // Images
12128
- "89504e470d0a1a0a": "image/png",
12129
- // \x89PNG\r\n\x1a\n
12130
- "ffd8ff": "image/jpeg",
12131
- "474946383761": "image/gif",
12132
- // GIF87a
12133
- "474946383961": "image/gif",
12134
- // GIF89a
12135
- "424d": "image/bmp",
12136
- // BM
12137
- "00000100": "image/x-icon",
12138
- "00000200": "image/x-icon",
12139
- // MP4
12140
- "00000018667479706d703432": "video/mp4",
12141
- // ...ftypmp42
12142
- "000000186674797069736f6d": "video/mp4",
12143
- // ...ftypisom
12144
- // ... (simplified for key common ones)
12145
- // Documents
12146
- "25504446": "application/pdf",
12147
- // %PDF
12148
- // Archives
12149
- "504b0304": "application/zip",
12150
- // PK\x03\x04
12151
- "1f8b08": "application/gzip",
12152
- "526172211a0700": "application/x-rar-compressed",
12153
- // Rar!
12154
- "377abcaf271c": "application/x-7z-compressed",
12155
- // 7z...
12156
- // Database
12157
- "53514c69746520666f726d6174203300": "application/x-sqlite3"
12158
- // SQLite format 3\0
12159
- };
12160
- static OLE_SIGNATURE = "d0cf11e0a1b11ae1";
12161
- /**
12162
- * Helper to convert hex string to Uint8Array for easy comparison if needed,
12163
- * but we will convert input bytes to hex for lookup.
12164
- */
12165
- detect(content) {
12166
- return this.detectFromBytes(content);
12167
- }
12168
- detectFromBytes(content) {
12169
- if (this.startsWithAscii(content, "RIFF")) {
12170
- return this.detectRiffFormat(content);
12171
- }
12172
- const hexHeader = this.toHex(content.slice(0, 32));
12173
- for (const [signature, mimeType] of Object.entries(_BinarySignatureDetector.SIGNATURES)) {
12174
- if (hexHeader.startsWith(signature)) {
12175
- if (signature === _BinarySignatureDetector.OLE_SIGNATURE) {
12176
- return "application/oleobject";
12177
- }
12178
- if (signature === "504b0304") {
12179
- return "application/zip";
12180
- }
12181
- return mimeType;
12182
- }
12183
- }
12184
- return "application/octet-stream";
12185
- }
12186
- detectRiffFormat(content) {
12187
- if (content.length < 12) return "application/octet-stream";
12188
- const formatType = this.toAscii(content.slice(8, 12));
12189
- if (formatType === "WAVE") return "audio/wav";
12190
- if (formatType === "WEBP") return "image/webp";
12191
- return "application/octet-stream";
12192
- }
12193
- startsWithAscii(content, str) {
12194
- if (content.length < str.length) return false;
12195
- for (let i = 0; i < str.length; i++) {
12196
- if (content[i] !== str.charCodeAt(i)) return false;
12197
- }
12198
- return true;
12199
- }
12200
- toAscii(content) {
12201
- return Array.from(content).map((b) => String.fromCharCode(b)).join("");
12202
- }
12203
- toHex(content) {
12204
- return Array.from(content).map((b) => b.toString(16).padStart(2, "0")).join("");
12205
- }
12206
- };
12207
-
12208
10894
  // src/model/validators/BinaryValidator.ts
12209
10895
  var BinaryValidator = class _BinaryValidator extends BaseValidator {
12210
10896
  static BINARY_MIME_TYPES = /* @__PURE__ */ new Set([
@@ -12218,7 +10904,6 @@ var BinaryValidator = class _BinaryValidator extends BaseValidator {
12218
10904
  "audio/wav",
12219
10905
  "application/octet-stream"
12220
10906
  ]);
12221
- detector = new BinarySignatureDetector2();
12222
10907
  canValidate(mimeType) {
12223
10908
  return _BinaryValidator.BINARY_MIME_TYPES.has(mimeType) || mimeType.startsWith("image/") || mimeType.startsWith("audio/") || mimeType.startsWith("video/");
12224
10909
  }
@@ -12246,29 +10931,19 @@ var BinaryValidator = class _BinaryValidator extends BaseValidator {
12246
10931
  } else if (mimeType === "image/gif" && content.length <= 6) {
12247
10932
  throw new ValidationError("Invalid GIF content: truncated file");
12248
10933
  }
12249
- const signatures = BinarySignatureDetector2.SIGNATURES;
12250
- let expectedSig = null;
12251
- for (const [sig, mime] of Object.entries(signatures)) {
12252
- if (mime === mimeType) {
12253
- expectedSig = sig;
12254
- }
12255
- }
12256
- if (expectedSig) {
12257
- const contentHex = this.toHex(content.slice(0, expectedSig.length / 2));
12258
- if (contentHex !== expectedSig) {
12259
- let hasMatch = false;
12260
- for (const [sig, mime] of Object.entries(signatures)) {
12261
- if (mime === mimeType) {
12262
- const currentHex = this.toHex(content.slice(0, sig.length / 2));
12263
- if (currentHex === sig) {
12264
- hasMatch = true;
12265
- break;
12266
- }
12267
- }
12268
- }
12269
- if (!hasMatch) {
12270
- throw new ValidationError(`Invalid ${mimeType} content: missing proper header`);
12271
- }
10934
+ const signatures = {
10935
+ "image/png": "89504e470d0a1a0a",
10936
+ // \x89PNG\r\n\x1a\n
10937
+ "image/jpeg": "ffd8ff",
10938
+ // \xff\xd8\xff
10939
+ "image/gif": "47494638"
10940
+ // GIF8
10941
+ };
10942
+ if (signatures[mimeType]) {
10943
+ const expectedSig = signatures[mimeType];
10944
+ const currentHex = this.toHex(content.slice(0, expectedSig.length / 2));
10945
+ if (!currentHex.startsWith(expectedSig) && currentHex !== expectedSig) {
10946
+ throw new ValidationError(`Invalid ${mimeType} content: missing proper header`);
12272
10947
  }
12273
10948
  }
12274
10949
  }
@@ -12306,7 +10981,7 @@ var ValidationRegistry = class {
12306
10981
  }
12307
10982
  /**
12308
10983
  * Validate content using appropriate validator.
12309
- *
10984
+ *
12310
10985
  * @param content The content to validate
12311
10986
  * @param mimeType The detected MIME type
12312
10987
  * @throws ValidationError If content is invalid