Spaces:
Sleeping
Sleeping
github-actions commited on
Commit ·
e8cd1ef
0
Parent(s):
Deploy clean workspace to Hugging Face Spaces
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .dockerignore +10 -0
- .github/workflows/deploy.yml +56 -0
- .gitignore +73 -0
- Calculate_Riasec_Score.py +71 -0
- Dockerfile +44 -0
- QUICK_START_RAG.md +40 -0
- README.md +212 -0
- USER_FLOW.md +553 -0
- WINDOWS_SETUP.md +115 -0
- backend/careers_cleaned.json +0 -0
- backend/package-lock.json +1826 -0
- backend/package.json +40 -0
- backend/prisma/schema.prisma +84 -0
- backend/requirements.txt +21 -0
- backend/src/middleware/auth.ts +65 -0
- backend/src/routes/assessment.ts +725 -0
- backend/src/routes/auth.ts +233 -0
- backend/src/routes/chat.ts +482 -0
- backend/src/routes/home.ts +160 -0
- backend/src/routes/profile.ts +125 -0
- backend/src/server.ts +171 -0
- backend/src/services/gemini.ts +1529 -0
- backend/src/services/ragChat.ts +426 -0
- backend/src/services/rag_service.py +881 -0
- backend/src/services/riasecService.ts +298 -0
- backend/src/types.ts +73 -0
- backend/tsconfig.json +19 -0
- careers_with_riasec_codes.csv +503 -0
- data_processing/career_names.json +504 -0
- data_processing/clean_text.py +48 -0
- data_processing/read_pdf.py +25 -0
- data_processing/split_to_json.py +59 -0
- frontend/index.html +15 -0
- frontend/package-lock.json +0 -0
- frontend/package.json +62 -0
- frontend/src/App.tsx +556 -0
- frontend/src/components/AssessmentHistoryPage.tsx +383 -0
- frontend/src/components/AssessmentResponsesPage.tsx +253 -0
- frontend/src/components/ChatbotPage.tsx +560 -0
- frontend/src/components/HomePage.tsx +321 -0
- frontend/src/components/LanguageSelector.tsx +35 -0
- frontend/src/components/LoginPage.tsx +480 -0
- frontend/src/components/ProcessingPage.tsx +410 -0
- frontend/src/components/SettingsPage.tsx +667 -0
- frontend/src/components/SetupPage.tsx +453 -0
- frontend/src/components/TestFormPage.tsx +0 -0
- frontend/src/components/TestSelectionPage.tsx +340 -0
- frontend/src/components/figma/ImageWithFallback.tsx +27 -0
- frontend/src/components/ui/accordion.tsx +66 -0
- frontend/src/components/ui/alert-dialog.tsx +157 -0
.dockerignore
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
node_modules
|
| 2 |
+
**/node_modules
|
| 3 |
+
backend/venv
|
| 4 |
+
frontend/build
|
| 5 |
+
backend/dist
|
| 6 |
+
.git
|
| 7 |
+
.env
|
| 8 |
+
backend/.env
|
| 9 |
+
frontend/.env
|
| 10 |
+
*.sqlite3-journal
|
.github/workflows/deploy.yml
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Sync to Hugging Face Hub
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches: [main, master]
|
| 6 |
+
workflow_dispatch:
|
| 7 |
+
|
| 8 |
+
jobs:
|
| 9 |
+
sync-to-hub:
|
| 10 |
+
runs-on: ubuntu-latest
|
| 11 |
+
steps:
|
| 12 |
+
- name: Checkout Code
|
| 13 |
+
uses: actions/checkout@v3
|
| 14 |
+
with:
|
| 15 |
+
fetch-depth: 0
|
| 16 |
+
lfs: true
|
| 17 |
+
|
| 18 |
+
- name: Clean and Push to Hugging Face
|
| 19 |
+
env:
|
| 20 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 21 |
+
run: |
|
| 22 |
+
# 1. Delete offending files, documentations, and heavy media
|
| 23 |
+
find . -type f \( -name "*.pptx" -o -name "*.pdf" -o -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" -o -name "*.mp4" -o -name "*.mov" -o -name "*.zip" \) -not -path '*/node_modules/*' -delete
|
| 24 |
+
rm -rf backend/chroma_data_multilingual
|
| 25 |
+
rm -rf backend/chroma_data_full
|
| 26 |
+
|
| 27 |
+
# 2. Add them to .gitignore so they are never tracked in the fresh commit
|
| 28 |
+
echo "backend/chroma_data_multilingual/" >> .gitignore
|
| 29 |
+
echo "backend/chroma_data_full/" >> .gitignore
|
| 30 |
+
echo "*.pptx" >> .gitignore
|
| 31 |
+
echo "*.pdf" >> .gitignore
|
| 32 |
+
echo "*.png" >> .gitignore
|
| 33 |
+
echo "*.jpg" >> .gitignore
|
| 34 |
+
echo "*.jpeg" >> .gitignore
|
| 35 |
+
echo "*.mp4" >> .gitignore
|
| 36 |
+
echo "*.mov" >> .gitignore
|
| 37 |
+
echo "*.zip" >> .gitignore
|
| 38 |
+
|
| 39 |
+
# 3. Find and delete ANY remaining file larger than 9MB (just to be safe)
|
| 40 |
+
find . -type f -size +9M -not -path '*/node_modules/*' -delete
|
| 41 |
+
|
| 42 |
+
# 4. Wipe Git history to get rid of large files in past commits
|
| 43 |
+
rm -rf .git
|
| 44 |
+
|
| 45 |
+
# 5. Re-initialize a clean git repository in the runner
|
| 46 |
+
git init
|
| 47 |
+
git checkout -b main
|
| 48 |
+
git config user.name "github-actions"
|
| 49 |
+
git config user.email "github-actions@github.com"
|
| 50 |
+
|
| 51 |
+
# 6. Commit the clean code files
|
| 52 |
+
git add .
|
| 53 |
+
git commit -m "Deploy clean workspace to Hugging Face Spaces"
|
| 54 |
+
|
| 55 |
+
# 7. Force-push the single clean commit directly to Hugging Face
|
| 56 |
+
git push --force https://NeerjaK:$HF_TOKEN@huggingface.co/spaces/NeerjaK/CareerSetu main:main
|
.gitignore
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Dependencies
|
| 2 |
+
node_modules/
|
| 3 |
+
/.pnp
|
| 4 |
+
.pnp.js
|
| 5 |
+
|
| 6 |
+
# Testing
|
| 7 |
+
/coverage
|
| 8 |
+
|
| 9 |
+
# Production
|
| 10 |
+
/build
|
| 11 |
+
/dist
|
| 12 |
+
|
| 13 |
+
# Environment variables
|
| 14 |
+
.env
|
| 15 |
+
|
| 16 |
+
# Logs
|
| 17 |
+
npm-debug.log*
|
| 18 |
+
yarn-debug.log*
|
| 19 |
+
yarn-error.log*
|
| 20 |
+
lerna-debug.log*
|
| 21 |
+
.pnpm-debug.log*
|
| 22 |
+
|
| 23 |
+
# Database
|
| 24 |
+
*.sqlite
|
| 25 |
+
*.sqlite3
|
| 26 |
+
*.db
|
| 27 |
+
|
| 28 |
+
# IDE
|
| 29 |
+
.vscode/
|
| 30 |
+
.idea/
|
| 31 |
+
*.swp
|
| 32 |
+
*.swo
|
| 33 |
+
*~
|
| 34 |
+
|
| 35 |
+
# OS
|
| 36 |
+
.DS_Store
|
| 37 |
+
Thumbs.db
|
| 38 |
+
|
| 39 |
+
# Prisma
|
| 40 |
+
backend/prisma/migrations/
|
| 41 |
+
|
| 42 |
+
# TypeScript
|
| 43 |
+
*.tsbuildinfo
|
| 44 |
+
|
| 45 |
+
backend/test_unicode.js
|
| 46 |
+
backend/delete_neerja_chat.js
|
| 47 |
+
|
| 48 |
+
# Python
|
| 49 |
+
backend/venv/
|
| 50 |
+
backend/src/services/__pycache__/
|
| 51 |
+
__pycache__/
|
| 52 |
+
*.pyc
|
| 53 |
+
*.pyo
|
| 54 |
+
|
| 55 |
+
# Chroma vector database (unneeded)
|
| 56 |
+
backend/chroma_data_full/
|
| 57 |
+
backend/chroma_data_multilingual/
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
# Test files
|
| 61 |
+
backend/nift.txt
|
| 62 |
+
|
| 63 |
+
*.pptx
|
| 64 |
+
*.pdfbackend/chroma_data_multilingual/
|
| 65 |
+
backend/chroma_data_full/
|
| 66 |
+
*.pptx
|
| 67 |
+
*.pdf
|
| 68 |
+
*.png
|
| 69 |
+
*.jpg
|
| 70 |
+
*.jpeg
|
| 71 |
+
*.mp4
|
| 72 |
+
*.mov
|
| 73 |
+
*.zip
|
Calculate_Riasec_Score.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
|
| 3 |
+
# --- Load your RIASEC question mapping ---
|
| 4 |
+
with open("riasec_mapping.json", "r") as f:
|
| 5 |
+
QUESTIONS = json.load(f)
|
| 6 |
+
|
| 7 |
+
# # --- Configurable weights ---
|
| 8 |
+
# WEIGHT_INTEREST = 1.0
|
| 9 |
+
# WEIGHT_APTITUDE = 1.2
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def score_riasec(responses):
|
| 13 |
+
"""
|
| 14 |
+
responses: list of Likert-scale values (1–5), in same order as QUESTIONS
|
| 15 |
+
returns: dict of normalized RIASEC scores + top code
|
| 16 |
+
"""
|
| 17 |
+
assert len(responses) == len(QUESTIONS), "Response count mismatch"
|
| 18 |
+
|
| 19 |
+
scores = {k: 0.0 for k in "RIASEC"}
|
| 20 |
+
counts = {k: 0 for k in "RIASEC"}
|
| 21 |
+
|
| 22 |
+
for q, score in zip(QUESTIONS, responses):
|
| 23 |
+
t = q["riasec"]
|
| 24 |
+
mult = -1 if q["negative"] else 1
|
| 25 |
+
# w = WEIGHT_APTITUDE if q["dimension"] == "aptitude" else WEIGHT_INTEREST
|
| 26 |
+
scores[t] += mult * score
|
| 27 |
+
counts[t] += 1
|
| 28 |
+
|
| 29 |
+
# Average per RIASEC
|
| 30 |
+
for t in scores:
|
| 31 |
+
scores[t] = scores[t] / counts[t] if counts[t] > 0 else 0
|
| 32 |
+
|
| 33 |
+
# Normalize 0–100
|
| 34 |
+
min_score = min(scores.values())
|
| 35 |
+
max_score = max(scores.values())
|
| 36 |
+
if max_score != min_score:
|
| 37 |
+
for t in scores:
|
| 38 |
+
scores[t] = 100 * (scores[t] - min_score) / (max_score - min_score)
|
| 39 |
+
else:
|
| 40 |
+
for t in scores:
|
| 41 |
+
scores[t] = 50 # fallback if all equal
|
| 42 |
+
|
| 43 |
+
# Sort and label
|
| 44 |
+
sorted_types = sorted(scores.items(), key=lambda x: x[1], reverse=True)
|
| 45 |
+
top_3 = "".join([x[0] for x in sorted_types[:3]])
|
| 46 |
+
|
| 47 |
+
return {
|
| 48 |
+
"scores": scores,
|
| 49 |
+
"top_3": top_3,
|
| 50 |
+
"ordered": sorted_types
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# --- Example ---
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
# Dummy user answers (Likert 1–5)
|
| 57 |
+
user_responses = [
|
| 58 |
+
4, 2, 5, 1, 3, 5, 4, 2, 4, 3,
|
| 59 |
+
2, 5, 3, 5, 5, 4, 4, 5, 2, 2,
|
| 60 |
+
4, 1, 5, 5, 4, 5, 3, 4, 5, 4,
|
| 61 |
+
5, 4, 5
|
| 62 |
+
]
|
| 63 |
+
|
| 64 |
+
result = score_riasec(user_responses)
|
| 65 |
+
print("RIASEC Scores:", result["scores"])
|
| 66 |
+
print("Top 3 Code:", result["top_3"])
|
| 67 |
+
|
| 68 |
+
# find the occurence for each letter in the questions mapping
|
| 69 |
+
for letter in "RIASEC":
|
| 70 |
+
count = sum(1 for q in QUESTIONS if q["riasec"] == letter)
|
| 71 |
+
print(f"Count of {letter} questions: {count}")
|
Dockerfile
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use Node.js base image
|
| 2 |
+
FROM node:20-slim
|
| 3 |
+
|
| 4 |
+
# Install Python and build tools for RAG chatbot
|
| 5 |
+
RUN apt-get update && apt-get install -y \
|
| 6 |
+
python3 \
|
| 7 |
+
python3-pip \
|
| 8 |
+
python3-venv \
|
| 9 |
+
build-essential \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
WORKDIR /app
|
| 13 |
+
|
| 14 |
+
# Copy package configurations
|
| 15 |
+
COPY package*.json ./
|
| 16 |
+
COPY frontend/package*.json ./frontend/
|
| 17 |
+
COPY backend/package*.json ./backend/
|
| 18 |
+
|
| 19 |
+
# Install dependencies for both frontend and backend
|
| 20 |
+
RUN npm install
|
| 21 |
+
RUN cd frontend && npm install
|
| 22 |
+
RUN cd backend && npm install
|
| 23 |
+
|
| 24 |
+
# Copy Python requirements and set up Python venv
|
| 25 |
+
COPY backend/requirements.txt ./backend/
|
| 26 |
+
RUN python3 -m venv backend/venv
|
| 27 |
+
ENV PATH="/app/backend/venv/bin:$PATH"
|
| 28 |
+
RUN pip install --no-cache-dir -r backend/requirements.txt
|
| 29 |
+
|
| 30 |
+
# Copy all source files
|
| 31 |
+
COPY . .
|
| 32 |
+
|
| 33 |
+
# Build frontend static files (outputs to frontend/build)
|
| 34 |
+
RUN cd frontend && npm run build
|
| 35 |
+
|
| 36 |
+
# Generate Prisma Client and Build TypeScript backend
|
| 37 |
+
RUN cd backend && npx prisma generate && npm run build
|
| 38 |
+
|
| 39 |
+
# Expose port (Hugging Face Spaces exposes 7860, Render uses PORT)
|
| 40 |
+
ENV PORT=7860
|
| 41 |
+
EXPOSE 7860
|
| 42 |
+
|
| 43 |
+
# Start Express server from backend
|
| 44 |
+
CMD ["node", "backend/dist/server.js"]
|
QUICK_START_RAG.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Quick Reference - RAG Chatbot Integration
|
| 2 |
+
|
| 3 |
+
## Setup Commands
|
| 4 |
+
|
| 5 |
+
```bash
|
| 6 |
+
# 1. Install Python dependencies
|
| 7 |
+
cd backend
|
| 8 |
+
python -m venv venv # optional use venv
|
| 9 |
+
.\venv\Scripts\activate # for Windows
|
| 10 |
+
pip install -r requirements.txt
|
| 11 |
+
|
| 12 |
+
# 2. Test RAG service
|
| 13 |
+
npm run test:rag
|
| 14 |
+
|
| 15 |
+
# 3. Start backend
|
| 16 |
+
npm run dev
|
| 17 |
+
|
| 18 |
+
# 4. Start frontend (separate terminal)
|
| 19 |
+
cd ../frontend
|
| 20 |
+
npm run dev
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
## Required Environment Variables
|
| 24 |
+
|
| 25 |
+
Add these to `backend/.env`:
|
| 26 |
+
|
| 27 |
+
```env
|
| 28 |
+
RAG_PROVIDER=google
|
| 29 |
+
GOOGLE_API_KEY=your_google_api_key
|
| 30 |
+
HUGGINGFACEHUB_API_TOKEN=your_hf_token
|
| 31 |
+
HF_TOKEN=your_hf_token
|
| 32 |
+
HUGGINGFACE_TOKEN=your_hf_token
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
## Getting API Keys
|
| 36 |
+
|
| 37 |
+
- **Google Gemini**: https://makersuite.google.com/app/apikey
|
| 38 |
+
- **HuggingFace**: https://huggingface.co/settings/tokens
|
| 39 |
+
- **Groq** (optional): https://console.groq.com/
|
| 40 |
+
|
README.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: CareerSetu
|
| 3 |
+
emoji: 🎓
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# Career Guidance Web App
|
| 11 |
+
|
| 12 |
+
A web-based career guidance platform that combines psychometric assessments with AI-powered career recommendations. Students complete RIASEC, values, and preference assessments, after which Google Gemini AI generates personalized career suggestions with clear reasoning. A multilingual RAG chatbot (with built-in guardrails) enables safe, contextual career exploration in six Indian languages. All guidance content is sourced from cleaned and processed NCERT Career Cards. The platform includes dashboards for reviewing assessment history, results, and chat transcripts.
|
| 13 |
+
|
| 14 |
+
## Documentation
|
| 15 |
+
|
| 16 |
+
Each phase of this project has been documented thoroughly.
|
| 17 |
+
|
| 18 |
+
The first phase involved literature and design space review which can be found in [assignment 1 report](https://github.com/ashmitchhoker/assignment_HCI/blob/master/HCI_report1.pdf)
|
| 19 |
+
|
| 20 |
+
The second phase involved building a low fi prototype which was built using Figma. We also made a presentation that included personas and storyboarding, system feedback, sitemap etc. Check our [report](https://github.com/ashmitchhoker/assignment_HCI/blob/master/HCI%20Task%202%20report.pdf) and [presentation](https://github.com/ashmitchhoker/assignment_HCI/blob/master/HCI%20task%202%20ppt%20Group%201.pptx)
|
| 21 |
+
|
| 22 |
+
The third phase involved building a low fi prototype which is the majority of the codebase here. We also conducted user testing and mapped user interaction flow and system architecture shown in our presentation. Check our [report](https://github.com/ashmitchhoker/assignment_HCI/blob/master/HCI%20Task%203%20Report.pdf) and [presentation](https://github.com/ashmitchhoker/assignment_HCI/blob/master/task3_ppt_HCI.pdf)
|
| 23 |
+
|
| 24 |
+
## How to Use
|
| 25 |
+
|
| 26 |
+
1. Setup as instructed
|
| 27 |
+
2. **Start the app** (backend + frontend)
|
| 28 |
+
3. **Login/Register** in the web interface
|
| 29 |
+
4. **Take an assessment** or **Talk to career guide** from the home page
|
| 30 |
+
6. **Ask career questions** - the RAG chatbot will respond with:
|
| 31 |
+
- Accurate information from NCERT sourced career database
|
| 32 |
+
- Context-aware responses based on assessment results
|
| 33 |
+
|
| 34 |
+
## Demo Video
|
| 35 |
+
|
| 36 |
+
<p align="center">
|
| 37 |
+
<a href="https://drive.google.com/file/d/1ITmBoVXgdBZyP-qMDiVIFe9UQ6swHkgh/view?usp=drive_link">
|
| 38 |
+
<img src="Thumbnail.png" alt="User Journey Video" width="600">
|
| 39 |
+
</a>
|
| 40 |
+
</p>
|
| 41 |
+
|
| 42 |
+
<p align="center">
|
| 43 |
+
<a href="https://drive.google.com/file/d/1ITmBoVXgdBZyP-qMDiVIFe9UQ6swHkgh/view?usp=drive_link">
|
| 44 |
+
▶ Watch User Journey Video
|
| 45 |
+
</a>
|
| 46 |
+
</p>
|
| 47 |
+
|
| 48 |
+
## Tech Stack Requirement
|
| 49 |
+
|
| 50 |
+
### Backend
|
| 51 |
+
|
| 52 |
+
- **Node.js** + **Express** + **TypeScript**
|
| 53 |
+
- **Prisma** ORM with **SQLite** database
|
| 54 |
+
- **Google Gemini API** for recommendations and chat
|
| 55 |
+
- **Python RAG Service** with LangChain + ChromaDB for advanced chatbot
|
| 56 |
+
- **HuggingFace Embeddings** for vector db
|
| 57 |
+
|
| 58 |
+
### Frontend
|
| 59 |
+
|
| 60 |
+
- **React** + **TypeScript** + **Vite**
|
| 61 |
+
- **Tailwind CSS** for styling
|
| 62 |
+
- **Radix UI** components
|
| 63 |
+
- **Axios** for API calls
|
| 64 |
+
|
| 65 |
+
## Setup Instructions
|
| 66 |
+
|
| 67 |
+
### Prerequisites
|
| 68 |
+
|
| 69 |
+
- Node.js 18+ and npm
|
| 70 |
+
- Python 3.8+
|
| 71 |
+
|
| 72 |
+
### Backend Setup
|
| 73 |
+
|
| 74 |
+
1. Navigate to backend directory:
|
| 75 |
+
|
| 76 |
+
```bash
|
| 77 |
+
cd backend
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
2. Install Node.js dependencies:
|
| 81 |
+
|
| 82 |
+
```bash
|
| 83 |
+
npm install
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
3. Set up Python virtual environment:
|
| 87 |
+
|
| 88 |
+
**macOS/Linux:**
|
| 89 |
+
```bash
|
| 90 |
+
python3 -m venv venv
|
| 91 |
+
source venv/bin/activate
|
| 92 |
+
pip install -r requirements.txt
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
**Windows (PowerShell):**
|
| 96 |
+
```powershell
|
| 97 |
+
python -m venv venv
|
| 98 |
+
.\venv\Scripts\Activate
|
| 99 |
+
pip install -r requirements.txt
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
5. Add `.env` and add your configuration:
|
| 103 |
+
|
| 104 |
+
```env
|
| 105 |
+
PORT=3000
|
| 106 |
+
NODE_ENV=development
|
| 107 |
+
FRONTEND_URL=http://localhost:5173
|
| 108 |
+
|
| 109 |
+
DATABASE_URL="file:./db.sqlite3"
|
| 110 |
+
|
| 111 |
+
JWT_SECRET=your-secret-key-change-in-production
|
| 112 |
+
JWT_ACCESS_EXPIRES_IN=1h
|
| 113 |
+
JWT_REFRESH_EXPIRES_IN=7d
|
| 114 |
+
|
| 115 |
+
# AI Configuration
|
| 116 |
+
GEMINI_API_KEY=your_gemini_api_key_here
|
| 117 |
+
GOOGLE_API_KEY=your_gemini_api_key_here
|
| 118 |
+
|
| 119 |
+
# RAG Service Configuration
|
| 120 |
+
RAG_PROVIDER=google # Options: 'google' or 'groq'
|
| 121 |
+
HUGGINGFACEHUB_API_TOKEN=your_huggingface_token_here
|
| 122 |
+
HF_TOKEN=your_huggingface_token_here
|
| 123 |
+
HUGGINGFACE_TOKEN=your_huggingface_token_here
|
| 124 |
+
|
| 125 |
+
# Optional: Groq API if using Groq provider
|
| 126 |
+
GROQ_API_KEY=your_groq_api_key_here
|
| 127 |
+
|
| 128 |
+
MAX_RETRY_ATTEMPTS=3
|
| 129 |
+
RETRY_DELAY_MS=1000
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
6. Initialize Prisma and database:
|
| 133 |
+
|
| 134 |
+
```bash
|
| 135 |
+
npx prisma generate
|
| 136 |
+
npx prisma migrate dev --name init
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
7. Start the backend server:
|
| 140 |
+
|
| 141 |
+
```bash
|
| 142 |
+
npm run dev
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
The backend will run on `http://localhost:3000`
|
| 146 |
+
|
| 147 |
+
> **Note**: For detailed RAG setup instructions, see [backend/RAG_SETUP.md](backend/RAG_SETUP.md)
|
| 148 |
+
|
| 149 |
+
### Frontend Setup
|
| 150 |
+
|
| 151 |
+
1. Navigate to frontend directory:
|
| 152 |
+
|
| 153 |
+
```bash
|
| 154 |
+
cd frontend
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
2. Install dependencies:
|
| 158 |
+
|
| 159 |
+
```bash
|
| 160 |
+
npm install
|
| 161 |
+
```
|
| 162 |
+
|
| 163 |
+
3. Create `.env` file (optional, defaults to localhost:3000):
|
| 164 |
+
|
| 165 |
+
```env
|
| 166 |
+
VITE_API_BASE_URL=http://localhost:3000/api
|
| 167 |
+
```
|
| 168 |
+
|
| 169 |
+
4. Start the frontend development server:
|
| 170 |
+
|
| 171 |
+
```bash
|
| 172 |
+
npm run dev
|
| 173 |
+
```
|
| 174 |
+
|
| 175 |
+
The frontend will run on `http://localhost:5173`
|
| 176 |
+
|
| 177 |
+
## Project Structure
|
| 178 |
+
|
| 179 |
+
```
|
| 180 |
+
Final/
|
| 181 |
+
├── backend/
|
| 182 |
+
│ ├── src/
|
| 183 |
+
│ │ ���── routes/
|
| 184 |
+
│ │ │ ├── auth.ts # Authentication routes
|
| 185 |
+
│ │ │ ├── home.ts # Home page data
|
| 186 |
+
│ │ │ ├── assessment.ts # Assessment routes
|
| 187 |
+
│ │ │ ├── chat.ts # Chat routes
|
| 188 |
+
│ │ │ └── profile.ts # Profile management
|
| 189 |
+
│ │ ├── services/
|
| 190 |
+
│ │ │ └── gemini.ts # Gemini AI service
|
| 191 |
+
│ │ ├── middleware/
|
| 192 |
+
│ │ │ └── auth.ts # JWT authentication middleware
|
| 193 |
+
│ │ ├── types.ts # TypeScript types
|
| 194 |
+
│ │ └── server.ts # Express server setup
|
| 195 |
+
│ ├── prisma/
|
| 196 |
+
│ │ └── schema.prisma # Database schema
|
| 197 |
+
│ ├── package.json
|
| 198 |
+
│ └── .env
|
| 199 |
+
│
|
| 200 |
+
└── frontend/
|
| 201 |
+
├── src/
|
| 202 |
+
│ ├── components/ # React components
|
| 203 |
+
│ ├── services/
|
| 204 |
+
│ │ ├── api.ts # Axios client
|
| 205 |
+
│ │ ├── authService.ts # Auth service
|
| 206 |
+
│ │ └── assessmentService.ts # Assessment service
|
| 207 |
+
│ ├── App.tsx # Main app component
|
| 208 |
+
│ └── main.tsx # Entry point
|
| 209 |
+
├── package.json
|
| 210 |
+
└── vite.config.ts
|
| 211 |
+
```
|
| 212 |
+
|
USER_FLOW.md
ADDED
|
@@ -0,0 +1,553 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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+
## High-Level Architecture
|
| 4 |
+
|
| 5 |
+
```mermaid
|
| 6 |
+
graph TB
|
| 7 |
+
User[User] --> Frontend[React Frontend]
|
| 8 |
+
Frontend --> Backend[Node.js Backend]
|
| 9 |
+
Backend --> DB[(SQLite DB)]
|
| 10 |
+
Backend --> Gemini[Google Gemini API]
|
| 11 |
+
Backend --> RAG[Python RAG Service]
|
| 12 |
+
RAG --> ChromaDB[(ChromaDB)]
|
| 13 |
+
RAG --> LLM[Groq/Gemini LLM]
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
## Authentication Flow
|
| 17 |
+
|
| 18 |
+
```mermaid
|
| 19 |
+
stateDiagram-v2
|
| 20 |
+
[*] --> Unauthenticated
|
| 21 |
+
Unauthenticated --> LoginPage: Open App
|
| 22 |
+
LoginPage --> Authenticated: POST /api/auth/login<br/>{email, password}
|
| 23 |
+
LoginPage --> RegisterPage: Click Register
|
| 24 |
+
RegisterPage --> Authenticated: POST /api/auth/register<br/>{email, password, name}
|
| 25 |
+
Authenticated --> HomePage: Redirect
|
| 26 |
+
HomePage --> [*]: Logout
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
## Complete User Journey
|
| 30 |
+
|
| 31 |
+
```mermaid
|
| 32 |
+
flowchart TD
|
| 33 |
+
Start([User Opens App]) --> Auth{Authenticated?}
|
| 34 |
+
Auth -->|No| Login[Login/Register Page]
|
| 35 |
+
Login --> |Success| Home[Home Page]
|
| 36 |
+
Auth -->|Yes| Home
|
| 37 |
+
|
| 38 |
+
Home --> Choice{User Choice}
|
| 39 |
+
|
| 40 |
+
Choice -->|Take Assessment| Assessment[Assessment Flow]
|
| 41 |
+
Choice -->|Talk to Career Guide| FreshChat[Fresh Chat Flow]
|
| 42 |
+
Choice -->|Assessment History| History[History Page]
|
| 43 |
+
|
| 44 |
+
Assessment --> AssessmentDetails[Assessment Sequence]
|
| 45 |
+
History --> HistoryChoice{Select Item}
|
| 46 |
+
HistoryChoice -->|View Results| Results[Assessment Results Page]
|
| 47 |
+
HistoryChoice -->|Open Chat| AssessmentChat[Assessment-Specific Chat Flow]
|
| 48 |
+
|
| 49 |
+
AssessmentDetails --> Home
|
| 50 |
+
FreshChat --> Home
|
| 51 |
+
AssessmentChat --> Home
|
| 52 |
+
Results --> Home
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
## Assessment Flow (Detailed)
|
| 56 |
+
|
| 57 |
+
```mermaid
|
| 58 |
+
sequenceDiagram
|
| 59 |
+
participant U as User
|
| 60 |
+
participant F as Frontend
|
| 61 |
+
participant B as Backend<br/>/api/assessments
|
| 62 |
+
participant G as Gemini Service
|
| 63 |
+
participant R as RAG Service
|
| 64 |
+
participant D as Database
|
| 65 |
+
|
| 66 |
+
U->>F: Click "Take Assessment"
|
| 67 |
+
F->>F: Navigate to TestSelectionPage
|
| 68 |
+
U->>F: Select Assessment Type<br/>(RIASEC/Values/Preferences)
|
| 69 |
+
F->>F: Navigate to TestFormPage
|
| 70 |
+
|
| 71 |
+
loop For Each Question
|
| 72 |
+
F->>U: Display Question
|
| 73 |
+
U->>F: Select Answer
|
| 74 |
+
F->>F: Store answer locally
|
| 75 |
+
end
|
| 76 |
+
|
| 77 |
+
U->>F: Submit Assessment
|
| 78 |
+
F->>F: Navigate to ProcessingPage
|
| 79 |
+
F->>B: POST /api/assessments<br/>{user_id, answers[], type}
|
| 80 |
+
|
| 81 |
+
B->>D: Save Assessment Record
|
| 82 |
+
B->>G: generateRecommendations(answers)
|
| 83 |
+
G->>G: Calculate RIASEC scores
|
| 84 |
+
G-->>B: Return recommendations
|
| 85 |
+
|
| 86 |
+
B->>G: generateGreeting(summary, language)
|
| 87 |
+
G-->>B: Return personalized greeting
|
| 88 |
+
|
| 89 |
+
B->>R: generateInitialGreeting(summary, language)
|
| 90 |
+
R-->>B: Return RAG greeting
|
| 91 |
+
|
| 92 |
+
B->>D: Save assessment_summary<br/>Save initial chat message
|
| 93 |
+
B-->>F: Return {assessment_id, summary, recommendations}
|
| 94 |
+
|
| 95 |
+
F->>F: Navigate to AssessmentResponsesPage
|
| 96 |
+
F->>U: Display Results + Chat Option
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
## Fresh Chat Flow (No Context)
|
| 100 |
+
|
| 101 |
+
```mermaid
|
| 102 |
+
sequenceDiagram
|
| 103 |
+
participant U as User
|
| 104 |
+
participant F as Frontend<br/>ChatbotPage
|
| 105 |
+
participant B as Backend<br/>/api/chat
|
| 106 |
+
participant R as RAG Service<br/>ragChat.ts
|
| 107 |
+
participant P as Python Service<br/>rag_service.py
|
| 108 |
+
participant C as ChromaDB
|
| 109 |
+
|
| 110 |
+
U->>F: Click "Talk to career guide"
|
| 111 |
+
F->>F: navigateTo('chatbot')<br/>setSelectedAssessmentId(undefined)
|
| 112 |
+
F->>F: Clear message history<br/>Show empty chat UI
|
| 113 |
+
|
| 114 |
+
U->>F: Type message in {language}
|
| 115 |
+
U->>F: Click Send
|
| 116 |
+
|
| 117 |
+
F->>B: POST /api/chat<br/>{message, language: 'hi', assessment_id: null}
|
| 118 |
+
|
| 119 |
+
Note over B: assessment_id is null
|
| 120 |
+
B->>B: previousMessages = []<br/>(Empty array)
|
| 121 |
+
|
| 122 |
+
B->>R: chat(message, [], language)
|
| 123 |
+
R->>P: Send command via stdin<br/>{"command":"chat",<br/>"message":"...",<br/>"chat_history":[],<br/>"language":"hi"}
|
| 124 |
+
|
| 125 |
+
P->>C: Retrieve relevant docs<br/>(semantic search)
|
| 126 |
+
C-->>P: Return career documents
|
| 127 |
+
|
| 128 |
+
P->>P: Generate response using<br/>Groq/Gemini with context
|
| 129 |
+
P-->>R: {"status":"success",<br/>"data":{"response":"...",<br/>"sources":[...],"error":null}}
|
| 130 |
+
|
| 131 |
+
R->>R: Check for data.error
|
| 132 |
+
R-->>B: Return response string
|
| 133 |
+
|
| 134 |
+
B->>B: Create ChatMessage record<br/>(user + assistant)
|
| 135 |
+
B-->>F: {reply, sources, timestamp}
|
| 136 |
+
|
| 137 |
+
F->>F: Add messages to UI
|
| 138 |
+
F->>U: Display response in Hindi
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
## Assessment-Specific Chat Flow (With Context)
|
| 142 |
+
|
| 143 |
+
```mermaid
|
| 144 |
+
sequenceDiagram
|
| 145 |
+
participant U as User
|
| 146 |
+
participant F as Frontend
|
| 147 |
+
participant B as Backend<br/>/api/chat
|
| 148 |
+
participant D as Database
|
| 149 |
+
participant R as RAG Service
|
| 150 |
+
|
| 151 |
+
U->>F: Open Assessment from History
|
| 152 |
+
F->>F: setSelectedAssessmentId(assessment_id)
|
| 153 |
+
|
| 154 |
+
F->>B: GET /api/chats?assessmentId={id}
|
| 155 |
+
B->>D: Query last 10 messages<br/>WHERE assessment_id = {id}
|
| 156 |
+
D-->>B: Return messages[]
|
| 157 |
+
B-->>F: Return chat history
|
| 158 |
+
|
| 159 |
+
F->>F: Preload messages in UI
|
| 160 |
+
F->>U: Display previous conversation
|
| 161 |
+
|
| 162 |
+
U->>F: Send new message
|
| 163 |
+
F->>B: POST /api/chat<br/>{message, language, assessment_id: {id}}
|
| 164 |
+
|
| 165 |
+
Note over B: assessment_id exists
|
| 166 |
+
B->>D: Query last 10 messages<br/>WHERE assessment_id = {id}<br/>AND id != userMessage.id
|
| 167 |
+
D-->>B: Return previousMessages[10]
|
| 168 |
+
|
| 169 |
+
B->>R: chat(message, previousMessages, language)
|
| 170 |
+
R-->>B: Return response
|
| 171 |
+
|
| 172 |
+
B->>D: Save user + assistant messages<br/>WITH assessment_id = {id}
|
| 173 |
+
B-->>F: Return {reply, sources, timestamp}
|
| 174 |
+
|
| 175 |
+
F->>U: Display response
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
+
## Language Change Flow
|
| 179 |
+
|
| 180 |
+
```mermaid
|
| 181 |
+
sequenceDiagram
|
| 182 |
+
participant U as User
|
| 183 |
+
participant F as Frontend
|
| 184 |
+
participant B as Backend
|
| 185 |
+
participant R as RAG Service
|
| 186 |
+
|
| 187 |
+
U->>F: Open Chat (any type)
|
| 188 |
+
F->>F: Current language: English
|
| 189 |
+
F->>U: Display chat in English
|
| 190 |
+
|
| 191 |
+
U->>F: Click Language Selector
|
| 192 |
+
U->>F: Select "हिंदी" (Hindi)
|
| 193 |
+
|
| 194 |
+
F->>F: setSelectedLanguage('hi')
|
| 195 |
+
F->>F: Clear displayed messages<br/>(UI reset)
|
| 196 |
+
F->>U: Show empty chat interface
|
| 197 |
+
|
| 198 |
+
Note over F,B: Backend still has old messages<br/>but they won't be displayed
|
| 199 |
+
|
| 200 |
+
U->>F: Send new message in Hindi
|
| 201 |
+
F->>B: POST /api/chat<br/>{message: "...", language: "hi", assessment_id}
|
| 202 |
+
|
| 203 |
+
Note over B: Backend loads previous messages<br/>(may include English messages)
|
| 204 |
+
B->>R: chat(message, previousMessages, "hi")
|
| 205 |
+
|
| 206 |
+
Note over R: RAG processes multilingual context<br/>Responds in requested language
|
| 207 |
+
R-->>B: Response in Hindi
|
| 208 |
+
B-->>F: {reply in Hindi, sources}
|
| 209 |
+
|
| 210 |
+
F->>U: Display Hindi response
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
## Error Handling Flow
|
| 214 |
+
|
| 215 |
+
```mermaid
|
| 216 |
+
sequenceDiagram
|
| 217 |
+
participant U as User
|
| 218 |
+
participant F as Frontend
|
| 219 |
+
participant B as Backend<br/>/api/chat
|
| 220 |
+
participant R as RAG Service
|
| 221 |
+
participant P as Python Service
|
| 222 |
+
|
| 223 |
+
U->>F: Send chat message
|
| 224 |
+
F->>B: POST /api/chat<br/>{message, language, assessment_id}
|
| 225 |
+
|
| 226 |
+
B->>R: chat(message, history, language)
|
| 227 |
+
R->>P: Send command via stdin
|
| 228 |
+
|
| 229 |
+
alt Python Error (e.g., API Key Expired)
|
| 230 |
+
P->>P: Exception in chat()<br/>catch block
|
| 231 |
+
P-->>R: {"status":"success",<br/>"data":{"response":null,<br/>"sources":[],<br/>"error":"API key expired..."}}
|
| 232 |
+
|
| 233 |
+
R->>R: Check response.data.error
|
| 234 |
+
R->>R: throw Error("RAG service error: API key expired...")
|
| 235 |
+
R-->>B: Throw error
|
| 236 |
+
|
| 237 |
+
B->>B: Catch error in route
|
| 238 |
+
B-->>F: 500 {error: "RAG service error: API key expired..."}
|
| 239 |
+
|
| 240 |
+
F->>F: Display error banner
|
| 241 |
+
F->>U: Show error message:<br/>"AI service error. Please contact admin."
|
| 242 |
+
else Success
|
| 243 |
+
P-->>R: {"status":"success",<br/>"data":{"response":"...","error":null}}
|
| 244 |
+
R-->>B: Return response
|
| 245 |
+
B-->>F: 200 {reply, sources}
|
| 246 |
+
F->>U: Display response
|
| 247 |
+
end
|
| 248 |
+
|
| 249 |
+
Note over F,P: Recent Fix: Added error checking<br/>in ragChat.ts to surface Python errors
|
| 250 |
+
```
|
| 251 |
+
|
| 252 |
+
## State Diagram: Chat Context Management
|
| 253 |
+
|
| 254 |
+
```mermaid
|
| 255 |
+
stateDiagram-v2
|
| 256 |
+
[*] --> HomePage
|
| 257 |
+
|
| 258 |
+
HomePage --> FreshChat: Click "Talk to career guide"<br/>assessmentId = undefined
|
| 259 |
+
HomePage --> AssessmentChat: Click chat from history<br/>assessmentId = {id}
|
| 260 |
+
|
| 261 |
+
state FreshChat {
|
| 262 |
+
[*] --> NoContext
|
| 263 |
+
NoContext: previousMessages = []
|
| 264 |
+
NoContext --> SendMessage: User types message
|
| 265 |
+
SendMessage --> NoContext: Response received
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
state AssessmentChat {
|
| 269 |
+
[*] --> LoadContext
|
| 270 |
+
LoadContext: Load last 10 messages<br/>WHERE assessment_id = {id}
|
| 271 |
+
LoadContext --> WithContext
|
| 272 |
+
WithContext: previousMessages = [msg1...msg10]
|
| 273 |
+
WithContext --> SendMessage: User types message
|
| 274 |
+
SendMessage --> WithContext: Response received
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
FreshChat --> HomePage: Navigate back
|
| 278 |
+
AssessmentChat --> HomePage: Navigate back
|
| 279 |
+
|
| 280 |
+
state LanguageChange <<choice>>
|
| 281 |
+
FreshChat --> LanguageChange: User changes language
|
| 282 |
+
AssessmentChat --> LanguageChange: User changes language
|
| 283 |
+
|
| 284 |
+
LanguageChange --> FreshChat: Clear UI messages<br/>Keep same state
|
| 285 |
+
LanguageChange --> AssessmentChat: Clear UI messages<br/>Keep same state
|
| 286 |
+
```
|
| 287 |
+
|
| 288 |
+
## API Endpoints Summary
|
| 289 |
+
|
| 290 |
+
```mermaid
|
| 291 |
+
graph LR
|
| 292 |
+
A[API Endpoints] --> B[Auth]
|
| 293 |
+
A --> C[Assessment]
|
| 294 |
+
A --> D[Chat]
|
| 295 |
+
A --> E[Profile]
|
| 296 |
+
|
| 297 |
+
B --> B1[POST /api/auth/login]
|
| 298 |
+
B --> B2[POST /api/auth/register]
|
| 299 |
+
B --> B3[POST /api/auth/logout]
|
| 300 |
+
|
| 301 |
+
C --> C1[POST /api/assessments]
|
| 302 |
+
C --> C2[GET /api/assessments/:id]
|
| 303 |
+
C --> C3[GET /api/assessments/history]
|
| 304 |
+
|
| 305 |
+
D --> D1[POST /api/chat]
|
| 306 |
+
D --> D2[GET /api/chats?assessmentId=id]
|
| 307 |
+
D --> D3[POST /api/chat/greeting]
|
| 308 |
+
|
| 309 |
+
E --> E1[GET /api/profile]
|
| 310 |
+
E --> E2[PUT /api/profile]
|
| 311 |
+
```
|
| 312 |
+
|
| 313 |
+
## Data Flow: Message Storage
|
| 314 |
+
|
| 315 |
+
```mermaid
|
| 316 |
+
erDiagram
|
| 317 |
+
USER ||--o{ ASSESSMENT : takes
|
| 318 |
+
USER ||--o{ CHAT_MESSAGE : sends
|
| 319 |
+
ASSESSMENT ||--o{ CHAT_MESSAGE : "has context"
|
| 320 |
+
|
| 321 |
+
USER {
|
| 322 |
+
string id PK
|
| 323 |
+
string email
|
| 324 |
+
string name
|
| 325 |
+
datetime created_at
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
ASSESSMENT {
|
| 329 |
+
string id PK
|
| 330 |
+
string user_id FK
|
| 331 |
+
string type
|
| 332 |
+
json answers
|
| 333 |
+
json summary
|
| 334 |
+
datetime created_at
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
CHAT_MESSAGE {
|
| 338 |
+
string id PK
|
| 339 |
+
string user_id FK
|
| 340 |
+
string assessment_id FK "nullable"
|
| 341 |
+
string role "user or assistant"
|
| 342 |
+
string content
|
| 343 |
+
string language
|
| 344 |
+
json sources "nullable"
|
| 345 |
+
datetime created_at
|
| 346 |
+
}
|
| 347 |
+
```
|
| 348 |
+
|
| 349 |
+
## Key Architectural Decisions
|
| 350 |
+
|
| 351 |
+
### Context Isolation Rules
|
| 352 |
+
|
| 353 |
+
| Scenario | assessment_id | previousMessages | Description |
|
| 354 |
+
| --------------- | -------------- | ---------------- | ------------------------------------- |
|
| 355 |
+
| Fresh Chat | `null` | `[]` (empty) | No context passed to RAG |
|
| 356 |
+
| Assessment Chat | `{uuid}` | Last 10 from DB | Filtered by exact assessment_id |
|
| 357 |
+
| Language Change | Same as before | Same as before | Frontend clears UI, backend unchanged |
|
| 358 |
+
|
| 359 |
+
### Error Propagation Chain
|
| 360 |
+
|
| 361 |
+
```mermaid
|
| 362 |
+
flowchart LR
|
| 363 |
+
A[Python Service Error] -->|return data.error| B[ragChat.ts]
|
| 364 |
+
B -->|throw Error| C[chat.ts route]
|
| 365 |
+
C -->|res.status 500| D[Frontend]
|
| 366 |
+
D -->|Show banner| E[User]
|
| 367 |
+
|
| 368 |
+
style A fill:#f9d5d5
|
| 369 |
+
style E fill:#d5f9d5
|
| 370 |
+
```
|
| 371 |
+
|
| 372 |
+
## File-to-Flow Mapping
|
| 373 |
+
|
| 374 |
+
| Flow Step | Frontend File | Backend File | Service File |
|
| 375 |
+
| ----------------- | ---------------------- | ---------------------- | ---------------------------- |
|
| 376 |
+
| Authentication | `LoginPage.tsx` | `routes/auth.ts` | - |
|
| 377 |
+
| Assessment Submit | `TestFormPage.tsx` | `routes/assessment.ts` | `services/gemini.ts` |
|
| 378 |
+
| Fresh Chat | `ChatbotPage.tsx` | `routes/chat.ts` | `services/ragChat.ts` |
|
| 379 |
+
| Assessment Chat | `ChatbotPage.tsx` | `routes/chat.ts` | `services/ragChat.ts` |
|
| 380 |
+
| Language Change | `LanguageSelector.tsx` | - | - |
|
| 381 |
+
| Navigation | `App.tsx` (navigateTo) | - | - |
|
| 382 |
+
| RAG Processing | - | `services/ragChat.ts` | `services/rag_service.py` |
|
| 383 |
+
| Error Handling | All components | All routes | `ragChat.ts` (lines 323-327) |
|
| 384 |
+
|
| 385 |
+
## Technical Implementation Notes
|
| 386 |
+
|
| 387 |
+
### Frontend State Management (`App.tsx`)
|
| 388 |
+
|
| 389 |
+
```typescript
|
| 390 |
+
// Context isolation for fresh chat
|
| 391 |
+
if (page === "chatbot" && assessmentId === undefined) {
|
| 392 |
+
setSelectedAssessmentId(undefined); // Clear for fresh chat
|
| 393 |
+
} else if (assessmentId !== undefined) {
|
| 394 |
+
setSelectedAssessmentId(assessmentId);
|
| 395 |
+
}
|
| 396 |
+
```
|
| 397 |
+
|
| 398 |
+
### Backend Context Filtering (`routes/chat.ts`)
|
| 399 |
+
|
| 400 |
+
```typescript
|
| 401 |
+
// Empty array for fresh chat, last 10 for assessment chat
|
| 402 |
+
const previousMessages = assessment
|
| 403 |
+
? await prisma.chatMessage.findMany({
|
| 404 |
+
where: {
|
| 405 |
+
user_id: userId,
|
| 406 |
+
assessment_id: assessment.id,
|
| 407 |
+
id: { not: userMessage.id },
|
| 408 |
+
},
|
| 409 |
+
orderBy: { created_at: "desc" },
|
| 410 |
+
take: 10,
|
| 411 |
+
})
|
| 412 |
+
: []; // No context for general chat
|
| 413 |
+
```
|
| 414 |
+
|
| 415 |
+
### RAG Service Error Handling (`ragChat.ts`)
|
| 416 |
+
|
| 417 |
+
```typescript
|
| 418 |
+
// Check for Python-level errors first
|
| 419 |
+
if (response.data && response.data.error) {
|
| 420 |
+
throw new Error(`RAG service error: ${response.data.error}`);
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
if (response.data && response.data.response) {
|
| 424 |
+
return response.data.response;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
throw new Error("Invalid chat response from RAG service");
|
| 428 |
+
```
|
| 429 |
+
|
| 430 |
+
### Python Service Response Structure (`rag_service.py`)
|
| 431 |
+
|
| 432 |
+
```python
|
| 433 |
+
# Success case
|
| 434 |
+
return {
|
| 435 |
+
"response": response,
|
| 436 |
+
"sources": sources,
|
| 437 |
+
"error": None
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
# Error case
|
| 441 |
+
return {
|
| 442 |
+
"response": None,
|
| 443 |
+
"sources": [],
|
| 444 |
+
"error": error_msg
|
| 445 |
+
}
|
| 446 |
+
```
|
| 447 |
+
|
| 448 |
+
## Payload Schemas
|
| 449 |
+
|
| 450 |
+
### Chat Request
|
| 451 |
+
|
| 452 |
+
```json
|
| 453 |
+
{
|
| 454 |
+
"message": "string (required)",
|
| 455 |
+
"language": "en|hi|te|ta|bn|gu (required, default: en)",
|
| 456 |
+
"assessment_id": "uuid|null (optional)"
|
| 457 |
+
}
|
| 458 |
+
```
|
| 459 |
+
|
| 460 |
+
### Chat Response (Success)
|
| 461 |
+
|
| 462 |
+
```json
|
| 463 |
+
{
|
| 464 |
+
"reply": "string",
|
| 465 |
+
"sources": [
|
| 466 |
+
{
|
| 467 |
+
"title": "string",
|
| 468 |
+
"chunk_index": 0,
|
| 469 |
+
"snippet": "string (first 250 chars)"
|
| 470 |
+
}
|
| 471 |
+
],
|
| 472 |
+
"timestamp": "2025-11-19T10:30:00.000Z"
|
| 473 |
+
}
|
| 474 |
+
```
|
| 475 |
+
|
| 476 |
+
### Chat Response (Error)
|
| 477 |
+
|
| 478 |
+
```json
|
| 479 |
+
{
|
| 480 |
+
"error": "string (error message)"
|
| 481 |
+
}
|
| 482 |
+
```
|
| 483 |
+
|
| 484 |
+
### Assessment Submission
|
| 485 |
+
|
| 486 |
+
```json
|
| 487 |
+
{
|
| 488 |
+
"type": "riasec|values|preferences",
|
| 489 |
+
"answers": [{ "question_id": "string", "answer": "string" }]
|
| 490 |
+
}
|
| 491 |
+
```
|
| 492 |
+
|
| 493 |
+
### Assessment Response
|
| 494 |
+
|
| 495 |
+
```json
|
| 496 |
+
{
|
| 497 |
+
"assessment_id": "uuid",
|
| 498 |
+
"summary": "string (assessment summary for RAG context)",
|
| 499 |
+
"recommendations": [
|
| 500 |
+
{
|
| 501 |
+
"career_name": "string",
|
| 502 |
+
"match_percentage": 85,
|
| 503 |
+
"reasoning": "string"
|
| 504 |
+
}
|
| 505 |
+
],
|
| 506 |
+
"scores": {
|
| 507 |
+
"RIASEC": {
|
| 508 |
+
"realistic": 7.5,
|
| 509 |
+
"investigative": 8.2,
|
| 510 |
+
...
|
| 511 |
+
}
|
| 512 |
+
}
|
| 513 |
+
}
|
| 514 |
+
```
|
| 515 |
+
|
| 516 |
+
## Environment Configuration
|
| 517 |
+
|
| 518 |
+
### Required Environment Variables
|
| 519 |
+
|
| 520 |
+
```env
|
| 521 |
+
# Backend (.env)
|
| 522 |
+
GEMINI_API_KEY=your_gemini_api_key
|
| 523 |
+
GOOGLE_API_KEY=your_gemini_api_key
|
| 524 |
+
RAG_PROVIDER=google # or 'groq'
|
| 525 |
+
HUGGINGFACEHUB_API_TOKEN=your_hf_token
|
| 526 |
+
GROQ_API_KEY=your_groq_api_key # if using Groq
|
| 527 |
+
JWT_SECRET=your_secret_key
|
| 528 |
+
DATABASE_URL=file:./db.sqlite3
|
| 529 |
+
FRONTEND_URL=http://localhost:5173
|
| 530 |
+
```
|
| 531 |
+
|
| 532 |
+
### Service Initialization
|
| 533 |
+
|
| 534 |
+
```mermaid
|
| 535 |
+
sequenceDiagram
|
| 536 |
+
participant B as Backend Server
|
| 537 |
+
participant R as RAG Service (ragChat.ts)
|
| 538 |
+
participant P as Python Process
|
| 539 |
+
|
| 540 |
+
B->>B: Start Express server
|
| 541 |
+
B->>R: First chat/greeting request
|
| 542 |
+
R->>R: Check if initialized
|
| 543 |
+
R->>P: spawn python rag_service.py
|
| 544 |
+
P->>P: Load environment variables
|
| 545 |
+
P->>P: Initialize embedding model (BGE-M3)
|
| 546 |
+
P->>P: Load ChromaDB (multilingual)
|
| 547 |
+
P->>P: Initialize LLM (Groq/Gemini)
|
| 548 |
+
P-->>R: {"status":"success","message":"initialized"}
|
| 549 |
+
R->>R: Set isInitialized = true
|
| 550 |
+
R-->>B: Ready to process requests
|
| 551 |
+
|
| 552 |
+
Note over R,P: Initialization takes 1-3 minutes<br/>on first run (model download)
|
| 553 |
+
```
|
WINDOWS_SETUP.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Windows Setup Guide
|
| 2 |
+
|
| 3 |
+
Step-by-step instructions to run the Career Guidance Web App on Windows.
|
| 4 |
+
|
| 5 |
+
## Prerequisites
|
| 6 |
+
|
| 7 |
+
1. **Node.js 18+** - Download from [nodejs.org](https://nodejs.org/)
|
| 8 |
+
2. **Python 3.10 or 3.11** - Download from [python.org](https://www.python.org/downloads/)
|
| 9 |
+
> ⚠️ **Important**: Use Python 3.10 or 3.11, NOT 3.12+ (compatibility issues with ML libraries)
|
| 10 |
+
3. **Git** - Download from [git-scm.com](https://git-scm.com/download/win)
|
| 11 |
+
|
| 12 |
+
## Setup Steps
|
| 13 |
+
|
| 14 |
+
### Step 1: Clone the Repository
|
| 15 |
+
|
| 16 |
+
```powershell
|
| 17 |
+
git clone https://github.com/ashmitchhoker/assignment_HCI.git
|
| 18 |
+
cd assignment_HCI
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
### Step 2: Backend Setup
|
| 22 |
+
|
| 23 |
+
Open PowerShell and run:
|
| 24 |
+
|
| 25 |
+
```powershell
|
| 26 |
+
cd backend
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
#### 2.1 Install Node.js dependencies:
|
| 30 |
+
```powershell
|
| 31 |
+
npm install
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
#### 2.2 Create Python virtual environment:
|
| 35 |
+
```powershell
|
| 36 |
+
python -m venv venv
|
| 37 |
+
.\venv\Scripts\Activate
|
| 38 |
+
pip install -r requirements.txt
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
#### 2.3 Create `.env` file:
|
| 42 |
+
|
| 43 |
+
Create a file named `.env` in the `backend` folder with:
|
| 44 |
+
|
| 45 |
+
```env
|
| 46 |
+
PORT=3000
|
| 47 |
+
NODE_ENV=development
|
| 48 |
+
FRONTEND_URL=http://localhost:5173
|
| 49 |
+
|
| 50 |
+
DATABASE_URL="file:./db.sqlite3"
|
| 51 |
+
|
| 52 |
+
JWT_SECRET=your-secret-key-change-in-production
|
| 53 |
+
JWT_ACCESS_EXPIRES_IN=1h
|
| 54 |
+
JWT_REFRESH_EXPIRES_IN=7d
|
| 55 |
+
|
| 56 |
+
# AI Configuration (get from https://aistudio.google.com/apikey)
|
| 57 |
+
GEMINI_API_KEY=your_gemini_api_key_here
|
| 58 |
+
GOOGLE_API_KEY=your_gemini_api_key_here
|
| 59 |
+
|
| 60 |
+
# RAG Service Configuration
|
| 61 |
+
RAG_PROVIDER=google
|
| 62 |
+
|
| 63 |
+
# Optional: Groq API (get from https://console.groq.com/)
|
| 64 |
+
# GROQ_API_KEY=your_groq_api_key_here
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
#### 2.4 Initialize the database:
|
| 68 |
+
```powershell
|
| 69 |
+
npx prisma generate
|
| 70 |
+
npx prisma migrate dev --name init
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
#### 2.5 Start the backend:
|
| 74 |
+
```powershell
|
| 75 |
+
npm run dev
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
> The first run will build the vector database (takes 2-5 minutes).
|
| 79 |
+
|
| 80 |
+
### Step 3: Frontend Setup
|
| 81 |
+
|
| 82 |
+
Open a **new PowerShell window** and run:
|
| 83 |
+
|
| 84 |
+
```powershell
|
| 85 |
+
cd assignment_HCI\frontend
|
| 86 |
+
npm install
|
| 87 |
+
npm run dev
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
### Step 4: Access the App
|
| 91 |
+
|
| 92 |
+
Open your browser and go to: **http://localhost:5173**
|
| 93 |
+
|
| 94 |
+
## Troubleshooting
|
| 95 |
+
|
| 96 |
+
### "python is not recognized"
|
| 97 |
+
- Make sure Python is added to PATH during installation
|
| 98 |
+
- Try using `py` instead of `python`
|
| 99 |
+
|
| 100 |
+
### Port 3000 already in use
|
| 101 |
+
```powershell
|
| 102 |
+
netstat -ano | findstr :3000
|
| 103 |
+
taskkill /PID <PID_NUMBER> /F
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
### Gemini API quota exceeded
|
| 107 |
+
- Get a new API key from [Google AI Studio](https://aistudio.google.com/apikey)
|
| 108 |
+
- Or switch to Groq (free): Set `RAG_PROVIDER=groq` in `.env`
|
| 109 |
+
|
| 110 |
+
### Vector database issues
|
| 111 |
+
Delete and rebuild:
|
| 112 |
+
```powershell
|
| 113 |
+
Remove-Item -Recurse backend\chroma_data_multilingual
|
| 114 |
+
npm run dev # Will rebuild automatically
|
| 115 |
+
```
|
backend/careers_cleaned.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
backend/package-lock.json
ADDED
|
@@ -0,0 +1,1826 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "career-guidance-backend",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"lockfileVersion": 3,
|
| 5 |
+
"requires": true,
|
| 6 |
+
"packages": {
|
| 7 |
+
"": {
|
| 8 |
+
"name": "career-guidance-backend",
|
| 9 |
+
"version": "1.0.0",
|
| 10 |
+
"license": "ISC",
|
| 11 |
+
"dependencies": {
|
| 12 |
+
"@google/generative-ai": "^0.21.0",
|
| 13 |
+
"@prisma/client": "^5.19.0",
|
| 14 |
+
"bcryptjs": "^2.4.3",
|
| 15 |
+
"cors": "^2.8.5",
|
| 16 |
+
"csv-parse": "^6.1.0",
|
| 17 |
+
"dotenv": "^16.4.5",
|
| 18 |
+
"express": "^4.18.2",
|
| 19 |
+
"jsonwebtoken": "^9.0.2"
|
| 20 |
+
},
|
| 21 |
+
"devDependencies": {
|
| 22 |
+
"@types/bcryptjs": "^2.4.6",
|
| 23 |
+
"@types/cors": "^2.8.17",
|
| 24 |
+
"@types/express": "^4.17.21",
|
| 25 |
+
"@types/jsonwebtoken": "^9.0.5",
|
| 26 |
+
"@types/node": "^20.10.0",
|
| 27 |
+
"prisma": "^5.19.0",
|
| 28 |
+
"tsx": "^4.7.0",
|
| 29 |
+
"typescript": "^5.3.3"
|
| 30 |
+
}
|
| 31 |
+
},
|
| 32 |
+
"node_modules/@esbuild/aix-ppc64": {
|
| 33 |
+
"version": "0.25.12",
|
| 34 |
+
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.12.tgz",
|
| 35 |
+
"integrity": "sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA==",
|
| 36 |
+
"cpu": [
|
| 37 |
+
"ppc64"
|
| 38 |
+
],
|
| 39 |
+
"dev": true,
|
| 40 |
+
"license": "MIT",
|
| 41 |
+
"optional": true,
|
| 42 |
+
"os": [
|
| 43 |
+
"aix"
|
| 44 |
+
],
|
| 45 |
+
"engines": {
|
| 46 |
+
"node": ">=18"
|
| 47 |
+
}
|
| 48 |
+
},
|
| 49 |
+
"node_modules/@esbuild/android-arm": {
|
| 50 |
+
"version": "0.25.12",
|
| 51 |
+
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.12.tgz",
|
| 52 |
+
"integrity": "sha512-VJ+sKvNA/GE7Ccacc9Cha7bpS8nyzVv0jdVgwNDaR4gDMC/2TTRc33Ip8qrNYUcpkOHUT5OZ0bUcNNVZQ9RLlg==",
|
| 53 |
+
"cpu": [
|
| 54 |
+
"arm"
|
| 55 |
+
],
|
| 56 |
+
"dev": true,
|
| 57 |
+
"license": "MIT",
|
| 58 |
+
"optional": true,
|
| 59 |
+
"os": [
|
| 60 |
+
"android"
|
| 61 |
+
],
|
| 62 |
+
"engines": {
|
| 63 |
+
"node": ">=18"
|
| 64 |
+
}
|
| 65 |
+
},
|
| 66 |
+
"node_modules/@esbuild/android-arm64": {
|
| 67 |
+
"version": "0.25.12",
|
| 68 |
+
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.12.tgz",
|
| 69 |
+
"integrity": "sha512-6AAmLG7zwD1Z159jCKPvAxZd4y/VTO0VkprYy+3N2FtJ8+BQWFXU+OxARIwA46c5tdD9SsKGZ/1ocqBS/gAKHg==",
|
| 70 |
+
"cpu": [
|
| 71 |
+
"arm64"
|
| 72 |
+
],
|
| 73 |
+
"dev": true,
|
| 74 |
+
"license": "MIT",
|
| 75 |
+
"optional": true,
|
| 76 |
+
"os": [
|
| 77 |
+
"android"
|
| 78 |
+
],
|
| 79 |
+
"engines": {
|
| 80 |
+
"node": ">=18"
|
| 81 |
+
}
|
| 82 |
+
},
|
| 83 |
+
"node_modules/@esbuild/android-x64": {
|
| 84 |
+
"version": "0.25.12",
|
| 85 |
+
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.12.tgz",
|
| 86 |
+
"integrity": "sha512-5jbb+2hhDHx5phYR2By8GTWEzn6I9UqR11Kwf22iKbNpYrsmRB18aX/9ivc5cabcUiAT/wM+YIZ6SG9QO6a8kg==",
|
| 87 |
+
"cpu": [
|
| 88 |
+
"x64"
|
| 89 |
+
],
|
| 90 |
+
"dev": true,
|
| 91 |
+
"license": "MIT",
|
| 92 |
+
"optional": true,
|
| 93 |
+
"os": [
|
| 94 |
+
"android"
|
| 95 |
+
],
|
| 96 |
+
"engines": {
|
| 97 |
+
"node": ">=18"
|
| 98 |
+
}
|
| 99 |
+
},
|
| 100 |
+
"node_modules/@esbuild/darwin-arm64": {
|
| 101 |
+
"version": "0.25.12",
|
| 102 |
+
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.12.tgz",
|
| 103 |
+
"integrity": "sha512-N3zl+lxHCifgIlcMUP5016ESkeQjLj/959RxxNYIthIg+CQHInujFuXeWbWMgnTo4cp5XVHqFPmpyu9J65C1Yg==",
|
| 104 |
+
"cpu": [
|
| 105 |
+
"arm64"
|
| 106 |
+
],
|
| 107 |
+
"dev": true,
|
| 108 |
+
"license": "MIT",
|
| 109 |
+
"optional": true,
|
| 110 |
+
"os": [
|
| 111 |
+
"darwin"
|
| 112 |
+
],
|
| 113 |
+
"engines": {
|
| 114 |
+
"node": ">=18"
|
| 115 |
+
}
|
| 116 |
+
},
|
| 117 |
+
"node_modules/@esbuild/darwin-x64": {
|
| 118 |
+
"version": "0.25.12",
|
| 119 |
+
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.12.tgz",
|
| 120 |
+
"integrity": "sha512-HQ9ka4Kx21qHXwtlTUVbKJOAnmG1ipXhdWTmNXiPzPfWKpXqASVcWdnf2bnL73wgjNrFXAa3yYvBSd9pzfEIpA==",
|
| 121 |
+
"cpu": [
|
| 122 |
+
"x64"
|
| 123 |
+
],
|
| 124 |
+
"dev": true,
|
| 125 |
+
"license": "MIT",
|
| 126 |
+
"optional": true,
|
| 127 |
+
"os": [
|
| 128 |
+
"darwin"
|
| 129 |
+
],
|
| 130 |
+
"engines": {
|
| 131 |
+
"node": ">=18"
|
| 132 |
+
}
|
| 133 |
+
},
|
| 134 |
+
"node_modules/@esbuild/freebsd-arm64": {
|
| 135 |
+
"version": "0.25.12",
|
| 136 |
+
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.12.tgz",
|
| 137 |
+
"integrity": "sha512-gA0Bx759+7Jve03K1S0vkOu5Lg/85dou3EseOGUes8flVOGxbhDDh/iZaoek11Y8mtyKPGF3vP8XhnkDEAmzeg==",
|
| 138 |
+
"cpu": [
|
| 139 |
+
"arm64"
|
| 140 |
+
],
|
| 141 |
+
"dev": true,
|
| 142 |
+
"license": "MIT",
|
| 143 |
+
"optional": true,
|
| 144 |
+
"os": [
|
| 145 |
+
"freebsd"
|
| 146 |
+
],
|
| 147 |
+
"engines": {
|
| 148 |
+
"node": ">=18"
|
| 149 |
+
}
|
| 150 |
+
},
|
| 151 |
+
"node_modules/@esbuild/freebsd-x64": {
|
| 152 |
+
"version": "0.25.12",
|
| 153 |
+
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.12.tgz",
|
| 154 |
+
"integrity": "sha512-TGbO26Yw2xsHzxtbVFGEXBFH0FRAP7gtcPE7P5yP7wGy7cXK2oO7RyOhL5NLiqTlBh47XhmIUXuGciXEqYFfBQ==",
|
| 155 |
+
"cpu": [
|
| 156 |
+
"x64"
|
| 157 |
+
],
|
| 158 |
+
"dev": true,
|
| 159 |
+
"license": "MIT",
|
| 160 |
+
"optional": true,
|
| 161 |
+
"os": [
|
| 162 |
+
"freebsd"
|
| 163 |
+
],
|
| 164 |
+
"engines": {
|
| 165 |
+
"node": ">=18"
|
| 166 |
+
}
|
| 167 |
+
},
|
| 168 |
+
"node_modules/@esbuild/linux-arm": {
|
| 169 |
+
"version": "0.25.12",
|
| 170 |
+
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.12.tgz",
|
| 171 |
+
"integrity": "sha512-lPDGyC1JPDou8kGcywY0YILzWlhhnRjdof3UlcoqYmS9El818LLfJJc3PXXgZHrHCAKs/Z2SeZtDJr5MrkxtOw==",
|
| 172 |
+
"cpu": [
|
| 173 |
+
"arm"
|
| 174 |
+
],
|
| 175 |
+
"dev": true,
|
| 176 |
+
"license": "MIT",
|
| 177 |
+
"optional": true,
|
| 178 |
+
"os": [
|
| 179 |
+
"linux"
|
| 180 |
+
],
|
| 181 |
+
"engines": {
|
| 182 |
+
"node": ">=18"
|
| 183 |
+
}
|
| 184 |
+
},
|
| 185 |
+
"node_modules/@esbuild/linux-arm64": {
|
| 186 |
+
"version": "0.25.12",
|
| 187 |
+
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.12.tgz",
|
| 188 |
+
"integrity": "sha512-8bwX7a8FghIgrupcxb4aUmYDLp8pX06rGh5HqDT7bB+8Rdells6mHvrFHHW2JAOPZUbnjUpKTLg6ECyzvas2AQ==",
|
| 189 |
+
"cpu": [
|
| 190 |
+
"arm64"
|
| 191 |
+
],
|
| 192 |
+
"dev": true,
|
| 193 |
+
"license": "MIT",
|
| 194 |
+
"optional": true,
|
| 195 |
+
"os": [
|
| 196 |
+
"linux"
|
| 197 |
+
],
|
| 198 |
+
"engines": {
|
| 199 |
+
"node": ">=18"
|
| 200 |
+
}
|
| 201 |
+
},
|
| 202 |
+
"node_modules/@esbuild/linux-ia32": {
|
| 203 |
+
"version": "0.25.12",
|
| 204 |
+
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.12.tgz",
|
| 205 |
+
"integrity": "sha512-0y9KrdVnbMM2/vG8KfU0byhUN+EFCny9+8g202gYqSSVMonbsCfLjUO+rCci7pM0WBEtz+oK/PIwHkzxkyharA==",
|
| 206 |
+
"cpu": [
|
| 207 |
+
"ia32"
|
| 208 |
+
],
|
| 209 |
+
"dev": true,
|
| 210 |
+
"license": "MIT",
|
| 211 |
+
"optional": true,
|
| 212 |
+
"os": [
|
| 213 |
+
"linux"
|
| 214 |
+
],
|
| 215 |
+
"engines": {
|
| 216 |
+
"node": ">=18"
|
| 217 |
+
}
|
| 218 |
+
},
|
| 219 |
+
"node_modules/@esbuild/linux-loong64": {
|
| 220 |
+
"version": "0.25.12",
|
| 221 |
+
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.12.tgz",
|
| 222 |
+
"integrity": "sha512-h///Lr5a9rib/v1GGqXVGzjL4TMvVTv+s1DPoxQdz7l/AYv6LDSxdIwzxkrPW438oUXiDtwM10o9PmwS/6Z0Ng==",
|
| 223 |
+
"cpu": [
|
| 224 |
+
"loong64"
|
| 225 |
+
],
|
| 226 |
+
"dev": true,
|
| 227 |
+
"license": "MIT",
|
| 228 |
+
"optional": true,
|
| 229 |
+
"os": [
|
| 230 |
+
"linux"
|
| 231 |
+
],
|
| 232 |
+
"engines": {
|
| 233 |
+
"node": ">=18"
|
| 234 |
+
}
|
| 235 |
+
},
|
| 236 |
+
"node_modules/@esbuild/linux-mips64el": {
|
| 237 |
+
"version": "0.25.12",
|
| 238 |
+
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.12.tgz",
|
| 239 |
+
"integrity": "sha512-iyRrM1Pzy9GFMDLsXn1iHUm18nhKnNMWscjmp4+hpafcZjrr2WbT//d20xaGljXDBYHqRcl8HnxbX6uaA/eGVw==",
|
| 240 |
+
"cpu": [
|
| 241 |
+
"mips64el"
|
| 242 |
+
],
|
| 243 |
+
"dev": true,
|
| 244 |
+
"license": "MIT",
|
| 245 |
+
"optional": true,
|
| 246 |
+
"os": [
|
| 247 |
+
"linux"
|
| 248 |
+
],
|
| 249 |
+
"engines": {
|
| 250 |
+
"node": ">=18"
|
| 251 |
+
}
|
| 252 |
+
},
|
| 253 |
+
"node_modules/@esbuild/linux-ppc64": {
|
| 254 |
+
"version": "0.25.12",
|
| 255 |
+
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.12.tgz",
|
| 256 |
+
"integrity": "sha512-9meM/lRXxMi5PSUqEXRCtVjEZBGwB7P/D4yT8UG/mwIdze2aV4Vo6U5gD3+RsoHXKkHCfSxZKzmDssVlRj1QQA==",
|
| 257 |
+
"cpu": [
|
| 258 |
+
"ppc64"
|
| 259 |
+
],
|
| 260 |
+
"dev": true,
|
| 261 |
+
"license": "MIT",
|
| 262 |
+
"optional": true,
|
| 263 |
+
"os": [
|
| 264 |
+
"linux"
|
| 265 |
+
],
|
| 266 |
+
"engines": {
|
| 267 |
+
"node": ">=18"
|
| 268 |
+
}
|
| 269 |
+
},
|
| 270 |
+
"node_modules/@esbuild/linux-riscv64": {
|
| 271 |
+
"version": "0.25.12",
|
| 272 |
+
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.12.tgz",
|
| 273 |
+
"integrity": "sha512-Zr7KR4hgKUpWAwb1f3o5ygT04MzqVrGEGXGLnj15YQDJErYu/BGg+wmFlIDOdJp0PmB0lLvxFIOXZgFRrdjR0w==",
|
| 274 |
+
"cpu": [
|
| 275 |
+
"riscv64"
|
| 276 |
+
],
|
| 277 |
+
"dev": true,
|
| 278 |
+
"license": "MIT",
|
| 279 |
+
"optional": true,
|
| 280 |
+
"os": [
|
| 281 |
+
"linux"
|
| 282 |
+
],
|
| 283 |
+
"engines": {
|
| 284 |
+
"node": ">=18"
|
| 285 |
+
}
|
| 286 |
+
},
|
| 287 |
+
"node_modules/@esbuild/linux-s390x": {
|
| 288 |
+
"version": "0.25.12",
|
| 289 |
+
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.12.tgz",
|
| 290 |
+
"integrity": "sha512-MsKncOcgTNvdtiISc/jZs/Zf8d0cl/t3gYWX8J9ubBnVOwlk65UIEEvgBORTiljloIWnBzLs4qhzPkJcitIzIg==",
|
| 291 |
+
"cpu": [
|
| 292 |
+
"s390x"
|
| 293 |
+
],
|
| 294 |
+
"dev": true,
|
| 295 |
+
"license": "MIT",
|
| 296 |
+
"optional": true,
|
| 297 |
+
"os": [
|
| 298 |
+
"linux"
|
| 299 |
+
],
|
| 300 |
+
"engines": {
|
| 301 |
+
"node": ">=18"
|
| 302 |
+
}
|
| 303 |
+
},
|
| 304 |
+
"node_modules/@esbuild/linux-x64": {
|
| 305 |
+
"version": "0.25.12",
|
| 306 |
+
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.12.tgz",
|
| 307 |
+
"integrity": "sha512-uqZMTLr/zR/ed4jIGnwSLkaHmPjOjJvnm6TVVitAa08SLS9Z0VM8wIRx7gWbJB5/J54YuIMInDquWyYvQLZkgw==",
|
| 308 |
+
"cpu": [
|
| 309 |
+
"x64"
|
| 310 |
+
],
|
| 311 |
+
"dev": true,
|
| 312 |
+
"license": "MIT",
|
| 313 |
+
"optional": true,
|
| 314 |
+
"os": [
|
| 315 |
+
"linux"
|
| 316 |
+
],
|
| 317 |
+
"engines": {
|
| 318 |
+
"node": ">=18"
|
| 319 |
+
}
|
| 320 |
+
},
|
| 321 |
+
"node_modules/@esbuild/netbsd-arm64": {
|
| 322 |
+
"version": "0.25.12",
|
| 323 |
+
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.12.tgz",
|
| 324 |
+
"integrity": "sha512-xXwcTq4GhRM7J9A8Gv5boanHhRa/Q9KLVmcyXHCTaM4wKfIpWkdXiMog/KsnxzJ0A1+nD+zoecuzqPmCRyBGjg==",
|
| 325 |
+
"cpu": [
|
| 326 |
+
"arm64"
|
| 327 |
+
],
|
| 328 |
+
"dev": true,
|
| 329 |
+
"license": "MIT",
|
| 330 |
+
"optional": true,
|
| 331 |
+
"os": [
|
| 332 |
+
"netbsd"
|
| 333 |
+
],
|
| 334 |
+
"engines": {
|
| 335 |
+
"node": ">=18"
|
| 336 |
+
}
|
| 337 |
+
},
|
| 338 |
+
"node_modules/@esbuild/netbsd-x64": {
|
| 339 |
+
"version": "0.25.12",
|
| 340 |
+
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.12.tgz",
|
| 341 |
+
"integrity": "sha512-Ld5pTlzPy3YwGec4OuHh1aCVCRvOXdH8DgRjfDy/oumVovmuSzWfnSJg+VtakB9Cm0gxNO9BzWkj6mtO1FMXkQ==",
|
| 342 |
+
"cpu": [
|
| 343 |
+
"x64"
|
| 344 |
+
],
|
| 345 |
+
"dev": true,
|
| 346 |
+
"license": "MIT",
|
| 347 |
+
"optional": true,
|
| 348 |
+
"os": [
|
| 349 |
+
"netbsd"
|
| 350 |
+
],
|
| 351 |
+
"engines": {
|
| 352 |
+
"node": ">=18"
|
| 353 |
+
}
|
| 354 |
+
},
|
| 355 |
+
"node_modules/@esbuild/openbsd-arm64": {
|
| 356 |
+
"version": "0.25.12",
|
| 357 |
+
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.12.tgz",
|
| 358 |
+
"integrity": "sha512-fF96T6KsBo/pkQI950FARU9apGNTSlZGsv1jZBAlcLL1MLjLNIWPBkj5NlSz8aAzYKg+eNqknrUJ24QBybeR5A==",
|
| 359 |
+
"cpu": [
|
| 360 |
+
"arm64"
|
| 361 |
+
],
|
| 362 |
+
"dev": true,
|
| 363 |
+
"license": "MIT",
|
| 364 |
+
"optional": true,
|
| 365 |
+
"os": [
|
| 366 |
+
"openbsd"
|
| 367 |
+
],
|
| 368 |
+
"engines": {
|
| 369 |
+
"node": ">=18"
|
| 370 |
+
}
|
| 371 |
+
},
|
| 372 |
+
"node_modules/@esbuild/openbsd-x64": {
|
| 373 |
+
"version": "0.25.12",
|
| 374 |
+
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.12.tgz",
|
| 375 |
+
"integrity": "sha512-MZyXUkZHjQxUvzK7rN8DJ3SRmrVrke8ZyRusHlP+kuwqTcfWLyqMOE3sScPPyeIXN/mDJIfGXvcMqCgYKekoQw==",
|
| 376 |
+
"cpu": [
|
| 377 |
+
"x64"
|
| 378 |
+
],
|
| 379 |
+
"dev": true,
|
| 380 |
+
"license": "MIT",
|
| 381 |
+
"optional": true,
|
| 382 |
+
"os": [
|
| 383 |
+
"openbsd"
|
| 384 |
+
],
|
| 385 |
+
"engines": {
|
| 386 |
+
"node": ">=18"
|
| 387 |
+
}
|
| 388 |
+
},
|
| 389 |
+
"node_modules/@esbuild/openharmony-arm64": {
|
| 390 |
+
"version": "0.25.12",
|
| 391 |
+
"resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.12.tgz",
|
| 392 |
+
"integrity": "sha512-rm0YWsqUSRrjncSXGA7Zv78Nbnw4XL6/dzr20cyrQf7ZmRcsovpcRBdhD43Nuk3y7XIoW2OxMVvwuRvk9XdASg==",
|
| 393 |
+
"cpu": [
|
| 394 |
+
"arm64"
|
| 395 |
+
],
|
| 396 |
+
"dev": true,
|
| 397 |
+
"license": "MIT",
|
| 398 |
+
"optional": true,
|
| 399 |
+
"os": [
|
| 400 |
+
"openharmony"
|
| 401 |
+
],
|
| 402 |
+
"engines": {
|
| 403 |
+
"node": ">=18"
|
| 404 |
+
}
|
| 405 |
+
},
|
| 406 |
+
"node_modules/@esbuild/sunos-x64": {
|
| 407 |
+
"version": "0.25.12",
|
| 408 |
+
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.12.tgz",
|
| 409 |
+
"integrity": "sha512-3wGSCDyuTHQUzt0nV7bocDy72r2lI33QL3gkDNGkod22EsYl04sMf0qLb8luNKTOmgF/eDEDP5BFNwoBKH441w==",
|
| 410 |
+
"cpu": [
|
| 411 |
+
"x64"
|
| 412 |
+
],
|
| 413 |
+
"dev": true,
|
| 414 |
+
"license": "MIT",
|
| 415 |
+
"optional": true,
|
| 416 |
+
"os": [
|
| 417 |
+
"sunos"
|
| 418 |
+
],
|
| 419 |
+
"engines": {
|
| 420 |
+
"node": ">=18"
|
| 421 |
+
}
|
| 422 |
+
},
|
| 423 |
+
"node_modules/@esbuild/win32-arm64": {
|
| 424 |
+
"version": "0.25.12",
|
| 425 |
+
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.12.tgz",
|
| 426 |
+
"integrity": "sha512-rMmLrur64A7+DKlnSuwqUdRKyd3UE7oPJZmnljqEptesKM8wx9J8gx5u0+9Pq0fQQW8vqeKebwNXdfOyP+8Bsg==",
|
| 427 |
+
"cpu": [
|
| 428 |
+
"arm64"
|
| 429 |
+
],
|
| 430 |
+
"dev": true,
|
| 431 |
+
"license": "MIT",
|
| 432 |
+
"optional": true,
|
| 433 |
+
"os": [
|
| 434 |
+
"win32"
|
| 435 |
+
],
|
| 436 |
+
"engines": {
|
| 437 |
+
"node": ">=18"
|
| 438 |
+
}
|
| 439 |
+
},
|
| 440 |
+
"node_modules/@esbuild/win32-ia32": {
|
| 441 |
+
"version": "0.25.12",
|
| 442 |
+
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.12.tgz",
|
| 443 |
+
"integrity": "sha512-HkqnmmBoCbCwxUKKNPBixiWDGCpQGVsrQfJoVGYLPT41XWF8lHuE5N6WhVia2n4o5QK5M4tYr21827fNhi4byQ==",
|
| 444 |
+
"cpu": [
|
| 445 |
+
"ia32"
|
| 446 |
+
],
|
| 447 |
+
"dev": true,
|
| 448 |
+
"license": "MIT",
|
| 449 |
+
"optional": true,
|
| 450 |
+
"os": [
|
| 451 |
+
"win32"
|
| 452 |
+
],
|
| 453 |
+
"engines": {
|
| 454 |
+
"node": ">=18"
|
| 455 |
+
}
|
| 456 |
+
},
|
| 457 |
+
"node_modules/@esbuild/win32-x64": {
|
| 458 |
+
"version": "0.25.12",
|
| 459 |
+
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.12.tgz",
|
| 460 |
+
"integrity": "sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA==",
|
| 461 |
+
"cpu": [
|
| 462 |
+
"x64"
|
| 463 |
+
],
|
| 464 |
+
"dev": true,
|
| 465 |
+
"license": "MIT",
|
| 466 |
+
"optional": true,
|
| 467 |
+
"os": [
|
| 468 |
+
"win32"
|
| 469 |
+
],
|
| 470 |
+
"engines": {
|
| 471 |
+
"node": ">=18"
|
| 472 |
+
}
|
| 473 |
+
},
|
| 474 |
+
"node_modules/@google/generative-ai": {
|
| 475 |
+
"version": "0.21.0",
|
| 476 |
+
"resolved": "https://registry.npmjs.org/@google/generative-ai/-/generative-ai-0.21.0.tgz",
|
| 477 |
+
"integrity": "sha512-7XhUbtnlkSEZK15kN3t+tzIMxsbKm/dSkKBFalj+20NvPKe1kBY7mR2P7vuijEn+f06z5+A8bVGKO0v39cr6Wg==",
|
| 478 |
+
"license": "Apache-2.0",
|
| 479 |
+
"engines": {
|
| 480 |
+
"node": ">=18.0.0"
|
| 481 |
+
}
|
| 482 |
+
},
|
| 483 |
+
"node_modules/@prisma/client": {
|
| 484 |
+
"version": "5.22.0",
|
| 485 |
+
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.22.0.tgz",
|
| 486 |
+
"integrity": "sha512-M0SVXfyHnQREBKxCgyo7sffrKttwE6R8PMq330MIUF0pTwjUhLbW84pFDlf06B27XyCR++VtjugEnIHdr07SVA==",
|
| 487 |
+
"hasInstallScript": true,
|
| 488 |
+
"license": "Apache-2.0",
|
| 489 |
+
"engines": {
|
| 490 |
+
"node": ">=16.13"
|
| 491 |
+
},
|
| 492 |
+
"peerDependencies": {
|
| 493 |
+
"prisma": "*"
|
| 494 |
+
},
|
| 495 |
+
"peerDependenciesMeta": {
|
| 496 |
+
"prisma": {
|
| 497 |
+
"optional": true
|
| 498 |
+
}
|
| 499 |
+
}
|
| 500 |
+
},
|
| 501 |
+
"node_modules/@prisma/debug": {
|
| 502 |
+
"version": "5.22.0",
|
| 503 |
+
"resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.22.0.tgz",
|
| 504 |
+
"integrity": "sha512-AUt44v3YJeggO2ZU5BkXI7M4hu9BF2zzH2iF2V5pyXT/lRTyWiElZ7It+bRH1EshoMRxHgpYg4VB6rCM+mG5jQ==",
|
| 505 |
+
"devOptional": true,
|
| 506 |
+
"license": "Apache-2.0"
|
| 507 |
+
},
|
| 508 |
+
"node_modules/@prisma/engines": {
|
| 509 |
+
"version": "5.22.0",
|
| 510 |
+
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.22.0.tgz",
|
| 511 |
+
"integrity": "sha512-UNjfslWhAt06kVL3CjkuYpHAWSO6L4kDCVPegV6itt7nD1kSJavd3vhgAEhjglLJJKEdJ7oIqDJ+yHk6qO8gPA==",
|
| 512 |
+
"devOptional": true,
|
| 513 |
+
"hasInstallScript": true,
|
| 514 |
+
"license": "Apache-2.0",
|
| 515 |
+
"dependencies": {
|
| 516 |
+
"@prisma/debug": "5.22.0",
|
| 517 |
+
"@prisma/engines-version": "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2",
|
| 518 |
+
"@prisma/fetch-engine": "5.22.0",
|
| 519 |
+
"@prisma/get-platform": "5.22.0"
|
| 520 |
+
}
|
| 521 |
+
},
|
| 522 |
+
"node_modules/@prisma/engines-version": {
|
| 523 |
+
"version": "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2",
|
| 524 |
+
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2.tgz",
|
| 525 |
+
"integrity": "sha512-2PTmxFR2yHW/eB3uqWtcgRcgAbG1rwG9ZriSvQw+nnb7c4uCr3RAcGMb6/zfE88SKlC1Nj2ziUvc96Z379mHgQ==",
|
| 526 |
+
"devOptional": true,
|
| 527 |
+
"license": "Apache-2.0"
|
| 528 |
+
},
|
| 529 |
+
"node_modules/@prisma/fetch-engine": {
|
| 530 |
+
"version": "5.22.0",
|
| 531 |
+
"resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.22.0.tgz",
|
| 532 |
+
"integrity": "sha512-bkrD/Mc2fSvkQBV5EpoFcZ87AvOgDxbG99488a5cexp5Ccny+UM6MAe/UFkUC0wLYD9+9befNOqGiIJhhq+HbA==",
|
| 533 |
+
"devOptional": true,
|
| 534 |
+
"license": "Apache-2.0",
|
| 535 |
+
"dependencies": {
|
| 536 |
+
"@prisma/debug": "5.22.0",
|
| 537 |
+
"@prisma/engines-version": "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2",
|
| 538 |
+
"@prisma/get-platform": "5.22.0"
|
| 539 |
+
}
|
| 540 |
+
},
|
| 541 |
+
"node_modules/@prisma/get-platform": {
|
| 542 |
+
"version": "5.22.0",
|
| 543 |
+
"resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.22.0.tgz",
|
| 544 |
+
"integrity": "sha512-pHhpQdr1UPFpt+zFfnPazhulaZYCUqeIcPpJViYoq9R+D/yw4fjE+CtnsnKzPYm0ddUbeXUzjGVGIRVgPDCk4Q==",
|
| 545 |
+
"devOptional": true,
|
| 546 |
+
"license": "Apache-2.0",
|
| 547 |
+
"dependencies": {
|
| 548 |
+
"@prisma/debug": "5.22.0"
|
| 549 |
+
}
|
| 550 |
+
},
|
| 551 |
+
"node_modules/@types/bcryptjs": {
|
| 552 |
+
"version": "2.4.6",
|
| 553 |
+
"resolved": "https://registry.npmjs.org/@types/bcryptjs/-/bcryptjs-2.4.6.tgz",
|
| 554 |
+
"integrity": "sha512-9xlo6R2qDs5uixm0bcIqCeMCE6HiQsIyel9KQySStiyqNl2tnj2mP3DX1Nf56MD6KMenNNlBBsy3LJ7gUEQPXQ==",
|
| 555 |
+
"dev": true,
|
| 556 |
+
"license": "MIT"
|
| 557 |
+
},
|
| 558 |
+
"node_modules/@types/body-parser": {
|
| 559 |
+
"version": "1.19.6",
|
| 560 |
+
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.6.tgz",
|
| 561 |
+
"integrity": "sha512-HLFeCYgz89uk22N5Qg3dvGvsv46B8GLvKKo1zKG4NybA8U2DiEO3w9lqGg29t/tfLRJpJ6iQxnVw4OnB7MoM9g==",
|
| 562 |
+
"dev": true,
|
| 563 |
+
"license": "MIT",
|
| 564 |
+
"dependencies": {
|
| 565 |
+
"@types/connect": "*",
|
| 566 |
+
"@types/node": "*"
|
| 567 |
+
}
|
| 568 |
+
},
|
| 569 |
+
"node_modules/@types/connect": {
|
| 570 |
+
"version": "3.4.38",
|
| 571 |
+
"resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz",
|
| 572 |
+
"integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==",
|
| 573 |
+
"dev": true,
|
| 574 |
+
"license": "MIT",
|
| 575 |
+
"dependencies": {
|
| 576 |
+
"@types/node": "*"
|
| 577 |
+
}
|
| 578 |
+
},
|
| 579 |
+
"node_modules/@types/cors": {
|
| 580 |
+
"version": "2.8.19",
|
| 581 |
+
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.19.tgz",
|
| 582 |
+
"integrity": "sha512-mFNylyeyqN93lfe/9CSxOGREz8cpzAhH+E93xJ4xWQf62V8sQ/24reV2nyzUWM6H6Xji+GGHpkbLe7pVoUEskg==",
|
| 583 |
+
"dev": true,
|
| 584 |
+
"license": "MIT",
|
| 585 |
+
"dependencies": {
|
| 586 |
+
"@types/node": "*"
|
| 587 |
+
}
|
| 588 |
+
},
|
| 589 |
+
"node_modules/@types/express": {
|
| 590 |
+
"version": "4.17.25",
|
| 591 |
+
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.25.tgz",
|
| 592 |
+
"integrity": "sha512-dVd04UKsfpINUnK0yBoYHDF3xu7xVH4BuDotC/xGuycx4CgbP48X/KF/586bcObxT0HENHXEU8Nqtu6NR+eKhw==",
|
| 593 |
+
"dev": true,
|
| 594 |
+
"license": "MIT",
|
| 595 |
+
"dependencies": {
|
| 596 |
+
"@types/body-parser": "*",
|
| 597 |
+
"@types/express-serve-static-core": "^4.17.33",
|
| 598 |
+
"@types/qs": "*",
|
| 599 |
+
"@types/serve-static": "^1"
|
| 600 |
+
}
|
| 601 |
+
},
|
| 602 |
+
"node_modules/@types/express-serve-static-core": {
|
| 603 |
+
"version": "4.19.7",
|
| 604 |
+
"resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.19.7.tgz",
|
| 605 |
+
"integrity": "sha512-FvPtiIf1LfhzsaIXhv/PHan/2FeQBbtBDtfX2QfvPxdUelMDEckK08SM6nqo1MIZY3RUlfA+HV8+hFUSio78qg==",
|
| 606 |
+
"dev": true,
|
| 607 |
+
"license": "MIT",
|
| 608 |
+
"dependencies": {
|
| 609 |
+
"@types/node": "*",
|
| 610 |
+
"@types/qs": "*",
|
| 611 |
+
"@types/range-parser": "*",
|
| 612 |
+
"@types/send": "*"
|
| 613 |
+
}
|
| 614 |
+
},
|
| 615 |
+
"node_modules/@types/http-errors": {
|
| 616 |
+
"version": "2.0.5",
|
| 617 |
+
"resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.5.tgz",
|
| 618 |
+
"integrity": "sha512-r8Tayk8HJnX0FztbZN7oVqGccWgw98T/0neJphO91KkmOzug1KkofZURD4UaD5uH8AqcFLfdPErnBod0u71/qg==",
|
| 619 |
+
"dev": true,
|
| 620 |
+
"license": "MIT"
|
| 621 |
+
},
|
| 622 |
+
"node_modules/@types/jsonwebtoken": {
|
| 623 |
+
"version": "9.0.10",
|
| 624 |
+
"resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.10.tgz",
|
| 625 |
+
"integrity": "sha512-asx5hIG9Qmf/1oStypjanR7iKTv0gXQ1Ov/jfrX6kS/EO0OFni8orbmGCn0672NHR3kXHwpAwR+B368ZGN/2rA==",
|
| 626 |
+
"dev": true,
|
| 627 |
+
"license": "MIT",
|
| 628 |
+
"dependencies": {
|
| 629 |
+
"@types/ms": "*",
|
| 630 |
+
"@types/node": "*"
|
| 631 |
+
}
|
| 632 |
+
},
|
| 633 |
+
"node_modules/@types/mime": {
|
| 634 |
+
"version": "1.3.5",
|
| 635 |
+
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz",
|
| 636 |
+
"integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==",
|
| 637 |
+
"dev": true,
|
| 638 |
+
"license": "MIT"
|
| 639 |
+
},
|
| 640 |
+
"node_modules/@types/ms": {
|
| 641 |
+
"version": "2.1.0",
|
| 642 |
+
"resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz",
|
| 643 |
+
"integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==",
|
| 644 |
+
"dev": true,
|
| 645 |
+
"license": "MIT"
|
| 646 |
+
},
|
| 647 |
+
"node_modules/@types/node": {
|
| 648 |
+
"version": "20.19.25",
|
| 649 |
+
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.25.tgz",
|
| 650 |
+
"integrity": "sha512-ZsJzA5thDQMSQO788d7IocwwQbI8B5OPzmqNvpf3NY/+MHDAS759Wo0gd2WQeXYt5AAAQjzcrTVC6SKCuYgoCQ==",
|
| 651 |
+
"dev": true,
|
| 652 |
+
"license": "MIT",
|
| 653 |
+
"dependencies": {
|
| 654 |
+
"undici-types": "~6.21.0"
|
| 655 |
+
}
|
| 656 |
+
},
|
| 657 |
+
"node_modules/@types/qs": {
|
| 658 |
+
"version": "6.14.0",
|
| 659 |
+
"resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.14.0.tgz",
|
| 660 |
+
"integrity": "sha512-eOunJqu0K1923aExK6y8p6fsihYEn/BYuQ4g0CxAAgFc4b/ZLN4CrsRZ55srTdqoiLzU2B2evC+apEIxprEzkQ==",
|
| 661 |
+
"dev": true,
|
| 662 |
+
"license": "MIT"
|
| 663 |
+
},
|
| 664 |
+
"node_modules/@types/range-parser": {
|
| 665 |
+
"version": "1.2.7",
|
| 666 |
+
"resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz",
|
| 667 |
+
"integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==",
|
| 668 |
+
"dev": true,
|
| 669 |
+
"license": "MIT"
|
| 670 |
+
},
|
| 671 |
+
"node_modules/@types/send": {
|
| 672 |
+
"version": "1.2.1",
|
| 673 |
+
"resolved": "https://registry.npmjs.org/@types/send/-/send-1.2.1.tgz",
|
| 674 |
+
"integrity": "sha512-arsCikDvlU99zl1g69TcAB3mzZPpxgw0UQnaHeC1Nwb015xp8bknZv5rIfri9xTOcMuaVgvabfIRA7PSZVuZIQ==",
|
| 675 |
+
"dev": true,
|
| 676 |
+
"license": "MIT",
|
| 677 |
+
"dependencies": {
|
| 678 |
+
"@types/node": "*"
|
| 679 |
+
}
|
| 680 |
+
},
|
| 681 |
+
"node_modules/@types/serve-static": {
|
| 682 |
+
"version": "1.15.10",
|
| 683 |
+
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.10.tgz",
|
| 684 |
+
"integrity": "sha512-tRs1dB+g8Itk72rlSI2ZrW6vZg0YrLI81iQSTkMmOqnqCaNr/8Ek4VwWcN5vZgCYWbg/JJSGBlUaYGAOP73qBw==",
|
| 685 |
+
"dev": true,
|
| 686 |
+
"license": "MIT",
|
| 687 |
+
"dependencies": {
|
| 688 |
+
"@types/http-errors": "*",
|
| 689 |
+
"@types/node": "*",
|
| 690 |
+
"@types/send": "<1"
|
| 691 |
+
}
|
| 692 |
+
},
|
| 693 |
+
"node_modules/@types/serve-static/node_modules/@types/send": {
|
| 694 |
+
"version": "0.17.6",
|
| 695 |
+
"resolved": "https://registry.npmjs.org/@types/send/-/send-0.17.6.tgz",
|
| 696 |
+
"integrity": "sha512-Uqt8rPBE8SY0RK8JB1EzVOIZ32uqy8HwdxCnoCOsYrvnswqmFZ/k+9Ikidlk/ImhsdvBsloHbAlewb2IEBV/Og==",
|
| 697 |
+
"dev": true,
|
| 698 |
+
"license": "MIT",
|
| 699 |
+
"dependencies": {
|
| 700 |
+
"@types/mime": "^1",
|
| 701 |
+
"@types/node": "*"
|
| 702 |
+
}
|
| 703 |
+
},
|
| 704 |
+
"node_modules/accepts": {
|
| 705 |
+
"version": "1.3.8",
|
| 706 |
+
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
|
| 707 |
+
"integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
|
| 708 |
+
"license": "MIT",
|
| 709 |
+
"dependencies": {
|
| 710 |
+
"mime-types": "~2.1.34",
|
| 711 |
+
"negotiator": "0.6.3"
|
| 712 |
+
},
|
| 713 |
+
"engines": {
|
| 714 |
+
"node": ">= 0.6"
|
| 715 |
+
}
|
| 716 |
+
},
|
| 717 |
+
"node_modules/array-flatten": {
|
| 718 |
+
"version": "1.1.1",
|
| 719 |
+
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
| 720 |
+
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
|
| 721 |
+
"license": "MIT"
|
| 722 |
+
},
|
| 723 |
+
"node_modules/bcryptjs": {
|
| 724 |
+
"version": "2.4.3",
|
| 725 |
+
"resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz",
|
| 726 |
+
"integrity": "sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ==",
|
| 727 |
+
"license": "MIT"
|
| 728 |
+
},
|
| 729 |
+
"node_modules/body-parser": {
|
| 730 |
+
"version": "1.20.3",
|
| 731 |
+
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.3.tgz",
|
| 732 |
+
"integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==",
|
| 733 |
+
"license": "MIT",
|
| 734 |
+
"dependencies": {
|
| 735 |
+
"bytes": "3.1.2",
|
| 736 |
+
"content-type": "~1.0.5",
|
| 737 |
+
"debug": "2.6.9",
|
| 738 |
+
"depd": "2.0.0",
|
| 739 |
+
"destroy": "1.2.0",
|
| 740 |
+
"http-errors": "2.0.0",
|
| 741 |
+
"iconv-lite": "0.4.24",
|
| 742 |
+
"on-finished": "2.4.1",
|
| 743 |
+
"qs": "6.13.0",
|
| 744 |
+
"raw-body": "2.5.2",
|
| 745 |
+
"type-is": "~1.6.18",
|
| 746 |
+
"unpipe": "1.0.0"
|
| 747 |
+
},
|
| 748 |
+
"engines": {
|
| 749 |
+
"node": ">= 0.8",
|
| 750 |
+
"npm": "1.2.8000 || >= 1.4.16"
|
| 751 |
+
}
|
| 752 |
+
},
|
| 753 |
+
"node_modules/buffer-equal-constant-time": {
|
| 754 |
+
"version": "1.0.1",
|
| 755 |
+
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
|
| 756 |
+
"integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==",
|
| 757 |
+
"license": "BSD-3-Clause"
|
| 758 |
+
},
|
| 759 |
+
"node_modules/bytes": {
|
| 760 |
+
"version": "3.1.2",
|
| 761 |
+
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
|
| 762 |
+
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
|
| 763 |
+
"license": "MIT",
|
| 764 |
+
"engines": {
|
| 765 |
+
"node": ">= 0.8"
|
| 766 |
+
}
|
| 767 |
+
},
|
| 768 |
+
"node_modules/call-bind-apply-helpers": {
|
| 769 |
+
"version": "1.0.2",
|
| 770 |
+
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
|
| 771 |
+
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
|
| 772 |
+
"license": "MIT",
|
| 773 |
+
"dependencies": {
|
| 774 |
+
"es-errors": "^1.3.0",
|
| 775 |
+
"function-bind": "^1.1.2"
|
| 776 |
+
},
|
| 777 |
+
"engines": {
|
| 778 |
+
"node": ">= 0.4"
|
| 779 |
+
}
|
| 780 |
+
},
|
| 781 |
+
"node_modules/call-bound": {
|
| 782 |
+
"version": "1.0.4",
|
| 783 |
+
"resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
|
| 784 |
+
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
|
| 785 |
+
"license": "MIT",
|
| 786 |
+
"dependencies": {
|
| 787 |
+
"call-bind-apply-helpers": "^1.0.2",
|
| 788 |
+
"get-intrinsic": "^1.3.0"
|
| 789 |
+
},
|
| 790 |
+
"engines": {
|
| 791 |
+
"node": ">= 0.4"
|
| 792 |
+
},
|
| 793 |
+
"funding": {
|
| 794 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 795 |
+
}
|
| 796 |
+
},
|
| 797 |
+
"node_modules/content-disposition": {
|
| 798 |
+
"version": "0.5.4",
|
| 799 |
+
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
|
| 800 |
+
"integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
|
| 801 |
+
"license": "MIT",
|
| 802 |
+
"dependencies": {
|
| 803 |
+
"safe-buffer": "5.2.1"
|
| 804 |
+
},
|
| 805 |
+
"engines": {
|
| 806 |
+
"node": ">= 0.6"
|
| 807 |
+
}
|
| 808 |
+
},
|
| 809 |
+
"node_modules/content-type": {
|
| 810 |
+
"version": "1.0.5",
|
| 811 |
+
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
|
| 812 |
+
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
|
| 813 |
+
"license": "MIT",
|
| 814 |
+
"engines": {
|
| 815 |
+
"node": ">= 0.6"
|
| 816 |
+
}
|
| 817 |
+
},
|
| 818 |
+
"node_modules/cookie": {
|
| 819 |
+
"version": "0.7.1",
|
| 820 |
+
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz",
|
| 821 |
+
"integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==",
|
| 822 |
+
"license": "MIT",
|
| 823 |
+
"engines": {
|
| 824 |
+
"node": ">= 0.6"
|
| 825 |
+
}
|
| 826 |
+
},
|
| 827 |
+
"node_modules/cookie-signature": {
|
| 828 |
+
"version": "1.0.6",
|
| 829 |
+
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
| 830 |
+
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==",
|
| 831 |
+
"license": "MIT"
|
| 832 |
+
},
|
| 833 |
+
"node_modules/cors": {
|
| 834 |
+
"version": "2.8.5",
|
| 835 |
+
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
| 836 |
+
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
|
| 837 |
+
"license": "MIT",
|
| 838 |
+
"dependencies": {
|
| 839 |
+
"object-assign": "^4",
|
| 840 |
+
"vary": "^1"
|
| 841 |
+
},
|
| 842 |
+
"engines": {
|
| 843 |
+
"node": ">= 0.10"
|
| 844 |
+
}
|
| 845 |
+
},
|
| 846 |
+
"node_modules/csv-parse": {
|
| 847 |
+
"version": "6.1.0",
|
| 848 |
+
"resolved": "https://registry.npmjs.org/csv-parse/-/csv-parse-6.1.0.tgz",
|
| 849 |
+
"integrity": "sha512-CEE+jwpgLn+MmtCpVcPtiCZpVtB6Z2OKPTr34pycYYoL7sxdOkXDdQ4lRiw6ioC0q6BLqhc6cKweCVvral8yhw==",
|
| 850 |
+
"license": "MIT"
|
| 851 |
+
},
|
| 852 |
+
"node_modules/debug": {
|
| 853 |
+
"version": "2.6.9",
|
| 854 |
+
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
| 855 |
+
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
| 856 |
+
"license": "MIT",
|
| 857 |
+
"dependencies": {
|
| 858 |
+
"ms": "2.0.0"
|
| 859 |
+
}
|
| 860 |
+
},
|
| 861 |
+
"node_modules/depd": {
|
| 862 |
+
"version": "2.0.0",
|
| 863 |
+
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
| 864 |
+
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
|
| 865 |
+
"license": "MIT",
|
| 866 |
+
"engines": {
|
| 867 |
+
"node": ">= 0.8"
|
| 868 |
+
}
|
| 869 |
+
},
|
| 870 |
+
"node_modules/destroy": {
|
| 871 |
+
"version": "1.2.0",
|
| 872 |
+
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
|
| 873 |
+
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
|
| 874 |
+
"license": "MIT",
|
| 875 |
+
"engines": {
|
| 876 |
+
"node": ">= 0.8",
|
| 877 |
+
"npm": "1.2.8000 || >= 1.4.16"
|
| 878 |
+
}
|
| 879 |
+
},
|
| 880 |
+
"node_modules/dotenv": {
|
| 881 |
+
"version": "16.6.1",
|
| 882 |
+
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.6.1.tgz",
|
| 883 |
+
"integrity": "sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow==",
|
| 884 |
+
"license": "BSD-2-Clause",
|
| 885 |
+
"engines": {
|
| 886 |
+
"node": ">=12"
|
| 887 |
+
},
|
| 888 |
+
"funding": {
|
| 889 |
+
"url": "https://dotenvx.com"
|
| 890 |
+
}
|
| 891 |
+
},
|
| 892 |
+
"node_modules/dunder-proto": {
|
| 893 |
+
"version": "1.0.1",
|
| 894 |
+
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
| 895 |
+
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
|
| 896 |
+
"license": "MIT",
|
| 897 |
+
"dependencies": {
|
| 898 |
+
"call-bind-apply-helpers": "^1.0.1",
|
| 899 |
+
"es-errors": "^1.3.0",
|
| 900 |
+
"gopd": "^1.2.0"
|
| 901 |
+
},
|
| 902 |
+
"engines": {
|
| 903 |
+
"node": ">= 0.4"
|
| 904 |
+
}
|
| 905 |
+
},
|
| 906 |
+
"node_modules/ecdsa-sig-formatter": {
|
| 907 |
+
"version": "1.0.11",
|
| 908 |
+
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
| 909 |
+
"integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==",
|
| 910 |
+
"license": "Apache-2.0",
|
| 911 |
+
"dependencies": {
|
| 912 |
+
"safe-buffer": "^5.0.1"
|
| 913 |
+
}
|
| 914 |
+
},
|
| 915 |
+
"node_modules/ee-first": {
|
| 916 |
+
"version": "1.1.1",
|
| 917 |
+
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
| 918 |
+
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
|
| 919 |
+
"license": "MIT"
|
| 920 |
+
},
|
| 921 |
+
"node_modules/encodeurl": {
|
| 922 |
+
"version": "2.0.0",
|
| 923 |
+
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
|
| 924 |
+
"integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
|
| 925 |
+
"license": "MIT",
|
| 926 |
+
"engines": {
|
| 927 |
+
"node": ">= 0.8"
|
| 928 |
+
}
|
| 929 |
+
},
|
| 930 |
+
"node_modules/es-define-property": {
|
| 931 |
+
"version": "1.0.1",
|
| 932 |
+
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
|
| 933 |
+
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
|
| 934 |
+
"license": "MIT",
|
| 935 |
+
"engines": {
|
| 936 |
+
"node": ">= 0.4"
|
| 937 |
+
}
|
| 938 |
+
},
|
| 939 |
+
"node_modules/es-errors": {
|
| 940 |
+
"version": "1.3.0",
|
| 941 |
+
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
| 942 |
+
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
| 943 |
+
"license": "MIT",
|
| 944 |
+
"engines": {
|
| 945 |
+
"node": ">= 0.4"
|
| 946 |
+
}
|
| 947 |
+
},
|
| 948 |
+
"node_modules/es-object-atoms": {
|
| 949 |
+
"version": "1.1.1",
|
| 950 |
+
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
|
| 951 |
+
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
|
| 952 |
+
"license": "MIT",
|
| 953 |
+
"dependencies": {
|
| 954 |
+
"es-errors": "^1.3.0"
|
| 955 |
+
},
|
| 956 |
+
"engines": {
|
| 957 |
+
"node": ">= 0.4"
|
| 958 |
+
}
|
| 959 |
+
},
|
| 960 |
+
"node_modules/esbuild": {
|
| 961 |
+
"version": "0.25.12",
|
| 962 |
+
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.12.tgz",
|
| 963 |
+
"integrity": "sha512-bbPBYYrtZbkt6Os6FiTLCTFxvq4tt3JKall1vRwshA3fdVztsLAatFaZobhkBC8/BrPetoa0oksYoKXoG4ryJg==",
|
| 964 |
+
"dev": true,
|
| 965 |
+
"hasInstallScript": true,
|
| 966 |
+
"license": "MIT",
|
| 967 |
+
"bin": {
|
| 968 |
+
"esbuild": "bin/esbuild"
|
| 969 |
+
},
|
| 970 |
+
"engines": {
|
| 971 |
+
"node": ">=18"
|
| 972 |
+
},
|
| 973 |
+
"optionalDependencies": {
|
| 974 |
+
"@esbuild/aix-ppc64": "0.25.12",
|
| 975 |
+
"@esbuild/android-arm": "0.25.12",
|
| 976 |
+
"@esbuild/android-arm64": "0.25.12",
|
| 977 |
+
"@esbuild/android-x64": "0.25.12",
|
| 978 |
+
"@esbuild/darwin-arm64": "0.25.12",
|
| 979 |
+
"@esbuild/darwin-x64": "0.25.12",
|
| 980 |
+
"@esbuild/freebsd-arm64": "0.25.12",
|
| 981 |
+
"@esbuild/freebsd-x64": "0.25.12",
|
| 982 |
+
"@esbuild/linux-arm": "0.25.12",
|
| 983 |
+
"@esbuild/linux-arm64": "0.25.12",
|
| 984 |
+
"@esbuild/linux-ia32": "0.25.12",
|
| 985 |
+
"@esbuild/linux-loong64": "0.25.12",
|
| 986 |
+
"@esbuild/linux-mips64el": "0.25.12",
|
| 987 |
+
"@esbuild/linux-ppc64": "0.25.12",
|
| 988 |
+
"@esbuild/linux-riscv64": "0.25.12",
|
| 989 |
+
"@esbuild/linux-s390x": "0.25.12",
|
| 990 |
+
"@esbuild/linux-x64": "0.25.12",
|
| 991 |
+
"@esbuild/netbsd-arm64": "0.25.12",
|
| 992 |
+
"@esbuild/netbsd-x64": "0.25.12",
|
| 993 |
+
"@esbuild/openbsd-arm64": "0.25.12",
|
| 994 |
+
"@esbuild/openbsd-x64": "0.25.12",
|
| 995 |
+
"@esbuild/openharmony-arm64": "0.25.12",
|
| 996 |
+
"@esbuild/sunos-x64": "0.25.12",
|
| 997 |
+
"@esbuild/win32-arm64": "0.25.12",
|
| 998 |
+
"@esbuild/win32-ia32": "0.25.12",
|
| 999 |
+
"@esbuild/win32-x64": "0.25.12"
|
| 1000 |
+
}
|
| 1001 |
+
},
|
| 1002 |
+
"node_modules/escape-html": {
|
| 1003 |
+
"version": "1.0.3",
|
| 1004 |
+
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
|
| 1005 |
+
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
|
| 1006 |
+
"license": "MIT"
|
| 1007 |
+
},
|
| 1008 |
+
"node_modules/etag": {
|
| 1009 |
+
"version": "1.8.1",
|
| 1010 |
+
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
|
| 1011 |
+
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
|
| 1012 |
+
"license": "MIT",
|
| 1013 |
+
"engines": {
|
| 1014 |
+
"node": ">= 0.6"
|
| 1015 |
+
}
|
| 1016 |
+
},
|
| 1017 |
+
"node_modules/express": {
|
| 1018 |
+
"version": "4.21.2",
|
| 1019 |
+
"resolved": "https://registry.npmjs.org/express/-/express-4.21.2.tgz",
|
| 1020 |
+
"integrity": "sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==",
|
| 1021 |
+
"license": "MIT",
|
| 1022 |
+
"dependencies": {
|
| 1023 |
+
"accepts": "~1.3.8",
|
| 1024 |
+
"array-flatten": "1.1.1",
|
| 1025 |
+
"body-parser": "1.20.3",
|
| 1026 |
+
"content-disposition": "0.5.4",
|
| 1027 |
+
"content-type": "~1.0.4",
|
| 1028 |
+
"cookie": "0.7.1",
|
| 1029 |
+
"cookie-signature": "1.0.6",
|
| 1030 |
+
"debug": "2.6.9",
|
| 1031 |
+
"depd": "2.0.0",
|
| 1032 |
+
"encodeurl": "~2.0.0",
|
| 1033 |
+
"escape-html": "~1.0.3",
|
| 1034 |
+
"etag": "~1.8.1",
|
| 1035 |
+
"finalhandler": "1.3.1",
|
| 1036 |
+
"fresh": "0.5.2",
|
| 1037 |
+
"http-errors": "2.0.0",
|
| 1038 |
+
"merge-descriptors": "1.0.3",
|
| 1039 |
+
"methods": "~1.1.2",
|
| 1040 |
+
"on-finished": "2.4.1",
|
| 1041 |
+
"parseurl": "~1.3.3",
|
| 1042 |
+
"path-to-regexp": "0.1.12",
|
| 1043 |
+
"proxy-addr": "~2.0.7",
|
| 1044 |
+
"qs": "6.13.0",
|
| 1045 |
+
"range-parser": "~1.2.1",
|
| 1046 |
+
"safe-buffer": "5.2.1",
|
| 1047 |
+
"send": "0.19.0",
|
| 1048 |
+
"serve-static": "1.16.2",
|
| 1049 |
+
"setprototypeof": "1.2.0",
|
| 1050 |
+
"statuses": "2.0.1",
|
| 1051 |
+
"type-is": "~1.6.18",
|
| 1052 |
+
"utils-merge": "1.0.1",
|
| 1053 |
+
"vary": "~1.1.2"
|
| 1054 |
+
},
|
| 1055 |
+
"engines": {
|
| 1056 |
+
"node": ">= 0.10.0"
|
| 1057 |
+
},
|
| 1058 |
+
"funding": {
|
| 1059 |
+
"type": "opencollective",
|
| 1060 |
+
"url": "https://opencollective.com/express"
|
| 1061 |
+
}
|
| 1062 |
+
},
|
| 1063 |
+
"node_modules/finalhandler": {
|
| 1064 |
+
"version": "1.3.1",
|
| 1065 |
+
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.1.tgz",
|
| 1066 |
+
"integrity": "sha512-6BN9trH7bp3qvnrRyzsBz+g3lZxTNZTbVO2EV1CS0WIcDbawYVdYvGflME/9QP0h0pYlCDBCTjYa9nZzMDpyxQ==",
|
| 1067 |
+
"license": "MIT",
|
| 1068 |
+
"dependencies": {
|
| 1069 |
+
"debug": "2.6.9",
|
| 1070 |
+
"encodeurl": "~2.0.0",
|
| 1071 |
+
"escape-html": "~1.0.3",
|
| 1072 |
+
"on-finished": "2.4.1",
|
| 1073 |
+
"parseurl": "~1.3.3",
|
| 1074 |
+
"statuses": "2.0.1",
|
| 1075 |
+
"unpipe": "~1.0.0"
|
| 1076 |
+
},
|
| 1077 |
+
"engines": {
|
| 1078 |
+
"node": ">= 0.8"
|
| 1079 |
+
}
|
| 1080 |
+
},
|
| 1081 |
+
"node_modules/forwarded": {
|
| 1082 |
+
"version": "0.2.0",
|
| 1083 |
+
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
| 1084 |
+
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
|
| 1085 |
+
"license": "MIT",
|
| 1086 |
+
"engines": {
|
| 1087 |
+
"node": ">= 0.6"
|
| 1088 |
+
}
|
| 1089 |
+
},
|
| 1090 |
+
"node_modules/fresh": {
|
| 1091 |
+
"version": "0.5.2",
|
| 1092 |
+
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
| 1093 |
+
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
|
| 1094 |
+
"license": "MIT",
|
| 1095 |
+
"engines": {
|
| 1096 |
+
"node": ">= 0.6"
|
| 1097 |
+
}
|
| 1098 |
+
},
|
| 1099 |
+
"node_modules/fsevents": {
|
| 1100 |
+
"version": "2.3.3",
|
| 1101 |
+
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
|
| 1102 |
+
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
|
| 1103 |
+
"hasInstallScript": true,
|
| 1104 |
+
"license": "MIT",
|
| 1105 |
+
"optional": true,
|
| 1106 |
+
"os": [
|
| 1107 |
+
"darwin"
|
| 1108 |
+
],
|
| 1109 |
+
"engines": {
|
| 1110 |
+
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
| 1111 |
+
}
|
| 1112 |
+
},
|
| 1113 |
+
"node_modules/function-bind": {
|
| 1114 |
+
"version": "1.1.2",
|
| 1115 |
+
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
| 1116 |
+
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
| 1117 |
+
"license": "MIT",
|
| 1118 |
+
"funding": {
|
| 1119 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1120 |
+
}
|
| 1121 |
+
},
|
| 1122 |
+
"node_modules/get-intrinsic": {
|
| 1123 |
+
"version": "1.3.0",
|
| 1124 |
+
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
| 1125 |
+
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
|
| 1126 |
+
"license": "MIT",
|
| 1127 |
+
"dependencies": {
|
| 1128 |
+
"call-bind-apply-helpers": "^1.0.2",
|
| 1129 |
+
"es-define-property": "^1.0.1",
|
| 1130 |
+
"es-errors": "^1.3.0",
|
| 1131 |
+
"es-object-atoms": "^1.1.1",
|
| 1132 |
+
"function-bind": "^1.1.2",
|
| 1133 |
+
"get-proto": "^1.0.1",
|
| 1134 |
+
"gopd": "^1.2.0",
|
| 1135 |
+
"has-symbols": "^1.1.0",
|
| 1136 |
+
"hasown": "^2.0.2",
|
| 1137 |
+
"math-intrinsics": "^1.1.0"
|
| 1138 |
+
},
|
| 1139 |
+
"engines": {
|
| 1140 |
+
"node": ">= 0.4"
|
| 1141 |
+
},
|
| 1142 |
+
"funding": {
|
| 1143 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1144 |
+
}
|
| 1145 |
+
},
|
| 1146 |
+
"node_modules/get-proto": {
|
| 1147 |
+
"version": "1.0.1",
|
| 1148 |
+
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
|
| 1149 |
+
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
| 1150 |
+
"license": "MIT",
|
| 1151 |
+
"dependencies": {
|
| 1152 |
+
"dunder-proto": "^1.0.1",
|
| 1153 |
+
"es-object-atoms": "^1.0.0"
|
| 1154 |
+
},
|
| 1155 |
+
"engines": {
|
| 1156 |
+
"node": ">= 0.4"
|
| 1157 |
+
}
|
| 1158 |
+
},
|
| 1159 |
+
"node_modules/get-tsconfig": {
|
| 1160 |
+
"version": "4.13.0",
|
| 1161 |
+
"resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.0.tgz",
|
| 1162 |
+
"integrity": "sha512-1VKTZJCwBrvbd+Wn3AOgQP/2Av+TfTCOlE4AcRJE72W1ksZXbAx8PPBR9RzgTeSPzlPMHrbANMH3LbltH73wxQ==",
|
| 1163 |
+
"dev": true,
|
| 1164 |
+
"license": "MIT",
|
| 1165 |
+
"dependencies": {
|
| 1166 |
+
"resolve-pkg-maps": "^1.0.0"
|
| 1167 |
+
},
|
| 1168 |
+
"funding": {
|
| 1169 |
+
"url": "https://github.com/privatenumber/get-tsconfig?sponsor=1"
|
| 1170 |
+
}
|
| 1171 |
+
},
|
| 1172 |
+
"node_modules/gopd": {
|
| 1173 |
+
"version": "1.2.0",
|
| 1174 |
+
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
|
| 1175 |
+
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
|
| 1176 |
+
"license": "MIT",
|
| 1177 |
+
"engines": {
|
| 1178 |
+
"node": ">= 0.4"
|
| 1179 |
+
},
|
| 1180 |
+
"funding": {
|
| 1181 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1182 |
+
}
|
| 1183 |
+
},
|
| 1184 |
+
"node_modules/has-symbols": {
|
| 1185 |
+
"version": "1.1.0",
|
| 1186 |
+
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
|
| 1187 |
+
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
|
| 1188 |
+
"license": "MIT",
|
| 1189 |
+
"engines": {
|
| 1190 |
+
"node": ">= 0.4"
|
| 1191 |
+
},
|
| 1192 |
+
"funding": {
|
| 1193 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1194 |
+
}
|
| 1195 |
+
},
|
| 1196 |
+
"node_modules/hasown": {
|
| 1197 |
+
"version": "2.0.2",
|
| 1198 |
+
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
|
| 1199 |
+
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
|
| 1200 |
+
"license": "MIT",
|
| 1201 |
+
"dependencies": {
|
| 1202 |
+
"function-bind": "^1.1.2"
|
| 1203 |
+
},
|
| 1204 |
+
"engines": {
|
| 1205 |
+
"node": ">= 0.4"
|
| 1206 |
+
}
|
| 1207 |
+
},
|
| 1208 |
+
"node_modules/http-errors": {
|
| 1209 |
+
"version": "2.0.0",
|
| 1210 |
+
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
|
| 1211 |
+
"integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
|
| 1212 |
+
"license": "MIT",
|
| 1213 |
+
"dependencies": {
|
| 1214 |
+
"depd": "2.0.0",
|
| 1215 |
+
"inherits": "2.0.4",
|
| 1216 |
+
"setprototypeof": "1.2.0",
|
| 1217 |
+
"statuses": "2.0.1",
|
| 1218 |
+
"toidentifier": "1.0.1"
|
| 1219 |
+
},
|
| 1220 |
+
"engines": {
|
| 1221 |
+
"node": ">= 0.8"
|
| 1222 |
+
}
|
| 1223 |
+
},
|
| 1224 |
+
"node_modules/iconv-lite": {
|
| 1225 |
+
"version": "0.4.24",
|
| 1226 |
+
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
| 1227 |
+
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
|
| 1228 |
+
"license": "MIT",
|
| 1229 |
+
"dependencies": {
|
| 1230 |
+
"safer-buffer": ">= 2.1.2 < 3"
|
| 1231 |
+
},
|
| 1232 |
+
"engines": {
|
| 1233 |
+
"node": ">=0.10.0"
|
| 1234 |
+
}
|
| 1235 |
+
},
|
| 1236 |
+
"node_modules/inherits": {
|
| 1237 |
+
"version": "2.0.4",
|
| 1238 |
+
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
| 1239 |
+
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
| 1240 |
+
"license": "ISC"
|
| 1241 |
+
},
|
| 1242 |
+
"node_modules/ipaddr.js": {
|
| 1243 |
+
"version": "1.9.1",
|
| 1244 |
+
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
| 1245 |
+
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
|
| 1246 |
+
"license": "MIT",
|
| 1247 |
+
"engines": {
|
| 1248 |
+
"node": ">= 0.10"
|
| 1249 |
+
}
|
| 1250 |
+
},
|
| 1251 |
+
"node_modules/jsonwebtoken": {
|
| 1252 |
+
"version": "9.0.2",
|
| 1253 |
+
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz",
|
| 1254 |
+
"integrity": "sha512-PRp66vJ865SSqOlgqS8hujT5U4AOgMfhrwYIuIhfKaoSCZcirrmASQr8CX7cUg+RMih+hgznrjp99o+W4pJLHQ==",
|
| 1255 |
+
"license": "MIT",
|
| 1256 |
+
"dependencies": {
|
| 1257 |
+
"jws": "^3.2.2",
|
| 1258 |
+
"lodash.includes": "^4.3.0",
|
| 1259 |
+
"lodash.isboolean": "^3.0.3",
|
| 1260 |
+
"lodash.isinteger": "^4.0.4",
|
| 1261 |
+
"lodash.isnumber": "^3.0.3",
|
| 1262 |
+
"lodash.isplainobject": "^4.0.6",
|
| 1263 |
+
"lodash.isstring": "^4.0.1",
|
| 1264 |
+
"lodash.once": "^4.0.0",
|
| 1265 |
+
"ms": "^2.1.1",
|
| 1266 |
+
"semver": "^7.5.4"
|
| 1267 |
+
},
|
| 1268 |
+
"engines": {
|
| 1269 |
+
"node": ">=12",
|
| 1270 |
+
"npm": ">=6"
|
| 1271 |
+
}
|
| 1272 |
+
},
|
| 1273 |
+
"node_modules/jsonwebtoken/node_modules/ms": {
|
| 1274 |
+
"version": "2.1.3",
|
| 1275 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
| 1276 |
+
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
| 1277 |
+
"license": "MIT"
|
| 1278 |
+
},
|
| 1279 |
+
"node_modules/jwa": {
|
| 1280 |
+
"version": "1.4.2",
|
| 1281 |
+
"resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.2.tgz",
|
| 1282 |
+
"integrity": "sha512-eeH5JO+21J78qMvTIDdBXidBd6nG2kZjg5Ohz/1fpa28Z4CcsWUzJ1ZZyFq/3z3N17aZy+ZuBoHljASbL1WfOw==",
|
| 1283 |
+
"license": "MIT",
|
| 1284 |
+
"dependencies": {
|
| 1285 |
+
"buffer-equal-constant-time": "^1.0.1",
|
| 1286 |
+
"ecdsa-sig-formatter": "1.0.11",
|
| 1287 |
+
"safe-buffer": "^5.0.1"
|
| 1288 |
+
}
|
| 1289 |
+
},
|
| 1290 |
+
"node_modules/jws": {
|
| 1291 |
+
"version": "3.2.2",
|
| 1292 |
+
"resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz",
|
| 1293 |
+
"integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==",
|
| 1294 |
+
"license": "MIT",
|
| 1295 |
+
"dependencies": {
|
| 1296 |
+
"jwa": "^1.4.1",
|
| 1297 |
+
"safe-buffer": "^5.0.1"
|
| 1298 |
+
}
|
| 1299 |
+
},
|
| 1300 |
+
"node_modules/lodash.includes": {
|
| 1301 |
+
"version": "4.3.0",
|
| 1302 |
+
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
|
| 1303 |
+
"integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==",
|
| 1304 |
+
"license": "MIT"
|
| 1305 |
+
},
|
| 1306 |
+
"node_modules/lodash.isboolean": {
|
| 1307 |
+
"version": "3.0.3",
|
| 1308 |
+
"resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz",
|
| 1309 |
+
"integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==",
|
| 1310 |
+
"license": "MIT"
|
| 1311 |
+
},
|
| 1312 |
+
"node_modules/lodash.isinteger": {
|
| 1313 |
+
"version": "4.0.4",
|
| 1314 |
+
"resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz",
|
| 1315 |
+
"integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==",
|
| 1316 |
+
"license": "MIT"
|
| 1317 |
+
},
|
| 1318 |
+
"node_modules/lodash.isnumber": {
|
| 1319 |
+
"version": "3.0.3",
|
| 1320 |
+
"resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz",
|
| 1321 |
+
"integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==",
|
| 1322 |
+
"license": "MIT"
|
| 1323 |
+
},
|
| 1324 |
+
"node_modules/lodash.isplainobject": {
|
| 1325 |
+
"version": "4.0.6",
|
| 1326 |
+
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
|
| 1327 |
+
"integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==",
|
| 1328 |
+
"license": "MIT"
|
| 1329 |
+
},
|
| 1330 |
+
"node_modules/lodash.isstring": {
|
| 1331 |
+
"version": "4.0.1",
|
| 1332 |
+
"resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz",
|
| 1333 |
+
"integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==",
|
| 1334 |
+
"license": "MIT"
|
| 1335 |
+
},
|
| 1336 |
+
"node_modules/lodash.once": {
|
| 1337 |
+
"version": "4.1.1",
|
| 1338 |
+
"resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
|
| 1339 |
+
"integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==",
|
| 1340 |
+
"license": "MIT"
|
| 1341 |
+
},
|
| 1342 |
+
"node_modules/math-intrinsics": {
|
| 1343 |
+
"version": "1.1.0",
|
| 1344 |
+
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
| 1345 |
+
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
|
| 1346 |
+
"license": "MIT",
|
| 1347 |
+
"engines": {
|
| 1348 |
+
"node": ">= 0.4"
|
| 1349 |
+
}
|
| 1350 |
+
},
|
| 1351 |
+
"node_modules/media-typer": {
|
| 1352 |
+
"version": "0.3.0",
|
| 1353 |
+
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
| 1354 |
+
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
|
| 1355 |
+
"license": "MIT",
|
| 1356 |
+
"engines": {
|
| 1357 |
+
"node": ">= 0.6"
|
| 1358 |
+
}
|
| 1359 |
+
},
|
| 1360 |
+
"node_modules/merge-descriptors": {
|
| 1361 |
+
"version": "1.0.3",
|
| 1362 |
+
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
|
| 1363 |
+
"integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==",
|
| 1364 |
+
"license": "MIT",
|
| 1365 |
+
"funding": {
|
| 1366 |
+
"url": "https://github.com/sponsors/sindresorhus"
|
| 1367 |
+
}
|
| 1368 |
+
},
|
| 1369 |
+
"node_modules/methods": {
|
| 1370 |
+
"version": "1.1.2",
|
| 1371 |
+
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
|
| 1372 |
+
"integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
|
| 1373 |
+
"license": "MIT",
|
| 1374 |
+
"engines": {
|
| 1375 |
+
"node": ">= 0.6"
|
| 1376 |
+
}
|
| 1377 |
+
},
|
| 1378 |
+
"node_modules/mime": {
|
| 1379 |
+
"version": "1.6.0",
|
| 1380 |
+
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
|
| 1381 |
+
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
|
| 1382 |
+
"license": "MIT",
|
| 1383 |
+
"bin": {
|
| 1384 |
+
"mime": "cli.js"
|
| 1385 |
+
},
|
| 1386 |
+
"engines": {
|
| 1387 |
+
"node": ">=4"
|
| 1388 |
+
}
|
| 1389 |
+
},
|
| 1390 |
+
"node_modules/mime-db": {
|
| 1391 |
+
"version": "1.52.0",
|
| 1392 |
+
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
| 1393 |
+
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
| 1394 |
+
"license": "MIT",
|
| 1395 |
+
"engines": {
|
| 1396 |
+
"node": ">= 0.6"
|
| 1397 |
+
}
|
| 1398 |
+
},
|
| 1399 |
+
"node_modules/mime-types": {
|
| 1400 |
+
"version": "2.1.35",
|
| 1401 |
+
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
| 1402 |
+
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
| 1403 |
+
"license": "MIT",
|
| 1404 |
+
"dependencies": {
|
| 1405 |
+
"mime-db": "1.52.0"
|
| 1406 |
+
},
|
| 1407 |
+
"engines": {
|
| 1408 |
+
"node": ">= 0.6"
|
| 1409 |
+
}
|
| 1410 |
+
},
|
| 1411 |
+
"node_modules/ms": {
|
| 1412 |
+
"version": "2.0.0",
|
| 1413 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
| 1414 |
+
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
|
| 1415 |
+
"license": "MIT"
|
| 1416 |
+
},
|
| 1417 |
+
"node_modules/negotiator": {
|
| 1418 |
+
"version": "0.6.3",
|
| 1419 |
+
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
|
| 1420 |
+
"integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
|
| 1421 |
+
"license": "MIT",
|
| 1422 |
+
"engines": {
|
| 1423 |
+
"node": ">= 0.6"
|
| 1424 |
+
}
|
| 1425 |
+
},
|
| 1426 |
+
"node_modules/object-assign": {
|
| 1427 |
+
"version": "4.1.1",
|
| 1428 |
+
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
| 1429 |
+
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
|
| 1430 |
+
"license": "MIT",
|
| 1431 |
+
"engines": {
|
| 1432 |
+
"node": ">=0.10.0"
|
| 1433 |
+
}
|
| 1434 |
+
},
|
| 1435 |
+
"node_modules/object-inspect": {
|
| 1436 |
+
"version": "1.13.4",
|
| 1437 |
+
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
|
| 1438 |
+
"integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
|
| 1439 |
+
"license": "MIT",
|
| 1440 |
+
"engines": {
|
| 1441 |
+
"node": ">= 0.4"
|
| 1442 |
+
},
|
| 1443 |
+
"funding": {
|
| 1444 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1445 |
+
}
|
| 1446 |
+
},
|
| 1447 |
+
"node_modules/on-finished": {
|
| 1448 |
+
"version": "2.4.1",
|
| 1449 |
+
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
|
| 1450 |
+
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
|
| 1451 |
+
"license": "MIT",
|
| 1452 |
+
"dependencies": {
|
| 1453 |
+
"ee-first": "1.1.1"
|
| 1454 |
+
},
|
| 1455 |
+
"engines": {
|
| 1456 |
+
"node": ">= 0.8"
|
| 1457 |
+
}
|
| 1458 |
+
},
|
| 1459 |
+
"node_modules/parseurl": {
|
| 1460 |
+
"version": "1.3.3",
|
| 1461 |
+
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
| 1462 |
+
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
|
| 1463 |
+
"license": "MIT",
|
| 1464 |
+
"engines": {
|
| 1465 |
+
"node": ">= 0.8"
|
| 1466 |
+
}
|
| 1467 |
+
},
|
| 1468 |
+
"node_modules/path-to-regexp": {
|
| 1469 |
+
"version": "0.1.12",
|
| 1470 |
+
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz",
|
| 1471 |
+
"integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==",
|
| 1472 |
+
"license": "MIT"
|
| 1473 |
+
},
|
| 1474 |
+
"node_modules/prisma": {
|
| 1475 |
+
"version": "5.22.0",
|
| 1476 |
+
"resolved": "https://registry.npmjs.org/prisma/-/prisma-5.22.0.tgz",
|
| 1477 |
+
"integrity": "sha512-vtpjW3XuYCSnMsNVBjLMNkTj6OZbudcPPTPYHqX0CJfpcdWciI1dM8uHETwmDxxiqEwCIE6WvXucWUetJgfu/A==",
|
| 1478 |
+
"devOptional": true,
|
| 1479 |
+
"hasInstallScript": true,
|
| 1480 |
+
"license": "Apache-2.0",
|
| 1481 |
+
"dependencies": {
|
| 1482 |
+
"@prisma/engines": "5.22.0"
|
| 1483 |
+
},
|
| 1484 |
+
"bin": {
|
| 1485 |
+
"prisma": "build/index.js"
|
| 1486 |
+
},
|
| 1487 |
+
"engines": {
|
| 1488 |
+
"node": ">=16.13"
|
| 1489 |
+
},
|
| 1490 |
+
"optionalDependencies": {
|
| 1491 |
+
"fsevents": "2.3.3"
|
| 1492 |
+
}
|
| 1493 |
+
},
|
| 1494 |
+
"node_modules/proxy-addr": {
|
| 1495 |
+
"version": "2.0.7",
|
| 1496 |
+
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
| 1497 |
+
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
|
| 1498 |
+
"license": "MIT",
|
| 1499 |
+
"dependencies": {
|
| 1500 |
+
"forwarded": "0.2.0",
|
| 1501 |
+
"ipaddr.js": "1.9.1"
|
| 1502 |
+
},
|
| 1503 |
+
"engines": {
|
| 1504 |
+
"node": ">= 0.10"
|
| 1505 |
+
}
|
| 1506 |
+
},
|
| 1507 |
+
"node_modules/qs": {
|
| 1508 |
+
"version": "6.13.0",
|
| 1509 |
+
"resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz",
|
| 1510 |
+
"integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==",
|
| 1511 |
+
"license": "BSD-3-Clause",
|
| 1512 |
+
"dependencies": {
|
| 1513 |
+
"side-channel": "^1.0.6"
|
| 1514 |
+
},
|
| 1515 |
+
"engines": {
|
| 1516 |
+
"node": ">=0.6"
|
| 1517 |
+
},
|
| 1518 |
+
"funding": {
|
| 1519 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1520 |
+
}
|
| 1521 |
+
},
|
| 1522 |
+
"node_modules/range-parser": {
|
| 1523 |
+
"version": "1.2.1",
|
| 1524 |
+
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
|
| 1525 |
+
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
|
| 1526 |
+
"license": "MIT",
|
| 1527 |
+
"engines": {
|
| 1528 |
+
"node": ">= 0.6"
|
| 1529 |
+
}
|
| 1530 |
+
},
|
| 1531 |
+
"node_modules/raw-body": {
|
| 1532 |
+
"version": "2.5.2",
|
| 1533 |
+
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz",
|
| 1534 |
+
"integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
|
| 1535 |
+
"license": "MIT",
|
| 1536 |
+
"dependencies": {
|
| 1537 |
+
"bytes": "3.1.2",
|
| 1538 |
+
"http-errors": "2.0.0",
|
| 1539 |
+
"iconv-lite": "0.4.24",
|
| 1540 |
+
"unpipe": "1.0.0"
|
| 1541 |
+
},
|
| 1542 |
+
"engines": {
|
| 1543 |
+
"node": ">= 0.8"
|
| 1544 |
+
}
|
| 1545 |
+
},
|
| 1546 |
+
"node_modules/resolve-pkg-maps": {
|
| 1547 |
+
"version": "1.0.0",
|
| 1548 |
+
"resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz",
|
| 1549 |
+
"integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==",
|
| 1550 |
+
"dev": true,
|
| 1551 |
+
"license": "MIT",
|
| 1552 |
+
"funding": {
|
| 1553 |
+
"url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1"
|
| 1554 |
+
}
|
| 1555 |
+
},
|
| 1556 |
+
"node_modules/safe-buffer": {
|
| 1557 |
+
"version": "5.2.1",
|
| 1558 |
+
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
| 1559 |
+
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
|
| 1560 |
+
"funding": [
|
| 1561 |
+
{
|
| 1562 |
+
"type": "github",
|
| 1563 |
+
"url": "https://github.com/sponsors/feross"
|
| 1564 |
+
},
|
| 1565 |
+
{
|
| 1566 |
+
"type": "patreon",
|
| 1567 |
+
"url": "https://www.patreon.com/feross"
|
| 1568 |
+
},
|
| 1569 |
+
{
|
| 1570 |
+
"type": "consulting",
|
| 1571 |
+
"url": "https://feross.org/support"
|
| 1572 |
+
}
|
| 1573 |
+
],
|
| 1574 |
+
"license": "MIT"
|
| 1575 |
+
},
|
| 1576 |
+
"node_modules/safer-buffer": {
|
| 1577 |
+
"version": "2.1.2",
|
| 1578 |
+
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
| 1579 |
+
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
|
| 1580 |
+
"license": "MIT"
|
| 1581 |
+
},
|
| 1582 |
+
"node_modules/semver": {
|
| 1583 |
+
"version": "7.7.3",
|
| 1584 |
+
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz",
|
| 1585 |
+
"integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==",
|
| 1586 |
+
"license": "ISC",
|
| 1587 |
+
"bin": {
|
| 1588 |
+
"semver": "bin/semver.js"
|
| 1589 |
+
},
|
| 1590 |
+
"engines": {
|
| 1591 |
+
"node": ">=10"
|
| 1592 |
+
}
|
| 1593 |
+
},
|
| 1594 |
+
"node_modules/send": {
|
| 1595 |
+
"version": "0.19.0",
|
| 1596 |
+
"resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz",
|
| 1597 |
+
"integrity": "sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==",
|
| 1598 |
+
"license": "MIT",
|
| 1599 |
+
"dependencies": {
|
| 1600 |
+
"debug": "2.6.9",
|
| 1601 |
+
"depd": "2.0.0",
|
| 1602 |
+
"destroy": "1.2.0",
|
| 1603 |
+
"encodeurl": "~1.0.2",
|
| 1604 |
+
"escape-html": "~1.0.3",
|
| 1605 |
+
"etag": "~1.8.1",
|
| 1606 |
+
"fresh": "0.5.2",
|
| 1607 |
+
"http-errors": "2.0.0",
|
| 1608 |
+
"mime": "1.6.0",
|
| 1609 |
+
"ms": "2.1.3",
|
| 1610 |
+
"on-finished": "2.4.1",
|
| 1611 |
+
"range-parser": "~1.2.1",
|
| 1612 |
+
"statuses": "2.0.1"
|
| 1613 |
+
},
|
| 1614 |
+
"engines": {
|
| 1615 |
+
"node": ">= 0.8.0"
|
| 1616 |
+
}
|
| 1617 |
+
},
|
| 1618 |
+
"node_modules/send/node_modules/encodeurl": {
|
| 1619 |
+
"version": "1.0.2",
|
| 1620 |
+
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
|
| 1621 |
+
"integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==",
|
| 1622 |
+
"license": "MIT",
|
| 1623 |
+
"engines": {
|
| 1624 |
+
"node": ">= 0.8"
|
| 1625 |
+
}
|
| 1626 |
+
},
|
| 1627 |
+
"node_modules/send/node_modules/ms": {
|
| 1628 |
+
"version": "2.1.3",
|
| 1629 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
| 1630 |
+
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
| 1631 |
+
"license": "MIT"
|
| 1632 |
+
},
|
| 1633 |
+
"node_modules/serve-static": {
|
| 1634 |
+
"version": "1.16.2",
|
| 1635 |
+
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.2.tgz",
|
| 1636 |
+
"integrity": "sha512-VqpjJZKadQB/PEbEwvFdO43Ax5dFBZ2UECszz8bQ7pi7wt//PWe1P6MN7eCnjsatYtBT6EuiClbjSWP2WrIoTw==",
|
| 1637 |
+
"license": "MIT",
|
| 1638 |
+
"dependencies": {
|
| 1639 |
+
"encodeurl": "~2.0.0",
|
| 1640 |
+
"escape-html": "~1.0.3",
|
| 1641 |
+
"parseurl": "~1.3.3",
|
| 1642 |
+
"send": "0.19.0"
|
| 1643 |
+
},
|
| 1644 |
+
"engines": {
|
| 1645 |
+
"node": ">= 0.8.0"
|
| 1646 |
+
}
|
| 1647 |
+
},
|
| 1648 |
+
"node_modules/setprototypeof": {
|
| 1649 |
+
"version": "1.2.0",
|
| 1650 |
+
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
| 1651 |
+
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
|
| 1652 |
+
"license": "ISC"
|
| 1653 |
+
},
|
| 1654 |
+
"node_modules/side-channel": {
|
| 1655 |
+
"version": "1.1.0",
|
| 1656 |
+
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz",
|
| 1657 |
+
"integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==",
|
| 1658 |
+
"license": "MIT",
|
| 1659 |
+
"dependencies": {
|
| 1660 |
+
"es-errors": "^1.3.0",
|
| 1661 |
+
"object-inspect": "^1.13.3",
|
| 1662 |
+
"side-channel-list": "^1.0.0",
|
| 1663 |
+
"side-channel-map": "^1.0.1",
|
| 1664 |
+
"side-channel-weakmap": "^1.0.2"
|
| 1665 |
+
},
|
| 1666 |
+
"engines": {
|
| 1667 |
+
"node": ">= 0.4"
|
| 1668 |
+
},
|
| 1669 |
+
"funding": {
|
| 1670 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1671 |
+
}
|
| 1672 |
+
},
|
| 1673 |
+
"node_modules/side-channel-list": {
|
| 1674 |
+
"version": "1.0.0",
|
| 1675 |
+
"resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz",
|
| 1676 |
+
"integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==",
|
| 1677 |
+
"license": "MIT",
|
| 1678 |
+
"dependencies": {
|
| 1679 |
+
"es-errors": "^1.3.0",
|
| 1680 |
+
"object-inspect": "^1.13.3"
|
| 1681 |
+
},
|
| 1682 |
+
"engines": {
|
| 1683 |
+
"node": ">= 0.4"
|
| 1684 |
+
},
|
| 1685 |
+
"funding": {
|
| 1686 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1687 |
+
}
|
| 1688 |
+
},
|
| 1689 |
+
"node_modules/side-channel-map": {
|
| 1690 |
+
"version": "1.0.1",
|
| 1691 |
+
"resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
|
| 1692 |
+
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
|
| 1693 |
+
"license": "MIT",
|
| 1694 |
+
"dependencies": {
|
| 1695 |
+
"call-bound": "^1.0.2",
|
| 1696 |
+
"es-errors": "^1.3.0",
|
| 1697 |
+
"get-intrinsic": "^1.2.5",
|
| 1698 |
+
"object-inspect": "^1.13.3"
|
| 1699 |
+
},
|
| 1700 |
+
"engines": {
|
| 1701 |
+
"node": ">= 0.4"
|
| 1702 |
+
},
|
| 1703 |
+
"funding": {
|
| 1704 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1705 |
+
}
|
| 1706 |
+
},
|
| 1707 |
+
"node_modules/side-channel-weakmap": {
|
| 1708 |
+
"version": "1.0.2",
|
| 1709 |
+
"resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
|
| 1710 |
+
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
|
| 1711 |
+
"license": "MIT",
|
| 1712 |
+
"dependencies": {
|
| 1713 |
+
"call-bound": "^1.0.2",
|
| 1714 |
+
"es-errors": "^1.3.0",
|
| 1715 |
+
"get-intrinsic": "^1.2.5",
|
| 1716 |
+
"object-inspect": "^1.13.3",
|
| 1717 |
+
"side-channel-map": "^1.0.1"
|
| 1718 |
+
},
|
| 1719 |
+
"engines": {
|
| 1720 |
+
"node": ">= 0.4"
|
| 1721 |
+
},
|
| 1722 |
+
"funding": {
|
| 1723 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1724 |
+
}
|
| 1725 |
+
},
|
| 1726 |
+
"node_modules/statuses": {
|
| 1727 |
+
"version": "2.0.1",
|
| 1728 |
+
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
|
| 1729 |
+
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
|
| 1730 |
+
"license": "MIT",
|
| 1731 |
+
"engines": {
|
| 1732 |
+
"node": ">= 0.8"
|
| 1733 |
+
}
|
| 1734 |
+
},
|
| 1735 |
+
"node_modules/toidentifier": {
|
| 1736 |
+
"version": "1.0.1",
|
| 1737 |
+
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
|
| 1738 |
+
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
|
| 1739 |
+
"license": "MIT",
|
| 1740 |
+
"engines": {
|
| 1741 |
+
"node": ">=0.6"
|
| 1742 |
+
}
|
| 1743 |
+
},
|
| 1744 |
+
"node_modules/tsx": {
|
| 1745 |
+
"version": "4.20.6",
|
| 1746 |
+
"resolved": "https://registry.npmjs.org/tsx/-/tsx-4.20.6.tgz",
|
| 1747 |
+
"integrity": "sha512-ytQKuwgmrrkDTFP4LjR0ToE2nqgy886GpvRSpU0JAnrdBYppuY5rLkRUYPU1yCryb24SsKBTL/hlDQAEFVwtZg==",
|
| 1748 |
+
"dev": true,
|
| 1749 |
+
"license": "MIT",
|
| 1750 |
+
"dependencies": {
|
| 1751 |
+
"esbuild": "~0.25.0",
|
| 1752 |
+
"get-tsconfig": "^4.7.5"
|
| 1753 |
+
},
|
| 1754 |
+
"bin": {
|
| 1755 |
+
"tsx": "dist/cli.mjs"
|
| 1756 |
+
},
|
| 1757 |
+
"engines": {
|
| 1758 |
+
"node": ">=18.0.0"
|
| 1759 |
+
},
|
| 1760 |
+
"optionalDependencies": {
|
| 1761 |
+
"fsevents": "~2.3.3"
|
| 1762 |
+
}
|
| 1763 |
+
},
|
| 1764 |
+
"node_modules/type-is": {
|
| 1765 |
+
"version": "1.6.18",
|
| 1766 |
+
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
| 1767 |
+
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
|
| 1768 |
+
"license": "MIT",
|
| 1769 |
+
"dependencies": {
|
| 1770 |
+
"media-typer": "0.3.0",
|
| 1771 |
+
"mime-types": "~2.1.24"
|
| 1772 |
+
},
|
| 1773 |
+
"engines": {
|
| 1774 |
+
"node": ">= 0.6"
|
| 1775 |
+
}
|
| 1776 |
+
},
|
| 1777 |
+
"node_modules/typescript": {
|
| 1778 |
+
"version": "5.9.3",
|
| 1779 |
+
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
| 1780 |
+
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
| 1781 |
+
"dev": true,
|
| 1782 |
+
"license": "Apache-2.0",
|
| 1783 |
+
"bin": {
|
| 1784 |
+
"tsc": "bin/tsc",
|
| 1785 |
+
"tsserver": "bin/tsserver"
|
| 1786 |
+
},
|
| 1787 |
+
"engines": {
|
| 1788 |
+
"node": ">=14.17"
|
| 1789 |
+
}
|
| 1790 |
+
},
|
| 1791 |
+
"node_modules/undici-types": {
|
| 1792 |
+
"version": "6.21.0",
|
| 1793 |
+
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
|
| 1794 |
+
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
|
| 1795 |
+
"dev": true,
|
| 1796 |
+
"license": "MIT"
|
| 1797 |
+
},
|
| 1798 |
+
"node_modules/unpipe": {
|
| 1799 |
+
"version": "1.0.0",
|
| 1800 |
+
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
| 1801 |
+
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
|
| 1802 |
+
"license": "MIT",
|
| 1803 |
+
"engines": {
|
| 1804 |
+
"node": ">= 0.8"
|
| 1805 |
+
}
|
| 1806 |
+
},
|
| 1807 |
+
"node_modules/utils-merge": {
|
| 1808 |
+
"version": "1.0.1",
|
| 1809 |
+
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
|
| 1810 |
+
"integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
|
| 1811 |
+
"license": "MIT",
|
| 1812 |
+
"engines": {
|
| 1813 |
+
"node": ">= 0.4.0"
|
| 1814 |
+
}
|
| 1815 |
+
},
|
| 1816 |
+
"node_modules/vary": {
|
| 1817 |
+
"version": "1.1.2",
|
| 1818 |
+
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
| 1819 |
+
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
|
| 1820 |
+
"license": "MIT",
|
| 1821 |
+
"engines": {
|
| 1822 |
+
"node": ">= 0.8"
|
| 1823 |
+
}
|
| 1824 |
+
}
|
| 1825 |
+
}
|
| 1826 |
+
}
|
backend/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "career-guidance-backend",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"description": "Backend API for Career Guidance Web App with Database and AI",
|
| 5 |
+
"main": "dist/server.js",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"dev": "tsx watch src/server.ts",
|
| 8 |
+
"build": "tsc",
|
| 9 |
+
"start": "node dist/server.js",
|
| 10 |
+
"type-check": "tsc --noEmit",
|
| 11 |
+
"prisma:generate": "prisma generate",
|
| 12 |
+
"prisma:migrate": "prisma migrate dev",
|
| 13 |
+
"prisma:studio": "prisma studio",
|
| 14 |
+
"setup:rag": "setup_rag.bat",
|
| 15 |
+
"test:rag": "python test_rag.py"
|
| 16 |
+
},
|
| 17 |
+
"keywords": [],
|
| 18 |
+
"author": "",
|
| 19 |
+
"license": "ISC",
|
| 20 |
+
"dependencies": {
|
| 21 |
+
"@google/generative-ai": "^0.21.0",
|
| 22 |
+
"@prisma/client": "^5.19.0",
|
| 23 |
+
"bcryptjs": "^2.4.3",
|
| 24 |
+
"cors": "^2.8.5",
|
| 25 |
+
"csv-parse": "^6.1.0",
|
| 26 |
+
"dotenv": "^16.4.5",
|
| 27 |
+
"express": "^4.18.2",
|
| 28 |
+
"jsonwebtoken": "^9.0.2"
|
| 29 |
+
},
|
| 30 |
+
"devDependencies": {
|
| 31 |
+
"@types/bcryptjs": "^2.4.6",
|
| 32 |
+
"@types/cors": "^2.8.17",
|
| 33 |
+
"@types/express": "^4.17.21",
|
| 34 |
+
"@types/jsonwebtoken": "^9.0.5",
|
| 35 |
+
"@types/node": "^20.10.0",
|
| 36 |
+
"prisma": "^5.19.0",
|
| 37 |
+
"tsx": "^4.7.0",
|
| 38 |
+
"typescript": "^5.3.3"
|
| 39 |
+
}
|
| 40 |
+
}
|
backend/prisma/schema.prisma
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
generator client {
|
| 2 |
+
provider = "prisma-client-js"
|
| 3 |
+
}
|
| 4 |
+
|
| 5 |
+
datasource db {
|
| 6 |
+
provider = "sqlite"
|
| 7 |
+
url = "file:./db.sqlite3?connection_limit=1&encoding=UTF-8"
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
model CustomUser {
|
| 11 |
+
id Int @id @default(autoincrement())
|
| 12 |
+
username String @unique
|
| 13 |
+
email String?
|
| 14 |
+
password String
|
| 15 |
+
phone String?
|
| 16 |
+
name String
|
| 17 |
+
grade String
|
| 18 |
+
age Int?
|
| 19 |
+
is_setup_complete Boolean @default(false)
|
| 20 |
+
created_at DateTime @default(now())
|
| 21 |
+
updated_at DateTime @updatedAt
|
| 22 |
+
last_login DateTime?
|
| 23 |
+
assessments Assessment[]
|
| 24 |
+
chat_messages ChatMessage[]
|
| 25 |
+
|
| 26 |
+
@@index([username])
|
| 27 |
+
@@index([email])
|
| 28 |
+
@@map("pathfinder_customuser")
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
model Assessment {
|
| 32 |
+
id Int @id @default(autoincrement())
|
| 33 |
+
user_id Int
|
| 34 |
+
user CustomUser @relation(fields: [user_id], references: [id], onDelete: Cascade)
|
| 35 |
+
assessment_number Int
|
| 36 |
+
status String @default("in_progress")
|
| 37 |
+
started_at DateTime @default(now())
|
| 38 |
+
completed_at DateTime?
|
| 39 |
+
test_responses TestResponse[]
|
| 40 |
+
chat_messages ChatMessage[]
|
| 41 |
+
|
| 42 |
+
@@unique([user_id, assessment_number])
|
| 43 |
+
@@index([user_id])
|
| 44 |
+
@@index([status])
|
| 45 |
+
@@index([completed_at])
|
| 46 |
+
@@map("pathfinder_assessment")
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
model TestResponse {
|
| 50 |
+
id Int @id @default(autoincrement())
|
| 51 |
+
assessment_id Int
|
| 52 |
+
assessment Assessment @relation(fields: [assessment_id], references: [id], onDelete: Cascade)
|
| 53 |
+
test_type String
|
| 54 |
+
responses String @default("{}")
|
| 55 |
+
started_at DateTime @default(now())
|
| 56 |
+
submitted_at DateTime?
|
| 57 |
+
is_completed Boolean @default(false)
|
| 58 |
+
current_question_index Int @default(0)
|
| 59 |
+
total_questions Int @default(0)
|
| 60 |
+
last_saved_at DateTime @updatedAt
|
| 61 |
+
|
| 62 |
+
@@unique([assessment_id, test_type])
|
| 63 |
+
@@index([assessment_id])
|
| 64 |
+
@@index([test_type])
|
| 65 |
+
@@map("pathfinder_testresponse")
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
model ChatMessage {
|
| 69 |
+
id Int @id @default(autoincrement())
|
| 70 |
+
user_id Int
|
| 71 |
+
user CustomUser @relation(fields: [user_id], references: [id], onDelete: Cascade)
|
| 72 |
+
assessment_id Int?
|
| 73 |
+
assessment Assessment? @relation(fields: [assessment_id], references: [id], onDelete: SetNull)
|
| 74 |
+
message_text String
|
| 75 |
+
sender String
|
| 76 |
+
created_at DateTime @default(now())
|
| 77 |
+
is_results_chat Boolean @default(false)
|
| 78 |
+
|
| 79 |
+
@@index([user_id, created_at])
|
| 80 |
+
@@index([assessment_id])
|
| 81 |
+
@@index([sender])
|
| 82 |
+
@@map("pathfinder_chatmessage")
|
| 83 |
+
}
|
| 84 |
+
|
backend/requirements.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
chromadb==1.3.4
|
| 2 |
+
google-ai-generativelanguage==0.9.0
|
| 3 |
+
google-api-core==2.28.1
|
| 4 |
+
google-auth==2.43.0
|
| 5 |
+
googleapis-common-protos==1.72.0
|
| 6 |
+
groq==0.34.1
|
| 7 |
+
huggingface-hub==0.36.0
|
| 8 |
+
langchain-chroma==1.0.0
|
| 9 |
+
langchain-core==1.0.5
|
| 10 |
+
langchain-google-genai==3.0.3
|
| 11 |
+
langchain-groq==1.0.1
|
| 12 |
+
langchain-huggingface==1.0.1
|
| 13 |
+
langchain-openai==1.0.3
|
| 14 |
+
langchain-text-splitters==1.0.0
|
| 15 |
+
langsmith==0.4.43
|
| 16 |
+
sentence-transformers==5.1.2
|
| 17 |
+
tiktoken==0.12.0
|
| 18 |
+
tokenizers==0.22.1
|
| 19 |
+
torch==2.9.1
|
| 20 |
+
transformers==4.57.1
|
| 21 |
+
python-dotenv==1.2.1
|
backend/src/middleware/auth.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Request, Response, NextFunction } from 'express';
|
| 2 |
+
import jwt from 'jsonwebtoken';
|
| 3 |
+
import { PrismaClient } from '@prisma/client';
|
| 4 |
+
|
| 5 |
+
const prisma = new PrismaClient();
|
| 6 |
+
|
| 7 |
+
// Extend Express Request type to include user
|
| 8 |
+
declare global {
|
| 9 |
+
namespace Express {
|
| 10 |
+
interface Request {
|
| 11 |
+
user?: {
|
| 12 |
+
id: number;
|
| 13 |
+
username: string;
|
| 14 |
+
name: string;
|
| 15 |
+
};
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
export const authenticateToken = async (
|
| 21 |
+
req: Request,
|
| 22 |
+
res: Response,
|
| 23 |
+
next: NextFunction
|
| 24 |
+
) => {
|
| 25 |
+
try {
|
| 26 |
+
const authHeader = req.headers['authorization'];
|
| 27 |
+
const token = authHeader && authHeader.split(' ')[1];
|
| 28 |
+
|
| 29 |
+
if (!token) {
|
| 30 |
+
return res.status(401).json({ error: 'Access token required' });
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
const decoded = jwt.verify(
|
| 34 |
+
token,
|
| 35 |
+
process.env.JWT_SECRET || 'your-secret-key'
|
| 36 |
+
) as { userId: number; username: string };
|
| 37 |
+
|
| 38 |
+
// Verify user exists in database
|
| 39 |
+
const user = await prisma.customUser.findUnique({
|
| 40 |
+
where: { id: decoded.userId },
|
| 41 |
+
select: { id: true, username: true, name: true },
|
| 42 |
+
});
|
| 43 |
+
|
| 44 |
+
if (!user) {
|
| 45 |
+
return res.status(403).json({ error: 'User not found' });
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
req.user = {
|
| 49 |
+
id: user.id,
|
| 50 |
+
username: user.username,
|
| 51 |
+
name: user.name,
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
next();
|
| 55 |
+
} catch (error: any) {
|
| 56 |
+
if (error.name === 'TokenExpiredError') {
|
| 57 |
+
return res.status(401).json({ error: 'Token expired' });
|
| 58 |
+
}
|
| 59 |
+
if (error.name === 'JsonWebTokenError') {
|
| 60 |
+
return res.status(403).json({ error: 'Invalid token' });
|
| 61 |
+
}
|
| 62 |
+
return res.status(500).json({ error: 'Authentication error' });
|
| 63 |
+
}
|
| 64 |
+
};
|
| 65 |
+
|
backend/src/routes/assessment.ts
ADDED
|
@@ -0,0 +1,725 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Router, Request, Response } from "express";
|
| 2 |
+
import { PrismaClient } from "@prisma/client";
|
| 3 |
+
import { authenticateToken } from "../middleware/auth";
|
| 4 |
+
import { GeminiService } from "../services/gemini";
|
| 5 |
+
import type { AssessmentPayload, AssessmentResponse } from "../types";
|
| 6 |
+
|
| 7 |
+
const router = Router();
|
| 8 |
+
const prisma = new PrismaClient();
|
| 9 |
+
|
| 10 |
+
// Lazy initialization of Gemini service
|
| 11 |
+
let geminiService: GeminiService | null = null;
|
| 12 |
+
|
| 13 |
+
function getGeminiService(): GeminiService {
|
| 14 |
+
if (!geminiService) {
|
| 15 |
+
const apiKey = process.env.GEMINI_API_KEY;
|
| 16 |
+
if (!apiKey) {
|
| 17 |
+
throw new Error(
|
| 18 |
+
"GEMINI_API_KEY is required. Please check your .env file."
|
| 19 |
+
);
|
| 20 |
+
}
|
| 21 |
+
geminiService = new GeminiService(apiKey);
|
| 22 |
+
}
|
| 23 |
+
return geminiService;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
// Helper to get user language type
|
| 27 |
+
type Language = "en" | "hi" | "te" | "ta" | "bn" | "gu";
|
| 28 |
+
|
| 29 |
+
// POST /api/assessment/start - Start a new assessment
|
| 30 |
+
router.post(
|
| 31 |
+
"/start",
|
| 32 |
+
authenticateToken,
|
| 33 |
+
async (req: Request, res: Response) => {
|
| 34 |
+
try {
|
| 35 |
+
const userId = req.user!.id;
|
| 36 |
+
|
| 37 |
+
// Check for existing in-progress assessment
|
| 38 |
+
const existingInProgress = await prisma.assessment.findFirst({
|
| 39 |
+
where: {
|
| 40 |
+
user_id: userId,
|
| 41 |
+
status: "in_progress",
|
| 42 |
+
},
|
| 43 |
+
});
|
| 44 |
+
|
| 45 |
+
if (existingInProgress) {
|
| 46 |
+
// Return the existing in-progress assessment
|
| 47 |
+
return res.status(200).json({
|
| 48 |
+
assessment_id: existingInProgress.id,
|
| 49 |
+
first_test_type: "riasec",
|
| 50 |
+
redirect_url: "/assessment/test/riasec/",
|
| 51 |
+
});
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// Find the next available assessment_number by checking the max
|
| 55 |
+
const maxAssessment = await prisma.assessment.findFirst({
|
| 56 |
+
where: { user_id: userId },
|
| 57 |
+
orderBy: { assessment_number: "desc" },
|
| 58 |
+
select: { assessment_number: true },
|
| 59 |
+
});
|
| 60 |
+
|
| 61 |
+
const nextAssessmentNumber = maxAssessment
|
| 62 |
+
? maxAssessment.assessment_number + 1
|
| 63 |
+
: 1;
|
| 64 |
+
|
| 65 |
+
// Create a new assessment
|
| 66 |
+
const assessment = await prisma.assessment.create({
|
| 67 |
+
data: {
|
| 68 |
+
user_id: userId,
|
| 69 |
+
assessment_number: nextAssessmentNumber,
|
| 70 |
+
status: "in_progress",
|
| 71 |
+
test_responses: {
|
| 72 |
+
create: {
|
| 73 |
+
test_type: "riasec",
|
| 74 |
+
total_questions: 0,
|
| 75 |
+
},
|
| 76 |
+
},
|
| 77 |
+
},
|
| 78 |
+
});
|
| 79 |
+
|
| 80 |
+
res.status(201).json({
|
| 81 |
+
assessment_id: assessment.id,
|
| 82 |
+
first_test_type: "riasec",
|
| 83 |
+
redirect_url: "/assessment/test/riasec/",
|
| 84 |
+
});
|
| 85 |
+
} catch (error: any) {
|
| 86 |
+
console.error("Error starting assessment:", error);
|
| 87 |
+
res.status(500).json({ error: "Failed to start assessment" });
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
);
|
| 91 |
+
|
| 92 |
+
// GET /api/assessment/test/:testType - Get test questions and progress
|
| 93 |
+
router.get(
|
| 94 |
+
"/test/:testType",
|
| 95 |
+
authenticateToken,
|
| 96 |
+
async (req: Request, res: Response) => {
|
| 97 |
+
try {
|
| 98 |
+
const userId = req.user!.id;
|
| 99 |
+
const { testType } = req.params;
|
| 100 |
+
const assessmentId = parseInt(req.query.assessmentId as string);
|
| 101 |
+
|
| 102 |
+
if (!["riasec", "values", "personal"].includes(testType)) {
|
| 103 |
+
return res.status(400).json({ error: "Invalid test type" });
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
let assessment;
|
| 107 |
+
if (assessmentId) {
|
| 108 |
+
assessment = await prisma.assessment.findFirst({
|
| 109 |
+
where: {
|
| 110 |
+
id: assessmentId,
|
| 111 |
+
user_id: userId,
|
| 112 |
+
},
|
| 113 |
+
});
|
| 114 |
+
} else {
|
| 115 |
+
assessment = await prisma.assessment.findFirst({
|
| 116 |
+
where: {
|
| 117 |
+
user_id: userId,
|
| 118 |
+
status: "in_progress",
|
| 119 |
+
},
|
| 120 |
+
});
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
if (!assessment) {
|
| 124 |
+
return res.status(404).json({ error: "Assessment not found" });
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
// Get or create test response
|
| 128 |
+
let testResponse = await prisma.testResponse.findUnique({
|
| 129 |
+
where: {
|
| 130 |
+
assessment_id_test_type: {
|
| 131 |
+
assessment_id: assessment.id,
|
| 132 |
+
test_type: testType,
|
| 133 |
+
},
|
| 134 |
+
},
|
| 135 |
+
});
|
| 136 |
+
|
| 137 |
+
if (!testResponse) {
|
| 138 |
+
testResponse = await prisma.testResponse.create({
|
| 139 |
+
data: {
|
| 140 |
+
assessment_id: assessment.id,
|
| 141 |
+
test_type: testType,
|
| 142 |
+
total_questions: 0,
|
| 143 |
+
},
|
| 144 |
+
});
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
// Parse saved responses
|
| 148 |
+
let savedAnswers = {};
|
| 149 |
+
try {
|
| 150 |
+
savedAnswers = JSON.parse(testResponse.responses || "{}");
|
| 151 |
+
} catch {
|
| 152 |
+
savedAnswers = {};
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
res.json({
|
| 156 |
+
test_type: testType,
|
| 157 |
+
test_response_id: testResponse.id,
|
| 158 |
+
current_question_index: testResponse.current_question_index,
|
| 159 |
+
total_questions: testResponse.total_questions,
|
| 160 |
+
saved_answers: savedAnswers,
|
| 161 |
+
is_completed: testResponse.is_completed,
|
| 162 |
+
});
|
| 163 |
+
} catch (error: any) {
|
| 164 |
+
console.error("Error getting test:", error);
|
| 165 |
+
res.status(500).json({ error: "Failed to get test data" });
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
);
|
| 169 |
+
|
| 170 |
+
// POST /api/assessment/save - Save test progress
|
| 171 |
+
router.post("/save", authenticateToken, async (req: Request, res: Response) => {
|
| 172 |
+
try {
|
| 173 |
+
const { test_response_id, answers, current_question_index } = req.body;
|
| 174 |
+
|
| 175 |
+
if (!test_response_id) {
|
| 176 |
+
return res.status(400).json({ error: "test_response_id is required" });
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
// Verify test response belongs to user
|
| 180 |
+
const testResponse = await prisma.testResponse.findUnique({
|
| 181 |
+
where: { id: test_response_id },
|
| 182 |
+
include: { assessment: true },
|
| 183 |
+
});
|
| 184 |
+
|
| 185 |
+
if (!testResponse || testResponse.assessment.user_id !== req.user!.id) {
|
| 186 |
+
return res.status(403).json({ error: "Unauthorized" });
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
// Update test response
|
| 190 |
+
await prisma.testResponse.update({
|
| 191 |
+
where: { id: test_response_id },
|
| 192 |
+
data: {
|
| 193 |
+
responses: JSON.stringify(answers || {}),
|
| 194 |
+
current_question_index: current_question_index || 0,
|
| 195 |
+
last_saved_at: new Date(),
|
| 196 |
+
},
|
| 197 |
+
});
|
| 198 |
+
|
| 199 |
+
res.json({ success: true, saved_at: new Date().toISOString() });
|
| 200 |
+
} catch (error: any) {
|
| 201 |
+
console.error("Error saving progress:", error);
|
| 202 |
+
res.status(500).json({ error: "Failed to save progress" });
|
| 203 |
+
}
|
| 204 |
+
});
|
| 205 |
+
|
| 206 |
+
// POST /api/assessment/submit - Submit completed test
|
| 207 |
+
router.post(
|
| 208 |
+
"/submit",
|
| 209 |
+
authenticateToken,
|
| 210 |
+
async (req: Request, res: Response) => {
|
| 211 |
+
try {
|
| 212 |
+
const { test_response_id, answers } = req.body;
|
| 213 |
+
|
| 214 |
+
if (!test_response_id || !answers) {
|
| 215 |
+
return res
|
| 216 |
+
.status(400)
|
| 217 |
+
.json({ error: "test_response_id and answers are required" });
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
// Verify test response belongs to user
|
| 221 |
+
const testResponse = await prisma.testResponse.findUnique({
|
| 222 |
+
where: { id: test_response_id },
|
| 223 |
+
include: { assessment: true },
|
| 224 |
+
});
|
| 225 |
+
|
| 226 |
+
if (!testResponse || testResponse.assessment.user_id !== req.user!.id) {
|
| 227 |
+
return res.status(403).json({ error: "Unauthorized" });
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
// Update test response as completed
|
| 231 |
+
await prisma.testResponse.update({
|
| 232 |
+
where: { id: test_response_id },
|
| 233 |
+
data: {
|
| 234 |
+
responses: JSON.stringify(answers),
|
| 235 |
+
is_completed: true,
|
| 236 |
+
submitted_at: new Date(),
|
| 237 |
+
},
|
| 238 |
+
});
|
| 239 |
+
|
| 240 |
+
const assessment = testResponse.assessment;
|
| 241 |
+
|
| 242 |
+
// Check if all tests are completed
|
| 243 |
+
const allTestResponses = await prisma.testResponse.findMany({
|
| 244 |
+
where: { assessment_id: assessment.id },
|
| 245 |
+
});
|
| 246 |
+
|
| 247 |
+
const testOrder = ["riasec", "values", "personal"];
|
| 248 |
+
const currentIndex = testOrder.indexOf(testResponse.test_type);
|
| 249 |
+
|
| 250 |
+
if (currentIndex < testOrder.length - 1) {
|
| 251 |
+
// Create next test response
|
| 252 |
+
const nextTestType = testOrder[currentIndex + 1];
|
| 253 |
+
await prisma.testResponse.upsert({
|
| 254 |
+
where: {
|
| 255 |
+
assessment_id_test_type: {
|
| 256 |
+
assessment_id: assessment.id,
|
| 257 |
+
test_type: nextTestType,
|
| 258 |
+
},
|
| 259 |
+
},
|
| 260 |
+
create: {
|
| 261 |
+
assessment_id: assessment.id,
|
| 262 |
+
test_type: nextTestType,
|
| 263 |
+
total_questions: 0,
|
| 264 |
+
},
|
| 265 |
+
update: {},
|
| 266 |
+
});
|
| 267 |
+
|
| 268 |
+
return res.json({
|
| 269 |
+
success: true,
|
| 270 |
+
next_test_type: nextTestType,
|
| 271 |
+
redirect_url: `/assessment/test/${nextTestType}/`,
|
| 272 |
+
});
|
| 273 |
+
} else {
|
| 274 |
+
// All tests completed
|
| 275 |
+
await prisma.assessment.update({
|
| 276 |
+
where: { id: assessment.id },
|
| 277 |
+
data: {
|
| 278 |
+
status: "completed",
|
| 279 |
+
completed_at: new Date(),
|
| 280 |
+
},
|
| 281 |
+
});
|
| 282 |
+
|
| 283 |
+
return res.json({
|
| 284 |
+
success: true,
|
| 285 |
+
next_test_type: null,
|
| 286 |
+
redirect_url: `/assessment/processing/${assessment.id}/`,
|
| 287 |
+
});
|
| 288 |
+
}
|
| 289 |
+
} catch (error: any) {
|
| 290 |
+
console.error("Error submitting test:", error);
|
| 291 |
+
res.status(500).json({ error: "Failed to submit test" });
|
| 292 |
+
}
|
| 293 |
+
}
|
| 294 |
+
);
|
| 295 |
+
|
| 296 |
+
// POST /api/assessment/complete - Process assessment and generate recommendations
|
| 297 |
+
router.post(
|
| 298 |
+
"/complete",
|
| 299 |
+
authenticateToken,
|
| 300 |
+
async (req: Request, res: Response) => {
|
| 301 |
+
try {
|
| 302 |
+
const payload: AssessmentPayload = req.body;
|
| 303 |
+
const userId = req.user!.id;
|
| 304 |
+
|
| 305 |
+
// Validate payload
|
| 306 |
+
if (
|
| 307 |
+
!payload.userProfile ||
|
| 308 |
+
!payload.tests ||
|
| 309 |
+
!Array.isArray(payload.tests)
|
| 310 |
+
) {
|
| 311 |
+
return res.status(400).json({
|
| 312 |
+
error: "Invalid payload. Required: userProfile, tests (array)",
|
| 313 |
+
});
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
if (payload.tests.length === 0) {
|
| 317 |
+
return res.status(400).json({
|
| 318 |
+
error: "At least one test result is required",
|
| 319 |
+
});
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
console.log(
|
| 323 |
+
`Processing assessment for user: ${payload.userProfile.name}`
|
| 324 |
+
);
|
| 325 |
+
|
| 326 |
+
// Get or verify assessment exists
|
| 327 |
+
const assessment = await prisma.assessment.findFirst({
|
| 328 |
+
where: {
|
| 329 |
+
id: payload.assessmentId,
|
| 330 |
+
user_id: userId,
|
| 331 |
+
},
|
| 332 |
+
include: {
|
| 333 |
+
test_responses: true,
|
| 334 |
+
},
|
| 335 |
+
});
|
| 336 |
+
|
| 337 |
+
if (!assessment) {
|
| 338 |
+
return res.status(404).json({ error: "Assessment not found" });
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
// Save/update test responses to database
|
| 342 |
+
for (const test of payload.tests) {
|
| 343 |
+
await prisma.testResponse.upsert({
|
| 344 |
+
where: {
|
| 345 |
+
assessment_id_test_type: {
|
| 346 |
+
assessment_id: assessment.id,
|
| 347 |
+
test_type: test.type,
|
| 348 |
+
},
|
| 349 |
+
},
|
| 350 |
+
create: {
|
| 351 |
+
assessment_id: assessment.id,
|
| 352 |
+
test_type: test.type,
|
| 353 |
+
responses: JSON.stringify(test.answers),
|
| 354 |
+
is_completed: true,
|
| 355 |
+
submitted_at: new Date(),
|
| 356 |
+
total_questions: Object.keys(test.answers).length,
|
| 357 |
+
},
|
| 358 |
+
update: {
|
| 359 |
+
responses: JSON.stringify(test.answers),
|
| 360 |
+
is_completed: true,
|
| 361 |
+
submitted_at: new Date(),
|
| 362 |
+
total_questions: Object.keys(test.answers).length,
|
| 363 |
+
},
|
| 364 |
+
});
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
// Mark assessment as completed
|
| 368 |
+
await prisma.assessment.update({
|
| 369 |
+
where: { id: assessment.id },
|
| 370 |
+
data: {
|
| 371 |
+
status: "completed",
|
| 372 |
+
completed_at: new Date(),
|
| 373 |
+
},
|
| 374 |
+
});
|
| 375 |
+
|
| 376 |
+
// Calculate RIASEC scores and fetch matching careers
|
| 377 |
+
let riasecScores = null;
|
| 378 |
+
let matchingCareers: string[] = [];
|
| 379 |
+
|
| 380 |
+
const riasecTest = payload.tests.find((test) => test.type === "riasec");
|
| 381 |
+
if (riasecTest) {
|
| 382 |
+
const { calculateRIASECScore, getCareersByRIASECCode } = await import(
|
| 383 |
+
"../services/riasecService"
|
| 384 |
+
);
|
| 385 |
+
// Convert numeric keys to strings for calculateRIASECScore
|
| 386 |
+
const answersWithStringKeys: {
|
| 387 |
+
[questionId: string]: string | string[];
|
| 388 |
+
} = {};
|
| 389 |
+
Object.entries(riasecTest.answers).forEach(([key, value]) => {
|
| 390 |
+
answersWithStringKeys[key] = value;
|
| 391 |
+
});
|
| 392 |
+
riasecScores = calculateRIASECScore(answersWithStringKeys);
|
| 393 |
+
matchingCareers = getCareersByRIASECCode(riasecScores.top3);
|
| 394 |
+
console.log(
|
| 395 |
+
`RIASEC Top 3: ${riasecScores.top3}, Found ${matchingCareers.length} matching careers`
|
| 396 |
+
);
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
// Generate recommendations using Gemini
|
| 400 |
+
// Use better retry defaults - the retry logic will auto-increase attempts for 503 errors
|
| 401 |
+
const recommendations = await getGeminiService().generateRecommendations(
|
| 402 |
+
payload,
|
| 403 |
+
{
|
| 404 |
+
maxAttempts: parseInt(process.env.MAX_RETRY_ATTEMPTS || "5"), // Increased default
|
| 405 |
+
initialDelay: parseInt(process.env.RETRY_DELAY_MS || "2000"), // Increased default
|
| 406 |
+
},
|
| 407 |
+
riasecScores,
|
| 408 |
+
matchingCareers
|
| 409 |
+
);
|
| 410 |
+
|
| 411 |
+
// Generate and save initial chatbot greeting message immediately
|
| 412 |
+
// This ensures it's ready when user clicks "View Results"
|
| 413 |
+
try {
|
| 414 |
+
const user = await prisma.customUser.findUnique({
|
| 415 |
+
where: { id: userId },
|
| 416 |
+
});
|
| 417 |
+
|
| 418 |
+
// Build assessment summary for chatbot with filtered recommendations
|
| 419 |
+
const testResponses = payload.tests.map((test) => ({
|
| 420 |
+
type: test.type,
|
| 421 |
+
answers: test.answers,
|
| 422 |
+
}));
|
| 423 |
+
|
| 424 |
+
const summaryParts = [
|
| 425 |
+
`Assessment #${assessment.assessment_number} completed.`,
|
| 426 |
+
`Student: ${user?.name || "Student"}, Grade: ${
|
| 427 |
+
user?.grade || "N/A"
|
| 428 |
+
}, Age: ${user?.age || "N/A"}`,
|
| 429 |
+
];
|
| 430 |
+
|
| 431 |
+
// Add RIASEC scores and matching careers to summary
|
| 432 |
+
if (riasecScores) {
|
| 433 |
+
summaryParts.push(`\nRIASEC Top 3: ${riasecScores.top3}`);
|
| 434 |
+
if (matchingCareers && matchingCareers.length > 0) {
|
| 435 |
+
summaryParts.push(
|
| 436 |
+
`\nMatching Careers (${matchingCareers.length}): ${matchingCareers
|
| 437 |
+
.slice(0, 10)
|
| 438 |
+
.join(", ")}${matchingCareers.length > 10 ? "..." : ""}`
|
| 439 |
+
);
|
| 440 |
+
}
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
summaryParts.push(`\nTest Responses:`);
|
| 444 |
+
testResponses.forEach((tr) => {
|
| 445 |
+
summaryParts.push(`\n${tr.type.toUpperCase()} Test:`);
|
| 446 |
+
Object.entries(tr.answers).forEach(([qId, answer]) => {
|
| 447 |
+
const answerStr = Array.isArray(answer)
|
| 448 |
+
? answer.join(", ")
|
| 449 |
+
: String(answer);
|
| 450 |
+
summaryParts.push(` Question ${qId}: ${answerStr}`);
|
| 451 |
+
});
|
| 452 |
+
});
|
| 453 |
+
|
| 454 |
+
// Add the filtered recommendations to the summary
|
| 455 |
+
summaryParts.push(`\n\nCareer Recommendations (from matching list):`);
|
| 456 |
+
recommendations.recommendations.forEach((rec, idx) => {
|
| 457 |
+
summaryParts.push(`\n${idx + 1}. ${rec.title}`);
|
| 458 |
+
summaryParts.push(` Reason: ${rec.reason}`);
|
| 459 |
+
summaryParts.push(` Next Steps: ${rec.next_steps.join(", ")}`);
|
| 460 |
+
});
|
| 461 |
+
|
| 462 |
+
const assessmentSummary = summaryParts.join("\n");
|
| 463 |
+
|
| 464 |
+
// Check if initial greeting already exists for this assessment to prevent duplicates
|
| 465 |
+
const existingInitialMessage = await prisma.chatMessage.findFirst({
|
| 466 |
+
where: {
|
| 467 |
+
user_id: userId,
|
| 468 |
+
assessment_id: assessment.id,
|
| 469 |
+
sender: "bot",
|
| 470 |
+
is_results_chat: true,
|
| 471 |
+
},
|
| 472 |
+
});
|
| 473 |
+
|
| 474 |
+
// Only create initial greeting if it doesn't already exist
|
| 475 |
+
if (!existingInitialMessage) {
|
| 476 |
+
// Generate initial greeting (language is validated to be one of the supported types)
|
| 477 |
+
const userLanguage = (payload.userProfile.language || "en") as
|
| 478 |
+
| "en"
|
| 479 |
+
| "hi"
|
| 480 |
+
| "te"
|
| 481 |
+
| "ta"
|
| 482 |
+
| "bn"
|
| 483 |
+
| "gu";
|
| 484 |
+
const aiMessage = await getGeminiService().generateInitialGreeting(
|
| 485 |
+
assessmentSummary,
|
| 486 |
+
userLanguage
|
| 487 |
+
);
|
| 488 |
+
|
| 489 |
+
// Save initial bot message to database
|
| 490 |
+
await prisma.chatMessage.create({
|
| 491 |
+
data: {
|
| 492 |
+
user_id: userId,
|
| 493 |
+
assessment_id: assessment.id,
|
| 494 |
+
message_text: aiMessage.reply,
|
| 495 |
+
sender: "bot",
|
| 496 |
+
is_results_chat: true,
|
| 497 |
+
},
|
| 498 |
+
});
|
| 499 |
+
}
|
| 500 |
+
} catch (greetingError) {
|
| 501 |
+
// Don't fail the whole request if greeting generation fails
|
| 502 |
+
console.error("Failed to generate initial greeting:", greetingError);
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
const response: AssessmentResponse = {
|
| 506 |
+
recommendations: recommendations.recommendations,
|
| 507 |
+
summary: recommendations.summary,
|
| 508 |
+
smsMessage: recommendations.smsMessage,
|
| 509 |
+
};
|
| 510 |
+
|
| 511 |
+
console.log(`Assessment completed for user: ${payload.userProfile.name}`);
|
| 512 |
+
|
| 513 |
+
res.json(response);
|
| 514 |
+
} catch (error: any) {
|
| 515 |
+
console.error("Error processing assessment:", error);
|
| 516 |
+
|
| 517 |
+
// Return fallback response
|
| 518 |
+
const fallback: AssessmentResponse = {
|
| 519 |
+
recommendations: [
|
| 520 |
+
{
|
| 521 |
+
title: "Career Exploration",
|
| 522 |
+
confidence: 0.7,
|
| 523 |
+
reason: "Continue exploring different fields",
|
| 524 |
+
next_steps: ["Research careers", "Talk to professionals"],
|
| 525 |
+
},
|
| 526 |
+
],
|
| 527 |
+
summary:
|
| 528 |
+
"Your assessment has been processed. We recommend exploring various career paths.",
|
| 529 |
+
};
|
| 530 |
+
|
| 531 |
+
res.status(500).json(fallback);
|
| 532 |
+
}
|
| 533 |
+
}
|
| 534 |
+
);
|
| 535 |
+
|
| 536 |
+
// GET /api/assessment/history - Get assessment history
|
| 537 |
+
router.get(
|
| 538 |
+
"/history",
|
| 539 |
+
authenticateToken,
|
| 540 |
+
async (req: Request, res: Response) => {
|
| 541 |
+
try {
|
| 542 |
+
const userId = req.user!.id;
|
| 543 |
+
|
| 544 |
+
const assessments = await prisma.assessment.findMany({
|
| 545 |
+
where: {
|
| 546 |
+
user_id: userId,
|
| 547 |
+
status: "completed",
|
| 548 |
+
},
|
| 549 |
+
orderBy: {
|
| 550 |
+
completed_at: "desc", // Most recent first (will be re-sorted below)
|
| 551 |
+
},
|
| 552 |
+
include: {
|
| 553 |
+
test_responses: {
|
| 554 |
+
where: { is_completed: true },
|
| 555 |
+
},
|
| 556 |
+
chat_messages: {
|
| 557 |
+
select: {
|
| 558 |
+
id: true,
|
| 559 |
+
},
|
| 560 |
+
},
|
| 561 |
+
},
|
| 562 |
+
});
|
| 563 |
+
|
| 564 |
+
// Sort: assessments with chat messages first, then by completed_at desc
|
| 565 |
+
const sortedAssessments = assessments.sort((a, b) => {
|
| 566 |
+
const aHasChat = a.chat_messages.length > 0;
|
| 567 |
+
const bHasChat = b.chat_messages.length > 0;
|
| 568 |
+
|
| 569 |
+
// If one has chat and the other doesn't, prioritize the one with chat
|
| 570 |
+
if (aHasChat && !bHasChat) return -1;
|
| 571 |
+
if (!aHasChat && bHasChat) return 1;
|
| 572 |
+
|
| 573 |
+
// If both have chat or both don't, sort by completed_at desc
|
| 574 |
+
return b.completed_at!.getTime() - a.completed_at!.getTime();
|
| 575 |
+
});
|
| 576 |
+
|
| 577 |
+
const assessmentsData = sortedAssessments.map((assessment) => ({
|
| 578 |
+
id: assessment.id,
|
| 579 |
+
assessment_number: assessment.assessment_number,
|
| 580 |
+
completed_at: assessment.completed_at,
|
| 581 |
+
status: assessment.status,
|
| 582 |
+
test_count: assessment.test_responses.length,
|
| 583 |
+
has_chat: assessment.chat_messages.length > 0,
|
| 584 |
+
}));
|
| 585 |
+
|
| 586 |
+
res.json({ completed_assessments: assessmentsData });
|
| 587 |
+
} catch (error: any) {
|
| 588 |
+
console.error("Error getting history:", error);
|
| 589 |
+
res.status(500).json({ error: "Failed to get assessment history" });
|
| 590 |
+
}
|
| 591 |
+
}
|
| 592 |
+
);
|
| 593 |
+
|
| 594 |
+
// DELETE /api/assessment/:id - Delete an assessment and all related data
|
| 595 |
+
router.delete(
|
| 596 |
+
"/:id",
|
| 597 |
+
authenticateToken,
|
| 598 |
+
async (req: Request, res: Response) => {
|
| 599 |
+
try {
|
| 600 |
+
const userId = req.user!.id;
|
| 601 |
+
const assessmentId = parseInt(req.params.id);
|
| 602 |
+
|
| 603 |
+
if (isNaN(assessmentId)) {
|
| 604 |
+
return res.status(400).json({ error: "Invalid assessment ID" });
|
| 605 |
+
}
|
| 606 |
+
|
| 607 |
+
// Verify assessment belongs to user
|
| 608 |
+
const assessment = await prisma.assessment.findFirst({
|
| 609 |
+
where: {
|
| 610 |
+
id: assessmentId,
|
| 611 |
+
user_id: userId,
|
| 612 |
+
},
|
| 613 |
+
});
|
| 614 |
+
|
| 615 |
+
if (!assessment) {
|
| 616 |
+
return res.status(404).json({ error: "Assessment not found" });
|
| 617 |
+
}
|
| 618 |
+
|
| 619 |
+
// Delete all related data (cascade deletes will handle test_responses and chat_messages)
|
| 620 |
+
await prisma.assessment.delete({
|
| 621 |
+
where: { id: assessmentId },
|
| 622 |
+
});
|
| 623 |
+
|
| 624 |
+
res.json({
|
| 625 |
+
success: true,
|
| 626 |
+
message: "Assessment deleted successfully",
|
| 627 |
+
});
|
| 628 |
+
} catch (error: any) {
|
| 629 |
+
console.error("Error deleting assessment:", error);
|
| 630 |
+
res.status(500).json({ error: "Failed to delete assessment" });
|
| 631 |
+
}
|
| 632 |
+
}
|
| 633 |
+
);
|
| 634 |
+
|
| 635 |
+
// GET /api/assessment/:id/responses - Get detailed responses for an assessment
|
| 636 |
+
router.get(
|
| 637 |
+
"/:id/responses",
|
| 638 |
+
authenticateToken,
|
| 639 |
+
async (req: Request, res: Response) => {
|
| 640 |
+
try {
|
| 641 |
+
const userId = req.user!.id;
|
| 642 |
+
const assessmentId = parseInt(req.params.id);
|
| 643 |
+
|
| 644 |
+
const assessment = await prisma.assessment.findFirst({
|
| 645 |
+
where: {
|
| 646 |
+
id: assessmentId,
|
| 647 |
+
user_id: userId,
|
| 648 |
+
},
|
| 649 |
+
include: {
|
| 650 |
+
test_responses: {
|
| 651 |
+
where: { is_completed: true },
|
| 652 |
+
},
|
| 653 |
+
},
|
| 654 |
+
});
|
| 655 |
+
|
| 656 |
+
if (!assessment) {
|
| 657 |
+
return res.status(404).json({ error: "Assessment not found" });
|
| 658 |
+
}
|
| 659 |
+
|
| 660 |
+
const testResponses = assessment.test_responses.map((tr) => {
|
| 661 |
+
let answers: { [key: string]: any } = {};
|
| 662 |
+
try {
|
| 663 |
+
answers = JSON.parse(tr.responses || "{}");
|
| 664 |
+
} catch (e) {
|
| 665 |
+
console.error("Error parsing test responses:", e);
|
| 666 |
+
answers = {};
|
| 667 |
+
}
|
| 668 |
+
|
| 669 |
+
// Clean answers - remove any chat message content that might have been accidentally included
|
| 670 |
+
const cleanedAnswers: { [key: string]: string | string[] } = {};
|
| 671 |
+
const chatPhrases = [
|
| 672 |
+
"great job on the assessment",
|
| 673 |
+
"career paths for you",
|
| 674 |
+
"exciting career paths",
|
| 675 |
+
"Based on your results",
|
| 676 |
+
"Hey",
|
| 677 |
+
"free to ask me any questions",
|
| 678 |
+
];
|
| 679 |
+
|
| 680 |
+
for (const [key, value] of Object.entries(answers)) {
|
| 681 |
+
if (!value) continue;
|
| 682 |
+
|
| 683 |
+
const valueStr = Array.isArray(value)
|
| 684 |
+
? value.join(" ")
|
| 685 |
+
: String(value);
|
| 686 |
+
const isChatMessage = chatPhrases.some((phrase) =>
|
| 687 |
+
valueStr.toLowerCase().includes(phrase.toLowerCase())
|
| 688 |
+
);
|
| 689 |
+
|
| 690 |
+
if (!isChatMessage && valueStr.trim().length > 0) {
|
| 691 |
+
// Clean up the value - remove any appended chat content
|
| 692 |
+
let cleanValue: string | string[] = value as string | string[];
|
| 693 |
+
if (typeof value === "string") {
|
| 694 |
+
const chatGreetingPattern =
|
| 695 |
+
/(?:Hey\s+[^,]+,?\s*)?(?:Grade:\s*\w+,?\s*)?(?:Age:\s*\d+,?\s*)?(?:great job on the assessment[^]*?career paths[^]*?)/i;
|
| 696 |
+
const cleaned = value.replace(chatGreetingPattern, "").trim();
|
| 697 |
+
cleanValue = cleaned || value; // Use original if cleaning removes everything
|
| 698 |
+
}
|
| 699 |
+
cleanedAnswers[key] = cleanValue;
|
| 700 |
+
}
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
return {
|
| 704 |
+
test_type: tr.test_type,
|
| 705 |
+
answers: cleanedAnswers,
|
| 706 |
+
submitted_at: tr.submitted_at,
|
| 707 |
+
};
|
| 708 |
+
});
|
| 709 |
+
|
| 710 |
+
res.json({
|
| 711 |
+
assessment: {
|
| 712 |
+
id: assessment.id,
|
| 713 |
+
assessment_number: assessment.assessment_number,
|
| 714 |
+
completed_at: assessment.completed_at,
|
| 715 |
+
},
|
| 716 |
+
test_responses: testResponses,
|
| 717 |
+
});
|
| 718 |
+
} catch (error: any) {
|
| 719 |
+
console.error("Error getting responses:", error);
|
| 720 |
+
res.status(500).json({ error: "Failed to get assessment responses" });
|
| 721 |
+
}
|
| 722 |
+
}
|
| 723 |
+
);
|
| 724 |
+
|
| 725 |
+
export default router;
|
backend/src/routes/auth.ts
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Router, Request, Response } from "express";
|
| 2 |
+
import jwt, { SignOptions } from "jsonwebtoken";
|
| 3 |
+
import bcrypt from "bcryptjs";
|
| 4 |
+
import { PrismaClient } from "@prisma/client";
|
| 5 |
+
import { authenticateToken } from "../middleware/auth";
|
| 6 |
+
|
| 7 |
+
const router = Router();
|
| 8 |
+
const prisma = new PrismaClient();
|
| 9 |
+
const JWT_SECRET: string = process.env.JWT_SECRET || "your-secret-key";
|
| 10 |
+
const JWT_ACCESS_EXPIRES_IN: string | number =
|
| 11 |
+
process.env.JWT_ACCESS_EXPIRES_IN || "1h";
|
| 12 |
+
const JWT_REFRESH_EXPIRES_IN: string | number =
|
| 13 |
+
process.env.JWT_REFRESH_EXPIRES_IN || "7d";
|
| 14 |
+
|
| 15 |
+
// Generate tokens
|
| 16 |
+
function generateTokens(userId: number, username: string) {
|
| 17 |
+
const accessOptions = {
|
| 18 |
+
expiresIn: JWT_ACCESS_EXPIRES_IN,
|
| 19 |
+
} as SignOptions;
|
| 20 |
+
const refreshOptions = {
|
| 21 |
+
expiresIn: JWT_REFRESH_EXPIRES_IN,
|
| 22 |
+
} as SignOptions;
|
| 23 |
+
|
| 24 |
+
const accessToken = jwt.sign({ userId, username }, JWT_SECRET, accessOptions);
|
| 25 |
+
const refreshToken = jwt.sign(
|
| 26 |
+
{ userId, username, type: "refresh" },
|
| 27 |
+
JWT_SECRET,
|
| 28 |
+
refreshOptions
|
| 29 |
+
);
|
| 30 |
+
return { accessToken, refreshToken };
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
// POST /api/auth/setup - User registration
|
| 34 |
+
router.post("/setup", async (req: Request, res: Response) => {
|
| 35 |
+
try {
|
| 36 |
+
const {
|
| 37 |
+
username,
|
| 38 |
+
password,
|
| 39 |
+
name,
|
| 40 |
+
grade,
|
| 41 |
+
age,
|
| 42 |
+
email,
|
| 43 |
+
phone,
|
| 44 |
+
preferred_language,
|
| 45 |
+
} = req.body;
|
| 46 |
+
|
| 47 |
+
// Validate required fields
|
| 48 |
+
if (!username || !password || !name || !grade) {
|
| 49 |
+
return res.status(400).json({
|
| 50 |
+
error: "Missing required fields: username, password, name, grade",
|
| 51 |
+
details: {
|
| 52 |
+
username: !username ? "Username is required" : undefined,
|
| 53 |
+
password: !password ? "Password is required" : undefined,
|
| 54 |
+
name: !name ? "Name is required" : undefined,
|
| 55 |
+
grade: !grade ? "Grade is required" : undefined,
|
| 56 |
+
},
|
| 57 |
+
});
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
// Check if username exists
|
| 61 |
+
const existingUser = await prisma.customUser.findUnique({
|
| 62 |
+
where: { username },
|
| 63 |
+
});
|
| 64 |
+
|
| 65 |
+
if (existingUser) {
|
| 66 |
+
return res.status(400).json({ error: "Username already exists" });
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
// Hash password
|
| 70 |
+
const hashedPassword = await bcrypt.hash(password, 10);
|
| 71 |
+
|
| 72 |
+
// Parse age - handle both string and number
|
| 73 |
+
let ageValue: number | null = null;
|
| 74 |
+
if (age) {
|
| 75 |
+
const parsedAge = typeof age === "string" ? parseInt(age) : age;
|
| 76 |
+
if (!isNaN(parsedAge) && parsedAge > 0) {
|
| 77 |
+
ageValue = parsedAge;
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// Create user
|
| 82 |
+
const user = await prisma.customUser.create({
|
| 83 |
+
data: {
|
| 84 |
+
username,
|
| 85 |
+
password: hashedPassword,
|
| 86 |
+
name,
|
| 87 |
+
grade,
|
| 88 |
+
age: ageValue,
|
| 89 |
+
email: email || null,
|
| 90 |
+
phone: phone || null,
|
| 91 |
+
is_setup_complete: true,
|
| 92 |
+
},
|
| 93 |
+
});
|
| 94 |
+
|
| 95 |
+
// Generate tokens
|
| 96 |
+
const { accessToken, refreshToken } = generateTokens(
|
| 97 |
+
user.id,
|
| 98 |
+
user.username
|
| 99 |
+
);
|
| 100 |
+
|
| 101 |
+
// Return user data (without password)
|
| 102 |
+
const { password: _, ...userWithoutPassword } = user;
|
| 103 |
+
|
| 104 |
+
res.status(201).json({
|
| 105 |
+
user: userWithoutPassword,
|
| 106 |
+
access: accessToken,
|
| 107 |
+
refresh: refreshToken,
|
| 108 |
+
});
|
| 109 |
+
} catch (error: any) {
|
| 110 |
+
console.error("Setup error:", error);
|
| 111 |
+
res.status(500).json({ error: "Failed to create user account" });
|
| 112 |
+
}
|
| 113 |
+
});
|
| 114 |
+
|
| 115 |
+
// POST /api/auth/login
|
| 116 |
+
router.post("/login", async (req: Request, res: Response) => {
|
| 117 |
+
try {
|
| 118 |
+
const { username, password } = req.body;
|
| 119 |
+
|
| 120 |
+
if (!username || !password) {
|
| 121 |
+
return res.status(400).json({
|
| 122 |
+
error: "Username and password required",
|
| 123 |
+
});
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
// Find user
|
| 127 |
+
const user = await prisma.customUser.findUnique({
|
| 128 |
+
where: { username },
|
| 129 |
+
});
|
| 130 |
+
|
| 131 |
+
if (!user) {
|
| 132 |
+
return res.status(401).json({ error: "Invalid credentials" });
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
// Verify password
|
| 136 |
+
const isValidPassword = await bcrypt.compare(password, user.password);
|
| 137 |
+
if (!isValidPassword) {
|
| 138 |
+
return res.status(401).json({ error: "Invalid credentials" });
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
// Update last login
|
| 142 |
+
await prisma.customUser.update({
|
| 143 |
+
where: { id: user.id },
|
| 144 |
+
data: { last_login: new Date() },
|
| 145 |
+
});
|
| 146 |
+
|
| 147 |
+
// Generate tokens
|
| 148 |
+
const { accessToken, refreshToken } = generateTokens(
|
| 149 |
+
user.id,
|
| 150 |
+
user.username
|
| 151 |
+
);
|
| 152 |
+
|
| 153 |
+
// Return user data (without password)
|
| 154 |
+
const { password: _, ...userWithoutPassword } = user;
|
| 155 |
+
|
| 156 |
+
res.json({
|
| 157 |
+
user: userWithoutPassword,
|
| 158 |
+
access: accessToken,
|
| 159 |
+
refresh: refreshToken,
|
| 160 |
+
});
|
| 161 |
+
} catch (error: any) {
|
| 162 |
+
console.error("Login error:", error);
|
| 163 |
+
res.status(500).json({ error: "Failed to login" });
|
| 164 |
+
}
|
| 165 |
+
});
|
| 166 |
+
|
| 167 |
+
// POST /api/auth/logout
|
| 168 |
+
router.post(
|
| 169 |
+
"/logout",
|
| 170 |
+
authenticateToken,
|
| 171 |
+
async (req: Request, res: Response) => {
|
| 172 |
+
try {
|
| 173 |
+
// In a production app, you might want to blacklist the refresh token
|
| 174 |
+
// For now, we'll just return success
|
| 175 |
+
res.json({
|
| 176 |
+
success: true,
|
| 177 |
+
message: "Logged out successfully",
|
| 178 |
+
});
|
| 179 |
+
} catch (error: any) {
|
| 180 |
+
console.error("Logout error:", error);
|
| 181 |
+
res.status(500).json({ error: "Failed to logout" });
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
);
|
| 185 |
+
|
| 186 |
+
// POST /api/auth/token/refresh
|
| 187 |
+
router.post("/token/refresh", async (req: Request, res: Response) => {
|
| 188 |
+
try {
|
| 189 |
+
const { refresh } = req.body;
|
| 190 |
+
|
| 191 |
+
if (!refresh) {
|
| 192 |
+
return res.status(400).json({ error: "Refresh token required" });
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
const decoded = jwt.verify(refresh, JWT_SECRET) as {
|
| 196 |
+
userId: number;
|
| 197 |
+
username: string;
|
| 198 |
+
type?: string;
|
| 199 |
+
};
|
| 200 |
+
|
| 201 |
+
if (decoded.type !== "refresh") {
|
| 202 |
+
return res.status(403).json({ error: "Invalid token type" });
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
// Verify user exists
|
| 206 |
+
const user = await prisma.customUser.findUnique({
|
| 207 |
+
where: { id: decoded.userId },
|
| 208 |
+
});
|
| 209 |
+
|
| 210 |
+
if (!user) {
|
| 211 |
+
return res.status(403).json({ error: "User not found" });
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
// Generate new access token
|
| 215 |
+
const accessOptions = {
|
| 216 |
+
expiresIn: JWT_ACCESS_EXPIRES_IN,
|
| 217 |
+
} as SignOptions;
|
| 218 |
+
const accessToken = jwt.sign(
|
| 219 |
+
{ userId: user.id, username: user.username },
|
| 220 |
+
JWT_SECRET,
|
| 221 |
+
accessOptions
|
| 222 |
+
);
|
| 223 |
+
|
| 224 |
+
res.json({ access: accessToken });
|
| 225 |
+
} catch (error: any) {
|
| 226 |
+
if (error.name === "TokenExpiredError") {
|
| 227 |
+
return res.status(401).json({ error: "Refresh token expired" });
|
| 228 |
+
}
|
| 229 |
+
return res.status(403).json({ error: "Invalid refresh token" });
|
| 230 |
+
}
|
| 231 |
+
});
|
| 232 |
+
|
| 233 |
+
export default router;
|
backend/src/routes/chat.ts
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Router, Request, Response } from 'express';
|
| 2 |
+
import { PrismaClient } from '@prisma/client';
|
| 3 |
+
import { authenticateToken } from '../middleware/auth';
|
| 4 |
+
import { RAGChatService } from '../services/ragChat';
|
| 5 |
+
import { GeminiService } from '../services/gemini';
|
| 6 |
+
import type {
|
| 7 |
+
ChatStartRequest,
|
| 8 |
+
ChatMessageRequest,
|
| 9 |
+
ChatMessageResponse,
|
| 10 |
+
} from '../types';
|
| 11 |
+
|
| 12 |
+
const router = Router();
|
| 13 |
+
const prisma = new PrismaClient({
|
| 14 |
+
log: ['error', 'warn'],
|
| 15 |
+
// Ensure UTF-8 for all database operations
|
| 16 |
+
});
|
| 17 |
+
|
| 18 |
+
// Lazy initialization of services
|
| 19 |
+
let ragService: RAGChatService | null = null;
|
| 20 |
+
let geminiService: GeminiService | null = null;
|
| 21 |
+
|
| 22 |
+
export function getRAGService(): RAGChatService {
|
| 23 |
+
if (!ragService) {
|
| 24 |
+
// Use Google provider by default (can also use 'groq')
|
| 25 |
+
const provider = process.env.RAG_PROVIDER || 'google';
|
| 26 |
+
ragService = new RAGChatService(provider);
|
| 27 |
+
}
|
| 28 |
+
return ragService;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
function getGeminiService(): GeminiService {
|
| 32 |
+
if (!geminiService) {
|
| 33 |
+
const apiKey = process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY;
|
| 34 |
+
if (!apiKey) {
|
| 35 |
+
throw new Error('GEMINI_API_KEY or GOOGLE_API_KEY is required for assessment greetings');
|
| 36 |
+
}
|
| 37 |
+
geminiService = new GeminiService(apiKey);
|
| 38 |
+
}
|
| 39 |
+
return geminiService;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
// POST /api/chat/start - Start a new chat session
|
| 43 |
+
router.post('/start', authenticateToken, async (req: Request, res: Response) => {
|
| 44 |
+
try {
|
| 45 |
+
const userId = req.user!.id;
|
| 46 |
+
const {
|
| 47 |
+
sessionId,
|
| 48 |
+
assessmentId,
|
| 49 |
+
assessmentSummary,
|
| 50 |
+
language = 'en',
|
| 51 |
+
}: ChatStartRequest = req.body;
|
| 52 |
+
|
| 53 |
+
if (!sessionId) {
|
| 54 |
+
return res.status(400).json({
|
| 55 |
+
error: 'sessionId is required',
|
| 56 |
+
});
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
// Get or create chat session context
|
| 60 |
+
let assessment = null;
|
| 61 |
+
if (assessmentId) {
|
| 62 |
+
assessment = await prisma.assessment.findFirst({
|
| 63 |
+
where: {
|
| 64 |
+
id: assessmentId,
|
| 65 |
+
user_id: userId,
|
| 66 |
+
},
|
| 67 |
+
});
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
// Get existing chat messages for this assessment ONLY (strictly filter by assessment_id)
|
| 71 |
+
// Never mix messages from different assessments
|
| 72 |
+
// IMPORTANT: If no assessmentId is provided, don't load any old messages - start fresh
|
| 73 |
+
let existingMessages: any[] = [];
|
| 74 |
+
if (assessment) {
|
| 75 |
+
// Only load messages if we have a specific assessment
|
| 76 |
+
existingMessages = await prisma.chatMessage.findMany({
|
| 77 |
+
where: {
|
| 78 |
+
user_id: userId,
|
| 79 |
+
assessment_id: assessment.id, // Use assessment.id to ensure we get messages for THIS assessment only
|
| 80 |
+
},
|
| 81 |
+
orderBy: { created_at: 'asc' },
|
| 82 |
+
take: 50,
|
| 83 |
+
});
|
| 84 |
+
}
|
| 85 |
+
// If no assessment, don't load any old messages - start with a clean chat session
|
| 86 |
+
|
| 87 |
+
// IMPORTANT: Double-check database to prevent race conditions
|
| 88 |
+
// Even if existingMessages is empty, check if an initial message exists in the database
|
| 89 |
+
// This prevents duplicates when /assessment/complete creates a message and /chat/start is called immediately
|
| 90 |
+
let dbHasInitialMessage = false;
|
| 91 |
+
if (assessment && existingMessages.length === 0) {
|
| 92 |
+
const dbCheck = await prisma.chatMessage.findFirst({
|
| 93 |
+
where: {
|
| 94 |
+
user_id: userId,
|
| 95 |
+
assessment_id: assessment.id,
|
| 96 |
+
sender: 'bot',
|
| 97 |
+
is_results_chat: true,
|
| 98 |
+
},
|
| 99 |
+
});
|
| 100 |
+
dbHasInitialMessage = !!dbCheck;
|
| 101 |
+
|
| 102 |
+
// If we found a message in the database but not in existingMessages, reload all messages
|
| 103 |
+
if (dbCheck) {
|
| 104 |
+
existingMessages = await prisma.chatMessage.findMany({
|
| 105 |
+
where: {
|
| 106 |
+
user_id: userId,
|
| 107 |
+
assessment_id: assessment.id,
|
| 108 |
+
},
|
| 109 |
+
orderBy: { created_at: 'asc' },
|
| 110 |
+
take: 50,
|
| 111 |
+
});
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
// Format existing messages for frontend
|
| 116 |
+
// Include assessment_id so frontend can verify messages belong to the correct assessment
|
| 117 |
+
const formattedMessages = existingMessages.map((msg) => ({
|
| 118 |
+
id: msg.id,
|
| 119 |
+
text: msg.message_text,
|
| 120 |
+
sender: msg.sender as 'user' | 'bot',
|
| 121 |
+
timestamp: msg.created_at,
|
| 122 |
+
assessment_id: msg.assessment_id, // Include for frontend filtering
|
| 123 |
+
}));
|
| 124 |
+
|
| 125 |
+
let initialMessage: ChatMessageResponse | null = null;
|
| 126 |
+
|
| 127 |
+
// Check if there's already an initial bot message for this assessment
|
| 128 |
+
// Since existingMessages are already filtered by assessment_id, we just need to check sender and is_results_chat
|
| 129 |
+
const hasInitialBotMessage = existingMessages.some(
|
| 130 |
+
(msg) => msg.sender === 'bot' && msg.is_results_chat
|
| 131 |
+
);
|
| 132 |
+
|
| 133 |
+
// Only generate initial greeting if:
|
| 134 |
+
// 1. No existing messages (after double-check)
|
| 135 |
+
// 2. No initial message in database (prevents race conditions)
|
| 136 |
+
// 3. We have an assessment summary
|
| 137 |
+
// 4. We have an assessment (to ensure it's assessment-specific)
|
| 138 |
+
if (existingMessages.length === 0 && !dbHasInitialMessage && assessmentSummary && !hasInitialBotMessage && assessment) {
|
| 139 |
+
try {
|
| 140 |
+
// Double-check one more time before creating (race condition protection)
|
| 141 |
+
const finalCheck = await prisma.chatMessage.findFirst({
|
| 142 |
+
where: {
|
| 143 |
+
user_id: userId,
|
| 144 |
+
assessment_id: assessment.id,
|
| 145 |
+
sender: 'bot',
|
| 146 |
+
is_results_chat: true,
|
| 147 |
+
},
|
| 148 |
+
});
|
| 149 |
+
|
| 150 |
+
// Only create if still doesn't exist after final check
|
| 151 |
+
if (!finalCheck) {
|
| 152 |
+
// OPTIMIZATION: Initialize RAG in parallel with Gemini greeting generation
|
| 153 |
+
// This ensures RAG is ready when user asks follow-up questions (no loading delay)
|
| 154 |
+
const ragInitPromise = getRAGService().initialize().catch(err => {
|
| 155 |
+
console.error('Failed to preload RAG service:', err);
|
| 156 |
+
// Don't fail the request if RAG preload fails - it will lazy load on first use
|
| 157 |
+
return undefined;
|
| 158 |
+
});
|
| 159 |
+
|
| 160 |
+
// Use Gemini for post-assessment initial greeting (preserves recommendation logic)
|
| 161 |
+
const geminiPromise = getGeminiService().generateInitialGreeting(
|
| 162 |
+
assessmentSummary,
|
| 163 |
+
language
|
| 164 |
+
);
|
| 165 |
+
|
| 166 |
+
// Wait for both to complete (RAG init happens in parallel with Gemini)
|
| 167 |
+
const [aiResponse, _ragInit] = await Promise.all([geminiPromise, ragInitPromise]);
|
| 168 |
+
|
| 169 |
+
initialMessage = {
|
| 170 |
+
reply: aiResponse.reply,
|
| 171 |
+
intent: aiResponse.intent,
|
| 172 |
+
};
|
| 173 |
+
|
| 174 |
+
// Save bot message to database
|
| 175 |
+
await prisma.chatMessage.create({
|
| 176 |
+
data: {
|
| 177 |
+
user_id: userId,
|
| 178 |
+
assessment_id: assessment.id,
|
| 179 |
+
message_text: aiResponse.reply,
|
| 180 |
+
sender: 'bot',
|
| 181 |
+
is_results_chat: true,
|
| 182 |
+
},
|
| 183 |
+
});
|
| 184 |
+
}
|
| 185 |
+
} catch (error) {
|
| 186 |
+
console.error('Failed to generate initial chat message:', error);
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
res.json({
|
| 191 |
+
sessionId,
|
| 192 |
+
assessmentId: assessment?.id,
|
| 193 |
+
messageCount: existingMessages.length + (initialMessage ? 1 : 0),
|
| 194 |
+
initialMessage,
|
| 195 |
+
existingMessages: formattedMessages,
|
| 196 |
+
});
|
| 197 |
+
} catch (error: any) {
|
| 198 |
+
console.error('Error starting chat session:', error);
|
| 199 |
+
res.status(500).json({
|
| 200 |
+
error: 'Failed to start chat session',
|
| 201 |
+
});
|
| 202 |
+
}
|
| 203 |
+
});
|
| 204 |
+
|
| 205 |
+
// POST /api/chat/message - Send a message and get AI response
|
| 206 |
+
router.post('/message', authenticateToken, async (req: Request, res: Response) => {
|
| 207 |
+
try {
|
| 208 |
+
const userId = req.user!.id;
|
| 209 |
+
const { sessionId, message, language, assessmentId }: ChatMessageRequest =
|
| 210 |
+
req.body;
|
| 211 |
+
|
| 212 |
+
if (
|
| 213 |
+
!sessionId ||
|
| 214 |
+
!message ||
|
| 215 |
+
typeof message !== 'string' ||
|
| 216 |
+
message.trim().length === 0
|
| 217 |
+
) {
|
| 218 |
+
return res.status(400).json({
|
| 219 |
+
error: 'sessionId and message (non-empty string) are required',
|
| 220 |
+
});
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
// Get assessment if provided
|
| 224 |
+
let assessment = null;
|
| 225 |
+
let assessmentSummary = '';
|
| 226 |
+
if (assessmentId) {
|
| 227 |
+
assessment = await prisma.assessment.findFirst({
|
| 228 |
+
where: {
|
| 229 |
+
id: assessmentId,
|
| 230 |
+
user_id: userId,
|
| 231 |
+
},
|
| 232 |
+
include: {
|
| 233 |
+
test_responses: {
|
| 234 |
+
where: { is_completed: true },
|
| 235 |
+
},
|
| 236 |
+
},
|
| 237 |
+
});
|
| 238 |
+
|
| 239 |
+
if (assessment) {
|
| 240 |
+
// Get user info
|
| 241 |
+
const user = await prisma.customUser.findUnique({
|
| 242 |
+
where: { id: userId },
|
| 243 |
+
});
|
| 244 |
+
|
| 245 |
+
// Build detailed assessment summary from test responses
|
| 246 |
+
const testResponses = assessment.test_responses.map((tr) => ({
|
| 247 |
+
type: tr.test_type,
|
| 248 |
+
answers: JSON.parse(tr.responses || '{}'),
|
| 249 |
+
}));
|
| 250 |
+
|
| 251 |
+
// Create a more detailed summary for better AI understanding
|
| 252 |
+
const summaryParts = [
|
| 253 |
+
`Assessment #${assessment.assessment_number} completed on ${assessment.completed_at?.toISOString()}.`,
|
| 254 |
+
`Student: ${user?.name || 'Student'}, Grade: ${user?.grade || 'N/A'}, Age: ${user?.age || 'N/A'}`,
|
| 255 |
+
`Test Responses:`,
|
| 256 |
+
];
|
| 257 |
+
|
| 258 |
+
testResponses.forEach((tr) => {
|
| 259 |
+
summaryParts.push(`\n${tr.type.toUpperCase()} Test:`);
|
| 260 |
+
Object.entries(tr.answers).forEach(([qId, answer]) => {
|
| 261 |
+
const answerStr = Array.isArray(answer) ? answer.join(', ') : String(answer);
|
| 262 |
+
summaryParts.push(` Question ${qId}: ${answerStr}`);
|
| 263 |
+
});
|
| 264 |
+
});
|
| 265 |
+
|
| 266 |
+
assessmentSummary = summaryParts.join('\n');
|
| 267 |
+
}
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
// Save user message to database first
|
| 271 |
+
const userMessage = await prisma.chatMessage.create({
|
| 272 |
+
data: {
|
| 273 |
+
user_id: userId,
|
| 274 |
+
assessment_id: assessment?.id || null,
|
| 275 |
+
message_text: message.trim(),
|
| 276 |
+
sender: 'user',
|
| 277 |
+
is_results_chat: !!assessment,
|
| 278 |
+
},
|
| 279 |
+
});
|
| 280 |
+
|
| 281 |
+
// Get previous messages for context (excluding the one we just created)
|
| 282 |
+
// CRITICAL: For assessment-specific chats, only load messages from that assessment
|
| 283 |
+
// For general chats (no assessment), load recent messages to maintain conversation context
|
| 284 |
+
let previousMessages;
|
| 285 |
+
if (assessment) {
|
| 286 |
+
// Assessment-specific chat: only load messages from that assessment
|
| 287 |
+
previousMessages = await prisma.chatMessage.findMany({
|
| 288 |
+
where: {
|
| 289 |
+
user_id: userId,
|
| 290 |
+
assessment_id: assessment.id,
|
| 291 |
+
id: { not: userMessage.id },
|
| 292 |
+
},
|
| 293 |
+
orderBy: { created_at: 'desc' },
|
| 294 |
+
take: 10,
|
| 295 |
+
});
|
| 296 |
+
} else {
|
| 297 |
+
// General chat: load recent messages (without assessment_id) for conversation context
|
| 298 |
+
// Only include messages from the last 10 minutes to create natural session boundaries
|
| 299 |
+
// This prevents old conversations from polluting new chat sessions
|
| 300 |
+
const tenMinutesAgo = new Date(Date.now() - 5 * 60 * 1000);
|
| 301 |
+
previousMessages = await prisma.chatMessage.findMany({
|
| 302 |
+
where: {
|
| 303 |
+
user_id: userId,
|
| 304 |
+
assessment_id: null, // Only general chat messages
|
| 305 |
+
id: { not: userMessage.id },
|
| 306 |
+
created_at: { gte: tenMinutesAgo }, // Only messages from last 10 minutes
|
| 307 |
+
},
|
| 308 |
+
orderBy: { created_at: 'desc' },
|
| 309 |
+
take: 10,
|
| 310 |
+
});
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
// Reverse to get chronological order
|
| 314 |
+
const contextMessages = previousMessages.reverse().map((msg) => ({
|
| 315 |
+
role: msg.sender === 'bot' ? ('assistant' as const) : ('user' as const),
|
| 316 |
+
content: msg.message_text,
|
| 317 |
+
timestamp: msg.created_at,
|
| 318 |
+
}));
|
| 319 |
+
|
| 320 |
+
// Use provided language or default to English
|
| 321 |
+
const userLanguage = language || 'en';
|
| 322 |
+
|
| 323 |
+
// Generate bot response using RAG with language parameter
|
| 324 |
+
const botReply = await getRAGService().chat(
|
| 325 |
+
message,
|
| 326 |
+
contextMessages,
|
| 327 |
+
userLanguage
|
| 328 |
+
);
|
| 329 |
+
|
| 330 |
+
// Save bot message to database
|
| 331 |
+
await prisma.chatMessage.create({
|
| 332 |
+
data: {
|
| 333 |
+
user_id: userId,
|
| 334 |
+
assessment_id: assessment?.id || null,
|
| 335 |
+
message_text: botReply,
|
| 336 |
+
sender: 'bot',
|
| 337 |
+
is_results_chat: !!assessment,
|
| 338 |
+
},
|
| 339 |
+
});
|
| 340 |
+
|
| 341 |
+
const response: ChatMessageResponse = {
|
| 342 |
+
reply: botReply,
|
| 343 |
+
intent: 'general', // RAG doesn't provide intent classification
|
| 344 |
+
};
|
| 345 |
+
|
| 346 |
+
res.json(response);
|
| 347 |
+
} catch (error: any) {
|
| 348 |
+
console.error('Error processing chat message:', error);
|
| 349 |
+
|
| 350 |
+
// Return fallback response
|
| 351 |
+
const fallback: ChatMessageResponse = {
|
| 352 |
+
reply:
|
| 353 |
+
"I'm having trouble processing that right now. Could you try rephrasing your question?",
|
| 354 |
+
intent: 'error',
|
| 355 |
+
};
|
| 356 |
+
|
| 357 |
+
res.status(500).json(fallback);
|
| 358 |
+
}
|
| 359 |
+
});
|
| 360 |
+
|
| 361 |
+
// GET /api/chat/history - Get chat history
|
| 362 |
+
router.get('/history', authenticateToken, async (req: Request, res: Response) => {
|
| 363 |
+
try {
|
| 364 |
+
const userId = req.user!.id;
|
| 365 |
+
const assessmentIdParam = req.query.assessment_id;
|
| 366 |
+
const assessmentId = assessmentIdParam
|
| 367 |
+
? parseInt(assessmentIdParam as string)
|
| 368 |
+
: null;
|
| 369 |
+
|
| 370 |
+
// If assessmentId is provided, verify it belongs to the user and strictly filter by it
|
| 371 |
+
// If assessmentId is not provided, only return non-assessment-specific messages
|
| 372 |
+
if (assessmentId !== null && !isNaN(assessmentId)) {
|
| 373 |
+
// Verify assessment belongs to user
|
| 374 |
+
const assessment = await prisma.assessment.findFirst({
|
| 375 |
+
where: {
|
| 376 |
+
id: assessmentId,
|
| 377 |
+
user_id: userId,
|
| 378 |
+
},
|
| 379 |
+
});
|
| 380 |
+
|
| 381 |
+
if (!assessment) {
|
| 382 |
+
return res.status(404).json({ error: 'Assessment not found' });
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
// CRITICAL: Strictly filter by assessment_id - ONLY return messages for this specific assessment
|
| 386 |
+
// NEVER return messages from other assessments or messages without assessment_id
|
| 387 |
+
const messages = await prisma.chatMessage.findMany({
|
| 388 |
+
where: {
|
| 389 |
+
user_id: userId,
|
| 390 |
+
assessment_id: assessmentId, // Strict filter - ONLY this assessment, no null values
|
| 391 |
+
},
|
| 392 |
+
orderBy: { created_at: 'asc' },
|
| 393 |
+
take: 50,
|
| 394 |
+
});
|
| 395 |
+
|
| 396 |
+
// Double-check: filter out any messages that don't match (shouldn't happen, but safety check)
|
| 397 |
+
const validMessages = messages.filter(msg => msg.assessment_id === assessmentId);
|
| 398 |
+
|
| 399 |
+
const messagesData = validMessages.map((msg) => ({
|
| 400 |
+
id: msg.id,
|
| 401 |
+
message_text: msg.message_text,
|
| 402 |
+
sender: msg.sender,
|
| 403 |
+
created_at: msg.created_at,
|
| 404 |
+
timestamp: msg.created_at,
|
| 405 |
+
is_results_chat: msg.is_results_chat,
|
| 406 |
+
assessment_id: msg.assessment_id, // Include for frontend filtering
|
| 407 |
+
}));
|
| 408 |
+
|
| 409 |
+
return res.json(messagesData);
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
// If no assessmentId, return only non-assessment-specific messages
|
| 413 |
+
const messages = await prisma.chatMessage.findMany({
|
| 414 |
+
where: {
|
| 415 |
+
user_id: userId,
|
| 416 |
+
assessment_id: null, // Only general chats, not assessment-specific
|
| 417 |
+
},
|
| 418 |
+
orderBy: { created_at: 'asc' },
|
| 419 |
+
take: 50,
|
| 420 |
+
});
|
| 421 |
+
|
| 422 |
+
const messagesData = messages.map((msg) => ({
|
| 423 |
+
id: msg.id,
|
| 424 |
+
message_text: msg.message_text,
|
| 425 |
+
sender: msg.sender,
|
| 426 |
+
created_at: msg.created_at,
|
| 427 |
+
timestamp: msg.created_at, // Add timestamp alias for frontend compatibility
|
| 428 |
+
is_results_chat: msg.is_results_chat,
|
| 429 |
+
}));
|
| 430 |
+
|
| 431 |
+
// Return as array directly for easier frontend consumption
|
| 432 |
+
res.json(messagesData);
|
| 433 |
+
} catch (error: any) {
|
| 434 |
+
console.error('Error getting chat history:', error);
|
| 435 |
+
res.status(500).json({ error: 'Failed to get chat history' });
|
| 436 |
+
}
|
| 437 |
+
});
|
| 438 |
+
|
| 439 |
+
// DELETE /api/chat/history - Delete chat history for an assessment or all chats
|
| 440 |
+
router.delete('/history', authenticateToken, async (req: Request, res: Response) => {
|
| 441 |
+
try {
|
| 442 |
+
const userId = req.user!.id;
|
| 443 |
+
const assessmentId = req.query.assessment_id
|
| 444 |
+
? parseInt(req.query.assessment_id as string)
|
| 445 |
+
: undefined;
|
| 446 |
+
|
| 447 |
+
if (assessmentId) {
|
| 448 |
+
// Delete chat history for specific assessment
|
| 449 |
+
const deleted = await prisma.chatMessage.deleteMany({
|
| 450 |
+
where: {
|
| 451 |
+
user_id: userId,
|
| 452 |
+
assessment_id: assessmentId,
|
| 453 |
+
},
|
| 454 |
+
});
|
| 455 |
+
|
| 456 |
+
res.json({
|
| 457 |
+
success: true,
|
| 458 |
+
message: `Deleted ${deleted.count} messages for assessment ${assessmentId}`,
|
| 459 |
+
deletedCount: deleted.count,
|
| 460 |
+
});
|
| 461 |
+
} else {
|
| 462 |
+
// Delete all chat history for user
|
| 463 |
+
const deleted = await prisma.chatMessage.deleteMany({
|
| 464 |
+
where: {
|
| 465 |
+
user_id: userId,
|
| 466 |
+
},
|
| 467 |
+
});
|
| 468 |
+
|
| 469 |
+
res.json({
|
| 470 |
+
success: true,
|
| 471 |
+
message: `Deleted ${deleted.count} messages`,
|
| 472 |
+
deletedCount: deleted.count,
|
| 473 |
+
});
|
| 474 |
+
}
|
| 475 |
+
} catch (error: any) {
|
| 476 |
+
console.error('Error deleting chat history:', error);
|
| 477 |
+
res.status(500).json({ error: 'Failed to delete chat history' });
|
| 478 |
+
}
|
| 479 |
+
});
|
| 480 |
+
|
| 481 |
+
export default router;
|
| 482 |
+
|
backend/src/routes/home.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Router, Request, Response } from 'express';
|
| 2 |
+
import { PrismaClient } from '@prisma/client';
|
| 3 |
+
import { authenticateToken } from '../middleware/auth';
|
| 4 |
+
|
| 5 |
+
const router = Router();
|
| 6 |
+
const prisma = new PrismaClient();
|
| 7 |
+
|
| 8 |
+
// GET /api/home - Get home page data
|
| 9 |
+
router.get('/', authenticateToken, async (req: Request, res: Response) => {
|
| 10 |
+
try {
|
| 11 |
+
const userId = req.user!.id;
|
| 12 |
+
|
| 13 |
+
// Get user profile
|
| 14 |
+
const user = await prisma.customUser.findUnique({
|
| 15 |
+
where: { id: userId },
|
| 16 |
+
select: {
|
| 17 |
+
id: true,
|
| 18 |
+
username: true,
|
| 19 |
+
name: true,
|
| 20 |
+
grade: true,
|
| 21 |
+
age: true,
|
| 22 |
+
email: true,
|
| 23 |
+
phone: true,
|
| 24 |
+
is_setup_complete: true,
|
| 25 |
+
created_at: true,
|
| 26 |
+
},
|
| 27 |
+
});
|
| 28 |
+
|
| 29 |
+
if (!user) {
|
| 30 |
+
return res.status(404).json({ error: 'User not found' });
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
// Get saved (in-progress) assessment - only if it has saved progress
|
| 34 |
+
let savedAssessment = await prisma.assessment.findFirst({
|
| 35 |
+
where: {
|
| 36 |
+
user_id: userId,
|
| 37 |
+
status: 'in_progress',
|
| 38 |
+
},
|
| 39 |
+
include: {
|
| 40 |
+
test_responses: {
|
| 41 |
+
orderBy: { test_type: 'asc' },
|
| 42 |
+
},
|
| 43 |
+
},
|
| 44 |
+
});
|
| 45 |
+
|
| 46 |
+
// Filter out assessments with no saved progress (0% progress)
|
| 47 |
+
// Only show assessments where user has actually saved at least one answer
|
| 48 |
+
if (savedAssessment) {
|
| 49 |
+
let hasAnyProgress = false;
|
| 50 |
+
|
| 51 |
+
// Check if any test response has saved answers or progress
|
| 52 |
+
for (const testResponse of savedAssessment.test_responses) {
|
| 53 |
+
// Check if there are saved responses (not empty)
|
| 54 |
+
if (testResponse.responses && testResponse.responses.trim() !== '' && testResponse.responses !== '{}') {
|
| 55 |
+
try {
|
| 56 |
+
const parsed = JSON.parse(testResponse.responses);
|
| 57 |
+
if (Object.keys(parsed).length > 0) {
|
| 58 |
+
hasAnyProgress = true;
|
| 59 |
+
break;
|
| 60 |
+
}
|
| 61 |
+
} catch {
|
| 62 |
+
// If parsing fails, check if it's not empty
|
| 63 |
+
if (testResponse.responses.trim().length > 2) {
|
| 64 |
+
hasAnyProgress = true;
|
| 65 |
+
break;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
// Also check if current_question_index > 0 (user has progressed)
|
| 70 |
+
if (testResponse.current_question_index && testResponse.current_question_index > 0) {
|
| 71 |
+
hasAnyProgress = true;
|
| 72 |
+
break;
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
// If no progress found, set savedAssessment to null so it won't be shown
|
| 77 |
+
if (!hasAnyProgress) {
|
| 78 |
+
// Optionally delete the empty assessment to clean up
|
| 79 |
+
// await prisma.assessment.delete({ where: { id: savedAssessment.id } });
|
| 80 |
+
// For now, just don't return it
|
| 81 |
+
savedAssessment = null;
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
// Get completed assessments
|
| 86 |
+
const completedAssessmentsRaw = await prisma.assessment.findMany({
|
| 87 |
+
where: {
|
| 88 |
+
user_id: userId,
|
| 89 |
+
status: 'completed',
|
| 90 |
+
},
|
| 91 |
+
orderBy: { completed_at: 'desc' },
|
| 92 |
+
take: 10,
|
| 93 |
+
include: {
|
| 94 |
+
chat_messages: {
|
| 95 |
+
select: {
|
| 96 |
+
id: true,
|
| 97 |
+
},
|
| 98 |
+
},
|
| 99 |
+
},
|
| 100 |
+
});
|
| 101 |
+
|
| 102 |
+
// Sort: assessments with chat messages first, then by completed_at desc
|
| 103 |
+
const completedAssessments = completedAssessmentsRaw.sort((a, b) => {
|
| 104 |
+
const aHasChat = a.chat_messages.length > 0;
|
| 105 |
+
const bHasChat = b.chat_messages.length > 0;
|
| 106 |
+
|
| 107 |
+
// If one has chat and the other doesn't, prioritize the one with chat
|
| 108 |
+
if (aHasChat && !bHasChat) return -1;
|
| 109 |
+
if (!aHasChat && bHasChat) return 1;
|
| 110 |
+
|
| 111 |
+
// If both have chat or both don't, sort by completed_at desc
|
| 112 |
+
return b.completed_at!.getTime() - a.completed_at!.getTime();
|
| 113 |
+
});
|
| 114 |
+
|
| 115 |
+
// Calculate completion stats
|
| 116 |
+
const totalAssessments = await prisma.assessment.count({
|
| 117 |
+
where: { user_id: userId },
|
| 118 |
+
});
|
| 119 |
+
const completedCount = completedAssessments.length;
|
| 120 |
+
const completionPercentage =
|
| 121 |
+
totalAssessments > 0
|
| 122 |
+
? Math.round((completedCount / totalAssessments) * 100 * 100) / 100
|
| 123 |
+
: 0;
|
| 124 |
+
|
| 125 |
+
res.json({
|
| 126 |
+
user_profile: user,
|
| 127 |
+
saved_assessment: savedAssessment
|
| 128 |
+
? {
|
| 129 |
+
id: savedAssessment.id,
|
| 130 |
+
assessment_number: savedAssessment.assessment_number,
|
| 131 |
+
status: savedAssessment.status,
|
| 132 |
+
started_at: savedAssessment.started_at,
|
| 133 |
+
test_responses: savedAssessment.test_responses.map((tr) => ({
|
| 134 |
+
id: tr.id,
|
| 135 |
+
test_type: tr.test_type,
|
| 136 |
+
is_completed: tr.is_completed,
|
| 137 |
+
current_question_index: tr.current_question_index,
|
| 138 |
+
})),
|
| 139 |
+
}
|
| 140 |
+
: null,
|
| 141 |
+
completed_assessments: completedAssessments.map((a) => ({
|
| 142 |
+
id: a.id,
|
| 143 |
+
assessment_number: a.assessment_number,
|
| 144 |
+
completed_at: a.completed_at,
|
| 145 |
+
status: a.status,
|
| 146 |
+
has_chat: a.chat_messages.length > 0,
|
| 147 |
+
})),
|
| 148 |
+
completion_stats: {
|
| 149 |
+
total_assessments: totalAssessments,
|
| 150 |
+
completed_percentage: completionPercentage,
|
| 151 |
+
},
|
| 152 |
+
});
|
| 153 |
+
} catch (error: any) {
|
| 154 |
+
console.error('Error getting home data:', error);
|
| 155 |
+
res.status(500).json({ error: 'Failed to get home data' });
|
| 156 |
+
}
|
| 157 |
+
});
|
| 158 |
+
|
| 159 |
+
export default router;
|
| 160 |
+
|
backend/src/routes/profile.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Router, Request, Response } from 'express';
|
| 2 |
+
import { PrismaClient } from '@prisma/client';
|
| 3 |
+
import { authenticateToken } from '../middleware/auth';
|
| 4 |
+
import bcrypt from 'bcryptjs';
|
| 5 |
+
|
| 6 |
+
const router = Router();
|
| 7 |
+
const prisma = new PrismaClient();
|
| 8 |
+
|
| 9 |
+
// GET /api/profile - Get user profile
|
| 10 |
+
router.get('/', authenticateToken, async (req: Request, res: Response) => {
|
| 11 |
+
try {
|
| 12 |
+
const userId = req.user!.id;
|
| 13 |
+
|
| 14 |
+
const user = await prisma.customUser.findUnique({
|
| 15 |
+
where: { id: userId },
|
| 16 |
+
select: {
|
| 17 |
+
id: true,
|
| 18 |
+
username: true,
|
| 19 |
+
name: true,
|
| 20 |
+
grade: true,
|
| 21 |
+
age: true,
|
| 22 |
+
email: true,
|
| 23 |
+
phone: true,
|
| 24 |
+
is_setup_complete: true,
|
| 25 |
+
created_at: true,
|
| 26 |
+
},
|
| 27 |
+
});
|
| 28 |
+
|
| 29 |
+
if (!user) {
|
| 30 |
+
return res.status(404).json({ error: 'User not found' });
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
res.json({ user });
|
| 34 |
+
} catch (error: any) {
|
| 35 |
+
console.error('Error getting profile:', error);
|
| 36 |
+
res.status(500).json({ error: 'Failed to get profile' });
|
| 37 |
+
}
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
// PATCH /api/profile/update - Update user profile
|
| 41 |
+
router.patch('/update', authenticateToken, async (req: Request, res: Response) => {
|
| 42 |
+
try {
|
| 43 |
+
const userId = req.user!.id;
|
| 44 |
+
const { name, grade, age, email, phone, currentPassword, newPassword } = req.body;
|
| 45 |
+
|
| 46 |
+
// Get current user to verify password if changing password
|
| 47 |
+
const currentUser = await prisma.customUser.findUnique({
|
| 48 |
+
where: { id: userId },
|
| 49 |
+
});
|
| 50 |
+
|
| 51 |
+
if (!currentUser) {
|
| 52 |
+
return res.status(404).json({ error: 'User not found' });
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
// If trying to change password, validate current password
|
| 56 |
+
if (newPassword) {
|
| 57 |
+
if (!currentPassword) {
|
| 58 |
+
return res.status(400).json({
|
| 59 |
+
error: 'Current password is required to change password'
|
| 60 |
+
});
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// Verify current password
|
| 64 |
+
const isValidPassword = await bcrypt.compare(currentPassword, currentUser.password);
|
| 65 |
+
if (!isValidPassword) {
|
| 66 |
+
return res.status(401).json({
|
| 67 |
+
error: 'Current password is incorrect'
|
| 68 |
+
});
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
const updateData: any = {};
|
| 73 |
+
if (name) updateData.name = name;
|
| 74 |
+
if (grade) updateData.grade = grade;
|
| 75 |
+
if (age !== undefined) updateData.age = parseInt(age) || null;
|
| 76 |
+
if (email !== undefined) updateData.email = email || null;
|
| 77 |
+
if (phone !== undefined) updateData.phone = phone || null;
|
| 78 |
+
if (newPassword) {
|
| 79 |
+
updateData.password = await bcrypt.hash(newPassword, 10);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
const user = await prisma.customUser.update({
|
| 83 |
+
where: { id: userId },
|
| 84 |
+
data: updateData,
|
| 85 |
+
select: {
|
| 86 |
+
id: true,
|
| 87 |
+
username: true,
|
| 88 |
+
name: true,
|
| 89 |
+
grade: true,
|
| 90 |
+
age: true,
|
| 91 |
+
email: true,
|
| 92 |
+
phone: true,
|
| 93 |
+
is_setup_complete: true,
|
| 94 |
+
},
|
| 95 |
+
});
|
| 96 |
+
|
| 97 |
+
res.json({ success: true, user });
|
| 98 |
+
} catch (error: any) {
|
| 99 |
+
console.error('Error updating profile:', error);
|
| 100 |
+
res.status(500).json({ error: 'Failed to update profile' });
|
| 101 |
+
}
|
| 102 |
+
});
|
| 103 |
+
|
| 104 |
+
// DELETE /api/profile/delete - Delete user account
|
| 105 |
+
router.delete('/delete', authenticateToken, async (req: Request, res: Response) => {
|
| 106 |
+
try {
|
| 107 |
+
const userId = req.user!.id;
|
| 108 |
+
|
| 109 |
+
// Delete user (cascade will delete assessments, messages, etc.)
|
| 110 |
+
await prisma.customUser.delete({
|
| 111 |
+
where: { id: userId },
|
| 112 |
+
});
|
| 113 |
+
|
| 114 |
+
res.json({
|
| 115 |
+
success: true,
|
| 116 |
+
message: 'Account deleted successfully',
|
| 117 |
+
});
|
| 118 |
+
} catch (error: any) {
|
| 119 |
+
console.error('Error deleting account:', error);
|
| 120 |
+
res.status(500).json({ error: 'Failed to delete account' });
|
| 121 |
+
}
|
| 122 |
+
});
|
| 123 |
+
|
| 124 |
+
export default router;
|
| 125 |
+
|
backend/src/server.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Load environment variables FIRST, before any other imports
|
| 2 |
+
import dotenv from 'dotenv';
|
| 3 |
+
import path from 'path';
|
| 4 |
+
|
| 5 |
+
// Load .env from the backend directory
|
| 6 |
+
const envPath = path.resolve(process.cwd(), '.env');
|
| 7 |
+
const result = dotenv.config({ path: envPath });
|
| 8 |
+
|
| 9 |
+
if (result.error) {
|
| 10 |
+
console.warn('⚠️ Warning: Could not load .env file:', result.error.message);
|
| 11 |
+
} else {
|
| 12 |
+
console.log('✅ Loaded .env file from:', envPath);
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
import express, { Request, Response } from 'express';
|
| 16 |
+
import cors from 'cors';
|
| 17 |
+
import authRoutes from './routes/auth';
|
| 18 |
+
import homeRoutes from './routes/home';
|
| 19 |
+
import assessmentRoutes from './routes/assessment';
|
| 20 |
+
import chatRoutes from './routes/chat';
|
| 21 |
+
import profileRoutes from './routes/profile';
|
| 22 |
+
|
| 23 |
+
const app = express();
|
| 24 |
+
const PORT = process.env.PORT || 3000;
|
| 25 |
+
|
| 26 |
+
// Eagerly initialize RAG service on server startup (in background)
|
| 27 |
+
// This preloads the Python process, embeddings model, and ChromaDB
|
| 28 |
+
// so it's ready when users need it (no wait time on first request)
|
| 29 |
+
// Import happens inside async function to avoid circular dependency
|
| 30 |
+
async function initializeRAGService() {
|
| 31 |
+
try {
|
| 32 |
+
console.log('🚀 Starting RAG service initialization in background...');
|
| 33 |
+
const { getRAGService } = await import('./routes/chat');
|
| 34 |
+
const ragService = getRAGService();
|
| 35 |
+
await ragService.initialize();
|
| 36 |
+
console.log('✅ RAG service preloaded successfully - ready for instant responses!');
|
| 37 |
+
} catch (err: any) {
|
| 38 |
+
console.error('⚠️ RAG service preload failed (will lazy load on first use):', err.message);
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
// Start initialization in background (don't await - let it run parallel to server startup)
|
| 43 |
+
initializeRAGService();
|
| 44 |
+
|
| 45 |
+
// Middleware
|
| 46 |
+
// CRITICAL: Parse JSON with UTF-8 encoding to support Hindi/Telugu/etc.
|
| 47 |
+
app.use(express.json({ limit: '10mb' }));
|
| 48 |
+
app.use(express.urlencoded({ extended: true, limit: '10mb' }));
|
| 49 |
+
|
| 50 |
+
app.use(
|
| 51 |
+
cors({
|
| 52 |
+
origin: function (origin, callback) {
|
| 53 |
+
// Allow requests with no origin (like mobile apps or curl requests)
|
| 54 |
+
if (!origin) return callback(null, true);
|
| 55 |
+
|
| 56 |
+
const allowedOrigins = [
|
| 57 |
+
process.env.FRONTEND_URL || 'http://localhost:5173',
|
| 58 |
+
'http://localhost:5173',
|
| 59 |
+
'http://localhost:5174',
|
| 60 |
+
'http://localhost:3000',
|
| 61 |
+
'http://127.0.0.1:5173',
|
| 62 |
+
'http://127.0.0.1:5174',
|
| 63 |
+
];
|
| 64 |
+
|
| 65 |
+
if (allowedOrigins.indexOf(origin) !== -1 || process.env.NODE_ENV === 'development') {
|
| 66 |
+
callback(null, true);
|
| 67 |
+
} else {
|
| 68 |
+
callback(new Error('Not allowed by CORS'));
|
| 69 |
+
}
|
| 70 |
+
},
|
| 71 |
+
credentials: true,
|
| 72 |
+
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
|
| 73 |
+
allowedHeaders: ['Content-Type', 'Authorization'],
|
| 74 |
+
})
|
| 75 |
+
);
|
| 76 |
+
app.use(express.json());
|
| 77 |
+
app.use(express.urlencoded({ extended: true }));
|
| 78 |
+
|
| 79 |
+
// Request logging middleware
|
| 80 |
+
app.use((req, res, next) => {
|
| 81 |
+
console.log(`${new Date().toISOString()} - ${req.method} ${req.path}`);
|
| 82 |
+
next();
|
| 83 |
+
});
|
| 84 |
+
|
| 85 |
+
// Health check endpoint
|
| 86 |
+
app.get('/health', (req: Request, res: Response) => {
|
| 87 |
+
res.json({
|
| 88 |
+
status: 'ok',
|
| 89 |
+
timestamp: new Date().toISOString(),
|
| 90 |
+
service: 'career-guidance-backend',
|
| 91 |
+
});
|
| 92 |
+
});
|
| 93 |
+
|
| 94 |
+
// API routes
|
| 95 |
+
app.use('/api/auth', authRoutes);
|
| 96 |
+
app.use('/api/home', homeRoutes);
|
| 97 |
+
app.use('/api/assessment', assessmentRoutes);
|
| 98 |
+
app.use('/api/chat', chatRoutes);
|
| 99 |
+
app.use('/api/profile', profileRoutes);
|
| 100 |
+
|
| 101 |
+
// Serve frontend static files in production
|
| 102 |
+
const frontendBuildPath = path.resolve(__dirname, '../../frontend/build');
|
| 103 |
+
app.use(express.static(frontendBuildPath));
|
| 104 |
+
|
| 105 |
+
// Support React Router SPA fallback (redirect non-API paths to frontend index.html)
|
| 106 |
+
app.get('*', (req: Request, res: Response, next) => {
|
| 107 |
+
if (req.path.startsWith('/api')) {
|
| 108 |
+
return next();
|
| 109 |
+
}
|
| 110 |
+
res.sendFile(path.join(frontendBuildPath, 'index.html'));
|
| 111 |
+
});
|
| 112 |
+
|
| 113 |
+
// 404 handler
|
| 114 |
+
app.use((req: Request, res: Response) => {
|
| 115 |
+
res.status(404).json({
|
| 116 |
+
error: 'Not found',
|
| 117 |
+
path: req.path,
|
| 118 |
+
});
|
| 119 |
+
});
|
| 120 |
+
|
| 121 |
+
// Error handler
|
| 122 |
+
app.use((err: any, req: Request, res: Response, next: any) => {
|
| 123 |
+
console.error('Unhandled error:', err);
|
| 124 |
+
res.status(500).json({
|
| 125 |
+
error: 'Internal server error',
|
| 126 |
+
message: process.env.NODE_ENV === 'development' ? err.message : undefined,
|
| 127 |
+
});
|
| 128 |
+
});
|
| 129 |
+
|
| 130 |
+
// Start server
|
| 131 |
+
const server = app.listen(PORT, () => {
|
| 132 |
+
console.log(`🚀 Server running on port ${PORT}`);
|
| 133 |
+
console.log(`📡 Health check: http://localhost:${PORT}/health`);
|
| 134 |
+
console.log(`🔗 API endpoints:`);
|
| 135 |
+
console.log(` POST /api/auth/setup`);
|
| 136 |
+
console.log(` POST /api/auth/login`);
|
| 137 |
+
console.log(` POST /api/auth/logout`);
|
| 138 |
+
console.log(` POST /api/auth/token/refresh`);
|
| 139 |
+
console.log(` GET /api/home`);
|
| 140 |
+
console.log(` POST /api/assessment/start`);
|
| 141 |
+
console.log(` POST /api/assessment/complete`);
|
| 142 |
+
console.log(` POST /api/chat/start`);
|
| 143 |
+
console.log(` POST /api/chat/message`);
|
| 144 |
+
console.log(` GET /api/chat/history`);
|
| 145 |
+
console.log(` GET /api/profile`);
|
| 146 |
+
console.log(` PATCH /api/profile/update`);
|
| 147 |
+
console.log(` DELETE /api/profile/delete`);
|
| 148 |
+
|
| 149 |
+
if (!process.env.GEMINI_API_KEY) {
|
| 150 |
+
console.warn('⚠️ WARNING: GEMINI_API_KEY not set. AI features will fail.');
|
| 151 |
+
}
|
| 152 |
+
if (!process.env.JWT_SECRET || process.env.JWT_SECRET === 'your-secret-key') {
|
| 153 |
+
console.warn('⚠️ WARNING: JWT_SECRET not set or using default. Change in production!');
|
| 154 |
+
}
|
| 155 |
+
});
|
| 156 |
+
|
| 157 |
+
// Handle port already in use error gracefully
|
| 158 |
+
server.on('error', (err: NodeJS.ErrnoException) => {
|
| 159 |
+
if (err.code === 'EADDRINUSE') {
|
| 160 |
+
console.error(`\n❌ Error: Port ${PORT} is already in use.`);
|
| 161 |
+
console.error(`💡 To free up port ${PORT}, run: lsof -ti:${PORT} | xargs kill -9`);
|
| 162 |
+
console.error(` Or use: npm run free-port (from root directory)\n`);
|
| 163 |
+
process.exit(1);
|
| 164 |
+
} else {
|
| 165 |
+
console.error('❌ Server error:', err);
|
| 166 |
+
process.exit(1);
|
| 167 |
+
}
|
| 168 |
+
});
|
| 169 |
+
|
| 170 |
+
export default app;
|
| 171 |
+
|
backend/src/services/gemini.ts
ADDED
|
@@ -0,0 +1,1529 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { GoogleGenerativeAI } from "@google/generative-ai";
|
| 2 |
+
import type {
|
| 3 |
+
Language,
|
| 4 |
+
AssessmentPayload,
|
| 5 |
+
CareerRecommendation,
|
| 6 |
+
AssessmentResponse,
|
| 7 |
+
ChatMessage,
|
| 8 |
+
} from "../types";
|
| 9 |
+
|
| 10 |
+
const MAX_RETRIES = 5; // Increased from 3 to 5 for better resilience
|
| 11 |
+
const INITIAL_RETRY_DELAY = 2000; // 2 seconds initial delay
|
| 12 |
+
|
| 13 |
+
interface RetryOptions {
|
| 14 |
+
maxAttempts?: number;
|
| 15 |
+
initialDelay?: number;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
async function sleep(ms: number): Promise<void> {
|
| 19 |
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
async function retryWithBackoff<T>(
|
| 23 |
+
fn: () => Promise<T>,
|
| 24 |
+
options: RetryOptions = {}
|
| 25 |
+
): Promise<T> {
|
| 26 |
+
// For 503 errors, use more attempts and longer delays
|
| 27 |
+
const is503Error = (error: any) =>
|
| 28 |
+
error?.status === 503 ||
|
| 29 |
+
error?.message?.includes("503") ||
|
| 30 |
+
error?.message?.toLowerCase().includes("overloaded") ||
|
| 31 |
+
error?.message?.toLowerCase().includes("service unavailable");
|
| 32 |
+
|
| 33 |
+
// Only increase attempts for 503 if maxAttempts wasn't explicitly set
|
| 34 |
+
const wasExplicitlySet = options.maxAttempts !== undefined;
|
| 35 |
+
let maxAttempts = options.maxAttempts || MAX_RETRIES;
|
| 36 |
+
const initialDelay = options.initialDelay || INITIAL_RETRY_DELAY;
|
| 37 |
+
|
| 38 |
+
let lastError: Error | null = null;
|
| 39 |
+
let detected503 = false;
|
| 40 |
+
|
| 41 |
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
| 42 |
+
try {
|
| 43 |
+
return await fn();
|
| 44 |
+
} catch (error: any) {
|
| 45 |
+
lastError = error;
|
| 46 |
+
|
| 47 |
+
// Check if it's a retryable error
|
| 48 |
+
const isRetryable =
|
| 49 |
+
error?.status === 429 ||
|
| 50 |
+
error?.status === 503 ||
|
| 51 |
+
error?.message?.includes("429") ||
|
| 52 |
+
error?.message?.includes("503") ||
|
| 53 |
+
error?.message?.toLowerCase().includes("quota") ||
|
| 54 |
+
error?.message?.toLowerCase().includes("rate limit") ||
|
| 55 |
+
error?.message?.toLowerCase().includes("overloaded") ||
|
| 56 |
+
error?.message?.toLowerCase().includes("service unavailable");
|
| 57 |
+
|
| 58 |
+
// If 503 detected and maxAttempts wasn't explicitly set, increase attempts dynamically
|
| 59 |
+
// This allows critical operations (recommendations) to retry more, while
|
| 60 |
+
// less critical ones (greeting) fail fast and use fallback
|
| 61 |
+
if (is503Error(error) && !detected503 && !wasExplicitlySet) {
|
| 62 |
+
detected503 = true;
|
| 63 |
+
maxAttempts = Math.max(maxAttempts, 7); // Up to 7 attempts for 503
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
if (!isRetryable || attempt === maxAttempts - 1) {
|
| 67 |
+
throw error;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
// Calculate delay based on error type
|
| 71 |
+
let delay: number;
|
| 72 |
+
if (error?.status === 503 || is503Error(error)) {
|
| 73 |
+
// For 503 (overloaded), use longer exponential backoff
|
| 74 |
+
// Attempt 0: 15s, 1: 20s, 2: 25s, 3: 30s, 4+: 30s
|
| 75 |
+
delay = Math.min(15000 + attempt * 5000, 30000);
|
| 76 |
+
} else if (error?.status === 429) {
|
| 77 |
+
// For 429 (rate limit), use exponential backoff
|
| 78 |
+
delay = initialDelay * Math.pow(2, attempt);
|
| 79 |
+
// But respect API's suggested retry delay if available
|
| 80 |
+
if (error?.message?.match(/retry in (\d+)/i)) {
|
| 81 |
+
const suggestedDelay =
|
| 82 |
+
parseInt(error.message.match(/retry in (\d+)/i)?.[1] || "0") * 1000;
|
| 83 |
+
if (suggestedDelay > delay) {
|
| 84 |
+
delay = Math.min(suggestedDelay, 60000); // Cap at 60s
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
} else {
|
| 88 |
+
// Default exponential backoff
|
| 89 |
+
delay = initialDelay * Math.pow(2, attempt);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
console.log(
|
| 93 |
+
`API error (${error?.status || "unknown"}), retrying in ${(
|
| 94 |
+
delay / 1000
|
| 95 |
+
).toFixed(1)}s (attempt ${attempt + 1}/${maxAttempts})`
|
| 96 |
+
);
|
| 97 |
+
await sleep(delay);
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
throw lastError || new Error("Max retries exceeded");
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
export class GeminiService {
|
| 104 |
+
private genAI: GoogleGenerativeAI;
|
| 105 |
+
private apiKey: string;
|
| 106 |
+
private readonly modelId = "gemini-2.5-flash";
|
| 107 |
+
|
| 108 |
+
constructor(apiKey: string) {
|
| 109 |
+
if (!apiKey) {
|
| 110 |
+
throw new Error("GEMINI_API_KEY is required");
|
| 111 |
+
}
|
| 112 |
+
this.apiKey = apiKey;
|
| 113 |
+
this.genAI = new GoogleGenerativeAI(apiKey);
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
private getSystemPrompt(
|
| 117 |
+
language: Language,
|
| 118 |
+
context: "recommendation" | "chat"
|
| 119 |
+
): string {
|
| 120 |
+
const languageNames: Record<Language, string> = {
|
| 121 |
+
en: "English",
|
| 122 |
+
hi: "Hindi",
|
| 123 |
+
te: "Telugu",
|
| 124 |
+
ta: "Tamil",
|
| 125 |
+
bn: "Bengali",
|
| 126 |
+
gu: "Gujarati",
|
| 127 |
+
};
|
| 128 |
+
|
| 129 |
+
const basePrompt = `You are a friendly, encouraging career counsellor for students aged 13-15.
|
| 130 |
+
Respond in ${languageNames[language]} (${language}).
|
| 131 |
+
|
| 132 |
+
Safety rules:
|
| 133 |
+
- Do not ask for highly-sensitive personal data (financial, medical).
|
| 134 |
+
- If such data is received, respond with a gentle refusal and redirect to guardian/teacher.
|
| 135 |
+
- Keep responses age-appropriate and encouraging.
|
| 136 |
+
- Focus on career guidance and educational paths.`;
|
| 137 |
+
|
| 138 |
+
if (context === "recommendation") {
|
| 139 |
+
return `${basePrompt}
|
| 140 |
+
|
| 141 |
+
Your task: Analyze the student's assessment responses and generate personalized career recommendations.
|
| 142 |
+
Return ONLY a valid JSON object with this exact structure:
|
| 143 |
+
{
|
| 144 |
+
"recommendations": [
|
| 145 |
+
{
|
| 146 |
+
"title": "Career Name",
|
| 147 |
+
"confidence": 0.85,
|
| 148 |
+
"reason": "Brief explanation why this fits",
|
| 149 |
+
"next_steps": ["Step 1", "Step 2"]
|
| 150 |
+
}
|
| 151 |
+
],
|
| 152 |
+
"summary": "A short, friendly 1-2 sentence summary for the student"
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
Provide 3-4 career recommendations based on their strengths, interests, and values.`;
|
| 156 |
+
} else {
|
| 157 |
+
return `${basePrompt}
|
| 158 |
+
|
| 159 |
+
You are chatting with a student who has completed a career assessment.
|
| 160 |
+
Use the assessment summary as context for your responses.
|
| 161 |
+
Be conversational, friendly, and helpful. Keep responses concise (2-3 sentences max).
|
| 162 |
+
Return a JSON object: {"reply": "your response", "intent": "follow_up" or "question" or "clarification"}`;
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
private formatFallbackGreeting(
|
| 167 |
+
assessmentSummary: string,
|
| 168 |
+
language: Language
|
| 169 |
+
): { reply: string; intent: string } {
|
| 170 |
+
// Parse assessment summary to extract student name and recommendations
|
| 171 |
+
const studentNameMatch = assessmentSummary.match(/Student:\s*([^,\n]+)/);
|
| 172 |
+
const studentName = studentNameMatch
|
| 173 |
+
? studentNameMatch[1].trim()
|
| 174 |
+
: "Student";
|
| 175 |
+
|
| 176 |
+
// Extract recommendations - handle both formats:
|
| 177 |
+
// Format 1: "Career Recommendations (from matching list):\n1. Title\n Reason: ...\n Next Steps: ..."
|
| 178 |
+
// Format 2: "Recommendations:\n1. Title (XX% match) - reason. Next steps: ..."
|
| 179 |
+
const recommendationsMatch = assessmentSummary.match(
|
| 180 |
+
/Career Recommendations[^:]*:\s*([\s\S]+?)(?=\n\n|\nTest|$)/i
|
| 181 |
+
);
|
| 182 |
+
let recommendationsText = recommendationsMatch
|
| 183 |
+
? recommendationsMatch[1].trim()
|
| 184 |
+
: "";
|
| 185 |
+
|
| 186 |
+
// Fallback: try just "Recommendations:" if "Career Recommendations" not found
|
| 187 |
+
if (!recommendationsText) {
|
| 188 |
+
const altMatch = assessmentSummary.match(
|
| 189 |
+
/^Recommendations:\s*([\s\S]+?)(?=\n\n|\nTest|$)/im
|
| 190 |
+
);
|
| 191 |
+
recommendationsText = altMatch ? altMatch[1].trim() : "";
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
// Parse each recommendation - handle both formats
|
| 195 |
+
const lines = recommendationsText.split("\n").filter((line) => line.trim());
|
| 196 |
+
const recommendations: Array<{
|
| 197 |
+
title: string;
|
| 198 |
+
percent: string;
|
| 199 |
+
reason: string;
|
| 200 |
+
steps: string[];
|
| 201 |
+
}> = [];
|
| 202 |
+
|
| 203 |
+
let currentRec: {
|
| 204 |
+
title: string;
|
| 205 |
+
percent: string;
|
| 206 |
+
reason: string;
|
| 207 |
+
steps: string[];
|
| 208 |
+
} | null = null;
|
| 209 |
+
|
| 210 |
+
for (const line of lines) {
|
| 211 |
+
const trimmed = line.trim();
|
| 212 |
+
|
| 213 |
+
// Check if this is a numbered list item (format: "1. Title" or "1. Title (XX%)")
|
| 214 |
+
const numberedMatch = trimmed.match(/^\d+\.\s*(.+)$/);
|
| 215 |
+
if (numberedMatch) {
|
| 216 |
+
// Save previous recommendation if exists
|
| 217 |
+
if (currentRec && currentRec.title) {
|
| 218 |
+
recommendations.push(currentRec);
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
// Start new recommendation
|
| 222 |
+
const titlePart = numberedMatch[1].trim();
|
| 223 |
+
// Check if it has percentage in format: "Title (XX%)"
|
| 224 |
+
const titleWithPercent = titlePart.match(/^(.+?)\s*\((\d+)%[^)]*\)/);
|
| 225 |
+
if (titleWithPercent) {
|
| 226 |
+
currentRec = {
|
| 227 |
+
title: titleWithPercent[1].trim(),
|
| 228 |
+
percent: titleWithPercent[2],
|
| 229 |
+
reason: "",
|
| 230 |
+
steps: [],
|
| 231 |
+
};
|
| 232 |
+
} else {
|
| 233 |
+
// Format: "1. Title" (new format)
|
| 234 |
+
currentRec = {
|
| 235 |
+
title: titlePart,
|
| 236 |
+
percent: "",
|
| 237 |
+
reason: "",
|
| 238 |
+
steps: [],
|
| 239 |
+
};
|
| 240 |
+
}
|
| 241 |
+
}
|
| 242 |
+
// Check for "Reason:" line (new format)
|
| 243 |
+
else if (trimmed.match(/^Reason:\s*/i) && currentRec) {
|
| 244 |
+
currentRec.reason = trimmed.replace(/^Reason:\s*/i, "").trim();
|
| 245 |
+
}
|
| 246 |
+
// Check for "Next Steps:" line (new format)
|
| 247 |
+
else if (trimmed.match(/^Next Steps?:\s*/i) && currentRec) {
|
| 248 |
+
const stepsText = trimmed.replace(/^Next Steps?:\s*/i, "").trim();
|
| 249 |
+
currentRec.steps = stepsText
|
| 250 |
+
.split(",")
|
| 251 |
+
.map((s) => s.trim())
|
| 252 |
+
.filter((s) => s.length > 0);
|
| 253 |
+
}
|
| 254 |
+
// Check for old format: "Title (XX%) - reason. Next steps: ..."
|
| 255 |
+
else if (trimmed.includes(" - ") && currentRec) {
|
| 256 |
+
const dashMatch = trimmed.match(/\s*-\s*(.+)$/);
|
| 257 |
+
if (dashMatch) {
|
| 258 |
+
const afterDash = dashMatch[1];
|
| 259 |
+
if (afterDash.includes(". Next steps:")) {
|
| 260 |
+
const parts = afterDash.split(/\.\s*Next steps?:\s*/i);
|
| 261 |
+
currentRec.reason = parts[0] ? parts[0].trim() : "";
|
| 262 |
+
if (parts[1]) {
|
| 263 |
+
currentRec.steps = parts[1]
|
| 264 |
+
.split(",")
|
| 265 |
+
.map((s) => s.trim())
|
| 266 |
+
.filter((s) => s.length > 0);
|
| 267 |
+
}
|
| 268 |
+
} else {
|
| 269 |
+
currentRec.reason = afterDash.trim().replace(/\.$/, "");
|
| 270 |
+
}
|
| 271 |
+
}
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
// Limit to 4 recommendations
|
| 275 |
+
if (recommendations.length >= 4) break;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
// Don't forget the last one
|
| 279 |
+
if (currentRec && currentRec.title && recommendations.length < 4) {
|
| 280 |
+
recommendations.push(currentRec);
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
// Format the response based on language
|
| 284 |
+
const greetings: Record<Language, string> = {
|
| 285 |
+
en: `Hey ${studentName}, great job on the assessment! Based on your results, here are some exciting career paths for you:\n\n`,
|
| 286 |
+
hi: `${studentName}, मूल्यांकन पूरा करने के लिए बधाई! आपके परिणामों के आधार पर, यहाँ कुछ रोमांचक करियर पथ हैं:\n\n`,
|
| 287 |
+
te: `${studentName}, అసెస్మెంట్ పూర్తి చేసినందుకు అభినందనలు! మీ ఫలితాల ఆధారంగా, మీ కోసం కొన్ని ఉత్తేజకరమైన కెరీర్ మార్గాలు ఇక్కడ ఉన్నాయి:\n\n`,
|
| 288 |
+
ta: `${studentName}, மதிப்பீட்டை முடித்ததற்கு வாழ்த்துக்கள்! உங்கள் முடிவுகளின் அடிப்படையில், உங்களுக்கான சில சுவாரஸ்யமான தொழில் பாதைகள் இங்கே:\n\n`,
|
| 289 |
+
bn: `${studentName}, মূল্যায়ন সম্পন্ন করার জন্য অভিনন্দন! আপনার ফলাফলের ভিত্তিতে, এখানে কিছু উত্তেজনাপূর্ণ ক্যারিয়ার পথ রয়েছে:\n\n`,
|
| 290 |
+
gu: `${studentName}, મૂલ્યાંકન પૂર્ણ કરવા માટે અભિનંદન! તમારા પરિણામોના આધારે, અહીં કેટલાક રોમાંચક કારકિર્દી માર્ગો છે:\n\n`,
|
| 291 |
+
};
|
| 292 |
+
|
| 293 |
+
const nextStepsLabels: Record<Language, string> = {
|
| 294 |
+
en: "Next steps",
|
| 295 |
+
hi: "अगले कदम",
|
| 296 |
+
te: "తదుపరి దశలు",
|
| 297 |
+
ta: "அடுத்த படிகள்",
|
| 298 |
+
bn: "পরবর্তী পদক্ষেপ",
|
| 299 |
+
gu: "આગળના પગલાં",
|
| 300 |
+
};
|
| 301 |
+
|
| 302 |
+
const closingMessages: Record<Language, string> = {
|
| 303 |
+
en: "\n\nFeel free to ask me any questions about these career paths!",
|
| 304 |
+
hi: "\n\nइन करियर पथों के बारे में कोई भी प्रश्न पूछने के लिए स्वतंत्र महसूस करें!",
|
| 305 |
+
te: "\n\nఈ కెరీర్ మార్గాల గురించి ఏవైనా ప్రశ్నలు అడగడానికి సంకోచించకండి!",
|
| 306 |
+
ta: "\n\nஇந்த தொழில் பாதைகள் பற்றி எந்த கேள்விகளையும் கேட்க தயங்க வேண்டாம்!",
|
| 307 |
+
bn: "\n\nএই ক্যারিয়ার পথ সম্পর্কে কোন প্রশ্ন করতে নির্দ্বিধায় জিজ্ঞাসা করুন!",
|
| 308 |
+
gu: "\n\nઆ કારકિર્દી માર્ગો વિશે કોઈપણ પ્રશ્નો પૂછવા માટે મફત લાગે!",
|
| 309 |
+
};
|
| 310 |
+
|
| 311 |
+
// Always start with the greeting - ensure it never includes summary text
|
| 312 |
+
let reply = greetings[language] || greetings.en;
|
| 313 |
+
|
| 314 |
+
console.log(
|
| 315 |
+
"[formatFallbackGreeting] Starting reply with:",
|
| 316 |
+
reply.substring(0, 50) + "..."
|
| 317 |
+
);
|
| 318 |
+
console.log(
|
| 319 |
+
"[formatFallbackGreeting] Parsed recommendations count:",
|
| 320 |
+
recommendations.length
|
| 321 |
+
);
|
| 322 |
+
|
| 323 |
+
// If no recommendations were parsed, try to extract matching careers from summary
|
| 324 |
+
if (recommendations.length === 0) {
|
| 325 |
+
console.log(
|
| 326 |
+
"[formatFallbackGreeting] No recommendations parsed, trying to extract matching careers from summary"
|
| 327 |
+
);
|
| 328 |
+
|
| 329 |
+
// Try to find "Matching Careers" section (extract just the career names, not the label)
|
| 330 |
+
// Format: "Matching Careers (2): Career1, Career2"
|
| 331 |
+
const matchingCareersMatch = assessmentSummary.match(
|
| 332 |
+
/Matching Careers\s*\([^)]+\):\s*([^\n]+)/i
|
| 333 |
+
);
|
| 334 |
+
if (matchingCareersMatch && matchingCareersMatch[1]) {
|
| 335 |
+
const careersText = matchingCareersMatch[1].trim();
|
| 336 |
+
// Remove trailing "..." if present
|
| 337 |
+
const cleanCareersText = careersText.replace(/\.\.\.$/, "").trim();
|
| 338 |
+
const careersList = cleanCareersText
|
| 339 |
+
.split(",")
|
| 340 |
+
.map((c) => c.trim())
|
| 341 |
+
.filter((c) => c.length > 0)
|
| 342 |
+
.slice(0, 4);
|
| 343 |
+
|
| 344 |
+
console.log(
|
| 345 |
+
"[formatFallbackGreeting] Extracted matching careers:",
|
| 346 |
+
careersList
|
| 347 |
+
);
|
| 348 |
+
|
| 349 |
+
if (careersList.length > 0) {
|
| 350 |
+
careersList.forEach((career, idx) => {
|
| 351 |
+
reply += `<strong>${career}</strong>\n`;
|
| 352 |
+
reply += `Based on your RIASEC profile, this career aligns with your interests and personality.\n`;
|
| 353 |
+
if (idx < careersList.length - 1) {
|
| 354 |
+
reply += "\n";
|
| 355 |
+
}
|
| 356 |
+
});
|
| 357 |
+
} else {
|
| 358 |
+
// If careers list is empty after parsing, use generic message
|
| 359 |
+
const fallbackMessages: Record<Language, string> = {
|
| 360 |
+
en: "I've analyzed your assessment and found some great career paths that match your interests! Take a look at your recommendations above and feel free to ask me any questions.",
|
| 361 |
+
hi: "मैंने आपके मूल्यांकन का विश्लेषण किया है और कुछ बेहतरीन करियर पथ पाए हैं जो आपकी रुचियों से मेल खाते हैं! अपने सुझावों पर एक नज़र डालें और मुझसे कोई भी प्रश्न पूछने के लिए स्वतंत्र महसूस करें।",
|
| 362 |
+
te: "నేను మీ అసెస్మెంట్ను విశ్లేషించాను మరియు మీ ఆసక్తులకు సరిపోయే కొన్ని గొప్ప కెరీర్ మార్గాలను కనుగొన్నాను! మీ సిఫార్సులను చూడండి మరియు నాతో ఏవైనా ప్రశ్నలు అడగడానికి సంకోచించకండి।",
|
| 363 |
+
ta: "நான் உங்கள் மதிப்பீட்டை பகுப்பாய்வு செய்து உங்கள் ஆர்வங்களுக்கு பொருந்தும் சில சிறந்த தொழில் பாதைகளைக் கண்டறிந்துள்ளேன்! உங்கள் பரிந்துரைகளைப் பாருங்கள் மற்றும் எந்த கேள்விகளையும் கேட்க தயங்க வேண்டாம்।",
|
| 364 |
+
bn: "আমি আপনার মূল্যায়ন বিশ্লেষণ করেছি এবং আপনার আগ্রহের সাথে মিলে এমন কিছু দুর্দান্ত ক্যারিয়ার পথ খুঁজে পেয়েছি! আপনার সুপারিশগুলির দিকে দেখুন এবং নির্দ্বিধায় আমাকে কোনো প্রশ্ন জিজ্ঞাসা করুন।",
|
| 365 |
+
gu: "મેં તમારા મૂલ્યાંકનનું વિશ્લેષણ કર્યું છે અને તમારા રુચિઓને મેળ ખાય તેવા કેટલાક મહાન કારકિર્દી માર્ગો શોધ્યા છે! તમારી ભલામણો જુઓ અને કોઈપણ પ્રશ્નો પૂછવા માટે મફત લાગે।",
|
| 366 |
+
};
|
| 367 |
+
reply += fallbackMessages[language] || fallbackMessages.en;
|
| 368 |
+
}
|
| 369 |
+
} else {
|
| 370 |
+
// Fallback: Generic encouraging message
|
| 371 |
+
const fallbackMessages: Record<Language, string> = {
|
| 372 |
+
en: "I've analyzed your assessment and found some great career paths that match your interests! Take a look at your recommendations above and feel free to ask me any questions.",
|
| 373 |
+
hi: "मैंने आपके मूल्यांकन का विश्लेषण किया है और कुछ बेहतरीन करियर पथ पाए हैं जो आपकी रुचियों से मेल खाते हैं! अपने सुझावों पर एक नज़र डालें और मुझसे कोई भी प्रश्न पूछने के लिए स्वतंत्र महसूस करें।",
|
| 374 |
+
te: "నేను మీ అసెస్మెంట్ను విశ్లేషించాను మరియు మీ ఆసక్తులకు సరిపోయే కొన్ని గొప్ప కెరీర్ మార్గాలను కనుగొన్నాను! మీ సిఫార్సులను చూడండి మరియు నాతో ఏవైనా ప్రశ్నలు అడగడానికి సంకోచించకండి।",
|
| 375 |
+
ta: "நான் உங்கள் மதிப்பீட்டை பகுப்பாய்வு செய்து உங்கள் ஆர்வங்களுக்கு பொருந்தும் சில சிறந்த தொழில் பாதைகளைக் கண்டறிந்துள்ளேன்! உங்கள் பரிந்துரைகளைப் பாருங்கள் மற்றும் எந்த கேள்விகளையும் கேட்க தயங்க வேண்டாம்।",
|
| 376 |
+
bn: "আমি আপনার মূল্যায়ন বিশ্লেষণ করেছি এবং আপনার আগ্রহের সাথে মিলে এমন কিছু দুর্দান্ত ক্যারিয়ার পথ খুঁজে পেয়েছি! আপনার সুপারিশগুলির দিকে দেখুন এবং নির্দ্বিধায় আমাকে কোনো প্রশ্ন জিজ্ঞাসা করুন।",
|
| 377 |
+
gu: "મેં તમારા મૂલ્યાંકનનું વિશ્લેષણ કર્યું છે અને તમારા રુચિઓને મેળ ખાય તેવા કેટલાક મહાન કારકિર્દી માર્ગો શોધ્યા છે! તમારી ભલામણો જુઓ અને કોઈપણ પ્રશ્નો પૂછવા માટે મફત લાગે।",
|
| 378 |
+
};
|
| 379 |
+
reply += fallbackMessages[language] || fallbackMessages.en;
|
| 380 |
+
}
|
| 381 |
+
} else {
|
| 382 |
+
// Format parsed recommendations
|
| 383 |
+
recommendations.forEach((rec, idx) => {
|
| 384 |
+
if (rec.title) {
|
| 385 |
+
reply += `<strong>${rec.title}</strong>`;
|
| 386 |
+
if (rec.percent) {
|
| 387 |
+
reply += ` (${rec.percent}% match)`;
|
| 388 |
+
}
|
| 389 |
+
reply += "\n";
|
| 390 |
+
if (rec.reason) {
|
| 391 |
+
reply += `${rec.reason}\n`;
|
| 392 |
+
}
|
| 393 |
+
if (rec.steps.length > 0) {
|
| 394 |
+
reply += `${nextStepsLabels[language] || nextStepsLabels.en}: `;
|
| 395 |
+
reply += rec.steps.slice(0, 3).join(" • ") + "\n";
|
| 396 |
+
}
|
| 397 |
+
if (idx < recommendations.length - 1) {
|
| 398 |
+
reply += "\n";
|
| 399 |
+
}
|
| 400 |
+
}
|
| 401 |
+
});
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
reply += closingMessages[language] || closingMessages.en;
|
| 405 |
+
|
| 406 |
+
// Safety check: Ensure reply never includes raw summary text like "Matching Careers" at the start
|
| 407 |
+
// If it does, replace with proper greeting
|
| 408 |
+
if (
|
| 409 |
+
reply.startsWith("Matching Careers") ||
|
| 410 |
+
reply.startsWith("Career Recommendations") ||
|
| 411 |
+
reply.startsWith("RIASEC")
|
| 412 |
+
) {
|
| 413 |
+
console.warn(
|
| 414 |
+
"[formatFallbackGreeting] Reply started with summary text, fixing it"
|
| 415 |
+
);
|
| 416 |
+
reply =
|
| 417 |
+
(greetings[language] || greetings.en) +
|
| 418 |
+
reply.replace(
|
| 419 |
+
/^(Matching Careers|Career Recommendations|RIASEC)[^!]*!\s*/i,
|
| 420 |
+
""
|
| 421 |
+
);
|
| 422 |
+
// If no recommendations were added, add a generic message
|
| 423 |
+
if (
|
| 424 |
+
!reply.includes("<strong>") &&
|
| 425 |
+
!reply.includes("analyzed your assessment")
|
| 426 |
+
) {
|
| 427 |
+
const genericMessage: Record<Language, string> = {
|
| 428 |
+
en: "I've analyzed your assessment and found some great career paths! Feel free to ask me any questions.",
|
| 429 |
+
hi: "मैंने आपके मूल्यांकन का विश्लेषण किया है और कुछ बेहतरीन करियर पथ पाए हैं! मुझसे कोई भी प्रश्न पूछने के लिए स्वतंत्र महसूस करें।",
|
| 430 |
+
te: "నేను మీ అసెస్మెంట్ను విశ్లేషించాను మరియు కొన్ని గొప్ప కెరీర్ మార్గాలను కనుగొన్నాను! నాతో ఏవైనా ప్రశ్నలు అడగడానికి సంకోచించకండి।",
|
| 431 |
+
ta: "நான் உங்கள் மதிப்பீட்டை பகுப்பாய்வு செய்து சில சிறந்த தொழில் பாதைகளைக் கண்டறிந்துள்ளேன்! எந்த கேள்விகளையும் கேட்க தயங்க வேண்டாம்।",
|
| 432 |
+
bn: "আমি আপনার মূল্যায়ন বিশ্লেষণ করেছি এবং কিছু দুর্দান্ত ক্যারিয়ার পথ খুঁজে পেয়েছি! নির্দ্বিধায় আমাকে কোনো প্রশ্ন জিজ্ঞাসা করুন।",
|
| 433 |
+
gu: "મેં તમારા મૂલ્યાંકનનું વિશ્લેષણ કર્યું છે અને કેટલાક મહાન કારકિર્દી માર્ગો શોધ્યા છે! કોઈપણ પ્રશ્નો પૂછવા માટે મફત લાગે।",
|
| 434 |
+
};
|
| 435 |
+
reply =
|
| 436 |
+
(greetings[language] || greetings.en) +
|
| 437 |
+
(genericMessage[language] || genericMessage.en);
|
| 438 |
+
}
|
| 439 |
+
reply += closingMessages[language] || closingMessages.en;
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
console.log(
|
| 443 |
+
"[formatFallbackGreeting] Final reply (first 100 chars):",
|
| 444 |
+
reply.substring(0, 100)
|
| 445 |
+
);
|
| 446 |
+
|
| 447 |
+
return { reply, intent: "follow_up" };
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
async generateInitialGreeting(
|
| 451 |
+
assessmentSummary: string,
|
| 452 |
+
language: Language
|
| 453 |
+
): Promise<{ reply: string; intent: string }> {
|
| 454 |
+
const systemPrompt = this.getSystemPrompt(language, "chat");
|
| 455 |
+
const prompt = `${systemPrompt}
|
| 456 |
+
|
| 457 |
+
This is the FIRST message after the assessment is complete.
|
| 458 |
+
Assessment summary:
|
| 459 |
+
${assessmentSummary}
|
| 460 |
+
|
| 461 |
+
CRITICAL INSTRUCTIONS:
|
| 462 |
+
- You MUST ONLY mention career paths that appear in the "Career Recommendations" section above.
|
| 463 |
+
- Use the EXACT career names from the recommendations list.
|
| 464 |
+
- Do NOT suggest, invent, or mention any other careers that are not in the recommendations list.
|
| 465 |
+
- If the summary shows "Matching Careers", you can ONLY use careers from that list.
|
| 466 |
+
|
| 467 |
+
Instruction:
|
| 468 |
+
- Greet the student by name if provided in the summary.
|
| 469 |
+
- Present the career paths from the "Career Recommendations" section in a structured format.
|
| 470 |
+
- Format each career path clearly with:
|
| 471 |
+
* Career name (use **bold** or similar emphasis) - MUST match exactly from recommendations
|
| 472 |
+
* Brief reason why it fits (use the reason from recommendations)
|
| 473 |
+
* Key next steps (use the next steps from recommendations)
|
| 474 |
+
- Use clear formatting with line breaks between each career path.
|
| 475 |
+
- Keep the overall message concise but informative.
|
| 476 |
+
- End with encouragement to ask follow-up questions.
|
| 477 |
+
- DO NOT add any careers that are not in the recommendations list above.
|
| 478 |
+
|
| 479 |
+
Respond with JSON {"reply":"...", "intent":"follow_up"}.`;
|
| 480 |
+
|
| 481 |
+
try {
|
| 482 |
+
// Use fewer retries for greeting (2 attempts max) since it's less critical
|
| 483 |
+
// If API is overloaded, we'll use fallback quickly
|
| 484 |
+
const response = await retryWithBackoff(
|
| 485 |
+
async () => {
|
| 486 |
+
const model = this.genAI.getGenerativeModel({ model: this.modelId });
|
| 487 |
+
const result = await model.generateContent(prompt);
|
| 488 |
+
return result.response.text();
|
| 489 |
+
},
|
| 490 |
+
{
|
| 491 |
+
maxAttempts: 2, // Only 2 attempts for greeting (vs 5+ for recommendations)
|
| 492 |
+
initialDelay: 2000,
|
| 493 |
+
}
|
| 494 |
+
);
|
| 495 |
+
|
| 496 |
+
return this.parseChatResponse(response, language);
|
| 497 |
+
} catch (error) {
|
| 498 |
+
console.error(
|
| 499 |
+
"Error generating initial greeting (using fallback):",
|
| 500 |
+
error
|
| 501 |
+
);
|
| 502 |
+
// Use formatted fallback that parses assessment summary
|
| 503 |
+
// This is fast and doesn't require API calls
|
| 504 |
+
return this.formatFallbackGreeting(assessmentSummary, language);
|
| 505 |
+
}
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
async generateRecommendations(
|
| 509 |
+
assessment: AssessmentPayload,
|
| 510 |
+
retryOptions?: RetryOptions,
|
| 511 |
+
riasecScores?: {
|
| 512 |
+
scores: { [code: string]: number };
|
| 513 |
+
top3: string;
|
| 514 |
+
ordered: Array<{ code: string; score: number }>;
|
| 515 |
+
} | null,
|
| 516 |
+
matchingCareers?: string[]
|
| 517 |
+
): Promise<AssessmentResponse> {
|
| 518 |
+
const prompt = this.buildRecommendationPrompt(
|
| 519 |
+
assessment,
|
| 520 |
+
riasecScores,
|
| 521 |
+
matchingCareers
|
| 522 |
+
);
|
| 523 |
+
|
| 524 |
+
try {
|
| 525 |
+
const response = await retryWithBackoff(async () => {
|
| 526 |
+
const model = this.genAI.getGenerativeModel({ model: this.modelId });
|
| 527 |
+
const result = await model.generateContent(prompt);
|
| 528 |
+
return result.response.text();
|
| 529 |
+
}, retryOptions);
|
| 530 |
+
|
| 531 |
+
const parsedResponse = this.parseRecommendationResponse(
|
| 532 |
+
response,
|
| 533 |
+
assessment.userProfile.language
|
| 534 |
+
);
|
| 535 |
+
|
| 536 |
+
// Validate and filter recommendations to only include careers from the matching list
|
| 537 |
+
if (matchingCareers && matchingCareers.length > 0) {
|
| 538 |
+
const validCareers = new Set(
|
| 539 |
+
matchingCareers.map((c) => c.toUpperCase().trim())
|
| 540 |
+
);
|
| 541 |
+
|
| 542 |
+
console.log(
|
| 543 |
+
`Validating ${parsedResponse.recommendations.length} recommendations against ${matchingCareers.length} valid careers`
|
| 544 |
+
);
|
| 545 |
+
console.log(
|
| 546 |
+
`Valid careers sample: ${Array.from(validCareers)
|
| 547 |
+
.slice(0, 5)
|
| 548 |
+
.join(", ")}`
|
| 549 |
+
);
|
| 550 |
+
|
| 551 |
+
const filteredRecommendations = parsedResponse.recommendations.filter(
|
| 552 |
+
(rec: CareerRecommendation) => {
|
| 553 |
+
const recTitle = rec.title.toUpperCase().trim();
|
| 554 |
+
|
| 555 |
+
// Remove common prefixes/suffixes that might be added by LLM
|
| 556 |
+
const cleanedTitle = recTitle
|
| 557 |
+
.replace(
|
| 558 |
+
/^(CHEF|CULINARY|FOOD|MECHANICAL|ENGINEER|SCIENTIST)\s+/i,
|
| 559 |
+
""
|
| 560 |
+
)
|
| 561 |
+
.replace(
|
| 562 |
+
/\s+(CHEF|CULINARY|FOOD|MECHANICAL|ENGINEER|SCIENTIST)$/i,
|
| 563 |
+
""
|
| 564 |
+
)
|
| 565 |
+
.trim();
|
| 566 |
+
|
| 567 |
+
// Check if the recommendation title matches any career in the list (case-insensitive, exact or partial match)
|
| 568 |
+
const matches = Array.from(validCareers).some((career) => {
|
| 569 |
+
const careerUpper = career.toUpperCase();
|
| 570 |
+
// Try exact match first
|
| 571 |
+
if (recTitle === careerUpper || cleanedTitle === careerUpper) {
|
| 572 |
+
return true;
|
| 573 |
+
}
|
| 574 |
+
// Try if career name is contained in recommendation (e.g., "INDUSTRIAL DESIGNER" matches "Industrial Designer")
|
| 575 |
+
if (
|
| 576 |
+
careerUpper.includes(recTitle) ||
|
| 577 |
+
recTitle.includes(careerUpper)
|
| 578 |
+
) {
|
| 579 |
+
return true;
|
| 580 |
+
}
|
| 581 |
+
// Try word-by-word matching for multi-word careers
|
| 582 |
+
const careerWords = careerUpper.split(/\s+/);
|
| 583 |
+
const recWords = recTitle.split(/\s+/);
|
| 584 |
+
if (careerWords.length > 1 && recWords.length > 1) {
|
| 585 |
+
// Check if all major words from career are in recommendation
|
| 586 |
+
const majorWords = careerWords.filter((w) => w.length > 3); // Skip short words like "THE", "AND"
|
| 587 |
+
if (
|
| 588 |
+
majorWords.length > 0 &&
|
| 589 |
+
majorWords.every((word) =>
|
| 590 |
+
recWords.some(
|
| 591 |
+
(rw) => rw.includes(word) || word.includes(rw)
|
| 592 |
+
)
|
| 593 |
+
)
|
| 594 |
+
) {
|
| 595 |
+
return true;
|
| 596 |
+
}
|
| 597 |
+
}
|
| 598 |
+
return false;
|
| 599 |
+
});
|
| 600 |
+
|
| 601 |
+
if (!matches) {
|
| 602 |
+
console.warn(
|
| 603 |
+
`❌ FILTERED OUT: "${
|
| 604 |
+
rec.title
|
| 605 |
+
}" (not in matching careers list). Valid careers are: ${Array.from(
|
| 606 |
+
validCareers
|
| 607 |
+
)
|
| 608 |
+
.slice(0, 10)
|
| 609 |
+
.join(", ")}...`
|
| 610 |
+
);
|
| 611 |
+
} else {
|
| 612 |
+
console.log(
|
| 613 |
+
`✅ VALID: "${rec.title}" matches a career in the list`
|
| 614 |
+
);
|
| 615 |
+
}
|
| 616 |
+
return matches;
|
| 617 |
+
}
|
| 618 |
+
);
|
| 619 |
+
|
| 620 |
+
if (
|
| 621 |
+
filteredRecommendations.length === 0 &&
|
| 622 |
+
parsedResponse.recommendations.length > 0
|
| 623 |
+
) {
|
| 624 |
+
console.warn(
|
| 625 |
+
`All recommendations were filtered out. Using first ${Math.min(
|
| 626 |
+
3,
|
| 627 |
+
matchingCareers.length
|
| 628 |
+
)} careers from matching list.`
|
| 629 |
+
);
|
| 630 |
+
// Fallback: use first few careers from matching list
|
| 631 |
+
return {
|
| 632 |
+
recommendations: matchingCareers
|
| 633 |
+
.slice(0, Math.min(3, matchingCareers.length))
|
| 634 |
+
.map((career) => ({
|
| 635 |
+
title: career,
|
| 636 |
+
confidence: 0.7,
|
| 637 |
+
reason: `Based on your RIASEC profile (${
|
| 638 |
+
riasecScores?.top3 || "N/A"
|
| 639 |
+
})`,
|
| 640 |
+
next_steps: [
|
| 641 |
+
"Research this career path",
|
| 642 |
+
"Talk to professionals in this field",
|
| 643 |
+
"Explore related opportunities",
|
| 644 |
+
],
|
| 645 |
+
})),
|
| 646 |
+
summary:
|
| 647 |
+
parsedResponse.summary ||
|
| 648 |
+
"Based on your assessment, here are some career paths to explore.",
|
| 649 |
+
smsMessage: parsedResponse.smsMessage,
|
| 650 |
+
};
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
return {
|
| 654 |
+
...parsedResponse,
|
| 655 |
+
recommendations: filteredRecommendations,
|
| 656 |
+
};
|
| 657 |
+
}
|
| 658 |
+
|
| 659 |
+
return parsedResponse;
|
| 660 |
+
} catch (error: any) {
|
| 661 |
+
console.error("Error generating recommendations:", error);
|
| 662 |
+
|
| 663 |
+
// Fallback: If we have matching careers, use them directly instead of generic fallback
|
| 664 |
+
if (matchingCareers && matchingCareers.length > 0) {
|
| 665 |
+
console.log(
|
| 666 |
+
`Using fallback with ${matchingCareers.length} matching careers from RIASEC`
|
| 667 |
+
);
|
| 668 |
+
return {
|
| 669 |
+
recommendations: matchingCareers
|
| 670 |
+
.slice(0, Math.min(4, matchingCareers.length))
|
| 671 |
+
.map((career) => ({
|
| 672 |
+
title: career,
|
| 673 |
+
confidence: 0.75,
|
| 674 |
+
reason: `Based on your RIASEC profile (${
|
| 675 |
+
riasecScores?.top3 || "N/A"
|
| 676 |
+
}), this career aligns with your interests and personality.`,
|
| 677 |
+
next_steps: [
|
| 678 |
+
"Research this career path in detail",
|
| 679 |
+
"Talk to professionals working in this field",
|
| 680 |
+
"Explore educational requirements and opportunities",
|
| 681 |
+
],
|
| 682 |
+
})),
|
| 683 |
+
summary:
|
| 684 |
+
"Based on your assessment results, here are some career paths that match your interests and personality. Explore these options to find what interests you most!",
|
| 685 |
+
smsMessage: `Your career recommendations: ${matchingCareers
|
| 686 |
+
.slice(0, 3)
|
| 687 |
+
.join(", ")}`,
|
| 688 |
+
};
|
| 689 |
+
}
|
| 690 |
+
|
| 691 |
+
// Final fallback to personalized response based on assessment data
|
| 692 |
+
return this.getFallbackRecommendations(assessment);
|
| 693 |
+
}
|
| 694 |
+
}
|
| 695 |
+
|
| 696 |
+
private buildRecommendationPrompt(
|
| 697 |
+
assessment: AssessmentPayload,
|
| 698 |
+
riasecScores?: {
|
| 699 |
+
scores: { [code: string]: number };
|
| 700 |
+
top3: string;
|
| 701 |
+
ordered: Array<{ code: string; score: number }>;
|
| 702 |
+
} | null,
|
| 703 |
+
matchingCareers?: string[]
|
| 704 |
+
): string {
|
| 705 |
+
const lang = assessment.userProfile.language;
|
| 706 |
+
const systemPrompt = this.getSystemPrompt(lang, "recommendation");
|
| 707 |
+
|
| 708 |
+
// Build assessment summary
|
| 709 |
+
let assessmentSummary = `Student: ${assessment.userProfile.name}, Class: ${assessment.userProfile.class}`;
|
| 710 |
+
if (assessment.userProfile.age) {
|
| 711 |
+
assessmentSummary += `, Age: ${assessment.userProfile.age}`;
|
| 712 |
+
}
|
| 713 |
+
assessmentSummary += `\n\nAssessment Results:\n`;
|
| 714 |
+
|
| 715 |
+
// Add RIASEC scores if available
|
| 716 |
+
if (riasecScores) {
|
| 717 |
+
assessmentSummary += `\nRIASEC Personality Assessment Results:\n`;
|
| 718 |
+
assessmentSummary += `Top 3 RIASEC Codes: ${riasecScores.top3}\n`;
|
| 719 |
+
assessmentSummary += `RIASEC Scores:\n`;
|
| 720 |
+
riasecScores.ordered.forEach(({ code, score }) => {
|
| 721 |
+
assessmentSummary += ` ${code}: ${score.toFixed(1)}%\n`;
|
| 722 |
+
});
|
| 723 |
+
|
| 724 |
+
if (matchingCareers && matchingCareers.length > 0) {
|
| 725 |
+
assessmentSummary += `\nMatching Careers from RIASEC Analysis (${matchingCareers.length} total):\n`;
|
| 726 |
+
assessmentSummary += `IMPORTANT: You MUST select careers ONLY from this list below:\n\n`;
|
| 727 |
+
// Limit to 25 careers to keep prompt size manageable
|
| 728 |
+
const maxCareersToShow = 25;
|
| 729 |
+
const careersToInclude = matchingCareers.slice(0, maxCareersToShow);
|
| 730 |
+
careersToInclude.forEach((career, idx) => {
|
| 731 |
+
assessmentSummary += ` ${idx + 1}. ${career}\n`;
|
| 732 |
+
});
|
| 733 |
+
if (matchingCareers.length > maxCareersToShow) {
|
| 734 |
+
assessmentSummary += ` ... and ${
|
| 735 |
+
matchingCareers.length - maxCareersToShow
|
| 736 |
+
} more careers (total: ${matchingCareers.length})\n`;
|
| 737 |
+
}
|
| 738 |
+
assessmentSummary += `\nREMINDER: You can ONLY recommend careers from the numbered list above. Do not suggest any other careers.\n`;
|
| 739 |
+
}
|
| 740 |
+
}
|
| 741 |
+
|
| 742 |
+
// Add test responses (summarized to reduce prompt size)
|
| 743 |
+
assessment.tests.forEach((test) => {
|
| 744 |
+
if (test.type === "riasec") {
|
| 745 |
+
// Skip detailed RIASEC answers since we have the scores
|
| 746 |
+
assessmentSummary += `\nRIASEC Test: Completed (see scores above)\n`;
|
| 747 |
+
} else {
|
| 748 |
+
const answers = Object.entries(test.answers);
|
| 749 |
+
assessmentSummary += `\n${test.type.toUpperCase()} Test (${
|
| 750 |
+
answers.length
|
| 751 |
+
} questions answered):\n`;
|
| 752 |
+
// Summarize answers instead of listing all
|
| 753 |
+
const answerSummary: Record<string, number> = {};
|
| 754 |
+
answers.forEach(([qId, answer]) => {
|
| 755 |
+
const answerStr = Array.isArray(answer)
|
| 756 |
+
? answer.join(", ")
|
| 757 |
+
: String(answer);
|
| 758 |
+
// Count common answer patterns
|
| 759 |
+
const key =
|
| 760 |
+
answerStr.length > 50
|
| 761 |
+
? answerStr.substring(0, 50) + "..."
|
| 762 |
+
: answerStr;
|
| 763 |
+
answerSummary[key] = (answerSummary[key] || 0) + 1;
|
| 764 |
+
});
|
| 765 |
+
// Include only first 10 unique answers to keep prompt small
|
| 766 |
+
const uniqueAnswers = Object.keys(answerSummary).slice(0, 10);
|
| 767 |
+
uniqueAnswers.forEach((answer, idx) => {
|
| 768 |
+
assessmentSummary += ` - ${answer}\n`;
|
| 769 |
+
});
|
| 770 |
+
if (answers.length > 10) {
|
| 771 |
+
assessmentSummary += ` ... and ${
|
| 772 |
+
answers.length - 10
|
| 773 |
+
} more responses\n`;
|
| 774 |
+
}
|
| 775 |
+
}
|
| 776 |
+
});
|
| 777 |
+
|
| 778 |
+
// Build instruction for LLM
|
| 779 |
+
let instruction = `\n\n=== CRITICAL INSTRUCTIONS ===\n`;
|
| 780 |
+
if (matchingCareers && matchingCareers.length > 0) {
|
| 781 |
+
instruction += `You MUST ONLY recommend careers from the "Matching Careers from RIASEC Analysis" list above.\n`;
|
| 782 |
+
instruction += `You have ${matchingCareers.length} careers to choose from. DO NOT invent, suggest, or recommend any careers that are NOT in that numbered list.\n\n`;
|
| 783 |
+
instruction += `STEP 1: Look at the numbered list of careers above (lines starting with numbers like "1.", "2.", etc.)\n`;
|
| 784 |
+
instruction += `STEP 2: From that list, select 4-5 careers that best match the student's values test responses and personal information\n`;
|
| 785 |
+
instruction += `STEP 3: For each selected career, use the EXACT career name as it appears in the numbered list\n`;
|
| 786 |
+
instruction += `STEP 4: Generate recommendations ONLY for those selected careers\n\n`;
|
| 787 |
+
instruction += `FORBIDDEN: Do NOT recommend careers like "Chef", "Food Scientist", "Historian", "Archaeologist" or any other careers UNLESS they appear in the numbered list above.\n`;
|
| 788 |
+
instruction += `If you cannot find a suitable career in the list, you must still only recommend careers from that list.\n\n`;
|
| 789 |
+
}
|
| 790 |
+
instruction += `Each recommendation must include:\n`;
|
| 791 |
+
instruction += `- Career title (EXACT name from the numbered list above - copy it exactly)\n`;
|
| 792 |
+
instruction += `- Why this career fits (based on RIASEC codes ${
|
| 793 |
+
riasecScores ? `(${riasecScores.top3})` : ""
|
| 794 |
+
}, values test responses, and personal information)\n`;
|
| 795 |
+
instruction += `- Next steps to pursue this career\n`;
|
| 796 |
+
instruction += `- Confidence/match percentage\n\n`;
|
| 797 |
+
instruction += `Remember: Only use career names from the numbered list. No exceptions.\n\n`;
|
| 798 |
+
instruction += `Generate recommendations now:`;
|
| 799 |
+
|
| 800 |
+
return `${systemPrompt}\n\n${assessmentSummary}${instruction}`;
|
| 801 |
+
}
|
| 802 |
+
|
| 803 |
+
private parseRecommendationResponse(
|
| 804 |
+
response: string,
|
| 805 |
+
language: Language
|
| 806 |
+
): AssessmentResponse {
|
| 807 |
+
try {
|
| 808 |
+
// Try to extract JSON from response (might have markdown code blocks)
|
| 809 |
+
let jsonStr = response.trim();
|
| 810 |
+
|
| 811 |
+
// Remove markdown code blocks if present
|
| 812 |
+
if (jsonStr.startsWith("```")) {
|
| 813 |
+
jsonStr = jsonStr
|
| 814 |
+
.replace(/^```(?:json)?\n?/, "")
|
| 815 |
+
.replace(/\n?```$/, "");
|
| 816 |
+
}
|
| 817 |
+
|
| 818 |
+
const parsed = JSON.parse(jsonStr);
|
| 819 |
+
|
| 820 |
+
// Validate structure
|
| 821 |
+
if (!parsed.recommendations || !Array.isArray(parsed.recommendations)) {
|
| 822 |
+
throw new Error("Invalid response structure");
|
| 823 |
+
}
|
| 824 |
+
|
| 825 |
+
// Generate SMS message
|
| 826 |
+
const smsMessage = this.generateSMSMessage(parsed, language);
|
| 827 |
+
|
| 828 |
+
return {
|
| 829 |
+
recommendations: parsed.recommendations,
|
| 830 |
+
summary:
|
| 831 |
+
parsed.summary ||
|
| 832 |
+
"Based on your assessment, we have some great career paths for you!",
|
| 833 |
+
smsMessage,
|
| 834 |
+
};
|
| 835 |
+
} catch (error) {
|
| 836 |
+
console.error("Failed to parse recommendation response:", error);
|
| 837 |
+
throw new Error("Invalid response format from AI");
|
| 838 |
+
}
|
| 839 |
+
}
|
| 840 |
+
|
| 841 |
+
private generateSMSMessage(data: any, language: Language): string {
|
| 842 |
+
const lang = language;
|
| 843 |
+
const recommendations = data.recommendations || [];
|
| 844 |
+
|
| 845 |
+
if (lang === "en") {
|
| 846 |
+
let sms = `Hi! Your career recommendations: `;
|
| 847 |
+
recommendations
|
| 848 |
+
.slice(0, 2)
|
| 849 |
+
.forEach((rec: CareerRecommendation, idx: number) => {
|
| 850 |
+
sms += `${idx + 1}. ${rec.title} `;
|
| 851 |
+
});
|
| 852 |
+
sms += `- ${data.summary || "Explore these paths!"}`;
|
| 853 |
+
return sms.substring(0, 160); // SMS length limit
|
| 854 |
+
}
|
| 855 |
+
|
| 856 |
+
// For other languages, keep it simple
|
| 857 |
+
return data.summary || "Your career recommendations are ready!";
|
| 858 |
+
}
|
| 859 |
+
|
| 860 |
+
private getFallbackRecommendations(
|
| 861 |
+
assessment: AssessmentPayload
|
| 862 |
+
): AssessmentResponse {
|
| 863 |
+
const language = assessment.userProfile.language;
|
| 864 |
+
|
| 865 |
+
// Analyze assessment answers to provide personalized recommendations
|
| 866 |
+
const analysis = this.analyzeAssessment(assessment);
|
| 867 |
+
|
| 868 |
+
// Generate recommendations based on analysis
|
| 869 |
+
return this.generatePersonalizedFallback(analysis, language);
|
| 870 |
+
}
|
| 871 |
+
|
| 872 |
+
private analyzeAssessment(assessment: AssessmentPayload): {
|
| 873 |
+
techInterest: number;
|
| 874 |
+
analyticalStrength: number;
|
| 875 |
+
creativeInterest: number;
|
| 876 |
+
socialInterest: number;
|
| 877 |
+
businessInterest: number;
|
| 878 |
+
preferredSubjects: string[];
|
| 879 |
+
careerInterest?: string;
|
| 880 |
+
} {
|
| 881 |
+
let techInterest = 0;
|
| 882 |
+
let analyticalStrength = 0;
|
| 883 |
+
let creativeInterest = 0;
|
| 884 |
+
let socialInterest = 0;
|
| 885 |
+
let businessInterest = 0;
|
| 886 |
+
const preferredSubjects: string[] = [];
|
| 887 |
+
let careerInterest: string | undefined;
|
| 888 |
+
|
| 889 |
+
// Analyze each test
|
| 890 |
+
assessment.tests.forEach((test) => {
|
| 891 |
+
if (test.type === "riasec") {
|
| 892 |
+
// Analyze RIASEC answers
|
| 893 |
+
Object.values(test.answers).forEach((answer) => {
|
| 894 |
+
const answerStr = Array.isArray(answer)
|
| 895 |
+
? answer.join(" ")
|
| 896 |
+
: String(answer).toLowerCase();
|
| 897 |
+
|
| 898 |
+
// Tech/analytical indicators
|
| 899 |
+
if (
|
| 900 |
+
answerStr.includes("agree") ||
|
| 901 |
+
answerStr.includes("strongly agree")
|
| 902 |
+
) {
|
| 903 |
+
// Questions about numbers, logic, problem-solving suggest tech/analytical
|
| 904 |
+
techInterest += 0.1;
|
| 905 |
+
analyticalStrength += 0.1;
|
| 906 |
+
}
|
| 907 |
+
|
| 908 |
+
// Creative indicators
|
| 909 |
+
if (
|
| 910 |
+
answerStr.includes("disagree") &&
|
| 911 |
+
answerStr.includes("creative")
|
| 912 |
+
) {
|
| 913 |
+
creativeInterest -= 0.1;
|
| 914 |
+
} else if (
|
| 915 |
+
answerStr.includes("agree") &&
|
| 916 |
+
answerStr.includes("creative")
|
| 917 |
+
) {
|
| 918 |
+
creativeInterest += 0.1;
|
| 919 |
+
}
|
| 920 |
+
|
| 921 |
+
// Social indicators
|
| 922 |
+
if (
|
| 923 |
+
answerStr.includes("group") ||
|
| 924 |
+
answerStr.includes("discussion") ||
|
| 925 |
+
answerStr.includes("speak")
|
| 926 |
+
) {
|
| 927 |
+
if (answerStr.includes("agree")) {
|
| 928 |
+
socialInterest += 0.15;
|
| 929 |
+
}
|
| 930 |
+
}
|
| 931 |
+
});
|
| 932 |
+
} else if (test.type === "values") {
|
| 933 |
+
// Analyze values - look for business, stability, impact indicators
|
| 934 |
+
Object.values(test.answers).forEach((answer) => {
|
| 935 |
+
const answerStr = Array.isArray(answer)
|
| 936 |
+
? answer.join(" ")
|
| 937 |
+
: String(answer).toLowerCase();
|
| 938 |
+
|
| 939 |
+
if (
|
| 940 |
+
answerStr.includes("salary") ||
|
| 941 |
+
answerStr.includes("stable") ||
|
| 942 |
+
answerStr.includes("benefits")
|
| 943 |
+
) {
|
| 944 |
+
if (answerStr.includes("agree")) {
|
| 945 |
+
businessInterest += 0.1;
|
| 946 |
+
}
|
| 947 |
+
}
|
| 948 |
+
|
| 949 |
+
if (
|
| 950 |
+
answerStr.includes("community") ||
|
| 951 |
+
answerStr.includes("society") ||
|
| 952 |
+
answerStr.includes("impact")
|
| 953 |
+
) {
|
| 954 |
+
if (answerStr.includes("agree")) {
|
| 955 |
+
socialInterest += 0.1;
|
| 956 |
+
}
|
| 957 |
+
}
|
| 958 |
+
});
|
| 959 |
+
} else if (test.type === "personal") {
|
| 960 |
+
// Extract personal preferences
|
| 961 |
+
Object.entries(test.answers).forEach(([qId, answer]) => {
|
| 962 |
+
if (qId === "53") {
|
| 963 |
+
// Preferred subjects
|
| 964 |
+
if (Array.isArray(answer)) {
|
| 965 |
+
preferredSubjects.push(...answer);
|
| 966 |
+
}
|
| 967 |
+
} else if (qId === "54") {
|
| 968 |
+
// Career interest
|
| 969 |
+
if (typeof answer === "string" && answer.trim().length > 0) {
|
| 970 |
+
careerInterest = answer;
|
| 971 |
+
}
|
| 972 |
+
}
|
| 973 |
+
});
|
| 974 |
+
}
|
| 975 |
+
});
|
| 976 |
+
|
| 977 |
+
// Normalize scores (0-1 range)
|
| 978 |
+
const normalize = (val: number, max: number) => Math.min(1, val / max);
|
| 979 |
+
|
| 980 |
+
return {
|
| 981 |
+
techInterest: normalize(techInterest, 1.5),
|
| 982 |
+
analyticalStrength: normalize(analyticalStrength, 1.5),
|
| 983 |
+
creativeInterest: normalize(creativeInterest, 1.0),
|
| 984 |
+
socialInterest: normalize(socialInterest, 1.5),
|
| 985 |
+
businessInterest: normalize(businessInterest, 1.0),
|
| 986 |
+
preferredSubjects,
|
| 987 |
+
careerInterest,
|
| 988 |
+
};
|
| 989 |
+
}
|
| 990 |
+
|
| 991 |
+
private generatePersonalizedFallback(
|
| 992 |
+
analysis: {
|
| 993 |
+
techInterest: number;
|
| 994 |
+
analyticalStrength: number;
|
| 995 |
+
creativeInterest: number;
|
| 996 |
+
socialInterest: number;
|
| 997 |
+
businessInterest: number;
|
| 998 |
+
preferredSubjects: string[];
|
| 999 |
+
careerInterest?: string;
|
| 1000 |
+
},
|
| 1001 |
+
language: Language
|
| 1002 |
+
): AssessmentResponse {
|
| 1003 |
+
// Define career options with scoring weights
|
| 1004 |
+
const careerOptions = [
|
| 1005 |
+
{
|
| 1006 |
+
title: {
|
| 1007 |
+
en: "Software Developer",
|
| 1008 |
+
hi: "सॉफ्टवेयर डेवलपर",
|
| 1009 |
+
te: "సాఫ్ట్వేర్ డెవలపర్",
|
| 1010 |
+
ta: "மென்பொருள் உருவாக்குநர்",
|
| 1011 |
+
bn: "সফটওয়্যার ডেভেলপার",
|
| 1012 |
+
gu: "સોફ્ટવેર ડેવલપર",
|
| 1013 |
+
},
|
| 1014 |
+
score: analysis.techInterest * 0.6 + analysis.analyticalStrength * 0.4,
|
| 1015 |
+
reason: {
|
| 1016 |
+
en: (subjects: string[]) => {
|
| 1017 |
+
if (
|
| 1018 |
+
subjects.some(
|
| 1019 |
+
(s) =>
|
| 1020 |
+
s.toLowerCase().includes("computer") ||
|
| 1021 |
+
s.toLowerCase().includes("coding")
|
| 1022 |
+
)
|
| 1023 |
+
) {
|
| 1024 |
+
return "Your interest in computer science and technology makes software development a great fit";
|
| 1025 |
+
}
|
| 1026 |
+
return "Your analytical thinking and problem-solving skills align well with software development";
|
| 1027 |
+
},
|
| 1028 |
+
hi: (subjects: string[]) => {
|
| 1029 |
+
if (
|
| 1030 |
+
subjects.some(
|
| 1031 |
+
(s) =>
|
| 1032 |
+
s.toLowerCase().includes("computer") ||
|
| 1033 |
+
s.toLowerCase().includes("coding")
|
| 1034 |
+
)
|
| 1035 |
+
) {
|
| 1036 |
+
return "कंप्यूटर विज्ञान और प्रौद्योगिकी में आपकी रुचि सॉफ्टवेयर विकास को एक बेहतरीन विकल्प बनाती है";
|
| 1037 |
+
}
|
| 1038 |
+
return "आपकी विश्लेषणात्मक सोच और समस्या-समाधान कौशल सॉफ्टवेयर विकास के साथ अच्छी तरह से मेल खाते हैं";
|
| 1039 |
+
},
|
| 1040 |
+
te: (subjects: string[]) => {
|
| 1041 |
+
if (
|
| 1042 |
+
subjects.some(
|
| 1043 |
+
(s) =>
|
| 1044 |
+
s.toLowerCase().includes("computer") ||
|
| 1045 |
+
s.toLowerCase().includes("coding")
|
| 1046 |
+
)
|
| 1047 |
+
) {
|
| 1048 |
+
return "కంప్యూటర్ సైన్స్ మరియు టెక్నాలజీలో మీ ఆసక్తి సాఫ్ట్వేర్ డెవలప్మెంట్ను గొప్ప ఎంపికగా చేస్తుంది";
|
| 1049 |
+
}
|
| 1050 |
+
return "మీ విశ్లేషణాత్మక ఆలోచన మరియు సమస్య-పరిష్కార నైపుణ్యాలు సాఫ్ట్వేర్ డెవలప్మెంట్తో బాగా సరిపోతాయి";
|
| 1051 |
+
},
|
| 1052 |
+
ta: (subjects: string[]) => {
|
| 1053 |
+
if (
|
| 1054 |
+
subjects.some(
|
| 1055 |
+
(s) =>
|
| 1056 |
+
s.toLowerCase().includes("computer") ||
|
| 1057 |
+
s.toLowerCase().includes("coding")
|
| 1058 |
+
)
|
| 1059 |
+
) {
|
| 1060 |
+
return "கணினி அறிவியல் மற்றும் தொழில்நுட்பத்தில் உங்கள் ஆர்வம் மென்பொருள் உருவாக்கத்தை சிறந்த தேர்வாக்குகிறது";
|
| 1061 |
+
}
|
| 1062 |
+
return "உங்கள் பகுப்பாய்வு சிந்தனை மற்றும் சிக்கல் தீர்ப்பு திறன்கள் மென்பொருள் உருவாக்கத்துடன் நன்றாக பொருந்துகின்றன";
|
| 1063 |
+
},
|
| 1064 |
+
bn: (subjects: string[]) => {
|
| 1065 |
+
if (
|
| 1066 |
+
subjects.some(
|
| 1067 |
+
(s) =>
|
| 1068 |
+
s.toLowerCase().includes("computer") ||
|
| 1069 |
+
s.toLowerCase().includes("coding")
|
| 1070 |
+
)
|
| 1071 |
+
) {
|
| 1072 |
+
return "কম্পিউটার বিজ্ঞান এবং প্রযুক্তিতে আপনার আগ্রহ সফটওয়্যার ডেভেলপমেন্টকে একটি দুর্দান্ত পছন্দ করে তোলে";
|
| 1073 |
+
}
|
| 1074 |
+
return "আপনার বিশ্লেষণাত্মক চিন্তাভাবনা এবং সমস্যা সমাধানের দক্ষতা সফটওয়্যার ���েভেলপমেন্টের সাথে ভালভাবে মিলে যায়";
|
| 1075 |
+
},
|
| 1076 |
+
gu: (subjects: string[]) => {
|
| 1077 |
+
if (
|
| 1078 |
+
subjects.some(
|
| 1079 |
+
(s) =>
|
| 1080 |
+
s.toLowerCase().includes("computer") ||
|
| 1081 |
+
s.toLowerCase().includes("coding")
|
| 1082 |
+
)
|
| 1083 |
+
) {
|
| 1084 |
+
return "કમ્પ્યુટર સાયન્સ અને ટેક્નોલોજીમાં તમારી રુચિ સોફ્ટવેર ડેવલપમેન્ટને એક મહાન પસંદગી બનાવે છે";
|
| 1085 |
+
}
|
| 1086 |
+
return "તમારી વિશ્લેષણાત્મક વિચારસરણી અને સમસ્યા-ઉકેલ કુશળતા સોફ્ટવેર ડેવલપમેન્ટ સાથે સારી રીતે મેળ ખાય છે";
|
| 1087 |
+
},
|
| 1088 |
+
},
|
| 1089 |
+
nextSteps: {
|
| 1090 |
+
en: [
|
| 1091 |
+
"Learn programming basics (Python or JavaScript)",
|
| 1092 |
+
"Build small projects",
|
| 1093 |
+
"Take computer science courses",
|
| 1094 |
+
],
|
| 1095 |
+
hi: [
|
| 1096 |
+
"प्रोग्रामिंग की मूल बातें सीखें (Python या JavaScript)",
|
| 1097 |
+
"छोटी परियोजनाएं बनाएं",
|
| 1098 |
+
"कंप्यूटर विज्ञान पाठ्यक्रम लें",
|
| 1099 |
+
],
|
| 1100 |
+
te: [
|
| 1101 |
+
"ప్రోగ్రామింగ్ ప్రాథమికాలు నేర్చుకోండి (Python లేదా JavaScript)",
|
| 1102 |
+
"చిన్న ప్రాజెక్ట్లను నిర్మించండి",
|
| 1103 |
+
"కంప్యూటర్ సైన్స్ కోర్సులు తీసుకోండి",
|
| 1104 |
+
],
|
| 1105 |
+
ta: [
|
| 1106 |
+
"நிரலாக்க அடிப்படைகளைக் கற்றுக்கொள்ளுங்கள் (Python அல்லது JavaScript)",
|
| 1107 |
+
"சிறிய திட்டங்களை உருவாக்குங்கள்",
|
| 1108 |
+
"கணினி அறிவியல் படிப்புகளை எடுத்துக்கொள்ளுங்கள்",
|
| 1109 |
+
],
|
| 1110 |
+
bn: [
|
| 1111 |
+
"প্রোগ্রামিং বেসিক শিখুন (Python বা JavaScript)",
|
| 1112 |
+
"ছোট প্রজেক্ট তৈরি করুন",
|
| 1113 |
+
"কম্পিউটার সায়েন্স কোর্স নিন",
|
| 1114 |
+
],
|
| 1115 |
+
gu: [
|
| 1116 |
+
"પ્રોગ્રામિંગ મૂળભૂત જાણો (Python અથવા JavaScript)",
|
| 1117 |
+
"નાના પ્રોજેક્ટ બનાવો",
|
| 1118 |
+
"કમ્પ્યુટર સાયન્સ કોર્સ લો",
|
| 1119 |
+
],
|
| 1120 |
+
},
|
| 1121 |
+
},
|
| 1122 |
+
{
|
| 1123 |
+
title: {
|
| 1124 |
+
en: "Data Analyst",
|
| 1125 |
+
hi: "डेटा विश्लेषक",
|
| 1126 |
+
te: "డేటా విశ్లేషకుడు",
|
| 1127 |
+
ta: "தரவு பகுப்பாய்வாளர்",
|
| 1128 |
+
bn: "ডেটা অ্যানালিস্ট",
|
| 1129 |
+
gu: "ડેટા એનાલિસ્ટ",
|
| 1130 |
+
},
|
| 1131 |
+
score: analysis.analyticalStrength * 0.7 + analysis.techInterest * 0.3,
|
| 1132 |
+
reason: {
|
| 1133 |
+
en: () =>
|
| 1134 |
+
"Your strong analytical skills and attention to detail make data analysis a great fit",
|
| 1135 |
+
hi: () =>
|
| 1136 |
+
"आपके मजबूत विश्लेषणात्मक कौशल और विवरण पर ध्यान डेटा विश्लेषण को एक बेहतरीन विकल्प बनाते हैं",
|
| 1137 |
+
te: () =>
|
| 1138 |
+
"మీ బలమైన విశ్లేషణాత్మక నైపుణ్యాలు మరియు వివరాలపై శ్రద్ధ డేటా విశ్లేషణను గొప్ప ఎంపికగా చేస్తాయి",
|
| 1139 |
+
ta: () =>
|
| 1140 |
+
"உங்கள் வலுவான பகுப்பாய்வு திறன்கள் மற்றும் விவரங்களில் கவனம் தரவு பகுப்பாய்வை சிறந்த தேர்வாக்குகிறது",
|
| 1141 |
+
bn: () =>
|
| 1142 |
+
"আপনার শক্তিশালী বিশ্লেষণাত্মক দক্ষতা এবং বিস্তারিত বিবরণে মনোযোগ ডেটা অ্যানালাইসিসকে একটি দুর্দান্ত পছন্দ করে তোলে",
|
| 1143 |
+
gu: () =>
|
| 1144 |
+
"તમારી મજબૂત વિશ્લેષણાત્મક કુશળતા અને વિગતો પર ધ્યાન ડેટા વિશ્લેષણને એક મહાન પસંદગી બનાવે છે",
|
| 1145 |
+
} as Record<Language, (subjects?: string[]) => string>,
|
| 1146 |
+
nextSteps: {
|
| 1147 |
+
en: [
|
| 1148 |
+
"Learn statistics and data visualization",
|
| 1149 |
+
"Practice with Excel and data tools",
|
| 1150 |
+
"Explore data science courses",
|
| 1151 |
+
],
|
| 1152 |
+
hi: [
|
| 1153 |
+
"सांख्यिकी और डेटा विज़ुअलाइज़ेशन सीखें",
|
| 1154 |
+
"Excel और डेटा टूल्स के साथ अभ्यास करें",
|
| 1155 |
+
"डेटा साइंस पाठ्यक्रमों का अन्वेषण करें",
|
| 1156 |
+
],
|
| 1157 |
+
te: [
|
| 1158 |
+
"గణాంకాలు మరియు డేటా విజువలైజేషన్ నేర్చుకోండి",
|
| 1159 |
+
"Excel మరియు డేటా టూల్స్తో ప్రాక్టీస్ చేయండి",
|
| 1160 |
+
"డేటా సైన్స్ కోర్సులను అన్వేషించండి",
|
| 1161 |
+
],
|
| 1162 |
+
ta: [
|
| 1163 |
+
"புள்ளிவிவரங்கள் மற்றும் தரவு காட்சிப்படுத்தலைக் கற்றுக்கொள்ளுங்கள்",
|
| 1164 |
+
"Excel மற்றும் தரவு கருவிகளுடன் பயிற்சி செய்யுங்கள்",
|
| 1165 |
+
"தரவு அறிவியல் படிப்புகளை ஆராயுங்கள்",
|
| 1166 |
+
],
|
| 1167 |
+
bn: [
|
| 1168 |
+
"পরিসংখ্যান এবং ডেটা ভিজ্যুয়ালাইজেশন শিখুন",
|
| 1169 |
+
"Excel এবং ডেটা টুলস দিয়ে অনুশীলন করুন",
|
| 1170 |
+
"ডেটা সায়েন্স কোর্স অন্বেষণ করুন",
|
| 1171 |
+
],
|
| 1172 |
+
gu: [
|
| 1173 |
+
"આંકડાશાસ્ત્ર અને ડેટા વિઝ્યુઅલાઇઝેશન શીખો",
|
| 1174 |
+
"Excel અને ડેટા ટૂલ્સ સાથે પ્રેક્ટિસ કરો",
|
| 1175 |
+
"ડેટા સાયન્સ કોર્સ અન્વેષણ કરો",
|
| 1176 |
+
],
|
| 1177 |
+
},
|
| 1178 |
+
},
|
| 1179 |
+
{
|
| 1180 |
+
title: {
|
| 1181 |
+
en: "Engineering",
|
| 1182 |
+
hi: "इंजीनियरिंग",
|
| 1183 |
+
te: "ఇంజనీరింగ్",
|
| 1184 |
+
ta: "பொறியியல்",
|
| 1185 |
+
bn: "ইঞ্জিনিয়ারিং",
|
| 1186 |
+
gu: "એન્જિનિયરિંગ",
|
| 1187 |
+
},
|
| 1188 |
+
score:
|
| 1189 |
+
analysis.analyticalStrength * 0.5 +
|
| 1190 |
+
(analysis.preferredSubjects.some(
|
| 1191 |
+
(s) =>
|
| 1192 |
+
s.toLowerCase().includes("math") ||
|
| 1193 |
+
s.toLowerCase().includes("science")
|
| 1194 |
+
)
|
| 1195 |
+
? 0.3
|
| 1196 |
+
: 0) +
|
| 1197 |
+
0.2,
|
| 1198 |
+
reason: {
|
| 1199 |
+
en: (subjects: string[]) => {
|
| 1200 |
+
if (
|
| 1201 |
+
subjects.some(
|
| 1202 |
+
(s) =>
|
| 1203 |
+
s.toLowerCase().includes("math") ||
|
| 1204 |
+
s.toLowerCase().includes("science")
|
| 1205 |
+
)
|
| 1206 |
+
) {
|
| 1207 |
+
return "Your strong foundation in math and science subjects makes engineering a natural fit";
|
| 1208 |
+
}
|
| 1209 |
+
return "Your analytical thinking and problem-solving approach align well with engineering";
|
| 1210 |
+
},
|
| 1211 |
+
hi: (subjects: string[]) => {
|
| 1212 |
+
if (
|
| 1213 |
+
subjects.some(
|
| 1214 |
+
(s) =>
|
| 1215 |
+
s.toLowerCase().includes("math") ||
|
| 1216 |
+
s.toLowerCase().includes("science")
|
| 1217 |
+
)
|
| 1218 |
+
) {
|
| 1219 |
+
return "गणित और विज्ञान विषयों में आपकी मजबूत नींव इंजीनियरिंग को एक प्राकृतिक फिट बनाती है";
|
| 1220 |
+
}
|
| 1221 |
+
return "आपकी विश्लेषणात्मक सोच और समस्या-समाधान दृष्टिकोण इंजीनियरिंग के साथ अच्छी तरह से मेल खाता है";
|
| 1222 |
+
},
|
| 1223 |
+
te: (subjects: string[]) => {
|
| 1224 |
+
if (
|
| 1225 |
+
subjects.some(
|
| 1226 |
+
(s) =>
|
| 1227 |
+
s.toLowerCase().includes("math") ||
|
| 1228 |
+
s.toLowerCase().includes("science")
|
| 1229 |
+
)
|
| 1230 |
+
) {
|
| 1231 |
+
return "గణితం మరియు సైన్స్ విషయాలలో మీ బలమైన పునాది ఇంజనీరింగ్ను సహజమైన ఎంపికగా చేస్తుంది";
|
| 1232 |
+
}
|
| 1233 |
+
return "మీ విశ్లేషణాత్మక ఆలోచన మరియు సమస్య-పరిష్కార విధానం ఇంజనీరింగ్తో బాగా సరిపోతుంది";
|
| 1234 |
+
},
|
| 1235 |
+
ta: (subjects: string[]) => {
|
| 1236 |
+
if (
|
| 1237 |
+
subjects.some(
|
| 1238 |
+
(s) =>
|
| 1239 |
+
s.toLowerCase().includes("math") ||
|
| 1240 |
+
s.toLowerCase().includes("science")
|
| 1241 |
+
)
|
| 1242 |
+
) {
|
| 1243 |
+
return "கணிதம் மற்றும் அறிவியல் பாடங்களில் உங்கள் வலுவான அடித்தளம் பொறியியலை இயற்கையான பொருத்தமாக்குகிறது";
|
| 1244 |
+
}
|
| 1245 |
+
return "உங்கள் பகுப்பாய்வு சிந்தனை மற்றும் சிக்கல் தீர்ப்பு அணுகுமுறை பொறியியலுடன் நன்றாக பொருந்துகிறது";
|
| 1246 |
+
},
|
| 1247 |
+
bn: (subjects: string[]) => {
|
| 1248 |
+
if (
|
| 1249 |
+
subjects.some(
|
| 1250 |
+
(s) =>
|
| 1251 |
+
s.toLowerCase().includes("math") ||
|
| 1252 |
+
s.toLowerCase().includes("science")
|
| 1253 |
+
)
|
| 1254 |
+
) {
|
| 1255 |
+
return "গণিত এবং বিজ্ঞান বিষয়ে আপনার শক্তিশালী ভিত্তি ইঞ্জিনিয়ারিংকে একটি প্রাকৃতিক ফিট করে তোলে";
|
| 1256 |
+
}
|
| 1257 |
+
return "আপনার বিশ্লেষণাত্মক চিন্তাভাবনা এবং সমস্যা সমাধানের পদ্ধতি ইঞ্জিনিয়ারিংয়ের সাথে ভালভাবে মিলে যায়";
|
| 1258 |
+
},
|
| 1259 |
+
gu: (subjects: string[]) => {
|
| 1260 |
+
if (
|
| 1261 |
+
subjects.some(
|
| 1262 |
+
(s) =>
|
| 1263 |
+
s.toLowerCase().includes("math") ||
|
| 1264 |
+
s.toLowerCase().includes("science")
|
| 1265 |
+
)
|
| 1266 |
+
) {
|
| 1267 |
+
return "ગણિત અને વિજ્ઞાન વિષયોમાં તમારી મજબૂત પાયો એન્જિનિયરિંગને કુદરતી ફિટ બનાવે છે";
|
| 1268 |
+
}
|
| 1269 |
+
return "તમારી વિશ્લેષણાત્મક વિચારસરણી અને સમસ્યા-ઉકેલ અભિગમ એન્જિનિયરિંગ સાથે સારી રીતે મેળ ખાય છે";
|
| 1270 |
+
},
|
| 1271 |
+
},
|
| 1272 |
+
nextSteps: {
|
| 1273 |
+
en: [
|
| 1274 |
+
"Focus on math and science subjects",
|
| 1275 |
+
"Join engineering clubs or competitions",
|
| 1276 |
+
"Research different engineering disciplines",
|
| 1277 |
+
],
|
| 1278 |
+
hi: [
|
| 1279 |
+
"गणित और विज्ञान विषयों पर ध्यान दें",
|
| 1280 |
+
"इंजीनियरिंग क्लब या प्रतियोगिताओं में शामिल हों",
|
| 1281 |
+
"विभिन्न इंजीनियरिंग विषयों पर शोध करें",
|
| 1282 |
+
],
|
| 1283 |
+
te: [
|
| 1284 |
+
"గణితం మరియు సైన్స్ విషయాలపై దృష్టి పెట్టండి",
|
| 1285 |
+
"ఇంజనీరింగ్ క్లబ్లు లేదా పోటీలలో చేరండి",
|
| 1286 |
+
"వివిధ ఇంజనీరింగ్ విభాగాలపై పరిశోధన చేయండి",
|
| 1287 |
+
],
|
| 1288 |
+
ta: [
|
| 1289 |
+
"கணிதம் மற்றும் அறிவியல் பாடங்களில் கவனம் செலுத்துங்கள்",
|
| 1290 |
+
"பொறியியல் கழகங்கள் அல்லது போட்டிகளில் சேரவும்",
|
| 1291 |
+
"வெவ்வேறு பொறியியல் துறைகளை ஆராயுங்கள்",
|
| 1292 |
+
],
|
| 1293 |
+
bn: [
|
| 1294 |
+
"গণিত এবং বিজ্ঞান বিষয়ে ফোকাস করুন",
|
| 1295 |
+
"ইঞ্জিনিয়ারিং ক্লাব বা প্রতিযোগিতায় যোগ দিন",
|
| 1296 |
+
"বিভিন্ন ইঞ্জিনিয়ারিং শাখা নিয়ে গবেষণা করুন",
|
| 1297 |
+
],
|
| 1298 |
+
gu: [
|
| 1299 |
+
"ગણિત અને વિજ્ઞાન વિષયો પર ધ્યાન કેન્દ્રિત કરો",
|
| 1300 |
+
"એન્જિનિયરિંગ ક્લબ અથવા સ્પર્ધાઓમાં જોડાઓ",
|
| 1301 |
+
"વિવિધ એન્જિનિયરિંગ શાખાઓ પર સંશોધન કરો",
|
| 1302 |
+
],
|
| 1303 |
+
},
|
| 1304 |
+
},
|
| 1305 |
+
{
|
| 1306 |
+
title: {
|
| 1307 |
+
en: "Business & Management",
|
| 1308 |
+
hi: "व्यवसाय और प्रबंधन",
|
| 1309 |
+
te: "వ్యాపారం మరియు నిర్వహణ",
|
| 1310 |
+
ta: "வணிகம் மற்றும் மேலாண்மை",
|
| 1311 |
+
bn: "ব্যবসা ও ব্যবস্থাপনা",
|
| 1312 |
+
gu: "વ્યવસાય અને વ્યવસ્થાપન",
|
| 1313 |
+
},
|
| 1314 |
+
score: analysis.businessInterest * 0.6 + analysis.socialInterest * 0.4,
|
| 1315 |
+
reason: {
|
| 1316 |
+
en: () =>
|
| 1317 |
+
"Your interest in leadership and strategic thinking makes business and management a great fit",
|
| 1318 |
+
hi: () =>
|
| 1319 |
+
"नेतृत्व और रणनीतिक सोच में आपकी रुचि व्यवसाय और प्रबंधन को एक बेहतरीन विकल्प बनाती है",
|
| 1320 |
+
te: () =>
|
| 1321 |
+
"నాయకత్వం మరియు వ్యూహాత్మక ఆలోచనలో మీ ఆసక్తి వ్యాపారం మరియు నిర్వహణను గొప్ప ఎంపికగా చేస్తుంది",
|
| 1322 |
+
ta: () =>
|
| 1323 |
+
"தலைமைத்துவம் மற்றும் உத்தியியல் சிந்தனையில் உங்கள் ஆர்வம் வணிகம் மற்றும் மேலாண்மையை சிறந்த தேர்வாக்குகிறது",
|
| 1324 |
+
bn: () =>
|
| 1325 |
+
"নেতৃত্ব এবং কৌশলগত চিন্তাভাবনায় আপনার আগ্রহ ব্যবসা ও ব্যবস্থাপনাকে একটি দুর্দান্ত পছন্দ করে তোলে",
|
| 1326 |
+
gu: () =>
|
| 1327 |
+
"નેતૃત્વ અને વ્યૂહાત્મક વિચારસરણીમાં તમારી રુચિ વ્યવસાય અને વ્યવસ્થાપનને એક મહાન પસંદગી બનાવે છે",
|
| 1328 |
+
} as Record<Language, (subjects?: string[]) => string>,
|
| 1329 |
+
nextSteps: {
|
| 1330 |
+
en: [
|
| 1331 |
+
"Learn about economics and finance",
|
| 1332 |
+
"Join business clubs or competitions",
|
| 1333 |
+
"Develop communication and teamwork skills",
|
| 1334 |
+
],
|
| 1335 |
+
hi: [
|
| 1336 |
+
"अर्थशास्त्र और वित्त के बारे में जानें",
|
| 1337 |
+
"व्यवसाय क्लब या प्रतियोगिताओं में शामिल हों",
|
| 1338 |
+
"संचार और टीमवर्क कौशल विकसित करें",
|
| 1339 |
+
],
|
| 1340 |
+
te: [
|
| 1341 |
+
"ఆర్థికశాస్త్రం మరియు ఫైనాన్స్ గురించి తెలుసుకోండి",
|
| 1342 |
+
"వ్యాపార క్లబ్లు లేదా పోటీలలో చేరండి",
|
| 1343 |
+
"కమ్యూనికేషన్ మరియు టీమ్వర్క్ నైపుణ్యాలను అభివృద్ధి చేయండి",
|
| 1344 |
+
],
|
| 1345 |
+
ta: [
|
| 1346 |
+
"பொருளாதாரம் மற்றும் நிதி பற்றி அறிக",
|
| 1347 |
+
"வணிக கழகங்கள் அல்லது போட்டிகளில் சேரவும்",
|
| 1348 |
+
"தொடர்பு மற்றும் குழு பணி திறன்களை வளர்த்துக் கொள்ளுங்கள்",
|
| 1349 |
+
],
|
| 1350 |
+
bn: [
|
| 1351 |
+
"অর্থনীতি এবং অর্থসংস্থান সম্পর্কে জানুন",
|
| 1352 |
+
"ব্যবসা ক্লাব বা প্রতিযোগিতায় যোগ দিন",
|
| 1353 |
+
"যোগাযোগ এবং টিমওয়ার্ক দক্ষতা বিকাশ করুন",
|
| 1354 |
+
],
|
| 1355 |
+
gu: [
|
| 1356 |
+
"અર્થશાસ્ત્ર અને નાણાં વિશે જાણો",
|
| 1357 |
+
"વ્યવસાય ક્લબ અથવા સ્પર્ધાઓમાં જોડાઓ",
|
| 1358 |
+
"સંચાર અને ટીમવર્ક કુશળતા વિકસાવો",
|
| 1359 |
+
],
|
| 1360 |
+
},
|
| 1361 |
+
},
|
| 1362 |
+
];
|
| 1363 |
+
|
| 1364 |
+
// Score and sort careers
|
| 1365 |
+
const scoredCareers = careerOptions
|
| 1366 |
+
.map((career) => ({
|
| 1367 |
+
...career,
|
| 1368 |
+
finalScore: career.score,
|
| 1369 |
+
}))
|
| 1370 |
+
.sort((a, b) => b.finalScore - a.finalScore)
|
| 1371 |
+
.slice(0, 4); // Take top 4
|
| 1372 |
+
|
| 1373 |
+
// Generate recommendations
|
| 1374 |
+
const recommendations = scoredCareers.map((career, index) => {
|
| 1375 |
+
const confidence = Math.max(0.65, Math.min(0.85, 0.85 - index * 0.05));
|
| 1376 |
+
const reasonFunc = (career.reason[language] || career.reason.en) as (
|
| 1377 |
+
subjects?: string[]
|
| 1378 |
+
) => string;
|
| 1379 |
+
const reason = reasonFunc(analysis.preferredSubjects);
|
| 1380 |
+
|
| 1381 |
+
return {
|
| 1382 |
+
title: career.title[language] || career.title.en,
|
| 1383 |
+
confidence: Math.round(confidence * 100) / 100,
|
| 1384 |
+
reason,
|
| 1385 |
+
next_steps: career.nextSteps[language] || career.nextSteps.en,
|
| 1386 |
+
};
|
| 1387 |
+
});
|
| 1388 |
+
|
| 1389 |
+
// Generate summary
|
| 1390 |
+
const summaries: Record<Language, string> = {
|
| 1391 |
+
en: analysis.careerInterest
|
| 1392 |
+
? `Based on your assessment and interest in ${analysis.careerInterest}, we've identified several exciting career paths for you.`
|
| 1393 |
+
: "Based on your assessment, we've identified several exciting career paths. Explore these options to find what interests you most!",
|
| 1394 |
+
hi: analysis.careerInterest
|
| 1395 |
+
? `आपके मूल्यांकन और ${analysis.careerInterest} में रुचि के आधार पर, हमने आपके लिए कई रोमांचक करियर पथों की पहचान की है।`
|
| 1396 |
+
: "आपके मूल्यांकन के आधार पर, हमने कई रोमांचक करियर पथों की पहचान की है। अपनी रुचि के अनुसार इन विकल्पों का अन्वेषण करें!",
|
| 1397 |
+
te: analysis.careerInterest
|
| 1398 |
+
? `మీ అసెస్మెంట్ మరియు ${analysis.careerInterest}లో ఆసక్తి ఆధారంగా, మేము మీ కోసం అనేక ఉత్తేజకరమైన కెరీర్ మార్గాలను గుర్తించాము।`
|
| 1399 |
+
: "మీ అసెస్మెంట్ ఆధారంగా, మేము అనేక ఉత్తేజకరమైన కెరీర్ మార్గాలను గుర్తించాము. మీకు ఆసక్తి ఉన్న వాటిని కనుగొనడానికి ఈ ఎంపికలను అన్వేషించండి!",
|
| 1400 |
+
ta: analysis.careerInterest
|
| 1401 |
+
? `உங்கள் மதிப்பீடு மற்றும் ${analysis.careerInterest}ல் உள்ள ஆர்வத்தின் அடிப்படையில், உங்களுக்கான பல சுவாரஸ்யமான தொழில் பாதைகளை நாங்கள் கண்டறிந்துள்ளோம்।`
|
| 1402 |
+
: "உங்கள் மதிப்பீட்டின் அடிப்படையில், பல சுவாரஸ்யமான தொழில் பாதைகளை நாங்கள் கண்டறிந்துள்ளோம். உங்கள் ஆர்வத்தைக் கண்டறிய இந்த விருப்பங்களை ஆராயுங்கள்!",
|
| 1403 |
+
bn: analysis.careerInterest
|
| 1404 |
+
? `আপনার মূল্যায়ন এবং ${analysis.careerInterest}তে আগ্রহের ভিত্তিতে, আমরা আপনার জন্য বেশ কয়েকটি উত্তেজনাপূর্ণ ক্যারিয়ার পথ চিহ্নিত করেছি।`
|
| 1405 |
+
: "আপনার মূল্যায়নের ভিত্তিতে, আমরা বেশ কয়েকটি উত্তেজনাপূর্ণ ক্যারিয়ার পথ চিহ্নিত করেছি। আপনার আগ্রহ খুঁজে পেতে এই বিকল্পগুলি অন্বেষণ করুন!",
|
| 1406 |
+
gu: analysis.careerInterest
|
| 1407 |
+
? `તમારા મૂલ્યાંકન અને ${analysis.careerInterest}માં રુચિના આધારે, અમે તમારા માટે અનેક રોમાંચક કારકિર્દી માર્ગો ઓળખ્યા છે।`
|
| 1408 |
+
: "તમારા મૂલ્યાંકનના આધારે, અમે અનેક રોમાંચક કારકિર્દી માર્ગો ઓળખ્યા છે. તમારી રુચિ શોધવા માટે આ વિકલ્પોનું અન્વેષણ કરો!",
|
| 1409 |
+
};
|
| 1410 |
+
|
| 1411 |
+
return {
|
| 1412 |
+
recommendations,
|
| 1413 |
+
summary: summaries[language] || summaries.en,
|
| 1414 |
+
};
|
| 1415 |
+
}
|
| 1416 |
+
|
| 1417 |
+
async generateChatResponse(
|
| 1418 |
+
message: string,
|
| 1419 |
+
context: {
|
| 1420 |
+
assessmentSummary?: string;
|
| 1421 |
+
previousMessages?: ChatMessage[];
|
| 1422 |
+
language: Language;
|
| 1423 |
+
},
|
| 1424 |
+
retryOptions?: RetryOptions
|
| 1425 |
+
): Promise<{ reply: string; intent: string }> {
|
| 1426 |
+
const systemPrompt = this.getSystemPrompt(context.language, "chat");
|
| 1427 |
+
|
| 1428 |
+
let conversationContext = "";
|
| 1429 |
+
if (context.assessmentSummary) {
|
| 1430 |
+
conversationContext = `Assessment Summary: ${context.assessmentSummary}\n\n`;
|
| 1431 |
+
}
|
| 1432 |
+
|
| 1433 |
+
if (context.previousMessages && context.previousMessages.length > 0) {
|
| 1434 |
+
conversationContext += "Recent conversation:\n";
|
| 1435 |
+
context.previousMessages.slice(-5).forEach((msg) => {
|
| 1436 |
+
conversationContext += `${
|
| 1437 |
+
msg.role === "user" ? "Student" : "Assistant"
|
| 1438 |
+
}: ${msg.content}\n`;
|
| 1439 |
+
});
|
| 1440 |
+
}
|
| 1441 |
+
|
| 1442 |
+
const prompt = `${systemPrompt}\n\n${conversationContext}Student: ${message}\n\nAssistant:`;
|
| 1443 |
+
|
| 1444 |
+
try {
|
| 1445 |
+
const response = await retryWithBackoff(async () => {
|
| 1446 |
+
const model = this.genAI.getGenerativeModel({ model: this.modelId });
|
| 1447 |
+
const result = await model.generateContent(prompt);
|
| 1448 |
+
return result.response.text();
|
| 1449 |
+
}, retryOptions);
|
| 1450 |
+
|
| 1451 |
+
return this.parseChatResponse(response, context.language);
|
| 1452 |
+
} catch (error: any) {
|
| 1453 |
+
console.error("Error generating chat response:", error);
|
| 1454 |
+
|
| 1455 |
+
// Fallback response
|
| 1456 |
+
const fallbacks: Record<Language, { reply: string; intent: string }> = {
|
| 1457 |
+
en: {
|
| 1458 |
+
reply:
|
| 1459 |
+
"I'm having trouble processing that right now. Could you try rephrasing your question?",
|
| 1460 |
+
intent: "error",
|
| 1461 |
+
},
|
| 1462 |
+
hi: {
|
| 1463 |
+
reply:
|
| 1464 |
+
"अभी मैं इसे संसाधित करने में परेशानी हो रही है। क्या आप अपना प्रश्न दोबारा लिख सकते हैं?",
|
| 1465 |
+
intent: "error",
|
| 1466 |
+
},
|
| 1467 |
+
te: {
|
| 1468 |
+
reply:
|
| 1469 |
+
"ప్రస్తుతం దాన్ని ప్రాసెస్ చేయడంలో నాకు సమస్య ఉంది. మీరు మీ ప్రశ్నను మళ్లీ రాయగలరా?",
|
| 1470 |
+
intent: "error",
|
| 1471 |
+
},
|
| 1472 |
+
ta: {
|
| 1473 |
+
reply:
|
| 1474 |
+
"தற்போது அதை செயலாக்குவதில் சிக்கல் உள்ளது. உங்கள் கேள்வியை மீண்டும் எழுதலாமா?",
|
| 1475 |
+
intent: "error",
|
| 1476 |
+
},
|
| 1477 |
+
bn: {
|
| 1478 |
+
reply:
|
| 1479 |
+
"এখন এটি প্রক্রিয়া করতে সমস্যা হচ্ছে। আপনি কি আপনার প্রশ্নটি আবার লিখতে পারেন?",
|
| 1480 |
+
intent: "error",
|
| 1481 |
+
},
|
| 1482 |
+
gu: {
|
| 1483 |
+
reply:
|
| 1484 |
+
"હમણાં તેને પ્રક્રિયા કરવામાં સમસ્યા આવી રહી છે. શું તમે તમારો પ્રશ્ન ફરીથી લખી શકો છો?",
|
| 1485 |
+
intent: "error",
|
| 1486 |
+
},
|
| 1487 |
+
};
|
| 1488 |
+
|
| 1489 |
+
return fallbacks[context.language] || fallbacks.en;
|
| 1490 |
+
}
|
| 1491 |
+
}
|
| 1492 |
+
|
| 1493 |
+
private parseChatResponse(
|
| 1494 |
+
response: string,
|
| 1495 |
+
language: Language
|
| 1496 |
+
): { reply: string; intent: string } {
|
| 1497 |
+
try {
|
| 1498 |
+
// Try to extract JSON
|
| 1499 |
+
let jsonStr = response.trim();
|
| 1500 |
+
if (jsonStr.startsWith("```")) {
|
| 1501 |
+
jsonStr = jsonStr
|
| 1502 |
+
.replace(/^```(?:json)?\n?/, "")
|
| 1503 |
+
.replace(/\n?```$/, "");
|
| 1504 |
+
}
|
| 1505 |
+
|
| 1506 |
+
// Try parsing as JSON first
|
| 1507 |
+
try {
|
| 1508 |
+
const parsed = JSON.parse(jsonStr);
|
| 1509 |
+
if (parsed.reply && parsed.intent) {
|
| 1510 |
+
return { reply: parsed.reply, intent: parsed.intent };
|
| 1511 |
+
}
|
| 1512 |
+
} catch {
|
| 1513 |
+
// If not JSON, treat as plain text
|
| 1514 |
+
}
|
| 1515 |
+
|
| 1516 |
+
// If not JSON or invalid, return as-is with default intent
|
| 1517 |
+
return {
|
| 1518 |
+
reply: jsonStr,
|
| 1519 |
+
intent: "follow_up",
|
| 1520 |
+
};
|
| 1521 |
+
} catch (error) {
|
| 1522 |
+
console.error("Failed to parse chat response:", error);
|
| 1523 |
+
return {
|
| 1524 |
+
reply: response,
|
| 1525 |
+
intent: "follow_up",
|
| 1526 |
+
};
|
| 1527 |
+
}
|
| 1528 |
+
}
|
| 1529 |
+
}
|
backend/src/services/ragChat.ts
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { spawn, ChildProcess } from "child_process";
|
| 2 |
+
import path from "path";
|
| 3 |
+
import fs from "fs";
|
| 4 |
+
import type { Language } from "../types";
|
| 5 |
+
|
| 6 |
+
interface ChatHistoryMessage {
|
| 7 |
+
role: "user" | "assistant";
|
| 8 |
+
content: string;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
interface RAGResponse {
|
| 12 |
+
response: string;
|
| 13 |
+
sources: Array<{
|
| 14 |
+
title: string;
|
| 15 |
+
chunk_index: number;
|
| 16 |
+
snippet: string;
|
| 17 |
+
}>;
|
| 18 |
+
error: string | null;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
interface PythonResponse {
|
| 22 |
+
status: "success" | "error";
|
| 23 |
+
message?: string;
|
| 24 |
+
data?: RAGResponse;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
interface PendingRequest {
|
| 28 |
+
resolve: (value: PythonResponse) => void;
|
| 29 |
+
reject: (error: Error) => void;
|
| 30 |
+
timeout: NodeJS.Timeout;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
export class RAGChatService {
|
| 34 |
+
private provider: string;
|
| 35 |
+
private careersJsonPath: string;
|
| 36 |
+
private chromaPersistDir: string;
|
| 37 |
+
private pythonProcess: ChildProcess | null = null;
|
| 38 |
+
private isInitialized: boolean = false;
|
| 39 |
+
private initializationPromise: Promise<void> | null = null;
|
| 40 |
+
private pendingRequests: PendingRequest[] = [];
|
| 41 |
+
private outputBuffer: string = "";
|
| 42 |
+
|
| 43 |
+
constructor(provider: string = "google") {
|
| 44 |
+
this.provider = provider;
|
| 45 |
+
|
| 46 |
+
// Set paths relative to backend directory
|
| 47 |
+
const backendDir = path.resolve(__dirname, "../..");
|
| 48 |
+
this.careersJsonPath = path.join(backendDir, "careers_cleaned.json");
|
| 49 |
+
this.chromaPersistDir = path.join(backendDir, "chroma_data_multilingual");
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Get the Python executable path
|
| 54 |
+
*/
|
| 55 |
+
private getPythonExecutable(): string {
|
| 56 |
+
// Check if virtual environment exists and use its Python
|
| 57 |
+
const backendDir = path.resolve(__dirname, "../..");
|
| 58 |
+
|
| 59 |
+
// Windows: venv/Scripts/python.exe
|
| 60 |
+
const venvPythonWin = path.join(backendDir, "venv", "Scripts", "python.exe");
|
| 61 |
+
if (fs.existsSync(venvPythonWin)) {
|
| 62 |
+
return venvPythonWin;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
// macOS/Linux: venv/bin/python
|
| 66 |
+
const venvPython = path.join(backendDir, "venv", "bin", "python");
|
| 67 |
+
if (fs.existsSync(venvPython)) {
|
| 68 |
+
return venvPython;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// Also check for venv/bin/python3 (some systems)
|
| 72 |
+
const venvPython3 = path.join(backendDir, "venv", "bin", "python3");
|
| 73 |
+
if (fs.existsSync(venvPython3)) {
|
| 74 |
+
return venvPython3;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
// Check for Python 3.12 (macOS specific)
|
| 78 |
+
const python312 = "/Library/Frameworks/Python.framework/Versions/3.12/bin/python3";
|
| 79 |
+
if (fs.existsSync(python312)) {
|
| 80 |
+
return python312;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
// Fallback to python3 (macOS/Linux) or python (Windows)
|
| 84 |
+
return process.platform === "win32" ? "python" : "python3";
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* Process a complete JSON response line
|
| 89 |
+
*/
|
| 90 |
+
private processResponseLine(line: string): void {
|
| 91 |
+
try {
|
| 92 |
+
const response: PythonResponse = JSON.parse(line);
|
| 93 |
+
|
| 94 |
+
// Get the next pending request (FIFO)
|
| 95 |
+
const pending = this.pendingRequests.shift();
|
| 96 |
+
|
| 97 |
+
if (pending) {
|
| 98 |
+
clearTimeout(pending.timeout);
|
| 99 |
+
|
| 100 |
+
if (response.status === "error") {
|
| 101 |
+
pending.reject(new Error(response.message || "Unknown error"));
|
| 102 |
+
} else {
|
| 103 |
+
pending.resolve(response);
|
| 104 |
+
}
|
| 105 |
+
} else {
|
| 106 |
+
console.warn("[RAG] Received response with no pending request");
|
| 107 |
+
}
|
| 108 |
+
} catch (error) {
|
| 109 |
+
console.error("[RAG] Failed to parse response:", line, error);
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Initialize the Python process (only once)
|
| 115 |
+
* Can be called externally to preload the service
|
| 116 |
+
*/
|
| 117 |
+
async initialize(): Promise<void> {
|
| 118 |
+
// If already initialized, return immediately
|
| 119 |
+
if (this.isInitialized && this.pythonProcess) {
|
| 120 |
+
return;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// If initialization is in progress, wait for it
|
| 124 |
+
if (this.initializationPromise) {
|
| 125 |
+
return this.initializationPromise;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
// Start new initialization
|
| 129 |
+
this.initializationPromise = new Promise(async (resolve, reject) => {
|
| 130 |
+
try {
|
| 131 |
+
const pythonScriptPath = path.join(__dirname, "rag_service.py");
|
| 132 |
+
const backendDir = path.resolve(__dirname, "../..");
|
| 133 |
+
const pythonExecutable = this.getPythonExecutable();
|
| 134 |
+
|
| 135 |
+
console.log(
|
| 136 |
+
`[RAG] Starting persistent Python process: ${pythonExecutable}`
|
| 137 |
+
);
|
| 138 |
+
|
| 139 |
+
// CRITICAL: Set UTF-8 encoding in environment variables
|
| 140 |
+
this.pythonProcess = spawn(pythonExecutable, [pythonScriptPath], {
|
| 141 |
+
stdio: ["pipe", "pipe", "pipe"],
|
| 142 |
+
cwd: backendDir,
|
| 143 |
+
env: {
|
| 144 |
+
...process.env,
|
| 145 |
+
PYTHONIOENCODING: "utf-8", // Force UTF-8 for Python I/O
|
| 146 |
+
PYTHONUTF8: "1", // Enable UTF-8 mode for Python 3.7+
|
| 147 |
+
LANG: "en_US.UTF-8", // Set locale to UTF-8
|
| 148 |
+
LC_ALL: "en_US.UTF-8", // Override all locale settings
|
| 149 |
+
},
|
| 150 |
+
});
|
| 151 |
+
|
| 152 |
+
// Handle stdout - parse JSON responses line by line
|
| 153 |
+
// CRITICAL: Explicitly set encoding to utf-8
|
| 154 |
+
this.pythonProcess.stdout?.setEncoding("utf-8");
|
| 155 |
+
this.pythonProcess.stdout?.on("data", (data: string) => {
|
| 156 |
+
console.log(`[RAG DEBUG] Received stdout (${data.length} chars):`, data.substring(0, 200));
|
| 157 |
+
this.outputBuffer += data;
|
| 158 |
+
|
| 159 |
+
// Process complete lines
|
| 160 |
+
const lines = this.outputBuffer.split("\n");
|
| 161 |
+
this.outputBuffer = lines.pop() || ""; // Keep incomplete line in buffer
|
| 162 |
+
|
| 163 |
+
for (const line of lines) {
|
| 164 |
+
const trimmed = line.trim();
|
| 165 |
+
if (trimmed) {
|
| 166 |
+
console.log(`[RAG DEBUG] Processing line:`, trimmed.substring(0, 100));
|
| 167 |
+
this.processResponseLine(trimmed);
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
});
|
| 171 |
+
|
| 172 |
+
// Handle stderr - log errors
|
| 173 |
+
// CRITICAL: Explicitly set encoding to utf-8
|
| 174 |
+
this.pythonProcess.stderr?.setEncoding("utf-8");
|
| 175 |
+
this.pythonProcess.stderr?.on("data", (data: string) => {
|
| 176 |
+
const msg = data.trim();
|
| 177 |
+
// Log ALL stderr for debugging
|
| 178 |
+
console.error(`[RAG STDERR]: ${msg}`);
|
| 179 |
+
});
|
| 180 |
+
|
| 181 |
+
// Handle process exit
|
| 182 |
+
this.pythonProcess.on("close", (code: number | null) => {
|
| 183 |
+
console.log(`[RAG] Python process exited with code: ${code}`);
|
| 184 |
+
this.isInitialized = false;
|
| 185 |
+
this.pythonProcess = null;
|
| 186 |
+
this.initializationPromise = null;
|
| 187 |
+
|
| 188 |
+
// Reject all pending requests
|
| 189 |
+
while (this.pendingRequests.length > 0) {
|
| 190 |
+
const pending = this.pendingRequests.shift()!;
|
| 191 |
+
clearTimeout(pending.timeout);
|
| 192 |
+
pending.reject(new Error("Python process terminated unexpectedly"));
|
| 193 |
+
}
|
| 194 |
+
});
|
| 195 |
+
|
| 196 |
+
this.pythonProcess.on("error", (error: Error) => {
|
| 197 |
+
console.error("[RAG] Python process error:", error);
|
| 198 |
+
this.isInitialized = false;
|
| 199 |
+
this.initializationPromise = null;
|
| 200 |
+
reject(error);
|
| 201 |
+
});
|
| 202 |
+
|
| 203 |
+
// Send initialization command
|
| 204 |
+
const initCommand = {
|
| 205 |
+
command: "initialize",
|
| 206 |
+
careers_json_path: this.careersJsonPath,
|
| 207 |
+
chroma_persist_dir: this.chromaPersistDir,
|
| 208 |
+
provider: this.provider,
|
| 209 |
+
};
|
| 210 |
+
|
| 211 |
+
const initPromise = new Promise<void>((resolveInit, rejectInit) => {
|
| 212 |
+
const timeout = setTimeout(() => {
|
| 213 |
+
rejectInit(new Error("Initialization timeout (60s)"));
|
| 214 |
+
}, 60000);
|
| 215 |
+
|
| 216 |
+
this.pendingRequests.push({
|
| 217 |
+
resolve: (response: PythonResponse) => {
|
| 218 |
+
clearTimeout(timeout);
|
| 219 |
+
if (response.status === "success") {
|
| 220 |
+
this.isInitialized = true;
|
| 221 |
+
console.log("[RAG] Service initialized successfully");
|
| 222 |
+
resolveInit();
|
| 223 |
+
} else {
|
| 224 |
+
rejectInit(
|
| 225 |
+
new Error(response.message || "Initialization failed")
|
| 226 |
+
);
|
| 227 |
+
}
|
| 228 |
+
},
|
| 229 |
+
reject: (error: Error) => {
|
| 230 |
+
clearTimeout(timeout);
|
| 231 |
+
rejectInit(error);
|
| 232 |
+
},
|
| 233 |
+
timeout,
|
| 234 |
+
});
|
| 235 |
+
});
|
| 236 |
+
|
| 237 |
+
// CRITICAL: Write with explicit UTF-8 encoding
|
| 238 |
+
this.pythonProcess.stdin?.write(
|
| 239 |
+
JSON.stringify(initCommand) + "\n",
|
| 240 |
+
"utf-8"
|
| 241 |
+
);
|
| 242 |
+
|
| 243 |
+
// Wait for initialization to complete
|
| 244 |
+
await initPromise;
|
| 245 |
+
resolve();
|
| 246 |
+
} catch (error: any) {
|
| 247 |
+
this.initializationPromise = null;
|
| 248 |
+
reject(new Error(`Failed to initialize RAG service: ${error.message}`));
|
| 249 |
+
}
|
| 250 |
+
});
|
| 251 |
+
|
| 252 |
+
return this.initializationPromise;
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
/**
|
| 256 |
+
* Send a command to the Python process
|
| 257 |
+
*/
|
| 258 |
+
private async sendCommand(command: any): Promise<PythonResponse> {
|
| 259 |
+
// Ensure initialized
|
| 260 |
+
await this.initialize();
|
| 261 |
+
|
| 262 |
+
if (!this.pythonProcess || !this.isInitialized) {
|
| 263 |
+
throw new Error("RAG service not initialized");
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
console.log(`[RAG DEBUG] Sending command: ${command.command}`);
|
| 267 |
+
|
| 268 |
+
return new Promise((resolve, reject) => {
|
| 269 |
+
// Set timeout for this request (increased to handle rate limits and retries)
|
| 270 |
+
const timeout = setTimeout(() => {
|
| 271 |
+
console.error(`[RAG DEBUG] Request timeout after 90s for command: ${command.command}`);
|
| 272 |
+
// Remove from pending requests
|
| 273 |
+
const index = this.pendingRequests.findIndex(
|
| 274 |
+
(req) => req.timeout === timeout
|
| 275 |
+
);
|
| 276 |
+
if (index !== -1) {
|
| 277 |
+
this.pendingRequests.splice(index, 1);
|
| 278 |
+
}
|
| 279 |
+
reject(new Error("Request timeout (90s)"));
|
| 280 |
+
}, 90000); // Increased from 30s to 90s to handle API rate limits
|
| 281 |
+
|
| 282 |
+
this.pendingRequests.push({
|
| 283 |
+
resolve,
|
| 284 |
+
reject,
|
| 285 |
+
timeout,
|
| 286 |
+
});
|
| 287 |
+
|
| 288 |
+
// Send command with explicit UTF-8 encoding
|
| 289 |
+
try {
|
| 290 |
+
// Serialize with proper Unicode handling (no ASCII escaping)
|
| 291 |
+
const jsonString = JSON.stringify(command);
|
| 292 |
+
this.pythonProcess!.stdin?.write(jsonString + "\n", "utf-8");
|
| 293 |
+
} catch (error: any) {
|
| 294 |
+
clearTimeout(timeout);
|
| 295 |
+
const index = this.pendingRequests.findIndex(
|
| 296 |
+
(req) => req.timeout === timeout
|
| 297 |
+
);
|
| 298 |
+
if (index !== -1) {
|
| 299 |
+
this.pendingRequests.splice(index, 1);
|
| 300 |
+
}
|
| 301 |
+
reject(new Error(`Failed to send command: ${error.message}`));
|
| 302 |
+
}
|
| 303 |
+
});
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
/**
|
| 307 |
+
* Send a chat message and get a response
|
| 308 |
+
* Handles full UTF-8 flow: Hindi input → processing → Hindi output
|
| 309 |
+
*/
|
| 310 |
+
async chat(
|
| 311 |
+
message: string,
|
| 312 |
+
chatHistory: ChatHistoryMessage[] = [],
|
| 313 |
+
language: Language = "en"
|
| 314 |
+
): Promise<string> {
|
| 315 |
+
// Verify message is properly encoded (defensive check)
|
| 316 |
+
if (typeof message !== "string") {
|
| 317 |
+
throw new Error("Message must be a string");
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
// Ensure chat history entries are properly formatted
|
| 321 |
+
const sanitizedHistory = chatHistory.map((msg) => ({
|
| 322 |
+
role: msg.role,
|
| 323 |
+
content: String(msg.content), // Ensure content is string
|
| 324 |
+
}));
|
| 325 |
+
|
| 326 |
+
const response = await this.sendCommand({
|
| 327 |
+
command: "chat",
|
| 328 |
+
message: message,
|
| 329 |
+
chat_history: sanitizedHistory,
|
| 330 |
+
language: language,
|
| 331 |
+
});
|
| 332 |
+
|
| 333 |
+
// Debug: log the full response from Python
|
| 334 |
+
console.log("[RAG] Full response from Python:", JSON.stringify(response, null, 2));
|
| 335 |
+
|
| 336 |
+
// Check for error status first
|
| 337 |
+
if (response.status === "error") {
|
| 338 |
+
throw new Error(response.message || "RAG service returned an error");
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
if (response.data && response.data.response) {
|
| 342 |
+
// Response should already be in the specified language
|
| 343 |
+
return response.data.response;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
// Log what we actually received for debugging
|
| 347 |
+
console.error("[RAG] Invalid response structure:", {
|
| 348 |
+
hasData: !!response.data,
|
| 349 |
+
dataResponse: response.data?.response,
|
| 350 |
+
fullResponse: response
|
| 351 |
+
});
|
| 352 |
+
throw new Error("Invalid chat response from RAG service: missing response field");
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
/**
|
| 356 |
+
* Generate an initial greeting based on assessment results
|
| 357 |
+
*/
|
| 358 |
+
async generateInitialGreeting(
|
| 359 |
+
assessmentSummary: string,
|
| 360 |
+
language: Language = "en"
|
| 361 |
+
): Promise<{ reply: string; timestamp: Date }> {
|
| 362 |
+
const response = await this.sendCommand({
|
| 363 |
+
command: "greeting",
|
| 364 |
+
assessment_summary: assessmentSummary,
|
| 365 |
+
language: language,
|
| 366 |
+
});
|
| 367 |
+
|
| 368 |
+
if (response.data && response.data.response) {
|
| 369 |
+
return {
|
| 370 |
+
reply: response.data.response,
|
| 371 |
+
timestamp: new Date(),
|
| 372 |
+
};
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
throw new Error("Invalid greeting response from RAG service");
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
/**
|
| 379 |
+
* Gracefully shutdown the Python process
|
| 380 |
+
*/
|
| 381 |
+
async shutdown(): Promise<void> {
|
| 382 |
+
if (this.pythonProcess) {
|
| 383 |
+
console.log("[RAG] Shutting down Python process...");
|
| 384 |
+
this.pythonProcess.kill("SIGTERM");
|
| 385 |
+
this.pythonProcess = null;
|
| 386 |
+
this.isInitialized = false;
|
| 387 |
+
this.initializationPromise = null;
|
| 388 |
+
|
| 389 |
+
// Clear all pending requests
|
| 390 |
+
while (this.pendingRequests.length > 0) {
|
| 391 |
+
const pending = this.pendingRequests.shift()!;
|
| 392 |
+
clearTimeout(pending.timeout);
|
| 393 |
+
pending.reject(new Error("Service shutting down"));
|
| 394 |
+
}
|
| 395 |
+
}
|
| 396 |
+
}
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
// Create a singleton instance that persists across requests
|
| 400 |
+
let ragServiceInstance: RAGChatService | null = null;
|
| 401 |
+
|
| 402 |
+
/**
|
| 403 |
+
* Get or create the singleton RAG service instance
|
| 404 |
+
*/
|
| 405 |
+
export function getRAGChatService(provider: string = "google"): RAGChatService {
|
| 406 |
+
if (!ragServiceInstance) {
|
| 407 |
+
ragServiceInstance = new RAGChatService(provider);
|
| 408 |
+
|
| 409 |
+
// Cleanup on process exit
|
| 410 |
+
process.on("SIGINT", async () => {
|
| 411 |
+
if (ragServiceInstance) {
|
| 412 |
+
await ragServiceInstance.shutdown();
|
| 413 |
+
}
|
| 414 |
+
process.exit(0);
|
| 415 |
+
});
|
| 416 |
+
|
| 417 |
+
process.on("SIGTERM", async () => {
|
| 418 |
+
if (ragServiceInstance) {
|
| 419 |
+
await ragServiceInstance.shutdown();
|
| 420 |
+
}
|
| 421 |
+
process.exit(0);
|
| 422 |
+
});
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
return ragServiceInstance;
|
| 426 |
+
}
|
backend/src/services/rag_service.py
ADDED
|
@@ -0,0 +1,881 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
RAG Service for Career Guidance Chatbot
|
| 3 |
+
This service wraps the RAG chatbot functionality for integration with the Node.js backend.
|
| 4 |
+
"""
|
| 5 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 6 |
+
from langchain_core.messages import HumanMessage, AIMessage
|
| 7 |
+
from langchain_core.output_parsers import StrOutputParser
|
| 8 |
+
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
| 9 |
+
from langchain_core.documents import Document
|
| 10 |
+
from langchain_chroma import Chroma
|
| 11 |
+
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 12 |
+
from dotenv import load_dotenv
|
| 13 |
+
import json
|
| 14 |
+
import os
|
| 15 |
+
import sys
|
| 16 |
+
import io
|
| 17 |
+
from typing import List, Dict, Optional
|
| 18 |
+
from pathlib import Path
|
| 19 |
+
|
| 20 |
+
# CRITICAL: Set up proper UTF-8 encoding for stdin/stdout
|
| 21 |
+
# This fixes encoding issues with Hindi, Telugu, and other Unicode languages
|
| 22 |
+
sys.stdin = io.TextIOWrapper(
|
| 23 |
+
sys.stdin.buffer, encoding='utf-8', errors='replace')
|
| 24 |
+
sys.stdout = io.TextIOWrapper(
|
| 25 |
+
sys.stdout.buffer, encoding='utf-8', errors='replace')
|
| 26 |
+
sys.stderr = io.TextIOWrapper(
|
| 27 |
+
sys.stderr.buffer, encoding='utf-8', errors='replace')
|
| 28 |
+
|
| 29 |
+
# Load environment variables from .env file
|
| 30 |
+
# Look for .env in backend directory (parent of src)
|
| 31 |
+
backend_dir = Path(__file__).parent.parent.parent
|
| 32 |
+
env_path = backend_dir / '.env'
|
| 33 |
+
if env_path.exists():
|
| 34 |
+
load_dotenv(env_path)
|
| 35 |
+
print(f"Loaded .env from {env_path}", file=sys.stderr)
|
| 36 |
+
else:
|
| 37 |
+
print(f"Warning: .env not found at {env_path}", file=sys.stderr)
|
| 38 |
+
load_dotenv() # Try to load from current directory
|
| 39 |
+
|
| 40 |
+
# Add parent directory to path for imports
|
| 41 |
+
sys.path.insert(0, str(backend_dir))
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# Configuration
|
| 45 |
+
CHUNK_SIZE = 512
|
| 46 |
+
CHUNK_OVERLAP = 150
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class RAGChatService:
|
| 50 |
+
def __init__(self, careers_json_path: str, chroma_persist_dir: str, provider: str = "google"):
|
| 51 |
+
"""
|
| 52 |
+
Initialize the RAG Chat Service
|
| 53 |
+
|
| 54 |
+
Args:
|
| 55 |
+
careers_json_path: Path to careers_cleaned.json
|
| 56 |
+
chroma_persist_dir: Path to chroma_data_full directory
|
| 57 |
+
provider: LLM provider to use ("google" or "groq")
|
| 58 |
+
"""
|
| 59 |
+
self.provider = provider
|
| 60 |
+
self.careers_json_path = careers_json_path
|
| 61 |
+
self.chroma_persist_dir = chroma_persist_dir
|
| 62 |
+
|
| 63 |
+
# Initialize embeddings
|
| 64 |
+
# self.embeddings = HuggingFaceEmbeddings(
|
| 65 |
+
# model_name="sentence-transformers/all-mpnet-base-v2"
|
| 66 |
+
# )
|
| 67 |
+
|
| 68 |
+
self.embeddings = HuggingFaceEmbeddings(
|
| 69 |
+
model_name="BAAI/bge-m3"
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
# Initialize or load vector database
|
| 73 |
+
self.vectordb = self._init_vectordb()
|
| 74 |
+
|
| 75 |
+
# Initialize LLM
|
| 76 |
+
self.llm = self._init_llm()
|
| 77 |
+
|
| 78 |
+
# Initialize retriever
|
| 79 |
+
self.retriever = self.vectordb.as_retriever(search_kwargs={"k": 3})
|
| 80 |
+
|
| 81 |
+
# Build the chain
|
| 82 |
+
self.chain = self._build_chain()
|
| 83 |
+
|
| 84 |
+
def _reformulate_query(self, question: str, chat_history: List) -> str:
|
| 85 |
+
"""
|
| 86 |
+
Reformulate the user's question by incorporating context from chat history.
|
| 87 |
+
This helps with follow-up questions like "any scholarship in this?" where
|
| 88 |
+
"this" refers to a career mentioned earlier.
|
| 89 |
+
|
| 90 |
+
Args:
|
| 91 |
+
question: The user's current question
|
| 92 |
+
chat_history: List of previous HumanMessage/AIMessage objects
|
| 93 |
+
|
| 94 |
+
Returns:
|
| 95 |
+
A reformulated, self-contained question for retrieval
|
| 96 |
+
"""
|
| 97 |
+
# Debug logging
|
| 98 |
+
print(f"[RAG DEBUG] _reformulate_query called with question='{question}', history_len={len(chat_history)}", file=sys.stderr)
|
| 99 |
+
|
| 100 |
+
# If no chat history, return as-is
|
| 101 |
+
if not chat_history:
|
| 102 |
+
print(f"[RAG DEBUG] No chat history, skipping reformulation", file=sys.stderr)
|
| 103 |
+
return question
|
| 104 |
+
|
| 105 |
+
# Always reformulate short questions (under 8 words) when there's chat history
|
| 106 |
+
# Short questions are often follow-ups that need context like:
|
| 107 |
+
# - "give example from the field"
|
| 108 |
+
# - "any scholarships?"
|
| 109 |
+
# - "what about salary?"
|
| 110 |
+
# - "how long does it take?"
|
| 111 |
+
is_short_question = len(question.split()) < 8
|
| 112 |
+
|
| 113 |
+
# Also check for pronouns/references that definitely need context
|
| 114 |
+
context_words = ['this', 'that', 'it', 'these', 'those', 'above', 'same', 'such', 'mentioned', 'the field', 'career', 'job']
|
| 115 |
+
has_context_words = any(word in question.lower() for word in context_words)
|
| 116 |
+
|
| 117 |
+
# Reformulate if question is short OR has context words
|
| 118 |
+
if not (is_short_question or has_context_words):
|
| 119 |
+
return question
|
| 120 |
+
|
| 121 |
+
try:
|
| 122 |
+
# Build context from recent messages
|
| 123 |
+
recent_context = []
|
| 124 |
+
for msg in chat_history[-4:]: # Last 4 messages
|
| 125 |
+
if isinstance(msg, HumanMessage):
|
| 126 |
+
recent_context.append(f"User: {msg.content}")
|
| 127 |
+
elif isinstance(msg, AIMessage):
|
| 128 |
+
# Only include a summary of AI responses
|
| 129 |
+
content = msg.content[:200] + "..." if len(msg.content) > 200 else msg.content
|
| 130 |
+
recent_context.append(f"Assistant: {content}")
|
| 131 |
+
|
| 132 |
+
context_text = "\n".join(recent_context)
|
| 133 |
+
|
| 134 |
+
reformulation_prompt = f"""Given this conversation context:
|
| 135 |
+
{context_text}
|
| 136 |
+
|
| 137 |
+
The user now asks: "{question}"
|
| 138 |
+
|
| 139 |
+
Rewrite the user's question to be a self-contained search query that includes the relevant context (like career name, topic, etc.).
|
| 140 |
+
Only output the reformulated question, nothing else. Keep it concise (under 20 words).
|
| 141 |
+
|
| 142 |
+
Reformulated question:"""
|
| 143 |
+
|
| 144 |
+
# Use the LLM to reformulate
|
| 145 |
+
reformulated = self.llm.invoke(reformulation_prompt)
|
| 146 |
+
if hasattr(reformulated, 'content'):
|
| 147 |
+
reformulated = reformulated.content
|
| 148 |
+
reformulated = str(reformulated).strip()
|
| 149 |
+
|
| 150 |
+
# Log for debugging
|
| 151 |
+
print(f"[RAG] Query reformulation: '{question}' -> '{reformulated}'", file=sys.stderr)
|
| 152 |
+
|
| 153 |
+
return reformulated if reformulated else question
|
| 154 |
+
|
| 155 |
+
except Exception as e:
|
| 156 |
+
print(f"[RAG] Query reformulation failed: {e}, using original", file=sys.stderr)
|
| 157 |
+
return question
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def _init_vectordb(self) -> Chroma:
|
| 161 |
+
"""Initialize or load Chroma vector database"""
|
| 162 |
+
if os.path.exists(self.chroma_persist_dir) and os.listdir(self.chroma_persist_dir):
|
| 163 |
+
print(
|
| 164 |
+
f"Loading existing Chroma DB from {self.chroma_persist_dir}", file=sys.stderr)
|
| 165 |
+
return Chroma(
|
| 166 |
+
persist_directory=self.chroma_persist_dir,
|
| 167 |
+
embedding_function=self.embeddings
|
| 168 |
+
)
|
| 169 |
+
else:
|
| 170 |
+
print(
|
| 171 |
+
f"Creating new Chroma DB at {self.chroma_persist_dir}", file=sys.stderr)
|
| 172 |
+
items = self._load_json(self.careers_json_path)
|
| 173 |
+
docs = self._json_to_docs(items)
|
| 174 |
+
return Chroma.from_documents(
|
| 175 |
+
documents=docs,
|
| 176 |
+
embedding=self.embeddings,
|
| 177 |
+
persist_directory=self.chroma_persist_dir
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
def _load_json(self, path: str) -> List[Dict]:
|
| 181 |
+
"""Load careers JSON file with proper UTF-8 encoding"""
|
| 182 |
+
with open(path, "r", encoding="utf-8") as f:
|
| 183 |
+
return json.load(f)
|
| 184 |
+
|
| 185 |
+
def _json_to_docs(self, items: List[Dict]) -> List[Document]:
|
| 186 |
+
"""Convert JSON items to Document chunks"""
|
| 187 |
+
splitter = RecursiveCharacterTextSplitter(
|
| 188 |
+
chunk_size=CHUNK_SIZE,
|
| 189 |
+
chunk_overlap=CHUNK_OVERLAP,
|
| 190 |
+
separators=["\n\n", "\n", " ", ""],
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
docs = []
|
| 194 |
+
for item in items:
|
| 195 |
+
combined = f"{item['title']}\n\n{item['content']}"
|
| 196 |
+
chunks = splitter.split_text(combined)
|
| 197 |
+
|
| 198 |
+
for i, ch in enumerate(chunks):
|
| 199 |
+
docs.append(Document(
|
| 200 |
+
page_content=ch,
|
| 201 |
+
metadata={
|
| 202 |
+
"source_id": item["id"],
|
| 203 |
+
"title": item["title"],
|
| 204 |
+
"chunk_index": i
|
| 205 |
+
}
|
| 206 |
+
))
|
| 207 |
+
return docs
|
| 208 |
+
|
| 209 |
+
def _init_llm(self):
|
| 210 |
+
"""Initialize the LLM based on provider"""
|
| 211 |
+
if self.provider == "groq":
|
| 212 |
+
from langchain_groq import ChatGroq
|
| 213 |
+
return ChatGroq(
|
| 214 |
+
model="llama-3.3-70b-versatile",
|
| 215 |
+
temperature=0.1,
|
| 216 |
+
max_tokens=1500
|
| 217 |
+
)
|
| 218 |
+
elif self.provider == "google":
|
| 219 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 220 |
+
# Use gemini-2.5-flash instead of gemini-2.5-pro for better free tier limits
|
| 221 |
+
# Flash has 15 requests/minute vs Pro's 2 requests/minute on free tier
|
| 222 |
+
# Get API key from environment (support both GEMINI_API_KEY and GOOGLE_API_KEY)
|
| 223 |
+
api_key = os.environ.get(
|
| 224 |
+
"GEMINI_API_KEY") or os.environ.get("GOOGLE_API_KEY")
|
| 225 |
+
if not api_key:
|
| 226 |
+
raise ValueError(
|
| 227 |
+
"GEMINI_API_KEY or GOOGLE_API_KEY environment variable is required")
|
| 228 |
+
print(
|
| 229 |
+
f"[DEBUG] Using Google API key: {api_key[:10]}...", file=sys.stderr)
|
| 230 |
+
return ChatGoogleGenerativeAI(
|
| 231 |
+
model="gemini-2.5-flash",
|
| 232 |
+
temperature=0.1,
|
| 233 |
+
max_output_tokens=1500,
|
| 234 |
+
google_api_key=api_key
|
| 235 |
+
)
|
| 236 |
+
else:
|
| 237 |
+
raise ValueError(f"Unknown provider: {self.provider}")
|
| 238 |
+
|
| 239 |
+
def _build_chain(self):
|
| 240 |
+
"""Build the conversational RAG chain"""
|
| 241 |
+
prompt = ChatPromptTemplate.from_messages([
|
| 242 |
+
("system",
|
| 243 |
+
"""You are a helpful and friendly multilingual career guidance assistant for Indian students aged 13-15.
|
| 244 |
+
|
| 245 |
+
LANGUAGE INSTRUCTION:
|
| 246 |
+
You MUST respond in this language: {language}
|
| 247 |
+
- If the user's input is not in {language}, translate internally as needed.
|
| 248 |
+
- All final answers MUST be in {language}.
|
| 249 |
+
|
| 250 |
+
When answering questions about careers, education paths, or professional guidance:
|
| 251 |
+
- Keep responses SHORT and CONCISE (2-4 paragraphs maximum)
|
| 252 |
+
- Prioritize information from the Context provided below
|
| 253 |
+
- Use the context to give detailed, specific answers
|
| 254 |
+
- If the context has relevant information, base your answer primarily on it
|
| 255 |
+
- If the context doesn't have the information, you can provide general career guidance relevant to India
|
| 256 |
+
- If the question is unrelated to career guidance/education/careers, politely inform the user that you can only assist with career-related queries
|
| 257 |
+
- Keep responses age-appropriate, encouraging, and culturally sensitive
|
| 258 |
+
|
| 259 |
+
Context:
|
| 260 |
+
{context}"""),
|
| 261 |
+
MessagesPlaceholder("chat_history"),
|
| 262 |
+
("human", "{question}")
|
| 263 |
+
])
|
| 264 |
+
|
| 265 |
+
def format_docs(docs):
|
| 266 |
+
if not docs:
|
| 267 |
+
return "No relevant information found."
|
| 268 |
+
formatted = []
|
| 269 |
+
for i, doc in enumerate(docs, 1):
|
| 270 |
+
formatted.append(
|
| 271 |
+
f"[Source {i}: {doc.metadata.get('title', 'Unknown')}]\n{doc.page_content}")
|
| 272 |
+
return "\n\n---\n\n".join(formatted)
|
| 273 |
+
|
| 274 |
+
def get_context(inputs):
|
| 275 |
+
question = inputs["question"]
|
| 276 |
+
docs = self.retriever.invoke(question)
|
| 277 |
+
return format_docs(docs)
|
| 278 |
+
|
| 279 |
+
chain = (
|
| 280 |
+
{
|
| 281 |
+
"context": get_context,
|
| 282 |
+
"question": lambda x: x["question"],
|
| 283 |
+
"language": lambda x: x.get("language", "en"),
|
| 284 |
+
"chat_history": lambda x: x.get("chat_history", [])
|
| 285 |
+
}
|
| 286 |
+
| prompt
|
| 287 |
+
| self.llm
|
| 288 |
+
| StrOutputParser()
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
return chain
|
| 292 |
+
|
| 293 |
+
def chat(self, message: str, chat_history: List[Dict], language: str = "en") -> Dict:
|
| 294 |
+
"""
|
| 295 |
+
Process a chat message and return a response
|
| 296 |
+
Handles full multilingual flow including Hindi, Telugu, etc.
|
| 297 |
+
|
| 298 |
+
Args:
|
| 299 |
+
message: User's message (can be in any language including Hindi/Telugu)
|
| 300 |
+
chat_history: List of previous messages in format [{"role": "user"|"assistant", "content": "..."}]
|
| 301 |
+
All content fields can contain multilingual text
|
| 302 |
+
language: Language code (en, hi, te, ta, bn, gu)
|
| 303 |
+
|
| 304 |
+
Returns:
|
| 305 |
+
Dict with 'response' and 'sources'
|
| 306 |
+
"""
|
| 307 |
+
try:
|
| 308 |
+
# Verify message encoding (defensive check)
|
| 309 |
+
if not isinstance(message, str):
|
| 310 |
+
message = str(message)
|
| 311 |
+
|
| 312 |
+
# Convert chat history to LangChain format
|
| 313 |
+
# This preserves all Unicode characters from previous conversations
|
| 314 |
+
lc_history = []
|
| 315 |
+
for msg in chat_history[-10:]: # Keep last 10 messages for context
|
| 316 |
+
content = msg.get("content", "")
|
| 317 |
+
# Ensure content is properly decoded string
|
| 318 |
+
if not isinstance(content, str):
|
| 319 |
+
content = str(content)
|
| 320 |
+
|
| 321 |
+
if msg["role"] == "user":
|
| 322 |
+
lc_history.append(HumanMessage(content=content))
|
| 323 |
+
elif msg["role"] == "assistant":
|
| 324 |
+
lc_history.append(AIMessage(content=content))
|
| 325 |
+
|
| 326 |
+
# Get relevant documents
|
| 327 |
+
print(
|
| 328 |
+
f"[DEBUG] Retrieving documents for message: {message[:50]}...", file=sys.stderr)
|
| 329 |
+
docs = self.retriever.invoke(message)
|
| 330 |
+
print(f"[DEBUG] Retrieved {len(docs)} documents", file=sys.stderr)
|
| 331 |
+
|
| 332 |
+
# Generate response - LLM will respond in specified language
|
| 333 |
+
print(
|
| 334 |
+
f"[DEBUG] Calling LLM chain with language: {language}", file=sys.stderr)
|
| 335 |
+
response = self.chain.invoke({
|
| 336 |
+
"question": message,
|
| 337 |
+
"chat_history": lc_history,
|
| 338 |
+
"language": language
|
| 339 |
+
})
|
| 340 |
+
print(
|
| 341 |
+
f"[DEBUG] LLM responded with {len(response) if response else 0} chars", file=sys.stderr)
|
| 342 |
+
|
| 343 |
+
# Verify response is string (should contain Hindi/Telugu if input was)
|
| 344 |
+
if not isinstance(response, str):
|
| 345 |
+
response = str(response)
|
| 346 |
+
|
| 347 |
+
# Format sources
|
| 348 |
+
sources = []
|
| 349 |
+
for doc in docs[:4]: # Top 4 sources
|
| 350 |
+
sources.append({
|
| 351 |
+
"title": doc.metadata.get("title", "Unknown"),
|
| 352 |
+
"chunk_index": doc.metadata.get("chunk_index", 0),
|
| 353 |
+
"snippet": doc.page_content[:250]
|
| 354 |
+
})
|
| 355 |
+
|
| 356 |
+
return {
|
| 357 |
+
"response": response,
|
| 358 |
+
"sources": sources,
|
| 359 |
+
"error": None
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
except Exception as e:
|
| 363 |
+
error_msg = str(e)
|
| 364 |
+
print(f"Error in chat: {error_msg}", file=sys.stderr)
|
| 365 |
+
return {
|
| 366 |
+
"response": None,
|
| 367 |
+
"sources": [],
|
| 368 |
+
"error": error_msg
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
def generate_initial_greeting(self, assessment_summary: str, language: str = "en") -> Dict:
|
| 372 |
+
"""
|
| 373 |
+
Generate an initial greeting based on assessment results
|
| 374 |
+
|
| 375 |
+
Args:
|
| 376 |
+
assessment_summary: Summary of the assessment results
|
| 377 |
+
language: Language code (currently only 'en' is fully supported)
|
| 378 |
+
|
| 379 |
+
Returns:
|
| 380 |
+
Dict with 'response' and 'sources'
|
| 381 |
+
"""
|
| 382 |
+
try:
|
| 383 |
+
# Language-specific instructions
|
| 384 |
+
lang_instructions = {
|
| 385 |
+
"en": "Generate in English",
|
| 386 |
+
"hi": "Generate in Hindi (हिंदी में जवाब दें)",
|
| 387 |
+
"te": "Generate in Telugu (తెలుగులో సమాధానం ఇవ్వండి)",
|
| 388 |
+
"ta": "Generate in Tamil (தமிழில் பதிலளிக்கவும்)",
|
| 389 |
+
"mr": "Generate in Marathi (मराठीत उत्तर द्या)",
|
| 390 |
+
"bn": "Generate in Bengali (বাংলায় উত্তর দিন)"
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
lang_instruction = lang_instructions.get(
|
| 394 |
+
language, "Generate in English")
|
| 395 |
+
|
| 396 |
+
greeting_prompt = f"""Based on this student's assessment results, generate a warm, encouraging greeting that:
|
| 397 |
+
1. Welcomes them to the career guidance chat
|
| 398 |
+
2. Briefly acknowledges their assessment results
|
| 399 |
+
3. Invites them to ask questions about their career recommendations
|
| 400 |
+
4. Is age-appropriate for students aged 13-15
|
| 401 |
+
|
| 402 |
+
{lang_instruction}
|
| 403 |
+
|
| 404 |
+
Assessment Summary:
|
| 405 |
+
{assessment_summary}
|
| 406 |
+
|
| 407 |
+
Keep the greeting concise (2-3 sentences) and friendly."""
|
| 408 |
+
|
| 409 |
+
result = self.chat(greeting_prompt, [], language)
|
| 410 |
+
return result
|
| 411 |
+
|
| 412 |
+
except Exception as e:
|
| 413 |
+
print(
|
| 414 |
+
f"Error generating initial greeting: {str(e)}", file=sys.stderr)
|
| 415 |
+
return {
|
| 416 |
+
"response": f"Hello! I'm your career guidance assistant. I'm here to help you explore your career options based on your assessment results. What would you like to know?",
|
| 417 |
+
"sources": [],
|
| 418 |
+
"error": str(e)
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
def safe_json_dumps(obj):
|
| 423 |
+
"""Safely serialize JSON with proper UTF-8 encoding"""
|
| 424 |
+
return json.dumps(obj, ensure_ascii=False, indent=None)
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
def main():
|
| 428 |
+
"""
|
| 429 |
+
Main function to handle JSON-based API requests from Node.js
|
| 430 |
+
Reads JSON from stdin (one command per line) and writes JSON to stdout
|
| 431 |
+
"""
|
| 432 |
+
# Global service instance
|
| 433 |
+
rag_service = None
|
| 434 |
+
|
| 435 |
+
# Read all input lines
|
| 436 |
+
for line in sys.stdin:
|
| 437 |
+
line = line.strip()
|
| 438 |
+
if not line:
|
| 439 |
+
continue
|
| 440 |
+
|
| 441 |
+
try:
|
| 442 |
+
input_data = json.loads(line)
|
| 443 |
+
command = input_data.get("command")
|
| 444 |
+
|
| 445 |
+
if command == "initialize":
|
| 446 |
+
# Initialize the service
|
| 447 |
+
careers_json = input_data.get("careers_json_path")
|
| 448 |
+
chroma_dir = input_data.get("chroma_persist_dir")
|
| 449 |
+
provider = input_data.get("provider", "google")
|
| 450 |
+
|
| 451 |
+
# Create service instance
|
| 452 |
+
rag_service = RAGChatService(
|
| 453 |
+
careers_json, chroma_dir, provider)
|
| 454 |
+
|
| 455 |
+
print(safe_json_dumps({
|
| 456 |
+
"status": "success",
|
| 457 |
+
"message": "RAG service initialized"
|
| 458 |
+
}), flush=True)
|
| 459 |
+
|
| 460 |
+
elif command == "chat":
|
| 461 |
+
message = input_data.get("message")
|
| 462 |
+
chat_history = input_data.get("chat_history", [])
|
| 463 |
+
language = input_data.get("language", "en")
|
| 464 |
+
|
| 465 |
+
if rag_service is None:
|
| 466 |
+
raise Exception(
|
| 467 |
+
"Service not initialized. Call 'initialize' first.")
|
| 468 |
+
|
| 469 |
+
result = rag_service.chat(message, chat_history, language)
|
| 470 |
+
|
| 471 |
+
# Debug: log what we're about to send
|
| 472 |
+
print(
|
| 473 |
+
f"[DEBUG] Chat result: response={result.get('response') is not None}, error={result.get('error')}", file=sys.stderr)
|
| 474 |
+
|
| 475 |
+
# If the chat method returned an error, propagate it properly
|
| 476 |
+
if result.get("error"):
|
| 477 |
+
print(safe_json_dumps({
|
| 478 |
+
"status": "error",
|
| 479 |
+
"message": result["error"],
|
| 480 |
+
"data": result
|
| 481 |
+
}), flush=True)
|
| 482 |
+
else:
|
| 483 |
+
print(safe_json_dumps({
|
| 484 |
+
"status": "success",
|
| 485 |
+
"data": result
|
| 486 |
+
}), flush=True)
|
| 487 |
+
|
| 488 |
+
elif command == "greeting":
|
| 489 |
+
assessment_summary = input_data.get("assessment_summary")
|
| 490 |
+
language = input_data.get("language", "en")
|
| 491 |
+
|
| 492 |
+
if rag_service is None:
|
| 493 |
+
raise Exception(
|
| 494 |
+
"Service not initialized. Call 'initialize' first.")
|
| 495 |
+
|
| 496 |
+
result = rag_service.generate_initial_greeting(
|
| 497 |
+
assessment_summary, language)
|
| 498 |
+
|
| 499 |
+
# If the greeting method returned an error, propagate it properly
|
| 500 |
+
if result.get("error"):
|
| 501 |
+
print(safe_json_dumps({
|
| 502 |
+
"status": "error",
|
| 503 |
+
"message": result["error"],
|
| 504 |
+
"data": result
|
| 505 |
+
}), flush=True)
|
| 506 |
+
else:
|
| 507 |
+
print(safe_json_dumps({
|
| 508 |
+
"status": "success",
|
| 509 |
+
"data": result
|
| 510 |
+
}), flush=True)
|
| 511 |
+
|
| 512 |
+
else:
|
| 513 |
+
print(safe_json_dumps({
|
| 514 |
+
"status": "error",
|
| 515 |
+
"message": f"Unknown command: {command}"
|
| 516 |
+
}), flush=True)
|
| 517 |
+
|
| 518 |
+
except Exception as e:
|
| 519 |
+
print(safe_json_dumps({
|
| 520 |
+
"status": "error",
|
| 521 |
+
"message": str(e)
|
| 522 |
+
}), flush=True)
|
| 523 |
+
|
| 524 |
+
|
| 525 |
+
if __name__ == "__main__":
|
| 526 |
+
main()
|
| 527 |
+
|
| 528 |
+
# """
|
| 529 |
+
# RAG Service for Career Guidance Chatbot
|
| 530 |
+
# This service wraps the RAG chatbot functionality for integration with the Node.js backend.
|
| 531 |
+
# """
|
| 532 |
+
# from langchain_huggingface import HuggingFaceEmbeddings
|
| 533 |
+
# from langchain_core.messages import HumanMessage, AIMessage
|
| 534 |
+
# from langchain_core.output_parsers import StrOutputParser
|
| 535 |
+
# from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
| 536 |
+
# from langchain_core.documents import Document
|
| 537 |
+
# from langchain_chroma import Chroma
|
| 538 |
+
# from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 539 |
+
# from dotenv import load_dotenv
|
| 540 |
+
# import json
|
| 541 |
+
# import os
|
| 542 |
+
# import sys
|
| 543 |
+
# from typing import List, Dict, Optional
|
| 544 |
+
# from pathlib import Path
|
| 545 |
+
|
| 546 |
+
# # Load environment variables from .env file
|
| 547 |
+
# # Look for .env in backend directory (parent of src)
|
| 548 |
+
# backend_dir = Path(__file__).parent.parent.parent
|
| 549 |
+
# env_path = backend_dir / '.env'
|
| 550 |
+
# if env_path.exists():
|
| 551 |
+
# load_dotenv(env_path)
|
| 552 |
+
# print(f"Loaded .env from {env_path}", file=sys.stderr)
|
| 553 |
+
# else:
|
| 554 |
+
# print(f"Warning: .env not found at {env_path}", file=sys.stderr)
|
| 555 |
+
# load_dotenv() # Try to load from current directory
|
| 556 |
+
|
| 557 |
+
# # Add parent directory to path for imports
|
| 558 |
+
# sys.path.insert(0, str(backend_dir))
|
| 559 |
+
|
| 560 |
+
|
| 561 |
+
# # Configuration
|
| 562 |
+
# CHUNK_SIZE = 512
|
| 563 |
+
# CHUNK_OVERLAP = 150
|
| 564 |
+
|
| 565 |
+
|
| 566 |
+
# class RAGChatService:
|
| 567 |
+
# def __init__(self, careers_json_path: str, chroma_persist_dir: str, provider: str = "google"):
|
| 568 |
+
# """
|
| 569 |
+
# Initialize the RAG Chat Service
|
| 570 |
+
|
| 571 |
+
# Args:
|
| 572 |
+
# careers_json_path: Path to careers_cleaned.json
|
| 573 |
+
# chroma_persist_dir: Path to chroma_data_full directory
|
| 574 |
+
# provider: LLM provider to use ("google" or "groq")
|
| 575 |
+
# """
|
| 576 |
+
# self.provider = provider
|
| 577 |
+
# self.careers_json_path = careers_json_path
|
| 578 |
+
# self.chroma_persist_dir = chroma_persist_dir
|
| 579 |
+
|
| 580 |
+
# # Initialize embeddings
|
| 581 |
+
# self.embeddings = HuggingFaceEmbeddings(
|
| 582 |
+
# model_name="sentence-transformers/all-mpnet-base-v2"
|
| 583 |
+
# )
|
| 584 |
+
# # self.embeddings = HuggingFaceEmbeddings(
|
| 585 |
+
# # model_name="BAAI/bge-m3"
|
| 586 |
+
# # )
|
| 587 |
+
|
| 588 |
+
# # Initialize or load vector database
|
| 589 |
+
# self.vectordb = self._init_vectordb()
|
| 590 |
+
|
| 591 |
+
# # Initialize LLM
|
| 592 |
+
# self.llm = self._init_llm()
|
| 593 |
+
|
| 594 |
+
# # Initialize retriever
|
| 595 |
+
# self.retriever = self.vectordb.as_retriever(search_kwargs={"k": 3})
|
| 596 |
+
|
| 597 |
+
# # Build the chain
|
| 598 |
+
# self.chain = self._build_chain()
|
| 599 |
+
|
| 600 |
+
# def _init_vectordb(self) -> Chroma:
|
| 601 |
+
# """Initialize or load Chroma vector database"""
|
| 602 |
+
# if os.path.exists(self.chroma_persist_dir) and os.listdir(self.chroma_persist_dir):
|
| 603 |
+
# print(
|
| 604 |
+
# f"Loading existing Chroma DB from {self.chroma_persist_dir}", file=sys.stderr)
|
| 605 |
+
# return Chroma(
|
| 606 |
+
# persist_directory=self.chroma_persist_dir,
|
| 607 |
+
# embedding_function=self.embeddings
|
| 608 |
+
# )
|
| 609 |
+
# else:
|
| 610 |
+
# print(
|
| 611 |
+
# f"Creating new Chroma DB at {self.chroma_persist_dir}", file=sys.stderr)
|
| 612 |
+
# items = self._load_json(self.careers_json_path)
|
| 613 |
+
# docs = self._json_to_docs(items)
|
| 614 |
+
# return Chroma.from_documents(
|
| 615 |
+
# documents=docs,
|
| 616 |
+
# embedding=self.embeddings,
|
| 617 |
+
# persist_directory=self.chroma_persist_dir
|
| 618 |
+
# )
|
| 619 |
+
|
| 620 |
+
# def _load_json(self, path: str) -> List[Dict]:
|
| 621 |
+
# """Load careers JSON file"""
|
| 622 |
+
# with open(path, "r", encoding="utf-8") as f:
|
| 623 |
+
# return json.load(f)
|
| 624 |
+
|
| 625 |
+
# def _json_to_docs(self, items: List[Dict]) -> List[Document]:
|
| 626 |
+
# """Convert JSON items to Document chunks"""
|
| 627 |
+
# splitter = RecursiveCharacterTextSplitter(
|
| 628 |
+
# chunk_size=CHUNK_SIZE,
|
| 629 |
+
# chunk_overlap=CHUNK_OVERLAP,
|
| 630 |
+
# separators=["\n\n", "\n", " ", ""],
|
| 631 |
+
# )
|
| 632 |
+
|
| 633 |
+
# docs = []
|
| 634 |
+
# for item in items:
|
| 635 |
+
# combined = f"{item['title']}\n\n{item['content']}"
|
| 636 |
+
# chunks = splitter.split_text(combined)
|
| 637 |
+
|
| 638 |
+
# for i, ch in enumerate(chunks):
|
| 639 |
+
# docs.append(Document(
|
| 640 |
+
# page_content=ch,
|
| 641 |
+
# metadata={
|
| 642 |
+
# "source_id": item["id"],
|
| 643 |
+
# "title": item["title"],
|
| 644 |
+
# "chunk_index": i
|
| 645 |
+
# }
|
| 646 |
+
# ))
|
| 647 |
+
# return docs
|
| 648 |
+
|
| 649 |
+
# def _init_llm(self):
|
| 650 |
+
# """Initialize the LLM based on provider"""
|
| 651 |
+
# if self.provider == "groq":
|
| 652 |
+
# from langchain_groq import ChatGroq
|
| 653 |
+
# return ChatGroq(
|
| 654 |
+
# model="llama-3.3-70b-versatile",
|
| 655 |
+
# temperature=0.1,
|
| 656 |
+
# max_tokens=1500
|
| 657 |
+
# )
|
| 658 |
+
# elif self.provider == "google":
|
| 659 |
+
# from langchain_google_genai import ChatGoogleGenerativeAI
|
| 660 |
+
# return ChatGoogleGenerativeAI(
|
| 661 |
+
# model="gemini-2.5-pro",
|
| 662 |
+
# temperature=0.1,
|
| 663 |
+
# max_output_tokens=1500
|
| 664 |
+
# )
|
| 665 |
+
# else:
|
| 666 |
+
# raise ValueError(f"Unknown provider: {self.provider}")
|
| 667 |
+
|
| 668 |
+
# def _build_chain(self):
|
| 669 |
+
# """Build the conversational RAG chain"""
|
| 670 |
+
# prompt = ChatPromptTemplate.from_messages([
|
| 671 |
+
# ("system",
|
| 672 |
+
# """You are a helpful and friendly career guidance assistant for Indian students aged 13-15.
|
| 673 |
+
|
| 674 |
+
# When answering questions about careers, education paths, or professional guidance:
|
| 675 |
+
# - Keep responses SHORT and CONCISE (2-4 paragraphs maximum)
|
| 676 |
+
# - Prioritize information from the Context provided below
|
| 677 |
+
# - Use the context to give detailed, specific answers
|
| 678 |
+
# - Consider Indian cultural context, family expectations, and local opportunities
|
| 679 |
+
# - If the context has relevant information, base your answer primarily on it
|
| 680 |
+
# - If the context doesn't have the information, you can provide general career guidance relevant to India
|
| 681 |
+
# - If the question is unrelated to career guidance/education/careers, politely inform the user that you can only assist with career-related queries
|
| 682 |
+
# - Keep responses age-appropriate, encouraging, and culturally sensitive
|
| 683 |
+
|
| 684 |
+
# Context:
|
| 685 |
+
# {context}"""),
|
| 686 |
+
# MessagesPlaceholder("chat_history"),
|
| 687 |
+
# ("human", "{question}")
|
| 688 |
+
# ])
|
| 689 |
+
|
| 690 |
+
# def format_docs(docs):
|
| 691 |
+
# if not docs:
|
| 692 |
+
# return "No relevant information found."
|
| 693 |
+
# formatted = []
|
| 694 |
+
# for i, doc in enumerate(docs, 1):
|
| 695 |
+
# formatted.append(
|
| 696 |
+
# f"[Source {i}: {doc.metadata.get('title', 'Unknown')}]\n{doc.page_content}")
|
| 697 |
+
# return "\n\n---\n\n".join(formatted)
|
| 698 |
+
|
| 699 |
+
# def get_context(inputs):
|
| 700 |
+
# question = inputs["question"]
|
| 701 |
+
# docs = self.retriever.invoke(question)
|
| 702 |
+
# return format_docs(docs)
|
| 703 |
+
|
| 704 |
+
# chain = (
|
| 705 |
+
# {
|
| 706 |
+
# "context": get_context,
|
| 707 |
+
# "question": lambda x: x["question"],
|
| 708 |
+
# "chat_history": lambda x: x.get("chat_history", [])
|
| 709 |
+
# }
|
| 710 |
+
# | prompt
|
| 711 |
+
# | self.llm
|
| 712 |
+
# | StrOutputParser()
|
| 713 |
+
# )
|
| 714 |
+
|
| 715 |
+
# return chain
|
| 716 |
+
|
| 717 |
+
# def chat(self, message: str, chat_history: List[Dict]) -> Dict:
|
| 718 |
+
# """
|
| 719 |
+
# Process a chat message and return a response
|
| 720 |
+
|
| 721 |
+
# Args:
|
| 722 |
+
# message: User's message
|
| 723 |
+
# chat_history: List of previous messages in format [{"role": "user"|"assistant", "content": "..."}]
|
| 724 |
+
|
| 725 |
+
# Returns:
|
| 726 |
+
# Dict with 'response' and 'sources'
|
| 727 |
+
# """
|
| 728 |
+
# try:
|
| 729 |
+
# # Convert chat history to LangChain format
|
| 730 |
+
# lc_history = []
|
| 731 |
+
# for msg in chat_history[-10:]: # Keep last 10 messages for context
|
| 732 |
+
# if msg["role"] == "user":
|
| 733 |
+
# lc_history.append(HumanMessage(content=msg["content"]))
|
| 734 |
+
# elif msg["role"] == "assistant":
|
| 735 |
+
# lc_history.append(AIMessage(content=msg["content"]))
|
| 736 |
+
|
| 737 |
+
# # Get relevant documents
|
| 738 |
+
# docs = self.retriever.invoke(message)
|
| 739 |
+
|
| 740 |
+
# # Generate response
|
| 741 |
+
# response = self.chain.invoke({
|
| 742 |
+
# "question": message,
|
| 743 |
+
# "chat_history": lc_history
|
| 744 |
+
# })
|
| 745 |
+
|
| 746 |
+
# # Format sources
|
| 747 |
+
# sources = []
|
| 748 |
+
# for doc in docs[:4]: # Top 4 sources
|
| 749 |
+
# sources.append({
|
| 750 |
+
# "title": doc.metadata.get("title", "Unknown"),
|
| 751 |
+
# "chunk_index": doc.metadata.get("chunk_index", 0),
|
| 752 |
+
# "snippet": doc.page_content[:250]
|
| 753 |
+
# })
|
| 754 |
+
|
| 755 |
+
# return {
|
| 756 |
+
# "response": response,
|
| 757 |
+
# "sources": sources,
|
| 758 |
+
# "error": None
|
| 759 |
+
# }
|
| 760 |
+
|
| 761 |
+
# except Exception as e:
|
| 762 |
+
# print(f"Error in chat: {str(e)}", file=sys.stderr)
|
| 763 |
+
# return {
|
| 764 |
+
# "response": None,
|
| 765 |
+
# "sources": [],
|
| 766 |
+
# "error": str(e)
|
| 767 |
+
# }
|
| 768 |
+
|
| 769 |
+
# def generate_initial_greeting(self, assessment_summary: str, language: str = "en") -> Dict:
|
| 770 |
+
# """
|
| 771 |
+
# Generate an initial greeting based on assessment results
|
| 772 |
+
|
| 773 |
+
# Args:
|
| 774 |
+
# assessment_summary: Summary of the assessment results
|
| 775 |
+
# language: Language code (currently only 'en' is fully supported)
|
| 776 |
+
|
| 777 |
+
# Returns:
|
| 778 |
+
# Dict with 'response' and 'sources'
|
| 779 |
+
# """
|
| 780 |
+
# try:
|
| 781 |
+
# greeting_prompt = f"""Based on this student's assessment results, generate a warm, encouraging greeting that:
|
| 782 |
+
# 1. Welcomes them to the career guidance chat
|
| 783 |
+
# 2. Briefly acknowledges their assessment results
|
| 784 |
+
# 3. Invites them to ask questions about their career recommendations
|
| 785 |
+
# 4. Is age-appropriate for students aged 13-15
|
| 786 |
+
|
| 787 |
+
# Assessment Summary:
|
| 788 |
+
# {assessment_summary}
|
| 789 |
+
|
| 790 |
+
# Keep the greeting concise (2-3 sentences) and friendly."""
|
| 791 |
+
|
| 792 |
+
# result = self.chat(greeting_prompt, [])
|
| 793 |
+
# return result
|
| 794 |
+
|
| 795 |
+
# except Exception as e:
|
| 796 |
+
# print(
|
| 797 |
+
# f"Error generating initial greeting: {str(e)}", file=sys.stderr)
|
| 798 |
+
# return {
|
| 799 |
+
# "response": f"Hello! I'm your career guidance assistant. I'm here to help you explore your career options based on your assessment results. What would you like to know?",
|
| 800 |
+
# "sources": [],
|
| 801 |
+
# "error": str(e)
|
| 802 |
+
# }
|
| 803 |
+
|
| 804 |
+
|
| 805 |
+
# def main():
|
| 806 |
+
# """
|
| 807 |
+
# Main function to handle JSON-based API requests from Node.js
|
| 808 |
+
# Reads JSON from stdin (one command per line) and writes JSON to stdout
|
| 809 |
+
# """
|
| 810 |
+
# # Global service instance
|
| 811 |
+
# rag_service = None
|
| 812 |
+
|
| 813 |
+
# # Read all input lines
|
| 814 |
+
# for line in sys.stdin:
|
| 815 |
+
# line = line.strip()
|
| 816 |
+
# if not line:
|
| 817 |
+
# continue
|
| 818 |
+
|
| 819 |
+
# try:
|
| 820 |
+
# input_data = json.loads(line)
|
| 821 |
+
# command = input_data.get("command")
|
| 822 |
+
|
| 823 |
+
# if command == "initialize":
|
| 824 |
+
# # Initialize the service
|
| 825 |
+
# careers_json = input_data.get("careers_json_path")
|
| 826 |
+
# chroma_dir = input_data.get("chroma_persist_dir")
|
| 827 |
+
# provider = input_data.get("provider", "google")
|
| 828 |
+
|
| 829 |
+
# # Create service instance
|
| 830 |
+
# rag_service = RAGChatService(
|
| 831 |
+
# careers_json, chroma_dir, provider)
|
| 832 |
+
|
| 833 |
+
# print(json.dumps({
|
| 834 |
+
# "status": "success",
|
| 835 |
+
# "message": "RAG service initialized"
|
| 836 |
+
# }), flush=True)
|
| 837 |
+
|
| 838 |
+
# elif command == "chat":
|
| 839 |
+
# message = input_data.get("message")
|
| 840 |
+
# chat_history = input_data.get("chat_history", [])
|
| 841 |
+
|
| 842 |
+
# if rag_service is None:
|
| 843 |
+
# raise Exception(
|
| 844 |
+
# "Service not initialized. Call 'initialize' first.")
|
| 845 |
+
|
| 846 |
+
# result = rag_service.chat(message, chat_history)
|
| 847 |
+
# print(json.dumps({
|
| 848 |
+
# "status": "success",
|
| 849 |
+
# "data": result
|
| 850 |
+
# }), flush=True)
|
| 851 |
+
|
| 852 |
+
# elif command == "greeting":
|
| 853 |
+
# assessment_summary = input_data.get("assessment_summary")
|
| 854 |
+
# language = input_data.get("language", "en")
|
| 855 |
+
|
| 856 |
+
# if rag_service is None:
|
| 857 |
+
# raise Exception(
|
| 858 |
+
# "Service not initialized. Call 'initialize' first.")
|
| 859 |
+
|
| 860 |
+
# result = rag_service.generate_initial_greeting(
|
| 861 |
+
# assessment_summary, language)
|
| 862 |
+
# print(json.dumps({
|
| 863 |
+
# "status": "success",
|
| 864 |
+
# "data": result
|
| 865 |
+
# }), flush=True)
|
| 866 |
+
|
| 867 |
+
# else:
|
| 868 |
+
# print(json.dumps({
|
| 869 |
+
# "status": "error",
|
| 870 |
+
# "message": f"Unknown command: {command}"
|
| 871 |
+
# }), flush=True)
|
| 872 |
+
|
| 873 |
+
# except Exception as e:
|
| 874 |
+
# print(json.dumps({
|
| 875 |
+
# "status": "error",
|
| 876 |
+
# "message": str(e)
|
| 877 |
+
# }), flush=True)
|
| 878 |
+
|
| 879 |
+
|
| 880 |
+
# if __name__ == "__main__":
|
| 881 |
+
# main()
|
backend/src/services/riasecService.ts
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as fs from 'fs';
|
| 2 |
+
import * as path from 'path';
|
| 3 |
+
|
| 4 |
+
// RIASEC question mapping - maps question ID to RIASEC code
|
| 5 |
+
// This matches the order in riasec_questions.csv
|
| 6 |
+
const RIASEC_QUESTION_MAPPING: { [questionId: number]: string } = {
|
| 7 |
+
1: 'C', 2: 'S', 3: 'E', 4: 'S', 5: 'C', 6: 'E', 7: 'S', 8: 'E', 9: 'I', 10: 'E',
|
| 8 |
+
11: 'E', 12: 'I', 13: 'I', 14: 'I', 15: 'I', 16: 'I', 17: 'S', 18: 'C', 19: 'I', 20: 'C',
|
| 9 |
+
21: 'S', 22: 'C', 23: 'S', 24: 'C', 25: 'R', 26: 'R', 27: 'I', 28: 'S', 29: 'A', 30: 'A',
|
| 10 |
+
31: 'A', 32: 'E', 33: 'A', 34: 'R', 35: 'R', 36: 'C', 37: 'R', 38: 'E', 39: 'A', 40: 'E',
|
| 11 |
+
41: 'R', 42: 'C', 43: 'A', 44: 'A', 45: 'S', 46: 'R', 47: 'A', 48: 'R'
|
| 12 |
+
};
|
| 13 |
+
|
| 14 |
+
// Map answer strings to Likert scale (1-5)
|
| 15 |
+
const ANSWER_TO_SCORE: { [key: string]: number } = {
|
| 16 |
+
// English
|
| 17 |
+
'strongly disagree': 1,
|
| 18 |
+
'disagree': 2,
|
| 19 |
+
'neutral': 3,
|
| 20 |
+
'agree': 4,
|
| 21 |
+
'strongly agree': 5,
|
| 22 |
+
// Hindi
|
| 23 |
+
'बिल्कुल असहमत': 1,
|
| 24 |
+
'असहमत': 2,
|
| 25 |
+
'तटस्थ': 3,
|
| 26 |
+
'सहमत': 4,
|
| 27 |
+
'पूर्णतः सहमत': 5,
|
| 28 |
+
// Telugu
|
| 29 |
+
'పూర్తిగా అంగీకరించను': 1,
|
| 30 |
+
'అంగీకరించను': 2,
|
| 31 |
+
'తటస్థ': 3,
|
| 32 |
+
'అంగీకరిస్తున్నాను': 4,
|
| 33 |
+
'పూర్తిగా అంగీకరిస్తున్నాను': 5,
|
| 34 |
+
// Tamil
|
| 35 |
+
'முற்றிலும் மறுக்கிறேன்': 1,
|
| 36 |
+
'மறுக்கிறேன்': 2,
|
| 37 |
+
'நடுநிலை': 3,
|
| 38 |
+
'ஒப்புக்கொள்கிறேன்': 4,
|
| 39 |
+
'முற்றிலும் ஒப்புக்கொள்கிறேன்': 5,
|
| 40 |
+
// Bengali
|
| 41 |
+
'সম্পূর্ণ অসম্মত': 1,
|
| 42 |
+
'অসম্মত': 2,
|
| 43 |
+
'নিরপেক্ষ': 3,
|
| 44 |
+
'সম্মত': 4,
|
| 45 |
+
'সম্পূর্ণ সম্মত': 5,
|
| 46 |
+
// Gujarati
|
| 47 |
+
'સંપૂર્ણ અસહમત': 1,
|
| 48 |
+
'અસહમત': 2,
|
| 49 |
+
'તટસ્થ': 3,
|
| 50 |
+
'સહમત': 4,
|
| 51 |
+
'સંપૂર્ણ સહમત': 5,
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
export interface RIASECScoreResult {
|
| 55 |
+
scores: { [code: string]: number }; // R, I, A, S, E, C scores (0-100)
|
| 56 |
+
top3: string; // Top 3 RIASEC codes (e.g., "IES")
|
| 57 |
+
ordered: Array<{ code: string; score: number }>; // All codes sorted by score
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
/**
|
| 61 |
+
* Converts answer string to Likert scale score (1-5)
|
| 62 |
+
*/
|
| 63 |
+
function answerToScore(answer: string | string[]): number {
|
| 64 |
+
const answerStr = Array.isArray(answer) ? answer[0] : answer;
|
| 65 |
+
const normalized = answerStr.toLowerCase().trim();
|
| 66 |
+
|
| 67 |
+
// Direct lookup
|
| 68 |
+
if (ANSWER_TO_SCORE[normalized]) {
|
| 69 |
+
return ANSWER_TO_SCORE[normalized];
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
// Fallback: try partial matches
|
| 73 |
+
for (const [key, score] of Object.entries(ANSWER_TO_SCORE)) {
|
| 74 |
+
if (normalized.includes(key) || key.includes(normalized)) {
|
| 75 |
+
return score;
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// Default to neutral if no match
|
| 80 |
+
return 3;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/**
|
| 84 |
+
* Calculates RIASEC scores from test answers
|
| 85 |
+
* @param answers - Object mapping question ID (as string) to answer value
|
| 86 |
+
* @returns RIASEC score result with normalized scores and top 3 codes
|
| 87 |
+
*/
|
| 88 |
+
export function calculateRIASECScore(
|
| 89 |
+
answers: { [questionId: string]: string | string[] }
|
| 90 |
+
): RIASECScoreResult {
|
| 91 |
+
const scores: { [code: string]: number } = { R: 0, I: 0, A: 0, S: 0, E: 0, C: 0 };
|
| 92 |
+
const counts: { [code: string]: number } = { R: 0, I: 0, A: 0, S: 0, E: 0, C: 0 };
|
| 93 |
+
|
| 94 |
+
// Process each answer
|
| 95 |
+
for (const [questionIdStr, answer] of Object.entries(answers)) {
|
| 96 |
+
const questionId = parseInt(questionIdStr, 10);
|
| 97 |
+
const riasecCode = RIASEC_QUESTION_MAPPING[questionId];
|
| 98 |
+
|
| 99 |
+
if (!riasecCode) {
|
| 100 |
+
console.warn(`No RIASEC code found for question ${questionId}`);
|
| 101 |
+
continue;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
const score = answerToScore(answer);
|
| 105 |
+
scores[riasecCode] += score;
|
| 106 |
+
counts[riasecCode] += 1;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
// Calculate averages
|
| 110 |
+
for (const code of Object.keys(scores)) {
|
| 111 |
+
if (counts[code] > 0) {
|
| 112 |
+
scores[code] = scores[code] / counts[code];
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
// Store averages before normalization for debugging
|
| 117 |
+
const averagesBeforeNormalization = { ...scores };
|
| 118 |
+
|
| 119 |
+
// Normalize to 0-100 scale
|
| 120 |
+
const scoreValues = Object.values(scores);
|
| 121 |
+
const minScore = Math.min(...scoreValues);
|
| 122 |
+
const maxScore = Math.max(...scoreValues);
|
| 123 |
+
|
| 124 |
+
if (maxScore !== minScore) {
|
| 125 |
+
for (const code of Object.keys(scores)) {
|
| 126 |
+
scores[code] = 100 * (scores[code] - minScore) / (maxScore - minScore);
|
| 127 |
+
}
|
| 128 |
+
} else {
|
| 129 |
+
// If all scores are equal, set to 50
|
| 130 |
+
for (const code of Object.keys(scores)) {
|
| 131 |
+
scores[code] = 50;
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
// Sort by score (descending) - use AVERAGES, not normalized scores for ranking
|
| 136 |
+
// This ensures we rank by actual preference, not normalized values
|
| 137 |
+
const ordered = Object.entries(averagesBeforeNormalization)
|
| 138 |
+
.map(([code, avgScore]) => ({
|
| 139 |
+
code,
|
| 140 |
+
averageScore: avgScore,
|
| 141 |
+
normalizedScore: scores[code]
|
| 142 |
+
}))
|
| 143 |
+
.sort((a, b) => b.averageScore - a.averageScore);
|
| 144 |
+
|
| 145 |
+
// Get top 3 codes based on average scores (before normalization)
|
| 146 |
+
const top3 = ordered.slice(0, 3).map(item => item.code).join('');
|
| 147 |
+
|
| 148 |
+
// Debug logging
|
| 149 |
+
console.log('=== RIASEC Score Calculation Debug ===');
|
| 150 |
+
console.log('Total answers processed:', Object.keys(answers).length);
|
| 151 |
+
console.log('Question counts per code:', counts);
|
| 152 |
+
console.log('Average scores (before normalization - used for ranking):', Object.fromEntries(
|
| 153 |
+
Object.entries(averagesBeforeNormalization).map(([code, score]) => [code, score.toFixed(2)])
|
| 154 |
+
));
|
| 155 |
+
console.log('Normalized scores (0-100 - for display only):', Object.fromEntries(
|
| 156 |
+
Object.entries(scores).map(([code, score]) => [code, score.toFixed(2)])
|
| 157 |
+
));
|
| 158 |
+
console.log('Ordered by average score:', ordered.map(item => `${item.code}: avg=${item.averageScore.toFixed(2)}, norm=${item.normalizedScore.toFixed(2)}`).join(', '));
|
| 159 |
+
console.log('Top 3 (by average):', top3);
|
| 160 |
+
console.log('=====================================');
|
| 161 |
+
|
| 162 |
+
// Return normalized scores for display, but ordered by average scores
|
| 163 |
+
return {
|
| 164 |
+
scores, // Normalized scores (0-100) for display
|
| 165 |
+
top3,
|
| 166 |
+
ordered: ordered.map(item => ({ code: item.code, score: item.normalizedScore })), // Use normalized for display
|
| 167 |
+
};
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
/**
|
| 171 |
+
* Loads careers from CSV file and returns careers matching RIASEC codes
|
| 172 |
+
* @param riasecCodes - String of 1-3 RIASEC codes (e.g., "IES", "R", "AS")
|
| 173 |
+
* @returns Array of matching career names
|
| 174 |
+
*/
|
| 175 |
+
export function getCareersByRIASECCode(riasecCodes: string): string[] {
|
| 176 |
+
const csvPath = path.join(__dirname, '../../..', 'careers_with_riasec_codes.csv');
|
| 177 |
+
|
| 178 |
+
if (!fs.existsSync(csvPath)) {
|
| 179 |
+
console.error(`Careers CSV not found at: ${csvPath}`);
|
| 180 |
+
return [];
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
const csvContent = fs.readFileSync(csvPath, 'utf-8');
|
| 184 |
+
const lines = csvContent.split('\n').filter(line => line.trim());
|
| 185 |
+
|
| 186 |
+
// Skip header
|
| 187 |
+
const dataLines = lines.slice(1);
|
| 188 |
+
|
| 189 |
+
const matchingCareers: string[] = [];
|
| 190 |
+
const codesArray = riasecCodes.split('').filter(c => c.length > 0);
|
| 191 |
+
|
| 192 |
+
// First pass: Try to match codes with letters in order
|
| 193 |
+
for (const line of dataLines) {
|
| 194 |
+
// Parse CSV: find the last comma and split there
|
| 195 |
+
// This handles careers with commas in their names
|
| 196 |
+
const lastCommaIndex = line.lastIndexOf(',');
|
| 197 |
+
if (lastCommaIndex === -1) continue;
|
| 198 |
+
|
| 199 |
+
const career = line.substring(0, lastCommaIndex).trim().replace(/^"|"$/g, '');
|
| 200 |
+
const careerCode = line.substring(lastCommaIndex + 1).trim();
|
| 201 |
+
|
| 202 |
+
// Match careers where the code:
|
| 203 |
+
// 1. Starts with the top 3 codes in order (e.g., "RIA" matches "RIA", "RIAS", "RIAC")
|
| 204 |
+
// 2. Contains the top 3 codes as a substring in order (e.g., "RIA" matches "XRIA", "RIASEC")
|
| 205 |
+
// 3. Has all letters in the same order (e.g., "RIA" matches codes where R comes before I, I comes before A)
|
| 206 |
+
|
| 207 |
+
let matches = false;
|
| 208 |
+
|
| 209 |
+
// Priority 1: Exact match or starts with the codes
|
| 210 |
+
if (careerCode.startsWith(riasecCodes)) {
|
| 211 |
+
matches = true;
|
| 212 |
+
}
|
| 213 |
+
// Priority 2: Contains the codes as substring in order
|
| 214 |
+
else if (careerCode.includes(riasecCodes)) {
|
| 215 |
+
matches = true;
|
| 216 |
+
}
|
| 217 |
+
// Priority 3: Check if all letters appear in order (R before I before A)
|
| 218 |
+
else {
|
| 219 |
+
const careerCodeLetters = careerCode.split('');
|
| 220 |
+
let lastIndex = -1;
|
| 221 |
+
let allInOrder = true;
|
| 222 |
+
|
| 223 |
+
for (const code of codesArray) {
|
| 224 |
+
const currentIndex = careerCodeLetters.indexOf(code, lastIndex + 1);
|
| 225 |
+
if (currentIndex === -1) {
|
| 226 |
+
allInOrder = false;
|
| 227 |
+
break;
|
| 228 |
+
}
|
| 229 |
+
lastIndex = currentIndex;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
matches = allInOrder;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
if (matches) {
|
| 236 |
+
matchingCareers.push(career);
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
// If no matches found with ordered logic, fall back to matching codes that contain all letters in any order
|
| 241 |
+
if (matchingCareers.length === 0) {
|
| 242 |
+
const generatePermutations = (arr: string[]): string[] => {
|
| 243 |
+
if (arr.length <= 1) return arr;
|
| 244 |
+
const result: string[] = [];
|
| 245 |
+
for (let i = 0; i < arr.length; i++) {
|
| 246 |
+
const rest = [...arr.slice(0, i), ...arr.slice(i + 1)];
|
| 247 |
+
const perms = generatePermutations(rest);
|
| 248 |
+
for (const perm of perms) {
|
| 249 |
+
result.push(arr[i] + perm);
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
return result;
|
| 253 |
+
};
|
| 254 |
+
|
| 255 |
+
const permutations = generatePermutations(codesArray);
|
| 256 |
+
|
| 257 |
+
for (const line of dataLines) {
|
| 258 |
+
const lastCommaIndex = line.lastIndexOf(',');
|
| 259 |
+
if (lastCommaIndex === -1) continue;
|
| 260 |
+
|
| 261 |
+
const career = line.substring(0, lastCommaIndex).trim().replace(/^"|"$/g, '');
|
| 262 |
+
const careerCode = line.substring(lastCommaIndex + 1).trim();
|
| 263 |
+
|
| 264 |
+
// Check if career code:
|
| 265 |
+
// 1. Is an exact permutation match (RIA, RAI, IAR, IRA, ARI, AIR)
|
| 266 |
+
// 2. Starts with any permutation
|
| 267 |
+
// 3. Contains any permutation as substring
|
| 268 |
+
// 4. Contains all letters in any order (fallback)
|
| 269 |
+
let matches = false;
|
| 270 |
+
|
| 271 |
+
// Check exact permutation match
|
| 272 |
+
if (permutations.includes(careerCode)) {
|
| 273 |
+
matches = true;
|
| 274 |
+
}
|
| 275 |
+
// Check if code starts with any permutation
|
| 276 |
+
else if (permutations.some(perm => careerCode.startsWith(perm))) {
|
| 277 |
+
matches = true;
|
| 278 |
+
}
|
| 279 |
+
// Check if code contains any permutation as substring
|
| 280 |
+
else if (permutations.some(perm => careerCode.includes(perm))) {
|
| 281 |
+
matches = true;
|
| 282 |
+
}
|
| 283 |
+
// Fallback: Check if career code contains all letters from riasecCodes (in any order)
|
| 284 |
+
else {
|
| 285 |
+
const careerCodeLetters = careerCode.split('');
|
| 286 |
+
const allCodesPresent = codesArray.every(code => careerCodeLetters.includes(code));
|
| 287 |
+
matches = allCodesPresent;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
if (matches) {
|
| 291 |
+
matchingCareers.push(career);
|
| 292 |
+
}
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
return matchingCareers;
|
| 297 |
+
}
|
| 298 |
+
|
backend/src/types.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export type Language = "en" | "hi" | "te" | "ta" | "bn" | "gu";
|
| 2 |
+
export type TestType = "riasec" | "values" | "personal";
|
| 3 |
+
|
| 4 |
+
export interface UserProfile {
|
| 5 |
+
name: string;
|
| 6 |
+
class: string;
|
| 7 |
+
age?: string;
|
| 8 |
+
language: Language;
|
| 9 |
+
email?: string;
|
| 10 |
+
phone?: string;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export interface AssessmentAnswer {
|
| 14 |
+
[questionId: number]: string | string[];
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export interface AssessmentPayload {
|
| 18 |
+
userProfile: UserProfile;
|
| 19 |
+
tests: {
|
| 20 |
+
type: TestType;
|
| 21 |
+
answers: AssessmentAnswer;
|
| 22 |
+
}[];
|
| 23 |
+
completedAt: string;
|
| 24 |
+
assessmentId: number;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
export interface CareerRecommendation {
|
| 28 |
+
title: string;
|
| 29 |
+
confidence: number;
|
| 30 |
+
reason: string;
|
| 31 |
+
next_steps: string[];
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
export interface AssessmentResponse {
|
| 35 |
+
recommendations: CareerRecommendation[];
|
| 36 |
+
summary: string;
|
| 37 |
+
smsMessage?: string;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
export interface ChatMessage {
|
| 41 |
+
role: "user" | "assistant";
|
| 42 |
+
content: string;
|
| 43 |
+
timestamp: Date;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
export interface ChatSession {
|
| 47 |
+
sessionId: string;
|
| 48 |
+
assessmentId?: number;
|
| 49 |
+
assessmentSummary?: string;
|
| 50 |
+
messages: ChatMessage[];
|
| 51 |
+
createdAt: Date;
|
| 52 |
+
lastActivity: Date;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
export interface ChatStartRequest {
|
| 56 |
+
sessionId: string;
|
| 57 |
+
assessmentId?: number;
|
| 58 |
+
assessmentSummary?: string;
|
| 59 |
+
language?: Language;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
export interface ChatMessageRequest {
|
| 63 |
+
sessionId: string;
|
| 64 |
+
message: string;
|
| 65 |
+
language?: Language;
|
| 66 |
+
assessmentId?: number;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
export interface ChatMessageResponse {
|
| 70 |
+
reply: string;
|
| 71 |
+
intent: string;
|
| 72 |
+
}
|
| 73 |
+
|
backend/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compilerOptions": {
|
| 3 |
+
"target": "ES2020",
|
| 4 |
+
"module": "commonjs",
|
| 5 |
+
"lib": ["ES2020"],
|
| 6 |
+
"outDir": "./dist",
|
| 7 |
+
"rootDir": "./src",
|
| 8 |
+
"strict": true,
|
| 9 |
+
"esModuleInterop": true,
|
| 10 |
+
"skipLibCheck": true,
|
| 11 |
+
"forceConsistentCasingInFileNames": true,
|
| 12 |
+
"resolveJsonModule": true,
|
| 13 |
+
"moduleResolution": "node",
|
| 14 |
+
"types": ["node"]
|
| 15 |
+
},
|
| 16 |
+
"include": ["src/**/*"],
|
| 17 |
+
"exclude": ["node_modules", "dist"]
|
| 18 |
+
}
|
| 19 |
+
|
careers_with_riasec_codes.csv
ADDED
|
@@ -0,0 +1,503 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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OCOLATIER,AIE
|
| 20 |
+
CHOREOGRAPHER,AIE
|
| 21 |
+
CINEMATOGRAPHER,AIE
|
| 22 |
+
COFFEE TASTER/BARRISTA/Q GRADER,AIE
|
| 23 |
+
CONSTRUCTION PAINTER AND DECORATOR,AIE
|
| 24 |
+
DANCER,AIE
|
| 25 |
+
DISC JOCKEY,AIE
|
| 26 |
+
DUBBING ARTIST OR VOICE ACTOR,AIE
|
| 27 |
+
FILM DIRECTOR,AIE
|
| 28 |
+
HOMECOOK,AIE
|
| 29 |
+
ILLUSTRATOR,AIE
|
| 30 |
+
MASTER HAND EMBROIDERER (HAND CRAFTED TEXTILES),AIE
|
| 31 |
+
PASTRY CHEF,AIE
|
| 32 |
+
RADIO JOCKEY (RJ),AIE
|
| 33 |
+
SCULPTOR,AIE
|
| 34 |
+
SINGER,AIE
|
| 35 |
+
STRINGING/BEADING ARTIST (FASHION JEWELLERY),AIE
|
| 36 |
+
TATTOO ARTIST,AIE
|
| 37 |
+
TEA TASTER,AIE
|
| 38 |
+
THEATRE ARTIST,AIE
|
| 39 |
+
TRAINEE CHEF/ASSISTANT COOK,AIE
|
| 40 |
+
VISUAL EFFECTS (VFX) EDITOR,AIE
|
| 41 |
+
CERAMICS/GLASS DESIGNER,AIR
|
| 42 |
+
ELECTRONICS DESIGNER/VLSI/EMBEDDED SYSTEM DESIGNER,AIR
|
| 43 |
+
FILM/VIDEO DESIGNER,AIR
|
| 44 |
+
FOOTWEAR DESIGNER,AIR
|
| 45 |
+
GAME DESIGNER AND DEVELOPER,AIR
|
| 46 |
+
GRAPHICS DESIGNER,AIR
|
| 47 |
+
INDUSTRIAL DESIGNER,AIR
|
| 48 |
+
MULTIMEDIA DESIGNER,AIR
|
| 49 |
+
PRODUCT DESIGNER,AIR
|
| 50 |
+
SOUND RECORDIST,AIR
|
| 51 |
+
TEXTILE DESIGNER,AIR
|
| 52 |
+
TOY DESIGNER,AIR
|
| 53 |
+
USER EXPERIENCE DESIGNER,AIR
|
| 54 |
+
VISUAL COMMUNICATION DESIGNER,AIR
|
| 55 |
+
WEB DESIGNER,AIR
|
| 56 |
+
ART HISTORIAN,AIS
|
| 57 |
+
CAMERAPERSON,AIS
|
| 58 |
+
COMMUNITY JOURNALIST,AIS
|
| 59 |
+
CONTENT WRITER,AIS
|
| 60 |
+
COPY EDITOR,AIS
|
| 61 |
+
COPY WRITER,AIS
|
| 62 |
+
CREATIVE WRITER,AIS
|
| 63 |
+
CURATOR,AIS
|
| 64 |
+
EDITOR,AIS
|
| 65 |
+
EDITORIAL ASSISTANT,AIS
|
| 66 |
+
ENGLISH LITERATURE SCHOLAR,AIS
|
| 67 |
+
HISTORIAN,AIS
|
| 68 |
+
INTERPRETER,AIS
|
| 69 |
+
JOURNALIST,AIS
|
| 70 |
+
LEXICOGRAPHER,AIS
|
| 71 |
+
LINGUIST,AIS
|
| 72 |
+
MUSICIAN,AIS
|
| 73 |
+
PHOTOJOURNALIST,AIS
|
| 74 |
+
PROOFREADER,AIS
|
| 75 |
+
SCREENWRITER,AIS
|
| 76 |
+
SCRIPTWRITER,AIS
|
| 77 |
+
TECHNICAL WRITER,AIS
|
| 78 |
+
TRANSLATOR,AIS
|
| 79 |
+
TRANSLATOR,AIS
|
| 80 |
+
APPLIQUE ARTISAN,ARC
|
| 81 |
+
BAMBOO UTILITY PRODUCT TAILOR,ARC
|
| 82 |
+
CROCHET LACEMAKER – FURNISHINGS,ARC
|
| 83 |
+
INSPECTOR OF INCOME TAX,CES
|
| 84 |
+
COMPUTER SCIENTIST,CIR
|
| 85 |
+
AIRLINE CARGO ASSISTANT,CSE
|
| 86 |
+
BANK CLERK,CSE
|
| 87 |
+
CHARTERED ACCOUNTANT,CSE
|
| 88 |
+
COMPANY SECRETARY,CSE
|
| 89 |
+
COMPLIANCE OFFICER,CSE
|
| 90 |
+
CONTRACT ADMINISTRATOR,CSE
|
| 91 |
+
COST AND WORKS ACCOUNTANT,CSE
|
| 92 |
+
FINANCIAL ACCOUNTANT,CSE
|
| 93 |
+
GRAMIN DAK SEVAK,CSE
|
| 94 |
+
INDIAN RAILWAY ACCOUNTS SERVICE,CSE
|
| 95 |
+
INDIAN RAILWAY PERSONNEL SERVICE,CSE
|
| 96 |
+
INDIAN RAILWAY STORES SERVICE (IRSS),CSE
|
| 97 |
+
INDIAN REVENUE SERVICE,CSE
|
| 98 |
+
LIBRARIAN,CSE
|
| 99 |
+
MICROFINANCE EXECUTIVE,CSE
|
| 100 |
+
MULTI-TASKING STAFF,CSE
|
| 101 |
+
OFFICE ADMINISTRATOR,CSE
|
| 102 |
+
SECRETARY/PERSONAL ASSISTANT,CSE
|
| 103 |
+
STOREKEEPER – CONSTRUCTION,CSE
|
| 104 |
+
TAX AUDITOR,CSE
|
| 105 |
+
ANCHOR,EAS
|
| 106 |
+
ART DEALER,EAS
|
| 107 |
+
AUCTIONEER,EAS
|
| 108 |
+
DAIRY FARMER/ENTREPRENEUR,EAS
|
| 109 |
+
SELF-EMPLOYED E-TAILER,EAS
|
| 110 |
+
TOUR OPERATOR,EAS
|
| 111 |
+
TOUR OPERATOR,EAS
|
| 112 |
+
TRAVEL CONSULTANT,EAS
|
| 113 |
+
COLD CHAIN PROCESS MANAGEMENT SPECIALIST,ECR
|
| 114 |
+
ASSISTANT CATERING MANAGER,ECS
|
| 115 |
+
BANK MANAGER/BRANCH MANAGER,ECS
|
| 116 |
+
BANK PROBATIONARY OFFICER,ECS
|
| 117 |
+
BRAND MANAGER,ECS
|
| 118 |
+
BUSINESS DEVELOPMENT COORDINATOR,ECS
|
| 119 |
+
COMMISSIONING EDITOR,ECS
|
| 120 |
+
CUSTOMS OFFICER,ECS
|
| 121 |
+
DIGITAL MARKETING EXPERT,ECS
|
| 122 |
+
DISTRIBUTION MANAGER,ECS
|
| 123 |
+
DISTRIBUTOR SALES REPRESENTATIVE,ECS
|
| 124 |
+
EVENT MANAGER,ECS
|
| 125 |
+
FINANCE MANAGER,ECS
|
| 126 |
+
FOOD AND BEVERAGE MANAGER,ECS
|
| 127 |
+
HEALTHCARE MANAGER,ECS
|
| 128 |
+
HUMAN RESOURCE MANAGER,ECS
|
| 129 |
+
INDIAN ADMINISTRATIVE SERVICE,ECS
|
| 130 |
+
INDIAN RAILWAYS TRAFFIC SERVICE (IRTS),ECS
|
| 131 |
+
INTERNATIONAL BUSINESS MANAGER,ECS
|
| 132 |
+
INVENTORY MANAGER,ECS
|
| 133 |
+
INVESTMENT BANKER,ECS
|
| 134 |
+
INVESTMENT/PORTFOLIO MANAGER,ECS
|
| 135 |
+
LITERARY AGENT,ECS
|
| 136 |
+
LOGISTICS MANAGER,ECS
|
| 137 |
+
MEDIA PLANNER,ECS
|
| 138 |
+
ONLINE ADVERTISING MANAGER,ECS
|
| 139 |
+
OPERATIONS MANAGER,ECS
|
| 140 |
+
PORT OPERATIONS MANAGER,ECS
|
| 141 |
+
PRODUCER,ECS
|
| 142 |
+
PRODUCTION MANAGER,ECS
|
| 143 |
+
PROPERTY MANAGER,ECS
|
| 144 |
+
PUBLIC RELATIONS MANAGER,ECS
|
| 145 |
+
PUBLIC RELATIONS OFFICER,ECS
|
| 146 |
+
PUBLICIST,ECS
|
| 147 |
+
PUBLISHER,ECS
|
| 148 |
+
PURCHASING AND MATERIALS MANAGER,ECS
|
| 149 |
+
QUALITY ASSURANCE MANAGER,ECS
|
| 150 |
+
REAL ESTATE AGENT,ECS
|
| 151 |
+
REAL ESTATE CONSULTANT,ECS
|
| 152 |
+
RELATIONSHIP MANAGER,ECS
|
| 153 |
+
RETAIL MANAGER,ECS
|
| 154 |
+
RISK MANAGER,ECS
|
| 155 |
+
RURAL DEVELOPMENT SPECIALIST/MANAGER,ECS
|
| 156 |
+
SALES AND MARKETING MANAGER,ECS
|
| 157 |
+
SALESMAN/SALES REPRESENTATIVE,ECS
|
| 158 |
+
SEO MANAGER,ECS
|
| 159 |
+
SOCIAL MEDIA EXECUTIVE,ECS
|
| 160 |
+
SOCIAL MEDIA MANAGER,ECS
|
| 161 |
+
SPORTS AGENT/MANAGER,ECS
|
| 162 |
+
SPORTS EQUIPMENT MANAGER,ECS
|
| 163 |
+
STOCK BROKER,ECS
|
| 164 |
+
SUPPLY CHAIN MANAGER,ECS
|
| 165 |
+
TALENT MANAGER,ECS
|
| 166 |
+
TEA PLANTATION MANAGER,ECS
|
| 167 |
+
TRANSPORTATION MANAGER,ECS
|
| 168 |
+
VENTURE CAPITALIST,ECS
|
| 169 |
+
FISHERIES OFFICER,ERI
|
| 170 |
+
FISHERIES DEVELOPMENT OFFICER,ESA
|
| 171 |
+
FISHERIES EXTENSION OFFICER,ESA
|
| 172 |
+
BPO EXECUTIVE,ESC
|
| 173 |
+
CUSTOMER CARE EXECUTIVE,ESC
|
| 174 |
+
FRONT OFFICE ASSOCIATE,ESC
|
| 175 |
+
HEALTH SAFETY AND ENVIRONMENT OFFICER,ESC
|
| 176 |
+
INSURANCE AGENT,ESC
|
| 177 |
+
KNOWLEDGE PROCESS OUTSOURCING EXECUTIVE,ESC
|
| 178 |
+
LIFE INSURANCE AGENT,ESC
|
| 179 |
+
LOAN OFFICER,ESC
|
| 180 |
+
RETAIL CASHIER,ESC
|
| 181 |
+
RETAIL STORE OPERATIONS ASSISTANT,ESC
|
| 182 |
+
SERVICE FULFILMENT EXECUTIVE,ESC
|
| 183 |
+
VISUAL MERCHANDISER,ESC
|
| 184 |
+
ARBITRATOR,ESI
|
| 185 |
+
CORPORATE LEGAL ADVISOR/COMPLIANCE OFFICER,ESI
|
| 186 |
+
DETECTIVE,ESI
|
| 187 |
+
HUMAN RIGHTS LAWYER,ESI
|
| 188 |
+
INDIAN FOREIGN SERVICE,ESI
|
| 189 |
+
INTERNATIONAL RELATIONS SPECIALIST,ESI
|
| 190 |
+
JUDGE,ESI
|
| 191 |
+
LAWYER/LAW OFFICER/ADVOCATE,ESI
|
| 192 |
+
MEDICO LEGAL ADVISOR,ESI
|
| 193 |
+
PATENT LAWYER,ESI
|
| 194 |
+
PUBLIC POLICY ADVISOR,ESI
|
| 195 |
+
SPORTS LAWYER,ESI
|
| 196 |
+
INDIAN POLICE SERVICE,ESR
|
| 197 |
+
SUB-INSPECTOR OF POLICE,ESR
|
| 198 |
+
ARCHIVIST,ICA
|
| 199 |
+
ARCHIVIST,ICA
|
| 200 |
+
BIG DATA ANALYST,ICA
|
| 201 |
+
EQUITY RESEARCH ANALYST,ICA
|
| 202 |
+
HELP DESK ANALYST,ICA
|
| 203 |
+
LOGISTICS ANALYST,ICA
|
| 204 |
+
MUSEOLOGIST,ICA
|
| 205 |
+
SPORTS ANALYST,ICA
|
| 206 |
+
SYSTEMS ANALYST,ICA
|
| 207 |
+
WEB ANALYST,ICA
|
| 208 |
+
ACTUARY,ICE
|
| 209 |
+
ECONOMIST,ICE
|
| 210 |
+
FINANCIAL ANALYST,ICE
|
| 211 |
+
INDUSTRIAL ENGINEER,ICE
|
| 212 |
+
PSEPHOLOGIST,ICE
|
| 213 |
+
BIOTECHNOLOGY ENGINEER,ICR
|
| 214 |
+
DATABASE ADMINISTRATOR,ICR
|
| 215 |
+
NETWORK ADMINISTRATOR,ICR
|
| 216 |
+
DEMOGRAPHER,ICS
|
| 217 |
+
PHARMACIST,ICS
|
| 218 |
+
FSSAI OFFICER,IEC
|
| 219 |
+
INDIAN FOREST SERVICE,IER
|
| 220 |
+
URBAN PLANNER,IER
|
| 221 |
+
AGRONOMIST,IRA
|
| 222 |
+
ANTHROPOLOGIST,IRA
|
| 223 |
+
ARCHAEOLOGIST,IRA
|
| 224 |
+
BOTANIST,IRA
|
| 225 |
+
ECOLOGIST,IRA
|
| 226 |
+
EPIGRAPHIST,IRA
|
| 227 |
+
FLORIST,IRA
|
| 228 |
+
GEOGRAPHER,IRA
|
| 229 |
+
HORTICULTURIST,IRA
|
| 230 |
+
METEOROLOGIST,IRA
|
| 231 |
+
PALEONTOLOGIST,IRA
|
| 232 |
+
PISCICULTURIST,IRA
|
| 233 |
+
SHRIMP FARMER,IRA
|
| 234 |
+
VEGETABLE GROWER,IRA
|
| 235 |
+
VINEYARD GROWER,IRA
|
| 236 |
+
ZOOLOGIST,IRA
|
| 237 |
+
ACADEMIC RESEARCHER,IRC
|
| 238 |
+
AERONAUTICAL ENGINEER,IRC
|
| 239 |
+
AGRICULTURAL ENGINEER,IRC
|
| 240 |
+
ANAESTHESIOLOGIST,IRC
|
| 241 |
+
ARTIFICIAL INTELLIGENCE ENGINEER,IRC
|
| 242 |
+
ASTROPHYSICIST,IRC
|
| 243 |
+
AUGMENTED REALITY ENGINEER,IRC
|
| 244 |
+
BACTERIOLOGIST,IRC
|
| 245 |
+
BACTERIOLOGIST,IRC
|
| 246 |
+
BIOINFORMATICS ENGINEERING,IRC
|
| 247 |
+
BLOCKCHAIN DEVELOPER,IRC
|
| 248 |
+
CARDIOLOGIST,IRC
|
| 249 |
+
CARTOGRAPHER,IRC
|
| 250 |
+
CERAMIC TECHNOLOGIST/ENGINEER,IRC
|
| 251 |
+
CHEMICAL ENGINEER,IRC
|
| 252 |
+
CIVIL ENGINEER/STRUCTURAL ENGINEER,IRC
|
| 253 |
+
CLOUD ENGINEER,IRC
|
| 254 |
+
COMPUTER HARDWARE ENGINEER,IRC
|
| 255 |
+
COMPUTER NETWORK ARCHITECT,IRC
|
| 256 |
+
COMPUTER SCIENCE ENGINEER,IRC
|
| 257 |
+
CORROSION ENGINEER,IRC
|
| 258 |
+
CYBER SECURITY SPECIALIST,IRC
|
| 259 |
+
CYTOLOGIST/CYTOTECHNOLOGIST,IRC
|
| 260 |
+
DATA SCIENTIST,IRC
|
| 261 |
+
DESIGN ENGINEER,IRC
|
| 262 |
+
DEVELOPMENT OPERATIONS ENGINEER,IRC
|
| 263 |
+
DRAUGHTSMAN,IRC
|
| 264 |
+
ELECTRICAL AND ELECTRONICS ENGINEER,IRC
|
| 265 |
+
ELECTRONICS AND COMMUNICATION ENGINEER,IRC
|
| 266 |
+
ENGINEERING PHYSICIST,IRC
|
| 267 |
+
FINANCIAL ENGINEER,IRC
|
| 268 |
+
FIRE AND SAFETY ENGINEER,IRC
|
| 269 |
+
FOOD ENGINEER,IRC
|
| 270 |
+
FORENSIC ENGINEER,IRC
|
| 271 |
+
FORENSIC SCIENTIST,IRC
|
| 272 |
+
FULL STACK DEVELOPER,IRC
|
| 273 |
+
GENETIC ENGINEER,IRC
|
| 274 |
+
GEO-INFORMATICS ENGINEER,IRC
|
| 275 |
+
GEO-INFORMATICS ENGINEER,IRC
|
| 276 |
+
IMMUNOLOGIST,IRC
|
| 277 |
+
INDIAN RAILWAY SERVICE OF ELECTRICAL ENGINEERS,IRC
|
| 278 |
+
INDIAN RAILWAY SERVICE OF ENGINEERS,IRC
|
| 279 |
+
INDIAN RAILWAY SERVICE OF MECHANICAL ENGINEERS,IRC
|
| 280 |
+
INDIAN RAILWAY SERVICE OF SIGNAL ENGINEERS,IRC
|
| 281 |
+
INFORMATION TECHNOLOGY ENGINEER,IRC
|
| 282 |
+
INSTRUMENTATION ENGINEER,IRC
|
| 283 |
+
INTERNET OF THINGS (IOT) SOLUTIONS ARCHITECT,IRC
|
| 284 |
+
MANUFACTURING ENGINEER,IRC
|
| 285 |
+
MATHEMATICIAN,IRC
|
| 286 |
+
METALLURGY ENGINEER,IRC
|
| 287 |
+
NANO SCIENTIST,IRC
|
| 288 |
+
NANOTECHNOLOGY/NANOSCIENCE ENGINEER,IRC
|
| 289 |
+
ONCOLOGIST,IRC
|
| 290 |
+
OPHTHALMOLOGIST,IRC
|
| 291 |
+
OPTICAL ENGINEER,IRC
|
| 292 |
+
OPTOMETRIST,IRC
|
| 293 |
+
ORTHOPAEDIST,IRC
|
| 294 |
+
ORTHOTIST/PROSTHETIST,IRC
|
| 295 |
+
PERIODONTIST,IRC
|
| 296 |
+
PHARMACEUTICAL ENGINEER,IRC
|
| 297 |
+
POLITICAL SCIENTIST,IRC
|
| 298 |
+
PRINTING ENGINEER/TECHNOLOGIST,IRC
|
| 299 |
+
PROCESS ENGINEER,IRC
|
| 300 |
+
PROGRAMMER/CODER/SOFTWARE ENGINEER,IRC
|
| 301 |
+
PULMONOLOGIST,IRC
|
| 302 |
+
QUALITY ASSURANCE ENGINEER,IRC
|
| 303 |
+
RADIOLOGIST,IRC
|
| 304 |
+
RAILWAY ENGINEER,IRC
|
| 305 |
+
ROBOTICS ENGINEER,IRC
|
| 306 |
+
SALES ENGINEER,IRC
|
| 307 |
+
SCIENTIFIC ASSISTANT (IMD),IRC
|
| 308 |
+
SEISMOLOGIST,IRC
|
| 309 |
+
SMART MANUFACTURING AND AUTOMATION ENGINEERING,IRC
|
| 310 |
+
SOIL SCIENTIST,IRC
|
| 311 |
+
SOUND ENGINEER,IRC
|
| 312 |
+
SPACE SCIENTIST,IRC
|
| 313 |
+
STATISTICIAN,IRC
|
| 314 |
+
TEXTILE ENGINEER,IRC
|
| 315 |
+
TOOL ENGINEER,IRC
|
| 316 |
+
TOXICOLOGIST,IRC
|
| 317 |
+
UROLOGIST,IRC
|
| 318 |
+
VIROLOGIST,IRC
|
| 319 |
+
VIRTUAL REALITY ENGINEER,IRC
|
| 320 |
+
WATER RESOURCE ENGINEER,IRC
|
| 321 |
+
AIR TRAFFIC CONTROLLER,IRE
|
| 322 |
+
ENVIRONMENTAL ENGINEER,IRE
|
| 323 |
+
GEOLOGIST,IRE
|
| 324 |
+
MARINE ENGINEER,IRE
|
| 325 |
+
MINING ENGINEER,IRE
|
| 326 |
+
PETROLEUM ENGINEER,IRE
|
| 327 |
+
PHYSICIST,IRE
|
| 328 |
+
BIOMEDICAL ENGINEER,IRS
|
| 329 |
+
CHIROPRACTOR,IRS
|
| 330 |
+
COSMETIC DERMATOLOGIST,IRS
|
| 331 |
+
DENTIST,IRS
|
| 332 |
+
DENTO ORAL HYGIENIST,IRS
|
| 333 |
+
ENDOCRINOLOGIST,IRS
|
| 334 |
+
GYNAECOLOGIST,IRS
|
| 335 |
+
SURGEON,IRS
|
| 336 |
+
VETERINARIAN,IRS
|
| 337 |
+
AYURVEDA DOCTOR,ISA
|
| 338 |
+
CRIMINOLOGIST,ISA
|
| 339 |
+
EAR NOSE THROAT DOCTOR,ISA
|
| 340 |
+
GENERAL PHYSICIAN,ISA
|
| 341 |
+
HOMEOPATHY DOCTOR,ISA
|
| 342 |
+
MEDICAL REPRESENTATIVE,ISA
|
| 343 |
+
MEDICAL TRANSCRIPTIONIST,ISA
|
| 344 |
+
MEDICAL WRITER,ISA
|
| 345 |
+
NATUROPATHIC DOCTOR,ISA
|
| 346 |
+
PAEDIATRICIAN,ISA
|
| 347 |
+
SOCIOLOGIST,ISA
|
| 348 |
+
UNANI DOCTOR,ISA
|
| 349 |
+
CAD JEWELLERY DESIGNER,RAC
|
| 350 |
+
BROADCAST ENGINEER,RCI
|
| 351 |
+
CAMP HELPER,RCI
|
| 352 |
+
AGNIVEER,REC
|
| 353 |
+
AIRCRAFT PILOT,REC
|
| 354 |
+
INDIAN AIR FORCE OFFICER,REC
|
| 355 |
+
INDIAN ARMY OFFICER,REC
|
| 356 |
+
INDIAN NAVY OFFICER,REC
|
| 357 |
+
LIGHT VEHICLE DRIVER (LMV),REC
|
| 358 |
+
LOCO PILOT,REC
|
| 359 |
+
MERCHANT NAVY,REC
|
| 360 |
+
REFEREE (FOOTBALL),REC
|
| 361 |
+
BORDER SECURITY FORCE (BSF),RES
|
| 362 |
+
CISF OFFICER,RES
|
| 363 |
+
COAST GUARD,RES
|
| 364 |
+
CRPF OFFICER,RES
|
| 365 |
+
FIRE FIGHTER,RES
|
| 366 |
+
INDIAN HOME GUARD,RES
|
| 367 |
+
ITBP OFFICER,RES
|
| 368 |
+
LIFEGUARD (POOL GUARD & BEACH LIFEGUARD & LIFE SAVER),RES
|
| 369 |
+
PARAMEDIC,RES
|
| 370 |
+
POLICE CONSTABLE,RES
|
| 371 |
+
RAILWAY PROTECTION FORCE (RPF),RES
|
| 372 |
+
SPORTS SCOUT,RES
|
| 373 |
+
SPORTSPERSON,RES
|
| 374 |
+
SSB-SASHASTRA SEEMA BAL OFFICER,RES
|
| 375 |
+
UMPIRE (CRICKET),RES
|
| 376 |
+
UNARMED SECURITY GUARD,RES
|
| 377 |
+
AIRLINE GROUND SUPPORT EQUIPMENT OPERATOR,RIC
|
| 378 |
+
ASSISTANT CARPENTER—WOODEN FURNITURE,RIC
|
| 379 |
+
ASSISTANT FALSE CEILING AND DRYWALL INSTALLER,RIC
|
| 380 |
+
ASSISTANT FITTER: LEVELLING ALIGNMENT AND BALANCING,RIC
|
| 381 |
+
ASSISTANT SURVEYOR,RIC
|
| 382 |
+
AUTO SERVICE TECHNICIAN LEVEL 3,RIC
|
| 383 |
+
AUTO/E-RICKSHAW DRIVER AND TECHNICIAN,RIC
|
| 384 |
+
AUTOMOTIVE ELECTRICIAN,RIC
|
| 385 |
+
BAMBOO MAT WEAVER,RIC
|
| 386 |
+
CCTV INSTALLATION TECHNICIAN,RIC
|
| 387 |
+
CNC OPERATOR TURNING,RIC
|
| 388 |
+
COMMERCIAL DRIVER,RIC
|
| 389 |
+
CONVEYOR OPERATION AND MAINTENANCE TECHNICIAN,RIC
|
| 390 |
+
CONVEYOR OPERATION AND MAINTENANCE TECHNICIAN,RIC
|
| 391 |
+
DAIRY TECHNOLOGIST,RIC
|
| 392 |
+
DATA COLLECTOR OR FIELD SURVEYOR ENUMERATOR,RIC
|
| 393 |
+
DIALYSIS TECHNICIAN,RIC
|
| 394 |
+
DOORS AND WINDOWS FIXER,RIC
|
| 395 |
+
DTH SET TOP BOX INSTALLATION AND SERVICE TECHNICIAN (CABLE TV OPERATOR),RIC
|
| 396 |
+
E-WASTE COLLECTOR,RIC
|
| 397 |
+
ELECTRIC VEHICLE ASSEMBLY TECHNICIAN,RIC
|
| 398 |
+
ELECTRICIAN (GENERAL),RIC
|
| 399 |
+
EMERGENCY MEDICAL TECHNICIAN (EMT),RIC
|
| 400 |
+
FIELD TECHNICIAN – OTHER HOME APPLIANCES,RIC
|
| 401 |
+
FISH AND SEA FOOD PROCESSOR,RIC
|
| 402 |
+
FISHERY TECHNICIAN/AQUACULTURE TECHNICIAN,RIC
|
| 403 |
+
FITTER & ELECTRICAL AND ELECTRONIC ASSEMBLY,RIC
|
| 404 |
+
FITTER – FABRICATION,RIC
|
| 405 |
+
FITTER – MECHANICAL ASSEMBLY,RIC
|
| 406 |
+
FITTER – PROCESSING,RIC
|
| 407 |
+
HELPER – FABRICATION,RIC
|
| 408 |
+
HELPER – SHUTTERING CARPENTER,RIC
|
| 409 |
+
HOME DELIVERY BOY,RIC
|
| 410 |
+
HYDROPONICS TECHNICIAN,RIC
|
| 411 |
+
INDUSTRIAL PRODUCTION WORKER – FOOD PROCESSING,RIC
|
| 412 |
+
INSTALLER – FRAMELESS GLASS DOORS/WINDOWS,RIC
|
| 413 |
+
LAPIDARIST,RIC
|
| 414 |
+
LEATHER TECHNOLOGIST,RIC
|
| 415 |
+
MASON (GENERAL),RIC
|
| 416 |
+
MASON (STONE),RIC
|
| 417 |
+
MASON (TILING),RIC
|
| 418 |
+
MECHANICAL FITTER,RIC
|
| 419 |
+
MEDICAL TECHNICIAN,RIC
|
| 420 |
+
MULTI-SKILL TECHNICIAN (ELECTRICAL),RIC
|
| 421 |
+
MULTI-SKILL TECHNICIAN (FOOD PROCESSING),RIC
|
| 422 |
+
OIL TECHNOLOGIST,RIC
|
| 423 |
+
OPERATOR-BORING MACHINE,RIC
|
| 424 |
+
PACKAGE DYEING MACHINE OPERATOR,RIC
|
| 425 |
+
PERFUSION TECHNOLOGIST,RIC
|
| 426 |
+
PHLEBOTOMIST/PHLEOBOTOMY TECHNICIAN,RIC
|
| 427 |
+
PLUMBER,RIC
|
| 428 |
+
REFRIGERATION TECHNICIAN,RIC
|
| 429 |
+
RUBBER TECHNOLOGIST,RIC
|
| 430 |
+
SEED TECHNOLOGIST,RIC
|
| 431 |
+
SEWING MACHINE OPERATOR,RIC
|
| 432 |
+
SMARTPHONE REPAIR TECHNICIAN,RIC
|
| 433 |
+
SOFTWARE APPLICATION PACKAGER,RIC
|
| 434 |
+
SOLAR AND LED TECHNICIAN,RIC
|
| 435 |
+
STONECUTTER (CUTTING MACHINE OPERATOR) – STONE CRAFT,RIC
|
| 436 |
+
SUGAR TECHNOLOGIST,RIC
|
| 437 |
+
TECHNICIAN DENTAL,RIC
|
| 438 |
+
TOWER TECHNICIAN,RIC
|
| 439 |
+
WASTE COLLECTOR,RIC
|
| 440 |
+
WOOD POLISHER,RIC
|
| 441 |
+
AUTOMOBILE ENGINEER,RIE
|
| 442 |
+
CAD DESIGNER FOR CARPETS,RIE
|
| 443 |
+
MECHANICAL ENGINEER,RIS
|
| 444 |
+
BULLDOZER OPERATOR,RRC
|
| 445 |
+
ACCENT TRAINER,SAC
|
| 446 |
+
ATHLETE DEVELOPMENT SPECIALIST,SAC
|
| 447 |
+
GENERAL HOUSEKEEPER,SAC
|
| 448 |
+
HOUSEKEEPING ATTENDANT (MANUAL CLEANING),SAC
|
| 449 |
+
KITCHEN STEWARD,SAC
|
| 450 |
+
PHYSICAL FITNESS TRAINER,SAC
|
| 451 |
+
RECEPTIONIST,SAC
|
| 452 |
+
ROOM ATTENDANT,SAC
|
| 453 |
+
SPORTS COACH,SAC
|
| 454 |
+
TRAINER,SAC
|
| 455 |
+
AIR HOSTESS/PURSER,SAE
|
| 456 |
+
AIRLINE CUSTOMER SERVICE EXECUTIVE,SAE
|
| 457 |
+
FOOD AND BEVERAGE SERVICE-STEWARD,SAE
|
| 458 |
+
SHOWROOM HOSTESS/HOST,SAE
|
| 459 |
+
SOCIAL WORKER,SAE
|
| 460 |
+
TOUR GUIDE,SAE
|
| 461 |
+
ASSISTANT PROFESSOR,SAI
|
| 462 |
+
ASSISTANT TEACHER,SAI
|
| 463 |
+
CURRICULUM DEVELOPER,SAI
|
| 464 |
+
FOREIGN LANGUAGE TEACHER,SAI
|
| 465 |
+
LECTURER (COLLEGE AND UNIVERSITY),SAI
|
| 466 |
+
NATURE GUIDE,SAI
|
| 467 |
+
PHYSICAL EDUCATOR,SAI
|
| 468 |
+
PRE-SCHOOL EDUCATOR,SAI
|
| 469 |
+
SCHOOL TEACHER,SAI
|
| 470 |
+
YOGA INSTRUCTOR,SAI
|
| 471 |
+
ANIMAL HEALTH WORKER,SIA
|
| 472 |
+
AQUACULTURE WORKER,SIA
|
| 473 |
+
AUXILIARY NURSE MIDWIFERY (ANM),SIA
|
| 474 |
+
CAREER COUNSELLOR,SIA
|
| 475 |
+
CAREGIVER FOR PERSONS WITH DISABILITIES (NON-CLINICAL),SIA
|
| 476 |
+
CHILD CARETAKER (NON-CLINICAL),SIA
|
| 477 |
+
CHILD DEVELOPMENT SPECIALIST,SIA
|
| 478 |
+
CLINICAL PSYCHOLOGIST,SIA
|
| 479 |
+
DIETICIAN,SIA
|
| 480 |
+
ELDERLY CARETAKER (NON-CLINICAL),SIA
|
| 481 |
+
FARMER: BACKYARD POULTRY/SMALL POULTRY,SIA
|
| 482 |
+
GENERAL DUTY ASSISTANT-ADVANCED OPTIONS: MATERNAL AND NEWBORN CARE/CRITICAL CARE/DIALYSIS/PARTURITION,SIA
|
| 483 |
+
GENERAL NURSE AND MIDWIFE (GNM),SIA
|
| 484 |
+
NURSE,SIA
|
| 485 |
+
NUTRITIONIST,SIA
|
| 486 |
+
PALLIATIVE AND HOSPICE CARE SPECIALIST,SIA
|
| 487 |
+
PSYCHIATRIST,SIA
|
| 488 |
+
PSYCHOLOGICAL COUNSELLOR/COUNSELLING PSYCHOLOGIST,SIA
|
| 489 |
+
PUBLIC HEALTH OFFICER,SIA
|
| 490 |
+
REHABILITATION SPECIALIST,SIA
|
| 491 |
+
SCHOOL COUNSELLOR,SIA
|
| 492 |
+
SPECIAL EDUCATOR,SIA
|
| 493 |
+
SPORTS PSYCHOLOGIST,SIA
|
| 494 |
+
ACUPUNCTURIST,SIR
|
| 495 |
+
AROMATHERAPIST,SIR
|
| 496 |
+
ASSISTANT BEAUTY THERAPIST,SIR
|
| 497 |
+
DANCE THERAPIST,SIR
|
| 498 |
+
MASSAGE THERAPIST,SIR
|
| 499 |
+
OCCUPATIONAL THERAPIST,SIR
|
| 500 |
+
PHYSIOTHERAPIST,SIR
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
"AERONAUTICAL ENGINEER",
|
| 3 |
+
"AUTOMOBILE ENGINEER",
|
| 4 |
+
"BIOINFORMATICS ENGINEERING",
|
| 5 |
+
"BIOMEDICAL ENGINEER",
|
| 6 |
+
"BIOTECHNOLOGY ENGINEER",
|
| 7 |
+
"BROADCAST ENGINEER",
|
| 8 |
+
"CAD DESIGNER FOR CARPETS",
|
| 9 |
+
"CAD JEWELLERY DESIGNER",
|
| 10 |
+
"CERAMIC TECHNOLOGIST/ENGINEER",
|
| 11 |
+
"CHEMICAL ENGINEER",
|
| 12 |
+
"CIVIL ENGINEER/STRUCTURAL ENGINEER",
|
| 13 |
+
"CORROSION ENGINEER",
|
| 14 |
+
"DESIGN ENGINEER",
|
| 15 |
+
"DEVELOPMENT OPERATIONS ENGINEER",
|
| 16 |
+
"ELECTRICAL AND ELECTRONICS ENGINEER",
|
| 17 |
+
"ELECTRONICS DESIGNER/VLSI/EMBEDDED SYSTEM DESIGNER",
|
| 18 |
+
"ELECTRONICS AND COMMUNICATION ENGINEER",
|
| 19 |
+
"ENVIRONMENTAL ENGINEER",
|
| 20 |
+
"FIRE AND SAFETY ENGINEER",
|
| 21 |
+
"FOOD ENGINEER",
|
| 22 |
+
"FOOTWEAR DESIGNER",
|
| 23 |
+
"FORENSIC ENGINEER",
|
| 24 |
+
"GEO-INFORMATICS ENGINEER",
|
| 25 |
+
"GRAPHICS DESIGNER",
|
| 26 |
+
"INDUSTRIAL DESIGNER",
|
| 27 |
+
"INDUSTRIAL ENGINEER",
|
| 28 |
+
"INSTRUMENTATION ENGINEER",
|
| 29 |
+
"MANUFACTURING ENGINEER",
|
| 30 |
+
"MARINE ENGINEER",
|
| 31 |
+
"MECHANICAL ENGINEER",
|
| 32 |
+
"METALLURGY ENGINEER",
|
| 33 |
+
"MINING ENGINEER",
|
| 34 |
+
"NANOTECHNOLOGY/NANOSCIENCE ENGINEER",
|
| 35 |
+
"OPTICAL ENGINEER",
|
| 36 |
+
"PETROLEUM ENGINEER",
|
| 37 |
+
"PHARMACEUTICAL ENGINEER",
|
| 38 |
+
"PRINTING ENGINEER/TECHNOLOGIST",
|
| 39 |
+
"PROCESS ENGINEER",
|
| 40 |
+
"PRODUCT DESIGNER",
|
| 41 |
+
"QUALITY ASSURANCE ENGINEER",
|
| 42 |
+
"RAILWAY ENGINEER",
|
| 43 |
+
"ROBOTICS ENGINEER",
|
| 44 |
+
"SALES ENGINEER",
|
| 45 |
+
"SMART MANUFACTURING AND AUTOMATION ENGINEERING",
|
| 46 |
+
"SOUND ENGINEER",
|
| 47 |
+
"TEXTILE ENGINEER",
|
| 48 |
+
"TOOL ENGINEER",
|
| 49 |
+
"WATER RESOURCE ENGINEER",
|
| 50 |
+
"AGNIVEER",
|
| 51 |
+
"BORDER SECURITY FORCE (BSF)",
|
| 52 |
+
"CISF OFFICER",
|
| 53 |
+
"COAST GUARD",
|
| 54 |
+
"CRPF OFFICER",
|
| 55 |
+
"CUSTOMS OFFICER",
|
| 56 |
+
"FSSAI OFFICER",
|
| 57 |
+
"GRAMIN DAK SEVAK",
|
| 58 |
+
"INDIAN ADMINISTRATIVE SERVICE",
|
| 59 |
+
"INDIAN AIR FORCE OFFICER",
|
| 60 |
+
"INDIAN ARMY OFFICER",
|
| 61 |
+
"INDIAN FOREIGN SERVICE",
|
| 62 |
+
"INDIAN FOREST SERVICE",
|
| 63 |
+
"INDIAN HOME GUARD",
|
| 64 |
+
"INDIAN NAVY OFFICER",
|
| 65 |
+
"INDIAN POLICE SERVICE",
|
| 66 |
+
"INDIAN RAILWAY ACCOUNTS SERVICE",
|
| 67 |
+
"INDIAN RAILWAY SERVICE OF ELECTRICAL ENGINEERS",
|
| 68 |
+
"INDIAN RAILWAY PERSONNEL SERVICE",
|
| 69 |
+
"INDIAN RAILWAY SERVICE OF ENGINEERS",
|
| 70 |
+
"INDIAN RAILWAY SERVICE OF MECHANICAL ENGINEERS",
|
| 71 |
+
"INDIAN RAILWAY SERVICE OF SIGNAL ENGINEERS",
|
| 72 |
+
"INDIAN RAILWAY STORES SERVICE (IRSS)",
|
| 73 |
+
"INDIAN RAILWAYS TRAFFIC SERVICE (IRTS)",
|
| 74 |
+
"INDIAN REVENUE SERVICE",
|
| 75 |
+
"ITBP OFFICER",
|
| 76 |
+
"INSPECTOR OF INCOME TAX",
|
| 77 |
+
"LOCO PILOT",
|
| 78 |
+
"MERCHANT NAVY",
|
| 79 |
+
"POLICE CONSTABLE",
|
| 80 |
+
"RAILWAY PROTECTION FORCE (RPF)",
|
| 81 |
+
"SSB-SASHASTRA SEEMA BAL OFFICER",
|
| 82 |
+
"SUB-INSPECTOR OF POLICE",
|
| 83 |
+
"ARTIFICIAL INTELLIGENCE ENGINEER",
|
| 84 |
+
"AUGMENTED REALITY ENGINEER",
|
| 85 |
+
"BIG DATA ANALYST",
|
| 86 |
+
"BLOCKCHAIN DEVELOPER",
|
| 87 |
+
"CLOUD ENGINEER",
|
| 88 |
+
"COMPUTER HARDWARE ENGINEER",
|
| 89 |
+
"COMPUTER NETWORK ARCHITECT",
|
| 90 |
+
"COMPUTER SCIENCE ENGINEER",
|
| 91 |
+
"COMPUTER SCIENTIST",
|
| 92 |
+
"CYBER SECURITY SPECIALIST",
|
| 93 |
+
"DATA SCIENTIST",
|
| 94 |
+
"DATABASE ADMINISTRATOR",
|
| 95 |
+
"FULL STACK DEVELOPER",
|
| 96 |
+
"GAME DESIGNER AND DEVELOPER",
|
| 97 |
+
"GEO-INFORMATICS ENGINEER",
|
| 98 |
+
"HELP DESK ANALYST",
|
| 99 |
+
"INFORMATION TECHNOLOGY ENGINEER",
|
| 100 |
+
"INTERNET OF THINGS (IOT) SOLUTIONS ARCHITECT",
|
| 101 |
+
"NETWORK ADMINISTRATOR",
|
| 102 |
+
"PROGRAMMER/CODER/SOFTWARE ENGINEER",
|
| 103 |
+
"SEO MANAGER",
|
| 104 |
+
"SOFTWARE APPLICATION PACKAGER",
|
| 105 |
+
"SYSTEMS ANALYST",
|
| 106 |
+
"USER EXPERIENCE DESIGNER",
|
| 107 |
+
"VIRTUAL REALITY ENGINEER",
|
| 108 |
+
"WEB ANALYST",
|
| 109 |
+
"WEB DESIGNER",
|
| 110 |
+
"ASSISTANT CATERING MANAGER",
|
| 111 |
+
"BPO EXECUTIVE",
|
| 112 |
+
"EVENT MANAGER",
|
| 113 |
+
"HUMAN RESOURCE MANAGER",
|
| 114 |
+
"INVENTORY MANAGER",
|
| 115 |
+
"KNOWLEDGE PROCESS OUTSOURCING EXECUTIVE",
|
| 116 |
+
"PURCHASING AND MATERIALS MANAGER",
|
| 117 |
+
"QUALITY ASSURANCE MANAGER",
|
| 118 |
+
"RETAIL MANAGER",
|
| 119 |
+
"RURAL DEVELOPMENT SPECIALIST/MANAGER",
|
| 120 |
+
"SALES AND MARKETING MANAGER",
|
| 121 |
+
"SPORTS AGENT/MANAGER",
|
| 122 |
+
"SPORTS EQUIPMENT MANAGER",
|
| 123 |
+
"AIRCRAFT PILOT",
|
| 124 |
+
"AIR HOSTESS/PURSER",
|
| 125 |
+
"AIRLINE CARGO ASSISTANT",
|
| 126 |
+
"AIRLINE CUSTOMER SERVICE EXECUTIVE",
|
| 127 |
+
"AIRLINE GROUND SUPPORT EQUIPMENT OPERATOR",
|
| 128 |
+
"AIR TRAFFIC CONTROLLER",
|
| 129 |
+
"AUCTIONEER",
|
| 130 |
+
"BARTENDER/MIXOLOGIST",
|
| 131 |
+
"BULLDOZER OPERATOR",
|
| 132 |
+
"COLD CHAIN PROCESS MANAGEMENT SPECIALIST",
|
| 133 |
+
"COMMERCIAL DRIVER",
|
| 134 |
+
"CONVEYOR OPERATION AND MAINTENANCE TECHNICIAN",
|
| 135 |
+
"DISTRIBUTION MANAGER",
|
| 136 |
+
"FOOD AND BEVERAGE MANAGER",
|
| 137 |
+
"FRONT OFFICE ASSOCIATE",
|
| 138 |
+
"LOGISTICS ANALYST",
|
| 139 |
+
"LOGISTICS MANAGER",
|
| 140 |
+
"MULTI-TASKING STAFF",
|
| 141 |
+
"NATURE GUIDE",
|
| 142 |
+
"OFFICE ADMINISTRATOR",
|
| 143 |
+
"OPERATIONS MANAGER",
|
| 144 |
+
"PACKAGE DYEING MACHINE OPERATOR",
|
| 145 |
+
"PORT OPERATIONS MANAGER",
|
| 146 |
+
"SECRETARY/PERSONAL ASSISTANT",
|
| 147 |
+
"SOMMELIER",
|
| 148 |
+
"SUPPLY CHAIN MANAGER",
|
| 149 |
+
"TOUR GUIDE",
|
| 150 |
+
"TOUR OPERATOR",
|
| 151 |
+
"TRANSPORTATION MANAGER",
|
| 152 |
+
"TRAVEL CONSULTANT",
|
| 153 |
+
"URBAN PLANNER",
|
| 154 |
+
"ARBITRATOR",
|
| 155 |
+
"CORPORATE LEGAL ADVISOR/COMPLIANCE OFFICER",
|
| 156 |
+
"DETECTIVE",
|
| 157 |
+
"FIRE FIGHTER",
|
| 158 |
+
"HUMAN RIGHTS LAWYER",
|
| 159 |
+
"INTERNATIONAL RELATIONS SPECIALIST",
|
| 160 |
+
"JUDGE",
|
| 161 |
+
"LAWYER/LAW OFFICER/ADVOCATE",
|
| 162 |
+
"MEDICO LEGAL ADVISOR",
|
| 163 |
+
"PATENT LAWYER",
|
| 164 |
+
"PSEPHOLOGIST",
|
| 165 |
+
"PUBLIC POLICY ADVISOR",
|
| 166 |
+
"SOCIAL WORKER",
|
| 167 |
+
"SPORTS LAWYER",
|
| 168 |
+
"UNARMED SECURITY GUARD",
|
| 169 |
+
"ANTHROPOLOGIST",
|
| 170 |
+
"ARCHAEOLOGIST",
|
| 171 |
+
"ARCHIVIST",
|
| 172 |
+
"ASTROPHYSICIST",
|
| 173 |
+
"BACTERIOLOGIST",
|
| 174 |
+
"BOTANIST",
|
| 175 |
+
"CHILD DEVELOPMENT SPECIALIST",
|
| 176 |
+
"CRIMINOLOGIST",
|
| 177 |
+
"CURATOR",
|
| 178 |
+
"CYTOLOGIST/CYTOTECHNOLOGIST",
|
| 179 |
+
"DATA COLLECTOR OR FIELD SURVEYOR ENUMERATOR",
|
| 180 |
+
"DEMOGRAPHER",
|
| 181 |
+
"ECOLOGIST",
|
| 182 |
+
"ECONOMIST",
|
| 183 |
+
"ENGINEERING PHYSICIST",
|
| 184 |
+
"ENGLISH LITERATURE SCHOLAR",
|
| 185 |
+
"EPIGRAPHIST",
|
| 186 |
+
"FORENSIC SCIENTIST",
|
| 187 |
+
"GENETIC ENGINEER",
|
| 188 |
+
"GEOGRAPHER",
|
| 189 |
+
"GEOLOGIST",
|
| 190 |
+
"HISTORIAN",
|
| 191 |
+
"MATHEMATICIAN",
|
| 192 |
+
"METEOROLOGIST",
|
| 193 |
+
"MUSEOLOGIST",
|
| 194 |
+
"NANO SCIENTIST",
|
| 195 |
+
"PALEONTOLOGIST",
|
| 196 |
+
"PHYSICIST",
|
| 197 |
+
"POLITICAL SCIENTIST",
|
| 198 |
+
"SCIENTIFIC ASSISTANT (IMD)",
|
| 199 |
+
"SEISMOLOGIST",
|
| 200 |
+
"SOCIOLOGIST",
|
| 201 |
+
"SPACE SCIENTIST",
|
| 202 |
+
"STATISTICIAN",
|
| 203 |
+
"TOXICOLOGIST",
|
| 204 |
+
"VIROLOGIST",
|
| 205 |
+
"ZOOLOGIST",
|
| 206 |
+
"APPLIQUE ARTISAN",
|
| 207 |
+
"ASSISTANT BEAUTY THERAPIST",
|
| 208 |
+
"ASSISTANT CARPENTER—WOODEN FURNITURE",
|
| 209 |
+
"ASSISTANT FALSE CEILING AND DRYWALL INSTALLER",
|
| 210 |
+
"ASSISTANT FITTER: LEVELLING, ALIGNMENT AND BALANCING",
|
| 211 |
+
"ASSISTANT HAIR STYLIST",
|
| 212 |
+
"ASSISTANT SURVEYOR",
|
| 213 |
+
"AUTO/E-RICKSHAW DRIVER AND TECHNICIAN",
|
| 214 |
+
"AUTOMOTIVE ELECTRICIAN",
|
| 215 |
+
"AUTO SERVICE TECHNICIAN LEVEL 3",
|
| 216 |
+
"BAMBOO MAT WEAVER",
|
| 217 |
+
"BAMBOO UTILITY PRODUCT TAILOR",
|
| 218 |
+
"OPERATOR-BORING MACHINE",
|
| 219 |
+
"CAKE ARTIST",
|
| 220 |
+
"CAMP HELPER",
|
| 221 |
+
"CCTV INSTALLATION TECHNICIAN",
|
| 222 |
+
"CHEF",
|
| 223 |
+
"CHILD CARETAKER (NON-CLINICAL)",
|
| 224 |
+
"CHOCOLATIER",
|
| 225 |
+
"CNC OPERATOR TURNING",
|
| 226 |
+
"COFFEE TASTER/BARRISTA/Q GRADER",
|
| 227 |
+
"CONVEYOR OPERATION AND MAINTENANCE TECHNICIAN",
|
| 228 |
+
"CROCHET LACEMAKER – FURNISHINGS",
|
| 229 |
+
"DOORS AND WINDOWS FIXER",
|
| 230 |
+
"DRAUGHTSMAN",
|
| 231 |
+
"DTH SET TOP BOX INSTALLATION AND SERVICE TECHNICIAN (CABLE TV OPERATOR)",
|
| 232 |
+
"ELECTRIC VEHICLE ASSEMBLY TECHNICIAN",
|
| 233 |
+
"ELECTRICIAN (GENERAL)",
|
| 234 |
+
"E-WASTE COLLECTOR",
|
| 235 |
+
"FIELD TECHNICIAN – OTHER HOME APPLIANCES",
|
| 236 |
+
"FITTER – ELECTRICAL AND ELECTRONIC ASSEMBLY",
|
| 237 |
+
"FITTER – FABRICATION",
|
| 238 |
+
"FITTER – MECHANICAL ASSEMBLY",
|
| 239 |
+
"FITTER – PROCESSING",
|
| 240 |
+
"FOOD AND BEVERAGE SERVICE-STEWARD",
|
| 241 |
+
"GENERAL HOUSEKEEPER",
|
| 242 |
+
"HELPER – SHUTTERING CARPENTER",
|
| 243 |
+
"HELPER – FABRICATION",
|
| 244 |
+
"HOMECOOK",
|
| 245 |
+
"HOME DELIVERY BOY",
|
| 246 |
+
"HOUSEKEEPING ATTENDANT (MANUAL CLEANING)",
|
| 247 |
+
"INDUSTRIAL PRODUCTION WORKER – FOOD PROCESSING",
|
| 248 |
+
"INSTALLER – FRAMELESS GLASS DOORS/WINDOWS",
|
| 249 |
+
"JUTE HANDLOOM WEAVER",
|
| 250 |
+
"KITCHEN STEWARD",
|
| 251 |
+
"LAPIDARIST",
|
| 252 |
+
"LEATHER TECHNOLOGIST",
|
| 253 |
+
"LIGHT VEHICLE DRIVER (LMV)",
|
| 254 |
+
"MASON (GENERAL)",
|
| 255 |
+
"MASON (STONE)",
|
| 256 |
+
"MASON (TILING)",
|
| 257 |
+
"MASTER HAND EMBROIDERER (HAND CRAFTED TEXTILES)",
|
| 258 |
+
"MECHANICAL FITTER",
|
| 259 |
+
"MULTI-SKILL TECHNICIAN (ELECTRICAL)",
|
| 260 |
+
"MULTI-SKILL TECHNICIAN (FOOD PROCESSING)",
|
| 261 |
+
"OIL TECHNOLOGIST",
|
| 262 |
+
"CONSTRUCTION PAINTER AND DECORATOR",
|
| 263 |
+
"PASTRY CHEF",
|
| 264 |
+
"PLUMBER",
|
| 265 |
+
"REFRIGERATION TECHNICIAN",
|
| 266 |
+
"RETAIL CASHIER",
|
| 267 |
+
"RETAIL STORE OPERATIONS ASSISTANT",
|
| 268 |
+
"ROOM ATTENDANT",
|
| 269 |
+
"RUBBER TECHNOLOGIST",
|
| 270 |
+
"SELF-EMPLOYED E-TAILER",
|
| 271 |
+
"SEWING MACHINE OPERATOR",
|
| 272 |
+
"SHOWROOM HOSTESS/HOST",
|
| 273 |
+
"SMARTPHONE REPAIR TECHNICIAN",
|
| 274 |
+
"SOLAR AND LED TECHNICIAN",
|
| 275 |
+
"SPA THERAPIST",
|
| 276 |
+
"STONECUTTER (CUTTING MACHINE OPERATOR) – STONE CRAFT",
|
| 277 |
+
"STOREKEEPER – CONSTRUCTION",
|
| 278 |
+
"STRINGING/BEADING ARTIST (FASHION JEWELLERY)",
|
| 279 |
+
"SUGAR TECHNOLOGIST",
|
| 280 |
+
"TEA TASTER",
|
| 281 |
+
"TOUR OPERATOR",
|
| 282 |
+
"TOWER TECHNICIAN",
|
| 283 |
+
"TRAINEE CHEF/ASSISTANT COOK",
|
| 284 |
+
"WASTE COLLECTOR",
|
| 285 |
+
"WOOD POLISHER",
|
| 286 |
+
"AGRICULTURAL ENGINEER",
|
| 287 |
+
"AGRONOMIST",
|
| 288 |
+
"ANIMAL HEALTH WORKER",
|
| 289 |
+
"AQUACULTURE WORKER",
|
| 290 |
+
"DAIRY FARMER/ENTREPRENEUR",
|
| 291 |
+
"DAIRY TECHNOLOGIST",
|
| 292 |
+
"FARMER: BACKYARD POULTRY/SMALL POULTRY",
|
| 293 |
+
"FISH AND SEA FOOD PROCESSOR",
|
| 294 |
+
"FISHERIES DEVELOPMENT OFFICER",
|
| 295 |
+
"FISHERIES EXTENSION OFFICER",
|
| 296 |
+
"FISHERIES OFFICER",
|
| 297 |
+
"FISHERY TECHNICIAN/AQUACULTURE TECHNICIAN",
|
| 298 |
+
"FLORIST",
|
| 299 |
+
"HORTICULTURIST",
|
| 300 |
+
"HYDROPONICS TECHNICIAN",
|
| 301 |
+
"PISCICULTURIST",
|
| 302 |
+
"SEED TECHNOLOGIST",
|
| 303 |
+
"SHRIMP FARMER",
|
| 304 |
+
"SOIL SCIENTIST",
|
| 305 |
+
"TEA PLANTATION MANAGER",
|
| 306 |
+
"VEGETABLE GROWER",
|
| 307 |
+
"VETERINARIAN",
|
| 308 |
+
"VINEYARD GROWER",
|
| 309 |
+
"ACTOR",
|
| 310 |
+
"ANCHOR",
|
| 311 |
+
"ANIMATOR",
|
| 312 |
+
"ARCHIVIST",
|
| 313 |
+
"ART DEALER",
|
| 314 |
+
"ART DIRECTOR",
|
| 315 |
+
"ART HISTORIAN",
|
| 316 |
+
"ARTIST",
|
| 317 |
+
"BLOGGER",
|
| 318 |
+
"BRAND MANAGER",
|
| 319 |
+
"CALLIGRAPHER",
|
| 320 |
+
"CAMERAPERSON",
|
| 321 |
+
"CARTOGRAPHER",
|
| 322 |
+
"CARTOONIST",
|
| 323 |
+
"CERAMICS/GLASS DESIGNER",
|
| 324 |
+
"CHOREOGRAPHER",
|
| 325 |
+
"CINEMATOGRAPHER",
|
| 326 |
+
"COMMISSIONING EDITOR",
|
| 327 |
+
"COMMUNITY JOURNALIST",
|
| 328 |
+
"CONTENT WRITER",
|
| 329 |
+
"COPY EDITOR",
|
| 330 |
+
"COPY WRITER",
|
| 331 |
+
"CREATIVE WRITER",
|
| 332 |
+
"DANCER",
|
| 333 |
+
"DIGITAL MARKETING EXPERT",
|
| 334 |
+
"DISC JOCKEY",
|
| 335 |
+
"DUBBING ARTIST OR VOICE ACTOR",
|
| 336 |
+
"EDITOR",
|
| 337 |
+
"EDITORIAL ASSISTANT",
|
| 338 |
+
"FASHION DESIGNER",
|
| 339 |
+
"FILM DIRECTOR",
|
| 340 |
+
"FILM/VIDEO DESIGNER",
|
| 341 |
+
"ILLUSTRATOR",
|
| 342 |
+
"JOURNALIST",
|
| 343 |
+
"LITERARY AGENT",
|
| 344 |
+
"MARKETING MANAGER",
|
| 345 |
+
"MEDIA PLANNER",
|
| 346 |
+
"MODEL",
|
| 347 |
+
"MULTIMEDIA DESIGNER",
|
| 348 |
+
"MUSICIAN",
|
| 349 |
+
"ONLINE ADVERTISING MANAGER",
|
| 350 |
+
"PHOTOGRAPHER",
|
| 351 |
+
"PHOTOJOURNALIST",
|
| 352 |
+
"PRODUCER",
|
| 353 |
+
"PRODUCTION MANAGER",
|
| 354 |
+
"PROOFREADER",
|
| 355 |
+
"PUBLIC RELATIONS MANAGER",
|
| 356 |
+
"PUBLIC RELATIONS OFFICER",
|
| 357 |
+
"PUBLICIST",
|
| 358 |
+
"PUBLISHER",
|
| 359 |
+
"RADIO JOCKEY (RJ)",
|
| 360 |
+
"RECEPTIONIST",
|
| 361 |
+
"SALESMAN/SALES REPRESENTATIVE",
|
| 362 |
+
"SCREENWRITER",
|
| 363 |
+
"SCRIPTWRITER",
|
| 364 |
+
"SCULPTOR",
|
| 365 |
+
"SINGER",
|
| 366 |
+
"SOCIAL MEDIA EXECUTIVE",
|
| 367 |
+
"SOCIAL MEDIA MANAGER",
|
| 368 |
+
"SOUND RECORDIST",
|
| 369 |
+
"TALENT MANAGER",
|
| 370 |
+
"TATTOO ARTIST",
|
| 371 |
+
"TECHNICAL WRITER",
|
| 372 |
+
"TEXTILE DESIGNER",
|
| 373 |
+
"THEATRE ARTIST",
|
| 374 |
+
"TOY DESIGNER",
|
| 375 |
+
"TRANSLATOR",
|
| 376 |
+
"VISUAL COMMUNICATION DESIGNER",
|
| 377 |
+
"VISUAL EFFECTS (VFX) EDITOR",
|
| 378 |
+
"VISUAL MERCHANDISER",
|
| 379 |
+
"ACTUARY",
|
| 380 |
+
"BANK CLERK",
|
| 381 |
+
"BANK MANAGER/BRANCH MANAGER",
|
| 382 |
+
"BANK PROBATIONARY OFFICER",
|
| 383 |
+
"BUSINESS DEVELOPMENT COORDINATOR",
|
| 384 |
+
"CHARTERED ACCOUNTANT",
|
| 385 |
+
"COMPANY SECRETARY",
|
| 386 |
+
"COMPLIANCE OFFICER",
|
| 387 |
+
"CONTRACT ADMINISTRATOR",
|
| 388 |
+
"COST AND WORKS ACCOUNTANT",
|
| 389 |
+
"CUSTOMER CARE EXECUTIVE",
|
| 390 |
+
"DISTRIBUTOR SALES REPRESENTATIVE",
|
| 391 |
+
"EQUITY RESEARCH ANALYST",
|
| 392 |
+
"FINANCE MANAGER",
|
| 393 |
+
"FINANCIAL ACCOUNTANT",
|
| 394 |
+
"FINANCIAL ANALYST",
|
| 395 |
+
"FINANCIAL ENGINEER",
|
| 396 |
+
"INSURANCE AGENT",
|
| 397 |
+
"INTERNATIONAL BUSINESS MANAGER",
|
| 398 |
+
"INVESTMENT BANKER",
|
| 399 |
+
"INVESTMENT/PORTFOLIO MANAGER",
|
| 400 |
+
"LIFE INSURANCE AGENT",
|
| 401 |
+
"LOAN OFFICER",
|
| 402 |
+
"MICROFINANCE EXECUTIVE",
|
| 403 |
+
"PROPERTY MANAGER",
|
| 404 |
+
"REAL ESTATE AGENT",
|
| 405 |
+
"REAL ESTATE CONSULTANT",
|
| 406 |
+
"RELATIONSHIP MANAGER",
|
| 407 |
+
"RISK MANAGER",
|
| 408 |
+
"SERVICE FULFILMENT EXECUTIVE",
|
| 409 |
+
"STOCK BROKER",
|
| 410 |
+
"TAX AUDITOR",
|
| 411 |
+
"VENTURE CAPITALIST",
|
| 412 |
+
"ACADEMIC RESEARCHER",
|
| 413 |
+
"ACCENT TRAINER",
|
| 414 |
+
"ASSISTANT PROFESSOR",
|
| 415 |
+
"ASSISTANT TEACHER",
|
| 416 |
+
"CAREER COUNSELLOR",
|
| 417 |
+
"CURRICULUM DEVELOPER",
|
| 418 |
+
"FOREIGN LANGUAGE TEACHER",
|
| 419 |
+
"INTERPRETER",
|
| 420 |
+
"LECTURER (COLLEGE AND UNIVERSITY)",
|
| 421 |
+
"LEXICOGRAPHER",
|
| 422 |
+
"LIBRARIAN",
|
| 423 |
+
"LINGUIST",
|
| 424 |
+
"PHYSICAL EDUCATOR",
|
| 425 |
+
"PHYSICAL FITNESS TRAINER",
|
| 426 |
+
"PRE-SCHOOL EDUCATOR",
|
| 427 |
+
"REFEREE (FOOTBALL)",
|
| 428 |
+
"SCHOOL COUNSELLOR",
|
| 429 |
+
"SCHOOL TEACHER",
|
| 430 |
+
"SPECIAL EDUCATOR",
|
| 431 |
+
"TRAINER",
|
| 432 |
+
"TRANSLATOR",
|
| 433 |
+
"ACUPUNCTURIST",
|
| 434 |
+
"ANAESTHESIOLOGIST",
|
| 435 |
+
"AROMATHERAPIST",
|
| 436 |
+
"ATHLETE DEVELOPMENT SPECIALIST",
|
| 437 |
+
"AUXILIARY NURSE MIDWIFERY (ANM)",
|
| 438 |
+
"AYURVEDA DOCTOR",
|
| 439 |
+
"BACTERIOLOGIST",
|
| 440 |
+
"CARDIOLOGIST",
|
| 441 |
+
"CAREGIVER – PERSONS WITH DISABILITIES (NON-CLINICAL)",
|
| 442 |
+
"CHIROPRACTOR",
|
| 443 |
+
"CLINICAL PSYCHOLOGIST",
|
| 444 |
+
"COSMETIC DERMATOLOGIST",
|
| 445 |
+
"DANCE THERAPIST",
|
| 446 |
+
"DENTIST",
|
| 447 |
+
"DENTO ORAL HYGIENIST",
|
| 448 |
+
"DIALYSIS TECHNICIAN",
|
| 449 |
+
"DIETICIAN",
|
| 450 |
+
"EAR NOSE THROAT DOCTOR",
|
| 451 |
+
"ELDERLY CARETAKER (NON-CLINICAL)",
|
| 452 |
+
"EMERGENCY MEDICAL TECHNICIAN (EMT)",
|
| 453 |
+
"ENDOCRINOLOGIST",
|
| 454 |
+
"GENERAL DUTY ASSISTANT-ADVANCED OPTIONS: MATERNAL AND NEWBORN CARE/CRITICAL CARE/DIALYSIS/PARTURITION",
|
| 455 |
+
"GENERAL NURSE AND MIDWIFE (GNM)",
|
| 456 |
+
"GENERAL PHYSICIAN",
|
| 457 |
+
"GYNAECOLOGIST",
|
| 458 |
+
"HEALTHCARE MANAGER",
|
| 459 |
+
"HEALTH, SAFETY AND ENVIRONMENT OFFICER",
|
| 460 |
+
"HOMEOPATHY DOCTOR",
|
| 461 |
+
"IMMUNOLOGIST",
|
| 462 |
+
"LIFEGUARD (POOL GUARD, BEACH LIFEGUARD, LIFE SAVER)",
|
| 463 |
+
"MASSAGE THERAPIST",
|
| 464 |
+
"MEDICAL REPRESENTATIVE",
|
| 465 |
+
"MEDICAL TECHNICIAN",
|
| 466 |
+
"MEDICAL TRANSCRIPTIONIST",
|
| 467 |
+
"MEDICAL WRITER",
|
| 468 |
+
"NATUROPATHIC DOCTOR",
|
| 469 |
+
"NURSE",
|
| 470 |
+
"NUTRITIONIST",
|
| 471 |
+
"OCCUPATIONAL THERAPIST",
|
| 472 |
+
"ONCOLOGIST",
|
| 473 |
+
"OPHTHALMOLOGIST",
|
| 474 |
+
"OPTOMETRIST",
|
| 475 |
+
"ORTHOPAEDIST",
|
| 476 |
+
"ORTHOTIST/PROSTHETIST",
|
| 477 |
+
"PAEDIATRICIAN",
|
| 478 |
+
"PALLIATIVE AND HOSPICE CARE SPECIALIST",
|
| 479 |
+
"PARAMEDIC",
|
| 480 |
+
"PERFUSION TECHNOLOGIST",
|
| 481 |
+
"PERIODONTIST",
|
| 482 |
+
"PHARMACIST",
|
| 483 |
+
"PHLEBOTOMIST/PHLEOBOTOMY TECHNICIAN",
|
| 484 |
+
"PHYSIOTHERAPIST",
|
| 485 |
+
"PSYCHIATRIST",
|
| 486 |
+
"PSYCHOLOGICAL COUNSELLOR/COUNSELLING PSYCHOLOGIST",
|
| 487 |
+
"PUBLIC HEALTH OFFICER",
|
| 488 |
+
"PULMONOLOGIST",
|
| 489 |
+
"RADIOLOGIST",
|
| 490 |
+
"REHABILITATION SPECIALIST",
|
| 491 |
+
"SPEECH AND LANGUAGE THERAPIST (SLP)/AUDIOLOGIST",
|
| 492 |
+
"SPORTS ANALYST",
|
| 493 |
+
"SPORTS COACH",
|
| 494 |
+
"SPORTS MEDICINE SPECIALIST",
|
| 495 |
+
"SPORTS PSYCHOLOGIST",
|
| 496 |
+
"SPORTS SCOUT",
|
| 497 |
+
"SPORTSPERSON",
|
| 498 |
+
"SURGEON",
|
| 499 |
+
"TECHNICIAN – DENTAL",
|
| 500 |
+
"UMPIRE (CRICKET)",
|
| 501 |
+
"UNANI DOCTOR",
|
| 502 |
+
"UROLOGIST",
|
| 503 |
+
"YOGA INSTRUCTOR"
|
| 504 |
+
]
|
data_processing/clean_text.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
def clean_pdf_text(text):
|
| 4 |
+
# --- Remove page markers like: --- Page 51 ---
|
| 5 |
+
text = re.sub(r'-{2,}\s*Page\s*\d+\s*-{2,}', ' ', text, flags=re.IGNORECASE)
|
| 6 |
+
|
| 7 |
+
# --- Remove timestamps (with or without seconds) ---
|
| 8 |
+
text = re.sub(r'\d{1,2}-[A-Za-z]{3}-\d{2}\s+\d{1,2}:\d{2}(:\d{2})?\s*[APMapm]{2}', ' ', text)
|
| 9 |
+
|
| 10 |
+
# --- Remove PDF header/footer garbage like: ---
|
| 11 |
+
# Career Guidance Book Vol-2_Engineering_1-96.indd 27
|
| 12 |
+
# ...Vol-3 - Research and Development_335-408.indd_ 342
|
| 13 |
+
text = re.sub(r'Career Guidance Book.*?indd[_\s-]*\d{1,4}', ' ', text, flags=re.IGNORECASE)
|
| 14 |
+
|
| 15 |
+
# --- Remove standalone page numbers (e.g., "66 |") ---
|
| 16 |
+
text = re.sub(r'\b\d{1,4}\s*\|', ' ', text)
|
| 17 |
+
|
| 18 |
+
# --- Remove lines containing only numbers (page numbers) ---
|
| 19 |
+
text = re.sub(r'^\s*\d{1,4}\s*$', ' ', text, flags=re.MULTILINE)
|
| 20 |
+
|
| 21 |
+
# --- Remove leftover bullets, pipes, dots ---
|
| 22 |
+
text = re.sub(r'[|·•◦▪]+', ' ', text)
|
| 23 |
+
|
| 24 |
+
# --- Remove stray unicode quotes and artifacts ---
|
| 25 |
+
text = text.replace('“', '"').replace('”', '"')
|
| 26 |
+
text = text.replace('’', "'").replace('‘', "'")
|
| 27 |
+
text = text.replace('—', ' ') # em-dash
|
| 28 |
+
text = text.replace('–', ' ') # en-dash
|
| 29 |
+
text = text.replace('', '') # soft hyphen
|
| 30 |
+
|
| 31 |
+
# --- Remove unreadable unicode (OCR junk) ---
|
| 32 |
+
text = text.encode("ascii", errors="ignore").decode()
|
| 33 |
+
|
| 34 |
+
# --- Collapse weird spacing ---
|
| 35 |
+
text = re.sub(r'\s+', ' ', text)
|
| 36 |
+
|
| 37 |
+
return text.strip()
|
| 38 |
+
|
| 39 |
+
# Read the extracted text file
|
| 40 |
+
with open("raw_text.txt", "r", encoding="utf-8") as f:
|
| 41 |
+
raw_text = f.read()
|
| 42 |
+
|
| 43 |
+
# Clean the text
|
| 44 |
+
cleaned_text = clean_pdf_text(raw_text)
|
| 45 |
+
|
| 46 |
+
# Write the cleaned text to a new file
|
| 47 |
+
with open("cleaned_text.txt", "w", encoding="utf-8") as f:
|
| 48 |
+
f.write(cleaned_text)
|
data_processing/read_pdf.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pdf2image import convert_from_path
|
| 2 |
+
import pytesseract
|
| 3 |
+
import os
|
| 4 |
+
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
|
| 5 |
+
poppler_path = r"C:\Program Files\poppler-25.07.0\Library\bin"
|
| 6 |
+
|
| 7 |
+
# Add Poppler to PATH at runtime
|
| 8 |
+
os.environ["PATH"] += os.pathsep + poppler_path
|
| 9 |
+
|
| 10 |
+
def ocr_pdf(pdf_path, start_page=25, end_page=608):
|
| 11 |
+
text = ""
|
| 12 |
+
# Convert only the required page range to images
|
| 13 |
+
images = convert_from_path(pdf_path, first_page=start_page, last_page=end_page)
|
| 14 |
+
for i, image in enumerate(images, start=start_page):
|
| 15 |
+
page_text = pytesseract.image_to_string(image, lang='eng')
|
| 16 |
+
text += f"\n--- Page {i} ---\n" + page_text
|
| 17 |
+
print(f"Processed page {i}")
|
| 18 |
+
return text
|
| 19 |
+
|
| 20 |
+
pdf_path = "Vol2.pdf"
|
| 21 |
+
text = ocr_pdf(pdf_path)
|
| 22 |
+
|
| 23 |
+
text_file_path = "extracted_text.txt"
|
| 24 |
+
with open(text_file_path, "w", encoding="utf-8") as text_file:
|
| 25 |
+
text_file.write(text)
|
data_processing/split_to_json.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
def split_careers_to_json(careers, text_file_path, output_path="careers.json"):
|
| 5 |
+
# Sort headings by length to avoid substring conflicts
|
| 6 |
+
careers_sorted = sorted(careers, key=len, reverse=True)
|
| 7 |
+
|
| 8 |
+
pattern = r"(" + "|".join(re.escape(c) for c in careers_sorted) + r")"
|
| 9 |
+
|
| 10 |
+
with open(text_file_path, "r", encoding="utf-8") as f:
|
| 11 |
+
text = f.read()
|
| 12 |
+
|
| 13 |
+
parts = re.split(pattern, text)
|
| 14 |
+
|
| 15 |
+
result = []
|
| 16 |
+
current_title = None
|
| 17 |
+
buffer = []
|
| 18 |
+
|
| 19 |
+
id_counter = 1
|
| 20 |
+
|
| 21 |
+
for part in parts:
|
| 22 |
+
stripped = part.strip()
|
| 23 |
+
if stripped in careers:
|
| 24 |
+
if current_title:
|
| 25 |
+
content = " ".join(buffer)
|
| 26 |
+
result.append({
|
| 27 |
+
"id": id_counter,
|
| 28 |
+
"title": current_title,
|
| 29 |
+
"content": content
|
| 30 |
+
})
|
| 31 |
+
id_counter += 1
|
| 32 |
+
|
| 33 |
+
current_title = stripped
|
| 34 |
+
buffer = []
|
| 35 |
+
else:
|
| 36 |
+
if current_title:
|
| 37 |
+
buffer.append(part)
|
| 38 |
+
|
| 39 |
+
# Last career block
|
| 40 |
+
if current_title:
|
| 41 |
+
content = " ".join(buffer)
|
| 42 |
+
result.append({
|
| 43 |
+
"id": id_counter,
|
| 44 |
+
"title": current_title,
|
| 45 |
+
"content": content
|
| 46 |
+
})
|
| 47 |
+
|
| 48 |
+
# Write JSON
|
| 49 |
+
with open(output_path, "w", encoding="utf-8") as f:
|
| 50 |
+
json.dump(result, f, indent=2, ensure_ascii=False)
|
| 51 |
+
|
| 52 |
+
return result
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
with open("career_names.json", "r", encoding="utf-8") as f:
|
| 56 |
+
career_names = json.load(f)
|
| 57 |
+
|
| 58 |
+
split_careers_to_json(career_names, "cleaned_text.txt", output_path="careers_cleaned.json")
|
| 59 |
+
|
frontend/index.html
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
<!DOCTYPE html>
|
| 3 |
+
<html lang="en">
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<title>Career Guidance Web App</title>
|
| 8 |
+
</head>
|
| 9 |
+
|
| 10 |
+
<body>
|
| 11 |
+
<div id="root"></div>
|
| 12 |
+
<script type="module" src="/src/main.tsx"></script>
|
| 13 |
+
</body>
|
| 14 |
+
</html>
|
| 15 |
+
|
frontend/package-lock.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontend/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "career-guidance-web-app",
|
| 3 |
+
"version": "0.1.0",
|
| 4 |
+
"private": true,
|
| 5 |
+
"dependencies": {
|
| 6 |
+
"@radix-ui/react-accordion": "^1.2.3",
|
| 7 |
+
"@radix-ui/react-alert-dialog": "^1.1.6",
|
| 8 |
+
"@radix-ui/react-aspect-ratio": "^1.1.2",
|
| 9 |
+
"@radix-ui/react-avatar": "^1.1.3",
|
| 10 |
+
"@radix-ui/react-checkbox": "^1.1.4",
|
| 11 |
+
"@radix-ui/react-collapsible": "^1.1.3",
|
| 12 |
+
"@radix-ui/react-context-menu": "^2.2.6",
|
| 13 |
+
"@radix-ui/react-dialog": "^1.1.6",
|
| 14 |
+
"@radix-ui/react-dropdown-menu": "^2.1.6",
|
| 15 |
+
"@radix-ui/react-hover-card": "^1.1.6",
|
| 16 |
+
"@radix-ui/react-label": "^2.1.2",
|
| 17 |
+
"@radix-ui/react-menubar": "^1.1.6",
|
| 18 |
+
"@radix-ui/react-navigation-menu": "^1.2.5",
|
| 19 |
+
"@radix-ui/react-popover": "^1.1.6",
|
| 20 |
+
"@radix-ui/react-progress": "^1.1.2",
|
| 21 |
+
"@radix-ui/react-radio-group": "^1.2.3",
|
| 22 |
+
"@radix-ui/react-scroll-area": "^1.2.3",
|
| 23 |
+
"@radix-ui/react-select": "^2.1.6",
|
| 24 |
+
"@radix-ui/react-separator": "^1.1.2",
|
| 25 |
+
"@radix-ui/react-slider": "^1.2.3",
|
| 26 |
+
"@radix-ui/react-slot": "^1.1.2",
|
| 27 |
+
"@radix-ui/react-switch": "^1.1.3",
|
| 28 |
+
"@radix-ui/react-tabs": "^1.1.3",
|
| 29 |
+
"@radix-ui/react-toggle": "^1.1.2",
|
| 30 |
+
"@radix-ui/react-toggle-group": "^1.1.2",
|
| 31 |
+
"@radix-ui/react-tooltip": "^1.1.8",
|
| 32 |
+
"axios": "^1.13.2",
|
| 33 |
+
"class-variance-authority": "^0.7.1",
|
| 34 |
+
"clsx": "^2.1.1",
|
| 35 |
+
"cmdk": "^1.1.1",
|
| 36 |
+
"embla-carousel-react": "^8.6.0",
|
| 37 |
+
"input-otp": "^1.4.2",
|
| 38 |
+
"lucide-react": "^0.487.0",
|
| 39 |
+
"react": "^18.3.1",
|
| 40 |
+
"react-day-picker": "^8.10.1",
|
| 41 |
+
"react-dom": "^18.3.1",
|
| 42 |
+
"react-hook-form": "^7.55.0",
|
| 43 |
+
"react-resizable-panels": "^2.1.7",
|
| 44 |
+
"recharts": "^2.15.2",
|
| 45 |
+
"sonner": "^2.0.3",
|
| 46 |
+
"tailwind-merge": "^2.5.0",
|
| 47 |
+
"vaul": "^1.1.2"
|
| 48 |
+
},
|
| 49 |
+
"devDependencies": {
|
| 50 |
+
"@types/node": "^20.10.0",
|
| 51 |
+
"@types/react": "^18.3.0",
|
| 52 |
+
"@types/react-dom": "^18.3.0",
|
| 53 |
+
"@vitejs/plugin-react-swc": "^3.10.2",
|
| 54 |
+
"typescript": "^5.6.0",
|
| 55 |
+
"vite": "^6.4.1"
|
| 56 |
+
},
|
| 57 |
+
"scripts": {
|
| 58 |
+
"dev": "vite",
|
| 59 |
+
"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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState, useEffect } from "react";
|
| 2 |
+
import { Toaster } from "./components/ui/sonner";
|
| 3 |
+
import { SetupPage } from "./components/SetupPage";
|
| 4 |
+
import { LoginPage } from "./components/LoginPage";
|
| 5 |
+
import { HomePage } from "./components/HomePage";
|
| 6 |
+
import { ChatbotPage } from "./components/ChatbotPage";
|
| 7 |
+
import { TestFormPage } from "./components/TestFormPage";
|
| 8 |
+
import { ProcessingPage } from "./components/ProcessingPage";
|
| 9 |
+
import { AssessmentHistoryPage } from "./components/AssessmentHistoryPage";
|
| 10 |
+
import { AssessmentResponsesPage } from "./components/AssessmentResponsesPage";
|
| 11 |
+
import { SettingsPage } from "./components/SettingsPage";
|
| 12 |
+
import { authService } from "./services/authService";
|
| 13 |
+
import { assessmentService } from "./services/assessmentService";
|
| 14 |
+
|
| 15 |
+
export type Page =
|
| 16 |
+
| "login"
|
| 17 |
+
| "setup"
|
| 18 |
+
| "home"
|
| 19 |
+
| "chatbot"
|
| 20 |
+
| "test-selection"
|
| 21 |
+
| "test-form"
|
| 22 |
+
| "processing"
|
| 23 |
+
| "results"
|
| 24 |
+
| "assessment-history"
|
| 25 |
+
| "assessment-responses"
|
| 26 |
+
| "settings";
|
| 27 |
+
export type TestType = "riasec" | "values" | "personal";
|
| 28 |
+
export type Language = "en" | "hi" | "te" | "ta" | "bn" | "gu";
|
| 29 |
+
|
| 30 |
+
export interface CompletedAssessment {
|
| 31 |
+
id: number;
|
| 32 |
+
completedAt: Date;
|
| 33 |
+
tests: TestType[];
|
| 34 |
+
has_chat?: boolean; // Optional flag to indicate if assessment has chat messages
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
export interface SavedAssessment {
|
| 38 |
+
testType: TestType;
|
| 39 |
+
progress: number; // Progress for current test
|
| 40 |
+
overallProgress?: number; // Overall assessment progress across all tests
|
| 41 |
+
answers: { [key: number]: string | string[] };
|
| 42 |
+
currentQuestionIndex: number;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
export interface AssessmentResults {
|
| 46 |
+
recommendations: {
|
| 47 |
+
title: string;
|
| 48 |
+
confidence: number;
|
| 49 |
+
reason: string;
|
| 50 |
+
next_steps: string[];
|
| 51 |
+
}[];
|
| 52 |
+
summary: string;
|
| 53 |
+
smsMessage?: string;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
export interface UserProfile {
|
| 57 |
+
name: string;
|
| 58 |
+
class: string;
|
| 59 |
+
age?: string;
|
| 60 |
+
language: Language;
|
| 61 |
+
email?: string;
|
| 62 |
+
phone?: string;
|
| 63 |
+
password?: string;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
function App() {
|
| 67 |
+
const [setupComplete, setSetupComplete] = useState(false);
|
| 68 |
+
const [currentPage, setCurrentPage] = useState<Page>("login");
|
| 69 |
+
const [isGuestMode, setIsGuestMode] = useState(false);
|
| 70 |
+
const [testFlow, setTestFlow] = useState<TestType[]>([
|
| 71 |
+
"riasec",
|
| 72 |
+
"values",
|
| 73 |
+
"personal",
|
| 74 |
+
]);
|
| 75 |
+
const [currentTestIndex, setCurrentTestIndex] = useState(0);
|
| 76 |
+
const [completedAssessments, setCompletedAssessments] = useState<
|
| 77 |
+
CompletedAssessment[]
|
| 78 |
+
>([]);
|
| 79 |
+
const [showResults, setShowResults] = useState(false);
|
| 80 |
+
const [savedAssessment, setSavedAssessment] =
|
| 81 |
+
useState<SavedAssessment | null>(null);
|
| 82 |
+
const [selectedAssessmentId, setSelectedAssessmentId] = useState<
|
| 83 |
+
number | null
|
| 84 |
+
>(null);
|
| 85 |
+
const [allTestAnswers, setAllTestAnswers] = useState<{
|
| 86 |
+
[testType: string]: { [key: number]: string | string[] };
|
| 87 |
+
}>({});
|
| 88 |
+
const [assessmentResults, setAssessmentResults] =
|
| 89 |
+
useState<AssessmentResults | null>(null);
|
| 90 |
+
const [userProfile, setUserProfile] = useState<UserProfile>({
|
| 91 |
+
name: "<Student name>",
|
| 92 |
+
class: "10th",
|
| 93 |
+
language: "en",
|
| 94 |
+
});
|
| 95 |
+
const [loading, setLoading] = useState(true);
|
| 96 |
+
|
| 97 |
+
// Function to load saved assessment from backend
|
| 98 |
+
const loadSavedAssessment = async (homeData?: any) => {
|
| 99 |
+
try {
|
| 100 |
+
let dataToUse = homeData;
|
| 101 |
+
|
| 102 |
+
// If homeData not provided, fetch it
|
| 103 |
+
if (!dataToUse) {
|
| 104 |
+
const response = await assessmentService.getHome();
|
| 105 |
+
dataToUse = response.data;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
if (dataToUse?.saved_assessment) {
|
| 109 |
+
const savedAssessmentData = dataToUse.saved_assessment;
|
| 110 |
+
const testResponses = savedAssessmentData.test_responses || [];
|
| 111 |
+
|
| 112 |
+
if (testResponses.length > 0) {
|
| 113 |
+
const testOrder: TestType[] = ['riasec', 'values', 'personal'];
|
| 114 |
+
const totalQuestions = {
|
| 115 |
+
riasec: 48,
|
| 116 |
+
values: 20,
|
| 117 |
+
personal: 15,
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
// Find the current active test (the one that's not completed or has the most progress)
|
| 121 |
+
let activeTest: TestType | null = null;
|
| 122 |
+
let activeTestProgress = 0;
|
| 123 |
+
let activeTestAnswers: { [key: number]: string | string[] } = {};
|
| 124 |
+
|
| 125 |
+
// Calculate overall progress and find active test
|
| 126 |
+
let totalProgress = 0;
|
| 127 |
+
let testCount = 0;
|
| 128 |
+
|
| 129 |
+
for (const testTypeItem of testOrder) {
|
| 130 |
+
const testResponse = testResponses.find((tr: any) => tr.test_type === testTypeItem);
|
| 131 |
+
|
| 132 |
+
if (testResponse) {
|
| 133 |
+
if (testResponse.is_completed) {
|
| 134 |
+
totalProgress += 100;
|
| 135 |
+
testCount++;
|
| 136 |
+
} else {
|
| 137 |
+
// Get progress for incomplete test
|
| 138 |
+
const questionCount = totalQuestions[testTypeItem] || 0;
|
| 139 |
+
let testProgress = 0;
|
| 140 |
+
|
| 141 |
+
if (questionCount > 0 && testResponse.current_question_index > 0) {
|
| 142 |
+
testProgress = Math.min(100, (testResponse.current_question_index / questionCount) * 100);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
totalProgress += testProgress;
|
| 146 |
+
testCount++;
|
| 147 |
+
|
| 148 |
+
// Set as active test if it has more progress than current active
|
| 149 |
+
if (testProgress > activeTestProgress || activeTest === null) {
|
| 150 |
+
activeTest = testTypeItem as TestType;
|
| 151 |
+
activeTestProgress = testProgress;
|
| 152 |
+
// Try to load answers for this test
|
| 153 |
+
try {
|
| 154 |
+
const testDataResponse = await assessmentService.getTestData(testTypeItem, savedAssessmentData.id);
|
| 155 |
+
const testData = testDataResponse.data;
|
| 156 |
+
if (testData.saved_answers) {
|
| 157 |
+
activeTestAnswers = testData.saved_answers;
|
| 158 |
+
}
|
| 159 |
+
} catch (error) {
|
| 160 |
+
console.error('Error loading test answers:', error);
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
} else {
|
| 165 |
+
testCount++; // Test not started = 0% progress
|
| 166 |
+
// If no active test yet, set first unstarted test as active
|
| 167 |
+
if (activeTest === null) {
|
| 168 |
+
activeTest = testTypeItem as TestType;
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
// Calculate overall progress as average
|
| 174 |
+
const overallProgress = testCount > 0 ? totalProgress / testCount : 0;
|
| 175 |
+
|
| 176 |
+
if (activeTest) {
|
| 177 |
+
const savedAssessment: SavedAssessment = {
|
| 178 |
+
testType: activeTest,
|
| 179 |
+
progress: activeTestProgress,
|
| 180 |
+
overallProgress: Math.min(100, Math.max(0, overallProgress)),
|
| 181 |
+
answers: activeTestAnswers,
|
| 182 |
+
currentQuestionIndex: testResponses.find((tr: any) => tr.test_type === activeTest)?.current_question_index || 0,
|
| 183 |
+
};
|
| 184 |
+
|
| 185 |
+
setSavedAssessment(savedAssessment);
|
| 186 |
+
setSelectedAssessmentId(savedAssessmentData.id);
|
| 187 |
+
|
| 188 |
+
// Also save to localStorage as backup
|
| 189 |
+
try {
|
| 190 |
+
localStorage.setItem('pathfinder_saved_assessment', JSON.stringify(savedAssessment));
|
| 191 |
+
localStorage.setItem('pathfinder_current_assessment_id', savedAssessmentData.id.toString());
|
| 192 |
+
} catch (error) {
|
| 193 |
+
console.error('Error saving to localStorage:', error);
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
} else {
|
| 198 |
+
// No saved assessment, clear state
|
| 199 |
+
setSavedAssessment(null);
|
| 200 |
+
setSelectedAssessmentId(null);
|
| 201 |
+
localStorage.removeItem('pathfinder_saved_assessment');
|
| 202 |
+
localStorage.removeItem('pathfinder_current_assessment_id');
|
| 203 |
+
}
|
| 204 |
+
} catch (error) {
|
| 205 |
+
console.error('Error loading saved assessment:', error);
|
| 206 |
+
// Try to restore from localStorage as fallback
|
| 207 |
+
try {
|
| 208 |
+
const savedData = localStorage.getItem('pathfinder_saved_assessment');
|
| 209 |
+
if (savedData) {
|
| 210 |
+
const parsed = JSON.parse(savedData);
|
| 211 |
+
setSavedAssessment(parsed);
|
| 212 |
+
}
|
| 213 |
+
} catch (localError) {
|
| 214 |
+
console.error('Error loading from localStorage:', localError);
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
};
|
| 218 |
+
|
| 219 |
+
// Function to load assessments - can be called from multiple places
|
| 220 |
+
const loadAssessments = async () => {
|
| 221 |
+
try {
|
| 222 |
+
const historyResponse = await assessmentService.getHistory();
|
| 223 |
+
const historyData = historyResponse.data;
|
| 224 |
+
if (historyData.completed_assessments) {
|
| 225 |
+
const assessments = historyData.completed_assessments
|
| 226 |
+
.map((a: any) => ({
|
| 227 |
+
id: a.id,
|
| 228 |
+
completedAt: new Date(a.completed_at),
|
| 229 |
+
tests: testFlow,
|
| 230 |
+
has_chat: a.has_chat || false,
|
| 231 |
+
}));
|
| 232 |
+
// Sort: assessments with chat first, then by completed_at desc
|
| 233 |
+
const sorted = assessments.sort((a: any, b: any) => {
|
| 234 |
+
if (a.has_chat && !b.has_chat) return -1;
|
| 235 |
+
if (!a.has_chat && b.has_chat) return 1;
|
| 236 |
+
return b.completedAt.getTime() - a.completedAt.getTime();
|
| 237 |
+
});
|
| 238 |
+
setCompletedAssessments(sorted);
|
| 239 |
+
}
|
| 240 |
+
} catch (historyError) {
|
| 241 |
+
console.error('Error loading assessment history:', historyError);
|
| 242 |
+
// Fallback to home data if history fails
|
| 243 |
+
try {
|
| 244 |
+
const homeResponse = await assessmentService.getHome();
|
| 245 |
+
const homeData = homeResponse.data;
|
| 246 |
+
if (homeData.completed_assessments) {
|
| 247 |
+
const assessments = homeData.completed_assessments
|
| 248 |
+
.map((a: any) => ({
|
| 249 |
+
id: a.id,
|
| 250 |
+
completedAt: new Date(a.completed_at),
|
| 251 |
+
tests: testFlow,
|
| 252 |
+
has_chat: a.has_chat || false,
|
| 253 |
+
}));
|
| 254 |
+
const sorted = assessments.sort((a: any, b: any) => {
|
| 255 |
+
if (a.has_chat && !b.has_chat) return -1;
|
| 256 |
+
if (!a.has_chat && b.has_chat) return 1;
|
| 257 |
+
return b.completedAt.getTime() - a.completedAt.getTime();
|
| 258 |
+
});
|
| 259 |
+
setCompletedAssessments(sorted);
|
| 260 |
+
}
|
| 261 |
+
} catch (homeError) {
|
| 262 |
+
console.error('Error loading assessments from home:', homeError);
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
};
|
| 266 |
+
|
| 267 |
+
// Check if user is authenticated on mount
|
| 268 |
+
useEffect(() => {
|
| 269 |
+
const checkAuth = async () => {
|
| 270 |
+
try {
|
| 271 |
+
// Check for guest mode
|
| 272 |
+
const guestMode = localStorage.getItem('pathfinder_guest_mode') === 'true';
|
| 273 |
+
if (guestMode) {
|
| 274 |
+
setIsGuestMode(true);
|
| 275 |
+
setSetupComplete(true);
|
| 276 |
+
setCurrentPage("home");
|
| 277 |
+
setLoading(false);
|
| 278 |
+
return;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
if (authService.isAuthenticated()) {
|
| 282 |
+
// Try to fetch home data to verify token
|
| 283 |
+
const response = await assessmentService.getHome();
|
| 284 |
+
const homeData = response.data;
|
| 285 |
+
|
| 286 |
+
setUserProfile({
|
| 287 |
+
name: homeData.user_profile.name || "<Student name>",
|
| 288 |
+
class: homeData.user_profile.grade || "10th",
|
| 289 |
+
age: homeData.user_profile.age?.toString(),
|
| 290 |
+
language: "en", // Default, can be updated from user profile
|
| 291 |
+
email: homeData.user_profile.email,
|
| 292 |
+
phone: homeData.user_profile.phone,
|
| 293 |
+
});
|
| 294 |
+
|
| 295 |
+
// Load saved assessment from backend
|
| 296 |
+
await loadSavedAssessment(homeData);
|
| 297 |
+
|
| 298 |
+
// Load ALL completed assessments
|
| 299 |
+
await loadAssessments();
|
| 300 |
+
|
| 301 |
+
setSetupComplete(true);
|
| 302 |
+
setCurrentPage("home");
|
| 303 |
+
} else {
|
| 304 |
+
setSetupComplete(false);
|
| 305 |
+
setCurrentPage("login");
|
| 306 |
+
}
|
| 307 |
+
} catch (error) {
|
| 308 |
+
console.error("Auth check failed:", error);
|
| 309 |
+
// Token invalid, clear and show login
|
| 310 |
+
authService.logout();
|
| 311 |
+
setSetupComplete(false);
|
| 312 |
+
setCurrentPage("login");
|
| 313 |
+
} finally {
|
| 314 |
+
setLoading(false);
|
| 315 |
+
}
|
| 316 |
+
};
|
| 317 |
+
|
| 318 |
+
checkAuth();
|
| 319 |
+
}, []);
|
| 320 |
+
|
| 321 |
+
const currentTest = testFlow[currentTestIndex];
|
| 322 |
+
|
| 323 |
+
const navigateTo = async (
|
| 324 |
+
page: Page,
|
| 325 |
+
displayResults?: boolean,
|
| 326 |
+
assessmentId?: number
|
| 327 |
+
) => {
|
| 328 |
+
if (displayResults !== undefined) {
|
| 329 |
+
setShowResults(displayResults);
|
| 330 |
+
} else {
|
| 331 |
+
setShowResults(false);
|
| 332 |
+
}
|
| 333 |
+
if (assessmentId !== undefined) {
|
| 334 |
+
setSelectedAssessmentId(assessmentId);
|
| 335 |
+
}
|
| 336 |
+
setCurrentPage(page);
|
| 337 |
+
|
| 338 |
+
// Reload saved assessment when navigating to home page
|
| 339 |
+
if (page === "home" && !isGuestMode && authService.isAuthenticated()) {
|
| 340 |
+
try {
|
| 341 |
+
await loadSavedAssessment();
|
| 342 |
+
} catch (error) {
|
| 343 |
+
console.error('Error reloading saved assessment:', error);
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
};
|
| 347 |
+
|
| 348 |
+
const startAssessmentFlow = async () => {
|
| 349 |
+
try {
|
| 350 |
+
// Clear previous assessment data before starting new one
|
| 351 |
+
setAllTestAnswers({});
|
| 352 |
+
setAssessmentResults(null);
|
| 353 |
+
setShowResults(false);
|
| 354 |
+
setSavedAssessment(null);
|
| 355 |
+
|
| 356 |
+
// If in guest mode, use a temporary assessment ID
|
| 357 |
+
if (isGuestMode) {
|
| 358 |
+
setSelectedAssessmentId(Date.now());
|
| 359 |
+
setCurrentTestIndex(0);
|
| 360 |
+
navigateTo("test-form");
|
| 361 |
+
return;
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
const response = await assessmentService.startAssessment();
|
| 365 |
+
const data = response.data;
|
| 366 |
+
setSelectedAssessmentId(data.assessment_id);
|
| 367 |
+
setCurrentTestIndex(0);
|
| 368 |
+
navigateTo("test-form");
|
| 369 |
+
} catch (error) {
|
| 370 |
+
console.error("Error starting assessment:", error);
|
| 371 |
+
// If error and in guest mode, still allow to proceed
|
| 372 |
+
if (isGuestMode) {
|
| 373 |
+
setSelectedAssessmentId(Date.now());
|
| 374 |
+
setCurrentTestIndex(0);
|
| 375 |
+
navigateTo("test-form");
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
};
|
| 379 |
+
|
| 380 |
+
const handleLogout = async () => {
|
| 381 |
+
await authService.logout();
|
| 382 |
+
localStorage.removeItem('pathfinder_guest_mode');
|
| 383 |
+
setIsGuestMode(false);
|
| 384 |
+
setSetupComplete(false);
|
| 385 |
+
setCurrentPage("login");
|
| 386 |
+
setCurrentTestIndex(0);
|
| 387 |
+
setSavedAssessment(null);
|
| 388 |
+
setShowResults(false);
|
| 389 |
+
setSelectedAssessmentId(null);
|
| 390 |
+
setCompletedAssessments([]);
|
| 391 |
+
};
|
| 392 |
+
|
| 393 |
+
const handleGuestMode = () => {
|
| 394 |
+
setIsGuestMode(true);
|
| 395 |
+
localStorage.setItem('pathfinder_guest_mode', 'true');
|
| 396 |
+
setSetupComplete(true);
|
| 397 |
+
setUserProfile({
|
| 398 |
+
name: "Guest User",
|
| 399 |
+
class: "10th",
|
| 400 |
+
language: userProfile.language,
|
| 401 |
+
});
|
| 402 |
+
navigateTo("home");
|
| 403 |
+
};
|
| 404 |
+
|
| 405 |
+
const completeTest = (testType: TestType) => {
|
| 406 |
+
// Move to next test or processing
|
| 407 |
+
if (currentTestIndex < testFlow.length - 1) {
|
| 408 |
+
setCurrentTestIndex(currentTestIndex + 1);
|
| 409 |
+
} else {
|
| 410 |
+
// All tests completed, create completed assessment
|
| 411 |
+
const newAssessment: CompletedAssessment = {
|
| 412 |
+
id: selectedAssessmentId || Date.now(),
|
| 413 |
+
completedAt: new Date(),
|
| 414 |
+
tests: testFlow,
|
| 415 |
+
};
|
| 416 |
+
setCompletedAssessments([...completedAssessments, newAssessment]);
|
| 417 |
+
setSelectedAssessmentId(newAssessment.id);
|
| 418 |
+
navigateTo("processing");
|
| 419 |
+
}
|
| 420 |
+
};
|
| 421 |
+
|
| 422 |
+
if (loading) {
|
| 423 |
+
return (
|
| 424 |
+
<div className="min-h-screen bg-gradient-to-br from-blue-50 via-white to-purple-50 flex items-center justify-center">
|
| 425 |
+
<div className="text-center">
|
| 426 |
+
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"></div>
|
| 427 |
+
<p className="mt-4 text-gray-600">Loading...</p>
|
| 428 |
+
</div>
|
| 429 |
+
</div>
|
| 430 |
+
);
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
return (
|
| 434 |
+
<>
|
| 435 |
+
<Toaster position="top-center" richColors />
|
| 436 |
+
<div className="min-h-screen bg-gradient-to-br from-blue-50 via-white to-purple-50">
|
| 437 |
+
{currentPage === "login" && (
|
| 438 |
+
<LoginPage
|
| 439 |
+
userProfile={userProfile}
|
| 440 |
+
setUserProfile={setUserProfile}
|
| 441 |
+
navigateTo={navigateTo}
|
| 442 |
+
onLoginComplete={async () => {
|
| 443 |
+
setIsGuestMode(false);
|
| 444 |
+
localStorage.removeItem('pathfinder_guest_mode');
|
| 445 |
+
setSetupComplete(true);
|
| 446 |
+
// Load assessments after login
|
| 447 |
+
await loadAssessments();
|
| 448 |
+
}}
|
| 449 |
+
onShowSignup={() => setCurrentPage("setup")}
|
| 450 |
+
onGuestMode={handleGuestMode}
|
| 451 |
+
/>
|
| 452 |
+
)}
|
| 453 |
+
{currentPage === "setup" && (
|
| 454 |
+
<SetupPage
|
| 455 |
+
userProfile={userProfile}
|
| 456 |
+
setUserProfile={setUserProfile}
|
| 457 |
+
navigateTo={navigateTo}
|
| 458 |
+
onSetupComplete={() => setSetupComplete(true)}
|
| 459 |
+
/>
|
| 460 |
+
)}
|
| 461 |
+
{currentPage === "home" && (
|
| 462 |
+
<HomePage
|
| 463 |
+
userProfile={userProfile}
|
| 464 |
+
setUserProfile={setUserProfile}
|
| 465 |
+
navigateTo={navigateTo}
|
| 466 |
+
savedAssessment={savedAssessment}
|
| 467 |
+
completedAssessments={completedAssessments}
|
| 468 |
+
startAssessmentFlow={startAssessmentFlow}
|
| 469 |
+
onLogout={handleLogout}
|
| 470 |
+
isGuestMode={isGuestMode}
|
| 471 |
+
/>
|
| 472 |
+
)}
|
| 473 |
+
{currentPage === "assessment-history" && (
|
| 474 |
+
<AssessmentHistoryPage
|
| 475 |
+
userProfile={userProfile}
|
| 476 |
+
setUserProfile={setUserProfile}
|
| 477 |
+
completedAssessments={completedAssessments}
|
| 478 |
+
navigateTo={navigateTo}
|
| 479 |
+
onAssessmentDeleted={async (assessmentId) => {
|
| 480 |
+
// Remove from local state
|
| 481 |
+
setCompletedAssessments(prev =>
|
| 482 |
+
prev.filter(a => a.id !== assessmentId)
|
| 483 |
+
);
|
| 484 |
+
}}
|
| 485 |
+
onAssessmentsUpdated={(assessments) => {
|
| 486 |
+
// Update parent state when assessments are refreshed
|
| 487 |
+
setCompletedAssessments(assessments);
|
| 488 |
+
}}
|
| 489 |
+
/>
|
| 490 |
+
)}
|
| 491 |
+
{currentPage === "assessment-responses" && selectedAssessmentId && (
|
| 492 |
+
<AssessmentResponsesPage
|
| 493 |
+
userProfile={userProfile}
|
| 494 |
+
setUserProfile={setUserProfile}
|
| 495 |
+
navigateTo={navigateTo}
|
| 496 |
+
assessmentId={selectedAssessmentId}
|
| 497 |
+
/>
|
| 498 |
+
)}
|
| 499 |
+
{currentPage === "chatbot" && (
|
| 500 |
+
<ChatbotPage
|
| 501 |
+
userProfile={userProfile}
|
| 502 |
+
setUserProfile={setUserProfile}
|
| 503 |
+
navigateTo={navigateTo}
|
| 504 |
+
showResults={showResults}
|
| 505 |
+
assessmentResults={assessmentResults}
|
| 506 |
+
assessmentId={selectedAssessmentId}
|
| 507 |
+
/>
|
| 508 |
+
)}
|
| 509 |
+
{currentPage === "test-form" && (
|
| 510 |
+
<TestFormPage
|
| 511 |
+
userProfile={userProfile}
|
| 512 |
+
setUserProfile={setUserProfile}
|
| 513 |
+
testType={currentTest}
|
| 514 |
+
navigateTo={navigateTo}
|
| 515 |
+
savedAssessment={savedAssessment}
|
| 516 |
+
setSavedAssessment={setSavedAssessment}
|
| 517 |
+
completeTest={completeTest}
|
| 518 |
+
currentTestIndex={currentTestIndex}
|
| 519 |
+
totalTests={testFlow.length}
|
| 520 |
+
assessmentId={selectedAssessmentId || undefined}
|
| 521 |
+
isGuestMode={isGuestMode}
|
| 522 |
+
onTestComplete={(testType, answers) => {
|
| 523 |
+
setAllTestAnswers((prev) => ({ ...prev, [testType]: answers }));
|
| 524 |
+
}}
|
| 525 |
+
/>
|
| 526 |
+
)}
|
| 527 |
+
{currentPage === "processing" && (
|
| 528 |
+
<ProcessingPage
|
| 529 |
+
userProfile={userProfile}
|
| 530 |
+
setUserProfile={setUserProfile}
|
| 531 |
+
navigateTo={navigateTo}
|
| 532 |
+
selectedTest={testFlow[testFlow.length - 1]}
|
| 533 |
+
allTestAnswers={allTestAnswers}
|
| 534 |
+
testFlow={testFlow}
|
| 535 |
+
assessmentId={selectedAssessmentId}
|
| 536 |
+
onResultsReceived={async (results) => {
|
| 537 |
+
setAssessmentResults(results);
|
| 538 |
+
// Refresh assessments list after completing assessment
|
| 539 |
+
await loadAssessments();
|
| 540 |
+
}}
|
| 541 |
+
/>
|
| 542 |
+
)}
|
| 543 |
+
{currentPage === "settings" && (
|
| 544 |
+
<SettingsPage
|
| 545 |
+
userProfile={userProfile}
|
| 546 |
+
setUserProfile={setUserProfile}
|
| 547 |
+
navigateTo={navigateTo}
|
| 548 |
+
/>
|
| 549 |
+
)}
|
| 550 |
+
</div>
|
| 551 |
+
</>
|
| 552 |
+
);
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
export default App;
|
| 556 |
+
|
frontend/src/components/AssessmentHistoryPage.tsx
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState, useEffect } from 'react';
|
| 2 |
+
import { ArrowLeft, ClipboardList, MessageCircle, FileText, Trash2 } from 'lucide-react';
|
| 3 |
+
import { Button } from './ui/button';
|
| 4 |
+
import { Card, CardContent } from './ui/card';
|
| 5 |
+
import { LanguageSelector } from './LanguageSelector';
|
| 6 |
+
import { assessmentService } from '../services/assessmentService';
|
| 7 |
+
import { toast } from 'sonner';
|
| 8 |
+
import {
|
| 9 |
+
Dialog,
|
| 10 |
+
DialogContent,
|
| 11 |
+
DialogDescription,
|
| 12 |
+
DialogHeader,
|
| 13 |
+
DialogTitle,
|
| 14 |
+
DialogFooter,
|
| 15 |
+
} from './ui/dialog';
|
| 16 |
+
import type { Page, UserProfile, CompletedAssessment, Language, TestType } from '../App';
|
| 17 |
+
|
| 18 |
+
const translations = {
|
| 19 |
+
en: {
|
| 20 |
+
title: 'Assessment History',
|
| 21 |
+
subtitle: 'View your completed assessments',
|
| 22 |
+
noAssessments: 'No assessments completed yet',
|
| 23 |
+
assessment: 'Assessment',
|
| 24 |
+
completedOn: 'Completed on',
|
| 25 |
+
viewResponses: 'View Responses',
|
| 26 |
+
viewChatHistory: 'Chat History',
|
| 27 |
+
delete: 'Delete',
|
| 28 |
+
deleteTitle: 'Delete Assessment',
|
| 29 |
+
deleteDescription: 'Are you sure you want to delete this assessment? This will permanently delete the assessment, all test responses, and chat history. This action cannot be undone.',
|
| 30 |
+
deleteButton: 'Delete',
|
| 31 |
+
cancel: 'Cancel',
|
| 32 |
+
deleting: 'Deleting...',
|
| 33 |
+
at: 'at'
|
| 34 |
+
},
|
| 35 |
+
hi: {
|
| 36 |
+
title: 'मूल्यांकन इतिहास',
|
| 37 |
+
subtitle: 'अपने पूर्ण मूल्यांकन देखें',
|
| 38 |
+
noAssessments: 'अभी तक कोई मूल्यांकन पूर्ण नहीं',
|
| 39 |
+
assessment: 'मूल्यांकन',
|
| 40 |
+
completedOn: 'पूर्ण किया',
|
| 41 |
+
viewResponses: 'प्रतिक्रियाएं देखें',
|
| 42 |
+
viewChatHistory: 'चैट इतिहास',
|
| 43 |
+
delete: 'हटाएं',
|
| 44 |
+
deleteTitle: 'मूल्यांकन हटाएं',
|
| 45 |
+
deleteDescription: 'क्या आप वाकई इस मूल्यांकन को हटाना चाहते हैं? यह मूल्यांकन, सभी परीक्षण प्रतिक्रियाएं और चैट इतिहास को स्थायी रूप से हटा देगा। इस क्रिया को पूर्ववत नहीं किया जा सकता।',
|
| 46 |
+
deleteButton: 'हटाएं',
|
| 47 |
+
cancel: 'रद्द करें',
|
| 48 |
+
deleting: 'हटा रहे हैं...',
|
| 49 |
+
at: 'को'
|
| 50 |
+
},
|
| 51 |
+
te: {
|
| 52 |
+
title: 'అసెస్మెంట్ చరిత్ర',
|
| 53 |
+
subtitle: 'మీ పూర్తి అసెస్మెంట్లు చూడండి',
|
| 54 |
+
noAssessments: 'ఇంకా అసెస్మెంట్లు పూర్తి కాలేదు',
|
| 55 |
+
assessment: 'అసెస్మెంట్',
|
| 56 |
+
completedOn: 'పూర్తి అయ్యింది',
|
| 57 |
+
viewResponses: 'ప్రతిస్పందనలు చూడండి',
|
| 58 |
+
viewChatHistory: 'చాట్ చరిత్ర',
|
| 59 |
+
delete: 'తొలగించు',
|
| 60 |
+
deleteTitle: 'అసెస్మెంట్ తొలగించు',
|
| 61 |
+
deleteDescription: 'మీరు నిజంగా ఈ అసెస్మెంట్ను తొలగించాలనుకుంటున్నారా? ఇది అసెస్మెంట్, అన్ని పరీక్ష ప్రతిస్పందనలు మరియు చాట్ చరిత్రను శాశ్వతంగా తొలగిస్తుంది. ఈ చర్యను రద్దు చేయలేరు.',
|
| 62 |
+
deleteButton: 'తొలగించు',
|
| 63 |
+
cancel: 'రద్దు చేయి',
|
| 64 |
+
deleting: 'తొలగిస్తోంది...',
|
| 65 |
+
at: 'న'
|
| 66 |
+
},
|
| 67 |
+
ta: {
|
| 68 |
+
title: 'மதிப்பீடு வரலாறு',
|
| 69 |
+
subtitle: 'முடிந்த மதிப்பீடுகளைப் பார்க்கவும்',
|
| 70 |
+
noAssessments: 'இன்னும் மதிப்பீடுகள் முடிக்கப்படவில்லை',
|
| 71 |
+
assessment: 'மதிப்பீடு',
|
| 72 |
+
completedOn: 'முடிக்கப்பட்டது',
|
| 73 |
+
viewResponses: 'பதில்களைப் பார்க்கவும்',
|
| 74 |
+
viewChatHistory: 'அரட்டை வரலாறு',
|
| 75 |
+
delete: 'நீக்கு',
|
| 76 |
+
deleteTitle: 'மதிப்பீட்டை நீக்கு',
|
| 77 |
+
deleteDescription: 'இந்த மதிப்பீட்டை நீக்க விரும்புகிறீர்களா? இது மதிப்பீடு, அனைத்து சோதனை பதில்கள் மற்றும் அரட்டை வரலாற்றை நிரந்தரமாக நீக்கும். இந்த செயலை மீளமுடியாது.',
|
| 78 |
+
deleteButton: 'நீக்கு',
|
| 79 |
+
cancel: 'ரத்துசெய்',
|
| 80 |
+
deleting: 'நீக்குகிறது...',
|
| 81 |
+
at: 'அன்று'
|
| 82 |
+
},
|
| 83 |
+
bn: {
|
| 84 |
+
title: 'মূল্যায়ন ইতিহাস',
|
| 85 |
+
subtitle: 'আপনার সম্পূর্ণ মূল্যায়ন দেখুন',
|
| 86 |
+
noAssessments: 'এখনও কোন মূল্যায়ন সম্পূর্ণ হয়নি',
|
| 87 |
+
assessment: 'মূল্যায়ন',
|
| 88 |
+
completedOn: 'সম্পূর্ণ হয়েছে',
|
| 89 |
+
viewResponses: 'প্রতিক্রিয়া দেখুন',
|
| 90 |
+
viewChatHistory: 'চ্যাট ইতিহাস',
|
| 91 |
+
delete: 'মুছুন',
|
| 92 |
+
deleteTitle: 'মূল্যায়ন মুছুন',
|
| 93 |
+
deleteDescription: 'আপনি কি নিশ্চিত যে আপনি এই মূল্যায়নটি মুছতে চান? এটি মূল্যায়ন, সমস্ত পরীক্ষার প্রতিক্রিয়া এবং চ্যাট ইতিহাস স্থায়ীভাবে মুছে ফেলবে। এই কাজটি পূর্বাবস্থায় ফেরানো যাবে না।',
|
| 94 |
+
deleteButton: 'মুছুন',
|
| 95 |
+
cancel: 'বাতিল',
|
| 96 |
+
deleting: 'মুছে ফেলছে...',
|
| 97 |
+
at: 'এ'
|
| 98 |
+
},
|
| 99 |
+
gu: {
|
| 100 |
+
title: 'મૂલ્યાંકન ઇતિહાસ',
|
| 101 |
+
subtitle: 'તમારા પૂર્ણ મૂલ્યાંકનો જુઓ',
|
| 102 |
+
noAssessments: 'હજી સુધી કોઈ મૂલ્યાંકન પૂર્ણ થયું નથી',
|
| 103 |
+
assessment: 'મૂલ્યાંકન',
|
| 104 |
+
completedOn: 'પૂર્ણ થયું',
|
| 105 |
+
viewResponses: 'પ્રતિસાદ જુઓ',
|
| 106 |
+
viewChatHistory: 'ચેટ ઇતિહાસ',
|
| 107 |
+
delete: 'કાઢી નાખો',
|
| 108 |
+
deleteTitle: 'મૂલ્યાંકન કાઢી નાખો',
|
| 109 |
+
deleteDescription: 'શું તમે ખરેખર આ મૂલ્યાંકન કાઢી નાખવા માંગો છો? આ મૂલ્યાંકન, બધી પરીક્ષણ પ્રતિસાદો અને ચેટ ઇતિહાસને કાયમી રીતે કાઢી નાખશે. આ ક્રિયાને પૂર્વવત્ કરી શકાતી નથી.',
|
| 110 |
+
deleteButton: 'કાઢી નાખો',
|
| 111 |
+
cancel: 'રદ કરો',
|
| 112 |
+
deleting: 'કાઢી રહ્યા છીએ...',
|
| 113 |
+
at: 'ના'
|
| 114 |
+
}
|
| 115 |
+
};
|
| 116 |
+
|
| 117 |
+
interface AssessmentHistoryPageProps {
|
| 118 |
+
userProfile: UserProfile;
|
| 119 |
+
setUserProfile: (profile: UserProfile) => void;
|
| 120 |
+
completedAssessments: CompletedAssessment[];
|
| 121 |
+
navigateTo: (page: Page, displayResults?: boolean, assessmentId?: number) => void;
|
| 122 |
+
onAssessmentDeleted?: (assessmentId: number) => void;
|
| 123 |
+
onAssessmentsUpdated?: (assessments: CompletedAssessment[]) => void;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
export function AssessmentHistoryPage({
|
| 127 |
+
userProfile,
|
| 128 |
+
setUserProfile,
|
| 129 |
+
completedAssessments: propCompletedAssessments,
|
| 130 |
+
navigateTo,
|
| 131 |
+
onAssessmentDeleted,
|
| 132 |
+
onAssessmentsUpdated
|
| 133 |
+
}: AssessmentHistoryPageProps) {
|
| 134 |
+
const t = translations[userProfile.language];
|
| 135 |
+
const [completedAssessments, setCompletedAssessments] = useState<CompletedAssessment[]>(propCompletedAssessments);
|
| 136 |
+
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
| 137 |
+
const [assessmentToDelete, setAssessmentToDelete] = useState<number | null>(null);
|
| 138 |
+
const [isDeleting, setIsDeleting] = useState(false);
|
| 139 |
+
const [isLoading, setIsLoading] = useState(false);
|
| 140 |
+
|
| 141 |
+
// Refresh assessments when component mounts or when navigating to this page
|
| 142 |
+
useEffect(() => {
|
| 143 |
+
const refreshAssessments = async () => {
|
| 144 |
+
setIsLoading(true);
|
| 145 |
+
try {
|
| 146 |
+
const response = await assessmentService.getHistory();
|
| 147 |
+
const data = response.data;
|
| 148 |
+
if (data.completed_assessments) {
|
| 149 |
+
const testFlow: TestType[] = ['riasec', 'values', 'personal'];
|
| 150 |
+
const assessments = data.completed_assessments
|
| 151 |
+
.map((a: any) => ({
|
| 152 |
+
id: a.id,
|
| 153 |
+
completedAt: new Date(a.completed_at),
|
| 154 |
+
tests: testFlow,
|
| 155 |
+
has_chat: a.has_chat || false,
|
| 156 |
+
}));
|
| 157 |
+
// Sort: assessments with chat first, then by completed_at desc
|
| 158 |
+
const sorted = assessments.sort((a: any, b: any) => {
|
| 159 |
+
if (a.has_chat && !b.has_chat) return -1;
|
| 160 |
+
if (!a.has_chat && b.has_chat) return 1;
|
| 161 |
+
return b.completedAt.getTime() - a.completedAt.getTime();
|
| 162 |
+
});
|
| 163 |
+
setCompletedAssessments(sorted);
|
| 164 |
+
// Notify parent component to update its state
|
| 165 |
+
if (onAssessmentsUpdated) {
|
| 166 |
+
onAssessmentsUpdated(sorted);
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
+
} catch (error) {
|
| 170 |
+
console.error('Error refreshing assessments:', error);
|
| 171 |
+
} finally {
|
| 172 |
+
setIsLoading(false);
|
| 173 |
+
}
|
| 174 |
+
};
|
| 175 |
+
|
| 176 |
+
refreshAssessments();
|
| 177 |
+
}, []); // Only run on mount
|
| 178 |
+
|
| 179 |
+
// Update local state when prop changes
|
| 180 |
+
useEffect(() => {
|
| 181 |
+
setCompletedAssessments(propCompletedAssessments);
|
| 182 |
+
}, [propCompletedAssessments]);
|
| 183 |
+
|
| 184 |
+
const handleLanguageChange = (lang: Language) => {
|
| 185 |
+
setUserProfile({ ...userProfile, language: lang });
|
| 186 |
+
};
|
| 187 |
+
|
| 188 |
+
const handleDeleteClick = (assessmentId: number) => {
|
| 189 |
+
setAssessmentToDelete(assessmentId);
|
| 190 |
+
setDeleteDialogOpen(true);
|
| 191 |
+
};
|
| 192 |
+
|
| 193 |
+
const handleDeleteConfirm = async () => {
|
| 194 |
+
if (!assessmentToDelete) return;
|
| 195 |
+
|
| 196 |
+
setIsDeleting(true);
|
| 197 |
+
try {
|
| 198 |
+
// Delete assessment via API (this will cascade delete test responses and chat messages)
|
| 199 |
+
await assessmentService.deleteAssessment(assessmentToDelete);
|
| 200 |
+
|
| 201 |
+
// Refresh assessments from server
|
| 202 |
+
const response = await assessmentService.getHistory();
|
| 203 |
+
const data = response.data;
|
| 204 |
+
if (data.completed_assessments) {
|
| 205 |
+
const testFlow: TestType[] = ['aptitude', 'values', 'personal'];
|
| 206 |
+
const assessments = data.completed_assessments
|
| 207 |
+
.map((a: any) => ({
|
| 208 |
+
id: a.id,
|
| 209 |
+
completedAt: new Date(a.completed_at),
|
| 210 |
+
tests: testFlow,
|
| 211 |
+
has_chat: a.has_chat || false,
|
| 212 |
+
}));
|
| 213 |
+
// Sort: assessments with chat first, then by completed_at desc
|
| 214 |
+
const sorted = assessments.sort((a: any, b: any) => {
|
| 215 |
+
if (a.has_chat && !b.has_chat) return -1;
|
| 216 |
+
if (!a.has_chat && b.has_chat) return 1;
|
| 217 |
+
return b.completedAt.getTime() - a.completedAt.getTime();
|
| 218 |
+
});
|
| 219 |
+
setCompletedAssessments(sorted);
|
| 220 |
+
// Notify parent component
|
| 221 |
+
if (onAssessmentsUpdated) {
|
| 222 |
+
onAssessmentsUpdated(sorted);
|
| 223 |
+
}
|
| 224 |
+
if (onAssessmentDeleted) {
|
| 225 |
+
onAssessmentDeleted(assessmentToDelete);
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
toast.success('Assessment deleted successfully');
|
| 230 |
+
setDeleteDialogOpen(false);
|
| 231 |
+
setAssessmentToDelete(null);
|
| 232 |
+
} catch (error: any) {
|
| 233 |
+
console.error('Error deleting assessment:', error);
|
| 234 |
+
toast.error(error.response?.data?.error || 'Failed to delete assessment');
|
| 235 |
+
} finally {
|
| 236 |
+
setIsDeleting(false);
|
| 237 |
+
}
|
| 238 |
+
};
|
| 239 |
+
|
| 240 |
+
const formatDate = (date: Date) => {
|
| 241 |
+
return new Intl.DateTimeFormat(userProfile.language === 'en' ? 'en-US' : 'en-IN', {
|
| 242 |
+
year: 'numeric',
|
| 243 |
+
month: 'short',
|
| 244 |
+
day: 'numeric'
|
| 245 |
+
}).format(date);
|
| 246 |
+
};
|
| 247 |
+
|
| 248 |
+
const formatTime = (date: Date) => {
|
| 249 |
+
return new Intl.DateTimeFormat(userProfile.language === 'en' ? 'en-US' : 'en-IN', {
|
| 250 |
+
hour: '2-digit',
|
| 251 |
+
minute: '2-digit'
|
| 252 |
+
}).format(date);
|
| 253 |
+
};
|
| 254 |
+
|
| 255 |
+
return (
|
| 256 |
+
<div className="min-h-screen bg-gradient-to-br from-blue-50 via-white to-purple-50">
|
| 257 |
+
{/* Header */}
|
| 258 |
+
<header className="bg-white shadow-sm border-b">
|
| 259 |
+
<div className="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-4">
|
| 260 |
+
<div className="flex items-center gap-4">
|
| 261 |
+
<Button
|
| 262 |
+
variant="ghost"
|
| 263 |
+
size="icon"
|
| 264 |
+
onClick={() => navigateTo('home')}
|
| 265 |
+
>
|
| 266 |
+
<ArrowLeft className="h-5 w-5" />
|
| 267 |
+
</Button>
|
| 268 |
+
<div className="flex-1">
|
| 269 |
+
<h2 className="text-gray-900">{t.title}</h2>
|
| 270 |
+
<p className="text-gray-600 text-sm">{t.subtitle}</p>
|
| 271 |
+
</div>
|
| 272 |
+
<LanguageSelector
|
| 273 |
+
language={userProfile.language}
|
| 274 |
+
onLanguageChange={handleLanguageChange}
|
| 275 |
+
/>
|
| 276 |
+
</div>
|
| 277 |
+
</div>
|
| 278 |
+
</header>
|
| 279 |
+
|
| 280 |
+
{/* Main Content */}
|
| 281 |
+
<main className="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
| 282 |
+
{isLoading ? (
|
| 283 |
+
<Card className="text-center py-12">
|
| 284 |
+
<CardContent>
|
| 285 |
+
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto mb-4"></div>
|
| 286 |
+
<p className="text-gray-600">Loading assessments...</p>
|
| 287 |
+
</CardContent>
|
| 288 |
+
</Card>
|
| 289 |
+
) : completedAssessments.length === 0 ? (
|
| 290 |
+
<Card className="text-center py-12">
|
| 291 |
+
<CardContent>
|
| 292 |
+
<ClipboardList className="h-16 w-16 mx-auto text-gray-400 mb-4" />
|
| 293 |
+
<p className="text-gray-600">{t.noAssessments}</p>
|
| 294 |
+
</CardContent>
|
| 295 |
+
</Card>
|
| 296 |
+
) : (
|
| 297 |
+
<div className="space-y-4">
|
| 298 |
+
{completedAssessments.map((assessment, index) => (
|
| 299 |
+
<Card
|
| 300 |
+
key={assessment.id}
|
| 301 |
+
className="border-2 hover:border-blue-300 transition-colors"
|
| 302 |
+
>
|
| 303 |
+
<CardContent className="p-6">
|
| 304 |
+
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
|
| 305 |
+
<div className="flex items-center gap-4">
|
| 306 |
+
<div className="bg-gradient-to-br from-blue-100 to-purple-100 p-4 rounded-xl">
|
| 307 |
+
<ClipboardList className="h-8 w-8 text-blue-600" />
|
| 308 |
+
</div>
|
| 309 |
+
<div>
|
| 310 |
+
<h3 className="text-gray-900">
|
| 311 |
+
{t.assessment} #{index + 1}
|
| 312 |
+
</h3>
|
| 313 |
+
<p className="text-gray-600 text-sm">
|
| 314 |
+
{t.completedOn} {formatDate(assessment.completedAt)} {t.at} {formatTime(assessment.completedAt)}
|
| 315 |
+
</p>
|
| 316 |
+
</div>
|
| 317 |
+
</div>
|
| 318 |
+
<div className="flex flex-col sm:flex-row gap-2 w-full sm:w-auto">
|
| 319 |
+
<Button
|
| 320 |
+
onClick={() => navigateTo('chatbot', true, assessment.id)}
|
| 321 |
+
className="gap-2 w-full sm:w-auto bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700"
|
| 322 |
+
>
|
| 323 |
+
<MessageCircle className="h-4 w-4" />
|
| 324 |
+
{t.viewChatHistory}
|
| 325 |
+
</Button>
|
| 326 |
+
<Button
|
| 327 |
+
onClick={() => navigateTo('assessment-responses', false, assessment.id)}
|
| 328 |
+
variant="outline"
|
| 329 |
+
className="gap-2 w-full sm:w-auto"
|
| 330 |
+
>
|
| 331 |
+
<FileText className="h-4 w-4" />
|
| 332 |
+
{t.viewResponses}
|
| 333 |
+
</Button>
|
| 334 |
+
<Button
|
| 335 |
+
onClick={() => handleDeleteClick(assessment.id)}
|
| 336 |
+
variant="outline"
|
| 337 |
+
className="gap-2 w-full sm:w-auto text-red-600 hover:text-red-700 hover:bg-red-50 border-red-200"
|
| 338 |
+
>
|
| 339 |
+
<Trash2 className="h-4 w-4" />
|
| 340 |
+
{t.delete}
|
| 341 |
+
</Button>
|
| 342 |
+
</div>
|
| 343 |
+
</div>
|
| 344 |
+
</CardContent>
|
| 345 |
+
</Card>
|
| 346 |
+
))}
|
| 347 |
+
</div>
|
| 348 |
+
)}
|
| 349 |
+
</main>
|
| 350 |
+
|
| 351 |
+
{/* Delete Assessment Dialog */}
|
| 352 |
+
<Dialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>
|
| 353 |
+
<DialogContent>
|
| 354 |
+
<DialogHeader>
|
| 355 |
+
<DialogTitle>{t.deleteTitle}</DialogTitle>
|
| 356 |
+
<DialogDescription>
|
| 357 |
+
{t.deleteDescription}
|
| 358 |
+
</DialogDescription>
|
| 359 |
+
</DialogHeader>
|
| 360 |
+
<DialogFooter>
|
| 361 |
+
<Button
|
| 362 |
+
variant="outline"
|
| 363 |
+
onClick={() => {
|
| 364 |
+
setDeleteDialogOpen(false);
|
| 365 |
+
setAssessmentToDelete(null);
|
| 366 |
+
}}
|
| 367 |
+
disabled={isDeleting}
|
| 368 |
+
>
|
| 369 |
+
{t.cancel}
|
| 370 |
+
</Button>
|
| 371 |
+
<Button
|
| 372 |
+
variant="destructive"
|
| 373 |
+
onClick={handleDeleteConfirm}
|
| 374 |
+
disabled={isDeleting}
|
| 375 |
+
>
|
| 376 |
+
{isDeleting ? t.deleting : t.deleteButton}
|
| 377 |
+
</Button>
|
| 378 |
+
</DialogFooter>
|
| 379 |
+
</DialogContent>
|
| 380 |
+
</Dialog>
|
| 381 |
+
</div>
|
| 382 |
+
);
|
| 383 |
+
}
|
frontend/src/components/AssessmentResponsesPage.tsx
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState, useEffect } from 'react';
|
| 2 |
+
import { ArrowLeft, ClipboardList, CheckCircle2, Loader2 } from 'lucide-react';
|
| 3 |
+
import { Button } from './ui/button';
|
| 4 |
+
import { Card, CardContent, CardHeader, CardTitle } from './ui/card';
|
| 5 |
+
import { LanguageSelector } from './LanguageSelector';
|
| 6 |
+
import { assessmentService } from '../services/assessmentService';
|
| 7 |
+
import { toast } from 'sonner';
|
| 8 |
+
import type { Page, UserProfile, Language } from '../App';
|
| 9 |
+
|
| 10 |
+
interface AssessmentResponsesPageProps {
|
| 11 |
+
userProfile: UserProfile;
|
| 12 |
+
setUserProfile: (profile: UserProfile) => void;
|
| 13 |
+
navigateTo: (page: Page) => void;
|
| 14 |
+
assessmentId: number;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
const translations = {
|
| 18 |
+
en: {
|
| 19 |
+
title: 'Assessment Responses',
|
| 20 |
+
subtitle: 'Review your selected options',
|
| 21 |
+
backToHistory: 'Back to History',
|
| 22 |
+
riasecTest: 'RIASEC Personality Test',
|
| 23 |
+
valuesTest: 'Values & Motivation Test',
|
| 24 |
+
personalTest: 'Personal Information',
|
| 25 |
+
noData: 'Options selected will appear here',
|
| 26 |
+
noDataDesc: 'Your assessment responses are not available in demo mode'
|
| 27 |
+
},
|
| 28 |
+
hi: {
|
| 29 |
+
title: 'मूल्यांकन प्रतिक्रियाएं',
|
| 30 |
+
subtitle: 'अपने चयनित विकल्पों की समीक्षा करें',
|
| 31 |
+
backToHistory: 'इतिहास पर वापस जाएं',
|
| 32 |
+
riasecTest: 'RIASEC व्यक्तित्व परीक्षा',
|
| 33 |
+
valuesTest: 'मूल्य और प्रेरणा परीक्षा',
|
| 34 |
+
personalTest: 'व्यक्तिगत जानकारी',
|
| 35 |
+
noData: 'चयनित विकल्प यहां दिखाई देंगे',
|
| 36 |
+
noDataDesc: 'डेमो मोड में आपकी मूल्यांकन प्रतिक्रियाएं उपलब्ध नहीं हैं'
|
| 37 |
+
},
|
| 38 |
+
te: {
|
| 39 |
+
title: 'అసెస్మెంట్ ప్రతిస్పందనలు',
|
| 40 |
+
subtitle: 'మీరు ఎంచుకున్న ఎంపికలను సమీక్షించండి',
|
| 41 |
+
backToHistory: 'చరిత్రకు తిరిగి వెళ్ళు',
|
| 42 |
+
riasecTest: 'RIASEC వ్యక్తిత్వ పరీక్ష',
|
| 43 |
+
valuesTest: 'విలువలు మరియు ప్రేరణ పరీక్ష',
|
| 44 |
+
personalTest: 'వ్యక్తిగత సమాచారం',
|
| 45 |
+
noData: 'ఎంచుకున్న ఎంపికలు ఇక్కడ కనిపిస్తాయి',
|
| 46 |
+
noDataDesc: 'డెమో మోడ్లో మీ అసెస్మెంట్ ప్రతిస్పందనలు అందుబాటులో లేవు'
|
| 47 |
+
},
|
| 48 |
+
ta: {
|
| 49 |
+
title: 'மதிப்பீட்டு பதில்கள்',
|
| 50 |
+
subtitle: 'தேர்ந்தெடுத்த விருப்பங்களை மதிப்பாய்வு செய்யவும்',
|
| 51 |
+
backToHistory: 'வரலாற்றுக்குத் திரும்பு',
|
| 52 |
+
riasecTest: 'RIASEC ஆளுமை தேர்வு',
|
| 53 |
+
valuesTest: 'மதிப்புகள் மற்றும் உந்துதல் தேர்வு',
|
| 54 |
+
personalTest: 'தனிப்பட்ட தகவல்',
|
| 55 |
+
noData: 'தேர்ந்தெடுத்த விருப்பங்கள் இங்கே தோன்றும்',
|
| 56 |
+
noDataDesc: 'டெமோ பயன்முறையில் உங்கள் மதிப்பீட்டு பதில்கள் கிடைக்கவில்லை'
|
| 57 |
+
},
|
| 58 |
+
bn: {
|
| 59 |
+
title: 'মূল্যায়ন প্রতিক্রিয়া',
|
| 60 |
+
subtitle: 'আপনার নির্বাচিত বিকল্পগুলি পর্যালোচনা করুন',
|
| 61 |
+
backToHistory: 'ইতিহাসে ফিরে যান',
|
| 62 |
+
riasecTest: 'RIASEC ব্যক্তিত্ব পরীক্ষা',
|
| 63 |
+
valuesTest: 'মূল্যবোধ এবং প্রেরণা পরীক্ষা',
|
| 64 |
+
personalTest: 'ব্যক্তিগত তথ্য',
|
| 65 |
+
noData: 'নির্বাচিত বিকল্পগুলি এখানে প্রদর্শিত হবে',
|
| 66 |
+
noDataDesc: 'ডেমো মোডে আপনার মূল্যায়ন প্রতিক্রিয়া উপলব্ধ নেই'
|
| 67 |
+
},
|
| 68 |
+
gu: {
|
| 69 |
+
title: 'મૂલ્યાંકન પ્રતિસાદ',
|
| 70 |
+
subtitle: 'તમારા પસંદ કરેલ વિકલ્પોની સમીક્ષા કરો',
|
| 71 |
+
backToHistory: 'ઇતિહાસ પર પાછા જાઓ',
|
| 72 |
+
riasecTest: 'RIASEC વ્યક્તિત્વ પરીક્ષા',
|
| 73 |
+
valuesTest: 'મૂલ્યો અને પ્રેરણા પરીક્ષા',
|
| 74 |
+
personalTest: 'વ્યક્તિગત માહિતી',
|
| 75 |
+
noData: 'પસંદ કરેલા વિકલ્પો અહીં દેખાશે',
|
| 76 |
+
noDataDesc: 'ડેમો મોડમાં ���મારા મૂલ્યાંકન પ્રતિસાદ ઉપલબ્ધ નથી'
|
| 77 |
+
}
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
interface TestResponse {
|
| 81 |
+
test_type: string;
|
| 82 |
+
answers: { [key: number]: string | string[] };
|
| 83 |
+
submitted_at: string | null;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
export function AssessmentResponsesPage({
|
| 87 |
+
userProfile,
|
| 88 |
+
setUserProfile,
|
| 89 |
+
navigateTo,
|
| 90 |
+
assessmentId
|
| 91 |
+
}: AssessmentResponsesPageProps) {
|
| 92 |
+
const t = translations[userProfile.language];
|
| 93 |
+
const [responses, setResponses] = useState<TestResponse[]>([]);
|
| 94 |
+
const [loading, setLoading] = useState(true);
|
| 95 |
+
|
| 96 |
+
const handleLanguageChange = (lang: Language) => {
|
| 97 |
+
setUserProfile({ ...userProfile, language: lang });
|
| 98 |
+
};
|
| 99 |
+
|
| 100 |
+
useEffect(() => {
|
| 101 |
+
const fetchResponses = async () => {
|
| 102 |
+
try {
|
| 103 |
+
setLoading(true);
|
| 104 |
+
const response = await assessmentService.getResponses(assessmentId);
|
| 105 |
+
setResponses(response.data.test_responses || []);
|
| 106 |
+
} catch (error: any) {
|
| 107 |
+
console.error('Error fetching responses:', error);
|
| 108 |
+
toast.error('Failed to load assessment responses');
|
| 109 |
+
} finally {
|
| 110 |
+
setLoading(false);
|
| 111 |
+
}
|
| 112 |
+
};
|
| 113 |
+
|
| 114 |
+
if (assessmentId) {
|
| 115 |
+
fetchResponses();
|
| 116 |
+
}
|
| 117 |
+
}, [assessmentId]);
|
| 118 |
+
|
| 119 |
+
const testSections = [
|
| 120 |
+
{ id: 'riasec', title: t.riasecTest, icon: ClipboardList },
|
| 121 |
+
{ id: 'values', title: t.valuesTest, icon: ClipboardList },
|
| 122 |
+
{ id: 'personal', title: t.personalTest, icon: ClipboardList }
|
| 123 |
+
];
|
| 124 |
+
|
| 125 |
+
const getTestTitle = (testType: string) => {
|
| 126 |
+
switch (testType) {
|
| 127 |
+
case 'riasec':
|
| 128 |
+
return t.riasecTest;
|
| 129 |
+
case 'values':
|
| 130 |
+
return t.valuesTest;
|
| 131 |
+
case 'personal':
|
| 132 |
+
return t.personalTest;
|
| 133 |
+
default:
|
| 134 |
+
return testType;
|
| 135 |
+
}
|
| 136 |
+
};
|
| 137 |
+
|
| 138 |
+
return (
|
| 139 |
+
<div className="min-h-screen bg-gradient-to-br from-blue-50 via-white to-purple-50">
|
| 140 |
+
{/* Header */}
|
| 141 |
+
<header className="bg-white shadow-sm border-b">
|
| 142 |
+
<div className="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-4">
|
| 143 |
+
<div className="flex items-center gap-4">
|
| 144 |
+
<Button
|
| 145 |
+
variant="ghost"
|
| 146 |
+
size="icon"
|
| 147 |
+
onClick={() => navigateTo('assessment-history')}
|
| 148 |
+
>
|
| 149 |
+
<ArrowLeft className="h-5 w-5" />
|
| 150 |
+
</Button>
|
| 151 |
+
<div className="flex-1">
|
| 152 |
+
<h2 className="text-gray-900">{t.title}</h2>
|
| 153 |
+
<p className="text-gray-600 text-sm">{t.subtitle}</p>
|
| 154 |
+
</div>
|
| 155 |
+
<LanguageSelector
|
| 156 |
+
language={userProfile.language}
|
| 157 |
+
onLanguageChange={handleLanguageChange}
|
| 158 |
+
/>
|
| 159 |
+
</div>
|
| 160 |
+
</div>
|
| 161 |
+
</header>
|
| 162 |
+
|
| 163 |
+
{/* Main Content */}
|
| 164 |
+
<main className="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
| 165 |
+
{loading ? (
|
| 166 |
+
<div className="flex items-center justify-center py-12">
|
| 167 |
+
<Loader2 className="h-8 w-8 animate-spin text-blue-600" />
|
| 168 |
+
</div>
|
| 169 |
+
) : responses.length === 0 ? (
|
| 170 |
+
<Card>
|
| 171 |
+
<CardContent className="text-center py-12">
|
| 172 |
+
<CheckCircle2 className="h-16 w-16 mx-auto text-gray-400 mb-4" />
|
| 173 |
+
<p className="text-gray-900 mb-2">{t.noData}</p>
|
| 174 |
+
<p className="text-gray-600 text-sm">{t.noDataDesc}</p>
|
| 175 |
+
</CardContent>
|
| 176 |
+
</Card>
|
| 177 |
+
) : (
|
| 178 |
+
<div className="space-y-6">
|
| 179 |
+
{responses.map((testResponse) => (
|
| 180 |
+
<Card key={testResponse.test_type}>
|
| 181 |
+
<CardHeader>
|
| 182 |
+
<CardTitle className="flex items-center gap-3">
|
| 183 |
+
<div className="bg-gradient-to-br from-blue-100 to-purple-100 p-3 rounded-lg">
|
| 184 |
+
<ClipboardList className="h-6 w-6 text-blue-600" />
|
| 185 |
+
</div>
|
| 186 |
+
{getTestTitle(testResponse.test_type)}
|
| 187 |
+
{testResponse.submitted_at && (
|
| 188 |
+
<span className="text-sm font-normal text-gray-500 ml-auto">
|
| 189 |
+
{new Date(testResponse.submitted_at).toLocaleDateString()}
|
| 190 |
+
</span>
|
| 191 |
+
)}
|
| 192 |
+
</CardTitle>
|
| 193 |
+
</CardHeader>
|
| 194 |
+
<CardContent>
|
| 195 |
+
<div className="space-y-4">
|
| 196 |
+
{Object.entries(testResponse.answers)
|
| 197 |
+
.filter(([questionId, answer]) => {
|
| 198 |
+
// Filter out answers that look like chat messages or are empty
|
| 199 |
+
if (!answer) return false;
|
| 200 |
+
const answerStr = Array.isArray(answer) ? answer.join(' ') : String(answer);
|
| 201 |
+
// Check if answer contains chatbot greeting phrases
|
| 202 |
+
const chatPhrases = [
|
| 203 |
+
'great job on the assessment',
|
| 204 |
+
'career paths for you',
|
| 205 |
+
'exciting career paths',
|
| 206 |
+
'Based on your results',
|
| 207 |
+
'Hey',
|
| 208 |
+
'free to ask me any questions'
|
| 209 |
+
];
|
| 210 |
+
const isChatMessage = chatPhrases.some(phrase =>
|
| 211 |
+
answerStr.toLowerCase().includes(phrase.toLowerCase())
|
| 212 |
+
);
|
| 213 |
+
return !isChatMessage && answerStr.trim().length > 0;
|
| 214 |
+
})
|
| 215 |
+
.map(([questionId, answer]) => {
|
| 216 |
+
// Clean up the answer - remove any chat message content
|
| 217 |
+
let cleanAnswer = answer;
|
| 218 |
+
if (typeof answer === 'string') {
|
| 219 |
+
// Remove chat greeting if it's appended
|
| 220 |
+
const chatGreetingPattern = /(?:Hey\s+[^,]+,?\s*)?(?:Grade:\s*\w+,?\s*)?(?:Age:\s*\d+,?\s*)?(?:great job on the assessment[^]*?career paths[^]*?)/i;
|
| 221 |
+
cleanAnswer = answer.replace(chatGreetingPattern, '').trim();
|
| 222 |
+
// If answer is empty after cleaning, use original
|
| 223 |
+
if (!cleanAnswer) cleanAnswer = answer;
|
| 224 |
+
}
|
| 225 |
+
return (
|
| 226 |
+
<div key={questionId} className="border-l-4 border-blue-500 pl-4 py-2">
|
| 227 |
+
<p className="text-sm font-medium text-gray-700 mb-1">
|
| 228 |
+
Question {questionId}
|
| 229 |
+
</p>
|
| 230 |
+
<div className="text-gray-900">
|
| 231 |
+
{Array.isArray(cleanAnswer) ? (
|
| 232 |
+
<ul className="list-disc list-inside space-y-1">
|
| 233 |
+
{cleanAnswer.map((item, idx) => (
|
| 234 |
+
<li key={idx}>{item}</li>
|
| 235 |
+
))}
|
| 236 |
+
</ul>
|
| 237 |
+
) : (
|
| 238 |
+
<p>{cleanAnswer}</p>
|
| 239 |
+
)}
|
| 240 |
+
</div>
|
| 241 |
+
</div>
|
| 242 |
+
);
|
| 243 |
+
})}
|
| 244 |
+
</div>
|
| 245 |
+
</CardContent>
|
| 246 |
+
</Card>
|
| 247 |
+
))}
|
| 248 |
+
</div>
|
| 249 |
+
)}
|
| 250 |
+
</main>
|
| 251 |
+
</div>
|
| 252 |
+
);
|
| 253 |
+
}
|
frontend/src/components/ChatbotPage.tsx
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState, useRef, useEffect, useMemo } from "react";
|
| 2 |
+
import { ArrowLeft, Send, Bot, User, AlertCircle } from "lucide-react";
|
| 3 |
+
import { Button } from "./ui/button";
|
| 4 |
+
import { Textarea } from "./ui/textarea";
|
| 5 |
+
import { Card } from "./ui/card";
|
| 6 |
+
import { Avatar, AvatarFallback } from "./ui/avatar";
|
| 7 |
+
import { Alert, AlertDescription } from "./ui/alert";
|
| 8 |
+
import { LanguageSelector } from "./LanguageSelector";
|
| 9 |
+
import { assessmentService } from "../services/assessmentService";
|
| 10 |
+
import { toast } from "sonner";
|
| 11 |
+
import {
|
| 12 |
+
Dialog,
|
| 13 |
+
DialogContent,
|
| 14 |
+
DialogDescription,
|
| 15 |
+
DialogHeader,
|
| 16 |
+
DialogTitle,
|
| 17 |
+
DialogFooter,
|
| 18 |
+
} from "./ui/dialog";
|
| 19 |
+
import type { Page, UserProfile, Language, AssessmentResults } from "../App";
|
| 20 |
+
|
| 21 |
+
interface ChatbotPageProps {
|
| 22 |
+
userProfile: UserProfile;
|
| 23 |
+
setUserProfile: (profile: UserProfile) => void;
|
| 24 |
+
navigateTo: (page: Page, displayResults?: boolean, assessmentId?: number) => void;
|
| 25 |
+
showResults?: boolean;
|
| 26 |
+
assessmentResults?: AssessmentResults | null;
|
| 27 |
+
assessmentId?: number | null;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
interface Message {
|
| 31 |
+
id: number | string;
|
| 32 |
+
text: string;
|
| 33 |
+
sender: "user" | "bot";
|
| 34 |
+
timestamp: Date;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
const connectionErrorMessages = {
|
| 38 |
+
en: "Connection failed. Unable to process more queries at this time. Please try again in some time.",
|
| 39 |
+
hi: "कनेक्शन विफल। इस समय अधिक प्रश्नों को संसाधित करने में असमर्थ। कृपया कुछ समय बाद पुनः प्रयास करें।",
|
| 40 |
+
te: "కనెక్షన్ విఫలమైంది. ప్రస్తుతం మరిన్ని ప్రశ్నలను ప్రాసెస్ చేయడం సాధ్యంలేదు. దయచేసి కొంతసమయం తర్వాత మళ్లీ ప్రయత్నించండి.",
|
| 41 |
+
ta: "இணைப்பு தோல்வியடைந்தது. தற்போது மேலும் கேள்விகளை செயலாக்க முடியவில்லை. தயவுசெய்து சிறிது நேரம் கழித்து மீண்டும் முயற்சிக்கவும்.",
|
| 42 |
+
bn: "সংযোগ ব্যর্থ হয়েছে। এই মুহূর্তে আরও প্রশ্ন প্রক্রিয়া করা সম্ভব নয়। অনুগ্রহ করে কিছু সময় পরে আবার চেষ্টা করুন।",
|
| 43 |
+
gu: "કનેક્શન નિષ્ફળ થયું. આ સમયે વધુ પ્રશ્નોની પ્રક્રિયા શક્ય નથી. કૃપા કરીને થોડા સમય પછી ફરી પ્રયાસ કરો.",
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
// Generic greetings for general chat (no assessment)
|
| 47 |
+
const fallbackInitialMessages: Record<Language, (name: string) => string> = {
|
| 48 |
+
en: (name) =>
|
| 49 |
+
`Hello ${name}! I'm your career guidance assistant. I'm here to help you explore career options, answer questions about different professions, and guide you on educational paths. What would you like to know about today?`,
|
| 50 |
+
hi: (name) =>
|
| 51 |
+
`नमस्ते ${name}! मैं आपका करियर गाइडेंस सहायक हूं। मैं यहां आपको करियर विकल्पों, विभिन्न व्यवसायों और शैक्षिक मार्गों के बारे में मदद करने के लिए हूं। आज आप क्या जानना चाहेंगे?`,
|
| 52 |
+
te: (name) =>
|
| 53 |
+
`హలో ${name}! నేను మీ కెరీర్ గైడెన్స్ అసిస్టెంట్. కెరీర్ ఎంపికలు, వివిధ వృత్తులు మరియు విద్యా మార్గాల గురించి మీకు సహాయం చేయడానికి నేను ఇక్కడ ఉన్నాను. ఈరోజు మీరు ఏమి తెలుసుకోవాలనుకుంటున్నారు?`,
|
| 54 |
+
ta: (name) =>
|
| 55 |
+
`வணக்கம் ${name}! நான் உங்கள் தொழில் வழிகாட்டி உதவியாளர். தொழில் விருப்பங்கள், பல்வேறு தொழில்கள் மற்றும் கல்விப் பாதைகள் குறித்து உங்களுக்கு உதவ நான் இங்கே இருக்கிறேன்。 இன்று நீங்கள் என்ன அறிய விரும்புகிறீர்கள்?`,
|
| 56 |
+
bn: (name) =>
|
| 57 |
+
`হ্যালো ${name}! আমি আপনার ক্যারিয়ার গাইডেন্স সহায়ক। আমি এখানে ক্যারিয়ার বিকল্প, বিভিন্ন পেশা এবং শিক্ষাগত পথ সম্পর্কে আপনাকে সাহায্য করতে এসেছি। আজ আপনি কী জানতে চান?`,
|
| 58 |
+
gu: (name) =>
|
| 59 |
+
`નમસ્તે ${name}! હું તમારો કારકિર્દી માર્ગદર્શન સહાયક છું। કારકિર્દી વિકલ્પો, વિવિધ વ્યવસાયો અને શૈક્ષણિક માર્ગો વિશે તમને સહાય કરવા માટે હું અહીં છું. આજે તમે શું જાણવા માંગો છો?`,
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
export function ChatbotPage({
|
| 63 |
+
userProfile,
|
| 64 |
+
setUserProfile,
|
| 65 |
+
navigateTo,
|
| 66 |
+
showResults = false,
|
| 67 |
+
assessmentResults,
|
| 68 |
+
assessmentId,
|
| 69 |
+
}: ChatbotPageProps) {
|
| 70 |
+
const assessmentSummaryForChat = useMemo(() => {
|
| 71 |
+
if (!assessmentResults || !showResults) {
|
| 72 |
+
return null;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
const { recommendations, summary } = assessmentResults;
|
| 76 |
+
const topRecommendations = recommendations
|
| 77 |
+
.map(
|
| 78 |
+
(rec, idx) =>
|
| 79 |
+
`${idx + 1}. ${rec.title} (${Math.round(
|
| 80 |
+
rec.confidence * 100
|
| 81 |
+
)}% match) - ${rec.reason}${
|
| 82 |
+
rec.next_steps?.length
|
| 83 |
+
? `. Next steps: ${rec.next_steps.join(", ")}`
|
| 84 |
+
: ""
|
| 85 |
+
}`
|
| 86 |
+
)
|
| 87 |
+
.join("\n");
|
| 88 |
+
|
| 89 |
+
return `Student: ${userProfile.name || "Student"} (Class ${
|
| 90 |
+
userProfile.class
|
| 91 |
+
})\nSummary: ${summary}\nRecommendations:\n${topRecommendations}`;
|
| 92 |
+
}, [assessmentResults, showResults, userProfile.class, userProfile.name]);
|
| 93 |
+
|
| 94 |
+
const [messages, setMessages] = useState<Message[]>([]);
|
| 95 |
+
const [inputValue, setInputValue] = useState("");
|
| 96 |
+
const [isLimitReached, setIsLimitReached] = useState(false);
|
| 97 |
+
const [isTyping, setIsTyping] = useState(false);
|
| 98 |
+
const [sessionId, setSessionId] = useState<string>(`session_${Date.now()}`);
|
| 99 |
+
const [isInitializing, setIsInitializing] = useState(true);
|
| 100 |
+
const messagesEndRef = useRef<HTMLDivElement>(null);
|
| 101 |
+
|
| 102 |
+
const createLocalInitialMessage = (text?: string): Message => ({
|
| 103 |
+
id: `initial-${Date.now()}-${Math.random()}`,
|
| 104 |
+
text:
|
| 105 |
+
text ||
|
| 106 |
+
fallbackInitialMessages[userProfile.language](userProfile.name || "Student"),
|
| 107 |
+
sender: "bot",
|
| 108 |
+
timestamp: new Date(),
|
| 109 |
+
});
|
| 110 |
+
|
| 111 |
+
// Initialize chat session when component mounts or dependencies change
|
| 112 |
+
useEffect(() => {
|
| 113 |
+
let isMounted = true;
|
| 114 |
+
const initSession = async () => {
|
| 115 |
+
setIsInitializing(true);
|
| 116 |
+
// CRITICAL: Reset messages when assessmentId changes to prevent showing messages from different assessments
|
| 117 |
+
// This ensures we never show stale messages from previous assessments
|
| 118 |
+
setMessages([]);
|
| 119 |
+
|
| 120 |
+
// Log for debugging
|
| 121 |
+
if (assessmentId) {
|
| 122 |
+
console.log(`[ChatbotPage] Initializing chat for assessment ID: ${assessmentId}`);
|
| 123 |
+
} else {
|
| 124 |
+
console.log('[ChatbotPage] Initializing general chat (no assessment ID) - starting fresh');
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
try {
|
| 128 |
+
// IMPORTANT: Only load existing messages if we have a specific assessmentId
|
| 129 |
+
// If no assessmentId, start with a clean chat session (no old messages)
|
| 130 |
+
// This prevents showing random chat history when clicking "Talk with Career Guide"
|
| 131 |
+
if (!assessmentId) {
|
| 132 |
+
// No assessmentId = general chat, start fresh with no old messages
|
| 133 |
+
console.log('[ChatbotPage] No assessmentId provided - starting fresh chat session');
|
| 134 |
+
if (isMounted) {
|
| 135 |
+
setMessages([createLocalInitialMessage()]);
|
| 136 |
+
setIsInitializing(false);
|
| 137 |
+
}
|
| 138 |
+
return;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
// If we have results and assessmentId, try to load existing messages first
|
| 142 |
+
// This avoids regenerating messages that already exist and makes "View Results" instant
|
| 143 |
+
// IMPORTANT: Only load messages for THIS specific assessmentId
|
| 144 |
+
if (showResults && assessmentId && assessmentResults) {
|
| 145 |
+
try {
|
| 146 |
+
// Try to get existing chat history first (fast, no AI generation)
|
| 147 |
+
// Pass assessmentId explicitly to ensure we only get messages for this assessment
|
| 148 |
+
const historyResponse = await assessmentService.getChatHistory(assessmentId);
|
| 149 |
+
const historyData = historyResponse.data;
|
| 150 |
+
|
| 151 |
+
// Check if we have messages in the response (can be array or object with messages property)
|
| 152 |
+
const messagesArray = Array.isArray(historyData) ? historyData : (historyData?.messages || []);
|
| 153 |
+
|
| 154 |
+
// STRICT FILTERING: Only show messages that belong to THIS assessment
|
| 155 |
+
// This is critical - never show messages from other assessments
|
| 156 |
+
const filteredMessages = messagesArray.filter((msg: any) => {
|
| 157 |
+
// If we have an assessmentId, ONLY include messages that match it
|
| 158 |
+
// Reject any message that doesn't have assessment_id or has a different assessment_id
|
| 159 |
+
if (assessmentId) {
|
| 160 |
+
// Message must have assessment_id AND it must match
|
| 161 |
+
if (msg.assessment_id === undefined || msg.assessment_id === null) {
|
| 162 |
+
console.warn('Rejecting message without assessment_id when assessmentId is provided:', msg);
|
| 163 |
+
return false; // Reject messages without assessment_id
|
| 164 |
+
}
|
| 165 |
+
if (msg.assessment_id !== assessmentId) {
|
| 166 |
+
console.warn(`Rejecting message from different assessment. Expected ${assessmentId}, got ${msg.assessment_id}:`, msg);
|
| 167 |
+
return false; // Reject messages from different assessments
|
| 168 |
+
}
|
| 169 |
+
return true; // Only accept if assessment_id matches exactly
|
| 170 |
+
}
|
| 171 |
+
// If no assessmentId, only include messages without assessment_id (general chat)
|
| 172 |
+
return msg.assessment_id === null || msg.assessment_id === undefined;
|
| 173 |
+
});
|
| 174 |
+
|
| 175 |
+
if (filteredMessages.length > 0) {
|
| 176 |
+
const loadedMessages: Message[] = filteredMessages.map((msg: any, index: number) => ({
|
| 177 |
+
id: msg.id || `msg-${Date.now()}-${index}-${Math.random()}`,
|
| 178 |
+
text: msg.message_text || msg.text,
|
| 179 |
+
sender: msg.sender === 'bot' ? 'bot' : 'user',
|
| 180 |
+
timestamp: new Date(msg.created_at || msg.timestamp || Date.now()),
|
| 181 |
+
}));
|
| 182 |
+
if (isMounted) {
|
| 183 |
+
setMessages(loadedMessages);
|
| 184 |
+
setIsInitializing(false);
|
| 185 |
+
return; // Exit early, we have existing messages - instant display!
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
} catch (historyError) {
|
| 189 |
+
// If history fetch fails, continue with normal flow
|
| 190 |
+
console.log("Could not load chat history, continuing with normal flow");
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
// Normal flow: call startChat API
|
| 195 |
+
const response = await assessmentService.startChat({
|
| 196 |
+
sessionId,
|
| 197 |
+
assessmentId: assessmentId || undefined,
|
| 198 |
+
assessmentSummary: assessmentSummaryForChat || undefined,
|
| 199 |
+
language: userProfile.language,
|
| 200 |
+
});
|
| 201 |
+
|
| 202 |
+
const data = response.data;
|
| 203 |
+
|
| 204 |
+
if (isMounted) {
|
| 205 |
+
// Load existing messages from database
|
| 206 |
+
// CRITICAL: STRICTLY filter by assessmentId to prevent loading messages from different assessments
|
| 207 |
+
if (data.existingMessages && data.existingMessages.length > 0) {
|
| 208 |
+
// STRICT FILTERING: Only show messages that belong to THIS assessment
|
| 209 |
+
const filteredMessages = data.existingMessages.filter((msg: any) => {
|
| 210 |
+
// If we have an assessmentId, ONLY include messages that match it exactly
|
| 211 |
+
if (assessmentId) {
|
| 212 |
+
// Reject messages without assessment_id
|
| 213 |
+
if (msg.assessment_id === undefined || msg.assessment_id === null) {
|
| 214 |
+
console.warn('Rejecting message without assessment_id when assessmentId is provided:', msg);
|
| 215 |
+
return false;
|
| 216 |
+
}
|
| 217 |
+
// Reject messages from different assessments
|
| 218 |
+
if (msg.assessment_id !== assessmentId) {
|
| 219 |
+
console.warn(`Rejecting message from different assessment. Expected ${assessmentId}, got ${msg.assessment_id}:`, msg);
|
| 220 |
+
return false;
|
| 221 |
+
}
|
| 222 |
+
return true; // Only accept if assessment_id matches exactly
|
| 223 |
+
}
|
| 224 |
+
// If no assessmentId, only include messages without assessment_id (general chat)
|
| 225 |
+
return msg.assessment_id === null || msg.assessment_id === undefined;
|
| 226 |
+
});
|
| 227 |
+
|
| 228 |
+
const loadedMessages: Message[] = filteredMessages.map((msg: any, index: number) => ({
|
| 229 |
+
id: msg.id || `msg-${Date.now()}-${index}-${Math.random()}`,
|
| 230 |
+
text: msg.text || msg.message_text,
|
| 231 |
+
sender: msg.sender === 'bot' ? 'bot' : 'user',
|
| 232 |
+
timestamp: new Date(msg.timestamp || msg.created_at),
|
| 233 |
+
}));
|
| 234 |
+
setMessages(loadedMessages);
|
| 235 |
+
} else {
|
| 236 |
+
// No existing messages in database response
|
| 237 |
+
// Check if there's an initial message from API, but be cautious:
|
| 238 |
+
// If we have existingMessages from earlier checks, don't show initialMessage from API
|
| 239 |
+
// This prevents showing duplicate initial greetings
|
| 240 |
+
const initialMessageText: string | undefined = data?.initialMessage?.reply;
|
| 241 |
+
|
| 242 |
+
// IMPORTANT: Only show initialMessage if we truly have no existing messages
|
| 243 |
+
// If we loaded messages from history earlier, don't show initialMessage to prevent duplicates
|
| 244 |
+
if (initialMessageText && messages.length === 0) {
|
| 245 |
+
setMessages([{
|
| 246 |
+
id: `initial-${Date.now()}-${Math.random()}`,
|
| 247 |
+
text: initialMessageText,
|
| 248 |
+
sender: 'bot' as const,
|
| 249 |
+
timestamp: new Date(),
|
| 250 |
+
}]);
|
| 251 |
+
} else if (messages.length === 0) {
|
| 252 |
+
// Only show fallback if we have no messages at all
|
| 253 |
+
setMessages([createLocalInitialMessage()]);
|
| 254 |
+
}
|
| 255 |
+
// If messages.length > 0, we already set them above, so don't overwrite
|
| 256 |
+
}
|
| 257 |
+
}
|
| 258 |
+
} catch (error) {
|
| 259 |
+
console.error("Error initializing chat session:", error);
|
| 260 |
+
if (isMounted) {
|
| 261 |
+
setMessages([createLocalInitialMessage()]);
|
| 262 |
+
}
|
| 263 |
+
} finally {
|
| 264 |
+
if (isMounted) {
|
| 265 |
+
setIsInitializing(false);
|
| 266 |
+
}
|
| 267 |
+
}
|
| 268 |
+
};
|
| 269 |
+
|
| 270 |
+
initSession();
|
| 271 |
+
|
| 272 |
+
return () => {
|
| 273 |
+
isMounted = false;
|
| 274 |
+
};
|
| 275 |
+
}, [
|
| 276 |
+
sessionId,
|
| 277 |
+
assessmentId,
|
| 278 |
+
assessmentSummaryForChat,
|
| 279 |
+
userProfile.language,
|
| 280 |
+
showResults,
|
| 281 |
+
assessmentResults, // Add this dependency
|
| 282 |
+
]);
|
| 283 |
+
|
| 284 |
+
const handleLanguageChange = (lang: Language) => {
|
| 285 |
+
setUserProfile({ ...userProfile, language: lang });
|
| 286 |
+
setSessionId(`session_${Date.now()}`);
|
| 287 |
+
setMessages([]);
|
| 288 |
+
};
|
| 289 |
+
|
| 290 |
+
const scrollToBottom = () => {
|
| 291 |
+
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
| 292 |
+
};
|
| 293 |
+
|
| 294 |
+
useEffect(() => {
|
| 295 |
+
scrollToBottom();
|
| 296 |
+
}, [messages]);
|
| 297 |
+
|
| 298 |
+
const handleSendMessage = async () => {
|
| 299 |
+
if (!inputValue.trim() || isLimitReached || isInitializing) return;
|
| 300 |
+
|
| 301 |
+
const userMessageText = inputValue.trim();
|
| 302 |
+
|
| 303 |
+
const userMessageTimestamp = new Date();
|
| 304 |
+
// Generate unique ID - use timestamp + random to ensure uniqueness
|
| 305 |
+
const newId = Date.now() + Math.random();
|
| 306 |
+
|
| 307 |
+
setMessages((prev) => [
|
| 308 |
+
...prev,
|
| 309 |
+
{
|
| 310 |
+
id: newId,
|
| 311 |
+
text: userMessageText,
|
| 312 |
+
sender: "user",
|
| 313 |
+
timestamp: userMessageTimestamp,
|
| 314 |
+
},
|
| 315 |
+
]);
|
| 316 |
+
setInputValue("");
|
| 317 |
+
setIsTyping(true);
|
| 318 |
+
|
| 319 |
+
try {
|
| 320 |
+
// Call backend API
|
| 321 |
+
const response = await assessmentService.sendChatMessage({
|
| 322 |
+
sessionId,
|
| 323 |
+
message: userMessageText,
|
| 324 |
+
language: userProfile.language,
|
| 325 |
+
assessmentId: assessmentId || undefined,
|
| 326 |
+
});
|
| 327 |
+
|
| 328 |
+
const data = response.data;
|
| 329 |
+
|
| 330 |
+
const botMessageTimestamp = new Date();
|
| 331 |
+
// Generate unique ID - use timestamp + random to ensure uniqueness
|
| 332 |
+
const newId = Date.now() + Math.random();
|
| 333 |
+
|
| 334 |
+
setMessages((prev) => [
|
| 335 |
+
...prev,
|
| 336 |
+
{
|
| 337 |
+
id: newId,
|
| 338 |
+
text: data.reply,
|
| 339 |
+
sender: "bot",
|
| 340 |
+
timestamp: botMessageTimestamp,
|
| 341 |
+
},
|
| 342 |
+
]);
|
| 343 |
+
} catch (error) {
|
| 344 |
+
console.error("Error sending message:", error);
|
| 345 |
+
|
| 346 |
+
// Fallback response
|
| 347 |
+
setMessages((prev) => [
|
| 348 |
+
...prev,
|
| 349 |
+
{
|
| 350 |
+
id: prev.length + 1,
|
| 351 |
+
text: connectionErrorMessages[userProfile.language],
|
| 352 |
+
sender: "bot",
|
| 353 |
+
timestamp: new Date(),
|
| 354 |
+
},
|
| 355 |
+
]);
|
| 356 |
+
setIsLimitReached(true);
|
| 357 |
+
} finally {
|
| 358 |
+
setIsTyping(false);
|
| 359 |
+
}
|
| 360 |
+
};
|
| 361 |
+
|
| 362 |
+
const handleKeyPress = (e: React.KeyboardEvent) => {
|
| 363 |
+
if (e.key === "Enter" && !e.shiftKey) {
|
| 364 |
+
e.preventDefault();
|
| 365 |
+
handleSendMessage();
|
| 366 |
+
}
|
| 367 |
+
};
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
return (
|
| 371 |
+
<div className="min-h-screen flex flex-col">
|
| 372 |
+
{/* Header */}
|
| 373 |
+
<header className="bg-white shadow-sm border-b sticky top-0 z-10">
|
| 374 |
+
<div className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-4">
|
| 375 |
+
<div className="flex items-center gap-4">
|
| 376 |
+
<Button
|
| 377 |
+
variant="ghost"
|
| 378 |
+
size="icon"
|
| 379 |
+
onClick={() => {
|
| 380 |
+
// If we have an assessmentId, we came from assessment history, so go back there
|
| 381 |
+
// Otherwise, go to home
|
| 382 |
+
if (assessmentId) {
|
| 383 |
+
navigateTo("assessment-history");
|
| 384 |
+
} else {
|
| 385 |
+
navigateTo("home");
|
| 386 |
+
}
|
| 387 |
+
}}
|
| 388 |
+
>
|
| 389 |
+
<ArrowLeft className="h-5 w-5" />
|
| 390 |
+
</Button>
|
| 391 |
+
<div className="flex items-center gap-3 flex-1">
|
| 392 |
+
<div className="bg-gradient-to-br from-blue-500 to-purple-500 p-2 rounded-xl">
|
| 393 |
+
<Bot className="h-6 w-6 text-white" />
|
| 394 |
+
</div>
|
| 395 |
+
<div>
|
| 396 |
+
<h2 className="text-gray-900">Career Guide</h2>
|
| 397 |
+
<p className="text-green-600 text-sm">● Online</p>
|
| 398 |
+
</div>
|
| 399 |
+
</div>
|
| 400 |
+
<LanguageSelector
|
| 401 |
+
language={userProfile.language}
|
| 402 |
+
onLanguageChange={handleLanguageChange}
|
| 403 |
+
/>
|
| 404 |
+
</div>
|
| 405 |
+
</div>
|
| 406 |
+
</header>
|
| 407 |
+
|
| 408 |
+
{/* Chat Messages */}
|
| 409 |
+
<main className="flex-1 overflow-y-auto bg-gradient-to-br from-blue-50 via-white to-purple-50">
|
| 410 |
+
<div className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-6 space-y-4">
|
| 411 |
+
{isInitializing && messages.length === 0 && (
|
| 412 |
+
<div className="flex justify-start">
|
| 413 |
+
<Card className="p-4 bg-white shadow animate-pulse max-w-[70%]">
|
| 414 |
+
<p className="text-sm text-gray-600">
|
| 415 |
+
Preparing your personalized summary...
|
| 416 |
+
</p>
|
| 417 |
+
</Card>
|
| 418 |
+
</div>
|
| 419 |
+
)}
|
| 420 |
+
{messages.map((message) => (
|
| 421 |
+
<div
|
| 422 |
+
key={message.id}
|
| 423 |
+
className={`flex gap-3 ${
|
| 424 |
+
message.sender === "user" ? "flex-row-reverse" : "flex-row"
|
| 425 |
+
}`}
|
| 426 |
+
>
|
| 427 |
+
<Avatar className="h-8 w-8 shrink-0">
|
| 428 |
+
<AvatarFallback
|
| 429 |
+
className={
|
| 430 |
+
message.sender === "bot"
|
| 431 |
+
? "bg-gradient-to-br from-blue-500 to-purple-500 text-white"
|
| 432 |
+
: "bg-gray-300"
|
| 433 |
+
}
|
| 434 |
+
>
|
| 435 |
+
{message.sender === "bot" ? (
|
| 436 |
+
<Bot className="h-4 w-4" />
|
| 437 |
+
) : (
|
| 438 |
+
<User className="h-4 w-4" />
|
| 439 |
+
)}
|
| 440 |
+
</AvatarFallback>
|
| 441 |
+
</Avatar>
|
| 442 |
+
<div
|
| 443 |
+
className={`flex flex-col max-w-[70%] ${
|
| 444 |
+
message.sender === "user" ? "items-end" : "items-start"
|
| 445 |
+
}`}
|
| 446 |
+
>
|
| 447 |
+
<Card
|
| 448 |
+
className={`p-3 ${
|
| 449 |
+
message.sender === "user"
|
| 450 |
+
? "bg-blue-600 text-white border-blue-600"
|
| 451 |
+
: "bg-white"
|
| 452 |
+
}`}
|
| 453 |
+
>
|
| 454 |
+
<p
|
| 455 |
+
className="text-sm whitespace-pre-wrap"
|
| 456 |
+
dangerouslySetInnerHTML={{
|
| 457 |
+
__html: (() => {
|
| 458 |
+
let html = message.text;
|
| 459 |
+
// Convert markdown bold (**text**) to HTML bold first
|
| 460 |
+
// Use non-greedy matching to handle multiple bold sections
|
| 461 |
+
html = html.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>');
|
| 462 |
+
// Convert newlines to <br /> (after bold conversion to avoid breaking tags)
|
| 463 |
+
html = html.replace(/\n/g, '<br />');
|
| 464 |
+
return html;
|
| 465 |
+
})()
|
| 466 |
+
}}
|
| 467 |
+
/>
|
| 468 |
+
</Card>
|
| 469 |
+
<span className="text-xs text-gray-500 mt-1">
|
| 470 |
+
{message.timestamp.toLocaleTimeString([], {
|
| 471 |
+
hour: "2-digit",
|
| 472 |
+
minute: "2-digit",
|
| 473 |
+
})}
|
| 474 |
+
</span>
|
| 475 |
+
</div>
|
| 476 |
+
</div>
|
| 477 |
+
))}
|
| 478 |
+
|
| 479 |
+
{/* Typing Indicator */}
|
| 480 |
+
{isTyping && (
|
| 481 |
+
<div className="flex gap-3 flex-row">
|
| 482 |
+
<Avatar className="h-8 w-8 shrink-0">
|
| 483 |
+
<AvatarFallback className="bg-gradient-to-br from-blue-500 to-purple-500 text-white">
|
| 484 |
+
<Bot className="h-4 w-4" />
|
| 485 |
+
</AvatarFallback>
|
| 486 |
+
</Avatar>
|
| 487 |
+
<div className="flex flex-col max-w-[70%] items-start">
|
| 488 |
+
<Card className="p-3 bg-white">
|
| 489 |
+
<div className="flex gap-1 items-center">
|
| 490 |
+
<span className="text-sm text-gray-600">typing</span>
|
| 491 |
+
<div className="flex gap-1">
|
| 492 |
+
<span
|
| 493 |
+
className="w-1.5 h-1.5 bg-gray-400 rounded-full animate-bounce"
|
| 494 |
+
style={{ animationDelay: "0ms" }}
|
| 495 |
+
></span>
|
| 496 |
+
<span
|
| 497 |
+
className="w-1.5 h-1.5 bg-gray-400 rounded-full animate-bounce"
|
| 498 |
+
style={{ animationDelay: "150ms" }}
|
| 499 |
+
></span>
|
| 500 |
+
<span
|
| 501 |
+
className="w-1.5 h-1.5 bg-gray-400 rounded-full animate-bounce"
|
| 502 |
+
style={{ animationDelay: "300ms" }}
|
| 503 |
+
></span>
|
| 504 |
+
</div>
|
| 505 |
+
</div>
|
| 506 |
+
</Card>
|
| 507 |
+
</div>
|
| 508 |
+
</div>
|
| 509 |
+
)}
|
| 510 |
+
|
| 511 |
+
<div ref={messagesEndRef} />
|
| 512 |
+
</div>
|
| 513 |
+
</main>
|
| 514 |
+
|
| 515 |
+
{/* Input Area */}
|
| 516 |
+
<div className="bg-white border-t sticky bottom-0">
|
| 517 |
+
<div className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-4">
|
| 518 |
+
{isLimitReached && (
|
| 519 |
+
<Alert className="mb-4 border-red-200 bg-red-50">
|
| 520 |
+
<AlertCircle className="h-4 w-4 text-red-600" />
|
| 521 |
+
<AlertDescription className="text-red-800 text-sm">
|
| 522 |
+
⚠️ {connectionErrorMessages[userProfile.language]}
|
| 523 |
+
</AlertDescription>
|
| 524 |
+
</Alert>
|
| 525 |
+
)}
|
| 526 |
+
<div className="flex gap-3">
|
| 527 |
+
<Textarea
|
| 528 |
+
value={inputValue}
|
| 529 |
+
onChange={(e) => setInputValue(e.target.value)}
|
| 530 |
+
onKeyPress={handleKeyPress}
|
| 531 |
+
placeholder={
|
| 532 |
+
isLimitReached
|
| 533 |
+
? "Connection failed..."
|
| 534 |
+
: isInitializing
|
| 535 |
+
? "Preparing your personalized recommendations..."
|
| 536 |
+
: "Type your question here..."
|
| 537 |
+
}
|
| 538 |
+
className="resize-none min-h-[60px]"
|
| 539 |
+
rows={2}
|
| 540 |
+
disabled={isLimitReached || isInitializing}
|
| 541 |
+
/>
|
| 542 |
+
<Button
|
| 543 |
+
onClick={handleSendMessage}
|
| 544 |
+
className="bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700 shrink-0"
|
| 545 |
+
size="icon"
|
| 546 |
+
disabled={isLimitReached || isInitializing}
|
| 547 |
+
>
|
| 548 |
+
<Send className="h-5 w-5" />
|
| 549 |
+
</Button>
|
| 550 |
+
</div>
|
| 551 |
+
{!isLimitReached && (
|
| 552 |
+
<p className="text-xs text-gray-500 mt-2 text-center">
|
| 553 |
+
Press Enter to send, Shift+Enter for new line
|
| 554 |
+
</p>
|
| 555 |
+
)}
|
| 556 |
+
</div>
|
| 557 |
+
</div>
|
| 558 |
+
</div>
|
| 559 |
+
);
|
| 560 |
+
}
|
frontend/src/components/HomePage.tsx
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { GraduationCap, MessageCircle, ClipboardList, User, Settings, LogOut } from 'lucide-react';
|
| 2 |
+
import { Button } from './ui/button';
|
| 3 |
+
import { Progress } from './ui/progress';
|
| 4 |
+
import { Avatar, AvatarFallback } from './ui/avatar';
|
| 5 |
+
import { Card, CardContent } from './ui/card';
|
| 6 |
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from './ui/dropdown-menu';
|
| 7 |
+
import { LanguageSelector } from './LanguageSelector';
|
| 8 |
+
import type { Page, UserProfile, Language, SavedAssessment, CompletedAssessment } from '../App';
|
| 9 |
+
|
| 10 |
+
interface HomePageProps {
|
| 11 |
+
userProfile: UserProfile;
|
| 12 |
+
setUserProfile: (profile: UserProfile) => void;
|
| 13 |
+
navigateTo: (page: Page) => void;
|
| 14 |
+
savedAssessment: SavedAssessment | null;
|
| 15 |
+
completedAssessments: CompletedAssessment[];
|
| 16 |
+
startAssessmentFlow: () => void;
|
| 17 |
+
onLogout: () => void;
|
| 18 |
+
isGuestMode?: boolean;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
const languages = {
|
| 22 |
+
en: 'English',
|
| 23 |
+
hi: 'हिंदी',
|
| 24 |
+
te: 'తెలుగు',
|
| 25 |
+
ta: 'தமிழ்',
|
| 26 |
+
bn: 'বাংলা',
|
| 27 |
+
gu: 'ગુજરાતી'
|
| 28 |
+
};
|
| 29 |
+
|
| 30 |
+
const translations = {
|
| 31 |
+
en: {
|
| 32 |
+
title: 'PathFinder',
|
| 33 |
+
subtitle: 'Your Career Guidance Companion',
|
| 34 |
+
welcome: 'Welcome back',
|
| 35 |
+
progress: 'Your Progress',
|
| 36 |
+
complete: 'Complete',
|
| 37 |
+
quickActions: 'Quick Actions',
|
| 38 |
+
chatbot: 'Talk to Career Guide',
|
| 39 |
+
chatbotDesc: 'Get instant answers to your career questions',
|
| 40 |
+
takeTest: 'Take Assessment',
|
| 41 |
+
takeTestDesc: 'Discover your strengths and interests',
|
| 42 |
+
viewResults: 'Previous Assessments',
|
| 43 |
+
viewResultsDesc: 'View your completed assessments',
|
| 44 |
+
language: 'Language',
|
| 45 |
+
settings: 'Settings',
|
| 46 |
+
logout: 'Logout',
|
| 47 |
+
noAssessments: 'No assessments completed yet',
|
| 48 |
+
pendingAssessment: 'Pending Assessment',
|
| 49 |
+
assessment: 'Assessment',
|
| 50 |
+
continue: 'Continue'
|
| 51 |
+
},
|
| 52 |
+
hi: {
|
| 53 |
+
title: 'पाथफाइंडर',
|
| 54 |
+
subtitle: 'आपका करियर मार्गदर्शन साथी',
|
| 55 |
+
welcome: 'वापसी पर स्वागत है',
|
| 56 |
+
progress: 'आपकी प्रगति',
|
| 57 |
+
complete: 'पूर्ण',
|
| 58 |
+
quickActions: 'त्वरित कार्य',
|
| 59 |
+
chatbot: 'करियर गाइड से बात करें',
|
| 60 |
+
chatbotDesc: 'अपने करियर प्रश्नों के तुरंत उत्तर पाएं',
|
| 61 |
+
takeTest: 'मूल्यांकन लें',
|
| 62 |
+
takeTestDesc: 'अपनी शक्तियों और रुचियों की खोज करें',
|
| 63 |
+
viewResults: 'पिछले मूल्यांकन',
|
| 64 |
+
viewResultsDesc: 'अपने पूर्ण मूल्यांकन देखें',
|
| 65 |
+
language: 'भाषा',
|
| 66 |
+
settings: 'सेटिंग्स',
|
| 67 |
+
logout: 'लॉगआउट',
|
| 68 |
+
noAssessments: 'अभी तक कोई मूल्यांकन पूर्ण नहीं',
|
| 69 |
+
pendingAssessment: 'लंबित मूल्यांकन',
|
| 70 |
+
assessment: 'मूल्यांकन',
|
| 71 |
+
continue: 'जारी रखें'
|
| 72 |
+
},
|
| 73 |
+
te: {
|
| 74 |
+
title: 'పాత్ఫైండర్',
|
| 75 |
+
subtitle: 'మీ కెరీర్ మార్గదర్శక సహచరుడు',
|
| 76 |
+
welcome: 'తిరిగి స్వాగతం',
|
| 77 |
+
progress: 'మీ పురోగతి',
|
| 78 |
+
complete: 'పూర్తి',
|
| 79 |
+
quickActions: 'శీఘ్ర చర్యలు',
|
| 80 |
+
chatbot: 'కెరీర్ గైడ్తో మాట్లాడండి',
|
| 81 |
+
chatbotDesc: 'మీ కెరీర్ ప్రశ్నలకు తక్షణ సమాధానాలు పొందండి',
|
| 82 |
+
takeTest: 'అసెస్మెంట్ తీసుకోండి',
|
| 83 |
+
takeTestDesc: 'మీ బలాలు మరియు ఆసక్తులను కనుగొనండి',
|
| 84 |
+
viewResults: 'మునుపటి అసెస్మెంట్లు',
|
| 85 |
+
viewResultsDesc: 'మీ పూర్తి అసెస్మెంట్లను చూడండి',
|
| 86 |
+
language: 'భాష',
|
| 87 |
+
settings: 'సెట్టింగ్లు',
|
| 88 |
+
logout: 'లాగౌట్',
|
| 89 |
+
noAssessments: 'ఇంకా అసెస్మెంట్లు పూర్తి కాలేదు',
|
| 90 |
+
pendingAssessment: 'పెండింగ్ అసెస్మెంట్',
|
| 91 |
+
assessment: 'అసెస్మెంట్',
|
| 92 |
+
continue: 'కొనసాగించండి'
|
| 93 |
+
},
|
| 94 |
+
ta: {
|
| 95 |
+
title: 'பாத்ஃபைண்டர்',
|
| 96 |
+
subtitle: 'உங்கள் தொழில் வழிகாட்டி துணை',
|
| 97 |
+
welcome: 'மீண்டும் வரவேற்கிறோம்',
|
| 98 |
+
progress: 'உங்கள் முன்னேற்றம்',
|
| 99 |
+
complete: 'முழுமை',
|
| 100 |
+
quickActions: 'விரைவு செயல்கள்',
|
| 101 |
+
chatbot: 'தொழில் வழிகாட்டியுடன் பேசுங்கள்',
|
| 102 |
+
chatbotDesc: 'உங்கள் தொழில் கேள���விகளுக்கு உடனடி பதில்களைப் பெறுங்கள்',
|
| 103 |
+
takeTest: 'மதிப்பீடு எடுங்கள்',
|
| 104 |
+
takeTestDesc: 'உங்கள் பலம் மற்றும் ஆர்வங்களைக் கண்டறியுங்கள்',
|
| 105 |
+
viewResults: 'முந்தைய மதிப்பீடுகள்',
|
| 106 |
+
viewResultsDesc: 'முடிந்த மதிப்பீடுகளைப் பார்க்கவும்',
|
| 107 |
+
language: 'மொழி',
|
| 108 |
+
settings: 'அமைப்புகள்',
|
| 109 |
+
logout: 'வெளியேறு',
|
| 110 |
+
noAssessments: 'இன்னும் மதிப்பீடுகள் முடிக்கப்படவில்லை',
|
| 111 |
+
pendingAssessment: 'நிலுவையில் உள்ள மதிப்பீடு',
|
| 112 |
+
assessment: 'மதிப்பீடு',
|
| 113 |
+
continue: 'தொடரவும்'
|
| 114 |
+
},
|
| 115 |
+
bn: {
|
| 116 |
+
title: 'পাথফাইন্ডার',
|
| 117 |
+
subtitle: 'আপনার ক্যারিয়ার গাইডেন্স সঙ্গী',
|
| 118 |
+
welcome: 'আবার স্বাগতম',
|
| 119 |
+
progress: 'আপনার অগ্রগতি',
|
| 120 |
+
complete: 'সম্পূর্ণ',
|
| 121 |
+
quickActions: 'দ্রুত কর্ম',
|
| 122 |
+
chatbot: 'ক্যারিয়ার গাইডের সাথে কথা বলুন',
|
| 123 |
+
chatbotDesc: 'আপনার ক্যারিয়ার প্রশ্নের তাৎক্ষণিক উত্তর পান',
|
| 124 |
+
takeTest: 'মূল্যায়ন নিন',
|
| 125 |
+
takeTestDesc: 'আপনার শক্তি এবং আগ্রহ আবিষ্কার করুন',
|
| 126 |
+
viewResults: 'পূর্ববর্তী মূল্যায়ন',
|
| 127 |
+
viewResultsDesc: 'সম্পূর্ণ মূল্যায়ন দেখুন',
|
| 128 |
+
language: 'ভাষা',
|
| 129 |
+
settings: 'সেটিংস',
|
| 130 |
+
logout: 'লগআউট',
|
| 131 |
+
noAssessments: 'এখনও কোন মূল্যায়ন সম্পূর্ণ হয়নি',
|
| 132 |
+
pendingAssessment: 'মুলতুবি মূল্যায়ন',
|
| 133 |
+
assessment: 'মূল্যায়ন',
|
| 134 |
+
continue: 'চালিয়ে যান'
|
| 135 |
+
},
|
| 136 |
+
gu: {
|
| 137 |
+
title: 'પાથફાઇન્ડર',
|
| 138 |
+
subtitle: 'તમારા કારકિર્દી માર્ગદર્શક સાથી',
|
| 139 |
+
welcome: 'ફરીથી સ્વાગત છે',
|
| 140 |
+
progress: 'તમારી પ્રગતિ',
|
| 141 |
+
complete: 'પૂર્ણ',
|
| 142 |
+
quickActions: 'ઝડપી ક્રિયાઓ',
|
| 143 |
+
chatbot: 'કારકિર્દી માર્ગદર્શક સાથે વાત કરો',
|
| 144 |
+
chatbotDesc: 'તમારા કારકિર્દી પ્રશ્નોના તાત્કાલિક જવાબો મેળવો',
|
| 145 |
+
takeTest: 'મૂલ્યાંકન લો',
|
| 146 |
+
takeTestDesc: 'તમારી શક્તિઓ અને રુચિઓ શોધો',
|
| 147 |
+
viewResults: 'અગાઉના મૂલ્યાંકનો',
|
| 148 |
+
viewResultsDesc: 'તમારા પૂર્ણ મૂલ્યાંકનો જુઓ',
|
| 149 |
+
language: 'ભાષા',
|
| 150 |
+
settings: 'સેટિંગ્સ',
|
| 151 |
+
logout: 'લૉગઆઉટ',
|
| 152 |
+
noAssessments: 'હજી સુધી કોઈ મૂલ્યાંકન પૂર્ણ થયું નથી',
|
| 153 |
+
pendingAssessment: 'પેન્ડિંગ મૂલ્યાંકન',
|
| 154 |
+
assessment: 'મૂલ્યાંકન',
|
| 155 |
+
continue: 'ચાલુ રાખો'
|
| 156 |
+
}
|
| 157 |
+
};
|
| 158 |
+
|
| 159 |
+
const testTitles: { [key: string]: string } = {
|
| 160 |
+
riasec: 'RIASEC Personality Assessment',
|
| 161 |
+
values: 'Values & Motivation',
|
| 162 |
+
personal: 'Personal Information'
|
| 163 |
+
};
|
| 164 |
+
|
| 165 |
+
export function HomePage({ userProfile, setUserProfile, navigateTo, savedAssessment, completedAssessments, startAssessmentFlow, onLogout, isGuestMode = false }: HomePageProps) {
|
| 166 |
+
const t = translations[userProfile.language];
|
| 167 |
+
|
| 168 |
+
const handleLanguageChange = (lang: Language) => {
|
| 169 |
+
setUserProfile({ ...userProfile, language: lang });
|
| 170 |
+
};
|
| 171 |
+
|
| 172 |
+
return (
|
| 173 |
+
<div className="min-h-screen">
|
| 174 |
+
{/* Header */}
|
| 175 |
+
<header className="bg-white shadow-sm border-b">
|
| 176 |
+
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4">
|
| 177 |
+
<div className="flex items-center justify-between">
|
| 178 |
+
<div className="flex items-center gap-3">
|
| 179 |
+
<div className="bg-gradient-to-br from-blue-600 to-purple-600 p-2 rounded-xl">
|
| 180 |
+
<GraduationCap className="h-8 w-8 text-white" />
|
| 181 |
+
</div>
|
| 182 |
+
<div>
|
| 183 |
+
<h1 className="text-blue-900">CareerBuddy</h1>
|
| 184 |
+
<p className="text-gray-600 text-sm">Your Career Guidance Companion</p>
|
| 185 |
+
</div>
|
| 186 |
+
</div>
|
| 187 |
+
|
| 188 |
+
<div className="flex items-center gap-4">
|
| 189 |
+
<LanguageSelector
|
| 190 |
+
language={userProfile.language}
|
| 191 |
+
onLanguageChange={handleLanguageChange}
|
| 192 |
+
/>
|
| 193 |
+
|
| 194 |
+
<DropdownMenu>
|
| 195 |
+
<DropdownMenuTrigger asChild>
|
| 196 |
+
<button className="rounded-full focus:outline-none focus:ring-2 focus:ring-purple-400 focus:ring-offset-2">
|
| 197 |
+
<Avatar className="h-10 w-10 cursor-pointer border-2 border-purple-200 hover:border-purple-400 transition-colors">
|
| 198 |
+
<AvatarFallback className="bg-gradient-to-br from-blue-500 to-purple-500 text-white">
|
| 199 |
+
{userProfile.name.charAt(0).toUpperCase()}
|
| 200 |
+
</AvatarFallback>
|
| 201 |
+
</Avatar>
|
| 202 |
+
</button>
|
| 203 |
+
</DropdownMenuTrigger>
|
| 204 |
+
<DropdownMenuContent align="end" className="w-48">
|
| 205 |
+
<DropdownMenuItem className="cursor-pointer" onClick={() => navigateTo('settings')}>
|
| 206 |
+
<Settings className="h-4 w-4 mr-2" />
|
| 207 |
+
{t.settings}
|
| 208 |
+
</DropdownMenuItem>
|
| 209 |
+
<DropdownMenuItem className="cursor-pointer" onClick={onLogout}>
|
| 210 |
+
<LogOut className="h-4 w-4 mr-2" />
|
| 211 |
+
{t.logout}
|
| 212 |
+
</DropdownMenuItem>
|
| 213 |
+
</DropdownMenuContent>
|
| 214 |
+
</DropdownMenu>
|
| 215 |
+
</div>
|
| 216 |
+
</div>
|
| 217 |
+
</div>
|
| 218 |
+
</header>
|
| 219 |
+
|
| 220 |
+
{/* Main Content */}
|
| 221 |
+
<main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
| 222 |
+
{/* Welcome Section */}
|
| 223 |
+
<div className="mb-8">
|
| 224 |
+
<h2 className="text-gray-900 mb-2">
|
| 225 |
+
{isGuestMode ? `${t.welcome}! 👋` : `${t.welcome}, ${userProfile.name}! 👋`}
|
| 226 |
+
</h2>
|
| 227 |
+
</div>
|
| 228 |
+
|
| 229 |
+
{/* Progress Card - Only show if there's a saved assessment */}
|
| 230 |
+
{savedAssessment && (
|
| 231 |
+
<Card className="mb-8 border-2 border-purple-100 shadow-lg">
|
| 232 |
+
<CardContent className="pt-6">
|
| 233 |
+
<div className="flex items-center justify-between mb-4">
|
| 234 |
+
<div>
|
| 235 |
+
<h3 className="text-gray-900">{t.pendingAssessment}</h3>
|
| 236 |
+
<p className="text-gray-600 text-sm mt-1">
|
| 237 |
+
Complete Assessment - Continue where you left off
|
| 238 |
+
</p>
|
| 239 |
+
</div>
|
| 240 |
+
<div className="text-right">
|
| 241 |
+
<div className="text-purple-600">{Math.round(savedAssessment.overallProgress ?? savedAssessment.progress)}%</div>
|
| 242 |
+
<div className="text-gray-500 text-sm">{t.complete}</div>
|
| 243 |
+
</div>
|
| 244 |
+
</div>
|
| 245 |
+
<Progress value={savedAssessment.overallProgress ?? savedAssessment.progress} className="h-3 mb-4" />
|
| 246 |
+
<Button
|
| 247 |
+
onClick={startAssessmentFlow}
|
| 248 |
+
className="w-full bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700 text-white"
|
| 249 |
+
>
|
| 250 |
+
{t.continue}
|
| 251 |
+
</Button>
|
| 252 |
+
</CardContent>
|
| 253 |
+
</Card>
|
| 254 |
+
)}
|
| 255 |
+
|
| 256 |
+
{/* Quick Actions */}
|
| 257 |
+
<div className="mb-6">
|
| 258 |
+
<h3 className="text-gray-900 mb-4">{t.quickActions}</h3>
|
| 259 |
+
</div>
|
| 260 |
+
|
| 261 |
+
<div className="grid md:grid-cols-3 gap-6">
|
| 262 |
+
{/* Chatbot Card */}
|
| 263 |
+
<Card
|
| 264 |
+
className="cursor-pointer hover:shadow-xl transition-all border-2 border-transparent hover:border-blue-300 group"
|
| 265 |
+
onClick={() => navigateTo('chatbot')}
|
| 266 |
+
>
|
| 267 |
+
<CardContent className="pt-6">
|
| 268 |
+
<div className="flex flex-col items-center text-center">
|
| 269 |
+
<div className="bg-blue-100 p-4 rounded-2xl mb-4 group-hover:bg-blue-200 transition-colors">
|
| 270 |
+
<MessageCircle className="h-10 w-10 text-blue-600" />
|
| 271 |
+
</div>
|
| 272 |
+
<h3 className="text-gray-900 mb-2">{t.chatbot}</h3>
|
| 273 |
+
<p className="text-gray-600 text-sm">{t.chatbotDesc}</p>
|
| 274 |
+
</div>
|
| 275 |
+
</CardContent>
|
| 276 |
+
</Card>
|
| 277 |
+
|
| 278 |
+
{/* Take Test Card */}
|
| 279 |
+
<Card
|
| 280 |
+
className="cursor-pointer hover:shadow-xl transition-all border-2 border-transparent hover:border-purple-300 group"
|
| 281 |
+
onClick={startAssessmentFlow}
|
| 282 |
+
>
|
| 283 |
+
<CardContent className="pt-6">
|
| 284 |
+
<div className="flex flex-col items-center text-center">
|
| 285 |
+
<div className="bg-purple-100 p-4 rounded-2xl mb-4 group-hover:bg-purple-200 transition-colors">
|
| 286 |
+
<ClipboardList className="h-10 w-10 text-purple-600" />
|
| 287 |
+
</div>
|
| 288 |
+
<h3 className="text-gray-900 mb-2">{t.takeTest}</h3>
|
| 289 |
+
<p className="text-gray-600 text-sm">{t.takeTestDesc}</p>
|
| 290 |
+
</div>
|
| 291 |
+
</CardContent>
|
| 292 |
+
</Card>
|
| 293 |
+
|
| 294 |
+
{/* Previous Assessments Card */}
|
| 295 |
+
<Card
|
| 296 |
+
className="cursor-pointer hover:shadow-xl transition-all border-2 border-transparent hover:border-green-300 group"
|
| 297 |
+
onClick={() => completedAssessments.length > 0 && navigateTo('assessment-history')}
|
| 298 |
+
>
|
| 299 |
+
<CardContent className="pt-6">
|
| 300 |
+
<div className="flex flex-col items-center text-center">
|
| 301 |
+
<div className="bg-green-100 p-4 rounded-2xl mb-4 group-hover:bg-green-200 transition-colors">
|
| 302 |
+
<User className="h-10 w-10 text-green-600" />
|
| 303 |
+
</div>
|
| 304 |
+
<h3 className="text-gray-900 mb-2">{t.viewResults}</h3>
|
| 305 |
+
<p className="text-gray-600 text-sm mb-4">{t.viewResultsDesc}</p>
|
| 306 |
+
|
| 307 |
+
{completedAssessments.length > 0 ? (
|
| 308 |
+
<div className="bg-blue-50 px-4 py-2 rounded-full">
|
| 309 |
+
<span className="text-blue-700">{completedAssessments.length} {completedAssessments.length === 1 ? t.assessment : t.viewResults}</span>
|
| 310 |
+
</div>
|
| 311 |
+
) : (
|
| 312 |
+
<p className="text-xs text-gray-500">{t.noAssessments}</p>
|
| 313 |
+
)}
|
| 314 |
+
</div>
|
| 315 |
+
</CardContent>
|
| 316 |
+
</Card>
|
| 317 |
+
</div>
|
| 318 |
+
</main>
|
| 319 |
+
</div>
|
| 320 |
+
);
|
| 321 |
+
}
|
frontend/src/components/LanguageSelector.tsx
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Globe } from 'lucide-react';
|
| 2 |
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './ui/select';
|
| 3 |
+
import type { Language } from '../App';
|
| 4 |
+
|
| 5 |
+
interface LanguageSelectorProps {
|
| 6 |
+
language: Language;
|
| 7 |
+
onLanguageChange: (lang: Language) => void;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
const languages = {
|
| 11 |
+
en: 'English',
|
| 12 |
+
hi: 'हिंदी',
|
| 13 |
+
te: 'తెలుగు',
|
| 14 |
+
ta: 'தமிழ்',
|
| 15 |
+
bn: 'বাংলা',
|
| 16 |
+
gu: 'ગુજરાતી'
|
| 17 |
+
};
|
| 18 |
+
|
| 19 |
+
export function LanguageSelector({ language, onLanguageChange }: LanguageSelectorProps) {
|
| 20 |
+
return (
|
| 21 |
+
<Select value={language} onValueChange={onLanguageChange}>
|
| 22 |
+
<SelectTrigger className="w-[140px]">
|
| 23 |
+
<Globe className="h-4 w-4 mr-2" />
|
| 24 |
+
<SelectValue />
|
| 25 |
+
</SelectTrigger>
|
| 26 |
+
<SelectContent>
|
| 27 |
+
{Object.entries(languages).map(([code, name]) => (
|
| 28 |
+
<SelectItem key={code} value={code}>
|
| 29 |
+
{name}
|
| 30 |
+
</SelectItem>
|
| 31 |
+
))}
|
| 32 |
+
</SelectContent>
|
| 33 |
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState, useRef, useEffect } from 'react';
|
| 2 |
+
import { GraduationCap, LogIn, UserPlus } from 'lucide-react';
|
| 3 |
+
import { Button } from './ui/button';
|
| 4 |
+
import { Input } from './ui/input';
|
| 5 |
+
import { Label } from './ui/label';
|
| 6 |
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from './ui/card';
|
| 7 |
+
import { LanguageSelector } from './LanguageSelector';
|
| 8 |
+
import { authService } from '../services/authService';
|
| 9 |
+
import { toast } from 'sonner';
|
| 10 |
+
import type { Page, UserProfile, Language } from '../App';
|
| 11 |
+
|
| 12 |
+
interface LoginPageProps {
|
| 13 |
+
userProfile: UserProfile;
|
| 14 |
+
setUserProfile: (profile: UserProfile) => void;
|
| 15 |
+
navigateTo: (page: Page) => void;
|
| 16 |
+
onLoginComplete: () => void;
|
| 17 |
+
onShowSignup: () => void;
|
| 18 |
+
onGuestMode: () => void;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
const translations = {
|
| 22 |
+
en: {
|
| 23 |
+
welcomeBack: 'Welcome Back',
|
| 24 |
+
subtitle: 'Sign in to continue your career journey',
|
| 25 |
+
username: 'Username',
|
| 26 |
+
usernamePlaceholder: 'Enter your username',
|
| 27 |
+
password: 'Password',
|
| 28 |
+
passwordPlaceholder: 'Enter your password',
|
| 29 |
+
signIn: 'Sign In',
|
| 30 |
+
signingIn: 'Signing in...',
|
| 31 |
+
noAccount: "Don't have an account?",
|
| 32 |
+
createAccount: 'Create New Account',
|
| 33 |
+
continueAsGuest: 'Continue as Guest',
|
| 34 |
+
usernameRequired: 'Username is required',
|
| 35 |
+
passwordRequired: 'Password is required',
|
| 36 |
+
invalidCredentials: 'Invalid username or password',
|
| 37 |
+
loginSuccess: 'Logged in successfully!',
|
| 38 |
+
loginFailed: 'Failed to login'
|
| 39 |
+
},
|
| 40 |
+
hi: {
|
| 41 |
+
welcomeBack: 'वापसी पर स्वागत है',
|
| 42 |
+
subtitle: 'अपनी करियर यात्रा जारी रखने के लिए साइन इन करें',
|
| 43 |
+
username: 'उपयोगकर्ता नाम',
|
| 44 |
+
usernamePlaceholder: 'अपना उपयोगकर्ता नाम दर्ज करें',
|
| 45 |
+
password: 'पासवर्ड',
|
| 46 |
+
passwordPlaceholder: 'अपना पासवर्ड दर्ज करें',
|
| 47 |
+
signIn: 'साइन इन करें',
|
| 48 |
+
signingIn: 'साइन इन हो रहा है...',
|
| 49 |
+
noAccount: 'खाता नहीं है?',
|
| 50 |
+
createAccount: 'नया खाता बनाएं',
|
| 51 |
+
continueAsGuest: 'अतिथि के रूप में जारी रखें',
|
| 52 |
+
usernameRequired: 'उपयोगकर्ता नाम आवश्यक है',
|
| 53 |
+
passwordRequired: 'पासवर्ड आवश्यक है',
|
| 54 |
+
invalidCredentials: 'अमान्य उपयोगकर्ता नाम या पासवर्ड',
|
| 55 |
+
loginSuccess: 'सफलतापूर्वक लॉग इन किया गया!',
|
| 56 |
+
loginFailed: 'लॉग इन करने में विफल'
|
| 57 |
+
},
|
| 58 |
+
te: {
|
| 59 |
+
welcomeBack: 'మళ్ళీ స్వాగతం',
|
| 60 |
+
subtitle: 'మీ కెరీర్ ప్రయాణాన్ని కొనసాగించడానికి సైన్ ఇన్ చేయండి',
|
| 61 |
+
username: 'వినియోగదారు పేరు',
|
| 62 |
+
usernamePlaceholder: 'మీ వినియోగదారు పేరును నమోదు చేయండి',
|
| 63 |
+
password: 'పాస్వర్డ్',
|
| 64 |
+
passwordPlaceholder: 'మీ పాస్వర్డ్ను నమోదు చేయండి',
|
| 65 |
+
signIn: 'సైన్ ఇన్ చేయండి',
|
| 66 |
+
signingIn: 'సైన్ ఇన్ అవుతోంది...',
|
| 67 |
+
noAccount: 'ఖాతా లేదా?',
|
| 68 |
+
createAccount: 'కొత్త ఖాతా సృష్టించండి',
|
| 69 |
+
continueAsGuest: 'అతిథిగా కొనసాగించండి',
|
| 70 |
+
usernameRequired: 'వినియోగదారు పేరు అవసరం',
|
| 71 |
+
passwordRequired: 'పాస్వర్డ్ అవసరం',
|
| 72 |
+
invalidCredentials: 'చెల్లని వినియోగదారు పేరు లేదా పాస్వర్డ్',
|
| 73 |
+
loginSuccess: 'విజయవంతంగా లాగిన్ అయ్యారు!',
|
| 74 |
+
loginFailed: 'లాగిన్ చేయడంలో విఫలమైంది'
|
| 75 |
+
},
|
| 76 |
+
ta: {
|
| 77 |
+
welcomeBack: 'மீண்டும் வரவேற்கிறோம்',
|
| 78 |
+
subtitle: 'உங்கள் தொழில் பயணத்தைத் தொடர உள்நுழையவும்',
|
| 79 |
+
username: 'பயனர் பெயர்',
|
| 80 |
+
usernamePlaceholder: 'உங்கள் பயனர் பெயரை உள்ளிடவும்',
|
| 81 |
+
password: 'கடவுச்சொல்',
|
| 82 |
+
passwordPlaceholder: 'உங்கள் கடவுச்சொல்லை உள்ளிடவும்',
|
| 83 |
+
signIn: 'உள்நுழையவும்',
|
| 84 |
+
signingIn: 'உள்நுழைகிறது...',
|
| 85 |
+
noAccount: 'கணக்கு இல்லையா?',
|
| 86 |
+
createAccount: 'புதிய கணக்கை உருவாக்கவும்',
|
| 87 |
+
continueAsGuest: 'விருந்தினராகத் தொடரவும்',
|
| 88 |
+
usernameRequired: 'பயனர் பெயர் தேவை',
|
| 89 |
+
passwordRequired: 'கடவுச்சொல் தேவை',
|
| 90 |
+
invalidCredentials: 'தவறான பயனர் பெயர் அல்லது கடவுச்சொல்',
|
| 91 |
+
loginSuccess: 'வெற்றிகரமாக உள்நுழைந்துள்ளீர்கள்!',
|
| 92 |
+
loginFailed: 'உள்நுழைவதில் தோல்வி'
|
| 93 |
+
},
|
| 94 |
+
bn: {
|
| 95 |
+
welcomeBack: 'আবার স্বাগতম',
|
| 96 |
+
subtitle: 'আপনার ক্যারিয়ার যাত্রা চালিয়ে যেতে সাইন ইন করুন',
|
| 97 |
+
username: 'ব্যবহারকারীর নাম',
|
| 98 |
+
usernamePlaceholder: 'আপনার ব্যবহারকারীর নাম লিখুন',
|
| 99 |
+
password: 'পাসওয়ার্ড',
|
| 100 |
+
passwordPlaceholder: 'আপনার পাসওয়ার্ড লিখুন',
|
| 101 |
+
signIn: 'সাইন ইন করুন',
|
| 102 |
+
signingIn: 'সাইন ইন করা হচ্ছে...',
|
| 103 |
+
noAccount: 'অ্যাকাউন্ট নেই?',
|
| 104 |
+
createAccount: 'নতুন অ্যাকাউন্ট তৈরি করুন',
|
| 105 |
+
continueAsGuest: 'অতিথি হিসাবে চালিয়ে যান',
|
| 106 |
+
usernameRequired: 'ব্যবহারকারীর নাম প্রয়োজন',
|
| 107 |
+
passwordRequired: 'পাসওয়ার্ড প্রয়োজন',
|
| 108 |
+
invalidCredentials: 'অবৈধ ব্যবহারকারীর নাম বা পাসওয়ার্ড',
|
| 109 |
+
loginSuccess: 'সফলভাবে লগইন হয়েছে!',
|
| 110 |
+
loginFailed: 'লগইন করতে ব্যর্থ'
|
| 111 |
+
},
|
| 112 |
+
gu: {
|
| 113 |
+
welcomeBack: 'ફરી સ્વાગત છે',
|
| 114 |
+
subtitle: 'તમારી કારકિર્દીની યાત્રા ચાલુ રાખવા માટે સાઇન ઇન કરો',
|
| 115 |
+
username: 'વપરાશકર્તા નામ',
|
| 116 |
+
usernamePlaceholder: 'તમારું વપરાશકર્તા નામ દાખલ કરો',
|
| 117 |
+
password: 'પાસવર્ડ',
|
| 118 |
+
passwordPlaceholder: 'તમારો પાસવર્ડ દાખલ કરો',
|
| 119 |
+
signIn: 'સાઇન ઇન કરો',
|
| 120 |
+
signingIn: 'સાઇન ઇન થઈ રહ્યું છે...',
|
| 121 |
+
noAccount: 'એકાઉન્ટ નથી?',
|
| 122 |
+
createAccount: 'નવું એકાઉન્ટ બનાવો',
|
| 123 |
+
continueAsGuest: 'મહેમાન તરીકે ચાલુ રાખો',
|
| 124 |
+
usernameRequired: 'વપરાશકર્તા નામ જરૂરી છે',
|
| 125 |
+
passwordRequired: 'પાસવર્ડ જરૂરી છે',
|
| 126 |
+
invalidCredentials: 'અમાન્ય વપરાશકર્તા નામ અથવા પાસવર્ડ',
|
| 127 |
+
loginSuccess: 'સફળતાપૂર્વક લૉગ ઇન થયું!',
|
| 128 |
+
loginFailed: 'લૉગ ઇન કરવામાં અસફળ'
|
| 129 |
+
}
|
| 130 |
+
};
|
| 131 |
+
|
| 132 |
+
export function LoginPage({
|
| 133 |
+
userProfile,
|
| 134 |
+
setUserProfile,
|
| 135 |
+
navigateTo,
|
| 136 |
+
onLoginComplete,
|
| 137 |
+
onShowSignup,
|
| 138 |
+
onGuestMode
|
| 139 |
+
}: LoginPageProps) {
|
| 140 |
+
// Use localStorage to persist username across re-renders
|
| 141 |
+
const [username, setUsername] = useState(() => {
|
| 142 |
+
return localStorage.getItem('pathfinder_login_username') || '';
|
| 143 |
+
});
|
| 144 |
+
const [password, setPassword] = useState('');
|
| 145 |
+
const [errors, setErrors] = useState<{ [key: string]: string }>({});
|
| 146 |
+
const [loading, setLoading] = useState(false);
|
| 147 |
+
const [loginError, setLoginError] = useState<string>(''); // Separate state for login error that persists
|
| 148 |
+
const passwordInputRef = useRef<HTMLInputElement>(null);
|
| 149 |
+
const usernameInputRef = useRef<HTMLInputElement>(null);
|
| 150 |
+
|
| 151 |
+
// Save username to localStorage whenever it changes
|
| 152 |
+
const handleUsernameChange = (value: string) => {
|
| 153 |
+
setUsername(value);
|
| 154 |
+
localStorage.setItem('pathfinder_login_username', value);
|
| 155 |
+
};
|
| 156 |
+
|
| 157 |
+
const t = translations[userProfile.language];
|
| 158 |
+
|
| 159 |
+
// Effect to restore error if it gets cleared while password is empty
|
| 160 |
+
useEffect(() => {
|
| 161 |
+
// If password is empty and we had a login error but it got cleared, restore it
|
| 162 |
+
if (password === '' && !loginError && !errors.password) {
|
| 163 |
+
// Check if we just had a login attempt (loading just finished with error)
|
| 164 |
+
// This is a safety net to restore the error if something clears it
|
| 165 |
+
const savedError = sessionStorage.getItem('pathfinder_last_login_error');
|
| 166 |
+
if (savedError) {
|
| 167 |
+
setLoginError(savedError);
|
| 168 |
+
// Only set password error, no username error - use function form
|
| 169 |
+
setErrors(() => ({ password: savedError }));
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
}, [password, loginError, errors.password]);
|
| 173 |
+
|
| 174 |
+
const validateForm = () => {
|
| 175 |
+
const newErrors: { [key: string]: string } = {};
|
| 176 |
+
|
| 177 |
+
if (!username.trim()) {
|
| 178 |
+
newErrors.username = t.usernameRequired;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
if (!password.trim()) {
|
| 182 |
+
newErrors.password = t.passwordRequired;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
// Only set errors for fields that have validation issues
|
| 186 |
+
// Use function form to ensure we're working with the latest state
|
| 187 |
+
setErrors(() => newErrors);
|
| 188 |
+
return Object.keys(newErrors).length === 0;
|
| 189 |
+
};
|
| 190 |
+
|
| 191 |
+
const handleSubmit = async (e: React.FormEvent) => {
|
| 192 |
+
e.preventDefault();
|
| 193 |
+
e.stopPropagation(); // Prevent event bubbling that might trigger browser validation
|
| 194 |
+
|
| 195 |
+
// Clear any existing errors before validation
|
| 196 |
+
// Use function form to ensure we're clearing the latest state
|
| 197 |
+
setErrors(() => ({}));
|
| 198 |
+
setLoginError('');
|
| 199 |
+
|
| 200 |
+
if (!validateForm()) {
|
| 201 |
+
return;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
setLoading(true);
|
| 205 |
+
try {
|
| 206 |
+
const user = await authService.login({
|
| 207 |
+
username: username.trim(),
|
| 208 |
+
password: password,
|
| 209 |
+
});
|
| 210 |
+
|
| 211 |
+
// Update user profile with data from server, preserving selected language
|
| 212 |
+
const updatedProfile: UserProfile = {
|
| 213 |
+
...userProfile,
|
| 214 |
+
name: user.name || userProfile.name,
|
| 215 |
+
class: user.grade || userProfile.class,
|
| 216 |
+
age: user.age?.toString() || userProfile.age,
|
| 217 |
+
language: userProfile.language, // Keep the selected language
|
| 218 |
+
};
|
| 219 |
+
setUserProfile(updatedProfile);
|
| 220 |
+
|
| 221 |
+
// Save language preference to localStorage
|
| 222 |
+
localStorage.setItem('pathfinder_user_language', userProfile.language);
|
| 223 |
+
|
| 224 |
+
// Store in localStorage
|
| 225 |
+
localStorage.setItem('pathfinder_setup_complete', 'true');
|
| 226 |
+
localStorage.setItem('pathfinder_user_name', user.name || '');
|
| 227 |
+
localStorage.setItem('pathfinder_user_grade', user.grade || '');
|
| 228 |
+
if (user.age) {
|
| 229 |
+
localStorage.setItem('pathfinder_user_age', user.age.toString());
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
// Clear saved username and any error state on successful login
|
| 233 |
+
localStorage.removeItem('pathfinder_login_username');
|
| 234 |
+
sessionStorage.removeItem('pathfinder_last_login_error');
|
| 235 |
+
setLoginError('');
|
| 236 |
+
|
| 237 |
+
toast.success(t.loginSuccess);
|
| 238 |
+
onLoginComplete();
|
| 239 |
+
navigateTo('home');
|
| 240 |
+
} catch (error: any) {
|
| 241 |
+
console.error('Login error:', error);
|
| 242 |
+
const errorMessage = error.response?.data?.error || error.message || t.loginFailed;
|
| 243 |
+
|
| 244 |
+
// Set error message - always show invalid credentials for login failures
|
| 245 |
+
const displayError = t.invalidCredentials;
|
| 246 |
+
|
| 247 |
+
// IMPORTANT: Only clear password, preserve username
|
| 248 |
+
// The username value should remain so user doesn't have to retype it
|
| 249 |
+
// Username is stored in localStorage, so it will persist even if component re-renders
|
| 250 |
+
|
| 251 |
+
// Save error to sessionStorage as backup
|
| 252 |
+
sessionStorage.setItem('pathfinder_last_login_error', displayError);
|
| 253 |
+
|
| 254 |
+
// CRITICAL: Clear browser validation state for username field
|
| 255 |
+
// Use ref if available, otherwise fallback to getElementById
|
| 256 |
+
const usernameInput = usernameInputRef.current || (document.getElementById('username') as HTMLInputElement);
|
| 257 |
+
if (usernameInput) {
|
| 258 |
+
usernameInput.setCustomValidity('');
|
| 259 |
+
// Remove any browser validation styling
|
| 260 |
+
usernameInput.style.boxShadow = 'none';
|
| 261 |
+
usernameInput.style.outline = 'none';
|
| 262 |
+
// Add CSS class to hide browser validation styling
|
| 263 |
+
usernameInput.classList.add('no-browser-validation');
|
| 264 |
+
// Force browser to re-evaluate validation state
|
| 265 |
+
setTimeout(() => {
|
| 266 |
+
usernameInput.blur();
|
| 267 |
+
usernameInput.focus();
|
| 268 |
+
usernameInput.blur();
|
| 269 |
+
}, 0);
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
// CRITICAL: Explicitly clear ALL errors and set ONLY password error
|
| 273 |
+
// Use a function to ensure we're working with the latest state
|
| 274 |
+
setLoginError(displayError);
|
| 275 |
+
setErrors(() => {
|
| 276 |
+
// Return a completely new object with ONLY password error
|
| 277 |
+
// This ensures username error is never present
|
| 278 |
+
return { password: displayError };
|
| 279 |
+
});
|
| 280 |
+
|
| 281 |
+
// Use a small delay before clearing password to ensure error state is set
|
| 282 |
+
setTimeout(() => {
|
| 283 |
+
setPassword('');
|
| 284 |
+
|
| 285 |
+
// Double-check error is still set after clearing password
|
| 286 |
+
setTimeout(() => {
|
| 287 |
+
if (!loginError && password === '') {
|
| 288 |
+
setLoginError(displayError);
|
| 289 |
+
// Only set password error, no username error - use function form
|
| 290 |
+
setErrors(() => ({ password: displayError }));
|
| 291 |
+
}
|
| 292 |
+
}, 50);
|
| 293 |
+
}, 10);
|
| 294 |
+
|
| 295 |
+
// Show toast notification
|
| 296 |
+
toast.error(displayError);
|
| 297 |
+
} finally {
|
| 298 |
+
setLoading(false);
|
| 299 |
+
}
|
| 300 |
+
};
|
| 301 |
+
|
| 302 |
+
const handleLanguageChange = (lang: Language) => {
|
| 303 |
+
setUserProfile({ ...userProfile, language: lang });
|
| 304 |
+
};
|
| 305 |
+
|
| 306 |
+
return (
|
| 307 |
+
<div className="min-h-screen bg-gradient-to-br from-blue-50 via-white to-purple-50 flex items-center justify-center p-4">
|
| 308 |
+
<Card className="w-full max-w-md">
|
| 309 |
+
<CardHeader className="text-center space-y-2">
|
| 310 |
+
<div className="flex justify-between items-start mb-4">
|
| 311 |
+
<div className="flex-1"></div>
|
| 312 |
+
<div className="flex justify-center flex-1">
|
| 313 |
+
<div className="bg-gradient-to-br from-blue-600 to-purple-600 p-4 rounded-full">
|
| 314 |
+
<GraduationCap className="w-12 h-12 text-white" />
|
| 315 |
+
</div>
|
| 316 |
+
</div>
|
| 317 |
+
<div className="flex-1 flex justify-end">
|
| 318 |
+
<LanguageSelector
|
| 319 |
+
language={userProfile.language}
|
| 320 |
+
onLanguageChange={handleLanguageChange}
|
| 321 |
+
/>
|
| 322 |
+
</div>
|
| 323 |
+
</div>
|
| 324 |
+
<CardTitle className="text-2xl bg-gradient-to-r from-blue-600 to-purple-600 bg-clip-text text-transparent">
|
| 325 |
+
{t.welcomeBack}
|
| 326 |
+
</CardTitle>
|
| 327 |
+
<CardDescription className="text-base">
|
| 328 |
+
{t.subtitle}
|
| 329 |
+
</CardDescription>
|
| 330 |
+
</CardHeader>
|
| 331 |
+
<CardContent>
|
| 332 |
+
<form onSubmit={handleSubmit} className="space-y-6" noValidate>
|
| 333 |
+
{/* Username Field */}
|
| 334 |
+
<div className="space-y-2">
|
| 335 |
+
<Label htmlFor="username">{t.username} *</Label>
|
| 336 |
+
<Input
|
| 337 |
+
ref={usernameInputRef}
|
| 338 |
+
id="username"
|
| 339 |
+
type="text"
|
| 340 |
+
placeholder={t.usernamePlaceholder}
|
| 341 |
+
value={username}
|
| 342 |
+
onChange={(e) => {
|
| 343 |
+
handleUsernameChange(e.target.value);
|
| 344 |
+
// Clear username error when user types
|
| 345 |
+
if (errors.username) {
|
| 346 |
+
setErrors((prev) => {
|
| 347 |
+
const newErrors = { ...prev };
|
| 348 |
+
delete newErrors.username;
|
| 349 |
+
return newErrors;
|
| 350 |
+
});
|
| 351 |
+
}
|
| 352 |
+
// Clear browser validation state when user types
|
| 353 |
+
e.currentTarget.setCustomValidity('');
|
| 354 |
+
}}
|
| 355 |
+
// Only show red border if there's a username-specific error, NOT for login errors
|
| 356 |
+
className={errors.username && !loginError ? 'border-red-500' : ''}
|
| 357 |
+
autoComplete="username"
|
| 358 |
+
// CRITICAL: Never set aria-invalid to true when there's a login error
|
| 359 |
+
// This prevents the Input component's CSS from showing red styling
|
| 360 |
+
aria-invalid={errors.username && !loginError ? 'true' : undefined}
|
| 361 |
+
// Hide browser validation styling with CSS
|
| 362 |
+
style={{
|
| 363 |
+
boxShadow: 'none',
|
| 364 |
+
outline: 'none',
|
| 365 |
+
}}
|
| 366 |
+
// Explicitly prevent browser validation styling
|
| 367 |
+
onInvalid={(e) => {
|
| 368 |
+
// Prevent browser's default invalid styling
|
| 369 |
+
e.preventDefault();
|
| 370 |
+
e.stopPropagation();
|
| 371 |
+
// Clear custom validity to prevent browser validation feedback
|
| 372 |
+
e.currentTarget.setCustomValidity('');
|
| 373 |
+
}}
|
| 374 |
+
onBlur={(e) => {
|
| 375 |
+
// Remove any browser validation styling on blur
|
| 376 |
+
e.currentTarget.setCustomValidity('');
|
| 377 |
+
}}
|
| 378 |
+
/>
|
| 379 |
+
{errors.username && !loginError && (
|
| 380 |
+
<p className="text-sm text-red-500">{errors.username}</p>
|
| 381 |
+
)}
|
| 382 |
+
</div>
|
| 383 |
+
|
| 384 |
+
{/* Password Field */}
|
| 385 |
+
<div className="space-y-2">
|
| 386 |
+
<Label htmlFor="password">{t.password} *</Label>
|
| 387 |
+
<Input
|
| 388 |
+
ref={passwordInputRef}
|
| 389 |
+
id="password"
|
| 390 |
+
type="password"
|
| 391 |
+
placeholder={t.passwordPlaceholder}
|
| 392 |
+
value={password}
|
| 393 |
+
onChange={(e) => {
|
| 394 |
+
const newPassword = e.target.value;
|
| 395 |
+
const oldPassword = password;
|
| 396 |
+
|
| 397 |
+
setPassword(newPassword);
|
| 398 |
+
|
| 399 |
+
// CRITICAL: Only clear error when user actively types NEW characters
|
| 400 |
+
// NEVER clear error when:
|
| 401 |
+
// 1. Password becomes empty (was programmatically cleared)
|
| 402 |
+
// 2. Password length decreases (user is deleting, not typing new content)
|
| 403 |
+
// Only clear when password length increases (user is typing new content)
|
| 404 |
+
|
| 405 |
+
if (newPassword.length > oldPassword.length && newPassword.length > 0) {
|
| 406 |
+
// User is actively typing new characters - clear the error
|
| 407 |
+
sessionStorage.removeItem('pathfinder_last_login_error');
|
| 408 |
+
if (loginError) {
|
| 409 |
+
setLoginError('');
|
| 410 |
+
}
|
| 411 |
+
if (errors.password) {
|
| 412 |
+
setErrors((prev) => {
|
| 413 |
+
const newErrors = { ...prev };
|
| 414 |
+
delete newErrors.password;
|
| 415 |
+
return newErrors;
|
| 416 |
+
});
|
| 417 |
+
}
|
| 418 |
+
} else if (newPassword.length === 0 && oldPassword.length > 0) {
|
| 419 |
+
// Password was cleared - restore error if it exists in sessionStorage
|
| 420 |
+
const savedError = sessionStorage.getItem('pathfinder_last_login_error');
|
| 421 |
+
if (savedError && !loginError) {
|
| 422 |
+
setLoginError(savedError);
|
| 423 |
+
// Only set password error, no username error - use function form
|
| 424 |
+
setErrors(() => ({ password: savedError }));
|
| 425 |
+
}
|
| 426 |
+
}
|
| 427 |
+
// If password length decreased but not empty, keep error visible
|
| 428 |
+
}}
|
| 429 |
+
className={(errors.password || loginError) ? 'border-red-500' : ''}
|
| 430 |
+
autoComplete="current-password"
|
| 431 |
+
/>
|
| 432 |
+
{(errors.password || loginError) && (
|
| 433 |
+
<p className="text-sm text-red-500 mt-1">{errors.password || loginError}</p>
|
| 434 |
+
)}
|
| 435 |
+
</div>
|
| 436 |
+
|
| 437 |
+
{/* Submit Button */}
|
| 438 |
+
<Button
|
| 439 |
+
type="submit"
|
| 440 |
+
className="w-full bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700"
|
| 441 |
+
disabled={loading}
|
| 442 |
+
>
|
| 443 |
+
<LogIn className="w-4 h-4 mr-2" />
|
| 444 |
+
{loading ? t.signingIn : t.signIn}
|
| 445 |
+
</Button>
|
| 446 |
+
|
| 447 |
+
{/* Sign Up Link */}
|
| 448 |
+
<div className="text-center pt-4 border-t space-y-3">
|
| 449 |
+
<p className="text-sm text-gray-600 mb-2">
|
| 450 |
+
{t.noAccount}
|
| 451 |
+
</p>
|
| 452 |
+
<Button
|
| 453 |
+
type="button"
|
| 454 |
+
variant="outline"
|
| 455 |
+
className="w-full"
|
| 456 |
+
onClick={onShowSignup}
|
| 457 |
+
>
|
| 458 |
+
<UserPlus className="w-4 h-4 mr-2" />
|
| 459 |
+
{t.createAccount}
|
| 460 |
+
</Button>
|
| 461 |
+
|
| 462 |
+
{/* Continue as Guest */}
|
| 463 |
+
<div className="pt-2">
|
| 464 |
+
<Button
|
| 465 |
+
type="button"
|
| 466 |
+
variant="ghost"
|
| 467 |
+
className="w-full text-gray-600 hover:text-gray-900"
|
| 468 |
+
onClick={onGuestMode}
|
| 469 |
+
>
|
| 470 |
+
{t.continueAsGuest}
|
| 471 |
+
</Button>
|
| 472 |
+
</div>
|
| 473 |
+
</div>
|
| 474 |
+
</form>
|
| 475 |
+
</CardContent>
|
| 476 |
+
</Card>
|
| 477 |
+
</div>
|
| 478 |
+
);
|
| 479 |
+
}
|
| 480 |
+
|
frontend/src/components/ProcessingPage.tsx
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useEffect, useState } from "react";
|
| 2 |
+
import { Loader2, CheckCircle2, Brain, Sparkles } from "lucide-react";
|
| 3 |
+
import { Button } from "./ui/button";
|
| 4 |
+
import { Card, CardContent } from "./ui/card";
|
| 5 |
+
import { Progress } from "./ui/progress";
|
| 6 |
+
import { LanguageSelector } from "./LanguageSelector";
|
| 7 |
+
import { assessmentService } from "../services/assessmentService";
|
| 8 |
+
import type {
|
| 9 |
+
Page,
|
| 10 |
+
UserProfile,
|
| 11 |
+
TestType,
|
| 12 |
+
Language,
|
| 13 |
+
AssessmentResults,
|
| 14 |
+
} from "../App";
|
| 15 |
+
|
| 16 |
+
interface ProcessingPageProps {
|
| 17 |
+
userProfile: UserProfile;
|
| 18 |
+
setUserProfile: (profile: UserProfile) => void;
|
| 19 |
+
navigateTo: (page: Page, displayResults?: boolean) => void;
|
| 20 |
+
selectedTest: TestType;
|
| 21 |
+
allTestAnswers: { [testType: string]: { [key: number]: string | string[] } };
|
| 22 |
+
testFlow: TestType[];
|
| 23 |
+
assessmentId: number | null;
|
| 24 |
+
isGuestMode?: boolean;
|
| 25 |
+
onResultsReceived: (results: AssessmentResults) => void;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
const processingSteps = {
|
| 29 |
+
en: [
|
| 30 |
+
{ id: 1, text: "Analyzing your responses...", duration: 2000 },
|
| 31 |
+
{ id: 2, text: "Identifying your strengths...", duration: 2500 },
|
| 32 |
+
{ id: 3, text: "Matching with career paths...", duration: 3000 },
|
| 33 |
+
{ id: 4, text: "Generating recommendations...", duration: 2000 },
|
| 34 |
+
{ id: 5, text: "Preparing your report...", duration: 1500 },
|
| 35 |
+
],
|
| 36 |
+
hi: [
|
| 37 |
+
{ id: 1, text: "आपकी प्रतिक्रियाओं का विश्लेषण...", duration: 2000 },
|
| 38 |
+
{ id: 2, text: "आपकी ताकत की पहचान...", duration: 2500 },
|
| 39 |
+
{ id: 3, text: "करियर पथों से मिलान...", duration: 3000 },
|
| 40 |
+
{ id: 4, text: "सिफारिशें तैयार की जा रही हैं...", duration: 2000 },
|
| 41 |
+
{ id: 5, text: "आपकी रिपोर्ट तैयार की जा रही है...", duration: 1500 },
|
| 42 |
+
],
|
| 43 |
+
te: [
|
| 44 |
+
{ id: 1, text: "మీ ప్రతిస్పందనలను విశ్లేషిస్తోంది...", duration: 2000 },
|
| 45 |
+
{ id: 2, text: "మీ బలాలను గుర్తిస్తోంది...", duration: 2500 },
|
| 46 |
+
{ id: 3, text: "కెరీర్ మార్గాలతో సరిపోల్చడం...", duration: 3000 },
|
| 47 |
+
{ id: 4, text: "సిఫార్సులు రూపొందిస్తోంది...", duration: 2000 },
|
| 48 |
+
{ id: 5, text: "మీ నివేదికను సిద్ధం చేస్తోంది...", duration: 1500 },
|
| 49 |
+
],
|
| 50 |
+
ta: [
|
| 51 |
+
{ id: 1, text: "உங்கள் பதில்களை பகுப்பாய்வு செய்கிறது...", duration: 2000 },
|
| 52 |
+
{ id: 2, text: "உங்கள் பலங்களை அடையாளம் காணுகிறது...", duration: 2500 },
|
| 53 |
+
{ id: 3, text: "தொழில் பாதைகளுடன் பொருத்துகிறது...", duration: 3000 },
|
| 54 |
+
{ id: 4, text: "பரிந்துரைகளை உருவாக்குகிறது...", duration: 2000 },
|
| 55 |
+
{ id: 5, text: "உங்கள் அறிக்கையை தயாரிக்கிறது...", duration: 1500 },
|
| 56 |
+
],
|
| 57 |
+
bn: [
|
| 58 |
+
{ id: 1, text: "আপনার প্রতিক্রিয়া বিশ্লেষণ করা হচ্ছে...", duration: 2000 },
|
| 59 |
+
{ id: 2, text: "আপনার শক্তি চিহ্নিত করা হচ্ছে...", duration: 2500 },
|
| 60 |
+
{ id: 3, text: "ক্যারিয়ার পথের সাথে মিলানো হচ্ছে...", duration: 3000 },
|
| 61 |
+
{ id: 4, text: "সুপারিশ তৈরি করা হচ্ছে...", duration: 2000 },
|
| 62 |
+
{ id: 5, text: "আপনার রিপোর্ট প্রস্তুত করা হচ্ছে...", duration: 1500 },
|
| 63 |
+
],
|
| 64 |
+
gu: [
|
| 65 |
+
{
|
| 66 |
+
id: 1,
|
| 67 |
+
text: "તમારા પ્રતિસાદોનું વિશ્લેષણ કરી રહ્યા છીએ...",
|
| 68 |
+
duration: 2000,
|
| 69 |
+
},
|
| 70 |
+
{ id: 2, text: "તમારી શક્તિઓની ઓળખ કરી રહ્યા છીએ...", duration: 2500 },
|
| 71 |
+
{
|
| 72 |
+
id: 3,
|
| 73 |
+
text: "કારકિર્દી માર્ગો સાથે મેચિંગ કરી રહ્યા છીએ...",
|
| 74 |
+
duration: 3000,
|
| 75 |
+
},
|
| 76 |
+
{ id: 4, text: "ભલામણો બનાવી રહ્યા છીએ...", duration: 2000 },
|
| 77 |
+
{ id: 5, text: "તમારો રિપોર્ટ તૈયાર કરી રહ્યા છીએ...", duration: 1500 },
|
| 78 |
+
],
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
const translations = {
|
| 82 |
+
en: {
|
| 83 |
+
processing: "Processing Your Assessment",
|
| 84 |
+
complete: "Analysis Complete!",
|
| 85 |
+
pleaseWait: "Please wait while we analyze your responses",
|
| 86 |
+
success: "Your personalized career recommendations are ready",
|
| 87 |
+
successDesc:
|
| 88 |
+
"We've analyzed your responses and prepared personalized career recommendations based on your aptitudes, values, and interests.",
|
| 89 |
+
viewResults: "View Results",
|
| 90 |
+
progress: "Progress",
|
| 91 |
+
didKnow: "Did you know?",
|
| 92 |
+
funFact:
|
| 93 |
+
"There are over 12,000 different career options available in India! We're helping you find the ones that match your unique profile.",
|
| 94 |
+
thankYou: "Thank you for completing the assessment",
|
| 95 |
+
},
|
| 96 |
+
hi: {
|
| 97 |
+
processing: "आपके मूल्यांकन का विश्लेषण",
|
| 98 |
+
complete: "विश्लेषण पूर्ण!",
|
| 99 |
+
pleaseWait:
|
| 100 |
+
"कृपया प्रतीक्षा करें जब तक हम आपकी प्रतिक्रियाओं का विश्लेषण करते हैं",
|
| 101 |
+
success: "आपकी व्यक्तिगत करियर सिफारिशें तैयार हैं",
|
| 102 |
+
successDesc:
|
| 103 |
+
"हमने आपकी प्रतिक्रियाओं का विश्लेषण किया है और आपकी योग्यताओं, मूल्यों और रुचियों के आधार पर व्यक्तिगत करियर सिफारिशें तैयार की हैं।",
|
| 104 |
+
viewResults: "परिणाम देखें",
|
| 105 |
+
progress: "प्रगति",
|
| 106 |
+
didKnow: "क्या आप जानते हैं?",
|
| 107 |
+
funFact:
|
| 108 |
+
"भारत में 12,000 से अधिक विभिन्न करियर विकल्प उपलब्ध हैं! हम आपको वे खोजने में मदद कर रहे हैं जो आपकी अनूठी प्रोफ़ाइल से मेल खाते हैं।",
|
| 109 |
+
thankYou: "मूल्यांकन पूरा करने के लिए धन्यवाद",
|
| 110 |
+
},
|
| 111 |
+
te: {
|
| 112 |
+
processing: "మీ అసెస్మెంట్ను ప్రాసెస్ చేస్తోంది",
|
| 113 |
+
complete: "విశ్లేషణ పూర్తయింది!",
|
| 114 |
+
pleaseWait:
|
| 115 |
+
"మేము మీ ప్రతిస్పందనలను విశ్లేషిస్తున్నప్పుడు దయచేసి వేచి ఉండండి",
|
| 116 |
+
success: "మీ వ్యక్తిగత కెరీర్ సిఫార్సులు సిద్ధంగా ఉన్నాయి",
|
| 117 |
+
successDesc:
|
| 118 |
+
"మేము మీ ప్రతిస్పందనలను విశ్లేషించాము మరియు మీ సామర్థ్యాలు, విలువలు మరియు ఆసక్తుల ఆధారంగా వ్యక్తిగత కెరీర్ సిఫార్సులను సిద్ధం చేసాము।",
|
| 119 |
+
viewResults: "ఫలితాలు చూడండి",
|
| 120 |
+
progress: "పురోగతి",
|
| 121 |
+
didKnow: "మీకు తెలుసా?",
|
| 122 |
+
funFact:
|
| 123 |
+
"భారతదేశంలో 12,000 కంటే ఎక్కువ వివిధ కెరీర్ ఎంపికలు అందుబాటులో ఉన్నాయి! మీ ప్రత్యేక ప్రొఫైల్కు సరిపోయేవాటిని కనుగొనడంలో మేము మీకు సహాయం చేస్తున్నాము।",
|
| 124 |
+
thankYou: "అసెస్మెంట్ పూర్తి చేసినందుకు ధన్యవాదాలు",
|
| 125 |
+
},
|
| 126 |
+
ta: {
|
| 127 |
+
processing: "உங்கள் மதிப்பீட்டை செயலாக்குகிறது",
|
| 128 |
+
complete: "பகுப்பாய்வு முடிந்தது!",
|
| 129 |
+
pleaseWait:
|
| 130 |
+
"நாங்கள் உங்கள் பதில்களை பகுப்பாய்வு செய்யும் வரை காத்திருக்கவும்",
|
| 131 |
+
success: "உங்கள் தனிப்பயன் தொழில் பரிந்துரைகள் தயார்",
|
| 132 |
+
successDesc:
|
| 133 |
+
"நாங்கள் உங்கள் பதில்களை பகுப்பாய்வு செய்து, உங்கள் திறன்கள், மதிப்புகள் மற்றும் ஆர்வங்களின் அடிப்படையில் தனிப்பயன் தொழில் பரிந்துரைகளை தயாரித்துள்ளோம்.",
|
| 134 |
+
viewResults: "முடிவுகளைப் பார்க்கவும்",
|
| 135 |
+
progress: "முன்னேற்றம்",
|
| 136 |
+
didKnow: "உங்களுக்குத் தெரியுமா?",
|
| 137 |
+
funFact:
|
| 138 |
+
"இந்தியாவில் 12,000க்கும் மேற்பட்ட வெவ்வேறு தொழில் விருப்பங்கள் உள்ளன! உங்கள் தனித்துவமான சுயவிவரத்துடன் பொருந்தும் விருப்பங்களைக் கண்டறிய நாங்கள் உதவுகிறோம்.",
|
| 139 |
+
thankYou: "மதிப்பீட்டை முடித்ததற்கு நன்றி",
|
| 140 |
+
},
|
| 141 |
+
bn: {
|
| 142 |
+
processing: "আপনার মূল্যায়ন প্রক্রিয়া করা হচ্ছে",
|
| 143 |
+
complete: "বিশ্লেষণ সম্পূর্ণ!",
|
| 144 |
+
pleaseWait: "আমরা আপনার উত্তর বিশ্লেষণ করার সময় অপেক্ষা করুন",
|
| 145 |
+
success: "আপনার ব্যক্তিগত ক্যারিয়ার সুপারিশ প্রস্তুত",
|
| 146 |
+
successDesc:
|
| 147 |
+
"আমরা আপনার উত্তর বিশ্লেষণ করেছি এবং আপনার যোগ্যতা, মূল্যবোধ এবং আগ্রহের ভিত্তিতে ব্যক্তিগত ক্যারিয়ার সুপারিশ প্রস্তুত করেছি।",
|
| 148 |
+
viewResults: "ফলাফল দেখুন",
|
| 149 |
+
progress: "অগ্রগতি",
|
| 150 |
+
didKnow: "আপনি কি জানেন?",
|
| 151 |
+
funFact:
|
| 152 |
+
"ভারতে 12,000 এরও বেশি বিভিন্ন ক্যারিয়ার বিকল্প উপলব্ধ! আমরা আপনাকে এমনগুলি খুঁজে পেতে সাহায্য করছি যা আপনার অনন্য প্রোফাইলের সাথে মেলে।",
|
| 153 |
+
thankYou: "মূল্যায়ন সম্পূর্ণ করার জন্য ধন্যবাদ",
|
| 154 |
+
},
|
| 155 |
+
gu: {
|
| 156 |
+
processing: "તમારું મૂલ્યાંકન પ્રોસેસ કરી રહ્યા છીએ",
|
| 157 |
+
complete: "વિશ્લેષણ પૂર્ણ!",
|
| 158 |
+
pleaseWait:
|
| 159 |
+
"કૃપા કરી રાહ જુઓ જ્યારે અમે તમારા પ્રતિસાદોનું વિશ્લેષણ કરીએ છીએ",
|
| 160 |
+
success: "તમારી વ્યક્તિગત કારકિર્દી ભલામણો તૈયાર છે",
|
| 161 |
+
successDesc:
|
| 162 |
+
"અમે તમારા પ્રતિસાદોનું વિશ્લેષણ કર્યું છે અને તમારી યોગ્યતાઓ, મૂલ્યો અને રુચિઓના આધારે વ્યક્તિગત કારકિર્દી ભલામણો તૈયાર કરી છે.",
|
| 163 |
+
viewResults: "પરિણામો જુઓ",
|
| 164 |
+
progress: "પ્રગતિ",
|
| 165 |
+
didKnow: "શું તમે જાણો છો?",
|
| 166 |
+
funFact:
|
| 167 |
+
"ભારતમાં 12,000 થી વધુ વિવિધ કારકિર્દી વિકલ્પો ઉપલબ્ધ છે! અમે તમને તે વિકલ્પો શોધવામાં મદદ કરી રહ્યા છીએ જે તમારી અનન્ય પ્રોફાઇલ સાથે મેળ ખાય છે.",
|
| 168 |
+
thankYou: "મૂલ્યાંકન પૂર્ણ કરવા બદલ આભાર",
|
| 169 |
+
},
|
| 170 |
+
};
|
| 171 |
+
|
| 172 |
+
export function ProcessingPage({
|
| 173 |
+
userProfile,
|
| 174 |
+
setUserProfile,
|
| 175 |
+
navigateTo,
|
| 176 |
+
selectedTest,
|
| 177 |
+
allTestAnswers,
|
| 178 |
+
testFlow,
|
| 179 |
+
assessmentId,
|
| 180 |
+
isGuestMode = false,
|
| 181 |
+
onResultsReceived,
|
| 182 |
+
}: ProcessingPageProps) {
|
| 183 |
+
const [currentStep, setCurrentStep] = useState(0);
|
| 184 |
+
const [progress, setProgress] = useState(0);
|
| 185 |
+
const [isComplete, setIsComplete] = useState(false);
|
| 186 |
+
const [isProcessing, setIsProcessing] = useState(false);
|
| 187 |
+
const [assessmentResults, setAssessmentResults] = useState<any>(null);
|
| 188 |
+
const lang = userProfile.language;
|
| 189 |
+
const t = translations[lang];
|
| 190 |
+
const steps = processingSteps[lang];
|
| 191 |
+
|
| 192 |
+
const handleLanguageChange = (newLang: Language) => {
|
| 193 |
+
setUserProfile({ ...userProfile, language: newLang });
|
| 194 |
+
};
|
| 195 |
+
|
| 196 |
+
// Start processing assessment when animation starts (not when it finishes)
|
| 197 |
+
useEffect(() => {
|
| 198 |
+
// Start processing after a short delay to show animation
|
| 199 |
+
if (currentStep > 0 && !isProcessing && !isComplete) {
|
| 200 |
+
const timer = setTimeout(() => {
|
| 201 |
+
setIsProcessing(true);
|
| 202 |
+
submitAssessment();
|
| 203 |
+
}, 1000); // Start processing 1 second after animation starts
|
| 204 |
+
return () => clearTimeout(timer);
|
| 205 |
+
}
|
| 206 |
+
}, [currentStep]);
|
| 207 |
+
|
| 208 |
+
// Don't auto-navigate - let user click "View Results" button manually
|
| 209 |
+
// Results are ready when isComplete is true, but user controls when to view them
|
| 210 |
+
|
| 211 |
+
const submitAssessment = async () => {
|
| 212 |
+
try {
|
| 213 |
+
// In guest mode, show mock results without backend call
|
| 214 |
+
if (isGuestMode) {
|
| 215 |
+
// Simulate processing delay
|
| 216 |
+
await new Promise(resolve => setTimeout(resolve, 1500));
|
| 217 |
+
|
| 218 |
+
const mockResults: AssessmentResults = {
|
| 219 |
+
recommendations: [
|
| 220 |
+
{
|
| 221 |
+
title: "Software Developer",
|
| 222 |
+
confidence: 0.92,
|
| 223 |
+
reason: "Your analytical thinking and problem-solving skills align well with software development.",
|
| 224 |
+
next_steps: ["Learn programming basics", "Build personal projects", "Explore computer science courses"]
|
| 225 |
+
},
|
| 226 |
+
{
|
| 227 |
+
title: "Data Analyst",
|
| 228 |
+
confidence: 0.88,
|
| 229 |
+
reason: "Your attention to detail and logical reasoning make you suitable for data analysis.",
|
| 230 |
+
next_steps: ["Study statistics", "Learn data visualization tools", "Practice with real datasets"]
|
| 231 |
+
},
|
| 232 |
+
{
|
| 233 |
+
title: "UX Designer",
|
| 234 |
+
confidence: 0.85,
|
| 235 |
+
reason: "Your creativity combined with technical interest suggests UX design as a great fit.",
|
| 236 |
+
next_steps: ["Learn design principles", "Study user psychology", "Build a portfolio"]
|
| 237 |
+
}
|
| 238 |
+
],
|
| 239 |
+
summary: "Based on your responses, you show strong aptitude for technology and creative problem-solving. Consider careers that blend analytical thinking with innovation."
|
| 240 |
+
};
|
| 241 |
+
|
| 242 |
+
setAssessmentResults(mockResults);
|
| 243 |
+
onResultsReceived(mockResults);
|
| 244 |
+
setIsComplete(true);
|
| 245 |
+
setIsProcessing(false);
|
| 246 |
+
return;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
// Regular backend submission for logged-in users
|
| 250 |
+
// Prepare assessment payload
|
| 251 |
+
const tests = testFlow.map((testType) => ({
|
| 252 |
+
type: testType,
|
| 253 |
+
answers: allTestAnswers[testType] || {},
|
| 254 |
+
}));
|
| 255 |
+
|
| 256 |
+
const payload = {
|
| 257 |
+
userProfile: {
|
| 258 |
+
name: userProfile.name,
|
| 259 |
+
class: userProfile.class,
|
| 260 |
+
age: userProfile.age,
|
| 261 |
+
language: userProfile.language,
|
| 262 |
+
email: userProfile.email,
|
| 263 |
+
phone: userProfile.phone,
|
| 264 |
+
},
|
| 265 |
+
tests,
|
| 266 |
+
completedAt: new Date().toISOString(),
|
| 267 |
+
assessmentId: assessmentId || Date.now(),
|
| 268 |
+
};
|
| 269 |
+
|
| 270 |
+
const response = await assessmentService.completeAssessment(payload);
|
| 271 |
+
const results: AssessmentResults = response.data;
|
| 272 |
+
setAssessmentResults(results);
|
| 273 |
+
onResultsReceived(results);
|
| 274 |
+
setIsComplete(true);
|
| 275 |
+
} catch (error) {
|
| 276 |
+
console.error("Error submitting assessment:", error);
|
| 277 |
+
// Still mark as complete with fallback
|
| 278 |
+
setIsComplete(true);
|
| 279 |
+
} finally {
|
| 280 |
+
setIsProcessing(false);
|
| 281 |
+
}
|
| 282 |
+
};
|
| 283 |
+
|
| 284 |
+
useEffect(() => {
|
| 285 |
+
if (currentStep < steps.length) {
|
| 286 |
+
const timer = setTimeout(() => {
|
| 287 |
+
setCurrentStep(currentStep + 1);
|
| 288 |
+
setProgress(((currentStep + 1) / steps.length) * 100);
|
| 289 |
+
}, steps[currentStep].duration);
|
| 290 |
+
|
| 291 |
+
return () => clearTimeout(timer);
|
| 292 |
+
}
|
| 293 |
+
}, [currentStep, steps.length]);
|
| 294 |
+
|
| 295 |
+
return (
|
| 296 |
+
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 via-white to-purple-50 p-4">
|
| 297 |
+
<div className="absolute top-4 right-4">
|
| 298 |
+
<LanguageSelector
|
| 299 |
+
language={userProfile.language}
|
| 300 |
+
onLanguageChange={handleLanguageChange}
|
| 301 |
+
/>
|
| 302 |
+
</div>
|
| 303 |
+
|
| 304 |
+
<div className="max-w-2xl w-full">
|
| 305 |
+
<Card className="border-2 shadow-2xl overflow-hidden">
|
| 306 |
+
<div className="bg-gradient-to-r from-blue-600 to-purple-600 p-8 text-white text-center">
|
| 307 |
+
<div className="inline-block p-4 bg-white/20 rounded-full mb-4">
|
| 308 |
+
{isComplete ? (
|
| 309 |
+
<CheckCircle2 className="h-12 w-12" />
|
| 310 |
+
) : (
|
| 311 |
+
<Brain className="h-12 w-12 animate-pulse" />
|
| 312 |
+
)}
|
| 313 |
+
</div>
|
| 314 |
+
<h2 className="text-white mb-2">
|
| 315 |
+
{isComplete ? t.complete : t.processing}
|
| 316 |
+
</h2>
|
| 317 |
+
<p className="text-blue-100">
|
| 318 |
+
{isComplete ? t.success : t.pleaseWait}
|
| 319 |
+
</p>
|
| 320 |
+
</div>
|
| 321 |
+
|
| 322 |
+
<CardContent className="p-8">
|
| 323 |
+
{/* Progress Bar */}
|
| 324 |
+
<div className="mb-8">
|
| 325 |
+
<div className="flex items-center justify-between mb-2">
|
| 326 |
+
<span className="text-sm text-gray-600">{t.progress}</span>
|
| 327 |
+
<span className="text-sm text-gray-900">
|
| 328 |
+
{Math.round(progress)}%
|
| 329 |
+
</span>
|
| 330 |
+
</div>
|
| 331 |
+
<Progress value={progress} className="h-3" />
|
| 332 |
+
</div>
|
| 333 |
+
|
| 334 |
+
{/* Processing Steps */}
|
| 335 |
+
<div className="space-y-4">
|
| 336 |
+
{steps.map((step, index) => (
|
| 337 |
+
<div
|
| 338 |
+
key={step.id}
|
| 339 |
+
className={`flex items-center gap-3 transition-all duration-500 ${
|
| 340 |
+
index < currentStep
|
| 341 |
+
? "opacity-100"
|
| 342 |
+
: index === currentStep
|
| 343 |
+
? "opacity-100"
|
| 344 |
+
: "opacity-30"
|
| 345 |
+
}`}
|
| 346 |
+
>
|
| 347 |
+
<div className="shrink-0">
|
| 348 |
+
{index < currentStep ? (
|
| 349 |
+
<div className="bg-green-500 rounded-full p-1">
|
| 350 |
+
<CheckCircle2 className="h-5 w-5 text-white" />
|
| 351 |
+
</div>
|
| 352 |
+
) : index === currentStep ? (
|
| 353 |
+
<Loader2 className="h-6 w-6 text-blue-600 animate-spin" />
|
| 354 |
+
) : (
|
| 355 |
+
<div className="h-6 w-6 rounded-full border-2 border-gray-300" />
|
| 356 |
+
)}
|
| 357 |
+
</div>
|
| 358 |
+
<span
|
| 359 |
+
className={
|
| 360 |
+
index <= currentStep ? "text-gray-900" : "text-gray-400"
|
| 361 |
+
}
|
| 362 |
+
>
|
| 363 |
+
{step.text}
|
| 364 |
+
</span>
|
| 365 |
+
</div>
|
| 366 |
+
))}
|
| 367 |
+
</div>
|
| 368 |
+
|
| 369 |
+
{/* Completion Message */}
|
| 370 |
+
{isComplete && (
|
| 371 |
+
<div className="mt-8 p-6 bg-gradient-to-r from-green-50 to-emerald-50 rounded-lg border-2 border-green-200">
|
| 372 |
+
<div className="flex items-start gap-3">
|
| 373 |
+
<Sparkles className="h-6 w-6 text-green-600 shrink-0 mt-1" />
|
| 374 |
+
<div>
|
| 375 |
+
<h3 className="text-green-900 mb-2">{t.complete}</h3>
|
| 376 |
+
<p className="text-green-700 text-sm mb-4">
|
| 377 |
+
{t.successDesc}
|
| 378 |
+
</p>
|
| 379 |
+
<Button
|
| 380 |
+
onClick={() => navigateTo("chatbot", true, assessmentId || undefined)}
|
| 381 |
+
className="bg-gradient-to-r from-green-600 to-emerald-600 hover:from-green-700 hover:to-emerald-700"
|
| 382 |
+
>
|
| 383 |
+
{t.viewResults}
|
| 384 |
+
</Button>
|
| 385 |
+
</div>
|
| 386 |
+
</div>
|
| 387 |
+
</div>
|
| 388 |
+
)}
|
| 389 |
+
|
| 390 |
+
{/* Fun Fact */}
|
| 391 |
+
{!isComplete && (
|
| 392 |
+
<div className="mt-8 p-4 bg-blue-50 rounded-lg border border-blue-200">
|
| 393 |
+
<p className="text-sm text-blue-900">
|
| 394 |
+
<strong>{t.didKnow}</strong> {t.funFact}
|
| 395 |
+
</p>
|
| 396 |
+
</div>
|
| 397 |
+
)}
|
| 398 |
+
</CardContent>
|
| 399 |
+
</Card>
|
| 400 |
+
|
| 401 |
+
{/* Additional Info */}
|
| 402 |
+
<div className="mt-6 text-center">
|
| 403 |
+
<p className="text-gray-600 text-sm">
|
| 404 |
+
{t.thankYou}, {userProfile.name}!
|
| 405 |
+
</p>
|
| 406 |
+
</div>
|
| 407 |
+
</div>
|
| 408 |
+
</div>
|
| 409 |
+
);
|
| 410 |
+
}
|
frontend/src/components/SettingsPage.tsx
ADDED
|
@@ -0,0 +1,667 @@
|
|
|
|
|
|
|
|
|
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{ Button } from './ui/button';
|
| 4 |
+
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from './ui/card';
|
| 5 |
+
import { Input } from './ui/input';
|
| 6 |
+
import { Label } from './ui/label';
|
| 7 |
+
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from './ui/alert-dialog';
|
| 8 |
+
import { LanguageSelector } from './LanguageSelector';
|
| 9 |
+
import { assessmentService } from '../services/assessmentService';
|
| 10 |
+
import { toast } from 'sonner';
|
| 11 |
+
import type { Page, UserProfile, Language } from '../App';
|
| 12 |
+
|
| 13 |
+
interface SettingsPageProps {
|
| 14 |
+
userProfile: UserProfile;
|
| 15 |
+
setUserProfile: (profile: UserProfile) => void;
|
| 16 |
+
navigateTo: (page: Page) => void;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
const translations = {
|
| 20 |
+
en: {
|
| 21 |
+
settings: 'Settings',
|
| 22 |
+
accountSettings: 'Account Settings',
|
| 23 |
+
accountDesc: 'Manage your account information and preferences',
|
| 24 |
+
personalInfo: 'Personal Information',
|
| 25 |
+
name: 'Name',
|
| 26 |
+
namePlaceholder: 'Enter your name',
|
| 27 |
+
grade: 'Grade/Class',
|
| 28 |
+
gradePlaceholder: 'e.g., 10th',
|
| 29 |
+
age: 'Age',
|
| 30 |
+
agePlaceholder: 'Enter your age',
|
| 31 |
+
email: 'Email Address',
|
| 32 |
+
emailPlaceholder: 'Enter your email',
|
| 33 |
+
phone: 'Phone Number',
|
| 34 |
+
phonePlaceholder: 'Enter your phone number',
|
| 35 |
+
security: 'Security',
|
| 36 |
+
password: 'Password',
|
| 37 |
+
passwordPlaceholder: 'Enter new password',
|
| 38 |
+
currentPassword: 'Current Password',
|
| 39 |
+
newPassword: 'New Password',
|
| 40 |
+
confirmPassword: 'Confirm Password',
|
| 41 |
+
showPassword: 'Show password',
|
| 42 |
+
hidePassword: 'Hide password',
|
| 43 |
+
dangerZone: 'Danger Zone',
|
| 44 |
+
deleteAccount: 'Delete Account',
|
| 45 |
+
deleteDesc: 'Permanently delete your account and all associated data',
|
| 46 |
+
deleteButton: 'Delete My Account',
|
| 47 |
+
deleteConfirmTitle: 'Are you absolutely sure?',
|
| 48 |
+
deleteConfirmDesc: 'This action cannot be undone. This will permanently delete your account and remove all your data from our servers.',
|
| 49 |
+
cancel: 'Cancel',
|
| 50 |
+
confirmDelete: 'Yes, Delete My Account',
|
| 51 |
+
saveChanges: 'Save Changes',
|
| 52 |
+
changesSaved: 'Changes saved successfully!',
|
| 53 |
+
accountDeleted: 'Account has been deleted',
|
| 54 |
+
language: 'Language',
|
| 55 |
+
optional: '(Optional)'
|
| 56 |
+
},
|
| 57 |
+
hi: {
|
| 58 |
+
settings: 'सेटिंग्स',
|
| 59 |
+
accountSettings: 'खाता सेटिंग्स',
|
| 60 |
+
accountDesc: 'अपनी खाता जानकारी और प्राथमिकताओं का प्रबंधन करें',
|
| 61 |
+
personalInfo: 'व्यक्तिगत जानकारी',
|
| 62 |
+
name: 'नाम',
|
| 63 |
+
namePlaceholder: 'अपना नाम दर्ज करें',
|
| 64 |
+
grade: 'कक्षा',
|
| 65 |
+
gradePlaceholder: 'उदा., 10वीं',
|
| 66 |
+
age: 'उम्र',
|
| 67 |
+
agePlaceholder: 'अपनी उम्र दर्ज करें',
|
| 68 |
+
email: 'ईमेल पता',
|
| 69 |
+
emailPlaceholder: 'अपना ईमेल दर्ज करें',
|
| 70 |
+
phone: 'फ़ोन नंबर',
|
| 71 |
+
phonePlaceholder: 'अपना फ़ोन नंबर दर्ज करें',
|
| 72 |
+
security: 'सुरक्षा',
|
| 73 |
+
password: 'पासवर्ड',
|
| 74 |
+
passwordPlaceholder: 'नया पासवर्ड दर्ज करें',
|
| 75 |
+
currentPassword: 'वर्तमान पासवर्ड',
|
| 76 |
+
newPassword: 'नया पासवर्ड',
|
| 77 |
+
confirmPassword: 'पासवर्ड की पुष्टि करें',
|
| 78 |
+
showPassword: 'पासवर्ड दिखाएं',
|
| 79 |
+
hidePassword: 'पासवर्ड छिपाएं',
|
| 80 |
+
dangerZone: 'खतरे का क्षेत्र',
|
| 81 |
+
deleteAccount: 'खाता हटाएं',
|
| 82 |
+
deleteDesc: 'अपने खाते और सभी संबंधित डेटा को स्थायी रूप से हटाएं',
|
| 83 |
+
deleteButton: 'मेरा खाता हटाएं',
|
| 84 |
+
deleteConfirmTitle: 'क्या आप पूरी तरह निश्चित हैं?',
|
| 85 |
+
deleteConfirmDesc: 'इस कार्रवाई को पूर्ववत नहीं किया जा सकता। यह आपके खाते को स्थायी रूप से हटा देगा और हमारे सर्वर से आपका सभी डेटा हटा देगा।',
|
| 86 |
+
cancel: 'रद्द करें',
|
| 87 |
+
confirmDelete: 'हां, मेरा खाता हटाएं',
|
| 88 |
+
saveChanges: 'परिवर्तन सहेजें',
|
| 89 |
+
changesSaved: 'परिवर्तन सफलतापूर्वक सहेजे गए!',
|
| 90 |
+
accountDeleted: 'खाता हटा दिया गया है',
|
| 91 |
+
language: 'भाषा',
|
| 92 |
+
optional: '(वैकल्पिक)'
|
| 93 |
+
},
|
| 94 |
+
te: {
|
| 95 |
+
settings: 'సెట్టింగ్లు',
|
| 96 |
+
accountSettings: 'ఖాతా సెట్టింగ్లు',
|
| 97 |
+
accountDesc: 'మీ ఖాతా సమాచారం మరియు ప్రాధాన్యతలను నిర్వహించండి',
|
| 98 |
+
personalInfo: 'వ్యక్తిగత సమాచారం',
|
| 99 |
+
name: 'పేరు',
|
| 100 |
+
namePlaceholder: 'మీ పేరు నమోదు చేయండి',
|
| 101 |
+
grade: 'తరగతి',
|
| 102 |
+
gradePlaceholder: 'ఉదా., 10వ తరగతి',
|
| 103 |
+
age: 'వయస్సు',
|
| 104 |
+
agePlaceholder: 'మీ వయస్సును నమోదు చేయండి',
|
| 105 |
+
email: 'ఈమెయిల్ చిరునామా',
|
| 106 |
+
emailPlaceholder: 'మీ ఈమెయిల్ నమోదు చేయండి',
|
| 107 |
+
phone: 'ఫోన్ నంబర్',
|
| 108 |
+
phonePlaceholder: 'మీ ఫోన్ నంబర్ నమోదు చేయండి',
|
| 109 |
+
security: 'భద్రత',
|
| 110 |
+
password: 'పాస్వర్డ్',
|
| 111 |
+
passwordPlaceholder: 'కొత్త పాస్వర్డ్ నమోదు చేయండి',
|
| 112 |
+
currentPassword: 'ప్రస్తుత పాస్వర్డ్',
|
| 113 |
+
newPassword: 'కొత్త పాస్వర్డ్',
|
| 114 |
+
confirmPassword: 'పాస్వర్డ్ను నిర్ధారించండి',
|
| 115 |
+
showPassword: 'పాస్వర్డ్ చూపించు',
|
| 116 |
+
hidePassword: 'పాస్వర్డ్ దాచు',
|
| 117 |
+
dangerZone: 'ప్రమాద ప్రాంతం',
|
| 118 |
+
deleteAccount: 'ఖాతాను తొలగించు',
|
| 119 |
+
deleteDesc: 'మీ ఖాతా మరియు అన్ని సంబంధిత డేటాను శాశ్వతంగా తొలగించండి',
|
| 120 |
+
deleteButton: 'నా ఖాతాను తొలగించు',
|
| 121 |
+
deleteConfirmTitle: 'మీరు ఖచ్చితంగా నిశ్చయించుకున్నారా?',
|
| 122 |
+
deleteConfirmDesc: 'ఈ చర్యను రద్దు చేయలేరు. ఇది మీ ఖాతాను శాశ్వతంగా తొలగిస్తుంది మరియు మా సర్వర్ల నుండి మీ డేటాను తొలగిస్తుంది.',
|
| 123 |
+
cancel: 'రద్దు చేయి',
|
| 124 |
+
confirmDelete: 'అవును, నా ఖాతాను తొలగించు',
|
| 125 |
+
saveChanges: 'మార్పులను సేవ్ చేయి',
|
| 126 |
+
changesSaved: 'మార్పులు విజయవంతంగా సేవ్ చేయబడ్డాయి!',
|
| 127 |
+
accountDeleted: 'ఖాతా తొలగించబడింది',
|
| 128 |
+
language: 'భాష',
|
| 129 |
+
optional: '(ఐచ్ఛికం)'
|
| 130 |
+
},
|
| 131 |
+
ta: {
|
| 132 |
+
settings: 'அமைப்புகள்',
|
| 133 |
+
accountSettings: 'கணக்கு அமைப்புகள்',
|
| 134 |
+
accountDesc: 'உங்கள் கணக்கு தகவல் மற்றும் விருப்பங்களை நிர்வகிக்கவும்',
|
| 135 |
+
personalInfo: 'தனிப்பட்ட தகவல்',
|
| 136 |
+
name: 'பெயர்',
|
| 137 |
+
namePlaceholder: 'உங்கள் பெயரை உள்ளிடவும்',
|
| 138 |
+
grade: 'வகுப்பு',
|
| 139 |
+
gradePlaceholder: 'எ.கா., 10வது',
|
| 140 |
+
age: 'வயது',
|
| 141 |
+
agePlaceholder: 'உங்கள் வயதை உள்ளிடவும்',
|
| 142 |
+
email: 'மின்னஞ்சல் முகவரி',
|
| 143 |
+
emailPlaceholder: 'உங்கள் மின்னஞ்சலை உள்ளிடவும்',
|
| 144 |
+
phone: 'தொலைபேசி எண்',
|
| 145 |
+
phonePlaceholder: 'உங்கள் தொலைபேசி எண்ணை உள்ளிடவும்',
|
| 146 |
+
security: 'பாதுகாப்பு',
|
| 147 |
+
password: 'கடவுச்சொல்',
|
| 148 |
+
passwordPlaceholder: 'புதிய கடவுச்சொல்லை உள்ளிடவும்',
|
| 149 |
+
currentPassword: 'தற்போதைய கடவுச்சொல்',
|
| 150 |
+
newPassword: 'புதிய கடவுச்சொல்',
|
| 151 |
+
confirmPassword: 'கடவுச்சொல்லை உறுதிப்படுத்தவும்',
|
| 152 |
+
showPassword: 'கடவுச்சொல்லைக் காட்டு',
|
| 153 |
+
hidePassword: 'கடவுச்சொல்லை மறை',
|
| 154 |
+
dangerZone: 'ஆபத்து மண்டலம்',
|
| 155 |
+
deleteAccount: 'கணக்கை நீக்கு',
|
| 156 |
+
deleteDesc: 'உங்கள் கணக்கு மற்றும் அனைத்து தொடர்புடைய தரவையும் நிரந்தரமாக நீக்கவும்',
|
| 157 |
+
deleteButton: 'என் கணக்கை நீக்கு',
|
| 158 |
+
deleteConfirmTitle: 'நீங்கள் முற்றிலும் உறுதியாக இருக்கிறீர்களா?',
|
| 159 |
+
deleteConfirmDesc: 'இந்த செயலை மீண்டும் செய்ய முடியாது. இது உங்கள் கணக்கை நிரந்தரமாக நீக்கி, எங்கள் சேவையகங்களில் இருந்து உங்கள் தரவை அகற்றும்.',
|
| 160 |
+
cancel: 'ரத்து செய்',
|
| 161 |
+
confirmDelete: 'ஆம், என் கணக்கை நீக்கு',
|
| 162 |
+
saveChanges: 'மாற்றங்களைச் சேமி',
|
| 163 |
+
changesSaved: 'மாற்றங்கள் வெற்றிகரமாகச் சேமிக்கப்பட்டன!',
|
| 164 |
+
accountDeleted: 'கணக்கு நீக்கப்பட்டது',
|
| 165 |
+
language: 'மொழி',
|
| 166 |
+
optional: '(விருப்பமானது)'
|
| 167 |
+
},
|
| 168 |
+
bn: {
|
| 169 |
+
settings: 'সেটিংস',
|
| 170 |
+
accountSettings: 'অ্যাকাউন্ট সেটিংস',
|
| 171 |
+
accountDesc: 'আপনার অ্যাকাউন্ট তথ্য এবং পছন্দগুলি পরিচালনা করুন',
|
| 172 |
+
personalInfo: 'ব্যক্তিগত তথ্য',
|
| 173 |
+
name: 'নাম',
|
| 174 |
+
namePlaceholder: 'আপনার নাম লিখুন',
|
| 175 |
+
grade: 'শ্রেণী',
|
| 176 |
+
gradePlaceholder: 'যেমন, দশম',
|
| 177 |
+
age: 'বয়স',
|
| 178 |
+
agePlaceholder: 'আপনার বয়স লিখুন',
|
| 179 |
+
email: 'ইমেল ঠিকানা',
|
| 180 |
+
emailPlaceholder: 'আপনার ইমেল লিখুন',
|
| 181 |
+
phone: 'ফোন নম্বর',
|
| 182 |
+
phonePlaceholder: 'আপনার ফোন নম্বর লিখুন',
|
| 183 |
+
security: 'নিরাপত্তা',
|
| 184 |
+
password: 'পাসওয়ার্ড',
|
| 185 |
+
passwordPlaceholder: 'নতুন পাসওয়ার্ড লিখুন',
|
| 186 |
+
currentPassword: 'বর্তমান পাসওয়ার্ড',
|
| 187 |
+
newPassword: 'নতুন পাসওয়ার্ড',
|
| 188 |
+
confirmPassword: 'পাসওয়ার্ড নিশ্চিত করুন',
|
| 189 |
+
showPassword: 'পাসওয়ার্ড দেখান',
|
| 190 |
+
hidePassword: 'পাসওয়ার্ড লুকান',
|
| 191 |
+
dangerZone: 'বিপদ অঞ্চল',
|
| 192 |
+
deleteAccount: 'অ্যাকাউন্ট মুছুন',
|
| 193 |
+
deleteDesc: 'আপনার অ্যাকাউন্ট এবং সমস্ত সংশ্লিষ্ট ডেটা স্থায়ীভাবে মুছুন',
|
| 194 |
+
deleteButton: 'আমার অ্যাকাউন্ট মুছুন',
|
| 195 |
+
deleteConfirmTitle: 'আপনি কি সম্পূর্ণ নিশ্চিত?',
|
| 196 |
+
deleteConfirmDesc: 'এই কাজটি পূর্বাবস্থায় ফেরানো যাবে না। এটি আপনার অ্যাকাউন্টটি স্থায়ীভাবে মুছে দেবে এবং আমাদের সার্ভার থেকে আপনার ডেটা সরিয়ে দেবে।',
|
| 197 |
+
cancel: 'বাতিল করুন',
|
| 198 |
+
confirmDelete: 'হ্যাঁ, আমার অ্যাকাউন্ট মুছুন',
|
| 199 |
+
saveChanges: 'পরিবর্তন সংরক্ষণ করুন',
|
| 200 |
+
changesSaved: 'পরিবর্তন সফলভাবে সংরক্ষিত হয়েছে!',
|
| 201 |
+
accountDeleted: 'অ্যাকাউন্ট মুছে ফেলা হয়েছে',
|
| 202 |
+
language: 'ভাষা',
|
| 203 |
+
optional: '(ঐচ্ছিক)'
|
| 204 |
+
},
|
| 205 |
+
gu: {
|
| 206 |
+
settings: 'સેટિંગ્સ',
|
| 207 |
+
accountSettings: 'એકાઉન્ટ સેટિંગ્સ',
|
| 208 |
+
accountDesc: 'તમારી એકાઉન્ટ માહિતી અને પસંદગીઓ સંચાલિત કરો',
|
| 209 |
+
personalInfo: 'વ્યક્તિગત માહિતી',
|
| 210 |
+
name: 'નામ',
|
| 211 |
+
namePlaceholder: 'તમારું નામ દાખલ કરો',
|
| 212 |
+
grade: 'ધોરણ',
|
| 213 |
+
gradePlaceholder: 'ઉદા., 10મું',
|
| 214 |
+
age: 'ઉંમર',
|
| 215 |
+
agePlaceholder: 'તમારી ઉંમર દાખલ કરો',
|
| 216 |
+
email: 'ઈમેલ સરનામું',
|
| 217 |
+
emailPlaceholder: 'તમારું ઈમેલ દાખલ કરો',
|
| 218 |
+
phone: 'ફોન નંબર',
|
| 219 |
+
phonePlaceholder: 'તમારો ફોન નંબર દાખલ કરો',
|
| 220 |
+
security: 'સુરક્ષા',
|
| 221 |
+
password: 'પાસવર્ડ',
|
| 222 |
+
passwordPlaceholder: 'નવો પાસવર્ડ દાખલ કરો',
|
| 223 |
+
currentPassword: 'વર્તમાન પાસવર્ડ',
|
| 224 |
+
newPassword: 'નવો પાસવર્ડ',
|
| 225 |
+
confirmPassword: 'પાસવર્ડની પુષ્ટિ કરો',
|
| 226 |
+
showPassword: 'પાસવર્ડ બતાવો',
|
| 227 |
+
hidePassword: 'પાસવર્ડ છુપાવો',
|
| 228 |
+
dangerZone: 'જોખમ ક્ષેત્ર',
|
| 229 |
+
deleteAccount: 'એકાઉન્ટ કાઢી નાખો',
|
| 230 |
+
deleteDesc: 'તમારું એકાઉન્ટ અને તમા��� સંલગ્ન ડેટાને કાયમ માટે કાઢી નાખો',
|
| 231 |
+
deleteButton: 'મારું એકાઉન્ટ કાઢી નાખો',
|
| 232 |
+
deleteConfirmTitle: 'શું તમે સંપૂર્ણપણે ખાતરી કરો છો?',
|
| 233 |
+
deleteConfirmDesc: 'આ ક્રિયા પાછી લેવી શકાશે નહીં. આ તમારું એકાઉન્ટ કાયમ માટે કાઢી નાખશે અને અમારા સર્વર પરથી તમારો ડેટા દૂર કરશે.',
|
| 234 |
+
cancel: 'રદ કરો',
|
| 235 |
+
confirmDelete: 'હા, મારું એકાઉન્ટ કાઢી નાખો',
|
| 236 |
+
saveChanges: 'ફેરફારો સાચવો',
|
| 237 |
+
changesSaved: 'ફેરફારો સફળતાપૂર્વક સાચવ્યા!',
|
| 238 |
+
accountDeleted: 'એકાઉન્ટ કાઢી નાખવામાં આવ્યું છે',
|
| 239 |
+
language: 'ભાષા',
|
| 240 |
+
optional: '(વૈકલ્પિક)'
|
| 241 |
+
}
|
| 242 |
+
};
|
| 243 |
+
|
| 244 |
+
export function SettingsPage({ userProfile, setUserProfile, navigateTo }: SettingsPageProps) {
|
| 245 |
+
const t = translations[userProfile.language];
|
| 246 |
+
const [formData, setFormData] = useState({
|
| 247 |
+
name: userProfile.name,
|
| 248 |
+
grade: userProfile.class,
|
| 249 |
+
age: userProfile.age || '',
|
| 250 |
+
email: userProfile.email || '',
|
| 251 |
+
phone: userProfile.phone || '',
|
| 252 |
+
currentPassword: '',
|
| 253 |
+
newPassword: '',
|
| 254 |
+
confirmPassword: ''
|
| 255 |
+
});
|
| 256 |
+
const [showCurrentPassword, setShowCurrentPassword] = useState(false);
|
| 257 |
+
const [showNewPassword, setShowNewPassword] = useState(false);
|
| 258 |
+
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
|
| 259 |
+
const [passwordError, setPasswordError] = useState('');
|
| 260 |
+
const [isSaving, setIsSaving] = useState(false);
|
| 261 |
+
|
| 262 |
+
const handleLanguageChange = (lang: Language) => {
|
| 263 |
+
setUserProfile({ ...userProfile, language: lang });
|
| 264 |
+
// Save language preference to localStorage immediately
|
| 265 |
+
localStorage.setItem('pathfinder_user_language', lang);
|
| 266 |
+
};
|
| 267 |
+
|
| 268 |
+
const handleInputChange = (field: string, value: string) => {
|
| 269 |
+
setFormData({ ...formData, [field]: value });
|
| 270 |
+
// Clear password error when user types
|
| 271 |
+
if (field === 'currentPassword' || field === 'newPassword' || field === 'confirmPassword') {
|
| 272 |
+
setPasswordError('');
|
| 273 |
+
}
|
| 274 |
+
};
|
| 275 |
+
|
| 276 |
+
const handleSave = async () => {
|
| 277 |
+
setIsSaving(true);
|
| 278 |
+
setPasswordError('');
|
| 279 |
+
|
| 280 |
+
try {
|
| 281 |
+
// Validate password change if user is trying to change it
|
| 282 |
+
if (formData.newPassword) {
|
| 283 |
+
// Require current password to be entered
|
| 284 |
+
if (!formData.currentPassword) {
|
| 285 |
+
const errorMsg = userProfile.language === 'en' ? 'Please enter your current password' :
|
| 286 |
+
userProfile.language === 'hi' ? 'कृपया अपना वर्तमान पासवर्ड दर्ज करें' :
|
| 287 |
+
userProfile.language === 'te' ? 'దయచేసి మీ ప్రస్తుత పాస్వర్డ్ను నమోదు చేయండి' :
|
| 288 |
+
userProfile.language === 'ta' ? 'உங்கள் தற்போதைய கடவுச்சொல்லை உள்ளிடவும்' :
|
| 289 |
+
userProfile.language === 'bn' ? 'আপনার বর্তমান পাসওয়ার্ড লিখুন' :
|
| 290 |
+
'કૃપા કરીને તમારો વર્તમાન પાસવર્ડ દાખલ કરો';
|
| 291 |
+
setPasswordError(errorMsg);
|
| 292 |
+
toast.error(errorMsg);
|
| 293 |
+
setIsSaving(false);
|
| 294 |
+
return;
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
// Validate new password length (minimum 8 characters)
|
| 298 |
+
if (formData.newPassword.length < 8) {
|
| 299 |
+
const errorMsg = userProfile.language === 'en' ? 'Password must be at least 8 characters' :
|
| 300 |
+
userProfile.language === 'hi' ? 'पासवर्ड कम से कम 8 अक्षरों का होना चाहिए' :
|
| 301 |
+
userProfile.language === 'te' ? 'పాస్వర్డ్ కనీసం 8 అక్షరాలుగా ఉండాలి' :
|
| 302 |
+
userProfile.language === 'ta' ? 'கடவுச்சொல் குறைந்தது 8 எழுத்துக்கள் இருக்க வேண்டும்' :
|
| 303 |
+
userProfile.language === 'bn' ? 'পাসওয়ার্ড কমপক্ষে 8 অক্ষরের হতে হবে' :
|
| 304 |
+
'પાસવર્ડ ઓછામાં ઓછા 8 અક્ષરોનો હોવો જોઈએ';
|
| 305 |
+
setPasswordError(errorMsg);
|
| 306 |
+
toast.error(errorMsg);
|
| 307 |
+
setIsSaving(false);
|
| 308 |
+
return;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
// Validate new password matches confirm password
|
| 312 |
+
if (formData.newPassword !== formData.confirmPassword) {
|
| 313 |
+
const errorMsg = userProfile.language === 'en' ? 'New password and confirm password do not match' :
|
| 314 |
+
userProfile.language === 'hi' ? 'नया पासवर्ड और पुष्टि पासवर्ड मेल नहीं खाते' :
|
| 315 |
+
userProfile.language === 'te' ? 'కొత్త పాస్వర్డ్ మరియు నిర్ధారణ పాస్వర్డ్ సరిపోలడం లేదు' :
|
| 316 |
+
userProfile.language === 'ta' ? 'புதிய கடவுச்சொல் மற்றும் உறுதிப்படுத்தல் கடவுச்சொல் பொருந்தவில்லை' :
|
| 317 |
+
userProfile.language === 'bn' ? 'নতুন পাসওয়ার্ড এবং নিশ্চিতকরণ পাসওয়ার্ড মেলে না' :
|
| 318 |
+
'નવો પાસવર્ડ અને પુષ્ટિકરણ પાસવર્ડ મેળ ખાતા નથી';
|
| 319 |
+
setPasswordError(errorMsg);
|
| 320 |
+
toast.error(errorMsg);
|
| 321 |
+
setIsSaving(false);
|
| 322 |
+
return;
|
| 323 |
+
}
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
// Prepare update data
|
| 327 |
+
const updateData: any = {
|
| 328 |
+
name: formData.name,
|
| 329 |
+
grade: formData.grade,
|
| 330 |
+
age: formData.age || undefined,
|
| 331 |
+
email: formData.email || undefined,
|
| 332 |
+
phone: formData.phone || undefined,
|
| 333 |
+
};
|
| 334 |
+
|
| 335 |
+
// Add password fields if changing password
|
| 336 |
+
if (formData.newPassword) {
|
| 337 |
+
updateData.currentPassword = formData.currentPassword;
|
| 338 |
+
updateData.newPassword = formData.newPassword;
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
// Call backend API to update profile
|
| 342 |
+
const response = await assessmentService.updateProfile(updateData);
|
| 343 |
+
|
| 344 |
+
if (response.data.success) {
|
| 345 |
+
// Update local state
|
| 346 |
+
const updatedProfile: UserProfile = {
|
| 347 |
+
...userProfile,
|
| 348 |
+
name: response.data.user.name,
|
| 349 |
+
class: response.data.user.grade,
|
| 350 |
+
age: response.data.user.age?.toString(),
|
| 351 |
+
email: response.data.user.email,
|
| 352 |
+
phone: response.data.user.phone,
|
| 353 |
+
};
|
| 354 |
+
|
| 355 |
+
setUserProfile(updatedProfile);
|
| 356 |
+
|
| 357 |
+
// Save to localStorage
|
| 358 |
+
localStorage.setItem('pathfinder_user_name', response.data.user.name);
|
| 359 |
+
localStorage.setItem('pathfinder_user_grade', response.data.user.grade);
|
| 360 |
+
if (response.data.user.age) {
|
| 361 |
+
localStorage.setItem('pathfinder_user_age', response.data.user.age.toString());
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
// Clear password fields after successful save
|
| 365 |
+
setFormData({
|
| 366 |
+
...formData,
|
| 367 |
+
currentPassword: '',
|
| 368 |
+
newPassword: '',
|
| 369 |
+
confirmPassword: ''
|
| 370 |
+
});
|
| 371 |
+
|
| 372 |
+
toast.success(t.changesSaved);
|
| 373 |
+
}
|
| 374 |
+
} catch (error: any) {
|
| 375 |
+
console.error('Error updating profile:', error);
|
| 376 |
+
const errorMessage = error.response?.data?.error || 'Failed to update profile';
|
| 377 |
+
setPasswordError(errorMessage);
|
| 378 |
+
toast.error(errorMessage);
|
| 379 |
+
} finally {
|
| 380 |
+
setIsSaving(false);
|
| 381 |
+
}
|
| 382 |
+
};
|
| 383 |
+
|
| 384 |
+
const handleDeleteAccount = () => {
|
| 385 |
+
toast.success(t.accountDeleted);
|
| 386 |
+
// Reset to default profile
|
| 387 |
+
setUserProfile({
|
| 388 |
+
name: '<Student name>',
|
| 389 |
+
class: '10th',
|
| 390 |
+
language: 'en'
|
| 391 |
+
});
|
| 392 |
+
navigateTo('home');
|
| 393 |
+
};
|
| 394 |
+
|
| 395 |
+
return (
|
| 396 |
+
<div className="min-h-screen bg-gradient-to-br from-blue-50 via-white to-purple-50">
|
| 397 |
+
{/* Header */}
|
| 398 |
+
<header className="bg-white shadow-sm border-b">
|
| 399 |
+
<div className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-4">
|
| 400 |
+
<div className="flex items-center justify-between">
|
| 401 |
+
<div className="flex items-center gap-4">
|
| 402 |
+
<Button
|
| 403 |
+
variant="ghost"
|
| 404 |
+
size="icon"
|
| 405 |
+
onClick={() => navigateTo('home')}
|
| 406 |
+
>
|
| 407 |
+
<ArrowLeft className="h-5 w-5" />
|
| 408 |
+
</Button>
|
| 409 |
+
<h1 className="text-gray-900">{t.settings}</h1>
|
| 410 |
+
</div>
|
| 411 |
+
<LanguageSelector
|
| 412 |
+
language={userProfile.language}
|
| 413 |
+
onLanguageChange={handleLanguageChange}
|
| 414 |
+
/>
|
| 415 |
+
</div>
|
| 416 |
+
</div>
|
| 417 |
+
</header>
|
| 418 |
+
|
| 419 |
+
{/* Main Content */}
|
| 420 |
+
<main className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
| 421 |
+
{/* Account Settings Card */}
|
| 422 |
+
<Card className="mb-6">
|
| 423 |
+
<CardHeader>
|
| 424 |
+
<CardTitle>{t.accountSettings}</CardTitle>
|
| 425 |
+
<CardDescription>{t.accountDesc}</CardDescription>
|
| 426 |
+
</CardHeader>
|
| 427 |
+
<CardContent className="space-y-6">
|
| 428 |
+
{/* Personal Information Section */}
|
| 429 |
+
<div>
|
| 430 |
+
<h3 className="mb-4 text-gray-900">{t.personalInfo}</h3>
|
| 431 |
+
<div className="space-y-4">
|
| 432 |
+
{/* Name */}
|
| 433 |
+
<div>
|
| 434 |
+
<Label htmlFor="name">{t.name}</Label>
|
| 435 |
+
<div className="flex items-center gap-2 mt-2">
|
| 436 |
+
<User className="h-4 w-4 text-gray-400" />
|
| 437 |
+
<Input
|
| 438 |
+
id="name"
|
| 439 |
+
value={formData.name}
|
| 440 |
+
onChange={(e) => handleInputChange('name', e.target.value)}
|
| 441 |
+
placeholder={t.namePlaceholder}
|
| 442 |
+
className="flex-1"
|
| 443 |
+
/>
|
| 444 |
+
</div>
|
| 445 |
+
</div>
|
| 446 |
+
|
| 447 |
+
{/* Grade */}
|
| 448 |
+
<div>
|
| 449 |
+
<Label htmlFor="grade">{t.grade}</Label>
|
| 450 |
+
<div className="flex items-center gap-2 mt-2">
|
| 451 |
+
<GraduationCap className="h-4 w-4 text-gray-400" />
|
| 452 |
+
<Input
|
| 453 |
+
id="grade"
|
| 454 |
+
value={formData.grade}
|
| 455 |
+
onChange={(e) => handleInputChange('grade', e.target.value)}
|
| 456 |
+
placeholder={t.gradePlaceholder}
|
| 457 |
+
className="flex-1"
|
| 458 |
+
/>
|
| 459 |
+
</div>
|
| 460 |
+
</div>
|
| 461 |
+
|
| 462 |
+
{/* Age */}
|
| 463 |
+
<div>
|
| 464 |
+
<Label htmlFor="age">{t.age} {t.optional}</Label>
|
| 465 |
+
<div className="flex items-center gap-2 mt-2">
|
| 466 |
+
<Calendar className="h-4 w-4 text-gray-400" />
|
| 467 |
+
<Input
|
| 468 |
+
id="age"
|
| 469 |
+
type="number"
|
| 470 |
+
value={formData.age}
|
| 471 |
+
onChange={(e) => handleInputChange('age', e.target.value)}
|
| 472 |
+
placeholder={t.agePlaceholder}
|
| 473 |
+
className="flex-1"
|
| 474 |
+
min="10"
|
| 475 |
+
max="25"
|
| 476 |
+
/>
|
| 477 |
+
</div>
|
| 478 |
+
</div>
|
| 479 |
+
|
| 480 |
+
{/* Email */}
|
| 481 |
+
<div>
|
| 482 |
+
<Label htmlFor="email">{t.email} {t.optional}</Label>
|
| 483 |
+
<div className="flex items-center gap-2 mt-2">
|
| 484 |
+
<Mail className="h-4 w-4 text-gray-400" />
|
| 485 |
+
<Input
|
| 486 |
+
id="email"
|
| 487 |
+
type="email"
|
| 488 |
+
value={formData.email}
|
| 489 |
+
onChange={(e) => handleInputChange('email', e.target.value)}
|
| 490 |
+
placeholder={t.emailPlaceholder}
|
| 491 |
+
className="flex-1"
|
| 492 |
+
/>
|
| 493 |
+
</div>
|
| 494 |
+
</div>
|
| 495 |
+
|
| 496 |
+
{/* Phone */}
|
| 497 |
+
<div>
|
| 498 |
+
<Label htmlFor="phone">{t.phone} {t.optional}</Label>
|
| 499 |
+
<div className="flex items-center gap-2 mt-2">
|
| 500 |
+
<Phone className="h-4 w-4 text-gray-400" />
|
| 501 |
+
<Input
|
| 502 |
+
id="phone"
|
| 503 |
+
type="tel"
|
| 504 |
+
value={formData.phone}
|
| 505 |
+
onChange={(e) => handleInputChange('phone', e.target.value)}
|
| 506 |
+
placeholder={t.phonePlaceholder}
|
| 507 |
+
className="flex-1"
|
| 508 |
+
/>
|
| 509 |
+
</div>
|
| 510 |
+
</div>
|
| 511 |
+
</div>
|
| 512 |
+
</div>
|
| 513 |
+
|
| 514 |
+
{/* Security Section */}
|
| 515 |
+
<div className="pt-6 border-t">
|
| 516 |
+
<h3 className="mb-4 text-gray-900">{t.security}</h3>
|
| 517 |
+
<div className="space-y-4">
|
| 518 |
+
{/* Current Password - required when changing password */}
|
| 519 |
+
<div>
|
| 520 |
+
<Label htmlFor="currentPassword">{t.currentPassword}</Label>
|
| 521 |
+
<div className="flex items-center gap-2 mt-2">
|
| 522 |
+
<Lock className="h-4 w-4 text-gray-400" />
|
| 523 |
+
<div className="flex-1 relative">
|
| 524 |
+
<Input
|
| 525 |
+
id="currentPassword"
|
| 526 |
+
type={showCurrentPassword ? "text" : "password"}
|
| 527 |
+
value={formData.currentPassword}
|
| 528 |
+
onChange={(e) => handleInputChange('currentPassword', e.target.value)}
|
| 529 |
+
placeholder={t.currentPassword}
|
| 530 |
+
className={passwordError ? 'border-red-500' : ''}
|
| 531 |
+
/>
|
| 532 |
+
<button
|
| 533 |
+
type="button"
|
| 534 |
+
onClick={() => setShowCurrentPassword(!showCurrentPassword)}
|
| 535 |
+
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600"
|
| 536 |
+
>
|
| 537 |
+
{showCurrentPassword ? (
|
| 538 |
+
<EyeOff className="h-4 w-4" />
|
| 539 |
+
) : (
|
| 540 |
+
<Eye className="h-4 w-4" />
|
| 541 |
+
)}
|
| 542 |
+
</button>
|
| 543 |
+
</div>
|
| 544 |
+
</div>
|
| 545 |
+
</div>
|
| 546 |
+
|
| 547 |
+
{/* New Password */}
|
| 548 |
+
<div>
|
| 549 |
+
<Label htmlFor="newPassword">{t.newPassword}</Label>
|
| 550 |
+
<div className="flex items-center gap-2 mt-2">
|
| 551 |
+
<Lock className="h-4 w-4 text-gray-400" />
|
| 552 |
+
<div className="flex-1 relative">
|
| 553 |
+
<Input
|
| 554 |
+
id="newPassword"
|
| 555 |
+
type={showNewPassword ? "text" : "password"}
|
| 556 |
+
value={formData.newPassword}
|
| 557 |
+
onChange={(e) => handleInputChange('newPassword', e.target.value)}
|
| 558 |
+
placeholder={t.passwordPlaceholder}
|
| 559 |
+
className={passwordError ? 'border-red-500' : ''}
|
| 560 |
+
/>
|
| 561 |
+
<button
|
| 562 |
+
type="button"
|
| 563 |
+
onClick={() => setShowNewPassword(!showNewPassword)}
|
| 564 |
+
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600"
|
| 565 |
+
>
|
| 566 |
+
{showNewPassword ? (
|
| 567 |
+
<EyeOff className="h-4 w-4" />
|
| 568 |
+
) : (
|
| 569 |
+
<Eye className="h-4 w-4" />
|
| 570 |
+
)}
|
| 571 |
+
</button>
|
| 572 |
+
</div>
|
| 573 |
+
</div>
|
| 574 |
+
</div>
|
| 575 |
+
|
| 576 |
+
{/* Confirm Password */}
|
| 577 |
+
<div>
|
| 578 |
+
<Label htmlFor="confirmPassword">{t.confirmPassword}</Label>
|
| 579 |
+
<div className="flex items-center gap-2 mt-2">
|
| 580 |
+
<Lock className="h-4 w-4 text-gray-400" />
|
| 581 |
+
<div className="flex-1 relative">
|
| 582 |
+
<Input
|
| 583 |
+
id="confirmPassword"
|
| 584 |
+
type={showConfirmPassword ? "text" : "password"}
|
| 585 |
+
value={formData.confirmPassword}
|
| 586 |
+
onChange={(e) => handleInputChange('confirmPassword', e.target.value)}
|
| 587 |
+
placeholder={t.confirmPassword}
|
| 588 |
+
className={passwordError ? 'border-red-500' : ''}
|
| 589 |
+
/>
|
| 590 |
+
<button
|
| 591 |
+
type="button"
|
| 592 |
+
onClick={() => setShowConfirmPassword(!showConfirmPassword)}
|
| 593 |
+
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600"
|
| 594 |
+
>
|
| 595 |
+
{showConfirmPassword ? (
|
| 596 |
+
<EyeOff className="h-4 w-4" />
|
| 597 |
+
) : (
|
| 598 |
+
<Eye className="h-4 w-4" />
|
| 599 |
+
)}
|
| 600 |
+
</button>
|
| 601 |
+
</div>
|
| 602 |
+
</div>
|
| 603 |
+
</div>
|
| 604 |
+
|
| 605 |
+
{passwordError && (
|
| 606 |
+
<p className="text-sm text-red-500 mt-1">{passwordError}</p>
|
| 607 |
+
)}
|
| 608 |
+
</div>
|
| 609 |
+
</div>
|
| 610 |
+
|
| 611 |
+
{/* Save Button */}
|
| 612 |
+
<div className="pt-4">
|
| 613 |
+
<Button
|
| 614 |
+
onClick={handleSave}
|
| 615 |
+
disabled={isSaving}
|
| 616 |
+
className="w-full sm:w-auto bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700"
|
| 617 |
+
>
|
| 618 |
+
<Save className="h-4 w-4 mr-2" />
|
| 619 |
+
{isSaving ? (userProfile.language === 'en' ? 'Saving...' : 'सहेजा जा रहा है...') : t.saveChanges}
|
| 620 |
+
</Button>
|
| 621 |
+
</div>
|
| 622 |
+
</CardContent>
|
| 623 |
+
</Card>
|
| 624 |
+
|
| 625 |
+
{/* Danger Zone Card */}
|
| 626 |
+
<Card className="border-red-200">
|
| 627 |
+
<CardHeader>
|
| 628 |
+
<CardTitle className="text-red-600">{t.dangerZone}</CardTitle>
|
| 629 |
+
</CardHeader>
|
| 630 |
+
<CardContent>
|
| 631 |
+
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
|
| 632 |
+
<div>
|
| 633 |
+
<h3 className="text-gray-900">{t.deleteAccount}</h3>
|
| 634 |
+
<p className="text-sm text-gray-600 mt-1">{t.deleteDesc}</p>
|
| 635 |
+
</div>
|
| 636 |
+
<AlertDialog>
|
| 637 |
+
<AlertDialogTrigger asChild>
|
| 638 |
+
<Button variant="destructive" className="gap-2 sm:w-auto w-full">
|
| 639 |
+
<Trash2 className="h-4 w-4" />
|
| 640 |
+
{t.deleteButton}
|
| 641 |
+
</Button>
|
| 642 |
+
</AlertDialogTrigger>
|
| 643 |
+
<AlertDialogContent>
|
| 644 |
+
<AlertDialogHeader>
|
| 645 |
+
<AlertDialogTitle>{t.deleteConfirmTitle}</AlertDialogTitle>
|
| 646 |
+
<AlertDialogDescription>
|
| 647 |
+
{t.deleteConfirmDesc}
|
| 648 |
+
</AlertDialogDescription>
|
| 649 |
+
</AlertDialogHeader>
|
| 650 |
+
<AlertDialogFooter>
|
| 651 |
+
<AlertDialogCancel>{t.cancel}</AlertDialogCancel>
|
| 652 |
+
<AlertDialogAction
|
| 653 |
+
onClick={handleDeleteAccount}
|
| 654 |
+
className="bg-red-600 hover:bg-red-700"
|
| 655 |
+
>
|
| 656 |
+
{t.confirmDelete}
|
| 657 |
+
</AlertDialogAction>
|
| 658 |
+
</AlertDialogFooter>
|
| 659 |
+
</AlertDialogContent>
|
| 660 |
+
</AlertDialog>
|
| 661 |
+
</div>
|
| 662 |
+
</CardContent>
|
| 663 |
+
</Card>
|
| 664 |
+
</main>
|
| 665 |
+
</div>
|
| 666 |
+
);
|
| 667 |
+
}
|
frontend/src/components/SetupPage.tsx
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState } from 'react';
|
| 2 |
+
import { GraduationCap } from 'lucide-react';
|
| 3 |
+
import { Button } from './ui/button';
|
| 4 |
+
import { Input } from './ui/input';
|
| 5 |
+
import { Label } from './ui/label';
|
| 6 |
+
import { Checkbox } from './ui/checkbox';
|
| 7 |
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from './ui/card';
|
| 8 |
+
import { LanguageSelector } from './LanguageSelector';
|
| 9 |
+
import { authService } from '../services/authService';
|
| 10 |
+
import { toast } from 'sonner';
|
| 11 |
+
import type { Page, UserProfile, Language } from '../App';
|
| 12 |
+
|
| 13 |
+
interface SetupPageProps {
|
| 14 |
+
userProfile: UserProfile;
|
| 15 |
+
setUserProfile: (profile: UserProfile) => void;
|
| 16 |
+
navigateTo: (page: Page) => void;
|
| 17 |
+
onSetupComplete: () => void;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
const translations = {
|
| 21 |
+
en: {
|
| 22 |
+
welcome: 'Welcome to PathFinder',
|
| 23 |
+
subtitle: 'Your Career Guidance Companion',
|
| 24 |
+
description: 'Let\'s get started by collecting some basic information',
|
| 25 |
+
nameLabel: 'Name',
|
| 26 |
+
namePlaceholder: 'your name',
|
| 27 |
+
gradeLabel: 'Grade/Class',
|
| 28 |
+
gradePlaceholder: 'e.g. 10',
|
| 29 |
+
ageLabel: 'Age',
|
| 30 |
+
agePlaceholder: 'Enter your age',
|
| 31 |
+
usernameLabel: 'Username',
|
| 32 |
+
usernamePlaceholder: 'Choose a username',
|
| 33 |
+
passwordLabel: 'Password',
|
| 34 |
+
passwordPlaceholder: 'Choose a password',
|
| 35 |
+
alreadyHaveAccount: 'Already have an account?',
|
| 36 |
+
signInInstead: 'Sign In Instead',
|
| 37 |
+
consentLabel: 'I consent to sharing my information for career guidance purposes',
|
| 38 |
+
language: 'Language',
|
| 39 |
+
getStarted: 'Get Started',
|
| 40 |
+
required: 'This field is required',
|
| 41 |
+
consentRequired: 'Please consent to continue',
|
| 42 |
+
note: 'Note: Your information will only be used to provide personalized career guidance and will be kept confidential.'
|
| 43 |
+
},
|
| 44 |
+
hi: {
|
| 45 |
+
welcome: 'पाथफाइंडर में आपका स्वागत है',
|
| 46 |
+
subtitle: 'आपका करियर मार्गदर्शन साथी',
|
| 47 |
+
description: 'आइए कुछ बुनियादी जानकारी एकत्र करके शुरुआत करें',
|
| 48 |
+
nameLabel: 'पूरा नाम',
|
| 49 |
+
namePlaceholder: 'अपना पूरा नाम दर्ज करें',
|
| 50 |
+
gradeLabel: 'कक्षा',
|
| 51 |
+
gradePlaceholder: 'उदा., 10वीं',
|
| 52 |
+
ageLabel: 'उम्र',
|
| 53 |
+
agePlaceholder: 'अपनी उम्र दर्ज करें',
|
| 54 |
+
usernameLabel: 'उपयोगकर्ता नाम',
|
| 55 |
+
usernamePlaceholder: 'एक उपयोगकर्ता नाम चुनें',
|
| 56 |
+
passwordLabel: 'पासवर्ड',
|
| 57 |
+
passwordPlaceholder: 'एक पासवर्ड चुनें',
|
| 58 |
+
alreadyHaveAccount: 'पहले से खाता है?',
|
| 59 |
+
signInInstead: 'इसके बजाय साइन इन करें',
|
| 60 |
+
consentLabel: 'मैं करियर मार्गदर्शन उद्देश्यों के लिए अपनी जानकारी साझा करने के लिए सहमत हूं',
|
| 61 |
+
language: 'भाषा',
|
| 62 |
+
getStarted: 'शुरू करें',
|
| 63 |
+
required: 'यह फ़ील्ड आवश्यक है',
|
| 64 |
+
consentRequired: 'जारी रखने के लिए कृपया सहमति दें',
|
| 65 |
+
note: 'नोट: आपकी जानकारी का उपयोग केवल व्यक्तिगत करियर मार्गदर्शन प्रदान करने के लिए किया जाएगा और इसे गोपनीय रखा जाएगा।'
|
| 66 |
+
},
|
| 67 |
+
te: {
|
| 68 |
+
welcome: 'పాత్ఫైండర్కు స్వాగతం',
|
| 69 |
+
subtitle: 'మీ కెరీర్ మార్గదర్శక సహచరుడు',
|
| 70 |
+
description: 'కొన్ని ప్రాథమిక సమాచారాన్ని సేకరించడం ద్వారా ప్రారంభిద్దాం',
|
| 71 |
+
nameLabel: 'పూర్తి పేరు',
|
| 72 |
+
namePlaceholder: 'మీ పూర్తి పేరును నమోదు చేయండి',
|
| 73 |
+
gradeLabel: 'తరగతి',
|
| 74 |
+
gradePlaceholder: 'ఉదా., 10వ తరగతి',
|
| 75 |
+
ageLabel: 'వయస్సు',
|
| 76 |
+
agePlaceholder: 'మీ వయస్సును నమోదు చేయండి',
|
| 77 |
+
usernameLabel: 'వినియోగదారు పేరు',
|
| 78 |
+
usernamePlaceholder: 'వినియోగదారు పేరును ఎంచుకోండి',
|
| 79 |
+
passwordLabel: 'పాస్వర్డ్',
|
| 80 |
+
passwordPlaceholder: 'పాస్వర్డ్ను ఎంచుకోండి',
|
| 81 |
+
alreadyHaveAccount: 'ఇప్పటికే ఖాతా ఉందా?',
|
| 82 |
+
signInInstead: 'బదులుగా సైన్ ఇన్ చేయండి',
|
| 83 |
+
consentLabel: 'కెరీర్ మార్గదర్శకత్వ ప్రయోజనాల కోసం నా సమాచారాన్ని పంచుకోవడానికి నేను అంగీకరిస్తున్నాను',
|
| 84 |
+
language: 'భాష',
|
| 85 |
+
getStarted: 'ప్రారంభించండి',
|
| 86 |
+
required: 'ఈ ఫీల్డ్ తప్పనిసరి',
|
| 87 |
+
consentRequired: 'కొనసాగించడానికి దయచేసి సమ్మతించండి',
|
| 88 |
+
note: 'గమనిక: మీ సమాచారం వ్యక్తిగత కెరీర్ మార్గదర్శకత్వాన్ని అందించడానికి మాత్రమే ఉపయోగించబడుతుంది మరియు గోప్యంగా ఉంచబడుతుంది.'
|
| 89 |
+
},
|
| 90 |
+
ta: {
|
| 91 |
+
welcome: 'PathFinder க்கு வரவேற்கிறோம்',
|
| 92 |
+
subtitle: 'உங்கள் தொழில் வழிகாட்டி துணை',
|
| 93 |
+
description: 'சில அடிப்படை தகவல்களைச் சேகரித்து தொடங்குவோம்',
|
| 94 |
+
nameLabel: 'முழு பெயர்',
|
| 95 |
+
namePlaceholder: 'உங்கள் முழு பெயரை உள்ளிடவும்',
|
| 96 |
+
gradeLabel: 'வகுப்பு',
|
| 97 |
+
gradePlaceholder: 'எ.கா., 10வது',
|
| 98 |
+
ageLabel: 'வயது',
|
| 99 |
+
agePlaceholder: 'உங்கள் வயதை உள்ளிடவும்',
|
| 100 |
+
usernameLabel: 'பயனர் பெயர்',
|
| 101 |
+
usernamePlaceholder: 'பயனர் பெயரைத் தேர்ந்தெடுக்கவும்',
|
| 102 |
+
passwordLabel: 'கடவுச்சொல்',
|
| 103 |
+
passwordPlaceholder: 'கடவுச்சொல்லைத் தேர்ந்தெடுக்கவும்',
|
| 104 |
+
alreadyHaveAccount: 'ஏற்கனவே கணக்கு உள்ளதா?',
|
| 105 |
+
signInInstead: 'அதற்கு பதிலாக உள்நுழையவும்',
|
| 106 |
+
consentLabel: 'தொழில் வழிகாட்டுதல் நோக்கங்களுக்காக எனது தகவலைப் பகிர்ந்து கொள்ள ஒப்புக்கொள்கிறேன்',
|
| 107 |
+
language: 'மொழி',
|
| 108 |
+
getStarted: 'தொடங்கவும்',
|
| 109 |
+
required: 'இந்த புலம் அவசியம்',
|
| 110 |
+
consentRequired: 'தொடர தயவுசெய்து ஒப்புக்கொள்ளவும்',
|
| 111 |
+
note: 'குறிப்பு: உங்கள் தகவல் தனிப்பயனாக்கப்பட்ட தொழில் வழிகாட்டுதலை வழங்க மட்டுமே பயன்படுத்தப்படும் மற்றும் ரகசியமாக வைக்கப்படும்.'
|
| 112 |
+
},
|
| 113 |
+
bn: {
|
| 114 |
+
welcome: 'PathFinder এ স্বাগতম',
|
| 115 |
+
subtitle: 'আপনার ক্যারিয়ার গাইডেন্স সঙ্গী',
|
| 116 |
+
description: 'চলুন কিছু মৌলিক তথ্য সংগ্রহ করে শুরু করি',
|
| 117 |
+
nameLabel: 'পুরো নাম',
|
| 118 |
+
namePlaceholder: 'আপনার পুরো নাম লিখুন',
|
| 119 |
+
gradeLabel: 'শ্রেণী',
|
| 120 |
+
gradePlaceholder: 'যেমন, দশম',
|
| 121 |
+
ageLabel: 'বয়স',
|
| 122 |
+
agePlaceholder: 'আপনার বয়স লিখুন',
|
| 123 |
+
usernameLabel: 'ব্যবহারকারীর নাম',
|
| 124 |
+
usernamePlaceholder: 'একটি ব্যবহারকারীর নাম বেছে নিন',
|
| 125 |
+
passwordLabel: 'পাসওয়ার্ড',
|
| 126 |
+
passwordPlaceholder: 'একটি পাসওয়ার্ড বেছে নিন',
|
| 127 |
+
alreadyHaveAccount: 'ইতিমধ্যে একটি অ্যাকাউন্ট আছে?',
|
| 128 |
+
signInInstead: 'পরিবর্তে সাইন ইন করুন',
|
| 129 |
+
consentLabel: 'আমি ক্যারিয়ার গাইডেন্স উদ্দেশ্যে আমার তথ্য শেয়ার করতে সম্মত',
|
| 130 |
+
language: 'ভাষা',
|
| 131 |
+
getStarted: 'শুরু করুন',
|
| 132 |
+
required: 'এই ক্ষেত্রটি আবশ্যক',
|
| 133 |
+
consentRequired: 'অগ্রসর হতে অনুগ্রহ করে সম্মতি দিন',
|
| 134 |
+
note: 'নোট: আপনার তথ্য শুধুমাত্র ব্যক্তিগতকৃত ক্যারিয়ার গাইডেন্স প্রদানের জন্য ব্যবহৃত হবে এবং গোপনীয় রাখা হবে।'
|
| 135 |
+
},
|
| 136 |
+
gu: {
|
| 137 |
+
welcome: 'PathFinder માં આપનું સ્વાગત છે',
|
| 138 |
+
subtitle: 'તમારો કારકિર્દી માર્ગદર્શન સાથી',
|
| 139 |
+
description: 'ચાલો કેટલીક મૂળભૂત માહિતી એકત્રિત કરીને શરૂઆત કરીએ',
|
| 140 |
+
nameLabel: 'પૂરું નામ',
|
| 141 |
+
namePlaceholder: 'તમારું પૂરું નામ દાખલ કરો',
|
| 142 |
+
gradeLabel: 'ધોરણ',
|
| 143 |
+
gradePlaceholder: 'ઉદા., 10મું',
|
| 144 |
+
ageLabel: 'ઉંમર',
|
| 145 |
+
agePlaceholder: 'તમારી ઉંમર દાખલ કરો',
|
| 146 |
+
usernameLabel: 'વપરાશકર્તા નામ',
|
| 147 |
+
usernamePlaceholder: 'વપરાશકર્તા નામ પસંદ કરો',
|
| 148 |
+
passwordLabel: 'પાસવર્ડ',
|
| 149 |
+
passwordPlaceholder: 'પાસવર્ડ પસંદ કરો',
|
| 150 |
+
alreadyHaveAccount: 'પહેલેથી જ એકાઉન્ટ છે?',
|
| 151 |
+
signInInstead: 'તેના બદલે સાઇન ઇન કરો',
|
| 152 |
+
consentLabel: 'હું કારકિર્દી માર્ગદર્શન હેતુઓ માટે મારી માહિતી શેર કરવા માટે સંમતિ આપું છું',
|
| 153 |
+
language: 'ભાષા',
|
| 154 |
+
getStarted: 'શરૂઆત કરો',
|
| 155 |
+
required: 'આ ફીલ્ડ જરૂરી છે',
|
| 156 |
+
consentRequired: 'કૃપા કરીને ચાલુ રાખવા માટે સંમતિ આપો',
|
| 157 |
+
note: 'નોંધ: તમારી માહિતીનો ઉપયોગ ફક્ત વ્યક્તિગત કારકિર્દી માર્ગદર્શન પ્રદાન કરવા માટે કરવામાં આવશે અને ગોપનીય રાખવામાં આવશે.'
|
| 158 |
+
}
|
| 159 |
+
};
|
| 160 |
+
|
| 161 |
+
export function SetupPage({ userProfile, setUserProfile, navigateTo, onSetupComplete }: SetupPageProps) {
|
| 162 |
+
const [name, setName] = useState('');
|
| 163 |
+
const [grade, setGrade] = useState('10th');
|
| 164 |
+
const [age, setAge] = useState('');
|
| 165 |
+
const [username, setUsername] = useState('');
|
| 166 |
+
const [password, setPassword] = useState('');
|
| 167 |
+
const [consent, setConsent] = useState(false);
|
| 168 |
+
const [errors, setErrors] = useState<{ [key: string]: string }>({});
|
| 169 |
+
const [loading, setLoading] = useState(false);
|
| 170 |
+
|
| 171 |
+
const lang = userProfile.language;
|
| 172 |
+
const t = translations[lang];
|
| 173 |
+
|
| 174 |
+
const handleLanguageChange = (newLanguage: Language) => {
|
| 175 |
+
setUserProfile({ ...userProfile, language: newLanguage });
|
| 176 |
+
// Immediately save language preference to localStorage so it persists across all screens
|
| 177 |
+
localStorage.setItem('pathfinder_user_language', newLanguage);
|
| 178 |
+
};
|
| 179 |
+
|
| 180 |
+
const validateForm = () => {
|
| 181 |
+
const newErrors: { [key: string]: string } = {};
|
| 182 |
+
|
| 183 |
+
if (!name.trim()) {
|
| 184 |
+
newErrors.name = t.required;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
if (!grade.trim()) {
|
| 188 |
+
newErrors.grade = t.required;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
if (!age.trim()) {
|
| 192 |
+
newErrors.age = t.required;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
if (!username.trim()) {
|
| 196 |
+
newErrors.username = t.required || 'Username is required';
|
| 197 |
+
} else if (username.length < 3) {
|
| 198 |
+
newErrors.username = 'Username must be at least 3 characters';
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
if (!password.trim()) {
|
| 202 |
+
newErrors.password = t.required || 'Password is required';
|
| 203 |
+
} else if (password.length < 8) {
|
| 204 |
+
newErrors.password = 'Password must be at least 8 characters';
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
if (!consent) {
|
| 208 |
+
newErrors.consent = t.consentRequired;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
setErrors(newErrors);
|
| 212 |
+
return Object.keys(newErrors).length === 0;
|
| 213 |
+
};
|
| 214 |
+
|
| 215 |
+
const handleSubmit = async (e: React.FormEvent) => {
|
| 216 |
+
e.preventDefault();
|
| 217 |
+
|
| 218 |
+
if (!validateForm()) {
|
| 219 |
+
return;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
setLoading(true);
|
| 223 |
+
try {
|
| 224 |
+
// Create user account via API
|
| 225 |
+
const user = await authService.setup({
|
| 226 |
+
username: username.trim(),
|
| 227 |
+
password: password,
|
| 228 |
+
name: name.trim(),
|
| 229 |
+
grade: grade.trim(),
|
| 230 |
+
age: age.trim() || undefined,
|
| 231 |
+
email: '',
|
| 232 |
+
phone: '',
|
| 233 |
+
});
|
| 234 |
+
|
| 235 |
+
// Update user profile with data from server
|
| 236 |
+
const updatedProfile: UserProfile = {
|
| 237 |
+
...userProfile,
|
| 238 |
+
name: user.name || name.trim(),
|
| 239 |
+
class: user.grade || grade.trim(),
|
| 240 |
+
age: user.age?.toString() || age.trim(),
|
| 241 |
+
language: userProfile.language,
|
| 242 |
+
};
|
| 243 |
+
setUserProfile(updatedProfile);
|
| 244 |
+
|
| 245 |
+
// Store setup completion in localStorage
|
| 246 |
+
localStorage.setItem('pathfinder_setup_complete', 'true');
|
| 247 |
+
localStorage.setItem('pathfinder_user_name', name.trim());
|
| 248 |
+
localStorage.setItem('pathfinder_user_grade', grade.trim());
|
| 249 |
+
localStorage.setItem('pathfinder_user_age', age.trim());
|
| 250 |
+
localStorage.setItem('pathfinder_user_language', userProfile.language);
|
| 251 |
+
|
| 252 |
+
toast.success('Account created successfully!');
|
| 253 |
+
|
| 254 |
+
// Mark setup as complete
|
| 255 |
+
onSetupComplete();
|
| 256 |
+
|
| 257 |
+
// Navigate to home
|
| 258 |
+
navigateTo('home');
|
| 259 |
+
} catch (error: any) {
|
| 260 |
+
console.error('Setup error:', error);
|
| 261 |
+
const errorData = error.response?.data;
|
| 262 |
+
const errorMessage = errorData?.error || error.message || 'Failed to create account';
|
| 263 |
+
|
| 264 |
+
// Handle field-specific errors
|
| 265 |
+
if (errorData?.details) {
|
| 266 |
+
const fieldErrors: { [key: string]: string } = {};
|
| 267 |
+
Object.entries(errorData.details).forEach(([field, message]) => {
|
| 268 |
+
if (message) {
|
| 269 |
+
fieldErrors[field] = message as string;
|
| 270 |
+
}
|
| 271 |
+
});
|
| 272 |
+
if (Object.keys(fieldErrors).length > 0) {
|
| 273 |
+
setErrors(fieldErrors);
|
| 274 |
+
}
|
| 275 |
+
} else if (errorMessage.includes('Username already exists')) {
|
| 276 |
+
setErrors({ username: 'Username already exists. Please choose another.' });
|
| 277 |
+
} else {
|
| 278 |
+
toast.error(errorMessage);
|
| 279 |
+
}
|
| 280 |
+
} finally {
|
| 281 |
+
setLoading(false);
|
| 282 |
+
}
|
| 283 |
+
};
|
| 284 |
+
|
| 285 |
+
return (
|
| 286 |
+
<div className="min-h-screen bg-gradient-to-br from-blue-50 via-white to-purple-50 flex items-center justify-center p-4">
|
| 287 |
+
<Card className="w-full max-w-md">
|
| 288 |
+
<CardHeader className="text-center space-y-2">
|
| 289 |
+
<div className="flex justify-center mb-4">
|
| 290 |
+
<div className="bg-gradient-to-br from-blue-600 to-purple-600 p-4 rounded-full">
|
| 291 |
+
<GraduationCap className="w-12 h-12 text-white" />
|
| 292 |
+
</div>
|
| 293 |
+
</div>
|
| 294 |
+
<CardTitle className="text-2xl bg-gradient-to-r from-blue-600 to-purple-600 bg-clip-text text-transparent">
|
| 295 |
+
Welcome to CareerBuddy
|
| 296 |
+
</CardTitle>
|
| 297 |
+
<CardDescription className="text-base">
|
| 298 |
+
Your Career Guidance Companion
|
| 299 |
+
</CardDescription>
|
| 300 |
+
<p className="text-sm text-muted-foreground pt-2">
|
| 301 |
+
{t.description}
|
| 302 |
+
</p>
|
| 303 |
+
</CardHeader>
|
| 304 |
+
<CardContent>
|
| 305 |
+
<form onSubmit={handleSubmit} className="space-y-6">
|
| 306 |
+
{/* Language Selector */}
|
| 307 |
+
<div className="space-y-2">
|
| 308 |
+
<Label>{t.language}</Label>
|
| 309 |
+
<LanguageSelector
|
| 310 |
+
language={userProfile.language}
|
| 311 |
+
onLanguageChange={handleLanguageChange}
|
| 312 |
+
/>
|
| 313 |
+
</div>
|
| 314 |
+
|
| 315 |
+
{/* Name Field */}
|
| 316 |
+
<div className="space-y-2">
|
| 317 |
+
<Label htmlFor="name">{t.nameLabel} *</Label>
|
| 318 |
+
<Input
|
| 319 |
+
id="name"
|
| 320 |
+
type="text"
|
| 321 |
+
placeholder={t.namePlaceholder}
|
| 322 |
+
value={name}
|
| 323 |
+
onChange={(e) => setName(e.target.value)}
|
| 324 |
+
className={errors.name ? 'border-red-500' : ''}
|
| 325 |
+
/>
|
| 326 |
+
{errors.name && (
|
| 327 |
+
<p className="text-sm text-red-500">{errors.name}</p>
|
| 328 |
+
)}
|
| 329 |
+
</div>
|
| 330 |
+
|
| 331 |
+
{/* Grade Field */}
|
| 332 |
+
<div className="space-y-2">
|
| 333 |
+
<Label htmlFor="grade">{t.gradeLabel} *</Label>
|
| 334 |
+
<Input
|
| 335 |
+
id="grade"
|
| 336 |
+
type="text"
|
| 337 |
+
placeholder={t.gradePlaceholder}
|
| 338 |
+
value={grade}
|
| 339 |
+
onChange={(e) => setGrade(e.target.value)}
|
| 340 |
+
className={errors.grade ? 'border-red-500' : ''}
|
| 341 |
+
/>
|
| 342 |
+
{errors.grade && (
|
| 343 |
+
<p className="text-sm text-red-500">{errors.grade}</p>
|
| 344 |
+
)}
|
| 345 |
+
</div>
|
| 346 |
+
|
| 347 |
+
{/* Age Field */}
|
| 348 |
+
<div className="space-y-2">
|
| 349 |
+
<Label htmlFor="age">{t.ageLabel} *</Label>
|
| 350 |
+
<Input
|
| 351 |
+
id="age"
|
| 352 |
+
type="number"
|
| 353 |
+
placeholder={t.agePlaceholder}
|
| 354 |
+
value={age}
|
| 355 |
+
onChange={(e) => setAge(e.target.value)}
|
| 356 |
+
className={errors.age ? 'border-red-500' : ''}
|
| 357 |
+
min="10"
|
| 358 |
+
max="25"
|
| 359 |
+
/>
|
| 360 |
+
{errors.age && (
|
| 361 |
+
<p className="text-sm text-red-500">{errors.age}</p>
|
| 362 |
+
)}
|
| 363 |
+
</div>
|
| 364 |
+
|
| 365 |
+
{/* Username Field */}
|
| 366 |
+
<div className="space-y-2">
|
| 367 |
+
<Label htmlFor="username">{t.usernameLabel} *</Label>
|
| 368 |
+
<Input
|
| 369 |
+
id="username"
|
| 370 |
+
type="text"
|
| 371 |
+
placeholder={t.usernamePlaceholder}
|
| 372 |
+
value={username}
|
| 373 |
+
onChange={(e) => setUsername(e.target.value)}
|
| 374 |
+
className={errors.username ? 'border-red-500' : ''}
|
| 375 |
+
/>
|
| 376 |
+
{errors.username && (
|
| 377 |
+
<p className="text-sm text-red-500">{errors.username}</p>
|
| 378 |
+
)}
|
| 379 |
+
</div>
|
| 380 |
+
|
| 381 |
+
{/* Password Field */}
|
| 382 |
+
<div className="space-y-2">
|
| 383 |
+
<Label htmlFor="password">{t.passwordLabel} *</Label>
|
| 384 |
+
<Input
|
| 385 |
+
id="password"
|
| 386 |
+
type="password"
|
| 387 |
+
placeholder={t.passwordPlaceholder}
|
| 388 |
+
value={password}
|
| 389 |
+
onChange={(e) => setPassword(e.target.value)}
|
| 390 |
+
className={errors.password ? 'border-red-500' : ''}
|
| 391 |
+
/>
|
| 392 |
+
{errors.password && (
|
| 393 |
+
<p className="text-sm text-red-500">{errors.password}</p>
|
| 394 |
+
)}
|
| 395 |
+
</div>
|
| 396 |
+
|
| 397 |
+
{/* Consent Checkbox */}
|
| 398 |
+
<div className="space-y-3">
|
| 399 |
+
<div className="flex items-start space-x-3">
|
| 400 |
+
<Checkbox
|
| 401 |
+
id="consent"
|
| 402 |
+
checked={consent}
|
| 403 |
+
onCheckedChange={(checked) => setConsent(checked as boolean)}
|
| 404 |
+
className={errors.consent ? 'border-red-500' : ''}
|
| 405 |
+
/>
|
| 406 |
+
<Label
|
| 407 |
+
htmlFor="consent"
|
| 408 |
+
className="text-sm leading-tight cursor-pointer"
|
| 409 |
+
>
|
| 410 |
+
{t.consentLabel}
|
| 411 |
+
</Label>
|
| 412 |
+
</div>
|
| 413 |
+
{errors.consent && (
|
| 414 |
+
<p className="text-sm text-red-500">{errors.consent}</p>
|
| 415 |
+
)}
|
| 416 |
+
</div>
|
| 417 |
+
|
| 418 |
+
{/* Privacy Note */}
|
| 419 |
+
<div className="bg-blue-50 border border-blue-200 rounded-lg p-3">
|
| 420 |
+
<p className="text-xs text-blue-800">
|
| 421 |
+
{t.note}
|
| 422 |
+
</p>
|
| 423 |
+
</div>
|
| 424 |
+
|
| 425 |
+
{/* Submit Button */}
|
| 426 |
+
<Button
|
| 427 |
+
type="submit"
|
| 428 |
+
className="w-full bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700"
|
| 429 |
+
disabled={loading}
|
| 430 |
+
>
|
| 431 |
+
{loading ? 'Creating Account...' : t.getStarted}
|
| 432 |
+
</Button>
|
| 433 |
+
|
| 434 |
+
{/* Sign In Link */}
|
| 435 |
+
<div className="text-center pt-4 border-t">
|
| 436 |
+
<p className="text-sm text-gray-600 mb-2">
|
| 437 |
+
{t.alreadyHaveAccount}
|
| 438 |
+
</p>
|
| 439 |
+
<Button
|
| 440 |
+
type="button"
|
| 441 |
+
variant="outline"
|
| 442 |
+
className="w-full"
|
| 443 |
+
onClick={() => navigateTo('login')}
|
| 444 |
+
>
|
| 445 |
+
{t.signInInstead}
|
| 446 |
+
</Button>
|
| 447 |
+
</div>
|
| 448 |
+
</form>
|
| 449 |
+
</CardContent>
|
| 450 |
+
</Card>
|
| 451 |
+
</div>
|
| 452 |
+
);
|
| 453 |
+
}
|
frontend/src/components/TestFormPage.tsx
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
frontend/src/components/TestSelectionPage.tsx
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
|
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import { ArrowLeft, Brain, Heart, UserCircle, ChevronRight, Info } from 'lucide-react';
|
| 2 |
+
import { Button } from './ui/button';
|
| 3 |
+
import { Card, CardContent } from './ui/card';
|
| 4 |
+
import { Badge } from './ui/badge';
|
| 5 |
+
import {
|
| 6 |
+
AlertDialog,
|
| 7 |
+
AlertDialogAction,
|
| 8 |
+
AlertDialogCancel,
|
| 9 |
+
AlertDialogContent,
|
| 10 |
+
AlertDialogDescription,
|
| 11 |
+
AlertDialogFooter,
|
| 12 |
+
AlertDialogHeader,
|
| 13 |
+
AlertDialogTitle,
|
| 14 |
+
} from './ui/alert-dialog';
|
| 15 |
+
import { useState } from 'react';
|
| 16 |
+
import type { Page, UserProfile, TestType, Language } from '../App';
|
| 17 |
+
|
| 18 |
+
interface TestSelectionPageProps {
|
| 19 |
+
userProfile: UserProfile;
|
| 20 |
+
navigateTo: (page: Page, testType?: TestType) => void;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
const translations = {
|
| 24 |
+
en: {
|
| 25 |
+
chooseAssessment: 'Choose Assessment',
|
| 26 |
+
selectTest: 'Select a test to begin your career discovery journey',
|
| 27 |
+
tip: 'Tip:',
|
| 28 |
+
tipText: 'Complete all three assessments for the most accurate career recommendations. You can save your progress and continue later!',
|
| 29 |
+
allAssessments: 'All assessments are designed specifically for 10th class students',
|
| 30 |
+
confidential: 'Your responses are confidential and used only for career guidance',
|
| 31 |
+
riasecTitle: 'RIASEC Personality Assessment',
|
| 32 |
+
riasecDesc: 'Discover your career personality type through the RIASEC assessment',
|
| 33 |
+
valuesTitle: 'Values & Motivation',
|
| 34 |
+
valuesDesc: 'Understand what drives you and what matters most in your career',
|
| 35 |
+
personalTitle: 'Personal Information',
|
| 36 |
+
personalDesc: 'Tell us about yourself, your interests, and academic preferences',
|
| 37 |
+
beforeYouBegin: 'Before You Begin',
|
| 38 |
+
startAssessment: 'Start Assessment',
|
| 39 |
+
cancel: 'Cancel',
|
| 40 |
+
riasecInstruction: "You'll now answer questions to help us understand your career personality type using the RIASEC model (Realistic, Investigative, Artistic, Social, Enterprising, Conventional).\n\nFor each question, choose how much you agree — from Strongly Disagree to Strongly Agree.\n\nThere are no right or wrong answers, just what feels true for you.\n\nYour responses will help us identify your top RIASEC personality types and suggest careers that match your interests.",
|
| 41 |
+
valuesInstruction: "This part explores what motivates you and what you value in a career — things like teamwork, creativity, stability, or social impact.\n\nAgain, select how much you agree with each statement on the scale from Strongly Disagree to Strongly Agree.\n\nBe honest — your answers help us find careers that match not just your skills, but also your values and goals.",
|
| 42 |
+
personalInstruction: "Finally, we'd love to know a few quick details to personalize your guidance.\n\nChoose the subjects you most enjoy, share any career interests or goals you have, and tell us your plans after 10th grade.\n\nThis information stays private and is only used to make your results more accurate and useful."
|
| 43 |
+
},
|
| 44 |
+
hi: {
|
| 45 |
+
chooseAssessment: 'मूल्यांकन चुनें',
|
| 46 |
+
selectTest: 'अपनी करियर खोज यात्रा शुरू करने के लिए एक परीक्षा चुनें',
|
| 47 |
+
tip: 'सुझाव:',
|
| 48 |
+
tipText: 'सबसे सटीक करियर अनुशंसाओं के लिए तीनों मूल्यांकन पूरे करें। आप अपनी प्रगति सहेज सकते हैं और बाद में जारी रख सकते हैं!',
|
| 49 |
+
allAssessments: 'सभी मूल्यांकन विशेष रूप से 10वीं कक्षा के छात्रों के लिए डिज़ाइन किए गए हैं',
|
| 50 |
+
confidential: 'आपकी प्रतिक्रियाएं गोपनीय हैं और केवल करियर मार्गदर्शन के लिए उपयोग की जाती हैं',
|
| 51 |
+
riasecTitle: 'RIASEC व्यक्तित्व मूल्यांकन',
|
| 52 |
+
riasecDesc: 'RIASEC मूल्यांकन के माध्यम से अपने करियर व्यक्तित्व प्रकार की खोज करें',
|
| 53 |
+
valuesTitle: 'मूल्य और प्रेरणा',
|
| 54 |
+
valuesDesc: 'समझें कि आपको क्या प्रेरित करता है और आपके करियर में सबसे महत्वपूर्ण क्या है',
|
| 55 |
+
personalTitle: 'व्यक्तिगत जानकारी',
|
| 56 |
+
personalDesc: 'हमें अपने बारे में, अपनी रुचियों और शैक्षणिक प्राथमिकताओं के बारे में बताएं',
|
| 57 |
+
beforeYouBegin: 'शुरू करने से पहले',
|
| 58 |
+
startAssessment: 'मूल्यांकन शुरू करें',
|
| 59 |
+
cancel: 'रद्द करें',
|
| 60 |
+
riasecInstruction: "अब आप RIASEC मॉडल (यथार्थवादी, अन्वेषक, कलात्��क, सामाजिक, उद्यमी, पारंपरिक) का उपयोग करके अपने करियर व्यक्तित्व प्रकार को समझने में मदद करने के लिए प्रश्नों का उत्तर देंगे।\n\nप्रत्येक प्रश्न के लिए, चुनें कि आप कितना सहमत हैं — पूरी तरह असहमत से पूरी तरह सहमत तक।\n\nकोई सही या गलत उत्तर नहीं हैं, बस जो आपके लिए सच लगता है।\n\nआपकी प्रतिक्रियाएं हमें आपके शीर्ष RIASEC व्यक्तित्व प्रकारों की पहचान करने और आपकी रुचियों से मेल खाने वाले करियर सुझाने में मदद करेंगी।",
|
| 61 |
+
valuesInstruction: "यह भाग यह पता लगाता है कि आपको क्या प्रेरित करता है और आप करियर में क्या महत्व देते हैं — जैसे टीम वर्क, रचनात्मकता, स्थिरता, या सामाजिक प्रभाव।\n\nफिर से, पूरी तरह असहमत से पूरी तरह सहमत तक के पैमाने पर प्रत्येक कथन से आप कितना सहमत हैं चुनें।\n\nईमानदार रहें — आपके उत्तर हमें ऐसे करियर खोजने में मदद करते हैं जो न केवल आपके कौशल से बल्कि आपके मूल्यों और लक्ष्यों से भी मेल खाते हैं।",
|
| 62 |
+
personalInstruction: "अंत में, हम आपके मार्गदर्शन को व्यक्तिगत बनाने के लिए कुछ त्वरित विवरण जानना चाहेंगे।\n\nउन विषयों को चुनें जिनका आप सबसे अधिक आनंद लेते हैं, किसी भी करियर रुचि या लक्ष्य को साझा करें, और हमें 10वीं के बाद अपनी योजनाओं के बारे में बताएं।\n\nयह जानकारी निजी रहती है और केवल आपके परिणामों को अधिक सटीक और उपयोगी बनाने के लिए उपयोग की जाती है।"
|
| 63 |
+
},
|
| 64 |
+
te: {
|
| 65 |
+
chooseAssessment: 'అంచనాను ఎంచుకోండి',
|
| 66 |
+
selectTest: 'మీ కెరీర్ అన్వేషణ ప్రయాణాన్ని ప్రారంభించడానికి ఒక పరీక్షను ఎంచుకోండి',
|
| 67 |
+
tip: 'చిట్కా:',
|
| 68 |
+
tipText: 'అత్యంత ఖచ్చితమైన కెరీర్ సిఫార్సుల కోసం మూడు అంచనాలను పూర్తి చేయండి. మీరు మీ పురోగతిని సేవ్ చేసి తరువాత కొనసాగించవచ్చు!',
|
| 69 |
+
allAssessments: 'అన్ని అంచనాలు ప్రత్యేకంగా 10వ తరగతి విద్యార్థుల కోసం రూపొందించబడ్డాయి',
|
| 70 |
+
confidential: 'మీ ప్రతిస్పందనలు గోప్యంగా ఉంటాయి మరియు కెరీర్ మార్గదర్శకత్వం కోసం మాత్రమే ఉపయోగించబడతాయి',
|
| 71 |
+
riasecTitle: 'RIASEC వ్యక్తిత్వ అంచనా',
|
| 72 |
+
riasecDesc: 'RIASEC అంచనా ద్వారా మీ కెరీర్ వ్యక్తిత్వ రకాన్ని కనుగొనండి',
|
| 73 |
+
valuesTitle: 'విలువలు & ప్రేరణ',
|
| 74 |
+
valuesDesc: 'మిమ్మల్ని ఏది ప్రేరేపిస్తుందో మరియు మీ కెరీర్లో అత్యంత ముఖ్యమైనది ఏమిటో అర్థం చేసుకోండి',
|
| 75 |
+
personalTitle: 'వ్యక్తిగత సమాచారం',
|
| 76 |
+
personalDesc: 'మీ గురించి, మీ ఆసక్తుల మరియు విద్యా ప్రాధాన్యతల గురించి మాకు చెప్పండి',
|
| 77 |
+
beforeYouBegin: 'మీరు ప్రారంభించే ముందు',
|
| 78 |
+
startAssessment: 'అంచనాను ప్రారంభించండి',
|
| 79 |
+
cancel: 'రద్దు చేయి',
|
| 80 |
+
riasecInstruction: "RIASEC మోడల్ (వాస్తవిక, పరిశోధనాత్మక, కళాత్మక, సామాజిక, వ్యాపార, సాంప్రదాయిక) ఉపయోగించి మీ కెరీర్ వ్యక్తిత్వ రకాన్ని అర్థం చేసుకోవడంలో సహాయపడే ప్రశ్నలకు మీరు ఇప్పుడు సమాధానం ఇస్తారు।\n\nప్రతి ప్రశ్నకు, మీరు ఎంతగా అంగీకరిస్తారో ఎంచుకోండి — పూర్తిగా అంగీకరించను నుండి పూర్తిగా అంగీకరిస్తున్నాను వరకు।\n\nసరైన లేదా తప్పు సమాధానాలు లేవు, మీకు నిజం అనిపించేది మాత్రమే।\n\nమీ ప్రతిస్పందనలు మీ టాప్ RIASEC వ్యక్తిత్వ రకాలను గుర్తించడంలో మరియు మీ ఆసక్తులకు సరిపోయే కెరీర్లను సూచించడంలో మాకు సహాయపడతాయి।",
|
| 81 |
+
valuesInstruction: "ఈ భాగం మిమ్మల్ని ఏమి ప్రేరేపిస్తుందో మరియు మీరు కెరీర్లో దేనికి విలువ ఇస్తారో అన్వేషిస్తుంది — టీమ్వర్క్, సృజనాత్మకత, స్థిరత్వం లేదా సామాజిక ప్రభావం వంటివి।\n\nమళ్లీ, పూర్తిగా అంగీకరించను నుండి పూర్తిగా అంగీకరిస్తున్నాను వరకు ప్రతి ప్రకటనతో మీరు ఎంతగా అంగీకరిస్తారో ఎంచుకోండి।\n\nనిజాయితీగా ఉండండి — మీ సమాధానాలు మీ నైపుణ్యాలకే కాకుండా మీ విలువలు మరియు లక్ష్యాలకు కూడా సరిపోయే కెరీర్లను కనుగొనడంలో మాకు సహాయపడతాయి।",
|
| 82 |
+
personalInstruction: "చివరగా, మీ మార్గదర్శకత్వాన్ని వ్యక్తిగతీకరించడానికి మేము కొన్ని త్వరిత వివరాలను తెలుసుకోవాలనుకుంటున్నాము।\n\nమీరు ఎక్కువగా ఆనందించే విషయాలను ఎంచుకోండి, మీకు ఉన్న ఏదైనా కెరీర్ ఆసక్తులు లేదా లక్ష్యాలను పంచుకోండి మరియు 10వ తరువాత మీ ప్రణాళికల గురించి మాకు చెప్పండి।\n\nఈ సమాచారం ప్రైవేట్గా ఉంటుంది మరియు మీ ఫలితాలను మరింత ఖచ్చితమైన మరియు ఉపయోగకరంగా చేయడానికి మాత్రమే ఉపయోగించబడుతుంది।"
|
| 83 |
+
},
|
| 84 |
+
ta: {
|
| 85 |
+
chooseAssessment: 'மதிப்பீட்டைத் தேர்வுசெய்க',
|
| 86 |
+
selectTest: 'உங்கள் தொழில் கண்டுபிடிப்பு பயணத்தைத் தொடங்க ஒரு சோதனையைத் தேர்ந்தெடுக்கவும்',
|
| 87 |
+
tip: 'குறிப்பு:',
|
| 88 |
+
tipText: 'மிகவும் துல்லியமான தொழில் பரிந்துரைகளுக்கு மூன்று மதிப்பீடுகளையும் முடிக்கவும். நீங்கள் உங்கள் முன்னேற்றத்தைச் சேமித்து பின்னர் தொடரலாம்!',
|
| 89 |
+
allAssessments: 'அனைத்து மதிப்பீடுகளும் குறிப்பாக 10வது வகுப்பு மாணவர்களுக்காக வடிவமைக்கப்பட்டுள்ளன',
|
| 90 |
+
confidential: 'உங்கள் பதில்கள் ரகசியமானவை மற்றும் தொழில் வழிகாட்டுதலுக்கு மட்டுமே பயன்படுத்தப்படும்',
|
| 91 |
+
riasecTitle: 'RIASEC ஆளுமை மதிப்பீடு',
|
| 92 |
+
riasecDesc: 'RIASEC மதிப்பீடு மூலம் உங்கள் தொழில் ஆளுமை வகையைக் கண்டறியவும்',
|
| 93 |
+
valuesTitle: 'மதிப்புகள் & உந்துதல்',
|
| 94 |
+
valuesDesc: 'உங்களை எது தூண்டுகிறது மற்றும் உங்கள் தொழிலில் மிக முக்கியமானது என்ன என்பதைப் புரிந்துகொள்ளுங்கள்',
|
| 95 |
+
personalTitle: 'தனிப்பட்ட தகவல்',
|
| 96 |
+
personalDesc: 'உங்களைப் பற்றியும், உங்கள் ஆர்வங்கள் மற்றும் கல்வி விருப்பத்தேர்வுகளைப் பற்றியும் எங்களுக்குச் சொல்லுங்கள்',
|
| 97 |
+
beforeYouBegin: 'நீங்கள் தொடங்கும் முன்',
|
| 98 |
+
startAssessment: 'மதிப்பீட்டைத் தொடங்கு',
|
| 99 |
+
cancel: 'ரத்து செய்',
|
| 100 |
+
riasecInstruction: "RIASEC மாதிரியை (உண்மையான, விசாரணை, கலை, சமூக, தொழில்முனைவு, வழமையான) பயன்படுத்தி உங்கள் தொழில் ஆளுமை வகையைப் புரிந்துகொள்ள உதவும் கேள்விகளுக்கு நீங்கள் இப்போது பதிலளிப்பீர்கள்।\n\nஒவ்வொரு கேள்விக்கும், நீங்கள் எவ்வளவு ஒப்புக்கொள்கிறீர்கள் என்பதைத் தேர்வுசெய்க — முற்றிலும் உடன்படவில்லை முதல் முற்றிலும் ஒப்புக்கொள்கிறேன் வரை।\n\nசரியான அல்லது தவறான பதில்கள் இல்லை, உங்களுக்கு உண்மை என்று தோன்றுவதுதான்।\n\nஉங்கள் பதில்கள் உங்கள் முதன்மை RIASEC ஆளுமை வகைகளை அடையாளம் காணவும் உங்கள் ஆர்வங்களுக்கு பொருந்தும் தொழில்களை பரிந்துரைக்கவும் உதவும்।",
|
| 101 |
+
valuesInstruction: "இந்த பகுதி உங்களை எது தூண்டுகிறது மற்றும் நீங்கள் தொழிலில் எதை மதிக்கிறீர்கள் என்பதை ஆராய்கிறது — குழுப்பணி, படைப்பாற்றல், நிலைத்தன்மை அல்லது சமூக தாக்கம் போன்றவை।\n\nமீண்டும், முற்றிலும் உடன்படவில்லை முதல் முற்றிலும் ஒப்புக்கொள்கிறேன் வரையிலான அளவில் ஒவ்வொரு அறிக்கையுடனும் நீங்கள் எவ்வளவு ஒப்புக்கொள்கிறீர்கள் என்பதைத் தேர்ந்தெடுக்கவும்।\n\nநேர்மையாக இருங்கள் — உங்கள் பதில்கள் உங்கள் திறன்களை மட்டுமல்ல, உங்கள் மதிப்புகள் மற்றும் இலக்குகளையும் பொருத்தும் தொழில்களைக் கண்டுபிடிக்க உதவுகின்றன।",
|
| 102 |
+
personalInstruction: "இறுதியாக, உங்கள் வழிகாட்டுதலைத் தனிப்பயனாக்க சில விரைவான விவரங்களை நாங்கள் அறிய விரும்புகிறோம்।\n\nநீங்கள் மிகவும் விரும்பும் பாடங்களைத் தேர்வுசெய்க, உங்களிடம் உள்ள எந்த தொழில் ஆர்வங்கள் அல்லது இலக்குகளையும் பகிர்ந்து கொள்ளுங்கள், மற்றும் 10வது க்குப் பிறகு உங்கள் திட்டங்களைப் பற்றி எங்களுக்குச் சொல்லுங்கள்।\n\nஇந்தத் தகவல் தனிப்பட்டதாக இருக்கும் மற்றும் உங்கள் முடிவுகளை மிகவும் துல்லியமாகவும் பயனுள்ளதாகவும் செய்ய மட்டுமே பயன்படுத்தப்படும்."
|
| 103 |
+
},
|
| 104 |
+
bn: {
|
| 105 |
+
chooseAssessment: 'মূল্যায়ন নির্বাচন করুন',
|
| 106 |
+
selectTest: 'আপনার ক্যারিয়ার আবিষ্কার যাত্রা শুরু করতে একটি পরীক্ষা নির্বাচন করুন',
|
| 107 |
+
tip: 'পরামর্শ:',
|
| 108 |
+
tipText: 'সবচেয়ে সঠিক ক্যারিয়ার সুপারিশের জন্য তিনটি মূল্যায়ন সম্পূর্ণ করুন। আপনি আপনার অগ্রগতি সংরক্ষণ করতে এবং পরে চালিয়ে যেতে পারেন!',
|
| 109 |
+
allAssessments: 'সমস্ত মূল্যায়ন বিশেষভাবে 10 শ্রেণীর শিক্ষার্থীদের জন্য ডিজাইন করা হয়েছে',
|
| 110 |
+
confidential: 'আপনার প্রতিক্রিয়া গোপনীয় এবং শুধুমাত্র ক্যারিয়ার নির্দেশনার জন্য ব্যবহৃত হয়',
|
| 111 |
+
riasecTitle: 'RIASEC ব্যক্তিত্ব মূল্যায়ন',
|
| 112 |
+
riasecDesc: 'RIASEC মূল্যায়নের মাধ্যমে আপনার ক্যারিয়ার ব্যক্তিত্বের ধরন আবিষ্কার করুন',
|
| 113 |
+
valuesTitle: 'মূল্যবোধ ও প্রেরণা',
|
| 114 |
+
valuesDesc: 'বুঝুন কি আপনাকে চালিত করে এবং আপনার ক্যারিয়ারে সবচেয়ে গুরুত্বপূর্ণ কি',
|
| 115 |
+
personalTitle: 'ব্যক্তিগত তথ্য',
|
| 116 |
+
personalDesc: 'আপনার সম্পর্কে, আপনার আগ্রহ এবং শিক্ষাগত পছন্দ সম্পর্কে আমাদের বলুন',
|
| 117 |
+
beforeYouBegin: 'আপনি শুরু করার আগে',
|
| 118 |
+
startAssessment: 'মূল্যায়ন শুরু করুন',
|
| 119 |
+
cancel: 'বাতিল করুন',
|
| 120 |
+
riasecInstruction: "RIASEC মডেল (বাস্তববাদী, অনুসন্ধানমূলক, শৈল্পিক, সামাজিক, উদ্যোগী, প্রচলিত) ব্যবহার করে আপনার ক্যারিয়ার ব্যক্তিত্বের ধরন বুঝতে সাহায্য করার জন্য আপনি এখন প্রশ্নের উত্তর দেবেন।\n\nপ্রতিটি প্রশ্নের জন্য, আপনি কতটা সম্মত তা চয়ন করুন — সম্পূর্ণভাবে অসম্মত থেকে সম্পূর্ণভাবে সম্মত পর্যন্ত।\n\nকোনো সঠিক বা ভুল উত্তর নেই, শুধু যা আপনার কাছে সত্য মনে হয়।\n\nআপনার প্রতিক্রিয়া আমাদের আপনার শীর্ষ RIASEC ব্যক্তিত্বের ধরন চিহ্নিত করতে এবং আপনার আগ্রহের সাথে মিলে যায় এমন ক্যারিয়ার সুপারিশ করতে সাহায্য করবে।",
|
| 121 |
+
valuesInstruction: "এই অংশটি অন্বেষণ করে যে কী আপনাকে অনুপ্রাণিত করে এবং আপনি ক্যারিয়ারে কী মূল্য দেন — যেমন টিমওয়ার্ক, সৃজনশীলতা, স্থিতিশীলতা বা সামাজিক প্রভাব।\n\nআবার, সম্পূর্ণভাবে অসম্মত থেকে সম্পূর্ণভাবে সম্মত পর্যন্ত স্কেলে প্রতিটি বিবৃতির সাথে আপনি কতটা সম্মত তা নির্বাচন করুন।\n\nসৎ থাকুন — আপনার উত্তর আমাদের এমন ক্যারিয়ার খুঁজে পেতে সাহায্য করে যা শুধু আপনার দক্ষতা নয়, আপনার মূল্যবোধ এবং লক্ষ্যের সাথেও মিলে।",
|
| 122 |
+
personalInstruction: "অবশেষে, আপনার নির্দেশনা ব্যক্তিগত করার জন্য আমরা কিছু দ্রুত বিবরণ জানতে চাই।\n\nআপনি সবচেয়ে বেশি উপভোগ করেন এমন বিষয়গুলি চয়ন করুন, আপনার য��কোনো ক্যারিয়ার আগ্রহ বা লক্ষ্য শেয়ার করুন এবং 10 শ্রেণীর পরে আপনার পরিকল্পনা আমাদের বলুন।\n\nএই তথ্য ব্যক্তিগত থাকে এবং শুধুমাত্র আপনার ফলাফল আরও সঠিক এবং দরকারী করতে ব্যবহৃত হয়।"
|
| 123 |
+
},
|
| 124 |
+
gu: {
|
| 125 |
+
chooseAssessment: 'મૂલ્યાંકન પસંદ કરો',
|
| 126 |
+
selectTest: 'તમારી કારકિર્દી શોધ યાત્રા શરૂ કરવા માટે એક પરીક્ષા પસંદ કરો',
|
| 127 |
+
tip: 'ટિપ:',
|
| 128 |
+
tipText: 'સૌથી ચોક્કસ કારકિર્દી ભલામણો માટે ત્રણેય મૂલ્યાંકન પૂર્ણ કરો. તમે તમારી પ્રગતિ સાચવી શકો છો અને પછીથી ચાલુ રાખી શકો છો!',
|
| 129 |
+
allAssessments: 'બધા મૂલ્યાંકન ખાસ કરીને 10મા ધોરણના વિદ્યાર્થીઓ માટે ડિઝાઇન કરવામાં આવ્યા છે',
|
| 130 |
+
confidential: 'તમારા પ્રતિભાવો ગોપનીય છે અને માત્ર કારકિર્દી માર્ગદર્શન માટે ઉપયોગ થાય છે',
|
| 131 |
+
riasecTitle: 'RIASEC વ્યક્તિત્વ મૂલ્યાંકન',
|
| 132 |
+
riasecDesc: 'RIASEC મૂલ્યાંકન દ્વારા તમારા કારકિર્દી વ્યક્તિત્વ પ્રકાર શોધો',
|
| 133 |
+
valuesTitle: 'મૂલ્યો અને પ્રેરણા',
|
| 134 |
+
valuesDesc: 'સમજો કે તમને શું પ્રેરિત કરે છે અને તમારી કારકિર્દીમાં સૌથી મહત્વપૂર્ણ શું છે',
|
| 135 |
+
personalTitle: 'વ્યક્તિગત માહિતી',
|
| 136 |
+
personalDesc: 'તમારા વિશે, તમારી રુચિઓ અને શૈક્ષણિક પસંદગીઓ વિશે અમને જણાવો',
|
| 137 |
+
beforeYouBegin: 'તમે શરૂ કરો તે પહેલાં',
|
| 138 |
+
startAssessment: 'મૂલ્યાંકન શરૂ કરો',
|
| 139 |
+
cancel: 'રદ કરો',
|
| 140 |
+
riasecInstruction: "RIASEC મોડલ (વાસ્તવિક, તપાસ, કલાત્મક, સામાજિક, વ્યવસાયિક, પરંપરાગત) નો ઉપયોગ કરીને તમારા કારકિર્દી વ્યક્તિત્વ પ્રકારને સમજવામાં મદદ કરવા માટે તમે હવે પ્રશ્નોના જવાબ આપશો।\n\nદરેક પ્રશ્ન માટે, તમે કેટલા સહમત છો તે પસંદ કરો — સંપૂર્ણપણે અસહમત થી સંપૂર્ણપણે સહમત સુધી।\n\nકોઈ સાચા કે ખોટા જવાબો નથી, ફક્ત તમારા માટે જે સાચું લાગે છે તે।\n\nતમારા પ્રતિભાવો અમને તમારા ટોપ RIASEC વ્યક્તિત્વ પ્રકારોને ઓળખવામાં અને તમારી રુચિઓ સાથે મેળ ખાતી કારકિર્દી સૂચવવામાં મદદ કરશે।",
|
| 141 |
+
valuesInstruction: "આ ભાગ અન્વેષણ કરે છે કે તમને શું પ્રેરિત કરે છે અને તમે કારકિર્દીમાં શું મહત્વ આપો છો — જેમ કે ટીમવર્ક, સર્જનાત્મકતા, સ્થિરતા અથવા સામાજિક પ્રભાવ।\n\nફરીથી, સંપૂર્ણપણે અસહમત થી સંપૂર્ણપણે સહમત સુધીના સ્કેલ પર દરેક નિવેદન સાથે તમે કેટલા સહમત છો તે પસંદ કરો।\n\nપ્રામાણિક રહો — તમારા જવાબો અમને તમારી કુશળતા જ નહીં, પરંતુ તમારી મૂલ્યો અને લક્ષ્યો સાથે પણ મેળ ખાતી કારકિર્દી શોધવામાં મદદ કરે છે।",
|
| 142 |
+
personalInstruction: "છેલ્લે, અમે તમારા માર્ગદર્શનને વ્યક્તિગત બનાવવા માટે થોડી ઝડપી વિગતો જાણવા માંગીએ છીએ।\n\nતમે સૌથી વધુ આનંદ માણો છો તેવા વિષયો પસંદ કરો, તમારી કોઈપણ કારકિર્દી રુચિઓ અથવા લક્ષ્યો શેર કરો, અને 10મા પછી તમારી યોજનાઓ અમને જણાવો।\n\nઆ માહિતી ખાનગી રહે છે અને માત્ર તમારા પરિણામોને વધુ ચોક્કસ અને ઉપયોગી બનાવવા માટે ઉપયોગમાં લેવાય છે।"
|
| 143 |
+
}
|
| 144 |
+
};
|
| 145 |
+
|
| 146 |
+
const tests = [
|
| 147 |
+
{
|
| 148 |
+
id: 'riasec' as TestType,
|
| 149 |
+
icon: Brain,
|
| 150 |
+
color: 'blue',
|
| 151 |
+
duration: '20 mins',
|
| 152 |
+
questions: 48,
|
| 153 |
+
gradient: 'from-blue-500 to-cyan-500'
|
| 154 |
+
},
|
| 155 |
+
{
|
| 156 |
+
id: 'values' as TestType,
|
| 157 |
+
icon: Heart,
|
| 158 |
+
color: 'purple',
|
| 159 |
+
duration: '15 mins',
|
| 160 |
+
questions: 20,
|
| 161 |
+
gradient: 'from-purple-500 to-pink-500'
|
| 162 |
+
},
|
| 163 |
+
{
|
| 164 |
+
id: 'personal' as TestType,
|
| 165 |
+
icon: UserCircle,
|
| 166 |
+
color: 'green',
|
| 167 |
+
duration: '10 mins',
|
| 168 |
+
questions: 15,
|
| 169 |
+
gradient: 'from-green-500 to-emerald-500'
|
| 170 |
+
}
|
| 171 |
+
];
|
| 172 |
+
|
| 173 |
+
export function TestSelectionPage({ userProfile, navigateTo }: TestSelectionPageProps) {
|
| 174 |
+
const [selectedTest, setSelectedTest] = useState<TestType | null>(null);
|
| 175 |
+
const [showDialog, setShowDialog] = useState(false);
|
| 176 |
+
const t = translations[userProfile.language];
|
| 177 |
+
|
| 178 |
+
const handleTestClick = (testId: TestType) => {
|
| 179 |
+
setSelectedTest(testId);
|
| 180 |
+
setShowDialog(true);
|
| 181 |
+
};
|
| 182 |
+
|
| 183 |
+
const handleStartTest = () => {
|
| 184 |
+
if (selectedTest) {
|
| 185 |
+
setShowDialog(false);
|
| 186 |
+
navigateTo('test-form', selectedTest);
|
| 187 |
+
}
|
| 188 |
+
};
|
| 189 |
+
|
| 190 |
+
const getTestInstruction = (testId: TestType) => {
|
| 191 |
+
switch (testId) {
|
| 192 |
+
case 'riasec':
|
| 193 |
+
return t.riasecInstruction;
|
| 194 |
+
case 'values':
|
| 195 |
+
return t.valuesInstruction;
|
| 196 |
+
case 'personal':
|
| 197 |
+
return t.personalInstruction;
|
| 198 |
+
default:
|
| 199 |
+
return '';
|
| 200 |
+
}
|
| 201 |
+
};
|
| 202 |
+
|
| 203 |
+
const getTestTitle = (testId: TestType) => {
|
| 204 |
+
switch (testId) {
|
| 205 |
+
case 'riasec':
|
| 206 |
+
return t.riasecTitle;
|
| 207 |
+
case 'values':
|
| 208 |
+
return t.valuesTitle;
|
| 209 |
+
case 'personal':
|
| 210 |
+
return t.personalTitle;
|
| 211 |
+
default:
|
| 212 |
+
return '';
|
| 213 |
+
}
|
| 214 |
+
};
|
| 215 |
+
|
| 216 |
+
const getTestDescription = (testId: TestType) => {
|
| 217 |
+
switch (testId) {
|
| 218 |
+
case 'riasec':
|
| 219 |
+
return t.riasecDesc;
|
| 220 |
+
case 'values':
|
| 221 |
+
return t.valuesDesc;
|
| 222 |
+
case 'personal':
|
| 223 |
+
return t.personalDesc;
|
| 224 |
+
default:
|
| 225 |
+
return '';
|
| 226 |
+
}
|
| 227 |
+
};
|
| 228 |
+
|
| 229 |
+
return (
|
| 230 |
+
<div className="min-h-screen">
|
| 231 |
+
{/* Header */}
|
| 232 |
+
<header className="bg-white shadow-sm border-b">
|
| 233 |
+
<div className="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-4">
|
| 234 |
+
<div className="flex items-center gap-4">
|
| 235 |
+
<Button
|
| 236 |
+
variant="ghost"
|
| 237 |
+
size="icon"
|
| 238 |
+
onClick={() => navigateTo('home')}
|
| 239 |
+
>
|
| 240 |
+
<ArrowLeft className="h-5 w-5" />
|
| 241 |
+
</Button>
|
| 242 |
+
<div>
|
| 243 |
+
<h1 className="text-gray-900">{t.chooseAssessment}</h1>
|
| 244 |
+
<p className="text-gray-600 text-sm">{t.selectTest}</p>
|
| 245 |
+
</div>
|
| 246 |
+
</div>
|
| 247 |
+
</div>
|
| 248 |
+
</header>
|
| 249 |
+
|
| 250 |
+
{/* Main Content */}
|
| 251 |
+
<main className="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
| 252 |
+
<div className="mb-8 bg-blue-50 border border-blue-200 rounded-lg p-4">
|
| 253 |
+
<p className="text-sm text-blue-900">
|
| 254 |
+
💡 <strong>{t.tip}</strong> {t.tipText}
|
| 255 |
+
</p>
|
| 256 |
+
</div>
|
| 257 |
+
|
| 258 |
+
<div className="grid md:grid-cols-1 gap-6">
|
| 259 |
+
{tests.map((test) => {
|
| 260 |
+
const Icon = test.icon;
|
| 261 |
+
return (
|
| 262 |
+
<Card
|
| 263 |
+
key={test.id}
|
| 264 |
+
className="cursor-pointer hover:shadow-xl transition-all border-2 border-transparent hover:border-opacity-50 group overflow-hidden"
|
| 265 |
+
style={{ borderColor: `transparent` }}
|
| 266 |
+
onClick={() => handleTestClick(test.id)}
|
| 267 |
+
>
|
| 268 |
+
<CardContent className="p-0">
|
| 269 |
+
<div className="flex flex-col md:flex-row">
|
| 270 |
+
{/* Icon Section */}
|
| 271 |
+
<div className={`bg-gradient-to-br ${test.gradient} p-8 md:w-48 flex items-center justify-center`}>
|
| 272 |
+
<Icon className="h-20 w-20 text-white" />
|
| 273 |
+
</div>
|
| 274 |
+
|
| 275 |
+
{/* Content Section */}
|
| 276 |
+
<div className="flex-1 p-6">
|
| 277 |
+
<div className="flex items-start justify-between mb-3">
|
| 278 |
+
<div>
|
| 279 |
+
<h3 className="text-gray-900 mb-2">{getTestTitle(test.id)}</h3>
|
| 280 |
+
<p className="text-gray-600">{getTestDescription(test.id)}</p>
|
| 281 |
+
</div>
|
| 282 |
+
<ChevronRight className="h-6 w-6 text-gray-400 group-hover:text-gray-600 transition-colors shrink-0 ml-4" />
|
| 283 |
+
</div>
|
| 284 |
+
|
| 285 |
+
<div className="flex flex-wrap gap-3 mt-4">
|
| 286 |
+
<Badge variant="secondary" className="bg-gray-100">
|
| 287 |
+
⏱️ {test.duration}
|
| 288 |
+
</Badge>
|
| 289 |
+
<Badge variant="secondary" className="bg-gray-100">
|
| 290 |
+
📝 {test.questions} questions
|
| 291 |
+
</Badge>
|
| 292 |
+
</div>
|
| 293 |
+
</div>
|
| 294 |
+
</div>
|
| 295 |
+
</CardContent>
|
| 296 |
+
</Card>
|
| 297 |
+
);
|
| 298 |
+
})}
|
| 299 |
+
</div>
|
| 300 |
+
|
| 301 |
+
{/* Bottom Info */}
|
| 302 |
+
<div className="mt-8 text-center">
|
| 303 |
+
<p className="text-gray-600 text-sm">
|
| 304 |
+
{t.allAssessments}
|
| 305 |
+
</p>
|
| 306 |
+
<p className="text-gray-500 text-sm mt-2">
|
| 307 |
+
{t.confidential}
|
| 308 |
+
</p>
|
| 309 |
+
</div>
|
| 310 |
+
</main>
|
| 311 |
+
|
| 312 |
+
{/* Instruction Dialog */}
|
| 313 |
+
<AlertDialog open={showDialog} onOpenChange={setShowDialog}>
|
| 314 |
+
<AlertDialogContent className="max-w-2xl">
|
| 315 |
+
<AlertDialogHeader>
|
| 316 |
+
<div className="flex items-center gap-3 mb-2">
|
| 317 |
+
<div className="p-2 bg-blue-100 rounded-lg">
|
| 318 |
+
<Info className="h-6 w-6 text-blue-600" />
|
| 319 |
+
</div>
|
| 320 |
+
<AlertDialogTitle className="text-xl">
|
| 321 |
+
{t.beforeYouBegin}
|
| 322 |
+
</AlertDialogTitle>
|
| 323 |
+
</div>
|
| 324 |
+
<AlertDialogDescription className="text-base leading-relaxed whitespace-pre-line pt-4">
|
| 325 |
+
{selectedTest && getTestInstruction(selectedTest)}
|
| 326 |
+
</AlertDialogDescription>
|
| 327 |
+
</AlertDialogHeader>
|
| 328 |
+
<AlertDialogFooter>
|
| 329 |
+
<AlertDialogCancel onClick={() => setShowDialog(false)}>
|
| 330 |
+
{t.cancel}
|
| 331 |
+
</AlertDialogCancel>
|
| 332 |
+
<AlertDialogAction onClick={handleStartTest}>
|
| 333 |
+
{t.startAssessment}
|
| 334 |
+
</AlertDialogAction>
|
| 335 |
+
</AlertDialogFooter>
|
| 336 |
+
</AlertDialogContent>
|
| 337 |
+
</AlertDialog>
|
| 338 |
+
</div>
|
| 339 |
+
);
|
| 340 |
+
}
|
frontend/src/components/figma/ImageWithFallback.tsx
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useState } from 'react'
|
| 2 |
+
|
| 3 |
+
const ERROR_IMG_SRC =
|
| 4 |
+
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iODgiIGhlaWdodD0iODgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjMDAwIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBvcGFjaXR5PSIuMyIgZmlsbD0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIzLjciPjxyZWN0IHg9IjE2IiB5PSIxNiIgd2lkdGg9IjU2IiBoZWlnaHQ9IjU2IiByeD0iNiIvPjxwYXRoIGQ9Im0xNiA1OCAxNi0xOCAzMiAzMiIvPjxjaXJjbGUgY3g9IjUzIiBjeT0iMzUiIHI9IjciLz48L3N2Zz4KCg=='
|
| 5 |
+
|
| 6 |
+
export function ImageWithFallback(props: React.ImgHTMLAttributes<HTMLImageElement>) {
|
| 7 |
+
const [didError, setDidError] = useState(false)
|
| 8 |
+
|
| 9 |
+
const handleError = () => {
|
| 10 |
+
setDidError(true)
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
const { src, alt, style, className, ...rest } = props
|
| 14 |
+
|
| 15 |
+
return didError ? (
|
| 16 |
+
<div
|
| 17 |
+
className={`inline-block bg-gray-100 text-center align-middle ${className ?? ''}`}
|
| 18 |
+
style={style}
|
| 19 |
+
>
|
| 20 |
+
<div className="flex items-center justify-center w-full h-full">
|
| 21 |
+
<img src={ERROR_IMG_SRC} alt="Error loading image" {...rest} data-original-url={src} />
|
| 22 |
+
</div>
|
| 23 |
+
</div>
|
| 24 |
+
) : (
|
| 25 |
+
<img src={src} alt={alt} className={className} style={style} {...rest} onError={handleError} />
|
| 26 |
+
)
|
| 27 |
+
}
|
frontend/src/components/ui/accordion.tsx
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import * as React from "react";
|
| 4 |
+
import * as AccordionPrimitive from "@radix-ui/react-accordion@1.2.3";
|
| 5 |
+
import { ChevronDownIcon } from "lucide-react@0.487.0";
|
| 6 |
+
|
| 7 |
+
import { cn } from "./utils";
|
| 8 |
+
|
| 9 |
+
function Accordion({
|
| 10 |
+
...props
|
| 11 |
+
}: React.ComponentProps<typeof AccordionPrimitive.Root>) {
|
| 12 |
+
return <AccordionPrimitive.Root data-slot="accordion" {...props} />;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
function AccordionItem({
|
| 16 |
+
className,
|
| 17 |
+
...props
|
| 18 |
+
}: React.ComponentProps<typeof AccordionPrimitive.Item>) {
|
| 19 |
+
return (
|
| 20 |
+
<AccordionPrimitive.Item
|
| 21 |
+
data-slot="accordion-item"
|
| 22 |
+
className={cn("border-b last:border-b-0", className)}
|
| 23 |
+
{...props}
|
| 24 |
+
/>
|
| 25 |
+
);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
function AccordionTrigger({
|
| 29 |
+
className,
|
| 30 |
+
children,
|
| 31 |
+
...props
|
| 32 |
+
}: React.ComponentProps<typeof AccordionPrimitive.Trigger>) {
|
| 33 |
+
return (
|
| 34 |
+
<AccordionPrimitive.Header className="flex">
|
| 35 |
+
<AccordionPrimitive.Trigger
|
| 36 |
+
data-slot="accordion-trigger"
|
| 37 |
+
className={cn(
|
| 38 |
+
"focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",
|
| 39 |
+
className,
|
| 40 |
+
)}
|
| 41 |
+
{...props}
|
| 42 |
+
>
|
| 43 |
+
{children}
|
| 44 |
+
<ChevronDownIcon className="text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200" />
|
| 45 |
+
</AccordionPrimitive.Trigger>
|
| 46 |
+
</AccordionPrimitive.Header>
|
| 47 |
+
);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
function AccordionContent({
|
| 51 |
+
className,
|
| 52 |
+
children,
|
| 53 |
+
...props
|
| 54 |
+
}: React.ComponentProps<typeof AccordionPrimitive.Content>) {
|
| 55 |
+
return (
|
| 56 |
+
<AccordionPrimitive.Content
|
| 57 |
+
data-slot="accordion-content"
|
| 58 |
+
className="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm"
|
| 59 |
+
{...props}
|
| 60 |
+
>
|
| 61 |
+
<div className={cn("pt-0 pb-4", className)}>{children}</div>
|
| 62 |
+
</AccordionPrimitive.Content>
|
| 63 |
+
);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };
|
frontend/src/components/ui/alert-dialog.tsx
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import * as React from "react";
|
| 4 |
+
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog@1.1.6";
|
| 5 |
+
|
| 6 |
+
import { cn } from "./utils";
|
| 7 |
+
import { buttonVariants } from "./button";
|
| 8 |
+
|
| 9 |
+
function AlertDialog({
|
| 10 |
+
...props
|
| 11 |
+
}: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
|
| 12 |
+
return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
function AlertDialogTrigger({
|
| 16 |
+
...props
|
| 17 |
+
}: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {
|
| 18 |
+
return (
|
| 19 |
+
<AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
|
| 20 |
+
);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
function AlertDialogPortal({
|
| 24 |
+
...props
|
| 25 |
+
}: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
|
| 26 |
+
return (
|
| 27 |
+
<AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />
|
| 28 |
+
);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
function AlertDialogOverlay({
|
| 32 |
+
className,
|
| 33 |
+
...props
|
| 34 |
+
}: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {
|
| 35 |
+
return (
|
| 36 |
+
<AlertDialogPrimitive.Overlay
|
| 37 |
+
data-slot="alert-dialog-overlay"
|
| 38 |
+
className={cn(
|
| 39 |
+
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
| 40 |
+
className,
|
| 41 |
+
)}
|
| 42 |
+
{...props}
|
| 43 |
+
/>
|
| 44 |
+
);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
function AlertDialogContent({
|
| 48 |
+
className,
|
| 49 |
+
...props
|
| 50 |
+
}: React.ComponentProps<typeof AlertDialogPrimitive.Content>) {
|
| 51 |
+
return (
|
| 52 |
+
<AlertDialogPortal>
|
| 53 |
+
<AlertDialogOverlay />
|
| 54 |
+
<AlertDialogPrimitive.Content
|
| 55 |
+
data-slot="alert-dialog-content"
|
| 56 |
+
className={cn(
|
| 57 |
+
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
|
| 58 |
+
className,
|
| 59 |
+
)}
|
| 60 |
+
{...props}
|
| 61 |
+
/>
|
| 62 |
+
</AlertDialogPortal>
|
| 63 |
+
);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
function AlertDialogHeader({
|
| 67 |
+
className,
|
| 68 |
+
...props
|
| 69 |
+
}: React.ComponentProps<"div">) {
|
| 70 |
+
return (
|
| 71 |
+
<div
|
| 72 |
+
data-slot="alert-dialog-header"
|
| 73 |
+
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
| 74 |
+
{...props}
|
| 75 |
+
/>
|
| 76 |
+
);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function AlertDialogFooter({
|
| 80 |
+
className,
|
| 81 |
+
...props
|
| 82 |
+
}: React.ComponentProps<"div">) {
|
| 83 |
+
return (
|
| 84 |
+
<div
|
| 85 |
+
data-slot="alert-dialog-footer"
|
| 86 |
+
className={cn(
|
| 87 |
+
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
| 88 |
+
className,
|
| 89 |
+
)}
|
| 90 |
+
{...props}
|
| 91 |
+
/>
|
| 92 |
+
);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
function AlertDialogTitle({
|
| 96 |
+
className,
|
| 97 |
+
...props
|
| 98 |
+
}: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
|
| 99 |
+
return (
|
| 100 |
+
<AlertDialogPrimitive.Title
|
| 101 |
+
data-slot="alert-dialog-title"
|
| 102 |
+
className={cn("text-lg font-semibold", className)}
|
| 103 |
+
{...props}
|
| 104 |
+
/>
|
| 105 |
+
);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
function AlertDialogDescription({
|
| 109 |
+
className,
|
| 110 |
+
...props
|
| 111 |
+
}: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
|
| 112 |
+
return (
|
| 113 |
+
<AlertDialogPrimitive.Description
|
| 114 |
+
data-slot="alert-dialog-description"
|
| 115 |
+
className={cn("text-muted-foreground text-sm", className)}
|
| 116 |
+
{...props}
|
| 117 |
+
/>
|
| 118 |
+
);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
function AlertDialogAction({
|
| 122 |
+
className,
|
| 123 |
+
...props
|
| 124 |
+
}: React.ComponentProps<typeof AlertDialogPrimitive.Action>) {
|
| 125 |
+
return (
|
| 126 |
+
<AlertDialogPrimitive.Action
|
| 127 |
+
className={cn(buttonVariants(), className)}
|
| 128 |
+
{...props}
|
| 129 |
+
/>
|
| 130 |
+
);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
function AlertDialogCancel({
|
| 134 |
+
className,
|
| 135 |
+
...props
|
| 136 |
+
}: React.ComponentProps<typeof AlertDialogPrimitive.Cancel>) {
|
| 137 |
+
return (
|
| 138 |
+
<AlertDialogPrimitive.Cancel
|
| 139 |
+
className={cn(buttonVariants({ variant: "outline" }), className)}
|
| 140 |
+
{...props}
|
| 141 |
+
/>
|
| 142 |
+
);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
export {
|
| 146 |
+
AlertDialog,
|
| 147 |
+
AlertDialogPortal,
|
| 148 |
+
AlertDialogOverlay,
|
| 149 |
+
AlertDialogTrigger,
|
| 150 |
+
AlertDialogContent,
|
| 151 |
+
AlertDialogHeader,
|
| 152 |
+
AlertDialogFooter,
|
| 153 |
+
AlertDialogTitle,
|
| 154 |
+
AlertDialogDescription,
|
| 155 |
+
AlertDialogAction,
|
| 156 |
+
AlertDialogCancel,
|
| 157 |
+
};
|