Commit Graph

72 Commits

Author SHA1 Message Date
hailin 925283d8e6 fix(schema): support anonymous users in conversations and user_memories
- Remove foreign key constraint from conversations.user_id
- Remove foreign key constraint from user_memories.user_id
- Add FACT and INTENT to user_memories.memory_type enum
- Both tables now support anonymous users (UUID without registration)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 05:28:59 -08:00
hailin 10a2449d05 fix(conversation): use VARCHAR instead of enum for consistency with init-db.sql
- Change MessageEntity.role from enum to VARCHAR(20)
- Change MessageEntity.type from enum to VARCHAR(30)
- Change ConversationEntity.status from enum to VARCHAR(20)
- Add nullable: true to userId to match database schema
- Add length constraints to match database schema
- Convert enums to const objects with type exports for type safety

This ensures TypeORM entities match the database schema exactly,
avoiding potential issues with enum type creation in production.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 05:06:36 -08:00
hailin 0f56cea96a fix(schema): sync ORM entities with database schema
- Add missing 'type' column to MessageORM entity
- Add 'TEXT_WITH_ATTACHMENTS' to messages.type CHECK constraint
  (matches MessageType enum in conversation-service)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 05:00:38 -08:00
hailin fcffaebdc9 docs: add link to Agent Evaluation Report in README
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 04:56:27 -08:00
hailin 2069a3cf0a fix(evolution): resolve pgvector type conflict in SystemExperienceORM
The embedding column was declared as float[] but the database uses
VECTOR(1536) from pgvector. TypeORM doesn't natively support pgvector
types, causing 500 errors when querying the system_experiences table.

Fixed by:
- Changed column type to 'text' with select: false
- This prevents TypeORM from trying to select/map the vector column
- The embedding field is only used for similarity searches via raw SQL

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 04:46:18 -08:00
hailin 9ae2feff09 fix(db): correct admin password hash in init-db.sql
The previous hash was not working correctly with bcrypt.compare().
Updated to a verified working hash for password 'admin123'.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 04:40:47 -08:00
hailin 8b99021e0e feat(deploy): auto-init database with pgvector support
- Change PostgreSQL image from postgres:15-alpine to pgvector/pgvector:pg15
- Add init_database() function to auto-detect and initialize database
- Add 'db init' command for manual database initialization
- Database init runs automatically on first 'start all' deployment
- Includes admin account creation and pgvector extension verification

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 04:28:51 -08:00
hailin 632e27213a fix(deploy): update start_kong for DB-less mode
Kong is configured to use DB-less mode with declarative config
(kong/kong.yml), so remove the obsolete kong-database and
migrations steps from the deploy script.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 04:10:35 -08:00
hailin d5b751fdf8 chore: add real-time tools API key configs to .env.example
Add optional configuration for:
- GOOGLE_SEARCH_API_KEY + GOOGLE_CSE_ID (for web_search tool)
- EXCHANGE_RATE_API_KEY (optional, v4 API is free without key)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 00:53:37 -08:00
hailin 36ce824db8 docs: add comprehensive agent tools documentation
Document all 10 tools available to the immigration consulting agent:
- 6 knowledge & memory tools (search, off-topic check, assessment, payment, memory, context)
- 4 real-time tools (datetime, web search, exchange rate, news)

Includes input parameters, return formats, implementation details, and configuration.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 00:49:10 -08:00
hailin 4c125f3276 feat(agent): add 4 real-time tools for enhanced agent capabilities
Add the following real-time tools to ImmigrationToolsService:
- get_current_datetime: Get current date/time with timezone support
- web_search: Search internet for latest immigration news/policies (Google CSE)
- get_exchange_rate: Query real-time currency exchange rates (for investment immigration)
- fetch_immigration_news: Fetch latest immigration announcements

All tools include graceful degradation with fallback responses when external APIs are unavailable.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 00:46:55 -08:00
hailin 022b1eb608 docs: add QMAS (优才计划) reference image
添加优才计划相关参考图片

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 23:47:03 -08:00
hailin 911132ab3e feat(agent): upgrade to Level 3 with real RAG, Memory and Evolution integration
## Summary
Upgrade iConsulting from Level 2 (48 points) to Level 3 (68 points) by
implementing real service-to-service integration between conversation-service
and knowledge-service.

## New Files
- knowledge-client.service.ts: HTTP client for knowledge-service APIs
- knowledge.module.ts: NestJS module for KnowledgeClientService
- AGENT_EVALUATION_REPORT.md: Agent capability evaluation report
- LEVEL3_UPGRADE_PLAN.md: Upgrade plan and completion report

## Changes

### RAG Integration
- search_knowledge tool now calls /api/v1/knowledge/retrieve
- check_off_topic tool calls /api/v1/knowledge/check-off-topic
- Results include real vector similarity search from knowledge base

### Memory Integration
- save_user_memory writes to PostgreSQL + Neo4j via knowledge-service
- collect_assessment_info saves user data to long-term memory
- generate_payment records payment intent to user memory
- New get_user_context tool retrieves user's historical memories

### Evolution Integration
- getAccumulatedExperience() fetches approved system experiences
- sendMessage() dynamically injects experiences into system prompt
- System learns from approved experiences across all conversations

## Expected Score Improvement
| Dimension  | Before | After | Delta |
|------------|--------|-------|-------|
| Tool Use   | 14/20  | 18/20 | +4    |
| Memory     | 12/20  | 16/20 | +4    |
| RAG        | 10/20  | 16/20 | +6    |
| Evolution  | 8/20   | 14/20 | +6    |
| Total      | 48     | 68    | +20   |

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 23:45:58 -08:00
hailin 4dbd6f075f docs: reorganize documentation and add architecture document
Changes:
- Create docs/ directory for centralized documentation
- Move DEVELOPMENT_GUIDE.md from root to docs/
- Add comprehensive ARCHITECTURE.md with:
  - System overview and architecture diagrams (ASCII)
  - Microservices responsibilities (6 services)
  - Technology stack details
  - Data flow diagrams (user conversation, admin evolution)
  - Production deployment architecture
  - Kong API routing table
  - Port mapping reference
  - Database schema overview (PostgreSQL, Neo4j, MinIO)
  - Security design notes
- Update README.md with documentation index table

Documentation structure:
  docs/
  ├── ARCHITECTURE.md      - System architecture reference
  └── DEVELOPMENT_GUIDE.md - Development guide and code examples

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 23:05:41 -08:00
hailin e6e69f15ce fix(admin): correct 401 redirect path to include /admin prefix
The API interceptor was redirecting to /login on 401 errors, but since
admin-client is deployed under /admin/, it should redirect to /admin/login.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 07:57:43 -08:00
hailin 731323ad7c fix(admin): add basename to BrowserRouter for /admin/ deployment
The router needs basename="/admin" to work correctly when deployed
under the /admin/ subpath.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 07:50:22 -08:00
hailin cb0b8c6ea9 fix(admin): configure base path for /admin/ deployment
- Add base: '/admin/' to vite.config.ts for proper asset paths
- Replace vite.svg favicon with inline SVG emoji icon
- Fixes 404 errors when accessing admin panel at /admin/ path

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 07:35:52 -08:00
hailin 5ff53b8ba7 fix(chat): align input area elements vertically centered
- Change flex container from items-end to items-center
- Use top-1/2 -translate-y-1/2 for send button vertical centering
- Adjust paperclip button padding for consistent sizing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 06:49:20 -08:00
hailin 3d120e1ce3 fix(chat): hide textarea scrollbar when content fits
- Set overflow-hidden by default on textarea
- Only show scrollbar when content exceeds max height (200px)
- Fix scrollbar appearing on empty input

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 06:44:59 -08:00
hailin 8a39505ee6 feat(chat): add paste and drag-drop file upload support
- Add clipboard paste handler for images and files (Ctrl+V / Cmd+V)
- Add drag-and-drop zone with visual feedback
- Update placeholder text to inform users about new features
- Improve file upload UX with drop overlay

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 06:22:59 -08:00
hailin 2570e4add9 fix(file-service): specify explicit column types for TypeORM entities
Fix DataTypeNotSupportedError by explicitly specifying PostgreSQL column types
for nullable fields that TypeORM was incorrectly inferring as Object type.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 06:05:36 -08:00
hailin d4925719fc feat(multimodal): add file upload and image support for chat
- Add MinIO object storage to docker-compose infrastructure
- Create file-service microservice for upload management with presigned URLs
- Add files table to database schema
- Update nginx and Kong for MinIO proxy routes
- Implement file upload UI in chat InputArea with drag-and-drop
- Add attachment preview in MessageBubble component
- Update conversation-service to handle multimodal messages
- Add Claude Vision API integration for image analysis

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 05:34:41 -08:00
hailin 7adbaaa871 fix(db): use POSTGRES_* env vars in knowledge and evolution services
These services were using DB_HOST, DB_USER etc. but docker-compose
sets POSTGRES_HOST, POSTGRES_USER etc.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 02:57:39 -08:00
hailin c98cae2e39 fix(payment): use PORT env variable instead of PAYMENT_SERVICE_PORT
Payment service was listening on wrong port (3004) because it used
PAYMENT_SERVICE_PORT which wasn't set in docker-compose.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 02:48:44 -08:00
hailin 224e1fb509 fix(health): exclude /health endpoint from API prefix
The health check endpoint should be at /health not /api/v1/health
for Docker health checks to work properly.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 02:30:24 -08:00
hailin 223aa25af1 fix(docker): add health check endpoints and fix IPv6 issue
- Add /health endpoints to all NestJS services (user, payment, knowledge, conversation, evolution)
- Fix nginx healthcheck to use 127.0.0.1 instead of localhost (IPv6 issue)
- Add healthcheck configuration to docker-compose for all backend services
- Use start_period to allow services time to initialize before health checks

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 02:13:42 -08:00
hailin 93050b6889 perf(claude): enable Prompt Caching for ~90% cost savings on system prompt 2026-01-10 01:42:33 -08:00
hailin c914693f94 feat(web): add markdown rendering for AI responses 2026-01-10 01:33:00 -08:00
hailin 0cd667b5c8 fix(websocket): use singleton socket to prevent disconnection on re-render 2026-01-10 01:26:49 -08:00
hailin bd65a431aa fix(websocket): add debug logging for connection issues 2026-01-10 01:24:11 -08:00
hailin d073bd5a9d fix(websocket): configure Socket.IO path for nginx proxy 2026-01-10 01:12:58 -08:00
hailin ab9f479f81 fix(nginx): preserve full path for WebSocket proxy 2026-01-10 01:09:41 -08:00
hailin f8fcf7c74b fix(web): integrate menu toggle into ChatWindow header, remove duplicate headers 2026-01-09 22:09:52 -08:00
hailin 4718d60bff fix(web): sidebar collapsed by default on all devices 2026-01-09 22:07:17 -08:00
hailin f12ca7a821 feat(web): add collapsible sidebar and delete conversation
Frontend:
- Add sidebarOpen state to chatStore with toggle functionality
- Make sidebar collapsible with smooth animation
- Add mobile-friendly drawer behavior with overlay
- Add toggle button for desktop view
- Implement delete conversation functionality with loading state

Backend:
- Add DELETE /conversations/:id endpoint
- Implement deleteConversation service method
- Delete messages before conversation (foreign key constraint)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 21:42:07 -08:00
hailin 72e67fa5d9 fix(conversation): implement proper tool loop for Claude API
- Fix streaming JSON parsing for tool inputs by accumulating partial JSON
  and parsing only on content_block_stop
- Implement proper tool loop to continue conversation after tool execution
- Send tool results back to Claude to get final response
- Add safety limit of 10 iterations for tool loops

This fixes the issue where AI responses were truncated after using tools
like search_knowledge.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 21:29:18 -08:00
hailin 141b45bec2 chore(db): sync init-db.sql with complete postgres schema
Sync scripts/init-db.sql with infrastructure/docker/services/postgres/init.sql
to include all required database columns:
- users: fingerprint, nickname columns for anonymous auth support
- conversations: ended_at column for tracking conversation end time
- messages: type enum column (USER, ASSISTANT, SYSTEM)

This ensures the schema files are consistent and include all columns
needed by the application entities.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 21:15:53 -08:00
hailin 3a675bf3a3 fix(user-service): handle optional fingerprint parameter
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 21:02:44 -08:00
hailin 3efce36f92 fix(user-service): add class-validator decorators to auth DTOs
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 21:01:54 -08:00
hailin f87c089ca2 fix: disable TLS verification for IP-based proxy
When ANTHROPIC_BASE_URL points to an IP address (proxy server),
disable TLS certificate verification to allow connection.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 20:50:15 -08:00
hailin 7f2fc153b5 refactor: simplify Anthropic client config using baseURL
Remove https-proxy-agent dependency since ANTHROPIC_BASE_URL already
supports pointing to a proxy server directly.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 20:45:44 -08:00
hailin a43e0b40e8 fix: use correct type for Anthropic client options
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 20:44:03 -08:00
hailin ea760b5695 chore: update pnpm-lock.yaml for https-proxy-agent
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 20:37:36 -08:00
hailin c6c9623f36 feat(conversation): add proxy support for Anthropic API
- Add https-proxy-agent dependency
- Configure httpAgent in ClaudeAgentService when ANTHROPIC_PROXY_URL is set
- Add ANTHROPIC_PROXY_URL environment variable to docker-compose.yml

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 20:34:13 -08:00
hailin 210e752223 fix(conversation): add class-validator decorators to DTO classes
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 20:20:46 -08:00
hailin f06e6ee76e feat(scripts): add unified deployment management script
Commands:
- start/stop/restart/status - service lifecycle
- logs - view service logs
- build/pull - build and deploy
- health - health check all services
- kong - Kong routes/services/plugins management
- db - PostgreSQL/Redis/Neo4j access and backup
- clean - cleanup images/volumes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 19:45:47 -08:00
hailin e98b0a424f fix(kong): add missing API routes
- payment-service: add /api/v1/orders
- knowledge-service: add /api/v1/memory
- evolution-service: add /api/v1/admin

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 19:39:44 -08:00
hailin 462bd64651 fix(kong,nginx): fix API routing configuration
- nginx: preserve full path when proxying to Kong (remove trailing /)
- nginx: increase API timeout to 120s for AI streaming
- kong: use format_version 2.1 for Kong 3.4 compatibility

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 19:38:32 -08:00
hailin b4a84b76fc refactor(kong): use DB-less mode with declarative config
- Remove kong-database, kong-migrations, kong-init services
- Use KONG_DATABASE=off with declarative config file
- Add kong/kong.yml with all services, routes, and plugins
- Remove kong_data volume (no longer needed)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 19:36:06 -08:00
hailin fd4f23accc refactor: move Kong config to kong/ directory
Organize infrastructure configs properly:
- nginx/ for Nginx configuration
- kong/ for Kong configuration

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 19:34:04 -08:00