Keep source, config, and deploy files. Leave runtime data, uploads, and logs out of git. Co-authored-by: Cursor <cursoragent@cursor.com>
70 lines
2.5 KiB
PowerShell
70 lines
2.5 KiB
PowerShell
# Foreground Kamidso API (FastAPI + engine). Blocks this terminal until Ctrl+C.
|
|
$ErrorActionPreference = 'Stop'
|
|
$Backend = Split-Path -Parent $PSScriptRoot
|
|
Set-Location $Backend
|
|
|
|
$envFile = Join-Path $Backend '.env'
|
|
if (Test-Path $envFile) {
|
|
Get-Content $envFile | ForEach-Object {
|
|
$line = $_.Trim()
|
|
if (-not $line -or $line.StartsWith('#')) { return }
|
|
$idx = $line.IndexOf('=')
|
|
if ($idx -lt 1) { return }
|
|
$name = $line.Substring(0, $idx).Trim()
|
|
$value = $line.Substring($idx + 1).Trim()
|
|
if ($value.StartsWith('"') -and $value.EndsWith('"')) {
|
|
$value = $value.Substring(1, $value.Length - 2)
|
|
}
|
|
Set-Item -Path "Env:$name" -Value $value
|
|
}
|
|
Write-Host "Loaded env from $envFile"
|
|
} else {
|
|
Write-Warning "No .env at $envFile (copy .env.example)"
|
|
}
|
|
|
|
$venvCandidates = @(
|
|
(Join-Path $Backend '.venv\Scripts\Activate.ps1'),
|
|
(Join-Path (Split-Path -Parent $Backend) '.venv\Scripts\Activate.ps1')
|
|
)
|
|
foreach ($venvActivate in $venvCandidates) {
|
|
if (Test-Path $venvActivate) {
|
|
. $venvActivate
|
|
break
|
|
}
|
|
}
|
|
|
|
$config = Join-Path $Backend 'configs\dbgpt-proxy-openai.toml'
|
|
$mongoUri = if ($env:MONGODB_URI) { $env:MONGODB_URI } else { 'mongodb://127.0.0.1:27017/kamidso' }
|
|
|
|
chcp 65001 | Out-Null
|
|
$env:PYTHONUTF8 = '1'
|
|
$env:PYTHONIOENCODING = 'utf-8'
|
|
|
|
if (-not (Get-NetTCPConnection -LocalPort 27017 -State Listen -ErrorAction SilentlyContinue)) {
|
|
Write-Warning 'MongoDB is not listening on 27017. Start: docker compose -f docker/kamidso/docker-compose.yml up -d'
|
|
}
|
|
|
|
$busy = Get-NetTCPConnection -LocalPort 5670 -State Listen -ErrorAction SilentlyContinue
|
|
if ($busy) {
|
|
$portPids = @($busy | ForEach-Object { $_.OwningProcess } | Sort-Object -Unique)
|
|
Write-Warning "Port 5670 already in use by PID(s): $($portPids -join ', ')"
|
|
foreach ($procId in $portPids) {
|
|
$proc = Get-CimInstance Win32_Process -Filter "ProcessId=$procId" -ErrorAction SilentlyContinue
|
|
if ($proc) { Write-Host " [$procId] $($proc.CommandLine)" }
|
|
}
|
|
Write-Host "Stop them: Stop-Process -Id $($portPids -join ',') -Force" -ForegroundColor Yellow
|
|
exit 1
|
|
}
|
|
|
|
Write-Host ''
|
|
Write-Host 'Starting Kamidso (foreground — like uvicorn/FastAPI)' -ForegroundColor Green
|
|
Write-Host " API: http://127.0.0.1:5670"
|
|
Write-Host " MongoDB: $mongoUri"
|
|
Write-Host " Engine: $config"
|
|
Write-Host " Login: $($env:KAMIDSO_ADMIN_EMAIL)"
|
|
Write-Host ' Status: .\scripts\status.ps1 (in another terminal)'
|
|
Write-Host ' Stop: Ctrl+C'
|
|
Write-Host ''
|
|
|
|
python -m kamidso.cli serve --host 127.0.0.1 --port 5670 --config $config
|