@ikyyofc/gemini-cli 2.0.0 → 2.0.2
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 +1 -1
- package/src/agent.js +2 -2
- package/src/gemini.js +2 -1
- package/utils/proxy-manager.js +112 -0
package/package.json
CHANGED
package/src/agent.js
CHANGED
|
@@ -18,7 +18,7 @@ import { printAssistant, printError, printWarning, printToolCall, printToolResul
|
|
|
18
18
|
export async function runAgentLoop(userMessage, history, {
|
|
19
19
|
systemInstruction = null,
|
|
20
20
|
autoApprove = false,
|
|
21
|
-
maxIterations =
|
|
21
|
+
maxIterations = 5000,
|
|
22
22
|
} = {}) {
|
|
23
23
|
|
|
24
24
|
// Build initial message list
|
|
@@ -50,7 +50,7 @@ export async function runAgentLoop(userMessage, history, {
|
|
|
50
50
|
} catch (err) {
|
|
51
51
|
spinner.fail(chalk.hex("#F44747")("API error"));
|
|
52
52
|
printError(err.message);
|
|
53
|
-
printError(err.response.data);
|
|
53
|
+
printError(JSON.stringify(err.response.data, null, 2));
|
|
54
54
|
return null;
|
|
55
55
|
}
|
|
56
56
|
|
package/src/gemini.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// src/gemini.js — Gemini API client with native function calling
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
import { fileTypeFromBuffer } from "file-type";
|
|
4
|
-
|
|
4
|
+
import { setupGlobalProxy } from '../utils/proxy-manager.js';
|
|
5
|
+
setupGlobalProxy();
|
|
5
6
|
const CONFIG = {
|
|
6
7
|
URL: "https://us-central1-gemmy-ai-bdc03.cloudfunctions.net/gemini",
|
|
7
8
|
MODEL: "gemini-pro-latest",
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
|
|
3
|
+
// 1. Menghapus data duplikat di proxyPool
|
|
4
|
+
const proxyPool = [
|
|
5
|
+
{ name: "caliph", host: "https://cors.caliph.my.id/" },
|
|
6
|
+
{ name: "eu", host: "https://cors.eu.org/" },
|
|
7
|
+
{ name: "prox", host: "https://prox.26bruunjorl.workers.dev/" },
|
|
8
|
+
{ name: "wave", host: "https://plain-wave-6f5f.apis1.workers.dev/" },
|
|
9
|
+
{ name: "hill", host: "https://young-hill-815e.apis3.workers.dev/" },
|
|
10
|
+
{ name: "icy", host: "https://icy-morning-72e2.apis2.workers.dev/" },
|
|
11
|
+
{ name: "fazri", host: "https://cors.fazri.workers.dev/" },
|
|
12
|
+
{ name: "spring", host: "https://spring-night-57a1.3540746063.workers.dev/" },
|
|
13
|
+
{ name: "sizable", host: "https://cors.sizable.workers.dev/" },
|
|
14
|
+
{ name: "jiashu", host: "https://jiashu.1win.eu.org/" },
|
|
15
|
+
{ name: "artemisandros", host: "https://cors.artemisandros.workers.dev/?" },
|
|
16
|
+
{ name: "supershadowcube", host: "https://cloudflare-cors-anywhere.supershadowcube.workers.dev/?url=" }
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const userAgents = [
|
|
20
|
+
// ... (daftar user-agent kamu biarkan sama)
|
|
21
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const failedProxies = new Map();
|
|
25
|
+
const COOLDOWN_TIME = 15 * 60 * 1000;
|
|
26
|
+
|
|
27
|
+
function getRandomProxy() {
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
|
|
30
|
+
for (const [name, failedAt] of failedProxies.entries()) {
|
|
31
|
+
if (now - failedAt > COOLDOWN_TIME) {
|
|
32
|
+
failedProxies.delete(name);
|
|
33
|
+
console.log(`[Global Proxy] 🔓 ${name} telah dibuka kembali`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const available = proxyPool.filter(p => !failedProxies.has(p.name));
|
|
38
|
+
|
|
39
|
+
if (available.length === 0) {
|
|
40
|
+
failedProxies.clear();
|
|
41
|
+
console.warn("[Global Proxy] ⚠️ Semua proxy gagal, mereset paksa daftar...");
|
|
42
|
+
return proxyPool[Math.floor(Math.random() * proxyPool.length)];
|
|
43
|
+
}
|
|
44
|
+
return available[Math.floor(Math.random() * available.length)];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function setupGlobalProxy() {
|
|
48
|
+
axios.interceptors.request.use(
|
|
49
|
+
config => {
|
|
50
|
+
// Hindari infinite loop pada saat auto-retry
|
|
51
|
+
if (config._isProxied) return config;
|
|
52
|
+
|
|
53
|
+
const url = config.url || "";
|
|
54
|
+
const isInternal = url.includes("localhost") || url.includes("127.0.0.1") || url.startsWith("/");
|
|
55
|
+
|
|
56
|
+
if (isInternal) return config;
|
|
57
|
+
|
|
58
|
+
const alreadyProxied = proxyPool.some(p => url.startsWith(p.host));
|
|
59
|
+
if (alreadyProxied) return config;
|
|
60
|
+
|
|
61
|
+
const proxy = getRandomProxy();
|
|
62
|
+
const randomUA = userAgents[Math.floor(Math.random() * userAgents.length)];
|
|
63
|
+
|
|
64
|
+
// 2. Perbaikan URL Encoding berdasarkan format proxy
|
|
65
|
+
if (proxy.host.endsWith("=") || proxy.host.endsWith("?")) {
|
|
66
|
+
config.url = `${proxy.host}${encodeURIComponent(url)}`;
|
|
67
|
+
} else {
|
|
68
|
+
config.url = `${proxy.host}${url}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
config.proxy = false;
|
|
72
|
+
config.headers = config.headers || {};
|
|
73
|
+
|
|
74
|
+
// Catatan: Ini akan diabaikan oleh browser, tapi berguna di Node.js
|
|
75
|
+
config.headers["User-Agent"] = randomUA;
|
|
76
|
+
|
|
77
|
+
config.metadata = { proxyName: proxy.name, proxyHost: proxy.host, originalUrl: url };
|
|
78
|
+
config._isProxied = true; // Flag untuk retry
|
|
79
|
+
|
|
80
|
+
console.log(`[Global Proxy] 🔄 ${proxy.name} → ${url}`);
|
|
81
|
+
|
|
82
|
+
return config;
|
|
83
|
+
},
|
|
84
|
+
error => Promise.reject(error)
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
axios.interceptors.response.use(
|
|
88
|
+
response => response,
|
|
89
|
+
async error => {
|
|
90
|
+
const config = error.config;
|
|
91
|
+
const meta = config?.metadata;
|
|
92
|
+
|
|
93
|
+
if (meta?.proxyName && !config._retryAttempted) {
|
|
94
|
+
// Tandai proxy gagal
|
|
95
|
+
failedProxies.set(meta.proxyName, Date.now());
|
|
96
|
+
console.warn(`[Global Proxy] ❌ Proxy "${meta.proxyName}" gagal, diblokir sementara.`);
|
|
97
|
+
|
|
98
|
+
// 3. Mekanisme Auto-Retry (Mencoba 1x lagi dengan proxy berbeda)
|
|
99
|
+
config._retryAttempted = true;
|
|
100
|
+
config._isProxied = false; // Reset agar dicegat ulang oleh request interceptor
|
|
101
|
+
config.url = meta.originalUrl; // Kembalikan ke URL asli
|
|
102
|
+
|
|
103
|
+
console.log(`[Global Proxy] 🔄 Mencoba ulang request ke ${meta.originalUrl}...`);
|
|
104
|
+
return axios(config); // Coba request ulang
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return Promise.reject(error);
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
console.log("🛡️ Global Proxy Manager diaktifkan!");
|
|
112
|
+
}
|