Fix CBT submission, add CBT seeds, update features table, layout AI coach chat and add local memory

This commit is contained in:
2026-09-25 12:15:10 +05:30
parent ba4ab2049b
commit 21d7cac565
5 changed files with 70 additions and 92 deletions

View File

@@ -146,7 +146,7 @@ class Attempt(SQLModel, table=True):
started_at: datetime started_at: datetime
submitted_at: Optional[datetime] = None submitted_at: Optional[datetime] = None
time_taken: Optional[int] = None # in seconds time_taken: Optional[int] = None # in seconds
answers: Optional[Dict[str, Any]] = Field(default=None, sa_type=JSON) # Array of {question_id, selected_answer, is_correct, time_spent} answers: Optional[List[Dict[str, Any]]] = Field(default=None, sa_type=JSON) # Array of {question_id, selected_answer, is_correct, time_spent}
score: int = Field(default=0) score: int = Field(default=0)
total_questions: int total_questions: int
accuracy: float = Field(default=0.0) accuracy: float = Field(default=0.0)
@@ -171,7 +171,7 @@ class StudyPlan(SQLModel, table=True):
id: UUID = Field(default_factory=uuid4, primary_key=True) id: UUID = Field(default_factory=uuid4, primary_key=True)
user_id: UUID = Field(foreign_key="user.id") user_id: UUID = Field(foreign_key="user.id")
date: date date: date
tasks: Dict[str, Any] = Field(sa_type=JSON) # Array of {type, description, duration_minutes, status} tasks: List[Dict[str, Any]] = Field(sa_type=JSON) # Array of {type, description, duration_minutes, status}
is_completed: bool = Field(default=False) is_completed: bool = Field(default=False)
generated_at: datetime = Field(default_factory=datetime.utcnow) generated_at: datetime = Field(default_factory=datetime.utcnow)
feedback: Optional[str] = None feedback: Optional[str] = None

View File

@@ -1,52 +1,11 @@
"use client" "use client"
import { TutorChat } from "@/components/AI/TutorChat" import { TutorChat } from "@/components/AI/TutorChat"
import { BrainCircuit, Sparkles, MessageSquare, Lightbulb } from "lucide-react"
import { Card, CardContent } from "@/components/ui/card"
const CAPABILITIES = [
{ icon: <Lightbulb size={16} className="text-yellow-400" />, label: "Concept Explanations", desc: "Step-by-step breakdown of Physics, Chemistry, Maths & Biology topics" },
{ icon: <Sparkles size={16} className="text-[var(--cyan-ai)]" />, label: "Problem Solving", desc: "Full worked solutions with formulas, derivations and shortcuts" },
{ icon: <MessageSquare size={16} className="text-green-400" />, label: "Doubt Clearing", desc: "Ask follow-up questions — the AI remembers context within the session" },
]
export default function TutorChatPage() { export default function TutorChatPage() {
return ( return (
<div className="p-6 md:p-8 space-y-6 animate-in fade-in zoom-in-95 origin-top duration-500 max-w-7xl mx-auto min-h-screen"> <div className="h-[calc(100vh-100px)] w-full flex flex-col pt-4 max-w-7xl mx-auto px-4">
{/* Page Header */} <div className="flex-1 rounded-3xl overflow-hidden border border-border/50 shadow-xl bg-background flex flex-col h-full">
<div className="border-b border-border/50 pb-6">
<div className="flex items-start justify-between gap-4 flex-wrap">
<div>
<h1 className="text-3xl md:text-4xl font-black tracking-tight flex items-center gap-3 mb-2">
<span className="p-2.5 rounded-xl bg-cyan-50 dark:bg-[var(--cyan-ai-10)] border border-cyan-300/60 dark:border-[var(--cyan-ai-20)]">
<BrainCircuit className="text-cyan-700 dark:text-[var(--cyan-ai)]" size={28} />
</span>
AI Tutor — 24/7 Doubt Solver
</h1>
<p className="text-muted-foreground text-base font-medium max-w-2xl pl-1">
Ask any JEE or NEET concept, get step-by-step explanations, formula derivations, and solved examples — instantly.
</p>
</div>
</div>
</div>
{/* Capabilities Strip */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
{CAPABILITIES.map(c => (
<Card key={c.label} className="border-border/50 bg-secondary/10 rounded-2xl">
<CardContent className="p-4 flex items-start gap-3">
<div className="mt-0.5 shrink-0">{c.icon}</div>
<div>
<div className="text-sm font-black">{c.label}</div>
<div className="text-xs text-muted-foreground font-medium mt-0.5">{c.desc}</div>
</div>
</CardContent>
</Card>
))}
</div>
{/* Chat — full height */}
<div className="flex-1 rounded-3xl overflow-hidden border border-border/50 shadow-xl bg-background" style={{ minHeight: "560px" }}>
<TutorChat /> <TutorChat />
</div> </div>
</div> </div>

View File

@@ -515,29 +515,29 @@ export default function MarketingPage() {
</thead> </thead>
<tbody className="divide-y divide-border/30 text-sm md:text-base"> <tbody className="divide-y divide-border/30 text-sm md:text-base">
{[ {[
{ name: "Daily Practice Sheets", free: "1/day", pro: "Unlimited", ai: "Unlimited" }, { name: "Basic Progress Dashboard", pro: true, ai: true },
{ name: "Answer Keys", free: true, pro: true, ai: true }, { name: "Streak Tracking", pro: true, ai: true },
{ name: "Basic Progress Dashboard", free: true, pro: true, ai: true }, { name: "Leaderboard", pro: true, ai: true },
{ name: "Streak Tracking", free: true, pro: true, ai: true }, { name: "Topic-wise Micro-tests", pro: true, ai: true },
{ name: "Leaderboard (City/School)", free: true, pro: true, ai: true }, { name: "Weekly Test Series", pro: true, ai: true },
{ name: "Topic-wise Micro-tests", free: "5/day", pro: "Unlimited", ai: "Unlimited" }, { name: "Full-Length Mock Tests", pro: true, ai: true },
{ name: "Weekly Test Series", free: false, pro: true, ai: true }, { name: "Chapter-wise Progress", pro: true, ai: true },
{ name: "Full-Length Mock Tests", free: false, pro: "4/month", ai: "Unlimited" }, { name: "Doubt Resolution (Community)", pro: true, ai: true },
{ name: "Previous Year Papers", free: false, pro: true, ai: true }, { name: "Monthly Progress Report for Guardian", pro: true, ai: true },
{ name: "Detailed Performance Analytics", free: false, pro: true, ai: true }, { name: "Parents Dashboard", pro: false, ai: true },
{ name: "Chapter-wise Progress", free: false, pro: true, ai: true }, { name: "Daily Practice Sheets", pro: false, ai: true },
{ name: "Doubt Resolution (Community)", free: false, pro: true, ai: true }, { name: "Answer Keys", pro: false, ai: true },
{ name: "Parent Dashboard", free: false, pro: true, ai: true }, { name: "Offline Mode (Download DPS)", pro: false, ai: true },
{ name: "Offline Mode (Download DPS)", free: false, pro: true, ai: true }, { name: "AI Mistake Tracking", pro: false, ai: true },
{ name: "AI Mistake Tracking", free: false, pro: false, ai: true }, { name: "Spaced Repetition", pro: false, ai: true },
{ name: "Spaced Repetition", free: false, pro: false, ai: true }, { name: "Personalized Daily Study Plan", pro: false, ai: true },
{ name: "Personalized Daily Study Plan", free: false, pro: false, ai: true }, { name: "AI Tutor Chat", pro: false, ai: true },
{ name: "AI Tutor Chat", free: false, pro: false, ai: true }, { name: "Exam Readiness Score", pro: false, ai: true },
{ name: "Exam Readiness Score", free: false, pro: false, ai: true }, { name: "Exam Day Strategy", pro: false, ai: true },
{ name: "Exam Day Strategy", free: false, pro: false, ai: true }, { name: "College Predictor", pro: false, ai: true },
{ name: "College Predictor", free: false, pro: false, ai: true }, { name: "Study Time Optimization", pro: false, ai: true },
{ name: "Study Time Optimization", free: false, pro: false, ai: true }, { name: "Detailed Performance Analytics", pro: false, ai: true },
].map((feature, idx) => ( ].map((feature, idx) => (
<tr key={idx} className="hover:bg-background/40 transition-colors"> <tr key={idx} className="hover:bg-background/40 transition-colors">
<td className="p-4 md:p-6 font-medium border-y border-l border-border/30">{feature.name}</td> <td className="p-4 md:p-6 font-medium border-y border-l border-border/30">{feature.name}</td>
{/* <td className="p-4 md:p-6 text-center text-muted-foreground border border-white"> {/* <td className="p-4 md:p-6 text-center text-muted-foreground border border-white">

View File

@@ -120,28 +120,28 @@ export default function UpgradePage() {
</thead> </thead>
<tbody className="divide-y divide-border/30 text-sm md:text-base"> <tbody className="divide-y divide-border/30 text-sm md:text-base">
{[ {[
{ name: "Daily Practice Sheets", free: "1/day", pro: "Unlimited", ai: "Unlimited" }, { name: "Basic Progress Dashboard", pro: true, ai: true },
{ name: "Answer Keys", free: true, pro: true, ai: true }, { name: "Streak Tracking", pro: true, ai: true },
{ name: "Basic Progress Dashboard", free: true, pro: true, ai: true }, { name: "Leaderboard", pro: true, ai: true },
{ name: "Streak Tracking", free: true, pro: true, ai: true }, { name: "Topic-wise Micro-tests", pro: true, ai: true },
{ name: "Leaderboard (City/School)", free: true, pro: true, ai: true }, { name: "Weekly Test Series", pro: true, ai: true },
{ name: "Topic-wise Micro-tests", free: "5/day", pro: "Unlimited", ai: "Unlimited" }, { name: "Full-Length Mock Tests", pro: true, ai: true },
{ name: "Weekly Test Series", free: false, pro: true, ai: true }, { name: "Chapter-wise Progress", pro: true, ai: true },
{ name: "Full-Length Mock Tests", free: false, pro: "4/month", ai: "Unlimited" }, { name: "Doubt Resolution (Community)", pro: true, ai: true },
{ name: "Previous Year Papers", free: false, pro: true, ai: true }, { name: "Monthly Progress Report for Guardian", pro: true, ai: true },
{ name: "Detailed Performance Analytics", free: false, pro: true, ai: true }, { name: "Parents Dashboard", pro: false, ai: true },
{ name: "Chapter-wise Progress", free: false, pro: true, ai: true }, { name: "Daily Practice Sheets", pro: false, ai: true },
{ name: "Doubt Resolution (Community)", free: false, pro: true, ai: true }, { name: "Answer Keys", pro: false, ai: true },
{ name: "Parent Dashboard", free: false, pro: true, ai: true }, { name: "Offline Mode (Download DPS)", pro: false, ai: true },
{ name: "Offline Mode (Download DPS)", free: false, pro: true, ai: true }, { name: "AI Mistake Tracking", pro: false, ai: true },
{ name: "AI Mistake Tracking", free: false, pro: false, ai: true }, { name: "Spaced Repetition", pro: false, ai: true },
{ name: "Spaced Repetition (SM-2)", free: false, pro: false, ai: true }, { name: "Personalized Daily Study Plan", pro: false, ai: true },
{ name: "Personalized Daily Study Plan", free: false, pro: false, ai: true }, { name: "AI Tutor Chat", pro: false, ai: true },
{ name: "AI Tutor Chat", free: false, pro: false, ai: true }, { name: "Exam Readiness Score", pro: false, ai: true },
{ name: "Exam Readiness Score", free: false, pro: false, ai: true }, { name: "Exam Day Strategy", pro: false, ai: true },
{ name: "Exam Day Strategy", free: false, pro: false, ai: true }, { name: "College Predictor", pro: false, ai: true },
{ name: "College Predictor", free: false, pro: false, ai: true }, { name: "Study Time Optimization", pro: false, ai: true },
{ name: "Study Time Optimization", free: false, pro: false, ai: true }, { name: "Detailed Performance Analytics", pro: false, ai: true },
].map((feature, idx) => ( ].map((feature, idx) => (
<tr key={idx} className="hover:bg-background/40 transition-colors"> <tr key={idx} className="hover:bg-background/40 transition-colors">
<td className="p-4 md:p-6 font-medium border-y border-l border-border/30">{feature.name}</td> <td className="p-4 md:p-6 font-medium border-y border-l border-border/30">{feature.name}</td>

View File

@@ -1,4 +1,4 @@
"use client" "use client"
import { fetchWithAuth } from "@/lib/apiClient"; import { fetchWithAuth } from "@/lib/apiClient";
import { useState, useRef, useEffect } from "react" import { useState, useRef, useEffect } from "react"
@@ -33,6 +33,25 @@ export function TutorChat() {
const { userId, loading: userLoading } = useActiveUser(); const { userId, loading: userLoading } = useActiveUser();
// Load from localStorage on mount
useEffect(() => {
if (userId) {
const saved = localStorage.getItem("ai_tutor_chat_" + userId)
if (saved) {
try {
setMessages(JSON.parse(saved))
} catch (e) {}
}
}
}, [userId])
// Save to localStorage whenever messages change
useEffect(() => {
if (userId && messages.length > 1) { // Only save if there's actual history beyond initial message
localStorage.setItem("ai_tutor_chat_" + userId, JSON.stringify(messages))
}
}, [messages, userId])
const scrollToBottom = () => { const scrollToBottom = () => {
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }) messagesEndRef.current?.scrollIntoView({ behavior: "smooth" })
} }