- Replace single-owner rating with per-user ratings stored in agent_ratings collection
- Any authenticated user can now rate any agent; average is computed and stored on agent doc
- Add GET /api/agents/{id}/my-rating endpoint for fetching user's own rating
- Add rating framework info modal showing 1-5 scale definitions and 4 performance areas
- Add "Pencil Agents" discipline with auto-tagging for agents with "pencil" in name
- Run Pencil migration on startup and auto-tag in collector API
- Remove star rating from edit modals (rating is now per-user, not admin-set)
- Add rating_count field to AiAgentResponse and CSV export
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
from motor.motor_asyncio import AsyncIOMotorClient
|
|
from dotenv import load_dotenv
|
|
import os
|
|
|
|
load_dotenv()
|
|
|
|
MONGODB_URI = os.getenv("MONGODB_URI", "mongodb://localhost:27017")
|
|
MONGODB_DBNAME = os.getenv("MONGODB_DBNAME", "agenthub_db")
|
|
|
|
client = AsyncIOMotorClient(MONGODB_URI)
|
|
db = client[MONGODB_DBNAME]
|
|
users_collection = db.get_collection("users")
|
|
agents_collection = db.get_collection("agents")
|
|
agent_usage_collection = db.get_collection("agent_usage")
|
|
notifications_collection = db.get_collection("token_notifications")
|
|
agent_ratings_collection = db.get_collection("agent_ratings")
|
|
|
|
async def ensure_indexes():
|
|
"""Create database indexes for performance"""
|
|
try:
|
|
await agent_ratings_collection.create_index(
|
|
[("agent_id", 1), ("user_id", 1)],
|
|
unique=True
|
|
)
|
|
print("Database indexes ensured successfully")
|
|
except Exception as e:
|
|
print(f"Warning: Failed to create indexes: {e}")
|
|
|
|
async def check_database_health():
|
|
"""Check MongoDB connection health"""
|
|
try:
|
|
# Attempt to ping the database
|
|
await client.admin.command('ping')
|
|
return {"status": "connected", "healthy": True}
|
|
except Exception as e:
|
|
return {"status": "disconnected", "healthy": False, "error": str(e)}
|