Create lib/logger.ts — lightweight wrapper that outputs plain text in dev
and structured JSON in production. Replace 117 console.log/error/warn
calls across 31 files (27 API routes + 4 lib files) with logger.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
pdf-parse v2 depends on @napi-rs/canvas which requires DOMMatrix
(available via process.getBuiltinModule in Node 22+). The build
crashes with "ReferenceError: DOMMatrix is not defined" on Node 18.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Standardize signup route to use jsonSuccess/jsonError helpers, extract
connection status config, clean up StatusBadge/ProviderCard inline maps,
add input validation to knowledge route, fix domain validation.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When a document is processed and has no user-assigned domains, analyze
its text content with the keyword-based domain detector and auto-tag it.
This ensures documents are correctly filtered when professionals search
for relevant context.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Core differentiator: professionals learn about users over time.
- Add user_context table with vector embeddings (migration 011)
- Add get_relevant_context() SQL function for semantic search
- Create lib/context/ module:
- store.ts: save and retrieve user context entries
- extractor.ts: LLM-based fact extraction from conversations
- domain-detector.ts: keyword-based domain classification
- Integrate into professional-chat route:
- Retrieve relevant user context and inject into system prompt
- Async extraction of facts after each conversation turn
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
In-memory rate limiting (LRU cache + Map) doesn't work correctly in
serverless — each function instance has its own memory. Replace with
a Supabase PostgreSQL function that atomically checks and increments
per key, shared across all instances.
- Add rate_limits table + check_rate_limit SQL function (migration 010)
- Rewrite lib/rate-limit.ts to call Supabase RPC instead of LRU cache
- Simplify lib/middleware/rate-limit.ts to wrap the new checkRateLimit
- Update all 7 routes using the old LRU-based limiter
- Remove lru-cache and @types/lru-cache dependencies
- Auth routes (5) unchanged — they already use the middleware wrapper
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replaced imports in lib/api-utils.ts (-> ./supabase-server) and
app/auth/callback/page.tsx (-> @/lib/supabase) with existing local
wrappers. Removed the deprecated package from dependencies.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Created lib/hooks/useLocalStorage.ts with SSR-safe boolean persistence.
Updated ChatAuthCTA and OnboardingChecklist to use it instead of raw
localStorage calls.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Created lib/config/env.ts as SSOT for all env vars with Zod schemas
(client + server split). Updated supabase.ts, supabase-server.ts, and
llm-client.ts to use getClientEnv()/getServerEnv() instead of raw
process.env access. Missing required vars now fail with clear messages.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Added welcomeMessage field to Professional interface and each professional
entry in data/professionals.ts. Removed 6-case switch in ProfessionalDemo.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Added 9 new mapping exports to lib/config/colors.ts (button, focus-ring,
checkbox, starter, message, dropzone, progress, context-panel, hero,
template-hover). Removed local accentColorClasses definitions from all
8 consumer components.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The professional-chat route queried .in('category', ...) but the
documents table has 'domains TEXT[]' (added in migration 009), not
'category'. Changed to .overlaps('domains', ...) for correct array
overlap matching. Updated Document interface to use domains[] field.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove duplicate ApiResponse, apiSuccess, apiError, withErrorHandling,
requireAuth, ERROR_MESSAGES from lib/api-utils.ts — only verifyUser
was actually imported anywhere. Response utils SSOT is lib/api/responses.ts
- Archive 14 historical LEX-era design docs to docs/archive/ — docs/
now has only 9 active reference files (down from 29)
- Remove mock data and placeholder images from Amazon/Ricardo platform
integrations — functions return [] until real APIs are implemented
- Update platform tests to match actual behavior
- Fix README.md: update backend tech (Groq/OpenRouter), add Supabase
to prerequisites
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- APIKeyInput: add focusRing field to ProviderColorClasses, replace
focus:${colors.ring} with static ${colors.focusRing} lookup
- ProfessionalCard: add groupHoverText field to accent color classes,
replace group-hover:${colors.text} with static ${colors.groupHoverText}
- Zero dynamic Tailwind interpolations remain in the codebase
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix dynamic Tailwind classes in ProfessionalDemo.tsx that were purged
at build time by replacing string interpolation with static lookups
- Deduplicate LLM config by importing GROQ/OpenRouter constants from
API_CONFIG instead of defining them locally in llm-client.ts
- Remove duplicate input type interfaces from types/ that duplicated
Zod-inferred types in lib/validations/, re-export from SSOT
- Extract shared navigation config (AUTH_NAV_ITEMS) and icon components
used by both AuthNav and MobileNav into lib/config/navigation.ts
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
TextEncoder/TextDecoder are globally available in modern Node.js.
Fixes build failure due to strict unused directive check.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add Cache-Control header support to API response utilities:
- NONE: no-store for mutations and sensitive data
- PRIVATE_SHORT: 1 minute for user-specific data
- PRIVATE_MEDIUM: 5 minutes for less frequent user data
- PUBLIC_SHORT: 5 minutes for public data
- PUBLIC_MEDIUM: 1 hour for semi-static data
- IMMUTABLE: 1 day for truly static data
Apply caching to key routes:
- GET /api/settings: private, 1 min cache
- GET /api/health: public, 5 min cache
- GET /api/documents: private, 1 min cache
- GET /api/stats: private, 1 min cache
- GET /api/conversations: private, 1 min cache
- All mutations (POST/PUT/DELETE): no-store
- All errors: no-store (automatic)
Expected impact: 2-3x reduction in database queries for
repeated requests within cache window.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive prompt sanitization to prevent LLM prompt injection:
- Create lib/prompt-sanitizer.ts with detection and filtering
- Detect injection patterns (instruction overrides, role manipulation, jailbreaks)
- Escape delimiter sequences that could break prompt structure
- Wrap user-provided context in XML-like tags with data-not-instructions note
- Apply sanitization to all 4 chat API routes:
- /api/quick-chat
- /api/professional-chat
- /api/demo/chat
- /api/demo/document-chat
Security measures:
- Length limits on all user inputs
- Injection pattern detection with filtering
- Control character removal
- Clear separation between instructions and user data
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Port features from legacy codebase:
- Add DocumentCategory type with 7 categories (legal, health, research, etc.)
- Add PROFESSIONAL_DOCUMENT_ACCESS mapping for category-based access
- Add CategoryBadge and CategorySelector components
- Add professional-chat API with document context integration
- Add ErrorBoundary component for error handling
- Add professionals layout with metadata
- Add useRateLimitCountdown hook
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add model visibility and switching UI for AI professionals:
- ModelIndicator: shows current model with icon in chat header
- ModelSelector: dropdown to switch models (auth-gated for guests)
- PrivacyTierInfo: expandable Cloud vs Self-Hosted comparison
- ChatAuthCTA: dismissible guest conversion banner
Config files (SSOT):
- privacy-tiers.ts: tier definitions, model display config
- auth-cta.ts: CTA content for guest/authenticated users
Also increases quick-chat maxTokens from 256 to 1024 to prevent
response cutoff.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces files needed to add a new bot from 7-8 to 3-4 by eliminating
hardcoded bot lists in multiple locations:
- Add `display` field to Bot interface for bots list page metadata
- Footer.tsx: Generate AI Assistants links from bots array
- app/bots/page.tsx: Remove 100-line botDetails Record, derive from bot.display
- menuItems.ts: Generate Professionals menu children from bots array
Adding a new bot now automatically updates the footer, navigation menu,
and bots list page without any additional code changes.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>