@iworkforces/tracelattice 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (422) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +260 -0
  3. package/dist/CliLifecycle.d.ts +31 -0
  4. package/dist/CliLifecycle.d.ts.map +1 -0
  5. package/dist/CliLifecycle.js +90 -0
  6. package/dist/CliLifecycle.js.map +1 -0
  7. package/dist/ServerConfig.d.ts +290 -0
  8. package/dist/ServerConfig.d.ts.map +1 -0
  9. package/dist/ServerConfig.js +175 -0
  10. package/dist/ServerConfig.js.map +1 -0
  11. package/dist/cache/DiscoveryCache.d.ts +269 -0
  12. package/dist/cache/DiscoveryCache.d.ts.map +1 -0
  13. package/dist/cache/DiscoveryCache.js +104 -0
  14. package/dist/cache/DiscoveryCache.js.map +1 -0
  15. package/dist/cli.d.ts +3 -0
  16. package/dist/cli.d.ts.map +1 -0
  17. package/dist/cli.js +5177 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/config/ConfigLoader.d.ts +270 -0
  20. package/dist/config/ConfigLoader.d.ts.map +1 -0
  21. package/dist/config/ConfigLoader.js +186 -0
  22. package/dist/config/ConfigLoader.js.map +1 -0
  23. package/dist/context/RequestContext.d.ts +43 -0
  24. package/dist/context/RequestContext.d.ts.map +1 -0
  25. package/dist/context/RequestContext.js +14 -0
  26. package/dist/context/RequestContext.js.map +1 -0
  27. package/dist/contracts/PersistenceBackend.d.ts +134 -0
  28. package/dist/contracts/PersistenceBackend.d.ts.map +1 -0
  29. package/dist/contracts/PersistenceBackend.js +6 -0
  30. package/dist/contracts/PersistenceBackend.js.map +1 -0
  31. package/dist/contracts/calibrator.d.ts +97 -0
  32. package/dist/contracts/calibrator.d.ts.map +1 -0
  33. package/dist/contracts/calibrator.js +1 -0
  34. package/dist/contracts/features.d.ts +35 -0
  35. package/dist/contracts/features.d.ts.map +1 -0
  36. package/dist/contracts/features.js +12 -0
  37. package/dist/contracts/features.js.map +1 -0
  38. package/dist/contracts/ids.d.ts +68 -0
  39. package/dist/contracts/ids.d.ts.map +1 -0
  40. package/dist/contracts/ids.js +40 -0
  41. package/dist/contracts/ids.js.map +1 -0
  42. package/dist/contracts/interfaces.d.ts +254 -0
  43. package/dist/contracts/interfaces.d.ts.map +1 -0
  44. package/dist/contracts/interfaces.js +1 -0
  45. package/dist/contracts/persistence-work.d.ts +96 -0
  46. package/dist/contracts/persistence-work.d.ts.map +1 -0
  47. package/dist/contracts/persistence-work.js +1 -0
  48. package/dist/contracts/reasoning-types.d.ts +21 -0
  49. package/dist/contracts/reasoning-types.d.ts.map +1 -0
  50. package/dist/contracts/reasoning-types.js +1 -0
  51. package/dist/contracts/strategy.d.ts +107 -0
  52. package/dist/contracts/strategy.d.ts.map +1 -0
  53. package/dist/contracts/strategy.js +1 -0
  54. package/dist/contracts/summary.d.ts +110 -0
  55. package/dist/contracts/summary.d.ts.map +1 -0
  56. package/dist/contracts/summary.js +1 -0
  57. package/dist/contracts/suspension.d.ts +215 -0
  58. package/dist/contracts/suspension.d.ts.map +1 -0
  59. package/dist/contracts/suspension.js +1 -0
  60. package/dist/contracts/transport.d.ts +26 -0
  61. package/dist/contracts/transport.d.ts.map +1 -0
  62. package/dist/contracts/transport.js +1 -0
  63. package/dist/core/CrossReferenceValidator.d.ts +18 -0
  64. package/dist/core/CrossReferenceValidator.d.ts.map +1 -0
  65. package/dist/core/CrossReferenceValidator.js +125 -0
  66. package/dist/core/CrossReferenceValidator.js.map +1 -0
  67. package/dist/core/HistoryManager.d.ts +215 -0
  68. package/dist/core/HistoryManager.d.ts.map +1 -0
  69. package/dist/core/HistoryManager.js +594 -0
  70. package/dist/core/HistoryManager.js.map +1 -0
  71. package/dist/core/IHistoryManager.d.ts +163 -0
  72. package/dist/core/IHistoryManager.d.ts.map +1 -0
  73. package/dist/core/IHistoryManager.js +1 -0
  74. package/dist/core/IThoughtFormatter.d.ts +51 -0
  75. package/dist/core/IThoughtFormatter.d.ts.map +1 -0
  76. package/dist/core/IThoughtFormatter.js +1 -0
  77. package/dist/core/InputNormalizer.d.ts +140 -0
  78. package/dist/core/InputNormalizer.d.ts.map +1 -0
  79. package/dist/core/InputNormalizer.js +95 -0
  80. package/dist/core/InputNormalizer.js.map +1 -0
  81. package/dist/core/PersistenceBuffer.d.ts +204 -0
  82. package/dist/core/PersistenceBuffer.d.ts.map +1 -0
  83. package/dist/core/PersistenceBuffer.js +382 -0
  84. package/dist/core/PersistenceBuffer.js.map +1 -0
  85. package/dist/core/PersistenceBufferErrors.d.ts +22 -0
  86. package/dist/core/PersistenceBufferErrors.d.ts.map +1 -0
  87. package/dist/core/PersistenceBufferErrors.js +30 -0
  88. package/dist/core/PersistenceBufferErrors.js.map +1 -0
  89. package/dist/core/PersistenceRestore.d.ts +21 -0
  90. package/dist/core/PersistenceRestore.d.ts.map +1 -0
  91. package/dist/core/PersistenceRestore.js +87 -0
  92. package/dist/core/PersistenceRestore.js.map +1 -0
  93. package/dist/core/PersistenceWorkQueue.d.ts +155 -0
  94. package/dist/core/PersistenceWorkQueue.d.ts.map +1 -0
  95. package/dist/core/PersistenceWorkQueue.js +298 -0
  96. package/dist/core/PersistenceWorkQueue.js.map +1 -0
  97. package/dist/core/PersistenceWriter.d.ts +55 -0
  98. package/dist/core/PersistenceWriter.d.ts.map +1 -0
  99. package/dist/core/PersistenceWriter.js +112 -0
  100. package/dist/core/PersistenceWriter.js.map +1 -0
  101. package/dist/core/SessionErrors.d.ts +37 -0
  102. package/dist/core/SessionErrors.d.ts.map +1 -0
  103. package/dist/core/SessionErrors.js +50 -0
  104. package/dist/core/SessionErrors.js.map +1 -0
  105. package/dist/core/SessionLifecycleCoordinator.d.ts +74 -0
  106. package/dist/core/SessionLifecycleCoordinator.d.ts.map +1 -0
  107. package/dist/core/SessionLifecycleCoordinator.js +222 -0
  108. package/dist/core/SessionLifecycleCoordinator.js.map +1 -0
  109. package/dist/core/SessionLock.d.ts +59 -0
  110. package/dist/core/SessionLock.d.ts.map +1 -0
  111. package/dist/core/SessionLock.js +39 -0
  112. package/dist/core/SessionLock.js.map +1 -0
  113. package/dist/core/SessionManager.d.ts +62 -0
  114. package/dist/core/SessionManager.d.ts.map +1 -0
  115. package/dist/core/SessionManager.js +75 -0
  116. package/dist/core/SessionManager.js.map +1 -0
  117. package/dist/core/SessionResetCoordinator.d.ts +37 -0
  118. package/dist/core/SessionResetCoordinator.d.ts.map +1 -0
  119. package/dist/core/SessionResetCoordinator.js +80 -0
  120. package/dist/core/SessionResetCoordinator.js.map +1 -0
  121. package/dist/core/ThoughtEvaluator.d.ts +48 -0
  122. package/dist/core/ThoughtEvaluator.d.ts.map +1 -0
  123. package/dist/core/ThoughtEvaluator.js +85 -0
  124. package/dist/core/ThoughtEvaluator.js.map +1 -0
  125. package/dist/core/ThoughtFormatter.d.ts +134 -0
  126. package/dist/core/ThoughtFormatter.d.ts.map +1 -0
  127. package/dist/core/ThoughtFormatter.js +118 -0
  128. package/dist/core/ThoughtFormatter.js.map +1 -0
  129. package/dist/core/ThoughtProcessor.d.ts +259 -0
  130. package/dist/core/ThoughtProcessor.d.ts.map +1 -0
  131. package/dist/core/ThoughtProcessor.js +451 -0
  132. package/dist/core/ThoughtProcessor.js.map +1 -0
  133. package/dist/core/ThoughtReferenceIndex.d.ts +23 -0
  134. package/dist/core/ThoughtReferenceIndex.d.ts.map +1 -0
  135. package/dist/core/ThoughtReferenceIndex.js +66 -0
  136. package/dist/core/ThoughtReferenceIndex.js.map +1 -0
  137. package/dist/core/VerificationOutcomeAdmission.d.ts +15 -0
  138. package/dist/core/VerificationOutcomeAdmission.d.ts.map +1 -0
  139. package/dist/core/VerificationOutcomeAdmission.js +28 -0
  140. package/dist/core/VerificationOutcomeAdmission.js.map +1 -0
  141. package/dist/core/compression/CompressionService.d.ts +76 -0
  142. package/dist/core/compression/CompressionService.d.ts.map +1 -0
  143. package/dist/core/compression/CompressionService.js +160 -0
  144. package/dist/core/compression/CompressionService.js.map +1 -0
  145. package/dist/core/compression/DehydrationPolicy.d.ts +75 -0
  146. package/dist/core/compression/DehydrationPolicy.d.ts.map +1 -0
  147. package/dist/core/compression/DehydrationPolicy.js +45 -0
  148. package/dist/core/compression/DehydrationPolicy.js.map +1 -0
  149. package/dist/core/compression/InMemorySummaryStore.d.ts +132 -0
  150. package/dist/core/compression/InMemorySummaryStore.d.ts.map +1 -0
  151. package/dist/core/compression/InMemorySummaryStore.js +69 -0
  152. package/dist/core/compression/InMemorySummaryStore.js.map +1 -0
  153. package/dist/core/compression/Summary.d.ts +74 -0
  154. package/dist/core/compression/Summary.d.ts.map +1 -0
  155. package/dist/core/compression/Summary.js +16 -0
  156. package/dist/core/compression/Summary.js.map +1 -0
  157. package/dist/core/evaluator/Aggregator.d.ts +40 -0
  158. package/dist/core/evaluator/Aggregator.d.ts.map +1 -0
  159. package/dist/core/evaluator/Aggregator.js +36 -0
  160. package/dist/core/evaluator/Aggregator.js.map +1 -0
  161. package/dist/core/evaluator/Calibrator.d.ts +52 -0
  162. package/dist/core/evaluator/Calibrator.d.ts.map +1 -0
  163. package/dist/core/evaluator/Calibrator.js +135 -0
  164. package/dist/core/evaluator/Calibrator.js.map +1 -0
  165. package/dist/core/evaluator/PatternDetector.d.ts +69 -0
  166. package/dist/core/evaluator/PatternDetector.d.ts.map +1 -0
  167. package/dist/core/evaluator/PatternDetector.js +192 -0
  168. package/dist/core/evaluator/PatternDetector.js.map +1 -0
  169. package/dist/core/evaluator/SignalComputer.d.ts +116 -0
  170. package/dist/core/evaluator/SignalComputer.d.ts.map +1 -0
  171. package/dist/core/evaluator/SignalComputer.js +110 -0
  172. package/dist/core/evaluator/SignalComputer.js.map +1 -0
  173. package/dist/core/evaluator/calibration-math.d.ts +39 -0
  174. package/dist/core/evaluator/calibration-math.d.ts.map +1 -0
  175. package/dist/core/evaluator/calibration-math.js +42 -0
  176. package/dist/core/evaluator/calibration-math.js.map +1 -0
  177. package/dist/core/evaluator/internals.d.ts +36 -0
  178. package/dist/core/evaluator/internals.d.ts.map +1 -0
  179. package/dist/core/evaluator/internals.js +43 -0
  180. package/dist/core/evaluator/internals.js.map +1 -0
  181. package/dist/core/graph/Edge.d.ts +58 -0
  182. package/dist/core/graph/Edge.d.ts.map +1 -0
  183. package/dist/core/graph/Edge.js +1 -0
  184. package/dist/core/graph/EdgeEmitter.d.ts +68 -0
  185. package/dist/core/graph/EdgeEmitter.d.ts.map +1 -0
  186. package/dist/core/graph/EdgeEmitter.js +118 -0
  187. package/dist/core/graph/EdgeEmitter.js.map +1 -0
  188. package/dist/core/graph/EdgeStore.d.ts +116 -0
  189. package/dist/core/graph/EdgeStore.d.ts.map +1 -0
  190. package/dist/core/graph/EdgeStore.js +107 -0
  191. package/dist/core/graph/EdgeStore.js.map +1 -0
  192. package/dist/core/graph/GraphView.d.ts +157 -0
  193. package/dist/core/graph/GraphView.d.ts.map +1 -0
  194. package/dist/core/graph/GraphView.js +149 -0
  195. package/dist/core/graph/GraphView.js.map +1 -0
  196. package/dist/core/ids.d.ts +33 -0
  197. package/dist/core/ids.d.ts.map +1 -0
  198. package/dist/core/ids.js +11 -0
  199. package/dist/core/ids.js.map +1 -0
  200. package/dist/core/reasoning/OutcomeRecorder.d.ts +88 -0
  201. package/dist/core/reasoning/OutcomeRecorder.d.ts.map +1 -0
  202. package/dist/core/reasoning/OutcomeRecorder.js +51 -0
  203. package/dist/core/reasoning/OutcomeRecorder.js.map +1 -0
  204. package/dist/core/reasoning/strategies/SequentialStrategy.d.ts +54 -0
  205. package/dist/core/reasoning/strategies/SequentialStrategy.d.ts.map +1 -0
  206. package/dist/core/reasoning/strategies/SequentialStrategy.js +22 -0
  207. package/dist/core/reasoning/strategies/SequentialStrategy.js.map +1 -0
  208. package/dist/core/reasoning/strategies/StrategyFactory.d.ts +25 -0
  209. package/dist/core/reasoning/strategies/StrategyFactory.d.ts.map +1 -0
  210. package/dist/core/reasoning/strategies/StrategyFactory.js +16 -0
  211. package/dist/core/reasoning/strategies/StrategyFactory.js.map +1 -0
  212. package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.d.ts +58 -0
  213. package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.d.ts.map +1 -0
  214. package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.js +103 -0
  215. package/dist/core/reasoning/strategies/TreeOfThoughtStrategy.js.map +1 -0
  216. package/dist/core/reasoning/strategies/plateau.d.ts +18 -0
  217. package/dist/core/reasoning/strategies/plateau.d.ts.map +1 -0
  218. package/dist/core/reasoning/strategies/plateau.js +12 -0
  219. package/dist/core/reasoning/strategies/plateau.js.map +1 -0
  220. package/dist/core/reasoning/strategies/totScoring.d.ts +91 -0
  221. package/dist/core/reasoning/strategies/totScoring.d.ts.map +1 -0
  222. package/dist/core/reasoning/strategies/totScoring.js +88 -0
  223. package/dist/core/reasoning/strategies/totScoring.js.map +1 -0
  224. package/dist/core/reasoning.d.ts +179 -0
  225. package/dist/core/reasoning.d.ts.map +1 -0
  226. package/dist/core/reasoning.js +1 -0
  227. package/dist/core/step.d.ts +50 -0
  228. package/dist/core/step.d.ts.map +1 -0
  229. package/dist/core/step.js +1 -0
  230. package/dist/core/thought.d.ts +113 -0
  231. package/dist/core/thought.d.ts.map +1 -0
  232. package/dist/core/thought.js +1 -0
  233. package/dist/core/tools/InMemorySuspensionStore.d.ts +66 -0
  234. package/dist/core/tools/InMemorySuspensionStore.d.ts.map +1 -0
  235. package/dist/core/tools/InMemorySuspensionStore.js +121 -0
  236. package/dist/core/tools/InMemorySuspensionStore.js.map +1 -0
  237. package/dist/di/Container.d.ts +253 -0
  238. package/dist/di/Container.d.ts.map +1 -0
  239. package/dist/di/Container.js +111 -0
  240. package/dist/di/Container.js.map +1 -0
  241. package/dist/di/ServiceRegistry.d.ts +50 -0
  242. package/dist/di/ServiceRegistry.d.ts.map +1 -0
  243. package/dist/di/ServiceRegistry.js +1 -0
  244. package/dist/errors.d.ts +663 -0
  245. package/dist/errors.d.ts.map +1 -0
  246. package/dist/errors.js +282 -0
  247. package/dist/errors.js.map +1 -0
  248. package/dist/health/HealthChecker.d.ts +73 -0
  249. package/dist/health/HealthChecker.d.ts.map +1 -0
  250. package/dist/health/HealthChecker.js +70 -0
  251. package/dist/health/HealthChecker.js.map +1 -0
  252. package/dist/lib.d.ts +273 -0
  253. package/dist/lib.d.ts.map +1 -0
  254. package/dist/lib.js +409 -0
  255. package/dist/lib.js.map +1 -0
  256. package/dist/logger/NullLogger.d.ts +154 -0
  257. package/dist/logger/NullLogger.d.ts.map +1 -0
  258. package/dist/logger/NullLogger.js +24 -0
  259. package/dist/logger/NullLogger.js.map +1 -0
  260. package/dist/logger/StructuredLogger.d.ts +327 -0
  261. package/dist/logger/StructuredLogger.d.ts.map +1 -0
  262. package/dist/logger/StructuredLogger.js +72 -0
  263. package/dist/logger/StructuredLogger.js.map +1 -0
  264. package/dist/metrics/metrics.impl.d.ts +252 -0
  265. package/dist/metrics/metrics.impl.d.ts.map +1 -0
  266. package/dist/metrics/metrics.impl.js +197 -0
  267. package/dist/metrics/metrics.impl.js.map +1 -0
  268. package/dist/persistence/FileLegacyImport.d.ts +2 -0
  269. package/dist/persistence/FileLegacyImport.d.ts.map +1 -0
  270. package/dist/persistence/FileLegacyImport.js +183 -0
  271. package/dist/persistence/FileLegacyImport.js.map +1 -0
  272. package/dist/persistence/FilePersistence.d.ts +53 -0
  273. package/dist/persistence/FilePersistence.d.ts.map +1 -0
  274. package/dist/persistence/FilePersistence.js +312 -0
  275. package/dist/persistence/FilePersistence.js.map +1 -0
  276. package/dist/persistence/FileSnapshotTypes.d.ts +29 -0
  277. package/dist/persistence/FileSnapshotTypes.d.ts.map +1 -0
  278. package/dist/persistence/FileSnapshotTypes.js +1 -0
  279. package/dist/persistence/FileSnapshotV2.d.ts +377 -0
  280. package/dist/persistence/FileSnapshotV2.d.ts.map +1 -0
  281. package/dist/persistence/FileSnapshotV2.js +124 -0
  282. package/dist/persistence/FileSnapshotV2.js.map +1 -0
  283. package/dist/persistence/FileSnapshotValidation.d.ts +15 -0
  284. package/dist/persistence/FileSnapshotValidation.d.ts.map +1 -0
  285. package/dist/persistence/FileSnapshotValidation.js +64 -0
  286. package/dist/persistence/FileSnapshotValidation.js.map +1 -0
  287. package/dist/persistence/FileWriter.d.ts +30 -0
  288. package/dist/persistence/FileWriter.d.ts.map +1 -0
  289. package/dist/persistence/FileWriter.js +155 -0
  290. package/dist/persistence/FileWriter.js.map +1 -0
  291. package/dist/persistence/MemoryPersistence.d.ts +45 -0
  292. package/dist/persistence/MemoryPersistence.d.ts.map +1 -0
  293. package/dist/persistence/MemoryPersistence.js +180 -0
  294. package/dist/persistence/MemoryPersistence.js.map +1 -0
  295. package/dist/persistence/PersistenceCodec.d.ts +7 -0
  296. package/dist/persistence/PersistenceCodec.d.ts.map +1 -0
  297. package/dist/persistence/PersistenceCodec.js +97 -0
  298. package/dist/persistence/PersistenceCodec.js.map +1 -0
  299. package/dist/persistence/PersistenceErrors.d.ts +23 -0
  300. package/dist/persistence/PersistenceErrors.d.ts.map +1 -0
  301. package/dist/persistence/PersistenceErrors.js +26 -0
  302. package/dist/persistence/PersistenceErrors.js.map +1 -0
  303. package/dist/persistence/PersistenceFactory.d.ts +21 -0
  304. package/dist/persistence/PersistenceFactory.d.ts.map +1 -0
  305. package/dist/persistence/PersistenceFactory.js +28 -0
  306. package/dist/persistence/PersistenceFactory.js.map +1 -0
  307. package/dist/persistence/PersistenceScope.d.ts +42 -0
  308. package/dist/persistence/PersistenceScope.d.ts.map +1 -0
  309. package/dist/persistence/PersistenceScope.js +93 -0
  310. package/dist/persistence/PersistenceScope.js.map +1 -0
  311. package/dist/persistence/SessionScopedPersistence.d.ts +4 -0
  312. package/dist/persistence/SessionScopedPersistence.d.ts.map +1 -0
  313. package/dist/persistence/SessionScopedPersistence.js +9 -0
  314. package/dist/persistence/SessionScopedPersistence.js.map +1 -0
  315. package/dist/persistence/SqliteDriver.d.ts +22 -0
  316. package/dist/persistence/SqliteDriver.d.ts.map +1 -0
  317. package/dist/persistence/SqliteDriver.js +29 -0
  318. package/dist/persistence/SqliteDriver.js.map +1 -0
  319. package/dist/persistence/SqliteLegacyImport.d.ts +14 -0
  320. package/dist/persistence/SqliteLegacyImport.d.ts.map +1 -0
  321. package/dist/persistence/SqliteLegacyImport.js +136 -0
  322. package/dist/persistence/SqliteLegacyImport.js.map +1 -0
  323. package/dist/persistence/SqliteLegacySchema.d.ts +15 -0
  324. package/dist/persistence/SqliteLegacySchema.d.ts.map +1 -0
  325. package/dist/persistence/SqliteLegacySchema.js +72 -0
  326. package/dist/persistence/SqliteLegacySchema.js.map +1 -0
  327. package/dist/persistence/SqlitePayload.d.ts +11 -0
  328. package/dist/persistence/SqlitePayload.d.ts.map +1 -0
  329. package/dist/persistence/SqlitePayload.js +86 -0
  330. package/dist/persistence/SqlitePayload.js.map +1 -0
  331. package/dist/persistence/SqlitePersistence.d.ts +49 -0
  332. package/dist/persistence/SqlitePersistence.d.ts.map +1 -0
  333. package/dist/persistence/SqlitePersistence.js +248 -0
  334. package/dist/persistence/SqlitePersistence.js.map +1 -0
  335. package/dist/persistence/SqliteSchemaV2.d.ts +14 -0
  336. package/dist/persistence/SqliteSchemaV2.d.ts.map +1 -0
  337. package/dist/persistence/SqliteSchemaV2.js +129 -0
  338. package/dist/persistence/SqliteSchemaV2.js.map +1 -0
  339. package/dist/persistence/SqliteSnapshotWriter.d.ts +17 -0
  340. package/dist/persistence/SqliteSnapshotWriter.d.ts.map +1 -0
  341. package/dist/persistence/SqliteSnapshotWriter.js +30 -0
  342. package/dist/persistence/SqliteSnapshotWriter.js.map +1 -0
  343. package/dist/pool/ConnectionPool.d.ts +203 -0
  344. package/dist/pool/ConnectionPool.d.ts.map +1 -0
  345. package/dist/pool/ConnectionPool.js +303 -0
  346. package/dist/pool/ConnectionPool.js.map +1 -0
  347. package/dist/pool/IConnectionPool.d.ts +143 -0
  348. package/dist/pool/IConnectionPool.d.ts.map +1 -0
  349. package/dist/pool/IConnectionPool.js +1 -0
  350. package/dist/pool/PoolErrors.d.ts +11 -0
  351. package/dist/pool/PoolErrors.d.ts.map +1 -0
  352. package/dist/pool/PoolErrors.js +16 -0
  353. package/dist/pool/PoolErrors.js.map +1 -0
  354. package/dist/registry/BaseRegistry.d.ts +219 -0
  355. package/dist/registry/BaseRegistry.d.ts.map +1 -0
  356. package/dist/registry/BaseRegistry.js +215 -0
  357. package/dist/registry/BaseRegistry.js.map +1 -0
  358. package/dist/registry/SkillRegistry.d.ts +67 -0
  359. package/dist/registry/SkillRegistry.d.ts.map +1 -0
  360. package/dist/registry/SkillRegistry.js +87 -0
  361. package/dist/registry/SkillRegistry.js.map +1 -0
  362. package/dist/registry/ToolRegistry.d.ts +70 -0
  363. package/dist/registry/ToolRegistry.d.ts.map +1 -0
  364. package/dist/registry/ToolRegistry.js +96 -0
  365. package/dist/registry/ToolRegistry.js.map +1 -0
  366. package/dist/sanitize.d.ts +164 -0
  367. package/dist/sanitize.d.ts.map +1 -0
  368. package/dist/sanitize.js +100 -0
  369. package/dist/sanitize.js.map +1 -0
  370. package/dist/schema.d.ts +562 -0
  371. package/dist/schema.d.ts.map +1 -0
  372. package/dist/schema.js +251 -0
  373. package/dist/schema.js.map +1 -0
  374. package/dist/transport/BaseTransport.d.ts +166 -0
  375. package/dist/transport/BaseTransport.d.ts.map +1 -0
  376. package/dist/transport/BaseTransport.js +199 -0
  377. package/dist/transport/BaseTransport.js.map +1 -0
  378. package/dist/transport/HttpHelpers.d.ts +53 -0
  379. package/dist/transport/HttpHelpers.d.ts.map +1 -0
  380. package/dist/transport/HttpHelpers.js +44 -0
  381. package/dist/transport/HttpHelpers.js.map +1 -0
  382. package/dist/transport/HttpRequestLifecycle.d.ts +37 -0
  383. package/dist/transport/HttpRequestLifecycle.d.ts.map +1 -0
  384. package/dist/transport/HttpRequestLifecycle.js +87 -0
  385. package/dist/transport/HttpRequestLifecycle.js.map +1 -0
  386. package/dist/transport/HttpTransport.d.ts +140 -0
  387. package/dist/transport/HttpTransport.d.ts.map +1 -0
  388. package/dist/transport/HttpTransport.js +245 -0
  389. package/dist/transport/HttpTransport.js.map +1 -0
  390. package/dist/transport/SseTransport.d.ts +149 -0
  391. package/dist/transport/SseTransport.d.ts.map +1 -0
  392. package/dist/transport/SseTransport.js +470 -0
  393. package/dist/transport/SseTransport.js.map +1 -0
  394. package/dist/transport/StreamableHttpTransport.d.ts +225 -0
  395. package/dist/transport/StreamableHttpTransport.d.ts.map +1 -0
  396. package/dist/transport/StreamableHttpTransport.js +449 -0
  397. package/dist/transport/StreamableHttpTransport.js.map +1 -0
  398. package/dist/types/disposable.d.ts +22 -0
  399. package/dist/types/disposable.d.ts.map +1 -0
  400. package/dist/types/disposable.js +1 -0
  401. package/dist/types/server-config.d.ts +32 -0
  402. package/dist/types/server-config.d.ts.map +1 -0
  403. package/dist/types/server-config.js +1 -0
  404. package/dist/types/skill.d.ts +74 -0
  405. package/dist/types/skill.d.ts.map +1 -0
  406. package/dist/types/skill.js +1 -0
  407. package/dist/types/tool.d.ts +78 -0
  408. package/dist/types/tool.d.ts.map +1 -0
  409. package/dist/types/tool.js +1 -0
  410. package/dist/utils.d.ts +27 -0
  411. package/dist/utils.d.ts.map +1 -0
  412. package/dist/utils.js +6 -0
  413. package/dist/utils.js.map +1 -0
  414. package/dist/watchers/SkillWatcher.d.ts +25 -0
  415. package/dist/watchers/SkillWatcher.d.ts.map +1 -0
  416. package/dist/watchers/SkillWatcher.js +96 -0
  417. package/dist/watchers/SkillWatcher.js.map +1 -0
  418. package/dist/watchers/ToolWatcher.d.ts +24 -0
  419. package/dist/watchers/ToolWatcher.d.ts.map +1 -0
  420. package/dist/watchers/ToolWatcher.js +92 -0
  421. package/dist/watchers/ToolWatcher.js.map +1 -0
  422. package/package.json +106 -0
@@ -0,0 +1,136 @@
1
+ import { link as promises_link, lstat, mkdir, mkdtemp, rm } from "node:fs/promises";
2
+ import { basename, dirname, join } from "node:path";
3
+ import { GLOBAL_SESSION_ID } from "../contracts/ids.js";
4
+ import { PersistenceCompatibilityError, PersistenceCorruptionError, PersistenceLegacyAmbiguityError } from "../errors.js";
5
+ import { parseFileSnapshotV2, serializeFileSnapshotV2 } from "./FileSnapshotV2.js";
6
+ import { isFileNotFound } from "./FileWriter.js";
7
+ import { validateSqliteV1Schema } from "./SqliteLegacySchema.js";
8
+ import { decodeEdgeRow, decodeSummaryRow, decodeThoughtRow, parseSqliteJson, stringField } from "./SqlitePayload.js";
9
+ import { parsePersistenceBranchId } from "./PersistenceScope.js";
10
+ import { writeSqliteSnapshot } from "./SqliteSnapshotWriter.js";
11
+ async function pathIsAbsent(path) {
12
+ try {
13
+ await lstat(path);
14
+ return false;
15
+ } catch (error) {
16
+ if (isFileNotFound(error)) return true;
17
+ throw error;
18
+ }
19
+ }
20
+ function groupBySession(values, sessionOf) {
21
+ const grouped = new Map();
22
+ for (const value of values){
23
+ const sessionId = sessionOf(value);
24
+ const sessionValues = grouped.get(sessionId) ?? [];
25
+ sessionValues.push(value);
26
+ grouped.set(sessionId, sessionValues);
27
+ }
28
+ return grouped;
29
+ }
30
+ function loadLegacyThoughts(database, sourcePath) {
31
+ const thoughts = database.prepare('SELECT data FROM thoughts ORDER BY id ASC').all().map((row, index)=>decodeThoughtRow(row, `${sourcePath}:thoughts:${index}`));
32
+ return [
33
+ ...groupBySession(thoughts, (thought)=>thought.session_id ?? GLOBAL_SESSION_ID)
34
+ ].map(([sessionId, sessionThoughts])=>({
35
+ sessionId,
36
+ thoughts: sessionThoughts
37
+ }));
38
+ }
39
+ function decodeLegacyBranch(row, sourcePath) {
40
+ const branchId = parsePersistenceBranchId(stringField(row, 'branch_id', sourcePath), sourcePath);
41
+ const data = parseSqliteJson(stringField(row, 'data', sourcePath), sourcePath);
42
+ if (!Array.isArray(data)) throw new PersistenceCorruptionError(sourcePath, new TypeError('branch data is not an array'));
43
+ const thoughts = data.map((value, index)=>decodeThoughtRow({
44
+ data: JSON.stringify(value)
45
+ }, `${sourcePath}:thought:${index}`));
46
+ if (0 === thoughts.length) throw new PersistenceLegacyAmbiguityError(sourcePath, 'empty branch has no inferable session');
47
+ const sessions = new Set(thoughts.map((thought)=>thought.session_id ?? GLOBAL_SESSION_ID));
48
+ if (1 !== sessions.size) throw new PersistenceLegacyAmbiguityError(sourcePath, 'branch thoughts resolve to multiple sessions');
49
+ const sessionId = sessions.values().next().value;
50
+ if (void 0 === sessionId) throw new PersistenceLegacyAmbiguityError(sourcePath, 'branch session is absent');
51
+ return {
52
+ sessionId,
53
+ branchId,
54
+ thoughts
55
+ };
56
+ }
57
+ function loadLegacyBranches(database, sourcePath, hasBranches) {
58
+ if (!hasBranches) return [];
59
+ return database.prepare('SELECT branch_id, data FROM branches ORDER BY branch_id ASC').all().map((row, index)=>decodeLegacyBranch(row, `${sourcePath}:branches:${index}`));
60
+ }
61
+ function loadLegacyEdges(database, sourcePath) {
62
+ const edges = database.prepare('SELECT id, session_id, from_id, to_id, kind, created_at, metadata FROM edges ORDER BY created_at ASC, id ASC').all().map((row, index)=>decodeEdgeRow(row, `${sourcePath}:edges:${index}`));
63
+ return [
64
+ ...groupBySession(edges, (edge)=>edge.sessionId)
65
+ ].map(([sessionId, sessionEdges])=>({
66
+ sessionId,
67
+ edges: sessionEdges
68
+ }));
69
+ }
70
+ function loadLegacySummaries(database, sourcePath) {
71
+ const summaries = database.prepare('SELECT id, session_id, branch_id, root_thought_id, covered_ids, covered_range_start, covered_range_end, topics, aggregate_confidence, created_at, meta FROM summaries ORDER BY created_at ASC, id ASC').all().map((row, index)=>decodeSummaryRow(row, `${sourcePath}:summaries:${index}`));
72
+ return [
73
+ ...groupBySession(summaries, (summary)=>summary.sessionId)
74
+ ].map(([sessionId, sessionSummaries])=>({
75
+ sessionId,
76
+ summaries: sessionSummaries
77
+ }));
78
+ }
79
+ function loadLegacySnapshot(database, sourcePath) {
80
+ const hasBranches = validateSqliteV1Schema(database, sourcePath);
81
+ const snapshot = {
82
+ version: 2,
83
+ thoughts: loadLegacyThoughts(database, sourcePath),
84
+ branches: loadLegacyBranches(database, sourcePath, hasBranches),
85
+ edges: loadLegacyEdges(database, sourcePath),
86
+ summaries: loadLegacySummaries(database, sourcePath)
87
+ };
88
+ return parseFileSnapshotV2(serializeFileSnapshotV2(snapshot, sourcePath), sourcePath);
89
+ }
90
+ async function importWithDriver(sourceDbPath, destinationDbPath, Database) {
91
+ if (!await pathIsAbsent(destinationDbPath)) throw new PersistenceCompatibilityError(destinationDbPath, 'destination must be absent');
92
+ const source = new Database(sourceDbPath, {
93
+ readonly: true,
94
+ fileMustExist: true
95
+ });
96
+ let snapshot;
97
+ try {
98
+ snapshot = loadLegacySnapshot(source, sourceDbPath);
99
+ } finally{
100
+ source.close();
101
+ }
102
+ await mkdir(dirname(destinationDbPath), {
103
+ recursive: true
104
+ });
105
+ const stagingDir = await mkdtemp(join(dirname(destinationDbPath), `.${basename(destinationDbPath)}.import-`));
106
+ const stagedDbPath = join(stagingDir, basename(destinationDbPath));
107
+ let destination;
108
+ try {
109
+ destination = new Database(stagedDbPath);
110
+ writeSqliteSnapshot(destination, snapshot, stagedDbPath);
111
+ destination.close();
112
+ destination = void 0;
113
+ await promises_link(stagedDbPath, destinationDbPath);
114
+ } catch (error) {
115
+ destination?.close();
116
+ throw error;
117
+ } finally{
118
+ await rm(stagingDir, {
119
+ recursive: true,
120
+ force: true
121
+ });
122
+ }
123
+ }
124
+ async function importLegacySqliteV1(sourceDbPath, destinationDbPath) {
125
+ let Database;
126
+ try {
127
+ const module = await import("better-sqlite3");
128
+ Database = module.default;
129
+ } catch (error) {
130
+ throw new PersistenceCompatibilityError(sourceDbPath, "SQLite import requires the optional 'better-sqlite3' package", error);
131
+ }
132
+ await importWithDriver(sourceDbPath, destinationDbPath, Database);
133
+ }
134
+ export { importLegacySqliteV1 };
135
+
136
+ //# sourceMappingURL=SqliteLegacyImport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistence/SqliteLegacyImport.js","sources":["../../src/persistence/SqliteLegacyImport.ts"],"sourcesContent":["import { lstat, link, mkdir, mkdtemp, rm } from 'node:fs/promises';\nimport { basename, dirname, join } from 'node:path';\nimport { GLOBAL_SESSION_ID, type SessionId } from '../contracts/ids.js';\nimport {\n\tPersistenceCompatibilityError,\n\tPersistenceCorruptionError,\n\tPersistenceLegacyAmbiguityError,\n} from '../errors.js';\nimport { parseFileSnapshotV2, serializeFileSnapshotV2 } from './FileSnapshotV2.js';\nimport type {\n\tBranchRecordV2,\n\tEdgeSessionV2,\n\tFileSnapshotV2,\n\tSummarySessionV2,\n\tThoughtSessionV2,\n} from './FileSnapshotTypes.js';\nimport { isFileNotFound } from './FileWriter.js';\nimport type { SqliteDatabase, SqliteDatabaseConstructor } from './SqliteDriver.js';\nimport { validateSqliteV1Schema } from './SqliteLegacySchema.js';\nimport {\n\tdecodeEdgeRow,\n\tdecodeSummaryRow,\n\tdecodeThoughtRow,\n\tparseSqliteJson,\n\tstringField,\n} from './SqlitePayload.js';\nimport { parsePersistenceBranchId } from './PersistenceScope.js';\nimport { writeSqliteSnapshot } from './SqliteSnapshotWriter.js';\n\nasync function pathIsAbsent(path: string): Promise<boolean> {\n\ttry {\n\t\tawait lstat(path);\n\t\treturn false;\n\t} catch (error) {\n\t\tif (isFileNotFound(error)) return true;\n\t\tthrow error;\n\t}\n}\n\nfunction groupBySession<T>(\n\tvalues: readonly T[],\n\tsessionOf: (value: T) => SessionId\n): Map<SessionId, T[]> {\n\tconst grouped = new Map<SessionId, T[]>();\n\tfor (const value of values) {\n\t\tconst sessionId = sessionOf(value);\n\t\tconst sessionValues = grouped.get(sessionId) ?? [];\n\t\tsessionValues.push(value);\n\t\tgrouped.set(sessionId, sessionValues);\n\t}\n\treturn grouped;\n}\n\nfunction loadLegacyThoughts(database: SqliteDatabase, sourcePath: string): ThoughtSessionV2[] {\n\tconst thoughts = database\n\t\t.prepare('SELECT data FROM thoughts ORDER BY id ASC')\n\t\t.all()\n\t\t.map((row, index) => decodeThoughtRow(row, `${sourcePath}:thoughts:${index}`));\n\treturn [...groupBySession(thoughts, (thought) => thought.session_id ?? GLOBAL_SESSION_ID)].map(\n\t\t([sessionId, sessionThoughts]) => ({ sessionId, thoughts: sessionThoughts })\n\t);\n}\n\nfunction decodeLegacyBranch(row: unknown, sourcePath: string): BranchRecordV2 {\n\tconst branchId = parsePersistenceBranchId(stringField(row, 'branch_id', sourcePath), sourcePath);\n\tconst data = parseSqliteJson(stringField(row, 'data', sourcePath), sourcePath);\n\tif (!Array.isArray(data)) {\n\t\tthrow new PersistenceCorruptionError(sourcePath, new TypeError('branch data is not an array'));\n\t}\n\tconst thoughts = data.map((value, index) =>\n\t\tdecodeThoughtRow({ data: JSON.stringify(value) }, `${sourcePath}:thought:${index}`)\n\t);\n\tif (thoughts.length === 0) {\n\t\tthrow new PersistenceLegacyAmbiguityError(sourcePath, 'empty branch has no inferable session');\n\t}\n\tconst sessions = new Set(thoughts.map((thought) => thought.session_id ?? GLOBAL_SESSION_ID));\n\tif (sessions.size !== 1) {\n\t\tthrow new PersistenceLegacyAmbiguityError(\n\t\t\tsourcePath,\n\t\t\t'branch thoughts resolve to multiple sessions'\n\t\t);\n\t}\n\tconst sessionId = sessions.values().next().value;\n\tif (sessionId === undefined) {\n\t\tthrow new PersistenceLegacyAmbiguityError(sourcePath, 'branch session is absent');\n\t}\n\treturn { sessionId, branchId, thoughts };\n}\n\nfunction loadLegacyBranches(\n\tdatabase: SqliteDatabase,\n\tsourcePath: string,\n\thasBranches: boolean\n): BranchRecordV2[] {\n\tif (!hasBranches) return [];\n\treturn database\n\t\t.prepare('SELECT branch_id, data FROM branches ORDER BY branch_id ASC')\n\t\t.all()\n\t\t.map((row, index) => decodeLegacyBranch(row, `${sourcePath}:branches:${index}`));\n}\n\nfunction loadLegacyEdges(database: SqliteDatabase, sourcePath: string): EdgeSessionV2[] {\n\tconst edges = database\n\t\t.prepare(\n\t\t\t'SELECT id, session_id, from_id, to_id, kind, created_at, metadata FROM edges ORDER BY created_at ASC, id ASC'\n\t\t)\n\t\t.all()\n\t\t.map((row, index) => decodeEdgeRow(row, `${sourcePath}:edges:${index}`));\n\treturn [...groupBySession(edges, (edge) => edge.sessionId)].map(([sessionId, sessionEdges]) => ({\n\t\tsessionId,\n\t\tedges: sessionEdges,\n\t}));\n}\n\nfunction loadLegacySummaries(database: SqliteDatabase, sourcePath: string): SummarySessionV2[] {\n\tconst summaries = database\n\t\t.prepare(\n\t\t\t'SELECT id, session_id, branch_id, root_thought_id, covered_ids, covered_range_start, covered_range_end, topics, aggregate_confidence, created_at, meta FROM summaries ORDER BY created_at ASC, id ASC'\n\t\t)\n\t\t.all()\n\t\t.map((row, index) => decodeSummaryRow(row, `${sourcePath}:summaries:${index}`));\n\treturn [...groupBySession(summaries, (summary) => summary.sessionId)].map(\n\t\t([sessionId, sessionSummaries]) => ({ sessionId, summaries: sessionSummaries })\n\t);\n}\n\nfunction loadLegacySnapshot(database: SqliteDatabase, sourcePath: string): FileSnapshotV2 {\n\tconst hasBranches = validateSqliteV1Schema(database, sourcePath);\n\tconst snapshot: FileSnapshotV2 = {\n\t\tversion: 2,\n\t\tthoughts: loadLegacyThoughts(database, sourcePath),\n\t\tbranches: loadLegacyBranches(database, sourcePath, hasBranches),\n\t\tedges: loadLegacyEdges(database, sourcePath),\n\t\tsummaries: loadLegacySummaries(database, sourcePath),\n\t};\n\treturn parseFileSnapshotV2(serializeFileSnapshotV2(snapshot, sourcePath), sourcePath);\n}\n\nasync function importWithDriver(\n\tsourceDbPath: string,\n\tdestinationDbPath: string,\n\tDatabase: SqliteDatabaseConstructor\n): Promise<void> {\n\tif (!(await pathIsAbsent(destinationDbPath))) {\n\t\tthrow new PersistenceCompatibilityError(destinationDbPath, 'destination must be absent');\n\t}\n\tconst source = new Database(sourceDbPath, { readonly: true, fileMustExist: true });\n\tlet snapshot: FileSnapshotV2;\n\ttry {\n\t\tsnapshot = loadLegacySnapshot(source, sourceDbPath);\n\t} finally {\n\t\tsource.close();\n\t}\n\tawait mkdir(dirname(destinationDbPath), { recursive: true });\n\tconst stagingDir = await mkdtemp(\n\t\tjoin(dirname(destinationDbPath), `.${basename(destinationDbPath)}.import-`)\n\t);\n\tconst stagedDbPath = join(stagingDir, basename(destinationDbPath));\n\tlet destination: SqliteDatabase | undefined;\n\ttry {\n\t\tdestination = new Database(stagedDbPath);\n\t\twriteSqliteSnapshot(destination, snapshot, stagedDbPath);\n\t\tdestination.close();\n\t\tdestination = undefined;\n\t\tawait link(stagedDbPath, destinationDbPath);\n\t} catch (error) {\n\t\tdestination?.close();\n\t\tthrow error;\n\t} finally {\n\t\tawait rm(stagingDir, { recursive: true, force: true });\n\t}\n}\n\n/**\n * Imports an immutable SQLite v1 database into a separately published SQLite v2 destination.\n *\n * @param sourceDbPath - Existing frozen v1 source database opened read-only.\n * @param destinationDbPath - Absent destination path atomically published after validation.\n * @returns A promise that resolves after the validated v2 database is published.\n *\n * @example\n * ```ts\n * await importLegacySqliteV1('fixtures/legacy.db', 'output/history.db');\n * ```\n */\nexport async function importLegacySqliteV1(\n\tsourceDbPath: string,\n\tdestinationDbPath: string\n): Promise<void> {\n\tlet Database: SqliteDatabaseConstructor;\n\ttry {\n\t\tconst module = await import('better-sqlite3');\n\t\tDatabase = module.default;\n\t} catch (error) {\n\t\tthrow new PersistenceCompatibilityError(\n\t\t\tsourceDbPath,\n\t\t\t\"SQLite import requires the optional 'better-sqlite3' package\",\n\t\t\terror\n\t\t);\n\t}\n\tawait importWithDriver(sourceDbPath, destinationDbPath, Database);\n}\n"],"names":["pathIsAbsent","path","lstat","error","isFileNotFound","groupBySession","values","sessionOf","grouped","Map","value","sessionId","sessionValues","loadLegacyThoughts","database","sourcePath","thoughts","row","index","decodeThoughtRow","thought","GLOBAL_SESSION_ID","sessionThoughts","decodeLegacyBranch","branchId","parsePersistenceBranchId","stringField","data","parseSqliteJson","Array","PersistenceCorruptionError","TypeError","JSON","PersistenceLegacyAmbiguityError","sessions","Set","undefined","loadLegacyBranches","hasBranches","loadLegacyEdges","edges","decodeEdgeRow","edge","sessionEdges","loadLegacySummaries","summaries","decodeSummaryRow","summary","sessionSummaries","loadLegacySnapshot","validateSqliteV1Schema","snapshot","parseFileSnapshotV2","serializeFileSnapshotV2","importWithDriver","sourceDbPath","destinationDbPath","Database","PersistenceCompatibilityError","source","mkdir","dirname","stagingDir","mkdtemp","join","basename","stagedDbPath","destination","writeSqliteSnapshot","link","rm","importLegacySqliteV1","module"],"mappings":";;;;;;;;;;AA6BA,eAAeA,aAAaC,IAAY;IACvC,IAAI;QACH,MAAMC,MAAMD;QACZ,OAAO;IACR,EAAE,OAAOE,OAAO;QACf,IAAIC,eAAeD,QAAQ,OAAO;QAClC,MAAMA;IACP;AACD;AAEA,SAASE,eACRC,MAAoB,EACpBC,SAAkC;IAElC,MAAMC,UAAU,IAAIC;IACpB,KAAK,MAAMC,SAASJ,OAAQ;QAC3B,MAAMK,YAAYJ,UAAUG;QAC5B,MAAME,gBAAgBJ,QAAQ,GAAG,CAACG,cAAc,EAAE;QAClDC,cAAc,IAAI,CAACF;QACnBF,QAAQ,GAAG,CAACG,WAAWC;IACxB;IACA,OAAOJ;AACR;AAEA,SAASK,mBAAmBC,QAAwB,EAAEC,UAAkB;IACvE,MAAMC,WAAWF,SACf,OAAO,CAAC,6CACR,GAAG,GACH,GAAG,CAAC,CAACG,KAAKC,QAAUC,iBAAiBF,KAAK,GAAGF,WAAW,UAAU,EAAEG,OAAO;IAC7E,OAAO;WAAIb,eAAeW,UAAU,CAACI,UAAYA,QAAQ,UAAU,IAAIC;KAAmB,CAAC,GAAG,CAC7F,CAAC,CAACV,WAAWW,gBAAgB,GAAM;YAAEX;YAAW,UAAUW;QAAgB;AAE5E;AAEA,SAASC,mBAAmBN,GAAY,EAAEF,UAAkB;IAC3D,MAAMS,WAAWC,yBAAyBC,YAAYT,KAAK,aAAaF,aAAaA;IACrF,MAAMY,OAAOC,gBAAgBF,YAAYT,KAAK,QAAQF,aAAaA;IACnE,IAAI,CAACc,MAAM,OAAO,CAACF,OAClB,MAAM,IAAIG,2B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OAAOrD,OAAO;QACfgE,aAAa;QACb,MAAMhE;IACP,SAAU;QACT,MAAMmE,GAAGR,YAAY;YAAE,WAAW;YAAM,OAAO;QAAK;IACrD;AACD;AAcO,eAAeS,qBACrBhB,YAAoB,EACpBC,iBAAyB;IAEzB,IAAIC;IACJ,IAAI;QACH,MAAMe,SAAS,MAAM,MAAM,CAAC;QAC5Bf,WAAWe,OAAO,OAAO;IAC1B,EAAE,OAAOrE,OAAO;QACf,MAAM,IAAIuD,8BACTH,cACA,gEACApD;IAEF;IACA,MAAMmD,iBAAiBC,cAAcC,mBAAmBC;AACzD"}
@@ -0,0 +1,15 @@
1
+ import type { SqliteDatabase } from './SqliteDriver.js';
2
+ /**
3
+ * Validates the frozen, unversioned SQLite v1 schema without mutating it.
4
+ *
5
+ * @param database - Read-only source database.
6
+ * @param sourcePath - Source name used by typed compatibility errors.
7
+ * @returns Whether the optional legacy branches table is present.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const hasBranches = validateSqliteV1Schema(database, 'legacy.db');
12
+ * ```
13
+ */
14
+ export declare function validateSqliteV1Schema(database: SqliteDatabase, sourcePath: string): boolean;
15
+ //# sourceMappingURL=SqliteLegacySchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqliteLegacySchema.d.ts","sourceRoot":"","sources":["../../src/persistence/SqliteLegacySchema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAoDxD;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAuB5F"}
@@ -0,0 +1,72 @@
1
+ import { PersistenceCompatibilityError } from "../errors.js";
2
+ const LEGACY_TABLES = new Map([
3
+ [
4
+ 'thoughts',
5
+ "CREATE TABLE thoughts (id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT NOT NULL, created_at INTEGER DEFAULT (strftime('%s', 'now')))"
6
+ ],
7
+ [
8
+ 'branches',
9
+ "CREATE TABLE branches (branch_id TEXT PRIMARY KEY, data TEXT NOT NULL, updated_at INTEGER DEFAULT (strftime('%s', 'now')))"
10
+ ],
11
+ [
12
+ 'edges',
13
+ 'CREATE TABLE edges (id TEXT PRIMARY KEY, session_id TEXT NOT NULL, from_id TEXT NOT NULL, to_id TEXT NOT NULL, kind TEXT NOT NULL, created_at INTEGER NOT NULL, metadata TEXT)'
14
+ ],
15
+ [
16
+ 'summaries',
17
+ 'CREATE TABLE summaries (id TEXT PRIMARY KEY, session_id TEXT NOT NULL, branch_id TEXT, root_thought_id TEXT NOT NULL, covered_ids TEXT NOT NULL, covered_range_start INTEGER NOT NULL, covered_range_end INTEGER NOT NULL, topics TEXT NOT NULL, aggregate_confidence REAL NOT NULL, created_at INTEGER NOT NULL, meta TEXT)'
18
+ ]
19
+ ]);
20
+ const LEGACY_INDEXES = new Map([
21
+ [
22
+ 'idx_thoughts_created_at',
23
+ 'CREATE INDEX idx_thoughts_created_at ON thoughts(created_at)'
24
+ ],
25
+ [
26
+ 'idx_edges_session',
27
+ 'CREATE INDEX idx_edges_session ON edges(session_id)'
28
+ ],
29
+ [
30
+ 'idx_edges_from',
31
+ 'CREATE INDEX idx_edges_from ON edges(session_id, from_id)'
32
+ ],
33
+ [
34
+ 'idx_edges_to',
35
+ 'CREATE INDEX idx_edges_to ON edges(session_id, to_id)'
36
+ ],
37
+ [
38
+ 'idx_summaries_session',
39
+ 'CREATE INDEX idx_summaries_session ON summaries(session_id)'
40
+ ]
41
+ ]);
42
+ function normalizeSql(sql) {
43
+ return sql.replace(/\s+/g, ' ').replace(/;$/, '').trim().toLowerCase();
44
+ }
45
+ function readObject(value, sourcePath) {
46
+ if ('object' != typeof value || null === value) throw new PersistenceCompatibilityError(sourcePath, 'invalid sqlite_master row');
47
+ const type = 'type' in value ? value.type : void 0;
48
+ const name = 'name' in value ? value.name : void 0;
49
+ const sql = 'sql' in value ? value.sql : void 0;
50
+ if ('string' != typeof type || 'string' != typeof name || 'string' != typeof sql) throw new PersistenceCompatibilityError(sourcePath, 'invalid sqlite_master fields');
51
+ return {
52
+ type,
53
+ name,
54
+ sql
55
+ };
56
+ }
57
+ function validateSqliteV1Schema(database, sourcePath) {
58
+ const objects = database.prepare("SELECT type, name, sql FROM sqlite_master WHERE name NOT LIKE 'sqlite_%' ORDER BY type, name").all().map((row)=>readObject(row, sourcePath));
59
+ const hasBranches = objects.some(({ type, name })=>'table' === type && 'branches' === name);
60
+ const expected = new Map();
61
+ for (const [name, sql] of LEGACY_TABLES)if ('branches' !== name || hasBranches) expected.set(`table:${name}`, normalizeSql(sql));
62
+ for (const [name, sql] of LEGACY_INDEXES)expected.set(`index:${name}`, normalizeSql(sql));
63
+ if (objects.length !== expected.size) throw new PersistenceCompatibilityError(sourcePath, 'SQLite v1 object set does not match');
64
+ for (const object of objects){
65
+ const expectedSql = expected.get(`${object.type}:${object.name}`);
66
+ if (void 0 === expectedSql || normalizeSql(object.sql) !== expectedSql) throw new PersistenceCompatibilityError(sourcePath, `SQLite v1 drift at '${object.name}'`);
67
+ }
68
+ return hasBranches;
69
+ }
70
+ export { validateSqliteV1Schema };
71
+
72
+ //# sourceMappingURL=SqliteLegacySchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistence/SqliteLegacySchema.js","sources":["../../src/persistence/SqliteLegacySchema.ts"],"sourcesContent":["import { PersistenceCompatibilityError } from '../errors.js';\nimport type { SqliteDatabase } from './SqliteDriver.js';\n\ntype LegacySchemaObject = {\n\treadonly type: string;\n\treadonly name: string;\n\treadonly sql: string;\n};\n\nconst LEGACY_TABLES = new Map<string, string>([\n\t[\n\t\t'thoughts',\n\t\t\"CREATE TABLE thoughts (id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT NOT NULL, created_at INTEGER DEFAULT (strftime('%s', 'now')))\",\n\t],\n\t[\n\t\t'branches',\n\t\t\"CREATE TABLE branches (branch_id TEXT PRIMARY KEY, data TEXT NOT NULL, updated_at INTEGER DEFAULT (strftime('%s', 'now')))\",\n\t],\n\t[\n\t\t'edges',\n\t\t'CREATE TABLE edges (id TEXT PRIMARY KEY, session_id TEXT NOT NULL, from_id TEXT NOT NULL, to_id TEXT NOT NULL, kind TEXT NOT NULL, created_at INTEGER NOT NULL, metadata TEXT)',\n\t],\n\t[\n\t\t'summaries',\n\t\t'CREATE TABLE summaries (id TEXT PRIMARY KEY, session_id TEXT NOT NULL, branch_id TEXT, root_thought_id TEXT NOT NULL, covered_ids TEXT NOT NULL, covered_range_start INTEGER NOT NULL, covered_range_end INTEGER NOT NULL, topics TEXT NOT NULL, aggregate_confidence REAL NOT NULL, created_at INTEGER NOT NULL, meta TEXT)',\n\t],\n]);\n\nconst LEGACY_INDEXES = new Map<string, string>([\n\t['idx_thoughts_created_at', 'CREATE INDEX idx_thoughts_created_at ON thoughts(created_at)'],\n\t['idx_edges_session', 'CREATE INDEX idx_edges_session ON edges(session_id)'],\n\t['idx_edges_from', 'CREATE INDEX idx_edges_from ON edges(session_id, from_id)'],\n\t['idx_edges_to', 'CREATE INDEX idx_edges_to ON edges(session_id, to_id)'],\n\t['idx_summaries_session', 'CREATE INDEX idx_summaries_session ON summaries(session_id)'],\n]);\n\nfunction normalizeSql(sql: string): string {\n\treturn sql.replace(/\\s+/g, ' ').replace(/;$/, '').trim().toLowerCase();\n}\n\nfunction readObject(value: unknown, sourcePath: string): LegacySchemaObject {\n\tif (typeof value !== 'object' || value === null) {\n\t\tthrow new PersistenceCompatibilityError(sourcePath, 'invalid sqlite_master row');\n\t}\n\tconst type = 'type' in value ? value.type : undefined;\n\tconst name = 'name' in value ? value.name : undefined;\n\tconst sql = 'sql' in value ? value.sql : undefined;\n\tif (typeof type !== 'string' || typeof name !== 'string' || typeof sql !== 'string') {\n\t\tthrow new PersistenceCompatibilityError(sourcePath, 'invalid sqlite_master fields');\n\t}\n\treturn { type, name, sql };\n}\n\n/**\n * Validates the frozen, unversioned SQLite v1 schema without mutating it.\n *\n * @param database - Read-only source database.\n * @param sourcePath - Source name used by typed compatibility errors.\n * @returns Whether the optional legacy branches table is present.\n *\n * @example\n * ```ts\n * const hasBranches = validateSqliteV1Schema(database, 'legacy.db');\n * ```\n */\nexport function validateSqliteV1Schema(database: SqliteDatabase, sourcePath: string): boolean {\n\tconst objects = database\n\t\t.prepare(\n\t\t\t\"SELECT type, name, sql FROM sqlite_master WHERE name NOT LIKE 'sqlite_%' ORDER BY type, name\"\n\t\t)\n\t\t.all()\n\t\t.map((row) => readObject(row, sourcePath));\n\tconst hasBranches = objects.some(({ type, name }) => type === 'table' && name === 'branches');\n\tconst expected = new Map<string, string>();\n\tfor (const [name, sql] of LEGACY_TABLES) {\n\t\tif (name !== 'branches' || hasBranches) expected.set(`table:${name}`, normalizeSql(sql));\n\t}\n\tfor (const [name, sql] of LEGACY_INDEXES) expected.set(`index:${name}`, normalizeSql(sql));\n\tif (objects.length !== expected.size) {\n\t\tthrow new PersistenceCompatibilityError(sourcePath, 'SQLite v1 object set does not match');\n\t}\n\tfor (const object of objects) {\n\t\tconst expectedSql = expected.get(`${object.type}:${object.name}`);\n\t\tif (expectedSql === undefined || normalizeSql(object.sql) !== expectedSql) {\n\t\t\tthrow new PersistenceCompatibilityError(sourcePath, `SQLite v1 drift at '${object.name}'`);\n\t\t}\n\t}\n\treturn hasBranches;\n}\n"],"names":["LEGACY_TABLES","Map","LEGACY_INDEXES","normalizeSql","sql","readObject","value","sourcePath","PersistenceCompatibilityError","type","undefined","name","validateSqliteV1Schema","database","objects","row","hasBranches","expected","object","expectedSql"],"mappings":";AASA,MAAMA,gBAAgB,IAAIC,IAAoB;IAC7C;QACC;QACA;KACA;IACD;QACC;QACA;KACA;IACD;QACC;QACA;KACA;IACD;QACC;QACA;KACA;CACD;AAED,MAAMC,iBAAiB,IAAID,IAAoB;IAC9C;QAAC;QAA2B;KAA+D;IAC3F;QAAC;QAAqB;KAAsD;IAC5E;QAAC;QAAkB;KAA4D;IAC/E;QAAC;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D,YAAY;IAErD,KAAK,MAAMW,UAAUJ,QAAS;QAC7B,MAAMK,cAAcF,SAAS,GAAG,CAAC,GAAGC,OAAO,IAAI,CAAC,CAAC,EAAEA,OAAO,IAAI,EAAE;QAChE,IAAIC,AAAgBT,WAAhBS,eAA6BhB,aAAae,OAAO,GAAG,MAAMC,aAC7D,MAAM,IAAIX,8BAA8BD,YAAY,CAAC,oBAAoB,EAAEW,OAAO,IAAI,CAAC,CAAC,CAAC;IAE3F;IACA,OAAOF;AACR"}
@@ -0,0 +1,11 @@
1
+ import type { Summary } from '../core/compression/Summary.js';
2
+ import type { Edge } from '../core/graph/Edge.js';
3
+ import type { ThoughtData } from '../core/thought.js';
4
+ export declare function stringField(row: unknown, key: string, sourcePath: string): string;
5
+ export declare function nullableStringField(row: unknown, key: string, sourcePath: string): string | null;
6
+ export declare function numberField(row: unknown, key: string, sourcePath: string): number;
7
+ export declare function parseSqliteJson(json: string, sourcePath: string): unknown;
8
+ export declare function decodeThoughtRow(row: unknown, sourcePath: string): ThoughtData;
9
+ export declare function decodeEdgeRow(row: unknown, sourcePath: string): Edge;
10
+ export declare function decodeSummaryRow(row: unknown, sourcePath: string): Summary;
11
+ //# sourceMappingURL=SqlitePayload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqlitePayload.d.ts","sourceRoot":"","sources":["../../src/persistence/SqlitePayload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAWtD,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAMjF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAShG;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CASjF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAMzE;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,WAAW,CAU9E;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAgBpE;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CA0B1E"}
@@ -0,0 +1,86 @@
1
+ import { PersistenceCorruptionError } from "../errors.js";
2
+ import { parseEdge, parseSummary, parseThoughtData } from "./PersistenceCodec.js";
3
+ function field(row, key, sourcePath) {
4
+ if ('object' != typeof row || null === row || !(key in row)) throw new PersistenceCorruptionError(sourcePath, new TypeError(`missing column '${key}'`));
5
+ return Object.getOwnPropertyDescriptor(row, key)?.value;
6
+ }
7
+ function stringField(row, key, sourcePath) {
8
+ const value = field(row, key, sourcePath);
9
+ if ('string' != typeof value) throw new PersistenceCorruptionError(sourcePath, new TypeError(`column '${key}' is not text`));
10
+ return value;
11
+ }
12
+ function nullableStringField(row, key, sourcePath) {
13
+ const value = field(row, key, sourcePath);
14
+ if (null !== value && 'string' != typeof value) throw new PersistenceCorruptionError(sourcePath, new TypeError(`column '${key}' is not nullable text`));
15
+ return value;
16
+ }
17
+ function numberField(row, key, sourcePath) {
18
+ const value = field(row, key, sourcePath);
19
+ if ('number' != typeof value || !Number.isFinite(value)) throw new PersistenceCorruptionError(sourcePath, new TypeError(`column '${key}' is not numeric`));
20
+ return value;
21
+ }
22
+ function parseSqliteJson(json, sourcePath) {
23
+ try {
24
+ return JSON.parse(json);
25
+ } catch (error) {
26
+ throw new PersistenceCorruptionError(sourcePath, error);
27
+ }
28
+ }
29
+ function decodeThoughtRow(row, sourcePath) {
30
+ try {
31
+ return parseThoughtData(parseSqliteJson(stringField(row, 'data', sourcePath), sourcePath), sourcePath);
32
+ } catch (error) {
33
+ if (error instanceof PersistenceCorruptionError) throw error;
34
+ throw new PersistenceCorruptionError(sourcePath, error);
35
+ }
36
+ }
37
+ function decodeEdgeRow(row, sourcePath) {
38
+ const metadata = nullableStringField(row, 'metadata', sourcePath);
39
+ try {
40
+ return parseEdge({
41
+ id: stringField(row, 'id', sourcePath),
42
+ sessionId: stringField(row, 'session_id', sourcePath),
43
+ from: stringField(row, 'from_id', sourcePath),
44
+ to: stringField(row, 'to_id', sourcePath),
45
+ kind: stringField(row, 'kind', sourcePath),
46
+ createdAt: numberField(row, 'created_at', sourcePath),
47
+ ...null === metadata ? {} : {
48
+ metadata: parseSqliteJson(metadata, sourcePath)
49
+ }
50
+ });
51
+ } catch (error) {
52
+ if (error instanceof PersistenceCorruptionError) throw error;
53
+ throw new PersistenceCorruptionError(sourcePath, error);
54
+ }
55
+ }
56
+ function decodeSummaryRow(row, sourcePath) {
57
+ const branchId = nullableStringField(row, 'branch_id', sourcePath);
58
+ const meta = nullableStringField(row, 'meta', sourcePath);
59
+ try {
60
+ return parseSummary({
61
+ id: stringField(row, 'id', sourcePath),
62
+ sessionId: stringField(row, 'session_id', sourcePath),
63
+ ...null === branchId ? {} : {
64
+ branchId
65
+ },
66
+ rootThoughtId: stringField(row, 'root_thought_id', sourcePath),
67
+ coveredIds: parseSqliteJson(stringField(row, 'covered_ids', sourcePath), sourcePath),
68
+ coveredRange: [
69
+ numberField(row, 'covered_range_start', sourcePath),
70
+ numberField(row, 'covered_range_end', sourcePath)
71
+ ],
72
+ topics: parseSqliteJson(stringField(row, 'topics', sourcePath), sourcePath),
73
+ aggregateConfidence: numberField(row, 'aggregate_confidence', sourcePath),
74
+ createdAt: numberField(row, 'created_at', sourcePath),
75
+ ...null === meta ? {} : {
76
+ meta: parseSqliteJson(meta, sourcePath)
77
+ }
78
+ }, sourcePath);
79
+ } catch (error) {
80
+ if (error instanceof PersistenceCorruptionError) throw error;
81
+ throw new PersistenceCorruptionError(sourcePath, error);
82
+ }
83
+ }
84
+ export { decodeEdgeRow, decodeSummaryRow, decodeThoughtRow, nullableStringField, numberField, parseSqliteJson, stringField };
85
+
86
+ //# sourceMappingURL=SqlitePayload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistence/SqlitePayload.js","sources":["../../src/persistence/SqlitePayload.ts"],"sourcesContent":["import type { Summary } from '../core/compression/Summary.js';\nimport type { Edge } from '../core/graph/Edge.js';\nimport type { ThoughtData } from '../core/thought.js';\nimport { PersistenceCorruptionError } from '../errors.js';\nimport { parseEdge, parseSummary, parseThoughtData } from './PersistenceCodec.js';\n\nfunction field(row: unknown, key: string, sourcePath: string): unknown {\n\tif (typeof row !== 'object' || row === null || !(key in row)) {\n\t\tthrow new PersistenceCorruptionError(sourcePath, new TypeError(`missing column '${key}'`));\n\t}\n\treturn Object.getOwnPropertyDescriptor(row, key)?.value;\n}\n\nexport function stringField(row: unknown, key: string, sourcePath: string): string {\n\tconst value = field(row, key, sourcePath);\n\tif (typeof value !== 'string') {\n\t\tthrow new PersistenceCorruptionError(sourcePath, new TypeError(`column '${key}' is not text`));\n\t}\n\treturn value;\n}\n\nexport function nullableStringField(row: unknown, key: string, sourcePath: string): string | null {\n\tconst value = field(row, key, sourcePath);\n\tif (value !== null && typeof value !== 'string') {\n\t\tthrow new PersistenceCorruptionError(\n\t\t\tsourcePath,\n\t\t\tnew TypeError(`column '${key}' is not nullable text`)\n\t\t);\n\t}\n\treturn value;\n}\n\nexport function numberField(row: unknown, key: string, sourcePath: string): number {\n\tconst value = field(row, key, sourcePath);\n\tif (typeof value !== 'number' || !Number.isFinite(value)) {\n\t\tthrow new PersistenceCorruptionError(\n\t\t\tsourcePath,\n\t\t\tnew TypeError(`column '${key}' is not numeric`)\n\t\t);\n\t}\n\treturn value;\n}\n\nexport function parseSqliteJson(json: string, sourcePath: string): unknown {\n\ttry {\n\t\treturn JSON.parse(json);\n\t} catch (error) {\n\t\tthrow new PersistenceCorruptionError(sourcePath, error);\n\t}\n}\n\nexport function decodeThoughtRow(row: unknown, sourcePath: string): ThoughtData {\n\ttry {\n\t\treturn parseThoughtData(\n\t\t\tparseSqliteJson(stringField(row, 'data', sourcePath), sourcePath),\n\t\t\tsourcePath\n\t\t);\n\t} catch (error) {\n\t\tif (error instanceof PersistenceCorruptionError) throw error;\n\t\tthrow new PersistenceCorruptionError(sourcePath, error);\n\t}\n}\n\nexport function decodeEdgeRow(row: unknown, sourcePath: string): Edge {\n\tconst metadata = nullableStringField(row, 'metadata', sourcePath);\n\ttry {\n\t\treturn parseEdge({\n\t\t\tid: stringField(row, 'id', sourcePath),\n\t\t\tsessionId: stringField(row, 'session_id', sourcePath),\n\t\t\tfrom: stringField(row, 'from_id', sourcePath),\n\t\t\tto: stringField(row, 'to_id', sourcePath),\n\t\t\tkind: stringField(row, 'kind', sourcePath),\n\t\t\tcreatedAt: numberField(row, 'created_at', sourcePath),\n\t\t\t...(metadata === null ? {} : { metadata: parseSqliteJson(metadata, sourcePath) }),\n\t\t});\n\t} catch (error) {\n\t\tif (error instanceof PersistenceCorruptionError) throw error;\n\t\tthrow new PersistenceCorruptionError(sourcePath, error);\n\t}\n}\n\nexport function decodeSummaryRow(row: unknown, sourcePath: string): Summary {\n\tconst branchId = nullableStringField(row, 'branch_id', sourcePath);\n\tconst meta = nullableStringField(row, 'meta', sourcePath);\n\ttry {\n\t\treturn parseSummary(\n\t\t\t{\n\t\t\t\tid: stringField(row, 'id', sourcePath),\n\t\t\t\tsessionId: stringField(row, 'session_id', sourcePath),\n\t\t\t\t...(branchId === null ? {} : { branchId }),\n\t\t\t\trootThoughtId: stringField(row, 'root_thought_id', sourcePath),\n\t\t\t\tcoveredIds: parseSqliteJson(stringField(row, 'covered_ids', sourcePath), sourcePath),\n\t\t\t\tcoveredRange: [\n\t\t\t\t\tnumberField(row, 'covered_range_start', sourcePath),\n\t\t\t\t\tnumberField(row, 'covered_range_end', sourcePath),\n\t\t\t\t],\n\t\t\t\ttopics: parseSqliteJson(stringField(row, 'topics', sourcePath), sourcePath),\n\t\t\t\taggregateConfidence: numberField(row, 'aggregate_confidence', sourcePath),\n\t\t\t\tcreatedAt: numberField(row, 'created_at', sourcePath),\n\t\t\t\t...(meta === null ? {} : { meta: parseSqliteJson(meta, sourcePath) }),\n\t\t\t},\n\t\t\tsourcePath\n\t\t);\n\t} catch (error) {\n\t\tif (error instanceof PersistenceCorruptionError) throw error;\n\t\tthrow new PersistenceCorruptionError(sourcePath, error);\n\t}\n}\n"],"names":["field","row","key","sourcePath","PersistenceCorruptionError","TypeError","Object","stringField","value","nullableStringField","numberField","Number","parseSqliteJson","json","JSON","error","decodeThoughtRow","parseThoughtData","decodeEdgeRow","metadata","parseEdge","decodeSummaryRow","branchId","meta","parseSummary"],"mappings":";;AAMA,SAASA,MAAMC,GAAY,EAAEC,GAAW,EAAEC,UAAkB;IAC3D,IAAI,AAAe,YAAf,OAAOF,OAAoBA,AAAQ,SAARA,OAAgB,CAAEC,CAAAA,OAAOD,GAAE,GACzD,MAAM,IAAIG,2BAA2BD,YAAY,IAAIE,UAAU,CAAC,gBAAgB,EAAEH,IAAI,CAAC,CAAC;IAEzF,OAAOI,OAAO,wBAAwB,CAACL,KAAKC,MAAM;AACnD;AAEO,SAASK,YAAYN,GAAY,EAAEC,GAAW,EAAEC,UAAkB;IACxE,MAAMK,QAAQR,MAAMC,KAAKC,KAAKC;IAC9B,IAAI,AAAiB,YAAjB,OAAOK,OACV,MAAM,IAAIJ,2BAA2BD,YAAY,IAAIE,UAAU,CAAC,QAAQ,EAAEH,IAAI,aAAa,CAAC;IAE7F,OAAOM;AACR;AAEO,SAASC,oBAAoBR,GAAY,EAAEC,GAAW,EAAEC,UAAkB;IAChF,MAAMK,QAA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O,UAAUhB;YAAY,CAAC;QACjF;IACD,EAAE,OAAOY,OAAO;QACf,IAAIA,iBAAiBX,4BAA4B,MAAMW;QACvD,MAAM,IAAIX,2BAA2BD,YAAYY;IAClD;AACD;AAEO,SAASM,iBAAiBpB,GAAY,EAAEE,UAAkB;IAChE,MAAMmB,WAAWb,oBAAoBR,KAAK,aAAaE;IACvD,MAAMoB,OAAOd,oBAAoBR,KAAK,QAAQE;IAC9C,IAAI;QACH,OAAOqB,aACN;YACC,IAAIjB,YAAYN,KAAK,MAAME;YAC3B,WAAWI,YAAYN,KAAK,cAAcE;YAC1C,GAAImB,AAAa,SAAbA,WAAoB,CAAC,IAAI;gBAAEA;YAAS,CAAC;YACzC,eAAef,YAAYN,KAAK,mBAAmBE;YACnD,YAAYS,gBAAgBL,YAAYN,KAAK,eAAeE,aAAaA;YACzE,cAAc;gBACbO,YAAYT,KAAK,uBAAuBE;gBACxCO,YAAYT,KAAK,qBAAqBE;aACtC;YACD,QAAQS,gBAAgBL,YAAYN,KAAK,UAAUE,aAAaA;YAChE,qBAAqBO,YAAYT,KAAK,wBAAwBE;YAC9D,WAAWO,YAAYT,KAAK,cAAcE;YAC1C,GAAIoB,AAAS,SAATA,OAAgB,CAAC,IAAI;gBAAE,MAAMX,gBAAgBW,MAAMpB;YAAY,CAAC;QACrE,GACAA;IAEF,EAAE,OAAOY,OAAO;QACf,IAAIA,iBAAiBX,4BAA4B,MAAMW;QACvD,MAAM,IAAIX,2BAA2BD,YAAYY;IAClD;AACD"}
@@ -0,0 +1,49 @@
1
+ import type { PersistenceConfig, SessionScopedPersistenceBackend } from '../contracts/PersistenceBackend.js';
2
+ import { type BranchId, type SessionId } from '../contracts/ids.js';
3
+ import type { Summary } from '../core/compression/Summary.js';
4
+ import type { Edge } from '../core/graph/Edge.js';
5
+ import type { ThoughtData } from '../core/thought.js';
6
+ import type { SqliteDatabase } from './SqliteDriver.js';
7
+ type SqliteOptions = PersistenceConfig['options'];
8
+ export declare class SqlitePersistence implements SessionScopedPersistenceBackend {
9
+ private readonly _db;
10
+ private readonly _sourcePath;
11
+ private readonly _maxHistorySize;
12
+ private readonly _persistBranches;
13
+ private constructor();
14
+ static createWithDatabase(database: SqliteDatabase, options?: SqliteOptions, sourcePath?: string): SqlitePersistence;
15
+ static create(options?: SqliteOptions): Promise<SqlitePersistence>;
16
+ saveThought(thought: ThoughtData): Promise<void>;
17
+ saveThoughtForSession(sessionId: SessionId, thought: ThoughtData): Promise<void>;
18
+ private _saveThought;
19
+ loadHistory(): Promise<ThoughtData[]>;
20
+ loadHistoryForSession(sessionId: SessionId): Promise<ThoughtData[]>;
21
+ saveBranch(branchId: BranchId, thoughts: ThoughtData[]): Promise<void>;
22
+ saveBranchForSession(sessionId: SessionId, branchId: BranchId, thoughts: readonly ThoughtData[]): Promise<void>;
23
+ private _saveBranch;
24
+ deleteBranch(branchId: BranchId): Promise<void>;
25
+ deleteBranchForSession(sessionId: SessionId, branchId: BranchId): Promise<void>;
26
+ loadBranch(branchId: BranchId): Promise<ThoughtData[] | undefined>;
27
+ loadBranchForSession(sessionId: SessionId, branchId: BranchId): Promise<ThoughtData[] | undefined>;
28
+ listBranches(): Promise<BranchId[]>;
29
+ listBranchesForSession(sessionId: SessionId): Promise<BranchId[]>;
30
+ listSessions(): Promise<SessionId[]>;
31
+ clear(): Promise<void>;
32
+ clearSession(sessionId: SessionId): Promise<void>;
33
+ saveEdges(sessionId: SessionId, edges: readonly Edge[]): Promise<void>;
34
+ loadEdges(sessionId: SessionId): Promise<Edge[]>;
35
+ listEdgeSessions(): Promise<SessionId[]>;
36
+ saveSummaries(sessionId: SessionId, summaries: readonly Summary[]): Promise<void>;
37
+ loadSummaries(sessionId: SessionId): Promise<Summary[]>;
38
+ healthy(): Promise<boolean>;
39
+ close(): Promise<void>;
40
+ getStats(): {
41
+ readonly thoughtCount: number;
42
+ readonly branchCount: number;
43
+ readonly dbSize: number;
44
+ };
45
+ private _loadValidatedThoughtState;
46
+ private loadHistoryRows;
47
+ }
48
+ export {};
49
+ //# sourceMappingURL=SqlitePersistence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SqlitePersistence.d.ts","sourceRoot":"","sources":["../../src/persistence/SqlitePersistence.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,iBAAiB,EACjB,+BAA+B,EAC/B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAkC,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACpG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,KAAK,EAAE,cAAc,EAA6B,MAAM,mBAAmB,CAAC;AAsBnF,KAAK,aAAa,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;AAOlD,qBAAa,iBAAkB,YAAW,+BAA+B;IAEvE,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAJlC,OAAO;WAOO,kBAAkB,CAC/B,QAAQ,EAAE,cAAc,EACxB,OAAO,GAAE,aAAkB,EAC3B,UAAU,SAAwB,GAChC,iBAAiB;WAUA,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAgClE,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAKhD,qBAAqB,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7F,OAAO,CAAC,YAAY;IAwBP,WAAW,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAIrC,qBAAqB,C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