agentdb 3.0.0-alpha.9 → 3.1.0
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.
- package/LICENSE +21 -0
- package/README.md +248 -269
- package/dist/schemas/frontier-schema.sql +7 -0
- package/dist/schemas/schema.sql +7 -0
- package/dist/src/backends/ExactSearch.d.ts +22 -0
- package/dist/src/backends/ExactSearch.d.ts.map +1 -0
- package/dist/src/backends/ExactSearch.js +36 -0
- package/dist/src/backends/ExactSearch.js.map +1 -0
- package/dist/src/backends/VectorBackend.d.ts +80 -6
- package/dist/src/backends/VectorBackend.d.ts.map +1 -1
- package/dist/src/backends/VectorBackend.js +67 -1
- package/dist/src/backends/VectorBackend.js.map +1 -1
- package/dist/src/backends/detector.js.map +1 -1
- package/dist/src/backends/factory.d.ts +16 -33
- package/dist/src/backends/factory.d.ts.map +1 -1
- package/dist/src/backends/factory.js +140 -110
- package/dist/src/backends/factory.js.map +1 -1
- package/dist/src/backends/graph/GraphDatabaseAdapter.d.ts +54 -6
- package/dist/src/backends/graph/GraphDatabaseAdapter.d.ts.map +1 -1
- package/dist/src/backends/graph/GraphDatabaseAdapter.js +143 -6
- package/dist/src/backends/graph/GraphDatabaseAdapter.js.map +1 -1
- package/dist/src/backends/hnswlib/HNSWLibBackend.d.ts.map +1 -1
- package/dist/src/backends/hnswlib/HNSWLibBackend.js +35 -8
- package/dist/src/backends/hnswlib/HNSWLibBackend.js.map +1 -1
- package/dist/src/backends/index.d.ts +2 -1
- package/dist/src/backends/index.d.ts.map +1 -1
- package/dist/src/backends/index.js +2 -0
- package/dist/src/backends/index.js.map +1 -1
- package/dist/src/backends/ruvector/RuVectorBackend.d.ts +256 -45
- package/dist/src/backends/ruvector/RuVectorBackend.d.ts.map +1 -1
- package/dist/src/backends/ruvector/RuVectorBackend.js +764 -290
- package/dist/src/backends/ruvector/RuVectorBackend.js.map +1 -1
- package/dist/src/backends/ruvector/RuVectorLearning.d.ts +0 -4
- package/dist/src/backends/ruvector/RuVectorLearning.d.ts.map +1 -1
- package/dist/src/backends/ruvector/RuVectorLearning.js +0 -6
- package/dist/src/backends/ruvector/RuVectorLearning.js.map +1 -1
- package/dist/src/backends/rvf/AdaptiveIndexTuner.d.ts +175 -0
- package/dist/src/backends/rvf/AdaptiveIndexTuner.d.ts.map +1 -0
- package/dist/src/backends/rvf/AdaptiveIndexTuner.js +567 -0
- package/dist/src/backends/rvf/AdaptiveIndexTuner.js.map +1 -0
- package/dist/src/backends/rvf/ContrastiveTrainer.d.ts +148 -0
- package/dist/src/backends/rvf/ContrastiveTrainer.d.ts.map +1 -0
- package/dist/src/backends/rvf/ContrastiveTrainer.js +438 -0
- package/dist/src/backends/rvf/ContrastiveTrainer.js.map +1 -0
- package/dist/src/backends/rvf/FederatedSessionManager.d.ts +212 -0
- package/dist/src/backends/rvf/FederatedSessionManager.d.ts.map +1 -0
- package/dist/src/backends/rvf/FederatedSessionManager.js +397 -0
- package/dist/src/backends/rvf/FederatedSessionManager.js.map +1 -0
- package/dist/src/backends/rvf/FilterBuilder.d.ts +136 -0
- package/dist/src/backends/rvf/FilterBuilder.d.ts.map +1 -0
- package/dist/src/backends/rvf/FilterBuilder.js +157 -0
- package/dist/src/backends/rvf/FilterBuilder.js.map +1 -0
- package/dist/src/backends/rvf/NativeAccelerator.d.ts +158 -0
- package/dist/src/backends/rvf/NativeAccelerator.d.ts.map +1 -0
- package/dist/src/backends/rvf/NativeAccelerator.js +702 -0
- package/dist/src/backends/rvf/NativeAccelerator.js.map +1 -0
- package/dist/src/backends/rvf/RvfBackend.d.ts +207 -0
- package/dist/src/backends/rvf/RvfBackend.d.ts.map +1 -0
- package/dist/src/backends/rvf/RvfBackend.js +651 -0
- package/dist/src/backends/rvf/RvfBackend.js.map +1 -0
- package/dist/src/backends/rvf/RvfSolver.d.ts +175 -0
- package/dist/src/backends/rvf/RvfSolver.d.ts.map +1 -0
- package/dist/src/backends/rvf/RvfSolver.js +176 -0
- package/dist/src/backends/rvf/RvfSolver.js.map +1 -0
- package/dist/src/backends/rvf/SelfLearningRvfBackend.d.ts +143 -0
- package/dist/src/backends/rvf/SelfLearningRvfBackend.d.ts.map +1 -0
- package/dist/src/backends/rvf/SelfLearningRvfBackend.js +612 -0
- package/dist/src/backends/rvf/SelfLearningRvfBackend.js.map +1 -0
- package/dist/src/backends/rvf/SemanticQueryRouter.d.ts +128 -0
- package/dist/src/backends/rvf/SemanticQueryRouter.d.ts.map +1 -0
- package/dist/src/backends/rvf/SemanticQueryRouter.js +415 -0
- package/dist/src/backends/rvf/SemanticQueryRouter.js.map +1 -0
- package/dist/src/backends/rvf/SimdFallbacks.d.ts +25 -0
- package/dist/src/backends/rvf/SimdFallbacks.d.ts.map +1 -0
- package/dist/src/backends/rvf/SimdFallbacks.js +287 -0
- package/dist/src/backends/rvf/SimdFallbacks.js.map +1 -0
- package/dist/src/backends/rvf/SolverBandit.d.ts +100 -0
- package/dist/src/backends/rvf/SolverBandit.d.ts.map +1 -0
- package/dist/src/backends/rvf/SolverBandit.js +216 -0
- package/dist/src/backends/rvf/SolverBandit.js.map +1 -0
- package/dist/src/backends/rvf/SonaLearningBackend.d.ts +157 -0
- package/dist/src/backends/rvf/SonaLearningBackend.d.ts.map +1 -0
- package/dist/src/backends/rvf/SonaLearningBackend.js +283 -0
- package/dist/src/backends/rvf/SonaLearningBackend.js.map +1 -0
- package/dist/src/backends/rvf/SqlJsRvfBackend.d.ts +104 -0
- package/dist/src/backends/rvf/SqlJsRvfBackend.d.ts.map +1 -0
- package/dist/src/backends/rvf/SqlJsRvfBackend.js +474 -0
- package/dist/src/backends/rvf/SqlJsRvfBackend.js.map +1 -0
- package/dist/src/backends/rvf/WasmStoreBridge.d.ts +27 -0
- package/dist/src/backends/rvf/WasmStoreBridge.d.ts.map +1 -0
- package/dist/src/backends/rvf/WasmStoreBridge.js +87 -0
- package/dist/src/backends/rvf/WasmStoreBridge.js.map +1 -0
- package/dist/src/backends/rvf/validation.d.ts +20 -0
- package/dist/src/backends/rvf/validation.d.ts.map +1 -0
- package/dist/src/backends/rvf/validation.js +78 -0
- package/dist/src/backends/rvf/validation.js.map +1 -0
- package/dist/src/benchmark/BenchmarkSuite.d.ts +318 -0
- package/dist/src/benchmark/BenchmarkSuite.d.ts.map +1 -0
- package/dist/src/benchmark/BenchmarkSuite.js +984 -0
- package/dist/src/benchmark/BenchmarkSuite.js.map +1 -0
- package/dist/src/benchmark/index.d.ts +29 -0
- package/dist/src/benchmark/index.d.ts.map +1 -0
- package/dist/src/benchmark/index.js +39 -0
- package/dist/src/benchmark/index.js.map +1 -0
- package/dist/src/browser/AttentionBrowser.d.ts.map +1 -1
- package/dist/src/browser/AttentionBrowser.js +1 -0
- package/dist/src/browser/AttentionBrowser.js.map +1 -1
- package/dist/src/cli/agentdb-cli.d.ts +14 -0
- package/dist/src/cli/agentdb-cli.d.ts.map +1 -1
- package/dist/src/cli/agentdb-cli.js +839 -143
- package/dist/src/cli/agentdb-cli.js.map +1 -1
- package/dist/src/cli/commands/attention.js +12 -2
- package/dist/src/cli/commands/attention.js.map +1 -1
- package/dist/src/cli/commands/doctor.js +5 -5
- package/dist/src/cli/commands/doctor.js.map +1 -1
- package/dist/src/cli/commands/hyperbolic.d.ts +11 -0
- package/dist/src/cli/commands/hyperbolic.d.ts.map +1 -0
- package/dist/src/cli/commands/hyperbolic.js +440 -0
- package/dist/src/cli/commands/hyperbolic.js.map +1 -0
- package/dist/src/cli/commands/install-embeddings.d.ts +1 -1
- package/dist/src/cli/commands/install-embeddings.d.ts.map +1 -1
- package/dist/src/cli/commands/install-embeddings.js +17 -11
- package/dist/src/cli/commands/install-embeddings.js.map +1 -1
- package/dist/src/cli/commands/learn.d.ts +11 -0
- package/dist/src/cli/commands/learn.d.ts.map +1 -0
- package/dist/src/cli/commands/learn.js +410 -0
- package/dist/src/cli/commands/learn.js.map +1 -0
- package/dist/src/cli/commands/migrate.d.ts +15 -0
- package/dist/src/cli/commands/migrate.d.ts.map +1 -1
- package/dist/src/cli/commands/migrate.js +190 -10
- package/dist/src/cli/commands/migrate.js.map +1 -1
- package/dist/src/cli/commands/route.d.ts +11 -0
- package/dist/src/cli/commands/route.d.ts.map +1 -0
- package/dist/src/cli/commands/route.js +419 -0
- package/dist/src/cli/commands/route.js.map +1 -0
- package/dist/src/cli/commands/rvf.d.ts +21 -0
- package/dist/src/cli/commands/rvf.d.ts.map +1 -0
- package/dist/src/cli/commands/rvf.js +448 -0
- package/dist/src/cli/commands/rvf.js.map +1 -0
- package/dist/src/cli/commands/simulate-report.js +14 -2
- package/dist/src/cli/commands/simulate-report.js.map +1 -1
- package/dist/src/cli/lib/report-store.d.ts +2 -1
- package/dist/src/cli/lib/report-store.d.ts.map +1 -1
- package/dist/src/cli/lib/report-store.js +85 -65
- package/dist/src/cli/lib/report-store.js.map +1 -1
- package/dist/src/cli/lib/simulation-runner.d.ts +40 -3
- package/dist/src/cli/lib/simulation-runner.d.ts.map +1 -1
- package/dist/src/cli/lib/simulation-runner.js +248 -6
- package/dist/src/cli/lib/simulation-runner.js.map +1 -1
- package/dist/src/compatibility/DeprecationWarnings.d.ts +54 -0
- package/dist/src/compatibility/DeprecationWarnings.d.ts.map +1 -0
- package/dist/src/compatibility/DeprecationWarnings.js +131 -0
- package/dist/src/compatibility/DeprecationWarnings.js.map +1 -0
- package/dist/src/compatibility/MigrationUtilities.d.ts +30 -0
- package/dist/src/compatibility/MigrationUtilities.d.ts.map +1 -0
- package/dist/src/compatibility/MigrationUtilities.js +184 -0
- package/dist/src/compatibility/MigrationUtilities.js.map +1 -0
- package/dist/src/compatibility/V1toV2Adapter.d.ts +76 -0
- package/dist/src/compatibility/V1toV2Adapter.d.ts.map +1 -0
- package/dist/src/compatibility/V1toV2Adapter.js +185 -0
- package/dist/src/compatibility/V1toV2Adapter.js.map +1 -0
- package/dist/src/compatibility/VersionDetector.d.ts +32 -0
- package/dist/src/compatibility/VersionDetector.d.ts.map +1 -0
- package/dist/src/compatibility/VersionDetector.js +144 -0
- package/dist/src/compatibility/VersionDetector.js.map +1 -0
- package/dist/src/compatibility/index.d.ts +14 -0
- package/dist/src/compatibility/index.d.ts.map +1 -0
- package/dist/src/compatibility/index.js +21 -0
- package/dist/src/compatibility/index.js.map +1 -0
- package/dist/src/compatibility/types.d.ts +103 -0
- package/dist/src/compatibility/types.d.ts.map +1 -0
- package/dist/src/compatibility/types.js +5 -0
- package/dist/src/compatibility/types.js.map +1 -0
- package/dist/src/controllers/AttentionService.d.ts +99 -202
- package/dist/src/controllers/AttentionService.d.ts.map +1 -1
- package/dist/src/controllers/AttentionService.js +450 -558
- package/dist/src/controllers/AttentionService.js.map +1 -1
- package/dist/src/controllers/CausalMemoryGraph.d.ts +30 -5
- package/dist/src/controllers/CausalMemoryGraph.d.ts.map +1 -1
- package/dist/src/controllers/CausalMemoryGraph.js +92 -15
- package/dist/src/controllers/CausalMemoryGraph.js.map +1 -1
- package/dist/src/controllers/CausalRecall.d.ts +4 -0
- package/dist/src/controllers/CausalRecall.d.ts.map +1 -1
- package/dist/src/controllers/CausalRecall.js +23 -5
- package/dist/src/controllers/CausalRecall.js.map +1 -1
- package/dist/src/controllers/EmbeddingService.d.ts +39 -0
- package/dist/src/controllers/EmbeddingService.d.ts.map +1 -1
- package/dist/src/controllers/EmbeddingService.js +166 -32
- package/dist/src/controllers/EmbeddingService.js.map +1 -1
- package/dist/src/controllers/EnhancedEmbeddingService.d.ts +4 -0
- package/dist/src/controllers/EnhancedEmbeddingService.d.ts.map +1 -1
- package/dist/src/controllers/EnhancedEmbeddingService.js +21 -7
- package/dist/src/controllers/EnhancedEmbeddingService.js.map +1 -1
- package/dist/src/controllers/ExplainableRecall.d.ts +1 -1
- package/dist/src/controllers/ExplainableRecall.d.ts.map +1 -1
- package/dist/src/controllers/ExplainableRecall.js +1 -1
- package/dist/src/controllers/ExplainableRecall.js.map +1 -1
- package/dist/src/controllers/HNSWIndex.d.ts +20 -2
- package/dist/src/controllers/HNSWIndex.d.ts.map +1 -1
- package/dist/src/controllers/HNSWIndex.js +114 -39
- package/dist/src/controllers/HNSWIndex.js.map +1 -1
- package/dist/src/controllers/LearningSystem.d.ts +6 -17
- package/dist/src/controllers/LearningSystem.d.ts.map +1 -1
- package/dist/src/controllers/LearningSystem.js +66 -155
- package/dist/src/controllers/LearningSystem.js.map +1 -1
- package/dist/src/controllers/MemoryController.d.ts +174 -0
- package/dist/src/controllers/MemoryController.d.ts.map +1 -0
- package/dist/src/controllers/MemoryController.js +320 -0
- package/dist/src/controllers/MemoryController.js.map +1 -0
- package/dist/src/controllers/MetadataFilter.d.ts.map +1 -1
- package/dist/src/controllers/MetadataFilter.js +38 -26
- package/dist/src/controllers/MetadataFilter.js.map +1 -1
- package/dist/src/controllers/MincutService.d.ts +92 -0
- package/dist/src/controllers/MincutService.d.ts.map +1 -0
- package/dist/src/controllers/MincutService.js +336 -0
- package/dist/src/controllers/MincutService.js.map +1 -0
- package/dist/src/controllers/NightlyLearner.d.ts +5 -1
- package/dist/src/controllers/NightlyLearner.d.ts.map +1 -1
- package/dist/src/controllers/NightlyLearner.js +45 -31
- package/dist/src/controllers/NightlyLearner.js.map +1 -1
- package/dist/src/controllers/QUICClient.d.ts +45 -0
- package/dist/src/controllers/QUICClient.d.ts.map +1 -1
- package/dist/src/controllers/QUICClient.js +211 -21
- package/dist/src/controllers/QUICClient.js.map +1 -1
- package/dist/src/controllers/QUICServer.d.ts.map +1 -1
- package/dist/src/controllers/QUICServer.js +36 -27
- package/dist/src/controllers/QUICServer.js.map +1 -1
- package/dist/src/controllers/ReasoningBank.d.ts +44 -5
- package/dist/src/controllers/ReasoningBank.d.ts.map +1 -1
- package/dist/src/controllers/ReasoningBank.js +187 -99
- package/dist/src/controllers/ReasoningBank.js.map +1 -1
- package/dist/src/controllers/ReflexionMemory.d.ts +129 -6
- package/dist/src/controllers/ReflexionMemory.d.ts.map +1 -1
- package/dist/src/controllers/ReflexionMemory.js +687 -220
- package/dist/src/controllers/ReflexionMemory.js.map +1 -1
- package/dist/src/controllers/SkillLibrary.d.ts +41 -3
- package/dist/src/controllers/SkillLibrary.d.ts.map +1 -1
- package/dist/src/controllers/SkillLibrary.js +291 -116
- package/dist/src/controllers/SkillLibrary.js.map +1 -1
- package/dist/src/controllers/SparsificationService.d.ts +151 -0
- package/dist/src/controllers/SparsificationService.d.ts.map +1 -0
- package/dist/src/controllers/SparsificationService.js +375 -0
- package/dist/src/controllers/SparsificationService.js.map +1 -0
- package/dist/src/controllers/SyncCoordinator.d.ts.map +1 -1
- package/dist/src/controllers/SyncCoordinator.js +126 -12
- package/dist/src/controllers/SyncCoordinator.js.map +1 -1
- package/dist/src/controllers/WASMVectorSearch.d.ts +12 -30
- package/dist/src/controllers/WASMVectorSearch.d.ts.map +1 -1
- package/dist/src/controllers/WASMVectorSearch.js +209 -119
- package/dist/src/controllers/WASMVectorSearch.js.map +1 -1
- package/dist/src/controllers/attention/AttentionCache.d.ts +38 -0
- package/dist/src/controllers/attention/AttentionCache.d.ts.map +1 -0
- package/dist/src/controllers/attention/AttentionCache.js +80 -0
- package/dist/src/controllers/attention/AttentionCache.js.map +1 -0
- package/dist/src/controllers/attention/AttentionConfig.d.ts +127 -0
- package/dist/src/controllers/attention/AttentionConfig.d.ts.map +1 -0
- package/dist/src/controllers/attention/AttentionConfig.js +124 -0
- package/dist/src/controllers/attention/AttentionConfig.js.map +1 -0
- package/dist/src/controllers/attention/AttentionCore.d.ts +89 -0
- package/dist/src/controllers/attention/AttentionCore.d.ts.map +1 -0
- package/dist/src/controllers/attention/AttentionCore.js +289 -0
- package/dist/src/controllers/attention/AttentionCore.js.map +1 -0
- package/dist/src/controllers/attention/AttentionHelpers.d.ts +55 -0
- package/dist/src/controllers/attention/AttentionHelpers.d.ts.map +1 -0
- package/dist/src/controllers/attention/AttentionHelpers.js +148 -0
- package/dist/src/controllers/attention/AttentionHelpers.js.map +1 -0
- package/dist/src/controllers/attention/AttentionMetrics.d.ts +55 -0
- package/dist/src/controllers/attention/AttentionMetrics.d.ts.map +1 -0
- package/dist/src/controllers/attention/AttentionMetrics.js +72 -0
- package/dist/src/controllers/attention/AttentionMetrics.js.map +1 -0
- package/dist/src/controllers/attention/AttentionWASM.d.ts +98 -0
- package/dist/src/controllers/attention/AttentionWASM.d.ts.map +1 -0
- package/dist/src/controllers/attention/AttentionWASM.js +147 -0
- package/dist/src/controllers/attention/AttentionWASM.js.map +1 -0
- package/dist/src/controllers/attention/CrossAttentionController.d.ts +141 -0
- package/dist/src/controllers/attention/CrossAttentionController.d.ts.map +1 -0
- package/dist/src/controllers/attention/CrossAttentionController.js +325 -0
- package/dist/src/controllers/attention/CrossAttentionController.js.map +1 -0
- package/dist/src/controllers/attention/MultiHeadAttentionController.d.ts +137 -0
- package/dist/src/controllers/attention/MultiHeadAttentionController.d.ts.map +1 -0
- package/dist/src/controllers/attention/MultiHeadAttentionController.js +336 -0
- package/dist/src/controllers/attention/MultiHeadAttentionController.js.map +1 -0
- package/dist/src/controllers/attention/SelfAttentionController.d.ts +117 -0
- package/dist/src/controllers/attention/SelfAttentionController.d.ts.map +1 -0
- package/dist/src/controllers/attention/SelfAttentionController.js +205 -0
- package/dist/src/controllers/attention/SelfAttentionController.js.map +1 -0
- package/dist/src/controllers/attention/index.d.ts +24 -0
- package/dist/src/controllers/attention/index.d.ts.map +1 -0
- package/dist/src/controllers/attention/index.js +20 -0
- package/dist/src/controllers/attention/index.js.map +1 -0
- package/dist/src/controllers/index.d.ts +15 -28
- package/dist/src/controllers/index.d.ts.map +1 -1
- package/dist/src/controllers/index.js +11 -19
- package/dist/src/controllers/index.js.map +1 -1
- package/dist/src/controllers/prerequisites.d.ts +76 -0
- package/dist/src/controllers/prerequisites.d.ts.map +1 -0
- package/dist/src/controllers/prerequisites.js +235 -0
- package/dist/src/controllers/prerequisites.js.map +1 -0
- package/dist/src/core/AgentDB.d.ts +33 -19
- package/dist/src/core/AgentDB.d.ts.map +1 -1
- package/dist/src/core/AgentDB.js +87 -127
- package/dist/src/core/AgentDB.js.map +1 -1
- package/dist/src/core/QueryCache.d.ts +138 -0
- package/dist/src/core/QueryCache.d.ts.map +1 -0
- package/dist/src/core/QueryCache.js +309 -0
- package/dist/src/core/QueryCache.js.map +1 -0
- package/dist/src/db-fallback.d.ts +52 -4
- package/dist/src/db-fallback.d.ts.map +1 -1
- package/dist/src/db-fallback.js +521 -71
- package/dist/src/db-fallback.js.map +1 -1
- package/dist/src/db-unified.d.ts.map +1 -1
- package/dist/src/db-unified.js +32 -30
- package/dist/src/db-unified.js.map +1 -1
- package/dist/src/embedding/EmbeddingSpaceIdentity.d.ts +58 -0
- package/dist/src/embedding/EmbeddingSpaceIdentity.d.ts.map +1 -0
- package/dist/src/embedding/EmbeddingSpaceIdentity.js +137 -0
- package/dist/src/embedding/EmbeddingSpaceIdentity.js.map +1 -0
- package/dist/src/embedding/index.d.ts +3 -0
- package/dist/src/embedding/index.d.ts.map +1 -0
- package/dist/src/embedding/index.js +2 -0
- package/dist/src/embedding/index.js.map +1 -0
- package/dist/src/examples/quic-sync-example.js +2 -2
- package/dist/src/examples/quic-sync-example.js.map +1 -1
- package/dist/src/governance/MetaHarnessGateway.d.ts +55 -0
- package/dist/src/governance/MetaHarnessGateway.d.ts.map +1 -0
- package/dist/src/governance/MetaHarnessGateway.js +65 -0
- package/dist/src/governance/MetaHarnessGateway.js.map +1 -0
- package/dist/src/governance/RvfExperimentBranch.d.ts +65 -0
- package/dist/src/governance/RvfExperimentBranch.d.ts.map +1 -0
- package/dist/src/governance/RvfExperimentBranch.js +115 -0
- package/dist/src/governance/RvfExperimentBranch.js.map +1 -0
- package/dist/src/index.d.ts +20 -16
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +44 -12
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/agentdb-mcp-server.js +318 -16
- package/dist/src/mcp/agentdb-mcp-server.js.map +1 -1
- package/dist/src/mcp/reset-database.d.ts +15 -0
- package/dist/src/mcp/reset-database.d.ts.map +1 -0
- package/dist/src/mcp/reset-database.js +45 -0
- package/dist/src/mcp/reset-database.js.map +1 -0
- package/dist/src/model/ModelCacheLoader.d.ts +31 -0
- package/dist/src/model/ModelCacheLoader.d.ts.map +1 -0
- package/dist/src/model/ModelCacheLoader.js +209 -0
- package/dist/src/model/ModelCacheLoader.js.map +1 -0
- package/dist/src/observability/index.d.ts +8 -0
- package/dist/src/observability/index.d.ts.map +1 -0
- package/dist/src/observability/index.js +8 -0
- package/dist/src/observability/index.js.map +1 -0
- package/dist/src/observability/integration.d.ts +32 -0
- package/dist/src/observability/integration.d.ts.map +1 -0
- package/dist/src/observability/integration.js +159 -0
- package/dist/src/observability/integration.js.map +1 -0
- package/dist/src/observability/telemetry.d.ts +137 -0
- package/dist/src/observability/telemetry.d.ts.map +1 -0
- package/dist/src/observability/telemetry.js +424 -0
- package/dist/src/observability/telemetry.js.map +1 -0
- package/dist/src/optimizations/BatchOperations.d.ts +47 -0
- package/dist/src/optimizations/BatchOperations.d.ts.map +1 -1
- package/dist/src/optimizations/BatchOperations.js +189 -35
- package/dist/src/optimizations/BatchOperations.js.map +1 -1
- package/dist/src/optimizations/Quantization.d.ts +330 -0
- package/dist/src/optimizations/Quantization.d.ts.map +1 -0
- package/dist/src/optimizations/Quantization.js +793 -0
- package/dist/src/optimizations/Quantization.js.map +1 -0
- package/dist/src/optimizations/index.d.ts +1 -3
- package/dist/src/optimizations/index.d.ts.map +1 -1
- package/dist/src/optimizations/index.js +0 -1
- package/dist/src/optimizations/index.js.map +1 -1
- package/dist/src/quantization/index.d.ts +7 -0
- package/dist/src/quantization/index.d.ts.map +1 -0
- package/dist/src/quantization/index.js +15 -0
- package/dist/src/quantization/index.js.map +1 -0
- package/dist/src/quantization/vector-quantization.d.ts +388 -0
- package/dist/src/quantization/vector-quantization.d.ts.map +1 -0
- package/dist/src/quantization/vector-quantization.js +1132 -0
- package/dist/src/quantization/vector-quantization.js.map +1 -0
- package/dist/src/schemas/inline.d.ts +3 -0
- package/dist/src/schemas/inline.d.ts.map +1 -0
- package/dist/src/schemas/inline.js +10 -0
- package/dist/src/schemas/inline.js.map +1 -0
- package/dist/src/search/HybridSearch.d.ts +311 -0
- package/dist/src/search/HybridSearch.d.ts.map +1 -0
- package/dist/src/search/HybridSearch.js +713 -0
- package/dist/src/search/HybridSearch.js.map +1 -0
- package/dist/src/search/index.d.ts +12 -0
- package/dist/src/search/index.d.ts.map +1 -0
- package/dist/src/search/index.js +16 -0
- package/dist/src/search/index.js.map +1 -0
- package/dist/src/security/input-validation.d.ts +30 -0
- package/dist/src/security/input-validation.d.ts.map +1 -1
- package/dist/src/security/input-validation.js +77 -3
- package/dist/src/security/input-validation.js.map +1 -1
- package/dist/src/security/limits.d.ts.map +1 -1
- package/dist/src/security/limits.js +12 -3
- package/dist/src/security/limits.js.map +1 -1
- package/dist/src/security/mcp-policy.d.ts +17 -0
- package/dist/src/security/mcp-policy.d.ts.map +1 -0
- package/dist/src/security/mcp-policy.js +94 -0
- package/dist/src/security/mcp-policy.js.map +1 -0
- package/dist/src/security/path-security.d.ts.map +1 -1
- package/dist/src/security/path-security.js +3 -1
- package/dist/src/security/path-security.js.map +1 -1
- package/dist/src/security/validation.js +3 -3
- package/dist/src/security/validation.js.map +1 -1
- package/dist/src/services/AttentionService.d.ts +303 -0
- package/dist/src/services/AttentionService.d.ts.map +1 -0
- package/dist/src/services/AttentionService.js +1165 -0
- package/dist/src/services/AttentionService.js.map +1 -0
- package/dist/src/services/LLMRouter.d.ts +70 -8
- package/dist/src/services/LLMRouter.d.ts.map +1 -1
- package/dist/src/services/LLMRouter.js +279 -28
- package/dist/src/services/LLMRouter.js.map +1 -1
- package/dist/src/services/audit-logger.service.d.ts +168 -0
- package/dist/src/services/audit-logger.service.d.ts.map +1 -0
- package/dist/src/services/audit-logger.service.js +331 -0
- package/dist/src/services/audit-logger.service.js.map +1 -0
- package/dist/src/services/enhanced-embeddings.d.ts +271 -0
- package/dist/src/services/enhanced-embeddings.d.ts.map +1 -0
- package/dist/src/services/enhanced-embeddings.js +1036 -0
- package/dist/src/services/enhanced-embeddings.js.map +1 -0
- package/dist/src/services/federated-learning.d.ts +172 -0
- package/dist/src/services/federated-learning.d.ts.map +1 -0
- package/dist/src/services/federated-learning.js +344 -0
- package/dist/src/services/federated-learning.js.map +1 -0
- package/dist/src/simd/index.d.ts +9 -0
- package/dist/src/simd/index.d.ts.map +1 -0
- package/dist/src/simd/index.js +27 -0
- package/dist/src/simd/index.js.map +1 -0
- package/dist/src/simd/simd-vector-ops.d.ts +343 -0
- package/dist/src/simd/simd-vector-ops.d.ts.map +1 -0
- package/dist/src/simd/simd-vector-ops.js +1012 -0
- package/dist/src/simd/simd-vector-ops.js.map +1 -0
- package/dist/src/types/database.types.d.ts +275 -0
- package/dist/src/types/database.types.d.ts.map +1 -0
- package/dist/src/types/database.types.js +55 -0
- package/dist/src/types/database.types.js.map +1 -0
- package/dist/src/types/graph.d.ts +29 -0
- package/dist/src/types/graph.d.ts.map +1 -0
- package/dist/src/types/graph.js +8 -0
- package/dist/src/types/graph.js.map +1 -0
- package/dist/src/utils/chalk-fallback.d.ts +3 -0
- package/dist/src/utils/chalk-fallback.d.ts.map +1 -0
- package/dist/src/utils/chalk-fallback.js +20 -0
- package/dist/src/utils/chalk-fallback.js.map +1 -0
- package/dist/src/utils/similarity.d.ts +11 -0
- package/dist/src/utils/similarity.d.ts.map +1 -0
- package/dist/src/utils/similarity.js +25 -0
- package/dist/src/utils/similarity.js.map +1 -0
- package/dist/src/utils/top-k.d.ts +44 -0
- package/dist/src/utils/top-k.d.ts.map +1 -0
- package/dist/src/utils/top-k.js +111 -0
- package/dist/src/utils/top-k.js.map +1 -0
- package/dist/src/wasm-loader.d.ts +66 -0
- package/dist/src/wasm-loader.d.ts.map +1 -0
- package/dist/src/wasm-loader.js +76 -0
- package/dist/src/wasm-loader.js.map +1 -0
- package/dist/src/wrappers/agentdb-fast.d.ts +140 -0
- package/dist/src/wrappers/agentdb-fast.d.ts.map +1 -0
- package/dist/src/wrappers/agentdb-fast.js +309 -0
- package/dist/src/wrappers/agentdb-fast.js.map +1 -0
- package/dist/src/wrappers/attention-fallbacks.d.ts +343 -0
- package/dist/src/wrappers/attention-fallbacks.d.ts.map +1 -0
- package/dist/src/wrappers/attention-fallbacks.js +1484 -0
- package/dist/src/wrappers/attention-fallbacks.js.map +1 -0
- package/dist/src/wrappers/attention-native.d.ts +111 -0
- package/dist/src/wrappers/attention-native.d.ts.map +1 -0
- package/dist/src/wrappers/attention-native.js +273 -0
- package/dist/src/wrappers/attention-native.js.map +1 -0
- package/dist/src/wrappers/embedding-service.d.ts +117 -0
- package/dist/src/wrappers/embedding-service.d.ts.map +1 -0
- package/dist/src/wrappers/embedding-service.js +370 -0
- package/dist/src/wrappers/embedding-service.js.map +1 -0
- package/dist/src/wrappers/gnn-wrapper.d.ts +71 -0
- package/dist/src/wrappers/gnn-wrapper.d.ts.map +1 -0
- package/dist/src/wrappers/gnn-wrapper.js +236 -0
- package/dist/src/wrappers/gnn-wrapper.js.map +1 -0
- package/dist/src/wrappers/index.d.ts +48 -0
- package/dist/src/wrappers/index.d.ts.map +1 -0
- package/dist/src/wrappers/index.js +83 -0
- package/dist/src/wrappers/index.js.map +1 -0
- package/package.json +130 -80
- package/scripts/postinstall.cjs +13 -144
- package/dist/agentdb.browser.js +0 -1685
- package/dist/agentdb.browser.js.map +0 -7
- package/dist/agentdb.browser.min.js +0 -3
- package/dist/agentdb.browser.min.js.map +0 -7
- package/dist/agentdb.wasm-loader.js +0 -207
- package/dist/backends/VectorBackend.d.ts +0 -120
- package/dist/backends/VectorBackend.js +0 -14
- package/dist/backends/VectorBackend.js.map +0 -1
- package/dist/optimizations/RVFOptimizer.d.ts +0 -225
- package/dist/optimizations/RVFOptimizer.js +0 -541
- package/dist/optimizations/RVFOptimizer.js.map +0 -1
- package/dist/simulation/cli.d.ts +0 -9
- package/dist/simulation/cli.d.ts.map +0 -1
- package/dist/simulation/cli.js +0 -68
- package/dist/simulation/cli.js.map +0 -1
- package/dist/simulation/runner.d.ts +0 -21
- package/dist/simulation/runner.d.ts.map +0 -1
- package/dist/simulation/runner.js +0 -241
- package/dist/simulation/runner.js.map +0 -1
- package/dist/simulation/scenarios/aidefence-integration.d.ts +0 -24
- package/dist/simulation/scenarios/aidefence-integration.d.ts.map +0 -1
- package/dist/simulation/scenarios/aidefence-integration.js +0 -124
- package/dist/simulation/scenarios/aidefence-integration.js.map +0 -1
- package/dist/simulation/scenarios/bmssp-integration.d.ts +0 -23
- package/dist/simulation/scenarios/bmssp-integration.d.ts.map +0 -1
- package/dist/simulation/scenarios/bmssp-integration.js +0 -104
- package/dist/simulation/scenarios/bmssp-integration.js.map +0 -1
- package/dist/simulation/scenarios/causal-reasoning.d.ts +0 -16
- package/dist/simulation/scenarios/causal-reasoning.d.ts.map +0 -1
- package/dist/simulation/scenarios/causal-reasoning.js +0 -108
- package/dist/simulation/scenarios/causal-reasoning.js.map +0 -1
- package/dist/simulation/scenarios/consciousness-explorer.d.ts +0 -25
- package/dist/simulation/scenarios/consciousness-explorer.d.ts.map +0 -1
- package/dist/simulation/scenarios/consciousness-explorer.js +0 -108
- package/dist/simulation/scenarios/consciousness-explorer.js.map +0 -1
- package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.d.ts +0 -135
- package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.d.ts.map +0 -1
- package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.js +0 -158
- package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.js.map +0 -1
- package/dist/simulation/scenarios/domain-examples/index.d.ts +0 -14
- package/dist/simulation/scenarios/domain-examples/index.d.ts.map +0 -1
- package/dist/simulation/scenarios/domain-examples/index.js +0 -14
- package/dist/simulation/scenarios/domain-examples/index.js.map +0 -1
- package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.d.ts +0 -178
- package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.d.ts.map +0 -1
- package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.js +0 -218
- package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.js.map +0 -1
- package/dist/simulation/scenarios/domain-examples/medical-imaging.d.ts +0 -122
- package/dist/simulation/scenarios/domain-examples/medical-imaging.d.ts.map +0 -1
- package/dist/simulation/scenarios/domain-examples/medical-imaging.js +0 -129
- package/dist/simulation/scenarios/domain-examples/medical-imaging.js.map +0 -1
- package/dist/simulation/scenarios/domain-examples/robotics-navigation.d.ts +0 -166
- package/dist/simulation/scenarios/domain-examples/robotics-navigation.d.ts.map +0 -1
- package/dist/simulation/scenarios/domain-examples/robotics-navigation.js +0 -161
- package/dist/simulation/scenarios/domain-examples/robotics-navigation.js.map +0 -1
- package/dist/simulation/scenarios/domain-examples/scientific-research.d.ts +0 -151
- package/dist/simulation/scenarios/domain-examples/scientific-research.d.ts.map +0 -1
- package/dist/simulation/scenarios/domain-examples/scientific-research.js +0 -187
- package/dist/simulation/scenarios/domain-examples/scientific-research.js.map +0 -1
- package/dist/simulation/scenarios/domain-examples/trading-systems.d.ts +0 -102
- package/dist/simulation/scenarios/domain-examples/trading-systems.d.ts.map +0 -1
- package/dist/simulation/scenarios/domain-examples/trading-systems.js +0 -100
- package/dist/simulation/scenarios/domain-examples/trading-systems.js.map +0 -1
- package/dist/simulation/scenarios/goalie-integration.d.ts +0 -24
- package/dist/simulation/scenarios/goalie-integration.d.ts.map +0 -1
- package/dist/simulation/scenarios/goalie-integration.js +0 -121
- package/dist/simulation/scenarios/goalie-integration.js.map +0 -1
- package/dist/simulation/scenarios/graph-traversal.d.ts +0 -17
- package/dist/simulation/scenarios/graph-traversal.d.ts.map +0 -1
- package/dist/simulation/scenarios/graph-traversal.js +0 -101
- package/dist/simulation/scenarios/graph-traversal.js.map +0 -1
- package/dist/simulation/scenarios/latent-space/attention-analysis.d.ts +0 -45
- package/dist/simulation/scenarios/latent-space/attention-analysis.d.ts.map +0 -1
- package/dist/simulation/scenarios/latent-space/attention-analysis.js +0 -435
- package/dist/simulation/scenarios/latent-space/attention-analysis.js.map +0 -1
- package/dist/simulation/scenarios/latent-space/clustering-analysis.d.ts +0 -55
- package/dist/simulation/scenarios/latent-space/clustering-analysis.d.ts.map +0 -1
- package/dist/simulation/scenarios/latent-space/clustering-analysis.js +0 -606
- package/dist/simulation/scenarios/latent-space/clustering-analysis.js.map +0 -1
- package/dist/simulation/scenarios/latent-space/hnsw-exploration.d.ts +0 -74
- package/dist/simulation/scenarios/latent-space/hnsw-exploration.d.ts.map +0 -1
- package/dist/simulation/scenarios/latent-space/hnsw-exploration.js +0 -391
- package/dist/simulation/scenarios/latent-space/hnsw-exploration.js.map +0 -1
- package/dist/simulation/scenarios/latent-space/hypergraph-exploration.d.ts +0 -51
- package/dist/simulation/scenarios/latent-space/hypergraph-exploration.d.ts.map +0 -1
- package/dist/simulation/scenarios/latent-space/hypergraph-exploration.js +0 -536
- package/dist/simulation/scenarios/latent-space/hypergraph-exploration.js.map +0 -1
- package/dist/simulation/scenarios/latent-space/index.d.ts +0 -35
- package/dist/simulation/scenarios/latent-space/index.d.ts.map +0 -1
- package/dist/simulation/scenarios/latent-space/index.js +0 -35
- package/dist/simulation/scenarios/latent-space/index.js.map +0 -1
- package/dist/simulation/scenarios/latent-space/neural-augmentation.d.ts +0 -52
- package/dist/simulation/scenarios/latent-space/neural-augmentation.d.ts.map +0 -1
- package/dist/simulation/scenarios/latent-space/neural-augmentation.js +0 -472
- package/dist/simulation/scenarios/latent-space/neural-augmentation.js.map +0 -1
- package/dist/simulation/scenarios/latent-space/quantum-hybrid.d.ts +0 -53
- package/dist/simulation/scenarios/latent-space/quantum-hybrid.d.ts.map +0 -1
- package/dist/simulation/scenarios/latent-space/quantum-hybrid.js +0 -391
- package/dist/simulation/scenarios/latent-space/quantum-hybrid.js.map +0 -1
- package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.d.ts +0 -52
- package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.d.ts.map +0 -1
- package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.js +0 -514
- package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.js.map +0 -1
- package/dist/simulation/scenarios/latent-space/traversal-optimization.d.ts +0 -53
- package/dist/simulation/scenarios/latent-space/traversal-optimization.d.ts.map +0 -1
- package/dist/simulation/scenarios/latent-space/traversal-optimization.js +0 -595
- package/dist/simulation/scenarios/latent-space/traversal-optimization.js.map +0 -1
- package/dist/simulation/scenarios/lean-agentic-swarm.d.ts +0 -18
- package/dist/simulation/scenarios/lean-agentic-swarm.d.ts.map +0 -1
- package/dist/simulation/scenarios/lean-agentic-swarm.js +0 -132
- package/dist/simulation/scenarios/lean-agentic-swarm.js.map +0 -1
- package/dist/simulation/scenarios/multi-agent-swarm.d.ts +0 -17
- package/dist/simulation/scenarios/multi-agent-swarm.d.ts.map +0 -1
- package/dist/simulation/scenarios/multi-agent-swarm.js +0 -111
- package/dist/simulation/scenarios/multi-agent-swarm.js.map +0 -1
- package/dist/simulation/scenarios/psycho-symbolic-reasoner.d.ts +0 -23
- package/dist/simulation/scenarios/psycho-symbolic-reasoner.d.ts.map +0 -1
- package/dist/simulation/scenarios/psycho-symbolic-reasoner.js +0 -98
- package/dist/simulation/scenarios/psycho-symbolic-reasoner.js.map +0 -1
- package/dist/simulation/scenarios/reflexion-learning.d.ts +0 -16
- package/dist/simulation/scenarios/reflexion-learning.d.ts.map +0 -1
- package/dist/simulation/scenarios/reflexion-learning.js +0 -98
- package/dist/simulation/scenarios/reflexion-learning.js.map +0 -1
- package/dist/simulation/scenarios/research-swarm.d.ts +0 -24
- package/dist/simulation/scenarios/research-swarm.d.ts.map +0 -1
- package/dist/simulation/scenarios/research-swarm.js +0 -146
- package/dist/simulation/scenarios/research-swarm.js.map +0 -1
- package/dist/simulation/scenarios/skill-evolution.d.ts +0 -16
- package/dist/simulation/scenarios/skill-evolution.d.ts.map +0 -1
- package/dist/simulation/scenarios/skill-evolution.js +0 -109
- package/dist/simulation/scenarios/skill-evolution.js.map +0 -1
- package/dist/simulation/scenarios/stock-market-emergence.d.ts +0 -33
- package/dist/simulation/scenarios/stock-market-emergence.d.ts.map +0 -1
- package/dist/simulation/scenarios/stock-market-emergence.js +0 -246
- package/dist/simulation/scenarios/stock-market-emergence.js.map +0 -1
- package/dist/simulation/scenarios/strange-loops.d.ts +0 -18
- package/dist/simulation/scenarios/strange-loops.d.ts.map +0 -1
- package/dist/simulation/scenarios/strange-loops.js +0 -133
- package/dist/simulation/scenarios/strange-loops.js.map +0 -1
- package/dist/simulation/scenarios/sublinear-solver.d.ts +0 -22
- package/dist/simulation/scenarios/sublinear-solver.d.ts.map +0 -1
- package/dist/simulation/scenarios/sublinear-solver.js +0 -82
- package/dist/simulation/scenarios/sublinear-solver.js.map +0 -1
- package/dist/simulation/scenarios/temporal-lead-solver.d.ts +0 -23
- package/dist/simulation/scenarios/temporal-lead-solver.d.ts.map +0 -1
- package/dist/simulation/scenarios/temporal-lead-solver.js +0 -90
- package/dist/simulation/scenarios/temporal-lead-solver.js.map +0 -1
- package/dist/simulation/scenarios/voting-system-consensus.d.ts +0 -27
- package/dist/simulation/scenarios/voting-system-consensus.d.ts.map +0 -1
- package/dist/simulation/scenarios/voting-system-consensus.js +0 -175
- package/dist/simulation/scenarios/voting-system-consensus.js.map +0 -1
- package/dist/simulation/types.d.ts +0 -162
- package/dist/simulation/types.d.ts.map +0 -1
- package/dist/simulation/types.js +0 -5
- package/dist/simulation/types.js.map +0 -1
- package/dist/simulation/utils/PerformanceOptimizer.d.ts +0 -115
- package/dist/simulation/utils/PerformanceOptimizer.d.ts.map +0 -1
- package/dist/simulation/utils/PerformanceOptimizer.js +0 -223
- package/dist/simulation/utils/PerformanceOptimizer.js.map +0 -1
- package/dist/src/backends/index.cjs +0 -6
- package/dist/src/backends/ruvector/GuardedVectorBackend.d.ts +0 -93
- package/dist/src/backends/ruvector/GuardedVectorBackend.d.ts.map +0 -1
- package/dist/src/backends/ruvector/GuardedVectorBackend.js +0 -182
- package/dist/src/backends/ruvector/GuardedVectorBackend.js.map +0 -1
- package/dist/src/consensus/RaftConsensus.d.ts +0 -220
- package/dist/src/consensus/RaftConsensus.d.ts.map +0 -1
- package/dist/src/consensus/RaftConsensus.js +0 -762
- package/dist/src/consensus/RaftConsensus.js.map +0 -1
- package/dist/src/controllers/HierarchicalMemory.d.ts +0 -197
- package/dist/src/controllers/HierarchicalMemory.d.ts.map +0 -1
- package/dist/src/controllers/HierarchicalMemory.js +0 -519
- package/dist/src/controllers/HierarchicalMemory.js.map +0 -1
- package/dist/src/controllers/MemoryConsolidation.d.ts +0 -142
- package/dist/src/controllers/MemoryConsolidation.d.ts.map +0 -1
- package/dist/src/controllers/MemoryConsolidation.js +0 -479
- package/dist/src/controllers/MemoryConsolidation.js.map +0 -1
- package/dist/src/controllers/QUICConnection.d.ts +0 -122
- package/dist/src/controllers/QUICConnection.d.ts.map +0 -1
- package/dist/src/controllers/QUICConnection.js +0 -329
- package/dist/src/controllers/QUICConnection.js.map +0 -1
- package/dist/src/controllers/QUICConnectionPool.d.ts +0 -83
- package/dist/src/controllers/QUICConnectionPool.d.ts.map +0 -1
- package/dist/src/controllers/QUICConnectionPool.js +0 -256
- package/dist/src/controllers/QUICConnectionPool.js.map +0 -1
- package/dist/src/controllers/QUICStreamManager.d.ts +0 -114
- package/dist/src/controllers/QUICStreamManager.d.ts.map +0 -1
- package/dist/src/controllers/QUICStreamManager.js +0 -267
- package/dist/src/controllers/QUICStreamManager.js.map +0 -1
- package/dist/src/controllers/StreamingEmbeddingService.d.ts +0 -82
- package/dist/src/controllers/StreamingEmbeddingService.d.ts.map +0 -1
- package/dist/src/controllers/StreamingEmbeddingService.js +0 -243
- package/dist/src/controllers/StreamingEmbeddingService.js.map +0 -1
- package/dist/src/controllers/index.cjs +0 -6
- package/dist/src/coordination/MultiDatabaseCoordinator.d.ts +0 -348
- package/dist/src/coordination/MultiDatabaseCoordinator.d.ts.map +0 -1
- package/dist/src/coordination/MultiDatabaseCoordinator.js +0 -803
- package/dist/src/coordination/MultiDatabaseCoordinator.js.map +0 -1
- package/dist/src/coordination/index.d.ts +0 -10
- package/dist/src/coordination/index.d.ts.map +0 -1
- package/dist/src/coordination/index.js +0 -10
- package/dist/src/coordination/index.js.map +0 -1
- package/dist/src/index.cjs +0 -6
- package/dist/src/optimizations/RVFOptimizer.d.ts +0 -226
- package/dist/src/optimizations/RVFOptimizer.d.ts.map +0 -1
- package/dist/src/optimizations/RVFOptimizer.js +0 -541
- package/dist/src/optimizations/RVFOptimizer.js.map +0 -1
- package/dist/src/security/AttestationLog.d.ts +0 -70
- package/dist/src/security/AttestationLog.d.ts.map +0 -1
- package/dist/src/security/AttestationLog.js +0 -174
- package/dist/src/security/AttestationLog.js.map +0 -1
- package/dist/src/security/MutationGuard.d.ts +0 -83
- package/dist/src/security/MutationGuard.d.ts.map +0 -1
- package/dist/src/security/MutationGuard.js +0 -364
- package/dist/src/security/MutationGuard.js.map +0 -1
- package/dist/src/security/index.cjs +0 -6
- package/dist/src/security/index.d.ts +0 -15
- package/dist/src/security/index.d.ts.map +0 -1
- package/dist/src/security/index.js +0 -18
- package/dist/src/security/index.js.map +0 -1
- package/dist/src/services/GNNService.d.ts +0 -172
- package/dist/src/services/GNNService.d.ts.map +0 -1
- package/dist/src/services/GNNService.js +0 -612
- package/dist/src/services/GNNService.js.map +0 -1
- package/dist/src/services/GraphTransformerService.d.ts +0 -80
- package/dist/src/services/GraphTransformerService.d.ts.map +0 -1
- package/dist/src/services/GraphTransformerService.js +0 -369
- package/dist/src/services/GraphTransformerService.js.map +0 -1
- package/dist/src/services/SemanticRouter.d.ts +0 -83
- package/dist/src/services/SemanticRouter.d.ts.map +0 -1
- package/dist/src/services/SemanticRouter.js +0 -160
- package/dist/src/services/SemanticRouter.js.map +0 -1
- package/dist/src/services/SonaTrajectoryService.d.ts +0 -224
- package/dist/src/services/SonaTrajectoryService.d.ts.map +0 -1
- package/dist/src/services/SonaTrajectoryService.js +0 -539
- package/dist/src/services/SonaTrajectoryService.js.map +0 -1
- package/dist/src/utils/LegacyAttentionAdapter.d.ts +0 -93
- package/dist/src/utils/LegacyAttentionAdapter.d.ts.map +0 -1
- package/dist/src/utils/LegacyAttentionAdapter.js +0 -241
- package/dist/src/utils/LegacyAttentionAdapter.js.map +0 -1
- package/dist/src/utils/vector-math.d.ts +0 -29
- package/dist/src/utils/vector-math.d.ts.map +0 -1
- package/dist/src/utils/vector-math.js +0 -66
- package/dist/src/utils/vector-math.js.map +0 -1
package/dist/src/db-fallback.js
CHANGED
|
@@ -1,68 +1,270 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Database System
|
|
3
|
-
*
|
|
2
|
+
* Database System backed by SQLite.
|
|
3
|
+
*
|
|
4
|
+
* Resolution order (ruflo #2235 A):
|
|
5
|
+
* 1. **better-sqlite3** if the optional peer is loadable — native, faster,
|
|
6
|
+
* what most callers actually want when they install the native module.
|
|
7
|
+
* 2. **sql.js** (WASM) — pure-JS fallback, requires no build tools.
|
|
8
|
+
*
|
|
9
|
+
* Both implementations expose the same `db.prepare(sql).run/get/all(...)`
|
|
10
|
+
* interface (the sql.js wrapper below was designed to mimic better-sqlite3),
|
|
11
|
+
* so callers don't care which one served them.
|
|
4
12
|
*
|
|
5
13
|
* SECURITY: Fixed SQL injection vulnerabilities:
|
|
6
14
|
* - PRAGMA commands validated against whitelist
|
|
7
15
|
* - Removed eval() usage (replaced with async import)
|
|
8
16
|
*/
|
|
9
17
|
import { validatePragmaCommand, ValidationError } from './security/input-validation.js';
|
|
18
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
10
19
|
import * as fs from 'fs';
|
|
11
20
|
import * as path from 'path';
|
|
12
|
-
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- cached impl (better-sqlite3 class or sql.js wrapper class)
|
|
22
|
+
let cachedImpl = null;
|
|
23
|
+
let cachedImplKind = null;
|
|
24
|
+
export class SqlJsConcurrentModificationError extends Error {
|
|
25
|
+
code = 'AGENTDB_SQLJS_CONCURRENT_MODIFICATION';
|
|
26
|
+
constructor(filename) {
|
|
27
|
+
super(`Refusing to overwrite "${filename}" because it changed after this sql.js instance opened. ` +
|
|
28
|
+
'Another process may have written to the database; reopen it before retrying.');
|
|
29
|
+
this.name = 'SqlJsConcurrentModificationError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function fingerprintFile(filename) {
|
|
33
|
+
let fd;
|
|
34
|
+
try {
|
|
35
|
+
fd = fs.openSync(filename, 'r');
|
|
36
|
+
const before = fs.fstatSync(fd);
|
|
37
|
+
const data = fs.readFileSync(fd);
|
|
38
|
+
const after = fs.fstatSync(fd);
|
|
39
|
+
if (before.dev !== after.dev ||
|
|
40
|
+
before.ino !== after.ino ||
|
|
41
|
+
before.size !== after.size ||
|
|
42
|
+
before.mtimeMs !== after.mtimeMs ||
|
|
43
|
+
before.ctimeMs !== after.ctimeMs) {
|
|
44
|
+
throw new SqlJsConcurrentModificationError(filename);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
exists: true,
|
|
48
|
+
device: after.dev,
|
|
49
|
+
inode: after.ino,
|
|
50
|
+
mode: after.mode,
|
|
51
|
+
size: after.size,
|
|
52
|
+
mtimeMs: after.mtimeMs,
|
|
53
|
+
ctimeMs: after.ctimeMs,
|
|
54
|
+
sha256: createHash('sha256').update(data).digest('hex'),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error.code === 'ENOENT')
|
|
59
|
+
return { exists: false };
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
if (fd !== undefined)
|
|
64
|
+
fs.closeSync(fd);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function captureDatabaseFileState(filename) {
|
|
68
|
+
return {
|
|
69
|
+
database: fingerprintFile(filename),
|
|
70
|
+
wal: fingerprintFile(`${filename}-wal`),
|
|
71
|
+
shm: fingerprintFile(`${filename}-shm`),
|
|
72
|
+
journal: fingerprintFile(`${filename}-journal`),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export function loadSqlJsDatabaseFile(filename) {
|
|
76
|
+
const state = captureDatabaseFileState(filename);
|
|
77
|
+
if ((state.wal.exists && state.wal.size > 0) ||
|
|
78
|
+
(state.journal.exists && state.journal.size > 0)) {
|
|
79
|
+
throw new Error(`Refusing to open "${filename}" with sql.js while an active SQLite WAL or journal exists. ` +
|
|
80
|
+
'Checkpoint/close the other SQLite writer first.');
|
|
81
|
+
}
|
|
82
|
+
if (!state.database.exists)
|
|
83
|
+
return { data: null, state };
|
|
84
|
+
// fingerprintFile hashes the exact bytes read from a stable descriptor.
|
|
85
|
+
// Read once more and verify the digest so the returned bytes and baseline
|
|
86
|
+
// are guaranteed to describe the same database generation.
|
|
87
|
+
const data = fs.readFileSync(filename);
|
|
88
|
+
const digest = createHash('sha256').update(data).digest('hex');
|
|
89
|
+
if (digest !== state.database.sha256) {
|
|
90
|
+
throw new SqlJsConcurrentModificationError(filename);
|
|
91
|
+
}
|
|
92
|
+
if (data.length < 16 ||
|
|
93
|
+
data.subarray(0, 16).toString('utf8') !== 'SQLite format 3\u0000') {
|
|
94
|
+
throw new Error(`Refusing to open invalid SQLite database file "${filename}"`);
|
|
95
|
+
}
|
|
96
|
+
return { data: new Uint8Array(data), state };
|
|
97
|
+
}
|
|
98
|
+
function sameDatabaseFileState(left, right) {
|
|
99
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
100
|
+
}
|
|
101
|
+
function fsyncDirectory(directory) {
|
|
102
|
+
let fd;
|
|
103
|
+
try {
|
|
104
|
+
fd = fs.openSync(directory, 'r');
|
|
105
|
+
fs.fsyncSync(fd);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
// Some platforms/filesystems do not permit opening or syncing directories.
|
|
109
|
+
const code = error.code;
|
|
110
|
+
if (code !== 'EINVAL' && code !== 'EPERM' && code !== 'EISDIR')
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
if (fd !== undefined)
|
|
115
|
+
fs.closeSync(fd);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export function persistSqlJsDatabase(filename, data, expectedState) {
|
|
119
|
+
const directory = path.dirname(filename);
|
|
120
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
121
|
+
if (fs.existsSync(filename) && fs.lstatSync(filename).isSymbolicLink()) {
|
|
122
|
+
throw new Error(`Refusing to replace symbolic-link database path "${filename}"`);
|
|
123
|
+
}
|
|
124
|
+
const lockPath = `${filename}.agentdb.lock`;
|
|
125
|
+
let lockFd;
|
|
126
|
+
let tempPath;
|
|
127
|
+
try {
|
|
128
|
+
try {
|
|
129
|
+
lockFd = fs.openSync(lockPath, 'wx', 0o600);
|
|
130
|
+
fs.writeSync(lockFd, `${process.pid}\n`);
|
|
131
|
+
fs.fsyncSync(lockFd);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (error.code === 'EEXIST') {
|
|
135
|
+
throw new SqlJsConcurrentModificationError(filename);
|
|
136
|
+
}
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
if (!sameDatabaseFileState(captureDatabaseFileState(filename), expectedState)) {
|
|
140
|
+
throw new SqlJsConcurrentModificationError(filename);
|
|
141
|
+
}
|
|
142
|
+
tempPath = path.join(directory, `.${path.basename(filename)}.${process.pid}.${randomUUID()}.tmp`);
|
|
143
|
+
const tempFd = fs.openSync(tempPath, 'wx', 0o600);
|
|
144
|
+
try {
|
|
145
|
+
fs.writeFileSync(tempFd, Buffer.from(data));
|
|
146
|
+
if (expectedState.database.exists && expectedState.database.mode !== undefined) {
|
|
147
|
+
fs.fchmodSync(tempFd, expectedState.database.mode);
|
|
148
|
+
}
|
|
149
|
+
fs.fsyncSync(tempFd);
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
fs.closeSync(tempFd);
|
|
153
|
+
}
|
|
154
|
+
// Recheck after export/write so a non-cooperating SQLite writer cannot be
|
|
155
|
+
// silently overwritten merely because it raced with the temporary write.
|
|
156
|
+
if (!sameDatabaseFileState(captureDatabaseFileState(filename), expectedState)) {
|
|
157
|
+
throw new SqlJsConcurrentModificationError(filename);
|
|
158
|
+
}
|
|
159
|
+
fs.renameSync(tempPath, filename);
|
|
160
|
+
tempPath = undefined;
|
|
161
|
+
fsyncDirectory(directory);
|
|
162
|
+
return captureDatabaseFileState(filename);
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
if (tempPath) {
|
|
166
|
+
try {
|
|
167
|
+
fs.unlinkSync(tempPath);
|
|
168
|
+
}
|
|
169
|
+
catch { /* best-effort cleanup */ }
|
|
170
|
+
}
|
|
171
|
+
if (lockFd !== undefined) {
|
|
172
|
+
fs.closeSync(lockFd);
|
|
173
|
+
try {
|
|
174
|
+
fs.unlinkSync(lockPath);
|
|
175
|
+
}
|
|
176
|
+
catch { /* preserve the original error */ }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
13
180
|
/**
|
|
14
|
-
* Get
|
|
181
|
+
* Get the SQLite database implementation. Prefers native `better-sqlite3`
|
|
182
|
+
* when loadable; falls back to WASM `sql.js` (no build tools required).
|
|
15
183
|
*/
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- returns dynamically constructed class
|
|
16
185
|
export async function getDatabaseImplementation() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
186
|
+
if (cachedImpl)
|
|
187
|
+
return cachedImpl;
|
|
188
|
+
// 1. Try native better-sqlite3 (optional peer; same prepare/run API).
|
|
189
|
+
if (!process.env.AGENTDB_FORCE_SQLJS) {
|
|
190
|
+
try {
|
|
191
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic optional import
|
|
192
|
+
const mod = await import('better-sqlite3');
|
|
193
|
+
const BetterSqlite3 = mod.default ?? mod;
|
|
194
|
+
if (typeof BetterSqlite3 === 'function') {
|
|
195
|
+
// Importing the JS wrapper can succeed even when its native binding is
|
|
196
|
+
// missing or incompatible with the current Node ABI. Probe an actual
|
|
197
|
+
// in-memory connection before selecting it.
|
|
198
|
+
const probe = new BetterSqlite3(':memory:');
|
|
199
|
+
probe.close();
|
|
200
|
+
cachedImpl = BetterSqlite3;
|
|
201
|
+
cachedImplKind = 'better-sqlite3';
|
|
202
|
+
console.error('✅ Using native better-sqlite3');
|
|
203
|
+
return cachedImpl;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
// Not installed or failed to load → fall through to sql.js.
|
|
208
|
+
}
|
|
20
209
|
}
|
|
210
|
+
// 2. Fall back to sql.js (WASM, no build tools).
|
|
21
211
|
try {
|
|
22
|
-
console.
|
|
212
|
+
console.error('✅ Using sql.js (WASM SQLite, no build tools required)');
|
|
23
213
|
// sql.js requires async initialization
|
|
24
214
|
const mod = await import('sql.js');
|
|
25
215
|
const SQL = await mod.default();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return
|
|
216
|
+
cachedImpl = createSqlJsWrapper(SQL);
|
|
217
|
+
cachedImplKind = 'sql.js';
|
|
218
|
+
return cachedImpl;
|
|
29
219
|
}
|
|
30
220
|
catch (error) {
|
|
31
221
|
console.error('❌ Failed to initialize sql.js:', error.message);
|
|
32
|
-
throw new Error('Failed to initialize SQLite.
|
|
33
|
-
'npm install
|
|
222
|
+
throw new Error('Failed to initialize SQLite. Install one of:\n' +
|
|
223
|
+
' npm install better-sqlite3 # native, faster (recommended)\n' +
|
|
224
|
+
' npm install sql.js # pure-JS fallback, no build tools');
|
|
34
225
|
}
|
|
35
226
|
}
|
|
227
|
+
/** Reset the cached implementation (intended for tests). */
|
|
228
|
+
export function _resetDatabaseImplementationForTests() {
|
|
229
|
+
cachedImpl = null;
|
|
230
|
+
cachedImplKind = null;
|
|
231
|
+
}
|
|
36
232
|
/**
|
|
37
233
|
* Create a better-sqlite3 compatible wrapper around sql.js
|
|
38
234
|
* This allows AgentDB to work (with reduced performance) without native compilation
|
|
39
235
|
*/
|
|
236
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- sql.js SQL factory type
|
|
40
237
|
function createSqlJsWrapper(SQL) {
|
|
41
238
|
return class SqlJsDatabase {
|
|
239
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- sql.js Database instance
|
|
42
240
|
db;
|
|
43
241
|
filename;
|
|
242
|
+
fileState;
|
|
243
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- sql.js Statement instances
|
|
44
244
|
activeStatements = new Map();
|
|
245
|
+
// Cache wrappers by SQL text so repeated db.prepare(sameSql) returns the
|
|
246
|
+
// same underlying sql.js Statement and doesn't add a new entry to
|
|
247
|
+
// activeStatements. Without this, callers using the
|
|
248
|
+
// db.prepare(sql).run(...)-and-discard pattern (idiomatic in
|
|
249
|
+
// better-sqlite3, where V8 GCs the handle) leak forever under sql.js.
|
|
250
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- prepared-statement wrapper objects
|
|
251
|
+
statementCache = new Map();
|
|
45
252
|
statementCounter = 0;
|
|
46
253
|
intervalId = null;
|
|
47
|
-
constructor(filename,
|
|
254
|
+
constructor(filename, _options) {
|
|
48
255
|
this.filename = filename;
|
|
256
|
+
const loaded = filename === ':memory:' ? null : loadSqlJsDatabaseFile(filename);
|
|
257
|
+
this.fileState = loaded?.state ?? null;
|
|
49
258
|
// In-memory database
|
|
50
259
|
if (filename === ':memory:') {
|
|
51
260
|
this.db = new SQL.Database();
|
|
52
261
|
}
|
|
53
262
|
else {
|
|
54
263
|
// File-based database - use safe fs module (no eval)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const buffer = fs.readFileSync(filename);
|
|
58
|
-
this.db = new SQL.Database(buffer);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
this.db = new SQL.Database();
|
|
62
|
-
}
|
|
264
|
+
if (loaded.data) {
|
|
265
|
+
this.db = new SQL.Database(loaded.data);
|
|
63
266
|
}
|
|
64
|
-
|
|
65
|
-
console.warn('⚠️ Could not read database file:', error.message);
|
|
267
|
+
else {
|
|
66
268
|
this.db = new SQL.Database();
|
|
67
269
|
}
|
|
68
270
|
}
|
|
@@ -72,19 +274,54 @@ function createSqlJsWrapper(SQL) {
|
|
|
72
274
|
console.warn(`⚠️ Detected ${this.activeStatements.size} active SQL statements - possible memory leak`);
|
|
73
275
|
}
|
|
74
276
|
}, 10000);
|
|
277
|
+
// Diagnostic only: must not keep a process alive that never calls close()
|
|
278
|
+
this.intervalId.unref?.();
|
|
75
279
|
}
|
|
76
280
|
prepare(sql) {
|
|
77
|
-
|
|
281
|
+
// Reuse the cached wrapper for an identical SQL string. The cache owns
|
|
282
|
+
// the underlying stmt's lifetime; finalize() is a no-op on a cached
|
|
283
|
+
// wrapper so concurrent callers that all called prepare(sql) keep
|
|
284
|
+
// working. close() drops everything.
|
|
285
|
+
const cached = this.statementCache.get(sql);
|
|
286
|
+
if (cached)
|
|
287
|
+
return cached;
|
|
288
|
+
let stmt = this.db.prepare(sql);
|
|
78
289
|
let isFinalized = false;
|
|
79
290
|
const stmtId = ++this.statementCounter;
|
|
291
|
+
const self = this;
|
|
292
|
+
// sql.js frees every prepared statement on export() (save(), or another
|
|
293
|
+
// wrapper of the same database), after which bind() throws the string
|
|
294
|
+
// "Statement closed". Re-prepare once instead of failing the call.
|
|
295
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- sql.js bind accepts heterogeneous params
|
|
296
|
+
const bindLive = (params) => {
|
|
297
|
+
try {
|
|
298
|
+
stmt.bind(params);
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
if (error !== SQLJS_STATEMENT_CLOSED)
|
|
302
|
+
throw error;
|
|
303
|
+
stmt = self.db.prepare(sql);
|
|
304
|
+
self.activeStatements.set(stmtId, stmt);
|
|
305
|
+
stmt.bind(params);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
80
308
|
// Track active statement
|
|
81
309
|
this.activeStatements.set(stmtId, stmt);
|
|
82
|
-
|
|
310
|
+
const evictOnError = () => {
|
|
311
|
+
if (!isFinalized) {
|
|
312
|
+
stmt.free();
|
|
313
|
+
isFinalized = true;
|
|
314
|
+
self.activeStatements.delete(stmtId);
|
|
315
|
+
self.statementCache.delete(sql);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
const wrapper = {
|
|
319
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- sql.js bind accepts heterogeneous params
|
|
83
320
|
run: (...params) => {
|
|
84
321
|
if (isFinalized)
|
|
85
322
|
throw new Error('Statement already finalized');
|
|
86
323
|
try {
|
|
87
|
-
|
|
324
|
+
bindLive(params);
|
|
88
325
|
stmt.step();
|
|
89
326
|
stmt.reset();
|
|
90
327
|
return {
|
|
@@ -93,20 +330,16 @@ function createSqlJsWrapper(SQL) {
|
|
|
93
330
|
};
|
|
94
331
|
}
|
|
95
332
|
catch (error) {
|
|
96
|
-
|
|
97
|
-
if (!isFinalized) {
|
|
98
|
-
stmt.free();
|
|
99
|
-
isFinalized = true;
|
|
100
|
-
this.activeStatements.delete(stmtId);
|
|
101
|
-
}
|
|
333
|
+
evictOnError();
|
|
102
334
|
throw error;
|
|
103
335
|
}
|
|
104
336
|
},
|
|
337
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- sql.js bind accepts heterogeneous params
|
|
105
338
|
get: (...params) => {
|
|
106
339
|
if (isFinalized)
|
|
107
340
|
throw new Error('Statement already finalized');
|
|
108
341
|
try {
|
|
109
|
-
|
|
342
|
+
bindLive(params);
|
|
110
343
|
const hasRow = stmt.step();
|
|
111
344
|
if (!hasRow) {
|
|
112
345
|
stmt.reset();
|
|
@@ -122,51 +355,45 @@ function createSqlJsWrapper(SQL) {
|
|
|
122
355
|
return result;
|
|
123
356
|
}
|
|
124
357
|
catch (error) {
|
|
125
|
-
|
|
126
|
-
if (!isFinalized) {
|
|
127
|
-
stmt.free();
|
|
128
|
-
isFinalized = true;
|
|
129
|
-
this.activeStatements.delete(stmtId);
|
|
130
|
-
}
|
|
358
|
+
evictOnError();
|
|
131
359
|
throw error;
|
|
132
360
|
}
|
|
133
361
|
},
|
|
362
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- sql.js bind accepts heterogeneous params
|
|
134
363
|
all: (...params) => {
|
|
135
364
|
if (isFinalized)
|
|
136
365
|
throw new Error('Statement already finalized');
|
|
137
366
|
try {
|
|
138
|
-
|
|
367
|
+
bindLive(params);
|
|
139
368
|
const results = [];
|
|
369
|
+
// Column names are fixed for one execution; read them once, not per row
|
|
370
|
+
let columns = null;
|
|
140
371
|
while (stmt.step()) {
|
|
141
|
-
|
|
372
|
+
if (!columns)
|
|
373
|
+
columns = stmt.getColumnNames();
|
|
142
374
|
const values = stmt.get();
|
|
143
375
|
const result = {};
|
|
144
|
-
columns.
|
|
145
|
-
result[
|
|
146
|
-
}
|
|
376
|
+
for (let idx = 0; idx < columns.length; idx++) {
|
|
377
|
+
result[columns[idx]] = values[idx];
|
|
378
|
+
}
|
|
147
379
|
results.push(result);
|
|
148
380
|
}
|
|
149
381
|
stmt.reset();
|
|
150
382
|
return results;
|
|
151
383
|
}
|
|
152
384
|
catch (error) {
|
|
153
|
-
|
|
154
|
-
if (!isFinalized) {
|
|
155
|
-
stmt.free();
|
|
156
|
-
isFinalized = true;
|
|
157
|
-
this.activeStatements.delete(stmtId);
|
|
158
|
-
}
|
|
385
|
+
evictOnError();
|
|
159
386
|
throw error;
|
|
160
387
|
}
|
|
161
388
|
},
|
|
162
389
|
finalize: () => {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
this.activeStatements.delete(stmtId);
|
|
167
|
-
}
|
|
390
|
+
// No-op while cached: the wrapper is shared and finalize() must not
|
|
391
|
+
// tear out a stmt another caller is about to use. close() handles
|
|
392
|
+
// the real teardown.
|
|
168
393
|
}
|
|
169
394
|
};
|
|
395
|
+
this.statementCache.set(sql, wrapper);
|
|
396
|
+
return wrapper;
|
|
170
397
|
}
|
|
171
398
|
exec(sql) {
|
|
172
399
|
return this.db.exec(sql);
|
|
@@ -175,13 +402,8 @@ function createSqlJsWrapper(SQL) {
|
|
|
175
402
|
// Save to file if needed
|
|
176
403
|
if (this.filename !== ':memory:') {
|
|
177
404
|
try {
|
|
178
|
-
// Create parent directories if they don't exist
|
|
179
|
-
const dir = path.dirname(this.filename);
|
|
180
|
-
if (!fs.existsSync(dir)) {
|
|
181
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
182
|
-
}
|
|
183
405
|
const data = this.db.export();
|
|
184
|
-
|
|
406
|
+
this.fileState = persistSqlJsDatabase(this.filename, data, this.fileState);
|
|
185
407
|
}
|
|
186
408
|
catch (error) {
|
|
187
409
|
console.error('❌ Could not save database to file:', error.message);
|
|
@@ -190,32 +412,38 @@ function createSqlJsWrapper(SQL) {
|
|
|
190
412
|
}
|
|
191
413
|
}
|
|
192
414
|
close() {
|
|
415
|
+
let saveError;
|
|
416
|
+
try {
|
|
417
|
+
this.save();
|
|
418
|
+
}
|
|
419
|
+
catch (error) {
|
|
420
|
+
saveError = error;
|
|
421
|
+
}
|
|
193
422
|
// Clear interval timer
|
|
194
423
|
if (this.intervalId) {
|
|
195
424
|
clearInterval(this.intervalId);
|
|
196
425
|
this.intervalId = null;
|
|
197
426
|
}
|
|
198
427
|
// Free all active statements to prevent memory leaks
|
|
199
|
-
for (const [
|
|
428
|
+
for (const [, stmt] of this.activeStatements.entries()) {
|
|
200
429
|
try {
|
|
201
430
|
stmt.free();
|
|
202
431
|
}
|
|
203
|
-
catch
|
|
432
|
+
catch {
|
|
204
433
|
// Statement may already be freed
|
|
205
434
|
}
|
|
206
435
|
}
|
|
207
436
|
this.activeStatements.clear();
|
|
208
|
-
|
|
209
|
-
this.save();
|
|
437
|
+
this.statementCache.clear();
|
|
210
438
|
this.db.close();
|
|
439
|
+
if (saveError)
|
|
440
|
+
throw saveError;
|
|
211
441
|
}
|
|
212
|
-
pragma(pragma,
|
|
442
|
+
pragma(pragma, _options) {
|
|
213
443
|
try {
|
|
214
444
|
// SECURITY: Validate PRAGMA command against whitelist to prevent SQL injection
|
|
215
445
|
const validatedPragma = validatePragmaCommand(pragma);
|
|
216
|
-
|
|
217
|
-
const result = this.db.exec(`PRAGMA ${validatedPragma}`);
|
|
218
|
-
return result[0]?.values[0]?.[0];
|
|
446
|
+
return runPragma(this.db, validatedPragma);
|
|
219
447
|
}
|
|
220
448
|
catch (error) {
|
|
221
449
|
if (error instanceof ValidationError) {
|
|
@@ -243,22 +471,244 @@ function createSqlJsWrapper(SQL) {
|
|
|
243
471
|
}
|
|
244
472
|
};
|
|
245
473
|
}
|
|
474
|
+
/** What sql.js throws (a string, not an Error) when using a freed statement */
|
|
475
|
+
export const SQLJS_STATEMENT_CLOSED = 'Statement closed';
|
|
476
|
+
/**
|
|
477
|
+
* Run one validated PRAGMA as a single prepared statement (exec() would run
|
|
478
|
+
* any stacked statements). table_info(...) returns its rows, like
|
|
479
|
+
* better-sqlite3; other pragmas return the first value.
|
|
480
|
+
*/
|
|
481
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- sql.js raw database
|
|
482
|
+
function runPragma(rawDb, validatedPragma) {
|
|
483
|
+
const stmt = rawDb.prepare(`PRAGMA ${validatedPragma}`);
|
|
484
|
+
try {
|
|
485
|
+
if (/^table_info\(/i.test(validatedPragma)) {
|
|
486
|
+
const rows = [];
|
|
487
|
+
while (stmt.step())
|
|
488
|
+
rows.push(stmt.getAsObject());
|
|
489
|
+
return rows;
|
|
490
|
+
}
|
|
491
|
+
return stmt.step() ? stmt.get()[0] : undefined;
|
|
492
|
+
}
|
|
493
|
+
finally {
|
|
494
|
+
stmt.free();
|
|
495
|
+
}
|
|
496
|
+
}
|
|
246
497
|
/**
|
|
247
498
|
* Create a database instance using sql.js
|
|
248
499
|
*/
|
|
500
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- returns dynamically constructed SqlJsDatabase
|
|
249
501
|
export async function createDatabase(filename, options) {
|
|
250
502
|
const DatabaseImpl = await getDatabaseImplementation();
|
|
251
503
|
return new DatabaseImpl(filename, options);
|
|
252
504
|
}
|
|
505
|
+
/**
|
|
506
|
+
* Wrap an EXISTING sql.js raw database with the better-sqlite3-compatible API.
|
|
507
|
+
* Used by AgentDB unified mode to share one sql.js Database instance for both
|
|
508
|
+
* vector (rvf) and relational tables in a single .rvf file.
|
|
509
|
+
*
|
|
510
|
+
* Unlike createDatabase(), this does NOT create a new SQL.Database — it wraps
|
|
511
|
+
* the one already held by SqlJsRvfBackend.
|
|
512
|
+
*/
|
|
513
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- sql.js raw database and returned wrapper
|
|
514
|
+
export function wrapExistingSqlJsDatabase(rawDb, filename = ':memory:') {
|
|
515
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- sql.js Statement instances
|
|
516
|
+
const activeStatements = new Map();
|
|
517
|
+
// SQL-text cache; see SqlJsDatabase.statementCache for rationale.
|
|
518
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- prepared-statement wrapper objects
|
|
519
|
+
const statementCache = new Map();
|
|
520
|
+
let statementCounter = 0;
|
|
521
|
+
const loaded = filename === ':memory:' ? null : loadSqlJsDatabaseFile(filename);
|
|
522
|
+
let fileState = loaded?.state ?? null;
|
|
523
|
+
if (loaded?.data) {
|
|
524
|
+
const rawDigest = createHash('sha256').update(rawDb.export()).digest('hex');
|
|
525
|
+
if (rawDigest !== fileState.database.sha256) {
|
|
526
|
+
throw new SqlJsConcurrentModificationError(filename);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return {
|
|
530
|
+
prepare(sql) {
|
|
531
|
+
const cached = statementCache.get(sql);
|
|
532
|
+
if (cached)
|
|
533
|
+
return cached;
|
|
534
|
+
let stmt = rawDb.prepare(sql);
|
|
535
|
+
let isFinalized = false;
|
|
536
|
+
const stmtId = ++statementCounter;
|
|
537
|
+
activeStatements.set(stmtId, stmt);
|
|
538
|
+
// See SqlJsDatabase.prepare: re-prepare after sql.js freed the statement
|
|
539
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- sql.js bind accepts heterogeneous params
|
|
540
|
+
const bindLive = (params) => {
|
|
541
|
+
try {
|
|
542
|
+
stmt.bind(params);
|
|
543
|
+
}
|
|
544
|
+
catch (error) {
|
|
545
|
+
if (error !== SQLJS_STATEMENT_CLOSED)
|
|
546
|
+
throw error;
|
|
547
|
+
stmt = rawDb.prepare(sql);
|
|
548
|
+
activeStatements.set(stmtId, stmt);
|
|
549
|
+
stmt.bind(params);
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
const evictOnError = () => {
|
|
553
|
+
if (!isFinalized) {
|
|
554
|
+
stmt.free();
|
|
555
|
+
isFinalized = true;
|
|
556
|
+
activeStatements.delete(stmtId);
|
|
557
|
+
statementCache.delete(sql);
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
const wrapper = {
|
|
561
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- sql.js bind accepts heterogeneous params
|
|
562
|
+
run(...params) {
|
|
563
|
+
if (isFinalized)
|
|
564
|
+
throw new Error('Statement already finalized');
|
|
565
|
+
try {
|
|
566
|
+
bindLive(params);
|
|
567
|
+
stmt.step();
|
|
568
|
+
stmt.reset();
|
|
569
|
+
return {
|
|
570
|
+
changes: rawDb.getRowsModified(),
|
|
571
|
+
lastInsertRowid: rawDb.exec('SELECT last_insert_rowid()')[0]?.values[0]?.[0] || 0,
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
catch (error) {
|
|
575
|
+
evictOnError();
|
|
576
|
+
throw error;
|
|
577
|
+
}
|
|
578
|
+
},
|
|
579
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- sql.js bind accepts heterogeneous params
|
|
580
|
+
get(...params) {
|
|
581
|
+
if (isFinalized)
|
|
582
|
+
throw new Error('Statement already finalized');
|
|
583
|
+
try {
|
|
584
|
+
bindLive(params);
|
|
585
|
+
const hasRow = stmt.step();
|
|
586
|
+
if (!hasRow) {
|
|
587
|
+
stmt.reset();
|
|
588
|
+
return undefined;
|
|
589
|
+
}
|
|
590
|
+
const columns = stmt.getColumnNames();
|
|
591
|
+
const values = stmt.get();
|
|
592
|
+
stmt.reset();
|
|
593
|
+
const result = {};
|
|
594
|
+
columns.forEach((col, idx) => { result[col] = values[idx]; });
|
|
595
|
+
return result;
|
|
596
|
+
}
|
|
597
|
+
catch (error) {
|
|
598
|
+
evictOnError();
|
|
599
|
+
throw error;
|
|
600
|
+
}
|
|
601
|
+
},
|
|
602
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- sql.js bind accepts heterogeneous params
|
|
603
|
+
all(...params) {
|
|
604
|
+
if (isFinalized)
|
|
605
|
+
throw new Error('Statement already finalized');
|
|
606
|
+
try {
|
|
607
|
+
bindLive(params);
|
|
608
|
+
const results = [];
|
|
609
|
+
// Column names are fixed for one execution; read them once, not per row
|
|
610
|
+
let columns = null;
|
|
611
|
+
while (stmt.step()) {
|
|
612
|
+
if (!columns)
|
|
613
|
+
columns = stmt.getColumnNames();
|
|
614
|
+
const values = stmt.get();
|
|
615
|
+
const result = {};
|
|
616
|
+
for (let idx = 0; idx < columns.length; idx++)
|
|
617
|
+
result[columns[idx]] = values[idx];
|
|
618
|
+
results.push(result);
|
|
619
|
+
}
|
|
620
|
+
stmt.reset();
|
|
621
|
+
return results;
|
|
622
|
+
}
|
|
623
|
+
catch (error) {
|
|
624
|
+
evictOnError();
|
|
625
|
+
throw error;
|
|
626
|
+
}
|
|
627
|
+
},
|
|
628
|
+
finalize() {
|
|
629
|
+
// No-op while cached; close() handles teardown.
|
|
630
|
+
},
|
|
631
|
+
};
|
|
632
|
+
statementCache.set(sql, wrapper);
|
|
633
|
+
return wrapper;
|
|
634
|
+
},
|
|
635
|
+
exec(sql) {
|
|
636
|
+
return rawDb.exec(sql);
|
|
637
|
+
},
|
|
638
|
+
save() {
|
|
639
|
+
if (filename !== ':memory:') {
|
|
640
|
+
const data = rawDb.export();
|
|
641
|
+
fileState = persistSqlJsDatabase(filename, data, fileState);
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
close() {
|
|
645
|
+
let saveError;
|
|
646
|
+
try {
|
|
647
|
+
this.save();
|
|
648
|
+
}
|
|
649
|
+
catch (error) {
|
|
650
|
+
saveError = error;
|
|
651
|
+
}
|
|
652
|
+
for (const [, stmt] of activeStatements.entries()) {
|
|
653
|
+
try {
|
|
654
|
+
stmt.free();
|
|
655
|
+
}
|
|
656
|
+
catch { /* already freed */ }
|
|
657
|
+
}
|
|
658
|
+
activeStatements.clear();
|
|
659
|
+
statementCache.clear();
|
|
660
|
+
rawDb.close();
|
|
661
|
+
if (saveError)
|
|
662
|
+
throw saveError;
|
|
663
|
+
},
|
|
664
|
+
pragma(pragma, _options) {
|
|
665
|
+
try {
|
|
666
|
+
const validatedPragma = validatePragmaCommand(pragma);
|
|
667
|
+
return runPragma(rawDb, validatedPragma);
|
|
668
|
+
}
|
|
669
|
+
catch (error) {
|
|
670
|
+
if (error instanceof ValidationError) {
|
|
671
|
+
console.error(`Invalid PRAGMA command: ${error.message}`);
|
|
672
|
+
throw error;
|
|
673
|
+
}
|
|
674
|
+
throw error;
|
|
675
|
+
}
|
|
676
|
+
},
|
|
677
|
+
transaction(fn) {
|
|
678
|
+
return () => {
|
|
679
|
+
try {
|
|
680
|
+
rawDb.exec('BEGIN TRANSACTION');
|
|
681
|
+
const result = fn();
|
|
682
|
+
rawDb.exec('COMMIT');
|
|
683
|
+
return result;
|
|
684
|
+
}
|
|
685
|
+
catch (error) {
|
|
686
|
+
rawDb.exec('ROLLBACK');
|
|
687
|
+
throw error;
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
},
|
|
691
|
+
};
|
|
692
|
+
}
|
|
253
693
|
/**
|
|
254
694
|
* Get information about current database implementation
|
|
255
695
|
*/
|
|
256
696
|
export function getDatabaseInfo() {
|
|
697
|
+
// Reports the currently-loaded backend; falls back to the sql.js description
|
|
698
|
+
// before getDatabaseImplementation() has run.
|
|
699
|
+
if (cachedImplKind === 'better-sqlite3') {
|
|
700
|
+
return {
|
|
701
|
+
implementation: 'better-sqlite3 (native)',
|
|
702
|
+
isNative: true,
|
|
703
|
+
performance: 'high',
|
|
704
|
+
requiresBuildTools: true,
|
|
705
|
+
};
|
|
706
|
+
}
|
|
257
707
|
return {
|
|
258
708
|
implementation: 'sql.js (WASM)',
|
|
259
709
|
isNative: false,
|
|
260
710
|
performance: 'medium',
|
|
261
|
-
requiresBuildTools: false
|
|
711
|
+
requiresBuildTools: false,
|
|
262
712
|
};
|
|
263
713
|
}
|
|
264
714
|
//# sourceMappingURL=db-fallback.js.map
|