ai-codegen-cli-vrk 2.0.9 → 2.1.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/package.json +4 -1
- package/src/aiClient.js +28 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-codegen-cli-vrk",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Minimalist Terminal-based AI code generator",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -14,5 +14,8 @@
|
|
|
14
14
|
"@google/generative-ai": "^0.21.0",
|
|
15
15
|
"fs-extra": "^11.2.0",
|
|
16
16
|
"readline-sync": "^1.4.10"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18.0.0"
|
|
17
20
|
}
|
|
18
21
|
}
|
package/src/aiClient.js
CHANGED
|
@@ -8,39 +8,38 @@ export function setApiKey(apiKey) {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Ultimate discovery: Asks Google for a list of working models for your key.
|
|
12
12
|
*/
|
|
13
13
|
async function getWorkingModel() {
|
|
14
14
|
if (activeModel) return activeModel;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
}
|
|
16
|
+
try {
|
|
17
|
+
// Attempt to list models to see what this specific key is allowed to use
|
|
18
|
+
// We use v1beta as it has the most complete model list
|
|
19
|
+
const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${genAI.apiKey}`);
|
|
20
|
+
const data = await response.json();
|
|
21
|
+
|
|
22
|
+
if (data.models) {
|
|
23
|
+
// Look for 1.5-flash or 2.0-flash in the permitted list
|
|
24
|
+
const best = data.models.find(m =>
|
|
25
|
+
m.supportedGenerationMethods.includes("generateContent") &&
|
|
26
|
+
(m.name.includes("1.5-flash") || m.name.includes("2.0-flash"))
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
if (best) {
|
|
30
|
+
// Strip "models/" prefix if present for the SDK
|
|
31
|
+
const modelName = best.name.split('/').pop();
|
|
32
|
+
activeModel = genAI.getGenerativeModel({ model: modelName }, { apiVersion: "v1beta" });
|
|
33
|
+
return activeModel;
|
|
39
34
|
}
|
|
40
35
|
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
// If listing fails, fall back to a safe guess
|
|
41
38
|
}
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
|
|
40
|
+
// Final fallback to the most common working model
|
|
41
|
+
activeModel = genAI.getGenerativeModel({ model: "gemini-1.5-flash" }, { apiVersion: "v1beta" });
|
|
42
|
+
return activeModel;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
export async function generateFullProject(task, tests, retryCount = 0) {
|
|
@@ -76,9 +75,9 @@ ${tests}
|
|
|
76
75
|
|
|
77
76
|
} catch (error) {
|
|
78
77
|
// Handle Overloaded (503) or Rate Limit (429) - Critical for Free Tier
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
const msg = error.message || "";
|
|
79
|
+
if ((msg.includes("503") || msg.includes("429") || msg.includes("overloaded")) && retryCount < 5) {
|
|
80
|
+
console.log(`..... (Server busy, waiting 15s to retry ${retryCount + 1}/5)`);
|
|
82
81
|
await new Promise(r => setTimeout(r, 15000));
|
|
83
82
|
return generateFullProject(task, tests, retryCount + 1);
|
|
84
83
|
}
|