@affectively/aeon-pages-runtime 0.1.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Aeon Speculative Pre-Rendering
3
+ *
4
+ * Pre-renders pages before user clicks based on:
5
+ * 1. NavigationPredictor predictions (Markov chain, community patterns)
6
+ * 2. Link visibility (IntersectionObserver)
7
+ * 3. Hover intent signals
8
+ * 4. Browser Speculation Rules API (when available)
9
+ *
10
+ * This enables zero-latency navigation by having the page ready in memory.
11
+ */
12
+ export interface PreRenderedPage {
13
+ route: string;
14
+ html: string;
15
+ prefetchedAt: number;
16
+ confidence: number;
17
+ stale: boolean;
18
+ size: number;
19
+ }
20
+ export interface SpeculativeRendererConfig {
21
+ /** Maximum pages to keep in memory cache */
22
+ maxCachedPages: number;
23
+ /** Maximum total size in bytes for cache */
24
+ maxCacheSize: number;
25
+ /** Time before a cached page is considered stale (ms) */
26
+ staleTTL: number;
27
+ /** Minimum confidence threshold to pre-render */
28
+ minConfidence: number;
29
+ /** Root margin for IntersectionObserver */
30
+ intersectionRootMargin: string;
31
+ /** Whether to use browser's Speculation Rules API */
32
+ useSpeculationRules: boolean;
33
+ /** Whether to pre-render on hover */
34
+ prerenderOnHover: boolean;
35
+ /** Hover delay before pre-rendering (ms) */
36
+ hoverDelay: number;
37
+ /** Base URL for session fetches */
38
+ sessionBaseUrl: string;
39
+ }
40
+ export declare class SpeculativeRenderer {
41
+ private config;
42
+ private cache;
43
+ private currentCacheSize;
44
+ private observer;
45
+ private hoverTimeouts;
46
+ private initialized;
47
+ constructor(config?: Partial<SpeculativeRendererConfig>);
48
+ /**
49
+ * Initialize the speculative renderer
50
+ * Call this after the page has loaded
51
+ */
52
+ init(): void;
53
+ /**
54
+ * Cleanup resources
55
+ */
56
+ destroy(): void;
57
+ /**
58
+ * Pre-render a specific route
59
+ */
60
+ prerender(route: string, confidence?: number): Promise<boolean>;
61
+ /**
62
+ * Navigate to a route using pre-rendered content if available
63
+ * Returns true if handled, false if fallback to normal navigation
64
+ */
65
+ navigate(route: string): Promise<boolean>;
66
+ /**
67
+ * Invalidate cached pages
68
+ */
69
+ invalidate(routes?: string[]): void;
70
+ /**
71
+ * Get cache statistics
72
+ */
73
+ getStats(): {
74
+ cachedPages: number;
75
+ cacheSize: number;
76
+ cacheHitRate: number;
77
+ };
78
+ private setupIntersectionObserver;
79
+ private observeLinks;
80
+ private onLinksVisible;
81
+ private setupHoverListeners;
82
+ private onLinkHover;
83
+ private onLinkLeave;
84
+ private injectSpeculationRules;
85
+ private setupNavigationInterception;
86
+ private startPredictivePrerendering;
87
+ private reinitialize;
88
+ private evictIfNeeded;
89
+ }
90
+ export declare function getSpeculativeRenderer(): SpeculativeRenderer;
91
+ export declare function setSpeculativeRenderer(renderer: SpeculativeRenderer): void;
92
+ /**
93
+ * Initialize speculative rendering (call on page load)
94
+ */
95
+ export declare function initSpeculativeRendering(config?: Partial<SpeculativeRendererConfig>): SpeculativeRenderer;
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Aeon Pages Conflict Resolver
3
+ *
4
+ * Handles conflict detection and resolution for offline-first applications.
5
+ * Optimized for edge environments with configurable resolution strategies.
6
+ *
7
+ * Features:
8
+ * - Multiple resolution strategies (local-wins, remote-wins, merge, last-modified)
9
+ * - Automatic resolution for low-severity conflicts
10
+ * - Manual resolution queue for high-severity conflicts
11
+ * - Conflict statistics and history
12
+ */
13
+ import type { OfflineOperation, StoredConflict, ResolutionStrategy } from '../offline/types';
14
+ export interface ConflictResolverConfig {
15
+ /** Default resolution strategy */
16
+ defaultStrategy: ResolutionStrategy;
17
+ /** Enable automatic merging for similar updates */
18
+ enableAutoMerge: boolean;
19
+ /** Enable local-wins fallback */
20
+ enableLocalWins: boolean;
21
+ /** Maximum conflicts to cache */
22
+ maxConflictCacheSize: number;
23
+ /** Conflict resolution timeout in ms */
24
+ conflictTimeoutMs: number;
25
+ /** Similarity threshold (0-100) for auto-merge */
26
+ mergeThreshold: number;
27
+ }
28
+ export interface ConflictStats {
29
+ totalConflicts: number;
30
+ resolvedConflicts: number;
31
+ unresolvedConflicts: number;
32
+ conflictsByType: {
33
+ 'update_update': number;
34
+ 'delete_update': number;
35
+ 'update_delete': number;
36
+ 'concurrent': number;
37
+ };
38
+ resolutionsByStrategy: {
39
+ 'local-wins': number;
40
+ 'remote-wins': number;
41
+ 'merge': number;
42
+ 'manual': number;
43
+ 'last-modified': number;
44
+ };
45
+ averageResolutionTimeMs: number;
46
+ }
47
+ type EventHandler<T> = (data: T) => void;
48
+ declare class EventEmitter<Events extends Record<string, unknown> = Record<string, unknown>> {
49
+ private handlers;
50
+ on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): void;
51
+ off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): void;
52
+ emit<K extends keyof Events>(event: K, data?: Events[K]): void;
53
+ }
54
+ export declare class ConflictResolver extends EventEmitter<{
55
+ 'conflict:detected': StoredConflict;
56
+ 'conflict:resolved': {
57
+ conflict: StoredConflict;
58
+ strategy: ResolutionStrategy;
59
+ };
60
+ 'config:updated': ConflictResolverConfig;
61
+ }> {
62
+ private conflicts;
63
+ private conflictsByEntity;
64
+ private config;
65
+ private resolutionTimings;
66
+ private stats;
67
+ constructor(config?: Partial<ConflictResolverConfig>);
68
+ /**
69
+ * Detect conflicts between local and remote operations
70
+ */
71
+ detectConflict(localOp: OfflineOperation, remoteOp: OfflineOperation): StoredConflict | null;
72
+ /**
73
+ * Calculate conflict severity
74
+ */
75
+ private calculateSeverity;
76
+ /**
77
+ * Calculate data similarity (0-100)
78
+ */
79
+ private calculateDataSimilarity;
80
+ /**
81
+ * Find conflicting fields between two data objects
82
+ */
83
+ private findConflictingFields;
84
+ /**
85
+ * Determine if conflict should auto-resolve
86
+ */
87
+ private shouldAutoResolve;
88
+ /**
89
+ * Resolve a conflict using specified strategy
90
+ */
91
+ resolveConflict(conflictId: string, strategy?: ResolutionStrategy): StoredConflict['resolution'] | null;
92
+ /**
93
+ * Attempt to merge conflicting data
94
+ */
95
+ private attemptMerge;
96
+ /**
97
+ * Get conflict by ID
98
+ */
99
+ getConflict(conflictId: string): StoredConflict | undefined;
100
+ /**
101
+ * Get all unresolved conflicts
102
+ */
103
+ getUnresolvedConflicts(): StoredConflict[];
104
+ /**
105
+ * Get conflicts for a session
106
+ */
107
+ getConflictsForSession(sessionId: string): StoredConflict[];
108
+ /**
109
+ * Get high severity unresolved conflicts
110
+ */
111
+ getHighSeverityConflicts(): StoredConflict[];
112
+ /**
113
+ * Get statistics
114
+ */
115
+ getStats(): ConflictStats;
116
+ /**
117
+ * Configure resolver
118
+ */
119
+ configure(config: Partial<ConflictResolverConfig>): void;
120
+ /**
121
+ * Get current configuration
122
+ */
123
+ getConfig(): ConflictResolverConfig;
124
+ /**
125
+ * Clear all conflicts
126
+ */
127
+ clear(): void;
128
+ /**
129
+ * Reset service (for testing)
130
+ */
131
+ reset(): void;
132
+ }
133
+ /**
134
+ * Get the singleton conflict resolver instance
135
+ */
136
+ export declare function getConflictResolver(): ConflictResolver;
137
+ /**
138
+ * Create a new conflict resolver with custom configuration
139
+ */
140
+ export declare function createConflictResolver(config?: Partial<ConflictResolverConfig>): ConflictResolver;
141
+ /**
142
+ * Reset the singleton resolver (for testing)
143
+ */
144
+ export declare function resetConflictResolver(): void;
145
+ export {};
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Aeon Pages Sync Coordinator
3
+ *
4
+ * Coordinates synchronization of offline operations with server.
5
+ * Handles bandwidth optimization, batching, and network state management.
6
+ *
7
+ * Features:
8
+ * - Adaptive batch sizing based on network conditions
9
+ * - Network state tracking and monitoring
10
+ * - Bandwidth profiling
11
+ * - Sync progress tracking
12
+ * - Configurable compression and delta sync
13
+ */
14
+ import type { OfflineOperation, SyncBatch, SyncResult, SyncCoordinatorConfig, SyncProgressEvent, NetworkState, NetworkStateEvent, BandwidthProfile } from '../offline/types';
15
+ export interface SyncStats {
16
+ totalSyncsAttempted: number;
17
+ successfulSyncs: number;
18
+ failedSyncs: number;
19
+ totalOperationsSynced: number;
20
+ averageSyncDurationMs: number;
21
+ lastSyncTime?: number;
22
+ networkStateHistory: Array<{
23
+ state: NetworkState;
24
+ timestamp: number;
25
+ }>;
26
+ bandwidthHistory: BandwidthProfile[];
27
+ }
28
+ type EventHandler<T> = (data: T) => void;
29
+ declare class EventEmitter<Events extends Record<string, unknown> = Record<string, unknown>> {
30
+ private handlers;
31
+ on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): void;
32
+ off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): void;
33
+ emit<K extends keyof Events>(event: K, data?: Events[K]): void;
34
+ }
35
+ export declare class SyncCoordinator extends EventEmitter<{
36
+ 'network:changed': NetworkStateEvent;
37
+ 'network:online': void;
38
+ 'network:offline': void;
39
+ 'bandwidth:updated': BandwidthProfile;
40
+ 'batch:created': SyncBatch;
41
+ 'batch:started': {
42
+ batchId: string;
43
+ };
44
+ 'batch:progress': SyncProgressEvent;
45
+ 'batch:completed': {
46
+ batch: SyncBatch;
47
+ result: SyncResult;
48
+ };
49
+ 'batch:failed': {
50
+ batch: SyncBatch;
51
+ error: string;
52
+ };
53
+ 'batch:retry': {
54
+ batch: SyncBatch;
55
+ attempt: number;
56
+ };
57
+ 'config:updated': SyncCoordinatorConfig;
58
+ }> {
59
+ private networkState;
60
+ private bandwidthProfile;
61
+ private batches;
62
+ private progress;
63
+ private currentSyncBatchId;
64
+ private config;
65
+ private syncTimings;
66
+ private stats;
67
+ constructor(config?: Partial<SyncCoordinatorConfig>);
68
+ /**
69
+ * Initialize network state detection
70
+ */
71
+ private initNetworkDetection;
72
+ /**
73
+ * Update bandwidth profile from Network Information API
74
+ */
75
+ private updateBandwidthFromConnection;
76
+ /**
77
+ * Update network state
78
+ */
79
+ setNetworkState(state: NetworkState): void;
80
+ /**
81
+ * Get current network state
82
+ */
83
+ getNetworkState(): NetworkState;
84
+ /**
85
+ * Update bandwidth profile
86
+ */
87
+ updateBandwidthProfile(profile: Partial<BandwidthProfile>): void;
88
+ /**
89
+ * Get current bandwidth profile
90
+ */
91
+ getBandwidthProfile(): BandwidthProfile;
92
+ /**
93
+ * Create a sync batch from operations
94
+ */
95
+ createSyncBatch(operations: OfflineOperation[]): SyncBatch;
96
+ /**
97
+ * Start syncing a batch
98
+ */
99
+ startSyncBatch(batchId: string): void;
100
+ /**
101
+ * Update sync progress
102
+ */
103
+ updateProgress(batchId: string, syncedOperations: number, bytesSynced: number): void;
104
+ /**
105
+ * Complete a sync batch
106
+ */
107
+ completeSyncBatch(batchId: string, result: SyncResult): void;
108
+ /**
109
+ * Mark batch as failed
110
+ */
111
+ failSyncBatch(batchId: string, error: string, retryable?: boolean): void;
112
+ /**
113
+ * Get batch by ID
114
+ */
115
+ getBatch(batchId: string): SyncBatch | undefined;
116
+ /**
117
+ * Get all pending batches
118
+ */
119
+ getPendingBatches(): SyncBatch[];
120
+ /**
121
+ * Get current sync progress
122
+ */
123
+ getCurrentProgress(): SyncProgressEvent | undefined;
124
+ /**
125
+ * Estimate sync time for given bytes
126
+ */
127
+ estimateSyncTime(bytes: number): number;
128
+ /**
129
+ * Adapt batch sizes based on bandwidth
130
+ */
131
+ private adaptBatchSizes;
132
+ /**
133
+ * Get sync statistics
134
+ */
135
+ getStats(): SyncStats;
136
+ /**
137
+ * Configure the coordinator
138
+ */
139
+ configure(config: Partial<SyncCoordinatorConfig>): void;
140
+ /**
141
+ * Get current configuration
142
+ */
143
+ getConfig(): SyncCoordinatorConfig;
144
+ /**
145
+ * Clear all batches
146
+ */
147
+ clear(): void;
148
+ /**
149
+ * Reset service (for testing)
150
+ */
151
+ reset(): void;
152
+ }
153
+ /**
154
+ * Get the singleton sync coordinator instance
155
+ */
156
+ export declare function getSyncCoordinator(): SyncCoordinator;
157
+ /**
158
+ * Create a new sync coordinator with custom configuration
159
+ */
160
+ export declare function createSyncCoordinator(config?: Partial<SyncCoordinatorConfig>): SyncCoordinator;
161
+ /**
162
+ * Reset the singleton coordinator (for testing)
163
+ */
164
+ export declare function resetSyncCoordinator(): void;
165
+ export {};
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Tree → TSX Compiler
3
+ *
4
+ * Converts component trees from the visual editor back to TSX source code.
5
+ */
6
+ interface TreeNode {
7
+ id: string;
8
+ type: string;
9
+ props?: Record<string, unknown>;
10
+ children?: string[] | TreeNode[];
11
+ text?: string;
12
+ }
13
+ interface CompilerOptions {
14
+ /** Route path for the page */
15
+ route: string;
16
+ /** Include 'use aeon' directive */
17
+ useAeon?: boolean;
18
+ /** Component imports to add */
19
+ imports?: Record<string, string>;
20
+ /** Whether to format output */
21
+ format?: boolean;
22
+ }
23
+ /**
24
+ * Compile a tree to TSX source code
25
+ */
26
+ export declare function compileTreeToTSX(tree: TreeNode | TreeNode[], options: CompilerOptions): string;
27
+ export {};