humanbehavior-js 0.4.16 → 0.4.18

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 (89) hide show
  1. package/dist/cjs/wizard/index.cjs +6 -8
  2. package/dist/cjs/wizard/index.cjs.map +1 -1
  3. package/dist/cli/ai-auto-install.js +6 -8
  4. package/dist/cli/ai-auto-install.js.map +1 -1
  5. package/dist/esm/wizard/index.js +6 -8
  6. package/dist/esm/wizard/index.js.map +1 -1
  7. package/package/WIZARD_USAGE_GUIDE.md +381 -0
  8. package/package/canvas-recording-demo.html +143 -0
  9. package/package/clean-console-demo.html +39 -0
  10. package/package/dist/cjs/angular/index.cjs +14354 -0
  11. package/package/dist/cjs/angular/index.cjs.map +1 -0
  12. package/package/dist/cjs/index.cjs +14323 -0
  13. package/package/dist/cjs/index.cjs.map +1 -0
  14. package/package/dist/cjs/install-wizard.cjs +1530 -0
  15. package/package/dist/cjs/install-wizard.cjs.map +1 -0
  16. package/package/dist/cjs/react/index.cjs +14478 -0
  17. package/package/dist/cjs/react/index.cjs.map +1 -0
  18. package/package/dist/cjs/remix/index.cjs +14452 -0
  19. package/package/dist/cjs/remix/index.cjs.map +1 -0
  20. package/package/dist/cjs/svelte/index.cjs +14308 -0
  21. package/package/dist/cjs/svelte/index.cjs.map +1 -0
  22. package/package/dist/cjs/vue/index.cjs +14317 -0
  23. package/package/dist/cjs/vue/index.cjs.map +1 -0
  24. package/package/dist/cjs/wizard/index.cjs +3446 -0
  25. package/package/dist/cjs/wizard/index.cjs.map +1 -0
  26. package/package/dist/cli/ai-auto-install.cjs +57161 -0
  27. package/package/dist/cli/ai-auto-install.cjs.map +1 -0
  28. package/package/dist/cli/ai-auto-install.js +1969 -0
  29. package/package/dist/cli/ai-auto-install.js.map +1 -0
  30. package/package/dist/cli/auto-install.cjs +56352 -0
  31. package/package/dist/cli/auto-install.cjs.map +1 -0
  32. package/package/dist/cli/auto-install.js +1957 -0
  33. package/package/dist/cli/auto-install.js.map +1 -0
  34. package/package/dist/esm/angular/index.js +14350 -0
  35. package/package/dist/esm/angular/index.js.map +1 -0
  36. package/package/dist/esm/index.js +14309 -0
  37. package/package/dist/esm/index.js.map +1 -0
  38. package/package/dist/esm/install-wizard.js +1507 -0
  39. package/package/dist/esm/install-wizard.js.map +1 -0
  40. package/package/dist/esm/react/index.js +14472 -0
  41. package/package/dist/esm/react/index.js.map +1 -0
  42. package/package/dist/esm/remix/index.js +14448 -0
  43. package/package/dist/esm/remix/index.js.map +1 -0
  44. package/package/dist/esm/svelte/index.js +14306 -0
  45. package/package/dist/esm/svelte/index.js.map +1 -0
  46. package/package/dist/esm/vue/index.js +14315 -0
  47. package/package/dist/esm/vue/index.js.map +1 -0
  48. package/package/dist/esm/wizard/index.js +3415 -0
  49. package/package/dist/esm/wizard/index.js.map +1 -0
  50. package/package/dist/index.min.js +2 -0
  51. package/package/dist/index.min.js.map +1 -0
  52. package/package/dist/types/angular/index.d.ts +267 -0
  53. package/package/dist/types/index.d.ts +373 -0
  54. package/package/dist/types/install-wizard.d.ts +156 -0
  55. package/package/dist/types/react/index.d.ts +255 -0
  56. package/package/dist/types/remix/index.d.ts +246 -0
  57. package/package/dist/types/svelte/index.d.ts +232 -0
  58. package/package/dist/types/vue/index.d.ts +15 -0
  59. package/package/dist/types/wizard/index.d.ts +523 -0
  60. package/package/package.json +105 -0
  61. package/package/readme.md +281 -0
  62. package/package/rollup.config.js +422 -0
  63. package/package/simple-demo.html +26 -0
  64. package/package/simple-spa.html +838 -0
  65. package/package/src/angular/index.ts +79 -0
  66. package/package/src/api.ts +376 -0
  67. package/package/src/index.ts +28 -0
  68. package/package/src/react/AutoInstallWizard.tsx +557 -0
  69. package/package/src/react/browser.ts +8 -0
  70. package/package/src/react/index.tsx +308 -0
  71. package/package/src/redact.ts +521 -0
  72. package/package/src/remix/index.ts +16 -0
  73. package/package/src/svelte/index.ts +14 -0
  74. package/package/src/tracker.ts +1319 -0
  75. package/package/src/types/clack.d.ts +31 -0
  76. package/package/src/utils/logger.ts +144 -0
  77. package/package/src/vue/index.ts +29 -0
  78. package/package/src/wizard/README.md +114 -0
  79. package/package/src/wizard/ai/ai-install-wizard.ts +897 -0
  80. package/package/src/wizard/ai/manual-framework-wizard.ts +238 -0
  81. package/package/src/wizard/cli/ai-auto-install.ts +243 -0
  82. package/package/src/wizard/cli/auto-install.ts +224 -0
  83. package/package/src/wizard/core/install-wizard.ts +1744 -0
  84. package/package/src/wizard/index.ts +23 -0
  85. package/package/src/wizard/services/centralized-ai-service.ts +668 -0
  86. package/package/src/wizard/services/remote-ai-service.ts +240 -0
  87. package/package/tsconfig.json +24 -0
  88. package/package.json +1 -1
  89. package/src/wizard/cli/ai-auto-install.ts +4 -6
@@ -0,0 +1,31 @@
1
+ declare module '@clack/prompts' {
2
+ export function intro(message: string): void;
3
+ export function outro(message: string): void;
4
+ export function cancel(message: string): void;
5
+ export function note(message: string, title?: string): void;
6
+
7
+ export function text(options: {
8
+ message: string;
9
+ placeholder?: string;
10
+ defaultValue?: string;
11
+ validate?: (value: string) => string | undefined;
12
+ }): Promise<string>;
13
+
14
+ export function select(options: {
15
+ message: string;
16
+ options: Array<{
17
+ label: string;
18
+ value: string;
19
+ hint?: string;
20
+ }>;
21
+ }): Promise<string>;
22
+
23
+ export function confirm(options: {
24
+ message: string;
25
+ }): Promise<boolean>;
26
+
27
+ export function spinner(): {
28
+ start(message: string): void;
29
+ stop(message?: string): void;
30
+ };
31
+ }
@@ -0,0 +1,144 @@
1
+ export enum LogLevel {
2
+ NONE = 0,
3
+ ERROR = 1,
4
+ WARN = 2,
5
+ INFO = 3,
6
+ DEBUG = 4
7
+ }
8
+
9
+ export interface LoggerConfig {
10
+ level: LogLevel;
11
+ enableConsole: boolean;
12
+ enableStorage: boolean;
13
+ }
14
+
15
+ class Logger {
16
+ private config: LoggerConfig = {
17
+ level: LogLevel.ERROR, // Default to only errors in production
18
+ enableConsole: true,
19
+ enableStorage: false
20
+ };
21
+
22
+ private isBrowser = typeof window !== 'undefined';
23
+
24
+ constructor(config?: Partial<LoggerConfig>) {
25
+ if (config) {
26
+ this.config = { ...this.config, ...config };
27
+ }
28
+ }
29
+
30
+ setConfig(config: Partial<LoggerConfig>): void {
31
+ this.config = { ...this.config, ...config };
32
+ }
33
+
34
+ private shouldLog(level: LogLevel): boolean {
35
+ return level <= this.config.level;
36
+ }
37
+
38
+ private formatMessage(level: string, message: string, ...args: any[]): string {
39
+ const timestamp = new Date().toISOString();
40
+ return `[HumanBehavior ${level}] ${timestamp}: ${message}`;
41
+ }
42
+
43
+ error(message: string, ...args: any[]): void {
44
+ if (!this.shouldLog(LogLevel.ERROR)) return;
45
+
46
+ const formattedMessage = this.formatMessage('ERROR', message);
47
+
48
+ if (this.config.enableConsole) {
49
+ console.error(formattedMessage, ...args);
50
+ }
51
+
52
+ if (this.config.enableStorage && this.isBrowser) {
53
+ this.logToStorage(formattedMessage, args);
54
+ }
55
+ }
56
+
57
+ warn(message: string, ...args: any[]): void {
58
+ if (!this.shouldLog(LogLevel.WARN)) return;
59
+
60
+ const formattedMessage = this.formatMessage('WARN', message);
61
+
62
+ if (this.config.enableConsole) {
63
+ console.warn(formattedMessage, ...args);
64
+ }
65
+
66
+ if (this.config.enableStorage && this.isBrowser) {
67
+ this.logToStorage(formattedMessage, args);
68
+ }
69
+ }
70
+
71
+ info(message: string, ...args: any[]): void {
72
+ if (!this.shouldLog(LogLevel.INFO)) return;
73
+
74
+ const formattedMessage = this.formatMessage('INFO', message);
75
+
76
+ if (this.config.enableConsole) {
77
+ console.log(formattedMessage, ...args);
78
+ }
79
+
80
+ if (this.config.enableStorage && this.isBrowser) {
81
+ this.logToStorage(formattedMessage, args);
82
+ }
83
+ }
84
+
85
+ debug(message: string, ...args: any[]): void {
86
+ if (!this.shouldLog(LogLevel.DEBUG)) return;
87
+
88
+ const formattedMessage = this.formatMessage('DEBUG', message);
89
+
90
+ if (this.config.enableConsole) {
91
+ console.log(formattedMessage, ...args);
92
+ }
93
+
94
+ if (this.config.enableStorage && this.isBrowser) {
95
+ this.logToStorage(formattedMessage, args);
96
+ }
97
+ }
98
+
99
+ private logToStorage(message: string, args: any[]): void {
100
+ try {
101
+ const logs = JSON.parse(localStorage.getItem('human_behavior_logs') || '[]');
102
+ const logEntry = {
103
+ message,
104
+ args: args.length > 0 ? args : undefined,
105
+ timestamp: Date.now()
106
+ };
107
+ logs.push(logEntry);
108
+
109
+ // Keep only last 1000 logs to prevent storage bloat
110
+ if (logs.length > 1000) {
111
+ logs.splice(0, logs.length - 1000);
112
+ }
113
+
114
+ localStorage.setItem('human_behavior_logs', JSON.stringify(logs));
115
+ } catch (e) {
116
+ // Silently fail if storage is not available
117
+ }
118
+ }
119
+
120
+ getLogs(): any[] {
121
+ if (!this.isBrowser) return [];
122
+
123
+ try {
124
+ return JSON.parse(localStorage.getItem('human_behavior_logs') || '[]');
125
+ } catch (e) {
126
+ return [];
127
+ }
128
+ }
129
+
130
+ clearLogs(): void {
131
+ if (this.isBrowser) {
132
+ localStorage.removeItem('human_behavior_logs');
133
+ }
134
+ }
135
+ }
136
+
137
+ // Create singleton instance
138
+ export const logger = new Logger();
139
+
140
+ // Export convenience methods
141
+ export const logError = (message: string, ...args: any[]) => logger.error(message, ...args);
142
+ export const logWarn = (message: string, ...args: any[]) => logger.warn(message, ...args);
143
+ export const logInfo = (message: string, ...args: any[]) => logger.info(message, ...args);
144
+ export const logDebug = (message: string, ...args: any[]) => logger.debug(message, ...args);
@@ -0,0 +1,29 @@
1
+ import { HumanBehaviorTracker } from '../index.js';
2
+ import type { App } from 'vue';
3
+
4
+ interface HumanBehaviorPluginOptions {
5
+ apiKey: string;
6
+ ingestionUrl?: string;
7
+ logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
8
+ redactFields?: string[];
9
+ suppressConsoleErrors?: boolean;
10
+ recordCanvas?: boolean; // Enable canvas recording with PostHog-style protection
11
+ }
12
+
13
+ export const HumanBehaviorPlugin = {
14
+ install: (app: App, options: HumanBehaviorPluginOptions) => {
15
+ const tracker = HumanBehaviorTracker.init(options.apiKey, {
16
+ ingestionUrl: options.ingestionUrl,
17
+ logLevel: options.logLevel,
18
+ redactFields: options.redactFields,
19
+ suppressConsoleErrors: options.suppressConsoleErrors,
20
+ recordCanvas: options.recordCanvas, // Pass canvas recording option
21
+ });
22
+
23
+ // Make tracker available globally
24
+ app.config.globalProperties.$humanBehavior = tracker;
25
+
26
+ // Also provide it via inject/provide
27
+ app.provide('humanBehavior', tracker);
28
+ }
29
+ };
@@ -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.