# Aurora Service

`aurora-service` is a FastAPI scaffold for AISTALK media forensics workflows.

## API

- `POST /api/aurora/upload` (`multipart/form-data`)
  - fields: `file`, `mode` (`tactical|forensic`)
  - returns `job_id`
- `GET /api/aurora/status/{job_id}`
- `GET /api/aurora/jobs`
- `GET /api/aurora/result/{job_id}`
- `POST /api/aurora/cancel/{job_id}`
- `POST /api/aurora/delete/{job_id}`
- `GET /api/aurora/files/{job_id}/{file_name}`

## Notes

- Visual media (`video`, `photo`) run deterministic sequential enhancement with conservative defaults:
  - `frame -> pre-denoise -> deblur -> face restore (GFPGAN / CodeFormer-style fallback) -> Real-ESRGAN`
  - For `priority=faces`, pipeline can switch to ROI-only face processing (background preserved).
  - Score-driven candidate selection is enabled for forensic face workflows.
- `audio` path remains scaffold (`Echo`) for now.
- Forensic mode adds chain-of-custody artifacts and signature metadata.
- Model weights are auto-downloaded to `AURORA_MODELS_DIR` on first run.

## Local run

```bash
cd services/aurora-service
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 9401
```

## Native macOS run (Apple Silicon)

```bash
cd services/aurora-service
./setup-native-macos.sh
./start-native-macos.sh
```

This profile enables:
- `AURORA_FORCE_CPU=false`
- `AURORA_PREFER_MPS=true`
- `AURORA_ENABLE_VIDEOTOOLBOX=true`

### Runtime env vars

- `AURORA_DATA_DIR` (default: `/data/aurora`)
- `AURORA_MODELS_DIR` (default: `/data/aurora/models`)
- `AURORA_FORCE_CPU` (default: `true`)
- `AURORA_PREFER_MPS` (default: `true`)
- `AURORA_ENABLE_VIDEOTOOLBOX` (default: `true`)
- `AURORA_FFMPEG_VIDEO_ENCODER` (optional override, e.g. `h264_videotoolbox`)
- `KLING_ACCESS_KEY` / `KLING_SECRET_KEY` (required for Kling endpoints)
- `KLING_BASE_URL` (default: `https://api.klingai.com`)
- `KLING_TIMEOUT` (default: `60`)

## Autostart via launchd (macOS)

```bash
cd services/aurora-service
./launchd/install-launchd.sh
```

Optional Kling setup via Keychain:

```bash
cd services/aurora-service
./launchd/configure-kling-keychain.sh
```

The script stores credentials in macOS Keychain (`daarion.kling.access_key`, `daarion.kling.secret_key`) and restarts launchd service. `start-native-macos.sh` reads Keychain-backed values automatically when `KLING_*` env vars are not set.

Alternative: create `${HOME}/.sofiia/aurora.env` (chmod `600`) with:

```bash
KLING_ACCESS_KEY=...
KLING_SECRET_KEY=...
KLING_BASE_URL=https://api.klingai.com
KLING_TIMEOUT=60
```

`install-launchd.sh` sets `AURORA_ENV_FILE=${HOME}/.sofiia/aurora.env` by default.

Useful commands:

```bash
./launchd/status-launchd.sh
./launchd/uninstall-launchd.sh
```

`install-launchd.sh` bootstraps the service immediately, so reboot is not required.
