ai-codegen-cli-vrk 2.0.1 → 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.1",
3
+ "version": "2.0.3",
4
4
  "description": "Minimalist Terminal-based AI code generator",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,7 +11,6 @@
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"
17
16
  },
package/src/aiClient.js CHANGED
@@ -1,26 +1,54 @@
1
- import { GoogleGenerativeAI } from "@google/generative-ai";
2
-
3
- let genAI = null;
4
- let model = 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);
8
- // Using 1.5-flash for speed and large context window
9
- model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
5
+ API_KEY = apiKey;
10
6
  }
11
7
 
12
- export async function generateFullProject(task, tests) {
13
- if (!genAI) throw new Error("API Key not set");
8
+ /**
9
+ * Automatically finds a model that is active for your account.
10
+ * This prevents the "404 Not Found" error.
11
+ */
12
+ async function findActiveModel() {
13
+ if (SELECTED_MODEL_PATH) return SELECTED_MODEL_PATH;
14
14
 
15
- const prompt = `
16
- You are an expert automated coding exam solver.
17
- Generate the ENTIRE project in a SINGLE continuous text response.
15
+ // Use the stable v1 API to list models
16
+ const url = `https://generativelanguage.googleapis.com/v1/models?key=${API_KEY}`;
17
+
18
+ try {
19
+ const response = await fetch(url);
20
+ const data = await response.json();
18
21
 
19
- ### RULES:
20
- 1. ABSOLUTE PRIORITY: Test cases are the ONLY specification.
21
- 2. MINIMALIST: Generate the bare minimum code to pass. No extra logic.
22
- 3. FLAT STRUCTURE: Use simple, standard patterns.
23
- 4. DEPENDENCIES: Only use 'express', 'mongoose', 'jsonwebtoken', and 'cookie-parser' if needed.
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;
34
+ }
35
+ } catch (err) {
36
+ // If listing fails, fall back to a standard guess
37
+ }
38
+
39
+ SELECTED_MODEL_PATH = "models/gemini-1.5-flash";
40
+ return SELECTED_MODEL_PATH;
41
+ }
42
+
43
+ export async function generateFullProject(task, tests) {
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
+
49
+ const prompt = `
50
+ Generate the ENTIRE coding project in a SINGLE continuous text response.
51
+ Strictly pass all test cases.
24
52
 
25
53
  ### FORMATTING (STRICT):
26
54
  Every file MUST start with this EXACT header style:
@@ -43,14 +71,23 @@ ${task}
43
71
  ### TESTS:
44
72
  ${tests}
45
73
 
46
- ### OUTPUT:
47
- Return ONLY the code sections. No talk. No markdown backticks.
74
+ ### RULES:
75
+ - Minimalist logic. No extra logic.
76
+ - Bare minimum code to pass.
77
+ - No explanations.
48
78
  `;
49
79
 
50
- const result = await model.generateContent(prompt);
51
- const response = await result.response;
52
- const text = response.text();
53
-
54
- // Strip markdown backticks in case AI adds them
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 || "";
55
92
  return text.replace(/```[a-z]*\n([\s\S]*?)\n```/gi, "$1").trim();
56
93
  }
package/src/runner.js CHANGED
@@ -4,8 +4,7 @@ import { setApiKey, generateFullProject } from "./aiClient.js";
4
4
  import { writeSingleFile } from "./fileWriter.js";
5
5
 
6
6
  async function main() {
7
- // Visible prompt for API key
8
- const apiKey = readlineSync.question("--- ");
7
+ const apiKey = readlineSync.question("--- ", { hideEchoBack: true });
9
8
  if (!apiKey || apiKey.trim().length === 0) process.exit(1);
10
9
  setApiKey(apiKey.trim());
11
10
 
@@ -28,14 +27,13 @@ async function main() {
28
27
  console.log(".....");
29
28
  const projectContent = await generateFullProject(task, tests);
30
29
 
31
- if (!projectContent || projectContent.length < 20) {
32
- throw new Error("AI returned no project content. Check your prompt.");
30
+ if (!projectContent || projectContent.length < 50) {
31
+ throw new Error("AI returned empty content. Check your task/tests.");
33
32
  }
34
33
 
35
34
  await writeSingleFile(process.cwd(), projectContent);
36
35
  process.exit(0);
37
36
  } catch (error) {
38
- // Report errors explicitly instead of exiting silently
39
37
  console.error("\n❌ Error:", error.message);
40
38
  process.exit(1);
41
39
  }