diff --git a/client/package-lock.json b/client/package-lock.json index f10dbcf..9c6976a 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -9,8 +9,9 @@ "version": "0.0.0", "dependencies": { "@radix-ui/react-dialog": "^1.1.11", - "howler": "^2.2.4", "lucide-react": "^0.503.0", + "react": "^19.0.0", + "react-dom": "^19.0.0" "react": "^19.1.0", "react-dom": "^19.0.0", "react-router-dom": "^6.30.0" @@ -3139,12 +3140,6 @@ "node": ">=8" } }, - "node_modules/howler": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/howler/-/howler-2.2.4.tgz", - "integrity": "sha512-iARIBPgcQrwtEr+tALF+rapJ8qSc+Set2GJQl7xT1MQzWaVkFebdJhR3alVlSiUf5U7nAANKuj3aWpwerocD5w==", - "license": "MIT" - }, "node_modules/ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", diff --git a/client/package.json b/client/package.json index ee981eb..c27dfc3 100644 --- a/client/package.json +++ b/client/package.json @@ -11,19 +11,15 @@ }, "dependencies": { "@radix-ui/react-dialog": "^1.1.11", - "howler": "^2.2.4", "lucide-react": "^0.503.0", - "react": "^19.1.0", - "react-dom": "^19.0.0", - "react-router-dom": "^6.30.0" + "react": "^19.0.0", + "react-dom": "^19.0.0" }, "devDependencies": { "@eslint/js": "^9.21.0", "@tailwindcss/postcss": "^4.1.4", "@types/react": "^19.0.10", "@types/react-dom": "^19.0.4", - "@types/react-howler": "^5.2.3", - "@types/react-router-dom": "^5.3.3", "@vitejs/plugin-react": "^4.3.4", "autoprefixer": "^10.4.21", "eslint": "^9.21.0", diff --git a/client/src/components/BackgroundMusic.tsx b/client/src/components/BackgroundMusic.tsx index 8401a32..bc86f9a 100644 --- a/client/src/components/BackgroundMusic.tsx +++ b/client/src/components/BackgroundMusic.tsx @@ -1,27 +1,27 @@ -import { useEffect } from 'react'; +// import { useEffect } from 'react'; -const BackgroundMusic = () => { - useEffect(() => { - const audio = new Audio('/80s-loop-5.wav'); // or '/background-music.mp3' - audio.loop = true; - audio.volume = 0.5; +// const BackgroundMusic = () => { +// useEffect(() => { +// const audio = new Audio('/80s-loop-5.wav'); // or '/background-music.mp3' +// audio.loop = true; +// audio.volume = 0.5; - // Try autoplay inside a user interaction-friendly trigger - const playAudio = () => { - audio.play().catch((err) => { - console.warn('Autoplay blocked by browser:', err); - }); - }; +// // Try autoplay inside a user interaction-friendly trigger +// const playAudio = () => { +// audio.play().catch((err) => { +// console.warn('Autoplay blocked by browser:', err); +// }); +// }; - // Listen for first click - document.body.addEventListener('click', playAudio, { once: true }); +// // Listen for first click +// document.body.addEventListener('click', playAudio, { once: true }); - return () => { - audio.pause(); - }; - }, []); +// return () => { +// audio.pause(); +// }; +// }, []); - return null; -}; +// return null; +// }; -export default BackgroundMusic; +// export default BackgroundMusic; diff --git a/client/src/components/ModalBase.tsx b/client/src/components/ModalBase.tsx new file mode 100644 index 0000000..ed6e0ec --- /dev/null +++ b/client/src/components/ModalBase.tsx @@ -0,0 +1,33 @@ +// src/components/ModalBase.tsx + +"use client"; + +import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from "@/components/ui/dialog"; + +interface ModalBaseProps { + open: boolean; + onOpenChange: (open: boolean) => void; + title: string; + description?: string; + children?: React.ReactNode; +} + +const ModalBase = ({ open, onOpenChange, title, description, children }: ModalBaseProps) => { + return ( + + + + {title} + {description && ( + + {description} + + )} + + {children} + + + ); +}; + +export default ModalBase; diff --git a/client/src/components/ModalBasel.tsx b/client/src/components/ModalBasel.tsx deleted file mode 100644 index 58603f8..0000000 --- a/client/src/components/ModalBasel.tsx +++ /dev/null @@ -1,4 +0,0 @@ -ModalBase.tsx: -- Core styling and backdrop -- Accepts props: isOpen, content, onClose, variant -- Applies shared layout \ No newline at end of file diff --git a/client/src/components/NarrationModal.tsx b/client/src/components/NarrationModal.tsx index bba9540..e60fb14 100644 --- a/client/src/components/NarrationModal.tsx +++ b/client/src/components/NarrationModal.tsx @@ -1,3 +1,27 @@ -- Imports ModalBase -- Passes variant='narration' -- Can include avatar or sprite of Dr. Dan, text-only \ No newline at end of file +// src/components/NarrationModal.tsx + +"use client"; + +import ModalBase from "@/components/ModalBase"; + +interface NarrationModalProps { + isOpen: boolean; + onClose: () => void; + text: string; +} + +const NarrationModal = ({ isOpen, onClose, text }: NarrationModalProps) => { + return ( + { if (!open) onClose(); }} + title="Narration" + description={text} + > + {/* Optional: You can add more children here later if needed */} + + ); +}; + +export default NarrationModal; + diff --git a/client/src/components/ResponseModal.tsx b/client/src/components/ResponseModal.tsx index f13c0b9..da45528 100644 --- a/client/src/components/ResponseModal.tsx +++ b/client/src/components/ResponseModal.tsx @@ -1,4 +1,23 @@ -- Imports ModalBase -- Passes variant='response' -- Includes buttons for Try Again or Next -- Custom feedback messages \ No newline at end of file +"use client" + +import ModalBase from "@/components/ModalBase"; + +interface ResponseModalProps { + isOpen: boolean; + onClose: () => void; + text: string; + +} + +const ResponseModal = ({ isOpen, onClose, text }: ResponseModalProps) => { + return ( + { if(!open) onClose(); }} + title="Narration" + description={text} + > + + ); +}; +export default ResponseModal; \ No newline at end of file diff --git a/client/src/components/ui/dialog.tsx b/client/src/components/ui/dialog.tsx index f018786..620ea34 100644 --- a/client/src/components/ui/dialog.tsx +++ b/client/src/components/ui/dialog.tsx @@ -14,7 +14,7 @@ const DialogPortal = ({ ...props }: DialogPrimitive.DialogPortalProps) => ( ); const DialogOverlay = React.forwardRef< - React.ElementRef, + React.ComponentRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( , + React.ComponentRef, React.ComponentPropsWithoutRef >(({ className, children, ...props }, ref) => ( + ref={ref} + className={cn( + "fixed z-[70] left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-lg rounded-2xl bg-gradient-to-b from-blue-950 to-black text-white p-6 shadow-2xl ring-4 ring-blue-400/50 transition-all duration-500 ease-in-out animate-fadeIn", + className + )} + {...props} +> +
{children}
@@ -63,7 +64,7 @@ const DialogHeader = ({ DialogHeader.displayName = "DialogHeader"; const DialogTitle = React.forwardRef< - React.ElementRef, + React.ComponentRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( , + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +DialogDescription.displayName = DialogPrimitive.Description.displayName; + export { Dialog, DialogTrigger, DialogContent, DialogHeader, - DialogTitle + DialogTitle, + DialogDescription }; diff --git a/client/src/lib/fallbackQuestions.ts b/client/src/lib/fallbackQuestions.ts new file mode 100644 index 0000000..1692caf --- /dev/null +++ b/client/src/lib/fallbackQuestions.ts @@ -0,0 +1,142 @@ +export interface FallbackQuestion { + question: string; + choices: string[]; + correctIndex: number; + } + +export const fallbackQuestion: Record = { + NullByte: [ + { + question: "What is the result of the expression `null + 1` in JavaScript?", + choices: ["1", "TypeError", "NaN", "undefined"], + correctIndex: 2, // "NaN" + }, + { + question: "Which of these values is *falsy* in JavaScript?", + choices: ["0", "'0'", "[]", "{}"], + correctIndex: 0, // 0 + }, + { + question: "How do you check if a variable `x` is exactly null (and not undefined)?", + choices: ["`x == null`", "`x === null`", "`typeof x === 'null'`", "`x instanceof Null`"], + correctIndex: 1, // x === null + }, + ], + + DeBug: [ + { + question: "What is wrong with this JavaScript code?\n\n```js\nlet num = 5;\nconsole.log(numm);\n```", + choices: [ + "SyntaxError", + "ReferenceError", + "TypeError", + "The code runs and logs undefined" + ], + correctIndex: 1, + }, + { + question: "What bug is in this if-statement?\n\n```js\nif (x = 5) {\n console.log(\"Equal!\");\n}\n```", + choices: [ + "It will throw an error", + "It will always be false", + "It assigns instead of compares", + "It compares incorrectly but still works" + ], + correctIndex: 2, + }, + { + question: "What will this function log?\n\n```js\nfunction greet() {\n \"Hello World\";\n}\nconsole.log(greet());\n```", + choices: [ + "Hello World", + "undefined", + "null", + "ReferenceError" + ], + correctIndex: 1, + } + ], + Python: [ + { + question: "What type of value does the expression `3.14` have in Python?", + choices: ["int", "str", "float", "bool"], + correctIndex: 2, + }, + { + question: "Which keyword is used to loop over a sequence in Python?", + choices: ["loop", "iterate", "for", "while"], + correctIndex: 2, + }, + { + question: "What is the value of `my_list[1]`?\n\n```python\nmy_list = [10, 20, 30]\n```", + choices: ["10", "20", "30", "Error"], + correctIndex: 1, + }, +], +Typerroruss: [ + { + question: "What happens if you try to call `.toUpperCase()` on an undefined value in JavaScript?", + choices: [ + "It returns undefined", + "It throws a TypeError", + "It logs 'undefined'", + "It returns null" + ], + correctIndex: 1, + }, + { + question: "What is the result of this JavaScript expression?\n\n```js\n'5' + 3\n```", + choices: [ + "'8'", + "'53'", + "8", + "Error" + ], + correctIndex: 1, + }, + { + question: "What happens if you access a property on `null` in JavaScript?", + choices: [ + "It throws a ReferenceError", + "It throws a TypeError", + "It returns null", + "It returns undefined" + ], + correctIndex: 1, + } +], +Codezilla: [ + { + question: "In a MongoDB query, what does the `$set` operator do?", + choices: [ + "Deletes fields from a document", + "Adds a new document to the collection", + "Updates specific fields in a document", + "Finds documents that match a condition" + ], + correctIndex: 2, + }, + { + question: "In React, why is providing a unique `key` prop important when rendering lists?", + choices: [ + "It helps React optimize rendering", + "It makes the list sortable", + "It binds event handlers automatically", + "It prevents API calls" + ], + correctIndex: 0, + }, + { + question: "What happens if error-handling middleware is placed before route handlers in Express?", + choices: [ + "It will not catch any errors", + "It will prevent routes from being reached", + "It will automatically reroute to '/'", + "It improves performance" + ], + correctIndex: 1, + } +], +} + + + diff --git a/client/tailwind.config.js b/client/tailwind.config.js index b5a69a8..6be31eb 100644 --- a/client/tailwind.config.js +++ b/client/tailwind.config.js @@ -5,7 +5,17 @@ module.exports = { "./src/**/*.{js,ts,jsx,tsx}", ], theme: { - extend: {}, + extend: { + keyframes: { + fadeIn: { + '0%': { opacity: 0 }, + '100%': { opacity: 1}, + }, + }, + animation: { + fadeIn: 'fadeIn 0.5s ease-in-out', + }, + }, }, plugins: [], } diff --git a/et --soft HEAD~1 b/et --soft HEAD~1 new file mode 100644 index 0000000..4848843 --- /dev/null +++ b/et --soft HEAD~1 @@ -0,0 +1,30 @@ +4724f5b (HEAD -> feature/Modals) HEAD@{0}: commit: committing to pull +9f2756b (group-origin/main, group-origin/HEAD) HEAD@{1}: pull group-origin main: Fast-forward +2e42503 (group-origin/feature/tts-integration, tts) HEAD@{2}: reset: moving to HEAD +2e42503 (group-origin/feature/tts-integration, tts) HEAD@{3}: checkout: moving from main to feature/Modals +9631bfb (main) HEAD@{4}: reset: moving to HEAD +9631bfb (main) HEAD@{5}: pull group-origin main: Fast-forward +9409cce HEAD@{6}: checkout: moving from feature/Modals to main +2e42503 (group-origin/feature/tts-integration, tts) HEAD@{7}: reset: moving to HEAD +2e42503 (group-origin/feature/tts-integration, tts) HEAD@{8}: reset: moving to HEAD~1 +5e2b808 HEAD@{9}: commit: added minion to promptbuilder and beginning code for models +2e42503 (group-origin/feature/tts-integration, tts) HEAD@{10}: checkout: moving from main to feature/Modals +9409cce HEAD@{11}: reset: moving to HEAD +9409cce HEAD@{12}: checkout: moving from feature/Modals to main +2e42503 (group-origin/feature/tts-integration, tts) HEAD@{13}: checkout: moving from tts to feature/Modals +2e42503 (group-origin/feature/tts-integration, tts) HEAD@{14}: commit: updated gitignore +82dd80c HEAD@{15}: commit (merge): Merge group main with my changes +c7b497a HEAD@{16}: commit: initial commit +944ba98 HEAD@{17}: pull origin main: Merge made by the 'ort' strategy. +5565cb0 (origin/tts) HEAD@{18}: reset: moving to HEAD +5565cb0 (origin/tts) HEAD@{19}: commit: created tts for characters +fe4b593 (origin/modals, modals) HEAD@{20}: checkout: moving from modals to tts +fe4b593 (origin/modals, modals) HEAD@{21}: commit: set up dir tree +f21ef68 HEAD@{22}: commit: updated code structure with modals, added tailwind framework and installs for testing modals +dc5f79c (origin/OpenAI, OpenAI) HEAD@{23}: checkout: moving from OpenAI to modals +dc5f79c (origin/OpenAI, OpenAI) HEAD@{24}: commit: added speech model to server +2b056df HEAD@{25}: commit: Added openai route, index.ts, promptbuilder +9409cce HEAD@{26}: checkout: moving from main to OpenAI +9409cce HEAD@{27}: commit: initial commit +f853f34 HEAD@{28}: Branch: renamed refs/heads/master to refs/heads/main +f853f34 HEAD@{30}: commit (initial): first commit diff --git a/package-lock.json b/package-lock.json index f691d2b..8e7872d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,31 +14,23 @@ "bcrypt": "^5.1.1", "cors": "^2.8.5", "dotenv": "^16.5.0", -<<<<<<< HEAD "express": "^5.1.0", "mongoose": "^8.13.3", -======= - "express": "^4.17.1", ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "openai": "^4.95.1", "react": "^19.1.0" }, "devDependencies": { -<<<<<<< HEAD "@types/express": "^5.0.1", -======= - "@types/bcrypt": "^5.0.2", - "@types/express": "^4.17.17", - "@types/jsonwebtoken": "^9.0.9", ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "@types/mongoose": "^5.11.96", "@types/node": "^22.14.1", "concurrently": "^9.1.2", + "nodemon": "^3.1.10", - "ts-node": "^10.9.2", +"tailwindcss": "^4.1.4", +"ts-node": "^10.9.2", "typescript": "^5.8.3" - } - }, + }, + "node_modules/@apollo/protobufjs": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/@apollo/protobufjs/-/protobufjs-1.2.7.tgz", @@ -376,8 +368,6 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, -<<<<<<< HEAD -======= "node_modules/@mapbox/node-pre-gyp": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.11.tgz", @@ -398,22 +388,16 @@ "node-pre-gyp": "bin/node-pre-gyp" } }, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "node_modules/@mongodb-js/saslprep": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.2.2.tgz", "integrity": "sha512-EB0O3SCSNRUFk66iRCpI+cXzIjdswfCs7F6nOC3RAGJ7xr5YhaicvsRwJ9eyzYvYRlCSDUO/c7g4yNulxKC1WA==", -<<<<<<< HEAD -======= "dev": true, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "license": "MIT", "dependencies": { "sparse-bitfield": "^3.0.3" } }, -<<<<<<< HEAD -======= "node_modules/@protobufjs/aspromise": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", @@ -478,7 +462,6 @@ "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==", "license": "BSD-3-Clause" }, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "node_modules/@tsconfig/node10": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", @@ -623,16 +606,8 @@ "integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==", "dev": true, "license": "MIT" - }, - "node_modules/@types/mongoose": { - "version": "5.11.96", - "resolved": "https://registry.npmjs.org/@types/mongoose/-/mongoose-5.11.96.tgz", - "integrity": "sha512-keiY22ljJtXyM7osgScmZOHV6eL5VFUD5tQumlu+hjS++HND5nM8jNEdj5CSWfKIJpVwQfPuwQ2SfBqUnCAVRw==", - "dev": true, - "license": "MIT", - "dependencies": { - "mongoose": "*" - } + } + }, "node_modules/@types/node": { "version": "22.15.2", @@ -690,34 +665,25 @@ "version": "7.0.3", "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", "integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==", -<<<<<<< HEAD -======= "dev": true, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "license": "MIT" }, "node_modules/@types/whatwg-url": { "version": "11.0.5", "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.5.tgz", "integrity": "sha512-coYR071JRaHa+xoEvvYqvnIHaVqaYrLPbsufM9BF63HkwI5Lgmy2QR8Q5K/lYDYo5AK82wOvSOS0UsLTpTG7uQ==", -<<<<<<< HEAD -======= "dev": true, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "license": "MIT", "dependencies": { "@types/webidl-conversions": "*" } }, -<<<<<<< HEAD -======= "node_modules/abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", "license": "ISC" }, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "node_modules/abort-controller": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", @@ -1191,10 +1157,7 @@ "version": "6.10.3", "resolved": "https://registry.npmjs.org/bson/-/bson-6.10.3.tgz", "integrity": "sha512-MTxGsqgYTwfshYWTRdmZRC+M7FnG1b4y7RO7p2k3X24Wq0yv1m77Wsj0BzlPzd/IowgESfsruQCUToa7vbOpPQ==", -<<<<<<< HEAD -======= "dev": true, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "license": "Apache-2.0", "engines": { "node": ">=16.20.1" @@ -2207,15 +2170,6 @@ "node": ">=12.0.0" } }, - "node_modules/kareem": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.6.3.tgz", - "integrity": "sha512-C3iHfuGUXK2u8/ipq9LfjFfXFxAZMQJJq7vLS45r3D9Y2xQ/m4S8zaR4zMLFWh9AsNPXmcFfUDhTEO8UIC/V6Q==", - "license": "Apache-2.0", - "engines": { - "node": ">=12.0.0" - } - }, "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", @@ -2313,10 +2267,7 @@ "version": "1.5.0", "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", -<<<<<<< HEAD -======= "dev": true, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "license": "MIT" }, "node_modules/merge-descriptors": { @@ -2379,12 +2330,6 @@ "node": "*" } }, -<<<<<<< HEAD - "node_modules/mongodb": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.15.0.tgz", - "integrity": "sha512-ifBhQ0rRzHDzqp9jAQP6OwHSH7dbYIQjD3SbJs9YYk9AikKEettW/9s/tbSFDTpXcRbF+u1aLrhHxDFaYtZpFQ==", -======= "node_modules/minipass": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", @@ -2436,7 +2381,6 @@ "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.16.0.tgz", "integrity": "sha512-D1PNcdT0y4Grhou5Zi/qgipZOYeWrhLEpk33n3nm6LGtz61jvO88WlrWCK/bigMjpnOdAUKKQwsGIl0NtWMyYw==", "dev": true, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "license": "Apache-2.0", "dependencies": { "@mongodb-js/saslprep": "^1.1.9", @@ -2483,10 +2427,7 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.2.tgz", "integrity": "sha512-rMO7CGo/9BFwyZABcKAWL8UJwH/Kc2x0g72uhDWzG48URRax5TCIcJ7Rc3RZqffZzO/Gwff/jyKwCU9TN8gehA==", -<<<<<<< HEAD -======= "dev": true, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "license": "Apache-2.0", "dependencies": { "@types/whatwg-url": "^11.0.2", @@ -2497,10 +2438,7 @@ "version": "5.1.1", "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz", "integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==", -<<<<<<< HEAD -======= "dev": true, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "license": "MIT", "dependencies": { "punycode": "^2.3.1" @@ -2513,10 +2451,7 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", -<<<<<<< HEAD -======= "dev": true, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "license": "BSD-2-Clause", "engines": { "node": ">=12" @@ -2526,10 +2461,7 @@ "version": "14.2.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", -<<<<<<< HEAD -======= "dev": true, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "license": "MIT", "dependencies": { "tr46": "^5.1.0", @@ -2540,25 +2472,15 @@ } }, "node_modules/mongoose": { -<<<<<<< HEAD - "version": "8.13.3", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.13.3.tgz", - "integrity": "sha512-85S6AOABJcgn77ZKFZKOQkWID69vvtv0YFOk+mMOUrq/7+ziIyybWGZSGQRxN9M41Ehe6a9ug41nV13uJFB9Pw==", -======= "version": "8.14.0", "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.14.0.tgz", "integrity": "sha512-IxDxIUu42apE7oEknJK535xkQ6Gd7GKx/gNrNHY+vP4+ucVU2TOCWjVVW14Vc79y9DEEElzHDlTOuVNM8glUFA==", "dev": true, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "license": "MIT", "dependencies": { "bson": "^6.10.3", "kareem": "2.6.3", -<<<<<<< HEAD - "mongodb": "~6.15.0", -======= "mongodb": "~6.16.0", ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "mpath": "0.9.0", "mquery": "5.0.0", "ms": "2.1.3", @@ -2576,10 +2498,7 @@ "version": "0.9.0", "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==", -<<<<<<< HEAD -======= "dev": true, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "license": "MIT", "engines": { "node": ">=4.0.0" @@ -2589,10 +2508,7 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz", "integrity": "sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==", -<<<<<<< HEAD -======= "dev": true, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "license": "MIT", "dependencies": { "debug": "4.x" @@ -2894,10 +2810,7 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", -<<<<<<< HEAD -======= "dev": true, ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "license": "MIT", "engines": { "node": ">=6" @@ -3213,193 +3126,6 @@ ], "license": "MIT" }, -<<<<<<< HEAD - "node_modules/safer-buffer": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "license": "MIT" - }, - "node_modules/semver": { - "version": "7.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", - "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", - "dev": true, - "license": "ISC", - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/send": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/send/-/send-1.2.0.tgz", - "integrity": "sha512-uaW0WwXKpL9blXE2o0bRhoL2EGXIrZxQ2ZQ4mgcfoBxdFmQold+qWsD2jLrfZ0trjKL6vOw0j//eAwcALFjKSw==", - "license": "MIT", - "dependencies": { - "debug": "^4.3.5", - "encodeurl": "^2.0.0", - "escape-html": "^1.0.3", - "etag": "^1.8.1", - "fresh": "^2.0.0", - "http-errors": "^2.0.0", - "mime-types": "^3.0.1", - "ms": "^2.1.3", - "on-finished": "^2.4.1", - "range-parser": "^1.2.1", - "statuses": "^2.0.1" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/serve-static": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.0.tgz", - "integrity": "sha512-61g9pCh0Vnh7IutZjtLGGpTA355+OPn2TyDv/6ivP2h/AdAVX9azsoxmg2/M6nZeQZNYBEwIcsne1mJd9oQItQ==", - "license": "MIT", - "dependencies": { - "encodeurl": "^2.0.0", - "escape-html": "^1.0.3", - "parseurl": "^1.3.3", - "send": "^1.2.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/setprototypeof": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", - "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", - "license": "ISC" - }, - "node_modules/shell-quote": { - "version": "1.8.2", - "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.2.tgz", - "integrity": "sha512-AzqKpGKjrj7EM6rKVQEPpB288oCfnrEIuyoT9cyF4nmGa7V8Zk6f7RRqYisX8X9m+Q7bd632aZW4ky7EhbQztA==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/side-channel": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", - "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "object-inspect": "^1.13.3", - "side-channel-list": "^1.0.0", - "side-channel-map": "^1.0.1", - "side-channel-weakmap": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/side-channel-list": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", - "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "object-inspect": "^1.13.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/side-channel-map": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", - "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", - "license": "MIT", - "dependencies": { - "call-bound": "^1.0.2", - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.5", - "object-inspect": "^1.13.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/side-channel-weakmap": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", - "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", - "license": "MIT", - "dependencies": { - "call-bound": "^1.0.2", - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.5", - "object-inspect": "^1.13.3", - "side-channel-map": "^1.0.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/sift": { - "version": "17.1.3", - "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", - "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==", - "license": "MIT" - }, - "node_modules/simple-update-notifier": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", - "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", - "dev": true, - "license": "MIT", - "dependencies": { - "semver": "^7.5.3" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/sparse-bitfield": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", - "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", - "license": "MIT", - "dependencies": { - "memory-pager": "^1.0.2" - } - }, - "node_modules/statuses": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", - "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, -======= ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", @@ -3441,8 +3167,18 @@ }, "engines": { "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" } }, + "node_modules/tailwindcss": { + "version": "4.1.4", + "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.1.4.tgz", + "integrity": "sha512-1ZIUqtPITFbv/DxRmDr5/agPqJwF69d24m9qmM1939TJehgY539CtzeZRjbLt5G6fSy/7YqqYsfvoTEw9xUI2A==", + "dev": true, + "license": "MIT" + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", diff --git a/package.json b/package.json index eabd66e..076fe88 100644 --- a/package.json +++ b/package.json @@ -29,27 +29,19 @@ "bcrypt": "^5.1.1", "cors": "^2.8.5", "dotenv": "^16.5.0", -<<<<<<< HEAD - "express": "^5.1.0", - "mongoose": "^8.13.3", -======= "express": "^4.17.1", ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "openai": "^4.95.1", "react": "^19.1.0" }, "devDependencies": { -<<<<<<< HEAD - "@types/express": "^5.0.1", -======= "@types/bcrypt": "^5.0.2", "@types/express": "^4.17.17", "@types/jsonwebtoken": "^9.0.9", ->>>>>>> f02311985330e2744b6b35806e278a31f6acc830 "@types/mongoose": "^5.11.96", "@types/node": "^22.14.1", "concurrently": "^9.1.2", - "nodemon": "^3.1.10", + "nodemon": "^3.1.9", + "tailwindcss": "^4.1.4", "ts-node": "^10.9.2", "typescript": "^5.8.3" } diff --git a/server/models/Questions.ts b/server/models/Questions.ts new file mode 100644 index 0000000..f97b58d --- /dev/null +++ b/server/models/Questions.ts @@ -0,0 +1,13 @@ +import mongoose, { Schema, Document } from "mongoose"; + +export interface IQuestion extends Document { + prompt: string; + difficulty: "easy" | "medium" | "hard"; +} + +const QuestionSchema: Schema = new Schema({ + prompt: { type: String, required: true }, + difficulty: { type: String, enum: ["easy", "medium", "hard"], required: true }, +}); + +export const Question = mongoose.model("Question", QuestionSchema); \ No newline at end of file diff --git a/server/models/User.ts b/server/models/User.ts new file mode 100644 index 0000000..56a6421 --- /dev/null +++ b/server/models/User.ts @@ -0,0 +1,12 @@ +// Ensure this file exports the User model +import mongoose from "mongoose"; + +const userSchema = new mongoose.Schema({ + username: String, + email: String, + password: String, +}); + +const User = mongoose.model("User", userSchema); + +export { User }; // Export the User model \ No newline at end of file diff --git a/server/routes/openai.ts b/server/routes/openai.ts index 996dc29..6bf0fba 100644 --- a/server/routes/openai.ts +++ b/server/routes/openai.ts @@ -7,65 +7,67 @@ import dotenv from 'dotenv'; dotenv.config(); const router = express.Router(); + +/** + * Parses the OpenAI response into a structured format. + * @param rawResponse - The raw response content from OpenAI. + * @returns A structured question object. + */ +function parseOpenAIResponse(rawResponse: string): GeneratedQuestion { + // Example parsing logic (adjust as needed based on actual response format) + const [question, ...choicesAndAnswer] = rawResponse.split('\n').filter(Boolean); + const choices = choicesAndAnswer.slice(0, -1); + const answer = choicesAndAnswer[choicesAndAnswer.length - 1]; + return { question, choices, answer }; +} const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); -/** Existing route: generate a coding question */ -router.post('/generate-question', async (req: Request, res: Response) : Promise => { - try { - const { track, level } = req.body; - if (!track || !level) { - res.status(400).json({ error: 'Missing track or level' }); - return; +type GeneratedQuestion = { + question: string; + choices: string[]; + answer: string; +}; + +/** Generate a coding question via OpenAI, with fallback */ +router.post( + '/generate-question', + async (req: Request, res: Response) : Promise => { + const { track, level, minion } = req.body; + if (!track || !level || !minion) { + res.status(400).json({ error: 'Missing track, level, or minion' }); + return; } + // Build the LLM prompt const prompt = PromptBuilder.getPrompt(track, level); - const completion = await openai.chat.completions.create({ - model: 'gpt-3.5-turbo', - messages: [{ role: 'user', content: prompt }], - max_tokens: 250, - }); - - const question = completion.choices[0].message.content; - res.json({ question }); - } catch (error) { - console.error(error); - res.status(500).json({ error: 'Failed to generate a question' }); - } -}); -type Character = 'Dr. Dan' | 'Nullbyte' | 'Pie-thon' | "D'Bug" | 'Codezilla'; -/** New route: generate speech for character */ -router.post('/tts', async (req: Request, res: Response): Promise => { - const { text, character } = req.body; + try { + const completion = await openai.chat.completions.create({ + model: 'gpt-3.5-turbo', + messages: [{ role: 'user', content: prompt }], + max_tokens: 250, + }); - if (!text) { - res.status(400).json({ error: "Missing 'text'" }); - return; - } - - try { - const voiceMap = { - "Dr. Dan": "echo", - "Codezilla": "echo", - "Nullbyte": "nova", - "D'Bug": "shimmer" - }; + // Parse the raw text into structured question/choices/answer + const raw = completion.choices[0].message.content ?? ''; + const parsed = parseOpenAIResponse(raw); - const voice = voiceMap[character as keyof typeof voiceMap] || "echo"; + res.json(parsed); + } catch (err) { + console.error('OpenAI failed, falling back:', err); - const speech = await openai.audio.speech.create({ - model: 'tts-1', - voice, - input: text - }); + // Fallback: pick a hard-coded question + const fb = PromptBuilder.getFallbackQuestion(minion); - const buffer = Buffer.from(await speech.arrayBuffer()); - res.set({ "Content-Type": "audio/mpeg" }); - res.send(buffer); - } catch (err) { - console.error("TTS route error:", err); - res.status(500).json({ error: "Failed to generate speech." }); + res.json({ + question: fb.question, + choices: fb.choices, + answer: fb.choices[fb.correctIndex], + }); + } } -}); +); + +// ... your existing /tts route ... -export default router; \ No newline at end of file +export default router; diff --git a/server/seed.ts b/server/seed.ts index 646ef66..b43fbdb 100644 --- a/server/seed.ts +++ b/server/seed.ts @@ -1,22 +1,29 @@ import mongoose from "mongoose"; import dotenv from "dotenv"; -import { User } from "./models/User.ts"; -import { Question } from "./models/Question"; +import { User } from "./models/User"; +import { Question } from "./models/Questions"; // Ensure the file './models/Question.ts' exists and exports 'Question' dotenv.config(); -await mongoose.connect(process.env.MONGODB_URI!); +async function seedDatabase() { + await mongoose.connect(process.env.MONGODB_URI!); -// Wipe collections -await User.deleteMany({}); -await Question.deleteMany({}); + // Wipe collections + await User.deleteMany({}); + await Question.deleteMany({}); -// Seed data -await User.create({ username: "playerOne", email: "player@example.com", password: "123456" }); -await Question.insertMany([ - { prompt: "Explain closures in JavaScript", difficulty: "hard" }, - { prompt: "What is a component in React?", difficulty: "easy" } -]); + // Seed data + await User.create({ username: "playerOne", email: "player@example.com", password: "123456" }); + await Question.insertMany([ + { prompt: "Explain closures in JavaScript", difficulty: "hard" }, + { prompt: "What is a component in React?", difficulty: "easy" } + ]); -console.log("🌱 Seeding complete!"); -mongoose.connection.close(); + console.log("🌱 Seeding complete!"); + mongoose.connection.close(); +} + +seedDatabase().catch((error) => { + console.error("Error seeding database:", error); + mongoose.connection.close(); +}); diff --git a/server/src/utils/PromptBuilder.ts b/server/src/utils/PromptBuilder.ts index d56e25c..e950c74 100644 --- a/server/src/utils/PromptBuilder.ts +++ b/server/src/utils/PromptBuilder.ts @@ -1,146 +1,175 @@ +import { fallbackQuestions, FallbackQuestion } from "@/utils/fallbackQuestions"; + export class PromptBuilder { - static getPrompt(track: string, level: string): string { - // Choose minion based on level - switch (level) { - case 'easy': - return this.nullbytePrompt(track); - case 'medium': - return this.debugPrompt(track); - case 'hard': - return this.pythonPrompt(track); - case 'boss': - return this.codezillaPrompt(track); - default: - return this.genericPrompt(track, level); - } - } - - private static genericPrompt(track: string, level: string): string { - return ` - Generate a concise ${level} JavaScript multiple-choice coding question for a ${track}-level developer. - - Requirements: - - Focus on real-world coding concepts. - - Limit the question to 2 sentences max. - - Include 4 answer choices labeled A through D. - - Clearly indicate the correct answer at the end using: "Correct Answer: B" - - Format: - Question: ... - A) ... - B) ... - C) ... - D) ... - Correct Answer: ... - `; - } - - private static nullbytePrompt(track: string): string { - return ` - You're facing **Nullbyte**, the minion of bugs and broken logic. - - Generate an **easy-level** HTML, JavaScript, CSS multiple-choice coding question that focuses on **debugging or fixing broken code** for a ${track}-level developer. - - Requirements: - - Limit to 2 sentences max. - - Use a real JavaScript bug or common mistake (like misuse of == vs ===, off-by-one errors, etc). - - Provide 4 answer options labeled A-D. - - Indicate the correct answer at the end using: "Correct Answer: X" - - Format: - Question: ... - A) ... - B) ... - C) ... - D) ... - Correct Answer: ... - `; - } - - private static debugPrompt(track: string): string { - return ` - You're facing **D'bug**, the glitchy minion of confusion. - - Generate a **medium-level** multiple-choice JavaScript coding question that challenges the player to understand code behavior, logic, or flow — suitable for a ${track}-level developer. - - Requirements: - - Limit the question to 2 sentences max. - - Avoid fantasy themes. - - Provide 4 answer choices labeled A-D. - - End with "Correct Answer: X" - - Format: - Question: ... - A) ... - B) ... - C) ... - D) ... - Correct Answer: ... - `; - } - - private static pythonPrompt(track: string): string { - return ` - You’re up against **Pie-thon**, the toughest minion before the boss. - - Generate a **hard-level** Python multiple-choice question involving complex concepts (e.g. closures, asynchronous behavior, or prototypes), aimed at a ${track}-level developer. - - Requirements: - - Be concise (2 sentences max). - - Provide 4 answer options labeled A-D. - - Clearly indicate the correct answer. - - Format: - Question: ... - A) ... - B) ... - C) ... - D) ... - Correct Answer: ... - `; - } - - private static codezillaPrompt(track: string): string { - return ` - This is the final challenge: **Codezilla**, the boss monster of code. - - Generate a **boss-level** multiple-choice MERN Stack question that requires deep understanding of advanced topics (e.g. event loop, execution context, performance optimization), tailored for a ${track}-level developer. - - Requirements: - - Keep it under 2 sentences. - - Avoid fantasy language and be strictly technical. - - Include 4 choices labeled A-D and mark the correct answer. - - Format: - Question: ... - A) ... - B) ... - C) ... - D) ... - Correct Answer: ... - `; - } + /** + * Return the appropriate LLM prompt based on difficulty level + */ + static getPrompt(track: string, level: string): string { + switch (level) { + case 'easy': + return this.nullbytePrompt(track); + case 'medium': + return this.debugPrompt(track); + case 'hard': + return this.pythonPrompt(track); + case 'boss': + return this.codezillaPrompt(track); + default: + return this.genericPrompt(track, level); + } } - export function parseOpenAIResponse(raw: string) { - const lines = raw.split('\n').map(line => line.trim()).filter(line => line !== ''); - - let question = ''; - const choices: string[] = []; - let answer = ''; - - for (const line of lines) { - if (line.toLowerCase().startsWith('question:')) { - question = line.replace(/^question:\s*/i, '').trim(); - } else if (/^[a-dA-D]\)/.test(line)) { - choices.push(line); - } else if (line.toLowerCase().startsWith('correct answer')) { - const match = line.match(/[A-D]/i); - if (match) { - answer = match[0].toUpperCase(); - } - } - } - - return { question, choices, answer }; + + /** + * Generic prompt for unspecified levels + */ + private static genericPrompt(track: string, level: string): string { + return ` +Generate a concise ${level} JavaScript multiple-choice coding question for a ${track}-level developer. + +Requirements: +- Focus on real-world coding concepts. +- Limit the question to 2 sentences max. +- Include 4 answer choices labeled A through D. +- Clearly indicate the correct answer at the end using: "Correct Answer: B" + +Format: +Question: ... +A) ... +B) ... +C) ... +D) ... +Correct Answer: ... +`; } - \ No newline at end of file + + /** + * Easy-level question prompt for NullByte + */ + private static nullbytePrompt(track: string): string { + return ` +You're facing **NullByte**, the minion of bugs and broken logic. + +Generate an **easy-level** HTML, JavaScript, or CSS multiple-choice coding question that focuses on **debugging or fixing broken code** for a ${track}-level developer. + +Requirements: +- Limit to 2 sentences max. +- Use a real JavaScript bug or common mistake (like misuse of == vs ===, off-by-one errors, etc). +- Provide 4 answer options labeled A-D. +- Indicate the correct answer at the end using: "Correct Answer: X" + +Format: +Question: ... +A) ... +B) ... +C) ... +D) ... +Correct Answer: ... +`; + } + + /** + * Medium-level debugging prompt + */ + private static debugPrompt(track: string): string { + return ` +You're facing **D'bug**, the glitchy minion of confusion. + +Generate a **medium-level** multiple-choice JavaScript coding question that challenges the player to understand code behavior, logic, or flow — suitable for a ${track}-level developer. + +Requirements: +- Limit the question to 2 sentences max. +- Avoid fantasy themes. +- Provide 4 answer choices labeled A-D. +- End with "Correct Answer: X" + +Format: +Question: ... +A) ... +B) ... +C) ... +D) ... +Correct Answer: ... +`; + } + + /** + * Hard-level Python prompt + */ + private static pythonPrompt(track: string): string { + return ` +You’re up against **Pie-thon**, the toughest minion before the boss. + +Generate a **hard-level** Python multiple-choice question involving complex concepts (e.g. closures, asynchronous behavior, or prototypes), aimed at a ${track}-level developer. + +Requirements: +- Be concise (2 sentences max). +- Provide 4 answer options labeled A-D. +- Clearly indicate the correct answer. + +Format: +Question: ... +A) ... +B) ... +C) ... +D) ... +Correct Answer: ... +`; + } + + /** + * Boss-level Codezilla prompt + */ + private static codezillaPrompt(track: string): string { + return ` +This is the final challenge: **Codezilla**, the boss monster of code. + +Generate a **boss-level** multiple-choice MERN Stack question that requires deep understanding of advanced topics (e.g. event loop, execution context, performance optimization), tailored for a ${track}-level developer. + +Requirements: +- Keep it under 2 sentences. +- Avoid fantasy language and be strictly technical. +- Include 4 choices labeled A-D and mark the correct answer. + +Format: +Question: ... +A) ... +B) ... +C) ... +D) ... +Correct Answer: ... +`; + } + + /** + * If the LLM API fails, pick a random fallback question + */ + static getFallbackQuestion(minionName: string): FallbackQuestion { + const pool = fallbackQuestions[minionName] || []; + const idx = Math.floor(Math.random() * pool.length); + return pool[idx]; + } +} + +/** + * Parses the raw OpenAI response into question, choices, and answer + */ +export function parseOpenAIResponse(raw: string) { + const lines = raw.split("\n").map(line => line.trim()).filter(Boolean); + + let question = ""; + const choices: string[] = []; + let answer = ""; + + for (const line of lines) { + if (/^question:/i.test(line)) { + question = line.replace(/^question:\s*/i, ""); + } else if (/^[A-D]\)/.test(line)) { + choices.push(line); + } else if (/^correct answer:/i.test(line)) { + const match = line.match(/[A-D]/i); + if (match) answer = match[0].toUpperCase(); + } + } + + return { question, choices, answer }; +}