start-web-agent.ps1 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. $ErrorActionPreference = "Stop"
  2. $root = Split-Path -Parent $PSScriptRoot
  3. $runtimeDir = Join-Path $root "smqjh-agent-runtime"
  4. $logsDir = Join-Path $root "logs"
  5. if (-not (Test-Path $runtimeDir)) {
  6. throw "Runtime directory not found: $runtimeDir"
  7. }
  8. New-Item -ItemType Directory -Force -Path $logsDir | Out-Null
  9. if (-not $env:SMQJH_MCP_URL) {
  10. $env:SMQJH_MCP_URL = "http://127.0.0.1:8765/mcp"
  11. }
  12. if (-not $env:WEB_AGENT_PORT) {
  13. $env:WEB_AGENT_PORT = "5188"
  14. }
  15. $venvDir = Join-Path $runtimeDir ".venv"
  16. $python = Join-Path $venvDir "Scripts\python.exe"
  17. if (-not (Test-Path $python)) {
  18. Push-Location $runtimeDir
  19. try {
  20. python -m venv .venv
  21. } finally {
  22. Pop-Location
  23. }
  24. }
  25. Push-Location $runtimeDir
  26. try {
  27. & $python -m pip install --disable-pip-version-check -r requirements.txt
  28. } finally {
  29. Pop-Location
  30. }
  31. $stamp = Get-Date -Format "yyyyMMdd-HHmmss"
  32. $stdout = Join-Path $logsDir "web-agent-$stamp.out.log"
  33. $stderr = Join-Path $logsDir "web-agent-$stamp.err.log"
  34. Start-Process `
  35. -FilePath $python `
  36. -ArgumentList @("-m", "app.server") `
  37. -WorkingDirectory $runtimeDir `
  38. -WindowStyle Hidden `
  39. -RedirectStandardOutput $stdout `
  40. -RedirectStandardError $stderr
  41. Write-Host "Web Agent start requested."
  42. Write-Host "URL: http://127.0.0.1:$env:WEB_AGENT_PORT"
  43. Write-Host "MCP: $env:SMQJH_MCP_URL"
  44. Write-Host "stdout: $stdout"
  45. Write-Host "stderr: $stderr"