mongossee 1.0.14 → 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 +29 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -21,8 +21,10 @@ async function generateProject(prompt, directoryName) {
|
|
|
21
21
|
// Note: 'newPrompt' wala logic ab Server (api/server.js) ke paas hai,
|
|
22
22
|
// isliye yahan se hata diya taki code simple rahe.
|
|
23
23
|
|
|
24
|
+
// ⚠️ CHANGE: Humne prompt me strict instruction add kar di hai
|
|
25
|
+
// taaki AI response me comments na bheje.
|
|
24
26
|
const body = {
|
|
25
|
-
prompt: prompt
|
|
27
|
+
prompt: prompt + " . IMPORTANT: Return strictly code only. Do not include any comments, docstrings, or explanations inside the code files."
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
try {
|
|
@@ -44,24 +46,40 @@ async function generateProject(prompt, directoryName) {
|
|
|
44
46
|
const data = await response.json();
|
|
45
47
|
let responseText = data.candidates[0].content.parts[0].text;
|
|
46
48
|
|
|
47
|
-
// ---
|
|
48
|
-
|
|
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(']');
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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;
|
|
53
59
|
}
|
|
54
60
|
|
|
61
|
+
// Sirf kaam ka JSON hissa nikalo
|
|
62
|
+
let cleanJson = responseText.substring(jsonStartIndex, jsonEndIndex + 1);
|
|
63
|
+
|
|
55
64
|
let files;
|
|
56
65
|
try {
|
|
57
|
-
files = JSON.parse(
|
|
58
|
-
if (!Array.isArray(files)) throw new Error("AI did not return a JSON array.");
|
|
66
|
+
files = JSON.parse(cleanJson);
|
|
59
67
|
} catch (parseError) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
+
}
|
|
63
77
|
}
|
|
64
78
|
|
|
79
|
+
if (!Array.isArray(files)) throw new Error("AI did not return a JSON array.");
|
|
80
|
+
|
|
81
|
+
// --- FILE CREATION LOGIC ---
|
|
82
|
+
|
|
65
83
|
// Create the main project directory
|
|
66
84
|
fs.mkdirSync(directoryName, { recursive: true });
|
|
67
85
|
console.log(``);
|