param( [string]$BackendUrl = "http://127.0.0.1:8008", [string]$A1111Url = "http://127.0.0.1:7860", [int]$TimeoutSeconds = 60, [switch]$RequireA1111 ) $ErrorActionPreference = "Stop" function Wait-Endpoint { param( [Parameter(Mandatory = $true)][string]$Url, [Parameter(Mandatory = $true)][string]$Name, [Parameter(Mandatory = $true)][int]$Timeout ) $deadline = (Get-Date).AddSeconds($Timeout) do { try { $resp = Invoke-RestMethod -Uri $Url -Method Get -TimeoutSec 5 Write-Host "OK $Name -> $Url" return $resp } catch { Start-Sleep -Milliseconds 750 } } while ((Get-Date) -lt $deadline) throw "$Name not reachable within ${Timeout}s: $Url" } $null = Wait-Endpoint -Url "$BackendUrl/health" -Name "Backend health" -Timeout $TimeoutSeconds $null = Wait-Endpoint -Url "$BackendUrl/ready" -Name "Backend readiness" -Timeout $TimeoutSeconds $models = Wait-Endpoint -Url "$BackendUrl/models" -Name "Backend models" -Timeout $TimeoutSeconds $a1111Model = $models | Where-Object { $_.id -eq "a1111" } | Select-Object -First 1 if ($null -eq $a1111Model) { throw "Model 'a1111' is not registered in backend /models response" } if ($RequireA1111.IsPresent) { $null = Wait-Endpoint -Url "$A1111Url/sdapi/v1/sd-models" -Name "A1111 API" -Timeout $TimeoutSeconds if (-not $a1111Model.available) { throw "A1111 API reachable but backend still reports a1111.available=false" } } Write-Host "Stack readiness check passed."