humanbehavior-js 0.4.6 → 0.4.8

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.
Files changed (58) hide show
  1. package/dist/cjs/angular/index.cjs +52 -7
  2. package/dist/cjs/angular/index.cjs.map +1 -1
  3. package/dist/cjs/index.cjs +52 -7
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/cjs/install-wizard.cjs +4 -2
  6. package/dist/cjs/install-wizard.cjs.map +1 -1
  7. package/dist/cjs/react/index.cjs +52 -7
  8. package/dist/cjs/react/index.cjs.map +1 -1
  9. package/dist/cjs/remix/index.cjs +52 -7
  10. package/dist/cjs/remix/index.cjs.map +1 -1
  11. package/dist/cjs/svelte/index.cjs +52 -7
  12. package/dist/cjs/svelte/index.cjs.map +1 -1
  13. package/dist/cjs/vue/index.cjs +52 -7
  14. package/dist/cjs/vue/index.cjs.map +1 -1
  15. package/dist/cjs/wizard/index.cjs +3208 -0
  16. package/dist/cjs/wizard/index.cjs.map +1 -0
  17. package/dist/cli/ai-auto-install.js +2024 -0
  18. package/dist/cli/ai-auto-install.js.map +1 -0
  19. package/dist/cli/auto-install.js +4 -2
  20. package/dist/cli/auto-install.js.map +1 -1
  21. package/dist/esm/angular/index.js +52 -7
  22. package/dist/esm/angular/index.js.map +1 -1
  23. package/dist/esm/index.js +52 -7
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/install-wizard.js +4 -2
  26. package/dist/esm/install-wizard.js.map +1 -1
  27. package/dist/esm/react/index.js +52 -7
  28. package/dist/esm/react/index.js.map +1 -1
  29. package/dist/esm/remix/index.js +52 -7
  30. package/dist/esm/remix/index.js.map +1 -1
  31. package/dist/esm/svelte/index.js +52 -7
  32. package/dist/esm/svelte/index.js.map +1 -1
  33. package/dist/esm/vue/index.js +52 -7
  34. package/dist/esm/vue/index.js.map +1 -1
  35. package/dist/esm/wizard/index.js +3178 -0
  36. package/dist/esm/wizard/index.js.map +1 -0
  37. package/dist/index.min.js +1 -1
  38. package/dist/index.min.js.map +1 -1
  39. package/dist/types/angular/index.d.ts +7 -0
  40. package/dist/types/index.d.ts +7 -0
  41. package/dist/types/install-wizard.d.ts +8 -8
  42. package/dist/types/react/index.d.ts +7 -0
  43. package/dist/types/remix/index.d.ts +7 -0
  44. package/dist/types/svelte/index.d.ts +7 -0
  45. package/dist/types/wizard/index.d.ts +489 -0
  46. package/package.json +14 -8
  47. package/rollup.config.js +65 -3
  48. package/src/react/AutoInstallWizard.tsx +1 -1
  49. package/src/tracker.ts +59 -8
  50. package/src/wizard/README.md +114 -0
  51. package/src/wizard/ai/ai-install-wizard.ts +894 -0
  52. package/src/wizard/ai/manual-framework-wizard.ts +236 -0
  53. package/src/wizard/cli/ai-auto-install.ts +369 -0
  54. package/src/{cli → wizard/cli}/auto-install.ts +1 -1
  55. package/src/{install-wizard.ts → wizard/core/install-wizard.ts} +12 -10
  56. package/src/wizard/index.ts +23 -0
  57. package/src/wizard/services/centralized-ai-service.ts +668 -0
  58. package/src/wizard/services/remote-ai-service.ts +224 -0
package/rollup.config.js CHANGED
@@ -294,7 +294,7 @@ export default [
294
294
 
295
295
  // CLI bundle
296
296
  {
297
- input: 'src/cli/auto-install.ts',
297
+ input: 'src/wizard/cli/auto-install.ts',
298
298
  output: {
299
299
  file: 'dist/cli/auto-install.js',
300
300
  format: 'es',
@@ -314,9 +314,31 @@ export default [
314
314
  external: nodeExternal
315
315
  },
316
316
 
317
+ // AI CLI bundle
318
+ {
319
+ input: 'src/wizard/cli/ai-auto-install.ts',
320
+ output: {
321
+ file: 'dist/cli/ai-auto-install.js',
322
+ format: 'es',
323
+ sourcemap: true
324
+ },
325
+ plugins: [
326
+ resolve({
327
+ preferBuiltins: true
328
+ }),
329
+ commonjs(),
330
+ typescript({
331
+ tsconfig: './tsconfig.json',
332
+ declaration: false,
333
+ declarationMap: false
334
+ })
335
+ ],
336
+ external: nodeExternal
337
+ },
338
+
317
339
  // Install wizard bundle
318
340
  {
319
- input: 'src/install-wizard.ts',
341
+ input: 'src/wizard/core/install-wizard.ts',
320
342
  output: [
321
343
  {
322
344
  file: 'dist/cjs/install-wizard.cjs',
@@ -345,12 +367,52 @@ export default [
345
367
 
346
368
  // Install wizard types
347
369
  {
348
- input: 'src/install-wizard.ts',
370
+ input: 'src/wizard/core/install-wizard.ts',
349
371
  output: {
350
372
  file: 'dist/types/install-wizard.d.ts',
351
373
  format: 'es'
352
374
  },
353
375
  plugins: [dts()],
354
376
  external: nodeExternal
377
+ },
378
+
379
+ // Wizard module bundle
380
+ {
381
+ input: 'src/wizard/index.ts',
382
+ output: [
383
+ {
384
+ file: 'dist/cjs/wizard/index.cjs',
385
+ format: 'cjs',
386
+ sourcemap: true
387
+ },
388
+ {
389
+ file: 'dist/esm/wizard/index.js',
390
+ format: 'es',
391
+ sourcemap: true
392
+ }
393
+ ],
394
+ plugins: [
395
+ resolve({
396
+ preferBuiltins: true
397
+ }),
398
+ commonjs(),
399
+ typescript({
400
+ tsconfig: './tsconfig.json',
401
+ declaration: false,
402
+ declarationMap: false
403
+ })
404
+ ],
405
+ external: nodeExternal
406
+ },
407
+
408
+ // Wizard module types
409
+ {
410
+ input: 'src/wizard/index.ts',
411
+ output: {
412
+ file: 'dist/types/wizard/index.d.ts',
413
+ format: 'es'
414
+ },
415
+ plugins: [dts()],
416
+ external: nodeExternal
355
417
  }
356
418
  ];
@@ -1,5 +1,5 @@
1
1
  import React, { useState, useEffect } from 'react';
2
- import { BrowserAutoInstallationWizard } from '../install-wizard';
2
+ import { BrowserAutoInstallationWizard } from '../wizard/core/install-wizard';
3
3
 
4
4
  interface AutoInstallWizardProps {
5
5
  apiKey: string;
package/src/tracker.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { record } from '@rrweb/record';
2
+ import type { listenerHandler } from '@rrweb/types';
2
3
  import { v1 as uuidv1 } from 'uuid';
3
4
  import { HumanBehaviorAPI } from './api';
4
5
  import { RedactionManager, RedactionOptions } from './redact';
@@ -45,8 +46,10 @@ export class HumanBehaviorTracker {
45
46
  private originalReplaceState: typeof history.replaceState | null = null;
46
47
  private navigationListeners: Array<() => void> = [];
47
48
  private _connectionBlocked: boolean = false;
48
- private recordInstance: any = null;
49
+ private recordInstance: listenerHandler | null = null;
49
50
  private sessionStartTime: number = Date.now();
51
+ private rrwebRecord: any = null;
52
+ private fullSnapshotTimeout: number | null = null;
50
53
 
51
54
  /**
52
55
  * Initialize the HumanBehavior tracker
@@ -225,6 +228,9 @@ export class HumanBehaviorTracker {
225
228
 
226
229
  // Track navigation event
227
230
  this.trackNavigationEvent('pushState', this.previousUrl, this.currentUrl);
231
+
232
+ // Take FullSnapshot on navigation
233
+ this.takeFullSnapshot();
228
234
  };
229
235
 
230
236
  // Override replaceState to capture programmatic navigation
@@ -237,6 +243,9 @@ export class HumanBehaviorTracker {
237
243
 
238
244
  // Track navigation event
239
245
  this.trackNavigationEvent('replaceState', this.previousUrl, this.currentUrl);
246
+
247
+ // Take FullSnapshot on navigation
248
+ this.takeFullSnapshot();
240
249
  };
241
250
 
242
251
  // Listen for popstate events (back/forward navigation)
@@ -244,6 +253,9 @@ export class HumanBehaviorTracker {
244
253
  this.previousUrl = this.currentUrl;
245
254
  this.currentUrl = window.location.href;
246
255
  this.trackNavigationEvent('popstate', this.previousUrl, this.currentUrl);
256
+
257
+ // Take FullSnapshot on navigation
258
+ this.takeFullSnapshot();
247
259
  };
248
260
 
249
261
  window.addEventListener('popstate', popstateListener);
@@ -751,8 +763,8 @@ export class HumanBehaviorTracker {
751
763
  this.flush();
752
764
  }, this.FLUSH_INTERVAL_MS);
753
765
 
754
- // Enable console tracking
755
- this.enableConsoleTracking();
766
+ // Disable console tracking to reduce event pollution
767
+ // this.enableConsoleTracking();
756
768
 
757
769
  // ✅ DOM READY DETECTION
758
770
  // Wait for DOM to be ready before starting recording
@@ -760,6 +772,7 @@ export class HumanBehaviorTracker {
760
772
  logDebug('🎯 DOM ready, starting session recording');
761
773
 
762
774
  // ✅ HUMANBEHAVIOR RRWEB CONFIGURATION
775
+ this.rrwebRecord = record;
763
776
  const recordInstance = record({
764
777
  emit: (event) => {
765
778
  // ✅ DIRECT EVENT HANDLING - Let rrweb handle events natively
@@ -784,13 +797,12 @@ export class HumanBehaviorTracker {
784
797
  // ✅ CANVAS RECORDING - Disabled to prevent large data URIs
785
798
  recordCanvas: false, // Disabled to prevent large data URIs
786
799
 
787
- // ✅ FULLSNAPSHOT GENERATION - Use reasonable intervals
788
- // checkoutEveryNms: 300000, // Take FullSnapshot every 5 minutes
789
- // checkoutEveryNth: 1000, // Take FullSnapshot every 1000 events
800
+ // ✅ FULLSNAPSHOT GENERATION - No periodic snapshots to avoid animation issues
801
+ // Rely on initial FullSnapshot + navigation-triggered ones only
790
802
  });
791
803
 
792
- // Store the record instance for cleanup
793
- this.recordInstance = recordInstance;
804
+ // Store the record instance for cleanup
805
+ this.recordInstance = recordInstance || null;
794
806
  };
795
807
 
796
808
  // ✅ DOM READY DETECTION
@@ -809,6 +821,37 @@ export class HumanBehaviorTracker {
809
821
  }
810
822
  }
811
823
 
824
+ /**
825
+ * Manually trigger a FullSnapshot (for navigation events)
826
+ * Delays snapshot to avoid capturing mid-animation states
827
+ */
828
+ private takeFullSnapshot(): void {
829
+ // Clear any existing timeout to avoid multiple snapshots
830
+ if (this.fullSnapshotTimeout) {
831
+ clearTimeout(this.fullSnapshotTimeout);
832
+ }
833
+
834
+ // Delay FullSnapshot to let animations settle
835
+ this.fullSnapshotTimeout = window.setTimeout(() => {
836
+ try {
837
+ // Wait for any pending animations/transitions to complete
838
+ requestAnimationFrame(() => {
839
+ requestAnimationFrame(() => {
840
+ // Access takeFullSnapshot from the rrweb record function
841
+ if (this.rrwebRecord && typeof this.rrwebRecord.takeFullSnapshot === 'function') {
842
+ this.rrwebRecord.takeFullSnapshot();
843
+ logDebug('✅ FullSnapshot taken for navigation (delayed for animations)');
844
+ } else {
845
+ logWarn('⚠️ takeFullSnapshot not available on record function');
846
+ }
847
+ });
848
+ });
849
+ } catch (error) {
850
+ logError('❌ Failed to take FullSnapshot for navigation:', error);
851
+ }
852
+ }, 1000); // Wait 1 second for animations to settle
853
+ }
854
+
812
855
  public async stop() {
813
856
  await this.ensureInitialized();
814
857
  if (!isBrowser) return;
@@ -823,6 +866,14 @@ export class HumanBehaviorTracker {
823
866
  this.recordInstance();
824
867
  this.recordInstance = null;
825
868
  }
869
+
870
+ // Clear any pending FullSnapshot timeouts
871
+ if (this.fullSnapshotTimeout) {
872
+ clearTimeout(this.fullSnapshotTimeout);
873
+ this.fullSnapshotTimeout = null;
874
+ }
875
+
876
+ this.rrwebRecord = null;
826
877
 
827
878
  // Disable console tracking
828
879
  this.disableConsoleTracking();
@@ -0,0 +1,114 @@
1
+ # HumanBehavior SDK Wizard Module
2
+
3
+ This module provides AI-enhanced auto-installation capabilities for the HumanBehavior SDK.
4
+
5
+ ## 📁 Directory Structure
6
+
7
+ ```
8
+ src/wizard/
9
+ ├── core/ # Core installation wizard
10
+ │ └── install-wizard.ts
11
+ ├── ai/ # AI-enhanced wizard components
12
+ │ └── ai-install-wizard.ts
13
+ ├── cli/ # Command-line interfaces
14
+ │ ├── auto-install.ts
15
+ │ └── ai-auto-install.ts
16
+ ├── services/ # AI service implementations
17
+ │ ├── remote-ai-service.ts
18
+ │ └── centralized-ai-service.ts
19
+ ├── index.ts # Main exports
20
+ └── README.md # This file
21
+ ```
22
+
23
+ ## 🚀 Key Components
24
+
25
+ ### Core (`core/`)
26
+ - **`install-wizard.ts`**: Traditional installation wizard
27
+ - Framework detection and code modification
28
+ - Environment variable management
29
+ - Package installation
30
+
31
+ ### AI (`ai/`)
32
+ - **`ai-install-wizard.ts`**: AI-enhanced installation wizard
33
+ - AI-powered framework detection
34
+ - Intelligent code analysis
35
+ - Conflict resolution
36
+ - Learning system
37
+
38
+ ### CLI (`cli/`)
39
+ - **`auto-install.ts`**: Traditional CLI interface
40
+ - **`ai-auto-install.ts`**: AI-enhanced CLI interface
41
+ - User interaction and command parsing
42
+ - Installation mode selection
43
+
44
+ ### Services (`services/`)
45
+ - **`remote-ai-service.ts`**: Connects to deployed Lambda AI service
46
+ - **`centralized-ai-service.ts`**: Local AI service implementation
47
+ - Heuristic fallback when AI is unavailable
48
+
49
+ ## 🔧 Usage
50
+
51
+ ### Traditional Installation
52
+ ```typescript
53
+ import { AutoInstallationWizard } from 'humanbehavior-js/wizard';
54
+
55
+ const wizard = new AutoInstallationWizard(apiKey, projectPath);
56
+ const result = await wizard.install();
57
+ ```
58
+
59
+ ### AI-Enhanced Installation
60
+ ```typescript
61
+ import { AIEnhancedInstallationWizard, RemoteAIService } from 'humanbehavior-js/wizard';
62
+
63
+ const aiService = new RemoteAIService({
64
+ apiEndpoint: 'https://your-lambda-api.execute-api.region.amazonaws.com/prod'
65
+ });
66
+
67
+ const wizard = new AIEnhancedInstallationWizard(apiKey, projectPath, aiService);
68
+ const result = await wizard.install();
69
+ ```
70
+
71
+ ### CLI Usage
72
+ ```bash
73
+ # Traditional installation
74
+ npx humanbehavior-js auto-install YOUR_API_KEY
75
+
76
+ # AI-enhanced installation
77
+ npx humanbehavior-js ai-auto-install YOUR_API_KEY --ai
78
+ ```
79
+
80
+ ## 🧠 AI Features
81
+
82
+ - **Intelligent Framework Detection**: Beyond package.json analysis
83
+ - **Code Pattern Analysis**: Understands project structure and patterns
84
+ - **Conflict Resolution**: Smart handling of existing integrations
85
+ - **Future-Proofing**: Adaptive strategies for new frameworks
86
+ - **Learning System**: Improves over time with usage patterns
87
+
88
+ ## 🔄 Backward Compatibility
89
+
90
+ All existing imports continue to work:
91
+ - `humanbehavior-js/install-wizard` → `humanbehavior-js/wizard`
92
+ - Traditional wizard functionality unchanged
93
+ - AI features are additive, not breaking
94
+
95
+ ## 🚀 Lambda Deployment
96
+
97
+ The `lambda-deployment/` directory contains the AI service for AWS Lambda deployment. This is separate from the client-side wizard code and should not be modified unless deploying AI service updates.
98
+
99
+ ### 📁 Lambda Deployment Structure
100
+ ```
101
+ lambda-deployment/
102
+ ├── index.js # Lambda entry point
103
+ ├── ai-install-wizard.ts # AI service implementation
104
+ ├── install-wizard.ts # Core wizard logic
105
+ ├── centralized-ai-service.ts # AI service interface
106
+ └── README.md # Deployment documentation
107
+ ```
108
+
109
+ ### 🔗 Client-Server Relationship
110
+ - **Client**: `src/wizard/` - User-facing installation wizard
111
+ - **Server**: `lambda-deployment/` - AI service backend
112
+ - **Connection**: `RemoteAIService` connects client to Lambda
113
+
114
+ See `lambda-deployment/README.md` for detailed deployment instructions.