Spaces:
Running
Running
Commit ·
8800c81
0
Parent(s):
feat: initial commit for AlgoSpaced DSA Review
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .dockerignore +42 -0
- .gitignore +48 -0
- .python-version +1 -0
- .streamlit/secrets.toml.example +17 -0
- Dockerfile +50 -0
- README.md +94 -0
- ai_cache.py +124 -0
- ai_provider.py +424 -0
- algospaced-ui/.gitignore +22 -0
- algospaced-ui/.node-version +1 -0
- algospaced-ui/.prettierrc +7 -0
- algospaced-ui/README.md +73 -0
- algospaced-ui/dist/assets/CreateProblemForm-tTF8KCdI.js +10 -0
- algospaced-ui/dist/assets/FileExplorer-BA3lbKpy.js +3 -0
- algospaced-ui/dist/assets/JourneyPath-BQEZfHUb.js +0 -0
- algospaced-ui/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- algospaced-ui/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- algospaced-ui/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- algospaced-ui/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- algospaced-ui/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- algospaced-ui/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- algospaced-ui/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- algospaced-ui/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- algospaced-ui/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- algospaced-ui/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- algospaced-ui/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- algospaced-ui/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- algospaced-ui/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- algospaced-ui/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- algospaced-ui/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- algospaced-ui/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- algospaced-ui/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- algospaced-ui/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- algospaced-ui/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- algospaced-ui/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- algospaced-ui/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- algospaced-ui/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- algospaced-ui/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- algospaced-ui/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- algospaced-ui/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- algospaced-ui/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- algospaced-ui/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- algospaced-ui/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- algospaced-ui/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- algospaced-ui/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- algospaced-ui/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- algospaced-ui/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- algospaced-ui/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- algospaced-ui/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- algospaced-ui/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
.dockerignore
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Virtual environments
|
| 2 |
+
venv/
|
| 3 |
+
.venv/
|
| 4 |
+
env/
|
| 5 |
+
ENV/
|
| 6 |
+
|
| 7 |
+
# Node modules
|
| 8 |
+
algospaced-ui/node_modules/
|
| 9 |
+
node_modules/
|
| 10 |
+
|
| 11 |
+
# Python cache & logs
|
| 12 |
+
__pycache__/
|
| 13 |
+
*.pyc
|
| 14 |
+
*.pyo
|
| 15 |
+
*.pyd
|
| 16 |
+
.ruff_cache/
|
| 17 |
+
*.db
|
| 18 |
+
sync.log
|
| 19 |
+
debug_cookies.txt
|
| 20 |
+
debug_db.txt
|
| 21 |
+
|
| 22 |
+
# Git & environment
|
| 23 |
+
.git/
|
| 24 |
+
.gitignore
|
| 25 |
+
.env
|
| 26 |
+
.env.local
|
| 27 |
+
.env.*.local
|
| 28 |
+
.streamlit/secrets.toml
|
| 29 |
+
|
| 30 |
+
# Credentials & sensitive files
|
| 31 |
+
*firebase-credentials*.json
|
| 32 |
+
*serviceAccount*.json
|
| 33 |
+
*credentials*.json
|
| 34 |
+
gcp-credentials.json
|
| 35 |
+
scratch/
|
| 36 |
+
|
| 37 |
+
# Hidden directories & dotfiles (ignores root-level dot folders/configs)
|
| 38 |
+
.*
|
| 39 |
+
|
| 40 |
+
# Documentation (only README is needed for package build)
|
| 41 |
+
*.md
|
| 42 |
+
!README.md
|
.gitignore
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Virtual environment
|
| 2 |
+
venv/
|
| 3 |
+
.venv/
|
| 4 |
+
env/
|
| 5 |
+
ENV/
|
| 6 |
+
|
| 7 |
+
# Python caching
|
| 8 |
+
__pycache__/
|
| 9 |
+
*.pyc
|
| 10 |
+
*.pyo
|
| 11 |
+
*.pyd
|
| 12 |
+
|
| 13 |
+
# Local SQLite databases and logs
|
| 14 |
+
*.db
|
| 15 |
+
scratch/
|
| 16 |
+
/scratch/db_*.sqlite
|
| 17 |
+
/scratch/sandbox.db
|
| 18 |
+
sandbox.db
|
| 19 |
+
sync.log
|
| 20 |
+
debug_cookies.txt
|
| 21 |
+
debug_db.txt
|
| 22 |
+
.ruff_cache/
|
| 23 |
+
|
| 24 |
+
# Node dependencies
|
| 25 |
+
node_modules/
|
| 26 |
+
algospaced-ui/node_modules/
|
| 27 |
+
|
| 28 |
+
# Local configuration and secrets
|
| 29 |
+
.streamlit/secrets.toml
|
| 30 |
+
.env
|
| 31 |
+
.env.local
|
| 32 |
+
.env.*.local
|
| 33 |
+
*firebase-credentials*.json
|
| 34 |
+
*serviceAccount*.json
|
| 35 |
+
*credentials*.json
|
| 36 |
+
gcp-credentials.json
|
| 37 |
+
|
| 38 |
+
# Design layouts and binaries
|
| 39 |
+
*.png
|
| 40 |
+
*.jpg
|
| 41 |
+
*.jpeg
|
| 42 |
+
*.gif
|
| 43 |
+
*.ico
|
| 44 |
+
*.zip
|
| 45 |
+
*.tar.gz
|
| 46 |
+
*.pdf
|
| 47 |
+
|
| 48 |
+
buildlogs.txt
|
.python-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
3.14
|
.streamlit/secrets.toml.example
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# .streamlit/secrets.toml
|
| 2 |
+
|
| 3 |
+
GEMINI_API_KEY = "your_gemini_api_key_here"
|
| 4 |
+
GDRIVE_FOLDER_ID = "your_gdrive_folder_id_here"
|
| 5 |
+
|
| 6 |
+
# Contents of your google-credentials.json
|
| 7 |
+
[gcp_service_account]
|
| 8 |
+
type = "service_account"
|
| 9 |
+
project_id = "..."
|
| 10 |
+
private_key_id = "..."
|
| 11 |
+
private_key = "..."
|
| 12 |
+
client_email = "..."
|
| 13 |
+
client_id = "..."
|
| 14 |
+
auth_uri = "https://accounts.google.com/o/oauth2/auth"
|
| 15 |
+
token_uri = "https://oauth2.googleapis.com/token"
|
| 16 |
+
auth_provider_x509_cert_url = "https://www.googleapis.com/oauth2/v1/certs"
|
| 17 |
+
client_x509_cert_url = "..."
|
Dockerfile
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Stage 1: Build React Frontend
|
| 2 |
+
FROM node:24-slim AS frontend-builder
|
| 3 |
+
WORKDIR /app/algospaced-ui
|
| 4 |
+
RUN npm install -g npm@12.0.2 --loglevel=error
|
| 5 |
+
COPY algospaced-ui/package*.json ./
|
| 6 |
+
RUN npm ci --loglevel=error --no-audit --no-fund
|
| 7 |
+
COPY algospaced-ui/ ./
|
| 8 |
+
RUN npm run build
|
| 9 |
+
|
| 10 |
+
# Stage 2: Python Backend
|
| 11 |
+
FROM python:3.14-slim
|
| 12 |
+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
| 13 |
+
WORKDIR /app
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# Set up non-root user for Hugging Face Spaces (UID 1000)
|
| 18 |
+
RUN useradd -m -u 1000 user && \
|
| 19 |
+
chown -R user:user /app
|
| 20 |
+
|
| 21 |
+
# Switch to non-root user early
|
| 22 |
+
USER user
|
| 23 |
+
ENV HOME=/home/user \
|
| 24 |
+
PATH=/home/user/.local/bin:$PATH \
|
| 25 |
+
PORT=7860
|
| 26 |
+
|
| 27 |
+
# Install python dependencies via uv sync
|
| 28 |
+
COPY --chown=user:user pyproject.toml uv.lock ./
|
| 29 |
+
RUN uv sync --frozen --no-install-project
|
| 30 |
+
|
| 31 |
+
# Add the virtual environment to PATH
|
| 32 |
+
ENV PATH="/app/.venv/bin:$PATH"
|
| 33 |
+
|
| 34 |
+
# Copy application source and assets
|
| 35 |
+
COPY --chown=user:user *.py schema.sql README.md ./
|
| 36 |
+
COPY --chown=user:user core/ ./core/
|
| 37 |
+
COPY --chown=user:user data/ ./data/
|
| 38 |
+
COPY --chown=user:user routers/ ./routers/
|
| 39 |
+
COPY --chown=user:user src/ ./src/
|
| 40 |
+
|
| 41 |
+
# Sync the project itself
|
| 42 |
+
RUN uv sync --frozen
|
| 43 |
+
|
| 44 |
+
# Ensure the fresh build from Stage 1 is used
|
| 45 |
+
COPY --from=frontend-builder --chown=user:user /app/algospaced-ui/dist /app/algospaced-ui/dist
|
| 46 |
+
|
| 47 |
+
EXPOSE 7860
|
| 48 |
+
|
| 49 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
| 50 |
+
|
README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: AlgoSpaced DSA
|
| 3 |
+
emoji: 💻
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# AlgoSpaced-DSA-Review 🚀
|
| 12 |
+
|
| 13 |
+
A retro-styled Spaced Repetition System (SRS) for mastering Data Structures & Algorithms, daily coding challenges, interactive SQL sandboxing, and hand-drawn adventure trail exploration.
|
| 14 |
+
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
## 🌟 Features
|
| 18 |
+
|
| 19 |
+
- **SRS Review Queue**: Leitner 5-box spaced repetition algorithm with AI critique and hints.
|
| 20 |
+
- **Expedition Trail Map**: Hand-drawn vintage cartography map visualizing progress along the LeetCode 150 path.
|
| 21 |
+
- **Interactive Sandboxes**: Python algorithm practice and SQLite sandbox with real-time validation.
|
| 22 |
+
- **File Explorer & Exporter**: Tag, manage, and export DSA solutions as `.py` archives.
|
| 23 |
+
- **Multi-User Isolation & Guest Mode**: Firebase Authentication (Google OAuth + Email) with isolated user progress and instant offline sandbox mode.
|
| 24 |
+
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
## 🛠️ Tech Stack
|
| 28 |
+
|
| 29 |
+
- **Frontend**: React 19, TypeScript, Vite, Tailwind CSS, Lucide Icons, Canvas Confetti.
|
| 30 |
+
- **Backend**: FastAPI, Uvicorn, Pydantic, Firebase Admin SDK.
|
| 31 |
+
- **Database & Auth**: Firebase Authentication & Google Cloud Firestore.
|
| 32 |
+
- **AI**: Google Gemini API (`google-genai`).
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
+
## 🚀 Quick Start
|
| 37 |
+
|
| 38 |
+
### Single-Command (Recommended)
|
| 39 |
+
|
| 40 |
+
Spins up both the FastAPI backend and React frontend with a single command and synchronized logs:
|
| 41 |
+
|
| 42 |
+
```bash
|
| 43 |
+
npm install # Installs root dev orchestration dependencies
|
| 44 |
+
npm run dev # Runs uvicorn + vite with synchronized, color-coded logs
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
### Or Run Services Separately
|
| 48 |
+
|
| 49 |
+
<details>
|
| 50 |
+
<summary>Manual Multi-Terminal Setup</summary>
|
| 51 |
+
|
| 52 |
+
#### 1. Backend
|
| 53 |
+
|
| 54 |
+
```bash
|
| 55 |
+
# Using uv (recommended)
|
| 56 |
+
uv run uvicorn main:app --reload --port 8000
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
#### 2. Frontend
|
| 60 |
+
|
| 61 |
+
```bash
|
| 62 |
+
cd algospaced-ui
|
| 63 |
+
npm install
|
| 64 |
+
npm run dev
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
</details>
|
| 68 |
+
|
| 69 |
+
Open `http://localhost:5173` in your browser.
|
| 70 |
+
|
| 71 |
+
---
|
| 72 |
+
|
| 73 |
+
## 🔑 Environment Variables
|
| 74 |
+
|
| 75 |
+
Create a `.env` file in the project root:
|
| 76 |
+
|
| 77 |
+
```env
|
| 78 |
+
# Backend Firebase Credentials
|
| 79 |
+
FIREBASE_CREDENTIALS_PATH=firebase-credentials.json
|
| 80 |
+
|
| 81 |
+
# Frontend Firebase Config (served via /api/config)
|
| 82 |
+
FIREBASE_API_KEY=your_api_key
|
| 83 |
+
FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
|
| 84 |
+
FIREBASE_PROJECT_ID=your-project-id
|
| 85 |
+
FIREBASE_STORAGE_BUCKET=your-project.appspot.com
|
| 86 |
+
FIREBASE_MESSAGING_SENDER_ID=your_sender_id
|
| 87 |
+
FIREBASE_APP_ID=your_app_id
|
| 88 |
+
|
| 89 |
+
# AI & Reviews (Multi-Provider Fallback)
|
| 90 |
+
GEMINI_API_KEY=your_gemini_api_key
|
| 91 |
+
GROQ_API_KEY=your_groq_api_key # Optional: Free ultra-fast Llama 3.3 / Qwen fallback
|
| 92 |
+
OPENROUTER_API_KEY=your_openrouter_key # Optional: OpenRouter free models fallback
|
| 93 |
+
```
|
| 94 |
+
|
ai_cache.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import re
|
| 3 |
+
import threading
|
| 4 |
+
from datetime import UTC, datetime
|
| 5 |
+
from typing import Any
|
| 6 |
+
|
| 7 |
+
import cache
|
| 8 |
+
import db
|
| 9 |
+
|
| 10 |
+
logger = logging.getLogger("ai_cache")
|
| 11 |
+
logger.setLevel(logging.INFO)
|
| 12 |
+
|
| 13 |
+
_memory_cache: dict[str, Any] = {}
|
| 14 |
+
_cache_lock = threading.Lock()
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def normalize_slug(slug_or_title: str) -> str:
|
| 18 |
+
"""Sanitizes titles/slugs for safe Firestore doc IDs and cache keys."""
|
| 19 |
+
if not slug_or_title:
|
| 20 |
+
return "unknown"
|
| 21 |
+
s = slug_or_title.strip().lower()
|
| 22 |
+
s = re.sub(r"https?://[^\s/]+/problems/", "", s)
|
| 23 |
+
s = re.sub(r"[^a-z0-9_\-]+", "_", s)
|
| 24 |
+
return s.strip("_")[:100]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def get_cached_item(cache_key: str) -> Any | None:
|
| 28 |
+
"""Checks Memory -> Redis -> Firestore."""
|
| 29 |
+
# 1. Memory
|
| 30 |
+
with _cache_lock:
|
| 31 |
+
if cache_key in _memory_cache:
|
| 32 |
+
return _memory_cache[cache_key]
|
| 33 |
+
|
| 34 |
+
# 2. Redis (if available)
|
| 35 |
+
try:
|
| 36 |
+
val = cache.get_cache(f"ai_cache:{cache_key}")
|
| 37 |
+
if val:
|
| 38 |
+
with _cache_lock:
|
| 39 |
+
_memory_cache[cache_key] = val
|
| 40 |
+
return val
|
| 41 |
+
except Exception:
|
| 42 |
+
pass
|
| 43 |
+
|
| 44 |
+
# 3. Firestore (if available)
|
| 45 |
+
try:
|
| 46 |
+
firestore_client = db.init_firebase()
|
| 47 |
+
if firestore_client:
|
| 48 |
+
doc_ref = firestore_client.collection("ai_cache").document(cache_key)
|
| 49 |
+
doc = doc_ref.get()
|
| 50 |
+
if doc.exists:
|
| 51 |
+
data = doc.to_dict()
|
| 52 |
+
cached_val = data.get("payload") if data and "payload" in data else data
|
| 53 |
+
if cached_val:
|
| 54 |
+
with _cache_lock:
|
| 55 |
+
_memory_cache[cache_key] = cached_val
|
| 56 |
+
return cached_val
|
| 57 |
+
except Exception as e:
|
| 58 |
+
logger.debug(f"Firestore cache fetch skipped/failed: {e}")
|
| 59 |
+
|
| 60 |
+
return None
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def set_cached_item(cache_key: str, value: Any, ttl_seconds: int = 86400 * 30):
|
| 64 |
+
"""Saves to Memory -> Redis -> Firestore."""
|
| 65 |
+
if not value or not cache_key:
|
| 66 |
+
return
|
| 67 |
+
|
| 68 |
+
# 1. Memory
|
| 69 |
+
with _cache_lock:
|
| 70 |
+
_memory_cache[cache_key] = value
|
| 71 |
+
|
| 72 |
+
# 2. Redis
|
| 73 |
+
try:
|
| 74 |
+
cache.set_cache(f"ai_cache:{cache_key}", value, ttl_seconds=ttl_seconds)
|
| 75 |
+
except Exception:
|
| 76 |
+
pass
|
| 77 |
+
|
| 78 |
+
# 3. Firestore
|
| 79 |
+
try:
|
| 80 |
+
firestore_client = db.init_firebase()
|
| 81 |
+
if firestore_client:
|
| 82 |
+
doc_ref = firestore_client.collection("ai_cache").document(cache_key)
|
| 83 |
+
doc_ref.set({"payload": value, "cached_at": datetime.now(UTC).isoformat()})
|
| 84 |
+
except Exception as e:
|
| 85 |
+
logger.debug(f"Firestore cache set skipped/failed: {e}")
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
# --- High-level cache helpers ---
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def get_daily_python_challenge(date_str: str) -> dict[str, Any] | None:
|
| 92 |
+
return get_cached_item(f"daily_python_{date_str}")
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def set_daily_python_challenge(date_str: str, challenge: dict[str, Any]):
|
| 96 |
+
set_cached_item(f"daily_python_{date_str}", challenge, ttl_seconds=86400 * 7)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def get_daily_sql_challenge(date_str: str) -> dict[str, Any] | None:
|
| 100 |
+
return get_cached_item(f"daily_sql_{date_str}")
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def set_daily_sql_challenge(date_str: str, challenge: dict[str, Any]):
|
| 104 |
+
set_cached_item(f"daily_sql_{date_str}", challenge, ttl_seconds=86400 * 7)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def get_leetcode_problem(slug_or_url: str) -> dict[str, Any] | None:
|
| 108 |
+
slug = normalize_slug(slug_or_url)
|
| 109 |
+
return get_cached_item(f"leetcode_meta_{slug}")
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def set_leetcode_problem(slug_or_url: str, data: dict[str, Any]):
|
| 113 |
+
slug = normalize_slug(slug_or_url)
|
| 114 |
+
set_cached_item(f"leetcode_meta_{slug}", data, ttl_seconds=86400 * 90)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def get_leetcode_intuition(slug_or_title: str) -> dict[str, Any] | None:
|
| 118 |
+
slug = normalize_slug(slug_or_title)
|
| 119 |
+
return get_cached_item(f"leetcode_intuition_{slug}")
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def set_leetcode_intuition(slug_or_title: str, data: dict[str, Any]):
|
| 123 |
+
slug = normalize_slug(slug_or_title)
|
| 124 |
+
set_cached_item(f"leetcode_intuition_{slug}", data, ttl_seconds=86400 * 90)
|
ai_provider.py
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import logging
|
| 3 |
+
import re
|
| 4 |
+
import urllib.error
|
| 5 |
+
import urllib.request
|
| 6 |
+
from typing import Any
|
| 7 |
+
|
| 8 |
+
from gdrive_sync import get_secret
|
| 9 |
+
|
| 10 |
+
logger = logging.getLogger("ai_provider")
|
| 11 |
+
logger.setLevel(logging.INFO)
|
| 12 |
+
|
| 13 |
+
# Optional genai import
|
| 14 |
+
try:
|
| 15 |
+
from google import genai
|
| 16 |
+
from google.genai import types
|
| 17 |
+
except ImportError:
|
| 18 |
+
genai = None
|
| 19 |
+
types = None
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def clean_json_response(raw_text: str) -> str:
|
| 23 |
+
"""Strips markdown code blocks, comments, or leading/trailing text to extract clean JSON."""
|
| 24 |
+
if not raw_text:
|
| 25 |
+
return ""
|
| 26 |
+
text = raw_text.strip()
|
| 27 |
+
|
| 28 |
+
# Remove markdown code fences if present
|
| 29 |
+
match = re.search(r"```(?:json)?\s*([\s\S]*?)\s*```", text, re.IGNORECASE)
|
| 30 |
+
if match:
|
| 31 |
+
text = match.group(1).strip()
|
| 32 |
+
|
| 33 |
+
# If text is still wrapped in another fence or has leading text
|
| 34 |
+
if not (text.startswith("{") or text.startswith("[")):
|
| 35 |
+
start_brace = text.find("{")
|
| 36 |
+
start_bracket = text.find("[")
|
| 37 |
+
if start_brace != -1 and (start_bracket == -1 or start_brace < start_bracket):
|
| 38 |
+
end_brace = text.rfind("}")
|
| 39 |
+
if end_brace != -1:
|
| 40 |
+
text = text[start_brace : end_brace + 1]
|
| 41 |
+
elif start_bracket != -1:
|
| 42 |
+
end_bracket = text.rfind("]")
|
| 43 |
+
if end_bracket != -1:
|
| 44 |
+
text = text[start_bracket : end_bracket + 1]
|
| 45 |
+
|
| 46 |
+
return text.strip()
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def call_gemini(
|
| 50 |
+
api_key: str, system_instruction: str, user_prompt: str, is_json: bool = False
|
| 51 |
+
) -> str:
|
| 52 |
+
"""Calls Google Gemini API with fallback models."""
|
| 53 |
+
models = [
|
| 54 |
+
"gemini-3.5-flash-lite",
|
| 55 |
+
"gemini-2.5-flash",
|
| 56 |
+
"gemini-3.7-flash",
|
| 57 |
+
"gemini-2.5-flash-lite",
|
| 58 |
+
"gemini-3.5-flash",
|
| 59 |
+
"gemini-2.5-pro",
|
| 60 |
+
"gemini-2.0-flash",
|
| 61 |
+
"gemini-1.5-flash",
|
| 62 |
+
]
|
| 63 |
+
|
| 64 |
+
# If official SDK is available
|
| 65 |
+
if genai is not None:
|
| 66 |
+
client = genai.Client(api_key=api_key)
|
| 67 |
+
last_err = None
|
| 68 |
+
for model_name in models:
|
| 69 |
+
try:
|
| 70 |
+
config = (
|
| 71 |
+
types.GenerateContentConfig(
|
| 72 |
+
system_instruction=system_instruction,
|
| 73 |
+
response_mime_type="application/json",
|
| 74 |
+
)
|
| 75 |
+
if is_json
|
| 76 |
+
else types.GenerateContentConfig(
|
| 77 |
+
system_instruction=system_instruction,
|
| 78 |
+
)
|
| 79 |
+
)
|
| 80 |
+
response = client.models.generate_content(
|
| 81 |
+
model=model_name, contents=user_prompt, config=config
|
| 82 |
+
)
|
| 83 |
+
if response and hasattr(response, "text") and response.text:
|
| 84 |
+
return response.text
|
| 85 |
+
except Exception as e:
|
| 86 |
+
last_err = e
|
| 87 |
+
logger.warning(f"Gemini model {model_name} failed: {e}")
|
| 88 |
+
continue
|
| 89 |
+
if last_err:
|
| 90 |
+
raise last_err
|
| 91 |
+
raise RuntimeError("Gemini failed to return text")
|
| 92 |
+
|
| 93 |
+
# Fallback to direct REST call if SDK missing
|
| 94 |
+
last_err = None
|
| 95 |
+
for model_name in models:
|
| 96 |
+
try:
|
| 97 |
+
url = f"https://generativelanguage.googleapis.com/v1beta/models/{model_name}:generateContent?key={api_key}"
|
| 98 |
+
payload = {
|
| 99 |
+
"contents": [{"parts": [{"text": user_prompt}]}],
|
| 100 |
+
"systemInstruction": {"parts": [{"text": system_instruction}]},
|
| 101 |
+
}
|
| 102 |
+
if is_json:
|
| 103 |
+
payload["generationConfig"] = {"responseMimeType": "application/json"}
|
| 104 |
+
|
| 105 |
+
req = urllib.request.Request(
|
| 106 |
+
url,
|
| 107 |
+
data=json.dumps(payload).encode("utf-8"),
|
| 108 |
+
headers={"Content-Type": "application/json"},
|
| 109 |
+
)
|
| 110 |
+
with urllib.request.urlopen(req, timeout=30) as resp:
|
| 111 |
+
data = json.loads(resp.read().decode("utf-8"))
|
| 112 |
+
candidates = data.get("candidates", [])
|
| 113 |
+
if candidates:
|
| 114 |
+
parts = candidates[0].get("content", {}).get("parts", [])
|
| 115 |
+
if parts:
|
| 116 |
+
return parts[0].get("text", "")
|
| 117 |
+
except Exception as e:
|
| 118 |
+
last_err = e
|
| 119 |
+
continue
|
| 120 |
+
if last_err:
|
| 121 |
+
raise last_err
|
| 122 |
+
raise RuntimeError("Gemini REST API failed")
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def stream_gemini(api_key: str, system_instruction: str, user_prompt: str, is_json: bool = False):
|
| 126 |
+
"""Streams Google Gemini API responses chunk by chunk."""
|
| 127 |
+
models = [
|
| 128 |
+
"gemini-2.5-flash",
|
| 129 |
+
"gemini-3.5-flash-lite",
|
| 130 |
+
"gemini-3.7-flash",
|
| 131 |
+
"gemini-2.5-flash-lite",
|
| 132 |
+
"gemini-3.5-flash",
|
| 133 |
+
"gemini-2.0-flash",
|
| 134 |
+
"gemini-1.5-flash",
|
| 135 |
+
]
|
| 136 |
+
if genai is not None:
|
| 137 |
+
client = genai.Client(api_key=api_key)
|
| 138 |
+
for model_name in models:
|
| 139 |
+
try:
|
| 140 |
+
config = (
|
| 141 |
+
types.GenerateContentConfig(
|
| 142 |
+
system_instruction=system_instruction,
|
| 143 |
+
response_mime_type="application/json",
|
| 144 |
+
)
|
| 145 |
+
if is_json
|
| 146 |
+
else types.GenerateContentConfig(
|
| 147 |
+
system_instruction=system_instruction,
|
| 148 |
+
)
|
| 149 |
+
)
|
| 150 |
+
response = client.models.generate_content_stream(
|
| 151 |
+
model=model_name, contents=user_prompt, config=config
|
| 152 |
+
)
|
| 153 |
+
has_yielded = False
|
| 154 |
+
for chunk in response:
|
| 155 |
+
if chunk and hasattr(chunk, "text") and chunk.text:
|
| 156 |
+
has_yielded = True
|
| 157 |
+
yield chunk.text
|
| 158 |
+
if has_yielded:
|
| 159 |
+
return
|
| 160 |
+
except Exception as e:
|
| 161 |
+
logger.warning(f"Gemini streaming model {model_name} failed: {e}")
|
| 162 |
+
continue
|
| 163 |
+
|
| 164 |
+
# Fallback to standard call if streaming fails or SDK missing
|
| 165 |
+
full_text = call_gemini(api_key, system_instruction, user_prompt, is_json=is_json)
|
| 166 |
+
if full_text:
|
| 167 |
+
yield full_text
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def call_groq(
|
| 171 |
+
api_key: str, system_instruction: str, user_prompt: str, is_json: bool = False
|
| 172 |
+
) -> str:
|
| 173 |
+
"""Calls Groq Cloud API with OpenAI-compatible payload."""
|
| 174 |
+
models = [
|
| 175 |
+
"qwen/qwen3.8-27b",
|
| 176 |
+
"openai/gpt-oss-20b",
|
| 177 |
+
"qwen/qwen3.6-27b",
|
| 178 |
+
"openai/gpt-oss-120b",
|
| 179 |
+
"groq/compound-mini",
|
| 180 |
+
"groq/compound",
|
| 181 |
+
]
|
| 182 |
+
url = "https://api.groq.com/openai/v1/chat/completions"
|
| 183 |
+
last_err = None
|
| 184 |
+
|
| 185 |
+
for model_name in models:
|
| 186 |
+
try:
|
| 187 |
+
payload: dict[str, Any] = {
|
| 188 |
+
"model": model_name,
|
| 189 |
+
"messages": [
|
| 190 |
+
{"role": "system", "content": system_instruction},
|
| 191 |
+
{"role": "user", "content": user_prompt},
|
| 192 |
+
],
|
| 193 |
+
"temperature": 0.2,
|
| 194 |
+
}
|
| 195 |
+
if is_json:
|
| 196 |
+
payload["response_format"] = {"type": "json_object"}
|
| 197 |
+
|
| 198 |
+
req = urllib.request.Request(
|
| 199 |
+
url,
|
| 200 |
+
data=json.dumps(payload).encode("utf-8"),
|
| 201 |
+
headers={
|
| 202 |
+
"Content-Type": "application/json",
|
| 203 |
+
"Authorization": f"Bearer {api_key}",
|
| 204 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AlgoSpaced/1.0",
|
| 205 |
+
},
|
| 206 |
+
)
|
| 207 |
+
with urllib.request.urlopen(req, timeout=30) as resp:
|
| 208 |
+
data = json.loads(resp.read().decode("utf-8"))
|
| 209 |
+
choices = data.get("choices", [])
|
| 210 |
+
if choices:
|
| 211 |
+
content = choices[0].get("message", {}).get("content", "")
|
| 212 |
+
if content:
|
| 213 |
+
return content
|
| 214 |
+
except Exception as e:
|
| 215 |
+
last_err = e
|
| 216 |
+
logger.warning(f"Groq model {model_name} failed: {e}")
|
| 217 |
+
continue
|
| 218 |
+
|
| 219 |
+
if last_err:
|
| 220 |
+
raise last_err
|
| 221 |
+
raise RuntimeError("Groq failed to return content")
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def call_openrouter(
|
| 225 |
+
api_key: str, system_instruction: str, user_prompt: str, is_json: bool = False
|
| 226 |
+
) -> str:
|
| 227 |
+
"""Calls OpenRouter API with free and standard model fallbacks."""
|
| 228 |
+
models = [
|
| 229 |
+
"openrouter/free",
|
| 230 |
+
"deepseek/deepseek-chat",
|
| 231 |
+
"meta-llama/llama-3.3-70b-instruct",
|
| 232 |
+
"minimax/minimax-m2.7:free",
|
| 233 |
+
"google/gemma-4-31b-it:free",
|
| 234 |
+
"meta-llama/llama-3.1-8b-instruct:free",
|
| 235 |
+
]
|
| 236 |
+
url = "https://openrouter.ai/api/v1/chat/completions"
|
| 237 |
+
last_err = None
|
| 238 |
+
|
| 239 |
+
for model_name in models:
|
| 240 |
+
try:
|
| 241 |
+
payload: dict[str, Any] = {
|
| 242 |
+
"model": model_name,
|
| 243 |
+
"messages": [
|
| 244 |
+
{"role": "system", "content": system_instruction},
|
| 245 |
+
{"role": "user", "content": user_prompt},
|
| 246 |
+
],
|
| 247 |
+
"temperature": 0.2,
|
| 248 |
+
}
|
| 249 |
+
if is_json:
|
| 250 |
+
payload["response_format"] = {"type": "json_object"}
|
| 251 |
+
|
| 252 |
+
req = urllib.request.Request(
|
| 253 |
+
url,
|
| 254 |
+
data=json.dumps(payload).encode("utf-8"),
|
| 255 |
+
headers={
|
| 256 |
+
"Content-Type": "application/json",
|
| 257 |
+
"Authorization": f"Bearer {api_key}",
|
| 258 |
+
"HTTP-Referer": "https://algospaced.io",
|
| 259 |
+
"X-Title": "AlgoSpaced DSA",
|
| 260 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AlgoSpaced/1.0",
|
| 261 |
+
},
|
| 262 |
+
)
|
| 263 |
+
with urllib.request.urlopen(req, timeout=30) as resp:
|
| 264 |
+
data = json.loads(resp.read().decode("utf-8"))
|
| 265 |
+
choices = data.get("choices", [])
|
| 266 |
+
if choices:
|
| 267 |
+
content = choices[0].get("message", {}).get("content", "")
|
| 268 |
+
if content:
|
| 269 |
+
return content
|
| 270 |
+
except Exception as e:
|
| 271 |
+
last_err = e
|
| 272 |
+
logger.warning(f"OpenRouter model {model_name} failed: {e}")
|
| 273 |
+
continue
|
| 274 |
+
|
| 275 |
+
if last_err:
|
| 276 |
+
raise last_err
|
| 277 |
+
raise RuntimeError("OpenRouter failed to return content")
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
def detect_provider(provider: str | None, api_key: str | None) -> str:
|
| 281 |
+
"""Infers provider from name or key pattern."""
|
| 282 |
+
if provider:
|
| 283 |
+
p = provider.lower().strip()
|
| 284 |
+
if "groq" in p:
|
| 285 |
+
return "groq"
|
| 286 |
+
if "openrouter" in p or "open_router" in p:
|
| 287 |
+
return "openrouter"
|
| 288 |
+
if "gemini" in p or "google" in p:
|
| 289 |
+
return "gemini"
|
| 290 |
+
|
| 291 |
+
if api_key:
|
| 292 |
+
k = api_key.strip()
|
| 293 |
+
if k.startswith("gsk_"):
|
| 294 |
+
return "groq"
|
| 295 |
+
if k.startswith("sk-or-"):
|
| 296 |
+
return "openrouter"
|
| 297 |
+
if k.startswith("AIza"):
|
| 298 |
+
return "gemini"
|
| 299 |
+
|
| 300 |
+
return "gemini"
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
def generate_ai_content(
|
| 304 |
+
system_instruction: str,
|
| 305 |
+
user_prompt: str,
|
| 306 |
+
is_json: bool = False,
|
| 307 |
+
custom_provider: str | None = None,
|
| 308 |
+
custom_api_key: str | None = None,
|
| 309 |
+
) -> tuple[str, str]:
|
| 310 |
+
"""
|
| 311 |
+
Unified multi-provider AI dispatcher with automatic failover.
|
| 312 |
+
Returns tuple of (response_text, provider_used).
|
| 313 |
+
"""
|
| 314 |
+
# 1. Custom BYOK Request
|
| 315 |
+
if custom_api_key and custom_api_key.strip():
|
| 316 |
+
key = custom_api_key.strip()
|
| 317 |
+
provider = detect_provider(custom_provider, key)
|
| 318 |
+
if provider == "groq":
|
| 319 |
+
text = call_groq(key, system_instruction, user_prompt, is_json=is_json)
|
| 320 |
+
return text, "groq (custom)"
|
| 321 |
+
elif provider == "openrouter":
|
| 322 |
+
text = call_openrouter(key, system_instruction, user_prompt, is_json=is_json)
|
| 323 |
+
return text, "openrouter (custom)"
|
| 324 |
+
else:
|
| 325 |
+
text = call_gemini(key, system_instruction, user_prompt, is_json=is_json)
|
| 326 |
+
return text, "gemini (custom)"
|
| 327 |
+
|
| 328 |
+
# 2. Server Shared Default Tier (Multi-Provider Fallback Chain)
|
| 329 |
+
gemini_key = get_secret("GEMINI_API_KEY")
|
| 330 |
+
groq_key = get_secret("GROQ_API_KEY")
|
| 331 |
+
openrouter_key = get_secret("OPENROUTER_API_KEY")
|
| 332 |
+
|
| 333 |
+
errors: list[str] = []
|
| 334 |
+
|
| 335 |
+
# Priority 1: Gemini
|
| 336 |
+
if gemini_key:
|
| 337 |
+
try:
|
| 338 |
+
text = call_gemini(gemini_key, system_instruction, user_prompt, is_json=is_json)
|
| 339 |
+
return text, "gemini (server)"
|
| 340 |
+
except Exception as e:
|
| 341 |
+
err_msg = f"Gemini server key failed: {e}"
|
| 342 |
+
logger.warning(err_msg)
|
| 343 |
+
errors.append(err_msg)
|
| 344 |
+
|
| 345 |
+
# Priority 2: Groq (if available on server)
|
| 346 |
+
if groq_key:
|
| 347 |
+
try:
|
| 348 |
+
text = call_groq(groq_key, system_instruction, user_prompt, is_json=is_json)
|
| 349 |
+
return text, "groq (server fallback)"
|
| 350 |
+
except Exception as e:
|
| 351 |
+
err_msg = f"Groq server key failed: {e}"
|
| 352 |
+
logger.warning(err_msg)
|
| 353 |
+
errors.append(err_msg)
|
| 354 |
+
|
| 355 |
+
# Priority 3: OpenRouter (if available on server)
|
| 356 |
+
if openrouter_key:
|
| 357 |
+
try:
|
| 358 |
+
text = call_openrouter(openrouter_key, system_instruction, user_prompt, is_json=is_json)
|
| 359 |
+
return text, "openrouter (server fallback)"
|
| 360 |
+
except Exception as e:
|
| 361 |
+
err_msg = f"OpenRouter server key failed: {e}"
|
| 362 |
+
logger.warning(err_msg)
|
| 363 |
+
errors.append(err_msg)
|
| 364 |
+
|
| 365 |
+
if not (gemini_key or groq_key or openrouter_key):
|
| 366 |
+
raise RuntimeError(
|
| 367 |
+
"No AI API keys configured on server. Please configure your API key in Settings."
|
| 368 |
+
)
|
| 369 |
+
|
| 370 |
+
raise RuntimeError(f"All AI providers failed. Summary of errors: {'; '.join(errors)}")
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
def stream_ai_content(
|
| 374 |
+
system_instruction: str,
|
| 375 |
+
user_prompt: str,
|
| 376 |
+
is_json: bool = False,
|
| 377 |
+
custom_provider: str | None = None,
|
| 378 |
+
custom_api_key: str | None = None,
|
| 379 |
+
):
|
| 380 |
+
"""
|
| 381 |
+
Streams AI content chunks. Yields tuples of (chunk_text, provider_name).
|
| 382 |
+
"""
|
| 383 |
+
# 1. Custom BYOK Request
|
| 384 |
+
if custom_api_key and custom_api_key.strip():
|
| 385 |
+
key = custom_api_key.strip()
|
| 386 |
+
provider = detect_provider(custom_provider, key)
|
| 387 |
+
if provider == "gemini":
|
| 388 |
+
for chunk in stream_gemini(key, system_instruction, user_prompt, is_json=is_json):
|
| 389 |
+
yield chunk, "gemini (custom)"
|
| 390 |
+
return
|
| 391 |
+
elif provider == "groq":
|
| 392 |
+
text = call_groq(key, system_instruction, user_prompt, is_json=is_json)
|
| 393 |
+
yield text, "groq (custom)"
|
| 394 |
+
return
|
| 395 |
+
elif provider == "openrouter":
|
| 396 |
+
text = call_openrouter(key, system_instruction, user_prompt, is_json=is_json)
|
| 397 |
+
yield text, "openrouter (custom)"
|
| 398 |
+
return
|
| 399 |
+
else:
|
| 400 |
+
for chunk in stream_gemini(key, system_instruction, user_prompt, is_json=is_json):
|
| 401 |
+
yield chunk, "gemini (custom)"
|
| 402 |
+
return
|
| 403 |
+
|
| 404 |
+
# 2. Server Shared Default Tier
|
| 405 |
+
gemini_key = get_secret("GEMINI_API_KEY")
|
| 406 |
+
if gemini_key:
|
| 407 |
+
try:
|
| 408 |
+
for chunk in stream_gemini(
|
| 409 |
+
gemini_key, system_instruction, user_prompt, is_json=is_json
|
| 410 |
+
):
|
| 411 |
+
yield chunk, "gemini (server)"
|
| 412 |
+
return
|
| 413 |
+
except Exception as e:
|
| 414 |
+
logger.warning(f"Gemini server stream failed: {e}")
|
| 415 |
+
|
| 416 |
+
# Fallback to standard generation
|
| 417 |
+
text, provider = generate_ai_content(
|
| 418 |
+
system_instruction=system_instruction,
|
| 419 |
+
user_prompt=user_prompt,
|
| 420 |
+
is_json=is_json,
|
| 421 |
+
custom_provider=custom_provider,
|
| 422 |
+
custom_api_key=custom_api_key,
|
| 423 |
+
)
|
| 424 |
+
yield text, provider
|
algospaced-ui/.gitignore
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Logs
|
| 2 |
+
logs
|
| 3 |
+
*.log
|
| 4 |
+
npm-debug.log*
|
| 5 |
+
yarn-debug.log*
|
| 6 |
+
yarn-error.log*
|
| 7 |
+
pnpm-debug.log*
|
| 8 |
+
lerna-debug.log*
|
| 9 |
+
|
| 10 |
+
node_modules
|
| 11 |
+
*.local
|
| 12 |
+
|
| 13 |
+
# Editor directories and files
|
| 14 |
+
.vscode/*
|
| 15 |
+
!.vscode/extensions.json
|
| 16 |
+
.idea
|
| 17 |
+
.DS_Store
|
| 18 |
+
*.suo
|
| 19 |
+
*.ntvs*
|
| 20 |
+
*.njsproj
|
| 21 |
+
*.sln
|
| 22 |
+
*.sw?
|
algospaced-ui/.node-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
24
|
algospaced-ui/.prettierrc
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"semi": false,
|
| 3 |
+
"singleQuote": true,
|
| 4 |
+
"trailingComma": "es5",
|
| 5 |
+
"printWidth": 80,
|
| 6 |
+
"tabWidth": 2
|
| 7 |
+
}
|
algospaced-ui/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# React + TypeScript + Vite
|
| 2 |
+
|
| 3 |
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
| 4 |
+
|
| 5 |
+
Currently, two official plugins are available:
|
| 6 |
+
|
| 7 |
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
| 8 |
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
| 9 |
+
|
| 10 |
+
## React Compiler
|
| 11 |
+
|
| 12 |
+
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
| 13 |
+
|
| 14 |
+
## Expanding the ESLint configuration
|
| 15 |
+
|
| 16 |
+
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
| 17 |
+
|
| 18 |
+
```js
|
| 19 |
+
export default defineConfig([
|
| 20 |
+
globalIgnores(['dist']),
|
| 21 |
+
{
|
| 22 |
+
files: ['**/*.{ts,tsx}'],
|
| 23 |
+
extends: [
|
| 24 |
+
// Other configs...
|
| 25 |
+
|
| 26 |
+
// Remove tseslint.configs.recommended and replace with this
|
| 27 |
+
tseslint.configs.recommendedTypeChecked,
|
| 28 |
+
// Alternatively, use this for stricter rules
|
| 29 |
+
tseslint.configs.strictTypeChecked,
|
| 30 |
+
// Optionally, add this for stylistic rules
|
| 31 |
+
tseslint.configs.stylisticTypeChecked,
|
| 32 |
+
|
| 33 |
+
// Other configs...
|
| 34 |
+
],
|
| 35 |
+
languageOptions: {
|
| 36 |
+
parserOptions: {
|
| 37 |
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
| 38 |
+
tsconfigRootDir: import.meta.dirname,
|
| 39 |
+
},
|
| 40 |
+
// other options...
|
| 41 |
+
},
|
| 42 |
+
},
|
| 43 |
+
])
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
| 47 |
+
|
| 48 |
+
```js
|
| 49 |
+
// eslint.config.js
|
| 50 |
+
import reactX from 'eslint-plugin-react-x'
|
| 51 |
+
import reactDom from 'eslint-plugin-react-dom'
|
| 52 |
+
|
| 53 |
+
export default defineConfig([
|
| 54 |
+
globalIgnores(['dist']),
|
| 55 |
+
{
|
| 56 |
+
files: ['**/*.{ts,tsx}'],
|
| 57 |
+
extends: [
|
| 58 |
+
// Other configs...
|
| 59 |
+
// Enable lint rules for React
|
| 60 |
+
reactX.configs['recommended-typescript'],
|
| 61 |
+
// Enable lint rules for React DOM
|
| 62 |
+
reactDom.configs.recommended,
|
| 63 |
+
],
|
| 64 |
+
languageOptions: {
|
| 65 |
+
parserOptions: {
|
| 66 |
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
| 67 |
+
tsconfigRootDir: import.meta.dirname,
|
| 68 |
+
},
|
| 69 |
+
// other options...
|
| 70 |
+
},
|
| 71 |
+
},
|
| 72 |
+
])
|
| 73 |
+
```
|
algospaced-ui/dist/assets/CreateProblemForm-tTF8KCdI.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import{a as e,c as t,i as n,t as r}from"./jsx-runtime-UoOgdb2P.js";var i=t(e(),1),a=r(),o=[`Arrays & Hashing`,`Two Pointers`,`Sliding Window`,`Stack`,`Binary Search`,`Linked List`,`Trees`,`Tries`,`Heap / Priority Queue`,`Backtracking`,`Graphs`,`Advanced Graphs`,`1-D Dynamic Programming`,`2-D Dynamic Programming`,`Greedy`,`Intervals`,`Math & Geometry`,`Bit Manipulation`];function s({onClose:e,onSuccess:t}){let[r,s]=(0,i.useState)(`form`),[c,ee]=(0,i.useState)(``),[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)(()=>{try{let e=localStorage.getItem(`algospaced_prefill_draft`);if(e)return JSON.parse(e).name||``}catch{}return``}),[p,m]=(0,i.useState)(``),[h,g]=(0,i.useState)(()=>{try{let e=localStorage.getItem(`algospaced_prefill_draft`);if(e)return JSON.parse(e).pattern||``}catch{}return`Arrays & Hashing`}),[_,v]=(0,i.useState)(`Medium`),[y,b]=(0,i.useState)(`O(N)`),[x,S]=(0,i.useState)(`O(N)`),[C,w]=(0,i.useState)(``),[T,E]=(0,i.useState)([{input:``,output:``,explanation:``}]),[D,O]=(0,i.useState)(``),[k,A]=(0,i.useState)(``),[j,M]=(0,i.useState)(()=>{try{let e=localStorage.getItem(`algospaced_prefill_draft`);if(e)return JSON.parse(e).code||``}catch{}return``}),[N,P]=(0,i.useState)(!0),[F,I]=(0,i.useState)(``),[L,R]=(0,i.useState)(``),[z,B]=(0,i.useState)(!1),[V,H]=(0,i.useState)(!1),[U,W]=(0,i.useState)(!1),[G,K]=(0,i.useState)(!1);i.useEffect(()=>{localStorage.removeItem(`algospaced_prefill_draft`)},[]);let q=async()=>{let{data:{session:e}}=await n.auth.getSession(),t=e?e.access_token:`sandbox`,r=localStorage.getItem(`algospaced_custom_api_key`)||localStorage.getItem(`sandbox_gemini_api_key`)||``,i=localStorage.getItem(`algospaced_custom_ai_provider`)||`default`,a={"Content-Type":`application/json`,Authorization:`Bearer ${t}`};return i&&i!=="default"&&r&&r.trim()&&(a[`x-custom-api-key`]=r.trim(),a[`x-gemini-api-key`]=r.trim(),a[`x-ai-provider`]=i),a},J=async()=>{if(c.trim()){u(!0),I(``);try{let e=await q(),t=await fetch(`/api/explorer/problems/fetch-leetcode`,{method:`POST`,headers:e,body:JSON.stringify({query:c.trim()})});if(t.ok){let e=await t.json();e.problem_number!==void 0&&e.problem_number!==null&&m(e.problem_number),e.title&&f(e.title),e.difficulty&&v(e.difficulty),e.pattern&&g(e.pattern),e.optimal_time&&b(e.optimal_time),e.optimal_space&&S(e.optimal_space),e.description&&w(e.description),e.how_to_solve&&A(e.how_to_solve),e.starter_code&&!j.trim()&&M(e.starter_code),Array.isArray(e.examples)&&e.examples.length>0&&E(e.examples),Array.isArray(e.constraints)?O(e.constraints.join(`
|
| 2 |
+
`)):typeof e.constraints==`string`&&O(e.constraints)}else{let e=await t.json();I(e.detail||`Failed to fetch LeetCode problem data.`)}}catch{I(`Fetch request failed due to connection error.`)}finally{u(!1)}}},Y=async()=>{if(d.trim()||j.trim()){K(!0),I(``);try{let e=await q(),t=await fetch(`/api/explorer/problems/prefill`,{method:`POST`,headers:e,body:JSON.stringify({name:d,code:j})});if(t.ok){let e=await t.json();e.problem_number!==void 0&&e.problem_number!==null&&m(e.problem_number),e.title&&!d&&f(e.title),e.pattern&&g(e.pattern),e.difficulty&&v(e.difficulty),e.optimal_time&&b(e.optimal_time),e.optimal_space&&S(e.optimal_space),e.description&&w(e.description),e.reference_code&&!j.trim()&&M(e.reference_code)}else{let e=await t.json();I(e.detail||`Prefill failed.`)}}catch{I(`Prefill request failed due to connection error.`)}finally{K(!1)}}},X=async()=>{if(!d.trim()&&!j.trim()){I(`Please enter a problem name or code first.`);return}H(!0),I(``);try{let e=await q(),t=await fetch(`/api/explorer/problems/assist-field`,{method:`POST`,headers:e,body:JSON.stringify({field:`intuition`,title:d,code:j,description:C})});if(t.ok){let e=await t.json();e.how_to_solve&&A(e.how_to_solve)}else{let e=await t.json();I(e.detail||`Failed to generate intuition.`)}}catch{I(`Intuition generator failed due to connection error.`)}finally{H(!1)}},Z=async()=>{if(!j.trim()){I(`Please enter some Python code to format.`);return}W(!0),I(``);try{let e=await q(),t=await fetch(`/api/explorer/problems/assist-field`,{method:`POST`,headers:e,body:JSON.stringify({field:`comments`,title:d,code:j})});if(t.ok){let e=await t.json();e.formatted_code&&M(e.formatted_code)}else{let e=await t.json();I(e.detail||`Failed to format code.`)}}catch{I(`Code formatter failed due to connection error.`)}finally{W(!1)}},Q=async n=>{if(n.preventDefault(),!d.trim()){I(`Problem name cannot be empty`);return}B(!0),I(``),R(``);try{let n=await q(),r=D.split(`
|
| 3 |
+
`).map(e=>e.trim()).filter(Boolean),i=await fetch(`/api/explorer/problems/create`,{method:`POST`,headers:n,body:JSON.stringify({name:d.trim(),pattern:h.trim()||`General`,difficulty:_,reference_code:j,description:C,problem_number:p===``?null:Number(p),optimal_time:y,optimal_space:x,examples:T.filter(e=>e.input.trim()||e.output.trim()),constraints:r,how_to_solve:k,sync_to_gdoc:N})}),a=await i.json();i.ok&&a.success?(R(`Problem saved and synced successfully!`),setTimeout(()=>{t(),e()},1e3)):I(a.detail||`Failed to create problem.`)}catch{I(`Connection timed out.`)}finally{B(!1)}},te=()=>{E([...T,{input:``,output:``,explanation:``}])},ne=e=>{T.length<=1||E(T.filter((t,n)=>n!==e))},$=(e,t,n)=>{let r=[...T];r[e]={...r[e],[t]:n},E(r)};return(0,a.jsxs)(`form`,{onSubmit:Q,className:`flex flex-col h-full bg-[#fdf8e1] text-ink-black font-sans overflow-hidden`,children:[(0,a.jsxs)(`div`,{className:`bg-[#f0e6c8] p-2.5 border-b-2 border-ink-black flex flex-col gap-2 shrink-0`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,a.jsx)(`span`,{className:`font-arcade text-xs text-primary-purple`,children:`✦`}),(0,a.jsx)(`h2`,{className:`text-xs font-bold font-arcade tracking-tight uppercase`,children:`Problem & Note Studio`})]}),(0,a.jsxs)(`div`,{className:`flex border-2 border-ink-black bg-white rounded overflow-hidden shadow-[1px_1px_0px_#1E293B]`,children:[(0,a.jsx)(`button`,{type:`button`,onClick:()=>s(`form`),className:`px-3 py-1 text-[10px] font-bold uppercase transition-colors ${r===`form`?`bg-primary-purple text-white`:`hover:bg-slate-100`}`,children:`✏️ Editor`}),(0,a.jsx)(`button`,{type:`button`,onClick:()=>s(`preview`),className:`px-3 py-1 text-[10px] font-bold uppercase transition-colors ${r===`preview`?`bg-primary-purple text-white`:`hover:bg-slate-100`}`,children:`📄 Doc Preview`})]})]}),(0,a.jsxs)(`div`,{className:`flex gap-1.5 items-center`,children:[(0,a.jsx)(`input`,{type:`text`,value:c,onChange:e=>ee(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),J())},placeholder:`Paste LeetCode URL (e.g. https://leetcode.com/problems/two-sum/) or Title...`,className:`flex-1 bg-white border-2 border-ink-black px-2 py-1 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-medium`}),(0,a.jsxs)(`button`,{type:`button`,onClick:J,disabled:l||!c.trim(),className:`bg-[#ffe24c] hover:bg-yellow-300 disabled:opacity-50 text-ink-black font-arcade text-[9px] font-bold px-2.5 py-1.5 border-2 border-ink-black shadow-[1px_1px_0px_#1E293B] active:translate-y-0.5 cursor-pointer flex items-center gap-1 shrink-0`,children:[(0,a.jsx)(`span`,{children:`⚡`}),` `,l?`FETCHING...`:`FETCH LEETCODE`]})]})]}),F&&(0,a.jsxs)(`div`,{className:`mx-3 mt-2 p-2 border-2 border-red-500 bg-red-50 text-red-800 text-[11px] font-mono leading-relaxed shrink-0`,children:[`⚠️ `,F]}),L&&(0,a.jsxs)(`div`,{className:`mx-3 mt-2 p-2 border-2 border-green-500 bg-green-50 text-green-800 text-[11px] font-mono leading-relaxed shrink-0`,children:[`✅ `,L]}),(0,a.jsx)(`div`,{className:`flex-1 overflow-y-auto custom-scrollbar p-3 space-y-3`,children:r===`form`?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(`div`,{className:`grid grid-cols-12 gap-2`,children:[(0,a.jsxs)(`div`,{className:`col-span-3 flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Problem #:`}),(0,a.jsx)(`input`,{type:`number`,value:p,onChange:e=>m(e.target.value===``?``:Number(e.target.value)),placeholder:`e.g. 1`,className:`bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-bold`})]}),(0,a.jsxs)(`div`,{className:`col-span-6 flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Title:`}),(0,a.jsxs)(`button`,{type:`button`,onClick:Y,disabled:G||!d.trim()&&!j.trim(),className:`text-[8px] font-arcade font-bold px-1.5 py-0.5 border border-ink-black bg-[#ffe24c] hover:bg-yellow-300 disabled:opacity-50 flex items-center gap-1 cursor-pointer`,children:[(0,a.jsx)(`span`,{children:`✦`}),` `,G?`...`:`AUTO-FILL`]})]}),(0,a.jsx)(`input`,{type:`text`,required:!0,value:d,onChange:e=>f(e.target.value),placeholder:`e.g. Two Sum`,className:`bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-bold`})]}),(0,a.jsxs)(`div`,{className:`col-span-3 flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Difficulty:`}),(0,a.jsxs)(`select`,{value:_,onChange:e=>v(e.target.value),className:`border-2 border-ink-black p-1.5 text-xs font-bold outline-none cursor-pointer ${_===`Easy`?`bg-emerald-100 text-emerald-900`:_===`Medium`?`bg-amber-100 text-amber-900`:`bg-rose-100 text-rose-900`}`,children:[(0,a.jsx)(`option`,{value:`Easy`,children:`Easy`}),(0,a.jsx)(`option`,{value:`Medium`,children:`Medium`}),(0,a.jsx)(`option`,{value:`Hard`,children:`Hard`})]})]})]}),(0,a.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Pattern / Topic:`}),(0,a.jsx)(`input`,{type:`text`,list:`pattern-suggestions`,value:h,onChange:e=>g(e.target.value),placeholder:`e.g. Arrays & Hashing`,className:`bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-medium`}),(0,a.jsx)(`datalist`,{id:`pattern-suggestions`,children:o.map(e=>(0,a.jsx)(`option`,{value:e},e))})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Time Complexity:`}),(0,a.jsx)(`input`,{type:`text`,value:y,onChange:e=>b(e.target.value),placeholder:`e.g. O(N)`,className:`bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-semibold`})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Space Complexity:`}),(0,a.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),placeholder:`e.g. O(1)`,className:`bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-semibold`})]})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Problem Description:`}),(0,a.jsx)(`textarea`,{value:C,onChange:e=>w(e.target.value),placeholder:`Given an array of integers nums and an integer target...`,className:`bg-white border-2 border-ink-black p-2 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-sans h-20 resize-y leading-relaxed`})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1.5 bg-[#f6edd2] p-2.5 border-2 border-ink-black rounded`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsxs)(`label`,{className:`text-[10px] font-bold text-slate-700 uppercase flex items-center gap-1`,children:[(0,a.jsx)(`span`,{children:`🧪`}),` Examples (`,T.length,`)`]}),(0,a.jsx)(`button`,{type:`button`,onClick:te,className:`text-[9px] font-bold px-2 py-0.5 border border-ink-black bg-white hover:bg-slate-100 cursor-pointer shadow-[1px_1px_0px_#1E293B]`,children:`+ Add Example`})]}),T.map((e,t)=>(0,a.jsxs)(`div`,{className:`bg-white border border-ink-black p-2 space-y-1.5 rounded relative text-xs`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsxs)(`span`,{className:`font-bold text-[10px] text-slate-500`,children:[`Example `,t+1,`:`]}),T.length>1&&(0,a.jsx)(`button`,{type:`button`,onClick:()=>ne(t),className:`text-[10px] text-red-600 hover:text-red-800 font-bold`,children:`✕`})]}),(0,a.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,a.jsx)(`input`,{type:`text`,value:e.input,onChange:e=>$(t,`input`,e.target.value),placeholder:`Input: nums = [2,7,11,15], target = 9`,className:`bg-slate-50 border border-slate-300 p-1 text-[11px] font-mono outline-none`}),(0,a.jsx)(`input`,{type:`text`,value:e.output,onChange:e=>$(t,`output`,e.target.value),placeholder:`Output: [0,1]`,className:`bg-slate-50 border border-slate-300 p-1 text-[11px] font-mono outline-none`})]}),(0,a.jsx)(`input`,{type:`text`,value:e.explanation||``,onChange:e=>$(t,`explanation`,e.target.value),placeholder:`Explanation (Optional): Because nums[0] + nums[1] == 9, we return [0, 1].`,className:`bg-slate-50 border border-slate-300 p-1 text-[11px] outline-none w-full`})]},t))]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Constraints (1 per line):`}),(0,a.jsx)(`textarea`,{value:D,onChange:e=>O(e.target.value),placeholder:`2 <= nums.length <= 10^4
|
| 4 |
+
-10^9 <= nums[i] <= 10^9
|
| 5 |
+
Only one valid answer exists.`,className:`bg-white border-2 border-ink-black p-2 text-xs font-mono outline-none focus:ring-1 focus:ring-primary-purple h-16 resize-y leading-snug`})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsxs)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase flex items-center gap-1`,children:[(0,a.jsx)(`span`,{children:`💡`}),` "How to solve?" Intuition:`]}),(0,a.jsxs)(`button`,{type:`button`,onClick:X,disabled:V,className:`text-[9px] font-arcade font-bold px-2 py-0.5 border-2 border-ink-black bg-[#ffe24c] hover:bg-yellow-300 disabled:opacity-50 flex items-center gap-1 shadow-[1px_1px_0px_#1E293B] cursor-pointer`,children:[(0,a.jsx)(`span`,{children:`✦`}),` `,V?`GENERATING...`:`AI INTUITION`]})]}),(0,a.jsx)(`textarea`,{value:k,onChange:e=>A(e.target.value),placeholder:`Explain the mental model, dummy nodes, invariants, or two-pointer logic...`,className:`bg-white border-2 border-ink-black p-2 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-sans h-24 resize-y leading-relaxed`})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsxs)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase flex items-center gap-1`,children:[(0,a.jsx)(`span`,{children:`🐍`}),` Solution Code (Python):`]}),(0,a.jsxs)(`button`,{type:`button`,onClick:Z,disabled:U||!j.trim(),className:`text-[9px] font-arcade font-bold px-2 py-0.5 border-2 border-ink-black bg-[#a7f3d0] hover:bg-emerald-300 disabled:opacity-50 flex items-center gap-1 shadow-[1px_1px_0px_#1E293B] cursor-pointer text-emerald-950`,children:[(0,a.jsx)(`span`,{children:`✨`}),` `,U?`FORMATTING...`:`ADD EMOJI COMMENTS`]})]}),(0,a.jsx)(`textarea`,{value:j,onChange:e=>M(e.target.value),placeholder:`def twoSum(nums: list[int], target: int) -> list[int]:
|
| 6 |
+
# 1. 🗺️ Initialize lookup map
|
| 7 |
+
seen = {}
|
| 8 |
+
...
|
| 9 |
+
return []`,className:`bg-slate-900 text-[#4ADE80] font-mono p-2.5 border-2 border-ink-black rounded outline-none h-44 text-xs leading-relaxed resize-y w-full`})]})]}):(0,a.jsxs)(`div`,{className:`bg-white border-2 border-ink-black p-6 rounded shadow-sm font-sans space-y-4 text-slate-800`,children:[(0,a.jsx)(`div`,{className:`border-b pb-2`,children:(0,a.jsx)(`span`,{className:`text-[10px] font-mono uppercase bg-purple-100 text-purple-800 px-2 py-0.5 rounded font-bold`,children:`Google Doc Preview (Exact formatting preview)`})}),(0,a.jsxs)(`h1`,{className:`text-xl font-bold text-slate-900`,children:[p?`${p}. `:``,d||`Problem Title`]}),(0,a.jsx)(`div`,{children:(0,a.jsx)(`span`,{className:`text-xs font-bold px-2.5 py-0.5 rounded ${_===`Easy`?`bg-emerald-100 text-[#137c36]`:_===`Medium`?`bg-amber-100 text-[#c06100]`:`bg-rose-100 text-[#c5221f]`}`,children:_})}),C&&(0,a.jsx)(`div`,{className:`text-xs text-slate-700 leading-relaxed whitespace-pre-wrap`,children:C}),T.some(e=>e.input.trim()||e.output.trim())&&(0,a.jsx)(`div`,{className:`space-y-3 pt-2`,children:T.map((e,t)=>(0,a.jsxs)(`div`,{className:`text-xs space-y-1`,children:[(0,a.jsxs)(`div`,{className:`font-bold text-slate-800`,children:[`Example `,t+1,`:`]}),e.input&&(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`text-slate-600`,children:`Input: `}),(0,a.jsx)(`span`,{className:`bg-[#d9d9d9] font-mono px-1.5 py-0.5 rounded text-[11px]`,children:e.input})]}),e.output&&(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`text-slate-600`,children:`Output: `}),(0,a.jsx)(`span`,{className:`bg-[#d9d9d9] font-mono px-1.5 py-0.5 rounded text-[11px]`,children:e.output})]}),e.explanation&&(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`text-slate-600`,children:`Explanation: `}),(0,a.jsx)(`span`,{className:`bg-[#d9d9d9] font-mono px-1.5 py-0.5 rounded text-[11px]`,children:e.explanation})]})]},t))}),D&&(0,a.jsxs)(`div`,{className:`space-y-1.5 pt-2`,children:[(0,a.jsx)(`div`,{className:`font-bold text-xs text-slate-800`,children:`Constraints:`}),(0,a.jsx)(`ul`,{className:`list-disc pl-5 text-xs space-y-1`,children:D.split(`
|
| 10 |
+
`).filter(Boolean).map((e,t)=>(0,a.jsx)(`li`,{children:(0,a.jsx)(`span`,{className:`bg-[#d9d9d9] font-mono px-1.5 py-0.5 rounded text-[11px]`,children:e.replace(/^[•\-\*]\s*/,``)})},t))})]}),(0,a.jsxs)(`div`,{className:`pt-2`,children:[(0,a.jsx)(`div`,{className:`font-bold text-xs text-slate-800`,children:`Method:`}),(0,a.jsx)(`div`,{className:`text-xs text-slate-600`,children:`Pattern:`}),(0,a.jsx)(`h3`,{className:`text-base font-bold text-primary-purple mt-0.5`,children:h||`Standard`})]}),(0,a.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`font-bold text-slate-800`,children:`Time Complexity: `}),(0,a.jsx)(`span`,{className:`font-mono text-slate-900`,children:y})]}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`font-bold text-slate-800`,children:`Space Complexity: `}),(0,a.jsx)(`span`,{className:`font-mono text-slate-900`,children:x})]})]}),k&&(0,a.jsxs)(`div`,{className:`space-y-1.5 pt-2`,children:[(0,a.jsx)(`h3`,{className:`text-sm font-bold text-slate-900`,children:`How to solve?`}),(0,a.jsx)(`div`,{className:`text-xs text-slate-700 leading-relaxed whitespace-pre-wrap`,children:k})]}),j&&(0,a.jsx)(`div`,{className:`pt-2`,children:(0,a.jsx)(`div`,{className:`bg-[#f8fafc] border border-slate-300 p-3 rounded font-mono text-[11.5px] leading-relaxed text-slate-900 overflow-x-auto whitespace-pre`,children:j})})]})}),(0,a.jsxs)(`div`,{className:`p-3 bg-[#f0e6c8] border-t-2 border-ink-black flex flex-wrap items-center justify-between gap-2 shrink-0`,children:[(0,a.jsxs)(`label`,{className:`flex items-center gap-2 text-xs font-bold text-slate-700 cursor-pointer select-none`,children:[(0,a.jsx)(`input`,{type:`checkbox`,checked:N,onChange:e=>P(e.target.checked),className:`w-4 h-4 accent-primary-purple cursor-pointer`}),(0,a.jsx)(`span`,{children:`Format & Sync to Google Doc`})]}),(0,a.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,a.jsx)(`button`,{type:`button`,onClick:e,className:`px-3 py-1.5 bg-white hover:bg-slate-50 border-2 border-ink-black text-xs font-bold cursor-pointer`,children:`CANCEL`}),(0,a.jsxs)(`button`,{type:`submit`,disabled:z,className:`px-4 py-1.5 bg-primary-purple hover:bg-purple-600 text-white font-arcade text-[10px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer flex items-center gap-1.5`,children:[(0,a.jsx)(`span`,{children:`💾`}),` `,z?`SAVING...`:`SAVE SOLUTION`]})]})]})]})}export{s as default};
|
algospaced-ui/dist/assets/FileExplorer-BA3lbKpy.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import{a as e,c as t,i as n,t as r}from"./jsx-runtime-UoOgdb2P.js";var i=t(e(),1),a=r(),o=[{name:`Retro Arcade Grid.img`,url:`https://lh3.googleusercontent.com/aida-public/AB6AXuAMJHVhhK8_G7F8sbhn8F7w4AZWXb1O_-HLKvrZ_fJlbUVMcVuxxEOO_LlOh8qIwtAn2KvzvCwzmtNLLEZ5uYkCEsx8ZWXJR609qgSMRSX8LBBeskk4VzVXnyzsgIKCedeV2PvGxJlUNnledcWKCXqG9egQi8dgTcA7C2z82QyM73KZ4s7ZRzZHNupuQt1ocfcMl9E_x1PWFRridl751LIpyGZgednS5CmVw2rZvFc_tbp2QTxgVHJ_59myEBmy6aajbO06AhkKmCvI`,desc:`Default AlgoSpaced purple grid and pixel theme background.`},{name:`Classic Board Logo.img`,url:`https://lh3.googleusercontent.com/aida-public/AB6AXuD2tUGA2d7QiNyajDAWYK183zhNTgtAZpOXK3E9wRvHGs-t6ykWt9uPScYe_fziWzQI0pREcY_ThI341WvGMusyYmnAkagfuwx6wubIs1ES68DO8CCNAlcHcb2zOUU4MJeYuhWDy1uYRqyGYjIaDUqfgNWk2vm4WzwRqoorn2dxtZ6QdJhEKbXjG8fG9chkkvr68qJf0fLUL6bIqBXZg2FJ30S7zS3oZ4IZsug-wLyRYuJ4Gu_86snNUo1whNrBdZm5OMREfc9sLbwJ`,desc:`System info and arcade machine diagram wallpaper.`},{name:`Terminal Console Icon.img`,url:`https://lh3.googleusercontent.com/aida-public/AB6AXuA2AvcQ2oKWP8AJ8yR5nF82LLDEH1FKySUK-npnqEjvJ6Cs9xp8joCwH7x43oTCAC5xhO2rQdYzka3B6u72FNbdxMnsv3WJLye3bKochu8AnnRlS3szfYSaj724sYsiZo4n8G-oWqvl7C0rOGaDaU2nRH1xXmW2PBi6L2NryTsUaTCVZQKTKBBNNEOig5kh7B52e-iIuj2PTzaSjF9ebp6gMuCnBtJT8Sxo5Qsmvfm-t2U5r_qQpRiYj--Ut41T7NTh-tHgs4S4kBvz`,desc:`Dark retro CRT terminal screen layout.`},{name:`Synthwave Sunset Grid.img`,url:`https://images.unsplash.com/photo-1550745165-9bc0b252726f?q=80&w=1000&auto=format&fit=crop`,desc:`Glowing neon grids and vector mountains styling.`},{name:`Matrix Code Rain.img`,url:`https://images.unsplash.com/photo-1526374965328-7f61d4dc18c5?q=80&w=1000&auto=format&fit=crop`,desc:`Falling green digital characters rain.`}];function s({onSetWallpaper:e,activeWallpaperUrl:t,onOpenCreateProblem:r,onOpenQueue:s,onOpenJourney:c,refreshTrigger:l}){let[u,d]=(0,i.useState)([`C:`]),[f,p]=(0,i.useState)([]),[m,h]=(0,i.useState)(!0),[g,_]=(0,i.useState)(null),v=i.useMemo(()=>{let e=[...o],t=localStorage.getItem(`customWallpaperUrl`),n=localStorage.getItem(`customWallpaperName`)||`Custom Wallpaper.img`;return t&&(e.some(e=>e.url===t)||e.push({name:n,url:t,desc:`User uploaded custom background wallpaper.`})),e},[t]),[y,ee]=(0,i.useState)(``),[b,te]=(0,i.useState)(`All`),[x,S]=(0,i.useState)(`All`),[C,w]=(0,i.useState)(!1),[ne,T]=(0,i.useState)(!1),[E,D]=(0,i.useState)(!1),[O,k]=(0,i.useState)(``),[A,j]=(0,i.useState)(``),re=async e=>{let t=e.target.files;if(!t||t.length===0)return;let r=t[0];e.target.value=``,D(!0),k(``),j(``);try{let{data:{session:e}}=await n.auth.getSession(),t=e?e.access_token:`sandbox`,i=new FormData;i.append(`file`,r);let a=await fetch(`/api/explorer/import`,{method:`POST`,headers:{Authorization:`Bearer ${t}`},body:i}),o=await a.json();a.ok?(j(o.message||`Problems imported successfully!`),setTimeout(()=>{q()},500),setTimeout(()=>{T(!1),j(``)},2e3)):k(o.detail||`Import failed. Verify the file format.`)}catch{k(`Import failed due to a network error.`)}finally{D(!1)}},[M,N]=(0,i.useState)(null),[P,F]=(0,i.useState)(`description`),[I,L]=(0,i.useState)(!1),[R,z]=(0,i.useState)(``),[B,V]=(0,i.useState)(``),[H,U]=(0,i.useState)(!1),[W,G]=(0,i.useState)(!1),[ie,K]=(0,i.useState)(!1),q=async()=>{h(!0);try{let{data:{session:e}}=await n.auth.getSession();if(!e)return;let t=await fetch(`/api/explorer/problems`,{headers:{Authorization:`Bearer ${e.access_token}`}});if(t.ok){let e=await t.json();p(e)}}catch(e){console.error(`Failed to fetch explorer files:`,e)}finally{h(!1)}};(0,i.useEffect)(()=>{q()},[l]);let J=e=>{d([`C:`,e]),_(null)},ae=()=>{u.length>1&&(d([`C:`]),_(null))},oe=async()=>{try{let{data:{session:e}}=await n.auth.getSession();if(!e)return;let t=await fetch(`/api/explorer/export`,{headers:{Authorization:`Bearer ${e.access_token}`}});if(t.ok){let e=await t.blob(),n=window.URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`algospaced_solutions.zip`,document.body.appendChild(r),r.click(),document.body.removeChild(r),window.URL.revokeObjectURL(n)}}catch(e){console.error(`Failed to download solutions ZIP:`,e)}},se=async()=>{if(M){U(!0),G(!1);try{let{data:{session:e}}=await n.auth.getSession();if(!e)return;if((await fetch(`/api/explorer/problems/${M.id}`,{method:`PUT`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${e.access_token}`},body:JSON.stringify({name:M.name,pattern:M.pattern,difficulty:M.difficulty,reference_code:R,description:B})})).ok){G(!0),L(!1);let e=f.map(e=>e.id===M.id?{...e,reference_code:R,description:B}:e);p(e),N({...M,reference_code:R,description:B}),setTimeout(()=>G(!1),2e3)}}catch(e){console.error(`Failed to update solution code:`,e)}finally{U(!1)}}},ce=e=>{e.preventDefault(),w(!0)},le=()=>{w(!1)},ue=async e=>{e.preventDefault(),w(!1);let t=e.dataTransfer.files;if(t.length>0){let e=t[0];if(e.name.endsWith(`.py`))try{let t=await e.text(),n=e.name.replace(`.py`,``).replace(/_/g,` `).replace(/-/g,` `),i=`General`,a=`Medium`,o=t.match(/#\s*Pattern:\s*(.+)/i);o&&(i=o[1].trim());let s=t.match(/#\s*Difficulty:\s*(.+)/i);if(s){let e=s[1].trim();[`Easy`,`Medium`,`Hard`].includes(e)&&(a=e)}let c=t.split(`
|
| 2 |
+
`),l=[];for(let e of c){let t=e.trim();if(t.startsWith(`#`)){if(t.match(/#\s*(Pattern|Difficulty|Problem|Description):/i))continue;l.push(t.replace(/^#\s*/,``))}else if(t!==``)break}let u=l.join(`
|
| 3 |
+
`).trim();localStorage.setItem(`algospaced_prefill_draft`,JSON.stringify({name:n,pattern:i,difficulty:a,code:t,description:u})),r&&r()}catch(e){console.error(`Failed to parse uploaded script:`,e)}}},de=e=>{navigator.clipboard.writeText(e),K(!0),setTimeout(()=>K(!1),2e3)},Y=u.length>1?u[1]:`root`,X=f.length,fe=f.filter(e=>e.reference_code&&e.reference_code.trim()).length,Z=X>0?Math.round(fe/X*100):0,Q={1:0,2:0,3:0,4:0,5:0};f.forEach(e=>{if(e.box_level!==null&&e.box_level!==void 0){let t=e.box_level;t>=1&&t<=5&&Q[t]++}});let pe=Array.from(new Set(f.map(e=>e.pattern).filter(Boolean))),$=f.filter(e=>{let t=e.name.toLowerCase().includes(y.toLowerCase()),n=b===`All`||e.difficulty===b,r=x===`All`||e.pattern===x;return t&&n&&r});return(0,a.jsxs)(`div`,{className:`w-full h-full bg-paper-white text-ink-black flex flex-col overflow-hidden text-xs md:text-sm font-sans select-none`,children:[(0,a.jsxs)(`div`,{className:`bg-slate-200 border-b-[3px] border-ink-black p-2 flex items-center justify-between shrink-0`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-2 flex-1`,children:[(0,a.jsx)(`button`,{onClick:ae,disabled:u.length===1,className:`w-7 h-7 bg-white border-2 border-ink-black flex items-center justify-center hover:bg-slate-100 disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer active:translate-y-0.5`,title:`Up One Folder`,children:(0,a.jsx)(`span`,{className:`material-symbols-outlined text-[16px] font-bold`,children:`arrow_upward`})}),(0,a.jsx)(`div`,{className:`bg-white border-2 border-ink-black px-3 py-1 font-mono text-[10px] flex-1 max-w-[280px] truncate`,children:u.join(`\\`)})]}),(0,a.jsxs)(`div`,{className:`flex gap-3 text-[10px] font-bold pr-2 font-mono items-center`,children:[Y===`Database_Codes`&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(`button`,{onClick:()=>r&&r(),className:`text-blue-700 hover:underline cursor-pointer flex items-center gap-0.5`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-[12px] font-bold`,children:`add_box`}),`NEW FILE`]}),(0,a.jsx)(`span`,{className:`text-slate-400`,children:`|`}),(0,a.jsxs)(`button`,{onClick:()=>T(!0),className:`text-indigo-700 hover:underline cursor-pointer flex items-center gap-0.5`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-[12px] font-bold`,children:`upload`}),`IMPORT (.CSV / .DB)`]}),(0,a.jsx)(`span`,{className:`text-slate-400`,children:`|`}),(0,a.jsxs)(`button`,{onClick:oe,className:`text-purple-700 hover:underline cursor-pointer flex items-center gap-0.5`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-[12px] font-bold`,children:`downloadzip`}),`BACKUP (.ZIP)`]}),(0,a.jsx)(`span`,{className:`text-slate-400`,children:`|`})]}),(0,a.jsx)(`span`,{className:`text-slate-500`,children:Y===`root`?`2 Folder(s)`:Y===`Database_Codes`?`${$.length} of ${f.length} item(s)`:`${v.length} image(s)`})]})]}),(0,a.jsxs)(`div`,{className:`flex-1 flex overflow-hidden`,children:[(0,a.jsxs)(`aside`,{className:`w-1/3 border-r-[3px] border-ink-black bg-[#fdf8e1] p-3 overflow-y-auto custom-scrollbar flex flex-col gap-4 shrink-0`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`text-[9px] font-arcade text-slate-500 block uppercase mb-1.5`,children:`Folders`}),(0,a.jsxs)(`div`,{className:`space-y-1`,children:[(0,a.jsxs)(`button`,{onClick:()=>d([`C:`]),className:`w-full text-left p-1.5 flex items-center gap-1.5 font-semibold border-2 border-transparent hover:bg-slate-100 rounded ${u.length===1?`bg-white border-ink-black`:``}`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-[#855400] text-sm`,style:{fontVariationSettings:`'FILL' 1`},children:`desktop_windows`}),(0,a.jsx)(`span`,{children:`C: (Root)`})]}),(0,a.jsxs)(`div`,{className:`pl-4 space-y-1`,children:[(0,a.jsxs)(`button`,{onClick:()=>J(`Database_Codes`),className:`w-full text-left p-1.5 flex items-center gap-1.5 font-semibold border-2 border-transparent hover:bg-slate-100 rounded ${Y===`Database_Codes`?`bg-white border-ink-black`:``}`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-yellow-600 text-sm`,style:{fontVariationSettings:`'FILL' 1`},children:`folder`}),(0,a.jsx)(`span`,{className:`truncate`,children:`Database_Codes`})]}),(0,a.jsxs)(`button`,{onClick:()=>J(`Wallpapers`),className:`w-full text-left p-1.5 flex items-center gap-1.5 font-semibold border-2 border-transparent hover:bg-slate-100 rounded ${Y===`Wallpapers`?`bg-white border-ink-black`:``}`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-yellow-600 text-sm`,style:{fontVariationSettings:`'FILL' 1`},children:`folder`}),(0,a.jsx)(`span`,{className:`truncate`,children:`Wallpapers`})]})]})]})]}),(0,a.jsxs)(`div`,{className:`border-t-2 border-dashed border-slate-300 pt-3`,children:[(0,a.jsx)(`span`,{className:`text-[9px] font-arcade text-slate-500 block uppercase mb-2`,children:`System Statistics`}),(0,a.jsxs)(`div`,{className:`space-y-3 font-sans text-[11px] font-bold text-slate-700`,children:[(0,a.jsxs)(`div`,{className:`space-y-1`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between text-[10px]`,children:[(0,a.jsx)(`span`,{children:`CODE COMPLETION:`}),(0,a.jsxs)(`span`,{className:`font-mono text-emerald-600`,children:[Z,`%`]})]}),(0,a.jsx)(`div`,{className:`w-full h-4 bg-white border-2 border-ink-black overflow-hidden relative`,children:(0,a.jsx)(`div`,{style:{width:`${Z}%`},className:`h-full bg-emerald-500 border-r-2 border-ink-black transition-all duration-500`})})]}),(0,a.jsxs)(`div`,{className:`space-y-1.5 mt-2`,children:[(0,a.jsx)(`span`,{className:`text-[9px] uppercase text-slate-500 block`,children:`Leitner Distribution:`}),[1,2,3,4,5].map(e=>{let t=Q[e],n=Math.max(...Object.values(Q),1),r=Math.max(8,Math.round(t/n*100));return(0,a.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,a.jsxs)(`span`,{className:`w-9 font-mono text-[10px] text-slate-400`,children:[`Box `,e,`:`]}),(0,a.jsx)(`div`,{className:`flex-1 h-3 bg-white border border-ink-black overflow-hidden relative`,children:(0,a.jsx)(`div`,{style:{width:`${r}%`},className:`h-full bg-[#0ea5e9] border-r border-ink-black transition-all`})}),(0,a.jsx)(`span`,{className:`w-4 text-right font-mono text-[10px] text-slate-600`,children:t})]},e)})]})]})]})]}),(0,a.jsxs)(`main`,{onDragOver:ce,onDragLeave:le,onDrop:ue,className:`flex-1 bg-white p-4 overflow-y-auto custom-scrollbar flex flex-col relative transition-all ${C?`bg-blue-50 border-4 border-dashed border-blue-500 m-2`:``}`,children:[C&&(0,a.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center text-blue-800 bg-white/80 pointer-events-none select-none z-[10] gap-2 font-sans font-bold`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-5xl animate-bounce`,children:`upload_file`}),(0,a.jsx)(`div`,{className:`text-sm`,children:`DROP SOLUTIONS PYTHON SCRIPT (.PY) HERE`}),(0,a.jsx)(`p`,{className:`text-[10px] text-slate-400`,children:`Will load and parse file metadata for import`})]}),m?(0,a.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center font-arcade text-[8px] animate-pulse`,children:`READING SYSTEM DISK...`}):(0,a.jsxs)(a.Fragment,{children:[Y===`Database_Codes`&&(0,a.jsxs)(`div`,{className:`mb-4 bg-slate-50 border-[2px] border-ink-black p-2 flex flex-col gap-2 shrink-0 select-none`,children:[(0,a.jsx)(`div`,{className:`flex gap-2`,children:(0,a.jsxs)(`div`,{className:`flex-1 bg-white border border-slate-300 rounded px-2 py-1 flex items-center gap-1`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-slate-400 text-sm`,children:`search`}),(0,a.jsx)(`input`,{type:`text`,value:y,onChange:e=>ee(e.target.value),className:`w-full bg-transparent outline-none border-none p-0 text-[11px] focus:ring-0 font-sans`,placeholder:`Search codes by name...`})]})}),(0,a.jsxs)(`div`,{className:`flex gap-3 text-[10px] font-bold text-slate-600`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,a.jsx)(`span`,{children:`Diff:`}),(0,a.jsxs)(`select`,{value:b,onChange:e=>te(e.target.value),className:`bg-white border border-slate-300 p-0.5 text-[9px] rounded font-sans cursor-pointer focus:ring-1 outline-none`,children:[(0,a.jsx)(`option`,{value:`All`,children:`All`}),(0,a.jsx)(`option`,{value:`Easy`,children:`Easy`}),(0,a.jsx)(`option`,{value:`Medium`,children:`Medium`}),(0,a.jsx)(`option`,{value:`Hard`,children:`Hard`})]})]}),(0,a.jsxs)(`div`,{className:`flex items-center gap-1 flex-1`,children:[(0,a.jsx)(`span`,{children:`Pattern:`}),(0,a.jsxs)(`select`,{value:x,onChange:e=>S(e.target.value),className:`bg-white border border-slate-300 p-0.5 text-[9px] rounded font-sans cursor-pointer max-w-[120px] focus:ring-1 outline-none truncate`,children:[(0,a.jsx)(`option`,{value:`All`,children:`All`}),pe.map(e=>(0,a.jsx)(`option`,{value:e,children:e},e))]})]})]})]}),Y===`root`&&(0,a.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,a.jsxs)(`div`,{onDoubleClick:()=>s&&s(),onClick:()=>_(`queue_app`),className:`flex flex-col items-center justify-center p-3 border-[3px] border-transparent hover:bg-slate-50 cursor-pointer rounded select-none ${g===`queue_app`?`bg-green-50 border-dashed border-ink-black`:``}`,children:[(0,a.jsx)(`div`,{className:`w-12 h-12 bg-grass-green border-2 border-ink-black flex items-center justify-center shadow-[2px_2px_0px_0px_#1E293B]`,children:(0,a.jsx)(`span`,{className:`material-symbols-outlined text-3xl text-ink-black`,style:{fontVariationSettings:`'FILL' 1`},children:`view_list`})}),(0,a.jsx)(`span`,{className:`font-bold text-center mt-2 text-xs`,children:`Daily_Queue.exe`}),(0,a.jsx)(`span`,{className:`text-[9px] text-slate-400 mt-0.5`,children:`Spaced Repetition Review`})]}),(0,a.jsxs)(`div`,{onDoubleClick:()=>c&&c(),onClick:()=>_(`journey_app`),className:`flex flex-col items-center justify-center p-3 border-[3px] border-transparent hover:bg-slate-50 cursor-pointer rounded select-none ${g===`journey_app`?`bg-blue-50 border-dashed border-ink-black`:``}`,children:[(0,a.jsx)(`div`,{className:`w-12 h-12 bg-[#0ea5e9] border-2 border-ink-black flex items-center justify-center shadow-[2px_2px_0px_0px_#1E293B]`,children:(0,a.jsx)(`span`,{className:`material-symbols-outlined text-3xl text-white`,style:{fontVariationSettings:`'FILL' 1`},children:`route`})}),(0,a.jsx)(`span`,{className:`font-bold text-center mt-2 text-xs`,children:`Journey_Path.exe`}),(0,a.jsx)(`span`,{className:`text-[9px] text-slate-400 mt-0.5`,children:`NeetCode 150 Road`})]}),(0,a.jsxs)(`div`,{onDoubleClick:()=>J(`Database_Codes`),onClick:()=>_(`codes`),className:`flex flex-col items-center justify-center p-3 border-[3px] border-transparent hover:bg-slate-50 cursor-pointer rounded select-none ${g===`codes`?`bg-yellow-50 border-dashed border-ink-black`:``}`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-5xl text-yellow-500`,style:{fontVariationSettings:`'FILL' 1`},children:`folder`}),(0,a.jsx)(`span`,{className:`font-bold text-center mt-2 text-xs`,children:`Database_Codes`}),(0,a.jsx)(`span`,{className:`text-[9px] text-slate-400 mt-0.5`,children:`Synced solution files`})]}),(0,a.jsxs)(`div`,{onDoubleClick:()=>J(`Wallpapers`),onClick:()=>_(`wallpapers`),className:`flex flex-col items-center justify-center p-3 border-[3px] border-transparent hover:bg-slate-50 cursor-pointer rounded select-none ${g===`wallpapers`?`bg-yellow-50 border-dashed border-ink-black`:``}`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-5xl text-yellow-500`,style:{fontVariationSettings:`'FILL' 1`},children:`folder`}),(0,a.jsx)(`span`,{className:`font-bold text-center mt-2 text-xs`,children:`Wallpapers`}),(0,a.jsx)(`span`,{className:`text-[9px] text-slate-400 mt-0.5`,children:`Desktop wallpaper images`})]})]}),Y===`Database_Codes`&&($.length===0?(0,a.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center text-slate-400 p-6 italic select-none`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-3xl mb-1`,children:`drafts`}),`No matching files found. Drag and drop a .py script to upload/create!`]}):(0,a.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:$.map(e=>{let t=`${e.name.replace(/\s+/g,`_`)}.py`,n=g===e.id;return(0,a.jsxs)(`div`,{onClick:()=>_(e.id),onDoubleClick:()=>{N(e),z(e.reference_code||``),V(e.description||``),F(`description`),L(!1)},className:`flex flex-col items-center p-2 border-[3px] border-transparent hover:bg-slate-50 cursor-pointer rounded select-none text-center ${n?`bg-yellow-50 border-dashed border-ink-black`:``}`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-3xl text-emerald-600`,children:`article`}),(0,a.jsx)(`span`,{className:`font-bold text-[10px] truncate w-full mt-1.5 leading-tight`,children:t}),(0,a.jsx)(`span`,{className:`text-[8px] text-slate-400 font-bold uppercase mt-0.5`,children:e.difficulty})]},e.id)})})),Y===`Wallpapers`&&(0,a.jsx)(`div`,{className:`grid grid-cols-2 gap-3 select-none`,children:v.map(n=>{let r=g===n.name,i=t===n.url;return(0,a.jsxs)(`div`,{onClick:()=>_(n.name),className:`border-[3px] p-2 flex flex-col cursor-pointer bg-slate-50 relative hover:bg-slate-100 ${r?`border-ink-black bg-yellow-50 shadow-[2px_2px_0_0_#1E293B]`:`border-slate-300`}`,children:[(0,a.jsxs)(`div`,{className:`aspect-video w-full border border-slate-300 overflow-hidden bg-black shrink-0 relative`,children:[(0,a.jsx)(`img`,{src:n.url,alt:n.name,className:`w-full h-full object-cover select-none`}),i&&(0,a.jsx)(`div`,{className:`absolute top-1 right-1 bg-green-500 text-white rounded-full w-5 h-5 flex items-center justify-center border border-white`,title:`Active Wallpaper`,children:(0,a.jsx)(`span`,{className:`material-symbols-outlined text-[12px] font-extrabold`,children:`check`})})]}),(0,a.jsx)(`span`,{className:`font-bold text-[10px] mt-1.5 truncate`,children:n.name}),(0,a.jsx)(`p`,{className:`text-[8px] text-slate-400 font-sans leading-tight mt-0.5 line-clamp-2`,children:n.desc}),r&&(0,a.jsx)(`button`,{onClick:t=>{t.stopPropagation(),e(n.url),localStorage.setItem(`desktopWallpaperUrl`,n.url)},className:`mt-2 w-full py-1 bg-highlight-pink text-white border-2 border-ink-black font-window-title font-bold text-[9px] hover:bg-pink-400 shadow-[1px_1px_0px_rgba(0,0,0,1)] active:translate-y-0.5 active:shadow-none transition-all text-center cursor-pointer`,children:`APPLY BACKGROUND`})]},n.name)})})]})]})]}),M&&(0,a.jsx)(`div`,{className:`absolute inset-0 bg-black/60 z-[999] flex items-center justify-center p-4`,children:(0,a.jsxs)(`div`,{className:`w-[90%] h-[90%] bg-paper-white border-[4px] border-ink-black shadow-[6px_6px_0px_0px_#1E293B] flex flex-col overflow-hidden animate-scale-up text-ink-black`,children:[(0,a.jsxs)(`div`,{className:`bg-emerald-600 text-white p-2 border-b-[3px] border-ink-black flex justify-between items-center shrink-0 select-none`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-sm`,children:`article`}),(0,a.jsxs)(`span`,{className:`font-window-title font-bold text-xs`,children:[M.name.replace(/\s+/g,`_`),`.py`]})]}),(0,a.jsx)(`button`,{onClick:()=>N(null),className:`bg-white text-ink-black border-[2px] border-ink-black w-5 h-5 flex items-center justify-center font-bold hover:bg-red-500 hover:text-white cursor-pointer`,children:`X`})]}),(0,a.jsxs)(`div`,{className:`bg-slate-200 border-b-2 border-ink-black flex shrink-0 select-none`,children:[(0,a.jsx)(`button`,{onClick:()=>F(`description`),className:`px-4 py-2 border-r-2 border-ink-black font-bold text-[11px] cursor-pointer ${P===`description`?`bg-white translate-y-[2px]`:`bg-slate-300 hover:bg-slate-100`}`,children:`PROBLEM DESCRIPTION`}),(0,a.jsx)(`button`,{onClick:()=>F(`code`),className:`px-4 py-2 border-r-2 border-ink-black font-bold text-[11px] cursor-pointer ${P===`code`?`bg-white translate-y-[2px]`:`bg-slate-300 hover:bg-slate-100`}`,children:`CODE VIEW & EDIT`}),(0,a.jsx)(`button`,{onClick:()=>F(`properties`),className:`px-4 py-2 border-r-2 border-ink-black font-bold text-[11px] cursor-pointer ${P===`properties`?`bg-white translate-y-[2px]`:`bg-slate-300 hover:bg-slate-100`}`,children:`LEITNER PROPERTIES`})]}),P===`description`&&(0,a.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden bg-slate-900 relative`,children:[I?(0,a.jsx)(`textarea`,{value:B,onChange:e=>V(e.target.value),className:`flex-1 w-full bg-slate-950 text-[#4ADE80] font-mono p-4 outline-none border-none text-xs leading-relaxed resize-none custom-scrollbar`,placeholder:`Enter problem description / question body here...`,spellCheck:`false`}):(0,a.jsx)(`div`,{className:`flex-1 p-4 bg-slate-900 text-[#4ADE80] font-sans text-xs leading-relaxed overflow-y-auto custom-scrollbar select-text`,children:(0,a.jsx)(`div`,{className:`whitespace-pre-wrap font-semibold`,children:M.description||`No description provided for this problem.`})}),I&&(0,a.jsx)(`div`,{className:`absolute top-2 right-2 bg-yellow-400 text-ink-black border border-ink-black px-2 py-0.5 text-[9px] font-bold select-none animate-pulse`,children:`EDIT MODE ACTIVE`})]}),P===`code`&&(0,a.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden bg-slate-900 relative`,children:[I?(0,a.jsx)(`textarea`,{value:R,onChange:e=>z(e.target.value),className:`flex-1 w-full bg-slate-950 text-[#4ADE80] font-mono p-4 outline-none border-none text-xs leading-relaxed resize-none custom-scrollbar`,spellCheck:`false`}):(0,a.jsx)(`textarea`,{readOnly:!0,value:M.reference_code||`# Write your solution here.`,className:`flex-1 w-full bg-slate-900 text-[#4ADE80] font-mono p-4 outline-none border-none text-xs leading-relaxed resize-none custom-scrollbar`,spellCheck:`false`}),I&&(0,a.jsx)(`div`,{className:`absolute top-2 right-2 bg-yellow-400 text-ink-black border border-ink-black px-2 py-0.5 text-[9px] font-bold select-none animate-pulse`,children:`EDIT MODE ACTIVE`})]}),P===`properties`&&(0,a.jsxs)(`div`,{className:`flex-1 p-6 overflow-y-auto custom-scrollbar bg-slate-50 font-sans leading-relaxed select-text flex flex-col gap-4`,children:[(0,a.jsx)(`h3`,{className:`font-arcade text-[10px] border-b border-slate-300 pb-1 text-slate-500`,children:`Card Diagnostics`}),(0,a.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,a.jsxs)(`div`,{className:`border-[3px] border-ink-black bg-white p-3 space-y-2`,children:[(0,a.jsx)(`span`,{className:`text-[9px] font-arcade text-[#0ea5e9] block`,children:`Scheduling Status`}),(0,a.jsxs)(`div`,{children:[`Leitner Combo Box: `,(0,a.jsx)(`span`,{className:`font-mono font-bold text-lg text-sky-600`,children:M.box_level||`N/A (Box 1)`})]}),(0,a.jsxs)(`div`,{children:[`Next Review Date: `,(0,a.jsx)(`span`,{className:`font-mono text-xs font-semibold`,children:M.next_review?new Date(M.next_review).toLocaleString():`N/A (Due)`})]}),(0,a.jsxs)(`div`,{children:[`Last Reviewed: `,(0,a.jsx)(`span`,{className:`font-mono text-xs font-semibold`,children:M.last_reviewed?new Date(M.last_reviewed).toLocaleDateString():`Never`})]})]}),(0,a.jsxs)(`div`,{className:`border-[3px] border-ink-black bg-white p-3 space-y-2`,children:[(0,a.jsx)(`span`,{className:`text-[9px] font-arcade text-emerald-600 block`,children:`Performance History`}),(0,a.jsxs)(`div`,{children:[`Total Attempts: `,(0,a.jsx)(`span`,{className:`font-mono font-bold text-sm`,children:M.total_attempts})]}),(0,a.jsxs)(`div`,{children:[`Times Correct: `,(0,a.jsx)(`span`,{className:`font-mono font-bold text-sm text-green-600`,children:M.times_correct})]}),(0,a.jsxs)(`div`,{children:[`Success Ratio: `,(0,a.jsx)(`span`,{className:`font-mono font-bold text-sm text-purple-700`,children:M.total_attempts>0?`${Math.round(M.times_correct/M.total_attempts*100)}%`:`0%`})]})]})]}),(0,a.jsxs)(`div`,{className:`border-[3px] border-ink-black bg-white p-3 space-y-1.5 text-xs font-semibold`,children:[(0,a.jsx)(`span`,{className:`text-[9px] font-arcade text-slate-400 block`,children:`Properties`}),(0,a.jsxs)(`div`,{children:[`File ID: `,(0,a.jsx)(`span`,{className:`font-mono text-[10px] text-slate-500`,children:M.id})]}),(0,a.jsxs)(`div`,{children:[`Logical Pattern: `,(0,a.jsx)(`span`,{className:`text-blue-600`,children:M.pattern})]}),(0,a.jsxs)(`div`,{children:[`Difficulty Tag: `,(0,a.jsx)(`span`,{className:`uppercase`,children:M.difficulty})]})]})]}),(0,a.jsxs)(`div`,{className:`p-3 bg-slate-100 border-t-[3px] border-ink-black flex justify-between items-center shrink-0 select-none`,children:[(0,a.jsx)(`div`,{children:W&&(0,a.jsx)(`span`,{className:`text-green-600 font-bold text-xs animate-pulse`,children:`✓ Solution saved!`})}),(0,a.jsxs)(`div`,{className:`flex gap-2`,children:[(P===`code`||P===`description`)&&(I?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`button`,{onClick:()=>{z(M.reference_code||``),V(M.description||``),L(!1)},className:`px-3 py-1.5 bg-white hover:bg-slate-50 text-ink-black border-2 border-ink-black font-bold text-xs cursor-pointer`,children:`CANCEL`}),(0,a.jsx)(`button`,{disabled:H,onClick:se,className:`px-3 py-1.5 bg-[#4ADE80] hover:bg-emerald-400 text-ink-black border-2 border-ink-black font-bold text-xs cursor-pointer shadow-[2px_2px_0px_rgba(0,0,0,1)] active:translate-y-0.5 active:shadow-none`,children:H?`SAVING...`:`SAVE CHANGES`})]}):(0,a.jsxs)(`button`,{onClick:()=>L(!0),className:`px-3 py-1.5 bg-yellow-400 hover:bg-yellow-300 text-ink-black border-2 border-ink-black font-bold text-xs cursor-pointer shadow-[2px_2px_0px_rgba(0,0,0,1)] active:translate-y-0.5 active:shadow-none flex items-center gap-1`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-sm`,children:`edit`}),`EDIT FILE`]})),(0,a.jsxs)(`button`,{onClick:()=>de(I?R:M.reference_code),className:`px-3 py-1.5 bg-[#ffcc00] hover:bg-yellow-300 text-ink-black border-2 border-ink-black font-bold text-xs shadow-[2px_2px_0px_rgba(0,0,0,1)] active:translate-y-0.5 active:shadow-none cursor-pointer flex items-center gap-1`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-sm`,children:`content_copy`}),ie?`COPIED!`:`COPY CODE`]}),(0,a.jsx)(`button`,{onClick:()=>N(null),className:`px-3 py-1.5 bg-white hover:bg-slate-50 text-ink-black border-2 border-ink-black font-bold text-xs shadow-[2px_2px_0px_rgba(0,0,0,1)] active:translate-y-0.5 active:shadow-none cursor-pointer`,children:`CLOSE`})]})]})]})}),ne&&(0,a.jsx)(`div`,{className:`absolute inset-0 bg-black/60 z-[999] flex items-center justify-center p-4 select-none`,children:(0,a.jsxs)(`div`,{className:`w-[80%] max-w-[400px] bg-paper-white border-[4px] border-ink-black shadow-[6px_6px_0px_0px_#1E293B] flex flex-col overflow-hidden animate-scale-up text-ink-black font-sans`,children:[(0,a.jsxs)(`div`,{className:`bg-indigo-700 text-white p-2.5 border-b-[3px] border-ink-black flex justify-between items-center font-bold`,children:[(0,a.jsx)(`span`,{className:`font-window-title text-xs`,children:`IMPORT PROBLEMS`}),(0,a.jsx)(`button`,{onClick:()=>{T(!1),k(``),j(``)},className:`bg-white text-ink-black border-[2px] border-ink-black w-5 h-5 flex items-center justify-center font-bold hover:bg-red-500 hover:text-white cursor-pointer`,children:`X`})]}),(0,a.jsxs)(`div`,{className:`p-6 space-y-4`,children:[O&&(0,a.jsx)(`div`,{className:`p-2 border-2 border-red-500 bg-red-50 text-red-800 text-[10px] font-mono leading-relaxed`,children:O}),A&&(0,a.jsx)(`div`,{className:`p-2 border-2 border-green-500 bg-green-50 text-green-800 text-[10px] font-mono leading-relaxed`,children:A}),(0,a.jsxs)(`div`,{className:`flex flex-col items-center justify-center border-4 border-dashed border-ink-black p-6 relative ${E?`bg-indigo-50 cursor-wait`:`bg-slate-50 hover:bg-slate-100 cursor-pointer`}`,children:[E?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-4xl text-indigo-700 mb-2 animate-bounce`,children:`cloud_upload`}),(0,a.jsx)(`span`,{className:`text-xs font-bold text-indigo-800 text-center`,children:`UPLOADING & PROCESSING...`}),(0,a.jsx)(`span`,{className:`text-[9px] text-indigo-600 mt-1 uppercase font-semibold text-center`,children:`Please wait, this might take a moment`})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-4xl text-indigo-700 mb-2`,children:`upload_file`}),(0,a.jsx)(`span`,{className:`text-xs font-bold text-ink-black text-center`,children:`SELECT A CSV OR SQLite (.DB) FILE`}),(0,a.jsx)(`span`,{className:`text-[9px] text-slate-400 mt-1 uppercase font-semibold text-center`,children:`Imports problems & solution notes`})]}),(0,a.jsx)(`input`,{type:`file`,accept:`.csv,.db`,disabled:E,onChange:re,className:`absolute inset-0 opacity-0 cursor-pointer w-full h-full disabled:cursor-wait`})]}),(0,a.jsxs)(`div`,{className:`text-[9px] text-slate-400 font-medium leading-normal space-y-1 font-sans`,children:[(0,a.jsxs)(`p`,{children:[`• `,(0,a.jsx)(`b`,{children:`CSV File:`}),` Must have a `,(0,a.jsx)(`code`,{children:`name`}),` column. Optional: `,(0,a.jsx)(`code`,{children:`problem_number`}),`, `,(0,a.jsx)(`code`,{children:`pattern`}),`, `,(0,a.jsx)(`code`,{children:`difficulty`}),`, `,(0,a.jsx)(`code`,{children:`optimal_time`}),`, `,(0,a.jsx)(`code`,{children:`optimal_space`}),`, `,(0,a.jsx)(`code`,{children:`reference_code`}),`, `,(0,a.jsx)(`code`,{children:`description`}),`.`]}),(0,a.jsxs)(`p`,{children:[`• `,(0,a.jsx)(`b`,{children:`SQLite DB File:`}),` Must be a standard database backup containing a `,(0,a.jsx)(`code`,{children:`problems`}),` table matching AlgoSpaced design.`]})]})]})]})})]})}export{s as default};
|
algospaced-ui/dist/assets/JourneyPath-BQEZfHUb.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
algospaced-ui/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2
ADDED
|
Binary file (28.1 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff
ADDED
|
Binary file (33.5 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf
ADDED
|
Binary file (63.6 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf
ADDED
|
Binary file (12.4 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff
ADDED
|
Binary file (7.72 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2
ADDED
|
Binary file (6.91 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff
ADDED
|
Binary file (7.66 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2
ADDED
|
Binary file (6.91 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf
ADDED
|
Binary file (12.3 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf
ADDED
|
Binary file (19.6 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff
ADDED
|
Binary file (13.3 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2
ADDED
|
Binary file (11.3 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf
ADDED
|
Binary file (19.6 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2
ADDED
|
Binary file (11.3 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff
ADDED
|
Binary file (13.2 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2
ADDED
|
Binary file (25.3 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff
ADDED
|
Binary file (29.9 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf
ADDED
|
Binary file (51.3 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2
ADDED
|
Binary file (16.8 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf
ADDED
|
Binary file (33 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff
ADDED
|
Binary file (19.4 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf
ADDED
|
Binary file (33.6 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff
ADDED
|
Binary file (19.7 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2
ADDED
|
Binary file (17 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2
ADDED
|
Binary file (26.3 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff
ADDED
|
Binary file (30.8 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf
ADDED
|
Binary file (53.6 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf
ADDED
|
Binary file (31.2 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2
ADDED
|
Binary file (16.4 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff
ADDED
|
Binary file (18.7 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff
ADDED
|
Binary file (18.7 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf
ADDED
|
Binary file (31.3 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2
ADDED
|
Binary file (16.4 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf
ADDED
|
Binary file (24.5 kB). View file
|
|
|
algospaced-ui/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2
ADDED
|
Binary file (12.2 kB). View file
|
|
|