agentdb 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +38 -0
- package/LICENSE-APACHE +190 -0
- package/LICENSE-MIT +21 -0
- package/README.md +953 -0
- package/bin/agentdb.js +485 -0
- package/bin/plugin-cli-wrapper.mjs +21 -0
- package/dist/cache/query-cache.d.ts +105 -0
- package/dist/cache/query-cache.d.ts.map +1 -0
- package/dist/cache/query-cache.js +224 -0
- package/dist/cache/query-cache.js.map +1 -0
- package/dist/cache/query-cache.mjs +219 -0
- package/dist/cli/cache/query-cache.d.ts +104 -0
- package/dist/cli/cache/query-cache.js +244 -0
- package/dist/cli/cli/db-commands.d.ts +48 -0
- package/dist/cli/cli/db-commands.js +613 -0
- package/dist/cli/commands.d.ts +7 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +113 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/commands.mjs +104 -0
- package/dist/cli/core/backend-interface.d.ts +70 -0
- package/dist/cli/core/backend-interface.js +15 -0
- package/dist/cli/core/native-backend.d.ts +140 -0
- package/dist/cli/core/native-backend.js +432 -0
- package/dist/cli/core/vector-db.d.ts +126 -0
- package/dist/cli/core/vector-db.js +338 -0
- package/dist/cli/core/wasm-backend.d.ts +95 -0
- package/dist/cli/core/wasm-backend.js +418 -0
- package/dist/cli/db-commands.d.ts +49 -0
- package/dist/cli/db-commands.d.ts.map +1 -0
- package/dist/cli/db-commands.js +533 -0
- package/dist/cli/db-commands.js.map +1 -0
- package/dist/cli/db-commands.mjs +522 -0
- package/dist/cli/generator.d.ts +11 -0
- package/dist/cli/generator.d.ts.map +1 -0
- package/dist/cli/generator.js +567 -0
- package/dist/cli/generator.js.map +1 -0
- package/dist/cli/generator.mjs +527 -0
- package/dist/cli/help.d.ts +18 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/help.js +676 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/help.mjs +667 -0
- package/dist/cli/index/hnsw.d.ts +164 -0
- package/dist/cli/index/hnsw.js +558 -0
- package/dist/cli/plugin-cli.d.ts +7 -0
- package/dist/cli/plugin-cli.d.ts.map +1 -0
- package/dist/cli/plugin-cli.js +295 -0
- package/dist/cli/plugin-cli.js.map +1 -0
- package/dist/cli/plugin-cli.mjs +289 -0
- package/dist/cli/quantization/product-quantization.d.ts +108 -0
- package/dist/cli/quantization/product-quantization.js +350 -0
- package/dist/cli/query/query-builder.d.ts +322 -0
- package/dist/cli/query/query-builder.js +600 -0
- package/dist/cli/templates.d.ts +14 -0
- package/dist/cli/templates.d.ts.map +1 -0
- package/dist/cli/templates.js +182 -0
- package/dist/cli/templates.js.map +1 -0
- package/dist/cli/templates.mjs +176 -0
- package/dist/cli/types/index.d.ts +116 -0
- package/dist/cli/types/index.js +5 -0
- package/dist/cli/types.d.ts +91 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +6 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/types.mjs +4 -0
- package/dist/cli/wizard/index.d.ts +6 -0
- package/dist/cli/wizard/index.d.ts.map +1 -0
- package/dist/cli/wizard/index.js +138 -0
- package/dist/cli/wizard/index.js.map +1 -0
- package/dist/cli/wizard/index.mjs +131 -0
- package/dist/cli/wizard/prompts.d.ts +11 -0
- package/dist/cli/wizard/prompts.d.ts.map +1 -0
- package/dist/cli/wizard/prompts.js +482 -0
- package/dist/cli/wizard/prompts.js.map +1 -0
- package/dist/cli/wizard/prompts.mjs +470 -0
- package/dist/cli/wizard/validator.d.ts +13 -0
- package/dist/cli/wizard/validator.d.ts.map +1 -0
- package/dist/cli/wizard/validator.js +234 -0
- package/dist/cli/wizard/validator.js.map +1 -0
- package/dist/cli/wizard/validator.mjs +224 -0
- package/dist/core/backend-interface.d.ts +71 -0
- package/dist/core/backend-interface.d.ts.map +1 -0
- package/dist/core/backend-interface.js +16 -0
- package/dist/core/backend-interface.js.map +1 -0
- package/dist/core/backend-interface.mjs +12 -0
- package/dist/core/native-backend.d.ts +141 -0
- package/dist/core/native-backend.d.ts.map +1 -0
- package/dist/core/native-backend.js +457 -0
- package/dist/core/native-backend.js.map +1 -0
- package/dist/core/native-backend.mjs +449 -0
- package/dist/core/vector-db.d.ts +127 -0
- package/dist/core/vector-db.d.ts.map +1 -0
- package/dist/core/vector-db.js +266 -0
- package/dist/core/vector-db.js.map +1 -0
- package/dist/core/vector-db.mjs +261 -0
- package/dist/core/wasm-backend.d.ts +96 -0
- package/dist/core/wasm-backend.d.ts.map +1 -0
- package/dist/core/wasm-backend.js +393 -0
- package/dist/core/wasm-backend.js.map +1 -0
- package/dist/core/wasm-backend.mjs +385 -0
- package/dist/index/hnsw-optimized.d.ts +75 -0
- package/dist/index/hnsw-optimized.d.ts.map +1 -0
- package/dist/index/hnsw-optimized.js +412 -0
- package/dist/index/hnsw-optimized.js.map +1 -0
- package/dist/index/hnsw-optimized.mjs +407 -0
- package/dist/index/hnsw.d.ts +165 -0
- package/dist/index/hnsw.d.ts.map +1 -0
- package/dist/index/hnsw.js +521 -0
- package/dist/index/hnsw.js.map +1 -0
- package/dist/index/hnsw.mjs +516 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +63 -0
- package/dist/mcp-server.d.ts +27 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +789 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/mcp-server.mjs +784 -0
- package/dist/plugins/base-plugin.d.ts +114 -0
- package/dist/plugins/base-plugin.d.ts.map +1 -0
- package/dist/plugins/base-plugin.js +313 -0
- package/dist/plugins/base-plugin.js.map +1 -0
- package/dist/plugins/base-plugin.mjs +275 -0
- package/dist/plugins/implementations/active-learning.d.ts +135 -0
- package/dist/plugins/implementations/active-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/active-learning.js +372 -0
- package/dist/plugins/implementations/active-learning.js.map +1 -0
- package/dist/plugins/implementations/active-learning.mjs +367 -0
- package/dist/plugins/implementations/actor-critic.d.ts +64 -0
- package/dist/plugins/implementations/actor-critic.d.ts.map +1 -0
- package/dist/plugins/implementations/actor-critic.js +363 -0
- package/dist/plugins/implementations/actor-critic.js.map +1 -0
- package/dist/plugins/implementations/actor-critic.mjs +358 -0
- package/dist/plugins/implementations/adversarial-training.d.ts +133 -0
- package/dist/plugins/implementations/adversarial-training.d.ts.map +1 -0
- package/dist/plugins/implementations/adversarial-training.js +409 -0
- package/dist/plugins/implementations/adversarial-training.js.map +1 -0
- package/dist/plugins/implementations/adversarial-training.mjs +404 -0
- package/dist/plugins/implementations/curriculum-learning.d.ts +132 -0
- package/dist/plugins/implementations/curriculum-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/curriculum-learning.js +354 -0
- package/dist/plugins/implementations/curriculum-learning.js.map +1 -0
- package/dist/plugins/implementations/curriculum-learning.mjs +349 -0
- package/dist/plugins/implementations/decision-transformer.d.ts +77 -0
- package/dist/plugins/implementations/decision-transformer.d.ts.map +1 -0
- package/dist/plugins/implementations/decision-transformer.js +422 -0
- package/dist/plugins/implementations/decision-transformer.js.map +1 -0
- package/dist/plugins/implementations/decision-transformer.mjs +417 -0
- package/dist/plugins/implementations/federated-learning.d.ts +126 -0
- package/dist/plugins/implementations/federated-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/federated-learning.js +436 -0
- package/dist/plugins/implementations/federated-learning.js.map +1 -0
- package/dist/plugins/implementations/federated-learning.mjs +431 -0
- package/dist/plugins/implementations/index.d.ts +30 -0
- package/dist/plugins/implementations/index.d.ts.map +1 -0
- package/dist/plugins/implementations/index.js +45 -0
- package/dist/plugins/implementations/index.js.map +1 -0
- package/dist/plugins/implementations/index.mjs +31 -0
- package/dist/plugins/implementations/multi-task-learning.d.ts +115 -0
- package/dist/plugins/implementations/multi-task-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/multi-task-learning.js +369 -0
- package/dist/plugins/implementations/multi-task-learning.js.map +1 -0
- package/dist/plugins/implementations/multi-task-learning.mjs +364 -0
- package/dist/plugins/implementations/neural-architecture-search.d.ts +148 -0
- package/dist/plugins/implementations/neural-architecture-search.d.ts.map +1 -0
- package/dist/plugins/implementations/neural-architecture-search.js +379 -0
- package/dist/plugins/implementations/neural-architecture-search.js.map +1 -0
- package/dist/plugins/implementations/neural-architecture-search.mjs +374 -0
- package/dist/plugins/implementations/q-learning.d.ts +98 -0
- package/dist/plugins/implementations/q-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/q-learning.js +435 -0
- package/dist/plugins/implementations/q-learning.js.map +1 -0
- package/dist/plugins/implementations/q-learning.mjs +430 -0
- package/dist/plugins/implementations/sarsa.d.ts +103 -0
- package/dist/plugins/implementations/sarsa.d.ts.map +1 -0
- package/dist/plugins/implementations/sarsa.js +347 -0
- package/dist/plugins/implementations/sarsa.js.map +1 -0
- package/dist/plugins/implementations/sarsa.mjs +342 -0
- package/dist/plugins/index.d.ts +107 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +179 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/index.mjs +168 -0
- package/dist/plugins/interface.d.ts +439 -0
- package/dist/plugins/interface.d.ts.map +1 -0
- package/dist/plugins/interface.js +12 -0
- package/dist/plugins/interface.js.map +1 -0
- package/dist/plugins/interface.mjs +10 -0
- package/dist/plugins/learning-plugin.interface.d.ts +257 -0
- package/dist/plugins/learning-plugin.interface.d.ts.map +1 -0
- package/dist/plugins/learning-plugin.interface.js +7 -0
- package/dist/plugins/learning-plugin.interface.js.map +1 -0
- package/dist/plugins/learning-plugin.interface.mjs +5 -0
- package/dist/plugins/plugin-exports.d.ts +71 -0
- package/dist/plugins/plugin-exports.d.ts.map +1 -0
- package/dist/plugins/plugin-exports.js +78 -0
- package/dist/plugins/plugin-exports.js.map +1 -0
- package/dist/plugins/plugin-exports.mjs +69 -0
- package/dist/plugins/registry.d.ts +206 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +365 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/registry.mjs +356 -0
- package/dist/plugins/validator.d.ts +63 -0
- package/dist/plugins/validator.d.ts.map +1 -0
- package/dist/plugins/validator.js +464 -0
- package/dist/plugins/validator.js.map +1 -0
- package/dist/plugins/validator.mjs +458 -0
- package/dist/quantization/binary-quantization.d.ts +104 -0
- package/dist/quantization/binary-quantization.d.ts.map +1 -0
- package/dist/quantization/binary-quantization.js +246 -0
- package/dist/quantization/binary-quantization.js.map +1 -0
- package/dist/quantization/binary-quantization.mjs +240 -0
- package/dist/quantization/optimized-pq.d.ts +138 -0
- package/dist/quantization/optimized-pq.d.ts.map +1 -0
- package/dist/quantization/optimized-pq.js +320 -0
- package/dist/quantization/optimized-pq.js.map +1 -0
- package/dist/quantization/optimized-pq.mjs +313 -0
- package/dist/quantization/product-quantization.d.ts +109 -0
- package/dist/quantization/product-quantization.d.ts.map +1 -0
- package/dist/quantization/product-quantization.js +287 -0
- package/dist/quantization/product-quantization.js.map +1 -0
- package/dist/quantization/product-quantization.mjs +282 -0
- package/dist/quantization/scalar-quantization.d.ts +100 -0
- package/dist/quantization/scalar-quantization.d.ts.map +1 -0
- package/dist/quantization/scalar-quantization.js +324 -0
- package/dist/quantization/scalar-quantization.js.map +1 -0
- package/dist/quantization/scalar-quantization.mjs +319 -0
- package/dist/query/index.d.ts +6 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +9 -0
- package/dist/query/index.js.map +1 -0
- package/dist/query/index.mjs +4 -0
- package/dist/query/query-builder.d.ts +323 -0
- package/dist/query/query-builder.d.ts.map +1 -0
- package/dist/query/query-builder.js +524 -0
- package/dist/query/query-builder.js.map +1 -0
- package/dist/query/query-builder.mjs +519 -0
- package/dist/reasoning/context-synthesizer.d.ts +57 -0
- package/dist/reasoning/context-synthesizer.d.ts.map +1 -0
- package/dist/reasoning/context-synthesizer.js +224 -0
- package/dist/reasoning/context-synthesizer.js.map +1 -0
- package/dist/reasoning/context-synthesizer.mjs +219 -0
- package/dist/reasoning/experience-curator.d.ts +66 -0
- package/dist/reasoning/experience-curator.d.ts.map +1 -0
- package/dist/reasoning/experience-curator.js +288 -0
- package/dist/reasoning/experience-curator.js.map +1 -0
- package/dist/reasoning/experience-curator.mjs +283 -0
- package/dist/reasoning/memory-optimizer.d.ts +69 -0
- package/dist/reasoning/memory-optimizer.d.ts.map +1 -0
- package/dist/reasoning/memory-optimizer.js +331 -0
- package/dist/reasoning/memory-optimizer.js.map +1 -0
- package/dist/reasoning/memory-optimizer.mjs +326 -0
- package/dist/reasoning/pattern-matcher.d.ts +59 -0
- package/dist/reasoning/pattern-matcher.d.ts.map +1 -0
- package/dist/reasoning/pattern-matcher.js +229 -0
- package/dist/reasoning/pattern-matcher.js.map +1 -0
- package/dist/reasoning/pattern-matcher.mjs +224 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts +118 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts.map +1 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.js +477 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.js.map +1 -0
- package/dist/reasoningbank/adapter/types.d.ts +113 -0
- package/dist/reasoningbank/adapter/types.d.ts.map +1 -0
- package/dist/reasoningbank/adapter/types.js +9 -0
- package/dist/reasoningbank/adapter/types.js.map +1 -0
- package/dist/reasoningbank/cli/commands.d.ts +16 -0
- package/dist/reasoningbank/cli/commands.d.ts.map +1 -0
- package/dist/reasoningbank/cli/commands.js +272 -0
- package/dist/reasoningbank/cli/commands.js.map +1 -0
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts +319 -0
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts.map +1 -0
- package/dist/reasoningbank/mcp/agentdb-tools.js +301 -0
- package/dist/reasoningbank/mcp/agentdb-tools.js.map +1 -0
- package/dist/reasoningbank/migration/migrate.d.ts +25 -0
- package/dist/reasoningbank/migration/migrate.d.ts.map +1 -0
- package/dist/reasoningbank/migration/migrate.js +178 -0
- package/dist/reasoningbank/migration/migrate.js.map +1 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts +37 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.js +114 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.js.map +1 -0
- package/dist/reasoningbank/reasoning/experience-curator.d.ts +39 -0
- package/dist/reasoningbank/reasoning/experience-curator.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/experience-curator.js +98 -0
- package/dist/reasoningbank/reasoning/experience-curator.js.map +1 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts +44 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.js +184 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.js.map +1 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts +40 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.js +87 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.js.map +1 -0
- package/dist/reasoningbank/sync/quic-sync.d.ts +77 -0
- package/dist/reasoningbank/sync/quic-sync.d.ts.map +1 -0
- package/dist/reasoningbank/sync/quic-sync.js +165 -0
- package/dist/reasoningbank/sync/quic-sync.js.map +1 -0
- package/dist/sync/conflict.d.ts +78 -0
- package/dist/sync/conflict.d.ts.map +1 -0
- package/dist/sync/conflict.js +202 -0
- package/dist/sync/conflict.js.map +1 -0
- package/dist/sync/conflict.mjs +196 -0
- package/dist/sync/coordinator.d.ts +111 -0
- package/dist/sync/coordinator.d.ts.map +1 -0
- package/dist/sync/coordinator.js +256 -0
- package/dist/sync/coordinator.js.map +1 -0
- package/dist/sync/coordinator.mjs +250 -0
- package/dist/sync/delta.d.ts +81 -0
- package/dist/sync/delta.d.ts.map +1 -0
- package/dist/sync/delta.js +245 -0
- package/dist/sync/delta.js.map +1 -0
- package/dist/sync/delta.mjs +238 -0
- package/dist/sync/index.d.ts +11 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +22 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/index.mjs +9 -0
- package/dist/sync/quic-sync.d.ts +81 -0
- package/dist/sync/quic-sync.d.ts.map +1 -0
- package/dist/sync/quic-sync.js +329 -0
- package/dist/sync/quic-sync.js.map +1 -0
- package/dist/sync/quic-sync.mjs +323 -0
- package/dist/sync/types.d.ts +168 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync/types.js +8 -0
- package/dist/sync/types.js.map +1 -0
- package/dist/sync/types.mjs +6 -0
- package/dist/types/index.d.ts +117 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +4 -0
- package/dist/wasm-loader.d.ts +32 -0
- package/dist/wasm-loader.d.ts.map +1 -0
- package/dist/wasm-loader.js +75 -0
- package/dist/wasm-loader.js.map +1 -0
- package/dist/wasm-loader.mjs +64 -0
- package/examples/adaptive-learning.ts +284 -0
- package/examples/browser/README.md +732 -0
- package/examples/browser/adaptive-recommendations/index.html +427 -0
- package/examples/browser/collaborative-filtering/index.html +310 -0
- package/examples/browser/continual-learning/index.html +736 -0
- package/examples/browser/experience-replay/index.html +616 -0
- package/examples/browser/index.html +369 -0
- package/examples/browser/meta-learning/index.html +789 -0
- package/examples/browser/neuro-symbolic/index.html +692 -0
- package/examples/browser/pattern-learning/index.html +620 -0
- package/examples/browser/quantum-inspired/index.html +728 -0
- package/examples/browser/rag/index.html +624 -0
- package/examples/browser/swarm-intelligence/index.html +811 -0
- package/examples/browser-basic.html +170 -0
- package/examples/hnsw-example.ts +148 -0
- package/examples/node-basic.js +70 -0
- package/examples/quic-sync-example.ts +310 -0
- package/examples/quick-start.js +68 -0
- package/examples/wasm-example.ts +222 -0
- package/package.json +118 -0
|
@@ -0,0 +1,329 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,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QAC3B,CAAC;QAED,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;CACF;AAtXD,wCAsXC;AAED;;GAEG;AACI,KAAK,UAAU,gBAAgB,CACpC,EAAO,EACP,MAAc,EACd,MAA4B,EAC5B,UAAgB;IAEhB,MAAM,IAAI,GAAG,IAAI,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACpD,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAClC,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,323 @@
|
|
|
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
|
+
}
|