Skip to content

Current Production 2025-10-19#3

Open
YinChingZ wants to merge 28 commits into
LQ458:mainfrom
YinChingZ:main
Open

Current Production 2025-10-19#3
YinChingZ wants to merge 28 commits into
LQ458:mainfrom
YinChingZ:main

Conversation

@YinChingZ
Copy link
Copy Markdown

Everything up-to-date and working, without a database

This pull request introduces comprehensive documentation and configuration updates to support the production deployment and robust operation of the LawAI application. The changes provide clear setup instructions for environment variables, third-party service integrations (AI, database, OAuth, vector DB), deployment workflows, and troubleshooting. Additionally, the PR summarizes backend feature completion for guest users, outlines recent bug fixes, and details the final deployment status and verification steps.

Environment and Service Configuration

  • Added .env.local.example as a template for all required environment variables, covering MongoDB, NextAuth, ZhipuAI, Baidu AI, Pinecone, Google OAuth, and runtime settings.
  • Created API_SETUP_GUIDE.md with step-by-step instructions for registering, configuring, and integrating ZhipuAI, Baidu AI, Pinecone, MongoDB Atlas, NextAuth, and Google OAuth, including example values and validation checklists.

Deployment Documentation

  • Added DEPLOYMENT.md and DEPLOYMENT_STATUS.md with detailed production deployment steps for Vercel, including environment variable setup, Google OAuth redirect configuration, post-deployment validation, and troubleshooting guidance. [1] [2]

Project Architecture and Technical Guides

  • Introduced copilot-instructions.md outlining LawAI’s architecture, coding conventions, API patterns, business logic flows, recommended development practices, and integration notes for AI and vector DB services.
  • Provided CODESPACE_OAUTH_SETUP.md for configuring Google OAuth in GitHub Codespace environments, including redirect URI management and troubleshooting.

Feature and Bug Fix Summaries

  • Documented backend completion for guest user support in COMPLETION_REPORT.md, detailing new types, session management, API upgrades, data migration, and hooks, as well as next steps for frontend integration and testing.
  • Summarized fixes for AI request failures in AI_REQUEST_FIX_SUMMARY.md, including MongoDB connection optimizations, improved session and user lookup logic, and enhanced request logging for diagnostics.

✅ Core Fixes:
- Fixed TypeScript errors in user model with conditional validation
- Resolved JSON parsing errors in streaming AI responses
- Enhanced MongoDB connection with proper error handling
- Updated OAuth configuration for Codespace/production environments

🛠️ API Improvements:
- Enhanced fetchAi route with comprehensive logging
- Optimized database connections across all API routes
- Fixed user lookup logic in getChats route
- Added proper error handling to all endpoints

📚 Documentation:
- Created comprehensive deployment guides
- Added environment variable examples
- OAuth setup instructions for different environments
- Troubleshooting guides and verification checklists

🔧 Configuration:
- Added Vercel deployment configuration
- Created GitHub workflows
- Updated Next.js config for production
- Enhanced MongoDB adapter for better reliability

All major functionality tested and working:
- Google OAuth authentication ✅
- AI chat with streaming responses ✅
- Vector search and recommendations ✅
- User session management ✅
- Database operations ✅
- Removed builds property from vercel.json
- Kept functions property for API route configuration
- Fixed: The functions property cannot be used in conjunction with the builds property
- Vercel will auto-detect Next.js without explicit builds configuration
✅ Fixed unused variable errors:
- Remove unused 'err' parameter from bookmark/route.ts catch block
- Remove unused 'err' parameter from like/route.ts catch block
- Remove unused 'error' parameters from mongodb.ts catch blocks

✅ Fixed unused imports in recommend/route.ts:
- Removed unused imports: Like, Bookmark, getToken
- Removed unused getRecommendations function
- Removed unused userId parameter

🚀 All TypeScript errors resolved - ready for Vercel build
- Removed unused RecommendationParams interface
- Removed unused RecommendationItem interface
- Final fix for TypeScript build errors
✅ Fixed type definitions:
- Updated IRecord interface to include missing properties (link, date, category, etc.)
- Added missing properties to RecommendationResponse (author, link, publishDate)
- Removed duplicate IRecordWithUserState definition
- Fixed import paths in test files

✅ Fixed component type errors:
- RecommendCard: Added null check for publishDate
- CaseCard: Now has proper link property access
- Test imports: Updated to use correct component paths

🎯 Core production TypeScript errors resolved
@vercel
Copy link
Copy Markdown

vercel Bot commented Oct 19, 2025

@YinChingZ is attempting to deploy a commit to the lq458's projects Team on Vercel.

A member of the Team first needs to authorize it.

@gitguardian
Copy link
Copy Markdown

gitguardian Bot commented Oct 19, 2025

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
- - Pinecone API Key 7bb1dc8 debug-pinecone.js View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@YinChingZ
Copy link
Copy Markdown
Author

Adjustments were required to combine with the depolyment setting of the main repo.

YinChingZ and others added 19 commits October 25, 2025 16:29
- Add pagination to prevent unlimited queries (max 50 records/page)
- Optimize MongoDB connection pool (maxPoolSize: 15, minPoolSize: 5)
- Increase socket timeout (45s -> 60s) for large queries
- Add query timeout protection with maxTimeMS()
- Use lean() for better query performance
- Fix frontend request from limit=9999 to pageSize=50
- Add explicit TLS configuration

Resolves MongoDB TLS alert internal error caused by large query timeouts
The explicit TLS settings (tls: true, tlsAllowInvalidCertificates, etc.)
conflict with MongoDB Atlas auto-configuration. Remove them to restore
database connectivity for all services.
- Remove complex pagination logic (skip, lean, maxTimeMS)
- Use simple limit(100) to prevent overload
- Remove Promise.all and countDocuments
- Simplify frontend request (no pageSize param)

The complex query optimizations were causing issues.
Use simple, proven approach instead.
Key changes:
- Change recommend API to POST (add guest user support)
- Add Like/Bookmark status for both authenticated and guest users
- Import getUserIdentityFromBody and related models
- Keep GET method for backward compatibility
- Update frontend to send POST with guestProfile
- Add useGuest hook integration in recommend page

This aligns recommend API with cases API pattern and fixes
the mismatch between guest user implementation and recommend page.
BREAKING CHANGE: Chat model userId field now uses email (String) instead of ObjectId

Key Changes:
- Update fetchAi API: use user.email when creating/querying chats
- Update getChats API: query chats by user.email
- Update deleteChat API: delete chats by user.email
- Add migration script: scripts/migrate-chat-userid.js
- Add migration guide: DATABASE_REBUILD_GUIDE.md
- Add audit report: DATABASE_FORMAT_AUDIT.md

Benefits:
✅ Guest user chat migration now works correctly
✅ All models now use consistent userId format (email)
✅ Recommendation system can correlate chat behavior
✅ Better data consistency and maintainability

Migration Required:
Run 'node scripts/migrate-chat-userid.js' to convert existing Chat records
from ObjectId format to email format. The script includes:
- Automatic backup before migration
- Detailed logging and statistics
- Data integrity verification
- Rollback support

This fix ensures guest users can see their migrated chats after login,
and resolves the data inconsistency between Chat and other models
(Like, Bookmark, UserProfile) which all use email as userId.
✨ Features:
- Remove forced login dialog on page load
- Add friendly guest mode info card in sidebar
- Allow guest users to use all features immediately
- Add 'Login to sync data' button for optional authentication
- Support guest user in requestAi function with x-guest-id header
- Initialize chat for both guest and authenticated users

🎨 UI/UX:
- Guest mode indicator with info icon
- Dismissable login dialog (only shown when user clicks)
- Clear messaging about local data storage
- Responsive design for mobile and desktop

🔧 Technical:
- Integrate guestId from useAuth hook
- Add guest ID to API request headers
- Update useCallback dependencies
- Maintain 100% backward compatibility with existing login system
✨ Features:
- Remove forced login dialog on page load
- Add friendly guest mode info card in sidebar
- Allow guest users to use all features immediately
- Add 'Login to sync data' button for optional authentication
- Support guest user in requestAi function with x-guest-id header
- Initialize chat for both guest and authenticated users

🎨 UI/UX:
- Guest mode indicator with info icon
- Dismissable login dialog (only shown when user clicks)
- Clear messaging about local data storage
- Responsive design for mobile and desktop

🔧 Technical:
- Integrate guestId from useAuth hook
- Add guest ID to API request headers
- Update useCallback dependencies
- Maintain 100% backward compatibility with existing login system
Co-authored-by: YinChingZ <190606053+YinChingZ@users.noreply.github.com>
Co-authored-by: YinChingZ <190606053+YinChingZ@users.noreply.github.com>
Co-authored-by: YinChingZ <190606053+YinChingZ@users.noreply.github.com>
Co-authored-by: YinChingZ <190606053+YinChingZ@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants