ai-codegen-cli-vrk 2.0.0 → 2.0.1
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/package.json +3 -2
- package/src/aiClient.js +18 -40
- package/src/runner.js +9 -12
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-codegen-cli-vrk",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "Minimalist Terminal-based AI code generator
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Minimalist Terminal-based AI code generator",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"ai-codegen": "bin/index.js"
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"src"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
+
"@google/generative-ai": "^0.21.0",
|
|
14
15
|
"fs-extra": "^11.2.0",
|
|
15
16
|
"readline-sync": "^1.4.10"
|
|
16
17
|
},
|
package/src/aiClient.js
CHANGED
|
@@ -1,43 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
let SELECTED_MODEL = null;
|
|
1
|
+
import { GoogleGenerativeAI } from "@google/generative-ai";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
3
|
+
let genAI = null;
|
|
4
|
+
let model = null;
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (SELECTED_MODEL) return SELECTED_MODEL;
|
|
13
|
-
const url = `https://generativelanguage.googleapis.com/v1/models?key=${API_KEY}`;
|
|
14
|
-
try {
|
|
15
|
-
const response = await fetch(url);
|
|
16
|
-
const data = await response.json();
|
|
17
|
-
if (!response.ok) throw new Error();
|
|
18
|
-
const found = (data.models || []).find(m =>
|
|
19
|
-
m.supportedGenerationMethods.includes("generateContent") &&
|
|
20
|
-
(m.name.includes("flash") || m.name.includes("pro"))
|
|
21
|
-
);
|
|
22
|
-
SELECTED_MODEL = found ? found.name : "models/gemini-1.5-flash";
|
|
23
|
-
return SELECTED_MODEL;
|
|
24
|
-
} catch {
|
|
25
|
-
SELECTED_MODEL = "models/gemini-1.5-flash";
|
|
26
|
-
return SELECTED_MODEL;
|
|
27
|
-
}
|
|
6
|
+
export function setApiKey(apiKey) {
|
|
7
|
+
genAI = new GoogleGenerativeAI(apiKey);
|
|
8
|
+
// Using 1.5-flash for speed and large context window
|
|
9
|
+
model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
|
|
28
10
|
}
|
|
29
11
|
|
|
30
12
|
export async function generateFullProject(task, tests) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
13
|
+
if (!genAI) throw new Error("API Key not set");
|
|
14
|
+
|
|
34
15
|
const prompt = `
|
|
35
16
|
You are an expert automated coding exam solver.
|
|
36
17
|
Generate the ENTIRE project in a SINGLE continuous text response.
|
|
37
18
|
|
|
38
19
|
### RULES:
|
|
39
20
|
1. ABSOLUTE PRIORITY: Test cases are the ONLY specification.
|
|
40
|
-
2. MINIMALIST: Generate the bare minimum code to pass. No extra logic
|
|
21
|
+
2. MINIMALIST: Generate the bare minimum code to pass. No extra logic.
|
|
41
22
|
3. FLAT STRUCTURE: Use simple, standard patterns.
|
|
42
23
|
4. DEPENDENCIES: Only use 'express', 'mongoose', 'jsonwebtoken', and 'cookie-parser' if needed.
|
|
43
24
|
|
|
@@ -61,18 +42,15 @@ ${task}
|
|
|
61
42
|
|
|
62
43
|
### TESTS:
|
|
63
44
|
${tests}
|
|
64
|
-
`;
|
|
65
|
-
|
|
66
|
-
const response = await fetch(url, {
|
|
67
|
-
method: "POST",
|
|
68
|
-
headers: { "Content-Type": "application/json" },
|
|
69
|
-
body: JSON.stringify({ contents: [{ parts: [{ text: prompt }] }] })
|
|
70
|
-
});
|
|
71
45
|
|
|
72
|
-
|
|
73
|
-
|
|
46
|
+
### OUTPUT:
|
|
47
|
+
Return ONLY the code sections. No talk. No markdown backticks.
|
|
48
|
+
`;
|
|
74
49
|
|
|
75
|
-
const
|
|
76
|
-
|
|
50
|
+
const result = await model.generateContent(prompt);
|
|
51
|
+
const response = await result.response;
|
|
52
|
+
const text = response.text();
|
|
53
|
+
|
|
54
|
+
// Strip markdown backticks in case AI adds them
|
|
77
55
|
return text.replace(/```[a-z]*\n([\s\S]*?)\n```/gi, "$1").trim();
|
|
78
56
|
}
|
package/src/runner.js
CHANGED
|
@@ -4,16 +4,14 @@ import { setApiKey, generateFullProject } from "./aiClient.js";
|
|
|
4
4
|
import { writeSingleFile } from "./fileWriter.js";
|
|
5
5
|
|
|
6
6
|
async function main() {
|
|
7
|
-
//
|
|
8
|
-
const apiKey = readlineSync.question("--- "
|
|
7
|
+
// Visible prompt for API key
|
|
8
|
+
const apiKey = readlineSync.question("--- ");
|
|
9
9
|
if (!apiKey || apiKey.trim().length === 0) process.exit(1);
|
|
10
10
|
setApiKey(apiKey.trim());
|
|
11
11
|
|
|
12
|
-
// Input: Task
|
|
13
12
|
const task = readlineSync.question("- ");
|
|
14
13
|
if (!task || task.trim().length === 0) process.exit(1);
|
|
15
14
|
|
|
16
|
-
// Input: Test cases (Path or Raw Text)
|
|
17
15
|
const testsInput = readlineSync.question("-- ");
|
|
18
16
|
let tests = "";
|
|
19
17
|
try {
|
|
@@ -27,19 +25,18 @@ async function main() {
|
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
try {
|
|
30
|
-
// Silent Indicator
|
|
31
28
|
console.log(".....");
|
|
32
|
-
|
|
33
|
-
// Process Single Request
|
|
34
29
|
const projectContent = await generateFullProject(task, tests);
|
|
35
30
|
|
|
36
|
-
|
|
31
|
+
if (!projectContent || projectContent.length < 20) {
|
|
32
|
+
throw new Error("AI returned no project content. Check your prompt.");
|
|
33
|
+
}
|
|
34
|
+
|
|
37
35
|
await writeSingleFile(process.cwd(), projectContent);
|
|
38
|
-
|
|
39
|
-
// Silent Exit on Success
|
|
40
36
|
process.exit(0);
|
|
41
|
-
} catch {
|
|
42
|
-
//
|
|
37
|
+
} catch (error) {
|
|
38
|
+
// Report errors explicitly instead of exiting silently
|
|
39
|
+
console.error("\n❌ Error:", error.message);
|
|
43
40
|
process.exit(1);
|
|
44
41
|
}
|
|
45
42
|
}
|