xithead 1.1.0 → 1.1.1
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/npm/bin/xithead.js +60 -14
- package/npm/postinstall.js +43 -0
- package/package.json +5 -1
package/npm/bin/xithead.js
CHANGED
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
const { spawnSync, spawn } = require('child_process');
|
|
9
9
|
const http = require('http');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
|
|
12
|
+
const PKG_VERSION = (() => {
|
|
13
|
+
try { return require(path.join(__dirname, '../../package.json')).version; } catch { return '1.1.0'; }
|
|
14
|
+
})();
|
|
10
15
|
|
|
11
16
|
const args = process.argv.slice(2);
|
|
12
17
|
const PROXY_PORT = 8787;
|
|
@@ -23,25 +28,42 @@ function findPython() {
|
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
function proxyAlive() {
|
|
31
|
+
// Try /health first (fast), fall back to /api/stats
|
|
26
32
|
return new Promise(resolve => {
|
|
27
|
-
const
|
|
28
|
-
|
|
33
|
+
const tryEndpoint = (path, cb) => {
|
|
34
|
+
const req = http.get(`${PROXY_URL}${path}`, { timeout: 3000 }, res => {
|
|
35
|
+
cb(res.statusCode === 200);
|
|
36
|
+
});
|
|
37
|
+
req.on('error', () => cb(false));
|
|
38
|
+
req.on('timeout', () => { req.destroy(); cb(false); });
|
|
39
|
+
};
|
|
40
|
+
tryEndpoint('/health', ok => {
|
|
41
|
+
if (ok) return resolve(true);
|
|
42
|
+
tryEndpoint('/api/stats', resolve);
|
|
29
43
|
});
|
|
30
|
-
req.on('error', () => resolve(false));
|
|
31
|
-
req.on('timeout', () => { req.destroy(); resolve(false); });
|
|
32
44
|
});
|
|
33
45
|
}
|
|
34
46
|
|
|
35
47
|
function startProxy(py) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
const isWin = process.platform === 'win32';
|
|
49
|
+
// On Windows use 'start' to open a background process properly
|
|
50
|
+
if (isWin) {
|
|
51
|
+
const child = spawn('cmd', ['/c', 'start', '/b', py, '-m', 'xithead.cli.main', 'proxy', '--port', String(PROXY_PORT)], {
|
|
52
|
+
detached: true,
|
|
53
|
+
stdio: 'ignore',
|
|
54
|
+
shell: false,
|
|
55
|
+
});
|
|
56
|
+
child.unref();
|
|
57
|
+
} else {
|
|
58
|
+
const child = spawn(py, ['-m', 'xithead.cli.main', 'proxy', '--port', String(PROXY_PORT)], {
|
|
59
|
+
detached: true,
|
|
60
|
+
stdio: 'ignore',
|
|
61
|
+
});
|
|
62
|
+
child.unref();
|
|
63
|
+
}
|
|
42
64
|
}
|
|
43
65
|
|
|
44
|
-
function waitForProxy(timeoutMs =
|
|
66
|
+
function waitForProxy(timeoutMs = 20000) {
|
|
45
67
|
return new Promise(async resolve => {
|
|
46
68
|
const deadline = Date.now() + timeoutMs;
|
|
47
69
|
while (Date.now() < deadline) {
|
|
@@ -57,6 +79,17 @@ function hasPythonXithead(py) {
|
|
|
57
79
|
return r.status === 0;
|
|
58
80
|
}
|
|
59
81
|
|
|
82
|
+
function hasProxyDeps(py) {
|
|
83
|
+
const r = spawnSync(py, ['-c', 'import fastapi, uvicorn, httpx'], { stdio: 'pipe' });
|
|
84
|
+
return r.status === 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function installProxyDeps(py) {
|
|
88
|
+
process.stdout.write('\x1b[33m [xithead] Installiere Proxy-Abhängigkeiten...\x1b[0m\n');
|
|
89
|
+
const r = spawnSync(py, ['-m', 'pip', 'install', '-q', 'xithead[proxy]'], { stdio: 'inherit' });
|
|
90
|
+
return r.status === 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
60
93
|
// ── Commands ──────────────────────────────────────────────────────────────────
|
|
61
94
|
|
|
62
95
|
function showBanner(proxyOk) {
|
|
@@ -70,7 +103,8 @@ function showBanner(proxyOk) {
|
|
|
70
103
|
};
|
|
71
104
|
console.log('');
|
|
72
105
|
console.log(`${c.cyan} ╔═══════════════════════════════════════════╗${c.reset}`);
|
|
73
|
-
|
|
106
|
+
const ver = `v${PKG_VERSION}`.padEnd(7);
|
|
107
|
+
console.log(`${c.cyan} ║ Xtream-ITSolutions — xithead ${ver} ║${c.reset}`);
|
|
74
108
|
console.log(`${c.cyan} ║ discord.gg/xtream-itsolutions ║${c.reset}`);
|
|
75
109
|
console.log(`${c.cyan} ╠═══════════════════════════════════════════╣${c.reset}`);
|
|
76
110
|
console.log(`${c.green} ║ Modell: claude-sonnet-4-6 ║${c.reset}`);
|
|
@@ -165,10 +199,22 @@ async function main() {
|
|
|
165
199
|
let proxyOk = await proxyAlive();
|
|
166
200
|
|
|
167
201
|
if (!proxyOk && py && hasPythonXithead(py)) {
|
|
202
|
+
// Auto-install proxy deps if missing
|
|
203
|
+
if (!hasProxyDeps(py)) {
|
|
204
|
+
const ok = installProxyDeps(py);
|
|
205
|
+
if (!ok) {
|
|
206
|
+
console.log('\x1b[31m [xithead] Proxy-Abhängigkeiten konnten nicht installiert werden.\x1b[0m');
|
|
207
|
+
console.log(' Manuell: pip install "xithead[proxy]"');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
168
210
|
process.stdout.write('\x1b[33m [xithead] Proxy startet...\x1b[0m');
|
|
169
211
|
startProxy(py);
|
|
170
|
-
proxyOk = await waitForProxy();
|
|
171
|
-
|
|
212
|
+
proxyOk = await waitForProxy(20000);
|
|
213
|
+
if (!proxyOk) {
|
|
214
|
+
// Port may already be in use from a previous run — check once more
|
|
215
|
+
proxyOk = await proxyAlive();
|
|
216
|
+
}
|
|
217
|
+
process.stdout.write(proxyOk ? ' \x1b[32mbereit!\x1b[0m\n' : ' \x1b[33mTimeout — direkte API\x1b[0m\n');
|
|
172
218
|
}
|
|
173
219
|
|
|
174
220
|
showBanner(proxyOk);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* xithead postinstall — auto-installs Python proxy dependencies
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
const { spawnSync } = require('child_process');
|
|
8
|
+
|
|
9
|
+
function findPython() {
|
|
10
|
+
for (const cmd of ['python', 'python3', 'py']) {
|
|
11
|
+
const r = spawnSync(cmd, ['--version'], { stdio: 'pipe' });
|
|
12
|
+
if (r.status === 0) return cmd;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const py = findPython();
|
|
18
|
+
if (!py) {
|
|
19
|
+
console.log('[xithead] Python nicht gefunden — überspringe Proxy-Setup.');
|
|
20
|
+
console.log(' Installiere Python von https://python.org und führe dann aus:');
|
|
21
|
+
console.log(' pip install "xithead[proxy]"');
|
|
22
|
+
process.exit(0);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Check if proxy deps already installed
|
|
26
|
+
const check = spawnSync(py, ['-c', 'import fastapi, uvicorn, httpx'], { stdio: 'pipe' });
|
|
27
|
+
if (check.status === 0) {
|
|
28
|
+
console.log('[xithead] Proxy-Abhängigkeiten bereits installiert ✓');
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
console.log('[xithead] Installiere xithead[proxy] (fastapi + uvicorn + httpx)...');
|
|
33
|
+
const result = spawnSync(
|
|
34
|
+
py, ['-m', 'pip', 'install', '-q', '--upgrade', 'xithead[proxy]'],
|
|
35
|
+
{ stdio: 'inherit' }
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (result.status === 0) {
|
|
39
|
+
console.log('[xithead] Proxy-Abhängigkeiten erfolgreich installiert ✓');
|
|
40
|
+
} else {
|
|
41
|
+
console.log('[xithead] Hinweis: Proxy-Installation fehlgeschlagen.');
|
|
42
|
+
console.log(' Manuell: pip install "xithead[proxy]"');
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xithead",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Aggressive Claude context optimizer - Cut API costs by 50-95%. By Xtream-ITSolutions UG.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude",
|
|
@@ -34,9 +34,13 @@
|
|
|
34
34
|
"README.md",
|
|
35
35
|
"LICENSE"
|
|
36
36
|
],
|
|
37
|
+
"bundledDependencies": [],
|
|
37
38
|
"engines": {
|
|
38
39
|
"node": ">=18.0.0"
|
|
39
40
|
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"postinstall": "node npm/postinstall.js"
|
|
43
|
+
},
|
|
40
44
|
"dependencies": {
|
|
41
45
|
"node-fetch": "^3.3.2"
|
|
42
46
|
},
|