humanbehavior-js 0.4.7 → 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 (52) hide show
  1. package/dist/cjs/angular/index.cjs +5 -6
  2. package/dist/cjs/angular/index.cjs.map +1 -1
  3. package/dist/cjs/index.cjs +5 -6
  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 +5 -6
  8. package/dist/cjs/react/index.cjs.map +1 -1
  9. package/dist/cjs/remix/index.cjs +5 -6
  10. package/dist/cjs/remix/index.cjs.map +1 -1
  11. package/dist/cjs/svelte/index.cjs +5 -6
  12. package/dist/cjs/svelte/index.cjs.map +1 -1
  13. package/dist/cjs/vue/index.cjs +5 -6
  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 +5 -6
  22. package/dist/esm/angular/index.js.map +1 -1
  23. package/dist/esm/index.js +5 -6
  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 +5 -6
  28. package/dist/esm/react/index.js.map +1 -1
  29. package/dist/esm/remix/index.js +5 -6
  30. package/dist/esm/remix/index.js.map +1 -1
  31. package/dist/esm/svelte/index.js +5 -6
  32. package/dist/esm/svelte/index.js.map +1 -1
  33. package/dist/esm/vue/index.js +5 -6
  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.map +1 -1
  38. package/dist/types/install-wizard.d.ts +8 -8
  39. package/dist/types/wizard/index.d.ts +489 -0
  40. package/package.json +14 -8
  41. package/rollup.config.js +65 -3
  42. package/src/react/AutoInstallWizard.tsx +1 -1
  43. package/src/tracker.ts +5 -6
  44. package/src/wizard/README.md +114 -0
  45. package/src/wizard/ai/ai-install-wizard.ts +894 -0
  46. package/src/wizard/ai/manual-framework-wizard.ts +236 -0
  47. package/src/wizard/cli/ai-auto-install.ts +369 -0
  48. package/src/{cli → wizard/cli}/auto-install.ts +1 -1
  49. package/src/{install-wizard.ts → wizard/core/install-wizard.ts} +12 -10
  50. package/src/wizard/index.ts +23 -0
  51. package/src/wizard/services/centralized-ai-service.ts +668 -0
  52. package/src/wizard/services/remote-ai-service.ts +224 -0
@@ -0,0 +1,224 @@
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' | 'node';
12
+ bundler?: 'vite' | 'webpack' | 'esbuild' | 'rollup';
13
+ packageManager?: 'npm' | 'yarn' | 'pnpm';
14
+ hasTypeScript?: boolean;
15
+ hasRouter?: boolean;
16
+ projectRoot?: string;
17
+ }
18
+
19
+ export interface RemoteAIServiceConfig {
20
+ apiEndpoint: string;
21
+ timeout?: number;
22
+ }
23
+
24
+ export class RemoteAIService {
25
+ private config: RemoteAIServiceConfig;
26
+
27
+ constructor(config: RemoteAIServiceConfig) {
28
+ this.config = {
29
+ timeout: 10000, // 10 seconds
30
+ ...config
31
+ };
32
+ }
33
+
34
+ /**
35
+ * Analyze code patterns using your deployed AI service
36
+ */
37
+ async analyzeCodePatterns(codeSamples: string[]): Promise<AICodeAnalysis> {
38
+ try {
39
+ const response = await fetch(`${this.config.apiEndpoint}/analyze`, {
40
+ method: 'POST',
41
+ headers: {
42
+ 'Content-Type': 'application/json',
43
+ },
44
+ body: JSON.stringify({ codeSamples }),
45
+ signal: AbortSignal.timeout(this.config.timeout || 10000)
46
+ });
47
+
48
+ if (!response.ok) {
49
+ throw new Error(`AI service returned ${response.status}: ${response.statusText}`);
50
+ }
51
+
52
+ const result = await response.json();
53
+ return result.analysis;
54
+ } catch (error) {
55
+ console.warn('Remote AI service failed, falling back to heuristic analysis:', error);
56
+ return this.performHeuristicAnalysis(codeSamples);
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Resolve conflicts using your deployed AI service
62
+ */
63
+ async resolveConflicts(conflicts: string[], framework: FrameworkInfo): Promise<string[]> {
64
+ try {
65
+ const response = await fetch(`${this.config.apiEndpoint}/resolve-conflicts`, {
66
+ method: 'POST',
67
+ headers: {
68
+ 'Content-Type': 'application/json',
69
+ },
70
+ body: JSON.stringify({ conflicts, framework }),
71
+ signal: AbortSignal.timeout(this.config.timeout || 10000)
72
+ });
73
+
74
+ if (!response.ok) {
75
+ throw new Error(`AI service returned ${response.status}: ${response.statusText}`);
76
+ }
77
+
78
+ const result = await response.json();
79
+ return result.resolutions || [];
80
+ } catch (error) {
81
+ console.warn('Remote AI conflict resolution failed, using heuristic approach:', error);
82
+ return this.resolveConflictsHeuristic(conflicts, framework);
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Generate optimizations using your deployed AI service
88
+ */
89
+ async generateOptimizations(framework: FrameworkInfo, patterns: string[]): Promise<string[]> {
90
+ try {
91
+ const response = await fetch(`${this.config.apiEndpoint}/optimize`, {
92
+ method: 'POST',
93
+ headers: {
94
+ 'Content-Type': 'application/json',
95
+ },
96
+ body: JSON.stringify({ framework, patterns }),
97
+ signal: AbortSignal.timeout(this.config.timeout || 10000)
98
+ });
99
+
100
+ if (!response.ok) {
101
+ throw new Error(`AI service returned ${response.status}: ${response.statusText}`);
102
+ }
103
+
104
+ const result = await response.json();
105
+ return result.optimizations || [];
106
+ } catch (error) {
107
+ console.warn('Remote AI optimization generation failed, using heuristic approach:', error);
108
+ return this.generateOptimizationsHeuristic(framework, patterns);
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Heuristic analysis fallback
114
+ */
115
+ private performHeuristicAnalysis(codeSamples: string[]): AICodeAnalysis {
116
+ const patterns = codeSamples.join(' ').toLowerCase();
117
+
118
+ // Framework detection
119
+ let framework: FrameworkInfo = { name: 'vanilla', type: 'vanilla' };
120
+ let confidence = 0.5;
121
+
122
+ 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')) {
123
+ framework = { name: 'nuxt', type: 'nuxt' };
124
+ confidence = 0.95;
125
+ } 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/')) {
126
+ framework = { name: 'nextjs', type: 'nextjs' };
127
+ confidence = 0.95;
128
+ } else if (patterns.includes('react')) {
129
+ framework = { name: 'react', type: 'react' };
130
+ confidence = 0.9;
131
+ } else if (patterns.includes('vue')) {
132
+ framework = { name: 'vue', type: 'vue' };
133
+ confidence = 0.9;
134
+ } else if (patterns.includes('angular')) {
135
+ framework = { name: 'angular', type: 'angular' };
136
+ confidence = 0.9;
137
+ } else if (patterns.includes('svelte')) {
138
+ framework = { name: 'svelte', type: 'svelte' };
139
+ confidence = 0.9;
140
+ }
141
+
142
+ // Integration strategy
143
+ let integrationStrategy: 'provider' | 'plugin' | 'module' | 'script' | 'standalone' = 'script';
144
+ if (framework.type === 'react' || framework.type === 'nextjs') {
145
+ integrationStrategy = 'provider';
146
+ } else if (framework.type === 'vue') {
147
+ integrationStrategy = 'plugin';
148
+ } else if (framework.type === 'angular') {
149
+ integrationStrategy = 'module';
150
+ }
151
+
152
+ // Compatibility mode
153
+ let compatibilityMode: 'modern' | 'legacy' | 'hybrid' = 'modern';
154
+ if (patterns.includes('require(') || patterns.includes('var ')) {
155
+ compatibilityMode = 'legacy';
156
+ }
157
+
158
+ return {
159
+ framework,
160
+ confidence,
161
+ patterns: codeSamples,
162
+ conflicts: [],
163
+ recommendations: [],
164
+ integrationStrategy,
165
+ compatibilityMode
166
+ };
167
+ }
168
+
169
+ /**
170
+ * Heuristic conflict resolution
171
+ */
172
+ private resolveConflictsHeuristic(conflicts: string[], framework: FrameworkInfo): string[] {
173
+ const resolutions: string[] = [];
174
+
175
+ for (const conflict of conflicts) {
176
+ switch (conflict) {
177
+ case 'existing_humanbehavior_code':
178
+ resolutions.push('update_existing_integration');
179
+ break;
180
+ case 'existing_provider':
181
+ resolutions.push('merge_providers');
182
+ break;
183
+ case 'module_system_conflict':
184
+ resolutions.push('hybrid_module_support');
185
+ break;
186
+ default:
187
+ resolutions.push('skip_conflict');
188
+ }
189
+ }
190
+
191
+ return resolutions;
192
+ }
193
+
194
+ /**
195
+ * Heuristic optimization generation
196
+ */
197
+ private generateOptimizationsHeuristic(framework: FrameworkInfo, patterns: string[]): string[] {
198
+ const optimizations: string[] = [];
199
+
200
+ switch (framework.type) {
201
+ case 'react':
202
+ optimizations.push('Use React.memo for performance optimization');
203
+ optimizations.push('Implement error boundaries for better error tracking');
204
+ optimizations.push('Consider using React.lazy for code splitting');
205
+ break;
206
+ case 'vue':
207
+ optimizations.push('Use Vue 3 Composition API for better performance');
208
+ optimizations.push('Implement proper error handling in components');
209
+ optimizations.push('Consider using Vue Router for navigation tracking');
210
+ break;
211
+ case 'angular':
212
+ optimizations.push('Use Angular standalone components for better tree-shaking');
213
+ optimizations.push('Implement proper error handling with ErrorHandler');
214
+ optimizations.push('Consider using Angular signals for state management');
215
+ break;
216
+ default:
217
+ optimizations.push('Enable performance tracking');
218
+ optimizations.push('Implement error tracking');
219
+ optimizations.push('Consider progressive enhancement');
220
+ }
221
+
222
+ return optimizations;
223
+ }
224
+ }