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.
Files changed (2) hide show
  1. package/index.js +29 -11
  2. 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 // Sirf user ka prompt bhej rahe hain
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
- // --- NEW JSON PARSING & FILE CREATION LOGIC ---
48
- // console.log("Building project...");
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
- // Clean up potential markdown fences from the AI's response
51
- if (responseText.startsWith("```json")) {
52
- responseText = responseText.substring(7, responseText.length - 3).trim();
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(responseText);
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
- console.error("❌ ERROR: Failed to parse the AI's response. The response was not valid JSON.");
61
- console.error("Raw AI Response:", responseText);
62
- return;
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(``);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongossee",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {