@echo off
title AgentOSP - Mix of Agents
cd /d "%~dp0"
set "PYTHONUTF8=1"

if exist "%~dp0Tools\Python\python.exe" (
    "%~dp0Tools\Python\python.exe" "%~dp0Scripts\AgentOSP.py" %*
    goto end
)

if exist "%~dp0Installers\Python\*.zip" (
    echo [PYTHON] Portable Python runtime not found. Extracting bundled Python...
    powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$z=Get-ChildItem -Path '%~dp0Installers\Python' -Filter '*.zip' | Select-Object -First 1; if($z){ New-Item -ItemType Directory -Path '%~dp0Tools\Python' -Force | Out-Null; Expand-Archive -Path $z.FullName -DestinationPath '%~dp0Tools\Python' -Force }"
    if exist "%~dp0Tools\Python\python.exe" (
        "%~dp0Tools\Python\python.exe" "%~dp0Scripts\AgentOSP.py" %*
        goto end
    )
)

py -3 --version >nul 2>&1
if %errorlevel% equ 0 (
    py -3 "%~dp0Scripts\AgentOSP.py" %*
    goto end
)

python --version >nul 2>&1
if %errorlevel% equ 0 (
    python "%~dp0Scripts\AgentOSP.py" %*
    goto end
)

echo [ERROR] Python runtime was not found.
echo Expected one of: Tools\Python\python.exe, Windows py launcher, PATH python.exe, or bundled Installers\Python\*.zip.
echo Re-run Install Mix of Agents.bat to bootstrap bundled portable Python, or use Start AgentOS.bat / Start AgentOSH.bat.
pause
:end
