ai-codegen-cli-vrk 2.0.7 → 2.0.8

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.8",
4
4
  "description": "Minimalist Terminal-based AI code generator",
5
5
  "type": "module",
6
6
  "bin": {
package/src/aiClient.js CHANGED
@@ -4,31 +4,41 @@ 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
 
12
10
  async function getWorkingModel() {
13
11
  if (activeModel) return activeModel;
14
12
 
15
- const candidates = ["gemini-1.5-flash", "gemini-1.5-flash-latest", "gemini-pro"];
13
+ const modelNames = ["gemini-1.5-flash", "gemini-pro", "gemini-1.5-flash-latest"];
14
+ const apiVersions = ["v1beta", "v1"];
16
15
 
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;
16
+ let lastError = null;
17
+
18
+ for (const ver of apiVersions) {
19
+ for (const name of modelNames) {
20
+ try {
21
+ const m = genAI.getGenerativeModel({ model: name }, { apiVersion: ver });
22
+ // Minimal verification call
23
+ await m.generateContent({
24
+ contents: [{ role: "user", parts: [{ text: "hi" }] }],
25
+ generationConfig: { maxOutputTokens: 1 }
26
+ });
27
+ activeModel = m;
28
+ return m;
29
+ } catch (err) {
30
+ lastError = err;
31
+ // If it's a 404, this combination is invalid; try next.
32
+ if (err.message.includes("404") || err.message.includes("not found")) continue;
33
+ // If it's an Auth error, stop and throw it.
34
+ if (err.message.includes("API key not valid") || err.message.includes("401")) {
35
+ throw new Error("Invalid API Key. Please check it at aistudio.google.com");
36
+ }
37
+ }
29
38
  }
30
39
  }
31
- throw new Error("No compatible Gemini models found.");
40
+
41
+ throw new Error(`Connection Failed. Last error: ${lastError?.message || "Unknown"}`);
32
42
  }
33
43
 
34
44
  export async function generateFullProject(task, tests, retryCount = 0) {
@@ -36,6 +46,7 @@ export async function generateFullProject(task, tests, retryCount = 0) {
36
46
  const model = await getWorkingModel();
37
47
 
38
48
  const prompt = `
49
+ You are an expert automated coding exam solver.
39
50
  Generate the ENTIRE project in a SINGLE response.
40
51
  Strictly pass all test cases.
41
52
 
@@ -63,11 +74,7 @@ ${tests}
63
74
  return text.replace(/```[a-z]*\n([\s\S]*?)\n```/gi, "$1").trim();
64
75
 
65
76
  } 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
-
77
+ // Handle Overloaded (503) or Rate Limit (429)
71
78
  if ((error.message.includes("503") || error.message.includes("429")) && retryCount < 5) {
72
79
  console.log(`..... (Server busy, retrying ${retryCount + 1}/5)`);
73
80
  await new Promise(r => setTimeout(r, 10000));
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("- ");