feat: implement user activity stream and multiple API improvements

Activity Stream:
- Add UserActivity model with ActivityType enum to track user actions
- Create activity logging service with fire-and-forget pattern
- Add /api/user/activity endpoint with cursor pagination
- Add cleanup cron job for 90-day activity retention
- Integrate activity logging into 18 mutation API routes
- Add DashboardActivityStream component with virtualized rendering

API Improvements:
- Add distributed rate limiting via Vercel KV (with in-memory fallback)
- Add rate limiting to chat endpoint (30 req/min)
- Optimize BM25 search with database-level pre-filtering
- Fix JSON parse crash in search endpoint
- Add pagination to collection tools response (toolsLimit/toolsOffset)
- Add take limits to agent detail query to prevent excessive data fetch
- Fix hardcoded tool count calculation in agents dashboard

Schema Extraction:
- Add schemaExtractionAttemptAt and schemaExtractionError fields
- Separate rate limiting for failed (1 min) vs successful (1 hour) attempts
- Allow retry of failed extractions

Standardization:
- Create api-response.ts with standardized response helpers
- Add apiSuccess, apiError, apiNotFound, apiForbidden, etc.
- Update agents routes to use standardized format

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ajax Davis 2026-01-08 04:11:01 +10:00
parent 1b0cff7332
commit e1bbd80f9b
26 changed files with 1448 additions and 146 deletions

View file

@ -56,6 +56,10 @@
{
"path": "/api/sync/stats-snapshot",
"schedule": "0 0 * * *"
},
{
"path": "/api/sync/cleanup-activity",
"schedule": "0 3 * * *"
}
]
}