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,3490 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var fs = require('fs');
|
|
4
|
-
var path = require('path');
|
|
5
|
-
var clack = require('@clack/prompts');
|
|
6
|
-
|
|
7
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
8
|
-
function _interopNamespaceDefault(e) {
|
|
9
|
-
var n = Object.create(null);
|
|
10
|
-
if (e) {
|
|
11
|
-
Object.keys(e).forEach(function (k) {
|
|
12
|
-
if (k !== 'default') {
|
|
13
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () { return e[k]; }
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
n.default = e;
|
|
22
|
-
return Object.freeze(n);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
26
|
-
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
27
|
-
var clack__namespace = /*#__PURE__*/_interopNamespaceDefault(clack);
|
|
28
|
-
|
|
29
|
-
/******************************************************************************
|
|
30
|
-
Copyright (c) Microsoft Corporation.
|
|
31
|
-
|
|
32
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
33
|
-
purpose with or without fee is hereby granted.
|
|
34
|
-
|
|
35
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
36
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
37
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
38
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
39
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
40
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
41
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
42
|
-
***************************************************************************** */
|
|
43
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
47
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
48
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
49
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
50
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
51
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
52
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
57
|
-
var e = new Error(message);
|
|
58
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* HumanBehavior SDK Auto-Installation Wizard
|
|
63
|
-
*
|
|
64
|
-
* This wizard automatically detects the user's framework and modifies their codebase
|
|
65
|
-
* to integrate the SDK with minimal user intervention.
|
|
66
|
-
*/
|
|
67
|
-
class AutoInstallationWizard {
|
|
68
|
-
constructor(apiKey, projectRoot = process.cwd()) {
|
|
69
|
-
this.framework = null;
|
|
70
|
-
this.apiKey = apiKey;
|
|
71
|
-
this.projectRoot = projectRoot;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Simple version comparison utility
|
|
75
|
-
*/
|
|
76
|
-
compareVersions(version1, version2) {
|
|
77
|
-
const v1Parts = version1.split('.').map(Number);
|
|
78
|
-
const v2Parts = version2.split('.').map(Number);
|
|
79
|
-
for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
|
|
80
|
-
const v1 = v1Parts[i] || 0;
|
|
81
|
-
const v2 = v2Parts[i] || 0;
|
|
82
|
-
if (v1 > v2)
|
|
83
|
-
return 1;
|
|
84
|
-
if (v1 < v2)
|
|
85
|
-
return -1;
|
|
86
|
-
}
|
|
87
|
-
return 0;
|
|
88
|
-
}
|
|
89
|
-
isVersionGte(version, target) {
|
|
90
|
-
return this.compareVersions(version, target) >= 0;
|
|
91
|
-
}
|
|
92
|
-
getMajorVersion(version) {
|
|
93
|
-
return parseInt(version.split('.')[0]) || 0;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Main installation method - detects framework and auto-installs
|
|
97
|
-
*/
|
|
98
|
-
install() {
|
|
99
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
-
try {
|
|
101
|
-
// Step 1: Detect framework
|
|
102
|
-
this.framework = yield this.detectFramework();
|
|
103
|
-
// Step 2: Install package
|
|
104
|
-
yield this.installPackage();
|
|
105
|
-
// Step 3: Generate and apply code modifications
|
|
106
|
-
const modifications = yield this.generateModifications();
|
|
107
|
-
yield this.applyModifications(modifications);
|
|
108
|
-
// Step 4: Generate next steps
|
|
109
|
-
const nextSteps = this.generateNextSteps();
|
|
110
|
-
return {
|
|
111
|
-
success: true,
|
|
112
|
-
framework: this.framework,
|
|
113
|
-
modifications,
|
|
114
|
-
errors: [],
|
|
115
|
-
nextSteps
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
return {
|
|
120
|
-
success: false,
|
|
121
|
-
framework: this.framework || { name: 'unknown', type: 'vanilla' },
|
|
122
|
-
modifications: [],
|
|
123
|
-
errors: [error instanceof Error ? error.message : 'Unknown error'],
|
|
124
|
-
nextSteps: []
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Detect the current framework and project setup
|
|
131
|
-
*/
|
|
132
|
-
detectFramework() {
|
|
133
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
-
const packageJsonPath = path__namespace.join(this.projectRoot, 'package.json');
|
|
135
|
-
if (!fs__namespace.existsSync(packageJsonPath)) {
|
|
136
|
-
return {
|
|
137
|
-
name: 'vanilla',
|
|
138
|
-
type: 'vanilla',
|
|
139
|
-
projectRoot: this.projectRoot
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
const packageJson = JSON.parse(fs__namespace.readFileSync(packageJsonPath, 'utf8'));
|
|
143
|
-
const dependencies = Object.assign(Object.assign({}, packageJson.dependencies), packageJson.devDependencies);
|
|
144
|
-
// Detect framework with version information
|
|
145
|
-
let framework = {
|
|
146
|
-
name: 'vanilla',
|
|
147
|
-
type: 'vanilla',
|
|
148
|
-
projectRoot: this.projectRoot,
|
|
149
|
-
features: {}
|
|
150
|
-
};
|
|
151
|
-
if (dependencies.nuxt) {
|
|
152
|
-
const nuxtVersion = dependencies.nuxt;
|
|
153
|
-
const isNuxt3 = this.isVersionGte(nuxtVersion, '3.0.0');
|
|
154
|
-
framework = {
|
|
155
|
-
name: 'nuxt',
|
|
156
|
-
type: 'nuxt',
|
|
157
|
-
version: nuxtVersion,
|
|
158
|
-
majorVersion: this.getMajorVersion(nuxtVersion),
|
|
159
|
-
hasTypeScript: !!dependencies.typescript,
|
|
160
|
-
hasRouter: true,
|
|
161
|
-
projectRoot: this.projectRoot,
|
|
162
|
-
features: {
|
|
163
|
-
hasNuxt3: isNuxt3
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
else if (dependencies.next) {
|
|
168
|
-
const nextVersion = dependencies.next;
|
|
169
|
-
const isNext13 = this.isVersionGte(nextVersion, '13.0.0');
|
|
170
|
-
framework = {
|
|
171
|
-
name: 'nextjs',
|
|
172
|
-
type: 'nextjs',
|
|
173
|
-
version: nextVersion,
|
|
174
|
-
majorVersion: this.getMajorVersion(nextVersion),
|
|
175
|
-
hasTypeScript: !!dependencies.typescript || !!dependencies['@types/node'],
|
|
176
|
-
hasRouter: true,
|
|
177
|
-
projectRoot: this.projectRoot,
|
|
178
|
-
features: {
|
|
179
|
-
hasNextAppRouter: isNext13
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
else if (dependencies['@remix-run/react'] || dependencies['@remix-run/dev']) {
|
|
184
|
-
const remixVersion = dependencies['@remix-run/react'] || dependencies['@remix-run/dev'];
|
|
185
|
-
framework = {
|
|
186
|
-
name: 'remix',
|
|
187
|
-
type: 'remix',
|
|
188
|
-
version: remixVersion,
|
|
189
|
-
majorVersion: this.getMajorVersion(remixVersion),
|
|
190
|
-
hasTypeScript: !!dependencies.typescript || !!dependencies['@types/react'],
|
|
191
|
-
hasRouter: true,
|
|
192
|
-
projectRoot: this.projectRoot,
|
|
193
|
-
features: {}
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
else if (dependencies.react) {
|
|
197
|
-
const reactVersion = dependencies.react;
|
|
198
|
-
const isReact18 = this.isVersionGte(reactVersion, '18.0.0');
|
|
199
|
-
framework = {
|
|
200
|
-
name: 'react',
|
|
201
|
-
type: 'react',
|
|
202
|
-
version: reactVersion,
|
|
203
|
-
majorVersion: this.getMajorVersion(reactVersion),
|
|
204
|
-
hasTypeScript: !!dependencies.typescript || !!dependencies['@types/react'],
|
|
205
|
-
hasRouter: !!dependencies['react-router-dom'] || !!dependencies['react-router'],
|
|
206
|
-
projectRoot: this.projectRoot,
|
|
207
|
-
features: {
|
|
208
|
-
hasReact18: isReact18
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
else if (dependencies.vue) {
|
|
213
|
-
const vueVersion = dependencies.vue;
|
|
214
|
-
const isVue3 = this.isVersionGte(vueVersion, '3.0.0');
|
|
215
|
-
framework = {
|
|
216
|
-
name: 'vue',
|
|
217
|
-
type: 'vue',
|
|
218
|
-
version: vueVersion,
|
|
219
|
-
majorVersion: this.getMajorVersion(vueVersion),
|
|
220
|
-
hasTypeScript: !!dependencies.typescript || !!dependencies['@vue/cli-service'],
|
|
221
|
-
hasRouter: !!dependencies['vue-router'],
|
|
222
|
-
projectRoot: this.projectRoot,
|
|
223
|
-
features: {
|
|
224
|
-
hasVue3: isVue3
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
else if (dependencies['@angular/core']) {
|
|
229
|
-
const angularVersion = dependencies['@angular/core'];
|
|
230
|
-
const isAngular17 = this.isVersionGte(angularVersion, '17.0.0');
|
|
231
|
-
framework = {
|
|
232
|
-
name: 'angular',
|
|
233
|
-
type: 'angular',
|
|
234
|
-
version: angularVersion,
|
|
235
|
-
majorVersion: this.getMajorVersion(angularVersion),
|
|
236
|
-
hasTypeScript: true,
|
|
237
|
-
hasRouter: true,
|
|
238
|
-
projectRoot: this.projectRoot,
|
|
239
|
-
features: {
|
|
240
|
-
hasAngularStandalone: isAngular17
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
else if (dependencies.svelte) {
|
|
245
|
-
const svelteVersion = dependencies.svelte;
|
|
246
|
-
const isSvelteKit = !!dependencies['@sveltejs/kit'];
|
|
247
|
-
framework = {
|
|
248
|
-
name: 'svelte',
|
|
249
|
-
type: 'svelte',
|
|
250
|
-
version: svelteVersion,
|
|
251
|
-
majorVersion: this.getMajorVersion(svelteVersion),
|
|
252
|
-
hasTypeScript: !!dependencies.typescript || !!dependencies['svelte-check'],
|
|
253
|
-
hasRouter: !!dependencies['svelte-routing'] || !!dependencies['@sveltejs/kit'],
|
|
254
|
-
projectRoot: this.projectRoot,
|
|
255
|
-
features: {
|
|
256
|
-
hasSvelteKit: isSvelteKit
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
else if (dependencies.astro) {
|
|
261
|
-
const astroVersion = dependencies.astro;
|
|
262
|
-
framework = {
|
|
263
|
-
name: 'astro',
|
|
264
|
-
type: 'astro',
|
|
265
|
-
version: astroVersion,
|
|
266
|
-
majorVersion: this.getMajorVersion(astroVersion),
|
|
267
|
-
hasTypeScript: !!dependencies.typescript || !!dependencies['@astrojs/ts-plugin'],
|
|
268
|
-
hasRouter: true,
|
|
269
|
-
projectRoot: this.projectRoot,
|
|
270
|
-
features: {}
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
else if (dependencies.gatsby) {
|
|
274
|
-
const gatsbyVersion = dependencies.gatsby;
|
|
275
|
-
framework = {
|
|
276
|
-
name: 'gatsby',
|
|
277
|
-
type: 'gatsby',
|
|
278
|
-
version: gatsbyVersion,
|
|
279
|
-
majorVersion: this.getMajorVersion(gatsbyVersion),
|
|
280
|
-
hasTypeScript: !!dependencies.typescript || !!dependencies['@types/react'],
|
|
281
|
-
hasRouter: true,
|
|
282
|
-
projectRoot: this.projectRoot,
|
|
283
|
-
features: {}
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
// Detect bundler
|
|
287
|
-
if (dependencies.vite) {
|
|
288
|
-
framework.bundler = 'vite';
|
|
289
|
-
}
|
|
290
|
-
else if (dependencies.webpack) {
|
|
291
|
-
framework.bundler = 'webpack';
|
|
292
|
-
}
|
|
293
|
-
else if (dependencies.esbuild) {
|
|
294
|
-
framework.bundler = 'esbuild';
|
|
295
|
-
}
|
|
296
|
-
else if (dependencies.rollup) {
|
|
297
|
-
framework.bundler = 'rollup';
|
|
298
|
-
}
|
|
299
|
-
// Detect package manager
|
|
300
|
-
if (fs__namespace.existsSync(path__namespace.join(this.projectRoot, 'yarn.lock'))) {
|
|
301
|
-
framework.packageManager = 'yarn';
|
|
302
|
-
}
|
|
303
|
-
else if (fs__namespace.existsSync(path__namespace.join(this.projectRoot, 'pnpm-lock.yaml'))) {
|
|
304
|
-
framework.packageManager = 'pnpm';
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
framework.packageManager = 'npm';
|
|
308
|
-
}
|
|
309
|
-
return framework;
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Install the SDK package with latest version range
|
|
314
|
-
*/
|
|
315
|
-
installPackage() {
|
|
316
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
-
var _a, _b, _c, _d;
|
|
318
|
-
const { execSync } = yield import('child_process');
|
|
319
|
-
// Build base command with latest version range
|
|
320
|
-
let command = ((_a = this.framework) === null || _a === void 0 ? void 0 : _a.packageManager) === 'yarn'
|
|
321
|
-
? 'yarn add humanbehavior-js@latest'
|
|
322
|
-
: ((_b = this.framework) === null || _b === void 0 ? void 0 : _b.packageManager) === 'pnpm'
|
|
323
|
-
? 'pnpm add humanbehavior-js@latest'
|
|
324
|
-
: 'npm install humanbehavior-js@latest';
|
|
325
|
-
// Add legacy peer deps flag for npm to handle dependency conflicts
|
|
326
|
-
if (((_c = this.framework) === null || _c === void 0 ? void 0 : _c.packageManager) !== 'yarn' && ((_d = this.framework) === null || _d === void 0 ? void 0 : _d.packageManager) !== 'pnpm') {
|
|
327
|
-
command += ' --legacy-peer-deps';
|
|
328
|
-
}
|
|
329
|
-
try {
|
|
330
|
-
execSync(command, { cwd: this.projectRoot, stdio: 'inherit' });
|
|
331
|
-
}
|
|
332
|
-
catch (error) {
|
|
333
|
-
throw new Error(`Failed to install humanbehavior-js: ${error}`);
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Generate code modifications based on framework
|
|
339
|
-
*/
|
|
340
|
-
generateModifications() {
|
|
341
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
-
var _a;
|
|
343
|
-
const modifications = [];
|
|
344
|
-
switch ((_a = this.framework) === null || _a === void 0 ? void 0 : _a.type) {
|
|
345
|
-
case 'react':
|
|
346
|
-
modifications.push(...yield this.generateReactModifications());
|
|
347
|
-
break;
|
|
348
|
-
case 'nextjs':
|
|
349
|
-
modifications.push(...yield this.generateNextJSModifications());
|
|
350
|
-
break;
|
|
351
|
-
case 'nuxt':
|
|
352
|
-
modifications.push(...yield this.generateNuxtModifications());
|
|
353
|
-
break;
|
|
354
|
-
case 'astro':
|
|
355
|
-
modifications.push(...yield this.generateAstroModifications());
|
|
356
|
-
break;
|
|
357
|
-
case 'gatsby':
|
|
358
|
-
modifications.push(...yield this.generateGatsbyModifications());
|
|
359
|
-
break;
|
|
360
|
-
case 'remix':
|
|
361
|
-
modifications.push(...yield this.generateRemixModifications());
|
|
362
|
-
break;
|
|
363
|
-
case 'vue':
|
|
364
|
-
modifications.push(...yield this.generateVueModifications());
|
|
365
|
-
break;
|
|
366
|
-
case 'angular':
|
|
367
|
-
modifications.push(...yield this.generateAngularModifications());
|
|
368
|
-
break;
|
|
369
|
-
case 'svelte':
|
|
370
|
-
modifications.push(...yield this.generateSvelteModifications());
|
|
371
|
-
break;
|
|
372
|
-
default:
|
|
373
|
-
modifications.push(...yield this.generateVanillaModifications());
|
|
374
|
-
}
|
|
375
|
-
return modifications;
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Generate React-specific modifications
|
|
380
|
-
*/
|
|
381
|
-
generateReactModifications() {
|
|
382
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
383
|
-
const modifications = [];
|
|
384
|
-
// Find main App component or index file
|
|
385
|
-
const appFile = this.findReactAppFile();
|
|
386
|
-
if (appFile) {
|
|
387
|
-
const content = fs__namespace.readFileSync(appFile, 'utf8');
|
|
388
|
-
const modifiedContent = this.injectReactProvider(content, appFile);
|
|
389
|
-
modifications.push({
|
|
390
|
-
filePath: appFile,
|
|
391
|
-
action: 'modify',
|
|
392
|
-
content: modifiedContent,
|
|
393
|
-
description: 'Added HumanBehaviorProvider to React app'
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
// Create or append to environment file
|
|
397
|
-
modifications.push(this.createEnvironmentModification(this.framework));
|
|
398
|
-
return modifications;
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Generate Next.js-specific modifications
|
|
403
|
-
*/
|
|
404
|
-
generateNextJSModifications() {
|
|
405
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
406
|
-
const modifications = [];
|
|
407
|
-
// Check for App Router
|
|
408
|
-
const appLayoutFile = path__namespace.join(this.projectRoot, 'src', 'app', 'layout.tsx');
|
|
409
|
-
const pagesLayoutFile = path__namespace.join(this.projectRoot, 'src', 'pages', '_app.tsx');
|
|
410
|
-
if (fs__namespace.existsSync(appLayoutFile)) {
|
|
411
|
-
// Create providers.tsx file for App Router
|
|
412
|
-
modifications.push({
|
|
413
|
-
filePath: path__namespace.join(this.projectRoot, 'src', 'app', 'providers.tsx'),
|
|
414
|
-
action: 'create',
|
|
415
|
-
content: `'use client';
|
|
416
|
-
|
|
417
|
-
import { HumanBehaviorProvider } from 'humanbehavior-js/react';
|
|
418
|
-
|
|
419
|
-
export function Providers({ children }: { children: React.ReactNode }) {
|
|
420
|
-
return (
|
|
421
|
-
<HumanBehaviorProvider apiKey={process.env.NEXT_PUBLIC_HUMANBEHAVIOR_API_KEY}>
|
|
422
|
-
{children}
|
|
423
|
-
</HumanBehaviorProvider>
|
|
424
|
-
);
|
|
425
|
-
}`,
|
|
426
|
-
description: 'Created providers.tsx file for Next.js App Router'
|
|
427
|
-
});
|
|
428
|
-
// Modify layout.tsx to use the provider
|
|
429
|
-
const content = fs__namespace.readFileSync(appLayoutFile, 'utf8');
|
|
430
|
-
const modifiedContent = this.injectNextJSAppRouter(content);
|
|
431
|
-
modifications.push({
|
|
432
|
-
filePath: appLayoutFile,
|
|
433
|
-
action: 'modify',
|
|
434
|
-
content: modifiedContent,
|
|
435
|
-
description: 'Added Providers wrapper to Next.js App Router layout'
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
else if (fs__namespace.existsSync(pagesLayoutFile)) {
|
|
439
|
-
// Create providers.tsx file for Pages Router
|
|
440
|
-
modifications.push({
|
|
441
|
-
filePath: path__namespace.join(this.projectRoot, 'src', 'components', 'providers.tsx'),
|
|
442
|
-
action: 'create',
|
|
443
|
-
content: `'use client';
|
|
444
|
-
|
|
445
|
-
import { HumanBehaviorProvider } from 'humanbehavior-js/react';
|
|
446
|
-
|
|
447
|
-
export function Providers({ children }: { children: React.ReactNode }) {
|
|
448
|
-
return (
|
|
449
|
-
<HumanBehaviorProvider apiKey={process.env.NEXT_PUBLIC_HUMANBEHAVIOR_API_KEY}>
|
|
450
|
-
{children}
|
|
451
|
-
</HumanBehaviorProvider>
|
|
452
|
-
);
|
|
453
|
-
}`,
|
|
454
|
-
description: 'Created providers.tsx file for Pages Router'
|
|
455
|
-
});
|
|
456
|
-
// Modify _app.tsx to use the provider
|
|
457
|
-
const content = fs__namespace.readFileSync(pagesLayoutFile, 'utf8');
|
|
458
|
-
const modifiedContent = this.injectNextJSPagesRouter(content);
|
|
459
|
-
modifications.push({
|
|
460
|
-
filePath: pagesLayoutFile,
|
|
461
|
-
action: 'modify',
|
|
462
|
-
content: modifiedContent,
|
|
463
|
-
description: 'Added Providers wrapper to Next.js Pages Router'
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
// Create or append to environment file
|
|
467
|
-
modifications.push(this.createEnvironmentModification(this.framework));
|
|
468
|
-
return modifications;
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Generate Astro-specific modifications
|
|
473
|
-
*/
|
|
474
|
-
generateAstroModifications() {
|
|
475
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
476
|
-
const modifications = [];
|
|
477
|
-
// Create Astro component for HumanBehavior
|
|
478
|
-
const astroComponentPath = path__namespace.join(this.projectRoot, 'src', 'components', 'HumanBehavior.astro');
|
|
479
|
-
const astroComponentContent = `---
|
|
480
|
-
// This component will only run on the client side
|
|
481
|
-
---
|
|
482
|
-
|
|
483
|
-
<script>
|
|
484
|
-
import { HumanBehaviorTracker } from 'humanbehavior-js';
|
|
485
|
-
|
|
486
|
-
// Get API key from environment variable
|
|
487
|
-
const apiKey = import.meta.env.PUBLIC_HUMANBEHAVIOR_API_KEY;
|
|
488
|
-
|
|
489
|
-
console.log('HumanBehavior: API key found:', apiKey ? 'Yes' : 'No');
|
|
490
|
-
|
|
491
|
-
if (apiKey) {
|
|
492
|
-
try {
|
|
493
|
-
const tracker = HumanBehaviorTracker.init(apiKey);
|
|
494
|
-
console.log('HumanBehavior: Tracker initialized successfully');
|
|
495
|
-
|
|
496
|
-
// Test event to verify tracking is working
|
|
497
|
-
setTimeout(() => {
|
|
498
|
-
tracker.customEvent('astro_page_view', {
|
|
499
|
-
page: window.location.pathname,
|
|
500
|
-
framework: 'astro'
|
|
501
|
-
}).then(() => {
|
|
502
|
-
console.log('HumanBehavior: Test event sent successfully');
|
|
503
|
-
}).catch((error) => {
|
|
504
|
-
console.error('HumanBehavior: Failed to send test event:', error);
|
|
505
|
-
});
|
|
506
|
-
}, 1000);
|
|
507
|
-
|
|
508
|
-
} catch (error) {
|
|
509
|
-
console.error('HumanBehavior: Failed to initialize tracker:', error);
|
|
510
|
-
}
|
|
511
|
-
} else {
|
|
512
|
-
console.error('HumanBehavior: No API key found');
|
|
513
|
-
}
|
|
514
|
-
</script>`;
|
|
515
|
-
modifications.push({
|
|
516
|
-
filePath: astroComponentPath,
|
|
517
|
-
action: 'create',
|
|
518
|
-
content: astroComponentContent,
|
|
519
|
-
description: 'Created Astro component for HumanBehavior SDK'
|
|
520
|
-
});
|
|
521
|
-
// Find and update layout file
|
|
522
|
-
const layoutFiles = [
|
|
523
|
-
path__namespace.join(this.projectRoot, 'src', 'layouts', 'Layout.astro'),
|
|
524
|
-
path__namespace.join(this.projectRoot, 'src', 'layouts', 'layout.astro'),
|
|
525
|
-
path__namespace.join(this.projectRoot, 'src', 'layouts', 'BaseLayout.astro')
|
|
526
|
-
];
|
|
527
|
-
let layoutFile = null;
|
|
528
|
-
for (const file of layoutFiles) {
|
|
529
|
-
if (fs__namespace.existsSync(file)) {
|
|
530
|
-
layoutFile = file;
|
|
531
|
-
break;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
if (layoutFile) {
|
|
535
|
-
const content = fs__namespace.readFileSync(layoutFile, 'utf8');
|
|
536
|
-
const modifiedContent = this.injectAstroLayout(content);
|
|
537
|
-
modifications.push({
|
|
538
|
-
filePath: layoutFile,
|
|
539
|
-
action: 'modify',
|
|
540
|
-
content: modifiedContent,
|
|
541
|
-
description: 'Added HumanBehavior component to Astro layout'
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
// Add environment variable
|
|
545
|
-
modifications.push(this.createEnvironmentModification(this.framework));
|
|
546
|
-
return modifications;
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
/**
|
|
550
|
-
* Generate Nuxt-specific modifications
|
|
551
|
-
*/
|
|
552
|
-
generateNuxtModifications() {
|
|
553
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
554
|
-
const modifications = [];
|
|
555
|
-
// Create plugin file for Nuxt (in app directory)
|
|
556
|
-
const pluginFile = path__namespace.join(this.projectRoot, 'app', 'plugins', 'humanbehavior.client.ts');
|
|
557
|
-
modifications.push({
|
|
558
|
-
filePath: pluginFile,
|
|
559
|
-
action: 'create',
|
|
560
|
-
content: `import { HumanBehaviorTracker } from 'humanbehavior-js';
|
|
561
|
-
|
|
562
|
-
export default defineNuxtPlugin(() => {
|
|
563
|
-
const config = useRuntimeConfig();
|
|
564
|
-
|
|
565
|
-
// Initialize HumanBehavior SDK (client-side only)
|
|
566
|
-
if (typeof window !== 'undefined') {
|
|
567
|
-
const apiKey = config.public.humanBehaviorApiKey;
|
|
568
|
-
console.log('HumanBehavior: API key:', apiKey ? 'present' : 'missing');
|
|
569
|
-
|
|
570
|
-
if (apiKey) {
|
|
571
|
-
try {
|
|
572
|
-
const tracker = HumanBehaviorTracker.init(apiKey);
|
|
573
|
-
console.log('HumanBehavior: Tracker initialized successfully');
|
|
574
|
-
} catch (error) {
|
|
575
|
-
console.error('HumanBehavior: Failed to initialize tracker:', error);
|
|
576
|
-
}
|
|
577
|
-
} else {
|
|
578
|
-
console.error('HumanBehavior: No API key found in runtime config');
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
});`,
|
|
582
|
-
description: 'Created Nuxt plugin for HumanBehavior SDK in app directory'
|
|
583
|
-
});
|
|
584
|
-
// Create environment configuration
|
|
585
|
-
const nuxtConfigFile = path__namespace.join(this.projectRoot, 'nuxt.config.ts');
|
|
586
|
-
if (fs__namespace.existsSync(nuxtConfigFile)) {
|
|
587
|
-
const content = fs__namespace.readFileSync(nuxtConfigFile, 'utf8');
|
|
588
|
-
const modifiedContent = this.injectNuxtConfig(content);
|
|
589
|
-
modifications.push({
|
|
590
|
-
filePath: nuxtConfigFile,
|
|
591
|
-
action: 'modify',
|
|
592
|
-
content: modifiedContent,
|
|
593
|
-
description: 'Added HumanBehavior runtime config to Nuxt config'
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
// Create or append to environment file
|
|
597
|
-
modifications.push(this.createEnvironmentModification(this.framework));
|
|
598
|
-
return modifications;
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
/**
|
|
602
|
-
* Generate Remix-specific modifications
|
|
603
|
-
*/
|
|
604
|
-
generateRemixModifications() {
|
|
605
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
606
|
-
const modifications = [];
|
|
607
|
-
// Find root.tsx file
|
|
608
|
-
const rootFile = path__namespace.join(this.projectRoot, 'app', 'root.tsx');
|
|
609
|
-
if (fs__namespace.existsSync(rootFile)) {
|
|
610
|
-
const content = fs__namespace.readFileSync(rootFile, 'utf8');
|
|
611
|
-
const modifiedContent = this.injectRemixProvider(content);
|
|
612
|
-
modifications.push({
|
|
613
|
-
filePath: rootFile,
|
|
614
|
-
action: 'modify',
|
|
615
|
-
content: modifiedContent,
|
|
616
|
-
description: 'Added HumanBehaviorProvider to Remix root component'
|
|
617
|
-
});
|
|
618
|
-
}
|
|
619
|
-
// Create or append to environment file
|
|
620
|
-
modifications.push(this.createEnvironmentModification(this.framework));
|
|
621
|
-
return modifications;
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
* Generate Vue-specific modifications
|
|
626
|
-
*/
|
|
627
|
-
generateVueModifications() {
|
|
628
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
629
|
-
const modifications = [];
|
|
630
|
-
// Find main.js or main.ts
|
|
631
|
-
const mainFile = this.findVueMainFile();
|
|
632
|
-
if (mainFile) {
|
|
633
|
-
const content = fs__namespace.readFileSync(mainFile, 'utf8');
|
|
634
|
-
const modifiedContent = this.injectVuePlugin(content);
|
|
635
|
-
modifications.push({
|
|
636
|
-
filePath: mainFile,
|
|
637
|
-
action: 'modify',
|
|
638
|
-
content: modifiedContent,
|
|
639
|
-
description: 'Added HumanBehaviorPlugin to Vue app'
|
|
640
|
-
});
|
|
641
|
-
}
|
|
642
|
-
// Create or append to environment file
|
|
643
|
-
modifications.push(this.createEnvironmentModification(this.framework));
|
|
644
|
-
return modifications;
|
|
645
|
-
});
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
* Generate Angular-specific modifications
|
|
649
|
-
*/
|
|
650
|
-
generateAngularModifications() {
|
|
651
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
652
|
-
const modifications = [];
|
|
653
|
-
// Check for modern Angular (standalone components) vs legacy (NgModule)
|
|
654
|
-
const appModuleFile = path__namespace.join(this.projectRoot, 'src', 'app', 'app.module.ts');
|
|
655
|
-
const appComponentFile = path__namespace.join(this.projectRoot, 'src', 'app', 'app.ts');
|
|
656
|
-
const mainFile = path__namespace.join(this.projectRoot, 'src', 'main.ts');
|
|
657
|
-
const isModernAngular = fs__namespace.existsSync(appComponentFile) && !fs__namespace.existsSync(appModuleFile);
|
|
658
|
-
if (isModernAngular) {
|
|
659
|
-
// Modern Angular 17+ with standalone components
|
|
660
|
-
if (fs__namespace.existsSync(mainFile)) {
|
|
661
|
-
const content = fs__namespace.readFileSync(mainFile, 'utf8');
|
|
662
|
-
const modifiedContent = this.injectAngularStandaloneInit(content);
|
|
663
|
-
modifications.push({
|
|
664
|
-
filePath: mainFile,
|
|
665
|
-
action: 'modify',
|
|
666
|
-
content: modifiedContent,
|
|
667
|
-
description: 'Added HumanBehavior initialization to Angular main.ts'
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
else if (fs__namespace.existsSync(appModuleFile)) {
|
|
672
|
-
// Legacy Angular with NgModule
|
|
673
|
-
const content = fs__namespace.readFileSync(appModuleFile, 'utf8');
|
|
674
|
-
const modifiedContent = this.injectAngularModule(content);
|
|
675
|
-
modifications.push({
|
|
676
|
-
filePath: appModuleFile,
|
|
677
|
-
action: 'modify',
|
|
678
|
-
content: modifiedContent,
|
|
679
|
-
description: 'Added HumanBehaviorModule to Angular app'
|
|
680
|
-
});
|
|
681
|
-
}
|
|
682
|
-
// Handle Angular environment files (proper Angular way)
|
|
683
|
-
const envFile = path__namespace.join(this.projectRoot, 'src', 'environments', 'environment.ts');
|
|
684
|
-
const envProdFile = path__namespace.join(this.projectRoot, 'src', 'environments', 'environment.prod.ts');
|
|
685
|
-
// Create environments directory if it doesn't exist
|
|
686
|
-
const envDir = path__namespace.dirname(envFile);
|
|
687
|
-
if (!fs__namespace.existsSync(envDir)) {
|
|
688
|
-
fs__namespace.mkdirSync(envDir, { recursive: true });
|
|
689
|
-
}
|
|
690
|
-
// Create or update development environment
|
|
691
|
-
if (fs__namespace.existsSync(envFile)) {
|
|
692
|
-
const content = fs__namespace.readFileSync(envFile, 'utf8');
|
|
693
|
-
if (!content.includes('humanBehaviorApiKey')) {
|
|
694
|
-
const modifiedContent = content.replace(/export const environment = {([\s\S]*?)};/, `export const environment = {
|
|
695
|
-
$1,
|
|
696
|
-
humanBehaviorApiKey: '${this.apiKey}'
|
|
697
|
-
};`);
|
|
698
|
-
modifications.push({
|
|
699
|
-
filePath: envFile,
|
|
700
|
-
action: 'modify',
|
|
701
|
-
content: modifiedContent,
|
|
702
|
-
description: 'Added API key to Angular development environment'
|
|
703
|
-
});
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
else {
|
|
707
|
-
// Create new development environment file
|
|
708
|
-
modifications.push({
|
|
709
|
-
filePath: envFile,
|
|
710
|
-
action: 'create',
|
|
711
|
-
content: `export const environment = {
|
|
712
|
-
production: false,
|
|
713
|
-
humanBehaviorApiKey: '${this.apiKey}'
|
|
714
|
-
};`,
|
|
715
|
-
description: 'Created Angular development environment file'
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
// Create or update production environment
|
|
719
|
-
if (fs__namespace.existsSync(envProdFile)) {
|
|
720
|
-
const content = fs__namespace.readFileSync(envProdFile, 'utf8');
|
|
721
|
-
if (!content.includes('humanBehaviorApiKey')) {
|
|
722
|
-
const modifiedContent = content.replace(/export const environment = {([\s\S]*?)};/, `export const environment = {
|
|
723
|
-
$1,
|
|
724
|
-
humanBehaviorApiKey: '${this.apiKey}'
|
|
725
|
-
};`);
|
|
726
|
-
modifications.push({
|
|
727
|
-
filePath: envProdFile,
|
|
728
|
-
action: 'modify',
|
|
729
|
-
content: modifiedContent,
|
|
730
|
-
description: 'Added API key to Angular production environment'
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
else {
|
|
735
|
-
// Create new production environment file
|
|
736
|
-
modifications.push({
|
|
737
|
-
filePath: envProdFile,
|
|
738
|
-
action: 'create',
|
|
739
|
-
content: `export const environment = {
|
|
740
|
-
production: true,
|
|
741
|
-
humanBehaviorApiKey: '${this.apiKey}'
|
|
742
|
-
};`,
|
|
743
|
-
description: 'Created Angular production environment file'
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
// For Angular, we don't need .env files since we use environment.ts
|
|
747
|
-
// The environment files are already created above
|
|
748
|
-
return modifications;
|
|
749
|
-
});
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* Generate Svelte-specific modifications
|
|
753
|
-
*/
|
|
754
|
-
generateSvelteModifications() {
|
|
755
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
756
|
-
const modifications = [];
|
|
757
|
-
// Check for SvelteKit
|
|
758
|
-
const svelteConfigFile = path__namespace.join(this.projectRoot, 'svelte.config.js');
|
|
759
|
-
const isSvelteKit = fs__namespace.existsSync(svelteConfigFile);
|
|
760
|
-
if (isSvelteKit) {
|
|
761
|
-
// SvelteKit - create layout file
|
|
762
|
-
const layoutFile = path__namespace.join(this.projectRoot, 'src', 'routes', '+layout.svelte');
|
|
763
|
-
if (fs__namespace.existsSync(layoutFile)) {
|
|
764
|
-
const content = fs__namespace.readFileSync(layoutFile, 'utf8');
|
|
765
|
-
const modifiedContent = this.injectSvelteKitLayout(content);
|
|
766
|
-
modifications.push({
|
|
767
|
-
filePath: layoutFile,
|
|
768
|
-
action: 'modify',
|
|
769
|
-
content: modifiedContent,
|
|
770
|
-
description: 'Added HumanBehavior store to SvelteKit layout'
|
|
771
|
-
});
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
else {
|
|
775
|
-
// Regular Svelte - modify main file
|
|
776
|
-
const mainFile = this.findSvelteMainFile();
|
|
777
|
-
if (mainFile) {
|
|
778
|
-
const content = fs__namespace.readFileSync(mainFile, 'utf8');
|
|
779
|
-
const modifiedContent = this.injectSvelteStore(content);
|
|
780
|
-
modifications.push({
|
|
781
|
-
filePath: mainFile,
|
|
782
|
-
action: 'modify',
|
|
783
|
-
content: modifiedContent,
|
|
784
|
-
description: 'Added HumanBehavior store to Svelte app'
|
|
785
|
-
});
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
// Create or append to environment file
|
|
789
|
-
modifications.push(this.createEnvironmentModification(this.framework));
|
|
790
|
-
return modifications;
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
/**
|
|
794
|
-
* Generate vanilla JS/TS modifications
|
|
795
|
-
*/
|
|
796
|
-
generateVanillaModifications() {
|
|
797
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
798
|
-
const modifications = [];
|
|
799
|
-
// Find HTML file to inject script
|
|
800
|
-
const htmlFile = this.findHTMLFile();
|
|
801
|
-
if (htmlFile) {
|
|
802
|
-
const content = fs__namespace.readFileSync(htmlFile, 'utf8');
|
|
803
|
-
const modifiedContent = this.injectVanillaScript(content);
|
|
804
|
-
modifications.push({
|
|
805
|
-
filePath: htmlFile,
|
|
806
|
-
action: 'modify',
|
|
807
|
-
content: modifiedContent,
|
|
808
|
-
description: 'Added HumanBehavior CDN script to HTML file'
|
|
809
|
-
});
|
|
810
|
-
}
|
|
811
|
-
// Create or append to environment file
|
|
812
|
-
modifications.push(this.createEnvironmentModification(this.framework));
|
|
813
|
-
return modifications;
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
/**
|
|
817
|
-
* Generate Gatsby-specific modifications
|
|
818
|
-
*/
|
|
819
|
-
generateGatsbyModifications() {
|
|
820
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
821
|
-
const modifications = [];
|
|
822
|
-
// Modify or create gatsby-browser.js for Gatsby
|
|
823
|
-
const gatsbyBrowserFile = path__namespace.join(this.projectRoot, 'gatsby-browser.js');
|
|
824
|
-
if (fs__namespace.existsSync(gatsbyBrowserFile)) {
|
|
825
|
-
const content = fs__namespace.readFileSync(gatsbyBrowserFile, 'utf8');
|
|
826
|
-
const modifiedContent = this.injectGatsbyBrowser(content);
|
|
827
|
-
modifications.push({
|
|
828
|
-
filePath: gatsbyBrowserFile,
|
|
829
|
-
action: 'modify',
|
|
830
|
-
content: modifiedContent,
|
|
831
|
-
description: 'Added HumanBehavior initialization to Gatsby browser'
|
|
832
|
-
});
|
|
833
|
-
}
|
|
834
|
-
else {
|
|
835
|
-
// Create gatsby-browser.js if it doesn't exist
|
|
836
|
-
modifications.push({
|
|
837
|
-
filePath: gatsbyBrowserFile,
|
|
838
|
-
action: 'create',
|
|
839
|
-
content: `import { HumanBehaviorTracker } from 'humanbehavior-js';
|
|
840
|
-
|
|
841
|
-
export const onClientEntry = () => {
|
|
842
|
-
console.log('Gatsby browser entry point loaded');
|
|
843
|
-
const apiKey = process.env.GATSBY_HUMANBEHAVIOR_API_KEY;
|
|
844
|
-
console.log('API Key found:', apiKey ? 'Yes' : 'No');
|
|
845
|
-
if (apiKey) {
|
|
846
|
-
const tracker = HumanBehaviorTracker.init(apiKey);
|
|
847
|
-
console.log('HumanBehavior SDK initialized for Gatsby');
|
|
848
|
-
} else {
|
|
849
|
-
console.log('No API key found in environment variables');
|
|
850
|
-
}
|
|
851
|
-
};`,
|
|
852
|
-
description: 'Created gatsby-browser.js with HumanBehavior initialization'
|
|
853
|
-
});
|
|
854
|
-
}
|
|
855
|
-
// Create or append to environment file
|
|
856
|
-
modifications.push(this.createEnvironmentModification(this.framework));
|
|
857
|
-
return modifications;
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
/**
|
|
861
|
-
* Apply modifications to the codebase
|
|
862
|
-
*/
|
|
863
|
-
applyModifications(modifications) {
|
|
864
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
865
|
-
for (const modification of modifications) {
|
|
866
|
-
try {
|
|
867
|
-
const dir = path__namespace.dirname(modification.filePath);
|
|
868
|
-
if (!fs__namespace.existsSync(dir)) {
|
|
869
|
-
fs__namespace.mkdirSync(dir, { recursive: true });
|
|
870
|
-
}
|
|
871
|
-
switch (modification.action) {
|
|
872
|
-
case 'create':
|
|
873
|
-
fs__namespace.writeFileSync(modification.filePath, modification.content);
|
|
874
|
-
break;
|
|
875
|
-
case 'modify':
|
|
876
|
-
fs__namespace.writeFileSync(modification.filePath, modification.content);
|
|
877
|
-
break;
|
|
878
|
-
case 'append':
|
|
879
|
-
fs__namespace.appendFileSync(modification.filePath, '\n' + modification.content);
|
|
880
|
-
break;
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
catch (error) {
|
|
884
|
-
throw new Error(`Failed to apply modification to ${modification.filePath}: ${error}`);
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* Generate next steps for the user
|
|
891
|
-
*/
|
|
892
|
-
generateNextSteps() {
|
|
893
|
-
var _a, _b;
|
|
894
|
-
const steps = [
|
|
895
|
-
'✅ SDK installed and configured automatically!',
|
|
896
|
-
'🚀 Your app is now tracking user behavior',
|
|
897
|
-
'📊 View sessions in your HumanBehavior dashboard',
|
|
898
|
-
'🔧 Customize tracking in your code as needed'
|
|
899
|
-
];
|
|
900
|
-
if (((_a = this.framework) === null || _a === void 0 ? void 0 : _a.type) === 'react' || ((_b = this.framework) === null || _b === void 0 ? void 0 : _b.type) === 'nextjs') {
|
|
901
|
-
steps.push('💡 Use the useHumanBehavior() hook to track custom events');
|
|
902
|
-
}
|
|
903
|
-
return steps;
|
|
904
|
-
}
|
|
905
|
-
// Helper methods for file detection and content injection
|
|
906
|
-
findReactAppFile() {
|
|
907
|
-
const possibleFiles = [
|
|
908
|
-
'src/App.jsx', 'src/App.js', 'src/App.tsx', 'src/App.ts',
|
|
909
|
-
'src/index.js', 'src/index.tsx', 'src/main.js', 'src/main.tsx'
|
|
910
|
-
];
|
|
911
|
-
for (const file of possibleFiles) {
|
|
912
|
-
const fullPath = path__namespace.join(this.projectRoot, file);
|
|
913
|
-
if (fs__namespace.existsSync(fullPath)) {
|
|
914
|
-
return fullPath;
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
return null;
|
|
918
|
-
}
|
|
919
|
-
findVueMainFile() {
|
|
920
|
-
const possibleFiles = [
|
|
921
|
-
'src/main.js', 'src/main.ts', 'src/main.jsx', 'src/main.tsx'
|
|
922
|
-
];
|
|
923
|
-
for (const file of possibleFiles) {
|
|
924
|
-
const fullPath = path__namespace.join(this.projectRoot, file);
|
|
925
|
-
if (fs__namespace.existsSync(fullPath)) {
|
|
926
|
-
return fullPath;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
return null;
|
|
930
|
-
}
|
|
931
|
-
findSvelteMainFile() {
|
|
932
|
-
const possibleFiles = [
|
|
933
|
-
'src/main.js', 'src/main.ts', 'src/main.svelte'
|
|
934
|
-
];
|
|
935
|
-
for (const file of possibleFiles) {
|
|
936
|
-
const fullPath = path__namespace.join(this.projectRoot, file);
|
|
937
|
-
if (fs__namespace.existsSync(fullPath)) {
|
|
938
|
-
return fullPath;
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
return null;
|
|
942
|
-
}
|
|
943
|
-
findHTMLFile() {
|
|
944
|
-
const possibleFiles = ['index.html', 'public/index.html', 'dist/index.html'];
|
|
945
|
-
for (const file of possibleFiles) {
|
|
946
|
-
const fullPath = path__namespace.join(this.projectRoot, file);
|
|
947
|
-
if (fs__namespace.existsSync(fullPath)) {
|
|
948
|
-
return fullPath;
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
return null;
|
|
952
|
-
}
|
|
953
|
-
injectReactProvider(content, filePath) {
|
|
954
|
-
var _a, _b, _c;
|
|
955
|
-
filePath.endsWith('.tsx') || filePath.endsWith('.ts');
|
|
956
|
-
// Check if already has HumanBehaviorProvider
|
|
957
|
-
if (content.includes('HumanBehaviorProvider')) {
|
|
958
|
-
return content;
|
|
959
|
-
}
|
|
960
|
-
// Determine the correct environment variable syntax based on bundler
|
|
961
|
-
const isVite = ((_a = this.framework) === null || _a === void 0 ? void 0 : _a.bundler) === 'vite';
|
|
962
|
-
const envVar = isVite
|
|
963
|
-
? 'import.meta.env.VITE_HUMANBEHAVIOR_API_KEY!'
|
|
964
|
-
: 'process.env.HUMANBEHAVIOR_API_KEY!';
|
|
965
|
-
const importStatement = `import { HumanBehaviorProvider } from 'humanbehavior-js/react';`;
|
|
966
|
-
// Enhanced parsing for React 18+ features
|
|
967
|
-
const hasReact18 = (_c = (_b = this.framework) === null || _b === void 0 ? void 0 : _b.features) === null || _c === void 0 ? void 0 : _c.hasReact18;
|
|
968
|
-
// Handle different React patterns
|
|
969
|
-
if (content.includes('function App()') || content.includes('const App =')) {
|
|
970
|
-
// Add import statement
|
|
971
|
-
let modifiedContent = content.replace(/(import.*?from.*?['"]react['"];?)/, `$1\n${importStatement}`);
|
|
972
|
-
// If no React import found, add it at the top
|
|
973
|
-
if (!modifiedContent.includes(importStatement)) {
|
|
974
|
-
modifiedContent = `${importStatement}\n\n${modifiedContent}`;
|
|
975
|
-
}
|
|
976
|
-
// Wrap the App component return with HumanBehaviorProvider
|
|
977
|
-
modifiedContent = modifiedContent.replace(/(return\s*\([\s\S]*?\)\s*;)/, `return (
|
|
978
|
-
<HumanBehaviorProvider apiKey={${envVar}}>
|
|
979
|
-
$1
|
|
980
|
-
</HumanBehaviorProvider>
|
|
981
|
-
);`);
|
|
982
|
-
return modifiedContent;
|
|
983
|
-
}
|
|
984
|
-
// Handle React 18+ createRoot pattern
|
|
985
|
-
if (hasReact18 && content.includes('createRoot')) {
|
|
986
|
-
let modifiedContent = content.replace(/(import.*?from.*?['"]react['"];?)/, `$1\n${importStatement}`);
|
|
987
|
-
if (!modifiedContent.includes(importStatement)) {
|
|
988
|
-
modifiedContent = `${importStatement}\n\n${modifiedContent}`;
|
|
989
|
-
}
|
|
990
|
-
// Wrap the root render with HumanBehaviorProvider
|
|
991
|
-
modifiedContent = modifiedContent.replace(/(root\.render\s*\([\s\S]*?\)\s*;)/, `root.render(
|
|
992
|
-
<HumanBehaviorProvider apiKey={${envVar}}>
|
|
993
|
-
$1
|
|
994
|
-
</HumanBehaviorProvider>
|
|
995
|
-
);`);
|
|
996
|
-
return modifiedContent;
|
|
997
|
-
}
|
|
998
|
-
// Fallback: simple injection
|
|
999
|
-
return `${importStatement}\n\n${content}`;
|
|
1000
|
-
}
|
|
1001
|
-
injectNextJSAppRouter(content) {
|
|
1002
|
-
if (content.includes('Providers')) {
|
|
1003
|
-
return content;
|
|
1004
|
-
}
|
|
1005
|
-
const importStatement = `import { Providers } from './providers';`;
|
|
1006
|
-
// First, add the import statement
|
|
1007
|
-
let modifiedContent = content.replace(/export default function RootLayout/, `${importStatement}\n\nexport default function RootLayout`);
|
|
1008
|
-
// Then wrap the body content with Providers
|
|
1009
|
-
// Use a more specific approach to handle the body content
|
|
1010
|
-
modifiedContent = modifiedContent.replace(/<body([^>]*)>([\s\S]*?)<\/body>/, (match, bodyAttrs, bodyContent) => {
|
|
1011
|
-
// Trim whitespace and newlines from bodyContent
|
|
1012
|
-
const trimmedContent = bodyContent.trim();
|
|
1013
|
-
return `<body${bodyAttrs}>
|
|
1014
|
-
<Providers>
|
|
1015
|
-
${trimmedContent}
|
|
1016
|
-
</Providers>
|
|
1017
|
-
</body>`;
|
|
1018
|
-
});
|
|
1019
|
-
return modifiedContent;
|
|
1020
|
-
}
|
|
1021
|
-
injectNextJSPagesRouter(content) {
|
|
1022
|
-
if (content.includes('Providers')) {
|
|
1023
|
-
return content;
|
|
1024
|
-
}
|
|
1025
|
-
const importStatement = `import { Providers } from '../components/providers';`;
|
|
1026
|
-
return content.replace(/function MyApp/, `${importStatement}\n\nfunction MyApp`).replace(/return \(([\s\S]*?)\);/, `return (
|
|
1027
|
-
<Providers>
|
|
1028
|
-
$1
|
|
1029
|
-
</Providers>
|
|
1030
|
-
);`);
|
|
1031
|
-
}
|
|
1032
|
-
injectRemixProvider(content) {
|
|
1033
|
-
if (content.includes('HumanBehaviorProvider')) {
|
|
1034
|
-
return content;
|
|
1035
|
-
}
|
|
1036
|
-
const importStatement = `import { HumanBehaviorProvider, createHumanBehaviorLoader } from 'humanbehavior-js/remix';`;
|
|
1037
|
-
const useLoaderDataImport = `import { useLoaderData } from "@remix-run/react";`;
|
|
1038
|
-
// Add imports more robustly
|
|
1039
|
-
let modifiedContent = content;
|
|
1040
|
-
// Add HumanBehaviorProvider import - find the last import and add after it
|
|
1041
|
-
if (!content.includes('HumanBehaviorProvider')) {
|
|
1042
|
-
const lastImportIndex = modifiedContent.lastIndexOf('import');
|
|
1043
|
-
if (lastImportIndex !== -1) {
|
|
1044
|
-
const nextLineIndex = modifiedContent.indexOf('\n', lastImportIndex);
|
|
1045
|
-
if (nextLineIndex !== -1) {
|
|
1046
|
-
modifiedContent = modifiedContent.slice(0, nextLineIndex + 1) +
|
|
1047
|
-
importStatement + '\n' +
|
|
1048
|
-
modifiedContent.slice(nextLineIndex + 1);
|
|
1049
|
-
}
|
|
1050
|
-
else {
|
|
1051
|
-
modifiedContent = modifiedContent + '\n' + importStatement;
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
else {
|
|
1055
|
-
modifiedContent = importStatement + '\n' + modifiedContent;
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
// Add useLoaderData import - find the last import and add after it
|
|
1059
|
-
if (!content.includes('useLoaderData')) {
|
|
1060
|
-
const lastImportIndex = modifiedContent.lastIndexOf('import');
|
|
1061
|
-
if (lastImportIndex !== -1) {
|
|
1062
|
-
const nextLineIndex = modifiedContent.indexOf('\n', lastImportIndex);
|
|
1063
|
-
if (nextLineIndex !== -1) {
|
|
1064
|
-
modifiedContent = modifiedContent.slice(0, nextLineIndex + 1) +
|
|
1065
|
-
useLoaderDataImport + '\n' +
|
|
1066
|
-
modifiedContent.slice(nextLineIndex + 1);
|
|
1067
|
-
}
|
|
1068
|
-
else {
|
|
1069
|
-
modifiedContent = modifiedContent + '\n' + useLoaderDataImport;
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
else {
|
|
1073
|
-
modifiedContent = useLoaderDataImport + '\n' + modifiedContent;
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
// Add loader function before the App component
|
|
1077
|
-
if (!content.includes('export const loader')) {
|
|
1078
|
-
modifiedContent = modifiedContent.replace(/export default function App\(\)/, `export const loader = createHumanBehaviorLoader();
|
|
1079
|
-
|
|
1080
|
-
export default function App()`);
|
|
1081
|
-
}
|
|
1082
|
-
// Wrap the App component content with HumanBehaviorProvider
|
|
1083
|
-
modifiedContent = modifiedContent.replace(/export default function App\(\) \{[\s\S]*?return \(([\s\S]*?)\);[\s\S]*?\}/, `export default function App() {
|
|
1084
|
-
const data = useLoaderData<typeof loader>();
|
|
1085
|
-
|
|
1086
|
-
return (
|
|
1087
|
-
<HumanBehaviorProvider apiKey={data.ENV.HUMANBEHAVIOR_API_KEY}>
|
|
1088
|
-
$1
|
|
1089
|
-
</HumanBehaviorProvider>
|
|
1090
|
-
);
|
|
1091
|
-
}`);
|
|
1092
|
-
return modifiedContent;
|
|
1093
|
-
}
|
|
1094
|
-
injectVuePlugin(content) {
|
|
1095
|
-
var _a, _b;
|
|
1096
|
-
if (content.includes('HumanBehaviorPlugin')) {
|
|
1097
|
-
return content;
|
|
1098
|
-
}
|
|
1099
|
-
const importStatement = `import { HumanBehaviorPlugin } from 'humanbehavior-js/vue';`;
|
|
1100
|
-
// Enhanced Vue 3 support with version detection
|
|
1101
|
-
const hasVue3 = (_b = (_a = this.framework) === null || _a === void 0 ? void 0 : _a.features) === null || _b === void 0 ? void 0 : _b.hasVue3;
|
|
1102
|
-
if (hasVue3) {
|
|
1103
|
-
// Vue 3 with Composition API
|
|
1104
|
-
const pluginUsage = `app.use(HumanBehaviorPlugin, {
|
|
1105
|
-
apiKey: import.meta.env.VITE_HUMANBEHAVIOR_API_KEY
|
|
1106
|
-
});`;
|
|
1107
|
-
let modifiedContent = content;
|
|
1108
|
-
// Add import statement
|
|
1109
|
-
if (!content.includes(importStatement)) {
|
|
1110
|
-
modifiedContent = content.replace(/(import.*?from.*?['"]vue['"];?)/, `$1\n${importStatement}`);
|
|
1111
|
-
// If no Vue import found, add it at the top
|
|
1112
|
-
if (!modifiedContent.includes(importStatement)) {
|
|
1113
|
-
modifiedContent = `${importStatement}\n\n${modifiedContent}`;
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
// Handle createApp pattern
|
|
1117
|
-
if (content.includes('createApp')) {
|
|
1118
|
-
modifiedContent = modifiedContent.replace(/(app\.mount\(.*?\))/, `${pluginUsage}\n\n$1`);
|
|
1119
|
-
}
|
|
1120
|
-
return modifiedContent;
|
|
1121
|
-
}
|
|
1122
|
-
else {
|
|
1123
|
-
// Vue 2 with Options API
|
|
1124
|
-
const pluginUsage = `Vue.use(HumanBehaviorPlugin, {
|
|
1125
|
-
apiKey: process.env.VUE_APP_HUMANBEHAVIOR_API_KEY
|
|
1126
|
-
});`;
|
|
1127
|
-
let modifiedContent = content;
|
|
1128
|
-
// Add import statement
|
|
1129
|
-
if (!content.includes(importStatement)) {
|
|
1130
|
-
modifiedContent = content.replace(/(import.*?from.*?['"]vue['"];?)/, `$1\n${importStatement}`);
|
|
1131
|
-
if (!modifiedContent.includes(importStatement)) {
|
|
1132
|
-
modifiedContent = `${importStatement}\n\n${modifiedContent}`;
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
// Handle new Vue pattern
|
|
1136
|
-
if (content.includes('new Vue')) {
|
|
1137
|
-
modifiedContent = modifiedContent.replace(/(new Vue\(.*?\))/, `${pluginUsage}\n\n$1`);
|
|
1138
|
-
}
|
|
1139
|
-
return modifiedContent;
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
injectAngularModule(content) {
|
|
1143
|
-
if (content.includes('HumanBehaviorModule')) {
|
|
1144
|
-
return content;
|
|
1145
|
-
}
|
|
1146
|
-
const importStatement = `import { HumanBehaviorModule } from 'humanbehavior-js/angular';`;
|
|
1147
|
-
const environmentImport = `import { environment } from '../environments/environment';`;
|
|
1148
|
-
// Add environment import if not present
|
|
1149
|
-
let modifiedContent = content;
|
|
1150
|
-
if (!content.includes('environment')) {
|
|
1151
|
-
modifiedContent = content.replace(/import.*from.*['"]@angular/, `${environmentImport}\n$&`);
|
|
1152
|
-
}
|
|
1153
|
-
return modifiedContent.replace(/imports:\s*\[([\s\S]*?)\]/, `imports: [
|
|
1154
|
-
$1,
|
|
1155
|
-
HumanBehaviorModule.forRoot({
|
|
1156
|
-
apiKey: environment.humanBehaviorApiKey
|
|
1157
|
-
})
|
|
1158
|
-
]`).replace(/import.*from.*['"]@angular/, `$&\n${importStatement}`);
|
|
1159
|
-
}
|
|
1160
|
-
injectAngularStandaloneInit(content) {
|
|
1161
|
-
if (content.includes('initializeHumanBehavior')) {
|
|
1162
|
-
return content;
|
|
1163
|
-
}
|
|
1164
|
-
const importStatement = `import { initializeHumanBehavior } from 'humanbehavior-js/angular';`;
|
|
1165
|
-
const environmentImport = `import { environment } from './environments/environment';`;
|
|
1166
|
-
// Add imports at the top
|
|
1167
|
-
let modifiedContent = content.replace(/import.*from.*['"]@angular/, `${importStatement}\n${environmentImport}\n$&`);
|
|
1168
|
-
// Add initialization after bootstrapApplication
|
|
1169
|
-
modifiedContent = modifiedContent.replace(/(bootstrapApplication\([^}]+\}?\)(?:\s*\.catch[^;]+;)?)/, `$1
|
|
1170
|
-
|
|
1171
|
-
// Initialize HumanBehavior SDK (client-side only)
|
|
1172
|
-
if (typeof window !== 'undefined') {
|
|
1173
|
-
const tracker = initializeHumanBehavior(environment.humanBehaviorApiKey);
|
|
1174
|
-
}`);
|
|
1175
|
-
return modifiedContent;
|
|
1176
|
-
}
|
|
1177
|
-
injectSvelteStore(content) {
|
|
1178
|
-
if (content.includes('humanBehaviorStore')) {
|
|
1179
|
-
return content;
|
|
1180
|
-
}
|
|
1181
|
-
const importStatement = `import { humanBehaviorStore } from 'humanbehavior-js/svelte';`;
|
|
1182
|
-
const initCode = `humanBehaviorStore.init(process.env.PUBLIC_HUMANBEHAVIOR_API_KEY || '');`;
|
|
1183
|
-
return `${importStatement}\n${initCode}\n\n${content}`;
|
|
1184
|
-
}
|
|
1185
|
-
injectSvelteKitLayout(content) {
|
|
1186
|
-
if (content.includes('humanBehaviorStore')) {
|
|
1187
|
-
return content;
|
|
1188
|
-
}
|
|
1189
|
-
const importStatement = `import { humanBehaviorStore } from 'humanbehavior-js/svelte';`;
|
|
1190
|
-
const envImport = `import { PUBLIC_HUMANBEHAVIOR_API_KEY } from '$env/static/public';`;
|
|
1191
|
-
const initCode = `humanBehaviorStore.init(PUBLIC_HUMANBEHAVIOR_API_KEY || '');`;
|
|
1192
|
-
// Add to script section - handle different script tag patterns
|
|
1193
|
-
if (content.includes('<script lang="ts">')) {
|
|
1194
|
-
return content.replace(/<script lang="ts">/, `<script lang="ts">\n\t${envImport}\n\t${importStatement}\n\t${initCode}`);
|
|
1195
|
-
}
|
|
1196
|
-
else if (content.includes('<script>')) {
|
|
1197
|
-
return content.replace(/<script>/, `<script>\n\t${envImport}\n\t${importStatement}\n\t${initCode}`);
|
|
1198
|
-
}
|
|
1199
|
-
else if (content.includes('<script context="module">')) {
|
|
1200
|
-
return content.replace(/<script\s+context="module">/, `<script context="module">\n\t${envImport}\n\t${importStatement}\n\t${initCode}`);
|
|
1201
|
-
}
|
|
1202
|
-
else {
|
|
1203
|
-
// If no script tag found, add one at the beginning
|
|
1204
|
-
return content.replace(/<svelte:head>/, `<script lang="ts">\n\t${envImport}\n\t${importStatement}\n\t${initCode}\n</script>\n\n<svelte:head>`);
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
injectVanillaScript(content) {
|
|
1208
|
-
if (content.includes('humanbehavior-js')) {
|
|
1209
|
-
return content;
|
|
1210
|
-
}
|
|
1211
|
-
const cdnScript = `<script src="https://unpkg.com/humanbehavior-js@latest/dist/index.min.js"></script>`;
|
|
1212
|
-
const initScript = `<script>
|
|
1213
|
-
// Initialize HumanBehavior SDK
|
|
1214
|
-
// Note: For vanilla HTML, the API key must be hardcoded since env vars aren't available
|
|
1215
|
-
const tracker = HumanBehaviorTracker.init('${this.apiKey}');
|
|
1216
|
-
</script>`;
|
|
1217
|
-
return content.replace(/<\/head>/, ` ${cdnScript}\n ${initScript}\n</head>`);
|
|
1218
|
-
}
|
|
1219
|
-
/**
|
|
1220
|
-
* Inject Astro layout with HumanBehavior component
|
|
1221
|
-
*/
|
|
1222
|
-
injectAstroLayout(content) {
|
|
1223
|
-
// Check if HumanBehavior component is already imported
|
|
1224
|
-
if (content.includes('HumanBehavior') || content.includes('humanbehavior-js')) {
|
|
1225
|
-
return content; // Already has HumanBehavior
|
|
1226
|
-
}
|
|
1227
|
-
// Add import inside frontmatter if not present
|
|
1228
|
-
let modifiedContent = content;
|
|
1229
|
-
if (!content.includes('import HumanBehavior')) {
|
|
1230
|
-
const importStatement = 'import HumanBehavior from \'../components/HumanBehavior.astro\';';
|
|
1231
|
-
const frontmatterEndIndex = content.indexOf('---', 3);
|
|
1232
|
-
if (frontmatterEndIndex !== -1) {
|
|
1233
|
-
// Insert import inside frontmatter, before the closing ---
|
|
1234
|
-
modifiedContent = content.slice(0, frontmatterEndIndex) + '\n' + importStatement + '\n' + content.slice(frontmatterEndIndex);
|
|
1235
|
-
}
|
|
1236
|
-
else {
|
|
1237
|
-
// No frontmatter, add at the very beginning
|
|
1238
|
-
modifiedContent = '---\n' + importStatement + '\n---\n\n' + content;
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
// Find the closing </body> tag and add HumanBehavior component before it
|
|
1242
|
-
const bodyCloseIndex = modifiedContent.lastIndexOf('</body>');
|
|
1243
|
-
if (bodyCloseIndex === -1) {
|
|
1244
|
-
// No body tag found, append to end
|
|
1245
|
-
return modifiedContent + '\n\n<HumanBehavior />';
|
|
1246
|
-
}
|
|
1247
|
-
// Add component before closing body tag
|
|
1248
|
-
return modifiedContent.slice(0, bodyCloseIndex) + ' <HumanBehavior />\n' + modifiedContent.slice(bodyCloseIndex);
|
|
1249
|
-
}
|
|
1250
|
-
injectNuxtConfig(content) {
|
|
1251
|
-
var _a, _b;
|
|
1252
|
-
if (content.includes('humanBehaviorApiKey')) {
|
|
1253
|
-
return content;
|
|
1254
|
-
}
|
|
1255
|
-
// Enhanced Nuxt 3 support with version detection
|
|
1256
|
-
const hasNuxt3 = (_b = (_a = this.framework) === null || _a === void 0 ? void 0 : _a.features) === null || _b === void 0 ? void 0 : _b.hasNuxt3;
|
|
1257
|
-
if (hasNuxt3) {
|
|
1258
|
-
// Nuxt 3 with runtime config
|
|
1259
|
-
return content.replace(/export default defineNuxtConfig\(\{/, `export default defineNuxtConfig({
|
|
1260
|
-
runtimeConfig: {
|
|
1261
|
-
public: {
|
|
1262
|
-
humanBehaviorApiKey: process.env.NUXT_PUBLIC_HUMANBEHAVIOR_API_KEY
|
|
1263
|
-
}
|
|
1264
|
-
},`);
|
|
1265
|
-
}
|
|
1266
|
-
else {
|
|
1267
|
-
// Nuxt 2 with env config
|
|
1268
|
-
return content.replace(/export default \{/, `export default {
|
|
1269
|
-
env: {
|
|
1270
|
-
humanBehaviorApiKey: process.env.HUMANBEHAVIOR_API_KEY
|
|
1271
|
-
},`);
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
injectGatsbyLayout(content) {
|
|
1275
|
-
if (content.includes('HumanBehavior')) {
|
|
1276
|
-
return content;
|
|
1277
|
-
}
|
|
1278
|
-
const importStatement = `import HumanBehavior from './HumanBehavior';`;
|
|
1279
|
-
const componentUsage = `<HumanBehavior apiKey={process.env.GATSBY_HUMANBEHAVIOR_API_KEY || ''} />`;
|
|
1280
|
-
// Add import at the top
|
|
1281
|
-
let modifiedContent = content.replace(/import.*from.*['"]\./, `${importStatement}\n$&`);
|
|
1282
|
-
// Add component before closing body tag
|
|
1283
|
-
modifiedContent = modifiedContent.replace(/(\s*<\/body>)/, `\n ${componentUsage}\n$1`);
|
|
1284
|
-
return modifiedContent;
|
|
1285
|
-
}
|
|
1286
|
-
injectGatsbyBrowser(content) {
|
|
1287
|
-
if (content.includes('HumanBehaviorTracker')) {
|
|
1288
|
-
return content;
|
|
1289
|
-
}
|
|
1290
|
-
const importStatement = `import { HumanBehaviorTracker } from 'humanbehavior-js';`;
|
|
1291
|
-
const initCode = `
|
|
1292
|
-
// Initialize HumanBehavior SDK
|
|
1293
|
-
export const onClientEntry = () => {
|
|
1294
|
-
console.log('Gatsby browser entry point loaded');
|
|
1295
|
-
const apiKey = process.env.GATSBY_HUMANBEHAVIOR_API_KEY;
|
|
1296
|
-
console.log('API Key found:', apiKey ? 'Yes' : 'No');
|
|
1297
|
-
if (apiKey) {
|
|
1298
|
-
const tracker = HumanBehaviorTracker.init(apiKey);
|
|
1299
|
-
console.log('HumanBehavior SDK initialized for Gatsby');
|
|
1300
|
-
} else {
|
|
1301
|
-
console.log('No API key found in environment variables');
|
|
1302
|
-
}
|
|
1303
|
-
};`;
|
|
1304
|
-
// If the file already has content, add the import and init code
|
|
1305
|
-
if (content.trim()) {
|
|
1306
|
-
return `${importStatement}${initCode}\n\n${content}`;
|
|
1307
|
-
}
|
|
1308
|
-
else {
|
|
1309
|
-
// If file is empty, just return the new content
|
|
1310
|
-
return `${importStatement}${initCode}`;
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
/**
|
|
1314
|
-
* Helper method to find the best environment file for a framework
|
|
1315
|
-
*/
|
|
1316
|
-
findBestEnvFile(framework) {
|
|
1317
|
-
const possibleEnvFiles = [
|
|
1318
|
-
'.env.local',
|
|
1319
|
-
'.env.development.local',
|
|
1320
|
-
'.env.development',
|
|
1321
|
-
'.env.local.development',
|
|
1322
|
-
'.env',
|
|
1323
|
-
'.env.production',
|
|
1324
|
-
'.env.staging'
|
|
1325
|
-
];
|
|
1326
|
-
// Framework-specific environment variable names
|
|
1327
|
-
const getEnvVarName = (framework) => {
|
|
1328
|
-
// Handle React+Vite specifically
|
|
1329
|
-
if (framework.type === 'react' && framework.bundler === 'vite') {
|
|
1330
|
-
return 'VITE_HUMANBEHAVIOR_API_KEY';
|
|
1331
|
-
}
|
|
1332
|
-
// Framework-specific mappings
|
|
1333
|
-
const envVarNames = {
|
|
1334
|
-
react: 'HUMANBEHAVIOR_API_KEY',
|
|
1335
|
-
nextjs: 'NEXT_PUBLIC_HUMANBEHAVIOR_API_KEY',
|
|
1336
|
-
vue: 'VITE_HUMANBEHAVIOR_API_KEY',
|
|
1337
|
-
svelte: 'PUBLIC_HUMANBEHAVIOR_API_KEY',
|
|
1338
|
-
angular: 'HUMANBEHAVIOR_API_KEY',
|
|
1339
|
-
nuxt: 'NUXT_PUBLIC_HUMANBEHAVIOR_API_KEY',
|
|
1340
|
-
remix: 'HUMANBEHAVIOR_API_KEY',
|
|
1341
|
-
vanilla: 'HUMANBEHAVIOR_API_KEY',
|
|
1342
|
-
astro: 'PUBLIC_HUMANBEHAVIOR_API_KEY',
|
|
1343
|
-
gatsby: 'GATSBY_HUMANBEHAVIOR_API_KEY',
|
|
1344
|
-
node: 'HUMANBEHAVIOR_API_KEY',
|
|
1345
|
-
auto: 'HUMANBEHAVIOR_API_KEY'
|
|
1346
|
-
};
|
|
1347
|
-
return envVarNames[framework.type] || 'HUMANBEHAVIOR_API_KEY';
|
|
1348
|
-
};
|
|
1349
|
-
const envVarName = getEnvVarName(framework);
|
|
1350
|
-
// Check for existing files
|
|
1351
|
-
for (const envFile of possibleEnvFiles) {
|
|
1352
|
-
const fullPath = path__namespace.join(this.projectRoot, envFile);
|
|
1353
|
-
if (fs__namespace.existsSync(fullPath)) {
|
|
1354
|
-
return { filePath: fullPath, envVarName };
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
// Framework-specific default file creation
|
|
1358
|
-
const defaultFiles = {
|
|
1359
|
-
react: '.env.local',
|
|
1360
|
-
nextjs: '.env.local',
|
|
1361
|
-
vue: '.env.local',
|
|
1362
|
-
svelte: '.env',
|
|
1363
|
-
angular: '.env',
|
|
1364
|
-
nuxt: '.env',
|
|
1365
|
-
remix: '.env.local',
|
|
1366
|
-
vanilla: '.env',
|
|
1367
|
-
astro: '.env',
|
|
1368
|
-
gatsby: '.env.development',
|
|
1369
|
-
node: '.env',
|
|
1370
|
-
auto: '.env'
|
|
1371
|
-
};
|
|
1372
|
-
const defaultFile = defaultFiles[framework.type] || '.env';
|
|
1373
|
-
return {
|
|
1374
|
-
filePath: path__namespace.join(this.projectRoot, defaultFile),
|
|
1375
|
-
envVarName
|
|
1376
|
-
};
|
|
1377
|
-
}
|
|
1378
|
-
/**
|
|
1379
|
-
* Helper method to create or append to environment files
|
|
1380
|
-
*/
|
|
1381
|
-
createEnvironmentModification(framework) {
|
|
1382
|
-
const { filePath, envVarName } = this.findBestEnvFile(framework);
|
|
1383
|
-
// Clean the API key to prevent formatting issues
|
|
1384
|
-
const cleanApiKey = this.apiKey.trim();
|
|
1385
|
-
if (fs__namespace.existsSync(filePath)) {
|
|
1386
|
-
// Check if the variable already exists
|
|
1387
|
-
const content = fs__namespace.readFileSync(filePath, 'utf8');
|
|
1388
|
-
if (content.includes(envVarName)) {
|
|
1389
|
-
// Variable exists, don't modify
|
|
1390
|
-
return {
|
|
1391
|
-
filePath,
|
|
1392
|
-
action: 'modify',
|
|
1393
|
-
content: content, // No change
|
|
1394
|
-
description: `API key already exists in ${path__namespace.basename(filePath)}`
|
|
1395
|
-
};
|
|
1396
|
-
}
|
|
1397
|
-
else {
|
|
1398
|
-
// Append to existing file
|
|
1399
|
-
return {
|
|
1400
|
-
filePath,
|
|
1401
|
-
action: 'append',
|
|
1402
|
-
content: `\n${envVarName}=${cleanApiKey}`,
|
|
1403
|
-
description: `Added API key to existing ${path__namespace.basename(filePath)}`
|
|
1404
|
-
};
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
else {
|
|
1408
|
-
// Create new file
|
|
1409
|
-
return {
|
|
1410
|
-
filePath,
|
|
1411
|
-
action: 'create',
|
|
1412
|
-
content: `${envVarName}=${cleanApiKey}`,
|
|
1413
|
-
description: `Created ${path__namespace.basename(filePath)} with API key`
|
|
1414
|
-
};
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
/**
|
|
1420
|
-
* AI-Enhanced HumanBehavior SDK Auto-Installation Wizard
|
|
1421
|
-
*
|
|
1422
|
-
* This wizard uses AI to intelligently detect frameworks, analyze code patterns,
|
|
1423
|
-
* and generate optimal integration code that's both future-proof and backward-compatible.
|
|
1424
|
-
*
|
|
1425
|
-
* 🚀 KEY FEATURES:
|
|
1426
|
-
* - AI-powered framework detection beyond package.json
|
|
1427
|
-
* - Intelligent code pattern analysis
|
|
1428
|
-
* - Future-proof integration strategies
|
|
1429
|
-
* - Backward compatibility with legacy frameworks
|
|
1430
|
-
* - Adaptive code generation for new frameworks
|
|
1431
|
-
* - Smart conflict resolution
|
|
1432
|
-
* - Learning from user feedback
|
|
1433
|
-
* - Centralized AI service (no user API keys required)
|
|
1434
|
-
*/
|
|
1435
|
-
/**
|
|
1436
|
-
* Default AI Service Implementation
|
|
1437
|
-
* Uses heuristic analysis when centralized service is not available
|
|
1438
|
-
*/
|
|
1439
|
-
class DefaultAIService {
|
|
1440
|
-
analyzeCodePatterns(codeSamples) {
|
|
1441
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1442
|
-
return this.analyzeWithHeuristics(codeSamples);
|
|
1443
|
-
});
|
|
1444
|
-
}
|
|
1445
|
-
resolveConflicts(conflicts, framework) {
|
|
1446
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1447
|
-
// Default conflict resolution strategies
|
|
1448
|
-
const resolutions = [];
|
|
1449
|
-
for (const conflict of conflicts) {
|
|
1450
|
-
switch (conflict) {
|
|
1451
|
-
case 'existing_humanbehavior_code':
|
|
1452
|
-
resolutions.push('update_existing_integration');
|
|
1453
|
-
break;
|
|
1454
|
-
case 'existing_provider':
|
|
1455
|
-
resolutions.push('merge_providers');
|
|
1456
|
-
break;
|
|
1457
|
-
case 'module_system_conflict':
|
|
1458
|
-
resolutions.push('hybrid_module_support');
|
|
1459
|
-
break;
|
|
1460
|
-
default:
|
|
1461
|
-
resolutions.push('skip_conflict');
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
return resolutions;
|
|
1465
|
-
});
|
|
1466
|
-
}
|
|
1467
|
-
generateOptimizations(framework, patterns) {
|
|
1468
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1469
|
-
const optimizations = [];
|
|
1470
|
-
// Framework-specific optimizations
|
|
1471
|
-
switch (framework.type) {
|
|
1472
|
-
case 'react':
|
|
1473
|
-
optimizations.push('Use React.memo for performance optimization');
|
|
1474
|
-
optimizations.push('Implement error boundaries for better error tracking');
|
|
1475
|
-
optimizations.push('Consider using React.lazy for code splitting');
|
|
1476
|
-
break;
|
|
1477
|
-
case 'vue':
|
|
1478
|
-
optimizations.push('Use Vue 3 Composition API for better performance');
|
|
1479
|
-
optimizations.push('Implement proper error handling in components');
|
|
1480
|
-
optimizations.push('Consider using Vue Router for navigation tracking');
|
|
1481
|
-
break;
|
|
1482
|
-
case 'angular':
|
|
1483
|
-
optimizations.push('Use Angular standalone components for better tree-shaking');
|
|
1484
|
-
optimizations.push('Implement proper error handling with ErrorHandler');
|
|
1485
|
-
optimizations.push('Consider using Angular signals for state management');
|
|
1486
|
-
break;
|
|
1487
|
-
default:
|
|
1488
|
-
optimizations.push('Enable performance tracking');
|
|
1489
|
-
optimizations.push('Implement error tracking');
|
|
1490
|
-
optimizations.push('Consider progressive enhancement');
|
|
1491
|
-
}
|
|
1492
|
-
return optimizations;
|
|
1493
|
-
});
|
|
1494
|
-
}
|
|
1495
|
-
analyzeWithHeuristics(codeSamples) {
|
|
1496
|
-
const patterns = codeSamples.join(' ').toLowerCase();
|
|
1497
|
-
// Framework detection
|
|
1498
|
-
let framework = { name: 'vanilla', type: 'vanilla' };
|
|
1499
|
-
let confidence = 0.5;
|
|
1500
|
-
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')) {
|
|
1501
|
-
framework = { name: 'nuxt', type: 'nuxt' };
|
|
1502
|
-
confidence = 0.95;
|
|
1503
|
-
}
|
|
1504
|
-
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/')) {
|
|
1505
|
-
framework = { name: 'nextjs', type: 'nextjs' };
|
|
1506
|
-
confidence = 0.95;
|
|
1507
|
-
}
|
|
1508
|
-
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')) {
|
|
1509
|
-
framework = { name: 'gatsby', type: 'gatsby' };
|
|
1510
|
-
confidence = 0.95;
|
|
1511
|
-
}
|
|
1512
|
-
else if (patterns.includes('react')) {
|
|
1513
|
-
framework = { name: 'react', type: 'react' };
|
|
1514
|
-
confidence = 0.9;
|
|
1515
|
-
}
|
|
1516
|
-
else if (patterns.includes('vue')) {
|
|
1517
|
-
framework = { name: 'vue', type: 'vue' };
|
|
1518
|
-
confidence = 0.9;
|
|
1519
|
-
}
|
|
1520
|
-
else if (patterns.includes('angular')) {
|
|
1521
|
-
framework = { name: 'angular', type: 'angular' };
|
|
1522
|
-
confidence = 0.9;
|
|
1523
|
-
}
|
|
1524
|
-
else if (patterns.includes('svelte')) {
|
|
1525
|
-
framework = { name: 'svelte', type: 'svelte' };
|
|
1526
|
-
confidence = 0.9;
|
|
1527
|
-
}
|
|
1528
|
-
// Integration strategy
|
|
1529
|
-
let integrationStrategy = 'script';
|
|
1530
|
-
if (framework.type === 'react' || framework.type === 'nextjs' || framework.type === 'gatsby') {
|
|
1531
|
-
integrationStrategy = 'provider';
|
|
1532
|
-
}
|
|
1533
|
-
else if (framework.type === 'vue') {
|
|
1534
|
-
integrationStrategy = 'plugin';
|
|
1535
|
-
}
|
|
1536
|
-
else if (framework.type === 'angular') {
|
|
1537
|
-
integrationStrategy = 'module';
|
|
1538
|
-
}
|
|
1539
|
-
// Compatibility mode
|
|
1540
|
-
let compatibilityMode = 'modern';
|
|
1541
|
-
if (patterns.includes('require(') || patterns.includes('var ')) {
|
|
1542
|
-
compatibilityMode = 'legacy';
|
|
1543
|
-
}
|
|
1544
|
-
return {
|
|
1545
|
-
framework,
|
|
1546
|
-
confidence,
|
|
1547
|
-
patterns: codeSamples,
|
|
1548
|
-
conflicts: [],
|
|
1549
|
-
recommendations: [],
|
|
1550
|
-
integrationStrategy,
|
|
1551
|
-
compatibilityMode
|
|
1552
|
-
};
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
class AIEnhancedInstallationWizard extends AutoInstallationWizard {
|
|
1556
|
-
constructor(apiKey, projectRoot = process.cwd(), aiService) {
|
|
1557
|
-
super(apiKey, projectRoot);
|
|
1558
|
-
this.learningCache = new Map();
|
|
1559
|
-
this.patternDatabase = new Map();
|
|
1560
|
-
this.aiService = aiService || new DefaultAIService();
|
|
1561
|
-
this.loadLearningData();
|
|
1562
|
-
}
|
|
1563
|
-
/**
|
|
1564
|
-
* AI-enhanced installation with intelligent analysis
|
|
1565
|
-
*/
|
|
1566
|
-
install() {
|
|
1567
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1568
|
-
try {
|
|
1569
|
-
// Step 1: AI-powered framework detection
|
|
1570
|
-
const aiAnalysis = yield this.performAICodeAnalysis();
|
|
1571
|
-
// Step 2: Smart framework detection with AI validation
|
|
1572
|
-
this.framework = yield this.detectFrameworkWithAI(aiAnalysis);
|
|
1573
|
-
// Step 3: Generate AI-optimized modifications
|
|
1574
|
-
const modifications = yield this.generateAIOptimizedModifications(aiAnalysis);
|
|
1575
|
-
// Step 4: Apply modifications with conflict resolution
|
|
1576
|
-
yield this.applyModificationsWithAI(modifications, aiAnalysis);
|
|
1577
|
-
// Step 5: Generate intelligent next steps
|
|
1578
|
-
const nextSteps = this.generateAINextSteps(aiAnalysis);
|
|
1579
|
-
// Step 6: Learn from this installation
|
|
1580
|
-
yield this.learnFromInstallation(aiAnalysis, modifications);
|
|
1581
|
-
return {
|
|
1582
|
-
success: true,
|
|
1583
|
-
framework: this.framework,
|
|
1584
|
-
modifications,
|
|
1585
|
-
errors: [],
|
|
1586
|
-
nextSteps,
|
|
1587
|
-
aiAnalysis,
|
|
1588
|
-
learningData: {
|
|
1589
|
-
patterns: aiAnalysis.patterns,
|
|
1590
|
-
framework: this.framework.name,
|
|
1591
|
-
success: true
|
|
1592
|
-
}
|
|
1593
|
-
};
|
|
1594
|
-
}
|
|
1595
|
-
catch (error) {
|
|
1596
|
-
return {
|
|
1597
|
-
success: false,
|
|
1598
|
-
framework: this.framework || { name: 'unknown', type: 'vanilla' },
|
|
1599
|
-
modifications: [],
|
|
1600
|
-
errors: [error instanceof Error ? error.message : 'Unknown error'],
|
|
1601
|
-
nextSteps: [],
|
|
1602
|
-
aiAnalysis: {
|
|
1603
|
-
framework: { name: 'unknown', type: 'vanilla' },
|
|
1604
|
-
confidence: 0,
|
|
1605
|
-
patterns: [],
|
|
1606
|
-
conflicts: [],
|
|
1607
|
-
recommendations: [],
|
|
1608
|
-
integrationStrategy: 'script',
|
|
1609
|
-
compatibilityMode: 'legacy'
|
|
1610
|
-
},
|
|
1611
|
-
learningData: {
|
|
1612
|
-
patterns: [],
|
|
1613
|
-
framework: 'unknown',
|
|
1614
|
-
success: false
|
|
1615
|
-
}
|
|
1616
|
-
};
|
|
1617
|
-
}
|
|
1618
|
-
});
|
|
1619
|
-
}
|
|
1620
|
-
/**
|
|
1621
|
-
* AI-powered code analysis using centralized service
|
|
1622
|
-
*/
|
|
1623
|
-
performAICodeAnalysis() {
|
|
1624
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1625
|
-
const projectFiles = yield this.scanProjectFiles();
|
|
1626
|
-
const codeSamples = yield this.extractCodeSamples(projectFiles);
|
|
1627
|
-
// Use centralized AI service (no user API key required)
|
|
1628
|
-
return yield this.aiService.analyzeCodePatterns(codeSamples);
|
|
1629
|
-
});
|
|
1630
|
-
}
|
|
1631
|
-
/**
|
|
1632
|
-
* Scan project files for analysis
|
|
1633
|
-
*/
|
|
1634
|
-
scanProjectFiles() {
|
|
1635
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1636
|
-
const files = [];
|
|
1637
|
-
const scanDir = (dir, depth = 0) => {
|
|
1638
|
-
if (depth > 3)
|
|
1639
|
-
return; // Limit depth
|
|
1640
|
-
try {
|
|
1641
|
-
const items = fs__namespace.readdirSync(dir);
|
|
1642
|
-
for (const item of items) {
|
|
1643
|
-
const fullPath = path__namespace.join(dir, item);
|
|
1644
|
-
const stat = fs__namespace.statSync(fullPath);
|
|
1645
|
-
if (stat.isDirectory() && !item.startsWith('.') && item !== 'node_modules') {
|
|
1646
|
-
scanDir(fullPath, depth + 1);
|
|
1647
|
-
}
|
|
1648
|
-
else if (stat.isFile() && this.isRelevantFile(item)) {
|
|
1649
|
-
files.push(fullPath);
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
catch (error) {
|
|
1654
|
-
// Skip inaccessible directories
|
|
1655
|
-
}
|
|
1656
|
-
};
|
|
1657
|
-
scanDir(this.projectRoot);
|
|
1658
|
-
return files;
|
|
1659
|
-
});
|
|
1660
|
-
}
|
|
1661
|
-
/**
|
|
1662
|
-
* Check if file is relevant for analysis
|
|
1663
|
-
*/
|
|
1664
|
-
isRelevantFile(filename) {
|
|
1665
|
-
const relevantExtensions = [
|
|
1666
|
-
'.js', '.jsx', '.ts', '.tsx', '.vue', '.svelte', '.html',
|
|
1667
|
-
'.json', '.config.js', '.config.ts', '.babelrc', '.eslintrc'
|
|
1668
|
-
];
|
|
1669
|
-
const relevantNames = [
|
|
1670
|
-
'package.json', 'tsconfig.json', 'vite.config', 'webpack.config',
|
|
1671
|
-
'next.config', 'nuxt.config', 'angular.json', 'svelte.config',
|
|
1672
|
-
'app/layout', 'app/page', 'pages/index', 'pages/_app', 'pages/_document'
|
|
1673
|
-
];
|
|
1674
|
-
return relevantExtensions.some(ext => filename.endsWith(ext)) ||
|
|
1675
|
-
relevantNames.some(name => filename.includes(name));
|
|
1676
|
-
}
|
|
1677
|
-
/**
|
|
1678
|
-
* Extract code samples for AI analysis
|
|
1679
|
-
*/
|
|
1680
|
-
extractCodeSamples(files) {
|
|
1681
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1682
|
-
const samples = [];
|
|
1683
|
-
for (const file of files.slice(0, 20)) { // Limit to 20 files
|
|
1684
|
-
try {
|
|
1685
|
-
const content = fs__namespace.readFileSync(file, 'utf8');
|
|
1686
|
-
const relativePath = path__namespace.relative(this.projectRoot, file);
|
|
1687
|
-
// Extract relevant code patterns
|
|
1688
|
-
const patterns = this.extractCodePatterns(content);
|
|
1689
|
-
if (patterns.length > 0) {
|
|
1690
|
-
samples.push(`File: ${relativePath}\n${patterns.join('\n')}`);
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
|
-
catch (error) {
|
|
1694
|
-
// Skip unreadable files
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
return samples;
|
|
1698
|
-
});
|
|
1699
|
-
}
|
|
1700
|
-
/**
|
|
1701
|
-
* Extract relevant code patterns
|
|
1702
|
-
*/
|
|
1703
|
-
extractCodePatterns(content) {
|
|
1704
|
-
const patterns = [];
|
|
1705
|
-
// Framework-specific patterns
|
|
1706
|
-
const frameworkPatterns = {
|
|
1707
|
-
react: [
|
|
1708
|
-
/import\s+React\s+from\s+['"]react['"]/gi,
|
|
1709
|
-
/from\s+['"]react['"]/gi,
|
|
1710
|
-
/function\s+\w+\s*\(\s*\)\s*{/gi,
|
|
1711
|
-
/const\s+\w+\s*=\s*\(\s*\)\s*=>\s*{/gi
|
|
1712
|
-
],
|
|
1713
|
-
vue: [
|
|
1714
|
-
/import\s+{\s*createApp\s*}\s+from\s+['"]vue['"]/gi,
|
|
1715
|
-
/from\s+['"]vue['"]/gi,
|
|
1716
|
-
/<template>/gi,
|
|
1717
|
-
/<script\s+setup>/gi
|
|
1718
|
-
],
|
|
1719
|
-
angular: [
|
|
1720
|
-
/import\s+{\s*Component\s*}\s+from\s+['"]@angular\/core['"]/gi,
|
|
1721
|
-
/@Component\s*\(\s*{/gi,
|
|
1722
|
-
/from\s+['"]@angular/gi
|
|
1723
|
-
],
|
|
1724
|
-
svelte: [
|
|
1725
|
-
/<script>/gi,
|
|
1726
|
-
/import\s+.*\s+from\s+['"]svelte/gi,
|
|
1727
|
-
/from\s+['"]svelte/gi
|
|
1728
|
-
],
|
|
1729
|
-
nextjs: [
|
|
1730
|
-
/import\s+.*\s+from\s+['"]next/gi,
|
|
1731
|
-
/from\s+['"]next/gi,
|
|
1732
|
-
/export\s+default\s+function\s+Page/gi,
|
|
1733
|
-
/export\s+default\s+function\s+Layout/gi,
|
|
1734
|
-
/export\s+default\s+function\s+Loading/gi,
|
|
1735
|
-
/export\s+default\s+function\s+Error/gi,
|
|
1736
|
-
/export\s+default\s+function\s+Not-found/gi,
|
|
1737
|
-
/useRouter\s+from\s+['"]next\/navigation['"]/gi,
|
|
1738
|
-
/useRouter\s+from\s+['"]next\/router['"]/gi,
|
|
1739
|
-
/Link\s+from\s+['"]next\/link['"]/gi,
|
|
1740
|
-
/Image\s+from\s+['"]next\/image['"]/gi,
|
|
1741
|
-
/getServerSideProps/gi,
|
|
1742
|
-
/getStaticProps/gi,
|
|
1743
|
-
/getStaticPaths/gi,
|
|
1744
|
-
/next\.config/gi,
|
|
1745
|
-
/app\/layout\.tsx/gi,
|
|
1746
|
-
/app\/page\.tsx/gi,
|
|
1747
|
-
/pages\/.*\.tsx/gi,
|
|
1748
|
-
/pages\/.*\.jsx/gi,
|
|
1749
|
-
/pages\/.*\.ts/gi,
|
|
1750
|
-
/pages\/.*\.js/gi
|
|
1751
|
-
],
|
|
1752
|
-
nuxt: [
|
|
1753
|
-
/import\s+.*\s+from\s+['"]nuxt/gi,
|
|
1754
|
-
/from\s+['"]nuxt/gi,
|
|
1755
|
-
/export\s+default\s+defineNuxtConfig/gi,
|
|
1756
|
-
/defineNuxtConfig/gi,
|
|
1757
|
-
/nuxt\.config\.ts/gi,
|
|
1758
|
-
/nuxt\.config\.js/gi,
|
|
1759
|
-
/@nuxt\//gi,
|
|
1760
|
-
/#app/gi,
|
|
1761
|
-
/useNuxtApp/gi,
|
|
1762
|
-
/useRuntimeConfig/gi,
|
|
1763
|
-
/useSeoMeta/gi,
|
|
1764
|
-
/useHead/gi,
|
|
1765
|
-
/useLazyFetch/gi,
|
|
1766
|
-
/useFetch/gi,
|
|
1767
|
-
/useAsyncData/gi,
|
|
1768
|
-
/<NuxtLayout/gi,
|
|
1769
|
-
/<NuxtPage/gi,
|
|
1770
|
-
/NuxtLayout/gi,
|
|
1771
|
-
/NuxtPage/gi,
|
|
1772
|
-
/pages\/.*\.vue/gi,
|
|
1773
|
-
/layouts\/.*\.vue/gi,
|
|
1774
|
-
/components\/.*\.vue/gi,
|
|
1775
|
-
/composables\/.*\.ts/gi,
|
|
1776
|
-
/middleware\/.*\.ts/gi,
|
|
1777
|
-
/server\/.*\.ts/gi,
|
|
1778
|
-
/plugins\/.*\.ts/gi,
|
|
1779
|
-
/public\//gi,
|
|
1780
|
-
/assets\//gi,
|
|
1781
|
-
/content\//gi
|
|
1782
|
-
]
|
|
1783
|
-
};
|
|
1784
|
-
// Extract patterns for each framework
|
|
1785
|
-
for (const [framework, regexes] of Object.entries(frameworkPatterns)) {
|
|
1786
|
-
for (const regex of regexes) {
|
|
1787
|
-
const matches = content.match(regex);
|
|
1788
|
-
if (matches) {
|
|
1789
|
-
// Add raw patterns for heuristic analysis
|
|
1790
|
-
patterns.push(...matches.slice(0, 3));
|
|
1791
|
-
// Also add formatted patterns for debugging
|
|
1792
|
-
patterns.push(`${framework.toUpperCase()}: ${matches.slice(0, 3).join(', ')}`);
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
}
|
|
1796
|
-
// Extract import patterns
|
|
1797
|
-
const importMatches = content.match(/import\s+.*\s+from\s+['"][^'"]+['"]/gi);
|
|
1798
|
-
if (importMatches) {
|
|
1799
|
-
patterns.push(`IMPORTS: ${importMatches.slice(0, 5).join(', ')}`);
|
|
1800
|
-
}
|
|
1801
|
-
// Extract export patterns
|
|
1802
|
-
const exportMatches = content.match(/export\s+.*/gi);
|
|
1803
|
-
if (exportMatches) {
|
|
1804
|
-
patterns.push(`EXPORTS: ${exportMatches.slice(0, 3).join(', ')}`);
|
|
1805
|
-
}
|
|
1806
|
-
return patterns;
|
|
1807
|
-
}
|
|
1808
|
-
/**
|
|
1809
|
-
* AI-enhanced framework detection
|
|
1810
|
-
*/
|
|
1811
|
-
detectFrameworkWithAI(aiAnalysis) {
|
|
1812
|
-
const _super = Object.create(null, {
|
|
1813
|
-
detectFramework: { get: () => super.detectFramework }
|
|
1814
|
-
});
|
|
1815
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1816
|
-
// Combine AI analysis with traditional detection
|
|
1817
|
-
const traditionalFramework = yield _super.detectFramework.call(this);
|
|
1818
|
-
// Use AI analysis if confidence is high, but preserve bundler info
|
|
1819
|
-
if (aiAnalysis.confidence > 0.8) {
|
|
1820
|
-
return Object.assign(Object.assign({}, aiAnalysis.framework), { bundler: traditionalFramework.bundler, packageManager: traditionalFramework.packageManager, hasTypeScript: traditionalFramework.hasTypeScript, hasRouter: traditionalFramework.hasRouter, projectRoot: this.projectRoot });
|
|
1821
|
-
}
|
|
1822
|
-
// Merge AI insights with traditional detection
|
|
1823
|
-
return Object.assign(Object.assign({}, traditionalFramework), (aiAnalysis.framework.type !== 'vanilla' && {
|
|
1824
|
-
type: aiAnalysis.framework.type,
|
|
1825
|
-
name: aiAnalysis.framework.name
|
|
1826
|
-
}));
|
|
1827
|
-
});
|
|
1828
|
-
}
|
|
1829
|
-
/**
|
|
1830
|
-
* Generate AI-optimized modifications
|
|
1831
|
-
*/
|
|
1832
|
-
generateAIOptimizedModifications(aiAnalysis) {
|
|
1833
|
-
const _super = Object.create(null, {
|
|
1834
|
-
generateModifications: { get: () => super.generateModifications }
|
|
1835
|
-
});
|
|
1836
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1837
|
-
const baseModifications = yield _super.generateModifications.call(this);
|
|
1838
|
-
// Enhance with AI recommendations
|
|
1839
|
-
const enhancedModifications = baseModifications.map(mod => {
|
|
1840
|
-
return this.enhanceModificationWithAI(mod, aiAnalysis);
|
|
1841
|
-
});
|
|
1842
|
-
// Add AI-specific optimizations
|
|
1843
|
-
const aiOptimizations = this.generateAIOptimizations(aiAnalysis);
|
|
1844
|
-
enhancedModifications.push(...aiOptimizations);
|
|
1845
|
-
return enhancedModifications;
|
|
1846
|
-
});
|
|
1847
|
-
}
|
|
1848
|
-
/**
|
|
1849
|
-
* Enhance modification with AI insights
|
|
1850
|
-
*/
|
|
1851
|
-
enhanceModificationWithAI(mod, aiAnalysis) {
|
|
1852
|
-
let enhancedContent = mod.content;
|
|
1853
|
-
// Add compatibility comments
|
|
1854
|
-
if (aiAnalysis.compatibilityMode === 'legacy') {
|
|
1855
|
-
enhancedContent = `// HumanBehavior SDK - Legacy Compatibility Mode\n${enhancedContent}`;
|
|
1856
|
-
}
|
|
1857
|
-
// Add future-proofing comments
|
|
1858
|
-
if (aiAnalysis.integrationStrategy === 'provider') {
|
|
1859
|
-
enhancedContent = `// HumanBehavior SDK - Provider Pattern (Future-proof)\n${enhancedContent}`;
|
|
1860
|
-
}
|
|
1861
|
-
// Add conflict resolution
|
|
1862
|
-
if (aiAnalysis.conflicts.length > 0) {
|
|
1863
|
-
enhancedContent = `// Conflict Resolution: ${aiAnalysis.conflicts.join(', ')}\n${enhancedContent}`;
|
|
1864
|
-
}
|
|
1865
|
-
return Object.assign(Object.assign({}, mod), { content: enhancedContent, description: `${mod.description} (AI-optimized)` });
|
|
1866
|
-
}
|
|
1867
|
-
/**
|
|
1868
|
-
* Generate AI-specific optimizations
|
|
1869
|
-
*/
|
|
1870
|
-
generateAIOptimizations(aiAnalysis) {
|
|
1871
|
-
const optimizations = [];
|
|
1872
|
-
// AI optimizations are now handled through environment variables and code injection
|
|
1873
|
-
// No separate config file needed - everything is integrated into the existing codebase
|
|
1874
|
-
return optimizations;
|
|
1875
|
-
}
|
|
1876
|
-
/**
|
|
1877
|
-
* Apply modifications with AI conflict resolution
|
|
1878
|
-
*/
|
|
1879
|
-
applyModificationsWithAI(modifications, aiAnalysis) {
|
|
1880
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1881
|
-
for (const modification of modifications) {
|
|
1882
|
-
try {
|
|
1883
|
-
// Check for conflicts
|
|
1884
|
-
const conflicts = yield this.detectConflicts(modification);
|
|
1885
|
-
if (conflicts.length > 0) {
|
|
1886
|
-
// Resolve conflicts using centralized AI service
|
|
1887
|
-
const resolutions = yield this.aiService.resolveConflicts(conflicts, aiAnalysis.framework);
|
|
1888
|
-
const resolvedModification = yield this.resolveConflicts(modification, conflicts, resolutions, aiAnalysis);
|
|
1889
|
-
yield this.applyModification(resolvedModification);
|
|
1890
|
-
}
|
|
1891
|
-
else {
|
|
1892
|
-
yield this.applyModification(modification);
|
|
1893
|
-
}
|
|
1894
|
-
}
|
|
1895
|
-
catch (error) {
|
|
1896
|
-
throw new Error(`Failed to apply AI-optimized modification to ${modification.filePath}: ${error}`);
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
});
|
|
1900
|
-
}
|
|
1901
|
-
/**
|
|
1902
|
-
* Detect potential conflicts
|
|
1903
|
-
*/
|
|
1904
|
-
detectConflicts(modification) {
|
|
1905
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1906
|
-
const conflicts = [];
|
|
1907
|
-
if (fs__namespace.existsSync(modification.filePath)) {
|
|
1908
|
-
const existingContent = fs__namespace.readFileSync(modification.filePath, 'utf8');
|
|
1909
|
-
// Check for existing HumanBehavior code
|
|
1910
|
-
if (existingContent.includes('HumanBehavior') || existingContent.includes('humanbehavior')) {
|
|
1911
|
-
conflicts.push('existing_humanbehavior_code');
|
|
1912
|
-
}
|
|
1913
|
-
// Check for conflicting providers/plugins
|
|
1914
|
-
if (modification.content.includes('Provider') && existingContent.includes('Provider')) {
|
|
1915
|
-
conflicts.push('existing_provider');
|
|
1916
|
-
}
|
|
1917
|
-
// Check for TypeScript conflicts
|
|
1918
|
-
if (modification.content.includes('import') && existingContent.includes('require(')) {
|
|
1919
|
-
conflicts.push('module_system_conflict');
|
|
1920
|
-
}
|
|
1921
|
-
}
|
|
1922
|
-
return conflicts;
|
|
1923
|
-
});
|
|
1924
|
-
}
|
|
1925
|
-
/**
|
|
1926
|
-
* Resolve conflicts with AI
|
|
1927
|
-
*/
|
|
1928
|
-
resolveConflicts(modification, conflicts, resolutions, aiAnalysis) {
|
|
1929
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1930
|
-
let resolvedContent = modification.content;
|
|
1931
|
-
for (let i = 0; i < conflicts.length; i++) {
|
|
1932
|
-
const conflict = conflicts[i];
|
|
1933
|
-
const resolution = resolutions[i];
|
|
1934
|
-
switch (resolution) {
|
|
1935
|
-
case 'update_existing_integration':
|
|
1936
|
-
resolvedContent = `// Updated HumanBehavior Integration\n${resolvedContent}`;
|
|
1937
|
-
break;
|
|
1938
|
-
case 'merge_providers':
|
|
1939
|
-
resolvedContent = resolvedContent.replace(/<HumanBehaviorProvider/g, '<HumanBehaviorProvider key="updated"');
|
|
1940
|
-
break;
|
|
1941
|
-
case 'hybrid_module_support':
|
|
1942
|
-
resolvedContent = `// Hybrid module system support\n${resolvedContent}`;
|
|
1943
|
-
break;
|
|
1944
|
-
case 'skip_conflict':
|
|
1945
|
-
// Skip this modification
|
|
1946
|
-
return Object.assign(Object.assign({}, modification), { content: '', description: `${modification.description} (skipped due to conflict)` });
|
|
1947
|
-
default:
|
|
1948
|
-
// Default resolution
|
|
1949
|
-
resolvedContent = `// Conflict resolved: ${conflict}\n${resolvedContent}`;
|
|
1950
|
-
}
|
|
1951
|
-
}
|
|
1952
|
-
return Object.assign(Object.assign({}, modification), { content: resolvedContent, description: `${modification.description} (conflict-resolved)` });
|
|
1953
|
-
});
|
|
1954
|
-
}
|
|
1955
|
-
/**
|
|
1956
|
-
* Apply single modification
|
|
1957
|
-
*/
|
|
1958
|
-
applyModification(modification) {
|
|
1959
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1960
|
-
if (!modification.content)
|
|
1961
|
-
return; // Skip empty modifications
|
|
1962
|
-
const dir = path__namespace.dirname(modification.filePath);
|
|
1963
|
-
if (!fs__namespace.existsSync(dir)) {
|
|
1964
|
-
fs__namespace.mkdirSync(dir, { recursive: true });
|
|
1965
|
-
}
|
|
1966
|
-
switch (modification.action) {
|
|
1967
|
-
case 'create':
|
|
1968
|
-
fs__namespace.writeFileSync(modification.filePath, modification.content);
|
|
1969
|
-
break;
|
|
1970
|
-
case 'modify':
|
|
1971
|
-
fs__namespace.writeFileSync(modification.filePath, modification.content);
|
|
1972
|
-
break;
|
|
1973
|
-
case 'append':
|
|
1974
|
-
fs__namespace.appendFileSync(modification.filePath, '\n' + modification.content);
|
|
1975
|
-
break;
|
|
1976
|
-
}
|
|
1977
|
-
});
|
|
1978
|
-
}
|
|
1979
|
-
/**
|
|
1980
|
-
* Generate AI-enhanced next steps
|
|
1981
|
-
*/
|
|
1982
|
-
generateAINextSteps(aiAnalysis) {
|
|
1983
|
-
const steps = [
|
|
1984
|
-
'✅ AI-optimized SDK installation completed!',
|
|
1985
|
-
`🎯 Framework detected: ${aiAnalysis.framework.name} (confidence: ${Math.round(aiAnalysis.confidence * 100)}%)`,
|
|
1986
|
-
`🔧 Integration strategy: ${aiAnalysis.integrationStrategy}`,
|
|
1987
|
-
`🔄 Compatibility mode: ${aiAnalysis.compatibilityMode}`,
|
|
1988
|
-
'🚀 Your app is now tracking user behavior with AI-optimized configuration'
|
|
1989
|
-
];
|
|
1990
|
-
if (aiAnalysis.recommendations.length > 0) {
|
|
1991
|
-
steps.push('💡 AI Recommendations:');
|
|
1992
|
-
aiAnalysis.recommendations.forEach(rec => steps.push(` • ${rec}`));
|
|
1993
|
-
}
|
|
1994
|
-
return steps;
|
|
1995
|
-
}
|
|
1996
|
-
/**
|
|
1997
|
-
* Learn from installation for future improvements
|
|
1998
|
-
*/
|
|
1999
|
-
learnFromInstallation(aiAnalysis, modifications) {
|
|
2000
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2001
|
-
const learningData = {
|
|
2002
|
-
timestamp: new Date().toISOString(),
|
|
2003
|
-
framework: aiAnalysis.framework.name,
|
|
2004
|
-
patterns: aiAnalysis.patterns,
|
|
2005
|
-
integrationStrategy: aiAnalysis.integrationStrategy,
|
|
2006
|
-
compatibilityMode: aiAnalysis.compatibilityMode,
|
|
2007
|
-
modifications: modifications.length,
|
|
2008
|
-
success: true
|
|
2009
|
-
};
|
|
2010
|
-
// Store learning data
|
|
2011
|
-
this.learningCache.set(`${aiAnalysis.framework.name}_${Date.now()}`, learningData);
|
|
2012
|
-
// Update pattern database
|
|
2013
|
-
if (!this.patternDatabase.has(aiAnalysis.framework.name)) {
|
|
2014
|
-
this.patternDatabase.set(aiAnalysis.framework.name, []);
|
|
2015
|
-
}
|
|
2016
|
-
this.patternDatabase.get(aiAnalysis.framework.name).push(learningData);
|
|
2017
|
-
// Save to disk
|
|
2018
|
-
yield this.saveLearningData();
|
|
2019
|
-
});
|
|
2020
|
-
}
|
|
2021
|
-
/**
|
|
2022
|
-
* Load learning data from disk
|
|
2023
|
-
*/
|
|
2024
|
-
loadLearningData() {
|
|
2025
|
-
// Don't load learning data from user's project - keep it in memory only
|
|
2026
|
-
// This prevents cluttering the user's project with internal files
|
|
2027
|
-
}
|
|
2028
|
-
/**
|
|
2029
|
-
* Save learning data to disk
|
|
2030
|
-
*/
|
|
2031
|
-
saveLearningData() {
|
|
2032
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2033
|
-
// Don't save learning data to user's project - keep it in memory only
|
|
2034
|
-
// This prevents cluttering the user's project with internal files
|
|
2035
|
-
});
|
|
2036
|
-
}
|
|
2037
|
-
/**
|
|
2038
|
-
* Get AI insights for a specific framework
|
|
2039
|
-
*/
|
|
2040
|
-
getAIInsights(frameworkName) {
|
|
2041
|
-
return this.patternDatabase.get(frameworkName) || [];
|
|
2042
|
-
}
|
|
2043
|
-
/**
|
|
2044
|
-
* Get learning statistics
|
|
2045
|
-
*/
|
|
2046
|
-
getLearningStats() {
|
|
2047
|
-
const stats = {
|
|
2048
|
-
totalInstallations: this.learningCache.size,
|
|
2049
|
-
frameworks: {},
|
|
2050
|
-
patterns: {}
|
|
2051
|
-
};
|
|
2052
|
-
for (const [framework, data] of this.patternDatabase.entries()) {
|
|
2053
|
-
stats.frameworks[framework] = data.length;
|
|
2054
|
-
}
|
|
2055
|
-
return stats;
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
/**
|
|
2059
|
-
* Browser-based AI installation wizard
|
|
2060
|
-
*/
|
|
2061
|
-
class AIBrowserInstallationWizard {
|
|
2062
|
-
constructor(apiKey, aiService) {
|
|
2063
|
-
this.apiKey = apiKey;
|
|
2064
|
-
this.aiService = aiService || new DefaultAIService();
|
|
2065
|
-
}
|
|
2066
|
-
install() {
|
|
2067
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2068
|
-
try {
|
|
2069
|
-
// AI-powered browser detection
|
|
2070
|
-
const aiAnalysis = yield this.performBrowserAIAnalysis();
|
|
2071
|
-
// Generate AI-optimized browser modifications
|
|
2072
|
-
const modifications = this.generateAIBrowserModifications(aiAnalysis);
|
|
2073
|
-
return {
|
|
2074
|
-
success: true,
|
|
2075
|
-
framework: aiAnalysis.framework,
|
|
2076
|
-
modifications,
|
|
2077
|
-
errors: [],
|
|
2078
|
-
nextSteps: [
|
|
2079
|
-
'✅ AI-optimized browser integration ready!',
|
|
2080
|
-
`🎯 Framework detected: ${aiAnalysis.framework.name}`,
|
|
2081
|
-
`🔧 Integration strategy: ${aiAnalysis.integrationStrategy}`,
|
|
2082
|
-
'📋 Copy the generated code to your project',
|
|
2083
|
-
'🚀 Your app will be ready to track user behavior'
|
|
2084
|
-
],
|
|
2085
|
-
aiAnalysis,
|
|
2086
|
-
learningData: {
|
|
2087
|
-
patterns: aiAnalysis.patterns,
|
|
2088
|
-
framework: aiAnalysis.framework.name,
|
|
2089
|
-
success: true
|
|
2090
|
-
}
|
|
2091
|
-
};
|
|
2092
|
-
}
|
|
2093
|
-
catch (error) {
|
|
2094
|
-
return {
|
|
2095
|
-
success: false,
|
|
2096
|
-
framework: { name: 'unknown', type: 'vanilla' },
|
|
2097
|
-
modifications: [],
|
|
2098
|
-
errors: [error instanceof Error ? error.message : 'Unknown error'],
|
|
2099
|
-
nextSteps: [],
|
|
2100
|
-
aiAnalysis: {
|
|
2101
|
-
framework: { name: 'unknown', type: 'vanilla' },
|
|
2102
|
-
confidence: 0,
|
|
2103
|
-
patterns: [],
|
|
2104
|
-
conflicts: [],
|
|
2105
|
-
recommendations: [],
|
|
2106
|
-
integrationStrategy: 'script',
|
|
2107
|
-
compatibilityMode: 'legacy'
|
|
2108
|
-
},
|
|
2109
|
-
learningData: {
|
|
2110
|
-
patterns: [],
|
|
2111
|
-
framework: 'unknown',
|
|
2112
|
-
success: false
|
|
2113
|
-
}
|
|
2114
|
-
};
|
|
2115
|
-
}
|
|
2116
|
-
});
|
|
2117
|
-
}
|
|
2118
|
-
performBrowserAIAnalysis() {
|
|
2119
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2120
|
-
// Browser-based framework detection
|
|
2121
|
-
this.detectBrowserFramework();
|
|
2122
|
-
// Analyze browser environment
|
|
2123
|
-
const patterns = this.analyzeBrowserPatterns();
|
|
2124
|
-
// Use centralized AI service for analysis
|
|
2125
|
-
const codeSamples = [`Browser Environment: ${patterns.join(', ')}`];
|
|
2126
|
-
return yield this.aiService.analyzeCodePatterns(codeSamples);
|
|
2127
|
-
});
|
|
2128
|
-
}
|
|
2129
|
-
detectBrowserFramework() {
|
|
2130
|
-
if (typeof window !== 'undefined') {
|
|
2131
|
-
if (window.React) {
|
|
2132
|
-
return { name: 'react', type: 'react' };
|
|
2133
|
-
}
|
|
2134
|
-
if (window.Vue) {
|
|
2135
|
-
return { name: 'vue', type: 'vue' };
|
|
2136
|
-
}
|
|
2137
|
-
if (window.angular) {
|
|
2138
|
-
return { name: 'angular', type: 'angular' };
|
|
2139
|
-
}
|
|
2140
|
-
}
|
|
2141
|
-
return { name: 'vanilla', type: 'vanilla' };
|
|
2142
|
-
}
|
|
2143
|
-
analyzeBrowserPatterns() {
|
|
2144
|
-
const patterns = [];
|
|
2145
|
-
if (typeof window !== 'undefined') {
|
|
2146
|
-
// Analyze global objects
|
|
2147
|
-
if (window.React)
|
|
2148
|
-
patterns.push('React global detected');
|
|
2149
|
-
if (window.Vue)
|
|
2150
|
-
patterns.push('Vue global detected');
|
|
2151
|
-
if (window.angular)
|
|
2152
|
-
patterns.push('Angular global detected');
|
|
2153
|
-
// Analyze DOM patterns
|
|
2154
|
-
if (document.querySelector('[data-reactroot]'))
|
|
2155
|
-
patterns.push('React DOM detected');
|
|
2156
|
-
if (document.querySelector('[data-vue]'))
|
|
2157
|
-
patterns.push('Vue DOM detected');
|
|
2158
|
-
// Analyze script patterns
|
|
2159
|
-
const scripts = document.querySelectorAll('script');
|
|
2160
|
-
scripts.forEach(script => {
|
|
2161
|
-
if (script.src.includes('react'))
|
|
2162
|
-
patterns.push('React script detected');
|
|
2163
|
-
if (script.src.includes('vue'))
|
|
2164
|
-
patterns.push('Vue script detected');
|
|
2165
|
-
});
|
|
2166
|
-
}
|
|
2167
|
-
return patterns;
|
|
2168
|
-
}
|
|
2169
|
-
generateAIBrowserModifications(aiAnalysis) {
|
|
2170
|
-
const modifications = [];
|
|
2171
|
-
switch (aiAnalysis.framework.type) {
|
|
2172
|
-
case 'react':
|
|
2173
|
-
modifications.push({
|
|
2174
|
-
filePath: 'App.jsx',
|
|
2175
|
-
action: 'create',
|
|
2176
|
-
content: `// AI-Optimized React Integration
|
|
2177
|
-
import { HumanBehaviorProvider } from 'humanbehavior-js/react';
|
|
2178
|
-
|
|
2179
|
-
function App() {
|
|
2180
|
-
return (
|
|
2181
|
-
<HumanBehaviorProvider
|
|
2182
|
-
apiKey="${this.apiKey}"
|
|
2183
|
-
config={{
|
|
2184
|
-
// AI-generated optimizations
|
|
2185
|
-
enablePerformanceTracking: true,
|
|
2186
|
-
enableErrorTracking: true,
|
|
2187
|
-
framework: '${aiAnalysis.framework.name}',
|
|
2188
|
-
integrationStrategy: '${aiAnalysis.integrationStrategy}'
|
|
2189
|
-
}}
|
|
2190
|
-
>
|
|
2191
|
-
{/* Your app components */}
|
|
2192
|
-
</HumanBehaviorProvider>
|
|
2193
|
-
);
|
|
2194
|
-
}
|
|
2195
|
-
|
|
2196
|
-
export default App;`,
|
|
2197
|
-
description: 'AI-optimized React component with HumanBehaviorProvider'
|
|
2198
|
-
});
|
|
2199
|
-
break;
|
|
2200
|
-
default:
|
|
2201
|
-
modifications.push({
|
|
2202
|
-
filePath: 'humanbehavior-init.js',
|
|
2203
|
-
action: 'create',
|
|
2204
|
-
content: `// AI-Optimized Vanilla JS Integration
|
|
2205
|
-
import { HumanBehaviorTracker } from 'humanbehavior-js';
|
|
2206
|
-
|
|
2207
|
-
const tracker = HumanBehaviorTracker.init('${this.apiKey}', {
|
|
2208
|
-
// AI-generated configuration
|
|
2209
|
-
framework: '${aiAnalysis.framework.name}',
|
|
2210
|
-
integrationStrategy: '${aiAnalysis.integrationStrategy}',
|
|
2211
|
-
compatibilityMode: '${aiAnalysis.compatibilityMode}',
|
|
2212
|
-
enablePerformanceTracking: true,
|
|
2213
|
-
enableErrorTracking: true
|
|
2214
|
-
});`,
|
|
2215
|
-
description: 'AI-optimized vanilla JS initialization'
|
|
2216
|
-
});
|
|
2217
|
-
}
|
|
2218
|
-
return modifications;
|
|
2219
|
-
}
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
|
-
/**
|
|
2223
|
-
* Remote AI Service Implementation
|
|
2224
|
-
*
|
|
2225
|
-
* This connects to your deployed Lambda function via API Gateway
|
|
2226
|
-
*/
|
|
2227
|
-
class RemoteAIService {
|
|
2228
|
-
constructor(config) {
|
|
2229
|
-
this.config = Object.assign({ timeout: 10000 }, config);
|
|
2230
|
-
}
|
|
2231
|
-
/**
|
|
2232
|
-
* Analyze code patterns using your deployed AI service
|
|
2233
|
-
*/
|
|
2234
|
-
analyzeCodePatterns(codeSamples) {
|
|
2235
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2236
|
-
try {
|
|
2237
|
-
const response = yield fetch(`${this.config.apiEndpoint}/analyze`, {
|
|
2238
|
-
method: 'POST',
|
|
2239
|
-
headers: {
|
|
2240
|
-
'Content-Type': 'application/json',
|
|
2241
|
-
},
|
|
2242
|
-
body: JSON.stringify({ codeSamples }),
|
|
2243
|
-
signal: AbortSignal.timeout(this.config.timeout || 10000)
|
|
2244
|
-
});
|
|
2245
|
-
if (!response.ok) {
|
|
2246
|
-
throw new Error(`AI service returned ${response.status}: ${response.statusText}`);
|
|
2247
|
-
}
|
|
2248
|
-
const result = yield response.json();
|
|
2249
|
-
return result.analysis;
|
|
2250
|
-
}
|
|
2251
|
-
catch (error) {
|
|
2252
|
-
console.warn('Remote AI service failed, falling back to heuristic analysis:', error);
|
|
2253
|
-
return this.performHeuristicAnalysis(codeSamples);
|
|
2254
|
-
}
|
|
2255
|
-
});
|
|
2256
|
-
}
|
|
2257
|
-
/**
|
|
2258
|
-
* Resolve conflicts using your deployed AI service
|
|
2259
|
-
*/
|
|
2260
|
-
resolveConflicts(conflicts, framework) {
|
|
2261
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2262
|
-
try {
|
|
2263
|
-
const response = yield fetch(`${this.config.apiEndpoint}/resolve-conflicts`, {
|
|
2264
|
-
method: 'POST',
|
|
2265
|
-
headers: {
|
|
2266
|
-
'Content-Type': 'application/json',
|
|
2267
|
-
},
|
|
2268
|
-
body: JSON.stringify({ conflicts, framework }),
|
|
2269
|
-
signal: AbortSignal.timeout(this.config.timeout || 10000)
|
|
2270
|
-
});
|
|
2271
|
-
if (!response.ok) {
|
|
2272
|
-
throw new Error(`AI service returned ${response.status}: ${response.statusText}`);
|
|
2273
|
-
}
|
|
2274
|
-
const result = yield response.json();
|
|
2275
|
-
return result.resolutions || [];
|
|
2276
|
-
}
|
|
2277
|
-
catch (error) {
|
|
2278
|
-
console.warn('Remote AI conflict resolution failed, using heuristic approach:', error);
|
|
2279
|
-
return this.resolveConflictsHeuristic(conflicts, framework);
|
|
2280
|
-
}
|
|
2281
|
-
});
|
|
2282
|
-
}
|
|
2283
|
-
/**
|
|
2284
|
-
* Generate optimizations using your deployed AI service
|
|
2285
|
-
*/
|
|
2286
|
-
generateOptimizations(framework, patterns) {
|
|
2287
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2288
|
-
try {
|
|
2289
|
-
const response = yield fetch(`${this.config.apiEndpoint}/optimize`, {
|
|
2290
|
-
method: 'POST',
|
|
2291
|
-
headers: {
|
|
2292
|
-
'Content-Type': 'application/json',
|
|
2293
|
-
},
|
|
2294
|
-
body: JSON.stringify({ framework, patterns }),
|
|
2295
|
-
signal: AbortSignal.timeout(this.config.timeout || 10000)
|
|
2296
|
-
});
|
|
2297
|
-
if (!response.ok) {
|
|
2298
|
-
throw new Error(`AI service returned ${response.status}: ${response.statusText}`);
|
|
2299
|
-
}
|
|
2300
|
-
const result = yield response.json();
|
|
2301
|
-
return result.optimizations || [];
|
|
2302
|
-
}
|
|
2303
|
-
catch (error) {
|
|
2304
|
-
console.warn('Remote AI optimization generation failed, using heuristic approach:', error);
|
|
2305
|
-
return this.generateOptimizationsHeuristic(framework, patterns);
|
|
2306
|
-
}
|
|
2307
|
-
});
|
|
2308
|
-
}
|
|
2309
|
-
/**
|
|
2310
|
-
* Heuristic analysis fallback
|
|
2311
|
-
*/
|
|
2312
|
-
performHeuristicAnalysis(codeSamples) {
|
|
2313
|
-
const patterns = codeSamples.join(' ').toLowerCase();
|
|
2314
|
-
// Framework detection
|
|
2315
|
-
let framework = { name: 'vanilla', type: 'vanilla' };
|
|
2316
|
-
let confidence = 0.5;
|
|
2317
|
-
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')) {
|
|
2318
|
-
framework = { name: 'nuxt', type: 'nuxt' };
|
|
2319
|
-
confidence = 0.95;
|
|
2320
|
-
}
|
|
2321
|
-
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/')) {
|
|
2322
|
-
framework = { name: 'nextjs', type: 'nextjs' };
|
|
2323
|
-
confidence = 0.95;
|
|
2324
|
-
}
|
|
2325
|
-
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')) {
|
|
2326
|
-
framework = { name: 'gatsby', type: 'gatsby' };
|
|
2327
|
-
confidence = 0.95;
|
|
2328
|
-
}
|
|
2329
|
-
else if (patterns.includes('react')) {
|
|
2330
|
-
framework = { name: 'react', type: 'react' };
|
|
2331
|
-
confidence = 0.9;
|
|
2332
|
-
}
|
|
2333
|
-
else if (patterns.includes('vue')) {
|
|
2334
|
-
framework = { name: 'vue', type: 'vue' };
|
|
2335
|
-
confidence = 0.9;
|
|
2336
|
-
}
|
|
2337
|
-
else if (patterns.includes('angular')) {
|
|
2338
|
-
framework = { name: 'angular', type: 'angular' };
|
|
2339
|
-
confidence = 0.9;
|
|
2340
|
-
}
|
|
2341
|
-
else if (patterns.includes('svelte')) {
|
|
2342
|
-
framework = { name: 'svelte', type: 'svelte' };
|
|
2343
|
-
confidence = 0.9;
|
|
2344
|
-
}
|
|
2345
|
-
else if (patterns.includes('astro')) {
|
|
2346
|
-
framework = { name: 'astro', type: 'astro' };
|
|
2347
|
-
confidence = 0.9;
|
|
2348
|
-
}
|
|
2349
|
-
// Integration strategy
|
|
2350
|
-
let integrationStrategy = 'script';
|
|
2351
|
-
if (framework.type === 'react' || framework.type === 'nextjs' || framework.type === 'gatsby') {
|
|
2352
|
-
integrationStrategy = 'provider';
|
|
2353
|
-
}
|
|
2354
|
-
else if (framework.type === 'vue') {
|
|
2355
|
-
integrationStrategy = 'plugin';
|
|
2356
|
-
}
|
|
2357
|
-
else if (framework.type === 'angular') {
|
|
2358
|
-
integrationStrategy = 'module';
|
|
2359
|
-
}
|
|
2360
|
-
// Compatibility mode
|
|
2361
|
-
let compatibilityMode = 'modern';
|
|
2362
|
-
if (patterns.includes('require(') || patterns.includes('var ')) {
|
|
2363
|
-
compatibilityMode = 'legacy';
|
|
2364
|
-
}
|
|
2365
|
-
return {
|
|
2366
|
-
framework,
|
|
2367
|
-
confidence,
|
|
2368
|
-
patterns: codeSamples,
|
|
2369
|
-
conflicts: [],
|
|
2370
|
-
recommendations: [],
|
|
2371
|
-
integrationStrategy,
|
|
2372
|
-
compatibilityMode
|
|
2373
|
-
};
|
|
2374
|
-
}
|
|
2375
|
-
/**
|
|
2376
|
-
* Heuristic conflict resolution
|
|
2377
|
-
*/
|
|
2378
|
-
resolveConflictsHeuristic(conflicts, framework) {
|
|
2379
|
-
const resolutions = [];
|
|
2380
|
-
for (const conflict of conflicts) {
|
|
2381
|
-
switch (conflict) {
|
|
2382
|
-
case 'existing_humanbehavior_code':
|
|
2383
|
-
resolutions.push('update_existing_integration');
|
|
2384
|
-
break;
|
|
2385
|
-
case 'existing_provider':
|
|
2386
|
-
resolutions.push('merge_providers');
|
|
2387
|
-
break;
|
|
2388
|
-
case 'module_system_conflict':
|
|
2389
|
-
resolutions.push('hybrid_module_support');
|
|
2390
|
-
break;
|
|
2391
|
-
default:
|
|
2392
|
-
resolutions.push('skip_conflict');
|
|
2393
|
-
}
|
|
2394
|
-
}
|
|
2395
|
-
return resolutions;
|
|
2396
|
-
}
|
|
2397
|
-
/**
|
|
2398
|
-
* Heuristic optimization generation
|
|
2399
|
-
*/
|
|
2400
|
-
generateOptimizationsHeuristic(framework, patterns) {
|
|
2401
|
-
const optimizations = [];
|
|
2402
|
-
switch (framework.type) {
|
|
2403
|
-
case 'react':
|
|
2404
|
-
optimizations.push('Use React.memo for performance optimization');
|
|
2405
|
-
optimizations.push('Implement error boundaries for better error tracking');
|
|
2406
|
-
optimizations.push('Consider using React.lazy for code splitting');
|
|
2407
|
-
break;
|
|
2408
|
-
case 'vue':
|
|
2409
|
-
optimizations.push('Use Vue 3 Composition API for better performance');
|
|
2410
|
-
optimizations.push('Implement proper error handling in components');
|
|
2411
|
-
optimizations.push('Consider using Vue Router for navigation tracking');
|
|
2412
|
-
break;
|
|
2413
|
-
case 'angular':
|
|
2414
|
-
optimizations.push('Use Angular standalone components for better tree-shaking');
|
|
2415
|
-
optimizations.push('Implement proper error handling with ErrorHandler');
|
|
2416
|
-
optimizations.push('Consider using Angular signals for state management');
|
|
2417
|
-
break;
|
|
2418
|
-
default:
|
|
2419
|
-
optimizations.push('Enable performance tracking');
|
|
2420
|
-
optimizations.push('Implement error tracking');
|
|
2421
|
-
optimizations.push('Consider progressive enhancement');
|
|
2422
|
-
}
|
|
2423
|
-
return optimizations;
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
|
|
2427
|
-
/**
|
|
2428
|
-
* Manual Framework Installation Wizard
|
|
2429
|
-
*
|
|
2430
|
-
* This wizard allows users to manually specify their framework instead of auto-detection.
|
|
2431
|
-
* Useful when auto-detection fails or users want more control.
|
|
2432
|
-
*/
|
|
2433
|
-
class ManualFrameworkInstallationWizard extends AutoInstallationWizard {
|
|
2434
|
-
constructor(apiKey, projectRoot = process.cwd(), framework) {
|
|
2435
|
-
super(apiKey, projectRoot);
|
|
2436
|
-
this.selectedFramework = framework.toLowerCase();
|
|
2437
|
-
this.framework = this.createFrameworkInfo(this.selectedFramework);
|
|
2438
|
-
}
|
|
2439
|
-
/**
|
|
2440
|
-
* Manual installation with user-specified framework
|
|
2441
|
-
*/
|
|
2442
|
-
install() {
|
|
2443
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2444
|
-
try {
|
|
2445
|
-
// Step 1: Handle framework selection
|
|
2446
|
-
if (this.selectedFramework === 'auto') {
|
|
2447
|
-
// Use full AI detection for "Other" option
|
|
2448
|
-
this.framework = yield this.runFullDetection();
|
|
2449
|
-
}
|
|
2450
|
-
else {
|
|
2451
|
-
// Set framework based on user selection
|
|
2452
|
-
this.framework = this.createFrameworkInfo(this.selectedFramework);
|
|
2453
|
-
if (!this.framework) {
|
|
2454
|
-
this.framework = { name: 'unknown', type: 'vanilla' };
|
|
2455
|
-
}
|
|
2456
|
-
// Step 2: Run full detection logic to find entry points, file names, etc.
|
|
2457
|
-
const detectedFramework = yield this.runFullDetection();
|
|
2458
|
-
// Step 3: Merge manual framework with detected details
|
|
2459
|
-
this.framework = Object.assign(Object.assign({}, detectedFramework), { name: this.framework.name, type: this.framework.type });
|
|
2460
|
-
}
|
|
2461
|
-
// Step 4: Install package
|
|
2462
|
-
yield this.installPackage();
|
|
2463
|
-
// Step 5: Generate and apply code modifications
|
|
2464
|
-
const modifications = yield this.generateModifications();
|
|
2465
|
-
yield this.applyModifications(modifications);
|
|
2466
|
-
// Step 6: Generate next steps
|
|
2467
|
-
const nextSteps = this.generateManualNextSteps();
|
|
2468
|
-
return {
|
|
2469
|
-
success: true,
|
|
2470
|
-
framework: this.framework,
|
|
2471
|
-
modifications,
|
|
2472
|
-
errors: [],
|
|
2473
|
-
nextSteps,
|
|
2474
|
-
selectedFramework: this.selectedFramework,
|
|
2475
|
-
manualMode: true
|
|
2476
|
-
};
|
|
2477
|
-
}
|
|
2478
|
-
catch (error) {
|
|
2479
|
-
return {
|
|
2480
|
-
success: false,
|
|
2481
|
-
framework: this.framework || { name: 'unknown', type: 'vanilla' },
|
|
2482
|
-
modifications: [],
|
|
2483
|
-
errors: [error instanceof Error ? error.message : 'Unknown error'],
|
|
2484
|
-
nextSteps: [],
|
|
2485
|
-
selectedFramework: this.selectedFramework,
|
|
2486
|
-
manualMode: true
|
|
2487
|
-
};
|
|
2488
|
-
}
|
|
2489
|
-
});
|
|
2490
|
-
}
|
|
2491
|
-
/**
|
|
2492
|
-
* Run full detection logic to find entry points, file names, bundler, etc.
|
|
2493
|
-
*/
|
|
2494
|
-
runFullDetection() {
|
|
2495
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2496
|
-
if (this.selectedFramework === 'auto') {
|
|
2497
|
-
// Use AI service for auto-detection
|
|
2498
|
-
const aiService = new RemoteAIService({
|
|
2499
|
-
apiEndpoint: 'https://ik3zxh4790.execute-api.us-east-1.amazonaws.com/prod'
|
|
2500
|
-
});
|
|
2501
|
-
// Use AI service directly for detection
|
|
2502
|
-
const projectFiles = yield this.scanProjectFiles();
|
|
2503
|
-
const codeSamples = yield this.extractCodeSamples(projectFiles);
|
|
2504
|
-
const aiAnalysis = yield aiService.analyzeCodePatterns(codeSamples);
|
|
2505
|
-
return aiAnalysis.framework;
|
|
2506
|
-
}
|
|
2507
|
-
else {
|
|
2508
|
-
// Use traditional detection for manual frameworks
|
|
2509
|
-
const tempWizard = new AutoInstallationWizard(this.apiKey, this.projectRoot);
|
|
2510
|
-
const detected = yield tempWizard.detectFramework();
|
|
2511
|
-
return detected;
|
|
2512
|
-
}
|
|
2513
|
-
});
|
|
2514
|
-
}
|
|
2515
|
-
/**
|
|
2516
|
-
* Scan project files for analysis
|
|
2517
|
-
*/
|
|
2518
|
-
scanProjectFiles() {
|
|
2519
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2520
|
-
const files = [];
|
|
2521
|
-
const scanDir = (dir, depth = 0) => {
|
|
2522
|
-
if (depth > 3)
|
|
2523
|
-
return; // Limit depth
|
|
2524
|
-
try {
|
|
2525
|
-
const items = fs__namespace.readdirSync(dir);
|
|
2526
|
-
for (const item of items) {
|
|
2527
|
-
const fullPath = path__namespace.join(dir, item);
|
|
2528
|
-
const stat = fs__namespace.statSync(fullPath);
|
|
2529
|
-
if (stat.isDirectory() && !item.startsWith('.') && item !== 'node_modules') {
|
|
2530
|
-
scanDir(fullPath, depth + 1);
|
|
2531
|
-
}
|
|
2532
|
-
else if (stat.isFile() && this.isRelevantFile(item)) {
|
|
2533
|
-
files.push(fullPath);
|
|
2534
|
-
}
|
|
2535
|
-
}
|
|
2536
|
-
}
|
|
2537
|
-
catch (error) {
|
|
2538
|
-
// Skip inaccessible directories
|
|
2539
|
-
}
|
|
2540
|
-
};
|
|
2541
|
-
scanDir(this.projectRoot);
|
|
2542
|
-
return files;
|
|
2543
|
-
});
|
|
2544
|
-
}
|
|
2545
|
-
/**
|
|
2546
|
-
* Check if file is relevant for analysis
|
|
2547
|
-
*/
|
|
2548
|
-
isRelevantFile(filename) {
|
|
2549
|
-
const relevantExtensions = [
|
|
2550
|
-
'.js', '.jsx', '.ts', '.tsx', '.vue', '.svelte', '.html',
|
|
2551
|
-
'.json', '.config.js', '.config.ts', '.babelrc', '.eslintrc'
|
|
2552
|
-
];
|
|
2553
|
-
const relevantNames = [
|
|
2554
|
-
'package.json', 'tsconfig.json', 'vite.config', 'webpack.config',
|
|
2555
|
-
'next.config', 'nuxt.config', 'angular.json', 'svelte.config'
|
|
2556
|
-
];
|
|
2557
|
-
return relevantExtensions.some(ext => filename.endsWith(ext)) ||
|
|
2558
|
-
relevantNames.some(name => filename.includes(name));
|
|
2559
|
-
}
|
|
2560
|
-
/**
|
|
2561
|
-
* Extract code samples for AI analysis
|
|
2562
|
-
*/
|
|
2563
|
-
extractCodeSamples(files) {
|
|
2564
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2565
|
-
const samples = [];
|
|
2566
|
-
for (const file of files.slice(0, 20)) { // Limit to 20 files
|
|
2567
|
-
try {
|
|
2568
|
-
const content = fs__namespace.readFileSync(file, 'utf8');
|
|
2569
|
-
const relativePath = path__namespace.relative(this.projectRoot, file);
|
|
2570
|
-
samples.push(`File: ${relativePath}\n${content.substring(0, 1000)}`);
|
|
2571
|
-
}
|
|
2572
|
-
catch (error) {
|
|
2573
|
-
// Skip unreadable files
|
|
2574
|
-
}
|
|
2575
|
-
}
|
|
2576
|
-
return samples;
|
|
2577
|
-
});
|
|
2578
|
-
}
|
|
2579
|
-
/**
|
|
2580
|
-
* Create framework info based on user selection
|
|
2581
|
-
*/
|
|
2582
|
-
createFrameworkInfo(framework) {
|
|
2583
|
-
const frameworkMap = {
|
|
2584
|
-
'react': { name: 'react', type: 'react' },
|
|
2585
|
-
'nextjs': { name: 'nextjs', type: 'nextjs' },
|
|
2586
|
-
'next': { name: 'nextjs', type: 'nextjs' },
|
|
2587
|
-
'vue': { name: 'vue', type: 'vue' },
|
|
2588
|
-
'nuxt': { name: 'nuxt', type: 'nuxt' },
|
|
2589
|
-
'nuxtjs': { name: 'nuxt', type: 'nuxt' },
|
|
2590
|
-
'angular': { name: 'angular', type: 'angular' },
|
|
2591
|
-
'svelte': { name: 'svelte', type: 'svelte' },
|
|
2592
|
-
'sveltekit': { name: 'svelte', type: 'svelte' },
|
|
2593
|
-
'remix': { name: 'remix', type: 'remix' },
|
|
2594
|
-
'astro': { name: 'astro', type: 'astro' },
|
|
2595
|
-
'gatsby': { name: 'gatsby', type: 'gatsby' },
|
|
2596
|
-
'vanilla': { name: 'vanilla', type: 'vanilla' },
|
|
2597
|
-
'node': { name: 'node', type: 'node' },
|
|
2598
|
-
'auto': { name: 'auto-detected', type: 'auto' }
|
|
2599
|
-
};
|
|
2600
|
-
return frameworkMap[framework] || { name: framework, type: 'vanilla' };
|
|
2601
|
-
}
|
|
2602
|
-
/**
|
|
2603
|
-
* Override framework detection to use manual selection
|
|
2604
|
-
*/
|
|
2605
|
-
detectFramework() {
|
|
2606
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2607
|
-
return this.framework || { name: 'unknown', type: 'vanilla' };
|
|
2608
|
-
});
|
|
2609
|
-
}
|
|
2610
|
-
/**
|
|
2611
|
-
* Generate next steps with manual mode info
|
|
2612
|
-
*/
|
|
2613
|
-
generateManualNextSteps() {
|
|
2614
|
-
var _a;
|
|
2615
|
-
return [
|
|
2616
|
-
'✅ Manual framework installation completed!',
|
|
2617
|
-
`🎯 Selected framework: ${((_a = this.framework) === null || _a === void 0 ? void 0 : _a.name) || 'unknown'}`,
|
|
2618
|
-
`🔧 Integration strategy: ${this.getIntegrationStrategy()}`,
|
|
2619
|
-
'🚀 Your app is now ready to track user behavior',
|
|
2620
|
-
'📊 View sessions in your HumanBehavior dashboard'
|
|
2621
|
-
];
|
|
2622
|
-
}
|
|
2623
|
-
/**
|
|
2624
|
-
* Get integration strategy based on framework
|
|
2625
|
-
*/
|
|
2626
|
-
getIntegrationStrategy() {
|
|
2627
|
-
var _a;
|
|
2628
|
-
if (!((_a = this.framework) === null || _a === void 0 ? void 0 : _a.type))
|
|
2629
|
-
return 'script';
|
|
2630
|
-
switch (this.framework.type) {
|
|
2631
|
-
case 'react':
|
|
2632
|
-
case 'nextjs':
|
|
2633
|
-
return 'provider';
|
|
2634
|
-
case 'vue':
|
|
2635
|
-
return 'plugin';
|
|
2636
|
-
case 'angular':
|
|
2637
|
-
return 'module';
|
|
2638
|
-
default:
|
|
2639
|
-
return 'script';
|
|
2640
|
-
}
|
|
2641
|
-
}
|
|
2642
|
-
}
|
|
2643
|
-
|
|
2644
|
-
/**
|
|
2645
|
-
* AI-Enhanced HumanBehavior SDK Auto-Installation CLI
|
|
2646
|
-
*
|
|
2647
|
-
* Usage: npx humanbehavior-js ai-auto-install [api-key]
|
|
2648
|
-
*
|
|
2649
|
-
* This tool uses AI to intelligently detect frameworks, analyze code patterns,
|
|
2650
|
-
* and generate optimal integration code that's both future-proof and backward-compatible.
|
|
2651
|
-
*/
|
|
2652
|
-
class AIAutoInstallCLI {
|
|
2653
|
-
constructor(options) {
|
|
2654
|
-
this.options = options;
|
|
2655
|
-
}
|
|
2656
|
-
run() {
|
|
2657
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2658
|
-
clack__namespace.intro('🤖 AI-Enhanced HumanBehavior SDK Auto-Installation');
|
|
2659
|
-
try {
|
|
2660
|
-
// Get API key
|
|
2661
|
-
const apiKey = yield this.getApiKey();
|
|
2662
|
-
if (!apiKey) {
|
|
2663
|
-
clack__namespace.cancel('API key is required');
|
|
2664
|
-
process.exit(1);
|
|
2665
|
-
}
|
|
2666
|
-
// Get project path
|
|
2667
|
-
const projectPath = this.options.projectPath || process.cwd();
|
|
2668
|
-
// Choose framework
|
|
2669
|
-
const framework = yield this.chooseFramework();
|
|
2670
|
-
if (!framework) {
|
|
2671
|
-
clack__namespace.cancel('Installation cancelled.');
|
|
2672
|
-
process.exit(0);
|
|
2673
|
-
}
|
|
2674
|
-
// Confirm installation
|
|
2675
|
-
if (!this.options.yes) {
|
|
2676
|
-
const confirmed = yield this.confirmInstallation(projectPath, framework);
|
|
2677
|
-
if (!confirmed) {
|
|
2678
|
-
clack__namespace.cancel('Installation cancelled.');
|
|
2679
|
-
process.exit(0);
|
|
2680
|
-
}
|
|
2681
|
-
}
|
|
2682
|
-
// Run installation
|
|
2683
|
-
const spinner = clack__namespace.spinner();
|
|
2684
|
-
spinner.start('🔍 Analyzing your project with AI...');
|
|
2685
|
-
const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
|
|
2686
|
-
const result = yield wizard.install();
|
|
2687
|
-
spinner.stop('Analysis complete!');
|
|
2688
|
-
// Display results
|
|
2689
|
-
this.displayResults(result, framework);
|
|
2690
|
-
}
|
|
2691
|
-
catch (error) {
|
|
2692
|
-
clack__namespace.cancel(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
2693
|
-
process.exit(1);
|
|
2694
|
-
}
|
|
2695
|
-
});
|
|
2696
|
-
}
|
|
2697
|
-
getApiKey() {
|
|
2698
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2699
|
-
if (this.options.apiKey) {
|
|
2700
|
-
return this.options.apiKey;
|
|
2701
|
-
}
|
|
2702
|
-
const apiKey = yield clack__namespace.text({
|
|
2703
|
-
message: 'Enter your HumanBehavior API key:',
|
|
2704
|
-
placeholder: 'hb_...',
|
|
2705
|
-
validate: (value) => {
|
|
2706
|
-
if (!value)
|
|
2707
|
-
return 'API key is required';
|
|
2708
|
-
if (!value.startsWith('hb_'))
|
|
2709
|
-
return 'API key should start with "hb_"';
|
|
2710
|
-
return undefined;
|
|
2711
|
-
}
|
|
2712
|
-
});
|
|
2713
|
-
return apiKey;
|
|
2714
|
-
});
|
|
2715
|
-
}
|
|
2716
|
-
confirmInstallation(projectPath, framework) {
|
|
2717
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2718
|
-
const confirmed = yield clack__namespace.confirm({
|
|
2719
|
-
message: `Ready to install HumanBehavior SDK in ${projectPath} for ${framework}?`
|
|
2720
|
-
});
|
|
2721
|
-
return confirmed;
|
|
2722
|
-
});
|
|
2723
|
-
}
|
|
2724
|
-
chooseFramework() {
|
|
2725
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2726
|
-
const framework = yield clack__namespace.select({
|
|
2727
|
-
message: 'Select your framework:',
|
|
2728
|
-
options: [
|
|
2729
|
-
{ label: 'React', value: 'react' },
|
|
2730
|
-
{ label: 'Next.js', value: 'nextjs' },
|
|
2731
|
-
{ label: 'Vue', value: 'vue' },
|
|
2732
|
-
{ label: 'Angular', value: 'angular' },
|
|
2733
|
-
{ label: 'Svelte', value: 'svelte' },
|
|
2734
|
-
{ label: 'Nuxt.js', value: 'nuxt' },
|
|
2735
|
-
{ label: 'Remix', value: 'remix' },
|
|
2736
|
-
{ label: 'Astro', value: 'astro' },
|
|
2737
|
-
{ label: 'Gatsby', value: 'gatsby' },
|
|
2738
|
-
{ label: 'Vanilla JS/TS', value: 'vanilla' }
|
|
2739
|
-
]
|
|
2740
|
-
});
|
|
2741
|
-
return framework;
|
|
2742
|
-
});
|
|
2743
|
-
}
|
|
2744
|
-
displayResults(result, framework) {
|
|
2745
|
-
if (result.success) {
|
|
2746
|
-
clack__namespace.outro('🎉 Installation completed successfully!');
|
|
2747
|
-
// Display framework info
|
|
2748
|
-
clack__namespace.note(`Framework detected: ${result.framework.name} (${result.framework.type})`, 'Framework Info');
|
|
2749
|
-
// Display modifications
|
|
2750
|
-
if (result.modifications && result.modifications.length > 0) {
|
|
2751
|
-
const modifications = result.modifications.map((mod) => `${mod.action}: ${mod.filePath} - ${mod.description}`);
|
|
2752
|
-
clack__namespace.note(modifications.join('\n'), 'Files Modified');
|
|
2753
|
-
}
|
|
2754
|
-
// Display next steps
|
|
2755
|
-
if (result.nextSteps && result.nextSteps.length > 0) {
|
|
2756
|
-
clack__namespace.note(result.nextSteps.join('\n'), 'Next Steps');
|
|
2757
|
-
}
|
|
2758
|
-
// Display AI insights if available
|
|
2759
|
-
if (result.aiAnalysis) {
|
|
2760
|
-
clack__namespace.note(`Confidence: ${Math.round(result.aiAnalysis.confidence * 100)}%`, 'AI Analysis');
|
|
2761
|
-
if (result.aiAnalysis.recommendations && result.aiAnalysis.recommendations.length > 0) {
|
|
2762
|
-
clack__namespace.note(result.aiAnalysis.recommendations.join('\n'), 'AI Recommendations');
|
|
2763
|
-
}
|
|
2764
|
-
}
|
|
2765
|
-
}
|
|
2766
|
-
else {
|
|
2767
|
-
clack__namespace.cancel('Installation failed');
|
|
2768
|
-
if (result.errors && result.errors.length > 0) {
|
|
2769
|
-
clack__namespace.note(result.errors.join('\n'), 'Errors');
|
|
2770
|
-
}
|
|
2771
|
-
}
|
|
2772
|
-
}
|
|
2773
|
-
}
|
|
2774
|
-
function parseArgs$1() {
|
|
2775
|
-
const args = process.argv.slice(2);
|
|
2776
|
-
const options = {};
|
|
2777
|
-
for (let i = 0; i < args.length; i++) {
|
|
2778
|
-
const arg = args[i];
|
|
2779
|
-
switch (arg) {
|
|
2780
|
-
case '--help':
|
|
2781
|
-
case '-h':
|
|
2782
|
-
showHelp$1();
|
|
2783
|
-
process.exit(0);
|
|
2784
|
-
break;
|
|
2785
|
-
case '--yes':
|
|
2786
|
-
case '-y':
|
|
2787
|
-
options.yes = true;
|
|
2788
|
-
break;
|
|
2789
|
-
case '--dry-run':
|
|
2790
|
-
options.dryRun = true;
|
|
2791
|
-
break;
|
|
2792
|
-
case '--project':
|
|
2793
|
-
case '-p':
|
|
2794
|
-
options.projectPath = args[++i];
|
|
2795
|
-
break;
|
|
2796
|
-
case '--framework':
|
|
2797
|
-
case '-f':
|
|
2798
|
-
options.framework = args[++i];
|
|
2799
|
-
break;
|
|
2800
|
-
default:
|
|
2801
|
-
if (!options.apiKey && !arg.startsWith('-')) {
|
|
2802
|
-
options.apiKey = arg;
|
|
2803
|
-
}
|
|
2804
|
-
break;
|
|
2805
|
-
}
|
|
2806
|
-
}
|
|
2807
|
-
return options;
|
|
2808
|
-
}
|
|
2809
|
-
function showHelp$1() {
|
|
2810
|
-
console.log(`
|
|
2811
|
-
🤖 HumanBehavior SDK AI Auto-Installation
|
|
2812
|
-
|
|
2813
|
-
Usage: npx humanbehavior-js ai-auto-install [api-key] [options]
|
|
2814
|
-
|
|
2815
|
-
Options:
|
|
2816
|
-
-h, --help Show this help message
|
|
2817
|
-
-y, --yes Skip all prompts and use defaults
|
|
2818
|
-
--dry-run Show what would be changed without making changes
|
|
2819
|
-
|
|
2820
|
-
-p, --project <path> Specify project directory
|
|
2821
|
-
-f, --framework <name> Specify framework manually
|
|
2822
|
-
|
|
2823
|
-
Examples:
|
|
2824
|
-
npx humanbehavior-js ai-auto-install
|
|
2825
|
-
npx humanbehavior-js ai-auto-install hb_your_api_key_here
|
|
2826
|
-
npx humanbehavior-js ai-auto-install --project ./my-app --ai
|
|
2827
|
-
npx humanbehavior-js ai-auto-install --framework react --yes
|
|
2828
|
-
`);
|
|
2829
|
-
}
|
|
2830
|
-
// Main execution
|
|
2831
|
-
const options = parseArgs$1();
|
|
2832
|
-
const cli = new AIAutoInstallCLI(options);
|
|
2833
|
-
cli.run().catch((error) => {
|
|
2834
|
-
clack__namespace.cancel(`Unexpected error: ${error.message}`);
|
|
2835
|
-
process.exit(1);
|
|
2836
|
-
});
|
|
2837
|
-
|
|
2838
|
-
/**
|
|
2839
|
-
* HumanBehavior SDK Auto-Installation CLI
|
|
2840
|
-
*
|
|
2841
|
-
* Usage: npx humanbehavior-js auto-install [api-key]
|
|
2842
|
-
*
|
|
2843
|
-
* This tool automatically detects the user's framework and modifies their codebase
|
|
2844
|
-
* to integrate the SDK with minimal user intervention.
|
|
2845
|
-
*/
|
|
2846
|
-
class AutoInstallCLI {
|
|
2847
|
-
constructor(options) {
|
|
2848
|
-
this.options = options;
|
|
2849
|
-
}
|
|
2850
|
-
run() {
|
|
2851
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2852
|
-
clack__namespace.intro('🚀 HumanBehavior SDK Auto-Installation');
|
|
2853
|
-
try {
|
|
2854
|
-
// Get API key
|
|
2855
|
-
const apiKey = yield this.getApiKey();
|
|
2856
|
-
if (!apiKey) {
|
|
2857
|
-
clack__namespace.cancel('API key is required');
|
|
2858
|
-
process.exit(1);
|
|
2859
|
-
}
|
|
2860
|
-
// Get project path
|
|
2861
|
-
const projectPath = this.options.projectPath || process.cwd();
|
|
2862
|
-
// Choose framework
|
|
2863
|
-
const framework = yield this.chooseFramework();
|
|
2864
|
-
if (!framework) {
|
|
2865
|
-
clack__namespace.cancel('Installation cancelled.');
|
|
2866
|
-
process.exit(0);
|
|
2867
|
-
}
|
|
2868
|
-
// Confirm installation
|
|
2869
|
-
if (!this.options.yes) {
|
|
2870
|
-
const confirmed = yield this.confirmInstallation(projectPath, framework);
|
|
2871
|
-
if (!confirmed) {
|
|
2872
|
-
clack__namespace.cancel('Installation cancelled.');
|
|
2873
|
-
process.exit(0);
|
|
2874
|
-
}
|
|
2875
|
-
}
|
|
2876
|
-
// Run installation
|
|
2877
|
-
const spinner = clack__namespace.spinner();
|
|
2878
|
-
spinner.start('🔍 Analyzing your project...');
|
|
2879
|
-
const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
|
|
2880
|
-
const result = yield wizard.install();
|
|
2881
|
-
spinner.stop('Detection complete!');
|
|
2882
|
-
// Display results
|
|
2883
|
-
this.displayResults(result);
|
|
2884
|
-
}
|
|
2885
|
-
catch (error) {
|
|
2886
|
-
clack__namespace.cancel(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
2887
|
-
process.exit(1);
|
|
2888
|
-
}
|
|
2889
|
-
});
|
|
2890
|
-
}
|
|
2891
|
-
getApiKey() {
|
|
2892
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2893
|
-
if (this.options.apiKey) {
|
|
2894
|
-
return this.options.apiKey;
|
|
2895
|
-
}
|
|
2896
|
-
const apiKey = yield clack__namespace.text({
|
|
2897
|
-
message: 'Enter your HumanBehavior API key:',
|
|
2898
|
-
placeholder: 'hb_...',
|
|
2899
|
-
validate: (value) => {
|
|
2900
|
-
if (!value)
|
|
2901
|
-
return 'API key is required';
|
|
2902
|
-
if (!value.startsWith('hb_'))
|
|
2903
|
-
return 'API key should start with "hb_"';
|
|
2904
|
-
return undefined;
|
|
2905
|
-
}
|
|
2906
|
-
});
|
|
2907
|
-
return apiKey;
|
|
2908
|
-
});
|
|
2909
|
-
}
|
|
2910
|
-
chooseFramework() {
|
|
2911
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2912
|
-
const framework = yield clack__namespace.select({
|
|
2913
|
-
message: 'Select your framework:',
|
|
2914
|
-
options: [
|
|
2915
|
-
{ label: 'React', value: 'react' },
|
|
2916
|
-
{ label: 'Next.js', value: 'nextjs' },
|
|
2917
|
-
{ label: 'Vue', value: 'vue' },
|
|
2918
|
-
{ label: 'Angular', value: 'angular' },
|
|
2919
|
-
{ label: 'Svelte', value: 'svelte' },
|
|
2920
|
-
{ label: 'Nuxt.js', value: 'nuxt' },
|
|
2921
|
-
{ label: 'Remix', value: 'remix' },
|
|
2922
|
-
{ label: 'Astro', value: 'astro' },
|
|
2923
|
-
{ label: 'Gatsby', value: 'gatsby' },
|
|
2924
|
-
{ label: 'Vanilla JS/TS', value: 'vanilla' }
|
|
2925
|
-
]
|
|
2926
|
-
});
|
|
2927
|
-
return framework;
|
|
2928
|
-
});
|
|
2929
|
-
}
|
|
2930
|
-
confirmInstallation(projectPath, framework) {
|
|
2931
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2932
|
-
const confirmed = yield clack__namespace.confirm({
|
|
2933
|
-
message: `Ready to install HumanBehavior SDK in ${projectPath} for ${framework}?`
|
|
2934
|
-
});
|
|
2935
|
-
return confirmed;
|
|
2936
|
-
});
|
|
2937
|
-
}
|
|
2938
|
-
displayResults(result) {
|
|
2939
|
-
if (result.success) {
|
|
2940
|
-
clack__namespace.outro('🎉 Installation completed successfully!');
|
|
2941
|
-
// Display framework info
|
|
2942
|
-
clack__namespace.note(`Framework detected: ${result.framework.name} (${result.framework.type})`, 'Framework Info');
|
|
2943
|
-
// Display modifications
|
|
2944
|
-
if (result.modifications && result.modifications.length > 0) {
|
|
2945
|
-
const modifications = result.modifications.map((mod) => `${mod.action}: ${mod.filePath} - ${mod.description}`);
|
|
2946
|
-
clack__namespace.note(modifications.join('\n'), 'Files Modified');
|
|
2947
|
-
}
|
|
2948
|
-
// Display next steps
|
|
2949
|
-
if (result.nextSteps && result.nextSteps.length > 0) {
|
|
2950
|
-
clack__namespace.note(result.nextSteps.join('\n'), 'Next Steps');
|
|
2951
|
-
}
|
|
2952
|
-
}
|
|
2953
|
-
else {
|
|
2954
|
-
clack__namespace.cancel('Installation failed');
|
|
2955
|
-
if (result.errors && result.errors.length > 0) {
|
|
2956
|
-
clack__namespace.note(result.errors.join('\n'), 'Errors');
|
|
2957
|
-
}
|
|
2958
|
-
}
|
|
2959
|
-
}
|
|
2960
|
-
}
|
|
2961
|
-
function parseArgs() {
|
|
2962
|
-
const args = process.argv.slice(2);
|
|
2963
|
-
const options = {};
|
|
2964
|
-
for (let i = 0; i < args.length; i++) {
|
|
2965
|
-
const arg = args[i];
|
|
2966
|
-
switch (arg) {
|
|
2967
|
-
case '--help':
|
|
2968
|
-
case '-h':
|
|
2969
|
-
showHelp();
|
|
2970
|
-
process.exit(0);
|
|
2971
|
-
break;
|
|
2972
|
-
case '--yes':
|
|
2973
|
-
case '-y':
|
|
2974
|
-
options.yes = true;
|
|
2975
|
-
break;
|
|
2976
|
-
case '--dry-run':
|
|
2977
|
-
options.dryRun = true;
|
|
2978
|
-
break;
|
|
2979
|
-
case '--project':
|
|
2980
|
-
case '-p':
|
|
2981
|
-
options.projectPath = args[++i];
|
|
2982
|
-
break;
|
|
2983
|
-
default:
|
|
2984
|
-
if (!options.apiKey && !arg.startsWith('-')) {
|
|
2985
|
-
options.apiKey = arg;
|
|
2986
|
-
}
|
|
2987
|
-
break;
|
|
2988
|
-
}
|
|
2989
|
-
}
|
|
2990
|
-
return options;
|
|
2991
|
-
}
|
|
2992
|
-
function showHelp() {
|
|
2993
|
-
console.log(`
|
|
2994
|
-
🚀 HumanBehavior SDK Auto-Installation
|
|
2995
|
-
|
|
2996
|
-
Usage: npx humanbehavior-js auto-install [api-key] [options]
|
|
2997
|
-
|
|
2998
|
-
This tool automatically detects your framework and integrates the HumanBehavior SDK.
|
|
2999
|
-
|
|
3000
|
-
Options:
|
|
3001
|
-
-h, --help Show this help message
|
|
3002
|
-
-y, --yes Skip all prompts and use defaults
|
|
3003
|
-
--dry-run Show what would be changed without making changes
|
|
3004
|
-
-p, --project <path> Specify project directory
|
|
3005
|
-
|
|
3006
|
-
Examples:
|
|
3007
|
-
npx humanbehavior-js auto-install
|
|
3008
|
-
npx humanbehavior-js auto-install hb_your_api_key_here
|
|
3009
|
-
npx humanbehavior-js auto-install --project ./my-app --yes
|
|
3010
|
-
`);
|
|
3011
|
-
}
|
|
3012
|
-
// Main execution
|
|
3013
|
-
if ((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) === `file://${process.argv[1]}`) {
|
|
3014
|
-
const options = parseArgs();
|
|
3015
|
-
const cli = new AutoInstallCLI(options);
|
|
3016
|
-
cli.run().catch((error) => {
|
|
3017
|
-
clack__namespace.cancel(`Unexpected error: ${error.message}`);
|
|
3018
|
-
process.exit(1);
|
|
3019
|
-
});
|
|
3020
|
-
}
|
|
3021
|
-
|
|
3022
|
-
/**
|
|
3023
|
-
* Centralized AI Service Implementation
|
|
3024
|
-
*
|
|
3025
|
-
* This service runs on your backend infrastructure and provides AI-powered
|
|
3026
|
-
* code analysis without requiring users to provide their own API keys.
|
|
3027
|
-
*
|
|
3028
|
-
* The service can be deployed as:
|
|
3029
|
-
* - AWS Lambda function
|
|
3030
|
-
* - Docker container
|
|
3031
|
-
* - Express.js server
|
|
3032
|
-
* - Cloud function
|
|
3033
|
-
*/
|
|
3034
|
-
/**
|
|
3035
|
-
* Centralized AI Service Implementation
|
|
3036
|
-
* This runs on your backend infrastructure
|
|
3037
|
-
*/
|
|
3038
|
-
class CentralizedAIService {
|
|
3039
|
-
constructor(config) {
|
|
3040
|
-
this.cache = new Map();
|
|
3041
|
-
this.config = Object.assign({ openaiModel: 'gpt-4', maxTokens: 2000, temperature: 0.3, enableCaching: true, cacheTTL: 3600 }, config);
|
|
3042
|
-
this.initializeOpenAI();
|
|
3043
|
-
}
|
|
3044
|
-
/**
|
|
3045
|
-
* Initialize OpenAI client
|
|
3046
|
-
*/
|
|
3047
|
-
initializeOpenAI() {
|
|
3048
|
-
try {
|
|
3049
|
-
// Import OpenAI dynamically to avoid bundling issues
|
|
3050
|
-
const { OpenAI } = require('openai');
|
|
3051
|
-
this.openai = new OpenAI({
|
|
3052
|
-
apiKey: this.config.openaiApiKey
|
|
3053
|
-
});
|
|
3054
|
-
}
|
|
3055
|
-
catch (error) {
|
|
3056
|
-
console.warn('OpenAI not available, falling back to heuristic analysis');
|
|
3057
|
-
this.openai = null;
|
|
3058
|
-
}
|
|
3059
|
-
}
|
|
3060
|
-
/**
|
|
3061
|
-
* Analyze code patterns using AI
|
|
3062
|
-
*/
|
|
3063
|
-
analyzeCodePatterns(codeSamples) {
|
|
3064
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
3065
|
-
const request = {
|
|
3066
|
-
codeSamples,
|
|
3067
|
-
timestamp: new Date().toISOString()
|
|
3068
|
-
};
|
|
3069
|
-
// Check cache first
|
|
3070
|
-
const cacheKey = this.generateCacheKey(request);
|
|
3071
|
-
if (this.config.enableCaching) {
|
|
3072
|
-
const cached = this.cache.get(cacheKey);
|
|
3073
|
-
if (cached && this.isCacheValid(cached.timestamp)) {
|
|
3074
|
-
return cached.analysis;
|
|
3075
|
-
}
|
|
3076
|
-
}
|
|
3077
|
-
const analysis = yield this.performAIAnalysis(request);
|
|
3078
|
-
// Cache the result
|
|
3079
|
-
if (this.config.enableCaching) {
|
|
3080
|
-
this.cache.set(cacheKey, {
|
|
3081
|
-
analysis,
|
|
3082
|
-
timestamp: Date.now()
|
|
3083
|
-
});
|
|
3084
|
-
}
|
|
3085
|
-
return analysis;
|
|
3086
|
-
});
|
|
3087
|
-
}
|
|
3088
|
-
/**
|
|
3089
|
-
* Resolve conflicts using AI
|
|
3090
|
-
*/
|
|
3091
|
-
resolveConflicts(conflicts, framework) {
|
|
3092
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
3093
|
-
var _a, _b;
|
|
3094
|
-
const request = {
|
|
3095
|
-
conflicts,
|
|
3096
|
-
framework,
|
|
3097
|
-
codeContext: 'HumanBehavior SDK integration'
|
|
3098
|
-
};
|
|
3099
|
-
if (!this.openai) {
|
|
3100
|
-
return this.resolveConflictsHeuristic(conflicts, framework);
|
|
3101
|
-
}
|
|
3102
|
-
try {
|
|
3103
|
-
const prompt = this.buildConflictResolutionPrompt(request);
|
|
3104
|
-
const response = yield this.openai.chat.completions.create({
|
|
3105
|
-
model: this.config.openaiModel,
|
|
3106
|
-
messages: [
|
|
3107
|
-
{
|
|
3108
|
-
role: 'system',
|
|
3109
|
-
content: 'You are an expert at resolving code integration conflicts. Provide specific resolution strategies.'
|
|
3110
|
-
},
|
|
3111
|
-
{
|
|
3112
|
-
role: 'user',
|
|
3113
|
-
content: prompt
|
|
3114
|
-
}
|
|
3115
|
-
],
|
|
3116
|
-
max_tokens: this.config.maxTokens,
|
|
3117
|
-
temperature: this.config.temperature
|
|
3118
|
-
});
|
|
3119
|
-
const content = (_b = (_a = response.choices[0]) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.content;
|
|
3120
|
-
if (content && typeof content === 'string') {
|
|
3121
|
-
return this.parseConflictResolutions(content);
|
|
3122
|
-
}
|
|
3123
|
-
return [];
|
|
3124
|
-
}
|
|
3125
|
-
catch (error) {
|
|
3126
|
-
console.warn('AI conflict resolution failed, using heuristic approach:', error instanceof Error ? error.message : 'Unknown error');
|
|
3127
|
-
}
|
|
3128
|
-
return this.resolveConflictsHeuristic(conflicts, framework);
|
|
3129
|
-
});
|
|
3130
|
-
}
|
|
3131
|
-
/**
|
|
3132
|
-
* Generate optimizations using AI
|
|
3133
|
-
*/
|
|
3134
|
-
generateOptimizations(framework, patterns) {
|
|
3135
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
3136
|
-
var _a, _b;
|
|
3137
|
-
const request = {
|
|
3138
|
-
framework,
|
|
3139
|
-
patterns,
|
|
3140
|
-
projectContext: 'HumanBehavior SDK integration'
|
|
3141
|
-
};
|
|
3142
|
-
if (!this.openai) {
|
|
3143
|
-
return this.generateOptimizationsHeuristic(framework, patterns);
|
|
3144
|
-
}
|
|
3145
|
-
try {
|
|
3146
|
-
const prompt = this.buildOptimizationPrompt(request);
|
|
3147
|
-
const response = yield this.openai.chat.completions.create({
|
|
3148
|
-
model: this.config.openaiModel,
|
|
3149
|
-
messages: [
|
|
3150
|
-
{
|
|
3151
|
-
role: 'system',
|
|
3152
|
-
content: 'You are an expert at optimizing code integration. Provide specific, actionable recommendations.'
|
|
3153
|
-
},
|
|
3154
|
-
{
|
|
3155
|
-
role: 'user',
|
|
3156
|
-
content: prompt
|
|
3157
|
-
}
|
|
3158
|
-
],
|
|
3159
|
-
max_tokens: this.config.maxTokens,
|
|
3160
|
-
temperature: this.config.temperature
|
|
3161
|
-
});
|
|
3162
|
-
const content = (_b = (_a = response.choices[0]) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.content;
|
|
3163
|
-
if (content) {
|
|
3164
|
-
return this.parseOptimizations(content);
|
|
3165
|
-
}
|
|
3166
|
-
}
|
|
3167
|
-
catch (error) {
|
|
3168
|
-
console.warn('AI optimization generation failed, using heuristic approach:', error instanceof Error ? error.message : 'Unknown error');
|
|
3169
|
-
}
|
|
3170
|
-
return this.generateOptimizationsHeuristic(framework, patterns);
|
|
3171
|
-
});
|
|
3172
|
-
}
|
|
3173
|
-
/**
|
|
3174
|
-
* Perform AI analysis
|
|
3175
|
-
*/
|
|
3176
|
-
performAIAnalysis(request) {
|
|
3177
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
3178
|
-
var _a, _b;
|
|
3179
|
-
if (!this.openai) {
|
|
3180
|
-
return this.performHeuristicAnalysis(request);
|
|
3181
|
-
}
|
|
3182
|
-
try {
|
|
3183
|
-
const prompt = this.buildAnalysisPrompt(request);
|
|
3184
|
-
const response = yield this.openai.chat.completions.create({
|
|
3185
|
-
model: this.config.openaiModel,
|
|
3186
|
-
messages: [
|
|
3187
|
-
{
|
|
3188
|
-
role: 'system',
|
|
3189
|
-
content: 'You are an expert at analyzing code patterns and determining optimal integration strategies. Provide detailed analysis in JSON format.'
|
|
3190
|
-
},
|
|
3191
|
-
{
|
|
3192
|
-
role: 'user',
|
|
3193
|
-
content: prompt
|
|
3194
|
-
}
|
|
3195
|
-
],
|
|
3196
|
-
max_tokens: this.config.maxTokens,
|
|
3197
|
-
temperature: this.config.temperature,
|
|
3198
|
-
response_format: { type: 'json_object' }
|
|
3199
|
-
});
|
|
3200
|
-
const content = (_b = (_a = response.choices[0]) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.content;
|
|
3201
|
-
if (content) {
|
|
3202
|
-
return this.parseAnalysisResult(content);
|
|
3203
|
-
}
|
|
3204
|
-
}
|
|
3205
|
-
catch (error) {
|
|
3206
|
-
console.warn('AI analysis failed, using heuristic approach:', error instanceof Error ? error.message : 'Unknown error');
|
|
3207
|
-
}
|
|
3208
|
-
return this.performHeuristicAnalysis(request);
|
|
3209
|
-
});
|
|
3210
|
-
}
|
|
3211
|
-
/**
|
|
3212
|
-
* Build analysis prompt
|
|
3213
|
-
*/
|
|
3214
|
-
buildAnalysisPrompt(request) {
|
|
3215
|
-
return `Analyze these code samples to determine the framework and integration strategy:
|
|
3216
|
-
|
|
3217
|
-
${request.codeSamples.join('\n\n')}
|
|
3218
|
-
|
|
3219
|
-
Provide analysis in JSON format with:
|
|
3220
|
-
- framework: { name, type, confidence (0-1) }
|
|
3221
|
-
- patterns: array of detected patterns
|
|
3222
|
-
- conflicts: array of potential conflicts
|
|
3223
|
-
- recommendations: array of integration recommendations
|
|
3224
|
-
- integrationStrategy: "provider" | "plugin" | "module" | "script" | "standalone"
|
|
3225
|
-
- compatibilityMode: "modern" | "legacy" | "hybrid"
|
|
3226
|
-
|
|
3227
|
-
Focus on:
|
|
3228
|
-
1. Framework detection beyond package.json
|
|
3229
|
-
2. Code patterns and architecture
|
|
3230
|
-
3. Integration compatibility
|
|
3231
|
-
4. Future-proof strategies
|
|
3232
|
-
5. Backward compatibility needs
|
|
3233
|
-
|
|
3234
|
-
Respond with valid JSON only.`;
|
|
3235
|
-
}
|
|
3236
|
-
/**
|
|
3237
|
-
* Build conflict resolution prompt
|
|
3238
|
-
*/
|
|
3239
|
-
buildConflictResolutionPrompt(request) {
|
|
3240
|
-
return `Resolve these integration conflicts for ${request.framework.name}:
|
|
3241
|
-
|
|
3242
|
-
Conflicts: ${request.conflicts.join(', ')}
|
|
3243
|
-
|
|
3244
|
-
Framework: ${request.framework.name} (${request.framework.type})
|
|
3245
|
-
Context: ${request.codeContext}
|
|
3246
|
-
|
|
3247
|
-
Provide specific resolution strategies for each conflict. Options:
|
|
3248
|
-
- update_existing_integration: Update existing code
|
|
3249
|
-
- merge_providers: Merge multiple providers
|
|
3250
|
-
- hybrid_module_support: Support both module systems
|
|
3251
|
-
- skip_conflict: Skip the modification
|
|
3252
|
-
- custom_resolution: Custom resolution strategy
|
|
3253
|
-
|
|
3254
|
-
Respond with a JSON array of resolution strategies.`;
|
|
3255
|
-
}
|
|
3256
|
-
/**
|
|
3257
|
-
* Build optimization prompt
|
|
3258
|
-
*/
|
|
3259
|
-
buildOptimizationPrompt(request) {
|
|
3260
|
-
return `Generate optimizations for ${request.framework.name} integration:
|
|
3261
|
-
|
|
3262
|
-
Framework: ${request.framework.name} (${request.framework.type})
|
|
3263
|
-
Patterns: ${request.patterns.join(', ')}
|
|
3264
|
-
Context: ${request.projectContext}
|
|
3265
|
-
|
|
3266
|
-
Provide specific, actionable optimization recommendations for:
|
|
3267
|
-
1. Performance improvements
|
|
3268
|
-
2. Error handling
|
|
3269
|
-
3. Code organization
|
|
3270
|
-
4. Future-proofing
|
|
3271
|
-
5. Backward compatibility
|
|
3272
|
-
|
|
3273
|
-
Respond with a JSON array of optimization recommendations.`;
|
|
3274
|
-
}
|
|
3275
|
-
/**
|
|
3276
|
-
* Parse analysis result
|
|
3277
|
-
*/
|
|
3278
|
-
parseAnalysisResult(content) {
|
|
3279
|
-
try {
|
|
3280
|
-
const result = JSON.parse(content);
|
|
3281
|
-
return {
|
|
3282
|
-
framework: result.framework || { name: 'vanilla', type: 'vanilla' },
|
|
3283
|
-
confidence: result.confidence || 0.5,
|
|
3284
|
-
patterns: result.patterns || [],
|
|
3285
|
-
conflicts: result.conflicts || [],
|
|
3286
|
-
recommendations: result.recommendations || [],
|
|
3287
|
-
integrationStrategy: result.integrationStrategy || 'script',
|
|
3288
|
-
compatibilityMode: result.compatibilityMode || 'modern'
|
|
3289
|
-
};
|
|
3290
|
-
}
|
|
3291
|
-
catch (error) {
|
|
3292
|
-
console.warn('Failed to parse AI analysis result:', error);
|
|
3293
|
-
return this.getDefaultAnalysis();
|
|
3294
|
-
}
|
|
3295
|
-
}
|
|
3296
|
-
/**
|
|
3297
|
-
* Parse conflict resolutions
|
|
3298
|
-
*/
|
|
3299
|
-
parseConflictResolutions(content) {
|
|
3300
|
-
try {
|
|
3301
|
-
const result = JSON.parse(content);
|
|
3302
|
-
return Array.isArray(result) ? result : [];
|
|
3303
|
-
}
|
|
3304
|
-
catch (error) {
|
|
3305
|
-
console.warn('Failed to parse conflict resolutions:', error);
|
|
3306
|
-
return [];
|
|
3307
|
-
}
|
|
3308
|
-
}
|
|
3309
|
-
/**
|
|
3310
|
-
* Parse optimizations
|
|
3311
|
-
*/
|
|
3312
|
-
parseOptimizations(content) {
|
|
3313
|
-
try {
|
|
3314
|
-
const result = JSON.parse(content);
|
|
3315
|
-
return Array.isArray(result) ? result : [];
|
|
3316
|
-
}
|
|
3317
|
-
catch (error) {
|
|
3318
|
-
console.warn('Failed to parse optimizations:', error);
|
|
3319
|
-
return [];
|
|
3320
|
-
}
|
|
3321
|
-
}
|
|
3322
|
-
/**
|
|
3323
|
-
* Heuristic analysis fallback
|
|
3324
|
-
*/
|
|
3325
|
-
performHeuristicAnalysis(request) {
|
|
3326
|
-
const patterns = request.codeSamples.join(' ').toLowerCase();
|
|
3327
|
-
// Framework detection
|
|
3328
|
-
let framework = { name: 'vanilla', type: 'vanilla' };
|
|
3329
|
-
let confidence = 0.5;
|
|
3330
|
-
if (patterns.includes('react')) {
|
|
3331
|
-
framework = { name: 'react', type: 'react' };
|
|
3332
|
-
confidence = 0.9;
|
|
3333
|
-
}
|
|
3334
|
-
else if (patterns.includes('vue')) {
|
|
3335
|
-
framework = { name: 'vue', type: 'vue' };
|
|
3336
|
-
confidence = 0.9;
|
|
3337
|
-
}
|
|
3338
|
-
else if (patterns.includes('angular')) {
|
|
3339
|
-
framework = { name: 'angular', type: 'angular' };
|
|
3340
|
-
confidence = 0.9;
|
|
3341
|
-
}
|
|
3342
|
-
else if (patterns.includes('svelte')) {
|
|
3343
|
-
framework = { name: 'svelte', type: 'svelte' };
|
|
3344
|
-
confidence = 0.9;
|
|
3345
|
-
}
|
|
3346
|
-
else if (patterns.includes('next')) {
|
|
3347
|
-
framework = { name: 'nextjs', type: 'nextjs' };
|
|
3348
|
-
confidence = 0.9;
|
|
3349
|
-
}
|
|
3350
|
-
else if (patterns.includes('nuxt')) {
|
|
3351
|
-
framework = { name: 'nuxt', type: 'nuxt' };
|
|
3352
|
-
confidence = 0.9;
|
|
3353
|
-
}
|
|
3354
|
-
// Integration strategy
|
|
3355
|
-
let integrationStrategy = 'script';
|
|
3356
|
-
if (framework.type === 'react' || framework.type === 'nextjs') {
|
|
3357
|
-
integrationStrategy = 'provider';
|
|
3358
|
-
}
|
|
3359
|
-
else if (framework.type === 'vue') {
|
|
3360
|
-
integrationStrategy = 'plugin';
|
|
3361
|
-
}
|
|
3362
|
-
else if (framework.type === 'angular') {
|
|
3363
|
-
integrationStrategy = 'module';
|
|
3364
|
-
}
|
|
3365
|
-
// Compatibility mode
|
|
3366
|
-
let compatibilityMode = 'modern';
|
|
3367
|
-
if (patterns.includes('require(') || patterns.includes('var ')) {
|
|
3368
|
-
compatibilityMode = 'legacy';
|
|
3369
|
-
}
|
|
3370
|
-
return {
|
|
3371
|
-
framework,
|
|
3372
|
-
confidence,
|
|
3373
|
-
patterns: request.codeSamples,
|
|
3374
|
-
conflicts: [],
|
|
3375
|
-
recommendations: [],
|
|
3376
|
-
integrationStrategy,
|
|
3377
|
-
compatibilityMode
|
|
3378
|
-
};
|
|
3379
|
-
}
|
|
3380
|
-
/**
|
|
3381
|
-
* Heuristic conflict resolution
|
|
3382
|
-
*/
|
|
3383
|
-
resolveConflictsHeuristic(conflicts, framework) {
|
|
3384
|
-
const resolutions = [];
|
|
3385
|
-
for (const conflict of conflicts) {
|
|
3386
|
-
switch (conflict) {
|
|
3387
|
-
case 'existing_humanbehavior_code':
|
|
3388
|
-
resolutions.push('update_existing_integration');
|
|
3389
|
-
break;
|
|
3390
|
-
case 'existing_provider':
|
|
3391
|
-
resolutions.push('merge_providers');
|
|
3392
|
-
break;
|
|
3393
|
-
case 'module_system_conflict':
|
|
3394
|
-
resolutions.push('hybrid_module_support');
|
|
3395
|
-
break;
|
|
3396
|
-
default:
|
|
3397
|
-
resolutions.push('skip_conflict');
|
|
3398
|
-
}
|
|
3399
|
-
}
|
|
3400
|
-
return resolutions;
|
|
3401
|
-
}
|
|
3402
|
-
/**
|
|
3403
|
-
* Heuristic optimization generation
|
|
3404
|
-
*/
|
|
3405
|
-
generateOptimizationsHeuristic(framework, patterns) {
|
|
3406
|
-
const optimizations = [];
|
|
3407
|
-
switch (framework.type) {
|
|
3408
|
-
case 'react':
|
|
3409
|
-
optimizations.push('Use React.memo for performance optimization');
|
|
3410
|
-
optimizations.push('Implement error boundaries for better error tracking');
|
|
3411
|
-
optimizations.push('Consider using React.lazy for code splitting');
|
|
3412
|
-
break;
|
|
3413
|
-
case 'vue':
|
|
3414
|
-
optimizations.push('Use Vue 3 Composition API for better performance');
|
|
3415
|
-
optimizations.push('Implement proper error handling in components');
|
|
3416
|
-
optimizations.push('Consider using Vue Router for navigation tracking');
|
|
3417
|
-
break;
|
|
3418
|
-
case 'angular':
|
|
3419
|
-
optimizations.push('Use Angular standalone components for better tree-shaking');
|
|
3420
|
-
optimizations.push('Implement proper error handling with ErrorHandler');
|
|
3421
|
-
optimizations.push('Consider using Angular signals for state management');
|
|
3422
|
-
break;
|
|
3423
|
-
default:
|
|
3424
|
-
optimizations.push('Enable performance tracking');
|
|
3425
|
-
optimizations.push('Implement error tracking');
|
|
3426
|
-
optimizations.push('Consider progressive enhancement');
|
|
3427
|
-
}
|
|
3428
|
-
return optimizations;
|
|
3429
|
-
}
|
|
3430
|
-
/**
|
|
3431
|
-
* Generate cache key
|
|
3432
|
-
*/
|
|
3433
|
-
generateCacheKey(request) {
|
|
3434
|
-
const content = JSON.stringify(request);
|
|
3435
|
-
return Buffer.from(content).toString('base64').substring(0, 32);
|
|
3436
|
-
}
|
|
3437
|
-
/**
|
|
3438
|
-
* Check if cache is valid
|
|
3439
|
-
*/
|
|
3440
|
-
isCacheValid(timestamp) {
|
|
3441
|
-
const now = Date.now();
|
|
3442
|
-
const ttl = (this.config.cacheTTL || 3600) * 1000; // Convert to milliseconds
|
|
3443
|
-
return (now - timestamp) < ttl;
|
|
3444
|
-
}
|
|
3445
|
-
/**
|
|
3446
|
-
* Get default analysis
|
|
3447
|
-
*/
|
|
3448
|
-
getDefaultAnalysis() {
|
|
3449
|
-
return {
|
|
3450
|
-
framework: { name: 'vanilla', type: 'vanilla' },
|
|
3451
|
-
confidence: 0.5,
|
|
3452
|
-
patterns: [],
|
|
3453
|
-
conflicts: [],
|
|
3454
|
-
recommendations: [],
|
|
3455
|
-
integrationStrategy: 'script',
|
|
3456
|
-
compatibilityMode: 'modern'
|
|
3457
|
-
};
|
|
3458
|
-
}
|
|
3459
|
-
/**
|
|
3460
|
-
* Get service statistics
|
|
3461
|
-
*/
|
|
3462
|
-
getStats() {
|
|
3463
|
-
return {
|
|
3464
|
-
cacheSize: this.cache.size,
|
|
3465
|
-
config: {
|
|
3466
|
-
model: this.config.openaiModel,
|
|
3467
|
-
maxTokens: this.config.maxTokens,
|
|
3468
|
-
temperature: this.config.temperature,
|
|
3469
|
-
caching: this.config.enableCaching
|
|
3470
|
-
},
|
|
3471
|
-
openaiAvailable: !!this.openai
|
|
3472
|
-
};
|
|
3473
|
-
}
|
|
3474
|
-
/**
|
|
3475
|
-
* Clear cache
|
|
3476
|
-
*/
|
|
3477
|
-
clearCache() {
|
|
3478
|
-
this.cache.clear();
|
|
3479
|
-
}
|
|
3480
|
-
}
|
|
3481
|
-
|
|
3482
|
-
exports.AIAutoInstallCLI = AIAutoInstallCLI;
|
|
3483
|
-
exports.AIBrowserInstallationWizard = AIBrowserInstallationWizard;
|
|
3484
|
-
exports.AIEnhancedInstallationWizard = AIEnhancedInstallationWizard;
|
|
3485
|
-
exports.AutoInstallCLI = AutoInstallCLI;
|
|
3486
|
-
exports.AutoInstallationWizard = AutoInstallationWizard;
|
|
3487
|
-
exports.CentralizedAIService = CentralizedAIService;
|
|
3488
|
-
exports.InstallWizard = AutoInstallationWizard;
|
|
3489
|
-
exports.RemoteAIService = RemoteAIService;
|
|
3490
|
-
//# sourceMappingURL=index.cjs.map
|