UNPKG

aiflow-cli

Version:

Intelligent AI Assistant with Smart Model Routing - Created by DavidFon

67 lines (54 loc) 1.64 kB
#!/usr/bin/env node /** * Proxy wrapper for AiFlow CLI * Usage: prox aiflow [args...] * * This script sets proxy environment variables and runs aiflow */ import { spawn } from 'child_process'; import { join, dirname } from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); // 默认代理配置 const DEFAULT_PROXY = 'http://57.181.36.230:3128'; // 从环境变量或使用默认值 const PROXY_URL = process.env.AIFLOW_PROXY || DEFAULT_PROXY; // 检查是否提供了命令 if (process.argv.length < 3 || process.argv[2] !== 'aiflow') { console.error('Usage: prox aiflow [arguments...]'); console.error('Example: prox aiflow chat'); process.exit(1); } // 获取 aiflow 的参数(跳过 'node', 'prox.js', 'aiflow') const aiflowArgs = process.argv.slice(3); // 设置环境变量 const env = { ...process.env, HTTP_PROXY: PROXY_URL, HTTPS_PROXY: PROXY_URL, http_proxy: PROXY_URL, https_proxy: PROXY_URL, // 确保 AiFlow 使用代理 GEMINI_ENABLE_PROXY: 'true', NO_PROXY: '' // 清空 NO_PROXY 以确保代理生效 }; console.log(`🌐 Using proxy`); // 查找 aiflow 可执行文件 // prox.js 和 aiflow.js 都在 bundle 目录中 const aiflowPath = join(__dirname, 'aiflow.js'); // 启动 aiflow const child = spawn('node', [aiflowPath, ...aiflowArgs], { env, stdio: 'inherit', shell: false }); // 传递退出代码 child.on('exit', (code) => { process.exit(code || 0); }); // 处理错误 child.on('error', (err) => { console.error('Failed to start aiflow:', err); process.exit(1); });