Phase 6: PDF & Polish — PDF generation, admin users/settings, AI tool
Backend: - Setting + GeneratedPdf models, Alembic migration with default settings seed - PDF generation service (WeasyPrint + Jinja2 with autoescape) - Health report HTML template with memory entries + document excerpts - Admin user management: list, create, update (role/max_chats/is_active) - Admin settings: self_registration_enabled, default_max_chats - Self-registration check wired into auth register endpoint - default_max_chats applied to new user registrations - AI tool: generate_pdf creates health compilation PDFs - PDF compile/list/download API endpoints - WeasyPrint system deps added to Dockerfile Frontend: - PDF reports page with generate + download - Admin users page with create/edit/activate/deactivate - Admin settings page with self-registration toggle + max chats - Extended sidebar with PDF reports + admin users/settings links - English + Russian translations for all new UI Review fixes applied: - Jinja2 autoescape enabled (XSS prevention in PDFs) - db.refresh after flush (created_at populated correctly) - storage_path removed from API response (no internal path leak) - Role field uses Literal["user", "admin"] validation - React hooks called before conditional returns (rules of hooks) - default_max_chats setting now applied during registration Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -92,6 +92,17 @@ AI_TOOLS = [
|
||||
"required": ["title", "body"],
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "generate_pdf",
|
||||
"description": "Generate a PDF health report compilation from the user's data. Use this when the user asks for a document or summary of their health information.",
|
||||
"input_schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {"type": "string", "description": "Title for the PDF report"},
|
||||
},
|
||||
"required": ["title"],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
@@ -161,6 +172,17 @@ async def _execute_tool(
|
||||
"title": notif.title,
|
||||
})
|
||||
|
||||
elif tool_name == "generate_pdf":
|
||||
from app.services.pdf_service import generate_health_pdf
|
||||
pdf = await generate_health_pdf(db, user_id, title=tool_input["title"])
|
||||
await db.commit()
|
||||
return json.dumps({
|
||||
"status": "generated",
|
||||
"id": str(pdf.id),
|
||||
"title": pdf.title,
|
||||
"download_url": f"/api/v1/pdf/{pdf.id}/download",
|
||||
})
|
||||
|
||||
return json.dumps({"error": f"Unknown tool: {tool_name}"})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user