-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.bat
More file actions
116 lines (104 loc) · 4.24 KB
/
setup.bat
File metadata and controls
116 lines (104 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
@echo off
setlocal enableextensions enabledelayedexpansion
rem Resolve repo root (folder containing this script)
set "REPO_ROOT=%~dp0"
if "%REPO_ROOT:~-1%"=="\" set "REPO_ROOT=%REPO_ROOT:~0,-1%"
cd /d "%REPO_ROOT%"
echo [1/7] Checking Docker...
where docker >nul 2>&1
if errorlevel 1 (
where winget >nul 2>&1
if not errorlevel 1 (
echo Docker not found. Attempting to install Docker Desktop with winget...
winget install -e --id Docker.DockerDesktop --accept-package-agreements --accept-source-agreements
)
)
where docker >nul 2>&1
if errorlevel 1 (
echo Docker is not installed. Please install Docker Desktop, then re-run setup.bat.
exit /b 1
)
docker info >nul 2>&1
if errorlevel 1 (
echo Docker is installed but not running.
echo Start Docker Desktop, wait for it to be ready, then re-run setup.bat.
exit /b 1
)
echo [2/7] Checking required files...
if not exist "%REPO_ROOT%\open hand\docker_runtime.py" (
echo Missing file: %REPO_ROOT%\open hand\docker_runtime.py
exit /b 1
)
if not exist "%REPO_ROOT%\open hand\openhands_cli.py" (
echo Missing file: %REPO_ROOT%\open hand\openhands_cli.py
exit /b 1
)
echo [3/7] Detecting local model...
if not defined LLM_MODEL (
for /f "usebackq delims=" %%M in (`powershell -NoProfile -Command "$ErrorActionPreference='SilentlyContinue'; try { $r = Invoke-RestMethod -UseBasicParsing -TimeoutSec 3 http://localhost:8000/v1/models; if ($r.data) { ($r.data | Select-Object -ExpandProperty id) -join \"`n\" } } catch { }"`) do (
if /i "%%M"=="gpt-oss-120b" set "LLM_MODEL=%%M"
if not defined LLM_MODEL set "LLM_MODEL=%%M"
)
)
if not defined LLM_MODEL set "LLM_MODEL=gpt-oss-120b"
echo Using model: %LLM_MODEL%
echo [4/7] Computing workspace mount path...
rem Default workspace is the parent of the repo root (so sibling projects are visible)
for %%I in ("%REPO_ROOT%\..") do set "WORKSPACE_WIN=%%~fI"
if defined WORKSPACE_DIR set "WORKSPACE_WIN=%WORKSPACE_DIR%"
if not exist "%WORKSPACE_WIN%" (
echo Workspace path not found: %WORKSPACE_WIN%
exit /b 1
)
rem Convert Windows path to Docker Desktop POSIX path
for /f "usebackq tokens=*" %%P in (`powershell -NoProfile -Command "$ws = [System.IO.Path]::GetFullPath('%WORKSPACE_WIN%'); $drive = $ws.Substring(0,1).ToLower(); $rest = $ws.Substring(2).Replace('\','/'); Write-Host \"/run/desktop/mnt/host/$drive$rest\""`) do set "WORKSPACE_POSIX=%%P"
if not defined WORKSPACE_POSIX (
echo Failed to compute workspace path for Docker.
exit /b 1
)
echo Workspace: %WORKSPACE_WIN%
if not defined LLM_BASE_URL set "LLM_BASE_URL=http://host.docker.internal:8000/v1"
if not defined LLM_API_KEY set "LLM_API_KEY=local-llm"
echo [5/7] Cleaning old containers...
docker rm -f openhands-app >nul 2>&1
for /f %%C in ('docker ps -aq --filter "name=openhands-runtime-"') do docker rm -f %%C >nul 2>&1
echo [6/7] Starting OpenHands...
docker run -d --pull=missing ^
-e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.openhands.dev/openhands/runtime:1.1-nikolaik ^
-e LOG_ALL_EVENTS=true ^
-e LLM_MODEL=%LLM_MODEL% ^
-e LLM_API_KEY=%LLM_API_KEY% ^
-e LLM_BASE_URL=%LLM_BASE_URL% ^
-e LLM_CUSTOM_LLM_PROVIDER=openai ^
-e ENABLE_BROWSER=false ^
-e SANDBOX_SKIP_CHOWN=1 ^
-e "SANDBOX_VOLUMES=%WORKSPACE_POSIX%:/workspace:rw" ^
-v /var/run/docker.sock:/var/run/docker.sock ^
-v openhands_data:/.openhands ^
-p 3000:3000 ^
--add-host host.docker.internal:host-gateway ^
--name openhands-app ^
docker.openhands.dev/openhands/openhands:1.1
if errorlevel 1 (
echo Failed to start OpenHands container.
exit /b 1
)
echo [7/7] Applying runtime patch and restarting...
docker cp "%REPO_ROOT%\open hand\docker_runtime.py" openhands-app:/app/openhands/runtime/impl/docker/docker_runtime.py >nul 2>&1
docker restart openhands-app >nul 2>&1
echo Waiting for OpenHands API to be ready...
:wait_loop
powershell -NoProfile -Command "try { Invoke-RestMethod -Uri http://localhost:3000/api/options/config -TimeoutSec 2 | Out-Null; exit 0 } catch { exit 1 }"
if errorlevel 1 (
timeout /t 3 /nobreak >nul
goto wait_loop
)
echo OpenHands API is ready.
echo.
echo Setup complete.
echo Run the CLI:
echo python "%REPO_ROOT%\open hand\openhands_cli.py"
echo.
echo Note: Your local model server must be running at http://localhost:8000/v1
echo If you move this repo, just run setup.bat again.
endlocal