Download opencode-tools.sh from airsltd/myoc: direct link, hf CLI and curl.
- Browser
- Download file 5.31 kB
-
https://huggingface.co/spaces/airsltd/myoc/resolve/main/opencode-tools.sh
- Command line
-
hf download hf://spaces/airsltd/myoc/opencode-tools.sh
-
curl -L -o opencode-tools.sh https://huggingface.co/spaces/airsltd/myoc/resolve/main/opencode-tools.sh
5.31 kB
| # OpenCode AI Web Interface - 统一工具脚本 | |
| # 集成诊断、修复和验证功能 | |
| set -e | |
| # 颜色定义 | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| BLUE='\033[0;34m' | |
| NC='\033[0m' # No Color | |
| print_info() { | |
| echo -e "${BLUE}ℹ️ $1${NC}" | |
| } | |
| print_success() { | |
| echo -e "${GREEN}✅ $1${NC}" | |
| } | |
| print_warning() { | |
| echo -e "${YELLOW}⚠️ $1${NC}" | |
| } | |
| print_error() { | |
| echo -e "${RED}❌ $1${NC}" | |
| } | |
| print_header() { | |
| echo -e "${BLUE}" | |
| echo "==================================" | |
| echo " OpenCode AI 统一工具" | |
| echo "==================================" | |
| echo -e "${NC}" | |
| } | |
| # 显示帮助信息 | |
| show_help() { | |
| echo "OpenCode AI Web Interface 统一工具" | |
| echo "" | |
| echo "用法: $0 [选项]" | |
| echo "" | |
| echo "选项:" | |
| echo " verify 验证服务状态" | |
| echo " diagnose 运行深度诊断" | |
| echo " network 网络连接诊断" | |
| echo " js JavaScript 错误诊断" | |
| echo " local 启动本地部署" | |
| echo " help 显示此帮助信息" | |
| echo "" | |
| echo "示例:" | |
| echo " $0 verify # 验证服务状态" | |
| echo " $0 diagnose # 运行完整诊断" | |
| echo " $0 local # 启动本地服务" | |
| } | |
| # 验证服务状态 | |
| verify_service() { | |
| print_info "验证 OpenCode AI 服务状态..." | |
| local base_url="https://airsltd-hfoc.hf.space" | |
| local health_url="$base_url/global/health" | |
| # 测试健康检查 | |
| local health_response=$(curl -s --connect-timeout 10 "$health_url" 2>/dev/null) | |
| if echo "$health_response" | grep -q "healthy.*true"; then | |
| print_success "✅ 服务器健康检查通过" | |
| local version=$(echo "$health_response" | grep -o '"version":"[^"]*"' | cut -d'"' -f4) | |
| print_info "版本: $version" | |
| return 0 | |
| else | |
| print_error "❌ 服务器健康检查失败" | |
| return 1 | |
| fi | |
| } | |
| # 网络连接诊断 | |
| diagnose_network() { | |
| print_info "执行网络连接诊断..." | |
| local base_url="https://airsltd-hfoc.hf.space" | |
| # 基本网络测试 | |
| print_info "测试基本网络连接..." | |
| if curl -s --connect-timeout 5 "https://www.google.com" >/dev/null 2>&1; then | |
| print_success "互联网连接正常" | |
| else | |
| print_warning "互联网连接可能有问题" | |
| fi | |
| # Hugging Face 相关测试 | |
| print_info "测试 Hugging Face Spaces 连接..." | |
| if curl -s --connect-timeout 10 "$base_url" >/dev/null 2>&1; then | |
| print_success "Hugging Face Spaces 连接正常" | |
| else | |
| print_error "Hugging Face Spaces 连接失败" | |
| print_info "建议:" | |
| echo "1. 使用 VPN 或代理" | |
| echo "2. 尝试本地部署" | |
| echo "3. 检查网络设置" | |
| fi | |
| } | |
| # JavaScript 错误诊断 | |
| diagnose_js() { | |
| print_info "诊断 JavaScript 错误..." | |
| print_warning "常见的 JavaScript 错误:" | |
| echo "1. InvalidCharacterError: atob 解码失败" | |
| echo "2. 网络连接错误" | |
| echo "3. 资源加载失败" | |
| echo "" | |
| print_info "解决方案:" | |
| echo "1. 清除浏览器缓存: Ctrl+Shift+Delete" | |
| echo "2. 强制刷新: Ctrl+Shift+R" | |
| echo "3. 尝试无痕模式" | |
| echo "4. 使用本地部署作为备用" | |
| } | |
| # 深度诊断 | |
| deep_diagnose() { | |
| print_info "执行深度诊断..." | |
| # 依次执行各种诊断 | |
| verify_service | |
| diagnose_network | |
| diagnose_js | |
| echo "" | |
| print_info "深度诊断完成" | |
| } | |
| # 启动本地部署 | |
| start_local() { | |
| print_info "启动本地 OpenCode 服务..." | |
| # 检查 OpenCode 是否已安装 | |
| if ! command_exists opencode; then | |
| print_info "检测到 OpenCode 未安装,正在安装..." | |
| if command_exists npm; then | |
| print_info "使用 npm 安装 OpenCode..." | |
| npm install -g opencode-ai | |
| elif command_exists brew; then | |
| print_info "使用 Homebrew 安装 OpenCode..." | |
| brew install opencode-ai/tap/opencode | |
| else | |
| print_error "未找到 npm 或 brew,请手动安装 OpenCode" | |
| exit 1 | |
| fi | |
| fi | |
| # 设置端口 | |
| local PORT=7860 | |
| if lsof -Pi :$PORT -sTCP:LISTEN -t >/dev/null 2>&1; then | |
| print_warning "端口 $PORT 已被占用,尝试端口 7861..." | |
| PORT=7861 | |
| fi | |
| print_info "启动 OpenCode Web Interface..." | |
| echo "" | |
| echo -e "${GREEN}服务地址: http://localhost:$PORT${NC}" | |
| echo "" | |
| # 启动服务 | |
| export HTTP_PROXY="" | |
| export HTTPS_PROXY="" | |
| export NO_PROXY="localhost,127.0.0.1,0.0.0.0" | |
| opencode serve --port $PORT --hostname 0.0.0.0 --cors "*" | |
| } | |
| # 检查命令是否存在 | |
| command_exists() { | |
| command -v "$1" >/dev/null 2>&1 | |
| } | |
| # 主函数 | |
| main() { | |
| case "${1:-help}" in | |
| "verify") | |
| print_header | |
| verify_service | |
| ;; | |
| "diagnose") | |
| print_header | |
| deep_diagnose | |
| ;; | |
| "network") | |
| print_header | |
| diagnose_network | |
| ;; | |
| "js") | |
| print_header | |
| diagnose_js | |
| ;; | |
| "local") | |
| print_header | |
| start_local | |
| ;; | |
| "help"|*) | |
| show_help | |
| ;; | |
| esac | |
| } | |
| # 运行主函数 | |
| main "$@" |