Files
Agent-Workbench/scripts/Stop-Workbench.ps1
2026-10-31 09:03:01 +08:00

14 lines
1.1 KiB
PowerShell

[CmdletBinding()]
param([int]$Port = 0, [string]$DataRoot = '', [string]$NodePath = '')
$ErrorActionPreference = 'Stop'
[Console]::OutputEncoding = [Text.UTF8Encoding]::new($false)
$appRoot = [IO.Path]::GetFullPath((Split-Path -Parent $PSScriptRoot))
if ($Port -eq 0) { $Port = if ($env:AGENT_WORKBENCH_PORT) { [int]$env:AGENT_WORKBENCH_PORT } else { 4318 } }
if (-not $DataRoot) { $DataRoot = if ($env:AGENT_WORKBENCH_DATA_DIR) { $env:AGENT_WORKBENCH_DATA_DIR } else { Join-Path $env:LOCALAPPDATA 'AgentWorkbench' } }
$DataRoot = [IO.Path]::GetFullPath($DataRoot)
if (-not $NodePath) { $NodePath = Join-Path $appRoot 'runtime\node.exe' }
if (-not (Test-Path -LiteralPath $NodePath)) { $NodePath = (Get-Command node.exe -ErrorAction Stop).Source }
$output = & $NodePath (Join-Path $appRoot 'dist-server\host-launcher.mjs') stop --app-root $appRoot --data-root $DataRoot --node $NodePath --port ([string]$Port)
if ($LASTEXITCODE -ne 0) { throw 'The original host stop remains unverified. See the diagnostic above.' }
$result = $output | ConvertFrom-Json
Write-Output ('Agent Workbench host: ' + $result.state)