mongossee 1.0.16 → 1.0.17

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 +19 -46
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -5,8 +5,7 @@ const path = require('path'); // Node.js Path module
5
5
  const yargs = require('yargs/yargs');
6
6
  const { hideBin } = require('yargs/helpers');
7
7
 
8
- // šŸ‘‡ IMP: Yahan apni Vercel App ka link daalna hoga (Deploy karne ke baad milega)
9
- // Filhal ye placeholder rakhein, baad me edit karke update kar dena.
8
+
10
9
  const SERVER_URL = "https://mongossee.vercel.app/api/server";
11
10
 
12
11
 
@@ -17,12 +16,7 @@ const SERVER_URL = "https://mongossee.vercel.app/api/server";
17
16
  */
18
17
  async function generateProject(prompt, directoryName) {
19
18
 
20
- // āš ļø CHANGE 3: Hum ab Google ko nahi, apne Server ko call kar rahe hain
21
- // Note: 'newPrompt' wala logic ab Server (api/server.js) ke paas hai,
22
- // isliye yahan se hata diya taki code simple rahe.
23
19
 
24
- // āš ļø CHANGE: Humne prompt me strict instruction add kar di hai
25
- // taaki AI response me comments na bheje.
26
20
  const body = {
27
21
  prompt: prompt + " . IMPORTANT: Return strictly code only. Do not include any comments, docstrings, or explanations inside the code files."
28
22
  };
@@ -36,47 +30,26 @@ async function generateProject(prompt, directoryName) {
36
30
  body: JSON.stringify(body),
37
31
  });
38
32
 
39
- if (!response.ok) {
40
- // Agar server down hai ya error hai
41
- const errorText = await response.text();
42
- console.error('āŒ Server Error:', response.status, errorText);
43
- throw new Error(`Server request failed with status ${response.status}`);
44
- }
45
-
46
33
  const data = await response.json();
47
- let responseText = data.candidates[0].content.parts[0].text;
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(']');
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;
59
- }
60
34
 
61
- // Sirf kaam ka JSON hissa nikalo
62
- let cleanJson = responseText.substring(jsonStartIndex, jsonEndIndex + 1);
63
-
64
- let files;
65
- try {
66
- files = JSON.parse(cleanJson);
67
- } catch (parseError) {
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;
35
+ // 1. Check Server Success
36
+ // Ab server khud bata dega ki success hua ya fail
37
+ if (!response.ok || !data.success) {
38
+ const errorMessage = data.error || 'Unknown Server Error';
39
+ console.error(`\nāŒ Server Error: ${errorMessage}`);
40
+ if (data.raw_response) {
41
+ console.log("Raw Output (Debug):", data.raw_response);
76
42
  }
43
+ return; // Stop here
77
44
  }
78
45
 
79
- if (!Array.isArray(files)) throw new Error("AI did not return a JSON array.");
46
+ // 2. Get Files Directly (No Parsing Needed)
47
+ // Server ne saaf-suthra array bheja hai
48
+ const files = data.files;
49
+
50
+ if (!Array.isArray(files)) {
51
+ throw new Error("Invalid response format: 'files' is not an array.");
52
+ }
80
53
 
81
54
  // --- FILE CREATION LOGIC ---
82
55
 
@@ -109,7 +82,7 @@ async function generateProject(prompt, directoryName) {
109
82
  // --- NEW YARGS SETUP ---
110
83
  yargs(hideBin(process.argv))
111
84
  .command(
112
- '$0 <prompt>', // The default command
85
+ '$0 <prompt>',
113
86
  'Generates a full project structure from a text prompt.',
114
87
  (yargs) => {
115
88
  return yargs
@@ -117,11 +90,11 @@ yargs(hideBin(process.argv))
117
90
  describe: 'The project you want to generate',
118
91
  type: 'string',
119
92
  })
120
- .option('directory', { // Replaces the old 'output' flag
93
+ .option('directory', {
121
94
  alias: 'd',
122
95
  describe: 'The name of the new directory to create the project in',
123
96
  type: 'string',
124
- demandOption: true, // This flag is now required
97
+ demandOption: true,
125
98
  });
126
99
  },
127
100
  (argv) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongossee",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {