Add /api/dreamer/status and /api/dreamer/run endpoints
This commit is contained in:
@@ -625,6 +625,39 @@ async def transcribe_audio(request: Request, audio: UploadFile = File(...), auth
|
||||
os.unlink(tmp_path)
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@app.get("/api/dreamer/status")
|
||||
async def dreamer_status(auth: str = Depends(require_auth)):
|
||||
try:
|
||||
state_path = Path.home() / "aaronai" / "dreamer_state.json"
|
||||
if state_path.exists():
|
||||
state = json.loads(state_path.read_text())
|
||||
else:
|
||||
state = {}
|
||||
last_ts = state.get("last_dream_timestamp", 0)
|
||||
last_dt = datetime.fromtimestamp(last_ts).strftime("%Y-%m-%d %H:%M") if last_ts else "never"
|
||||
return JSONResponse({
|
||||
"last_dream": last_dt,
|
||||
"last_mode": state.get("last_dream_mode", "none"),
|
||||
"last_file": state.get("last_dream_file", ""),
|
||||
})
|
||||
except Exception as e:
|
||||
return JSONResponse({"last_dream": "unknown", "last_mode": "none", "last_file": "", "error": str(e)})
|
||||
|
||||
@app.post("/api/dreamer/run")
|
||||
async def run_dreamer(request: Request, auth: str = Depends(require_auth)):
|
||||
try:
|
||||
body = await request.json()
|
||||
mode = body.get("mode", "nrem")
|
||||
task = body.get("task", None)
|
||||
dream_script = str(Path.home() / "aaronai" / "scripts" / "dream.py")
|
||||
cmd = [PYTHON, dream_script, "--mode", mode]
|
||||
if task:
|
||||
cmd += ["--task", task]
|
||||
subprocess.Popen(cmd, cwd=str(Path.home() / "aaronai"))
|
||||
return JSONResponse({"started": True, "mode": mode})
|
||||
except Exception as e:
|
||||
return JSONResponse({"started": False, "error": str(e)})
|
||||
|
||||
@app.post("/api/capture")
|
||||
async def capture_audio(audio: UploadFile = File(...)):
|
||||
"""Auth-free capture endpoint — saves transcribed audio to Nextcloud Journal/Captures/"""
|
||||
|
||||
Reference in New Issue
Block a user