agentdb 1.0.11 → 1.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/README.md +196 -838
- package/dist/benchmarks/comprehensive-benchmark.js +664 -0
- package/dist/benchmarks/frontier-benchmark.js +419 -0
- package/dist/benchmarks/reflexion-benchmark.js +370 -0
- package/dist/cli/agentdb-cli.d.ts +117 -0
- package/dist/cli/agentdb-cli.d.ts.map +1 -0
- package/dist/cli/agentdb-cli.js +718 -0
- package/dist/cli/agentdb-cli.js.map +1 -0
- package/dist/controllers/CausalMemoryGraph.d.ts +125 -0
- package/dist/controllers/CausalMemoryGraph.d.ts.map +1 -0
- package/dist/controllers/CausalMemoryGraph.js +323 -0
- package/dist/controllers/CausalMemoryGraph.js.map +1 -0
- package/dist/controllers/CausalRecall.d.ts +111 -0
- package/dist/controllers/CausalRecall.d.ts.map +1 -0
- package/dist/controllers/CausalRecall.js +282 -0
- package/dist/controllers/CausalRecall.js.map +1 -0
- package/dist/controllers/EmbeddingService.d.ts +37 -0
- package/dist/controllers/EmbeddingService.d.ts.map +1 -0
- package/dist/controllers/EmbeddingService.js +119 -0
- package/dist/controllers/EmbeddingService.js.map +1 -0
- package/dist/controllers/ExplainableRecall.d.ts +138 -0
- package/dist/controllers/ExplainableRecall.d.ts.map +1 -0
- package/dist/controllers/ExplainableRecall.js +388 -0
- package/dist/controllers/ExplainableRecall.js.map +1 -0
- package/dist/controllers/NightlyLearner.d.ts +113 -0
- package/dist/controllers/NightlyLearner.d.ts.map +1 -0
- package/dist/controllers/NightlyLearner.js +383 -0
- package/dist/controllers/NightlyLearner.js.map +1 -0
- package/dist/controllers/ReflexionMemory.d.ts +84 -0
- package/dist/controllers/ReflexionMemory.d.ts.map +1 -0
- package/dist/controllers/ReflexionMemory.js +240 -0
- package/dist/controllers/ReflexionMemory.js.map +1 -0
- package/dist/controllers/SkillLibrary.d.ts +96 -0
- package/dist/controllers/SkillLibrary.d.ts.map +1 -0
- package/dist/controllers/SkillLibrary.js +277 -0
- package/dist/controllers/SkillLibrary.js.map +1 -0
- package/dist/controllers/frontier-index.d.ts +14 -0
- package/dist/controllers/frontier-index.d.ts.map +1 -0
- package/dist/controllers/frontier-index.js +10 -0
- package/dist/controllers/frontier-index.js.map +1 -0
- package/dist/controllers/index.d.ts +12 -0
- package/dist/controllers/index.d.ts.map +1 -0
- package/dist/controllers/index.js +9 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/optimizations/BatchOperations.d.ts +61 -0
- package/dist/optimizations/BatchOperations.d.ts.map +1 -0
- package/dist/optimizations/BatchOperations.js +199 -0
- package/dist/optimizations/BatchOperations.js.map +1 -0
- package/dist/optimizations/QueryOptimizer.d.ts +82 -0
- package/dist/optimizations/QueryOptimizer.d.ts.map +1 -0
- package/dist/optimizations/QueryOptimizer.js +226 -0
- package/dist/optimizations/QueryOptimizer.js.map +1 -0
- package/dist/optimizations/index.d.ts +10 -0
- package/dist/optimizations/index.d.ts.map +1 -0
- package/dist/optimizations/index.js +8 -0
- package/dist/optimizations/index.js.map +1 -0
- package/dist/schemas/frontier-schema.sql +341 -0
- package/dist/schemas/schema.sql +382 -0
- package/dist/tests/frontier-features.test.js +665 -0
- package/package.json +54 -117
- package/src/cli/agentdb-cli.ts +861 -0
- package/src/cli/examples.sh +83 -0
- package/src/controllers/CausalMemoryGraph.ts +504 -0
- package/src/controllers/CausalRecall.ts +395 -0
- package/src/controllers/EmbeddingService.ts +141 -0
- package/src/controllers/ExplainableRecall.ts +577 -0
- package/src/controllers/NightlyLearner.ts +475 -0
- package/src/controllers/ReflexionMemory.ts +349 -0
- package/src/controllers/SkillLibrary.ts +391 -0
- package/src/controllers/frontier-index.ts +35 -0
- package/src/controllers/index.ts +13 -0
- package/src/optimizations/BatchOperations.ts +292 -0
- package/src/optimizations/QueryOptimizer.ts +294 -0
- package/src/optimizations/index.ts +11 -0
- package/src/schemas/frontier-schema.sql +341 -0
- package/src/schemas/schema.sql +382 -0
- package/CHANGELOG.md +0 -166
- package/LICENSE +0 -38
- package/LICENSE-APACHE +0 -190
- package/LICENSE-MIT +0 -21
- package/bin/agentdb.js +0 -733
- package/bin/benchmark.js +0 -162
- package/bin/plugin-cli-wrapper.mjs +0 -21
- package/dist/agentdb.js +0 -5352
- package/dist/agentdb.js.map +0 -7
- package/dist/agentdb.min.js +0 -143
- package/dist/agentdb.min.js.map +0 -7
- package/dist/cache/query-cache.d.ts +0 -105
- package/dist/cache/query-cache.d.ts.map +0 -1
- package/dist/cache/query-cache.js +0 -224
- package/dist/cache/query-cache.js.map +0 -1
- package/dist/cache/query-cache.mjs +0 -219
- package/dist/cli/cache/query-cache.d.ts +0 -104
- package/dist/cli/cache/query-cache.js +0 -244
- package/dist/cli/cli/db-commands.d.ts +0 -48
- package/dist/cli/cli/db-commands.js +0 -613
- package/dist/cli/commands.d.ts +0 -7
- package/dist/cli/commands.d.ts.map +0 -1
- package/dist/cli/commands.js +0 -113
- package/dist/cli/commands.js.map +0 -1
- package/dist/cli/commands.mjs +0 -104
- package/dist/cli/core/backend-interface.d.ts +0 -70
- package/dist/cli/core/backend-interface.js +0 -15
- package/dist/cli/core/native-backend.d.ts +0 -140
- package/dist/cli/core/native-backend.js +0 -432
- package/dist/cli/core/vector-db.d.ts +0 -126
- package/dist/cli/core/vector-db.js +0 -338
- package/dist/cli/core/wasm-backend.d.ts +0 -95
- package/dist/cli/core/wasm-backend.js +0 -418
- package/dist/cli/db-commands.d.ts +0 -49
- package/dist/cli/db-commands.d.ts.map +0 -1
- package/dist/cli/db-commands.js +0 -533
- package/dist/cli/db-commands.js.map +0 -1
- package/dist/cli/db-commands.mjs +0 -522
- package/dist/cli/generator.d.ts +0 -11
- package/dist/cli/generator.d.ts.map +0 -1
- package/dist/cli/generator.js +0 -567
- package/dist/cli/generator.js.map +0 -1
- package/dist/cli/generator.mjs +0 -527
- package/dist/cli/help.d.ts +0 -18
- package/dist/cli/help.d.ts.map +0 -1
- package/dist/cli/help.js +0 -676
- package/dist/cli/help.js.map +0 -1
- package/dist/cli/help.mjs +0 -667
- package/dist/cli/index/hnsw.d.ts +0 -164
- package/dist/cli/index/hnsw.js +0 -558
- package/dist/cli/plugin-cli.d.ts +0 -7
- package/dist/cli/plugin-cli.d.ts.map +0 -1
- package/dist/cli/plugin-cli.js +0 -295
- package/dist/cli/plugin-cli.js.map +0 -1
- package/dist/cli/plugin-cli.mjs +0 -289
- package/dist/cli/quantization/product-quantization.d.ts +0 -108
- package/dist/cli/quantization/product-quantization.js +0 -350
- package/dist/cli/query/query-builder.d.ts +0 -322
- package/dist/cli/query/query-builder.js +0 -600
- package/dist/cli/templates.d.ts +0 -14
- package/dist/cli/templates.d.ts.map +0 -1
- package/dist/cli/templates.js +0 -182
- package/dist/cli/templates.js.map +0 -1
- package/dist/cli/templates.mjs +0 -176
- package/dist/cli/types/index.d.ts +0 -116
- package/dist/cli/types/index.js +0 -5
- package/dist/cli/types.d.ts +0 -91
- package/dist/cli/types.d.ts.map +0 -1
- package/dist/cli/types.js +0 -6
- package/dist/cli/types.js.map +0 -1
- package/dist/cli/types.mjs +0 -4
- package/dist/cli/wizard/index.d.ts +0 -6
- package/dist/cli/wizard/index.d.ts.map +0 -1
- package/dist/cli/wizard/index.js +0 -138
- package/dist/cli/wizard/index.js.map +0 -1
- package/dist/cli/wizard/index.mjs +0 -131
- package/dist/cli/wizard/prompts.d.ts +0 -11
- package/dist/cli/wizard/prompts.d.ts.map +0 -1
- package/dist/cli/wizard/prompts.js +0 -482
- package/dist/cli/wizard/prompts.js.map +0 -1
- package/dist/cli/wizard/prompts.mjs +0 -470
- package/dist/cli/wizard/validator.d.ts +0 -13
- package/dist/cli/wizard/validator.d.ts.map +0 -1
- package/dist/cli/wizard/validator.js +0 -234
- package/dist/cli/wizard/validator.js.map +0 -1
- package/dist/cli/wizard/validator.mjs +0 -224
- package/dist/core/backend-interface.d.ts +0 -71
- package/dist/core/backend-interface.d.ts.map +0 -1
- package/dist/core/backend-interface.js +0 -16
- package/dist/core/backend-interface.js.map +0 -1
- package/dist/core/backend-interface.mjs +0 -12
- package/dist/core/native-backend.d.ts +0 -141
- package/dist/core/native-backend.d.ts.map +0 -1
- package/dist/core/native-backend.js +0 -457
- package/dist/core/native-backend.js.map +0 -1
- package/dist/core/native-backend.mjs +0 -449
- package/dist/core/vector-db.d.ts +0 -127
- package/dist/core/vector-db.d.ts.map +0 -1
- package/dist/core/vector-db.js +0 -270
- package/dist/core/vector-db.js.map +0 -1
- package/dist/core/vector-db.mjs +0 -265
- package/dist/core/wasm-backend.d.ts +0 -96
- package/dist/core/wasm-backend.d.ts.map +0 -1
- package/dist/core/wasm-backend.js +0 -393
- package/dist/core/wasm-backend.js.map +0 -1
- package/dist/core/wasm-backend.mjs +0 -385
- package/dist/index/hnsw-optimized.d.ts +0 -75
- package/dist/index/hnsw-optimized.d.ts.map +0 -1
- package/dist/index/hnsw-optimized.js +0 -412
- package/dist/index/hnsw-optimized.js.map +0 -1
- package/dist/index/hnsw-optimized.mjs +0 -407
- package/dist/index/hnsw.d.ts +0 -165
- package/dist/index/hnsw.d.ts.map +0 -1
- package/dist/index/hnsw.js +0 -521
- package/dist/index/hnsw.js.map +0 -1
- package/dist/index/hnsw.mjs +0 -516
- package/dist/index.browser.d.ts +0 -47
- package/dist/index.browser.d.ts.map +0 -1
- package/dist/index.browser.js +0 -72
- package/dist/index.browser.js.map +0 -1
- package/dist/index.browser.mjs +0 -54
- package/dist/index.d.ts +0 -59
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -84
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -65
- package/dist/mcp/learning/core/experience-buffer.d.ts +0 -61
- package/dist/mcp/learning/core/experience-buffer.d.ts.map +0 -1
- package/dist/mcp/learning/core/experience-buffer.js +0 -175
- package/dist/mcp/learning/core/experience-buffer.js.map +0 -1
- package/dist/mcp/learning/core/experience-buffer.mjs +0 -170
- package/dist/mcp/learning/core/experience-recorder.d.ts +0 -40
- package/dist/mcp/learning/core/experience-recorder.d.ts.map +0 -1
- package/dist/mcp/learning/core/experience-recorder.js +0 -200
- package/dist/mcp/learning/core/experience-recorder.js.map +0 -1
- package/dist/mcp/learning/core/experience-recorder.mjs +0 -195
- package/dist/mcp/learning/core/learning-manager.d.ts +0 -66
- package/dist/mcp/learning/core/learning-manager.d.ts.map +0 -1
- package/dist/mcp/learning/core/learning-manager.js +0 -252
- package/dist/mcp/learning/core/learning-manager.js.map +0 -1
- package/dist/mcp/learning/core/learning-manager.mjs +0 -247
- package/dist/mcp/learning/core/policy-optimizer.d.ts +0 -53
- package/dist/mcp/learning/core/policy-optimizer.d.ts.map +0 -1
- package/dist/mcp/learning/core/policy-optimizer.js +0 -251
- package/dist/mcp/learning/core/policy-optimizer.js.map +0 -1
- package/dist/mcp/learning/core/policy-optimizer.mjs +0 -246
- package/dist/mcp/learning/core/reward-estimator.d.ts +0 -44
- package/dist/mcp/learning/core/reward-estimator.d.ts.map +0 -1
- package/dist/mcp/learning/core/reward-estimator.js +0 -158
- package/dist/mcp/learning/core/reward-estimator.js.map +0 -1
- package/dist/mcp/learning/core/reward-estimator.mjs +0 -153
- package/dist/mcp/learning/core/session-manager.d.ts +0 -63
- package/dist/mcp/learning/core/session-manager.d.ts.map +0 -1
- package/dist/mcp/learning/core/session-manager.js +0 -202
- package/dist/mcp/learning/core/session-manager.js.map +0 -1
- package/dist/mcp/learning/core/session-manager.mjs +0 -197
- package/dist/mcp/learning/index.d.ts +0 -19
- package/dist/mcp/learning/index.d.ts.map +0 -1
- package/dist/mcp/learning/index.js +0 -30
- package/dist/mcp/learning/index.js.map +0 -1
- package/dist/mcp/learning/index.mjs +0 -19
- package/dist/mcp/learning/tools/mcp-learning-tools.d.ts +0 -369
- package/dist/mcp/learning/tools/mcp-learning-tools.d.ts.map +0 -1
- package/dist/mcp/learning/tools/mcp-learning-tools.js +0 -361
- package/dist/mcp/learning/tools/mcp-learning-tools.js.map +0 -1
- package/dist/mcp/learning/tools/mcp-learning-tools.mjs +0 -356
- package/dist/mcp/learning/types/index.d.ts +0 -138
- package/dist/mcp/learning/types/index.d.ts.map +0 -1
- package/dist/mcp/learning/types/index.js +0 -6
- package/dist/mcp/learning/types/index.js.map +0 -1
- package/dist/mcp/learning/types/index.mjs +0 -4
- package/dist/mcp-server.d.ts +0 -29
- package/dist/mcp-server.d.ts.map +0 -1
- package/dist/mcp-server.js +0 -862
- package/dist/mcp-server.js.map +0 -1
- package/dist/mcp-server.mjs +0 -857
- package/dist/plugins/base-plugin.d.ts +0 -114
- package/dist/plugins/base-plugin.d.ts.map +0 -1
- package/dist/plugins/base-plugin.js +0 -313
- package/dist/plugins/base-plugin.js.map +0 -1
- package/dist/plugins/base-plugin.mjs +0 -275
- package/dist/plugins/implementations/active-learning.d.ts +0 -135
- package/dist/plugins/implementations/active-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/active-learning.js +0 -372
- package/dist/plugins/implementations/active-learning.js.map +0 -1
- package/dist/plugins/implementations/active-learning.mjs +0 -367
- package/dist/plugins/implementations/actor-critic.d.ts +0 -64
- package/dist/plugins/implementations/actor-critic.d.ts.map +0 -1
- package/dist/plugins/implementations/actor-critic.js +0 -363
- package/dist/plugins/implementations/actor-critic.js.map +0 -1
- package/dist/plugins/implementations/actor-critic.mjs +0 -358
- package/dist/plugins/implementations/adversarial-training.d.ts +0 -133
- package/dist/plugins/implementations/adversarial-training.d.ts.map +0 -1
- package/dist/plugins/implementations/adversarial-training.js +0 -409
- package/dist/plugins/implementations/adversarial-training.js.map +0 -1
- package/dist/plugins/implementations/adversarial-training.mjs +0 -404
- package/dist/plugins/implementations/curriculum-learning.d.ts +0 -132
- package/dist/plugins/implementations/curriculum-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/curriculum-learning.js +0 -354
- package/dist/plugins/implementations/curriculum-learning.js.map +0 -1
- package/dist/plugins/implementations/curriculum-learning.mjs +0 -349
- package/dist/plugins/implementations/decision-transformer.d.ts +0 -77
- package/dist/plugins/implementations/decision-transformer.d.ts.map +0 -1
- package/dist/plugins/implementations/decision-transformer.js +0 -422
- package/dist/plugins/implementations/decision-transformer.js.map +0 -1
- package/dist/plugins/implementations/decision-transformer.mjs +0 -417
- package/dist/plugins/implementations/federated-learning.d.ts +0 -126
- package/dist/plugins/implementations/federated-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/federated-learning.js +0 -436
- package/dist/plugins/implementations/federated-learning.js.map +0 -1
- package/dist/plugins/implementations/federated-learning.mjs +0 -431
- package/dist/plugins/implementations/index.d.ts +0 -30
- package/dist/plugins/implementations/index.d.ts.map +0 -1
- package/dist/plugins/implementations/index.js +0 -45
- package/dist/plugins/implementations/index.js.map +0 -1
- package/dist/plugins/implementations/index.mjs +0 -31
- package/dist/plugins/implementations/multi-task-learning.d.ts +0 -115
- package/dist/plugins/implementations/multi-task-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/multi-task-learning.js +0 -369
- package/dist/plugins/implementations/multi-task-learning.js.map +0 -1
- package/dist/plugins/implementations/multi-task-learning.mjs +0 -364
- package/dist/plugins/implementations/neural-architecture-search.d.ts +0 -148
- package/dist/plugins/implementations/neural-architecture-search.d.ts.map +0 -1
- package/dist/plugins/implementations/neural-architecture-search.js +0 -379
- package/dist/plugins/implementations/neural-architecture-search.js.map +0 -1
- package/dist/plugins/implementations/neural-architecture-search.mjs +0 -374
- package/dist/plugins/implementations/q-learning.d.ts +0 -98
- package/dist/plugins/implementations/q-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/q-learning.js +0 -435
- package/dist/plugins/implementations/q-learning.js.map +0 -1
- package/dist/plugins/implementations/q-learning.mjs +0 -430
- package/dist/plugins/implementations/sarsa.d.ts +0 -103
- package/dist/plugins/implementations/sarsa.d.ts.map +0 -1
- package/dist/plugins/implementations/sarsa.js +0 -347
- package/dist/plugins/implementations/sarsa.js.map +0 -1
- package/dist/plugins/implementations/sarsa.mjs +0 -342
- package/dist/plugins/index.d.ts +0 -107
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/index.js +0 -179
- package/dist/plugins/index.js.map +0 -1
- package/dist/plugins/index.mjs +0 -168
- package/dist/plugins/interface.d.ts +0 -439
- package/dist/plugins/interface.d.ts.map +0 -1
- package/dist/plugins/interface.js +0 -12
- package/dist/plugins/interface.js.map +0 -1
- package/dist/plugins/interface.mjs +0 -10
- package/dist/plugins/learning-plugin.interface.d.ts +0 -257
- package/dist/plugins/learning-plugin.interface.d.ts.map +0 -1
- package/dist/plugins/learning-plugin.interface.js +0 -7
- package/dist/plugins/learning-plugin.interface.js.map +0 -1
- package/dist/plugins/learning-plugin.interface.mjs +0 -5
- package/dist/plugins/plugin-exports.d.ts +0 -71
- package/dist/plugins/plugin-exports.d.ts.map +0 -1
- package/dist/plugins/plugin-exports.js +0 -78
- package/dist/plugins/plugin-exports.js.map +0 -1
- package/dist/plugins/plugin-exports.mjs +0 -69
- package/dist/plugins/registry.d.ts +0 -206
- package/dist/plugins/registry.d.ts.map +0 -1
- package/dist/plugins/registry.js +0 -365
- package/dist/plugins/registry.js.map +0 -1
- package/dist/plugins/registry.mjs +0 -356
- package/dist/plugins/validator.d.ts +0 -63
- package/dist/plugins/validator.d.ts.map +0 -1
- package/dist/plugins/validator.js +0 -464
- package/dist/plugins/validator.js.map +0 -1
- package/dist/plugins/validator.mjs +0 -458
- package/dist/presets.d.ts +0 -65
- package/dist/presets.d.ts.map +0 -1
- package/dist/presets.js +0 -145
- package/dist/presets.js.map +0 -1
- package/dist/presets.mjs +0 -140
- package/dist/quantization/binary-quantization.d.ts +0 -104
- package/dist/quantization/binary-quantization.d.ts.map +0 -1
- package/dist/quantization/binary-quantization.js +0 -246
- package/dist/quantization/binary-quantization.js.map +0 -1
- package/dist/quantization/binary-quantization.mjs +0 -240
- package/dist/quantization/optimized-pq.d.ts +0 -138
- package/dist/quantization/optimized-pq.d.ts.map +0 -1
- package/dist/quantization/optimized-pq.js +0 -320
- package/dist/quantization/optimized-pq.js.map +0 -1
- package/dist/quantization/optimized-pq.mjs +0 -313
- package/dist/quantization/product-quantization.d.ts +0 -109
- package/dist/quantization/product-quantization.d.ts.map +0 -1
- package/dist/quantization/product-quantization.js +0 -287
- package/dist/quantization/product-quantization.js.map +0 -1
- package/dist/quantization/product-quantization.mjs +0 -282
- package/dist/quantization/scalar-quantization.d.ts +0 -100
- package/dist/quantization/scalar-quantization.d.ts.map +0 -1
- package/dist/quantization/scalar-quantization.js +0 -324
- package/dist/quantization/scalar-quantization.js.map +0 -1
- package/dist/quantization/scalar-quantization.mjs +0 -319
- package/dist/query/index.d.ts +0 -6
- package/dist/query/index.d.ts.map +0 -1
- package/dist/query/index.js +0 -9
- package/dist/query/index.js.map +0 -1
- package/dist/query/index.mjs +0 -4
- package/dist/query/query-builder.d.ts +0 -323
- package/dist/query/query-builder.d.ts.map +0 -1
- package/dist/query/query-builder.js +0 -524
- package/dist/query/query-builder.js.map +0 -1
- package/dist/query/query-builder.mjs +0 -519
- package/dist/reasoning/context-synthesizer.d.ts +0 -57
- package/dist/reasoning/context-synthesizer.d.ts.map +0 -1
- package/dist/reasoning/context-synthesizer.js +0 -224
- package/dist/reasoning/context-synthesizer.js.map +0 -1
- package/dist/reasoning/context-synthesizer.mjs +0 -219
- package/dist/reasoning/experience-curator.d.ts +0 -66
- package/dist/reasoning/experience-curator.d.ts.map +0 -1
- package/dist/reasoning/experience-curator.js +0 -288
- package/dist/reasoning/experience-curator.js.map +0 -1
- package/dist/reasoning/experience-curator.mjs +0 -283
- package/dist/reasoning/memory-optimizer.d.ts +0 -69
- package/dist/reasoning/memory-optimizer.d.ts.map +0 -1
- package/dist/reasoning/memory-optimizer.js +0 -331
- package/dist/reasoning/memory-optimizer.js.map +0 -1
- package/dist/reasoning/memory-optimizer.mjs +0 -326
- package/dist/reasoning/pattern-matcher.d.ts +0 -59
- package/dist/reasoning/pattern-matcher.d.ts.map +0 -1
- package/dist/reasoning/pattern-matcher.js +0 -229
- package/dist/reasoning/pattern-matcher.js.map +0 -1
- package/dist/reasoning/pattern-matcher.mjs +0 -224
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts +0 -118
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts.map +0 -1
- package/dist/reasoningbank/adapter/agentdb-adapter.js +0 -477
- package/dist/reasoningbank/adapter/agentdb-adapter.js.map +0 -1
- package/dist/reasoningbank/adapter/types.d.ts +0 -113
- package/dist/reasoningbank/adapter/types.d.ts.map +0 -1
- package/dist/reasoningbank/adapter/types.js +0 -9
- package/dist/reasoningbank/adapter/types.js.map +0 -1
- package/dist/reasoningbank/cli/commands.d.ts +0 -16
- package/dist/reasoningbank/cli/commands.d.ts.map +0 -1
- package/dist/reasoningbank/cli/commands.js +0 -272
- package/dist/reasoningbank/cli/commands.js.map +0 -1
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts +0 -319
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts.map +0 -1
- package/dist/reasoningbank/mcp/agentdb-tools.js +0 -301
- package/dist/reasoningbank/mcp/agentdb-tools.js.map +0 -1
- package/dist/reasoningbank/migration/migrate.d.ts +0 -25
- package/dist/reasoningbank/migration/migrate.d.ts.map +0 -1
- package/dist/reasoningbank/migration/migrate.js +0 -178
- package/dist/reasoningbank/migration/migrate.js.map +0 -1
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts +0 -37
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts.map +0 -1
- package/dist/reasoningbank/reasoning/context-synthesizer.js +0 -114
- package/dist/reasoningbank/reasoning/context-synthesizer.js.map +0 -1
- package/dist/reasoningbank/reasoning/experience-curator.d.ts +0 -39
- package/dist/reasoningbank/reasoning/experience-curator.d.ts.map +0 -1
- package/dist/reasoningbank/reasoning/experience-curator.js +0 -98
- package/dist/reasoningbank/reasoning/experience-curator.js.map +0 -1
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts +0 -44
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts.map +0 -1
- package/dist/reasoningbank/reasoning/memory-optimizer.js +0 -184
- package/dist/reasoningbank/reasoning/memory-optimizer.js.map +0 -1
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts +0 -40
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts.map +0 -1
- package/dist/reasoningbank/reasoning/pattern-matcher.js +0 -87
- package/dist/reasoningbank/reasoning/pattern-matcher.js.map +0 -1
- package/dist/reasoningbank/sync/quic-sync.d.ts +0 -77
- package/dist/reasoningbank/sync/quic-sync.d.ts.map +0 -1
- package/dist/reasoningbank/sync/quic-sync.js +0 -165
- package/dist/reasoningbank/sync/quic-sync.js.map +0 -1
- package/dist/sync/conflict.d.ts +0 -78
- package/dist/sync/conflict.d.ts.map +0 -1
- package/dist/sync/conflict.js +0 -202
- package/dist/sync/conflict.js.map +0 -1
- package/dist/sync/conflict.mjs +0 -196
- package/dist/sync/coordinator.d.ts +0 -111
- package/dist/sync/coordinator.d.ts.map +0 -1
- package/dist/sync/coordinator.js +0 -256
- package/dist/sync/coordinator.js.map +0 -1
- package/dist/sync/coordinator.mjs +0 -250
- package/dist/sync/delta.d.ts +0 -81
- package/dist/sync/delta.d.ts.map +0 -1
- package/dist/sync/delta.js +0 -245
- package/dist/sync/delta.js.map +0 -1
- package/dist/sync/delta.mjs +0 -238
- package/dist/sync/index.d.ts +0 -11
- package/dist/sync/index.d.ts.map +0 -1
- package/dist/sync/index.js +0 -22
- package/dist/sync/index.js.map +0 -1
- package/dist/sync/index.mjs +0 -9
- package/dist/sync/quic-sync.d.ts +0 -81
- package/dist/sync/quic-sync.d.ts.map +0 -1
- package/dist/sync/quic-sync.js +0 -329
- package/dist/sync/quic-sync.js.map +0 -1
- package/dist/sync/quic-sync.mjs +0 -323
- package/dist/sync/types.d.ts +0 -168
- package/dist/sync/types.d.ts.map +0 -1
- package/dist/sync/types.js +0 -8
- package/dist/sync/types.js.map +0 -1
- package/dist/sync/types.mjs +0 -6
- package/dist/types/index.d.ts +0 -117
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -6
- package/dist/types/index.js.map +0 -1
- package/dist/types/index.mjs +0 -4
- package/dist/wasm/sql-wasm-debug.js +0 -6989
- package/dist/wasm/sql-wasm-debug.wasm +0 -0
- package/dist/wasm/sql-wasm.js +0 -188
- package/dist/wasm/sql-wasm.wasm +0 -0
- package/dist/wasm-loader.d.ts +0 -32
- package/dist/wasm-loader.d.ts.map +0 -1
- package/dist/wasm-loader.js +0 -78
- package/dist/wasm-loader.js.map +0 -1
- package/dist/wasm-loader.mjs +0 -67
- package/examples/adaptive-learning.ts +0 -284
- package/examples/browser/README.md +0 -732
- package/examples/browser/adaptive-recommendations/index.html +0 -427
- package/examples/browser/collaborative-filtering/index.html +0 -310
- package/examples/browser/continual-learning/index.html +0 -736
- package/examples/browser/experience-replay/index.html +0 -616
- package/examples/browser/index.html +0 -369
- package/examples/browser/meta-learning/index.html +0 -789
- package/examples/browser/neuro-symbolic/index.html +0 -692
- package/examples/browser/pattern-learning/index.html +0 -620
- package/examples/browser/quantum-inspired/index.html +0 -728
- package/examples/browser/rag/index.html +0 -624
- package/examples/browser/swarm-intelligence/index.html +0 -811
- package/examples/browser-basic.html +0 -170
- package/examples/browser-wasm-real.html +0 -231
- package/examples/hnsw-example.ts +0 -148
- package/examples/mcp-learning-example.ts +0 -220
- package/examples/node-basic.js +0 -70
- package/examples/quic-sync-example.ts +0 -310
- package/examples/quick-start.js +0 -68
- package/examples/test-v1.0.7-cdn.html +0 -190
- package/examples/wasm-example.ts +0 -222
package/dist/sync/quic-sync.js
DELETED
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* SQLiteVector QUIC Sync - Main Synchronization Layer
|
|
4
|
-
*
|
|
5
|
-
* Real-time shard synchronization using QUIC transport from agentic-flow
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.VectorQuicSync = void 0;
|
|
9
|
-
exports.createVectorSync = createVectorSync;
|
|
10
|
-
class QuicTransport {
|
|
11
|
-
static async create(config) {
|
|
12
|
-
throw new Error('QUIC transport not available - install @agentic-flow/core or set up local QUIC server');
|
|
13
|
-
}
|
|
14
|
-
async send(address, message) {
|
|
15
|
-
throw new Error('QUIC transport not available');
|
|
16
|
-
}
|
|
17
|
-
async receive(address) {
|
|
18
|
-
throw new Error('QUIC transport not available');
|
|
19
|
-
}
|
|
20
|
-
async request(address, message) {
|
|
21
|
-
await this.send(address, message);
|
|
22
|
-
return this.receive(address);
|
|
23
|
-
}
|
|
24
|
-
async getStats() {
|
|
25
|
-
return { active: 0, idle: 0, created: 0, closed: 0 };
|
|
26
|
-
}
|
|
27
|
-
async close() { }
|
|
28
|
-
}
|
|
29
|
-
const delta_1 = require("./delta");
|
|
30
|
-
const conflict_1 = require("./conflict");
|
|
31
|
-
/**
|
|
32
|
-
* QUIC-based vector database synchronization
|
|
33
|
-
*/
|
|
34
|
-
class VectorQuicSync {
|
|
35
|
-
constructor(db, nodeId, config = {}) {
|
|
36
|
-
this.session = null;
|
|
37
|
-
this.syncTimers = new Map();
|
|
38
|
-
this.nodeId = nodeId;
|
|
39
|
-
this.changelogReader = new delta_1.ChangelogReader(db);
|
|
40
|
-
this.conflictTracker = new conflict_1.ConflictTracker();
|
|
41
|
-
// Default configuration
|
|
42
|
-
this.config = {
|
|
43
|
-
conflictStrategy: config.conflictStrategy || 'last-write-wins',
|
|
44
|
-
batchSize: config.batchSize || 100,
|
|
45
|
-
compression: config.compression ?? true,
|
|
46
|
-
syncIntervalMs: config.syncIntervalMs || 0,
|
|
47
|
-
maxRetries: config.maxRetries || 3,
|
|
48
|
-
retryBackoffMs: config.retryBackoffMs || 1000,
|
|
49
|
-
persistSession: config.persistSession ?? true
|
|
50
|
-
};
|
|
51
|
-
this.conflictResolver = new conflict_1.ConflictResolver(this.config.conflictStrategy);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Initialize QUIC transport and sync session
|
|
55
|
-
*/
|
|
56
|
-
async initialize(quicConfig) {
|
|
57
|
-
// Create QUIC transport
|
|
58
|
-
this.transport = await QuicTransport.create({
|
|
59
|
-
serverName: quicConfig?.serverName || 'vector-sync',
|
|
60
|
-
maxIdleTimeoutMs: quicConfig?.maxIdleTimeoutMs || 60000,
|
|
61
|
-
maxConcurrentStreams: quicConfig?.maxConcurrentStreams || 100,
|
|
62
|
-
enable0Rtt: quicConfig?.enable0Rtt ?? true
|
|
63
|
-
});
|
|
64
|
-
// Restore or create session
|
|
65
|
-
if (this.config.persistSession) {
|
|
66
|
-
await this.restoreSession();
|
|
67
|
-
}
|
|
68
|
-
if (!this.session) {
|
|
69
|
-
this.session = {
|
|
70
|
-
id: `session-${this.nodeId}-${Date.now()}`,
|
|
71
|
-
nodeId: this.nodeId,
|
|
72
|
-
shardIds: [],
|
|
73
|
-
lastChangeIds: new Map(),
|
|
74
|
-
versionVectors: new Map(),
|
|
75
|
-
pendingConflicts: [],
|
|
76
|
-
createdAt: Date.now() * 1000,
|
|
77
|
-
updatedAt: Date.now() * 1000
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Synchronize shard with remote peer
|
|
83
|
-
*/
|
|
84
|
-
async sync(shardId, peerAddress, force = false) {
|
|
85
|
-
const startTime = Date.now();
|
|
86
|
-
try {
|
|
87
|
-
// Add shard to session
|
|
88
|
-
if (!this.session.shardIds.includes(shardId)) {
|
|
89
|
-
this.session.shardIds.push(shardId);
|
|
90
|
-
}
|
|
91
|
-
// Get local state
|
|
92
|
-
const lastChangeId = this.session.lastChangeIds.get(shardId) || 0;
|
|
93
|
-
const localChangeId = await this.changelogReader.getLatestChangeId(shardId);
|
|
94
|
-
// Check if sync needed
|
|
95
|
-
if (!force && lastChangeId === localChangeId) {
|
|
96
|
-
return {
|
|
97
|
-
shardId,
|
|
98
|
-
changesApplied: 0,
|
|
99
|
-
conflictsDetected: 0,
|
|
100
|
-
conflictsResolved: 0,
|
|
101
|
-
conflictsUnresolved: [],
|
|
102
|
-
durationMs: Date.now() - startTime,
|
|
103
|
-
success: true
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
// Read local changes
|
|
107
|
-
const localChanges = await this.changelogReader.readChanges(shardId, lastChangeId);
|
|
108
|
-
// Request remote changes
|
|
109
|
-
const remoteChanges = await this.requestRemoteChanges(peerAddress, shardId, lastChangeId);
|
|
110
|
-
// Send local changes
|
|
111
|
-
if (localChanges.length > 0) {
|
|
112
|
-
await this.sendLocalChanges(peerAddress, shardId, localChanges);
|
|
113
|
-
}
|
|
114
|
-
// Resolve conflicts and apply changes
|
|
115
|
-
const { resolved, conflicts } = this.conflictResolver.resolveAll(localChanges, remoteChanges);
|
|
116
|
-
// Apply resolved changes
|
|
117
|
-
const applied = await this.applyChanges(shardId, resolved);
|
|
118
|
-
// Track unresolved conflicts
|
|
119
|
-
for (const conflict of conflicts) {
|
|
120
|
-
this.conflictTracker.addConflict(conflict);
|
|
121
|
-
}
|
|
122
|
-
// Update session
|
|
123
|
-
this.session.lastChangeIds.set(shardId, localChangeId);
|
|
124
|
-
const versionVector = await this.changelogReader.getVersionVector(shardId);
|
|
125
|
-
this.session.versionVectors.set(shardId, versionVector);
|
|
126
|
-
this.session.updatedAt = Date.now() * 1000;
|
|
127
|
-
if (this.config.persistSession) {
|
|
128
|
-
await this.saveSession();
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
shardId,
|
|
132
|
-
changesApplied: applied,
|
|
133
|
-
conflictsDetected: conflicts.length,
|
|
134
|
-
conflictsResolved: conflicts.length,
|
|
135
|
-
conflictsUnresolved: this.conflictTracker.getForShard(shardId),
|
|
136
|
-
durationMs: Date.now() - startTime,
|
|
137
|
-
success: true
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
return {
|
|
142
|
-
shardId,
|
|
143
|
-
changesApplied: 0,
|
|
144
|
-
conflictsDetected: 0,
|
|
145
|
-
conflictsResolved: 0,
|
|
146
|
-
conflictsUnresolved: [],
|
|
147
|
-
durationMs: Date.now() - startTime,
|
|
148
|
-
success: false,
|
|
149
|
-
error: error instanceof Error ? error.message : String(error)
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Request remote changes from peer
|
|
155
|
-
*/
|
|
156
|
-
async requestRemoteChanges(peerAddress, shardId, fromChangeId) {
|
|
157
|
-
const message = {
|
|
158
|
-
id: `sync-request-${Date.now()}`,
|
|
159
|
-
type: 'sync-request',
|
|
160
|
-
payload: {
|
|
161
|
-
shardId,
|
|
162
|
-
fromChangeId,
|
|
163
|
-
nodeId: this.nodeId
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
// Send request via QUIC
|
|
167
|
-
const response = await this.transport.request(peerAddress, message);
|
|
168
|
-
if (response.type === 'sync-response') {
|
|
169
|
-
const deltaBytes = new Uint8Array(response.payload.delta);
|
|
170
|
-
const delta = delta_1.DeltaEncoder.deserialize(deltaBytes);
|
|
171
|
-
return delta_1.DeltaEncoder.decode(delta);
|
|
172
|
-
}
|
|
173
|
-
return [];
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Send local changes to peer
|
|
177
|
-
*/
|
|
178
|
-
async sendLocalChanges(peerAddress, shardId, changes) {
|
|
179
|
-
// Batch changes
|
|
180
|
-
const batches = delta_1.DeltaEncoder.batch(changes, this.config.batchSize);
|
|
181
|
-
for (const batch of batches) {
|
|
182
|
-
const delta = delta_1.DeltaEncoder.encode(shardId, batch, this.config.compression ? 'msgpack' : 'none');
|
|
183
|
-
const deltaBytes = delta_1.DeltaEncoder.serialize(delta);
|
|
184
|
-
const message = {
|
|
185
|
-
id: `sync-push-${Date.now()}`,
|
|
186
|
-
type: 'sync-push',
|
|
187
|
-
payload: {
|
|
188
|
-
shardId,
|
|
189
|
-
delta: Array.from(deltaBytes),
|
|
190
|
-
nodeId: this.nodeId
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
await this.transport.send(peerAddress, message);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Apply changes to local database
|
|
198
|
-
*/
|
|
199
|
-
async applyChanges(shardId, changes) {
|
|
200
|
-
let applied = 0;
|
|
201
|
-
for (const change of changes) {
|
|
202
|
-
// Skip changes from this node
|
|
203
|
-
if (change.sourceNode === this.nodeId) {
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
// Apply based on operation type
|
|
207
|
-
switch (change.operation) {
|
|
208
|
-
case 'insert':
|
|
209
|
-
case 'update':
|
|
210
|
-
// Implementation would insert/update vector in database
|
|
211
|
-
applied++;
|
|
212
|
-
break;
|
|
213
|
-
case 'delete':
|
|
214
|
-
// Implementation would delete vector from database
|
|
215
|
-
applied++;
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
return applied;
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Start automatic periodic sync
|
|
223
|
-
*/
|
|
224
|
-
startAutoSync(shardId, peerAddress) {
|
|
225
|
-
if (this.config.syncIntervalMs === 0) {
|
|
226
|
-
throw new Error('syncIntervalMs must be > 0 for auto-sync');
|
|
227
|
-
}
|
|
228
|
-
// Clear existing timer
|
|
229
|
-
this.stopAutoSync(shardId);
|
|
230
|
-
// Start periodic sync
|
|
231
|
-
const timer = setInterval(async () => {
|
|
232
|
-
await this.sync(shardId, peerAddress);
|
|
233
|
-
}, this.config.syncIntervalMs);
|
|
234
|
-
this.syncTimers.set(shardId, timer);
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Stop automatic sync for shard
|
|
238
|
-
*/
|
|
239
|
-
stopAutoSync(shardId) {
|
|
240
|
-
const timer = this.syncTimers.get(shardId);
|
|
241
|
-
if (timer) {
|
|
242
|
-
clearInterval(timer);
|
|
243
|
-
this.syncTimers.delete(shardId);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Stop all automatic syncs
|
|
248
|
-
*/
|
|
249
|
-
stopAllAutoSyncs() {
|
|
250
|
-
for (const shardId of this.syncTimers.keys()) {
|
|
251
|
-
this.stopAutoSync(shardId);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Get current session
|
|
256
|
-
*/
|
|
257
|
-
getSession() {
|
|
258
|
-
return this.session;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Get shard state
|
|
262
|
-
*/
|
|
263
|
-
async getShardState(shardId) {
|
|
264
|
-
const currentChangeId = await this.changelogReader.getLatestChangeId(shardId);
|
|
265
|
-
const versionVector = await this.changelogReader.getVersionVector(shardId);
|
|
266
|
-
const lastSyncAt = this.session?.lastChangeIds.get(shardId) || 0;
|
|
267
|
-
return {
|
|
268
|
-
shardId,
|
|
269
|
-
currentChangeId,
|
|
270
|
-
versionVector,
|
|
271
|
-
vectorCount: 0, // Would query actual count
|
|
272
|
-
lastSyncAt,
|
|
273
|
-
status: 'idle'
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Get unresolved conflicts
|
|
278
|
-
*/
|
|
279
|
-
getUnresolvedConflicts(shardId) {
|
|
280
|
-
return shardId
|
|
281
|
-
? this.conflictTracker.getForShard(shardId)
|
|
282
|
-
: this.conflictTracker.getUnresolved();
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Save session to persistent storage
|
|
286
|
-
*/
|
|
287
|
-
async saveSession() {
|
|
288
|
-
if (!this.session)
|
|
289
|
-
return;
|
|
290
|
-
// Serialize session
|
|
291
|
-
const sessionData = {
|
|
292
|
-
...this.session,
|
|
293
|
-
lastChangeIds: Object.fromEntries(this.session.lastChangeIds),
|
|
294
|
-
versionVectors: Object.fromEntries(Array.from(this.session.versionVectors.entries()).map(([k, v]) => [
|
|
295
|
-
k,
|
|
296
|
-
Object.fromEntries(v)
|
|
297
|
-
]))
|
|
298
|
-
};
|
|
299
|
-
// Save to database or file
|
|
300
|
-
// Implementation depends on storage backend
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Restore session from persistent storage
|
|
304
|
-
*/
|
|
305
|
-
async restoreSession() {
|
|
306
|
-
// Load from database or file
|
|
307
|
-
// Implementation depends on storage backend
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Close sync and cleanup resources
|
|
311
|
-
*/
|
|
312
|
-
async close() {
|
|
313
|
-
this.stopAllAutoSyncs();
|
|
314
|
-
if (this.config.persistSession && this.session) {
|
|
315
|
-
await this.saveSession();
|
|
316
|
-
}
|
|
317
|
-
await this.transport.close();
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
exports.VectorQuicSync = VectorQuicSync;
|
|
321
|
-
/**
|
|
322
|
-
* Create VectorQuicSync instance with convenience wrapper
|
|
323
|
-
*/
|
|
324
|
-
async function createVectorSync(db, nodeId, config, quicConfig) {
|
|
325
|
-
const sync = new VectorQuicSync(db, nodeId, config);
|
|
326
|
-
await sync.initialize(quicConfig);
|
|
327
|
-
return sync;
|
|
328
|
-
}
|
|
329
|
-
//# sourceMappingURL=quic-sync.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"quic-sync.js","sourceRoot":"","sources":["../../src/sync/quic-sync.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAybH,4CASC;AA1aD,MAAM,aAAa;IACjB,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAA2B;QAC7C,MAAM,IAAI,KAAK,CAAC,uFAAuF,CAAC,CAAC;IAC3G,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAe,EAAE,OAAqB;QAC/C,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAe;QAC3B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAe,E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,IAAI,CAAC;AACd,CAAC"}
|
package/dist/sync/quic-sync.mjs
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SQLiteVector QUIC Sync - Main Synchronization Layer
|
|
3
|
-
*
|
|
4
|
-
* Real-time shard synchronization using QUIC transport from agentic-flow
|
|
5
|
-
*/
|
|
6
|
-
class QuicTransport {
|
|
7
|
-
static async create(config) {
|
|
8
|
-
throw new Error('QUIC transport not available - install @agentic-flow/core or set up local QUIC server');
|
|
9
|
-
}
|
|
10
|
-
async send(address, message) {
|
|
11
|
-
throw new Error('QUIC transport not available');
|
|
12
|
-
}
|
|
13
|
-
async receive(address) {
|
|
14
|
-
throw new Error('QUIC transport not available');
|
|
15
|
-
}
|
|
16
|
-
async request(address, message) {
|
|
17
|
-
await this.send(address, message);
|
|
18
|
-
return this.receive(address);
|
|
19
|
-
}
|
|
20
|
-
async getStats() {
|
|
21
|
-
return { active: 0, idle: 0, created: 0, closed: 0 };
|
|
22
|
-
}
|
|
23
|
-
async close() { }
|
|
24
|
-
}
|
|
25
|
-
import { DeltaEncoder, ChangelogReader } from './delta.mjs';
|
|
26
|
-
import { ConflictResolver, ConflictTracker } from './conflict.mjs';
|
|
27
|
-
/**
|
|
28
|
-
* QUIC-based vector database synchronization
|
|
29
|
-
*/
|
|
30
|
-
export class VectorQuicSync {
|
|
31
|
-
constructor(db, nodeId, config = {}) {
|
|
32
|
-
this.session = null;
|
|
33
|
-
this.syncTimers = new Map();
|
|
34
|
-
this.nodeId = nodeId;
|
|
35
|
-
this.changelogReader = new ChangelogReader(db);
|
|
36
|
-
this.conflictTracker = new ConflictTracker();
|
|
37
|
-
// Default configuration
|
|
38
|
-
this.config = {
|
|
39
|
-
conflictStrategy: config.conflictStrategy || 'last-write-wins',
|
|
40
|
-
batchSize: config.batchSize || 100,
|
|
41
|
-
compression: config.compression ?? true,
|
|
42
|
-
syncIntervalMs: config.syncIntervalMs || 0,
|
|
43
|
-
maxRetries: config.maxRetries || 3,
|
|
44
|
-
retryBackoffMs: config.retryBackoffMs || 1000,
|
|
45
|
-
persistSession: config.persistSession ?? true
|
|
46
|
-
};
|
|
47
|
-
this.conflictResolver = new ConflictResolver(this.config.conflictStrategy);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Initialize QUIC transport and sync session
|
|
51
|
-
*/
|
|
52
|
-
async initialize(quicConfig) {
|
|
53
|
-
// Create QUIC transport
|
|
54
|
-
this.transport = await QuicTransport.create({
|
|
55
|
-
serverName: quicConfig?.serverName || 'vector-sync',
|
|
56
|
-
maxIdleTimeoutMs: quicConfig?.maxIdleTimeoutMs || 60000,
|
|
57
|
-
maxConcurrentStreams: quicConfig?.maxConcurrentStreams || 100,
|
|
58
|
-
enable0Rtt: quicConfig?.enable0Rtt ?? true
|
|
59
|
-
});
|
|
60
|
-
// Restore or create session
|
|
61
|
-
if (this.config.persistSession) {
|
|
62
|
-
await this.restoreSession();
|
|
63
|
-
}
|
|
64
|
-
if (!this.session) {
|
|
65
|
-
this.session = {
|
|
66
|
-
id: `session-${this.nodeId}-${Date.now()}`,
|
|
67
|
-
nodeId: this.nodeId,
|
|
68
|
-
shardIds: [],
|
|
69
|
-
lastChangeIds: new Map(),
|
|
70
|
-
versionVectors: new Map(),
|
|
71
|
-
pendingConflicts: [],
|
|
72
|
-
createdAt: Date.now() * 1000,
|
|
73
|
-
updatedAt: Date.now() * 1000
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Synchronize shard with remote peer
|
|
79
|
-
*/
|
|
80
|
-
async sync(shardId, peerAddress, force = false) {
|
|
81
|
-
const startTime = Date.now();
|
|
82
|
-
try {
|
|
83
|
-
// Add shard to session
|
|
84
|
-
if (!this.session.shardIds.includes(shardId)) {
|
|
85
|
-
this.session.shardIds.push(shardId);
|
|
86
|
-
}
|
|
87
|
-
// Get local state
|
|
88
|
-
const lastChangeId = this.session.lastChangeIds.get(shardId) || 0;
|
|
89
|
-
const localChangeId = await this.changelogReader.getLatestChangeId(shardId);
|
|
90
|
-
// Check if sync needed
|
|
91
|
-
if (!force && lastChangeId === localChangeId) {
|
|
92
|
-
return {
|
|
93
|
-
shardId,
|
|
94
|
-
changesApplied: 0,
|
|
95
|
-
conflictsDetected: 0,
|
|
96
|
-
conflictsResolved: 0,
|
|
97
|
-
conflictsUnresolved: [],
|
|
98
|
-
durationMs: Date.now() - startTime,
|
|
99
|
-
success: true
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
// Read local changes
|
|
103
|
-
const localChanges = await this.changelogReader.readChanges(shardId, lastChangeId);
|
|
104
|
-
// Request remote changes
|
|
105
|
-
const remoteChanges = await this.requestRemoteChanges(peerAddress, shardId, lastChangeId);
|
|
106
|
-
// Send local changes
|
|
107
|
-
if (localChanges.length > 0) {
|
|
108
|
-
await this.sendLocalChanges(peerAddress, shardId, localChanges);
|
|
109
|
-
}
|
|
110
|
-
// Resolve conflicts and apply changes
|
|
111
|
-
const { resolved, conflicts } = this.conflictResolver.resolveAll(localChanges, remoteChanges);
|
|
112
|
-
// Apply resolved changes
|
|
113
|
-
const applied = await this.applyChanges(shardId, resolved);
|
|
114
|
-
// Track unresolved conflicts
|
|
115
|
-
for (const conflict of conflicts) {
|
|
116
|
-
this.conflictTracker.addConflict(conflict);
|
|
117
|
-
}
|
|
118
|
-
// Update session
|
|
119
|
-
this.session.lastChangeIds.set(shardId, localChangeId);
|
|
120
|
-
const versionVector = await this.changelogReader.getVersionVector(shardId);
|
|
121
|
-
this.session.versionVectors.set(shardId, versionVector);
|
|
122
|
-
this.session.updatedAt = Date.now() * 1000;
|
|
123
|
-
if (this.config.persistSession) {
|
|
124
|
-
await this.saveSession();
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
shardId,
|
|
128
|
-
changesApplied: applied,
|
|
129
|
-
conflictsDetected: conflicts.length,
|
|
130
|
-
conflictsResolved: conflicts.length,
|
|
131
|
-
conflictsUnresolved: this.conflictTracker.getForShard(shardId),
|
|
132
|
-
durationMs: Date.now() - startTime,
|
|
133
|
-
success: true
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
return {
|
|
138
|
-
shardId,
|
|
139
|
-
changesApplied: 0,
|
|
140
|
-
conflictsDetected: 0,
|
|
141
|
-
conflictsResolved: 0,
|
|
142
|
-
conflictsUnresolved: [],
|
|
143
|
-
durationMs: Date.now() - startTime,
|
|
144
|
-
success: false,
|
|
145
|
-
error: error instanceof Error ? error.message : String(error)
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Request remote changes from peer
|
|
151
|
-
*/
|
|
152
|
-
async requestRemoteChanges(peerAddress, shardId, fromChangeId) {
|
|
153
|
-
const message = {
|
|
154
|
-
id: `sync-request-${Date.now()}`,
|
|
155
|
-
type: 'sync-request',
|
|
156
|
-
payload: {
|
|
157
|
-
shardId,
|
|
158
|
-
fromChangeId,
|
|
159
|
-
nodeId: this.nodeId
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
// Send request via QUIC
|
|
163
|
-
const response = await this.transport.request(peerAddress, message);
|
|
164
|
-
if (response.type === 'sync-response') {
|
|
165
|
-
const deltaBytes = new Uint8Array(response.payload.delta);
|
|
166
|
-
const delta = DeltaEncoder.deserialize(deltaBytes);
|
|
167
|
-
return DeltaEncoder.decode(delta);
|
|
168
|
-
}
|
|
169
|
-
return [];
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Send local changes to peer
|
|
173
|
-
*/
|
|
174
|
-
async sendLocalChanges(peerAddress, shardId, changes) {
|
|
175
|
-
// Batch changes
|
|
176
|
-
const batches = DeltaEncoder.batch(changes, this.config.batchSize);
|
|
177
|
-
for (const batch of batches) {
|
|
178
|
-
const delta = DeltaEncoder.encode(shardId, batch, this.config.compression ? 'msgpack' : 'none');
|
|
179
|
-
const deltaBytes = DeltaEncoder.serialize(delta);
|
|
180
|
-
const message = {
|
|
181
|
-
id: `sync-push-${Date.now()}`,
|
|
182
|
-
type: 'sync-push',
|
|
183
|
-
payload: {
|
|
184
|
-
shardId,
|
|
185
|
-
delta: Array.from(deltaBytes),
|
|
186
|
-
nodeId: this.nodeId
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
await this.transport.send(peerAddress, message);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Apply changes to local database
|
|
194
|
-
*/
|
|
195
|
-
async applyChanges(shardId, changes) {
|
|
196
|
-
let applied = 0;
|
|
197
|
-
for (const change of changes) {
|
|
198
|
-
// Skip changes from this node
|
|
199
|
-
if (change.sourceNode === this.nodeId) {
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
// Apply based on operation type
|
|
203
|
-
switch (change.operation) {
|
|
204
|
-
case 'insert':
|
|
205
|
-
case 'update':
|
|
206
|
-
// Implementation would insert/update vector in database
|
|
207
|
-
applied++;
|
|
208
|
-
break;
|
|
209
|
-
case 'delete':
|
|
210
|
-
// Implementation would delete vector from database
|
|
211
|
-
applied++;
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return applied;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Start automatic periodic sync
|
|
219
|
-
*/
|
|
220
|
-
startAutoSync(shardId, peerAddress) {
|
|
221
|
-
if (this.config.syncIntervalMs === 0) {
|
|
222
|
-
throw new Error('syncIntervalMs must be > 0 for auto-sync');
|
|
223
|
-
}
|
|
224
|
-
// Clear existing timer
|
|
225
|
-
this.stopAutoSync(shardId);
|
|
226
|
-
// Start periodic sync
|
|
227
|
-
const timer = setInterval(async () => {
|
|
228
|
-
await this.sync(shardId, peerAddress);
|
|
229
|
-
}, this.config.syncIntervalMs);
|
|
230
|
-
this.syncTimers.set(shardId, timer);
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Stop automatic sync for shard
|
|
234
|
-
*/
|
|
235
|
-
stopAutoSync(shardId) {
|
|
236
|
-
const timer = this.syncTimers.get(shardId);
|
|
237
|
-
if (timer) {
|
|
238
|
-
clearInterval(timer);
|
|
239
|
-
this.syncTimers.delete(shardId);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Stop all automatic syncs
|
|
244
|
-
*/
|
|
245
|
-
stopAllAutoSyncs() {
|
|
246
|
-
for (const shardId of this.syncTimers.keys()) {
|
|
247
|
-
this.stopAutoSync(shardId);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Get current session
|
|
252
|
-
*/
|
|
253
|
-
getSession() {
|
|
254
|
-
return this.session;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Get shard state
|
|
258
|
-
*/
|
|
259
|
-
async getShardState(shardId) {
|
|
260
|
-
const currentChangeId = await this.changelogReader.getLatestChangeId(shardId);
|
|
261
|
-
const versionVector = await this.changelogReader.getVersionVector(shardId);
|
|
262
|
-
const lastSyncAt = this.session?.lastChangeIds.get(shardId) || 0;
|
|
263
|
-
return {
|
|
264
|
-
shardId,
|
|
265
|
-
currentChangeId,
|
|
266
|
-
versionVector,
|
|
267
|
-
vectorCount: 0, // Would query actual count
|
|
268
|
-
lastSyncAt,
|
|
269
|
-
status: 'idle'
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Get unresolved conflicts
|
|
274
|
-
*/
|
|
275
|
-
getUnresolvedConflicts(shardId) {
|
|
276
|
-
return shardId
|
|
277
|
-
? this.conflictTracker.getForShard(shardId)
|
|
278
|
-
: this.conflictTracker.getUnresolved();
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Save session to persistent storage
|
|
282
|
-
*/
|
|
283
|
-
async saveSession() {
|
|
284
|
-
if (!this.session)
|
|
285
|
-
return;
|
|
286
|
-
// Serialize session
|
|
287
|
-
const sessionData = {
|
|
288
|
-
...this.session,
|
|
289
|
-
lastChangeIds: Object.fromEntries(this.session.lastChangeIds),
|
|
290
|
-
versionVectors: Object.fromEntries(Array.from(this.session.versionVectors.entries()).map(([k, v]) => [
|
|
291
|
-
k,
|
|
292
|
-
Object.fromEntries(v)
|
|
293
|
-
]))
|
|
294
|
-
};
|
|
295
|
-
// Save to database or file
|
|
296
|
-
// Implementation depends on storage backend
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Restore session from persistent storage
|
|
300
|
-
*/
|
|
301
|
-
async restoreSession() {
|
|
302
|
-
// Load from database or file
|
|
303
|
-
// Implementation depends on storage backend
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Close sync and cleanup resources
|
|
307
|
-
*/
|
|
308
|
-
async close() {
|
|
309
|
-
this.stopAllAutoSyncs();
|
|
310
|
-
if (this.config.persistSession && this.session) {
|
|
311
|
-
await this.saveSession();
|
|
312
|
-
}
|
|
313
|
-
await this.transport.close();
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Create VectorQuicSync instance with convenience wrapper
|
|
318
|
-
*/
|
|
319
|
-
export async function createVectorSync(db, nodeId, config, quicConfig) {
|
|
320
|
-
const sync = new VectorQuicSync(db, nodeId, config);
|
|
321
|
-
await sync.initialize(quicConfig);
|
|
322
|
-
return sync;
|
|
323
|
-
}
|