feat: 完善企业场景多线路由与执行稳定性
补齐平台模板与场景 DSL、预算控制、执行看板和企业场景脚本,增强 Windows 启动/迁移与前端代理和聊天会话记忆,修复执行创建阶段 500 与异步链路排障体验。 Made-with: Cursor
This commit is contained in:
@@ -15,12 +15,50 @@ Get-CimInstance Win32_Process | Where-Object {
|
||||
Stop-Process -Id $_.ProcessId -Force
|
||||
}
|
||||
|
||||
# 兜底:清理仍占用 8037 的监听进程(多实例会随机命中旧代码并出现 500 / 路由不一致)
|
||||
for ($round = 0; $round -lt 8; $round++) {
|
||||
$pids = @()
|
||||
try {
|
||||
$pids = @(Get-NetTCPConnection -LocalPort 8037 -State Listen -ErrorAction SilentlyContinue |
|
||||
ForEach-Object { $_.OwningProcess } | Where-Object { $_ -and $_ -gt 0 } | Sort-Object -Unique)
|
||||
} catch {}
|
||||
if (-not $pids -or $pids.Count -eq 0) { break }
|
||||
foreach ($proc in $pids) {
|
||||
Write-Host "Stop port 8037 PID $proc"
|
||||
Stop-Process -Id ([int]$proc) -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
Start-Sleep -Milliseconds 600
|
||||
}
|
||||
netstat -ano 2>$null | Select-String ":8037\s+.*LISTENING" | ForEach-Object {
|
||||
$parts = ($_.Line -replace '\s+', ' ').Trim() -split ' '
|
||||
$lpid = $parts[-1]
|
||||
if ($lpid -match '^\d+$' -and [int]$lpid -gt 0) {
|
||||
Write-Host "Stop port 8037 (netstat) PID $lpid"
|
||||
Stop-Process -Id ([int]$lpid) -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
Start-Sleep -Seconds 2
|
||||
|
||||
$py = Join-Path $backend "venv\Scripts\python.exe"
|
||||
Write-Host "Start Uvicorn :8037 ..."
|
||||
if ($env:SKIP_ALEMBIC -ne "1") {
|
||||
Write-Host "alembic upgrade head ..."
|
||||
Push-Location $backend
|
||||
try {
|
||||
& $py -m alembic upgrade head 2>&1 | ForEach-Object { Write-Host $_ }
|
||||
} catch {
|
||||
Write-Host "alembic failed: $($_.Exception.Message)"
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
} else {
|
||||
Write-Host "SKIP_ALEMBIC=1 - skipped alembic."
|
||||
}
|
||||
|
||||
# 不使用 --reload:Windows 上 reload 会多进程且多次重启易残留多个 8037 监听,导致随机命中旧实例、POST 执行 500
|
||||
Write-Host "Start Uvicorn :8037 (no --reload) ..."
|
||||
Start-Process -FilePath $py -ArgumentList @(
|
||||
"-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8037", "--reload"
|
||||
"-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8037"
|
||||
) -WorkingDirectory $backend -WindowStyle Minimized
|
||||
|
||||
Start-Sleep -Seconds 2
|
||||
@@ -35,6 +73,15 @@ Start-Sleep -Seconds 3
|
||||
try {
|
||||
$r = Invoke-WebRequest -Uri "http://127.0.0.1:8037/health" -UseBasicParsing -TimeoutSec 15
|
||||
Write-Host "health: $($r.Content)"
|
||||
$j = $r.Content | ConvertFrom-Json
|
||||
$names = @($j.PSObject.Properties.Name)
|
||||
if (-not ($names -contains "checks")) {
|
||||
Write-Host ""
|
||||
Write-Host "[WARN] /health has no 'checks' field; port 8037 may not be this repo API."
|
||||
Write-Host "Kill stray python/uvicorn, then: uvicorn app.main:app --host 0.0.0.0 --port 8037"
|
||||
Write-Host "Or use port 8040 and set AIAGENT_API_PROXY for npm run dev (see vite.config.ts)."
|
||||
Write-Host ""
|
||||
}
|
||||
} catch {
|
||||
Write-Host "health check failed: $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user