agentdb 1.6.0 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1098 -350
- package/dist/agentdb-advanced.js +2110 -0
- package/dist/agentdb-advanced.min.js +1 -0
- package/dist/agentdb.min.js +4 -4
- package/dist/backends/GraphBackend.d.ts +196 -0
- package/dist/backends/GraphBackend.d.ts.map +1 -0
- package/dist/backends/GraphBackend.js +33 -0
- package/dist/backends/GraphBackend.js.map +1 -0
- package/dist/backends/LearningBackend.d.ts +148 -0
- package/dist/backends/LearningBackend.d.ts.map +1 -0
- package/dist/backends/LearningBackend.js +27 -0
- package/dist/backends/LearningBackend.js.map +1 -0
- package/dist/backends/VectorBackend.d.ts +119 -0
- package/dist/backends/VectorBackend.d.ts.map +1 -0
- package/dist/backends/VectorBackend.js +14 -0
- package/dist/backends/VectorBackend.js.map +1 -0
- package/dist/backends/detector.d.ts +81 -0
- package/dist/backends/detector.d.ts.map +1 -0
- package/dist/backends/detector.js +192 -0
- package/dist/backends/detector.js.map +1 -0
- package/dist/backends/factory.d.ts +50 -0
- package/dist/backends/factory.d.ts.map +1 -0
- package/dist/backends/factory.js +161 -0
- package/dist/backends/factory.js.map +1 -0
- package/dist/backends/graph/GraphDatabaseAdapter.d.ts +139 -0
- package/dist/backends/graph/GraphDatabaseAdapter.d.ts.map +1 -0
- package/dist/backends/graph/GraphDatabaseAdapter.js +194 -0
- package/dist/backends/graph/GraphDatabaseAdapter.js.map +1 -0
- package/dist/backends/hnswlib/HNSWLibBackend.d.ts +92 -0
- package/dist/backends/hnswlib/HNSWLibBackend.d.ts.map +1 -0
- package/dist/backends/hnswlib/HNSWLibBackend.js +316 -0
- package/dist/backends/hnswlib/HNSWLibBackend.js.map +1 -0
- package/dist/backends/hnswlib/index.d.ts +7 -0
- package/dist/backends/hnswlib/index.d.ts.map +1 -0
- package/dist/backends/hnswlib/index.js +7 -0
- package/dist/backends/hnswlib/index.js.map +1 -0
- package/dist/backends/index.d.ts +14 -0
- package/dist/backends/index.d.ts.map +1 -0
- package/dist/backends/index.js +13 -0
- package/dist/backends/index.js.map +1 -0
- package/dist/backends/ruvector/RuVectorBackend.d.ts +75 -0
- package/dist/backends/ruvector/RuVectorBackend.d.ts.map +1 -0
- package/dist/backends/ruvector/RuVectorBackend.js +198 -0
- package/dist/backends/ruvector/RuVectorBackend.js.map +1 -0
- package/dist/backends/ruvector/RuVectorLearning.d.ts +104 -0
- package/dist/backends/ruvector/RuVectorLearning.d.ts.map +1 -0
- package/dist/backends/ruvector/RuVectorLearning.js +177 -0
- package/dist/backends/ruvector/RuVectorLearning.js.map +1 -0
- package/dist/backends/ruvector/index.d.ts +9 -0
- package/dist/backends/ruvector/index.d.ts.map +1 -0
- package/dist/backends/ruvector/index.js +8 -0
- package/dist/backends/ruvector/index.js.map +1 -0
- package/dist/browser/AdvancedFeatures.d.ts +144 -0
- package/dist/browser/AdvancedFeatures.d.ts.map +1 -0
- package/dist/browser/AdvancedFeatures.js +430 -0
- package/dist/browser/AdvancedFeatures.js.map +1 -0
- package/dist/browser/HNSWIndex.d.ts +117 -0
- package/dist/browser/HNSWIndex.d.ts.map +1 -0
- package/dist/browser/HNSWIndex.js +402 -0
- package/dist/browser/HNSWIndex.js.map +1 -0
- package/dist/browser/ProductQuantization.d.ts +107 -0
- package/dist/browser/ProductQuantization.d.ts.map +1 -0
- package/dist/browser/ProductQuantization.js +337 -0
- package/dist/browser/ProductQuantization.js.map +1 -0
- package/dist/browser/browser/AdvancedFeatures.d.ts +144 -0
- package/dist/browser/browser/AdvancedFeatures.d.ts.map +1 -0
- package/dist/browser/browser/AdvancedFeatures.js +427 -0
- package/dist/browser/browser/HNSWIndex.d.ts +117 -0
- package/dist/browser/browser/HNSWIndex.d.ts.map +1 -0
- package/dist/browser/browser/HNSWIndex.js +402 -0
- package/dist/browser/browser/ProductQuantization.d.ts +107 -0
- package/dist/browser/browser/ProductQuantization.d.ts.map +1 -0
- package/dist/browser/browser/ProductQuantization.js +348 -0
- package/dist/browser/browser/index.d.ts +223 -0
- package/dist/browser/browser/index.d.ts.map +1 -0
- package/dist/browser/browser/index.js +233 -0
- package/dist/browser/index.d.ts +223 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +225 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/cli/agentdb-cli.d.ts.map +1 -1
- package/dist/cli/agentdb-cli.js +130 -8
- package/dist/cli/agentdb-cli.js.map +1 -1
- package/dist/cli/agentdb.db +0 -0
- package/dist/cli/commands/init.d.ts +12 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +115 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/install-embeddings.d.ts +10 -0
- package/dist/cli/commands/install-embeddings.d.ts.map +1 -0
- package/dist/cli/commands/install-embeddings.js +68 -0
- package/dist/cli/commands/install-embeddings.js.map +1 -0
- package/dist/cli/commands/migrate.d.ts +15 -0
- package/dist/cli/commands/migrate.d.ts.map +1 -0
- package/dist/cli/commands/migrate.js +425 -0
- package/dist/cli/commands/migrate.js.map +1 -0
- package/dist/cli/commands/status.d.ts +10 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +129 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/controllers/CausalRecall.d.ts +3 -1
- package/dist/controllers/CausalRecall.d.ts.map +1 -1
- package/dist/controllers/CausalRecall.js +35 -4
- package/dist/controllers/CausalRecall.js.map +1 -1
- package/dist/controllers/ExplainableRecall.d.ts +24 -0
- package/dist/controllers/ExplainableRecall.d.ts.map +1 -1
- package/dist/controllers/ExplainableRecall.js +102 -5
- package/dist/controllers/ExplainableRecall.js.map +1 -1
- package/dist/controllers/HNSWIndex.d.ts +128 -0
- package/dist/controllers/HNSWIndex.d.ts.map +1 -0
- package/dist/controllers/HNSWIndex.js +361 -0
- package/dist/controllers/HNSWIndex.js.map +1 -0
- package/dist/controllers/NightlyLearner.d.ts.map +1 -1
- package/dist/controllers/NightlyLearner.js +7 -4
- package/dist/controllers/NightlyLearner.js.map +1 -1
- package/dist/controllers/ReasoningBank.d.ts +101 -2
- package/dist/controllers/ReasoningBank.d.ts.map +1 -1
- package/dist/controllers/ReasoningBank.js +196 -4
- package/dist/controllers/ReasoningBank.js.map +1 -1
- package/dist/controllers/ReflexionMemory.d.ts +41 -1
- package/dist/controllers/ReflexionMemory.d.ts.map +1 -1
- package/dist/controllers/ReflexionMemory.js +282 -5
- package/dist/controllers/ReflexionMemory.js.map +1 -1
- package/dist/controllers/SkillLibrary.d.ts +27 -9
- package/dist/controllers/SkillLibrary.d.ts.map +1 -1
- package/dist/controllers/SkillLibrary.js +136 -47
- package/dist/controllers/SkillLibrary.js.map +1 -1
- package/dist/controllers/index.d.ts +2 -0
- package/dist/controllers/index.d.ts.map +1 -1
- package/dist/controllers/index.js +1 -0
- package/dist/controllers/index.js.map +1 -1
- package/dist/db-fallback.d.ts.map +1 -1
- package/dist/db-fallback.js +100 -29
- package/dist/db-fallback.js.map +1 -1
- package/dist/db-test.d.ts +13 -0
- package/dist/db-test.d.ts.map +1 -0
- package/dist/db-test.js +55 -0
- package/dist/db-test.js.map +1 -0
- package/dist/db-unified.d.ts +76 -0
- package/dist/db-unified.d.ts.map +1 -0
- package/dist/db-unified.js +278 -0
- package/dist/db-unified.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/malp/core/ccc.d.ts +99 -0
- package/dist/malp/core/ccc.d.ts.map +1 -0
- package/dist/malp/core/ccc.js +181 -0
- package/dist/malp/core/ccc.js.map +1 -0
- package/dist/malp/core/index.d.ts +9 -0
- package/dist/malp/core/index.d.ts.map +1 -0
- package/dist/malp/core/index.js +9 -0
- package/dist/malp/core/index.js.map +1 -0
- package/dist/malp/core/linalg.d.ts +101 -0
- package/dist/malp/core/linalg.d.ts.map +1 -0
- package/dist/malp/core/linalg.js +278 -0
- package/dist/malp/core/linalg.js.map +1 -0
- package/dist/malp/core/optimizer.d.ts +68 -0
- package/dist/malp/core/optimizer.d.ts.map +1 -0
- package/dist/malp/core/optimizer.js +160 -0
- package/dist/malp/core/optimizer.js.map +1 -0
- package/dist/malp/index.d.ts +33 -0
- package/dist/malp/index.d.ts.map +1 -0
- package/dist/malp/index.js +37 -0
- package/dist/malp/index.js.map +1 -0
- package/dist/malp/metrics/agreement.d.ts +106 -0
- package/dist/malp/metrics/agreement.d.ts.map +1 -0
- package/dist/malp/metrics/agreement.js +199 -0
- package/dist/malp/metrics/agreement.js.map +1 -0
- package/dist/malp/metrics/comparison.d.ts +93 -0
- package/dist/malp/metrics/comparison.d.ts.map +1 -0
- package/dist/malp/metrics/comparison.js +256 -0
- package/dist/malp/metrics/comparison.js.map +1 -0
- package/dist/malp/metrics/index.d.ts +8 -0
- package/dist/malp/metrics/index.d.ts.map +1 -0
- package/dist/malp/metrics/index.js +8 -0
- package/dist/malp/metrics/index.js.map +1 -0
- package/dist/malp/metrics/performance.d.ts +61 -0
- package/dist/malp/metrics/performance.d.ts.map +1 -0
- package/dist/malp/metrics/performance.js +190 -0
- package/dist/malp/metrics/performance.js.map +1 -0
- package/dist/malp/models/index.d.ts +7 -0
- package/dist/malp/models/index.d.ts.map +1 -0
- package/dist/malp/models/index.js +7 -0
- package/dist/malp/models/index.js.map +1 -0
- package/dist/malp/models/malp.d.ts +116 -0
- package/dist/malp/models/malp.d.ts.map +1 -0
- package/dist/malp/models/malp.js +206 -0
- package/dist/malp/models/malp.js.map +1 -0
- package/dist/malp/models/regressor.d.ts +80 -0
- package/dist/malp/models/regressor.d.ts.map +1 -0
- package/dist/malp/models/regressor.js +229 -0
- package/dist/malp/models/regressor.js.map +1 -0
- package/dist/malp/reasoningbank_validator.d.ts +187 -0
- package/dist/malp/reasoningbank_validator.d.ts.map +1 -0
- package/dist/malp/reasoningbank_validator.js +246 -0
- package/dist/malp/reasoningbank_validator.js.map +1 -0
- package/dist/malp/wasm_bindings.d.ts +344 -0
- package/dist/malp/wasm_bindings.d.ts.map +1 -0
- package/dist/malp/wasm_bindings.js +9 -0
- package/dist/malp/wasm_bindings.js.map +1 -0
- package/dist/mcp/agentdb-mcp-server.js +512 -33
- package/dist/mcp/agentdb-mcp-server.js.map +1 -1
- package/dist/optimizations/BatchOperations.d.ts +42 -0
- package/dist/optimizations/BatchOperations.d.ts.map +1 -1
- package/dist/optimizations/BatchOperations.js +181 -0
- package/dist/optimizations/BatchOperations.js.map +1 -1
- package/dist/optimizations/ToolCache.d.ts +137 -0
- package/dist/optimizations/ToolCache.d.ts.map +1 -0
- package/dist/optimizations/ToolCache.js +281 -0
- package/dist/optimizations/ToolCache.js.map +1 -0
- package/dist/security/input-validation.d.ts +24 -0
- package/dist/security/input-validation.d.ts.map +1 -1
- package/dist/security/input-validation.js +106 -0
- package/dist/security/input-validation.js.map +1 -1
- package/dist/security/limits.d.ts +150 -0
- package/dist/security/limits.d.ts.map +1 -0
- package/dist/security/limits.js +288 -0
- package/dist/security/limits.js.map +1 -0
- package/dist/security/path-security.d.ts +100 -0
- package/dist/security/path-security.d.ts.map +1 -0
- package/dist/security/path-security.js +337 -0
- package/dist/security/path-security.js.map +1 -0
- package/dist/security/validation.d.ts +95 -0
- package/dist/security/validation.d.ts.map +1 -0
- package/dist/security/validation.js +315 -0
- package/dist/security/validation.js.map +1 -0
- package/dist/simulation/cli.d.ts +9 -0
- package/dist/simulation/cli.d.ts.map +1 -0
- package/dist/simulation/cli.js +68 -0
- package/dist/simulation/cli.js.map +1 -0
- package/dist/simulation/runner.d.ts +21 -0
- package/dist/simulation/runner.d.ts.map +1 -0
- package/dist/simulation/runner.js +241 -0
- package/dist/simulation/runner.js.map +1 -0
- package/dist/simulation/scenarios/aidefence-integration.d.ts +24 -0
- package/dist/simulation/scenarios/aidefence-integration.d.ts.map +1 -0
- package/dist/simulation/scenarios/aidefence-integration.js +124 -0
- package/dist/simulation/scenarios/aidefence-integration.js.map +1 -0
- package/dist/simulation/scenarios/bmssp-integration.d.ts +23 -0
- package/dist/simulation/scenarios/bmssp-integration.d.ts.map +1 -0
- package/dist/simulation/scenarios/bmssp-integration.js +104 -0
- package/dist/simulation/scenarios/bmssp-integration.js.map +1 -0
- package/dist/simulation/scenarios/causal-reasoning.d.ts +16 -0
- package/dist/simulation/scenarios/causal-reasoning.d.ts.map +1 -0
- package/dist/simulation/scenarios/causal-reasoning.js +108 -0
- package/dist/simulation/scenarios/causal-reasoning.js.map +1 -0
- package/dist/simulation/scenarios/consciousness-explorer.d.ts +25 -0
- package/dist/simulation/scenarios/consciousness-explorer.d.ts.map +1 -0
- package/dist/simulation/scenarios/consciousness-explorer.js +108 -0
- package/dist/simulation/scenarios/consciousness-explorer.js.map +1 -0
- package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.d.ts +135 -0
- package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.d.ts.map +1 -0
- package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.js +158 -0
- package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.js.map +1 -0
- package/dist/simulation/scenarios/domain-examples/index.d.ts +14 -0
- package/dist/simulation/scenarios/domain-examples/index.d.ts.map +1 -0
- package/dist/simulation/scenarios/domain-examples/index.js +14 -0
- package/dist/simulation/scenarios/domain-examples/index.js.map +1 -0
- package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.d.ts +178 -0
- package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.d.ts.map +1 -0
- package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.js +218 -0
- package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.js.map +1 -0
- package/dist/simulation/scenarios/domain-examples/medical-imaging.d.ts +122 -0
- package/dist/simulation/scenarios/domain-examples/medical-imaging.d.ts.map +1 -0
- package/dist/simulation/scenarios/domain-examples/medical-imaging.js +129 -0
- package/dist/simulation/scenarios/domain-examples/medical-imaging.js.map +1 -0
- package/dist/simulation/scenarios/domain-examples/robotics-navigation.d.ts +166 -0
- package/dist/simulation/scenarios/domain-examples/robotics-navigation.d.ts.map +1 -0
- package/dist/simulation/scenarios/domain-examples/robotics-navigation.js +161 -0
- package/dist/simulation/scenarios/domain-examples/robotics-navigation.js.map +1 -0
- package/dist/simulation/scenarios/domain-examples/scientific-research.d.ts +151 -0
- package/dist/simulation/scenarios/domain-examples/scientific-research.d.ts.map +1 -0
- package/dist/simulation/scenarios/domain-examples/scientific-research.js +187 -0
- package/dist/simulation/scenarios/domain-examples/scientific-research.js.map +1 -0
- package/dist/simulation/scenarios/domain-examples/trading-systems.d.ts +102 -0
- package/dist/simulation/scenarios/domain-examples/trading-systems.d.ts.map +1 -0
- package/dist/simulation/scenarios/domain-examples/trading-systems.js +100 -0
- package/dist/simulation/scenarios/domain-examples/trading-systems.js.map +1 -0
- package/dist/simulation/scenarios/goalie-integration.d.ts +24 -0
- package/dist/simulation/scenarios/goalie-integration.d.ts.map +1 -0
- package/dist/simulation/scenarios/goalie-integration.js +121 -0
- package/dist/simulation/scenarios/goalie-integration.js.map +1 -0
- package/dist/simulation/scenarios/graph-traversal.d.ts +17 -0
- package/dist/simulation/scenarios/graph-traversal.d.ts.map +1 -0
- package/dist/simulation/scenarios/graph-traversal.js +101 -0
- package/dist/simulation/scenarios/graph-traversal.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/attention-analysis.d.ts +45 -0
- package/dist/simulation/scenarios/latent-space/attention-analysis.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/attention-analysis.js +435 -0
- package/dist/simulation/scenarios/latent-space/attention-analysis.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/clustering-analysis.d.ts +55 -0
- package/dist/simulation/scenarios/latent-space/clustering-analysis.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/clustering-analysis.js +606 -0
- package/dist/simulation/scenarios/latent-space/clustering-analysis.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/hnsw-exploration.d.ts +74 -0
- package/dist/simulation/scenarios/latent-space/hnsw-exploration.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/hnsw-exploration.js +391 -0
- package/dist/simulation/scenarios/latent-space/hnsw-exploration.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/hypergraph-exploration.d.ts +51 -0
- package/dist/simulation/scenarios/latent-space/hypergraph-exploration.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/hypergraph-exploration.js +536 -0
- package/dist/simulation/scenarios/latent-space/hypergraph-exploration.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/index.d.ts +35 -0
- package/dist/simulation/scenarios/latent-space/index.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/index.js +35 -0
- package/dist/simulation/scenarios/latent-space/index.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/neural-augmentation.d.ts +52 -0
- package/dist/simulation/scenarios/latent-space/neural-augmentation.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/neural-augmentation.js +472 -0
- package/dist/simulation/scenarios/latent-space/neural-augmentation.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/quantum-hybrid.d.ts +53 -0
- package/dist/simulation/scenarios/latent-space/quantum-hybrid.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/quantum-hybrid.js +391 -0
- package/dist/simulation/scenarios/latent-space/quantum-hybrid.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.d.ts +52 -0
- package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.js +514 -0
- package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/traversal-optimization.d.ts +53 -0
- package/dist/simulation/scenarios/latent-space/traversal-optimization.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/traversal-optimization.js +595 -0
- package/dist/simulation/scenarios/latent-space/traversal-optimization.js.map +1 -0
- package/dist/simulation/scenarios/lean-agentic-swarm.d.ts +18 -0
- package/dist/simulation/scenarios/lean-agentic-swarm.d.ts.map +1 -0
- package/dist/simulation/scenarios/lean-agentic-swarm.js +132 -0
- package/dist/simulation/scenarios/lean-agentic-swarm.js.map +1 -0
- package/dist/simulation/scenarios/multi-agent-swarm.d.ts +17 -0
- package/dist/simulation/scenarios/multi-agent-swarm.d.ts.map +1 -0
- package/dist/simulation/scenarios/multi-agent-swarm.js +111 -0
- package/dist/simulation/scenarios/multi-agent-swarm.js.map +1 -0
- package/dist/simulation/scenarios/psycho-symbolic-reasoner.d.ts +23 -0
- package/dist/simulation/scenarios/psycho-symbolic-reasoner.d.ts.map +1 -0
- package/dist/simulation/scenarios/psycho-symbolic-reasoner.js +98 -0
- package/dist/simulation/scenarios/psycho-symbolic-reasoner.js.map +1 -0
- package/dist/simulation/scenarios/reflexion-learning.d.ts +16 -0
- package/dist/simulation/scenarios/reflexion-learning.d.ts.map +1 -0
- package/dist/simulation/scenarios/reflexion-learning.js +98 -0
- package/dist/simulation/scenarios/reflexion-learning.js.map +1 -0
- package/dist/simulation/scenarios/research-swarm.d.ts +24 -0
- package/dist/simulation/scenarios/research-swarm.d.ts.map +1 -0
- package/dist/simulation/scenarios/research-swarm.js +146 -0
- package/dist/simulation/scenarios/research-swarm.js.map +1 -0
- package/dist/simulation/scenarios/skill-evolution.d.ts +16 -0
- package/dist/simulation/scenarios/skill-evolution.d.ts.map +1 -0
- package/dist/simulation/scenarios/skill-evolution.js +109 -0
- package/dist/simulation/scenarios/skill-evolution.js.map +1 -0
- package/dist/simulation/scenarios/stock-market-emergence.d.ts +33 -0
- package/dist/simulation/scenarios/stock-market-emergence.d.ts.map +1 -0
- package/dist/simulation/scenarios/stock-market-emergence.js +246 -0
- package/dist/simulation/scenarios/stock-market-emergence.js.map +1 -0
- package/dist/simulation/scenarios/strange-loops.d.ts +18 -0
- package/dist/simulation/scenarios/strange-loops.d.ts.map +1 -0
- package/dist/simulation/scenarios/strange-loops.js +133 -0
- package/dist/simulation/scenarios/strange-loops.js.map +1 -0
- package/dist/simulation/scenarios/sublinear-solver.d.ts +22 -0
- package/dist/simulation/scenarios/sublinear-solver.d.ts.map +1 -0
- package/dist/simulation/scenarios/sublinear-solver.js +82 -0
- package/dist/simulation/scenarios/sublinear-solver.js.map +1 -0
- package/dist/simulation/scenarios/temporal-lead-solver.d.ts +23 -0
- package/dist/simulation/scenarios/temporal-lead-solver.d.ts.map +1 -0
- package/dist/simulation/scenarios/temporal-lead-solver.js +90 -0
- package/dist/simulation/scenarios/temporal-lead-solver.js.map +1 -0
- package/dist/simulation/scenarios/voting-system-consensus.d.ts +27 -0
- package/dist/simulation/scenarios/voting-system-consensus.d.ts.map +1 -0
- package/dist/simulation/scenarios/voting-system-consensus.js +175 -0
- package/dist/simulation/scenarios/voting-system-consensus.js.map +1 -0
- package/dist/simulation/types.d.ts +162 -0
- package/dist/simulation/types.d.ts.map +1 -0
- package/dist/simulation/types.js +5 -0
- package/dist/simulation/types.js.map +1 -0
- package/dist/simulation/utils/PerformanceOptimizer.d.ts +115 -0
- package/dist/simulation/utils/PerformanceOptimizer.d.ts.map +1 -0
- package/dist/simulation/utils/PerformanceOptimizer.js +223 -0
- package/dist/simulation/utils/PerformanceOptimizer.js.map +1 -0
- package/dist/src/backends/GraphBackend.d.ts +196 -0
- package/dist/src/backends/GraphBackend.d.ts.map +1 -0
- package/dist/src/backends/GraphBackend.js +33 -0
- package/dist/src/backends/GraphBackend.js.map +1 -0
- package/dist/src/backends/LearningBackend.d.ts +148 -0
- package/dist/src/backends/LearningBackend.d.ts.map +1 -0
- package/dist/src/backends/LearningBackend.js +27 -0
- package/dist/src/backends/LearningBackend.js.map +1 -0
- package/dist/src/backends/VectorBackend.d.ts +119 -0
- package/dist/src/backends/VectorBackend.d.ts.map +1 -0
- package/dist/src/backends/VectorBackend.js +14 -0
- package/dist/src/backends/VectorBackend.js.map +1 -0
- package/dist/src/backends/detector.d.ts +81 -0
- package/dist/src/backends/detector.d.ts.map +1 -0
- package/dist/src/backends/detector.js +192 -0
- package/dist/src/backends/detector.js.map +1 -0
- package/dist/src/backends/factory.d.ts +50 -0
- package/dist/src/backends/factory.d.ts.map +1 -0
- package/dist/src/backends/factory.js +161 -0
- package/dist/src/backends/factory.js.map +1 -0
- package/dist/src/backends/graph/GraphDatabaseAdapter.d.ts +151 -0
- package/dist/src/backends/graph/GraphDatabaseAdapter.d.ts.map +1 -0
- package/dist/src/backends/graph/GraphDatabaseAdapter.js +224 -0
- package/dist/src/backends/graph/GraphDatabaseAdapter.js.map +1 -0
- package/dist/src/backends/hnswlib/HNSWLibBackend.d.ts +92 -0
- package/dist/src/backends/hnswlib/HNSWLibBackend.d.ts.map +1 -0
- package/dist/src/backends/hnswlib/HNSWLibBackend.js +316 -0
- package/dist/src/backends/hnswlib/HNSWLibBackend.js.map +1 -0
- package/dist/src/backends/hnswlib/index.d.ts +7 -0
- package/dist/src/backends/hnswlib/index.d.ts.map +1 -0
- package/dist/src/backends/hnswlib/index.js +7 -0
- package/dist/src/backends/hnswlib/index.js.map +1 -0
- package/dist/src/backends/index.d.ts +14 -0
- package/dist/src/backends/index.d.ts.map +1 -0
- package/dist/src/backends/index.js +13 -0
- package/dist/src/backends/index.js.map +1 -0
- package/dist/src/backends/ruvector/RuVectorBackend.d.ts +75 -0
- package/dist/src/backends/ruvector/RuVectorBackend.d.ts.map +1 -0
- package/dist/src/backends/ruvector/RuVectorBackend.js +198 -0
- package/dist/src/backends/ruvector/RuVectorBackend.js.map +1 -0
- package/dist/src/backends/ruvector/RuVectorLearning.d.ts +104 -0
- package/dist/src/backends/ruvector/RuVectorLearning.d.ts.map +1 -0
- package/dist/src/backends/ruvector/RuVectorLearning.js +177 -0
- package/dist/src/backends/ruvector/RuVectorLearning.js.map +1 -0
- package/dist/src/backends/ruvector/index.d.ts +9 -0
- package/dist/src/backends/ruvector/index.d.ts.map +1 -0
- package/dist/src/backends/ruvector/index.js +8 -0
- package/dist/src/backends/ruvector/index.js.map +1 -0
- package/dist/src/benchmarks/wasm-vector-benchmark.d.ts +10 -0
- package/dist/src/benchmarks/wasm-vector-benchmark.d.ts.map +1 -0
- package/dist/src/benchmarks/wasm-vector-benchmark.js +196 -0
- package/dist/src/benchmarks/wasm-vector-benchmark.js.map +1 -0
- package/dist/src/browser/AdvancedFeatures.d.ts +144 -0
- package/dist/src/browser/AdvancedFeatures.d.ts.map +1 -0
- package/dist/src/browser/AdvancedFeatures.js +430 -0
- package/dist/src/browser/AdvancedFeatures.js.map +1 -0
- package/dist/src/browser/HNSWIndex.d.ts +117 -0
- package/dist/src/browser/HNSWIndex.d.ts.map +1 -0
- package/dist/src/browser/HNSWIndex.js +402 -0
- package/dist/src/browser/HNSWIndex.js.map +1 -0
- package/dist/src/browser/ProductQuantization.d.ts +107 -0
- package/dist/src/browser/ProductQuantization.d.ts.map +1 -0
- package/dist/src/browser/ProductQuantization.js +337 -0
- package/dist/src/browser/ProductQuantization.js.map +1 -0
- package/dist/src/browser/index.d.ts +223 -0
- package/dist/src/browser/index.d.ts.map +1 -0
- package/dist/src/browser/index.js +225 -0
- package/dist/src/browser/index.js.map +1 -0
- package/dist/src/cli/agentdb-cli.d.ts +154 -0
- package/dist/src/cli/agentdb-cli.d.ts.map +1 -0
- package/dist/src/cli/agentdb-cli.js +2273 -0
- package/dist/src/cli/agentdb-cli.js.map +1 -0
- package/dist/src/cli/commands/init.d.ts +12 -0
- package/dist/src/cli/commands/init.d.ts.map +1 -0
- package/dist/src/cli/commands/init.js +115 -0
- package/dist/src/cli/commands/init.js.map +1 -0
- package/dist/src/cli/commands/install-embeddings.d.ts +10 -0
- package/dist/src/cli/commands/install-embeddings.d.ts.map +1 -0
- package/dist/src/cli/commands/install-embeddings.js +68 -0
- package/dist/src/cli/commands/install-embeddings.js.map +1 -0
- package/dist/src/cli/commands/migrate.d.ts +15 -0
- package/dist/src/cli/commands/migrate.d.ts.map +1 -0
- package/dist/src/cli/commands/migrate.js +425 -0
- package/dist/src/cli/commands/migrate.js.map +1 -0
- package/dist/src/cli/commands/simulate-custom.d.ts +26 -0
- package/dist/src/cli/commands/simulate-custom.d.ts.map +1 -0
- package/dist/src/cli/commands/simulate-custom.js +207 -0
- package/dist/src/cli/commands/simulate-custom.js.map +1 -0
- package/dist/src/cli/commands/simulate-report.d.ts +15 -0
- package/dist/src/cli/commands/simulate-report.d.ts.map +1 -0
- package/dist/src/cli/commands/simulate-report.js +136 -0
- package/dist/src/cli/commands/simulate-report.js.map +1 -0
- package/dist/src/cli/commands/simulate-wizard.d.ts +6 -0
- package/dist/src/cli/commands/simulate-wizard.d.ts.map +1 -0
- package/dist/src/cli/commands/simulate-wizard.js +352 -0
- package/dist/src/cli/commands/simulate-wizard.js.map +1 -0
- package/dist/src/cli/commands/simulate.d.ts +7 -0
- package/dist/src/cli/commands/simulate.d.ts.map +1 -0
- package/dist/src/cli/commands/simulate.js +100 -0
- package/dist/src/cli/commands/simulate.js.map +1 -0
- package/dist/src/cli/commands/status.d.ts +10 -0
- package/dist/src/cli/commands/status.d.ts.map +1 -0
- package/dist/src/cli/commands/status.js +129 -0
- package/dist/src/cli/commands/status.js.map +1 -0
- package/dist/src/cli/lib/config-manager.d.ts +110 -0
- package/dist/src/cli/lib/config-manager.d.ts.map +1 -0
- package/dist/src/cli/lib/config-manager.js +512 -0
- package/dist/src/cli/lib/config-manager.js.map +1 -0
- package/dist/src/cli/lib/config-validator.d.ts +43 -0
- package/dist/src/cli/lib/config-validator.d.ts.map +1 -0
- package/dist/src/cli/lib/config-validator.js +217 -0
- package/dist/src/cli/lib/config-validator.js.map +1 -0
- package/dist/src/cli/lib/health-monitor.d.ts +149 -0
- package/dist/src/cli/lib/health-monitor.d.ts.map +1 -0
- package/dist/src/cli/lib/health-monitor.js +380 -0
- package/dist/src/cli/lib/health-monitor.js.map +1 -0
- package/dist/src/cli/lib/help-formatter.d.ts +38 -0
- package/dist/src/cli/lib/help-formatter.d.ts.map +1 -0
- package/dist/src/cli/lib/help-formatter.js +357 -0
- package/dist/src/cli/lib/help-formatter.js.map +1 -0
- package/dist/src/cli/lib/history-tracker.d.ts +103 -0
- package/dist/src/cli/lib/history-tracker.d.ts.map +1 -0
- package/dist/src/cli/lib/history-tracker.js +346 -0
- package/dist/src/cli/lib/history-tracker.js.map +1 -0
- package/dist/src/cli/lib/report-generator.d.ts +24 -0
- package/dist/src/cli/lib/report-generator.d.ts.map +1 -0
- package/dist/src/cli/lib/report-generator.js +417 -0
- package/dist/src/cli/lib/report-generator.js.map +1 -0
- package/dist/src/cli/lib/report-store.d.ts +116 -0
- package/dist/src/cli/lib/report-store.d.ts.map +1 -0
- package/dist/src/cli/lib/report-store.js +464 -0
- package/dist/src/cli/lib/report-store.js.map +1 -0
- package/dist/src/cli/lib/simulation-registry.d.ts +165 -0
- package/dist/src/cli/lib/simulation-registry.d.ts.map +1 -0
- package/dist/src/cli/lib/simulation-registry.js +332 -0
- package/dist/src/cli/lib/simulation-registry.js.map +1 -0
- package/dist/src/cli/lib/simulation-runner.d.ts +90 -0
- package/dist/src/cli/lib/simulation-runner.d.ts.map +1 -0
- package/dist/src/cli/lib/simulation-runner.js +211 -0
- package/dist/src/cli/lib/simulation-runner.js.map +1 -0
- package/dist/src/controllers/CausalMemoryGraph.d.ts +127 -0
- package/dist/src/controllers/CausalMemoryGraph.d.ts.map +1 -0
- package/dist/src/controllers/CausalMemoryGraph.js +354 -0
- package/dist/src/controllers/CausalMemoryGraph.js.map +1 -0
- package/dist/src/controllers/CausalRecall.d.ts +139 -0
- package/dist/src/controllers/CausalRecall.d.ts.map +1 -0
- package/dist/src/controllers/CausalRecall.js +356 -0
- package/dist/src/controllers/CausalRecall.js.map +1 -0
- package/dist/src/controllers/ContextSynthesizer.d.ts +65 -0
- package/dist/src/controllers/ContextSynthesizer.d.ts.map +1 -0
- package/dist/src/controllers/ContextSynthesizer.js +208 -0
- package/dist/src/controllers/ContextSynthesizer.js.map +1 -0
- package/dist/src/controllers/EmbeddingService.d.ts +37 -0
- package/dist/src/controllers/EmbeddingService.d.ts.map +1 -0
- package/dist/src/controllers/EmbeddingService.js +136 -0
- package/dist/src/controllers/EmbeddingService.js.map +1 -0
- package/dist/src/controllers/EnhancedEmbeddingService.d.ts +50 -0
- package/dist/src/controllers/EnhancedEmbeddingService.d.ts.map +1 -0
- package/dist/src/controllers/EnhancedEmbeddingService.js +119 -0
- package/dist/src/controllers/EnhancedEmbeddingService.js.map +1 -0
- package/dist/src/controllers/ExplainableRecall.d.ts +163 -0
- package/dist/src/controllers/ExplainableRecall.d.ts.map +1 -0
- package/dist/src/controllers/ExplainableRecall.js +485 -0
- package/dist/src/controllers/ExplainableRecall.js.map +1 -0
- package/dist/src/controllers/HNSWIndex.d.ts +128 -0
- package/dist/src/controllers/HNSWIndex.d.ts.map +1 -0
- package/dist/src/controllers/HNSWIndex.js +361 -0
- package/dist/src/controllers/HNSWIndex.js.map +1 -0
- package/dist/src/controllers/LearningSystem.d.ts +195 -0
- package/dist/src/controllers/LearningSystem.d.ts.map +1 -0
- package/dist/src/controllers/LearningSystem.js +929 -0
- package/dist/src/controllers/LearningSystem.js.map +1 -0
- package/dist/src/controllers/MMRDiversityRanker.d.ts +50 -0
- package/dist/src/controllers/MMRDiversityRanker.d.ts.map +1 -0
- package/dist/src/controllers/MMRDiversityRanker.js +130 -0
- package/dist/src/controllers/MMRDiversityRanker.js.map +1 -0
- package/dist/src/controllers/MetadataFilter.d.ts +70 -0
- package/dist/src/controllers/MetadataFilter.d.ts.map +1 -0
- package/dist/src/controllers/MetadataFilter.js +243 -0
- package/dist/src/controllers/MetadataFilter.js.map +1 -0
- package/dist/src/controllers/NightlyLearner.d.ts +114 -0
- package/dist/src/controllers/NightlyLearner.d.ts.map +1 -0
- package/dist/src/controllers/NightlyLearner.js +394 -0
- package/dist/src/controllers/NightlyLearner.js.map +1 -0
- package/dist/src/controllers/QUICClient.d.ts +109 -0
- package/dist/src/controllers/QUICClient.d.ts.map +1 -0
- package/dist/src/controllers/QUICClient.js +299 -0
- package/dist/src/controllers/QUICClient.js.map +1 -0
- package/dist/src/controllers/QUICServer.d.ts +121 -0
- package/dist/src/controllers/QUICServer.d.ts.map +1 -0
- package/dist/src/controllers/QUICServer.js +383 -0
- package/dist/src/controllers/QUICServer.js.map +1 -0
- package/dist/src/controllers/ReasoningBank.d.ts +196 -0
- package/dist/src/controllers/ReasoningBank.d.ts.map +1 -0
- package/dist/src/controllers/ReasoningBank.js +494 -0
- package/dist/src/controllers/ReasoningBank.js.map +1 -0
- package/dist/src/controllers/ReflexionMemory.d.ts +125 -0
- package/dist/src/controllers/ReflexionMemory.d.ts.map +1 -0
- package/dist/src/controllers/ReflexionMemory.js +654 -0
- package/dist/src/controllers/ReflexionMemory.js.map +1 -0
- package/dist/src/controllers/SkillLibrary.d.ts +150 -0
- package/dist/src/controllers/SkillLibrary.d.ts.map +1 -0
- package/dist/src/controllers/SkillLibrary.js +608 -0
- package/dist/src/controllers/SkillLibrary.js.map +1 -0
- package/dist/src/controllers/SyncCoordinator.d.ts +120 -0
- package/dist/src/controllers/SyncCoordinator.d.ts.map +1 -0
- package/dist/src/controllers/SyncCoordinator.js +441 -0
- package/dist/src/controllers/SyncCoordinator.js.map +1 -0
- package/dist/src/controllers/WASMVectorSearch.d.ts +89 -0
- package/dist/src/controllers/WASMVectorSearch.d.ts.map +1 -0
- package/dist/src/controllers/WASMVectorSearch.js +234 -0
- package/dist/src/controllers/WASMVectorSearch.js.map +1 -0
- package/dist/src/controllers/frontier-index.d.ts +14 -0
- package/dist/src/controllers/frontier-index.d.ts.map +1 -0
- package/dist/src/controllers/frontier-index.js +10 -0
- package/dist/src/controllers/frontier-index.js.map +1 -0
- package/dist/src/controllers/index.d.ts +30 -0
- package/dist/src/controllers/index.d.ts.map +1 -0
- package/dist/src/controllers/index.js +18 -0
- package/dist/src/controllers/index.js.map +1 -0
- package/dist/src/db-fallback.d.ts +26 -0
- package/dist/src/db-fallback.d.ts.map +1 -0
- package/dist/src/db-fallback.js +264 -0
- package/dist/src/db-fallback.js.map +1 -0
- package/dist/src/db-test.d.ts +13 -0
- package/dist/src/db-test.d.ts.map +1 -0
- package/dist/src/db-test.js +55 -0
- package/dist/src/db-test.js.map +1 -0
- package/dist/src/db-unified.d.ts +76 -0
- package/dist/src/db-unified.d.ts.map +1 -0
- package/dist/src/db-unified.js +279 -0
- package/dist/src/db-unified.js.map +1 -0
- package/dist/src/examples/quic-sync-example.d.ts +9 -0
- package/dist/src/examples/quic-sync-example.d.ts.map +1 -0
- package/dist/src/examples/quic-sync-example.js +169 -0
- package/dist/src/examples/quic-sync-example.js.map +1 -0
- package/dist/src/examples/wasm-vector-usage.d.ts +12 -0
- package/dist/src/examples/wasm-vector-usage.d.ts.map +1 -0
- package/dist/src/examples/wasm-vector-usage.js +190 -0
- package/dist/src/examples/wasm-vector-usage.js.map +1 -0
- package/dist/src/index.d.ts +28 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +35 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mcp/agentdb-mcp-server.d.ts +8 -0
- package/dist/src/mcp/agentdb-mcp-server.d.ts.map +1 -0
- package/dist/src/mcp/agentdb-mcp-server.js +2116 -0
- package/dist/src/mcp/agentdb-mcp-server.js.map +1 -0
- package/dist/src/mcp/learning-tools-handlers.d.ts +16 -0
- package/dist/src/mcp/learning-tools-handlers.d.ts.map +1 -0
- package/dist/src/mcp/learning-tools-handlers.js +105 -0
- package/dist/src/mcp/learning-tools-handlers.js.map +1 -0
- package/dist/src/optimizations/BatchOperations.d.ts +109 -0
- package/dist/src/optimizations/BatchOperations.d.ts.map +1 -0
- package/dist/src/optimizations/BatchOperations.js +407 -0
- package/dist/src/optimizations/BatchOperations.js.map +1 -0
- package/dist/src/optimizations/QueryOptimizer.d.ts +83 -0
- package/dist/src/optimizations/QueryOptimizer.d.ts.map +1 -0
- package/dist/src/optimizations/QueryOptimizer.js +228 -0
- package/dist/src/optimizations/QueryOptimizer.js.map +1 -0
- package/dist/src/optimizations/ToolCache.d.ts +137 -0
- package/dist/src/optimizations/ToolCache.d.ts.map +1 -0
- package/dist/src/optimizations/ToolCache.js +281 -0
- package/dist/src/optimizations/ToolCache.js.map +1 -0
- package/dist/src/optimizations/index.d.ts +10 -0
- package/dist/src/optimizations/index.d.ts.map +1 -0
- package/dist/src/optimizations/index.js +8 -0
- package/dist/src/optimizations/index.js.map +1 -0
- package/dist/src/security/input-validation.d.ts +109 -0
- package/dist/src/security/input-validation.d.ts.map +1 -0
- package/dist/src/security/input-validation.js +398 -0
- package/dist/src/security/input-validation.js.map +1 -0
- package/dist/src/security/limits.d.ts +150 -0
- package/dist/src/security/limits.d.ts.map +1 -0
- package/dist/src/security/limits.js +288 -0
- package/dist/src/security/limits.js.map +1 -0
- package/dist/src/security/path-security.d.ts +100 -0
- package/dist/src/security/path-security.d.ts.map +1 -0
- package/dist/src/security/path-security.js +337 -0
- package/dist/src/security/path-security.js.map +1 -0
- package/dist/src/security/validation.d.ts +95 -0
- package/dist/src/security/validation.d.ts.map +1 -0
- package/dist/src/security/validation.js +315 -0
- package/dist/src/security/validation.js.map +1 -0
- package/dist/src/services/LLMRouter.d.ts +84 -0
- package/dist/src/services/LLMRouter.d.ts.map +1 -0
- package/dist/src/services/LLMRouter.js +329 -0
- package/dist/src/services/LLMRouter.js.map +1 -0
- package/dist/src/types/quic.d.ts +518 -0
- package/dist/src/types/quic.d.ts.map +1 -0
- package/dist/src/types/quic.js +272 -0
- package/dist/src/types/quic.js.map +1 -0
- package/dist/src/utils/NodeIdMapper.d.ts +38 -0
- package/dist/src/utils/NodeIdMapper.d.ts.map +1 -0
- package/dist/src/utils/NodeIdMapper.js +57 -0
- package/dist/src/utils/NodeIdMapper.js.map +1 -0
- package/package.json +15 -3
- package/scripts/README.md +314 -0
- package/src/backends/GraphBackend.ts +290 -0
- package/src/backends/LearningBackend.ts +210 -0
- package/src/backends/README.md +389 -0
- package/src/backends/VectorBackend.ts +145 -0
- package/src/backends/detector.ts +283 -0
- package/src/backends/factory.ts +193 -0
- package/src/backends/graph/GraphDatabaseAdapter.ts +334 -0
- package/src/backends/hnswlib/HNSWLibBackend.ts +413 -0
- package/src/backends/hnswlib/index.ts +7 -0
- package/src/backends/index.ts +32 -0
- package/src/backends/ruvector/RuVectorBackend.ts +232 -0
- package/src/backends/ruvector/RuVectorLearning.ts +242 -0
- package/src/backends/ruvector/index.ts +9 -0
- package/src/backends/ruvector/types.d.ts +64 -0
- package/src/browser/AdvancedFeatures.ts +565 -0
- package/src/browser/HNSWIndex.ts +494 -0
- package/src/browser/ProductQuantization.ts +419 -0
- package/src/browser/index.ts +301 -0
- package/src/cli/agentdb-cli.ts +131 -8
- package/src/cli/commands/init.ts +148 -0
- package/src/cli/commands/install-embeddings.ts +81 -0
- package/src/cli/commands/migrate.ts +545 -0
- package/src/cli/commands/simulate-custom.ts +232 -0
- package/src/cli/commands/simulate-report.ts +171 -0
- package/src/cli/commands/simulate-wizard.ts +379 -0
- package/src/cli/commands/simulate.ts +115 -0
- package/src/cli/commands/status.ts +156 -0
- package/src/cli/lib/config-manager.ts +627 -0
- package/src/cli/lib/config-validator.ts +261 -0
- package/src/cli/lib/health-monitor.ts +513 -0
- package/src/cli/lib/help-formatter.ts +406 -0
- package/src/cli/lib/history-tracker.ts +497 -0
- package/src/cli/lib/report-generator.ts +455 -0
- package/src/cli/lib/report-store.ts +582 -0
- package/src/cli/lib/simulation-registry.ts +502 -0
- package/src/cli/lib/simulation-runner.ts +291 -0
- package/src/cli/tests/agentdb-cli.test.ts +58 -0
- package/src/controllers/CausalMemoryGraph.ts +42 -2
- package/src/controllers/CausalRecall.ts +41 -4
- package/src/controllers/ExplainableRecall.ts +123 -5
- package/src/controllers/HNSWIndex.ts +495 -0
- package/src/controllers/NightlyLearner.ts +8 -4
- package/src/controllers/ReasoningBank.ts +268 -5
- package/src/controllers/ReflexionMemory.ts +531 -6
- package/src/controllers/SkillLibrary.ts +234 -60
- package/src/controllers/index.ts +2 -0
- package/src/db-fallback.ts +103 -35
- package/src/db-test.ts +59 -0
- package/src/db-unified.ts +327 -0
- package/src/index.ts +2 -1
- package/src/mcp/agentdb-mcp-server.ts +544 -38
- package/src/optimizations/BatchOperations.ts +270 -0
- package/src/optimizations/ToolCache.ts +355 -0
- package/src/security/input-validation.ts +166 -0
- package/src/security/limits.ts +375 -0
- package/src/security/path-security.ts +436 -0
- package/src/security/validation.ts +556 -0
- package/src/services/LLMRouter.ts +406 -0
- package/src/types/xenova-transformers.d.ts +26 -0
- package/src/utils/NodeIdMapper.ts +64 -0
|
@@ -11,20 +11,23 @@
|
|
|
11
11
|
// Database type from db-fallback
|
|
12
12
|
type Database = any;
|
|
13
13
|
import { EmbeddingService } from './EmbeddingService.js';
|
|
14
|
+
import { VectorBackend } from '../backends/VectorBackend.js';
|
|
15
|
+
import type { GraphDatabaseAdapter } from '../backends/graph/GraphDatabaseAdapter.js';
|
|
16
|
+
import { NodeIdMapper } from '../utils/NodeIdMapper.js';
|
|
14
17
|
|
|
15
18
|
export interface Skill {
|
|
16
19
|
id?: number;
|
|
17
20
|
name: string;
|
|
18
21
|
description?: string;
|
|
19
|
-
signature:
|
|
22
|
+
signature?: { // v1 API: optional
|
|
20
23
|
inputs: Record<string, any>;
|
|
21
24
|
outputs: Record<string, any>;
|
|
22
25
|
};
|
|
23
26
|
code?: string;
|
|
24
27
|
successRate: number;
|
|
25
|
-
uses
|
|
26
|
-
avgReward
|
|
27
|
-
avgLatencyMs
|
|
28
|
+
uses?: number; // v1 API: optional (defaults to 0)
|
|
29
|
+
avgReward?: number; // v1 API: optional (defaults to 0)
|
|
30
|
+
avgLatencyMs?: number; // v1 API: optional (defaults to 0)
|
|
28
31
|
createdFromEpisode?: number;
|
|
29
32
|
metadata?: Record<string, any>;
|
|
30
33
|
}
|
|
@@ -38,7 +41,10 @@ export interface SkillLink {
|
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
export interface SkillQuery {
|
|
41
|
-
|
|
44
|
+
/** v2 API: task description */
|
|
45
|
+
task?: string;
|
|
46
|
+
/** v1 API: query string (alias for task) */
|
|
47
|
+
query?: string;
|
|
42
48
|
k?: number;
|
|
43
49
|
minSuccessRate?: number;
|
|
44
50
|
preferRecent?: boolean;
|
|
@@ -47,16 +53,45 @@ export interface SkillQuery {
|
|
|
47
53
|
export class SkillLibrary {
|
|
48
54
|
private db: Database;
|
|
49
55
|
private embedder: EmbeddingService;
|
|
56
|
+
private vectorBackend: VectorBackend | null;
|
|
57
|
+
private graphBackend?: any; // GraphBackend or GraphDatabaseAdapter
|
|
50
58
|
|
|
51
|
-
constructor(db: Database, embedder: EmbeddingService) {
|
|
59
|
+
constructor(db: Database, embedder: EmbeddingService, vectorBackend?: VectorBackend, graphBackend?: any) {
|
|
52
60
|
this.db = db;
|
|
53
61
|
this.embedder = embedder;
|
|
62
|
+
this.vectorBackend = vectorBackend || null;
|
|
63
|
+
this.graphBackend = graphBackend;
|
|
54
64
|
}
|
|
55
65
|
|
|
56
66
|
/**
|
|
57
67
|
* Create a new skill manually or from an episode
|
|
58
68
|
*/
|
|
59
69
|
async createSkill(skill: Skill): Promise<number> {
|
|
70
|
+
// Use GraphDatabaseAdapter if available (AgentDB v2)
|
|
71
|
+
if (this.graphBackend && 'storeSkill' in this.graphBackend) {
|
|
72
|
+
const graphAdapter = this.graphBackend as any as GraphDatabaseAdapter;
|
|
73
|
+
|
|
74
|
+
const text = this.buildSkillText(skill);
|
|
75
|
+
const embedding = await this.embedder.embed(text);
|
|
76
|
+
|
|
77
|
+
const nodeId = await graphAdapter.storeSkill({
|
|
78
|
+
id: skill.id ? `skill-${skill.id}` : `skill-${Date.now()}-${Math.random()}`,
|
|
79
|
+
name: skill.name,
|
|
80
|
+
description: skill.description || '',
|
|
81
|
+
code: skill.code || '',
|
|
82
|
+
usageCount: skill.uses ?? 0,
|
|
83
|
+
avgReward: skill.avgReward ?? 0,
|
|
84
|
+
createdAt: Date.now(),
|
|
85
|
+
updatedAt: Date.now(),
|
|
86
|
+
tags: JSON.stringify(skill.metadata || {})
|
|
87
|
+
}, embedding);
|
|
88
|
+
|
|
89
|
+
const numericId = parseInt(nodeId.split('-').pop() || '0', 36);
|
|
90
|
+
NodeIdMapper.getInstance().register(numericId, nodeId);
|
|
91
|
+
return numericId;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Fallback to SQLite
|
|
60
95
|
const stmt = this.db.prepare(`
|
|
61
96
|
INSERT INTO skills (
|
|
62
97
|
name, description, signature, code, success_rate, uses,
|
|
@@ -64,24 +99,46 @@ export class SkillLibrary {
|
|
|
64
99
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
65
100
|
`);
|
|
66
101
|
|
|
102
|
+
// v1 API compatibility: provide defaults for optional fields
|
|
103
|
+
const signature = skill.signature || { inputs: {}, outputs: {} };
|
|
104
|
+
const uses = skill.uses ?? 0;
|
|
105
|
+
const avgReward = skill.avgReward ?? 0;
|
|
106
|
+
const avgLatencyMs = skill.avgLatencyMs ?? 0;
|
|
107
|
+
|
|
67
108
|
const result = stmt.run(
|
|
68
109
|
skill.name,
|
|
69
110
|
skill.description || null,
|
|
70
|
-
JSON.stringify(
|
|
111
|
+
JSON.stringify(signature),
|
|
71
112
|
skill.code || null,
|
|
72
113
|
skill.successRate,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
114
|
+
uses,
|
|
115
|
+
avgReward,
|
|
116
|
+
avgLatencyMs,
|
|
76
117
|
skill.metadata ? JSON.stringify(skill.metadata) : null
|
|
77
118
|
);
|
|
78
119
|
|
|
79
120
|
const skillId = result.lastInsertRowid as number;
|
|
80
121
|
|
|
81
|
-
// Generate and store embedding
|
|
122
|
+
// Generate and store embedding in VectorBackend
|
|
82
123
|
const text = this.buildSkillText(skill);
|
|
83
124
|
const embedding = await this.embedder.embed(text);
|
|
84
|
-
|
|
125
|
+
|
|
126
|
+
// Store in VectorBackend with skill metadata (if available)
|
|
127
|
+
if (this.vectorBackend) {
|
|
128
|
+
this.vectorBackend.insert(
|
|
129
|
+
`skill:${skillId}`,
|
|
130
|
+
embedding,
|
|
131
|
+
{
|
|
132
|
+
name: skill.name,
|
|
133
|
+
description: skill.description,
|
|
134
|
+
successRate: skill.successRate,
|
|
135
|
+
avgReward: skill.avgReward
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
} else {
|
|
139
|
+
// Legacy: store in database
|
|
140
|
+
this.storeSkillEmbeddingLegacy(skillId, embedding);
|
|
141
|
+
}
|
|
85
142
|
|
|
86
143
|
return skillId;
|
|
87
144
|
}
|
|
@@ -111,33 +168,139 @@ export class SkillLibrary {
|
|
|
111
168
|
}
|
|
112
169
|
|
|
113
170
|
async retrieveSkills(query: SkillQuery): Promise<Skill[]> {
|
|
114
|
-
|
|
171
|
+
// v1 API compatibility: accept both 'query' and 'task'
|
|
172
|
+
const task = query.task || query.query;
|
|
173
|
+
if (!task) {
|
|
174
|
+
throw new Error('SkillQuery must provide either task (v2) or query (v1)');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const { k = 5, minSuccessRate = 0.5, preferRecent = true } = query;
|
|
115
178
|
|
|
116
179
|
// Generate query embedding
|
|
117
180
|
const queryEmbedding = await this.embedder.embed(task);
|
|
118
181
|
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
182
|
+
// Use GraphDatabaseAdapter if available (AgentDB v2)
|
|
183
|
+
if (this.graphBackend && 'searchSkills' in this.graphBackend) {
|
|
184
|
+
const graphAdapter = this.graphBackend as any as GraphDatabaseAdapter;
|
|
185
|
+
|
|
186
|
+
const searchResults = await graphAdapter.searchSkills(queryEmbedding, k);
|
|
187
|
+
|
|
188
|
+
return searchResults.map(result => {
|
|
189
|
+
// Handle metadata/tags parsing
|
|
190
|
+
let metadata: any = undefined;
|
|
191
|
+
if (result.tags) {
|
|
192
|
+
if (typeof result.tags === 'string') {
|
|
193
|
+
// Skip parsing if it's a String object representation
|
|
194
|
+
if (!result.tags.startsWith('String(')) {
|
|
195
|
+
try {
|
|
196
|
+
metadata = JSON.parse(result.tags);
|
|
197
|
+
} catch (e) {
|
|
198
|
+
// Invalid JSON, skip
|
|
199
|
+
metadata = undefined;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
// Already an object
|
|
204
|
+
metadata = result.tags;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
id: parseInt(result.id.split('-').pop() || '0', 36),
|
|
210
|
+
name: result.name,
|
|
211
|
+
description: result.description,
|
|
212
|
+
code: result.code,
|
|
213
|
+
successRate: result.avgReward, // Use avgReward as successRate proxy
|
|
214
|
+
uses: result.usageCount,
|
|
215
|
+
avgReward: result.avgReward,
|
|
216
|
+
metadata
|
|
217
|
+
};
|
|
218
|
+
}).filter(skill => skill.successRate >= minSuccessRate);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Use VectorBackend for semantic search (if available)
|
|
222
|
+
if (this.vectorBackend) {
|
|
223
|
+
const searchResults = this.vectorBackend.search(queryEmbedding, k * 3);
|
|
224
|
+
|
|
225
|
+
// Map results back to skill IDs and fetch full skill data
|
|
226
|
+
const skillsWithSimilarity: (Skill & { similarity: number })[] = [];
|
|
227
|
+
|
|
228
|
+
// Prepare statement ONCE outside loop (better-sqlite3 best practice)
|
|
229
|
+
const getSkillStmt = this.db.prepare('SELECT * FROM skills WHERE id = ?');
|
|
230
|
+
|
|
231
|
+
for (const result of searchResults) {
|
|
232
|
+
// Extract skill ID from vector ID (format: "skill:123")
|
|
233
|
+
const skillId = parseInt(result.id.replace('skill:', ''));
|
|
234
|
+
|
|
235
|
+
// Fetch full skill data from database
|
|
236
|
+
const row = getSkillStmt.get(skillId);
|
|
237
|
+
|
|
238
|
+
if (!row) continue;
|
|
239
|
+
|
|
240
|
+
// Apply filters
|
|
241
|
+
if (row.success_rate < minSuccessRate) continue;
|
|
242
|
+
|
|
243
|
+
skillsWithSimilarity.push({
|
|
244
|
+
id: row.id,
|
|
245
|
+
name: row.name,
|
|
246
|
+
description: row.description,
|
|
247
|
+
signature: JSON.parse(row.signature),
|
|
248
|
+
code: row.code,
|
|
249
|
+
successRate: row.success_rate,
|
|
250
|
+
uses: row.uses,
|
|
251
|
+
avgReward: row.avg_reward,
|
|
252
|
+
avgLatencyMs: row.avg_latency_ms,
|
|
253
|
+
createdFromEpisode: row.created_from_episode,
|
|
254
|
+
metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
|
|
255
|
+
similarity: result.similarity
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Compute composite scores
|
|
260
|
+
skillsWithSimilarity.sort((a, b) => {
|
|
261
|
+
const scoreA = this.computeSkillScore(a);
|
|
262
|
+
const scoreB = this.computeSkillScore(b);
|
|
263
|
+
return scoreB - scoreA;
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
return skillsWithSimilarity.slice(0, k);
|
|
267
|
+
} else {
|
|
268
|
+
// Legacy: use SQL-based similarity search
|
|
269
|
+
return this.retrieveSkillsLegacy(query);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
122
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Legacy SQL-based skill retrieval (fallback when VectorBackend not available)
|
|
275
|
+
*/
|
|
276
|
+
private async retrieveSkillsLegacy(query: SkillQuery): Promise<Skill[]> {
|
|
277
|
+
// v1 API compatibility: accept both 'query' and 'task'
|
|
278
|
+
const task = query.task || query.query;
|
|
279
|
+
if (!task) {
|
|
280
|
+
throw new Error('SkillQuery must provide either task (v2) or query (v1)');
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const { k = 5, minSuccessRate = 0.5 } = query;
|
|
284
|
+
const queryEmbedding = await this.embedder.embed(task);
|
|
285
|
+
|
|
286
|
+
// Fetch all skills with embeddings
|
|
123
287
|
const stmt = this.db.prepare(`
|
|
124
|
-
SELECT
|
|
125
|
-
s.*,
|
|
126
|
-
se.embedding
|
|
288
|
+
SELECT s.*, e.embedding
|
|
127
289
|
FROM skills s
|
|
128
|
-
JOIN skill_embeddings
|
|
129
|
-
WHERE
|
|
130
|
-
ORDER BY ${preferRecent ? 's.last_used_at DESC,' : ''} s.success_rate DESC
|
|
290
|
+
LEFT JOIN skill_embeddings e ON s.id = e.skill_id
|
|
291
|
+
WHERE s.success_rate >= ?
|
|
131
292
|
`);
|
|
293
|
+
const rows = stmt.all(minSuccessRate);
|
|
132
294
|
|
|
133
|
-
|
|
295
|
+
// Compute similarities
|
|
296
|
+
const skillsWithSimilarity: (Skill & { similarity: number })[] = [];
|
|
297
|
+
for (const row of rows) {
|
|
298
|
+
if (!row.embedding) continue;
|
|
134
299
|
|
|
135
|
-
|
|
136
|
-
const skills: (Skill & { similarity: number })[] = rows.map(row => {
|
|
137
|
-
const embedding = this.deserializeEmbedding(row.embedding);
|
|
300
|
+
const embedding = new Float32Array(row.embedding.buffer);
|
|
138
301
|
const similarity = this.cosineSimilarity(queryEmbedding, embedding);
|
|
139
302
|
|
|
140
|
-
|
|
303
|
+
skillsWithSimilarity.push({
|
|
141
304
|
id: row.id,
|
|
142
305
|
name: row.name,
|
|
143
306
|
description: row.description,
|
|
@@ -150,17 +313,47 @@ export class SkillLibrary {
|
|
|
150
313
|
createdFromEpisode: row.created_from_episode,
|
|
151
314
|
metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
|
|
152
315
|
similarity
|
|
153
|
-
};
|
|
154
|
-
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
155
318
|
|
|
156
|
-
//
|
|
157
|
-
|
|
319
|
+
// Sort by composite score
|
|
320
|
+
skillsWithSimilarity.sort((a, b) => {
|
|
158
321
|
const scoreA = this.computeSkillScore(a);
|
|
159
322
|
const scoreB = this.computeSkillScore(b);
|
|
160
323
|
return scoreB - scoreA;
|
|
161
324
|
});
|
|
162
325
|
|
|
163
|
-
return
|
|
326
|
+
return skillsWithSimilarity.slice(0, k);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Store skill embedding (legacy fallback)
|
|
331
|
+
*/
|
|
332
|
+
private storeSkillEmbeddingLegacy(skillId: number, embedding: Float32Array): void {
|
|
333
|
+
const stmt = this.db.prepare(`
|
|
334
|
+
INSERT INTO skill_embeddings (skill_id, embedding)
|
|
335
|
+
VALUES (?, ?)
|
|
336
|
+
ON CONFLICT(skill_id) DO UPDATE SET embedding = excluded.embedding
|
|
337
|
+
`);
|
|
338
|
+
const buffer = Buffer.from(embedding.buffer);
|
|
339
|
+
stmt.run(skillId, buffer);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Cosine similarity between two vectors
|
|
344
|
+
*/
|
|
345
|
+
private cosineSimilarity(a: Float32Array, b: Float32Array): number {
|
|
346
|
+
let dotProduct = 0;
|
|
347
|
+
let normA = 0;
|
|
348
|
+
let normB = 0;
|
|
349
|
+
|
|
350
|
+
for (let i = 0; i < a.length; i++) {
|
|
351
|
+
dotProduct += a[i] * b[i];
|
|
352
|
+
normA += a[i] * a[i];
|
|
353
|
+
normB += b[i] * b[i];
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
164
357
|
}
|
|
165
358
|
|
|
166
359
|
/**
|
|
@@ -592,39 +785,20 @@ export class SkillLibrary {
|
|
|
592
785
|
return parts.join('\n');
|
|
593
786
|
}
|
|
594
787
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
`);
|
|
600
|
-
stmt.run(skillId, Buffer.from(embedding.buffer));
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
private deserializeEmbedding(buffer: Buffer): Float32Array {
|
|
604
|
-
return new Float32Array(buffer.buffer, buffer.byteOffset, buffer.length / 4);
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
private cosineSimilarity(a: Float32Array, b: Float32Array): number {
|
|
608
|
-
let dotProduct = 0;
|
|
609
|
-
let normA = 0;
|
|
610
|
-
let normB = 0;
|
|
611
|
-
|
|
612
|
-
for (let i = 0; i < a.length; i++) {
|
|
613
|
-
dotProduct += a[i] * b[i];
|
|
614
|
-
normA += a[i] * a[i];
|
|
615
|
-
normB += b[i] * b[i];
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
619
|
-
}
|
|
620
|
-
|
|
788
|
+
/**
|
|
789
|
+
* Compute composite skill score from similarity and metadata
|
|
790
|
+
* VectorBackend provides normalized similarity (0-1)
|
|
791
|
+
*/
|
|
621
792
|
private computeSkillScore(skill: Skill & { similarity: number }): number {
|
|
622
793
|
// Composite score: similarity * 0.4 + success_rate * 0.3 + (uses/1000) * 0.1 + avg_reward * 0.2
|
|
794
|
+
const uses = skill.uses ?? 0;
|
|
795
|
+
const avgReward = skill.avgReward ?? 0;
|
|
796
|
+
|
|
623
797
|
return (
|
|
624
798
|
skill.similarity * 0.4 +
|
|
625
799
|
skill.successRate * 0.3 +
|
|
626
|
-
Math.min(
|
|
627
|
-
|
|
800
|
+
Math.min(uses / 1000, 1.0) * 0.1 +
|
|
801
|
+
avgReward * 0.2
|
|
628
802
|
);
|
|
629
803
|
}
|
|
630
804
|
}
|
package/src/controllers/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { ReflexionMemory } from './ReflexionMemory.js';
|
|
|
8
8
|
export { SkillLibrary } from './SkillLibrary.js';
|
|
9
9
|
export { EmbeddingService } from './EmbeddingService.js';
|
|
10
10
|
export { WASMVectorSearch } from './WASMVectorSearch.js';
|
|
11
|
+
export { HNSWIndex } from './HNSWIndex.js';
|
|
11
12
|
export { EnhancedEmbeddingService } from './EnhancedEmbeddingService.js';
|
|
12
13
|
export { MMRDiversityRanker } from './MMRDiversityRanker.js';
|
|
13
14
|
export { ContextSynthesizer } from './ContextSynthesizer.js';
|
|
@@ -20,6 +21,7 @@ export type { Episode, EpisodeWithEmbedding, ReflexionQuery } from './ReflexionM
|
|
|
20
21
|
export type { Skill, SkillLink, SkillQuery } from './SkillLibrary.js';
|
|
21
22
|
export type { EmbeddingConfig } from './EmbeddingService.js';
|
|
22
23
|
export type { VectorSearchConfig, VectorSearchResult, VectorIndex } from './WASMVectorSearch.js';
|
|
24
|
+
export type { HNSWConfig, HNSWSearchResult, HNSWStats } from './HNSWIndex.js';
|
|
23
25
|
export type { EnhancedEmbeddingConfig } from './EnhancedEmbeddingService.js';
|
|
24
26
|
export type { MMROptions, MMRCandidate } from './MMRDiversityRanker.js';
|
|
25
27
|
export type { MemoryPattern, SynthesizedContext } from './ContextSynthesizer.js';
|
package/src/db-fallback.ts
CHANGED
|
@@ -53,6 +53,9 @@ function createSqlJsWrapper(SQL: any) {
|
|
|
53
53
|
return class SqlJsDatabase {
|
|
54
54
|
private db: any;
|
|
55
55
|
private filename: string;
|
|
56
|
+
private activeStatements: Map<number, any> = new Map();
|
|
57
|
+
private statementCounter: number = 0;
|
|
58
|
+
private intervalId: NodeJS.Timeout | null = null;
|
|
56
59
|
|
|
57
60
|
constructor(filename: string, options?: any) {
|
|
58
61
|
this.filename = filename;
|
|
@@ -74,66 +77,115 @@ function createSqlJsWrapper(SQL: any) {
|
|
|
74
77
|
this.db = new SQL.Database();
|
|
75
78
|
}
|
|
76
79
|
}
|
|
80
|
+
|
|
81
|
+
// Warn if too many active statements (memory leak detection)
|
|
82
|
+
this.intervalId = setInterval(() => {
|
|
83
|
+
if (this.activeStatements.size > 50) {
|
|
84
|
+
console.warn(`⚠️ Detected ${this.activeStatements.size} active SQL statements - possible memory leak`);
|
|
85
|
+
}
|
|
86
|
+
}, 10000);
|
|
77
87
|
}
|
|
78
88
|
|
|
79
89
|
prepare(sql: string) {
|
|
80
90
|
const stmt = this.db.prepare(sql);
|
|
91
|
+
let isFinalized = false;
|
|
92
|
+
const stmtId = ++this.statementCounter;
|
|
93
|
+
|
|
94
|
+
// Track active statement
|
|
95
|
+
this.activeStatements.set(stmtId, stmt);
|
|
81
96
|
|
|
82
97
|
return {
|
|
83
98
|
run: (...params: any[]) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
changes: this.db.getRowsModified(),
|
|
90
|
-
lastInsertRowid: this.db.exec('SELECT last_insert_rowid()')[0]?.values[0]?.[0] || 0
|
|
91
|
-
};
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
get: (...params: any[]) => {
|
|
95
|
-
stmt.bind(params);
|
|
96
|
-
const hasRow = stmt.step();
|
|
97
|
-
|
|
98
|
-
if (!hasRow) {
|
|
99
|
+
if (isFinalized) throw new Error('Statement already finalized');
|
|
100
|
+
try {
|
|
101
|
+
stmt.bind(params);
|
|
102
|
+
stmt.step();
|
|
99
103
|
stmt.reset();
|
|
100
|
-
return undefined;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const columns = stmt.getColumnNames();
|
|
104
|
-
const values = stmt.get();
|
|
105
|
-
stmt.reset();
|
|
106
104
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
return {
|
|
106
|
+
changes: this.db.getRowsModified(),
|
|
107
|
+
lastInsertRowid: this.db.exec('SELECT last_insert_rowid()')[0]?.values[0]?.[0] || 0
|
|
108
|
+
};
|
|
109
|
+
} catch (error) {
|
|
110
|
+
// Auto-free on error to prevent memory leak
|
|
111
|
+
if (!isFinalized) {
|
|
112
|
+
stmt.free();
|
|
113
|
+
isFinalized = true;
|
|
114
|
+
this.activeStatements.delete(stmtId);
|
|
115
|
+
}
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
113
118
|
},
|
|
114
119
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
120
|
+
get: (...params: any[]) => {
|
|
121
|
+
if (isFinalized) throw new Error('Statement already finalized');
|
|
122
|
+
try {
|
|
123
|
+
stmt.bind(params);
|
|
124
|
+
const hasRow = stmt.step();
|
|
125
|
+
|
|
126
|
+
if (!hasRow) {
|
|
127
|
+
stmt.reset();
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
118
130
|
|
|
119
|
-
while (stmt.step()) {
|
|
120
131
|
const columns = stmt.getColumnNames();
|
|
121
132
|
const values = stmt.get();
|
|
133
|
+
stmt.reset();
|
|
122
134
|
|
|
123
135
|
const result: any = {};
|
|
124
136
|
columns.forEach((col: string, idx: number) => {
|
|
125
137
|
result[col] = values[idx];
|
|
126
138
|
});
|
|
127
139
|
|
|
128
|
-
|
|
140
|
+
return result;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
// Auto-free on error to prevent memory leak
|
|
143
|
+
if (!isFinalized) {
|
|
144
|
+
stmt.free();
|
|
145
|
+
isFinalized = true;
|
|
146
|
+
this.activeStatements.delete(stmtId);
|
|
147
|
+
}
|
|
148
|
+
throw error;
|
|
129
149
|
}
|
|
150
|
+
},
|
|
130
151
|
|
|
131
|
-
|
|
132
|
-
|
|
152
|
+
all: (...params: any[]) => {
|
|
153
|
+
if (isFinalized) throw new Error('Statement already finalized');
|
|
154
|
+
try {
|
|
155
|
+
stmt.bind(params);
|
|
156
|
+
const results: any[] = [];
|
|
157
|
+
|
|
158
|
+
while (stmt.step()) {
|
|
159
|
+
const columns = stmt.getColumnNames();
|
|
160
|
+
const values = stmt.get();
|
|
161
|
+
|
|
162
|
+
const result: any = {};
|
|
163
|
+
columns.forEach((col: string, idx: number) => {
|
|
164
|
+
result[col] = values[idx];
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
results.push(result);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
stmt.reset();
|
|
171
|
+
return results;
|
|
172
|
+
} catch (error) {
|
|
173
|
+
// Auto-free on error to prevent memory leak
|
|
174
|
+
if (!isFinalized) {
|
|
175
|
+
stmt.free();
|
|
176
|
+
isFinalized = true;
|
|
177
|
+
this.activeStatements.delete(stmtId);
|
|
178
|
+
}
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
133
181
|
},
|
|
134
182
|
|
|
135
183
|
finalize: () => {
|
|
136
|
-
|
|
184
|
+
if (!isFinalized) {
|
|
185
|
+
stmt.free();
|
|
186
|
+
isFinalized = true;
|
|
187
|
+
this.activeStatements.delete(stmtId);
|
|
188
|
+
}
|
|
137
189
|
}
|
|
138
190
|
};
|
|
139
191
|
}
|
|
@@ -162,6 +214,22 @@ function createSqlJsWrapper(SQL: any) {
|
|
|
162
214
|
}
|
|
163
215
|
|
|
164
216
|
close() {
|
|
217
|
+
// Clear interval timer
|
|
218
|
+
if (this.intervalId) {
|
|
219
|
+
clearInterval(this.intervalId);
|
|
220
|
+
this.intervalId = null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Free all active statements to prevent memory leaks
|
|
224
|
+
for (const [stmtId, stmt] of this.activeStatements.entries()) {
|
|
225
|
+
try {
|
|
226
|
+
stmt.free();
|
|
227
|
+
} catch (e) {
|
|
228
|
+
// Statement may already be freed
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
this.activeStatements.clear();
|
|
232
|
+
|
|
165
233
|
// Save to file before closing
|
|
166
234
|
this.save();
|
|
167
235
|
this.db.close();
|
package/src/db-test.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Database Factory - Uses better-sqlite3 when available for testing
|
|
3
|
+
*
|
|
4
|
+
* Integration tests need to create large datasets and run many queries,
|
|
5
|
+
* which can exceed sql.js WASM memory limit (64MB). This factory attempts
|
|
6
|
+
* to use better-sqlite3 for tests, falling back to sql.js if unavailable.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { Database } from 'better-sqlite3';
|
|
10
|
+
|
|
11
|
+
let betterSqlite3: any = null;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Try to load better-sqlite3 (optional dependency)
|
|
15
|
+
*/
|
|
16
|
+
async function loadBetterSqlite3(): Promise<any> {
|
|
17
|
+
if (betterSqlite3) return betterSqlite3;
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
betterSqlite3 = (await import('better-sqlite3')).default;
|
|
21
|
+
console.log('✅ Using better-sqlite3 for tests (no memory limit)');
|
|
22
|
+
return betterSqlite3;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.warn('⚠️ better-sqlite3 not available, falling back to sql.js (64MB memory limit)');
|
|
25
|
+
console.warn(' Install with: npm install --save-dev better-sqlite3');
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Wrap better-sqlite3 to add sql.js-compatible save() method
|
|
32
|
+
*/
|
|
33
|
+
function wrapBetterSqlite3(db: any): any {
|
|
34
|
+
// Add sql.js-compatible save() method (no-op for better-sqlite3)
|
|
35
|
+
if (!db.save) {
|
|
36
|
+
db.save = function() {
|
|
37
|
+
// better-sqlite3 auto-saves, so this is a no-op
|
|
38
|
+
return;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return db;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Create database for testing - prefers better-sqlite3, falls back to sql.js
|
|
46
|
+
*/
|
|
47
|
+
export async function createTestDatabase(filename: string, options?: any): Promise<Database> {
|
|
48
|
+
const BetterSqlite3 = await loadBetterSqlite3();
|
|
49
|
+
|
|
50
|
+
if (BetterSqlite3) {
|
|
51
|
+
// Use better-sqlite3 (native, no memory limit)
|
|
52
|
+
const db = new BetterSqlite3(filename, options);
|
|
53
|
+
return wrapBetterSqlite3(db);
|
|
54
|
+
} else {
|
|
55
|
+
// Fall back to sql.js (WASM, 64MB limit)
|
|
56
|
+
const { createDatabase } = await import('./db-fallback.js');
|
|
57
|
+
return createDatabase(filename, options);
|
|
58
|
+
}
|
|
59
|
+
}
|