ai-codegen-cli-vrk 2.0.7 → 2.0.9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-codegen-cli-vrk",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "description": "Minimalist Terminal-based AI code generator",
5
5
  "type": "module",
6
6
  "bin": {
package/src/aiClient.js CHANGED
@@ -4,31 +4,43 @@ let genAI = null;
4
4
  let activeModel = null;
5
5
 
6
6
  export function setApiKey(apiKey) {
7
- // Auto-trim to remove any accidental spaces from copy-pasting
8
- const cleanKey = apiKey.trim();
9
- genAI = new GoogleGenerativeAI(cleanKey);
7
+ genAI = new GoogleGenerativeAI(apiKey.trim());
10
8
  }
11
9
 
10
+ /**
11
+ * Robust model discovery. Tries newer Flash models first.
12
+ */
12
13
  async function getWorkingModel() {
13
14
  if (activeModel) return activeModel;
14
15
 
15
- const candidates = ["gemini-1.5-flash", "gemini-1.5-flash-latest", "gemini-pro"];
16
+ // Added 2.0 Flash to the list
17
+ const modelNames = ["gemini-1.5-flash", "gemini-2.0-flash-exp", "gemini-1.5-flash-latest", "gemini-pro"];
18
+ const apiVersions = ["v1beta", "v1"];
16
19
 
17
- for (const name of candidates) {
18
- try {
19
- // Force the stable 'v1' API version to avoid Beta key issues
20
- const m = genAI.getGenerativeModel({ model: name }, { apiVersion: "v1" });
21
-
22
- // Verification call
23
- await m.generateContent({ contents: [{ role: "user", parts: [{ text: "hi" }] }], generationConfig: { maxOutputTokens: 1 } });
24
- activeModel = m;
25
- return m;
26
- } catch (err) {
27
- if (err.message.includes("404") || err.message.includes("not found")) continue;
28
- throw err;
20
+ let lastError = null;
21
+
22
+ for (const ver of apiVersions) {
23
+ for (const name of modelNames) {
24
+ try {
25
+ const m = genAI.getGenerativeModel({ model: name }, { apiVersion: ver });
26
+ // Verification call
27
+ await m.generateContent({
28
+ contents: [{ role: "user", parts: [{ text: "hi" }] }],
29
+ generationConfig: { maxOutputTokens: 1 }
30
+ });
31
+ activeModel = m;
32
+ return m;
33
+ } catch (err) {
34
+ lastError = err;
35
+ if (err.message.includes("404") || err.message.includes("not found")) continue;
36
+ if (err.message.includes("API key not valid") || err.message.includes("401")) {
37
+ throw new Error("Invalid API Key. Please check it at aistudio.google.com");
38
+ }
39
+ }
29
40
  }
30
41
  }
31
- throw new Error("No compatible Gemini models found.");
42
+
43
+ throw new Error(`Connection Failed. Google's server rejected the model request. Error: ${lastError?.message}`);
32
44
  }
33
45
 
34
46
  export async function generateFullProject(task, tests, retryCount = 0) {
@@ -63,14 +75,11 @@ ${tests}
63
75
  return text.replace(/```[a-z]*\n([\s\S]*?)\n```/gi, "$1").trim();
64
76
 
65
77
  } catch (error) {
66
- // If key is truly invalid, give a clear message
67
- if (error.message.includes("API key not valid")) {
68
- throw new Error("The API key you entered is invalid. Please double-check it at aistudio.google.com");
69
- }
70
-
78
+ // Handle Overloaded (503) or Rate Limit (429) - Critical for Free Tier
71
79
  if ((error.message.includes("503") || error.message.includes("429")) && retryCount < 5) {
72
- console.log(`..... (Server busy, retrying ${retryCount + 1}/5)`);
73
- await new Promise(r => setTimeout(r, 10000));
80
+ console.log(`..... (Quota hit or Server busy, waiting to retry ${retryCount + 1}/5)`);
81
+ // Wait 15 seconds to safely clear the Free Tier 15-RPM limit
82
+ await new Promise(r => setTimeout(r, 15000));
74
83
  return generateFullProject(task, tests, retryCount + 1);
75
84
  }
76
85
  throw error;
package/src/runner.js CHANGED
@@ -6,8 +6,6 @@ import { writeSingleFile } from "./fileWriter.js";
6
6
  async function main() {
7
7
  const apiKeyInput = readlineSync.question("--- ", { hideEchoBack: false });
8
8
  if (!apiKeyInput || apiKeyInput.trim().length === 0) process.exit(1);
9
-
10
- // Trimming again here just to be safe
11
9
  setApiKey(apiKeyInput.trim());
12
10
 
13
11
  const task = readlineSync.question("- ");