File size: 1,514 Bytes
d03f57f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
PII-Scrub-Assistant-v1 -- FastAPI Server (port 7860)
=====================================================
OpenEnv 2026 Sync Protocol with player_id + session_id validation.
"""
from __future__ import annotations
from fastapi import FastAPI, HTTPException
from environment import ScrubEnvironment
from models import ResetRequest, ScrubObservation, ScrubState, StepRequest

app = FastAPI(title="PII-Scrub-Assistant-v1", version="1.0.0",
    description="OpenEnv 2026 Sync -- PII redaction with player_id + session_id.")

env = ScrubEnvironment()

@app.post("/reset", response_model=ScrubObservation)
async def reset(body: ResetRequest):
    try:
        return env.reset(player_id=body.player_id, session_id=body.session_id, task_id=body.task_id)
    except ValueError as e:
        raise HTTPException(400, detail=str(e))

@app.post("/step", response_model=ScrubObservation)
async def step(body: StepRequest):
    try:
        return env.step(player_id=body.player_id, session_id=body.session_id, redacted_text=body.action.redacted_text)
    except PermissionError as e:
        raise HTTPException(403, detail=str(e))
    except RuntimeError as e:
        raise HTTPException(409, detail=str(e))

@app.get("/state", response_model=ScrubState)
async def state():
    return env.state()

@app.get("/health")
async def health():
    return {"status": "ok", "environment": "PII-Scrub-Assistant-v1"}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)