humanbehavior-js 0.4.27 → 0.5.0
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.
- package/README.md +151 -0
- package/package.json +114 -71
- package/packages/angular/dist/index.d.ts +46 -0
- package/packages/angular/dist/index.d.ts.map +1 -0
- package/packages/angular/dist/index.js +2 -0
- package/packages/angular/dist/index.js.map +1 -0
- package/packages/angular/dist/index.mjs +2 -0
- package/packages/angular/dist/index.mjs.map +1 -0
- package/packages/browser/dist/index.d.ts +5 -0
- package/packages/browser/dist/index.d.ts.map +1 -0
- package/packages/browser/dist/index.iife.js +12095 -0
- package/packages/browser/dist/index.iife.js.map +1 -0
- package/packages/browser/dist/index.js +2 -0
- package/packages/browser/dist/index.js.map +1 -0
- package/packages/browser/dist/index.min.js +2 -0
- package/packages/browser/dist/index.min.js.map +1 -0
- package/packages/browser/dist/index.mjs +2 -0
- package/packages/browser/dist/index.mjs.map +1 -0
- package/packages/react/dist/browser.d.ts +2 -0
- package/packages/react/dist/browser.d.ts.map +1 -0
- package/packages/react/dist/index.d.ts +48 -0
- package/packages/react/dist/index.d.ts.map +1 -0
- package/packages/react/dist/index.js +2 -0
- package/packages/react/dist/index.js.map +1 -0
- package/packages/react/dist/index.mjs +2 -0
- package/packages/react/dist/index.mjs.map +1 -0
- package/packages/remix/dist/index.d.ts +8 -0
- package/packages/remix/dist/index.d.ts.map +1 -0
- package/packages/remix/dist/index.js +2 -0
- package/packages/remix/dist/index.js.map +1 -0
- package/packages/remix/dist/index.mjs +2 -0
- package/packages/remix/dist/index.mjs.map +1 -0
- package/packages/svelte/dist/index.d.ts +11 -0
- package/packages/svelte/dist/index.d.ts.map +1 -0
- package/packages/svelte/dist/index.js +2 -0
- package/packages/svelte/dist/index.js.map +1 -0
- package/packages/svelte/dist/index.mjs +2 -0
- package/packages/svelte/dist/index.mjs.map +1 -0
- package/{dist/types/vue → packages/vue/dist}/index.d.ts +4 -5
- package/packages/vue/dist/index.d.ts.map +1 -0
- package/packages/vue/dist/index.js +2 -0
- package/packages/vue/dist/index.js.map +1 -0
- package/packages/vue/dist/index.mjs +2 -0
- package/packages/vue/dist/index.mjs.map +1 -0
- package/packages/wizard/dist/ai/ai-install-wizard.d.ts +145 -0
- package/packages/wizard/dist/ai/ai-install-wizard.d.ts.map +1 -0
- package/packages/wizard/dist/ai/manual-framework-wizard.d.ts +52 -0
- package/packages/wizard/dist/ai/manual-framework-wizard.d.ts.map +1 -0
- package/packages/wizard/dist/cli/ai-auto-install.d.ts +27 -0
- package/packages/wizard/dist/cli/ai-auto-install.d.ts.map +1 -0
- package/{dist → packages/wizard/dist}/cli/ai-auto-install.js +821 -905
- package/packages/wizard/dist/cli/ai-auto-install.js.map +1 -0
- package/packages/wizard/dist/cli/auto-install.d.ts +26 -0
- package/packages/wizard/dist/cli/auto-install.d.ts.map +1 -0
- package/{dist → packages/wizard/dist}/cli/auto-install.js +821 -905
- package/packages/wizard/dist/cli/auto-install.js.map +1 -0
- package/{dist/types → packages/wizard/dist/core}/install-wizard.d.ts +6 -8
- package/packages/wizard/dist/core/install-wizard.d.ts.map +1 -0
- package/packages/wizard/dist/index.d.ts +18 -0
- package/packages/wizard/dist/index.d.ts.map +1 -0
- package/packages/wizard/dist/index.js +2 -0
- package/packages/wizard/dist/index.js.map +1 -0
- package/packages/wizard/dist/index.mjs +2 -0
- package/packages/wizard/dist/index.mjs.map +1 -0
- package/packages/wizard/dist/services/centralized-ai-service.d.ts +159 -0
- package/packages/wizard/dist/services/centralized-ai-service.d.ts.map +1 -0
- package/packages/wizard/dist/services/remote-ai-service.d.ts +58 -0
- package/packages/wizard/dist/services/remote-ai-service.d.ts.map +1 -0
- package/WIZARD_USAGE_GUIDE.md +0 -381
- package/dist/cjs/angular/index.cjs +0 -14979
- package/dist/cjs/angular/index.cjs.map +0 -1
- package/dist/cjs/index.cjs +0 -14964
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/install-wizard.cjs +0 -1576
- package/dist/cjs/install-wizard.cjs.map +0 -1
- package/dist/cjs/react/index.cjs +0 -15103
- package/dist/cjs/react/index.cjs.map +0 -1
- package/dist/cjs/remix/index.cjs +0 -15077
- package/dist/cjs/remix/index.cjs.map +0 -1
- package/dist/cjs/svelte/index.cjs +0 -14933
- package/dist/cjs/svelte/index.cjs.map +0 -1
- package/dist/cjs/vue/index.cjs +0 -14942
- package/dist/cjs/vue/index.cjs.map +0 -1
- package/dist/cjs/wizard/index.cjs +0 -3490
- package/dist/cjs/wizard/index.cjs.map +0 -1
- package/dist/cli/ai-auto-install.js.map +0 -1
- package/dist/cli/auto-install.js.map +0 -1
- package/dist/esm/angular/index.js +0 -14975
- package/dist/esm/angular/index.js.map +0 -1
- package/dist/esm/index.js +0 -14941
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/install-wizard.js +0 -1553
- package/dist/esm/install-wizard.js.map +0 -1
- package/dist/esm/react/index.js +0 -15097
- package/dist/esm/react/index.js.map +0 -1
- package/dist/esm/remix/index.js +0 -15073
- package/dist/esm/remix/index.js.map +0 -1
- package/dist/esm/svelte/index.js +0 -14931
- package/dist/esm/svelte/index.js.map +0 -1
- package/dist/esm/vue/index.js +0 -14940
- package/dist/esm/vue/index.js.map +0 -1
- package/dist/esm/wizard/index.js +0 -3459
- package/dist/esm/wizard/index.js.map +0 -1
- package/dist/index.min.js +0 -2
- package/dist/index.min.js.map +0 -1
- package/dist/types/angular/index.d.ts +0 -357
- package/dist/types/index.d.ts +0 -644
- package/dist/types/react/index.d.ts +0 -345
- package/dist/types/remix/index.d.ts +0 -336
- package/dist/types/svelte/index.d.ts +0 -322
- package/dist/types/wizard/index.d.ts +0 -523
- package/readme.md +0 -335
- package/rollup.config.js +0 -422
- package/simple-spa.html +0 -1000
- package/src/angular/index.ts +0 -79
- package/src/api.ts +0 -416
- package/src/index.ts +0 -35
- package/src/react/AutoInstallWizard.tsx +0 -557
- package/src/react/browser.ts +0 -8
- package/src/react/index.tsx +0 -308
- package/src/redact.ts +0 -327
- package/src/remix/index.ts +0 -16
- package/src/svelte/index.ts +0 -14
- package/src/tracker.ts +0 -1587
- package/src/types/clack.d.ts +0 -31
- package/src/utils/ip-detector.ts +0 -158
- package/src/utils/logger.ts +0 -144
- package/src/utils/property-detector.ts +0 -345
- package/src/utils/property-manager.ts +0 -274
- package/src/vue/index.ts +0 -29
- package/src/wizard/README.md +0 -114
- package/src/wizard/ai/ai-install-wizard.ts +0 -897
- package/src/wizard/ai/manual-framework-wizard.ts +0 -238
- package/src/wizard/cli/ai-auto-install.ts +0 -241
- package/src/wizard/cli/auto-install.ts +0 -224
- package/src/wizard/core/install-wizard.ts +0 -1794
- package/src/wizard/index.ts +0 -23
- package/src/wizard/services/centralized-ai-service.ts +0 -668
- package/src/wizard/services/remote-ai-service.ts +0 -240
- package/tsconfig.json +0 -24
|
@@ -1,897 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AI-Enhanced HumanBehavior SDK Auto-Installation Wizard
|
|
3
|
-
*
|
|
4
|
-
* This wizard uses AI to intelligently detect frameworks, analyze code patterns,
|
|
5
|
-
* and generate optimal integration code that's both future-proof and backward-compatible.
|
|
6
|
-
*
|
|
7
|
-
* 🚀 KEY FEATURES:
|
|
8
|
-
* - AI-powered framework detection beyond package.json
|
|
9
|
-
* - Intelligent code pattern analysis
|
|
10
|
-
* - Future-proof integration strategies
|
|
11
|
-
* - Backward compatibility with legacy frameworks
|
|
12
|
-
* - Adaptive code generation for new frameworks
|
|
13
|
-
* - Smart conflict resolution
|
|
14
|
-
* - Learning from user feedback
|
|
15
|
-
* - Centralized AI service (no user API keys required)
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import * as fs from 'fs';
|
|
19
|
-
import * as path from 'path';
|
|
20
|
-
import { AutoInstallationWizard, FrameworkInfo, CodeModification, InstallationResult } from '../core/install-wizard';
|
|
21
|
-
|
|
22
|
-
export interface AICodeAnalysis {
|
|
23
|
-
framework: FrameworkInfo;
|
|
24
|
-
confidence: number;
|
|
25
|
-
patterns: string[];
|
|
26
|
-
conflicts: string[];
|
|
27
|
-
recommendations: string[];
|
|
28
|
-
integrationStrategy: 'provider' | 'plugin' | 'module' | 'script' | 'standalone';
|
|
29
|
-
compatibilityMode: 'modern' | 'legacy' | 'hybrid';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface AIInstallationResult extends InstallationResult {
|
|
33
|
-
aiAnalysis: AICodeAnalysis;
|
|
34
|
-
learningData: {
|
|
35
|
-
patterns: string[];
|
|
36
|
-
framework: string;
|
|
37
|
-
success: boolean;
|
|
38
|
-
userFeedback?: string;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Centralized AI Service Interface
|
|
44
|
-
* This runs on your backend infrastructure, not in the user's environment
|
|
45
|
-
*/
|
|
46
|
-
interface CentralizedAIService {
|
|
47
|
-
analyzeCodePatterns(codeSamples: string[]): Promise<AICodeAnalysis>;
|
|
48
|
-
resolveConflicts(conflicts: string[], framework: FrameworkInfo): Promise<string[]>;
|
|
49
|
-
generateOptimizations(framework: FrameworkInfo, patterns: string[]): Promise<string[]>;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Default AI Service Implementation
|
|
54
|
-
* Uses heuristic analysis when centralized service is not available
|
|
55
|
-
*/
|
|
56
|
-
class DefaultAIService implements CentralizedAIService {
|
|
57
|
-
async analyzeCodePatterns(codeSamples: string[]): Promise<AICodeAnalysis> {
|
|
58
|
-
return this.analyzeWithHeuristics(codeSamples);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async resolveConflicts(conflicts: string[], framework: FrameworkInfo): Promise<string[]> {
|
|
62
|
-
// Default conflict resolution strategies
|
|
63
|
-
const resolutions: string[] = [];
|
|
64
|
-
|
|
65
|
-
for (const conflict of conflicts) {
|
|
66
|
-
switch (conflict) {
|
|
67
|
-
case 'existing_humanbehavior_code':
|
|
68
|
-
resolutions.push('update_existing_integration');
|
|
69
|
-
break;
|
|
70
|
-
case 'existing_provider':
|
|
71
|
-
resolutions.push('merge_providers');
|
|
72
|
-
break;
|
|
73
|
-
case 'module_system_conflict':
|
|
74
|
-
resolutions.push('hybrid_module_support');
|
|
75
|
-
break;
|
|
76
|
-
default:
|
|
77
|
-
resolutions.push('skip_conflict');
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return resolutions;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async generateOptimizations(framework: FrameworkInfo, patterns: string[]): Promise<string[]> {
|
|
85
|
-
const optimizations: string[] = [];
|
|
86
|
-
|
|
87
|
-
// Framework-specific optimizations
|
|
88
|
-
switch (framework.type) {
|
|
89
|
-
case 'react':
|
|
90
|
-
optimizations.push('Use React.memo for performance optimization');
|
|
91
|
-
optimizations.push('Implement error boundaries for better error tracking');
|
|
92
|
-
optimizations.push('Consider using React.lazy for code splitting');
|
|
93
|
-
break;
|
|
94
|
-
case 'vue':
|
|
95
|
-
optimizations.push('Use Vue 3 Composition API for better performance');
|
|
96
|
-
optimizations.push('Implement proper error handling in components');
|
|
97
|
-
optimizations.push('Consider using Vue Router for navigation tracking');
|
|
98
|
-
break;
|
|
99
|
-
case 'angular':
|
|
100
|
-
optimizations.push('Use Angular standalone components for better tree-shaking');
|
|
101
|
-
optimizations.push('Implement proper error handling with ErrorHandler');
|
|
102
|
-
optimizations.push('Consider using Angular signals for state management');
|
|
103
|
-
break;
|
|
104
|
-
default:
|
|
105
|
-
optimizations.push('Enable performance tracking');
|
|
106
|
-
optimizations.push('Implement error tracking');
|
|
107
|
-
optimizations.push('Consider progressive enhancement');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return optimizations;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private analyzeWithHeuristics(codeSamples: string[]): AICodeAnalysis {
|
|
114
|
-
const patterns = codeSamples.join(' ').toLowerCase();
|
|
115
|
-
|
|
116
|
-
// Framework detection
|
|
117
|
-
let framework: FrameworkInfo = { name: 'vanilla', type: 'vanilla' };
|
|
118
|
-
let confidence = 0.5;
|
|
119
|
-
|
|
120
|
-
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')) {
|
|
121
|
-
framework = { name: 'nuxt', type: 'nuxt' };
|
|
122
|
-
confidence = 0.95;
|
|
123
|
-
} 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/')) {
|
|
124
|
-
framework = { name: 'nextjs', type: 'nextjs' };
|
|
125
|
-
confidence = 0.95;
|
|
126
|
-
} 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')) {
|
|
127
|
-
framework = { name: 'gatsby', type: 'gatsby' };
|
|
128
|
-
confidence = 0.95;
|
|
129
|
-
} else if (patterns.includes('react')) {
|
|
130
|
-
framework = { name: 'react', type: 'react' };
|
|
131
|
-
confidence = 0.9;
|
|
132
|
-
} else if (patterns.includes('vue')) {
|
|
133
|
-
framework = { name: 'vue', type: 'vue' };
|
|
134
|
-
confidence = 0.9;
|
|
135
|
-
} else if (patterns.includes('angular')) {
|
|
136
|
-
framework = { name: 'angular', type: 'angular' };
|
|
137
|
-
confidence = 0.9;
|
|
138
|
-
} else if (patterns.includes('svelte')) {
|
|
139
|
-
framework = { name: 'svelte', type: 'svelte' };
|
|
140
|
-
confidence = 0.9;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Integration strategy
|
|
144
|
-
let integrationStrategy: 'provider' | 'plugin' | 'module' | 'script' | 'standalone' = 'script';
|
|
145
|
-
if (framework.type === 'react' || framework.type === 'nextjs' || framework.type === 'gatsby') {
|
|
146
|
-
integrationStrategy = 'provider';
|
|
147
|
-
} else if (framework.type === 'vue') {
|
|
148
|
-
integrationStrategy = 'plugin';
|
|
149
|
-
} else if (framework.type === 'angular') {
|
|
150
|
-
integrationStrategy = 'module';
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Compatibility mode
|
|
154
|
-
let compatibilityMode: 'modern' | 'legacy' | 'hybrid' = 'modern';
|
|
155
|
-
if (patterns.includes('require(') || patterns.includes('var ')) {
|
|
156
|
-
compatibilityMode = 'legacy';
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return {
|
|
160
|
-
framework,
|
|
161
|
-
confidence,
|
|
162
|
-
patterns: codeSamples,
|
|
163
|
-
conflicts: [],
|
|
164
|
-
recommendations: [],
|
|
165
|
-
integrationStrategy,
|
|
166
|
-
compatibilityMode
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export class AIEnhancedInstallationWizard extends AutoInstallationWizard {
|
|
172
|
-
private aiService: CentralizedAIService;
|
|
173
|
-
private learningCache: Map<string, any> = new Map();
|
|
174
|
-
private patternDatabase: Map<string, any[]> = new Map();
|
|
175
|
-
|
|
176
|
-
constructor(apiKey: string, projectRoot: string = process.cwd(), aiService?: CentralizedAIService) {
|
|
177
|
-
super(apiKey, projectRoot);
|
|
178
|
-
this.aiService = aiService || new DefaultAIService();
|
|
179
|
-
this.loadLearningData();
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* AI-enhanced installation with intelligent analysis
|
|
184
|
-
*/
|
|
185
|
-
async install(): Promise<AIInstallationResult> {
|
|
186
|
-
try {
|
|
187
|
-
// Step 1: AI-powered framework detection
|
|
188
|
-
const aiAnalysis = await this.performAICodeAnalysis();
|
|
189
|
-
|
|
190
|
-
// Step 2: Smart framework detection with AI validation
|
|
191
|
-
this.framework = await this.detectFrameworkWithAI(aiAnalysis);
|
|
192
|
-
|
|
193
|
-
// Step 3: Generate AI-optimized modifications
|
|
194
|
-
const modifications = await this.generateAIOptimizedModifications(aiAnalysis);
|
|
195
|
-
|
|
196
|
-
// Step 4: Apply modifications with conflict resolution
|
|
197
|
-
await this.applyModificationsWithAI(modifications, aiAnalysis);
|
|
198
|
-
|
|
199
|
-
// Step 5: Generate intelligent next steps
|
|
200
|
-
const nextSteps = this.generateAINextSteps(aiAnalysis);
|
|
201
|
-
|
|
202
|
-
// Step 6: Learn from this installation
|
|
203
|
-
await this.learnFromInstallation(aiAnalysis, modifications);
|
|
204
|
-
|
|
205
|
-
return {
|
|
206
|
-
success: true,
|
|
207
|
-
framework: this.framework,
|
|
208
|
-
modifications,
|
|
209
|
-
errors: [],
|
|
210
|
-
nextSteps,
|
|
211
|
-
aiAnalysis,
|
|
212
|
-
learningData: {
|
|
213
|
-
patterns: aiAnalysis.patterns,
|
|
214
|
-
framework: this.framework.name,
|
|
215
|
-
success: true
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
} catch (error) {
|
|
219
|
-
return {
|
|
220
|
-
success: false,
|
|
221
|
-
framework: this.framework || { name: 'unknown', type: 'vanilla' },
|
|
222
|
-
modifications: [],
|
|
223
|
-
errors: [error instanceof Error ? error.message : 'Unknown error'],
|
|
224
|
-
nextSteps: [],
|
|
225
|
-
aiAnalysis: {
|
|
226
|
-
framework: { name: 'unknown', type: 'vanilla' },
|
|
227
|
-
confidence: 0,
|
|
228
|
-
patterns: [],
|
|
229
|
-
conflicts: [],
|
|
230
|
-
recommendations: [],
|
|
231
|
-
integrationStrategy: 'script',
|
|
232
|
-
compatibilityMode: 'legacy'
|
|
233
|
-
},
|
|
234
|
-
learningData: {
|
|
235
|
-
patterns: [],
|
|
236
|
-
framework: 'unknown',
|
|
237
|
-
success: false
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* AI-powered code analysis using centralized service
|
|
245
|
-
*/
|
|
246
|
-
public async performAICodeAnalysis(): Promise<AICodeAnalysis> {
|
|
247
|
-
const projectFiles = await this.scanProjectFiles();
|
|
248
|
-
const codeSamples = await this.extractCodeSamples(projectFiles);
|
|
249
|
-
|
|
250
|
-
// Use centralized AI service (no user API key required)
|
|
251
|
-
return await this.aiService.analyzeCodePatterns(codeSamples);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Scan project files for analysis
|
|
256
|
-
*/
|
|
257
|
-
private async scanProjectFiles(): Promise<string[]> {
|
|
258
|
-
const files: string[] = [];
|
|
259
|
-
const scanDir = (dir: string, depth: number = 0) => {
|
|
260
|
-
if (depth > 3) return; // Limit depth
|
|
261
|
-
|
|
262
|
-
try {
|
|
263
|
-
const items = fs.readdirSync(dir);
|
|
264
|
-
for (const item of items) {
|
|
265
|
-
const fullPath = path.join(dir, item);
|
|
266
|
-
const stat = fs.statSync(fullPath);
|
|
267
|
-
|
|
268
|
-
if (stat.isDirectory() && !item.startsWith('.') && item !== 'node_modules') {
|
|
269
|
-
scanDir(fullPath, depth + 1);
|
|
270
|
-
} else if (stat.isFile() && this.isRelevantFile(item)) {
|
|
271
|
-
files.push(fullPath);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
} catch (error) {
|
|
275
|
-
// Skip inaccessible directories
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
scanDir(this.projectRoot);
|
|
280
|
-
return files;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Check if file is relevant for analysis
|
|
285
|
-
*/
|
|
286
|
-
private isRelevantFile(filename: string): boolean {
|
|
287
|
-
const relevantExtensions = [
|
|
288
|
-
'.js', '.jsx', '.ts', '.tsx', '.vue', '.svelte', '.html',
|
|
289
|
-
'.json', '.config.js', '.config.ts', '.babelrc', '.eslintrc'
|
|
290
|
-
];
|
|
291
|
-
|
|
292
|
-
const relevantNames = [
|
|
293
|
-
'package.json', 'tsconfig.json', 'vite.config', 'webpack.config',
|
|
294
|
-
'next.config', 'nuxt.config', 'angular.json', 'svelte.config',
|
|
295
|
-
'app/layout', 'app/page', 'pages/index', 'pages/_app', 'pages/_document'
|
|
296
|
-
];
|
|
297
|
-
|
|
298
|
-
return relevantExtensions.some(ext => filename.endsWith(ext)) ||
|
|
299
|
-
relevantNames.some(name => filename.includes(name));
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Extract code samples for AI analysis
|
|
304
|
-
*/
|
|
305
|
-
private async extractCodeSamples(files: string[]): Promise<string[]> {
|
|
306
|
-
const samples: string[] = [];
|
|
307
|
-
|
|
308
|
-
for (const file of files.slice(0, 20)) { // Limit to 20 files
|
|
309
|
-
try {
|
|
310
|
-
const content = fs.readFileSync(file, 'utf8');
|
|
311
|
-
const relativePath = path.relative(this.projectRoot, file);
|
|
312
|
-
|
|
313
|
-
// Extract relevant code patterns
|
|
314
|
-
const patterns = this.extractCodePatterns(content);
|
|
315
|
-
if (patterns.length > 0) {
|
|
316
|
-
samples.push(`File: ${relativePath}\n${patterns.join('\n')}`);
|
|
317
|
-
}
|
|
318
|
-
} catch (error) {
|
|
319
|
-
// Skip unreadable files
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
return samples;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Extract relevant code patterns
|
|
328
|
-
*/
|
|
329
|
-
private extractCodePatterns(content: string): string[] {
|
|
330
|
-
const patterns: string[] = [];
|
|
331
|
-
|
|
332
|
-
// Framework-specific patterns
|
|
333
|
-
const frameworkPatterns = {
|
|
334
|
-
react: [
|
|
335
|
-
/import\s+React\s+from\s+['"]react['"]/gi,
|
|
336
|
-
/from\s+['"]react['"]/gi,
|
|
337
|
-
/function\s+\w+\s*\(\s*\)\s*{/gi,
|
|
338
|
-
/const\s+\w+\s*=\s*\(\s*\)\s*=>\s*{/gi
|
|
339
|
-
],
|
|
340
|
-
vue: [
|
|
341
|
-
/import\s+{\s*createApp\s*}\s+from\s+['"]vue['"]/gi,
|
|
342
|
-
/from\s+['"]vue['"]/gi,
|
|
343
|
-
/<template>/gi,
|
|
344
|
-
/<script\s+setup>/gi
|
|
345
|
-
],
|
|
346
|
-
angular: [
|
|
347
|
-
/import\s+{\s*Component\s*}\s+from\s+['"]@angular\/core['"]/gi,
|
|
348
|
-
/@Component\s*\(\s*{/gi,
|
|
349
|
-
/from\s+['"]@angular/gi
|
|
350
|
-
],
|
|
351
|
-
svelte: [
|
|
352
|
-
/<script>/gi,
|
|
353
|
-
/import\s+.*\s+from\s+['"]svelte/gi,
|
|
354
|
-
/from\s+['"]svelte/gi
|
|
355
|
-
],
|
|
356
|
-
nextjs: [
|
|
357
|
-
/import\s+.*\s+from\s+['"]next/gi,
|
|
358
|
-
/from\s+['"]next/gi,
|
|
359
|
-
/export\s+default\s+function\s+Page/gi,
|
|
360
|
-
/export\s+default\s+function\s+Layout/gi,
|
|
361
|
-
/export\s+default\s+function\s+Loading/gi,
|
|
362
|
-
/export\s+default\s+function\s+Error/gi,
|
|
363
|
-
/export\s+default\s+function\s+Not-found/gi,
|
|
364
|
-
/useRouter\s+from\s+['"]next\/navigation['"]/gi,
|
|
365
|
-
/useRouter\s+from\s+['"]next\/router['"]/gi,
|
|
366
|
-
/Link\s+from\s+['"]next\/link['"]/gi,
|
|
367
|
-
/Image\s+from\s+['"]next\/image['"]/gi,
|
|
368
|
-
/getServerSideProps/gi,
|
|
369
|
-
/getStaticProps/gi,
|
|
370
|
-
/getStaticPaths/gi,
|
|
371
|
-
/next\.config/gi,
|
|
372
|
-
/app\/layout\.tsx/gi,
|
|
373
|
-
/app\/page\.tsx/gi,
|
|
374
|
-
/pages\/.*\.tsx/gi,
|
|
375
|
-
/pages\/.*\.jsx/gi,
|
|
376
|
-
/pages\/.*\.ts/gi,
|
|
377
|
-
/pages\/.*\.js/gi
|
|
378
|
-
],
|
|
379
|
-
nuxt: [
|
|
380
|
-
/import\s+.*\s+from\s+['"]nuxt/gi,
|
|
381
|
-
/from\s+['"]nuxt/gi,
|
|
382
|
-
/export\s+default\s+defineNuxtConfig/gi,
|
|
383
|
-
/defineNuxtConfig/gi,
|
|
384
|
-
/nuxt\.config\.ts/gi,
|
|
385
|
-
/nuxt\.config\.js/gi,
|
|
386
|
-
/@nuxt\//gi,
|
|
387
|
-
/#app/gi,
|
|
388
|
-
/useNuxtApp/gi,
|
|
389
|
-
/useRuntimeConfig/gi,
|
|
390
|
-
/useSeoMeta/gi,
|
|
391
|
-
/useHead/gi,
|
|
392
|
-
/useLazyFetch/gi,
|
|
393
|
-
/useFetch/gi,
|
|
394
|
-
/useAsyncData/gi,
|
|
395
|
-
/<NuxtLayout/gi,
|
|
396
|
-
/<NuxtPage/gi,
|
|
397
|
-
/NuxtLayout/gi,
|
|
398
|
-
/NuxtPage/gi,
|
|
399
|
-
/pages\/.*\.vue/gi,
|
|
400
|
-
/layouts\/.*\.vue/gi,
|
|
401
|
-
/components\/.*\.vue/gi,
|
|
402
|
-
/composables\/.*\.ts/gi,
|
|
403
|
-
/middleware\/.*\.ts/gi,
|
|
404
|
-
/server\/.*\.ts/gi,
|
|
405
|
-
/plugins\/.*\.ts/gi,
|
|
406
|
-
/public\//gi,
|
|
407
|
-
/assets\//gi,
|
|
408
|
-
/content\//gi
|
|
409
|
-
]
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
// Extract patterns for each framework
|
|
413
|
-
for (const [framework, regexes] of Object.entries(frameworkPatterns)) {
|
|
414
|
-
for (const regex of regexes) {
|
|
415
|
-
const matches = content.match(regex);
|
|
416
|
-
if (matches) {
|
|
417
|
-
// Add raw patterns for heuristic analysis
|
|
418
|
-
patterns.push(...matches.slice(0, 3));
|
|
419
|
-
// Also add formatted patterns for debugging
|
|
420
|
-
patterns.push(`${framework.toUpperCase()}: ${matches.slice(0, 3).join(', ')}`);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// Extract import patterns
|
|
426
|
-
const importMatches = content.match(/import\s+.*\s+from\s+['"][^'"]+['"]/gi);
|
|
427
|
-
if (importMatches) {
|
|
428
|
-
patterns.push(`IMPORTS: ${importMatches.slice(0, 5).join(', ')}`);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
// Extract export patterns
|
|
432
|
-
const exportMatches = content.match(/export\s+.*/gi);
|
|
433
|
-
if (exportMatches) {
|
|
434
|
-
patterns.push(`EXPORTS: ${exportMatches.slice(0, 3).join(', ')}`);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
return patterns;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* AI-enhanced framework detection
|
|
442
|
-
*/
|
|
443
|
-
private async detectFrameworkWithAI(aiAnalysis: AICodeAnalysis): Promise<FrameworkInfo> {
|
|
444
|
-
// Combine AI analysis with traditional detection
|
|
445
|
-
const traditionalFramework = await super.detectFramework();
|
|
446
|
-
|
|
447
|
-
// Use AI analysis if confidence is high, but preserve bundler info
|
|
448
|
-
if (aiAnalysis.confidence > 0.8) {
|
|
449
|
-
return {
|
|
450
|
-
...aiAnalysis.framework,
|
|
451
|
-
bundler: traditionalFramework.bundler, // Preserve bundler detection
|
|
452
|
-
packageManager: traditionalFramework.packageManager, // Preserve package manager
|
|
453
|
-
hasTypeScript: traditionalFramework.hasTypeScript, // Preserve TypeScript detection
|
|
454
|
-
hasRouter: traditionalFramework.hasRouter, // Preserve router detection
|
|
455
|
-
projectRoot: this.projectRoot
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
// Merge AI insights with traditional detection
|
|
460
|
-
return {
|
|
461
|
-
...traditionalFramework,
|
|
462
|
-
// Override with AI insights if available
|
|
463
|
-
...(aiAnalysis.framework.type !== 'vanilla' && {
|
|
464
|
-
type: aiAnalysis.framework.type,
|
|
465
|
-
name: aiAnalysis.framework.name
|
|
466
|
-
})
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* Generate AI-optimized modifications
|
|
472
|
-
*/
|
|
473
|
-
private async generateAIOptimizedModifications(aiAnalysis: AICodeAnalysis): Promise<CodeModification[]> {
|
|
474
|
-
const baseModifications = await super.generateModifications();
|
|
475
|
-
|
|
476
|
-
// Enhance with AI recommendations
|
|
477
|
-
const enhancedModifications = baseModifications.map(mod => {
|
|
478
|
-
return this.enhanceModificationWithAI(mod, aiAnalysis);
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
// Add AI-specific optimizations
|
|
482
|
-
const aiOptimizations = this.generateAIOptimizations(aiAnalysis);
|
|
483
|
-
enhancedModifications.push(...aiOptimizations);
|
|
484
|
-
|
|
485
|
-
return enhancedModifications;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* Enhance modification with AI insights
|
|
490
|
-
*/
|
|
491
|
-
private enhanceModificationWithAI(mod: CodeModification, aiAnalysis: AICodeAnalysis): CodeModification {
|
|
492
|
-
let enhancedContent = mod.content;
|
|
493
|
-
|
|
494
|
-
// Add compatibility comments
|
|
495
|
-
if (aiAnalysis.compatibilityMode === 'legacy') {
|
|
496
|
-
enhancedContent = `// HumanBehavior SDK - Legacy Compatibility Mode\n${enhancedContent}`;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
// Add future-proofing comments
|
|
500
|
-
if (aiAnalysis.integrationStrategy === 'provider') {
|
|
501
|
-
enhancedContent = `// HumanBehavior SDK - Provider Pattern (Future-proof)\n${enhancedContent}`;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
// Add conflict resolution
|
|
505
|
-
if (aiAnalysis.conflicts.length > 0) {
|
|
506
|
-
enhancedContent = `// Conflict Resolution: ${aiAnalysis.conflicts.join(', ')}\n${enhancedContent}`;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
return {
|
|
510
|
-
...mod,
|
|
511
|
-
content: enhancedContent,
|
|
512
|
-
description: `${mod.description} (AI-optimized)`
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
/**
|
|
517
|
-
* Generate AI-specific optimizations
|
|
518
|
-
*/
|
|
519
|
-
private generateAIOptimizations(aiAnalysis: AICodeAnalysis): CodeModification[] {
|
|
520
|
-
const optimizations: CodeModification[] = [];
|
|
521
|
-
|
|
522
|
-
// AI optimizations are now handled through environment variables and code injection
|
|
523
|
-
// No separate config file needed - everything is integrated into the existing codebase
|
|
524
|
-
|
|
525
|
-
return optimizations;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
/**
|
|
529
|
-
* Apply modifications with AI conflict resolution
|
|
530
|
-
*/
|
|
531
|
-
private async applyModificationsWithAI(modifications: CodeModification[], aiAnalysis: AICodeAnalysis): Promise<void> {
|
|
532
|
-
for (const modification of modifications) {
|
|
533
|
-
try {
|
|
534
|
-
// Check for conflicts
|
|
535
|
-
const conflicts = await this.detectConflicts(modification);
|
|
536
|
-
|
|
537
|
-
if (conflicts.length > 0) {
|
|
538
|
-
// Resolve conflicts using centralized AI service
|
|
539
|
-
const resolutions = await this.aiService.resolveConflicts(conflicts, aiAnalysis.framework);
|
|
540
|
-
const resolvedModification = await this.resolveConflicts(modification, conflicts, resolutions, aiAnalysis);
|
|
541
|
-
await this.applyModification(resolvedModification);
|
|
542
|
-
} else {
|
|
543
|
-
await this.applyModification(modification);
|
|
544
|
-
}
|
|
545
|
-
} catch (error) {
|
|
546
|
-
throw new Error(`Failed to apply AI-optimized modification to ${modification.filePath}: ${error}`);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
/**
|
|
552
|
-
* Detect potential conflicts
|
|
553
|
-
*/
|
|
554
|
-
private async detectConflicts(modification: CodeModification): Promise<string[]> {
|
|
555
|
-
const conflicts: string[] = [];
|
|
556
|
-
|
|
557
|
-
if (fs.existsSync(modification.filePath)) {
|
|
558
|
-
const existingContent = fs.readFileSync(modification.filePath, 'utf8');
|
|
559
|
-
|
|
560
|
-
// Check for existing HumanBehavior code
|
|
561
|
-
if (existingContent.includes('HumanBehavior') || existingContent.includes('humanbehavior')) {
|
|
562
|
-
conflicts.push('existing_humanbehavior_code');
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
// Check for conflicting providers/plugins
|
|
566
|
-
if (modification.content.includes('Provider') && existingContent.includes('Provider')) {
|
|
567
|
-
conflicts.push('existing_provider');
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// Check for TypeScript conflicts
|
|
571
|
-
if (modification.content.includes('import') && existingContent.includes('require(')) {
|
|
572
|
-
conflicts.push('module_system_conflict');
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
return conflicts;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
/**
|
|
580
|
-
* Resolve conflicts with AI
|
|
581
|
-
*/
|
|
582
|
-
private async resolveConflicts(modification: CodeModification, conflicts: string[], resolutions: string[], aiAnalysis: AICodeAnalysis): Promise<CodeModification> {
|
|
583
|
-
let resolvedContent = modification.content;
|
|
584
|
-
|
|
585
|
-
for (let i = 0; i < conflicts.length; i++) {
|
|
586
|
-
const conflict = conflicts[i];
|
|
587
|
-
const resolution = resolutions[i];
|
|
588
|
-
|
|
589
|
-
switch (resolution) {
|
|
590
|
-
case 'update_existing_integration':
|
|
591
|
-
resolvedContent = `// Updated HumanBehavior Integration\n${resolvedContent}`;
|
|
592
|
-
break;
|
|
593
|
-
case 'merge_providers':
|
|
594
|
-
resolvedContent = resolvedContent.replace(/<HumanBehaviorProvider/g, '<HumanBehaviorProvider key="updated"');
|
|
595
|
-
break;
|
|
596
|
-
case 'hybrid_module_support':
|
|
597
|
-
resolvedContent = `// Hybrid module system support\n${resolvedContent}`;
|
|
598
|
-
break;
|
|
599
|
-
case 'skip_conflict':
|
|
600
|
-
// Skip this modification
|
|
601
|
-
return { ...modification, content: '', description: `${modification.description} (skipped due to conflict)` };
|
|
602
|
-
default:
|
|
603
|
-
// Default resolution
|
|
604
|
-
resolvedContent = `// Conflict resolved: ${conflict}\n${resolvedContent}`;
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
return {
|
|
609
|
-
...modification,
|
|
610
|
-
content: resolvedContent,
|
|
611
|
-
description: `${modification.description} (conflict-resolved)`
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
* Apply single modification
|
|
617
|
-
*/
|
|
618
|
-
private async applyModification(modification: CodeModification): Promise<void> {
|
|
619
|
-
if (!modification.content) return; // Skip empty modifications
|
|
620
|
-
|
|
621
|
-
const dir = path.dirname(modification.filePath);
|
|
622
|
-
if (!fs.existsSync(dir)) {
|
|
623
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
switch (modification.action) {
|
|
627
|
-
case 'create':
|
|
628
|
-
fs.writeFileSync(modification.filePath, modification.content);
|
|
629
|
-
break;
|
|
630
|
-
case 'modify':
|
|
631
|
-
fs.writeFileSync(modification.filePath, modification.content);
|
|
632
|
-
break;
|
|
633
|
-
case 'append':
|
|
634
|
-
fs.appendFileSync(modification.filePath, '\n' + modification.content);
|
|
635
|
-
break;
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
/**
|
|
640
|
-
* Generate AI-enhanced next steps
|
|
641
|
-
*/
|
|
642
|
-
private generateAINextSteps(aiAnalysis: AICodeAnalysis): string[] {
|
|
643
|
-
const steps = [
|
|
644
|
-
'✅ AI-optimized SDK installation completed!',
|
|
645
|
-
`🎯 Framework detected: ${aiAnalysis.framework.name} (confidence: ${Math.round(aiAnalysis.confidence * 100)}%)`,
|
|
646
|
-
`🔧 Integration strategy: ${aiAnalysis.integrationStrategy}`,
|
|
647
|
-
`🔄 Compatibility mode: ${aiAnalysis.compatibilityMode}`,
|
|
648
|
-
'🚀 Your app is now tracking user behavior with AI-optimized configuration'
|
|
649
|
-
];
|
|
650
|
-
|
|
651
|
-
if (aiAnalysis.recommendations.length > 0) {
|
|
652
|
-
steps.push('💡 AI Recommendations:');
|
|
653
|
-
aiAnalysis.recommendations.forEach(rec => steps.push(` • ${rec}`));
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
return steps;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
/**
|
|
660
|
-
* Learn from installation for future improvements
|
|
661
|
-
*/
|
|
662
|
-
private async learnFromInstallation(aiAnalysis: AICodeAnalysis, modifications: CodeModification[]): Promise<void> {
|
|
663
|
-
const learningData = {
|
|
664
|
-
timestamp: new Date().toISOString(),
|
|
665
|
-
framework: aiAnalysis.framework.name,
|
|
666
|
-
patterns: aiAnalysis.patterns,
|
|
667
|
-
integrationStrategy: aiAnalysis.integrationStrategy,
|
|
668
|
-
compatibilityMode: aiAnalysis.compatibilityMode,
|
|
669
|
-
modifications: modifications.length,
|
|
670
|
-
success: true
|
|
671
|
-
};
|
|
672
|
-
|
|
673
|
-
// Store learning data
|
|
674
|
-
this.learningCache.set(`${aiAnalysis.framework.name}_${Date.now()}`, learningData);
|
|
675
|
-
|
|
676
|
-
// Update pattern database
|
|
677
|
-
if (!this.patternDatabase.has(aiAnalysis.framework.name)) {
|
|
678
|
-
this.patternDatabase.set(aiAnalysis.framework.name, []);
|
|
679
|
-
}
|
|
680
|
-
this.patternDatabase.get(aiAnalysis.framework.name)!.push(learningData);
|
|
681
|
-
|
|
682
|
-
// Save to disk
|
|
683
|
-
await this.saveLearningData();
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
/**
|
|
687
|
-
* Load learning data from disk
|
|
688
|
-
*/
|
|
689
|
-
private loadLearningData(): void {
|
|
690
|
-
// Don't load learning data from user's project - keep it in memory only
|
|
691
|
-
// This prevents cluttering the user's project with internal files
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
/**
|
|
695
|
-
* Save learning data to disk
|
|
696
|
-
*/
|
|
697
|
-
private async saveLearningData(): Promise<void> {
|
|
698
|
-
// Don't save learning data to user's project - keep it in memory only
|
|
699
|
-
// This prevents cluttering the user's project with internal files
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
/**
|
|
703
|
-
* Get AI insights for a specific framework
|
|
704
|
-
*/
|
|
705
|
-
public getAIInsights(frameworkName: string): any[] {
|
|
706
|
-
return this.patternDatabase.get(frameworkName) || [];
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
/**
|
|
710
|
-
* Get learning statistics
|
|
711
|
-
*/
|
|
712
|
-
public getLearningStats(): any {
|
|
713
|
-
const stats = {
|
|
714
|
-
totalInstallations: this.learningCache.size,
|
|
715
|
-
frameworks: {} as any,
|
|
716
|
-
patterns: {} as any
|
|
717
|
-
};
|
|
718
|
-
|
|
719
|
-
for (const [framework, data] of this.patternDatabase.entries()) {
|
|
720
|
-
stats.frameworks[framework] = data.length;
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
return stats;
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
/**
|
|
728
|
-
* Browser-based AI installation wizard
|
|
729
|
-
*/
|
|
730
|
-
export class AIBrowserInstallationWizard {
|
|
731
|
-
private apiKey: string;
|
|
732
|
-
private aiService: CentralizedAIService;
|
|
733
|
-
|
|
734
|
-
constructor(apiKey: string, aiService?: CentralizedAIService) {
|
|
735
|
-
this.apiKey = apiKey;
|
|
736
|
-
this.aiService = aiService || new DefaultAIService();
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
async install(): Promise<AIInstallationResult> {
|
|
740
|
-
try {
|
|
741
|
-
// AI-powered browser detection
|
|
742
|
-
const aiAnalysis = await this.performBrowserAIAnalysis();
|
|
743
|
-
|
|
744
|
-
// Generate AI-optimized browser modifications
|
|
745
|
-
const modifications = this.generateAIBrowserModifications(aiAnalysis);
|
|
746
|
-
|
|
747
|
-
return {
|
|
748
|
-
success: true,
|
|
749
|
-
framework: aiAnalysis.framework,
|
|
750
|
-
modifications,
|
|
751
|
-
errors: [],
|
|
752
|
-
nextSteps: [
|
|
753
|
-
'✅ AI-optimized browser integration ready!',
|
|
754
|
-
`🎯 Framework detected: ${aiAnalysis.framework.name}`,
|
|
755
|
-
`🔧 Integration strategy: ${aiAnalysis.integrationStrategy}`,
|
|
756
|
-
'📋 Copy the generated code to your project',
|
|
757
|
-
'🚀 Your app will be ready to track user behavior'
|
|
758
|
-
],
|
|
759
|
-
aiAnalysis,
|
|
760
|
-
learningData: {
|
|
761
|
-
patterns: aiAnalysis.patterns,
|
|
762
|
-
framework: aiAnalysis.framework.name,
|
|
763
|
-
success: true
|
|
764
|
-
}
|
|
765
|
-
};
|
|
766
|
-
} catch (error) {
|
|
767
|
-
return {
|
|
768
|
-
success: false,
|
|
769
|
-
framework: { name: 'unknown', type: 'vanilla' },
|
|
770
|
-
modifications: [],
|
|
771
|
-
errors: [error instanceof Error ? error.message : 'Unknown error'],
|
|
772
|
-
nextSteps: [],
|
|
773
|
-
aiAnalysis: {
|
|
774
|
-
framework: { name: 'unknown', type: 'vanilla' },
|
|
775
|
-
confidence: 0,
|
|
776
|
-
patterns: [],
|
|
777
|
-
conflicts: [],
|
|
778
|
-
recommendations: [],
|
|
779
|
-
integrationStrategy: 'script',
|
|
780
|
-
compatibilityMode: 'legacy'
|
|
781
|
-
},
|
|
782
|
-
learningData: {
|
|
783
|
-
patterns: [],
|
|
784
|
-
framework: 'unknown',
|
|
785
|
-
success: false
|
|
786
|
-
}
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
private async performBrowserAIAnalysis(): Promise<AICodeAnalysis> {
|
|
792
|
-
// Browser-based framework detection
|
|
793
|
-
const framework = this.detectBrowserFramework();
|
|
794
|
-
|
|
795
|
-
// Analyze browser environment
|
|
796
|
-
const patterns = this.analyzeBrowserPatterns();
|
|
797
|
-
|
|
798
|
-
// Use centralized AI service for analysis
|
|
799
|
-
const codeSamples = [`Browser Environment: ${patterns.join(', ')}`];
|
|
800
|
-
return await this.aiService.analyzeCodePatterns(codeSamples);
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
private detectBrowserFramework(): FrameworkInfo {
|
|
804
|
-
if (typeof window !== 'undefined') {
|
|
805
|
-
if ((window as any).React) {
|
|
806
|
-
return { name: 'react', type: 'react' };
|
|
807
|
-
}
|
|
808
|
-
if ((window as any).Vue) {
|
|
809
|
-
return { name: 'vue', type: 'vue' };
|
|
810
|
-
}
|
|
811
|
-
if ((window as any).angular) {
|
|
812
|
-
return { name: 'angular', type: 'angular' };
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
return { name: 'vanilla', type: 'vanilla' };
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
private analyzeBrowserPatterns(): string[] {
|
|
820
|
-
const patterns: string[] = [];
|
|
821
|
-
|
|
822
|
-
if (typeof window !== 'undefined') {
|
|
823
|
-
// Analyze global objects
|
|
824
|
-
if ((window as any).React) patterns.push('React global detected');
|
|
825
|
-
if ((window as any).Vue) patterns.push('Vue global detected');
|
|
826
|
-
if ((window as any).angular) patterns.push('Angular global detected');
|
|
827
|
-
|
|
828
|
-
// Analyze DOM patterns
|
|
829
|
-
if (document.querySelector('[data-reactroot]')) patterns.push('React DOM detected');
|
|
830
|
-
if (document.querySelector('[data-vue]')) patterns.push('Vue DOM detected');
|
|
831
|
-
|
|
832
|
-
// Analyze script patterns
|
|
833
|
-
const scripts = document.querySelectorAll('script');
|
|
834
|
-
scripts.forEach(script => {
|
|
835
|
-
if (script.src.includes('react')) patterns.push('React script detected');
|
|
836
|
-
if (script.src.includes('vue')) patterns.push('Vue script detected');
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
return patterns;
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
private generateAIBrowserModifications(aiAnalysis: AICodeAnalysis): CodeModification[] {
|
|
844
|
-
const modifications: CodeModification[] = [];
|
|
845
|
-
|
|
846
|
-
switch (aiAnalysis.framework.type) {
|
|
847
|
-
case 'react':
|
|
848
|
-
modifications.push({
|
|
849
|
-
filePath: 'App.jsx',
|
|
850
|
-
action: 'create',
|
|
851
|
-
content: `// AI-Optimized React Integration
|
|
852
|
-
import { HumanBehaviorProvider } from 'humanbehavior-js/react';
|
|
853
|
-
|
|
854
|
-
function App() {
|
|
855
|
-
return (
|
|
856
|
-
<HumanBehaviorProvider
|
|
857
|
-
apiKey="${this.apiKey}"
|
|
858
|
-
config={{
|
|
859
|
-
// AI-generated optimizations
|
|
860
|
-
enablePerformanceTracking: true,
|
|
861
|
-
enableErrorTracking: true,
|
|
862
|
-
framework: '${aiAnalysis.framework.name}',
|
|
863
|
-
integrationStrategy: '${aiAnalysis.integrationStrategy}'
|
|
864
|
-
}}
|
|
865
|
-
>
|
|
866
|
-
{/* Your app components */}
|
|
867
|
-
</HumanBehaviorProvider>
|
|
868
|
-
);
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
export default App;`,
|
|
872
|
-
description: 'AI-optimized React component with HumanBehaviorProvider'
|
|
873
|
-
});
|
|
874
|
-
break;
|
|
875
|
-
|
|
876
|
-
default:
|
|
877
|
-
modifications.push({
|
|
878
|
-
filePath: 'humanbehavior-init.js',
|
|
879
|
-
action: 'create',
|
|
880
|
-
content: `// AI-Optimized Vanilla JS Integration
|
|
881
|
-
import { HumanBehaviorTracker } from 'humanbehavior-js';
|
|
882
|
-
|
|
883
|
-
const tracker = HumanBehaviorTracker.init('${this.apiKey}', {
|
|
884
|
-
// AI-generated configuration
|
|
885
|
-
framework: '${aiAnalysis.framework.name}',
|
|
886
|
-
integrationStrategy: '${aiAnalysis.integrationStrategy}',
|
|
887
|
-
compatibilityMode: '${aiAnalysis.compatibilityMode}',
|
|
888
|
-
enablePerformanceTracking: true,
|
|
889
|
-
enableErrorTracking: true
|
|
890
|
-
});`,
|
|
891
|
-
description: 'AI-optimized vanilla JS initialization'
|
|
892
|
-
});
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
return modifications;
|
|
896
|
-
}
|
|
897
|
-
}
|