-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathquickstart.ps1
More file actions
277 lines (234 loc) · 10.8 KB
/
quickstart.ps1
File metadata and controls
277 lines (234 loc) · 10.8 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
269
270
271
272
273
274
275
276
277
# ============================================================================
# M-Flow Quickstart — one command to launch the full stack (Windows)
# Usage: .\quickstart.ps1
# ============================================================================
$ErrorActionPreference = "Stop"
function Write-Ok { param($msg) Write-Host " ✓ $msg" -ForegroundColor Green }
function Write-Warn { param($msg) Write-Host " ! $msg" -ForegroundColor Yellow }
function Write-Err { param($msg) Write-Host " ✗ $msg" -ForegroundColor Red }
function Exit-Fatal { param($msg) Write-Err $msg; exit 1 }
function Show-Banner {
Write-Host ""
Write-Host " ╔══════════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host " ║ ║" -ForegroundColor Cyan
Write-Host " ║ M - F L O W Q U I C K S T A R T ║" -ForegroundColor Cyan
Write-Host " ║ ║" -ForegroundColor Cyan
Write-Host " ╚══════════════════════════════════════════╝" -ForegroundColor Cyan
Write-Host ""
}
function Show-ReadyBanner {
Write-Host ""
Write-Host " ╔══════════════════════════════════════════╗" -ForegroundColor Green
Write-Host " ║ M-Flow is ready! ║" -ForegroundColor Green
Write-Host " ║ ║" -ForegroundColor Green
Write-Host " ║ Frontend : http://localhost:3000 ║" -ForegroundColor Green
Write-Host " ║ API : http://localhost:8000 ║" -ForegroundColor Green
Write-Host " ║ API Docs : http://localhost:8000/docs ║" -ForegroundColor Green
Write-Host " ║ ║" -ForegroundColor Green
Write-Host " ║ Press Ctrl+C to stop ║" -ForegroundColor Green
Write-Host " ╚══════════════════════════════════════════╝" -ForegroundColor Green
Write-Host ""
}
# ── Safety ─────────────────────────────────────────────────────────────────
if (-not (Test-Path "pyproject.toml")) {
Exit-Fatal "Not in M-Flow project root. Run this from the cloned repo directory."
}
# ── Environment checks ────────────────────────────────────────────────────
Show-Banner
Write-Host " Checking environment..."
$hasDocker = $false
$hasPython = $false
try {
$dockerVer = & docker --version 2>$null
$composeVer = & docker compose version 2>$null
if ($dockerVer -and $composeVer) {
Write-Ok "Docker: $dockerVer"
Write-Ok "Compose: $composeVer"
$info = & docker info 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Ok "Docker daemon running"
$hasDocker = $true
} else {
Write-Warn "Docker installed but daemon not running"
}
}
} catch {
Write-Warn "Docker not found (install: https://docs.docker.com/get-docker/)"
}
try {
$pyVer = & python --version 2>$null
if ($pyVer -match "3\.(\d+)") {
$minor = [int]$Matches[1]
if ($minor -ge 10) {
Write-Ok $pyVer
$hasPython = $true
} else {
Write-Warn "$pyVer (need 3.10+)"
}
}
} catch {
Write-Warn "Python not found"
}
if (-not $hasDocker -and -not $hasPython) {
Exit-Fatal "Neither Docker nor Python 3.10+ found."
}
# Port checks
foreach ($port in @(8000, 3000)) {
try {
$conn = Test-NetConnection -ComputerName localhost -Port $port -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
if ($conn.TcpTestSucceeded) {
Write-Warn "Port $port already in use"
} else {
Write-Ok "Port $port available"
}
} catch {
Write-Ok "Port $port available"
}
}
# ── Mode selection ────────────────────────────────────────────────────────
Write-Host ""
Write-Host " Select deployment mode:"
Write-Host ""
if ($hasDocker) {
Write-Host " [1] Docker (recommended) — Backend + Frontend"
Write-Host " [2] Docker + Neo4j"
Write-Host " [3] Docker + PostgreSQL"
}
if ($hasPython) {
Write-Host " [4] Local Python (no Docker)"
}
if ($hasDocker) {
Write-Host " [5] Custom Docker profiles"
}
Write-Host ""
$choice = Read-Host " >"
if (-not $choice) { $choice = "1" }
# ── API Key configuration ────────────────────────────────────────────────
Write-Host ""
Write-Host " Configuring environment..."
if (Test-Path ".env") {
$ow = Read-Host " .env already exists. Overwrite? [y/N]"
if ($ow -eq "y" -or $ow -eq "Y") {
Copy-Item ".env.template" ".env" -Force
Write-Ok "Created fresh .env"
} else {
Write-Ok "Keeping existing .env"
}
} else {
Copy-Item ".env.template" ".env"
Write-Ok "Created .env from template"
}
$currentKey = (Get-Content .env | Select-String "^LLM_API_KEY=" | ForEach-Object { $_ -replace 'LLM_API_KEY=|"', '' }).Trim()
if ($currentKey -eq "your_api_key" -or [string]::IsNullOrEmpty($currentKey)) {
$secKey = Read-Host " Enter your LLM API key" -AsSecureString
$apiKey = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($secKey))
if ($apiKey) {
(Get-Content .env) -replace '^LLM_API_KEY=.*', "LLM_API_KEY=`"$apiKey`"" | Set-Content .env
Write-Ok "API key saved"
} else {
Write-Warn "No key entered — set LLM_API_KEY in .env later"
}
} else {
Write-Ok "API key already configured"
}
$provider = Read-Host " LLM provider [openai]"
if (-not $provider) { $provider = "openai" }
(Get-Content .env) -replace '^LLM_PROVIDER=.*', "LLM_PROVIDER=`"$provider`"" | Set-Content .env
$model = Read-Host " LLM model [gpt-5-nano]"
if (-not $model) { $model = "gpt-5-nano" }
(Get-Content .env) -replace '^LLM_MODEL=.*', "LLM_MODEL=`"$provider/$model`"" | Set-Content .env
Write-Ok "Configuration saved to .env"
# ── Health check ─────────────────────────────────────────────────────────
function Wait-ForHealth {
param($url, $timeout)
$elapsed = 0
while ($elapsed -lt $timeout) {
try {
$r = Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 3 -ErrorAction SilentlyContinue
if ($r.StatusCode -eq 200) { return $true }
} catch {}
Start-Sleep -Seconds 3
$elapsed += 3
Write-Host "." -NoNewline
}
Write-Host ""
return $false
}
# ── Launch ───────────────────────────────────────────────────────────────
function Launch-Docker {
param($profiles)
Write-Host ""
Write-Host " Starting M-Flow (first run may take 5-10 minutes)..."
$cmd = "docker compose $profiles up -d --build"
Invoke-Expression $cmd
Write-Host " Waiting for backend" -NoNewline
if (Wait-ForHealth "http://localhost:8000/health" 300) { Write-Ok "Backend ready" }
else { Write-Warn "Backend may still be starting" }
Write-Host " Waiting for frontend" -NoNewline
if (Wait-ForHealth "http://localhost:3000" 120) { Write-Ok "Frontend ready" }
else { Write-Warn "Frontend may still be building" }
Show-ReadyBanner
Start-Process "http://localhost:3000"
Write-Host " Streaming logs (Ctrl+C to stop)..."
try {
Invoke-Expression "docker compose $profiles logs -f"
} finally {
Write-Host " Stopping containers..."
Invoke-Expression "docker compose $profiles down"
Write-Host " Done."
}
}
function Launch-Local {
Write-Host ""
# Check uv
if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
Write-Host " Installing uv..."
Invoke-RestMethod https://astral.sh/uv/install.ps1 | Invoke-Expression
}
Write-Ok "uv installed"
# Check pnpm
if (-not (Get-Command pnpm -ErrorAction SilentlyContinue)) {
if (Get-Command npm -ErrorAction SilentlyContinue) {
npm install -g pnpm
} else {
Exit-Fatal "pnpm/npm not found. Install Node.js: https://nodejs.org"
}
}
Write-Ok "pnpm installed"
Write-Host " Installing dependencies..."
uv sync --extra api --extra dev
Push-Location m_flow-frontend; pnpm install --frozen-lockfile; Pop-Location
Write-Ok "Dependencies installed"
Write-Host " Starting backend on :8000..."
$backend = Start-Process -FilePath "uv" -ArgumentList "run python -m uvicorn m_flow.api.client:app --host 0.0.0.0 --port 8000" -PassThru -NoNewWindow
Write-Host " Starting frontend on :3000..."
$frontend = Start-Process -FilePath "pnpm" -ArgumentList "dev" -WorkingDirectory "m_flow-frontend" -PassThru -NoNewWindow
try {
Write-Host " Waiting for backend" -NoNewline
if (Wait-ForHealth "http://localhost:8000/health" 90) { Write-Ok "Backend ready" }
Write-Host " Waiting for frontend" -NoNewline
if (Wait-ForHealth "http://localhost:3000" 60) { Write-Ok "Frontend ready" }
Show-ReadyBanner
Start-Process "http://localhost:3000"
Write-Host " Press Ctrl+C to stop..."
Wait-Process -Id $backend.Id
} finally {
if (-not $backend.HasExited) { Stop-Process -Id $backend.Id -Force }
if (-not $frontend.HasExited) { Stop-Process -Id $frontend.Id -Force }
Write-Host " Stopped."
}
}
# ── Execute ──────────────────────────────────────────────────────────────
switch ($choice) {
"1" { Launch-Docker "--profile ui" }
"2" { Launch-Docker "--profile ui --profile neo4j" }
"3" { Launch-Docker "--profile ui --profile postgres" }
"4" { Launch-Local }
"5" {
Write-Host " Available profiles: ui, mcp, neo4j, postgres, chromadb, redis"
$custom = Read-Host " Enter profiles (space-separated)"
$profiles = ($custom.Split(" ") | ForEach-Object { "--profile $_" }) -join " "
Launch-Docker $profiles
}
default { Exit-Fatal "Invalid choice: $choice" }
}