|
| 1 | +$ErrorActionPreference = "Stop" |
| 2 | + |
| 3 | +$Root = Split-Path -Parent $MyInvocation.MyCommand.Path |
| 4 | +$Node = (Get-Command node.exe -ErrorAction Stop).Source |
| 5 | +$Opm = Join-Path $Root "packages\openmemory-js\bin\opm.js" |
| 6 | +$DataDir = Join-Path $Root "data" |
| 7 | +$LogDir = Join-Path $Root "logs" |
| 8 | +$DbPath = Join-Path $DataDir "openmemory.sqlite" |
| 9 | +$Stdout = Join-Path $LogDir "openmemory-server.log" |
| 10 | +$Stderr = Join-Path $LogDir "openmemory-server.err.log" |
| 11 | + |
| 12 | +function Test-OpenMemoryHealth { |
| 13 | + try { |
| 14 | + $response = Invoke-RestMethod -Uri "http://127.0.0.1:8080/health" -TimeoutSec 3 |
| 15 | + return [bool]$response.ok |
| 16 | + } catch { |
| 17 | + return $false |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +if (Test-OpenMemoryHealth) { |
| 22 | + return |
| 23 | +} |
| 24 | + |
| 25 | +if (-not (Test-Path -LiteralPath $Opm)) { |
| 26 | + throw "OpenMemory CLI missing at $Opm. Run npm install in packages\openmemory-js." |
| 27 | +} |
| 28 | + |
| 29 | +New-Item -ItemType Directory -Force -Path $DataDir, $LogDir | Out-Null |
| 30 | + |
| 31 | +$env:OPENMEMORY_URL = "http://127.0.0.1:8080" |
| 32 | +$env:OM_PORT = "8080" |
| 33 | +$env:OM_DB_PATH = $DbPath |
| 34 | +$env:OM_TIER = "hybrid" |
| 35 | +$env:NO_COLOR = "1" |
| 36 | + |
| 37 | +Start-Process ` |
| 38 | + -FilePath $Node ` |
| 39 | + -ArgumentList @("`"$Opm`"", "serve") ` |
| 40 | + -WorkingDirectory $Root ` |
| 41 | + -WindowStyle Hidden ` |
| 42 | + -RedirectStandardOutput $Stdout ` |
| 43 | + -RedirectStandardError $Stderr | Out-Null |
| 44 | + |
| 45 | +$deadline = (Get-Date).AddSeconds(20) |
| 46 | +while ((Get-Date) -lt $deadline) { |
| 47 | + if (Test-OpenMemoryHealth) { |
| 48 | + return |
| 49 | + } |
| 50 | + Start-Sleep -Milliseconds 500 |
| 51 | +} |
| 52 | + |
| 53 | +throw "OpenMemory did not become healthy on http://127.0.0.1:8080/health. Check $Stdout and $Stderr." |
0 commit comments