codecli-hostapi
Advanced tools
+43
-9
@@ -9,4 +9,2 @@ #!/usr/bin/env node | ||
| const PROXY_PORT = 18080; | ||
| const PROXY_HOST = '127.0.0.1'; | ||
| const PROXY_BASE_URL = `http://${PROXY_HOST}:${PROXY_PORT}`; | ||
@@ -21,7 +19,8 @@ // XDG-compliant paths | ||
| const PROXY_SCRIPT = `#!/usr/bin/env python3 | ||
| function getProxyScript(host) { | ||
| return `#!/usr/bin/env python3 | ||
| import json, subprocess, time, sys, uuid | ||
| from http.server import BaseHTTPRequestHandler, HTTPServer | ||
| HOST = "${PROXY_HOST}" | ||
| HOST = "${host}" | ||
| PORT = ${PROXY_PORT} | ||
@@ -190,2 +189,3 @@ | ||
| `; | ||
| } | ||
@@ -200,2 +200,17 @@ // ============ Utility Functions ============ | ||
| function getLocalIP() { | ||
| try { | ||
| const os = require('os'); | ||
| const interfaces = os.networkInterfaces(); | ||
| for (const name of Object.keys(interfaces)) { | ||
| for (const iface of interfaces[name]) { | ||
| if (iface.family === 'IPv4' && !iface.internal) { | ||
| return iface.address; | ||
| } | ||
| } | ||
| } | ||
| } catch {} | ||
| return '0.0.0.0'; | ||
| } | ||
| function run(cmd, opts = {}) { | ||
@@ -312,8 +327,17 @@ if (!opts.silent) console.log(`> ${cmd}`); | ||
| // Ask for access mode | ||
| console.log('\n🌐 选择访问模式:'); | ||
| console.log(' 1. 仅本地 (127.0.0.1) - 只能本机访问'); | ||
| console.log(' 2. 本地+远程 (0.0.0.0) - 允许外部访问'); | ||
| const modeChoice = await prompt('请选择 (1/2, 默认1): '); | ||
| const proxyHost = modeChoice === '2' ? '0.0.0.0' : '127.0.0.1'; | ||
| const isRemote = proxyHost === '0.0.0.0'; | ||
| // Install proxy script | ||
| console.log('\n📦 安装代理脚本...'); | ||
| ensureDir(DATA_DIR); | ||
| fs.writeFileSync(PROXY_SCRIPT_PATH, PROXY_SCRIPT); | ||
| fs.writeFileSync(PROXY_SCRIPT_PATH, getProxyScript(proxyHost)); | ||
| fs.chmodSync(PROXY_SCRIPT_PATH, '755'); | ||
| console.log(` ✓ 已安装: ${PROXY_SCRIPT_PATH}`); | ||
| console.log(` ✓ 绑定地址: ${proxyHost}:${PROXY_PORT}`); | ||
@@ -363,6 +387,12 @@ // Setup systemd service (Linux only) | ||
| config.installedAt = new Date().toISOString(); | ||
| config.proxyHost = proxyHost; | ||
| saveConfig(config); | ||
| const displayHost = isRemote ? getLocalIP() : '127.0.0.1'; | ||
| console.log('\n✅ 安装完成!'); | ||
| console.log(`\n📡 API 端点: ${PROXY_BASE_URL}/v1/messages`); | ||
| console.log(`\n📡 API 端点: http://${displayHost}:${PROXY_PORT}/v1/messages`); | ||
| if (isRemote) { | ||
| console.log(` 本地访问: http://127.0.0.1:${PROXY_PORT}/v1/messages`); | ||
| console.log(' 客户端 API Key 可填任意值 (如 sk-placeholder)'); | ||
| } | ||
| console.log(' 将此地址作为 Anthropic API 的 baseUrl 使用'); | ||
@@ -541,6 +571,10 @@ | ||
| const running = isProxyRunning(); | ||
| const proxyHost = config.proxyHost || '127.0.0.1'; | ||
| const isRemote = proxyHost === '0.0.0.0'; | ||
| const displayHost = isRemote ? getLocalIP() : '127.0.0.1'; | ||
| console.log(` 已安装: ${config.installed ? '✓ 是' : '○ 否'}`); | ||
| console.log(` 运行中: ${running ? '✓ 是' : '○ 否'}`); | ||
| console.log(` 端点: ${PROXY_BASE_URL}/v1/messages`); | ||
| console.log(` 模式: ${isRemote ? '本地+远程 (0.0.0.0)' : '仅本地 (127.0.0.1)'}`); | ||
| console.log(` 端点: http://${displayHost}:${PROXY_PORT}/v1/messages`); | ||
@@ -561,3 +595,3 @@ if (process.platform === 'linux') { | ||
| const baseUrl = cfg?.models?.providers?.anthropic?.baseUrl || '(默认)'; | ||
| const usingProxy = baseUrl === PROXY_BASE_URL; | ||
| const usingProxy = baseUrl.includes(`127.0.0.1:${PROXY_PORT}`) || baseUrl.includes(`localhost:${PROXY_PORT}`); | ||
| console.log(`\n Clawdbot: ${clawdbotConfig}`); | ||
@@ -578,3 +612,3 @@ console.log(` BaseURL: ${baseUrl}`); | ||
| console.log('\n╔════════════════════════════════════════╗'); | ||
| console.log('║ codecli-hostapi v1.3.0 ║'); | ||
| console.log('║ codecli-hostapi v1.4.0 ║'); | ||
| console.log('║ 将 Claude CLI 转为本地 API 端点 ║'); | ||
@@ -581,0 +615,0 @@ console.log('╚════════════════════════════════════════╝'); |
+1
-1
| { | ||
| "name": "codecli-hostapi", | ||
| "version": "1.3.0", | ||
| "version": "1.4.0", | ||
| "description": "One-command setup to proxy Anthropic API requests through Claude Code CLI", | ||
@@ -5,0 +5,0 @@ "bin": { |
System shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Embedded URLs or IPs
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
System shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Embedded URLs or IPs
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
21852
6.65%552
6.15%