"""Shared helpers for the admin API package. These helpers are used by 2+ admin sub-modules and must not live in __init__.py to avoid circular imports (T-08-04-04, RESEARCH.md Pitfall 2). _ai_config_to_dict lives in ai.py (only ai.py uses it — local is correct). """ from __future__ import annotations from db.models import User def _user_to_dict(user: User) -> dict: """Return a safe subset of User fields — never includes password_hash, credentials_enc, totp_secret, or any document content (T-02-27, SEC-07). """ return { "id": str(user.id), "handle": user.handle, "email": user.email, "role": user.role, "is_active": user.is_active, "totp_enabled": user.totp_enabled, "ai_provider": user.ai_provider, "ai_model": user.ai_model, "password_must_change": user.password_must_change, "created_at": user.created_at.isoformat() if user.created_at else None, }