mongossee 1.0.12 ā 1.0.13
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/api/server.js +53 -0
- package/index.js +115 -1
- package/package.json +1 -1
package/api/server.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// File: api/server.js
|
|
2
|
+
|
|
3
|
+
export const config = {
|
|
4
|
+
runtime: 'edge', // Code ko fast banata hai
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export default async function handler(req) {
|
|
8
|
+
// 1. Sirf POST request accept karein
|
|
9
|
+
if (req.method !== 'POST') {
|
|
10
|
+
return new Response(JSON.stringify({ error: 'Method Not Allowed' }), { status: 405 });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
// 2. User ke computer se PROMPT receive karein
|
|
15
|
+
const { prompt } = await req.json();
|
|
16
|
+
|
|
17
|
+
// 3. Vercel ke safe locker se API Key nikalein
|
|
18
|
+
// (Ye key code me nahi likhi hai, ye Vercel settings se aayegi)
|
|
19
|
+
const API_KEY = process.env.GEMINI_API_KEY;
|
|
20
|
+
|
|
21
|
+
if (!API_KEY) {
|
|
22
|
+
return new Response(JSON.stringify({ error: 'Server Error: API Key missing' }), { status: 500 });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 4. Google Gemini API URL
|
|
26
|
+
const googleUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${API_KEY}`;
|
|
27
|
+
|
|
28
|
+
// 5. Naya Prompt Structure banayein
|
|
29
|
+
const finalPrompt = `
|
|
30
|
+
You are an expert developer. Generate a JSON array of files.
|
|
31
|
+
Response format: [{"filename": "string", "code": "string"}]
|
|
32
|
+
User Prompt: "${prompt}"
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
// 6. Google ko request bhejein
|
|
36
|
+
const googleResponse = await fetch(googleUrl, {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
headers: { 'Content-Type': 'application/json' },
|
|
39
|
+
body: JSON.stringify({ contents: [{ parts: [{ text: finalPrompt }] }] })
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const data = await googleResponse.json();
|
|
43
|
+
|
|
44
|
+
// 7. Result wapis user ko bhejein
|
|
45
|
+
return new Response(JSON.stringify(data), {
|
|
46
|
+
status: 200,
|
|
47
|
+
headers: { 'Content-Type': 'application/json' }
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
} catch (error) {
|
|
51
|
+
return new Response(JSON.stringify({ error: error.message }), { status: 500 });
|
|
52
|
+
}
|
|
53
|
+
}
|
package/index.js
CHANGED
|
@@ -1 +1,115 @@
|
|
|
1
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs'); // Node.js File System
|
|
4
|
+
const path = require('path'); // Node.js Path module
|
|
5
|
+
const yargs = require('yargs/yargs');
|
|
6
|
+
const { hideBin } = require('yargs/helpers');
|
|
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.
|
|
10
|
+
const SERVER_URL = "https://mongossee.vercel.app/api/server";
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Generates a full project structure based on a prompt.
|
|
15
|
+
* @param {string} prompt - The user's project request.
|
|
16
|
+
* @param {string} directoryName - The name of the folder to create the project in.
|
|
17
|
+
*/
|
|
18
|
+
async function generateProject(prompt, directoryName) {
|
|
19
|
+
|
|
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
|
+
|
|
24
|
+
const body = {
|
|
25
|
+
prompt: prompt // Sirf user ka prompt bhej rahe hain
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
console.log(`Code Running in Expresss`);
|
|
30
|
+
|
|
31
|
+
const response = await fetch(SERVER_URL, {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
headers: { 'Content-Type': 'application/json' },
|
|
34
|
+
body: JSON.stringify(body),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
// Agar server down hai ya error hai
|
|
39
|
+
const errorText = await response.text();
|
|
40
|
+
console.error('ā Server Error:', response.status, errorText);
|
|
41
|
+
throw new Error(`Server request failed with status ${response.status}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const data = await response.json();
|
|
45
|
+
let responseText = data.candidates[0].content.parts[0].text;
|
|
46
|
+
|
|
47
|
+
// --- NEW JSON PARSING & FILE CREATION LOGIC ---
|
|
48
|
+
// console.log("Building project...");
|
|
49
|
+
|
|
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();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let files;
|
|
56
|
+
try {
|
|
57
|
+
files = JSON.parse(responseText);
|
|
58
|
+
if (!Array.isArray(files)) throw new Error("AI did not return a JSON array.");
|
|
59
|
+
} 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;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Create the main project directory
|
|
66
|
+
fs.mkdirSync(directoryName, { recursive: true });
|
|
67
|
+
console.log(``);
|
|
68
|
+
|
|
69
|
+
// Loop through the files array and create each file
|
|
70
|
+
for (const file of files) {
|
|
71
|
+
const filePath = path.join(directoryName, file.filename);
|
|
72
|
+
const fileDir = path.dirname(filePath);
|
|
73
|
+
|
|
74
|
+
// Create subdirectories if they don't exist
|
|
75
|
+
if (!fs.existsSync(fileDir)) {
|
|
76
|
+
fs.mkdirSync(fileDir, { recursive: true });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Write the code to the file
|
|
80
|
+
fs.writeFileSync(filePath, file.code);
|
|
81
|
+
//console.log(`Created file: ${filePath}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// console.log(`\nš Project "${directoryName}" created successfully!`);
|
|
85
|
+
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error('ā An error occurred:', error.message);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// --- NEW YARGS SETUP ---
|
|
92
|
+
yargs(hideBin(process.argv))
|
|
93
|
+
.command(
|
|
94
|
+
'$0 <prompt>', // The default command
|
|
95
|
+
'Generates a full project structure from a text prompt.',
|
|
96
|
+
(yargs) => {
|
|
97
|
+
return yargs
|
|
98
|
+
.positional('prompt', {
|
|
99
|
+
describe: 'The project you want to generate',
|
|
100
|
+
type: 'string',
|
|
101
|
+
})
|
|
102
|
+
.option('directory', { // Replaces the old 'output' flag
|
|
103
|
+
alias: 'd',
|
|
104
|
+
describe: 'The name of the new directory to create the project in',
|
|
105
|
+
type: 'string',
|
|
106
|
+
demandOption: true, // This flag is now required
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
(argv) => {
|
|
110
|
+
|
|
111
|
+
generateProject(argv.prompt, argv.directory);
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
.demandCommand(1, 'Please provide a prompt.')
|
|
115
|
+
.parse();
|