mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-01-30 14:22:04 +00:00
Python (ruff F401 - unused imports): - Remove unused DEFAULT_YOLO_MODE import from server/routers/settings.py - Remove unused AVAILABLE_MODELS import from server/schemas.py ESLint (missing config for v9): - Add ui/eslint.config.js with flat config format for ESLint v9 - Configure TypeScript, React Hooks, and React Refresh plugins - Fix unnecessary regex escapes in AgentThought.tsx - Remove unused onComplete from useSpecChat.ts dependency array Additional: - Add .claude/commands/check-code.md for local CI verification Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
75 lines
2.0 KiB
Python
75 lines
2.0 KiB
Python
"""
|
|
Settings Router
|
|
===============
|
|
|
|
API endpoints for global settings management.
|
|
Settings are stored in the registry database and shared across all projects.
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from fastapi import APIRouter
|
|
|
|
from ..schemas import ModelInfo, ModelsResponse, SettingsResponse, SettingsUpdate
|
|
|
|
# Add root to path for registry import
|
|
ROOT_DIR = Path(__file__).parent.parent.parent
|
|
if str(ROOT_DIR) not in sys.path:
|
|
sys.path.insert(0, str(ROOT_DIR))
|
|
|
|
from registry import (
|
|
AVAILABLE_MODELS,
|
|
DEFAULT_MODEL,
|
|
get_all_settings,
|
|
set_setting,
|
|
)
|
|
|
|
router = APIRouter(prefix="/api/settings", tags=["settings"])
|
|
|
|
|
|
def _parse_yolo_mode(value: str | None) -> bool:
|
|
"""Parse YOLO mode string to boolean."""
|
|
return (value or "false").lower() == "true"
|
|
|
|
|
|
@router.get("/models", response_model=ModelsResponse)
|
|
async def get_available_models():
|
|
"""Get list of available models.
|
|
|
|
Frontend should call this to get the current list of models
|
|
instead of hardcoding them.
|
|
"""
|
|
return ModelsResponse(
|
|
models=[ModelInfo(id=m["id"], name=m["name"]) for m in AVAILABLE_MODELS],
|
|
default=DEFAULT_MODEL,
|
|
)
|
|
|
|
|
|
@router.get("", response_model=SettingsResponse)
|
|
async def get_settings():
|
|
"""Get current global settings."""
|
|
all_settings = get_all_settings()
|
|
|
|
return SettingsResponse(
|
|
yolo_mode=_parse_yolo_mode(all_settings.get("yolo_mode")),
|
|
model=all_settings.get("model", DEFAULT_MODEL),
|
|
)
|
|
|
|
|
|
@router.patch("", response_model=SettingsResponse)
|
|
async def update_settings(update: SettingsUpdate):
|
|
"""Update global settings."""
|
|
if update.yolo_mode is not None:
|
|
set_setting("yolo_mode", "true" if update.yolo_mode else "false")
|
|
|
|
if update.model is not None:
|
|
set_setting("model", update.model)
|
|
|
|
# Return updated settings
|
|
all_settings = get_all_settings()
|
|
return SettingsResponse(
|
|
yolo_mode=_parse_yolo_mode(all_settings.get("yolo_mode")),
|
|
model=all_settings.get("model", DEFAULT_MODEL),
|
|
)
|