ai-codegen-cli-vrk 2.1.1 → 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.1",
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,48 +1,34 @@
1
- import { GoogleGenerativeAI } from "@google/generative-ai";
2
-
3
- let genAI = null;
4
- let modelQueue = [];
5
- let currentModelIndex = 0;
1
+ let API_KEY = null;
2
+ let SELECTED_MODEL_PATH = null;
6
3
 
7
4
  export function setApiKey(apiKey) {
8
- genAI = new GoogleGenerativeAI(apiKey.trim());
5
+ API_KEY = apiKey;
9
6
  }
10
7
 
11
- /**
12
- * Lists all usable models and sorts them by stability.
13
- */
14
- async function refreshModelQueue() {
15
- if (modelQueue.length > 0) return;
16
-
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}`;
17
11
  try {
18
- const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${genAI.apiKey}`);
12
+ const response = await fetch(url);
19
13
  const data = await response.json();
20
-
21
- if (data.models) {
22
- // Prioritize 1.5-flash (most stable) then 2.0-flash (experimental)
23
- const usable = data.models
24
- .filter(m => m.supportedGenerationMethods.includes("generateContent"))
25
- .map(m => m.name.split('/').pop());
26
-
27
- const preferred = ["gemini-1.5-flash", "gemini-1.5-flash-latest", "gemini-2.0-flash-exp", "gemini-pro"];
28
-
29
- modelQueue = preferred.filter(p => usable.includes(p));
30
- // Add any other usable models found as backup
31
- usable.forEach(u => { if(!modelQueue.includes(u)) modelQueue.push(u); });
32
- }
33
- } catch (e) {
34
- modelQueue = ["gemini-1.5-flash", "gemini-pro"];
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;
35
24
  }
36
25
  }
37
26
 
38
27
  export async function generateFullProject(task, tests, retryCount = 0) {
39
- await refreshModelQueue();
28
+ const modelPath = await findActiveModel();
29
+ const url = `https://generativelanguage.googleapis.com/v1/${modelPath}:generateContent?key=${API_KEY}`;
40
30
 
41
- const modelName = modelQueue[currentModelIndex] || "gemini-1.5-flash";
42
- const model = genAI.getGenerativeModel({ model: modelName }, { apiVersion: "v1beta" });
43
-
44
- try {
45
- const prompt = `
31
+ const prompt = `
46
32
  Generate the ENTIRE project in a SINGLE response.
47
33
  Strictly pass all test cases.
48
34
 
@@ -59,35 +45,28 @@ TESTS:
59
45
  ${tests}
60
46
 
61
47
  ### RULES:
62
- - Minimalist logic.
48
+ - Minimalist logic only.
63
49
  - Bare minimum code to pass.
64
50
  - No talk or explanations.
65
51
  `;
66
52
 
67
- const result = await model.generateContent(prompt);
68
- const response = await result.response;
69
- const text = response.text();
70
- 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
+ });
71
58
 
72
- } catch (error) {
73
- const msg = error.message || "";
74
-
75
- // Handle Quota Exceeded (429) or Server Busy (503)
76
- if ((msg.includes("429") || msg.includes("quota") || msg.includes("503") || msg.includes("overloaded")) && retryCount < 5) {
77
-
78
- // If a specific model is exhausted, try to switch to the next one in the queue
79
- if (currentModelIndex < modelQueue.length - 1) {
80
- console.log(`..... (Model ${modelName} exhausted, switching to ${modelQueue[currentModelIndex+1]}...)`);
81
- currentModelIndex++;
82
- return generateFullProject(task, tests, retryCount + 1);
83
- }
59
+ const data = await response.json();
84
60
 
85
- // If all models are exhausted, wait a full 60 seconds
86
- console.log(`..... (All models busy/exhausted, waiting 60s to reset quota...)`);
87
- await new Promise(r => setTimeout(r, 60000));
88
- currentModelIndex = 0; // Reset queue and try again
89
- return generateFullProject(task, tests, retryCount + 1);
90
- }
91
- throw error;
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);
92
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();
93
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 {