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