start-web-agent.ps1 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. if (-not (Test-Path (Join-Path $runtimeDir "node_modules"))) {
  16. Push-Location $runtimeDir
  17. try {
  18. npm install
  19. } finally {
  20. Pop-Location
  21. }
  22. }
  23. $stamp = Get-Date -Format "yyyyMMdd-HHmmss"
  24. $stdout = Join-Path $logsDir "web-agent-$stamp.out.log"
  25. $stderr = Join-Path $logsDir "web-agent-$stamp.err.log"
  26. Start-Process `
  27. -FilePath "powershell" `
  28. -ArgumentList @("-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", "npm run dev") `
  29. -WorkingDirectory $runtimeDir `
  30. -WindowStyle Hidden `
  31. -RedirectStandardOutput $stdout `
  32. -RedirectStandardError $stderr
  33. Write-Host "Web Agent start requested."
  34. Write-Host "URL: http://127.0.0.1:$env:WEB_AGENT_PORT"
  35. Write-Host "MCP: $env:SMQJH_MCP_URL"
  36. Write-Host "stdout: $stdout"
  37. Write-Host "stderr: $stderr"