$ErrorActionPreference = "Stop" if (Test-Path -LiteralPath ".env") { Get-Content -LiteralPath ".env" | ForEach-Object { $line = $_.Trim() if ($line -and -not $line.StartsWith("#") -and $line.Contains("=")) { $name, $value = $line -split "=", 2 [Environment]::SetEnvironmentVariable($name.Trim(), $value.Trim(), "Process") } } } if (-not $env:MIMO_API_KEY) { Write-Error "MIMO_API_KEY is not set. Copy .env.example to .env and add your Xiaomi MiMo API key." } $hostAddress = if ($env:HOST) { $env:HOST } else { "127.0.0.1" } $portNumber = if ($env:PORT) { $env:PORT } else { "8787" } $installedPython = Join-Path $env:LOCALAPPDATA "Programs\Python\Python313\python.exe" if (Test-Path -LiteralPath $installedPython) { & $installedPython -m uvicorn mimo_gateway:app --host $hostAddress --port $portNumber exit $LASTEXITCODE } $python = Get-Command python -ErrorAction SilentlyContinue if ($python -and $python.Source -notlike "*WindowsApps*") { & $python.Source -m uvicorn mimo_gateway:app --host $hostAddress --port $portNumber exit $LASTEXITCODE } $pyLauncher = Get-Command py -ErrorAction SilentlyContinue if ($pyLauncher) { & $pyLauncher.Source -3 -m uvicorn mimo_gateway:app --host $hostAddress --port $portNumber exit $LASTEXITCODE } Write-Error "Python 3.11 or newer was not found. Install Python, then run this script again."