@affectively/aeon 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 +21 -0
- package/README.md +332 -0
- package/dist/core/index.cjs +4 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +146 -0
- package/dist/core/index.d.ts +146 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -0
- package/dist/distributed/index.cjs +1874 -0
- package/dist/distributed/index.cjs.map +1 -0
- package/dist/distributed/index.d.cts +2 -0
- package/dist/distributed/index.d.ts +2 -0
- package/dist/distributed/index.js +1869 -0
- package/dist/distributed/index.js.map +1 -0
- package/dist/index-C_4CMV5c.d.cts +1207 -0
- package/dist/index-C_4CMV5c.d.ts +1207 -0
- package/dist/index.cjs +4671 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +812 -0
- package/dist/index.d.ts +812 -0
- package/dist/index.js +4632 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/index.cjs +64 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +38 -0
- package/dist/utils/index.d.ts +38 -0
- package/dist/utils/index.js +57 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/versioning/index.cjs +871 -0
- package/dist/versioning/index.cjs.map +1 -0
- package/dist/versioning/index.d.cts +472 -0
- package/dist/versioning/index.d.ts +472 -0
- package/dist/versioning/index.js +866 -0
- package/dist/versioning/index.js.map +1 -0
- package/package.json +142 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,812 @@
|
|
|
1
|
+
import { Operation, OperationPriority } from './core/index.js';
|
|
2
|
+
export { BandwidthProfile, CRDTOperation, ConflictDetectionResult, EventCallback, EventUnsubscribe, IEventEmitter, NetworkState, OperationStatus, OperationType, PresenceInfo, ResolutionStrategy, SyncBatch, SyncCoordinatorConfig, SyncResult, VectorClock } from './core/index.js';
|
|
3
|
+
export { Logger, createNamespacedLogger, disableLogging, getLogger, logger, resetLogger, setLogger } from './utils/index.js';
|
|
4
|
+
export { CompatibilityRule, DataTransformer, FieldTransformer, Migration, MigrationEngine, MigrationRecord, MigrationResult, MigrationState, MigrationTracker, RollbackPath, SchemaVersion, SchemaVersionManager, TransformationResult, TransformationRule, VersionMetadata } from './versioning/index.js';
|
|
5
|
+
export { A as AEON_CAPABILITIES, a as AeonCapability, b as AeonCapabilityResult, c as AeonCryptoConfig, d as AeonEncryptionMode, e as AuthenticatedMessageFields, C as Capability, D as DEFAULT_CRYPTO_CONFIG, f as DID, g as DecryptionResult, h as DomainCategory, E as ECKeyPair, i as EncryptedPayload, j as EncryptionAlgorithm, H as Handshake, I as ICryptoProvider, k as Identity, K as KeyPair, M as MergeStrategy, N as NullCryptoProvider, P as ProtocolError, R as ReconciliationResult, l as Replica, m as ReplicationEvent, n as ReplicationManager, o as ReplicationPolicy, S as SecureNodeInfo, p as SecureSyncSession, q as SignedSyncData, r as SigningAlgorithm, s as StateDiff, t as StateReconciler, u as StateVersion, v as SyncCoordinator, w as SyncEvent, x as SyncMessage, y as SyncNode, z as SyncProtocol, B as SyncRequest, F as SyncResponse, G as SyncSession, U as UCANPayload, J as UCANToken, V as VerificationResult } from './index-C_4CMV5c.js';
|
|
6
|
+
import { EventEmitter } from 'eventemitter3';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Offline Operation Queue (Phase 11)
|
|
10
|
+
*
|
|
11
|
+
* Manages pending operations for offline-first clients.
|
|
12
|
+
* Provides priority-based queuing, persistence, and retry logic.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
interface OfflineOperation {
|
|
16
|
+
id: string;
|
|
17
|
+
type: Operation['type'];
|
|
18
|
+
data: Record<string, unknown>;
|
|
19
|
+
sessionId: string;
|
|
20
|
+
priority: OperationPriority;
|
|
21
|
+
createdAt: number;
|
|
22
|
+
retryCount: number;
|
|
23
|
+
maxRetries: number;
|
|
24
|
+
lastError?: string;
|
|
25
|
+
status: 'pending' | 'syncing' | 'failed' | 'synced';
|
|
26
|
+
}
|
|
27
|
+
interface OfflineQueueStats {
|
|
28
|
+
pending: number;
|
|
29
|
+
syncing: number;
|
|
30
|
+
failed: number;
|
|
31
|
+
synced: number;
|
|
32
|
+
totalOperations: number;
|
|
33
|
+
oldestPendingMs: number;
|
|
34
|
+
averageRetries: number;
|
|
35
|
+
}
|
|
36
|
+
interface OfflineQueueEvents {
|
|
37
|
+
'operation-added': (operation: OfflineOperation) => void;
|
|
38
|
+
'operation-synced': (operation: OfflineOperation) => void;
|
|
39
|
+
'operation-failed': (operation: OfflineOperation, error: Error) => void;
|
|
40
|
+
'queue-empty': () => void;
|
|
41
|
+
'sync-started': () => void;
|
|
42
|
+
'sync-completed': (stats: {
|
|
43
|
+
synced: number;
|
|
44
|
+
failed: number;
|
|
45
|
+
}) => void;
|
|
46
|
+
}
|
|
47
|
+
declare class OfflineOperationQueue extends EventEmitter<OfflineQueueEvents> {
|
|
48
|
+
private queue;
|
|
49
|
+
private syncingIds;
|
|
50
|
+
private maxQueueSize;
|
|
51
|
+
private defaultMaxRetries;
|
|
52
|
+
constructor(maxQueueSize?: number, defaultMaxRetries?: number);
|
|
53
|
+
/**
|
|
54
|
+
* Add operation to the queue
|
|
55
|
+
*/
|
|
56
|
+
enqueue(type: Operation['type'], data: Record<string, unknown>, sessionId: string, priority?: OperationPriority, maxRetries?: number): OfflineOperation;
|
|
57
|
+
/**
|
|
58
|
+
* Get next operations to sync (by priority)
|
|
59
|
+
*/
|
|
60
|
+
getNextBatch(batchSize?: number): OfflineOperation[];
|
|
61
|
+
/**
|
|
62
|
+
* Mark operations as syncing
|
|
63
|
+
*/
|
|
64
|
+
markSyncing(operationIds: string[]): void;
|
|
65
|
+
/**
|
|
66
|
+
* Mark operation as synced
|
|
67
|
+
*/
|
|
68
|
+
markSynced(operationId: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Mark operation as failed
|
|
71
|
+
*/
|
|
72
|
+
markFailed(operationId: string, error: Error): void;
|
|
73
|
+
/**
|
|
74
|
+
* Get operation by ID
|
|
75
|
+
*/
|
|
76
|
+
getOperation(operationId: string): OfflineOperation | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Get all pending operations
|
|
79
|
+
*/
|
|
80
|
+
getPendingOperations(): OfflineOperation[];
|
|
81
|
+
/**
|
|
82
|
+
* Get pending count
|
|
83
|
+
*/
|
|
84
|
+
getPendingCount(): number;
|
|
85
|
+
/**
|
|
86
|
+
* Get queue statistics
|
|
87
|
+
*/
|
|
88
|
+
getStats(): OfflineQueueStats;
|
|
89
|
+
/**
|
|
90
|
+
* Clear all operations
|
|
91
|
+
*/
|
|
92
|
+
clear(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Clear failed operations
|
|
95
|
+
*/
|
|
96
|
+
clearFailed(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Retry failed operations
|
|
99
|
+
*/
|
|
100
|
+
retryFailed(): void;
|
|
101
|
+
/**
|
|
102
|
+
* Find oldest low-priority operation
|
|
103
|
+
*/
|
|
104
|
+
private findOldestLowPriority;
|
|
105
|
+
/**
|
|
106
|
+
* Export queue for persistence
|
|
107
|
+
*/
|
|
108
|
+
export(): OfflineOperation[];
|
|
109
|
+
/**
|
|
110
|
+
* Import queue from persistence
|
|
111
|
+
*/
|
|
112
|
+
import(operations: OfflineOperation[]): void;
|
|
113
|
+
}
|
|
114
|
+
declare function getOfflineOperationQueue(): OfflineOperationQueue;
|
|
115
|
+
declare function resetOfflineOperationQueue(): void;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Compression Engine (Phase 12)
|
|
119
|
+
*
|
|
120
|
+
* Provides compression for delta operations using native CompressionStream API.
|
|
121
|
+
* Falls back gracefully when native compression is unavailable.
|
|
122
|
+
*/
|
|
123
|
+
interface CompressedBatch {
|
|
124
|
+
id: string;
|
|
125
|
+
compressed: Uint8Array;
|
|
126
|
+
originalSize: number;
|
|
127
|
+
compressedSize: number;
|
|
128
|
+
compressionRatio: number;
|
|
129
|
+
algorithm: 'gzip' | 'deflate' | 'none';
|
|
130
|
+
timestamp: number;
|
|
131
|
+
}
|
|
132
|
+
interface CompressedChunk {
|
|
133
|
+
chunkId: string;
|
|
134
|
+
batchId: string;
|
|
135
|
+
data: Uint8Array;
|
|
136
|
+
index: number;
|
|
137
|
+
total: number;
|
|
138
|
+
checksum: string;
|
|
139
|
+
}
|
|
140
|
+
interface CompressionStats {
|
|
141
|
+
totalCompressed: number;
|
|
142
|
+
totalDecompressed: number;
|
|
143
|
+
totalOriginalBytes: number;
|
|
144
|
+
totalCompressedBytes: number;
|
|
145
|
+
averageCompressionRatio: number;
|
|
146
|
+
compressionTimeMs: number;
|
|
147
|
+
decompressionTimeMs: number;
|
|
148
|
+
}
|
|
149
|
+
declare class CompressionEngine {
|
|
150
|
+
private stats;
|
|
151
|
+
private preferredAlgorithm;
|
|
152
|
+
constructor(preferredAlgorithm?: 'gzip' | 'deflate');
|
|
153
|
+
/**
|
|
154
|
+
* Check if native compression is available
|
|
155
|
+
*/
|
|
156
|
+
supportsNativeCompression(): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Compress data
|
|
159
|
+
*/
|
|
160
|
+
compress(data: Uint8Array | string): Promise<CompressedBatch>;
|
|
161
|
+
/**
|
|
162
|
+
* Decompress data
|
|
163
|
+
*/
|
|
164
|
+
decompress(batch: CompressedBatch): Promise<Uint8Array>;
|
|
165
|
+
/**
|
|
166
|
+
* Compress using native CompressionStream
|
|
167
|
+
*/
|
|
168
|
+
private compressNative;
|
|
169
|
+
/**
|
|
170
|
+
* Decompress using native DecompressionStream
|
|
171
|
+
*/
|
|
172
|
+
private decompressNative;
|
|
173
|
+
/**
|
|
174
|
+
* Split compressed batch into chunks for transmission
|
|
175
|
+
*/
|
|
176
|
+
splitIntoChunks(batch: CompressedBatch, chunkSize?: number): CompressedChunk[];
|
|
177
|
+
/**
|
|
178
|
+
* Reassemble chunks into compressed batch
|
|
179
|
+
*/
|
|
180
|
+
reassembleChunks(chunks: CompressedChunk[]): Uint8Array;
|
|
181
|
+
/**
|
|
182
|
+
* Simple checksum for chunk verification
|
|
183
|
+
*/
|
|
184
|
+
private simpleChecksum;
|
|
185
|
+
/**
|
|
186
|
+
* Update average compression ratio
|
|
187
|
+
*/
|
|
188
|
+
private updateAverageRatio;
|
|
189
|
+
/**
|
|
190
|
+
* Get statistics
|
|
191
|
+
*/
|
|
192
|
+
getStats(): CompressionStats;
|
|
193
|
+
/**
|
|
194
|
+
* Reset statistics
|
|
195
|
+
*/
|
|
196
|
+
resetStats(): void;
|
|
197
|
+
}
|
|
198
|
+
declare function getCompressionEngine(): CompressionEngine;
|
|
199
|
+
declare function resetCompressionEngine(): void;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Delta Sync Optimizer (Phase 12)
|
|
203
|
+
*
|
|
204
|
+
* Implements field-level change detection to reduce payload size.
|
|
205
|
+
* Computes delta between current and previous operation state.
|
|
206
|
+
*
|
|
207
|
+
* Performance Impact:
|
|
208
|
+
* - Delta sync alone: 70-80% payload reduction
|
|
209
|
+
* - Combined with compression: 80-90% total reduction
|
|
210
|
+
*/
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Delta operation - represents only changed fields
|
|
214
|
+
*/
|
|
215
|
+
interface DeltaOperation {
|
|
216
|
+
id: string;
|
|
217
|
+
type: 'full' | 'delta';
|
|
218
|
+
operationId: string;
|
|
219
|
+
operationType: Operation['type'];
|
|
220
|
+
sessionId: string;
|
|
221
|
+
timestamp: number;
|
|
222
|
+
changes?: Record<string, unknown>;
|
|
223
|
+
changeMask?: string[];
|
|
224
|
+
fullData?: Record<string, unknown>;
|
|
225
|
+
priority?: 'high' | 'normal' | 'low';
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Batch of delta operations
|
|
229
|
+
*/
|
|
230
|
+
interface DeltaBatch {
|
|
231
|
+
batchId: string;
|
|
232
|
+
operations: DeltaOperation[];
|
|
233
|
+
timestamp: number;
|
|
234
|
+
totalOriginalSize: number;
|
|
235
|
+
totalDeltaSize: number;
|
|
236
|
+
reductionPercent: number;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Statistics about delta sync performance
|
|
240
|
+
*/
|
|
241
|
+
interface DeltaStats {
|
|
242
|
+
totalOperations: number;
|
|
243
|
+
totalFull: number;
|
|
244
|
+
totalDelta: number;
|
|
245
|
+
totalOriginalSize: number;
|
|
246
|
+
totalDeltaSize: number;
|
|
247
|
+
averageReductionPercent: number;
|
|
248
|
+
lastSyncTime: number;
|
|
249
|
+
fullOperationThreshold: number;
|
|
250
|
+
}
|
|
251
|
+
declare class DeltaSyncOptimizer {
|
|
252
|
+
private operationHistory;
|
|
253
|
+
private stats;
|
|
254
|
+
constructor(fullOperationThreshold?: number);
|
|
255
|
+
/**
|
|
256
|
+
* Compute delta for single operation
|
|
257
|
+
*/
|
|
258
|
+
computeDelta(operation: Operation): DeltaOperation;
|
|
259
|
+
/**
|
|
260
|
+
* Compute deltas for batch of operations
|
|
261
|
+
*/
|
|
262
|
+
computeBatchDeltas(operations: Operation[]): DeltaBatch;
|
|
263
|
+
/**
|
|
264
|
+
* Decompress delta operation back to full operation
|
|
265
|
+
*/
|
|
266
|
+
decompressDelta(delta: DeltaOperation): Operation;
|
|
267
|
+
/**
|
|
268
|
+
* Update history after successful sync
|
|
269
|
+
*/
|
|
270
|
+
updateHistory(operations: Operation[]): void;
|
|
271
|
+
/**
|
|
272
|
+
* Clear history for specific operations
|
|
273
|
+
*/
|
|
274
|
+
clearHistory(operationIds: string[]): void;
|
|
275
|
+
/**
|
|
276
|
+
* Get current performance statistics
|
|
277
|
+
*/
|
|
278
|
+
getStats(): DeltaStats;
|
|
279
|
+
/**
|
|
280
|
+
* Reset statistics
|
|
281
|
+
*/
|
|
282
|
+
resetStats(): void;
|
|
283
|
+
/**
|
|
284
|
+
* Set the full operation threshold
|
|
285
|
+
*/
|
|
286
|
+
setFullOperationThreshold(bytes: number): void;
|
|
287
|
+
/**
|
|
288
|
+
* Get history size for memory monitoring
|
|
289
|
+
*/
|
|
290
|
+
getHistorySize(): number;
|
|
291
|
+
/**
|
|
292
|
+
* Get memory footprint estimate
|
|
293
|
+
*/
|
|
294
|
+
getMemoryEstimate(): number;
|
|
295
|
+
/**
|
|
296
|
+
* Deep equality check for nested objects
|
|
297
|
+
*/
|
|
298
|
+
private deepEqual;
|
|
299
|
+
}
|
|
300
|
+
declare function getDeltaSyncOptimizer(threshold?: number): DeltaSyncOptimizer;
|
|
301
|
+
declare function resetDeltaSyncOptimizer(): void;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Prefetching Engine (Phase 13)
|
|
305
|
+
*
|
|
306
|
+
* Predictively pre-compresses batches based on detected operation patterns.
|
|
307
|
+
* Analyzes historical data to predict which operations are most likely to occur.
|
|
308
|
+
*/
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Pattern in operation sequence
|
|
312
|
+
*/
|
|
313
|
+
interface OperationPattern {
|
|
314
|
+
sequence: string[];
|
|
315
|
+
frequency: number;
|
|
316
|
+
probability: number;
|
|
317
|
+
lastOccurred: number;
|
|
318
|
+
avgIntervalMs: number;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Prediction for next operations
|
|
322
|
+
*/
|
|
323
|
+
interface OperationPrediction {
|
|
324
|
+
operationType: string;
|
|
325
|
+
probability: number;
|
|
326
|
+
reason: string;
|
|
327
|
+
shouldPrefetch: boolean;
|
|
328
|
+
estimatedTimeMs: number;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Prefetched batch
|
|
332
|
+
*/
|
|
333
|
+
interface PrefetchedBatch {
|
|
334
|
+
id: string;
|
|
335
|
+
operationType: string;
|
|
336
|
+
compressed: Uint8Array;
|
|
337
|
+
compressedSize: number;
|
|
338
|
+
originalSize: number;
|
|
339
|
+
compressionRatio: number;
|
|
340
|
+
compressed_at: number;
|
|
341
|
+
created_at: number;
|
|
342
|
+
ttl: number;
|
|
343
|
+
expiresAt: number;
|
|
344
|
+
hitCount: number;
|
|
345
|
+
missCount: number;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Prefetching statistics
|
|
349
|
+
*/
|
|
350
|
+
interface PrefetchingStats {
|
|
351
|
+
totalPrefetched: number;
|
|
352
|
+
totalHits: number;
|
|
353
|
+
totalMisses: number;
|
|
354
|
+
totalOverwrites: number;
|
|
355
|
+
hitRatio: number;
|
|
356
|
+
bandwidthSaved: number;
|
|
357
|
+
patternsDetected: number;
|
|
358
|
+
predictionAccuracy: number;
|
|
359
|
+
}
|
|
360
|
+
declare class PrefetchingEngine {
|
|
361
|
+
private operationHistory;
|
|
362
|
+
private patterns;
|
|
363
|
+
private prefetchCache;
|
|
364
|
+
private maxHistoryEntries;
|
|
365
|
+
private maxCachePerType;
|
|
366
|
+
private prefetchTTL;
|
|
367
|
+
private predictionThreshold;
|
|
368
|
+
private stats;
|
|
369
|
+
private lastPredictionTime;
|
|
370
|
+
private predictionInterval;
|
|
371
|
+
constructor();
|
|
372
|
+
/**
|
|
373
|
+
* Record operation for pattern analysis
|
|
374
|
+
*/
|
|
375
|
+
recordOperation(operationType: string, size: number): void;
|
|
376
|
+
/**
|
|
377
|
+
* Analyze patterns in operation history
|
|
378
|
+
*/
|
|
379
|
+
private analyzePatterns;
|
|
380
|
+
/**
|
|
381
|
+
* Predict next operations
|
|
382
|
+
*/
|
|
383
|
+
predictNextOperations(recentOperations: Operation[]): OperationPrediction[];
|
|
384
|
+
/**
|
|
385
|
+
* Add prefetched batch
|
|
386
|
+
*/
|
|
387
|
+
addPrefetchedBatch(operationType: string, compressed: Uint8Array, originalSize: number): PrefetchedBatch;
|
|
388
|
+
/**
|
|
389
|
+
* Try to use prefetched batch
|
|
390
|
+
*/
|
|
391
|
+
getPrefetchedBatch(operationType: string): PrefetchedBatch | null;
|
|
392
|
+
/**
|
|
393
|
+
* Update prediction accuracy metric
|
|
394
|
+
*/
|
|
395
|
+
private updatePredictionAccuracy;
|
|
396
|
+
/**
|
|
397
|
+
* Clean expired prefetches
|
|
398
|
+
*/
|
|
399
|
+
private cleanExpiredPrefetches;
|
|
400
|
+
/**
|
|
401
|
+
* Get statistics
|
|
402
|
+
*/
|
|
403
|
+
getStats(): PrefetchingStats;
|
|
404
|
+
/**
|
|
405
|
+
* Clear all caches
|
|
406
|
+
*/
|
|
407
|
+
clear(): void;
|
|
408
|
+
}
|
|
409
|
+
declare function getPrefetchingEngine(): PrefetchingEngine;
|
|
410
|
+
declare function resetPrefetchingEngine(): void;
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Batch Timing Optimizer (Phase 13)
|
|
414
|
+
*
|
|
415
|
+
* Intelligently schedules batch transmission based on network conditions,
|
|
416
|
+
* device resources, and user activity patterns.
|
|
417
|
+
*/
|
|
418
|
+
/**
|
|
419
|
+
* Network window quality assessment
|
|
420
|
+
*/
|
|
421
|
+
interface NetworkWindow {
|
|
422
|
+
startTime: number;
|
|
423
|
+
endTime: number;
|
|
424
|
+
expectedDurationMs: number;
|
|
425
|
+
latencyMs: number;
|
|
426
|
+
bandwidthMbps: number;
|
|
427
|
+
quality: 'excellent' | 'good' | 'fair' | 'poor';
|
|
428
|
+
isStable: boolean;
|
|
429
|
+
congestionLevel: number;
|
|
430
|
+
recommendedBatchSize: number;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Activity pattern
|
|
434
|
+
*/
|
|
435
|
+
interface ActivityPattern {
|
|
436
|
+
type: 'user-active' | 'idle' | 'background' | 'sleep';
|
|
437
|
+
startTime: number;
|
|
438
|
+
duration: number;
|
|
439
|
+
probability: number;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Batch scheduling decision
|
|
443
|
+
*/
|
|
444
|
+
interface SchedulingDecision {
|
|
445
|
+
shouldSendNow: boolean;
|
|
446
|
+
nextOptimalWindowMs: number;
|
|
447
|
+
recommendedDelay: number;
|
|
448
|
+
reason: string;
|
|
449
|
+
priority: 'critical' | 'high' | 'normal' | 'low';
|
|
450
|
+
estimatedDeliveryMs: number;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Batch timing statistics
|
|
454
|
+
*/
|
|
455
|
+
interface BatchTimingStats {
|
|
456
|
+
totalBatches: number;
|
|
457
|
+
immediateDeliveries: number;
|
|
458
|
+
deferredBatches: number;
|
|
459
|
+
averageWaitTimeMs: number;
|
|
460
|
+
averageDeliveryTimeMs: number;
|
|
461
|
+
networkWindowsUsed: number;
|
|
462
|
+
congestionAvoided: number;
|
|
463
|
+
userFocusedOptimizations: number;
|
|
464
|
+
}
|
|
465
|
+
declare class BatchTimingOptimizer {
|
|
466
|
+
private networkHistory;
|
|
467
|
+
private activityHistory;
|
|
468
|
+
private stats;
|
|
469
|
+
private lastActivityTime;
|
|
470
|
+
private isUserActive;
|
|
471
|
+
private congestionDetectionWindow;
|
|
472
|
+
private optimalBatchSize;
|
|
473
|
+
constructor();
|
|
474
|
+
/**
|
|
475
|
+
* Record network measurement
|
|
476
|
+
*/
|
|
477
|
+
recordNetworkMeasurement(latencyMs: number, bandwidthMbps: number): void;
|
|
478
|
+
/**
|
|
479
|
+
* Assess network quality
|
|
480
|
+
*/
|
|
481
|
+
private assessNetworkQuality;
|
|
482
|
+
/**
|
|
483
|
+
* Detect congestion in network
|
|
484
|
+
*/
|
|
485
|
+
private detectCongestion;
|
|
486
|
+
/**
|
|
487
|
+
* Find next optimal network window
|
|
488
|
+
*/
|
|
489
|
+
private findOptimalWindow;
|
|
490
|
+
/**
|
|
491
|
+
* Get scheduling decision for a batch
|
|
492
|
+
*/
|
|
493
|
+
getSchedulingDecision(batchSize: number, batchPriority?: 'critical' | 'high' | 'normal' | 'low', isUserTriggered?: boolean): SchedulingDecision;
|
|
494
|
+
/**
|
|
495
|
+
* Apply scheduling and update stats
|
|
496
|
+
*/
|
|
497
|
+
applyScheduling(batchSize: number, sendNow: boolean, actualDelay: number): void;
|
|
498
|
+
/**
|
|
499
|
+
* Get optimal batch size recommendation
|
|
500
|
+
*/
|
|
501
|
+
getOptimalBatchSize(): number;
|
|
502
|
+
/**
|
|
503
|
+
* Get current network window
|
|
504
|
+
*/
|
|
505
|
+
getCurrentNetworkWindow(): NetworkWindow;
|
|
506
|
+
/**
|
|
507
|
+
* Set user activity state
|
|
508
|
+
*/
|
|
509
|
+
setUserActive(active: boolean): void;
|
|
510
|
+
/**
|
|
511
|
+
* Get statistics
|
|
512
|
+
*/
|
|
513
|
+
getStats(): BatchTimingStats;
|
|
514
|
+
/**
|
|
515
|
+
* Clear history
|
|
516
|
+
*/
|
|
517
|
+
clear(): void;
|
|
518
|
+
}
|
|
519
|
+
declare function getBatchTimingOptimizer(): BatchTimingOptimizer;
|
|
520
|
+
declare function resetBatchTimingOptimizer(): void;
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Adaptive Compression Optimizer (Phase 13)
|
|
524
|
+
*
|
|
525
|
+
* Automatically adjusts compression level based on network conditions,
|
|
526
|
+
* device capabilities, and real-time performance metrics.
|
|
527
|
+
*/
|
|
528
|
+
/**
|
|
529
|
+
* Network conditions affecting compression
|
|
530
|
+
*/
|
|
531
|
+
interface NetworkProfile {
|
|
532
|
+
estimatedSpeedKbps: number;
|
|
533
|
+
latencyMs: number;
|
|
534
|
+
isOnline: boolean;
|
|
535
|
+
isWifi: boolean;
|
|
536
|
+
isFast: boolean;
|
|
537
|
+
isSlow: boolean;
|
|
538
|
+
isEmpty: boolean;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Device capabilities for compression
|
|
542
|
+
*/
|
|
543
|
+
interface DeviceProfile {
|
|
544
|
+
cpuCores: number;
|
|
545
|
+
cpuUtilization: number;
|
|
546
|
+
memoryAvailableMB: number;
|
|
547
|
+
memoryTotalMB: number;
|
|
548
|
+
isConstrained: boolean;
|
|
549
|
+
isPremium: boolean;
|
|
550
|
+
supportsWebWorkers: boolean;
|
|
551
|
+
supportsWebAssembly: boolean;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Compression recommendation based on conditions
|
|
555
|
+
*/
|
|
556
|
+
interface CompressionRecommendation {
|
|
557
|
+
recommendedLevel: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
558
|
+
reason: string;
|
|
559
|
+
confidence: number;
|
|
560
|
+
estimatedCompressionMs: number;
|
|
561
|
+
estimatedRatio: number;
|
|
562
|
+
networkFactor: number;
|
|
563
|
+
deviceFactor: number;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Adaptive compression statistics
|
|
567
|
+
*/
|
|
568
|
+
interface AdaptiveStats {
|
|
569
|
+
currentLevel: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
570
|
+
averageCompressionMs: number;
|
|
571
|
+
averageRatio: number;
|
|
572
|
+
levelsUsed: Set<number>;
|
|
573
|
+
adjustmentCount: number;
|
|
574
|
+
totalBatches: number;
|
|
575
|
+
networkCondition: 'fast' | 'normal' | 'slow' | 'offline';
|
|
576
|
+
}
|
|
577
|
+
declare class AdaptiveCompressionOptimizer {
|
|
578
|
+
private currentLevel;
|
|
579
|
+
private networkProfile;
|
|
580
|
+
private deviceProfile;
|
|
581
|
+
private compressionHistory;
|
|
582
|
+
private stats;
|
|
583
|
+
constructor();
|
|
584
|
+
/**
|
|
585
|
+
* Update network conditions
|
|
586
|
+
*/
|
|
587
|
+
updateNetworkConditions(speedKbps: number, latencyMs?: number, isOnline?: boolean): void;
|
|
588
|
+
/**
|
|
589
|
+
* Update device resource usage
|
|
590
|
+
*/
|
|
591
|
+
updateDeviceResources(cpuUtilization: number, memoryAvailableMB: number): void;
|
|
592
|
+
/**
|
|
593
|
+
* Record compression performance
|
|
594
|
+
*/
|
|
595
|
+
recordCompressionPerformance(level: number, compressionMs: number, ratio: number): void;
|
|
596
|
+
/**
|
|
597
|
+
* Get compression recommendation based on conditions
|
|
598
|
+
*/
|
|
599
|
+
getRecommendedLevel(): CompressionRecommendation;
|
|
600
|
+
/**
|
|
601
|
+
* Calculate network factor (0-1)
|
|
602
|
+
*/
|
|
603
|
+
private calculateNetworkFactor;
|
|
604
|
+
/**
|
|
605
|
+
* Calculate device factor (0-1)
|
|
606
|
+
*/
|
|
607
|
+
private calculateDeviceFactor;
|
|
608
|
+
/**
|
|
609
|
+
* Estimate compression time for a level (in ms)
|
|
610
|
+
*/
|
|
611
|
+
private estimateCompressionTime;
|
|
612
|
+
/**
|
|
613
|
+
* Estimate compression ratio for a level
|
|
614
|
+
*/
|
|
615
|
+
private estimateCompressionRatio;
|
|
616
|
+
/**
|
|
617
|
+
* Apply recommendation and get new level
|
|
618
|
+
*/
|
|
619
|
+
applyRecommendation(): 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
620
|
+
/**
|
|
621
|
+
* Get current level
|
|
622
|
+
*/
|
|
623
|
+
getCurrentLevel(): 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
624
|
+
/**
|
|
625
|
+
* Get statistics
|
|
626
|
+
*/
|
|
627
|
+
getStats(): AdaptiveStats;
|
|
628
|
+
/**
|
|
629
|
+
* Get detailed analysis
|
|
630
|
+
*/
|
|
631
|
+
getDetailedAnalysis(): {
|
|
632
|
+
stats: AdaptiveStats;
|
|
633
|
+
network: NetworkProfile;
|
|
634
|
+
device: DeviceProfile;
|
|
635
|
+
recommendation: CompressionRecommendation;
|
|
636
|
+
history: {
|
|
637
|
+
level: number;
|
|
638
|
+
ratio: number;
|
|
639
|
+
timeMs: number;
|
|
640
|
+
timestamp: number;
|
|
641
|
+
}[];
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
declare function getAdaptiveCompressionOptimizer(): AdaptiveCompressionOptimizer;
|
|
645
|
+
declare function resetAdaptiveCompressionOptimizer(): void;
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Agent Presence Manager (Phase 14)
|
|
649
|
+
*
|
|
650
|
+
* Tracks real-time presence of all agents in a session.
|
|
651
|
+
* Provides status updates, cursor tracking, and activity monitoring.
|
|
652
|
+
*/
|
|
653
|
+
|
|
654
|
+
interface AgentPresence {
|
|
655
|
+
agentId: string;
|
|
656
|
+
name: string;
|
|
657
|
+
role: 'user' | 'assistant' | 'monitor' | 'admin';
|
|
658
|
+
status: 'online' | 'away' | 'offline' | 'reconnecting';
|
|
659
|
+
joinedAt: string;
|
|
660
|
+
lastSeen: string;
|
|
661
|
+
cursorPosition?: {
|
|
662
|
+
x: number;
|
|
663
|
+
y: number;
|
|
664
|
+
path: string;
|
|
665
|
+
};
|
|
666
|
+
activeSection?: string;
|
|
667
|
+
metadata?: Record<string, unknown>;
|
|
668
|
+
}
|
|
669
|
+
interface PresenceUpdate {
|
|
670
|
+
agentId: string;
|
|
671
|
+
changes: Partial<AgentPresence>;
|
|
672
|
+
timestamp: string;
|
|
673
|
+
}
|
|
674
|
+
interface PresenceEvents {
|
|
675
|
+
presence_updated: (data: {
|
|
676
|
+
agentId: string;
|
|
677
|
+
presence: AgentPresence;
|
|
678
|
+
}) => void;
|
|
679
|
+
agent_joined: (data: {
|
|
680
|
+
agentId: string;
|
|
681
|
+
presence: AgentPresence;
|
|
682
|
+
}) => void;
|
|
683
|
+
agent_left: (data: {
|
|
684
|
+
agentId: string;
|
|
685
|
+
presence: AgentPresence;
|
|
686
|
+
}) => void;
|
|
687
|
+
cursor_updated: (data: {
|
|
688
|
+
agentId: string;
|
|
689
|
+
cursorPosition: {
|
|
690
|
+
x: number;
|
|
691
|
+
y: number;
|
|
692
|
+
path: string;
|
|
693
|
+
};
|
|
694
|
+
}) => void;
|
|
695
|
+
section_updated: (data: {
|
|
696
|
+
agentId: string;
|
|
697
|
+
activeSection: string;
|
|
698
|
+
}) => void;
|
|
699
|
+
status_updated: (data: {
|
|
700
|
+
agentId: string;
|
|
701
|
+
status: AgentPresence['status'];
|
|
702
|
+
}) => void;
|
|
703
|
+
}
|
|
704
|
+
declare class AgentPresenceManager extends EventEmitter<PresenceEvents> {
|
|
705
|
+
private presences;
|
|
706
|
+
private sessionId;
|
|
707
|
+
private heartbeatInterval;
|
|
708
|
+
private heartbeatTimeout;
|
|
709
|
+
private inactivityThreshold;
|
|
710
|
+
constructor(sessionId: string);
|
|
711
|
+
/**
|
|
712
|
+
* Add or update agent presence
|
|
713
|
+
*/
|
|
714
|
+
updatePresence(agentId: string, presence: Omit<AgentPresence, 'joinedAt' | 'lastSeen'>): void;
|
|
715
|
+
/**
|
|
716
|
+
* Agent joined
|
|
717
|
+
*/
|
|
718
|
+
agentJoined(agentId: string, name: string, role?: AgentPresence['role'], metadata?: Record<string, unknown>): void;
|
|
719
|
+
/**
|
|
720
|
+
* Agent left
|
|
721
|
+
*/
|
|
722
|
+
agentLeft(agentId: string): void;
|
|
723
|
+
/**
|
|
724
|
+
* Update cursor position
|
|
725
|
+
*/
|
|
726
|
+
updateCursor(agentId: string, x: number, y: number, path: string): void;
|
|
727
|
+
/**
|
|
728
|
+
* Update active section
|
|
729
|
+
*/
|
|
730
|
+
updateActiveSection(agentId: string, section: string): void;
|
|
731
|
+
/**
|
|
732
|
+
* Update status
|
|
733
|
+
*/
|
|
734
|
+
updateStatus(agentId: string, status: AgentPresence['status']): void;
|
|
735
|
+
/**
|
|
736
|
+
* Heartbeat from agent (keeps them online)
|
|
737
|
+
*/
|
|
738
|
+
heartbeat(agentId: string): void;
|
|
739
|
+
/**
|
|
740
|
+
* Get presence for agent
|
|
741
|
+
*/
|
|
742
|
+
getPresence(agentId: string): AgentPresence | undefined;
|
|
743
|
+
/**
|
|
744
|
+
* Get all online agents
|
|
745
|
+
*/
|
|
746
|
+
getOnlineAgents(): AgentPresence[];
|
|
747
|
+
/**
|
|
748
|
+
* Get all agents
|
|
749
|
+
*/
|
|
750
|
+
getAllAgents(): AgentPresence[];
|
|
751
|
+
/**
|
|
752
|
+
* Get all presences
|
|
753
|
+
*/
|
|
754
|
+
getAllPresences(): AgentPresence[];
|
|
755
|
+
/**
|
|
756
|
+
* Get agent count
|
|
757
|
+
*/
|
|
758
|
+
getAgentCount(): Record<AgentPresence['status'], number>;
|
|
759
|
+
/**
|
|
760
|
+
* Get statistics
|
|
761
|
+
*/
|
|
762
|
+
getStats(): {
|
|
763
|
+
totalAgents: number;
|
|
764
|
+
onlineAgents: number;
|
|
765
|
+
offlineAgents: number;
|
|
766
|
+
awayAgents: number;
|
|
767
|
+
reconnectingAgents: number;
|
|
768
|
+
};
|
|
769
|
+
/**
|
|
770
|
+
* Clear expired presences
|
|
771
|
+
*/
|
|
772
|
+
clearExpiredPresences(maxAgeMs: number): void;
|
|
773
|
+
/**
|
|
774
|
+
* Get agents by role
|
|
775
|
+
*/
|
|
776
|
+
getByRole(role: AgentPresence['role']): AgentPresence[];
|
|
777
|
+
/**
|
|
778
|
+
* Get agents in active section
|
|
779
|
+
*/
|
|
780
|
+
getInSection(section: string): AgentPresence[];
|
|
781
|
+
/**
|
|
782
|
+
* Get presence timeline
|
|
783
|
+
*/
|
|
784
|
+
getPresenceStats(): {
|
|
785
|
+
total: number;
|
|
786
|
+
online: number;
|
|
787
|
+
away: number;
|
|
788
|
+
offline: number;
|
|
789
|
+
reconnecting: number;
|
|
790
|
+
byRole: Record<string, number>;
|
|
791
|
+
};
|
|
792
|
+
/**
|
|
793
|
+
* Start heartbeat check (mark inactive agents as away)
|
|
794
|
+
*/
|
|
795
|
+
private startHeartbeatCheck;
|
|
796
|
+
/**
|
|
797
|
+
* Stop heartbeat monitoring
|
|
798
|
+
*/
|
|
799
|
+
stopHeartbeatMonitoring(): void;
|
|
800
|
+
/**
|
|
801
|
+
* Clear all presences
|
|
802
|
+
*/
|
|
803
|
+
clear(): void;
|
|
804
|
+
/**
|
|
805
|
+
* Destroy the manager
|
|
806
|
+
*/
|
|
807
|
+
destroy(): void;
|
|
808
|
+
}
|
|
809
|
+
declare function getAgentPresenceManager(sessionId: string): AgentPresenceManager;
|
|
810
|
+
declare function clearAgentPresenceManager(sessionId: string): void;
|
|
811
|
+
|
|
812
|
+
export { type ActivityPattern, AdaptiveCompressionOptimizer, type AdaptiveStats, type AgentPresence, AgentPresenceManager, BatchTimingOptimizer, type BatchTimingStats, type CompressedBatch, type CompressedChunk, CompressionEngine, type CompressionRecommendation, type CompressionStats, type DeltaBatch, type DeltaOperation, type DeltaStats, DeltaSyncOptimizer, type DeviceProfile, type NetworkProfile, type NetworkWindow, type OfflineOperation, OfflineOperationQueue, type OfflineQueueEvents, type OfflineQueueStats, Operation, type OperationPattern, type OperationPrediction, OperationPriority, type PrefetchedBatch, PrefetchingEngine, type PrefetchingStats, type PresenceEvents, type PresenceUpdate, type SchedulingDecision, clearAgentPresenceManager, getAdaptiveCompressionOptimizer, getAgentPresenceManager, getBatchTimingOptimizer, getCompressionEngine, getDeltaSyncOptimizer, getOfflineOperationQueue, getPrefetchingEngine, resetAdaptiveCompressionOptimizer, resetBatchTimingOptimizer, resetCompressionEngine, resetDeltaSyncOptimizer, resetOfflineOperationQueue, resetPrefetchingEngine };
|