humanbehavior-js 0.4.16 → 0.4.17

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,240 @@
1
+ /**
2
+ * Remote AI Service Implementation
3
+ *
4
+ * This connects to your deployed Lambda function via API Gateway
5
+ */
6
+
7
+ import { AICodeAnalysis } from '../ai/ai-install-wizard';
8
+
9
+ export interface FrameworkInfo {
10
+ name: string;
11
+ type: 'react' | 'vue' | 'angular' | 'svelte' | 'nextjs' | 'nuxt' | 'remix' | 'vanilla' | 'astro' | 'gatsby' | 'node';
12
+ bundler?: 'vite' | 'webpack' | 'esbuild' | 'rollup';
13
+ packageManager?: 'npm' | 'yarn' | 'pnpm';
14
+ hasTypeScript?: boolean;
15
+ hasRouter?: boolean;
16
+ projectRoot?: string;
17
+ version?: string;
18
+ majorVersion?: number;
19
+ features?: {
20
+ hasReact18?: boolean;
21
+ hasVue3?: boolean;
22
+ hasNuxt3?: boolean;
23
+ hasAngularStandalone?: boolean;
24
+ hasNextAppRouter?: boolean;
25
+ hasSvelteKit?: boolean;
26
+ };
27
+ }
28
+
29
+ export interface RemoteAIServiceConfig {
30
+ apiEndpoint: string;
31
+ timeout?: number;
32
+ }
33
+
34
+ export class RemoteAIService {
35
+ private config: RemoteAIServiceConfig;
36
+
37
+ constructor(config: RemoteAIServiceConfig) {
38
+ this.config = {
39
+ timeout: 10000, // 10 seconds
40
+ ...config
41
+ };
42
+ }
43
+
44
+ /**
45
+ * Analyze code patterns using your deployed AI service
46
+ */
47
+ async analyzeCodePatterns(codeSamples: string[]): Promise<AICodeAnalysis> {
48
+ try {
49
+ const response = await fetch(`${this.config.apiEndpoint}/analyze`, {
50
+ method: 'POST',
51
+ headers: {
52
+ 'Content-Type': 'application/json',
53
+ },
54
+ body: JSON.stringify({ codeSamples }),
55
+ signal: AbortSignal.timeout(this.config.timeout || 10000)
56
+ });
57
+
58
+ if (!response.ok) {
59
+ throw new Error(`AI service returned ${response.status}: ${response.statusText}`);
60
+ }
61
+
62
+ const result = await response.json();
63
+ return result.analysis;
64
+ } catch (error) {
65
+ console.warn('Remote AI service failed, falling back to heuristic analysis:', error);
66
+ return this.performHeuristicAnalysis(codeSamples);
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Resolve conflicts using your deployed AI service
72
+ */
73
+ async resolveConflicts(conflicts: string[], framework: FrameworkInfo): Promise<string[]> {
74
+ try {
75
+ const response = await fetch(`${this.config.apiEndpoint}/resolve-conflicts`, {
76
+ method: 'POST',
77
+ headers: {
78
+ 'Content-Type': 'application/json',
79
+ },
80
+ body: JSON.stringify({ conflicts, framework }),
81
+ signal: AbortSignal.timeout(this.config.timeout || 10000)
82
+ });
83
+
84
+ if (!response.ok) {
85
+ throw new Error(`AI service returned ${response.status}: ${response.statusText}`);
86
+ }
87
+
88
+ const result = await response.json();
89
+ return result.resolutions || [];
90
+ } catch (error) {
91
+ console.warn('Remote AI conflict resolution failed, using heuristic approach:', error);
92
+ return this.resolveConflictsHeuristic(conflicts, framework);
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Generate optimizations using your deployed AI service
98
+ */
99
+ async generateOptimizations(framework: FrameworkInfo, patterns: string[]): Promise<string[]> {
100
+ try {
101
+ const response = await fetch(`${this.config.apiEndpoint}/optimize`, {
102
+ method: 'POST',
103
+ headers: {
104
+ 'Content-Type': 'application/json',
105
+ },
106
+ body: JSON.stringify({ framework, patterns }),
107
+ signal: AbortSignal.timeout(this.config.timeout || 10000)
108
+ });
109
+
110
+ if (!response.ok) {
111
+ throw new Error(`AI service returned ${response.status}: ${response.statusText}`);
112
+ }
113
+
114
+ const result = await response.json();
115
+ return result.optimizations || [];
116
+ } catch (error) {
117
+ console.warn('Remote AI optimization generation failed, using heuristic approach:', error);
118
+ return this.generateOptimizationsHeuristic(framework, patterns);
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Heuristic analysis fallback
124
+ */
125
+ private performHeuristicAnalysis(codeSamples: string[]): AICodeAnalysis {
126
+ const patterns = codeSamples.join(' ').toLowerCase();
127
+
128
+ // Framework detection
129
+ let framework: FrameworkInfo = { name: 'vanilla', type: 'vanilla' };
130
+ let confidence = 0.5;
131
+
132
+ if (patterns.includes('nuxt') || patterns.includes('nuxtjs') || patterns.includes('defineNuxtConfig') || patterns.includes('nuxt.config') || patterns.includes('@nuxt/') || patterns.includes('useNuxtApp') || patterns.includes('useRuntimeConfig') || patterns.includes('useSeoMeta') || patterns.includes('useHead') || patterns.includes('useLazyFetch') || patterns.includes('useFetch') || patterns.includes('useAsyncData') || patterns.includes('#app')) {
133
+ framework = { name: 'nuxt', type: 'nuxt' };
134
+ confidence = 0.95;
135
+ } else if (patterns.includes('next') || patterns.includes('nextjs') || patterns.includes('next/link') || patterns.includes('next/image') || patterns.includes('next/navigation') || patterns.includes('next/router') || patterns.includes('getserverSideProps') || patterns.includes('getstaticProps') || patterns.includes('getstaticPaths') || patterns.includes('app/layout') || patterns.includes('app/page') || patterns.includes('pages/')) {
136
+ framework = { name: 'nextjs', type: 'nextjs' };
137
+ confidence = 0.95;
138
+ } else if (patterns.includes('gatsby') || patterns.includes('gatsby-browser') || patterns.includes('gatsby-ssr') || patterns.includes('gatsby-node') || patterns.includes('gatsby-config') || patterns.includes('useStaticQuery') || patterns.includes('graphql')) {
139
+ framework = { name: 'gatsby', type: 'gatsby' };
140
+ confidence = 0.95;
141
+ } else if (patterns.includes('react')) {
142
+ framework = { name: 'react', type: 'react' };
143
+ confidence = 0.9;
144
+ } else if (patterns.includes('vue')) {
145
+ framework = { name: 'vue', type: 'vue' };
146
+ confidence = 0.9;
147
+ } else if (patterns.includes('angular')) {
148
+ framework = { name: 'angular', type: 'angular' };
149
+ confidence = 0.9;
150
+ } else if (patterns.includes('svelte')) {
151
+ framework = { name: 'svelte', type: 'svelte' };
152
+ confidence = 0.9;
153
+ } else if (patterns.includes('astro')) {
154
+ framework = { name: 'astro', type: 'astro' };
155
+ confidence = 0.9;
156
+ }
157
+
158
+ // Integration strategy
159
+ let integrationStrategy: 'provider' | 'plugin' | 'module' | 'script' | 'standalone' = 'script';
160
+ if (framework.type === 'react' || framework.type === 'nextjs' || framework.type === 'gatsby') {
161
+ integrationStrategy = 'provider';
162
+ } else if (framework.type === 'vue') {
163
+ integrationStrategy = 'plugin';
164
+ } else if (framework.type === 'angular') {
165
+ integrationStrategy = 'module';
166
+ }
167
+
168
+ // Compatibility mode
169
+ let compatibilityMode: 'modern' | 'legacy' | 'hybrid' = 'modern';
170
+ if (patterns.includes('require(') || patterns.includes('var ')) {
171
+ compatibilityMode = 'legacy';
172
+ }
173
+
174
+ return {
175
+ framework,
176
+ confidence,
177
+ patterns: codeSamples,
178
+ conflicts: [],
179
+ recommendations: [],
180
+ integrationStrategy,
181
+ compatibilityMode
182
+ };
183
+ }
184
+
185
+ /**
186
+ * Heuristic conflict resolution
187
+ */
188
+ private resolveConflictsHeuristic(conflicts: string[], framework: FrameworkInfo): string[] {
189
+ const resolutions: string[] = [];
190
+
191
+ for (const conflict of conflicts) {
192
+ switch (conflict) {
193
+ case 'existing_humanbehavior_code':
194
+ resolutions.push('update_existing_integration');
195
+ break;
196
+ case 'existing_provider':
197
+ resolutions.push('merge_providers');
198
+ break;
199
+ case 'module_system_conflict':
200
+ resolutions.push('hybrid_module_support');
201
+ break;
202
+ default:
203
+ resolutions.push('skip_conflict');
204
+ }
205
+ }
206
+
207
+ return resolutions;
208
+ }
209
+
210
+ /**
211
+ * Heuristic optimization generation
212
+ */
213
+ private generateOptimizationsHeuristic(framework: FrameworkInfo, patterns: string[]): string[] {
214
+ const optimizations: string[] = [];
215
+
216
+ switch (framework.type) {
217
+ case 'react':
218
+ optimizations.push('Use React.memo for performance optimization');
219
+ optimizations.push('Implement error boundaries for better error tracking');
220
+ optimizations.push('Consider using React.lazy for code splitting');
221
+ break;
222
+ case 'vue':
223
+ optimizations.push('Use Vue 3 Composition API for better performance');
224
+ optimizations.push('Implement proper error handling in components');
225
+ optimizations.push('Consider using Vue Router for navigation tracking');
226
+ break;
227
+ case 'angular':
228
+ optimizations.push('Use Angular standalone components for better tree-shaking');
229
+ optimizations.push('Implement proper error handling with ErrorHandler');
230
+ optimizations.push('Consider using Angular signals for state management');
231
+ break;
232
+ default:
233
+ optimizations.push('Enable performance tracking');
234
+ optimizations.push('Implement error tracking');
235
+ optimizations.push('Consider progressive enhancement');
236
+ }
237
+
238
+ return optimizations;
239
+ }
240
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./dist/",
4
+ "sourceMap": true,
5
+ "noImplicitAny": true,
6
+ "module": "ESNext",
7
+ "target": "es2015",
8
+ "downlevelIteration": true,
9
+ "jsx": "react",
10
+ "allowJs": true,
11
+ "moduleResolution": "node",
12
+ "allowSyntheticDefaultImports": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "esModuleInterop": true,
16
+ "strict": true,
17
+ "skipLibCheck": true,
18
+ "forceConsistentCasingInFileNames": true,
19
+ "lib": ["dom", "dom.iterable", "esnext"]
20
+ },
21
+ "include": ["src/**/*.ts", "src/**/*.tsx", "src/types/**/*.d.ts"],
22
+
23
+ "exclude": ["node_modules", "dist", "test-website"]
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "humanbehavior-js",
3
- "version": "0.4.16",
3
+ "version": "0.4.17",
4
4
  "description": "SDK for HumanBehavior session and event recording",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -231,13 +231,11 @@ Examples:
231
231
  }
232
232
 
233
233
  // Main execution
234
- if (import.meta.url === `file://${process.argv[1]}`) {
235
- const options = parseArgs();
236
- const cli = new AIAutoInstallCLI(options);
237
- cli.run().catch((error) => {
234
+ const options = parseArgs();
235
+ const cli = new AIAutoInstallCLI(options);
236
+ cli.run().catch((error) => {
238
237
  clack.cancel(`Unexpected error: ${error.message}`);
239
238
  process.exit(1);
240
- });
241
- }
239
+ });
242
240
 
243
241
  export { AIAutoInstallCLI };