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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-codegen-cli-vrk",
3
- "version": "2.0.2",
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
- import { GoogleGenerativeAI } from "@google/generative-ai";
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
- genAI = new GoogleGenerativeAI(apiKey);
5
+ API_KEY = apiKey;
8
6
  }
9
7
 
10
8
  /**
11
- * Automatically finds a model that doesn't return 404
9
+ * Automatically finds a model that is active for your account.
10
+ * This prevents the "404 Not Found" error.
12
11
  */
13
- async function getWorkingModel() {
14
- if (SELECTED_MODEL_NAME) return genAI.getGenerativeModel({ model: SELECTED_MODEL_NAME });
12
+ async function findActiveModel() {
13
+ if (SELECTED_MODEL_PATH) return SELECTED_MODEL_PATH;
15
14
 
16
- const candidates = ["gemini-1.5-flash", "gemini-1.5-flash-latest", "gemini-pro"];
15
+ // Use the stable v1 API to list models
16
+ const url = `https://generativelanguage.googleapis.com/v1/models?key=${API_KEY}`;
17
17
 
18
- for (const name of candidates) {
19
- try {
20
- const model = genAI.getGenerativeModel({ model: name });
21
- // Quick test call to verify if model exists for this key
22
- await model.generateContent({ contents: [{ role: "user", parts: [{ text: "hi" }] }], generationConfig: { maxOutputTokens: 5 } });
23
- SELECTED_MODEL_NAME = name;
24
- return model;
25
- } catch (err) {
26
- // If it's a 404, try the next model
27
- if (err.message.includes("404")) continue;
28
- throw err; // Stop if it's an Auth or Quota error
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
- throw new Error("No compatible Gemini models found for your API key.");
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
- if (!genAI) throw new Error("API Key not initialized");
36
-
37
- const model = await getWorkingModel();
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
- You are an expert automated coding exam solver.
41
- Generate the ENTIRE project in a SINGLE continuous text response.
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 result = await model.generateContent(prompt);
72
- const response = await result.response;
73
- const text = response.text();
74
-
75
- // Clean markdown backticks
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 < 20) {
31
- throw new Error("AI output too short or empty.");
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);