ai-codegen-cli-vrk 2.1.0 → 2.2.0

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/bin/index.js CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  import "../src/runner.js";
package/package.json CHANGED
@@ -1,21 +1,20 @@
1
- {
2
- "name": "ai-codegen-cli-vrk",
3
- "version": "2.1.0",
4
- "description": "Minimalist Terminal-based AI code generator",
5
- "type": "module",
6
- "bin": {
7
- "ai-codegen": "bin/index.js"
8
- },
9
- "files": [
10
- "bin",
11
- "src"
12
- ],
13
- "dependencies": {
14
- "@google/generative-ai": "^0.21.0",
15
- "fs-extra": "^11.2.0",
16
- "readline-sync": "^1.4.10"
17
- },
18
- "engines": {
19
- "node": ">=18.0.0"
20
- }
1
+ {
2
+ "name": "ai-codegen-cli-vrk",
3
+ "version": "2.2.0",
4
+ "description": "Minimalist Terminal-based AI code generator",
5
+ "type": "module",
6
+ "bin": {
7
+ "ai-codegen": "bin/index.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "src"
12
+ ],
13
+ "dependencies": {
14
+ "fs-extra": "^11.2.0",
15
+ "readline-sync": "^1.4.10"
16
+ },
17
+ "engines": {
18
+ "node": ">=18.0.0"
19
+ }
21
20
  }
package/src/aiClient.js CHANGED
@@ -1,52 +1,34 @@
1
- import { GoogleGenerativeAI } from "@google/generative-ai";
2
-
3
- let genAI = null;
4
- let activeModel = null;
1
+ let API_KEY = null;
2
+ let SELECTED_MODEL_PATH = null;
5
3
 
6
4
  export function setApiKey(apiKey) {
7
- genAI = new GoogleGenerativeAI(apiKey.trim());
5
+ API_KEY = apiKey;
8
6
  }
9
7
 
10
- /**
11
- * Ultimate discovery: Asks Google for a list of working models for your key.
12
- */
13
- async function getWorkingModel() {
14
- if (activeModel) return activeModel;
15
-
8
+ async function findActiveModel() {
9
+ if (SELECTED_MODEL_PATH) return SELECTED_MODEL_PATH;
10
+ const url = `https://generativelanguage.googleapis.com/v1/models?key=${API_KEY}`;
16
11
  try {
17
- // Attempt to list models to see what this specific key is allowed to use
18
- // We use v1beta as it has the most complete model list
19
- const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${genAI.apiKey}`);
12
+ const response = await fetch(url);
20
13
  const data = await response.json();
21
-
22
- if (data.models) {
23
- // Look for 1.5-flash or 2.0-flash in the permitted list
24
- const best = data.models.find(m =>
25
- m.supportedGenerationMethods.includes("generateContent") &&
26
- (m.name.includes("1.5-flash") || m.name.includes("2.0-flash"))
27
- );
28
-
29
- if (best) {
30
- // Strip "models/" prefix if present for the SDK
31
- const modelName = best.name.split('/').pop();
32
- activeModel = genAI.getGenerativeModel({ model: modelName }, { apiVersion: "v1beta" });
33
- return activeModel;
34
- }
35
- }
36
- } catch (e) {
37
- // If listing fails, fall back to a safe guess
14
+ if (!response.ok) throw new Error(data.error?.message || "Invalid API Key");
15
+ const match = (data.models || []).find(m =>
16
+ m.supportedGenerationMethods.includes("generateContent") &&
17
+ (m.name.includes("flash") || m.name.includes("pro"))
18
+ );
19
+ SELECTED_MODEL_PATH = match ? match.name : "models/gemini-1.5-flash";
20
+ return SELECTED_MODEL_PATH;
21
+ } catch {
22
+ SELECTED_MODEL_PATH = "models/gemini-1.5-flash";
23
+ return SELECTED_MODEL_PATH;
38
24
  }
39
-
40
- // Final fallback to the most common working model
41
- activeModel = genAI.getGenerativeModel({ model: "gemini-1.5-flash" }, { apiVersion: "v1beta" });
42
- return activeModel;
43
25
  }
44
26
 
45
27
  export async function generateFullProject(task, tests, retryCount = 0) {
46
- try {
47
- const model = await getWorkingModel();
48
-
49
- const prompt = `
28
+ const modelPath = await findActiveModel();
29
+ const url = `https://generativelanguage.googleapis.com/v1/${modelPath}:generateContent?key=${API_KEY}`;
30
+
31
+ const prompt = `
50
32
  Generate the ENTIRE project in a SINGLE response.
51
33
  Strictly pass all test cases.
52
34
 
@@ -63,24 +45,28 @@ TESTS:
63
45
  ${tests}
64
46
 
65
47
  ### RULES:
66
- - Minimalist logic.
48
+ - Minimalist logic only.
67
49
  - Bare minimum code to pass.
68
50
  - No talk or explanations.
69
51
  `;
70
52
 
71
- const result = await model.generateContent(prompt);
72
- const response = await result.response;
73
- const text = response.text();
74
- return text.replace(/```[a-z]*\n([\s\S]*?)\n```/gi, "$1").trim();
53
+ const response = await fetch(url, {
54
+ method: "POST",
55
+ headers: { "Content-Type": "application/json" },
56
+ body: JSON.stringify({ contents: [{ parts: [{ text: prompt }] }] })
57
+ });
75
58
 
76
- } catch (error) {
77
- // Handle Overloaded (503) or Rate Limit (429) - Critical for Free Tier
78
- const msg = error.message || "";
79
- if ((msg.includes("503") || msg.includes("429") || msg.includes("overloaded")) && retryCount < 5) {
80
- console.log(`..... (Server busy, waiting 15s to retry ${retryCount + 1}/5)`);
81
- await new Promise(r => setTimeout(r, 15000));
82
- return generateFullProject(task, tests, retryCount + 1);
83
- }
84
- throw error;
59
+ const data = await response.json();
60
+
61
+ // If overloaded (503) or rate limited (429), wait 10 seconds and retry
62
+ if ((response.status === 503 || response.status === 429) && retryCount < 5) {
63
+ console.log(`..... (Server busy, waiting 10s to retry ${retryCount + 1}/5)`);
64
+ await new Promise(r => setTimeout(r, 10000));
65
+ return generateFullProject(task, tests, retryCount + 1);
85
66
  }
67
+
68
+ if (!response.ok) throw new Error(data.error?.message || "Generation failed");
69
+
70
+ const text = data.candidates?.[0]?.content?.parts?.[0]?.text || "";
71
+ return text.replace(/```[a-z]*\n([\s\S]*?)\n```/gi, "$1").trim();
86
72
  }
@@ -0,0 +1,13 @@
1
+ // ==========================================
2
+ // FILE: palindrome_checker.py
3
+ // ==========================================
4
+
5
+ def is_palindrome(text):
6
+ return text == text[::-1]
7
+
8
+ if __name__ == "__main__":
9
+ user_input = input("Enter a string: ")
10
+ if is_palindrome(user_input):
11
+ print("It is a palindrome.")
12
+ else:
13
+ print("It is not a palindrome.")
package/src/runner.js CHANGED
@@ -4,13 +4,16 @@ import { setApiKey, generateFullProject } from "./aiClient.js";
4
4
  import { writeSingleFile } from "./fileWriter.js";
5
5
 
6
6
  async function main() {
7
- const apiKeyInput = readlineSync.question("--- ", { hideEchoBack: false });
8
- if (!apiKeyInput || apiKeyInput.trim().length === 0) process.exit(1);
9
- setApiKey(apiKeyInput.trim());
7
+ // Input API Key - set to visible
8
+ const apiKey = readlineSync.question("--- ", { hideEchoBack: false });
9
+ if (!apiKey || apiKey.trim().length === 0) process.exit(1);
10
+ setApiKey(apiKey.trim());
10
11
 
12
+ // Input Task
11
13
  const task = readlineSync.question("- ");
12
14
  if (!task || task.trim().length === 0) process.exit(1);
13
15
 
16
+ // Input Tests
14
17
  const testsInput = readlineSync.question("-- ");
15
18
  let tests = "";
16
19
  try {