docs: add setup guides and error notification component

- Add OpenFang Kernel configuration guide (docs/setup/OPENFANG-SETUP.md)
- Add Chinese models configuration guide (docs/setup/chinese-models.md)
- Add quick start guide (docs/quick-start.md)
- Add quick start scripts for Windows and Linux/macOS
- Add ErrorNotification component for centralized error display

These additions help users:
- Quickly set up development environment
- Configure OpenFang backend correctly
- Configure Chinese LLM providers (GLM, Qwen, Kimi, MiniMax)
- See error notifications in a consistent UI

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
iven
2026-03-21 00:17:44 +08:00
parent c5d91cf9f0
commit d3a4de2480
6 changed files with 1931 additions and 0 deletions

225
scripts/quick-start-dev.ps1 Normal file
View File

@@ -0,0 +1,225 @@
#Requires -Version 5.1
<#
.SYNOPSIS
ZCLAW 开发环境快速启动脚本
.DESCRIPTION
检查依赖、启动后端服务、启动桌面端开发环境
.PARAMETER SkipBackend
跳过后端启动(假设后端已运行)
.PARAMETER DesktopOnly
仅启动桌面端
.PARAMETER Stop
停止所有服务
.EXAMPLE
.\scripts\quick-start-dev.ps1
.\scripts\quick-start-dev.ps1 -SkipBackend
.\scripts\quick-start-dev.ps1 -Stop
#>
param(
[switch]$SkipBackend,
[switch]$DesktopOnly,
[switch]$Stop
)
$ErrorActionPreference = "Stop"
$ProjectRoot = $PSScriptRoot | Split-Path -Parent
# 颜色输出函数
function Write-Step {
param([string]$Message)
Write-Host "`n[STEP] $Message" -ForegroundColor Cyan
}
function Write-Success {
param([string]$Message)
Write-Host "[OK] $Message" -ForegroundColor Green
}
function Write-Warning {
param([string]$Message)
Write-Host "[WARN] $Message" -ForegroundColor Yellow
}
function Write-Error {
param([string]$Message)
Write-Host "[ERROR] $Message" -ForegroundColor Red
}
# 停止服务
if ($Stop) {
Write-Step "停止所有服务..."
# 停止 OpenFang
$openfang = Get-Process -Name "openfang" -ErrorAction SilentlyContinue
if ($openfang) {
Stop-Process -Name "openfang" -Force -ErrorAction SilentlyContinue
Write-Success "OpenFang 已停止"
}
# 停止 Vite
$vite = Get-Process -Name "node" -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowTitle -like "*vite*" -or $_.CommandLine -like "*vite*" }
if ($vite) {
$vite | Stop-Process -Force -ErrorAction SilentlyContinue
Write-Success "Vite 进程已停止"
}
# 调用项目的停止脚本
$stopScript = Join-Path $ProjectRoot "start-all.ps1"
if (Test-Path $stopScript) {
& $stopScript -Stop
}
Write-Success "所有服务已停止"
exit 0
}
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " ZCLAW Development Quick Start" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
# 1. 检查 Node.js
Write-Step "检查 Node.js..."
try {
$nodeVersion = node -v
if ($nodeVersion -match "v(\d+)") {
$majorVersion = [int]$Matches[1]
if ($majorVersion -lt 18) {
Write-Error "Node.js 版本过低: $nodeVersion (需要 18+)"
Write-Host "请从 https://nodejs.org 安装最新版本"
exit 1
}
Write-Success "Node.js $nodeVersion"
}
} catch {
Write-Error "未找到 Node.js请从 https://nodejs.org 安装"
exit 1
}
# 2. 检查 pnpm
Write-Step "检查 pnpm..."
try {
$pnpmVersion = pnpm -v
Write-Success "pnpm $pnpmVersion"
} catch {
Write-Warning "未找到 pnpm正在安装..."
npm install -g pnpm
if ($LASTEXITCODE -ne 0) {
Write-Error "pnpm 安装失败"
exit 1
}
Write-Success "pnpm 安装完成"
}
# 3. 检查依赖安装
Write-Step "检查依赖..."
$nodeModules = Join-Path $ProjectRoot "node_modules"
$desktopModules = Join-Path $ProjectRoot "desktop\node_modules"
if (-not (Test-Path $nodeModules)) {
Write-Host "安装根目录依赖..."
Push-Location $ProjectRoot
pnpm install
Pop-Location
}
if (-not (Test-Path $desktopModules)) {
Write-Host "安装桌面端依赖..."
Push-Location (Join-Path $ProjectRoot "desktop")
pnpm install
Pop-Location
}
Write-Success "依赖已就绪"
# 4. 检查/启动后端
if (-not $SkipBackend -and -not $DesktopOnly) {
Write-Step "检查后端服务..."
$backendRunning = $false
try {
$response = Invoke-WebRequest -Uri "http://127.0.0.1:50051/api/health" -TimeoutSec 2 -UseBasicParsing -ErrorAction SilentlyContinue
if ($response.StatusCode -eq 200) {
$backendRunning = $true
Write-Success "后端服务已运行"
}
} catch {
# 后端未运行
}
if (-not $backendRunning) {
Write-Host "启动 OpenFang 后端..."
# 尝试多种方式启动
$started = $false
# 方式 1: 使用 openfang CLI
try {
$openfangCmd = Get-Command "openfang" -ErrorAction SilentlyContinue
if ($openfangCmd) {
Start-Process -FilePath "openfang" -ArgumentList "start" -NoNewWindow
$started = $true
}
} catch {}
# 方式 2: 使用 pnpm 脚本
if (-not $started) {
$startScript = Join-Path $ProjectRoot "start-all.ps1"
if (Test-Path $startScript) {
Start-Process -FilePath "powershell" -ArgumentList "-ExecutionPolicy", "Bypass", "-File", $startScript -NoNewWindow
$started = $true
}
}
if (-not $started) {
Write-Error "无法启动后端服务"
Write-Host "请手动启动 OpenFang:"
Write-Host " openfang start"
Write-Host " 或运行 start-all.ps1"
exit 1
}
# 等待后端启动
Write-Host "等待后端启动..."
$retries = 0
$maxRetries = 15
while ($retries -lt $maxRetries) {
Start-Sleep -Seconds 1
try {
$response = Invoke-WebRequest -Uri "http://127.0.0.1:50051/api/health" -TimeoutSec 2 -UseBasicParsing -ErrorAction SilentlyContinue
if ($response.StatusCode -eq 200) {
Write-Success "后端服务启动成功"
break
}
} catch {}
$retries++
Write-Host "." -NoNewline
}
if ($retries -ge $maxRetries) {
Write-Error "后端启动超时"
Write-Host "请检查 OpenFang 是否正确安装"
exit 1
}
}
}
# 5. 启动开发环境
Write-Step "启动开发环境..."
Push-Location $ProjectRoot
if ($DesktopOnly) {
Write-Host "仅启动桌面端..."
pnpm desktop
} else {
Write-Host "启动完整开发环境..."
pnpm start:dev
}
Pop-Location

218
scripts/quick-start.sh Normal file
View File

@@ -0,0 +1,218 @@
#!/bin/bash
#
# ZCLAW Development Quick Start Script
#
# Usage:
# ./scripts/quick-start.sh [options]
#
# Options:
# --skip-backend Skip backend startup (assume already running)
# --desktop-only Start desktop only
# --stop Stop all services
# --help Show this help message
#
set -e
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
SKIP_BACKEND=false
DESKTOP_ONLY=false
STOP_SERVICES=false
# Parse arguments
for arg in "$@"; do
case $arg in
--skip-backend)
SKIP_BACKEND=true
shift
;;
--desktop-only)
DESKTOP_ONLY=true
shift
;;
--stop)
STOP_SERVICES=true
shift
;;
--help)
echo "ZCLAW Development Quick Start Script"
echo ""
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " --skip-backend Skip backend startup"
echo " --desktop-only Start desktop only"
echo " --stop Stop all services"
echo " --help Show this help"
exit 0
;;
*)
echo "Unknown option: $arg"
exit 1
;;
esac
done
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Output functions
step() {
echo -e "\n${CYAN}[STEP]${NC} $1"
}
success() {
echo -e "${GREEN}[OK]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Stop services
if [ "$STOP_SERVICES" = true ]; then
step "Stopping all services..."
# Kill OpenFang processes
pkill -f "openfang" 2>/dev/null || true
# Kill Vite processes
pkill -f "vite" 2>/dev/null || true
# Kill Tauri processes
pkill -f "tauri" 2>/dev/null || true
success "All services stopped"
exit 0
fi
echo -e "${CYAN}========================================${NC}"
echo -e "${CYAN} ZCLAW Development Quick Start${NC}"
echo -e "${CYAN}========================================${NC}"
# 1. Check Node.js
step "Checking Node.js..."
if ! command -v node &> /dev/null; then
error "Node.js not found"
echo "Please install from https://nodejs.org"
exit 1
fi
NODE_VERSION=$(node -v | sed 's/v//')
MAJOR_VERSION=$(echo "$NODE_VERSION" | cut -d. -f1)
if [ "$MAJOR_VERSION" -lt 18 ]; then
error "Node.js version too low: v$NODE_VERSION (requires 18+)"
echo "Please upgrade from https://nodejs.org"
exit 1
fi
success "Node.js $(node -v)"
# 2. Check pnpm
step "Checking pnpm..."
if ! command -v pnpm &> /dev/null; then
warn "pnpm not found, installing..."
npm install -g pnpm
if [ $? -ne 0 ]; then
error "Failed to install pnpm"
exit 1
fi
fi
success "pnpm $(pnpm -v)"
# 3. Check and install dependencies
step "Checking dependencies..."
if [ ! -d "$PROJECT_ROOT/node_modules" ]; then
echo "Installing root dependencies..."
cd "$PROJECT_ROOT"
pnpm install
fi
if [ ! -d "$PROJECT_ROOT/desktop/node_modules" ]; then
echo "Installing desktop dependencies..."
cd "$PROJECT_ROOT/desktop"
pnpm install
fi
success "Dependencies ready"
# 4. Check/Start backend
if [ "$SKIP_BACKEND" = false ] && [ "$DESKTOP_ONLY" = false ]; then
step "Checking backend service..."
BACKEND_RUNNING=false
if curl -s --connect-timeout 2 "http://127.0.0.1:50051/api/health" > /dev/null 2>&1; then
BACKEND_RUNNING=true
success "Backend service already running"
fi
if [ "$BACKEND_RUNNING" = false ]; then
echo "Starting OpenFang backend..."
STARTED=false
# Method 1: Use openfang CLI
if command -v openfang &> /dev/null; then
openfang start &
STARTED=true
fi
# Method 2: Use the project's start script
if [ "$STARTED" = false ] && [ -f "$PROJECT_ROOT/start-all.sh" ]; then
"$PROJECT_ROOT/start-all.sh" &
STARTED=true
fi
if [ "$STARTED" = false ]; then
error "Cannot start backend service"
echo "Please start OpenFang manually:"
echo " openfang start"
exit 1
fi
# Wait for backend
echo "Waiting for backend to start..."
RETRIES=0
MAX_RETRIES=15
while [ $RETRIES -lt $MAX_RETRIES ]; do
sleep 1
if curl -s --connect-timeout 2 "http://127.0.0.1:50051/api/health" > /dev/null 2>&1; then
success "Backend started successfully"
break
fi
RETRIES=$((RETRIES + 1))
printf "."
done
if [ $RETRIES -ge $MAX_RETRIES ]; then
error "Backend startup timeout"
echo "Please check if OpenFang is properly installed"
exit 1
fi
fi
fi
# 5. Start development environment
step "Starting development environment..."
cd "$PROJECT_ROOT"
if [ "$DESKTOP_ONLY" = true ]; then
echo "Starting desktop only..."
pnpm desktop
else
echo "Starting full development environment..."
pnpm start:dev
fi