fix: normalize unicode escape sequences and reformat multi-line expressions across codebase

This commit is contained in:
2026-06-09 16:48:08 +00:00
parent 66dfda88bc
commit c4f2937415
175 changed files with 12660 additions and 4175 deletions
+64 -15
View File
@@ -12,7 +12,12 @@ from devplacepy.database import get_int_setting
from devplacepy.seo import site_url
from devplacepy.services.manager import service_manager
from devplacepy.templating import templates
from devplacepy.utils import _user_from_api_key, _user_from_session, get_current_user, is_admin
from devplacepy.utils import (
_user_from_api_key,
_user_from_session,
get_current_user,
is_admin,
)
logger = logging.getLogger("devii.router")
@@ -43,7 +48,13 @@ def _resolve_ws_owner(websocket: WebSocket):
if key:
user = _user_from_api_key(key)
if user:
return "user", user["uid"], user.get("username", ""), user.get("api_key", ""), is_admin(user)
return (
"user",
user["uid"],
user.get("username", ""),
user.get("api_key", ""),
is_admin(user),
)
guest_id = websocket.cookies.get(GUEST_COOKIE) or uuid_utils.uuid7().hex
return "guest", guest_id, "guest", "", False
@@ -60,10 +71,23 @@ def _owner_from_request(request: Request):
async def devii_page(request: Request):
user = get_current_user(request)
response = templates.TemplateResponse(
request, "devii.html", {"request": request, "user": user, "page_title": "Devii", "meta_robots": "noindex,nofollow"}
request,
"devii.html",
{
"request": request,
"user": user,
"page_title": "Devii",
"meta_robots": "noindex,nofollow",
},
)
if not user and not request.cookies.get(GUEST_COOKIE):
response.set_cookie(GUEST_COOKIE, uuid_utils.uuid7().hex, httponly=True, samesite="lax", max_age=GUEST_COOKIE_MAX_AGE)
response.set_cookie(
GUEST_COOKIE,
uuid_utils.uuid7().hex,
httponly=True,
samesite="lax",
max_age=GUEST_COOKIE_MAX_AGE,
)
return response
@@ -80,7 +104,13 @@ async def devii_session(request: Request):
}
response = JSONResponse(payload)
if not user and not request.cookies.get(GUEST_COOKIE):
response.set_cookie(GUEST_COOKIE, uuid_utils.uuid7().hex, httponly=True, samesite="lax", max_age=GUEST_COOKIE_MAX_AGE)
response.set_cookie(
GUEST_COOKIE,
uuid_utils.uuid7().hex,
httponly=True,
samesite="lax",
max_age=GUEST_COOKIE_MAX_AGE,
)
return response
@@ -104,7 +134,9 @@ async def devii_adopt(request: Request):
token = session.take_pending_session() if session else None
if token:
max_age = max(1, get_int_setting("session_remember_days", 30)) * 86400
response.set_cookie("session", token, max_age=max_age, httponly=True, samesite="lax")
response.set_cookie(
"session", token, max_age=max_age, httponly=True, samesite="lax"
)
return response
@@ -142,7 +174,9 @@ async def clippy_proxy(request: Request):
async with httpx.AsyncClient(timeout=45.0) as client:
upstream = await client.post(cfg["devii_ai_url"], content=body, headers=headers)
return JSONResponse(
content=upstream.json() if upstream.headers.get("content-type", "").startswith("application/json") else {"raw": upstream.text},
content=upstream.json()
if upstream.headers.get("content-type", "").startswith("application/json")
else {"raw": upstream.text},
status_code=upstream.status_code,
)
@@ -157,14 +191,23 @@ async def devii_ws(websocket: WebSocket):
if not service_manager.owns_lock():
await websocket.close(code=4013)
return
owner_kind, owner_id, username, api_key, owner_is_admin = _resolve_ws_owner(websocket)
owner_kind, owner_id, username, api_key, owner_is_admin = _resolve_ws_owner(
websocket
)
if owner_kind == "guest" and not svc.guests_enabled():
await websocket.send_json({"type": "error", "text": "Guest access to Devii is disabled."})
await websocket.send_json(
{"type": "error", "text": "Guest access to Devii is disabled."}
)
await websocket.close(code=1008)
return
session = svc.hub().get_or_create(
owner_kind, owner_id, username, api_key, svc.instance_base_url(), is_admin=owner_is_admin
owner_kind,
owner_id,
username,
api_key,
svc.instance_base_url(),
is_admin=owner_is_admin,
)
session.attach(websocket)
try:
@@ -179,10 +222,12 @@ async def devii_ws(websocket: WebSocket):
limit = svc.daily_limit_for(owner_kind, owner_is_admin)
spent = svc.spent_24h(owner_kind, owner_id)
if limit > 0 and spent >= limit:
await websocket.send_json({
"type": "error",
"text": "Daily AI quota reached (100%). Try again later.",
})
await websocket.send_json(
{
"type": "error",
"text": "Daily AI quota reached (100%). Try again later.",
}
)
continue
session.spawn_turn(text)
elif kind == "reset":
@@ -190,7 +235,11 @@ async def devii_ws(websocket: WebSocket):
elif kind == "clear":
await session.reset_conversation()
elif kind == "visibility":
session.set_visibility(websocket, bool(data.get("visible", True)), bool(data.get("focused", False)))
session.set_visibility(
websocket,
bool(data.get("visible", True)),
bool(data.get("focused", False)),
)
elif kind in ("avatar_result", "client_result"):
session.resolve_query(str(data.get("id", "")), data.get("result"))
except WebSocketDisconnect: