ai-codegen-cli-vrk 2.0.2 → 2.0.3
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 +4 -2
- package/src/aiClient.js +54 -38
- package/src/runner.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-codegen-cli-vrk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "Minimalist Terminal-based AI code generator",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
"src"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@google/generative-ai": "^0.21.0",
|
|
15
14
|
"fs-extra": "^11.2.0",
|
|
16
15
|
"readline-sync": "^1.4.10"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18.0.0"
|
|
17
19
|
}
|
|
18
20
|
}
|
package/src/aiClient.js
CHANGED
|
@@ -1,50 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
let genAI = null;
|
|
4
|
-
let SELECTED_MODEL_NAME = null;
|
|
1
|
+
let API_KEY = null;
|
|
2
|
+
let SELECTED_MODEL_PATH = null;
|
|
5
3
|
|
|
6
4
|
export function setApiKey(apiKey) {
|
|
7
|
-
|
|
5
|
+
API_KEY = apiKey;
|
|
8
6
|
}
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
|
-
* Automatically finds a model that
|
|
9
|
+
* Automatically finds a model that is active for your account.
|
|
10
|
+
* This prevents the "404 Not Found" error.
|
|
12
11
|
*/
|
|
13
|
-
async function
|
|
14
|
-
if (
|
|
12
|
+
async function findActiveModel() {
|
|
13
|
+
if (SELECTED_MODEL_PATH) return SELECTED_MODEL_PATH;
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
// Use the stable v1 API to list models
|
|
16
|
+
const url = `https://generativelanguage.googleapis.com/v1/models?key=${API_KEY}`;
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
try {
|
|
19
|
+
const response = await fetch(url);
|
|
20
|
+
const data = await response.json();
|
|
21
|
+
|
|
22
|
+
if (!response.ok) throw new Error(data.error?.message || "Invalid API Key");
|
|
23
|
+
|
|
24
|
+
// Find the first model that supports content generation
|
|
25
|
+
const models = data.models || [];
|
|
26
|
+
const match = models.find(m =>
|
|
27
|
+
m.supportedGenerationMethods.includes("generateContent") &&
|
|
28
|
+
(m.name.includes("flash") || m.name.includes("pro"))
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (match) {
|
|
32
|
+
SELECTED_MODEL_PATH = match.name; // e.g. "models/gemini-1.5-flash"
|
|
33
|
+
return SELECTED_MODEL_PATH;
|
|
29
34
|
}
|
|
35
|
+
} catch (err) {
|
|
36
|
+
// If listing fails, fall back to a standard guess
|
|
30
37
|
}
|
|
31
|
-
|
|
38
|
+
|
|
39
|
+
SELECTED_MODEL_PATH = "models/gemini-1.5-flash";
|
|
40
|
+
return SELECTED_MODEL_PATH;
|
|
32
41
|
}
|
|
33
42
|
|
|
34
43
|
export async function generateFullProject(task, tests) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
const modelPath = await findActiveModel();
|
|
45
|
+
|
|
46
|
+
// Use v1 (stable) to avoid v1beta 404 issues
|
|
47
|
+
const url = `https://generativelanguage.googleapis.com/v1/${modelPath}:generateContent?key=${API_KEY}`;
|
|
48
|
+
|
|
39
49
|
const prompt = `
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
### RULES:
|
|
44
|
-
1. Test cases are the ONLY specification.
|
|
45
|
-
2. MINIMALIST: Bare minimum code to pass. No extra logic.
|
|
46
|
-
3. FLAT STRUCTURE: Standard patterns.
|
|
47
|
-
4. No talk, no explanations.
|
|
50
|
+
Generate the ENTIRE coding project in a SINGLE continuous text response.
|
|
51
|
+
Strictly pass all test cases.
|
|
48
52
|
|
|
49
53
|
### FORMATTING (STRICT):
|
|
50
54
|
Every file MUST start with this EXACT header style:
|
|
@@ -66,12 +70,24 @@ ${task}
|
|
|
66
70
|
|
|
67
71
|
### TESTS:
|
|
68
72
|
${tests}
|
|
73
|
+
|
|
74
|
+
### RULES:
|
|
75
|
+
- Minimalist logic. No extra logic.
|
|
76
|
+
- Bare minimum code to pass.
|
|
77
|
+
- No explanations.
|
|
69
78
|
`;
|
|
70
79
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
const response = await fetch(url, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: { "Content-Type": "application/json" },
|
|
83
|
+
body: JSON.stringify({
|
|
84
|
+
contents: [{ parts: [{ text: prompt }] }]
|
|
85
|
+
})
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const data = await response.json();
|
|
89
|
+
if (!response.ok) throw new Error(data.error?.message || "Generation failed");
|
|
90
|
+
|
|
91
|
+
const text = data.candidates?.[0]?.content?.parts?.[0]?.text || "";
|
|
76
92
|
return text.replace(/```[a-z]*\n([\s\S]*?)\n```/gi, "$1").trim();
|
|
77
93
|
}
|
package/src/runner.js
CHANGED
|
@@ -27,8 +27,8 @@ async function main() {
|
|
|
27
27
|
console.log(".....");
|
|
28
28
|
const projectContent = await generateFullProject(task, tests);
|
|
29
29
|
|
|
30
|
-
if (!projectContent || projectContent.length <
|
|
31
|
-
throw new Error("AI
|
|
30
|
+
if (!projectContent || projectContent.length < 50) {
|
|
31
|
+
throw new Error("AI returned empty content. Check your task/tests.");
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
await writeSingleFile(process.cwd(), projectContent);
|