param(
  [string]$BaseUrl = "https://agent-fleet.cn/v1",
  [string]$ApiKey = "replace-with-customer-key",
  [string]$Model = "fleet-auto"
)
$ErrorActionPreference = "Stop"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$BundleRoot = Resolve-Path (Join-Path $ScriptDir "..")
$ConfigPath = Join-Path $BundleRoot "config\customer.config.json"

if ($ApiKey -eq "replace-with-customer-key" -or [string]::IsNullOrWhiteSpace($ApiKey)) {
  $ApiKey = Read-Host "请输入 Fleet API Key"
}

$json = Get-Content -Raw -Encoding UTF8 $ConfigPath | ConvertFrom-Json
$json.fleet_base_url = $BaseUrl
$json.fleet_api_key = $ApiKey
$json.default_model = $Model
$json | ConvertTo-Json -Depth 8 | Set-Content -Encoding UTF8 $ConfigPath
Write-Host "Config updated:" $ConfigPath

function Show-CommandStatus {
  param([string]$Name, [string]$Hint)
  $cmd = Get-Command $Name -ErrorAction SilentlyContinue
  if ($null -eq $cmd) {
    Write-Host "[MISSING] $Name" -ForegroundColor Yellow
    Write-Host "  Hint: $Hint"
  } else {
    Write-Host "[OK] $Name -> $($cmd.Path)" -ForegroundColor Green
  }
}

Write-Host "Checking local executor CLIs..."
Show-CommandStatus -Name "claude" -Hint "Install Claude Code CLI and ensure 'claude' is in PATH."
Show-CommandStatus -Name "hermes" -Hint "Install Hermes CLI and ensure 'hermes' is in PATH."
Show-CommandStatus -Name "openclaw" -Hint "Install OpenClaw CLI and ensure 'openclaw' is in PATH."

python (Join-Path $ScriptDir "launch.py")
