refactor(indentation): Apply codebase-wide 1-space ultra-compact refactor. Formatted 21 core modules and tests.
This commit is contained in:
19
gui_2.py
19
gui_2.py
@@ -102,6 +102,7 @@ class ConfirmDialog:
|
||||
self._condition = threading.Condition()
|
||||
self._done = False
|
||||
self._approved = False
|
||||
|
||||
def wait(self) -> tuple[bool, str]:
|
||||
with self._condition:
|
||||
while not self._done:
|
||||
@@ -115,6 +116,7 @@ class MMAApprovalDialog:
|
||||
self._condition = threading.Condition()
|
||||
self._done = False
|
||||
self._approved = False
|
||||
|
||||
def wait(self) -> tuple[bool, str]:
|
||||
with self._condition:
|
||||
while not self._done:
|
||||
@@ -131,6 +133,7 @@ class MMASpawnApprovalDialog:
|
||||
self._done = False
|
||||
self._approved = False
|
||||
self._abort = False
|
||||
|
||||
def wait(self) -> dict[str, Any]:
|
||||
with self._condition:
|
||||
while not self._done:
|
||||
@@ -293,6 +296,7 @@ class App:
|
||||
|
||||
def _prune_old_logs(self) -> None:
|
||||
"""Asynchronously prunes old insignificant logs on startup."""
|
||||
|
||||
def run_prune() -> None:
|
||||
try:
|
||||
registry = LogRegistry("logs/log_registry.toml")
|
||||
@@ -306,6 +310,7 @@ class App:
|
||||
@property
|
||||
def current_provider(self) -> str:
|
||||
return self._current_provider
|
||||
|
||||
@current_provider.setter
|
||||
def current_provider(self, value: str) -> None:
|
||||
if value != self._current_provider:
|
||||
@@ -325,6 +330,7 @@ class App:
|
||||
@property
|
||||
def current_model(self) -> str:
|
||||
return self._current_model
|
||||
|
||||
@current_model.setter
|
||||
def current_model(self, value: str) -> None:
|
||||
if value != self._current_model:
|
||||
@@ -390,15 +396,18 @@ class App:
|
||||
def create_api(self) -> FastAPI:
|
||||
"""Creates and configures the FastAPI application for headless mode."""
|
||||
api = FastAPI(title="Manual Slop Headless API")
|
||||
|
||||
class GenerateRequest(BaseModel):
|
||||
prompt: str
|
||||
auto_add_history: bool = True
|
||||
temperature: float | None = None
|
||||
max_tokens: int | None = None
|
||||
|
||||
class ConfirmRequest(BaseModel):
|
||||
approved: bool
|
||||
API_KEY_NAME = "X-API-KEY"
|
||||
api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=False)
|
||||
|
||||
async def get_api_key(header_key: str = Depends(api_key_header)) -> str:
|
||||
"""Validates the API key from the request header against configuration."""
|
||||
headless_cfg = self.config.get("headless", {})
|
||||
@@ -410,10 +419,12 @@ class App:
|
||||
if header_key == target_key:
|
||||
return header_key
|
||||
raise HTTPException(status_code=403, detail="Could not validate API Key")
|
||||
|
||||
@api.get("/health")
|
||||
def health() -> dict[str, str]:
|
||||
"""Basic health check endpoint."""
|
||||
return {"status": "ok"}
|
||||
|
||||
@api.get("/status", dependencies=[Depends(get_api_key)])
|
||||
def status() -> dict[str, Any]:
|
||||
"""Returns the current status of the AI provider and active project."""
|
||||
@@ -424,6 +435,7 @@ class App:
|
||||
"ai_status": self.ai_status,
|
||||
"session_usage": self.session_usage
|
||||
}
|
||||
|
||||
@api.get("/api/v1/pending_actions", dependencies=[Depends(get_api_key)])
|
||||
def pending_actions() -> list[dict[str, Any]]:
|
||||
"""Lists all PowerShell scripts awaiting manual confirmation."""
|
||||
@@ -442,6 +454,7 @@ class App:
|
||||
"base_dir": self._pending_dialog._base_dir
|
||||
})
|
||||
return actions
|
||||
|
||||
@api.post("/api/v1/confirm/{action_id}", dependencies=[Depends(get_api_key)])
|
||||
def confirm_action(action_id: str, req: ConfirmRequest) -> dict[str, Any]:
|
||||
"""Approves or denies a pending PowerShell script execution."""
|
||||
@@ -449,6 +462,7 @@ class App:
|
||||
if not success:
|
||||
raise HTTPException(status_code=404, detail=f"Action ID {action_id} not found")
|
||||
return {"status": "success", "action_id": action_id, "approved": req.approved}
|
||||
|
||||
@api.get("/api/v1/sessions", dependencies=[Depends(get_api_key)])
|
||||
def list_sessions() -> list[str]:
|
||||
"""Lists all available session log files."""
|
||||
@@ -456,6 +470,7 @@ class App:
|
||||
if not log_dir.exists():
|
||||
return []
|
||||
return sorted([f.name for f in log_dir.glob("*.log")], reverse=True)
|
||||
|
||||
@api.get("/api/v1/sessions/{filename}", dependencies=[Depends(get_api_key)])
|
||||
def get_session(filename: str) -> dict[str, str]:
|
||||
"""Retrieves the content of a specific session log file."""
|
||||
@@ -469,6 +484,7 @@ class App:
|
||||
return {"filename": filename, "content": content}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@api.delete("/api/v1/sessions/{filename}", dependencies=[Depends(get_api_key)])
|
||||
def delete_session(filename: str) -> dict[str, str]:
|
||||
"""Deletes a specific session log file."""
|
||||
@@ -482,6 +498,7 @@ class App:
|
||||
return {"status": "success", "message": f"Deleted {filename}"}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@api.get("/api/v1/context", dependencies=[Depends(get_api_key)])
|
||||
def get_context() -> dict[str, Any]:
|
||||
"""Returns the current file and screenshot context configuration."""
|
||||
@@ -491,6 +508,7 @@ class App:
|
||||
"files_base_dir": self.ui_files_base_dir,
|
||||
"screenshots_base_dir": self.ui_shots_base_dir
|
||||
}
|
||||
|
||||
@api.post("/api/v1/generate", dependencies=[Depends(get_api_key)])
|
||||
def generate(req: GenerateRequest) -> dict[str, Any]:
|
||||
"""Triggers an AI generation request using the current project context."""
|
||||
@@ -547,6 +565,7 @@ class App:
|
||||
raise HTTPException(status_code=502, detail=f"AI Provider Error: {e.ui_message()}")
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"In-flight AI request failure: {e}")
|
||||
|
||||
@api.post("/api/v1/stream", dependencies=[Depends(get_api_key)])
|
||||
async def stream(req: GenerateRequest) -> Any:
|
||||
"""Placeholder for streaming AI generation responses (Not yet implemented)."""
|
||||
|
||||
Reference in New Issue
Block a user