mongossee 1.0.15 → 1.0.16
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/index.js +27 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -46,24 +46,40 @@ async function generateProject(prompt, directoryName) {
|
|
|
46
46
|
const data = await response.json();
|
|
47
47
|
let responseText = data.candidates[0].content.parts[0].text;
|
|
48
48
|
|
|
49
|
-
// ---
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
// --- 2. UPDATED SMART JSON PARSING (Ye naya hissa hai) ---
|
|
50
|
+
|
|
51
|
+
// Code start '[' aur end ']' dhoondho taaki faltu text ignore ho jaye
|
|
52
|
+
const jsonStartIndex = responseText.indexOf('[');
|
|
53
|
+
const jsonEndIndex = responseText.lastIndexOf(']');
|
|
54
|
+
|
|
55
|
+
if (jsonStartIndex === -1 || jsonEndIndex === -1) {
|
|
56
|
+
console.error("❌ ERROR: AI response me Valid JSON nahi mila.");
|
|
57
|
+
console.log("Raw Response:", responseText);
|
|
58
|
+
return;
|
|
55
59
|
}
|
|
56
60
|
|
|
61
|
+
// Sirf kaam ka JSON hissa nikalo
|
|
62
|
+
let cleanJson = responseText.substring(jsonStartIndex, jsonEndIndex + 1);
|
|
63
|
+
|
|
57
64
|
let files;
|
|
58
65
|
try {
|
|
59
|
-
files = JSON.parse(
|
|
60
|
-
if (!Array.isArray(files)) throw new Error("AI did not return a JSON array.");
|
|
66
|
+
files = JSON.parse(cleanJson);
|
|
61
67
|
} catch (parseError) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
// Agar normal parse fail ho, to control characters hata kar try karo
|
|
69
|
+
try {
|
|
70
|
+
cleanJson = cleanJson.replace(/[\u0000-\u0019]+/g, "");
|
|
71
|
+
files = JSON.parse(cleanJson);
|
|
72
|
+
} catch (retryError) {
|
|
73
|
+
console.error("❌ Parsing Failed. Raw Response niche dekhein:");
|
|
74
|
+
console.log(responseText);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
65
77
|
}
|
|
66
78
|
|
|
79
|
+
if (!Array.isArray(files)) throw new Error("AI did not return a JSON array.");
|
|
80
|
+
|
|
81
|
+
// --- FILE CREATION LOGIC ---
|
|
82
|
+
|
|
67
83
|
// Create the main project directory
|
|
68
84
|
fs.mkdirSync(directoryName, { recursive: true });
|
|
69
85
|
console.log(``);
|