Repository navigation
Expand file tree
/
Copy pathstart.bat
More file actions
268 lines (238 loc) · 9.59 KB
/
Copy pathstart.bat
File metadata and controls
268 lines (238 loc) · 9.59 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
@echo off
setlocal enabledelayedexpansion
REM ============================================================================
REM Oracle-X Financial Terminal - Windows Quick Start
REM Windows counterpart of start.sh: provisions deps, frees ports 8000/3100,
REM boots backend + frontend in their own windows, seeds the RAG 2.0 index.
REM ============================================================================
cd /d "%~dp0"
title Oracle-X Launcher
echo.
echo ===============================================================
echo ORACLE-X - FINANCIAL INTELLIGENCE
echo ===============================================================
echo.
REM ---------------------------------------------------------------------------
REM SYSTEM CHECK
REM ---------------------------------------------------------------------------
echo [ SYSTEM CHECK ]
echo.
where npm >nul 2>&1
if errorlevel 1 (
echo [X] npm not found^^!
echo Install Node.js 18+ from https://nodejs.org/
goto :fail
)
for /f "delims=" %%v in ('node -v 2^>nul') do set "NODE_VER=%%v"
echo [OK] Node.js !NODE_VER! detected
set "PY_CMD="
python --version >nul 2>&1 && set "PY_CMD=python"
if not defined PY_CMD (
py -3 --version >nul 2>&1 && set "PY_CMD=py -3"
)
if not defined PY_CMD (
echo [X] Python not found^^!
echo Install Python 3.11+ from https://www.python.org/downloads/
echo Make sure "Add python.exe to PATH" is checked during setup.
goto :fail
)
for /f "delims=" %%v in ('!PY_CMD! --version 2^>^&1') do set "PY_VER=%%v"
echo [OK] !PY_VER! detected
REM 3.11 is the floor rather than a preference: the backend annotates with
REM `X | None` and CI runs 3.11. An older interpreter - and the one the
REM Microsoft Store offers is often older - fails at import with a syntax
REM error that reads like a corrupt source file instead of a wrong Python.
!PY_CMD! -c "import sys; sys.exit(0 if sys.version_info[:2] >= (3, 11) else 1)" >nul 2>&1
if errorlevel 1 (
echo [X] Python 3.11 or newer is required^^!
echo Install it from https://www.python.org/downloads/
goto :fail
)
REM ---------------------------------------------------------------------------
REM ENVIRONMENT FILES
REM ---------------------------------------------------------------------------
echo.
echo [ ENVIRONMENT ]
echo.
if not exist "backend\.env" (
if exist "backend\.env.example" (
copy /y "backend\.env.example" "backend\.env" >nul
echo [OK] backend\.env created from .env.example - fill in your keys
)
) else (
echo [OK] backend\.env present
)
if not exist "frontend\.env.local" (
if exist "frontend\.env.example" (
copy /y "frontend\.env.example" "frontend\.env.local" >nul
echo [OK] frontend\.env.local created from .env.example
)
) else (
echo [OK] frontend\.env.local present
)
REM ---------------------------------------------------------------------------
REM DEPENDENCIES
REM ---------------------------------------------------------------------------
echo.
echo [ DEPENDENCIES ]
echo.
REM Windows uses its own venv dir so it never collides with a macOS/Linux
REM "backend\venv" created by start.sh in the same checkout.
REM Existence is not readiness. The first install pulls torch through
REM sentence-transformers, which is a multi-gigabyte download that people
REM interrupt - and a half-installed venv still activates, so the old check
REM reported "cached" and then uvicorn died on an import in a window that
REM scrolled past. Probe the imports instead.
set "VENV_READY="
if exist "backend\venv-win\Scripts\activate.bat" (
call "backend\venv-win\Scripts\activate.bat"
REM find_spec rather than a real import: importing chromadb costs seconds
REM of model-registry work on a cold filesystem, and this runs every time.
python -c "import importlib.util as u, sys; sys.exit(0 if all(u.find_spec(m) for m in ('fastapi','uvicorn','chromadb')) else 1)" >nul 2>&1 && set "VENV_READY=1"
)
if defined VENV_READY (
echo [OK] Python environment cached
) else (
if not exist "backend\venv-win\Scripts\activate.bat" (
echo [~] Creating Python virtual environment...
!PY_CMD! -m venv "backend\venv-win"
if errorlevel 1 (
echo [X] Failed to create the virtual environment.
goto :fail
)
call "backend\venv-win\Scripts\activate.bat"
)
echo [~] Installing Python packages - budget a few GB and ten
echo minutes on the first run. Progress is left visible on
echo purpose: quiet output here looks like a hang.
python -m pip install --upgrade pip -q
pip install -r "backend\requirements.txt"
if errorlevel 1 (
echo [X] pip install failed - see the output above.
echo On Windows this is usually chromadb's hnswlib with no
echo matching wheel: install "Microsoft C++ Build Tools", or
echo use Python 3.11/3.12, which have prebuilt wheels.
goto :fail
)
echo [OK] Python environment ready
)
if not exist "frontend\node_modules" (
echo [~] Installing frontend packages...
pushd "frontend"
call npm install --silent
popd
echo [OK] Frontend packages installed
) else (
echo [OK] Frontend packages cached
)
REM ---------------------------------------------------------------------------
REM PORT CLEANUP
REM ---------------------------------------------------------------------------
echo.
echo [ PORT CLEANUP ]
echo.
call :free_port 8000
call :free_port 3100
REM ---------------------------------------------------------------------------
REM STARTING SERVICES
REM ---------------------------------------------------------------------------
echo.
echo [ STARTING SERVICES ]
echo.
REM uvicorn must run with cwd=backend - the app uses flat imports.
pushd "backend"
start "Oracle-X Backend" cmd /k "call venv-win\Scripts\activate.bat && set PYTHONUNBUFFERED=1 && uvicorn main:app --reload --host 0.0.0.0 --port 8000"
popd
echo [OK] Backend starting - FastAPI on port 8000
pushd "frontend"
start "Oracle-X Frontend" cmd /k "npm run dev"
popd
echo [OK] Frontend starting - Next.js on port 3100
REM ---------------------------------------------------------------------------
REM RAG 2.0 INITIALIZATION
REM ---------------------------------------------------------------------------
echo.
echo [ RAG 2.0 INITIALIZATION ]
echo.
REM The backend seeds its own corpus in the boot warm-up now
REM (services/rag_v2_service.ensure_seeded), building a year of history only
REM when there is not one already. This block reports; it no longer triggers.
REM
REM It used to POST /api/rag/initialize. That route is admin-only now, because
REM an open endpoint that re-embeds the whole corpus is a way for anyone to
REM pin the embedding model - and a batch file has no token to present.
where curl >nul 2>&1
if errorlevel 1 (
echo [!] curl not found - cannot report the RAG corpus state.
echo The backend seeds it on its own regardless.
goto :seeded
)
REM Poll rather than sleep ten seconds. A cold start loads Chroma and can
REM take longer than that, and a backend that died on a missing
REM SUPABASE_SERVICE_ROLE_KEY never takes any time at all - both were
REM reported the same way by a fixed wait followed by one attempt.
echo [~] Waiting for the API to come up...
set "API_UP="
for /l %%i in (1,1,30) do (
if not defined API_UP (
curl -s -o nul http://localhost:8000/api/system/health && set "API_UP=1"
if not defined API_UP timeout /t 2 /nobreak >nul
)
)
if not defined API_UP (
echo [!] The API did not answer within a minute. Read the backend
echo window - it will say why, and it usually says a missing key.
goto :seeded
)
curl -s http://localhost:8000/api/rag/stats | findstr /C:"\"status\":\"healthy\"" >nul 2>&1
if errorlevel 1 (
echo [!] RAG store unavailable - AI answers will run without
echo historical context. The backend window says why.
) else (
echo [OK] RAG 2.0 corpus ready
)
:seeded
REM ---------------------------------------------------------------------------
REM READY
REM ---------------------------------------------------------------------------
echo.
echo ===============================================================
echo ORACLE-X IS READY
echo ===============================================================
echo Frontend : http://localhost:3100
echo Backend : http://localhost:8000
echo API Docs : http://localhost:8000/docs
echo ===============================================================
echo.
echo Backend and frontend run in their own windows.
echo Close those windows to stop the services.
echo.
start "" http://localhost:3100
pause
exit /b 0
REM ---------------------------------------------------------------------------
REM SUBROUTINES
REM ---------------------------------------------------------------------------
:free_port
set "PORT=%~1"
set "FOUND="
REM The trailing space matters: ":3100" is a substring of ":31000", so the
REM unanchored match could kill an unrelated listener on a five-digit port.
for /f "tokens=5" %%p in ('netstat -ano ^| findstr /C:":%PORT% " ^| findstr "LISTENING"') do (
if not "%%p"=="0" (
taskkill /F /PID %%p >nul 2>&1
set "FOUND=1"
)
)
if defined FOUND (
echo [OK] Port %PORT% freed
) else (
echo [OK] Port %PORT% available
)
goto :eof
:fail
echo.
echo Startup aborted.
echo.
pause
exit /b 1