humanbehavior-js 0.4.28 → 0.5.1
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 +116 -78
- 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,238 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manual Framework Installation Wizard
|
|
3
|
-
*
|
|
4
|
-
* This wizard allows users to manually specify their framework instead of auto-detection.
|
|
5
|
-
* Useful when auto-detection fails or users want more control.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import * as fs from 'fs';
|
|
9
|
-
import * as path from 'path';
|
|
10
|
-
import { AutoInstallationWizard, FrameworkInfo, CodeModification, InstallationResult } from '../core/install-wizard';
|
|
11
|
-
import { RemoteAIService } from '../services/remote-ai-service';
|
|
12
|
-
|
|
13
|
-
export interface ManualInstallationResult extends InstallationResult {
|
|
14
|
-
selectedFramework: string;
|
|
15
|
-
manualMode: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class ManualFrameworkInstallationWizard extends AutoInstallationWizard {
|
|
19
|
-
private selectedFramework: string;
|
|
20
|
-
|
|
21
|
-
constructor(apiKey: string, projectRoot: string = process.cwd(), framework: string) {
|
|
22
|
-
super(apiKey, projectRoot);
|
|
23
|
-
this.selectedFramework = framework.toLowerCase();
|
|
24
|
-
this.framework = this.createFrameworkInfo(this.selectedFramework);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Manual installation with user-specified framework
|
|
29
|
-
*/
|
|
30
|
-
async install(): Promise<ManualInstallationResult> {
|
|
31
|
-
try {
|
|
32
|
-
// Step 1: Handle framework selection
|
|
33
|
-
if (this.selectedFramework === 'auto') {
|
|
34
|
-
// Use full AI detection for "Other" option
|
|
35
|
-
this.framework = await this.runFullDetection();
|
|
36
|
-
} else {
|
|
37
|
-
// Set framework based on user selection
|
|
38
|
-
this.framework = this.createFrameworkInfo(this.selectedFramework);
|
|
39
|
-
if (!this.framework) {
|
|
40
|
-
this.framework = { name: 'unknown', type: 'vanilla' };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Step 2: Run full detection logic to find entry points, file names, etc.
|
|
44
|
-
const detectedFramework = await this.runFullDetection();
|
|
45
|
-
|
|
46
|
-
// Step 3: Merge manual framework with detected details
|
|
47
|
-
this.framework = {
|
|
48
|
-
...detectedFramework,
|
|
49
|
-
name: this.framework.name,
|
|
50
|
-
type: this.framework.type
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Step 4: Install package
|
|
55
|
-
await this.installPackage();
|
|
56
|
-
|
|
57
|
-
// Step 5: Generate and apply code modifications
|
|
58
|
-
const modifications = await this.generateModifications();
|
|
59
|
-
await this.applyModifications(modifications);
|
|
60
|
-
|
|
61
|
-
// Step 6: Generate next steps
|
|
62
|
-
const nextSteps = this.generateManualNextSteps();
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
success: true,
|
|
66
|
-
framework: this.framework,
|
|
67
|
-
modifications,
|
|
68
|
-
errors: [],
|
|
69
|
-
nextSteps,
|
|
70
|
-
selectedFramework: this.selectedFramework,
|
|
71
|
-
manualMode: true
|
|
72
|
-
};
|
|
73
|
-
} catch (error) {
|
|
74
|
-
return {
|
|
75
|
-
success: false,
|
|
76
|
-
framework: this.framework || { name: 'unknown', type: 'vanilla' },
|
|
77
|
-
modifications: [],
|
|
78
|
-
errors: [error instanceof Error ? error.message : 'Unknown error'],
|
|
79
|
-
nextSteps: [],
|
|
80
|
-
selectedFramework: this.selectedFramework,
|
|
81
|
-
manualMode: true
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Run full detection logic to find entry points, file names, bundler, etc.
|
|
88
|
-
*/
|
|
89
|
-
private async runFullDetection(): Promise<FrameworkInfo> {
|
|
90
|
-
if (this.selectedFramework === 'auto') {
|
|
91
|
-
// Use AI service for auto-detection
|
|
92
|
-
const aiService = new RemoteAIService({
|
|
93
|
-
apiEndpoint: 'https://ik3zxh4790.execute-api.us-east-1.amazonaws.com/prod'
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// Use AI service directly for detection
|
|
97
|
-
const projectFiles = await this.scanProjectFiles();
|
|
98
|
-
const codeSamples = await this.extractCodeSamples(projectFiles);
|
|
99
|
-
const aiAnalysis = await aiService.analyzeCodePatterns(codeSamples);
|
|
100
|
-
return aiAnalysis.framework;
|
|
101
|
-
} else {
|
|
102
|
-
// Use traditional detection for manual frameworks
|
|
103
|
-
const tempWizard = new AutoInstallationWizard(this.apiKey, this.projectRoot);
|
|
104
|
-
const detected = await tempWizard.detectFramework();
|
|
105
|
-
return detected;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Scan project files for analysis
|
|
111
|
-
*/
|
|
112
|
-
private async scanProjectFiles(): Promise<string[]> {
|
|
113
|
-
const files: string[] = [];
|
|
114
|
-
const scanDir = (dir: string, depth: number = 0) => {
|
|
115
|
-
if (depth > 3) return; // Limit depth
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
const items = fs.readdirSync(dir);
|
|
119
|
-
for (const item of items) {
|
|
120
|
-
const fullPath = path.join(dir, item);
|
|
121
|
-
const stat = fs.statSync(fullPath);
|
|
122
|
-
|
|
123
|
-
if (stat.isDirectory() && !item.startsWith('.') && item !== 'node_modules') {
|
|
124
|
-
scanDir(fullPath, depth + 1);
|
|
125
|
-
} else if (stat.isFile() && this.isRelevantFile(item)) {
|
|
126
|
-
files.push(fullPath);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
} catch (error) {
|
|
130
|
-
// Skip inaccessible directories
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
scanDir(this.projectRoot);
|
|
135
|
-
return files;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Check if file is relevant for analysis
|
|
140
|
-
*/
|
|
141
|
-
private isRelevantFile(filename: string): boolean {
|
|
142
|
-
const relevantExtensions = [
|
|
143
|
-
'.js', '.jsx', '.ts', '.tsx', '.vue', '.svelte', '.html',
|
|
144
|
-
'.json', '.config.js', '.config.ts', '.babelrc', '.eslintrc'
|
|
145
|
-
];
|
|
146
|
-
|
|
147
|
-
const relevantNames = [
|
|
148
|
-
'package.json', 'tsconfig.json', 'vite.config', 'webpack.config',
|
|
149
|
-
'next.config', 'nuxt.config', 'angular.json', 'svelte.config'
|
|
150
|
-
];
|
|
151
|
-
|
|
152
|
-
return relevantExtensions.some(ext => filename.endsWith(ext)) ||
|
|
153
|
-
relevantNames.some(name => filename.includes(name));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Extract code samples for AI analysis
|
|
158
|
-
*/
|
|
159
|
-
private async extractCodeSamples(files: string[]): Promise<string[]> {
|
|
160
|
-
const samples: string[] = [];
|
|
161
|
-
|
|
162
|
-
for (const file of files.slice(0, 20)) { // Limit to 20 files
|
|
163
|
-
try {
|
|
164
|
-
const content = fs.readFileSync(file, 'utf8');
|
|
165
|
-
const relativePath = path.relative(this.projectRoot, file);
|
|
166
|
-
samples.push(`File: ${relativePath}\n${content.substring(0, 1000)}`);
|
|
167
|
-
} catch (error) {
|
|
168
|
-
// Skip unreadable files
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return samples;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Create framework info based on user selection
|
|
177
|
-
*/
|
|
178
|
-
private createFrameworkInfo(framework: string): FrameworkInfo {
|
|
179
|
-
const frameworkMap: Record<string, FrameworkInfo> = {
|
|
180
|
-
'react': { name: 'react', type: 'react' },
|
|
181
|
-
'nextjs': { name: 'nextjs', type: 'nextjs' },
|
|
182
|
-
'next': { name: 'nextjs', type: 'nextjs' },
|
|
183
|
-
'vue': { name: 'vue', type: 'vue' },
|
|
184
|
-
'nuxt': { name: 'nuxt', type: 'nuxt' },
|
|
185
|
-
'nuxtjs': { name: 'nuxt', type: 'nuxt' },
|
|
186
|
-
'angular': { name: 'angular', type: 'angular' },
|
|
187
|
-
'svelte': { name: 'svelte', type: 'svelte' },
|
|
188
|
-
'sveltekit': { name: 'svelte', type: 'svelte' },
|
|
189
|
-
'remix': { name: 'remix', type: 'remix' },
|
|
190
|
-
'astro': { name: 'astro', type: 'astro' },
|
|
191
|
-
'gatsby': { name: 'gatsby', type: 'gatsby' },
|
|
192
|
-
'vanilla': { name: 'vanilla', type: 'vanilla' },
|
|
193
|
-
'node': { name: 'node', type: 'node' },
|
|
194
|
-
'auto': { name: 'auto-detected', type: 'auto' }
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
return frameworkMap[framework] || { name: framework, type: 'vanilla' };
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Override framework detection to use manual selection
|
|
202
|
-
*/
|
|
203
|
-
public async detectFramework(): Promise<FrameworkInfo> {
|
|
204
|
-
return this.framework || { name: 'unknown', type: 'vanilla' };
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Generate next steps with manual mode info
|
|
209
|
-
*/
|
|
210
|
-
private generateManualNextSteps(): string[] {
|
|
211
|
-
return [
|
|
212
|
-
'✅ Manual framework installation completed!',
|
|
213
|
-
`🎯 Selected framework: ${this.framework?.name || 'unknown'}`,
|
|
214
|
-
`🔧 Integration strategy: ${this.getIntegrationStrategy()}`,
|
|
215
|
-
'🚀 Your app is now ready to track user behavior',
|
|
216
|
-
'📊 View sessions in your HumanBehavior dashboard'
|
|
217
|
-
];
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Get integration strategy based on framework
|
|
222
|
-
*/
|
|
223
|
-
private getIntegrationStrategy(): string {
|
|
224
|
-
if (!this.framework?.type) return 'script';
|
|
225
|
-
|
|
226
|
-
switch (this.framework.type) {
|
|
227
|
-
case 'react':
|
|
228
|
-
case 'nextjs':
|
|
229
|
-
return 'provider';
|
|
230
|
-
case 'vue':
|
|
231
|
-
return 'plugin';
|
|
232
|
-
case 'angular':
|
|
233
|
-
return 'module';
|
|
234
|
-
default:
|
|
235
|
-
return 'script';
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* AI-Enhanced HumanBehavior SDK Auto-Installation CLI
|
|
5
|
-
*
|
|
6
|
-
* Usage: npx humanbehavior-js ai-auto-install [api-key]
|
|
7
|
-
*
|
|
8
|
-
* This tool uses AI to intelligently detect frameworks, analyze code patterns,
|
|
9
|
-
* and generate optimal integration code that's both future-proof and backward-compatible.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { AIEnhancedInstallationWizard, AIBrowserInstallationWizard } from '../ai/ai-install-wizard';
|
|
13
|
-
import { ManualFrameworkInstallationWizard } from '../ai/manual-framework-wizard';
|
|
14
|
-
import { AutoInstallationWizard } from '../core/install-wizard';
|
|
15
|
-
import { RemoteAIService } from '../services/remote-ai-service';
|
|
16
|
-
import * as clack from '@clack/prompts';
|
|
17
|
-
import * as fs from 'fs';
|
|
18
|
-
import * as path from 'path';
|
|
19
|
-
|
|
20
|
-
interface AICLIOptions {
|
|
21
|
-
apiKey?: string;
|
|
22
|
-
projectPath?: string;
|
|
23
|
-
yes?: boolean;
|
|
24
|
-
dryRun?: boolean;
|
|
25
|
-
framework?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
class AIAutoInstallCLI {
|
|
29
|
-
private options: AICLIOptions;
|
|
30
|
-
|
|
31
|
-
constructor(options: AICLIOptions) {
|
|
32
|
-
this.options = options;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async run() {
|
|
36
|
-
clack.intro('🤖 AI-Enhanced HumanBehavior SDK Auto-Installation');
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
// Get API key
|
|
40
|
-
const apiKey = await this.getApiKey();
|
|
41
|
-
if (!apiKey) {
|
|
42
|
-
clack.cancel('API key is required');
|
|
43
|
-
process.exit(1);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Get project path
|
|
47
|
-
const projectPath = this.options.projectPath || process.cwd();
|
|
48
|
-
|
|
49
|
-
// Choose framework
|
|
50
|
-
const framework = await this.chooseFramework();
|
|
51
|
-
if (!framework) {
|
|
52
|
-
clack.cancel('Installation cancelled.');
|
|
53
|
-
process.exit(0);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Confirm installation
|
|
57
|
-
if (!this.options.yes) {
|
|
58
|
-
const confirmed = await this.confirmInstallation(projectPath, framework);
|
|
59
|
-
if (!confirmed) {
|
|
60
|
-
clack.cancel('Installation cancelled.');
|
|
61
|
-
process.exit(0);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Run installation
|
|
66
|
-
const spinner = clack.spinner();
|
|
67
|
-
spinner.start('🔍 Analyzing your project with AI...');
|
|
68
|
-
|
|
69
|
-
const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
|
|
70
|
-
const result = await wizard.install();
|
|
71
|
-
|
|
72
|
-
spinner.stop('Analysis complete!');
|
|
73
|
-
|
|
74
|
-
// Display results
|
|
75
|
-
this.displayResults(result, framework);
|
|
76
|
-
|
|
77
|
-
} catch (error) {
|
|
78
|
-
clack.cancel(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private async getApiKey(): Promise<string> {
|
|
84
|
-
if (this.options.apiKey) {
|
|
85
|
-
return this.options.apiKey;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const apiKey = await clack.text({
|
|
89
|
-
message: 'Enter your HumanBehavior API key:',
|
|
90
|
-
placeholder: 'hb_...',
|
|
91
|
-
validate: (value) => {
|
|
92
|
-
if (!value) return 'API key is required';
|
|
93
|
-
if (!value.startsWith('hb_')) return 'API key should start with "hb_"';
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
return apiKey;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
private async confirmInstallation(projectPath: string, framework: string): Promise<boolean> {
|
|
106
|
-
const confirmed = await clack.confirm({
|
|
107
|
-
message: `Ready to install HumanBehavior SDK in ${projectPath} for ${framework}?`
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
return confirmed;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private async chooseFramework(): Promise<string> {
|
|
114
|
-
const framework = await clack.select({
|
|
115
|
-
message: 'Select your framework:',
|
|
116
|
-
options: [
|
|
117
|
-
{ label: 'React', value: 'react' },
|
|
118
|
-
{ label: 'Next.js', value: 'nextjs' },
|
|
119
|
-
{ label: 'Vue', value: 'vue' },
|
|
120
|
-
{ label: 'Angular', value: 'angular' },
|
|
121
|
-
{ label: 'Svelte', value: 'svelte' },
|
|
122
|
-
{ label: 'Nuxt.js', value: 'nuxt' },
|
|
123
|
-
{ label: 'Remix', value: 'remix' },
|
|
124
|
-
{ label: 'Astro', value: 'astro' },
|
|
125
|
-
{ label: 'Gatsby', value: 'gatsby' },
|
|
126
|
-
{ label: 'Vanilla JS/TS', value: 'vanilla' }
|
|
127
|
-
]
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
return framework;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private displayResults(result: any, framework: string) {
|
|
134
|
-
if (result.success) {
|
|
135
|
-
clack.outro('🎉 Installation completed successfully!');
|
|
136
|
-
|
|
137
|
-
// Display framework info
|
|
138
|
-
clack.note(`Framework detected: ${result.framework.name} (${result.framework.type})`, 'Framework Info');
|
|
139
|
-
|
|
140
|
-
// Display modifications
|
|
141
|
-
if (result.modifications && result.modifications.length > 0) {
|
|
142
|
-
const modifications = result.modifications.map((mod: any) =>
|
|
143
|
-
`${mod.action}: ${mod.filePath} - ${mod.description}`
|
|
144
|
-
);
|
|
145
|
-
clack.note(modifications.join('\n'), 'Files Modified');
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Display next steps
|
|
149
|
-
if (result.nextSteps && result.nextSteps.length > 0) {
|
|
150
|
-
clack.note(result.nextSteps.join('\n'), 'Next Steps');
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Display AI insights if available
|
|
154
|
-
if (result.aiAnalysis) {
|
|
155
|
-
clack.note(`Confidence: ${Math.round(result.aiAnalysis.confidence * 100)}%`, 'AI Analysis');
|
|
156
|
-
if (result.aiAnalysis.recommendations && result.aiAnalysis.recommendations.length > 0) {
|
|
157
|
-
clack.note(result.aiAnalysis.recommendations.join('\n'), 'AI Recommendations');
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
} else {
|
|
162
|
-
clack.cancel('Installation failed');
|
|
163
|
-
|
|
164
|
-
if (result.errors && result.errors.length > 0) {
|
|
165
|
-
clack.note(result.errors.join('\n'), 'Errors');
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function parseArgs(): AICLIOptions {
|
|
172
|
-
const args = process.argv.slice(2);
|
|
173
|
-
const options: AICLIOptions = {};
|
|
174
|
-
|
|
175
|
-
for (let i = 0; i < args.length; i++) {
|
|
176
|
-
const arg = args[i];
|
|
177
|
-
|
|
178
|
-
switch (arg) {
|
|
179
|
-
case '--help':
|
|
180
|
-
case '-h':
|
|
181
|
-
showHelp();
|
|
182
|
-
process.exit(0);
|
|
183
|
-
break;
|
|
184
|
-
case '--yes':
|
|
185
|
-
case '-y':
|
|
186
|
-
options.yes = true;
|
|
187
|
-
break;
|
|
188
|
-
case '--dry-run':
|
|
189
|
-
options.dryRun = true;
|
|
190
|
-
break;
|
|
191
|
-
|
|
192
|
-
case '--project':
|
|
193
|
-
case '-p':
|
|
194
|
-
options.projectPath = args[++i];
|
|
195
|
-
break;
|
|
196
|
-
case '--framework':
|
|
197
|
-
case '-f':
|
|
198
|
-
options.framework = args[++i];
|
|
199
|
-
break;
|
|
200
|
-
default:
|
|
201
|
-
if (!options.apiKey && !arg.startsWith('-')) {
|
|
202
|
-
options.apiKey = arg;
|
|
203
|
-
}
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return options;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function showHelp() {
|
|
212
|
-
console.log(`
|
|
213
|
-
🤖 HumanBehavior SDK AI Auto-Installation
|
|
214
|
-
|
|
215
|
-
Usage: npx humanbehavior-js ai-auto-install [api-key] [options]
|
|
216
|
-
|
|
217
|
-
Options:
|
|
218
|
-
-h, --help Show this help message
|
|
219
|
-
-y, --yes Skip all prompts and use defaults
|
|
220
|
-
--dry-run Show what would be changed without making changes
|
|
221
|
-
|
|
222
|
-
-p, --project <path> Specify project directory
|
|
223
|
-
-f, --framework <name> Specify framework manually
|
|
224
|
-
|
|
225
|
-
Examples:
|
|
226
|
-
npx humanbehavior-js ai-auto-install
|
|
227
|
-
npx humanbehavior-js ai-auto-install hb_your_api_key_here
|
|
228
|
-
npx humanbehavior-js ai-auto-install --project ./my-app --ai
|
|
229
|
-
npx humanbehavior-js ai-auto-install --framework react --yes
|
|
230
|
-
`);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// Main execution
|
|
234
|
-
const options = parseArgs();
|
|
235
|
-
const cli = new AIAutoInstallCLI(options);
|
|
236
|
-
cli.run().catch((error) => {
|
|
237
|
-
clack.cancel(`Unexpected error: ${error.message}`);
|
|
238
|
-
process.exit(1);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
export { AIAutoInstallCLI };
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* HumanBehavior SDK Auto-Installation CLI
|
|
5
|
-
*
|
|
6
|
-
* Usage: npx humanbehavior-js auto-install [api-key]
|
|
7
|
-
*
|
|
8
|
-
* This tool automatically detects the user's framework and modifies their codebase
|
|
9
|
-
* to integrate the SDK with minimal user intervention.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { AutoInstallationWizard } from '../core/install-wizard';
|
|
13
|
-
import { ManualFrameworkInstallationWizard } from '../ai/manual-framework-wizard';
|
|
14
|
-
import * as clack from '@clack/prompts';
|
|
15
|
-
import * as fs from 'fs';
|
|
16
|
-
import * as path from 'path';
|
|
17
|
-
|
|
18
|
-
interface CLIOptions {
|
|
19
|
-
apiKey?: string;
|
|
20
|
-
projectPath?: string;
|
|
21
|
-
yes?: boolean;
|
|
22
|
-
dryRun?: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
class AutoInstallCLI {
|
|
26
|
-
private options: CLIOptions;
|
|
27
|
-
|
|
28
|
-
constructor(options: CLIOptions) {
|
|
29
|
-
this.options = options;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async run() {
|
|
33
|
-
clack.intro('🚀 HumanBehavior SDK Auto-Installation');
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
// Get API key
|
|
37
|
-
const apiKey = await this.getApiKey();
|
|
38
|
-
if (!apiKey) {
|
|
39
|
-
clack.cancel('API key is required');
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Get project path
|
|
44
|
-
const projectPath = this.options.projectPath || process.cwd();
|
|
45
|
-
|
|
46
|
-
// Choose framework
|
|
47
|
-
const framework = await this.chooseFramework();
|
|
48
|
-
if (!framework) {
|
|
49
|
-
clack.cancel('Installation cancelled.');
|
|
50
|
-
process.exit(0);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Confirm installation
|
|
54
|
-
if (!this.options.yes) {
|
|
55
|
-
const confirmed = await this.confirmInstallation(projectPath, framework);
|
|
56
|
-
if (!confirmed) {
|
|
57
|
-
clack.cancel('Installation cancelled.');
|
|
58
|
-
process.exit(0);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Run installation
|
|
63
|
-
const spinner = clack.spinner();
|
|
64
|
-
spinner.start('🔍 Analyzing your project...');
|
|
65
|
-
|
|
66
|
-
const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
|
|
67
|
-
const result = await wizard.install();
|
|
68
|
-
|
|
69
|
-
spinner.stop('Detection complete!');
|
|
70
|
-
|
|
71
|
-
// Display results
|
|
72
|
-
this.displayResults(result);
|
|
73
|
-
|
|
74
|
-
} catch (error) {
|
|
75
|
-
clack.cancel(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
76
|
-
process.exit(1);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private async getApiKey(): Promise<string> {
|
|
81
|
-
if (this.options.apiKey) {
|
|
82
|
-
return this.options.apiKey;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const apiKey = await clack.text({
|
|
86
|
-
message: 'Enter your HumanBehavior API key:',
|
|
87
|
-
placeholder: 'hb_...',
|
|
88
|
-
validate: (value) => {
|
|
89
|
-
if (!value) return 'API key is required';
|
|
90
|
-
if (!value.startsWith('hb_')) return 'API key should start with "hb_"';
|
|
91
|
-
return undefined;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
return apiKey;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
private async chooseFramework(): Promise<string> {
|
|
101
|
-
const framework = await clack.select({
|
|
102
|
-
message: 'Select your framework:',
|
|
103
|
-
options: [
|
|
104
|
-
{ label: 'React', value: 'react' },
|
|
105
|
-
{ label: 'Next.js', value: 'nextjs' },
|
|
106
|
-
{ label: 'Vue', value: 'vue' },
|
|
107
|
-
{ label: 'Angular', value: 'angular' },
|
|
108
|
-
{ label: 'Svelte', value: 'svelte' },
|
|
109
|
-
{ label: 'Nuxt.js', value: 'nuxt' },
|
|
110
|
-
{ label: 'Remix', value: 'remix' },
|
|
111
|
-
{ label: 'Astro', value: 'astro' },
|
|
112
|
-
{ label: 'Gatsby', value: 'gatsby' },
|
|
113
|
-
{ label: 'Vanilla JS/TS', value: 'vanilla' }
|
|
114
|
-
]
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
return framework;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private async confirmInstallation(projectPath: string, framework: string): Promise<boolean> {
|
|
121
|
-
const confirmed = await clack.confirm({
|
|
122
|
-
message: `Ready to install HumanBehavior SDK in ${projectPath} for ${framework}?`
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
return confirmed;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
private displayResults(result: any) {
|
|
129
|
-
if (result.success) {
|
|
130
|
-
clack.outro('🎉 Installation completed successfully!');
|
|
131
|
-
|
|
132
|
-
// Display framework info
|
|
133
|
-
clack.note(`Framework detected: ${result.framework.name} (${result.framework.type})`, 'Framework Info');
|
|
134
|
-
|
|
135
|
-
// Display modifications
|
|
136
|
-
if (result.modifications && result.modifications.length > 0) {
|
|
137
|
-
const modifications = result.modifications.map((mod: any) =>
|
|
138
|
-
`${mod.action}: ${mod.filePath} - ${mod.description}`
|
|
139
|
-
);
|
|
140
|
-
clack.note(modifications.join('\n'), 'Files Modified');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Display next steps
|
|
144
|
-
if (result.nextSteps && result.nextSteps.length > 0) {
|
|
145
|
-
clack.note(result.nextSteps.join('\n'), 'Next Steps');
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
} else {
|
|
149
|
-
clack.cancel('Installation failed');
|
|
150
|
-
|
|
151
|
-
if (result.errors && result.errors.length > 0) {
|
|
152
|
-
clack.note(result.errors.join('\n'), 'Errors');
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function parseArgs(): CLIOptions {
|
|
159
|
-
const args = process.argv.slice(2);
|
|
160
|
-
const options: CLIOptions = {};
|
|
161
|
-
|
|
162
|
-
for (let i = 0; i < args.length; i++) {
|
|
163
|
-
const arg = args[i];
|
|
164
|
-
|
|
165
|
-
switch (arg) {
|
|
166
|
-
case '--help':
|
|
167
|
-
case '-h':
|
|
168
|
-
showHelp();
|
|
169
|
-
process.exit(0);
|
|
170
|
-
break;
|
|
171
|
-
case '--yes':
|
|
172
|
-
case '-y':
|
|
173
|
-
options.yes = true;
|
|
174
|
-
break;
|
|
175
|
-
case '--dry-run':
|
|
176
|
-
options.dryRun = true;
|
|
177
|
-
break;
|
|
178
|
-
case '--project':
|
|
179
|
-
case '-p':
|
|
180
|
-
options.projectPath = args[++i];
|
|
181
|
-
break;
|
|
182
|
-
default:
|
|
183
|
-
if (!options.apiKey && !arg.startsWith('-')) {
|
|
184
|
-
options.apiKey = arg;
|
|
185
|
-
}
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return options;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function showHelp() {
|
|
194
|
-
console.log(`
|
|
195
|
-
🚀 HumanBehavior SDK Auto-Installation
|
|
196
|
-
|
|
197
|
-
Usage: npx humanbehavior-js auto-install [api-key] [options]
|
|
198
|
-
|
|
199
|
-
This tool automatically detects your framework and integrates the HumanBehavior SDK.
|
|
200
|
-
|
|
201
|
-
Options:
|
|
202
|
-
-h, --help Show this help message
|
|
203
|
-
-y, --yes Skip all prompts and use defaults
|
|
204
|
-
--dry-run Show what would be changed without making changes
|
|
205
|
-
-p, --project <path> Specify project directory
|
|
206
|
-
|
|
207
|
-
Examples:
|
|
208
|
-
npx humanbehavior-js auto-install
|
|
209
|
-
npx humanbehavior-js auto-install hb_your_api_key_here
|
|
210
|
-
npx humanbehavior-js auto-install --project ./my-app --yes
|
|
211
|
-
`);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Main execution
|
|
215
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
216
|
-
const options = parseArgs();
|
|
217
|
-
const cli = new AutoInstallCLI(options);
|
|
218
|
-
cli.run().catch((error) => {
|
|
219
|
-
clack.cancel(`Unexpected error: ${error.message}`);
|
|
220
|
-
process.exit(1);
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
export { AutoInstallCLI };
|